Skip to content

Commit

Permalink
added wta, wtp version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHeitmann committed Sep 6, 2024
1 parent 7b217ea commit 507d170
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/fileTypeUtils/audio/bnkIO.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import 'dart:typed_data';

import '../../utils/utils.dart';
import '../utils/ByteDataWrapper.dart';
import 'wemIdsToNames.dart';

Expand All @@ -29,14 +30,22 @@ abstract class BnkChunkBase extends ChunkBase {
}
}

const _supportedVersion = 72;
class BnkFile extends ChunkWithSize {
List<BnkChunkBase> chunks = [];

BnkFile(this.chunks);

BnkFile.read(ByteDataWrapper bytes) {
while (bytes.position < bytes.length) {
chunks.add(_makeNextChunk(bytes));
var chunk = _makeNextChunk(bytes);
if (chunk is BnkHeader) {
if (chunk.version != _supportedVersion) {
showToast("Warning: BNK version ${chunk.version} is not supported. Expected $_supportedVersion");
throw Exception("Unsupported BNK version ${chunk.version}");
}
}
chunks.add(chunk);
}
}

Expand Down Expand Up @@ -103,7 +112,7 @@ class BnkHeader extends BnkChunkBase {
BnkHeader(super.chunkId, super.chunkSize, this.version, this.bnkId, this.languageId, this.isFeedbackInBnk, this.padding, [this.unknown]);

BnkHeader.read(ByteDataWrapper bytes) : super.read(bytes) {
if (chunkSize > 30) {
if (chunkSize > 32) {
bytes.endian = Endian.big;
bytes.position -= 4;
chunkSize = bytes.readUint32();
Expand Down
5 changes: 4 additions & 1 deletion lib/stateManagement/openFiles/types/WtaWtpData.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class WtaWtpTextures with HasUuid, Undoable implements Disposable {

static Future<WtaWtpTextures> fromWtaWtp(OpenFileId file, String wtaPath, String? wtpPath, String extractDir, bool isWtb) async {
var wta = await WtaFile.readFromFile(wtaPath);
var wtaVersion = wta.header.version;
if (![0, 1].contains(wtaVersion))
showToast("Unexpected WTA version: $wtaVersion (supported: 0, 1)");
var wtpFile = await File(isWtb ? wtaPath : wtpPath!).open();
var textures = ValueListNotifier<WtaTextureEntry>([], fileId: file);
try {
Expand Down Expand Up @@ -214,7 +217,7 @@ class WtaWtpTextures with HasUuid, Undoable implements Disposable {

messageLog.add("Done extracting textures");

return WtaWtpTextures(file, wtaPath, wtpPath, isWtb, wta.header.version, textures, useFlagsSimpleMode, hashAnySimpleModeFlags);
return WtaWtpTextures(file, wtaPath, wtpPath, isWtb, wtaVersion, textures, useFlagsSimpleMode, hashAnySimpleModeFlags);
}

Future<void> save() async {
Expand Down

0 comments on commit 507d170

Please sign in to comment.