Ejemplo n.º 1
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.º 2
0
            public override void Read(CGameCtnMacroBlockInfo n, GameBoxReader r, GameBoxWriter unknownW)
            {
                Version = r.ReadInt32();

                n.AnchoredObjects = r.ReadArray(i =>
                {
                    var v = r.ReadInt32();

                    var itemModel = r.ReadIdent();

                    Vec3 pitchYawRoll  = default;
                    Vec3 pivotPosition = default;
                    float scale        = 1;

                    if (v < 3)
                    {
                        var quarterY = r.ReadByte();

                        if (v != 0)
                        {
                            var additionalDir = r.ReadByte();
                        }
                    }
                    else
                    {
                        pitchYawRoll = r.ReadVec3();
                    }

                    var blockCoord = r.ReadInt3();
                    var lookback   = r.ReadId();
                    var pos        = r.ReadVec3();

                    if (v < 5)
                    {
                        r.ReadInt32();
                    }
                    if (v < 6)
                    {
                        r.ReadInt32();
                    }
                    if (v >= 6)
                    {
                        r.ReadInt16(); // 0
                    }
                    if (v >= 7)
                    {
                        pivotPosition = r.ReadVec3();
                    }
                    if (v >= 8)
                    {
                        r.ReadNodeRef(); // probably waypoint
                    }
                    if (v >= 9)
                    {
                        scale = r.ReadSingle(); // 1
                    }
                    if (v >= 10)
                    {
                        r.ReadArray <int>(3); // 0 1 -1
                    }
                    return(new CGameCtnAnchoredObject()
                    {
                        ItemModel = itemModel,
                        PitchYawRoll = pitchYawRoll,
                        BlockUnitCoord = (Byte3)blockCoord,
                        AbsolutePositionInMap = pos,
                        PivotPosition = pivotPosition,
                        Scale = scale,
                    });
                });

                var num = r.ReadInt32();

                if (num == 1)
                {
                    r.ReadInt32();
                    r.ReadInt32();
                }
            }