diff options
Diffstat (limited to 'NorthstarDLL/util')
-rw-r--r-- | NorthstarDLL/util/printcommands.cpp | 124 |
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; } |