1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-08 19:33:27 +08:00
This commit is contained in:
2025-10-20 22:45:29 +08:00
parent a183485286
commit e9bbcf5e2c

View File

@@ -220,7 +220,7 @@ public class GamePatch : PatchImpl<GamePatch>
} }
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(Screen), nameof(Screen.SetResolution), typeof(int), typeof(int), typeof(FullScreenMode), typeof(int))] [HarmonyPatch(typeof(Screen), nameof(Screen.SetResolution), typeof(int), typeof(int), typeof(FullScreenMode), typeof(RefreshRate))]
private static void Screen_SetResolution_Prefix(ref int width, ref int height, FullScreenMode fullscreenMode, ref Vector2Int __state) private static void Screen_SetResolution_Prefix(ref int width, ref int height, FullScreenMode fullscreenMode, ref Vector2Int __state)
{ {
if (fullscreenMode is FullScreenMode.ExclusiveFullScreen or FullScreenMode.FullScreenWindow or FullScreenMode.MaximizedWindow) return; if (fullscreenMode is FullScreenMode.ExclusiveFullScreen or FullScreenMode.FullScreenWindow or FullScreenMode.MaximizedWindow) return;
@@ -247,7 +247,7 @@ public class GamePatch : PatchImpl<GamePatch>
} }
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(Screen), nameof(Screen.SetResolution), typeof(int), typeof(int), typeof(FullScreenMode), typeof(int))] [HarmonyPatch(typeof(Screen), nameof(Screen.SetResolution), typeof(int), typeof(int), typeof(FullScreenMode), typeof(RefreshRate))]
private static void Screen_SetResolution_Postfix(FullScreenMode fullscreenMode, Vector2Int __state) private static void Screen_SetResolution_Postfix(FullScreenMode fullscreenMode, Vector2Int __state)
{ {
if (fullscreenMode is FullScreenMode.ExclusiveFullScreen or FullScreenMode.FullScreenWindow or FullScreenMode.MaximizedWindow) return; if (fullscreenMode is FullScreenMode.ExclusiveFullScreen or FullScreenMode.FullScreenWindow or FullScreenMode.MaximizedWindow) return;
@@ -271,36 +271,6 @@ public class GamePatch : PatchImpl<GamePatch>
ThreadingHelper.Instance.StartCoroutine(SetWindowPositionCoroutine(wnd, x, y)); ThreadingHelper.Instance.StartCoroutine(SetWindowPositionCoroutine(wnd, x, y));
} }
private static GameOption _gameOption;
[HarmonyPostfix]
[HarmonyPatch(typeof(UIOptionWindow), nameof(UIOptionWindow._OnOpen))]
private static void UIOptionWindow__OnOpen_Postfix()
{
_gameOption = DSPGame.globalOption;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(GameOption), nameof(GameOption.Apply))]
private static IEnumerable<CodeInstruction> UIOptionWindow_ApplyOptions_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
var matcher = new CodeMatcher(instructions, generator);
var label1 = generator.DefineLabel();
matcher.MatchForward(false,
new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(Screen), nameof(Screen.SetResolution), [typeof(int), typeof(int), typeof(FullScreenMode), typeof(RefreshRate)]))
).Advance(1).Labels.Add(label1);
matcher.Start().Insert(
Transpilers.EmitDelegate(() =>
_gameOption.displayMode != EOptionDisplayMode.Windowed &&
_gameOption.resolution.width == DSPGame.globalOption.resolution.width &&
_gameOption.resolution.height == DSPGame.globalOption.resolution.height &&
_gameOption.resolution.refreshRateRatio.Equals(DSPGame.globalOption.resolution.refreshRateRatio)
),
new CodeInstruction(OpCodes.Brtrue, label1)
);
return matcher.InstructionEnumeration();
}
private class EnableWindowResize : PatchImpl<EnableWindowResize> private class EnableWindowResize : PatchImpl<EnableWindowResize>
{ {
private static bool _enabled; private static bool _enabled;