diff --git a/.gitignore b/.gitignore deleted file mode 100644 index f450f81..0000000 --- a/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -**/Debug -**/Properties -obj -bin \ No newline at end of file diff --git a/DD2Switcher.sln b/DD2Switcher.sln deleted file mode 100644 index 6001d6b..0000000 --- a/DD2Switcher.sln +++ /dev/null @@ -1,16 +0,0 @@ - -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 deleted file mode 100644 index 7c3bbf1..0000000 --- a/DD2Switcher.sln.DotSettings.user +++ /dev/null @@ -1,5 +0,0 @@ - - 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 deleted file mode 100644 index 69f9d64..0000000 --- a/DD2Switcher/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/DD2Switcher/DD2Switcher.csproj b/DD2Switcher/DD2Switcher.csproj deleted file mode 100644 index 1f8ff78..0000000 --- a/DD2Switcher/DD2Switcher.csproj +++ /dev/null @@ -1,88 +0,0 @@ - - - - - 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 deleted file mode 100644 index 554befa..0000000 --- a/DD2Switcher/Form1.Designer.cs +++ /dev/null @@ -1,40 +0,0 @@ -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 deleted file mode 100644 index 9b0bd05..0000000 --- a/DD2Switcher/Form1.cs +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index b554fbe..0000000 --- a/DD2Switcher/HotKeyManager.cs +++ /dev/null @@ -1,105 +0,0 @@ -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 deleted file mode 100644 index 6988065..0000000 --- a/DD2Switcher/Pixel.cs +++ /dev/null @@ -1,25 +0,0 @@ -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 deleted file mode 100644 index 3d57d5a..0000000 --- a/DD2Switcher/Program.cs +++ /dev/null @@ -1,211 +0,0 @@ -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); - - } -} diff --git a/DD2Switcher/beep.wav b/DD2Switcher/beep.wav deleted file mode 100644 index b8c1994..0000000 Binary files a/DD2Switcher/beep.wav and /dev/null differ