From 25bdc7d9dd4edc4d878cd47f3cff996fcb4411c4 Mon Sep 17 00:00:00 2001 From: Tau Date: Sun, 31 Mar 2019 18:47:00 -0400 Subject: [PATCH] wip --- src/idz/decoder.ts | 21 +++++++++++++++++++++ src/idz/defs.ts | 12 ++++++++++-- src/idz/encoder.ts | 31 +++++++++++++++++++++++++++++-- src/idz/index.ts | 33 ++++++++++++++++++++++++++++++--- src/idz/request.ts | 18 ++++++++++++++++++ src/idz/response.ts | 25 +++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 7 deletions(-) diff --git a/src/idz/decoder.ts b/src/idz/decoder.ts index 37de2f7..933cfc0 100644 --- a/src/idz/decoder.ts +++ b/src/idz/decoder.ts @@ -86,6 +86,21 @@ readers.set(MSG.GET_EXIST_RECORD_REQ, buf => { }; }); +readers.set(MSG.GET_RECORD_REQ, buf => { + return { + type: "get_record_req", + aimeId: buf.readUInt32LE(0x0004), + pcbId: buf.slice(0x0008, buf.indexOf("\0", 0x0008)).toString("ascii"), + }; +}); + +readers.set(MSG.GET_STOCKER_REQ, buf => { + return { + type: "get_stocker_req", + aimeId: buf.readUInt32LE(0x0004), + }; +}); + readers.set(MSG.GET_REWARD_TABLE_REQ, () => { return { type: "get_reward_table_req", @@ -110,6 +125,12 @@ readers.set(MSG.UPDATE_RECORD_REQ, buf => { }; }); +readers.set(MSG.UPDATE_STORY_CLEAR_NUM_REQ, () => { + return { + type: "update_story_clear_num_req", + }; +}); + readers.set(MSG.UPDATE_TOPIC_REQ, buf => { const aimeId = buf.readUInt32LE(0x0004); diff --git a/src/idz/defs.ts b/src/idz/defs.ts index 560918d..4adfb08 100644 --- a/src/idz/defs.ts +++ b/src/idz/defs.ts @@ -4,7 +4,10 @@ export const MSG = { GET_CONFIG_RES: 0x0005, GET_SERVER_LIST_REQ: 0x0006, GET_SERVER_LIST_RES: 0x0007, + GET_RECORD_V1_RES: 0x0064, + GET_RECORD_V2_RES: 0x0065, CREATE_RECORD_REQ: 0x0066, + GET_RECORD_REQ: 0x0067, UPDATE_RECORD_REQ: 0x0068, ACCOUNT_LOCK_REQ: 0x0069, ACCOUNT_LOCK_RES: 0x006a, @@ -14,7 +17,8 @@ export const MSG = { ACCOUNT_UNLOCK_RES: 0x0070, CREATE_TEAM_REQ: 0x007b, CREATE_TEAM_RES: 0x007c, - UPDATE_STORY_CLEAR_REQ: 0x007f, + UPDATE_STORY_CLEAR_NUM_REQ: 0x007f, + UPDATE_STORY_CLEAR_NUM_RES: 0x0080, UPDATE_PROVISIONAL_STORE_RANK_REQ: 0x0082, UPDATE_PROVISIONAL_STORE_RANK_RES: 0x0083, GET_REWARD_TABLE_REQ: 0x0086, @@ -23,6 +27,8 @@ export const MSG = { UPDATE_TOPIC_RES: 0x009b, GET_CONFIG_DATA_2_REQ: 0x00ab, GET_CONFIG_DATA_2_RES: 0x00ac, + GET_STOCKER_REQ: 0x00a7, + GET_STOCKER_RES: 0x00a8, }; export const REQ_LEN = new Map(); @@ -34,9 +40,11 @@ REQ_LEN.set(MSG.CREATE_TEAM_REQ, 0x0010); REQ_LEN.set(MSG.GET_CONFIG_REQ, 0x0050); REQ_LEN.set(MSG.GET_CONFIG_DATA_2_REQ, 0x0010); REQ_LEN.set(MSG.GET_EXIST_RECORD_REQ, 0x0010); +REQ_LEN.set(MSG.GET_RECORD_REQ, 0x0020); REQ_LEN.set(MSG.GET_REWARD_TABLE_REQ, 0x0010); REQ_LEN.set(MSG.GET_SERVER_LIST_REQ, 0x0020); +REQ_LEN.set(MSG.GET_STOCKER_REQ, 0x0010); REQ_LEN.set(MSG.UPDATE_PROVISIONAL_STORE_RANK_REQ, 0x0010); REQ_LEN.set(MSG.UPDATE_RECORD_REQ, 0x0940); -REQ_LEN.set(MSG.UPDATE_STORY_CLEAR_REQ, 0x0020); +REQ_LEN.set(MSG.UPDATE_STORY_CLEAR_NUM_REQ, 0x0010); REQ_LEN.set(MSG.UPDATE_TOPIC_REQ, 0x0010); diff --git a/src/idz/encoder.ts b/src/idz/encoder.ts index 3b6fb17..806323b 100644 --- a/src/idz/encoder.ts +++ b/src/idz/encoder.ts @@ -53,14 +53,14 @@ export class Encoder extends Transform { case "get_config_res": buf = Buffer.alloc(0x01a0); buf.writeUInt16LE(MSG.GET_CONFIG_RES, 0x0000); - buf.writeUInt16LE(obj.status, 0x0002); + buf.writeUInt8(obj.status, 0x0002); break; case "get_config_2_res": buf = Buffer.alloc(0x230); buf.writeUInt16LE(MSG.GET_CONFIG_DATA_2_RES, 0x0000); - buf.writeUInt16LE(obj.status, 0x0002); + buf.writeUInt8(obj.status, 0x0002); break; @@ -71,6 +71,20 @@ export class Encoder extends Transform { break; + case "get_record_v1_res": + buf = Buffer.alloc(0x0c60); + buf.writeUInt16LE(MSG.GET_RECORD_V1_RES, 0x0000); + //iconv.encode("てすと", sjis).copy(buf, 0x03ea); + + break; + + case "get_record_v2_res": + buf = Buffer.alloc(0x0d30); + buf.writeUInt16LE(MSG.GET_RECORD_V2_RES, 0x0000); + iconv.encode("てすと", sjis).copy(buf, 0x03ea); + + break; + case "get_reward_table_res": buf = Buffer.alloc(0x01c0); buf.writeUInt16LE(MSG.GET_REWARD_TABLE_RES, 0x0000); @@ -105,6 +119,13 @@ export class Encoder extends Transform { break; + case "get_stocker_res": + buf = Buffer.alloc(0x00a0); + buf.writeUInt16LE(MSG.GET_STOCKER_RES, 0x0000); + buf.writeUInt8(obj.status, 0x0002); + + break; + case "update_provisional_store_rank_res": buf = Buffer.alloc(0x02b0); buf.writeUInt16LE(MSG.UPDATE_PROVISIONAL_STORE_RANK_RES, 0x0000); @@ -123,6 +144,12 @@ export class Encoder extends Transform { break; + case "update_story_clear_num_res": + buf = Buffer.alloc(0x0220); + buf.writeUInt16LE(MSG.UPDATE_STORY_CLEAR_NUM_RES, 0x0000); + + break; + case "update_topic_res": buf = Buffer.alloc(0x05d0); buf.writeUInt16LE(MSG.UPDATE_TOPIC_RES, 0x0000); diff --git a/src/idz/index.ts b/src/idz/index.ts index b2f93dc..ae1e214 100644 --- a/src/idz/index.ts +++ b/src/idz/index.ts @@ -62,6 +62,21 @@ export default async function idz(socket: Socket) { break; + case "get_exist_record_req": + output.write({ + type: "get_exist_record_res", + result: true, + }); + + break; + + case "get_record_req": + output.write({ + type: "get_record_v2_res", + }); + + break; + case "get_reward_table_req": output.write({ type: "get_reward_table_res", @@ -114,10 +129,10 @@ export default async function idz(socket: Socket) { break; - case "get_exist_record_req": + case "get_stocker_req": output.write({ - type: "get_exist_record_res", - result: false, + type: "get_stocker_res", + status: 1, }); break; @@ -138,12 +153,24 @@ export default async function idz(socket: Socket) { break; + case "update_story_clear_num_req": + output.write({ + type: "update_story_clear_num_res", + }); + + break; + case "update_topic_req": output.write({ type: "update_topic_res", }); break; + + default: + const exhaustCheck: never = msg; + + throw new Error(`Unhandled message ${msg["type"]}`); } } } catch (e) { diff --git a/src/idz/request.ts b/src/idz/request.ts index 175bebb..1de9038 100644 --- a/src/idz/request.ts +++ b/src/idz/request.ts @@ -57,6 +57,12 @@ export interface GetExistRecordRequest { aimeId: number; } +export interface GetRecordRequest { + type: "get_record_req"; + aimeId: number; + pcbId: string; +} + export interface GetRewardTableRequest { type: "get_reward_table_req"; } @@ -65,6 +71,11 @@ export interface GetServerListRequest { type: "get_server_list_req"; } +export interface GetStockerRequest { + type: "get_stocker_req"; + aimeId: number; +} + export interface UpdateProvisionalStoreRankRequest { type: "update_provisional_store_rank_req"; aimeId: number; @@ -75,6 +86,10 @@ export interface UpdateRecordRequest { // TODO } +export interface UpdateStoryClearNumRequest { + type: "update_story_clear_num_req"; +} + export interface UpdateTopicRequest { type: "update_topic_req"; aimeId?: number; @@ -88,8 +103,11 @@ export type Request = | GetConfigRequest | GetConfigRequest2 | GetExistRecordRequest + | GetRecordRequest | GetRewardTableRequest | GetServerListRequest + | GetStockerRequest | UpdateProvisionalStoreRankRequest | UpdateRecordRequest + | UpdateStoryClearNumRequest | UpdateTopicRequest; diff --git a/src/idz/response.ts b/src/idz/response.ts index 7c5489e..68b90ac 100644 --- a/src/idz/response.ts +++ b/src/idz/response.ts @@ -35,6 +35,16 @@ export interface GetExistRecordResponse { result: boolean; } +export interface GetRecordResponse1 { + type: "get_record_v1_res"; + // giga TODO +} + +export interface GetRecordResponse2 { + type: "get_record_v2_res"; + // giga TODO +} + export interface GetRewardTableResponse { type: "get_reward_table_res"; // TODO @@ -80,6 +90,12 @@ export interface GetServerListResponse { reportErrorUrl: string; } +export interface GetStockerResponse { + type: "get_stocker_res"; + status: number; + // mega TODO +} + export interface UpdateProvisionalStoreRankResponseRow { field_0000: number; field_0004: number; @@ -92,6 +108,11 @@ export interface UpdateProvisionalStoreRankResponse { rows: UpdateProvisionalStoreRankResponseRow[]; } +export interface UpdateStoryClearNumResponse { + type: "update_story_clear_num_res"; + // TODO, looks like a table of 9 * 10 u32 fields +} + export interface UpdateTopicResponse { type: "update_topic_res"; // mega TODO @@ -105,7 +126,11 @@ export type Response = | GetConfigResponse | GetConfigResponse2 | GetExistRecordResponse + | GetRecordResponse1 + | GetRecordResponse2 | GetRewardTableResponse | GetServerListResponse + | GetStockerResponse | UpdateProvisionalStoreRankResponse + | UpdateStoryClearNumResponse | UpdateTopicResponse;