3.5 KiB
Dispatch & SDK patch
Rewrites client URLs to a chosen HTTP or HTTPS server. The server is a host or IP with an optional port, without scheme or path.
URL rules (dispatch/mod.rs)
dispatchreplaces the"DispatchUrls": [...]list with"<origin>/query_dispatch"entries inside its original byte range, space-padding the rest.sdkrewrites the URLs of the productionbh3_*records inserver_pc(env0forbh3_cn, else2), padding each record to its original length.android_urlsrewriteshttp(s)/ws(s)URLs and bare hosts on the official domains (bh3.com,honkaiimpact3.com,mihoyo.com,hoyoverse.com, plus one known IP). Shorter replacements keep the original length with anx…@userinfo prefix;ws/wssfollow the chosen scheme.
If a replacement is longer than the original, dispatch_grow, sdk_grow
or android_urls_grow writes it at full length and the asset is
enlarged: unity::replace_script rewrites the serialized object table and
header size, and Bundle::replace_node re-chunks a UnityFS node and
fixes its directory. The tool then prints a warning that assets were
enlarged.
Windows (dispatch/windows.rs)
Writes three files together and rolls back on failure:
| File | Content patched |
|---|---|
BH3_Data/sharedassets0.assets |
ChannelConfig dispatch URLs; also identifies the region |
BH3_Data/resources.assets |
server_pc SDK URLs |
BH3_Data/StreamingAssets/MiHoYoSDKRes/PC/mihoyo_sdk_res |
the server_pc copy inside the SDK bundle |
Both server_pc copies must be byte-equal before patching.
Android (dispatch/android.rs)
Patches serialized files, UnityFS bundle nodes and plain text among the
candidate assets/ entries (assets/bin/data/* and known text
extensions, except package_config.json, share_config.json, .wmv
and .bak). .splitN parts are joined for patching and re-split at the
original chunk size; enlarging can add parts. DEX, native libraries and
.wmv are copied unchanged, except for the CN passport URL below. At
least one ChannelConfig and one SDK/resource URL are required, otherwise
no APK is written. The result is repacked and signed by android::sign.
CN passport URL (dispatch/cn_android.rs)
The CN passport login URL is a plaintext string in the DEX that declares
…account.sdk.utils.RSAUtils; only that DEX is edited. The server must
use HTTP — HTTPS is rejected.
The patch inserts the origin as a new string at its sorted position in
string_ids (format::dex::insert_string) and repoints the
const-string that loaded the official login URL
(https://passport-api.mihoyo.com) to it, so login goes to the server.
Any origin is accepted, not only ones that sort next to a reusable slot.
Insertion shifts every string index at or after the new one, so
insert_string renumbers all references — the fixed-width id tables,
const-string/const-string/jumbo operands, and the ULEB128 string
indices in debug info and annotations — and relocates every file offset
(itself and the string data grow 4-aligned). A DEX with more than 65536
strings can hold a 16-bit const-string whose operand would overflow
when renumbered; format::dex::promote rewrites those to
const-string/jumbo first, rebuilding the affected method (branch and
switch targets fixed, the code item re-padded to 4-byte alignment). If
the origin is already present (for example the stock http://127.0.0.1
when the server runs on the device), the login is repointed to the
existing id with no insertion. Checksums are recomputed.