Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions doc/config/modloader.ini.0
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
;
[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.
ExcludeAllMods = false ; Excludes all mods from being loaded except the ones at IncludeMods list

[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]
Expand Down
3 changes: 2 additions & 1 deletion src/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 9 additions & 5 deletions src/core/extras/gta3/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(MenuEntry&)> cb) -> std::function<bool(ActionInfo&)>
{
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)
{
Expand All @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions src/core/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void Loader::FolderInformation::Clear()
mods.clear();
profiles.clear();
current_profile = nullptr;
priority_limit = default_priority_limit;
}

/*
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/core/loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<class T>
struct SimplePriorityPred
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -454,6 +459,7 @@ class Loader : public modloader_t
Loader::Profile* current_profile;// Curretly selected profile from the 'profiles' list
std::unique_ptr<Loader::Profile> 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; }
Expand Down
2 changes: 1 addition & 1 deletion src/core/profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/*
Expand Down