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

Get command before game dll gets it?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
devicenull
Veteran Member
Join Date: Mar 2004
Location: CT
Old 08-17-2005 , 22:52   Get command before game dll gets it?
Reply With Quote #1

Is this possible?

The mod does:
ConCommand buy( "buy", Buy_f, "Buy stuff" );

And I want to intercept it before the mod sees it..
Tried using SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientCommand, m_ServerClients, &g_SourceForts, &SourceForts::ClientCommand, false);
and everything else needed for that.. but it didnt work
__________________
Various bits of semi-useful code in a bunch of languages: http://code.devicenull.org/
devicenull is offline
BAILOPAN
Join Date: Jan 2004
Old 08-17-2005 , 22:55  
Reply With Quote #2

You can do this (copied from CS:S DM for hooking say)

Code:
	//more hax - hook say cmd
	ConCommandBase *pCmd = m_ICvar->GetCommands();
	while (pCmd)
	{
		if (pCmd->IsCommand()
			&& (strcmp(pCmd->GetName(), "say") == 0))
			break;
		pCmd = const_cast<ConCommandBase *>(pCmd->GetNext());
	}

	if (pCmd)
	{
		pSayCmd = (ConCommand *)pCmd;
		SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pSayCmd, Say_handler, false);
	} else {
		pSayCmd = NULL;
	}
Just make sure to SH_DECL_HOOK0_void the Dispatch from ConCommand. Also! Don't forget you need to hook SetCommandClient, which sends the last id to use a server command.

So in your handler, you'd do like:
Code:
void BuyDispatch_handler()
{
   //srcds gives index - 1 for some reason
   int index = OmgMyPlugin.GetCommandClient() + 1;
}
BEHOLD, the power of SourceHook!
__________________
egg
BAILOPAN is offline
sslice
Senior Member
Join Date: Feb 2005
Location: Texas, USA
Old 08-17-2005 , 23:35  
Reply With Quote #3

Yeah, SourceHook is truly awesome.
__________________
sslice is offline
Mysterious
Junior Member
Join Date: Apr 2009
Old 06-01-2009 , 06:28   Re: Get command before game dll gets it?
Reply With Quote #4

That's exactly what I've been searching for but I can't get it to work.
I bound SourceHook into the EmptyServerPlugin-Template but the server crashed every time when it had to pass the following code:
Code:
ConCommandBase *pCmd = cvar->GetCommands();
I tried several ways to run the code: in the Plugin::Load() function, in a concommand and in the Plugin::ServerActivate() function.

I don't know if it was correct to use the cvar-object which is from the "icvar.h"-file.

It would be kind of you to explain me the whole thing detailed.

With best wishes
Mysterious
Mysterious is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 06-01-2009 , 08:56   Re: Get command before game dll gets it?
Reply With Quote #5

The quickest way for it to crash is if cvar is NULL. Has cvar been defined at that point?
Keeper is offline
Mysterious
Junior Member
Join Date: Apr 2009
Old 06-01-2009 , 10:39   Re: Get command before game dll gets it?
Reply With Quote #6

Oh...
Of course
Stupid mistake. But the plugin templates code was a bit confusing.

Thank you

Another Question:
Now I have got my handler but how can I prevent the execution of the main concommand?

Yours
Mysterious

[EDIT]
Found it:
Code:
RETURN_META(MRES_SUPERCEDE);

Last edited by Mysterious; 06-01-2009 at 10:58.
Mysterious 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 17:06.


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