Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/twhl-community/halflife-unified-sdk/llms.txt

Use this file to discover all available pages before exploring further.

The Half-Life Unified SDK includes an abstraction layer over the engine’s console command and CVar facilities. The primary goal of this system is to allow code that runs on both the client and server to register commands and CVars without scattering #ifdef CLIENT_DLL preprocessor guards throughout the codebase. A unified registration API handles the platform-specific details transparently.
The console command system uses the logger named cvar. Use this logger name when filtering log output related to command and CVar registration.

Library Prefix

A key concept in this system is the library prefix. Because the same code can be compiled into both the client library and the server library, each registered command or CVar is automatically prefixed to indicate its origin:
ContextPrefix
Client librarycl
Server librarysv
For example, a command registered as my_command becomes cl_my_command on the client and sv_my_command on the server. This prevents name collisions between client and server registrations of the same logical command. The prefix can be suppressed on a per-registration basis when needed (see below).

Registering Commands

Commands are registered through the global g_ConCommands object using CreateCommand. Each command is backed by a std::function with the signature void(const CCommandArgs& args). The recommended pattern is a capturing lambda that forwards execution to a member function:
g_ConCommands.CreateCommand("command_name", [this](const auto& args) { MyMemberFunction(args); });

void CMyClass::MyMemberFunction(const CCommandArgs& args)
{
	if (args.Count() > 1)
	{
		Con_Printf("%s\n", args.Argument(1));
	}
}
Commands take a std::function object for a function signature void(const CCommandArgs& args). Typical use involves using a capturing lambda to forward command execution to a member function, as shown above.

Disabling the Library Prefix for Commands

To register a command without any library prefix, pass CommandLibraryPrefix::No as the third argument:
g_ConCommands.CreateCommand("command_name", [this](const auto& args) { MyMemberFunction(args); }, CommandLibraryPrefix::No);

Registering CVars

CVars are registered through g_ConCommands.CreateCVar. Provide the base name, default value string, and any engine CVar flags:
m_MyCvar = g_ConCommands.CreateCVar("my_cvar", "0", FCVAR_PROTECTED);
You can set the initial value and flags.

Disabling the Library Prefix for CVars

Just like commands, you can opt out of the library prefix for a CVar:
m_MyCvar = g_ConCommands.CreateCVar("my_cvar", "0", FCVAR_PROTECTED, CommandLibraryPrefix::No);

Setting CVars From the Command Line

CVars registered with this system can be set from the command line in one of two ways. Both ways require you to prefix the CVar name with :. The first is to use the complete CVar name:
:sv_cvar_name argument
The second is to use only the base name without the library prefix:
:cvar_name argument
This allows you to set both the client and server version of a CVar at the same time. CVar values should be quoted if they have spaces or if they start with a + or -.

Build docs developers (and LLMs) love