mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-22 23:48:08 -05:00
hooks try to get enabled
This commit is contained in:
parent
eeb4bea97a
commit
cef0f3f3bb
5 changed files with 23 additions and 20 deletions
|
@ -132,7 +132,7 @@ CPMAddPackage("gh:mity/md4c#e9ff661")
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE ${md4c_SOURCE_DIR}/src)
|
target_include_directories(${PROJECT_NAME} PRIVATE ${md4c_SOURCE_DIR}/src)
|
||||||
|
|
||||||
# Tulip hook (hooking)
|
# Tulip hook (hooking)
|
||||||
CPMAddPackage("gh:altalk23/TulipHook#92b3cca")
|
CPMAddPackage("gh:altalk23/TulipHook#5ba99a8")
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} md4c z TulipHook geode-sdk)
|
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/Loader.hpp"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/UI.hpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/UI.hpp"
|
||||||
# "${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/Bindings.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/include/cocos2d.h"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/cocos/extensions/cocos-ext.h"
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/Geode/cocos/extensions/cocos-ext.h"
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include <tulip/TulipHook.hpp>
|
#include <tulip/TulipHook.hpp>
|
||||||
|
|
||||||
#define GEODE_APPLY_MODIFY_FOR_FUNCTION(addr_index, pure_index, convention, className, functionName) \
|
#define GEODE_APPLY_MODIFY_FOR_FUNCTION(addr_index, pure_index, convention, className, functionName) \
|
||||||
{ \
|
do { \
|
||||||
using DerivedWrap = wrap::functionName<Derived, types::pure##pure_index>; \
|
using DerivedWrap = wrap::functionName<Derived, types::pure##pure_index>; \
|
||||||
using BaseWrap = wrap::functionName<Base, types::pure##pure_index>; \
|
using BaseWrap = wrap::functionName<Base, types::pure##pure_index>; \
|
||||||
if constexpr (DerivedWrap::uuid != nullptr && (void*)BaseWrap::uuid != (void*)DerivedWrap::uuid) { \
|
if constexpr (DerivedWrap::uuid != nullptr && (void*)BaseWrap::uuid != (void*)DerivedWrap::uuid) { \
|
||||||
|
@ -22,9 +22,9 @@
|
||||||
DerivedWrap::value, \
|
DerivedWrap::value, \
|
||||||
#className "::" #functionName \
|
#className "::" #functionName \
|
||||||
); \
|
); \
|
||||||
BaseModify::m_hooks[FunctionUUID<DerivedWrap::value>::value] = hook; \
|
this->m_hooks[#className "::" #functionName] = hook; \
|
||||||
} \
|
} \
|
||||||
}
|
} while (0);
|
||||||
|
|
||||||
namespace geode::modifier {
|
namespace geode::modifier {
|
||||||
|
|
||||||
|
@ -34,25 +34,25 @@ namespace geode::modifier {
|
||||||
template <class ModifyDerived>
|
template <class ModifyDerived>
|
||||||
class ModifyBase {
|
class ModifyBase {
|
||||||
public:
|
public:
|
||||||
std::map<void (*)(), Hook*> m_hooks;
|
std::map<std::string, Hook*> m_hooks;
|
||||||
|
|
||||||
template <auto Function>
|
Result<Hook*> getHook(std::string const& name) {
|
||||||
Result<Hook*> getHook() {
|
if (m_hooks.find(name) == m_hooks.end()) {
|
||||||
auto uuid = FunctionUUID<Function>::value;
|
|
||||||
if (m_hooks.find(uuid) == m_hooks.end()) {
|
|
||||||
return Err("Hook not in this modify");
|
return Err("Hook not in this modify");
|
||||||
}
|
}
|
||||||
return m_hooks[uuid];
|
return Ok(m_hooks[name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// unordered_map<handles> idea
|
// unordered_map<handles> idea
|
||||||
ModifyBase() {
|
ModifyBase() {
|
||||||
this->apply();
|
// i really dont want to recompile codegen
|
||||||
|
auto test = static_cast<ModifyDerived*>(this);
|
||||||
|
test->ModifyDerived::apply();
|
||||||
ModifyDerived::Derived::onModify(*this);
|
ModifyDerived::Derived::onModify(*this);
|
||||||
for (auto& [uuid, hook] : m_hooks) {
|
for (auto& [uuid, hook] : m_hooks) {
|
||||||
auto res = Mod::get()->addHook(hook);
|
auto res = Mod::get()->addHook(hook);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
log::error("Failed to add hook: {}", res.error());
|
log::error("Failed to add hook {}: {}", hook->getDisplayName(), res.error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,9 @@ Hook::Impl::Impl(void* address, void* detour, std::string const& displayName, tu
|
||||||
m_displayName(displayName),
|
m_displayName(displayName),
|
||||||
m_handlerMetadata(handlerMetadata),
|
m_handlerMetadata(handlerMetadata),
|
||||||
m_hookMetadata(hookMetadata),
|
m_hookMetadata(hookMetadata),
|
||||||
m_owner(owner) {}
|
m_owner(owner),
|
||||||
|
m_enabled(false),
|
||||||
|
m_autoEnable(true) {}
|
||||||
Hook::Impl::~Impl() {
|
Hook::Impl::~Impl() {
|
||||||
if (m_enabled) {
|
if (m_enabled) {
|
||||||
auto res = this->disable();
|
auto res = this->disable();
|
||||||
|
@ -46,11 +48,10 @@ Result<> Hook::Impl::enable() {
|
||||||
if (!LoaderImpl::get()->hasHandler(m_address)) {
|
if (!LoaderImpl::get()->hasHandler(m_address)) {
|
||||||
GEODE_UNWRAP(LoaderImpl::get()->createHandler(m_address, m_handlerMetadata));
|
GEODE_UNWRAP(LoaderImpl::get()->createHandler(m_address, m_handlerMetadata));
|
||||||
}
|
}
|
||||||
|
|
||||||
GEODE_UNWRAP_INTO(auto handler, LoaderImpl::get()->getHandler(m_address));
|
GEODE_UNWRAP_INTO(auto handler, LoaderImpl::get()->getHandler(m_address));
|
||||||
|
|
||||||
m_handle = tulip::hook::createHook(handler, m_detour, m_hookMetadata);
|
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;
|
m_enabled = true;
|
||||||
}
|
}
|
||||||
return Ok();
|
return Ok();
|
||||||
|
|
|
@ -409,9 +409,12 @@ bool Mod::depends(std::string const& id) const {
|
||||||
// Hooks
|
// Hooks
|
||||||
|
|
||||||
Result<> Mod::enableHook(Hook* hook) {
|
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();
|
auto res = hook->enable();
|
||||||
if (res) m_hooks.push_back(hook);
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,9 +172,9 @@ int geodeEntry(void* platformData) {
|
||||||
|
|
||||||
log::debug("Set up loader");
|
log::debug("Set up loader");
|
||||||
|
|
||||||
if (InternalMod::get()->getSettingValue<bool>("show-platform-console")) {
|
// if (InternalMod::get()->getSettingValue<bool>("show-platform-console")) {
|
||||||
Loader::get()->openPlatformConsole();
|
// Loader::get()->openPlatformConsole();
|
||||||
}
|
// }
|
||||||
|
|
||||||
log::debug("Entry done.");
|
log::debug("Entry done.");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue