#define HOOKPOS_CEventDamage__AffectsPed 0x4B35A0
bool ProcessDamageEvent(CEventDamageSAInterface* event, CPedSAInterface* affectsPed)
{
if (event)
{
SF->Log("Event!");
CPools *pPools = GAME->GetPools();
CPed * pPed = pPools->GetPed((DWORD *)affectsPed);
CEntity * pInflictor = NULL;
if (pPed)
{
// This creates a CEventDamageSA for us
CEventDamage* pEvent = GAME->GetEventList()->GetEventDamage(event);
pEvent->SetDamageReason(EDamageReason::OTHER);
// Destroy the CEventDamageSA (so we dont get a leak)
pEvent->Destroy();
// Finally, return
}
}
return true;
}
CPedSAInterface* affectsPed = 0;
CEventDamageSAInterface* event = 0;
void _declspec(naked) HOOK_CEventDamage__AffectsPed()
{
/*
004B35A0 83EC 0C SUB ESP,0C
004B35A3 56 PUSH ESI
004B35A4 8BF1 MOV ESI,ECX
*/
_asm
{
push esi
mov esi, [esp + 8]
mov affectsPed, esi // store the ped
mov event, ecx // store the event pointer
pop esi
pushad
}
if (ProcessDamageEvent(event, affectsPed))
{
// they want the damage to happen!
_asm
{
popad
sub esp, 0xC // replacement code
push esi
mov esi, ecx
mov ecx, HOOKPOS_CEventDamage__AffectsPed
add ecx, 6
jmp ecx
}
}
else
{
// they want the player to escape unscathed
_asm
{
popad
xor eax, eax
retn 4 // return from the function
}
}
}
void CALLBACK mainloop()
{
static bool init = false;
if (!init)
{
if (GAME == nullptr)
return;
if (GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME)
return;
// HookInstall ( HOOKPOS_CEventDamage__AffectsPed, (DWORD)HOOK_CEventDamage__AffectsPed, 6 );
SF->getGame()->createHook((void*)HOOKPOS_CEventDamage__AffectsPed, HOOK_CEventDamage__AffectsPed, DETOUR_TYPE_JMP, 6);
SF->Log("Plugin initiliazed!");
init = true;
}
}