Skip to content

Instantly share code, notes, and snippets.

@absoIute
Created January 23, 2024 00:20
Show Gist options
  • Save absoIute/3b160bec2938fdbe2a855f512edd306c to your computer and use it in GitHub Desktop.
Save absoIute/3b160bec2938fdbe2a855f512edd306c to your computer and use it in GitHub Desktop.
Geode Translation Layer
#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()));
}
}
@matcool
Copy link

matcool commented Jan 28, 2024

hi! you have your asterisks in the wrong spot. sorry

@altalk23
Copy link

good boy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment