fix thunk adjust

This commit is contained in:
HJfod 2023-01-23 19:31:38 +02:00
parent d264694700
commit 21e25ff382
5 changed files with 14 additions and 40 deletions

View file

@ -123,7 +123,7 @@ CPMAddPackage("gh:fmtlib/fmt#9.1.0")
CPMAddPackage("gh:gulrak/filesystem#3e5b930")
# Tulip hook (hooking)
CPMAddPackage("gh:geode-sdk/TulipHook#65457c6")
CPMAddPackage("gh:geode-sdk/TulipHook#9980bcf")
target_link_libraries(${PROJECT_NAME} INTERFACE ghc_filesystem fmt TulipHookInclude GeodeCodegenSources)

View file

@ -31,7 +31,7 @@ namespace geode::modifier {{
char const* statics_declare_identifier = R"GEN(
#ifndef GEODE_STATICS_{function_name}
#define GEODE_STATICS_{function_name}
{macro_name}({function_name})
GEODE_AS_STATIC_FUNCTION({function_name})
#endif
)GEN";
@ -94,10 +94,6 @@ std::string generateModifyHeader(Root& root, ghc::filesystem::path const& single
statics += fmt::format(
format_strings::statics_declare_identifier,
fmt::arg("function_name", fn->name),
fmt::arg("macro_name",
(fn->is_virtual ? "GEODE_VIRTUAL_AS_STATIC_FUNCTION" :
"GEODE_AS_STATIC_FUNCTION")
)
);
}
}

View file

@ -22,40 +22,6 @@ namespace geode::modifier {
struct Impl<Return (Class::*)(Params...)> { \
static Return GEODE_CDECL_CALL function(Class* self, Params... params) { \
auto self2 = addresser::rthunkAdjust(Function, self); \
log::debug("{}", __FUNCTION__);\
log::debug("self {} -> self2 {}", (void*)(self), (void*)(self2));\
return self2->Class2::FunctionName_(params...); \
} \
}; \
template <class Return, class Class, class... Params> \
struct Impl<Return (Class::*)(Params...) const> { \
static Return GEODE_CDECL_CALL function(Class const* self, Params... params) { \
auto self2 = addresser::rthunkAdjust(Function, self); \
log::debug("{}", __FUNCTION__);\
log::debug("self {} -> self2 {}", (void*)(self), (void*)(self2));\
return self2->Class2::FunctionName_(params...); \
} \
}; \
static constexpr auto value = &Impl<decltype(Function)>::function; \
};
#define GEODE_VIRTUAL_AS_STATIC_FUNCTION(FunctionName_) \
template <class Class2, auto Function> \
struct AsStaticFunction_##FunctionName_ { \
template <class FunctionType2> \
struct Impl {}; \
template <class Return, class... Params> \
struct Impl<Return (*)(Params...)> { \
static Return GEODE_CDECL_CALL function(Params... params) { \
return Class2::FunctionName_(params...); \
} \
}; \
template <class Return, class Class, class... Params> \
struct Impl<Return (Class::*)(Params...)> { \
static Return GEODE_CDECL_CALL function(Class* self, Params... params) { \
auto self2 = addresser::rthunkAdjust(Function, self); \
log::debug("{}", __FUNCTION__);\
log::debug("self {} -> self2 {}", (void*)(self), (void*)(self2));\
return self2->Class2::FunctionName_(params...); \
} \
}; \

View file

@ -10,6 +10,7 @@
#include <cstdlib>
#include <stddef.h>
#include <type_traits>
#include <Geode/loader/Log.hpp>
namespace geode::addresser {
@ -198,11 +199,19 @@ namespace geode::addresser {
template <typename T, typename F>
inline F thunkAdjust(T func, F self) {
// do NOT delete the line below.
// doing so breaks thunk adjusting on windows.
// why? bruh idk
auto _ = *union_cast<ptrdiff_t*>(&func);
return (F)((intptr_t)self + Addresser::thunkOf(func));
}
template <typename T, typename F>
inline F rthunkAdjust(T func, F self) {
// do NOT delete the line below.
// doing so breaks thunk adjusting on windows.
// why? bruh idk
auto _ = *union_cast<ptrdiff_t*>(&func);
return (F)((intptr_t)self - Addresser::thunkOf(func));
}
#endif

View file

@ -17,6 +17,9 @@ namespace std {
}
#endif
#undef min
#undef max
namespace geode::utils::ranges {
template <class C>
concept ValidConstContainer = requires(C const& c) {