aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2022-05-10 01:25:10 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2022-05-10 01:25:10 +0100
commit4f29baf18ca6ec7abe87724682c95f1ab3a26808 (patch)
treecc9528c6ac866ba62225ad2ed4bc974636bb518b /NorthstarDedicatedTest
parent8b74f2021cb89615b5dabd9b86124ab5812c91ed (diff)
downloadNorthstarLauncher-4f29baf18ca6ec7abe87724682c95f1ab3a26808.tar.gz
NorthstarLauncher-4f29baf18ca6ec7abe87724682c95f1ab3a26808.zip
add cvar help and find
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r--NorthstarDedicatedTest/convar.h34
-rw-r--r--NorthstarDedicatedTest/sourceconsole.cpp119
2 files changed, 149 insertions, 4 deletions
diff --git a/NorthstarDedicatedTest/convar.h b/NorthstarDedicatedTest/convar.h
index f316562b..8dbbd07d 100644
--- a/NorthstarDedicatedTest/convar.h
+++ b/NorthstarDedicatedTest/convar.h
@@ -67,6 +67,40 @@
// #define FCVAR_AVAILABLE (1<<27)
// #define FCVAR_AVAILABLE (1<<31)
+// flag => string stuff
+const std::map<int, const char*> g_PrintCommandFlags = {
+ {FCVAR_UNREGISTERED, "UNREGISTERED"},
+ {FCVAR_DEVELOPMENTONLY, "DEVELOPMENTONLY"},
+ {FCVAR_GAMEDLL, "GAMEDLL"},
+ {FCVAR_CLIENTDLL, "CLIENTDLL"},
+ {FCVAR_HIDDEN, "HIDDEN"},
+ {FCVAR_PROTECTED, "PROTECTED"},
+ {FCVAR_SPONLY, "SPONLY"},
+ {FCVAR_ARCHIVE, "ARCHIVE"},
+ {FCVAR_NOTIFY, "NOTIFY"},
+ {FCVAR_USERINFO, "USERINFO"},
+ {FCVAR_PRINTABLEONLY, "PRINTABLEONLY"},
+ {FCVAR_GAMEDLL_FOR_REMOTE_CLIENTS, "GAMEDLL_FOR_REMOTE_CLIENTS"},
+ {FCVAR_UNLOGGED, "UNLOGGED"},
+ {FCVAR_NEVER_AS_STRING, "NEVER_AS_STRING"},
+ {FCVAR_REPLICATED, "REPLICATED"},
+ {FCVAR_CHEAT, "CHEAT"},
+ {FCVAR_SS, "SS"},
+ {FCVAR_DEMO, "DEMO"},
+ {FCVAR_DONTRECORD, "DONTRECORD"},
+ {FCVAR_SS_ADDED, "SS_ADDED"},
+ {FCVAR_RELEASE, "RELEASE"},
+ {FCVAR_RELOAD_MATERIALS, "RELOAD_MATERIALS"},
+ {FCVAR_RELOAD_TEXTURES, "RELOAD_TEXTURES"},
+ {FCVAR_NOT_CONNECTED, "NOT_CONNECTED"},
+ {FCVAR_MATERIAL_SYSTEM_THREAD, "MATERIAL_SYSTEM_THREAD"},
+ {FCVAR_ARCHIVE_PLAYERPROFILE, "ARCHIVE_PLAYERPROFILE"},
+ {FCVAR_SERVER_CAN_EXECUTE, "SERVER_CAN_EXECUTE"},
+ {FCVAR_SERVER_CANNOT_QUERY, "SERVER_CANNOT_QUERY"},
+ {FCVAR_CLIENTCMD_CAN_EXECUTE, "CLIENTCMD_CAN_EXECUTE"},
+ {FCVAR_ACCESSIBLE_FROM_THREADS, "ACCESSIBLE_FROM_THREADS"}
+};
+
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
diff --git a/NorthstarDedicatedTest/sourceconsole.cpp b/NorthstarDedicatedTest/sourceconsole.cpp
index 8f56d6c4..ee05cc66 100644
--- a/NorthstarDedicatedTest/sourceconsole.cpp
+++ b/NorthstarDedicatedTest/sourceconsole.cpp
@@ -26,6 +26,89 @@ void ConCommand_hideconsole(const CCommand& arg)
(*g_SourceGameConsole)->Hide();
}
+void PrintCommandHelpDialogue(const ConCommandBase* command, const char* name)
+{
+ if (!command)
+ {
+ spdlog::info("unknown command {}", name);
+ return;
+ }
+
+ // build string for flags if not FCVAR_NONE
+ std::string flagString;
+ if (command->GetFlags() != FCVAR_NONE)
+ {
+ flagString = "( ";
+
+ for (auto& flagPair : g_PrintCommandFlags)
+ {
+ if (command->GetFlags() & flagPair.first)
+ {
+ flagString += flagPair.second;
+ flagString += " ";
+ }
+ }
+
+ flagString += ") ";
+ }
+
+ // temp because command->IsCommand does not currently work
+ ConVar* cvar = g_pCVar->FindVar(command->m_pszName);
+ if (cvar)
+ spdlog::info("\"{}\" = \"{}\" {}- {}", cvar->GetBaseName(), cvar->GetString(), flagString, cvar->GetHelpText());
+ else
+ spdlog::info("\"{}\" {} - {}", command->m_pszName, flagString, command->GetHelpText());
+}
+
+void ConCommand_help(const CCommand& arg)
+{
+ if (arg.ArgC() < 2)
+ {
+ spdlog::info("Usage: help <cvarname>");
+ return;
+ }
+
+ PrintCommandHelpDialogue(g_pCVar->FindCommandBase(arg.Arg(1)), arg.Arg(1));
+}
+
+void ConCommand_find(const CCommand& arg)
+{
+ if (arg.ArgC() < 2)
+ {
+ spdlog::info("Usage: find <string> [<string>...]");
+ return;
+ }
+
+ char pTempName[256];
+ char pTempSearchTerm[256];
+
+ for (auto& map : g_pCVar->DumpToMap())
+ {
+ bool bPrintCommand = true;
+ for (int i = 0; i < arg.ArgC() - 1; i++)
+ {
+ // make lowercase to avoid case sensitivity
+ strncpy(pTempName, map.second->m_pszName, sizeof(pTempName));
+ strncpy(pTempSearchTerm, arg.Arg(i + 1), sizeof(pTempSearchTerm));
+
+ for (int i = 0; pTempName[i]; i++)
+ pTempName[i] = tolower(pTempName[i]);
+
+ for (int i = 0; pTempSearchTerm[i]; i++)
+ pTempSearchTerm[i] = tolower(pTempSearchTerm[i]);
+
+ if (!strstr(pTempName, pTempSearchTerm))
+ {
+ bPrintCommand = false;
+ break;
+ }
+ }
+
+ if (bPrintCommand)
+ PrintCommandHelpDialogue(map.second, map.second->m_pszName);
+ }
+}
+
typedef void (*OnCommandSubmittedType)(CConsoleDialog* consoleDialog, const char* pCommand);
OnCommandSubmittedType onCommandSubmittedOriginal;
void OnCommandSubmittedHook(CConsoleDialog* consoleDialog, const char* pCommand)
@@ -34,7 +117,28 @@ void OnCommandSubmittedHook(CConsoleDialog* consoleDialog, const char* pCommand)
consoleDialog->m_pConsolePanel->Print(pCommand);
consoleDialog->m_pConsolePanel->Print("\n");
- // todo: call the help command in the future
+ // try to display help text for this cvar
+ {
+ int pCommandLen = strlen(pCommand);
+ char* pCvarStr = new char[pCommandLen];
+ strcpy(pCvarStr, pCommand);
+
+ // trim whitespace from right
+ for (int i = pCommandLen - 1; i; i--)
+ {
+ if (isspace(pCvarStr[i]))
+ pCvarStr[i] = '\0';
+ else
+ break;
+ }
+
+ // check if we're inputting a cvar, but not setting it at all
+ ConVar* cvar = g_pCVar->FindVar(pCvarStr);
+ if (cvar)
+ PrintCommandHelpDialogue(&cvar->m_ConCommandBase, pCvarStr);
+
+ delete[] pCvarStr;
+ }
onCommandSubmittedOriginal(consoleDialog, pCommand);
}
@@ -87,7 +191,14 @@ void SourceConsoleSink::flush_() {}
ON_DLL_LOAD_CLIENT_RELIESON("client.dll", SourceConsole, ConCommand, [](HMODULE baseAddress)
{
g_SourceGameConsole = new SourceInterface<CGameConsole>("client.dll", "GameConsole004");
- RegisterConCommand("toggleconsole", ConCommand_toggleconsole, "toggles the console", FCVAR_DONTRECORD);
- RegisterConCommand("showconsole", ConCommand_showconsole, "shows the console", FCVAR_DONTRECORD);
- RegisterConCommand("hideconsole", ConCommand_hideconsole, "hides the console", FCVAR_DONTRECORD);
+ RegisterConCommand("toggleconsole", ConCommand_toggleconsole, "Show/hide the console.", FCVAR_DONTRECORD);
+ RegisterConCommand("showconsole", ConCommand_showconsole, "Show the console.", FCVAR_DONTRECORD);
+ RegisterConCommand("hideconsole", ConCommand_hideconsole, "Hide the console.", FCVAR_DONTRECORD);
+ RegisterConCommand("find", ConCommand_find, "Find concommands with the specified string in their name/help text.", FCVAR_NONE);
+
+ // help is already a command, so we need to modify the preexisting command to use our func instead
+ // and clear the flags also
+ ConCommand* helpCommand = g_pCVar->FindCommand("help");
+ helpCommand->m_nFlags = 0;
+ helpCommand->m_pCommandCallback = ConCommand_help;
}) \ No newline at end of file