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
using TodoReturn = void;
struct TodoReturnPlaceholder {};
using TodoReturn = TodoReturnPlaceholder;
// thanks pie
enum class SearchType {

View file

@ -1,6 +1,7 @@
#pragma once
#include "AsStaticFunction.hpp"
#include "Field.hpp"
#include <Geode/Enums.hpp>
#include "IDManager.hpp"
#include <Geode/loader/Loader.hpp>
@ -8,28 +9,36 @@
#include <iostream>
#include <tulip/TulipHook.hpp>
#define GEODE_APPLY_MODIFY_FOR_FUNCTION(AddressInline_, Convention_, ClassName_, FunctionName_, ...) \
do { \
if constexpr (Unique::different< \
Resolve<__VA_ARGS__>::func(&Base::FunctionName_), \
Resolve<__VA_ARGS__>::func(&Derived::FunctionName_)>()) { \
static auto address = AddressInline_; \
if (address == 0) { \
log::error( \
"Address of {} returned nullptr, can't hook", #ClassName_ "::" #FunctionName_ \
); \
break; \
} \
auto hook = Hook::create( \
reinterpret_cast<void*>(address), \
AsStaticFunction_##FunctionName_< \
Derived, \
decltype(Resolve<__VA_ARGS__>::func(&Derived::FunctionName_))>::value, \
#ClassName_ "::" #FunctionName_, \
tulip::hook::TulipConvention::Convention_ \
); \
this->m_hooks[#ClassName_ "::" #FunctionName_] = hook; \
} \
#define GEODE_APPLY_MODIFY_FOR_FUNCTION(AddressInline_, Convention_, ClassName_, FunctionName_, ...) \
do { \
static auto constexpr different = Unique::different< \
Resolve<__VA_ARGS__>::func(&Base::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_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) { \
log::error( \
"Address of {} returned nullptr, can't hook", #ClassName_ "::" #FunctionName_ \
); \
break; \
} \
auto hook = Hook::create( \
reinterpret_cast<void*>(address), \
AsStaticFunction_##FunctionName_< \
Derived, \
DerivedFuncType>::value, \
#ClassName_ "::" #FunctionName_, \
tulip::hook::TulipConvention::Convention_ \
); \
this->m_hooks[#ClassName_ "::" #FunctionName_] = hook; \
} \
} while (0);
#define GEODE_APPLY_MODIFY_FOR_CONSTRUCTOR(AddressInline_, Convention_, ClassName_, ...) \

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
* function type. The return type is ignored.