diff --git a/LibraryCore/Globals.cs b/LibraryCore/Globals.cs index 5c790524..09c4afdf 100644 --- a/LibraryCore/Globals.cs +++ b/LibraryCore/Globals.cs @@ -6,6 +6,7 @@ using System.Drawing; using System.Linq; using System.Text.RegularExpressions; +using MemoryPack; namespace Library { @@ -318,7 +319,8 @@ public static string PluginPath(string assemblyName) } } - public sealed class SelectInfo + [MemoryPackable] + public sealed partial class SelectInfo { public int CharacterIndex { get; set; } public string CharacterName { get; set; } @@ -330,13 +332,15 @@ public sealed class SelectInfo public DateTime LastLogin { get; set; } } - public sealed class StartInformation + [MemoryPackable] + public sealed partial class StartInformation { public int Index { get; set; } public uint ObjectID { get; set; } public string Name { get; set; } public string Caption { get; set; } + [MemoryPackAllowSerialize] public Color NameColour { get; set; } public string GuildName { get; set; } public string GuildRank { get; set; } @@ -351,11 +355,13 @@ public sealed class StartInformation public int Level { get; set; } public int HairType { get; set; } + [MemoryPackAllowSerialize] public Color HairColour { get; set; } public int Weapon { get; set; } public int Armour { get; set; } public int Costume { get; set; } public int Shield { get; set; } + [MemoryPackAllowSerialize] public Color ArmourColour { get; set; } public ExteriorEffect ArmourEffect { get; set; } @@ -409,6 +415,7 @@ public sealed class StartInformation public List Quests { get; set; } public List CompanionUnlocks { get; set; } + [MemoryPackIgnore] public List AvailableCompanions = new List(); public List Companions { get; set; } @@ -425,7 +432,7 @@ public sealed class StartInformation public bool StruckEnabled { get; set; } public bool HermitEnabled { get; set; } - [CompleteObject] + [MemoryPackOnDeserialized] public void OnComplete() { foreach (int index in CompanionUnlocks) @@ -433,8 +440,10 @@ public void OnComplete() } } - public sealed class ClientUserItem + [MemoryPackable] + public sealed partial class ClientUserItem { + [MemoryPackIgnore] public ItemInfo Info; public int Index { get; set; } //ItemID @@ -450,21 +459,22 @@ public sealed class ClientUserItem public int Level { get; set; } public decimal Experience { get; set; } + [MemoryPackAllowSerialize] public Color Colour { get; set; } public TimeSpan SpecialRepairCoolDown { get; set; } public TimeSpan ResetCoolDown { get; set; } public bool New; + [MemoryPackIgnore] public DateTime NextSpecialRepair, NextReset; public Stats AddedStats { get; set; } public UserItemFlags Flags { get; set; } public TimeSpan ExpireTime { get; set; } - - - [IgnorePropertyPacket] + + [MemoryPackIgnore] public int Weight { get @@ -480,7 +490,7 @@ public int Weight } } - [CompleteObject] + [MemoryPackOnDeserialized] public void Complete() { Info = Globals.ItemInfoList.Binding.FirstOrDefault(x => x.Index == InfoIndex); @@ -489,6 +499,7 @@ public void Complete() NextReset = Time.Now + ResetCoolDown; } + [MemoryPackConstructor] public ClientUserItem() { } public ClientUserItem(ItemInfo info, long count) @@ -760,14 +771,16 @@ public int FragmentCount() } } - public sealed class ClientBeltLink + [MemoryPackable] + public sealed partial class ClientBeltLink { public int Slot { get; set; } public int LinkInfoIndex { get; set; } public int LinkItemIndex { get; set; } } - public sealed class ClientAutoPotionLink + [MemoryPackable] + public sealed partial class ClientAutoPotionLink { public int Slot { get; set; } public int LinkInfoIndex { get; set; } @@ -776,10 +789,12 @@ public sealed class ClientAutoPotionLink public bool Enabled { get; set; } } - public class ClientUserMagic + [MemoryPackable] + public partial class ClientUserMagic { public int Index { get; set; } public int InfoIndex { get; set; } + [MemoryPackIgnore] public MagicInfo Info; public SpellKey Set1Key { get; set; } @@ -793,13 +808,13 @@ public class ClientUserMagic public TimeSpan Cooldown { get; set; } + [MemoryPackIgnore] public DateTime NextCast; - - - [IgnorePropertyPacket] + + [MemoryPackIgnore] public int Cost => Info.BaseCost + Level * Info.LevelCost / 3; - [CompleteObject] + [MemoryPackOnDeserialized] public void Complete() { NextCast = Time.Now + Cooldown; @@ -807,20 +822,23 @@ public void Complete() } } - public class ClientNPCValues + [MemoryPackable] + public partial class ClientNPCValues { public int ID { get; set; } public string Value { get; set; } } - public class CellLinkInfo + [MemoryPackable] + public partial class CellLinkInfo { public GridType GridType { get; set; } public int Slot { get; set; } public long Count { get; set; } } - public class ClientBuffInfo + [MemoryPackable] + public partial class ClientBuffInfo { public int Index { get; set; } public BuffType Type { get; set; } @@ -832,7 +850,8 @@ public class ClientBuffInfo public int Extra { get; set; } } - public class ClientRefineInfo + [MemoryPackable] + public partial class ClientRefineInfo { public int Index { get; set; } public ClientUserItem Weapon { get; set; } @@ -842,9 +861,10 @@ public class ClientRefineInfo public int MaxChance { get; set; } public TimeSpan ReadyDuration { get; set; } + [MemoryPackIgnore] public DateTime RetrieveTime; - [CompleteObject] + [MemoryPackOnDeserialized] public void Complete() { RetrieveTime = Time.Now + ReadyDuration; @@ -852,7 +872,8 @@ public void Complete() } - public sealed class RankInfo + [MemoryPackable] + public sealed partial class RankInfo { public int Rank { get; set; } public int Index { get; set; } @@ -867,7 +888,8 @@ public sealed class RankInfo public int RankChange { get; set; } } - public class ClientMarketPlaceInfo + [MemoryPackable] + public partial class ClientMarketPlaceInfo { public int Index { get; set; } public ClientUserItem Item { get; set; } @@ -881,7 +903,8 @@ public class ClientMarketPlaceInfo public bool Loading; } - public class ClientMailInfo + [MemoryPackable] + public partial class ClientMailInfo { public int Index { get; set; } public bool Opened { get; set; } @@ -896,7 +919,8 @@ public class ClientMailInfo public List Items { get; set; } } - public class ClientGuildInfo + [MemoryPackable] + public partial class ClientGuildInfo { public string GuildName { get; set; } @@ -918,18 +942,20 @@ public class ClientGuildInfo public string DefaultRank { get; set; } public GuildPermission DefaultPermission { get; set; } + [MemoryPackAllowSerialize] public Color Colour { get; set; } public int Flag { get; set; } public List Members { get; set; } public List Storage { get; set; } - - [IgnorePropertyPacket] + + [MemoryPackIgnore] public GuildPermission Permission => Members.FirstOrDefault(x => x.Index == UserIndex)?.Permission ?? GuildPermission.None; } - public class ClientGuildMemberInfo + [MemoryPackable] + public partial class ClientGuildMemberInfo { public int Index { get; set; } public string Name { get; set; } @@ -940,10 +966,11 @@ public class ClientGuildMemberInfo public GuildPermission Permission { get; set; } + [MemoryPackIgnore] public DateTime LastOnline; public uint ObjectID { get; set; } - [CompleteObject] + [MemoryPackOnDeserialized] public void Complete() { if (Online == TimeSpan.MinValue) @@ -954,11 +981,12 @@ public void Complete() } - public class ClientUserQuest + [MemoryPackable] + public partial class ClientUserQuest { public int Index { get; set; } - - [IgnorePropertyPacket] + + [MemoryPackIgnore] public QuestInfo Quest { get; set; } public int QuestIndex { get; set; } @@ -971,41 +999,43 @@ public class ClientUserQuest public DateTime DateTaken { get; set; } public DateTime DateCompleted { get; set; } - - [IgnorePropertyPacket] + + [MemoryPackIgnore] public bool IsComplete => Tasks.Count == Quest.Tasks.Count && Tasks.All(x => x.Completed); public List Tasks { get; set; } - [CompleteObject] + [MemoryPackOnDeserialized] public void Complete() { Quest = Globals.QuestInfoList.Binding.First(x => x.Index == QuestIndex); } } - public class ClientUserQuestTask + [MemoryPackable] + public partial class ClientUserQuestTask { public int Index { get; set; } - - [IgnorePropertyPacket] + + [MemoryPackIgnore] public QuestTask Task { get; set; } public int TaskIndex { get; set; } public long Amount { get; set; } - - [IgnorePropertyPacket] + + [MemoryPackIgnore] public bool Completed => Amount >= Task.Amount; - [CompleteObject] + [MemoryPackOnDeserialized] public void Complete() { Task = Globals.QuestTaskList.Binding.First(x => x.Index == TaskIndex); } } - public class ClientCompanionObject + [MemoryPackable] + public partial class ClientCompanionObject { public string Name { get; set; } @@ -1013,12 +1043,14 @@ public class ClientCompanionObject public int BackShape { get; set; } } - public class ClientUserCompanion + [MemoryPackable] + public partial class ClientUserCompanion { public int Index { get; set; } public string Name { get; set; } public int CompanionIndex { get; set; } + [MemoryPackIgnore] public CompanionInfo CompanionInfo; public int Level { get; set; } @@ -1037,10 +1069,11 @@ public class ClientUserCompanion public List Items { get; set; } + [MemoryPackIgnore] public ClientUserItem[] EquipmentArray = new ClientUserItem[Globals.CompanionEquipmentSize], InventoryArray = new ClientUserItem[Globals.CompanionInventorySize]; - [CompleteObject] + [MemoryPackOnDeserialized] public void OnComplete() { CompanionInfo = Globals.CompanionInfoList.Binding.First(x => x.Index == CompanionIndex); @@ -1056,13 +1089,15 @@ public void OnComplete() } - public class ClientPlayerInfo + [MemoryPackable] + public partial class ClientPlayerInfo { public uint ObjectID { get; set; } public string Name { get; set; } } - public class ClientObjectData + [MemoryPackable] + public partial class ClientObjectData { public uint ObjectID; @@ -1087,31 +1122,36 @@ public class ClientObjectData public bool Dead; } - public class ClientBlockInfo + [MemoryPackable] + public partial class ClientBlockInfo { public int Index { get; set; } public string Name { get; set; } } - public class ClientFriendInfo + [MemoryPackable] + public partial class ClientFriendInfo { public int Index { get; set; } public string Name { get; set; } public OnlineState State { get; set; } } - public class ClientFortuneInfo + [MemoryPackable] + public partial class ClientFortuneInfo { public int ItemIndex { get; set; } + [MemoryPackIgnore] public ItemInfo ItemInfo; public TimeSpan CheckTime { get; set; } public long DropCount { get; set; } public decimal Progress { get; set; } + [MemoryPackIgnore] public DateTime CheckDate; - [CompleteObject] + [MemoryPackOnDeserialized] public void OnComplete() { ItemInfo = Globals.ItemInfoList.Binding.First(x => x.Index == ItemIndex); @@ -1120,27 +1160,30 @@ public void OnComplete() } } - public class CompanionFiltersInfo + [MemoryPackable] + public partial class CompanionFiltersInfo { public string FilterClass { get; set; } public string FilterRarity { get; set; } public string FilterItemType { get; set; } } - public class ClientUserCurrency + [MemoryPackable] + public partial class ClientUserCurrency { public int CurrencyIndex { get; set; } public CurrencyInfo Info; public long Amount { get; set; } - - [IgnorePropertyPacket] + + [MemoryPackIgnore] public bool CanPickup { get { return Info != null && Info.DropItem != null && Info.DropItem.CanDrop; } } } - public class ClientUserDiscipline + [MemoryPackable] + public partial class ClientUserDiscipline { public int InfoIndex { get; set; } public DisciplineInfo DisciplineInfo; @@ -1149,28 +1192,32 @@ public class ClientUserDiscipline public List Magics { get; set; } } - public class ClientBundleItemInfo + [MemoryPackable] + public partial class ClientBundleItemInfo { public int ItemIndex { get; set; } + [MemoryPackIgnore] public ItemInfo ItemInfo; public int Amount { get; set; } public int Slot { get; set; } - [CompleteObject] + [MemoryPackOnDeserialized] public void OnComplete() { ItemInfo = Globals.ItemInfoList.Binding.First(x => x.Index == ItemIndex); } } - public class ClientLootBoxItemInfo + [MemoryPackable] + public partial class ClientLootBoxItemInfo { public int ItemIndex { get; set; } + [MemoryPackIgnore] public ItemInfo ItemInfo; public int Amount { get; set; } public int Slot { get; set; } - [CompleteObject] + [MemoryPackOnDeserialized] public void OnComplete() { ItemInfo = Globals.ItemInfoList.Binding.FirstOrDefault(x => x.Index == ItemIndex); diff --git a/LibraryCore/LibraryCore.csproj b/LibraryCore/LibraryCore.csproj index 58990cd5..f1edfc8c 100644 --- a/LibraryCore/LibraryCore.csproj +++ b/LibraryCore/LibraryCore.csproj @@ -4,4 +4,12 @@ net8.0 + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/LibraryCore/MemoryPackFormatter.cs b/LibraryCore/MemoryPackFormatter.cs new file mode 100644 index 00000000..b7eabc66 --- /dev/null +++ b/LibraryCore/MemoryPackFormatter.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using System.Drawing; +using Library; +using MemoryPack; + +namespace LibraryCore; + +public sealed class StatsFormatter : MemoryPackFormatter +{ + public override void Serialize(ref MemoryPackWriter writer, scoped ref Stats value) + { + writer.WriteCollectionHeader(value.Values.Count); + foreach (var pair in value.Values) + { + writer.WriteVarInt((int)pair.Key); + writer.WriteVarInt(pair.Value); + } + } + + public override void Deserialize(ref MemoryPackReader reader, scoped ref Stats value) + { + reader.TryReadCollectionHeader(out var length); + + var dict = new SortedDictionary(); + for (int i = 0; i < length; i++) + { + dict[(Stat)reader.ReadVarIntInt32()] = reader.ReadVarIntInt32(); + } + value = new Stats() { Values = dict }; + } +} + +public sealed class ColorFormatter : MemoryPackFormatter +{ + public override void Serialize(ref MemoryPackWriter writer, scoped ref Color value) + { + var argb = value.ToArgb(); + var rgba = argb << 8 | argb >> 24; + writer.WriteVarInt(rgba); + } + + public override void Deserialize(ref MemoryPackReader reader, scoped ref Color value) + { + var rgba = reader.ReadVarIntInt32(); + var argb = rgba >> 8 | rgba << 24; + value = Color.FromArgb(argb); + } +} diff --git a/LibraryCore/Network/BaseConnection.cs b/LibraryCore/Network/BaseConnection.cs index 97212c23..5c5baba9 100644 --- a/LibraryCore/Network/BaseConnection.cs +++ b/LibraryCore/Network/BaseConnection.cs @@ -315,22 +315,23 @@ private void ProcessPacket(Packet p) DateTime start = Time.Now; + var packetType = p.GetType(); MethodInfo info; - if (!PacketMethods.TryGetValue(p.PacketType, out info)) - PacketMethods[p.PacketType] = info = GetType().GetMethod("Process", new[] { p.PacketType }); + if (!PacketMethods.TryGetValue(packetType, out info)) + PacketMethods[packetType] = info = GetType().GetMethod("Process", new[] { packetType }); if (info == null) - throw new NotImplementedException($"Not Implemented Exception: Method Process({p.PacketType})."); + throw new NotImplementedException($"Not Implemented Exception: Method Process({packetType})."); - info.Invoke(this, new object[] { p }); + info.Invoke(this, [p]); if (!Monitor) return; TimeSpan execution = Time.Now - start; DiagnosticValue value; - if (!Diagnostics.TryGetValue(p.PacketType.FullName, out value)) - Diagnostics[p.PacketType.FullName] = value = new DiagnosticValue { Name = p.PacketType.FullName }; + if (!Diagnostics.TryGetValue(packetType.FullName, out value)) + Diagnostics[packetType.FullName] = value = new DiagnosticValue { Name = packetType.FullName }; value.Count++; value.TotalTime += execution; diff --git a/LibraryCore/Network/ClientPackets.cs b/LibraryCore/Network/ClientPackets.cs index 30135c88..7987df5e 100644 --- a/LibraryCore/Network/ClientPackets.cs +++ b/LibraryCore/Network/ClientPackets.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.Drawing; +using MemoryPack; namespace Library.Network.ClientPackets { - public sealed class NewAccount : Packet + [MemoryPackable] + public sealed partial class NewAccount : Packet { public string EMailAddress { get; set; } public string Password { get; set; } @@ -14,7 +16,8 @@ public sealed class NewAccount : Packet public string CheckSum { get; set; } } - public sealed class ChangePassword : Packet + [MemoryPackable] + public sealed partial class ChangePassword : Packet { public string EMailAddress { get; set; } public string CurrentPassword { get; set; } @@ -22,89 +25,107 @@ public sealed class ChangePassword : Packet public string CheckSum { get; set; } } - public sealed class RequestPasswordReset : Packet + [MemoryPackable] + public sealed partial class RequestPasswordReset : Packet { public string EMailAddress { get; set; } public string CheckSum { get; set; } } - public sealed class ResetPassword : Packet + [MemoryPackable] + public sealed partial class ResetPassword : Packet { public string ResetKey { get; set; } public string NewPassword { get; set; } public string CheckSum { get; set; } } - public sealed class Activation : Packet + [MemoryPackable] + public sealed partial class Activation : Packet { public string ActivationKey { get; set; } public string CheckSum { get; set; } } - public sealed class RequestActivationKey : Packet + [MemoryPackable] + public sealed partial class RequestActivationKey : Packet { public string EMailAddress { get; set; } public string CheckSum { get; set; } } - public sealed class SelectLanguage : Packet + [MemoryPackable] + public sealed partial class SelectLanguage : Packet { public string Language { get; set; } } - public sealed class Login : Packet + [MemoryPackable] + public sealed partial class Login : Packet { public string EMailAddress { get; set; } public string Password { get; set; } public string CheckSum { get; set; } } - public sealed class Logout : Packet { } + [MemoryPackable] + public sealed partial class Logout : Packet { } - public sealed class NewCharacter : Packet + [MemoryPackable] + public sealed partial class NewCharacter : Packet { public string CharacterName { get; set; } public MirClass Class { get; set; } public MirGender Gender { get; set; } public int HairType { get; set; } + [MemoryPackAllowSerialize] public Color HairColour { get; set; } + [MemoryPackAllowSerialize] public Color ArmourColour { get; set; } public string CheckSum { get; set; } } - public sealed class DeleteCharacter : Packet + [MemoryPackable] + public sealed partial class DeleteCharacter : Packet { public int CharacterIndex { get; set; } public string CheckSum { get; set; } } - public sealed class StartGame : Packet + [MemoryPackable] + public sealed partial class StartGame : Packet { public int CharacterIndex { get; set; } } - public sealed class TownRevive : Packet { } + [MemoryPackable] + public sealed partial class TownRevive : Packet { } - public sealed class Turn : Packet + [MemoryPackable] + public sealed partial class Turn : Packet { public MirDirection Direction { get; set; } } - public sealed class Harvest : Packet + [MemoryPackable] + public sealed partial class Harvest : Packet { public MirDirection Direction { get; set; } } - public sealed class Move : Packet + [MemoryPackable] + public sealed partial class Move : Packet { public MirDirection Direction { get; set; } public int Distance { get; set; } } - public sealed class Mount : Packet { } + [MemoryPackable] + public sealed partial class Mount : Packet { } - public sealed class FishingCast : Packet + [MemoryPackable] + public sealed partial class FishingCast : Packet { public FishingState State { get; set; } public MirDirection Direction { get; set; } @@ -112,26 +133,30 @@ public sealed class FishingCast : Packet public bool CaughtFish { get; set; } } - public sealed class Attack : Packet + [MemoryPackable] + public sealed partial class Attack : Packet { public MirDirection Direction { get; set; } public MirAction Action { get; set; } public MagicType AttackMagic { get; set; } } - public sealed class RangeAttack : Packet + [MemoryPackable] + public sealed partial class RangeAttack : Packet { public MirDirection Direction { get; set; } public uint Target { get; set; } public int DelayedTime { get; set; } } - public sealed class Mining : Packet + [MemoryPackable] + public sealed partial class Mining : Packet { public MirDirection Direction { get; set; } } - public sealed class Magic : Packet + [MemoryPackable] + public sealed partial class Magic : Packet { public MirDirection Direction { get; set; } public MirAction Action { get; set; } @@ -140,7 +165,8 @@ public sealed class Magic : Packet public Point Location { get; set; } } - public sealed class ItemMove : Packet + [MemoryPackable] + public sealed partial class ItemMove : Packet { public GridType FromGrid { get; set; } public GridType ToGrid { get; set; } @@ -149,56 +175,65 @@ public sealed class ItemMove : Packet public bool MergeItem { get; set; } } - public sealed class ItemSort : Packet + [MemoryPackable] + public sealed partial class ItemSort : Packet { public GridType Grid { get; set; } } - public sealed class ItemDelete : Packet + [MemoryPackable] + public sealed partial class ItemDelete : Packet { public GridType Grid { get; set; } public int Slot { get; set; } } - public sealed class ItemSplit : Packet + [MemoryPackable] + public sealed partial class ItemSplit : Packet { public GridType Grid { get; set; } public int Slot { get; set; } public long Count { get; set; } } - public sealed class ItemDrop : Packet + [MemoryPackable] + public sealed partial class ItemDrop : Packet { public CellLinkInfo Link { get; set; } public int Slot { get; set; } } - public sealed class CurrencyDrop : Packet + [MemoryPackable] + public sealed partial class CurrencyDrop : Packet { public int CurrencyIndex { get; set; } public long Amount { get; set; } } - public sealed class ItemUse : Packet + [MemoryPackable] + public sealed partial class ItemUse : Packet { public CellLinkInfo Link { get; set; } } - public sealed class ItemLock : Packet + [MemoryPackable] + public sealed partial class ItemLock : Packet { public GridType GridType { get; set; } public int SlotIndex { get; set; } public bool Locked { get; set; } } - public sealed class BeltLinkChanged : Packet + [MemoryPackable] + public sealed partial class BeltLinkChanged : Packet { public int Slot { get; set; } public int LinkIndex { get; set; } public int LinkItemIndex { get; set; } } - public sealed class AutoPotionLinkChanged : Packet + [MemoryPackable] + public sealed partial class AutoPotionLinkChanged : Packet { public int Slot { get; set; } public int LinkIndex { get; set; } @@ -207,59 +242,70 @@ public sealed class AutoPotionLinkChanged : Packet public bool Enabled { get; set; } } - public sealed class PickUp : Packet { } + [MemoryPackable] + public sealed partial class PickUp : Packet { } - public sealed class Chat : Packet + [MemoryPackable] + public sealed partial class Chat : Packet { public string Text { get; set; } } - public sealed class NPCCall : Packet + [MemoryPackable] + public sealed partial class NPCCall : Packet { public uint ObjectID { get; set; } } - public sealed class NPCButton : Packet + [MemoryPackable] + public sealed partial class NPCButton : Packet { public int ButtonID { get; set; } } - public sealed class NPCRoll : Packet + [MemoryPackable] + public sealed partial class NPCRoll : Packet { public int Type { get; set; } } - public sealed class NPCRollResult : Packet + [MemoryPackable] + public sealed partial class NPCRollResult : Packet { } - public sealed class NPCBuy : Packet + [MemoryPackable] + public sealed partial class NPCBuy : Packet { public int Index { get; set; } public long Amount { get; set; } public bool GuildFunds { get; set; } } - public sealed class NPCSell : Packet + [MemoryPackable] + public sealed partial class NPCSell : Packet { public List Links { get; set; } } - public sealed class NPCFragment : Packet + [MemoryPackable] + public sealed partial class NPCFragment : Packet { public List Links { get; set; } } - public sealed class NPCRepair : Packet + [MemoryPackable] + public sealed partial class NPCRepair : Packet { public List Links { get; set; } public bool Special { get; set; } public bool GuildFunds { get; set; } } - public sealed class NPCRefine : Packet + [MemoryPackable] + public sealed partial class NPCRefine : Packet { public RefineType RefineType { get; set; } public RefineQuality RefineQuality { get; set; } @@ -267,7 +313,8 @@ public sealed class NPCRefine : Packet public List Items { get; set; } public List Specials { get; set; } } - public sealed class NPCMasterRefine : Packet + [MemoryPackable] + public sealed partial class NPCMasterRefine : Packet { public RefineType RefineType { get; set; } public List Fragment1s { get; set; } @@ -276,7 +323,8 @@ public sealed class NPCMasterRefine : Packet public List Stones { get; set; } public List Specials { get; set; } } - public sealed class NPCMasterRefineEvaluate : Packet + [MemoryPackable] + public sealed partial class NPCMasterRefineEvaluate : Packet { public RefineType RefineType { get; set; } public List Fragment1s { get; set; } @@ -285,7 +333,8 @@ public sealed class NPCMasterRefineEvaluate : Packet public List Stones { get; set; } public List Specials { get; set; } } - public sealed class NPCRefinementStone : Packet + [MemoryPackable] + public sealed partial class NPCRefinementStone : Packet { public List IronOres { get; set; } public List SilverOres { get; set; } @@ -295,27 +344,32 @@ public sealed class NPCRefinementStone : Packet public long Gold { get; set; } } - public sealed class NPCClose : Packet + [MemoryPackable] + public sealed partial class NPCClose : Packet { } - public sealed class NPCRefineRetrieve : Packet + [MemoryPackable] + public sealed partial class NPCRefineRetrieve : Packet { public int Index { get; set; } } - public sealed class NPCAccessoryLevelUp : Packet + [MemoryPackable] + public sealed partial class NPCAccessoryLevelUp : Packet { public CellLinkInfo Target { get; set; } public List Links { get; set; } } - public sealed class NPCAccessoryUpgrade : Packet + [MemoryPackable] + public sealed partial class NPCAccessoryUpgrade : Packet { public CellLinkInfo Target { get; set; } public RefineType RefineType { get; set; } } - public sealed class MagicKey : Packet + [MemoryPackable] + public sealed partial class MagicKey : Packet { public MagicType Magic { get; set; } @@ -325,73 +379,86 @@ public sealed class MagicKey : Packet public SpellKey Set4Key { get; set; } } - public sealed class MagicToggle : Packet + [MemoryPackable] + public sealed partial class MagicToggle : Packet { public MagicType Magic { get; set; } public bool CanUse { get; set; } } - public sealed class GroupSwitch : Packet + [MemoryPackable] + public sealed partial class GroupSwitch : Packet { public bool Allow { get; set; } } - public sealed class GroupInvite : Packet + [MemoryPackable] + public sealed partial class GroupInvite : Packet { public string Name { get; set; } } - public sealed class GroupRemove : Packet + [MemoryPackable] + public sealed partial class GroupRemove : Packet { public string Name { get; set; } } - public sealed class GroupResponse : Packet + [MemoryPackable] + public sealed partial class GroupResponse : Packet { public bool Accept { get; set; } } - public sealed class Inspect : Packet + [MemoryPackable] + public sealed partial class Inspect : Packet { public int Index { get; set; } public bool Ranking { get; set; } } - public sealed class RankRequest : Packet + [MemoryPackable] + public sealed partial class RankRequest : Packet { public RequiredClass Class { get; set; } public bool OnlineOnly { get; set; } public int StartIndex { get; set; } } - public sealed class RankSearch : Packet + [MemoryPackable] + public sealed partial class RankSearch : Packet { public string Name { get; set; } } - public sealed class ObserverRequest : Packet + [MemoryPackable] + public sealed partial class ObserverRequest : Packet { public string Name { get; set; } } - public sealed class ObservableSwitch : Packet + [MemoryPackable] + public sealed partial class ObservableSwitch : Packet { public bool Allow { get; set; } } - public sealed class Hermit : Packet + [MemoryPackable] + public sealed partial class Hermit : Packet { public Stat Stat { get; set; } } - public sealed class MarketPlaceHistory : Packet + [MemoryPackable] + public sealed partial class MarketPlaceHistory : Packet { public int Index { get; set; } public int Display { get; set; } public int PartIndex { get; set; } } - public sealed class MarketPlaceConsign : Packet + [MemoryPackable] + public sealed partial class MarketPlaceConsign : Packet { public CellLinkInfo Link { get; set; } @@ -400,7 +467,8 @@ public sealed class MarketPlaceConsign : Packet public string Message { get; set; } public bool GuildFunds { get; set; } } - public sealed class MarketPlaceSearch : Packet + [MemoryPackable] + public sealed partial class MarketPlaceSearch : Packet { public string Name { get; set; } @@ -409,22 +477,26 @@ public sealed class MarketPlaceSearch : Packet public MarketPlaceSort Sort { get; set; } } - public sealed class MarketPlaceSearchIndex : Packet + [MemoryPackable] + public sealed partial class MarketPlaceSearchIndex : Packet { public int Index { get; set; } } - public sealed class MarketPlaceCancelConsign : Packet + [MemoryPackable] + public sealed partial class MarketPlaceCancelConsign : Packet { public int Index { get; set; } public long Count { get; set; } } - public sealed class MarketPlaceBuy : Packet + [MemoryPackable] + public sealed partial class MarketPlaceBuy : Packet { public long Index { get; set; } public long Count { get; set; } public bool GuildFunds { get; set; } } - public sealed class MarketPlaceStoreBuy : Packet + [MemoryPackable] + public sealed partial class MarketPlaceStoreBuy : Packet { public int Index { get; set; } public long Count { get; set; } @@ -432,20 +504,24 @@ public sealed class MarketPlaceStoreBuy : Packet } - public sealed class MailOpened : Packet + [MemoryPackable] + public sealed partial class MailOpened : Packet { public int Index { get; set; } } - public sealed class MailGetItem : Packet + [MemoryPackable] + public sealed partial class MailGetItem : Packet { public int Index { get; set; } public int Slot { get; set; } } - public sealed class MailDelete : Packet + [MemoryPackable] + public sealed partial class MailDelete : Packet { public int Index { get; set; } } - public sealed class MailSend : Packet + [MemoryPackable] + public sealed partial class MailSend : Packet { public List Links { get; set; } public string Recipient { get; set; } @@ -455,242 +531,297 @@ public sealed class MailSend : Packet } - public sealed class ChangeAttackMode : Packet + [MemoryPackable] + public sealed partial class ChangeAttackMode : Packet { public AttackMode Mode { get; set; } } - public sealed class ChangePetMode : Packet + [MemoryPackable] + public sealed partial class ChangePetMode : Packet { public PetMode Mode { get; set; } } - public sealed class GameGoldRecharge : Packet + [MemoryPackable] + public sealed partial class GameGoldRecharge : Packet { } - public sealed class TradeRequest : Packet + [MemoryPackable] + public sealed partial class TradeRequest : Packet { } - public sealed class TradeRequestResponse : Packet + [MemoryPackable] + public sealed partial class TradeRequestResponse : Packet { public bool Accept { get; set; } } - public sealed class TradeClose : Packet + [MemoryPackable] + public sealed partial class TradeClose : Packet { } - public sealed class TradeAddGold : Packet + [MemoryPackable] + public sealed partial class TradeAddGold : Packet { public long Gold { get; set; } } - public sealed class TradeAddItem : Packet + [MemoryPackable] + public sealed partial class TradeAddItem : Packet { public CellLinkInfo Cell { get; set; } } - public sealed class TradeConfirm : Packet + [MemoryPackable] + public sealed partial class TradeConfirm : Packet { } - public sealed class GuildCreate : Packet + [MemoryPackable] + public sealed partial class GuildCreate : Packet { public string Name { get; set; } public bool UseGold { get; set; } public int Members { get; set; } public int Storage { get; set; } } - public sealed class GuildEditNotice : Packet + [MemoryPackable] + public sealed partial class GuildEditNotice : Packet { public string Notice { get; set; } } - public sealed class GuildEditMember : Packet + [MemoryPackable] + public sealed partial class GuildEditMember : Packet { public int Index { get; set; } public string Rank { get; set; } public GuildPermission Permission { get; set; } } - public sealed class GuildInviteMember : Packet + [MemoryPackable] + public sealed partial class GuildInviteMember : Packet { public string Name { get; set; } } - public sealed class GuildKickMember : Packet + [MemoryPackable] + public sealed partial class GuildKickMember : Packet { public int Index { get; set; } } - public sealed class GuildTax : Packet + [MemoryPackable] + public sealed partial class GuildTax : Packet { public long Tax { get; set; } } - public sealed class GuildIncreaseMember : Packet + [MemoryPackable] + public sealed partial class GuildIncreaseMember : Packet { } - public sealed class GuildIncreaseStorage : Packet + [MemoryPackable] + public sealed partial class GuildIncreaseStorage : Packet { } - public sealed class GuildResponse : Packet + [MemoryPackable] + public sealed partial class GuildResponse : Packet { public bool Accept { get; set; } } - public sealed class GuildWar : Packet + [MemoryPackable] + public sealed partial class GuildWar : Packet { public string GuildName { get; set; } } - public sealed class GuildRequestConquest : Packet + [MemoryPackable] + public sealed partial class GuildRequestConquest : Packet { public int Index { get; set; } } - public sealed class GuildColour : Packet + [MemoryPackable] + public sealed partial class GuildColour : Packet { + [MemoryPackAllowSerialize] public Color Colour { get; set; } } - public sealed class GuildFlag : Packet + [MemoryPackable] + public sealed partial class GuildFlag : Packet { public int Flag { get; set; } } - public sealed class GuildToggleCastleGates : Packet + [MemoryPackable] + public sealed partial class GuildToggleCastleGates : Packet { } - public sealed class GuildRepairCastleGates : Packet + [MemoryPackable] + public sealed partial class GuildRepairCastleGates : Packet { } - public sealed class GuildRepairCastleGuards : Packet + [MemoryPackable] + public sealed partial class GuildRepairCastleGuards : Packet { } - public sealed class QuestAccept : Packet + [MemoryPackable] + public sealed partial class QuestAccept : Packet { public int Index { get; set; } } - public sealed class QuestComplete : Packet + [MemoryPackable] + public sealed partial class QuestComplete : Packet { public int Index { get; set; } public int ChoiceIndex { get; set; } } - public sealed class QuestTrack : Packet + [MemoryPackable] + public sealed partial class QuestTrack : Packet { public int Index { get; set; } public bool Track { get; set; } } - public sealed class QuestAbandon : Packet + [MemoryPackable] + public sealed partial class QuestAbandon : Packet { public int Index { get; set; } } - public sealed class CompanionUnlock : Packet + [MemoryPackable] + public sealed partial class CompanionUnlock : Packet { public int Index { get; set; } } - public sealed class CompanionAdopt : Packet + [MemoryPackable] + public sealed partial class CompanionAdopt : Packet { public int Index { get; set; } public string Name { get; set; } } - public sealed class CompanionRetrieve : Packet + [MemoryPackable] + public sealed partial class CompanionRetrieve : Packet { public int Index { get; set; } } - - public sealed class CompanionRelease : Packet + + [MemoryPackable] + public sealed partial class CompanionRelease : Packet { public int Index { get; set; } } - public sealed class CompanionStore : Packet + + [MemoryPackable] + public sealed partial class CompanionStore : Packet { public int Index { get; set; } } - public sealed class MarriageResponse : Packet + [MemoryPackable] + public sealed partial class MarriageResponse : Packet { public bool Accept { get; set; } } - public sealed class MarriageMakeRing : Packet + [MemoryPackable] + public sealed partial class MarriageMakeRing : Packet { public int Slot { get; set; } } - public sealed class MarriageTeleport : Packet + [MemoryPackable] + public sealed partial class MarriageTeleport : Packet { } - public sealed class BlockAdd : Packet + [MemoryPackable] + public sealed partial class BlockAdd : Packet { public string Name { get; set; } } - public sealed class BlockRemove : Packet + [MemoryPackable] + public sealed partial class BlockRemove : Packet { public int Index { get; set; } } - public sealed class HelmetToggle : Packet + [MemoryPackable] + public sealed partial class HelmetToggle : Packet { public bool HideHelmet { get; set; } } - public sealed class GenderChange : Packet + [MemoryPackable] + public sealed partial class GenderChange : Packet { public MirGender Gender { get; set; } public int HairType { get; set; } + [MemoryPackAllowSerialize] public Color HairColour { get; set; } } - public sealed class HairChange : Packet + [MemoryPackable] + public sealed partial class HairChange : Packet { public int HairType { get; set; } + [MemoryPackAllowSerialize] public Color HairColour { get; set; } } - public sealed class ArmourDye : Packet + [MemoryPackable] + public sealed partial class ArmourDye : Packet { + [MemoryPackAllowSerialize] public Color ArmourColour { get; set; } } - public sealed class NameChange : Packet + [MemoryPackable] + public sealed partial class NameChange : Packet { public string Name { get; set; } } - public sealed class CaptionChange : Packet + [MemoryPackable] + public sealed partial class CaptionChange : Packet { public string Caption { get; set; } } - public sealed class FortuneCheck : Packet + [MemoryPackable] + public sealed partial class FortuneCheck : Packet { public int ItemIndex { get; set; } } - public sealed class TeleportRing : Packet + [MemoryPackable] + public sealed partial class TeleportRing : Packet { public Point Location { get; set; } public int Index { get; set; } } - public sealed class JoinStarterGuild : Packet + [MemoryPackable] + public sealed partial class JoinStarterGuild : Packet { } - public sealed class NPCAccessoryReset : Packet + [MemoryPackable] + public sealed partial class NPCAccessoryReset : Packet { public CellLinkInfo Cell { get; set; } } - public sealed class NPCWeaponCraft : Packet + [MemoryPackable] + public sealed partial class NPCWeaponCraft : Packet { public RequiredClass Class { get; set; } public CellLinkInfo Template { get; set; } @@ -701,75 +832,89 @@ public sealed class NPCWeaponCraft : Packet public CellLinkInfo Green { get; set; } public CellLinkInfo Grey { get; set; } } - public sealed class NPCAccessoryRefine : Packet + [MemoryPackable] + public sealed partial class NPCAccessoryRefine : Packet { public CellLinkInfo Target { get; set; } public CellLinkInfo OreTarget { get; set; } public List Links { get; set; } public RefineType RefineType { get; set; } } - public sealed class JoinInstance : Packet + [MemoryPackable] + public sealed partial class JoinInstance : Packet { public int Index { get; set; } } - public sealed class SendCompanionFilters : Packet + [MemoryPackable] + public sealed partial class SendCompanionFilters : Packet { public List FilterClass { get; set; } public List FilterRarity { get; set; } public List FilterItemType { get; set; } } - public sealed class ChangeOnlineState : Packet + [MemoryPackable] + public sealed partial class ChangeOnlineState : Packet { public OnlineState State { get; set; } } - public sealed class FriendAdd : Packet + [MemoryPackable] + public sealed partial class FriendAdd : Packet { public string Name { get; set; } } - public sealed class FriendRemove : Packet + [MemoryPackable] + public sealed partial class FriendRemove : Packet { public int Index { get; set; } } - public sealed class IncreaseDiscipline : Packet + [MemoryPackable] + public sealed partial class IncreaseDiscipline : Packet { } - public sealed class LootBoxOpen : Packet + [MemoryPackable] + public sealed partial class LootBoxOpen : Packet { public int Slot { get; set; } } - public sealed class LootBoxReroll : Packet + [MemoryPackable] + public sealed partial class LootBoxReroll : Packet { public int Slot { get; set; } } - public sealed class LootBoxConfirmSelection : Packet + [MemoryPackable] + public sealed partial class LootBoxConfirmSelection : Packet { public int Slot { get; set; } } - public sealed class LootBoxReveal : Packet + [MemoryPackable] + public sealed partial class LootBoxReveal : Packet { public int Slot { get; set; } public int Choice { get; set; } } - public sealed class LootBoxTakeItems : Packet + [MemoryPackable] + public sealed partial class LootBoxTakeItems : Packet { public int Slot { get; set; } public int Choice { get; set; } } - public sealed class BundleOpen : Packet + [MemoryPackable] + public sealed partial class BundleOpen : Packet { public int Slot { get; set; } } - public sealed class BundleConfirm : Packet + [MemoryPackable] + public sealed partial class BundleConfirm : Packet { public int Slot { get; set; } public int Choice { get; set; } diff --git a/LibraryCore/Network/GeneralPackets.cs b/LibraryCore/Network/GeneralPackets.cs index 8b35f5a7..3bc074fe 100644 --- a/LibraryCore/Network/GeneralPackets.cs +++ b/LibraryCore/Network/GeneralPackets.cs @@ -1,24 +1,33 @@ -namespace Library.Network.GeneralPackets +using MemoryPack; + +namespace Library.Network.GeneralPackets { - public sealed class Connected : Packet { } - public sealed class Ping : Packet { } - public sealed class CheckVersion : Packet + [MemoryPackable] + public sealed partial class Connected : Packet { } + [MemoryPackable] + public sealed partial class Ping : Packet { } + [MemoryPackable] + public sealed partial class CheckVersion : Packet { } - public sealed class Version : Packet + [MemoryPackable] + public sealed partial class Version : Packet { public byte[] ClientHash { get; set; } } - public sealed class GoodVersion : Packet + [MemoryPackable] + public sealed partial class GoodVersion : Packet { public byte[] DatabaseKey { get; set; } } - public sealed class PingResponse : Packet + [MemoryPackable] + public sealed partial class PingResponse : Packet { public int Ping { get; set; } } - public sealed class Disconnect : Packet + [MemoryPackable] + public sealed partial class Disconnect : Packet { public DisconnectReason Reason { get; set; } } diff --git a/LibraryCore/Network/Packet.cs b/LibraryCore/Network/Packet.cs index a385049e..06959901 100644 --- a/LibraryCore/Network/Packet.cs +++ b/LibraryCore/Network/Packet.cs @@ -3,127 +3,45 @@ using System.Collections.Generic; using System.Drawing; using System.IO; +using System.Linq; using System.Reflection; +using LibraryCore; +using MemoryPack; +using MemoryPack.Formatters; namespace Library.Network { - public abstract class Packet + [MemoryPackable(GenerateType.NoGenerate)] + public abstract partial class Packet { - private static readonly List Packets; - private static readonly Dictionary> TypeWrite; - private static readonly Dictionary> TypeRead; - public static bool IsClient { get; set; } - public Type PacketType; - + [MemoryPackIgnore] public int Length; + [MemoryPackIgnore] public bool ObserverPacket = true; static Packet() { - Packets = new List(); - - Type[] list = Assembly.GetExecutingAssembly().GetTypes(); - - - foreach (Type type in list) - { - if (type.BaseType != typeof(Packet)) continue; - Packets.Add(type); - } - - Packets.Sort((x1, x2) => - { - if (String.Compare(x1.Namespace, x2.Namespace, StringComparison.Ordinal) == 0) - return String.Compare(x1.Name, x2.Name, StringComparison.Ordinal); - - if (string.Compare(x1.Namespace, @"Library.Network.GeneralPackets", StringComparison.Ordinal) == 0) //We want General Packets shifted To the top. - return -1; - - if (string.Compare(x2.Namespace, @"Library.Network.GeneralPackets", StringComparison.Ordinal) == 0) //We want General Packets shifted To the top. - return 1; - - return String.Compare(x1.Name, x2.Name, StringComparison.Ordinal); - }); - - #region Writes - - TypeWrite = new Dictionary> - { - [typeof(Boolean)] = (v, w) => w.Write((bool)v), - [typeof(Byte)] = (v, w) => w.Write((Byte)v), - [typeof(Byte[])] = (v, w) => - { - w.Write(v != null ? ((Byte[])v).Length : 0); - w.Write(v != null ? (Byte[])v : new byte[0]); - }, - [typeof(Char)] = (v, w) => w.Write((Char)v), - [typeof(Color)] = (v, w) => w.Write(((Color)v).ToArgb()), - [typeof(DateTime)] = (v, w) => w.Write(((DateTime)v).ToBinary()), - [typeof(Decimal)] = (v, w) => w.Write((Decimal)v), - [typeof(Double)] = (v, w) => w.Write((Double)v), - [typeof(Int16)] = (v, w) => w.Write((Int16)v), - [typeof(Int32)] = (v, w) => w.Write((Int32)v), - [typeof(Int64)] = (v, w) => w.Write((Int64)v), - [typeof(Point)] = (v, w) => - { - w.Write(((Point)v).X); - w.Write(((Point)v).Y); - }, - [typeof(SByte)] = (v, w) => w.Write((SByte)v), - [typeof(Single)] = (v, w) => w.Write((Single)v), - [typeof(Size)] = (v, w) => - { - w.Write(((Size)v).Width); - w.Write(((Size)v).Height); - }, - [typeof(String)] = (v, w) => w.Write((String)v ?? string.Empty), - [typeof(TimeSpan)] = (v, w) => w.Write(((TimeSpan)v).Ticks), - [typeof(UInt16)] = (v, w) => w.Write((UInt16)v), - [typeof(UInt32)] = (v, w) => w.Write((UInt32)v), - [typeof(UInt64)] = (v, w) => w.Write((UInt64)v) - }; - - #endregion - - #region Reads - - TypeRead = new Dictionary> - { - [typeof(Boolean)] = (r) => r.ReadBoolean(), - [typeof(Byte)] = (r) => r.ReadByte(), - [typeof(Byte[])] = (r) => r.ReadBytes(r.ReadInt32()), - [typeof(Char)] = (r) => r.ReadChar(), - [typeof(Color)] = (r) => Color.FromArgb(r.ReadInt32()), - [typeof(DateTime)] = (r) => DateTime.FromBinary(r.ReadInt64()), - [typeof(Decimal)] = (r) => r.ReadDecimal(), - [typeof(Double)] = (r) => r.ReadDouble(), - [typeof(Enum)] = (r) => r.ReadInt32(), - [typeof(Int16)] = (r) => r.ReadInt16(), - [typeof(Int32)] = (r) => r.ReadInt32(), - [typeof(Int64)] = (r) => r.ReadInt64(), - [typeof(Point)] = (r) => new Point(r.ReadInt32(), r.ReadInt32()), - [typeof(SByte)] = (r) => r.ReadSByte(), - [typeof(Single)] = (r) => r.ReadSingle(), - [typeof(Size)] = (r) => new Size(r.ReadInt32(), r.ReadInt32()), - [typeof(String)] = (r) => r.ReadString(), - [typeof(TimeSpan)] = (r) => TimeSpan.FromTicks(r.ReadInt64()), - [typeof(UInt16)] = (r) => r.ReadUInt16(), - [typeof(UInt32)] = (r) => r.ReadUInt32(), - [typeof(UInt64)] = (r) => r.ReadUInt64() - }; - - #endregion - + MemoryPackFormatterProvider.Register(new StatsFormatter()); + MemoryPackFormatterProvider.Register(new ColorFormatter()); + + var array = Assembly + .GetExecutingAssembly() + .GetTypes() + .Where(type=>type.IsSubclassOf(typeof(Packet))) + .OrderBy(type=>type.FullName) + .Select((type, index) => ((ushort)index, type)) + .ToArray(); + + var formatter = new DynamicUnionFormatter(array); + MemoryPackFormatterProvider.Register(formatter); } public static Packet ReceivePacket(byte[] rawBytes, out byte[] extra) { extra = rawBytes; - Packet p = null; - if (rawBytes.Length < 4) return null; //4Bytes: Packet Size | int length = rawBytes[3] << 24 | rawBytes[2] << 16 | rawBytes[1] << 8 | rawBytes[0]; @@ -132,305 +50,25 @@ public static Packet ReceivePacket(byte[] rawBytes, out byte[] extra) extra = new byte[rawBytes.Length - length]; Buffer.BlockCopy(rawBytes, length, extra, 0, rawBytes.Length - length); - - - using (MemoryStream stream = new MemoryStream(rawBytes)) - using (BinaryReader reader = new BinaryReader(stream)) - { - stream.Seek(4, SeekOrigin.Begin); - - short id = reader.ReadInt16(); - if (id >= 0 && id < Packets.Count) - { - p = (Packet)Activator.CreateInstance(Packets[id]); - p.PacketType = Packets[id]; - ReadObject(reader, p); - } - } - + + var p = MemoryPackSerializer.Deserialize(rawBytes.AsSpan(4)); p.Length = length; return p; } public byte[] GetPacketBytes() { - byte[] packet; - - using (MemoryStream stream = new MemoryStream()) - using (BinaryWriter writer = new BinaryWriter(stream)) - { - writer.Write((short)Packets.IndexOf(GetType())); - WriteObject(writer, this); - packet = stream.ToArray(); - } - - Length = packet.Length; - using (MemoryStream stream = new MemoryStream()) using (BinaryWriter writer = new BinaryWriter(stream)) { - writer.Write(packet.Length + 4); //| 4Bytes: Packet Size | Data... | - writer.Write(packet); + var array = MemoryPackSerializer.Serialize(this); + writer.Write(array.Length + 4); //| 4Bytes: Packet Size | Data... | + writer.Write(array); + Length = (int)stream.Length; return stream.ToArray(); } } - private static void WriteObject(BinaryWriter writer, object ob) - { - PropertyInfo[] properties = ob.GetType().GetProperties(); - - foreach (PropertyInfo item in properties) - { - if (item.GetCustomAttribute() != null) continue; - - Action writeAction; - if (!TypeWrite.TryGetValue(item.PropertyType, out writeAction)) - { - - if (item.PropertyType.IsClass) - { - object value = item.GetValue(ob); - writer.Write(value != null); - if (value == null) continue; - } - - if (item.PropertyType.IsEnum) - TypeWrite[item.PropertyType.GetEnumUnderlyingType()](item.GetValue(ob), writer); - else if (item.PropertyType.IsGenericType) - { - if (item.PropertyType.GetGenericTypeDefinition() == typeof(List<>)) - { - IList list = (IList)item.GetValue(ob); - - writer.Write(list.Count); - Type genType = item.PropertyType.GetGenericArguments()[0]; - - if (!TypeWrite.TryGetValue(genType, out writeAction)) - { - if (genType.IsEnum) - { - genType = genType.GetEnumUnderlyingType(); - foreach (object x in list) - TypeWrite[genType](x, writer); - } - else - { - foreach (object x in list) - { - writer.Write(x != null); - - if (x == null) continue; - - WriteObject(writer, x); - } - } - } - else - { - foreach (object x in list) - writeAction(x, writer); - } - } - else if (item.PropertyType.GetGenericTypeDefinition() == typeof(SortedDictionary<,>) || item.PropertyType.GetGenericTypeDefinition() == typeof(Dictionary<,>)) - { - IDictionary dictionary = (IDictionary)item.GetValue(ob); - - writer.Write(dictionary.Count); - - Type genKey = item.PropertyType.GetGenericArguments()[0]; - Type genValue = item.PropertyType.GetGenericArguments()[1]; - - Action keyAction = null; - Action valueAction = null; - - - if (!TypeWrite.TryGetValue(genKey, out keyAction)) - { - if (genKey.IsEnum) - keyAction = TypeWrite[genKey.GetEnumUnderlyingType()]; - } - - if (!TypeWrite.TryGetValue(genValue, out valueAction)) - { - if (genValue.IsEnum) - valueAction = TypeWrite[genValue.GetEnumUnderlyingType()]; - } - - foreach (object key in dictionary.Keys) - { - if (keyAction == null) - WriteObject(writer, key); //Not allowed to have Null Key so no point checking. - else - keyAction(key, writer); - - if (valueAction == null) - { - writer.Write(dictionary[key] != null); - if (dictionary[key] == null) continue; - - WriteObject(writer, dictionary[key]); - } - else - valueAction(dictionary[key], writer); - } - } - } - else if (item.PropertyType.IsClass) - WriteObject(writer, item.GetValue(ob)); - else - throw new NotImplementedException($"Not Implemented Exception: WirteObject: Type:{item.PropertyType}."); - - continue; - } - - writeAction(item.GetValue(ob), writer); - } - } - private static void ReadObject(BinaryReader reader, object ob) - { - Type type = ob.GetType(); - PropertyInfo[] properties = type.GetProperties(); - - foreach (PropertyInfo item in properties) - { - if (item.GetCustomAttribute() != null) continue; - - Func readAction; - if (!TypeRead.TryGetValue(item.PropertyType, out readAction)) - { - if (item.PropertyType.IsClass) - { - if (!reader.ReadBoolean()) continue; - item.SetValue(ob, Activator.CreateInstance(item.PropertyType)); - } - - if (item.PropertyType.IsEnum) - item.SetValue(ob, TypeRead[item.PropertyType.GetEnumUnderlyingType()](reader)); - else if (item.PropertyType.IsGenericType) - { - if (item.PropertyType.GetGenericTypeDefinition() == typeof(List<>)) - { - IList list = (IList)item.GetValue(ob); - - int count = reader.ReadInt32(); - Type genType = item.PropertyType.GetGenericArguments()[0]; - if (!TypeRead.TryGetValue(genType, out readAction)) - { - if (genType.IsEnum) - { - genType = genType.GetEnumUnderlyingType(); - - for (int i = 0; i < count; i++) - list.Add(TypeRead[genType](reader)); - } - else - { - for (int i = 0; i < count; i++) - { - if (!reader.ReadBoolean()) continue; - - object value = Activator.CreateInstance(genType); - list.Add(value); - ReadObject(reader, value); - } - } - } - else - { - for (int i = 0; i < count; i++) - list.Add(readAction(reader)); - } - } - else if (item.PropertyType.GetGenericTypeDefinition() == typeof(SortedDictionary<,>) || item.PropertyType.GetGenericTypeDefinition() == typeof(Dictionary<,>)) - { - IDictionary dictionary = (IDictionary)item.GetValue(ob); - - int count = reader.ReadInt32(); - - Type genKey = item.PropertyType.GetGenericArguments()[0]; - Type genValue = item.PropertyType.GetGenericArguments()[1]; - - Func keyAction = null; - Func valueAction = null; - - if (!TypeRead.TryGetValue(genKey, out keyAction)) - { - if (genKey.IsEnum) - keyAction = TypeRead[genKey.GetEnumUnderlyingType()]; - } - - if (!TypeRead.TryGetValue(genValue, out valueAction)) - { - if (genValue.IsEnum) - valueAction = TypeRead[genValue.GetEnumUnderlyingType()]; - } - - for (int i = 0; i < count; i++) - { - object key; - object value; - - if (keyAction == null) - { - key = Activator.CreateInstance(genKey); //Never Null as it's a key - - ReadObject(reader, key); - } - else - key = keyAction(reader); - - if (valueAction == null) - { - if (!reader.ReadBoolean()) - { - value = null; - } - else - { - value = Activator.CreateInstance(genValue); - - ReadObject(reader, value); - } - } - else - value = valueAction(reader); - - dictionary[key] = value; - } - } - } - else if (item.PropertyType.IsClass) - ReadObject(reader, item.GetValue(ob)); - else - throw new NotImplementedException($"Not Implemented Exception: ReadObject: Type: {item.PropertyType}."); - - continue; - } - - item.SetValue(ob, readAction(reader)); - } - - MethodInfo[] Methods = type.GetMethods(); - - foreach (MethodInfo item in Methods) - { - if (item.GetCustomAttribute() == null) continue; - - item.Invoke(ob, null); - } - } - } - - [AttributeUsage(AttributeTargets.Property)] - internal class IgnorePropertyPacket : Attribute - { - - } - - [AttributeUsage(AttributeTargets.Method)] - internal class CompleteObject : Attribute - { - } } diff --git a/LibraryCore/Network/ServerPackets.cs b/LibraryCore/Network/ServerPackets.cs index 2ef3368c..dd06616f 100644 --- a/LibraryCore/Network/ServerPackets.cs +++ b/LibraryCore/Network/ServerPackets.cs @@ -3,21 +3,25 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; +using MemoryPack; namespace Library.Network.ServerPackets { - public sealed class NewAccount : Packet + [MemoryPackable] + public sealed partial class NewAccount : Packet { public NewAccountResult Result { get; set; } } - public sealed class ChangePassword : Packet + [MemoryPackable] + public sealed partial class ChangePassword : Packet { public ChangePasswordResult Result { get; set; } public string Message { get; set; } public TimeSpan Duration { get; set; } } - public sealed class Login : Packet + [MemoryPackable] + public sealed partial class Login : Packet { public LoginResult Result { get; set; } @@ -33,45 +37,54 @@ public sealed class Login : Packet public bool TestServer { get; set; } } - public sealed class RequestPasswordReset : Packet + [MemoryPackable] + public sealed partial class RequestPasswordReset : Packet { public RequestPasswordResetResult Result { get; set; } public string Message { get; set; } public TimeSpan Duration { get; set; } } - public sealed class ResetPassword : Packet + [MemoryPackable] + public sealed partial class ResetPassword : Packet { public ResetPasswordResult Result { get; set; } } - public sealed class Activation : Packet + [MemoryPackable] + public sealed partial class Activation : Packet { public ActivationResult Result { get; set; } } - public sealed class RequestActivationKey : Packet + [MemoryPackable] + public sealed partial class RequestActivationKey : Packet { public RequestActivationKeyResult Result { get; set; } public TimeSpan Duration { get; set; } } - public sealed class SelectLogout : Packet + [MemoryPackable] + public sealed partial class SelectLogout : Packet { } - public sealed class GameLogout : Packet + [MemoryPackable] + public sealed partial class GameLogout : Packet { public List Characters { get; set; } } - public sealed class NewCharacter : Packet + [MemoryPackable] + public sealed partial class NewCharacter : Packet { public NewCharacterResult Result { get; set; } public SelectInfo Character { get; set; } } - public sealed class DeleteCharacter : Packet + [MemoryPackable] + public sealed partial class DeleteCharacter : Packet { public DeleteCharacterResult Result { get; set; } public int DeletedIndex { get; set; } } - public sealed class StartGame : Packet + [MemoryPackable] + public sealed partial class StartGame : Packet { public StartGameResult Result { get; set; } @@ -80,40 +93,47 @@ public sealed class StartGame : Packet public StartInformation StartInformation { get; set; } } - public sealed class MapChanged : Packet + [MemoryPackable] + public sealed partial class MapChanged : Packet { public int MapIndex { get; set; } public int InstanceIndex { get; set; } } - public sealed class UserLocation : Packet + [MemoryPackable] + public sealed partial class UserLocation : Packet { public MirDirection Direction { get; set; } public Point Location { get; set; } } - public sealed class ObjectRemove : Packet + [MemoryPackable] + public sealed partial class ObjectRemove : Packet { public uint ObjectID { get; set; } } - public sealed class ObjectTurn : Packet + [MemoryPackable] + public sealed partial class ObjectTurn : Packet { public uint ObjectID { get; set; } public MirDirection Direction { get; set; } public Point Location { get; set; } public TimeSpan Slow { get; set; } } - public sealed class ObjectHarvest : Packet + [MemoryPackable] + public sealed partial class ObjectHarvest : Packet { public uint ObjectID { get; set; } public MirDirection Direction { get; set; } public Point Location { get; set; } public TimeSpan Slow { get; set; } } - public sealed class ObjectMount : Packet + [MemoryPackable] + public sealed partial class ObjectMount : Packet { public uint ObjectID { get; set; } public HorseType Horse { get; set; } } - public sealed class ObjectFishing : Packet + [MemoryPackable] + public sealed partial class ObjectFishing : Packet { public uint ObjectID { get; set; } public FishingState State { get; set; } @@ -121,7 +141,8 @@ public sealed class ObjectFishing : Packet public Point FloatLocation { get; set; } public bool FishFound { get; set; } } - public sealed class FishingStats : Packet + [MemoryPackable] + public sealed partial class FishingStats : Packet { public bool CanAutoCast { get; set; } public int CurrentPoints { get; set; } @@ -131,7 +152,8 @@ public sealed class FishingStats : Packet public int MovementSpeed { get; set; } //1 time public int RequiredAccuracy { get; set; } //1 time } - public sealed class ObjectMove : Packet + [MemoryPackable] + public sealed partial class ObjectMove : Packet { public uint ObjectID { get; set; } public MirDirection Direction { get; set; } @@ -139,7 +161,8 @@ public sealed class ObjectMove : Packet public int Distance { get; set; } public TimeSpan Slow { get; set; } } - public sealed class ObjectDash : Packet + [MemoryPackable] + public sealed partial class ObjectDash : Packet { public uint ObjectID { get; set; } public MirDirection Direction { get; set; } @@ -147,13 +170,16 @@ public sealed class ObjectDash : Packet public int Distance { get; set; } public MagicType Magic { get; set; } } - public sealed class ObjectPushed : Packet + [MemoryPackable] + public sealed partial class ObjectPushed : Packet { public uint ObjectID { get; set; } public MirDirection Direction { get; set; } public Point Location { get; set; } } - public sealed class ObjectIdle : Packet + + [MemoryPackable] + public sealed partial class ObjectIdle : Packet { public uint ObjectID { get; set; } public MirDirection Direction { get; set; } @@ -161,7 +187,8 @@ public sealed class ObjectIdle : Packet public int Type { get; set; } } - public sealed class ObjectAttack : Packet + [MemoryPackable] + public sealed partial class ObjectAttack : Packet { public uint ObjectID { get; set; } @@ -175,7 +202,8 @@ public sealed class ObjectAttack : Packet public TimeSpan Slow { get; set; } } - public sealed class ObjectRangeAttack : Packet + [MemoryPackable] + public sealed partial class ObjectRangeAttack : Packet { public uint ObjectID { get; set; } @@ -187,7 +215,8 @@ public sealed class ObjectRangeAttack : Packet public List Targets { get; set; } = new List(); } - public sealed class ObjectMagic : Packet + [MemoryPackable] + public sealed partial class ObjectMagic : Packet { public uint ObjectID { get; set; } @@ -202,7 +231,8 @@ public sealed class ObjectMagic : Packet public TimeSpan Slow { get; set; } } - public sealed class ObjectProjectile : Packet + [MemoryPackable] + public sealed partial class ObjectProjectile : Packet { public uint ObjectID { get; set; } @@ -214,7 +244,8 @@ public sealed class ObjectProjectile : Packet public List Locations { get; set; } = new List(); } - public sealed class ObjectMining : Packet + [MemoryPackable] + public sealed partial class ObjectMining : Packet { public uint ObjectID { get; set; } @@ -224,54 +255,63 @@ public sealed class ObjectMining : Packet public TimeSpan Slow { get; set; } public bool Effect { get; set; } } - public sealed class ObjectPetOwnerChanged : Packet + [MemoryPackable] + public sealed partial class ObjectPetOwnerChanged : Packet { public uint ObjectID { get; set; } public string PetOwner { get; set; } } - public sealed class ObjectShow : Packet + [MemoryPackable] + public sealed partial class ObjectShow : Packet { public uint ObjectID { get; set; } public MirDirection Direction { get; set; } public Point Location { get; set; } } - public sealed class ObjectHide : Packet + [MemoryPackable] + public sealed partial class ObjectHide : Packet { public uint ObjectID { get; set; } public MirDirection Direction { get; set; } public Point Location { get; set; } } - public sealed class ObjectEffect : Packet + [MemoryPackable] + public sealed partial class ObjectEffect : Packet { public uint ObjectID { get; set; } public Effect Effect { get; set; } } - public sealed class MapEffect : Packet + [MemoryPackable] + public sealed partial class MapEffect : Packet { public Point Location { get; set; } public Effect Effect { get; set; } public MirDirection Direction { get; set; } } - public sealed class ObjectBuffAdd : Packet + [MemoryPackable] + public sealed partial class ObjectBuffAdd : Packet { public uint ObjectID { get; set; } public BuffType Type { get; set; } public int Extra { get;set; } } - public sealed class ObjectBuffRemove : Packet + [MemoryPackable] + public sealed partial class ObjectBuffRemove : Packet { public uint ObjectID { get; set; } public BuffType Type { get; set; } } - public sealed class ObjectPoison : Packet + [MemoryPackable] + public sealed partial class ObjectPoison : Packet { public uint ObjectID { get; set; } public PoisonType Poison { get; set; } } - public sealed class ObjectPlayer : Packet + [MemoryPackable] + public sealed partial class ObjectPlayer : Packet { public int Index { get; set; } @@ -279,6 +319,7 @@ public sealed class ObjectPlayer : Packet public string Name { get; set; } public string Caption { get; set; } + [MemoryPackAllowSerialize] public Color NameColour { get; set; } public string GuildName { get; set; } @@ -289,11 +330,13 @@ public sealed class ObjectPlayer : Packet public MirGender Gender { get; set; } public int HairType { get; set; } + [MemoryPackAllowSerialize] public Color HairColour { get; set; } public int Weapon { get; set; } public int Shield { get; set; } public int Armour { get; set; } public int Costume { get; set; } + [MemoryPackAllowSerialize] public Color ArmourColour { get; set; } public ExteriorEffect ArmourEffect { get; set; } public ExteriorEffect EmblemEffect { get; set; } @@ -319,11 +362,13 @@ public sealed class ObjectPlayer : Packet public bool HideHead; } - public sealed class ObjectMonster : Packet + [MemoryPackable] + public sealed partial class ObjectMonster : Packet { public uint ObjectID { get; set; } public int MonsterIndex { get; set; } public string CustomName { get; set; } + [MemoryPackAllowSerialize] public Color NameColour { get; set; } public string PetOwner { get; set; } @@ -343,12 +388,14 @@ public sealed class ObjectMonster : Packet public bool Extra { get; set; } public int Extra1 { get; set; } + [MemoryPackAllowSerialize] public Color Colour { get; set; } public ClientCompanionObject CompanionObject { get; set; } } - public sealed class ObjectNPC : Packet + [MemoryPackable] + public sealed partial class ObjectNPC : Packet { public uint ObjectID { get; set; } @@ -357,7 +404,8 @@ public sealed class ObjectNPC : Packet public MirDirection Direction { get; set; } } - public sealed class ObjectItem : Packet + [MemoryPackable] + public sealed partial class ObjectItem : Packet { public uint ObjectID { get; set; } @@ -365,7 +413,8 @@ public sealed class ObjectItem : Packet public Point Location { get; set; } } - public sealed class ObjectSpell : Packet + [MemoryPackable] + public sealed partial class ObjectSpell : Packet { public uint ObjectID { get; set; } public MirDirection Direction { get; set; } @@ -374,24 +423,29 @@ public sealed class ObjectSpell : Packet public int Power { get; set; } } - public sealed class ObjectSpellChanged : Packet + [MemoryPackable] + public sealed partial class ObjectSpellChanged : Packet { public uint ObjectID { get; set; } public int Power { get; set; } } - public sealed class ObjectNameColour : Packet + [MemoryPackable] + public sealed partial class ObjectNameColour : Packet { public uint ObjectID { get; set; } + [MemoryPackAllowSerialize] public Color Colour { get; set; } } - public sealed class PlayerUpdate : Packet + [MemoryPackable] + public sealed partial class PlayerUpdate : Packet { public uint ObjectID { get; set; } public int Weapon { get; set; } public int Shield { get; set; } public int Armour { get; set; } public int Costume { get; set; } + [MemoryPackAllowSerialize] public Color ArmourColour { get; set; } public ExteriorEffect ArmourEffect { get; set; } public ExteriorEffect EmblemEffect { get; set; } @@ -406,86 +460,95 @@ public sealed class PlayerUpdate : Packet } - public sealed class MagicToggle : Packet + [MemoryPackable] + public sealed partial class MagicToggle : Packet { public MagicType Magic { get; set; } public bool CanUse { get; set; } } - public sealed class DayChanged : Packet + [MemoryPackable] + public sealed partial class DayChanged : Packet { public float DayTime { get; set; } } - public sealed class TimeOfDayChanged : Packet - { - public TimeOfDay TimeOfDay { get; set; } - } - - public sealed class InformMaxExperience : Packet + [MemoryPackable] + public sealed partial class InformMaxExperience : Packet { public decimal MaxExperience { get; set; } } - public sealed class LevelChanged : Packet + [MemoryPackable] + public sealed partial class LevelChanged : Packet { public int Level { get; set; } public decimal Experience { get; set; } public decimal MaxExperience { get; set; } } - public sealed class ObjectLeveled : Packet + [MemoryPackable] + public sealed partial class ObjectLeveled : Packet { public uint ObjectID { get; set; } } - public sealed class ObjectRevive : Packet + [MemoryPackable] + public sealed partial class ObjectRevive : Packet { public uint ObjectID { get; set; } public Point Location { get; set; } public bool Effect { get; set; } } - public sealed class GainedExperience : Packet + [MemoryPackable] + public sealed partial class GainedExperience : Packet { public decimal Amount { get; set; } } - public sealed class NewMagic : Packet + [MemoryPackable] + public sealed partial class NewMagic : Packet { public ClientUserMagic Magic { get; set; } } - public sealed class MagicLeveled : Packet + [MemoryPackable] + public sealed partial class MagicLeveled : Packet { public int InfoIndex { get; set; } + [MemoryPackIgnore] public MagicInfo Info; public int Level { get; set; } public long Experience { get; set; } - [CompleteObject] + [MemoryPackOnDeserialized] public void Complete() { Info = Globals.MagicInfoList.Binding.FirstOrDefault(x => x.Index == InfoIndex); } } - public sealed class MagicCooldown : Packet + [MemoryPackable] + public sealed partial class MagicCooldown : Packet { public int InfoIndex { get; set; } public int Delay { get; set; } + [MemoryPackIgnore] public MagicInfo Info; - [CompleteObject] + [MemoryPackOnDeserialized] public void Complete() { Info = Globals.MagicInfoList.Binding.FirstOrDefault(x => x.Index == InfoIndex); } } - public sealed class StatsUpdate : Packet + [MemoryPackable] + public sealed partial class StatsUpdate : Packet { public Stats Stats { get; set; } public Stats HermitStats { get; set; } public int HermitPoints { get; set; } } - public sealed class HealthChanged : Packet + [MemoryPackable] + public sealed partial class HealthChanged : Packet { public uint ObjectID { get; set; } public int Change { get; set; } @@ -493,25 +556,29 @@ public sealed class HealthChanged : Packet public bool Block { get; set; } public bool Critical { get; set; } } - public sealed class ObjectStats : Packet + [MemoryPackable] + public sealed partial class ObjectStats : Packet { public uint ObjectID { get; set; } public Stats Stats { get; set; } } - public sealed class ManaChanged : Packet + [MemoryPackable] + public sealed partial class ManaChanged : Packet { public uint ObjectID { get; set; } public int Change { get; set; } } - public sealed class FocusChanged : Packet + [MemoryPackable] + public sealed partial class FocusChanged : Packet { public uint ObjectID { get; set; } public int Change { get; set; } } - public sealed class ObjectStruck : Packet + [MemoryPackable] + public sealed partial class ObjectStruck : Packet { public uint ObjectID { get; set; } public MirDirection Direction { get; set; } @@ -519,13 +586,15 @@ public sealed class ObjectStruck : Packet public uint AttackerID { get; set; } public Element Element { get; set; } } - public sealed class ObjectDied : Packet + [MemoryPackable] + public sealed partial class ObjectDied : Packet { public uint ObjectID { get; set; } public MirDirection Direction { get; set; } public Point Location { get; set; } } - public sealed class ObjectHarvested : Packet + [MemoryPackable] + public sealed partial class ObjectHarvested : Packet { public uint ObjectID { get; set; } public MirDirection Direction { get; set; } @@ -534,11 +603,13 @@ public sealed class ObjectHarvested : Packet - public sealed class ItemsGained : Packet + [MemoryPackable] + public sealed partial class ItemsGained : Packet { public List Items { get; set; } } - public sealed class ItemMove : Packet + [MemoryPackable] + public sealed partial class ItemMove : Packet { public GridType FromGrid { get; set; } public GridType ToGrid { get; set; } @@ -549,14 +620,16 @@ public sealed class ItemMove : Packet public bool Success { get; set; } } - public sealed class ItemSort : Packet + [MemoryPackable] + public sealed partial class ItemSort : Packet { public GridType Grid { get; set; } public List Items { get; set; } public bool Success { get; set; } } - public sealed class ItemSplit : Packet + [MemoryPackable] + public sealed partial class ItemSplit : Packet { public GridType Grid { get; set; } public int Slot { get; set; } @@ -566,14 +639,16 @@ public sealed class ItemSplit : Packet public bool Success { get; set; } } - public sealed class ItemDelete : Packet + [MemoryPackable] + public sealed partial class ItemDelete : Packet { public GridType Grid { get; set; } public int Slot { get; set; } public bool Success { get; set; } } - public sealed class ItemLock : Packet + [MemoryPackable] + public sealed partial class ItemLock : Packet { public GridType Grid { get; set; } public int Slot { get; set; } @@ -581,35 +656,41 @@ public sealed class ItemLock : Packet } - public sealed class ItemUseDelay : Packet + [MemoryPackable] + public sealed partial class ItemUseDelay : Packet { public TimeSpan Delay { get; set; } } - public sealed class ItemChanged : Packet + [MemoryPackable] + public sealed partial class ItemChanged : Packet { public CellLinkInfo Link { get; set; } public bool Success { get; set; } } - public sealed class ItemStatsChanged : Packet + [MemoryPackable] + public sealed partial class ItemStatsChanged : Packet { public GridType GridType { get; set; } public int Slot { get; set; } public Stats NewStats { get; set; } } - public sealed class ItemStatsRefreshed : Packet + [MemoryPackable] + public sealed partial class ItemStatsRefreshed : Packet { public GridType GridType { get; set; } public int Slot { get; set; } public Stats NewStats { get; set; } } - public sealed class ItemDurability : Packet + [MemoryPackable] + public sealed partial class ItemDurability : Packet { public GridType GridType { get; set; } public int Slot { get; set; } public int CurrentDurability { get; set; } } - public sealed class ItemExperience : Packet + [MemoryPackable] + public sealed partial class ItemExperience : Packet { public CellLinkInfo Target { get; set; } public decimal Experience { get; set; } @@ -617,7 +698,8 @@ public sealed class ItemExperience : Packet public UserItemFlags Flags { get; set; } } - public sealed class Chat : Packet + [MemoryPackable] + public sealed partial class Chat : Packet { public uint ObjectID { get; set; } public string Text { get; set; } @@ -626,33 +708,38 @@ public sealed class Chat : Packet public bool OverheadOnly { get; set; } } - public sealed class NPCResponse : Packet + [MemoryPackable] + public sealed partial class NPCResponse : Packet { public uint ObjectID { get; set; } public int Index { get; set; } public List Values { get; set; } + [MemoryPackIgnore] public NPCPage Page; - [CompleteObject] + [MemoryPackOnDeserialized] public void Complete() { Page = Globals.NPCPageList.Binding.FirstOrDefault(x => x.Index == Index); } } - public sealed class ItemsChanged : Packet + [MemoryPackable] + public sealed partial class ItemsChanged : Packet { public List Links { get; set; } public bool Success { get; set; } } - public sealed class NPCRepair : Packet + [MemoryPackable] + public sealed partial class NPCRepair : Packet { public List Links { get; set; } public bool Special { get; set; } public bool Success { get; set; } public TimeSpan SpecialRepairDelay { get; set; } } - public sealed class NPCRefinementStone : Packet + [MemoryPackable] + public sealed partial class NPCRefinementStone : Packet { public List IronOres { get; set; } public List SilverOres { get; set; } @@ -660,7 +747,8 @@ public sealed class NPCRefinementStone : Packet public List GoldOres { get; set; } public List Crystal { get; set; } } - public sealed class NPCRefine : Packet + [MemoryPackable] + public sealed partial class NPCRefine : Packet { public RefineType RefineType { get; set; } public RefineQuality RefineQuality { get; set; } @@ -669,7 +757,8 @@ public sealed class NPCRefine : Packet public List Specials { get; set; } public bool Success { get; set; } } - public sealed class NPCMasterRefine : Packet + [MemoryPackable] + public sealed partial class NPCMasterRefine : Packet { public List Fragment1s { get; set; } public List Fragment2s { get; set; } @@ -679,17 +768,20 @@ public sealed class NPCMasterRefine : Packet public bool Success { get; set; } } - public sealed class NPCClose : Packet + [MemoryPackable] + public sealed partial class NPCClose : Packet { } - public sealed class NPCAccessoryLevelUp : Packet + [MemoryPackable] + public sealed partial class NPCAccessoryLevelUp : Packet { public CellLinkInfo Target { get; set; } public List Links { get; set; } } - public sealed class NPCAccessoryUpgrade : Packet + [MemoryPackable] + public sealed partial class NPCAccessoryUpgrade : Packet { public CellLinkInfo Target { get; set; } public RefineType RefineType { get; set; } @@ -697,70 +789,85 @@ public sealed class NPCAccessoryUpgrade : Packet } - public sealed class NPCRefineRetrieve : Packet + [MemoryPackable] + public sealed partial class NPCRefineRetrieve : Packet { public int Index { get; set; } } - public sealed class RefineList : Packet + [MemoryPackable] + public sealed partial class RefineList : Packet { public List List { get; set; } } - public sealed class GroupSwitch : Packet + [MemoryPackable] + public sealed partial class GroupSwitch : Packet { public bool Allow { get; set; } } - public sealed class GroupMember : Packet + [MemoryPackable] + public sealed partial class GroupMember : Packet { public uint ObjectID { get; set; } public string Name { get; set; } } - public sealed class GroupRemove : Packet + [MemoryPackable] + public sealed partial class GroupRemove : Packet { public uint ObjectID { get; set; } } - public sealed class GroupInvite : Packet + [MemoryPackable] + public sealed partial class GroupInvite : Packet { public string Name { get; set; } } - public sealed class BuffAdd : Packet + [MemoryPackable] + public sealed partial class BuffAdd : Packet { public ClientBuffInfo Buff { get; set; } } - public sealed class BuffRemove : Packet + [MemoryPackable] + public sealed partial class BuffRemove : Packet { public int Index { get; set; } } - public sealed class BuffChanged : Packet + [MemoryPackable] + public sealed partial class BuffChanged : Packet { public int Index { get; set; } public Stats Stats { get; set; } } - public sealed class BuffTime : Packet + [MemoryPackable] + public sealed partial class BuffTime : Packet { public int Index { get; set; } public TimeSpan Time { get; set; } } - public sealed class BuffPaused : Packet + [MemoryPackable] + public sealed partial class BuffPaused : Packet { public int Index { get; set; } public bool Paused { get; set; } } - public sealed class SafeZoneChanged : Packet + [MemoryPackable] + public sealed partial class SafeZoneChanged : Packet { public bool InSafeZone { get; set; } } - public sealed class CombatTime : Packet + [MemoryPackable] + public sealed partial class CombatTime : Packet { } - public sealed class Inspect : Packet + [MemoryPackable] + public sealed partial class Inspect : Packet { public string Name { get; set; } public string GuildName { get; set; } public string GuildRank { get; set; } public int GuildFlag { get; set; } = -1; + [MemoryPackAllowSerialize] public Color GuildColour { get; set; } public string Partner { get; set; } public MirClass Class { get; set; } @@ -771,6 +878,7 @@ public sealed class Inspect : Packet //public int HermitPoints { get; set; } public List Items { get; set; } public int Hair { get; set; } + [MemoryPackAllowSerialize] public Color HairColour { get; set; } public int Fame { get; set; } @@ -779,7 +887,8 @@ public sealed class Inspect : Packet public bool Ranking { get; set; } } - public sealed class Rankings : Packet + [MemoryPackable] + public sealed partial class Rankings : Packet { public bool OnlineOnly { get; set; } public RequiredClass Class { get; set; } @@ -789,22 +898,26 @@ public sealed class Rankings : Packet public List Ranks { get; set; } } - public sealed class RankSearch : Packet + [MemoryPackable] + public sealed partial class RankSearch : Packet { public RankInfo Rank { get; set; } } - public sealed class StartObserver : Packet + [MemoryPackable] + public sealed partial class StartObserver : Packet { public StartInformation StartInformation { get; set; } public List Items { get; set; } } - public sealed class ObservableSwitch : Packet + [MemoryPackable] + public sealed partial class ObservableSwitch : Packet { public bool Allow { get; set; } } - public sealed class MarketPlaceHistory : Packet + [MemoryPackable] + public sealed partial class MarketPlaceHistory : Packet { public int Index { get; set; } public long SaleCount { get; set; } @@ -813,86 +926,103 @@ public sealed class MarketPlaceHistory : Packet public int Display { get; set; } } - public sealed class MarketPlaceConsign : Packet + [MemoryPackable] + public sealed partial class MarketPlaceConsign : Packet { public List Consignments { get; set; } } - public sealed class MarketPlaceSearch : Packet + [MemoryPackable] + public sealed partial class MarketPlaceSearch : Packet { public int Count { get; set; } public List Results { get; set; } } - public sealed class MarketPlaceSearchCount : Packet + [MemoryPackable] + public sealed partial class MarketPlaceSearchCount : Packet { public int Count { get; set; } } - public sealed class MarketPlaceSearchIndex : Packet + [MemoryPackable] + public sealed partial class MarketPlaceSearchIndex : Packet { public int Index { get; set; } public ClientMarketPlaceInfo Result { get; set; } } - public sealed class MarketPlaceBuy : Packet + [MemoryPackable] + public sealed partial class MarketPlaceBuy : Packet { public int Index { get; set; } public long Count { get; set; } public bool Success { get; set; } } - public sealed class MarketPlaceStoreBuy : Packet + [MemoryPackable] + public sealed partial class MarketPlaceStoreBuy : Packet { } - public sealed class MarketPlaceConsignChanged : Packet + [MemoryPackable] + public sealed partial class MarketPlaceConsignChanged : Packet { public int Index { get; set; } public long Count { get; set; } } - public sealed class MailList : Packet + [MemoryPackable] + public sealed partial class MailList : Packet { public List Mail { get; set; } } - public sealed class MailNew : Packet + [MemoryPackable] + public sealed partial class MailNew : Packet { public ClientMailInfo Mail { get; set; } } - public sealed class MailDelete : Packet + [MemoryPackable] + public sealed partial class MailDelete : Packet { public int Index { get; set; } } - public sealed class MailItemDelete : Packet + [MemoryPackable] + public sealed partial class MailItemDelete : Packet { public int Index { get; set; } public int Slot { get; set; } } - public sealed class MailSend : Packet + [MemoryPackable] + public sealed partial class MailSend : Packet { } - public sealed class ChangeAttackMode : Packet + [MemoryPackable] + public sealed partial class ChangeAttackMode : Packet { public AttackMode Mode { get; set; } } - public sealed class ChangePetMode : Packet + [MemoryPackable] + public sealed partial class ChangePetMode : Packet { public PetMode Mode { get; set; } } - public sealed class CurrencyChanged : Packet + [MemoryPackable] + public sealed partial class CurrencyChanged : Packet { public int CurrencyIndex { get; set; } public long Amount { get; set; } } - public sealed class MountFailed : Packet + [MemoryPackable] + public sealed partial class MountFailed : Packet { public HorseType Horse { get; set; } } - public sealed class WeightUpdate : Packet + [MemoryPackable] + public sealed partial class WeightUpdate : Packet { public int BagWeight { get; set; } public int WearWeight { get; set; } @@ -900,65 +1030,79 @@ public sealed class WeightUpdate : Packet } - public sealed class TradeRequest : Packet + [MemoryPackable] + public sealed partial class TradeRequest : Packet { public string Name { get; set; } } - public sealed class TradeOpen : Packet + [MemoryPackable] + public sealed partial class TradeOpen : Packet { public string Name { get; set; } } - public sealed class TradeClose : Packet { } + [MemoryPackable] + public sealed partial class TradeClose : Packet { } - public sealed class TradeAddItem : Packet + [MemoryPackable] + public sealed partial class TradeAddItem : Packet { public CellLinkInfo Cell { get; set; } public bool Success { get; set; } } - public sealed class TradeAddGold : Packet + [MemoryPackable] + public sealed partial class TradeAddGold : Packet { public long Gold { get; set; } } - public sealed class TradeItemAdded : Packet + [MemoryPackable] + public sealed partial class TradeItemAdded : Packet { public ClientUserItem Item { get; set; } } - public sealed class TradeGoldAdded : Packet + [MemoryPackable] + public sealed partial class TradeGoldAdded : Packet { public long Gold { get; set; } } - public sealed class TradeUnlock : Packet { } + [MemoryPackable] + public sealed partial class TradeUnlock : Packet { } - public sealed class GuildCreate : Packet + [MemoryPackable] + public sealed partial class GuildCreate : Packet { } - public sealed class GuildInfo : Packet + [MemoryPackable] + public sealed partial class GuildInfo : Packet { public ClientGuildInfo Guild { get; set; } } - public sealed class GuildNoticeChanged : Packet + [MemoryPackable] + public sealed partial class GuildNoticeChanged : Packet { public string Notice { get; set; } } - public sealed class GuildNewItem : Packet + [MemoryPackable] + public sealed partial class GuildNewItem : Packet { public int Slot { get; set; } public ClientUserItem Item { get; set; } //public int Count { get; set; } } - public sealed class GuildGetItem : Packet + [MemoryPackable] + public sealed partial class GuildGetItem : Packet { public GridType Grid { get; set; } public int Slot { get; set; } public ClientUserItem Item { get; set; } } - public sealed class GuildUpdate : Packet + [MemoryPackable] + public sealed partial class GuildUpdate : Packet { public int MemberLimit { get; set; } public int StorageLimit { get; set; } @@ -975,98 +1119,117 @@ public sealed class GuildUpdate : Packet public string DefaultRank { get; set; } public GuildPermission DefaultPermission { get; set; } + [MemoryPackAllowSerialize] public Color Colour { get; set; } public int Flag { get; set; } public List Members { get; set; } } - public sealed class GuildKick : Packet + [MemoryPackable] + public sealed partial class GuildKick : Packet { public int Index { get; set; } } - public sealed class GuildTax : Packet + [MemoryPackable] + public sealed partial class GuildTax : Packet { } - public sealed class GuildIncreaseMember : Packet + [MemoryPackable] + public sealed partial class GuildIncreaseMember : Packet { } - public sealed class GuildIncreaseStorage : Packet + [MemoryPackable] + public sealed partial class GuildIncreaseStorage : Packet { } - public sealed class GuildInviteMember : Packet + [MemoryPackable] + public sealed partial class GuildInviteMember : Packet { } - public sealed class GuildInvite : Packet + [MemoryPackable] + public sealed partial class GuildInvite : Packet { public string Name { get; set; } public string GuildName { get; set; } } - public sealed class GuildStats : Packet + [MemoryPackable] + public sealed partial class GuildStats : Packet { public int Index { get; set; } public Stats Stats { get; set; } } - public sealed class GuildMemberOffline : Packet + [MemoryPackable] + public sealed partial class GuildMemberOffline : Packet { public int Index { get; set; } } - public sealed class GuildMemberOnline : Packet + [MemoryPackable] + public sealed partial class GuildMemberOnline : Packet { public int Index { get; set; } public string Name { get; set; } public uint ObjectID { get; set; } } - public sealed class GuildMemberContribution : Packet + [MemoryPackable] + public sealed partial class GuildMemberContribution : Packet { public int Index { get; set; } public long Contribution { get; set; } } - public sealed class GuildDayReset : Packet + [MemoryPackable] + public sealed partial class GuildDayReset : Packet { } - public sealed class GuildFundsChanged : Packet + [MemoryPackable] + public sealed partial class GuildFundsChanged : Packet { public long Change { get; set; } } - public sealed class GuildChanged : Packet + [MemoryPackable] + public sealed partial class GuildChanged : Packet { public uint ObjectID { get; set; } public string GuildName { get; set; } public string GuildRank { get; set; } } - public sealed class GuildWarFinished : Packet + [MemoryPackable] + public sealed partial class GuildWarFinished : Packet { public string GuildName { get; set; } } - public sealed class GuildWar : Packet + [MemoryPackable] + public sealed partial class GuildWar : Packet { public bool Success { get; set; } } - public sealed class GuildWarStarted : Packet + [MemoryPackable] + public sealed partial class GuildWarStarted : Packet { public string GuildName { get; set; } public TimeSpan Duration { get; set; } } - public sealed class GuildConquestDate : Packet + [MemoryPackable] + public sealed partial class GuildConquestDate : Packet { public int Index { get; set; } public TimeSpan WarTime { get; set; } + [MemoryPackIgnore] public DateTime WarDate; - [CompleteObject] + [MemoryPackOnDeserialized] public void Update() { if (WarTime == TimeSpan.MinValue) @@ -1075,80 +1238,98 @@ public void Update() WarDate = Time.Now + WarTime; } } - public sealed class GuildCastleInfo : Packet + [MemoryPackable] + public sealed partial class GuildCastleInfo : Packet { public int Index { get; set; } public string Owner { get; set; } } - public sealed class GuildConquestStarted : Packet + [MemoryPackable] + public sealed partial class GuildConquestStarted : Packet { public int Index { get; set; } } - public sealed class GuildConquestFinished : Packet + [MemoryPackable] + public sealed partial class GuildConquestFinished : Packet { public int Index { get; set; } } - public sealed class ReviveTimers : Packet + [MemoryPackable] + public sealed partial class ReviveTimers : Packet { public TimeSpan ItemReviveTime { get; set; } public TimeSpan ReincarnationPillTime { get; set; } } - public sealed class QuestChanged : Packet + [MemoryPackable] + public sealed partial class QuestChanged : Packet { public ClientUserQuest Quest { get; set; } } - public sealed class QuestCancelled : Packet + [MemoryPackable] + public sealed partial class QuestCancelled : Packet { public int Index { get; set; } } - public sealed class CompanionUnlock : Packet + [MemoryPackable] + public sealed partial class CompanionUnlock : Packet { public int Index { get; set; } } - public sealed class CompanionAdopt : Packet + [MemoryPackable] + public sealed partial class CompanionAdopt : Packet { public ClientUserCompanion UserCompanion { get; set; } } - public sealed class CompanionRetrieve : Packet + [MemoryPackable] + public sealed partial class CompanionRetrieve : Packet { public int Index { get; set; } } - public sealed class CompanionRelease : Packet + + [MemoryPackable] + public sealed partial class CompanionRelease : Packet { public int Index { get; set; } } - public sealed class CompanionStore : Packet + + [MemoryPackable] + public sealed partial class CompanionStore : Packet { } - public sealed class CompanionWeightUpdate : Packet + [MemoryPackable] + public sealed partial class CompanionWeightUpdate : Packet { public int BagWeight { get; set; } public int MaxBagWeight { get; set; } public int InventorySize { get; set; } } - public sealed class CompanionShapeUpdate : Packet + [MemoryPackable] + public sealed partial class CompanionShapeUpdate : Packet { public uint ObjectID { get; set; } public int HeadShape { get; set; } public int BackShape { get; set; } } - public sealed class CompanionItemsGained : Packet + [MemoryPackable] + public sealed partial class CompanionItemsGained : Packet { public List Items { get; set; } } - public sealed class CompanionUpdate : Packet + [MemoryPackable] + public sealed partial class CompanionUpdate : Packet { public int Level { get; set; } public int Experience { get; set; } public int Hunger { get; set; } } - public sealed class CompanionSkillUpdate : Packet + [MemoryPackable] + public sealed partial class CompanionSkillUpdate : Packet { public Stats Level3 { get; set; } public Stats Level5 { get; set; } @@ -1159,33 +1340,40 @@ public sealed class CompanionSkillUpdate : Packet public Stats Level15 { get; set; } } - public sealed class MarriageInvite : Packet + [MemoryPackable] + public sealed partial class MarriageInvite : Packet { public string Name { get; set; } } - public sealed class MarriageInfo : Packet + [MemoryPackable] + public sealed partial class MarriageInfo : Packet { public ClientPlayerInfo Partner { get; set; } } - public sealed class MarriageRemoveRing : Packet + [MemoryPackable] + public sealed partial class MarriageRemoveRing : Packet { } - public sealed class MarriageMakeRing : Packet + [MemoryPackable] + public sealed partial class MarriageMakeRing : Packet { } - public sealed class MarriageOnlineChanged : Packet + [MemoryPackable] + public sealed partial class MarriageOnlineChanged : Packet { public uint ObjectID { get; set; } } - public sealed class DataObjectRemove : Packet + [MemoryPackable] + public sealed partial class DataObjectRemove : Packet { public uint ObjectID { get; set; } } - public sealed class DataObjectPlayer : Packet + [MemoryPackable] + public sealed partial class DataObjectPlayer : Packet { public uint ObjectID { get; set; } public int MapIndex { get; set; } @@ -1200,13 +1388,15 @@ public sealed class DataObjectPlayer : Packet public int MaxHealth { get; set; } public int MaxMana { get; set; } } - public sealed class DataObjectMonster : Packet + [MemoryPackable] + public sealed partial class DataObjectMonster : Packet { public uint ObjectID { get; set; } public int MapIndex { get; set; } public Point CurrentLocation { get; set; } + [MemoryPackIgnore] public MonsterInfo MonsterInfo; public int MonsterIndex { get; set; } public string PetOwner { get; set; } @@ -1215,35 +1405,39 @@ public sealed class DataObjectMonster : Packet public Stats Stats { get; set; } public bool Dead { get; set; } - [CompleteObject] + [MemoryPackOnDeserialized] public void OnComplete() { MonsterInfo = Globals.MonsterInfoList.Binding.First(x => x.Index == MonsterIndex); } } - public sealed class DataObjectItem : Packet + [MemoryPackable] + public sealed partial class DataObjectItem : Packet { public uint ObjectID { get; set; } public int MapIndex { get; set; } public Point CurrentLocation { get; set; } + [MemoryPackIgnore] public ItemInfo ItemInfo; public int ItemIndex { get; set; } - [CompleteObject] + [MemoryPackOnDeserialized] public void OnComplete() { ItemInfo = Globals.ItemInfoList.Binding.First(x => x.Index == ItemIndex); } } - public sealed class DataObjectLocation : Packet + [MemoryPackable] + public sealed partial class DataObjectLocation : Packet { public uint ObjectID { get; set; } public int MapIndex { get; set; } public Point CurrentLocation { get; set; } } - public sealed class DataObjectHealthMana : Packet + [MemoryPackable] + public sealed partial class DataObjectHealthMana : Packet { public uint ObjectID { get; set; } @@ -1251,7 +1445,8 @@ public sealed class DataObjectHealthMana : Packet public int Mana { get; set; } public bool Dead { get; set; } } - public sealed class DataObjectMaxHealthMana : Packet + [MemoryPackable] + public sealed partial class DataObjectMaxHealthMana : Packet { public uint ObjectID { get; set; } @@ -1259,27 +1454,32 @@ public sealed class DataObjectMaxHealthMana : Packet public int MaxMana { get; set; } public Stats Stats { get; set; } } - public sealed class BlockAdd : Packet + [MemoryPackable] + public sealed partial class BlockAdd : Packet { public ClientBlockInfo Info { get; set; } } - public sealed class BlockRemove : Packet + [MemoryPackable] + public sealed partial class BlockRemove : Packet { public int Index { get; set; } } - public sealed class HelmetToggle : Packet + [MemoryPackable] + public sealed partial class HelmetToggle : Packet { public bool HideHelmet { get; set; } } - public sealed class StorageSize : Packet + [MemoryPackable] + public sealed partial class StorageSize : Packet { public int Size { get; set; } } - public sealed class PlayerChangeUpdate : Packet + [MemoryPackable] + public sealed partial class PlayerChangeUpdate : Packet { public uint ObjectID { get; set; } @@ -1288,17 +1488,21 @@ public sealed class PlayerChangeUpdate : Packet public MirGender Gender { get; set; } public int HairType { get; set; } + [MemoryPackAllowSerialize] public Color HairColour { get; set; } + [MemoryPackAllowSerialize] public Color ArmourColour { get; set; } } - public sealed class FortuneUpdate : Packet + [MemoryPackable] + public sealed partial class FortuneUpdate : Packet { public List Fortunes { get; set; } } - public sealed class NPCWeaponCraft : Packet + [MemoryPackable] + public sealed partial class NPCWeaponCraft : Packet { public CellLinkInfo Template { get; set; } public CellLinkInfo Yellow { get; set; } @@ -1311,7 +1515,8 @@ public sealed class NPCWeaponCraft : Packet public bool Success { get; set; } } - public sealed class NPCAccessoryRefine : Packet + [MemoryPackable] + public sealed partial class NPCAccessoryRefine : Packet { public CellLinkInfo Target { get; set; } public CellLinkInfo OreTarget { get; set; } @@ -1320,81 +1525,95 @@ public sealed class NPCAccessoryRefine : Packet public bool Success { get; set; } } - public sealed class ItemAcessoryRefined : Packet + [MemoryPackable] + public sealed partial class ItemAcessoryRefined : Packet { public GridType GridType { get; set; } public int Slot { get; set; } public Stats NewStats { get; set; } } - public sealed class JoinInstance : Packet + [MemoryPackable] + public sealed partial class JoinInstance : Packet { public InstanceResult Result { get; set; } public bool Success { get; set; } } - public sealed class SendCompanionFilters : Packet + [MemoryPackable] + public sealed partial class SendCompanionFilters : Packet { public List FilterClass { get; set; } public List FilterRarity { get; set; } public List FilterItemType { get; set; } } - public sealed class FriendUpdate : Packet + [MemoryPackable] + public sealed partial class FriendUpdate : Packet { public ClientFriendInfo Info { get; set; } } - public sealed class FriendAdd : Packet + [MemoryPackable] + public sealed partial class FriendAdd : Packet { public ClientFriendInfo Info { get; set; } } - public sealed class FriendRemove : Packet + [MemoryPackable] + public sealed partial class FriendRemove : Packet { public int Index { get; set; } } - public sealed class DisciplineUpdate : Packet + [MemoryPackable] + public sealed partial class DisciplineUpdate : Packet { public ClientUserDiscipline Discipline { get; set; } } - public sealed class DisciplineExperienceChanged : Packet + [MemoryPackable] + public sealed partial class DisciplineExperienceChanged : Packet { public long Experience { get; set; } } - public sealed class NPCRoll : Packet + [MemoryPackable] + public sealed partial class NPCRoll : Packet { public int Type { get; set; } public int Result { get; set; } } - public sealed class SetTimer : Packet + [MemoryPackable] + public sealed partial class SetTimer : Packet { public string Key { get; set; } public byte Type { get; set; } public int Seconds { get; set; } } - public sealed class LootBoxOpen : Packet + [MemoryPackable] + public sealed partial class LootBoxOpen : Packet { public int Slot { get; set; } public List Items { get; set; } } - public sealed class LootBoxClose : Packet + [MemoryPackable] + public sealed partial class LootBoxClose : Packet { } - public sealed class BundleOpen : Packet + [MemoryPackable] + public sealed partial class BundleOpen : Packet { public int Slot { get; set; } public List Items { get; set; } } - public sealed class BundleClose : Packet + [MemoryPackable] + public sealed partial class BundleClose : Packet { } diff --git a/LibraryCore/Stat.cs b/LibraryCore/Stat.cs index ec3c8976..6e8430c3 100644 --- a/LibraryCore/Stat.cs +++ b/LibraryCore/Stat.cs @@ -4,17 +4,19 @@ using System.IO; using System.Linq; using System.Reflection; +using MemoryPack; namespace Library { - public sealed class Stats + [MemoryPackable] + public sealed partial class Stats { public SortedDictionary Values { get; set; } = new SortedDictionary(); - - [IgnorePropertyPacket] + + [MemoryPackIgnore] public int Count => Values.Sum(pair => Math.Abs(pair.Value)); - - [IgnorePropertyPacket] + + [MemoryPackIgnore] public int this[Stat stat] { get @@ -36,6 +38,7 @@ public int this[Stat stat] } } + [MemoryPackConstructor] public Stats() { } diff --git a/LibraryCore/SystemModels/CompanionInfo.cs b/LibraryCore/SystemModels/CompanionInfo.cs index bd7aa15c..c15bb4f1 100644 --- a/LibraryCore/SystemModels/CompanionInfo.cs +++ b/LibraryCore/SystemModels/CompanionInfo.cs @@ -1,8 +1,10 @@ -using MirDB; +using MemoryPack; +using MirDB; namespace Library.SystemModels { - public class CompanionInfo : DBObject + [MemoryPackable] + public partial class CompanionInfo : DBObject { [IsIdentity] public MonsterInfo MonsterInfo diff --git a/LibraryCore/SystemModels/CurrencyInfo.cs b/LibraryCore/SystemModels/CurrencyInfo.cs index f410632d..5e7e1e42 100644 --- a/LibraryCore/SystemModels/CurrencyInfo.cs +++ b/LibraryCore/SystemModels/CurrencyInfo.cs @@ -1,8 +1,10 @@ -using MirDB; +using MemoryPack; +using MirDB; namespace Library.SystemModels { - public sealed class CurrencyInfo : DBObject + [MemoryPackable] + public sealed partial class CurrencyInfo : DBObject { [IsIdentity] public string Name diff --git a/LibraryCore/SystemModels/DisciplineInfo.cs b/LibraryCore/SystemModels/DisciplineInfo.cs index 5f41b675..6ed7dfe3 100644 --- a/LibraryCore/SystemModels/DisciplineInfo.cs +++ b/LibraryCore/SystemModels/DisciplineInfo.cs @@ -1,8 +1,10 @@ -using MirDB; +using MemoryPack; +using MirDB; namespace Library.SystemModels { - public class DisciplineInfo : DBObject + [MemoryPackable] + public partial class DisciplineInfo : DBObject { [IsIdentity] public int Level diff --git a/LibraryCore/SystemModels/ItemInfo.cs b/LibraryCore/SystemModels/ItemInfo.cs index 037e5d6f..374fccae 100644 --- a/LibraryCore/SystemModels/ItemInfo.cs +++ b/LibraryCore/SystemModels/ItemInfo.cs @@ -1,10 +1,12 @@ using MirDB; using System; using System.Text.Json.Serialization; +using MemoryPack; namespace Library.SystemModels { - public class ItemInfo : DBObject + [MemoryPackable] + public partial class ItemInfo : DBObject { [IsIdentity] public string ItemName diff --git a/LibraryCore/SystemModels/MagicInfo.cs b/LibraryCore/SystemModels/MagicInfo.cs index bd36c494..3bb60317 100644 --- a/LibraryCore/SystemModels/MagicInfo.cs +++ b/LibraryCore/SystemModels/MagicInfo.cs @@ -1,8 +1,10 @@ -using MirDB; +using MemoryPack; +using MirDB; namespace Library.SystemModels { - public sealed class MagicInfo : DBObject + [MemoryPackable] + public sealed partial class MagicInfo : DBObject { [IsIdentity] public string Name diff --git a/LibraryCore/SystemModels/MonsterInfo.cs b/LibraryCore/SystemModels/MonsterInfo.cs index 3f27dc74..b0d5dc51 100644 --- a/LibraryCore/SystemModels/MonsterInfo.cs +++ b/LibraryCore/SystemModels/MonsterInfo.cs @@ -1,9 +1,11 @@ using MirDB; using System.Text.Json.Serialization; +using MemoryPack; namespace Library.SystemModels { - public sealed class MonsterInfo : DBObject + [MemoryPackable] + public sealed partial class MonsterInfo : DBObject { [IsIdentity] public string MonsterName diff --git a/LibraryCore/SystemModels/MonsterInfoStat.cs b/LibraryCore/SystemModels/MonsterInfoStat.cs index 17f10a49..115a4e33 100644 --- a/LibraryCore/SystemModels/MonsterInfoStat.cs +++ b/LibraryCore/SystemModels/MonsterInfoStat.cs @@ -1,8 +1,10 @@ -using MirDB; +using MemoryPack; +using MirDB; namespace Library.SystemModels { - public sealed class MonsterInfoStat : DBObject + [MemoryPackable] + public sealed partial class MonsterInfoStat : DBObject { [IsIdentity] [Association("MonsterInfoStats")] diff --git a/LibraryCore/SystemModels/NPCInfo.cs b/LibraryCore/SystemModels/NPCInfo.cs index 7386aa6d..6b946966 100644 --- a/LibraryCore/SystemModels/NPCInfo.cs +++ b/LibraryCore/SystemModels/NPCInfo.cs @@ -1,6 +1,7 @@ using MirDB; using System; using System.Text.Json.Serialization; +using MemoryPack; namespace Library.SystemModels { @@ -129,7 +130,8 @@ public bool Equals(CurrentQuest other) } } - public sealed class NPCPage : DBObject + [MemoryPackable] + public sealed partial class NPCPage : DBObject { [IsIdentity] public string Description diff --git a/LibraryCore/SystemModels/SetInfo.cs b/LibraryCore/SystemModels/SetInfo.cs index 8c1f5334..d618cdcf 100644 --- a/LibraryCore/SystemModels/SetInfo.cs +++ b/LibraryCore/SystemModels/SetInfo.cs @@ -1,9 +1,11 @@ using MirDB; using System.Text.Json.Serialization; +using MemoryPack; namespace Library.SystemModels { - public class SetInfo : DBObject + [MemoryPackable] + public partial class SetInfo : DBObject { [IsIdentity] public string SetName