Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/deps/RED4extSdk.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ option(RED4EXT_USE_PCH "" ON)
FetchContent_Declare(
RED4ext.SDK
GIT_REPOSITORY https://github.com/wopss/RED4ext.SDK.git
GIT_TAG 5e5d4fba9917a58a9622c72c4c902dfd27f553b8
GIT_TAG cb224205a41cc458e3db41a81d7a6589bc1baa7e
)
FetchContent_MakeAvailable(RED4ext.SDK)

Expand Down
4 changes: 2 additions & 2 deletions src/dll/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ App::App()
spdlog::info("Product version: {}.{}{}", productVer.major, productVer.minor, productVer.patch);
spdlog::info("File version: {}.{}.{}.{}", fileVer.major, fileVer.minor, fileVer.build, fileVer.revision);

auto minimumVersion = RED4EXT_RUNTIME_2_31;
if (fileVer < RED4EXT_RUNTIME_2_31)
const auto minimumVersion = RED4EXT_V1_RUNTIME_2_31;
if (fileVer < minimumVersion)
{
spdlog::error(L"To use this version of RED4ext, ensure your game is updated to patch 2.31 or newer");
return;
Expand Down
28 changes: 21 additions & 7 deletions src/dll/Image.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
#include "Image.hpp"
#include "Utils.hpp"

#include <RED4ext/Api/v1/FileVer.hpp>
#include <RED4ext/Api/v1/SemVer.hpp>
#include <fmt/xchar.h>
#include <wil/win32_helpers.h>

#include <Windows.h>

#include <cstdint>
#include <memory>
#include <new>
#include <string>
#include <string_view>
#include <vector>

Image::Image()
: m_isCyberpunk(false)
, m_fileVersion(RED4EXT_V0_FILEVER(0, 0, 0, 0))
, m_productVersion(RED4EXT_V0_SEMVER(0, 0, 0))
, m_fileVersion(RED4EXT_V1_FILEVER(0, 0, 0, 0))
, m_productVersion(RED4EXT_V1_SEMVER(0, 0, 0))
{
std::wstring fileName;
auto hr = wil::GetModuleFileNameW(nullptr, fileName);
Expand Down Expand Up @@ -98,15 +112,15 @@ Image::Image()
uint16_t build = (fileInfo->dwFileVersionLS >> 16) & 0xFFFF;
uint16_t revision = fileInfo->dwFileVersionLS & 0xFFFF;

m_fileVersion = RED4EXT_FILEVER(major, minor, build, revision);
m_fileVersion = RED4EXT_V1_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_productVersion = RED4EXT_SEMVER(major, minor, patch);
m_productVersion = RED4EXT_V1_SEMVER(major, minor, patch);
}
}
}
Expand Down Expand Up @@ -136,17 +150,17 @@ bool Image::IsSupported() const
return false;
}

const RED4ext::FileVer& Image::GetFileVersion() const
const RED4ext::v1::FileVer& Image::GetFileVersion() const
{
return m_fileVersion;
}

const RED4ext::SemVer& Image::GetProductVersion() const
const RED4ext::v1::SemVer& Image::GetProductVersion() const
{
return m_productVersion;
}

const std::vector<RED4ext::FileVer> Image::GetSupportedVersions() const
const std::vector<RED4ext::v1::FileVer> Image::GetSupportedVersions() const
{
return {m_fileVersion};
}
15 changes: 10 additions & 5 deletions src/dll/Image.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#pragma once

#include <RED4ext/Api/v1/FileVer.hpp>
#include <RED4ext/Api/v1/SemVer.hpp>

#include <vector>

class Image
{
public:
Expand All @@ -8,15 +13,15 @@ class Image
bool IsCyberpunk() const;
bool IsSupported() const;

const RED4ext::FileVer& GetFileVersion() const;
const RED4ext::SemVer& GetProductVersion() const;
const std::vector<RED4ext::FileVer> GetSupportedVersions() const;
const RED4ext::v1::FileVer& GetFileVersion() const;
const RED4ext::v1::SemVer& GetProductVersion() const;
const std::vector<RED4ext::v1::FileVer> GetSupportedVersions() const;

private:
Image();
~Image() = default;

bool m_isCyberpunk;
RED4ext::FileVer m_fileVersion;
RED4ext::SemVer m_productVersion;
RED4ext::v1::FileVer m_fileVersion;
RED4ext::v1::SemVer m_productVersion;
};
23 changes: 17 additions & 6 deletions src/dll/PluginBase.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#include "stdafx.hpp"
#include "PluginBase.hpp"
#include "Utils.hpp"

