|
CS2-Kit
C++23 library for CS2 Metamod:Source plugin development
|
Work in Progress — The SDK wrapper API may change.
The Sdk module (CS2Kit::Sdk) provides typed wrappers around HL2SDK interfaces, abstracting away raw pointer manipulation and engine-specific details.
Centralized holder for all SDK interface pointers. Automatically populated by CS2Kit::Initialize() — no manual setup needed.
All other Sdk classes read from this singleton internally.
CS2-Kit ships built-in gamedata (gamedata/signatures.jsonc) that is automatically loaded during CS2Kit::Initialize(). The gamedata contains engine signatures and offsets used internally by Entity, PlayerController, and UserMessage subsystems.
Consumer plugins can also use GameData for their own signatures:
Access player controllers and entity data:
Typed wrapper around CCSPlayerController providing common operations:
SetVisible toggles transparency on the player pawn body. Weapons, gloves, and grenades stay visible — CS2 routes those through systems a server plugin can't reach (the client-side glow/render pipeline), and there is currently no known server-side path to hide them.
Read or force a player into a specific spectator mode:
Read/write m_iszPlayerName on the controller. SetPlayerName truncates to 127 characters and issues NetworkStateChanged so the scoreboard re-syncs:
Mutate m_nRenderMode and m_clrRender on any CBaseModelEntity. Used internally by PlayerController::SetVisible, but exposed so plugins can hide/recolor any entity (props, dropped weapons, world objects).
m_clrRender is RGBA packed as (A << 24) | (B << 16) | (G << 8) | R — ColorInvisible (0x00FFFFFF) is white at zero alpha.
Resolves entity field offsets at runtime using CS2's schema system. Results are cached:
Low-level byte-pattern scanning for finding functions in memory:
Wildcard bytes are represented as ?? in pattern strings.
Read and write ConVars with type safety:
Create, fire, and listen for game events:
Send chat and center-HTML messages to players:
Per-slot pending-prompt registry that backs the menu system's free-text CS2Kit::Menu::InputOption. Use it directly when you need a prompt outside of a menu (e.g. a chat command that asks the player to type a value as a follow-up).
The validator returns true to accept the input (capture clears) or false to re-prompt the player. The capture auto-cancels after timeoutMs of no input.
CS2Kit cannot install its own chat hook because suppressing a chat broadcast must happen inside the plugin's Hook_DispatchConCommand (or equivalent SourceHook hook on say / say_team). The plugin is expected to call CS2Kit::Sdk::ChatInputCapture::TryConsume before its own command parsing and supersede the broadcast when it returns true:
If no capture is pending for slot, TryConsume returns false and the message falls through to your normal chat handling.
| Method | Description |
|---|---|
BeginCapture(slot, prompt, callback, timeoutMs = 30000) | Start waiting for slot's next chat line. Replaces any previous pending prompt for the same slot. |
IsCapturing(slot) | true if slot has a pending prompt. |
TryConsume(slot, text) | Route a chat line to the active prompt. Returns true when the message was consumed. |
CancelCapture(slot) | Drop the pending prompt without firing the callback. |
GetPrompt(slot) | Returns the active prompt string (used by MenuRenderer to draw the overlay), or nullptr. |
OnPlayerDisconnect(slot) | Lifecycle hook — called automatically by CS2Kit::OnPlayerDisconnect. |