Update... idk what happened...

This commit is contained in:
2024-11-02 23:11:46 +01:00
parent bf81aad59d
commit bc79315ca2
10 changed files with 503 additions and 509 deletions

8
.gitignore vendored
View File

@@ -1,3 +1,5 @@
.idea .idea
**/Debug **/Debug
**/Properties **/Properties
obj
bin

View File

@@ -1,16 +1,16 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DD2Switcher", "DD2Switcher\DD2Switcher.csproj", "{2AC26899-8E27-4B96-85A9-C387186EAD27}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DD2Switcher", "DD2Switcher\DD2Switcher.csproj", "{2AC26899-8E27-4B96-85A9-C387186EAD27}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2AC26899-8E27-4B96-85A9-C387186EAD27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {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}.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.ActiveCfg = Release|Any CPU
{2AC26899-8E27-4B96-85A9-C387186EAD27}.Release|Any CPU.Build.0 = Release|Any CPU {2AC26899-8E27-4B96-85A9-C387186EAD27}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@@ -1,2 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/ActualSeverity/@EntryValue">INFO</s:String></wpf:ResourceDictionary> <s:String x:Key="/Default/CodeInspection/PencilsConfiguration/ActualSeverity/@EntryValue">INFO</s:String>
<s:String x:Key="/Default/Environment/Hierarchy/Build/BuildTool/CustomBuildToolPath/@EntryValue">C:\Users\Administrator\AppData\Local\JetBrains\Toolbox\apps\Rider\ch-0\231.8109.212\tools\MSBuild\Current\Bin\amd64\MSBuild.exe</s:String>
</wpf:ResourceDictionary>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup> </startup>
</configuration> </configuration>

View File

@@ -1,88 +1,88 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2AC26899-8E27-4B96-85A9-C387186EAD27}</ProjectGuid> <ProjectGuid>{2AC26899-8E27-4B96-85A9-C387186EAD27}</ProjectGuid>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<RootNamespace>DD2Switcher</RootNamespace> <RootNamespace>DD2Switcher</RootNamespace>
<AssemblyName>DD2Switcher</AssemblyName> <AssemblyName>DD2Switcher</AssemblyName>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion> <TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
<LangVersion>10</LangVersion> <LangVersion>10</LangVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32bit>false</Prefer32bit> <Prefer32bit>false</Prefer32bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32bit>false</Prefer32bit> <Prefer32bit>false</Prefer32bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System"/> <Reference Include="System"/>
<Reference Include="System.Core"/> <Reference Include="System.Core"/>
<Reference Include="System.Xml.Linq"/> <Reference Include="System.Xml.Linq"/>
<Reference Include="System.Data.DataSetExtensions"/> <Reference Include="System.Data.DataSetExtensions"/>
<Reference Include="Microsoft.CSharp"/> <Reference Include="Microsoft.CSharp"/>
<Reference Include="System.Data"/> <Reference Include="System.Data"/>
<Reference Include="System.Deployment"/> <Reference Include="System.Deployment"/>
<Reference Include="System.Drawing"/> <Reference Include="System.Drawing"/>
<Reference Include="System.Net.Http"/> <Reference Include="System.Net.Http"/>
<Reference Include="System.Windows.Forms"/> <Reference Include="System.Windows.Forms"/>
<Reference Include="System.Xml"/> <Reference Include="System.Xml"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Form1.cs"> <Compile Include="Form1.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="Form1.Designer.cs"> <Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon> <DependentUpon>Form1.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="HotKeyManager.cs"/> <Compile Include="HotKeyManager.cs"/>
<Compile Include="Pixel.cs"/> <Compile Include="Pixel.cs"/>
<Compile Include="Program.cs"/> <Compile Include="Program.cs"/>
<Compile Include="Properties\AssemblyInfo.cs"/> <Compile Include="Properties\AssemblyInfo.cs"/>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</EmbeddedResource> </EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs"> <Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None> </None>
<Compile Include="Properties\Settings.Designer.cs"> <Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon> <DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput> <DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config"/> <None Include="App.config"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="beep.wav"/> <Content Include="beep.wav"/>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
</Project> </Project>

