Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
112 lines (100 loc) · 4.71 KB
/
Copy pathProgram.cs
File metadata and controls
112 lines (100 loc) · 4.71 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
111
112
// Main entry point. Sets up everything and runs the overlay.
// I have a loop for updating entities in a background thread.
// Checks if CS2 is running and handles foreground focus.
using Microsoft.COM.Surogate;
using Microsoft.COM.Surogate.Data;
using Microsoft.COM.Surogate.Modules;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
internal static class Program
{
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
[STAThread]
private static async Task Main()
{
Console.Title = "Microsoft.COM.Surogate";
Console.WriteLine("\r\n __ _ __ \r\n / _\\_ __ ___ ___ | | _____ _ _/ _\\ ___ _ __ ___ ___ \r\n \\ \\| '_ ` _ \\ / _ \\| |/ / _ \\ | | \\ \\ / _ \\ '_ \\ / __/ _ \\\r\n _\\ \\ | | | | | (_) | < __/ |_| |\\ \\ __/ | | | (_| __/\r\n \\__/_| |_| |_|\\___/|_|\\_\\___|\\__, \\__/\\___|_| |_|\\___\\___| v1.0 BETA\r\n |___/ ");
if (Process.GetProcessesByName("cs2").Length == 0)
{
Console.WriteLine("[i]: CS2 is not running. Please start the game first!");
Thread.Sleep(3000);
Environment.Exit(0);
}
try
{
bool countNumberofReads = true;
Functions.LoadConfig();
Functions.StartConfigWatcher();
Application.ApplicationExit += (s, e) => Functions.StopConfigWatcher();
Console.WriteLine("[i]: Initializing memory for CS2...");
Memory memory = new Memory();
EntityManager entityManager = new EntityManager(memory);
Console.WriteLine("[i]: Updating offsets...");
await OffsetGrabber.UpdateOffsets();
Console.WriteLine("[i]: Startup completed!");
// Background thread for entity updates
Thread updateThread = new Thread(() =>
{
Stopwatch swReadCountPerSec = countNumberofReads ? Stopwatch.StartNew() :null;
long readsCounter = 0;
Stopwatch sw = Stopwatch.StartNew();
while (true)
{
Process proc = memory.GetProcess();
bool isForeground = false;
IntPtr fgWindow = GetForegroundWindow();
if (fgWindow != IntPtr.Zero)
{
GetWindowThreadProcessId(fgWindow, out uint pid);
isForeground = pid == (uint)proc.Id;
}
if ((Functions.BoxESPEnabled || Functions.BoneESPEnabled || Functions.AimAssistEnabled) && isForeground)
{
long startMs = sw.ElapsedTicks / 10000;
List<Entity> entities = entityManager.GetEntities();
Entity local = entityManager.GetLocalPlayer();
entityManager.UpdateLocalPlayer(local);
entityManager.UpdateEntities(entities);
if (countNumberofReads)
{
readsCounter++;
if (swReadCountPerSec.ElapsedMilliseconds >= 1000)
{
swReadCountPerSec.Restart();
Console.WriteLine ( $"Reads/s: {readsCounter}");
readsCounter = 0;
}
}
long elapsedMs = (sw.ElapsedTicks / 10000) - startMs;
int targetMs = 7;
if (elapsedMs < targetMs) Thread.Sleep(targetMs - (int)elapsedMs);
}
else
{
Thread.Sleep(1000);
}
}
});
updateThread.IsBackground = true;
updateThread.Priority = ThreadPriority.BelowNormal;
updateThread.Start();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Overlay(memory, entityManager));
}
catch (Exception ex)
{
Console.WriteLine($"[i]: {ex.Message}");
Thread.Sleep(5000);
Environment.Exit(1);
}
}
}