-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddonEnemyListHooks.cs
72 lines (60 loc) · 2.29 KB
/
AddonEnemyListHooks.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using Dalamud.Game.Addon.Lifecycle;
using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
using FFXIVClientStructs.FFXIV.Client.Game.Character;
using FFXIVClientStructs.FFXIV.Client.System.Framework;
using FFXIVClientStructs.FFXIV.Client.UI;
using System;
using System.Linq;
namespace Interjection;
public unsafe class AddonEnemyListHooks : IDisposable
{
private readonly byte[] TankClasses = [
/*GLA*/ 1,
/*MRD*/ 3,
/*PLD*/ 19,
/*WAR*/ 21,
/*DRK*/ 32,
/*GNB*/ 37
];
private readonly EnemyList _enemyList;
public AddonEnemyListHooks()
{
Plugin.AddonLifecycle.RegisterListener(AddonEvent.PostDraw, "_EnemyList", AddonPostDraw);
_enemyList = new();
}
public void Dispose()
{
Plugin.AddonLifecycle.UnregisterListener(AddonPostDraw);
_enemyList.Dispose();
}
public void AddonPostDraw(AddonEvent type, AddonArgs args)
{
AddonEnemyList* thisPtr = (AddonEnemyList*)args.Addon;
if (thisPtr == null || !Plugin.Config.Enabled)
{
_enemyList.Dispose();
return;
}
if (!_enemyList.Built)
{
_enemyList.Initialize(thisPtr);
}
var numArrayHolder = Framework.Instance()->GetUIModule()->GetRaptureAtkModule()->AtkModule.AtkArrayDataHolder;
if (numArrayHolder.NumberArrayCount <= 21)
{
return;
}
var enemyListArray = numArrayHolder.NumberArrays[21];
for (var i = 0; i < thisPtr->EnemyCount; i++)
{
uint enemyObjectId = (uint)enemyListArray->IntArray[8 + i * 6];
BattleChara* enemyChara = CharacterManager.Instance()->LookupBattleCharaByEntityId(enemyObjectId);
if (enemyChara is null) continue;
BattleChara* targetChara = CharacterManager.Instance()->LookupBattleCharaByEntityId((uint)enemyChara->Character.GetTargetId());
bool isTargetTank = targetChara != null && TankClasses.Contains(targetChara->Character.CharacterData.ClassJob);
bool isTargetLocalPlayer = Plugin.ClientState.LocalPlayer?.EntityId == enemyChara->Character.GetTargetId();
var castinfo = enemyChara->GetCastInfo();
_enemyList.UpdateIndex(i, castinfo, isTargetTank && !isTargetLocalPlayer);
}
}
}