Skip to content

Commit 0e2b203

Browse files
authored
Split grenade collision from weapon collision (PR #2716)
1 parent ff5e653 commit 0e2b203

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

Client/multiplayer_sa/CMultiplayerSA.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,7 @@ void CMultiplayerSA::InitHooks()
15721572

15731573
InitHooks_Streaming();
15741574
InitHooks_FrameRateFixes();
1575+
InitHooks_ProjectileCollisionFix();
15751576
InitHooks_ObjectStreamerOptimization();
15761577
}
15771578

Client/multiplayer_sa/CMultiplayerSA.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class CMultiplayerSA : public CMultiplayer
7777
void InitHooks_FixLineOfSightArgs();
7878
void InitHooks_Streaming();
7979
void InitHooks_FrameRateFixes();
80+
void InitHooks_ProjectileCollisionFix();
8081
void InitHooks_ObjectStreamerOptimization();
8182
CRemoteDataStorage* CreateRemoteDataStorage();
8283
void DestroyRemoteDataStorage(CRemoteDataStorage* pData);
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: multiplayer_sa/CMultiplayerSA_ProjectileCollisionFix.cpp
6+
*
7+
* Multi Theft Auto is available from https://www.multitheftauto.com/
8+
*
9+
*****************************************************************************/
10+
11+
#include "StdInc.h"
12+
#include "../game_sa/CColModelSA.h"
13+
14+
static CColModelSAInterface colModelGrenade;
15+
16+
static void InitializeGrenadeColModel()
17+
{
18+
// CColModel::CColModel
19+
((CColModelSAInterface*(__thiscall*)(CColModelSAInterface*))(0x40FB60))(&colModelGrenade);
20+
21+
colModelGrenade.m_bounds.m_vecMin = CVector(-0.25f, -0.25f, -0.25f);
22+
colModelGrenade.m_bounds.m_vecMax = CVector(0.25f, 0.25f, 0.25f);
23+
24+
colModelGrenade.m_sphere.m_center = CVector(0, 0, 0);
25+
colModelGrenade.m_sphere.m_radius = 0.25f;
26+
27+
// CColModel::AllocateData
28+
((void(__thiscall*)(CColModelSAInterface*, int, int, int, int, int, int))(0x40F870))(&colModelGrenade, 1, 0, 0, 0, 0, 0);
29+
30+
// CColSphere::Set
31+
((void(__thiscall*)(CColSphereSA*, float, CVector&, unsigned char, char, unsigned char))(0x40FD10))(
32+
&colModelGrenade.m_data->m_spheres[0],
33+
colModelGrenade.m_sphere.m_radius * 0.75f,
34+
colModelGrenade.m_sphere.m_center,
35+
56, 0, 255);
36+
}
37+
38+
#define HOOKPOS_CTempColModels__Initialise 0x5BB87D
39+
#define HOOKSIZE_CTempColModels__Initialise 0x6
40+
static const unsigned int RETURN_CTempColModels__Initialise = 0x5BB883;
41+
static void _declspec(naked) HOOK_CTempColModels__Initialise()
42+
{
43+
_asm {
44+
mov ds:[0x968FE4], edx
45+
46+
call InitializeGrenadeColModel
47+
48+
jmp RETURN_CTempColModels__Initialise
49+
}
50+
}
51+
52+
#define HOOKPOS_CFileLoader__LoadWeaponObject 0x5B401E
53+
#define HOOKSIZE_CFileLoader__LoadWeaponObject 0x5
54+
static const unsigned int RETURN_CFileLoader__LoadWeaponObject = 0x5B4023;
55+
static void _declspec(naked) HOOK_CFileLoader__LoadWeaponObject()
56+
{
57+
_asm {
58+
mov eax, [esp+0x8]
59+
cmp eax, 342
60+
je grenade
61+
cmp eax, 343
62+
je grenade
63+
cmp eax, 344
64+
je grenade
65+
cmp eax, 363
66+
je grenade
67+
68+
push 0x968FD0
69+
jmp RETURN_CFileLoader__LoadWeaponObject
70+
71+
grenade:
72+
push offset colModelGrenade
73+
jmp RETURN_CFileLoader__LoadWeaponObject
74+
}
75+
}
76+
77+
void CMultiplayerSA::InitHooks_ProjectileCollisionFix()
78+
{
79+
EZHookInstall(CTempColModels__Initialise);
80+
EZHookInstall(CFileLoader__LoadWeaponObject);
81+
82+
MemCpy((void*)0x7383FF, "\xE9\x5E\x01\x00\x00", 5);
83+
MemSet((void*)0x738404, 0x90, 0x9C);
84+
}

0 commit comments

Comments
 (0)