-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWallHackService.cs
More file actions
311 lines (268 loc) · 10.7 KB
/
WallHackService.cs
File metadata and controls
311 lines (268 loc) · 10.7 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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
namespace DungeonRampageCheat
{
public class WallHackService : IDisposable
{
private readonly MemoryManager memoryManager;
private readonly WallHackConfig config;
private readonly Dictionary<string, List<IntPtr>> mapAddresses;
private bool isAttached = false;
public event EventHandler<string>? OnStatusChanged;
public event EventHandler<string>? OnError;
public MemoryManager MemoryManager => memoryManager;
public WallHackService()
{
memoryManager = new MemoryManager();
config = new WallHackConfig();
mapAddresses = [];
}
public async Task<bool> AttachToGameAsync(string processName)
{
try
{
OnStatusChanged?.Invoke(this, $"🔍 Searching for process '{processName}'...");
bool result = await Task.Run(() => memoryManager.AttachToProcess(processName));
if (result)
{
isAttached = true;
string processInfo = memoryManager.GetProcessInfo();
OnStatusChanged?.Invoke(this, $"✅ Successfully connected to: {processInfo}");
OnStatusChanged?.Invoke(this, "Ready to scan memory!");
return true;
}
else
{
OnError?.Invoke(this, $"❌ Could not find or attach to process '{processName}'");
OnError?.Invoke(this, "Make sure the game is running and try again");
isAttached = false;
return false;
}
}
catch (Exception ex)
{
OnError?.Invoke(this, $"Error attaching to process: {ex.Message}");
return false;
}
}
public async Task ScanAllMapsAsync()
{
if (!isAttached)
{
OnError?.Invoke(this, "Not connected to process! Attach first.");
return;
}
await Task.Run(() =>
{
try
{
OnStatusChanged?.Invoke(this, "🚀 Starting comprehensive map scan...");
OnStatusChanged?.Invoke(this, "This may take a few seconds...");
mapAddresses.Clear();
int totalFound = 0;
int mapsScanned = 0;
int mapsFound = 0;
foreach (var map in config.Maps)
{
mapsScanned++;
OnStatusChanged?.Invoke(this, $"[{mapsScanned}/{config.Maps.Count}] Scanning '{map.MapName}'...");
var addresses = memoryManager.ScanMemoryPatternAll(map.ScanPattern);
if (addresses.Count > 0)
{
mapAddresses[map.MapName] = addresses;
totalFound += addresses.Count;
mapsFound++;
OnStatusChanged?.Invoke(this, $" ✅ '{map.MapName}': {addresses.Count} addresses");
}
else
{
OnStatusChanged?.Invoke(this, $" ⚠️ '{map.MapName}': Not found (may not be loaded)");
}
}
OnStatusChanged?.Invoke(this, "🎉 Scan complete!");
OnStatusChanged?.Invoke(this, $"Found {totalFound} addresses across {mapsFound} maps");
if (totalFound > 0)
{
OnStatusChanged?.Invoke(this, "✅ Ready to apply wallhacks!");
}
else
{
OnError?.Invoke(this, "❌ No patterns found. Make sure:");
OnError?.Invoke(this, " 1) Game is fully loaded");
OnError?.Invoke(this, " 2) You're in a map");
OnError?.Invoke(this, " 3) Game version matches patterns");
}
}
catch (Exception ex)
{
OnError?.Invoke(this, $"Scan error: {ex.Message}");
}
});
}
public bool ApplyWallHack(string mapName)
{
return ApplyWallHack(mapName, true);
}
public bool RestoreMap(string mapName)
{
return ApplyWallHack(mapName, false);
}
private bool ApplyWallHack(string mapName, bool applyHack)
{
if (!isAttached)
{
OnError?.Invoke(this, "Not connected to process!");
return false;
}
if (!mapAddresses.TryGetValue(mapName, out var addresses))
{
OnError?.Invoke(this, $"Map '{mapName}' not found. Run scan first.");
return false;
}
var map = config.Maps.Find(m => m.MapName == mapName);
if (map == null)
return false;
byte[] data = applyHack ? map.ReplacePattern : map.ScanPattern;
string action = applyHack ? "applying WallHack" : "restoring";
OnStatusChanged?.Invoke(this, $"{action} on '{mapName}' at {addresses.Count} addresses...");
int successCount = 0;
int totalAddresses = addresses.Count;
for (int i = 0; i < totalAddresses; i++)
{
try
{
if (memoryManager.WriteMemory(addresses[i], data))
{
successCount++;
}
if (i % 10 == 0 && i > 0)
{
OnStatusChanged?.Invoke(this, $" Progress: {i}/{totalAddresses}");
}
}
catch (Exception ex)
{
OnError?.Invoke(this, $"Error at address 0x{addresses[i].ToInt64():X}: {ex.Message}");
}
}
if (successCount > 0)
{
map.IsEnabled = applyHack;
OnStatusChanged?.Invoke(this, $"✅ {action} on '{mapName}': {successCount}/{totalAddresses} addresses");
return true;
}
else
{
OnError?.Invoke(this, $"❌ Failed to {action} on '{mapName}'");
return false;
}
}
public async Task ApplyAllAsync()
{
if (!isAttached)
{
OnError?.Invoke(this, "Not connected to process!");
return;
}
await Task.Run(() =>
{
try
{
OnStatusChanged?.Invoke(this, "Applying WallHack to all maps...");
int successMaps = 0;
int totalMaps = config.Maps.Count;
int currentMap = 0;
foreach (var map in config.Maps)
{
currentMap++;
OnStatusChanged?.Invoke(this, $"[{currentMap}/{totalMaps}] Processing '{map.MapName}'...");
if (!mapAddresses.ContainsKey(map.MapName))
{
OnStatusChanged?.Invoke(this, $" Map not scanned, scanning now...");
var addresses = memoryManager.ScanMemoryPatternAll(map.ScanPattern);
if (addresses.Count > 0)
{
mapAddresses[map.MapName] = addresses;
}
else
{
OnStatusChanged?.Invoke(this, $" ⚠️ '{map.MapName}': Pattern not found");
continue;
}
}
if (ApplyWallHack(map.MapName))
{
successMaps++;
OnStatusChanged?.Invoke(this, $" ✅ '{map.MapName}': Applied successfully");
}
else
{
OnStatusChanged?.Invoke(this, $" ❌ '{map.MapName}': Failed to apply");
}
}
OnStatusChanged?.Invoke(this, $"WallHack applied to {successMaps}/{totalMaps} maps!");
}
catch (Exception ex)
{
OnError?.Invoke(this, $"Error applying all: {ex.Message}");
}
});
}
public async Task RestoreAllAsync()
{
if (!isAttached)
{
OnError?.Invoke(this, "Not connected to process!");
return;
}
await Task.Run(() =>
{
try
{
OnStatusChanged?.Invoke(this, "Restoring all maps...");
int successMaps = 0;
int totalMaps = config.Maps.Count;
int currentMap = 0;
foreach (var map in config.Maps)
{
currentMap++;
OnStatusChanged?.Invoke(this, $"[{currentMap}/{totalMaps}] Restoring '{map.MapName}'...");
if (mapAddresses.ContainsKey(map.MapName) && RestoreMap(map.MapName))
{
successMaps++;
OnStatusChanged?.Invoke(this, $" ✅ '{map.MapName}': Restored successfully");
}
else
{
OnStatusChanged?.Invoke(this, $" ⚠️ '{map.MapName}': No addresses to restore");
}
}
OnStatusChanged?.Invoke(this, $"{successMaps}/{totalMaps} maps restored!");
}
catch (Exception ex)
{
OnError?.Invoke(this, $"Error restoring all: {ex.Message}");
}
});
}
public bool IsConnected()
{
return isAttached && memoryManager.IsProcessRunning();
}
public string GetProcessInfo()
{
return memoryManager.GetProcessInfo();
}
public WallHackConfig GetConfig()
{
return config;
}
public void Dispose()
{
memoryManager?.Dispose();
GC.SuppressFinalize(this);
}
}
}