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) |
- Send 0x140028d10: a message with flag 0x8000 is first put on a pending list keyed by sequence (0x140028a40, list at manager + 0x28d8), then every message goes on the send queue (manager + 0x27f0) that the send thread (0x140028e90 → 0x140029080) empties. The destination address comes from the endpoint pair of the connection.
- Receive 0x140029330 → dispatcher 0x140029c50: flag 0x8000 → an acknowledge (type 4) with the same sequence goes back; type 4 removes the pending entry (0x14002a6a0); other types go to their event (heartbeat, hello, chat, custom with n = type − 0x40 and the body = length − 7 bytes).
- Duplicate / order filter 0x140029bb0: only when the manager’s flag + 0x90 is set, a message is dropped unless its sequence is above the last one seen and less than 0xCCC ahead. The game creates the mesh with that flag 0 (0x1400f94dc), so nothing is filtered at this layer; order and duplicates are handled by the game packet layer (newest tick per sender, sequence lists).
- Connections have a state: 2 = associated (an endpoint pair exists; an incoming one is accepted for any remote device, 0x140037740), 3 = hello exchanged. Two timer threads (0x1400166f0(period)): every 1000 ms 0x140037840 tries to create the endpoint pairs still missing; every 2048 ms 0x140038080 sends a hello (responding = 0) to each state 2 connection and a heartbeat to each state 3 connection. A hello with responding = 0 is answered with one with responding = 1 (0x14003aab0); either moves the connection to state 3 (M, the state numbers are from the routine’s two loops; the 2 → 3 step was not read line by line).
- The game sends to a peer only through a state 3 connection whose device address equals the session member’s address (0x1400fa1a0 compares length and bytes; a send to the own address is looped back locally).
- Resend and time-out (completed by netcompat2, see “Session control, mesh leftovers, lobby values and card trade”): the mesh has no resend timer and no heartbeat time-out; a peer is dropped by the session layer’s 150-tick silence rule.
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):
- Voice captured since the last tick is appended to the outgoing packets (manager + 0x518, length + 0x718).
- A pending type 9 is acted on.
- 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.
- 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)
- Position message 0x1C /
0x1E: two looping attachments on the
body’s action component (C + 0x12f00): id A at +
0xC34, started / stopped by 0x140259540 /
0x140259670; id B at
- 0xC48, by 0x140259800 / 0x1402598d0. The remote update (0x14018f504..) starts the new id when the sample’s differs and stops it on −1. They sit next to the damage effect sender (message 20), so A / B are read as the looping body effect and the looping cue (L for which resource table each id indexes).
- Header 0x14: see the header table.
- Start order and stage variant are the only host-drawn random values a peer must take over; both travel in the lobby (type 2, type 1).
- Still open: the first value of message 22 (C + 0x60), the setters of object flag 0x1000 other than 0x14026f4b6, stage message fields 0x11 / 0x12 of message 7.
Implementation notes for the rebuild
- A compatible net mode needs, bottom up: the 7-byte mesh header with hello / heartbeat / acknowledge (answer every flagged message, send hello until answered, heartbeat every 2048 ms), the 8-byte wrapper with type 8, the 0x18 game header, then lobby types 0..10 and 21 and the battle messages.
- The lobby is a repeat-until-complete exchange at one packet per member every 3rd frame; implement it as the same small state per peer (info sent, info received, complete, type-3 sent) rather than as request / reply.
- Take stage, variant, type and rule only from net index 0, the start order from type 2.
- Session control (wrapper types 0..10) is the gap between “mesh connected” and “in the member table with a net index”: decode it or capture it before building the join.
- Card trade (types 11..20) can be refused: never enter trade state.