public override BinaryClassChunk Serialize()
        {
            BinaryClassChunk binaryClassChunk = base.Serialize();

            binaryClassChunk.AddProperty("direction", (object)this.direction);
            return(binaryClassChunk);
        }
        private Array DeserializeArray(System.Type type, System.Type arrayType, BitBuffer data)
        {
            int   num      = this._data.ReadInt();
            Array instance = Activator.CreateInstance(type, (object)num) as Array;

            for (int index = 0; index < num; ++index)
            {
                bool   flag = this._data.ReadBool();
                object obj  = (object)null;
                if (flag)
                {
                    if (typeof(BinaryClassChunk).IsAssignableFrom(arrayType))
                    {
                        BinaryClassChunk binaryClassChunk = BinaryClassChunk.DeserializeHeader(arrayType, this._data, root: false, skipData: true);
                        binaryClassChunk?.Deserialize();
                        obj = (object)binaryClassChunk;
                    }
                    else
                    {
                        obj = this._data.Read(arrayType);
                    }
                }
                instance.SetValue(obj, index);
            }
            return(instance);
        }
        public object GetProperty(string id, bool multiple = false)
        {
            if (this._extraProperties == null)
            {
                return((object)null);
            }
            List <object> list = (List <object>)null;

            this._extraProperties.TryGetValue(id, out list);
            if (list != null)
            {
                foreach (object obj in list)
                {
                    if (obj is BinaryClassChunk)
                    {
                        BinaryClassChunk binaryClassChunk = obj as BinaryClassChunk;
                        if (binaryClassChunk._result == DeserializeResult.HeaderDeserialized)
                        {
                            binaryClassChunk.Deserialize();
                        }
                    }
                    if (obj is BitBuffer)
                    {
                        (obj as BitBuffer).SeekToStart();
                    }
                    if (!multiple)
                    {
                        return(obj);
                    }
                }
            }
            return((object)list);
        }
        public override BinaryClassChunk Serialize()
        {
            BinaryClassChunk binaryClassChunk = base.Serialize();

            binaryClassChunk.AddProperty("contains", (object)MysteryGun.SerializeTypeProb(this.contains));
            return(binaryClassChunk);
        }
        public static T FromData <T>(BitBuffer data) where T : BinaryClassChunk
        {
            BinaryClassChunk instance = Activator.CreateInstance(typeof(T), (object[])null) as BinaryClassChunk;

            instance.SetData(data);
            return((T)instance);
        }
 public override bool Deserialize(BinaryClassChunk node)
 {
     base.Deserialize(node);
     this.fireDirection = node.GetProperty <float>("fireDirection");
     this.firePower     = node.GetProperty <float>("firePower");
     return(true);
 }
        public override BinaryClassChunk Serialize()
        {
            BinaryClassChunk binaryClassChunk = base.Serialize();

            binaryClassChunk.AddProperty("frame", (object)(this.graphic as SpriteMap).frame);
            return(binaryClassChunk);
        }
 public static BinaryClassChunk DeserializeHeader(
     System.Type t,
     BitBuffer data,
     BinaryClassChunk target = null,
     bool root     = true,
     bool skipData = false)
 {
     if (target == null)
     {
         target = Activator.CreateInstance(t, (object[])null) as BinaryClassChunk;
     }
     try
     {
         long num1 = 0;
         if (root)
         {
             num1 = data.ReadLong();
             if (num1 != BinaryClassChunk.MagicNumber(t) && num1 != 5033950674723417L)
             {
                 target._result = DeserializeResult.InvalidMagicNumber;
                 return(target);
             }
             target._checksum = data.ReadUInt();
         }
         ushort num2 = data.ReadUShort();
         ushort num3 = BinaryClassChunk.ChunkVersion(t);
         if ((int)num2 != (int)num3 && (!(target is LevelData) || num2 != (ushort)2))
         {
             target._result = (int)num2 <= (int)num3 ? DeserializeResult.FileVersionTooOld : DeserializeResult.FileVersionTooNew;
             return(target);
         }
         if (num2 == (ushort)2 && target is LevelData && data.ReadBool())
         {
             BinaryClassChunk binaryClassChunk = BinaryClassChunk.DeserializeHeader(Editor.GetType(data.ReadString()), data, root: false);
             if (binaryClassChunk != null && binaryClassChunk._result == DeserializeResult.HeaderDeserialized)
             {
                 binaryClassChunk.Deserialize();
                 target._headerDictionary["metaData"] = binaryClassChunk;
             }
         }
         target._magicNumber = num1;
         target._version     = num2;
         target._size        = data.ReadUInt();
         target._offset      = (uint)data.position;
         target._data        = data;
         target._result      = DeserializeResult.HeaderDeserialized;
         if (skipData)
         {
             data.position = (int)target._offset + (int)target._size;
         }
         return(target);
     }
     catch (Exception ex)
     {
         target._exception = ex;
         target._result    = DeserializeResult.ExceptionThrown;
         return(target);
     }
 }
 public void SetData(BitBuffer data)
 {
     BinaryClassChunk.DeserializeHeader(this.GetType(), data, this);
     if (this._result != DeserializeResult.HeaderDeserialized)
     {
         return;
     }
     this.Deserialize();
 }
