mirror of
https://github.com/djhackersdev/minime.git
synced 2026-08-27 05:01:23 -05:00
idz: Use string I/O helpers
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import iconv from "iconv-lite";
|
||||
|
||||
import { car } from "./_car";
|
||||
import { chara } from "./_chara";
|
||||
import { CreateProfileRequest } from "../request/createProfile";
|
||||
import { AimeId } from "../../../model";
|
||||
import { readAsciiStr, readSjisStr } from "../../util/bin";
|
||||
|
||||
createProfile.msgCode = 0x0066;
|
||||
createProfile.msgLen = 0x00c0;
|
||||
@@ -12,11 +11,8 @@ export function createProfile(buf: Buffer): CreateProfileRequest {
|
||||
return {
|
||||
type: "create_profile_req",
|
||||
aimeId: buf.readInt32LE(0x0004) as AimeId,
|
||||
luid: buf.slice(0x0008, buf.indexOf("\0", 0x0008)).toString("ascii"),
|
||||
name: iconv.decode(
|
||||
buf.slice(0x001e, buf.indexOf("\0", 0x001e)),
|
||||
"shift_jis"
|
||||
),
|
||||
luid: readAsciiStr(buf, 0x0008, 0x001e),
|
||||
name: readSjisStr(buf, 0x001e, 0x0034),
|
||||
field_0034: buf.readUInt32LE(0x0034),
|
||||
car: car(buf.slice(0x0040, 0x00a0)),
|
||||
chara: chara(buf.slice(0x00a0, 0x00b4)),
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import iconv from "iconv-lite";
|
||||
|
||||
import { CreateTeamRequest } from "../request/createTeam";
|
||||
import { AimeId } from "../../../model";
|
||||
import { readAsciiStr, readSjisStr } from "../../util/bin";
|
||||
|
||||
createTeam.msgCode = 0x0071;
|
||||
createTeam.msgLen = 0x0050;
|
||||
@@ -10,15 +9,12 @@ export function createTeam(buf: Buffer): CreateTeamRequest {
|
||||
return {
|
||||
type: "create_team_req",
|
||||
aimeId: buf.readUInt32LE(0x0004) as AimeId,
|
||||
teamName: iconv.decode(
|
||||
buf.slice(0x0008, buf.indexOf("\0", 0x0008)),
|
||||
"shift_jis"
|
||||
),
|
||||
teamName: readSjisStr(buf, 0x0008, 0x0028),
|
||||
field_0028: buf.readUInt16LE(0x0028),
|
||||
field_002C: buf.readUInt32LE(0x002c),
|
||||
nameBg: buf.readUInt8(0x0030),
|
||||
field_0032: buf.readUInt16LE(0x0032),
|
||||
prevTeamId: buf.readUInt32LE(0x0034),
|
||||
pcbId: buf.slice(0x0038, buf.indexOf("\0", 0x0038)).toString("ascii"),
|
||||
pcbId: readAsciiStr(buf, 0x0038, 0x0050),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
LoadProfileRequest3,
|
||||
} from "../request/loadProfile";
|
||||
import { AimeId } from "../../../model";
|
||||
import { readAsciiStr } from "../../util/bin";
|
||||
|
||||
loadProfile2.msgCode = 0x0067;
|
||||
loadProfile2.msgLen = 0x0020;
|
||||
@@ -12,7 +13,7 @@ export function loadProfile2(buf: Buffer): LoadProfileRequest2 {
|
||||
type: "load_profile_req",
|
||||
format: 2,
|
||||
aimeId: buf.readUInt32LE(0x0004) as AimeId,
|
||||
luid: buf.slice(0x0008, buf.indexOf("\0", 0x0008)).toString("ascii"),
|
||||
luid: readAsciiStr(buf, 0x0008, 0x0020),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -24,6 +25,6 @@ export function loadProfile3(buf: Buffer): LoadProfileRequest3 {
|
||||
type: "load_profile_req",
|
||||
format: 3,
|
||||
aimeId: buf.readUInt32LE(0x0004) as AimeId,
|
||||
luid: buf.slice(0x0008, buf.indexOf("\0", 0x0008)).toString("ascii"),
|
||||
luid: readAsciiStr(buf, 0x0008, 0x0020),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { readAsciiStr } from "../../util/bin";
|
||||
import { LockProfileRequest } from "../request/lockProfile";
|
||||
|
||||
lockProfile.msgCode = 0x0069;
|
||||
@@ -7,7 +8,7 @@ export function lockProfile(buf: Buffer): LockProfileRequest {
|
||||
return {
|
||||
type: "lock_profile_req",
|
||||
aimeId: buf.readUInt32LE(0x0004),
|
||||
pcbId: buf.slice(0x0008, buf.indexOf("\0", 0x0008)).toString("ascii"),
|
||||
pcbId: readAsciiStr(buf, 0x0008, 0x0018),
|
||||
field_0018: buf.readUInt16LE(0x0018),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { LockProfileExtendRequest } from "../request/lockProfileExtend";
|
||||
import { AimeId } from "../../../model";
|
||||
import { readAsciiStr } from "../../util/bin";
|
||||
|
||||
lockProfileExtend.msgCode = 0x006d;
|
||||
lockProfileExtend.msgLen = 0x0020;
|
||||
@@ -8,6 +9,6 @@ export function lockProfileExtend(buf: Buffer): LockProfileExtendRequest {
|
||||
return {
|
||||
type: "lock_profile_extend_req",
|
||||
aimeId: buf.readUInt32LE(0x0004) as AimeId,
|
||||
luid: buf.slice(0x0008, buf.indexOf("\0")).toString("ascii"),
|
||||
luid: readAsciiStr(buf, 0x0008, 0x0020),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { car } from "./_car";
|
||||
import { SaveNewCarRequest } from "../request/saveNewCar";
|
||||
import { readAsciiStr } from "../../util/bin";
|
||||
import { AimeId } from "../../../model";
|
||||
|
||||
saveNewCar.msgCode = 0x0079;
|
||||
@@ -9,7 +10,7 @@ export function saveNewCar(buf: Buffer): SaveNewCarRequest {
|
||||
return {
|
||||
type: "save_new_car_req",
|
||||
aimeId: buf.readUInt32LE(0x0004) as AimeId,
|
||||
luid: buf.slice(0x0008, buf.indexOf(0, 0x0008)).toString("ascii"),
|
||||
luid: readAsciiStr(buf, 0x0008, 0x001e),
|
||||
car: car(buf.slice(0x0020, 0x0080)),
|
||||
field_0080: buf.readUInt32LE(0x0080),
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ExtId } from "../model/base";
|
||||
import { Team } from "../model/team";
|
||||
import { UpdateTeamLeaderRequest } from "../request/updateTeamLeader";
|
||||
import { AimeId } from "../../../model";
|
||||
import { readAsciiStr } from "../../util/bin";
|
||||
|
||||
updateTeamLeader.msgCode = 0x008a;
|
||||
updateTeamLeader.msgLen = 0x0020;
|
||||
@@ -11,6 +12,6 @@ export function updateTeamLeader(buf: Buffer): UpdateTeamLeaderRequest {
|
||||
type: "update_team_leader_req",
|
||||
aimeId: buf.readUInt32LE(0x0004) as AimeId,
|
||||
teamExtId: buf.readUInt32LE(0x0008) as ExtId<Team>,
|
||||
field_000C: buf.slice(0x000c, buf.indexOf("\0", 0x000c)).toString("ascii"),
|
||||
field_000C: readAsciiStr(buf, 0x000c, 0x0020),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import iconv from "iconv-lite";
|
||||
|
||||
import { writeSjisStr } from "../../util/bin";
|
||||
import { CreateAutoTeamResponse } from "../response/createAutoTeam";
|
||||
import { LoadTeamResponse } from "../response/loadTeam";
|
||||
import { encodeChara } from "./_chara";
|
||||
@@ -15,9 +14,9 @@ export function _team(res: CreateAutoTeamResponse | LoadTeamResponse) {
|
||||
|
||||
const leader = res.members.find(item => item.leader === true);
|
||||
buf.writeUInt32LE(res.team.extId, 0x000c);
|
||||
iconv.encode(leader ? leader.profile.name : "Error\0", "shift_jis").copy(buf, 0x0010);
|
||||
iconv.encode(res.team.name, "shift_jis").copy(buf, 0x0024);
|
||||
iconv.encode(process.env.SHOP_NAME ? process.env.SHOP_NAME : "\0", "shift_jis").copy(buf, 0x0044);
|
||||
writeSjisStr(buf, 0x0010, 0x0024, leader ? leader.profile.name : "Error");
|
||||
writeSjisStr(buf, 0x0024, 0x0044, res.team.name);
|
||||
writeSjisStr(buf, 0x0044, 0x00d8, process.env.SHOP_NAME || "");
|
||||
buf.writeUInt32LE(res.team.nameBg, 0x00d8);
|
||||
buf.writeUInt32LE(res.team.nameFx, 0x00dc);
|
||||
buf.fill(0xff, 0x00e0, 0x00f9); // Bitset: Unlocked BGs probably
|
||||
@@ -36,7 +35,7 @@ export function _team(res: CreateAutoTeamResponse | LoadTeamResponse) {
|
||||
const accessTime = (profile.accessTime.getTime() / 1000) | 0;
|
||||
|
||||
buf.writeInt32LE(profile.aimeId, base + 0x0000);
|
||||
iconv.encode(profile.name + "\0", "shift_jis").copy(buf, base + 0x0004);
|
||||
writeSjisStr(buf, 0x0004, 0x0018, profile.name);
|
||||
buf.writeInt32LE(profile.lv, base + 0x0018);
|
||||
buf.writeInt32LE(0, base + 0x0024); // Month points, TODO
|
||||
buf.writeUInt32LE(accessTime, base + 0x0034);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import iconv from "iconv-lite";
|
||||
|
||||
import { LoadGeneralRewardResponse } from "../response/loadGeneralReward";
|
||||
import { writeSjisStr } from "../../util/bin";
|
||||
|
||||
export function loadGeneralReward(res: LoadGeneralRewardResponse) {
|
||||
const buf = Buffer.alloc(0x0330);
|
||||
@@ -15,7 +14,7 @@ export function loadGeneralReward(res: LoadGeneralRewardResponse) {
|
||||
const item = res.items[i];
|
||||
const base = 0x04 + 0x50 * i;
|
||||
|
||||
iconv.encode(item.field_04, "shift_jis").copy(buf, base + 0x04);
|
||||
writeSjisStr(buf, base + 0x04, base + 0x2c, item.field_04);
|
||||
buf.writeUInt32LE(item.field_2C, base + 0x2c);
|
||||
buf.writeUInt8(item.field_38, base + 0x38);
|
||||
buf.writeUInt8(item.field_39, base + 0x39);
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import iconv from "iconv-lite";
|
||||
|
||||
import { encodeBitmap } from "./_bitmap";
|
||||
import { encodeCar } from "./_car";
|
||||
import { encodeChara } from "./_chara";
|
||||
import { encodeMission } from "./_mission";
|
||||
import { LoadProfileResponse2 } from "../response/loadProfile";
|
||||
import { writeSjisStr } from "../../util/bin";
|
||||
|
||||
export function loadProfile2(res: LoadProfileResponse2) {
|
||||
const buf = Buffer.alloc(0x0d30);
|
||||
@@ -87,7 +86,7 @@ export function loadProfile2(res: LoadProfileResponse2) {
|
||||
buf.writeUInt32LE(res.settings.pack, 0x03d8);
|
||||
buf.writeUInt32LE(res.dpoint, 0x03e8);
|
||||
buf.writeUInt32LE(res.fame, 0x0404);
|
||||
iconv.encode(res.name + "\0", "shift_jis").copy(buf, 0x03ee);
|
||||
writeSjisStr(buf, 0x03ee, 0x40e, res.name);
|
||||
buf.writeUInt8(res.story.y, 0x0670);
|
||||
buf.writeUInt16LE(res.story.x, 0x06bc);
|
||||
encodeMission(res.missions.solo).copy(buf, 0x06e4);
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import iconv from "iconv-lite";
|
||||
|
||||
import { encodeBitmap } from "./_bitmap";
|
||||
import { encodeCar } from "./_car";
|
||||
import { encodeChara } from "./_chara";
|
||||
import { encodeMission } from "./_mission";
|
||||
import { LoadProfileResponse3 } from "../response/loadProfile";
|
||||
import { writeSjisStr } from "../../util/bin";
|
||||
|
||||
export function loadProfile3(res: LoadProfileResponse3) {
|
||||
const buf = Buffer.alloc(0x0ea0);
|
||||
@@ -87,7 +86,7 @@ export function loadProfile3(res: LoadProfileResponse3) {
|
||||
buf.writeUInt32LE(res.settings.pack, 0x04b4);
|
||||
buf.writeUInt32LE(res.dpoint, 0x04c4);
|
||||
buf.writeUInt32LE(res.fame, 0x04e0);
|
||||
iconv.encode(res.name + "\0", "shift_jis").copy(buf, 0x04ca);
|
||||
writeSjisStr(buf, 0x04ca, 0x04ea, res.name);
|
||||
buf.writeUInt8(res.story.y, 0x080c);
|
||||
buf.writeUInt16LE(res.story.x, 0x0828);
|
||||
encodeMission(res.missions.solo).copy(buf, 0x0858);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import iconv from "iconv-lite";
|
||||
|
||||
import { writeSjisStr } from "../../util/bin";
|
||||
import { LoadTopTenResponse } from "../response/loadTopTen";
|
||||
|
||||
export function loadTopTen(res: LoadTopTenResponse): Buffer {
|
||||
@@ -49,9 +48,9 @@ export function loadTopTen(res: LoadTopTenResponse): Buffer {
|
||||
buf.writeUInt8(row.field_0E ? 1 : 0, innerOff + 0x000e); // Boolean
|
||||
buf.writeUInt8(row.field_0F ? 1 : 0, innerOff + 0x000f); // Boolean
|
||||
buf.writeUInt8(row.field_10, innerOff + 0x0010);
|
||||
iconv.encode(row.driverName, "shift_jis").copy(buf, innerOff + 0x0014);
|
||||
iconv.encode(row.team.name, "shift_jis").copy(buf, innerOff + 0x0028);
|
||||
iconv.encode(row.shopName, "shift_jis").copy(buf, innerOff + 0x0048);
|
||||
writeSjisStr(buf, innerOff + 0x0014, innerOff + 0x0028, row.driverName);
|
||||
writeSjisStr(buf, innerOff + 0x0028, innerOff + 0x0048, row.team.name);
|
||||
writeSjisStr(buf, innerOff + 0x0048, innerOff + 0x0074, row.shopName);
|
||||
buf.writeUInt32LE(row.team.nameBg, innerOff + 0x0074);
|
||||
buf.writeUInt16LE(row.team.nameFx, innerOff + 0x0078);
|
||||
buf.writeUInt8(row.field_7C, innerOff + 0x007c);
|
||||
@@ -70,7 +69,7 @@ export function loadTopTen(res: LoadTopTenResponse): Buffer {
|
||||
buf.writeUInt8(trailer.courseId, offset + 0x02);
|
||||
buf.writeUInt8(trailer.isNight ? 1 : 0, offset + 0x03);
|
||||
buf.writeUInt32LE(trailer.totalMsec, offset + 0x04);
|
||||
iconv.encode(trailer.name, "shift_jis").copy(buf, offset + 0x08);
|
||||
writeSjisStr(buf, offset + 0x08, offset + 0x1c, trailer.name);
|
||||
} else {
|
||||
buf.writeUInt8(0xff, offset + 0x02);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import iconv from "iconv-lite";
|
||||
|
||||
import { UpdateProvisionalStoreRankResponse } from "../response/updateProvisionalStoreRank";
|
||||
import { writeSjisStr } from "../../util/bin";
|
||||
|
||||
export function updateProvisionalStoreRank(
|
||||
res: UpdateProvisionalStoreRankResponse
|
||||
@@ -16,8 +15,8 @@ export function updateProvisionalStoreRank(
|
||||
if (row !== undefined) {
|
||||
buf.writeInt16LE(row.field_0000, offset + 0x0000);
|
||||
buf.writeInt32LE(row.field_0004, offset + 0x0004);
|
||||
iconv.encode(row.field_0010, "shift_jis").copy(buf, offset + 0x0010);
|
||||
iconv.encode(row.field_003B, "shift_jis").copy(buf, offset + 0x003b);
|
||||
writeSjisStr(buf, offset + 0x0010, offset + 0x003b, row.field_0010);
|
||||
writeSjisStr(buf, offset + 0x003b, offset + 0x0044, row.field_003B);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user