Skip to content

Commit

Permalink
Fix leaving hang, fix vanilla DunGen issue
Browse files Browse the repository at this point in the history
  • Loading branch information
DaXcess committed Sep 28, 2024
1 parent ef2f83e commit 38fec3b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
30 changes: 30 additions & 0 deletions Source/Patches/DunGenPatches.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// 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.
/// </summary>
[LCVRPatch(LCVRPatchTarget.Universal)]
[HarmonyPatch]
internal static class DunGenPatches
{
[HarmonyPatch(typeof(DungeonGenerator), nameof(DungeonGenerator.InnerGenerate), MethodType.Enumerator)]
[HarmonyTranspiler]
[HarmonyDebug]
private static IEnumerable<CodeInstruction> DunGenAllowInfiniteRetries(IEnumerable<CodeInstruction> 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();
}
}
3 changes: 2 additions & 1 deletion Source/Patches/GameNetworkManagerPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ private static void OnLeaveGame()
return;

foreach (var player in NetworkSystem.Instance.Players)
player.GetComponent<RigBuilder>().enabled = false;
if (player.TryGetComponent<RigBuilder>(out var rb))
rb.enabled = false;
}
}

0 comments on commit 38fec3b

Please sign in to comment.