Fixed escalators crash - SA 1.0

This commit is contained in:
Silent 2016-04-24 20:37:14 +02:00
parent fcd036595b
commit 27d80800a0
3 changed files with 78 additions and 0 deletions

View File

@ -109,3 +109,21 @@ RwCamera* CShadowCamera::Update(CEntity* pEntity)
} }
return m_pCamera; return m_pCamera;
} }
std::vector<CEntity*> 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;
}

View File

@ -556,10 +556,42 @@ public:
RwCamera* Update(CEntity* pEntity); RwCamera* Update(CEntity* pEntity);
}; };
#include <vector>
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<CEntity*> ms_entitiesToRemove;
public:
void SwitchOffNoRemove();
};
RpAtomic* ShadowCameraRenderCB(RpAtomic* pAtomic, void* pData); RpAtomic* ShadowCameraRenderCB(RpAtomic* pAtomic, void* pData);
static_assert(sizeof(CEntity) == 0x38, "Wrong size: CEntity"); static_assert(sizeof(CEntity) == 0x38, "Wrong size: CEntity");
static_assert(sizeof(CPhysical) == 0x138, "Wrong size: CPhysical"); static_assert(sizeof(CPhysical) == 0x138, "Wrong size: CPhysical");
static_assert(sizeof(CObject) == 0x17C, "Wrong size: CObject"); static_assert(sizeof(CObject) == 0x17C, "Wrong size: CObject");
static_assert(sizeof(CEscalator) == 0x150, "Wrong size: CEscalator");
#endif #endif

View File

@ -199,6 +199,8 @@ static void (*ShutdownRenderWare)();
static void (*DoSunAndMoon)(); static void (*DoSunAndMoon)();
static void (*sub_5DA6A0)(void*, void*, void*, void*); static void (*sub_5DA6A0)(void*, void*, void*, void*);
auto WorldRemove = AddressByVersion<void(*)(CEntity*)>(0x563280, 0, 0);
// SA variables // SA variables
void** rwengine = *AddressByVersion<void***>(0x58FFC0, 0x53F032, 0x48C194, 0x48B167, 0x48B167); void** rwengine = *AddressByVersion<void***>(0x58FFC0, 0x53F032, 0x48C194, 0x48B167, 0x48B167);
@ -844,6 +846,23 @@ void* CollisionData_NewAndInit( size_t size )
return mem; 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 <xnamath.h> #include <xnamath.h>
static void* pNVCShader = nullptr; static void* pNVCShader = nullptr;
@ -2529,6 +2548,7 @@ BOOL InjectDelayedPatches_Steam()
static char aNoDesktopMode[64]; static char aNoDesktopMode[64];
void Patch_SA_10() void Patch_SA_10()
{ {
using namespace MemoryVP; using namespace MemoryVP;
@ -2893,6 +2913,14 @@ void Patch_SA_10()
InjectHook(0x745A81, GetNumVideoModes_Retrieve); 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 // Fixed police scanner names
char* pScannerNames = *(char**)0x4E72D4; char* pScannerNames = *(char**)0x4E72D4;
strcpy(pScannerNames + (8*113), "WESTP"); strcpy(pScannerNames + (8*113), "WESTP");