Raised This Month: $32 Target: $400
 8% 

Extension: Help with events hooking?


Post New Thread Reply   
 
Thread Tools Display Modes
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
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 06-14-2020 , 20:20   Re: Extension: Help with events hooking?
Reply With Quote #2

Quote:
Is there any way to catch Events instead of hooking IGameEventManager2::FireEvent?
Look at the SDK.

Quote:
Pretty sure the reason is SourceMod with his FreeEvent(IGameEvent*)
If SM is incorrectly telling the server to free an event, then the server itself would be crashing without your extension.
Fyren is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-14-2020 , 21:36   Re: Extension: Help with events hooking?
Reply With Quote #3

There’s not much that can be done about this, https://bugs.alliedmods.net/show_bug.cgi?id=5097 has all the details.

The extension API is designed only to extend the API for plugins - a better design would be to add natives/forwards for the functionality you can’t do in a plugin (if anything) then have the event hook (and the entity input stuff you PM’d about) live plugin-side.

Between SDKTools, DHooks, and SourceScramble, there is very little that warrants writing and maintaining new bespoke extensions.
__________________
asherkin is offline
KillMan
Member
Join Date: Aug 2017
Location: Belarus
Old 06-14-2020 , 23:36   Re: Extension: Help with events hooking?
Reply With Quote #4

Quote:
Originally Posted by Fyren View Post
Look at the SDK.
Looks like I'm blind. Help me a bit? XD

@asherkin, also im sure that i don't need a 0.1kb plugin on my server to work xD

P.S. Used EventListener from Interface. Looks like its working now...

Last edited by KillMan; 06-15-2020 at 00:51.
KillMan is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:44.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode