Example #1
0
        public static ObjectDef Read(NReader rdr)
        {
            ObjectDef ret = new ObjectDef();

            ret.ObjectType = rdr.ReadInt16();
            ret.Stats      = ObjectStats.Read(rdr);
            return(ret);
        }
Example #2
0
 public static ObjectDef Read(NReader rdr)
 {
     ObjectDef ret = new ObjectDef();
     ret.ObjectType = rdr.ReadInt16();
     ret.Stats = ObjectStats.Read(rdr);
     return ret;
 }
        void ProcessSvr()
        {
            try
            {
                var rdr = new NReader(dest.GetStream());
                var wtr = new NWriter(new NetworkStream(skt));
                while (true)
                {
                    int len = rdr.ReadInt32() - 5;
                    byte id = rdr.ReadByte();
                    byte[] content = rdr.ReadBytes(len);

                    wtr.Write(len + 5);
                    wtr.Write((byte)id);
                    wtr.Write(content);

                    svrPkts.Add(new Packet() { id = id, content = SendKey.Crypt(content) });
                }
            }
            catch { }
            finally
            {
                skt.Close();
            }
            JsonMap map = new JsonMap();
            for (var i = 0; i < svrPkts.Count; i++)
            {
                File.WriteAllBytes("svr_pkt/" + i + "_" + svrPkts[i].id, svrPkts[i].content);
                if (svrPkts[i].id == 37)
                {
                    map.Init(IPAddress.NetworkToHostOrder(BitConverter.ToInt32(svrPkts[i].content, 0)),
                        IPAddress.NetworkToHostOrder(BitConverter.ToInt32(svrPkts[i].content, 4)));
                    File.WriteAllBytes("mapinfo.packet", svrPkts[i].content);
                }
                if (svrPkts[i].id == 5)
                {
                    using (NReader rdr = new NReader(new MemoryStream(svrPkts[i].content)))
                    {
                        short count = rdr.ReadInt16();
                        for (var x = 0; x < count; x++)
                        {
                            map.Tiles[rdr.ReadInt16()][rdr.ReadInt16()] = (Tile)rdr.ReadByte();
                        }
                        count = rdr.ReadInt16();
                        for (var x = 0; x < count; x++)
                        {
                            ObjectDef def = ObjectDef.Read(rdr);
                            def.Stats.Position.X -= 0.5F;
                            def.Stats.Position.Y -= 0.5F;
                            if (def.Stats.Position.X == (int)def.Stats.Position.X &&
                                def.Stats.Position.Y == (int)def.Stats.Position.Y)
                            {
                                int _x = (int)def.Stats.Position.X;
                                int _y = (int)def.Stats.Position.Y;
                                Array.Resize(ref map.Entities[_x][_y], map.Entities[_x][_y].Length + 1);
                                ObjectDef[] arr = map.Entities[_x][_y];

                                arr[arr.Length - 1] = def;
                            }
                        }
                    }
                }
            }
            File.WriteAllText("map.jm", map.ToJson());
        }