From c147841543a19c6ca8a80e72fe8a98b4fe33d6d4 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sun, 16 Sep 2018 20:22:14 +0100 Subject: [PATCH] Add PluginInterface::GetHeaderVersion() --- include/loot/plugin_interface.h | 8 ++++++++ src/api/plugin.cpp | 11 +++++++++++ src/api/plugin.h | 1 + src/tests/api/internals/plugin_test.h | 13 +++++++++++++ 4 files changed, 33 insertions(+) diff --git a/include/loot/plugin_interface.h b/include/loot/plugin_interface.h index 89041e63..f8f58a92 100644 --- a/include/loot/plugin_interface.h +++ b/include/loot/plugin_interface.h @@ -45,6 +45,14 @@ public: */ virtual std::string GetName() const = 0; + /** + * Get the value of the version field in the HEDR subrecord of the plugin's + * TES4 record. + * @return The value of the version field, or NaN if the field could not be + * found. + */ + virtual float GetHeaderVersion() const = 0; + /** * Get the plugin's version number from its description field. * diff --git a/src/api/plugin.cpp b/src/api/plugin.cpp index 692e1600..83fabd20 100644 --- a/src/api/plugin.cpp +++ b/src/api/plugin.cpp @@ -131,6 +131,17 @@ Plugin::Plugin(const GameType gameType, std::string Plugin::GetName() const { return name_; } +float Plugin::GetHeaderVersion() const { + float version; + auto ret = esp_plugin_header_version(esPlugin.get(), &version); + if (ret != ESP_OK) { + throw FileAccessError(name_ + + " : esplugin error code: " + std::to_string(ret)); + } + + return version; +} + std::optional Plugin::GetVersion() const { std::string version = Version(GetDescription()).AsString(); if (version.empty()) { diff --git a/src/api/plugin.h b/src/api/plugin.h index 1be0317a..19e9defc 100644 --- a/src/api/plugin.h +++ b/src/api/plugin.h @@ -50,6 +50,7 @@ public: const bool headerOnly); std::string GetName() const; + float GetHeaderVersion() const; std::optional GetVersion() const; std::vector GetMasters() const; std::set GetBashTags() const; diff --git a/src/tests/api/internals/plugin_test.h b/src/tests/api/internals/plugin_test.h index e02cf1f7..f89a4b3a 100644 --- a/src/tests/api/internals/plugin_test.h +++ b/src/tests/api/internals/plugin_test.h @@ -125,6 +125,7 @@ private: class OtherPluginType : public PluginInterface { public: std::string GetName() const { return ""; } + float GetHeaderVersion() const { return 0.0f; } std::optional GetVersion() const { return std::nullopt; } std::vector GetMasters() const { return std::vector(); @@ -173,6 +174,12 @@ TEST_P(PluginTest, loadingHeaderOnlyShouldReadHeaderData) { EXPECT_TRUE(plugin.IsMaster()); EXPECT_FALSE(plugin.IsEmpty()); EXPECT_EQ("5.0", plugin.GetVersion()); + + if (GetParam() == GameType::tes4) { + EXPECT_FLOAT_EQ(0.8f, plugin.GetHeaderVersion()); + } else { + EXPECT_FLOAT_EQ(0.94f, plugin.GetHeaderVersion()); + } } TEST_P(PluginTest, loadingHeaderOnlyShouldNotReadFieldsOrCalculateCrc) { @@ -197,6 +204,12 @@ TEST_P(PluginTest, loadingWholePluginShouldReadHeaderData) { EXPECT_TRUE(plugin.IsMaster()); EXPECT_FALSE(plugin.IsEmpty()); EXPECT_EQ("5.0", plugin.GetVersion()); + + if (GetParam() == GameType::tes4) { + EXPECT_FLOAT_EQ(0.8f, plugin.GetHeaderVersion()); + } else { + EXPECT_FLOAT_EQ(0.94f, plugin.GetHeaderVersion()); + } } TEST_P(PluginTest, loadingWholePluginShouldReadFields) {