Skip to content

Commit c52c8d8

Browse files
authored
Add support for V1 API (#129)
1 parent af5a285 commit c52c8d8

18 files changed

Lines changed: 367 additions & 277 deletions

cmake/deps/RED4extSdk.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ option(RED4EXT_USE_PCH "" ON)
44
FetchContent_Declare(
55
RED4ext.SDK
66
GIT_REPOSITORY https://github.com/wopss/RED4ext.SDK.git
7-
GIT_TAG 4ea14b652a8b52e8bda4efc7ab5e4a030d60407c
7+
GIT_TAG 1.0.0
88
)
99
FetchContent_MakeAvailable(RED4ext.SDK)
1010

src/dll/App.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ App::App()
8989
spdlog::info("Product version: {}.{}{}", productVer.major, productVer.minor, productVer.patch);
9090
spdlog::info("File version: {}.{}.{}.{}", fileVer.major, fileVer.minor, fileVer.build, fileVer.revision);
9191

92-
auto minimumVersion = RED4EXT_RUNTIME_2_31;
93-
if (fileVer < RED4EXT_RUNTIME_2_31)
92+
const auto minimumVersion = RED4EXT_V1_RUNTIME_VERSION_2_31;
93+
if (fileVer < minimumVersion)
9494
{
9595
spdlog::error(L"To use this version of RED4ext, ensure your game is updated to patch 2.31 or newer");
9696
return;

src/dll/Image.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
#include "Image.hpp"
22
#include "Utils.hpp"
33

4+
#include <RED4ext/Api/v1/FileVer.hpp>
5+
#include <RED4ext/Api/v1/SemVer.hpp>
6+
#include <fmt/xchar.h>
7+
#include <wil/win32_helpers.h>
8+
9+
#include <Windows.h>
10+
11+
#include <cstdint>
12+
#include <memory>
13+
#include <new>
14+
#include <string>
15+
#include <string_view>
16+
#include <vector>
17+
418
Image::Image()
519
: m_isCyberpunk(false)
6-
, m_fileVersion(RED4EXT_V0_FILEVER(0, 0, 0, 0))
7-
, m_productVersion(RED4EXT_V0_SEMVER(0, 0, 0))
20+
, m_fileVersion(RED4EXT_V1_FILEVER(0, 0, 0, 0))
21+
, m_productVersion(RED4EXT_V1_SEMVER(0, 0, 0))
822
{
923
std::wstring fileName;
1024
auto hr = wil::GetModuleFileNameW(nullptr, fileName);
@@ -98,15 +112,15 @@ Image::Image()
98112
uint16_t build = (fileInfo->dwFileVersionLS >> 16) & 0xFFFF;
99113
uint16_t revision = fileInfo->dwFileVersionLS & 0xFFFF;
100114

101-
m_fileVersion = RED4EXT_FILEVER(major, minor, build, revision);
115+
m_fileVersion = RED4EXT_V1_FILEVER(major, minor, build, revision);
102116
}
103117

104118
{
105119
uint8_t major = (fileInfo->dwProductVersionMS >> 16) & 0xFF;
106120
uint16_t minor = fileInfo->dwProductVersionMS & 0xFFFF;
107121
uint32_t patch = (fileInfo->dwProductVersionLS >> 16) & 0xFFFF;
108122

109-
m_productVersion = RED4EXT_SEMVER(major, minor, patch);
123+
m_productVersion = RED4EXT_V1_SEMVER(major, minor, patch);
110124
}
111125
}
112126
}
@@ -136,17 +150,17 @@ bool Image::IsSupported() const
136150
return false;
137151
}
138152

139-
const RED4ext::FileVer& Image::GetFileVersion() const
153+
const RED4ext::v1::FileVer& Image::GetFileVersion() const
140154
{
141155
return m_fileVersion;
142156
}
143157

144-
const RED4ext::SemVer& Image::GetProductVersion() const
158+
const RED4ext::v1::SemVer& Image::GetProductVersion() const
145159
{
146160
return m_productVersion;
147161
}
148162

149-
const std::vector<RED4ext::FileVer> Image::GetSupportedVersions() const
163+
const std::vector<RED4ext::v1::FileVer> Image::GetSupportedVersions() const
150164
{
151165
return {m_fileVersion};
152166
}

src/dll/Image.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#pragma once
22

