From 18f87ffcc689b3725839ee38032883433d58dc08 Mon Sep 17 00:00:00 2001 From: Sour Date: Wed, 1 Jan 2020 18:47:13 -0500 Subject: [PATCH] Study Box: Updated loader to match new file format specs --- Core/RomData.h | 1 + Core/StudyBoxLoader.cpp | 31 ++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Core/RomData.h b/Core/RomData.h index c82b1617..20c795b0 100644 --- a/Core/RomData.h +++ b/Core/RomData.h @@ -94,6 +94,7 @@ struct RomInfo struct PageInfo { + uint32_t LeadInOffset; uint32_t AudioOffset; vector Data; }; diff --git a/Core/StudyBoxLoader.cpp b/Core/StudyBoxLoader.cpp index d91498c7..337b8f4b 100644 --- a/Core/StudyBoxLoader.cpp +++ b/Core/StudyBoxLoader.cpp @@ -63,21 +63,33 @@ bool StudyBoxLoader::LoadStudyBoxTape(vector studyBoxFile, StudyBoxData } uint32_t prevAudioOffset = 0; + uint32_t prevLeadInOffset = 0; while(data < end - 4) { string cc = ReadFourCC(data); if(cc == "PAGE") { uint32_t pageSize = ReadInt(data); + uint32_t leadInOffset = ReadInt(data); uint32_t audioOffset = ReadInt(data); - if(audioOffset < prevAudioOffset) { + + if(audioOffset < leadInOffset) { + //Invalid file, lead in must start before the track + Log("[Study Box] Track lead in must start before the first bit of data"); + return false; + } + + if(audioOffset < prevAudioOffset || leadInOffset < prevLeadInOffset) { //Invalid file, page chunks must be in the order found on the tape Log("[Study Box] PAGE chunks must be in the order found on the audio tape"); return false; } - if((end - data) >= pageSize - 4) { - vector pageData = ReadArray(data, pageSize - 4); - studyBoxData.Pages.push_back({ audioOffset, pageData }); + prevAudioOffset = audioOffset; + prevLeadInOffset = leadInOffset; + + if((end - data) >= pageSize - 8) { + vector pageData = ReadArray(data, pageSize - 8); + studyBoxData.Pages.push_back({ leadInOffset, audioOffset, pageData }); } else { //Invalid size value Log("[Study Box] Invalid size value for PAGE chunk"); @@ -87,9 +99,14 @@ bool StudyBoxLoader::LoadStudyBoxTape(vector studyBoxFile, StudyBoxData uint32_t size = ReadInt(data); uint32_t fileType = ReadInt(data); if(fileType == 0) { - studyBoxData.AudioFile = ReadArray(data, size); - //AUDI chunk should be the last in the file - break; + if((end - data) >= size - 4) { + studyBoxData.AudioFile = ReadArray(data, size - 4); + //AUDI chunk should be the last in the file + break; + } else { + Log("[Study Box] Invalid size value for AUDI chunk"); + return false; + } } else { //Unsupported audio type Log("[Study Box] Unsupported audio type: " + std::to_string(fileType));