Skip to content

Commit

Permalink
Added utility ConCommand to unhide FCVAR_DEVELOPMENTONLY and FCVAR_HI…
Browse files Browse the repository at this point in the history
…DDEN ConVars and ConCommands.
  • Loading branch information
OrsellGaming committed Nov 10, 2024
1 parent 0ad02e8 commit 6602818
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class CPortal_Player;
#define COMMAND_COMPLETION_MAXITEMS 64
#define COMMAND_COMPLETION_ITEM_LENGTH 64

// A macro to iterate through all ConVars and ConCommand in the game.
// Thanks to Nanoman2525 for this.
#define FOR_ALL_CONSOLE_COMMANDS( pCommandVarName ) \
ConCommandBase *m_pConCommandList = *reinterpret_cast<ConCommandBase **>((uintptr_t)g_pCVar + 0x30); /* CCvar::m_pConCommandList */ \
for (ConCommandBase *pCommandVarName = m_pConCommandList; \
pCommandVarName; pCommandVarName = *reinterpret_cast<ConCommandBase **>(reinterpret_cast<uintptr_t>(pCommandVarName) + 0x04)) /* ConCommandBase::m_pNext (private variable) */

// Player team enum.
enum
{
Expand Down
35 changes: 35 additions & 0 deletions p2mm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,41 @@ CON_COMMAND(p2mm_helloworld2, "Hello World 2: Electric Boogaloo!")
UTIL_HudMessage(UTIL_PlayerByIndex(1), helloWorldParams, msg);
}

bool m_ConVarConCommandsShown = false; // Bool to track if the hidden ConVars and ConCommands are showing.
std::vector<ConCommandBase*> toggledCVCCs; // List of toggled ConVars and ConCommands with the FCVAR_DEVELOPMENTONLY and FCVAR_HIDDEN ConVar flags removed.
CON_COMMAND(p2mm_toggle_dev_cc_cvars, "Toggle unhiding or hiding any ConVars and ConCommands that have the FCVAR_DEVELOPMENTONLY and FCVAR_HIDDEN ConVar flags. WARNING: Some of these ConVars and ConCommands are not intended to be manipulated directly, hence why they are hidden. ONLY USE THIS IF YOU KNOW WHAT YOU ARE DOING!")
{
int iToggleCount = 0; // To tell the user how many ConVars and ConCommands where toggle to show or hide.

if (m_ConVarConCommandsShown)
{
// Hide the ConVars and ConCommands
for (ConCommandBase* pCommandVarName : toggledCVCCs)
{
pCommandVarName->AddFlags(FCVAR_DEVELOPMENTONLY | FCVAR_HIDDEN);
iToggleCount++;
}
toggledCVCCs.clear();
m_ConVarConCommandsShown = false;
}
else
{
// Unhide the ConVars and ConCommands
FOR_ALL_CONSOLE_COMMANDS(pCommandVarName)
{
if (pCommandVarName->IsFlagSet(FCVAR_DEVELOPMENTONLY) || pCommandVarName->IsFlagSet(FCVAR_HIDDEN))
{
pCommandVarName->RemoveFlags(FCVAR_DEVELOPMENTONLY | FCVAR_HIDDEN);
iToggleCount++;
toggledCVCCs.push_back(pCommandVarName);
}
}
m_ConVarConCommandsShown = true;
}

P2MMLog(0, false, "%s %i ConVars/ConCommands!", m_ConVarConCommandsShown ? "Unhid" : "Hid", iToggleCount);
}

//---------------------------------------------------------------------------------
// Purpose: constructor
//---------------------------------------------------------------------------------
Expand Down

0 comments on commit 6602818

Please sign in to comment.