Beispiel #1
0
        public ArchiveCodec(string ArchivePath)
        {
            ArchivePath_ = ArchivePath;

            ReadStream_  = new ArchiveReadStream();
            Decoder_     = new ArchiveDecoder(ReadStream_);
            WriteStream_ = new ArchiveWriteStream();
            Encoder_     = new ArchiveEncoder(WriteStream_);
            WriteArchiveCrcConst();
        }
Beispiel #2
0
        private IArchiveInfo ReadFromSubStream(ArchiveReadStream MainStream, Type SubType)
        {
            var SubStream  = MainStream.ReadStream();
            var SubEncoder = new ArchiveDecoder(SubStream);

            SubEncoder.Flush();
            var SubInfo = Activator.CreateInstance(SubType) as IArchiveInfo;

            SubInfo.Decode(SubEncoder);
            return(SubInfo);
        }
Beispiel #3
0
        private (string, object) ReadFromStream(ArchiveReadStream Stream)
        {
            var Key      = Stream.ReadString();
            var DataType = (ArchiveDataType)Stream.ReadInt8();

            switch (DataType)
            {
            case ArchiveDataType.Bool:
                return(Key, Stream.ReadBool());

            case ArchiveDataType.Int8:
                return(Key, Stream.ReadInt8());

            case ArchiveDataType.Int16:
                return(Key, Stream.ReadInt16());

            case ArchiveDataType.Int32:
                return(Key, Stream.ReadInt32());

            case ArchiveDataType.UInt32:
                return(Key, Stream.ReadUInt32());

            case ArchiveDataType.Int64:
                return(Key, Stream.ReadInt64());

            case ArchiveDataType.Float:
                return(Key, Stream.ReadFloat());

            case ArchiveDataType.Double:
                return(Key, Stream.ReadDouble());

            case ArchiveDataType.String:
                return(Key, Stream.ReadString());

            case ArchiveDataType.BigInteger:
                return(Key, Stream.ReadBigInteger());

            case ArchiveDataType.Vector2:
                return(Key, new UnityEngine.Vector2(Stream.ReadFloat(), Stream.ReadFloat()));

            case ArchiveDataType.Vector3:
                return(Key, new UnityEngine.Vector3(Stream.ReadFloat(), Stream.ReadFloat(), Stream.ReadFloat()));

            case ArchiveDataType.Vector2Int:
                return(Key, new UnityEngine.Vector2Int(Stream.ReadInt32(), Stream.ReadInt32()));

            case ArchiveDataType.Vector3Int:
                return(Key, new UnityEngine.Vector3Int(Stream.ReadInt32(), Stream.ReadInt32(), Stream.ReadInt32()));

            case ArchiveDataType.ArrayBool:
                return(Key, Stream.ReadArrayBool());

            case ArchiveDataType.ArrayInt32:
                return(Key, Stream.ReadArrayInt32());

            case ArchiveDataType.Array2Int32:
                return(Key, Stream.ReadArray2Int32());

            case ArchiveDataType.ArrayBigInteger:
                return(Key, Stream.ReadArrayBigInteger());

            case ArchiveDataType.Array2BigInteger:
                return(Key, Stream.ReadArray2BigInteger());

            case ArchiveDataType.ArrayString:
                return(Key, Stream.ReadArrayString());

            case ArchiveDataType.Array:
                var Count = Stream.ReadInt16();
                if (Count == -1)
                {
                    return(Key, null);
                }

                var ArrayT     = Type.GetType(Stream.ReadString());
                var ArrayValue = new object[Count];

                for (var Index = 0; Index < Count; ++Index)
                {
                    if (Stream.ReadBool() == false)
                    {
                        ArrayValue[Index] = default;
                    }
                    else
                    {
                        ArrayValue[Index] = ReadFromSubStream(Stream, ArrayT);
                    }
                }

                return(Key, ArrayValue);

            case ArchiveDataType.Array2:
                var Width = Stream.ReadInt16();
                if (Width == 0)
                {
                    return(Key, null);
                }

                var Height = Stream.ReadInt16();

                var Array2T     = Type.GetType(Stream.ReadString());
                var Array2Value = new object[Width, Height];

                for (var X = 0; X < Width; ++X)
                {
                    for (var Y = 0; Y < Height; ++Y)
                    {
                        if (Stream.ReadBool() == false)
                        {
                            Array2Value[X, Y] = default;
                        }
                        else
                        {
                            Array2Value[X, Y] = ReadFromSubStream(Stream, Array2T);
                        }
                    }
                }

                return(Key, Array2Value);

            case ArchiveDataType.Sub:
                var SubType = Type.GetType(Stream.ReadString());
                return(Key, ReadFromSubStream(Stream, SubType));

            default:
                break;
            }

            return(string.Empty, null);
        }
Beispiel #4
0
 public ArchiveDecoder(ArchiveReadStream Stream)
 {
     Stream_    = Stream;
     CacheList_ = new Dictionary <string, object>();
 }