diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-09-30 21:46:08 +0100 |
---|---|---|
committer | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-09-30 21:46:08 +0100 |
commit | 1ff8e068e62d095775ef2ae54d3685d89238f28c (patch) | |
tree | 5aedcc16f144c2225d7398dd1f19b4f11cd467c1 /NorthstarDedicatedTest | |
parent | 8b93a09f5b12ce7967df5824794ed24b3ff31cdc (diff) | |
download | NorthstarLauncher-1ff8e068e62d095775ef2ae54d3685d89238f28c.tar.gz NorthstarLauncher-1ff8e068e62d095775ef2ae54d3685d89238f28c.zip |
small modmanager refactors
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r-- | NorthstarDedicatedTest/filesystem.cpp | 8 | ||||
-rw-r--r-- | NorthstarDedicatedTest/keyvalues.cpp | 12 | ||||
-rw-r--r-- | NorthstarDedicatedTest/masterserver.cpp | 4 | ||||
-rw-r--r-- | NorthstarDedicatedTest/masterserver.h | 2 | ||||
-rw-r--r-- | NorthstarDedicatedTest/modlocalisation.cpp | 4 | ||||
-rw-r--r-- | NorthstarDedicatedTest/modmanager.cpp | 121 | ||||
-rw-r--r-- | NorthstarDedicatedTest/modmanager.h | 12 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptmodmenu.cpp | 36 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptsrson.cpp | 16 | ||||
-rw-r--r-- | NorthstarDedicatedTest/serverauthentication.cpp | 4 | ||||
-rw-r--r-- | NorthstarDedicatedTest/serverauthentication.h | 2 | ||||
-rw-r--r-- | NorthstarDedicatedTest/squirrel.cpp | 60 | ||||
-rw-r--r-- | NorthstarDedicatedTest/squirrel.h | 6 |
13 files changed, 142 insertions, 145 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 3d527e62..61170177 100644 --- a/NorthstarDedicatedTest/keyvalues.cpp +++ b/NorthstarDedicatedTest/keyvalues.cpp @@ -53,9 +53,9 @@ void ModManager::TryBuildKeyValues(const char* filename) for (int i = m_loadedMods.size() - 1; i > -1; i--) { 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" @@ -70,7 +70,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); } } } @@ -120,9 +120,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 d7f966db..b4df3916 100644 --- a/NorthstarDedicatedTest/masterserver.cpp +++ b/NorthstarDedicatedTest/masterserver.cpp @@ -17,7 +17,7 @@ ConVar* Cvar_ns_server_name; ConVar* Cvar_ns_server_desc; ConVar* Cvar_ns_server_password; -MasterServerManager* g_MasterServerManager; +std::unique_ptr<MasterServerManager> g_MasterServerManager; typedef void(*CHostState__State_NewGameType)(CHostState* hostState); CHostState__State_NewGameType CHostState__State_NewGame; @@ -596,7 +596,7 @@ void InitialiseSharedMasterServer(HMODULE baseAddress) Cvar_ns_server_password = RegisterConVar("ns_server_password", "", FCVAR_GAMEDLL, ""); Cvar_ns_report_server_to_masterserver = RegisterConVar("ns_report_server_to_masterserver", "1", FCVAR_GAMEDLL, ""); Cvar_ns_report_sp_server_to_masterserver = RegisterConVar("ns_report_sp_server_to_masterserver", "0", FCVAR_GAMEDLL, ""); - g_MasterServerManager = new MasterServerManager; + g_MasterServerManager = std::make_unique<MasterServerManager>(); RegisterConCommand("ns_fetchservers", ConCommand_ns_fetchservers, "", FCVAR_CLIENTDLL); diff --git a/NorthstarDedicatedTest/masterserver.h b/NorthstarDedicatedTest/masterserver.h index d7dcf485..a8e887ab 100644 --- a/NorthstarDedicatedTest/masterserver.h +++ b/NorthstarDedicatedTest/masterserver.h @@ -69,5 +69,5 @@ public: void InitialiseSharedMasterServer(HMODULE baseAddress); -extern MasterServerManager* g_MasterServerManager; +extern std::unique_ptr<MasterServerManager> g_MasterServerManager; extern ConVar* Cvar_ns_masterserver_hostname;
\ No newline at end of file diff --git a/NorthstarDedicatedTest/modlocalisation.cpp b/NorthstarDedicatedTest/modlocalisation.cpp index d8168d0c..d30fb2c9 100644 --- a/NorthstarDedicatedTest/modlocalisation.cpp +++ b/NorthstarDedicatedTest/modlocalisation.cpp @@ -21,8 +21,8 @@ bool AddLocalisationFileHook(void* g_pVguiLocalize, const char* path, const char loadModLocalisationFiles = false; - for (Mod* mod : g_ModManager->m_loadedMods) - for (std::string& localisationFile : mod->LocalisationFiles) + for (Mod mod : g_ModManager->m_loadedMods) + 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 f5deed1a..c687f70f 100644 --- a/NorthstarDedicatedTest/modmanager.cpp +++ b/NorthstarDedicatedTest/modmanager.cpp @@ -11,7 +11,7 @@ #include <sstream> #include <vector> -ModManager* g_ModManager; +std::unique_ptr<ModManager> g_ModManager; Mod::Mod(fs::path modDir, char* jsonBuf) { @@ -85,20 +85,20 @@ Mod::Mod(fs::path modDir, char* jsonBuf) if (!convarObj.IsObject() || !convarObj.HasMember("Name") || !convarObj.HasMember("DefaultValue")) continue; - ModConVar* convar = new ModConVar; - convar->Name = convarObj["Name"].GetString(); - convar->DefaultValue = convarObj["DefaultValue"].GetString(); + ModConVar convar; + convar.Name = convarObj["Name"].GetString(); + convar.DefaultValue = convarObj["DefaultValue"].GetString(); if (convarObj.HasMember("HelpString")) - convar->HelpString = convarObj["HelpString"].GetString(); + convar.HelpString = convarObj["HelpString"].GetString(); else - convar->HelpString = ""; + convar.HelpString = ""; // todo: could possibly parse FCVAR names here instead if (convarObj.HasMember("Flags")) - convar->Flags = convarObj["Flags"].GetInt(); + convar.Flags = convarObj["Flags"].GetInt(); else - convar->Flags = FCVAR_NONE; + convar.Flags = FCVAR_NONE; ConVars.push_back(convar); } @@ -112,51 +112,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); @@ -214,41 +214,38 @@ void ModManager::LoadMods() jsonStream.close(); - Mod* mod = new Mod(modDir, (char*)jsonStringStream.str().c_str()); + Mod mod = Mod(modDir, (char*)jsonStringStream.str().c_str()); - if (mod->wasReadSuccessfully) + if (mod.wasReadSuccessfully) { - spdlog::info("Loaded mod {} successfully", mod->Name); + spdlog::info("Loaded mod {} successfully", 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) - 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()); + 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 @@ -258,22 +255,22 @@ void ModManager::LoadMods() std::string formattedPath = file.path().filename().string(); // this really fucking sucks but it'll work - mod->Vpks.push_back((file.path().parent_path() / formattedPath.substr(strlen("english"), formattedPath.find(".bsp") - 3)).string()); + mod.Vpks.push_back((file.path().parent_path() / formattedPath.substr(strlen("english"), formattedPath.find(".bsp") - 3)).string()); } } } // 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); } } } @@ -282,20 +279,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)); } } @@ -311,14 +308,14 @@ void ModManager::UnloadMods() m_modFiles.clear(); fs::remove_all(COMPILED_ASSETS_PATH); - 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(); } // do we need to dealloc individual entries in m_loadedMods? idk, rework @@ -334,10 +331,10 @@ 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) { 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; @@ -353,7 +350,7 @@ void ReloadModsCommand(const CCommand& args) void InitialiseModManager(HMODULE baseAddress) { - g_ModManager = new ModManager(); + g_ModManager = std::make_unique<ModManager>(); RegisterConCommand("reload_mods", ReloadModsCommand, "idk", FCVAR_NONE); }
\ No newline at end of file diff --git a/NorthstarDedicatedTest/modmanager.h b/NorthstarDedicatedTest/modmanager.h index 079e1613..df3cd1d3 100644 --- a/NorthstarDedicatedTest/modmanager.h +++ b/NorthstarDedicatedTest/modmanager.h @@ -40,7 +40,7 @@ public: std::string Path; std::string RsonRunOn; - std::vector<ModScriptCallback*> Callbacks; + std::vector<ModScriptCallback> Callbacks; }; class Mod @@ -67,9 +67,9 @@ 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; + std::vector<ModConVar> ConVars; // custom localisation files created by the mod std::vector<std::string> LocalisationFiles; @@ -97,8 +97,8 @@ public: class ModManager { 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(); @@ -113,4 +113,4 @@ public: void InitialiseModManager(HMODULE baseAddress); -extern ModManager* g_ModManager;
\ No newline at end of file +extern std::unique_ptr<ModManager> g_ModManager;
\ No newline at end of file diff --git a/NorthstarDedicatedTest/scriptmodmenu.cpp b/NorthstarDedicatedTest/scriptmodmenu.cpp index ca7d047d..d154aff8 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_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 1; } } @@ -42,11 +42,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 1; } } @@ -60,11 +60,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 1; } } @@ -78,11 +78,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 1; } } @@ -97,13 +97,13 @@ 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_pushstring(sqvm, cvar.Name.c_str(), -1); ClientSq_arrayappend(sqvm, -2); } diff --git a/NorthstarDedicatedTest/scriptsrson.cpp b/NorthstarDedicatedTest/scriptsrson.cpp index bc49ed26..1c37d000 100644 --- a/NorthstarDedicatedTest/scriptsrson.cpp +++ b/NorthstarDedicatedTest/scriptsrson.cpp @@ -17,14 +17,14 @@ 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) { // 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" @@ -34,11 +34,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"; } } @@ -49,9 +49,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/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp index fed4eb82..48ae1cf2 100644 --- a/NorthstarDedicatedTest/serverauthentication.cpp +++ b/NorthstarDedicatedTest/serverauthentication.cpp @@ -29,7 +29,7 @@ typedef char(*CGameClient__ExecuteStringCommandType)(void* self, uint32_t unknow CGameClient__ExecuteStringCommandType CGameClient__ExecuteStringCommand; // global vars -ServerAuthenticationManager* g_ServerAuthenticationManager; +std::unique_ptr<ServerAuthenticationManager> g_ServerAuthenticationManager; ConVar* Cvar_ns_player_auth_port; ConVar* Cvar_ns_erase_auth_info; @@ -299,7 +299,7 @@ char CGameClient__ExecuteStringCommandHook(void* self, uint32_t unknown, const c void InitialiseServerAuthentication(HMODULE baseAddress) { - g_ServerAuthenticationManager = new ServerAuthenticationManager; + g_ServerAuthenticationManager = std::make_unique<ServerAuthenticationManager>(); Cvar_ns_erase_auth_info = RegisterConVar("ns_erase_auth_info", "1", FCVAR_GAMEDLL, "Whether auth info should be erased from this server on disconnect or crash"); CVar_ns_auth_allow_insecure = RegisterConVar("ns_auth_allow_insecure", "0", FCVAR_GAMEDLL, "Whether this server will allow unauthenicated players to connect"); diff --git a/NorthstarDedicatedTest/serverauthentication.h b/NorthstarDedicatedTest/serverauthentication.h index 38008e9b..e026f54b 100644 --- a/NorthstarDedicatedTest/serverauthentication.h +++ b/NorthstarDedicatedTest/serverauthentication.h @@ -43,5 +43,5 @@ public: void InitialiseServerAuthentication(HMODULE baseAddress); -extern ServerAuthenticationManager* g_ServerAuthenticationManager; +extern std::unique_ptr<ServerAuthenticationManager> g_ServerAuthenticationManager; extern ConVar* Cvar_ns_player_auth_port;
\ No newline at end of file diff --git a/NorthstarDedicatedTest/squirrel.cpp b/NorthstarDedicatedTest/squirrel.cpp index 85e26c45..ffd9a816 100644 --- a/NorthstarDedicatedTest/squirrel.cpp +++ b/NorthstarDedicatedTest/squirrel.cpp @@ -85,9 +85,9 @@ sq_getfloatType ServerSq_getfloat; template<Context context> void ExecuteCodeCommand(const CCommand& args); // inits -SquirrelManager<CLIENT>* g_ClientSquirrelManager; -SquirrelManager<SERVER>* g_ServerSquirrelManager; -SquirrelManager<UI>* g_UISquirrelManager; +std::unique_ptr<SquirrelManager<CLIENT>> g_ClientSquirrelManager; +std::unique_ptr<SquirrelManager<SERVER>> g_ServerSquirrelManager; +std::unique_ptr<SquirrelManager<UI>> g_UISquirrelManager; SQInteger NSTestFunc(void* sqvm) { @@ -102,13 +102,13 @@ void InitialiseClientSquirrel(HMODULE baseAddress) HookEnabler hook; // client inits - g_ClientSquirrelManager = new SquirrelManager<CLIENT>(); + g_ClientSquirrelManager = std::make_unique<SquirrelManager<CLIENT>>(); ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x12B00, &SQPrintHook<CLIENT>, reinterpret_cast<LPVOID*>(&ClientSQPrint)); // client print function RegisterConCommand("script_client", ExecuteCodeCommand<CLIENT>, "Executes script code on the client vm", FCVAR_CLIENTDLL); // ui inits - g_UISquirrelManager = new SquirrelManager<UI>(); + g_UISquirrelManager = std::make_unique<SquirrelManager<UI>>(); ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x12BA0, &SQPrintHook<UI>, reinterpret_cast<LPVOID*>(&UISQPrint)); // ui print function RegisterConCommand("script_ui", ExecuteCodeCommand<UI>, "Executes script code on the ui vm", FCVAR_CLIENTDLL); @@ -139,7 +139,7 @@ void InitialiseClientSquirrel(HMODULE baseAddress) void InitialiseServerSquirrel(HMODULE baseAddress) { - g_ServerSquirrelManager = new SquirrelManager<SERVER>(); + g_ServerSquirrelManager = std::make_unique<SquirrelManager<SERVER>>(); g_ServerSquirrelManager->AddFuncRegistration("void", "SavePdataForEntityIndex", "int i", "idk", NSTestFunc); HookEnabler hook; @@ -278,16 +278,16 @@ 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) { - 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()); } } } @@ -302,16 +302,16 @@ 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) { - 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()); } } } @@ -327,16 +327,16 @@ 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) { - 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()); } } } @@ -351,16 +351,16 @@ 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) { - 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()); } } } diff --git a/NorthstarDedicatedTest/squirrel.h b/NorthstarDedicatedTest/squirrel.h index 66abcd76..cd91d8ac 100644 --- a/NorthstarDedicatedTest/squirrel.h +++ b/NorthstarDedicatedTest/squirrel.h @@ -211,6 +211,6 @@ public: } }; -extern SquirrelManager<CLIENT>* g_ClientSquirrelManager; -extern SquirrelManager<SERVER>* g_ServerSquirrelManager; -extern SquirrelManager<UI>* g_UISquirrelManager;
\ No newline at end of file +extern std::unique_ptr<SquirrelManager<CLIENT>> g_ClientSquirrelManager; +extern std::unique_ptr<SquirrelManager<SERVER>> g_ServerSquirrelManager; +extern std::unique_ptr<SquirrelManager<UI>> g_UISquirrelManager;
\ No newline at end of file |