idz: Use string I/O helpers

This commit is contained in:
Tau
2021-02-03 23:43:37 +00:00
committed by Tau
parent 8291994c93
commit 3d0bdf25d4
13 changed files with 36 additions and 45 deletions
+5 -6
View File
@@ -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);
+2 -3
View File
@@ -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);
+2 -3
View File
@@ -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);
+2 -3
View File
@@ -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);
+5 -6
View File
@@ -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);
}
}