From d7b510193fc8ec9b8341cf3234596ef1d454fd78 Mon Sep 17 00:00:00 2001 From: Tau Date: Fri, 5 Apr 2019 21:08:17 -0400 Subject: [PATCH] modelize chara --- src/idz/decoder/_chara.ts | 14 +++++++++ src/idz/decoder/createProfile.ts | 10 ++----- src/idz/encoder/_bitSet.ts | 12 ++++++++ src/idz/encoder/_chara.ts | 16 ++++++++++ src/idz/encoder/loadProfile2.ts | 50 ++++++++++++++------------------ src/idz/encoder/loadStocker.ts | 4 ++- src/idz/handler/_team.ts | 8 +---- src/idz/handler/loadProfile.ts | 13 ++++++++- src/idz/index.ts | 2 +- src/idz/model/chara.ts | 10 +++++++ src/idz/request/createProfile.ts | 10 ++----- src/idz/response/loadProfile2.ts | 6 +++- 12 files changed, 99 insertions(+), 56 deletions(-) create mode 100644 src/idz/decoder/_chara.ts create mode 100644 src/idz/encoder/_bitSet.ts create mode 100644 src/idz/encoder/_chara.ts create mode 100644 src/idz/model/chara.ts diff --git a/src/idz/decoder/_chara.ts b/src/idz/decoder/_chara.ts new file mode 100644 index 0000000..12815a3 --- /dev/null +++ b/src/idz/decoder/_chara.ts @@ -0,0 +1,14 @@ +import { Chara } from "../model/chara"; + +export function chara(buf: Buffer): Chara { + return { + gender: buf.readUInt16LE(0x00) === 0 ? "male" : "female", + clothing: buf.readUInt16LE(0x02), + mouth: buf.readUInt16LE(0x04), + field_06: buf.readUInt16LE(0x06), + field_08: buf.readUInt16LE(0x08), + field_0A: buf.readUInt16LE(0x0a), + field_0C: buf.readUInt16LE(0x0c), + field_0E: buf.readUInt16LE(0x0e), + }; +} diff --git a/src/idz/decoder/createProfile.ts b/src/idz/decoder/createProfile.ts index 6b88404..3def125 100644 --- a/src/idz/decoder/createProfile.ts +++ b/src/idz/decoder/createProfile.ts @@ -3,6 +3,7 @@ import iconv = require("iconv-lite"); import { RequestCode } from "../defs"; import { CreateProfileRequest } from "../request/createProfile"; import { car } from "./_car"; +import { chara } from "./_chara"; createProfile.msgCode = 0x0066 as RequestCode; createProfile.msgLen = 0x00c0; @@ -18,14 +19,7 @@ export function createProfile(buf: Buffer): CreateProfileRequest { ), field_0034: buf.readUInt32LE(0x0034), car: car(buf.slice(0x0040, 0x00a0)), - 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), + chara: chara(buf.slice(0x00a0, 0x00b0)), field_00B0: buf.readUInt16LE(0x00b0), field_00B2: buf.readUInt8(0x00b2), }; diff --git a/src/idz/encoder/_bitSet.ts b/src/idz/encoder/_bitSet.ts new file mode 100644 index 0000000..8a250dd --- /dev/null +++ b/src/idz/encoder/_bitSet.ts @@ -0,0 +1,12 @@ +export function bitSet(items: number[], nbytes: number): Buffer { + const buf = Buffer.alloc(nbytes); + + for (const item of items) { + const byte = (item / 8) | 0; + const bit = item % 8; + + buf.writeUInt8(buf.readUInt8(byte) | (1 << bit), byte); + } + + return buf; +} diff --git a/src/idz/encoder/_chara.ts b/src/idz/encoder/_chara.ts new file mode 100644 index 0000000..77f7096 --- /dev/null +++ b/src/idz/encoder/_chara.ts @@ -0,0 +1,16 @@ +import { Chara } from "../model/chara"; + +export function chara(chara: Chara): Buffer { + const buf = Buffer.alloc(0x0010); + + buf.writeUInt8(chara.gender === "male" ? 0 : 1, 0x00); + buf.writeUInt16LE(chara.clothing, 0x02); + buf.writeUInt16LE(chara.mouth, 0x04); + buf.writeUInt16LE(chara.field_06, 0x06); + buf.writeUInt16LE(chara.field_08, 0x08); + buf.writeUInt16LE(chara.field_0A, 0x0a); + buf.writeUInt16LE(chara.field_0C, 0x0c); + buf.writeUInt16LE(chara.field_0E, 0x0e); + + return buf; +} diff --git a/src/idz/encoder/loadProfile2.ts b/src/idz/encoder/loadProfile2.ts index 440b2c6..844dda3 100644 --- a/src/idz/encoder/loadProfile2.ts +++ b/src/idz/encoder/loadProfile2.ts @@ -1,49 +1,41 @@ import iconv = require("iconv-lite"); import { car } from "./_car"; +import { chara } from "./_chara"; import { LoadProfileResponse2 } from "../response/loadProfile2"; export function loadProfile2(res: LoadProfileResponse2) { - const buf = Buffer.alloc(0x0d30); - // Story stuff //buf.writeUInt32LE(0x1ff, 0x0228); - // face - buf.writeUInt8(1, 0x070c); // Male/female - buf.writeUInt16LE(0x0066, 0x070e); // Unknown - buf.writeUInt16LE(0x00fc, 0x0710); // Face shape? - buf.writeUInt16LE(0x0000, 0x0712); // Unknown, some weird behind-face protrusion - buf.writeUInt16LE(0x0000, 0x0714); // Unknown - buf.writeUInt16LE(0x0000, 0x0716); - buf.writeUInt16LE(0x0000, 0x0718); - buf.writeUInt16LE(0x0000, 0x071a); - buf.writeUInt16LE(0x00d7, 0x071c); // Background - buf.writeUInt16LE(0x0000, 0x071e); // Flair - // Flairs (bitmap) // buf.fill(0xff, 0x071c, 0x071c + 0xb4); - buf.writeInt16LE(0x0065, 0x0000); - buf.writeInt32LE(res.profileId, 0x3b8); - buf.writeUInt16LE(res.settings.bgMusic, 0x3c8); - buf.writeInt16LE(res.lv, 0x03cc); - buf.writeUInt32LE( + const settingsPack = ((res.settings.forceQuitEn ? 1 : 0) << 0) | - (res.settings.steeringForce << 1) | - (res.settings.bgVolume << 5) | - (res.settings.seVolume << 9) | - ((res.settings.cornerGuide ? 1 : 0) << 13) | - ((res.settings.lineGuide ? 1 : 0) << 14) | - ((res.settings.ghostEn ? 1 : 0) << 15) | - ((res.settings.taResultSkip ? 1 : 0) << 16), - 0x3d8 - ); + (res.settings.steeringForce << 1) | + (res.settings.bgVolume << 5) | + (res.settings.seVolume << 9) | + ((res.settings.cornerGuide ? 1 : 0) << 13) | + ((res.settings.lineGuide ? 1 : 0) << 14) | + ((res.settings.ghostEn ? 1 : 0) << 15) | + ((res.settings.taResultSkip ? 1 : 0) << 16); + + const buf = Buffer.alloc(0x0d30); + + buf.writeInt16LE(0x0065, 0x0000); + buf.writeInt32LE(res.profileId, 0x03b8); + buf.writeUInt16LE(res.settings.bgMusic, 0x03c8); + buf.writeInt16LE(res.lv, 0x03cc); + buf.writeUInt32LE(settingsPack, 0x3d8); buf.writeInt32LE(res.dpoint, 0x03e8); buf.writeInt32LE(res.fame, 0x0404); iconv.encode(res.name + "\0", "shift_jis").copy(buf, 0x03ee); + chara(res.chara).copy(buf, 0x070c); + buf.writeUInt16LE(res.background, 0x071c); + buf.writeUInt16LE(res.title, 0x071e); buf.writeInt32LE(res.teamId, 0x07e0); - car(res.car).copy(buf, 0xc5c); + car(res.car).copy(buf, 0x0c5c); return buf; } diff --git a/src/idz/encoder/loadStocker.ts b/src/idz/encoder/loadStocker.ts index 6dbfdb0..9456013 100644 --- a/src/idz/encoder/loadStocker.ts +++ b/src/idz/encoder/loadStocker.ts @@ -4,7 +4,9 @@ export function loadStocker(res: LoadStockerResponse) { const buf = Buffer.alloc(0x00a0); buf.writeInt16LE(0x00a8, 0x0000); - buf.writeInt8(res.status, 0x0002); + buf.writeUInt8(res.status, 0x0002); + //buf.fill(0xff, 0x0003, 0x000a); + buf.writeUInt8(0x08, 0x0008); return buf; } diff --git a/src/idz/handler/_team.ts b/src/idz/handler/_team.ts index 0cdb3d4..44d5444 100644 --- a/src/idz/handler/_team.ts +++ b/src/idz/handler/_team.ts @@ -10,13 +10,7 @@ export function _team( ): CreateTeamResponse | LoadTeamResponse { const bits = { name: "ASS GENTLEMEN", - members: [ - { - name: "てすと", - lv: 69, - monthPoints: 1234, - }, - ], + members: [], }; if (req.type === "create_team_req") { diff --git a/src/idz/handler/loadProfile.ts b/src/idz/handler/loadProfile.ts index f9877a9..cfad94a 100644 --- a/src/idz/handler/loadProfile.ts +++ b/src/idz/handler/loadProfile.ts @@ -1,7 +1,6 @@ import { LoadProfileRequest } from "../request/loadProfile"; import { LoadProfileResponse2 } from "../response/loadProfile2"; import { World } from "../world"; -import { Car } from "../model/car"; export function loadProfile( w: World, @@ -26,6 +25,18 @@ export function loadProfile( ghostEn: false, taResultSkip: false, }, + chara: { + gender: "male", + clothing: 0, + mouth: 0, + field_06: 0, + field_08: 0, + field_0A: 0, + field_0C: 0, + field_0E: 0, + }, + background: 0, + title: 0, car: { field_00: 0, field_02: 0, diff --git a/src/idz/index.ts b/src/idz/index.ts index f35a94e..85413be 100644 --- a/src/idz/index.ts +++ b/src/idz/index.ts @@ -19,5 +19,5 @@ export default async function idz(socket: Socket) { console.log("Idz: Error", e); } - console.log("Idz: Connection closed"); + console.log("Idz: Connection closed\n"); } diff --git a/src/idz/model/chara.ts b/src/idz/model/chara.ts new file mode 100644 index 0000000..5784005 --- /dev/null +++ b/src/idz/model/chara.ts @@ -0,0 +1,10 @@ +export interface Chara { + gender: "male" | "female"; + clothing: number; + mouth: number; + field_06: number; + field_08: number; + field_0A: number; + field_0C: number; + field_0E: number; +} diff --git a/src/idz/request/createProfile.ts b/src/idz/request/createProfile.ts index 1fec795..216e61b 100644 --- a/src/idz/request/createProfile.ts +++ b/src/idz/request/createProfile.ts @@ -1,4 +1,5 @@ import { Car } from "../model/car"; +import { Chara } from "../model/chara"; export interface CreateProfileRequest { type: "create_profile_req"; @@ -7,14 +8,7 @@ export interface CreateProfileRequest { name: string; field_0034: number; car: Car; - gender: "male" | "female"; - field_00A2: number; - field_00A4: number; - field_00A6: number; - field_00A8: number; - field_00AA: number; - field_00AC: number; - field_00AE: number; + chara: Chara; field_00B0: number; field_00B2: number; } diff --git a/src/idz/response/loadProfile2.ts b/src/idz/response/loadProfile2.ts index 40732e7..4e647f6 100644 --- a/src/idz/response/loadProfile2.ts +++ b/src/idz/response/loadProfile2.ts @@ -1,5 +1,6 @@ -import { Settings } from "../model/settings"; import { Car } from "../model/car"; +import { Chara } from "../model/chara"; +import { Settings } from "../model/settings"; export interface LoadProfileResponse2 { type: "load_profile_v2_res"; @@ -10,6 +11,9 @@ export interface LoadProfileResponse2 { dpoint: number; teamId: number; settings: Settings; + chara: Chara; + background: number; + title: number; car: Car; // giga TODO }