Created
January 23, 2024 00:20
-
-
Save absoIute/3b160bec2938fdbe2a855f512edd306c to your computer and use it in GitHub Desktop.
Geode Translation Layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Geode/utils/Result.hpp> | |
#include <Geode/loader/Tulip.hpp> | |
namespace geode | |
{ | |
class Hook; | |
class Loader | |
{ | |
protected: | |
Mod *takeNextMod(); | |
public: | |
static Loader *get(); | |
friend Mod *takeNextLoaderMod(); | |
}; | |
inline GEODE_HIDDEN Mod *takeNextLoaderMod() | |
{ | |
return Loader::get()->takeNextMod(); | |
} | |
namespace hook | |
{ | |
std::shared_ptr<tulip::hook::CallingConvention> createConvention(tulip::hook::TulipConvention convention) noexcept; | |
} | |
class Hook | |
{ | |
public: | |
static std::shared_ptr<Hook> create(void *address, void *detour, std::string const &displayName, tulip::hook::HandlerMetadata const &handlerMetadata, tulip::hook::HookMetadata const &hookMetadata); | |
}; | |
class Mod | |
{ | |
public: | |
template <class = void> | |
static inline GEODE_HIDDEN Mod *sharedMod = nullptr; | |
template <class = void> | |
static inline GEODE_HIDDEN Mod *get() | |
{ | |
if (!sharedMod<>) | |
sharedMod<> = takeNextLoaderMod(); | |
return sharedMod<>; | |
} | |
std::string getName() const; | |
Result<Hook *> claimHook(std::shared_ptr<Hook> hook); | |
}; | |
} | |
namespace GeodeTranslationLayer | |
{ | |
static auto mod = geode::Mod::get(); | |
template <class ReturnType, class Class, class HookF, class... Params> | |
void Hook(ReturnType(Class:: *f)(Params...), HookF hookf, const char *name, tulip::hook::TulipConvention convention = tulip::hook::TulipConvention::Thiscall) | |
{ | |
auto mod = geode::Mod::get(); | |
tulip::hook::HandlerMetadata handleMeta = { | |
.m_convention = geode::hook::createConvention(convention), | |
.m_abstract = tulip::hook::AbstractFunction::from(static_cast<HookF>(nullptr)), | |
}; | |
mod->claimHook(geode::Hook::create(sx_void_cast(f), hookf, name, handleMeta, tulip::hook::HookMetadata())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi! you have your asterisks in the wrong spot. sorry