-
Notifications
You must be signed in to change notification settings - Fork 9
/
IPC.cs
86 lines (75 loc) · 3.44 KB
/
IPC.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
using System;
using System.Collections.Generic;
using System.Numerics;
using Dalamud.Plugin.Ipc;
using Newtonsoft.Json;
namespace SimpleHeels;
public static class IPC {
public static class CustomizePlus {
private static readonly ICallGateSubscriber<(int Breaking, int Feature)> GetApiVersionSubscriber;
private static readonly ICallGateSubscriber<bool> IsValidSubscriber;
private static readonly ICallGateSubscriber<ushort, (int errorCode, Guid? result)> GetActiveProfileIdOnCharacterSubscriber;
private static readonly ICallGateSubscriber<Guid, (int errorCode, string? result)> GetProfileByUniqueIdSubscriber;
public class Profile {
public class BoneConfig {
public Vector3 Translation;
public Vector3 Rotation;
public Vector3 Scaling;
public bool PropagateTranslation;
public bool PropagateRotation;
public bool PropagateScale;
}
public Dictionary<string, BoneConfig> Bones = new();
}
static CustomizePlus() {
GetApiVersionSubscriber = PluginService.PluginInterface.GetIpcSubscriber<(int Breaking, int Feature)>("CustomizePlus.General.GetApiVersion");
IsValidSubscriber = PluginService.PluginInterface.GetIpcSubscriber<bool>("CustomizePlus.General.IsValid");
GetActiveProfileIdOnCharacterSubscriber = PluginService.PluginInterface.GetIpcSubscriber<ushort, (int errorCode, Guid? result)>("CustomizePlus.Profile.GetActiveProfileIdOnCharacter");
GetProfileByUniqueIdSubscriber = PluginService.PluginInterface.GetIpcSubscriber<Guid, (int errorCode, string? result)>("CustomizePlus.Profile.GetByUniqueId");
}
public static bool GetApiVersion(out int breaking, out int feature) {
try {
(breaking, feature) = GetApiVersionSubscriber.InvokeFunc();
return true;
} catch {
breaking = 0;
feature = 0;
return false;
}
}
public static bool IsValid() {
try {
if (!GetApiVersion(out var breaking, out _) || breaking != 6) return false;
return IsValidSubscriber.InvokeFunc();
} catch {
return false;
}
}
public static Guid? GetActiveProfileIdOnCharacter(ushort gameObjectIndex) {
try {
var r = GetActiveProfileIdOnCharacterSubscriber.InvokeFunc(gameObjectIndex);
return r.errorCode == 0 ? r.result : null;
} catch {
return null;
}
}
public static string? GetProfileByUniqueId(Guid guid) {
try {
var r = GetProfileByUniqueIdSubscriber.InvokeFunc(guid);
return r.errorCode == 0 ? r.result : null;
} catch {
return null;
}
}
public static Profile? GetProfileOnCharacter(ushort gameObjectIndex) {
using var _ = PerformanceMonitors.Run("IPC.GetCustomizePlusProfile");
try {
if (!IsValid()) return null;
var profileId = GetActiveProfileIdOnCharacter(gameObjectIndex);
return profileId == null ? null : JsonConvert.DeserializeObject<Profile>(GetProfileByUniqueId(profileId.Value) ?? "{}");
} catch {
return null;
}
}
}
}