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

Problem with say-hook in SourceMM


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Roger Devil
Senior Member
Join Date: Dec 2004
Location: Germany
Old 01-27-2006 , 09:20   Problem with say-hook in SourceMM
Reply With Quote #1

Hi, i implemented a say hook in my plugin. When i start a Listen-Server, the hook isnt installed. Heres my Load-Function, perhaps some of you can help me out :
Code:
bool CGMPPlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
	PLUGIN_SAVEVARS();

	char iface_buffer[255];
	int num=0;

	strcpy(iface_buffer, INTERFACEVERSION_SERVERGAMEDLL);
	FIND_IFACE(serverFactory, m_ServerDll, num, iface_buffer, IServerGameDLL *)
	strcpy(iface_buffer, INTERFACEVERSION_VENGINESERVER);
	FIND_IFACE(engineFactory, engine, num, iface_buffer, IVEngineServer *)
	strcpy(iface_buffer, INTERFACEVERSION_SERVERGAMECLIENTS);
	FIND_IFACE(serverFactory, m_ServerClients, num, iface_buffer, IServerGameClients *)
	strcpy(iface_buffer, INTERFACEVERSION_GAMEEVENTSMANAGER2);
	FIND_IFACE(engineFactory, m_GameEventManager, num, iface_buffer, IGameEventManager2 *);
	strcpy(iface_buffer, FILESYSTEM_INTERFACE_VERSION);
	FIND_IFACE(engineFactory, filesystem, num, iface_buffer, IFileSystem *)
	strcpy(iface_buffer, INTERFACEVERSION_PLAYERINFOMANAGER);
	FIND_IFACE(serverFactory, playerinfomanager, num, iface_buffer, IPlayerInfoManager *)
	strcpy(iface_buffer, VENGINE_CVAR_INTERFACE_VERSION);
	FIND_IFACE(engineFactory, g_pCVars, num, iface_buffer, ICvar *)
	strcpy(iface_buffer, IEFFECTS_INTERFACE_VERSION);
	FIND_IFACE(serverFactory, g_pEffects, num, iface_buffer, IEffects *)
	strcpy(iface_buffer, IENGINESOUND_SERVER_INTERFACE_VERSION);
	FIND_IFACE(engineFactory, enginesound, num, iface_buffer, IEngineSound *)

	engine->GetGameDir( g_szDir, 255 );

	if( g_pEffects )
		pEnts=GetAdvancedEffects();

	META_LOG(g_PLAPI, "Starting plugin.\n");
	ismm->AddListener(this, &g_Listener);

	//Init our cvars/concmds
	ConCommandBaseMgr::OneTimeInit(&g_Accessor);

	//We're hooking the following things as POST, in order to seem like Server Plugins.
	//However, I don't actually know if Valve has done server plugins as POST or not.
	//Change the last parameter to 'false' in order to change this to PRE.
	//SH_ADD_HOOK_MEMFUNC means "SourceHook, Add Hook, Member Function".

	//Hook LevelInit to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, m_ServerDll, &g_GMPPlugin, &CGMPPlugin::LevelInit, true);
	//Hook ServerActivate to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, m_ServerDll, &g_GMPPlugin, &CGMPPlugin::ServerActivate, true);
	//Hook GameFrame to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, GameFrame, m_ServerDll, &g_GMPPlugin, &CGMPPlugin::GameFrame, true);
	//Hook LevelShutdown to our function -- this makes more sense as pre I guess
	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, m_ServerDll, &g_GMPPlugin, &CGMPPlugin::LevelShutdown, false);
	//Hook ClientActivate to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientActive, m_ServerClients, &g_GMPPlugin, &CGMPPlugin::ClientActive, true);
	//Hook ClientDisconnect to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, m_ServerClients, &g_GMPPlugin, &CGMPPlugin::ClientDisconnect, true);
	//Hook ClientPutInServer to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientPutInServer, m_ServerClients, &g_GMPPlugin, &CGMPPlugin::ClientPutInServer, true);
	//Hook SetCommandClient to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, m_ServerClients, &g_GMPPlugin, &CGMPPlugin::SetCommandClient, true);
	//Hook ClientSettingsChanged to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientSettingsChanged, m_ServerClients, &g_GMPPlugin, &CGMPPlugin::ClientSettingsChanged, true);

	//The following functions are pre handled, because that's how they are in IServerPluginCallbacks

	//Hook ClientConnect to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientConnect, m_ServerClients, &g_GMPPlugin, &CGMPPlugin::ClientConnect, false);
	//Hook ClientCommand to our function
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientCommand, m_ServerClients, &g_GMPPlugin, &CGMPPlugin::ClientCommand, false);

	//This hook is a static hook, no member function
	SH_ADD_HOOK_STATICFUNC(IGameEventManager2, FireEvent, m_GameEventManager, FireEvent_Handler, false); 

	m_Engine_CC = SH_GET_CALLCLASS(engine);

	SH_CALL(m_Engine_CC, &IVEngineServer::LogPrint)("All hooks started!\n");

	g_SMAPI->AddListener(g_PLAPI, this);

	META_LOG(g_PLAPI, "Starting GlitterMod plugin.\n");

	//Get the call class for IVServerEngine so we can safely call functions without
	// invoking their hooks (when needed).
	if( late )
	{
		ConCommandBase *pCmd = g_pCVars->GetCommands();
		int n=0;
		while (pCmd)
		{
			if (pCmd->IsCommand() )
			{   
//				META_CONPRINTF("[GMP]: Hooking ConCommand: %s\n",pCmd->GetName());
				if( stricmp(pCmd->GetName(),"say") == 0  ) 
				{
					pSayCmd = (ConCommand *)pCmd;
					META_CONPRINTF("[GMP]:  Hooking ConCommand: %s\n",pSayCmd->GetName());
					SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pSayCmd, Say_handler, false);	
					n++;
				}
				else if( stricmp(pCmd->GetName(),"autobuy") == 0  ) 
				{
					pAutobuyCmd = (ConCommand *)pCmd;
					META_CONPRINTF("[GMP]: Hooking ConCommand: %s\n",pAutobuyCmd->GetName());
					SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pAutobuyCmd, Autobuy_handler, false);	
					n++;
				}
				else if( stricmp(pCmd->GetName(),"rebuy") == 0  ) 
				{
					pRebuyCmd = (ConCommand *)pCmd;
					META_CONPRINTF("[GMP]: Hooking ConCommand: %s\n",pRebuyCmd->GetName());
					SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pRebuyCmd, Rebuy_handler, false);	
					n++;
				}
			}
			if( n >= 3 ) 
				break;
			pCmd = const_cast<ConCommandBase *>(pCmd->GetNext());
		}
	}
	
	return true;
}
Thanks in advanve
Roger Devil is offline
Send a message via ICQ to Roger Devil
L. Duke
Veteran Member
Join Date: Apr 2005
Location: Walla Walla
Old 01-27-2006 , 10:11  
Reply With Quote #2

A couple mms updates ago (1.1?) my Autobuy/Rebuy hook stopped working. I found out that it was not finding the concommand names during Load. I moved the hooks to AllPluginsLoaded and they worked fine again.
L. Duke is offline
sslice
Senior Member
Join Date: Feb 2005
Location: Texas, USA
Old 01-27-2006 , 16:01  
Reply With Quote #3

Yeah, move ConCommand hooks to AllPluginsLoaded()
__________________
sslice is offline
Roger Devil
Senior Member
Join Date: Dec 2004
Location: Germany
Old 01-28-2006 , 03:31  
Reply With Quote #4

Thanks for your help, i will try this out.
[update]
I tried it, and yes it works when hooking in AllPluginsLoaded()
Roger Devil is offline
Send a message via ICQ to Roger Devil
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 03:34.


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