Operation Big Sister - Make TodoReturn a struct and disallow modifying TodoReturn functions

This commit is contained in:
altalk23 2024-03-27 20:55:14 +03:00
parent 7155705f35
commit f3267b0f43
3 changed files with 57 additions and 23 deletions

View file

@ -1,6 +1,8 @@
#pragma once #pragma once
using TodoReturn = void; struct TodoReturnPlaceholder {};
using TodoReturn = TodoReturnPlaceholder;
// thanks pie // thanks pie
enum class SearchType { enum class SearchType {

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "AsStaticFunction.hpp" #include "AsStaticFunction.hpp"
#include "Field.hpp" #include "Field.hpp"
#include <Geode/Enums.hpp>
#include "IDManager.hpp" #include "IDManager.hpp"
#include <Geode/loader/Loader.hpp> #include <Geode/loader/Loader.hpp>
@ -10,10 +11,18 @@
#define GEODE_APPLY_MODIFY_FOR_FUNCTION(AddressInline_, Convention_, ClassName_, FunctionName_, ...) \ #define GEODE_APPLY_MODIFY_FOR_FUNCTION(AddressInline_, Convention_, ClassName_, FunctionName_, ...) \
do { \ do { \
if constexpr (Unique::different< \ static auto constexpr different = Unique::different< \
Resolve<__VA_ARGS__>::func(&Base::FunctionName_), \ Resolve<__VA_ARGS__>::func(&Base::FunctionName_), \
Resolve<__VA_ARGS__>::func(&Derived::FunctionName_)>()) { \ Resolve<__VA_ARGS__>::func(&Derived::FunctionName_) \
>(); \
using BaseFuncType = decltype(Resolve<__VA_ARGS__>::func(&Base::FunctionName_)); \
using DerivedFuncType = decltype(Resolve<__VA_ARGS__>::func(&Derived::FunctionName_)); \
if constexpr (different) { \
static auto address = AddressInline_; \ static auto address = AddressInline_; \
static_assert(!different || !std::is_same_v<typename ReturnType<BaseFuncType>::type, TodoReturn>, \
"Function" #ClassName_ "::" #FunctionName_ " has a TodoReturn type, " \
"please fix it by editing the bindings." \
); \
if (address == 0) { \ if (address == 0) { \
log::error( \ log::error( \
"Address of {} returned nullptr, can't hook", #ClassName_ "::" #FunctionName_ \ "Address of {} returned nullptr, can't hook", #ClassName_ "::" #FunctionName_ \
@ -24,7 +33,7 @@
reinterpret_cast<void*>(address), \ reinterpret_cast<void*>(address), \
AsStaticFunction_##FunctionName_< \ AsStaticFunction_##FunctionName_< \
Derived, \ Derived, \
decltype(Resolve<__VA_ARGS__>::func(&Derived::FunctionName_))>::value, \ DerivedFuncType>::value, \
#ClassName_ "::" #FunctionName_, \ #ClassName_ "::" #FunctionName_, \
tulip::hook::TulipConvention::Convention_ \ tulip::hook::TulipConvention::Convention_ \
); \ ); \

View file

@ -166,6 +166,29 @@ namespace geode::modifier {
} }
}; };
/**
* Gets the return type of a given resolved function pointer.
*/
template <class Func>
struct ReturnType {
using type = void;
};
template <class Return, class... Params>
struct ReturnType<Return(*)(Params...)> {
using type = Return;
};
template <class Return, class Class, class... Params>
struct ReturnType<Return(Class::*)(Params...)> {
using type = Return;
};
template <class Return, class Class, class... Params>
struct ReturnType<Return(Class::*)(Params...) const> {
using type = Return;
};
/** /**
* A specialization for giving the variadic types as a single type with the * A specialization for giving the variadic types as a single type with the
* function type. The return type is ignored. * function type. The return type is ignored.