Skip to content

fix compilation error caused by substitution failure when installing hook at raw pointer, implement InstallAtSymbol with exlaunch's symbol lookup#27

Open
Werechang wants to merge 3 commits into
shadowninja108:mainfrom
Werechang:feat/module-compat
Open

fix compilation error caused by substitution failure when installing hook at raw pointer, implement InstallAtSymbol with exlaunch's symbol lookup#27
Werechang wants to merge 3 commits into
shadowninja108:mainfrom
Werechang:feat/module-compat

Conversation

@Werechang
Copy link
Copy Markdown
Contributor

The obligatory usage:

MyHook::InstallAtSymbol("_ZN10StageScene7exePlayEv");

A static_assert(false) in type_traits.hpp caused the compilation to fail, since the compiler tried to substitute uintptr_t in FuncPtrTraits to test the application of a templated function.

@aquacluck
Copy link
Copy Markdown

Nice, I've been doing something similar in https://github.com/aquacluck/totk-lotuskit/blob/main/exlaunch/patches/0002-feature-install-at-named-reloc.patch#L1-L18, using exlaunch's new symbol table utility:

        static ALWAYS_INLINE void Install() {
            _HOOK_STATIC_CALLBACK_ASSERT();

            const auto entry = exl::reloc::GetLookupTable().FindByName(Derived::s_name);
            //auto mod = exl::util::GetModuleInfo(entry->m_ModuleIndex); // XXX cheat: always main module anyways for now
            hook::HookInline(util::modules::GetTargetOffset(entry->m_Offset), Derived::Callback);
        }

Usage:

HOOK_DEFINE_INLINE(OnRecallUpdateHighlightActorHook) {
    static constexpr auto s_name = "game::ai::execute::ExecutePlayerReverseRecorder::updateImpl_::state0";
    static void Callback(exl::hook::InlineCtx* ctx) {
        auto* highlightedActor = (engine::actor::ActorBase*)(ctx->X[8]);
        lotuskit::ActorWatcher::resolveRecallHighlight(highlightedActor);
    }
};
// then OnRecallUpdateHighlightActorHook::Install(), same idea

I'm not sure of the best way to handle these, just wanted to bring up these different patterns for symbol lookup, they're both useful :)

@Werechang
Copy link
Copy Markdown
Contributor Author

Thanks for bringing this to my attention. I will update my code to use the exlaunch lookup. However, I'll stick to the principle of passing the target info inside the installation function to be consistent with the design.

@Werechang Werechang changed the title fix compilation error caused by substitution failure when installing hook at raw pointer, implement InstallAtSymbol when exlaunch is loaded as a module fix compilation error caused by substitution failure when installing hook at raw pointer, implement InstallAtSymbol with exlaunch's symbol lookup Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants