mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 15:09:26 -07:00
41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using UnityEngine;
|
|
|
|
internal static class ToolCollisionLayerRestore
|
|
{
|
|
private static int _failures;
|
|
|
|
internal static void Restore(Tool tool)
|
|
{
|
|
if (tool == null) return;
|
|
try
|
|
{
|
|
if (tool.MEDCLKFANNC) return;
|
|
int layer = (int)tool.EHNBBIAIJIK;
|
|
if (layer < 0 || layer > 31)
|
|
throw new InvalidOperationException("Invalid default collision layer " + layer);
|
|
|
|
foreach (var collider in tool.GetComponentsInChildren<Collider>(true))
|
|
{
|
|
if (collider == null || collider.isTrigger) continue;
|
|
if (collider.GetComponentInParent<Tool>() != tool) continue;
|
|
var owner = collider.gameObject;
|
|
if (!ShouldRestore(owner.layer, (int)tool.HeldCollisionLayer,
|
|
(int)tool.EquippedCollisionLayer, (int)tool.AttachedCollisionLayer)) continue;
|
|
if (owner.layer == layer) continue;
|
|
owner.layer = layer;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (++_failures <= 5)
|
|
RadicadeEacBypassPlugin.LogSource.LogWarning("[ToolGuard] collision-layer restore failed: " + ex);
|
|
}
|
|
}
|
|
|
|
private static bool ShouldRestore(int layer, int held, int equipped, int attached)
|
|
{
|
|
return layer == held || layer == equipped || layer == attached
|
|
|| layer is 0 or 10 or 11 or 13 or 17 or 18 or 23 or 24 or 27;
|
|
}
|
|
}
|