From 8b57f321250a03a71853e09589c1e0ce8977c02e Mon Sep 17 00:00:00 2001 From: James Puleo Date: Tue, 20 Dec 2022 21:36:31 -0500 Subject: [PATCH] Detect invalid TShock installations There are two common mistakes made by those installing/updating TShock: - Extracting TShock into the Terraria client directory - Extracting TShock 5 or newer into a legacy (TShock 4 or older) install By checking for the existence of a file named `TerrariaServer.exe`, we can potentially detect these invalid installations, and prompt the user with a more useful diagnostic, rather than (likely) crashing moments later. --- TShockLauncher/Program.cs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/TShockLauncher/Program.cs b/TShockLauncher/Program.cs index 4a139370..0163cc2d 100644 --- a/TShockLauncher/Program.cs +++ b/TShockLauncher/Program.cs @@ -29,12 +29,30 @@ along with this program. If not, see . using System.Reflection; using TShockPluginManager; +// On occasion, users have been seen extracting TShock into their client installation directory -- this is of course incorrect, and is known +// to cause issues. Let's attempt to catch this before anything happens (specifically, before Terraria assemblies are resolved) and prevent +// TShock from launching. +if (File.Exists("TerrariaServer.exe")) +{ + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine("A \"TerrariaServer.exe\" file has been found in the current working directory."); + Console.Error.WriteLine( + "This indicates either installation into a Terraria client directory, or installation into a legacy (TShock 4 or older) TShock directory."); + Console.Error.WriteLine( + "TShock is never to be installed inside a Terraria client directory. You should instead extract your TShock installation into it's own directory."); + Console.Error.WriteLine( + "If you are updating a legacy TShock installation, please follow the following documentation to update: https://ikebukuro.tshock.co/#/?id=upgrading-from-tshock-4"); + Console.Error.WriteLine("The launcher will now exit."); + Console.ResetColor(); + return 1; +} + if (args.Length > 0 && args[0].ToLower() == "plugins") { var items = args.ToList(); items.RemoveAt(0); await NugetCLI.Main(items); - return; + return 0; } @@ -42,7 +60,7 @@ Dictionary _cache = new Dictionary(); System.Runtime.Loader.AssemblyLoadContext.Default.Resolving += Default_Resolving; -Start(); +return Start(); /// /// Resolves a module from the ./bin folder, either with a .dll by preference or .exe @@ -70,7 +88,8 @@ Assembly? Default_Resolving(System.Runtime.Loader.AssemblyLoadContext arg1, Asse /// Initiates the TSAPI server. /// /// This method exists so that the resolver can attach before TSAPI needs its dependencies. -void Start() +int Start() { TerrariaApi.Server.Program.Main(args); + return 0; }