Example #1
0
        public byte[] GetDatas()
        {
            var writer = new BigEndianWriter();
            int count  = 0;

            writer.WriteShort((short)_colors.Count);
            foreach (var item in _colors)
            {
                writer.WriteInt(item.Key);
                writer.WriteInt(item.Value);
            }
            writer.WriteShort((short)_scales.Count);
            foreach (var item in _scales)
            {
                writer.WriteInt(item);
            }
            writer.WriteShort((short)_skins.Count);
            foreach (var item in _skins)
            {
                writer.WriteUInt(item);
            }
            writer.WriteShort((short)_subLooks.Count);
            for (int i = 0; i < count; i++)
            {
            }
            writer.WriteUInt(_bonesID);
            writer.WriteByte((byte)_binding);

            return(writer.Data);
        }
Example #2
0
 public override void Serialize(BigEndianWriter writer)
 {
     writer.WriteShort(msgId);
     writer.WriteUInt(timeStamp);
     writer.WriteUTF(owner);
     writer.WriteUInt(objectGenericId);
 }
 public override void Serialize(BigEndianWriter writer)
 {
     writer.WriteInt(memberId);
     writer.WriteShort(rank);
     writer.WriteSByte(experienceGivenPercent);
     writer.WriteUInt(rights);
 }
 public override void Serialize(BigEndianWriter writer)
 {
     writer.WriteShort(msgId);
     writer.WriteUShort((ushort)parameters.Length);
     foreach (var entry in parameters)
     {
         writer.WriteUTF(entry);
     }
     writer.WriteUInt(livingObject);
 }
 public virtual void Serialize(BigEndianWriter writer)
 {
     writer.WriteInt(houseId);
     writer.WriteShort(modelId);
     writer.WriteInt(ownerId);
     writer.WriteUTF(ownerName);
     writer.WriteShort(worldX);
     writer.WriteShort(worldY);
     writer.WriteUInt(price);
     writer.WriteBoolean(isLocked);
 }
Example #6
0
        public void Send(NetworkMessage message, bool encrypt = true)
        {
            BigEndianWriter writer = new BigEndianWriter();

            message.Pack(writer);
            byte[] data = writer.Data;
            if (encrypt)
            {
                writer.Seek(0);
                writer.WriteUInt((uint)writer.Data.Length);
                data = writer.Data;
                this.keyPairEncryption.Encrypt(ref data, 0, writer.Data.Length);
            }
            else
            {
                writer.Seek(0);
                writer.WriteUInt((uint)writer.Data.Length);
            }

            Send(data);
            Console.WriteLine(string.Format("[SND] {0} -> {1}", IP, message));
        }
 public override void Write(BigEndianWriter writer, int mapVersion)
 {
     writer.WriteByte(2);
     writer.WriteUInt((uint)ElementId);
     writer.WriteSByte((sbyte)Hue.Red);
     writer.WriteSByte((sbyte)Hue.Green);
     writer.WriteSByte((sbyte)Hue.Blue);
     writer.WriteSByte((sbyte)Shadow.Red);
     writer.WriteSByte((sbyte)Shadow.Green);
     writer.WriteSByte((sbyte)Shadow.Blue);
     if (mapVersion <= 4)
     {
         writer.WriteSByte((sbyte)OffsetX);
         writer.WriteSByte((sbyte)OffsetY);
     }
     else
     {
         writer.WriteShort((short)(PixelOffsetX));
         writer.WriteShort((short)(PixelOffsetY));
     }
     writer.WriteSByte((sbyte)Altitude);
     writer.WriteUInt((uint)Identifier);
 }
Example #8
0
 public virtual void Serialize(BigEndianWriter writer)
 {
     writer.WriteInt(houseId);
     writer.WriteInt(modelId);
     writer.WriteUTF(ownerName);
     writer.WriteShort(worldX);
     writer.WriteShort(worldY);
     writer.WriteInt(mapId);
     writer.WriteShort(subAreaId);
     writer.WriteUShort((ushort)skillListIds.Length);
     foreach (var entry in skillListIds)
     {
         writer.WriteInt(entry);
     }
     writer.WriteUInt(guildshareParams);
 }
