Prechádzať zdrojové kódy

Migrate from `MobHuntStruct` to `FFXIVClientStructs.FFXIV.Client.Game.UI.MobHunt` and remove SigScanner

SheepGoMeh 1 rok pred
rodič
commit
ebbaa87307

+ 26 - 0
HuntBuddy/BillEnum.cs

@@ -0,0 +1,26 @@
+namespace HuntBuddy;
+
+public enum BillEnum: uint {
+	ArrRank1,
+	HwRank1,
+	HwRank2,
+	HwRank3,
+	ArrElite,
+	HwElite,
+	SbRank1,
+	SbRank2,
+	SbRank3,
+	SbElite,
+	ShbRank1,
+	ShbRank2,
+	ShbRank3,
+	ShbElite,
+	EwRank1,
+	EwRank2,
+	EwRank3,
+	EwElite,
+	DtRank1,
+	DtRank2,
+	DtRank3,
+	DtElite,
+}

+ 1 - 1
HuntBuddy/Location.cs

@@ -600,7 +600,7 @@ public static class Location {
 
 		(int X, int Y) pos = MapToWorldCoordinates(Database[mobHuntId].Coordinate, mapId);
 
-		map->IsFlagMarkerSet = 0;
+		map->IsFlagMarkerSet = false;
 		map->SetFlagMapMarker(territoryType, mapId, pos.X, pos.Y, 60004);
 
 		switch (openType) {

+ 3 - 1
HuntBuddy/MobHuntEntry.cs

@@ -17,7 +17,9 @@ public class MobHuntEntry {
 
 	public bool IsEliteMark { get; init; }
 
-	public uint CurrentKillsOffset { get; init; }
+	public byte BillNumber { get; set; }
+
+	public byte MobIndex { get; set; }
 
 	public uint NeededKills { get; set; }
 

+ 14 - 21
HuntBuddy/Plugin.cs

@@ -11,17 +11,18 @@ using Dalamud.Plugin;
 using Dalamud.Plugin.Services;
 using Dalamud.Utility;
 
+using FFXIVClientStructs.FFXIV.Client.Game.UI;
+
 using HuntBuddy.Attributes;
 using HuntBuddy.Ipc;
-using HuntBuddy.Structs;
 using HuntBuddy.Windows;
 
 using ImGuiNET;
 
 using Lumina.Excel;
 using Lumina.Excel.Sheets;
-using Lumina.Text;
-using Lumina.Text.ReadOnly;
+
+using Map = Lumina.Excel.Sheets.Map;
 
 namespace HuntBuddy;
 
@@ -30,13 +31,12 @@ public class Plugin: IDalamudPlugin {
 
 	private readonly PluginCommandManager<Plugin> commandManager;
 
-	private ObtainedBillEnum lastState;
+	private int lastState;
 
 	// Dictionary<string ExpansionName, Dictionary<KeyValuePair<uint MobTerritoryType, string MobTerritoryName>, List<MobHuntEntry MobsInZone>>>
 	public readonly Dictionary<string, Dictionary<KeyValuePair<uint, string>, List<MobHuntEntry>>> MobHuntEntries;
 	public readonly ConcurrentBag<MobHuntEntry> CurrentAreaMobHuntEntries;
 	public bool MobHuntEntriesReady = true;
-	public readonly unsafe MobHuntStruct* MobHuntStruct;
 	public readonly Configuration Configuration;
 	public static TeleportConsumer? TeleportConsumer { get; private set; }
 	public static EspConsumer? EspConsumer { get; private set; }
@@ -70,12 +70,6 @@ public class Plugin: IDalamudPlugin {
 		this.Configuration.IconBackgroundColourU32 =
 			ImGui.ColorConvertFloat4ToU32(this.Configuration.IconBackgroundColour);
 
-		unsafe {
-			this.MobHuntStruct =
-				(MobHuntStruct*)Service.SigScanner.GetStaticAddressFromSig(
-					"48 8D 0D ?? ?? ?? ?? 8B D8 0F B6 52");
-		}
-
 		this.MainWindow = new MainWindow();
 		this.ConfigurationWindow = new ConfigurationWindow();
 
@@ -94,11 +88,11 @@ public class Plugin: IDalamudPlugin {
 	}
 
 	private unsafe void FrameworkOnUpdate(IFramework framework) {
-		if (this.lastState == this.MobHuntStruct->ObtainedBillEnumFlags) {
+		if (this.lastState == MobHunt.Instance()->ObtainedFlags) {
 			return;
 		}
 
-		this.lastState = this.MobHuntStruct->ObtainedBillEnumFlags;
+		this.lastState = MobHunt.Instance()->ObtainedFlags;
 		this.PluginCommand(string.Empty, "reload");
 	}
 
@@ -152,9 +146,8 @@ public class Plugin: IDalamudPlugin {
 				case "next":
 					if (this.MobHuntEntries.Count > 0) {
 						bool filterPredicate(MobHuntEntry entry) => entry.IsEliteMark ||
-							this.MobHuntStruct->CurrentKills[
-								entry.CurrentKillsOffset] <
-							entry.NeededKills;
+						                                            MobHunt.Instance()->GetKillCount(entry.BillNumber,
+							                                            entry.MobIndex) < entry.NeededKills;
 						Location.OpenType openType = Location.OpenType.None;
 						Vector3 playerLocation = Service.ClientState.LocalPlayer!.Position;
 						Map map = Service.DataManager.GetExcelSheet<TerritoryType>()!.GetRow(Service.ClientState
@@ -211,8 +204,7 @@ public class Plugin: IDalamudPlugin {
 								}
 							}
 							else {
-								long remaining = chosen.NeededKills -
-												 this.MobHuntStruct->CurrentKills[chosen.CurrentKillsOffset];
+								long remaining = chosen.NeededKills - MobHunt.Instance()->GetKillCount(chosen.BillNumber, chosen.MobIndex);
 								Service.Chat.Print($"Hunting {remaining}x {chosen.Name} in {chosen.TerritoryName}");
 								Location.CreateMapMarker(
 									chosen.TerritoryType,
@@ -262,7 +254,7 @@ public class Plugin: IDalamudPlugin {
 		SubrowExcelSheet<MobHuntOrder> mobHuntOrderSheet = Service.DataManager.GetSubrowExcelSheet<MobHuntOrder>();
 
 		foreach (BillEnum billNumber in Enum.GetValues<BillEnum>()) {
-			if (!this.MobHuntStruct->ObtainedBillEnumFlags.HasFlag((ObtainedBillEnum)(1 << (int)billNumber))) {
+			if ((MobHunt.Instance()->ObtainedFlags & (1 << (int)billNumber)) == 0) {
 				continue;
 			}
 
@@ -270,7 +262,7 @@ public class Plugin: IDalamudPlugin {
 				Service.DataManager.Excel.GetSheet<MobHuntOrderType>()!.GetRow((uint)billNumber)!;
 
 			uint rowId = mobHuntOrderTypeRow.OrderStart.Value!.RowId +
-						 (uint)(this.MobHuntStruct->BillOffset[mobHuntOrderTypeRow.RowId] - 1);
+						 (uint)(MobHunt.Instance()->ObtainedMarkId[(int)mobHuntOrderTypeRow.RowId] - 1);
 
 			IEnumerable<MobHuntOrder> mobHuntOrderRows = mobHuntOrderSheet[rowId];
 
@@ -293,7 +285,8 @@ public class Plugin: IDalamudPlugin {
 							TerritoryType = mobHuntOrderRow.Target.Value.TerritoryType.Value.TerritoryType.RowId,
 							MobHuntId = mobHuntOrderRow.Target.Value.Name.RowId,
 							IsEliteMark = mobHuntOrderTypeRow.Type == 2,
-							CurrentKillsOffset = (5 * (uint)billNumber) + mobHuntOrderRow.SubrowId,
+							BillNumber = (byte)billNumber,
+							MobIndex = (byte)mobHuntOrderRow.SubrowId,
 							NeededKills = mobHuntOrderRow.NeededKills,
 							Icon = mobHuntOrderRow.Target.Value.Icon,
 						});

+ 1 - 8
HuntBuddy/Service.cs

@@ -1,5 +1,4 @@
-using Dalamud.Game;
-using Dalamud.IoC;
+using Dalamud.IoC;
 using Dalamud.Plugin;
 using Dalamud.Plugin.Services;
 
@@ -30,12 +29,6 @@ public class Service {
 		set;
 	} = null!;
 
-	[PluginService]
-	public static ISigScanner SigScanner {
-		get;
-		set;
-	} = null!;
-
 	[PluginService]
 	public static IGameGui GameGui {
 		get;

+ 0 - 64
HuntBuddy/Structs/MobHuntStruct.cs

@@ -1,64 +0,0 @@
-using System;
-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,
-	DtRank1,
-	DtRank2,
-	DtRank3,
-	DtElite,
-}
-
-[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,
-	DtRank1 = 1 << 18,
-	DtRank2 = 1 << 19,
-	DtRank3 = 1 << 20,
-	DtElite = 1 << 21,
-}
-
-// Signature to get struct address
-// D1 48 8D 0D ? ? ? ? 48 83 C4 20 5F E9 ? ? ? ?
-[StructLayout(LayoutKind.Explicit, Size = 0x198)]
-public unsafe struct MobHuntStruct {
-	[FieldOffset(0x1E)] public fixed byte BillOffset[22];
-	[FieldOffset(0x34)] public fixed int CurrentKills[5 * 22];
-	[FieldOffset(0x1EC)] public readonly ObtainedBillEnum ObtainedBillEnumFlags;
-}

+ 4 - 2
HuntBuddy/Windows/LocalHuntsWindow.cs

@@ -5,6 +5,8 @@ using Dalamud.Game.ClientState.Conditions;
 using Dalamud.Interface;
 using Dalamud.Interface.Windowing;
 
+using FFXIVClientStructs.FFXIV.Client.Game.UI;
+
 using HuntBuddy.Utils;
 
 using ImGuiNET;
@@ -51,11 +53,11 @@ public class LocalHuntsWindow: Window {
 		&& !Service.Condition.Any(ConditionFlag.WatchingCutscene, ConditionFlag.OccupiedInCutSceneEvent)
 		&& !Plugin.Instance.CurrentAreaMobHuntEntries.IsEmpty
 		&& Plugin.Instance.CurrentAreaMobHuntEntries
-			.Count(x => Plugin.Instance.MobHuntStruct->CurrentKills[x.CurrentKillsOffset] == x.NeededKills) != Plugin.Instance.CurrentAreaMobHuntEntries.Count;
+			.Count(x => MobHunt.Instance()->GetKillCount(x.BillNumber, x.MobIndex) == x.NeededKills) != Plugin.Instance.CurrentAreaMobHuntEntries.Count;
 
 	public override unsafe void Draw() {
 		foreach (MobHuntEntry? mobHuntEntry in Plugin.Instance.CurrentAreaMobHuntEntries) {
-			int currentKills = Plugin.Instance.MobHuntStruct->CurrentKills[mobHuntEntry.CurrentKillsOffset];
+			int currentKills = MobHunt.Instance()->GetKillCount(mobHuntEntry.BillNumber, mobHuntEntry.MobIndex);
 
 			if (Plugin.Instance.Configuration.HideCompletedHunts && currentKills == mobHuntEntry.NeededKills) {
 				continue;

+ 4 - 2
HuntBuddy/Windows/MainWindow.cs

@@ -7,6 +7,8 @@ using Dalamud.Interface;
 using Dalamud.Interface.Utility;
 using Dalamud.Interface.Windowing;
 
+using FFXIVClientStructs.FFXIV.Client.Game.UI;
+
 using HuntBuddy.Utils;
 
 using ImGuiNET;
@@ -83,7 +85,7 @@ public class MainWindow: Window {
 				.Where(entry => {
 					bool treeOpen = ImGui.TreeNodeEx(entry.Key.Value, ImGuiTreeNodeFlags.AllowItemOverlap);
 					ImGui.SameLine();
-					int killedCount = entry.Value.Count(x => Plugin.Instance.MobHuntStruct->CurrentKills[x.CurrentKillsOffset] == x.NeededKills);
+					int killedCount = entry.Value.Count(x => MobHunt.Instance()->GetKillCount(x.BillNumber, x.MobIndex) == x.NeededKills);
 					if (killedCount != entry.Value.Count) {
 						ImGui.Text($"({killedCount}/{entry.Value.Count})");
 					}
@@ -183,7 +185,7 @@ public class MainWindow: Window {
 						}
 					}
 
-					int currentKills = Plugin.Instance.MobHuntStruct->CurrentKills[mobHuntEntry.CurrentKillsOffset];
+					int currentKills = MobHunt.Instance()->GetKillCount(mobHuntEntry.BillNumber, mobHuntEntry.MobIndex);
 					ImGui.Text(mobHuntEntry.Name);
 					if (ImGui.IsItemHovered()) {
 						ImGui.PushStyleColor(ImGuiCol.PopupBg, Vector4.Zero);