CS2-Kit
C++23 library for CS2 Metamod:Source plugin development
Loading...
Searching...
No Matches
Architecture

Work in Progress — This architecture may change as the library evolves.

Overview

CS2-Kit is organized into six modules, each in its own namespace under CS2Kit:

CS2Kit
├── Core Foundational patterns and services
├── Commands Chat command framework
├── Menu WASD center-HTML menu system
├── Players Connected-player tracking
├── Sdk HL2SDK abstraction layer
└── Utils General-purpose utilities

Design Principles

  • Single-threaded — All code runs on the game thread. No mutexes needed. Metamod hooks are always called from the main thread.
  • Singleton pattern — Manager classes use the CRTP Singleton<T> base with pass-key idiom for safe, lazy initialization.
  • Builder pattern — Complex objects (commands, menus) are constructed via fluent builders.
  • Minimal boilerplateCS2Kit::Initialize(ismm, error, maxlen) handles all SDK interface resolution, gamedata loading, and subsystem init. The consumer only needs to drive the player lifecycle (PlayerManager::AddPlayer/RemovePlayer) from its connect/disconnect hooks; ILogger has a built-in default.

CRTP Singleton

All singleton classes inherit from CS2Kit::Core::Singleton<T>:

class MyManager : public Core::Singleton<MyManager>
{
public:
explicit MyManager(Token) {} // Required constructor
void DoWork();
private:
int _state = 0;
};
// Usage:
MyManager::Instance().DoWork();

The pass-key idiom (Token) prevents external code from constructing additional instances while allowing Singleton<T> to create the one instance.

Module Dependencies

Utils ──────────────────────────┐
│ │
Core ──────────────────┐ │
│ │ │
├── Commands ────────┤ │
│ │ │
├── Menu ────────────┤ │
│ │ │
├── Players ─────────┤────────┤
│ │ │
└── Sdk ─────────────┘────────┘
  • Utils has no internal dependencies (only standard library)
  • Core depends on nothing within CS2-Kit
  • Commands, Menu, Players, and Sdk depend on Core
  • Players and Sdk additionally depend on Utils (for SteamID, string helpers)
  • Commands, Menu, and Players are independent of each other

Callback Conventions

CS2-Kit uses std::function callbacks throughout:

Callback Signature Used in
Command handler CommandResult(Players::Player*, const vector<string>&) CommandBuilder
Menu button activate void(int slot) MenuBuilder (AddButton, AddDynamicButton)
Menu toggle get / flip bool(int) / void(int) MenuBuilder (AddToggle)
Menu choice get / set / commit int(int) / void(int, int) / void(int, const T&) MenuBuilder (AddChoice, AddSelector)
Menu slider get / set int(int) / void(int, int) MenuBuilder (AddSlider)
Menu input get / validate string(int) / bool(int, string_view) MenuBuilder (AddInput)
Menu close void(int slot) MenuBuilder
Submenu factory shared_ptr<Menu>(int slot) MenuBuilder (AddSubmenu)
Chat input capture bool(int slot, string_view text) ChatInputCapture (BeginCapture)
Scheduler task void() Scheduler
Permission check bool(int slot, const string& flags) CommandManager

Interface Contracts

Interface Purpose Required?
ILogger Logging backend (Info/Warn/Error) No — built-in ConsoleLogger used by default