Skip to content

Mod Compatibility Fixes #291

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Mod Compatibility Fixes #291

wants to merge 2 commits into from

Conversation

BrickPi
Copy link
Contributor

@BrickPi BrickPi commented Feb 3, 2025

  • Implements a "ModManager" which loads .mod files
  • Implements replace_path when searching for files
  • Myriad changes to better reflect how V2 handles systems
  • HPM now successfully loads and runs under OpenVic

@BrickPi BrickPi added the enhancement New feature or request label Feb 3, 2025
Copy link
Contributor

@wvpm wvpm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this PR do not reflect how Victoria 2 works.
Carefully research Victoria 2 instead of trusting in mods.
Mods often just use things without realising it doesn't work.

@@ -79,6 +79,7 @@ bool ConditionManager::setup_conditions(DefinitionManager const& definition_mana
ret &= add_condition("any_greater_power", GROUP, COUNTRY, COUNTRY);
ret &= add_condition("any_neighbor_country", GROUP, COUNTRY, COUNTRY);
ret &= add_condition("any_owned_province", GROUP, COUNTRY, PROVINCE);
ret &= add_condition("any_owned", GROUP, COUNTRY, PROVINCE); // alias? not in vanilla, but used by HPM poptypes, so used by a ton of derivative mods too
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an effect scope. See https://vic2.paradoxwikis.com/List_of_scopes#any_owned
It is easily mistaken for a condition scope.

@BrickPi BrickPi force-pushed the improve-mod-loading branch from 76f501e to e5a01cf Compare March 17, 2025 11:22
@@ -120,7 +121,10 @@ using namespace std::string_view_literals;
constexpr bool key_value_success_callback(std::string_view, ast::NodeCPtr) {
return true;
}

inline bool key_value_warn_callback(std::string_view key, ast::NodeCPtr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map_key_value_ignore_invalid_callback was added in a recent PR.
Please use that instead as it lists the valid keys.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue with map_key_value_ignore_invalid_callback for this usecase is it returns false, when the vic2 behaviour is to continue and ignore, hence a warning callback fits better here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map_key_value_ignore_invalid_callback is only added in #363 see https://github.com/OpenVicProject/OpenVic-Simulation/pull/363/files#diff-863e89118363d8d3e04ddc1233a97cc3c3fef0851315e8d61847db35e681c07c
Once that is merged, you can use it here. If there is an obstacle to merging, I'll take the nodetools part out and make a separate PR for that.

"rotation", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(rotation))
"rotation", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(rotation)),

"maxWidth", ZERO_OR_ONE, [](ast::NodeCPtr node) -> bool { Logger::warning("maxWidth has no effect, so this line will do nothing."); return true; }, /* some mods use these to no effect */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a custom callback for this?
Wouldn't the default map_key_value_invalid_callback suffice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't work in this scenario since we only have a NodeCPtr to pass. Changed to success_callback here to match the rest of GUI.cpp

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A success_callback lies to modders by acting as if these values are parsed. Instead they are invalid and should result in a warning.

My clangd is broken so I can't untangle the nodetools overloads mess.
Still there is a method that uses map_key_value_invalid_callback as default callback so invalid keys are reported as warnings and valid keys are listed. Use that instead of adding entries for made up keys.

wvpm
wvpm previously approved these changes Mar 17, 2025
Copy link
Contributor

@wvpm wvpm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with minor comments.

@BrickPi BrickPi force-pushed the improve-mod-loading branch from 5b7386e to 558e096 Compare March 24, 2025 17:39
@BrickPi BrickPi requested a review from wvpm March 24, 2025 17:40
@BrickPi BrickPi force-pushed the improve-mod-loading branch from 558e096 to 73423c5 Compare March 24, 2025 17:43
@@ -218,6 +234,7 @@ int main(int argc, char const* argv[]) {

char const* program_name = StringUtils::get_filename(argc > 0 ? argv[0] : nullptr, "<program>");
fs::path root;
std::vector<std::string> mods;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::vector<std::string> mods;
std::vector<std::string> mods;
mods.reserve(argc);

Copy link
Member

@Spartan322 Spartan322 Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically we could have std::vector<std::string_view> here, but vector of string_views is not convertible to vector of strings so everything need to support vector of string_views instead.

@@ -159,7 +160,8 @@ bool ProvinceHistoryMap::_load_history_entry(
}
}
return ret;
}
},
"revolt", ZERO_OR_ONE, [&entry](ast::NodeCPtr node) -> bool { Logger::warning("In province history for ", entry.get_province(), " key \"revolt\" has no effect!"); return true; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a custom message. Use either map_key_value_ignore_invalid_callback or map_key_value_invalid_callback to handle all such cases.

Copy link
Contributor

@wvpm wvpm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid custom callbacks for invalid keys. Use the default handling instead.
Either map_key_value_invalid_callback or map_key_value_ignore_invalid_callback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants