diff --git a/include/loot/plugin_interface.h b/include/loot/plugin_interface.h index 3290eea5..de335a94 100644 --- a/include/loot/plugin_interface.h +++ b/include/loot/plugin_interface.h @@ -99,6 +99,12 @@ public: */ virtual bool IsLightPlugin() const = 0; + /** + * Check if the plugin is a medium plugin. + * @return True if plugin is a medium plugin, false otherwise. + */ + virtual bool IsMediumPlugin() const = 0; + /** * Check if the plugin is an override plugin. * @return True if plugin is an override plugin, false otherwise. @@ -112,6 +118,13 @@ public: */ virtual bool IsValidAsLightPlugin() const = 0; + /** + * Check if the plugin is or would be valid as a medium plugin. + * @return True if the plugin is a valid medium plugin or would be a valid + * medium plugin, false otherwise. + */ + virtual bool IsValidAsMediumPlugin() const = 0; + /** * Check if the plugin is or would be valid as an override plugin. * @return True if the plugin is a valid override plugin or would be a valid diff --git a/src/api/plugin.cpp b/src/api/plugin.cpp index 40be787c..871c65d6 100644 --- a/src/api/plugin.cpp +++ b/src/api/plugin.cpp @@ -307,6 +307,14 @@ bool Plugin::IsLightPlugin() const { return isLightPlugin; } +bool Plugin::IsMediumPlugin() const { + bool isMediumPlugin = false; + const auto ret = esp_plugin_is_medium_plugin(esPlugin.get(), &isMediumPlugin); + HandleEspluginError("check if \"" + name_ + "\" is a medium plugin", ret); + + return isMediumPlugin; +} + bool Plugin::IsOverridePlugin() const { bool isOverridePlugin = false; const auto ret = @@ -326,6 +334,16 @@ bool Plugin::IsValidAsLightPlugin() const { return isValid; } +bool Plugin::IsValidAsMediumPlugin() const { + bool isValid = false; + const auto ret = + esp_plugin_is_valid_as_medium_plugin(esPlugin.get(), &isValid); + HandleEspluginError("check if \"" + name_ + "\" is valid as a medium plugin", + ret); + + return isValid; +} + bool Plugin::IsValidAsOverridePlugin() const { bool isValid = false; const auto ret = diff --git a/src/api/plugin.h b/src/api/plugin.h index 1295049e..fce6b107 100644 --- a/src/api/plugin.h +++ b/src/api/plugin.h @@ -72,9 +72,11 @@ public: bool IsMaster() const override; bool IsLightPlugin() const override; + bool IsMediumPlugin() const override; bool IsOverridePlugin() const override; bool IsValidAsLightPlugin() const override; + bool IsValidAsMediumPlugin() const override; bool IsValidAsOverridePlugin() const override; bool IsEmpty() const override; bool LoadsArchive() const override; diff --git a/src/tests/api/internals/plugin_test.h b/src/tests/api/internals/plugin_test.h index 2b2aeffe..112a3d58 100644 --- a/src/tests/api/internals/plugin_test.h +++ b/src/tests/api/internals/plugin_test.h @@ -197,8 +197,10 @@ public: bool IsMaster() const override { return false; } bool IsLightPlugin() const override { return false; } + bool IsMediumPlugin() const override { return false; } bool IsOverridePlugin() const override { return false; } bool IsValidAsLightPlugin() const override { return false; } + bool IsValidAsMediumPlugin() const override { return false; } bool IsValidAsOverridePlugin() const override { return false; } bool IsEmpty() const override { return false; } bool LoadsArchive() const override { return false; } @@ -358,6 +360,23 @@ TEST_P( plugin3.IsLightPlugin()); } +TEST_P( + PluginTest, + isMediumPluginShouldBeTrueForAMediumFlaggedPluginForStarfield) { + if (GetParam() != GameType::starfield) { + auto bytes = ReadFile(dataPath / blankEsm); + bytes[9] = 0x4; + WriteFile(dataPath / blankEsm, bytes); + } + + const auto pluginName = + GetParam() == GameType::starfield ? blankMediumEsm : blankEsm; + Plugin plugin(game_.GetType(), game_.GetCache(), game_.DataPath() / pluginName, + true); + + EXPECT_EQ(GetParam() == GameType::starfield, plugin.IsMediumPlugin()); +} + TEST_P(PluginTest, isOverridePluginShouldOnlyBeTrueForAStarfieldOverridePlugin) { auto bytes = ReadFile(dataPath / blankMasterDependentEsp); @@ -545,6 +564,20 @@ TEST_P( } } +TEST_P( + PluginTest, + isValidAsMediumPluginShouldReturnTrueOnlyForAStarfieldPluginWithNewFormIdsBetween0And0xFFFFInclusive) { + bool valid = + Plugin( + game_.GetType(), game_.GetCache(), dataPath / blankEsm, true) + .IsValidAsMediumPlugin(); + if (GetParam() == GameType::starfield) { + EXPECT_TRUE(valid); + } else { + EXPECT_FALSE(valid); + } +} + TEST_P( PluginTest, IsValidAsOverridePluginShouldOnlyReturnTrueForAStarfieldPluginWithNoNewRecords) { diff --git a/src/tests/api/internals/sorting/plugin_graph_test.h b/src/tests/api/internals/sorting/plugin_graph_test.h index 16d38091..97a565ad 100644 --- a/src/tests/api/internals/sorting/plugin_graph_test.h +++ b/src/tests/api/internals/sorting/plugin_graph_test.h @@ -60,10 +60,14 @@ public: bool IsLightPlugin() const override { return false; } + bool IsMediumPlugin() const override { return false; } + bool IsOverridePlugin() const override { return false; } bool IsValidAsLightPlugin() const override { return false; } + bool IsValidAsMediumPlugin() const override { return false; } + bool IsValidAsOverridePlugin() const override { return false; } bool IsEmpty() const override { return false; }