-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathBrioAPI_V2.cs
374 lines (301 loc) · 16.1 KB
/
BrioAPI_V2.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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Plugin;
using Dalamud.Plugin.Ipc;
using System.Numerics;
namespace Brio;
public static class BrioAPI
{
public static readonly (int major, int minor) APIVersion = (2, 0);
private static bool hasInit = false;
//
private static ICallGateSubscriber<(int, int)> API_Version_IPC;
private static ICallGateSubscriber<IGameObject?> Actor_Spawn_IPC;
private static ICallGateSubscriber<Task<IGameObject?>> Actor_SpawnAsync_IPC;
private static ICallGateSubscriber<bool, bool, bool, Task<IGameObject?>> Actor_SpawnExAsync_IPC;
private static ICallGateSubscriber<IGameObject, bool> Actor_DespawnActor_Ipc;
private static ICallGateSubscriber<IGameObject, Vector3?, Quaternion?, Vector3?, bool, bool> Actor_SetModelTransform_IPC;
private static ICallGateSubscriber<IGameObject, (Vector3?, Quaternion?, Vector3?)> Actor_GetModelTransform_IPC;
private static ICallGateSubscriber<IGameObject, bool> Actor_ResetModelTransform_IPC;
private static ICallGateSubscriber<IGameObject, string, bool> Actor_Pose_LoadFromFile_IPC;
private static ICallGateSubscriber<IGameObject, string, bool, bool> Actor_Pose_LoadFromJson_IPC;
private static ICallGateSubscriber<IGameObject, string> Actor_Pose_GetFromJson_IPC;
private static ICallGateSubscriber<IGameObject, bool, bool> Actor_Pose_Reset_IPC;
private static ICallGateSubscriber<IGameObject, bool> Actor_Exists_IPC;
private static ICallGateSubscriber<IGameObject[]?> Actor_GetAll_IPC;
private static ICallGateSubscriber<IGameObject, float, bool> Actor_SetSpeed_IPC;
private static ICallGateSubscriber<IGameObject, float> Actor_GetSpeed_IPC;
private static ICallGateSubscriber<IGameObject, bool> Actor_Freeze_IPC;
private static ICallGateSubscriber<IGameObject, bool> Actor_UnFreeze_IPC;
private static ICallGateSubscriber<bool> FreezePhysics_IPC;
private static ICallGateSubscriber<bool> UnFreezePhysics_IPC;
//
//
/// <summary>
/// Initializes the Brio API with the given plugin interface.
/// </summary>
/// <param name="pluginInterface">The Dalamud plugin interface.</param>
public static void InitBrioAPI(IDalamudPluginInterface pluginInterface)
{
hasInit = true;
API_Version_IPC = pluginInterface.GetIpcSubscriber<(int, int)>("Brio.ApiVersion");
Actor_Spawn_IPC = pluginInterface.GetIpcSubscriber<IGameObject?>("Brio.Actor.Spawn");
Actor_SpawnAsync_IPC = pluginInterface.GetIpcSubscriber<Task<IGameObject?>>("Brio.Actor.SpawnAsync");
Actor_SpawnExAsync_IPC = pluginInterface.GetIpcSubscriber<bool, bool, bool, Task<IGameObject?>>("Brio.Actor.SpawnExAsync");
Actor_DespawnActor_Ipc = pluginInterface.GetIpcSubscriber<IGameObject, bool>("Brio.Actor.Despawn");
Actor_SetModelTransform_IPC = pluginInterface.GetIpcSubscriber<IGameObject, Vector3?, Quaternion?, Vector3?, bool, bool>("Brio.Actor.SetModelTransform");
Actor_GetModelTransform_IPC = pluginInterface.GetIpcSubscriber<IGameObject, (Vector3?, Quaternion?, Vector3?)>("Brio.Actor.GetModelTransform");
Actor_ResetModelTransform_IPC = pluginInterface.GetIpcSubscriber<IGameObject, bool>("Brio.Actor.ResetModelTransform");
Actor_Pose_LoadFromFile_IPC = pluginInterface.GetIpcSubscriber<IGameObject, string, bool>("Brio.Actor.Pose.LoadFromFile");
Actor_Pose_LoadFromJson_IPC = pluginInterface.GetIpcSubscriber<IGameObject, string, bool, bool>("Brio.Actor.Pose.LoadFromJson");
Actor_Pose_GetFromJson_IPC = pluginInterface.GetIpcSubscriber<IGameObject, string>("Brio.Actor.Pose.GetPoseAsJson");
Actor_Pose_Reset_IPC = pluginInterface.GetIpcSubscriber<IGameObject, bool, bool>("Brio.Actor.Pose.Reset");
Actor_Exists_IPC = pluginInterface.GetIpcSubscriber<IGameObject, bool>("Brio.Actor.Exists");
Actor_GetAll_IPC = pluginInterface.GetIpcSubscriber<IGameObject[]?>("Brio.Actor.GetAll");
Actor_SetSpeed_IPC = pluginInterface.GetIpcSubscriber<IGameObject, float, bool>("Brio.Actor.SetSpeed");
Actor_GetSpeed_IPC = pluginInterface.GetIpcSubscriber<IGameObject, float>("Brio.Actor.GetSpeed");
Actor_Freeze_IPC = pluginInterface.GetIpcSubscriber<IGameObject, bool>("Brio.Actor.Freeze");
Actor_UnFreeze_IPC = pluginInterface.GetIpcSubscriber<IGameObject, bool>("Brio.Actor.UnFreeze");
FreezePhysics_IPC = pluginInterface.GetIpcSubscriber<bool>("Brio.FreezePhysics");
UnFreezePhysics_IPC = pluginInterface.GetIpcSubscriber<bool>("Brio.UnFreezePhysics");
}
/// <summary>
/// Checks if the API version is compatible with this implementation on Brio's IPC API.
/// </summary>
/// <returns>True if the API version is compatible, otherwise false.</returns>
public static bool IsVersionCompatible()
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return API_Version_IPC.InvokeFunc() == APIVersion;
}
/// <summary>
/// Gets the Brio IPC API version .
/// </summary>
/// <returns>A tuple containing the major and minor version numbers.</returns>
public static (int Major, int Minor) GetVersion()
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return API_Version_IPC.InvokeFunc();
}
/// <summary>
/// Spawns an actor.
/// </summary>
/// <returns>The spawned actor, or null if the spawn failed.</returns>
public static IGameObject? SpawnActor()
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_Spawn_IPC.InvokeFunc();
}
/// <summary>
/// Spawns an actor asynchronously.
/// </summary>
/// <param name="spawnWithCompanionSlot">Whether to spawn with a companion slot.</param>
/// <param name="selectInHierarchy">Whether to select the actor in the hierarchy.</param>
/// <param name="spawnFrozen">Whether to spawn the actor with animation speed of 0f.</param>
/// <returns>The spawned actor, or null if the spawn failed.</returns>
public static async Task<IGameObject?> SpawnActorAsync(bool spawnWithCompanionSlot = false, bool selectInHierarchy = false, bool spawnFrozen = false)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return await Actor_SpawnExAsync_IPC.InvokeFunc(spawnWithCompanionSlot, selectInHierarchy, spawnFrozen);
}
/// <summary>
/// Despawns an actor.
/// </summary>
/// <param name="actorToDespawn">The actor to despawn.</param>
/// <returns>True if the actor was successfully despawned, otherwise false.</returns>
public static bool DespawnActor(IGameObject actorToDespawn)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_DespawnActor_Ipc.InvokeFunc(actorToDespawn);
}
/// <summary>
/// Sets the model transform of an actor.
/// </summary>
/// <param name="actor">The actor to transform.</param>
/// <param name="position">The new position of the actor.</param>
/// <param name="rotation">The new rotation of the actor.</param>
/// <param name="scale">The new scale of the actor.</param>
/// <param name="additive">Whether the transformation should be additive otherwise will override.</param>
/// <returns>True if the transformation was successful, otherwise false.</returns>
public static bool SetActorModelTransform(IGameObject actor, Vector3? position, Quaternion? rotation, Vector3? scale, bool additive = true)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_SetModelTransform_IPC.InvokeFunc(actor, position, rotation, scale, additive);
}
/// <summary>
/// Gets the model transform of an actor.
/// </summary>
/// <param name="actor">The actor to get the transform of.</param>
/// <returns>A tuple containing the position, rotation, and scale of the actor.</returns>
public static (Vector3? Position, Quaternion? Rotation, Vector3? Scale) GetActorModelTransform(IGameObject actor)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_GetModelTransform_IPC.InvokeFunc(actor);
}
/// <summary>
/// Resets the model transform of an actor.
/// </summary>
/// <param name="actor">The actor to reset the transform of.</param>
/// <returns>True if the transformation was successfully reset, otherwise false.</returns>
public static bool ResetActorModelTransform(IGameObject actor)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_ResetModelTransform_IPC.InvokeFunc(actor);
}
/// <summary>
/// Sets the position of an actor.
/// </summary>
/// <param name="actor">The actor to set the position of.</param>
/// <param name="position">The new position of the actor.</param>
/// <param name="additive">Whether the position change should be additive otherwise will override.</param>
/// <returns>True if the position was successfully set, otherwise false.</returns>
public static bool SetActorPosition(IGameObject actor, Vector3 position, bool additive = true)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_SetModelTransform_IPC.InvokeFunc(actor, position, null, null, additive);
}
/// <summary>
/// Sets the rotation of an actor.
/// </summary>
/// <param name="actor">The actor to set the rotation of.</param>
/// <param name="rotation">The new rotation of the actor.</param>
/// <param name="additive">Whether the rotation change should be additive otherwise will override.</param>
/// <returns>True if the rotation was successfully set, otherwise false.</returns>
public static bool SetActorRotation(IGameObject actor, Quaternion rotation, bool additive = true)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_SetModelTransform_IPC.InvokeFunc(actor, null, rotation, null, additive);
}
/// <summary>
/// Sets the scale of an actor.
/// </summary>
/// <param name="actor">The actor to set the scale of.</param>
/// <param name="scale">The new scale of the actor.</param>
/// <param name="additive">Whether the scale change should be additive otherwise will override.</param>
/// <returns>True if the scale was successfully set, otherwise false.</returns>
public static bool SetActorScale(IGameObject actor, Vector3 scale, bool additive = true)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_SetModelTransform_IPC.InvokeFunc(actor, null, null, scale, additive);
}
/// <summary>
/// Sets the pose of an actor from a file path.
/// </summary>
/// <param name="actor">The actor to set the pose of.</param>
/// <param name="fileName">The file path to load the pose from.</param>
/// <returns>True if the pose was successfully set, otherwise false.</returns>
public static bool SetActorPoseFromFilePath(IGameObject actor, string fileName)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_Pose_LoadFromFile_IPC.InvokeFunc(actor, fileName);
}
/// <summary>
/// Sets the pose of an actor from a JSON string.
/// </summary>
/// <param name="actor">The actor to set the pose of.</param>
/// <param name="json">The JSON string to load the pose from.</param>
/// <param name="isCMPformat">Whether the JSON string is in the CMP format.</param>
/// <returns>True if the pose was successfully set, otherwise false.</returns>
public static bool SetActorPoseFromJson(IGameObject actor, string json, bool isCMPformat = false)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_Pose_LoadFromJson_IPC.InvokeFunc(actor, json, isCMPformat);
}
/// <summary>
/// Gets the pose of an actor as a JSON string.
/// </summary>
/// <param name="actor">The actor to get the pose of.</param>
/// <returns>The pose of the actor as a JSON string.</returns>
public static string GetActorPoseAsJson(IGameObject actor)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_Pose_GetFromJson_IPC.InvokeFunc(actor);
}
/// <summary>
/// Resets the pose of an actor.
/// </summary>
/// <param name="actor">The actor to reset the pose of.</param>
/// <param name="clearRedoHistory">Whether to clear the redo history.</param>
/// <returns>True if the pose was successfully reset, otherwise false.</returns>
public static bool ResetActorPose(IGameObject actor, bool clearRedoHistory = false)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_Pose_Reset_IPC.InvokeFunc(actor, clearRedoHistory);
}
/// <summary>
/// Checks if an actor exists.
/// </summary>
/// <param name="actor">The actor to check.</param>
/// <returns>True if the actor exists, otherwise false.</returns>
public static bool ActorExists(IGameObject actor)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_Exists_IPC.InvokeFunc(actor);
}
/// <summary>
/// Gets all active actors.
/// </summary>
/// <returns>A tuple containing a boolean indicating if there is at least one actor, and an array of all active actors.</returns>
public static (bool HasAtLeastOne, IGameObject[] Actors) GetAllActiveActors()
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
var actors = Actor_GetAll_IPC.InvokeFunc();
return (actors?.Length > 1, actors!);
}
/// <summary>
/// Sets the speed of the specified actor.
/// </summary>
/// <param name="actor">The actor whose speed is to be set.</param>
/// <param name="speed">The speed to set for the actor.</param>
/// <returns>True if the speed was successfully set, otherwise false.</returns>
public static bool SetActorSpeed(IGameObject actor, float speed)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_SetSpeed_IPC.InvokeFunc(actor, speed);
}
/// <summary>
/// Gets the speed of the specified actor.
/// </summary>
/// <param name="actor">The actor whose speed is to be retrieved.</param>
/// <returns>The speed of the specified actor.</returns>
public static float GetActorSpeed(IGameObject actor)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_GetSpeed_IPC.InvokeFunc(actor);
}
/// <summary>
/// Freezes the specified actor.
/// </summary>
/// <param name="actor">The actor to be frozen.</param>
/// <returns>True if the actor was successfully frozen, otherwise false.</returns>
public static bool FreezeActor(IGameObject actor)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_Freeze_IPC.InvokeFunc(actor);
}
/// <summary>
/// Unfreezes the specified actor.
/// </summary>
/// <param name="actor">The actor to be unfrozen.</param>
/// <returns>True if the actor was successfully unfrozen, otherwise false.</returns>
public static bool UnFreezeActor(IGameObject actor)
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return Actor_UnFreeze_IPC.InvokeFunc(actor);
}
/// <summary>
/// Freezes FFXIV's physics simulation.
/// </summary>
public static bool FreezePhysics()
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return FreezePhysics_IPC.InvokeFunc();
}
/// <summary>
/// Unfreezes FFXIV's physics simulation.
/// </summary>
public static bool UnFreezePhysics()
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");
return UnFreezePhysics_IPC.InvokeFunc();
}
}