The TF2 source tree lives underDocumentation 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.
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
| Directory | Purpose |
|---|---|
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.
game/server/ — server.dll / server_srv.so
game/server/ — server.dll / server_srv.so
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/
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.game/client/ — client.dll / client.so
game/client/ — client.dll / client.so
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
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).game/shared/ — compiled into both DLLs
game/shared/ — compiled into both DLLs
The tier library system
Valve layered the runtime into four tiers of increasing abstraction. Each tier depends only on tiers below it.tier0 — core runtime
tier0 — core runtime
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)
tier0.dll is the very first DLL loaded. On Linux it becomes tier0_srv.so or links statically via tier0_staticlink.vpc.tier1 — containers and key/value store
tier1 — containers and key/value store
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) — theCreateInterfacemechanism used to cross DLL boundaries
tier2 — filesystem and sound abstraction
tier2 — filesystem and sound abstraction
Depends on tier1. Wraps platform I/O behind the
IFileSystem interface and provides:- Filesystem helpers (
filesystem_init.cppinpublic/) - Sound I/O abstractions
- Material system interface plumbing
tier3 — rendering abstraction
tier3 — rendering abstraction
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-tree | Contents |
|---|---|
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 |
public/:
eiface.h—IServerGameDLL, the contract betweenengine.dllandserver.dllcdll_int.h—IBaseClientDLL, the contract betweenengine.dllandclient.dlldt_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).
.vpc files support:
$Macro— named string substitutions (e.g.$SRCDIR,$GAMENAME)$Include— compose multiple.vpcfragments (e.g.server_tf.vpcincludesserver_base.vpc)$Configuration— compiler/linker settings per build configuration$Folder— logical grouping of files in the IDE- Conditional blocks using
[$WINDOWS],[$POSIX], etc.
vpc_scripts/ directory holds base scripts shared across many projects:
| Script | Purpose |
|---|---|
source_dll_base.vpc | Base settings for all Source DLL projects |
source_dll_win32_base.vpc | Windows-specific DLL settings |
source_dll_posix_base.vpc | Linux/macOS DLL settings |
source_lib_base.vpc | Base settings for static library projects |
source_exe_base.vpc | Base settings for executable projects |
source_win32_base.vpc | Common Windows compiler flags |
source_posix_base.vpc | Common POSIX compiler flags |
groups.vgc | Named project groups (game, dedicated, everything, etc.) |
projects.vgc | Maps project names to their .vpc file paths |
default.vgc | Default 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.