using System;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Win32;
namespace SC2GameStartSwitcher
{
class Program
{
//Import the FindWindow API to find our window
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindowNative(string className, string windowName);
//Import the SetForeground API to activate it
[DllImport("User32.dll", EntryPoint = "SetForegroundWindow")]
private static extern IntPtr SetForegroundWindowNative(IntPtr hWnd);
public static IntPtr FindWindow(string className, string windowName)
{
return FindWindowNative(className, windowName);
}
public static IntPtr SetForegroundWindow(IntPtr hWnd)
{
return SetForegroundWindowNative(hWnd);
}
public static void Activate(string title)
{
//Find the window, using the Window Title
IntPtr hWnd = FindWindow(null, title);
if (hWnd.ToInt32() > 0) //If found
{
SetForegroundWindow(hWnd); //Activate it
}
}
static void Main()
{
int gameState = 0;
RegistryKey MyReg = Registry.CurrentUser.OpenSubKey
("Software\\Razer\\Starcraft2", true);
MyReg.SetValue("APMValue", "1000");
Console.WriteLine("\nWelcome to the StarCraft II Automatic Game Start Switcher.\n");
Console.WriteLine("Game scanning initiated. Feel free to minimize this window.");
while (true)
{
if (gameState == 0) { // in menus
Thread.Sleep(2000); // pause for 2 seconds
if ((int)MyReg.GetValue("StartModule") == 1) {
gameState = 1;
}
} else if (gameState == 1) { // a game is loading
Thread.Sleep(10); // pause for 10 milliseconds
if (!MyReg.GetValue("APMValue").Equals("1000")) {
Activate("StarCraft II");
gameState = 2;
}
} else if (gameState == 2) { // in a game
Thread.Sleep(2000); // pause for 2 seconds
if ((int)MyReg.GetValue("StartModule") == 0) {
gameState = 0;
MyReg.SetValue("APMValue", "1000");
}
}
}
}
}
}