Update... idk what happened...
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
.idea
|
||||
**/Debug
|
||||
**/Properties
|
||||
obj
|
||||
bin
|
@@ -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">
|
||||
<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>
|
@@ -1,33 +1,17 @@
|
||||
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 List<Process> processes = new();
|
||||
|
||||
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 Process activeProcess;
|
||||
private static readonly IntPtr defaultAffinity = new(0xFF000000);
|
||||
private static readonly IntPtr fullAffinity = new(0xFFFFFFFF);
|
||||
private static bool paused = true;
|
||||
|
||||
private static List<Point> relevantPoints = new List<Point>();
|
||||
private static List<Point> pointsToRemove = new List<Point>();
|
||||
|
||||
[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();
|
||||
@@ -35,56 +19,67 @@ internal static class Program {
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("User32.dll", SetLastError = true)]
|
||||
[DllImport("kernel32.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;
|
||||
}
|
||||
static extern bool AllocConsole();
|
||||
|
||||
private static void AdjustAffinities() {
|
||||
foreach (var game in games)
|
||||
if (game != activeGame)
|
||||
game.ProcessorAffinity = defaultAffinity;
|
||||
activeGame.ProcessorAffinity = fullAffinity;
|
||||
List<Process> 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() {
|
||||
foreach (var game in games) game.PriorityClass = ProcessPriorityClass.Idle;
|
||||
activeGame.PriorityClass = ProcessPriorityClass.High;
|
||||
}
|
||||
List<Process> fuckedProcesses = new();
|
||||
|
||||
private static void NerfAll() {
|
||||
foreach (var game in games) {
|
||||
game.ProcessorAffinity = defaultAffinity;
|
||||
game.PriorityClass = ProcessPriorityClass.Idle;
|
||||
foreach (var process in processes) {
|
||||
try {
|
||||
process.PriorityClass = ProcessPriorityClass.Idle;
|
||||
}
|
||||
catch (Exception e) {
|
||||
fuckedProcesses.Add(process);
|
||||
}
|
||||
}
|
||||
|
||||
private static void BuffAll() {
|
||||
foreach (var game in games) {
|
||||
game.ProcessorAffinity = fullAffinity;
|
||||
game.PriorityClass = ProcessPriorityClass.Normal;
|
||||
try {
|
||||
activeProcess.PriorityClass = ProcessPriorityClass.High;
|
||||
}
|
||||
catch (Exception e) {
|
||||
fuckedProcesses.Add(activeProcess);
|
||||
}
|
||||
|
||||
private static void SwitchToGame(int index) {
|
||||
if (index >= games.Length) return;
|
||||
SetForegroundWindow(games[index].MainWindowHandle);
|
||||
activeGame = games[index];
|
||||
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();
|
||||
}
|
||||
@@ -95,29 +90,59 @@ internal static class Program {
|
||||
var foregroundGameIndex = -1;
|
||||
var exists = false;
|
||||
|
||||
foreach (var game in games)
|
||||
if (foregroundWindow == game.MainWindowHandle) {
|
||||
foreach (var process in processes)
|
||||
if (foregroundWindow == process.MainWindowHandle) {
|
||||
exists = true;
|
||||
foregroundGame = game;
|
||||
foregroundGameIndex = Array.IndexOf(games, game);
|
||||
foregroundGame = process;
|
||||
foregroundGameIndex = processes.IndexOf(process);
|
||||
break;
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
var tempGame = games[0];
|
||||
games[0] = foregroundGame;
|
||||
games[foregroundGameIndex] = tempGame;
|
||||
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)
|
||||
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);
|
||||
@@ -125,9 +150,15 @@ internal static class Program {
|
||||
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.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>();
|
||||
@@ -137,86 +168,44 @@ internal static class Program {
|
||||
static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) {
|
||||
switch (e.Key) {
|
||||
case Keys.D1:
|
||||
SwitchToGame(0);
|
||||
SwitchToProcess(0);
|
||||
break;
|
||||
case Keys.D2:
|
||||
SwitchToGame(1);
|
||||
SwitchToProcess(1);
|
||||
break;
|
||||
case Keys.D3:
|
||||
SwitchToGame(2);
|
||||
SwitchToProcess(2);
|
||||
break;
|
||||
case Keys.D4:
|
||||
SwitchToGame(3);
|
||||
SwitchToProcess(3);
|
||||
break;
|
||||
case Keys.D5:
|
||||
SwitchMainGame();
|
||||
SwitchToProcess(4);
|
||||
break;
|
||||
case Keys.D6:
|
||||
Environment.Exit(0);
|
||||
SwitchToProcess(5);
|
||||
break;
|
||||
case Keys.W:
|
||||
if (paused) {
|
||||
beeper.Play();
|
||||
paused = false;
|
||||
}
|
||||
else {
|
||||
beeper.Play();
|
||||
Thread.Sleep(150);
|
||||
beeper.Play();
|
||||
paused = true;
|
||||
}
|
||||
|
||||
case Keys.D7:
|
||||
SwitchToProcess(6);
|
||||
break;
|
||||
case Keys.D8:
|
||||
SwitchToProcess(7);
|
||||
break;
|
||||
case Keys.D9:
|
||||
SwitchToProcess(8);
|
||||
break;
|
||||
case Keys.Oemtilde:
|
||||
ToggleGame();
|
||||
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);
|
||||
Console.CancelKeyPress += (sender, e) => {
|
||||
Process.GetCurrentProcess().Kill();
|
||||
};
|
||||
while (true)
|
||||
System.Threading.Thread.Sleep(100000);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user