2023-01-14 14:24:12 -05:00
|
|
|
#pragma once
|
|
|
|
#include "../utils/addresser.hpp"
|
|
|
|
#include "Traits.hpp"
|
2023-01-23 09:53:43 -05:00
|
|
|
#include "../loader/Log.hpp"
|
2023-01-14 14:24:12 -05:00
|
|
|
|
|
|
|
namespace geode::modifier {
|
|
|
|
/**
|
|
|
|
* A helper struct that generates a static function that calls the given function.
|
|
|
|
*/
|
|
|
|
#define GEODE_AS_STATIC_FUNCTION(FunctionName_) \
|
2023-01-26 08:10:11 -05:00
|
|
|
template <class Class2, class FunctionType> \
|
2023-01-14 14:24:12 -05:00
|
|
|
struct AsStaticFunction_##FunctionName_ { \
|
|
|
|
template <class FunctionType2> \
|
|
|
|
struct Impl {}; \
|
|
|
|
template <class Return, class... Params> \
|
|
|
|
struct Impl<Return (*)(Params...)> { \
|
2023-01-23 09:53:43 -05:00
|
|
|
static Return GEODE_CDECL_CALL function(Params... params) { \
|
|
|
|
return Class2::FunctionName_(params...); \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
template <class Return, class Class, class... Params> \
|
|
|
|
struct Impl<Return (Class::*)(Params...)> { \
|
|
|
|
static Return GEODE_CDECL_CALL function(Class* self, Params... params) { \
|
2023-01-25 12:29:13 -05:00
|
|
|
auto self2 = addresser::rthunkAdjust( \
|
|
|
|
Resolve<Params...>::func(&Class2::FunctionName_), self \
|
|
|
|
); \
|
2023-01-14 14:24:12 -05:00
|
|
|
return self2->Class2::FunctionName_(params...); \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
template <class Return, class Class, class... Params> \
|
|
|
|
struct Impl<Return (Class::*)(Params...) const> { \
|
2023-01-21 15:44:37 -05:00
|
|
|
static Return GEODE_CDECL_CALL function(Class const* self, Params... params) { \
|
2023-01-25 12:29:13 -05:00
|
|
|
auto self2 = addresser::rthunkAdjust( \
|
|
|
|
Resolve<Params...>::func(&Class2::FunctionName_), self \
|
|
|
|
); \
|
2023-01-14 14:24:12 -05:00
|
|
|
return self2->Class2::FunctionName_(params...); \
|
|
|
|
} \
|
|
|
|
}; \
|
2023-01-26 08:10:11 -05:00
|
|
|
static constexpr auto value = &Impl<FunctionType>::function; \
|
2023-01-14 14:24:12 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
GEODE_AS_STATIC_FUNCTION(constructor)
|
|
|
|
GEODE_AS_STATIC_FUNCTION(destructor)
|
|
|
|
}
|