Skip to content

Commit

Permalink
Mostly fixed for DT
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownX7 committed Jun 30, 2024
1 parent b44a283 commit d770d70
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 82 deletions.
2 changes: 1 addition & 1 deletion ActionStackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private static bool CheckActionStack(uint id, Configuration.ActionStack stack, o
}

private static bool CanUseAction(uint id, GameObject* target)
=> ActionManager.CanUseActionOnGameObject(id, target) && Common.ActionManager->CS.GetActionStatus(ActionType.Action, id, target->ObjectID, false, false) == 0;
=> ActionManager.CanUseActionOnGameObject(id, target) && Common.ActionManager->CS.GetActionStatus(ActionType.Action, id, target->GetGameObjectId(), false, false) == 0;

private static void SetInstantGroundTarget(uint actionType, uint useType)
{
Expand Down
7 changes: 7 additions & 0 deletions DalamudPackager.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<Target Name="DebugPlugin" AfterTargets="Build" Condition="'$(Configuration)' == 'Debug'">
<DalamudPackager
ProjectDir="$(ProjectDir)"
OutputPath="$(OutputPath)"
AssemblyName="$(AssemblyName)"
MakeZip="false"/>
</Target>
<Target Name="PackagePlugin" AfterTargets="Build" Condition="'$(Configuration)' == 'Release'">
<DalamudPackager
ProjectDir="$(ProjectDir)"
Expand Down
42 changes: 19 additions & 23 deletions Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Dalamud.Hooking;
using FFXIVClientStructs.FFXIV.Client.Game.Control;
using FFXIVClientStructs.FFXIV.Client.System.Framework;
using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
using FFXIVClientStructs.FFXIV.Client.UI.Shell;
using Hypostasis.Game.Structures;
Expand All @@ -17,27 +16,27 @@ public static unsafe class Game
{
public const uint InvalidObjectID = 0xE0000000;

public static readonly AsmPatch queueGroundTargetsPatch = new("75 49 44 8B C3 41 8B D6", new byte?[] { 0x90, 0x90 }, ReAction.Config.EnableGroundTargetQueuing);
public static readonly AsmPatch queueGroundTargetsPatch = new("75 49 44 8B C7 41 8B D5", [ 0x90, 0x90 ], ReAction.Config.EnableGroundTargetQueuing);

// test byte ptr [r15+39], 04
// jnz A7h
public static readonly AsmPatch spellAutoAttackPatch = new("41 B0 01 41 0F B6 D0 E9 ?? ?? ?? ?? 41 B0 01", new byte?[] { 0x41, 0xF6, 0x47, 0x39, 0x04, 0x0F, 0x85, 0xA7, 0x00, 0x00, 0x00, 0x90 }, ReAction.Config.EnableSpellAutoAttacks && ReAction.Config.EnableSpellAutoAttacksOutOfCombat);
// test byte ptr [rsi+3A], 04
// jnz 7Ah
public static readonly AsmPatch spellAutoAttackPatch = new("41 B0 01 44 0F B6 CA 41 0F B6 D0 E9 ?? ?? ?? ?? 41 B0 01", [ 0xF6, 0x46, 0x3A, 0x04, 0x0F, 0x85, 0x7A, 0x00, 0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 ], ReAction.Config.EnableSpellAutoAttacks && ReAction.Config.EnableSpellAutoAttacksOutOfCombat);

public static readonly AsmPatch allowUnassignableActionsPatch = new("75 07 32 C0 E9 ?? ?? ?? ?? 48 8B 00", new byte?[] { 0xEB }, ReAction.Config.EnableUnassignableActions);
public static readonly AsmPatch allowUnassignableActionsPatch = new("75 07 32 C0 E9 ?? ?? ?? ?? 48 8B 00", [ 0xEB ], ReAction.Config.EnableUnassignableActions);

// mov eax, 1000f
// movd xmm1, eax
// mulss xmm0, xmm1
// cvttss2si rcx, xmm0
public static readonly AsmPatch waitSyntaxDecimalPatch = new("F3 0F 58 05 ?? ?? ?? ?? F3 48 0F 2C C0 69 C8",
new byte?[] {
[
0xB8, 0x00, 0x00, 0x7A, 0x44,
0x66, 0x0F, 0x6E, 0xC8,
0xF3, 0x0F, 0x59, 0xC1,
0xF3, 0x48, 0x0F, 0x2C, 0xC8,
0x90,
0x90, 0x90, 0x90, 0x90, 0x90
},
],
ReAction.Config.EnableFractionality);

// mov eax, 1000f
Expand All @@ -47,7 +46,7 @@ public static unsafe class Game
// mov [rbx+58h], ecx
// jmp
public static readonly AsmPatch waitCommandDecimalPatch = new("F3 0F 58 0D ?? ?? ?? ?? F3 48 0F 2C C1 69 C8",
new byte?[] {
[
0xB8, 0x00, 0x00, 0x7A, 0x44,
0x66, 0x0F, 0x6E, 0xC0,
0xF3, 0x0F, 0x59, 0xC8,
Expand All @@ -56,22 +55,22 @@ public static unsafe class Game
0x89, 0x4B, 0x58,
0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
0xEB // 0x1F
},
],
ReAction.Config.EnableFractionality);

public static readonly AsmPatch queueACCommandPatch = new("02 00 00 00 41 8B D7 89", new byte?[] { 0x64 }, ReAction.Config.EnableMacroQueue);
public static readonly AsmPatch queueACCommandPatch = new("02 00 00 00 41 8B D7 89", [ 0x64 ], ReAction.Config.EnableMacroQueue);

public static ulong GetObjectID(GameObject* o)
{
if (o == null) return InvalidObjectID;

var id = o->GetObjectID();
return (ulong)((id.Type * 0x1_0000_0000) | id.ObjectID);
var id = o->GetGameObjectId();
return (ulong)((id.Type * 0x1_0000_0000) | id.ObjectId);
}

[HypostasisSignatureInjection("E8 ?? ?? ?? ?? 44 0F B6 C3 48 8B D0")]
public static delegate* unmanaged<ulong, GameObject*> fpGetGameObjectFromObjectID;
public static GameObject* GetGameObjectFromObjectID(ulong id) => fpGetGameObjectFromObjectID(id);
[HypostasisSignatureInjection("E8 ?? ?? ?? ?? 48 8B D8 F3 0F 10 15")]
public static delegate* unmanaged<ulong, Bool, GameObject*> fpGetGameObjectFromObjectID;
public static GameObject* GetGameObjectFromObjectID(ulong id) => fpGetGameObjectFromObjectID(id, false);

// The game is dumb and I cannot check LoS easily because not facing the target will override it
public static bool IsActionOutOfRange(uint actionID, GameObject* o) => DalamudApi.ClientState.LocalPlayer is { } p && o != null
Expand Down Expand Up @@ -99,13 +98,10 @@ public static bool IsActionOutOfRange(uint actionID, GameObject* o) => DalamudAp
return targetSystem->GetMouseOverObject(Common.InputData->GetAxisInput(0), Common.InputData->GetAxisInput(1), array, camera);
}

[HypostasisSignatureInjection("E8 ?? ?? ?? ?? 4C 39 6F 08")]
private static delegate* unmanaged<HotBarSlot*, UIModule*, byte, uint, void> fpSetHotbarSlot;
public static void SetHotbarSlot(int hotbar, int slot, byte type, uint id)
{
if (fpSetHotbarSlot == null || hotbar is < 0 or > 17 || (hotbar < 10 ? slot is < 0 or > 11 : slot is < 0 or > 15)) return;
var raptureHotbarModule = Framework.Instance()->GetUiModule()->GetRaptureHotbarModule();
fpSetHotbarSlot(raptureHotbarModule->HotBarsSpan[hotbar].GetHotbarSlot((uint)slot), raptureHotbarModule->UiModule, type, id);
if (hotbar is < 0 or > 17 || (hotbar < 10 ? slot is < 0 or > 11 : slot is < 0 or > 15)) return;
Framework.Instance()->GetUIModule()->GetRaptureHotbarModule()->SetAndSaveSlot((uint)hotbar, (uint)slot, (RaptureHotbarModule.HotbarSlotType)type, id);
}

public delegate Bool UseActionDelegate(ActionManager* actionManager, uint actionType, uint actionID, ulong targetObjectID, uint param, uint useType, int pvp, bool* isGroundTarget);
Expand All @@ -120,7 +116,7 @@ private static Bool UseActionDetour(ActionManager* actionManager, uint actionTyp
public static Hook<SetFocusTargetByObjectIDDelegate> SetFocusTargetByObjectIDHook;
private static void SetFocusTargetByObjectIDDetour(TargetSystem* targetSystem, ulong objectID)
{
if (ReAction.Config.AutoFocusTargetID == 0 || DalamudApi.TargetManager.FocusTarget == DalamudApi.ObjectTable.FirstOrDefault(o => o.DataId == FocusTargetInfo.DataID && o.Name.ToString() == FocusTargetInfo.Name))
if (ReAction.Config.AutoFocusTargetID == 0 || DalamudApi.TargetManager.FocusTarget == null || DalamudApi.TargetManager.FocusTarget.Equals(DalamudApi.ObjectTable.FirstOrDefault(o => o.DataId == FocusTargetInfo.DataID && o.Name.ToString() == FocusTargetInfo.Name)))
SetFocusTargetByObjectIDHook.Original(targetSystem, objectID);
FocusTargetInfo = DalamudApi.TargetManager.FocusTarget is { } o ? (o.Name.ToString(), o.DataId) : (null, 0);
}
Expand All @@ -144,7 +140,7 @@ public static void RefocusTarget()
}

private delegate uint GetTextCommandParamIDDelegate(PronounModule* pronounModule, nint* text, int len); // Probably not an issue, but this function doesn't get called if the length is > 31
[HypostasisSignatureInjection("48 89 5C 24 10 48 89 6C 24 18 56 48 83 EC 20 48 83 79 18 00")] // E8 ?? ?? ?? ?? E9 ?? ?? ?? ?? E8 ?? ?? ?? ?? CC CC (lol)
[HypostasisSignatureInjection("E8 ?? ?? ?? ?? EB C3 48 63 F7")] // Original was inlined, may override default game placeholders if not careful!
private static Hook<GetTextCommandParamIDDelegate> GetTextCommandParamIDHook;
private static uint GetTextCommandParamIDDetour(PronounModule* pronounModule, nint* bytePtrPtr, int len)
{
Expand Down
7 changes: 3 additions & 4 deletions Modules/AutoTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ static bool IsBetween(double val, double a, double b)
return val >= a && val <= b;
}

Dalamud.Game.ClientState.Objects.Types.GameObject closest = null;
foreach (var o in DalamudApi.ObjectTable.Where(o => o.YalmDistanceX < 30
&& o.ObjectKind is ObjectKind.Player or ObjectKind.BattleNpc
&& ((BattleChara)o).CurrentHp > 0
IGameObject closest = null;
foreach (var o in DalamudApi.ObjectTable.Where(o => o is { YalmDistanceX: < 30, ObjectKind: ObjectKind.Player or ObjectKind.BattleNpc }
&& ((IBattleChara)o).CurrentHp > 0
&& ActionManager.CanUseActionOnGameObject(7, (GameObject*)o.Address)))
{
var posDiff = o.Position - p.Position;
Expand Down
6 changes: 4 additions & 2 deletions Modules/Decombos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ private enum ActionID : uint
Geirskogul = 3555
}

public override bool ShouldEnable => ReAction.Config.EnableDecomboMeditation
/*public override bool ShouldEnable => ReAction.Config.EnableDecomboMeditation
|| ReAction.Config.EnableDecomboBunshin
|| ReAction.Config.EnableDecomboWanderersMinuet
|| ReAction.Config.EnableDecomboLiturgy
|| ReAction.Config.EnableDecomboEarthlyStar
|| ReAction.Config.EnableDecomboMinorArcana
|| ReAction.Config.EnableDecomboGeirskogul;
|| ReAction.Config.EnableDecomboGeirskogul;*/

public override bool ShouldEnable => false;

protected override void Enable() => GetAdjustedActionIdHook.Enable();
protected override void Disable() => GetAdjustedActionIdHook.Disable();
Expand Down
6 changes: 4 additions & 2 deletions Modules/EnhancedAutoFaceTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ namespace ReAction.Modules;

public unsafe class EnhancedAutoFaceTarget : PluginModule
{
private static readonly AsmPatch removeAutoFaceTargetPatch = new("41 80 7F 33 06 75 1E 48 8D 0D", new byte?[] { 0x90, 0x90, 0x90, 0x90, 0x90, 0xEB, 0x1C });
private static readonly AsmPatch removeAutoFaceGroundTargetPatch = new("41 80 7F 33 06 74 22 49 8D 8E", new byte?[] { 0x90, 0x90, 0x90, 0x90, 0x90, 0xEB });
// jmp 1Ch
private static readonly AsmPatch removeAutoFaceTargetPatch = new("80 7E 33 06 75 1E 48 8D 0D", [ 0x90, 0x90, 0x90, 0x90, 0xEB, 0x1C ]);
// jz -> jmp ??
private static readonly AsmPatch removeAutoFaceGroundTargetPatch = new("80 7E 33 06 74 21 48 8D 8F", [ 0x90, 0x90, 0x90, 0x90, 0xEB ]);

public override bool ShouldEnable => ReAction.Config.EnableEnhancedAutoFaceTarget;

Expand Down
4 changes: 2 additions & 2 deletions Modules/QueueAdjustments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static void PostUseAction(ActionManager* actionManager, uint actionType,
[HypostasisSignatureInjection("E8 ?? ?? ?? ?? 8B 4F 44 33 D2", Required = true)]
private static delegate* unmanaged<ActionManager*, uint, uint, int> getAdditionalRecastGroup;

[HypostasisSignatureInjection("E8 ?? ?? ?? ?? 84 C0 74 12 48 83 FF 0F", Required = true)]
[HypostasisSignatureInjection("E8 ?? ?? ?? ?? 84 C0 74 10 48 83 FF 0F", Required = true)]
private static delegate* unmanaged<ActionManager*, uint, Bool> canUseActionAsCurrentClass;

private static float? GetRemainingActionRecast(ActionManager* actionManager, uint actionType, uint actionID)
Expand All @@ -80,7 +80,7 @@ private static void PostUseAction(ActionManager* actionManager, uint actionType,

if (recastGroupDetail->IsActive == 0) return additionalRecastRemaining;

var charges = canUseActionAsCurrentClass(actionManager, recastGroupDetail->ActionID) ? FFXIVClientStructs.FFXIV.Client.Game.ActionManager.GetMaxCharges(ActionManager.GetSpellIDForAction(actionType, actionID), 90) : 1;
var charges = canUseActionAsCurrentClass(actionManager, recastGroupDetail->ActionId) ? FFXIVClientStructs.FFXIV.Client.Game.ActionManager.GetMaxCharges(ActionManager.GetSpellIDForAction(actionType, actionID), 90) : 1;
var recastRemaining = recastGroupDetail->Total / charges - recastGroupDetail->Elapsed;
return recastRemaining > additionalRecastRemaining ? recastRemaining : additionalRecastRemaining;
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/QueueMore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ReAction.Modules;

public unsafe class QueueMore : PluginModule
{
private static readonly AsmPatch allowQueuingPatch = new("76 0A 41 80 F8 04", new byte?[] { 0xEB });
private static readonly AsmPatch allowQueuingPatch = new("76 0A 41 80 F8 04", [ 0xEB ]);
private static ushort lastLBSequence = 0;

public override bool ShouldEnable => ReAction.Config.EnableQueuingMore;
Expand Down Expand Up @@ -39,7 +39,7 @@ private static void PreUseAction(ActionManager* actionManager, ref uint actionTy
case 5 when actionID == 4:
actionType = 1;
actionID = 3;
targetObjectID = DalamudApi.ClientState.LocalPlayer!.ObjectId;
targetObjectID = DalamudApi.ClientState.LocalPlayer!.GameObjectId;
break;
}
}
Expand Down
Loading

0 comments on commit d770d70

Please sign in to comment.