From ab0cb538a42efe94492ec4580f41d3287f973234 Mon Sep 17 00:00:00 2001 From: Fabian Date: Tue, 4 Jul 2023 22:17:55 +0200 Subject: [PATCH] Some QoL improvements: - Disable dev mode on IPv6 or unreachable game portal host names. - Print the client build and path on launcher start. - Disable anti crash feature when dev/custom file/static auth seed modes are disabled. This restores the original client side security features when using external hosts. --- src/Launcher.cs | 25 ++++++++++++++++++++++--- src/Misc/Helpers.cs | 22 ++++++++++++++++------ src/Program.cs | 3 ++- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/Launcher.cs b/src/Launcher.cs index 18a5353..f4a0709 100644 --- a/src/Launcher.cs +++ b/src/Launcher.cs @@ -152,6 +152,14 @@ static class Launcher // Build the version URL from the game binary build. var clientVersion = GetVersionValueFromClient(appPath); + + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(); + Console.WriteLine($"Client Build {clientVersion}"); + Console.WriteLine($"Client Path '{appPath}'"); + Console.WriteLine(); + Console.ResetColor(); + byte[] versionPatch = Patches.Common.GetVersionUrl(clientVersion.Build); // Refresh the client data before patching. @@ -187,7 +195,17 @@ static class Launcher NativeWindows.NtResumeProcess(processInfo.ProcessHandle); - WaitForUnpack(ref processInfo, memory, ref mbi, gameAppData); + var antiCrash = false; + + // Enable anti crash in dev mode, custom file mode or static auth seed mode. +#if CUSTOM_FILES + antiCrash = true; +#else + antiCrash = commandLineResult.HasOption(LaunchOptions.UseStaticAuthSeed) || + commandLineResult.GetValueForOption(LaunchOptions.DevMode) && LaunchOptions.IsDevModeAllowed; +#endif + + WaitForUnpack(ref processInfo, memory, ref mbi, gameAppData, antiCrash); #if x64 if (clientVersion is (1, >= 14, _, _) or (3, 4, <= 1, _) or (9, _, _, _) or (10, <= 1, _, _) and not (10, 1, 5, _)) @@ -321,7 +339,7 @@ static class Launcher #endif } - static void WaitForUnpack(ref ProcessInformation processInfo, WinMemory memory, ref MemoryBasicInformation mbi, Stream gameAppData) + static void WaitForUnpack(ref ProcessInformation processInfo, WinMemory memory, ref MemoryBasicInformation mbi, Stream gameAppData, bool antiCrash) { #if x64 // Wait for client initialization. @@ -356,7 +374,8 @@ static class Launcher while (memory?.Read(virtualTextSectionEnd, 1)?[0] == null || memory?.Read(virtualTextSectionEnd, 1)?[0] == textSectionEndValue) Thread.Sleep(100); #endif - PrepareAntiCrash(memory, ref mbi, ref processInfo); + if (antiCrash) + PrepareAntiCrash(memory, ref mbi, ref processInfo); memory.RefreshMemoryData((int)mbi.RegionSize); } diff --git a/src/Misc/Helpers.cs b/src/Misc/Helpers.cs index cd448cb..8e3bc3c 100644 --- a/src/Misc/Helpers.cs +++ b/src/Misc/Helpers.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Net; +using System.Net.Sockets; namespace Arctium.WoW.Launcher.Misc; @@ -69,14 +70,23 @@ static class Helpers var ipSpan = colonIndex != -1 ? portalSpan[..colonIndex] : portalSpan; var portalString = ipSpan.ToString().Trim(); - if (IPAddress.TryParse(portalString, out var ipAddress)) - return ipAddress.ToString().AsSpan(); + try + { + if (IPAddress.TryParse(portalString, out var ipAddress)) + return ipAddress.ToString().AsSpan(); - var ipv4Address = Dns.GetHostAddresses(portalString).FirstOrDefault(a => a.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork); + var ipv4Address = Dns.GetHostAddresses(portalString).FirstOrDefault(a => a.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork); - if (ipv4Address == null) - throw new Exception("No IPv4 address found for the provided hostname."); + if (ipv4Address == null) + throw new Exception("No IPv4 address found for the provided hostname."); - return ipv4Address.ToString().AsSpan(); + return ipv4Address.ToString().AsSpan(); + } + catch (SocketException) + { + Console.WriteLine("No valid portal found. Dev (Local) mode disabled."); + + return string.Empty.AsSpan(); + } } } diff --git a/src/Program.cs b/src/Program.cs index 92997ab..fa0853c 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -15,7 +15,8 @@ LaunchOptions.RootCommand.SetHandler(context => { CreateDevIPFilter(out var ipFilter); - var appPath = Launcher.PrepareGameLaunch(context.ParseResult, ipFilter); + // Prefer / instead of \ for the client path. + var appPath = Launcher.PrepareGameLaunch(context.ParseResult, ipFilter).Replace("\\", "/"); var gameCommandLine = string.Join(" ", context.ParseResult.UnmatchedTokens); // Add config parameter to the game command line.