#include <RED4ext/Api/v1/EMainReason.hpp>
#include <RED4ext/Api/v1/PluginHandle.hpp>
#include <spdlog/spdlog.h>
#include <wil/resource.h>

#include <Windows.h>

#include <exception>
#include <filesystem>
#include <utility>

PluginBase::PluginBase(const std::filesystem::path& aPath, wil::unique_hmodule aModule)
: m_path(aPath)
, m_module(std::move(aModule))
Expand Down Expand Up @@ -71,15 +81,15 @@ bool PluginBase::Query()
return true;
}

bool PluginBase::Main(RED4ext::EMainReason aReason)
bool PluginBase::Main(RED4ext::v1::EMainReason aReason)
{
const auto module = GetModule();
const auto name = GetName();
const auto reasonStr = aReason == RED4ext::EMainReason::Load ? L"Load" : L"Unload";
const auto reasonStr = aReason == RED4ext::v1::EMainReason::Load ? L"Load" : L"Unload";

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

using Main_t = bool (*)(RED4ext::PluginHandle, RED4ext::EMainReason, const void*);
using Main_t = bool (*)(RED4ext::v1::PluginHandle, RED4ext::v1::EMainReason, const void*);
auto mainFn = reinterpret_cast<Main_t>(GetProcAddress(module, "Main"));
if (mainFn)
{
Expand All @@ -103,8 +113,9 @@ bool PluginBase::Main(RED4ext::EMainReason aReason)
}
catch (...)
{
spdlog::warn(L"An unknown exception occured while calling 'Main' function with reason '{}', exported by '{}'",
reasonStr, name);
spdlog::warn(
L"An unknown exception occured while calling 'Main' function with reason '{}', exported by '{}'",
reasonStr, name);
return false;
}
}
Expand Down
19 changes: 15 additions & 4 deletions src/dll/PluginBase.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#pragma once

#include <RED4ext/Api/v1/EMainReason.hpp>
#include <RED4ext/Api/v1/FileVer.hpp>
#include <RED4ext/Api/v1/SemVer.hpp>
#include <wil/resource.h>

#include <Windows.h>

#include <cstdint>
#include <filesystem>
#include <string_view>

