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

Detouring in-game functions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 11-04-2015 , 11:44   Detouring in-game functions
Reply With Quote #1

Title says above.

How does one detour an in-game function to execute some other code rather than the one Valve has set it to execute?

So rather than function A executing instructions 1, 2, 3, 4, 5 and return 0.2 (as written by Valve), make function A execute instructions 6, 7, 8, 9 and return 0.3 (written by me or someone else).

Is there a tutorial or some methodical way to do this? I'm assuming an SM extension would be required to do this?
Potato Uno is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 11-04-2015 , 11:46   Re: Detouring in-game functions
Reply With Quote #2

use DHooks
__________________
Chdata is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 11-04-2015 , 11:55   Re: Detouring in-game functions
Reply With Quote #3

Here is a simple example for beginners:
https://forums.alliedmods.net/showthread.php?t=159876

Last edited by kadet.89; 11-04-2015 at 12:04.
kadet.89 is offline
Send a message via Skype™ to kadet.89
pheadxdll
AlliedModders Donor
Join Date: Jun 2008
Old 11-04-2015 , 12:20   Re: Detouring in-game functions
Reply With Quote #4

Use dhooks or sourcehook for hooking virtual functions. They modify the vmt leaving the original function unchanged.
Use CDetour for everything else (static/member functions). They modify the first few instructions of the function to perform the hook.

These two things are what 99% of extensions do.
__________________

Last edited by pheadxdll; 11-04-2015 at 12:22.
pheadxdll is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 11-04-2015 , 12:40   Re: Detouring in-game functions
Reply With Quote #5

Quote:
Originally Posted by pheadxdll View Post
Use dhooks or sourcehook for hooking virtual functions. They modify the vmt leaving the original function unchanged.
Use CDetour for everything else (static/member functions). They modify the first few instructions of the function to perform the hook.

These two things are what 99% of extensions do.
SourceHook and CDetour are what extensions use, DHooks is a wrapper of SH I believe(I'm not 100% sure but I'm pretty sure) for plugins to interact with it.
WildCard65 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 11-04-2015 , 14:22   Re: Detouring in-game functions
Reply With Quote #6

Quote:
Originally Posted by Chdata View Post
use DHooks
If it's a virtual function, use DHooks and avoid the pain of writing / maintaining (where the real pain is) an extension.

There is a tutorial here: https://forums.alliedmods.net/showthread.php?t=191171
__________________
asherkin is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 11-04-2015 , 18:40   Re: Detouring in-game functions
Reply With Quote #7

What's with people saying extensions are so painful? Can I have a couple of reasons WHY they are painful? Using TF2Items for example it only broke like 3 times this year, whereas gamedata went stale like 10 times (or more).

If extensions are truly painful then I might not even want to bother dealing with them lol.

Also how do you know if a function is a virtual function?

Last edited by Potato Uno; 11-04-2015 at 18:41.
Potato Uno is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 11-04-2015 , 18:53   Re: Detouring in-game functions
Reply With Quote #8

Quote:
Originally Posted by Potato Uno View Post
What's with people saying extensions are so painful? Can I have a couple of reasons WHY they are painful? Using TF2Items for example it only broke like 3 times this year, whereas gamedata went stale like 10 times (or more).

If extensions are truly painful then I might not even want to bother dealing with them lol.
TF2Items has 5 years of experience and the entire AlliedModders build infrastructure behind it, it's in maintenance mode only and requires absolutely no manual work to build - just push a commit and a download for each package magically appears within 10 minutes. You're not going to have this.

Quote:
Originally Posted by Potato Uno View Post
Also how do you know if a function is a virtual function?
See if it has a reference from a vtable (and only from a vtable).
__________________
asherkin 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 03:15.


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