Search by

andach / php-doom-wad-analysis

andach-andreas

A set of PHP classes to analyse and parse DOOM wads.

Package info

github.com/andach-andreas/php-doom-wad-analysis

pkg:composer/andach/php-doom-wad-analysis

Statistics

Installs: 31

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.0.2 2025-05-30 09:53 UTC

This package is auto-updated.

Last update: 2026-12-01 14:19:58 UTC


README

This is a PHP class to analyse DOOM wads. It is currently in development.

Installation

composer install andach/php-doom-wad-analysis

Usage

use Andach\DoomWadAnalysis\WadAnalyser;

$settings = [
    'colormap' => true,
    'playpal'  => true,
    'maps' => [
        'images'   => true,
        'counts'   => true,
        'things'   => true,
        'linedefs' => true,
        'sidedefs' => true,
        'vertexes' => true,
        'textures' => true,
    ],
];

$analyser = new WadAnalyser($settings);
$result = $analyser->analyse('/path/to/file.wad');

Examples

The examples/ folder has small runnable scripts. Each one defaults to a fixture in tests/, so you can run it without arguments:

Script Shows
examples/analyse-wad.php [file.wad] Full WadAnalyser output for a WAD
examples/read-lumps.php [file.wad] [LUMP] Listing lumps and reading raw lump data with WadFile
examples/parse-text-file.php [file.txt] Parsing an idgames .txt file with TextFile
examples/demo-stats.php [demo.lmp] [game] Demo header, length and tic layout with Demo
examples/demo-tics-to-csv.php [demo.lmp] Streaming every decoded tic to CSV in constant memory
examples/batch-demos.php [folder] Summarising a folder of demos and skipping unsupported ones
examples/dsda-records.php [wad] Fetching a WAD's demo list from dsdarchive.com (needs network access)
php examples/demo-stats.php path/to/demo.lmp

Demos (LMP files)

Demo reads the header of a demo and counts its tics. It supports vanilla Doom, Boom/MBF/MBF21, PrBoom(+)/UMAPINFO, DSDA-Doom, Eternity, CDoom, Doom64 EX, Strife, RUDE, Heretic, Hexen and the Doom alpha.

use Andach\DoomWadAnalysis\Demo;
use Andach\DoomWadAnalysis\UnsupportedDemoException;

$demo = new Demo('/path/to/demo.lmp');

try {
    $header = $demo->lmpStats();          // full header array (vers, skll, epis, miss, plys, tics, foot, ...)
} catch (UnsupportedDemoException $e) {
    echo $e->getMessage();                // e.g. "version 99", "version 202 unexpected signature: ..."
}

$demo->stats;
// [
//     'version' => 202, 'skill_number' => 4, 'mode_number' => 0,
//     'respawn' => 0, 'fast' => 0, 'nomonsters' => 0,
//     'number_of_players' => 1, 'tics' => 24551, 'seconds' => 701.46,
// ]

lmpStats() options

$demo->lmpStats(
    game: null,       // null = Doom, 'H' = Heretic, 'X0' / 'X1' = Hexen v1.0 / v1.1, 'A' = Doom alpha
    debug: 0,         // 1 = print start/end offsets, 2 = also print every tic
    classic: false,   // Doom Classic v1.11 format
    zdoom9: false,
    keepTics: false,  // true = also decode every tic into $demo->tics (see below)
);

lmpStats() throws UnsupportedDemoException when the file cannot be opened, is empty, or is in an unknown format. It never writes to stdout unless debug is set. $demo->stats is [] until a demo has been parsed successfully.

stats['tics'] is an int. In a multiplayer demo it is the number of records divided by the number of players. It is only a float when that division doesn't come out even, which means the demo is truncated.

Properties set by lmpStats()

