示例#1
0
        /// <inheritdoc/>
        public void AddSkill(Skill skill)
        {
            using (var writer = this.connection.StartSafeWrite(0xC1, 0x0A))
            {
                var packet = writer.Span;
                packet[2] = 0xF3;
                packet[3] = 0x11;
                packet[4] = 0xFE;

                byte?skillIndex = null;
                for (byte i = 0; i < this.SkillList.Count; i++)
                {
                    if (this.SkillList[i] == null)
                    {
                        skillIndex = i;
                    }
                }

                if (skillIndex == null)
                {
                    this.SkillList.Add(skill);
                    skillIndex = (byte)(this.SkillList.Count - 1);
                }

                packet[6] = skillIndex.Value;
                var unsignedSkillId = ShortExtensions.ToUnsigned(skill.Number);
                packet[7] = unsignedSkillId.GetLowByte();
                packet[8] = unsignedSkillId.GetHighByte();
                writer.Commit();
            }
        }
示例#2
0
        /// <inheritdoc/>
        public void UpdateSkillList()
        {
            this.SkillList.Clear();
            byte[] packet = new byte[6 + (4 * this.player.SkillList.SkillCount)];
            packet[0] = 0xC1;
            packet[1] = (byte)packet.Length;
            packet[2] = 0xF3;
            packet[3] = 0x11;
            packet[4] = this.player.SkillList.SkillCount;

            byte i = 0;

            foreach (var skillEntry in this.player.SkillList.Skills)
            {
                int offset = i * 4;
                packet[6 + offset] = i;
                this.SkillList.Add(skillEntry.Skill);
                var unsignedSkillId = ShortExtensions.ToUnsigned(skillEntry.Skill.SkillID);
                packet[7 + offset] = unsignedSkillId.GetLowByte();
                packet[8 + offset] = unsignedSkillId.GetHighByte();
                packet[9 + offset] = (byte)skillEntry.Level;
                i++;
            }

            this.connection.Send(packet);
        }
示例#3
0
        /// <inheritdoc/>
        public void UpdateSkillList()
        {
            this.SkillList.Clear();
            using (var writer = this.connection.StartSafeWrite(0xC1, 6 + (4 * this.player.SkillList.SkillCount)))
            {
                var packet = writer.Span;
                packet[2] = 0xF3;
                packet[3] = 0x11;
                packet[4] = this.player.SkillList.SkillCount;

                byte i = 0;
                foreach (var skillEntry in this.player.SkillList.Skills)
                {
                    int offset = i * 4;
                    packet[6 + offset] = i;
                    this.SkillList.Add(skillEntry.Skill);
                    var unsignedSkillId = ShortExtensions.ToUnsigned(skillEntry.Skill.SkillID);
                    packet[7 + offset] = unsignedSkillId.GetLowByte();
                    packet[8 + offset] = unsignedSkillId.GetHighByte();
                    packet[9 + offset] = (byte)skillEntry.Level;
                    i++;
                }

                writer.Commit();
            }
        }
示例#4
0
        /// <inheritdoc/>
        public void AddSkill(Skill skill)
        {
            byte[] packet     = { 0xC1, 0x0A, 0xF3, 0x11, 0xFE, 0, 0, 0, 0, 0 };
            byte?  skillIndex = null;

            for (byte i = 0; i < this.SkillList.Count; i++)
            {
                if (this.SkillList[i] == null)
                {
                    skillIndex = i;
                }
            }

            if (skillIndex == null)
            {
                this.SkillList.Add(skill);
                skillIndex = (byte)(this.SkillList.Count - 1);
            }

            packet[6] = skillIndex.Value;
            var unsignedSkillId = ShortExtensions.ToUnsigned(skill.SkillID);

            packet[7] = unsignedSkillId.GetLowByte();
            packet[8] = unsignedSkillId.GetHighByte();
            this.connection.Send(packet);
        }
 public static void Write(this byte[] buffer, int offset, short value, Endianity endianity)
 {
     if (ByteArrayExtensions.IsWrongEndianity(endianity))
     {
         value = ShortExtensions.ReverseEndianity(value);
     }
     ByteArrayExtensions.Write(buffer, offset, value);
 }
