aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL
diff options
context:
space:
mode:
authorunknown <for.oliver.kirkham@gmail.com>2023-02-10 21:55:36 +0000
committerunknown <for.oliver.kirkham@gmail.com>2023-02-10 21:55:36 +0000
commita4e798b2778a8606f56cc78ce11a5889cf5a8b5a (patch)
tree783e62de55f687f21fef78d44033df2539b2f412 /NorthstarDLL
parent75ae0bf4f6fab277a611ab42fc037580bfdfc06e (diff)
downloadNorthstarLauncher-a4e798b2778a8606f56cc78ce11a5889cf5a8b5a.tar.gz
NorthstarLauncher-a4e798b2778a8606f56cc78ce11a5889cf5a8b5a.zip
temp commit for switch
Diffstat (limited to 'NorthstarDLL')
-rw-r--r--NorthstarDLL/core/convar/concommand.h1
-rw-r--r--NorthstarDLL/core/convar/convar.cpp2
-rw-r--r--NorthstarDLL/mods/modmanager.cpp36
3 files changed, 30 insertions, 9 deletions
diff --git a/NorthstarDLL/core/convar/concommand.h b/NorthstarDLL/core/convar/concommand.h
index 89363bc7..c170c6a5 100644
--- a/NorthstarDLL/core/convar/concommand.h
+++ b/NorthstarDLL/core/convar/concommand.h
@@ -97,7 +97,6 @@ class ConCommandBase
bool IsCommand(void) const;
bool IsRegistered(void) const;
bool IsFlagSet(int nFlags) const;
- static bool IsFlagSet(ConCommandBase* pCommandBase, int nFlags); // For hooking to engine's implementation.
int GetFlags(void) const;
ConCommandBase* GetNext(void) const;
diff --git a/NorthstarDLL/core/convar/convar.cpp b/NorthstarDLL/core/convar/convar.cpp
index 11411c0a..81648f53 100644
--- a/NorthstarDLL/core/convar/convar.cpp
+++ b/NorthstarDLL/core/convar/convar.cpp
@@ -527,4 +527,6 @@ int ParseConVarFlagsString(std::string modName, std::string sFlags)
sCurrentFlag += sFlags[i];
}
}
+
+ return FCVAR_NONE;
}
diff --git a/NorthstarDLL/mods/modmanager.cpp b/NorthstarDLL/mods/modmanager.cpp
index 6310b7ec..891ab978 100644
--- a/NorthstarDLL/mods/modmanager.cpp
+++ b/NorthstarDLL/mods/modmanager.cpp
@@ -438,16 +438,37 @@ void ModManager::LoadMods()
continue;
// register convars
- // for reloads, this is sorta barebones, when we have a good findconvar method, we could probably reset flags and stuff on
- // preexisting convars note: we don't delete convars if they already exist because they're used for script stuff, unfortunately this
- // causes us to leak memory on reload, but not much, potentially find a way to not do this at some point
for (ModConVar* convar : mod.ConVars)
{
- // make sure convar isn't registered yet, unsure if necessary but idk what
- // behaviour is for defining same convar multiple times
- if (!R2::g_pCVar->FindVar(convar->Name.c_str()))
- {
+ ConVar* pVar = R2::g_pCVar->FindVar(convar->Name.c_str());
+
+ // make sure convar isn't registered yet, if it is then modify its flags, helpstring etc
+ if (!pVar)
new ConVar(convar->Name.c_str(), convar->DefaultValue.c_str(), convar->Flags, convar->HelpString.c_str());
+ else
+ {
+ // TODO: should probably make sure this is actually a mod convar we're messing with
+
+ pVar->m_ConCommandBase.m_nFlags = convar->Flags;
+
+ // unfortunately this leaks memory and we can't really not leak memory because we don't know who allocated this
+ // so we can't delete it without risking a crash
+ if (convar->HelpString.compare(pVar->GetHelpText()))
+ {
+ int nHelpSize = convar->HelpString.size();
+ char* pNewHelpString = new char[nHelpSize + 1];
+ strncpy_s(pNewHelpString, nHelpSize + 1, convar->HelpString.c_str(), convar->HelpString.size());
+ pVar->m_ConCommandBase.m_pszHelpString = pNewHelpString;
+ }
+
+ if (convar->DefaultValue.compare(pVar->m_pszDefaultValue))
+ {
+ int nDefaultValueSize = convar->DefaultValue.size();
+ char* pNewDefaultValueString = new char[nDefaultValueSize + 1];
+ strncpy_s(pNewDefaultValueString, nDefaultValueSize + 1, convar->DefaultValue.c_str(), convar->DefaultValue.size());
+ pVar->m_pszDefaultValue = pNewDefaultValueString;
+ pVar->SetValue(pNewDefaultValueString);
+ }
}
}
@@ -456,7 +477,6 @@ void ModManager::LoadMods()
// make sure command isnt't registered multiple times.
if (!R2::g_pCVar->FindCommand(command->Name.c_str()))
{
- ConCommand* newCommand = new ConCommand();
std::string funcName = command->Function;
RegisterConCommand(command->Name.c_str(), ModConCommandCallback, command->HelpString.c_str(), command->Flags);
}