Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sr2echa/TF2-Source-Code/llms.txt

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

The TF2 source tree lives under tf2_src/ and contains around 69 top-level directories spanning the engine, game logic, rendering, physics, UI, and build infrastructure. Understanding where each subsystem lives is the first step toward reading or modifying the code.

Top-level directory reference

DirectoryPurpose
app/Application-level startup glue
appframework/IAppSystem interface — the common service-locator used by all DLLs
bitmap/CPU-side bitmap manipulation (pixel format conversion, mip generation)
choreoobjects/Choreography scene objects (lip-sync, flex animations)
common/Shared utilities consumed by both client and server (e.g. ServerBrowser/, GameUI/ scripts)
datacache/Async resource loading and caching layer
datamodel/DMX/element-based data model used by tools (Hammer, SFM)
dedicated/Dedicated server binary entry point
dedicated_main/main() shim for the dedicated server process
devtools/Pre-built VPC and other Valve dev tools binaries
dmserializers/DMX file format serializers
dmxloader/DMX loader library
engine/The Source engine core: networking, console, BSP rendering pipeline
external/External dependency references
fgdlib/FGD (game data) parsing library used by Hammer
filesystem/Filesystem interface implementations (filesystem_stdio)
game/Game DLLs — server, client, and shared subdirectories
gameui/Main menu and pause menu UI
gcsdk/Game Coordinator SDK (Steam back-end services, matchmaking, economy)
hammer/The Hammer map editor DLL
hammer_launcher/Hammer process entry point
inputsystem/Raw input handling (mouse, keyboard, gamepad)
launcher/launcher.dll — bootstraps engine.dll
launcher_main/hl2.exe / hl2_linux entry point
lib/Pre-built static and import libraries (public/, common/, platform subdirs)
linux_sdk/Linux platform headers and toolchain files
linux/Linux-specific build helpers
materialsystem/VMT/VTF material pipeline, shader dispatch
mathlib/SIMD-optimised math (Vector, QAngle, matrix3x4_t, etc.)
mdllib/MDL model file parser
mdlobjects/In-memory representation of compiled models
movieobjects/Animation/movie data objects used by the Source Filmmaker
networksystem/Low-level networking (UDP, encryption wrappers)
particles/Particle system
public/Shared header-only interface layer — see below
raytrace/Software ray-casting used by certain lighting tools
replay/Demo-recording / replay system
scenefilecache/Runtime cache for choreography scene files
sdklauncher/SDK Launcher UI
serverbrowser/In-game server browser
sfmobjects/Source Filmmaker data objects
soundemittersystem/soundemitter — maps script names to WAV paths
soundsystem/Low-level audio mixer
sourcevr/OpenVR / SteamVR integration
studiorender/MDL runtime renderer (skinning, flex, LOD)
thirdparty/Third-party vendored libraries
tier0/Core runtime: memory allocator, threads, profiling, debug — see below
tier1/Containers, KeyValues, string tools — see below
tier2/Filesystem and sound abstractions built on tier1
tier3/Rendering-layer abstractions built on tier2
togl/OpenGL translation layer (used on Linux/macOS)
tools/Source SDK tools (VRAD, VBSP, VVIS, studiomdl, etc.) and runtimes
tracker/Valve tracker / friends network remnants
unicode/Unicode string utilities
unitlib/Unit-test harness
unittests/Unit-test binaries
utils/Build utilities and content-pipeline tools
vgui2/VGUI2 UI framework (vgui_dll, vgui_controls, vgui_surfacelib)
vguimatsurface/Material-system rendering surface for VGUI2
video/Video playback (Bink, WebM, QuickTime adapters)
vpc_scripts/VPC base scripts shared across all projects — see below
vphysics/Havok-based physics DLL
vpklib/VPK archive reader/writer
vstdlib/Valve standard library extensions (string, random, KeyValuesSystem)
vtf/VTF texture format read/write

The game/ directory

The game-logic code is split across three subdirectories that map directly onto how the Source engine loads the game DLLs.
Compiled into server.dll (Windows) or server_srv.so (Linux). This code runs only on the server process. It owns:
  • All entity logic (CBaseEntity, CBasePlayer, CTFPlayer, weapon objects, etc.)
  • AI and navigation (ai_basenpc.cpp, NavMesh, NextBot framework)
  • Game rules and round management
  • TF2-specific objects: sentry guns, dispensers, teleporters, Payload logic, MvM population manager
  • Bot behaviour trees under tf/bot/behavior/
The TF build target is defined in server_tf.vpc. It $Includes server_base.vpc and server_econ_base.vpc, then adds the TF_DLL preprocessor define and pulls in every TF-specific source file.
Compiled into client.dll (Windows) or client.so (Linux). This code runs only in the game client process. It owns:
  • Client-side entity shadows (C_BaseEntity, C_TFPlayer, etc.)
  • HUD elements (tf_hud_*.cpp) and all VGUI panels
  • Client-side prediction copy of player movement
  • Rendering proxies, particle effects, view rendering
  • In-game store, loadout, matchmaking UI
The TF build target is client_tf.vpc. It defines TF_CLIENT_DLL, USES_ECON_ITEMS, and ENABLE_GC_MATCHMAKING, and conditionally enables Steam Workshop import on Windows ($WORKSHOP_IMPORT_ENABLE).
Source files in game/shared/ are compiled into both server.dll and client.dll. They provide:
  • Movement code (gamemovement.cpp, tf_gamemovement.cpp)
  • Shared game rules base (gamerules.cpp, teamplay_gamerules.cpp, tf_gamerules.cpp)
  • All weapon implementations (tf_weapon_*.cpp) — the same .cpp is compiled server-side and client-side
  • Player state, animation state, conditions (tf_player_shared.cpp, tf_condition.cpp)
  • Economy / item schema (tf_item_schema.cpp, tf_item_inventory.cpp)
  • Shared definitions (tf_shareddefs.cpp, shareddefs.h)
