Skip to content

Commit

Permalink
Replaced DunGen patch
Browse files Browse the repository at this point in the history
- Removed the DunGen bandaid fix
- Replaced the debug menu patch with patching the game code instead of patching Unity code, which trips up DunGen with modded moons
  • Loading branch information
DaXcess committed Sep 29, 2024
1 parent b202382 commit 9997505
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 39 deletions.
96 changes: 87 additions & 9 deletions Source/Experiments/Experiments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
using LCVR.Patches;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using LCVR.Assets;
using Unity.Netcode;
using UnityEngine;
using static HarmonyLib.AccessTools;

namespace LCVR.Experiments;

Expand Down Expand Up @@ -131,18 +133,94 @@ private static LineRenderer CreateRenderer()
#if DEBUG
[LCVRPatch(LCVRPatchTarget.Universal)]
[HarmonyPatch]
internal static class ExperimentalPatches
internal static class ExperimentalPatches;

/// <summary>
/// All the patches in this class will enable the debug menu in Lethal Company
/// </summary>
[LCVRPatch(LCVRPatchTarget.Universal)]
[HarmonyPatch]
internal static class DebugMenuPatches
{
/// <summary>
/// Enables the game's built in debug mode
/// </summary>
[HarmonyPatch(typeof(Application), nameof(Application.isEditor), MethodType.Getter)]
[HarmonyPrefix]
private static bool DeveloperMode(ref bool __result)
private static IEnumerable<CodeInstruction> PatchIsEditor(IEnumerable<CodeInstruction> instructions)
{
__result = true;
return new CodeMatcher(instructions)
.MatchForward(false,
new CodeMatch(OpCodes.Call, PropertyGetter(typeof(Application), nameof(Application.isEditor))))
.SetOpcodeAndAdvance(OpCodes.Ldc_I4_1)
.InstructionEnumeration();
}

return false;
[HarmonyPatch(typeof(QuickMenuManager), nameof(QuickMenuManager.CanEnableDebugMenu))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> CanEnableDebugMenu(IEnumerable<CodeInstruction> instructions)
{
return PatchIsEditor(instructions);
}

[HarmonyPatch(typeof(QuickMenuManager), nameof(QuickMenuManager.Debug_KillLocalPlayer))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Debug_KillLocalPlayer(IEnumerable<CodeInstruction> instructions)
{
return PatchIsEditor(instructions);
}

[HarmonyPatch(typeof(QuickMenuManager), nameof(QuickMenuManager.Debug_SpawnEnemy))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Debug_SpawnEnemy(IEnumerable<CodeInstruction> instructions)
{
return PatchIsEditor(instructions);
}

[HarmonyPatch(typeof(QuickMenuManager), nameof(QuickMenuManager.Debug_SpawnItem))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Debug_SpawnItem(IEnumerable<CodeInstruction> instructions)
{
return PatchIsEditor(instructions);
}

[HarmonyPatch(typeof(QuickMenuManager), nameof(QuickMenuManager.Debug_SpawnTruck))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Debug_SpawnTruck(IEnumerable<CodeInstruction> instructions)
{
return PatchIsEditor(instructions);
}

[HarmonyPatch(typeof(QuickMenuManager), nameof(QuickMenuManager.Debug_ToggleAllowDeath))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Debug_ToggleAllowDeath(IEnumerable<CodeInstruction> instructions)
{
return PatchIsEditor(instructions);
}

[HarmonyPatch(typeof(QuickMenuManager), nameof(QuickMenuManager.Debug_ToggleTestRoom))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Debug_ToggleTestRoom(IEnumerable<CodeInstruction> instructions)
{
return PatchIsEditor(instructions);
}

[HarmonyPatch(typeof(StartOfRound), nameof(StartOfRound.Debug_EnableTestRoomServerRpc))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Debug_EnableTestRoomServerRpc(IEnumerable<CodeInstruction> instructions)
{
return PatchIsEditor(instructions);
}

[HarmonyPatch(typeof(StartOfRound), nameof(StartOfRound.Debug_ReviveAllPlayersServerRpc))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Debug_ReviveAllPlayersServerRpc(
IEnumerable<CodeInstruction> instructions)
{
return PatchIsEditor(instructions);
}

[HarmonyPatch(typeof(StartOfRound), nameof(StartOfRound.Debug_ToggleAllowDeathServerRpc))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Debug_ToggleAllowDeathServerRpc(
IEnumerable<CodeInstruction> instructions)
{
return PatchIsEditor(instructions);
}
}
#endif
Expand Down
30 changes: 0 additions & 30 deletions Source/Patches/DunGenPatches.cs

This file was deleted.

0 comments on commit 9997505

Please sign in to comment.