From 1d5971b2d5183d2563eedd3ab2eaa4937f03712d Mon Sep 17 00:00:00 2001 From: Tau Date: Wed, 3 Apr 2019 14:49:34 -0400 Subject: [PATCH] wip crack decoder --- src/idz/decoder.ts | 264 ------------------ src/idz/decoder/accountLock.ts | 14 + src/idz/decoder/accountUnlock.ts | 13 + src/idz/decoder/createProfile.ts | 40 +++ src/idz/decoder/createTeam.ts | 14 + src/idz/decoder/discoverProfile.ts | 12 + src/idz/decoder/index.ts | 144 ++++++++++ src/idz/decoder/load2on2.ts | 14 + src/idz/decoder/loadConfig.ts | 9 + src/idz/decoder/loadConfig2.ts | 9 + src/idz/decoder/loadGeneralReward.ts | 12 + src/idz/decoder/loadProfile.ts | 13 + src/idz/decoder/loadRewardTable.ts | 11 + src/idz/decoder/loadServerList.ts | 9 + src/idz/decoder/loadStocker.ts | 12 + src/idz/decoder/loadTeam.ts | 13 + src/idz/decoder/saveExpedition.ts | 12 + src/idz/decoder/saveProfile.ts | 12 + src/idz/decoder/saveSettings.ts | 19 ++ src/idz/decoder/saveTopic.ts | 14 + src/idz/decoder/updateProvisionalStoreRank.ts | 14 + src/idz/decoder/updateStoryClearNum.ts | 11 + src/idz/defs.ts | 86 +++--- 23 files changed, 464 insertions(+), 307 deletions(-) delete mode 100644 src/idz/decoder.ts create mode 100644 src/idz/decoder/accountLock.ts create mode 100644 src/idz/decoder/accountUnlock.ts create mode 100644 src/idz/decoder/createProfile.ts create mode 100644 src/idz/decoder/createTeam.ts create mode 100644 src/idz/decoder/discoverProfile.ts create mode 100644 src/idz/decoder/index.ts create mode 100644 src/idz/decoder/load2on2.ts create mode 100644 src/idz/decoder/loadConfig.ts create mode 100644 src/idz/decoder/loadConfig2.ts create mode 100644 src/idz/decoder/loadGeneralReward.ts create mode 100644 src/idz/decoder/loadProfile.ts create mode 100644 src/idz/decoder/loadRewardTable.ts create mode 100644 src/idz/decoder/loadServerList.ts create mode 100644 src/idz/decoder/loadStocker.ts create mode 100644 src/idz/decoder/loadTeam.ts create mode 100644 src/idz/decoder/saveExpedition.ts create mode 100644 src/idz/decoder/saveProfile.ts create mode 100644 src/idz/decoder/saveSettings.ts create mode 100644 src/idz/decoder/saveTopic.ts create mode 100644 src/idz/decoder/updateProvisionalStoreRank.ts create mode 100644 src/idz/decoder/updateStoryClearNum.ts diff --git a/src/idz/decoder.ts b/src/idz/decoder.ts deleted file mode 100644 index 2ac486b..0000000 --- a/src/idz/decoder.ts +++ /dev/null @@ -1,264 +0,0 @@ -import iconv = require("iconv-lite"); -import { Transform } from "stream"; - -import { MSG, RequestId, getRequestLength } from "./defs"; -import { Request } from "./request"; - -type ReaderFn = (buf: Buffer) => Request; - -const sjis = "shift_jis"; -const readers = new Map(); - -function readHeader(buf: Buffer) { - return { - blah: "blah", - }; -} - -readers.set(MSG.ACCOUNT_LOCK_REQ, buf => { - return { - type: "account_lock_req", - aimeId: buf.readUInt32LE(0x0004), - pcbId: buf.slice(0x0008, buf.indexOf("\0", 0x0008)).toString("ascii"), - field_0018: buf.readUInt16LE(0x0018), - }; -}); - -readers.set(MSG.ACCOUNT_UNLOCK_REQ, buf => { - return { - type: "account_unlock_req", - aimeId: buf.readUInt32LE(0x0004), - pcbId: buf.slice(0x0008, buf.indexOf("\0", 0x0008)).toString("ascii"), - }; -}); - -readers.set(MSG.CREATE_PROFILE_REQ, buf => { - return { - type: "create_profile_req", - aimeId: buf.readInt32LE(0x0004), - luid: buf.slice(0x0008, buf.indexOf("\0", 0x0008)).toString("ascii"), - name: iconv.decode(buf.slice(0x001e, buf.indexOf("\0", 0x001e)), sjis), - field_0034: buf.readUInt32LE(0x0034), - field_0040: buf.slice(0x0040, 0x0084), - car_type: buf.readUInt16LE(0x0084), - car_color: buf.readUInt16LE(0x0086), - transmission: buf.readUInt16LE(0x0088) === 0 ? "auto" : "manual", - field_008A: buf.readUInt16LE(0x008a), - field_008C: buf.readUInt16LE(0x008c), - field_0090: - BigInt(buf.readUInt32LE(0x0090)) | - (BigInt(buf.readUInt32LE(0x0094)) << 32n), - field_009C: buf.readUInt16LE(0x009c), - gender: buf.readUInt16LE(0x00a0) === 0 ? "male" : "female", - field_00A2: buf.readUInt16LE(0x00a2), - field_00A4: buf.readUInt16LE(0x00a4), - field_00A6: buf.readUInt16LE(0x00a6), - field_00A8: buf.readUInt16LE(0x00a8), - field_00AA: buf.readUInt16LE(0x00aa), - field_00AC: buf.readUInt16LE(0x00ac), - field_00AE: buf.readUInt16LE(0x00ae), - field_00B0: buf.readUInt16LE(0x00b0), - field_00B2: buf.readUInt8(0x00b2), - }; -}); - -readers.set(MSG.CREATE_TEAM_REQ, buf => { - return { - type: "create_team_req", - field_0004: buf.readUInt32LE(0x0004), - field_0008: buf.readUInt32LE(0x0008), - field_000C: buf.readUInt8(0x000c), - }; -}); - -readers.set(MSG.LOAD_2ON2_REQ, buf => { - return { - type: "load_2on2_req", - field_0002: buf.readUInt16LE(0x0002), - field_0004: buf.readUInt32LE(0x0004), - field_0008: buf.readUInt32LE(0x0008), - }; -}); - -readers.set(MSG.LOAD_CONFIG_REQ, () => { - return { type: "load_config_req" }; -}); - -readers.set(MSG.LOAD_CONFIG_V2_REQ, () => { - return { type: "load_config_v2_req" }; -}); - -readers.set(MSG.DISCOVER_PROFILE_REQ, buf => { - return { - type: "discover_profile_req", - aimeId: buf.readUInt32LE(0x0004), - }; -}); - -readers.set(MSG.LOAD_GENERAL_REWARD_REQ, buf => { - return { - type: "load_general_reward_req", - field_0004: buf.readUInt32LE(0x0004), - }; -}); - -readers.set(MSG.LOAD_PROFILE_REQ, buf => { - return { - type: "load_profile_req", - aimeId: buf.readUInt32LE(0x0004), - pcbId: buf.slice(0x0008, buf.indexOf("\0", 0x0008)).toString("ascii"), - }; -}); - -readers.set(MSG.LOAD_STOCKER_REQ, buf => { - return { - type: "load_stocker_req", - field_0004: buf.readUInt32LE(0x0004), - }; -}); - -readers.set(MSG.LOAD_REWARD_TABLE_REQ, () => { - return { - type: "load_reward_table_req", - }; -}); - -readers.set(MSG.LOAD_SERVER_LIST_REQ, () => { - return { type: "load_server_list_req" }; -}); - -readers.set(MSG.LOAD_TEAM_REQ, buf => { - return { - type: "load_team_req", - profileId: buf.readUInt32LE(0x0004), - teamId: buf.readUInt32LE(0x0008), - }; -}); - -readers.set(MSG.SAVE_EXPEDITION_REQ, buf => { - return { - type: "save_expedition_req", - field_0004: buf.readUInt32LE(0x0004), - }; -}); - -readers.set(MSG.UPDATE_PROVISIONAL_STORE_RANK_REQ, buf => { - return { - type: "update_provisional_store_rank_req", - aimeId: buf.readUInt32LE(0x0004), - }; -}); - -readers.set(MSG.SAVE_RECORD_REQ, buf => { - return { - type: "save_profile_req", - // mega TODO - }; -}); - -readers.set(MSG.SAVE_SETTINGS_REQ, buf => { - return { - type: "save_settings_req", - field_0002: buf.readUInt16LE(0x0002), - profileId: buf.readUInt32LE(0x0004), - dpoint: buf.readUInt32LE(0x0008), - field_000C: buf.readUInt32LE(0x000c), - field_0010: buf.readUInt8(0x0010), - field_0011: buf.readUInt8(0x0011), - field_0012: buf.readUInt8(0x0012), - field_0013: buf.readUInt8(0x0013), - }; -}); - -readers.set(MSG.UPDATE_STORY_CLEAR_NUM_REQ, () => { - return { - type: "update_story_clear_num_req", - }; -}); - -readers.set(MSG.SAVE_TOPIC_REQ, buf => { - const aimeId = buf.readUInt32LE(0x0004); - - return { - type: "save_topic_req", - aimeId: aimeId !== 0xffffffff ? aimeId : undefined, - }; -}); - -export class Decoder extends Transform { - state: Buffer; - - constructor() { - super({ - readableObjectMode: true, - writableObjectMode: true, - }); - - this.state = Buffer.alloc(0); - } - - _transform(chunk: Buffer, encoding, callback) { - this.state = Buffer.concat([this.state, chunk]); - - // Read header - - if (this.state.length < 0x04) { - return callback(null); - } - - const magic = this.state.readUInt32LE(0); - - if (magic !== 0x01020304) { - return callback( - new Error( - "Invalid magic number, cryptographic processing probably incorrect." - ) - ); - } - - if (this.state.length < 0x30) { - return callback(null); - } - - const header = readHeader(this.state); - - if (this.state.length < 0x32) { - return callback(null); - } - - const msgCode = this.state.readUInt16LE(0x30) as RequestId; - const msgLen = getRequestLength(msgCode); - - if (msgLen === undefined) { - return callback( - new Error( - `Unknown command code ${msgCode.toString(16)}, cannot continue` - ) - ); - } - - if (this.state.length < 0x30 + msgLen) { - return callback(null); - } - - const reqBuf = this.state.slice(0, 0x30 + msgLen); - const payloadBuf = reqBuf.slice(0x30); - - console.log("Idz: Req: Raw:", reqBuf.toString("hex")); - console.log("Idz: Req: Header:", header); - - const reader = readers.get(msgCode); - - if (reader === undefined) { - return callback( - new Error(`No reader for command code ${msgCode.toString(16)}`) - ); - } - - const payload = reader(payloadBuf); - - console.log("Idz: Req: Payload:", payload); - - return callback(null, payload); - } -} diff --git a/src/idz/decoder/accountLock.ts b/src/idz/decoder/accountLock.ts new file mode 100644 index 0000000..0f0e0f8 --- /dev/null +++ b/src/idz/decoder/accountLock.ts @@ -0,0 +1,14 @@ +import { RequestCode } from "../defs"; +import { AccountLockRequest } from "../request/accountLock"; + +accountLock.msgCode = 0x0069 as RequestCode; +accountLock.msgLen = 0x0020; + +export function accountLock(buf: Buffer): AccountLockRequest { + return { + type: "account_lock_req", + aimeId: buf.readUInt32LE(0x0004), + pcbId: buf.slice(0x0008, buf.indexOf("\0", 0x0008)).toString("ascii"), + field_0018: buf.readUInt16LE(0x0018), + }; +} diff --git a/src/idz/decoder/accountUnlock.ts b/src/idz/decoder/accountUnlock.ts new file mode 100644 index 0000000..e20b9ec --- /dev/null +++ b/src/idz/decoder/accountUnlock.ts @@ -0,0 +1,13 @@ +import { RequestCode } from "../defs"; +import { AccountUnlockRequest } from "../request/accountUnlock"; + +accountUnlock.msgCode = 0x006f as RequestCode; +accountUnlock.msgLen = 0x0020; + +export function accountUnlock(buf: Buffer): AccountUnlockRequest { + return { + type: "account_unlock_req", + aimeId: buf.readUInt32LE(0x0004), + pcbId: buf.slice(0x0008, buf.indexOf("\0", 0x0008)).toString("ascii"), + }; +} diff --git a/src/idz/decoder/createProfile.ts b/src/idz/decoder/createProfile.ts new file mode 100644 index 0000000..91e8ccd --- /dev/null +++ b/src/idz/decoder/createProfile.ts @@ -0,0 +1,40 @@ +import iconv = require("iconv-lite"); + +import { RequestCode } from "../defs"; +import { CreateProfileRequest } from "../request/createProfile"; + +createProfile.msgCode = 0x0066 as RequestCode; +createProfile.msgLen = 0x00c0; + +export function createProfile(buf: Buffer): CreateProfileRequest { + return { + type: "create_profile_req", + aimeId: buf.readInt32LE(0x0004), + luid: buf.slice(0x0008, buf.indexOf("\0", 0x0008)).toString("ascii"), + name: iconv.decode( + buf.slice(0x001e, buf.indexOf("\0", 0x001e)), + "shift_jis" + ), + field_0034: buf.readUInt32LE(0x0034), + field_0040: buf.slice(0x0040, 0x0084), + car_type: buf.readUInt16LE(0x0084), + car_color: buf.readUInt16LE(0x0086), + transmission: buf.readUInt16LE(0x0088) === 0 ? "auto" : "manual", + field_008A: buf.readUInt16LE(0x008a), + field_008C: buf.readUInt16LE(0x008c), + field_0090: + BigInt(buf.readUInt32LE(0x0090)) | + (BigInt(buf.readUInt32LE(0x0094)) << 32n), + field_009C: buf.readUInt16LE(0x009c), + gender: buf.readUInt16LE(0x00a0) === 0 ? "male" : "female", + field_00A2: buf.readUInt16LE(0x00a2), + field_00A4: buf.readUInt16LE(0x00a4), + field_00A6: buf.readUInt16LE(0x00a6), + field_00A8: buf.readUInt16LE(0x00a8), + field_00AA: buf.readUInt16LE(0x00aa), + field_00AC: buf.readUInt16LE(0x00ac), + field_00AE: buf.readUInt16LE(0x00ae), + field_00B0: buf.readUInt16LE(0x00b0), + field_00B2: buf.readUInt8(0x00b2), + }; +} diff --git a/src/idz/decoder/createTeam.ts b/src/idz/decoder/createTeam.ts new file mode 100644 index 0000000..9b1d240 --- /dev/null +++ b/src/idz/decoder/createTeam.ts @@ -0,0 +1,14 @@ +import { RequestCode } from "../defs"; +import { CreateTeamRequest } from "../request/createTeam"; + +createTeam.msgCode = 0x007b as RequestCode; +createTeam.msgLen = 0x0010; + +export function createTeam(buf: Buffer): CreateTeamRequest { + return { + type: "create_team_req", + field_0004: buf.readUInt32LE(0x0004), + field_0008: buf.readUInt32LE(0x0008), + field_000C: buf.readUInt8(0x000c), + }; +} diff --git a/src/idz/decoder/discoverProfile.ts b/src/idz/decoder/discoverProfile.ts new file mode 100644 index 0000000..7fb1f2f --- /dev/null +++ b/src/idz/decoder/discoverProfile.ts @@ -0,0 +1,12 @@ +import { RequestCode } from "../defs"; +import { DiscoverProfileRequest } from "../request/discoverProfile"; + +discoverProfile.msgCode = 0x006b as RequestCode; +discoverProfile.msgLen = 0x0010; + +export function discoverProfile(buf: Buffer): DiscoverProfileRequest { + return { + type: "discover_profile_req", + aimeId: buf.readUInt32LE(0x0004), + }; +} diff --git a/src/idz/decoder/index.ts b/src/idz/decoder/index.ts new file mode 100644 index 0000000..fde562a --- /dev/null +++ b/src/idz/decoder/index.ts @@ -0,0 +1,144 @@ +import { Transform } from "stream"; + +import { accountLock } from "./accountLock"; +import { accountUnlock } from "./accountUnlock"; +import { createProfile } from "./createProfile"; +import { createTeam } from "./createTeam"; +import { discoverProfile } from "./discoverProfile"; +import { load2on2 } from "./load2on2"; +import { loadConfig } from "./loadConfig"; +import { loadConfig2 } from "./loadConfig2"; +import { loadGeneralReward } from "./loadGeneralReward"; +import { loadProfile } from "./loadProfile"; +import { loadRewardTable } from "./loadRewardTable"; +import { loadServerList } from "./loadServerList"; +import { loadStocker } from "./loadStocker"; +import { loadTeam } from "./loadTeam"; +import { saveExpedition } from "./saveExpedition"; +import { saveProfile } from "./saveProfile"; +import { saveSettings } from "./saveSettings"; +import { saveTopic } from "./saveTopic"; +import { updateProvisionalStoreRank } from "./updateProvisionalStoreRank"; +import { updateStoryClearNum } from "./updateStoryClearNum"; +import { RequestCode } from "../defs"; +import { Request } from "../request"; + +export type ReaderFn = ((buf: Buffer) => Request) & { + msgCode: RequestCode; + msgLen: number; +}; + +const funcList: ReaderFn[] = [ + accountLock, + accountUnlock, + createProfile, + createTeam, + discoverProfile, + load2on2, + loadConfig, + loadConfig2, + loadGeneralReward, + loadProfile, + loadRewardTable, + loadServerList, + loadStocker, + loadTeam, + saveExpedition, + saveProfile, + saveSettings, + saveTopic, + updateProvisionalStoreRank, + updateStoryClearNum, +]; + +const readerFns = new Map(); +const msgLengths = new Map(); + +for (const fn of funcList) { + readerFns.set(fn.msgCode, fn); + msgLengths.set(fn.msgCode, fn.msgLen); +} + +function readHeader(buf: Buffer) { + return { + blah: "blah", + }; +} + +export class Decoder extends Transform { + state: Buffer; + + constructor() { + super({ + readableObjectMode: true, + writableObjectMode: true, + }); + + this.state = Buffer.alloc(0); + } + + _transform(chunk: Buffer, encoding, callback) { + this.state = Buffer.concat([this.state, chunk]); + + // Read header + + if (this.state.length < 0x04) { + return callback(null); + } + + const magic = this.state.readUInt32LE(0); + + if (magic !== 0x01020304) { + return callback( + new Error( + "Invalid magic number, cryptographic processing probably incorrect." + ) + ); + } + + if (this.state.length < 0x30) { + return callback(null); + } + + const header = readHeader(this.state); + + if (this.state.length < 0x32) { + return callback(null); + } + + const msgCode = this.state.readUInt16LE(0x30) as RequestCode; + const msgLen = msgLengths.get(msgCode); + + if (msgLen === undefined) { + return callback( + new Error( + `Unknown command code ${msgCode.toString(16)}, cannot continue` + ) + ); + } + + if (this.state.length < 0x30 + msgLen) { + return callback(null); + } + + const reqBuf = this.state.slice(0, 0x30 + msgLen); + const payloadBuf = reqBuf.slice(0x30); + + console.log("Idz: Req: Raw:", reqBuf.toString("hex")); + console.log("Idz: Req: Header:", header); + + const reader = readerFns.get(msgCode); + + if (reader === undefined) { + return callback( + new Error(`No reader for command code ${msgCode.toString(16)}`) + ); + } + + const payload = reader(payloadBuf); + + console.log("Idz: Req: Payload:", payload); + + return callback(null, payload); + } +} diff --git a/src/idz/decoder/load2on2.ts b/src/idz/decoder/load2on2.ts new file mode 100644 index 0000000..b79525f --- /dev/null +++ b/src/idz/decoder/load2on2.ts @@ -0,0 +1,14 @@ +import { RequestCode } from "../defs"; +import { Load2on2Request } from "../request/load2on2"; + +load2on2.msgCode = 0x00b0 as RequestCode; +load2on2.msgLen = 0x0010; + +export function load2on2(buf: Buffer): Load2on2Request { + return { + type: "load_2on2_req", + field_0002: buf.readUInt16LE(0x0002), + field_0004: buf.readUInt32LE(0x0004), + field_0008: buf.readUInt32LE(0x0008), + }; +} diff --git a/src/idz/decoder/loadConfig.ts b/src/idz/decoder/loadConfig.ts new file mode 100644 index 0000000..7f75d02 --- /dev/null +++ b/src/idz/decoder/loadConfig.ts @@ -0,0 +1,9 @@ +import { RequestCode } from "../defs"; +import { LoadConfigRequest } from "../request/loadConfig"; + +loadConfig.msgCode = 0x0004 as RequestCode; +loadConfig.msgLen = 0x0050; + +export function loadConfig(): LoadConfigRequest { + return { type: "load_config_req" }; +} diff --git a/src/idz/decoder/loadConfig2.ts b/src/idz/decoder/loadConfig2.ts new file mode 100644 index 0000000..8fe76fd --- /dev/null +++ b/src/idz/decoder/loadConfig2.ts @@ -0,0 +1,9 @@ +import { RequestCode } from "../defs"; +import { LoadConfigRequest2 } from "../request/loadConfig2"; + +loadConfig2.msgCode = 0x00ab as RequestCode; +loadConfig2.msgLen = 0x0010; + +export function loadConfig2(): LoadConfigRequest2 { + return { type: "load_config_v2_req" }; +} diff --git a/src/idz/decoder/loadGeneralReward.ts b/src/idz/decoder/loadGeneralReward.ts new file mode 100644 index 0000000..1f254a5 --- /dev/null +++ b/src/idz/decoder/loadGeneralReward.ts @@ -0,0 +1,12 @@ +import { RequestCode } from "../defs"; +import { LoadGeneralRewardRequest } from "../request/loadGeneralReward"; + +loadGeneralReward.msgCode = 0x009c as RequestCode; +loadGeneralReward.msgLen = 0x0010; + +export function loadGeneralReward(buf: Buffer): LoadGeneralRewardRequest { + return { + type: "load_general_reward_req", + field_0004: buf.readUInt32LE(0x0004), + }; +} diff --git a/src/idz/decoder/loadProfile.ts b/src/idz/decoder/loadProfile.ts new file mode 100644 index 0000000..b31b179 --- /dev/null +++ b/src/idz/decoder/loadProfile.ts @@ -0,0 +1,13 @@ +import { RequestCode } from "../defs"; +import { LoadProfileRequest } from "../request/loadProfile"; + +loadProfile.msgCode = 0x0067 as RequestCode; +loadProfile.msgLen = 0x0020; + +export function loadProfile(buf: Buffer): LoadProfileRequest { + return { + type: "load_profile_req", + aimeId: buf.readUInt32LE(0x0004), + pcbId: buf.slice(0x0008, buf.indexOf("\0", 0x0008)).toString("ascii"), + }; +} diff --git a/src/idz/decoder/loadRewardTable.ts b/src/idz/decoder/loadRewardTable.ts new file mode 100644 index 0000000..b0a5105 --- /dev/null +++ b/src/idz/decoder/loadRewardTable.ts @@ -0,0 +1,11 @@ +import { RequestCode } from "../defs"; +import { LoadRewardTableRequest } from "../request/loadRewardTable"; + +loadRewardTable.msgCode = 0x0086 as RequestCode; +loadRewardTable.msgLen = 0x0010; + +export function loadRewardTable(): LoadRewardTableRequest { + return { + type: "load_reward_table_req", + }; +} diff --git a/src/idz/decoder/loadServerList.ts b/src/idz/decoder/loadServerList.ts new file mode 100644 index 0000000..8aad6a5 --- /dev/null +++ b/src/idz/decoder/loadServerList.ts @@ -0,0 +1,9 @@ +import { RequestCode } from "../defs"; +import { LoadServerListRequest } from "../request/loadServerList"; + +loadServerList.msgCode = 0x0006 as RequestCode; +loadServerList.msgLen = 0x0020; + +export function loadServerList(): LoadServerListRequest { + return { type: "load_server_list_req" }; +} diff --git a/src/idz/decoder/loadStocker.ts b/src/idz/decoder/loadStocker.ts new file mode 100644 index 0000000..11c870a --- /dev/null +++ b/src/idz/decoder/loadStocker.ts @@ -0,0 +1,12 @@ +import { RequestCode } from "../defs"; +import { LoadStockerRequest } from "../request/loadStocker"; + +loadStocker.msgCode = 0x00a7 as RequestCode; +loadStocker.msgLen = 0x0010; + +export function loadStocker(buf: Buffer): LoadStockerRequest { + return { + type: "load_stocker_req", + field_0004: buf.readUInt32LE(0x0004), + }; +} diff --git a/src/idz/decoder/loadTeam.ts b/src/idz/decoder/loadTeam.ts new file mode 100644 index 0000000..852e435 --- /dev/null +++ b/src/idz/decoder/loadTeam.ts @@ -0,0 +1,13 @@ +import { RequestCode } from "../defs"; +import { LoadTeamRequest } from "../request/loadTeam"; + +loadTeam.msgCode = 0x0077 as RequestCode; +loadTeam.msgLen = 0x0010; + +export function loadTeam(buf: Buffer): LoadTeamRequest { + return { + type: "load_team_req", + profileId: buf.readUInt32LE(0x0004), + teamId: buf.readUInt32LE(0x0008), + }; +} diff --git a/src/idz/decoder/saveExpedition.ts b/src/idz/decoder/saveExpedition.ts new file mode 100644 index 0000000..1d2c920 --- /dev/null +++ b/src/idz/decoder/saveExpedition.ts @@ -0,0 +1,12 @@ +import { RequestCode } from "../defs"; +import { SaveExpeditionRequest } from "../request/saveExpedition"; + +saveExpedition.msgCode = 0x008c as RequestCode; +saveExpedition.msgLen = 0x0010; + +export function saveExpedition(buf: Buffer): SaveExpeditionRequest { + return { + type: "save_expedition_req", + field_0004: buf.readUInt32LE(0x0004), + }; +} diff --git a/src/idz/decoder/saveProfile.ts b/src/idz/decoder/saveProfile.ts new file mode 100644 index 0000000..75358c1 --- /dev/null +++ b/src/idz/decoder/saveProfile.ts @@ -0,0 +1,12 @@ +import { RequestCode } from "../defs"; +import { SaveProfileRequest } from "../request/saveProfile"; + +saveProfile.msgCode = 0x0068 as RequestCode; +saveProfile.msgLen = 0x0940; + +export function saveProfile(buf: Buffer): SaveProfileRequest { + return { + type: "save_profile_req", + // mega TODO + }; +} diff --git a/src/idz/decoder/saveSettings.ts b/src/idz/decoder/saveSettings.ts new file mode 100644 index 0000000..3162ef6 --- /dev/null +++ b/src/idz/decoder/saveSettings.ts @@ -0,0 +1,19 @@ +import { RequestCode } from "../defs"; +import { SaveSettingsRequest } from "../request/saveSettings"; + +saveSettings.msgCode = 0x00a5 as RequestCode; +saveSettings.msgLen = 0x0020; + +export function saveSettings(buf: Buffer): SaveSettingsRequest { + return { + type: "save_settings_req", + field_0002: buf.readUInt16LE(0x0002), + profileId: buf.readUInt32LE(0x0004), + dpoint: buf.readUInt32LE(0x0008), + field_000C: buf.readUInt32LE(0x000c), + field_0010: buf.readUInt8(0x0010), + field_0011: buf.readUInt8(0x0011), + field_0012: buf.readUInt8(0x0012), + field_0013: buf.readUInt8(0x0013), + }; +} diff --git a/src/idz/decoder/saveTopic.ts b/src/idz/decoder/saveTopic.ts new file mode 100644 index 0000000..b9aecde --- /dev/null +++ b/src/idz/decoder/saveTopic.ts @@ -0,0 +1,14 @@ +import { RequestCode } from "../defs"; +import { SaveTopicRequest } from "../request/saveTopic"; + +saveTopic.msgCode = 0x009a as RequestCode; +saveTopic.msgLen = 0x0010; + +export function saveTopic(buf: Buffer): SaveTopicRequest { + const aimeId = buf.readUInt32LE(0x0004); + + return { + type: "save_topic_req", + aimeId: aimeId !== 0xffffffff ? aimeId : undefined, + }; +} diff --git a/src/idz/decoder/updateProvisionalStoreRank.ts b/src/idz/decoder/updateProvisionalStoreRank.ts new file mode 100644 index 0000000..b19ab22 --- /dev/null +++ b/src/idz/decoder/updateProvisionalStoreRank.ts @@ -0,0 +1,14 @@ +import { RequestCode } from "../defs"; +import { UpdateProvisionalStoreRankRequest } from "../request/updateProvisionalStoreRank"; + +updateProvisionalStoreRank.msgCode = 0x0082 as RequestCode; +updateProvisionalStoreRank.msgLen = 0x0010; + +export function updateProvisionalStoreRank( + buf: Buffer +): UpdateProvisionalStoreRankRequest { + return { + type: "update_provisional_store_rank_req", + aimeId: buf.readUInt32LE(0x0004), + }; +} diff --git a/src/idz/decoder/updateStoryClearNum.ts b/src/idz/decoder/updateStoryClearNum.ts new file mode 100644 index 0000000..96ff66d --- /dev/null +++ b/src/idz/decoder/updateStoryClearNum.ts @@ -0,0 +1,11 @@ +import { RequestCode } from "../defs"; +import { UpdateStoryClearNumRequest } from "../request/updateStoryClearNum"; + +updateStoryClearNum.msgCode = 0x007f as RequestCode; +updateStoryClearNum.msgLen = 0x0010; + +export function updateStoryClearNum(buf: Buffer): UpdateStoryClearNumRequest { + return { + type: "update_story_clear_num_req", + }; +} diff --git a/src/idz/defs.ts b/src/idz/defs.ts index 173c428..24b7641 100644 --- a/src/idz/defs.ts +++ b/src/idz/defs.ts @@ -2,53 +2,53 @@ // The double-underscore properties never actually exist at runtime, we just // pretend they do. -export type RequestId = number & { __requestId: null }; -export type ResponseId = number & { __responseId: null }; +export type RequestCode = number & { __requestId: null }; +export type ResponseCode = number & { __responseId: null }; const _MSG = { - GENERIC_RES: 0x0001 as ResponseId, - LOAD_CONFIG_REQ: 0x0004 as RequestId, - LOAD_CONFIG_RES: 0x0005 as ResponseId, - LOAD_SERVER_LIST_REQ: 0x0006 as RequestId, - LOAD_SERVER_LIST_RES: 0x0007 as ResponseId, - LOAD_PROFILE_V1_RES: 0x0064 as ResponseId, - LOAD_PROFILE_V2_RES: 0x0065 as ResponseId, - CREATE_PROFILE_REQ: 0x0066 as RequestId, - LOAD_PROFILE_REQ: 0x0067 as RequestId, - SAVE_RECORD_REQ: 0x0068 as RequestId, - ACCOUNT_LOCK_REQ: 0x0069 as RequestId, - ACCOUNT_LOCK_RES: 0x006a as ResponseId, - DISCOVER_PROFILE_REQ: 0x006b as RequestId, - DISCOVER_PROFILE_RES: 0x006c as ResponseId, - ACCOUNT_UNLOCK_REQ: 0x006f as RequestId, - ACCOUNT_UNLOCK_RES: 0x0070 as ResponseId, - LOAD_TEAM_REQ: 0x0077 as RequestId, - LOAD_TEAM_RES: 0x0078 as ResponseId, - CREATE_TEAM_REQ: 0x007b as RequestId, - CREATE_TEAM_RES: 0x007c as ResponseId, - UPDATE_STORY_CLEAR_NUM_REQ: 0x007f as RequestId, - UPDATE_STORY_CLEAR_NUM_RES: 0x0080 as ResponseId, - UPDATE_PROVISIONAL_STORE_RANK_REQ: 0x0082 as RequestId, - UPDATE_PROVISIONAL_STORE_RANK_RES: 0x0083 as ResponseId, - LOAD_REWARD_TABLE_REQ: 0x0086 as RequestId, - LOAD_REWARD_TABLE_RES: 0x0087 as ResponseId, - SAVE_EXPEDITION_REQ: 0x008c as RequestId, - SAVE_EXPEDITION_RES: 0x008d as ResponseId, - SAVE_TOPIC_REQ: 0x009a as RequestId, - SAVE_TOPIC_RES: 0x009b as ResponseId, - LOAD_GENERAL_REWARD_REQ: 0x009c as RequestId, - LOAD_GENERAL_REWARD_RES: 0x009d as ResponseId, - SAVE_SETTINGS_REQ: 0x00a5 as RequestId, - LOAD_CONFIG_V2_REQ: 0x00ab as RequestId, - LOAD_CONFIG_V2_RES: 0x00ac as ResponseId, - LOAD_STOCKER_REQ: 0x00a7 as RequestId, - LOAD_STOCKER_RES: 0x00a8 as ResponseId, - LOAD_2ON2_REQ: 0x00b0 as RequestId, - LOAD_2ON2_RES: 0x00b1 as ResponseId, + GENERIC_RES: 0x0001 as ResponseCode, + LOAD_CONFIG_REQ: 0x0004 as RequestCode, + LOAD_CONFIG_RES: 0x0005 as ResponseCode, + LOAD_SERVER_LIST_REQ: 0x0006 as RequestCode, + LOAD_SERVER_LIST_RES: 0x0007 as ResponseCode, + LOAD_PROFILE_V1_RES: 0x0064 as ResponseCode, + LOAD_PROFILE_V2_RES: 0x0065 as ResponseCode, + CREATE_PROFILE_REQ: 0x0066 as RequestCode, + LOAD_PROFILE_REQ: 0x0067 as RequestCode, + SAVE_RECORD_REQ: 0x0068 as RequestCode, + ACCOUNT_LOCK_REQ: 0x0069 as RequestCode, + ACCOUNT_LOCK_RES: 0x006a as ResponseCode, + DISCOVER_PROFILE_REQ: 0x006b as RequestCode, + DISCOVER_PROFILE_RES: 0x006c as ResponseCode, + ACCOUNT_UNLOCK_REQ: 0x006f as RequestCode, + ACCOUNT_UNLOCK_RES: 0x0070 as ResponseCode, + LOAD_TEAM_REQ: 0x0077 as RequestCode, + LOAD_TEAM_RES: 0x0078 as ResponseCode, + CREATE_TEAM_REQ: 0x007b as RequestCode, + CREATE_TEAM_RES: 0x007c as ResponseCode, + UPDATE_STORY_CLEAR_NUM_REQ: 0x007f as RequestCode, + UPDATE_STORY_CLEAR_NUM_RES: 0x0080 as ResponseCode, + UPDATE_PROVISIONAL_STORE_RANK_REQ: 0x0082 as RequestCode, + UPDATE_PROVISIONAL_STORE_RANK_RES: 0x0083 as ResponseCode, + LOAD_REWARD_TABLE_REQ: 0x0086 as RequestCode, + LOAD_REWARD_TABLE_RES: 0x0087 as ResponseCode, + SAVE_EXPEDITION_REQ: 0x008c as RequestCode, + SAVE_EXPEDITION_RES: 0x008d as ResponseCode, + SAVE_TOPIC_REQ: 0x009a as RequestCode, + SAVE_TOPIC_RES: 0x009b as ResponseCode, + LOAD_GENERAL_REWARD_REQ: 0x009c as RequestCode, + LOAD_GENERAL_REWARD_RES: 0x009d as ResponseCode, + SAVE_SETTINGS_REQ: 0x00a5 as RequestCode, + LOAD_CONFIG_V2_REQ: 0x00ab as RequestCode, + LOAD_CONFIG_V2_RES: 0x00ac as ResponseCode, + LOAD_STOCKER_REQ: 0x00a7 as RequestCode, + LOAD_STOCKER_RES: 0x00a8 as ResponseCode, + LOAD_2ON2_REQ: 0x00b0 as RequestCode, + LOAD_2ON2_RES: 0x00b1 as ResponseCode, }; export const MSG = _MSG as Readonly; -const RL = new Map(); +const RL = new Map(); RL.set(MSG.ACCOUNT_LOCK_REQ, 0x0020); RL.set(MSG.ACCOUNT_UNLOCK_REQ, 0x0020); @@ -71,6 +71,6 @@ RL.set(MSG.SAVE_TOPIC_REQ, 0x0010); RL.set(MSG.UPDATE_PROVISIONAL_STORE_RANK_REQ, 0x0010); RL.set(MSG.UPDATE_STORY_CLEAR_NUM_REQ, 0x0010); -export function getRequestLength(id: RequestId): number | undefined { +export function getRequestLength(id: RequestCode): number | undefined { return RL.get(id); }