usercall detour test!

This commit is contained in:
ineed bots 2023-04-29 13:54:00 -06:00
parent f23df3ca3f
commit 1b41b53d78
3 changed files with 41 additions and 5 deletions

View File

@ -11,6 +11,9 @@ namespace test
{ {
utils::hook::detour gscr_spawn_hook; utils::hook::detour gscr_spawn_hook;
// a __usercall detour! :o
utils::hook::detour scr_getentityid_hook;
namespace namespace
{ {
game::dvar_s* custom_dvar; game::dvar_s* custom_dvar;
@ -91,6 +94,37 @@ namespace test
retn; retn;
} }
} }
unsigned int __stdcall scr_getentityid_call(game::scriptInstance_t inst, game::classNum_e classnum, unsigned int clientnum, unsigned int entnum)
{
// minhook allocated space for the original asm, we want to execute that instead because the original gamecode has the jump from the detour
return game::Scr_GetEntityId(inst, entnum, classnum, clientnum, scr_getentityid_hook.get_original());
}
unsigned int __declspec(naked) __cdecl scr_getentityid_stub(game::scriptInstance_t inst, game::classNum_e classnum, unsigned int clientnum)
{
// 00692520 unsigned int __usercall Scr_GetEntityId@<eax>(unsigned int entnum@<eax>, scriptInstance_t inst, classNum_e classnum, unsigned int clientnum)
__asm
{
// prol
push ebp;
mov ebp, esp;
// push shit for our call, remember eax is a param in the usercall, rest was on stack
// we can access params like this in naked because we correctly setup the ebp
push eax;
push clientnum;
push classnum;
push inst;
call scr_getentityid_call;
// we made this a __stdcall, so we dont need to clean up stack
// epil
mov esp, ebp;
pop ebp;
ret;
}
}
} }
class component final : public component_interface class component final : public component_interface
@ -137,6 +171,9 @@ namespace test
// fix NEGOTIATION links // fix NEGOTIATION links
//utils::hook::jump(0x4D3296, our_funny_hook); //utils::hook::jump(0x4D3296, our_funny_hook);
// test usercall detour!
scr_getentityid_hook.create(0x692520, scr_getentityid_stub);
} }
private: private:

View File

@ -303,10 +303,8 @@ namespace game
} }
} }
unsigned int Scr_GetEntityId(scriptInstance_t inst, int entNum, classNum_e classnum, unsigned int clientnum) unsigned int Scr_GetEntityId(scriptInstance_t inst, unsigned int entnum, classNum_e classnum, unsigned int clientnum, void* call_addr)
{ {
static const auto call_addr = SELECT(0x0, 0x692520);
unsigned int answer; unsigned int answer;
__asm __asm
@ -314,7 +312,7 @@ namespace game
push clientnum; push clientnum;
push classnum; push classnum;
push inst; push inst;
mov eax, entNum; mov eax, entnum;
call call_addr; call call_addr;
add esp, 0xC; add esp, 0xC;
mov answer, eax; mov answer, eax;

View File

@ -3,6 +3,7 @@
#include "structs.hpp" #include "structs.hpp"
#define SELECT(mp, sp) (game::environment::t4mp() ? mp : sp) #define SELECT(mp, sp) (game::environment::t4mp() ? mp : sp)
#define CALL_ADDR(mp, sp) reinterpret_cast<void*>(SELECT(mp, sp))
namespace game namespace game
{ {
@ -50,7 +51,7 @@ namespace game
void Scr_AddUndefined(game::scriptInstance_t inst); void Scr_AddUndefined(game::scriptInstance_t inst);
gentity_s* Scr_GetEntity(unsigned int arg_index); gentity_s* Scr_GetEntity(unsigned int arg_index);
void Scr_AddEntity(game::scriptInstance_t inst, gentity_s* ent); void Scr_AddEntity(game::scriptInstance_t inst, gentity_s* ent);
unsigned int Scr_GetEntityId(scriptInstance_t inst, int entNum, classNum_e classnum, unsigned int clientnum); unsigned int Scr_GetEntityId(scriptInstance_t inst, unsigned int entnum, classNum_e classnum, unsigned int clientnum, void* call_addr = CALL_ADDR(0x0, 0x692520));
void Scr_AddEntityNum(scriptInstance_t inst, unsigned int entid); void Scr_AddEntityNum(scriptInstance_t inst, unsigned int entid);
pathnode_t* Scr_GetPathnode(scriptInstance_t inst); pathnode_t* Scr_GetPathnode(scriptInstance_t inst);
void Scr_AddPathnode(scriptInstance_t inst, pathnode_t* node); void Scr_AddPathnode(scriptInstance_t inst, pathnode_t* node);