示例#6
0
        /// <inheritdoc/>
        public void AddSkill(Skill skill, int skillIndex)
        {
            byte[] packet = { 0xC1, 0x0A, 0xF3, 0x11, 0xFE, 0, 0, 0, 0, 0 };
            packet[6] = (byte)skillIndex;
            var unsignedSkillId = ShortExtensions.ToUnsigned(skill.SkillID);

            packet[7] = unsignedSkillId.GetLowByte();
            packet[8] = unsignedSkillId.GetHighByte();
            this.connection.Send(packet);
        }
示例#7
0
        /// <inheritdoc/>
        public void RemoveSkill(Skill skill)
        {
            byte[] packet = { 0xC1, 0x0A, 0xF3, 0x11, 0xFF, 0, 0, 0, 0, 0 };
            packet[6] = (byte)this.SkillList.IndexOf(skill);
            var unsignedSkillId = ShortExtensions.ToUnsigned(skill.SkillID);

            packet[7] = unsignedSkillId.GetLowByte();
            packet[8] = unsignedSkillId.GetHighByte();
            this.connection.Send(packet);
        }
        public static short ReadShort(this byte[] buffer, int offset, Endianity endianity)
        {
            short num = ByteArrayExtensions.ReadShort(buffer, offset);

            if (ByteArrayExtensions.IsWrongEndianity(endianity))
            {
                num = ShortExtensions.ReverseEndianity(num);
            }
            return(num);
        }
示例#9
0
        /// <summary>
        /// Writes a skill into the specified block.
        /// </summary>
        /// <param name="skillBlock">The skill block.</param>
        /// <param name="skill">The skill.</param>
        /// <param name="skillLevel">The skill level.</param>
        /// <param name="skillIndex">Index of the skill.</param>
        protected virtual void WriteSkillBlock(Span <byte> skillBlock, Skill skill, byte skillLevel, byte skillIndex)
        {
            skillBlock[0] = skillIndex;
            var unsignedSkillId = ShortExtensions.ToUnsigned(skill.Number);

            skillBlock[1] = unsignedSkillId.GetLowByte();
            skillBlock[2] = unsignedSkillId.GetHighByte();

            if (skillBlock.Length > 3)
            {
                skillBlock[3] = skillLevel;
            }
        }
示例#10
0
        /// <inheritdoc/>
        public void UpdateCharacterStats()
        {
            using (var writer = this.connection.StartSafeWrite(0xC3, 0x48))
            {
                var packet = writer.Span;
                packet[2] = 0xF3;
                packet[3] = 0x03;
                packet[4] = this.player.Position.X;
                packet[5] = this.player.Position.Y;
                var unsignedMapNumber = ShortExtensions.ToUnsigned(this.player.SelectedCharacter.CurrentMap.Number);
                packet[6] = unsignedMapNumber.GetLowByte();
                packet[7] = unsignedMapNumber.GetHighByte();
                packet.Slice(8).SetLongSmallEndian(this.player.SelectedCharacter.Experience);
                packet.Slice(16).SetLongSmallEndian(this.context.Configuration.ExperienceTable[(int)this.player.Attributes[Stats.Level] + 1]);
                packet.Slice(24).SetShortBigEndian((ushort)this.player.SelectedCharacter.LevelUpPoints);
                packet.Slice(26).SetShortBigEndian((ushort)this.player.Attributes[Stats.BaseStrength]);
                packet.Slice(28).SetShortBigEndian((ushort)this.player.Attributes[Stats.BaseAgility]);
                packet.Slice(30).SetShortBigEndian((ushort)this.player.Attributes[Stats.BaseVitality]);
                packet.Slice(32).SetShortBigEndian((ushort)this.player.Attributes[Stats.BaseEnergy]);
                packet.Slice(34).SetShortBigEndian((ushort)this.player.Attributes[Stats.CurrentHealth]);
                packet.Slice(36).SetShortBigEndian((ushort)this.player.Attributes[Stats.MaximumHealth]);
                packet.Slice(38).SetShortBigEndian((ushort)this.player.Attributes[Stats.CurrentMana]);
                packet.Slice(40).SetShortBigEndian((ushort)this.player.Attributes[Stats.MaximumMana]);
                packet.Slice(42).SetShortBigEndian((ushort)this.player.Attributes[Stats.CurrentShield]);
                packet.Slice(44).SetShortBigEndian((ushort)this.player.Attributes[Stats.MaximumShield]);
                packet.Slice(46).SetShortBigEndian((ushort)this.player.Attributes[Stats.CurrentAbility]);
                packet.Slice(48).SetShortBigEndian((ushort)this.player.Attributes[Stats.MaximumAbility]);

                //// 2 missing bytes here are padding
                packet.Slice(52).SetIntegerBigEndian((uint)this.player.Money);
                packet[56] = (byte)this.player.SelectedCharacter.State;
                packet[57] = (byte)this.player.SelectedCharacter.CharacterStatus;
                packet.Slice(58).SetShortBigEndian((ushort)this.player.SelectedCharacter.UsedFruitPoints);
                packet.Slice(60).SetShortBigEndian(this.player.SelectedCharacter.GetMaximumFruitPoints());
                packet.Slice(62).SetShortBigEndian((ushort)this.player.Attributes[Stats.BaseLeadership]);
                packet.Slice(64).SetShortBigEndian((ushort)this.player.SelectedCharacter.UsedNegFruitPoints);
                packet.Slice(66).SetShortBigEndian(this.player.SelectedCharacter.GetMaximumFruitPoints());
                packet[68] = this.player.Account.IsVaultExtended ? (byte)1 : (byte)0;
                //// 3 additional bytes are padding

                writer.Commit();
            }

            if (this.player.SelectedCharacter.CharacterClass.IsMasterClass)
            {
                this.SendMasterStats();
            }

            this.SendKeyConfiguration();
        }
