Skip to content

Commit

Permalink
Fix CullFactory timing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
DaXcess committed Sep 24, 2024
1 parent 6f11c6c commit 30b5e98
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

**Bug fixes**:
- Fixed player head rotation being applied in the wrong order
- Fixed CullFactory breaking item rendering when traversing an entrance

# 1.3.3

Expand Down
35 changes: 35 additions & 0 deletions Source/Compatibility/CullFactory/Patches.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection.Emit;
using CullFactory.Data;
using CullFactory.Extenders;
using GameNetcodeStuff;
using HarmonyLib;
using LCVR.Patches;
using LCVR.Player;
using UnityEngine;
using static HarmonyLib.AccessTools;

namespace LCVR.Compatibility.CullFactory;

Expand All @@ -26,4 +33,32 @@ private static void OnCollectAllPlayerLights()

DynamicObjects.allPlayerLights[clientId] = [..lights, ..cameraLights];
}

/// <summary>
/// Rather interesting patch that delays the player teleport code in CullFactory by a single frame
///
/// Fixes items turning invisible due to CullFactory thinking they're inside/outside the factory whilst we are not
/// </summary>
[HarmonyPatch(typeof(TeleportExtender), nameof(TeleportExtender.OnPlayerTeleported))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> DelayPlayerTeleport(IEnumerable<CodeInstruction> instructions)
{
return new CodeMatcher(instructions)
.MatchForward(false, new CodeMatch(OpCodes.Call,
Method(typeof(DynamicObjects), nameof(DynamicObjects.OnPlayerTeleported))))
.SetOperandAndAdvance(((Action<PlayerControllerB>)OnPlayerTeleport).Method)
.InstructionEnumeration();

static void OnPlayerTeleport(PlayerControllerB player)
{
StartOfRound.Instance.StartCoroutine(OnPlayerTeleportedCoroutine(player));
}

static IEnumerator OnPlayerTeleportedCoroutine(PlayerControllerB player)
{
yield return null;

DynamicObjects.OnPlayerTeleported(player);
}
}
}

0 comments on commit 30b5e98

Please sign in to comment.