From dcb1b59c1ba8d4855f86c49a9557aa6af390e5eb Mon Sep 17 00:00:00 2001 From: Nicholas Estelami Date: Wed, 15 Jun 2022 12:22:21 -0400 Subject: [PATCH] Updated sequence file format and updated resource version to Rachael --- OTRExporter/OTRExporter/AudioExporter.cpp | 15 ++++---- OTRExporter/OTRExporter/Exporter.cpp | 5 +-- OTRExporter/OTRExporter/Exporter.h | 3 +- libultraship/libultraship/Audio.cpp | 31 +++++++++++++--- libultraship/libultraship/Audio.h | 30 +++++++++++----- .../libultraship/Factories/AudioFactory.cpp | 35 ++++++++++++++----- .../libultraship/Factories/AudioFactory.h | 6 ++++ .../libultraship/Factories/ResourceLoader.cpp | 3 ++ libultraship/libultraship/Resource.h | 1 + soh/soh/OTRGlobals.cpp | 19 +++++----- 10 files changed, 107 insertions(+), 41 deletions(-) diff --git a/OTRExporter/OTRExporter/AudioExporter.cpp b/OTRExporter/OTRExporter/AudioExporter.cpp index b15b276fd..ac3fa1869 100644 --- a/OTRExporter/OTRExporter/AudioExporter.cpp +++ b/OTRExporter/OTRExporter/AudioExporter.cpp @@ -30,7 +30,7 @@ void OTRExporter_Audio::WriteSampleEntryReference(ZAudio* audio, SampleEntry* en void OTRExporter_Audio::WriteSampleEntry(SampleEntry* entry, BinaryWriter* writer) { - WriteHeader(nullptr, "", writer, Ship::ResourceType::AudioSample); + WriteHeader(nullptr, "", writer, Ship::ResourceType::AudioSample, Ship::Version::Rachael); writer->Write(entry->codec); writer->Write(entry->medium); @@ -82,7 +82,7 @@ void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWrit { ZAudio* audio = (ZAudio*)res; - WriteHeader(res, outPath, writer, Ship::ResourceType::Audio); + WriteHeader(res, outPath, writer, Ship::ResourceType::Audio, Ship::Version::Rachael); // Write Samples as individual files for (auto pair : audio->samples) @@ -115,7 +115,7 @@ void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWrit MemoryStream* fntStream = new MemoryStream(); BinaryWriter fntWriter = BinaryWriter(fntStream); - WriteHeader(nullptr, "", &fntWriter, Ship::ResourceType::AudioSoundFont); + WriteHeader(nullptr, "", &fntWriter, Ship::ResourceType::AudioSoundFont, Ship::Version::Rachael); fntWriter.Write((uint32_t)i); fntWriter.Write(audio->soundFontTable[i].medium); @@ -174,17 +174,18 @@ void OTRExporter_Audio::Save(ZResource* res, const fs::path& outPath, BinaryWrit MemoryStream* seqStream = new MemoryStream(); BinaryWriter seqWriter = BinaryWriter(seqStream); - seqWriter.Write((uint8_t)0); // Version 0 of format... + WriteHeader(nullptr, "", &seqWriter, Ship::ResourceType::AudioSequence, Ship::Version::Rachael); + + seqWriter.Write((uint32_t)seq.size()); + seqWriter.Write(seq.data(), seq.size()); seqWriter.Write((uint8_t)i); seqWriter.Write((uint8_t)audio->sequenceTable[i].medium); seqWriter.Write((uint8_t)audio->sequenceTable[i].cachePolicy); - seqWriter.Write((uint8_t)audio->fontIndices[i].size()); + seqWriter.Write((uint32_t)audio->fontIndices[i].size()); for (int k = 0; k < audio->fontIndices[i].size(); k++) seqWriter.Write((uint8_t)audio->fontIndices[i][k]); - seqWriter.Write(seq.data(), seq.size()); - std::string fName = OTRExporter_DisplayList::GetPathToRes(res, StringHelper::Sprintf("sequences/%s", audio->seqNames[i].c_str())); AddFile(fName, seqStream->ToVector()); } diff --git a/OTRExporter/OTRExporter/Exporter.cpp b/OTRExporter/OTRExporter/Exporter.cpp index 78c7ed3f4..b8b0612f5 100644 --- a/OTRExporter/OTRExporter/Exporter.cpp +++ b/OTRExporter/OTRExporter/Exporter.cpp @@ -1,7 +1,7 @@ #include "Exporter.h" #include "VersionInfo.h" -void OTRExporter::WriteHeader(ZResource* res, const fs::path& outPath, BinaryWriter* writer, Ship::ResourceType resType) +void OTRExporter::WriteHeader(ZResource* res, const fs::path& outPath, BinaryWriter* writer, Ship::ResourceType resType, Ship::Version resVersion) { writer->Write((uint8_t)Endianess::Little); // 0x00 writer->Write((uint8_t)0); // 0x01 @@ -9,7 +9,8 @@ void OTRExporter::WriteHeader(ZResource* res, const fs::path& outPath, BinaryWri writer->Write((uint8_t)0); // 0x03 writer->Write((uint32_t)resType); // 0x04 - writer->Write((uint32_t)MAJOR_VERSION); // 0x08 + //writer->Write((uint32_t)MAJOR_VERSION); // 0x08 + writer->Write((uint32_t)resVersion); // 0x08 writer->Write((uint64_t)0xDEADBEEFDEADBEEF); // id, 0x0C writer->Write((uint32_t)resourceVersions[resType]); // 0x10 writer->Write((uint64_t)0); // ROM CRC, 0x14 diff --git a/OTRExporter/OTRExporter/Exporter.h b/OTRExporter/OTRExporter/Exporter.h index 45681662a..103617ede 100644 --- a/OTRExporter/OTRExporter/Exporter.h +++ b/OTRExporter/OTRExporter/Exporter.h @@ -4,9 +4,10 @@ //#include "OTRExporter.h" #include #include +#include "VersionInfo.h" class OTRExporter : public ZResourceExporter { protected: - static void WriteHeader(ZResource* res, const fs::path& outPath, BinaryWriter* writer, Ship::ResourceType resType); + static void WriteHeader(ZResource* res, const fs::path& outPath, BinaryWriter* writer, Ship::ResourceType resType, Ship::Version resVersion = MAJOR_VERSION); }; \ No newline at end of file diff --git a/libultraship/libultraship/Audio.cpp b/libultraship/libultraship/Audio.cpp index 4f4668e88..a65fc43d9 100644 --- a/libultraship/libultraship/Audio.cpp +++ b/libultraship/libultraship/Audio.cpp @@ -2,7 +2,30 @@ namespace Ship { - void AudioSampleV1::ParseFileBinary(BinaryReader* reader, Resource* res) + void AudioSequenceV2::ParseFileBinary(BinaryReader* reader, Resource* res) + { + AudioSequence* seq = (AudioSequence*)res; + + ResourceFile::ParseFileBinary(reader, res); + + int seqDataSize = reader->ReadInt32(); + + seq->seqData.reserve(seqDataSize); + + for (int i = 0; i < seqDataSize; i++) + seq->seqData.push_back(reader->ReadUByte()); + + seq->seqNumber = reader->ReadUByte(); + seq->medium = reader->ReadUByte(); + seq->cachePolicy = reader->ReadUByte(); + + int numFonts = reader->ReadInt32(); + + for (int i = 0; i < numFonts; i++) + seq->fonts.push_back(reader->ReadUByte()); + } + + void AudioSampleV2::ParseFileBinary(BinaryReader* reader, Resource* res) { AudioSample* entry = (AudioSample*)res; @@ -36,7 +59,7 @@ namespace Ship entry->book.books.push_back(reader->ReadInt16()); } - void AudioSoundFontV1::ParseFileBinary(BinaryReader* reader, Resource* res) + void AudioSoundFontV2::ParseFileBinary(BinaryReader* reader, Resource* res) { AudioSoundFont* soundFont = (AudioSoundFont*)res; @@ -137,7 +160,7 @@ namespace Ship } } - std::vector AudioSoundFontV1::ReadEnvelopeData(BinaryReader* reader) + std::vector AudioSoundFontV2::ReadEnvelopeData(BinaryReader* reader) { std::vector envelopes; @@ -155,7 +178,7 @@ namespace Ship return envelopes; } - void AudioV1::ParseFileBinary(BinaryReader* reader, Resource* res) + void AudioV2::ParseFileBinary(BinaryReader* reader, Resource* res) { Audio* audio = (Audio*)res; diff --git a/libultraship/libultraship/Audio.h b/libultraship/libultraship/Audio.h index aa063d638..3607a405e 100644 --- a/libultraship/libultraship/Audio.h +++ b/libultraship/libultraship/Audio.h @@ -57,26 +57,43 @@ namespace Ship SoundFontEntry* highNotesSound = nullptr; }; - class AudioSoundFontV1 : public ResourceFile + class AudioSequenceV2 : public ResourceFile { public: void ParseFileBinary(BinaryReader* reader, Resource* res) override; static std::vector ReadEnvelopeData(BinaryReader* reader); }; - class AudioSampleV1 : public ResourceFile + class AudioSoundFontV2 : public ResourceFile + { + public: + void ParseFileBinary(BinaryReader* reader, Resource* res) override; + static std::vector ReadEnvelopeData(BinaryReader* reader); + }; + + class AudioSampleV2 : public ResourceFile { public: void ParseFileBinary(BinaryReader* reader, Resource* res) override; }; - class AudioV1 : public ResourceFile + class AudioV2 : public ResourceFile { public: void ParseFileBinary(BinaryReader* reader, Resource* res) override; }; - struct AudioSoundFont : public Resource + class AudioSequence : public Resource + { + public: + std::vector seqData; + uint8_t seqNumber; + uint8_t medium; + uint8_t cachePolicy; + std::vector fonts; + }; + + class AudioSoundFont : public Resource { public: uint32_t ptr; @@ -110,10 +127,5 @@ namespace Ship class Audio : public Resource { public: - //std::vector soundFontTable; - //std::vector sequenceTable; - //std::vector sampleBankTable; - //std::vector sequences; - //std::vector samples; }; } \ No newline at end of file diff --git a/libultraship/libultraship/Factories/AudioFactory.cpp b/libultraship/libultraship/Factories/AudioFactory.cpp index e4639feae..43214a265 100644 --- a/libultraship/libultraship/Factories/AudioFactory.cpp +++ b/libultraship/libultraship/Factories/AudioFactory.cpp @@ -9,9 +9,9 @@ namespace Ship switch (version) { - case Version::Roy: + case Version::Rachael: { - AudioV1 audioFac = AudioV1(); + AudioV2 audioFac = AudioV2(); audioFac.ParseFileBinary(reader, audio); } break; @@ -30,10 +30,9 @@ namespace Ship switch (version) { - case Version::Deckard: // OTRTODO: Remove this line after we merge in that refactor - case Version::Roy: + case Version::Rachael: { - AudioSampleV1 audioSampleFac = AudioSampleV1(); + AudioSampleV2 audioSampleFac = AudioSampleV2(); audioSampleFac.ParseFileBinary(reader, audioSample); } break; @@ -52,10 +51,9 @@ namespace Ship switch (version) { - case Version::Deckard: // OTRTODO: Remove this line after we merge in that refactor - case Version::Roy: + case Version::Rachael: { - AudioSoundFontV1 audioSFFac = AudioSoundFontV1(); + AudioSoundFontV2 audioSFFac = AudioSoundFontV2(); audioSFFac.ParseFileBinary(reader, audioSF); } break; @@ -66,4 +64,25 @@ namespace Ship return audioSF; } + + AudioSequence* AudioSequenceFactory::ReadAudioSequence(BinaryReader* reader) + { + AudioSequence* audioSeq = new AudioSequence(); + Version version = (Version)reader->ReadUInt32(); + + switch (version) + { + case Version::Rachael: + { + AudioSequenceV2 audioSeqFac = AudioSequenceV2(); + audioSeqFac.ParseFileBinary(reader, audioSeq); + } + break; + default: + // VERSION NOT SUPPORTED + break; + } + + return audioSeq; + } }; \ No newline at end of file diff --git a/libultraship/libultraship/Factories/AudioFactory.h b/libultraship/libultraship/Factories/AudioFactory.h index 40c0c689b..cf9444e27 100644 --- a/libultraship/libultraship/Factories/AudioFactory.h +++ b/libultraship/libultraship/Factories/AudioFactory.h @@ -20,4 +20,10 @@ namespace Ship public: static AudioSoundFont* ReadAudioSoundFont(BinaryReader* reader); }; + + class AudioSequenceFactory + { + public: + static AudioSequence* ReadAudioSequence(BinaryReader* reader); + }; } \ No newline at end of file diff --git a/libultraship/libultraship/Factories/ResourceLoader.cpp b/libultraship/libultraship/Factories/ResourceLoader.cpp index 099d71931..af031c7fd 100644 --- a/libultraship/libultraship/Factories/ResourceLoader.cpp +++ b/libultraship/libultraship/Factories/ResourceLoader.cpp @@ -94,6 +94,9 @@ namespace Ship case ResourceType::AudioSoundFont: result = AudioSoundFontFactory::ReadAudioSoundFont(reader.get()); break; + case ResourceType::AudioSequence: + result = AudioSequenceFactory::ReadAudioSequence(reader.get()); + break; default: // RESOURCE TYPE NOT SUPPORTED break; diff --git a/libultraship/libultraship/Resource.h b/libultraship/libultraship/Resource.h index 7a1e09517..a1be208d0 100644 --- a/libultraship/libultraship/Resource.h +++ b/libultraship/libultraship/Resource.h @@ -33,6 +33,7 @@ namespace Ship Audio = 'OAUD', AudioSample = 'OSMP', AudioSoundFont = 'OSFT', + AudioSequence = 'OSEQ', }; enum class DataType diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 125207a5b..9ef359589 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -569,21 +569,20 @@ extern "C" Vtx* ResourceMgr_LoadVtxByName(const char* path) extern "C" SequenceData ResourceMgr_LoadSeqByName(const char* path) { - auto file = OTRGlobals::Instance->context->GetResourceManager()->LoadFile(path).get(); - - char* data = file->buffer.get(); + auto file = std::static_pointer_cast(OTRGlobals::Instance->context->GetResourceManager() + ->LoadResource(path)); SequenceData seqData; - seqData.seqNumber = data[1]; - seqData.medium = data[2]; - seqData.cachePolicy = data[3]; - seqData.numFonts = data[4]; + seqData.seqNumber = file->seqNumber; + seqData.medium = file->medium; + seqData.cachePolicy = file->cachePolicy; + seqData.numFonts = file->fonts.size(); for (int i = 0; i < seqData.numFonts; i++) - seqData.fonts[i] = data[5 + i]; + seqData.fonts[i] = file->fonts[i]; - seqData.seqData = &data[5 + seqData.numFonts]; - seqData.seqDataSize = file->dwBufferSize - 5 - seqData.numFonts; + seqData.seqData = file->seqData.data(); + seqData.seqDataSize = file->seqData.size(); return seqData; }