Esempio n. 10
0
 public override bool Deserialize(BinaryClassChunk node)
 {
     base.Deserialize(node);
     this.stanceSetting = node.GetProperty <int>("stanceSetting");
     this.contains      = Editor.GetType(node.GetProperty <string>("contains"));
     this.chestPlate    = node.GetProperty <bool>("chestPlate");
     this.helmet        = node.GetProperty <bool>("helmet");
     return(true);
 }
Esempio n. 11
0
        public void SerializeField(BinaryClassChunk element, string name)
        {
            ClassMember member = Editor.GetMember(this.GetType(), name);

            if (member == null)
            {
                return;
            }
            element.AddProperty(name, member.GetValue((object)this));
        }
Esempio n. 12
0
        public override BinaryClassChunk Serialize()
        {
            BinaryClassChunk binaryClassChunk = base.Serialize();

            binaryClassChunk.AddProperty("stanceSetting", (object)this.stanceSetting);
            binaryClassChunk.AddProperty("contains", this.contains != (System.Type)null ? (object)ModLoader.SmallTypeName(this.contains) : (object)"");
            binaryClassChunk.AddProperty("chestPlate", (object)this.chestPlate);
            binaryClassChunk.AddProperty("helmet", (object)this.helmet);
            return(binaryClassChunk);
        }
Esempio n. 13
0
 public bool Deserialize(BinaryClassChunk node)
 {
     this.DeserializeField(node, "trophy");
     this.DeserializeField(node, "bestTime");
     this.DeserializeField(node, "profileID");
     this.DeserializeField(node, "targets");
     this.DeserializeField(node, "goodies");
     this.DeserializeField(node, "frameID");
     this.DeserializeField(node, "frameImage");
     return(true);
 }
Esempio n. 14
0
        public static LevelData LoadLevel(byte[] data)
        {
            LevelData levelData = BinaryClassChunk.FromData <LevelData>(new BitBuffer(data, false));

            if (levelData != null && levelData.GetResult() != DeserializeResult.InvalidMagicNumber)
            {
                return(levelData);
            }
            Promise <LevelData> promise = Tasker.Task <LevelData>((Func <LevelData>)(() => DuckFile.ConvertLevel(data)));

            promise.WaitForComplete();
            return(promise.Result);
        }
