diff --git a/src/aimedb/encoder.ts b/src/aimedb/encoder.ts index 2de438d..21b849a 100644 --- a/src/aimedb/encoder.ts +++ b/src/aimedb/encoder.ts @@ -95,7 +95,7 @@ export class Encoder extends Transform { return callback(new Error("Unimplemented response type")); } - console.log("Aimedb: Send", buf); + console.log("Aimedb: Send", buf.toString("hex")); return callback(null, buf); } diff --git a/src/aimedb/frame.ts b/src/aimedb/frame.ts index aa958c8..0414ce9 100644 --- a/src/aimedb/frame.ts +++ b/src/aimedb/frame.ts @@ -33,7 +33,7 @@ export class Deframer extends Transform { const frame = this.state.slice(0, len); - console.log("Aimedb: Recv", frame); + console.log("Aimedb: Recv", frame.toString("hex")); this.state = this.state.slice(len); diff --git a/src/idz/decoder.ts b/src/idz/decoder.ts index a79a2bf..3a1d97e 100644 --- a/src/idz/decoder.ts +++ b/src/idz/decoder.ts @@ -73,10 +73,16 @@ readers.set(MSG.GET_SERVER_LIST_REQ, () => { return { type: "get_server_list_req" }; }); +readers.set(MSG.UPDATE_PROVISIONAL_STORE_RANK_REQ, buf => { + return { + type: "update_provisional_store_rank_req", + aimeId: buf.readUInt32LE(0x0004), + }; +}); + readers.set(MSG.UPDATE_RECORD_REQ, buf => { return { type: "update_record_req", - payload: buf, // hack }; }); diff --git a/src/idz/defs.ts b/src/idz/defs.ts index 95b64ec..555cb34 100644 --- a/src/idz/defs.ts +++ b/src/idz/defs.ts @@ -1,27 +1,30 @@ export const MSG = { GENERIC_RES: 0x0001, - CREATE_RECORD_REQ: 0x0066, - UPDATE_RECORD_REQ: 0x0068, - CREATE_TEAM_REQ: 0x007b, - CREATE_TEAM_RES: 0x007c, GET_CONFIG_REQ: 0x0004, GET_CONFIG_RES: 0x0005, GET_SERVER_LIST_REQ: 0x0006, GET_SERVER_LIST_RES: 0x0007, + CREATE_RECORD_REQ: 0x0066, + UPDATE_RECORD_REQ: 0x0068, ACCOUNT_LOCK_REQ: 0x0069, ACCOUNT_LOCK_RES: 0x006a, + CREATE_TEAM_REQ: 0x007b, + CREATE_TEAM_RES: 0x007c, UPDATE_STORY_CLEAR_REQ: 0x007f, + UPDATE_PROVISIONAL_STORE_RANK_REQ: 0x0082, + UPDATE_PROVISIONAL_STORE_RANK_RES: 0x0083, GET_CONFIG_DATA_2_REQ: 0x00ab, GET_CONFIG_DATA_2_RES: 0x00ac, }; export const REQ_LEN = new Map(); +REQ_LEN.set(MSG.ACCOUNT_LOCK_REQ, 0x0020); REQ_LEN.set(MSG.CREATE_RECORD_REQ, 0x00c0); 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.ACCOUNT_LOCK_REQ, 0x0020); +REQ_LEN.set(MSG.GET_SERVER_LIST_REQ, 0x0020); +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.GET_SERVER_LIST_REQ, 0x0020); diff --git a/src/idz/encoder.ts b/src/idz/encoder.ts index 5dfed86..33a19df 100644 --- a/src/idz/encoder.ts +++ b/src/idz/encoder.ts @@ -29,13 +29,6 @@ export class Encoder extends Transform { break; - case "generic_res": - buf = Buffer.alloc(0x0020); - buf.writeUInt16LE(MSG.GENERIC_RES, 0x0000); - buf.writeUInt32LE(obj.field_0004, 0x0004); - - break; - case "create_team_res": buf = Buffer.alloc(0x0ca0); buf.writeUInt16LE(MSG.CREATE_TEAM_RES, 0x0000); @@ -43,6 +36,13 @@ export class Encoder extends Transform { break; + case "generic_res": + buf = Buffer.alloc(0x0020); + buf.writeUInt16LE(MSG.GENERIC_RES, 0x0000); + buf.writeUInt32LE(obj.field_0004, 0x0004); + + break; + case "get_config_res": buf = Buffer.alloc(0x01a0); buf.writeUInt16LE(MSG.GET_CONFIG_RES, 0x0000); @@ -85,6 +85,24 @@ export class Encoder extends Transform { break; + case "update_provisional_store_rank_res": + buf = Buffer.alloc(0x02b0); + buf.writeUInt16LE(MSG.UPDATE_PROVISIONAL_STORE_RANK_RES, 0x0000); + + for (let i = 0; i < 10; i++) { + const offset = 0x44 + i; + const row = obj.rows[i]; + + if (row !== undefined) { + buf.writeUInt16LE(row.field_0000, offset + 0x0000); + buf.writeUInt32LE(row.field_0004, offset + 0x0004); + iconv.encode(row.field_0010, sjis).copy(buf, offset + 0x0010); + iconv.encode(row.field_003B, sjis).copy(buf, offset + 0x003b); + } + } + + break; + default: return callback(new Error(`No writer fn for ${obj["type"]}`)); } diff --git a/src/idz/index.ts b/src/idz/index.ts index ce55f5a..9411d78 100644 --- a/src/idz/index.ts +++ b/src/idz/index.ts @@ -2,6 +2,7 @@ import { Socket } from "net"; import { hostname } from "os"; import setup from "./setup"; +import { objectExpression } from "@babel/types"; export default async function idz(socket: Socket) { const { input, output } = setup(socket); @@ -98,6 +99,19 @@ export default async function idz(socket: Socket) { break; + case "update_provisional_store_rank_req": + output.write({ + type: "update_provisional_store_rank_res", + rows: [10, 11, 12, 13].map(rank => ({ + field_0000: rank, + field_0004: msg.aimeId + rank - 11, + field_0010: `x${rank}`, + field_003B: `y${rank}`, + })), + }); + + break; + case "update_record_req": output.write({ type: "generic_res", diff --git a/src/idz/request.ts b/src/idz/request.ts index 7145ad4..c1d15aa 100644 --- a/src/idz/request.ts +++ b/src/idz/request.ts @@ -50,9 +50,14 @@ export interface GetServerListRequest { type: "get_server_list_req"; } +export interface UpdateProvisionalStoreRankRequest { + type: "update_provisional_store_rank_req"; + aimeId: number; +} + export interface UpdateRecordRequest { type: "update_record_req"; - payload: Buffer; + // TODO } export type Request = @@ -62,4 +67,5 @@ export type Request = | GetConfigRequest | GetConfigRequest2 | GetServerListRequest + | UpdateProvisionalStoreRankRequest | UpdateRecordRequest; diff --git a/src/idz/response.ts b/src/idz/response.ts index 363cbfd..1105a05 100644 --- a/src/idz/response.ts +++ b/src/idz/response.ts @@ -65,10 +65,23 @@ export interface GetServerListResponse { reportErrorUrl: string; } +export interface UpdateProvisionalStoreRankResponseRow { + field_0000: number; + field_0004: number; + field_0010: string; + field_003B: string; +} + +export interface UpdateProvisionalStoreRankResponse { + type: "update_provisional_store_rank_res"; + rows: UpdateProvisionalStoreRankResponseRow[]; +} + export type Response = | AccountLockResponse | CreateTeamResponse | GenericResponse | GetConfigResponse | GetConfigResponse2 - | GetServerListResponse; + | GetServerListResponse + | UpdateProvisionalStoreRankResponse;