Ejemplo n.º 1
0
        /// <summary>
        /// Writes the node array that are presented directly and not as a node reference.
        /// </summary>
        /// <typeparam name="T">Type of the node.</typeparam>
        /// <param name="nodes">Node array.</param>
        public void WriteNodes <T>(IEnumerable <T> nodes) where T : CMwNod
        {
            var watch = Stopwatch.StartNew();

            var count = nodes.Count();

            var nodeType = typeof(T);

            Write(count);

            var counter = 0;

            foreach (var node in nodes)
            {
                Write(node.ID);
                node.Write(this);

                string logProgress = $"[{nodeType.FullName.Substring("GBX.NET.Engines".Length + 1).Replace(".", "::")}] {counter + 1}/{count} ({watch.Elapsed.TotalMilliseconds}ms)";
                if (GBX == null || !GBX.ID.HasValue || CMwNod.Remap(GBX.ID.Value) != node.ID)
                {
                    logProgress = "~ " + logProgress;
                }

                Log.Write(logProgress, ConsoleColor.Magenta);

                if (counter != count - 1)
                {
                    Log.Push(node.Chunks.Count + 2);
                }

                counter += 1;
            }
        }
Ejemplo n.º 2
0
        public bool Read(GameBoxReader reader)
        {
            if (reader.HasMagic(GameBox.Magic))
            {
                Log.Write("GBX recognized!", ConsoleColor.Green);
            }
            else
            {
                Log.Write("GBX magic missing! Corrupted file or not a GBX file.", ConsoleColor.Red);
                return(false);
            }

            Version = reader.ReadInt16();
            Log.Write($"- Version: {Version}");

            if (Version >= 3)
            {
                ByteFormat = (char)reader.ReadByte();
                Log.Write($"- Byte format: {ByteFormat}");

                if (ByteFormat == 'T')
                {
                    throw new NotSupportedException("Text-formatted GBX files are not supported.");
                }

                RefTableCompression = (char)reader.ReadByte();
                Log.Write($"- Ref. table compression: {RefTableCompression}");

                BodyCompression = (char)reader.ReadByte();
                Log.Write($"- Body compression: {BodyCompression}");

                if (Version >= 4)
                {
                    UnknownByte = (char)reader.ReadByte();
                    Log.Write($"- Unknown byte: {UnknownByte}");
                }

                ID = CMwNod.Remap(reader.ReadUInt32());
                Log.Write($"- Class ID: 0x{ID:X8}");

                if (Version >= 6)
                {
                    var userDataSize = reader.ReadInt32();
                    Log.Write($"- User data size: {userDataSize / 1024f} kB");

                    if (userDataSize > 0)
                    {
                        UserData = reader.ReadBytes(userDataSize);
                    }
                }

                NumNodes = reader.ReadInt32();
                Log.Write($"- Number of nodes: {NumNodes}");
            }

            Log.Write("Header completed!", ConsoleColor.Green);

            return(true);
        }
Ejemplo n.º 3
0
    /// <exception cref="TextFormatNotSupportedException">Text-formatted GBX files are not supported.</exception>
    internal bool Read(GameBoxReader reader)
    {
        if (!reader.HasMagic(GameBox.Magic))
        {
            Log.Write("GBX magic missing! Corrupted file or not a GBX file.", ConsoleColor.Red);
            return(false);
        }

        Log.Write("GBX recognized!", ConsoleColor.Green);

        Version = reader.ReadInt16();
        Log.Write("- Version: " + Version.ToString());

        if (Version >= 3)
        {
            ByteFormat = (GameBoxByteFormat)reader.ReadByte();
            Log.Write("- Byte format: " + ByteFormat.ToString());

            if (ByteFormat == GameBoxByteFormat.Text)
            {
                throw new TextFormatNotSupportedException();
            }

            CompressionOfRefTable = (GameBoxCompression)reader.ReadByte();
            Log.Write("- Ref. table compression: " + CompressionOfRefTable.ToString());

            CompressionOfBody = (GameBoxCompression)reader.ReadByte();
            Log.Write("- Body compression: " + CompressionOfBody.ToString());

            if (Version >= 4)
            {
                UnknownByte = (char)reader.ReadByte();
                Log.Write("- Unknown byte: " + UnknownByte.ToString());
            }

            ID = CMwNod.Remap(reader.ReadUInt32());
            Log.Write("- Class ID: 0x" + ID.Value.ToString("X8"));

            if (Version >= 6)
            {
                var userDataSize = reader.ReadInt32();
                Log.Write($"- User data size: {(userDataSize / 1024f).ToString()} kB");

                if (userDataSize > 0)
                {
                    UserData = reader.ReadBytes(userDataSize);
                }
            }

            NumNodes = reader.ReadInt32();
            Log.Write("- Number of nodes: " + NumNodes.ToString());
        }

        Log.Write("Header completed!", ConsoleColor.Green);

        return(true);
    }
Ejemplo n.º 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;
    }