Esempio n. 15
0
        public BinaryClassChunk Serialize()
        {
            BinaryClassChunk element = new BinaryClassChunk();

            this.SerializeField(element, "trophy");
            this.SerializeField(element, "bestTime");
            this.SerializeField(element, "profileID");
            this.SerializeField(element, "targets");
            this.SerializeField(element, "goodies");
            this.SerializeField(element, "frameID");
            this.SerializeField(element, "frameImage");
            return(element);
        }
        public override bool Deserialize(BinaryClassChunk node)
        {
            if (!Level.symmetry)
            {
                return(this.DoDeserialize(node));
            }
            Level.leftSymmetry            = true;
            Level.loadingOppositeSymmetry = false;
            this.DoDeserialize(node);
            List <Thing> thingList = new List <Thing>((IEnumerable <Thing>) this._things);

            Level.loadingOppositeSymmetry = true;
            Level.leftSymmetry            = false;
            this.DoDeserialize(node);
            this._things.AddRange((IEnumerable <Thing>)thingList);
            return(true);
        }
Esempio n. 17
0
        public static void SaveChunk(BinaryClassChunk doc, string path)
        {
            DuckFile.CreatePath(Path.GetDirectoryName(path));
            try
            {
                if (File.Exists(path))
                {
                    File.SetAttributes(path, FileAttributes.Normal);
                }
            }
            catch (Exception ex)
            {
            }
            BitBuffer  bitBuffer  = doc.Serialize();
            FileStream fileStream = File.Create(path);

            fileStream.Write(bitBuffer.buffer, 0, bitBuffer.lengthInBytes);
            fileStream.Close();
            DuckFile.SaveCloudFile(path);
        }
        public T GetChunk <T>(string name)
        {
            BinaryClassChunk binaryClassChunk = (BinaryClassChunk)null;

            if (!this._headerDictionary.TryGetValue(name, out binaryClassChunk))
            {
                if (this._data != null)
                {
                    return(default(T));
                }
                binaryClassChunk             = Activator.CreateInstance(typeof(T), (object[])null) as BinaryClassChunk;
                binaryClassChunk._result     = DeserializeResult.Success;
                this._headerDictionary[name] = binaryClassChunk;
            }
            if (binaryClassChunk == null)
            {
                return(default(T));
            }
            if (binaryClassChunk._result == DeserializeResult.HeaderDeserialized)
            {
                binaryClassChunk.Deserialize();
            }
            return((T)(Object)binaryClassChunk);
        }
        public BitBuffer Serialize(BitBuffer data = null, bool root = true)
        {
            if (data == null)
            {
                data = new BitBuffer(false);
            }
            this._serializedData = data;
            if (data.allowPacking)
            {
                throw new Exception("This class does not support serialization with a packed bit buffer. Construct the buffer with allowPacking set to false.");
            }
            System.Type              type1   = this.GetType();
            List <ClassMember>       members = Editor.GetMembers(type1);
            List <BinaryClassMember> binaryClassMemberList = new List <BinaryClassMember>();

            foreach (ClassMember classMember in members)
            {
                if (!classMember.isPrivate && (classMember.type.IsEnum || classMember.type.IsPrimitive || (classMember.type.Equals(typeof(string)) || typeof(BinaryClassChunk).IsAssignableFrom(classMember.type)) || classMember.type.IsArray || classMember.type.IsGenericType && (classMember.type.GetGenericTypeDefinition() == typeof(List <>) || classMember.type.GetGenericTypeDefinition() == typeof(HashSet <>))))
                {
                    object obj = classMember.GetValue((object)this);
                    if (classMember.type.IsEnum)
                    {
                        obj = (object)(int)obj;
                    }
                    if (obj != null)
                    {
                        BinaryClassMember binaryClassMember = new BinaryClassMember()
                        {
                            name = classMember.name,
                            data = obj
                        };
                        binaryClassMemberList.Add(binaryClassMember);
                    }
                }
            }
            if (this._extraProperties != null)
            {
                foreach (KeyValuePair <string, List <object> > extraProperty in (MultiMap <string, object, List <object> >) this._extraProperties)
                {
                    if (extraProperty.Value != null)
                    {
                        foreach (object obj1 in extraProperty.Value)
                        {
                            object obj2 = obj1;
                            if (obj2.GetType().IsEnum)
                            {
                                obj2 = (object)(int)obj2;
                            }
                            BinaryClassMember binaryClassMember = new BinaryClassMember()
                            {
                                name  = "@" + extraProperty.Key,
                                data  = obj2,
                                extra = true
                            };
                            binaryClassMemberList.Add(binaryClassMember);
                        }
                    }
                }
            }
            if (root)
            {
                long val = BinaryClassChunk.MagicNumber(type1);
                data.Write(val);
                data.Write(0U);
            }
            data.Write(BinaryClassChunk.ChunkVersion(type1));
            int position1 = data.position;

            data.Write(0U);
            data.Write((ushort)binaryClassMemberList.Count);
            foreach (BinaryClassMember binaryClassMember in binaryClassMemberList)
            {
                data.Write(binaryClassMember.name);
                if (binaryClassMember.extra)
                {
                    byte        val   = 0;
                    System.Type type2 = binaryClassMember.data.GetType();
                    if (BinaryClassMember.typeMap.TryGetValue(type2, out val))
                    {
                        val = (byte)((int)val << 1 | 1);
                    }
                    data.Write(val);
                    if (val == (byte)0)
                    {
                        data.Write(ModLoader.SmallTypeName(type2));
                    }
                }
                int position2 = data.position;
                data.Write(0U);
                if (binaryClassMember.data is BinaryClassChunk)
                {
                    (binaryClassMember.data as BinaryClassChunk).Serialize(data, false);
                }
                else if (binaryClassMember.data is Array)
                {
                    this.SerializeArray(binaryClassMember.data as Array, binaryClassMember.data.GetType().GetElementType(), data);
                }
                else if (binaryClassMember.data.GetType().IsGenericType&& binaryClassMember.data.GetType().GetGenericTypeDefinition() == typeof(List <>))
                {
                    IList data1 = binaryClassMember.data as IList;
                    Array array = (Array) new object[data1.Count];
                    data1.CopyTo(array, 0);
                    this.SerializeArray(array, binaryClassMember.data.GetType().GetGenericArguments()[0], data);
                }
                else if (binaryClassMember.data.GetType().IsGenericType&& binaryClassMember.data.GetType().GetGenericTypeDefinition() == typeof(HashSet <>))
                {
                    IEnumerable   data1      = binaryClassMember.data as IEnumerable;
                    List <object> objectList = new List <object>();
                    foreach (object obj in data1)
                    {
                        objectList.Add(obj);
                    }
                    object[] array = new object[objectList.Count];
                    objectList.CopyTo(array, 0);
                    this.SerializeArray((Array)array, binaryClassMember.data.GetType().GetGenericArguments()[0], data);
                }
                else
                {
                    data.Write(binaryClassMember.data);
                }
                int position3 = data.position;
                data.position = position2;
                data.Write((uint)(position3 - position2 - 4));
                data.position = position3;
            }
            int position4 = data.position;

            data.position = position1;
            data.Write((uint)(position4 - position1 - 4));
            if (root)
            {
                this._checksum = Editor.Checksum(data.buffer);
                data.position  = 8;
                data.Write(this._checksum);
            }
            data.position = position4;
            return(data);
        }
