Study Box: Updated loader to match new file format specs

This commit is contained in:
Sour 2020-01-01 18:47:13 -05:00
parent 8047fe44bb
commit 18f87ffcc6
2 changed files with 25 additions and 7 deletions

View file

@ -94,6 +94,7 @@ struct RomInfo
struct PageInfo struct PageInfo
{ {
uint32_t LeadInOffset;
uint32_t AudioOffset; uint32_t AudioOffset;
vector<uint8_t> Data; vector<uint8_t> Data;
}; };

View file

@ -63,21 +63,33 @@ bool StudyBoxLoader::LoadStudyBoxTape(vector<uint8_t> studyBoxFile, StudyBoxData
} }
uint32_t prevAudioOffset = 0; uint32_t prevAudioOffset = 0;
uint32_t prevLeadInOffset = 0;
while(data < end - 4) { while(data < end - 4) {
string cc = ReadFourCC(data); string cc = ReadFourCC(data);
if(cc == "PAGE") { if(cc == "PAGE") {
uint32_t pageSize = ReadInt(data); uint32_t pageSize = ReadInt(data);
uint32_t leadInOffset = ReadInt(data);
uint32_t audioOffset = 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 //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"); Log("[Study Box] PAGE chunks must be in the order found on the audio tape");
return false; return false;
} }
if((end - data) >= pageSize - 4) { prevAudioOffset = audioOffset;
vector<uint8_t> pageData = ReadArray(data, pageSize - 4); prevLeadInOffset = leadInOffset;
studyBoxData.Pages.push_back({ audioOffset, pageData });
if((end - data) >= pageSize - 8) {
vector<uint8_t> pageData = ReadArray(data, pageSize - 8);
studyBoxData.Pages.push_back({ leadInOffset, audioOffset, pageData });
} else { } else {
//Invalid size value //Invalid size value
Log("[Study Box] Invalid size value for PAGE chunk"); Log("[Study Box] Invalid size value for PAGE chunk");
@ -87,9 +99,14 @@ bool StudyBoxLoader::LoadStudyBoxTape(vector<uint8_t> studyBoxFile, StudyBoxData
uint32_t size = ReadInt(data); uint32_t size = ReadInt(data);
uint32_t fileType = ReadInt(data); uint32_t fileType = ReadInt(data);
if(fileType == 0) { if(fileType == 0) {
studyBoxData.AudioFile = ReadArray(data, size); if((end - data) >= size - 4) {
//AUDI chunk should be the last in the file studyBoxData.AudioFile = ReadArray(data, size - 4);
break; //AUDI chunk should be the last in the file
break;
} else {
Log("[Study Box] Invalid size value for AUDI chunk");
return false;
}
} else { } else {
//Unsupported audio type //Unsupported audio type
Log("[Study Box] Unsupported audio type: " + std::to_string(fileType)); Log("[Study Box] Unsupported audio type: " + std::to_string(fileType));