From 107cc4f990335885294f9b13d51dde52b5f0f868 Mon Sep 17 00:00:00 2001 From: Fabian Date: Sat, 26 Nov 2022 11:38:23 +0100 Subject: [PATCH] Fix win-arm64 build. --- src/Launcher.cs | 30 ++++++++++++++++++++++++++---- src/ModLoader.cs | 2 ++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Launcher.cs b/src/Launcher.cs index 5b2a6af..e6facf0 100644 --- a/src/Launcher.cs +++ b/src/Launcher.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.CommandLine.Parsing; +using System.Reflection.PortableExecutable; using static Arctium.WoW.Launcher.Misc.Helpers; @@ -157,7 +158,7 @@ class Launcher NativeWindows.NtResumeProcess(processInfo.ProcessHandle); - WaitForUnpack(ref processInfo, memory, ref mbi); + WaitForUnpack(ref processInfo, memory, ref mbi, gameAppData); #if x64 Task.WaitAll(new[] @@ -204,9 +205,9 @@ class Launcher #elif ARM64 Task.WaitAll(new[] { - memory.QueuePatch(Patterns.Windows.CertBundle, Patches.Windows.CertBundle, "CertBundle", 19), + memory.QueuePatch(Patterns.Windows.CertBundle, Patches.Windows.Branch, "CertBundle", 19), memory.QueuePatch(Patterns.Windows.CertCommonName, Patches.Windows.CertCommonName, "CertCommonName", 6), - }, Program.CancellationTokenSource.Token); + }, CancellationTokenSource.Token); #endif NativeWindows.NtResumeProcess(processInfo.ProcessHandle); @@ -251,6 +252,7 @@ class Launcher static long GenerateAuthSeedFunctionPatch(WinMemory memory, long modulusOffset) { +#if x64 var authSeedLoadOffset = memory.Data.FindPattern(Patterns.Windows.AuthSeed); if (authSeedLoadOffset == 0) @@ -267,10 +269,14 @@ class Launcher Unsafe.WriteUnaligned(ref Patches.Windows.AuthSeed[3], (uint)(modulusOffset - authSeedFunctionOffset - 7)); return authSeedFunctionOffset; +#else + throw new NotImplementedException(); +#endif } - static void WaitForUnpack(ref ProcessInformation processInfo, WinMemory memory, ref MemoryBasicInformation mbi) + static void WaitForUnpack(ref ProcessInformation processInfo, WinMemory memory, ref MemoryBasicInformation mbi, Stream gameAppData) { +#if x64 // Wait for client initialization. var initOffset = memory?.Read(mbi.BaseAddress, (int)mbi.RegionSize)?.FindPattern(Patterns.Windows.Init) ?? 0; @@ -286,7 +292,23 @@ class Launcher while (memory?.Read(initOffset + memory.BaseAddress, 1)?[0] == null || memory?.Read(initOffset + memory.BaseAddress, 1)?[0] == 0) memory.Data = memory.Read(mbi.BaseAddress, (int)mbi.RegionSize); +#else + // Get PE header info for client initialization. + var peHeaders = new PEHeaders(gameAppData); + SectionHeader textSectionHeader = peHeaders.SectionHeaders.Single(sectionHeader => sectionHeader.Name.ToLower() == ".text"); + + gameAppData.Position = textSectionHeader.VirtualSize + textSectionHeader.PointerToRawData; + + var textSectionEndValue = gameAppData.ReadByte(); + + Console.WriteLine("Waiting for client initialization..."); + + var virtualTextSectionEnd = memory.BaseAddress + textSectionHeader.VirtualAddress + textSectionHeader.VirtualSize; + + while (memory?.Read(virtualTextSectionEnd, 1)?[0] == null || memory?.Read(virtualTextSectionEnd, 1)?[0] == textSectionEndValue) + Thread.Sleep(100); +#endif PrepareAntiCrash(memory, ref mbi, ref processInfo); memory.RefreshMemoryData((int)mbi.RegionSize); diff --git a/src/ModLoader.cs b/src/ModLoader.cs index 5c4dad0..083ad6a 100644 --- a/src/ModLoader.cs +++ b/src/ModLoader.cs @@ -3,6 +3,7 @@ namespace Arctium.WoW.Launcher; +#if x64 class ModLoader { static readonly HashSet loadedFileIds = new(); @@ -192,3 +193,4 @@ class ModLoader return (idAlloc, stringAlloc); } } +#endif