Car explosion crash with multimonitor - 1.0/newsteam r2

This commit is contained in:
Silent 2016-04-22 20:45:33 +02:00
parent 36ca4ec879
commit 7cbd4a59bf
2 changed files with 87 additions and 13 deletions

View file

@ -50,20 +50,33 @@ typedef struct
char name[0x18]; char name[0x18];
} ColModelFileHeader; } ColModelFileHeader;
typedef struct class CColData
{ {
WORD numColSpheres; public:
WORD numColBoxes; unsigned short m_wNumSpheres;
WORD numColTriangles; unsigned short m_wNumBoxes;
BYTE ucNumWheels; unsigned short m_wNumTriangles;
BYTE pad3; unsigned char m_bNumLines;
CColSphere* pColSpheres; unsigned char m_bFlags;
CColBox* pColBoxes; CColSphere *m_pSpheres;
void* pSuspensionLines; CColBox *m_pBoxes;
void* pUnknown; /* possibly was the union with some unknown yet collision model which was used for CMtruck only.
void* pColTriangles; union{
void* pColTrianglePlanes; CColLine *m_pLines;
} CColData; 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 class CColModel
{ {

View file

@ -808,6 +808,28 @@ void MSAAText( char* buffer, const char*, DWORD level )
sprintf( buffer, "%ux", 1 << 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 <xnamath.h> #include <xnamath.h>
static void* pNVCShader = nullptr; static void* pNVCShader = nullptr;
@ -2822,6 +2844,19 @@ void Patch_SA_10()
// Fixed car collisions - car you're hitting gets proper damage now // Fixed car collisions - car you're hitting gets proper damage now
InjectHook(0x5428EA, FixedCarDamage, PATCH_CALL); 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 // Fixed police scanner names
char* pScannerNames = *(char**)0x4E72D4; char* pScannerNames = *(char**)0x4E72D4;
strcpy(pScannerNames + (8*113), "WESTP"); strcpy(pScannerNames + (8*113), "WESTP");
@ -3684,6 +3719,19 @@ void Patch_SA_NewSteam_r2()
Nop(0x5538D0, 2); Nop(0x5538D0, 2);
InjectHook(0x5538D2, FixedCarDamage_Newsteam, PATCH_CALL); 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 // Proper aspect ratios
static const float f43 = 4.0f/3.0f, f54 = 5.0f/4.0f, f169 = 16.0f/9.0f; static const float f43 = 4.0f/3.0f, f54 = 5.0f/4.0f, f169 = 16.0f/9.0f;
Patch<const void*>(0x73424B, &f169); Patch<const void*>(0x73424B, &f169);
@ -3821,6 +3869,19 @@ void Patch_SA_NewSteam_r2_lv()
Nop(0x553800, 2); Nop(0x553800, 2);
InjectHook(0x553802, FixedCarDamage_Newsteam, PATCH_CALL); 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 // Proper aspect ratios
static const float f43 = 4.0f/3.0f, f54 = 5.0f/4.0f, f169 = 16.0f/9.0f; static const float f43 = 4.0f/3.0f, f54 = 5.0f/4.0f, f169 = 16.0f/9.0f;
Patch<const void*>(0x73414B, &f169); Patch<const void*>(0x73414B, &f169);