Skip to content
Merged
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 4ea14b652a8b52e8bda4efc7ab5e4a030d60407c
GIT_TAG 1.0.0
)
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_VERSION_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
32 changes: 17 additions & 15 deletions src/dll/Systems/PluginSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
#include "PluginBase.hpp"
#include "Utils.hpp"
#include "Version.hpp"
#include "v0/Plugin.hpp"
#include "v1/Plugin.hpp"

#include <RED4ext/Api/EMainReason.hpp>
#include <RED4ext/Api/Runtime.hpp>
#include <RED4ext/Api/Version.hpp>
#include <RED4ext/Api/v0/FileVer.hpp>
#include <RED4ext/Api/v0/SemVer.hpp>
#include <RED4ext/Api/ApiVersion.hpp>
#include <RED4ext/Api/v1/EMainReason.hpp>
#include <RED4ext/Api/v1/FileVer.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>
Expand All @@ -28,10 +29,10 @@
#include <utility>
#include <vector>

#define MINIMUM_API_VERSION RED4EXT_API_VERSION_0
#define LATEST_API_VERSION RED4EXT_API_VERSION_LATEST
#define MINIMUM_API_VERSION RED4EXT_API_VERSION_1_COMPAT_0
#define MAXIMUM_API_VERSION RED4EXT_API_VERSION_1

#define MINIMUM_SDK_VERSION RED4EXT_SDK_0_5_0
#define MINIMUM_SDK_VERSION RED4EXT_V1_SDK_VERSION_1_0_0_COMPAT_0_5_0

#define LOG_FS_ERROR(text, ec) \
auto val = ec.value(); \
Expand Down Expand Up @@ -267,7 +268,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_VERSION_INDEPENDENT)
{
// Check if the plugins is compiled for a supported version.
bool isSupported = false;
Expand Down Expand Up @@ -307,7 +308,7 @@ void PluginSystem::Load(const std::filesystem::path& aPath, bool aUseAlteredSear
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 @@ -321,7 +322,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 @@ -372,17 +373,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
23 changes: 0 additions & 23 deletions src/dll/v0/Funcs.hpp

This file was deleted.

45 changes: 0 additions & 45 deletions src/dll/v0/Logger.hpp

This file was deleted.

Loading