diff options
-rw-r--r-- | NorthstarDedicatedTest/filesystem.cpp | 8 | ||||
-rw-r--r-- | NorthstarDedicatedTest/keyvalues.cpp | 14 | ||||
-rw-r--r-- | NorthstarDedicatedTest/masterserver.cpp | 8 | ||||
-rw-r--r-- | NorthstarDedicatedTest/modlocalisation.cpp | 6 | ||||
-rw-r--r-- | NorthstarDedicatedTest/modmanager.cpp | 125 | ||||
-rw-r--r-- | NorthstarDedicatedTest/modmanager.h | 8 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptmodmenu.cpp | 52 | ||||
-rw-r--r-- | NorthstarDedicatedTest/scriptsrson.cpp | 18 | ||||
-rw-r--r-- | NorthstarDedicatedTest/squirrel.cpp | 56 | ||||
-rw-r--r-- | enc_temp_folder/1f2f287a281d83d9f25d929b98193d/dedicatedmaterialsystem.cpp | 186 | ||||
-rw-r--r-- | enc_temp_folder/9532ad42f9bf304d9fb7388cf83b5966/dllmain.cpp | 106 |
11 files changed, 147 insertions, 440 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()); } } } diff --git a/enc_temp_folder/1f2f287a281d83d9f25d929b98193d/dedicatedmaterialsystem.cpp b/enc_temp_folder/1f2f287a281d83d9f25d929b98193d/dedicatedmaterialsystem.cpp deleted file mode 100644 index 30a55b94..00000000 --- a/enc_temp_folder/1f2f287a281d83d9f25d929b98193d/dedicatedmaterialsystem.cpp +++ /dev/null @@ -1,186 +0,0 @@ -#pragma once -#include "pch.h" -#include "dedicated.h" -#include "dedicatedmaterialsystem.h" -#include "hookutils.h" - -void InitialiseDedicatedMaterialSystem(HMODULE baseAddress) -{ - if (!IsDedicated()) - return; - - //while (!IsDebuggerPresent()) - // Sleep(100); - - // not using these for now since they're related to nopping renderthread/gamewindow i.e. very hard - //{ - // // function that launches renderthread - // char* ptr = (char*)baseAddress + 0x87047; - // TempReadWrite rw(ptr); - // - // // make it not launch renderthread - // *ptr = (char)0x90; - // *(ptr + 1) = (char)0x90; - // *(ptr + 2) = (char)0x90; - // *(ptr + 3) = (char)0x90; - // *(ptr + 4) = (char)0x90; - // *(ptr + 5) = (char)0x90; - //} - // - //{ - // // some function that waits on renderthread job - // char* ptr = (char*)baseAddress + 0x87d00; - // TempReadWrite rw(ptr); - // - // // return immediately - // *ptr = (char)0xC3; - //} - - { - // CMaterialSystem::FindMaterial - char* ptr = (char*)baseAddress + 0x5F0F1; - TempReadWrite rw(ptr); - - // make the game always use the error material - *ptr = 0xE9; - *(ptr + 1) = (char)0x34; - *(ptr + 2) = (char)0x03; - *(ptr + 3) = (char)0x00; - } - - if (DisableDedicatedWindowCreation()) - { - { - // materialsystem rpak type registrations - char* ptr = (char*)baseAddress + 0x22B5; - TempReadWrite rw(ptr); - - // nop a call that crashes, not needed on dedi - *ptr = 0x90; - *(ptr + 1) = (char)0x90; - *(ptr + 2) = (char)0x90; - *(ptr + 3) = (char)0x90; - *(ptr + 4) = (char)0x90; - } - - // these don't work, they cause game to hang on loading - { - // materialsystem rpak type: texture - char* ptr = (char*)baseAddress + 0x2B00; - TempReadWrite rw(ptr); - - // make it return 0 - // mov rax,0 - *ptr = 0x48; - *(ptr + 1) = (char)0xB8; - *(ptr + 2) = (char)0x00; - *(ptr + 3) = (char)0x00; - *(ptr + 4) = (char)0x00; - *(ptr + 5) = (char)0x00; - *(ptr + 6) = (char)0x00; - *(ptr + 7) = (char)0x00; - *(ptr + 8) = (char)0x00; - *(ptr + 9) = (char)0x00; - - // ret - *(ptr + 10) = (char)0xC3; - } - - { - // materialsystem rpak type: material - char* ptr = (char*)baseAddress + 0x50AA0; - TempReadWrite rw(ptr); - - // make it return 0 - // mov rax,0 - *ptr = 0x48; - *(ptr + 1) = (char)0xB8; - *(ptr + 2) = (char)0x00; - *(ptr + 3) = (char)0x00; - *(ptr + 4) = (char)0x00; - *(ptr + 5) = (char)0x00; - *(ptr + 6) = (char)0x00; - *(ptr + 7) = (char)0x00; - *(ptr + 8) = (char)0x00; - *(ptr + 9) = (char)0x00; - - // ret - *(ptr + 10) = (char)0xC3; - } - - { - // materialsystem rpak type: shader - char* ptr = (char*)baseAddress + 0x2850; - TempReadWrite rw(ptr); - - // make it return 0 - // mov rax,0 - *ptr = 0x48; - *(ptr + 1) = (char)0xB8; - *(ptr + 2) = (char)0x00; - *(ptr + 3) = (char)0x00; - *(ptr + 4) = (char)0x00; - *(ptr + 5) = (char)0x00; - *(ptr + 6) = (char)0x00; - *(ptr + 7) = (char)0x00; - *(ptr + 8) = (char)0x00; - *(ptr + 9) = (char)0x00; - - // ret - *(ptr + 10) = (char)0xC3; - } - - { - // some renderthread stuff - char* ptr = (char*)baseAddress + 0x8C10; - TempReadWrite rw(ptr); - - // call => nop - *ptr = (char)0x90; - *(ptr + 1) = (char)0x90; - } - } -} - -// rpak pain -struct RpakTypeDefinition -{ - int64_t magic; - char* longName; - - // more fields but they don't really matter for what we use them for -}; - -typedef void*(*RegisterRpakTypeType)(RpakTypeDefinition* rpakStruct, unsigned int a1, unsigned int a2); -RegisterRpakTypeType RegisterRpakType; - -typedef void(*RegisterMaterialSystemRpakTypes)(); - -void* RegisterRpakTypeHook(RpakTypeDefinition* rpakStruct, unsigned int a1, unsigned int a2) -{ - // make sure this prints right - char magicName[5]; - memcpy(magicName, &rpakStruct->magic, 4); - magicName[4] = 0; - - spdlog::info("rpak type {} {} registered {} {}", magicName, rpakStruct->longName, a1, a2); - - // reregister rpak types that aren't registered on a windowless dedi - if (IsDedicated() && DisableDedicatedWindowCreation() && rpakStruct->magic == 0x64636C72) // rlcd, this one is registered last - ((RegisterMaterialSystemRpakTypes)((char*)GetModuleHandleA("materialsystem_dx11.dll") + 0x22A0))(); // slightly hellish call - - return RegisterRpakType(rpakStruct, a1, a2); -} - -void InitialiseDedicatedRtechGame(HMODULE baseAddress) -{ - spdlog::info("InitialiseDedicatedRtechGame"); - - HookEnabler hook; - ENABLER_CREATEHOOK(hook, (char*)GetModuleHandleA("rtech_game.dll") + 0x7BE0, &RegisterRpakTypeHook, reinterpret_cast<LPVOID*>(&RegisterRpakType)); - - if (!IsDedicated()) - return; - - -}
\ No newline at end of file diff --git a/enc_temp_folder/9532ad42f9bf304d9fb7388cf83b5966/dllmain.cpp b/enc_temp_folder/9532ad42f9bf304d9fb7388cf83b5966/dllmain.cpp deleted file mode 100644 index 7d347097..00000000 --- a/enc_temp_folder/9532ad42f9bf304d9fb7388cf83b5966/dllmain.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include "pch.h" -#include "hooks.h" -#include "main.h" -#include "squirrel.h" -#include "tier0.h" -#include "dedicated.h" -#include "dedicatedmaterialsystem.h" -#include "sourceconsole.h" -#include "logging.h" -#include "concommand.h" -#include "modmanager.h" -#include "filesystem.h" -#include "serverauthentication.h" -#include "scriptmodmenu.h" -#include "scriptserverbrowser.h" -#include "keyvalues.h" -#include "masterserver.h" -#include "gameutils.h" -#include "chatcommand.h" -#include "modlocalisation.h" -#include "playlist.h" -#include "securitypatches.h" -#include "miscserverscript.h" - -bool initialised = false; - -BOOL APIENTRY DllMain( HMODULE hModule, - DWORD ul_reason_for_call, - LPVOID lpReserved - ) -{ - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - - if (!initialised) - InitialiseNorthstar(); - initialised = true; - - return TRUE; -} - -void WaitForDebugger(HMODULE baseAddress) -{ - // earlier waitfordebugger call than is in vanilla, just so we can debug stuff a little easier - if (CommandLine()->CheckParm("-waitfordebugger")) - { - while (!IsDebuggerPresent()) - Sleep(100); - } -} - -// in the future this will be called from launcher instead of dllmain -void InitialiseNorthstar() -{ - InitialiseLogging(); - - // apply initial hooks - InstallInitialHooks(); - InitialiseInterfaceCreationHooks(); - - AddDllLoadCallback("engine.dll", WaitForDebugger); - AddDllLoadCallback("engine.dll", InitialiseEngineGameUtilFunctions); - AddDllLoadCallback("server.dll", InitialiseServerGameUtilFunctions); - AddDllLoadCallback("engine.dll", InitialiseEngineSpewFuncHooks); - - // dedi patches - { - AddDllLoadCallback("engine.dll", InitialiseDedicated); - AddDllLoadCallback("launcher.dll", InitialiseDedicatedOrigin); - AddDllLoadCallback("materialsystem_dx11.dll", InitialiseDedicatedMaterialSystem); - AddDllLoadCallback("engine.dll", InitialiseDedicatedRtechGame); - } - - AddDllLoadCallback("engine.dll", InitialiseConVars); - AddDllLoadCallback("engine.dll", InitialiseConCommands); - - // client-exclusive patches - { - AddDllLoadCallback("engine.dll", InitialiseClientEngineSecurityPatches); - AddDllLoadCallback("client.dll", InitialiseClientSquirrel); - AddDllLoadCallback("client.dll", InitialiseSourceConsole); - AddDllLoadCallback("engine.dll", InitialiseChatCommands); - AddDllLoadCallback("client.dll", InitialiseScriptModMenu); - AddDllLoadCallback("client.dll", InitialiseScriptServerBrowser); - AddDllLoadCallback("localize.dll", InitialiseModLocalisation); - } - - AddDllLoadCallback("server.dll", InitialiseServerSquirrel); - AddDllLoadCallback("engine.dll", InitialiseServerAuthentication); - AddDllLoadCallback("engine.dll", InitialiseSharedMasterServer); - AddDllLoadCallback("server.dll", InitialiseMiscServerScriptCommand); - - AddDllLoadCallback("engine.dll", InitialisePlaylistHooks); - - AddDllLoadCallback("filesystem_stdio.dll", InitialiseFilesystem); - AddDllLoadCallback("engine.dll", InitialiseKeyValues); - - // mod manager after everything else - AddDllLoadCallback("engine.dll", InitialiseModManager); -}
\ No newline at end of file |