-
Notifications
You must be signed in to change notification settings - Fork 0
/
KagHooks.cs
165 lines (146 loc) · 6.25 KB
/
KagHooks.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
using CM3D2.ExternalSaveData.Managed;
using script;
using System;
using System.Reflection;
using UnityEngine;
using System.Diagnostics;
internal static class KagHooks {
static bool bKagTagPropSetHooked = false;
static string PluginName;
static MethodInfo GetWaitEventListMethodInfo;
delegate bool TagProcDelegate(BaseKagManager baseKagManager, KagTagSupport tag_data);
public static void SetHook(string PluginName_, bool bForceSet) {
PluginName = PluginName_;
if (!bForceSet && bKagTagPropSetHooked) {
return;
}
bKagTagPropSetHooked = true;
HookTagCallback("propset", TagPropSet);
HookTagCallback("faceblend", TagFaceBlend);
HookTagCallback("face", TagFace);
HookTagCallback("eyetocamera", TagEyeToCamera);
}
static void HookTagCallback(string tagName, TagProcDelegate tagProcDelegate) {
foreach (var kv in GameMain.Instance.ScriptMgr.kag_mot_dic) {
BaseKagManager mgr = kv.Value;
KagScript kag = mgr.kag;
kag.RemoveTagCallBack(tagName);
if (tagProcDelegate == null) continue;
kag.AddTagCallBack(tagName, new KagScript.KagTagCallBack(delegate (KagTagSupport tag_data) {
return tagProcDelegate(mgr, tag_data);
}));
}
{
BaseKagManager mgr = GameMain.Instance.ScriptMgr.adv_kag;
KagScript kag = mgr.kag;
kag.RemoveTagCallBack(tagName);
if (tagProcDelegate != null) {
kag.AddTagCallBack(tagName, new KagScript.KagTagCallBack(delegate (KagTagSupport tag_data) {
return tagProcDelegate(mgr, tag_data);
}));
}
}
{
BaseKagManager mgr = GameMain.Instance.ScriptMgr.yotogi_kag;
KagScript kag = mgr.kag;
kag.RemoveTagCallBack(tagName);
if (tagProcDelegate != null) {
kag.AddTagCallBack(tagName, new KagScript.KagTagCallBack(delegate (KagTagSupport tag_data) {
return tagProcDelegate(mgr, tag_data);
}));
}
}
}
static bool TagPropSet(BaseKagManager baseKagManager, KagTagSupport tag_data) {
Maid maidAndMan = baseKagManager.GetMaidAndMan(tag_data);
if (maidAndMan != null && ExSaveData.GetBool(maidAndMan, PluginName, "PROPSET_OFF", false)) {
string str = tag_data.GetTagProperty("category").AsString();
if (Array.IndexOf(PluginHelper.MpnStrings, str) >= 0) {
#if DEBUG
Console.WriteLine("PROPSET_OFF(category={0}) -> match", str);
Helper.Log("PROPSET_OFF(category={0}) -> match", str);
#endif
return false;
}
}
return baseKagManager.TagPropSet(tag_data);
}
static bool TagEyeToCamera(BaseKagManager baseKagManager, KagTagSupport tag_data) {
Maid maidAndMan = baseKagManager.GetMaidAndMan(tag_data);
if (maidAndMan != null && ExSaveData.GetBool(maidAndMan, PluginName, "EYETOCAMERA_OFF", false)) {
return false;
}
return baseKagManager.TagEyeToCamera(tag_data);
}
static bool TagFace(BaseKagManager baseKagManager, KagTagSupport tag_data) {
Maid maidAndMan = baseKagManager.GetMaidAndMan(tag_data);
if (maidAndMan == null) {
return false;
}
if (maidAndMan != null && ExSaveData.GetBool(maidAndMan, PluginName, "FACE_OFF", false)) {
// Helper.Log("FACE_OFF() -> match");
return false;
}
baseKagManager.CheckAbsolutelyNecessaryTag(tag_data, "face", new string[] { "name" });
string oldName = tag_data.GetTagProperty("name").AsString();
string newName = FaceScriptTemplates.ProcFaceName(maidAndMan, PluginName, oldName);
// Helper.Log("TagFace({0})->({1})", oldName, newName);
WaitEventList waitEventList = GetWaitEventList(baseKagManager, "face");
int num = 0;
if (tag_data.IsValid("wait")) {
num = tag_data.GetTagProperty("wait").AsInteger();
}
if (num > 0) {
waitEventList.Add(() => {
if (maidAndMan != null && maidAndMan.body0 != null && maidAndMan.body0.isLoadedBody) {
maidAndMan.FaceAnime(newName, 1f, 0);
}
}, num);
} else {
maidAndMan.FaceAnime(newName, 1f, 0);
waitEventList.Clear();
}
return false;
}
static bool TagFaceBlend(BaseKagManager baseKagManager, KagTagSupport tag_data) {
Maid maidAndMan = baseKagManager.GetMaidAndMan(tag_data);
if (maidAndMan == null) {
return false;
}
if (ExSaveData.GetBool(maidAndMan, PluginName, "FACEBLEND_OFF", false)) {
Trace.WriteLine("FACEBLEND_OFF() -> match");
return false;
}
baseKagManager.CheckAbsolutelyNecessaryTag(tag_data, "faceblend", new string[] { "name" });
string oldName = tag_data.GetTagProperty("name").AsString();
if (oldName == "なし") {
oldName = "無し";
}
string newName = FaceScriptTemplates.ProcFaceBlendName(maidAndMan, PluginName, oldName);
Trace.WriteLine(string.Format("TagFaceBlend({0})->({1})", oldName, newName));
if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "ScenePhotoMode") {
newName = "オリジナル";
}
maidAndMan.FaceBlend(newName);
return false;
}
static WaitEventList GetWaitEventList(BaseKagManager baseKagManager, string list_name) {
// class BaseKagManager protected WaitEventList GetWaitEventList(string list_name)
MethodInfo methodInfo = GetWaitEventListMethodInfo;
if (methodInfo == null) {
methodInfo = typeof(BaseKagManager).GetMethod(
"GetWaitEventList",
BindingFlags.NonPublic | BindingFlags.Instance,
null,
new Type[] { typeof(string) },
null
);
GetWaitEventListMethodInfo = methodInfo;
}
if (methodInfo == null) {
return null;
}
object obj = methodInfo.Invoke(baseKagManager, new object[] { list_name });
return obj as WaitEventList;
}
}