Skip to content

Commit

Permalink
Added bxt_disable_cheats_check_in_demo
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileyAG committed Dec 2, 2023
1 parent d0d183a commit eba65c6
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 0 deletions.
3 changes: 3 additions & 0 deletions BunnymodXT/cvars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
X(fps_max) \
X(default_fov) \
X(skill) \
X(gl_monolights) \
X(r_fullbright) \
X(host_framerate) \
X(sensitivity)

Expand Down Expand Up @@ -59,6 +61,7 @@
X(bxt_fix_mouse_horizontal_limit, "0") \
X(bxt_hud_game_color, "") \
X(bxt_disable_gamedir_check_in_demo, "0") \
X(bxt_disable_cheats_check_in_demo, "0") \
X(bxt_remove_fps_limit, "0") \
X(bxt_cof_disable_save_lock, "0") \
X(bxt_remove_viewmodel, "0") \
Expand Down
132 changes: 132 additions & 0 deletions BunnymodXT/modules/HwDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,21 @@ extern "C" qboolean __cdecl CL_CheckGameDirectory(char *gamedir)
return HwDLL::HOOKED_CL_CheckGameDirectory(gamedir);
}

extern "C" qboolean __cdecl Cvar_Command()
{
return HwDLL::HOOKED_Cvar_Command();
}

extern "C" qboolean __cdecl Cvar_CommandWithPrivilegeCheck(qboolean bIsPrivileged)
{
return HwDLL::HOOKED_Cvar_CommandWithPrivilegeCheck(bIsPrivileged);
}

extern "C" void __cdecl R_ForceCvars(qboolean mp)
{
return HwDLL::HOOKED_R_ForceCvars(mp);
}

