Skip to content

Commit bfda2b0

Browse files
Synchronize changes from 1.6 master branch [ci skip]
3bce408 Fix multiple damage instances in certain areas during explosions (#4187)
2 parents 5ce0b77 + 3bce408 commit bfda2b0

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

Client/multiplayer_sa/CMultiplayerSA.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,7 @@ void CMultiplayerSA::InitHooks()
15951595
InitHooks_ObjectStreamerOptimization();
15961596

15971597
InitHooks_Postprocess();
1598+
InitHooks_Explosions();
15981599
}
15991600

16001601
// Used to store copied pointers for explosions in the FxSystem

Client/multiplayer_sa/CMultiplayerSA.h

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class CMultiplayerSA : public CMultiplayer
8181
void InitHooks_ObjectStreamerOptimization();
8282
void InitHooks_Postprocess();
8383
void InitHooks_DeviceSelection();
84+
void InitHooks_Explosions();
8485
CRemoteDataStorage* CreateRemoteDataStorage();
8586
void DestroyRemoteDataStorage(CRemoteDataStorage* pData);
8687
void AddRemoteDataStorage(CPlayerPed* pPed, CRemoteDataStorage* pData);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: multiplayer_sa/CMultiplayerSA_Explosions.cpp
6+
*
7+
* Multi Theft Auto is available from https://www.multitheftauto.com/
8+
*
9+
*****************************************************************************/
10+
#include "StdInc.h"
11+
12+
//////////////////////////////////////////////////////////////////////////////////////////
13+
//
14+
// CWorld::TriggerExplosion
15+
//
16+
// Fix for multiple damage instances in certain areas during explosions (GH #4125, #997)
17+
//
18+
//////////////////////////////////////////////////////////////////////////////////////////
19+
#define HOOKPOS_CWorld_TriggerExplosion 0x56B82E
20+
#define HOOKSIZE_CWorld_TriggerExplosion 8
21+
static constexpr std::uintptr_t RETURN_CWorld_TriggerExplosion = 0x56B836;
22+
static void _declspec(naked) HOOK_CWorld_TriggerExplosion()
23+
{
24+
_asm
25+
{
26+
mov [esp+1Ch-8h], eax
27+
mov [esp+1Ch-10h], ecx
28+
29+
// Call SetNextScanCode
30+
mov ecx, 0x4072E0
31+
call ecx
32+
mov ecx, esi
33+
34+
// SetNextScanCode overwrote the result of the cmp instruction at 0x56B82A
35+
// so we call it again
36+
cmp esi, eax
37+
jmp RETURN_CWorld_TriggerExplosion
38+
}
39+
}
40+
41+
#define HOOKPOS_CWorld_TriggerExplosionSectorList 0x5677F4
42+
#define HOOKSIZE_CWorld_TriggerExplosionSectorList 7
43+
static constexpr std::uintptr_t RETURN_CWorld_TriggerExplosionSectorList = 0x5677FB;
44+
static constexpr std::uintptr_t SKIP_CWorld_TriggerExplosionSectorList = 0x568473;
45+
static void _declspec(naked) HOOK_CWorld_TriggerExplosionSectorList()
46+
{
47+
_asm
48+
{
49+
// check entity->m_nScanCode == CWorld::ms_nCurrentScanCode
50+
mov ecx, dword ptr ds:[0xB7CD78]
51+
cmp [esi+2Ch], ecx
52+
jz skip
53+
54+
// set entity current scan code
55+
mov [esi+2Ch], ecx
56+
57+
mov al, [esi+36h]
58+
and al, 7
59+
cmp al, 4
60+
jmp RETURN_CWorld_TriggerExplosionSectorList
61+
62+
skip:
63+
jmp SKIP_CWorld_TriggerExplosionSectorList
64+
}
65+
}
66+
67+
//////////////////////////////////////////////////////////////////////////////////////////
68+
//
69+
// CMultiplayerSA::InitHooks_Explosions
70+
//
71+
// Setup hooks
72+
//
73+
//////////////////////////////////////////////////////////////////////////////////////////
74+
void CMultiplayerSA::InitHooks_Explosions()
75+
{
76+
EZHookInstall(CWorld_TriggerExplosion);
77+
EZHookInstall(CWorld_TriggerExplosionSectorList);
78+
}

0 commit comments

Comments
 (0)