Skip to content

feat: implement KHook - #1418

Open
roflmuffin wants to merge 3 commits into
mainfrom
feat/khook
Open

feat: implement KHook#1418
roflmuffin wants to merge 3 commits into
mainfrom
feat/khook

Conversation

@roflmuffin

@roflmuffin roflmuffin commented Sep 11, 2026

Copy link
Copy Markdown
Owner

Mostly clanker based PR to migrate all detours and dynamic hooks to KHook

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Player connection handling reads the mutable hook-chain result instead of the original engine result, and the new ABI-sensitive backend needs stronger coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Migrates CounterStrikeSharp’s hook infrastructure from SourceHook, FunHook, and DynoHook to Metamod’s KHook API.

Changes:

  • Adds reusable virtual, function, and dynamic KHook abstractions.
  • Migrates engine, player, event, command, voice, entity, chat, HUD, and user-message hooks.
  • Updates build dependencies and installation requirements.
File summaries
File Description
src/scripting/natives/natives_usermessages.cpp Bypasses hooked user-message slot.
src/scripting/natives/natives_memory.cpp Converts hook exceptions to native errors.
src/scripting/natives/natives_dynamichooks.cpp Uses the new dynamic-hook context.
src/mm_plugin.h Declares KHook callbacks and ownership.
src/mm_plugin.cpp Migrates plugin lifecycle hooks.
src/core/memory_module.cpp Adds KHook-aware signature lookup.
src/core/managers/voice_manager.h Declares KHook voice hooks.
src/core/managers/voice_manager.cpp Migrates voice interception.
src/core/managers/usermessage_manager.h Declares KHook user-message hooks.
src/core/managers/usermessage_manager.cpp Migrates user-message interception.
src/core/managers/server_manager.h Declares KHook server hooks.
src/core/managers/server_manager.cpp Migrates server lifecycle hooks.
src/core/managers/player_manager.h Declares KHook player hooks.
src/core/managers/player_manager.cpp Migrates player lifecycle hooks.
src/core/managers/event_manager.h Simplifies event-hook state.
src/core/managers/event_manager.cpp Implements recursive-safe event dispatch.
src/core/managers/entity_manager.h Declares KHook entity hooks.
src/core/managers/entity_manager.cpp Migrates entity and output hooks.
src/core/managers/con_command_manager.h Declares KHook command hooks.
src/core/managers/con_command_manager.cpp Migrates command dispatch hooks.
src/core/managers/chat_manager.h Declares the KHook chat detour.
src/core/managers/chat_manager.cpp Migrates chat interception.
src/core/hooks.h Adds shared KHook wrappers and ownership.
src/core/globals.h Removes SourceHook globals.
src/core/globals.cpp Migrates initialization detours.
src/core/function.h Integrates dynamic KHook state.
src/core/function.cpp Replaces DynoHook dispatch and invocation.
src/core/dynamic_hook.h Defines dynamic hook contexts.
src/core/dynamic_hook.cpp Implements runtime ABI hook dispatch.
src/core/detours.h Updates damage-hook context types.
src/core/customhudlayout.h Declares KHook HUD interception.
src/core/customhudlayout.cpp Migrates HUD message hooks.
makefiles/windows.base.cmake Updates Windows hook dependencies.
makefiles/shared.cmake Updates KHook include paths.
makefiles/linux.base.cmake Updates Linux linking and visibility.
docfx/docs/guides/getting-started.md Documents the required Metamod build.
CMakeLists.txt Removes legacy hook libraries and adds the backend.
Review details
  • Files reviewed: 39/40 changed files
  • Comments generated: 3
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/core/managers/player_manager.cpp Outdated
Comment thread src/core/dynamic_hook.cpp
Comment on lines +291 to +295
DynamicHook::DynamicHook(void* address, const std::vector<DataType_t>& types, DataType_t returnType, Handler handler)
: m_state(std::make_shared<State>(types, returnType, std::move(handler)))
{
if (!address) throw std::invalid_argument("Cannot hook a null function");
std::string signature;
Comment thread src/core/managers/usermessage_manager.cpp Outdated
roflmuffin and others added 2 commits September 11, 2026 22:16
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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