Skip to content

Commit

Permalink
feat: add incompatibility check for PrivateProfileRedirector < 0.6.2 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
FlayaN authored Nov 12, 2024
1 parent 7d4af8c commit 1df68ad
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
#include "Utils/GameSetting.h"
#include "Utils/Serialize.h"
#include "Utils/UI.h"
#include "Utils/WinApi.h"
1 change: 1 addition & 0 deletions src/Utils/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Util
}
return result;
}

std::string DefinesToString(const std::vector<D3D_SHADER_MACRO>& defines)
{
std::string result;
Expand Down
30 changes: 30 additions & 0 deletions src/Utils/WinApi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "WinApi.h"

namespace Util
{
std::optional<REL::Version> GetDllVersion(const std::wstring& dllPath)
{
DWORD handle = 0;
DWORD size = GetFileVersionInfoSize(dllPath.c_str(), &handle);
if (size == 0) {
return std::nullopt;
}

std::vector<BYTE> buffer(size);
if (!GetFileVersionInfo(dllPath.c_str(), handle, size, buffer.data())) {
return std::nullopt;
}

VS_FIXEDFILEINFO* fileInfo = nullptr;
UINT fileInfoSize = 0;
if (!VerQueryValue(buffer.data(), L"\\", reinterpret_cast<void**>(&fileInfo), &fileInfoSize)) {
return std::nullopt;
}

if (fileInfoSize == sizeof(VS_FIXEDFILEINFO)) {
return REL::Version(HIWORD(fileInfo->dwFileVersionMS), LOWORD(fileInfo->dwFileVersionMS), HIWORD(fileInfo->dwFileVersionLS), LOWORD(fileInfo->dwFileVersionLS));
}

return std::nullopt;
}
} // namespace Util
6 changes: 6 additions & 0 deletions src/Utils/WinApi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

namespace Util
{
std::optional<REL::Version> GetDllVersion(const std::wstring& dllPath);
} // namespace Util
5 changes: 5 additions & 0 deletions src/XSEPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ bool Load()
REL::IDDatabase::get().IsVRAddressLibraryAtLeastVersion("0.158.0", true);
}

auto privateProfileRedirectorVersion = Util::GetDllVersion(L"Data/SKSE/Plugins/PrivateProfileRedirector.dll");
if (privateProfileRedirectorVersion.has_value() && privateProfileRedirectorVersion.value().compare(REL::Version(0, 6, 2)) == std::strong_ordering::less) {
stl::report_and_fail("Old version of PrivateProfileRedirector detected, 0.6.2+ required if using it."sv);
}

auto messaging = SKSE::GetMessagingInterface();
messaging->RegisterListener("SKSE", MessageHandler);

Expand Down

0 comments on commit 1df68ad

Please sign in to comment.