public static IEnumerable <WinHandle> FindWindows(Predicate <WinHandle> pred)
        {
            if (pred == null)
            {
                throw new ArgumentNullException(nameof(pred));
            }

            List <WinHandle> winList = null;

            NtApi.EnumWindows((ptr, lp) =>
            {
                var win = new WinHandle(ptr);

                if (pred.Invoke(win))
                {
                    if (winList == null)
                    {
                        winList = new List <WinHandle>();
                    }
                    winList.Add(win);
                }

                return(NtApi.EnumWindowsContinueEnumerating);
            }, IntPtr.Zero);

            return(winList ?? Enumerable.Empty <WinHandle>());
        }
 public static WinHandle SendKey(this WinHandle win, char c)
 {
     if (NtApi.GetForegroundWindow() != win.Handle)
     {
         NtApi.SetForegroundWindow(win.Handle);
     }
     WinSendKeys.SendWait(c.ToString());
     return(win);
 }
        public IntPtr GetSteamWarningWindow()
        {
            var hwnd = NtApi.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "vguiPopupWindow", @"Steam —");

            if (hwnd == IntPtr.Zero)
            {
                hwnd = NtApi.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "vguiPopupWindow", "Steam - ");
            }
            return(hwnd);
        }
        public IntPtr GetSteamMainWindow()
        {
            var steamHwnd = NtApi.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "vguiPopupWindow", "Steam");

            if (steamHwnd == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }
            var cef = NtApi.FindWindowEx(steamHwnd, IntPtr.Zero, "CefBrowserWindow", "");

            return(cef);
        }
        //some shitty extensions pls

        public static string GetWindowText(this WinHandle win)
        {
            var size = NtApi.GetWindowTextLength(win.Handle);

            if (size > 0)
            {
                var sb = new StringBuilder(size + 1); // +1 [size+1] = '\0';
                NtApi.GetWindowText(win.Handle, sb, sb.Capacity);
                return(sb.ToString());
            }

            return(string.Empty);
        }
        public static string GetClassName(this WinHandle win)
        {
            var           limit = 255;
            var           aSize = 0;
            StringBuilder sb;

            do
            {
                sb     = new StringBuilder(limit);
                aSize  = NtApi.GetClassName(win.Handle, sb, sb.Capacity);
                aSize *= 2;
            } while (aSize == limit - 1);

            return(sb.ToString());
        }
        public static WinHandle SendKeys(this WinHandle win, string text, bool sendCharbyChar = false,
                                         int interval = 10)
        {
            if (sendCharbyChar)
            {
                foreach (var c in text)
                {
                    Thread.Sleep(interval);
                    win.SendKey(c);
                }
            }
            else
            {
                if (NtApi.GetForegroundWindow() != win.Handle)
                {
                    NtApi.SetForegroundWindow(win.Handle);
                }
                WinSendKeys.SendWait(text);
            }

            return(win);
        }
        public static WinHandle FindWindow(Predicate <WinHandle> pred)
        {
            if (pred == null)
            {
                throw new ArgumentNullException(nameof(pred));
            }

            var ret = WinHandle.Invalid;

            NtApi.EnumWindows((ptr, lp) =>
            {
                var win = new WinHandle(ptr);
                if (pred.Invoke(win))
                {
                    ret = win;
                    return(NtApi.EnumWindowsStopEnumerating);
                }

                return(NtApi.EnumWindowsContinueEnumerating);
            }, IntPtr.Zero);

            return(ret);
        }
        public void DoLogin(SteamUser login)
        {
            Task.Run(() =>
            {
                var calledShutdown = false;
                while (IsOnSteamGuard() || IsOnMainWindow() || IsOnLogin())
                {
                    if (!calledShutdown)
                    {
                        calledShutdown = true;
                        Shutdown();
                    }

                    Thread.Sleep(10);
                }

                Process.Start(new ProcessStartInfo(GetSteamPath(), $"-login {login.Username} {login.Password}"));

                while (!IsOnLogin() || Process.GetProcessesByName("Steam").Length == 0)
                {
                    Thread.Sleep(10);
                }

                while (IsOnSteamGuard() && !IsOnMainWindow())
                {
                    Thread.Sleep(250); // CPU Saving and window timing
                    //Do steam guard job here
                    var sgHwnd = GetSteamGuardWindow();

                    if (NtApi.GetForegroundWindow() != sgHwnd)
                    {
                        NtApi.SetForegroundWindow(sgHwnd);
                    }

                    var pId           = 0;
                    var attempts      = 0;
                    var attemptsLimit = 10;

                    while ((attempts < attemptsLimit) & (pId == 0))
                    {
                        NtApi.GetWindowThreadProcessId(sgHwnd, out pId);
                        Thread.Sleep(250);
                        attempts++;
                    }

                    new WinHandle(sgHwnd).SendKeys(login.SteamGuard.GenerateSteamGuardCode());

                    NtApi.SetForegroundWindow(sgHwnd);

                    SendKeys.SendWait("{ENTER}");

                    Thread.Sleep(
                        5000); // i think 5 seconds is enough hmm (3 seconds sometimes send another key command)
                    if (!IsOnSteamGuard())
                    {
                        break;
                    }
                }

                //continue to main window gg!
            });
        }
Beispiel #10
0
 public IntPtr GetSteamLoginWindow()
 {
     return(NtApi.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "vguiPopupWindow", "Steam Login"));
 }
 public static bool IsVisible(this WinHandle win)
 {
     return(NtApi.IsWindowVisible(win.Handle));
 }
 public static WinHandle GetForegroundWindow()
 {
     return(new WinHandle(NtApi.GetForegroundWindow()));
 }