-
-
Notifications
You must be signed in to change notification settings - Fork 38
Description
Hi! This is both a request to improve the documentation and an attempt to verify that my understanding of the process.
Please correct me if I'm wrong. To hook a native call in a C++ game, I need:
-
Launcher: Write a C# application that will launch the game process in the Suspended state and inject a C++ DLL into it, wait for initialization to complete and resume the process.
1.1. To start a process in the Suspended state, use WinAPI CreateProcess with the appropriate flag.
1.2. To load the library, use WinAPI CreateThread(loadLibraryWPtr, pathPtr)
1.3. To allocate memory in a remote process and pass the path to the loaded library, use Kernel32.VirtualAllocEx
1.4. Reloaded.Injector is not suitable for this task, since it cannot inject itself into processes in the Suspended State.
1.5. To bypass the restrictions of Steam, which may refuse to enable the overlay if the original launcher has been replaced, register the custom launcher registration as Debugger in the Windows registry for the original.exe. -
Bootstrap: Write a native C++ DLL that will be injected by the launcher to the game process and then rise the .NET Runtime.
2.1 x86 for x86 games, x64 for x64 games
2.2. This is a simple example: Reloaded.Core.Bootstrap
2.3. This is a advanced example of DllMain which raises .NET Runtime in a separate thread, thereby avoiding deadlock: Reloaded.Mod.Loader.Bootstrapper -
.NET Mod: Write a managed .NET8+ DLL that will be loaded from async thread in DllMain and will use Reloaded.Hooks
3.1 Good example of how to call it from DllMain: Reloaded.Mod.Loader.Bootstrapper
3.2 RTFM: GettingStarted
Am I understanding everything correctly?
Or are there already easier ways to do this?
P.S. Just in case, I’ll explain why, with lack of knowledge about the wonderful world of C++, I write a launcher myself, rather than using Reloaded-II:
It's all about delivering the mod to the end player:
I would like to have one .exe file or .zip archive that needs to be launched/unpacked into the game, after which launching the game on Steam will launch a modified version of the game without performing any additional actions.
At the same time, I want to remain compatible with the latest version of all libraries (which makes it seem like a bad idea to ship Reloaded with the mod in the same archive).
At the same time, I want not to break compatibility with other mods that the player already has installed.
As far as I know, you are currently developing Reloaded-3. Perhaps these comments will give you some ideas.
In my ideal world, Reloaded could package itself and selected mods into a self-contained .exe file, which when run, would check for Reloaded in the game folder. If it exists, the mod will add it to it. If it is not there, it will unpack it from the archive or offer to download a newer version if there is a network. Then it will launch the game. And each subsequent launch through this .exe file will launch the game with the mod forcibly enabled (and the rest that are included in Reloaded, if any) without displaying the Reloaded window.