示例#11
0
 /// <inheritdoc/>
 public void RemoveSkill(Skill skill)
 {
     using (var writer = this.connection.StartSafeWrite(0xC1, 0x0A))
     {
         var packet = writer.Span;
         packet[2] = 0xF3;
         packet[3] = 0x11;
         packet[4] = 0xFF;
         packet[6] = (byte)this.SkillList.IndexOf(skill);
         var unsignedSkillId = ShortExtensions.ToUnsigned(skill.Number);
         packet[7] = unsignedSkillId.GetLowByte();
         packet[8] = unsignedSkillId.GetHighByte();
         writer.Commit();
     }
 }
示例#12
0
        /// <inheritdoc/>
        public void UpdateCharacterStats()
        {
            var packet = new byte[0x48];

            packet.SetValues <byte>(0xC3, (byte)packet.Length, 0xF3, 0x03);
            packet[4] = this.player.X;
            packet[5] = this.player.Y;
            var unsignedMapNumber = ShortExtensions.ToUnsigned(this.player.SelectedCharacter.CurrentMap.Number);

            packet[6] = unsignedMapNumber.GetLowByte();
            packet[7] = unsignedMapNumber.GetHighByte();
            packet.SetLongSmallEndian(this.player.SelectedCharacter.Experience, 8);
            packet.SetLongSmallEndian(this.context.Configuration.ExperienceTable[(int)this.player.Attributes[Stats.Level] + 1], 16);
            packet.SetShortBigEndian((ushort)this.player.SelectedCharacter.LevelUpPoints, 24);
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.BaseStrength], 26);
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.BaseAgility], 28);
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.BaseVitality], 30);
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.BaseEnergy], 32);
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.CurrentHealth], 34);
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.MaximumHealth], 36);
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.CurrentMana], 38);
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.MaximumMana], 40);
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.CurrentShield], 42);
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.MaximumShield], 44);
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.CurrentAbility], 46);
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.MaximumAbility], 48);

            //// 2 missing bytes here are padding
            packet.SetIntegerBigEndian((uint)this.player.Money, 52);
            packet[56] = (byte)this.player.SelectedCharacter.PlayerKillCount;
            packet[57] = (byte)this.player.SelectedCharacter.State;
            packet.SetShortBigEndian((ushort)this.player.SelectedCharacter.UsedFruitPoints, 58);
            packet.SetShortBigEndian(127, 60); // TODO: MaxFruits, calculate the right value
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.BaseLeadership], 62);
            packet.SetShortBigEndian((ushort)this.player.SelectedCharacter.UsedNegFruitPoints, 64);
            packet.SetShortBigEndian(127, 66); // TODO: MaxNegFruits, calculate the right value
            packet[68] = this.player.Account.IsVaultExtended ? (byte)1 : (byte)0;
            //// 3 additional bytes are padding

            this.connection.Send(packet);

            if (this.player.SelectedCharacter.CharacterClass.IsMasterClass)
            {
                this.SendMasterStats();
            }
        }
