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

CS:GO Game Events and accces api


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
merhaben
Junior Member
Join Date: Jun 2016
Old 06-10-2016 , 16:15   CS:GO Game Events and accces api
Reply With Quote #1

i want to handle cs:go events in the metamod:source plugin. but the server gives me a message below in the server console:
Code:
GameEventListener2 callback in list that should NOT be - weapon_reload!
My Code:
Code:
#include <stdio.h> 
#include "stub_mm.h" 
 
SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int, int); 
SH_DECL_HOOK1_void(IGameEventListener2, FireGameEvent, SH_NOATTRIB, 0, IGameEvent *); 
SH_DECL_HOOK3(IGameEventManager2, AddListener, SH_NOATTRIB, 0, bool, IGameEventListener2 *, const char *, bool); 
SH_DECL_HOOK2(IGameEventManager2, FindListener, SH_NOATTRIB, 0, bool, IGameEventListener2 *, const char *); 
SH_DECL_HOOK2(IGameEventManager2, FireEvent, SH_NOATTRIB, 0, bool, IGameEvent *, bool); 
 
StubPlugin g_StubPlugin; 
IServerGameDLL *server = NULL; 
IGameEventListener2 *eventListener = NULL; 
IGameEventManager2 *eventManager = NULL; 
 
PLUGIN_EXPOSE(StubPlugin, g_StubPlugin); 
bool StubPlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late) 
{ 
    PLUGIN_SAVEVARS(); 
 
    GET_V_IFACE_CURRENT(GetServerFactory, server, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); 
    GET_V_IFACE_CURRENT(GetEngineFactory, eventListener, IGameEventListener2, INTERFACEVERSION_GAMEEVENTSMANAGER2); 
    GET_V_IFACE_CURRENT(GetEngineFactory, eventManager, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2); 
 
    SH_ADD_HOOK_STATICFUNC(IServerGameDLL, ServerActivate, server, Hook_ServerActivate, true); 
    //SH_ADD_HOOK(IGameEventListener2, FireGameEvent, eventListener, SH_STATIC(Hook_FireGameEvent), true); 
    //SH_ADD_HOOK_STATICFUNC(IGameEventManager2, FindListener,  eventManager, Hook_FindListener, true); 
    //SH_ADD_HOOK(IGameEventManager2, FireEvent, eventManager, SH_STATIC(Hook_FireEvent), true); 
 
    g_SMAPI->EnableVSPListener(); 
    g_SMAPI->AddListener(this, this);
 
 
    g_SMAPI->ConPrintf("Plugin::Load\n"); 
    return true; 
}

void StubPlugin::FireGameEvent( IGameEvent *event ) {
    g_SMAPI->ConPrintf("event..: %s", event->GetName());
}

int StubPlugin::GetEventDebugID() {} 
 
void StubPlugin::OnVSPListening(IServerPluginCallbacks *iface) { 
    g_SMAPI->ConPrintf("Plugin::ONVSPListening\n"); 
} 
 
bool StubPlugin::Unload(char *error, size_t maxlen) 
{ 
    SH_REMOVE_HOOK_STATICFUNC(IServerGameDLL, ServerActivate, server, Hook_ServerActivate, true); 
    g_SMAPI->ConPrintf("Plugin::UnLoad\n"); 
    return true; 
} 
 
bool Hook_FindListener( IGameEventListener2 * listener, const char *name ) { 
    g_SMAPI->ConPrintf("hook_Listener..: %s\n", name); 
} 
 
void Hook_ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) 
{ 
    g_SMAPI->ConPrintf("Hello World - %s - %d\n", g_PLAPI->GetAuthor(), g_PLID); 
    eventManager->AddListener( &g_StubPlugin, "weapon_reload", true ); 
} 
 
void Hook_FireGameEvent( IGameEvent *event ) 
{ 
    g_SMAPI->ConPrintf("Event..: %s\n", event->GetName()); 
} 
 
bool Hook_FireEvent( IGameEvent *event, bool bDontBroadCast ) 
{ 
    g_SMAPI->ConPrintf("Plugin::FireEvent\n"); 
} 
 
void StubPlugin::AllPluginsLoaded() 
{ 
    g_SMAPI->ConPrintf("Plugin::AllPluginsLoaded\n"); 
} 
 
bool StubPlugin::Pause(char *error, size_t maxlen) 
{ 
    return true; 
} 
 
bool StubPlugin::Unpause(char *error, size_t maxlen) 
{ 
    return true; 
} 
 
const char *StubPlugin::GetLicense() 
{ 
    return "Public Domain"; 
} 
 
const char *StubPlugin::GetVersion() 
{ 
    return "1.0.0.0"; 
} 
 
