Raised This Month: $12 Target: $400
 3% 

Blocking events


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 12-26-2016 , 20:09   Blocking events
Reply With Quote #1

So yeah, like the title says I want to block some events from happening, I tried calling FireEvent function from IGameEventManager2 by getting the interface of IGameEventManager2 like this:
PHP Code:
SH_DECL_HOOK2(IGameEventManager2FireEventSH_NOATTRIB0boolIGameEvent *, bool);

.....

bool CSample::SDK_OnMetamodLoad(ISmmAPI *ismmchar *errorsize_t maxlenbool late)
{
    
// Getting dem interfaces!
    
GET_V_IFACE_CURRENT(GetEngineFactoryg_pGameEventManagerIGameEventManager2INTERFACEVERSION_GAMEEVENTSMANAGER2);
    
    if (!
g_pGameEventManager)
        
rootconsole->ConsolePrint("IGameEventManager2 interface was not found.");    

    
SH_ADD_HOOK(IGameEventManager2FireEventg_pGameEventManagerSH_STATIC(Hook_OnFireEvent), true);
//    g_pGameEventManager->AddListener(this, "player_death", true); This is not needed since I want to block the actual event...

    
return true;
}

void CSample::SDK_OnUnload()
{    
    
SH_REMOVE_HOOK(IGameEventManager2FireEventg_pGameEventManagerSH_STATIC(Hook_OnFireEvent), true);
}

bool Hook_OnFireEvent(IGameEvent *eventbool dontBroadcast)
{
    
int clientattacker;

    const 
char *pEventName event->GetName();

    if (
strcmp(pEventName"player_death") == 0)
    {
        
client event->GetInt();
        
attacker event->GetInt();        

        
rootconsole->ConsolePrint("[DEBUG] Event: 'player_death' Fired.");
        
rootconsole->ConsolePrint("[DEBUG] client='%d', attacker='%d'."clientattacker);
    }

    
RETURN_META_VALUE(MRES_IGNOREDtrue);

but this doesnt seem to work, why?

EDIT: I know that this example show the 'post' hook which has nothing to do with blocking event, basically I want to block and call event in the same time, so I'll call the pre and post FireEvent. and btw this is for CS:GO.

EDIT 2: Okay, so after looking at the EventManager from Sourcemod core (which I dunno why I didnt look before lol, thought it doesnt exist) I figured out the way it works, so basically you have to add a listener.

It worked just fine for the pre-event hook, however it didnt work for the post-event hook and it crashes the server on map load without any error

PHP Code:
#include "main.h"

CSample g_Extension;    
SMEXT_LINK(&g_Extension);

SH_DECL_HOOK2(IGameEventManager2FireEventSH_NOATTRIB0boolIGameEvent *, bool);

IGameEventManager2 *g_pGameEventManager 0;

void CSample::SDK_OnAllLoaded()
{    
    
SH_ADD_HOOK(IGameEventManager2FireEventg_pGameEventManagerSH_STATIC(Hook_OnPreFireEvent), false);                // This works just fine
//    SH_ADD_HOOK(IGameEventManager2, FireEvent, g_pGameEventManager, SH_STATIC(Hook_OnFireEvent), true);                    // This crashes the server on map load without any error...

    
g_pGameEventManager->AddListener(this"player_death"true);
}

void CSample::SDK_OnUnload()
{    
    
SH_REMOVE_HOOK(IGameEventManager2FireEventg_pGameEventManagerSH_STATIC(Hook_OnPreFireEvent), false);                    
//    SH_REMOVE_HOOK(IGameEventManager2, FireEvent, g_pGameEventManager, SH_STATIC(Hook_OnFireEvent), true);

    
g_pGameEventManager->RemoveListener(this);        
}

bool CSample::SDK_OnMetamodLoad(ISmmAPI *ismmchar *errorsize_t maxlenbool late)
{
    
// Getting dem interfaces!    
    
GET_V_IFACE_CURRENT(GetEngineFactoryg_pGameEventManagerIGameEventManager2INTERFACEVERSION_GAMEEVENTSMANAGER2);
    
    if (!
g_pGameEventManager)
        
rootconsole->ConsolePrint("IGameEventManager2 interface was not found.");        

    return 
true;
}

void CSample::FireGameEvent(IGameEvent *event)
{
}

int CSample::GetEventDebugID()
{
    return 
EVENT_DEBUG_ID_INIT
}

bool Hook_OnPreFireEvent(IGameEvent *eventbool dontBroadcast)
{
    if (!
event)
    {
        
RETURN_META_VALUE(MRES_IGNOREDfalse);
    }

    
int clientattacker;

    const 
char *pEventName event->GetName();

    if (
strcmp(pEventName"player_death") == 0)
    {
        
client event->GetInt();
        
attacker event->GetInt();        

        
rootconsole->ConsolePrint("[DEBUG] Pre-Event: 'player_death' Fired.");
        
rootconsole->ConsolePrint("[DEBUG] client='%d', attacker='%d'."clientattacker);        
    }

    
RETURN_META_VALUE(MRES_IGNOREDtrue);
}

bool Hook_OnFireEvent(IGameEvent *eventbool dontBroadcast)
{
    if (!
event)
    {
        
RETURN_META_VALUE(MRES_IGNOREDfalse);
    }

    
int clientattacker;

    const 
char *pEventName event->GetName();

    if (
strcmp(pEventName"player_death") == 0)
    {
        
client event->GetInt();
        
attacker event->GetInt();

        
rootconsole->ConsolePrint("[DEBUG] Post-Event: 'player_death' Fired.");
        
rootconsole->ConsolePrint("[DEBUG] client='%d', attacker='%d'."clientattacker);
    }
    
    
RETURN_META_VALUE(MRES_IGNOREDtrue);


Last edited by TheDS1337; 12-27-2016 at 04:40.
TheDS1337 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 12-28-2016 , 06:54   Re: Blocking events
Reply With Quote #2

I didn't really even skim your code, but using the SH return macros in a post hook doesn't make sense. Off the top of my head, I don't know if using them is a problem or if they'll be ignored. Perhaps the documentation says.

Use a debugger and try to see where and why it's crashing. This will probably be easier if you have symbols for the game server.
Fyren is offline
Reply


Thread Tools
Display Modes

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 04:36.


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