From d237401bb97c1fa2d6ee87220d49e4b3343e7201 Mon Sep 17 00:00:00 2001
From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com>
Date: Sun, 13 Nov 2022 00:26:46 +0000
Subject: allow kb_act.lst to be compiled from multiple mods (#298)
* allow kb_act.lst to be compiled from multiple mods
* fixup formatting
* add a couple extra comments because i really did not add enough
---
NorthstarDLL/NorthstarDLL.vcxproj | 1 +
NorthstarDLL/NorthstarDLL.vcxproj.filters | 3 +++
NorthstarDLL/kb_act.cpp | 45 +++++++++++++++++++++++++++++++
NorthstarDLL/modmanager.cpp | 3 +++
NorthstarDLL/modmanager.h | 2 ++
5 files changed, 54 insertions(+)
create mode 100644 NorthstarDLL/kb_act.cpp
diff --git a/NorthstarDLL/NorthstarDLL.vcxproj b/NorthstarDLL/NorthstarDLL.vcxproj
index 11f42d64..894de139 100644
--- a/NorthstarDLL/NorthstarDLL.vcxproj
+++ b/NorthstarDLL/NorthstarDLL.vcxproj
@@ -575,6 +575,7 @@
+
diff --git a/NorthstarDLL/NorthstarDLL.vcxproj.filters b/NorthstarDLL/NorthstarDLL.vcxproj.filters
index 168b4751..b34f1c71 100644
--- a/NorthstarDLL/NorthstarDLL.vcxproj.filters
+++ b/NorthstarDLL/NorthstarDLL.vcxproj.filters
@@ -1700,6 +1700,9 @@
Source Files\Scripted
+
+ Source Files\Mods\Compiled Assets
+
Source Files\Client
diff --git a/NorthstarDLL/kb_act.cpp b/NorthstarDLL/kb_act.cpp
new file mode 100644
index 00000000..5fe71cdb
--- /dev/null
+++ b/NorthstarDLL/kb_act.cpp
@@ -0,0 +1,45 @@
+#include "pch.h"
+#include "modmanager.h"
+#include "filesystem.h"
+
+#include
+
+const char* KB_ACT_PATH = "scripts\\kb_act.lst";
+
+// compiles the file kb_act.lst, that defines entries for keybindings in the options menu
+void ModManager::BuildKBActionsList()
+{
+ spdlog::info("Building kb_act.lst");
+
+ fs::create_directories(GetCompiledAssetsPath() / "scripts");
+ std::ofstream soCompiledKeys(GetCompiledAssetsPath() / KB_ACT_PATH, std::ios::binary);
+
+ // write vanilla file's content to compiled file
+ soCompiledKeys << R2::ReadVPKOriginalFile(KB_ACT_PATH);
+
+ for (Mod& mod : m_LoadedMods)
+ {
+ if (!mod.m_bEnabled)
+ continue;
+
+ // write content of each modded file to compiled file
+ std::ifstream siModKeys(mod.m_ModDirectory / "kb_act.lst");
+
+ if (siModKeys.good())
+ soCompiledKeys << siModKeys.rdbuf() << std::endl;
+
+ siModKeys.close();
+ }
+
+ soCompiledKeys.close();
+
+ // push to overrides
+ ModOverrideFile overrideFile;
+ overrideFile.m_pOwningMod = nullptr;
+ overrideFile.m_Path = KB_ACT_PATH;
+
+ if (m_ModFiles.find(KB_ACT_PATH) == m_ModFiles.end())
+ m_ModFiles.insert(std::make_pair(KB_ACT_PATH, overrideFile));
+ else
+ m_ModFiles[KB_ACT_PATH] = overrideFile;
+}
diff --git a/NorthstarDLL/modmanager.cpp b/NorthstarDLL/modmanager.cpp
index 07a197dd..d95bcbce 100644
--- a/NorthstarDLL/modmanager.cpp
+++ b/NorthstarDLL/modmanager.cpp
@@ -262,6 +262,7 @@ ModManager::ModManager()
m_hPdefHash = STR_HASH(
"cfg\\server\\persistent_player_data_version_231.pdef" // this can have multiple versions, but we use 231 so that's what we hash
);
+ m_hKBActHash = STR_HASH("scripts\\kb_act.lst");
LoadMods();
}
@@ -685,6 +686,8 @@ void ModManager::CompileAssetsForFile(const char* filename)
BuildScriptsRson();
else if (fileHash == m_hPdefHash)
BuildPdef();
+ else if (fileHash == m_hKBActHash)
+ BuildKBActionsList();
else
{
// check if we should build keyvalues, depending on whether any of our mods have patch kvs for this file
diff --git a/NorthstarDLL/modmanager.h b/NorthstarDLL/modmanager.h
index 9f57c69a..6540a3de 100644
--- a/NorthstarDLL/modmanager.h
+++ b/NorthstarDLL/modmanager.h
@@ -127,6 +127,7 @@ class ModManager
// precalculated hashes
size_t m_hScriptsRsonHash;
size_t m_hPdefHash;
+ size_t m_hKBActHash;
public:
std::vector m_LoadedMods;
@@ -144,6 +145,7 @@ class ModManager
void BuildScriptsRson();
void TryBuildKeyValues(const char* filename);
void BuildPdef();
+ void BuildKBActionsList();
};
fs::path GetModFolderPath();
--
cgit v1.2.3