-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SignalisFix.cs
369 lines (322 loc) · 15.6 KB
/
SignalisFix.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
using BepInEx;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using BepInEx.Configuration;
using UnityEngine;
using BepInEx.Logging;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEngine.Events;
using System.Collections.Generic;
using System;
namespace SignalisFix
{
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
public class SignalisFix : BasePlugin
{
// Custom Resolution
public static ConfigEntry<bool> bCustomResolution;
public static ConfigEntry<float> fDesiredResolutionX;
public static ConfigEntry<float> fDesiredResolutionY;
public static ConfigEntry<int> iWindowMode;
// Features
public static ConfigEntry<bool> bUltrawideFixes;
public static ConfigEntry<bool> bIntroSkip;
internal static new ManualLogSource Log;
public override void Load()
{
Log = base.Log;
// Plugin startup logic
Log.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!");
// Custom Resolution
bCustomResolution = Config.Bind("Set Custom Resolution",
"CustomResolution",
false, // Game resolution options should suffice.
"Set to true to enable the custom resolution below.");
fDesiredResolutionX = Config.Bind("Set Custom Resolution",
"ResolutionWidth",
(float)Display.main.systemWidth, // Set default to display width so we don't leave an unsupported resolution as default.
"Set desired resolution width.");
fDesiredResolutionY = Config.Bind("Set Custom Resolution",
"ResolutionHeight",
(float)Display.main.systemHeight, // Set default to display height so we don't leave an unsupported resolution as default.
"Set desired resolution height.");
iWindowMode = Config.Bind("Set Custom Resolution",
"WindowMode",
(int)1,
new ConfigDescription("Set window mode. 1 = Fullscreen, 2 = Borderless, 3 = Windowed.",
new AcceptableValueRange<int>(1, 3)));
// Features
bUltrawideFixes = Config.Bind("General",
"UltrawideFixes",
true,
"Set to true to enable ultrawide fixes.");
bIntroSkip = Config.Bind("General",
"IntroSkip",
true,
"Skip intro logos.");
if (bCustomResolution.Value)
{
var __0 = (int)fDesiredResolutionX.Value;
var __1 = (int)fDesiredResolutionY.Value;
var __3 = 0; // Default to highest refresh rate
var fullscreenMode = iWindowMode.Value switch
{
1 => FullScreenMode.ExclusiveFullScreen,
2 => FullScreenMode.FullScreenWindow,
3 => FullScreenMode.Windowed,
_ => FullScreenMode.ExclusiveFullScreen,
};
Screen.SetResolution(__0, __1, fullscreenMode, __3);
Log.LogInfo($"Custom Resolution: Set resolution {__0}x{__1}@{__3}hz. Fullscreen = {fullscreenMode}.");
Harmony.CreateAndPatchAll(typeof(CustomResolutionPatch));
}
if (bUltrawideFixes.Value)
{
Harmony.CreateAndPatchAll(typeof(UltrawidePatch));
}
if (bIntroSkip.Value)
{
Harmony.CreateAndPatchAll(typeof(IntroSkipPatch));
}
SceneManager.sceneLoaded += (UnityAction<Scene, LoadSceneMode>)OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
// Set all cameras background color to black
foreach (var camera in Camera.allCameras)
{
camera.backgroundColor = Color.black;
}
}
[HarmonyPatch]
[HarmonyPriority(1)]
public class CustomResolutionPatch
{
// Apply custom resolution
[HarmonyPatch(typeof(UnityEngine.Screen), nameof(UnityEngine.Screen.SetResolution), new Type[] { typeof(int), typeof(int), typeof(bool), typeof(int) })]
[HarmonyPrefix]
public static bool CustomRes(UnityEngine.Screen __instance, ref int __0, ref int __1, ref bool __2, ref int __3)
{
Log.LogInfo($"Skipped: Set resolution {__0}x{__1}@{__3}hz. Fullscreen = {__2}.");
return false;
}
}
[HarmonyPatch]
[HarmonyPriority(2)]
public class UltrawidePatch
{
// Aspect Ratio
public static float DefaultAspectRatio = (float)16 / 9;
public static float NewAspectRatio = (float)Screen.width / (float)Screen.height;
public static float AspectMultiplier = NewAspectRatio / DefaultAspectRatio;
public static float NewHorFloat = 640 * AspectMultiplier;
public static int NewHor = (int)Mathf.CeilToInt(NewHorFloat);
// Update scaling on res change. Allows it to be dynamic.
[HarmonyPatch(typeof(Screen), nameof(UnityEngine.Screen.SetResolution), new Type[] { typeof(int), typeof(int), typeof(bool), typeof(int) })]
[HarmonyPatch(typeof(Screen), nameof(UnityEngine.Screen.SetResolution), new Type[] { typeof(int), typeof(int), typeof(FullScreenMode), typeof(int) })] // Custom Resolution
[HarmonyPostfix]
public static void UpdateScaling(ref int __0, ref int __1)
{
if (!bCustomResolution.Value)
{
NewAspectRatio = (float)__0 / (float)__1;
AspectMultiplier = NewAspectRatio / DefaultAspectRatio;
NewHorFloat = 640 * AspectMultiplier;
NewHor = (int)Mathf.CeilToInt(NewHorFloat);
Log.LogInfo($"Current res = {__0}x{__1}.");
}
if (NewAspectRatio > DefaultAspectRatio)
{
ScalingManager.scalingType = ScalingManager.ScalingType.distort;
List<Camera> cameras = new List<Camera>();
for (int i = 0; i < SceneManager.sceneCount; i++)
{
var s = SceneManager.GetSceneAt(i);
if (s.isLoaded)
{
var allGameObjects = s.GetRootGameObjects();
for (int j = 0; j < allGameObjects.Length; j++)
{
var go = allGameObjects[j];
cameras.AddRange(go.GetComponentsInChildren<Camera>(true));
}
}
}
foreach (Camera cam in cameras)
{
if (cam.targetTexture != null && cam.targetTexture.name == "MainScreen")
{
RenderTexture old = cam.targetTexture;
old.Release();
old.width = NewHor;
old.height = 360;
cam.ResetAspect();
cam.backgroundColor = Color.black;
Log.LogInfo($"Released and resized render texture for MainScreen ({NewHor}x360).");
}
}
var diagcam = GameObject.Find("Diag/Effects Camera").GetComponent<Camera>();
diagcam.aspect = NewAspectRatio;
diagcam.backgroundColor = Color.black;
Log.LogInfo($"Adjust Diag/Effects aspect ratio.");
}
}
// Release and resize Enemy FX Camera render texture
[HarmonyPatch(typeof(EnemyManager), nameof(EnemyManager.OnEnable))]
[HarmonyPostfix]
public static void EnemyFXFix()
{
if (NewAspectRatio > DefaultAspectRatio)
{
var enemyFX = GameObject.Find("Enemy FX Camera").GetComponent<Camera>();
if (enemyFX.targetTexture != null)
{
RenderTexture enemyrt = enemyFX.targetTexture;
enemyrt.Release();
enemyrt.width = NewHor;
enemyrt.height = 360;
enemyFX.ResetAspect();
Log.LogInfo($"Released and resized render texture for Enemy FX Camera.");
}
}
}
// Fix fotos
[HarmonyPatch(typeof(EideticModule), nameof(EideticModule.OnEnable))]
[HarmonyPostfix]
public static void EnemyFXFix(EideticModule __instance)
{
if (NewAspectRatio > DefaultAspectRatio)
{
var quad = __instance._camera.transform.GetChild(0);
var quadtrans = quad.GetComponent<Transform>();
if (quad && quadtrans.localScale.x == 64)
{
Vector3 quadscale = quad.localScale;
quadscale.x *= AspectMultiplier;
quadtrans.localScale = quadscale;
Log.LogInfo($"Rescaled foto camera quad.");
}
}
}
// Adjust size of input canvas during "Events"
[HarmonyPatch(typeof(EventScreen3DCam), nameof(EventScreen3DCam.OnEnable))]
[HarmonyPostfix]
public static void InputFix()
{
if (NewAspectRatio > DefaultAspectRatio)
{
var pivot = GameObject.Find("EventUICanvas/Pivot").GetComponent<RectTransform>();
if (pivot && pivot.gameObject.transform.localScale.x == (float)640)
{
Vector3 pivotscale = pivot.gameObject.transform.localScale;
pivotscale.x *= AspectMultiplier;
pivot.gameObject.transform.localScale = pivotscale;
Vector3 pivotpos = pivot.gameObject.transform.localPosition;
pivotpos.x *= AspectMultiplier;
pivot.gameObject.transform.localPosition = pivotpos;
Log.LogInfo($"Rescaled input transform.");
}
}
}
// Resize black bars in skippable cutscenes
[HarmonyPatch(typeof(SkippableCutscene), nameof(SkippableCutscene.Check))]
[HarmonyPostfix]
public static void CutsceneBlackBars(SkippableCutscene __instance)
{
if (NewAspectRatio > DefaultAspectRatio)
{
List<SpriteRenderer> spriterenderers = new List<SpriteRenderer>();
for (int i = 0; i < SceneManager.sceneCount; i++)
{
var s = SceneManager.GetSceneAt(i);
if (s.isLoaded)
{
var allGameObjects = s.GetRootGameObjects();
for (int j = 0; j < allGameObjects.Length; j++)
{
var go = allGameObjects[j];
spriterenderers.AddRange(go.GetComponentsInChildren<SpriteRenderer>(true));
}
}
}
foreach (SpriteRenderer spriterender in spriterenderers)
{
if (spriterender != null && spriterender.sprite != null && spriterender.sprite.name == "ultrawide_bars")
{
spriterender.gameObject.transform.localScale = new Vector3((float)1 * AspectMultiplier, (float)1, (float)1);
Log.LogInfo($"Resized ultrawide bars.");
}
}
}
}
// Resize black bars in cutscenes
[HarmonyPatch(typeof(BlackBars), nameof(BlackBars.On))]
[HarmonyPatch(typeof(BlackBars), nameof(BlackBars.FadeIn), new Type[] { } )]
[HarmonyPatch(typeof(BlackBars), nameof(BlackBars.FadeIn), new Type[] { typeof(float) })]
[HarmonyPatch(typeof(BlackBars), nameof(BlackBars.fadeIn), new Type[] { typeof(float) })]
[HarmonyPostfix]
public static void BlackBarsFix(BlackBars __instance)
{
if (NewAspectRatio > DefaultAspectRatio)
{
if (BlackBars.instance != null)
{
var topbar = BlackBars.instance.barTop.sizeDelta;
var botbar = BlackBars.instance.barBottom.sizeDelta;
if (topbar.x == 650 && botbar.x == 650)
{
topbar.x *= AspectMultiplier;
botbar.x *= (float)1 * AspectMultiplier;
BlackBars.instance.barTop.sizeDelta = topbar;
BlackBars.instance.barBottom.sizeDelta = botbar;
}
}
}
}
// Resize white fades/letterboxing
[HarmonyPatch(typeof(MainFader), nameof(MainFader.OnEnable))]
[HarmonyPostfix]
public static void FadesFix(MainFader __instance)
{
if (NewAspectRatio > DefaultAspectRatio)
{
List<Image> images = new List<Image>();
for (int i = 0; i < SceneManager.sceneCount; i++)
{
var s = SceneManager.GetSceneAt(i);
if (s.isLoaded)
{
var allGameObjects = s.GetRootGameObjects();
for (int j = 0; j < allGameObjects.Length; j++)
{
var go = allGameObjects[j];
images.AddRange(go.GetComponentsInChildren<Image>(true));
}
}
}
foreach (Image image in images)
{
if (image != null && image.sprite != null && image.sprite.name == "ultrawide_bars" || image != null && image.sprite != null && image.sprite.name == "WhitePixel")
{
image.gameObject.transform.localScale = new Vector3((float)1 * AspectMultiplier, (float)1, (float)1);
Log.LogInfo($"Resized ultrawide bars and or white overlay.");
}
}
}
}
}
[HarmonyPatch]
public class IntroSkipPatch
{
// Skip intro cards
[HarmonyPatch(typeof(OpeningCards), nameof(OpeningCards.Start))]
[HarmonyPostfix]
public static void IntroSkip(OpeningCards __instance)
{
__instance.Skip();
Log.LogInfo($"Skipped intro.");
}
}
}
}