From b64052ff748fed6fa1fa5468492db7d9fc051b67 Mon Sep 17 00:00:00 2001 From: George Wu Date: Wed, 15 Apr 2020 16:26:06 +0200 Subject: [PATCH] Fixed external ACB extraction in CAcbFile::OpenDataStream() --- src/lib/ichinose/CAcbFile.cpp | 8 ++++---- src/lib/ichinose/CAfs2Archive.cpp | 22 ++++++++++++++-------- src/lib/ichinose/CAfs2Archive.h | 2 ++ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/lib/ichinose/CAcbFile.cpp b/src/lib/ichinose/CAcbFile.cpp index c6b22b1..e6e8d4a 100644 --- a/src/lib/ichinose/CAcbFile.cpp +++ b/src/lib/ichinose/CAcbFile.cpp @@ -33,10 +33,11 @@ CAcbFile::CAcbFile(IStream *stream, uint64_t streamOffset, const char *fileName) _internalAwb = nullptr; _externalAwb = nullptr; _fileName = fileName; + _formatVersion = 0; } CAcbFile::~CAcbFile() { - for (auto pair : _tables) { + for (const auto &pair : _tables) { delete pair.second; } @@ -303,9 +304,7 @@ IStream *CAcbFile::GetDataStreamFromCueInfo(const ACB_CUE_RECORD &cue, const cha auto &file = files.at(cue.waveformId); - CFileStream fs(file.fileName, FileMode::OpenExisting, FileAccess::Read); - - result = CAcbHelper::ExtractToNewStream(&fs, file.fileOffsetAligned, static_cast(file.fileSize)); + result = CAcbHelper::ExtractToNewStream(externalAwb->GetStream(), file.fileOffsetAligned, static_cast(file.fileSize)); } else { auto internalAwb = _internalAwb; @@ -389,6 +388,7 @@ static string GetExtensionForEncodeType(uint8_t encodeType) { case CGSS_ACB_WAVEFORM_ADX: return ".adx"; case CGSS_ACB_WAVEFORM_HCA: + case CGSS_ACB_WAVEFORM_HCA2: return ".hca"; case CGSS_ACB_WAVEFORM_VAG: return ".vag"; diff --git a/src/lib/ichinose/CAfs2Archive.cpp b/src/lib/ichinose/CAfs2Archive.cpp index 6d0d841..984ae30 100644 --- a/src/lib/ichinose/CAfs2Archive.cpp +++ b/src/lib/ichinose/CAfs2Archive.cpp @@ -13,6 +13,9 @@ CAfs2Archive::CAfs2Archive(cgss::IStream *stream, uint64_t offset, const char *f _stream = stream; _streamOffset = offset; _disposeStream = disposeStream; + _byteAlignment = 0; + _version = 0; + _hcaKeyModifier = 0; const auto fileNameLength = strlen(fileName); _fileName = new char[fileNameLength + 1]; @@ -54,7 +57,6 @@ bool_t CAfs2Archive::IsAfs2Archive(IStream *stream, uint64_t offset) { void CAfs2Archive::Initialize() { auto stream = _stream; auto offset = _streamOffset; - auto acbFileName = _fileName; if (!IsAfs2Archive(stream, offset)) { throw CFormatException("The file is not a valid AFS2 archive."); @@ -62,20 +64,20 @@ void CAfs2Archive::Initialize() { CBinaryReader reader(stream); - auto fileCount = reader.PeekInt32LE(offset + 8); + const auto version = reader.PeekUInt32LE(offset + 4); + _version = version; + + const auto fileCount = reader.PeekInt32LE(offset + 8); - if (fileCount > 65535) { + if (fileCount > UINT16_MAX) { throw CFormatException("File count exceeds max file entries."); } - auto byteAlignment = reader.PeekUInt32LE(offset + 12); + const auto byteAlignment = reader.PeekUInt32LE(offset + 12); _byteAlignment = byteAlignment & 0xffff; _hcaKeyModifier = static_cast(byteAlignment >> 16); - auto version = reader.PeekUInt32LE(offset + 4); - _version = version; - - auto offsetFieldSize = (version >> 8) & 0xff; + const auto offsetFieldSize = (version >> 8) & 0xff; uint32_t offsetMask = 0; for (auto i = 0; i < offsetFieldSize; ++i) { @@ -120,6 +122,10 @@ uint32_t CAfs2Archive::GetVersion() const { return _version; } +IStream *CAfs2Archive::GetStream() const { + return _stream; +} + uint32_t CAfs2Archive::GetByteAlignment() const { return _byteAlignment; } diff --git a/src/lib/ichinose/CAfs2Archive.h b/src/lib/ichinose/CAfs2Archive.h index 4595f76..1c6b98f 100644 --- a/src/lib/ichinose/CAfs2Archive.h +++ b/src/lib/ichinose/CAfs2Archive.h @@ -22,6 +22,8 @@ CGSS_NS_BEGIN const std::map &GetFiles() const; + IStream *GetStream() const; + uint32_t GetByteAlignment() const; uint32_t GetVersion() const;