Decompiled source of Gun Sniper Rifle v0.6.0

TheSniperRifle.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Wakaura")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TheSniperRifle")]
[assembly: AssemblyTitle("TheSniperRifle")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 TheSniperRifle
{
	public enum CustomInputKey
	{
		ZoomMode,
		ZoomModeTuningDecreaseFOV,
		ZoomModeTuningIncreaseFOV,
		LaserDot
	}
	public class CustomSettingManager : MonoBehaviour
	{
		public enum CustomSetting
		{
			Undefined,
			ZoomeModeScrollingFactor,
			ZoomModeTuningUseMouseScrolling
		}

		public enum CustomSettingType
		{
			Gameplay,
			Debug
		}

		public static CustomSettingManager instance;

		private Dictionary<CustomSetting, string> settingsName = new Dictionary<CustomSetting, string>();

		private Dictionary<CustomSetting, int> settingsValue = new Dictionary<CustomSetting, int>();

		private Dictionary<CustomSetting, int> defaultSettingsValue = new Dictionary<CustomSetting, int>();

		private Dictionary<CustomSettingType, List<CustomSetting>> settings = new Dictionary<CustomSettingType, List<CustomSetting>>();

		private const string es3keyName = "CustomSettings";

		private const string fileName = "SettingsDataCustom.es3";

		private Dictionary<string, string> debugMessages = new Dictionary<string, string>
		{
			{ "NoKeyInFile", "Key {0} not found in file: {1}" },
			{ "FailLoading", "Failed to load settings: {0}; file will be deleted." },
			{ "ExistedSetting", "Setting already exists: {0} {1}" },
			{ "NoSetting", "Setting not found: {0}" },
			{ "NoDefaultValue", "Default value not found for setting: {0}" },
			{ "NoSettingType", "SettingType not found: {0}" },
			{ "DuplicateInstance", "A duplicate CustomSettingManager was detected and destroyed." }
		};

		public static bool IsAvailable => instance != null;

		private void SettingAdd(CustomSettingType settingType, CustomSetting setting, string _name, int value)
		{
			if (settings.ContainsKey(settingType))
			{
				settings[settingType].Add(setting);
			}
			else
			{
				settings[settingType] = new List<CustomSetting> { setting };
			}
			if (settingsName.ContainsKey(setting))
			{
				Debug.LogError((object)string.Format(debugMessages["ExistedSetting"], setting.ToString(), _name));
				return;
			}
			settingsName[setting] = _name;
			settingsValue[setting] = value;
			defaultSettingsValue[setting] = value;
		}

		private void InitializeSettings()
		{
			SettingAdd(CustomSettingType.Gameplay, CustomSetting.ZoomModeTuningUseMouseScrolling, "SniperRifle: UseMouseScrollingForZoomTuning", 1);
			SettingAdd(CustomSettingType.Gameplay, CustomSetting.ZoomeModeScrollingFactor, "SniperRifle: ZoomTuningFactor", 10);
		}

		public void SaveSettings()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			SettingsSaveData val = new SettingsSaveData();
			val.settingsValue = new Dictionary<string, int>();
			foreach (KeyValuePair<CustomSetting, int> item in settingsValue)
			{
				val.settingsValue[item.Key.ToString()] = item.Value;
			}
			ES3Settings val2 = new ES3Settings(new Enum[1] { (Enum)(object)(Location)4 });
			val2.path = "SettingsDataCustom.es3";
			ES3.Save<SettingsSaveData>("CustomSettings", val, val2);
			ES3.StoreCachedFile(val2);
		}

		public void LoadSettings()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			try
			{
				ES3Settings val = new ES3Settings("SettingsDataCustom.es3", new Enum[1] { (Enum)(object)(Location)0 });
				if (ES3.FileExists(val))
				{
					if (ES3.KeyExists("CustomSettings", val))
					{
						foreach (KeyValuePair<string, int> item in ES3.Load<SettingsSaveData>("CustomSettings", val).settingsValue)
						{
							if (Enum.TryParse<CustomSetting>(item.Key, out var result) && settingsValue.ContainsKey(result))
							{
								settingsValue[result] = item.Value;
							}
						}
						return;
					}
					Debug.LogWarning((object)string.Format(debugMessages["NoKeyInFile"], "CustomSettings", val.FullPath));
				}
				else
				{
					SaveSettings();
				}
			}
			catch (Exception ex)
			{
				Debug.LogError((object)string.Format(debugMessages["FailLoading"], ex.Message));
				ES3.DeleteFile("SettingsDataCustom.es3");
				SaveSettings();
			}
		}

		public int SettingValueFetch(CustomSetting setting)
		{
			if (!settingsValue.ContainsKey(setting))
			{
				return 0;
			}
			return settingsValue[setting];
		}

		public float SettingValueFetchFloat(CustomSetting setting)
		{
			return (float)settingsValue[setting] / 100f;
		}

		public void SettingValueSet(CustomSetting setting, int value)
		{
			if (settingsValue.ContainsKey(setting))
			{
				settingsValue[setting] = value;
			}
			else
			{
				Debug.LogWarning((object)string.Format(debugMessages["NoKeyInFile"], setting));
			}
		}

		public void ResetSettingToDefault(CustomSetting setting)
		{
			if (defaultSettingsValue.ContainsKey(setting))
			{
				settingsValue[setting] = defaultSettingsValue[setting];
			}
			else
			{
				Debug.LogWarning((object)string.Format(debugMessages["NoDefaultValue"], setting));
			}
		}

		public void ResetSettingTypeToDefault(CustomSettingType settingType)
		{
			if (settings.ContainsKey(settingType))
			{
				foreach (CustomSetting item in settings[settingType])
				{
					if (defaultSettingsValue.ContainsKey(item))
					{
						settingsValue[item] = defaultSettingsValue[item];
					}
				}
				return;
			}
			Debug.LogWarning((object)string.Format(debugMessages["NoSettingType"], settingType));
		}

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
				Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
				Debug.Log((object)(((Object)instance).name + " initialized."));
				InitializeSettings();
				LoadSettings();
			}
			else
			{
				Debug.LogWarning((object)debugMessages["DuplicateInstance"]);
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}
	}
	[Serializable]
	public class CustomKeyBindingSaveData
	{
		public Dictionary<CustomInputKey, List<string>> bindingOverrides;
	}
	public class CustomInputManager : MonoBehaviour
	{
		public static CustomInputManager instance;

		private Dictionary<CustomInputKey, InputAction> inputActions;

		private Dictionary<CustomInputKey, List<string>> defaultBindingPaths;

		private Dictionary<string, CustomInputKey> tagDictionary = new Dictionary<string, CustomInputKey>();

		private const string es3keyName = "CustomKeyBindings";

		public const string DEFAULT_KEYBINDING_FILE = "DefaultCustomKeyBindings.es3";

		private const string CURRENT_KEYBINDING_FILE = "CurrentCustomKeyBindings.es3";

		private static readonly Dictionary<string, string> mouseMappings = new Dictionary<string, string>
		{
			{ "leftButton", "Mouse Left" },
			{ "rightButton", "Mouse Right" },
			{ "middleButton", "Mouse Middle" },
			{ "press", "Mouse Press" },
			{ "backButton", "Mouse Back" },
			{ "forwardButton", "Mouse Forward" }
		};

		public static bool IsAvailable => instance != null;

		private void InitializeInputs()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			inputActions = new Dictionary<CustomInputKey, InputAction>
			{
				{
					CustomInputKey.ZoomMode,
					new InputAction("Zoom Mode", (InputActionType)0, "<Keyboard>/z", (string)null, (string)null, (string)null)
				},
				{
					CustomInputKey.LaserDot,
					new InputAction("Laser Dot", (InputActionType)0, "<Keyboard>/x", (string)null, (string)null, (string)null)
				},
				{
					CustomInputKey.ZoomModeTuningDecreaseFOV,
					new InputAction("Zoom Mode", (InputActionType)0, "<Keyboard>/Numpad5", (string)null, (string)null, (string)null)
				},
				{
					CustomInputKey.ZoomModeTuningIncreaseFOV,
					new InputAction("Zoom Mode", (InputActionType)0, "<Keyboard>/Numpad8", (string)null, (string)null, (string)null)
				}
			};
			foreach (InputAction value in inputActions.Values)
			{
				value.Enable();
			}
		}

		private void StoreDefaultBindings()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			defaultBindingPaths = new Dictionary<CustomInputKey, List<string>>();
			foreach (CustomInputKey key in inputActions.Keys)
			{
				InputAction val = inputActions[key];
				List<string> list = new List<string>();
				Enumerator<InputBinding> enumerator2 = val.bindings.GetEnumerator();
				try
				{
					while (enumerator2.MoveNext())
					{
						InputBinding current2 = enumerator2.Current;
						list.Add(((InputBinding)(ref current2)).path);
					}
				}
				finally
				{
					((IDisposable)enumerator2).Dispose();
				}
				defaultBindingPaths[key] = list;
			}
		}

		public void SaveDefaultKeyBindings()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			CustomKeyBindingSaveData customKeyBindingSaveData = new CustomKeyBindingSaveData();
			customKeyBindingSaveData.bindingOverrides = defaultBindingPaths;
			ES3Settings val = new ES3Settings(new Enum[1] { (Enum)(object)(Location)4 });
			val.path = "DefaultCustomKeyBindings.es3";
			ES3.Save<CustomKeyBindingSaveData>("CustomKeyBindings", customKeyBindingSaveData, val);
			ES3.StoreCachedFile(val);
		}

		public void SaveCurrentKeyBindings()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			CustomKeyBindingSaveData customKeyBindingSaveData = new CustomKeyBindingSaveData();
			customKeyBindingSaveData.bindingOverrides = new Dictionary<CustomInputKey, List<string>>();
			foreach (CustomInputKey key in inputActions.Keys)
			{
				InputAction val = inputActions[key];
				List<string> list = new List<string>();
				Enumerator<InputBinding> enumerator2 = val.bindings.GetEnumerator();
				try
				{
					while (enumerator2.MoveNext())
					{
						InputBinding current2 = enumerator2.Current;
						list.Add(string.IsNullOrEmpty(((InputBinding)(ref current2)).overridePath) ? ((InputBinding)(ref current2)).path : ((InputBinding)(ref current2)).overridePath);
					}
				}
				finally
				{
					((IDisposable)enumerator2).Dispose();
				}
				customKeyBindingSaveData.bindingOverrides[key] = list;
			}
			ES3Settings val2 = new ES3Settings(new Enum[1] { (Enum)(object)(Location)4 });
			val2.path = "CurrentCustomKeyBindings.es3";
			ES3.Save<CustomKeyBindingSaveData>("CustomKeyBindings", customKeyBindingSaveData, val2);
			ES3.StoreCachedFile(val2);
			Debug.Log((object)"Custom keybindings saved.");
		}

		public void LoadKeyBindings(string filename)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			try
			{
				ES3Settings val = new ES3Settings(filename, new Enum[1] { (Enum)(object)(Location)0 });
				if (ES3.FileExists(val))
				{
					CustomKeyBindingSaveData saveData = ES3.Load<CustomKeyBindingSaveData>("CustomKeyBindings", val);
					ApplyLoadedKeyBindings(saveData);
				}
				else
				{
					Debug.LogWarning((object)("Custom Keybindings file not found: " + filename));
				}
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Failed to load custom keybindings: " + ex.Message));
			}
		}

		private void ApplyLoadedKeyBindings(CustomKeyBindingSaveData saveData)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			foreach (CustomInputKey key in saveData.bindingOverrides.Keys)
			{
				if (!inputActions.TryGetValue(key, out InputAction value))
				{
					continue;
				}
				List<string> list = saveData.bindingOverrides[key];
				value.Disable();
				for (int i = 0; i < list.Count; i++)
				{
					string text = list[i];
					if (!string.IsNullOrEmpty(text) && value.bindings.Count > i)
					{
						InputActionRebindingExtensions.ApplyBindingOverride(value, i, text);
					}
				}
				value.Enable();
			}
		}

		public void ResetKeyToDefault(CustomInputKey key)
		{
			if (inputActions.TryGetValue(key, out InputAction value))
			{
				List<string> list = defaultBindingPaths[key];
				value.Disable();
				for (int i = 0; i < list.Count; i++)
				{
					InputActionRebindingExtensions.ApplyBindingOverride(value, i, list[i]);
				}
				value.Enable();
			}
			else
			{
				Debug.LogWarning((object)("CustomInputKey not found: " + key));
			}
		}

		public bool KeyDown(CustomInputKey key)
		{
			if (inputActions.TryGetValue(key, out InputAction value))
			{
				return value.WasPressedThisFrame();
			}
			return false;
		}

		public bool KeyUp(CustomInputKey key)
		{
			if (inputActions.TryGetValue(key, out InputAction value))
			{
				return value.WasReleasedThisFrame();
			}
			return false;
		}

		public InputAction? GetAction(CustomInputKey key)
		{
			if (inputActions.TryGetValue(key, out InputAction value))
			{
				return value;
			}
			return null;
		}

		public bool KeyHold(CustomInputKey key)
		{
			if (inputActions.TryGetValue(key, out InputAction value))
			{
				return value.IsPressed();
			}
			return false;
		}

		public void Rebind(CustomInputKey key, string newBinding)
		{
			if (inputActions.TryGetValue(key, out InputAction value))
			{
				InputActionRebindingExtensions.ApplyBindingOverride(value, newBinding, (string)null, (string)null);
			}
		}

		public string GetKeyString(CustomInputKey key)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//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)
			InputAction? action = GetAction(key);
			object obj;
			if (action == null)
			{
				obj = null;
			}
			else
			{
				InputBinding val = action.bindings[0];
				obj = ((InputBinding)(ref val)).effectivePath;
			}
			if (obj == null)
			{
				obj = "";
			}
			return (string)obj;
		}

		public string InputDisplayGet(CustomInputKey _inputKey, MenuCustomKeybind.KeyType _keyType)
		{
			if (_keyType == MenuCustomKeybind.KeyType.InputKey)
			{
				InputAction action = GetAction(_inputKey);
				if (action != null)
				{
					int bindingIndex = 0;
					return InputDisplayGetString(action, bindingIndex);
				}
			}
			return "Unassigned";
		}

		public string InputDisplayGetString(InputAction action, int bindingIndex)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			InputBinding val = action.bindings[bindingIndex];
			string text = InputControlPath.ToHumanReadableString(((InputBinding)(ref val)).effectivePath, (HumanReadableStringOptions)2, (InputControl)null);
			bool flag = false;
			if (text.EndsWith("Scroll/Y"))
			{
				text = "Mouse Scroll";
				flag = true;
			}
			if (((InputBinding)(ref val)).effectivePath.Contains("Mouse") && !flag)
			{
				text = InputDisplayMouseStringGet(((InputBinding)(ref val)).effectivePath);
			}
			return text.ToUpper();
		}

		private string InputDisplayMouseStringGet(string path)
		{
			foreach (KeyValuePair<string, string> mouseMapping in mouseMappings)
			{
				if (path.Contains(mouseMapping.Key))
				{
					return mouseMapping.Value;
				}
			}
			int num = path.IndexOf("button");
			if (num != -1 && num + "button".Length < path.Length)
			{
				string text = path.Substring(num + "button".Length);
				return "Mouse " + text;
			}
			return "Mouse Button";
		}

		public string InputDisplayReplaceTags(string _text)
		{
			foreach (KeyValuePair<string, CustomInputKey> item in tagDictionary)
			{
				string text = "";
				text = InputDisplayGet(item.Value, MenuCustomKeybind.KeyType.InputKey);
				_text = _text.Replace(item.Key, "<u><b>" + text + "</b></u>");
			}
			return _text;
		}

		public void ResetInput()
		{
			InputSystem.ResetHaptics();
			InputSystem.ResetDevice((InputDevice)(object)Keyboard.current, false);
			foreach (KeyValuePair<CustomInputKey, InputAction> inputAction in inputActions)
			{
				inputAction.Value.Reset();
			}
		}

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
				Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
				Debug.Log((object)(((Object)instance).name + " initialized."));
				InitializeInputs();
				StoreDefaultBindings();
			}
			else
			{
				Debug.LogWarning((object)"A duplicate CustomInputManager was detected and destroyed.");
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		private void Start()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			tagDictionary = new Dictionary<string, CustomInputKey>
			{
				{
					"[zoommode]",
					CustomInputKey.ZoomMode
				},
				{
					"[zoommodeincreasefov]",
					CustomInputKey.ZoomModeTuningIncreaseFOV
				},
				{
					"[zoommodedecreasefov]",
					CustomInputKey.ZoomModeTuningDecreaseFOV
				},
				{
					"[laserdot]",
					CustomInputKey.LaserDot
				}
			};
			ES3.DeleteFile("DefaultCustomKeyBindings.es3");
			if (!ES3.FileExists(new ES3Settings("DefaultCustomKeyBindings.es3", new Enum[1] { (Enum)(object)(Location)0 })))
			{
				SaveDefaultKeyBindings();
			}
			if (!ES3.FileExists(new ES3Settings("CurrentCustomKeyBindings.es3", new Enum[1] { (Enum)(object)(Location)0 })))
			{
				SaveCurrentKeyBindings();
			}
			LoadKeyBindings("CurrentCustomKeyBindings.es3");
			Debug.Log((object)(((Object)instance).name + " started."));
		}
	}
	public class CustomPrefabManager : MonoBehaviour
	{
		[Serializable]
		public class PrefabData
		{
			public bool canBeCloned = true;

			public GameObject prefab;

			public bool isReady => canBeCloned && (Object)(object)prefab != (Object)null;

			public PrefabData(GameObject newObj)
			{
				prefab = newObj;
				base..ctor();
			}
		}

		public static CustomPrefabManager instance;

		private List<PrefabData> data = new List<PrefabData>();

		private const string FAILED_PREFAB_NAME = "(Failed Clone Object)";

		private Dictionary<string, string> debugMessages = new Dictionary<string, string>
		{
			{ "FailedGetByName", "Target prefab is not found in the CustomPrefabManager: \"{0}\"" },
			{ "FailedGet", "Failed to get a custom prefab data from the CustomPrefabManager. The reference is not found." },
			{ "FailedAdd", "Failed to add a custom prefab to the CustomPrefabManager. The reference is a null." },
			{ "FailedClone", "The required prefab: \"{0}\" is not found in the CustomPrefabManager. An empty object will be created." },
			{ "DuplicateInstance", "A duplicate CustomPrefabManager was detected and destroyed." }
		};

		public static bool IsAvailable => instance != null;

		private PrefabData? FindByName(string name)
		{
			int count = data.Count;
			if (count == 0)
			{
				return null;
			}
			for (int i = 0; i < count; i++)
			{
				if (((Object)data[i].prefab).name == name)
				{
					return data[i];
				}
			}
			Debug.Log((object)string.Format(debugMessages["FailedGetByName"], name));
			return null;
		}

		public void Add(GameObject objectRefernece)
		{
			if (Object.op_Implicit((Object)(object)objectRefernece))
			{
				PrefabData item = new PrefabData(objectRefernece);
				data.Add(item);
			}
			else
			{
				Debug.LogWarning((object)debugMessages["FailedAdd"]);
			}
		}

		public PrefabData? Get(int index = -1, string name = "")
		{
			if (index >= 0 && index < data.Count)
			{
				return data[index];
			}
			if (!string.IsNullOrEmpty(name))
			{
				return FindByName(name);
			}
			Debug.LogWarning((object)debugMessages["FailedGet"]);
			return null;
		}

		public GameObject Clone(string name = "", bool initialActiveState = true)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			PrefabData prefabData = Get(-1, name);
			if (prefabData != null && prefabData.isReady)
			{
				GameObject val = Object.Instantiate<GameObject>(prefabData.prefab);
				val.SetActive(initialActiveState);
				return val;
			}
			Debug.Log((object)string.Format(debugMessages["FailedClone"], name));
			return new GameObject("(Failed Clone Object)");
		}

		public bool SetActive(string name = "", bool state = true)
		{
			PrefabData prefabData = Get(-1, name);
			if (prefabData != null)
			{
				prefabData.canBeCloned = state;
				return prefabData.canBeCloned;
			}
			Debug.LogWarning((object)debugMessages["FailedGet"]);
			return false;
		}

		public bool Validate(GameObject target)
		{
			return (Object)(object)target != (Object)null && ((Object)target).name != "(Failed Clone Object)";
		}

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
				Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
				Debug.Log((object)(((Object)instance).name + " initialized."));
			}
			else if ((Object)(object)instance != (Object)(object)this)
			{
				Debug.LogWarning((object)debugMessages["DuplicateInstance"]);
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}
	}
	public class MenuCustomKeybind : MonoBehaviour
	{
		public enum KeyType
		{
			InputKey
		}

		[CompilerGenerated]
		private sealed class <LateStart>d__8 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public MenuCustomKeybind <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <LateStart>d__8(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.UpdateBindingDisplay();
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public KeyType keyType;

		public CustomInputKey inputKey;

		private MenuBigButton menuBigButton;

		private MenuPage parentPage;

		private MenuSettingElement settingElement;

		private float actionValue;

		private RebindingOperation rebindingOperation;

		[IteratorStateMachine(typeof(<LateStart>d__8))]
		private IEnumerator LateStart()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LateStart>d__8(0)
			{
				<>4__this = this
			};
		}

		private void UpdateBindingDisplay()
		{
			string text = CustomInputManager.instance.InputDisplayGet(inputKey, keyType);
			menuBigButton.buttonName = text;
			menuBigButton.menuButton.buttonTextString = text;
			((TMP_Text)((Component)menuBigButton.menuButton).GetComponentInChildren<TextMeshProUGUI>()).text = text;
			if (Object.op_Implicit((Object)(object)MenuPageLobby.instance))
			{
				MenuPageLobby.instance.UpdateChatPrompt();
			}
		}

		public void OnClick()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			int num = (int)TSRHelperFunc.GetFieldValue(settingElement, "settingElementID");
			if (parentPage.SettingElementActiveCheckFree(num))
			{
				menuBigButton.state = (State)1;
				parentPage.SettingElementActiveSet(num);
				StartRebinding();
			}
		}

		private void StartRebinding()
		{
			if (keyType != 0)
			{
				return;
			}
			InputAction action = CustomInputManager.instance.GetAction(inputKey);
			if (action != null)
			{
				int num = 0;
				action.Disable();
				rebindingOperation = InputActionRebindingExtensions.PerformInteractiveRebinding(action, num).WithExpectedControlType("Axis").OnComplete((Action<RebindingOperation>)delegate
				{
					//IL_002a: Unknown result type (might be due to invalid IL or missing references)
					action.Enable();
					rebindingOperation.Dispose();
					menuBigButton.state = (State)0;
					UpdateBindingDisplay();
					MenuManager.instance.MenuEffectClick((MenuClickEffectType)1, parentPage, 0.2f, -1f, false);
				})
					.Start();
			}
		}

		private void Start()
		{
			menuBigButton = ((Component)this).GetComponent<MenuBigButton>();
			parentPage = ((Component)this).GetComponentInParent<MenuPage>();
			settingElement = ((Component)this).GetComponent<MenuSettingElement>();
			((MonoBehaviour)this).StartCoroutine(LateStart());
		}
	}
	public class SniperLaserDot : MonoBehaviour
	{
		public enum ToggleMode
		{
			standard,
			force,
			reset
		}

		private bool useInternalInput = false;

		private bool requirementPassed = false;

		internal int playerGrabberPhotonID;

		private PhotonView? photonView;

		private PhysGrabObject? physGrabObject;

		private ItemEquippable? itemEquippable;

		private Transform? laserOrigin;

		private GameObject? laserDot;

		private ItemBattery? itemBattery;

		private float batteryMinimumDrainAmount = 0.5f;

		private float drainRate = 0.1f;

		public bool isEnabled = false;

		public float maxDistance = 100f;

		public LayerMask hitLayers = LayerMask.op_Implicit(0);

		public Sound? soundToggleEnable;

		public Sound? soundToggleDisable;

		private bool isCoolDown = false;

		private static readonly float toggleCoolDownSetter = 0.5f;

		private float toggleCoolDown = 0f;

		private bool key_LaserDot => useInternalInput ? Input.GetKeyDown((KeyCode)120) : CustomInputManager.instance.KeyDown(CustomInputKey.LaserDot);

		private bool isEquipped => (Object)(object)itemEquippable != (Object)null && itemEquippable.IsEquipped();

		private bool isGrabbedByLocalPlayer => (Object)(object)physGrabObject != (Object)null && !SemiFunc.IsMultiplayer() && physGrabObject.playerGrabbing.Count > 0;

		private bool isGrabbedByMeInMultiplayer
		{
			get
			{
				if (!SemiFunc.IsMultiplayer() || (Object)(object)physGrabObject == (Object)null || physGrabObject.playerGrabbing.Count < 1)
				{
					return false;
				}
				if (physGrabObject.grabbed)
				{
					foreach (PhysGrabber item in physGrabObject.playerGrabbing)
					{
						if (item.photonView.IsMine)
						{
							return true;
						}
					}
				}
				return false;
			}
		}

		private bool hasBatteryPower => (Object)(object)itemBattery != (Object)null && itemBattery.batteryLife > 0f;

		private bool isBatteryPowerMoreThanMinimumDrainRate => (Object)(object)itemBattery != (Object)null && itemBattery.batteryLife > batteryMinimumDrainAmount;

		private void ActiveCoolDownTimer()
		{
			toggleCoolDown = toggleCoolDownSetter;
		}

		private void TryDrainBattery(bool state)
		{
			if (state && (Object)(object)itemBattery != (Object)null && isBatteryPowerMoreThanMinimumDrainRate)
			{
				itemBattery.Drain(drainRate);
			}
		}

		private void UpdateLaserDot()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0080: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			if (!requirementPassed)
			{
				return;
			}
			if (!isEnabled)
			{
				visibility(((Component)laserOrigin).gameObject, s: false);
			}
			else if (isEnabled)
			{
				visibility(((Component)laserOrigin).gameObject, s: true);
				Ray val = default(Ray);
				((Ray)(ref val))..ctor(laserOrigin.position, laserOrigin.forward);
				RaycastHit val2 = default(RaycastHit);
				if (Physics.Raycast(val, ref val2, maxDistance, LayerMask.op_Implicit(hitLayers)))
				{
					visibility(laserDot, s: true);
					laserDot.transform.position = ((RaycastHit)(ref val2)).point + ((RaycastHit)(ref val2)).normal * 0.01f;
					laserDot.transform.rotation = Quaternion.LookRotation(((RaycastHit)(ref val2)).normal);
				}
				else
				{
					visibility(laserDot, s: false);
				}
			}
			static void visibility(GameObject g, bool s)
			{
				if ((Object)(object)g != (Object)null && g.activeSelf != s)
				{
					g.SetActive(s);
				}
			}
		}

		private void ToggleLaserDotLogic(int t)
		{
			switch (t)
			{
			case 0:
				isEnabled = hasBatteryPower && !isEnabled;
				break;
			case 1:
				if (!isEnabled)
				{
					isEnabled = (hasBatteryPower ? true : false);
				}
				break;
			case 2:
				if (isEnabled)
				{
					isEnabled = false;
				}
				break;
			}
			TSRHelperFunc.ToggleSound(isEnabled, (Sound[])(object)new Sound[2] { soundToggleDisable, soundToggleEnable }, ((Component)this).gameObject);
		}

		[PunRPC]
		private void ToggleLaserDotRPC(int t)
		{
			ToggleLaserDotLogic(t);
		}

		public void ToggleLaserDot(ToggleMode t = ToggleMode.standard)
		{
			if ((t != ToggleMode.reset || isEnabled) && (t != ToggleMode.force || !isEnabled))
			{
				ActiveCoolDownTimer();
				if (SemiFunc.IsMultiplayer() && (Object)(object)photonView != (Object)null)
				{
					photonView.RPC("ToggleLaserDotRPC", (RpcTarget)0, new object[1] { (int)t });
				}
				else
				{
					ToggleLaserDotLogic((int)t);
				}
			}
		}

		private void Awake()
		{
			if (!CustomInputManager.IsAvailable)
			{
				useInternalInput = true;
			}
			laserOrigin = ((Component)this).transform.Find("Laser Dot");
			Transform? obj = laserOrigin;
			laserDot = ((obj != null) ? ((Component)((Component)obj).transform.GetChild(0)).gameObject : null);
			itemBattery = ((Component)this).GetComponent<ItemBattery>();
			photonView = ((Component)this).GetComponent<PhotonView>();
			physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
			itemEquippable = ((Component)this).GetComponent<ItemEquippable>();
			if ((Object)(object)laserDot != (Object)null && (Object)(object)laserOrigin != (Object)null && (Object)(object)photonView != (Object)null && (Object)(object)physGrabObject != (Object)null && (Object)(object)itemEquippable != (Object)null)
			{
				requirementPassed = true;
			}
		}

		private void Update()
		{
			if (requirementPassed)
			{
				isCoolDown = TSRHelperFunc.CountDown(ref toggleCoolDown);
				if (isEquipped && isEnabled)
				{
					ToggleLaserDot(ToggleMode.reset);
				}
				if ((isGrabbedByLocalPlayer || isGrabbedByMeInMultiplayer) && key_LaserDot && !isCoolDown)
				{
					ToggleLaserDot();
				}
				TryDrainBattery(isEnabled);
				UpdateLaserDot();
			}
		}
	}
	public class ItemSniperGun : MonoBehaviour
	{
		private enum ZoomToggleMode
		{
			standard,
			reset,
			force
		}

		private bool useInternalInput = false;

		public bool UseScrollforZoomTuning = true;

		public float ZoomTuningStrength = 0.1f;

		private bool requirementPassed = false;

		private float cameraZoom_FOV1_min = 5f;

		private float cameraZoom_FOV1_ori = 10f;

		private float[] cameraZoom_FOV = new float[2] { 70f, 10f };

		private ItemGun? itemGun;

		public int AdditionalTarget = 1;

		private ItemEquippable? itemEquippable;

		private ItemBattery? itemBattery;

		private Rigidbody? physGrabObjectCompRb;

		private SniperLaserDot? laserDot;

		internal int playerGrabberPhotonID;

		private PhotonView? photonView;

		private PlayerAvatar? theGrabber;

		private CameraZoom? cameraZoom;

		private PhysGrabObject? physGrabObject;

		private bool hasNewGrabber = false;

		private MapToolController? mapToolController;

		private GameObject? reloadingIndicator;

		private GameObject? zoomTarget;

		private GameObject? mesh;

		private List<GameObject> toggledObjectList = new List<GameObject>();

		private Dictionary<string, (string message, bool printed)> debugMessages = new Dictionary<string, (string, bool)>
		{
			{
				"SniperReady",
				("Sniper Rifle is ready.", false)
			},
			{
				"SkipSpreadAdjustment",
				("This weapon has no random spread; the suppression will be skipped.", false)
			},
			{
				"Pirecing",
				("Piercing bullet can only be shoot in the zoom mode.", false)
			}
		};

		public bool zoomMode = false;

		private float aimVerticalAdjust = -5.4f;

		private float aimVerticalOffset_ori = -1f;

		private float torqueMultiplierAdjust = 2f;

		private float torqueMultiplier_ori = 1f;

		private float gunRandomSpread_ori = -1f;

		private int[] enemyHurtDamage = new int[2] { 250, 355 };

		private bool rb_overrided = false;

		[Range(0f, 1f)]
		public float gunRandomSpreadSurpress = 0f;

		public Sound? soundToggleZoomModeEnable;

		public Sound? soundToggleZoomModeDisable;

		public Sound? soundToggleZoomModeUnavailable;

		public Sound? soundTuning;

		private bool key_FOVPlus => useInternalInput ? Input.GetKeyDown((KeyCode)261) : CustomInputManager.instance.KeyDown(CustomInputKey.ZoomModeTuningIncreaseFOV);

		private bool key_FOVMinus => useInternalInput ? Input.GetKeyDown((KeyCode)264) : CustomInputManager.instance.KeyDown(CustomInputKey.ZoomModeTuningDecreaseFOV);

		private bool key_ZoomMode => useInternalInput ? Input.GetKeyDown((KeyCode)122) : CustomInputManager.instance.KeyDown(CustomInputKey.ZoomMode);

		private bool isEquipped => (Object)(object)itemEquippable != (Object)null && itemEquippable.IsEquipped();

		private bool hasBatteryPower => (Object)(object)itemBattery == (Object)null || ((Object)(object)itemBattery != (Object)null && itemBattery.batteryLife > 0f);

		private bool isGrabbedByLocalPlayer => (Object)(object)physGrabObject != (Object)null && !SemiFunc.IsMultiplayer() && physGrabObject.playerGrabbing.Count > 0;

		private bool isGrabbedByMultiple => (Object)(object)physGrabObject != (Object)null && physGrabObject.playerGrabbing.Count > 1;

		private bool isGrabbedByMeOnly => (Object)(object)physGrabObject != (Object)null && (Object)(object)theGrabber != (Object)null && theGrabber.photonView.IsMine && !isGrabbedByMultiple;

		private bool hasGrabberInfo => (Object)(object)theGrabber != (Object)null && (Object)(object)mapToolController != (Object)null && (Object)(object)cameraZoom != (Object)null;

		private bool hasMultiplayerGrabberInfo => hasGrabberInfo && playerGrabberPhotonID != -1;

		private bool isGrabberMapActive => (Object)(object)mapToolController != (Object)null && TSRHelperFunc.GetFieldValueAsBool(mapToolController, "Active");

		public bool IsReloading
		{
			get
			{
				if ((Object)(object)itemGun == (Object)null)
				{
					return false;
				}
				string fieldValueAsString = TSRHelperFunc.GetFieldValueAsString(itemGun, "stateCurrent");
				if (fieldValueAsString == null)
				{
					return false;
				}
				return fieldValueAsString == "Reloading";
			}
		}

		public bool EnterReloading
		{
			get
			{
				if ((Object)(object)itemGun == (Object)null)
				{
					return false;
				}
				string fieldValueAsString = TSRHelperFunc.GetFieldValueAsString(itemGun, "stateCurrent");
				string fieldValueAsString2 = TSRHelperFunc.GetFieldValueAsString(itemGun, "statePrev");
				if (fieldValueAsString == null || fieldValueAsString2 == null)
				{
					return false;
				}
				return fieldValueAsString != fieldValueAsString2 && fieldValueAsString == "Reloading";
			}
		}

		private void PrintOneTimeMessages(string key)
		{
			(string, bool) tuple = debugMessages[key];
			if (!tuple.Item2)
			{
				debugMessages[key] = (tuple.Item1, true);
				Debug.Log((object)tuple.Item1);
			}
		}

		public void ShootPiercingBullet()
		{
			//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)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)itemGun == (Object)null)
			{
				return;
			}
			if (zoomMode && AdditionalTarget > 0)
			{
				Vector3[] array = (Vector3[])(object)new Vector3[1] { itemGun.gunMuzzle.position };
				bool flag = false;
				Vector3 val = itemGun.gunMuzzle.forward;
				if (itemGun.gunRandomSpread > 0f)
				{
					float num = Random.Range(0f, itemGun.gunRandomSpread / 2f);
					float num2 = Random.Range(0f, 360f);
					Vector3 val2 = Vector3.Cross(val, Random.onUnitSphere);
					Vector3 normalized = ((Vector3)(ref val2)).normalized;
					Quaternion val3 = Quaternion.AngleAxis(num, normalized);
					val2 = Quaternion.AngleAxis(num2, val) * val3 * val;
					val = ((Vector3)(ref val2)).normalized;
				}
				int num3 = LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()) + LayerMask.GetMask(new string[1] { "Enemy" });
				Ray val4 = default(Ray);
				((Ray)(ref val4))..ctor(itemGun.gunMuzzle.position, val);
				RaycastHit[] array2 = Physics.RaycastAll(val4, itemGun.gunRange, num3);
				Array.Sort(array2, (RaycastHit x, RaycastHit y) => ((RaycastHit)(ref x)).distance.CompareTo(((RaycastHit)(ref y)).distance));
				if (array2.Length > 1)
				{
					int num4 = ((AdditionalTarget + 1 > array2.Length) ? array2.Length : (AdditionalTarget + 1));
					array = (Vector3[])(object)new Vector3[num4];
					for (int i = 1; i < num4; i++)
					{
						array[i] = ((RaycastHit)(ref array2[i])).point;
					}
					flag = true;
				}
				if (!SemiFunc.IsMasterClientOrSingleplayer())
				{
					return;
				}
				if (SemiFunc.IsMultiplayer())
				{
					for (int j = 1; j < array.Length; j++)
					{
						photonView.RPC("ShootBulletRPC", (RpcTarget)0, new object[2]
						{
							array[j],
							flag
						});
					}
				}
				else
				{
					for (int k = 1; k < array.Length; k++)
					{
						itemGun.ShootBulletRPC(array[k], flag, default(PhotonMessageInfo));
					}
				}
			}
			else if (!zoomMode && AdditionalTarget > 0)
			{
				PrintOneTimeMessages("PenetrateBullet");
			}
		}

		private void OverrideFOV()
		{
			if ((Object)(object)cameraZoom != (Object)null)
			{
				cameraZoom.OverrideZoomSet(cameraZoom_FOV[1], 0.05f, 2f, 2f, zoomTarget ?? ((Component)this).gameObject, 50);
			}
		}

		private void HideMesh(bool state)
		{
			if (!((Object)(object)mesh == (Object)null))
			{
				if (mesh.activeSelf && state)
				{
					mesh.SetActive(false);
				}
				else
				{
					mesh.SetActive(true);
				}
			}
		}

		private void ToggleGameObjectLogic(bool state, int index)
		{
			if (toggledObjectList != null && !((Object)(object)toggledObjectList[index] == (Object)null))
			{
				toggledObjectList[index].SetActive(state);
			}
		}

		[PunRPC]
		private void ToggleGameObjectRPC(bool state, int index)
		{
			ToggleGameObjectLogic(state, index);
		}

		private void ToggleGameObject(bool state, int index, bool globalSignal = false)
		{
			if (toggledObjectList != null && !((Object)(object)toggledObjectList[index] == (Object)null))
			{
				if (globalSignal && SemiFunc.IsMultiplayer() && (Object)(object)photonView != (Object)null)
				{
					photonView.RPC("ToggleGameObjectRPC", (RpcTarget)0, new object[2] { state, index });
				}
				else
				{
					ToggleGameObjectLogic(state, index);
				}
			}
		}

		private void UpdateBulletPrefabHurtDamage(bool increased)
		{
			if (!((Object)(object)itemGun == (Object)null))
			{
				HurtCollider component = ((Component)itemGun.bulletPrefab.transform.Find("Hurt Collider")).GetComponent<HurtCollider>();
				component.enemyDamage = (increased ? enemyHurtDamage[1] : enemyHurtDamage[0]);
				component.playerDamage = (increased ? enemyHurtDamage[1] : enemyHurtDamage[0]);
			}
		}

		private void ApplyFocusMode(bool state)
		{
			if (!((Object)(object)itemGun == (Object)null))
			{
				float gunRandomSpread = itemGun.gunRandomSpread;
				float aimVerticalOffset = itemGun.aimVerticalOffset;
				float torqueMultiplier = itemGun.torqueMultiplier;
				if (gunRandomSpread > 0f)
				{
					StateChooser(state, gunRandomSpread, new float[2]
					{
						gunRandomSpread_ori,
						gunRandomSpread_ori * gunRandomSpreadSurpress
					}, ref itemGun.gunRandomSpread);
				}
				else
				{
					PrintOneTimeMessages("SkipSpreadAdjustment");
				}
				StateChooser(state, aimVerticalOffset, new float[2] { aimVerticalOffset_ori, aimVerticalAdjust }, ref itemGun.aimVerticalOffset);
				StateChooser(state, torqueMultiplier, new float[2] { torqueMultiplier_ori, torqueMultiplierAdjust }, ref itemGun.torqueMultiplier);
			}
			static void StateChooser(bool b, float v_cur, float[] v, ref float v_toAssign)
			{
				if (b && v_cur != v[1])
				{
					v_toAssign = v[1];
				}
				else if (!b && v_cur != v[0])
				{
					v_toAssign = v[0];
				}
			}
		}

		private void ApplyStableGrab(bool state)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)physGrabObject == (Object)null)
			{
				return;
			}
			if (state)
			{
				if (!SemiFunc.IsMultiplayer() || isGrabbedByMeOnly)
				{
					if ((Object)(object)physGrabObjectCompRb != (Object)null)
					{
						physGrabObjectCompRb.rotation = Quaternion.Slerp(physGrabObjectCompRb.rotation, TSRHelperFunc.GetFieldValueAsQuaternion(PlayerController.instance.cameraAim, "playerAim"), 10f * Time.fixedDeltaTime);
						physGrabObjectCompRb.constraints = (RigidbodyConstraints)80;
					}
					physGrabObject.OverrideMass(Mathf.Max(SemiFunc.PlayerAvatarLocal().physGrabber.grabStrength / 2f, 0.5f), 0.1f);
					physGrabObject.OverrideGrabStrength(2f, 0.1f);
					physGrabObject.OverrideTorqueStrength(5f, 0.1f);
					physGrabObject.OverrideDrag(2f, 0.1f);
					physGrabObject.OverrideAngularDrag(10f, 0.1f);
				}
			}
			else if ((Object)(object)physGrabObjectCompRb != (Object)null)
			{
				physGrabObjectCompRb.constraints = (RigidbodyConstraints)0;
				rb_overrided = false;
			}
		}

		private void ClearGrabberInfo()
		{
			if (!((Object)(object)mapToolController == (Object)null) || !((Object)(object)cameraZoom == (Object)null) || !((Object)(object)theGrabber == (Object)null))
			{
				cameraZoom = null;
				mapToolController = null;
				theGrabber = null;
			}
		}

		private void UpdateGrabberInfo()
		{
			if ((Object)(object)physGrabObject == (Object)null || physGrabObject.playerGrabbing.Count < 1)
			{
				return;
			}
			if (isGrabbedByLocalPlayer)
			{
				TryAssignNewGrabber(physGrabObject.playerGrabbing[physGrabObject.playerGrabbing.Count - 1].playerAvatar);
				return;
			}
			PlayerAvatar playerAvatar = physGrabObject.playerGrabbing[physGrabObject.playerGrabbing.Count - 1].playerAvatar;
			if (!((Object)(object)playerAvatar == (Object)null))
			{
				TryAssignNewGrabber(playerAvatar);
			}
			bool SetGrabberInfo(PlayerAvatar g)
			{
				if ((Object)(object)g != (Object)null)
				{
					theGrabber = g;
					mapToolController = theGrabber?.mapToolController;
					cameraZoom = CameraZoom.Instance;
					playerGrabberPhotonID = (SemiFunc.IsMultiplayer() ? g.photonView.ViewID : (-1));
					return true;
				}
				return false;
			}
			bool TryAssignNewGrabber(PlayerAvatar grabber)
			{
				if ((Object)(object)grabber == (Object)null)
				{
					return false;
				}
				if (!SemiFunc.IsMultiplayer())
				{
					if (hasGrabberInfo)
					{
						return false;
					}
					if (!hasGrabberInfo)
					{
						return SetGrabberInfo(grabber);
					}
				}
				else if ((hasMultiplayerGrabberInfo && grabber.photonView.ViewID != playerGrabberPhotonID) || !hasGrabberInfo)
				{
					hasNewGrabber = true;
					return SetGrabberInfo(grabber);
				}
				return false;
			}
		}

		private bool IsBeingGrabbed()
		{
			if ((Object)(object)physGrabObject == (Object)null)
			{
				return false;
			}
			bool grabbed = physGrabObject.grabbed;
			if (grabbed)
			{
				UpdateGrabberInfo();
			}
			if (!grabbed)
			{
				ClearGrabberInfo();
			}
			return grabbed;
		}

		private void ResetTargetFOV()
		{
			if (cameraZoom_FOV[1] != cameraZoom_FOV1_ori)
			{
				cameraZoom_FOV[1] = cameraZoom_FOV1_ori;
			}
		}

		private void UpdateTargetFOV(float v)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			float num = cameraZoom_FOV[1] + v;
			cameraZoom_FOV[1] = ((!(num < cameraZoom_FOV1_min)) ? num : ((num > cameraZoom_FOV[0]) ? cameraZoom_FOV[0] : num));
			Sound? obj = soundTuning;
			if (obj != null)
			{
				obj.Play(((Component)this).gameObject.transform.position, 1f, 1f, 1f, 1f);
			}
		}

		private int GetMouseScrollEvent()
		{
			float scrollY = InputManager.instance.GetScrollY();
			return (scrollY > 0f) ? 1 : ((scrollY < 0f) ? (-1) : 0);
		}

		private void MonitorZoomTuningEvent()
		{
			if (!SemiFunc.IsMultiplayer() || isGrabbedByMeOnly)
			{
				switch (checkEvent())
				{
				case 0:
					break;
				case 1:
					UpdateTargetFOV(0f - ZoomTuningStrength);
					break;
				case -1:
					UpdateTargetFOV(ZoomTuningStrength);
					break;
				}
			}
			int checkEvent()
			{
				if (UseScrollforZoomTuning)
				{
					return GetMouseScrollEvent();
				}
				if (key_FOVPlus)
				{
					return -1;
				}
				if (key_FOVMinus)
				{
					return 1;
				}
				return 0;
			}
		}

		private void MoniterReloadingState()
		{
			if ((Object)(object)reloadingIndicator != (Object)null)
			{
				if (IsReloading && !reloadingIndicator.activeSelf)
				{
					reloadingIndicator.SetActive(true);
				}
				if (!IsReloading && reloadingIndicator.activeSelf)
				{
					reloadingIndicator.SetActive(false);
				}
			}
		}

		private bool CheckPassees()
		{
			bool flag = (Object)(object)itemGun != (Object)null;
			bool flag2 = (Object)(object)itemEquippable != (Object)null;
			bool flag3 = (Object)(object)physGrabObject != (Object)null && (Object)(object)physGrabObjectCompRb != (Object)null;
			bool flag4 = (Object)(object)photonView != (Object)null;
			requirementPassed = flag && flag2 && flag3 && flag4;
			return requirementPassed;
		}

		private void ToggleZoom(ZoomToggleMode z = ZoomToggleMode.standard)
		{
			if (!SemiFunc.IsMultiplayer() || isGrabbedByMeOnly)
			{
				ToggleZoomLogic(z);
			}
			else if (z == ZoomToggleMode.reset)
			{
				ToggleZoomLogic(z);
			}
			void ToggleZoomLogic(ZoomToggleMode z = ZoomToggleMode.standard)
			{
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				switch (z)
				{
				case ZoomToggleMode.standard:
					if (hasBatteryPower)
					{
						toggle(!zoomMode);
					}
					else
					{
						zoomMode = false;
						if (soundToggleZoomModeUnavailable != null)
						{
							soundToggleZoomModeUnavailable.Play(((Component)this).gameObject.transform.position, 1f, 1f, 1f, 1f);
						}
					}
					break;
				case ZoomToggleMode.reset:
					if (zoomMode)
					{
						toggle(t: false);
					}
					break;
				case ZoomToggleMode.force:
					if (!zoomMode)
					{
						toggle(t: true);
					}
					break;
				}
				if (hasNewGrabber)
				{
					hasNewGrabber = false;
				}
			}
			void toggle(bool t)
			{
				if (zoomMode != t)
				{
					zoomMode = t;
					ApplyFocusMode(t);
					UpdateBulletPrefabHurtDamage(t);
					HideMesh(t);
					ToggleGameObject(t, 0, globalSignal: true);
					if (!t)
					{
						ResetTargetFOV();
					}
					TSRHelperFunc.ToggleSound(t, (Sound[])(object)new Sound[2] { soundToggleZoomModeDisable, soundToggleZoomModeEnable }, ((Component)this).gameObject);
				}
			}
		}

		private void Awake()
		{
			if (!CustomInputManager.IsAvailable)
			{
				useInternalInput = true;
			}
			laserDot = ((Component)this).GetComponent<SniperLaserDot>();
			itemGun = ((Component)this).GetComponent<ItemGun>();
			itemEquippable = ((Component)this).GetComponent<ItemEquippable>();
			physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
			itemBattery = ((Component)this).GetComponent<ItemBattery>();
			photonView = ((Component)this).GetComponent<PhotonView>();
			if ((Object)(object)laserDot != (Object)null)
			{
				laserDot.maxDistance = (((Object)(object)itemGun == (Object)null) ? laserDot.maxDistance : itemGun.gunRange);
			}
			if ((Object)(object)itemGun != (Object)null)
			{
				gunRandomSpread_ori = itemGun.gunRandomSpread;
				aimVerticalOffset_ori = itemGun.aimVerticalOffset;
				torqueMultiplier_ori = itemGun.torqueMultiplier;
			}
			if ((Object)(object)physGrabObject != (Object)null)
			{
				physGrabObjectCompRb = physGrabObject.rb;
			}
			zoomTarget = ((Component)((Component)this).gameObject.transform.Find("Focus Object")).gameObject;
			reloadingIndicator = ((Component)((Component)this).transform.Find("Item Reloading")).gameObject;
			mesh = ((Component)((Component)this).gameObject.transform.Find("Mesh")).gameObject;
			toggledObjectList.Add(((Component)((Component)this).gameObject.transform.Find("Scope Light")).gameObject);
			if (CheckPassees())
			{
				PrintOneTimeMessages("SniperReady");
			}
		}

		private void FixedUpdate()
		{
			if (requirementPassed)
			{
				ApplyStableGrab(zoomMode);
			}
		}

		private void Update()
		{
			if (!requirementPassed)
			{
				return;
			}
			MoniterReloadingState();
			bool flag = IsBeingGrabbed();
			if (!flag && zoomMode)
			{
				ToggleZoom(ZoomToggleMode.reset);
			}
			else
			{
				if (!flag)
				{
					return;
				}
				if (hasNewGrabber || isGrabbedByMultiple)
				{
					ToggleZoom(ZoomToggleMode.reset);
					return;
				}
				if (zoomMode)
				{
					if (SemiFunc.InputDown((InputKey)2))
					{
						ShootPiercingBullet();
					}
					if (SemiFunc.InputDown((InputKey)8) || isEquipped || isGrabberMapActive || !hasBatteryPower)
					{
						ToggleZoom(ZoomToggleMode.reset);
						return;
					}
					MonitorZoomTuningEvent();
					OverrideFOV();
				}
				if (key_ZoomMode)
				{
					ToggleZoom();
				}
			}
		}
	}
	[BepInPlugin("Wakaura.TheSniperRifle", "TheSniperRifle", "0.6.0")]
	public class TheSniperRifle : BaseUnityPlugin
	{
		private const string UI_BUNDLE = "thesniperrifle_customui.ab";

		private string[] bundleNameOnDisk = new string[1] { "thesniperrifle_customui.ab" };

		private Dictionary<string, AssetBundle> bundleMap = new Dictionary<string, AssetBundle>();

		private Dictionary<string, string> prefabsToBeLoaded = new Dictionary<string, string>
		{
			{ "Header Custom", "thesniperrifle_customui.ab" },
			{ "Big Button Custom - Sniper Rifle Zoom", "thesniperrifle_customui.ab" },
			{ "Big Button Custom - Sniper Rifle LaserDot", "thesniperrifle_customui.ab" }
		};

		private List<GameObject> prefabList = new List<GameObject>();

		internal static TheSniperRifle Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private bool hasCustomAssetBundleLoaded => bundleMap != null && bundleMap.Count > 0;

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded.");
		}

		private void Start()
		{
			bundleMap = LoadAssetBundles(bundleNameOnDisk);
			if (hasCustomAssetBundleLoaded)
			{
				prefabList = LoadPrefabsInAssetBundles();
			}
			InitCustomPrefabManager(prefabList);
			InitCustomGlobalComponent<CustomInputManager>();
			InitCustomGlobalComponent<CustomSettingManager>();
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private Dictionary<string, AssetBundle> LoadAssetBundles(string[] bundleNames)
		{
			Dictionary<string, AssetBundle> dictionary = new Dictionary<string, AssetBundle>();
			for (int i = 0; i < bundleNames.Length; i++)
			{
				string text = FindBundleRecursive(Paths.PluginPath, bundleNames[i]);
				AssetBundle val = AssetBundle.LoadFromFile(text);
				if ((Object)(object)val == (Object)null)
				{
					Logger.LogError((object)("Failed to load " + bundleNames[i]));
					continue;
				}
				dictionary.Add(bundleNames[i], val);
				Logger.LogInfo((object)("AssetBundle: " + bundleNames[i] + " is loaded."));
			}
			if (dictionary.Count > 0)
			{
				return dictionary;
			}
			Logger.LogInfo((object)"No assetbundle to be loaded.");
			return dictionary;
		}

		private AssetBundle? GetAssetBundle(int index = -1, string name = "")
		{
			if (hasCustomAssetBundleLoaded)
			{
				if (index >= 0 && index < bundleNameOnDisk.Length)
				{
					return bundleMap[bundleNameOnDisk[index]];
				}
				if (bundleMap.TryGetValue(name, out AssetBundle value))
				{
					return value;
				}
				return null;
			}
			return null;
		}

		private Component? InitCustomGlobalComponent<T>() where T : Component
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			if ((Object)(object)Object.FindObjectOfType<T>() == (Object)null)
			{
				GameObject val = new GameObject(typeof(T).Name);
				Component result = (Component)(object)val.AddComponent<T>();
				Object.DontDestroyOnLoad((Object)(object)val);
				Logger.LogInfo((object)(typeof(T).Name + " component added."));
				return result;
			}
			Logger.LogInfo((object)(typeof(T).Name + " component already exists. Skipping."));
			return null;
		}

		private void InitCustomPrefabManager(List<GameObject>? prefabsToBeInitialized = null)
		{
			CustomPrefabManager customPrefabManager = InitCustomGlobalComponent<CustomPrefabManager>() as CustomPrefabManager;
			if ((Object)(object)customPrefabManager != (Object)null)
			{
				if (prefabsToBeInitialized != null && prefabsToBeInitialized.Count > 0)
				{
					for (int i = 0; i < prefabsToBeInitialized.Count; i++)
					{
						customPrefabManager.Add(prefabsToBeInitialized[i]);
					}
				}
			}
			else
			{
				Logger.LogInfo((object)"CustomPrefabManager is null, cannot load prefabs into the PrefabData list.");
			}
		}

		private List<GameObject> LoadPrefabsInAssetBundles()
		{
			List<GameObject> list = new List<GameObject>();
			if (hasCustomAssetBundleLoaded)
			{
				foreach (KeyValuePair<string, string> item in prefabsToBeLoaded)
				{
					item.Deconstruct(out var key, out var value);
					string text = key;
					string text2 = value;
					AssetBundle assetBundle = GetAssetBundle(-1, text2);
					if ((Object)(object)assetBundle != (Object)null)
					{
						GameObject val = assetBundle.LoadAsset<GameObject>(text);
						if ((Object)(object)val != (Object)null)
						{
							list.Add(val);
						}
						else
						{
							Logger.LogWarning((object)("Prefab " + text + " not found in bundle " + text2));
						}
					}
				}
			}
			return list;
		}

		private string FindBundleRecursive(string rootDir, string bundleFileName)
		{
			try
			{
				string[] files = Directory.GetFiles(rootDir, bundleFileName, SearchOption.AllDirectories);
				return files.FirstOrDefault();
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Error while searching for AssetBundle: " + ex.Message));
				return "";
			}
		}
	}
	[HarmonyPatch(typeof(MenuManager), "PageOpen")]
	internal class Patch_MenuManager_PageOpen
	{
		[HarmonyPostfix]
		private static void Postfix(MenuPageIndex menuPageIndex, bool addedPageOnTop, MenuPage __result)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Invalid comparison between Unknown and I4
			if ((int)menuPageIndex != 6)
			{
				return;
			}
			if ((Object)(object)__result == (Object)null)
			{
				Debug.LogWarning((object)"PageOpen returned null for SettingsControls.");
				return;
			}
			if (!CustomPrefabManager.IsAvailable)
			{
				Debug.LogWarning((object)"CustomPrefabManager is null, cannot inject.");
				return;
			}
			Transform val = ((Component)__result).transform.Find("Scroll Box/Mask/Scroller");
			Transform lastItem2 = null;
			if ((Object)(object)val != (Object)null && val.childCount > 0)
			{
				lastItem2 = val.GetChild(val.childCount - 1);
			}
			lastItem2 = createAndplaceAtLast("Header Custom", val, lastItem2, isHeader: true);
			lastItem2 = createAndplaceAtLast("Big Button Custom - Sniper Rifle Zoom", val, lastItem2, isHeader: false, 12f);
			createAndplaceAtLast("Big Button Custom - Sniper Rifle LaserDot", val, lastItem2);
			static Transform createAndplaceAtLast(string prefabNameToClone, Transform root, Transform lastItem, bool isHeader = false, float spaceAdjust = 0f)
			{
				//IL_005f: 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_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a1: 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)
				GameObject val2 = CustomPrefabManager.instance.Clone(prefabNameToClone, initialActiveState: false);
				Transform transform = val2.transform;
				if (!CustomPrefabManager.instance.Validate(val2))
				{
					return transform;
				}
				float num = 62.8f;
				float num2 = 42f;
				if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)root))
				{
					transform.SetParent(root, false);
					transform.localPosition = Vector3.zero;
					transform.localScale = Vector3.one;
					if ((Object)(object)lastItem != (Object)null)
					{
						transform.localPosition = new Vector3(isHeader ? num : 0f, lastItem.localPosition.y - num2 - spaceAdjust, lastItem.localPosition.z);
					}
				}
				MenuBigButton val3 = default(MenuBigButton);
				if (val2.TryGetComponent<MenuBigButton>(ref val3))
				{
					MenuButton menuButton = val3.menuButton;
					if ((Object)(object)menuButton != (Object)null)
					{
						TSRHelperFunc.SetFieldValue(menuButton, "parentPage", ((Component)menuButton).GetComponentInParent<MenuPage>());
					}
				}
				val2.SetActive(true);
				return transform;
			}
		}
	}
	[HarmonyPatch(typeof(MenuPageSettingsControls), "SaveControls")]
	internal class Patch_MenuPageSettingsControls_SaveControls
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			if (!CustomInputManager.IsAvailable)
			{
				Debug.LogWarning((object)"CustomInputManager is null, cannot save settings.");
			}
			else
			{
				CustomInputManager.instance.SaveCurrentKeyBindings();
			}
		}
	}
	[HarmonyPatch(typeof(MenuPageSettingsControls), "ResetControls")]
	internal class Patch_MenuPageSettingsControls_ResetControls
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			if (!CustomInputManager.IsAvailable)
			{
				Debug.LogWarning((object)"CustomInputManager is null, cannot reset settings.");
			}
			else
			{
				CustomInputManager.instance.LoadKeyBindings("DefaultCustomKeyBindings.es3");
			}
		}
	}
	public static class TSRHelperFunc
	{
		public static (Component, Type)? CollectComponent(GameObject g, string compName)
		{
			Component component = g.GetComponent(compName);
			if ((Object)(object)component != (Object)null)
			{
				return (component, ((object)component).GetType());
			}
			return null;
		}

		public static (GameObject, Type)? TryGetByType(string monobehaviour)
		{
			Type type = Type.GetType(monobehaviour);
			if (type == null)
			{
				Debug.LogWarning((object)("Type " + monobehaviour + " not found."));
				return null;
			}
			Object val = Object.FindObjectOfType(type);
			if (val != (Object)null)
			{
				MonoBehaviour val2 = (MonoBehaviour)(object)((val is MonoBehaviour) ? val : null);
				if (val2 != null)
				{
					GameObject gameObject = ((Component)val2).gameObject;
					Debug.Log((object)(monobehaviour + " instance found via reflection."));
					return (gameObject, ((object)val).GetType());
				}
			}
			Debug.LogWarning((object)("No instance of " + monobehaviour + " found in the scene."));
			return null;
		}

		public static object? GetFieldValue(object o, string fieldname)
		{
			FieldInfo field = o.GetType().GetField(fieldname, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field == null)
			{
				return null;
			}
			object value = field.GetValue(o);
			if (value == null)
			{
				return null;
			}
			return value;
		}

		public static void SetFieldValue(object o, string fieldname, object value)
		{
			FieldInfo field = o.GetType().GetField(fieldname, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field == null)
			{
				Debug.LogWarning((object)("The field does not present in the target object \"" + o.ToString() + "\": " + fieldname));
			}
			else
			{
				field.SetValue(o, value);
			}
		}

		public static string? GetFieldValueAsString(object o, string fieldname)
		{
			object fieldValue = GetFieldValue(o, fieldname);
			if (fieldValue == null)
			{
				return null;
			}
			return fieldValue?.ToString();
		}

		public static bool GetFieldValueAsBool(object o, string fieldname)
		{
			object fieldValue = GetFieldValue(o, fieldname);
			if (fieldValue == null)
			{
				return false;
			}
			return (bool)fieldValue;
		}

		public static Quaternion GetFieldValueAsQuaternion(object o, string fieldname)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			object fieldValue = GetFieldValue(o, fieldname);
			if (fieldValue == null)
			{
				return Quaternion.identity;
			}
			return (Quaternion)fieldValue;
		}

		public static void ToggleSound(bool state, Sound[] sounds, GameObject playLoc)
		{
			//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)
			if (sounds != null)
			{
				if (!state)
				{
					sounds[0].Play(playLoc.transform.position, 1f, 1f, 1f, 1f);
				}
				else if (state)
				{
					sounds[1].Play(playLoc.transform.position, 1f, 1f, 1f, 1f);
				}
			}
		}

		public static bool CountDown(ref float t)
		{
			if (t > 0f)
			{
				t -= Time.deltaTime;
				return true;
			}
			if (t < 0f)
			{
				t = 0f;
				return false;
			}
			return false;
		}

		public static bool CheckAvailability(object o, bool silentCheck = false)
		{
			bool flag = o == null;
			bool flag2 = o == null;
			string text = "";
			text = ((!flag) ? $"Object is available at {Time.time}\nObject type: {o.GetType().Name}\nObject ToString: '{o.ToString()}'\nIs reference null: {flag2}" : $"Object is null (==) at {Time.time}\nIs reference null: {flag2}");
			text += $"\nThread: {Thread.CurrentThread.ManagedThreadId}";
			if (!silentCheck)
			{
				Debug.LogWarning((object)text);
			}
			return !flag2;
		}
	}
}