Skip to content

Fix multiple damage instances in certain areas during explosions #4187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Client/multiplayer_sa/CMultiplayerSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,7 @@ void CMultiplayerSA::InitHooks()
InitHooks_ObjectStreamerOptimization();

InitHooks_Postprocess();
InitHooks_Explosions();
}

// Used to store copied pointers for explosions in the FxSystem
Expand Down
1 change: 1 addition & 0 deletions Client/multiplayer_sa/CMultiplayerSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class CMultiplayerSA : public CMultiplayer
void InitHooks_ObjectStreamerOptimization();
void InitHooks_Postprocess();
void InitHooks_DeviceSelection();
void InitHooks_Explosions();
CRemoteDataStorage* CreateRemoteDataStorage();
void DestroyRemoteDataStorage(CRemoteDataStorage* pData);
void AddRemoteDataStorage(CPlayerPed* pPed, CRemoteDataStorage* pData);
Expand Down
78 changes: 78 additions & 0 deletions Client/multiplayer_sa/CMultiplayerSA_Explosions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: multiplayer_sa/CMultiplayerSA_Explosions.cpp
*
* Multi Theft Auto is available from https://www.multitheftauto.com/
*
*****************************************************************************/
#include "StdInc.h"

//////////////////////////////////////////////////////////////////////////////////////////
//
// CWorld::TriggerExplosion
//
// Fix for multiple damage instances in certain areas during explosions (GH #4125, #997)
//
//////////////////////////////////////////////////////////////////////////////////////////
#define HOOKPOS_CWorld_TriggerExplosion 0x56B82E
#define HOOKSIZE_CWorld_TriggerExplosion 8
static constexpr std::uintptr_t RETURN_CWorld_TriggerExplosion = 0x56B836;
static void _declspec(naked) HOOK_CWorld_TriggerExplosion()
{
_asm
{
mov [esp+1Ch-8h], eax
mov [esp+1Ch-10h], ecx

// Call SetNextScanCode
mov ecx, 0x4072E0
call ecx
mov ecx, esi

// SetNextScanCode overwrote the result of the cmp instruction at 0x56B82A
// so we call it again
cmp esi, eax
jmp RETURN_CWorld_TriggerExplosion
}
}

#define HOOKPOS_CWorld_TriggerExplosionSectorList 0x5677F4
#define HOOKSIZE_CWorld_TriggerExplosionSectorList 7
static constexpr std::uintptr_t RETURN_CWorld_TriggerExplosionSectorList = 0x5677FB;
static constexpr std::uintptr_t SKIP_CWorld_TriggerExplosionSectorList = 0x568473;
static void _declspec(naked) HOOK_CWorld_TriggerExplosionSectorList()
{
_asm
{
// check entity->m_nScanCode == CWorld::ms_nCurrentScanCode
mov ecx, dword ptr ds:[0xB7CD78]
cmp [esi+2Ch], ecx
jz skip

// set entity current scan code
mov [esi+2Ch], ecx

mov al, [esi+36h]
and al, 7
cmp al, 4
jmp RETURN_CWorld_TriggerExplosionSectorList

skip:
jmp SKIP_CWorld_TriggerExplosionSectorList
}
}

//////////////////////////////////////////////////////////////////////////////////////////
//
// CMultiplayerSA::InitHooks_Explosions
//
// Setup hooks
//
//////////////////////////////////////////////////////////////////////////////////////////
void CMultiplayerSA::InitHooks_Explosions()
{
EZHookInstall(CWorld_TriggerExplosion);
EZHookInstall(CWorld_TriggerExplosionSectorList);
}
Loading