Esempio n. 1
0
 public void Deserialize(Packet packet)
 {
     command           = new DrawCmdRec();
     command.nextOfst  = packet.ReadSInt16();
     command.reserved  = packet.ReadSInt16();
     command.drawCmd   = packet.ReadSInt16();
     command.cmdLength = packet.ReadUInt16();
     command.dataOfst  = packet.ReadSInt16();
     command.data      = packet.getData(command.cmdLength, 0, true);
 }
Esempio n. 2
0
        public void DeserializeJSON(string json)
        {
            var jsonResponse = (dynamic)null;

            try
            {
                jsonResponse = (dynamic)JsonConvert.DeserializeObject <JObject>(json);

                command = new DrawCmdRec
                {
                    type  = jsonResponse.type,
                    layer = jsonResponse.layer,
                    data  = ((string)jsonResponse.data ?? string.Empty).ReadPalaceString(),
                };
            }
            catch
            {
            }
        }
        public void Deserialize(Packet inPacket = null)
        {
            NotifyPropertyChanged();
            //isDirty = true;
            HasUnsavedAuthorChanges = true;
            HasUnsavedChanges       = true;

            if (inPacket != null)
            {
                Flush(true);
                _data = new List <byte>(inPacket.getData());
            }

            try
            {
                roomFlags      = ReadSInt32();
                facesID        = ReadSInt32();
                roomID         = ReadSInt16();
                roomNameOfst   = ReadSInt16();
                pictNameOfst   = ReadSInt16();
                artistNameOfst = ReadSInt16();
                passwordOfst   = ReadSInt16();
                nbrHotspots    = ReadSInt16();
                hotspotOfst    = ReadSInt16();
                nbrPictures    = ReadSInt16();
                pictureOfst    = ReadSInt16();
                nbrDrawCmds    = ReadSInt16();
                firstDrawCmd   = ReadSInt16();
                DropBytes(2); //nbrPeople
                nbrLProps  = ReadSInt16();
                firstLProp = ReadSInt16();
                DropBytes(2);
                lenVars = ReadSInt16();

                // Get the strings
                roomName     = PeekPString(32, roomNameOfst);
                roomPicture  = PeekPString(32, pictNameOfst);
                roomArtist   = PeekPString(32, artistNameOfst);
                roomPassword = PeekPString(32, passwordOfst);

                // Paint
                #region Paint

                for (int i = 0; i < nbrDrawCmds; i++)
                {
                    Seek(firstDrawCmd + i * DrawCmdRec.SizeOf);

                    var drawCmd = new DrawCmdRec();
                    drawCmd.nextOfst  = PeekSInt16();
                    drawCmd.reserved  = PeekSInt16();
                    drawCmd.drawCmd   = PeekSInt16();
                    drawCmd.cmdLength = PeekUInt16();
                    drawCmd.dataOfst  = PeekSInt16();
                    drawCmd.data      = _data
                                        .Skip(drawCmd.dataOfst)
                                        .Take(drawCmd.cmdLength)
                                        .ToArray();

                    _drawCmds.Add(drawCmd);
                }

                #endregion

                // Loose Props
                #region Loose Props
                for (int i = 0; i < nbrLProps; i++)
                {
                    Seek(firstLProp + i * LoosePropRec.SizeOf);

                    var prop = new LoosePropRec();
                    prop.nextOfst = PeekSInt16();
                    prop.reserved = PeekSInt16();

                    prop.propSpec     = new AssetSpec();
                    prop.propSpec.id  = PeekSInt32();
                    prop.propSpec.crc = (UInt32)PeekSInt32();
                    prop.flags        = PeekSInt32();
                    prop.refCon       = PeekSInt32();

                    prop.loc   = new Point();
                    prop.loc.v = PeekSInt16();
                    prop.loc.h = PeekSInt16();

                    _looseProps.Add(prop);
                }
                #endregion

                // Pictures
                #region Pictures
                for (int i = 0; i < nbrPictures; i++)
                {
                    Seek(pictureOfst + PictureRec.SizeOf * i);

                    var picture = new PictureRec();
                    picture.refCon      = PeekSInt32();
                    picture.picID       = PeekSInt16();
                    picture.picNameOfst = PeekSInt16();
                    picture.transColor  = PeekSInt16();
                    picture.reserved    = PeekSInt16();

                    if (picture.picNameOfst > 0 && picture.picNameOfst < Count)
                    {
                        picture.name = PeekPString(32, picture.picNameOfst);

                        _pictures.Add(picture);
                    }
                }
                #endregion

                //Hotspots
                #region Hotspots

                for (int i = 0; i < nbrHotspots; i++)
                {
                    Seek(hotspotOfst + HotspotRec.SizeOf * i);

                    var hotspot = new HotspotRec
                    {
                        Vortexes = new List <Point>(),
                        states   = new List <HotspotStateRec>(),
                    };
                    hotspot.scriptEventMask = PeekSInt32();
                    hotspot.flags           = PeekSInt32();
                    hotspot.secureInfo      = PeekSInt32();
                    hotspot.refCon          = PeekSInt32();

                    hotspot.loc   = new Point();
                    hotspot.loc.v = PeekSInt16();
                    hotspot.loc.h = PeekSInt16();

                    hotspot.id             = PeekSInt16();
                    hotspot.dest           = PeekSInt16();
                    hotspot.nbrPts         = PeekSInt16();
                    hotspot.ptsOfst        = PeekSInt16();
                    hotspot.type           = (HotspotTypes)PeekSInt16();
                    hotspot.groupID        = PeekSInt16();
                    hotspot.nbrScripts     = PeekSInt16();
                    hotspot.scriptRecOfst  = PeekSInt16();
                    hotspot.state          = PeekSInt16();
                    hotspot.nbrStates      = PeekSInt16();
                    hotspot.stateRecOfst   = PeekSInt16();
                    hotspot.nameOfst       = PeekSInt16();
                    hotspot.scriptTextOfst = PeekSInt16();
                    hotspot.alignReserved  = PeekSInt16();

                    if (hotspot.nameOfst > 0 && hotspot.nameOfst < Count)
                    {
                        hotspot.name = PeekPString(32, hotspot.nameOfst);
                    }

                    if (hotspot.scriptTextOfst > 0 && hotspot.scriptTextOfst < Count)
                    {
                        hotspot.script = ReadCString(hotspot.scriptTextOfst);
                    }

                    if (hotspot.nbrPts > 0 && hotspot.ptsOfst > 0 && hotspot.ptsOfst < Count - (Point.SizeOf * hotspot.nbrPts))
                    {
                        for (int s = 0; s < hotspot.nbrPts; s++)
                        {
                            Seek(hotspot.ptsOfst + s * Point.SizeOf);

                            var p = new Point();
                            p.v = PeekSInt16();
                            p.h = PeekSInt16();

                            hotspot.Vortexes.Add(p);
                        }
                    }

                    for (int s = 0; s < hotspot.nbrStates; s++)
                    {
                        Seek(hotspot.stateRecOfst + s * HotspotStateRec.SizeOf);

                        var hs = new HotspotStateRec();
                        hs.pictID   = PeekSInt16();
                        hs.reserved = PeekSInt16();

                        hs.picLoc   = new Point();
                        hs.picLoc.v = PeekSInt16();
                        hs.picLoc.h = PeekSInt16();

                        hotspot.states.Add(hs);
                    }

                    _hotspots.Add(hotspot);
                }

                #endregion
            }
            catch (Exception ex)
            {
                ex.DebugLog();
            }
        }