diff --git a/Source/Framework/Dynamic/OptionalType.cs b/Source/Framework/Dynamic/OptionalType.cs index 447e05752..03e043140 100644 --- a/Source/Framework/Dynamic/OptionalType.cs +++ b/Source/Framework/Dynamic/OptionalType.cs @@ -17,25 +17,26 @@ namespace Framework.Dynamic { - public struct Optional where T : new() + public struct Optional { private bool _hasValue; public T Value; + public Optional(T value) + { + Value = value; + _hasValue = true; + } + public bool HasValue { get { return _hasValue; } - set - { - _hasValue = value; - Value = _hasValue ? new T() : default; - } } - public void Set(T v) + public void Set(T value) { + Value = value; _hasValue = true; - Value = v; } public void Clear() @@ -49,9 +50,14 @@ namespace Framework.Dynamic return HasValue ? Value : otherValue; } - public static explicit operator T(Optional value) + public static explicit operator T(Optional optional) { - return (T)value; + return optional.Value; + } + + public static implicit operator Optional(T value) + { + return new Optional(value); } } } diff --git a/Source/Framework/Dynamic/TaskScheduler.cs b/Source/Framework/Dynamic/TaskScheduler.cs index 8b6e17b56..bc705b091 100644 --- a/Source/Framework/Dynamic/TaskScheduler.cs +++ b/Source/Framework/Dynamic/TaskScheduler.cs @@ -561,7 +561,7 @@ namespace Framework.Dynamic /// TaskContext ClearGroup() { - _task._group.HasValue = false; + _task._group.Clear(); return this; } diff --git a/Source/Game/Arenas/Arena.cs b/Source/Game/Arenas/Arena.cs index ec2b4270e..5718ec16d 100644 --- a/Source/Game/Arenas/Arena.cs +++ b/Source/Game/Arenas/Arena.cs @@ -104,8 +104,7 @@ namespace Game.Arenas if (IsRated()) { - pvpLogData.Ratings.HasValue = true; - + pvpLogData.Ratings.Value = new(); for (byte i = 0; i < SharedConst.PvpTeamsCount; ++i) { pvpLogData.Ratings.Value.Postmatch[i] = _arenaTeamScores[i].PostMatchRating; diff --git a/Source/Game/AuctionHouse/AuctionManager.cs b/Source/Game/AuctionHouse/AuctionManager.cs index 08a76aad8..d683bf205 100644 --- a/Source/Game/AuctionHouse/AuctionManager.cs +++ b/Source/Game/AuctionHouse/AuctionManager.cs @@ -1658,7 +1658,7 @@ namespace Game { if (alwaysSendItem) { - auctionItem.Item.HasValue = true; + auctionItem.Item.Value = new(); auctionItem.Item.Value = new ItemInstance(Items[0]); } @@ -1666,7 +1666,7 @@ namespace Game } else { - auctionItem.Item.HasValue = true; + auctionItem.Item.Value = new(); auctionItem.Item.Value = new ItemInstance(Items[0]); auctionItem.Charges = new[] { Items[0].GetSpellCharges(0), Items[0].GetSpellCharges(1), Items[0].GetSpellCharges(2), Items[0].GetSpellCharges(3), Items[0].GetSpellCharges(4) }.Max(); for (EnchantmentSlot enchantmentSlot = 0; enchantmentSlot < EnchantmentSlot.MaxInspected; enchantmentSlot++) diff --git a/Source/Game/BattleGrounds/BattleGround.cs b/Source/Game/BattleGrounds/BattleGround.cs index 17baba2ac..880c22dcb 100644 --- a/Source/Game/BattleGrounds/BattleGround.cs +++ b/Source/Game/BattleGrounds/BattleGround.cs @@ -702,7 +702,7 @@ namespace Game.BattleGrounds PVPMatchComplete pvpMatchComplete = new(); pvpMatchComplete.Winner = (byte)GetWinner(); pvpMatchComplete.Duration = (int)Math.Max(0, (GetElapsedTime() - (int)BattlegroundStartTimeIntervals.Delay2m) / Time.InMilliseconds); - pvpMatchComplete.LogData.HasValue = true; + pvpMatchComplete.LogData.Value = new(); BuildPvPLogDataPacket(out pvpMatchComplete.LogData.Value); pvpMatchComplete.Write(); diff --git a/Source/Game/BattleGrounds/BattleGroundScore.cs b/Source/Game/BattleGrounds/BattleGroundScore.cs index 13aad2817..7fbe2ed35 100644 --- a/Source/Game/BattleGrounds/BattleGroundScore.cs +++ b/Source/Game/BattleGrounds/BattleGroundScore.cs @@ -65,7 +65,7 @@ namespace Game.BattleGrounds playerData.Faction = (byte)TeamId; if (HonorableKills != 0 || Deaths != 0 || BonusHonor != 0) { - playerData.Honor.HasValue = true; + playerData.Honor.Value = new(); playerData.Honor.Value.HonorKills = HonorableKills; playerData.Honor.Value.Deaths = Deaths; playerData.Honor.Value.ContributionPoints = BonusHonor; diff --git a/Source/Game/BattlePets/BattlePetManager.cs b/Source/Game/BattlePets/BattlePetManager.cs index 350b6b5a6..2d4ff28b7 100644 --- a/Source/Game/BattlePets/BattlePetManager.cs +++ b/Source/Game/BattlePets/BattlePetManager.cs @@ -230,7 +230,7 @@ namespace Game.BattlePets if (!ownerGuid.IsEmpty()) { - pet.PacketInfo.OwnerInfo.HasValue = true; + pet.PacketInfo.OwnerInfo.Value = new(); pet.PacketInfo.OwnerInfo.Value.Guid = ownerGuid; pet.PacketInfo.OwnerInfo.Value.PlayerVirtualRealm = Global.WorldMgr.GetVirtualRealmAddress(); pet.PacketInfo.OwnerInfo.Value.PlayerNativeRealm = Global.WorldMgr.GetVirtualRealmAddress(); @@ -398,7 +398,7 @@ namespace Game.BattlePets Player player = _owner.GetPlayer(); if (battlePetSpecies.GetFlags().HasFlag(BattlePetSpeciesFlags.NotAccountWide)) { - pet.PacketInfo.OwnerInfo.HasValue = true; + pet.PacketInfo.OwnerInfo.Value = new(); pet.PacketInfo.OwnerInfo.Value.Guid = player.GetGUID(); pet.PacketInfo.OwnerInfo.Value.PlayerVirtualRealm = Global.WorldMgr.GetVirtualRealmAddress(); pet.PacketInfo.OwnerInfo.Value.PlayerNativeRealm = Global.WorldMgr.GetVirtualRealmAddress(); diff --git a/Source/Game/BlackMarket/BlackMarketEntry.cs b/Source/Game/BlackMarket/BlackMarketEntry.cs index 070e87593..1270b7ace 100644 --- a/Source/Game/BlackMarket/BlackMarketEntry.cs +++ b/Source/Game/BlackMarket/BlackMarketEntry.cs @@ -50,7 +50,7 @@ namespace Game.BlackMarket if (!bonusListIDs.Empty()) { - Item.ItemBonus.HasValue = true; + Item.ItemBonus.Value = new(); Item.ItemBonus.Value.BonusListIDs = bonusListIDs; } diff --git a/Source/Game/Entities/AreaTrigger/AreaTrigger.cs b/Source/Game/Entities/AreaTrigger/AreaTrigger.cs index ded4a1c2a..968453965 100644 --- a/Source/Game/Entities/AreaTrigger/AreaTrigger.cs +++ b/Source/Game/Entities/AreaTrigger/AreaTrigger.cs @@ -759,7 +759,7 @@ namespace Game.Entities AreaTriggerRePath reshape = new(); reshape.TriggerGUID = GetGUID(); - reshape.AreaTriggerSpline.HasValue = true; + reshape.AreaTriggerSpline.Value = new(); reshape.AreaTriggerSpline.Value.ElapsedTimeForMovement = GetElapsedTimeForMovement(); reshape.AreaTriggerSpline.Value.TimeToTarget = timeToTarget; reshape.AreaTriggerSpline.Value.Points = splinePoints; diff --git a/Source/Game/Entities/Player/Player.Items.cs b/Source/Game/Entities/Player/Player.Items.cs index fdb10a5b4..7e411c3a5 100644 --- a/Source/Game/Entities/Player/Player.Items.cs +++ b/Source/Game/Entities/Player/Player.Items.cs @@ -200,7 +200,7 @@ namespace Game.Entities itemPurchaseRefundResult.Result = error; if (error == 0) { - itemPurchaseRefundResult.Contents.HasValue = true; + itemPurchaseRefundResult.Contents.Value = new(); itemPurchaseRefundResult.Contents.Value.Money = item.GetPaidMoney(); for (byte i = 0; i < ItemConst.MaxItemExtCostItems; ++i) // item cost data { diff --git a/Source/Game/Entities/Player/Player.cs b/Source/Game/Entities/Player/Player.cs index 3010ebd09..68e1811c2 100644 --- a/Source/Game/Entities/Player/Player.cs +++ b/Source/Game/Entities/Player/Player.cs @@ -1836,7 +1836,7 @@ namespace Game.Entities transport = GetTransport(); if (transport) { - transferPending.Ship.HasValue = true; + transferPending.Ship.Value = new(); transferPending.Ship.Value.Id = transport.GetEntry(); transferPending.Ship.Value.OriginMapID = (int)GetMapId(); } @@ -4983,7 +4983,7 @@ namespace Game.Entities rewardEntry.Quantity = item.Quantity; if (!item.BonusListIDs.Empty()) { - rewardEntry.Item.ItemBonus.HasValue = true; + rewardEntry.Item.ItemBonus.Value = new(); rewardEntry.Item.ItemBonus.Value.BonusListIDs = item.BonusListIDs; } reward.Items.Add(rewardEntry); @@ -5012,7 +5012,7 @@ namespace Game.Entities rewardEntry.Quantity = item.Quantity; if (!item.BonusListIDs.Empty()) { - rewardEntry.Item.ItemBonus.HasValue = true; + rewardEntry.Item.ItemBonus.Value = new(); rewardEntry.Item.ItemBonus.Value.BonusListIDs = item.BonusListIDs; } diff --git a/Source/Game/Garrisons/Garrisons.cs b/Source/Game/Garrisons/Garrisons.cs index 758a18cfd..2d27bf899 100644 --- a/Source/Game/Garrisons/Garrisons.cs +++ b/Source/Game/Garrisons/Garrisons.cs @@ -77,7 +77,7 @@ namespace Game.Garrisons if (!CliDB.GarrBuildingStorage.ContainsKey(buildingId)) continue; - plot.BuildingInfo.PacketInfo.HasValue = true; + plot.BuildingInfo.PacketInfo.Value = new(); plot.BuildingInfo.PacketInfo.Value.GarrPlotInstanceID = plotInstanceId; plot.BuildingInfo.PacketInfo.Value.GarrBuildingID = buildingId; plot.BuildingInfo.PacketInfo.Value.TimeBuilt = timeBuilt; diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index 414964030..446ca3042 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -5800,7 +5800,7 @@ namespace Game if (!result.IsNull(7)) { - info.createPositionNPE.HasValue = true; + info.createPositionNPE.Value = new(); info.createPositionNPE.Value.Loc = new WorldLocation(result.Read(7), result.Read(8), result.Read(9), result.Read(10), result.Read(11)); if (!result.IsNull(12)) @@ -5809,13 +5809,13 @@ namespace Game if (!CliDB.MapStorage.ContainsKey(info.createPositionNPE.Value.Loc.GetMapId())) { Log.outError(LogFilter.Sql, $"Invalid NPE map id {info.createPositionNPE.Value.Loc.GetMapId()} for class {currentclass} race {currentrace} pair in `playercreateinfo` table, ignoring."); - info.createPositionNPE.HasValue = false; + info.createPositionNPE.Clear(); } if (info.createPositionNPE.HasValue && info.createPositionNPE.Value.TransportGuid.HasValue && Global.TransportMgr.GetTransportSpawn(info.createPositionNPE.Value.TransportGuid.Value) == null) { Log.outError(LogFilter.Sql, $"Invalid NPE transport spawn id {info.createPositionNPE.Value.TransportGuid.Value} for class {currentclass} race {currentrace} pair in `playercreateinfo` table, ignoring."); - info.createPositionNPE.HasValue = false; // remove entire NPE data - assume user put transport offsets into npe_position fields + info.createPositionNPE.Clear(); // remove entire NPE data - assume user put transport offsets into npe_position fields } } diff --git a/Source/Game/Groups/Group.cs b/Source/Game/Groups/Group.cs index 02b69b2cb..f11e5f3e3 100644 --- a/Source/Game/Groups/Group.cs +++ b/Source/Game/Groups/Group.cs @@ -1483,14 +1483,14 @@ namespace Game.Groups if (GetMembersCount() > 1) { // LootSettings - partyUpdate.LootSettings.HasValue = true; + partyUpdate.LootSettings.Value = new(); partyUpdate.LootSettings.Value.Method = (byte)m_lootMethod; partyUpdate.LootSettings.Value.Threshold = (byte)m_lootThreshold; partyUpdate.LootSettings.Value.LootMaster = m_lootMethod == LootMethod.MasterLoot ? m_masterLooterGuid : ObjectGuid.Empty; // Difficulty Settings - partyUpdate.DifficultySettings.HasValue = true; + partyUpdate.DifficultySettings.Value = new(); partyUpdate.DifficultySettings.Value.DungeonDifficultyID = (uint)m_dungeonDifficulty; partyUpdate.DifficultySettings.Value.RaidDifficultyID = (uint)m_raidDifficulty; @@ -1500,7 +1500,7 @@ namespace Game.Groups // LfgInfos if (IsLFGGroup()) { - partyUpdate.LfgInfos.HasValue = true; + partyUpdate.LfgInfos.Value = new(); partyUpdate.LfgInfos.Value.Slot = Global.LFGMgr.GetLFGDungeonEntry(Global.LFGMgr.GetDungeon(m_guid)); partyUpdate.LfgInfos.Value.BootCount = 0; diff --git a/Source/Game/Handlers/AuctionHandler.cs b/Source/Game/Handlers/AuctionHandler.cs index 08b0be730..61659f5e6 100644 --- a/Source/Game/Handlers/AuctionHandler.cs +++ b/Source/Game/Handlers/AuctionHandler.cs @@ -57,7 +57,7 @@ namespace Game AuctionListBucketsResult listBucketsResult = new(); if (!browseQuery.ItemClassFilters.Empty()) { - classFilters.HasValue = true; + classFilters.Value = new(); foreach (var classFilter in browseQuery.ItemClassFilters) { diff --git a/Source/Game/Handlers/AuthenticationHandler.cs b/Source/Game/Handlers/AuthenticationHandler.cs index c46121075..6cb6d7af5 100644 --- a/Source/Game/Handlers/AuthenticationHandler.cs +++ b/Source/Game/Handlers/AuthenticationHandler.cs @@ -29,7 +29,7 @@ namespace Game if (code == BattlenetRpcErrorCode.Ok) { - response.SuccessInfo.HasValue = true; + response.SuccessInfo.Value = new(); response.SuccessInfo.Value = new AuthResponse.AuthSuccessInfo(); response.SuccessInfo.Value.ActiveExpansionLevel = (byte)GetExpansion(); @@ -51,7 +51,7 @@ namespace Game if (queued) { - response.WaitInfo.HasValue = true; + response.WaitInfo.Value = new(); response.WaitInfo.Value.WaitCount = queuePos; } diff --git a/Source/Game/Handlers/CharacterHandler.cs b/Source/Game/Handlers/CharacterHandler.cs index a4875dd41..299e33aea 100644 --- a/Source/Game/Handlers/CharacterHandler.cs +++ b/Source/Game/Handlers/CharacterHandler.cs @@ -1091,7 +1091,7 @@ namespace Game features.VoiceEnabled = false; features.BrowserEnabled = false; // Has to be false, otherwise client will crash if "Customer Support" is opened - features.EuropaTicketSystemStatus.HasValue = true; + features.EuropaTicketSystemStatus.Value = new(); features.EuropaTicketSystemStatus.Value.ThrottleState.MaxTries = 10; features.EuropaTicketSystemStatus.Value.ThrottleState.PerMilliseconds = 60000; features.EuropaTicketSystemStatus.Value.ThrottleState.TryCount = 1; @@ -2533,7 +2533,7 @@ namespace Game if (result == ResponseCodes.Success) { - packet.Display.HasValue = true; + packet.Display.Value = new(); packet.Display.Value.Name = factionChangeInfo.Name; packet.Display.Value.SexID = (byte)factionChangeInfo.SexID; packet.Display.Value.Customizations = factionChangeInfo.Customizations; diff --git a/Source/Game/Handlers/InspectHandler.cs b/Source/Game/Handlers/InspectHandler.cs index 6a0f63ffc..350b4b1c0 100644 --- a/Source/Game/Handlers/InspectHandler.cs +++ b/Source/Game/Handlers/InspectHandler.cs @@ -58,7 +58,7 @@ namespace Game Guild guild = Global.GuildMgr.GetGuildById(player.GetGuildId()); if (guild) { - inspectResult.GuildData.HasValue = true; + inspectResult.GuildData.Value = new(); InspectGuildData guildData; guildData.GuildGUID = guild.GetGUID(); diff --git a/Source/Game/Handlers/NPCHandler.cs b/Source/Game/Handlers/NPCHandler.cs index af2e2c5df..353f3d47d 100644 --- a/Source/Game/Handlers/NPCHandler.cs +++ b/Source/Game/Handlers/NPCHandler.cs @@ -533,7 +533,7 @@ namespace Game item.Item.ItemID = vendorItem.item; if (!vendorItem.BonusListIDs.Empty()) { - item.Item.ItemBonus.HasValue = true; + item.Item.ItemBonus.Value = new(); item.Item.ItemBonus.Value.BonusListIDs = vendorItem.BonusListIDs; } diff --git a/Source/Game/Handlers/TaxiHandler.cs b/Source/Game/Handlers/TaxiHandler.cs index e29bb7927..b73d9ce64 100644 --- a/Source/Game/Handlers/TaxiHandler.cs +++ b/Source/Game/Handlers/TaxiHandler.cs @@ -104,7 +104,7 @@ namespace Game GetPlayer().SetTaxiCheater(true); // Grimwing in Ebon Hold, special case. NOTE: Not perfect, Zul'Aman should not be included according to WoWhead, and I think taxicheat includes it. ShowTaxiNodes data = new(); - data.WindowInfo.HasValue = true; + data.WindowInfo.Value = new(); data.WindowInfo.Value.UnitGUID = unit.GetGUID(); data.WindowInfo.Value.CurrentNode = (int)curloc; diff --git a/Source/Game/Handlers/TradeHandler.cs b/Source/Game/Handlers/TradeHandler.cs index 2d2bf1375..4a6228e9f 100644 --- a/Source/Game/Handlers/TradeHandler.cs +++ b/Source/Game/Handlers/TradeHandler.cs @@ -64,7 +64,7 @@ namespace Game tradeItem.GiftCreator = item.GetGiftCreator(); if (!item.IsWrapped()) { - tradeItem.Unwrapped.HasValue = true; + tradeItem.Unwrapped.Value = new(); TradeUpdated.UnwrappedTradeItem unwrappedItem = tradeItem.Unwrapped.Value; unwrappedItem.EnchantID = (int)item.GetEnchantmentId(EnchantmentSlot.Perm); unwrappedItem.OnUseEnchantmentID = (int)item.GetEnchantmentId(EnchantmentSlot.Use); diff --git a/Source/Game/Maps/Map.cs b/Source/Game/Maps/Map.cs index 20e379119..cfab136ff 100644 --- a/Source/Game/Maps/Map.cs +++ b/Source/Game/Maps/Map.cs @@ -2120,7 +2120,7 @@ namespace Game.Maps } } - data.LiquidInfo.HasValue = true; + data.LiquidInfo.Value = new(); data.LiquidInfo.Value.level = wmoData.liquidInfo.Value.Level; data.LiquidInfo.Value.depth_level = wmoData.floorZ; data.LiquidInfo.Value.entry = liquidType; diff --git a/Source/Game/Movement/MoveSplineInit.cs b/Source/Game/Movement/MoveSplineInit.cs index 2e929392b..24acd6b21 100644 --- a/Source/Game/Movement/MoveSplineInit.cs +++ b/Source/Game/Movement/MoveSplineInit.cs @@ -313,7 +313,7 @@ namespace Game.Movement public void SetAnimation(AnimType anim) { args.time_perc = 0.0f; - args.animTier.HasValue = true; + args.animTier.Value = new(); args.animTier.Value.AnimTier = (byte)anim; args.flags.EnableAnimation(); } diff --git a/Source/Game/Networking/Packets/AuctionHousePackets.cs b/Source/Game/Networking/Packets/AuctionHousePackets.cs index 802b82761..a1a0b3d94 100644 --- a/Source/Game/Networking/Packets/AuctionHousePackets.cs +++ b/Source/Game/Networking/Packets/AuctionHousePackets.cs @@ -51,7 +51,7 @@ namespace Game.Networking.Packets KnownPets[i] = _worldPacket.ReadUInt8(); if (_worldPacket.HasBit()) - TaintedBy.HasValue = true; + TaintedBy.Value = new(); uint nameLength = _worldPacket.ReadBits(8); uint itemClassFilterCount = _worldPacket.ReadBits(3); @@ -79,10 +79,12 @@ namespace Game.Networking.Packets public override void Read() { Auctioneer = _worldPacket.ReadPackedGuid(); - TaintedBy.HasValue = _worldPacket.HasBit(); - if (TaintedBy.HasValue) + if (_worldPacket.HasBit()) + { + TaintedBy.Value = new(); TaintedBy.Value.Read(_worldPacket); + } } } @@ -100,10 +102,12 @@ namespace Game.Networking.Packets Auctioneer = _worldPacket.ReadPackedGuid(); ItemID = _worldPacket.ReadInt32(); Quantity = _worldPacket.ReadUInt32(); - TaintedBy.HasValue = _worldPacket.HasBit(); - if (TaintedBy.HasValue) + if (_worldPacket.HasBit()) + { + TaintedBy.Value = new(); TaintedBy.Value.Read(_worldPacket); + } } } @@ -133,7 +137,8 @@ namespace Game.Networking.Packets { Auctioneer = _worldPacket.ReadPackedGuid(); Offset = _worldPacket.ReadUInt32(); - TaintedBy.HasValue = _worldPacket.HasBit(); + if (_worldPacket.HasBit()) + TaintedBy.Value = new(); uint auctionIDCount = _worldPacket.ReadBits(7); uint sortCount = _worldPacket.ReadBits(2); @@ -161,7 +166,8 @@ namespace Game.Networking.Packets public override void Read() { Auctioneer = _worldPacket.ReadPackedGuid(); - TaintedBy.HasValue = _worldPacket.HasBit(); + if (_worldPacket.HasBit()) + TaintedBy.Value = new(); uint bucketKeysCount = _worldPacket.ReadBits(7); uint sortCount = _worldPacket.ReadBits(2); @@ -193,7 +199,8 @@ namespace Game.Networking.Packets Auctioneer = _worldPacket.ReadPackedGuid(); Offset = _worldPacket.ReadUInt32(); Unknown830 = _worldPacket.ReadInt8(); - TaintedBy.HasValue = _worldPacket.HasBit(); + if (_worldPacket.HasBit()) + TaintedBy.Value = new(); uint sortCount = _worldPacket.ReadBits(2); for (var i = 0; i < sortCount; ++i) @@ -225,7 +232,7 @@ namespace Game.Networking.Packets Offset = _worldPacket.ReadUInt32(); if (_worldPacket.HasBit()) - TaintedBy.HasValue = true; + TaintedBy.Value = new(); uint sortCount = _worldPacket.ReadBits(2); @@ -250,7 +257,8 @@ namespace Game.Networking.Packets { Auctioneer = _worldPacket.ReadPackedGuid(); Offset = _worldPacket.ReadUInt32(); - TaintedBy.HasValue = _worldPacket.HasBit(); + if (_worldPacket.HasBit()) + TaintedBy.Value = new(); uint sortCount = _worldPacket.ReadBits(2); @@ -276,10 +284,12 @@ namespace Game.Networking.Packets Auctioneer = _worldPacket.ReadPackedGuid(); AuctionID = _worldPacket.ReadUInt32(); BidAmount = _worldPacket.ReadUInt64(); - TaintedBy.HasValue = _worldPacket.HasBit(); - if (TaintedBy.HasValue) + if (_worldPacket.HasBit()) + { + TaintedBy.Value = new(); TaintedBy.Value.Read(_worldPacket); + } } } @@ -295,10 +305,12 @@ namespace Game.Networking.Packets { Auctioneer = _worldPacket.ReadPackedGuid(); AuctionID = _worldPacket.ReadUInt32(); - TaintedBy.HasValue = _worldPacket.HasBit(); - if (TaintedBy.HasValue) + if (_worldPacket.HasBit()) + { + TaintedBy.Value = new(); TaintedBy.Value.Read(_worldPacket); + } } } @@ -320,10 +332,12 @@ namespace Game.Networking.Packets ChangeNumberCursor = _worldPacket.ReadUInt32(); ChangeNumberTombstone = _worldPacket.ReadUInt32(); Count = _worldPacket.ReadUInt32(); - TaintedBy.HasValue = _worldPacket.HasBit(); - if (TaintedBy.HasValue) + if (_worldPacket.HasBit()) + { + TaintedBy.Value = new(); TaintedBy.Value.Read(_worldPacket); + } } } @@ -342,7 +356,9 @@ namespace Game.Networking.Packets Auctioneer = _worldPacket.ReadPackedGuid(); UnitPrice = _worldPacket.ReadUInt64(); RunTime = _worldPacket.ReadUInt32(); - TaintedBy.HasValue = _worldPacket.HasBit(); + if (_worldPacket.HasBit()) + TaintedBy.Value = new(); + uint itemCount = _worldPacket.ReadBits(6); if (TaintedBy.HasValue) @@ -371,7 +387,9 @@ namespace Game.Networking.Packets BuyoutPrice = _worldPacket.ReadUInt64(); RunTime = _worldPacket.ReadUInt32(); - TaintedBy.HasValue = _worldPacket.HasBit(); + if (_worldPacket.HasBit()) + TaintedBy.Value = new(); + uint itemCount = _worldPacket.ReadBits(6); if (TaintedBy.HasValue) @@ -410,10 +428,12 @@ namespace Game.Networking.Packets Auctioneer = _worldPacket.ReadPackedGuid(); ItemID = _worldPacket.ReadInt32(); Quantity = _worldPacket.ReadUInt32(); - TaintedBy.HasValue = _worldPacket.HasBit(); - if (TaintedBy.HasValue) + if (_worldPacket.HasBit()) + { + TaintedBy.Value = new(); TaintedBy.Value.Read(_worldPacket); + } } } @@ -719,12 +739,12 @@ namespace Game.Networking.Packets ItemID = data.ReadBits(20); if (data.HasBit()) - BattlePetSpeciesID.HasValue = true; + BattlePetSpeciesID.Value = new(); ItemLevel = data.ReadBits(11); if (data.HasBit()) - SuffixItemNameDescriptionID.HasValue = true; + SuffixItemNameDescriptionID.Value = new(); if (BattlePetSpeciesID.HasValue) BattlePetSpeciesID.Set(data.ReadUInt16()); diff --git a/Source/Game/Networking/Packets/ItemPackets.cs b/Source/Game/Networking/Packets/ItemPackets.cs index d34895020..36fc54976 100644 --- a/Source/Game/Networking/Packets/ItemPackets.cs +++ b/Source/Game/Networking/Packets/ItemPackets.cs @@ -855,7 +855,7 @@ namespace Game.Networking.Packets List bonusListIds = item.m_itemData.BonusListIDs; if (!bonusListIds.Empty()) { - ItemBonus.HasValue = true; + ItemBonus.Value = new(); ItemBonus.Value.BonusListIDs.AddRange(bonusListIds); ItemBonus.Value.Context = item.GetContext(); } @@ -870,7 +870,7 @@ namespace Game.Networking.Packets if (!lootItem.BonusListIDs.Empty() || lootItem.randomBonusListId != 0) { - ItemBonus.HasValue = true; + ItemBonus.Value = new(); ItemBonus.Value.BonusListIDs = lootItem.BonusListIDs; ItemBonus.Value.Context = lootItem.context; if (lootItem.randomBonusListId != 0) @@ -890,7 +890,7 @@ namespace Game.Networking.Packets if (!voidItem.BonusListIDs.Empty()) { - ItemBonus.HasValue = true; + ItemBonus.Value = new(); ItemBonus.Value.Context = voidItem.Context; ItemBonus.Value.BonusListIDs = voidItem.BonusListIDs; } @@ -927,7 +927,9 @@ namespace Game.Networking.Packets { ItemID = data.ReadUInt32(); - ItemBonus.HasValue = data.HasBit(); + if (data.HasBit()) + ItemBonus.Value = new(); + data.ResetBitPos(); Modifications.Read(data); diff --git a/Source/Game/Networking/Packets/LFGPackets.cs b/Source/Game/Networking/Packets/LFGPackets.cs index 73b9666f3..642a20276 100644 --- a/Source/Game/Networking/Packets/LFGPackets.cs +++ b/Source/Game/Networking/Packets/LFGPackets.cs @@ -674,7 +674,7 @@ namespace Game.Networking.Packets if (!isCurrency) { - RewardItem.HasValue = true; + RewardItem.Value = new(); RewardItem.Value.ItemID = id; } else diff --git a/Source/Game/Networking/Packets/MovementPackets.cs b/Source/Game/Networking/Packets/MovementPackets.cs index e6331af2d..a7a545f78 100644 --- a/Source/Game/Networking/Packets/MovementPackets.cs +++ b/Source/Game/Networking/Packets/MovementPackets.cs @@ -377,7 +377,7 @@ namespace Game.Networking.Packets if (splineFlags.HasFlag(SplineFlag.Animation)) { - movementSpline.AnimTierTransition.HasValue = true; + movementSpline.AnimTierTransition.Value = new(); movementSpline.AnimTierTransition.Value.TierTransitionID = (int)moveSpline.anim_tier.Value.TierTransitionId; movementSpline.AnimTierTransition.Value.StartTime = (uint)moveSpline.effect_start_time; movementSpline.AnimTierTransition.Value.AnimTier = moveSpline.anim_tier.Value.AnimTier; @@ -387,7 +387,7 @@ namespace Game.Networking.Packets if (splineFlags.HasFlag(SplineFlag.Parabolic) && (!moveSpline.spell_effect_extra.HasValue || moveSpline.effect_start_time != 0)) { - movementSpline.JumpExtraData.HasValue = true; + movementSpline.JumpExtraData.Value = new(); movementSpline.JumpExtraData.Value.JumpGravity = moveSpline.vertical_acceleration; movementSpline.JumpExtraData.Value.StartTime = (uint)moveSpline.effect_start_time; } @@ -397,7 +397,7 @@ namespace Game.Networking.Packets if (moveSpline.spell_effect_extra.HasValue) { - movementSpline.SpellEffectExtraData.HasValue = true; + movementSpline.SpellEffectExtraData.Value = new(); movementSpline.SpellEffectExtraData.Value.TargetGuid = moveSpline.spell_effect_extra.Value.Target; movementSpline.SpellEffectExtraData.Value.SpellVisualID = moveSpline.spell_effect_extra.Value.SpellVisualId; movementSpline.SpellEffectExtraData.Value.ProgressCurveID = moveSpline.spell_effect_extra.Value.ProgressCurveId; @@ -915,7 +915,7 @@ namespace Game.Networking.Packets Ack.Read(_worldPacket); if (_worldPacket.HasBit()) { - Speeds.HasValue = true; + Speeds.Value = new(); Speeds.Value.Read(_worldPacket); } } diff --git a/Source/Game/Networking/Packets/PartyPackets.cs b/Source/Game/Networking/Packets/PartyPackets.cs index e5ee807ec..1db493531 100644 --- a/Source/Game/Networking/Packets/PartyPackets.cs +++ b/Source/Game/Networking/Packets/PartyPackets.cs @@ -319,7 +319,7 @@ namespace Game.Networking.Packets { Pet pet = player.GetPet(); - MemberStats.PetStats.HasValue = true; + MemberStats.PetStats.Value = new(); MemberStats.PetStats.Value.GUID = pet.GetGUID(); MemberStats.PetStats.Value.Name = pet.GetName(); diff --git a/Source/Game/Networking/Packets/SpellPackets.cs b/Source/Game/Networking/Packets/SpellPackets.cs index a8f1f14f8..bab6e3def 100644 --- a/Source/Game/Networking/Packets/SpellPackets.cs +++ b/Source/Game/Networking/Packets/SpellPackets.cs @@ -1519,10 +1519,18 @@ namespace Game.Networking.Packets public void Read(WorldPacket data) { Flags = (SpellCastTargetFlags)data.ReadBits(26); - SrcLocation.HasValue = data.HasBit(); - DstLocation.HasValue = data.HasBit(); - Orientation.HasValue = data.HasBit(); - MapID.HasValue = data.HasBit(); + if (data.HasBit()) + SrcLocation.Value = new(); + + if (data.HasBit()) + DstLocation.Value = new(); + + if (data.HasBit()) + Orientation.Value = new(); + + if (data.HasBit()) + MapID.Value = new(); + uint nameLength = data.ReadBits(7); Unit = data.ReadPackedGuid(); @@ -1661,7 +1669,9 @@ namespace Game.Networking.Packets OptionalCurrencies[i].Read(data); SendCastFlags = data.ReadBits(5); - MoveUpdate.HasValue = data.HasBit(); + if (data.HasBit()) + MoveUpdate.Value = new(); + var weightCount = data.ReadBits(2); Target.Read(data); diff --git a/Source/Game/Networking/Packets/TicketPackets.cs b/Source/Game/Networking/Packets/TicketPackets.cs index 142d3c0ca..610fe2ea8 100644 --- a/Source/Game/Networking/Packets/TicketPackets.cs +++ b/Source/Game/Networking/Packets/TicketPackets.cs @@ -147,7 +147,7 @@ namespace Game.Networking.Packets if (hasClubMessage) { - CommunityMessage.HasValue = true; + CommunityMessage.Value = new(); CommunityMessage.Value.IsPlayerUsingVoice = _worldPacket.HasBit(); _worldPacket.ResetBitPos(); } @@ -158,49 +158,49 @@ namespace Game.Networking.Packets if (hasMailInfo) { - MailInfo.HasValue = true; + MailInfo.Value = new(); MailInfo.Value.Read(_worldPacket); } if (hasCalendarInfo) { - CalenderInfo.HasValue = true; + CalenderInfo.Value = new(); CalenderInfo.Value.Read(_worldPacket); } if (hasPetInfo) { - PetInfo.HasValue = true; + PetInfo.Value = new(); PetInfo.Value.Read(_worldPacket); } if (hasGuildInfo) { - GuildInfo.HasValue = true; + GuildInfo.Value = new(); GuildInfo.Value.Read(_worldPacket); } if (hasLFGListSearchResult) { - LFGListSearchResult.HasValue = true; + LFGListSearchResult.Value = new(); LFGListSearchResult.Value.Read(_worldPacket); } if (hasLFGListApplicant) { - LFGListApplicant.HasValue = true; + LFGListApplicant.Value = new(); LFGListApplicant.Value.Read(_worldPacket); } if (hasClubFinderResult) { - ClubFinderResult.HasValue = true; + ClubFinderResult.Value = new(); ClubFinderResult.Value.Read(_worldPacket); } if (hasUnk910) { - Unused910.HasValue = true; + Unused910.Value = new(); Unused910.Value.Read(_worldPacket); } } @@ -250,7 +250,9 @@ namespace Game.Networking.Packets public void Read(WorldPacket data) { uint linesCount = data.ReadUInt32(); - ReportLineIndex.HasValue = data.HasBit(); + if (data.HasBit()) + ReportLineIndex.Value = new(); + data.ResetBitPos(); for (uint i = 0; i < linesCount; i++) @@ -279,19 +281,19 @@ namespace Game.Networking.Packets if (hasClubID) { - ClubID.HasValue = true; + ClubID.Value = new(); ClubID.Value = data.ReadUInt64(); } if (hasChannelGUID) { - ChannelGUID.HasValue = true; + ChannelGUID.Value = new(); ChannelGUID.Value = data.ReadPackedGuid(); } if (hasRealmAddress) { - RealmAddress.HasValue = true; + RealmAddress.Value = new(); RealmAddress.Value.VirtualRealmAddress = data.ReadUInt32(); RealmAddress.Value.field_4 = data.ReadUInt16(); RealmAddress.Value.field_6 = data.ReadUInt8(); @@ -299,7 +301,7 @@ namespace Game.Networking.Packets if (hasSlashCmd) { - SlashCmd.HasValue = true; + SlashCmd.Value = new(); SlashCmd.Value = data.ReadInt32(); } diff --git a/Source/Game/Networking/Packets/WhoPackets.cs b/Source/Game/Networking/Packets/WhoPackets.cs index b22401470..396d20afb 100644 --- a/Source/Game/Networking/Packets/WhoPackets.cs +++ b/Source/Game/Networking/Packets/WhoPackets.cs @@ -117,7 +117,9 @@ namespace Game.Networking.Packets ShowEnemies = data.HasBit(); ShowArenaPlayers = data.HasBit(); ExactName = data.HasBit(); - ServerInfo.HasValue = data.HasBit(); + if (data.HasBit()) + ServerInfo.Value = new(); + data.ResetBitPos(); for (int i = 0; i < wordsCount; ++i) diff --git a/Source/Game/Networking/WorldSocket.cs b/Source/Game/Networking/WorldSocket.cs index bf98db7ee..5a4e8d0b1 100644 --- a/Source/Game/Networking/WorldSocket.cs +++ b/Source/Game/Networking/WorldSocket.cs @@ -775,8 +775,8 @@ namespace Game.Networking public void SendAuthResponseError(BattlenetRpcErrorCode code) { AuthResponse response = new(); - response.SuccessInfo.HasValue = false; - response.WaitInfo.HasValue = false; + response.SuccessInfo.Clear(); + response.WaitInfo.Clear(); response.Result = code; SendPacket(response); } diff --git a/Source/Game/Spells/Auras/Aura.cs b/Source/Game/Spells/Auras/Aura.cs index d21cf49cc..fd4af826b 100644 --- a/Source/Game/Spells/Auras/Aura.cs +++ b/Source/Game/Spells/Auras/Aura.cs @@ -237,7 +237,7 @@ namespace Game.Spells if (remove) return; - auraInfo.AuraData.HasValue = true; + auraInfo.AuraData.Value = new(); Aura aura = GetBase(); diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index 1486aa624..7dc094658 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -3539,7 +3539,7 @@ namespace Game.Spells if (castFlags.HasAnyFlag(SpellCastFlags.RuneList)) // rune cooldowns list { - castData.RemainingRunes.HasValue = true; + castData.RemainingRunes.Value = new(); RuneData runeData = castData.RemainingRunes.Value; //TODO: There is a crash caused by a spell with CAST_FLAG_RUNE_LIST casted by a creature @@ -3654,7 +3654,7 @@ namespace Game.Spells if (Convert.ToBoolean(castFlags & SpellCastFlags.RuneList)) // rune cooldowns list { - castData.RemainingRunes.HasValue = true; + castData.RemainingRunes.Value = new(); RuneData runeData = castData.RemainingRunes.Value; Player player = m_caster.ToPlayer(); @@ -3965,7 +3965,7 @@ namespace Game.Spells if (schoolImmunityMask != 0 || mechanicImmunityMask != 0) { - spellChannelStart.InterruptImmunities.HasValue = true; + spellChannelStart.InterruptImmunities.Value = new(); spellChannelStart.InterruptImmunities.Value.SchoolImmunities = (int)schoolImmunityMask; spellChannelStart.InterruptImmunities.Value.Immunities = (int)mechanicImmunityMask; } diff --git a/Source/Game/Spells/SpellCastTargets.cs b/Source/Game/Spells/SpellCastTargets.cs index 19798590a..0c1216d57 100644 --- a/Source/Game/Spells/SpellCastTargets.cs +++ b/Source/Game/Spells/SpellCastTargets.cs @@ -88,7 +88,7 @@ namespace Game.Spells if (m_targetMask.HasAnyFlag(SpellCastTargetFlags.SourceLocation)) { - data.SrcLocation.HasValue = true; + data.SrcLocation.Value = new(); TargetLocation target = new(); target.Transport = m_src.TransportGUID; // relative position guid here - transport for example if (!m_src.TransportGUID.IsEmpty()) @@ -101,7 +101,7 @@ namespace Game.Spells if (Convert.ToBoolean(m_targetMask & SpellCastTargetFlags.DestLocation)) { - data.DstLocation.HasValue = true; + data.DstLocation.Value = new(); TargetLocation target = new(); target.Transport = m_dst.TransportGUID; // relative position guid here - transport for example if (!m_dst.TransportGUID.IsEmpty()) diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index c04ce312b..99adb323a 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -5395,14 +5395,14 @@ namespace Game.Spells Optional arrivalCast = new(); if (effectInfo.TriggerSpell != 0) { - arrivalCast.HasValue = true; + arrivalCast.Value = new(); arrivalCast.Value.SpellId = effectInfo.TriggerSpell; } Optional effectExtra = new(); if (jumpParams.SpellVisualId.HasValue || jumpParams.ProgressCurveId.HasValue || jumpParams.ParabolicCurveId.HasValue) { - effectExtra.HasValue = true; + effectExtra.Value = new(); if (jumpParams.SpellVisualId.HasValue) effectExtra.Value.SpellVisualId = jumpParams.SpellVisualId.Value; diff --git a/Source/Game/Text/ChatTextBuilder.cs b/Source/Game/Text/ChatTextBuilder.cs index 2f2e93fd0..32e2c1904 100644 --- a/Source/Game/Text/ChatTextBuilder.cs +++ b/Source/Game/Text/ChatTextBuilder.cs @@ -68,7 +68,7 @@ namespace Game.Chat if (!TranslatedPacket.HasValue) { - TranslatedPacket.HasValue = true; + TranslatedPacket.Value = new(); TranslatedPacket.Value.Initialize(Type, Language, Sender, Receiver, Global.LanguageMgr.Translate(Text, (uint)Language, player.GetSession().GetSessionDbcLocale()), AchievementId, "", Locale); TranslatedPacket.Value.Write(); }