Code format
This commit is contained in:
@@ -7,205 +7,213 @@ using System.Windows.Forms;
|
|||||||
namespace DD2Switcher;
|
namespace DD2Switcher;
|
||||||
|
|
||||||
internal static class Program {
|
internal static class Program {
|
||||||
private static List<Process> processes = new();
|
private static List<Process> processes = new();
|
||||||
|
|
||||||
private static Process activeProcess;
|
private static Process activeProcess;
|
||||||
private static readonly IntPtr defaultAffinity = new(0xFF000000);
|
private static readonly IntPtr defaultAffinity = new(0xFF000000);
|
||||||
private static readonly IntPtr fullAffinity = new(0xFFFFFFFF);
|
private static readonly IntPtr fullAffinity = new(0xFFFFFFFF);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern IntPtr GetForegroundWindow();
|
public static extern IntPtr GetForegroundWindow();
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||||
|
|
||||||
[DllImport("kernel32.dll", SetLastError = true)]
|
[DllImport("kernel32.dll", SetLastError = true)]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
static extern bool AllocConsole();
|
static extern bool AllocConsole();
|
||||||
|
|
||||||
private static void AdjustAffinities() {
|
private static void AdjustAffinities() {
|
||||||
List<Process> fuckedProcesses = new();
|
List<Process> fuckedProcesses = new();
|
||||||
|
|
||||||
foreach (var process in processes)
|
foreach (var process in processes)
|
||||||
if (process != activeProcess) {
|
if (process != activeProcess) {
|
||||||
try {
|
try {
|
||||||
process.ProcessorAffinity = defaultAffinity;
|
process.ProcessorAffinity = defaultAffinity;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
fuckedProcesses.Add(process);
|
fuckedProcesses.Add(process);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
activeProcess.ProcessorAffinity = fullAffinity;
|
activeProcess.ProcessorAffinity = fullAffinity;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
fuckedProcesses.Add(activeProcess);
|
fuckedProcesses.Add(activeProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var fucked in fuckedProcesses)
|
foreach (var fucked in fuckedProcesses)
|
||||||
processes.Remove(fucked);
|
processes.Remove(fucked);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AdjustPriorities() {
|
private static void AdjustPriorities() {
|
||||||
List<Process> fuckedProcesses = new();
|
List<Process> fuckedProcesses = new();
|
||||||
|
|
||||||
foreach (var process in processes) {
|
foreach (var process in processes) {
|
||||||
try {
|
try {
|
||||||
process.PriorityClass = ProcessPriorityClass.Idle;
|
process.PriorityClass = ProcessPriorityClass.Idle;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
fuckedProcesses.Add(process);
|
fuckedProcesses.Add(process);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
activeProcess.PriorityClass = ProcessPriorityClass.High;
|
activeProcess.PriorityClass = ProcessPriorityClass.High;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
fuckedProcesses.Add(activeProcess);
|
fuckedProcesses.Add(activeProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var fucked in fuckedProcesses)
|
foreach (var fucked in fuckedProcesses)
|
||||||
processes.Remove(fucked);
|
processes.Remove(fucked);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SwitchToProcess(int index) {
|
private static void SwitchToProcess(int index) {
|
||||||
Console.WriteLine("Switching to process at index " + index);
|
Console.WriteLine("Switching to process at index " + index);
|
||||||
if (index >= processes.Count) return;
|
if (index >= processes.Count) return;
|
||||||
var targetWindowHandle = processes[processes.Count - 1 - index].MainWindowHandle;
|
var targetWindowHandle = processes[processes.Count - 1 - index].MainWindowHandle;
|
||||||
if (targetWindowHandle == IntPtr.Zero) {
|
if (targetWindowHandle == IntPtr.Zero) {
|
||||||
processes.RemoveAt(processes.Count - 1 - index);
|
processes.RemoveAt(processes.Count - 1 - index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SetForegroundWindow(targetWindowHandle);
|
|
||||||
activeProcess = processes[processes.Count - 1 - index];
|
|
||||||
AdjustAffinities();
|
|
||||||
AdjustPriorities();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void SwitchMainGame() {
|
SetForegroundWindow(targetWindowHandle);
|
||||||
var foregroundWindow = GetForegroundWindow();
|
activeProcess = processes[processes.Count - 1 - index];
|
||||||
Process foregroundGame = null;
|
AdjustAffinities();
|
||||||
var foregroundGameIndex = -1;
|
AdjustPriorities();
|
||||||
var exists = false;
|
}
|
||||||
|
|
||||||
foreach (var process in processes)
|
private static void SwitchMainGame() {
|
||||||
if (foregroundWindow == process.MainWindowHandle) {
|
var foregroundWindow = GetForegroundWindow();
|
||||||
exists = true;
|
Process foregroundGame = null;
|
||||||
foregroundGame = process;
|
var foregroundGameIndex = -1;
|
||||||
foregroundGameIndex = processes.IndexOf(process);
|
var exists = false;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exists) {
|
foreach (var process in processes)
|
||||||
var tempGame = processes[0];
|
if (foregroundWindow == process.MainWindowHandle) {
|
||||||
processes[0] = foregroundGame;
|
exists = true;
|
||||||
processes[foregroundGameIndex] = tempGame;
|
foregroundGame = process;
|
||||||
}
|
foregroundGameIndex = processes.IndexOf(process);
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
private static void ToggleGame() {
|
if (exists) {
|
||||||
Console.WriteLine("Toggling foreground window as tracked...");
|
var tempGame = processes[0];
|
||||||
var foregroundWindow = GetForegroundWindow();
|
processes[0] = foregroundGame;
|
||||||
var systemProcesses = Process.GetProcesses();
|
processes[foregroundGameIndex] = tempGame;
|
||||||
Process foregroundProcess = null;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var process in systemProcesses)
|
private static void ToggleGame() {
|
||||||
if (foregroundWindow == process.MainWindowHandle) {
|
Console.WriteLine("Toggling foreground window as tracked...");
|
||||||
foregroundProcess = process;
|
var foregroundWindow = GetForegroundWindow();
|
||||||
break;
|
var systemProcesses = Process.GetProcesses();
|
||||||
}
|
Process foregroundProcess = null;
|
||||||
|
|
||||||
if (foregroundProcess == null) return;
|
foreach (var process in systemProcesses)
|
||||||
Console.WriteLine("Foreground process: " + foregroundProcess.ProcessName);
|
if (foregroundWindow == process.MainWindowHandle) {
|
||||||
var existingProcess = processes.Find(process => process.Id == foregroundProcess.Id);
|
foregroundProcess = process;
|
||||||
if (existingProcess != null) {
|
break;
|
||||||
Console.WriteLine("Removing foreground process from tracked...");
|
}
|
||||||
processes.Remove(existingProcess);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Console.WriteLine("Adding foreground process to tracked...");
|
|
||||||
processes.Add(foregroundProcess);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[STAThread]
|
if (foregroundProcess == null) return;
|
||||||
private static void Main() {
|
Console.WriteLine("Foreground process: " + foregroundProcess.ProcessName);
|
||||||
// AllocConsole();
|
var existingProcess = processes.Find(process => process.Id == foregroundProcess.Id);
|
||||||
|
if (existingProcess != null) {
|
||||||
|
Console.WriteLine("Removing foreground process from tracked...");
|
||||||
|
processes.Remove(existingProcess);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Console.WriteLine("Adding foreground process to tracked...");
|
||||||
|
processes.Add(foregroundProcess);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var processes = Process.GetProcesses();
|
[STAThread]
|
||||||
var currentProcess = Process.GetCurrentProcess();
|
private static void Main() {
|
||||||
|
// AllocConsole();
|
||||||
|
|
||||||
foreach (var process in processes)
|
var processes = Process.GetProcesses();
|
||||||
if (process.Id != currentProcess.Id && process.ProcessName == currentProcess.ProcessName) {
|
var currentProcess = Process.GetCurrentProcess();
|
||||||
process.Kill();
|
|
||||||
Process.GetCurrentProcess().Kill();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
foreach (var process in processes)
|
||||||
HotKeyManager.RegisterHotKey(Keys.D1, KeyModifiers.Alt);
|
if (process.Id != currentProcess.Id && process.ProcessName == currentProcess.ProcessName) {
|
||||||
HotKeyManager.RegisterHotKey(Keys.D2, KeyModifiers.Alt);
|
process.Kill();
|
||||||
HotKeyManager.RegisterHotKey(Keys.D3, KeyModifiers.Alt);
|
Process.GetCurrentProcess().Kill();
|
||||||
HotKeyManager.RegisterHotKey(Keys.D4, KeyModifiers.Alt);
|
}
|
||||||
HotKeyManager.RegisterHotKey(Keys.D5, KeyModifiers.Alt);
|
|
||||||
HotKeyManager.RegisterHotKey(Keys.D6, KeyModifiers.Alt);
|
|
||||||
HotKeyManager.RegisterHotKey(Keys.D7, KeyModifiers.Alt);
|
|
||||||
HotKeyManager.RegisterHotKey(Keys.D8, KeyModifiers.Alt);
|
|
||||||
HotKeyManager.RegisterHotKey(Keys.D9, KeyModifiers.Alt);
|
|
||||||
|
|
||||||
HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Alt);
|
|
||||||
|
|
||||||
// HotKeyManager.RegisterHotKey(Keys.Q, KeyModifiers.Alt);
|
|
||||||
// HotKeyManager.RegisterHotKey(Keys.W, KeyModifiers.Alt);
|
|
||||||
// HotKeyManager.RegisterHotKey(Keys.R, KeyModifiers.Alt);
|
|
||||||
HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed;
|
|
||||||
|
|
||||||
var pixelList = new System.Collections.Generic.List<Pixel>();
|
|
||||||
// pixelList.Add(new Pixel(1401, 1234, 224, 224, 224));
|
|
||||||
pixelList.Add(new Pixel(1359, 1235, 220, 220, 220));
|
|
||||||
|
|
||||||
static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) {
|
|
||||||
switch (e.Key) {
|
|
||||||
case Keys.D1:
|
|
||||||
SwitchToProcess(0);
|
|
||||||
break;
|
|
||||||
case Keys.D2:
|
|
||||||
SwitchToProcess(1);
|
|
||||||
break;
|
|
||||||
case Keys.D3:
|
|
||||||
SwitchToProcess(2);
|
|
||||||
break;
|
|
||||||
case Keys.D4:
|
|
||||||
SwitchToProcess(3);
|
|
||||||
break;
|
|
||||||
case Keys.D5:
|
|
||||||
SwitchToProcess(4);
|
|
||||||
break;
|
|
||||||
case Keys.D6:
|
|
||||||
SwitchToProcess(5);
|
|
||||||
break;
|
|
||||||
case Keys.D7:
|
|
||||||
SwitchToProcess(6);
|
|
||||||
break;
|
|
||||||
case Keys.D8:
|
|
||||||
SwitchToProcess(7);
|
|
||||||
break;
|
|
||||||
case Keys.D9:
|
|
||||||
SwitchToProcess(8);
|
|
||||||
break;
|
|
||||||
case Keys.Oemtilde:
|
|
||||||
ToggleGame();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Console.CancelKeyPress += (sender, e) => {
|
HotKeyManager.RegisterHotKey(Keys.D1, KeyModifiers.Alt);
|
||||||
Process.GetCurrentProcess().Kill();
|
HotKeyManager.RegisterHotKey(Keys.D2, KeyModifiers.Alt);
|
||||||
};
|
HotKeyManager.RegisterHotKey(Keys.D3, KeyModifiers.Alt);
|
||||||
while (true)
|
HotKeyManager.RegisterHotKey(Keys.D4, KeyModifiers.Alt);
|
||||||
System.Threading.Thread.Sleep(100000);
|
HotKeyManager.RegisterHotKey(Keys.D5, KeyModifiers.Alt);
|
||||||
|
HotKeyManager.RegisterHotKey(Keys.D6, KeyModifiers.Alt);
|
||||||
|
HotKeyManager.RegisterHotKey(Keys.D7, KeyModifiers.Alt);
|
||||||
|
HotKeyManager.RegisterHotKey(Keys.D8, KeyModifiers.Alt);
|
||||||
|
HotKeyManager.RegisterHotKey(Keys.D9, KeyModifiers.Alt);
|
||||||
|
|
||||||
}
|
HotKeyManager.RegisterHotKey(Keys.D1, KeyModifiers.Alt | KeyModifiers.Shift);
|
||||||
}
|
HotKeyManager.RegisterHotKey(Keys.D2, KeyModifiers.Alt | KeyModifiers.Shift);
|
||||||
|
HotKeyManager.RegisterHotKey(Keys.D3, KeyModifiers.Alt | KeyModifiers.Shift);
|
||||||
|
HotKeyManager.RegisterHotKey(Keys.D4, KeyModifiers.Alt | KeyModifiers.Shift);
|
||||||
|
HotKeyManager.RegisterHotKey(Keys.D5, KeyModifiers.Alt | KeyModifiers.Shift);
|
||||||
|
HotKeyManager.RegisterHotKey(Keys.D6, KeyModifiers.Alt | KeyModifiers.Shift);
|
||||||
|
HotKeyManager.RegisterHotKey(Keys.D7, KeyModifiers.Alt | KeyModifiers.Shift);
|
||||||
|
HotKeyManager.RegisterHotKey(Keys.D8, KeyModifiers.Alt | KeyModifiers.Shift);
|
||||||
|
HotKeyManager.RegisterHotKey(Keys.D9, KeyModifiers.Alt | KeyModifiers.Shift);
|
||||||
|
|
||||||
|
HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Alt);
|
||||||
|
|
||||||
|
// HotKeyManager.RegisterHotKey(Keys.Q, KeyModifiers.Alt);
|
||||||
|
// HotKeyManager.RegisterHotKey(Keys.W, KeyModifiers.Alt);
|
||||||
|
// HotKeyManager.RegisterHotKey(Keys.R, KeyModifiers.Alt);
|
||||||
|
HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed;
|
||||||
|
|
||||||
|
var pixelList = new System.Collections.Generic.List<Pixel>();
|
||||||
|
// pixelList.Add(new Pixel(1401, 1234, 224, 224, 224));
|
||||||
|
pixelList.Add(new Pixel(1359, 1235, 220, 220, 220));
|
||||||
|
|
||||||
|
static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) {
|
||||||
|
switch (e.Key) {
|
||||||
|
case Keys.D1:
|
||||||
|
SwitchToProcess(0);
|
||||||
|
break;
|
||||||
|
case Keys.D2:
|
||||||
|
SwitchToProcess(1);
|
||||||
|
break;
|
||||||
|
case Keys.D3:
|
||||||
|
SwitchToProcess(2);
|
||||||
|
break;
|
||||||
|
case Keys.D4:
|
||||||
|
SwitchToProcess(3);
|
||||||
|
break;
|
||||||
|
case Keys.D5:
|
||||||
|
SwitchToProcess(4);
|
||||||
|
break;
|
||||||
|
case Keys.D6:
|
||||||
|
SwitchToProcess(5);
|
||||||
|
break;
|
||||||
|
case Keys.D7:
|
||||||
|
SwitchToProcess(6);
|
||||||
|
break;
|
||||||
|
case Keys.D8:
|
||||||
|
SwitchToProcess(7);
|
||||||
|
break;
|
||||||
|
case Keys.D9:
|
||||||
|
SwitchToProcess(8);
|
||||||
|
break;
|
||||||
|
case Keys.Oemtilde:
|
||||||
|
ToggleGame();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Console.CancelKeyPress += (sender, e) => { Process.GetCurrentProcess().Kill(); };
|
||||||
|
while (true)
|
||||||
|
System.Threading.Thread.Sleep(100000);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user