From 9b26855d3db1d762d74a586e415d1b3428d87137 Mon Sep 17 00:00:00 2001 From: Silent Date: Wed, 11 Dec 2019 21:37:18 +0100 Subject: [PATCH] Unified math functions --- SilentPatch/General.h | 83 --- SilentPatch/Maths.h | 518 ++++++++++++++++++ SilentPatch/RWGTA.cpp | 5 +- SilentPatch/StoredCar.h | 2 +- SilentPatchIII/SilentPatchIII.cpp | 10 +- SilentPatchIII/SilentPatchIII.vcxproj | 2 +- SilentPatchIII/SilentPatchIII.vcxproj.filters | 6 +- SilentPatchSA/GeneralSA.h | 52 -- SilentPatchSA/Maths.h | 399 -------------- SilentPatchSA/SilentPatchSA.cpp | 20 +- SilentPatchSA/SilentPatchSA.vcxproj | 2 +- SilentPatchSA/SilentPatchSA.vcxproj.filters | 6 +- SilentPatchVC/ModelInfoVC.h | 1 - SilentPatchVC/SilentPatchVC.cpp | 2 +- SilentPatchVC/SilentPatchVC.vcxproj | 2 +- SilentPatchVC/SilentPatchVC.vcxproj.filters | 6 +- 16 files changed, 547 insertions(+), 569 deletions(-) delete mode 100644 SilentPatch/General.h create mode 100644 SilentPatch/Maths.h delete mode 100644 SilentPatchSA/Maths.h diff --git a/SilentPatch/General.h b/SilentPatch/General.h deleted file mode 100644 index 7896791..0000000 --- a/SilentPatch/General.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef __GENERAL -#define __GENERAL - -#include - -class CRGBA -{ -public: - BYTE r, g, b, a; - - inline CRGBA() {} - - inline CRGBA(const CRGBA& in) - : r(in.r), g(in.g), b(in.b), a(in.a) - {} - - inline CRGBA(const CRGBA& in, BYTE alpha) - : r(in.r), g(in.g), b(in.b), a(alpha) - {} - - - inline CRGBA(BYTE red, BYTE green, BYTE blue, BYTE alpha = 255) - : r(red), g(green), b(blue), a(alpha) - {} -}; - -class CRect -{ -public: - float x1, y1; - float x2, y2; - - inline CRect() {} - inline CRect(float a, float b, float c, float d) - : x1(a), y1(b), x2(c), y2(d) - {} -}; - -class CVector -{ -public: - float x, y, z; - - CVector() - {} - - constexpr CVector(float fX, float fY, float fZ=0.0f) - : x(fX), y(fY), z(fZ) - {} - - - CVector& operator+=(const CVector& vec) - { x += vec.x; y += vec.y; z += vec.z; - return *this; } - CVector& operator-=(const CVector& vec) - { x -= vec.x; y -= vec.y; z -= vec.z; - return *this; } - - inline float Magnitude() const - { return sqrt(x * x + y * y + z * z); } - inline constexpr float MagnitudeSqr() const - { return x * x + y * y + z * z; } - inline CVector& Normalize() - { float fInvLen = 1.0f / Magnitude(); x *= fInvLen; y *= fInvLen; z *= fInvLen; return *this; } - - friend inline float DotProduct(const CVector& vec1, const CVector& vec2) - { return vec1.x * vec2.x + vec1.x * vec2.y + vec1.z * vec2.z; } - friend inline CVector CrossProduct(const CVector& vec1, const CVector& vec2) - { return CVector( vec1.y * vec2.z - vec1.z * vec2.y, - vec1.z * vec2.x - vec1.x * vec2.z, - vec1.x * vec2.y - vec1.y * vec2.x); } - - friend inline CVector operator*(const CVector& in, float fMul) - { return CVector(in.x * fMul, in.y * fMul, in.z * fMul); } - friend inline CVector operator+(const CVector& vec1, const CVector& vec2) - { return CVector(vec1.x + vec2.x, vec1.y + vec2.y, vec1.z + vec2.z); } - friend inline CVector operator-(const CVector& vec1, const CVector& vec2) - { return CVector(vec1.x - vec2.x, vec1.y - vec2.y, vec1.z - vec2.z); } - friend inline CVector operator-(const CVector& vec) - { return CVector(-vec.x, -vec.y, -vec.z); } -}; - -#endif \ No newline at end of file diff --git a/SilentPatch/Maths.h b/SilentPatch/Maths.h new file mode 100644 index 0000000..cef91ee --- /dev/null +++ b/SilentPatch/Maths.h @@ -0,0 +1,518 @@ +#ifndef __MATHS__H +#define __MATHS__H + +#include + +constexpr double RAD_TO_DEG (180.0/3.1415926535897932385); +constexpr double DEG_TO_RAD (3.1415926535897932385/180.0); + +class CRGBA +{ +public: + uint8_t r, g, b, a; + + inline CRGBA() {} + + inline constexpr CRGBA(const CRGBA& in) + : r(in.r), g(in.g), b(in.b), a(in.a) + {} + + inline constexpr CRGBA(const CRGBA& in, uint8_t alpha) + : r(in.r), g(in.g), b(in.b), a(alpha) + {} + + + inline constexpr CRGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255) + : r(red), g(green), b(blue), a(alpha) + {} + + friend constexpr CRGBA Blend(const CRGBA& From, const CRGBA& To, double BlendVal) + { const double InvBlendVal = 1.0 - BlendVal; + return CRGBA( uint8_t(To.r * BlendVal + From.r * InvBlendVal), + uint8_t(To.g * BlendVal + From.g * InvBlendVal), + uint8_t(To.b * BlendVal + From.b * InvBlendVal), + uint8_t(To.a * BlendVal + From.a * InvBlendVal)); } + + friend constexpr CRGBA BlendSqr(const CRGBA& From, const CRGBA& To, double BlendVal) + { const double InvBlendVal = 1.0 - BlendVal; + return CRGBA( uint8_t(sqrt((To.r * To.r) * BlendVal + (From.r * From.r) * InvBlendVal)), + uint8_t(sqrt((To.g * To.g) * BlendVal + (From.g * From.g) * InvBlendVal)), + uint8_t(sqrt((To.b * To.b) * BlendVal + (From.b * From.b) * InvBlendVal)), + uint8_t(sqrt((To.a * To.a) * BlendVal + (From.a * From.a) * InvBlendVal))); } +}; + +class CRect +{ +public: + float x1, y1; + float x2, y2; + + inline CRect() {} + inline constexpr CRect(float a, float b, float c, float d) + : x1(a), y1(b), x2(c), y2(d) + {} +}; + +class CVector +{ +public: + float x, y, z; + + CVector() + {} + + constexpr CVector(float fX, float fY, float fZ=0.0f) + : x(fX), y(fY), z(fZ) + {} + + constexpr CVector(const RwV3d& rwVec) + : x(rwVec.x), y(rwVec.y), z(rwVec.z) + {} + + CVector& operator+=(const CVector& vec) + { x += vec.x; y += vec.y; z += vec.z; + return *this; } + CVector& operator+=(const RwV3d& vec) + { x += vec.x; y += vec.y; z += vec.z; + return *this; } + CVector& operator-=(const CVector& vec) + { x -= vec.x; y -= vec.y; z -= vec.z; + return *this; } + CVector& operator-=(const RwV3d& vec) + { x -= vec.x; y -= vec.y; z -= vec.z; + return *this; } + + inline float Magnitude() const + { return sqrt(x * x + y * y + z * z); } + inline constexpr float MagnitudeSqr() const + { return x * x + y * y + z * z; } + inline CVector& Normalize() + { float fInvLen = 1.0f / Magnitude(); x *= fInvLen; y *= fInvLen; z *= fInvLen; return *this; } + + friend inline float DotProduct(const CVector& vec1, const CVector& vec2) + { return vec1.x * vec2.x + vec1.x * vec2.y + vec1.z * vec2.z; } + friend inline CVector CrossProduct(const CVector& vec1, const CVector& vec2) + { return CVector( vec1.y * vec2.z - vec1.z * vec2.y, + vec1.z * vec2.x - vec1.x * vec2.z, + vec1.x * vec2.y - vec1.y * vec2.x); } + + friend inline CVector operator*(const CVector& in, float fMul) + { return CVector(in.x * fMul, in.y * fMul, in.z * fMul); } + friend inline CVector operator+(const CVector& vec1, const CVector& vec2) + { return CVector(vec1.x + vec2.x, vec1.y + vec2.y, vec1.z + vec2.z); } + friend inline CVector operator+(const CVector& vec1, const RwV3d& vec2) + { return CVector(vec1.x + vec2.x, vec1.y + vec2.y, vec1.z + vec2.z); } + friend inline CVector operator-(const CVector& vec1, const CVector& vec2) + { return CVector(vec1.x - vec2.x, vec1.y - vec2.y, vec1.z - vec2.z); } + friend inline CVector operator-(const CVector& vec1, const RwV3d& vec2) + { return CVector(vec1.x - vec2.x, vec1.y - vec2.y, vec1.z - vec2.z); } + friend inline CVector operator-(const CVector& vec) + { return CVector(-vec.x, -vec.y, -vec.z); } + + inline CVector& FromMultiply(const class CMatrix& mat, const CVector& vec); + inline CVector& FromMultiply3X3(const class CMatrix& mat, const CVector& vec); +}; + +class CVector2D +{ +public: + float x, y; + + CVector2D() + {} + + constexpr CVector2D(float fX, float fY) + : x(fX), y(fY) + {} + + CVector2D& operator+=(const CVector2D& vec) + { x += vec.x; y += vec.y; + return *this; } + CVector2D& operator-=(const CVector2D& vec) + { x -= vec.x; y -= vec.y; + return *this; } + + inline float Magnitude() const + { return sqrt(x * x + y * y); } + inline constexpr float MagnitudeSqr() const + { return x * x + y * y; } + inline CVector2D& Normalize() + { float fInvLen = 1.0f / Magnitude(); x *= fInvLen; y *= fInvLen; return *this; } + + friend inline float DotProduct(const CVector2D& vec1, const CVector2D& vec2) + { return vec1.x * vec2.x + vec1.x * vec2.y; } + + friend inline CVector2D operator*(const CVector2D& in, float fMul) + { return CVector2D(in.x * fMul, in.y * fMul); } + friend inline CVector2D operator+(const CVector2D& vec1, const CVector2D& vec2) + { return CVector2D(vec1.x + vec2.x, vec1.y + vec2.y); } + friend inline CVector2D operator-(const CVector2D& vec1, const CVector2D& vec2) + { return CVector2D(vec1.x - vec2.x, vec1.y - vec2.y); } + friend inline CVector2D operator-(const CVector2D& vec) + { return CVector2D(-vec.x, -vec.y); } +}; + +class CSphere +{ +public: + RwSphere sphere; + +public: + void Set(float fRadius, const CVector& vecCenter) + { + sphere.center.x = vecCenter.x; + sphere.center.y = vecCenter.y; + sphere.center.z = vecCenter.z; + sphere.radius = fRadius; + } +}; + +class CMatrix +{ +private: + RwMatrix m_matrix; + RwMatrix* m_pMatrix = nullptr; + RwBool m_haveRwMatrix = FALSE; + +public: + inline CMatrix() = default; + + inline CMatrix(RwMatrix* pMatrix, bool bHasMatrix=false) + { Attach(pMatrix, bHasMatrix); } + + inline CMatrix(const CMatrix& theMatrix) + : m_matrix(theMatrix.m_matrix) + {} + + inline CMatrix(const CVector& vecRight, const CVector& vecUp, const CVector& vecAt, const CVector& vecPos) + { + GetRight() = vecRight; + GetUp() = vecUp; + GetAt() = vecAt; + GetPos() = vecPos; + } + + inline ~CMatrix() + { if ( m_haveRwMatrix && m_pMatrix ) + RwMatrixDestroy(m_pMatrix); } + + inline CMatrix& operator*=(const CMatrix& right) + { + CVector vright(this->m_matrix.right.x * right.m_matrix.right.x + this->m_matrix.right.y * right.m_matrix.up.x + this->m_matrix.right.z * right.m_matrix.at.x + right.m_matrix.pos.x, + this->m_matrix.right.x * right.m_matrix.right.y + this->m_matrix.right.y * right.m_matrix.up.y + this->m_matrix.right.z * right.m_matrix.at.y + right.m_matrix.pos.y, + this->m_matrix.right.x * right.m_matrix.right.z + this->m_matrix.right.y * right.m_matrix.up.z + this->m_matrix.right.z * right.m_matrix.at.z + right.m_matrix.pos.z); + CVector vup(this->m_matrix.up.x * right.m_matrix.right.x + this->m_matrix.up.y * right.m_matrix.up.x + this->m_matrix.up.z * right.m_matrix.at.x + right.m_matrix.pos.x, + this->m_matrix.up.x * right.m_matrix.right.y + this->m_matrix.up.y * right.m_matrix.up.y + this->m_matrix.up.z * right.m_matrix.at.y + right.m_matrix.pos.y, + this->m_matrix.up.x * right.m_matrix.right.z + this->m_matrix.up.y * right.m_matrix.up.z + this->m_matrix.up.z * right.m_matrix.at.z + right.m_matrix.pos.z); + CVector vat(this->m_matrix.at.x * right.m_matrix.right.x + this->m_matrix.at.y * right.m_matrix.up.x + this->m_matrix.at.z * right.m_matrix.at.x + right.m_matrix.pos.x, + this->m_matrix.at.x * right.m_matrix.right.y + this->m_matrix.at.y * right.m_matrix.up.y + this->m_matrix.at.z * right.m_matrix.at.y + right.m_matrix.pos.y, + this->m_matrix.at.x * right.m_matrix.right.z + this->m_matrix.at.y * right.m_matrix.up.z + this->m_matrix.at.z * right.m_matrix.at.z + right.m_matrix.pos.z); + CVector vpos(this->m_matrix.pos.x * right.m_matrix.right.x + this->m_matrix.pos.y * right.m_matrix.up.x + this->m_matrix.pos.z * right.m_matrix.at.x + right.m_matrix.pos.x, + this->m_matrix.pos.x * right.m_matrix.right.y + this->m_matrix.pos.y * right.m_matrix.up.y + this->m_matrix.pos.z * right.m_matrix.at.y + right.m_matrix.pos.y, + this->m_matrix.pos.x * right.m_matrix.right.z + this->m_matrix.pos.y * right.m_matrix.up.z + this->m_matrix.pos.z * right.m_matrix.at.z + right.m_matrix.pos.z); + + GetRight() = vright; + GetUp() = vup; + GetAt() = vat; + GetPos() = vpos; + + return *this; + } + + friend inline CMatrix operator*(const CMatrix& Rot1, const CMatrix& Rot2) + { return CMatrix( CVector(Rot1.m_matrix.right.x * Rot2.m_matrix.right.x + Rot1.m_matrix.right.y * Rot2.m_matrix.up.x + Rot1.m_matrix.right.z * Rot2.m_matrix.at.x + Rot2.m_matrix.pos.x, + Rot1.m_matrix.right.x * Rot2.m_matrix.right.y + Rot1.m_matrix.right.y * Rot2.m_matrix.up.y + Rot1.m_matrix.right.z * Rot2.m_matrix.at.y + Rot2.m_matrix.pos.y, + Rot1.m_matrix.right.x * Rot2.m_matrix.right.z + Rot1.m_matrix.right.y * Rot2.m_matrix.up.z + Rot1.m_matrix.right.z * Rot2.m_matrix.at.z + Rot2.m_matrix.pos.z), + CVector(Rot1.m_matrix.up.x * Rot2.m_matrix.right.x + Rot1.m_matrix.up.y * Rot2.m_matrix.up.x + Rot1.m_matrix.up.z * Rot2.m_matrix.at.x + Rot2.m_matrix.pos.x, + Rot1.m_matrix.up.x * Rot2.m_matrix.right.y + Rot1.m_matrix.up.y * Rot2.m_matrix.up.y + Rot1.m_matrix.up.z * Rot2.m_matrix.at.y + Rot2.m_matrix.pos.y, + Rot1.m_matrix.up.x * Rot2.m_matrix.right.z + Rot1.m_matrix.up.y * Rot2.m_matrix.up.z + Rot1.m_matrix.up.z * Rot2.m_matrix.at.z + Rot2.m_matrix.pos.z), + CVector(Rot1.m_matrix.at.x * Rot2.m_matrix.right.x + Rot1.m_matrix.at.y * Rot2.m_matrix.up.x + Rot1.m_matrix.at.z * Rot2.m_matrix.at.x + Rot2.m_matrix.pos.x, + Rot1.m_matrix.at.x * Rot2.m_matrix.right.y + Rot1.m_matrix.at.y * Rot2.m_matrix.up.y + Rot1.m_matrix.at.z * Rot2.m_matrix.at.y + Rot2.m_matrix.pos.y, + Rot1.m_matrix.at.x * Rot2.m_matrix.right.z + Rot1.m_matrix.at.y * Rot2.m_matrix.up.z + Rot1.m_matrix.at.z * Rot2.m_matrix.at.z + Rot2.m_matrix.pos.z), + CVector(Rot1.m_matrix.pos.x * Rot2.m_matrix.right.x + Rot1.m_matrix.pos.y * Rot2.m_matrix.up.x + Rot1.m_matrix.pos.z * Rot2.m_matrix.at.x + Rot2.m_matrix.pos.x, + Rot1.m_matrix.pos.x * Rot2.m_matrix.right.y + Rot1.m_matrix.pos.y * Rot2.m_matrix.up.y + Rot1.m_matrix.pos.z * Rot2.m_matrix.at.y + Rot2.m_matrix.pos.y, + Rot1.m_matrix.pos.x * Rot2.m_matrix.right.z + Rot1.m_matrix.pos.y * Rot2.m_matrix.up.z + Rot1.m_matrix.pos.z * Rot2.m_matrix.at.z + Rot2.m_matrix.pos.z)); }; + + friend inline CVector operator*(const CMatrix& m_matrix, const CVector& vec) + { return CVector(m_matrix.m_matrix.up.x * vec.y + m_matrix.m_matrix.right.x * vec.x + m_matrix.m_matrix.at.x * vec.z + m_matrix.m_matrix.pos.x, + m_matrix.m_matrix.up.y * vec.y + m_matrix.m_matrix.right.y * vec.x + m_matrix.m_matrix.at.y * vec.z + m_matrix.m_matrix.pos.y, + m_matrix.m_matrix.up.z * vec.y + m_matrix.m_matrix.right.z * vec.x + m_matrix.m_matrix.at.z * vec.z + m_matrix.m_matrix.pos.z); }; + + friend inline CMatrix operator+(const CMatrix& Rot1, const CMatrix& Rot2) + { return CMatrix( Rot1.GetRight() + Rot2.GetRight(), Rot1.GetUp() + Rot2.GetUp(), Rot1.GetAt() + Rot2.GetAt(), Rot1.GetPos() + Rot2.GetPos() ); } + + inline CMatrix& operator=(const CMatrix& mat) + { + m_matrix = mat.m_matrix; + if ( m_pMatrix != nullptr ) + UpdateRwMatrix(m_pMatrix); + return *this; + } + + inline CMatrix& operator+=(const CMatrix& mat) + { + GetRight() += mat.GetRight(); + GetUp() += mat.GetUp(); + GetAt() += mat.GetAt(); + GetPos() += mat.GetPos(); + + return *this; + } + + friend inline CMatrix& Invert(const CMatrix& src, CMatrix& dst) + { + dst.GetRight() = CVector(src.m_matrix.right.x, src.m_matrix.up.x, src.m_matrix.at.x); + dst.GetUp() = CVector(src.m_matrix.right.y, src.m_matrix.up.y, src.m_matrix.at.y); + dst.GetAt() = CVector(src.m_matrix.right.z, src.m_matrix.up.z, src.m_matrix.at.z); + + dst.GetPos() = -(dst.GetRight() * src.GetPos().x + dst.GetUp() * src.GetPos().y + dst.GetAt() * src.GetPos().z); + + return dst; + } + + friend inline CMatrix Invert(const CMatrix& src) + { + CMatrix NewMatrix; + Invert(src, NewMatrix); + return NewMatrix; + } + + friend inline CVector Multiply3x3(const CMatrix& m_matrix, const CVector& vec) + { return CVector(m_matrix.m_matrix.up.x * vec.y + m_matrix.m_matrix.right.x * vec.x + m_matrix.m_matrix.at.x * vec.z, + m_matrix.m_matrix.up.y * vec.y + m_matrix.m_matrix.right.y * vec.x + m_matrix.m_matrix.at.y * vec.z, + m_matrix.m_matrix.up.z * vec.y + m_matrix.m_matrix.right.z * vec.x + m_matrix.m_matrix.at.z * vec.z); }; + + friend inline CVector Multiply3x3(const CVector& vec, const CMatrix& m_matrix) + { return CVector(DotProduct(m_matrix.GetRight(), vec), DotProduct(m_matrix.GetUp(), vec), DotProduct(m_matrix.GetAt(), vec)); } + + inline CVector& GetRight() + { return *reinterpret_cast(&m_matrix.right); } + inline CVector& GetUp() + { return *reinterpret_cast(&m_matrix.up); } + inline CVector& GetAt() + { return *reinterpret_cast(&m_matrix.at); } + inline CVector& GetPos() + { return *reinterpret_cast(&m_matrix.pos); } + + inline const CVector& GetRight() const + { return *reinterpret_cast(&m_matrix.right); } + inline const CVector& GetUp() const + { return *reinterpret_cast(&m_matrix.up); } + inline const CVector& GetAt() const + { return *reinterpret_cast(&m_matrix.at); } + inline const CVector& GetPos() const + { return *reinterpret_cast(&m_matrix.pos); } + + inline void SetTranslateOnly(float fX, float fY, float fZ) + { m_matrix.pos.x = fX; m_matrix.pos.y = fY; m_matrix.pos.z = fZ; } + + inline void SetRotateX(float fAngle) + { SetRotateXOnly(fAngle); m_matrix.pos.x = 0.0f; m_matrix.pos.y = 0.0f; m_matrix.pos.z = 0.0f; } + inline void SetRotateY(float fAngle) + { SetRotateYOnly(fAngle); m_matrix.pos.x = 0.0f; m_matrix.pos.y = 0.0f; m_matrix.pos.z = 0.0f; } + inline void SetRotateZ(float fAngle) + { SetRotateZOnly(fAngle); m_matrix.pos.x = 0.0f; m_matrix.pos.y = 0.0f; m_matrix.pos.z = 0.0f; } + inline void SetRotate(float fAngleX, float fAngleY, float fAngleZ) + { SetRotateOnly(fAngleX, fAngleY, fAngleZ); m_matrix.pos.x = 0.0f; m_matrix.pos.y = 0.0f; m_matrix.pos.z = 0.0f; } + inline void SetTranslate(float fX, float fY, float fZ) + { m_matrix.right.x = 1.0f; m_matrix.right.y = 0.0f; m_matrix.right.z = 0.0f; + m_matrix.up.x = 0.0f; m_matrix.up.y = 1.0f; m_matrix.up.z = 0.0f; + m_matrix.at.x = 0.0f; m_matrix.at.y = 0.0f; m_matrix.at.z = 1.0f; + SetTranslateOnly(fX, fY, fZ); } + + inline void ResetOrientation() + { + m_matrix.right.x = 1.0f; m_matrix.right.y = 0.0f; m_matrix.right.z = 0.0f; + m_matrix.up.x = 0.0f; m_matrix.up.y = 1.0f; m_matrix.up.z = 0.0f; + m_matrix.at.x = 0.0f; m_matrix.at.y = 0.0f; m_matrix.at.z = 1.0f; + } + + inline void SetUnity() + { + ResetOrientation(); + m_matrix.pos.x = 0.0f; m_matrix.pos.y = 0.0f; m_matrix.pos.z = 0.0f; + } + + inline void SetScale(float fScale) + { + m_matrix.right.x = fScale; m_matrix.right.y = 0.0f; m_matrix.right.z = 0.0f; + m_matrix.up.x = 0.0f; m_matrix.up.y = fScale; m_matrix.up.z = 0.0f; + m_matrix.at.x = 0.0f; m_matrix.at.y = 0.0f; m_matrix.at.z = fScale; + m_matrix.pos.x = 0.0f; m_matrix.pos.y = 0.0f; m_matrix.pos.z = 0.0f; + } + + inline void RotateX(float fAngle) + { + CMatrix RotationMatrix; + RotationMatrix.SetRotateX(fAngle); + *this *= RotationMatrix; + } + + inline void RotateY(float fAngle) + { + CMatrix RotationMatrix; + RotationMatrix.SetRotateY(fAngle); + *this *= RotationMatrix; + } + + inline void RotateZ(float fAngle) + { + CMatrix RotationMatrix; + RotationMatrix.SetRotateZ(fAngle); + *this *= RotationMatrix; + } + + inline void Rotate(float fAngleX, float fAngleY, float fAngleZ) + { + CMatrix RotationMatrix; + RotationMatrix.SetRotate(fAngleX, fAngleY, fAngleZ); + *this *= RotationMatrix; + } + + inline void SetRotateXOnly(float fAngle) + { + m_matrix.right.x = 1.0f; + m_matrix.right.y = 0.0f; + m_matrix.right.z = 0.0f; + + m_matrix.up.x = 0.0f; + m_matrix.up.y = cos(fAngle); + m_matrix.up.z = sin(fAngle); + + m_matrix.at.x = 0.0f; + m_matrix.at.y = -sin(fAngle); + m_matrix.at.z = cos(fAngle); + } + + inline void SetRotateYOnly(float fAngle) + { + m_matrix.right.x = cos(fAngle); + m_matrix.right.y = 0.0f; + m_matrix.right.z = sin(fAngle); + + m_matrix.up.x = 0.0f; + m_matrix.up.y = 1.0f; + m_matrix.up.z = 0.0f; + + m_matrix.at.x = -sin(fAngle); + m_matrix.at.y = 0.0f; + m_matrix.at.z = cos(fAngle); + } + + inline void SetRotateZOnly(float fAngle) + { + m_matrix.at.x = 0.0f; + m_matrix.at.y = 0.0f; + m_matrix.at.z = 1.0f; + + m_matrix.up.x = -sin(fAngle); + m_matrix.up.y = cos(fAngle); + m_matrix.up.z = 0.0f; + + m_matrix.right.x = cos(fAngle); + m_matrix.right.y = sin(fAngle); + m_matrix.right.z = 0.0f; + } + + inline void SetRotateOnly(float fAngleX, float fAngleY, float fAngleZ) + { + m_matrix.right.x = cos(fAngleZ) * cos(fAngleY) - sin(fAngleZ) * sin(fAngleX) * sin(fAngleY); + m_matrix.right.y = cos(fAngleZ) * sin(fAngleX) * sin(fAngleY) + sin(fAngleZ) * cos(fAngleY); + m_matrix.right.z = -cos(fAngleX) * sin(fAngleY); + + m_matrix.up.x = -sin(fAngleZ) * cos(fAngleX); + m_matrix.up.y = cos(fAngleZ) * cos(fAngleX); + m_matrix.up.z = sin(fAngleX); + + m_matrix.at.x = sin(fAngleZ) * sin(fAngleX) * cos(fAngleY) + cos(fAngleZ) * sin(fAngleY); + m_matrix.at.y = sin(fAngleZ) * sin(fAngleY) - cos(fAngleZ) * sin(fAngleX) * cos(fAngleY); + m_matrix.at.z = cos(fAngleX) * cos(fAngleY); + } + + inline void Attach(RwMatrix* pMatrix, bool bHasMatrix) + { + if ( m_pMatrix && m_haveRwMatrix ) + RwMatrixDestroy(m_pMatrix); + + m_pMatrix = pMatrix; + m_haveRwMatrix = bHasMatrix; + + Update(); + } + + inline void AttachRw(RwMatrix* pMatrix, bool bHasMatrix) + { + if ( m_pMatrix && m_haveRwMatrix ) + RwMatrixDestroy(m_pMatrix); + + m_pMatrix = pMatrix; + m_haveRwMatrix = bHasMatrix; + + UpdateRW(); + } + + inline void Detach() + { + if ( m_pMatrix ) + { + if ( m_haveRwMatrix ) + RwMatrixDestroy(m_pMatrix); + m_pMatrix = nullptr; + } + } + + inline void UpdateRW() const + { + if ( m_pMatrix ) + UpdateRwMatrix(m_pMatrix); + } + + inline void Update() + { + UpdateMatrix(m_pMatrix); + } + + inline void UpdateMatrix(RwMatrix* pMatrix) + { + m_matrix.right = pMatrix->right; + m_matrix.up = pMatrix->up; + m_matrix.at = pMatrix->at; + m_matrix.pos = pMatrix->pos; + } + + inline void UpdateRwMatrix(RwMatrix* pMatrix) const + { + pMatrix->right = m_matrix.right; + pMatrix->up = m_matrix.up; + pMatrix->at = m_matrix.at; + pMatrix->pos = m_matrix.pos; + RwMatrixUpdate(pMatrix); + } + + inline void CopyToRwMatrix(RwMatrix* pMatrix) const + { + pMatrix->right = m_pMatrix->right; + pMatrix->up = m_pMatrix->up; + pMatrix->at = m_pMatrix->at; + pMatrix->pos = m_pMatrix->pos; + RwMatrixUpdate(pMatrix); + } + + inline void CopyOnlyMatrix(const CMatrix& from) + { + m_matrix = from.m_matrix; + } +}; + +// These need to land here +inline CVector& CVector::FromMultiply(const CMatrix& mat, const CVector& vec) +{ + return *this = mat * vec; +} + +inline CVector& CVector::FromMultiply3X3(const CMatrix& mat, const CVector& vec) +{ + return *this = Multiply3x3(mat, vec); +} + +#endif \ No newline at end of file diff --git a/SilentPatch/RWGTA.cpp b/SilentPatch/RWGTA.cpp index 64b3456..73c711a 100644 --- a/SilentPatch/RWGTA.cpp +++ b/SilentPatch/RWGTA.cpp @@ -54,4 +54,7 @@ RwBool RwIm2DRenderLine(RwIm2DVertex *vertices, RwInt32 numVertices, RwInt32 ver RwReal RwIm2DGetNearScreenZ() { return GTARWSRCGLOBAL(dOpenDevice).zBufferNear; -} \ No newline at end of file +} + +// Unreachable stub +RwBool RwMatrixDestroy(RwMatrix* mpMat) { assert(!"Unreachable!"); return TRUE; } \ No newline at end of file diff --git a/SilentPatch/StoredCar.h b/SilentPatch/StoredCar.h index 8009f31..3ee5494 100644 --- a/SilentPatch/StoredCar.h +++ b/SilentPatch/StoredCar.h @@ -1,6 +1,6 @@ #pragma once -#include "General.h" +#include "Maths.h" #if _GTA_III #include "../SilentPatchIII/VehicleIII.h" diff --git a/SilentPatchIII/SilentPatchIII.cpp b/SilentPatchIII/SilentPatchIII.cpp index 15924ae..0afe49f 100644 --- a/SilentPatchIII/SilentPatchIII.cpp +++ b/SilentPatchIII/SilentPatchIII.cpp @@ -1,6 +1,6 @@ #include "StdAfx.h" -#include "General.h" +#include "Maths.h" #include "Timer.h" #include "Utils/Patterns.h" #include "Common.h" @@ -41,14 +41,6 @@ struct RsGlobalType void* pad; }; - - -struct RwV2d -{ - float x; /**< X value*/ - float y; /**< Y value */ -}; - DebugMenuAPI gDebugMenuAPI; static HMODULE hDLLModule; diff --git a/SilentPatchIII/SilentPatchIII.vcxproj b/SilentPatchIII/SilentPatchIII.vcxproj index 86a2ed3..a5ff2e6 100644 --- a/SilentPatchIII/SilentPatchIII.vcxproj +++ b/SilentPatchIII/SilentPatchIII.vcxproj @@ -48,7 +48,7 @@ - + diff --git a/SilentPatchIII/SilentPatchIII.vcxproj.filters b/SilentPatchIII/SilentPatchIII.vcxproj.filters index 49254c6..f36b263 100644 --- a/SilentPatchIII/SilentPatchIII.vcxproj.filters +++ b/SilentPatchIII/SilentPatchIII.vcxproj.filters @@ -50,9 +50,6 @@ Header Files - - Header Files - Header Files @@ -83,6 +80,9 @@ Header Files + + Header Files + diff --git a/SilentPatchSA/GeneralSA.h b/SilentPatchSA/GeneralSA.h index 4fc1dc4..fd1ed76 100644 --- a/SilentPatchSA/GeneralSA.h +++ b/SilentPatchSA/GeneralSA.h @@ -11,58 +11,6 @@ public: float m_heading; }; -class CRGBA -{ -public: - uint8_t r, g, b, a; - - inline CRGBA() {} - - inline constexpr CRGBA(const CRGBA& in) - : r(in.r), g(in.g), b(in.b), a(in.a) - {} - - inline constexpr CRGBA(const CRGBA& in, uint8_t alpha) - : r(in.r), g(in.g), b(in.b), a(alpha) - {} - - - inline constexpr CRGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255) - : r(red), g(green), b(blue), a(alpha) - {} - - friend constexpr CRGBA Blend(const CRGBA& From, const CRGBA& To, double BlendVal) - { double InvBlendVal = 1.0 - BlendVal; - return CRGBA( uint8_t(To.r * BlendVal + From.r * InvBlendVal), - uint8_t(To.g * BlendVal + From.g * InvBlendVal), - uint8_t(To.b * BlendVal + From.b * InvBlendVal), - uint8_t(To.a * BlendVal + From.a * InvBlendVal)); } - - friend constexpr CRGBA BlendSqr(const CRGBA& From, const CRGBA& To, double BlendVal) - { double InvBlendVal = 1.0 - BlendVal; - return CRGBA( uint8_t(sqrt((To.r * To.r) * BlendVal + (From.r * From.r) * InvBlendVal)), - uint8_t(sqrt((To.g * To.g) * BlendVal + (From.g * From.g) * InvBlendVal)), - uint8_t(sqrt((To.b * To.b) * BlendVal + (From.b * From.b) * InvBlendVal)), - uint8_t(sqrt((To.a * To.a) * BlendVal + (From.a * From.a) * InvBlendVal))); } - - // SilentPatch - CRGBA* BlendGangColour(uint8_t r, uint8_t g, uint8_t b, uint8_t a); - CRGBA* BlendGangColour_Dynamic(uint8_t r, uint8_t g, uint8_t b, uint8_t a); -}; - -class CRect -{ -public: - float x1, y1; - float x2, y2; - - inline CRect() {} - inline constexpr CRect(float a, float b, float c, float d) - : x1(a), y1(b), x2(c), y2(d) - {} -}; - - class CPlaceable { private: diff --git a/SilentPatchSA/Maths.h b/SilentPatchSA/Maths.h deleted file mode 100644 index afa0a2e..0000000 --- a/SilentPatchSA/Maths.h +++ /dev/null @@ -1,399 +0,0 @@ -#ifndef __MATHS__H -#define __MATHS__H - -#define RAD_TO_DEG (180.0/M_PI) -#define DEG_TO_RAD (M_PI/180.0) - -class CVector -{ -public: - float x, y, z; - - CVector() - {} - - constexpr CVector(float fX, float fY, float fZ=0.0f) - : x(fX), y(fY), z(fZ) - {} - - constexpr CVector(const RwV3d& rwVec) - : x(rwVec.x), y(rwVec.y), z(rwVec.z) - {} - - CVector& operator+=(const CVector& vec) - { x += vec.x; y += vec.y; z += vec.z; - return *this; } - CVector& operator+=(const RwV3d& vec) - { x += vec.x; y += vec.y; z += vec.z; - return *this; } - CVector& operator-=(const CVector& vec) - { x -= vec.x; y -= vec.y; z -= vec.z; - return *this; } - CVector& operator-=(const RwV3d& vec) - { x -= vec.x; y -= vec.y; z -= vec.z; - return *this; } - - inline float Magnitude() const - { return sqrt(x * x + y * y + z * z); } - inline constexpr float MagnitudeSqr() const - { return x * x + y * y + z * z; } - inline CVector& Normalize() - { float fInvLen = 1.0f / Magnitude(); x *= fInvLen; y *= fInvLen; z *= fInvLen; return *this; } - - friend inline float DotProduct(const CVector& vec1, const CVector& vec2) - { return vec1.x * vec2.x + vec1.x * vec2.y + vec1.z * vec2.z; } - friend inline CVector CrossProduct(const CVector& vec1, const CVector& vec2) - { return CVector( vec1.y * vec2.z - vec1.z * vec2.y, - vec1.z * vec2.x - vec1.x * vec2.z, - vec1.x * vec2.y - vec1.y * vec2.x); } - - friend inline CVector operator*(const CVector& in, float fMul) - { return CVector(in.x * fMul, in.y * fMul, in.z * fMul); } - friend inline CVector operator+(const CVector& vec1, const CVector& vec2) - { return CVector(vec1.x + vec2.x, vec1.y + vec2.y, vec1.z + vec2.z); } - friend inline CVector operator+(const CVector& vec1, const RwV3d& vec2) - { return CVector(vec1.x + vec2.x, vec1.y + vec2.y, vec1.z + vec2.z); } - friend inline CVector operator-(const CVector& vec1, const CVector& vec2) - { return CVector(vec1.x - vec2.x, vec1.y - vec2.y, vec1.z - vec2.z); } - friend inline CVector operator-(const CVector& vec1, const RwV3d& vec2) - { return CVector(vec1.x - vec2.x, vec1.y - vec2.y, vec1.z - vec2.z); } - friend inline CVector operator-(const CVector& vec) - { return CVector(-vec.x, -vec.y, -vec.z); } -}; - -class CVector2D -{ -public: - float x, y; - - CVector2D() - {} - - constexpr CVector2D(float fX, float fY) - : x(fX), y(fY) - {} - - CVector2D& operator+=(const CVector2D& vec) - { x += vec.x; y += vec.y; - return *this; } - CVector2D& operator-=(const CVector2D& vec) - { x -= vec.x; y -= vec.y; - return *this; } - - inline float Magnitude() const - { return sqrt(x * x + y * y); } - inline constexpr float MagnitudeSqr() const - { return x * x + y * y; } - inline CVector2D& Normalize() - { float fInvLen = 1.0f / Magnitude(); x *= fInvLen; y *= fInvLen; return *this; } - - friend inline float DotProduct(const CVector2D& vec1, const CVector2D& vec2) - { return vec1.x * vec2.x + vec1.x * vec2.y; } - - friend inline CVector2D operator*(const CVector2D& in, float fMul) - { return CVector2D(in.x * fMul, in.y * fMul); } - friend inline CVector2D operator+(const CVector2D& vec1, const CVector2D& vec2) - { return CVector2D(vec1.x + vec2.x, vec1.y + vec2.y); } - friend inline CVector2D operator-(const CVector2D& vec1, const CVector2D& vec2) - { return CVector2D(vec1.x - vec2.x, vec1.y - vec2.y); } - friend inline CVector2D operator-(const CVector2D& vec) - { return CVector2D(-vec.x, -vec.y); } -}; - -class CMatrix -{ -private: - RwMatrix matrix; - RwMatrix* pMatrix = nullptr; - BOOL haveRwMatrix = FALSE; - -public: - inline CMatrix() = default; - - inline CMatrix(RwMatrix* pMatrix, bool bHasMatrix=false) - { Attach(pMatrix, bHasMatrix); } - - inline CMatrix(const CMatrix& theMatrix) - : matrix(theMatrix.matrix) - {} - - inline CMatrix(const CVector& vecRight, const CVector& vecUp, const CVector& vecAt, const CVector& vecPos) - { - matrix.right.x = vecRight.x; - matrix.right.y = vecRight.y; - matrix.right.z = vecRight.z; - - matrix.up.x = vecUp.x; - matrix.up.y = vecUp.y; - matrix.up.z = vecUp.z; - - matrix.at.x = vecAt.x; - matrix.at.y = vecAt.y; - matrix.at.z = vecAt.z; - - matrix.pos.x = vecPos.x; - matrix.pos.y = vecPos.y; - matrix.pos.z = vecPos.z; - } - - inline ~CMatrix() - { if ( haveRwMatrix && pMatrix ) - RwMatrixDestroy(pMatrix); } - - inline CMatrix& operator*=(const CMatrix& right) - { - CVector vright(this->matrix.right.x * right.matrix.right.x + this->matrix.right.y * right.matrix.up.x + this->matrix.right.z * right.matrix.at.x + right.matrix.pos.x, - this->matrix.right.x * right.matrix.right.y + this->matrix.right.y * right.matrix.up.y + this->matrix.right.z * right.matrix.at.y + right.matrix.pos.y, - this->matrix.right.x * right.matrix.right.z + this->matrix.right.y * right.matrix.up.z + this->matrix.right.z * right.matrix.at.z + right.matrix.pos.z); - CVector vup(this->matrix.up.x * right.matrix.right.x + this->matrix.up.y * right.matrix.up.x + this->matrix.up.z * right.matrix.at.x + right.matrix.pos.x, - this->matrix.up.x * right.matrix.right.y + this->matrix.up.y * right.matrix.up.y + this->matrix.up.z * right.matrix.at.y + right.matrix.pos.y, - this->matrix.up.x * right.matrix.right.z + this->matrix.up.y * right.matrix.up.z + this->matrix.up.z * right.matrix.at.z + right.matrix.pos.z); - CVector vat(this->matrix.at.x * right.matrix.right.x + this->matrix.at.y * right.matrix.up.x + this->matrix.at.z * right.matrix.at.x + right.matrix.pos.x, - this->matrix.at.x * right.matrix.right.y + this->matrix.at.y * right.matrix.up.y + this->matrix.at.z * right.matrix.at.y + right.matrix.pos.y, - this->matrix.at.x * right.matrix.right.z + this->matrix.at.y * right.matrix.up.z + this->matrix.at.z * right.matrix.at.z + right.matrix.pos.z); - CVector vpos(this->matrix.pos.x * right.matrix.right.x + this->matrix.pos.y * right.matrix.up.x + this->matrix.pos.z * right.matrix.at.x + right.matrix.pos.x, - this->matrix.pos.x * right.matrix.right.y + this->matrix.pos.y * right.matrix.up.y + this->matrix.pos.z * right.matrix.at.y + right.matrix.pos.y, - this->matrix.pos.x * right.matrix.right.z + this->matrix.pos.y * right.matrix.up.z + this->matrix.pos.z * right.matrix.at.z + right.matrix.pos.z); - - GetRight() = vright; - GetUp() = vup; - GetAt() = vat; - GetPos() = vpos; - - return *this; - } - - friend inline CMatrix operator*(const CMatrix& Rot1, const CMatrix& Rot2) - { return CMatrix( CVector(Rot1.matrix.right.x * Rot2.matrix.right.x + Rot1.matrix.right.y * Rot2.matrix.up.x + Rot1.matrix.right.z * Rot2.matrix.at.x + Rot2.matrix.pos.x, - Rot1.matrix.right.x * Rot2.matrix.right.y + Rot1.matrix.right.y * Rot2.matrix.up.y + Rot1.matrix.right.z * Rot2.matrix.at.y + Rot2.matrix.pos.y, - Rot1.matrix.right.x * Rot2.matrix.right.z + Rot1.matrix.right.y * Rot2.matrix.up.z + Rot1.matrix.right.z * Rot2.matrix.at.z + Rot2.matrix.pos.z), - CVector(Rot1.matrix.up.x * Rot2.matrix.right.x + Rot1.matrix.up.y * Rot2.matrix.up.x + Rot1.matrix.up.z * Rot2.matrix.at.x + Rot2.matrix.pos.x, - Rot1.matrix.up.x * Rot2.matrix.right.y + Rot1.matrix.up.y * Rot2.matrix.up.y + Rot1.matrix.up.z * Rot2.matrix.at.y + Rot2.matrix.pos.y, - Rot1.matrix.up.x * Rot2.matrix.right.z + Rot1.matrix.up.y * Rot2.matrix.up.z + Rot1.matrix.up.z * Rot2.matrix.at.z + Rot2.matrix.pos.z), - CVector(Rot1.matrix.at.x * Rot2.matrix.right.x + Rot1.matrix.at.y * Rot2.matrix.up.x + Rot1.matrix.at.z * Rot2.matrix.at.x + Rot2.matrix.pos.x, - Rot1.matrix.at.x * Rot2.matrix.right.y + Rot1.matrix.at.y * Rot2.matrix.up.y + Rot1.matrix.at.z * Rot2.matrix.at.y + Rot2.matrix.pos.y, - Rot1.matrix.at.x * Rot2.matrix.right.z + Rot1.matrix.at.y * Rot2.matrix.up.z + Rot1.matrix.at.z * Rot2.matrix.at.z + Rot2.matrix.pos.z), - CVector(Rot1.matrix.pos.x * Rot2.matrix.right.x + Rot1.matrix.pos.y * Rot2.matrix.up.x + Rot1.matrix.pos.z * Rot2.matrix.at.x + Rot2.matrix.pos.x, - Rot1.matrix.pos.x * Rot2.matrix.right.y + Rot1.matrix.pos.y * Rot2.matrix.up.y + Rot1.matrix.pos.z * Rot2.matrix.at.y + Rot2.matrix.pos.y, - Rot1.matrix.pos.x * Rot2.matrix.right.z + Rot1.matrix.pos.y * Rot2.matrix.up.z + Rot1.matrix.pos.z * Rot2.matrix.at.z + Rot2.matrix.pos.z)); }; - - friend inline CVector operator*(const CMatrix& matrix, const CVector& vec) - { return CVector(matrix.matrix.up.x * vec.y + matrix.matrix.right.x * vec.x + matrix.matrix.at.x * vec.z + matrix.matrix.pos.x, - matrix.matrix.up.y * vec.y + matrix.matrix.right.y * vec.x + matrix.matrix.at.y * vec.z + matrix.matrix.pos.y, - matrix.matrix.up.z * vec.y + matrix.matrix.right.z * vec.x + matrix.matrix.at.z * vec.z + matrix.matrix.pos.z); }; - - inline CVector& GetRight() - { return *reinterpret_cast(&matrix.right); } - inline CVector& GetUp() - { return *reinterpret_cast(&matrix.up); } - inline CVector& GetAt() - { return *reinterpret_cast(&matrix.at); } - inline CVector& GetPos() - { return *reinterpret_cast(&matrix.pos); } - - inline const CVector& GetRight() const - { return *reinterpret_cast(&matrix.right); } - inline const CVector& GetUp() const - { return *reinterpret_cast(&matrix.up); } - inline const CVector& GetAt() const - { return *reinterpret_cast(&matrix.at); } - inline const CVector& GetPos() const - { return *reinterpret_cast(&matrix.pos); } - - inline void SetTranslateOnly(float fX, float fY, float fZ) - { matrix.pos.x = fX; matrix.pos.y = fY; matrix.pos.z = fZ; } - - inline void SetRotateX(float fAngle) - { SetRotateXOnly(fAngle); matrix.pos.x = 0.0f; matrix.pos.y = 0.0f; matrix.pos.z = 0.0f; } - inline void SetRotateY(float fAngle) - { SetRotateYOnly(fAngle); matrix.pos.x = 0.0f; matrix.pos.y = 0.0f; matrix.pos.z = 0.0f; } - inline void SetRotateZ(float fAngle) - { SetRotateZOnly(fAngle); matrix.pos.x = 0.0f; matrix.pos.y = 0.0f; matrix.pos.z = 0.0f; } - inline void SetRotate(float fAngleX, float fAngleY, float fAngleZ) - { SetRotateOnly(fAngleX, fAngleY, fAngleZ); matrix.pos.x = 0.0f; matrix.pos.y = 0.0f; matrix.pos.z = 0.0f; } - inline void SetTranslate(float fX, float fY, float fZ) - { matrix.right.x = 1.0f; matrix.right.y = 0.0f; matrix.right.z = 0.0f; - matrix.up.x = 0.0f; matrix.up.y = 1.0f; matrix.up.z = 0.0f; - matrix.at.x = 0.0f; matrix.at.y = 0.0f; matrix.at.z = 1.0f; - SetTranslateOnly(fX, fY, fZ); } - - inline void SetUnity() - { - matrix.right.x = 1.0f; matrix.right.y = 0.0f; matrix.right.z = 0.0f; - matrix.up.x = 0.0f; matrix.up.y = 1.0f; matrix.up.z = 0.0f; - matrix.at.x = 0.0f; matrix.at.y = 0.0f; matrix.at.z = 1.0f; - matrix.pos.x = 0.0f; matrix.pos.y = 0.0f; matrix.pos.z = 0.0f; - } - - inline void SetScale(float fScale) - { - matrix.right.x = fScale; matrix.right.y = 0.0f; matrix.right.z = 0.0f; - matrix.up.x = 0.0f; matrix.up.y = fScale; matrix.up.z = 0.0f; - matrix.at.x = 0.0f; matrix.at.y = 0.0f; matrix.at.z = fScale; - matrix.pos.x = 0.0f; matrix.pos.y = 0.0f; matrix.pos.z = 0.0f; - } - - inline void RotateX(float fAngle) - { - CMatrix RotationMatrix; - RotationMatrix.SetRotateX(fAngle); - *this *= RotationMatrix; - } - - inline void RotateY(float fAngle) - { - CMatrix RotationMatrix; - RotationMatrix.SetRotateY(fAngle); - *this *= RotationMatrix; - } - - inline void RotateZ(float fAngle) - { - CMatrix RotationMatrix; - RotationMatrix.SetRotateZ(fAngle); - *this *= RotationMatrix; - } - - inline void Rotate(float fAngleX, float fAngleY, float fAngleZ) - { - CMatrix RotationMatrix; - RotationMatrix.SetRotate(fAngleX, fAngleY, fAngleZ); - *this *= RotationMatrix; - } - - inline void SetRotateXOnly(float fAngle) - { - matrix.right.x = 1.0f; - matrix.right.y = 0.0f; - matrix.right.z = 0.0f; - - matrix.up.x = 0.0f; - matrix.up.y = cos(fAngle); - matrix.up.z = sin(fAngle); - - matrix.at.x = 0.0f; - matrix.at.y = -sin(fAngle); - matrix.at.z = cos(fAngle); - } - - inline void SetRotateYOnly(float fAngle) - { - matrix.right.x = cos(fAngle); - matrix.right.y = 0.0f; - matrix.right.z = sin(fAngle); - - matrix.up.x = 0.0f; - matrix.up.y = 1.0f; - matrix.up.z = 0.0f; - - matrix.at.x = -sin(fAngle); - matrix.at.y = 0.0f; - matrix.at.z = cos(fAngle); - } - - inline void SetRotateZOnly(float fAngle) - { - matrix.at.x = 0.0f; - matrix.at.y = 0.0f; - matrix.at.z = 1.0f; - - matrix.up.x = -sin(fAngle); - matrix.up.y = cos(fAngle); - matrix.up.z = 0.0f; - - matrix.right.x = cos(fAngle); - matrix.right.y = sin(fAngle); - matrix.right.z = 0.0f; - } - - inline void SetRotateOnly(float fAngleX, float fAngleY, float fAngleZ) - { - matrix.right.x = cos(fAngleZ) * cos(fAngleY) - sin(fAngleZ) * sin(fAngleX) * sin(fAngleY); - matrix.right.y = cos(fAngleZ) * sin(fAngleX) * sin(fAngleY) + sin(fAngleZ) * cos(fAngleY); - matrix.right.z = -cos(fAngleX) * sin(fAngleY); - - matrix.up.x = -sin(fAngleZ) * cos(fAngleX); - matrix.up.y = cos(fAngleZ) * cos(fAngleX); - matrix.up.z = sin(fAngleX); - - matrix.at.x = sin(fAngleZ) * sin(fAngleX) * cos(fAngleY) + cos(fAngleZ) * sin(fAngleY); - matrix.at.y = sin(fAngleZ) * sin(fAngleY) - cos(fAngleZ) * sin(fAngleX) * cos(fAngleY); - matrix.at.z = cos(fAngleX) * cos(fAngleY); - } - - inline void Attach(RwMatrix* pMatrix, bool bHasMatrix) - { - if ( this->pMatrix && haveRwMatrix ) - RwMatrixDestroy(this->pMatrix); - - this->pMatrix = pMatrix; - haveRwMatrix = bHasMatrix; - - Update(); - } - - inline void AttachRw(RwMatrix* pMatrix, bool bHasMatrix) - { - if ( this->pMatrix && haveRwMatrix ) - RwMatrixDestroy(this->pMatrix); - - this->pMatrix = pMatrix; - haveRwMatrix = bHasMatrix; - - UpdateRW(); - } - - inline void Detach() - { - if ( pMatrix ) - { - if ( haveRwMatrix ) - RwMatrixDestroy(pMatrix); - pMatrix = nullptr; - } - } - - inline void UpdateRW() const - { - if ( pMatrix ) - UpdateRwMatrix(pMatrix); - } - - inline void Update() - { - UpdateMatrix(pMatrix); - } - - inline void UpdateMatrix(RwMatrix* pMatrix) - { - matrix.right = pMatrix->right; - matrix.up = pMatrix->up; - matrix.at = pMatrix->at; - matrix.pos = pMatrix->pos; - } - - inline void UpdateRwMatrix(RwMatrix* pMatrix) const - { - pMatrix->right = matrix.right; - pMatrix->up = matrix.up; - pMatrix->at = matrix.at; - pMatrix->pos = matrix.pos; - RwMatrixUpdate(pMatrix); - } - - inline void CopyToRwMatrix(RwMatrix* pMatrix) const - { - pMatrix->right = this->pMatrix->right; - pMatrix->up = this->pMatrix->up; - pMatrix->at = this->pMatrix->at; - pMatrix->pos = this->pMatrix->pos; - RwMatrixUpdate(pMatrix); - } - - inline void CopyOnlyMatrix(const CMatrix& from) - { - matrix = from.matrix; - } -}; - -#endif \ No newline at end of file diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index aa0c4a9..f639571 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -611,22 +611,22 @@ bool GetCurrentZoneLockedOrUnlocked_Steam(float fPosX, float fPosY) return true; } -CRGBA* CRGBA::BlendGangColour(uint8_t r, uint8_t g, uint8_t b, uint8_t a) +CRGBA* __fastcall BlendGangColour(CRGBA* pThis, void*, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { const double colourIntensity = std::min( static_cast(pCurrZoneInfo->ZoneColour.a) / 120.0, 1.0 ); - *this = CRGBA(BlendSqr( HudColour[3], CRGBA(r, g, b), colourIntensity ), a); - return this; + *pThis = CRGBA(BlendSqr( HudColour[3], CRGBA(r, g, b), colourIntensity ), a); + return pThis; } static bool bColouredZoneNames; -CRGBA* CRGBA::BlendGangColour_Dynamic(uint8_t r, uint8_t g, uint8_t b, uint8_t a) +CRGBA* __fastcall BlendGangColour_Dynamic(CRGBA* pThis, void*, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { if ( bColouredZoneNames ) { - return BlendGangColour(r, g, b, a); + return BlendGangColour(pThis, nullptr, r, g, b, a); } - *this = CRGBA(HudColour[3], a); - return this; + *pThis = CRGBA(HudColour[3], a); + return pThis; } void SunAndMoonFarClip() @@ -2719,7 +2719,7 @@ BOOL InjectDelayedPatches_10() Patch(0x58ADBE, 0x0E75); Patch(0x58ADC5, 0x0775); - InjectHook(0x58ADE4, &CRGBA::BlendGangColour_Dynamic); + InjectHook(0x58ADE4, &BlendGangColour_Dynamic); if ( bHasDebugMenu ) { @@ -3154,7 +3154,7 @@ BOOL InjectDelayedPatches_11() Patch(0x58B58E, 0x0E75); Patch(0x58B595, 0x0775); - InjectHook(0x58B5B4, &CRGBA::BlendGangColour); + InjectHook(0x58B5B4, &BlendGangColour); } else if ( INIoption == 0 ) { @@ -3325,7 +3325,7 @@ BOOL InjectDelayedPatches_Steam() Patch(0x598F65, 0x0C75); Patch(0x598F6B, 0x0675); - InjectHook(0x598F87, &CRGBA::BlendGangColour); + InjectHook(0x598F87, &BlendGangColour); } else if ( INIoption == 0 ) { diff --git a/SilentPatchSA/SilentPatchSA.vcxproj b/SilentPatchSA/SilentPatchSA.vcxproj index 278bfbc..5716f8f 100644 --- a/SilentPatchSA/SilentPatchSA.vcxproj +++ b/SilentPatchSA/SilentPatchSA.vcxproj @@ -224,6 +224,7 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio + @@ -235,7 +236,6 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio - diff --git a/SilentPatchSA/SilentPatchSA.vcxproj.filters b/SilentPatchSA/SilentPatchSA.vcxproj.filters index c8e965c..ad472dd 100644 --- a/SilentPatchSA/SilentPatchSA.vcxproj.filters +++ b/SilentPatchSA/SilentPatchSA.vcxproj.filters @@ -122,9 +122,6 @@ Header Files - - Header Files - Header Files @@ -173,6 +170,9 @@ Header Files\Utils + + Header Files + diff --git a/SilentPatchVC/ModelInfoVC.h b/SilentPatchVC/ModelInfoVC.h index ff87aa6..fe32b02 100644 --- a/SilentPatchVC/ModelInfoVC.h +++ b/SilentPatchVC/ModelInfoVC.h @@ -1,6 +1,5 @@ #pragma once -#include "General.h" #include #include diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index cbbd303..e84842d 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -1,10 +1,10 @@ #include "StdAfx.h" +#include "Maths.h" #include "Timer.h" #include "Utils/Patterns.h" #include "Common.h" #include "Common_ddraw.h" -#include "General.h" #include "ModelInfoVC.h" #include diff --git a/SilentPatchVC/SilentPatchVC.vcxproj b/SilentPatchVC/SilentPatchVC.vcxproj index d773a7a..b08a458 100644 --- a/SilentPatchVC/SilentPatchVC.vcxproj +++ b/SilentPatchVC/SilentPatchVC.vcxproj @@ -173,7 +173,7 @@ - + diff --git a/SilentPatchVC/SilentPatchVC.vcxproj.filters b/SilentPatchVC/SilentPatchVC.vcxproj.filters index 1b1557e..d855db8 100644 --- a/SilentPatchVC/SilentPatchVC.vcxproj.filters +++ b/SilentPatchVC/SilentPatchVC.vcxproj.filters @@ -24,9 +24,6 @@ Header Files - - Header Files - Header Files @@ -57,6 +54,9 @@ Header Files + + Header Files +