#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS
#include <windows.h>
#include <string>
#include <assert.h>
#include <process.h>
#include "SAMPFUNCS_API.h"
#include "game_api\game_api.h"
SAMPFUNCS *SF = new SAMPFUNCS();
#define HOOKPOS_CEventDamage__AffectsPed 0x4B35A0
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool ProcessDamageEvent(CEventDamageSAInterface* xevent, CPedSAInterface* affectsPed)
{
if (xevent)
{
CPools *pPools = GAME->GetPools();
CPed * pPed = pPools->GetPed((DWORD *)affectsPed);
CEntity * pInflictor = NULL;
if (pPed == PEDSELF)
{
CEventDamage* pEvent = GAME->GetEventList()->GetEventDamage(xevent);
if ((pEvent->GetWeaponUsed() >= 22 && pEvent->GetWeaponUsed() <= 34))
{
SF->getSAMP()->getChat()->AddChatMessage( D3DCOLOR_XRGB(51, 204, 255),
"Event!!!!! BodyPart: %d", pEvent->GetPedPieceType());
pEvent->SetDamageReason(EDamageReason::OTHER);
ProcessWarning = false;
}
pEvent->Destroy();
}
}
return true;
}
CPedSAInterface* affectsPed = 0;
CEventDamageSAInterface* event = 0;
void _declspec(naked) HOOK_CEventDamage__AffectsPed()
{
_asm
{
push esi
mov esi, [esp + 8]
mov affectsPed, esi
mov event, ecx
pop esi
pushad
}
if (ProcessDamageEvent(event, affectsPed))
{
_asm
{
popad
sub esp, 0xC
push esi
mov esi, ecx
mov ecx, HOOKPOS_CEventDamage__AffectsPed
add ecx, 6
jmp ecx
}
}
else
{
_asm
{
popad
xor eax, eax
retn 4
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void __stdcall mainloop( void )
{
static bool init = false;
if (!init)
{
if (GAME == nullptr) return;
if (GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME) return;
if(!SF->getSAMP()->IsInitialized()) return;
SF->getGame()->createHook((void*)HOOKPOS_CEventDamage__AffectsPed, HOOK_CEventDamage__AffectsPed, DETOUR_TYPE_JMP, 6);
init = true;
}
}
bool WINAPI DllMain( HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved )
{
switch ( dwReasonForCall )
{
case DLL_PROCESS_ATTACH:
SF->initPlugin( mainloop, hModule );
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}