aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2023-07-16 21:23:50 +0200
committerGitHub <noreply@github.com>2023-07-16 21:23:50 +0200
commit0309af134ef01e0074057e0580c8155028998fcf (patch)
tree4f74e4321b5a5b2170762da6c86e4cdd18d0a3d6
parent9f9e3a906f2792ee518c7d9910d70607469f80ae (diff)
downloadNorthstarLauncher-0309af134ef01e0074057e0580c8155028998fcf.tar.gz
NorthstarLauncher-0309af134ef01e0074057e0580c8155028998fcf.zip
Add support for loading Thunderstore mods natively (#503)
Allows for loading Thunderstore mods directly from a separate directory called `packages`.
-rw-r--r--NorthstarDLL/mods/modmanager.cpp30
-rw-r--r--NorthstarDLL/mods/modmanager.h2
2 files changed, 32 insertions, 0 deletions
diff --git a/NorthstarDLL/mods/modmanager.cpp b/NorthstarDLL/mods/modmanager.cpp
index d2cc8eb8..c54314c0 100644
--- a/NorthstarDLL/mods/modmanager.cpp
+++ b/NorthstarDLL/mods/modmanager.cpp
@@ -587,6 +587,7 @@ void ModManager::LoadMods()
// ensure dirs exist
fs::remove_all(GetCompiledAssetsPath());
fs::create_directories(GetModFolderPath());
+ fs::create_directories(GetThunderstoreModFolderPath());
fs::create_directories(GetRemoteModFolderPath());
m_DependencyConstants.clear();
@@ -616,6 +617,31 @@ void ModManager::LoadMods()
if (fs::exists(dir.path() / "mod.json"))
modDirs.push_back(dir.path());
+ // Special case for Thunderstore mods dir
+ std::filesystem::directory_iterator thunderstoreModsDir = fs::directory_iterator(GetThunderstoreModFolderPath());
+ // Set up regex for `AUTHOR-MOD-VERSION` pattern
+ std::regex pattern(R"(.*\\([a-zA-Z0-9_]+)-([a-zA-Z0-9_]+)-(\d+\.\d+\.\d+))");
+ for (fs::directory_entry dir : thunderstoreModsDir)
+ {
+ fs::path modsDir = dir.path() / "mods"; // Check for mods folder in the Thunderstore mod
+ // Use regex to match `AUTHOR-MOD-VERSION` pattern
+ if (!std::regex_match(dir.path().string(), pattern))
+ {
+ spdlog::warn("The following directory did not match 'AUTHOR-MOD-VERSION': {}", modsDir.string());
+ continue; // skip loading mod that doesn't match
+ }
+ if (fs::exists(modsDir) && fs::is_directory(modsDir))
+ {
+ for (fs::directory_entry subDir : fs::directory_iterator(modsDir))
+ {
+ if (fs::exists(subDir.path() / "mod.json"))
+ {
+ modDirs.push_back(subDir.path());
+ }
+ }
+ }
+ }
+
for (fs::path modDir : modDirs)
{
// read mod json file
@@ -1049,6 +1075,10 @@ fs::path GetModFolderPath()
{
return fs::path(GetNorthstarPrefix() + MOD_FOLDER_SUFFIX);
}
+fs::path GetThunderstoreModFolderPath()
+{
+ return fs::path(GetNorthstarPrefix() + THUNDERSTORE_MOD_FOLDER_SUFFIX);
+}
fs::path GetRemoteModFolderPath()
{
return fs::path(GetNorthstarPrefix() + REMOTE_MOD_FOLDER_SUFFIX);
diff --git a/NorthstarDLL/mods/modmanager.h b/NorthstarDLL/mods/modmanager.h
index 33f4ceac..6f89f9f2 100644
--- a/NorthstarDLL/mods/modmanager.h
+++ b/NorthstarDLL/mods/modmanager.h
@@ -9,6 +9,7 @@
#include <filesystem>
const std::string MOD_FOLDER_SUFFIX = "/mods";
+const std::string THUNDERSTORE_MOD_FOLDER_SUFFIX = "/packages";
const std::string REMOTE_MOD_FOLDER_SUFFIX = "/runtime/remote/mods";
const fs::path MOD_OVERRIDE_DIR = "mod";
const std::string COMPILED_ASSETS_SUFFIX = "/runtime/compiled";
@@ -176,6 +177,7 @@ class ModManager
fs::path GetModFolderPath();
fs::path GetRemoteModFolderPath();
+fs::path GetThunderstoreModFolderPath();
fs::path GetCompiledAssetsPath();
extern ModManager* g_pModManager;