Decompiled source of weaponinspector holdview v0.2.0

BepInEx\plugins\WeaponInspector.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using Player;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("WeaponInspector")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WeaponInspector")]
[assembly: AssemblyTitle("WeaponInspector")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 WeaponInspector
{
	[BepInPlugin("com.doubao.WeaponInspector", "Weapon Inspector", "0.2.0")]
	[BepInProcess("GTFO.exe")]
	public class WeaponInspectorPlugin : BasePlugin
	{
		public const string GUID = "com.doubao.WeaponInspector";

		public static ManualLogSource L;

		public override void Load()
		{
			L = ((BasePlugin)this).Log;
			((BasePlugin)this).Log.LogInfo((object)"[WeaponInspector] Load begin v0.2.0");
			try
			{
				((BasePlugin)this).AddComponent<WeaponInspectorManager>();
				((BasePlugin)this).Log.LogInfo((object)"[WeaponInspector] Loaded. F4/Float, J/Fixed, K/Hands");
			}
			catch (Exception ex)
			{
				((BasePlugin)this).Log.LogError((object)("[WeaponInspector] init failed: " + ex));
			}
		}
	}
	public enum InspectMode
	{
		None,
		Float,
		Fixed
	}
	public class WeaponInspectorManager : MonoBehaviour
	{
		public static InspectMode Mode;

		private PlayerAgent _agent;

		private FirstPersonItemHolder _holder;

		private PlayerFPSBody _arms;

		private Transform _cam;

		private readonly List<ItemEquippable> _items = new List<ItemEquippable>();

		private readonly List<bool> _savedActive = new List<bool>();

		private readonly List<Transform> _savedParent = new List<Transform>();

		private readonly List<Vector3> _savedPos = new List<Vector3>();

		private readonly List<Quaternion> _savedRot = new List<Quaternion>();

		private int _cur = -1;

		private bool _showHands;

		private bool _savedRelax;

		private bool _savedCrouch;

		private Vector3 _centerOffset;

		private bool _centerCached;

		private float _yaw;

		private float _pitch = 8f;

		private float _dist = 1.6f;

		private float _strafe;

		private float _lift;

		private Quaternion _camRotPrev;

		private float _zoom;

		private float _yawF = -32f;

		private float _pitchF = 8f;

		private float _rollF;

		private float _liftY;

		private float _strafeX;

		private const float FROLL = 6f;

		private const float YAW_LIMIT_HAND = 55f;

		private const float YAW_LIMIT_NO_HAND = 90f;

		private float _flipT = -1f;

		private const float FLIP_DUR = 1.2f;

		private InventorySlot[] _slots = (InventorySlot[])(object)new InventorySlot[0];

		private int _slotIdx;

		private float _pendingTimer = -1f;

		private string _pendingWant;

		private bool _rewielding;

		private void Update()
		{
			try
			{
				if (Input.GetKeyDown((KeyCode)285))
				{
					if (Mode == InspectMode.None)
					{
						EnterInspect(InspectMode.Float);
					}
					else
					{
						Exit();
					}
				}
				else if (Input.GetKeyDown((KeyCode)106))
				{
					if (Mode != InspectMode.None)
					{
						SwitchMode();
					}
				}
				else
				{
					if (Mode == InspectMode.None)
					{
						return;
					}
					if (Input.GetKeyDown((KeyCode)107) && Mode == InspectMode.Fixed)
					{
						_showHands = !_showHands;
						if (_showHands)
						{
							_yawF = Mathf.Clamp(_yawF, -55f, 55f);
						}
						ApplyHands();
					}
					if (Input.GetKeyDown((KeyCode)108) && Mode == InspectMode.Fixed)
					{
						_flipT = 0f;
					}
					if (Mode == InspectMode.Fixed)
					{
						TickFixed();
					}
					else
					{
						TickFloat();
					}
				}
			}
			catch (Exception ex)
			{
				Log("Update error: " + ex);
			}
		}

		private void LateUpdate()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0075: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: 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_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Expected O, but got Unknown
			//IL_0198: Expected O, but got Unknown
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (Mode == InspectMode.None || _cur < 0 || _cur >= _items.Count)
				{
					return;
				}
				ItemEquippable val = _items[_cur];
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				Transform transform = ((Component)val).transform;
				if (Mode == InspectMode.Float)
				{
					if ((Object)transform.parent != (Object)_cam)
					{
						transform.SetParent(_cam, true);
					}
					Vector3 position = _cam.position + _cam.forward * _dist + _cam.right * _strafe + _cam.up * _lift;
					Quaternion rotation = _cam.rotation * Quaternion.Euler(_pitch, _yaw, 0f);
					transform.position = position;
					transform.rotation = rotation;
					if ((Object)(object)_arms != (Object)null)
					{
						try
						{
							_arms.SetVisible(false);
							return;
						}
						catch
						{
							return;
						}
					}
				}
				else
				{
					if (Mode != InspectMode.Fixed)
					{
						return;
					}
					int cur = _cur;
					Transform val2 = ((cur >= 0 && cur < _savedParent.Count) ? _savedParent[cur] : null);
					if ((Object)(object)val2 != (Object)null && (Object)transform.parent != (Object)val2)
					{
						transform.SetParent(val2, true);
					}
					if (cur >= 0 && cur < _savedPos.Count)
					{
						transform.localPosition = _savedPos[cur] + new Vector3(_strafeX, _liftY + CurrentInspectLift(), _zoom);
						transform.localRotation = _savedRot[cur] * Quaternion.Euler(_pitchF, _yawF + CurrentInspectYaw(), 6f + _rollF + CurrentFlipAngle());
					}
					bool flag = InspectProgress() >= 0f;
					if ((Object)(object)_arms != (Object)null)
					{
						try
						{
							_arms.SetVisible(_showHands && !flag);
							return;
						}
						catch
						{
							return;
						}
					}
				}
			}
			catch (Exception ex)
			{
				Log("LateUpdate error: " + ex);
			}
		}

		private bool EnsureAgent()
		{
			if (!PlayerManager.HasLocalPlayerAgent())
			{
				return false;
			}
			PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
			if ((Object)(object)localPlayerAgent == (Object)null || (Object)(object)localPlayerAgent.FPItemHolder == (Object)null || (Object)(object)localPlayerAgent.FPSCamera == (Object)null)
			{
				return false;
			}
			_agent = localPlayerAgent;
			_holder = localPlayerAgent.FPItemHolder;
			_cam = ((Component)localPlayerAgent.FPSCamera).transform;
			try
			{
				_arms = _holder.FPSArms;
			}
			catch
			{
			}
			return true;
		}

		private void DetectCurrentSlot()
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			_slotIdx = 0;
			try
			{
				PlayerInventoryBase inventory = _agent.Inventory;
				string[] names = Enum.GetNames(typeof(InventorySlot));
				Array values = Enum.GetValues(typeof(InventorySlot));
				List<InventorySlot> list = new List<InventorySlot>();
				string[] array = new string[4] { "GearStandard", "GearSpecial", "GearMelee", "HackingTool" };
				for (int i = 0; i < names.Length; i++)
				{
					string text = names[i];
					bool flag = false;
					string[] array2 = array;
					foreach (string text2 in array2)
					{
						if (text == text2)
						{
							flag = true;
						}
					}
					if (flag)
					{
						list.Add((InventorySlot)values.GetValue(i));
					}
				}
				list.Sort((InventorySlot a, InventorySlot b) => ((int)a).CompareTo((int)b));
				_slots = list.ToArray();
				Log("[DIAG] InventorySlot names=" + string.Join(",", names));
				MethodInfo[] methods = ((object)inventory).GetType().GetMethods();
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.Name.Contains("Wield"))
					{
						ParameterInfo[] parameters = methodInfo.GetParameters();
						Log("[DIAG] method " + methodInfo.Name + "(" + string.Join(",", Array.ConvertAll(parameters, (ParameterInfo p) => p.ParameterType.Name + " " + p.Name)) + ") decl=" + methodInfo.DeclaringType.Name);
					}
				}
				int num = -1;
				try
				{
					PropertyInfo property = ((object)inventory).GetType().GetProperty("WieldedSlot");
					if (property != null)
					{
						object value = property.GetValue(inventory);
						num = (int)value;
						Log("[DIAG] WieldedSlot=" + value);
					}
				}
				catch (Exception ex)
				{
					LogErr("get WieldedSlot: " + ex.Message);
				}
				for (int num2 = 0; num2 < _slots.Length; num2++)
				{
					if ((int)_slots[num2] == num)
					{
						_slotIdx = num2;
						break;
					}
				}
				Log("[DIAG] DetectCurrentSlot cur=" + num + " idx=" + _slotIdx + " slots=" + string.Join(",", _slots));
			}
			catch (Exception ex2)
			{
				LogErr("slot detect: " + ex2.Message);
			}
		}

		private void EnterInspect(InspectMode mode)
		{
			if (!EnsureAgent())
			{
				return;
			}
			Collect();
			if (_items.Count == 0)
			{
				CleanupLists();
				return;
			}
			_cur = 0;
			for (int i = 0; i < _items.Count; i++)
			{
				bool flag = false;
				try
				{
					flag = _items[i].m_isWielded;
				}
				catch
				{
				}
				if (flag)
				{
					_cur = i;
					break;
				}
			}
			ShowCurrent();
			try
			{
				_savedRelax = FirstPersonItemHolder.RelaxPoseEnabled;
				_savedCrouch = FirstPersonItemHolder.CrouchTiltEnabled;
				FirstPersonItemHolder.RelaxPoseEnabled = true;
				FirstPersonItemHolder.CrouchTiltEnabled = false;
			}
			catch
			{
			}
			_showHands = mode == InspectMode.Fixed;
			ApplyHands();
			ResetFloatParams();
			ResetFixedParams();
			ShowMsg((mode == InspectMode.Float) ? "F4 Float (360 orbit)" : "J Hold view");
			Mode = mode;
		}

		private void SwitchMode()
		{
			if (Mode == InspectMode.Float)
			{
				_showHands = true;
				ResetFixedParams();
				ShowMsg("J Hold view");
				Mode = InspectMode.Fixed;
			}
			else
			{
				_showHands = false;
				ResetFloatParams();
				ShowCurrent();
				ShowMsg("F4 Float (360 orbit)");
				Mode = InspectMode.Float;
			}
			ApplyHands();
		}

		private void ResetFloatParams()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			_yaw = 0f;
			_pitch = 8f;
			_dist = 1.2f;
			_strafe = 0f;
			_lift = 0f;
			if ((Object)(object)_cam != (Object)null)
			{
				_camRotPrev = _cam.rotation;
			}
		}

		private void ResetFloatParamsKeepAngle()
		{
			_dist = 1.2f;
			_strafe = 0f;
			_lift = 0f;
		}

		private void ResetFixedParams()
		{
			_zoom = 0f;
			_yawF = -32f;
			_pitchF = 8f;
			_rollF = 0f;
			_liftY = 0f;
			_strafeX = 0f;
		}

		private void TickFloat()
		{
			float deltaTime = Time.deltaTime;
			if (Input.GetMouseButton(2))
			{
				_yaw += Input.GetAxis("Mouse X") * 0.6f;
				_pitch -= Input.GetAxis("Mouse y") * 0.6f;
			}
			if (Input.GetKeyDown((KeyCode)113))
			{
				_cur = (_cur + 1 + _items.Count) % _items.Count;
				ShowCurrent();
				ResetFloatParamsKeepAngle();
			}
			if (Input.GetKeyDown((KeyCode)101))
			{
				_cur = (_cur - 1 + _items.Count) % _items.Count;
				ShowCurrent();
				ResetFloatParamsKeepAngle();
			}
			if (Input.GetKey((KeyCode)273))
			{
				_lift = Mathf.Clamp(_lift + deltaTime * 0.4f, -2f, 2f);
			}
			if (Input.GetKey((KeyCode)274))
			{
				_lift = Mathf.Clamp(_lift - deltaTime * 0.4f, -2f, 2f);
			}
			if (Input.GetKey((KeyCode)276))
			{
				_strafe = Mathf.Clamp(_strafe - deltaTime * 0.4f, -2f, 2f);
			}
			if (Input.GetKey((KeyCode)275))
			{
				_strafe = Mathf.Clamp(_strafe + deltaTime * 0.4f, -2f, 2f);
			}
			if (Input.GetKey((KeyCode)91))
			{
				_dist = Mathf.Clamp(_dist - deltaTime * 0.8f, 0.4f, 6f);
			}
			if (Input.GetKey((KeyCode)93))
			{
				_dist = Mathf.Clamp(_dist + deltaTime * 0.8f, 0.4f, 6f);
			}
		}

		private void SwitchFloat(int dir)
		{
			if (_slots == null || _slots.Length == 0)
			{
				Log("[DIAG] SwitchFloat: no slots, rebuilding");
				DetectCurrentSlot();
				if (_slots == null || _slots.Length == 0)
				{
					LogErr("no inventory slots available");
					return;
				}
			}
			int num = (_slotIdx = (_slotIdx + dir + _slots.Length) % _slots.Length);
			_rewielding = true;
			_pendingTimer = 0f;
			try
			{
				RestoreAllTransforms();
				bool flag = false;
				PlayerInventoryBase inventory = _agent.Inventory;
				object obj = _slots[num];
				try
				{
					PropertyInfo property = ((object)inventory).GetType().GetProperty("WieldedSlot");
					if (property != null && property.CanWrite)
					{
						property.SetValue(inventory, obj);
						flag = true;
					}
				}
				catch (Exception ex)
				{
					LogErr("set WieldedSlot: " + ex.Message);
				}
				_pendingWant = null;
				Log("[DIAG] wield -> " + obj?.ToString() + " called=" + flag);
				if (!flag)
				{
					_rewielding = false;
					LogErr("no wield method found");
				}
			}
			catch (Exception ex2)
			{
				LogErr("wield: " + ex2.Message);
				_rewielding = false;
			}
			ResetFloatParams();
			_centerCached = false;
		}

		private void RestoreAllTransforms()
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < _items.Count; i++)
			{
				ItemEquippable val = _items[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				try
				{
					Transform transform = ((Component)val).transform;
					if (i < _savedParent.Count && (Object)(object)_savedParent[i] != (Object)null)
					{
						transform.SetParent(_savedParent[i], true);
					}
					if (i < _savedPos.Count)
					{
						transform.localPosition = _savedPos[i];
					}
					if (i < _savedRot.Count)
					{
						transform.localRotation = _savedRot[i];
					}
				}
				catch
				{
				}
			}
		}

		private void HandlePendingWield()
		{
			if (!_rewielding)
			{
				return;
			}
			_pendingTimer += Time.deltaTime;
			try
			{
				ItemEquippable wieldedItem = _agent.Inventory.WieldedItem;
				if ((Object)(object)wieldedItem != (Object)null && (Object)(object)((Component)wieldedItem).gameObject != (Object)null && ((Component)wieldedItem).gameObject.activeInHierarchy)
				{
					string pendingWant = ((Object)wieldedItem).name ?? "";
					if (_pendingWant == null)
					{
						_pendingWant = pendingWant;
					}
					if (!(_pendingTimer >= 0.25f))
					{
						return;
					}
					_rewielding = false;
					_ = _showHands;
					Collect();
					_cur = -1;
					for (int i = 0; i < _items.Count; i++)
					{
						bool flag = false;
						try
						{
							flag = _items[i].m_isWielded;
						}
						catch
						{
						}
						if (flag)
						{
							_cur = i;
							break;
						}
					}
					if (_cur < 0 && _items.Count > 0)
					{
						_cur = 0;
					}
					ShowCurrent();
					ResetFloatParams();
					_centerCached = false;
					Log("[DIAG] rewield done, items=" + _items.Count + " cur=" + _cur + " name=" + CurName());
				}
				else if (_pendingTimer > 1f)
				{
					_rewielding = false;
					Log("[DIAG] rewield timeout");
				}
			}
			catch (Exception ex)
			{
				LogErr("pending: " + ex.Message);
				_rewielding = false;
			}
		}

		private void TickFixed()
		{
			float deltaTime = Time.deltaTime;
			float num = (_showHands ? 55f : 90f);
			if (Input.GetKey((KeyCode)61) || Input.GetKey((KeyCode)270))
			{
				_zoom = Mathf.Clamp(_zoom + deltaTime * 0.4f, -1.5f, 0.3f);
			}
			if (Input.GetKey((KeyCode)45) || Input.GetKey((KeyCode)269))
			{
				_zoom = Mathf.Clamp(_zoom - deltaTime * 0.4f, -1.5f, 0.3f);
			}
			if (Input.GetKey((KeyCode)91))
			{
				_yawF = Mathf.Clamp(_yawF - deltaTime * 70f, 0f - num, num);
			}
			if (Input.GetKey((KeyCode)93))
			{
				_yawF = Mathf.Clamp(_yawF + deltaTime * 70f, 0f - num, num);
			}
			if (Input.GetKey((KeyCode)59))
			{
				_pitchF = Mathf.Clamp(_pitchF - deltaTime * 70f, -60f, 60f);
			}
			if (Input.GetKey((KeyCode)39))
			{
				_pitchF = Mathf.Clamp(_pitchF + deltaTime * 70f, -60f, 60f);
			}
			if (Input.GetKey((KeyCode)44))
			{
				_rollF = Mathf.Clamp(_rollF - deltaTime * 70f, -180f, 180f);
			}
			if (Input.GetKey((KeyCode)46))
			{
				_rollF = Mathf.Clamp(_rollF + deltaTime * 70f, -180f, 180f);
			}
			if (Input.GetKey((KeyCode)273))
			{
				_liftY = Mathf.Clamp(_liftY + deltaTime * 0.3f, -0.35f, 0.35f);
			}
			if (Input.GetKey((KeyCode)274))
			{
				_liftY = Mathf.Clamp(_liftY - deltaTime * 0.3f, -0.35f, 0.35f);
			}
			if (Input.GetKey((KeyCode)276))
			{
				_strafeX = Mathf.Clamp(_strafeX - deltaTime * 0.3f, -0.35f, 0.35f);
			}
			if (Input.GetKey((KeyCode)275))
			{
				_strafeX = Mathf.Clamp(_strafeX + deltaTime * 0.3f, -0.35f, 0.35f);
			}
			if (_flipT >= 0f)
			{
				_flipT += deltaTime;
				if (_flipT > 1.2f)
				{
					_flipT = -1f;
				}
			}
		}

		private float InspectProgress()
		{
			if (_flipT < 0f)
			{
				return -1f;
			}
			return Mathf.Clamp01(_flipT / 1.2f);
		}

		private float CurrentFlipAngle()
		{
			float num = InspectProgress();
			if (num < 0f)
			{
				return 0f;
			}
			return Mathf.Sin(num * (float)Math.PI) * 150f;
		}

		private float CurrentInspectLift()
		{
			float num = InspectProgress();
			if (num < 0f)
			{
				return 0f;
			}
			return Mathf.Sin(num * (float)Math.PI) * 0.08f;
		}

		private float CurrentInspectYaw()
		{
			float num = InspectProgress();
			if (num < 0f)
			{
				return 0f;
			}
			return Mathf.Sin(num * (float)Math.PI) * 28f;
		}

		private void ApplyHands()
		{
			if ((Object)(object)_arms == (Object)null)
			{
				return;
			}
			bool visible = _showHands && Mode == InspectMode.Fixed;
			try
			{
				_arms.SetVisible(visible);
			}
			catch
			{
			}
		}

		private void ShowCurrent()
		{
			for (int i = 0; i < _items.Count; i++)
			{
				try
				{
					((Component)_items[i]).gameObject.SetActive(i == _cur);
				}
				catch
				{
				}
			}
		}

		private void Collect()
		{
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			CleanupLists();
			try
			{
				Il2CppArrayBase<ItemEquippable> componentsInChildren = ((Component)_holder).GetComponentsInChildren<ItemEquippable>(true);
				Log("[DIAG] ItemEquippable count=" + componentsInChildren.Length);
				foreach (ItemEquippable item in componentsInChildren)
				{
					if (!((Object)(object)item == (Object)null))
					{
						_items.Add(item);
						Log("[DIAG] item: " + ((Object)item).name + " active=" + ((Component)item).gameObject.activeSelf + " wielded=" + item.m_isWielded);
					}
				}
			}
			catch (Exception ex)
			{
				LogErr("collect: " + ex.Message);
			}
			try
			{
				PlayerInventoryBase inventory = _agent.Inventory;
				BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
				Log("[DIAG] === Inventory type=" + ((object)inventory).GetType().FullName + " ===");
				FieldInfo[] fields = ((object)inventory).GetType().GetFields(bindingAttr);
				foreach (FieldInfo fieldInfo in fields)
				{
					string name = fieldInfo.FieldType.Name;
					if (!name.Contains("Int") && !name.Contains("Single") && !name.Contains("Boolean") && !name.Contains("Byte"))
					{
						Log("[DIAG] FLD " + fieldInfo.Name + " : " + name + " decl=" + fieldInfo.DeclaringType.Name);
					}
				}
			}
			catch (Exception ex2)
			{
				LogErr("inv diag: " + ex2.Message);
			}
			foreach (ItemEquippable item2 in _items)
			{
				try
				{
					_savedActive.Add(((Component)item2).gameObject.activeSelf);
					_savedParent.Add(((Component)item2).transform.parent);
					_savedPos.Add(((Component)item2).transform.localPosition);
					_savedRot.Add(((Component)item2).transform.localRotation);
				}
				catch
				{
					_savedActive.Add(item: false);
					_savedParent.Add(null);
					_savedPos.Add(Vector3.zero);
					_savedRot.Add(Quaternion.identity);
				}
			}
		}

		private void Exit()
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				for (int i = 0; i < _items.Count; i++)
				{
					ItemEquippable val = _items[i];
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					try
					{
						Transform transform = ((Component)val).transform;
						if (i < _savedParent.Count && (Object)(object)_savedParent[i] != (Object)null)
						{
							transform.SetParent(_savedParent[i], true);
						}
						if (i < _savedPos.Count)
						{
							transform.localPosition = _savedPos[i];
						}
						if (i < _savedRot.Count)
						{
							transform.localRotation = _savedRot[i];
						}
						if (i < _savedActive.Count)
						{
							((Component)val).gameObject.SetActive(_savedActive[i]);
						}
					}
					catch
					{
					}
				}
				if ((Object)(object)_arms != (Object)null)
				{
					try
					{
						_arms.SetVisible(true);
					}
					catch
					{
					}
				}
				try
				{
					if ((Object)(object)_holder != (Object)null)
					{
						FirstPersonItemHolder.RelaxPoseEnabled = _savedRelax;
						FirstPersonItemHolder.CrouchTiltEnabled = _savedCrouch;
					}
				}
				catch
				{
				}
			}
			catch
			{
			}
			CleanupLists();
			Mode = InspectMode.None;
			_agent = null;
			_holder = null;
			_arms = null;
			_cam = null;
			_cur = -1;
			_centerCached = false;
		}

		private void CleanupLists()
		{
			_items.Clear();
			_savedActive.Clear();
			_savedParent.Clear();
			_savedPos.Clear();
			_savedRot.Clear();
		}

		private void OnDestroy()
		{
			if (Mode != InspectMode.None)
			{
				Exit();
			}
		}

		private string CurName()
		{
			try
			{
				if (_cur >= 0 && _cur < _items.Count && (Object)(object)_items[_cur] != (Object)null)
				{
					return ((Object)_items[_cur]).name ?? "";
				}
			}
			catch
			{
			}
			return "";
		}

		private void OnGUI()
		{
			//IL_0020: 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_0039: Expected O, but got Unknown
			try
			{
				if (Mode != InspectMode.None)
				{
					GUILayout.BeginArea(new Rect(16f, 16f, 460f, 150f), new GUIStyle(GUI.skin.box));
					string text = CurName();
					int count = _items.Count;
					int num = ((_cur >= 0) ? (_cur + 1) : 0);
					GUILayout.Label("<b>武器检视</b>  (" + num + "/" + count + ")  " + text, (Il2CppReferenceArray<GUILayoutOption>)null);
					if (Mode == InspectMode.Float)
					{
						GUILayout.Label("【悬浮】中键拖动旋转 | 方向键移动 | [ ] 前后", (Il2CppReferenceArray<GUILayoutOption>)null);
						GUILayout.Label("Q/E 切武器(含BIO/近战) | J 持枪检视 | F4 退出", (Il2CppReferenceArray<GUILayoutOption>)null);
					}
					else
					{
						GUILayout.Label("【持枪】K 藏/显手 | L 翻转枪 | ; ' 俯仰 | , . 侧翻", (Il2CppReferenceArray<GUILayoutOption>)null);
						GUILayout.Label("方向键移动 | [ ] 前后距离 | J 回悬浮 | F4 退出", (Il2CppReferenceArray<GUILayoutOption>)null);
					}
					GUILayout.EndArea();
				}
			}
			catch
			{
			}
		}

		private static void ShowMsg(string m)
		{
		}

		private void Log(string m)
		{
			try
			{
				if (WeaponInspectorPlugin.L != null)
				{
					WeaponInspectorPlugin.L.LogInfo((object)("[Inspector] " + m));
				}
			}
			catch
			{
			}
		}

		private void LogErr(string m)
		{
			try
			{
				if (WeaponInspectorPlugin.L != null)
				{
					WeaponInspectorPlugin.L.LogError((object)("[Inspector] " + m));
				}
			}
			catch
			{
			}
		}
	}
}