diff --git a/entry.cpp b/entry.cpp index cd4cc17d..937e32ca 100644 --- a/entry.cpp +++ b/entry.cpp @@ -16,4 +16,4 @@ namespace geode { namespace { // to make sure the instance is set into the sharedMod<> in load time static auto mod = geode::getMod(); -} \ No newline at end of file +} diff --git a/loader/include/Geode/Loader.hpp b/loader/include/Geode/Loader.hpp index 7dee235d..a1bb4c37 100644 --- a/loader/include/Geode/Loader.hpp +++ b/loader/include/Geode/Loader.hpp @@ -4,6 +4,7 @@ #include "loader/Loader.hpp" #include "loader/Log.hpp" #include "loader/Mod.hpp" +#include "loader/ModEvent.hpp" #include "loader/Setting.hpp" #include "loader/Dirs.hpp" diff --git a/loader/include/Geode/loader/Hook.hpp b/loader/include/Geode/loader/Hook.hpp index d1ef0c3c..c3e89a80 100644 --- a/loader/include/Geode/loader/Hook.hpp +++ b/loader/include/Geode/loader/Hook.hpp @@ -26,15 +26,50 @@ namespace geode { Result<> disable(); public: - static Hook* create(Mod* owner, void* address, void* detour, std::string const& displayName, tulip::hook::HandlerMetadata const& handlerMetadata, tulip::hook::HookMetadata const& hookMetadata); + /** + * 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. + * @param owner The mod that owns this hook; must be provided + * @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 + * @param displayName A human-readable name describing the hook, + * usually the fully qualified name of the function being hooked + * @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->addHook! + */ + static Hook* create( + Mod* owner, + void* address, + void* detour, + std::string const& displayName, + tulip::hook::HandlerMetadata const& handlerMetadata, + tulip::hook::HookMetadata const& hookMetadata + ); template - static Hook* create(Mod* owner, void* address, DetourType detour, std::string const& displayName, tulip::hook::HookMetadata const& hookMetadata = tulip::hook::HookMetadata()) { + static Hook* create( + Mod* owner, + void* address, + DetourType detour, + std::string const& displayName, + tulip::hook::HookMetadata const& hookMetadata = tulip::hook::HookMetadata() + ) { auto handlerMetadata = tulip::hook::HandlerMetadata{ .m_convention = std::make_shared(), .m_abstract = tulip::hook::AbstractFunction::from(detour) }; - return Hook::create(owner, address, reinterpret_cast(detour), displayName, handlerMetadata, hookMetadata); + return Hook::create( + owner, + address, + reinterpret_cast(detour), + displayName, + handlerMetadata, + hookMetadata + ); } Hook(Hook const&) = delete; diff --git a/loader/src/loader/Hook.cpp b/loader/src/loader/Hook.cpp index ee1d5a9b..f3125191 100644 --- a/loader/src/loader/Hook.cpp +++ b/loader/src/loader/Hook.cpp @@ -15,8 +15,17 @@ USE_GEODE_NAMESPACE(); Hook::Hook(std::shared_ptr&& impl) : m_impl(std::move(impl)) {} Hook::~Hook() {} -Hook* Hook::create(Mod* owner, void* address, void* detour, std::string const& displayName, tulip::hook::HandlerMetadata const& handlerMetadata, tulip::hook::HookMetadata const& hookMetadata) { - auto impl = std::make_shared(address, detour, displayName, handlerMetadata, hookMetadata, owner); +Hook* Hook::create( + Mod* owner, + void* address, + void* detour, + std::string const& displayName, + tulip::hook::HandlerMetadata const& handlerMetadata, + tulip::hook::HookMetadata const& hookMetadata +) { + auto impl = std::make_shared( + address, detour, displayName, handlerMetadata, hookMetadata, owner + ); return new Hook(std::move(impl)); } diff --git a/loader/src/loader/HookImpl.hpp b/loader/src/loader/HookImpl.hpp index 5cd891c9..551f38d5 100644 --- a/loader/src/loader/HookImpl.hpp +++ b/loader/src/loader/HookImpl.hpp @@ -13,7 +13,14 @@ USE_GEODE_NAMESPACE(); class Hook::Impl { public: - Impl(void* address, void* detour, std::string const& displayName, tulip::hook::HandlerMetadata const& handlerMetadata, tulip::hook::HookMetadata const& hookMetadata, Mod* owner); + Impl( + void* address, + void* detour, + std::string const& displayName, + tulip::hook::HandlerMetadata const& handlerMetadata, + tulip::hook::HookMetadata const& hookMetadata, + Mod* owner + ); ~Impl(); diff --git a/loader/src/loader/ModImpl.cpp b/loader/src/loader/ModImpl.cpp index aac9a1d9..37da6a7a 100644 --- a/loader/src/loader/ModImpl.cpp +++ b/loader/src/loader/ModImpl.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/loader/test/main/main.cpp b/loader/test/main/main.cpp index 0da97db7..a94d3001 100644 --- a/loader/test/main/main.cpp +++ b/loader/test/main/main.cpp @@ -1,5 +1,6 @@ #include #include +#include USE_GEODE_NAMESPACE();