geode/loader/include/Geode/modify/Wrapper.hpp

100 lines
8.2 KiB
C++
Raw Normal View History

2022-07-30 12:24:03 -04:00
#pragma once
#include "Traits.hpp"
#include "../utils/addresser.hpp"
2022-07-30 12:24:03 -04:00
#define GEODE_WRAPPER_FOR_IDENTIFIER(identifier) \
/* Default - function Return Class::identifier(Parameters...) does not exist */ \
template < \
class Class, \
class FunctionType, \
class = void \
> \
struct identifier { \
public: \
constexpr static inline auto value = nullptr; \
constexpr static inline auto uuid = nullptr; \
}; \
/* Specialization - function Return Class::identifier(Parameters...) is a member function */ \
template < \
class Class, \
class Return, \
class ...Parameters \
> \
struct identifier< \
Class, \
Return(Parameters...), std::enable_if_t< \
std::is_member_function_pointer_v< \
decltype(substitute<Return(Parameters...)>(&Class::identifier)) \
> \
> \
> { \
private: \
static Return wrapperImpl(Class* self, Parameters... ps) { \
self = addresser::rthunkAdjust(substitute<Return(Parameters...)>(&Class::identifier), self); \
2022-07-30 12:24:03 -04:00
return self->Class::identifier(ps...); \
} \
public: \
constexpr static inline auto value = &wrapperImpl; \
constexpr static inline auto uuid = function_uuid< \
substitute<Return(Parameters...)>(&Class::identifier) \
>::value; \
}; \
/* Specialization - function Return Class::identifier(Parameters...) is a static function */ \
template < \
class Class, \
class Return, \
class ...Parameters \
> \
struct identifier< \
Class, \
Return(Parameters...), std::enable_if_t< \
std::is_pointer_v< \
decltype(substitute<Return(Parameters...)>(&Class::identifier)) \
> \
> \
> { \
private: \
static Return wrapperImpl(Parameters... ps) { \
return Class::identifier(ps...); \
} \
public: \
constexpr static inline auto value = &wrapperImpl; \
constexpr static inline auto uuid = function_uuid< \
substitute<Return(Parameters...)>(&Class::identifier) \
>::value; \
}; \
namespace geode::modifier {
2022-10-20 15:45:43 -04:00
namespace wrap {
2022-07-30 12:24:03 -04:00
GEODE_WRAPPER_FOR_IDENTIFIER(constructor)
GEODE_WRAPPER_FOR_IDENTIFIER(destructor)
};
// template <template<class, class, class=void> class Identifier, class Base, class Derived, class ...Types>
// struct PotentiallyWrongIdentifier {
// template <typename D>
// static std::true_type existsImpl(...);
// template <typename D, typename = std::enable_if_t<
// (... && (
// Identifier<D, Types>::uuid == nullptr ||
// Identifier<Base, Types>::uuid == Identifier<D, Types>::uuid
// ))
// >>
// static std::false_type existsImpl(char);
// template <typename D, typename = std::enable_if_t<
// (... || (
// Identifier<D, Types>::uuid != nullptr &&
// Identifier<Base, Types>::uuid == Identifier<D, Types>::uuid
// ))
// >>
// static std::false_type existsImpl(int);
// static constexpr bool value = decltype(existsImpl<Derived>(0))::value;
// };
}