Beispiel #1
0
    public byte[]? GetData()
    {
        if (data is not null)
        {
            return(data);
        }

        owner.Stream.Position = owner.DataStart + Offset;

        var roundedDataSize = 8 + CompressedSize;

        if ((roundedDataSize & 7) != 0)
        {
            roundedDataSize = (roundedDataSize & ~7) + 8;
        }

        var buffer = new byte[roundedDataSize];

        owner.Stream.Read(buffer, 0, buffer.Length);

        using var ms = new MemoryStream(buffer);
        using var r  = new GameBoxReader(ms);

        var iv = r.ReadUInt64();

        using var blowfish = new BlowfishCBCStream(ms, owner.Key, iv);

        if (IsCompressed)
        {
            using var deflate = new CompressedStream(blowfish, CompressionMode.Decompress);
            using var rr      = new GameBoxReader(deflate);

            try
            {
                data = rr.ReadBytes(UncompressedSize); // CopyTo nefunguje xd
            }
            catch (InvalidDataException)
            {
            }
        }
        else
        {
            using var rr = new GameBoxReader(blowfish);
            data         = rr.ReadBytes(UncompressedSize); // CopyTo nefunguje xd
        }

        return(data);
    }
Beispiel #2
0
    private void Read(GameBoxReader r)
    {
        if (!r.HasMagic("NadeoPak"))
        {
            throw new Exception("Not a pak file.");
        }

        Version = r.ReadInt32();
        var headerIV = r.ReadUInt64();

        using (blowfish = new BlowfishCBCStream(r.BaseStream, Key, headerIV))
            using (var rr = new GameBoxReader(blowfish))
            {
                ReadEncrypted(rr);
            }
    }
Beispiel #3
0
    private void ReadMetadata()
    {
        Stream.Position = MetadataStart;

        using var reader = new GameBoxReader(Stream);
        var iv = reader.ReadUInt64();

        using (blowfish = new BlowfishCBCStream(Stream, Key, iv))
            using (var deflate = new CompressedStream(blowfish, CompressionMode.Decompress))
                using (var r = new GameBoxReader(deflate))
                {
                    int fileIndex;

                    do
                    {
                        fileIndex = r.ReadInt32();
                        var header = new GameBoxHeaderInfo(r);
                    }while (fileIndex != -1);
                }
    }
Beispiel #4
0
    private void ReadFiles(GameBoxReader r, NadeoPakFolder[] folders)
    {
        var numFiles = r.ReadInt32();
        var files    = new NadeoPakFile[numFiles];

        for (var i = 0; i < numFiles; i++)
        {
            var folderIndex      = r.ReadInt32(); // index into folders
            var name             = r.ReadString();
            var unknown          = r.ReadInt32();
            var uncompressedSize = r.ReadInt32();
            var compressedSize   = r.ReadInt32();
            var offset           = r.ReadInt32();
            var classID          = CMwNod.Remap(r.ReadUInt32()); // indicates the type of the file
            var flags            = r.ReadUInt64();

            var folder = folders.ElementAtOrDefault(folderIndex);

            var file = new NadeoPakFile(this, folder, name, uncompressedSize, compressedSize, offset, classID, flags)
            {
                U01 = unknown
            };

            files[i] = file;

            if (folder == null)
            {
                Files.Add(file);
            }
            else
            {
                folder.Files.Add(file);
            }
        }

        this.files = files;
    }