3+
#include <RED4ext/Api/v1/FileVer.hpp>
4+
#include <RED4ext/Api/v1/SemVer.hpp>
5+
6+
#include <vector>
7+
38
class Image
49
{
510
public:
@@ -8,15 +13,15 @@ class Image
813
bool IsCyberpunk() const;
914
bool IsSupported() const;
1015

11-
const RED4ext::FileVer& GetFileVersion() const;
12-
const RED4ext::SemVer& GetProductVersion() const;
13-
const std::vector<RED4ext::FileVer> GetSupportedVersions() const;
16+
const RED4ext::v1::FileVer& GetFileVersion() const;
17+
const RED4ext::v1::SemVer& GetProductVersion() const;
18+
const std::vector<RED4ext::v1::FileVer> GetSupportedVersions() const;
1419

1520
private:
1621
Image();
1722
~Image() = default;
1823

1924
bool m_isCyberpunk;
20-
RED4ext::FileVer m_fileVersion;
21-
RED4ext::SemVer m_productVersion;
25+
RED4ext::v1::FileVer m_fileVersion;
26+
RED4ext::v1::SemVer m_productVersion;
2227
};

src/dll/PluginBase.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
#include "stdafx.hpp"
21
#include "PluginBase.hpp"
32
#include "Utils.hpp"
43

4+
#include <RED4ext/Api/v1/EMainReason.hpp>
5+
#include <RED4ext/Api/v1/PluginHandle.hpp>
6+
#include <spdlog/spdlog.h>
7+
#include <wil/resource.h>
8+
9+
#include <Windows.h>
10+
11+
#include <exception>
12+
#include <filesystem>
13+
#include <utility>
14+
515
PluginBase::PluginBase(const std::filesystem::path& aPath, wil::unique_hmodule aModule)
616
: m_path(aPath)
717
, m_module(std::move(aModule))
@@ -71,15 +81,15 @@ bool PluginBase::Query()
7181
return true;
7282
}
7383

74-
bool PluginBase::Main(RED4ext::EMainReason aReason)
84+
bool PluginBase::Main(RED4ext::v1::EMainReason aReason)
7585
{
7686
const auto module = GetModule();
7787
const auto name = GetName();
78-
const auto reasonStr = aReason == RED4ext::EMainReason::Load ? L"Load" : L"Unload";
88+
const auto reasonStr = aReason == RED4ext::v1::EMainReason::Load ? L"Load" : L"Unload";
7989

8090
spdlog::trace(L"Calling 'Main' function exported by '{}' with reason '{}'...", name, reasonStr);
8191

82-
using Main_t = bool (*)(RED4ext::PluginHandle, RED4ext::EMainReason, const void*);
92+
using Main_t = bool (*)(RED4ext::v1::PluginHandle, RED4ext::v1::EMainReason, const void*);
8393
auto mainFn = reinterpret_cast<Main_t>(GetProcAddress(module, "Main"));
8494
if (mainFn)
8595
{
@@ -103,8 +113,9 @@ bool PluginBase::Main(RED4ext::EMainReason aReason)
103113
}
104114
catch (...)
105115
{
106-
spdlog::warn(L"An unknown exception occured while calling 'Main' function with reason '{}', exported by '{}'",
107-
reasonStr, name);
116+
spdlog::warn(
117+
L"An unknown exception occured while calling 'Main' function with reason '{}', exported by '{}'",
118+
reasonStr, name);
108119
return false;
109120
}
110121
}

src/dll/PluginBase.hpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
#pragma once
22

