move tulip wrappers to their own namespace

This commit is contained in:
HJfod 2023-01-23 22:14:36 +02:00
parent b9dfd1b115
commit 9be7bea66f
6 changed files with 44 additions and 39 deletions
codegen/src
loader

View file

@ -8,7 +8,7 @@ namespace { namespace format_strings {
#include <Geode/utils/addresser.hpp>
#include <Geode/modify/Addresses.hpp>
#include <Geode/modify/Traits.hpp>
#include <Geode/loader/Loader.hpp>
#include <Geode/loader/Tulip.hpp>
using namespace geode;
using namespace geode::modifier;
@ -30,7 +30,7 @@ CCDestructor::~CCDestructor() {{
}}
auto wrapFunction(uintptr_t address, tulip::hook::WrapperMetadata const& metadata) {
auto wrapped = Loader::get()->createWrapper(reinterpret_cast<void*>(address), metadata);
auto wrapped = geode::hook::createWrapper(reinterpret_cast<void*>(address), metadata);
if (wrapped.isErr()) {{
throw std::runtime_error(wrapped.unwrapErr());
}}
@ -42,7 +42,7 @@ auto wrapFunction(uintptr_t address, tulip::hook::WrapperMetadata const& metadat
auto {class_name}::{function_name}({parameters}){const} -> decltype({function_name}({arguments})) {{
using FunctionType = decltype({function_name}({arguments}))(*)({class_name}{const}*{parameter_comma}{parameter_types});
static auto func = wrapFunction(address<{addr_index}>(), tulip::hook::WrapperMetadata{{
.m_convention = Loader::get()->createConvention(tulip::hook::TulipConvention::{convention}),
.m_convention = geode::hook::createConvention(tulip::hook::TulipConvention::{convention}),
.m_abstract = tulip::hook::AbstractFunction::from(FunctionType(nullptr)),
}});
return reinterpret_cast<FunctionType>(func)(this{parameter_comma}{arguments});
@ -54,7 +54,7 @@ auto {class_name}::{function_name}({parameters}){const} -> decltype({function_na
auto self = addresser::thunkAdjust(Resolve<{parameter_types}>::func(&{class_name}::{function_name}), this);
using FunctionType = decltype({function_name}({arguments}))(*)({class_name}{const}*{parameter_comma}{parameter_types});
static auto func = wrapFunction(address<{addr_index}>(), tulip::hook::WrapperMetadata{{
.m_convention = Loader::get()->createConvention(tulip::hook::TulipConvention::{convention}),
.m_convention = geode::hook::createConvention(tulip::hook::TulipConvention::{convention}),
.m_abstract = tulip::hook::AbstractFunction::from(FunctionType(nullptr)),
}});
return reinterpret_cast<FunctionType>(func)(self{parameter_comma}{arguments});
@ -65,7 +65,7 @@ auto {class_name}::{function_name}({parameters}){const} -> decltype({function_na
auto {class_name}::{function_name}({parameters}){const} -> decltype({function_name}({arguments})) {{
using FunctionType = decltype({function_name}({arguments}))(*)({parameter_types});
static auto func = wrapFunction(address<{addr_index}>(), tulip::hook::WrapperMetadata{{
.m_convention = Loader::get()->createConvention(tulip::hook::TulipConvention::{convention}),
.m_convention = geode::hook::createConvention(tulip::hook::TulipConvention::{convention}),
.m_abstract = tulip::hook::AbstractFunction::from(FunctionType(nullptr)),
}});
return reinterpret_cast<FunctionType>(func)({arguments});
@ -79,7 +79,7 @@ auto {class_name}::{function_name}({parameters}){const} -> decltype({function_na
if (CCDestructor::lock(this)) return;
using FunctionType = void(*)({class_name}*{parameter_comma}{parameter_types});
static auto func = wrapFunction(address<{addr_index}>(), tulip::hook::WrapperMetadata{{
.m_convention = Loader::get()->createConvention(tulip::hook::TulipConvention::{convention}),
.m_convention = geode::hook::createConvention(tulip::hook::TulipConvention::{convention}),
.m_abstract = tulip::hook::AbstractFunction::from(FunctionType(nullptr)),
}});
reinterpret_cast<FunctionType>(func)(this{parameter_comma}{arguments});
@ -99,7 +99,7 @@ auto {class_name}::{function_name}({parameters}){const} -> decltype({function_na
{class_name}::~{unqualified_class_name}();
using FunctionType = void(*)({class_name}*{parameter_comma}{parameter_types});
static auto func = wrapFunction(address<{addr_index}>(), tulip::hook::WrapperMetadata{{
.m_convention = Loader::get()->createConvention(tulip::hook::TulipConvention::{convention}),
.m_convention = geode::hook::createConvention(tulip::hook::TulipConvention::{convention}),
.m_abstract = tulip::hook::AbstractFunction::from(FunctionType(nullptr)),
}});
reinterpret_cast<FunctionType>(func)(this{parameter_comma}{arguments});

View file

@ -4,6 +4,7 @@
#include "../hook-core/Hook.hpp"
#include "../utils/general.hpp"
#include "../external/json/json_fwd.hpp"
#include "Tulip.hpp"
#include <inttypes.h>
#include <string_view>
#include <tulip/TulipHook.hpp>
@ -60,7 +61,7 @@ namespace geode {
tulip::hook::HookMetadata const& hookMetadata = tulip::hook::HookMetadata()
) {
auto handlerMetadata = tulip::hook::HandlerMetadata{
.m_convention = Loader::get()->createConvention(convention),
.m_convention = geode::hook::createConvention(convention),
.m_abstract = tulip::hook::AbstractFunction::from(detour)
};
return Hook::create(

View file

@ -5,7 +5,6 @@
#include "Log.hpp"
#include "ModInfo.hpp"
#include "Types.hpp"
#include <tulip/TulipHook.hpp>
#include <atomic>
#include <mutex>
@ -80,20 +79,6 @@ namespace geode {
bool didLastLaunchCrash() const;
/**
* Create a calling convention wrapper for a function.
*/
Result<void*> createWrapper(
void* address,
tulip::hook::WrapperMetadata const& metadata
) noexcept;
/**
* Create an abstract calling convention handler for TulipHook
*/
std::shared_ptr<tulip::hook::CallingConvention> createConvention(
tulip::hook::TulipConvention convention
) noexcept;
friend class LoaderImpl;
friend Mod* takeNextLoaderMod();

View file

@ -0,0 +1,20 @@
#pragma once
#include <tulip/TulipHook.hpp>
namespace geode::hook {
/**
* Create a calling convention wrapper for a function.
*/
GEODE_DLL tulip::hook::Result<void*> createWrapper(
void* address,
tulip::hook::WrapperMetadata const& metadata
) noexcept;
/**
* Create an abstract calling convention handler for TulipHook
*/
GEODE_DLL std::shared_ptr<tulip::hook::CallingConvention> createConvention(
tulip::hook::TulipConvention convention
) noexcept;
}

View file

@ -122,19 +122,3 @@ bool Loader::didLastLaunchCrash() const {
Mod* Loader::takeNextMod() {
return m_impl->takeNextMod();
}
Result<void*> Loader::createWrapper(void* address, tulip::hook::WrapperMetadata const& metadata) noexcept {
auto res = tulip::hook::createWrapper(address, metadata);
if (res) {
return Ok(res.unwrap());
}
else {
return Err(res.unwrapErr());
}
}
std::shared_ptr<tulip::hook::CallingConvention> Loader::createConvention(
tulip::hook::TulipConvention convention
) noexcept {
return tulip::hook::createConvention(convention);
}

View file

@ -0,0 +1,15 @@
#include <Geode/loader/Tulip.hpp>
tulip::hook::Result<void*> geode::hook::createWrapper(
void* address,
tulip::hook::WrapperMetadata const& metadata
) noexcept {
return tulip::hook::createWrapper(address, metadata);
}
std::shared_ptr<tulip::hook::CallingConvention> geode::hook::createConvention(
tulip::hook::TulipConvention convention
) noexcept {
return tulip::hook::createConvention(convention);
}