-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsDuskFallsFix.cs
242 lines (209 loc) · 9.81 KB
/
AsDuskFallsFix.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
using BepInEx;
using BepInEx.Configuration;
using BepInEx.IL2CPP;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;
using InteriorNight.MenuSystem;
using InteriorNight;
namespace AsDuskFallsFix
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class ADF : BasePlugin
{
internal static new ManualLogSource Log;
public static ConfigEntry<bool> bUltrawideFixes;
public static ConfigEntry<bool> bCustomResolution;
public static ConfigEntry<float> fDesiredResolutionX;
public static ConfigEntry<float> fDesiredResolutionY;
public static ConfigEntry<bool> bIntroSkip;
public static ConfigEntry<bool> bUncapFPS;
public static ConfigEntry<int> iAnisotropicFiltering;
public static ConfigEntry<int> iAntialiasing;
public override void Load()
{
// Plugin startup logic
Log = base.Log;
Log.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
// Features
bUltrawideFixes = Config.Bind("Ultrawide UI Fixes",
"UltrawideFixes",
true,
"Set to true to enable ultrawide UI fixes.");
bIntroSkip = Config.Bind("Intro Skip",
"IntroSkip",
true,
"Skip intro logos.");
bUncapFPS = Config.Bind("Uncap Framerate",
"UncapFPS",
true,
"Set to true to remove 30 FPS cap and enable vsync.");
// Custom Resolution
bCustomResolution = Config.Bind("Set Custom Resolution",
"CustomResolution",
true,
"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.");
// Graphical Settings
iAnisotropicFiltering = Config.Bind("Graphical Tweaks",
"AnisotropicFiltering.Value",
(int)16, // Default = unknown?
new ConfigDescription("Set Anisotropic Filtering level. 16 is recommended for quality.",
new AcceptableValueRange<int>(1, 16)));
iAntialiasing = Config.Bind("Graphical Tweaks",
"Antialiasing.Value",
(int)2, // Default = 2
new ConfigDescription("Set MSAA Antialiasing level. 8 is recommended for quality.",
new AcceptableValueList<int>(0,2,4,8)));
// Run CustomResolutionPatch
if (bCustomResolution.Value)
{
Harmony.CreateAndPatchAll(typeof(CustomResolutionPatch));
}
// Run UltrawidePatch
if (bUltrawideFixes.Value)
{
Harmony.CreateAndPatchAll(typeof(UltrawidePatch));
}
// Run IntroSkipPatch
if (bIntroSkip.Value)
{
Harmony.CreateAndPatchAll(typeof(IntroSkipPatch));
}
Harmony.CreateAndPatchAll(typeof(SettingsPatch));
}
[HarmonyPatch]
public class CustomResolutionPatch
{
// Add custom resolution
[HarmonyPatch(typeof(GraphicsSettingsController), nameof(GraphicsSettingsController.GetBestAlternativeResolution))]
[HarmonyPrefix]
public static bool CustomResList(GraphicsSettingsController __instance, int __result, ref Il2CppSystem.Collections.Generic.List<INResolution> __0)
{
INResolution customResolution = new INResolution
{
width = (int)fDesiredResolutionX.Value,
height = (int)fDesiredResolutionY.Value,
refreshRate = 0 // 0 = use highest available
};
__0.Add(customResolution);
Log.LogInfo($"Custom resolution {fDesiredResolutionX}x{fDesiredResolutionY} added.");
return true;
}
// Update target aspect ratio
[HarmonyPatch(typeof(CameraAspectRatioFitter), nameof(CameraAspectRatioFitter.Awake))]
[HarmonyPrefix]
public static bool StopAspect(CameraAspectRatioFitter __instance)
{
__instance.wantedAspectRatio = (float)fDesiredResolutionX.Value / fDesiredResolutionY.Value;
Log.LogInfo($"AspectRatioFitter wantedAspectRatio set to {__instance.wantedAspectRatio}.");
return true;
}
// Cursor Clamp
// This is so janky lmao
[HarmonyPatch(typeof(LocalClient), nameof(LocalClient.ClampCursorPos))]
[HarmonyPrefix]
public static bool Prefix(LocalClient __instance)
{
GlobalSettings.TARGET_ASPECT_RATIO = (float)Screen.width / Screen.height;
//Log.LogInfo($"Cursor clamp adjusted.");
return true;
}
[HarmonyPatch(typeof(LocalClient), nameof(LocalClient.ClampCursorPos))]
[HarmonyPostfix]
public static void Postfix(LocalClient __instance)
{
GlobalSettings.TARGET_ASPECT_RATIO = (float)16/9;
}
}
[HarmonyPatch]
public class SettingsPatch
{
// Override game settings
[HarmonyPatch(typeof(QualityManager), nameof(QualityManager.SetResolutionAndDisplayMode))]
[HarmonyPostfix]
public static void SettingsChange()
{
if (bUncapFPS.Value)
{
QualitySettings.vSyncCount = 1;
Application.targetFrameRate = 500;
Log.LogInfo($"Vsync set to {QualitySettings.vSyncCount}. targetFrameRate set to {Application.targetFrameRate}.");
}
if (iAntialiasing.Value > 0)
{
QualitySettings.antiAliasing = iAntialiasing.Value;
Log.LogInfo($"Antialiasing set to {iAntialiasing.Value}.");
}
if (iAnisotropicFiltering.Value > 0)
{
QualitySettings.anisotropicFiltering = AnisotropicFiltering.ForceEnable;
Texture.SetGlobalAnisotropicFilteringLimits(iAnisotropicFiltering.Value, iAnisotropicFiltering.Value);
Log.LogInfo($"Anisotropic filtering force enabled. Value = {iAnisotropicFiltering.Value}.");
}
}
}
[HarmonyPatch]
public class UltrawidePatch
{
public static float DefaultAspectRatio = (float)16 / 9;
public static float NewAspectRatio = (float)fDesiredResolutionX.Value / fDesiredResolutionY.Value;
public static float AspectMultiplier = NewAspectRatio / DefaultAspectRatio;
public static float AspectDivider = DefaultAspectRatio / NewAspectRatio;
// Set screen match mode when object has canvasscaler enabled
[HarmonyPatch(typeof(CanvasScaler), nameof(CanvasScaler.OnEnable))]
[HarmonyPostfix]
public static void SetScreenMatchMode(CanvasScaler __instance)
{
if (NewAspectRatio > DefaultAspectRatio)
{
__instance.m_ScreenMatchMode = CanvasScaler.ScreenMatchMode.Expand;
}
}
// Center main menu
[HarmonyPatch(typeof(MainMenu), nameof(MainMenu.OnEnable))]
[HarmonyPostfix]
public static void FixMainMenu(MainMenu __instance)
{
if (NewAspectRatio > DefaultAspectRatio)
{
GameObject MainMenu = GameObject.Find("Managers/MenuManager/MenuRoot");
var oldxPos = MainMenu.transform.position.x;
var newxPos = -(float)16/9;
Vector3 newPos = MainMenu.transform.position;
newPos.x = newxPos;
MainMenu.transform.position = newPos;
Log.LogInfo($"Centered main menu.");
}
}
}
[HarmonyPatch]
public class IntroSkipPatch
{
// Skip splashscreens
[HarmonyPatch(typeof(SplashScreenManager), nameof(SplashScreenManager.Start))]
[HarmonyPostfix]
public static void SkipSplash(SplashScreenManager __instance)
{
SplashScreenManager.s_splashScreensDone = true;
Log.LogInfo($"Splashscreens skipped.");
}
// Skip splash video
[HarmonyPatch(typeof(SplashScreenManager.SplashScreen), nameof(SplashScreenManager.SplashScreen.SetupVideo))]
[HarmonyPrefix]
public static bool SkipSplashVideo(SplashScreenManager.SplashScreen __instance)
{
Log.LogInfo($"Startup video skipped.");
return false;
}
}
}
}