FSO.SimAntics.Marshals.VMMarshal.Deserialize C# (CSharp) Method

Deserialize() public method

public Deserialize ( BinaryReader reader ) : void
reader System.IO.BinaryReader
return void
        public void Deserialize(BinaryReader reader)
        {
            if (new string(reader.ReadChars(4)) != "FSOv") return;

            Version = reader.ReadInt32();
            Compressed = reader.ReadBoolean();

            var uReader = reader;
            MemoryStream cStream = null;
            GZipStream zipStream = null;
            if (Compressed)
            {
                var length = reader.ReadInt32();
                cStream = new MemoryStream(reader.ReadBytes(length));
                zipStream = new GZipStream(cStream, CompressionMode.Decompress);
                reader = new BinaryReader(zipStream);
            }

            Context = new VMContextMarshal();
            Context.Deserialize(reader);

            int ents = reader.ReadInt32();
            Entities = new VMEntityMarshal[ents];
            for (int i=0; i<ents; i++)
            {
                var type = reader.ReadByte();
                var ent = (type == 1) ? (VMEntityMarshal) new VMAvatarMarshal(Version) : new VMGameObjectMarshal(Version);
                ent.Deserialize(reader);
                Entities[i] = ent;
            }

            int thrN = reader.ReadInt32();
            Threads = new VMThreadMarshal[thrN];
            for (int i = 0; i < thrN; i++)
            {
                Threads[i] = new VMThreadMarshal(Version);
                Threads[i].Deserialize(reader);
            }

            int mtgN = reader.ReadInt32();
            MultitileGroups = new VMMultitileGroupMarshal[mtgN];
            for (int i = 0; i < mtgN; i++)
            {
                MultitileGroups[i] = new VMMultitileGroupMarshal();
                MultitileGroups[i].Deserialize(reader);
            }

            int globs = reader.ReadInt32();
            GlobalState = new short[globs];
            for (int i = 0; i < globs; i++)
            {
                GlobalState[i] = reader.ReadInt16();
            }

            //assume TSO for now
            PlatformState = new VMTSOLotState();
            PlatformState.Deserialize(reader);

            ObjectId = reader.ReadInt16();
        }

Usage Example

Example #1
0
        public void BlueprintReset(string path)
        {
            string filename = Path.GetFileName(path);

            try
            {
                using (var file = new BinaryReader(File.OpenRead(Path.Combine(FSOEnvironment.UserDir, "LocalHouse/") + filename.Substring(0, filename.Length - 4) + ".fsov")))
                {
                    var marshal = new FSO.SimAntics.Marshals.VMMarshal();
                    marshal.Deserialize(file);
                    //vm.SendCommand(new VMStateSyncCmd()
                    //{
                    //    State = marshal
                    //});

                    vm.Load(marshal);
                    vm.Reset();
                }
            }
            catch (Exception)
            {
                var floorClip  = Rectangle.Empty;
                var offset     = new Point();
                var targetSize = 0;

                var   isIff    = path.EndsWith(".iff");
                short jobLevel = -1;
                if (isIff)
                {
                    jobLevel = short.Parse(path.Substring(path.Length - 6, 2));
                }
                vm.SendCommand(new VMBlueprintRestoreCmd
                {
                    JobLevel = jobLevel,
                    XMLData  = File.ReadAllBytes(path),
                    IffData  = isIff,

                    FloorClipX      = floorClip.X,
                    FloorClipY      = floorClip.Y,
                    FloorClipWidth  = floorClip.Width,
                    FloorClipHeight = floorClip.Height,
                    OffsetX         = offset.X,
                    OffsetY         = offset.Y,
                    TargetSize      = targetSize
                });
            }

            vm.Tick();

            if (ActiveFamily == null)
            {
                vm.SetGlobalValue(32, 1);
                vm.SpeedMultiplier = -1;
            }
        }
All Usage Examples Of FSO.SimAntics.Marshals.VMMarshal::Deserialize