View File

@@ -1,40 +1,40 @@
namespace DD2Switcher namespace DD2Switcher
{ {
partial class Form1 partial class Form1
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// Clean up any resources being used. /// Clean up any resources being used.
/// </summary> /// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
{ {
components.Dispose(); components.Dispose();
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
#region Windows Form Designer generated code #region Windows Form Designer generated code
/// <summary> /// <summary>
/// Required method for Designer support - do not modify /// Required method for Designer support - do not modify
/// the contents of this method with the code editor. /// the contents of this method with the code editor.
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1"; this.Text = "Form1";
} }
#endregion #endregion
} }
} }

View File

@@ -1,9 +1,9 @@
using System.Windows.Forms; using System.Windows.Forms;
namespace DD2Switcher; namespace DD2Switcher;
public partial class Form1 : Form { public partial class Form1 : Form {
public Form1() { public Form1() {
InitializeComponent(); InitializeComponent();
} }
} }

View File

@@ -1,105 +1,105 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
namespace DD2Switcher; namespace DD2Switcher;
public static class HotKeyManager { public static class HotKeyManager {
private static volatile MessageWindow _wnd; private static volatile MessageWindow _wnd;
private static volatile IntPtr _hwnd; private static volatile IntPtr _hwnd;
private static readonly ManualResetEvent _windowReadyEvent = new(false); private static readonly ManualResetEvent _windowReadyEvent = new(false);
private static int _id; private static int _id;
static HotKeyManager() { static HotKeyManager() {
var messageLoop = new Thread(delegate() { Application.Run(new MessageWindow()); }); var messageLoop = new Thread(delegate() { Application.Run(new MessageWindow()); });
messageLoop.Name = "MessageLoopThread"; messageLoop.Name = "MessageLoopThread";
messageLoop.IsBackground = true; messageLoop.IsBackground = true;
messageLoop.Start(); messageLoop.Start();
} }
public static event EventHandler<HotKeyEventArgs> HotKeyPressed; public static event EventHandler<HotKeyEventArgs> HotKeyPressed;
public static int RegisterHotKey(Keys key, KeyModifiers modifiers) { public static int RegisterHotKey(Keys key, KeyModifiers modifiers) {
_windowReadyEvent.WaitOne(); _windowReadyEvent.WaitOne();
var id = Interlocked.Increment(ref _id); var id = Interlocked.Increment(ref _id);
_wnd.Invoke(new RegisterHotKeyDelegate(RegisterHotKeyInternal), _hwnd, id, (uint)modifiers, (uint)key); _wnd.Invoke(new RegisterHotKeyDelegate(RegisterHotKeyInternal), _hwnd, id, (uint)modifiers, (uint)key);
return id; return id;
} }
public static void UnregisterHotKey(int id) { public static void UnregisterHotKey(int id) {
_wnd.Invoke(new UnRegisterHotKeyDelegate(UnRegisterHotKeyInternal), _hwnd, id); _wnd.Invoke(new UnRegisterHotKeyDelegate(UnRegisterHotKeyInternal), _hwnd, id);
} }
private static void RegisterHotKeyInternal(IntPtr hwnd, int id, uint modifiers, uint key) { private static void RegisterHotKeyInternal(IntPtr hwnd, int id, uint modifiers, uint key) {
RegisterHotKey(hwnd, id, modifiers, key); RegisterHotKey(hwnd, id, modifiers, key);
} }
private static void UnRegisterHotKeyInternal(IntPtr hwnd, int id) { private static void UnRegisterHotKeyInternal(IntPtr hwnd, int id) {
UnregisterHotKey(_hwnd, id); UnregisterHotKey(_hwnd, id);
} }
private static void OnHotKeyPressed(HotKeyEventArgs e) { private static void OnHotKeyPressed(HotKeyEventArgs e) {
if (HotKeyPressed != null) HotKeyPressed(null, e); if (HotKeyPressed != null) HotKeyPressed(null, e);
} }
[DllImport("user32", SetLastError = true)] [DllImport("user32", SetLastError = true)]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk); private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
[DllImport("user32", SetLastError = true)] [DllImport("user32", SetLastError = true)]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id); private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
private delegate void RegisterHotKeyDelegate(IntPtr hwnd, int id, uint modifiers, uint key); private delegate void RegisterHotKeyDelegate(IntPtr hwnd, int id, uint modifiers, uint key);
private delegate void UnRegisterHotKeyDelegate(IntPtr hwnd, int id); private delegate void UnRegisterHotKeyDelegate(IntPtr hwnd, int id);
private class MessageWindow : Form { private class MessageWindow : Form {
private const int WM_HOTKEY = 0x312; private const int WM_HOTKEY = 0x312;
public MessageWindow() { public MessageWindow() {
_wnd = this; _wnd = this;
_hwnd = Handle; _hwnd = Handle;
_windowReadyEvent.Set(); _windowReadyEvent.Set();
} }
protected override void WndProc(ref Message m) { protected override void WndProc(ref Message m) {
if (m.Msg == WM_HOTKEY) { if (m.Msg == WM_HOTKEY) {
var e = new HotKeyEventArgs(m.LParam); var e = new HotKeyEventArgs(m.LParam);
OnHotKeyPressed(e); OnHotKeyPressed(e);
} }
base.WndProc(ref m); base.WndProc(ref m);
} }
protected override void SetVisibleCore(bool value) { protected override void SetVisibleCore(bool value) {
// Ensure the window never becomes visible // Ensure the window never becomes visible
base.SetVisibleCore(false); base.SetVisibleCore(false);
} }
} }
} }
public class HotKeyEventArgs : EventArgs { public class HotKeyEventArgs : EventArgs {
public readonly Keys Key; public readonly Keys Key;
public readonly KeyModifiers Modifiers; public readonly KeyModifiers Modifiers;
public HotKeyEventArgs(Keys key, KeyModifiers modifiers) { public HotKeyEventArgs(Keys key, KeyModifiers modifiers) {
Key = key; Key = key;
Modifiers = modifiers; Modifiers = modifiers;
} }
public HotKeyEventArgs(IntPtr hotKeyParam) { public HotKeyEventArgs(IntPtr hotKeyParam) {
var param = (uint)hotKeyParam.ToInt64(); var param = (uint)hotKeyParam.ToInt64();
Key = (Keys)((param & 0xffff0000) >> 16); Key = (Keys)((param & 0xffff0000) >> 16);
Modifiers = (KeyModifiers)(param & 0x0000ffff); Modifiers = (KeyModifiers)(param & 0x0000ffff);
} }
} }
[Flags] [Flags]
public enum KeyModifiers { public enum KeyModifiers {
Alt = 1, Alt = 1,
Control = 2, Control = 2,
Shift = 4, Shift = 4,
Windows = 8, Windows = 8,
NoRepeat = 0x4000 NoRepeat = 0x4000
} }

