Session, mesh and lobby layers under the battle protocol

What sits below and before the 26 battle messages of “The original network protocol (executable)”: read from PDUWP.exe (image base 0x140000000). Nothing here was checked against a packet capture, so the best grade is M (read in code); tables dumped from the data section are H. Names are ours. The summary for a compatible peer, with the Epic Online Services side of Phantom Dust Rebirth, is converter/NETCOMPAT.md.

Corrections to the older section made with this one: the battle send’s odd-tick packet is the player info packet (lobby type 1) carrying the voice bytes, not a voice-only packet; the lobby dispatch has handlers for types 1..21 (1..10 match lobby, 11..20 card trade, 21 leave), not “23 lobby handlers”.

Layers of one datagram

layer size what
UDP – one dual-stack socket (the port of the app’s network manifest, 43210; address and port of a peer come from the platform’s endpoint pair)
mesh message header 7 below
session wrapper 8 {u16 game packet length + 6 (voice not counted), u16 0x1200, u16 type, s16 sender’s member id}
game packet ≥ 0x18 the 0x18 header of the network section, then battle messages or a lobby payload
voice 0..0x200 appended when the sender has voice for that peer

Mesh layer (the platform sample’s mesh component, compiled into the exe) (M)

Classes carry the handles NetworkMesh.MeshManager, MeshPacketManager, MeshConnection. Packet manager constructor 0x140027870 (object size 0x2928), created by the mesh manager initialiser 0x1400370a0; game side wrapper object at 0x1404bbc48.

Message header, little-endian, packed:

off type field
0x00 u16 sequence: one counter per packet manager for all peers (manager + 0x80), incremented before use, so the first is 1
0x02 u8 type
0x03 u16 length of the whole message, header included
0x05 u16 flags: 0x8000 = the receiver must acknowledge
type body builder meaning
1 none (the heartbeat payload size, manager + 0x289c, is 0) 0x1400281a0 heartbeat
2 u8 responding, u16 name length in characters, UTF-16 name 0x140028310 hello
3 bytes – chat (not used by the game’s own traffic)
4 none; the header’s sequence is the acknowledged sequence 0x140028670 acknowledge
0x40 + n bytes 0x1400287e0 (n must be below 0xC0) custom message n; the game sends everything as n = 0, flag clear (0x1400fa1a0)

Session wrapper and session control (M)

Wrapper builder 0x140125430(member, –, game packet, length, voice, voice length): {u16 length = game packet length + 6, u16 0x1200, u16 type = 8, s16 sender’s member id 0x140594e80 (−1 before a join is accepted)}; the voice bytes follow the game packet and are not counted in the length word (the datagram is 8 + game packet + voice). Voice is left out when the member’s flag + 0x24 is set. The receive side (0x1401252f0, up to 0x400 bytes) checks the 0x1200 word; type 8 goes to the game packet arrival (0x140190c80), types below 11 go through the handler table at 0x1403e6810 (11 entries of 16 bytes, H dump). (Corrected by netcompat2: the word at + 6 is the sender’s member id, not a session word, and all of types 0..10 have a handler; the control messages are decoded in “Session control, mesh leftovers, lobby values and card trade”.)

Session member table 0x140595ea8: records of 0x298, count 0x140594ea4 (M):

off field
0x00 u32 in use
0x04 u32 player (net) index 0..3; index 0 is the host
0x08 u32 keep-alive countdown (0xF written after a send)
0x24 u32 no-voice flag
0x28 u32 address length, then the device address bytes (at most 300)
0x288 pointer used for the member’s display entry

What the platform supplies, and only this: the session document (who is a member, the host device token, the members’ device addresses as opaque byte strings) and the endpoint pair that turns a device address into a UDP address. Peer ids on the wire are the net indices 0..3 of the member table; the index is in every game packet header (+ 0x08).

Game packet header, completed (M)

off type field
0x00 u64 battle: presence mask; lobby: 0x8000000000000000 + lobby type
0x08 u32 sender’s net index
0x0C u32 battle: elapsed tick / 2; lobby type 3: the member count the sender is complete for; else 0
0x10 u32 battle: lead report; lobby: 0
0x14 u32 talk flag: the value of 0x140184730 (1 in one voice mode: 0x14050d2a4 = 4 with bit 0x10000 of 0x14051d428, else from 0x14051c0a0). A receiver that sees a peer’s packet with voice while this is not 1 lights that peer’s talk mark for 30 frames (manager + 0x71c[sender]) (L for the exact meaning)

Packet arrival 0x140190c80: for a lobby packet (bit 63) the low word of the mask is the type, at most 22, dispatched through 0x1403e8850; for a battle packet the in-battle flag 0x140527a00[sender] is set and its countdown 0x1405279c8[sender] goes to 10. A lobby packet from a peer counts that countdown down (the “10 lobby packets without a battle packet” rule of the network section’s Disconnect).

Lobby messages (M; table H)

Dispatch table 0x1403e8850, 23 entries, handler(–, packet). Types 0, 12, 17, 22 have the empty handler. All lobby packets are sent unreliably and repeated by the lobby tick; the protocol converges by repetition, not by acknowledge.

