From c729c1c654831a7def9a95e1368b7a8b1e12da69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <1123993881@qq.com> Date: Sun, 12 Feb 2023 17:35:34 +0800 Subject: [PATCH] style: add more info about battle character. --- RotationSolver/Helpers/ObjectHelper.cs | 30 +++++++++++-------- .../CustomRotation/CustomRotation_Ability.cs | 2 +- .../SigReplacers/PluginAddressResolver.cs | 4 +-- .../Updaters/TargetUpdater_Major.cs | 5 ++-- RotationSolver/Windows/OverlayWindow.cs | 2 +- .../Windows/RotationConfigWindow_Debug.cs | 10 ++++--- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/RotationSolver/Helpers/ObjectHelper.cs b/RotationSolver/Helpers/ObjectHelper.cs index 6327790cf..79f26103a 100644 --- a/RotationSolver/Helpers/ObjectHelper.cs +++ b/RotationSolver/Helpers/ObjectHelper.cs @@ -38,19 +38,33 @@ internal static bool HasPositional(this GameObject obj) internal static unsafe bool IsOthersPlayers(this GameObject obj) { //SpecialType but no NamePlateIcon - if (_eventType.Contains(obj.GetAddress()->EventId.Type)) + if (_eventType.Contains(obj.GetEventType())) { return obj.GetNamePlateIcon() == 0; } return false; } - internal static unsafe bool IsNPCEnemy(this GameObject obj) => obj.GetObjectKind() == ObjectKind.BattleNpc - && obj.GetBattleNPCSubkind() == BattleNpcSubKind.Enemy; + static readonly EventHandlerType[] _someSpecialEvent = new EventHandlerType[] + { + EventHandlerType.PublicContentDirector, //Island Sanctuary.. + EventHandlerType.FateDirector, //Island Sanctuary.. + }; + internal static unsafe bool IsNPCEnemy(this GameObject obj) + => obj.GetObjectKind() == ObjectKind.BattleNpc + && obj.GetBattleNPCSubkind() == BattleNpcSubKind.Enemy + && !_someSpecialEvent.Contains(obj.GetEventType()) + && obj.CanAttack(); + + private unsafe static bool CanAttack(this GameObject actor) + { + return ((delegate*)Service.Address.CanAttackFunction)(142L, actor.Address) == 1; + } internal static unsafe ObjectKind GetObjectKind(this GameObject obj) => (ObjectKind)obj.GetAddress()->ObjectKind; internal static unsafe uint GetNamePlateIcon(this GameObject obj) => obj.GetAddress()->NamePlateIconId; + internal static unsafe EventHandlerType GetEventType(this GameObject obj) => obj.GetAddress()->EventId.Type; internal static unsafe BattleNpcSubKind GetBattleNPCSubkind(this GameObject obj) => (BattleNpcSubKind)obj.GetAddress()->SubKind; @@ -127,7 +141,7 @@ internal static bool CanDot(this BattleChara b) return b.CurrentHp >= GetHealthFromMulty(1.5f); } - internal static EnemyPositional FindEnemyLocation(this GameObject enemy) + internal static EnemyPositional FindEnemyPositional(this GameObject enemy) { Vector3 pPosition = enemy.Position; float rotation = enemy.Rotation; @@ -143,14 +157,6 @@ internal static EnemyPositional FindEnemyLocation(this GameObject enemy) return EnemyPositional.Flank; } - //public unsafe static bool CanAttack(this GameObject actor) - //{ - // if (actor == null) return false; - // if (actor is not BattleChara b) return false; - // if (b.CurrentHp == 0) return false; - // return ((delegate*)Service.Address.CanAttackFunction)(142L, actor.Address) == 1; - //} - #if DEBUG internal static uint GetHealthFromMulty(float mult) #else diff --git a/RotationSolver/Rotations/CustomRotation/CustomRotation_Ability.cs b/RotationSolver/Rotations/CustomRotation/CustomRotation_Ability.cs index 5b31f477b..a0d32dacc 100644 --- a/RotationSolver/Rotations/CustomRotation/CustomRotation_Ability.cs +++ b/RotationSolver/Rotations/CustomRotation/CustomRotation_Ability.cs @@ -255,7 +255,7 @@ private protected virtual bool EmergencyAbility(byte abilitiesRemaining, IAction if (Service.Configuration.AutoUseTrueNorth && abilitiesRemaining == 1 && action.EnermyPositonal != EnemyPositional.None && action.Target != null) { - if (action.EnermyPositonal != action.Target.FindEnemyLocation() && action.Target.HasPositional()) + if (action.EnermyPositonal != action.Target.FindEnemyPositional() && action.Target.HasPositional()) { if (TrueNorth.CanUse(out act, emptyOrSkipCombo: true)) return true; } diff --git a/RotationSolver/SigReplacers/PluginAddressResolver.cs b/RotationSolver/SigReplacers/PluginAddressResolver.cs index 96e78a6d2..a1dd7d0b3 100644 --- a/RotationSolver/SigReplacers/PluginAddressResolver.cs +++ b/RotationSolver/SigReplacers/PluginAddressResolver.cs @@ -7,7 +7,7 @@ namespace RotationSolver.SigReplacers; internal class PluginAddressResolver : BaseAddressResolver { public IntPtr IsActionIdReplaceable { get; private set; } - //public IntPtr CanAttackFunction { get; private set; } + public IntPtr CanAttackFunction { get; private set; } public IntPtr MovingController { get; private set; } public IntPtr ReceiveAbilty { get; private set; } public IntPtr CountdownTimerAdress { get; private set; } @@ -22,7 +22,7 @@ protected override void Setup64Bit(SigScanner scanner) IsActionIdReplaceable = scanner.ScanText("E8 ?? ?? ?? ?? 84 C0 74 4C 8B D3"); //IDK - //CanAttackFunction = scanner.ScanText("48 89 5C 24 ?? 57 48 83 EC 20 48 8B DA 8B F9 E8 ?? ?? ?? ?? 4C 8B C3 "); + CanAttackFunction = scanner.ScanText("48 89 5C 24 ?? 57 48 83 EC 20 48 8B DA 8B F9 E8 ?? ?? ?? ?? 4C 8B C3 "); MovingController = scanner.ScanText("40 55 53 48 8D 6C 24 ?? 48 81 EC ?? ?? ?? ?? 48 83 79 ?? ??"); ReceiveAbilty = scanner.ScanText("4C 89 44 24 ?? 55 56 41 54 41 55 41 56"); CountdownTimerAdress = scanner.ScanText("48 89 5C 24 ?? 57 48 83 EC 40 8B 41"); diff --git a/RotationSolver/Updaters/TargetUpdater_Major.cs b/RotationSolver/Updaters/TargetUpdater_Major.cs index 65fc86415..96c24d14f 100644 --- a/RotationSolver/Updaters/TargetUpdater_Major.cs +++ b/RotationSolver/Updaters/TargetUpdater_Major.cs @@ -13,12 +13,11 @@ internal static partial class TargetUpdater internal static IEnumerable AllTargets { get; private set; } internal static void UpdateTarget() { - var wholeTargets = Service.ObjectTable.GetObjectInRadius(60); - AllTargets = wholeTargets.GetObjectInRadius(30); + AllTargets = Service.ObjectTable.GetObjectInRadius(30); var battles = AllTargets.OfType(); UpdateHostileTargets(battles); UpdateFriends(battles); - UpdateNamePlate(wholeTargets.OfType()); + UpdateNamePlate(Service.ObjectTable.OfType()); } } } diff --git a/RotationSolver/Windows/OverlayWindow.cs b/RotationSolver/Windows/OverlayWindow.cs index c07c08cb7..e8455f3e9 100644 --- a/RotationSolver/Windows/OverlayWindow.cs +++ b/RotationSolver/Windows/OverlayWindow.cs @@ -162,7 +162,7 @@ private static void DrawLocation() } pts.Add(scrPos); - bool wrong = ShouldPositional != EnemyLocationTarget.FindEnemyLocation(); + bool wrong = ShouldPositional != EnemyLocationTarget.FindEnemyPositional(); var color = wrong ? new Vector3(0.3f, 0.8f, 0.2f) : new Vector3(1, 1, 1); pts.ForEach(pt => ImGui.GetWindowDrawList().PathLineTo(pt)); diff --git a/RotationSolver/Windows/RotationConfigWindow_Debug.cs b/RotationSolver/Windows/RotationConfigWindow_Debug.cs index 6f338cb3b..a516f5703 100644 --- a/RotationSolver/Windows/RotationConfigWindow_Debug.cs +++ b/RotationSolver/Windows/RotationConfigWindow_Debug.cs @@ -67,13 +67,15 @@ private unsafe void DrawTargetData() { if (Service.TargetManager.Target is BattleChara b) { + ImGui.Text("HP: " + b.CurrentHp + " / " + b.MaxHp); ImGui.Text("Is Boss: " + b.IsBoss().ToString()); ImGui.Text("Has Positional: " + b.HasPositional().ToString()); ImGui.Text("Is Dying: " + b.IsDying().ToString()); - ImGui.Text("NamePlate: " + b.GetAddress()->NamePlateIconId.ToString()); - ImGui.Text("Kind: " + b.GetAddress()->ObjectKind.ToString()); - ImGui.Text("Subkind: " + b.GetAddress()->SubKind.ToString()); - ImGui.Text("EventType: " + b.GetAddress()->EventId.Type.ToString()); + ImGui.Text("Kind: " + b.GetObjectKind().ToString()); + ImGui.Text("Subkind: " + b.GetBattleNPCSubkind().ToString()); + ImGui.Text("EventType: " + b.GetEventType().ToString()); + ImGui.Text("NamePlate: " + b.GetNamePlateIcon().ToString()); + ImGui.Text("StatusFlags: " + b.StatusFlags.ToString()); foreach (var status in b.StatusList) {