diff --git a/src/red4ext.dll/App.cpp b/src/red4ext.dll/App.cpp index 4c632df8..d153a742 100644 --- a/src/red4ext.dll/App.cpp +++ b/src/red4ext.dll/App.cpp @@ -72,19 +72,25 @@ App::App() spdlog::debug("Base address is {}", reinterpret_cast(GetModuleHandle(nullptr))); const auto image = Image::Get(); - const auto& ver = image->GetVersion(); - spdlog::info("Game version is {}.{}{}", ver.major, ver.minor, ver.patch); + + const auto& productVer = image->GetProductVersion(); + spdlog::info("Game version is {}.{}{}", productVer.major, productVer.minor, productVer.patch); + + const auto& fileVer = image->GetFileVersion(); + spdlog::info("File version {}.{}.{}.{}", fileVer.major, fileVer.minor, fileVer.build, fileVer.revision); if (!image->IsSupported()) { - spdlog::error("This game version ({}.{}{}) is not supported.", ver.major, ver.minor, ver.patch); + spdlog::error("This game version ({}.{}{}) is not supported.", productVer.major, productVer.minor, + productVer.patch); const auto supportedVer = image->GetSupportedVersion(); fmt::memory_buffer out; - fmt::format_to(std::back_inserter(out), "The current version of the mod supports only version {}.{}{}, ", - supportedVer.major, supportedVer.minor, supportedVer.patch); + fmt::format_to(std::back_inserter(out), + "The current version of RED4ext supports only file version {}.{}.{}.{}, ", supportedVer.major, + supportedVer.minor, supportedVer.build, supportedVer.revision); - if (ver < supportedVer) + if (fileVer < supportedVer) { fmt::format_to(std::back_inserter(out), "try downgrading the mod or updating the game."); } diff --git a/src/red4ext.dll/Image.cpp b/src/red4ext.dll/Image.cpp index f98f85b5..8f03484f 100644 --- a/src/red4ext.dll/Image.cpp +++ b/src/red4ext.dll/Image.cpp @@ -4,7 +4,8 @@ Image::Image() : m_isCyberpunk(false) - , m_version(RED4EXT_V0_SEMVER(0, 0, 0)) + , m_fileVersion(RED4EXT_V0_FILEVER(0, 0, 0, 0)) + , m_productVersion(RED4EXT_V0_SEMVER(0, 0, 0)) { std::wstring fileName; auto hr = wil::GetModuleFileNameW(nullptr, fileName); @@ -21,7 +22,7 @@ Image::Image() { SHOW_LAST_ERROR_MESSAGE_FILE_LINE(L"Could not retrieve version info size.\n\nFile name: {}", fileName); } - + // Else, fail silently, executables might not have the version information. return; } @@ -73,7 +74,7 @@ Image::Image() if (m_isCyberpunk) { - VS_FIXEDFILEINFO* fileInfo; + VS_FIXEDFILEINFO* fileInfo = nullptr; UINT fileInfoBytes; if (!VerQueryValue(data.get(), L"\\", reinterpret_cast(&fileInfo), &fileInfoBytes)) @@ -91,11 +92,22 @@ Image::Image() return; } - uint8_t major = (fileInfo->dwProductVersionMS >> 16) & 0xFF; - uint16_t minor = fileInfo->dwProductVersionMS & 0xFFFF; - uint32_t patch = (fileInfo->dwProductVersionLS >> 16) & 0xFFFF; + { + uint16_t major = (fileInfo->dwFileVersionMS >> 16) & 0xFF; + uint16_t minor = fileInfo->dwFileVersionMS & 0xFFFF; + uint16_t build = (fileInfo->dwFileVersionLS >> 16) & 0xFFFF; + uint16_t revision = fileInfo->dwFileVersionLS & 0xFFFF; + + m_fileVersion = RED4EXT_FILEVER(major, minor, build, revision); + } + + { + uint8_t major = (fileInfo->dwProductVersionMS >> 16) & 0xFF; + uint16_t minor = fileInfo->dwProductVersionMS & 0xFFFF; + uint32_t patch = (fileInfo->dwProductVersionLS >> 16) & 0xFFFF; - m_version = RED4EXT_SEMVER(major, minor, patch); + m_productVersion = RED4EXT_SEMVER(major, minor, patch); + } } } @@ -112,15 +124,20 @@ bool Image::IsCyberpunk() const bool Image::IsSupported() const { - return m_version == GetSupportedVersion(); + return m_fileVersion == GetSupportedVersion(); +} + +const RED4ext::FileVer& Image::GetFileVersion() const +{ + return m_fileVersion; } -const RED4ext::VersionInfo& Image::GetVersion() const +const RED4ext::SemVer& Image::GetProductVersion() const { - return m_version; + return m_productVersion; } -const RED4ext::VersionInfo Image::GetSupportedVersion() const +const RED4ext::FileVer Image::GetSupportedVersion() const { return RED4EXT_RUNTIME_LATEST; } diff --git a/src/red4ext.dll/Image.hpp b/src/red4ext.dll/Image.hpp index a02231b0..e39215cd 100644 --- a/src/red4ext.dll/Image.hpp +++ b/src/red4ext.dll/Image.hpp @@ -6,15 +6,17 @@ class Image static Image* Get(); bool IsCyberpunk() const; - bool IsSupported() const; - const RED4ext::VersionInfo& GetVersion() const; - const RED4ext::VersionInfo GetSupportedVersion() const; + + const RED4ext::FileVer& GetFileVersion() const; + const RED4ext::SemVer& GetProductVersion() const; + const RED4ext::FileVer GetSupportedVersion() const; private: Image(); ~Image() = default; bool m_isCyberpunk; - RED4ext::VersionInfo m_version; + RED4ext::FileVer m_fileVersion; + RED4ext::SemVer m_productVersion; }; diff --git a/src/red4ext.dll/PluginBase.hpp b/src/red4ext.dll/PluginBase.hpp index 6dc98763..08f0e7b5 100644 --- a/src/red4ext.dll/PluginBase.hpp +++ b/src/red4ext.dll/PluginBase.hpp @@ -12,9 +12,9 @@ class PluginBase virtual const std::wstring_view GetName() const = 0; virtual const std::wstring_view GetAuthor() const = 0; - virtual const RED4ext::VersionInfo& GetVersion() const = 0; - virtual const RED4ext::VersionInfo& GetRuntimeVersion() const = 0; - virtual const RED4ext::VersionInfo& GetSdkVersion() const = 0; + virtual const RED4ext::SemVer& GetVersion() const = 0; + virtual const RED4ext::FileVer& GetRuntimeVersion() const = 0; + virtual const RED4ext::SemVer& GetSdkVersion() const = 0; const std::filesystem::path& GetPath() const; HMODULE GetModule() const; diff --git a/src/red4ext.dll/Systems/PluginSystem.cpp b/src/red4ext.dll/Systems/PluginSystem.cpp index 8e5047db..d28e56e2 100644 --- a/src/red4ext.dll/Systems/PluginSystem.cpp +++ b/src/red4ext.dll/Systems/PluginSystem.cpp @@ -8,7 +8,7 @@ #define MINIMUM_API_VERSION RED4EXT_API_VERSION_0 #define LATEST_API_VERSION RED4EXT_API_VERSION_LATEST -#define MINIMUM_SDK_VERSION RED4EXT_SDK_0_2_0 +#define MINIMUM_SDK_VERSION RED4EXT_SDK_0_3_0 #define LATEST_SDK_VERSION RED4EXT_SDK_LATEST #define LOG_FS_ERROR(text, ec) \ @@ -208,15 +208,16 @@ void PluginSystem::Load(const std::filesystem::path& aPath, bool aSearchLoadDir) const auto& pluginVersion = plugin->GetVersion(); const auto image = Image::Get(); - const auto& runtime = image->GetVersion(); + const auto& fileVer = image->GetFileVersion(); + const auto& productVer = image->GetProductVersion(); const auto& requestedRuntime = plugin->GetRuntimeVersion(); - if (requestedRuntime != RED4EXT_RUNTIME_INDEPENDENT && requestedRuntime != runtime) + if (requestedRuntime != RED4EXT_RUNTIME_INDEPENDENT && requestedRuntime != fileVer) { - spdlog::warn(L"{} (version: {}) is not incompatible with the current game's version ({}.{}{}). This version of " - L"the plugin supports only version {}.{}{}", - pluginName, std::to_wstring(pluginVersion), runtime.major, runtime.minor, runtime.patch, - requestedRuntime.major, requestedRuntime.minor, requestedRuntime.patch); + spdlog::warn(L"{} (version: {}) is not incompatible with the current game's version. This version of the " + L"plugin supports only runtime version {}.{}.{}.{}", + pluginName, std::to_wstring(pluginVersion), requestedRuntime.major, requestedRuntime.minor, + requestedRuntime.build, requestedRuntime.revision); return; } diff --git a/src/red4ext.dll/v0/Plugin.cpp b/src/red4ext.dll/v0/Plugin.cpp index 4b797275..f4344ff7 100644 --- a/src/red4ext.dll/v0/Plugin.cpp +++ b/src/red4ext.dll/v0/Plugin.cpp @@ -8,7 +8,7 @@ v0::Plugin::Plugin(const std::filesystem::path& aPath, wil::unique_hmodule aModu : PluginBase(aPath, std::move(aModule)) , m_info{} , m_sdk{} - , m_runtime(Image::Get()->GetVersion()) + , m_runtime(Image::Get()->GetProductVersion()) , m_logger{} , m_hooking{} , m_gameStates{} @@ -71,17 +71,17 @@ const std::wstring_view v0::Plugin::GetAuthor() const return m_info.author; } -const RED4ext::VersionInfo& v0::Plugin::GetVersion() const +const RED4ext::SemVer& v0::Plugin::GetVersion() const { return m_info.version; } -const RED4ext::VersionInfo& v0::Plugin::GetRuntimeVersion() const +const RED4ext::FileVer& v0::Plugin::GetRuntimeVersion() const { return m_info.runtime; } -const RED4ext::VersionInfo& v0::Plugin::GetSdkVersion() const +const RED4ext::SemVer& v0::Plugin::GetSdkVersion() const { return m_info.sdk; } diff --git a/src/red4ext.dll/v0/Plugin.hpp b/src/red4ext.dll/v0/Plugin.hpp index 7574932f..0a725eea 100644 --- a/src/red4ext.dll/v0/Plugin.hpp +++ b/src/red4ext.dll/v0/Plugin.hpp @@ -15,15 +15,15 @@ class Plugin : public PluginBase virtual const std::wstring_view GetName() const final; virtual const std::wstring_view GetAuthor() const final; - virtual const RED4ext::VersionInfo& GetVersion() const final; - virtual const RED4ext::VersionInfo& GetRuntimeVersion() const final; - virtual const RED4ext::VersionInfo& GetSdkVersion() const final; + virtual const RED4ext::SemVer& GetVersion() const final; + virtual const RED4ext::FileVer& GetRuntimeVersion() const final; + virtual const RED4ext::SemVer& GetSdkVersion() const final; private: RED4ext::v0::PluginInfo m_info; RED4ext::v0::Sdk m_sdk; - RED4ext::v0::VersionInfo m_runtime; + RED4ext::v0::SemVer m_runtime; RED4ext::v0::Logger m_logger; RED4ext::v0::Hooking m_hooking; RED4ext::v0::GameStates m_gameStates;