Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.9.9.40 #715

Merged
merged 5 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Daybreak.GWCA/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ endif()
set(VERSION_MAJOR 0)
set(VERSION_MINOR 9)
set(VERSION_PATCH 9)
set(VERSION_TWEAK 39)
set(VERSION_TWEAK 40)

set(VERSION_RC "${CMAKE_CURRENT_BINARY_DIR}/version.rc")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in" "${VERSION_RC}" @ONLY)
Expand Down
27 changes: 0 additions & 27 deletions Daybreak/Configuration/Options/PriceCheckerOptions.cs

This file was deleted.

5 changes: 0 additions & 5 deletions Daybreak/Configuration/ProjectConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@
using Daybreak.Services.ReShade.Notifications;
using Daybreak.Services.UBlockOrigin;
using Daybreak.Services.Browser;
using Daybreak.Services.PriceChecker;
using Daybreak.Services.PriceChecker.Models;
using Daybreak.Services.ApplicationArguments;
using Daybreak.Services.ApplicationArguments.ArgumentHandling;

Expand Down Expand Up @@ -267,7 +265,6 @@ public override void RegisterServices(IServiceCollection services)
services.AddScoped<ILaunchConfigurationService, LaunchConfigurationService>();
services.AddScoped<IBrowserHistoryManager, BrowserHistoryManager>();
services.AddScoped<IEventService, EventService>();
services.AddScoped<IPriceCheckerService, PriceCheckerService>();
services.AddScoped<IApplicationArgumentService, ApplicationArgumentService>();
services.AddScoped<IArgumentHandlerProducer, IApplicationArgumentService>(sp => sp.GetRequiredService<IApplicationArgumentService>());
}
Expand Down Expand Up @@ -433,7 +430,6 @@ public override void RegisterOptions(IOptionsProducer optionsProducer)
optionsProducer.RegisterOptions<ScreenManagerOptions>();
optionsProducer.RegisterOptions<KamadanTradeChatOptions>();
optionsProducer.RegisterOptions<AscalonTradeChatOptions>();
optionsProducer.RegisterOptions<PriceCheckerOptions>();
optionsProducer.RegisterOptions<LoggingOptions>();
optionsProducer.RegisterOptions<PriceHistoryOptions>();
optionsProducer.RegisterOptions<TraderQuotesOptions>();
Expand Down Expand Up @@ -490,6 +486,5 @@ private void RegisterLiteCollections(IServiceCollection services)
this.RegisterLiteCollection<TraderQuoteDTO, PriceHistoryOptions>(services);
this.RegisterLiteCollection<NotificationDTO, NotificationStorageOptions>(services);
this.RegisterLiteCollection<TraderMessageDTO, TraderMessagesOptions>(services);
this.RegisterLiteCollection<PriceCheckDTO, PriceCheckerOptions>(services);
}
}
2 changes: 1 addition & 1 deletion Daybreak/Daybreak.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<LangVersion>preview</LangVersion>
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
<Version>0.9.9.39</Version>
<Version>0.9.9.40</Version>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<UserSecretsId>cfb2a489-db80-448d-a969-80270f314c46</UserSecretsId>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
Expand Down
104 changes: 90 additions & 14 deletions Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ namespace Daybreak.Services.ApplicationLauncher;

internal sealed class ApplicationLauncher : IApplicationLauncher
{
private const int MaxRetries = 10;
private const string ProcessName = "gw";
private const string ArenaNetMutex = "AN-Mute";
private const double LaunchMemoryThreshold = 200000000;

private static readonly TimeSpan LaunchTimeout = TimeSpan.FromMinutes(1);

private readonly INotificationService notificationService;
private readonly ILiveOptions<LauncherOptions> launcherOptions;
Expand Down Expand Up @@ -317,31 +319,42 @@ public void RestartDaybreakAsNormalUser()
CloseHandle(clientHandle);
}

var retries = 0;
while (retries < MaxRetries)
var sw = Stopwatch.StartNew();
while (sw.Elapsed.TotalSeconds < LaunchTimeout.TotalSeconds)
{
await Task.Delay(1000);
retries++;
await Task.Delay(500);
var gwProcess = Process.GetProcessesByName("gw").FirstOrDefault();
if (gwProcess is null && retries < MaxRetries)
if (gwProcess is null)
{
continue;
}
else if (gwProcess is null && retries >= MaxRetries)

if (gwProcess!.MainWindowHandle == IntPtr.Zero)
{
throw new InvalidOperationException("Newly launched gw process not detected");
continue;
}

if (gwProcess!.MainWindowHandle == IntPtr.Zero)
var windows = GetRootWindowsOfProcess(gwProcess.Id)
.Select(root => (root, GetChildWindows(root)))
.SelectMany(tuple =>
{
tuple.Item2.Add(tuple.root);
return tuple.Item2;
})
.Select(GetWindowTitle).ToList();

/*
* Detect when the game window has shown. Because both the updater and the game window are called Guild Wars,
* we need to look at the other windows created by the process. Especially, we need to detect the input windows
* to check when the game is ready to accept input
*/
if (!windows.Contains("Guild Wars"))
{
continue;
}

int titleLength = NativeMethods.GetWindowTextLength(gwProcess.MainWindowHandle);
var titleBuffer = new StringBuilder(titleLength);
var readCount = NativeMethods.GetWindowText(gwProcess.MainWindowHandle, titleBuffer, titleLength + 1);
var title = titleBuffer.ToString();
if (title != "Guild Wars")
var virtualMemory = gwProcess.VirtualMemorySize64;
if (virtualMemory < LaunchMemoryThreshold)
{
continue;
}
Expand All @@ -353,6 +366,15 @@ public void RestartDaybreakAsNormalUser()
continue;
}

/*
* GW loads more than 110 modules when it starts properly. If there are less than
* 110 modules, GW probably has failed to start or has not started yet
*/
if (gwProcess.Modules.Count < 110)
{
continue;
}

/*
* Run the actions one by one, to avoid injection issues
*/
Expand Down Expand Up @@ -727,4 +749,58 @@ private static IntPtr GetProcessModuleBase(IntPtr process)

return peb.ImageBaseAddress + 0x1000;
}

private static List<IntPtr> GetRootWindowsOfProcess(int pid)
{
var rootWindows = GetChildWindows(IntPtr.Zero);
var dsProcRootWindows = new List<IntPtr>();
foreach (IntPtr hWnd in rootWindows)
{
_ = GetWindowThreadProcessId(hWnd, out var lpdwProcessId);
if (lpdwProcessId == pid)
dsProcRootWindows.Add(hWnd);
}

return dsProcRootWindows;
}

private static List<IntPtr> GetChildWindows(IntPtr parent)
{
var result = new List<IntPtr>();
var listHandle = GCHandle.Alloc(result);
try
{
Win32Callback childProc = new Win32Callback(EnumWindow);
EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle));
}
finally
{
if (listHandle.IsAllocated)
listHandle.Free();
}

return result;
}

private static string GetWindowTitle(IntPtr hwnd)
{
var titleLength = NativeMethods.GetWindowTextLength(hwnd);
var titleBuffer = new StringBuilder(titleLength);
_ = NativeMethods.GetWindowText(hwnd, titleBuffer, titleLength + 1);
var title = titleBuffer.ToString();

return title;
}

private static bool EnumWindow(IntPtr handle, IntPtr pointer)
{
var gch = GCHandle.FromIntPtr(pointer);
if (gch.Target is not List<IntPtr> list)
{
return false;
}

list.Add(handle);
return true;
}
}

This file was deleted.

Loading
Loading