geode/loader/include/Geode/meta/thiscall.hpp

26 lines
724 B
C++
Raw Normal View History

2022-07-30 12:24:03 -04:00
#ifndef GEODE_CORE_META_THISCALL_HPP
#define GEODE_CORE_META_THISCALL_HPP
namespace geode::core::meta::x86 {
template <class Ret, class... Args>
class Thiscall {
private:
template <Ret (*detour)(Args...)>
static Ret __thiscall wrapper(Args... all) {
return detour(all...);
}
public:
static Ret invoke(void* address, Args... all) {
Ret(__thiscall * raw)(Args...) = reinterpret_cast<decltype(raw)>(address);
return raw(all...);
}
template <Ret (*detour)(Args...)>
2022-11-24 16:41:02 -05:00
static auto get_wrapper() {
return reinterpret_cast<void*>(&wrapper<detour>);
2022-07-30 12:24:03 -04:00
}
};
}
#endif /* GEODE_CORE_META_THISCALL_HPP */