using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using OtherLoader;
using UnityEngine;
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace DumpPouch
{
public class Pouch : FVRPhysicalObject
{
[Header("Dump Pouch")]
[Tooltip("The delete zone's centre, in the pouch's space")]
public Vector3 ZoneCenter = new Vector3(0f, 0.11f, 0f);
[Tooltip("The delete zone's half size, in the pouch's space")]
public Vector3 ZoneHalfExtents = new Vector3(0.055f, 0.09f, 0.036f);
[Tooltip("While in a quickbelt slot, hang upright with the back panel to the body instead of taking the slot's tilt")]
public bool HangUpright = true;
[Tooltip("Shortest gap between two drop sounds (s)")]
public float SoundCooldown = 0.08f;
[Tooltip("A new pouch waits this long before deleting anything, so spawning it onto a pad that already holds items doesn't eat them (s)")]
public float ArmDelay = 0.75f;
private static readonly Collider[] s_hits = (Collider[])(object)new Collider[64];
private static readonly List<FVRPhysicalObject> s_found = new List<FVRPhysicalObject>();
private static readonly HashSet<int> s_dumpedThisFrame = new HashSet<int>();
private static int s_dumpedFrame = -1;
private int m_mask = -1;
private float m_nextSound;
private float m_armedAt;
public override void Awake()
{
((FVRPhysicalObject)this).Awake();
int num = LayerMask.NameToLayer("NoCol");
m_mask = ((num < 0) ? (-1) : (~(1 << num)));
m_armedAt = Time.time + ArmDelay;
}
public override void FVRFixedUpdate()
{
((FVRPhysicalObject)this).FVRFixedUpdate();
if (Time.time >= m_armedAt)
{
Scan();
}
}
private void Scan()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: 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_0046: 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_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
if (s_dumpedFrame != Time.frameCount)
{
s_dumpedFrame = Time.frameCount;
s_dumpedThisFrame.Clear();
}
Transform transform = ((Component)this).transform;
Vector3 val = transform.TransformPoint(ZoneCenter);
Vector3 val2 = Vector3.Scale(ZoneHalfExtents, transform.lossyScale);
int num = Physics.OverlapBoxNonAlloc(val, val2, s_hits, transform.rotation, m_mask, (QueryTriggerInteraction)1);
s_found.Clear();
for (int i = 0; i < num; i++)
{
Collider val3 = s_hits[i];
s_hits[i] = null;
if ((Object)(object)val3 == (Object)null)
{
continue;
}
Rigidbody attachedRigidbody = val3.attachedRigidbody;
if (!((Object)(object)attachedRigidbody == (Object)null) && !((Object)(object)attachedRigidbody == (Object)(object)((FVRPhysicalObject)this).RootRigidbody))
{
FVRPhysicalObject component = ((Component)attachedRigidbody).GetComponent<FVRPhysicalObject>();
if (!((Object)(object)component == (Object)null) && !((Object)(object)component == (Object)(object)this) && !s_found.Contains(component) && !s_dumpedThisFrame.Contains(((Object)component).GetInstanceID()) && CanDump(component))
{
s_found.Add(component);
}
}
}
for (int j = 0; j < s_found.Count; j++)
{
Dump(s_found[j]);
}
s_found.Clear();
}
public static bool CanDump(FVRPhysicalObject obj)
{
if (!((Component)obj).gameObject.activeInHierarchy)
{
return false;
}
if (((FVRInteractiveObject)obj).IsHeld || obj.IsAltHeld)
{
return false;
}
if ((Object)(object)obj.QuickbeltSlot != (Object)null)
{
return false;
}
if ((Object)(object)((Component)obj).transform.parent != (Object)null)
{
return false;
}
if (obj.IsPickUpLocked)
{
return false;
}
if ((Object)(object)obj.RootRigidbody == (Object)null || obj.RootRigidbody.isKinematic)
{
return false;
}
if ((Object)(object)obj.AltGrip != (Object)null && ((FVRInteractiveObject)obj.AltGrip).IsHeld)
{
return false;
}
FVRInteractiveObject[] componentsInChildren = ((Component)obj).GetComponentsInChildren<FVRInteractiveObject>();
for (int i = 0; i < componentsInChildren.Length; i++)
{
if ((Object)(object)componentsInChildren[i] != (Object)null && componentsInChildren[i].IsHeld)
{
return false;
}
}
return true;
}
private void Dump(FVRPhysicalObject obj)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
s_dumpedThisFrame.Add(((Object)obj).GetInstanceID());
Vector3 position = ((Component)obj).transform.position;
Object.Destroy((Object)(object)((Component)obj).gameObject);
if (Time.time >= m_nextSound)
{
m_nextSound = Time.time + SoundCooldown;
SM.PlayHandlingReleaseIntoSlotSound((HandlingReleaseIntoSlotType)1, position);
}
}
public override Quaternion GetRotTarget()
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
if (!HangUpright || ((FVRInteractiveObject)this).IsHeld || (Object)(object)((FVRPhysicalObject)this).QuickbeltSlot == (Object)null || (Object)(object)((FVRPhysicalObject)this).QuickbeltSlot.PoseOverride == (Object)null)
{
return ((FVRPhysicalObject)this).GetRotTarget();
}
Transform poseOverride = ((FVRPhysicalObject)this).QuickbeltSlot.PoseOverride;
Vector3 val = Vector3.zero;
if (((FVRPhysicalObject)this).QuickbeltSlot.IsPlayer && (Object)(object)GM.CurrentPlayerBody != (Object)null && (Object)(object)GM.CurrentPlayerBody.Torso != (Object)null)
{
Transform torso = GM.CurrentPlayerBody.Torso;
val = Vector3.ProjectOnPlane(poseOverride.position - torso.position, Vector3.up);
if (((Vector3)(ref val)).sqrMagnitude < 0.0025000002f)
{
val = Vector3.ProjectOnPlane(torso.forward, Vector3.up);
}
}
if (((Vector3)(ref val)).sqrMagnitude < 1E-06f)
{
val = Vector3.ProjectOnPlane(poseOverride.forward, Vector3.up);
}
if (((Vector3)(ref val)).sqrMagnitude < 1E-06f)
{
val = Vector3.ProjectOnPlane(poseOverride.up, Vector3.up);
}
if (((Vector3)(ref val)).sqrMagnitude < 1E-06f)
{
return ((FVRPhysicalObject)this).GetRotTarget();
}
Quaternion val2 = Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up);
if ((Object)(object)((FVRInteractiveObject)this).QBPoseOverride != (Object)null && !((FVRPhysicalObject)this).QuickbeltSlot.UseStraightAxisAlignment)
{
val2 *= ((FVRInteractiveObject)this).QBPoseOverride.localRotation;
}
return val2;
}
private void OnDrawGizmosSelected()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
Gizmos.color = new Color(1f, 0.3f, 0.2f, 0.6f);
Gizmos.matrix = ((Component)this).transform.localToWorldMatrix;
Gizmos.DrawWireCube(ZoneCenter, ZoneHalfExtents * 2f);
}
}
}
namespace LJIndustries.DumpPouch
{
[BepInPlugin("LJIndustries.DumpPouch", "DumpPouch", "0.1.2")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
public class DumpPouchPlugin : BaseUnityPlugin
{
private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
internal static ManualLogSource Logger;
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
LoadAssets();
}
private void LoadAssets()
{
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "LJIndustries.DumpPouch");
OtherLoader.RegisterDirectLoad(BasePath, "LJIndustries.DumpPouch", "", "", "dump_pouch", "");
}
}
}