use of info.ata4.junity.serialize.SerializedFile in project disunity by ata4.
the class AssetUnpack method runSerializedFile.
@Override
protected void runSerializedFile(Path file, SerializedFile asset) {
try {
Path outputDir = PathUtils.removeExtension(file);
if (Files.isRegularFile(outputDir)) {
outputDir = PathUtils.append(outputDir, "_");
}
if (Files.notExists(outputDir)) {
Files.createDirectory(outputDir);
}
try (FileChannel fc = FileChannel.open(file)) {
DataBlock headerBlock = asset.headerBlock();
Path headerFile = outputDir.resolve("header.block");
copyBlock(headerBlock, headerFile, fc);
if (level > 0) {
DataBlock typeTreeBlock = asset.metadata().typeTreeBlock();
Path typeTreeFile = outputDir.resolve("type_tree.block");
copyBlock(typeTreeBlock, typeTreeFile, fc);
DataBlock objectInfoBlock = asset.metadata().objectInfoBlock();
Path objectInfoFile = outputDir.resolve("object_info.block");
copyBlock(objectInfoBlock, objectInfoFile, fc);
DataBlock objectIDBlock = asset.metadata().objectIDBlock();
if (objectIDBlock.length() > 0) {
Path objectIDFile = outputDir.resolve("object_ids.block");
copyBlock(objectIDBlock, objectIDFile, fc);
}
DataBlock fileIdentBlock = asset.metadata().externalsBlock();
Path fileIdentFile = outputDir.resolve("linked_files.block");
copyBlock(fileIdentBlock, fileIdentFile, fc);
} else {
DataBlock metadataBlock = asset.metadataBlock();
Path metadataFile = outputDir.resolve("metadata.block");
copyBlock(metadataBlock, metadataFile, fc);
}
if (level < 2) {
DataBlock objectDataBlock = asset.objectDataBlock();
Path objectDataFile = outputDir.resolve("object_data.block");
copyBlock(objectDataBlock, objectDataFile, fc);
}
}
if (level > 1) {
Path objectDataDir = outputDir.resolve("object_data");
if (Files.notExists(objectDataDir)) {
Files.createDirectory(objectDataDir);
}
for (SerializedObjectData od : asset.objectData()) {
String objectDataName = String.format("%010d", od.id());
Path objectDataFile = objectDataDir.resolve(objectDataName + ".block");
ByteBuffer objectDataBuffer = od.buffer();
objectDataBuffer.rewind();
ByteBufferUtils.save(objectDataFile, objectDataBuffer);
}
}
} catch (IOException ex) {
L.log(Level.WARNING, "Can't unpack asset file " + file, ex);
}
}
use of info.ata4.junity.serialize.SerializedFile in project disunity by ata4.
the class AssetCommand method runFileRecursive.
@Override
protected void runFileRecursive(Path file) {
if (BundleUtils.isBundle(file)) {
// file is a bundle, load serialized files from it
try (BundleReader bundleReader = new BundleReader(file)) {
Bundle bundle = bundleReader.read();
bundle.entries().stream().filter(not(BundleEntry::isLibrary)).filter(not(BundleEntry::isResource)).forEach(uncheck(entry -> {
try (SerializedFileReader reader = new SerializedFileReader(BundleUtils.dataReaderForEntry(entry))) {
SerializedFile serialized = reader.read();
runSerializedFile(file.resolve(entry.name()), serialized);
}
}));
} catch (UncheckedIOException | IOException ex) {
L.log(Level.WARNING, "Can't open asset bundle " + file, ex);
}
} else {
// load file directly
try (SerializedFileReader reader = new SerializedFileReader(file)) {
SerializedFile serialized = reader.read();
runSerializedFile(file, serialized);
} catch (IOException ex) {
L.log(Level.WARNING, "Can't open asset file " + file, ex);
}
}
}
use of info.ata4.junity.serialize.SerializedFile in project disunity by ata4.
the class AssetHeader method tableModel.
@Override
protected TableModel tableModel(SerializedFile serialized) {
SerializedFileHeader header = serialized.header();
TableBuilder table = new TableBuilder();
table.row("Field", "Value");
table.row("metadataSize", header.metadataSize());
table.row("fileSize", header.fileSize());
table.row("version", header.version());
table.row("dataOffset", header.dataOffset());
if (header.version() >= 9) {
table.row("endianness", header.endianness());
}
return new TableModel("Header", table.get());
}
Aggregations