Wormsign
Wormsign is the match’s tick clock and state hash. A tick is one 20 ms step of the game’s simulation, 50 per second. At the end of each tick Wormsign hashes the logic RNG, the turn, the worms, the scheduled tasks, the projectiles and the teams (the engine hash), plus whatever mods feed in (the mods hash). Two machines that agree on a tick’s hashes agree on the game state at that tick.
Replays
Section titled “Replays”A recording (Documents\Melange\replays\*.wsr) holds what is needed to play a local match again: the seeds, the
random draws made in the menus before the match, every input with its time, the hash of every tick and a fingerprint
of the match setup. A replay plays the match again with those inputs and compares each tick with the recording.
- Open the overlay panel Wormsign/Replay at the main menu and arm a recording.
2. Start a Quick Game from the main menu. The replay needs the same route into the match as the recording: the
match setup is rebuilt from the recorded menu draws, not written directly.
3. At the first tick the setup (level, land, theme, scheme and teams) is checked against the recording. If it
differs, the replay stops with “setup differs” and names the first difference. It never reports that as a
divergence.
4. While the replay plays, your own inputs are ignored and the recorded ones are sent at their recorded times.
Pause, change the speed (0.25x to 8x) or run to a tick. Running to a tick that has already passed needs a restart:
Restart arms the recording again, and once you quit the match you start the Quick Game again.
5. The panel counts the ticks compared and matched. At the first tick that differs it shows “Diverged at tick N” and
which parts of the state differ (diff). The replay keeps playing so you can watch what happens next.
Arming is refused while you are in a lobby or online, during a match, for a recording of an online match (or one
that ran an agreed online sim fix such as FixDrumFuse, which its HEAD lists under fixes: a replay runs offline,
without them), for a recording made with match rules on a build that cannot apply them (the Rules module is off or the exe is not build 1077: the reason names the rules hash), for a recording made with another game build, and for one made with different mod content (unless
[Wormsign] ReplayAnyContent=1). A recording whose hash version differs from this build’s plays without being
compared.
Known limitation (Melange 0.18). A LocalNet recording that ran an agreed online sim fix (FixDrumFuse) cannot be
replayed: arming it is refused with the fixes named, and replaying it offline is not planned for this
release. To check a LocalNet match, compare the two peers’ recordings with python tools/wsr/wsr.py diff a.wsr b.wsr.
The wormsign.replay test command does the same from scripts: arm <file>, disarm, pause, resume,
speed <x>, runto <tick>, restart [tick] and status.