class PluginBase
{
public:
Expand All @@ -12,15 +23,15 @@ class PluginBase

virtual const std::wstring_view GetName() const = 0;
virtual const std::wstring_view GetAuthor() const = 0;
virtual const RED4ext::SemVer& GetVersion() const = 0;
virtual const RED4ext::FileVer& GetRuntimeVersion() const = 0;
virtual const RED4ext::SemVer& GetSdkVersion() const = 0;
virtual const RED4ext::v1::SemVer& GetVersion() const = 0;
virtual const RED4ext::v1::FileVer& GetRuntimeVersion() const = 0;
virtual const RED4ext::v1::SemVer& GetSdkVersion() const = 0;

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

bool Query();
bool Main(RED4ext::EMainReason aReason);
bool Main(RED4ext::v1::EMainReason aReason);

private:
std::filesystem::path m_path;
Expand Down
50 changes: 37 additions & 13 deletions src/dll/Systems/PluginSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
#include "PluginSystem.hpp"
#include "Config.hpp"
#include "ESystemType.hpp"
#include "Image.hpp"
#include "Paths.hpp"
#include "PluginBase.hpp"
#include "Utils.hpp"
#include "Version.hpp"
#include "v0/Plugin.hpp"
#include "v1/Plugin.hpp"

#define MINIMUM_API_VERSION RED4EXT_API_VERSION_0
#define LATEST_API_VERSION RED4EXT_API_VERSION_LATEST
#include <RED4ext/Api/ApiVersion.hpp>
#include <RED4ext/Api/v1/EMainReason.hpp>
#include <RED4ext/Api/v1/Runtime.hpp>
#include <RED4ext/Api/v1/SemVer.hpp>
#include <RED4ext/Api/v1/Version.hpp>
#include <fmt/format.h>
#include <spdlog/spdlog.h>
#include <wil/resource.h>

#define MINIMUM_SDK_VERSION RED4EXT_SDK_0_5_0
#define LATEST_SDK_VERSION RED4EXT_SDK_LATEST
#include <Windows.h>

#include <cstdint>
#include <exception>
#include <filesystem>
#include <memory>
#include <system_error>
#include <utility>
#include <vector>

#define MINIMUM_API_VERSION RED4EXT_API_VERSION_1_COMPAT_0
#define MAXIMUM_API_VERSION RED4EXT_API_VERSION_1

#define MINIMUM_SDK_VERSION RED4EXT_V1_SDK_1_0_0_COMPAT_0_5_0
#define MAXIMUM_SDK_VERSION RED4EXT_V1_SDK_CURRENT

#define LOG_FS_ERROR(text, ec) \
auto val = ec.value(); \
Expand Down Expand Up @@ -244,7 +267,7 @@ void PluginSystem::Load(const std::filesystem::path& aPath, bool aUseAlteredSear
const auto image = Image::Get();

const auto& requestedRuntime = plugin->GetRuntimeVersion();
if (requestedRuntime != RED4EXT_RUNTIME_INDEPENDENT)
if (requestedRuntime != RED4EXT_V1_RUNTIME_INDEPENDENT)
{
// Check if the plugins is compiled for a supported version.
bool isSupported = false;
Expand All @@ -271,20 +294,20 @@ void PluginSystem::Load(const std::filesystem::path& aPath, bool aUseAlteredSear
}

const auto& pluginSdk = plugin->GetSdkVersion();
if (pluginSdk < MINIMUM_SDK_VERSION || pluginSdk > LATEST_SDK_VERSION)
if (pluginSdk < MINIMUM_SDK_VERSION || pluginSdk > MAXIMUM_SDK_VERSION)
{
spdlog::warn(L"{} (version: {}) uses RED4ext.SDK v{} which is not supported by RED4ext v{}. If you are the "
L"plugin's author, recompile the plugin with a version of RED4ext.SDK that meets the following "
L"criteria: RED4ext.SDK >= {} && RED4ext.SDK <= {}",
pluginName, std::to_wstring(pluginVersion), std::to_wstring(pluginSdk), Version::Get(),
std::to_wstring(MINIMUM_SDK_VERSION), std::to_wstring(LATEST_SDK_VERSION));
std::to_wstring(MINIMUM_SDK_VERSION), std::to_wstring(MAXIMUM_SDK_VERSION));
return;
}

auto module = plugin->GetModule();
m_plugins.emplace(module, plugin);

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

PluginSystem::MapIter_t PluginSystem::Unload(std::shared_ptr<PluginBase> aPlugin)
{
aPlugin->Main(RED4ext::EMainReason::Unload);
aPlugin->Main(RED4ext::v1::EMainReason::Unload);

auto module = aPlugin->GetModule();
auto iter = m_plugins.find(module);
Expand Down Expand Up @@ -349,17 +372,18 @@ std::shared_ptr<PluginBase> PluginSystem::CreatePlugin(const std::filesystem::pa
return nullptr;
}

if (apiVersion < MINIMUM_API_VERSION || apiVersion > LATEST_API_VERSION)
if (apiVersion < MINIMUM_API_VERSION || apiVersion > MAXIMUM_API_VERSION)
{
spdlog::warn(L"'{}' is using an unsupported API version. API version: {}, path: '{}'", stem, apiVersion, aPath);
return nullptr;
}

switch (apiVersion)
{
case RED4EXT_API_VERSION_0:
case RED4EXT_API_VERSION_1_COMPAT_0:
case RED4EXT_API_VERSION_1:
{
return std::make_shared<v0::Plugin>(aPath, std::move(aModule));
return std::make_shared<v1::Plugin>(aPath, std::move(aModule));
}
}

Expand Down
18 changes: 16 additions & 2 deletions src/dll/Utils.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#pragma once

#include <RED4ext/Api/v1/FileVer.hpp>
#include <RED4ext/GameStates.hpp>
#include <fmt/core.h>
#include <spdlog/logger.h>

#include <Windows.h>

#include <cstdint>
#include <filesystem>
#include <memory>
#include <string>
#include <string_view>
#include <utility>

class Config;
class DevConsole;
class Paths;
Expand Down Expand Up @@ -61,10 +75,10 @@ struct fmt::formatter<std::filesystem::path, Char> : formatter<basic_string_view
};

template<typename Char>
struct fmt::formatter<RED4ext::FileVer, Char> : formatter<basic_string_view<Char>, Char>
struct fmt::formatter<RED4ext::v1::FileVer, Char> : formatter<basic_string_view<Char>, Char>
{
template<typename FormatContext>
auto format(const RED4ext::FileVer& aFileVersion, FormatContext& ctx)
auto format(const RED4ext::v1::FileVer& aFileVersion, FormatContext& ctx)
{
return fmt::format_to(ctx.out(), "{}.{}.{}.{}", aFileVersion.major, aFileVersion.minor, aFileVersion.build,
aFileVersion.revision);
Expand Down
23 changes: 0 additions & 23 deletions src/dll/v0/Funcs.hpp

This file was deleted.

Loading