Help with DynamicHooks

All other Source.Python topics and issues.
Junior Member
Posts: 19
Joined: Fri Nov 06, 2015 11:49 pm

Help with DynamicHooks

Postby roflmuffin » Wed Oct 21, 2020 6:06 am

Hi there,

I wasn't sure of the best place to post this, so I figured General Discussion might suit. I am currently working on my own Valve Server Plugin and I was looking into using the wonderful Ayuto's DynamicHooks library. I ended up updating the library to use the latest version of AsmJit (mainly so I can compile for VS2019), which required a few code changes, however after a little while I was able to compile the library and the included tests completed successfully and stepping through it it all seems good.

The problem is now that I am looking to actually implement this into the server plugin, whenever I try and read from the arguments inside of a pre or post hook I get the classic error:

Code: Select all

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.

Unfortunately registers/assembly are not my strongest suit so its becoming harder and harder for me to debug this (though I am learning more and more).

The example hook reading code is a simple one (note this is a `x86MsThiscall` so I expect the first argument to be a pointer)

Code: Select all

bool Test(HookType_t type, CHook* pHook) {
   pHook->GetArgument<unsigned long>(0);
   return false;

I guess my main question is, why would all of the test cases work fine (and reading the arguments works well too), but as soon as I read arguments from a hook inside the game server I encounter the ESP issues.

Any help would be appreciated, or where to start looking. For interest, you can find the forked version of DynamicHooks here.

EDIT: So with some further investigating, it seems there is nothing actually wrong with the library, but any calls to "GetArgumentPtr" throws an ESP error, and a breakpoint I set inside GetArgumentPtr is not being called... its like the VTable its using to call on the ICallingConvention is messed up. I tried copying the body of the "GetArgumentPtr" into its own method and calling that and I receive the correct values. Not really sure where to go from here now.

EDIT2: So after all that, the problem was that the "convention.h" I was including in my application was missing the virtual destructor for ICallingConvention, this meant my app vtable was incorrect and calling the wrong methods off by 1. I can't believe how much time I wasted on such a simple issue lol, check your includes kids.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 4 guests