diff --git a/Source/Patches/DunGenPatches.cs b/Source/Patches/DunGenPatches.cs new file mode 100644 index 0000000..15b7499 --- /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 da8fa5c..ad10975 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; } }