Skip to content

Commit dcdbbd1

Browse files
committed
Interactable Toy NRE fix
1 parent 26736c7 commit dcdbbd1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using AdminToys;
2+
3+
using HarmonyLib;
4+
5+
namespace LabExtended.Patches.Fixes
6+
{
7+
/// <summary>
8+
/// Fixes a null reference exception caused by interactable toys being destroyed while being interacted with.
9+
/// </summary>
10+
public static class InteractableToySearchNreFix
11+
{
12+
[HarmonyPatch(typeof(InvisibleInteractableToy.InteractableToySearchCompletor), nameof(InvisibleInteractableToy.InteractableToySearchCompletor.ValidateDistance))]
13+
private static bool Prefix(InvisibleInteractableToy.InteractableToySearchCompletor __instance, ref bool __result)
14+
{
15+
__result = false;
16+
17+
if (__instance == null)
18+
return false;
19+
20+
if (__instance.Hub == null)
21+
return false;
22+
23+
if (__instance._target == null || __instance._target.gameObject == null)
24+
return false;
25+
26+
__result = (__instance._target.transform.position - __instance.Hub.transform.position).sqrMagnitude <= __instance._maxDistanceSqr;
27+
return false;
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)