diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-11-07 01:35:06 +0000 |
---|---|---|
committer | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-11-07 01:35:06 +0000 |
commit | 365191707407566841c1e37935619d260a4f67a7 (patch) | |
tree | 760ada58fcc051d892d886ddee9849ce3628d829 /NorthstarDedicatedTest | |
parent | a7fd103124d6e6a506d8f837b9a29a97f0ea7e63 (diff) | |
download | NorthstarLauncher-365191707407566841c1e37935619d260a4f67a7.tar.gz NorthstarLauncher-365191707407566841c1e37935619d260a4f67a7.zip |
more modmanager improvements
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r-- | NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj | 2 | ||||
-rw-r--r-- | NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters | 6 | ||||
-rw-r--r-- | NorthstarDedicatedTest/modmanager.cpp | 18 | ||||
-rw-r--r-- | NorthstarDedicatedTest/modmanager.h | 5 | ||||
-rw-r--r-- | NorthstarDedicatedTest/pdef.cpp | 13 | ||||
-rw-r--r-- | NorthstarDedicatedTest/pdef.h | 4 |
6 files changed, 42 insertions, 6 deletions
diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj index 4997b322..fc3d0fbe 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj @@ -315,6 +315,7 @@ <ClInclude Include="modlocalisation.h" /> <ClInclude Include="modmanager.h" /> <ClInclude Include="pch.h" /> + <ClInclude Include="pdef.h" /> <ClInclude Include="playlist.h" /> <ClInclude Include="miscserverscript.h" /> <ClInclude Include="securitypatches.h" /> @@ -352,6 +353,7 @@ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> </ClCompile> + <ClCompile Include="pdef.cpp" /> <ClCompile Include="playlist.cpp" /> <ClCompile Include="securitypatches.cpp" /> <ClCompile Include="scriptmodmenu.cpp" /> diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters index 99f45f39..59a5cb19 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters @@ -579,6 +579,9 @@ <ClInclude Include="miscserverscript.h"> <Filter>Header Files\Server</Filter> </ClInclude> + <ClInclude Include="pdef.h"> + <Filter>Header Files\Shared\Mods\Compiled</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="dllmain.cpp"> @@ -671,6 +674,9 @@ <ClCompile Include="miscserverscript.cpp"> <Filter>Source Files\Server</Filter> </ClCompile> + <ClCompile Include="pdef.cpp"> + <Filter>Source Files\Shared\Mods\Compiled</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <None Include="include\spdlog\fmt\bundled\LICENSE.rst"> diff --git a/NorthstarDedicatedTest/modmanager.cpp b/NorthstarDedicatedTest/modmanager.cpp index de06fb73..66e6d048 100644 --- a/NorthstarDedicatedTest/modmanager.cpp +++ b/NorthstarDedicatedTest/modmanager.cpp @@ -184,6 +184,11 @@ Mod::Mod(fs::path modDir, char* jsonBuf) ModManager::ModManager() { + // precaculated string hashes + // note: use backslashes for these, since we use lexically_normal for file paths which uses them + m_hScriptsRsonHash = std::hash<std::string>{}("scripts\\vscripts\\scripts.rson"); + m_hPdefHash = std::hash<std::string>{}("cfg\\server\\persistent_player_data_version_231.pdef"); // this can have multiple versions, but we use 231 so that's what we hash + LoadMods(); } @@ -356,8 +361,6 @@ void ModManager::LoadMods() void ModManager::UnloadMods() { // clean up stuff from mods before we unload - - // do we need to dealloc individual entries in m_modFiles? idk, rework m_modFiles.clear(); fs::remove_all(COMPILED_ASSETS_PATH); @@ -373,6 +376,8 @@ void ModManager::UnloadMods() mod.KeyValues.clear(); // write to m_enabledModsCfg + // should we be doing this here or should scripts be doing this manually? + // main issue with doing this here is when we reload mods for connecting to a server, we write enabled mods, which isn't necessarily what we wanna do if (!m_enabledModsCfg.HasMember(mod.Name.c_str())) m_enabledModsCfg.AddMember(rapidjson::StringRef(mod.Name.c_str()), rapidjson::Value(false), m_enabledModsCfg.GetAllocator()); @@ -390,11 +395,13 @@ void ModManager::UnloadMods() void ModManager::CompileAssetsForFile(const char* filename) { - fs::path path(filename); + size_t fileHash = std::hash<std::string>{}(fs::path(filename).lexically_normal().string()); - if (!path.filename().compare("scripts.rson")) + if (fileHash == m_hScriptsRsonHash) BuildScriptsRson(); - else //if (!strcmp((filename + strlen(filename)) - 3, "txt")) // check if it's a .txt + else if (fileHash == m_hPdefHash) + BuildPdef(); + else { // check if we should build keyvalues, depending on whether any of our mods have patch kvs for this file for (Mod& mod : m_loadedMods) @@ -402,7 +409,6 @@ void ModManager::CompileAssetsForFile(const char* filename) if (!mod.Enabled) continue; - size_t fileHash = std::hash<std::string>{}(fs::path(filename).lexically_normal().string()); if (mod.KeyValues.find(fileHash) != mod.KeyValues.end()) { TryBuildKeyValues(filename); diff --git a/NorthstarDedicatedTest/modmanager.h b/NorthstarDedicatedTest/modmanager.h index e1c246b1..cc3442ec 100644 --- a/NorthstarDedicatedTest/modmanager.h +++ b/NorthstarDedicatedTest/modmanager.h @@ -102,6 +102,10 @@ private: bool m_hasEnabledModsCfg; rapidjson::Document m_enabledModsCfg; + // precalculated hashes + size_t m_hScriptsRsonHash; + size_t m_hPdefHash; + public: std::vector<Mod> m_loadedMods; std::unordered_map<std::string, ModOverrideFile> m_modFiles; @@ -115,6 +119,7 @@ public: // compile asset type stuff, these are done in files under Mods/Compiled/ void BuildScriptsRson(); void TryBuildKeyValues(const char* filename); + void BuildPdef(); }; void InitialiseModManager(HMODULE baseAddress); diff --git a/NorthstarDedicatedTest/pdef.cpp b/NorthstarDedicatedTest/pdef.cpp new file mode 100644 index 00000000..75ce3656 --- /dev/null +++ b/NorthstarDedicatedTest/pdef.cpp @@ -0,0 +1,13 @@ +#include "pch.h" +#include "modmanager.h" +#include "filesystem.h" +#include "hookutils.h" +#include "pdef.h" + +void ModManager::BuildPdef() +{ + spdlog::info("Building persistent_player_data_version_231.pdef..."); + + std::string originalPdef = ReadVPKOriginalFile(VPK_PDEF_PATH); + spdlog::info(originalPdef); +}
\ No newline at end of file diff --git a/NorthstarDedicatedTest/pdef.h b/NorthstarDedicatedTest/pdef.h new file mode 100644 index 00000000..eb5f668b --- /dev/null +++ b/NorthstarDedicatedTest/pdef.h @@ -0,0 +1,4 @@ +#pragma once + +const fs::path MOD_PDEF_PATH = COMPILED_ASSETS_PATH / "cfg/server/persistent_player_data_version_231.pdef"; +const char* VPK_PDEF_PATH = "cfg/server/persistent_player_data_version_231.pdef";
\ No newline at end of file |