Add base detour for G_ClientDoPerFrameNotifies.

This commit is contained in:
JezuzLizard 2023-04-29 18:51:54 -07:00
parent 5d4f84e570
commit 2416967be7
5 changed files with 1805 additions and 1 deletions

93
src/component/player.cpp Normal file
View File

@ -0,0 +1,93 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include <utils/hook.hpp>
#include <utils/io.hpp>
#include <utils/string.hpp>
#include <utils/thread.hpp>
#include <utils/compression.hpp>
#include <exception/minidump.hpp>
namespace player
{
namespace
{
utils::hook::detour g_clientdoperframenotifies_hook;
void G_ClientDoPerFrameNotifies_custom(game::gentity_s* ent)
{
game::gclient_s* client; // esi
unsigned int weapon; // eax
bool clientIsFiring; // bl
client = ent->client;
weapon = client->ps.weapon;
if (weapon != client->lastWeapon)
{
game::Scr_AddString(game::SCRIPTINSTANCE_SERVER, game::BG_WeaponNames[weapon]->szInternalName);
game::Scr_NotifyNum(game::SCRIPTINSTANCE_SERVER, ent->s.number, 0, game::scr_const->weapon_change, 1);
weapon = client->ps.weapon;
client->lastWeapon = weapon;
}
if (!client->previouslyChangingWeapon || client->ps.weaponstate == game::WEAPON_RAISING || client->ps.weaponstate == game::WEAPON_RAISING_ALTSWITCH)
{
if (client->ps.weaponstate == game::WEAPON_RAISING || client->ps.weaponstate == game::WEAPON_RAISING_ALTSWITCH)
client->previouslyChangingWeapon = 1;
}
else
{
game::Scr_AddString(game::SCRIPTINSTANCE_SERVER, game::BG_WeaponNames[weapon]->szInternalName);
game::Scr_NotifyNum(game::SCRIPTINSTANCE_SERVER, ent->s.number, 0, game::scr_const->weapon_change_complete, 1);
client->previouslyChangingWeapon = 0;
}
clientIsFiring = client->ps.weaponstate == game::WEAPON_FIRING && client->ps.pm_type < game::PM_LASTSTAND_TRANSITION;
if (clientIsFiring != client->previouslyFiring)
{
if (clientIsFiring)
game::Scr_NotifyNum(game::SCRIPTINSTANCE_SERVER, ent->s.number, 0, game::scr_const->begin_firing, 0);
else
game::Scr_NotifyNum(game::SCRIPTINSTANCE_SERVER, ent->s.number, 0, game::scr_const->end_firing, 0);
client->previouslyFiring = clientIsFiring;
}
if ((client->ps.weapFlags & 0x40) != 0)
{
if (!client->previouslyUsingNightVision)
{
client->previouslyUsingNightVision = 1;
game::Scr_NotifyNum(game::SCRIPTINSTANCE_SERVER, ent->s.number, 0, game::scr_const->night_vision_on, 0);
}
}
else if (client->previouslyUsingNightVision)
{
client->previouslyUsingNightVision = 0;
game::Scr_NotifyNum(game::SCRIPTINSTANCE_SERVER, ent->s.number, 0, game::scr_const->night_vision_off, 0);
}
}
void __declspec(naked) G_ClientDoPerFrameNotifies_stub()
{
__asm
{
push edi;
call G_ClientDoPerFrameNotifies_custom;
add esp, 0x4;
ret;
}
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
// test usercall detour!
g_clientdoperframenotifies_hook.create(game::G_ClientDoPerFrameNotifies(), G_ClientDoPerFrameNotifies_stub);
}
};
}
REGISTER_COMPONENT(player::component)

View File

@ -32,6 +32,15 @@ namespace game
{ "dead", TEAM_DEAD }
};
void G_ClientDoPerFrameNotifies(gentity_s* ent, void* call_addr)
{
__asm
{
mov edi, ent;
call call_addr;
}
}
void Scr_PrintPrevCodePos(const char* codepos, int scriptInstance, con_channel_e channel, int index)
{
static const auto call_addr = SELECT(0x0, 0x68B340);
@ -437,6 +446,20 @@ namespace game
return answer;
}
void Scr_NotifyNum(scriptInstance_t inst, int entNum, int entClass, unsigned int notifStr, int numParams, void* call_addr)
{
__asm
{
push numParams;
push notifStr;
push entClass;
push entNum;
mov eax, inst;
call call_addr;
add esp, 0x10;
}
}
unsigned int Scr_GetNumParam(scriptInstance_t inst)
{
return gScrVmPub[inst].outparamcount;

View File

@ -24,6 +24,9 @@ namespace game
extern std::map<std::string, team_t> team_map;
__inline void* G_ClientDoPerFrameNotifies() { return CALL_ADDR(0x0, 0x503540); }
void G_ClientDoPerFrameNotifies(gentity_s* ent, void* call_addr = G_ClientDoPerFrameNotifies());
void Scr_PrintPrevCodePos(const char* codepos, int scriptInstance, con_channel_e channel, int index);
void RemoveRefToObject(scriptInstance_t inst, unsigned int id);
int Scr_LoadScript(const char* file, scriptInstance_t inst);
@ -62,6 +65,9 @@ namespace game
void Scr_AddArrayStringIndexed(scriptInstance_t inst, unsigned short id);
unsigned short Scr_ExecThread(scriptInstance_t inst, int handle, int paramCount);
unsigned short Scr_ExecEntThread(scriptInstance_t inst, int entNum, int handle, int numParams, int entClass);
__inline void* Scr_NotifyNum() { return CALL_ADDR(0x0, 0x698CC0); }
void Scr_NotifyNum(scriptInstance_t inst, int entNum, int entClass, unsigned int notifStr, int numParams, void* call_addr = Scr_NotifyNum());
unsigned int Scr_GetNumParam(scriptInstance_t inst);
VariableType Scr_GetType(scriptInstance_t inst, unsigned int index);
void Scr_Error(const char* err, scriptInstance_t inst, bool is_terminal);

File diff suppressed because it is too large Load Diff

View File

@ -32,6 +32,8 @@ namespace game
WEAK symbol<function_stack_t> function_stack{ 0x0, 0x3BDDDD0 };
WEAK symbol<scr_const_t> scr_const{0x0, 0x1F33B90};
WEAK symbol<WeaponDef*> BG_WeaponNames{ 0x0, 0x8F6770 };
// Dvars
WEAK symbol<dvar_s*> com_developer{ 0x0, 0x1F55288 };