Hooks a virtual function in a table that does not exist for the class. This is useful for adding hooks to functions that are not part of the original class definition. This should be called on every instance that needs to be hooked.
Class VMTHookManager
#include <Geode/utils/VMTHookManager.hpp>classVMTHookManager{ ... }
No description provided
Examples0
Public static methods1
staticgeode::VMTHookManager&get()
No description provided
Public member functions3
template<class Class>geode::Result<std::optional<geode::Hook*>>addHook(Class*instance,std::stringdisplayName,tulip::hook::TulipConventionconvention,tulip::hook::HookMetadatahookMetadata)
instance
The instance to hook.
displayName
The display name for the hook.
convention
The calling convention for the hook.
hookMetadata
Additional metadata for the hook.
Function
The detour function.
A result containing the hook, if successful. Will return a nullopt if the hook has already been created.
```cpp
auto mainHook = VMTHookManager::get().addHook<
ResolveC<GJGarageLayerTest2>::func(&GJGarageLayerTest2::ccTouchBegan)
>(this, "GJGarageLayer::ccTouchBegan");
// This should also be called for delegate hooks, with ResolveC pointing to the Delegate
// In Windows, this will be a no-op, but it will hook the other function in other platforms
auto delegateHook = VMTHookManager::get().addHook<
ResolveC<CCTouchDelegate>::func(&GJGarageLayerTest2::ccTouchBegan)
>(this, "GJGarageLayer::ccTouchBegan");
bool ccTouchBegan(CCTouch* touch, CCEvent* event) override {
// Yes, you need to call the original by seemingly recursing.
// Otherwise you would just call the base class function, and
// that wouldn't call other hooks.
this->ccTouchBegan(touch, event);
return true;
}
```template<class Class>geode::Result<>forceEnableFunction(Class*instance)
Force enable a function by its address. This will enable back the disabled function.
template<class Class>geode::Result<>forceDisableFunction(Class*instance)
Force disable a function by its address. This will disable the function, and all of its hooks. You need to call forceEnableFunction to enable back those hooks.