Example #9
0
 public override void Serialize(BigEndianWriter writer)
 {
     base.Serialize(writer);
     writer.WriteSByte(breed);
     writer.WriteBoolean(sex);
     writer.WriteShort(rank);
     writer.WriteDouble(givenExperience);
     writer.WriteSByte(experienceGivenPercent);
     writer.WriteUInt(rights);
     writer.WriteSByte(connected);
     writer.WriteSByte(alignmentSide);
     writer.WriteUShort(hoursSinceLastConnection);
     writer.WriteSByte(moodSmileyId);
     writer.WriteInt(accountId);
     writer.WriteInt(achievementPoints);
     writer.WriteShort(status.TypeId);
     status.Serialize(writer);
 }
Example #10
0
    public void BigEndianIO_TEST()
    {
        for (int i = 0; i <= ushort.MaxValue; ++i)
        {
            ushort value = (ushort)i;
            var    ms    = new MemoryStream();
            BigEndianWriter.WriteUShort(ms, value);
            ushort read1 = BigEndianReader.ReadUShort(ms.ToArray(), 0);
            Assert.AreEqual(read1, value);

            ulong read2 = BigEndianReader.ReadNBytesUnsignedInteger(ms.ToArray(), 2, 0);
            Assert.IsTrue(read2 <= ushort.MaxValue);
            Assert.AreEqual((ushort)read2, value);
        }

        Xorshift random = new Xorshift(Seed);

        for (int i = 0; i < 100000; ++i)
        {
            uint value = random.Generate();
            var  ms    = new MemoryStream();
            BigEndianWriter.WriteUInt(ms, value);
            uint read1 = BigEndianReader.ReadUInt(ms.ToArray(), 0);
            Assert.AreEqual(read1, value);

            ulong read2 = BigEndianReader.ReadNBytesUnsignedInteger(ms.ToArray(), 4, 0);
            Assert.IsTrue(read2 <= uint.MaxValue);
            Assert.AreEqual((uint)read2, value);
        }

        for (int i = 0; i < 100000; ++i)
        {
            ulong value = (ulong)random.Generate() | ((ulong)random.Generate() << 32);
            var   ms    = new MemoryStream();
            BigEndianWriter.WriteULong(ms, value);
            ulong read1 = BigEndianReader.ReadULong(ms.ToArray(), 0);
            Assert.AreEqual(read1, value);

            ulong read2 = BigEndianReader.ReadNBytesUnsignedInteger(ms.ToArray(), 8, 0);
            Assert.AreEqual(read2, value);
        }
    }
Example #11
0
        public void ToSwl()
        {
            var writer = new BigEndianWriter();

            writer.WriteByte(76); //Header
            writer.WriteByte(Version);
            writer.WriteUInt(FrameRate);
            writer.WriteInt(Classes.Count);

            foreach (var classe in Classes)
            {
                writer.WriteUTF(classe);
            }

            writer.WriteBytes(SwfData);

            var swlName = FilePath.Replace(".swf", ".swl");
            var file    = File.Create(swlName);

            file.Write(writer.Data, 0, writer.Data.Length);

            file.Dispose();
            writer.Dispose();
        }
Example #12
0
 public override void Serialize(BigEndianWriter writer)
 {
     writer.WriteBoolean(enable);
     writer.WriteUInt(rights);
 }
