diff --git a/.gitignore b/.gitignore
index a6c2861..f450f81 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
-.idea
-**/Debug
-**/Properties
\ No newline at end of file
+.idea
+**/Debug
+**/Properties
+obj
+bin
\ No newline at end of file
diff --git a/DD2Switcher.sln b/DD2Switcher.sln
index 34f425b..6001d6b 100644
--- a/DD2Switcher.sln
+++ b/DD2Switcher.sln
@@ -1,16 +1,16 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DD2Switcher", "DD2Switcher\DD2Switcher.csproj", "{2AC26899-8E27-4B96-85A9-C387186EAD27}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {2AC26899-8E27-4B96-85A9-C387186EAD27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {2AC26899-8E27-4B96-85A9-C387186EAD27}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {2AC26899-8E27-4B96-85A9-C387186EAD27}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {2AC26899-8E27-4B96-85A9-C387186EAD27}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
-EndGlobal
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DD2Switcher", "DD2Switcher\DD2Switcher.csproj", "{2AC26899-8E27-4B96-85A9-C387186EAD27}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {2AC26899-8E27-4B96-85A9-C387186EAD27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2AC26899-8E27-4B96-85A9-C387186EAD27}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2AC26899-8E27-4B96-85A9-C387186EAD27}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2AC26899-8E27-4B96-85A9-C387186EAD27}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+EndGlobal
diff --git a/DD2Switcher.sln.DotSettings.user b/DD2Switcher.sln.DotSettings.user
index f591ba1..7c3bbf1 100644
--- a/DD2Switcher.sln.DotSettings.user
+++ b/DD2Switcher.sln.DotSettings.user
@@ -1,2 +1,5 @@
- INFO
\ No newline at end of file
+ INFO
+ C:\Users\Administrator\AppData\Local\JetBrains\Toolbox\apps\Rider\ch-0\231.8109.212\tools\MSBuild\Current\Bin\amd64\MSBuild.exe
+
+
\ No newline at end of file
diff --git a/DD2Switcher/App.config b/DD2Switcher/App.config
index 8ec5bdd..69f9d64 100644
--- a/DD2Switcher/App.config
+++ b/DD2Switcher/App.config
@@ -1,6 +1,6 @@
-
-
-
-
-
+
+
+
+
+
\ No newline at end of file
diff --git a/DD2Switcher/DD2Switcher.csproj b/DD2Switcher/DD2Switcher.csproj
index 3db0316..1f8ff78 100644
--- a/DD2Switcher/DD2Switcher.csproj
+++ b/DD2Switcher/DD2Switcher.csproj
@@ -1,88 +1,88 @@
-
-
-
-
- Debug
- AnyCPU
- {2AC26899-8E27-4B96-85A9-C387186EAD27}
- WinExe
- DD2Switcher
- DD2Switcher
- v4.8.1
- 512
- true
- true
- 10
-
-
- x64
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- x64
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Form
-
-
- Form1.cs
-
-
-
-
-
-
- ResXFileCodeGenerator
- Resources.Designer.cs
- Designer
-
-
- True
- Resources.resx
-
-
- SettingsSingleFileGenerator
- Settings.Designer.cs
-
-
- True
- Settings.settings
- True
-
-
-
-
-
-
-
-
-
+
+
+
+
+ Debug
+ AnyCPU
+ {2AC26899-8E27-4B96-85A9-C387186EAD27}
+ WinExe
+ DD2Switcher
+ DD2Switcher
+ v4.8.1
+ 512
+ true
+ true
+ 10
+
+
+ x64
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+ false
+
+
+ x64
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Form
+
+
+ Form1.cs
+
+
+
+
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+ Designer
+
+
+ True
+ Resources.resx
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+ True
+ Settings.settings
+ True
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DD2Switcher/Form1.Designer.cs b/DD2Switcher/Form1.Designer.cs
index 9a8be34..554befa 100644
--- a/DD2Switcher/Form1.Designer.cs
+++ b/DD2Switcher/Form1.Designer.cs
@@ -1,40 +1,40 @@
-namespace DD2Switcher
-{
- partial class Form1
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
-
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Text = "Form1";
- }
-
- #endregion
- }
+namespace DD2Switcher
+{
+ partial class Form1
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.components = new System.ComponentModel.Container();
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Text = "Form1";
+ }
+
+ #endregion
+ }
}
\ No newline at end of file
diff --git a/DD2Switcher/Form1.cs b/DD2Switcher/Form1.cs
index 4cd1087..9b0bd05 100644
--- a/DD2Switcher/Form1.cs
+++ b/DD2Switcher/Form1.cs
@@ -1,9 +1,9 @@
-using System.Windows.Forms;
-
-namespace DD2Switcher;
-
-public partial class Form1 : Form {
- public Form1() {
- InitializeComponent();
- }
+using System.Windows.Forms;
+
+namespace DD2Switcher;
+
+public partial class Form1 : Form {
+ public Form1() {
+ InitializeComponent();
+ }
}
\ No newline at end of file
diff --git a/DD2Switcher/HotKeyManager.cs b/DD2Switcher/HotKeyManager.cs
index ddf71d1..b554fbe 100644
--- a/DD2Switcher/HotKeyManager.cs
+++ b/DD2Switcher/HotKeyManager.cs
@@ -1,105 +1,105 @@
-using System;
-using System.Runtime.InteropServices;
-using System.Threading;
-using System.Windows.Forms;
-
-namespace DD2Switcher;
-
-public static class HotKeyManager {
- private static volatile MessageWindow _wnd;
- private static volatile IntPtr _hwnd;
- private static readonly ManualResetEvent _windowReadyEvent = new(false);
-
- private static int _id;
-
- static HotKeyManager() {
- var messageLoop = new Thread(delegate() { Application.Run(new MessageWindow()); });
- messageLoop.Name = "MessageLoopThread";
- messageLoop.IsBackground = true;
- messageLoop.Start();
- }
-
- public static event EventHandler HotKeyPressed;
-
- public static int RegisterHotKey(Keys key, KeyModifiers modifiers) {
- _windowReadyEvent.WaitOne();
- var id = Interlocked.Increment(ref _id);
- _wnd.Invoke(new RegisterHotKeyDelegate(RegisterHotKeyInternal), _hwnd, id, (uint)modifiers, (uint)key);
- return id;
- }
-
- public static void UnregisterHotKey(int id) {
- _wnd.Invoke(new UnRegisterHotKeyDelegate(UnRegisterHotKeyInternal), _hwnd, id);
- }
-
- private static void RegisterHotKeyInternal(IntPtr hwnd, int id, uint modifiers, uint key) {
- RegisterHotKey(hwnd, id, modifiers, key);
- }
-
- private static void UnRegisterHotKeyInternal(IntPtr hwnd, int id) {
- UnregisterHotKey(_hwnd, id);
- }
-
- private static void OnHotKeyPressed(HotKeyEventArgs e) {
- if (HotKeyPressed != null) HotKeyPressed(null, e);
- }
-
- [DllImport("user32", SetLastError = true)]
- private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
-
- [DllImport("user32", SetLastError = true)]
- private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
-
- private delegate void RegisterHotKeyDelegate(IntPtr hwnd, int id, uint modifiers, uint key);
-
- private delegate void UnRegisterHotKeyDelegate(IntPtr hwnd, int id);
-
- private class MessageWindow : Form {
- private const int WM_HOTKEY = 0x312;
-
- public MessageWindow() {
- _wnd = this;
- _hwnd = Handle;
- _windowReadyEvent.Set();
- }
-
- protected override void WndProc(ref Message m) {
- if (m.Msg == WM_HOTKEY) {
- var e = new HotKeyEventArgs(m.LParam);
- OnHotKeyPressed(e);
- }
-
- base.WndProc(ref m);
- }
-
- protected override void SetVisibleCore(bool value) {
- // Ensure the window never becomes visible
- base.SetVisibleCore(false);
- }
- }
-}
-
-public class HotKeyEventArgs : EventArgs {
- public readonly Keys Key;
- public readonly KeyModifiers Modifiers;
-
- public HotKeyEventArgs(Keys key, KeyModifiers modifiers) {
- Key = key;
- Modifiers = modifiers;
- }
-
- public HotKeyEventArgs(IntPtr hotKeyParam) {
- var param = (uint)hotKeyParam.ToInt64();
- Key = (Keys)((param & 0xffff0000) >> 16);
- Modifiers = (KeyModifiers)(param & 0x0000ffff);
- }
-}
-
-[Flags]
-public enum KeyModifiers {
- Alt = 1,
- Control = 2,
- Shift = 4,
- Windows = 8,
- NoRepeat = 0x4000
+using System;
+using System.Runtime.InteropServices;
+using System.Threading;
+using System.Windows.Forms;
+
+namespace DD2Switcher;
+
+public static class HotKeyManager {
+ private static volatile MessageWindow _wnd;
+ private static volatile IntPtr _hwnd;
+ private static readonly ManualResetEvent _windowReadyEvent = new(false);
+
+ private static int _id;
+
+ static HotKeyManager() {
+ var messageLoop = new Thread(delegate() { Application.Run(new MessageWindow()); });
+ messageLoop.Name = "MessageLoopThread";
+ messageLoop.IsBackground = true;
+ messageLoop.Start();
+ }
+
+ public static event EventHandler HotKeyPressed;
+
+ public static int RegisterHotKey(Keys key, KeyModifiers modifiers) {
+ _windowReadyEvent.WaitOne();
+ var id = Interlocked.Increment(ref _id);
+ _wnd.Invoke(new RegisterHotKeyDelegate(RegisterHotKeyInternal), _hwnd, id, (uint)modifiers, (uint)key);
+ return id;
+ }
+
+ public static void UnregisterHotKey(int id) {
+ _wnd.Invoke(new UnRegisterHotKeyDelegate(UnRegisterHotKeyInternal), _hwnd, id);
+ }
+
+ private static void RegisterHotKeyInternal(IntPtr hwnd, int id, uint modifiers, uint key) {
+ RegisterHotKey(hwnd, id, modifiers, key);
+ }
+
+ private static void UnRegisterHotKeyInternal(IntPtr hwnd, int id) {
+ UnregisterHotKey(_hwnd, id);
+ }
+
+ private static void OnHotKeyPressed(HotKeyEventArgs e) {
+ if (HotKeyPressed != null) HotKeyPressed(null, e);
+ }
+
+ [DllImport("user32", SetLastError = true)]
+ private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
+
+ [DllImport("user32", SetLastError = true)]
+ private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
+
+ private delegate void RegisterHotKeyDelegate(IntPtr hwnd, int id, uint modifiers, uint key);
+
+ private delegate void UnRegisterHotKeyDelegate(IntPtr hwnd, int id);
+
+ private class MessageWindow : Form {
+ private const int WM_HOTKEY = 0x312;
+
+ public MessageWindow() {
+ _wnd = this;
+ _hwnd = Handle;
+ _windowReadyEvent.Set();
+ }
+
+ protected override void WndProc(ref Message m) {
+ if (m.Msg == WM_HOTKEY) {
+ var e = new HotKeyEventArgs(m.LParam);
+ OnHotKeyPressed(e);
+ }
+
+ base.WndProc(ref m);
+ }
+
+ protected override void SetVisibleCore(bool value) {
+ // Ensure the window never becomes visible
+ base.SetVisibleCore(false);
+ }
+ }
+}
+
+public class HotKeyEventArgs : EventArgs {
+ public readonly Keys Key;
+ public readonly KeyModifiers Modifiers;
+
+ public HotKeyEventArgs(Keys key, KeyModifiers modifiers) {
+ Key = key;
+ Modifiers = modifiers;
+ }
+
+ public HotKeyEventArgs(IntPtr hotKeyParam) {
+ var param = (uint)hotKeyParam.ToInt64();
+ Key = (Keys)((param & 0xffff0000) >> 16);
+ Modifiers = (KeyModifiers)(param & 0x0000ffff);
+ }
+}
+
+[Flags]
+public enum KeyModifiers {
+ Alt = 1,
+ Control = 2,
+ Shift = 4,
+ Windows = 8,
+ NoRepeat = 0x4000
}
\ No newline at end of file
diff --git a/DD2Switcher/Pixel.cs b/DD2Switcher/Pixel.cs
index 1cf917f..6988065 100644
--- a/DD2Switcher/Pixel.cs
+++ b/DD2Switcher/Pixel.cs
@@ -1,25 +1,25 @@
-using System.Diagnostics;
-using System.Drawing;
-
-namespace DD2Switcher;
-
-public class Pixel {
- public Pixel(int x, int y, int R, int G, int B) {
- this.x = x;
- this.y = y;
- this.R = R;
- this.G = G;
- this.B = B;
- }
-
- private int x { get; }
- private int y { get; }
- private int R { get; }
- private int G { get; }
- private int B { get; }
-
- public bool ProcessBitmap(Bitmap bmp) {
- var tempPixel = bmp.GetPixel(x, y);
- return tempPixel.R >= R && tempPixel.B >= B && tempPixel.G >= G;
- }
+using System.Diagnostics;
+using System.Drawing;
+
+namespace DD2Switcher;
+
+public class Pixel {
+ public Pixel(int x, int y, int R, int G, int B) {
+ this.x = x;
+ this.y = y;
+ this.R = R;
+ this.G = G;
+ this.B = B;
+ }
+
+ private int x { get; }
+ private int y { get; }
+ private int R { get; }
+ private int G { get; }
+ private int B { get; }
+
+ public bool ProcessBitmap(Bitmap bmp) {
+ var tempPixel = bmp.GetPixel(x, y);
+ return tempPixel.R >= R && tempPixel.B >= B && tempPixel.G >= G;
+ }
}
\ No newline at end of file
diff --git a/DD2Switcher/Program.cs b/DD2Switcher/Program.cs
index aa04bc2..3d57d5a 100644
--- a/DD2Switcher/Program.cs
+++ b/DD2Switcher/Program.cs
@@ -1,222 +1,211 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Drawing;
-using System.Media;
-using System.Runtime.InteropServices;
-using System.Threading;
-using System.Windows.Forms;
-
-namespace DD2Switcher;
-
-internal static class Program {
- private static Rectangle rect = new(0, 0, 2560, 1440);
- private static readonly Process[] games = Process.GetProcessesByName("Dundefgame");
-
- private static readonly SoundPlayer beeper =
- new(@"C:\Users\Administrator\RiderProjects\DD2Switcher\DD2Switcher\beep.wav");
-
- private static Process activeGame = games[0];
- private static Bitmap screenshot;
- private static Graphics graphics;
- private static readonly IntPtr defaultAffinity = new(0xFF000000);
- private static readonly IntPtr fullAffinity = new(0xFFFFFFFF);
- private static bool paused = true;
-
- private static List relevantPoints = new List();
- private static List pointsToRemove = new List();
-
- [DllImport("user32.dll")]
- private static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, UIntPtr dwExtraInfo);
-
- [DllImport("user32.dll")]
- public static extern IntPtr GetForegroundWindow();
-
- [DllImport("user32.dll")]
- public static extern bool SetForegroundWindow(IntPtr hWnd);
-
- [DllImport("User32.dll", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- private static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);
-
- [DllImport("user32.dll")]
- private static extern bool GetWindowRect(IntPtr handle, ref Rectangle rect);
-
- [DllImport("user32.dll", SetLastError = true)]
- private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
-
- public static Bitmap CaptureWindow(IntPtr handle) {
- if (screenshot == null)
- screenshot = new Bitmap(rect.Width, rect.Height);
- graphics = Graphics.FromImage(screenshot);
- var hdc = graphics.GetHdc();
- PrintWindow(handle, hdc, 0);
- graphics.ReleaseHdc(hdc);
- return screenshot;
- }
-
- private static void AdjustAffinities() {
- foreach (var game in games)
- if (game != activeGame)
- game.ProcessorAffinity = defaultAffinity;
- activeGame.ProcessorAffinity = fullAffinity;
- }
-
- private static void AdjustPriorities() {
- foreach (var game in games) game.PriorityClass = ProcessPriorityClass.Idle;
- activeGame.PriorityClass = ProcessPriorityClass.High;
- }
-
- private static void NerfAll() {
- foreach (var game in games) {
- game.ProcessorAffinity = defaultAffinity;
- game.PriorityClass = ProcessPriorityClass.Idle;
- }
- }
-
- private static void BuffAll() {
- foreach (var game in games) {
- game.ProcessorAffinity = fullAffinity;
- game.PriorityClass = ProcessPriorityClass.Normal;
- }
- }
-
- private static void SwitchToGame(int index) {
- if (index >= games.Length) return;
- SetForegroundWindow(games[index].MainWindowHandle);
- activeGame = games[index];
- AdjustAffinities();
- AdjustPriorities();
- }
-
- private static void SwitchMainGame() {
- var foregroundWindow = GetForegroundWindow();
- Process foregroundGame = null;
- var foregroundGameIndex = -1;
- var exists = false;
-
- foreach (var game in games)
- if (foregroundWindow == game.MainWindowHandle) {
- exists = true;
- foregroundGame = game;
- foregroundGameIndex = Array.IndexOf(games, game);
- break;
- }
-
- if (exists) {
- var tempGame = games[0];
- games[0] = foregroundGame;
- games[foregroundGameIndex] = tempGame;
- }
- }
-
- [STAThread]
- private static void Main() {
- var processes = Process.GetProcesses();
- var currentProcess = Process.GetCurrentProcess();
-
- foreach (var process in processes)
- if (process.Id != currentProcess.Id && process.ProcessName == currentProcess.ProcessName)
- process.Kill();
-
- HotKeyManager.RegisterHotKey(Keys.D1, KeyModifiers.Alt);
- HotKeyManager.RegisterHotKey(Keys.D2, KeyModifiers.Alt);
- HotKeyManager.RegisterHotKey(Keys.D3, KeyModifiers.Alt);
- HotKeyManager.RegisterHotKey(Keys.D4, KeyModifiers.Alt);
- HotKeyManager.RegisterHotKey(Keys.D5, KeyModifiers.Alt);
- HotKeyManager.RegisterHotKey(Keys.D6, 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();
- // 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:
- SwitchToGame(0);
- break;
- case Keys.D2:
- SwitchToGame(1);
- break;
- case Keys.D3:
- SwitchToGame(2);
- break;
- case Keys.D4:
- SwitchToGame(3);
- break;
- case Keys.D5:
- SwitchMainGame();
- break;
- case Keys.D6:
- Environment.Exit(0);
- break;
- case Keys.W:
- if (paused) {
- beeper.Play();
- paused = false;
- }
- else {
- beeper.Play();
- Thread.Sleep(150);
- beeper.Play();
- paused = true;
- }
-
- break;
- }
- }
-
- while (true) {
- bool runOnce = false;
- bool AAA = false;
- relevantPoints.Clear();
- while (!paused) {
- screenshot = CaptureWindow(games[0].MainWindowHandle);
- // screenshot.Save("SS.png");
-
- // if (!runOnce) {
- // runOnce = true;
- // for (var y = 0; y < screenshot.Height; y++)
- // for (var x = 0; x < screenshot.Width; x++) {
- // var pixelColor = screenshot.GetPixel(x, y);
- // if (pixelColor.R > 220 && pixelColor.G > 220 && pixelColor.B > 220)
- // relevantPoints.Add(new Point(x, y));
- // }
- // }
- //
- // pointsToRemove.Clear();
- // foreach (var relevantPoint in relevantPoints) {
- // var pixel = screenshot.GetPixel(relevantPoint.X, relevantPoint.Y);
- // if (!(pixel.R > 220) || !(pixel.G > 220) || !(pixel.B > 220))
- // pointsToRemove.Add(relevantPoint);
- // }
- //
- // foreach (var point in pointsToRemove) {
- // relevantPoints.Remove(point);
- // }
- //
- // Debug.WriteLine(relevantPoints.Count);
-
- foreach (var p in pixelList)
- if (p.ProcessBitmap(screenshot)) {
- beeper.Play();
- break;
- }
-
- Thread.Sleep(250);
- }
-
- // System.IO.TextWriter tw = new System.IO.StreamWriter("SavedList.txt");
- // foreach (var point in relevantPoints) {
- // tw.WriteLine(point.ToString());
- // }
- // tw.Close();
-
- Thread.Sleep(250);
- }
- }
-}
\ No newline at end of file
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+using System.Windows.Forms;
+
+namespace DD2Switcher;
+
+internal static class Program {
+ private static List processes = new();
+
+ private static Process activeProcess;
+ private static readonly IntPtr defaultAffinity = new(0xFF000000);
+ private static readonly IntPtr fullAffinity = new(0xFFFFFFFF);
+
+ [DllImport("user32.dll")]
+ public static extern IntPtr GetForegroundWindow();
+
+ [DllImport("user32.dll")]
+ public static extern bool SetForegroundWindow(IntPtr hWnd);
+
+ [DllImport("kernel32.dll", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ static extern bool AllocConsole();
+
+ private static void AdjustAffinities() {
+ List fuckedProcesses = new();
+
+ foreach (var process in processes)
+ if (process != activeProcess) {
+ try {
+ process.ProcessorAffinity = defaultAffinity;
+ }
+ catch (Exception e) {
+ fuckedProcesses.Add(process);
+ }
+ }
+
+ try {
+ activeProcess.ProcessorAffinity = fullAffinity;
+ }
+ catch (Exception e) {
+ fuckedProcesses.Add(activeProcess);
+ }
+
+ foreach (var fucked in fuckedProcesses)
+ processes.Remove(fucked);
+ }
+
+ private static void AdjustPriorities() {
+ List fuckedProcesses = new();
+
+ foreach (var process in processes) {
+ try {
+ process.PriorityClass = ProcessPriorityClass.Idle;
+ }
+ catch (Exception e) {
+ fuckedProcesses.Add(process);
+ }
+ }
+
+ try {
+ activeProcess.PriorityClass = ProcessPriorityClass.High;
+ }
+ catch (Exception e) {
+ fuckedProcesses.Add(activeProcess);
+ }
+
+ foreach (var fucked in fuckedProcesses)
+ processes.Remove(fucked);
+ }
+
+ private static void SwitchToProcess(int index) {
+ Console.WriteLine("Switching to process at index " + index);
+ if (index >= processes.Count) return;
+ var targetWindowHandle = processes[processes.Count - 1 - index].MainWindowHandle;
+ if (targetWindowHandle == IntPtr.Zero) {
+ processes.RemoveAt(processes.Count - 1 - index);
+ return;
+ }
+ SetForegroundWindow(targetWindowHandle);
+ activeProcess = processes[processes.Count - 1 - index];
+ AdjustAffinities();
+ AdjustPriorities();
+ }
+
+ private static void SwitchMainGame() {
+ var foregroundWindow = GetForegroundWindow();
+ Process foregroundGame = null;
+ var foregroundGameIndex = -1;
+ var exists = false;
+
+ foreach (var process in processes)
+ if (foregroundWindow == process.MainWindowHandle) {
+ exists = true;
+ foregroundGame = process;
+ foregroundGameIndex = processes.IndexOf(process);
+ break;
+ }
+
+ if (exists) {
+ var tempGame = processes[0];
+ processes[0] = foregroundGame;
+ processes[foregroundGameIndex] = tempGame;
+ }
+ }
+
+ private static void ToggleGame() {
+ Console.WriteLine("Toggling foreground window as tracked...");
+ var foregroundWindow = GetForegroundWindow();
+ var systemProcesses = Process.GetProcesses();
+ Process foregroundProcess = null;
+
+ foreach (var process in systemProcesses)
+ if (foregroundWindow == process.MainWindowHandle) {
+ foregroundProcess = process;
+ break;
+ }
+
+ if (foregroundProcess == null) return;
+ Console.WriteLine("Foreground process: " + foregroundProcess.ProcessName);
+ 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);
+ }
+ }
+
+ [STAThread]
+ private static void Main() {
+ // AllocConsole();
+
+ var processes = Process.GetProcesses();
+ var currentProcess = Process.GetCurrentProcess();
+
+ foreach (var process in processes)
+ if (process.Id != currentProcess.Id && process.ProcessName == currentProcess.ProcessName) {
+ process.Kill();
+ Process.GetCurrentProcess().Kill();
+ }
+
+
+ HotKeyManager.RegisterHotKey(Keys.D1, KeyModifiers.Alt);
+ HotKeyManager.RegisterHotKey(Keys.D2, KeyModifiers.Alt);
+ HotKeyManager.RegisterHotKey(Keys.D3, KeyModifiers.Alt);
+ 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();
+ // 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);
+
+ }
+}