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
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ include(FetchContent)

include("${RED4EXT_CMAKE_DEPS_DIR}/Detours.cmake")
include("${RED4EXT_CMAKE_DEPS_DIR}/Fmt.cmake")
include("${RED4EXT_CMAKE_DEPS_DIR}/OrderedMap.cmake")
include("${RED4EXT_CMAKE_DEPS_DIR}/RED4extSdk.cmake")
include("${RED4EXT_CMAKE_DEPS_DIR}/Redscript.cmake")
include("${RED4EXT_CMAKE_DEPS_DIR}/Simdjson.cmake")
Expand All @@ -88,6 +87,10 @@ include("${RED4EXT_CMAKE_DEPS_DIR}/Wil.cmake")
# ------------------------------------------------------------------------------
# Toolchain settings for this project only
# ------------------------------------------------------------------------------
add_compile_definitions(
NOMINMAX
)

add_compile_options(
/GS
/sdl
Expand Down
2 changes: 1 addition & 1 deletion cmake/deps/Detours.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FetchContent_Declare(
Detours
GIT_REPOSITORY https://github.com/microsoft/Detours.git
GIT_TAG 4b8c659f549b0ab21cf649377c7a84eb708f5e68
GIT_TAG 9764cebcb1a75940e68fa83d6730ffaf0f669401
)
FetchContent_MakeAvailable(Detours)

Expand Down
8 changes: 2 additions & 6 deletions cmake/deps/Fmt.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
option(FMT_INSTALL "" OFF)

FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 10.1.1
GIT_TAG 12.1.0
GIT_SHALLOW ON
)
FetchContent_MakeAvailable(fmt)
Expand All @@ -15,19 +13,17 @@ set_target_properties(
)

mark_as_advanced(
FMT_CMAKE_DIR
FMT_CUDA_TEST
FMT_DEBUG_POSTFIX
FMT_DOC
FMT_FUZZ
FMT_INC_DIR
FMT_INSTALL
FMT_LIB_DIR
FMT_MODULE
FMT_OS
FMT_PEDANTIC
FMT_PKGCONFIG_DIR
FMT_SYSTEM_HEADERS
FMT_TEST
FMT_UNICODE
FMT_WERROR
)
13 changes: 0 additions & 13 deletions cmake/deps/OrderedMap.cmake

This file was deleted.

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 4ea14b652a8b52e8bda4efc7ab5e4a030d60407c
)
FetchContent_MakeAvailable(RED4ext.SDK)

Expand Down
6 changes: 5 additions & 1 deletion cmake/deps/Simdjson.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
option(SIMDJSON_BASH "" OFF)
set(SIMDJSON_CXX_STANDARD "${CMAKE_CXX_STANDARD}" CACHE STRING "")

FetchContent_Declare(
simdjson
GIT_REPOSITORY https://github.com/simdjson/simdjson.git
GIT_TAG v3.6.4
GIT_TAG v4.3.1
GIT_SHALLOW ON
EXCLUDE_FROM_ALL # The project does not have any INSTALL options.
)
Expand All @@ -16,6 +17,7 @@ set_target_properties(
)