View File

@@ -1,25 +1,25 @@
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
namespace DD2Switcher; namespace DD2Switcher;
public class Pixel { public class Pixel {
public Pixel(int x, int y, int R, int G, int B) { public Pixel(int x, int y, int R, int G, int B) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.R = R; this.R = R;
this.G = G; this.G = G;
this.B = B; this.B = B;
} }
private int x { get; } private int x { get; }
private int y { get; } private int y { get; }
private int R { get; } private int R { get; }
private int G { get; } private int G { get; }
private int B { get; } private int B { get; }
public bool ProcessBitmap(Bitmap bmp) { public bool ProcessBitmap(Bitmap bmp) {
var tempPixel = bmp.GetPixel(x, y); var tempPixel = bmp.GetPixel(x, y);
return tempPixel.R >= R && tempPixel.B >= B && tempPixel.G >= G; return tempPixel.R >= R && tempPixel.B >= B && tempPixel.G >= G;
} }
} }

View File

@@ -1,222 +1,211 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Runtime.InteropServices;
using System.Media; using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading; namespace DD2Switcher;
using System.Windows.Forms;
internal static class Program {
namespace DD2Switcher; private static List<Process> processes = new();
internal static class Program { private static Process activeProcess;
private static Rectangle rect = new(0, 0, 2560, 1440); private static readonly IntPtr defaultAffinity = new(0xFF000000);
private static readonly Process[] games = Process.GetProcessesByName("Dundefgame"); private static readonly IntPtr fullAffinity = new(0xFFFFFFFF);
private static readonly SoundPlayer beeper = [DllImport("user32.dll")]
new(@"C:\Users\Administrator\RiderProjects\DD2Switcher\DD2Switcher\beep.wav"); public static extern IntPtr GetForegroundWindow();
private static Process activeGame = games[0]; [DllImport("user32.dll")]
private static Bitmap screenshot; public static extern bool SetForegroundWindow(IntPtr hWnd);
private static Graphics graphics;
private static readonly IntPtr defaultAffinity = new(0xFF000000); [DllImport("kernel32.dll", SetLastError = true)]
private static readonly IntPtr fullAffinity = new(0xFFFFFFFF); [return: MarshalAs(UnmanagedType.Bool)]
private static bool paused = true; static extern bool AllocConsole();
private static List<Point> relevantPoints = new List<Point>(); private static void AdjustAffinities() {
private static List<Point> pointsToRemove = new List<Point>(); List<Process> fuckedProcesses = new();
[DllImport("user32.dll")] foreach (var process in processes)
private static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, UIntPtr dwExtraInfo); if (process != activeProcess) {
try {
[DllImport("user32.dll")] process.ProcessorAffinity = defaultAffinity;
public static extern IntPtr GetForegroundWindow(); }
catch (Exception e) {
[DllImport("user32.dll")] fuckedProcesses.Add(process);
public static extern bool SetForegroundWindow(IntPtr hWnd); }
}
[DllImport("User32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] try {
private static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags); activeProcess.ProcessorAffinity = fullAffinity;
}
[DllImport("user32.dll")] catch (Exception e) {
private static extern bool GetWindowRect(IntPtr handle, ref Rectangle rect); fuckedProcesses.Add(activeProcess);
}
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); foreach (var fucked in fuckedProcesses)
processes.Remove(fucked);
public static Bitmap CaptureWindow(IntPtr handle) { }
if (screenshot == null)
screenshot = new Bitmap(rect.Width, rect.Height); private static void AdjustPriorities() {
graphics = Graphics.FromImage(screenshot); List<Process> fuckedProcesses = new();
var hdc = graphics.GetHdc();
PrintWindow(handle, hdc, 0); foreach (var process in processes) {
graphics.ReleaseHdc(hdc); try {
return screenshot; process.PriorityClass = ProcessPriorityClass.Idle;
} }
catch (Exception e) {
private static void AdjustAffinities() { fuckedProcesses.Add(process);
foreach (var game in games) }
if (game != activeGame) }
game.ProcessorAffinity = defaultAffinity;
activeGame.ProcessorAffinity = fullAffinity; try {
} activeProcess.PriorityClass = ProcessPriorityClass.High;
}
private static void AdjustPriorities() { catch (Exception e) {
foreach (var game in games) game.PriorityClass = ProcessPriorityClass.Idle; fuckedProcesses.Add(activeProcess);
activeGame.PriorityClass = ProcessPriorityClass.High; }
}
foreach (var fucked in fuckedProcesses)
private static void NerfAll() { processes.Remove(fucked);
foreach (var game in games) { }
game.ProcessorAffinity = defaultAffinity;
game.PriorityClass = ProcessPriorityClass.Idle; 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;
private static void BuffAll() { if (targetWindowHandle == IntPtr.Zero) {
foreach (var game in games) { processes.RemoveAt(processes.Count - 1 - index);
game.ProcessorAffinity = fullAffinity; return;
game.PriorityClass = ProcessPriorityClass.Normal; }
} SetForegroundWindow(targetWindowHandle);
} activeProcess = processes[processes.Count - 1 - index];
AdjustAffinities();
private static void SwitchToGame(int index) { AdjustPriorities();
if (index >= games.Length) return; }
SetForegroundWindow(games[index].MainWindowHandle);
activeGame = games[index]; private static void SwitchMainGame() {
AdjustAffinities(); var foregroundWindow = GetForegroundWindow();
AdjustPriorities(); Process foregroundGame = null;
} var foregroundGameIndex = -1;
var exists = false;
private static void SwitchMainGame() {
var foregroundWindow = GetForegroundWindow(); foreach (var process in processes)
Process foregroundGame = null; if (foregroundWindow == process.MainWindowHandle) {
var foregroundGameIndex = -1; exists = true;
var exists = false; foregroundGame = process;
foregroundGameIndex = processes.IndexOf(process);
foreach (var game in games) break;
if (foregroundWindow == game.MainWindowHandle) { }
exists = true;
foregroundGame = game; if (exists) {
foregroundGameIndex = Array.IndexOf(games, game); var tempGame = processes[0];
break; processes[0] = foregroundGame;
} processes[foregroundGameIndex] = tempGame;
}
if (exists) { }
var tempGame = games[0];
games[0] = foregroundGame; private static void ToggleGame() {
games[foregroundGameIndex] = tempGame; Console.WriteLine("Toggling foreground window as tracked...");
} var foregroundWindow = GetForegroundWindow();
} var systemProcesses = Process.GetProcesses();
Process foregroundProcess = null;
[STAThread]
private static void Main() { foreach (var process in systemProcesses)
var processes = Process.GetProcesses(); if (foregroundWindow == process.MainWindowHandle) {
var currentProcess = Process.GetCurrentProcess(); foregroundProcess = process;
break;
foreach (var process in processes) }
if (process.Id != currentProcess.Id && process.ProcessName == currentProcess.ProcessName)
process.Kill(); if (foregroundProcess == null) return;
Console.WriteLine("Foreground process: " + foregroundProcess.ProcessName);
HotKeyManager.RegisterHotKey(Keys.D1, KeyModifiers.Alt); var existingProcess = processes.Find(process => process.Id == foregroundProcess.Id);
HotKeyManager.RegisterHotKey(Keys.D2, KeyModifiers.Alt); if (existingProcess != null) {
HotKeyManager.RegisterHotKey(Keys.D3, KeyModifiers.Alt); Console.WriteLine("Removing foreground process from tracked...");
HotKeyManager.RegisterHotKey(Keys.D4, KeyModifiers.Alt); processes.Remove(existingProcess);
HotKeyManager.RegisterHotKey(Keys.D5, KeyModifiers.Alt); }
HotKeyManager.RegisterHotKey(Keys.D6, KeyModifiers.Alt); else {
HotKeyManager.RegisterHotKey(Keys.Q, KeyModifiers.Alt); Console.WriteLine("Adding foreground process to tracked...");
HotKeyManager.RegisterHotKey(Keys.W, KeyModifiers.Alt); processes.Add(foregroundProcess);
HotKeyManager.RegisterHotKey(Keys.R, KeyModifiers.Alt); }
HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed; }
var pixelList = new System.Collections.Generic.List<Pixel>(); [STAThread]
// pixelList.Add(new Pixel(1401, 1234, 224, 224, 224)); private static void Main() {
pixelList.Add(new Pixel(1359, 1235, 220, 220, 220)); // AllocConsole();
static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) { var processes = Process.GetProcesses();
switch (e.Key) { var currentProcess = Process.GetCurrentProcess();
case Keys.D1:
SwitchToGame(0); foreach (var process in processes)
break; if (process.Id != currentProcess.Id && process.ProcessName == currentProcess.ProcessName) {
case Keys.D2: process.Kill();
SwitchToGame(1); Process.GetCurrentProcess().Kill();
break; }
case Keys.D3:
SwitchToGame(2);
break; HotKeyManager.RegisterHotKey(Keys.D1, KeyModifiers.Alt);
case Keys.D4: HotKeyManager.RegisterHotKey(Keys.D2, KeyModifiers.Alt);
SwitchToGame(3); HotKeyManager.RegisterHotKey(Keys.D3, KeyModifiers.Alt);
break; HotKeyManager.RegisterHotKey(Keys.D4, KeyModifiers.Alt);
case Keys.D5: HotKeyManager.RegisterHotKey(Keys.D5, KeyModifiers.Alt);
SwitchMainGame(); HotKeyManager.RegisterHotKey(Keys.D6, KeyModifiers.Alt);
break; HotKeyManager.RegisterHotKey(Keys.D7, KeyModifiers.Alt);
case Keys.D6: HotKeyManager.RegisterHotKey(Keys.D8, KeyModifiers.Alt);
Environment.Exit(0); HotKeyManager.RegisterHotKey(Keys.D9, KeyModifiers.Alt);
break;
case Keys.W: HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Alt);
if (paused) {
beeper.Play(); // HotKeyManager.RegisterHotKey(Keys.Q, KeyModifiers.Alt);
paused = false; // HotKeyManager.RegisterHotKey(Keys.W, KeyModifiers.Alt);
} // HotKeyManager.RegisterHotKey(Keys.R, KeyModifiers.Alt);
else { HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed;
beeper.Play();
Thread.Sleep(150); var pixelList = new System.Collections.Generic.List<Pixel>();
beeper.Play(); // pixelList.Add(new Pixel(1401, 1234, 224, 224, 224));
paused = true; pixelList.Add(new Pixel(1359, 1235, 220, 220, 220));
}
static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) {
break; switch (e.Key) {
} case Keys.D1:
} SwitchToProcess(0);
break;
while (true) { case Keys.D2:
bool runOnce = false; SwitchToProcess(1);
bool AAA = false; break;
relevantPoints.Clear(); case Keys.D3:
while (!paused) { SwitchToProcess(2);
screenshot = CaptureWindow(games[0].MainWindowHandle); break;
// screenshot.Save("SS.png"); case Keys.D4:
SwitchToProcess(3);
// if (!runOnce) { break;
// runOnce = true; case Keys.D5:
// for (var y = 0; y < screenshot.Height; y++) SwitchToProcess(4);
// for (var x = 0; x < screenshot.Width; x++) { break;
// var pixelColor = screenshot.GetPixel(x, y); case Keys.D6:
// if (pixelColor.R > 220 && pixelColor.G > 220 && pixelColor.B > 220) SwitchToProcess(5);
// relevantPoints.Add(new Point(x, y)); break;
// } case Keys.D7:
// } SwitchToProcess(6);
// break;
// pointsToRemove.Clear(); case Keys.D8:
// foreach (var relevantPoint in relevantPoints) { SwitchToProcess(7);
// var pixel = screenshot.GetPixel(relevantPoint.X, relevantPoint.Y); break;
// if (!(pixel.R > 220) || !(pixel.G > 220) || !(pixel.B > 220)) case Keys.D9:
// pointsToRemove.Add(relevantPoint); SwitchToProcess(8);
// } break;
// case Keys.Oemtilde:
// foreach (var point in pointsToRemove) { ToggleGame();
// relevantPoints.Remove(point); break;
// } }
// }
// Debug.WriteLine(relevantPoints.Count);
foreach (var p in pixelList) Console.CancelKeyPress += (sender, e) => {
if (p.ProcessBitmap(screenshot)) { Process.GetCurrentProcess().Kill();
beeper.Play(); };
break; while (true)
} System.Threading.Thread.Sleep(100000);
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);
}
}
}