2022-07-30 12:24:03 -04:00
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main class implementation, it has the structure
|
2022-10-30 14:59:20 -04:00
|
|
|
*
|
2022-07-30 12:24:03 -04:00
|
|
|
* class hook0Dummy;
|
|
|
|
* template<typename>
|
|
|
|
* struct hook0 {};
|
|
|
|
* namespace {
|
|
|
|
* struct hook0Parent {};
|
|
|
|
* }
|
|
|
|
* template<>
|
2022-11-09 12:11:50 -05:00
|
|
|
* struct GEODE_HIDDEN hook0<hook0Parent> : Modify<hook0<hook0Parent>, MenuLayer> {
|
2022-07-30 12:24:03 -04:00
|
|
|
* // code stuff idk
|
|
|
|
* };
|
2022-10-30 14:59:20 -04:00
|
|
|
*
|
2022-07-30 12:24:03 -04:00
|
|
|
* I tried to make the macro as verbose as it can be but
|
|
|
|
* I am bad at this stuff
|
|
|
|
*/
|
|
|
|
|
2022-11-09 12:11:50 -05:00
|
|
|
#define GEODE_MODIFY_DECLARE_ANONYMOUS(base, derived) \
|
|
|
|
derived##Dummy; \
|
|
|
|
template <class> \
|
|
|
|
struct derived {}; \
|
|
|
|
namespace { \
|
|
|
|
struct derived##Parent {}; \
|
|
|
|
} \
|
|
|
|
template <> \
|
|
|
|
struct GEODE_HIDDEN derived<derived##Parent> : geode::Modify<derived<derived##Parent>, base>
|
2022-10-30 14:59:20 -04:00
|
|
|
|
2022-11-09 12:11:50 -05:00
|
|
|
#define GEODE_MODIFY_DECLARE(base, derived) \
|
|
|
|
derived##Dummy; \
|
|
|
|
struct GEODE_HIDDEN derived : geode::Modify<derived, base>
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
|
|
#define GEODE_MODIFY_REDIRECT4(base, derived) GEODE_MODIFY_DECLARE(base, derived)
|
|
|
|
#define GEODE_MODIFY_REDIRECT3(base, derived) GEODE_MODIFY_DECLARE_ANONYMOUS(base, derived)
|
|
|
|
#define GEODE_MODIFY_REDIRECT2(base) GEODE_MODIFY_REDIRECT3(base, GEODE_CONCAT(hook, __LINE__))
|
|
|
|
#define GEODE_MODIFY_REDIRECT1(base) GEODE_MODIFY_REDIRECT2(base)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interfaces for the class implementation
|
2022-10-30 14:59:20 -04:00
|
|
|
*
|
2022-07-30 12:24:03 -04:00
|
|
|
* class $modify(MenuLayer) {};
|
|
|
|
* class $modify(MyMenuLayerInterface, MenuLayer) {};
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define GEODE_CRTP1(base) GEODE_MODIFY_REDIRECT1(base)
|
|
|
|
#define GEODE_CRTP2(derived, base) GEODE_MODIFY_REDIRECT4(base, derived)
|
2022-10-30 14:59:20 -04:00
|
|
|
#define $modify(...) \
|
|
|
|
GEODE_INVOKE(GEODE_CONCAT(GEODE_CRTP, GEODE_NUMBER_OF_ARGS(__VA_ARGS__)), __VA_ARGS__)
|
2022-07-30 12:24:03 -04:00
|
|
|
#define $(...) $modify(__VA_ARGS__)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get current hook class without needing to name it.
|
|
|
|
* Useful for callbacks
|
|
|
|
*/
|
|
|
|
#define $cls std::remove_pointer<decltype(this)>::type
|
|
|
|
|
|
|
|
#define GEODE_ONLY_FIELD(type, field_, default_) private: field<type> field_ = default_; public:
|
|
|
|
#define GEODE_INTERNAL_FIELD(type, field, name) inline type& name() { return this->*field; }
|
|
|
|
//#define GEODE_EXTERNAL_FIELD(type, field, name) static inline type& name##From(void* self) { return reinterpret_cast<decltype(this)>(self)->*field; }
|
|
|
|
#define GEODE_FIELD(type, field, name, default_) GEODE_ONLY_FIELD(type, field, default_) GEODE_INTERNAL_FIELD(type, field, name) //GEODE_EXTERNAL_FIELD(type, field, name)
|
|
|
|
|
|
|
|
|
2022-10-22 15:10:36 -04:00
|
|
|
#define $execute \
|
2022-07-30 12:24:03 -04:00
|
|
|
template<class> \
|
2022-10-22 15:40:38 -04:00
|
|
|
void GEODE_CONCAT(geodeExecFunction, __LINE__)(); \
|
2022-07-30 12:24:03 -04:00
|
|
|
namespace { \
|
2022-10-22 15:40:38 -04:00
|
|
|
struct GEODE_CONCAT(ExecFuncUnique, __LINE__) {}; \
|
2022-07-30 12:24:03 -04:00
|
|
|
} \
|
2022-10-24 04:43:17 -04:00
|
|
|
static inline auto GEODE_CONCAT(Exec, __LINE__) = (Loader::get()->scheduleOnModLoad(\
|
2022-10-22 15:10:36 -04:00
|
|
|
nullptr, &GEODE_CONCAT(geodeExecFunction, __LINE__)<GEODE_CONCAT(ExecFuncUnique, __LINE__)> \
|
2022-07-30 12:24:03 -04:00
|
|
|
), 0); \
|
|
|
|
template<class> \
|
2022-10-22 15:10:36 -04:00
|
|
|
void GEODE_CONCAT(geodeExecFunction, __LINE__)()
|