allow modifying cheat dvars from exec

fixes #37
This commit is contained in:
quaK 2023-03-30 01:55:40 +03:00
parent 676b377691
commit a37ae3ab8b
3 changed files with 19 additions and 7 deletions

View File

@ -25,7 +25,7 @@ namespace dvar_cheats
}
// if sv_cheats was enabled and it changes to disabled, we need to reset all cheat dvars
else if (dvar->current.enabled && !value->enabled)
/*else if (dvar->current.enabled && !value->enabled)
{
for (auto i = 0; i < *game::dvarCount; ++i)
{
@ -35,7 +35,7 @@ namespace dvar_cheats
game::Dvar_Reset(var, game::DvarSetSource::DVAR_SOURCE_INTERNAL);
}
}
}
}*/ // resets the r_hudOutline dvars, which are cheat dvars for some reason.
}
}
@ -61,20 +61,20 @@ namespace dvar_cheats
if (source == game::DvarSetSource::DVAR_SOURCE_EXTERNAL)
{
const auto cl_ingame = game::CL_IsGameClientActive(0);
const auto sv_running = game::Dvar_FindVar("sv_running");
const auto sv_running = game::SV_Loaded();
if ((dvar->flags & game::DvarFlags::DVAR_FLAG_REPLICATED) && (cl_ingame) && (sv_running && !sv_running->current.enabled))
if ((dvar->flags & game::DvarFlags::DVAR_FLAG_REPLICATED) && cl_ingame && !sv_running)
{
console::error("%s can only be changed by the server\n", dvars::dvar_get_name(dvar).data());
return false;
}
const auto sv_cheats = game::Dvar_FindVar("sv_cheats");
if ((dvar->flags & game::DvarFlags::DVAR_FLAG_CHEAT) && (sv_cheats && !sv_cheats->current.enabled))
if ((dvar->flags & game::DvarFlags::DVAR_FLAG_CHEAT) && ((sv_cheats && !sv_cheats->current.enabled) && *game::isCheatOverride))
{
#ifdef DEBUG
//#ifdef DEBUG
console::error("%s is cheat protected\n", dvars::dvar_get_name(dvar).data());
#endif
//#endif
return false;
}
}

View File

@ -208,6 +208,13 @@ namespace patches
return game::DB_ReadRawFile(filename, buf, size);
}
void cbuf_execute_buffer_internal_stub(int local_client_num, int controller_index, char* buffer, [[maybe_unused]]void* callback)
{
game::Dvar_OverrideCheatProtection(0);
game::Cbuf_ExecuteBufferInternal(local_client_num, controller_index, buffer, game::Cmd_ExecuteSingleCommand);
game::Dvar_OverrideCheatProtection(1);
}
void init_network_dvars_stub(game::dvar_t* dvar)
{
//init_network_dvars_hook.invoke<void>(dvar);
@ -250,6 +257,8 @@ namespace patches
// Allow executing custom cfg files with the "exec" command
utils::hook::call(0xB7CEF9_b, db_read_raw_file_stub);
// Add cheat override to exec
utils::hook::call(0xB7CF11_b, cbuf_execute_buffer_internal_stub);
// don't reset our fov
utils::hook::set<uint8_t>(0x8A6160_b, 0xC3);

View File

@ -98,6 +98,7 @@ namespace game
WEAK symbol<void(dvar_t* dvar, DvarSetSource source)> Dvar_Reset{ 0xCEC490 };
WEAK symbol<unsigned int(const char* name)> Dvar_GenerateChecksum{ 0xCEA520 };
WEAK symbol<void(dvar_t* dvar, int value)> Dvar_SetInt{ 0xCED3D0 };
WEAK symbol<void(bool cheatOverride)> Dvar_OverrideCheatProtection{ 0XCEB250 };
WEAK symbol<__int64(const char* qpath, char** buffer)> FS_ReadFile{ 0xCDE200 };
WEAK symbol<void(char* buffer)> FS_FreeFile{ 0xCDE1F0 };
@ -197,6 +198,8 @@ namespace game
WEAK symbol<int> dvarCount{ 0x7595E54 };
WEAK symbol<dvar_t*> dvarPool{ 0x7595E60 };
WEAK symbol<char> isCheatOverride{ 0x1BBEF28 };
WEAK symbol<gentity_s> g_entities{ 0x3D22610 };
WEAK symbol<unsigned int> svs_numclients{ 0x6B229E0 };