Example #13
0
        public void Send(MessagePart part, NetworkDestinationEnum destination)
        {
            ++this.Instance;
            BigEndianWriter bigEndianWriter1 = new BigEndianWriter();
            byte            num1             = part.Data.Length <= (int)ushort.MaxValue ? (part.Data.Length <= (int)byte.MaxValue ? ((uint)part.Data.Length <= 0U ? (byte)0 : (byte)1) : (byte)2) : (byte)3;
            BigEndianWriter bigEndianWriter2 = bigEndianWriter1;
            int?            nullable1        = part.MessageId;
            int?            nullable2        = nullable1.HasValue ? new int?(nullable1.GetValueOrDefault() << 2) : new int?();
            int             num2             = (int)num1;
            int?            nullable3;

            if (!nullable2.HasValue)
            {
                nullable1 = new int?();
                nullable3 = nullable1;
            }
            else
            {
                nullable3 = new int?(nullable2.GetValueOrDefault() | num2);
            }
            nullable1 = nullable3;
            int num3 = (int)(short)nullable1.Value;

            bigEndianWriter2.WriteShort((short)num3);
            if (destination == NetworkDestinationEnum.Server)
            {
                bigEndianWriter1.WriteUInt(this.Instance);
            }
            switch (num1)
            {
            case 1:
                bigEndianWriter1.WriteByte((byte)part.Data.Length);
                break;

            case 2:
                bigEndianWriter1.WriteShort((short)part.Data.Length);
                break;

            case 3:
                bigEndianWriter1.WriteByte((byte)(part.Data.Length >> 16 & (int)byte.MaxValue));
                bigEndianWriter1.WriteShort((short)(part.Data.Length & (int)ushort.MaxValue));
                break;
            }
            bigEndianWriter1.WriteBytes(part.Data);
            if (bigEndianWriter1.Data == null)
            {
                return;
            }
            try
            {
                switch (destination)
                {
                case NetworkDestinationEnum.Client:
                    this.Client.Send(bigEndianWriter1.Data);
                    break;

                case NetworkDestinationEnum.Server:
                    this.Server.Send(bigEndianWriter1.Data);
                    break;
                }
            }
            catch
            {
            }
        }
Example #14
0
 public override void Serialize(BigEndianWriter writer)
 {
     guildInfo.Serialize(writer);
     writer.WriteUInt(memberRights);
     writer.WriteBoolean(enabled);
 }
Example #15
0
 private static void WriteFieldUInt(BigEndianWriter writer, uint value)
 {
     writer.WriteUInt(value);
 }
Example #16
0
 public override void Serialize(BigEndianWriter writer)
 {
     writer.WriteShort(houseId);
     guildInfo.Serialize(writer);
     writer.WriteUInt(rights);
 }
Example #17
0
 public override void Serialize(BigEndianWriter writer)
 {
     writer.WriteUInt(reportedId);
     writer.WriteSByte(reason);
 }
        public void Send(MessagePart part, ConnectionDestination destination)
        {
            try
            {
                BigEndianWriter writer = new BigEndianWriter();
                byte            typeLen;
                if (part.Data.Length > 65535)
                {
                    typeLen = 3;
                }
                else if (part.Data.Length > 255)
                {
                    typeLen = 2;
                }
                else if (part.Data.Length > 0)
                {
                    typeLen = 1;
                }
                else
                {
                    typeLen = 0;
                }

                writer.WriteShort((short)(part.MessageId << 2 | typeLen));

                Instance += 1;
                if (destination == ConnectionDestination.Server)
                {
                    writer.WriteUInt(Instance);
                }

                switch (typeLen)
                {
                case 0:
                    break;

                case 1:
                    writer.WriteByte((byte)part.Data.Length);
                    break;

                case 2:
                    writer.WriteShort((short)part.Data.Length);
                    break;

                case 3:
                    writer.WriteByte((byte)(part.Data.Length >> 16 & 255));
                    writer.WriteShort((short)(part.Data.Length & 65535));
                    break;
                }

                writer.WriteBytes(part.Data);

                if (writer == null || writer.Data == null)
                {
                    return;
                }

                switch (destination)
                {
                case ConnectionDestination.Client:
                    ClientConnection.Send(writer.Data);
                    break;

                case ConnectionDestination.Server:
                    ServerConnection.Send(writer.Data);
                    break;
                }

                writer.Dispose();
                writer = null;
                part   = null;
            }
            catch (Exception ex)
            {
                if (Client != null && WindowManager.MainWindow.Logger != null)
                {
                    WindowManager.MainWindow.Logger.Error("[Network] Send Function -> " + ex.Message);
                }
                else
                {
                    WindowManager.MainWindow.Logger.Error("[Network] Send Function -> " + ex.Message);
                }
            }
        }