Prodvigat server

Player Models a Quarter Smaller: What We Found Inside CS 1.6 Models

Custom skins are the biggest download on most servers. We looked at how they are stored, found a lot of repeated data, and built a free tool that removes it.

The short version

A CS 1.6 player model is mostly animation, not the character you see. Model compilers store a lot of that animation twice. On four real sets of server skins we cut what players download by 20 to 28 percent without changing a single frame, and by 51 to 56 percent together with gzip compression.

The tool that does it is free and open source: CSB Model Optimizer (Windows app and command line). Below is what we found and how it works.

What is inside a model file

We measured the stock Counter-Strike files byte by byte. Weapon models are mostly mesh and texture. Player models are the opposite: almost the whole file is the animation of about 110 moves (walk, run, crouch, shoot with every weapon, die...).

Stacked bars: gign.mdl is 86 percent animation, vip.mdl 94 percent, v_ak47.mdl 7 percent, p_ak47.mdl under 1 percent.
Stock CS 1.6 files. A player model is 86-94% animation; a weapon model is mostly texture.

How GoldSrc stores animation

Each move (a sequence) has a table with one row per bone. Each row has six slots: position X, Y, Z and rotation X, Y, Z. A slot points at a small compressed list of values, one per frame, or is 0 when that bone does not move that way. The compression is a simple run-length scheme: valid values follow, and they cover total frames.

A model file contains sequences; each sequence points to a table of bones; each bone has six slots that point to compressed value streams or are zero.
The sequence points at its table with a 32-bit offset (it can point anywhere in the file); each slot points at its values with a 16-bit offset (at most 65,535 bytes ahead).

Those two offset sizes matter: they decide what can be shared and where.

Where the waste is

We went through a Zombie Plague model pack and three real server skin sets (about 370 player model files in all). The compression of each value list is already as tight as it gets, and the files have no unused or trailing bytes. The waste is in repetition:

  • Whole moves stored again. Many custom models carry the same sequence several times (the same idle or death under different names). Each copy is stored in full.
  • The same value list in many places. A bone that holds still has the same short list in every move it appears in, and blends of one move repeat most of their lists.
  • Lists of zeros. A list that only says "no movement" can simply be the 0 slot.
  • The same animation in different skins. Skin packs reuse one rig: five zombies in the pack had byte-identical animation (8 MB of the same data).

We also found plain mistakes that cost every player a download:

  • zombie_cubanoT.mdl in a popular Zombie Plague pack is a copy of the model itself, not its texture file. The skin has no textures at all, and every player downloads 1.4 MB for nothing.
  • Identical skins under two names on one server (for example werewolf and Lobisomem, 2.2 MB each).
  • A T.mdl texture file next to a model that has its own textures: the game never loads it.

Fix 1: pack each model

The first fix keeps every model a normal, single file with the same name. Repeated moves point at one table, because that offset can reach anywhere. Repeated value lists are written once. A slot can only point forward and at most 65,535 bytes ahead, so lists are shared inside a chunk of moves that fits in that window. All-zero lists become 0, and values a list repeats at its end are dropped (the game repeats the last value anyway).

Before, each sequence stores its own table and value lists, and a copied sequence is stored again. After, tables share one chunk where every distinct list is stored once, and the copy only points at the first table.
Colours are value lists. Packing stores each one once per chunk, and a repeated move costs only its pointer.

This alone takes most custom player models down by a fifth to a quarter, and it works with every client, stock or not, because the format is unchanged.

Fix 2: share animation between skins

GoldSrc has had a way to keep animation outside the model since Half-Life 1: sequence groups (the model01.mdl files). A model can say "my moves are in that other file", and the game, the client and the server all load it by name. We use that to give skins with the same animation one shared file, named after its content: models/player/_anims/<hash>.mdl. A player who already downloaded it for one server does not download it again for another.

Five zombie models with identical animation: 11.5 MB before; after, five slim models plus one shared 1.1 MB animation file, 4.7 MB in total.
Five zombies from a Zombie Plague pack whose animation was identical byte for byte.

Rules we kept to:

  • A shared file is only made if no skin ends up holding more animation in memory than before (each model keeps its own copy of the file in memory), and only if the download gets smaller.
  • The stock skins (gign, sas, arctic...) are never touched. With mp_consistency 1 the game checks their size from the animation inside the file and ignores sequence groups, so with a split stock skin the player's game quits while connecting. Every player has those files anyway.
  • Only models/player/ is split. Weapon models are only packed.
  • The server must send the shared files with the skins: one line each in maps/<map>.res, or precache_generic next to precache_model. The tool writes the list for you.

We tested the shared files in game: a slim skin is loaded and posed the same as the original, and a stock (non-kit) client downloaded the shared files from a stock server and joined.

Fix 3: gzip on top

Packing removes repeats that are far apart in a file, or in different files. gzip removes the small ones close together, so the two add up. The tool writes a .gz next to every file. Clients with our kits download those (see Fast Download in kit 8684.8); other clients keep downloading the normal files, which are smaller now too.

How the tool works

Five steps: read and parse, pack each model, share between player models, verify every frame, write files and gzip copies. If a check fails, the original is kept.
Your folder is only read. Every rewritten model is compared with its original before anything is written.

The check after each rewrite is what makes this safe. For every move, bone, slot and frame, the tool reads the value the way the game engine does and compares it with the original. It also compares the header, bones, move descriptions, meshes and textures. We ran a second, separate checker (written independently, in Python) over every model of four real sets: no differences.

Results

Grouped bars for four real sets: original size, gzip only, and packed plus gzip.
Player models only. The percentage is against the original files.
SetOriginalPacked + sharedPacked + shared + gzip
Zombie Plague pack69.2 MB49.7 MB33.7 MB
Skins server266.6 MB191.4 MB118.7 MB
Client skin set61.2 MB48.7 MB30.0 MB
Big skins server200.1 MB146.3 MB94.2 MB

A whole server download folder (1,350 files with maps, sounds and sprites) went from 771 MB to 393 MB of .gz files, in 27 seconds.

Try it on your server

  • Get CSB Model Optimizer (MIT license). The page has a step-by-step tutorial.
  • Pick your cstrike or fast-download folder and press Optimize. It writes an optimized copy; your folder is not changed.
  • Copy the result to your server and your fast-download host, .gz files included.
  • If animation was shared, add the files from shared_anims.txt to your .res files or plugin.

Or from the command line:

mdlopt run "C:\server\cstrike" "C:\server\cstrike_optimized" --report report.json

Players who already have the old files keep them; they still work. New players download the smaller ones.