Skip to content

Commit

Permalink
Merge pull request #25 from DaniElectra/updates-2024-05-01
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbarrow authored May 1, 2024
2 parents ebaa415 + ce3f2cc commit b089b3c
Show file tree
Hide file tree
Showing 19 changed files with 853 additions and 200 deletions.
45 changes: 45 additions & 0 deletions docs/misc/smm-2-protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
layout: post
toc: true
title: SMM 2 Protocol
---

SMM 2 uses [ENL](/docs/pia/enl).

### Matching Packet

| Offset | Size | Description |
|--------|--------|-------------------------------|
| 0x0 | 4 | State |
| 0x4 | 4 | Padding |
| 0x8 | 8 | NSA ID |
| 0x10 | 16 | UUID |
| 0x20 | 11 x 2 | Name |
| 0x36 | 2 | Padding |
| 0x38 | 88 | [Mii](/docs/switch/mii-data) |
| 0x90 | 2 | Top number |
| 0x92 | 2 | Bottom number |
| 0x94 | 2 | Headwear number |
| 0x96 | 2 | Anim number |
| 0x98 | 4 | Related to battle mode rating |
| 0x9C | 1 | Related to battle mode rating |
| 0x9D | 3 | Padding |
| 0xA0 | 4 | Unknown |
| 0xA4 | 4 | Unknown |
| 0xA8 | 4 | Unknown |
| 0xAC | 4 | Unknown |
| 0xB0 | 4 | Random value |
| 0xB4 | 1 | 0 = Battle, 1 = Coop |
| 0xB5 | 3 | Padding |
| 0xB8 | 4 | Always 4 |
| 0xBC | 4 | Unknown |

### Thumbnail Packet

