feat: implement KHook - #1418
Open
roflmuffin wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
🟡 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 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; |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mostly clanker based PR to migrate all detours and dynamic hooks to KHook