From 92f6f8c37c6f52e8c6ba9ab51ed763ec4b5eca12 Mon Sep 17 00:00:00 2001 From: DaXcess Date: Sat, 28 Sep 2024 21:57:02 +0200 Subject: [PATCH] Fix leaving hang, fix vanilla DunGen issue --- Source/Patches/DunGenPatches.cs | 30 +++++++++++++++++++++ Source/Patches/GameNetworkManagerPatches.cs | 3 ++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 Source/Patches/DunGenPatches.cs diff --git a/Source/Patches/DunGenPatches.cs b/Source/Patches/DunGenPatches.cs new file mode 100644 index 00000000..15b7499e --- /dev/null +++ b/Source/Patches/DunGenPatches.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using System.Reflection.Emit; +using DunGen; +using HarmonyLib; +using UnityEngine; +using static HarmonyLib.AccessTools; + +namespace LCVR.Patches; + +/// +/// This is a patch that fixes a problem in DunGen that should actually be done in a separate mod. +/// +/// But it is affected debug builds in the VR mod and I am too lazy to make another separate mod to fix it. +/// +[LCVRPatch(LCVRPatchTarget.Universal)] +[HarmonyPatch] +internal static class DunGenPatches +{ + [HarmonyPatch(typeof(DungeonGenerator), nameof(DungeonGenerator.InnerGenerate), MethodType.Enumerator)] + [HarmonyTranspiler] + [HarmonyDebug] + private static IEnumerable DunGenAllowInfiniteRetries(IEnumerable instructions) + { + return new CodeMatcher(instructions) + .MatchForward(false, + new CodeMatch(OpCodes.Call, PropertyGetter(typeof(Application), nameof(Application.isEditor)))) + .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Ldc_I4_0)) + .InstructionEnumeration(); + } +} diff --git a/Source/Patches/GameNetworkManagerPatches.cs b/Source/Patches/GameNetworkManagerPatches.cs index da8fa5cd..ad10975e 100644 --- a/Source/Patches/GameNetworkManagerPatches.cs +++ b/Source/Patches/GameNetworkManagerPatches.cs @@ -27,6 +27,7 @@ private static void OnLeaveGame() return; foreach (var player in NetworkSystem.Instance.Players) - player.GetComponent().enabled = false; + if (player.TryGetComponent(out var rb)) + rb.enabled = false; } }