From 7cbd4a59bfb13295ebdaa06cccc823c8c563c5b3 Mon Sep 17 00:00:00 2001 From: Silent Date: Fri, 22 Apr 2016 20:45:33 +0200 Subject: [PATCH] Car explosion crash with multimonitor - 1.0/newsteam r2 --- SilentPatchSA/ModelInfoSA.h | 39 ++++++++++++++------- SilentPatchSA/SilentPatchSA.cpp | 61 +++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 13 deletions(-) diff --git a/SilentPatchSA/ModelInfoSA.h b/SilentPatchSA/ModelInfoSA.h index cc099bd..ed52c5c 100644 --- a/SilentPatchSA/ModelInfoSA.h +++ b/SilentPatchSA/ModelInfoSA.h @@ -50,20 +50,33 @@ typedef struct char name[0x18]; } ColModelFileHeader; -typedef struct +class CColData { - WORD numColSpheres; - WORD numColBoxes; - WORD numColTriangles; - BYTE ucNumWheels; - BYTE pad3; - CColSphere* pColSpheres; - CColBox* pColBoxes; - void* pSuspensionLines; - void* pUnknown; - void* pColTriangles; - void* pColTrianglePlanes; -} CColData; +public: + unsigned short m_wNumSpheres; + unsigned short m_wNumBoxes; + unsigned short m_wNumTriangles; + unsigned char m_bNumLines; + unsigned char m_bFlags; + CColSphere *m_pSpheres; + CColBox *m_pBoxes; + /* possibly was the union with some unknown yet collision model which was used for CMtruck only. + union{ + CColLine *m_pLines; + CMtruckColLine *m_pMtruckLines; + }; + */ + void *m_pLines; + void *m_pVertices; + void *m_pTriangles; + void *m_pTrianglePlanes; + unsigned int m_dwNumShadowTriangles; + unsigned int m_dwNumShadowVertices; + void *m_pShadowVertices; + void *m_pShadowTriangles; +}; + +static_assert( sizeof(CColData) == 0x30, "Wrong size: CColData" ); class CColModel { diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index b053239..a8282e0 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -808,6 +808,28 @@ void MSAAText( char* buffer, const char*, DWORD level ) sprintf( buffer, "%ux", 1 << level ); } +static void* (*orgMemMgrMalloc)(RwUInt32, RwUInt32); +void* CollisionData_MallocAndInit( RwUInt32 size, RwUInt32 hint ) +{ + CColData* mem = (CColData*)orgMemMgrMalloc( size, hint ); + + mem->m_bFlags = 0; + mem->m_dwNumShadowTriangles = mem->m_dwNumShadowVertices =0; + mem->m_pShadowVertices = mem->m_pShadowTriangles = nullptr; + + return mem; +} + +static void* (*orgNewAlloc)(size_t); +void* CollisionData_NewAndInit( size_t size ) +{ + CColData* mem = (CColData*)orgNewAlloc( size ); + + mem->m_bFlags = 0; + + return mem; +} + #include static void* pNVCShader = nullptr; @@ -2822,6 +2844,19 @@ void Patch_SA_10() // Fixed car collisions - car you're hitting gets proper damage now InjectHook(0x5428EA, FixedCarDamage, PATCH_CALL); + + // Car explosion crash with multimonitor + // Unitialized collision data breaking stencil shadows + int pMemMgrMalloc = 0x40F8D3; + orgMemMgrMalloc = (void*(*)(RwUInt32,RwUInt32))(*(int*)(pMemMgrMalloc+1) + pMemMgrMalloc + 5); + InjectHook(0x40F8D3, CollisionData_MallocAndInit); + + int pNewAlloc = 0x40F74C; + orgNewAlloc = (void*(*)(size_t))(*(int*)(pNewAlloc+1) + pNewAlloc + 5); + InjectHook(0x40F74C, CollisionData_NewAndInit); + InjectHook(0x40F81D, CollisionData_NewAndInit); + + // Fixed police scanner names char* pScannerNames = *(char**)0x4E72D4; strcpy(pScannerNames + (8*113), "WESTP"); @@ -3684,6 +3719,19 @@ void Patch_SA_NewSteam_r2() Nop(0x5538D0, 2); InjectHook(0x5538D2, FixedCarDamage_Newsteam, PATCH_CALL); + + // Car explosion crash with multimonitor + // Unitialized collision data breaking stencil shadows + int pMemMgrMalloc = DynBaseAddress(0x41A661); + orgMemMgrMalloc = (void*(*)(RwUInt32,RwUInt32))(*(int*)(pMemMgrMalloc+1) + pMemMgrMalloc + 5); + InjectHook(0x41A661, CollisionData_MallocAndInit); + + int pNewAlloc = DynBaseAddress(0x41A4CC); + orgNewAlloc = (void*(*)(size_t))(*(int*)(pNewAlloc+1) + pNewAlloc + 5); + InjectHook(0x41A4CC, CollisionData_NewAndInit); + InjectHook(0x41A5A9, CollisionData_NewAndInit); + + // Proper aspect ratios static const float f43 = 4.0f/3.0f, f54 = 5.0f/4.0f, f169 = 16.0f/9.0f; Patch(0x73424B, &f169); @@ -3821,6 +3869,19 @@ void Patch_SA_NewSteam_r2_lv() Nop(0x553800, 2); InjectHook(0x553802, FixedCarDamage_Newsteam, PATCH_CALL); + + // Car explosion crash with multimonitor + // Unitialized collision data breaking stencil shadows + int pMemMgrMalloc = DynBaseAddress(0x41A661); + orgMemMgrMalloc = (void*(*)(RwUInt32,RwUInt32))(*(int*)(pMemMgrMalloc+1) + pMemMgrMalloc + 5); + InjectHook(0x41A661, CollisionData_MallocAndInit); + + int pNewAlloc = DynBaseAddress(0x41A4CC); + orgNewAlloc = (void*(*)(size_t))(*(int*)(pNewAlloc+1) + pNewAlloc + 5); + InjectHook(0x41A4CC, CollisionData_NewAndInit); + InjectHook(0x41A5A9, CollisionData_NewAndInit); + + // Proper aspect ratios static const float f43 = 4.0f/3.0f, f54 = 5.0f/4.0f, f169 = 16.0f/9.0f; Patch(0x73414B, &f169);