|
| 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