Setting ([Wormsign]) |
Default | |
|---|---|---|
Record |
1 | 0 records no match. Retention (KeepMatches, MaxMB) then prunes nothing either: a launch that records nothing never deletes a replay or a desync bundle (test launches with Record=0 had pruned a player’s recordings at every start, 118, 36 and 3 at a time), and the library view keeps the limits for the next recording launch |
ReplayAnyContent |
0 | 1 replays a recording made with different mod content |
ReplayPassLocal |
0 | 1 lets local-only inputs (the camera) through while a replay plays; by default every live input is ignored |
HashCamera |
0 | 1 adds the melange.camera contributor: the active logical camera in the mods hash of every tick (see The logical camera) |
Record layouts in a .wsr file
Section titled “Record layouts in a .wsr file”The container (chunks, compression, index, recovery of truncated files) is described in src/wormsign/format.h.
These are the payloads of the record chunks, little-endian and packed:
| Chunk | Payload |
|---|---|
SEED |
n × {u8 kind, u32 value, u32 caller, u32 t}: kind 0 is the logic RNG, 1 the second RNG; caller is the return address of the seed call |
PDRW |
n × {u8 rng, u32 ret, u32 stateAfter, u32 bits}: the random draws made before the match, in order; bits is the result (an integer or float bits) |
INPT |
n × {u8 type, u16 id, u32 a, u32 b, u32 time, u32 callT, u32 caller, u8 strLen, strLen bytes}: type 0-5 is message, int, two ints, float, two floats, string; a and b are the values (float bits for floats); time is when the input takes effect and callT the logic time of the call |
TICK |
u32 firstTick, then records: 0 followed by {u64 engine, u64 mods, u64 c[6], u32 rngLogic, u32 rng2, u16 fpucw, u16 inputs} for one tick (the next tick number follows), or 1 followed by u32 n for n missing ticks |
SETP |
JSON: v, level, landFile, landTheme, dataBank, timeOfDay, levelDetails, lastScheme, schemeName, scheme and init (16-digit hex hashes of the scheme and team setup), teams: [{name, worms}], and from 0.18 rulesHash (the SHA-256 of the match’s rules document, empty for none), rules (that resolved document as canonical JSON text, only when there were rules) and rulesFnv (the dereferencing scheme fnv, below) |
Match rules (0.18). A match with rules (docs/rules.md) records the applied document in SETP. Arming such a recording
validates the document against this build’s rules registry (its SHA-256 must equal rulesHash) and freezes it with
source replay: the replay’s match VM gets it, before the level reads its style, whatever a local rules switch or
rules.test would do, and it is dropped when the replay ends or is disarmed. The player logs [wormsign] replay: rules applied <hash16> (scheme fnv ...) at tick 1 and compares rulesHash and rulesFnv with the live match: a match with other
rules, or with rules where the recording had none, stops with “setup differs: match rules: …”. Recordings from before
0.18 have no such fields and are not compared. The fnv is the pointer-free hash over GM.SchemeData and its 58 weapon
objects (SchemeFnv, docs/rules.md “Applying the rules”), which the older scheme field cannot cover (it skips the weapon
references).
The contributor melange.rules (version 1) folds the applied document’s SHA-256 and that fnv into the mods hash. The fnv is
read at tick 1 and again after each turn start, not every tick; a match without rules hashes one constant byte. It exists
whenever the Rules module applies rules, so recordings made before 0.18 compare the engine hash only.
The HEAD chunk’s contributors (an array of {name, version}) decides whether a replay also compares the mods
hash: only when the recording and the running game have the same set.
Crashes and incomplete recordings
Section titled “Crashes and incomplete recordings”A recording is written while the match runs. HEAD, SEED and PDRW reach the disk when the match starts, SETP
at its first tick, and the ticks, inputs and details every 500 ticks (10 s); the writer thread flushes every batch it
writes. If the game crashes, the crash handler gives the writer what is still buffered and a NOTE with
"reason":"crash", and waits up to 3 s for it to reach the disk (recording: ... on disk in Melange.log). Without
that, a crash loses at most the last 10 s.
A file without INDX and the trailer is incomplete: the reader keeps every whole chunk up to the first damaged or
missing one. The library, the replay panels and tools/wsr/wsr.py info show it as incomplete. Export last game’s
logs includes it, redacted like any recording and marked "incomplete": true in manifest.json. A file too short to
hold its HEAD chunk (an empty one, for example) has nothing that can be redacted, so the export lists it under
absent with the reason (“empty: the game crashed before the recording was written”).
If reading another module’s state at the match start faults (the game state, the mod content id, the contributors, the RNG logs), the recording continues without that one value and the log names the read and the exception.
Desync detection
Section titled “Desync detection”In an online match every player runs the same simulation from the same inputs. When one machine’s state drifts, the game notices only at the end of a turn, and then ends the match with “This session is no longer available”. Wormsign compares the hashes of every tick with the other Melange players in the lobby, so a desync is reported at the tick where it happened, usually within a second.
- Who it talks to. Each Melange player with
[Wormsign] Exchange=1writes the lobby member keymlg.ws=1. Hashes go only to members whosemlg.wsis the same version. A player without Melange, or with Wormsign off, gets nothing: Melange never sends them a packet, and a match against them is byte-for-byte the same on the wire as without Melange. - How. Steam P2P channel 5, which the game neither uses nor reads. A batch of tick hashes goes out every half second, about 1.2 KB/s per player.
- What it compares. The engine hash, always. The mods hash, when both players have the same mod contributors; otherwise the Wormsign/Peers panel says “mod contributors differ”. With
HashCamera=1the mods hash includes the logical camera (melange.camera), so it is compared only with players that have it on too. - A contributor one side did not hash. A contributor’s value in a
COMPSanswer is 0 when that machine did not compute it at that tick (it was demoted there and skipped the tick, or had faulted): its mods hash then holds the contributor’s last computed value instead. Wormsign sorts every contributor that differs at a mods-only mismatch. Both sides hashed it: a desync of that contributor. One side did not, and that side’s mods hash is exactly the fold of its other values: the contributor faulted there (or was never computed) and is left out of that hash for good, so it is a desync too. One side did not, and its mods hash is not that fold: it was skipped by demotion there and its last value folded in, which is not evidence of different state. When every differing contributor is a skip, it is not a desync: the log says so (“tick 9004: the mods hash differs from player only because player did not hash mod.sandtide.env at that tick (demoted there)”) and the mods hash is no longer compared with that player for the rest of the match (the panel: “mods not compared: a contributor was skipped on one side at tick 9004”); the engine hash still is. When one side has several zeros a fault among them cannot be told from a skip, and the log and the panel say “cannot tell”. When a skipped contributor comes with one that really differs, the desync names the one that differs and the log lists the skipped one beside it. Melange 0.11.1 and earlier demoted a slow mod environment digest to every 10 ticks by default, so a mod’s first state change on a skipped tick was reported as a desync ofmod.<id>.envby every faster machine in the lobby; 0.11.2 never demotes by default (see For modules). - Confirming a mods-only mismatch. It is judged from the peer’s per-contributor hashes (its
COMPSanswer). When the answer is not there after 400 ms Wormsign asks once more and waits 2 s; when it never comes, the mismatch is logged as unconfirmed (“tick 700: the mods hash differs from player … unconfirmed, not reported as a desync”), there is no message and no bundle, and the mods hash is no longer compared with that player (the panel: “mods not compared: a mismatch at tick 700 was not confirmed”). An engine mismatch does not wait for it. - What a desync does. Nothing to the match: Wormsign never pauses or ends it, and the game’s own turn-end check keeps working as before. Wormsign shows a message (“Desync at tick 5000 (worms) with player, bundle saved”), writes the log, and saves a desync bundle.
[Wormsign] OnDesync=bundle-onlykeeps the message off the screen.
The overlay panel Wormsign/Peers lists every lobby member: whether hashes are exchanged (“no exchange” for a player without it, “version mismatch” for another protocol), the last tick both sides compared, how many ticks the other player is behind, and, after a desync, how long the two have stayed apart.
The desync bundle
Section titled “The desync bundle”Documents\Melange\replays\desync-<date>-p<process>-m<match>-t<tick>.zip holds:
| File | Content |
|---|---|
report.json |
The tick, both engine and mods hashes, which engine parts differ, the first differing mod contributor (with oursComputed/theirsComputed: false when that side did not hash it at that tick), every lobby member’s exchange state, Melange version and content hash, the game’s own turn-end checks during the match and engineCorrelation, which pairs the engine’s turn-end failure with the latest divergence whose engine hashes differed at or before the failed check (a mods-only flag earlier in the match is not it, nor is an engine divergence that started later) |
diff.txt |
Header lines with the hashes, the differing engine components and contributors (# contributor mod.x.env 33f3... -> (not hashed on the peer at this tick: demoted or faulted there) when the peer’s value is 0), the logic-RNG distance when both detail records are there (# rng: ours 0xe01dc3c7, theirs 0x42ecc01e (= our value at the end of tick 22521): the peer is 57 logic-RNG draws behind us; the game’s logic RNG is the LCG x * 1103515245 + 12345, so a known distance says how many draws one side made that the other did not), and the engine correlation. Then one line per field that differs at that tick, ours first: worms[3].energy 100 -> 1 |
detail-local.json, detail-peer.json |
The state at that tick on both machines, as far as it is known |
match.wsr |
The match recording, when one is kept |
logs/Melange.log, logs/session.jsonl |
The last two minutes of both logs |
mods.json, sysinfo.txt |
The enabled mods, and the system information of Save logs as… |
Bundles follow the redaction of Save logs as…: SteamIDs and IP addresses are replaced with a hash that is different in every bundle, and the Windows user and computer names are replaced. Export last game’s logs includes every bundle and recording of that game (matched by the pid in the file name); Save logs as… includes the newest bundle and recording.
When the game’s own turn-end check later fails, the log and the panel say how far behind it was and name every check that failed, not only the first: “Wormsign flagged tick 5000; the engine’s turn-end check failed at tick 7488 (reasons 7,8,9,11,13: camera’s active view matrix differs; camera’s logical position differs; camera’s logical target position differs; worm data mismatch; local and remote worm data differ)”, or “(reason 5: Random’s dont match)” for one. In session.jsonl the engine validation and engine correlation records keep reasons as the bitmask (bit n-1 for reason n) and add reasonList (“7,8,9,11,13”); engine validation’s reason and engine correlation’s reasonText hold every failed check’s text joined by “; “, and engine correlation’s numeric reason stays the first one. In report.json and the ENGV chunk each check’s reasons lists every number and reason every text.
The game’s reasons are: 1 source of validation differs, 2 no active worm, 3 worm indexes differ, 4 task list, 5 random numbers, 6 active camera name, 7 the active logical camera’s view matrix, 8 its position, 9 its target, 10 its up vector, 11 worm data, 12 weapon inventory, 13 local and remote worm data. Reasons 7-10 hash the active logical camera (GameStateValidationMsg 0x68a027/0x68a335 through CameraManagerService::GetLogicalViewMatrix 0x562730), the camera the simulation steps every tick, not the one on the screen.
The logical camera (melange.camera)
Section titled “The logical camera (melange.camera)”The engine hash does not include the camera. With [Wormsign] HashCamera=1, Wormsign adds the contributor melange.camera (version 1), which feeds the mods hash of every tick with the active logical camera’s raw position, target and up vector (camera +0x04, +0x10, +0x1c; the camera is *(0x95c370)’s camera vector at +0x2a0 indexed by m_uLogicalCamera at +0x28c) and a flag for whether it could be read. Those are the values reasons 7-10 compare, as stored bits rather than the engine’s sums of them, so a camera that drifts mid-turn is reported at its first differing tick. The camera index, the number of cameras and the view mode (+0x2c) are only in the detail record: the engine compares the camera by name (reason 6), and they need not be the same on every machine. The reads are fault guarded and only read memory.
Every detail record has the camera (camera in wormsign.detail, detail-local.json and detail-peer.json: present, index, count, view, pos, target, up and the contributor hash), with or without HashCamera; wormsign.detail also says whether the record’s camera matches the tick’s melange.camera hash.
Compatibility with players who do not have it (an older Melange, or HashCamera=0):
- It is a contributor, not an engine component. An engine component would change the engine hash version, and a peer with another version gets no exchange at all (“version mismatch”).
- The mods hash is compared only between players whose contributor lists match (
contributorListHashinHELLO). A player withoutmelange.camerahas another list, so with them only the engine hash is compared: no false desync, and a real engine desync is still found. The Wormsign/Peers panel says “mod contributors differ” for them. That also means the other mod contributors are not compared with that player. - Recordings list their contributors, so a replay compares the mods hash only when the recording has the same set (a recording made without
melange.cameraplays with the engine hash only). - An older Melange’s detail record has no
camera, so a bundle from a desync with it listscamera.*as “(none)” on its side indiff.txt. - It is off by default until two players have run whole matches with it and agreed: the game checks the logical camera only at turn ends and time syncs, so that it also agrees between those checks is not yet verified. Turn it on on every machine of a test match. A camera desync names
melange.cameraas the differing contributor, anddiff.txtnames the fields (camera.target.x 512.25 -> 512.5).
The girder kit’s aim (GirderKitLogicEntity 0x55a680, its +0xdc..+0xf0 vectors) is computed from the same camera’s target minus position, so it is covered through the camera; the girder kit entity itself is not hashed.
Testing a mod’s determinism
Section titled “Testing a mod’s determinism”A sim mod must do the same thing on every machine. A mod that reads something only one machine has (a local setting, the camera, the time) desyncs the match. dist\Mods\desync-probe (disabled by default) is a small content mod for trying the detector: on the local event sim.test.desync it changes a global of its own (kind 0) or draws an extra number from its random stream (kind 2). Enable it on both machines of a LocalNet or Steam match, raise the event on one of them, and the detector reports the tick with the mod’s contributor named.
For modules (C++)
Section titled “For modules (C++)”melange/wormsign.h has the tick clock, the hashes and the observers:
OnDivergence(fn, user): called on the main thread with aDivergencefor every desync with another player (Source::Peer) or a replay (Source::Replay): the tick, both hashes, the engine parts that differ (compMask), the first differing contributor and the other player’s SteamID.bundleis empty then; the bundle is written a few seconds later.AddContributor(name, fn, user, options)feeds a module’s own state into the mods hash. It is called at every tick end and should take under 5 µs; a contributor over 20 µs at the 95th percentile of a 500-tick window is logged once as slow ([wormsign] contributor x is slow: p95 50.0 us over 500 ticks,slowin the recording’s NOTE chunk) and keeps being hashed every tick.options.demoteEvery > 1opts in to demotion instead: over that p95 the contributor is hashed only everydemoteEveryticks and its last hash is folded in between. Demotion is decided from one machine’s own timing, so a demoted machine folds a stale hash while a faster peer folds the fresh one, and the first state change on a skipped tick is reported as a desync of that contributor by the faster peer. Leave it at 1 (the default) for anything compared with peers; the mod environment digests never demote.OnSession(fn, user)andOnTickEnd(fn, user, order)run fault-guarded: an observer that faults is skipped for that call, and the first fault is logged with the list, the handle, the observer’s name (Melange’s own observers have one; another module’s is named by the module its function is in) and the exception:[wormsign] session observer 1 (wormsign recorder, 70a1c2d0 melange.asi+0x1c2d0) faulted and was skipped: c0000005 at ..., read of address 00000000. After that it is logged at 10, 100, 1000 … faults.
Client Lua has wum.wormsign.onDivergence(fn) and the event wormsign.divergence (lua-api.md).
The automation verb wormsign.peers logs the exchange with each lobby member and the packet counters; wormsign.stats logs the tick clock and the hash cost.
The exchange protocol, version 1
Section titled “The exchange protocol, version 1”Little-endian. Every packet is at most 1100 bytes and starts with an 8-byte header: the magic WSX1, u8 kind, u8 protocol (1), u16 total length. A packet with a wrong magic, protocol or length is dropped. matchKey is an FNV-1a-64 of the lobby owner’s SteamID and the lobby id.
| Kind | Sent | Content after the header |
|---|---|---|
1 HELLO |
unreliable; every second until the other side has ours, then every 10 s | u32 engineHashVersion, u64 matchKey, u32 firstTick, u64 contributorListHash, u8 flags (1: we have yours, 2: names cut), str8 melangeVersion, str8 contentHash16, u8 n, n × {str8 name, u32 version} |
2 HASHES |
unreliable, every 25 ticks | u64 matchKey, u32 firstTick, u8 n (≤ 50), u64 presentMask, n × {u64 engine, u64 mods} for ticks firstTick..firstTick+n-1; each batch repeats the previous one’s last 15 ticks |
3 COMPS? |
reliable, on a desync | u64 matchKey, u32 tick |
4 COMPS |
reliable, the answer | u64 matchKey, u32 tick, u8 have, u64 engine, u64 mods, u64 components[6], u8 n, n × u64 per contributor, in HELLO order |
5 DETAIL? |
reliable, on a desync | u64 matchKey, u32 tick |
6 DETAIL |
reliable, the answer | u64 matchKey, u32 tick, u16 index, u16 count, u32 total, u16 len, bytes: the tick’s detail record as JSON, at most 64 KB in 1 KB chunks |
7 FLAG |
reliable, on a desync | u64 matchKey, u32 tick, u64 engine, u64 mods, u64 components[6]: the sender’s view of the first differing tick |
str8 is a length byte and that many bytes. The engine components are, in order, time and logic RNG, turn, worms, tasks, projectiles and teams. The contributor list hash is FNV-1a-64 over each name, a zero byte and its u32 version. Detail records are answered at most 4 times a minute per player, component requests 8 times, and only for the current match; nothing received is ever run or used as a path.