-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventLoggerPlugin.cs
More file actions
233 lines (174 loc) · 7.19 KB
/
EventLoggerPlugin.cs
File metadata and controls
233 lines (174 loc) · 7.19 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
SideStep is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
You should have received a copy of the license along with this
work. If not, see <http://creativecommons.org/licenses/by-nc-sa/4.0/>.
Original work done by zzi
*/
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using ff14bot;
using ff14bot.AClasses;
using ff14bot.Behavior;
using ff14bot.Directors;
using ff14bot.Enums;
using ff14bot.Managers;
using ff14bot.Navigation;
using ff14bot.NeoProfiles;
using ff14bot.Objects;
using Sidestep.Helpers;
using SideStep.Helpers;
using TreeSharp;
using Logger = Sidestep.Logging.ELogger;
namespace Sidestep
{
// ReSharper disable once UnusedType.Global
public class EventLoggerPlugin : BotPlugin
{
public override string Author => "ZZI";
public override Version Version => new Version(7, 4, 0);
public override string Name => "EventLogger";
public override string Description => "Loggs common combat events to the console. You should only enable this plugin to debug avoidance. ";
public override bool WantButton => true;
public override string ButtonText => "Clear";
private readonly LRUCache<(uint, uint), uint> _loggedSpells = new(20);
private readonly Dictionary<uint, ulong> _loggedWorldStates = new();
// ObjID - VfxIDs
private readonly Dictionary<uint, HashSet<uint>> _loggedVFX = new();
private static ActionRunCoroutine? _sHook;
private List<uint> _party;
#region Plugin Settings
public override void OnButtonPress() => Clear();
public override void OnEnabled()
{
Logger.Verbose("EventLogger has been Enabled");
TreeRoot.OnStart += OnStart;
TreeRoot.OnStop += OnStop;
GameEvents.OnMapChanged += OnMapChanged;
}
private void OnMapChanged(object? sender, EventArgs e) => Clear();
private void OnStop(BotBase bot) => Clear();
private void OnStart(BotBase bot) => Clear();
private void Clear()
{
_loggedWorldStates.Clear();
_loggedVFX.Clear();
_party = PartyManager.AllMembers.Select(k => k.ObjectId).ToList();
}
public override void OnDisabled()
{
Logger.Verbose("EventLogger has been Disabled");
if (_sHook != null)
TreeHooks.Instance.RemoveHook("TreeStart", _sHook);
TreeRoot.OnStart -= OnStart;
TreeRoot.OnStop -= OnStop;
GameEvents.OnMapChanged -= OnMapChanged;
Clear();
}
public override void OnPulse()
{
//don't run if we don't have a navigation provider
if (Navigator.NavigationProvider == null)
return;
// don't run if we can't do combat
if (WorldManager.InSanctuary)
return;
using (new PerformanceLogger("Pulse"))
{
// spells
foreach (var obj in GameObjectManager.GetObjectsOfType<BattleCharacter>().Where(bc => !_party.Contains(bc.ObjectId)))
{
IsValid(obj);
}
// world events
if (DirectorManager.ActiveDirector != null && DirectorManager.ActiveDirector.IsValid && DirectorManager.ActiveDirector is InstanceContentDirector ic)
{
// MapEffects is a collection, avoid LINQ
foreach (var effect in ic.MapEffects)
{
MapEffects(effect);
}
}
}
}
#endregion
private void MapEffects(MapEffect arg)
{
var zoneId = WorldManager.ZoneId;
var key = arg.ID;
// Assuming State is 16-bit and Flags is 8-bit
var packed = ((ulong)arg.unk << 24) | // Move 32-bit unk to bits 24-55
((ulong)(arg.State & 0xFFFF) << 8) | // Move 16-bit State to bits 8-23
(ushort)(arg.Flags & 0xFF); // Place 8-bit Flags in bits 0-7
var log = _loggedWorldStates.GetValueOrDefault(arg.ID, (uint)0) != packed;
if (log)
{
_loggedWorldStates[arg.ID] = packed;
Logger.Info( $"[World Detection] [ID: {arg.ID}] [State: {arg.State}] [Flags: {arg.Flags}] [Unk: {arg.unk}]");
}
}
private void IsValid(BattleCharacter c)
{
if (c.IsDead)
{
_loggedVFX.Remove(c.ObjectId);
return;
}
var old = _loggedVFX.GetValueOrDefault(c.ObjectId, new HashSet<uint> { });
var nvfx = new HashSet<uint>();
var name = "name";
if (c.IsNpc)
name = c.Name;
var log = false || !_loggedSpells.contains((c.ObjectId, c.CastingSpellId));
// only log hostile spellcasts on targets
if (log && !c.IsMe && c.CastingSpellId > 0 && c.StatusFlags.HasFlag(StatusFlags.Hostile))
{
var oid = c.SpellCastInfo.SpellData.Omen;
var spid = c.CastingSpellId;
var cid = c.SpellCastInfo.SpellData.RawCastType;
_loggedSpells.add((c.ObjectId, c.CastingSpellId), c.NpcId);
Logger.Info( $"[Spell Detection] [npc: {c.NpcId}] [Obj: {c.ObjectId}] [Name: {name}] [Spell: {c.CastingSpellId}] [Spell Name: {c.SpellCastInfo.Name}] [Omen: {oid}] [Raw Cast Type: {cid}]");
}
if (c.VfxContainer.IsValid && (c.StatusFlags.HasFlag(StatusFlags.Hostile) || c.IsMe))
{
for (var index = 0; index < c.VfxContainer.Vfx.Length; index++)
{
var vfx = c.VfxContainer.Vfx[index];
if (vfx == null) continue;
if (!vfx.IsValid) continue;
nvfx.Add(vfx.Id);
if (old.Contains(vfx.Id))
{
continue;
}
Logger.Info($"[VFX Detection] [npc: {c.NpcId}] [Obj: {c.ObjectId}] [Name: {name}] [Vfx: {vfx.Id}] [Slot: {SlotName(index)}]");
}
_loggedVFX[c.ObjectId] = nvfx;
}
}
/// <summary>
/// This needs to be updated as the game updates
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
private string SlotName(int index)
{
switch (index)
{
case 0:
return "Spell - 0";
case 6:
case 7:
return $"Omen - 0x{index:X}";
case 10:
case 11:
case 12:
return $"Lockon - 0x{index:X}";
default:
return $"Unknown - 0x{index:X}";
}
}
}
}