From ac366ac5e9162c13183ff88368d2197ed06361c8 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Thu, 8 Aug 2024 20:42:15 +0100 Subject: [PATCH] Add PluginInterface::IsBlueprintPlugin() --- include/loot/plugin_interface.h | 6 ++++++ src/api/plugin.cpp | 9 +++++++++ src/api/plugin.h | 1 + src/tests/api/internals/plugin_test.h | 17 +++++++++++++++++ .../api/internals/sorting/plugin_graph_test.h | 2 ++ 5 files changed, 35 insertions(+) diff --git a/include/loot/plugin_interface.h b/include/loot/plugin_interface.h index c26c5f1f..9f64ca01 100644 --- a/include/loot/plugin_interface.h +++ b/include/loot/plugin_interface.h @@ -111,6 +111,12 @@ class PluginInterface { */ virtual bool IsUpdatePlugin() const = 0; + /** + * Check if the plugin is a blueprint plugin. + * @return True if plugin is a blueprint plugin, false otherwise. + */ + virtual bool IsBlueprintPlugin() const = 0; + /** * Check if the plugin is or would be valid as a light plugin. * @return True if the plugin is a valid light plugin or would be a valid diff --git a/src/api/plugin.cpp b/src/api/plugin.cpp index 028884ef..43e68620 100644 --- a/src/api/plugin.cpp +++ b/src/api/plugin.cpp @@ -324,6 +324,15 @@ bool Plugin::IsUpdatePlugin() const { return isUpdatePlugin; } +bool Plugin::IsBlueprintPlugin() const { + bool isBlueprintPlugin = false; + const auto ret = + esp_plugin_is_blueprint_plugin(esPlugin.get(), &isBlueprintPlugin); + HandleEspluginError("check if \"" + name_ + "\" is a blueprint plugin", ret); + + return isBlueprintPlugin; +} + bool Plugin::IsValidAsLightPlugin() const { bool isValid = false; const auto ret = diff --git a/src/api/plugin.h b/src/api/plugin.h index 1184ebb8..d53f31c8 100644 --- a/src/api/plugin.h +++ b/src/api/plugin.h @@ -71,6 +71,7 @@ class Plugin final : public PluginSortingInterface { bool IsLightPlugin() const override; bool IsMediumPlugin() const override; bool IsUpdatePlugin() const override; + bool IsBlueprintPlugin() const override; bool IsValidAsLightPlugin() const override; bool IsValidAsMediumPlugin() const override; diff --git a/src/tests/api/internals/plugin_test.h b/src/tests/api/internals/plugin_test.h index a42f3581..e7e70109 100644 --- a/src/tests/api/internals/plugin_test.h +++ b/src/tests/api/internals/plugin_test.h @@ -199,6 +199,7 @@ class OtherPluginType final : public PluginSortingInterface { bool IsLightPlugin() const override { return false; } bool IsMediumPlugin() const override { return false; } bool IsUpdatePlugin() const override { return false; } + bool IsBlueprintPlugin() const override { return false; } bool IsValidAsLightPlugin() const override { return false; } bool IsValidAsMediumPlugin() const override { return false; } bool IsValidAsUpdatePlugin() const override { return false; } @@ -389,6 +390,22 @@ TEST_P(PluginTest, EXPECT_EQ(GetParam() == GameType::starfield, plugin2.IsUpdatePlugin()); } +TEST_P(PluginTest, isBlueprintPluginShouldOnlyBeTrueForAStarfieldBlueprintPlugin) { + auto bytes = ReadFile(dataPath / blankMasterDependentEsp); + bytes[9] = 0x8; + WriteFile(dataPath / blankMasterDependentEsp, bytes); + + Plugin plugin1( + game_.GetType(), game_.GetCache(), game_.DataPath() / blankEsp, true); + Plugin plugin2(game_.GetType(), + game_.GetCache(), + game_.DataPath() / blankMasterDependentEsp, + true); + + EXPECT_FALSE(plugin1.IsBlueprintPlugin()); + EXPECT_EQ(GetParam() == GameType::starfield, plugin2.IsBlueprintPlugin()); +} + TEST_P(PluginTest, loadingAPluginWithMastersShouldReadThemCorrectly) { Plugin plugin(game_.GetType(), game_.GetCache(), diff --git a/src/tests/api/internals/sorting/plugin_graph_test.h b/src/tests/api/internals/sorting/plugin_graph_test.h index d546b193..c4b7339e 100644 --- a/src/tests/api/internals/sorting/plugin_graph_test.h +++ b/src/tests/api/internals/sorting/plugin_graph_test.h @@ -64,6 +64,8 @@ class TestPlugin : public PluginSortingInterface { bool IsUpdatePlugin() const override { return false; } + bool IsBlueprintPlugin() const override { return false; } + bool IsValidAsLightPlugin() const override { return false; } bool IsValidAsMediumPlugin() const override { return false; }