aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH0L0 <H0L0.Business@outlook.com>2023-11-05 22:36:06 +1000
committerGitHub <noreply@github.com>2023-11-05 13:36:06 +0100
commit2b269d22a4d997ddb4424f84eb1a0953b7dd34fd (patch)
tree1d0023e101b834fcdea0751b90fd2ad964828da5
parent35581f1ff23c75c10b970d336811215f6ea70dd9 (diff)
downloadNorthstarLauncher-2b269d22a4d997ddb4424f84eb1a0953b7dd34fd.tar.gz
NorthstarLauncher-2b269d22a4d997ddb4424f84eb1a0953b7dd34fd.zip
Convar print commands (#539)v1.20.0-rc1
Adds various concommands such as - `convar_findByFlags` - `convar_list` - `convar_differences` - `convar_find` The first 3 listed above are already registered as concommands natively but didn't seem to do anything when tested. `convar_findByFlags` and `convar_find` were already implemented by Bob under the names `findflags` and `find` respectively but the names have been changed to reflect already existing convars.
-rw-r--r--NorthstarDLL/util/printcommands.cpp124
1 files changed, 118 insertions, 6 deletions
diff --git a/NorthstarDLL/util/printcommands.cpp b/NorthstarDLL/util/printcommands.cpp
index c3eb21ab..7c915318 100644
--- a/NorthstarDLL/util/printcommands.cpp
+++ b/NorthstarDLL/util/printcommands.cpp
@@ -1,4 +1,5 @@
#include "printcommands.h"
+#include "core/convar/cvar.h"
#include "core/convar/convar.h"
#include "core/convar/concommand.h"
@@ -94,7 +95,20 @@ void ConCommand_find(const CCommand& arg)
char pTempName[256];
char pTempSearchTerm[256];
- for (auto& map : R2::g_pCVar->DumpToMap())
+ ConCommandBase* var;
+ CCVarIteratorInternal* itint = R2::g_pCVar->FactoryInternalIterator();
+ std::map<std::string, ConCommandBase*> sorted;
+ for (itint->SetFirst(); itint->IsValid(); itint->Next())
+ {
+ var = itint->Get();
+ if (!var->IsFlagSet(FCVAR_DEVELOPMENTONLY) && !var->IsFlagSet(FCVAR_HIDDEN))
+ {
+ sorted.insert({var->m_pszName, var});
+ }
+ }
+ delete itint;
+
+ for (auto& map : sorted)
{
bool bPrintCommand = true;
for (int i = 0; i < arg.ArgC() - 1; i++)
@@ -150,8 +164,20 @@ void ConCommand_findflags(const CCommand& arg)
}
}
- // print cvars
- for (auto& map : R2::g_pCVar->DumpToMap())
+ ConCommandBase* var;
+ CCVarIteratorInternal* itint = R2::g_pCVar->FactoryInternalIterator();
+ std::map<std::string, ConCommandBase*> sorted;
+ for (itint->SetFirst(); itint->IsValid(); itint->Next())
+ {
+ var = itint->Get();
+ if (!var->IsFlagSet(FCVAR_DEVELOPMENTONLY) && !var->IsFlagSet(FCVAR_HIDDEN))
+ {
+ sorted.insert({var->m_pszName, var});
+ }
+ }
+ delete itint;
+
+ for (auto& map : sorted)
{
if (map.second->m_nFlags & resolvedFlag)
PrintCommandHelpDialogue(map.second, map.second->m_pszName);
@@ -160,14 +186,100 @@ void ConCommand_findflags(const CCommand& arg)
delete[] upperFlag;
}
+void ConCommand_list(const CCommand& arg)
+{
+ ConCommandBase* var;
+ CCVarIteratorInternal* itint = R2::g_pCVar->FactoryInternalIterator();
+ std::map<std::string, ConCommandBase*> sorted;
+ for (itint->SetFirst(); itint->IsValid(); itint->Next())
+ {
+ var = itint->Get();
+ if (!var->IsFlagSet(FCVAR_DEVELOPMENTONLY) && !var->IsFlagSet(FCVAR_HIDDEN))
+ {
+ sorted.insert({var->m_pszName, var});
+ }
+ }
+ delete itint;
+
+ for (auto& map : sorted)
+ {
+ PrintCommandHelpDialogue(map.second, map.second->m_pszName);
+ }
+ spdlog::info("{} total convars/concommands", sorted.size());
+}
+
+void ConCommand_differences(const CCommand& arg)
+{
+ CCVarIteratorInternal* itint = R2::g_pCVar->FactoryInternalIterator();
+ std::map<std::string, ConCommandBase*> sorted;
+
+ for (itint->SetFirst(); itint->IsValid(); itint->Next())
+ {
+ ConCommandBase* var = itint->Get();
+ if (!var->IsFlagSet(FCVAR_DEVELOPMENTONLY) && !var->IsFlagSet(FCVAR_HIDDEN))
+ {
+ sorted.insert({var->m_pszName, var});
+ }
+ }
+ delete itint;
+
+ for (auto& map : sorted)
+ {
+ ConVar* cvar = R2::g_pCVar->FindVar(map.second->m_pszName);
+
+ if (!cvar)
+ {
+ continue;
+ }
+
+ if (strcmp(cvar->GetString(), "FCVAR_NEVER_AS_STRING") == NULL)
+ {
+ continue;
+ }
+
+ if (strcmp(cvar->GetString(), cvar->m_pszDefaultValue) == NULL)
+ {
+ continue;
+ }
+
+ std::string formatted =
+ fmt::format("\"{}\" = \"{}\" ( def. \"{}\" )", cvar->GetBaseName(), cvar->GetString(), cvar->m_pszDefaultValue);
+
+ if (cvar->m_bHasMin)
+ {
+ formatted.append(fmt::format(" min. {}", cvar->m_fMinVal));
+ }
+
+ if (cvar->m_bHasMax)
+ {
+ formatted.append(fmt::format(" max. {}", cvar->m_fMaxVal));
+ }
+
+ formatted.append(fmt::format(" - {}", cvar->GetHelpText()));
+ spdlog::info(formatted);
+ }
+}
+
void InitialiseCommandPrint()
{
- RegisterConCommand("find", ConCommand_find, "Find concommands with the specified string in their name/help text.", FCVAR_NONE);
- RegisterConCommand("findflags", ConCommand_findflags, "Find concommands by flags.", FCVAR_NONE);
+ RegisterConCommand(
+ "convar_find", ConCommand_find, "Find convars/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
+ // these commands already exist, so we need to modify the preexisting command to use our func instead
// and clear the flags also
ConCommand* helpCommand = R2::g_pCVar->FindCommand("help");
helpCommand->m_nFlags = FCVAR_NONE;
helpCommand->m_pCommandCallback = ConCommand_help;
+
+ ConCommand* findCommand = R2::g_pCVar->FindCommand("convar_findByFlags");
+ findCommand->m_nFlags = FCVAR_NONE;
+ findCommand->m_pCommandCallback = ConCommand_findflags;
+
+ ConCommand* listCommand = R2::g_pCVar->FindCommand("convar_list");
+ listCommand->m_nFlags = FCVAR_NONE;
+ listCommand->m_pCommandCallback = ConCommand_list;
+
+ ConCommand* diffCommand = R2::g_pCVar->FindCommand("convar_differences");
+ diffCommand->m_nFlags = FCVAR_NONE;
+ diffCommand->m_pCommandCallback = ConCommand_differences;
}