diff --git a/src/CET.cpp b/src/CET.cpp index db2b02a8..9ec5caf6 100644 --- a/src/CET.cpp +++ b/src/CET.cpp @@ -71,7 +71,7 @@ CET::CET() , m_bindings(m_paths, m_options) , m_window(&m_bindings, &m_d3d12) , m_d3d12(m_window, m_paths, m_options) - , m_vm(m_paths, m_bindings, m_d3d12) + , m_vm(m_paths, m_options, m_bindings, m_d3d12) , m_overlay(m_bindings, m_options, m_persistentState, m_vm) { } diff --git a/src/Options.cpp b/src/Options.cpp index 17634c92..fa622720 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -18,14 +18,9 @@ void PatchesSettings::Load(const nlohmann::json& aConfig) nlohmann::json PatchesSettings::Save() const { return { - {"disable_async_compute", AsyncCompute}, - {"disable_antialiasing", Antialiasing}, - {"skip_start_menu", SkipStartMenu}, - {"disable_intro_movies", DisableIntroMovies}, - {"disable_vignette", DisableVignette}, - {"disable_boundary_teleport", DisableBoundaryTeleport}, - {"disable_win7_vsync", DisableWin7Vsync}, - {"minimap_flicker", MinimapFlicker}, + {"disable_async_compute", AsyncCompute}, {"disable_antialiasing", Antialiasing}, {"skip_start_menu", SkipStartMenu}, + {"disable_intro_movies", DisableIntroMovies}, {"disable_vignette", DisableVignette}, {"disable_boundary_teleport", DisableBoundaryTeleport}, + {"disable_win7_vsync", DisableWin7Vsync}, {"minimap_flicker", MinimapFlicker}, }; } @@ -60,6 +55,7 @@ void DeveloperSettings::Load(const nlohmann::json& aConfig) DumpGameOptions = aConfig.value("dump_game_options", DumpGameOptions); MaxLinesConsoleHistory = aConfig.value("max_lines_console_history", MaxLinesConsoleHistory); PersistentConsole = aConfig.value("persistent_console", PersistentConsole); + EnableJIT = aConfig.value("enable_jit", EnableJIT); // set global "Enable ImGui Assertions" g_ImGuiAssertionsEnabled = EnableImGuiAssertions; @@ -70,8 +66,8 @@ nlohmann::json DeveloperSettings::Save() const // set global "Enable ImGui Assertions" g_ImGuiAssertionsEnabled = EnableImGuiAssertions; - return {{"remove_dead_bindings", RemoveDeadBindings}, {"enable_imgui_assertions", EnableImGuiAssertions}, - {"dump_game_options", DumpGameOptions}, {"max_lines_console_history", MaxLinesConsoleHistory}, {"persistent_console", PersistentConsole}}; + return {{"remove_dead_bindings", RemoveDeadBindings}, {"enable_imgui_assertions", EnableImGuiAssertions}, {"dump_game_options", DumpGameOptions}, + {"max_lines_console_history", MaxLinesConsoleHistory}, {"persistent_console", PersistentConsole}, {"enable_jit", EnableJIT}}; } void DeveloperSettings::ResetToDefaults() diff --git a/src/Options.h b/src/Options.h index 7b01a506..97c870f7 100644 --- a/src/Options.h +++ b/src/Options.h @@ -50,6 +50,7 @@ struct DeveloperSettings bool DumpGameOptions{false}; uint64_t MaxLinesConsoleHistory{1000}; bool PersistentConsole{true}; + bool EnableJIT{true}; }; struct Options diff --git a/src/overlay/widgets/Settings.cpp b/src/overlay/widgets/Settings.cpp index af54fb30..fd49c2f6 100644 --- a/src/overlay/widgets/Settings.cpp +++ b/src/overlay/widgets/Settings.cpp @@ -107,6 +107,9 @@ void Settings::OnUpdate() UpdateAndDrawSetting( "Dump Game Options", "Dumps all game options into main log file (requires restart to take effect).", m_developer.DumpGameOptions, developerSettings.DumpGameOptions); + UpdateAndDrawSetting( + "Enable JIT for Lua", "Enables JIT compiler for Lua VM, which may majorly speed up the mods. Disable it in case you experience issues as a troubleshooting step (requires restart to take effect).", m_developer.EnableJIT, + developerSettings.EnableJIT); ImGui::EndTable(); } diff --git a/src/scripting/LuaVM.h b/src/scripting/LuaVM.h index c0881ac6..be8d4291 100644 --- a/src/scripting/LuaVM.h +++ b/src/scripting/LuaVM.h @@ -25,7 +25,7 @@ struct TDBIDLookupEntry struct Image; struct LuaVM { - LuaVM(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12); + LuaVM(const Paths& aPaths, const Options& aOptions, VKBindings& aBindings, D3D12& aD3D12); ~LuaVM() = default; [[nodiscard]] const VKBind* GetBind(const VKModBind& acModBind) const; diff --git a/src/scripting/LuaVM_Hooks.cpp b/src/scripting/LuaVM_Hooks.cpp index 088dd305..a7bb3693 100644 --- a/src/scripting/LuaVM_Hooks.cpp +++ b/src/scripting/LuaVM_Hooks.cpp @@ -258,8 +258,8 @@ void LuaVM::HookLogChannel(RED4ext::IScriptable*, RED4ext::CStackFrame* apStack, } } -LuaVM::LuaVM(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12) - : m_scripting(aPaths, aBindings, aD3D12) +LuaVM::LuaVM(const Paths& aPaths, const Options& aOptions, VKBindings& aBindings, D3D12& aD3D12) + : m_scripting(aPaths, aOptions, aBindings, aD3D12) , m_d3d12(aD3D12) { Hook(); diff --git a/src/scripting/Scripting.cpp b/src/scripting/Scripting.cpp index 1433088d..89a92b40 100644 --- a/src/scripting/Scripting.cpp +++ b/src/scripting/Scripting.cpp @@ -32,12 +32,13 @@ static constexpr bool s_cThrowLuaErrors = true; static RTTILocator s_stringType{RED4ext::FNV1a64("String")}; static RTTILocator s_resRefType{RED4ext::FNV1a64("redResourceReferenceScriptToken")}; -Scripting::Scripting(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12) +Scripting::Scripting(const Paths& aPaths, const Options& aOptions, VKBindings& aBindings, D3D12& aD3D12) : m_sandbox(this, aBindings) , m_mapper(m_lua.AsRef(), m_sandbox) , m_store(m_sandbox, aPaths, aBindings) , m_override(this) , m_paths(aPaths) + , m_options(aOptions) , m_d3d12(aD3D12) { CreateLogger(aPaths.CETRoot() / "scripting.log", "scripting"); @@ -50,6 +51,10 @@ void Scripting::Initialize() auto& luaVm = lua.Get(); luaVm.open_libraries(sol::lib::base, sol::lib::string, sol::lib::io, sol::lib::math, sol::lib::package, sol::lib::os, sol::lib::table, sol::lib::bit32); + + if (m_options.Developer.EnableJIT) + luaVm.open_libraries(sol::lib::jit); + luaVm.require("sqlite3", luaopen_lsqlite3); // make sure to set package path to current directory scope diff --git a/src/scripting/Scripting.h b/src/scripting/Scripting.h index 23938306..b6d25600 100644 --- a/src/scripting/Scripting.h +++ b/src/scripting/Scripting.h @@ -11,7 +11,7 @@ struct Scripting { using LockedState = TiltedPhoques::Locked; - Scripting(const Paths& aPaths, VKBindings& aBindings, D3D12& aD3D12); + Scripting(const Paths& aPaths, const Options& aOptions, VKBindings& aBindings, D3D12& aD3D12); ~Scripting() = default; void Initialize(); @@ -61,5 +61,6 @@ struct Scripting ScriptStore m_store; FunctionOverride m_override; const Paths& m_paths; + const Options& m_options; D3D12& m_d3d12; };