From 2a365651a8341308a33b38ecd2ed783ccf137a71 Mon Sep 17 00:00:00 2001 From: Tau Date: Wed, 8 May 2019 18:29:49 -0400 Subject: [PATCH] Fix v3 story --- src/idz/db/story.ts | 2 +- src/idz/decoder/saveProfile3.ts | 11 +++++------ src/idz/encoder/loadProfile3.ts | 14 +++++++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/idz/db/story.ts b/src/idz/db/story.ts index 0dd216e..a593afd 100644 --- a/src/idz/db/story.ts +++ b/src/idz/db/story.ts @@ -31,7 +31,7 @@ export class SqlStoryRepository implements FacetRepository { rows: new Array(), }; - for (let i = 0; i < 9; i++) { + for (let i = 0; i < 27; i++) { const row: StoryRow = { cells: new Array() }; for (let j = 0; j < 9; j++) { diff --git a/src/idz/decoder/saveProfile3.ts b/src/idz/decoder/saveProfile3.ts index 48584eb..c7e8c5c 100644 --- a/src/idz/decoder/saveProfile3.ts +++ b/src/idz/decoder/saveProfile3.ts @@ -12,15 +12,15 @@ saveProfile3.msgLen = 0x0a70; export function saveProfile3(buf: Buffer): SaveProfileRequest2 { const storyRows = new Array(); - /* Story seems to have changed somewhat + // Story layout has changed somewhat... - for (let i = 0; i < 9; i++) { + for (let i = 0; i < 27; i++) { const cells = new Array(); - const rowOffset = 0xXXXX + i * 0x3c; + const rowOffset = 0x01ac + i * 0x18; for (let j = 0; j < 9; j++) { - const a = buf.readUInt32LE(rowOffset + 0x04 + j * 4); - const b = buf.readUInt16LE(rowOffset + 0x28 + j * 2); + const a = buf.readUInt8(rowOffset + 0x00 + j); + const b = buf.readUInt8(rowOffset + 0x09 + j); const cell = { a, b }; cells.push(cell); @@ -30,7 +30,6 @@ export function saveProfile3(buf: Buffer): SaveProfileRequest2 { storyRows.push(row); } - */ const coursePlays = new Map(); diff --git a/src/idz/encoder/loadProfile3.ts b/src/idz/encoder/loadProfile3.ts index 1485385..2fd7231 100644 --- a/src/idz/encoder/loadProfile3.ts +++ b/src/idz/encoder/loadProfile3.ts @@ -34,16 +34,20 @@ export function loadProfile3(res: LoadProfileResponse3) { } } - for (let i = 0; i < 9 && i < res.story.rows.length; i++) { + // Not sure it actually goes up to 27, but there seem to be 512 bytes of + // space for story cells, and 27 rows * 19 bytes per row = 513 bytes, which + // is the max that will fit (the final byte of each row is unused). + + for (let i = 0; i < 27 && i < res.story.rows.length; i++) { const row = res.story.rows[i]; - const rowOffset = 0x0256 + i * 0x26; + const rowOffset = 0x0256 + i * 0x13; for (let j = 0; j < 9 && j < row.cells.length; j++) { const cell = row.cells[j]; - const cellOffset = rowOffset + j * 4; + const cellOffset = rowOffset + j * 2; - buf.writeUInt16LE(cell.a, cellOffset + 0); - buf.writeUInt16LE(cell.b, cellOffset + 2); + buf.writeUInt8(cell.a, cellOffset + 0); + buf.writeUInt8(cell.b, cellOffset + 1); } }