3+
#include <RED4ext/Api/v1/EMainReason.hpp>
4+
#include <RED4ext/Api/v1/FileVer.hpp>
5+
#include <RED4ext/Api/v1/SemVer.hpp>
6+
#include <wil/resource.h>
7+
8+
#include <Windows.h>
9+
10+
#include <cstdint>
11+
#include <filesystem>
12+
#include <string_view>
13+
314
class PluginBase
415
{
516
public:
@@ -12,15 +23,15 @@ class PluginBase
1223

1324
virtual const std::wstring_view GetName() const = 0;
1425
virtual const std::wstring_view GetAuthor() const = 0;
15-
virtual const RED4ext::SemVer& GetVersion() const = 0;
16-
virtual const RED4ext::FileVer& GetRuntimeVersion() const = 0;
17-
virtual const RED4ext::SemVer& GetSdkVersion() const = 0;
26+
virtual const RED4ext::v1::SemVer& GetVersion() const = 0;
27+
virtual const RED4ext::v1::FileVer& GetRuntimeVersion() const = 0;
28+
virtual const RED4ext::v1::SemVer& GetSdkVersion() const = 0;
1829

1930
const std::filesystem::path& GetPath() const;
2031
HMODULE GetModule() const;
2132

2233
bool Query();
23-
bool Main(RED4ext::EMainReason aReason);
34+
bool Main(RED4ext::v1::EMainReason aReason);
2435

2536
private:
2637
std::filesystem::path m_path;

src/dll/Systems/PluginSystem.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
#include "PluginBase.hpp"
77
#include "Utils.hpp"
88
#include "Version.hpp"
9-
#include "v0/Plugin.hpp"
9+
#include "v1/Plugin.hpp"
1010

11-
#include <RED4ext/Api/EMainReason.hpp>
12-
#include <RED4ext/Api/Runtime.hpp>
13-
#include <RED4ext/Api/Version.hpp>
14-
#include <RED4ext/Api/v0/FileVer.hpp>
15-
#include <RED4ext/Api/v0/SemVer.hpp>
11+
#include <RED4ext/Api/ApiVersion.hpp>
12+
#include <RED4ext/Api/v1/EMainReason.hpp>
13+
#include <RED4ext/Api/v1/FileVer.hpp>
14+
#include <RED4ext/Api/v1/Runtime.hpp>
15+
#include <RED4ext/Api/v1/SemVer.hpp>
16+
#include <RED4ext/Api/v1/Version.hpp>
1617

1718
#include <fmt/format.h>
1819
#include <spdlog/spdlog.h>
@@ -28,10 +29,10 @@
2829
#include <utility>
2930
#include <vector>
3031

31-
#define MINIMUM_API_VERSION RED4EXT_API_VERSION_0
32-
#define LATEST_API_VERSION RED4EXT_API_VERSION_LATEST
32+
#define MINIMUM_API_VERSION RED4EXT_API_VERSION_1_COMPAT_0
33+
#define MAXIMUM_API_VERSION RED4EXT_API_VERSION_1
3334

34-
#define MINIMUM_SDK_VERSION RED4EXT_SDK_0_5_0
35+
#define MINIMUM_SDK_VERSION RED4EXT_V1_SDK_VERSION_1_0_0_COMPAT_0_5_0
3536

3637
#define LOG_FS_ERROR(text, ec) \
3738
auto val = ec.value(); \
@@ -267,7 +268,7 @@ void PluginSystem::Load(const std::filesystem::path& aPath, bool aUseAlteredSear
267268
const auto image = Image::Get();
268269

269270
const auto& requestedRuntime = plugin->GetRuntimeVersion();
270-
if (requestedRuntime != RED4EXT_RUNTIME_INDEPENDENT)
271+
if (requestedRuntime != RED4EXT_V1_RUNTIME_VERSION_INDEPENDENT)
271272
{
272273
// Check if the plugins is compiled for a supported version.
273274
bool isSupported = false;
@@ -307,7 +308,7 @@ void PluginSystem::Load(const std::filesystem::path& aPath, bool aUseAlteredSear
307308
auto module = plugin->GetModule();
308309
m_plugins.emplace(module, plugin);
309310

310-
if (!plugin->Main(RED4ext::EMainReason::Load))
311+
if (!plugin->Main(RED4ext::v1::EMainReason::Load))
311312
{
312313
spdlog::warn(L"{} did not initialize properly, unloading...", pluginName);
313314
Unload(plugin);
@@ -321,7 +322,7 @@ void PluginSystem::Load(const std::filesystem::path& aPath, bool aUseAlteredSear
321322

322323
PluginSystem::MapIter_t PluginSystem::Unload(std::shared_ptr<PluginBase> aPlugin)
323324
{
324-
aPlugin->Main(RED4ext::EMainReason::Unload);
325+
aPlugin->Main(RED4ext::v1::EMainReason::Unload);
325326

326327
auto module = aPlugin->GetModule();
327328
auto iter = m_plugins.find(module);
@@ -372,17 +373,18 @@ std::shared_ptr<PluginBase> PluginSystem::CreatePlugin(const std::filesystem::pa
372373
return nullptr;
373374
}
374375

375-
if (apiVersion < MINIMUM_API_VERSION || apiVersion > LATEST_API_VERSION)
376+
if (apiVersion < MINIMUM_API_VERSION || apiVersion > MAXIMUM_API_VERSION)
376377
{
377378
spdlog::warn(L"'{}' is using an unsupported API version. API version: {}, path: '{}'", stem, apiVersion, aPath);
378379
return nullptr;
379380
}
380381

381382
switch (apiVersion)
382383
{
383-
case RED4EXT_API_VERSION_0:
384+
case RED4EXT_API_VERSION_1_COMPAT_0:
385+
case RED4EXT_API_VERSION_1:
384386
{
385-
return std::make_shared<v0::Plugin>(aPath, std::move(aModule));
387+
return std::make_shared<v1::Plugin>(aPath, std::move(aModule));
386388
}
387389
}
388390

src/dll/v0/Funcs.hpp

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/dll/v0/Logger.hpp

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)