Game Protocol

From Genshin Impact Technical Wiki
Jump to navigation Jump to search

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

Genshin Impact uses this protocol when communicating with game servers. Prior to connecting to one, the HTTP Protocol is used instead.

Due to obfuscation efforts by Genshin Impact's developer, miHoYo, research is tedious, and some information may be missing or outdated. This page avoids using version specific data such as packet IDs, and makes an effort to be general and flexible across versions.

Protocol Details

The Genshin Impact game protocol uses Protobuf, communicating via a modified version of KCP, a protocol built upon UDP. Packet IDs are chosen randomly, and are scrambled every patch to make analysis more difficult. As of version 4.0.0, there are 2558 different packets in Genshin Impact, not all of which have been reverse engineered.

KCP

Genshin Impact uses a modified version of KCP for protocol transmission, with the following changes:

  • The KCP overhead has been increased to 32 bytes
  • The XXH3 hash of the data segment is included as a uint32 after the KCP segment length

Packet Format

Field Name Field Size Notes
Magic Header 2 bytes Always equal to 0x4567 (17767)
Packet ID 2 bytes The ID of the packet. Packet IDs differ between versions
Header Length 2 bytes The length of the packet's header, in bytes
Data Length 4 bytes The length of the packet's data, in bytes
Header header length The packet's header
Data data length The packet's data (payload)
Magic Footer 2 bytes Always equal to 0x89AB (-30293)