Property Meaning
stats Summary array (above)
ticDataOffset Byte offset of the first tic record (null before parsing)
ticLength Bytes per tic record: 4 vanilla, 5 longtics, 6 Heretic/Hexen and v1.01/v1.12, 8 Doom64 EX, variable for Eternity
ticRate Tics per second: 35, or 30 for Doom64 EX
ticDecoder Demo::DECODER_VANILLA, DECODER_LONGTICS, DECODER_HERETIC, or null when the format's tics are only counted
footer Bytes after the 0x80 end marker (up to ~4 KB, usually the port's footer), or the leftover bytes of a partial final tic
ticCount Tic count as an int
tics Decoded tics, only when keepTics: true

Reading tics

Tics are not kept in memory by default. A multi-hour demo has hundreds of thousands of tics, and storing them all would use hundreds of MB. To read them, stream them with the tics() generator, which uses constant memory:

$demo->lmpStats();                 // optional: tics() calls it with defaults if needed

foreach ($demo->tics() as $tic) {
    // $tic = [
    //   'index' => 0, 'player' => 0, 'raw' => '32322000',
    //   'forward' => 50, 'strafe' => 50, 'turn' => 8192,
    //   'fire' => false, 'use' => false, 'weapon_slot' => null,
    //   'special' => false, 'pause' => null, 'save_slot' => null,
    //   'lookfly' => null, 'artifact' => null,
    // ]
    echo Demo::ticToCsvRow($tic), "\n";
}
  • turn is the full 16-bit angleturn. Short-tic formats only store the high byte, so their value is always a multiple of 256.
  • weapon_slot is only set when the tic requests a weapon change. It is a slot number, not a weapon: the game turns slot 0 into the chainsaw and slot 2 into the super shotgun, depending on what the player owns.
  • When special is true, the tic is a pause or save-game command. pause and save_slot are set, and fire, use and weapon_slot are null.
  • lookfly and artifact are only set for Heretic/Hexen.
  • player is the zero-based number of the player the record belongs to.
  • Formats without a decoder (ticDecoder === null) only fill index, player and raw.

For short demos you can keep everything in memory instead:

$demo->lmpStats(keepTics: true);
$demo->tics[0];
$demo->convertTicsToCsv();
file_put_contents('tics.csv', $demo->ticsCSV);

Testing

.\vendor\bin\phpunit.bat --coverage-html coverage

tests/DemoSyntheticTest.php builds small LMP files with pack() to cover each demo format and edge case.

Using this package with Claude Code

The package ships a Claude Code skill that explains how to use it, including the parts that are easy to get wrong: catching exceptions, streaming tics, and weapon slots. Copy it into the project that uses this package:

mkdir -p .claude/skills
cp -r vendor/andach/php-doom-wad-analysis/skills/php-doom-wad-analysis .claude/skills/

Claude loads it automatically whenever a task involves this package. Copy it again after upgrading to pick up API changes.

Changelog

See CHANGELOG.md.

Output

Calling $analyser->analyse() returns a deeply structured array that breaks down the contents of the WAD file. This output is intended for developers or tools that need to introspect, validate, visualize, or modify DOOM WAD data.

Top-Level Structure

[
    'type' => 'PWAD' | 'IWAD',
    'complevel'    => 21
    'has_playpal'  => true | false,
    'has_colormap' => true | false,
    'playpal'      => [...],    // Present only if has_playpal is true
    'colormap'     => [...],   // Present only if has_colormap is true
    'counts'   => [
        'maps'     => 32,
        'things'   => 1234,
        'linedefs' => 1234,
        'sidedefs' => 1234,
        'vertexes' => 1234,
        'sectors'  => 1234,
    ],
    'maps' => [
        'MAP01' => [
            'things'   => [...],
            'linedefs' => [...],
            'sidedefs' => [...],
            'vertexes' => [...],
            'sectors'  => [...],
            'counts'   => [
                'things'   => 1234,
                'linedefs' => 1234,
                'sidedefs' => 1234,
                'vertexes' => 1234,
                'sectors'  => 1234,
            ],
        ],
        ...
    ]
]

Maps Structure

Things

Entities such as players, monsters, items, decorations, etc.

[
    [
        'x' => 128,
        'y' => 512,
        'angle' => 0,
        'type' => 1,
        'flags' => 7,
    ],
    ...
]

Linedefs

Defines the walls and logic lines between points.

[
    [
        'start_vertex' => 0,
        'end_vertex' => 1,
        'flags' => 1,
        'special' => 0,
        'sector_tag' => 0,
        'right_sidedef' => 0,
        'left_sidedef' => -1,
    ],
    ...
]

Sidedefs

Texture information for each side of a wall (linedef).

[
    [
        'x_offset' => 0,
        'y_offset' => 0,
        'upper_texture' => 'BRICK1',
        'lower_texture' => 'BRICK2',
        'middle_texture' => 'BRICK3',
        'sector' => 1,
    ],
    ...
]

Vertexes

2D points used by linedefs to form geometry.

[
    [ 'x' => 128, 'y' => 64 ],
    ...
]

Sectors

Defines vertical space areas with floor/ceiling properties and lighting.

[
    [
        'floor_height' => 0,
        'ceiling_height' => 128,
        'floor_texture' => 'FLAT1',
        'ceiling_texture' => 'CEIL1',
        'light_level' => 160,
        'special' => 0,
        'tag' => 0,
    ],
    ...
]