-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProgram.cs
More file actions
110 lines (109 loc) · 3.95 KB
/
Program.cs
File metadata and controls
110 lines (109 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
namespace Anti_GG
{
internal class Program
{
static bool running = true;
static TaskCompletionSource taskCompletionSource;
#region Imports
[DllImport("kernel32.dll")]
static extern IntPtr OpenThread(int dwDesiredAccess, bool bInheritHandle, int dwThreadId);
[DllImport("kernel32.dll")]
static extern int SuspendThread(IntPtr hThread);
[DllImport("kernel32.dll")]
static extern int ResumeThread(IntPtr hThread);
[DllImport("kernel32.dll")]
static extern bool CloseHandle(IntPtr hObject);
[DllImport("user32.dll")]
static extern short GetAsyncKeyState(Keys vKey);
#endregion
enum Keys : int { NumPad0 = 0x60, NumPad1 = 0x61 }; // https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
static Task Main(string[] args)
{
taskCompletionSource = new TaskCompletionSource();
StartAntiGG();
Console.CancelKeyPress += (sender, eventArgs) =>
{
eventArgs.Cancel = true;
Console.WriteLine("Cancellation requested...");
running = false;
Thread.Sleep(500); //wait to allow thread to end and GG to be released
taskCompletionSource.SetResult();
};
return taskCompletionSource.Task;
}
static void StartAntiGG()
{
Thread T = new Thread(AntiGG) { IsBackground = true };
T.Start();
}
static bool Paused = false;
static DateTime Last = DateTime.Now;
static void AntiGG()
{
Thread.CurrentThread.Priority = ThreadPriority.Highest;
Process process = null;
Process[] processes = Process.GetProcessesByName("GameMon");
if (processes.Length > 0)
{
process = processes[0];
Console.WriteLine("GameGuard detected. Crippling GameGuard.");
for (int counter = 0; running; Thread.Sleep(10),counter++)
{
if (!Paused)
PauseProcess(process);
if (DateTime.Now.Subtract(Last).TotalMinutes >= 1)
UnpauseProcess(process);
if(counter >= 5)
{
ProcessKeyInput(process);
counter = 0;
}
}
//Unpause if running is ended
Console.WriteLine("Program ending, releasing GameGuard.");
UnpauseProcess(process);
}
else
{
Console.WriteLine("GameGuard not detected. Closing.");
running = false;
taskCompletionSource.SetResult();
}
}
static void UnpauseProcess(Process process)
{
Paused = false;
foreach (ProcessThread threadId in process.Threads)
{
IntPtr threadHandle = OpenThread(0x0002, false, threadId.Id);
ResumeThread(threadHandle);
CloseHandle(threadHandle);
}
}
static void PauseProcess(Process process)
{
Last = DateTime.Now;
Paused = true;
foreach (ProcessThread threadId in process.Threads)
{
IntPtr threadHandle = OpenThread(0x0002, false, threadId.Id);
SuspendThread(threadHandle);
CloseHandle(threadHandle);
}
}
static void ProcessKeyInput(Process process)
{
if (GetAsyncKeyState(Keys.NumPad0) == -32767)
{
UnpauseProcess(process);
Console.WriteLine("Manual unpause.");
Thread.Sleep(100);
}
}
}
}