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

Create mod entry in enabledmods.json if it doesn't exist #410

Merged
merged 15 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions NorthstarDLL/mods/modmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ Mod::Mod(fs::path modDir, char* jsonBuf)
ParseDependencies(modJson);
ParseInitScript(modJson);

// A mod is remote if it's located in the remote mods folder
m_bIsRemote = m_ModDirectory.generic_string().find(GetRemoteModFolderPath().generic_string()) != std::string::npos;

m_bWasReadSuccessfully = true;
}

Expand Down Expand Up @@ -703,11 +706,21 @@ void ModManager::LoadMods()
// sort by load prio, lowest-highest
std::sort(m_LoadedMods.begin(), m_LoadedMods.end(), [](Mod& a, Mod& b) { return a.LoadPriority < b.LoadPriority; });

// This is used to check if some mods have a folder but no entry in enabledmods.json
bool newModsDetected = false;

for (Mod& mod : m_LoadedMods)
{
if (!mod.m_bEnabled)
continue;

// Add mod entry to enabledmods.json if it doesn't exist
if (!mod.m_bIsRemote && !m_EnabledModsCfg.HasMember(mod.Name.c_str()))
GeckoEidechse marked this conversation as resolved.
Show resolved Hide resolved
{
m_EnabledModsCfg.AddMember(rapidjson_document::StringRefType(mod.Name.c_str()), true, m_EnabledModsCfg.GetAllocator());
newModsDetected = true;
}

// 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 note: we don't delete convars if they already exist because they're used for script stuff, unfortunately this
Expand Down Expand Up @@ -937,6 +950,15 @@ void ModManager::LoadMods()
}
}

// If there are new mods, we write entries accordingly in enabledmods.json
if (newModsDetected)
{
std::ofstream writeStream(GetNorthstarPrefix() + "/enabledmods.json");
rapidjson::OStreamWrapper writeStreamWrapper(writeStream);
rapidjson::PrettyWriter<rapidjson::OStreamWrapper> writer(writeStreamWrapper);
m_EnabledModsCfg.Accept(writer);
}

// in a seperate loop because we register mod files in reverse order, since mods loaded later should have their files prioritised
for (int64_t i = m_LoadedMods.size() - 1; i > -1; i--)
{
Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/mods/modmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Mod
bool m_bEnabled = true;
bool m_bWasReadSuccessfully = false;
fs::path m_ModDirectory;
// bool m_bIsRemote;
bool m_bIsRemote;

// mod.json stuff:

Expand Down