| Offset | Size | Description |
|---------|---------|---------------------------------|
| 0x0 | 0x1BF9C | Thumbnail (JPEG) |
| 0x1BF9C | 4 | Thumbnail size (always 0x1BF9C) |
| 0x1BFA0 | 32 | HMAC-SHA256 of JPEG data |
| 0x1BFC0 | 16 | RNG state for key generation |
| 0x1BFD0 | 48 | Padding (always 0) |
22 changes: 21 additions & 1 deletion docs/nex/protocols/datastore/super-mario-maker-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Some methods take a `resultOption` parameter. This parameter controls which fiel
| 101 | PostPlayResultMultiClear |
| 102 | PostPlayResultEventCourse |
| 103 | [GetDeathPositions](#103-getdeathpositions) |
| 104 | PostRatingInfo |
| 104 | [PostRatingInfo](#104-postratinginfo) |
| 105 | PostRatingInfos |
| 106 | PostRatingInfoBattleModePersonal |
| 107 | PostRatingInfoBattleModeEntire |
Expand Down Expand Up @@ -689,6 +689,16 @@ This method does not return anything.
| --------------------------------- | --------------- |
| [List]<[DeathPositionInfo]> | Death positions |

### (104) PostRatingInfo
#### Request

| Type | Description |
|--------------|-------------|
| [RatingInfo] | Rating info |

#### Response
This method does not return anything.

### (108) GetEndlessModeStatus
#### Request
This method does not take any parameters.
Expand Down Expand Up @@ -1379,6 +1389,15 @@ This structure is empty.
| Uint32 | Unknown |
| [List]<[String]> | Unknown |

### RatingInfo ([Structure])

| Type | Description |
|--------|-------------|
| Uint64 | Unknown |
| Uint8 | Unknown |
| Uint8 | Unknown |
| Bool | Unknown |

### ReadEventCourseListParam ([Structure])

| Type | Description |
Expand Down Expand Up @@ -1917,6 +1936,7 @@ Revision 3:
[BattleModeRating]: #battlemoderating-structure
[DeathPositionInfo]: #deathpositioninfo-structure
[WorldMapInfo]: #worldmapinfo-structure
[RatingInfo]: #ratinginfo-structure

[DataStoreGetMetaParam]: /docs/nex/protocols/datastore#datastoregetmetaparam-structure
[DataStorePreparePostParam]: /docs/nex/protocols/datastore#datastorepreparepostparam-structure
Expand Down
62 changes: 32 additions & 30 deletions docs/pia/enl/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ On the Switch, a new field was added that lets a client request a system-record.
| Uint32 | Record mask (system) |

## System information
In the tables below, the values of P and Q are configured by the game.
In the tables below, the values of P (maximum number of players) and Q (maximum number of CPUs) are configured by the game.

| Game | P | Q |
|---------------------|----|----|
Expand All @@ -54,50 +54,52 @@ In the tables below, the values of P and Q are configured by the game.

*Wii U:*

| Type | Description |
|-------------------------------|-------------------------|
| Uint32 | Connected AID bitmap |
| Uint32 | Disconnected AID bitmap |
| Uint32 | Unknown |
| Uint32 | Received AID bitmap |
| Uint64 | Session time |
| Uint32 | Principal id |
| Uint32 | Unknown |
| Uint8 | Unknown |
| [UniqueId](#uniqueid) (P*2-1) | Unknown |
| [UniqueId](#uniqueid) (Q) | Unknown |
| Uint8 | Unknown |
| Uint8 (P) | Player id table |
| Type | Description |
|-------------------------------|--------------------------------------------------------|
| Uint32 | Connected AID bitmap |
| Uint32 | Disconnected AID bitmap |
| Uint32 | CPU AID bitmap |
| Uint32 | Received AID bitmap |
| Uint64 | [Session time](/docs/pia/protocols/sync-clock) at join |
| Uint32 | Principal id |
| Uint32 | Unknown |
| Uint8 | Is player id table initialized |
| [UniqueId](#uniqueid) (P*2-1) | Player unique ids |
| [UniqueId](#uniqueid) (Q) | CPU unique ids |
| Uint8 | Player id sync unique |
| Uint8 (P) | Player id table |

*Switch:*

| Type | Description |
|-------------------------------|-------------------------|
| Uint64 | Connected AID bitmap |
| Uint64 | Disconnected AID bitmap |
| Uint64 | Unknown |
| Uint64 | Received AID bitmap |
| Uint64 | Session time |
| Uint64 | Principal id |
| Uint8 | Unknown |
| [UniqueId](#uniqueid) (P*2-1) | Unknown |
| [UniqueId](#uniqueid) (Q) | Unknown |
| Uint8 | Unknown |
| Uint8 (P) | Player id table |
| Type | Description |
|-------------------------------|--------------------------------------------------------|
| Uint64 | Connected AID bitmap |
| Uint64 | Disconnected AID bitmap |
| Uint64 | CPU AID bitmap |
| Uint64 | Received AID bitmap |
| Uint64 | [Session time](/docs/pia/protocols/sync-clock) at join |
| Uint64 | Principal id |
| Uint8 | Is player id table initialized |
| [UniqueId](#uniqueid) (P*2-1) | Player unique ids |
| [UniqueId](#uniqueid) (Q) | CPU unique ids |
| Uint8 | Player id sync unique |
| Uint8 (P) | Player id table |

### UniqueId
*Wii U:*

| Offset | Size | Description |
|--------|------|--------------------|
| 0x0 | 4 | Station id |
| 0x0 | 4 | [[Constant id]] |
| 0x4 | 2 | Unknown |
| 0x6 | 2 | Padding (always 0) |

*Switch:*

| Offset | Size | Description |
|--------|------|--------------------|
| 0x0 | 8 | Station id |
| 0x0 | 8 | [[Constant id]] |
| 0x8 | 2 | Unknown |
| 0xA | 6 | Padding (always 0) |

[Constant id]: /docs/pia/types#constant-id
13 changes: 7 additions & 6 deletions docs/pia/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ All peer-to-peer packets are sent through UDP. The packet format is described [h

* [Unreliable Protocol](/docs/pia/protocols/unreliable)
* [Reliable Protocol](/docs/pia/protocols/reliable)
* Stream Broadcast Reliable Protocol
* [Broadcast Reliable Protocol](/docs/pia/protocols/broadcast-reliable)
* [Stream Broadcast Reliable Protocol](/docs/pia/protocols/stream-broadcast-reliable)
* [Clone Protocol](/docs/pia/protocols/clone)
* Sync Protocol

### Session management
A group of connected consoles is called a mesh. Every mesh has a single "host" that controls the mesh. Initially, the console that created the mesh is the host. Once the host leaves the mesh, a new host is selected through "host migration". The host performs important tasks such as processing join requests by newcomers. The host may also perform some game-specific tasks. For example, in Mario Kart 8, the host decides which track is chosen by the track roulette.
A group of connected consoles is called a mesh. Every mesh has a single "host" that controls the mesh. Initially, the console that created the mesh is the host. Once the host leaves the mesh, a new host is selected through "host migration". The host performs important tasks such as processing join requests by newcomers.

### Joining a mesh
The following steps are performed to join a mesh:
Expand All @@ -48,12 +49,12 @@ The following steps are performed to join a mesh:
2. Your console [establishes a connection](#connection-establishment) to the host of the mesh.
3. Your console sends a [join request](/docs/pia/protocols/mesh) to the host.
4. The host decides if it wants to accept the join request. For example, if the mesh already has the maximum number of participants it may reject the join request.
5. The host sends a [join response](/docs/pia/protocols/mesh) to your console to inform it about its decision. If the join request was accepted, the join response also contains the addresses of the other consoles in the mesh.
6. If the join request was accepted, your console establishes a connection to the other consoles in the mesh.
7. Finally, your console starts sending/receiving data packets to/from the other consoles.
5. The host sends a [join response](/docs/pia/protocols/mesh) to your console to inform it about its decision. If the join request was accepted, the join response also information about the other consoles in the mesh.
6. If the join request was accepted, the host sends an [update message](/docs/pia/protocols/mesh) to all consoles in the mesh. The other consoles now try to establish a connection with your console.
7. Your console is now part of the mesh and can start exchanging game-specific packets.

### Connection establishment
After acquiring the [StationLocation](/docs/pia/types#stationlocation) of another console elsewhere (e.g. from [matchmaking](#matchmaking) or the [join response](#joining-a-mesh)), the following steps are performed to establish a connection with the console:
After acquiring the [StationLocation](/docs/pia/types#stationlocation) of another console elsewhere (e.g. from [matchmaking](#matchmaking) or a [mesh update](/docs/pia/protocols/mesh)), the following steps are performed to establish a connection with the console:

1. If necessary, [NAT traversal](#nat-traversal) is performed.
2. Your console sends a [connection request](/docs/pia/protocols/station#connection-request) to the other console.
Expand Down
48 changes: 25 additions & 23 deletions docs/pia/lan.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Every packet starts with a single byte that indicates its type.

## Packet types

| Value | Description |
| ----- | --------------------------------------------- |
| 0 | [Browse request](#0-browse-request) |
| 1 | [Browse reply](#1-browse-reply) |
| 3 | [Get host request](#3-get-host-request) |
| 4 | [Get host reply](#4-get-host-reply) |
| 5 | [Get session request](#5-get-session-request) |
| 6 | [Get session reply](#6-get-session-reply) |
| 7 | [Keep alive message](#7-keep-alive-message) |
| Value | Description |
|-------|---------------------------------------------|
| 0 | [Browse request](#0-browse-request) |
| 1 | [Browse reply](#1-browse-reply) |
| 3 | [Host request](#3-host-request) |
| 4 | [Host message](#4-host-message) |
| 5 | [Session request](#5-session-request) |
| 6 | [Session message](#6-session-message) |
| 7 | [Keep alive message](#7-keep-alive-message) |

### (0) Browse Request
*Up to 5.44:*
Expand Down Expand Up @@ -313,7 +313,7 @@ If the application data consumes less than 0x184 bytes, this is reflected in the
| 8 | 5.19 - 5.44 |
| 10 | 6.16 - 6.30 |

### (3) Get Host Request
### (3) Host Request
This packet is sent through UDP broadcast ports 49152 - 49155 and is encapsulated in a [Pia message](/docs/pia/protocol). The message payload contains the following data and is encrypted with the session key:

*Up to 5.44:*
Expand All @@ -324,7 +324,7 @@ This packet is sent through UDP broadcast ports 49152 - 49155 and is encapsulate
| 0x1 | 11 | Padding (always 0) |
| 0xC | 4 | Session id |

### (4) Get Host Reply
### (4) Host Message
This message is encapsulated in a [Pia message](/docs/pia/protocol) and is encrypted with the session key.

*Up to 5.9:*
Expand All @@ -345,7 +345,7 @@ This message is encapsulated in a [Pia message](/docs/pia/protocol) and is encry
| 0xC | 4 | Session id |
| 0x10 | | [StationLocation](/docs/pia/types#stationlocation) for host |

### (5) Get Session Request
### (5) Session Request
This packet is sent through UDP broadcast ports 49152 - 49155 and is encapsulated in a [Pia message](/docs/pia/protocol). The message payload contains the following data and is encrypted with the session key:

*Up to 5.44:*
Expand All @@ -356,21 +356,23 @@ This packet is sent through UDP broadcast ports 49152 - 49155 and is encapsulate
| 0x1 | 11 | Padding (always 0) |
| 0xC | 4 | Session id |

### (6) Get Session Reply
### (6) Session Message
This message is encapsulated in a [Pia message](/docs/pia/protocol) and is encrypted with the session key. The goal of this message is to transmit a [LanSessionInfo](#lansessioninfo) structure. Depending on the size of the [LanSessionInfo](#lansessioninfo), this message may be split into multiple fragments. Each fragment contains up to 800 bytes of data.

Whenever the session is updated, a session message is sent through UDP broadcast port 49152 - 49155. A session message is also sent to a specific station when the station requests an update with a [session request](#5-session-request).

*Up to 5.44:*

| Offset | Size | Description |
| ------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 0x0 | 1 | Message type (6) |
| 0x1 | 11 | Padding (always 0) |
| 0xC | 4 | This is a random value that must be the same in all fragments that belong to the same session reply. This is used to distinguish different session replies. |
| 0x10 | 2 | Session reply id. This is an incrementing number that should be the same in all fragments that belong to the same session reply. |
| 0x12 | 1 | Fragment index |
| 0x13 | 1 | Number of fragments |
| 0x14 | 4 | Fragment size |
| 0x18 | | Fragment data |
| Offset | Size | Description |
|--------|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 0x0 | 1 | Message type (6) |
| 0x1 | 11 | Padding (always 0) |
| 0xC | 4 | This is a random value that must be the same in all fragments that belong to the same session message. This is used to distinguish different session replies. |
| 0x10 | 2 | Session message id. This is an incrementing number that should be the same in all fragments that belong to the same session message. |
| 0x12 | 1 | Fragment index |
| 0x13 | 1 | Number of fragments |
| 0x14 | 4 | Fragment size |
| 0x18 | | Fragment data |

### (7) Keep Alive Message
This packet is sent through UDP broadcast port 49152 and is encapsulated in a [Pia message](/docs/pia/protocol). This message is sent once every two seconds, even if the console is not participating in a session. If the console is participating in a session, the message payload is encrypted with the session key. Otherwise, the payload is not encrypted. The message payload contains the following data:
Expand Down
Loading

0 comments on commit b089b3c

Please sign in to comment.