Skip to content

Commit

Permalink
Add sv_cheats check for Renderer / BulletPhysics debug view.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Feb 20, 2024
1 parent 0f3951e commit d1c12d7
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 178 deletions.
17 changes: 16 additions & 1 deletion Plugins/BulletPhysics/exportfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ cvar_t *bv_ragdoll_sleepaftertime = NULL;
cvar_t *bv_ragdoll_sleeplinearvel = NULL;
cvar_t *bv_ragdoll_sleepangularvel = NULL;
cvar_t *chase_active = NULL;
cvar_t* sv_cheats = NULL;

const int RagdollRenderState_None = 0;
const int RagdollRenderState_Monster = 1;
Expand All @@ -57,6 +58,16 @@ cl_entity_t* r_worldentity = NULL;

model_t* CounterStrike_RedirectPlayerModel(model_t* original_model, int PlayerNumber, int* modelindex);

bool AllowCheats()
{
if (g_iEngineType == ENGINE_SVENGINE)
{
return (*allow_cheats) != 0;
}

return (sv_cheats->value != 0) ? true : false;
}

typedef enum
{
ACT_RESET,
Expand Down Expand Up @@ -1384,6 +1395,7 @@ void HUD_Init(void)
bv_ragdoll_sleeplinearvel = gEngfuncs.pfnRegisterVariable("bv_ragdoll_sleeplinearvel", "5", FCVAR_CLIENTDLL | FCVAR_ARCHIVE);
bv_ragdoll_sleepangularvel = gEngfuncs.pfnRegisterVariable("bv_ragdoll_sleepangularvel", "3", FCVAR_CLIENTDLL | FCVAR_ARCHIVE);

sv_cheats = gEngfuncs.pfnGetCvarPointer("sv_cheats");
chase_active = gEngfuncs.pfnGetCvarPointer("chase_active");
cl_minmodels = gEngfuncs.pfnGetCvarPointer("cl_minmodels");
cl_min_ct = gEngfuncs.pfnGetCvarPointer("cl_min_ct");
Expand Down Expand Up @@ -1573,7 +1585,10 @@ void HUD_DrawNormalTriangles(void)
{
gExportfuncs.HUD_DrawNormalTriangles();

gPhysicsManager.DebugDraw();
if (AllowCheats())
{
gPhysicsManager.DebugDraw();
}
}

void HUD_CreateEntities(void)
Expand Down
3 changes: 2 additions & 1 deletion Plugins/BulletPhysics/exportfuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ void HUD_Shutdown(void);
void HUD_CreateEntities(void);

msurface_t* GetWorldSurfaceByIndex(int index);
int GetWorldSurfaceIndex(msurface_t* surf);
int GetWorldSurfaceIndex(msurface_t* surf);
bool AllowCheats();
38 changes: 38 additions & 0 deletions Plugins/BulletPhysics/privatehook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ void* mod_known = NULL;
int* mod_numknown = NULL;
TEMPENTITY* gTempEnts = NULL;

//Sven Co-op only
int* allow_cheats = NULL;

int* g_iUser1 = NULL;
int* g_iUser2 = NULL;

Expand Down Expand Up @@ -149,6 +152,41 @@ void Engine_FillAddreess(void)
}
}

if (g_iEngineType == ENGINE_SVENGINE)
{
auto CL_Set_ServerExtraInfo = g_pMetaHookAPI->FindCLParseFuncByName("svc_sendextrainfo");

Sig_VarNotFound(CL_Set_ServerExtraInfo);

g_pMetaHookAPI->DisasmRanges(CL_Set_ServerExtraInfo, 0x100, [](void* inst, PUCHAR address, size_t instLen, int instCount, int depth, PVOID context)
{
auto pinst = (cs_insn*)inst;

if (pinst->id == X86_INS_MOV &&
pinst->detail->x86.op_count == 2 &&
pinst->detail->x86.operands[0].type == X86_OP_MEM &&
pinst->detail->x86.operands[1].type == X86_OP_REG &&
pinst->detail->x86.operands[1].reg == X86_REG_EAX)
{
allow_cheats = (decltype(allow_cheats))pinst->detail->x86.operands[0].mem.disp;
}

if (allow_cheats)
return TRUE;

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

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

return FALSE;

}, 0, NULL);

Sig_VarNotFound(allow_cheats);
}

if (g_iEngineType == ENGINE_SVENGINE)
{
#define CL_VIEWENTITY_SIG_SVENGINE "\x68\x2A\x2A\x2A\x2A\x50\x6A\x06\xFF\x35\x2A\x2A\x2A\x2A\xE8"
Expand Down
2 changes: 2 additions & 0 deletions Plugins/BulletPhysics/privatehook.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ extern void *mod_known;
extern int *mod_numknown;
extern TEMPENTITY *gTempEnts;

extern int* allow_cheats;

extern int *g_iUser1;
extern int *g_iUser2;

Expand Down
Loading

0 comments on commit d1c12d7

Please sign in to comment.