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 {};
|
|
|
|
* Modify<hook0<hook0Parent>, MenuLayer> hook0Apply;
|
|
|
|
* struct GEODE_HIDDEN hook0Intermediate: public MenuLayer {
|
|
|
|
* geode::modifier::FieldIntermediate<MenuLayer,
|
|
|
|
* hook0<hook0Intermediate>, hook0<hook0Parent>
|
|
|
|
* > m_fields;
|
|
|
|
* };
|
|
|
|
* }
|
|
|
|
* template<>
|
|
|
|
* struct GEODE_HIDDEN hook0<hook0Parent>: hook0Intermediate {
|
|
|
|
* // 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-10-30 14:59:20 -04:00
|
|
|
#define GEODE_MODIFY_DECLARE_ANONYMOUS(base, derived) \
|
|
|
|
derived##Dummy; \
|
|
|
|
template <class> \
|
|
|
|
struct derived {}; \
|
|
|
|
namespace { \
|
|
|
|
struct derived##Parent {}; \
|
|
|
|
Modify<derived<derived##Parent>, base> derived##Apply; \
|
|
|
|
struct GEODE_HIDDEN derived##Intermediate : base { \
|
|
|
|
mutable geode::modifier::FieldIntermediate< \
|
|
|
|
base, derived##Intermediate, derived<derived##Parent>> \
|
|
|
|
m_fields; \
|
|
|
|
}; \
|
|
|
|
} \
|
|
|
|
template <> \
|
|
|
|
struct GEODE_HIDDEN derived<derived##Parent> : derived##Intermediate
|
|
|
|
|
|
|
|
#define GEODE_MODIFY_DECLARE(base, derived) \
|
|
|
|
derived##Dummy; \
|
|
|
|
struct derived; \
|
|
|
|
namespace { \
|
|
|
|
Modify<derived, base> derived##Apply; \
|
|
|
|
struct GEODE_HIDDEN derived##Intermediate : base { \
|
|
|
|
mutable geode::modifier::FieldIntermediate<base, derived##Intermediate, derived> \
|
|
|
|
m_fields; \
|
|
|
|
}; \
|
|
|
|
} \
|
|
|
|
struct GEODE_HIDDEN derived : derived##Intermediate
|
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
|
|
|
|
|
2022-10-30 14:59:20 -04:00
|
|
|
#define GEODE_EXECUTE_FUNC(Line_) \
|
|
|
|
template <class> \
|
|
|
|
void _##Line_##Function(); \
|
|
|
|
namespace { \
|
|
|
|
struct _##Line_##Unique {}; \
|
|
|
|
} \
|
|
|
|
static inline auto _line = \
|
|
|
|
(Loader::get()->scheduleOnModLoad(nullptr, &_##Line_##Function<_##Line_##Unique>), 0); \
|
|
|
|
template <class> \
|
|
|
|
void _##Line_##Function()
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
|
|
#define $execute GEODE_EXECUTE_FUNC(__LINE__)
|