✅ .NET Framework 4.7.2 - DLL Injection

Hi all, I am trying to make a ModLoader for a game that uses the XNA Framework on .NET 4.7.2
I have a ModLoader executable I have made that attempts to inject my Patcher dll into the process during runtime so that Harmony Lib can be used to make patches.
The ModLoader uses an inject function to inject my patcher DLL:
C#
 public static bool Inject(Process targetProcess)
        {
            IntPtr hProcess = OpenProcess(0x1F0FFF, false, targetProcess.Id); //The handler to the game process, with all access rights 
            if (hProcess == IntPtr.Zero) return false;

            byte[] dllPathBytes = Encoding.UTF8.GetBytes(patcherPath + "\0"); //Convert the path to SpeedPatcher.dll to a byte array
            IntPtr allocMem = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)dllPathBytes.Length, 0x3000, 0x40); //Allocate memory in the game
            if (allocMem == IntPtr.Zero) return false; //If we cannot allocate memory in the game process, return false

            if (!WriteProcessMemory(hProcess, allocMem, dllPathBytes, (uint)dllPathBytes.Length, out _)) return false; //Write the path to SpeedPatcher.dll into the allocated memory in the game process, if this fails, return false

            IntPtr loadLibAddr = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA"); //Get the address of the LoadLibraryA function in kernel32.dll, which we will call in the remote thread
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLibAddr, allocMem, 0, IntPtr.Zero); //Create a remote thread in the game process that calls LoadLibraryA with the path to SpeedPatcher.dll

            return hThread != IntPtr.Zero; //If the remote thread is created successfully, return true, otherwise return false

        }


When I run the executable, it is able to find the DLL, It says injection was successful, but when the game is running the patch has done nothing, does anybody know troubleshooting steps to figure this out?
Was this page helpful?