Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convar print commands #539

Merged
merged 13 commits into from
Nov 5, 2023
Prev Previous commit
Next Next commit
Remove unneeded sort as std::map is perfectly functional lmao
  • Loading branch information
H0L0theBard committed Oct 2, 2023
commit dc94412a9bb16d6ffca2dc3b8d3171ce7e128ccd
34 changes: 8 additions & 26 deletions NorthstarDLL/util/printcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
#include "core/convar/convar.h"
#include "core/convar/concommand.h"

std::vector<std::pair<std::string, ConCommandBase*>> ConvarSort(std::unordered_map<std::string, ConCommandBase*> map)
{
std::vector<std::pair<std::string, ConCommandBase*>> sorted(map.begin(), map.end());
std::sort(
sorted.begin(),
sorted.end(),
[](std::pair<std::string, ConCommandBase*>& a, std::pair<std::string, ConCommandBase*>& b) { return a.first < b.first; });
return sorted;
}

void PrintCommandHelpDialogue(const ConCommandBase* command, const char* name)
{
if (!command)
Expand Down Expand Up @@ -107,19 +97,17 @@ void ConCommand_find(const CCommand& arg)

ConCommandBase* var;
CCVarIteratorInternal* itint = R2::g_pCVar->FactoryInternalIterator();
std::unordered_map<std::string, ConCommandBase*> unsortedConvars;
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))
{
unsortedConvars.insert({var->m_pszName, var});
sorted.insert({var->m_pszName, var});
}
}
delete itint;

std::vector<std::pair<std::string, ConCommandBase*>> sorted = ConvarSort(unsortedConvars);

for (auto& map : sorted)
{
bool bPrintCommand = true;
Expand Down Expand Up @@ -178,19 +166,17 @@ void ConCommand_findflags(const CCommand& arg)

ConCommandBase* var;
CCVarIteratorInternal* itint = R2::g_pCVar->FactoryInternalIterator();
std::unordered_map<std::string, ConCommandBase*> unsortedConvars;
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))
{
unsortedConvars.insert({var->m_pszName, var});
sorted.insert({var->m_pszName, var});
}
}
delete itint;

std::vector<std::pair<std::string, ConCommandBase*>> sorted = ConvarSort(unsortedConvars);

for (auto& map : sorted)
{
if (map.second->m_nFlags & resolvedFlag)
Expand All @@ -204,19 +190,17 @@ void ConCommand_list(const CCommand& arg)
{
ConCommandBase* var;
CCVarIteratorInternal* itint = R2::g_pCVar->FactoryInternalIterator();
std::unordered_map<std::string, ConCommandBase*> unsortedConvars;
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))
{
unsortedConvars.insert({var->m_pszName, var});
sorted.insert({var->m_pszName, var});
}
}
delete itint;

std::vector<std::pair<std::string, ConCommandBase*>> sorted = ConvarSort(unsortedConvars);

for (auto& map : sorted)
{
PrintCommandHelpDialogue(map.second, map.second->m_pszName);
Expand All @@ -227,19 +211,17 @@ void ConCommand_differences(const CCommand& arg)
{
ConCommandBase* var;
CCVarIteratorInternal* itint = R2::g_pCVar->FactoryInternalIterator();
std::unordered_map<std::string, ConCommandBase*> unsortedConvars;
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))
{
unsortedConvars.insert({var->m_pszName, var});
sorted.insert({var->m_pszName, var});
}
}
delete itint;

std::vector<std::pair<std::string, ConCommandBase*>> sorted = ConvarSort(unsortedConvars);

for (auto& map : sorted)
{
ConVar* cvar = R2::g_pCVar->FindVar(map.second->m_pszName);
Expand Down