-
Notifications
You must be signed in to change notification settings - Fork 1
/
CSGO.cs
229 lines (188 loc) · 9.09 KB
/
CSGO.cs
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using csgo_external_cs.Extensions;
namespace csgo_external_cs
{
public static class CSGO
{
public static Process Process = null;
public static IntPtr Handle = IntPtr.Zero;
public static class Modules
{
public static Classes.CSGOModule Client = null;
public static Classes.CSGOModule Engine = null;
}
public static class Offsets
{
public static int m_iHealth = 0;
public static int m_iCrosshairId = 0;
public static int m_bDormant = 0;
public static int m_iTeamNum = 0;
public static int m_bSpotted = 0x93D;
public static int m_iGlowIndex = 0;
}
public static class Values
{
public static IntPtr LocalPlayerPointer = IntPtr.Zero;
public static IntPtr dwForceAttack = IntPtr.Zero;
public static IntPtr dwEntityList = IntPtr.Zero;
public static IntPtr dwGlowObjectManager = IntPtr.Zero;
}
public static void Initialize()
{
Program.Log("Initializing...");
Program.Log("\n" + (Program.Status = "Waiting for CS:GO... "));
CSGOInit.FindCSGO();
if (!CSGOInit.OpenCSGO() || !CSGOInit.LoadModules() || !CSGOInit.LoadOffsets() || !CSGOInit.LoadValues())
{
Program.Log("ERROR: Initialization failed!");
return;
}
Program.Status = "Initializing features";
CSGOInit.LoadFeatures();
Program.Status = "Ready!";
}
}
static class CSGOInit
{
public static void FindCSGO()
{
while (CSGO.Process == null)
{
Thread.Sleep(500);
Process[] ProcList = Process.GetProcessesByName("csgo");
if (ProcList.Length < 1)
continue;
CSGO.Process = ProcList[0];
Program.Log("Found!");
}
}
public static bool OpenCSGO()
{
Program.Log("\n" + (Program.Status = "Creating handle to CS:GO... "));
CSGO.Handle = PInvoke.kernel32.OpenProcess(
PInvoke.kernel32.ProcessAccessFlags.CreateThread | PInvoke.kernel32.ProcessAccessFlags.QueryInformation | PInvoke.kernel32.ProcessAccessFlags.VirtualMemoryOperation | PInvoke.kernel32.ProcessAccessFlags.VirtualMemoryRead | PInvoke.kernel32.ProcessAccessFlags.VirtualMemoryWrite,
false,
CSGO.Process.Id
);
if (CSGO.Handle == IntPtr.Zero)
{
Program.Log("Failed!");
Program.Status = "Failed to create handle!";
return false;
}
Program.Log("Success!");
return true;
}
public static bool LoadModules()
{
Program.Status = "Loading modules...";
Program.Log("\nWaiting for modules to load...");
try
{
while (CSGO.Process.Modules.Cast<ProcessModule>().FirstOrDefault(x => x.ModuleName == "serverbrowser.dll") == null)
Thread.Sleep(500);
}
catch (Exception ex)
{
Program.Log("\nFailed to check for modules! Restart application.");
return false;
}
// Initialize all the modules
CSGO.Modules.Client = new Classes.CSGOModule("client.dll");
CSGO.Modules.Engine = new Classes.CSGOModule("engine.dll");
Program.Log("\nModule Found: ");
foreach (ProcessModule Module in CSGO.Process.Modules)
{
foreach (KeyValuePair<string, Classes.CSGOModule> CSModuleEntry in Classes.CSGOModule.Instances)
{
if (CSModuleEntry.Key != Module.ModuleName)
continue;
Program.Log("\n\t>> " + Module.ModuleName + " ( 0x" + Module.BaseAddress.ToString("X") + " - " + Module.ModuleMemorySize + " byte(s) )");
CSModuleEntry.Value.BaseAddress = Module.BaseAddress;
CSModuleEntry.Value.Size = Module.ModuleMemorySize;
}
}
var UnfoundModules = Classes.CSGOModule.Instances.Where(x => x.Value.BaseAddress == IntPtr.Zero).ToArray();
if (UnfoundModules.Length > 0)
{
Program.Log("\n\nThe following modules were not found, initialization failed!");
foreach (var Module in UnfoundModules)
Program.Log("\n\t>> " + Module.Key);
return false;
}
return true;
}
public static bool LoadOffsets()
{
Program.Log("\n" + (Program.Status = "Loading offsets..."));
Program.Log("\n\t>> m_iHealth = ");
CSGO.Offsets.m_iHealth = (int)CSGO.Modules.Client.PatternScan(new byte[] { 0x83, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x2D }, "xx?????xx", 0x2, true);
Program.Log("0x" + CSGO.Offsets.m_iHealth.ToString("X"));
if (CSGO.Offsets.m_iHealth == 0)
return false;
Program.Log("\n\t>> m_iCrosshairId = ");
CSGO.Offsets.m_iCrosshairId = (int)CSGO.Modules.Client.PatternScan(new byte[] { 0x8B, 0x81, 0x00, 0x00, 0x00, 0x00, 0x85, 0xC0, 0x75, 0x19 }, "xx????xxxx", 0x2, true);
Program.Log("0x" + CSGO.Offsets.m_iCrosshairId.ToString("X"));
if (CSGO.Offsets.m_iCrosshairId == 0)
return false;
Program.Log("\n\t>> m_bDormant = ");
CSGO.Offsets.m_bDormant = (int)CSGO.Modules.Client.PatternScan(new byte[] { 0x8A, 0x81, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x32, 0xC0 }, "xx????xxx", 0x2, true) + 0x8;
Program.Log("0x" + CSGO.Offsets.m_bDormant.ToString("X"));
if (CSGO.Offsets.m_bDormant <= 0x8)
return false;
Program.Log("\n\t>> m_iTeamNum = ");
CSGO.Offsets.m_iTeamNum = (int)CSGO.Modules.Client.PatternScan(new byte[] { 0x8B, 0x89, 0x00, 0x00, 0x00, 0x00, 0xE9 }, "xx????x", 0x2, true);
Program.Log("0x" + CSGO.Offsets.m_iTeamNum.ToString("X"));
if (CSGO.Offsets.m_iTeamNum == 0)
return false;
// TODO: find proper sig
Program.Log("\n\t>> m_bSpotted (HARDCODED) = 0x" + CSGO.Offsets.m_bSpotted.ToString("X"));
Program.Log("\n\t>> m_iGlowIndex = ");
CSGO.Offsets.m_iGlowIndex = (int)CSGO.Modules.Client.PatternScan(new byte[] { 0x8B, 0xB3, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x8A }, "xx????x????x", 0x2, true);
Program.Log("0x" + CSGO.Offsets.m_iGlowIndex.ToString("X"));
if (CSGO.Offsets.m_iGlowIndex == 0)
return false;
return true;
}
public static bool LoadValues()
{
Program.Log("\n" + (Program.Status = "Loading Values..."));
Program.Log("\n\t>> LocalPlayerPointer = ");
CSGO.Values.LocalPlayerPointer = CSGO.Modules.Client.PatternScan(new byte[] { 0x0F, 0x45, 0x15, 0x00, 0x00, 0x00, 0x00, 0x56 }, "xxx????x", 0x3, true);
Program.Log("0x" + CSGO.Values.LocalPlayerPointer.ToString("X"));
if (CSGO.Values.LocalPlayerPointer == IntPtr.Zero)
return false;
Program.Log("\n\t>> dwForceAttack = ");
CSGO.Values.dwForceAttack = CSGO.Modules.Client.PatternScan(new byte[] { 0x89, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x8B, 0xF2, 0x8B, 0xC1, 0x83, 0xCE, 0x04 }, "xx????xx????xxxxxxx", 0x2, true);
Program.Log("0x" + CSGO.Values.dwForceAttack.ToString("X"));
if (CSGO.Values.dwForceAttack == IntPtr.Zero)
return false;
Program.Log("\n\t>> dwEntityList = ");
CSGO.Values.dwEntityList = CSGO.Modules.Client.PatternScan(new byte[] { 0xBB, 0x00, 0x00, 0x00, 0x00, 0x83, 0xFF, 0x01, 0x0F, 0x8C, 0x00, 0x00, 0x00, 0x00, 0x3B, 0xF8 }, "x????xxxxx????xx", 0x1, true);
Program.Log("0x" + CSGO.Values.dwEntityList.ToString("X"));
if (CSGO.Values.dwEntityList == IntPtr.Zero)
return false;
Program.Log("\n\t>> dwGlowObjectManager = ");
CSGO.Values.dwGlowObjectManager = CSGO.Modules.Client.PatternScan(new byte[] { 0x0F, 0x11, 0x05, 0x00, 0x00, 0x00, 0x00, 0x83, 0xC8, 0x01 }, "xxx????xxx", 0x3, true);
Program.Log("0x" + CSGO.Values.dwGlowObjectManager.ToString("X"));
if (CSGO.Values.dwGlowObjectManager == IntPtr.Zero)
return false;
return true;
}
public static void LoadFeatures()
{
foreach (Hacks.HackBase Feature in Program.HackInstances)
{
Program.Log("\nInitializing feature: " + Feature.Name);
Feature.Initialize();
}
}
}
}