From 5268bc631b41736a5ec956c6761532508582412a Mon Sep 17 00:00:00 2001 From: matcool <26722564+matcool@users.noreply.github.com> Date: Thu, 18 Jan 2024 13:20:48 -0300 Subject: [PATCH] add docs --- loader/include/Geode/loader/Hook.hpp | 10 ++++++---- loader/include/Geode/loader/Mod.hpp | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/loader/include/Geode/loader/Hook.hpp b/loader/include/Geode/loader/Hook.hpp index 9e55939e..bbf928b0 100644 --- a/loader/include/Geode/loader/Hook.hpp +++ b/loader/include/Geode/loader/Hook.hpp @@ -25,9 +25,11 @@ namespace geode { public: /** - * Create a hook at an address. The hook is enabled immediately. By - * default, the hook is placed at the end of the detour list; however, - * this can be controlled using metadata settings. + * Create a hook at an address. By default, the hook is disabled and + * placed at the end of the detour list; however, this can be + * controlled using metadata settings. + * After creating the hook object, we recommend you set its owner + * by calling `Mod::claimHook`, see its docs for more info. * @param address The address to hook * @param detour The detour to run when the hook is hit. The detour's * calling convention should be cdecl @@ -36,7 +38,7 @@ namespace geode { * @param handlerMetadata Metadata for the hook handler * @param hookMetadata Metadata for the hook itself * @returns The created hook, or an error. Make sure to add the created - * hook to the mod that owns it using mod->claimHook! + * hook to the mod that owns it using mod->claimHook(hook)! */ static std::shared_ptr<Hook> create( void* address, diff --git a/loader/include/Geode/loader/Mod.hpp b/loader/include/Geode/loader/Mod.hpp index 14aa1959..73996585 100644 --- a/loader/include/Geode/loader/Mod.hpp +++ b/loader/include/Geode/loader/Mod.hpp @@ -265,8 +265,20 @@ namespace geode { return Ok(ptr); } + /** + * Claims an existing hook object, marking this mod as its owner. + * If the hook has "auto enable" set, this will enable the hook. + * @returns Returns a pointer to the hook, or an error if the + * hook already has an owner, or was unable to enable the hook. + */ Result<Hook*> claimHook(std::shared_ptr<Hook>&& hook); + /** + * Disowns a hook which this mod owns, making this mod no longer its owner. + * If the hook has "auto enable" set, this will disable the hook. + * @returns Returns an error if this mod doesn't own the hook, or + * if disabling the hook failed. + */ Result<> disownHook(Hook* hook); /** @@ -288,8 +300,20 @@ namespace geode { return Ok(ptr); } + /** + * Claims an existing patch object, marking this mod as its owner. + * If the patch has "auto enable" set, this will enable the patch. + * @returns Returns a pointer to the patch, or an error if the + * patch already has an owner, or was unable to enable the patch. + */ Result<Patch*> claimPatch(std::shared_ptr<Patch>&& patch); + /** + * Disowns a patch which this mod owns, making this mod no longer its owner. + * If the patch has "auto enable" set, this will disable the patch. + * @returns Returns an error if this mod doesn't own the patch, or + * if disabling the patch failed. + */ Result<> disownPatch(Patch* patch); /**