type size sender receiver meaning
0 0x18 lobby tick – keep-alive (carries voice)
1 0x80 0x1401910a0 0x140191a60 player info (below)
2 0x30 0x140191700, host only 0x140191b40 start: the battle table (below)
3 0x18 0x1401912e0 0x140191be0 “I hold everyone’s info”; header + 0x0C = the member count it is true for; the receiver sets complete 0x140527c30[sender] when that equals its own count 0x140527a34
4 0x18 none in this build 0x140191c00 sets 0x140527990[sender], which nothing reads (only cleared, by 0x140187710 and when a member leaves): dead in this build (M, netcompat2)
5 / 6 0x18 lobby tick, non-host, to the host only 0x140191c20 / 0x140191cd0 team change request (team game only): the host sets side 0x140527c40[sender] to 0 / 1, forgets the info it holds from peers 1..3, recounts the members and answers everyone with type 9
7 0x18 lobby tick 0x140191d80 “send me your info again”: clears info-sent 0x1405279a0[sender]
8 0x18 lobby tick 0x140191da0 “I have not seen your type 3”: clears the own type-3-sent latch 0x14052797c
9 0x18 0x140191430 (to all) 0x140191db0 “the table changed”: sets 0x140594e90; the next lobby tick resets the exchange (0x1401870f0)
10 0x18 forced type of the lobby tick 0x140191dc0 “not complete”: clears 0x140527c30[sender]
11..20 0x18 0x140192330, 0x1401923a0, 0x140191430 0x140191de0.. card trade (state 0x140527abc, role 0x140527a44): decoded in the netcompat2 section
21 0x18 0x140213e30 0x140192030 leave: the receiver runs its session leave (0x140126aa0)

Type 1, player info (0x80 bytes with the header):

off type field
0x18 u64 player value 0x140527bd8 → 0x140527c58[sender]: a 0..999 999 counter of the sender’s save (netcompat2 section)
0x20 s32 menu choice 0x140527bc0 → 0x140527c20[sender], −1 = none (set by the script command 0x140213b80; meaning is the lobby script’s, L)
0x24 s32 side 0x140527c40[own] (team)
0x28 s32 host only (else 0): stage id (0x140527bc8)
0x2C s32 host only: the drawn stage variant (0x140527c54)
0x30 s32 host only: game type (0x1405277b4)
0x34 s32 host only: game rule (0x1405277fc)
0x38 s32 host only: free private slots 0x14051ede0
0x3C s32 host only: free public slots 0x14050e13c
0x40 char[64] player name → 0x140527ac0 + 0x40 × sender

Receiver: marks info-received 0x140527a20[sender]; the six host fields are taken only from net index 0. The same packet is sent on the odd ticks of a battle with the voice bytes, so names, sides and host settings keep flowing during the fight.

Type 2, start (host → every member, 0x30 bytes):

off type field
0x18 s8[4] start order: 4 × g + a random permutation of 0..3, g = 5 or 6, drawn by the host (0x1401907a0: 100 random swaps with the C library generator) → 0x1405279e8 (corrected, netmsg: the base 4 × g was missed; captured 24..27 and 20..23)
0x1C s32[4] the four menu choices (0x140527c20)
0x2C s8[4] the four sides (0x140527c40, copied to 0x140527980)

Start routine 0x140187e80 (lobby phase 0x140527920 must be 1): on the host (bit 2 of 0x1405277cc, after the all-complete check 0x140191910) it draws the order, clears the clock-sync state (lead, ahead, peer ticks −1) and sends type 2; on a client the type 2 receiver stores the table and runs the same routine without the send. Both set the match start latch 0x1404bbca4 = 0 and the lobby phase to 2.

Lobby tick 0x14027b480(–, –, forced type, flag), every 3rd frame of the lobby (counter 0x1405277c0), from 0x140187600 (forced type 10 while 0x1405277c4 is 0, else none) and 0x1401876b0 (none):

  1. Voice captured since the last tick is appended to the outgoing packets (manager + 0x518, length + 0x718).
  2. A pending type 9 is acted on.
  3. When the own info table is complete (0x14027a850: at least 2 members, info from each) and type 3 was not sent yet → type 3 to all. Else, team game on a client: the two shoulder inputs send type 5 / 6 to the host when the side would change.
  4. For each other member: info not sent yet → type 1; else the forced type when there is one; else type 7 when its info is missing, type 8 when its type 3 is missing, else type 0.

Lobby phases (0x140527920), set by the session script commands at 0x140187180..: 1 lobby → 2 started (type 2) → 3 (0x140187650: counter 90) → 4 (0x1401876b0: stage id and variant copied to the stage loader 0x1401d1b90) → 5 → 6 → 7; 0x140187b70 returns to 1 for the next round and the host draws a new variant. The battle itself then starts in step through battle message 22 (every present player loaded) and stays in step through the stall rule (network section, Clock).

What is not sent in the lobby: no deck, no card list, no random seed. A peer needs from the others only name, side, the menu choice and the host’s stage / variant / type / rule and start order; each deck stays on its owner’s machine (the battle shows the others only button cards, capsule states and the deck count).

Open fields of the battle messages, narrowed (M / L)

Implementation notes for the rebuild