M NosTaleGfless/NostaleLauncher.cs => NosTaleGfless/NostaleLauncher.cs +29 -0
@@ 1,6 1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
using System.Diagnostics;
using System.IO;
using System.Threading;
@@ 27,6 29,33 @@ namespace NosTaleGfless
NostaleProcess process = RunProcess(account, nostalePath);
process.Initialized = ProcessPipeServer(process, sessionToken).GetAwaiter().GetResult();
+ if (process.Initialized)
+ {
+ while (true)
+ {
+ List<IntPtr> handles = new List<IntPtr>();
+
+ // wait for main window open
+ User32.EnumDesktopWindows(IntPtr.Zero, (hWnd, lParam) =>
+ {
+ User32.GetWindowThreadProcessId(hWnd, out uint processId);
+ if (processId == process.ProcessId)
+ {
+ handles.Add(hWnd);
+ }
+
+ return true;
+ }, IntPtr.Zero);
+
+ if (handles.Count > 6)
+ {
+ break;
+ }
+
+ Task.Delay(50).GetAwaiter().GetResult();
+ }
+ }
+
return process;
}
});
A NosTaleGfless/User32.cs => NosTaleGfless/User32.cs +28 -0
@@ 0,0 1,28 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace NosTaleGfless
+{
+ public class User32
+ {
+ [DllImport("user32.dll")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool IsWindowVisible(IntPtr hWnd);
+
+ [DllImport("user32.dll", EntryPoint = "GetWindowText",
+ ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
+ public static extern int GetWindowText(IntPtr hWnd,
+ StringBuilder lpWindowText, int nMaxCount);
+
+ [DllImport("user32.dll", EntryPoint = "EnumDesktopWindows",
+ ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
+ public static extern bool EnumDesktopWindows(IntPtr hDesktop,
+ EnumDelegate lpEnumCallbackFunction, IntPtr lParam);
+
+ [DllImport("user32.dll", SetLastError=true)]
+ public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
+
+ public delegate bool EnumDelegate(IntPtr hWnd, int lParam);
+ }
+}<
\ No newline at end of file