示例#13
0
        /// <inheritdoc/>
        public void UpdateSkillList()
        {
            const int headerSize     = 6;
            const int skillBlockSize = 4;

            this.SkillList.Clear();
            using (var writer = this.connection.StartSafeWrite(0xC1, headerSize + (skillBlockSize * this.player.SkillList.SkillCount)))
            {
                var packet = writer.Span;
                packet[2] = 0xF3;
                packet[3] = 0x11;

                var skills = this.player.SkillList.Skills.ToList();
                if (this.player.SelectedCharacter.CharacterClass.IsMasterClass)
                {
                    var replacedSkills = skills.Select(entry => entry.Skill.MasterDefinition?.ReplacedSkill).Where(skill => skill != null);
                    skills.RemoveAll(s => replacedSkills.Contains(s.Skill));
                }

                byte i = 0;
                foreach (var skillEntry in skills.Distinct(default(SkillEqualityComparer)))
                {
                    int offset = i * 4;
                    packet[6 + offset] = i;
                    this.SkillList.Add(skillEntry.Skill);
                    var unsignedSkillId = ShortExtensions.ToUnsigned(skillEntry.Skill.Number);
                    packet[7 + offset] = unsignedSkillId.GetLowByte();
                    packet[8 + offset] = unsignedSkillId.GetHighByte();
                    packet[9 + offset] = (byte)skillEntry.Level;
                    i++;
                }

                packet[4] = i;
                var actualSize = headerSize + (skillBlockSize * i);
                packet.Slice(0, actualSize).SetPacketSize();
                writer.Commit(actualSize);
            }
        }
示例#14
0
        /// <inheritdoc/>
        public void UpdateCharacterStats()
        {
            var packet = new byte[0x48];

            packet.SetValues <byte>(0xC3, (byte)packet.Length, 0xF3, 0x03);
            var i = 4;

            packet[i++] = this.player.X;
            packet[i++] = this.player.Y;
            var unsignedMapNumber = ShortExtensions.ToUnsigned(this.player.SelectedCharacter.CurrentMap.Number);

            packet[i++] = unsignedMapNumber.GetLowByte();
            packet[i++] = unsignedMapNumber.GetHighByte();
            packet.SetLongSmallEndian(this.player.SelectedCharacter.Experience, i++);
            i += 7;
            packet.SetLongSmallEndian(this.context.Configuration.ExperienceTable[(int)this.player.Attributes[Stats.Level] + 1], i++);
            i += 7;
            packet.SetShortBigEndian((ushort)this.player.SelectedCharacter.LevelUpPoints, i++);
            i++;
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.BaseStrength], i++);
            i++;
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.BaseAgility], i++);
            i++;
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.BaseVitality], i++);
            i++;
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.BaseEnergy], i++);
            i++;
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.CurrentHealth], i++);
            i++;
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.MaximumHealth], i++);
            i++;
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.CurrentMana], i++);
            i++;
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.MaximumMana], i++);
            i++;
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.CurrentShield], i++);
            i++;
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.MaximumShield], i++);
            i++;
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.CurrentAbility], i++);
            i++;
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.MaximumAbility], i++);
            i++;
            packet[i++] = 0;    // unknown
            packet[i++] = 0x12; // unknown
            packet.SetIntegerBigEndian((uint)this.player.Money, i++);
            i          += 3;
            packet[i++] = (byte)this.player.SelectedCharacter.PlayerKillCount;
            packet[i++] = (byte)this.player.SelectedCharacter.State;
            packet.SetShortBigEndian((ushort)this.player.SelectedCharacter.UsedFruitPoints, i++);
            i++;
            packet.SetShortBigEndian(127, i++); // TODO: MaxFruits, calculate the right value
            i++;
            packet.SetShortBigEndian((ushort)this.player.Attributes[Stats.BaseLeadership], i++);
            i++;
            packet.SetShortBigEndian((ushort)this.player.SelectedCharacter.UsedNegFruitPoints, i++);
            i++;
            packet.SetShortBigEndian(127, i++); // TODO: MaxNegFruits, calculate the right value
            i++;
            packet[i++] = this.player.Account.IsVaultExtended ? (byte)1 : (byte)0;
            packet[i++] = 0x25; // unknown
            packet[i++] = 0xAB; // unknown
            packet[i]   = 0x71; // unknown
            this.connection.Send(packet);
        }
 public static ushort ReverseEndianity(this ushort value)
 {
     return((ushort)ShortExtensions.ReverseEndianity((short)value));
 }