Skip to content

Commit

Permalink
Fixed external ACB extraction in CAcbFile::OpenDataStream()
Browse files Browse the repository at this point in the history
  • Loading branch information
hozuki committed Apr 15, 2020
1 parent 8e4624d commit b64052f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/lib/ichinose/CAcbFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<uint32_t>(file.fileSize));
result = CAcbHelper::ExtractToNewStream(externalAwb->GetStream(), file.fileOffsetAligned, static_cast<uint32_t>(file.fileSize));
} else {
auto internalAwb = _internalAwb;

Expand Down Expand Up @@ -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";
Expand Down
22 changes: 14 additions & 8 deletions src/lib/ichinose/CAfs2Archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -54,28 +57,27 @@ 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.");
}

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<uint16_t>(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) {
Expand Down Expand Up @@ -120,6 +122,10 @@ uint32_t CAfs2Archive::GetVersion() const {
return _version;
}

IStream *CAfs2Archive::GetStream() const {
return _stream;
}

uint32_t CAfs2Archive::GetByteAlignment() const {
return _byteAlignment;
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/ichinose/CAfs2Archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ CGSS_NS_BEGIN

const std::map<uint32_t, AFS2_FILE_RECORD> &GetFiles() const;

IStream *GetStream() const;

uint32_t GetByteAlignment() const;

uint32_t GetVersion() const;
Expand Down

0 comments on commit b64052f

Please sign in to comment.