Skip to content

Commit

Permalink
Fix a bug that GameStudioRenderer_StudioRenderModel and GameStudioRen…
Browse files Browse the repository at this point in the history
…derer_StudioRenderFinal were not properly located in Counter-Strike.
  • Loading branch information
hzqst committed Sep 18, 2023
1 parent 35df1ae commit 373360e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
40 changes: 40 additions & 0 deletions Plugins/Renderer/exportfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,40 @@ int HUD_GetStudioModelInterface(int version, struct r_studio_interface_s **ppint
gRefFuncs.GameStudioRenderer_StudioSetupBones = (decltype(gRefFuncs.GameStudioRenderer_StudioSetupBones))vftable[gRefFuncs.GameStudioRenderer_StudioSetupBones_vftable_index];
gRefFuncs.GameStudioRenderer_StudioMergeBones = (decltype(gRefFuncs.GameStudioRenderer_StudioMergeBones))vftable[gRefFuncs.GameStudioRenderer_StudioMergeBones_vftable_index];

if (g_bIsCounterStrike)
{
g_pMetaHookAPI->DisasmRanges(gRefFuncs.GameStudioRenderer_StudioDrawPlayer, 0x100, [](void *inst, PUCHAR address, size_t instLen, int instCount, int depth, PVOID context) {

auto pinst = (cs_insn *)inst;

if (address[0] == 0xCC)
return TRUE;

if (pinst->id == X86_INS_RET)
return TRUE;

if (pinst->id == X86_INS_CALL &&
pinst->detail->x86.op_count == 1 &&
pinst->detail->x86.operands[0].type == X86_OP_MEM &&
pinst->detail->x86.operands[0].mem.disp >= 0x60 &&
pinst->detail->x86.operands[0].mem.disp <= 0x70)
{
gRefFuncs.GameStudioRenderer__StudioDrawPlayer_vftable_index = pinst->detail->x86.operands[0].mem.disp / 4;
}

if (gRefFuncs.GameStudioRenderer__StudioDrawPlayer_vftable_index)
return TRUE;

return FALSE;
}, 0, NULL);

if (gRefFuncs.GameStudioRenderer__StudioDrawPlayer_vftable_index == 0)
gRefFuncs.GameStudioRenderer__StudioDrawPlayer_vftable_index = 100 / 4;

gRefFuncs.GameStudioRenderer__StudioDrawPlayer = (decltype(gRefFuncs.GameStudioRenderer__StudioDrawPlayer))vftable[gRefFuncs.GameStudioRenderer__StudioDrawPlayer_vftable_index];

}

typedef struct
{
PVOID base;
Expand All @@ -1115,6 +1149,12 @@ int HUD_GetStudioModelInterface(int version, struct r_studio_interface_s **ppint
GameStudioRenderer_StudioDrawPlayer_ctx ctx = { 0 };

ctx.base = gRefFuncs.GameStudioRenderer_StudioDrawPlayer;

if (gRefFuncs.GameStudioRenderer__StudioDrawPlayer)
{
ctx.base = gRefFuncs.GameStudioRenderer__StudioDrawPlayer;
}

ctx.max_insts = 1000;
ctx.max_depth = 16;
ctx.walks.emplace_back(ctx.base, 0x1000, 0);
Expand Down
4 changes: 3 additions & 1 deletion Plugins/Renderer/ref_int_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,17 @@ typedef struct
void(__fastcall *GameStudioRenderer_StudioMergeBones)(void *pthis, int, model_t *pSubModel);
int(__fastcall *GameStudioRenderer_StudioDrawModel)(void *pthis, int, int flags);
int(__fastcall *GameStudioRenderer_StudioDrawPlayer)(void *pthis, int, int flags, struct entity_state_s *pplayer);
int(__fastcall *GameStudioRenderer__StudioDrawPlayer)(void *pthis, int, int flags, struct entity_state_s *pplayer);
void (__fastcall *GameStudioRenderer_StudioRenderModel)(void *pthis, int);
void (__fastcall *GameStudioRenderer_StudioRenderFinal)(void *pthis, int);

int GameStudioRenderer_StudioCalcAttachments_vftable_index;
int GameStudioRenderer_StudioSetupBones_vftable_index;
int GameStudioRenderer_StudioSaveBones_vftable_index;
int GameStudioRenderer_StudioMergeBones_vftable_index;
int GameStudioRenderer_StudioDrawPlayer_vftable_index;
int GameStudioRenderer_StudioDrawModel_vftable_index;
int GameStudioRenderer_StudioDrawPlayer_vftable_index;
int GameStudioRenderer__StudioDrawPlayer_vftable_index;
int GameStudioRenderer_StudioRenderModel_vftable_index;
int GameStudioRenderer_StudioRenderFinal_vftable_index;

Expand Down

0 comments on commit 373360e

Please sign in to comment.