- Home
- Developer Documentation
- Mod lifecycle
Mod lifecycle
What happens from loading to unloading.
Load#
- The injector checks the target: 64-bit, the right process name, no anti-cheat module, and the SHA-256 of the game executable.
- The DLL is loaded with
LoadLibraryW. The game executable is not patched. - The
DllMainpart of the framework starts your thread and checks the SHA-256 and all byte signatures in memory. If anything is off,sw_mod_start()is not called and the console says why. sw_mod_start()runs on its own thread. Until you set hooks, your code has no effect on game threads.
Unload#
- The loader (or the in-game mod menu) calls the export
swmod_shutdown(). - The framework sets
sw::mod::running()tofalse, waits for yoursw_mod_start()thread to end, callssw_mod_stop()and removes all hooks of the mod. - It waits until no game thread is still inside a callback of the DLL (
sw::Hook::idle()). - Only then is the DLL freed.
If a callback is still busy after up to 5 seconds, the DLL is left loaded: a small leak beats a crash.
Rules#
- Loops check
sw::mod::sleep(ms)orsw::mod::running(). - Callbacks are short; slow work goes to the mod thread.
- Do not keep pointers into the DLL after
sw_mod_stop().