-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathProgram.cs
More file actions
146 lines (118 loc) · 5.35 KB
/
Program.cs
File metadata and controls
146 lines (118 loc) · 5.35 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
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
namespace DSDeaths {
class Game {
public readonly string name;
public readonly int[] offsets32;
public readonly int[] offsets64;
public Game(in string name, in int[] offsets32, in int[] offsets64) {
this.name = name;
this.offsets32 = offsets32;
this.offsets64 = offsets64;
}
}
class Program {
const int PROCESS_WM_READ = 0x0010;
const int PROCESS_QUERY_INFORMATION = 0x0400;
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool IsWow64Process(IntPtr hProcess, ref bool Wow64Process);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool ReadProcessMemory(
IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);
static readonly Game[] games =
{
new Game("DARKSOULS", new int[] {0xF78700, 0x5C}, null),
new Game("DarkSoulsII", new int[] {0x1150414, 0x74, 0xB8, 0x34, 0x4, 0x28C, 0x100}, new int[] {0x16148F0, 0xD0, 0x490, 0x104}),
new Game("DarkSoulsIII", null, new int[] {0x47572B8, 0x98}),
new Game("DarkSoulsRemastered", null, new int[] {0x1C8A530, 0x98}),
new Game("Sekiro", null, new int[] {0x3D5AAC0, 0x90}),
new Game("eldenring", null, new int[] {0x3D5DF38, 0x94})
};
static bool Write(int value) {
try {
File.WriteAllText("DSDeaths.txt", value.ToString());
} catch (IOException) {
Console.WriteLine("Could not write to DSDeaths.txt.");
return false;
}
return true;
}
static bool PeekMemory(in IntPtr handle, in IntPtr baseAddress, bool isX64, in int[] offsets, ref int value) {
long address = baseAddress.ToInt64();
byte[] buffer = new byte[8];
int discard = 0;
foreach (int offset in offsets) {
if (address == 0) {
return false;
}
address += offset;
if (!ReadProcessMemory(handle, (IntPtr)address, buffer, 8, ref discard)) {
Console.WriteLine("Could not read game memory.");
return false;
}
address = isX64 ? BitConverter.ToInt64(buffer, 0) : BitConverter.ToInt32(buffer, 0);
}
value = (int)address;
return true;
}
static bool ScanProcesses(ref Process proc, ref Game game) {
foreach (Game g in games) {
Process[] process = Process.GetProcessesByName(g.name);
if (process.Length != 0) {
Console.WriteLine("Found: " + g.name);
proc = process[0];
game = g;
return true;
}
}
return false;
}
static void Main() {
Console.CancelKeyPress += delegate {
Write(0);
};
// put DSDeaths.txt in the same directory as the exe
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
Console.WriteLine("-----------------------------------WARNING-----------------------------------");
Console.WriteLine(" Does NOT work with Elden Ring if Easy Anti-Cheat (EAC) is running.");
Console.WriteLine(" Possible risk of BANS by trying to use with EAC enabled.");
Console.WriteLine(" USE AT YOUR OWN RISK.");
Console.WriteLine("-----------------------------------WARNING-----------------------------------");
Console.WriteLine();
while (true) {
Write(0);
Console.WriteLine("Looking for Dark Souls process...");
Process proc = null;
Game game = null;
while (!ScanProcesses(ref proc, ref game)) {
Thread.Sleep(500);
}
IntPtr handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_WM_READ, false, proc.Id);
IntPtr baseAddress = proc.MainModule.BaseAddress;
int oldValue = 0, value = 0;
bool isWow64 = false;
if (IsWow64Process(handle, ref isWow64)) {
Console.WriteLine("Found " + (isWow64 ? "32" : "64") + " bit variant.");
int[] offsets = isWow64 ? game.offsets32 : game.offsets64;
while (!proc.HasExited) {
if (PeekMemory(handle, baseAddress, !isWow64, offsets, ref value)) {
if (value != oldValue) {
oldValue = value;
Write(value);
Console.WriteLine("Deaths: " + value.ToString());
}
}
Thread.Sleep(500);
}
}
Console.WriteLine("Process has exited.");
Thread.Sleep(2000);
}
}
}
}