Esempio n. 20
0
 public static T LoadChunk <T>(string path) where T : BinaryClassChunk
 {
     DuckFile.CreatePath(Path.GetDirectoryName(path));
     DuckFile.PrepareToLoadCloudFile(path);
     return(!File.Exists(path) ? default(T) : BinaryClassChunk.FromData <T>(new BitBuffer(File.ReadAllBytes(path), 0, false)));
 }
        public override BinaryClassChunk Serialize()
        {
            BinaryClassChunk binaryClassChunk = new BinaryClassChunk();

            binaryClassChunk.AddProperty("type", (object)ModLoader.SmallTypeName(this.GetType()));
            binaryClassChunk.AddProperty("blockType", (object)ModLoader.SmallTypeName(this._type));
            BitBuffer bitBuffer1 = new BitBuffer(false);

            bitBuffer1.Write(this._things.Count);
            if (typeof(AutoBlock).IsAssignableFrom(this._type))
            {
                foreach (Thing thing in this._things)
                {
                    AutoBlock autoBlock = thing as AutoBlock;
                    autoBlock.groupedWithNeighbors = false;
                    autoBlock.neighborsInitialized = false;
                }
                BitBuffer bitBuffer2 = new BitBuffer(false);
                bitBuffer2.Write((ushort)0);
                ushort val = 0;
                foreach (Thing thing in this._things)
                {
                    AutoBlock autoBlock = thing as AutoBlock;
                    autoBlock.InitializeNeighbors();
                    bitBuffer1.Write(thing.x);
                    bitBuffer1.Write(thing.y);
                    bitBuffer1.Write((byte)thing.frame);
                    bitBuffer1.Write(autoBlock.upBlock != null ? (short)this._things.IndexOf((Thing)autoBlock.upBlock) : (short)-1);
                    bitBuffer1.Write(autoBlock.downBlock != null ? (short)this._things.IndexOf((Thing)autoBlock.downBlock) : (short)-1);
                    bitBuffer1.Write(autoBlock.rightBlock != null ? (short)this._things.IndexOf((Thing)autoBlock.rightBlock) : (short)-1);
                    bitBuffer1.Write(autoBlock.leftBlock != null ? (short)this._things.IndexOf((Thing)autoBlock.leftBlock) : (short)-1);
                    BlockGroup blockGroup = autoBlock.GroupWithNeighbors(false);
                    if (blockGroup != null)
                    {
                        bitBuffer2.Write(blockGroup.x);
                        bitBuffer2.Write(blockGroup.y);
                        bitBuffer2.Write(blockGroup.collisionOffset.x);
                        bitBuffer2.Write(blockGroup.collisionOffset.y);
                        bitBuffer2.Write(blockGroup.collisionSize.x);
                        bitBuffer2.Write(blockGroup.collisionSize.y);
                        bitBuffer2.Write(blockGroup.blocks.Count <Block>());
                        foreach (Block block in blockGroup.blocks)
                        {
                            bitBuffer2.Write((short)this._things.IndexOf((Thing)block));
                        }
                        ++val;
                    }
                }
                bitBuffer2.position = 0;
                bitBuffer2.Write(val);
                foreach (Thing thing in this._things)
                {
                    AutoBlock autoBlock = thing as AutoBlock;
                    autoBlock.groupedWithNeighbors = false;
                    autoBlock.neighborsInitialized = false;
                }
                if (bitBuffer2.lengthInBytes > 2)
                {
                    binaryClassChunk.AddProperty("groupData", (object)bitBuffer2);
                }
            }
            else
            {
                foreach (Thing thing in this._things)
                {
                    bitBuffer1.Write(thing.x);
                    bitBuffer1.Write(thing.y);
                    bitBuffer1.Write((byte)thing.frame);
                }
            }
            binaryClassChunk.AddProperty("data", (object)bitBuffer1);
            return(binaryClassChunk);
        }
        private bool DoDeserialize(BinaryClassChunk node)
        {
            System.Type type = Editor.GetType(node.GetProperty <string>("blockType"));
            if (type == (System.Type)null)
            {
                return(false);
            }
            bool flag1 = typeof(AutoBlock).IsAssignableFrom(type);

            this._things = new List <Thing>();
            BitBuffer property1 = node.GetProperty <BitBuffer>("data");

            if (!typeof(AutoBlock).IsAssignableFrom(type))
            {
                flag1 = false;
            }
            List <AutoBlock> autoBlockList = new List <AutoBlock>();
            int num1 = property1.ReadInt();

            for (int index = 0; index < num1; ++index)
            {
                float num2  = property1.ReadFloat();
                float num3  = property1.ReadFloat();
                int   num4  = (int)property1.ReadByte();
                bool  flag2 = Level.flipH;
                if (Level.loadingOppositeSymmetry)
                {
                    flag2 = !flag2;
                }
                if (flag2)
                {
                    num2 = (float)(192.0 - (double)num2 - 16.0);
                }
                Thing thing = Editor.CreateThing(type);
                if (flag2 && thing is AutoBlock)
                {
                    (thing as AutoBlock).needsRefresh = true;
                    (thing as AutoBlock).isFlipped    = true;
                }
                if (thing is BackgroundTile)
                {
                    if (flag2)
                    {
                        (thing as BackgroundTile).isFlipped = true;
                    }
                    (thing as BackgroundTile).oppositeSymmetry = !Level.loadingOppositeSymmetry;
                }
                if (flag2 && thing is AutoPlatform)
                {
                    (thing as AutoPlatform).needsRefresh = true;
                }
                thing.x      = num2;
                thing.y      = num3;
                thing.placed = true;
                if (thing.isStatic)
                {
                    this._isStatic = true;
                }
                if (flag1)
                {
                    short     num5      = property1.ReadShort();
                    short     num6      = property1.ReadShort();
                    short     num7      = property1.ReadShort();
                    short     num8      = property1.ReadShort();
                    AutoBlock autoBlock = thing as AutoBlock;
                    autoBlock.northIndex = (int)num5;
                    autoBlock.southIndex = (int)num6;
                    if (flag2)
                    {
                        autoBlock.westIndex = (int)num7;
                        autoBlock.eastIndex = (int)num8;
                    }
                    else
                    {
                        autoBlock.eastIndex = (int)num7;
                        autoBlock.westIndex = (int)num8;
                    }
                    autoBlockList.Add(autoBlock);
                }
                bool flag3 = true;
                if (Level.symmetry)
                {
                    if (Level.leftSymmetry && (double)num2 > 80.0)
                    {
                        flag3 = false;
                    }
                    if (!Level.leftSymmetry && (double)num2 < 96.0)
                    {
                        flag3 = false;
                    }
                }
                if (flag3)
                {
                    thing.frame = num4;
                    this._things.Add(thing);
                }
            }
            if (flag1 && !(Level.current is Editor))
            {
                foreach (AutoBlock autoBlock in autoBlockList)
                {
                    if (autoBlock.northIndex != -1)
                    {
                        autoBlock.upBlock = (Block)autoBlockList[autoBlock.northIndex];
                    }
                    if (autoBlock.southIndex != -1)
                    {
                        autoBlock.downBlock = (Block)autoBlockList[autoBlock.southIndex];
                    }
                    if (autoBlock.eastIndex != -1)
                    {
                        autoBlock.rightBlock = (Block)autoBlockList[autoBlock.eastIndex];
                    }
                    if (autoBlock.westIndex != -1)
                    {
                        autoBlock.leftBlock = (Block)autoBlockList[autoBlock.westIndex];
                    }
                    autoBlock.neighborsInitialized = true;
                }
                BitBuffer property2 = node.GetProperty <BitBuffer>("groupData");
                if (property2 != null)
                {
                    ushort num2 = property2.ReadUShort();
                    int    num3;
                    for (int index1 = 0; index1 < (int)num2; index1 = num3 + 1)
                    {
                        BlockGroup blockGroup = new BlockGroup();
                        blockGroup.position = new Vec2(property2.ReadFloat(), property2.ReadFloat());
                        bool flag2 = Level.flipH;
                        if (Level.loadingOppositeSymmetry)
                        {
                            flag2 = !flag2;
                        }
                        if (flag2)
                        {
                            blockGroup.position.x = (float)(192.0 - (double)blockGroup.position.x - 16.0);
                        }
                        blockGroup.collisionOffset = new Vec2(property2.ReadFloat(), property2.ReadFloat());
                        blockGroup.collisionSize   = new Vec2(property2.ReadFloat(), property2.ReadFloat());
                        float num4 = 88f;
                        if (Level.symmetry)
                        {
                            if (Level.leftSymmetry)
                            {
                                if ((double)blockGroup.left < (double)num4 && (double)blockGroup.right > (double)num4)
                                {
                                    float num5 = blockGroup.right - num4;
                                    float x    = blockGroup.collisionSize.x - num5;
                                    blockGroup.position.x     -= num5;
                                    blockGroup.position.x     += x / 2f;
                                    blockGroup.collisionSize   = new Vec2(x, blockGroup.collisionSize.y);
                                    blockGroup.collisionOffset = new Vec2((float)-((double)x / 2.0), blockGroup.collisionOffset.y);
                                    blockGroup.right           = num4;
                                }
                            }
                            else
                            {
                                num4 = 88f;
                                if ((double)blockGroup.right > (double)num4 && (double)blockGroup.left < (double)num4)
                                {
                                    float num5 = num4 - blockGroup.left;
                                    float x    = blockGroup.collisionSize.x - num5;
                                    blockGroup.position.x     += num5;
                                    blockGroup.position.x     -= x / 2f;
                                    blockGroup.collisionSize   = new Vec2(x, blockGroup.collisionSize.y);
                                    blockGroup.collisionOffset = new Vec2((float)-((double)x / 2.0), blockGroup.collisionOffset.y);
                                    blockGroup.left            = num4;
                                }
                            }
                        }
                        int num6 = property2.ReadInt();
                        for (int index2 = 0; index2 < num6; ++index2)
                        {
                            int index3 = (int)property2.ReadShort();
                            if (index3 >= 0)
                            {
                                AutoBlock autoBlock = autoBlockList[index3];
                                bool      flag3     = true;
                                if (Level.symmetry)
                                {
                                    if (Level.leftSymmetry && (double)autoBlock.x > 80.0)
                                    {
                                        flag3 = false;
                                    }
                                    if (!Level.leftSymmetry && (double)autoBlock.x < 96.0)
                                    {
                                        flag3 = false;
                                    }
                                }
                                if (flag3)
                                {
                                    autoBlock.groupedWithNeighbors = true;
                                    blockGroup.Add((Block)autoBlock);
                                    blockGroup.physicsMaterial = autoBlock.physicsMaterial;
                                    blockGroup.thickness       = autoBlock.thickness;
                                }
                                this._things.Remove((Thing)autoBlock);
                            }
                        }
                        num3 = index1 + num6;
                        if (flag2)
                        {
                            blockGroup.needsRefresh = true;
                        }
                        if (Level.symmetry)
                        {
                            if (Level.leftSymmetry && (double)blockGroup.left < (double)num4)
                            {
                                this._things.Add((Thing)blockGroup);
                            }
                            else if (!Level.leftSymmetry && (double)blockGroup.right > (double)num4)
                            {
                                this._things.Add((Thing)blockGroup);
                            }
                        }
                        else
                        {
                            this._things.Add((Thing)blockGroup);
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 23
0
 public void DeserializeField(BinaryClassChunk node, string name) => Editor.GetMember(this.GetType(), name)?.SetValue((object)this, node.GetProperty(name));
 public override bool Deserialize(BinaryClassChunk node)
 {
     base.Deserialize(node);
     this.contains = MysteryGun.DeserializeTypeProb(node.GetProperty <string>("contains"));
     return(true);
 }
 public void Add(BinaryClassChunk obj) => this.objects.Add(obj);
 public bool Deserialize()
 {
     if (this._data == null)
     {
         this._result = DeserializeResult.NoData;
         return(false);
     }
     if (this._result == DeserializeResult.Success)
     {
         return(true);
     }
     try
     {
         this._data.position = (int)this._offset;
         ushort num1 = this._data.ReadUShort();
         for (int index = 0; index < (int)num1; ++index)
         {
             string      str         = this._data.ReadString();
             ClassMember classMember = (ClassMember)null;
             System.Type key         = (System.Type)null;
             if (str.StartsWith("@"))
             {
                 if (this._extraProperties == null)
                 {
                     this._extraProperties = new MultiMap <string, object>();
                 }
                 byte num2 = this._data.ReadByte();
                 if (((int)num2 & 1) != 0)
                 {
                     byte num3 = (byte)((uint)num2 >> 1);
                     BinaryClassMember.typeMap.TryGetKey(num3, out key);
                 }
                 else
                 {
                     key = Editor.GetType(this._data.ReadString());
                 }
                 str = str.Substring(1, str.Length - 1);
             }
             else
             {
                 classMember = Editor.GetMember(this.GetType(), str);
                 if (classMember != null)
                 {
                     key = classMember.type;
                 }
             }
             uint num4 = this._data.ReadUInt();
             if (key != (System.Type)null)
             {
                 int position = this._data.position;
                 if (typeof(BinaryClassChunk).IsAssignableFrom(key))
                 {
                     BinaryClassChunk binaryClassChunk = BinaryClassChunk.DeserializeHeader(key, this._data, root: false);
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, (object)binaryClassChunk);
                     }
                     else
                     {
                         this._headerDictionary[str] = binaryClassChunk;
                     }
                     this._data.position = position + (int)num4;
                 }
                 else if (key.IsArray)
                 {
                     Array array = this.DeserializeArray(key, key.GetElementType(), this._data);
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, (object)array);
                     }
                     else
                     {
                         classMember.SetValue((object)this, (object)array);
                     }
                 }
                 else if (key.IsGenericType && key.GetGenericTypeDefinition() == typeof(List <>))
                 {
                     Array array    = this.DeserializeArray(typeof(object[]), key.GetGenericArguments()[0], this._data);
                     IList instance = Activator.CreateInstance(key) as IList;
                     foreach (object obj in array)
                     {
                         instance.Add(obj);
                     }
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, (object)instance);
                     }
                     else
                     {
                         classMember.SetValue((object)this, (object)instance);
                     }
                 }
                 else if (key.IsGenericType && key.GetGenericTypeDefinition() == typeof(HashSet <>))
                 {
                     Array array     = this.DeserializeArray(typeof(object[]), key.GetGenericArguments()[0], this._data);
                     IList instance1 = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(key.GetGenericArguments()[0]));
                     foreach (object obj in array)
                     {
                         instance1.Add(obj);
                     }
                     object instance2 = Activator.CreateInstance(key, (object)instance1);
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, instance2);
                     }
                     else
                     {
                         classMember.SetValue((object)this, instance2);
                     }
                 }
                 else
                 {
                     object element = !key.IsEnum ? this._data.Read(key, false) : (object)this._data.ReadInt();
                     if (classMember == null)
                     {
                         this._extraProperties.Add(str, element);
                     }
                     else
                     {
                         classMember.SetValue((object)this, element);
                     }
                 }
             }
             else
             {
                 this._data.position += (int)num4;
             }
         }
     }
     catch (Exception ex)
     {
         this._exception = ex;
         this._result    = DeserializeResult.ExceptionThrown;
         return(false);
     }
     this._result = DeserializeResult.Success;
     return(true);
 }
 public override bool Deserialize(BinaryClassChunk node)
 {
     base.Deserialize(node);
     this.direction = node.GetProperty <int>("direction");
     return(true);
 }
 public static long MagicNumber <T>() => BinaryClassChunk.MagicNumber(typeof(T));
 public override bool Deserialize(BinaryClassChunk node)
 {
     base.Deserialize(node);
     (this.graphic as SpriteMap).frame = node.GetProperty <int>("frame");
     return(true);
 }
 public static ushort ChunkVersion <T>() => BinaryClassChunk.ChunkVersion(typeof(T));