mark_as_advanced(
CMAKE_EXPORT_COMPILE_COMMANDS
SIMDJSON_AVX512_ALLOWED
SIMDJSON_BASH
SIMDJSON_BUILD_STATIC_LIB
Expand All @@ -31,10 +33,12 @@ mark_as_advanced(
SIMDJSON_IMPLEMENTATION
SIMDJSON_LIB_SOVERSION
SIMDJSON_LIB_VERSION
SIMDJSON_MINUS_ZERO_AS_FLOAT
SIMDJSON_SANITIZE
SIMDJSON_SANITIZE_MEMORY
SIMDJSON_SANITIZE_UNDEFINED
SIMDJSON_SKIPUTF8VALIDATION
SIMDJSON_STATIC_REFLECTION
SIMDJSON_STRUCTURAL_INDEXER_STEP
SIMDJSON_VERBOSE_LOGGING
SIMDJSON_VISUAL_STUDIO_BUILD_WITH_DEBUG_INFO_FOR_PROFILING
Expand Down
12 changes: 9 additions & 3 deletions cmake/deps/Spdlog.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
option(SPDLOG_ENABLE_PCH "" ON)
option(SPDLOG_DISABLE_DEFAULT_LOGGER "" ON)
option(SPDLOG_ENABLE_PCH "" ON)
option(SPDLOG_FMT_EXTERNAL "" ON)
option(SPDLOG_NO_THREAD_ID "" OFF)
option(SPDLOG_WCHAR_CONSOLE "" ON)
option(SPDLOG_WCHAR_FILENAMES "" ON)
option(SPDLOG_WCHAR_SUPPORT "" ON)

FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.12.0
GIT_TAG v1.17.0
GIT_SHALLOW ON
)
FetchContent_MakeAvailable(spdlog)
Expand All @@ -30,20 +30,26 @@ mark_as_advanced(
SPDLOG_BUILD_TESTS_HO
SPDLOG_BUILD_WARNINGS
SPDLOG_CLOCK_COARSE
SPDLOG_DEBUG_POSTFIX
SPDLOG_DISABLE_DEFAULT_LOGGER
SPDLOG_ENABLE_PCH
SPDLOG_FMT_EXTERNAL
SPDLOG_FMT_EXTERNAL_HO
SPDLOG_FWRITE_UNLOCKED
SPDLOG_INSTALL
SPDLOG_MSVC_UTF8
SPDLOG_NO_ATOMIC_LEVELS
SPDLOG_NO_EXCEPTIONS
SPDLOG_NO_THREAD_ID
SPDLOG_NO_TLS
SPDLOG_NO_TZ_OFFSET
SPDLOG_PREVENT_CHILD_FD
SPDLOG_SANITIZE_ADDRESS
SPDLOG_SANITIZE_THREAD
SPDLOG_SYSTEM_INCLUDES
SPDLOG_TIDY
SPDLOG_USE_STD_FORMAT
SPDLOG_WCHAR_CONSOLE
SPDLOG_WCHAR_FILENAMES
SPDLOG_WCHAR_SUPPORT
)
14 changes: 5 additions & 9 deletions cmake/deps/Toml11.cmake
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
option(toml11_INSTALL "" OFF)
option(BUILD_TESTING "" OFF)

FetchContent_Declare(
toml11
GIT_REPOSITORY https://github.com/ToruNiina/toml11.git
GIT_TAG v3.8.0
GIT_TAG v4.4.0
GIT_SHALLOW ON
)
FetchContent_MakeAvailable(toml11)

mark_as_advanced(
CMAKE_CXX_EXTENSIONS
CMAKE_CXX_STANDARD_REQUIRED
toml11_BUILD_TEST
toml11_INSTALL
toml11_TEST_WITH_ASAN
toml11_TEST_WITH_UBSAN
TOML11_USE_UNRELEASED_TOML_FEATURES
BUILD_TESTING
TOML11_ENABLE_ACCESS_CHECK
TOML11_PRECOMPILE
)
4 changes: 3 additions & 1 deletion cmake/deps/Wil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ option(WIL_BUILD_TESTS "" OFF)
FetchContent_Declare(
WIL
GIT_REPOSITORY https://github.com/microsoft/wil.git
GIT_TAG ff206266eddc3d1f788e11db472d9f28d799e08f
GIT_TAG 3ecba603d9789435b0661be7b7154d45c195ef98
EXCLUDE_FROM_ALL # The project does not have any INSTALL options.
)
FetchContent_MakeAvailable(WIL)
Expand All @@ -13,4 +13,6 @@ mark_as_advanced(
FAST_BUILD
WIL_BUILD_PACKAGING
WIL_BUILD_TESTS
WIL_ENABLE_ASAN
WIL_ENABLE_UBSAN
)
1 change: 0 additions & 1 deletion src/dll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,5 @@ target_link_libraries(
simdjson::simdjson
spdlog::spdlog
toml11::toml11
tsl::ordered_map
WIL::WIL
)
32 changes: 22 additions & 10 deletions src/dll/Config.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
#include "stdafx.hpp"
#include "Config.hpp"
#include "Paths.hpp"
#include "Utils.hpp"

#include <spdlog/common.h>
#include <toml11/find.hpp>
#include <toml11/parser.hpp>
#include <toml11/types.hpp>

#include <Windows.h>

#include <exception>
#include <filesystem>
#include <iostream>
#include <string>
#include <system_error>
#include <vector>

#define DEFAULT_TOML_EXCEPTION_MSG L"An exception occured while parsing the config file:\n\n{}\n\nFile: {}"

Config::Config(const Paths& aPaths)
Expand Down Expand Up @@ -91,20 +105,18 @@ void Config::Save(const std::filesystem::path& aFile)
{
try
{
using ordered_value = toml::basic_value<toml::preserve_comments, tsl::ordered_map>;

auto logLevel = spdlog::level::to_string_view(m_logging.level).data();
auto flushOn = spdlog::level::to_string_view(m_logging.flushOn).data();

ordered_value config{
toml::ordered_value config{toml::ordered_table{
{"version", LatestVersion},
{"logging", ordered_value{{"level", logLevel},
{"flush_on", flushOn},
{"max_files", m_logging.maxFiles},
{"max_file_size", m_logging.maxFileSize}}},
{"logging", toml::ordered_table{{"level", logLevel},
{"flush_on", flushOn},
{"max_files", m_logging.maxFiles},
{"max_file_size", m_logging.maxFileSize}}},

{"plugins", ordered_value{{"enabled", m_plugins.isEnabled}, {"ignored", std::vector<std::string>{}}}},
{"dev", ordered_value{{"console", m_dev.hasConsole}, {"wait_for_debugger", m_dev.waitForDebugger}}}};
{"plugins", toml::ordered_table{{"enabled", m_plugins.isEnabled}, {"ignored", std::vector<std::string>{}}}},
{"dev", toml::ordered_table{{"console", m_dev.hasConsole}, {"wait_for_debugger", m_dev.waitForDebugger}}}}};

config.comments().push_back(
" See https://docs.red4ext.com/getting-started/configuration for more options or information.");
Expand Down
16 changes: 16 additions & 0 deletions src/dll/Hooks/ValidateScripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@
#include "Detail/AddressHashes.hpp"
#include "Hook.hpp"
#include "RED4ext/Scripting/ScriptReport.hpp"
#include "ScriptValidationError.hpp"
#include "Systems/PluginSystem.hpp"
#include "Systems/ScriptCompilationSystem.hpp"
#include "Utils.hpp"

#include <fmt/xchar.h>
#include <spdlog/spdlog.h>

#include <Windows.h>

#include <cstdint>
#include <iterator>
#include <optional>
#include <string>
#include <string_view>
#include <unordered_set>
#include <vector>

namespace
{
Expand Down
26 changes: 25 additions & 1 deletion src/dll/Systems/PluginSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
#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 <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 <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 MINIMUM_API_VERSION RED4EXT_API_VERSION_0
#define LATEST_API_VERSION RED4EXT_API_VERSION_LATEST

Expand Down Expand Up @@ -263,7 +287,7 @@ void PluginSystem::Load(const std::filesystem::path& aPath, bool aUseAlteredSear
{
spdlog::warn(
L"{} (version: {}) is incompatible with the current patch. The requested runtime of the plugin is {}",
pluginName, std::to_wstring(pluginVersion), requestedRuntime);
pluginName, std::to_wstring(pluginVersion), std::to_wstring(requestedRuntime));

m_incompatiblePlugins.emplace_back(pluginName);
return;
Expand Down
33 changes: 29 additions & 4 deletions src/dll/Systems/ScriptCompilationSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
#include "ScriptCompilationSystem.hpp"
#include "ESystemType.hpp"
#include "Paths.hpp"
#include "PluginBase.hpp"
#include "SourceRefRepository.hpp"
#include "Utils.hpp"

#include <fmt/format.h>
#include <fmt/xchar.h>
#include <spdlog/spdlog.h>

#include <filesystem>
#include <format>
#include <fstream>
#include <iterator>
#include <memory>
#include <mutex>
#include <ostream>
#include <string>
#include <utility>
#include <vector>

ScriptCompilationSystem::ScriptCompilationSystem(const Paths& aPaths)
: m_paths(aPaths)
, m_hasScriptsBlob(false)
Expand Down Expand Up @@ -117,26 +136,32 @@ bool ScriptCompilationSystem::Add(std::shared_ptr<PluginBase> aPlugin, const wch
std::wstring ScriptCompilationSystem::GetCompilationArgs(const FixedWString& aOriginal)
{
fmt::wmemory_buffer buffer;

if (m_hasScriptsBlob)
{
spdlog::info("Using scriptsBlobPath");
format_to(std::back_inserter(buffer), LR"(-compile "{}" "{}")", m_paths.GetR6Scripts(), m_scriptsBlobPath);
fmt::format_to(std::back_inserter(buffer), LR"(-compile "{}" "{}")", m_paths.GetR6Scripts(), m_scriptsBlobPath);
}
else
{
format_to(std::back_inserter(buffer), aOriginal.str);
fmt::format_to(std::back_inserter(buffer), L"{}", aOriginal.str);
}

spdlog::info("Adding paths to redscript compilation:");

auto pathsFilePath = m_paths.GetRedscriptPathsFile();
std::wofstream pathsFile(pathsFilePath, std::ios::out);

for (const auto& [plugin, path] : m_scriptPaths)
{
spdlog::info(L"{}: '{}'", plugin->GetName(), path);
pathsFile << path.wstring() << std::endl;
}

spdlog::info(L"Paths written to: '{}'", pathsFilePath);
format_to(std::back_inserter(buffer), LR"( -compilePathsFile "{}")", pathsFilePath);
return fmt::to_string(buffer);
fmt::format_to(std::back_inserter(buffer), LR"( -compilePathsFile "{}")", pathsFilePath);

return fmt::to_wstring(buffer);
}

const ScriptCompilationSystem::Map_t& ScriptCompilationSystem::GetScriptPaths() const
Expand Down
Loading