r5sdk/r5dev/tier0/IConVar.cpp
IcePixelx dedd7867cd Squashed commit of the following:
commit 4da14d7ddecc0d8c322fc7ee372be67481fb0b99
Author: IcePixelx <41352111+PixieCore@users.noreply.github.com>
Date:   Sat Jan 15 20:13:11 2022 +0100

    Cleaned up native server browser and commented functions.

commit b366e4ce826c9c7dbeb2af26cb6c34656b2c93f2
Author: r-ex <67599507+r-ex@users.noreply.github.com>
Date:   Sat Jan 15 17:57:18 2022 +0000

    sq server browser clean up (#63)

    * sq server browser clean up

    * Properly loop through std::vector on GetAvailableMaps.

    Co-authored-by: IcePixelx <41352111+PixieCore@users.noreply.github.com>

commit 829e122cead5521d5ffa57daa7e9fbd10755d68f
Author: IcePixelx <41352111+PixieCore@users.noreply.github.com>
Date:   Sat Jan 15 15:25:19 2022 +0100

    SQ Serverbrowser V1 push. Clean-up following after @r-ex fixed SQ things.

commit 29fe6be989f176321406e4e521da406e65229acd
Author: IcePixelx <41352111+PixieCore@users.noreply.github.com>
Date:   Fri Jan 14 20:59:06 2022 +0100

    Fix pre-compiled headers for imgui_utility.cpp

commit f2f8a088bfbc8b7311f2efb402963eb3b0802a46
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Fri Jan 14 20:51:32 2022 +0100

    Fix compiler error caused merge from separate branch

commit 1c5df4e178a29234139c3ebf06b25fcd795689ea
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Fri Jan 14 20:45:36 2022 +0100

    Ansi terminal color support + big optimizations on all log systems + 'Warning()' hook

    * Ansi colors can now be enabled with the '-ansiclr- flag.
    * All loggers have been optimized and are all initialized only once at process startup.
    * New hook for 'Warning()' print function with warning level.

commit 012a317c846ba4fcf727ffb97678ee080f2dd976
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Fri Jan 14 15:39:09 2022 +0100

    Update init.cpp

commit a14480e7cfdb869d222da04275f2619ca1405ce3
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Fri Jan 14 15:38:48 2022 +0100

    Update stdafx.h

commit bdc67e90cb5624ee5d9f8a3620fe64a0d80726a5
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Fri Jan 14 15:37:08 2022 +0100

    Set default spdlog level to trace

commit 96ee434d4e58a79a091cb0fee0caa5d838f629df
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Fri Jan 14 15:36:51 2022 +0100

    Fix missing header errors for SpdLog

commit 6bbb16dcb9f821e6f71bbfa9f0b4b12167907f43
Author: IcePixelx <41352111+PixieCore@users.noreply.github.com>
Date:   Fri Jan 14 20:39:11 2022 +0100

    Fix sendrequest crash. Due to htResults being null.

commit 5612c7a3a7e38f725b17e98d17d06f146135feae
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Wed Jan 12 13:11:11 2022 +0100

    This seems no longer needed for dedicated servers

    Shader/texture assets are no longer loaded where the pointer parameters to the asset unloading function won't be out of scope anymore

commit e6254e3a036b26a70b4dc29df7f8a5082a0f5297
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Wed Jan 12 13:09:06 2022 +0100

    Fix issue with ImGui windows where input could loose focus and not work

    'ImGui_ImplWin32_WndProcHandler' has to be called at all times from the HwndProc handler as it has to track all events to prevent issues with input.

commit de3b3f53bd2c32015e9accaed873d06a722ab7da
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Wed Jan 12 02:53:07 2022 +0100

    Optimizations + QoL improvements/cleanup

    * IConsole overlay now clears the oldest log entries to stay under the vector limit instead of clearing the whole vector.
    * IConsole code cleanup.
    * IBrowser code cleanup, reordered class methods.
    * Use ConVar utilities to get/set values for strings in IBrowser and IConsole.
    * New ConVar's for RUI console overlay to tweak colors.

commit 44102abbcca2d088dcb253da8ec7c9b869064139
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Mon Jan 10 02:47:19 2022 +0100

    Execute dev configs when '-devsdk' parameter is passed

commit 8d1023212abd8e2b250f5fb7b33fdfa329b07b40
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Mon Jan 10 02:24:30 2022 +0100

    Small alignment

commit 38d9d431c9aaef1ede7b6ceb594aa9b9971c261f
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Mon Jan 10 02:03:31 2022 +0100

    Fix potential bug where 'cm_return_false_cmdquery_all' cvar would never work

commit c0f24e64ff04bacb8d5b51961de1687dfb75bc71
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Mon Jan 10 01:31:25 2022 +0100

    Rename global cvar pointer

commit 0146f22e0a8bcd7ec137bb205d117cea49f533dc
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Mon Jan 10 01:20:44 2022 +0100

    Implement CommandLine utilities

commit 64c07af6e067bc85385a78981d29770eebd3eb6b
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Sun Jan 9 17:17:05 2022 +0100

    Cleanup to use new ConVar utilities

commit 19f5010bd26e010746436766c05515dff85d7695
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Sun Jan 9 16:29:36 2022 +0100

    Fix compiler error + rename debug dll's

    Rename for easier debugging and config separation

commit c292d8ad46b22c7a34c6d3caf8143e131e8dd997
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Sun Jan 9 16:14:17 2022 +0100

    Implement new ConVar features

    Slight cleanup with new ConVar features to be used throughout the SDK

commit 0177c17da94dc977f85babe2aa8168cefb56bf45
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Sat Jan 8 02:05:33 2022 +0100

    Draw simulation stats and GPU stats to debug text overlay

commit 21a10e201b6ea7afd4ffdd7d6b9668806085b6a5
Author: IcePixelx <41352111+PixieCore@users.noreply.github.com>
Date:   Sun Jan 9 14:36:22 2022 +0100

    Typos.

commit ae09372cc79053f5515529e403402494ffa6dfe4
Author: IcePixelx <41352111+PixieCore@users.noreply.github.com>
Date:   Sun Jan 9 14:35:43 2022 +0100

    Pylon system changes.

commit 98a428ace9226442fa623a0870af9f7e12f35eb0
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Fri Jan 7 01:03:35 2022 +0100

    Fix S2 crash when launching a different version

commit c98301d175b8b1b80b2f480bc29e0703cf12c350
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Thu Jan 6 17:30:10 2022 +0100

    Fix LZHAM recompiling pch for each implementation file

commit b80be10c4dc2c1f27917cd68a2c4c47819ee5fe5
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Thu Jan 6 15:08:39 2022 +0100

    Compile LZHAM with the solution. Fix missing detours files for sdklauncher

commit a0b7bbf3661cc9b4d2d0cdefe9050a78f1c2bc67
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Thu Jan 6 02:22:28 2022 +0100

    Compile Microsoft Detours with the solution

commit 9a3175fb6df047445e26ca3d4692e42f01cbabc8
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Thu Jan 6 01:51:55 2022 +0100

    Fix console input text reclaim to reflect latest ImGui changes

commit 556894b3e3d81e41fa461321a749f50aa0eb169f
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Wed Jan 5 23:50:14 2022 +0100

    Add connect command fix back

    Accidentally removed.

commit 1612c439d2bb68fea29b4804b67c7de7a2aeaed7
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Wed Jan 5 23:44:01 2022 +0100

    Fix project filters

commit 47fdd4211d3088a84aeb93e425288928d1b37e70
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Wed Jan 5 23:43:51 2022 +0100

    Fix for S3

    For some reason the same byte pattern wasn't found in the miles dll for the S3 game, even though they where identical. Changed the byte patterns to search for the last 2 bytes of the instruction as well and made the conditional jmp instructions, unconditional for making sure mileswin64.dll doesn't close the process when a debugger is found.

commit d52bd5eeec4f9f86422b3864446521c4ca46f02b
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Wed Jan 5 22:56:49 2022 +0100

    Initial support for S1

commit 7c3994dfc280d8312632c9256f40a776c13158a4
Author: IcePixelx <41352111+PixieCore@users.noreply.github.com>
Date:   Wed Jan 5 19:23:53 2022 +0100

    dedicated refuselist

commit c486c2d59354b3672709013c24454017fdce5cf2
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Wed Jan 5 02:07:37 2022 +0100

    Portability to S2 completed

    CServer functions are evolving quite heavily over these seasons, so these need a bit of work

commit fbcea85631fe9ee1b378a3fc6657908230b85403
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Tue Jan 4 12:11:59 2022 +0100

    Fix compiler error caused by merging commits from different branches

commit 84e7729ca045c05e4add7f05d09d032833e39a7b
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Tue Jan 4 11:53:54 2022 +0100

    Add client and debug utilities + cleanup

commit 477152b35443246dace6f5b4deccd52ea1cc6e9c
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Fri Dec 31 03:45:48 2021 +0100

    Fix compiler error

commit 5f664d8e6ba9a2e0bd72c29c5f4ba5279e29e75a
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Fri Dec 31 03:41:33 2021 +0100

    Create signatures for all used Dedicated functions

commit 2c7ced128d8c48a5abf8fd64dbb06909dc632f35
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Thu Dec 30 22:13:15 2021 +0100

    Heavy dedicated cleanup

    * Since the material mode is set to '2', all of the render loops and shader loading functions are no longer called. These have all been removed.
    * Added description for patches that missed them
    * Traced root caller/cause for certain patches to skip even more unnecessary code and save more memory.

commit 22c0b5c867664a2524c18d865dbc54ff067dda22
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Thu Dec 30 17:20:41 2021 +0100

    Dedicated server improvements

commit 6d4f7e345f38872ce45751604b40871b969cec8f
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Thu Dec 30 02:47:42 2021 +0100

    Fix a typo

commit 39a8a8fd30612522a274e1474c9a66e5019aeea3
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Thu Dec 30 02:36:43 2021 +0100

    Implement patch to enable 'DrawAllOverlays()'.

commit 83129e88f8a6033f8f4c13e3cac639097068cb3c
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Wed Dec 29 22:59:34 2021 +0100

    Fix LLVM compiler error

commit c48ed7f7a53a9985e3c2642db3639007d7c9129a
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Wed Dec 29 18:06:37 2021 +0100

    Rename dedicated variables

commit d1ba2bd56720a0776824a8e309d7d859704244bc
Author: IcePixelx <41352111+PixieCore@users.noreply.github.com>
Date:   Wed Dec 29 15:35:48 2021 +0100

    Fixed changelevel, needs more research tho.

commit 46950125716c05171f25a12d8805811112e90551
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Wed Dec 29 13:58:03 2021 +0100

    Fix 'C_PropDoor' not spawning properly on the server

commit 6a9a00735a9d4b8c415acc248c83e6e8d6dc2ff1
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Wed Dec 29 13:57:16 2021 +0100

    Rename hooked command callbacks

commit b514f928a69a9c4ac1d3d1e5c662f93a1f0d131d
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Wed Dec 29 02:16:21 2021 +0100

    Use a separate executable for dedicated server

    The dedicated server still has directx dll imports which will cause issues with ReShade or 3DMigoto, or trying to load it on a headless machine with no directx installed. The imports have to be cleared to avoid issues. The most convenient approach is to do this with a separate exe rather then patching it in runtime.

commit bc8f9400d3911e360757059700a31510e329546d
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Wed Dec 29 00:18:56 2021 +0100

    Fix collisions for headless dedicated server

commit 0e36aa647ffb15ca4f8c76b0431f7c3a83741d80
Author: Amos <48657826+Mauler125@users.noreply.github.com>
Date:   Tue Dec 28 20:19:17 2021 +0100

    Dedicated without ShaderApi and DirectX pre-alpha

    The instruction at 'CalcPropStaticFrustumCull' [0x14028F3B0 + 0x5C7] moves RSP + 0x70 into the R13 register.
    RSP + 0x70 seems to contain a pointer to collission data for that particular prop model.
    When running NoShaderApi() and passing the dedicated server the '-noshaderapi' command line parameter, RSP + 0x70 will be a nullptr.
    This has to be fixed to have prop static collissions on the server.
2022-01-15 21:16:20 +01:00

619 lines
24 KiB
C++

//=============================================================================//
//
// Purpose: Console Variables
//
//=============================================================================//
#include "core/stdafx.h"
#include "tier0/cvar.h"
#include "tier0/IConVar.h"
#include "engine/sys_utils.h"
#include "engine/sys_dll2.h"
#include "mathlib/bits.h"
//-----------------------------------------------------------------------------
// purpose: construct/allocate
//-----------------------------------------------------------------------------
ConVar::ConVar(const char* pszName, const char* pszDefaultValue, int nFlags, const char* pszHelpString, bool bMin, float fMin, bool bMax, float fMax, void* pCallback, void* unk)
{
ConVar* allocatedConvar = reinterpret_cast<ConVar*>(MemAlloc_Wrapper(0xA0)); // Allocate new memory with StdMemAlloc else we crash.
memset(allocatedConvar, 0, 0xA0); // Set all to null.
std::uintptr_t cvarPtr = reinterpret_cast<std::uintptr_t>(allocatedConvar); // To ptr.
*(void**)(cvarPtr + 0x40) = g_pIConVarVtable.RCast<void*>(); // 0x40 to ICvar table.
*(void**)cvarPtr = g_pConVarVtable.RCast<void*>(); // 0x0 to ConVar vtable.
p_ConVar_Register.RCast<void(*)(ConVar*, const char*, const char*, int, const char*, bool, float, bool, float, void*, void*)>()
(allocatedConvar, pszName, pszDefaultValue, nFlags, pszHelpString, bMin, fMin, bMax, fMax, pCallback, unk); // Call to create ConVar.
*this = *allocatedConvar;
}
//-----------------------------------------------------------------------------
// purpose: destructor
//-----------------------------------------------------------------------------
ConVar::~ConVar(void)
{
if (m_pzsCurrentValue)
{
delete[] m_pzsCurrentValue;
m_pzsCurrentValue = NULL;
}
}
//-----------------------------------------------------------------------------
// Purpose: register ConVar
//-----------------------------------------------------------------------------
void ConVar::Init(void)
{
//-------------------------------------------------------------------------
// ENGINE |
cm_debug_cmdquery = new ConVar("cm_debug_cmdquery", "0", FCVAR_DEVELOPMENTONLY, "Prints the flags of each ConVar/ConCommand query to the console ( !slower! ).", false, 0.f, false, 0.f, nullptr, nullptr);
cm_return_false_cmdquery_all = new ConVar("cm_return_false_cmdquery_all", "0", FCVAR_DEVELOPMENTONLY, "Returns false on every ConVar/ConCommand query ( !warning! ).", false, 0.f, false, 0.f, nullptr, nullptr);
cm_return_false_cmdquery_cheats = new ConVar("cm_return_false_cmdquery_cheats", "0", FCVAR_DEVELOPMENTONLY, "Returns false on all FCVAR_DEVELOPMENTONLY and FCVAR_CHEAT ConVar/ConCommand queries ( !warning! ).", false, 0.f, false, 0.f, nullptr, nullptr);
r_debug_overlay_nodecay = new ConVar("r_debug_overlay_nodecay", "0", FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT, "Keeps all debug overlays alive regardless of their lifetime. Use command 'clear_debug_overlays' to clear everything.", false, 0.f, false, 0.f, nullptr, nullptr);
//-------------------------------------------------------------------------
// SERVER |
sv_showconnecting = new ConVar("sv_showconnecting", "1", FCVAR_RELEASE, "Logs information about the connecting client to the console.", false, 0.f, false, 0.f, nullptr, nullptr);
sv_pylonvisibility = new ConVar("sv_pylonvisibility", "0", FCVAR_RELEASE, "Determines the visiblity to the Pylon Master Server, 0 = Not visible, 1 = Visible, 2 = Hidden BUG BUG: not implemented yet.", false, 0.f, false, 0.f, nullptr, nullptr);
//-------------------------------------------------------------------------
// CLIENT |
cl_drawconsoleoverlay = new ConVar("cl_drawconsoleoverlay", "0", FCVAR_DEVELOPMENTONLY, "Draw the console overlay at the top of the screen.", false, 0.f, false, 0.f, nullptr, nullptr);
cl_consoleoverlay_lines = new ConVar("cl_consoleoverlay_lines", "3", FCVAR_DEVELOPMENTONLY, "Number of lines of console output to draw.", false, 0.f, false, 0.f, nullptr, nullptr);
cl_consoleoverlay_offset_x = new ConVar("cl_consoleoverlay_offset_x", "10", FCVAR_DEVELOPMENTONLY, "X offset for console overlay.", false, 1.f, false, 50.f, nullptr, nullptr);
cl_consoleoverlay_offset_y = new ConVar("cl_consoleoverlay_offset_y", "10", FCVAR_DEVELOPMENTONLY, "Y offset for console overlay.", false, 1.f, false, 50.f, nullptr, nullptr);
cl_consoleoverlay_native_clr = new ConVar("cl_consoleoverlay_native_clr", "255 255 255 255", FCVAR_DEVELOPMENTONLY, "Native RUI console overlay log color.", false, 1.f, false, 50.f, nullptr, nullptr);
cl_consoleoverlay_server_clr = new ConVar("cl_consoleoverlay_server_clr", "190 183 240 255", FCVAR_DEVELOPMENTONLY, "Server script VM RUI console overlay log color.", false, 1.f, false, 50.f, nullptr, nullptr);
cl_consoleoverlay_client_clr = new ConVar("cl_consoleoverlay_client_clr", "117 116 139 255", FCVAR_DEVELOPMENTONLY, "Client script VM RUI console overlay log color.", false, 1.f, false, 50.f, nullptr, nullptr);
cl_consoleoverlay_ui_clr = new ConVar("cl_consoleoverlay_ui_clr", "197 160 177 255", FCVAR_DEVELOPMENTONLY, "UI script VM RUI console overlay log color.", false, 1.f, false, 50.f, nullptr, nullptr);
cl_showsimstats = new ConVar("cl_showsimstats", "0", FCVAR_DEVELOPMENTONLY, "Shows the tick counter for the server/client simulation and the render frame.", false, 0.f, false, 0.f, nullptr, nullptr);
cl_simstats_offset_x = new ConVar("cl_simstats_offset_x", "1250", FCVAR_DEVELOPMENTONLY, "X offset for simulation debug overlay.", false, 0.f, false, 0.f, nullptr, nullptr);
cl_simstats_offset_y = new ConVar("cl_simstats_offset_y", "885", FCVAR_DEVELOPMENTONLY, "Y offset for simulation debug overlay.", false, 0.f, false, 0.f, nullptr, nullptr);
cl_showgpustats = new ConVar("cl_showgpustats", "0", FCVAR_DEVELOPMENTONLY, "Texture streaming debug overlay.", false, 0.f, false, 0.f, nullptr, nullptr);
cl_gpustats_offset_x = new ConVar("cl_gpustats_offset_x", "1250", FCVAR_DEVELOPMENTONLY, "X offset for texture streaming debug overlay.", false, 0.f, false, 0.f, nullptr, nullptr);
cl_gpustats_offset_y = new ConVar("cl_gpustats_offset_y", "900", FCVAR_DEVELOPMENTONLY, "Y offset for texture streaming debug overlay.", false, 0.f, false, 0.f, nullptr, nullptr);
//-------------------------------------------------------------------------
// FILESYSTEM |
fs_warning_level_native = new ConVar("fs_warning_level_native", "0", FCVAR_DEVELOPMENTONLY, "Set the filesystem warning level.", false, 0.f, false, 0.f, nullptr, nullptr);
fs_show_warning_output = new ConVar("fs_show_warning_output", "0", FCVAR_DEVELOPMENTONLY, "Logs the filesystem warnings to the console, filtered by 'fs_warning_level_native' ( !slower! ).", false, 0.f, false, 0.f, nullptr, nullptr);
fs_packedstore_entryblock_stats = new ConVar("fs_packedstore_entryblock_stats", "0", FCVAR_DEVELOPMENTONLY, "If set to 1, prints the stats of each file entry in the VPK during decompression ( !slower! ).", false, 0.f, false, 0.f, nullptr, nullptr);
//-------------------------------------------------------------------------
// FILESYSTEM |
mat_showdxoutput = new ConVar("mat_showdxoutput", "0", FCVAR_DEVELOPMENTONLY, "Shows debug output for the DirectX system.", false, 0.f, false, 0.f, nullptr, nullptr);
//-------------------------------------------------------------------------
// SQUIRREL |
sq_showrsonloading = new ConVar("sq_showrsonloading", "0", FCVAR_DEVELOPMENTONLY, "Logs all 'rson' files loaded by the SQVM ( !slower! ).", false, 0.f, false, 0.f, nullptr, nullptr);
sq_showscriptloading = new ConVar("sq_showscriptloading", "0", FCVAR_DEVELOPMENTONLY, "Logs all scripts loaded by the SQVM to be pre-compiled ( !slower! ).", false, 0.f, false, 0.f, nullptr, nullptr);
sq_showvmoutput = new ConVar("sq_showvmoutput", "1", FCVAR_DEVELOPMENTONLY, "Prints the VM output to the console. 1 = Log to file. 2 = 1 + log to console. 3 = 1 + 2 + log to overhead console. 4 = only log to overhead console.", false, 0.f, false, 0.f, nullptr, nullptr);
sq_showvmwarning = new ConVar("sq_showvmwarning", "0", FCVAR_DEVELOPMENTONLY, "Prints the VM warning output to the console. 1 = Log to file. 2 = 1 + log to console.", false, 0.f, false, 0.f, nullptr, nullptr);
//-------------------------------------------------------------------------
// NETCHANNEL |
net_userandomkey = new ConVar("net_userandomkey", "1", FCVAR_RELEASE, "If set to 1, the netchannel generates and sets a random base64 netkey.", false, 0.f, false, 0.f, nullptr, nullptr);
r5net_matchmaking_hostname = new ConVar("r5net_matchmaking_hostname", "r5a-comp-sv.herokuapp.com", FCVAR_RELEASE, "Holds the R5Net matchmaking hostname.", false, 0.f, false, 0.f, nullptr, nullptr);
r5net_show_debug = new ConVar("r5net_show_debug", "1", FCVAR_DEVELOPMENTONLY, "Shows debug output for R5Net.", false, 0.f, false, 0.f, nullptr, nullptr);
}
//-----------------------------------------------------------------------------
// Purpose: Returns the base ConVar name.
// Output : const char*
//-----------------------------------------------------------------------------
const char* ConVar::GetBaseName(void)
{
return m_pParent->m_ConCommandBase.m_pszName;
}
//-----------------------------------------------------------------------------
// Purpose: Returns the ConVar help text.
// Output : const char*
//-----------------------------------------------------------------------------
const char* ConVar::GetHelpText(void)
{
return m_pParent->m_ConCommandBase.m_pszHelpString;
}
//-----------------------------------------------------------------------------
// Purpose: Add's flags to ConVar.
// Input : nFlags -
//-----------------------------------------------------------------------------
void ConVar::AddFlags(int nFlags)
{
m_pParent->m_ConCommandBase.m_nFlags |= nFlags;
}
//-----------------------------------------------------------------------------
// Purpose: Removes flags from ConVar.
// Input : nFlags -
//-----------------------------------------------------------------------------
void ConVar::RemoveFlags(int nFlags)
{
m_ConCommandBase.m_nFlags &= ~nFlags;
}
//-----------------------------------------------------------------------------
// Purpose: Checks if ConVar is registered.
// Output : bool
//-----------------------------------------------------------------------------
bool ConVar::IsRegistered(void)
{
return m_pParent->m_ConCommandBase.m_bRegistered;
}
//-----------------------------------------------------------------------------
// Purpose: Return ConVar value as a boolean.
// Output : bool
//-----------------------------------------------------------------------------
bool ConVar::GetBool(void)
{
return !!GetInt();
}
//-----------------------------------------------------------------------------
// Purpose: Return ConVar value as a float.
// Output : float
//-----------------------------------------------------------------------------
float ConVar::GetFloat(void)
{
return m_pParent->m_flValue;
}
//-----------------------------------------------------------------------------
// Purpose: Return ConVar value as an integer.
// Output : int
//-----------------------------------------------------------------------------
int ConVar::GetInt(void)
{
return m_pParent->m_iValue;
}
//-----------------------------------------------------------------------------
// Purpose: Return ConVar value as a color.
// Output : Color
//-----------------------------------------------------------------------------
Color ConVar::GetColor(void)
{
unsigned char* pColorElement = ((unsigned char*)&m_pParent->m_iValue);
return Color(pColorElement[0], pColorElement[1], pColorElement[2], pColorElement[3]);
}
//-----------------------------------------------------------------------------
// Purpose: Return ConVar value as a string.
// Output : const char *
//-----------------------------------------------------------------------------
const char* ConVar::GetString(void)
{
if (m_ConCommandBase.m_nFlags & FCVAR_NEVER_AS_STRING)
{
return "FCVAR_NEVER_AS_STRING";
}
char const* str = m_pParent->m_pzsCurrentValue;
return str ? str : "";
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : flMinVal -
// Output : true if there is a min set.
//-----------------------------------------------------------------------------
bool ConVar::GetMin(float& flMinVal)
{
flMinVal = m_pParent->m_flMinValue;
return m_pParent->m_bHasMin;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : flMaxVal -
// Output : true if there is a max set.
//-----------------------------------------------------------------------------
bool ConVar::GetMax(float& flMaxVal)
{
flMaxVal = m_pParent->m_flMaxValue;
return m_pParent->m_bHasMax;
}
//-----------------------------------------------------------------------------
// Purpose: returns the min value.
// Output : float
//-----------------------------------------------------------------------------
float ConVar::GetMinValue(void)
{
return m_pParent->m_flMinValue;
}
//-----------------------------------------------------------------------------
// Purpose: returns the max value.
// Output : float
//-----------------------------------------------------------------------------
float ConVar::GetMaxValue(void)
{
return m_pParent->m_flMaxValue;;
}
//-----------------------------------------------------------------------------
// Purpose: checks if ConVar has min value.
// Output : bool
//-----------------------------------------------------------------------------
bool ConVar::HasMin(void)
{
return m_pParent->m_bHasMin;
}
//-----------------------------------------------------------------------------
// Purpose: checks if ConVar has max value.
// Output : bool
//-----------------------------------------------------------------------------
bool ConVar::HasMax(void)
{
return m_pParent->m_bHasMax;
}
//-----------------------------------------------------------------------------
// Purpose: sets the ConVar int value.
// Input : nValue -
//-----------------------------------------------------------------------------
void ConVar::SetValue(int nValue)
{
if (nValue == m_iValue)
{
return;
}
// Only valid for root ConVars.
assert(m_pParent == this);
float flValue = (float)nValue;
// Check bounds.
if (ClampValue(flValue))
{
nValue = (int)(flValue);
}
// Redetermine value.
float flOldValue = m_flValue;
m_flValue = flValue;
m_iValue = nValue;
if (!(m_ConCommandBase.m_nFlags & FCVAR_NEVER_AS_STRING))
{
char szTempValue[32];
snprintf(szTempValue, sizeof(szTempValue), "%d", m_iValue);
ChangeStringValue(szTempValue, flOldValue);
}
}
//-----------------------------------------------------------------------------
// Purpose: sets the ConVar float value.
// Input : flValue -
//-----------------------------------------------------------------------------
void ConVar::SetValue(float flValue)
{
if (flValue == m_flValue)
{
return;
}
// Only valid for root ConVars.
assert(m_pParent == this);
// Check bounds.
ClampValue(flValue);
// Redetermine value.
float flOldValue = m_flValue;
m_flValue = flValue;
m_iValue = (int)m_flValue;
if (!(m_ConCommandBase.m_nFlags & FCVAR_NEVER_AS_STRING))
{
char szTempValue[32];
snprintf(szTempValue, sizeof(szTempValue), "%f", m_flValue);
ChangeStringValue(szTempValue, flOldValue);
}
}
//-----------------------------------------------------------------------------
// Purpose: sets the ConVar string value.
// Input : *szValue -
//-----------------------------------------------------------------------------
void ConVar::SetValue(const char* pszValue)
{
if (strcmp(this->m_pParent->m_pzsCurrentValue, pszValue) == 0)
{
return;
}
this->m_pParent->m_pzsCurrentValue = pszValue;
char szTempValue[32]{};
const char* pszNewValue{};
// Only valid for root convars.
assert(m_pParent == this);
float flOldValue = m_flValue;
pszNewValue = (char*)pszValue;
if (!pszNewValue)
{
pszNewValue = "";
}
if (!SetColorFromString(pszValue))
{
// Not a color, do the standard thing
float flNewValue = (float)atof(pszValue);
if (!IsFinite(flNewValue))
{
DevMsg(eDLL_T::ENGINE ,"Warning: ConVar '%s' = '%s' is infinite, clamping value.\n", GetBaseName(), pszValue);
flNewValue = FLT_MAX;
}
if (ClampValue(flNewValue))
{
snprintf(szTempValue, sizeof(szTempValue), "%f", flNewValue);
pszNewValue = szTempValue;
}
// Redetermine value
m_flValue = flNewValue;
m_iValue = (int)(m_flValue);
}
if (!(m_ConCommandBase.m_nFlags & FCVAR_NEVER_AS_STRING))
{
ChangeStringValue(pszNewValue, flOldValue);
}
}
//-----------------------------------------------------------------------------
// Purpose: sets the ConVar color value.
// Input : clValue -
//-----------------------------------------------------------------------------
void ConVar::SetValue(Color clValue)
{
std::string svResult = "";
for (int i = 0; i < 4; i++)
{
if (!(clValue._color[i] == 0 && svResult.size() == 0))
{
svResult += std::to_string(clValue._color[i]);
svResult.append(" ");
}
}
this->m_pParent->m_pzsCurrentValue = svResult.c_str();
}
//-----------------------------------------------------------------------------
// Purpose: Reset to default value.
//-----------------------------------------------------------------------------
void ConVar::Revert(void)
{
this->SetValue(this->m_pszDefaultValue);
}
//-----------------------------------------------------------------------------
// Purpose: returns the default ConVar value.
// Output : const char
//-----------------------------------------------------------------------------
const char* ConVar::GetDefault(void)
{
return m_pParent->m_pszDefaultValue;
}
//-----------------------------------------------------------------------------
// Purpose: sets the default ConVar value.
// Input : *pszDefault -
//-----------------------------------------------------------------------------
void ConVar::SetDefault(const char* pszDefault)
{
static const char* pszEmpty = "";
m_pszDefaultValue = pszDefault ? pszDefault : pszEmpty;
assert(m_pszDefaultValue);
}
//-----------------------------------------------------------------------------
// Purpose: changes the ConVar string value.
// Input : *pszTempVal - flOldValue
//-----------------------------------------------------------------------------
void ConVar::ChangeStringValue(const char* pszTempVal, float flOldValue)
{
assert(!(m_ConCommandBase.m_nFlags & FCVAR_NEVER_AS_STRING));
char* pszOldValue = (char*)_malloca(m_iStringLength);
if (pszOldValue != NULL)
{
memcpy(pszOldValue, m_pzsCurrentValue, m_iStringLength);
}
if (pszTempVal)
{
int len = strlen(pszTempVal) + 1;
if (len > m_iStringLength)
{
if (m_pzsCurrentValue)
{
delete[] m_pzsCurrentValue;
}
m_pzsCurrentValue = new char[len];
m_iStringLength = len;
}
memcpy((char*)m_pzsCurrentValue, pszTempVal, len);
}
else
{
m_pzsCurrentValue = NULL;
}
pszOldValue = 0;
}
//-----------------------------------------------------------------------------
// Purpose: sets the ConVar color value from string.
// Input : *pszValue -
//-----------------------------------------------------------------------------
bool ConVar::SetColorFromString(const char* pszValue)
{
bool bColor = false;
// Try pulling RGBA color values out of the string.
int nRGBA[4]{};
int nParamsRead = sscanf_s(pszValue, "%i %i %i %i", &(nRGBA[0]), &(nRGBA[1]), &(nRGBA[2]), &(nRGBA[3]));
if (nParamsRead >= 3)
{
// This is probably a color!
if (nParamsRead == 3)
{
// Assume they wanted full alpha.
nRGBA[3] = 255;
}
if (nRGBA[0] >= 0 && nRGBA[0] <= 255 &&
nRGBA[1] >= 0 && nRGBA[1] <= 255 &&
nRGBA[2] >= 0 && nRGBA[2] <= 255 &&
nRGBA[3] >= 0 && nRGBA[3] <= 255)
{
//printf("*** WOW! Found a color!! ***\n");
// This is definitely a color!
bColor = true;
// Stuff all the values into each byte of our int.
unsigned char* pColorElement = ((unsigned char*)&m_iValue);
pColorElement[0] = nRGBA[0];
pColorElement[1] = nRGBA[1];
pColorElement[2] = nRGBA[2];
pColorElement[3] = nRGBA[3];
// Copy that value into our float.
m_flValue = (float)(m_iValue);
}
}
return bColor;
}
//-----------------------------------------------------------------------------
// Purpose: Check whether to clamp and then perform clamp.
// Input : flValue -
// Output : Returns true if value changed.
//-----------------------------------------------------------------------------
bool ConVar::ClampValue(float& flValue)
{
if (m_bHasMin && (flValue < m_flMinValue))
{
flValue = m_flMinValue;
return true;
}
if (m_bHasMax && (flValue > m_flMaxValue))
{
flValue = m_flMaxValue;
return true;
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: Test each ConVar query before setting the value.
// Input : *pConVar - nFlags
// Output : False if change is permitted, true if not.
//-----------------------------------------------------------------------------
bool ConVar::IsFlagSet(ConVar* pConVar, int nFlags)
{
if (cm_debug_cmdquery->GetBool())
{
printf("--------------------------------------------------\n");
printf(" Flaged: %08X\n", pConVar->m_ConCommandBase.m_nFlags);
}
if (cm_return_false_cmdquery_cheats->GetBool())
{
// Mask off FCVAR_CHEATS and FCVAR_DEVELOPMENTONLY.
pConVar->m_ConCommandBase.RemoveFlags(FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT);
}
else // Mask off FCVAR_DEVELOPMENTONLY.
{
pConVar->m_ConCommandBase.RemoveFlags(FCVAR_DEVELOPMENTONLY);
}
if (cm_debug_cmdquery->GetBool())
{
printf(" Masked: %08X\n", pConVar->m_ConCommandBase.m_nFlags);
printf(" Verify: %08X\n", nFlags);
printf("--------------------------------------------------\n");
}
if (nFlags & FCVAR_RELEASE && !cm_return_false_cmdquery_all->GetBool())
{
// Default retail behaviour.
return IConVar_IsFlagSet(pConVar, nFlags);
}
if (cm_return_false_cmdquery_all->GetBool())
{
// Returning false on all queries may cause problems.
return false;
}
// Return false on every FCVAR_DEVELOPMENTONLY query.
return pConVar->m_ConCommandBase.HasFlags(nFlags) != 0;
}
//-----------------------------------------------------------------------------
// Purpose: clear all hostname ConVar's.
//-----------------------------------------------------------------------------
void ConVar::ClearHostNames(void)
{
const char* pszHostnameArray[] =
{
"pin_telemetry_hostname",
"assetdownloads_hostname",
"users_hostname",
"persistence_hostname",
"speechtotexttoken_hostname",
"communities_hostname",
"persistenceDef_hostname",
"party_hostname",
"speechtotext_hostname",
"serverReports_hostname",
"subscription_hostname",
"steamlink_hostname",
"staticfile_hostname",
"matchmaking_hostname",
"skill_hostname",
"publication_hostname",
"stats_hostname"
};
for (int i = 0; i < 17; i++)
{
const char* pszName = pszHostnameArray[i];
ConVar* pCVar = g_pCVar->FindVar(pszName);
if (pCVar != nullptr)
{
pCVar->m_pzsCurrentValue = "0.0.0.0";
}
}
}
///////////////////////////////////////////////////////////////////////////////
void IConVar_Attach()
{
DetourAttach((LPVOID*)&IConVar_IsFlagSet, &ConVar::IsFlagSet);
}
void IConVar_Detach()
{
DetourDetach((LPVOID*)&IConVar_IsFlagSet, &ConVar::IsFlagSet);
}
///////////////////////////////////////////////////////////////////////////////
ConVar* g_pConVar = new ConVar();