View Single Post
Author Message
KillMan
Member
Join Date: Aug 2017
Location: Belarus
Old 06-14-2020 , 17:22   Extension: Help with events hooking?
Reply With Quote #1

Is there any way to catch Events instead of hooking IGameEventManager2::FireEvent?
Crashing while doing anything with ALREADY hooked event in any SP (maybe not with any).
Pretty sure the reason is SourceMod with his FreeEvent(IGameEvent*)

P.S. Using PRE hook.
Example of my code:
Code:
...
IGameEventManager2 *gameevents = NULL;
SH_DECL_HOOK2(IGameEventManager2, FireEvent, SH_NOATTRIB, 0, bool, IGameEvent *, bool);

bool Sample::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
    GET_V_IFACE_CURRENT(GetEngineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
    SH_ADD_HOOK(IGameEventManager2, FireEvent, gameevents, SH_MEMBER(this, &Sample::OnEventFire), false);
    return true;
}

void Sample::SDK_OnUnload()
{
    SH_REMOVE_HOOK(IGameEventManager2, FireEvent, gameevents, SH_MEMBER(this, &Sample::OnEventFire), false);
}

bool Sample::OnEventFire(IGameEvent *pEventOriginal, bool bDontBroadcast)
{
    IGameEvent *pEvent = gameevents->DuplicateEvent(pEventOriginal); // First attempt to fix (lol), but you can imagine this is from function. Btw crashing there too.
    if (!pEvent) RETURN_META_VALUE(MRES_IGNORED, false);
    const char *name = pEvent->GetName(); // <= Crashing. Error lower.
    gameevents->FreeEvent(pEvent); // Continue of attempt
    RETURN_META_VALUE(MRES_IGNORED, true);
}
Accelerator:
Code:
Sample.ext.2.csgo.so!Sample::OnEventFire(IGameEvent*, bool)
Sample.ext.2.csgo.so!fastdelegate::FastDelegate2<IGameEvent*, bool, bool>::operator()(IGameEvent*, bool) const [FastDelegate.h:1079 + 0x16]
Sample.ext.2.csgo.so!__SourceHook_FHCls_IGameEventManager2FireEvent0::CMyDelegateImpl::Call(IGameEvent*, bool) [extension.cpp:30 + 0x24]
sourcemod.2.csgo.so!__SourceHook_FHCls_IGameEventManager2FireEvent0::Func [EventManager.cpp:41 + 0x26]
P.P.S. Hooks in my *.SP, crashing when client/bot connects, maybe spawns
HookEvent("player_spawn", Player_Spawn_Post, EventHookMode_Post);
HookEvent("player_death", Player_Death_Pre, EventHookMode_Pre);
HookEvent("round_start", Round_Start_PostNoCopy, EventHookMode_PostNoCopy);
HookEvent("round_end", Round_End_PostNoCopy, EventHookMode_PostNoCopy);
HookEvent("player_team", Player_Team_Pre, EventHookMode_Pre);
HookEvent("player_disconnect", Player_Disconnect_Pre, EventHookMode_Pre);
HookEvent("cs_win_panel_match", OnMatchEnd_PostNoCopy, EventHookMode_PostNoCopy);

Last edited by KillMan; 06-14-2020 at 17:59. Reason: P.S., P.P.S.
KillMan is offline