diff options
author | Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> | 2024-08-18 11:21:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-18 12:21:06 +0200 |
commit | 5c730b0bb3ffcb5f6da9b15e05f54f778d86c23f (patch) | |
tree | e49ff21e6fccdadc7f122313756d350159d09cf0 /primedev/core/hooks.h | |
parent | a28c1cb10cc805907d22b656ccc300b39b720a88 (diff) | |
download | NorthstarLauncher-5c730b0bb3ffcb5f6da9b15e05f54f778d86c23f.tar.gz NorthstarLauncher-5c730b0bb3ffcb5f6da9b15e05f54f778d86c23f.zip |
Refactor DLL callbacks (#665)
Cherry-picked from primedev and slightly modified
Co-authored-by: F1F7Y <filip.bartos07@proton.me>
Diffstat (limited to 'primedev/core/hooks.h')
-rw-r--r-- | primedev/core/hooks.h | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/primedev/core/hooks.h b/primedev/core/hooks.h index e5a65354..facf51bf 100644 --- a/primedev/core/hooks.h +++ b/primedev/core/hooks.h @@ -3,7 +3,33 @@ #include <string> #include <iostream> -void InstallInitialHooks(); +//----------------------------------------------------------------------------- +// Purpose: Init minhook +//----------------------------------------------------------------------------- +void HookSys_Init(); + +//----------------------------------------------------------------------------- +// Purpose: MH_MakeHook wrapper +// Input : *ppOriginal - Original function being detoured +// pDetour - Detour function +//----------------------------------------------------------------------------- +inline void HookAttach(PVOID* ppOriginal, PVOID pDetour) +{ + PVOID pAddr = *ppOriginal; + if (MH_CreateHook(pAddr, pDetour, ppOriginal) == MH_OK) + { + if (MH_EnableHook(pAddr) != MH_OK) + { + spdlog::error("Failed enabling a function hook!"); + } + } + else + { + spdlog::error("Failed creating a function hook!"); + } +} + +void CallLoadLibraryACallbacks(LPCSTR lpLibFileName, HMODULE moduleAddress); typedef void (*DllLoadCallbackFuncType)(CModule moduleAddress); void AddDllLoadCallback(std::string dll, DllLoadCallbackFuncType callback, std::string tag = "", std::vector<std::string> reliesOn = {}); |