Skip to content

Commit 0e075df

Browse files
committed
add the base address to the patch address, fix struct initialization
1 parent a01653a commit 0e075df

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

patch1337tocpp/Program.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ static void Main(string[] args) {
4646

4747
w.WriteLine("#include <vector>");
4848
w.WriteLine("#include <windows.h>");
49+
w.WriteLine("int BaseAddress = (int)GetModuleHandle(nullptr);");
4950
w.Write("struct PatchAddress { ");
5051
w.Write("int Address; ");
5152
w.Write("unsigned char OldByte; ");
5253
w.Write("unsigned char NewByte; ");
5354
w.WriteLine("};");
5455
w.Write("struct Patch { ");
55-
w.Write("char* ModuleName; ");
56+
w.Write("const char* ModuleName; ");
5657
w.Write("std::vector<PatchAddress> Patches;");
5758
w.WriteLine("};");
5859
w.WriteLine("void PatchUChar(unsigned char* dst, unsigned char* src, int size) {");
@@ -74,12 +75,12 @@ static void Main(string[] args) {
7475

7576
w.WriteLine($"void patch_{addressableName}() {{");
7677
w.WriteLine($"for (PatchAddress addr : {addressableName}.Patches) {{");
77-
w.WriteLine("PatchUChar((unsigned char*)addr.Address, &addr.NewByte, 1); }");
78+
w.WriteLine("PatchUChar((unsigned char*)(BaseAddress + addr.Address), &addr.NewByte, 1); }");
7879
w.WriteLine("};");
7980

8081
w.WriteLine($"void unpatch_{addressableName}() {{");
8182
w.WriteLine($"for (PatchAddress addr : {addressableName}.Patches) {{");
82-
w.WriteLine("PatchUChar((unsigned char*)addr.Address,&addr.OldByte, 1); }");
83+
w.WriteLine("PatchUChar((unsigned char*)(BaseAddress + addr.Address), &addr.OldByte, 1); }");
8384
w.WriteLine("};");
8485
}
8586

0 commit comments

Comments
 (0)