-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUndressUtilPlugin.cs
314 lines (248 loc) · 9.07 KB
/
UndressUtilPlugin.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
using System;
using System.Collections;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
using BepInEx;
using BepInEx.Logging;
using COM3D2API;
namespace COM3D2.UndressUtil.Plugin
{
public static class Version
{
public const string NUMBER = "1.3.0.7";
#if DEBUG
public const string RELEASE_TYPE = "debug";
#else
public const string RELEASE_TYPE = "release";
#endif
public const string VARIANT = "standard";
}
[BepInPlugin("org.bepinex.plugins.com3d2.undressutil", "UndressUtil", Version.NUMBER)]
[BepInDependency("deathweasel.com3d2.api", BepInDependency.DependencyFlags.HardDependency)]
public class UndressUtilPlugin: BaseUnityPlugin
{
private enum SceneTypeEnum
{
/// <summary>メイド選択(夜伽、品評会の前など)</summary>
SceneCharacterSelect = 1,
/// <summary>品評会</summary>
SceneCompetitiveShow = 2,
/// <summary>昼夜メニュー、仕事結果</summary>
SceneDaily = 3,
/// <summary>ダンス1(ドキドキ Fallin' Love)</summary>
SceneDance_DDFL = 4,
/// <summary>メイドエディット</summary>
SceneEdit = 5,
/// <summary>メーカーロゴ</summary>
SceneLogo = 6,
/// <summary>メイド管理</summary>
SceneMaidManagement = 7,
/// <summary>ショップ</summary>
SceneShop = 8,
/// <summary>タイトル画面</summary>
SceneTitle = 9,
/// <summary>トロフィー閲覧</summary>
SceneTrophy = 10,
/// <summary>Chu-B Lip 夜伽</summary>
SceneYotogi_ChuB = 10,
/// <summary>???</summary>
SceneTryInfo = 11,
/// <summary>主人公エディット</summary>
SceneUserEdit = 12,
/// <summary>起動時警告画面</summary>
SceneWarning = 13,
/// <summary>夜伽</summary>
SceneYotogi = 14,
/// <summary>ADVパート(kgスクリプト処理)</summary>
SceneADV = 15,
/// <summary>日付画面</summary>
SceneStartDaily = 16,
/// <summary>タイトルに戻る</summary>
SceneToTitle = 17,
/// <summary>MVP</summary>
SceneSingleEffect = 18,
/// <summary>スタッフロール</summary>
SceneStaffRoll = 19,
/// <summary>ダンス2(Entrance To You)</summary>
SceneDance_ETY = 20,
/// <summary>ダンス3(Scarlet Leap)</summary>
SceneDance_SL = 22,
/// <summary>回想モード</summary>
SceneRecollection = 24,
/// <summary>撮影モード</summary>
ScenePhotoMode = 27,
/// <summary>Guest mode</summary>
SceneGuestMode = 53,
/// <sumary>Scout mode</sumary>
SceneScoutMode = 114
}
private static int[] EnableScenes = {
(int)SceneTypeEnum.SceneADV,
(int)SceneTypeEnum.SceneRecollection,
(int)SceneTypeEnum.SceneGuestMode,
(int)SceneTypeEnum.SceneScoutMode,
};
public static UndressUtilPlugin Instance { get; private set; }
public static UndressWindowManager Manager { get; private set; }
public static bool IsOnOrPastTitleScreen { get; private set; } = false;
public new UndressUtilConfig Config { get; private set; }
internal new ManualLogSource Logger { get
{
return base.Logger;
}
}
public bool IsAutoShow
{
get
{
if (GameMain.Instance.VRMode)
{
return Config.autoShowInVr.Value;
}
else
{
return Config.autoShowInNonVr.Value;
}
}
}
public bool IsAutoHide => Config.autoHide.Value;
public bool IsInSupportedLevel
{
get
{
if (Config.autoShowInAllScenes.Value) return true;
if (EnableScenes.Contains(currentLevel)) return true;
if (IsInYotogiLevel && Config.autoShowInYotogi.Value) return true;
return false;
}
}
public bool IsInYotogiLevel
{
get
{
return currentLevel == (int)SceneTypeEnum.SceneYotogi || currentLevel == (int)SceneTypeEnum.SceneYotogi_ChuB;
}
}
public bool IsInTitleLevel => currentLevel == (int)SceneTypeEnum.SceneTitle;
public bool IsKeepYotogiDressState => Config.keepYotogiUndressState.Value;
private int currentLevel;
void Awake()
{
if (UndressUtilPlugin.Instance != null)
{
throw new Exception("Already initialized");
}
GameObject.DontDestroyOnLoad(this);
UndressUtilPlugin.Instance = this;
this.Config = new UndressUtilConfig(base.Config);
this.enabled = this.Config.enable.Value;
this.Config.enable.SettingChanged += (sender, e) =>
{
this.enabled = this.Config.enable.Value;
if(this.enabled)
{
Log.LogInfo("Plugin enabled.");
}
else
{
Log.LogWarning("Plugin disabled. You must restart the game for settings to take effect");
}
};
Log.LogInfo("Plugin load complete!");
if (!this.enabled)
{
Log.LogWarning("Plugin is disabled in configuration. Enable in F1 configuration manager to use.");
}
}
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
currentLevel = scene.buildIndex;
if (IsInTitleLevel)
{
IsOnOrPastTitleScreen = true;
}
if (!this.enabled)
{
return;
}
StopCoroutine(nameof(AutoShowStartCoroutine));
if (IsAutoShow && IsOnOrPastTitleScreen && IsInSupportedLevel)
{
StartCoroutine(nameof(AutoShowStartCoroutine));
}
}
void Start()
{
Log.LogInfo("Plugin startup...");
SystemShortcutAPI.AddButton(
"Undress utility",
SystemShortcutCallback,
"Undress utility",
GetIcon());
SceneManager.sceneLoaded += this.OnSceneLoaded;
StartCoroutine(KeyboardCheckCoroutine());
Log.LogInfo("Plugin startup complete. Version {0}-{1} ({2})", Version.NUMBER, Version.VARIANT, Version.RELEASE_TYPE);
}
byte[] GetIcon()
{
var assembly = GetType().Assembly;
using (var stream = assembly.GetManifestResourceStream("COM3D2.UndressUtil.Plugin.Icon.png"))
{
var buffer = new byte[stream.Length];
stream.Read(buffer, 0, (int)stream.Length);
return buffer;
}
}
private UndressWindowManager EnsureManagerInitialized()
{
if(Manager == null)
{
Log.LogInfo("Initializing UndressWindowManager...");
GameObject uiroot = GameObject.Find("SystemUI Root");
Assert.IsNotNull(uiroot, "Could not find SystemUI Root");
var obj = Prefabs.CreateUndressWindow(uiroot);
Manager = obj.GetComponent<UndressWindowManager>();
Log.LogInfo("UndressWindowManager initialization complete!");
}
return Manager;
}
private void SystemShortcutCallback()
{
if (this.enabled)
{
StartCoroutine(SystemShortcutCallbackCoroutine());
}
}
private IEnumerator SystemShortcutCallbackCoroutine()
{
var manager = EnsureManagerInitialized();
yield return null;
manager.ToggleWindow();
}
private IEnumerator KeyboardCheckCoroutine()
{
while (true)
{
yield return null;
var shortcut = UndressUtilPlugin.Instance.Config.showShortcut.Value;
if (shortcut.IsDown())
{
EnsureManagerInitialized();
yield return null;
Log.LogInfo("Toggling undress window window...");
Manager.ToggleWindow();
}
}
}
private IEnumerator AutoShowStartCoroutine()
{
yield return new WaitForSeconds(1);
Log.LogInfo("AutoShow start");
var manager = EnsureManagerInitialized();
yield return null;
manager.DelayedShowWindow();
Log.LogInfo("Delayed show queued 1s");
}
}
}