From 8f8da7904122036db9d0d134cb97960e65929f01 Mon Sep 17 00:00:00 2001 From: Daan Vanden Bosch Date: Fri, 13 Sep 2019 22:47:50 +0200 Subject: [PATCH] Up to four .qst headers are now parsed. This fixes parsing of The Value of Money. --- FEATURES.md | 1 - src/core/data_formats/parsing/quest/index.ts | 2 +- src/core/data_formats/parsing/quest/qst.ts | 22 +++++++++++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index b0e108a5..ed76840a 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -136,5 +136,4 @@ Features that are in ***bold italics*** are planned and not yet implemented. - Switch (none door) - Energy Barrier - Teleporter -- [Load Quest](#load-quest): Can't parse quest 4 - [Load Quest](#load-quest): Can't parse quest 125 White Day diff --git a/src/core/data_formats/parsing/quest/index.ts b/src/core/data_formats/parsing/quest/index.ts index 6591f7ab..8207381f 100644 --- a/src/core/data_formats/parsing/quest/index.ts +++ b/src/core/data_formats/parsing/quest/index.ts @@ -21,7 +21,7 @@ import { object_data, ObjectType, pso_id_to_object_type } from "./object_types"; import { parse_qst, QstContainedFile, write_qst } from "./qst"; import { NpcType } from "./npc_types"; -const logger = Logger.get("data_formats/parsing/quest"); +const logger = Logger.get("core/data_formats/parsing/quest"); export type Quest = { readonly id: number; diff --git a/src/core/data_formats/parsing/quest/qst.ts b/src/core/data_formats/parsing/quest/qst.ts index 9b8f3e70..1ae63fa0 100644 --- a/src/core/data_formats/parsing/quest/qst.ts +++ b/src/core/data_formats/parsing/quest/qst.ts @@ -6,7 +6,7 @@ import { ResizableBufferCursor } from "../../cursor/ResizableBufferCursor"; import { WritableCursor } from "../../cursor/WritableCursor"; import { ResizableBuffer } from "../../ResizableBuffer"; -const logger = Logger.get("data_formats/parsing/quest/qst"); +const logger = Logger.get("core/data_formats/parsing/quest/qst"); export type QstContainedFile = { id?: number; @@ -110,13 +110,13 @@ type QstHeader = { size: number; }; -/** - * TODO: Read all headers instead of just the first 2. - */ function parse_headers(cursor: Cursor): QstHeader[] { const headers: QstHeader[] = []; - for (let i = 0; i < 2; ++i) { + let prev_quest_id: number | undefined; + let prev_file_name: string | undefined; + + for (let i = 0; i < 4; ++i) { cursor.seek(4); const quest_id = cursor.u16(); cursor.seek(38); @@ -125,6 +125,18 @@ function parse_headers(cursor: Cursor): QstHeader[] { // Not sure what this is: const file_name_2 = cursor.string_ascii(24, true, true); + if ( + prev_quest_id != undefined && + prev_file_name != undefined && + (quest_id !== prev_quest_id || file_name.slice(0, 5) !== prev_file_name.slice(0, 5)) + ) { + cursor.seek(-88); + break; + } + + prev_quest_id = quest_id; + prev_file_name = file_name; + headers.push({ quest_id, file_name,