diff --git a/doc/config/modloader.ini.0 b/doc/config/modloader.ini.0 index 11fa34f7..ffc06f3a 100644 --- a/doc/config/modloader.ini.0 +++ b/doc/config/modloader.ini.0 @@ -3,6 +3,7 @@ ; [Folder.Config] Profile = Default ; Profile to be used to configure mods +PriorityLimit = 100 ; Max allowed value in Profiles.*.Priority (minimum is 1) [Profiles.Default.Config] IgnoreAllMods = false ; Ignores all mods. This essentially disables mods loading. @@ -10,8 +11,9 @@ ExcludeAllMods = false ; Excludes all mods from being loaded except t [Profiles.Default.Priority] ; Defines mods priority (which mods should go into effect if both replaces the same file) -; The priority should be between 1 and 100, where 100 overrides 1, additionally priority 0 makes be ignored (just like IgnoreMods) -; The default priority is 50! +; The priority should be between 1 and PriorityLimit, where higher values override lower ones. +; Additionally priority 0 makes the mod be ignored (just like IgnoreMods). +; The default priority is 50. ;MyMod=50 [Profiles.Default.IgnoreFiles] diff --git a/src/core/config.cpp b/src/core/config.cpp index dd953f38..623be4d9 100644 --- a/src/core/config.cpp +++ b/src/core/config.cpp @@ -242,7 +242,8 @@ void Loader::UpdateOldConfig_0115_021() for(auto& kv : newer["Priority"]) { auto pr = std::stoi(kv.second); - kv.second = std::to_string(pr > 0 && pr <= 100? 101 - pr : pr); + auto limit = this->mods.GetPriorityLimit(); + kv.second = std::to_string(pr > 0 && pr <= limit? (limit + 1) - pr : pr); } newer.write_file(gamePath + "modloader/" + folderConfigFilename); diff --git a/src/core/extras/gta3/menu.cpp b/src/core/extras/gta3/menu.cpp index 186ed6c8..ffd07a1f 100644 --- a/src/core/extras/gta3/menu.cpp +++ b/src/core/extras/gta3/menu.cpp @@ -610,7 +610,7 @@ void TheMenu::ModPageEvents() // Helper function to setup a integer priority entry in the menu auto SetupPriorityEntry = [this](const char* label, uint32_t& priority, std::function cb) -> std::function { - static const uint32_t min = 0, max = 100, step = 1; + const uint32_t min = 0, max = loader.mods.GetPriorityLimit(), step = 1; auto PriorityLabel = [](const uint32_t& priority) { @@ -624,10 +624,14 @@ void TheMenu::ModPageEvents() entry->SetHelper(HelpLabel(label)); entry->OnStateChange(cb); - auto fInitStates = entry->SetupStatefulEntry(std::ref(priority), std::ref(PriorityLabel), [](const uint32_t& value, ActionInfo& info) - { - return std::min(std::max((value + step * info.wheel), min), max); - }); + auto fInitStates = entry->SetupStatefulEntry( + std::ref(priority), + std::ref(PriorityLabel), + [min, max, step](const uint32_t& value, ActionInfo& info) + { + return std::min(std::max((value + step * info.wheel), min), max); + } + ); return fInitStates; } diff --git a/src/core/folder.cpp b/src/core/folder.cpp index 7ffe2865..aa194667 100644 --- a/src/core/folder.cpp +++ b/src/core/folder.cpp @@ -16,6 +16,7 @@ void Loader::FolderInformation::Clear() mods.clear(); profiles.clear(); current_profile = nullptr; + priority_limit = default_priority_limit; } /* @@ -374,7 +375,13 @@ void Loader::FolderInformation::LoadConfigFromINI() // First take the profiles from modloader.ini if(ini.load_file(loader.folderConfigFilename)) + { + const auto default_limit = std::to_string(default_priority_limit); + const auto priority_limit = std::strtol(ini.get("Folder.Config", "PriorityLimit", default_limit).c_str(), 0, 0); + this->SetPriorityLimit(priority_limit); + ReadProfilesFromINI(ini, ""); + } else Log("Warning: Failed to load folder config file"); @@ -411,6 +418,7 @@ void Loader::FolderInformation::SaveConfigForINI() // Save current profile ini.set("Folder.Config", "Profile", this->Profile().GetName()); + ini.set("Folder.Config", "PriorityLimit", std::to_string(this->GetPriorityLimit())); // Save all the profiles for(auto& profile : this->profiles) diff --git a/src/core/loader.hpp b/src/core/loader.hpp index 2728ad39..3b377853 100644 --- a/src/core/loader.hpp +++ b/src/core/loader.hpp @@ -34,6 +34,8 @@ static const char* downurl = "https://github.com/thelink2012/modloader/releases" // static const char* default_profile_name = "Default"; +static const int default_priority_limit = 100; + // Functor for sorting based on priority template struct SimplePriorityPred @@ -413,6 +415,9 @@ class Loader : public modloader_t // Gets the path to this modfolder (relative to gamedir, normalized) const std::string& GetPath() { return path; } + + int GetPriorityLimit() const { return this->priority_limit; } + void SetPriorityLimit(int value) { this->priority_limit = std::max(value, 1); } // Clears all buffers from this structure void Clear(); @@ -454,6 +459,7 @@ class Loader : public modloader_t Loader::Profile* current_profile;// Curretly selected profile from the 'profiles' list std::unique_ptr anon_profile;// Forced temporary profile (made by command line, conditionals, etc) // The .first boolean specifies whether we have a temporary profile + int priority_limit = default_priority_limit; // Max allowed priority for mods in this folder config protected: void SetUnchanged() { if(status != Status::Removed) status = Status::Unchanged; } diff --git a/src/core/profiles.cpp b/src/core/profiles.cpp index 94915281..818665cf 100644 --- a/src/core/profiles.cpp +++ b/src/core/profiles.cpp @@ -256,7 +256,7 @@ void Loader::Profile::SetPriority(std::string name, int priority) if(priority == default_priority) mods_priority.erase(name); else - mods_priority[name] = std::max(std::min(priority, 100), 0); // clamp to 0-100 + mods_priority[name] = std::max(std::min(priority, this->parent.GetPriorityLimit()), 0); // clamp to 0-priorityLimit } /*