using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
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: AssemblyVersion("1.0.0.0")]
namespace WeaponInspector;
[BepInPlugin("com.doubao.WeaponInspector", "Weapon Inspector 武器检视器", "1.6.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");
try
{
((BasePlugin)this).AddComponent<WeaponInspectorUI>();
((BasePlugin)this).Log.LogInfo((object)"[WeaponInspector] Loaded. Press F4 in game to toggle.");
}
catch (Exception ex)
{
((BasePlugin)this).Log.LogError((object)("[WeaponInspector] FAILED to add component: " + ex));
}
}
}
public class WeaponInspectorUI : MonoBehaviour
{
private bool _inspecting;
private float _yaw;
private float _pitch;
private float _dist = 1.5f;
private PlayerAgent _agent;
private FirstPersonItemHolder _holder;
private readonly List<ItemEquippable> _items = new List<ItemEquippable>();
private readonly List<bool> _savedActives = new List<bool>();
private readonly List<Transform> _savedParents = new List<Transform>();
private readonly List<Vector3> _savedPos = new List<Vector3>();
private readonly List<Quaternion> _savedRot = new List<Quaternion>();
private int _curIdx = -1;
private bool _savedRelax;
private bool _savedCrouch;
private Transform _fpsBody;
private bool _savedFpsBodyActive;
private string _msg;
private float _msgTime;
private bool _handMode;
private Quaternion _holderRot;
private GameObject _fpsBodyRef;
public bool _fpsBodyMoved;
public Vector3 _fpsBodyOrigPos;
public Quaternion _fpsBodyOrigRot;
public Component _fpsBodyOrigParent;
public Quaternion _fpsBodyHoldLocalRot;
private void Update()
{
try
{
if (Input.GetKeyDown((KeyCode)285))
{
if (_inspecting)
{
ExitInspect();
}
else
{
EnterInspect();
}
}
else if (_inspecting)
{
TickInspect();
}
}
catch (Exception ex)
{
Log("Update error: " + ex);
}
}
private void LateUpdate()
{
try
{
if (_inspecting)
{
ApplyWeaponPose();
}
}
catch (Exception ex)
{
Log("LateUpdate error: " + ex);
}
}
private void EnterInspect()
{
//IL_0201: Unknown result type (might be due to invalid IL or missing references)
//IL_0211: Unknown result type (might be due to invalid IL or missing references)
//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
_handMode = true;
Log("EnterInspect called");
try
{
bool flag = false;
try
{
flag = PlayerManager.HasLocalPlayerAgent();
}
catch
{
}
if (!flag)
{
ShowMsg("尚未进入游戏,进局内再按 F4");
return;
}
PlayerAgent val = null;
try
{
val = PlayerManager.GetLocalPlayerAgent();
}
catch
{
}
if ((Object)(object)val == (Object)null)
{
ShowMsg("玩家对象不可用");
return;
}
FirstPersonItemHolder val2 = null;
try
{
val2 = val.FPItemHolder;
}
catch
{
}
if ((Object)(object)val2 == (Object)null)
{
ShowMsg("玩家对象不可用");
return;
}
_items.Clear();
try
{
foreach (ItemEquippable componentsInChild in ((Component)val2).GetComponentsInChildren<ItemEquippable>(true))
{
if ((Object)(object)componentsInChild != (Object)null)
{
_items.Add(componentsInChild);
}
}
}
catch (Exception ex)
{
LogErr("collect items: " + ex.Message);
}
if (_items.Count == 0)
{
ShowMsg("没有可检视的武器");
return;
}
Log("collected " + _items.Count + " weapons");
_agent = val;
_holder = val2;
_savedActives.Clear();
_savedParents.Clear();
_savedPos.Clear();
_savedRot.Clear();
foreach (ItemEquippable item in _items)
{
try
{
_savedActives.Add(((Component)item).gameObject.activeSelf);
_savedParents.Add(((Component)item).transform.parent);
_savedPos.Add(((Component)item).transform.localPosition);
_savedRot.Add(((Component)item).transform.localRotation);
}
catch
{
_savedActives.Add(item: false);
_savedParents.Add(null);
_savedPos.Add(Vector3.zero);
_savedRot.Add(Quaternion.identity);
}
}
_curIdx = 0;
for (int i = 0; i < _items.Count; i++)
{
bool flag2 = false;
try
{
flag2 = _items[i].m_isWielded;
}
catch
{
}
if (flag2)
{
_curIdx = i;
break;
}
}
try
{
_fpsBody = FindChild(((Component)val2).transform, "FPSBody");
_fpsBodyRef = ((Component)_fpsBody).gameObject;
if ((Object)(object)_fpsBody != (Object)null)
{
_savedFpsBodyActive = ((Component)_fpsBody).gameObject.activeSelf;
((Component)_fpsBody).gameObject.SetActive(false);
}
}
catch (Exception ex2)
{
LogErr("hide fpsbody: " + ex2.Message);
}
try
{
_savedRelax = FirstPersonItemHolder.RelaxPoseEnabled;
_savedCrouch = FirstPersonItemHolder.CrouchTiltEnabled;
FirstPersonItemHolder.RelaxPoseEnabled = true;
FirstPersonItemHolder.CrouchTiltEnabled = false;
}
catch
{
}
_inspecting = true;
_yaw = 0f;
_pitch = 0f;
_dist = 1.5f;
ShowWeapon(_curIdx);
Log("EnterInspect SUCCESS, showing [" + _curIdx + "] " + ((Object)_items[_curIdx]).name);
}
catch (Exception ex3)
{
LogErr("EnterInspect fatal: " + ex3);
Restore();
ShowMsg("开启失败: " + ex3.Message);
}
}
private void ShowWeapon(int idx)
{
if (idx < 0 || idx >= _items.Count)
{
return;
}
for (int i = 0; i < _items.Count; i++)
{
if (i != idx)
{
try
{
((Component)_items[i]).gameObject.SetActive(false);
}
catch
{
}
}
}
try
{
((Component)_items[idx]).gameObject.SetActive(true);
}
catch (Exception ex)
{
LogErr("activate weapon: " + ex.Message);
}
}
private void TickInspect()
{
if ((Object)(object)_agent == (Object)null || (Object)(object)_holder == (Object)null || _items.Count == 0)
{
ExitInspect();
return;
}
PlayerAgent agent = _agent;
Log("DIAG T0");
if ((Object)(object)agent.FPSCamera == (Object)null)
{
ExitInspect();
return;
}
if (Input.GetKeyDown((KeyCode)113))
{
_curIdx = (_curIdx + 1) % _items.Count;
ShowWeapon(_curIdx);
_yaw = 0f;
_pitch = 0f;
}
if (Input.GetKeyDown((KeyCode)101))
{
_curIdx = (_curIdx - 1 + _items.Count) % _items.Count;
ShowWeapon(_curIdx);
_yaw = 0f;
_pitch = 0f;
}
if (Input.GetKeyDown((KeyCode)273))
{
_dist = Mathf.Clamp(_dist - 0.25f, 0.3f, 6f);
}
if (Input.GetKeyDown((KeyCode)274))
{
_dist = Mathf.Clamp(_dist + 0.25f, 0.3f, 6f);
}
if (Input.GetMouseButton(2))
{
_yaw += Input.GetAxis("Mouse X") * 0.6f;
_pitch -= Input.GetAxis("Mouse y") * 0.6f;
return;
}
_yaw += Time.deltaTime * 0f;
_pitch = Mathf.Lerp(_pitch, 8f, Time.deltaTime * 0.01f);
Log("DIAG T3");
if (Input.GetKeyDown((KeyCode)106))
{
_handMode = !_handMode;
}
}
private void ApplyWeaponPose()
{
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: 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_0121: 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_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: 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_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: 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_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
Transform transform = ((Component)_agent.FPSCamera).transform;
Transform transform2 = ((Component)_items[_curIdx]).transform;
if (!_handMode)
{
transform2.SetParent(_savedParents[_curIdx], false);
transform2.localPosition = _savedPos[_curIdx];
transform2.localRotation = _savedRot[_curIdx];
transform2.SetParent(transform, true);
transform2.position = ((Component)_holder).transform.position + transform.forward * 0.9f;
transform2.rotation = transform.rotation * Quaternion.Euler(_pitch, _yaw, 0f);
if (!((Object)(object)_fpsBodyRef == (Object)null))
{
_fpsBodyRef.SetActive(true);
}
return;
}
try
{
transform2.SetParent(transform, true);
Vector3 position = transform.position + transform.forward * _dist;
Quaternion rotation = transform.rotation * Quaternion.Euler(_pitch, _yaw, 0f);
transform2.position = position;
transform2.rotation = rotation;
_fpsBodyRef.SetActive(false);
}
catch (Exception)
{
}
}
private void ExitInspect()
{
Restore();
_inspecting = false;
}
private void Restore()
{
//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: 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 < _savedParents.Count && (Object)(object)_savedParents[i] != (Object)null)
{
transform.SetParent(_savedParents[i], true);
}
if (i < _savedPos.Count)
{
transform.localPosition = _savedPos[i];
}
if (i < _savedRot.Count)
{
transform.localRotation = _savedRot[i];
}
if (i < _savedActives.Count)
{
((Component)val).gameObject.SetActive(_savedActives[i]);
}
}
catch
{
}
}
if ((Object)(object)_fpsBody != (Object)null)
{
try
{
((Component)_fpsBody).gameObject.SetActive(_savedFpsBodyActive);
}
catch
{
}
}
if ((Object)(object)_holder != (Object)null)
{
try
{
FirstPersonItemHolder.RelaxPoseEnabled = _savedRelax;
FirstPersonItemHolder.CrouchTiltEnabled = _savedCrouch;
}
catch
{
}
}
}
catch
{
}
_items.Clear();
_savedActives.Clear();
_savedParents.Clear();
_savedPos.Clear();
_savedRot.Clear();
_curIdx = -1;
_agent = null;
_holder = null;
if (_fpsBodyMoved)
{
if (!((Object)(object)_fpsBodyRef == (Object)null))
{
((Component)_fpsBodyRef).transform.SetParent((Transform)(object)_fpsBodyOrigParent, true);
((Component)_fpsBodyRef).transform.position = _fpsBodyOrigPos;
((Component)_fpsBodyRef).transform.rotation = _fpsBodyOrigRot;
}
_fpsBodyMoved = false;
}
_fpsBody = null;
}
private void OnDestroy()
{
if (_inspecting)
{
Restore();
}
}
private Transform FindChild(Transform parent, string namePart)
{
try
{
if ((Object)(object)parent == (Object)null)
{
return null;
}
if (((Object)parent).name != null && ((Object)parent).name.Contains(namePart))
{
return parent;
}
int childCount = parent.childCount;
for (int i = 0; i < childCount; i++)
{
Transform val = FindChild(parent.GetChild(i), namePart);
if ((Object)(object)val != (Object)null)
{
return val;
}
}
}
catch
{
}
return null;
}
private void ShowMsg(string m)
{
_msg = m;
_msgTime = Time.time;
}
private void OnGUI()
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Expected O, but got Unknown
try
{
if (_inspecting)
{
GUILayout.BeginArea(new Rect(20f, 20f, 420f, 120f), new GUIStyle(GUI.skin.box));
GUILayout.Label("武器检视 (" + (_curIdx + 1) + "/" + _items.Count + ") " + GetItemName(), (Il2CppReferenceArray<GUILayoutOption>)null);
GUILayout.Label("Q/E 切武器 左键开枪 R 换弹", (Il2CppReferenceArray<GUILayoutOption>)null);
GUILayout.Label("上/下键 调远近 按住中键拖动手动转", (Il2CppReferenceArray<GUILayoutOption>)null);
GUILayout.Label("F4: 退出", (Il2CppReferenceArray<GUILayoutOption>)null);
GUILayout.EndArea();
}
else if (_msg != null && Time.time - _msgTime < 4f)
{
GUILayout.BeginArea(new Rect(20f, 20f, 420f, 60f), new GUIStyle(GUI.skin.box));
GUILayout.Label("武器检视: " + _msg, (Il2CppReferenceArray<GUILayoutOption>)null);
GUILayout.EndArea();
}
}
catch
{
}
}
private string GetItemName()
{
try
{
if (_curIdx >= 0 && _curIdx < _items.Count && (Object)(object)_items[_curIdx] != (Object)null)
{
return ((Object)_items[_curIdx]).name ?? "武器";
}
}
catch
{
}
return "武器";
}
private void Log(string msg)
{
try
{
ManualLogSource l = WeaponInspectorPlugin.L;
if (l != null)
{
l.LogInfo((object)("[Inspector] " + msg));
}
}
catch
{
}
}
private void LogErr(string msg)
{
try
{
ManualLogSource l = WeaponInspectorPlugin.L;
if (l != null)
{
l.LogError((object)("[Inspector] " + msg));
}
}
catch
{
}
}
}