Browse Source

Fix patched jmp location

Bepis 3 years ago
parent
commit
a45ee28303
2 changed files with 9 additions and 1 deletions
  1. 1 1
      BepInEx.IL2CPP/TrampolineGenerator.cs
  2. 8 0
      BepInExTests/TrampolineTests.cs

+ 1 - 1
BepInEx.IL2CPP/TrampolineGenerator.cs

@@ -129,7 +129,7 @@ namespace BepInEx.IL2CPP
 					0x00, 0x00, 0x00, 0x00	// Relative destination address
 				};
 
-				Array.Copy(BitConverter.GetBytes(currentAddress.ToInt32() - address.ToInt32()), 0, jmpBytes, 1, 4);
+				Array.Copy(BitConverter.GetBytes(address.ToInt32() - (currentAddress.ToInt32() + 5)), 0, jmpBytes, 1, 4);
 			}
 
 			return jmpBytes;

+ 8 - 0
BepInExTests/TrampolineTests.cs

@@ -54,6 +54,14 @@ namespace BepInEx.Tests
 
 
 
+			Console.WriteLine("Modified:");
+			Console.WriteLine();
+
+
+			Marshal.Copy(exampleCodePointer, exampleCode, 0, exampleCode.Length);
+			Disassemble(exampleCode, (ulong)exampleCodePointer.ToInt64());
+
+
 			Console.WriteLine();
 			Console.WriteLine("Trampoline:");
 			Console.WriteLine();