modelize chara

This commit is contained in:
Tau
2019-04-05 21:08:17 -04:00
parent d1dfda62c9
commit d7b510193f
12 changed files with 99 additions and 56 deletions

14
src/idz/decoder/_chara.ts Normal file
View File

@@ -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),
};
}

View File

@@ -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),
};

View File

@@ -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;
}

16
src/idz/encoder/_chara.ts Normal file
View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -10,13 +10,7 @@ export function _team(
): CreateTeamResponse | LoadTeamResponse {
const bits = {
name: " ",
members: [
{
name: "てすと",
lv: 69,
monthPoints: 1234,
},
],
members: [],
};
if (req.type === "create_team_req") {

View File

@@ -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,

View File

@@ -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");
}

10
src/idz/model/chara.ts Normal file
View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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
}