Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for loading Thunderstore mods natively #503

Merged
merged 10 commits into from
Jul 16, 2023
22 changes: 22 additions & 0 deletions NorthstarDLL/mods/modmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,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();
Expand Down Expand Up @@ -410,6 +411,23 @@ 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());
for (fs::directory_entry dir : thunderstoreModsDir)
{
fs::path modsDir = dir.path() / "mods"; // Check for mods folder in the Thunderstore mod
GeckoEidechse marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -837,6 +855,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);
Expand Down
2 changes: 2 additions & 0 deletions NorthstarDLL/mods/modmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <filesystem>

const std::string MOD_FOLDER_SUFFIX = "/mods";
const std::string THUNDERSTORE_MOD_FOLDER_SUFFIX = "/thunderstore-mods";
GeckoEidechse marked this conversation as resolved.
Show resolved Hide resolved
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";
Expand Down Expand Up @@ -168,6 +169,7 @@ class ModManager

fs::path GetModFolderPath();
fs::path GetRemoteModFolderPath();
fs::path GetThunderstoreModFolderPath();
fs::path GetCompiledAssetsPath();

extern ModManager* g_pModManager;