From 715d1dce7501af8b38223eab556cd2aaeeb274dc Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Thu, 22 Aug 2024 20:43:08 +0100 Subject: [PATCH] Add PluginSortingInterface::IsBlueprintPlugin() Adding it to the sorting interface because it'll be needed by the sorting logic, but I'm not yet sure if it'll be useful as part of PluginInterface (and adding it there would break ABI). --- src/api/plugin.cpp | 9 +++++++++ src/api/plugin.h | 3 +++ src/tests/api/internals/plugin_test.h | 16 ++++++++++++++++ .../api/internals/sorting/plugin_graph_test.h | 2 ++ src/tests/common_game_test_fixture.h | 6 ++++++ 5 files changed, 36 insertions(+) diff --git a/src/api/plugin.cpp b/src/api/plugin.cpp index b4398e65..58fb811c 100644 --- a/src/api/plugin.cpp +++ b/src/api/plugin.cpp @@ -337,6 +337,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..19efd855 100644 --- a/src/api/plugin.h +++ b/src/api/plugin.h @@ -43,6 +43,8 @@ class GameCache; // An interface containing member functions that are used when sorting plugins. class PluginSortingInterface : public PluginInterface { public: + virtual bool IsBlueprintPlugin() const = 0; + virtual size_t GetOverrideRecordCount() const = 0; virtual uint32_t GetRecordAndGroupCount() const = 0; @@ -71,6 +73,7 @@ public: 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 dbf3e649..561503cb 100644 --- a/src/tests/api/internals/plugin_test.h +++ b/src/tests/api/internals/plugin_test.h @@ -182,6 +182,7 @@ public: 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; } @@ -370,6 +371,21 @@ TEST_P(PluginTest, isUpdatePluginShouldOnlyBeTrueForAStarfieldUpdatePlugin) { EXPECT_EQ(GetParam() == GameType::starfield, plugin2.IsUpdatePlugin()); } +TEST_P(PluginTest, + isBlueprintPluginShouldOnlyBeTrueForAStarfieldBlueprintPlugin) { + SetBlueprintFlag(dataPath / blankMasterDependentEsp); + + 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 @@ public: bool IsUpdatePlugin() const override { return false; } + bool IsBlueprintPlugin() const override { return false; } + bool IsValidAsLightPlugin() const override { return false; } bool IsValidAsMediumPlugin() const override { return false; } diff --git a/src/tests/common_game_test_fixture.h b/src/tests/common_game_test_fixture.h index 0bba7efa..c6224872 100644 --- a/src/tests/common_game_test_fixture.h +++ b/src/tests/common_game_test_fixture.h @@ -357,6 +357,12 @@ protected: } } + void SetBlueprintFlag(const std::filesystem::path& path) { + auto bytes = ReadFile(path); + bytes[9] = 0x8; + WriteFile(path, bytes); + } + private: const std::filesystem::path rootTestPath;