diff --git a/Barotrauma/BarotraumaClient/ClientSource/GameMain.cs b/Barotrauma/BarotraumaClient/ClientSource/GameMain.cs index 3fd8e318c..bbe4aff5a 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/GameMain.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/GameMain.cs @@ -577,7 +577,7 @@ namespace Barotrauma } #if CLIENT - LuaCsUpdateChecker.Check(); + LuaCsInstaller.CheckUpdate(); #endif yield return CoroutineStatus.Success; diff --git a/Barotrauma/BarotraumaClient/ClientSource/LuaCs/LuaCsUpdateChecker.cs b/Barotrauma/BarotraumaClient/ClientSource/LuaCs/LuaCsInstaller.cs similarity index 62% rename from Barotrauma/BarotraumaClient/ClientSource/LuaCs/LuaCsUpdateChecker.cs rename to Barotrauma/BarotraumaClient/ClientSource/LuaCs/LuaCsInstaller.cs index a6b4a7fd8..9d27c91a1 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/LuaCs/LuaCsUpdateChecker.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/LuaCs/LuaCsInstaller.cs @@ -4,9 +4,58 @@ using System.Linq; namespace Barotrauma { - static class LuaCsUpdateChecker + static partial class LuaCsInstaller { - public static void Check() + public static void Uninstall() + { + if (!File.Exists("Temp/Original/Barotrauma.dll")) + { + new GUIMessageBox("Error", "Error: Temp/Original/Barotrauma.dll not found, Github version? Use Steam validate files instead."); + + return; + } + + var msg = new GUIMessageBox("Confirm", "Are you sure you want to remove Client-Side LuaCs?", new LocalizedString[2] { TextManager.Get("Yes"), TextManager.Get("Cancel") }); + + msg.Buttons[0].OnClicked = (GUIButton button, object obj) => + { + msg.Close(); + + string[] filesToRemove = new string[] + { + "Barotrauma.dll", "Barotrauma.deps.json", + "System.Reflection.Metadata.dll", "System.Collections.Immutable.dll", + "System.Runtime.CompilerServices.Unsafe.dll" + }; + try + { + CreateMissingDirectory(); + + foreach (string file in filesToRemove) + { + File.Move(file, "Temp/ToDelete/" + file, true); + File.Move("Temp/Original/" + file, file, true); + } + } + catch (Exception e) + { + new GUIMessageBox("Error", $"{e} {e.InnerException} \nTry verifying files instead."); + return false; + } + + new GUIMessageBox("Restart", "Restart your game to apply the changes. If the mod continues to stay active after the restart, try verifying games instead."); + + return true; + }; + + msg.Buttons[1].OnClicked = (GUIButton button, object obj) => + { + msg.Close(); + return true; + }; + } + + public static void CheckUpdate() { if (!File.Exists(LuaCsSetup.VersionFile)) { return; } @@ -48,11 +97,13 @@ namespace Barotrauma try { + CreateMissingDirectory(); + foreach (string file in filesToUpdate) { try { - File.Move(file, file + ".todelete", true); + File.Move(file, "Temp/Old/" + file, true); File.Copy(Path.Combine(luaCsPath, "Binary", file), file, true); } catch (Exception e) diff --git a/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs b/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs index 97739f866..8569b995c 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs @@ -406,57 +406,7 @@ namespace Barotrauma ToolTip = "Remove Client-Side LuaCs.", OnClicked = (tb, userdata) => { - if (!File.Exists("Barotrauma.dll.old")) - { - new GUIMessageBox("Error", "Error: Barotrauma.dll.original not found, Github version? Use Steam validate files instead."); - - return false; - } - - if (!File.Exists("Barotrauma.deps.json.old")) - { - 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 LuaCs?", new LocalizedString[2] { TextManager.Get("Yes"), TextManager.Get("Cancel") }); - - msg.Buttons[0].OnClicked = (GUIButton button, object obj) => - { - msg.Close(); - - string[] filesToRemove = new string[] - { - "Barotrauma.dll", "Barotrauma.deps.json", - "System.Reflection.Metadata.dll", "System.Collections.Immutable.dll", - "System.Runtime.CompilerServices.Unsafe.dll" - }; - try - { - foreach (string file in filesToRemove) - { - System.IO.File.Move(file, file + ".todelete", true); - System.IO.File.Move(file + ".old", file, true); - } - } - catch(Exception e) - { - new GUIMessageBox("Error", $"{e} {e.InnerException}"); - return false; - } - - new GUIMessageBox("Restart", "Restart your game to apply the changes."); - - return true; - }; - - msg.Buttons[1].OnClicked = (GUIButton button, object obj) => - { - msg.Close(); - return true; - }; - + LuaCsInstaller.Uninstall(); return true; } }; diff --git a/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs b/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs index 5cd0bf125..a8723adda 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs @@ -1268,69 +1268,7 @@ namespace Barotrauma #if WINDOWS commands.Add(new Command("install_cl_lua", "Installs Client-Side Lua into your client.", (string[] args) => { - ContentPackage luaPackage = LuaCsSetup.GetPackage("Lua For Barotrauma"); - - if (luaPackage == null) - { - GameMain.Server.SendChatMessage("Couldn't find the Lua For Barotrauma package.", ChatMessageType.ServerMessageBox); - return; - } - - try - { - string path = Path.GetDirectoryName(luaPackage.Path); - - string[] filesToCopy = new string[] - { - "Barotrauma.dll", "Barotrauma.deps.json", - "0harmony.dll", "Mono.Cecil.dll", - "Sigil.dll", - "Mono.Cecil.Mdb.dll", "Mono.Cecil.Pdb.dll", - "Mono.Cecil.Rocks.dll", "MonoMod.Common.dll", - "MoonSharp.Interpreter.dll", - - "Microsoft.CodeAnalysis.dll", "Microsoft.CodeAnalysis.CSharp.dll", - "Microsoft.CodeAnalysis.CSharp.Scripting.dll", "Microsoft.CodeAnalysis.Scripting.dll", - - "System.Reflection.Metadata.dll", "System.Collections.Immutable.dll", - "System.Runtime.CompilerServices.Unsafe.dll" - }; - filesToCopy = filesToCopy.Concat(Directory.EnumerateFiles(path, "*.dll", SearchOption.AllDirectories) - .Where(s => s.Contains("mscordaccore_amd64_amd64_4.")).Select(s => Path.GetFileName(s))).ToArray(); - - File.Move("Barotrauma.dll", "Barotrauma.dll.old", true); - File.Move("Barotrauma.deps.json", "Barotrauma.deps.json.old", true); - - File.Move("System.Reflection.Metadata.dll", "System.Reflection.Metadata.dll.old", true); - File.Move("System.Collections.Immutable.dll", "System.Collections.Immutable.dll.old", true); - File.Move("System.Runtime.CompilerServices.Unsafe.dll", "System.Runtime.CompilerServices.Unsafe.dll.old", true); - - foreach (string file in filesToCopy) - { - if (File.Exists(file)) - { - File.Move(file, file + ".todelete", true); - } - File.Copy(Path.Combine(path, "Binary", file), file, true); - } - - File.WriteAllText(LuaCsSetup.VersionFile, luaPackage.ModVersion); - File.WriteAllText("LuaDedicatedServer.bat", "\"%LocalAppData%/Daedalic Entertainment GmbH/Barotrauma/WorkshopMods/Installed/2559634234/Binary/DedicatedServer.exe\""); - } - catch (UnauthorizedAccessException e) - { - GameMain.LuaCs.PrintError("You seem to already have Client Side Lua installed, if you are trying to reinstall, make sure uninstall it first (mainmenu button located top left).", LuaCsMessageOrigin.LuaCs); - - return; - } - catch (Exception e) - { - GameMain.LuaCs.HandleException(e, LuaCsMessageOrigin.LuaCs); - - return; - } - - GameMain.Server.SendChatMessage("Client-Side Lua installed, restart your game to apply changes.", ChatMessageType.ServerMessageBox); + LuaCsInstaller.Install(); })); #endif diff --git a/Barotrauma/BarotraumaServer/ServerSource/LuaCs/LuaCsInstaller.cs b/Barotrauma/BarotraumaServer/ServerSource/LuaCs/LuaCsInstaller.cs new file mode 100644 index 000000000..6bc770e15 --- /dev/null +++ b/Barotrauma/BarotraumaServer/ServerSource/LuaCs/LuaCsInstaller.cs @@ -0,0 +1,79 @@ +using Barotrauma.Networking; +using System; +using System.IO; +using System.Linq; + +namespace Barotrauma +{ + static partial class LuaCsInstaller + { + public static void Install() + { + ContentPackage luaPackage = LuaCsSetup.GetPackage("Lua For Barotrauma"); + + if (luaPackage == null) + { + GameMain.Server.SendChatMessage("Couldn't find the Lua For Barotrauma package.", ChatMessageType.ServerMessageBox); + return; + } + + try + { + string path = Path.GetDirectoryName(luaPackage.Path); + + string[] filesToCopy = new string[] + { + "Barotrauma.dll", "Barotrauma.deps.json", + "0harmony.dll", "Mono.Cecil.dll", + "Sigil.dll", + "Mono.Cecil.Mdb.dll", "Mono.Cecil.Pdb.dll", + "Mono.Cecil.Rocks.dll", "MonoMod.Common.dll", + "MoonSharp.Interpreter.dll", + + "Microsoft.CodeAnalysis.dll", "Microsoft.CodeAnalysis.CSharp.dll", + "Microsoft.CodeAnalysis.CSharp.Scripting.dll", "Microsoft.CodeAnalysis.Scripting.dll", + + "System.Reflection.Metadata.dll", "System.Collections.Immutable.dll", + "System.Runtime.CompilerServices.Unsafe.dll" + }; + filesToCopy = filesToCopy.Concat(Directory.EnumerateFiles(path, "*.dll", SearchOption.AllDirectories) + .Where(s => s.Contains("mscordaccore_amd64_amd64_4.")).Select(s => Path.GetFileName(s))).ToArray(); + + CreateMissingDirectory(); + + File.Move("Barotrauma.dll", "Temp/Original/Barotrauma.dll", true); + File.Move("Barotrauma.deps.json", "Temp/Original/Barotrauma.deps.json", true); + + File.Move("System.Reflection.Metadata.dll", "Temp/Original/System.Reflection.Metadata.dll", true); + File.Move("System.Collections.Immutable.dll", "Temp/Original/System.Collections.Immutable.dll", true); + File.Move("System.Runtime.CompilerServices.Unsafe.dll", "Temp/Original/System.Runtime.CompilerServices.Unsafe.dll", true); + + foreach (string file in filesToCopy) + { + if (File.Exists(file)) + { + File.Move(file, "Temp/ToDelete/" + file, true); + } + File.Copy(Path.Combine(path, "Binary", file), file, true); + } + + File.WriteAllText(LuaCsSetup.VersionFile, luaPackage.ModVersion); + File.WriteAllText("LuaDedicatedServer.bat", "\"%LocalAppData%/Daedalic Entertainment GmbH/Barotrauma/WorkshopMods/Installed/2559634234/Binary/DedicatedServer.exe\""); + } + catch (UnauthorizedAccessException e) + { + GameMain.LuaCs.PrintError("You seem to already have Client Side Lua installed, if you are trying to reinstall, make sure uninstall it first (mainmenu button located top left).", LuaCsMessageOrigin.LuaCs); + + return; + } + catch (Exception e) + { + GameMain.LuaCs.HandleException(e, LuaCsMessageOrigin.LuaCs); + + return; + } + + GameMain.Server.SendChatMessage("Client-Side Lua installed, restart your game to apply changes.", ChatMessageType.ServerMessageBox); + } + } +} diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsInstaller.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsInstaller.cs new file mode 100644 index 000000000..2ac182156 --- /dev/null +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsInstaller.cs @@ -0,0 +1,18 @@ + +using System; +using System.IO; +using System.Linq; + +namespace Barotrauma +{ + static partial class LuaCsInstaller + { + private static void CreateMissingDirectory() + { + Directory.CreateDirectory("Temp/Original"); + Directory.CreateDirectory("Temp/ToDelete"); + Directory.CreateDirectory("Temp/Old"); + } + + } +}