Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 cfb8421cdcf31470c6f3c1705631ea75d8c1aa7f
)
FetchContent_MakeAvailable(RED4ext.SDK)

Expand Down
19 changes: 17 additions & 2 deletions src/dll/Image.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
#include "Image.hpp"
#include "Utils.hpp"

#include <RED4ext/Api/FileVer.hpp>
#include <RED4ext/Api/Sdk.hpp>
#include <RED4ext/Api/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_FILEVER(0, 0, 0, 0))
, m_productVersion(RED4EXT_SEMVER(0, 0, 0))
{
std::wstring fileName;
auto hr = wil::GetModuleFileNameW(nullptr, fileName);
Expand Down
43 changes: 34 additions & 9 deletions src/dll/Systems/PluginSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
#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/EMainReason.hpp>
#include <RED4ext/Api/Runtime.hpp>
#include <RED4ext/Api/Version.hpp>
#include <RED4ext/Api/v1/SemVer.hpp>
#include <fmt/format.h>
#include <spdlog/spdlog.h>
#include <wil/resource.h>

#include <Windows.h>

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

#define BACKWARDS_COMP_RED4EXT_API_VERSION_0 0

#define MINIMUM_API_VERSION BACKWARDS_COMP_RED4EXT_API_VERSION_0
#define MAXIMUM_API_VERSION RED4EXT_API_VERSION_1

#define MINIMUM_SDK_VERSION RED4EXT_SDK_0_5_0
#define LATEST_SDK_VERSION RED4EXT_SDK_LATEST
#define MAXIMUM_SDK_VERSION RED4EXT_SDK_1_0_0

#define LOG_FS_ERROR(text, ec) \
auto val = ec.value(); \
Expand Down Expand Up @@ -271,13 +295,13 @@ 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;
}

Expand Down Expand Up @@ -349,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 BACKWARDS_COMP_RED4EXT_API_VERSION_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
96 changes: 0 additions & 96 deletions src/dll/v0/Plugin.cpp

This file was deleted.

12 changes: 6 additions & 6 deletions src/dll/v0/Funcs.cpp → src/dll/v1/Funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ std::shared_ptr<PluginBase> GetPluginByHandle(RED4ext::PluginHandle aHandle)
}
} // namespace

bool v0::Hooking::Attach(RED4ext::PluginHandle aHandle, void* aTarget, void* aDetour, void** aOriginal)
bool v1::Hooking::Attach(RED4ext::PluginHandle aHandle, void* aTarget, void* aDetour, void** aOriginal)
{
spdlog::trace("Attach request received from plugin with handle {}", fmt::ptr(aHandle));

Expand All @@ -50,7 +50,7 @@ bool v0::Hooking::Attach(RED4ext::PluginHandle aHandle, void* aTarget, void* aDe
return hookingSystem->Attach(plugin, aTarget, aDetour, aOriginal);
}

bool v0::Hooking::Detach(RED4ext::PluginHandle aHandle, void* aTarget)
bool v1::Hooking::Detach(RED4ext::PluginHandle aHandle, void* aTarget)
{
spdlog::trace("Detach request received from plugin with handle {}", fmt::ptr(aHandle));

Expand All @@ -76,7 +76,7 @@ bool v0::Hooking::Detach(RED4ext::PluginHandle aHandle, void* aTarget)
return hookingSystem->Detach(plugin, aTarget);
}

bool v0::GameStates::Add(RED4ext::PluginHandle aHandle, RED4ext::EGameStateType aType, RED4ext::GameState* aState)
bool v1::GameStates::Add(RED4ext::PluginHandle aHandle, RED4ext::EGameStateType aType, RED4ext::GameState* aState)
{
spdlog::trace("Request to add a game state has been received from plugin with handle {}", fmt::ptr(aHandle));

Expand Down Expand Up @@ -110,7 +110,7 @@ bool v0::GameStates::Add(RED4ext::PluginHandle aHandle, RED4ext::EGameStateType
return false;
}

bool v0::Scripts::Add(RED4ext::PluginHandle aHandle, const wchar_t* aPath)
bool v1::Scripts::Add(RED4ext::PluginHandle aHandle, const wchar_t* aPath)
{
auto app = App::Get();
if (!app)
Expand All @@ -128,7 +128,7 @@ bool v0::Scripts::Add(RED4ext::PluginHandle aHandle, const wchar_t* aPath)
return scriptCompilationSystem->Add(plugin, aPath);
}

bool v0::Scripts::RegisterNeverRefType(const char* aType)
bool v1::Scripts::RegisterNeverRefType(const char* aType)
{
auto app = App::Get();
if (!app)
Expand All @@ -141,7 +141,7 @@ bool v0::Scripts::RegisterNeverRefType(const char* aType)
return true;
}

bool v0::Scripts::RegisterMixedRefType(const char* aType)
bool v1::Scripts::RegisterMixedRefType(const char* aType)
{
auto app = App::Get();
if (!app)
Expand Down
4 changes: 2 additions & 2 deletions src/dll/v0/Funcs.hpp → src/dll/v1/Funcs.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

namespace v0
namespace v1
{
namespace Hooking
{
Expand All @@ -20,4 +20,4 @@ bool RegisterNeverRefType(const char* aType);
bool RegisterMixedRefType(const char* aType);
} // namespace Scripts

} // namespace v0
} // namespace v1
Loading