Browse Source

Rework data acquisition.

Thanks to @MidoriKami
Dragon 4 years ago
parent
commit
0ad7fd004e
4 changed files with 57 additions and 45 deletions
  1. 1 2
      Interface.cs
  2. 1 1
      MobHuntEntry.cs
  3. 9 42
      Plugin.cs
  4. 46 0
      Structs/MobHuntStruct.cs

+ 1 - 2
Interface.cs

@@ -287,8 +287,7 @@ namespace HuntBuddy
 			ImGui.InvisibleButton("canvas", imageSize);
 
 			var drawList = ImGui.GetWindowDrawList();
-			if (mobHuntEntry.ExpansionId == 4 &&
-			    mobHuntEntry.MobHuntType == 1) // Endwalker uses circle for non elite mobs
+			if (mobHuntEntry.ExpansionId == 4 && !mobHuntEntry.IsEliteMark) // Endwalker uses circle for non elite mobs
 			{
 				drawList.AddCircleFilled(cursorPos + imageSize / 2f, imageSize.X / 2f,
 					this._plugin.Configuration.IconBackgroundColourU32);

+ 1 - 1
MobHuntEntry.cs

@@ -12,7 +12,7 @@ namespace HuntBuddy
 		public uint MapId { get; init; }
 		public uint TerritoryType { get; init; }
 		public uint MobHuntId { get; init; }
-		public byte MobHuntType { get; init; }
+		public bool IsEliteMark { get; init; }
 		public uint CurrentKillsOffset { get; init; }
 		public uint NeededKills { get; set; }
 		public TextureWrap Icon { get; init; } = null!;

+ 9 - 42
Plugin.cs

@@ -143,50 +143,18 @@ namespace HuntBuddy
 
 		public unsafe void ReloadData()
 		{
-			var inventoryContainer = InventoryManager.Instance()->GetInventoryContainer(InventoryType.KeyItems);
-
-			if (inventoryContainer->Loaded == 0)
-			{
-				PluginLog.Log("Container not loaded!");
-				return;
-			}
-
-			if (inventoryContainer->Size == 0)
-			{
-				PluginLog.Log("Container is empty!");
-				return;
-			}
-
-			var huntBills = new List<KeyValuePair<byte,uint>>();
-
-			for (var i = 0; i != inventoryContainer->Size; ++i)
-			{
-				var inventoryItemPtr = inventoryContainer->GetInventorySlot(i);
-
-				if (inventoryItemPtr == null || (*inventoryItemPtr).ItemID == 0)
-				{
-					continue;
-				}
-
-				var inventoryItem = *inventoryItemPtr;
-
-				foreach (var row in Plugin.DataManager.Excel.GetSheet<MobHuntOrderType>()!)
-				{
-					if (inventoryItem.ItemID == row.EventItem.Row)
-					{
-						huntBills.Add(new KeyValuePair<byte, uint>(row.Type, row.RowId));
-						break;
-					}
-				}
-			}
-			
 			this.MobHuntEntries.Clear();
 			var mobHuntList = new List<MobHuntEntry>();
 			var mobHuntOrderSheet = Plugin.DataManager.Excel.GetSheet<MobHuntOrder>()!;
 			
-			foreach (var (mobHuntType, billNumber) in huntBills)
+			foreach (var billNumber in Enum.GetValues<BillEnum>())
 			{
-				var mobHuntOrderTypeRow = Plugin.DataManager.Excel.GetSheet<MobHuntOrderType>()!.GetRow(billNumber)!;
+				if (!this.MobHuntStruct->ObtainedBillEnumFlags.HasFlag((ObtainedBillEnum)(1 << (int)billNumber)))
+				{
+					continue;
+				}
+
+				var mobHuntOrderTypeRow = Plugin.DataManager.Excel.GetSheet<MobHuntOrderType>()!.GetRow((uint)billNumber)!;
 					
 				var rowId = mobHuntOrderTypeRow.OrderStart.Value!.RowId +
 				            (uint)(this.MobHuntStruct->BillOffset[mobHuntOrderTypeRow.RowId] - 1);
@@ -214,8 +182,8 @@ namespace HuntBuddy
 							MapId = mobHuntOrderRow.Target.Value!.TerritoryType.Row,
 							TerritoryType = mobHuntOrderRow.Target.Value!.TerritoryType.Value.TerritoryType.Row,
 							MobHuntId = mobHuntOrderRow.Target.Value!.Name.Row,
-							MobHuntType = mobHuntType,
-							CurrentKillsOffset = 5 * billNumber + mobHuntOrderRow.SubRowId,
+							IsEliteMark = billNumber is BillEnum.ArrElite or BillEnum.HwElite or BillEnum.SbElite or BillEnum.ShbElite or BillEnum.EwElite,
+							CurrentKillsOffset = 5 * (uint)billNumber + mobHuntOrderRow.SubRowId,
 							NeededKills = mobHuntOrderRow.NeededKills,
 							Icon = Plugin.LoadIcon(mobHuntOrderRow.Target.Value.Icon)
 						});
@@ -251,7 +219,6 @@ namespace HuntBuddy
 			this.ClientStateOnTerritoryChanged(null, 0);
 
 			this.MobHuntEntriesReady = true;
-			this._interface.DrawInterface = true;
 		}
 		
 		private static TexFile? GetHdIcon(uint id)

+ 46 - 0
Structs/MobHuntStruct.cs

@@ -3,6 +3,51 @@ using System.Runtime.InteropServices;
 
 namespace HuntBuddy.Structs
 {
+	public enum BillEnum : uint
+	{
+		ArrRank1,
+		HwRank1,
+		HwRank2,
+		HwRank3,
+		ArrElite,
+		HwElite,
+		SbRank1,
+		SbRank2,
+		SbRank3,
+		SbElite,
+		ShbRank1,
+		ShbRank2,
+		ShbRank3,
+		ShbElite,
+		EwRank1,
+		EwRank2,
+		EwRank3,
+		EwElite,
+	}
+	
+	[Flags]
+	public enum ObtainedBillEnum : uint
+	{
+		ArrRank1 = 1,
+		HwRank1 = 1 << 1,
+		HwRank2 = 1 << 2,
+		HwRank3 = 1 << 3,
+		ArrElite = 1 << 4,
+		HwElite = 1 << 5,
+		SbRank1 = 1 << 6,
+		SbRank2 = 1 << 7,
+		SbRank3 = 1 << 8,
+		SbElite = 1 << 9,
+		ShbRank1 = 1 << 10,
+		ShbRank2 = 1 << 11,
+		ShbRank3 = 1 << 12,
+		ShbElite = 1 << 13,
+		EwRank1 = 1 << 14,
+		EwRank2 = 1 << 15,
+		EwRank3 = 1 << 16,
+		EwElite = 1 << 17,
+	}
+
 	// Signature to get struct address
 	// D1 48 8D 0D ? ? ? ? 48 83 C4 20 5F E9 ? ? ? ?
 	[StructLayout(LayoutKind.Explicit, Size = 0x198)]
@@ -10,5 +55,6 @@ namespace HuntBuddy.Structs
 	{
 		[FieldOffset(0x1A)] public fixed byte BillOffset[18];
 		[FieldOffset(0x2C)] public fixed int CurrentKills[5 * 18];
+		[FieldOffset(0x194)] public readonly ObtainedBillEnum ObtainedBillEnumFlags;
 	}
 }