hooks try to get enabled

This commit is contained in:
altalk23 2022-12-13 16:32:49 +03:00
parent eeb4bea97a
commit cef0f3f3bb
5 changed files with 23 additions and 20 deletions

View file

@ -132,7 +132,7 @@ CPMAddPackage("gh:mity/md4c#e9ff661")
target_include_directories(${PROJECT_NAME} PRIVATE ${md4c_SOURCE_DIR}/src)
# Tulip hook (hooking)
CPMAddPackage("gh:altalk23/TulipHook#92b3cca")
CPMAddPackage("gh:altalk23/TulipHook#5ba99a8")
target_link_libraries(${PROJECT_NAME} md4c z TulipHook geode-sdk)
@ -143,7 +143,6 @@ target_precompile_headers(${PROJECT_NAME} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/Loader.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/UI.hpp"
# "${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/Bindings.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/Modify.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/cocos/include/cocos2d.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/cocos/extensions/cocos-ext.h"
)

View file

@ -12,7 +12,7 @@
#include <tulip/TulipHook.hpp>
#define GEODE_APPLY_MODIFY_FOR_FUNCTION(addr_index, pure_index, convention, className, functionName) \
{ \
do { \
using DerivedWrap = wrap::functionName<Derived, types::pure##pure_index>; \
using BaseWrap = wrap::functionName<Base, types::pure##pure_index>; \
if constexpr (DerivedWrap::uuid != nullptr && (void*)BaseWrap::uuid != (void*)DerivedWrap::uuid) { \
@ -22,9 +22,9 @@
DerivedWrap::value, \
#className "::" #functionName \
); \
BaseModify::m_hooks[FunctionUUID<DerivedWrap::value>::value] = hook; \
this->m_hooks[#className "::" #functionName] = hook; \
} \
}
} while (0);
namespace geode::modifier {
@ -34,25 +34,25 @@ namespace geode::modifier {
template <class ModifyDerived>
class ModifyBase {
public:
std::map<void (*)(), Hook*> m_hooks;
std::map<std::string, Hook*> m_hooks;
template <auto Function>
Result<Hook*> getHook() {
auto uuid = FunctionUUID<Function>::value;
if (m_hooks.find(uuid) == m_hooks.end()) {
Result<Hook*> getHook(std::string const& name) {
if (m_hooks.find(name) == m_hooks.end()) {
return Err("Hook not in this modify");
}
return m_hooks[uuid];
return Ok(m_hooks[name]);
}
// unordered_map<handles> idea
ModifyBase() {
this->apply();
// i really dont want to recompile codegen
auto test = static_cast<ModifyDerived*>(this);
test->ModifyDerived::apply();
ModifyDerived::Derived::onModify(*this);
for (auto& [uuid, hook] : m_hooks) {
auto res = Mod::get()->addHook(hook);
if (!res) {
log::error("Failed to add hook: {}", res.error());
log::error("Failed to add hook {}: {}", hook->getDisplayName(), res.error());
}
}
}

View file

@ -7,7 +7,9 @@ Hook::Impl::Impl(void* address, void* detour, std::string const& displayName, tu
m_displayName(displayName),
m_handlerMetadata(handlerMetadata),
m_hookMetadata(hookMetadata),
m_owner(owner) {}
m_owner(owner),
m_enabled(false),
m_autoEnable(true) {}
Hook::Impl::~Impl() {
if (m_enabled) {
auto res = this->disable();
@ -46,11 +48,10 @@ Result<> Hook::Impl::enable() {
if (!LoaderImpl::get()->hasHandler(m_address)) {
GEODE_UNWRAP(LoaderImpl::get()->createHandler(m_address, m_handlerMetadata));
}
GEODE_UNWRAP_INTO(auto handler, LoaderImpl::get()->getHandler(m_address));
m_handle = tulip::hook::createHook(handler, m_detour, m_hookMetadata);
log::debug("Enabling hook at function {}", m_displayName);
log::debug("Enabling hook at function {} with address {}", m_displayName, m_address);
m_enabled = true;
}
return Ok();

View file

@ -409,9 +409,12 @@ bool Mod::depends(std::string const& id) const {
// Hooks
Result<> Mod::enableHook(Hook* hook) {
log::debug("Enabling hook {} for mod {}", (void*)hook, m_info.id);
log::debug("Enabling hook {} for mod {} at address {}", (void*)hook, m_info.id, (void*)hook->getAddress());
auto res = hook->enable();
if (res) m_hooks.push_back(hook);
else {
log::error("Can't enable hook {} for mod {}: {}", (void*)hook, m_info.id, res.unwrapErr());
}
return res;
}

View file

@ -172,9 +172,9 @@ int geodeEntry(void* platformData) {
log::debug("Set up loader");
if (InternalMod::get()->getSettingValue<bool>("show-platform-console")) {
Loader::get()->openPlatformConsole();
}
// if (InternalMod::get()->getSettingValue<bool>("show-platform-console")) {
// Loader::get()->openPlatformConsole();
// }
log::debug("Entry done.");