extern "C" int __cdecl ValidStuffText(char *buf)
{
return HwDLL::HOOKED_ValidStuffText(buf);
Expand Down Expand Up @@ -458,6 +473,9 @@ void HwDLL::Hook(const std::wstring& moduleName, void* moduleHandle, void* modul
MemUtils::MarkAsExecutable(ORIG_Draw_FillRGBA);
MemUtils::MarkAsExecutable(ORIG_PF_traceline_DLL);
MemUtils::MarkAsExecutable(ORIG_CL_CheckGameDirectory);
MemUtils::MarkAsExecutable(ORIG_Cvar_Command);
MemUtils::MarkAsExecutable(ORIG_Cvar_CommandWithPrivilegeCheck);
MemUtils::MarkAsExecutable(ORIG_R_ForceCvars);
MemUtils::MarkAsExecutable(ORIG_Host_ValidSave);
MemUtils::MarkAsExecutable(ORIG_SaveGameSlot);
MemUtils::MarkAsExecutable(ORIG_SCR_NetGraph);
Expand Down Expand Up @@ -523,6 +541,9 @@ void HwDLL::Hook(const std::wstring& moduleName, void* moduleHandle, void* modul
ORIG_Draw_FillRGBA, HOOKED_Draw_FillRGBA,
ORIG_PF_traceline_DLL, HOOKED_PF_traceline_DLL,
ORIG_CL_CheckGameDirectory, HOOKED_CL_CheckGameDirectory,
ORIG_Cvar_Command, HOOKED_Cvar_Command,
ORIG_Cvar_CommandWithPrivilegeCheck, HOOKED_Cvar_CommandWithPrivilegeCheck,
ORIG_R_ForceCvars, HOOKED_R_ForceCvars,
ORIG_SaveGameSlot, HOOKED_SaveGameSlot,
ORIG_ReleaseEntityDlls, HOOKED_ReleaseEntityDlls,
ORIG_ValidStuffText, HOOKED_ValidStuffText,
Expand Down Expand Up @@ -607,6 +628,9 @@ void HwDLL::Unhook()
ORIG_Draw_FillRGBA,
ORIG_PF_traceline_DLL,
ORIG_CL_CheckGameDirectory,
ORIG_Cvar_Command,
ORIG_Cvar_CommandWithPrivilegeCheck,
ORIG_R_ForceCvars,
ORIG_SaveGameSlot,
ORIG_ReleaseEntityDlls,
ORIG_ValidStuffText,
Expand Down Expand Up @@ -702,6 +726,10 @@ void HwDLL::Clear()
ORIG_Draw_FillRGBA = nullptr;
ORIG_PF_traceline_DLL = nullptr;
ORIG_CL_CheckGameDirectory = nullptr;
ORIG_Cvar_Command = nullptr;
ORIG_Cvar_CommandWithPrivilegeCheck = nullptr;
ORIG_R_ForceCvars = nullptr;
ORIG_GL_BuildLightmaps = nullptr;
ORIG_CL_HudMessage = nullptr;
ORIG_SaveGameSlot = nullptr;
ORIG_SCR_NetGraph = nullptr;
Expand Down Expand Up @@ -1038,6 +1066,30 @@ void HwDLL::FindStuff()
EngineDevMsg("[hw dll] Found CL_CheckGameDirectory at %p.\n", ORIG_CL_CheckGameDirectory);
else
EngineDevWarning("[hw dll] Could not find CL_CheckGameDirectory.\n");

ORIG_Cvar_Command = reinterpret_cast<_Cvar_Command>(MemUtils::GetSymbolAddress(m_Handle, "Cvar_Command"));
if (ORIG_Cvar_Command)
EngineDevMsg("[hw dll] Found Cvar_Command at %p.\n", ORIG_Cvar_Command);
else
EngineDevWarning("[hw dll] Could not find Cvar_Command.\n");

ORIG_Cvar_CommandWithPrivilegeCheck = reinterpret_cast<_Cvar_CommandWithPrivilegeCheck>(MemUtils::GetSymbolAddress(m_Handle, "Cvar_CommandWithPrivilegeCheck"));
if (ORIG_Cvar_CommandWithPrivilegeCheck)
EngineDevMsg("[hw dll] Found Cvar_CommandWithPrivilegeCheck at %p.\n", ORIG_Cvar_CommandWithPrivilegeCheck);
else
EngineDevWarning("[hw dll] Could not find Cvar_CommandWithPrivilegeCheck.\n");

ORIG_R_ForceCvars = reinterpret_cast<_R_ForceCvars>(MemUtils::GetSymbolAddress(m_Handle, "R_ForceCvars"));
if (ORIG_R_ForceCvars)
EngineDevMsg("[hw dll] Found R_ForceCvars at %p.\n", ORIG_R_ForceCvars);
else
EngineDevWarning("[hw dll] Could not find R_ForceCvars.\n");

ORIG_GL_BuildLightmaps = reinterpret_cast<_GL_BuildLightmaps>(MemUtils::GetSymbolAddress(m_Handle, "GL_BuildLightmaps"));
if (ORIG_GL_BuildLightmaps)
EngineDevMsg("[hw dll] Found GL_BuildLightmaps at %p.\n", ORIG_GL_BuildLightmaps);
else
EngineDevWarning("[hw dll] Could not find GL_BuildLightmaps.\n");

ORIG_ValidStuffText = reinterpret_cast<_ValidStuffText>(MemUtils::GetSymbolAddress(m_Handle, "ValidStuffText"));
if (ORIG_ValidStuffText)
Expand Down Expand Up @@ -1325,6 +1377,10 @@ void HwDLL::FindStuff()
DEF_FUTURE(Draw_FillRGBA)
DEF_FUTURE(PF_traceline_DLL)
DEF_FUTURE(CL_CheckGameDirectory)
DEF_FUTURE(Cvar_Command)
DEF_FUTURE(Cvar_CommandWithPrivilegeCheck)
DEF_FUTURE(R_ForceCvars)
DEF_FUTURE(GL_BuildLightmaps)
DEF_FUTURE(SaveGameSlot)
DEF_FUTURE(CL_HudMessage)
DEF_FUTURE(SCR_NetGraph)
Expand Down Expand Up @@ -2297,6 +2353,10 @@ void HwDLL::FindStuff()
GET_FUTURE(Draw_FillRGBA);
GET_FUTURE(PF_traceline_DLL);
GET_FUTURE(CL_CheckGameDirectory);
GET_FUTURE(Cvar_Command);
GET_FUTURE(Cvar_CommandWithPrivilegeCheck);
GET_FUTURE(R_ForceCvars);
GET_FUTURE(GL_BuildLightmaps);
GET_FUTURE(Host_Noclip_f);
GET_FUTURE(Host_Notarget_f);
GET_FUTURE(SaveGameSlot);
Expand Down Expand Up @@ -5337,6 +5397,8 @@ void HwDLL::RegisterCVarsAndCommandsIfNeeded()
RegisterCVar(CVars::bxt_ch_checkpoint_with_vel);
RegisterCVar(CVars::bxt_ch_checkpoint_onground_only);

if (ORIG_Cvar_Command || ORIG_Cvar_CommandWithPrivilegeCheck || ORIG_R_ForceCvars)
RegisterCVar(CVars::bxt_disable_cheats_check_in_demo);
if (ORIG_R_SetFrustum && scr_fov_value)
{
RegisterCVar(CVars::bxt_force_fov);
Expand All @@ -5353,6 +5415,8 @@ void HwDLL::RegisterCVarsAndCommandsIfNeeded()
CVars::fps_max.Assign(FindCVar("fps_max"));
CVars::default_fov.Assign(FindCVar("default_fov"));
CVars::skill.Assign(FindCVar("skill"));
CVars::gl_monolights.Assign(FindCVar("gl_monolights"));
CVars::r_fullbright.Assign(FindCVar("r_fullbright"));
CVars::host_framerate.Assign(FindCVar("host_framerate"));
CVars::sensitivity.Assign(FindCVar("sensitivity"));

Expand Down Expand Up @@ -7770,6 +7834,74 @@ HOOK_DEF_1(HwDLL, qboolean, __cdecl, CL_CheckGameDirectory, char*, gamedir)
return ORIG_CL_CheckGameDirectory(gamedir);
}

HOOK_DEF_0(HwDLL, qboolean, __cdecl, Cvar_Command)
{
int *state;
int orig_state;
bool return_orig_value = false;

// We can avoid the multiplayer check if cls.state <= 1
if (cls && CVars::bxt_disable_cheats_check_in_demo.GetBool() && IsPlayingbackDemo())
{
state = reinterpret_cast<int*>(cls);
orig_state = *state;
*state = 1;
return_orig_value = true;
}

auto ret = ORIG_Cvar_Command();
if (return_orig_value)
*state = orig_state;

return ret;
}

HOOK_DEF_1(HwDLL, qboolean, __cdecl, Cvar_CommandWithPrivilegeCheck, qboolean, bIsPrivileged)
{
int *state;
int orig_state;
bool return_orig_value = false;

// We can avoid the multiplayer check if cls.state <= 1
if (cls && CVars::bxt_disable_cheats_check_in_demo.GetBool() && IsPlayingbackDemo())
{
state = reinterpret_cast<int*>(cls);
orig_state = *state;
*state = 1;
return_orig_value = true;
}

auto ret = ORIG_Cvar_CommandWithPrivilegeCheck(bIsPrivileged);
if (return_orig_value)
*state = orig_state;

return ret;
}

HOOK_DEF_1(HwDLL, void, __cdecl, R_ForceCvars, qboolean, mp)
{
static bool is_monolights_changed = CVars::gl_monolights.GetBool();
static bool is_fullbright_changed = CVars::r_fullbright.GetBool();

if (CVars::bxt_disable_cheats_check_in_demo.GetBool() && IsPlayingbackDemo())
{
if ((is_monolights_changed != CVars::gl_monolights.GetBool()) || (is_fullbright_changed != CVars::r_fullbright.GetBool()))
{
// Update "gl_monolights" and "r_fullbright" in real-time (code from R_ForceCvars does that too!)
if (ORIG_GL_BuildLightmaps)
ORIG_GL_BuildLightmaps();
}
is_monolights_changed = CVars::gl_monolights.GetBool();
is_fullbright_changed = CVars::r_fullbright.GetBool();
return;
}

ORIG_R_ForceCvars(mp);

is_monolights_changed = CVars::gl_monolights.GetBool();
is_fullbright_changed = CVars::r_fullbright.GetBool();
}

HOOK_DEF_0(HwDLL, int, __cdecl, Host_ValidSave)
{
if (cofSaveHack) {
Expand Down
5 changes: 5 additions & 0 deletions BunnymodXT/modules/HwDLL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class HwDLL : public IHookableNameFilterOrdered
HOOK_DECL(void, __cdecl, Draw_FillRGBA, int x, int y, int w, int h, int r, int g, int b, int a)
HOOK_DECL(void, __cdecl, PF_traceline_DLL, const Vector* v1, const Vector* v2, int fNoMonsters, edict_t* pentToSkip, TraceResult* ptr)
HOOK_DECL(qboolean, __cdecl, CL_CheckGameDirectory, char *gamedir)
HOOK_DECL(qboolean, __cdecl, Cvar_Command)
HOOK_DECL(qboolean, __cdecl, Cvar_CommandWithPrivilegeCheck, qboolean bIsPrivileged)
HOOK_DECL(void, __cdecl, R_ForceCvars, qboolean mp)
HOOK_DECL(int, __cdecl, Host_ValidSave)
HOOK_DECL(int, __cdecl, SaveGameSlot, const char* pSaveName, const char* pSaveComment)
HOOK_DECL(void, __cdecl, SCR_NetGraph)
Expand Down Expand Up @@ -420,6 +423,8 @@ class HwDLL : public IHookableNameFilterOrdered
_VGuiWrap2_IsGameUIVisible ORIG_VGuiWrap2_IsGameUIVisible;
typedef void(__cdecl *_SCR_DrawPause) ();
_SCR_DrawPause ORIG_SCR_DrawPause;
typedef void(__cdecl *_GL_BuildLightmaps) ();
_GL_BuildLightmaps ORIG_GL_BuildLightmaps;

void FindStuff();

Expand Down
30 changes: 30 additions & 0 deletions BunnymodXT/patterns.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,36 @@ namespace patterns
"55 8B EC 81 EC 04 01 00 00 83 7D ?? 00 74 ?? 8B 45 ?? 0F BE 08"
);

PATTERNS(Cvar_Command,
"HL-SteamPipe",
"56 6A 00 E8 ?? ?? ?? ?? 50 E8 ?? ?? ?? ?? 83 C4 08 85 C0 74 ?? 50 E8 ?? ?? ?? ?? 83 C4 04 85 C0",
"CoF-5936",
"55 8B EC 83 EC 08 C7 45 ?? 00 00 00 00 6A 00 E8 ?? ?? ?? ?? 83 C4 04 50 E8 ?? ?? ?? ?? 83 C4 04 89 45 ?? 83 7D ?? 00 74 ?? 8B 45"
);

PATTERNS(Cvar_CommandWithPrivilegeCheck,
"HL-SteamPipe-8684",
"55 8B EC 83 EC 14 53 56 57 6A 00 E8 ?? ?? ?? ?? 50 E8 ?? ?? ?? ?? 83 C4 08 85 C0 74 ?? 50"
);

PATTERNS(R_ForceCvars,
"HL-Steampipe",
"55 8B EC 8B 45 ?? 85 C0 0F 84 ?? ?? ?? ?? D9 05 ?? ?? ?? ?? D8 1D ?? ?? ?? ?? DF E0 F6 C4 44 7B ?? 68 ?? ?? ?? ?? 68 ?? ?? ?? ?? E8",
"HL-4554",
"8B 44 24 ?? 85 C0 0F 84 ?? ?? ?? ?? D9 05 ?? ?? ?? ?? D8 1D ?? ?? ?? ?? DF E0 F6 C4 40 75 ?? 68 ?? ?? ?? ?? 68 ?? ?? ?? ?? E8",
"CoF-5936",
"55 8B EC 83 7D ?? 00 0F 84 ?? ?? ?? ?? D9 05 ?? ?? ?? ?? D8 1D ?? ?? ?? ?? DF E0 F6 C4 40 75 ?? 68 ?? ?? ?? ?? 68 ?? ?? ?? ?? E8"
);

PATTERNS(GL_BuildLightmaps,
"HL-Steampipe",
"55 8B EC 51 53 56 57 68 00 80 00 00 6A 00 68 ?? ?? ?? ?? E8 ?? ?? ?? ?? A1 ?? ?? ?? ?? 83 C4 0C BF 01 00 00 00",
"HL-4554",
"51 68 00 80 00 00 6A 00 68 ?? ?? ?? ?? E8 ?? ?? ?? ?? A1 ?? ?? ?? ?? 83 C4 0C B9 01 00 00 00",
"CoF-5936",
"55 8B EC 83 EC 10 68 00 80 00 00 6A 00 68 ?? ?? ?? ?? E8 ?? ?? ?? ?? 83 C4 0C C7 05 ?? ?? ?? ?? 01 00 00 00 83 3D ?? ?? ?? ?? 00"
);

PATTERNS(SaveGameSlot,
"CoF-5936",
"55 8B EC 81 EC 8C 02 00 00 E8 ?? ?? ?? ?? 89 45 FC"
Expand Down

0 comments on commit eba65c6

Please sign in to comment.