aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-11-05 22:43:56 +0000
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-11-05 22:43:56 +0000
commitcfeeaf9561a294f359cc180b86f2644e3828d819 (patch)
tree4e2adfc4332f09b0ffd6b001c8e86313d5d47c46 /NorthstarDedicatedTest
parent3d4eb42b4aaf89a4f5f3e74cb50f1fa557b272ee (diff)
downloadNorthstarLauncher-cfeeaf9561a294f359cc180b86f2644e3828d819.tar.gz
NorthstarLauncher-cfeeaf9561a294f359cc180b86f2644e3828d819.zip
reworking modloading code
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r--NorthstarDedicatedTest/filesystem.cpp8
-rw-r--r--NorthstarDedicatedTest/keyvalues.cpp14
-rw-r--r--NorthstarDedicatedTest/masterserver.cpp8
-rw-r--r--NorthstarDedicatedTest/modlocalisation.cpp6
-rw-r--r--NorthstarDedicatedTest/modmanager.cpp125
-rw-r--r--NorthstarDedicatedTest/modmanager.h8
-rw-r--r--NorthstarDedicatedTest/scriptmodmenu.cpp52
-rw-r--r--NorthstarDedicatedTest/scriptsrson.cpp18
-rw-r--r--NorthstarDedicatedTest/squirrel.cpp56
9 files changed, 147 insertions, 148 deletions
diff --git a/NorthstarDedicatedTest/filesystem.cpp b/NorthstarDedicatedTest/filesystem.cpp
index 1e17017e..127a9484 100644
--- a/NorthstarDedicatedTest/filesystem.cpp
+++ b/NorthstarDedicatedTest/filesystem.cpp
@@ -107,7 +107,7 @@ bool TryReplaceFile(char* path, bool shouldCompile)
auto file = g_ModManager->m_modFiles.find(fs::path(path).lexically_normal().string());
if (file != g_ModManager->m_modFiles.end())
{
- SetNewModSearchPaths(file->second->owningMod);
+ SetNewModSearchPaths(file->second.owningMod);
return true;
}
@@ -167,12 +167,12 @@ VPKData* MountVPKHook(IFileSystem* fileSystem, const char* vpkPath)
spdlog::info("MountVPK {}", vpkPath);
VPKData* ret = mountVPK(fileSystem, vpkPath);
- for (Mod* mod : g_ModManager->m_loadedMods)
+ for (Mod mod : g_ModManager->m_loadedMods)
{
- if (!mod->Enabled)
+ if (!mod.Enabled)
continue;
- for (std::string& vpkPath : mod->Vpks)
+ for (std::string& vpkPath : mod.Vpks)
{
spdlog::info(vpkPath);
spdlog::info((void*)mountVPK(fileSystem, vpkPath.c_str()));
diff --git a/NorthstarDedicatedTest/keyvalues.cpp b/NorthstarDedicatedTest/keyvalues.cpp
index 3bf4ff48..7afad20c 100644
--- a/NorthstarDedicatedTest/keyvalues.cpp
+++ b/NorthstarDedicatedTest/keyvalues.cpp
@@ -52,13 +52,13 @@ void ModManager::TryBuildKeyValues(const char* filename)
// note: #include should be identical but it's actually just broken, thanks respawn
for (int i = m_loadedMods.size() - 1; i > -1; i--)
{
- if (!m_loadedMods[i]->Enabled)
+ if (!m_loadedMods[i].Enabled)
continue;
size_t fileHash = std::hash<std::string>{}(normalisedPath);
- for (int j = 0; j < m_loadedMods[i]->KeyValuesHash.size(); j++)
+ for (int j = 0; j < m_loadedMods[i].KeyValuesHash.size(); j++)
{
- if (fileHash == m_loadedMods[i]->KeyValuesHash[j])
+ if (fileHash == m_loadedMods[i].KeyValuesHash[j])
{
// should result in smth along the lines of #include "mod_patch_5_mp_weapon_car.txt"
@@ -73,7 +73,7 @@ void ModManager::TryBuildKeyValues(const char* filename)
fs::remove(compiledDir / patchFilePath);
- fs::copy_file(m_loadedMods[i]->ModDirectory / "keyvalues" / filename, compiledDir / patchFilePath);
+ fs::copy_file(m_loadedMods[i].ModDirectory / "keyvalues" / filename, compiledDir / patchFilePath);
}
}
}
@@ -123,9 +123,9 @@ void ModManager::TryBuildKeyValues(const char* filename)
writeStream << newKvs;
writeStream.close();
- ModOverrideFile* overrideFile = new ModOverrideFile;
- overrideFile->owningMod = nullptr;
- overrideFile->path = normalisedPath;
+ ModOverrideFile overrideFile;
+ overrideFile.owningMod = nullptr;
+ overrideFile.path = normalisedPath;
if (m_modFiles.find(normalisedPath) == m_modFiles.end())
m_modFiles.insert(std::make_pair(normalisedPath, overrideFile));
diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp
index b3b14c8a..495f2044 100644
--- a/NorthstarDedicatedTest/masterserver.cpp
+++ b/NorthstarDedicatedTest/masterserver.cpp
@@ -414,14 +414,14 @@ void MasterServerManager::AddSelfToServerList(int port, int authPort, char* name
modinfoDoc.AddMember("Mods", rapidjson::Value(rapidjson::kArrayType), modinfoDoc.GetAllocator());
int currentModIndex = 0;
- for (Mod* mod : g_ModManager->m_loadedMods)
+ for (Mod mod : g_ModManager->m_loadedMods)
{
- if (!mod->RequiredOnClient)
+ if (!mod.RequiredOnClient)
continue;
modinfoDoc["Mods"].PushBack(rapidjson::Value(rapidjson::kObjectType), modinfoDoc.GetAllocator());
- modinfoDoc["Mods"][currentModIndex].AddMember("Name", rapidjson::StringRef(mod->Name.c_str()), modinfoDoc.GetAllocator());
- modinfoDoc["Mods"][currentModIndex].AddMember("Version", rapidjson::StringRef(mod->Version.c_str()), modinfoDoc.GetAllocator());
+ modinfoDoc["Mods"][currentModIndex].AddMember("Name", rapidjson::StringRef(mod.Name.c_str()), modinfoDoc.GetAllocator());
+ modinfoDoc["Mods"][currentModIndex].AddMember("Version", rapidjson::StringRef(mod.Version.c_str()), modinfoDoc.GetAllocator());
currentModIndex++;
}
diff --git a/NorthstarDedicatedTest/modlocalisation.cpp b/NorthstarDedicatedTest/modlocalisation.cpp
index 91f0416a..f86773fb 100644
--- a/NorthstarDedicatedTest/modlocalisation.cpp
+++ b/NorthstarDedicatedTest/modlocalisation.cpp
@@ -21,9 +21,9 @@ bool AddLocalisationFileHook(void* g_pVguiLocalize, const char* path, const char
loadModLocalisationFiles = false;
- for (Mod* mod : g_ModManager->m_loadedMods)
- if (mod->Enabled)
- for (std::string& localisationFile : mod->LocalisationFiles)
+ for (Mod mod : g_ModManager->m_loadedMods)
+ if (mod.Enabled)
+ for (std::string& localisationFile : mod.LocalisationFiles)
AddLocalisationFile(g_pVguiLocalize, localisationFile.c_str(), pathId, unknown);
loadModLocalisationFiles = true;
diff --git a/NorthstarDedicatedTest/modmanager.cpp b/NorthstarDedicatedTest/modmanager.cpp
index cd479408..c9796ac1 100644
--- a/NorthstarDedicatedTest/modmanager.cpp
+++ b/NorthstarDedicatedTest/modmanager.cpp
@@ -88,6 +88,8 @@ Mod::Mod(fs::path modDir, char* jsonBuf)
if (!convarObj.IsObject() || !convarObj.HasMember("Name") || !convarObj.HasMember("DefaultValue"))
continue;
+ // have to allocate this manually, otherwise convar registration will break
+ // unfortunately this causes us to leak memory on reload, unsure of a way around this rn
ModConVar* convar = new ModConVar;
convar->Name = convarObj["Name"].GetString();
convar->DefaultValue = convarObj["DefaultValue"].GetString();
@@ -97,7 +99,7 @@ Mod::Mod(fs::path modDir, char* jsonBuf)
else
convar->HelpString = "";
- // todo: could possibly parse FCVAR names here instead
+ // todo: could possibly parse FCVAR names here instead, would be easier
if (convarObj.HasMember("Flags"))
convar->Flags = convarObj["Flags"].GetInt();
else
@@ -115,51 +117,51 @@ Mod::Mod(fs::path modDir, char* jsonBuf)
if (!scriptObj.IsObject() || !scriptObj.HasMember("Path") || !scriptObj.HasMember("RunOn"))
continue;
- ModScript* script = new ModScript;
+ ModScript script;
- script->Path = scriptObj["Path"].GetString();
- script->RsonRunOn = scriptObj["RunOn"].GetString();
+ script.Path = scriptObj["Path"].GetString();
+ script.RsonRunOn = scriptObj["RunOn"].GetString();
if (scriptObj.HasMember("ServerCallback") && scriptObj["ServerCallback"].IsObject())
{
- ModScriptCallback* callback = new ModScriptCallback;
- callback->Context = SERVER;
+ ModScriptCallback callback;
+ callback.Context = SERVER;
if (scriptObj["ServerCallback"].HasMember("Before") && scriptObj["ServerCallback"]["Before"].IsString())
- callback->BeforeCallback = scriptObj["ServerCallback"]["Before"].GetString();
+ callback.BeforeCallback = scriptObj["ServerCallback"]["Before"].GetString();
if (scriptObj["ServerCallback"].HasMember("After") && scriptObj["ServerCallback"]["After"].IsString())
- callback->AfterCallback = scriptObj["ServerCallback"]["After"].GetString();
+ callback.AfterCallback = scriptObj["ServerCallback"]["After"].GetString();
- script->Callbacks.push_back(callback);
+ script.Callbacks.push_back(callback);
}
if (scriptObj.HasMember("ClientCallback") && scriptObj["ClientCallback"].IsObject())
{
- ModScriptCallback* callback = new ModScriptCallback;
- callback->Context = CLIENT;
+ ModScriptCallback callback;
+ callback.Context = CLIENT;
if (scriptObj["ClientCallback"].HasMember("Before") && scriptObj["ClientCallback"]["Before"].IsString())
- callback->BeforeCallback = scriptObj["ClientCallback"]["Before"].GetString();
+ callback.BeforeCallback = scriptObj["ClientCallback"]["Before"].GetString();
if (scriptObj["ClientCallback"].HasMember("After") && scriptObj["ClientCallback"]["After"].IsString())
- callback->AfterCallback = scriptObj["ClientCallback"]["After"].GetString();
+ callback.AfterCallback = scriptObj["ClientCallback"]["After"].GetString();
- script->Callbacks.push_back(callback);
+ script.Callbacks.push_back(callback);
}
if (scriptObj.HasMember("UICallback") && scriptObj["UICallback"].IsObject())
{
- ModScriptCallback* callback = new ModScriptCallback;
- callback->Context = UI;
+ ModScriptCallback callback;
+ callback.Context = UI;
if (scriptObj["UICallback"].HasMember("Before") && scriptObj["UICallback"]["Before"].IsString())
- callback->BeforeCallback = scriptObj["UICallback"]["Before"].GetString();
+ callback.BeforeCallback = scriptObj["UICallback"]["Before"].GetString();
if (scriptObj["UICallback"].HasMember("After") && scriptObj["UICallback"]["After"].IsString())
- callback->AfterCallback = scriptObj["UICallback"]["After"].GetString();
+ callback.AfterCallback = scriptObj["UICallback"]["After"].GetString();
- script->Callbacks.push_back(callback);
+ script.Callbacks.push_back(callback);
}
Scripts.push_back(script);
@@ -234,51 +236,48 @@ void ModManager::LoadMods()
jsonStream.close();
- Mod* mod = new Mod(modDir, (char*)jsonStringStream.str().c_str());
+ Mod mod(modDir, (char*)jsonStringStream.str().c_str());
- if (m_hasEnabledModsCfg && m_enabledModsCfg.HasMember(mod->Name.c_str()))
- mod->Enabled = m_enabledModsCfg[mod->Name.c_str()].IsTrue();
+ if (m_hasEnabledModsCfg && m_enabledModsCfg.HasMember(mod.Name.c_str()))
+ mod.Enabled = m_enabledModsCfg[mod.Name.c_str()].IsTrue();
else
- mod->Enabled = true;
+ mod.Enabled = true;
- if (mod->wasReadSuccessfully)
+ if (mod.wasReadSuccessfully)
{
- spdlog::info("Loaded mod {} successfully", mod->Name);
- if (mod->Enabled)
- spdlog::info("Mod {} is enabled", mod->Name);
+ spdlog::info("Loaded mod {} successfully", mod.Name);
+ if (mod.Enabled)
+ spdlog::info("Mod {} is enabled", mod.Name);
else
- spdlog::info("Mod {} is disabled", mod->Name);
+ spdlog::info("Mod {} is disabled", mod.Name);
m_loadedMods.push_back(mod);
}
else
- {
spdlog::warn("Skipping loading mod file {}", (modDir / "mod.json").string());
- delete mod;
- }
}
// sort by load prio, lowest-highest
- std::sort(m_loadedMods.begin(), m_loadedMods.end(), [](Mod* a, Mod* b) {
- return a->LoadPriority < b->LoadPriority;
+ std::sort(m_loadedMods.begin(), m_loadedMods.end(), [](Mod a, Mod b) {
+ return a.LoadPriority < b.LoadPriority;
});
- for (Mod* mod : m_loadedMods)
+ for (Mod mod : m_loadedMods)
{
- if (!mod->Enabled)
+ if (!mod.Enabled)
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
- // potentially it might also be good to unregister convars if they get removed on a reload, but unsure if necessary
- for (ModConVar* convar : mod->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)
if (g_CustomConvars.find(convar->Name) == g_CustomConvars.end()) // make sure convar isn't registered yet, unsure if necessary but idk what behaviour is for defining same convar multiple times
RegisterConVar(convar->Name.c_str(), convar->DefaultValue.c_str(), convar->Flags, convar->HelpString.c_str());
// read vpk paths
- if (fs::exists(mod->ModDirectory / "vpk"))
+ if (fs::exists(mod.ModDirectory / "vpk"))
{
- for (fs::directory_entry file : fs::directory_iterator(mod->ModDirectory / "vpk"))
+ for (fs::directory_entry file : fs::directory_iterator(mod.ModDirectory / "vpk"))
{
// a bunch of checks to make sure we're only adding dir vpks and their paths are good
// note: the game will literally only load vpks with the english prefix
@@ -289,7 +288,7 @@ void ModManager::LoadMods()
// this really fucking sucks but it'll work
std::string vpkName = (file.path().parent_path() / formattedPath.substr(strlen("english"), formattedPath.find(".bsp") - 3)).string();
- mod->Vpks.push_back(vpkName);
+ mod.Vpks.push_back(vpkName);
if (m_hasLoadedMods)
(*g_Filesystem)->m_vtable->MountVPK(*g_Filesystem, vpkName.c_str());
@@ -299,15 +298,15 @@ void ModManager::LoadMods()
// read keyvalues paths
- if (fs::exists(mod->ModDirectory / "keyvalues"))
+ if (fs::exists(mod.ModDirectory / "keyvalues"))
{
- for (fs::directory_entry file : fs::recursive_directory_iterator(mod->ModDirectory / "keyvalues"))
+ for (fs::directory_entry file : fs::recursive_directory_iterator(mod.ModDirectory / "keyvalues"))
{
if (fs::is_regular_file(file))
{
- std::string kvStr = file.path().lexically_relative(mod->ModDirectory / "keyvalues").lexically_normal().string();
- mod->KeyValuesHash.push_back(std::hash<std::string>{}(kvStr));
- mod->KeyValues.push_back(kvStr);
+ std::string kvStr = file.path().lexically_relative(mod.ModDirectory / "keyvalues").lexically_normal().string();
+ mod.KeyValuesHash.push_back(std::hash<std::string>{}(kvStr));
+ mod.KeyValues.push_back(kvStr);
}
}
}
@@ -316,20 +315,20 @@ void ModManager::LoadMods()
// in a seperate loop because we register mod files in reverse order, since mods loaded later should have their files prioritised
for (int i = m_loadedMods.size() - 1; i > -1; i--)
{
- if (!m_loadedMods[i]->Enabled)
+ if (!m_loadedMods[i].Enabled)
continue;
- if (fs::exists(m_loadedMods[i]->ModDirectory / MOD_OVERRIDE_DIR))
+ if (fs::exists(m_loadedMods[i].ModDirectory / MOD_OVERRIDE_DIR))
{
- for (fs::directory_entry file : fs::recursive_directory_iterator(m_loadedMods[i]->ModDirectory / MOD_OVERRIDE_DIR))
+ for (fs::directory_entry file : fs::recursive_directory_iterator(m_loadedMods[i].ModDirectory / MOD_OVERRIDE_DIR))
{
- fs::path path = file.path().lexically_relative(m_loadedMods[i]->ModDirectory / MOD_OVERRIDE_DIR).lexically_normal();
+ fs::path path = file.path().lexically_relative(m_loadedMods[i].ModDirectory / MOD_OVERRIDE_DIR).lexically_normal();
if (file.is_regular_file() && m_modFiles.find(path.string()) == m_modFiles.end())
{
- ModOverrideFile* modFile = new ModOverrideFile;
- modFile->owningMod = m_loadedMods[i];
- modFile->path = path;
+ ModOverrideFile modFile;
+ modFile.owningMod = &m_loadedMods[i];
+ modFile.path = path;
m_modFiles.insert(std::make_pair(path.string(), modFile));
}
}
@@ -350,20 +349,20 @@ void ModManager::UnloadMods()
if (!m_hasEnabledModsCfg)
m_enabledModsCfg.SetObject();
- for (Mod* mod : m_loadedMods)
+ for (Mod mod : m_loadedMods)
{
// remove all built kvs
- for (std::string kvPaths : mod->KeyValues)
- fs::remove(COMPILED_ASSETS_PATH / fs::path(kvPaths).lexically_relative(mod->ModDirectory));
+ for (std::string kvPaths : mod.KeyValues)
+ fs::remove(COMPILED_ASSETS_PATH / fs::path(kvPaths).lexically_relative(mod.ModDirectory));
- mod->KeyValuesHash.clear();
- mod->KeyValues.clear();
+ mod.KeyValuesHash.clear();
+ mod.KeyValues.clear();
// write to m_enabledModsCfg
- if (!m_enabledModsCfg.HasMember(mod->Name.c_str()))
- m_enabledModsCfg.AddMember(rapidjson::StringRef(mod->Name.c_str()), rapidjson::Value(false), m_enabledModsCfg.GetAllocator());
+ if (!m_enabledModsCfg.HasMember(mod.Name.c_str()))
+ m_enabledModsCfg.AddMember(rapidjson::StringRef(mod.Name.c_str()), rapidjson::Value(false), m_enabledModsCfg.GetAllocator());
- m_enabledModsCfg[mod->Name.c_str()].SetBool(mod->Enabled);
+ m_enabledModsCfg[mod.Name.c_str()].SetBool(mod.Enabled);
}
std::ofstream writeStream("R2Northstar/enabledmods.json");
@@ -384,13 +383,13 @@ void ModManager::CompileAssetsForFile(const char* filename)
else //if (!strcmp((filename + strlen(filename)) - 3, "txt")) // check if it's a .txt
{
// check if we should build keyvalues, depending on whether any of our mods have patch kvs for this file
- for (Mod* mod : m_loadedMods)
+ for (Mod mod : m_loadedMods)
{
- if (!mod->Enabled)
+ if (!mod.Enabled)
continue;
size_t fileHash = std::hash<std::string>{}(fs::path(filename).lexically_normal().string());
- if (std::find(mod->KeyValuesHash.begin(), mod->KeyValuesHash.end(), fileHash) != mod->KeyValuesHash.end())
+ if (std::find(mod.KeyValuesHash.begin(), mod.KeyValuesHash.end(), fileHash) != mod.KeyValuesHash.end())
{
TryBuildKeyValues(filename);
return;
diff --git a/NorthstarDedicatedTest/modmanager.h b/NorthstarDedicatedTest/modmanager.h
index 03160dd8..e0f277e9 100644
--- a/NorthstarDedicatedTest/modmanager.h
+++ b/NorthstarDedicatedTest/modmanager.h
@@ -41,7 +41,7 @@ public:
std::string Path;
std::string RsonRunOn;
- std::vector<ModScriptCallback*> Callbacks;
+ std::vector<ModScriptCallback> Callbacks;
};
class Mod
@@ -68,7 +68,7 @@ public:
int LoadPriority;
// custom scripts used by the mod
- std::vector<ModScript*> Scripts;
+ std::vector<ModScript> Scripts;
// convars created by the mod
std::vector<ModConVar*> ConVars;
// custom localisation files created by the mod
@@ -103,8 +103,8 @@ private:
rapidjson::Document m_enabledModsCfg;
public:
- std::vector<Mod*> m_loadedMods;
- std::unordered_map<std::string, ModOverrideFile*> m_modFiles;
+ std::vector<Mod> m_loadedMods;
+ std::unordered_map<std::string, ModOverrideFile> m_modFiles;
public:
ModManager();
diff --git a/NorthstarDedicatedTest/scriptmodmenu.cpp b/NorthstarDedicatedTest/scriptmodmenu.cpp
index 88a5c773..54e7d0e1 100644
--- a/NorthstarDedicatedTest/scriptmodmenu.cpp
+++ b/NorthstarDedicatedTest/scriptmodmenu.cpp
@@ -9,9 +9,9 @@ SQInteger SQ_GetModNames(void* sqvm)
{
ClientSq_newarray(sqvm, 0);
- for (Mod* mod : g_ModManager->m_loadedMods)
+ for (Mod mod : g_ModManager->m_loadedMods)
{
- ClientSq_pushstring(sqvm, mod->Name.c_str(), -1);
+ ClientSq_pushstring(sqvm, mod.Name.c_str(), -1);
ClientSq_arrayappend(sqvm, -2);
}
@@ -24,11 +24,11 @@ SQInteger SQ_IsModEnabled(void* sqvm)
const SQChar* modName = ClientSq_getstring(sqvm, 1);
// manual lookup, not super performant but eh not a big deal
- for (Mod* mod : g_ModManager->m_loadedMods)
+ for (Mod mod : g_ModManager->m_loadedMods)
{
- if (!mod->Name.compare(modName))
+ if (!mod.Name.compare(modName))
{
- ClientSq_pushbool(sqvm, mod->Enabled);
+ ClientSq_pushbool(sqvm, mod.Enabled);
return SQRESULT_NOTNULL;
}
}
@@ -43,11 +43,11 @@ SQInteger SQ_SetModEnabled(void* sqvm)
const SQBool enabled = ClientSq_getbool(sqvm, 2);
// manual lookup, not super performant but eh not a big deal
- for (Mod* mod : g_ModManager->m_loadedMods)
+ for (Mod mod : g_ModManager->m_loadedMods)
{
- if (!mod->Name.compare(modName))
+ if (!mod.Name.compare(modName))
{
- mod->Enabled = enabled;
+ mod.Enabled = enabled;
return SQRESULT_NULL;
}
}
@@ -61,11 +61,11 @@ SQInteger SQ_GetModDescription(void* sqvm)
const SQChar* modName = ClientSq_getstring(sqvm, 1);
// manual lookup, not super performant but eh not a big deal
- for (Mod* mod : g_ModManager->m_loadedMods)
+ for (Mod mod : g_ModManager->m_loadedMods)
{
- if (!mod->Name.compare(modName))
+ if (!mod.Name.compare(modName))
{
- ClientSq_pushstring(sqvm, mod->Description.c_str(), -1);
+ ClientSq_pushstring(sqvm, mod.Description.c_str(), -1);
return SQRESULT_NOTNULL;
}
}
@@ -79,11 +79,11 @@ SQInteger SQ_GetModVersion(void* sqvm)
const SQChar* modName = ClientSq_getstring(sqvm, 1);
// manual lookup, not super performant but eh not a big deal
- for (Mod* mod : g_ModManager->m_loadedMods)
+ for (Mod mod : g_ModManager->m_loadedMods)
{
- if (!mod->Name.compare(modName))
+ if (!mod.Name.compare(modName))
{
- ClientSq_pushstring(sqvm, mod->Version.c_str(), -1);
+ ClientSq_pushstring(sqvm, mod.Version.c_str(), -1);
return SQRESULT_NOTNULL;
}
}
@@ -97,11 +97,11 @@ SQInteger SQ_GetModDownloadLink(void* sqvm)
const SQChar* modName = ClientSq_getstring(sqvm, 1);
// manual lookup, not super performant but eh not a big deal
- for (Mod* mod : g_ModManager->m_loadedMods)
+ for (Mod mod : g_ModManager->m_loadedMods)
{
- if (!mod->Name.compare(modName))
+ if (!mod.Name.compare(modName))
{
- ClientSq_pushstring(sqvm, mod->DownloadLink.c_str(), -1);
+ ClientSq_pushstring(sqvm, mod.DownloadLink.c_str(), -1);
return SQRESULT_NOTNULL;
}
}
@@ -115,11 +115,11 @@ SQInteger SQ_GetModLoadPriority(void* sqvm)
const SQChar* modName = ClientSq_getstring(sqvm, 1);
// manual lookup, not super performant but eh not a big deal
- for (Mod* mod : g_ModManager->m_loadedMods)
+ for (Mod mod : g_ModManager->m_loadedMods)
{
- if (!mod->Name.compare(modName))
+ if (!mod.Name.compare(modName))
{
- ClientSq_pushinteger(sqvm, mod->LoadPriority);
+ ClientSq_pushinteger(sqvm, mod.LoadPriority);
return SQRESULT_NOTNULL;
}
}
@@ -133,11 +133,11 @@ SQInteger SQ_IsModRequiredOnClient(void* sqvm)
const SQChar* modName = ClientSq_getstring(sqvm, 1);
// manual lookup, not super performant but eh not a big deal
- for (Mod* mod : g_ModManager->m_loadedMods)
+ for (Mod mod : g_ModManager->m_loadedMods)
{
- if (!mod->Name.compare(modName))
+ if (!mod.Name.compare(modName))
{
- ClientSq_pushbool(sqvm, mod->RequiredOnClient);
+ ClientSq_pushbool(sqvm, mod.RequiredOnClient);
return SQRESULT_NOTNULL;
}
}
@@ -152,11 +152,11 @@ SQInteger SQ_GetModConvars(void* sqvm)
ClientSq_newarray(sqvm, 0);
// manual lookup, not super performant but eh not a big deal
- for (Mod* mod : g_ModManager->m_loadedMods)
+ for (Mod mod : g_ModManager->m_loadedMods)
{
- if (!mod->Name.compare(modName))
+ if (!mod.Name.compare(modName))
{
- for (ModConVar* cvar : mod->ConVars)
+ for (ModConVar* cvar : mod.ConVars)
{
ClientSq_pushstring(sqvm, cvar->Name.c_str(), -1);
ClientSq_arrayappend(sqvm, -2);
diff --git a/NorthstarDedicatedTest/scriptsrson.cpp b/NorthstarDedicatedTest/scriptsrson.cpp
index 514d4f1c..0f6680a3 100644
--- a/NorthstarDedicatedTest/scriptsrson.cpp
+++ b/NorthstarDedicatedTest/scriptsrson.cpp
@@ -17,17 +17,17 @@ void ModManager::BuildScriptsRson()
std::string scriptsRson = ReadVPKOriginalFile(VPK_SCRIPTS_RSON_PATH);
scriptsRson += "\n\n// START MODDED SCRIPT CONTENT\n\n"; // newline before we start custom stuff
- for (Mod* mod : m_loadedMods)
+ for (Mod mod : m_loadedMods)
{
- if (!mod->Enabled)
+ if (!mod.Enabled)
continue;
// this isn't needed at all, just nice to have imo
scriptsRson += "// MOD: ";
- scriptsRson += mod->Name;
+ scriptsRson += mod.Name;
scriptsRson += ":\n\n";
- for (ModScript* script : mod->Scripts)
+ for (ModScript script : mod.Scripts)
{
/* should create something with this format for each script
When: "CONTEXT"
@@ -37,11 +37,11 @@ void ModManager::BuildScriptsRson()
]*/
scriptsRson += "When: \"";
- scriptsRson += script->RsonRunOn;
+ scriptsRson += script.RsonRunOn;
scriptsRson += "\"\n";
scriptsRson += "Scripts:\n[\n\t";
- scriptsRson += script->Path;
+ scriptsRson += script.Path;
scriptsRson += "\n]\n\n";
}
}
@@ -52,9 +52,9 @@ void ModManager::BuildScriptsRson()
writeStream << scriptsRson;
writeStream.close();
- ModOverrideFile* overrideFile = new ModOverrideFile;
- overrideFile->owningMod = nullptr;
- overrideFile->path = VPK_SCRIPTS_RSON_PATH;
+ ModOverrideFile overrideFile;
+ overrideFile.owningMod = nullptr;
+ overrideFile.path = VPK_SCRIPTS_RSON_PATH;
if (m_modFiles.find(VPK_SCRIPTS_RSON_PATH) == m_modFiles.end())
m_modFiles.insert(std::make_pair(VPK_SCRIPTS_RSON_PATH, overrideFile));
diff --git a/NorthstarDedicatedTest/squirrel.cpp b/NorthstarDedicatedTest/squirrel.cpp
index 5d8d69a2..48136f97 100644
--- a/NorthstarDedicatedTest/squirrel.cpp
+++ b/NorthstarDedicatedTest/squirrel.cpp
@@ -287,19 +287,19 @@ template<Context context> char CallScriptInitCallbackHook(void* sqvm, const char
// todo: we need to verify if RunOn is valid for current state before calling callbacks
if (shouldCallCustomCallbacks)
{
- for (Mod* mod : g_ModManager->m_loadedMods)
+ for (Mod mod : g_ModManager->m_loadedMods)
{
- if (!mod->Enabled)
+ if (!mod.Enabled)
continue;
- for (ModScript* script : mod->Scripts)
+ for (ModScript script : mod.Scripts)
{
- for (ModScriptCallback* modCallback : script->Callbacks)
+ for (ModScriptCallback modCallback : script.Callbacks)
{
- if (modCallback->Context == realContext && modCallback->BeforeCallback.length())
+ if (modCallback.Context == realContext && modCallback.BeforeCallback.length())
{
- spdlog::info("Running custom {} script callback \"{}\"", GetContextName(realContext), modCallback->BeforeCallback);
- ClientCallScriptInitCallback(sqvm, modCallback->BeforeCallback.c_str());
+ spdlog::info("Running custom {} script callback \"{}\"", GetContextName(realContext), modCallback.BeforeCallback);
+ ClientCallScriptInitCallback(sqvm, modCallback.BeforeCallback.c_str());
}
}
}
@@ -314,19 +314,19 @@ template<Context context> char CallScriptInitCallbackHook(void* sqvm, const char
// run after callbacks
if (shouldCallCustomCallbacks)
{
- for (Mod* mod : g_ModManager->m_loadedMods)
+ for (Mod mod : g_ModManager->m_loadedMods)
{
- if (!mod->Enabled)
+ if (!mod.Enabled)
continue;
- for (ModScript* script : mod->Scripts)
+ for (ModScript script : mod.Scripts)
{
- for (ModScriptCallback* modCallback : script->Callbacks)
+ for (ModScriptCallback modCallback : script.Callbacks)
{
- if (modCallback->Context == realContext && modCallback->AfterCallback.length())
+ if (modCallback.Context == realContext && modCallback.AfterCallback.length())
{
- spdlog::info("Running custom {} script callback \"{}\"", GetContextName(realContext), modCallback->AfterCallback);
- ClientCallScriptInitCallback(sqvm, modCallback->AfterCallback.c_str());
+ spdlog::info("Running custom {} script callback \"{}\"", GetContextName(realContext), modCallback.AfterCallback);
+ ClientCallScriptInitCallback(sqvm, modCallback.AfterCallback.c_str());
}
}
}
@@ -342,19 +342,19 @@ template<Context context> char CallScriptInitCallbackHook(void* sqvm, const char
// todo: we need to verify if RunOn is valid for current state before calling callbacks
if (shouldCallCustomCallbacks)
{
- for (Mod* mod : g_ModManager->m_loadedMods)
+ for (Mod mod : g_ModManager->m_loadedMods)
{
- if (!mod->Enabled)
+ if (!mod.Enabled)
continue;
- for (ModScript* script : mod->Scripts)
+ for (ModScript script : mod.Scripts)
{
- for (ModScriptCallback* modCallback : script->Callbacks)
+ for (ModScriptCallback modCallback : script.Callbacks)
{
- if (modCallback->Context == SERVER && modCallback->BeforeCallback.length())
+ if (modCallback.Context == SERVER && modCallback.BeforeCallback.length())
{
- spdlog::info("Running custom {} script callback \"{}\"", GetContextName(context), modCallback->BeforeCallback);
- ServerCallScriptInitCallback(sqvm, modCallback->BeforeCallback.c_str());
+ spdlog::info("Running custom {} script callback \"{}\"", GetContextName(context), modCallback.BeforeCallback);
+ ServerCallScriptInitCallback(sqvm, modCallback.BeforeCallback.c_str());
}
}
}
@@ -369,19 +369,19 @@ template<Context context> char CallScriptInitCallbackHook(void* sqvm, const char
// run after callbacks
if (shouldCallCustomCallbacks)
{
- for (Mod* mod : g_ModManager->m_loadedMods)
+ for (Mod mod : g_ModManager->m_loadedMods)
{
- if (!mod->Enabled)
+ if (!mod.Enabled)
continue;
- for (ModScript* script : mod->Scripts)
+ for (ModScript script : mod.Scripts)
{
- for (ModScriptCallback* modCallback : script->Callbacks)
+ for (ModScriptCallback modCallback : script.Callbacks)
{
- if (modCallback->Context == SERVER && modCallback->AfterCallback.length())
+ if (modCallback.Context == SERVER && modCallback.AfterCallback.length())
{
- spdlog::info("Running custom {} script callback \"{}\"", GetContextName(context), modCallback->AfterCallback);
- ServerCallScriptInitCallback(sqvm, modCallback->AfterCallback.c_str());
+ spdlog::info("Running custom {} script callback \"{}\"", GetContextName(context), modCallback.AfterCallback);
+ ServerCallScriptInitCallback(sqvm, modCallback.AfterCallback.c_str());
}
}
}