From af47136bbd2fecee7a785bf66654366ade74ced2 Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Fri, 29 Apr 2022 14:00:53 -0300 Subject: [PATCH] use cs package from backup packages --- .../BarotraumaClient/ClientSource/DebugConsole.cs | 2 +- .../ClientSource/LuaCs/LuaCsUpdateChecker.cs | 2 +- .../ClientSource/Screens/MainMenuScreen.cs | 2 +- .../BarotraumaServer/ServerSource/DebugConsole.cs | 2 +- .../ContentManagement/ContentPackageManager.cs | 2 +- .../SharedSource/LuaCs/LuaCsSetup.cs | 15 +++++++++++++-- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Barotrauma/BarotraumaClient/ClientSource/DebugConsole.cs b/Barotrauma/BarotraumaClient/ClientSource/DebugConsole.cs index c11cd30b7..ca771c34c 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/DebugConsole.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/DebugConsole.cs @@ -3228,7 +3228,7 @@ namespace Barotrauma })); commands.Add(new Command("cl_cs", "cs_cl: runs a string on the client", (string[] args) => { - if (LuaCsSetup.GetPackage("CsForBarotrauma", false) == null) { return; } + if (LuaCsSetup.GetPackage("CsForBarotrauma", false, true) == null) { return; } if (GameMain.Client != null && !GameMain.Client.HasPermission(ClientPermissions.ConsoleCommands)) { diff --git a/Barotrauma/BarotraumaClient/ClientSource/LuaCs/LuaCsUpdateChecker.cs b/Barotrauma/BarotraumaClient/ClientSource/LuaCs/LuaCsUpdateChecker.cs index 596188d0a..6806e0698 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/LuaCs/LuaCsUpdateChecker.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/LuaCs/LuaCsUpdateChecker.cs @@ -20,7 +20,7 @@ namespace Barotrauma if (clientVersion == workshopVersion) { return; } - string additional = LuaCsSetup.GetPackage("CsForBarotrauma", false) == null ? "" : "Cs"; + string additional = LuaCsSetup.GetPackage("CsForBarotrauma", false, true) == null ? "" : "Cs"; var msg = new GUIMessageBox($"Lua{additional} Update", $"Your Lua{additional} client version is different from the version found in the Lua{additional}ForBarotrauma workshop files. Do you want to update?\n\n Client Version: {clientVersion}\n Workshop Version: {workshopVersion}", new LocalizedString[2] { TextManager.Get("Yes"), TextManager.Get("Cancel") }); diff --git a/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs b/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs index 61aa737ac..fdaf001a0 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/Screens/MainMenuScreen.cs @@ -384,7 +384,7 @@ namespace Barotrauma } }; #endif - string additional = LuaCsSetup.GetPackage("CsForBarotrauma", false) == null ? "" : "Cs"; + string additional = LuaCsSetup.GetPackage("CsForBarotrauma", false, true) == null ? "" : "Cs"; new GUIButton(new RectTransform(new Point(300, 30), Frame.RectTransform, Anchor.TopLeft) { AbsoluteOffset = new Point(20, 50) }, $"Remove Client-Side Lua{additional}", style: "MainMenuGUIButton", color: GUIStyle.Red) diff --git a/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs b/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs index 25e7f5b5c..d827b04c2 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs @@ -1247,7 +1247,7 @@ namespace Barotrauma })); commands.Add(new Command("cs", "cs: runs a string", (string[] args) => { - if(LuaCsSetup.GetPackage("CsForBarotrauma", false) == null) { return; } + if(LuaCsSetup.GetPackage("CsForBarotrauma", false, true) == null) { return; } GameMain.LuaCs.CsScript.Run(string.Join(" ", args)); GameMain.LuaCs.RecreateCsScript(); diff --git a/Barotrauma/BarotraumaShared/SharedSource/ContentManagement/ContentPackageManager.cs b/Barotrauma/BarotraumaShared/SharedSource/ContentManagement/ContentPackageManager.cs index 68a695516..92df9e1cb 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/ContentManagement/ContentPackageManager.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/ContentManagement/ContentPackageManager.cs @@ -36,7 +36,7 @@ namespace Barotrauma ? (Core as ContentPackage).ToEnumerable().CollectionConcat(Regular) : Enumerable.Empty(); - private static class BackupPackages + public static class BackupPackages { public static CorePackage? Core; public static ImmutableArray? Regular; diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs index 13f0e1978..89a989375 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs @@ -84,7 +84,7 @@ namespace Barotrauma } - public static ContentPackage GetPackage(Identifier name, bool fallbackToAll = true) + public static ContentPackage GetPackage(Identifier name, bool fallbackToAll = true, bool useBackup = false) { foreach (ContentPackage package in ContentPackageManager.EnabledPackages.All) { @@ -113,6 +113,17 @@ namespace Barotrauma } } + if (useBackup) + { + foreach (ContentPackage package in ContentPackageManager.EnabledPackages.BackupPackages.Regular) + { + if (package.NameMatches(name)) + { + return package; + } + } + } + return null; } @@ -435,7 +446,7 @@ namespace Barotrauma lua.Globals["CLIENT"] = IsClient; - if (GetPackage("CsForBarotrauma", false) != null) + if (GetPackage("CsForBarotrauma", false, true) != null) { PrintMessage("Cs! Version " + AssemblyInfo.GitRevision);