From abb1db6b444ffa73d4f40c150bff484cf5027bfd Mon Sep 17 00:00:00 2001 From: Silent Date: Mon, 4 Aug 2014 14:30:16 +0200 Subject: [PATCH] Mostly ready for multiple EXEs compatibility TODO: RW calls --- SAFix/AudioHardwareSA.h | 3 --- SAFix/GeneralSA.cpp | 15 +++++---------- SAFix/ModelInfoSA.cpp | 11 ++++++----- SAFix/ModelInfoSA.h | 8 ++++---- SAFix/PNGFile.cpp | 5 +++-- SAFix/SilentPatchSA.cpp | 10 +++++++--- SAFix/StdAfxSA.h | 1 + SAFix/VehicleSA.cpp | 9 ++++++--- SAFix/VehicleSA.h | 2 +- SilentPatch/MemoryMgr.h | 16 ++++++++++++++++ 10 files changed, 49 insertions(+), 31 deletions(-) diff --git a/SAFix/AudioHardwareSA.h b/SAFix/AudioHardwareSA.h index 855ede2..2af683a 100644 --- a/SAFix/AudioHardwareSA.h +++ b/SAFix/AudioHardwareSA.h @@ -128,9 +128,6 @@ public: class CAEWaveDecoder : public CAEStreamingDecoder { private: - unsigned short nNumChannels; - unsigned short nBitRate; - unsigned int nSampleRate; unsigned int nDataSize; unsigned int nOffsetToData; //bool bInitialised; diff --git a/SAFix/GeneralSA.cpp b/SAFix/GeneralSA.cpp index 3c01d06..4e557b2 100644 --- a/SAFix/GeneralSA.cpp +++ b/SAFix/GeneralSA.cpp @@ -2,18 +2,13 @@ #include "GeneralSA.h" // Wrappers -WRAPPER bool CalcScreenCoors(const CVector& vecIn, CVector* vecOut) { WRAPARG(vecIn); WRAPARG(vecOut); EAXJMP(0x71DAB0); } -WRAPPER void LoadingScreenLoadingFile(const char* pText) { WRAPARG(pText); EAXJMP(0x5B3680); } +static void* EntityRender = AddressByVersion(0x534310, 0, 0); +WRAPPER void CEntity::Render() { VARJMP(EntityRender); } -WRAPPER void CEntity::UpdateRW() { EAXJMP(0x446F90); } -WRAPPER void CEntity::RegisterReference(CEntity** pAddress) { WRAPARG(pAddress); EAXJMP(0x571B70); } -WRAPPER void CEntity::CleanUpOldReference(CEntity** pAddress) { WRAPARG(pAddress); EAXJMP(0x571A00); } -WRAPPER void CEntity::Render() { EAXJMP(0x534310); } +static RwTexture*& ms_pRemapTexture = **AddressByVersion(0x59F1BD, 0, 0); +static unsigned char* ms_currentCol = *AddressByVersion(0x4C84C8, 0, 0); -static RwTexture*& ms_pRemapTexture = *(RwTexture**)0xB4E47C; -static unsigned char* ms_currentCol = *(unsigned char**)0x4C84C8; - -WRAPPER RpAtomic* SetEditableMaterialsCB(RpAtomic* pMaterial, void* pData) { WRAPARG(pMaterial); WRAPARG(pData); EAXJMP(0x4C83E0); } +auto SetEditableMaterialsCB = AddressByVersion(0x4C83E0, 0, 0); static void SetVehicleColour(unsigned char primaryColour, unsigned char secondaryColour, unsigned char tertiaryColour, unsigned char quaternaryColour) { diff --git a/SAFix/ModelInfoSA.cpp b/SAFix/ModelInfoSA.cpp index 591f920..7d22cb0 100644 --- a/SAFix/ModelInfoSA.cpp +++ b/SAFix/ModelInfoSA.cpp @@ -1,12 +1,13 @@ #include "StdAfxSA.h" #include "ModelInfoSA.h" -WRAPPER void CBaseModelInfo::Shutdown() { EAXJMP(0x4C4D50); } +static void* BaseModelInfoShutdown = AddressByVersion(0x4C4D50, 0, 0); +WRAPPER void CBaseModelInfo::Shutdown() { VARJMP(BaseModelInfoShutdown); } -WRAPPER RwTexture* CCustomCarPlateMgr::CreatePlateTexture(const char* pText, signed char nDesign) { EAXJMP(0x6FDEA0); } -WRAPPER bool CCustomCarPlateMgr::GeneratePlateText(char* pBuf, int nLen) { EAXJMP(0x6FD5B0); } -WRAPPER signed char CCustomCarPlateMgr::GetMapRegionPlateDesign() { EAXJMP(0x6FD7A0); } -WRAPPER void CCustomCarPlateMgr::SetupMaterialPlatebackTexture(RpMaterial* pMaterial, signed char nDesign) { EAXJMP(0x6FDE50); } +RwTexture* (*CCustomCarPlateMgr::CreatePlateTexture)(const char* pText, signed char nDesign) = AddressByVersion(0x6FDEA0, 0, 0); +bool (*CCustomCarPlateMgr::GeneratePlateText)(char* pBuf, int nLen) = AddressByVersion(0x6FD5B0, 0, 0); +signed char (*CCustomCarPlateMgr::GetMapRegionPlateDesign)() = AddressByVersion(0x6FD7A0, 0, 0); +void (*CCustomCarPlateMgr::SetupMaterialPlatebackTexture)(RpMaterial* pMaterial, signed char nDesign) = AddressByVersion(0x6FDE50, 0, 0); void CVehicleModelInfo::Shutdown() { diff --git a/SAFix/ModelInfoSA.h b/SAFix/ModelInfoSA.h index 0cc3b52..403ca94 100644 --- a/SAFix/ModelInfoSA.h +++ b/SAFix/ModelInfoSA.h @@ -292,10 +292,10 @@ private: //static signed char m_nCurPlateDesign; public: - static RwTexture* CreatePlateTexture(const char* pText, signed char nDesign); - static bool GeneratePlateText(char* pBuf, int nLen); - static signed char GetMapRegionPlateDesign(); - static void SetupMaterialPlatebackTexture(RpMaterial* pMaterial, signed char nDesign); + static RwTexture* (*CreatePlateTexture)(const char* pText, signed char nDesign); + static bool (*GeneratePlateText)(char* pBuf, int nLen); + static signed char (*GetMapRegionPlateDesign)(); + static void (*SetupMaterialPlatebackTexture)(RpMaterial* pMaterial, signed char nDesign); static void SetupClump(RpClump* pClump, RpMaterial** pMatsArray); static void SetupClumpAfterVehicleUpgrade(RpClump* pClump, RpMaterial** pMatsArray, signed char nDesign); diff --git a/SAFix/PNGFile.cpp b/SAFix/PNGFile.cpp index 49e3177..ffc4027 100644 --- a/SAFix/PNGFile.cpp +++ b/SAFix/PNGFile.cpp @@ -24,10 +24,11 @@ RwTexture* CPNGFile::ReadFromFile(const char* pFileName) RwTexture* CPNGFile::ReadFromMemory(const void* pMemory, unsigned int nLen) { + static BYTE* pMem = AddressByVersion(0x7CF9CA, 0, 0); RwTexture* pTexture = nullptr; // TOOO: EXEs - MemoryVP::Patch(0x7CF9CA, rwSTREAMMEMORY); + MemoryVP::Patch(pMem, rwSTREAMMEMORY); RwMemory PNGMemory; PNGMemory.start = const_cast(static_cast(pMemory)); @@ -48,7 +49,7 @@ RwTexture* CPNGFile::ReadFromMemory(const void* pMemory, unsigned int nLen) RwImageDestroy(pImage); } - MemoryVP::Patch(0x7CF9CA, rwSTREAMFILENAME); + MemoryVP::Patch(pMem, rwSTREAMFILENAME); return pTexture; } \ No newline at end of file diff --git a/SAFix/SilentPatchSA.cpp b/SAFix/SilentPatchSA.cpp index 8348cab..7933699 100644 --- a/SAFix/SilentPatchSA.cpp +++ b/SAFix/SilentPatchSA.cpp @@ -77,6 +77,9 @@ CZoneInfo*& pCurrZoneInfo = **AddressByVersion(0x58ADB1, 0, 0); CRGBA* HudColour = *AddressByVersion(0x58ADF6, 0, 0); unsigned char* ZonesVisited = *AddressByVersion(0x57216A, 0, 0) - 9; +float& m_fDNBalanceParam = **AddressByVersion(0x4A9062, 0, 0); +RpLight*& pAmbient = **AddressByVersion(0x5BA53A, 0, 0); + CLinkListSA& ms_weaponPedsForPC = **AddressByVersion**>(0x53EACA, 0, 0); CLinkListSA& m_alphaList = **AddressByVersion**>(0x733A4D, 0, 0); @@ -537,10 +540,9 @@ void SetShader(RxD3D9InstanceData* pInstData) { if ( bRenderNVC ) { - // TODO: Daynight balance var D3DMATRIX outMat; - float fEnvVars[2] = { *(float*)0x8D12C0, RpMaterialGetColor(pInstData->material)->alpha * (1.0f/255.0f) }; - RwRGBAReal* AmbientLight = RpLightGetColor(*(RpLight**)0xC886E8); + float fEnvVars[2] = { m_fDNBalanceParam, RpMaterialGetColor(pInstData->material)->alpha * (1.0f/255.0f) }; + RwRGBAReal* AmbientLight = RpLightGetColor(pAmbient); // Normalise the balance if ( fEnvVars[0] < 0.0f ) @@ -551,6 +553,7 @@ void SetShader(RxD3D9InstanceData* pInstData) RwD3D9SetVertexShader(pNVCShader); _rwD3D9VSSetActiveWorldMatrix(RwFrameGetLTM(RpAtomicGetFrame(pRenderedAtomic))); + //_rwD3D9VSSetActiveWorldMatrix(RwFrameGetMatrix(RpAtomicGetFrame(pRenderedAtomic))); _rwD3D9VSGetComposedTransformMatrix(&outMat); RwD3D9SetVertexShaderConstant(0, &outMat, 4); @@ -1307,6 +1310,7 @@ __forceinline void Patch_SA_10() // PS2 SUN!!!!!!!!!!!!!!!!! static const float fSunMult = (1050.0f * 0.95f) / 1500.0f; + // TODO: Use min() Nop(0x6FB17C, 3); Patch(0x6FC5B0, &fSunMult); //Patch(0x6FB172, 0x0BEB); diff --git a/SAFix/StdAfxSA.h b/SAFix/StdAfxSA.h index 91089ae..14422d5 100644 --- a/SAFix/StdAfxSA.h +++ b/SAFix/StdAfxSA.h @@ -2,6 +2,7 @@ #pragma warning(disable:4401) // member is bit field #pragma warning(disable:4733) // handler not registered as safe handler #pragma warning(disable:4725) // instruction may be inaccurate on some Pentiums +#pragma warning(disable:4201) // nonstandard extension used: nameless struct/union #define WIN32_LEAN_AND_MEAN #define _CRT_SECURE_NO_WARNINGS diff --git a/SAFix/VehicleSA.cpp b/SAFix/VehicleSA.cpp index 3ab4c18..f51cfc1 100644 --- a/SAFix/VehicleSA.cpp +++ b/SAFix/VehicleSA.cpp @@ -3,9 +3,12 @@ #include "VehicleSA.h" #include "TimerSA.h" -WRAPPER void CVehicle::SetComponentAtomicAlpha(RpAtomic* pAtomic, int nAlpha) { WRAPARG(pAtomic); WRAPARG(nAlpha); EAXJMP(0x6D2960); } -WRAPPER void CVehicle::Render() { EAXJMP(0x6D0E60); } -WRAPPER bool CVehicle::IsLawEnforcementVehicle() { EAXJMP(0x6D2370); } +void (*CVehicle::SetComponentAtomicAlpha)(RpAtomic* pAtomic, int nAlpha) = AddressByVersion(0x6D2960, 0, 0); + +static void* varVehicleRender = AddressByVersion(0x6D0E60, 0, 0); +WRAPPER void CVehicle::Render() { VARJMP(varVehicleRender); } +static void* varIsLawEnforcementVehicle = AddressByVersion(0x6D2370, 0, 0); +WRAPPER bool CVehicle::IsLawEnforcementVehicle() { VARJMP(varIsLawEnforcementVehicle); } static RwObject* GetCurrentAtomicObjectCB(RwObject* pObject, void* data) { diff --git a/SAFix/VehicleSA.h b/SAFix/VehicleSA.h index 305a0a7..dafed0d 100644 --- a/SAFix/VehicleSA.h +++ b/SAFix/VehicleSA.h @@ -115,7 +115,7 @@ public: bool IsLawEnforcementVehicle(); - static void SetComponentAtomicAlpha(RpAtomic* pAtomic, int nAlpha); + static void (*SetComponentAtomicAlpha)(RpAtomic* pAtomic, int nAlpha); }; class NOVMT CAutomobile : public CVehicle diff --git a/SilentPatch/MemoryMgr.h b/SilentPatch/MemoryMgr.h index dc07df1..2c61cf2 100644 --- a/SilentPatch/MemoryMgr.h +++ b/SilentPatch/MemoryMgr.h @@ -29,6 +29,12 @@ inline bool* GetEuropean() return &bEuropean; } +inline void* GetDummy() +{ + static DWORD dwDummy; + return &dwDummy; +} + // This function initially detects SA version then chooses the address basing on game version template inline T AddressByVersion(DWORD address10, DWORD address11, DWORD addressSteam) @@ -64,10 +70,16 @@ inline T AddressByVersion(DWORD address10, DWORD address11, DWORD addressSteam) *bEuropean = false; } } + switch ( *bVer ) { case 1: assert(address11); + + // Safety measures - if null, return dummy var pointer to prevent a crash + if ( !address11 ) + return (T)GetDummy(); + // Adjust to EU if needed if ( *bEuropean && address11 > 0x746FA0 ) { @@ -79,6 +91,10 @@ inline T AddressByVersion(DWORD address10, DWORD address11, DWORD addressSteam) return (T)address11; case 2: assert(addressSteam); + // Safety measures - if null, return dummy var pointer to prevent a crash + if ( !addressSteam ) + return (T)GetDummy(); + return (T)addressSteam; default: assert(address10);