const char *StubPlugin::GetDate() 
{ 
    return __DATE__; 
} 
 
const char *StubPlugin::GetLogTag() 
{ 
    return "STUB"; 
} 
 
const char *StubPlugin::GetAuthor() 
{ 
    return "@aaa"; 
} 
 
const char *StubPlugin::GetDescription() 
{ 
    return "Sample empty plugin"; 
} 
 
const char *StubPlugin::GetName() 
{ 
    return "Stub Plugin"; 
} 
 
const char *StubPlugin::GetURL() 
{ 
    return "http://www.sourcemm.net/"; 
}
My Plugin is :
Code:
class StubPlugin : public ISmmPlugin, public IMetamodListener, public IGameEventListener2
My Another questions...:
What is differences between GET_V_IFACE_CURRENT and GET_V_IFACE_ANY ?
What is GetEngineFactory and GetServerFactory, why do i use IServerGameDLL with GetServerFactory and IGameEventListener2 with GetEngineFactory ?
and
How to access game api like give weapon or entity apis, spawn entity like in sourcemod?
Thank you so much for your help...
merhaben is offline
waggel
Junior Member
Join Date: Aug 2007
Old 07-20-2016 , 21:27   Re: CS:GO Game Events and accces api
Reply With Quote #2

At your first question;
https://forums.alliedmods.net/showthread.php?t=194382

Second question, according to source code;
Code:
 /**
  * @brief Same as GET_V_IFACE, except searches for any.
  *
  * @param v_factory	Factory method to use from ISmmAPI (such as engineFactory).
  * @param v_var		Variable name to store into.
  * @param v_type		Interface type (do not include the pointer/asterisk).
  * @param v_name		Interface name.
  */
Which points to
Code:
/**
 * @brief Macro for automatically getting a current or newer Valve interface.
 *
 * @param v_factory		Factory method to use from ISmmAPI (such as engineFactory).
 * @param v_var			Variable name to store into.
 * @param v_type		Interface type (do not include the pointer/asterisk).
 * @param v_name		Interface name.
 */
If you go deeper it wraps the function "VInterfaceMatch" which says
Code:
		/**
		 * @brief Wrapper around InterfaceSearch().  Assumes no maximum.
		 * This is designed to replace the fact that searches only went upwards.
		 * The "V" is intended to convey that this is for Valve formatted 
		 * interface strings.
		 *
		 * @param fn			Interface factory function.
		 * @param iface			Interface string.
		 * @param min			Minimum value to search from.  If zero, searching 
		 *						begins from the first available version regardless 
		 *						of the interface.  Note that this can return 
		 *						interfaces EARLIER than the version specified.  A 
		 *						value of -1 (default) specifies the string version 
		 *						as the minimum.  Any other value specifices the 
		 *						minimum value to search from.
		 * @return				Interface pointer, or NULL if not found.
		 */
@Param min gives you the answer.

(If you are using Visual Studio, right click the function -> "Go to definition")

Third question, GetServerFactory is for the generic server functions, the source server is pretty much the same for all source based games. GetEngineFactory is for game specific calls and events.

Last question, download the sourcemod source files. Have a program like Notepad++ that has the function "Search in files", select the folder of sourcemod sources and as search input "give_weapon" or "spawn". It's a little guessing but you'll get close.

Know that all 'simple, straight forward' game events have already been written in SM and that plowing through the source code will get you a long way.

And if you are only going to change game behavior I'd suggest you should create your plugin on SM itself, pawn which is 100 times friendlier.

Also in your code;
Code:
bool Hook_FindListener( IGameEventListener2 * listener, const char *name ) { 
    g_SMAPI->ConPrintf("hook_Listener..: %s\n", name); 
}
You define a function that returns a boolean, but you don't return anything at all, and since there is no logic that defines it could return false or true you should go with a void return type declared function.

And for pretty c++ sake, 'return;' all functions, don't let it just run out of the scope (one ignore-warning compiler flag less)
Visual studio is very lax on compiling, but the moment you want to cross compile onto linux or mac you'll hit your head.
waggel is offline
psychonic

BAFFLED
Join Date: May 2008
Old 07-20-2016 , 21:35   Re: CS:GO Game Events and accces api
Reply With Quote #3

If you just want to listen to events and don't need to block them from firing, you don't need to invoke SourceHook. Just find the IGameEventManager2 iface and add yourself as a listener.
psychonic is offline
merhaben
Junior Member
Join Date: Jun 2016
Old 09-07-2016 , 05:55   Re: CS:GO Game Events and accces api
Reply With Quote #4

Thank you so much waggel and psychonic. I solved my all problem...
I changed my code like below and i can handle events.
int StubPlugin::GetEventDebugID() { return 42; }
merhaben 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 12:31.


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