diff --git a/cmake/ConfigureAndIncludeRedscript.cmake b/cmake/ConfigureAndIncludeRedscript.cmake index 8da1a259..a7f42db1 100644 --- a/cmake/ConfigureAndIncludeRedscript.cmake +++ b/cmake/ConfigureAndIncludeRedscript.cmake @@ -1,6 +1,6 @@ add_library(redscript INTERFACE) -set(REDSCRIPT_SRC_DIR "${PROJECT_SOURCE_DIR}/deps/redscript/scc/lib/include") +set(REDSCRIPT_SRC_DIR "${PROJECT_SOURCE_DIR}/deps/redscript/crates/scc/capi/include") set_target_properties(redscript PROPERTIES FOLDER "Dependencies") target_include_directories(redscript INTERFACE ${REDSCRIPT_SRC_DIR}) diff --git a/deps/red4ext.sdk b/deps/red4ext.sdk index f3868a82..7fb27972 160000 --- a/deps/red4ext.sdk +++ b/deps/red4ext.sdk @@ -1 +1 @@ -Subproject commit f3868a829d26085e46ea6afc95709399d3de45d6 +Subproject commit 7fb27972c5eadb07004b37f474b2e681db754229 diff --git a/deps/redscript b/deps/redscript index 9d553bc7..b413ba6a 160000 --- a/deps/redscript +++ b/deps/redscript @@ -1 +1 @@ -Subproject commit 9d553bc7af66a46cbdca146832adfc8f13d91472 +Subproject commit b413ba6a40098191d18bb24d1a095dd00190322e diff --git a/src/dll/Hooks/ExecuteProcess.cpp b/src/dll/Hooks/ExecuteProcess.cpp index 569aa5b6..5192dfb2 100644 --- a/src/dll/Hooks/ExecuteProcess.cpp +++ b/src/dll/Hooks/ExecuteProcess.cpp @@ -114,6 +114,16 @@ bool ExecuteScc(SccApi& scc) settings.AddScriptPath(path); } + for (const auto& type : scriptSystem->GetNeverRefTypes()) + { + settings.RegisterNeverRefType(type); + } + + for (const auto& type : scriptSystem->GetMixedRefTypes()) + { + settings.RegisterMixedRefType(type); + } + const auto result = settings.Compile(); if (const auto error = std::get_if(&result)) diff --git a/src/dll/ScriptCompiler/ScriptCompilerSettings.cpp b/src/dll/ScriptCompiler/ScriptCompilerSettings.cpp index 92bbddee..c89f47c8 100644 --- a/src/dll/ScriptCompiler/ScriptCompilerSettings.cpp +++ b/src/dll/ScriptCompiler/ScriptCompilerSettings.cpp @@ -30,6 +30,18 @@ ScriptCompilerSettings* ScriptCompilerSettings::SetOutputCacheFile(std::filesyst return this; } +ScriptCompilerSettings* ScriptCompilerSettings::RegisterNeverRefType(std::string aType) +{ + m_neverRefTypes.emplace_back(std::move(aType)); + return this; +} + +ScriptCompilerSettings* ScriptCompilerSettings::RegisterMixedRefType(std::string aType) +{ + m_mixedRefTypes.emplace_back(std::move(aType)); + return this; +} + ScriptCompilerSettings::Result ScriptCompilerSettings::Compile() { auto r6PathStr = m_r6Path.u8string(); @@ -53,6 +65,28 @@ ScriptCompilerSettings::Result ScriptCompilerSettings::Compile() m_scc.settings_add_script_path(settings, reinterpret_cast(pathStr.c_str())); } + const auto registerNeverRefType = m_scc.settings_register_never_ref_type; + // Only configure never ref types when the compiler supports it. + if (registerNeverRefType) + { + for (const auto& type : m_neverRefTypes) + { + auto typeStr = type.c_str(); + registerNeverRefType(settings, typeStr); + } + } + + const auto registerMixedRefType = m_scc.settings_register_mixed_ref_type; + // Only configure mixed ref types when the compiler supports it. + if (registerMixedRefType) + { + for (const auto& type : m_mixedRefTypes) + { + auto typeStr = type.c_str(); + registerMixedRefType(settings, typeStr); + } + } + auto result = m_scc.compile(settings); if (auto output = m_scc.get_success(result)) diff --git a/src/dll/ScriptCompiler/ScriptCompilerSettings.hpp b/src/dll/ScriptCompiler/ScriptCompilerSettings.hpp index 89ee404c..ab293de5 100644 --- a/src/dll/ScriptCompiler/ScriptCompilerSettings.hpp +++ b/src/dll/ScriptCompiler/ScriptCompilerSettings.hpp @@ -15,6 +15,8 @@ class ScriptCompilerSettings ScriptCompilerSettings* AddScriptPath(std::filesystem::path aPath); ScriptCompilerSettings* SetCustomCacheFile(std::filesystem::path aPath); ScriptCompilerSettings* SetOutputCacheFile(std::filesystem::path aPath); + ScriptCompilerSettings* RegisterNeverRefType(std::string aType); + ScriptCompilerSettings* RegisterMixedRefType(std::string aType); Result Compile(); private: @@ -23,4 +25,6 @@ class ScriptCompilerSettings std::vector m_scriptPaths; std::filesystem::path m_customCacheFile; std::filesystem::path m_outputCacheFile; + std::vector m_neverRefTypes; + std::vector m_mixedRefTypes; }; diff --git a/src/dll/Systems/ScriptCompilationSystem.cpp b/src/dll/Systems/ScriptCompilationSystem.cpp index f3568e6e..24d45b98 100644 --- a/src/dll/Systems/ScriptCompilationSystem.cpp +++ b/src/dll/Systems/ScriptCompilationSystem.cpp @@ -59,6 +59,26 @@ bool ScriptCompilationSystem::HasModdedScriptsBlob() const return m_hasModdedScriptsBlob; } +void ScriptCompilationSystem::RegisterNeverRefType(std::string aType) +{ + m_neverRefTypes.emplace_back(std::move(aType)); +} + +const std::vector& ScriptCompilationSystem::GetNeverRefTypes() const +{ + return m_neverRefTypes; +} + +void ScriptCompilationSystem::RegisterMixedRefType(std::string aType) +{ + m_mixedRefTypes.emplace_back(std::move(aType)); +} + +const std::vector& ScriptCompilationSystem::GetMixedRefTypes() const +{ + return m_mixedRefTypes; +} + bool ScriptCompilationSystem::Add(std::shared_ptr aPlugin, const wchar_t* aPath) { spdlog::trace(L"Adding path to script compilation: '{}'", aPath); diff --git a/src/dll/Systems/ScriptCompilationSystem.hpp b/src/dll/Systems/ScriptCompilationSystem.hpp index a2525c94..f0270fb3 100644 --- a/src/dll/Systems/ScriptCompilationSystem.hpp +++ b/src/dll/Systems/ScriptCompilationSystem.hpp @@ -36,6 +36,12 @@ class ScriptCompilationSystem : public ISystem const std::filesystem::path& GetModdedScriptsBlob() const; bool HasModdedScriptsBlob() const; + void RegisterNeverRefType(std::string aType); + const std::vector& GetNeverRefTypes() const; + + void RegisterMixedRefType(std::string aType); + const std::vector& GetMixedRefTypes() const; + std::wstring GetCompilationArgs(const FixedWString& aOriginal); const Map_t& GetScriptPaths() const; @@ -53,4 +59,6 @@ class ScriptCompilationSystem : public ISystem bool m_hasModdedScriptsBlob; std::filesystem::path m_moddedScriptsBlobPath; SourceRefRepository m_sourceRefs; + std::vector m_neverRefTypes; + std::vector m_mixedRefTypes; }; diff --git a/src/dll/v0/Funcs.cpp b/src/dll/v0/Funcs.cpp index 135effed..331d0747 100644 --- a/src/dll/v0/Funcs.cpp +++ b/src/dll/v0/Funcs.cpp @@ -127,3 +127,29 @@ bool v0::Scripts::Add(RED4ext::PluginHandle aHandle, const wchar_t* aPath) auto scriptCompilationSystem = app->GetScriptCompilationSystem(); return scriptCompilationSystem->Add(plugin, aPath); } + +bool v0::Scripts::RegisterNeverRefType(const char* aType) +{ + auto app = App::Get(); + if (!app) + { + return false; + } + + auto scriptCompilationSystem = app->GetScriptCompilationSystem(); + scriptCompilationSystem->RegisterNeverRefType(aType); + return true; +} + +bool v0::Scripts::RegisterMixedRefType(const char* aType) +{ + auto app = App::Get(); + if (!app) + { + return false; + } + + auto scriptCompilationSystem = app->GetScriptCompilationSystem(); + scriptCompilationSystem->RegisterMixedRefType(aType); + return true; +} diff --git a/src/dll/v0/Funcs.hpp b/src/dll/v0/Funcs.hpp index 992a62e6..744d9dd2 100644 --- a/src/dll/v0/Funcs.hpp +++ b/src/dll/v0/Funcs.hpp @@ -16,6 +16,8 @@ bool Add(RED4ext::PluginHandle aHandle, RED4ext::EGameStateType aType, RED4ext:: namespace Scripts { bool Add(RED4ext::PluginHandle aHandle, const wchar_t* aPath); +bool RegisterNeverRefType(const char* aType); +bool RegisterMixedRefType(const char* aType); } // namespace Scripts } // namespace v0 diff --git a/src/dll/v0/Plugin.cpp b/src/dll/v0/Plugin.cpp index 3a64f296..c64c49ec 100644 --- a/src/dll/v0/Plugin.cpp +++ b/src/dll/v0/Plugin.cpp @@ -1,6 +1,6 @@ -#include "stdafx.hpp" #include "v0/Plugin.hpp" #include "Image.hpp" +#include "stdafx.hpp" #include "v0/Funcs.hpp" #include "v0/Logger.hpp" @@ -51,6 +51,8 @@ v0::Plugin::Plugin(const std::filesystem::path& aPath, wil::unique_hmodule aModu m_gameStates.Add = v0::GameStates::Add; m_scripts.Add = v0::Scripts::Add; + m_scripts.RegisterNeverRefType = v0::Scripts::RegisterNeverRefType; + m_scripts.RegisterMixedRefType = v0::Scripts::RegisterMixedRefType; } const uint32_t v0::Plugin::GetApiVersion() const