This repository was archived by the owner on Jan 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVelaraUtils.cs
193 lines (157 loc) · 7.04 KB
/
VelaraUtils.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
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
using System;
using System.Threading;
using Dalamud.Data;
using Dalamud.Game;
using Dalamud.Game.ClientState;
using Dalamud.Game.ClientState.Buddy;
using Dalamud.Game.Command;
using Dalamud.Game.Gui;
using Dalamud.IoC;
using Dalamud.Plugin;
using Dalamud.Game.ClientState.Conditions;
using VelaraUtils.Internal;
using XivCommon;
using Dalamud.Game.ClientState.Party;
using FFXIVClientStructs.FFXIV.Client.Game;
using VelaraUtils.Chat;
using VelaraUtils.Configuration;
using VelaraUtils.Internal.Command;
using VelaraUtils.Internal.IPC;
using VelaraUtils.Internal.Macro;
using VelaraUtils.Internal.Target;
using VelaraUtils.Utils;
using ActionManager = VelaraUtils.Internal.Action.ActionManager;
// ReSharper disable UnusedAutoPropertyAccessor.Local
namespace VelaraUtils;
// ReSharper disable once ClassNeverInstantiated.Global
public unsafe class VelaraUtils : IDalamudPlugin
{
public const string PluginName = "VelaraUtils";
public const string Prefix = "VelaraUtils";
public string Name => PluginName;
private bool _disposed;
#nullable disable
[PluginService] internal static DalamudPluginInterface PluginInterface { get; private set; }
[PluginService] internal static SigScanner Scanner { get; private set; }
[PluginService] internal static ClientState Client { get; private set; }
[PluginService] internal static DataManager DataManager { get; private set; }
[PluginService] internal static ChatGui Chat { get; private set; }
[PluginService] internal static GameGui GameGui { get; private set; }
[PluginService] internal static CommandManager CmdManager { get; private set; }
[PluginService] internal static Condition Conditions { get; private set; }
[PluginService] internal static PartyList PartyList { get; private set; }
[PluginService] internal static BuddyList BuddyList { get; private set; }
internal static ConfigLoader ConfigLoader { get; private set; }
internal static GlobalConfiguration GlobalConfiguration { get; private set; }
internal static IVariablesConfiguration VariablesConfiguration { get; private set; }
internal static QolBar QolBar { get; private set; }
internal static XivCommonBase Common { get; private set; }
// internal static PluginCommandDelegate? PluginHelpCommand { get; private set; }
internal static PluginCommandManager CommandManager { get; private set; }
internal static PlaySound Sfx { get; private set; }
internal static TerritoryManager TerritoryManager { get; private set; }
internal static dynamic TargetManager { get; private set; }
// internal static CameraManager* CameraManager { get; private set; }
internal static ActionManager ActionManager { get; private set; }
internal static MacroManager MacroManager { get; private set; }
internal static CancellationTokenSource TaskScheduler { get; private set; }
#nullable restore
private static delegate* unmanaged<uint, uint, uint> _getActionId;
public VelaraUtils()
{
ConfigLoader = new ConfigLoader(PluginInterface!);
GlobalConfiguration = (GlobalConfiguration)(PluginInterface!.GetPluginConfig() ?? new GlobalConfiguration());
GlobalConfiguration.Initialize();
VariablesConfiguration = ConfigLoader.Load<VariablesConfiguration>("Variables");
// PluginHelpCommand = Delegate.CreateDelegate(typeof(PluginCommandDelegate), null,
// typeof(PluginCommands)
// .GetMethods()
// .First(m => m.GetCustomAttribute<PluginCommandHelpHandlerAttribute>() is not null)
// ) as PluginCommandDelegate;
// if (PluginHelpCommand is null)
// Logger.Warning("No plugin command was flagged as the default help/usage text method");
// CommandManager = new PluginCommandManager(PluginInterface);
Common = new XivCommonBase(); // just need the chat feature to send commands
Sfx = new PlaySound();
TerritoryManager = new TerritoryManager();
TargetManager = TargetState.Initialize(PluginInterface);
// CameraManager = (CameraManager*)Scanner?.GetStaticAddressFromSig("48 8D 35 ?? ?? ?? ?? 48 8B 09");
ActionManager = ActionManager.Initialize(PluginInterface);
MacroManager = MacroManager.Initialize(PluginInterface);
TaskScheduler = new CancellationTokenSource();
_getActionId = (delegate* unmanaged<uint, uint, uint>)Scanner?.ScanText("E8 ?? ?? ?? ?? 44 8B 4B 2C");
PlayLib.Init();
OffsetManager.Setup(Scanner!);
Client!.Login += OnLogin;
Client.Logout += OnLogout;
QolBar = new QolBar(PluginInterface);
if (VariablesConfiguration.Variables.TryGetValue("__init", out var cmd))
{
cmd = cmd.ExpandTokens(VariablesConfiguration.Variables);
if (cmd.Length > 0) ChatUtil.SendChatLineToServer(cmd);
}
CommandManager = new PluginCommandManager(PluginInterface);
}
private static void OnLogin(object? sender, EventArgs e)
{
if (VariablesConfiguration.Variables.TryGetValue("__login", out var cmd))
{
cmd = cmd.ExpandTokens(VariablesConfiguration.Variables);
if (cmd.Length > 0) ChatUtil.SendChatLineToServer(cmd);
}
}
private static void OnLogout(object? sender, EventArgs e)
{
if (VariablesConfiguration.Variables.TryGetValue("__logout", out var cmd))
{
cmd = cmd.ExpandTokens(VariablesConfiguration.Variables);
if (cmd.Length > 0) ChatUtil.SendChatLineToServer(cmd);
}
}
public static uint GetActionId(uint actionType, uint actionCategoryId)
{
return _getActionId(actionType, actionCategoryId);
}
public static uint GetActionId(ActionType actionType, uint actionCategoryId)
{
return _getActionId((uint)actionType, actionCategoryId);
}
// public static unsafe float GetRecastTime(ActionType actionType, uint actionId) =>
// MathF.Min(0, ActionManager.Instance()->GetRecastTime(actionType, actionId));
//
// public static float GetRecastTime(byte actionType, uint actionId) =>
// GetRecastTime((ActionType)actionType, actionId);
#region IDisposable Support
protected virtual void Dispose(bool disposing)
{
if (_disposed)
return;
if (disposing)
{
Client!.Login -= OnLogin;
Client.Logout -= OnLogout;
if (VariablesConfiguration.Variables.TryGetValue("__deinit", out var cmd))
{
cmd = cmd.ExpandTokens(VariablesConfiguration.Variables);
if (cmd.Length > 0) ChatUtil.SendChatLineToServer(cmd);
}
GlobalConfiguration.Save();
ConfigLoader.Save("Variables", VariablesConfiguration);
CommandManager?.Dispose();
// PluginInterface?.Dispose();
ActionManager?.Dispose();
MacroManager?.Dispose();
}
_disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
~VelaraUtils()
{
Dispose(false);
}
#endregion
}