From 27d80800a0fa5efb97c23cabf7b2465844fde81e Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 24 Apr 2016 20:37:14 +0200 Subject: [PATCH] Fixed escalators crash - SA 1.0 --- SilentPatchSA/GeneralSA.cpp | 18 ++++++++++++++++++ SilentPatchSA/GeneralSA.h | 32 ++++++++++++++++++++++++++++++++ SilentPatchSA/SilentPatchSA.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/SilentPatchSA/GeneralSA.cpp b/SilentPatchSA/GeneralSA.cpp index 5b90e31..20f3263 100644 --- a/SilentPatchSA/GeneralSA.cpp +++ b/SilentPatchSA/GeneralSA.cpp @@ -108,4 +108,22 @@ RwCamera* CShadowCamera::Update(CEntity* pEntity) RwCameraEndUpdate(m_pCamera); } return m_pCamera; +} + +std::vector CEscalator::ms_entitiesToRemove; +void CEscalator::SwitchOffNoRemove() +{ + if ( !m_bExists ) + return; + + for ( int i = 0, j = field_7C + field_80 + field_84; i < j; ++i ) + { + if ( m_pSteps[i] != nullptr ) + { + ms_entitiesToRemove.push_back( m_pSteps[i] ); + m_pSteps[i] = nullptr; + } + } + + m_bExists = false; } \ No newline at end of file diff --git a/SilentPatchSA/GeneralSA.h b/SilentPatchSA/GeneralSA.h index 716104a..450731f 100644 --- a/SilentPatchSA/GeneralSA.h +++ b/SilentPatchSA/GeneralSA.h @@ -556,10 +556,42 @@ public: RwCamera* Update(CEntity* pEntity); }; +#include + +class CEscalator +{ +private: + CVector field_0; + CVector field_C; + CVector field_18; + CVector field_24; + CMatrix m_matrix; + bool field_78; + bool m_bExists; + bool field_7A; + int field_7C; + int field_80; + int field_84; + char gap_88[8]; + CVector field_90; + float field_9C; + float field_A0; + CEntity* m_pMainEntity; + CEntity* m_pSteps[42]; + +public: + static std::vector ms_entitiesToRemove; + +public: + void SwitchOffNoRemove(); +}; + + RpAtomic* ShadowCameraRenderCB(RpAtomic* pAtomic, void* pData); static_assert(sizeof(CEntity) == 0x38, "Wrong size: CEntity"); static_assert(sizeof(CPhysical) == 0x138, "Wrong size: CPhysical"); static_assert(sizeof(CObject) == 0x17C, "Wrong size: CObject"); +static_assert(sizeof(CEscalator) == 0x150, "Wrong size: CEscalator"); #endif \ No newline at end of file diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index ad5a055..42f30b7 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -199,6 +199,8 @@ static void (*ShutdownRenderWare)(); static void (*DoSunAndMoon)(); static void (*sub_5DA6A0)(void*, void*, void*, void*); +auto WorldRemove = AddressByVersion(0x563280, 0, 0); + // SA variables void** rwengine = *AddressByVersion(0x58FFC0, 0x53F032, 0x48C194, 0x48B167, 0x48B167); @@ -844,6 +846,23 @@ void* CollisionData_NewAndInit( size_t size ) return mem; } + +static void (*orgEscalatorsUpdate)(); +void UpdateEscalators() +{ + if ( !CEscalator::ms_entitiesToRemove.empty() ) + { + for ( auto it : CEscalator::ms_entitiesToRemove ) + { + WorldRemove( it ); + delete it; + } + CEscalator::ms_entitiesToRemove.clear(); + } + orgEscalatorsUpdate(); +} + + #include static void* pNVCShader = nullptr; @@ -2529,6 +2548,7 @@ BOOL InjectDelayedPatches_Steam() static char aNoDesktopMode[64]; + void Patch_SA_10() { using namespace MemoryVP; @@ -2893,6 +2913,14 @@ void Patch_SA_10() InjectHook(0x745A81, GetNumVideoModes_Retrieve); + // Fixed escalators crash + int pUpdateEscalators = 0x7185B5; + orgEscalatorsUpdate = (void(*)())(*(int*)(pUpdateEscalators+1) + pUpdateEscalators + 5); + InjectHook(0x7185B5, UpdateEscalators); + InjectHook(0x71791F, &CEscalator::SwitchOffNoRemove); + + + // Fixed police scanner names char* pScannerNames = *(char**)0x4E72D4; strcpy(pScannerNames + (8*113), "WESTP");