HTTP Protocol

From Genshin Impact Technical Wiki
Jump to navigation Jump to search

This page documents the HTTP protocol of Genshin Impact (CN: 原神, known internally as HK4E).

Genshin Impact uses this protocol when communicating with authentication/dispatch servers on the Celestia screen, prior to connecting to a game server. After to connecting to one, the Game Protocol is used instead, with the exception of telemetery/logging endpoints, which continue to be used. See Login Sequence for more information on the authentication/dispatch system and how the protocol is used.

Protocol Details

Genshin Impact communicates with HTTP servers using simple GET/POST requests. Like the Game Protocol, the HTTP protocol makes use of Protobuf, encoding packets in base 64.

All requests are made using the user agent UnityPlayer/2017.4.30f1 (UnityWebRequest/1.0, libcurl/7.51.0-DEV) (as of Version 4.8.0). Requests include the Unity version: 2017.4.30f1, within the header X-Unity-Version.

Endpoints

Dispatch

Endpoints in this section are used to query regions and their information in order to dispatch the client to a game server.

/query_region_list

This endpoint, hosted on dispatchosglobal.yuanshen.com for overseas clients, and dispatchcnglobal.yuanshen.com for CN clients, provides the client with a list of regions and their dispatch servers

Request

The client accesses this endpoint via a GET request. The client passes along information about the request as query parameters in the request URL.

Parameter Notes
version The version of the client, including the channel, as shown on the Celestia screen, i.e. OSRELWin4.8.0
lang The language of the client. A value of 1 is used for English. TODO: A full list of possible values
platform The platform of the client.
Platform Value
Editor/Unknown 0
iOS 1
Android 2
PC 3
PS4 4
Server 5
Cloud Android 6
Cloud iOS 7
PS5 8
Cloud Web 9
Cloud TV 10
Cloud Mac 11
Cloud PC 12
Cloud 3rd Party Mobile 13
Cloud 3rd Party PC 14
binary TODO: research
time TODO: research
channel_id TODO: research
sub_channel TODO: research
Response

The dispatch server responds with a QueryRegionListHttpRsp Protobuf packet, base 64 encoded as a string.

QueryRegionListHttpRsp
Field Name Field Type
retcode int32
region_list Array<RegionSimpleInfo>
client_secret_key byte[]
client_custom_config_encrypted byte[]
enable_login_pc bool
RegionSimpleInfo
Field Name Field Type Notes
name string The internal name of the region, i.e. os_usa
title string The display name of the region, i.e. America
type string Seems to always be DEV_PUBLIC. TODO: More research is needed.
dispatch_url string The URL of this region's dispatch server

Logging

Endpoints in this section are used for debugging, analysis, and telemetry. Unlike the rest of the HTTP protocol, these endpoints continue to be used alongside the Game Protocol when the client has connected to a game server.

/sdk/dataUpload

This endpoint, hosted on ys-log-upload-os.hoyoverse.com for overseas clients (or ys-log-upload.mihoyo.com for CN clients), is used by the client to upload routine logs on client events to the server for analysis. There is no official way to opt out of this data collection.

Request

The client writes to this endpoint via a POST request. The client POSTs a large JSON including, but not limited to:

  • Game channel (either hk4e_global or hk4e_cn)
  • Unique device identifier
  • Device name and model
  • Monitor width and height
  • GPU make and model
  • GPU memory
  • Processor make and model
  • Processor count
  • Processor frequency
  • Total memory
  • Memory in use
  • Total disk space
  • Disk space in use
  • Operating system information
  • MAC address
Response

The server responds to the client in JSON, informing it that the request was successful.

{
    "code": 0,
    "message": "OK"
}

/log

This endpoint is used by the client to upload error logs to the server for analysis and debugging purposes. (TODO: find domains, I can only get the client to request this on a local server)

Request

The client writes to this endpoint via a POST request. The client POSTs a large JSON, including:

  • Basic device information
    • Processor make and model
    • Device name and model
    • GPU model
    • Operation system version
  • Information on the error
    • The error message, as a string
    • The category of the error
    • The code of the error
    • The level of the error. Observed levels are "Low", "Medium", and "High".
    • A stack trace leading up to the error
  • Game information
    • Full version string
    • Account name
    • Global Account UID
    • Region-specific UID
    • Region internal name (i.e. os_usa)

For unknown reasons, the client appears to post the log three times to this endpoint, and three times to the duplicate endpoint /crash/dataUpload, which seems to be used in the exact same way and as such is not discussed separately.

The client seems to keep track of errors it has reported to the server, and will avoid sending duplicate error logs.

Response

The server responds to the client in JSON, informing it that the request was successful.

{
    "code": 0,
    "message": "OK"
}