Versus network messages
The three network sections above were read
from the executable alone. This one checks them
against two loopback captures of a live
1v1 (11-14, the 2017 game run by
Phantom Dust Rebirth on two machines; the game’s
own datagrams are in clear on the loopback
interface between its UDP port 43210 and the
bridge’s local link port) and records what the
captures confirm, correct and add. The captures
are private test vectors and are not in any
repository. Parser:
converter/netmsg.py (structs from
the tables in these sections;
check, events,
state, lobby modes),
test converter/tests/test_netmsg.py
(made-up packets). Host = net index 0, joiner =
net index 1. Nothing here comes from the
bridge’s code.
Result of the check (H): every datagram of both captures (18 688 and 22 926; 14 950 and 18 821 of them battle packets) parses with the layouts below to its exact length: mesh length = datagram length, wrapper length = 6 + parsed game packet, no unknown mask bit, no trailing byte. So the mesh header, the wrapper, the 0x18 game header, the mask / table-order rule, the 26 sizes, the “u32 sequence after each reliable payload” rule and the acknowledge bits are H. Field meanings are H where a row below says “seen”, else they keep the grade of the older sections.
One datagram, as captured (H)
| layer | bytes | layout |
|---|---|---|
| mesh header | 7 | {u16 sequence, u8 type, u16 total length, u16 flags} |
| session wrapper | 8 | {u16 length = 6 + what follows it without voice, u16 0x1200, u16 type, s16 sender’s member id} |
| game header | 24 | {u64 mask, u32 net index, u32 elapsed tick / 2, u32 lead, u32 talk flag} |
| messages | – | per set mask bit 0..25, in table order: payload, then a u32 sequence when the type is reliable (types 2..25) |
| acknowledges | – | per set mask bit 26 + k (k = type − 2): one u32 sequence |
- An idle battle packet is 87 bytes (7 + 8 + 24 + message 0 (40) + message 1 (8)); the largest seen was 227. Lobby keep-alive 39, heartbeat 7, ping 31, session keep-alive 15.
- Mesh sequence: one counter per sending machine over all datagram types, + 1 per datagram (no other step in 18 686 steps). Type 0x40 for everything the game sends, flags 0; type 1 heartbeat every 2.0 s from each side, all through lobby and battle. No type 4 acknowledge and no type 2 hello occur in the captures (they start in the lobby, after the connection; the game never sets the acknowledge flag).
- How the first reading of these captures maps to this: its “message id 12 08 / 12 0a / 12 04” are the wrapper’s 0x1200 word followed by wrapper type 8 (game packet), 10 (ping), 4 (keep-alive); its “kind 0x01 ack” is the mesh heartbeat; its “75-byte state” is the last 3 wrapper bytes + game header + messages 0 and 1; its “event bitfield and matching ack bits 3 bytes later” are mask bits 2..25 and 26..49 (24 bits apart).
- Talk flag was 0 in every packet and no voice bytes followed any packet (the bridge carries voice elsewhere).
Session control and lobby, as captured (H for what was seen)
- Wrapper type 10, ping, lobby only: body {f64 sender’s clock in milliseconds, u32 flags, u32 0}. Each side sends one about every 0.5 s (its 15-tick countdown) and the other returns the same 16 bytes with flags bit 0 set within ~30 ms. No ping during a battle (476 s without one).
- Wrapper type 4, keep-alive (empty body): seen only in the seconds between the knockout and the next lobby packets, when nothing else was sent.
- Lobby packets (mask = 0x8000000000000000 + type, 24 bytes unless noted) go out at 10 per second per side (every 3rd frame). Seen: type 0 keep-alive (almost all), 1 player info (128), 2 start table (48), 3 complete (header 0x0C = 2 members), 7, 8, 10. Not seen: 4, 5, 6, 9, 11..21 (no team game, no trade, nobody left).
- Type 1 values seen: player value 1000 on both; menu choice 0 (host) and 0x30000 (joiner); side 1 on both; from the host stage 3, variant 1 (first match) then 0, game type 0, rule 0, free slots 0 / 0; a name of 4 bytes, zero-filled to 64.
- Type 2 start table, correction (H, read at 0x1401907a0 and seen twice): the four “start order” bytes are 4 × g + k, g = 5 or 6 drawn once (rand × 2 >> 15, + 5), k a permutation of 0..3 made by 100 random swaps; the captures hold a permutation of 24..27 and one of 20..23. The older text (“a permutation of 0..3”) missed the base. The menu choices were {0, 0x30000, −1, −1} and the sides {1, 1, 1, 1} (unused members: choice −1).
- Order at a match start: host type 2 → both sides repeat type 1 / 7 / 3 for ~0.5 s → battle packets with tick 0. After the knockout: battle packets go on for ~2 s, then type 4, lobby types 10, 8, 7, 3 and after ~9 s the next type 2 (rematch).
- Not captured: hello, the join (wrapper types 2, 3, 5) and leave (6); those stay M.
Game header (H layout; lead rule corrected)
- Tick / 2 rises by exactly 1 per packet (14 048 steps of 1, none larger; packets 66.7 ms apart, 15 per second). It stays 0 for the first ~3.4 s (about 50 packets per side: the phase 2 wait, where the start messages below are exchanged) and starts again at 0 for every battle.
- Lead (0x10), correction: the word is filled in every packet, not only once per 2 s. The sender routine 0x14027ba90 returns the momentary sum over the peers of (own tick − that peer’s newest tick), and only on the send where its send counter mod 30 is 15 the 30-send average (which it also keeps as its own lead). The receiver (0x140190e20) reads the word only in packets whose tick / 2 mod 30 is 15. In the capture the word is 0, 2 or 4 almost always (the other side’s packet is 0..2 packets old). No stall happened in the match (no repeated tick after the start).
Battle messages against the capture
“Seen” = number of first sends in the action-list match and the rematch start, both directions. Sequence numbers start at 0 per type, per sender, per battle.
| # | message | seen | what the capture shows |
|---|---|---|---|
| 0 | position and state | every packet | all fields plausible: health 20 at start, deck 30 → 26 once the four buttons are dealt, knockout tick −1 until the knockout, facing 0..65535 (full 16 bits, not 15), aura level + 1 per aura card used. 0x24 is the opponent’s index from tick 0 to the knockout (then −1) whether or not the lock was held: it is the current target, not “lock held”. Byte 0x27 went to 1 on both sides at tick 3600 of an idle battle (the draw countdown). 0x1A / 0x1C / 0x1E stayed −1 |
| 1 | button cards | every packet | −1 empty, 0 = aura card; a button shows the capsule’s card from the tick of the take and −1 after its last use |
| 2 | fire start | 46 | cast id rises by 1 per cast of that player (shared with message 3); 0x16 is the facing at the cast (equal to message 3’s facing unless the body turned in between); 0x18 = target player index or −1; 0x19 = 10 / 11 / 12 (ground / air / other cast state). Sent 2..30 ticks before the matching message 3 (per skill; 18 or 20 for most). Aura card uses and some button skills send no message 2, only message 3 |
| 3 | fire | 95 | same cast id as its message 2; the 16 floats are a 4 × 4 transform: three unit axis rows (w = 0) and the spawn point (w = 1); 0x52 = 100 in every one; 0x54 = 0 in every one; 0x56 = the cast profile record (equal to the skill id for most, 343 for the aura card, a different record for an air cast); 0x5A = a small per-skill value (0..7, 0xFFFF once); 0x5C button; 0x5D target player or −1; 0x5E = 0 |
| 4 | skill object control | 0 | not seen |
| 5 | skill object end | 26 | object id = the cast id; sent by the victim as well as by the owner: 17 of 26 name an object owned by the other player, with reasons 0, 1, 2, 3 (2 goes with the victim’s hit log in the same packet); the owner’s own are reason 1. 0x52 = 255 |
| 6 | stage hit reaction | 27 | layout as in “Stage events on the net”: s16[3] point at 4, s16[3] direction × 10 at 0xA, material at 0x11 |
| 7 | stage object event | 45 | wire order differs from the queue record (sender 0x14027c200 moves the stamp to the front): {u32 stamp @0, u8 code @4, u16 object index @6, s16[3] point @8, s16[3] direction × 10 @0xE, u8 @0x14, u8 @0x15, u8 @0x16, u8 @0x17, u32 @0x18, u32 @0x1C = record + 0x18}. Stamps are elapsed × 2 + player index (25894 from player 0 at tick 12947, 25901 from player 1 at 12950), so the factor at 0x1404bc9b4 is 2 here. Codes 0x45, 0x47, 0x48, 0x49 seen; 0x47 carried stamp 0 and 200 / 205 in byte 0x14 (not followed) |
| 8 | capsule state | 63 | three at tick 0 (timer 0, the dealt card, 0 = aura capsule); then one per take: timer 420, skill = the next card drawn into that slot, tick = the take; when the deck is used up, skill −1 timer 0. 0x0A = 1 once |
| 9 | environment entry | 3 | {f32[3] point, u32 start tick, u32 end tick, u32 stamp, s16 skill, u8 owner, u8 flags}: end = start + 1800 at the cast; after a capture the owner re-sends it with end = stamp = the capture tick |
| 10 | environment capture request | 1 | {u32 the entry’s start tick, u32 capture tick, u8 owner, u8 0}; answered in the owner’s next packet by the re-sent entry (9) and a message 11 that puts an aura card (skill 0) on the capturer’s button 0 |
| 11 | card into / out of a button | 2 | 0xFFFF = clear: seen once from the opponent, the target’s button went to −1 two ticks later; and the capture answer above |
| 12, 13, 16, 17, 18, 21, 25 | 0 | not seen (no capsule move, steal, player capture, warp, retire in a 1v1 on this stage) | |
| 14 | status slot | 52 | at tick 0 each player sends slots 0, 1, 2, 3 three times round (12 messages, all values 0), one per packet; none later (no stat slot changed in these battles) |
| 15 | draw countdown restart | 88 | payload 0; seen with capsule takes, health changes and environment events |
| 19 | no-damage timer | 4 | value 75, sent 72..84 ticks after the heavier hits (damage 3 and 6) |
| 20 | damage effect | 27 | from the victim in the same packet as its hit log: {effect id = the skill id here, kind 3, cue id} |
| 22 | ready to start | 2 per battle | first value 1 from player 0 and 3 from player 1 (it is written to the player record + 0xCC by the receiver 0x140250480; a per-player set-up value, L for its name); second value 0. Sent during the tick 0 wait |
| 23 | knockout tally | 2 | from the knocked-out player in the knockout packet: column {1, 0, 0, 0} = one for attacker 0 |
| 24 | hit log line | 34 | from the victim at the hit: skill, damage (0 for effect-only hits), attacker, effect flag; the health byte of message 0 drops in the same packet |
Status mask bits seen (message 0): 11 for exactly 90 ticks with each use of one defence card; 4 for 90 ticks and 9 for 450 ticks on the victim of two effect skills; 41 on both players while an environment is active (set in the packet of the entry, cleared in the packet of its end).
Reliability and timing, as captured (H)
- Resend after exactly 6 packets without an acknowledge (79 of 83 resends; the others after 9..11). 121 resends for 437 messages, almost all at tick 0, where 12 status messages queue behind each other.
- One message per type per packet: the 12 start status messages leave in 12 consecutive packets (0.8 s).
- The acknowledge comes in the receiver’s next packet (40..120 ms later for 90 %); a message that was sent twice is acknowledged twice. Two messages were never acknowledged inside the capture.
- Events of one tick ride in one packet in table order (a hit: 15, 20, 24 together with the lower health in message 0).
- The time field inside a message (messages 2, 3, 8) is the sender’s elapsed tick and is 0 or 1 below 2 × header tick.
Rules that rebuild every recorded send (netreplay 11-14; INFERRED where marked)
godot/scripts/net/pd_wire_peer.gd,
played as “this machine” on both recordings
(tests/test_pd_wire_peer.gd),
rebuilds every reliable send, resend and
acknowledge of both sides (9397 / 9397 and 7489
/ 7489 packets; 8 acknowledges of the second
Deck side one packet late, all at the battle 0
tick-0 burst, arrival timing). The rules:
- Send order: per type, at most one message per packet: a never-sent one first (oldest first), else the oldest unacknowledged one whose last send was ≥ 6 packets ago.
- Acknowledge reading (INFERRED): of the acknowledges in one received packet, each is compared against the first one’s sequence; a later one frees its message only when the two sequences are equal. This explains all 47 + 44 recorded resends (the “after 9..11” ones above are resends of messages whose acknowledge was read this way) and predicts none that did not happen.
- Pending list (INFERRED): only sequences 0..19 of a type are kept for resending; later ones go out once.
- Queue: 16 events per type (the net manager’s slots); a full queue drops the event.
- Acknowledge timing (INFERRED): in the first own packet at least one tick after arrival.
- Start: packet 0 holds message 1 and status slot 0 only (no message 0); the dealt capsules (8) start in packet 1, message 22 in packet 2. Tick 0 lasts 51..54 packets (3.3..3.5 s) in the recordings; the rebuild holds a fixed 52 (INFERRED).
- Heartbeat: 2.047..2.048 s apart; the rebuild uses 2048 ms.
- Unsent builds (open): the first Deck side’s battle 1 begins with 8#0, 14#0 and 14#1 missing from the wire; the rebuild matches it only by assuming two packets were built and not sent. Cause unknown.
- Units: position = Godot (x, y, −z) / 0.1; facing 32768 per turn (game yaw = atan2(dx, dz), median 1.6° off the walk direction), Godot rotation.y = −facing·τ/32768.
- Sizes: a packet with messages 0 and 1 and nothing else is 87 bytes (9045 + 7144 of them); each reliable message adds its size + 4, each acknowledge 4.
- Recorded shape per action (first sends per packet): capsule take {8, 15} in one packet (46 times; the three lone 8 are one side’s deck-out messages, skill −1); skill cast {2}, then {3} 1..15 packets later; aura card use and defence {3} alone; hit taken {20, 24} with 5 and / or 15. Rates: 14.8 packets/s over wall time (15 per tick pair; the deficit is hitches), tick / 2 rising by exactly 1.
The action-list match on the wire
Order played: stand, walk, jump, lock-on,
capsule pickup, missed attack, hit, defence,
erase, environment / status, slot overwrite,
pause, round end, second match. What the packets
show, in time order (ticks of the first battle;
netmsg.py events and
state print the full lists):
| tick | what is on the wire |
|---|---|
| 0 (3.4 s) | per player: 12 × message 14, 3 × message 8 (dealt capsules), message 22; message 0 with health 20, target = the opponent; message 1 with the dealt buttons |
| 1..1300 | stand, walk, jump: message 0 only. Action ids change with the position (0 standing; 1, 2, 4, 7, 12 while moving; 34 → 35 → 36 in a row, read as the jump); no reliable message at all for 43 s |
| lock-on | nothing of its own: the target byte never changes in a 1v1; a held lock shows only as target ≥ 0 in the casts’ messages 2 / 3 (−1 without) |
| 1302..1966 | capsule pickups: message 8 (timer 420, next card) + 15; the button shows the card; an aura card use is a message 3 with skill 0 and profile 343 and the aura level + 1 |
| 1847..2228 | missed attacks: message 2, then 3 after 18 ticks, target −1; nothing from the other side |
| 2285..2416 | hits: 2 + 3 (target = the victim when the lock was held); from the victim 20 + 24 + 15 and health 20 → 18 → 16, action 124 (its reaction) in the same packet |
| 2620.. | defence: message 3 only (no 2), status bit 11 for 90 ticks, action 37 → 39 |
| 9611..9636 | erase: a message 11 with 0xFFFF for the other player’s button 3, which empties |
| 11830..12696 | environment: cast (2, 3), entry (9), status bit 41 on both; captured by the other player 838 ticks later: 10 → 9 + 11, bit 41 off, aura card on the capturer’s button |
| throughout | slot overwrite: only message 1 changes (the button’s id is replaced at the take); no message of its own |
| – | pause: no trace. The tick never repeats and packets never stop; an online battle is not held by a pause |
| 13578..13636 | the loser’s deck is used up: three message 8 with skill −1; from 13726 its health falls 1 per 90 ticks |
| 13999 | round end: message 0 with knockout tick 13999, health 0, action 103; message 23; the winner’s target byte goes to −1; ~2 s of packets, then the lobby |
| second match | new type 2 (new start order group), tick and all sequences from 0, the same start burst |
What a third-party peer must do to be accepted
From the code and the captures; “accepted” = the game keeps the peer in the member table, starts the battle and does not knock it out.
- Be a session member with a net index: the join through wrapper types 2 / 3 / 5 (not captured, M) or whatever the platform bridge does in its place, and an endpoint the game’s socket can send to. Send from the address the member record holds.
- Mesh: answer the hello, then a 7-byte heartbeat every 2 s; count the 16-bit sequence up by 1 for every datagram of any type; type 0x40, flags 0, exact total length.
- Stay alive: any wrapper reloads the 150-tick silence countdown; in the lobby send a lobby packet 10 times per second and answer every ping (same 16 bytes, flags | 1).
- Lobby: type 1 with name, side and choice until the host stops asking (type 7), type 3 with the member count, then keep-alives; take stage, variant, type and rule from net index 0 and the start table from type 2.
- Start: at tick 0 send messages 0 and 1, the own three capsules (8), the four stat slots (14) and message 22 reliably; the host starts only when every present player’s 22 has arrived. Acknowledge everything received.
- Battle: one packet every 2 ticks with tick / 2 rising by 1, messages 0 and 1 in each; keep the own tick within 60 of the peer’s or the peer stops; put the averaged lead in the packets with tick / 2 mod 30 = 15; acknowledge each reliable sequence once in the next packet; resend unacknowledged ones every 6 packets; sequences per type from 0 each battle.
- Be honest about the own body: the game takes health, knockout tick, deck count, buttons, capsules and status from the peer without checking, and expects the peer to test the game’s shots against its own body and to answer hits with 20 / 24 (and 5 for the shot), requests with 11 / 13 / 17, and the knockout with the tick and 23.
No checksum, version field, signature or encryption exists in layers 2 to 7: nothing in the header, wrapper or messages identifies a build, and no receiver validates more than lengths, the 0x1200 word, the member id and sequence duplicates. Version gating happens only in the session directory (platform side).
What cannot be known without the bridge (not guessed here)
- How a peer gets into the session and member table when the platform is Rebirth’s bridge: the lobby directory, sign-in, the device address record, the connect handshake and the encrypted wire transport between two machines. The captures show only that the game’s datagrams cross it unchanged.
- Whether the bridge accepts a plain UDP peer at all, and what identifies an allowed build there.
- The hello’s name text and the join messages as sent in practice (capture started after the join).
Still open in the game’s own layers
Message 22’s first value by name; fire 0x52 (100), 0x54 (0 in all 95) and 0x5A by meaning; stage hit bytes 0, 0x10, 0x13.. and stage event bytes 0x14..0x1F; the reasons of message 5 by name; messages 4, 12, 13, 16..18, 21, 25 and lobby types 5, 6, 9, 21 were not exercised; a 3- or 4-player session (mesh fan-out, lead sum over several peers) was not captured.
Implementation notes for the rebuild
- Build the wire codec from
converter/netmsg.py’s tables (they parse all 41 614 datagrams of the two captures): mesh header, wrapper, game header, 26 message structs, sequence and acknowledge placement. Port them to GDScript as data, with the same made-up test packets. - A replay harness comes
first: feed a recorded peer stream
(
netmsg.pycan already split it) into the compatible mode and check that the remote body, buttons, capsules, casts and hits appear; then answer it (acknowledges, own state) and compare the own outgoing stream’s shape with the recorded one. - Start burst at tick 0: 3 capsules, slots 0..3 three times, message 22; hold tick 0 until every present player’s 22 is in.
- Message 0’s target byte = the current target (the opponent in a 1v1) from tick 0, −1 after a knockout; facing uses all 16 bits; deck count and aura level as the game counts them (level + 1 per aura card used).
- Casts: message 2 at the cast start (not for the aura card or the defence kind seen), message 3 at the spawn (2..30 ticks later, per skill) with the caster’s 4 × 4 spawn transform and the cast profile record; the cast id counts all of a player’s casts.
- The victim ends the attacker’s shot with message 5 (reason 2 next to its 20 / 24 on a hit; reasons 0 and 3 also come from the victim’s side); the owner ends its own with reason 1.
- Capsules: message 8 at every take with timer 420 and the next card of the slot; skill −1 when the deck is out. Environment: 9 at the cast (end = start + 1800), status bit 41 while active, capture by 10 → 9 + 11 (aura card to the capturer’s button 0).
- Lead word: momentary value in every packet, the 30-send average when the send counter mod 30 is 15; read it only at tick / 2 mod 30 = 15.
- Stage event wire order has the stamp first; stamp = elapsed × 2 + player index.