Search in sources :

Example 6 with SerializedFile

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);
    }
}
Also used : Path(java.nio.file.Path) SerializedObjectData(info.ata4.junity.serialize.SerializedObjectData) FileChannel(java.nio.channels.FileChannel) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) DataBlock(info.ata4.util.io.DataBlock)

Example 7 with SerializedFile

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);
        }
    }
}
Also used : RecursiveFileCommand(info.ata4.disunity.cli.command.RecursiveFileCommand) LogUtils(info.ata4.log.LogUtils) IOConsumer.uncheck(info.ata4.util.function.IOConsumer.uncheck) IOException(java.io.IOException) Logger(java.util.logging.Logger) BundleUtils(info.ata4.junity.bundle.BundleUtils) SerializedFile(info.ata4.junity.serialize.SerializedFile) Predicates.not(info.ata4.util.function.Predicates.not) Level(java.util.logging.Level) BundleEntry(info.ata4.junity.bundle.BundleEntry) UncheckedIOException(java.io.UncheckedIOException) Bundle(info.ata4.junity.bundle.Bundle) SerializedFileReader(info.ata4.junity.serialize.SerializedFileReader) BundleReader(info.ata4.junity.bundle.BundleReader) Path(java.nio.file.Path) SerializedFileReader(info.ata4.junity.serialize.SerializedFileReader) SerializedFile(info.ata4.junity.serialize.SerializedFile) Bundle(info.ata4.junity.bundle.Bundle) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) BundleEntry(info.ata4.junity.bundle.BundleEntry) BundleReader(info.ata4.junity.bundle.BundleReader)

Example 8 with SerializedFile

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());
}
Also used : TableBuilder(info.ata4.disunity.cli.util.TableBuilder) SerializedFileHeader(info.ata4.junity.serialize.SerializedFileHeader) TableModel(info.ata4.disunity.cli.util.TableModel)

Aggregations

TableBuilder (info.ata4.disunity.cli.util.TableBuilder)5 TableModel (info.ata4.disunity.cli.util.TableModel)5 Formatters (info.ata4.disunity.cli.util.Formatters)2 TextTableFormat (info.ata4.disunity.cli.util.TextTableFormat)2 SerializedFile (info.ata4.junity.serialize.SerializedFile)2 DataBlock (info.ata4.util.io.DataBlock)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Parameters (com.beust.jcommander.Parameters)1 RecursiveFileCommand (info.ata4.disunity.cli.command.RecursiveFileCommand)1 TablePrinter (info.ata4.disunity.cli.util.TablePrinter)1 Bundle (info.ata4.junity.bundle.Bundle)1 BundleEntry (info.ata4.junity.bundle.BundleEntry)1 BundleReader (info.ata4.junity.bundle.BundleReader)1 BundleUtils (info.ata4.junity.bundle.BundleUtils)1 SerializedFileHeader (info.ata4.junity.serialize.SerializedFileHeader)1 SerializedFileMetadata (info.ata4.junity.serialize.SerializedFileMetadata)1 SerializedFileReader (info.ata4.junity.serialize.SerializedFileReader)1 SerializedObjectData (info.ata4.junity.serialize.SerializedObjectData)1 FileIdentifier (info.ata4.junity.serialize.fileidentifier.FileIdentifier)1