The $SRCDIR macro in each .vpc file resolves to tf2_src/, so a path like $SRCDIR\game\shared\tf\tf_gamerules.cpp appears in both server_tf.vpc and client_tf.vpc.

The tier library system

Valve layered the runtime into four tiers of increasing abstraction. Each tier depends only on tiers below it.
No external dependencies. Provides the lowest-level primitives that every other module relies on:
  • Memory allocator (mem.cpp, memstd.cpp, memdbg.cpp)
  • Thread primitives (threadtools.cpp, thread.cpp, tslist.cpp)
  • Debug assertion dialog (dbg.cpp, assert_dialog.cpp)
  • Command-line parser (commandline.cpp)
  • Fast timer and CPU profiling (fasttimer.cpp, vprof.cpp)
  • Minidump writer (minidump.cpp)
  • Platform abstraction (platform.cpp, platform_posix.cpp)
On Windows, tier0.dll is the very first DLL loaded. On Linux it becomes tier0_srv.so or links statically via tier0_staticlink.vpc.
Depends on tier0. Provides general-purpose data structures and serialisation:
  • KeyValues — the ubiquitous key/value file format (KeyValues.cpp)
  • CUtlBuffer, CUtlString, CUtlVector, CUtlSymbol (utlbuffer.cpp, utlstring.cpp, utlsymbol.cpp)
  • ConVar / console variable system (convar.cpp)
  • Checksum and hash utilities (CRC, MD5, SHA1)
  • Compression helpers (LZSS, LZMA, Snappy)
  • Network address helpers (NetAdr.cpp)
  • Interface factory (interface.cpp) — the CreateInterface mechanism used to cross DLL boundaries
Depends on tier1. Wraps platform I/O behind the IFileSystem interface and provides:
  • Filesystem helpers (filesystem_init.cpp in public/)
  • Sound I/O abstractions
  • Material system interface plumbing
Depends on tier2. Provides:
  • Higher-level rendering interfaces
  • Material system and model rendering hooks used by tools and the engine

The public/ header directory

public/ is header-only (plus a few small .cpp helpers). It defines the interfaces that cross DLL boundaries, so that client.dll, server.dll, engine.dll, and every tool can agree on types without depending on each other’s implementation code. Key sub-trees inside public/:
Sub-treeContents
public/tier0/, public/tier1/, public/tier2/, public/tier3/Public headers for each tier library
public/appframework/IAppSystem base class
public/vphysics/Physics interface (IPhysicsEnvironment, etc.)
public/materialsystem/IMaterialSystem, material proxy interfaces
public/vgui/, public/vgui_controls/VGUI2 panel and control interfaces
public/game/Game interface headers (cdll_int.h, eiface.h)
public/filesystem/IFileSystem interface
public/inputsystem/Input device interface
public/shaderapi/, public/shaderlib/Shader API interfaces
public/steam/Steam SDK headers
Important standalone headers at the root of public/:
  • eiface.hIServerGameDLL, the contract between engine.dll and server.dll
  • cdll_int.hIBaseClientDLL, the contract between engine.dll and client.dll
  • dt_send.h / dt_recv.h — DataTable send/receive property descriptors (network serialisation)
  • const.h — engine-wide constants (max players, world size, etc.)
  • studio.h — compiled MDL format structures

VPC project files

Every buildable project in the tree has a .vpc file that describes its source files, preprocessor definitions, include paths, and output type (DLL, static lib, or executable).
$Macro SRCDIR    ".."

$Project "MyLibrary"
{
    $Folder "Source Files"
    {
        $File "$SRCDIR\mylib\mylib.cpp"
        $File "$SRCDIR\mylib\mylib.h"
    }
}

$Configuration
{
    $Compiler
    {
        $PreprocessorDefinitions    "$BASE;MYLIB_EXPORTS"
        $AdditionalIncludeDirectories    "$SRCDIR\public"
    }
}
.vpc files support:
  • $Macro — named string substitutions (e.g. $SRCDIR, $GAMENAME)
  • $Include — compose multiple .vpc fragments (e.g. server_tf.vpc includes server_base.vpc)
  • $Configuration — compiler/linker settings per build configuration
  • $Folder — logical grouping of files in the IDE
  • Conditional blocks using [$WINDOWS], [$POSIX], etc.
The vpc_scripts/ directory holds base scripts shared across many projects:
ScriptPurpose
source_dll_base.vpcBase settings for all Source DLL projects
source_dll_win32_base.vpcWindows-specific DLL settings
source_dll_posix_base.vpcLinux/macOS DLL settings
source_lib_base.vpcBase settings for static library projects
source_exe_base.vpcBase settings for executable projects
source_win32_base.vpcCommon Windows compiler flags
source_posix_base.vpcCommon POSIX compiler flags
groups.vgcNamed project groups (game, dedicated, everything, etc.)
projects.vgcMaps project names to their .vpc file paths
default.vgcDefault VPC configuration
The VPC tool binary lives at devtools/bin/vpc.exe. You invoke it from the tf2_src/ root. Pass +<groupname> to build a named group, or +<projectname> to build a single project. The /2013 flag selects the Visual Studio 2013 toolset.

Build docs developers (and LLMs) love