fix includes + add some doccing

This commit is contained in:
HJfod 2023-01-21 16:00:14 +02:00
parent c8e627d921
commit f089afc27c
7 changed files with 61 additions and 7 deletions

View file

@ -16,4 +16,4 @@ namespace geode {
namespace { namespace {
// to make sure the instance is set into the sharedMod<> in load time // to make sure the instance is set into the sharedMod<> in load time
static auto mod = geode::getMod(); static auto mod = geode::getMod();
} }

View file

@ -4,6 +4,7 @@
#include "loader/Loader.hpp" #include "loader/Loader.hpp"
#include "loader/Log.hpp" #include "loader/Log.hpp"
#include "loader/Mod.hpp" #include "loader/Mod.hpp"
#include "loader/ModEvent.hpp"
#include "loader/Setting.hpp" #include "loader/Setting.hpp"
#include "loader/Dirs.hpp" #include "loader/Dirs.hpp"

View file

@ -26,15 +26,50 @@ namespace geode {
Result<> disable(); Result<> disable();
public: 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 <class Convention, class DetourType> template <class Convention, class DetourType>
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{ auto handlerMetadata = tulip::hook::HandlerMetadata{
.m_convention = std::make_shared<Convention>(), .m_convention = std::make_shared<Convention>(),
.m_abstract = tulip::hook::AbstractFunction::from(detour) .m_abstract = tulip::hook::AbstractFunction::from(detour)
}; };
return Hook::create(owner, address, reinterpret_cast<void*>(detour), displayName, handlerMetadata, hookMetadata); return Hook::create(
owner,
address,
reinterpret_cast<void*>(detour),
displayName,
handlerMetadata,
hookMetadata
);
} }
Hook(Hook const&) = delete; Hook(Hook const&) = delete;

View file

@ -15,8 +15,17 @@ USE_GEODE_NAMESPACE();
Hook::Hook(std::shared_ptr<Impl>&& impl) : m_impl(std::move(impl)) {} Hook::Hook(std::shared_ptr<Impl>&& impl) : m_impl(std::move(impl)) {}
Hook::~Hook() {} 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) { Hook* Hook::create(
auto impl = std::make_shared<Hook::Impl>(address, detour, displayName, handlerMetadata, hookMetadata, owner); 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<Hook::Impl>(
address, detour, displayName, handlerMetadata, hookMetadata, owner
);
return new Hook(std::move(impl)); return new Hook(std::move(impl));
} }

View file

@ -13,7 +13,14 @@ USE_GEODE_NAMESPACE();
class Hook::Impl { class Hook::Impl {
public: 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(); ~Impl();

View file

@ -7,6 +7,7 @@
#include <Geode/loader/Loader.hpp> #include <Geode/loader/Loader.hpp>
#include <Geode/loader/Log.hpp> #include <Geode/loader/Log.hpp>
#include <Geode/loader/Mod.hpp> #include <Geode/loader/Mod.hpp>
#include <Geode/loader/ModEvent.hpp>
#include <Geode/utils/file.hpp> #include <Geode/utils/file.hpp>
#include <Geode/utils/JsonValidation.hpp> #include <Geode/utils/JsonValidation.hpp>
#include <optional> #include <optional>

View file

@ -1,5 +1,6 @@
#include <Geode/Loader.hpp> #include <Geode/Loader.hpp>
#include <Geode/loader/ModJsonTest.hpp> #include <Geode/loader/ModJsonTest.hpp>
#include <Geode/loader/ModEvent.hpp>
USE_GEODE_NAMESPACE(); USE_GEODE_NAMESPACE();