From 8500525722ed697b0f9008440ae860faa2ca77f6 Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Fri, 8 Oct 2021 10:44:24 -0300 Subject: [PATCH] client side lua install command thing --- .../ClientSource/Screens/MainMenuScreen.cs | 34 ++++++++++++++++- .../ServerSource/DebugConsole.cs | 4 ++ .../SharedSource/Lua/LuaSetup.cs | 38 ++++++++++++++++++- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs b/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs index 12f4e936a..b4e573d9c 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs @@ -431,9 +431,41 @@ namespace Barotrauma { if (!File.Exists("Barotrauma.dll.original")) { - new GUIMessageBox("", "Error: Barotrauma.dll.original not found, Github version? Use Steam validate files instead."); + new GUIMessageBox("Error", "Error: Barotrauma.dll.original not found, Github version? Use Steam validate files instead."); + + return false; } + if (!File.Exists("Barotrauma.deps.json.original")) + { + new GUIMessageBox("Error", "Error: Barotrauma.deps.json.original not found, Github version? Use Steam validate files instead."); + + return false; + } + + var msg = new GUIMessageBox("Confirm", "Are you sure you want to remove Client-Side Lua?", new string[] { "Remove", "Cancel" }); + + msg.Buttons[0].OnClicked = (GUIButton button, object obj) => + { + File.Delete("Barotrauma.dll"); + File.Delete("Barotrauma.deps.json"); + + File.Move("Barotrauma.dll.original", "Barotrauma.dll"); + File.Move("Barotrauma.deps.json.original", "Barotrauma.deps.json"); + + new GUIMessageBox("Restart", "Restart your game to apply the changes."); + + msg.Close(); + + return true; + }; + + msg.Buttons[1].OnClicked = (GUIButton button, object obj) => + { + msg.Close(); + return true; + }; + return true; } }; diff --git a/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs b/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs index 83d69cc3a..a3846fb7e 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs @@ -1253,6 +1253,10 @@ namespace Barotrauma GameMain.Lua.Initialize(); })); + commands.Add(new Command("install_cl_lua", "Installs client-side lua into your client.", (string[] args) => + { + LuaSetup.InstallClientSideLua(); + })); commands.Add(new Command("randomizeseed", "randomizeseed: Toggles level seed randomization on/off.", (string[] args) => { diff --git a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs index 52aa85d95..02dd73070 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaSetup.cs @@ -12,6 +12,7 @@ using System.Linq; using MoonSharp.Interpreter.Interop; using System.Reflection; using FarseerPhysics.Dynamics; +using System.IO.Compression; #if CLIENT using Microsoft.Xna.Framework.Graphics; @@ -236,6 +237,41 @@ namespace Barotrauma descriptor.AddMetaMember("__call", new ObjectCallbackMemberDescriptor("__call", HandleCall)); } +#if SERVER + public static void InstallClientSideLua() + { + if (!File.Exists("Mods/LuaForBarotrauma/clientside_files.zip")) + { + GameMain.Server.SendChatMessage("clientside_files.zip doesn't exist, Github version?", ChatMessageType.ServerMessageBox); + + return; + } + + try + { + + ZipFile.ExtractToDirectory("Mods/LuaForBarotrauma/clientside_files.zip", ".", true); + + File.Move("Barotrauma.dll", "Barotrauma.dll.temp"); + File.Move("Barotrauma.deps.json", "Barotrauma.deps.json.temp"); + + File.Move("Barotrauma.dll.original", "Barotrauma.dll"); + File.Move("Barotrauma.deps.json.original", "Barotrauma.deps.json"); + + File.Move("Barotrauma.dll.temp", "Barotrauma.dll.original"); + File.Move("Barotrauma.deps.json.temp", "Barotrauma.deps.json.original"); + }catch(Exception e) + { + LuaSetup.luaSetup.HandleLuaException(e); + + return; + } + + GameMain.Server.SendChatMessage("Client-Side Lua installed, restart your game to apply changes.", ChatMessageType.ServerMessageBox); + } + +#endif + public void Stop() { hook.Call("stop", new object[] { }); @@ -398,7 +434,7 @@ namespace Barotrauma AddCallMetaMember(UserData.RegisterType()); AddCallMetaMember(UserData.RegisterType()); AddCallMetaMember(UserData.RegisterType()); - + #endif lua = new Script(CoreModules.Preset_SoftSandbox);