using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using FistVR;
using Microsoft.CodeAnalysis;
using On.FistVR;
using OpenScripts2;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("HighlightCompatibleHiddenRails")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HighlightCompatibleHiddenRails")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a2628c8a-f5ff-42fa-820f-00f93b9ffb55")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace Cityrobo
{
public class RailHighlightController : MonoBehaviour
{
private GameObject _alternativeBoxMesh;
private MultipleHideOnAttach _multipleHideOnAttach;
private FVRFireArmAttachmentMount _mount;
private FVRViveHand[] _hands;
private bool _highlightEnabled;
private readonly Dictionary<MeshRenderer, Material[]> _originalMeshRendererMaterials = new Dictionary<MeshRenderer, Material[]>();
private bool _isHovered;
private static readonly Dictionary<FVRFireArmAttachmentMount, RailHighlightController> _existingHighlightControllers;
private Material HighlightMaterial => HighlightHiddenRails_BepInEx._highlightMaterial;
public void Awake()
{
_multipleHideOnAttach = ((Component)this).GetComponent<MultipleHideOnAttach>();
if ((Object)(object)_multipleHideOnAttach != (Object)null)
{
_mount = _multipleHideOnAttach.attachmentMount;
}
else
{
_mount = ((Component)this).GetComponent<FVRFireArmAttachmentMount>();
}
if (HighlightHiddenRails_BepInEx.HighlightMountsWithoutAHiddenMesh.Value && !_mount.HasHoverEnablePiece)
{
CreateProxyMesh();
}
_hands = GM.CurrentMovementManager.Hands;
MeshRenderer[] array = (MeshRenderer[])(((Object)(object)_multipleHideOnAttach != (Object)null) ? _multipleHideOnAttach.ObjectToHideOrShow.SelectMany((GameObject o) => o.GetComponentsInChildren<MeshRenderer>(true)).ToArray() : ((!_mount.HasHoverEnablePiece) ? ((Array)new MeshRenderer[1] { _alternativeBoxMesh.GetComponent<MeshRenderer>() }) : ((Array)_mount.EnableOnHover.GetComponentsInChildren<MeshRenderer>(true))));
MeshRenderer[] array2 = array;
foreach (MeshRenderer val in array2)
{
_originalMeshRendererMaterials.Add(val, ((Renderer)val).sharedMaterials);
}
_existingHighlightControllers.Add(_mount, this);
}
public void OnDestroy()
{
_existingHighlightControllers.Remove(_mount);
}
public void Update()
{
bool flag;
try
{
flag = !HighlightHiddenRails_BepInEx.OnlyHighlightOnHeldObject.Value || (HighlightHiddenRails_BepInEx.OnlyHighlightOnHeldObject.Value && ((FVRInteractiveObject)_mount.GetRootMount().MyObject).IsHeld);
}
catch (Exception)
{
FVRPhysicalObject componentInParent = ((Component)_mount).GetComponentInParent<FVRPhysicalObject>();
flag = !HighlightHiddenRails_BepInEx.OnlyHighlightOnHeldObject.Value || (HighlightHiddenRails_BepInEx.OnlyHighlightOnHeldObject.Value && (Object)(object)componentInParent != (Object)null && ((FVRInteractiveObject)componentInParent).IsHeld);
}
if (flag && !_isHovered)
{
if (!_highlightEnabled && !_mount.HasAttachmentsOnIt() && _hands.Any(delegate(FVRViveHand h)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)h.CurrentInteractable != (Object)null)
{
FVRInteractiveObject currentInteractable2 = h.CurrentInteractable;
FVRFireArmAttachment val2 = (FVRFireArmAttachment)(object)((currentInteractable2 is FVRFireArmAttachment) ? currentInteractable2 : null);
if (val2 != null)
{
return val2.Type == _mount.Type;
}
}
return false;
}))
{
EnableHighlighting();
}
else if (_highlightEnabled && !_mount.HasAttachmentsOnIt() && _hands.All(delegate(FVRViveHand h)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
if (h.CurrentInteractable is FVRFireArmAttachment)
{
FVRInteractiveObject currentInteractable = h.CurrentInteractable;
FVRFireArmAttachment val = (FVRFireArmAttachment)(object)((currentInteractable is FVRFireArmAttachment) ? currentInteractable : null);
if (val != null)
{
return val.Type != _mount.Type;
}
return false;
}
return true;
}))
{
DisableHighlighting(disableVis: true);
}
else if (_highlightEnabled && _mount.HasAttachmentsOnIt())
{
DisableHighlighting(disableVis: false);
}
}
else if (!flag)
{
if (_highlightEnabled && !_mount.HasAttachmentsOnIt())
{
DisableHighlighting(disableVis: true);
}
else if (_highlightEnabled && _mount.HasAttachmentsOnIt())
{
DisableHighlighting(disableVis: false);
}
}
}
private void EnableHighlighting()
{
_highlightEnabled = true;
foreach (MeshRenderer key in _originalMeshRendererMaterials.Keys)
{
Material[] array = (Material[])(object)new Material[((Renderer)key).sharedMaterials.Length];
for (int i = 0; i < array.Length; i++)
{
array[i] = HighlightMaterial;
}
((Renderer)key).sharedMaterials = array;
}
if ((Object)(object)_multipleHideOnAttach != (Object)null)
{
_multipleHideOnAttach.ManualOverride = true;
return;
}
if (_mount.HasHoverEnablePiece)
{
_mount.EnableOnHover.SetActive(true);
return;
}
GameObject alternativeBoxMesh = _alternativeBoxMesh;
if (alternativeBoxMesh != null)
{
alternativeBoxMesh.SetActive(true);
}
}
private void DisableHighlighting(bool disableVis)
{
_highlightEnabled = false;
if (disableVis)
{
if ((Object)(object)_multipleHideOnAttach != (Object)null)
{
_multipleHideOnAttach.ManualOverride = false;
}
else if (_mount.HasHoverEnablePiece)
{
_mount.EnableOnHover.SetActive(false);
}
}
GameObject alternativeBoxMesh = _alternativeBoxMesh;
if (alternativeBoxMesh != null)
{
alternativeBoxMesh.SetActive(false);
}
foreach (KeyValuePair<MeshRenderer, Material[]> originalMeshRendererMaterial in _originalMeshRendererMaterials)
{
((Renderer)originalMeshRendererMaterial.Key).sharedMaterials = originalMeshRendererMaterial.Value;
}
}
private void CreateProxyMesh()
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
Collider component = ((Component)_mount).GetComponent<Collider>();
if ((Object)(object)component != (Object)null)
{
_alternativeBoxMesh = GameObject.CreatePrimitive((PrimitiveType)3);
_alternativeBoxMesh.transform.parent = ((Component)_mount).transform;
_alternativeBoxMesh.transform.position = ((Component)_mount).transform.position;
_alternativeBoxMesh.transform.rotation = ((Component)_mount).transform.rotation;
_alternativeBoxMesh.transform.localScale = GetColliderSize(component);
_alternativeBoxMesh.transform.localPosition = GetColliderCenter(component);
Collider component2 = _alternativeBoxMesh.GetComponent<Collider>();
if ((Object)(object)component2 != (Object)null)
{
Object.Destroy((Object)(object)component2);
}
_alternativeBoxMesh.SetActive(false);
}
else
{
Object.Destroy((Object)(object)this);
}
}
private Vector3 GetColliderSize(Collider collider)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
BoxCollider val = (BoxCollider)(object)((collider is BoxCollider) ? collider : null);
if (val != null)
{
return val.size;
}
SphereCollider val2 = (SphereCollider)(object)((collider is SphereCollider) ? collider : null);
if (val2 != null)
{
float num = val2.radius * 2f;
return new Vector3(num, num, num);
}
CapsuleCollider val3 = (CapsuleCollider)(object)((collider is CapsuleCollider) ? collider : null);
if (val3 != null)
{
float num2 = val3.radius * 2f;
float height = val3.height;
return (Vector3)(val3.direction switch
{
0 => new Vector3(height, num2, num2),
1 => new Vector3(num2, height, num2),
2 => new Vector3(num2, num2, height),
_ => default(Vector3),
});
}
Bounds bounds = collider.bounds;
return ((Bounds)(ref bounds)).size;
}
private Vector3 GetColliderCenter(Collider collider)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
BoxCollider val = (BoxCollider)(object)((collider is BoxCollider) ? collider : null);
if (val == null)
{
SphereCollider val2 = (SphereCollider)(object)((collider is SphereCollider) ? collider : null);
if (val2 == null)
{
CapsuleCollider val3 = (CapsuleCollider)(object)((collider is CapsuleCollider) ? collider : null);
if (val3 != null)
{
return val3.center;
}
Bounds bounds = collider.bounds;
return ((Bounds)(ref bounds)).center;
}
return val2.center;
}
return val.center;
}
static RailHighlightController()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
_existingHighlightControllers = new Dictionary<FVRFireArmAttachmentMount, RailHighlightController>();
FVRFireArmAttachmentMount.BeginHover += new hook_BeginHover(FVRFireArmAttachmentMount_BeginHover);
FVRFireArmAttachmentMount.EndHover += new hook_EndHover(FVRFireArmAttachmentMount_EndHover);
}
private static void FVRFireArmAttachmentMount_BeginHover(orig_BeginHover orig, FVRFireArmAttachmentMount self)
{
orig.Invoke(self);
if (_existingHighlightControllers.TryGetValue(self, out var value))
{
value.DisableHighlighting(disableVis: false);
value._isHovered = true;
}
}
private static void FVRFireArmAttachmentMount_EndHover(orig_EndHover orig, FVRFireArmAttachmentMount self)
{
orig.Invoke(self);
if (_existingHighlightControllers.TryGetValue(self, out var value))
{
value.EnableHighlighting();
value._isHovered = false;
}
}
}
[BepInPlugin("h3vr.cityrobo.HighlightHiddenRails", "Highlight Hidden Rails", "1.0.2")]
public class HighlightHiddenRails_BepInEx : BaseUnityPlugin
{
public static Material _highlightMaterial;
public static ConfigEntry<bool> HighlightMountsWithoutAHiddenMesh;
public static ConfigEntry<bool> OnlyHighlightOnHeldObject;
public void Awake()
{
HighlightMountsWithoutAHiddenMesh = ((BaseUnityPlugin)this).Config.Bind<bool>("Highlight Hidden Rails", "Highlight mounts without a hidden mesh", true, "If a mount doesn't have a hidden mesh, still highlight it to potentially show places you didn't knwo you could mount it too. Useful for guns created before showing parts was added.");
OnlyHighlightOnHeldObject = ((BaseUnityPlugin)this).Config.Bind<bool>("Highlight Hidden Rails", "Only highlight on held object", true, "Only highlight the mounts on the currently held item.");
}
public void Update()
{
if ((Object)(object)_highlightMaterial == (Object)null && (Object)(object)ManagerSingleton<GM>.Instance != (Object)null && ManagerSingleton<GM>.Instance.QuickbeltConfigurations != null && ManagerSingleton<GM>.Instance.QuickbeltConfigurations.Length != 0)
{
_highlightMaterial = ((Renderer)ManagerSingleton<GM>.Instance.QuickbeltConfigurations[0].GetComponentInChildren<FVRQuickBeltSlot>().HoverGeo.GetComponent<MeshRenderer>()).material;
}
}
static HighlightHiddenRails_BepInEx()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
FVRPhysicalObject.Awake += new hook_Awake(FVRPhysicalObject_Awake);
}
private static void FVRPhysicalObject_Awake(orig_Awake orig, FVRPhysicalObject self)
{
orig.Invoke(self);
((MonoBehaviour)self).StartCoroutine(WaitForStart(self));
}
private static IEnumerator WaitForStart(FVRPhysicalObject self)
{
yield return null;
FVRFireArmAttachmentMount[] array = self.AttachmentMounts.Where((FVRFireArmAttachmentMount m) => (Object)(object)m != (Object)null && m.HasHoverEnablePiece && (Object)(object)m.EnableOnHover != (Object)null).ToArray();
for (int i = 0; i < array.Length; i++)
{
((Component)array[i]).gameObject.AddComponent<RailHighlightController>();
}
MultipleHideOnAttach[] array2 = (from m in ((Component)self).GetComponentsInChildren<MultipleHideOnAttach>(true)
where m.ShowOnAttach
select m).ToArray();
for (int i = 0; i < array2.Length; i++)
{
((Component)array2[i]).gameObject.AddComponent<RailHighlightController>();
}
if (!HighlightMountsWithoutAHiddenMesh.Value)
{
yield break;
}
array = self.AttachmentMounts.Where((FVRFireArmAttachmentMount m) => (Object)(object)m != (Object)null && !m.HasHoverEnablePiece).ToArray();
foreach (FVRFireArmAttachmentMount val in array)
{
if ((Object)(object)((Component)val).GetComponent<RailHighlightController>() == (Object)null)
{
((Component)val).gameObject.AddComponent<RailHighlightController>();
}
}
}
}
}