hi!
I'm developer of a program designed to provide features for games under GoldSrc (Half-Life #1 based games, like counter-strike 1.6, etc.) and I'm experiencing an issue when I compile a new module.
Question #1:
I'm using MinGW for the Windows binary, CygWin for the Linux one (with Makefile for both).
I have functions like this:
https://github.com/ValveSoftware/halflife/blob/master/dlls/player.cpp#L396
Which can't be called or hooked (I mean, once I call the function using my module or once the hook I've made using a memory patcher include is called, the game crash).
From my tests, it seems the "Vector" (
https://github.com/ValveSoftware/halflife/blob/master/dlls/vector.h) class among the format of the function is the problem, especially due to the fact it is passed at a standard (non-pointer) format.
I precise that this problem doesn't happen with functions that pass a such class at a pointer format (like "Vector *vecOrigin" or "Vector &vecOrigin".
I also precise this "bug/crash" only happens using MinGW compiler, this doesn't happen for the Linux binary using CygWin, neither when I use Visual Studio C++ 2010 Express.
You may wondering why I just not use VS2010 to fix? The reason is I'm using Windows XP, and my project requires variadic templates usage which, are not supported by this visual.
And about MinGW, I tried disabled & enabled a lot of options flags in the Makefile, but nothing has changed, and I don't know much about options, and even in C++ where I'm not expert with (that I do is just a hobby).
But I think an appropriate option may fix that problem (something to properly handle classes in the format of a function, once triggered), so, does anyone have an idea about?
Question #2:
The memory patcher include I'm using allows me to make hooks/detours (I mean, catch the function, then I can change the parameters, or block it), but the format of the callback is the standard one.
For example with that function:
https://github.com/ValveSoftware/halflife/blob/master/dlls/player.cpp#L396
The hook format is like this:
1 2 3 4 5 6 7 8 9 10
|
#if defined WIN32
void __fastcall HOOK_CBasePlayer_TraceAttack(void *pTargetClass, int i, entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType) {
#else
void HOOK_CBasePlayer_TraceAttack(void *pTargetClass, entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType) {
#endif
... function call
if(pHookFunction->Disable()) {
reinterpret_cast<void FUNCTION_FORMAT_CLASSES_PART1, entvars_t *, float, Vector, TraceResult *, int)>(pFunctionAddress)(pTargetClass, pevAttacker, lDamage, vecDir, ptr, bitsDamageType);
pHookFunction->Enable();
}
|
I would like to know if someone know how I could add an additionnal parameter (which will be the pointer of "pHookFunction" matching to some function data) in the hook/detour format? (before "void *pTargetClass).
In order to have a format like:
|
void HOOK_CBasePlayer_TraceAttack(void *pHookFuncAddress, void *pTargetClass, entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType) {
|
I'm pretty sure it's possible since I've already seen some hooks like this. But I don't know that I have to modify in the code because it's away from my knownledge. Any idea?
This is highly important for me and the goals of my project.
The main/start code that make the hook is like this:
1 2 3 4 5 6
|
m_vDetour = vDest;
memcpy(m_pOriginalAddress, m_vAddress, sizeof(m_szOriginalAddress));
m_pPatchedAddress[0] = 0xE9;
unsigned int *p = ( unsigned int* )( m_pPatchedAddress + 1 );
*p = ( unsigned int )vDest - ( unsigned int )m_vAddress - sizeof(m_szOriginalAddress);
|
Members infos:
m_vDetour & vDest is the callback (HOOK_CBasePlayer_TraceAttack), m_vAddress is the original function (pointer of "CBasePlayer::TraceAttack").
Like:
1 2 3 4 5 6 7
|
void* m_vAddress; // Function to patch.
void* m_vDetour; // Hook callback.
unsigned char m_szOriginalAddress[5];
unsigned char m_szPatchedAddress[5];
unsigned char *m_pOriginalAddress;
unsigned char *m_pPatchedAddress;
|
Question #3:
Due to the fact I'm using Windows XP & Visual C++2010 which has limits, is there a way to add support for variadic template to that software? (by remplacing some internal files or something similar?).
Feel free to ask me more details/content if you feel the need (as the list of options in the Makefile, etc.).
Thanks.