Created
August 14, 2019 21:04
-
-
Save dafzor/4d4964ef8753e6a992ec6691ce974cf0 to your computer and use it in GitHub Desktop.
Proof of concept for launching World of Warcraft Classic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Runtime.InteropServices; | |
using System.Text; | |
using System.Threading; | |
using System.Windows.Forms; | |
namespace ProofOfConcept | |
{ | |
class Program | |
{ | |
[DllImport("user32.dll")] | |
private static extern IntPtr GetForegroundWindow(); | |
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] | |
static extern int GetWindowTextLength(IntPtr hWnd); | |
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)] | |
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, | |
int nMaxCount); | |
static void Main(string[] args) | |
{ | |
// launch battle.net client with the parameters World of Warcraft Launcher.exe gives it, this will open the UI on the correct page | |
Process.Start("C:\\Program Files (x86)\\Battle.net\\Battle.net.exe", "--game=wow_enus --gamepath=\"G:\\World of Warcraft\" --productcode=wow_classic"); | |
while (true) | |
{ | |
// Check the foreground window title | |
IntPtr h = GetForegroundWindow(); | |
int len = GetWindowTextLength(h); | |
StringBuilder title = new StringBuilder(len + 1); | |
GetWindowText(h, title, title.Capacity); | |
Console.WriteLine(title.ToString()); | |
// if it's the battle.net client send the enter key to launch the game | |
if (title.ToString().Equals("Blizzard Battle.net")) | |
{ | |
SendKeys.SendWait("{ENTER}"); | |
return; | |
} | |
// unsire if i need to trottle down the foreground check or not | |
// Thread.Sleep(100); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment