Decompiled source of ReloadTriggerWellEnlarger v1.1.0

Niko666.ReloadTriggerWellEnlarger.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("Niko666")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Makes reload trigger zones larger so you can reload with ease without enabling Easy Mag Loading.")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("Niko666.ReloadTriggerWellEnlarger")]
[assembly: AssemblyTitle("ReloadTriggerWellEnlarger")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace Niko666
{
	[BepInProcess("h3vr.exe")]
	[BepInPlugin("Niko666.ReloadTriggerWellEnlarger", "ReloadTriggerWellEnlarger", "1.1.0")]
	public class ReloadTriggerWellEnlarger : BaseUnityPlugin
	{
		internal struct ConfigSnapshot
		{
			public bool Enabled;

			public float ScaleX;

			public float ScaleY;

			public float ScaleZ;

			public float RescanInterval;

			public bool ShowTriggerColliders;

			public bool ShowUnmanagedWells;

			public float DebugAlpha;

			public bool Verbose;
		}

		public class WeaponSettings
		{
			public float? ScaleXMultiplyAmount { get; set; }

			public float? ScaleYMultiplyAmount { get; set; }

			public float? ScaleZMultiplyAmount { get; set; }

			public bool? Enabled { get; set; }
		}

		public class WeaponOverrideFile
		{
			public Dictionary<string, WeaponSettings> WeaponOverrides { get; set; }
		}

		public ConfigEntry<bool> configEnabled;

		public ConfigEntry<float> configScaleXMultiplyAmount;

		public ConfigEntry<float> configScaleYMultiplyAmount;

		public ConfigEntry<float> configScaleZMultiplyAmount;

		public ConfigEntry<float> configRescanIntervalSeconds;

		public ConfigEntry<bool> configShowTriggerColliders;

		public ConfigEntry<bool> configShowUnmanagedWells;

		public ConfigEntry<float> configTriggerAlpha;

		public ConfigEntry<bool> configVerboseLogging;

		private const float DefaultScaleXMultiplyAmount = 1.1f;

		private const float DefaultScaleYMultiplyAmount = 2f;

		private const float DefaultScaleZMultiplyAmount = 1.1f;

		private const float DefaultTriggerAlpha = 0.35f;

		private const float DefaultRescanIntervalSeconds = 3f;

		internal static ConfigSnapshot Cfg;

		private static bool _applyPending;

		private static string _configFilePath;

		private static long _configFileStamp = -1L;

		private float _lastFileCheck;

		private float _lastSweep;

		private int _updateErrors;

		public static Dictionary<string, WeaponSettings> WeaponOverrides = new Dictionary<string, WeaponSettings>(StringComparer.OrdinalIgnoreCase);

		private static string _jsonConfigPath;

		private static long _jsonConfigStamp = -1L;

		public const string Id = "Niko666.ReloadTriggerWellEnlarger";

		public static ReloadTriggerWellEnlarger Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		public static string Name => "ReloadTriggerWellEnlarger";

		public static string Version => "1.1.0";

		private void BindConfig()
		{
			configEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master switch. Off: every reload well this mod took over is put back to the size the game shipped, and no well is touched. Takes effect immediately, no scene reload or restart.");
			configScaleXMultiplyAmount = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ScaleXMultiplyAmount", 1.1f, "Multiply the reload trigger zone on X-axis (width/radius). 1 being weapons' defaults.");
			configScaleYMultiplyAmount = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ScaleYMultiplyAmount", 2f, "Multiply the reload trigger zone on Y-axis (height, most effective). 1 being weapons' defaults.");
			configScaleZMultiplyAmount = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ScaleZMultiplyAmount", 1.1f, "Multiply the reload trigger zone on Z-axis (length along the muzzle). 1 being weapons' defaults.");
			configRescanIntervalSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RescanIntervalSeconds", 3f, "How often (in seconds) the scene is swept for reload wells, so a well the game only switches on later (a modular part, an attachment, anything spawned after its gun) is picked up on its own. 0 turns the rescan off; values under 0.5 are treated as 0.5. A sweep only rewrites values that are already worked out, so the cost is a lookup per well, not a frame time.");
			configShowTriggerColliders = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "ShowTriggerColliders", false, "Draw the reload trigger zone of every well as a semi transparent shape, so you can see where it sits and how big it really is while tuning the values above. The shapes live in the scene rather than inside the gun, so they are still drawn on a gun whose well the game currently has switched off (a handgun with its mag release held, an open bolt gun with its bolt forward).");
			configShowUnmanagedWells = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "ShowUnmanagedWells", false, "Extend ShowTriggerColliders to the wells this mod is NOT touching - the ones left alone by the master switch, or by a gun's JSON entry - so a well that is left alone can be compared with one the mod drives.");
			configTriggerAlpha = ((BaseUnityPlugin)this).Config.Bind<float>("Debug", "TriggerAlpha", 0.35f, "How see-through the debug shapes are (0.05-1).");
			configVerboseLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "VerboseLogging", false, "Log what the mod does to every gun: every weapon key it sees (the line reads 'weapon key seen: <ItemID>', which is exactly what a JSON entry has to be keyed by), every well it resizes with the old and the new collider values, and every gun that has no reload well at all. Turn this on first whenever the mod looks like it is doing nothing, then turn it back off.");
			AddSettingChangedListener<bool>(configEnabled);
			AddSettingChangedListener<float>(configScaleXMultiplyAmount);
			AddSettingChangedListener<float>(configScaleYMultiplyAmount);
			AddSettingChangedListener<float>(configScaleZMultiplyAmount);
			AddSettingChangedListener<float>(configRescanIntervalSeconds);
			AddSettingChangedListener<bool>(configShowTriggerColliders);
			AddSettingChangedListener<bool>(configShowUnmanagedWells);
			AddSettingChangedListener<float>(configTriggerAlpha);
			AddSettingChangedListener<bool>(configVerboseLogging);
		}

		private void AddSettingChangedListener<T>(ConfigEntry<T> entry)
		{
			entry.SettingChanged += delegate
			{
				OnConfigChanged();
			};
		}

		private void OnConfigChanged()
		{
			ReloadConfigSnapshot();
			_applyPending = true;
		}

		private void ReloadConfigSnapshot()
		{
			try
			{
				ConfigSnapshot cfg = DefaultSnapshot();
				if (configEnabled != null)
				{
					cfg.Enabled = configEnabled.Value;
					cfg.ScaleX = Safe(configScaleXMultiplyAmount.Value, 1.1f);
					cfg.ScaleY = Safe(configScaleYMultiplyAmount.Value, 2f);
					cfg.ScaleZ = Safe(configScaleZMultiplyAmount.Value, 1.1f);
					cfg.RescanInterval = ((configRescanIntervalSeconds.Value <= 0f) ? 0f : Mathf.Max(configRescanIntervalSeconds.Value, 0.5f));
					cfg.ShowTriggerColliders = configShowTriggerColliders.Value;
					cfg.ShowUnmanagedWells = configShowUnmanagedWells.Value;
					cfg.DebugAlpha = Mathf.Clamp(Safe(configTriggerAlpha.Value, 0.35f), 0.05f, 1f);
					cfg.Verbose = configVerboseLogging.Value;
				}
				Cfg = cfg;
			}
			catch (Exception ex)
			{
				LogWarning("Could not read the config, keeping the last good values: " + ex.Message);
			}
		}

		private static ConfigSnapshot DefaultSnapshot()
		{
			return new ConfigSnapshot
			{
				Enabled = true,
				ScaleX = 1.1f,
				ScaleY = 2f,
				ScaleZ = 1.1f,
				RescanInterval = 3f,
				ShowTriggerColliders = false,
				ShowUnmanagedWells = false,
				DebugAlpha = 0.35f,
				Verbose = false
			};
		}

		internal static float Safe(float value, float fallback)
		{
			if (float.IsNaN(value) || float.IsInfinity(value) || value == 0f)
			{
				return fallback;
			}
			return value;
		}

		internal void ReloadFromDisk()
		{
			try
			{
				if (((BaseUnityPlugin)this).Config != null)
				{
					((BaseUnityPlugin)this).Config.Reload();
				}
			}
			catch (Exception ex)
			{
				LogWarning("Config reload failed: " + ex.Message);
			}
			ReloadConfigSnapshot();
			RememberConfigFileStamp();
			LoadJsonConfig();
			_applyPending = true;
		}

		private void RememberConfigFileStamp()
		{
			if (string.IsNullOrEmpty(_configFilePath))
			{
				return;
			}
			try
			{
				_configFileStamp = (File.Exists(_configFilePath) ? File.GetLastWriteTimeUtc(_configFilePath).Ticks : (-1));
			}
			catch (Exception)
			{
				_configFileStamp = -1L;
			}
		}

		private void CheckFilesChanged()
		{
			if (string.IsNullOrEmpty(_configFilePath))
			{
				return;
			}
			if (GetStamp(_jsonConfigPath) != _jsonConfigStamp)
			{
				LogInfo("The weapon override file changed on disk, reloading it.");
				LoadJsonConfig();
				_applyPending = true;
			}
			try
			{
				if (File.Exists(_configFilePath) && File.GetLastWriteTimeUtc(_configFilePath).Ticks != _configFileStamp)
				{
					LogInfo("The config file changed on disk, reloading it.");
					ReloadFromDisk();
				}
			}
			catch (Exception)
			{
			}
		}

		public void LoadJsonConfig()
		{
			WeaponOverrides.Clear();
			try
			{
				if (string.IsNullOrEmpty(_jsonConfigPath))
				{
					_jsonConfigPath = GetJsonConfigPath();
				}
				if (string.IsNullOrEmpty(_jsonConfigPath))
				{
					LogError("Failed to get config directory path.");
					return;
				}
				if (!File.Exists(_jsonConfigPath))
				{
					LogWarning("Config file not found. Creating default config...");
					CreateDefaultJsonConfig(_jsonConfigPath);
				}
				WeaponOverrideFile weaponOverrideFile = JsonConvert.DeserializeObject<WeaponOverrideFile>(File.ReadAllText(_jsonConfigPath));
				if (weaponOverrideFile != null && weaponOverrideFile.WeaponOverrides != null)
				{
					foreach (KeyValuePair<string, WeaponSettings> weaponOverride in weaponOverrideFile.WeaponOverrides)
					{
						if (!string.IsNullOrEmpty(weaponOverride.Key) && weaponOverride.Value != null)
						{
							WeaponOverrides[weaponOverride.Key] = weaponOverride.Value;
						}
					}
					LogInfo("Successfully loaded " + WeaponOverrides.Count + " weapon overrides.");
				}
				else
				{
					LogWarning("No weapon overrides found in config file.");
				}
			}
			catch (Exception ex)
			{
				LogError("Error loading config: " + ex.Message);
				WeaponOverrides.Clear();
			}
			_jsonConfigStamp = GetStamp(_jsonConfigPath);
		}

		private static string GetJsonConfigPath()
		{
			string directoryName = Path.GetDirectoryName(Paths.BepInExConfigPath);
			if (string.IsNullOrEmpty(directoryName))
			{
				return null;
			}
			return Path.Combine(directoryName, "Niko666.ReloadTriggerWellEnlarger.json");
		}

		private static long GetStamp(string path)
		{
			if (string.IsNullOrEmpty(path))
			{
				return -1L;
			}
			try
			{
				return File.Exists(path) ? File.GetLastWriteTimeUtc(path).Ticks : (-1);
			}
			catch (Exception)
			{
				return -1L;
			}
		}

		public void CreateDefaultJsonConfig(string path)
		{
			try
			{
				string contents = JsonConvert.SerializeObject((object)new WeaponOverrideFile
				{
					WeaponOverrides = new Dictionary<string, WeaponSettings>
					{
						{
							"InsertFirearmObjectIDHere",
							new WeaponSettings
							{
								ScaleXMultiplyAmount = 1.1f,
								ScaleYMultiplyAmount = 0.9f,
								ScaleZMultiplyAmount = 10f
							}
						},
						{
							"ForExampleM1911Classic",
							new WeaponSettings
							{
								ScaleXMultiplyAmount = 1f,
								ScaleYMultiplyAmount = 1f,
								ScaleZMultiplyAmount = 1f
							}
						}
					}
				}, (Formatting)1);
				File.WriteAllText(path, contents);
				LogInfo("Created default config at: " + path);
			}
			catch (Exception ex)
			{
				LogError("Error creating default config: " + ex.Message + "\n" + ex.StackTrace);
			}
		}

		public void Awake()
		{
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			Cfg = DefaultSnapshot();
			try
			{
				BindConfig();
				ReloadConfigSnapshot();
			}
			catch (Exception ex)
			{
				LogError("Config could not be set up, the mod uses its built in defaults: " + ex);
			}
			try
			{
				_configFilePath = ((BaseUnityPlugin)this).Config.ConfigFilePath;
			}
			catch (Exception)
			{
				_configFilePath = null;
			}
			RememberConfigFileStamp();
			try
			{
				_jsonConfigPath = GetJsonConfigPath();
			}
			catch (Exception)
			{
				_jsonConfigPath = null;
			}
			Instance.LoadJsonConfig();
			PatchGroup(typeof(ReloadTriggerWellEnlargerPatch), "no gun will have its reload zone enlarged");
			PatchGroup(typeof(ReloadWellAttachmentPatch), "a magazine well that lives inside an attachment will be left at its original size");
			PatchGroup(typeof(ReloadWellAttachablePatch), "an underbarrel gun's magazine well will be left at its original size");
			try
			{
				SceneManager.sceneLoaded += OnSceneLoaded;
			}
			catch (Exception ex4)
			{
				LogWarning("Could not listen for scene loads: " + ex4.Message);
			}
			Logger.LogMessage((object)("Fuck this world! Sent from Niko666.ReloadTriggerWellEnlarger " + Version));
		}

		public void Update()
		{
			try
			{
				float unscaledTime = Time.unscaledTime;
				if (unscaledTime - _lastFileCheck >= 1f)
				{
					_lastFileCheck = unscaledTime;
					CheckFilesChanged();
				}
				if (_applyPending)
				{
					_applyPending = false;
					_lastSweep = unscaledTime;
					WellScaler.ApplyToAllWells();
				}
				else if (Cfg.RescanInterval > 0f && unscaledTime - _lastSweep >= Cfg.RescanInterval)
				{
					_lastSweep = unscaledTime;
					WellScaler.ApplyToAllWells();
				}
			}
			catch (Exception ex)
			{
				if (_updateErrors < 3)
				{
					_updateErrors++;
					LogError("Update failed: " + ex);
				}
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			try
			{
				ReloadFromDisk();
			}
			catch (Exception ex)
			{
				if (_updateErrors < 3)
				{
					_updateErrors++;
					LogError("Handling a scene load failed: " + ex);
				}
			}
		}

		private void PatchGroup(Type patchClass, string whatBreaksWithoutIt)
		{
			try
			{
				Harmony.CreateAndPatchAll(patchClass, "Niko666.ReloadTriggerWellEnlarger");
				Logger.LogMessage((object)("Patch group applied: " + patchClass.Name));
			}
			catch (Exception ex)
			{
				LogError("Patch group " + patchClass.Name + " failed, " + whatBreaksWithoutIt + ": " + ex);
			}
		}

		public static void CopyAndAdjustTrigger(FVRFireArm orig, string weaponID)
		{
			if ((Object)(object)orig == (Object)null)
			{
				LogError("CopyAndAdjustTrigger: FVRFireArm instance is null");
			}
			else
			{
				WellScaler.ProcessRoot(((Component)orig).gameObject, "firearm Awake");
			}
		}

		internal static void LogInfo(string message)
		{
			if (Logger != null)
			{
				Logger.LogMessage((object)message);
			}
		}

		private static void LogWarning(string message)
		{
			if (Logger != null)
			{
				Logger.LogWarning((object)message);
			}
		}

		private static void LogError(string message)
		{
			if (Logger != null)
			{
				Logger.LogError((object)message);
			}
		}
	}
	public class ReloadTriggerWellEnlargerPatch
	{
		[HarmonyPatch(typeof(FVRFireArm), "Awake")]
		[HarmonyPostfix]
		public static void AwakePatch(FVRFireArm __instance)
		{
			try
			{
				string weaponID = "";
				if ((Object)(object)((FVRPhysicalObject)__instance).ObjectWrapper == (Object)null)
				{
					ReloadTriggerWellEnlarger.LogInfo("ObjectWrapper is null for " + ((Object)__instance).name + ", how is that possible? Using global scaling.");
				}
				else if (string.IsNullOrEmpty(((FVRPhysicalObject)__instance).ObjectWrapper.ItemID))
				{
					ReloadTriggerWellEnlarger.LogInfo("ItemID is null or empty for " + ((Object)__instance).name + ", how is that possible? Using global scaling.");
				}
				else
				{
					weaponID = ((FVRPhysicalObject)__instance).ObjectWrapper.ItemID;
				}
				ReloadTriggerWellEnlarger.CopyAndAdjustTrigger(__instance, weaponID);
			}
			catch (Exception ex)
			{
				WellScaler.ReportProblem("Enlarging the reload wells of a gun failed", ex);
			}
		}

		[HarmonyPatch(typeof(SteamVR_LoadLevel), "Begin")]
		[HarmonyPrefix]
		public static bool BeginPatch()
		{
			if ((Object)(object)ReloadTriggerWellEnlarger.Instance != (Object)null)
			{
				ReloadTriggerWellEnlarger.Instance.ReloadFromDisk();
			}
			return true;
		}
	}
	public class ReloadWellAttachmentPatch
	{
		[HarmonyPatch(typeof(FVRFireArmAttachment), "Awake")]
		[HarmonyPostfix]
		public static void AwakePatch(FVRFireArmAttachment __instance)
		{
			try
			{
				WellScaler.ProcessRoot(((Component)__instance).gameObject, "attachment Awake");
			}
			catch (Exception ex)
			{
				WellScaler.ReportProblem("Enlarging the reload wells of an attachment failed", ex);
			}
		}
	}
	public class ReloadWellAttachablePatch
	{
		[HarmonyPatch(typeof(AttachableFirearm), "Awake")]
		[HarmonyPostfix]
		public static void AwakePatch(AttachableFirearm __instance)
		{
			try
			{
				WellScaler.ProcessRoot(((Component)__instance).gameObject, "attachable Awake");
			}
			catch (Exception ex)
			{
				WellScaler.ReportProblem("Enlarging the reload wells of an attached gun failed", ex);
			}
		}
	}
	public sealed class WellColliderState
	{
		public Collider Col;

		public Vector3 OriginalSize;

		public float OriginalRadius;

		public float OriginalHeight;

		public bool IsCapsule;

		public bool IsSphere;

		public bool IsBox;
	}
	public sealed class WellScaleMarker : MonoBehaviour
	{
		public bool Managed;

		public readonly List<WellColliderState> States = new List<WellColliderState>();

		public GameObject Visual;

		public int VisualPrimitive = -1;

		public Collider Primary()
		{
			for (int i = 0; i < States.Count; i++)
			{
				if ((Object)(object)States[i].Col != (Object)null)
				{
					return States[i].Col;
				}
			}
			return null;
		}

		public bool Knows(Collider collider)
		{
			for (int i = 0; i < States.Count; i++)
			{
				if ((Object)(object)States[i].Col == (Object)(object)collider)
				{
					return true;
				}
			}
			return false;
		}
	}
	public sealed class WellDebugVisual : MonoBehaviour
	{
		public Collider Target;

		private void LateUpdate()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00e2: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			Collider target = Target;
			if ((Object)(object)target == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			Transform transform = ((Component)target).transform;
			Vector3 lossyScale = transform.lossyScale;
			CapsuleCollider val = (CapsuleCollider)(object)((target is CapsuleCollider) ? target : null);
			BoxCollider val2 = (BoxCollider)(object)((target is BoxCollider) ? target : null);
			SphereCollider val3 = (SphereCollider)(object)((target is SphereCollider) ? target : null);
			Vector3 center;
			Vector3 scale = default(Vector3);
			Quaternion rotation;
			if ((Object)(object)val != (Object)null)
			{
				int direction = val.direction;
				float num = Component(lossyScale, direction);
				float num2 = (Component(lossyScale, 0) + Component(lossyScale, 1) + Component(lossyScale, 2) - num) * 0.5f;
				float num3 = val.radius * 2f * num2;
				float num4 = val.height * num;
				center = val.center;
				((Vector3)(ref scale))..ctor(num3, num4 * 0.5f, num3);
				rotation = transform.rotation * CapsuleRotation(direction);
			}
			else if ((Object)(object)val2 != (Object)null)
			{
				center = val2.center;
				((Vector3)(ref scale))..ctor(val2.size.x * lossyScale.x, val2.size.y * lossyScale.y, val2.size.z * lossyScale.z);
				rotation = transform.rotation;
			}
			else
			{
				if (!((Object)(object)val3 != (Object)null))
				{
					Bounds bounds = target.bounds;
					((Component)this).transform.position = ((Bounds)(ref bounds)).center;
					((Component)this).transform.rotation = transform.rotation;
					((Component)this).transform.localScale = Fit(((Bounds)(ref bounds)).size);
					return;
				}
				float num5 = Mathf.Max(Mathf.Abs(lossyScale.x), Mathf.Max(Mathf.Abs(lossyScale.y), Mathf.Abs(lossyScale.z)));
				float num6 = val3.radius * 2f * num5;
				center = val3.center;
				((Vector3)(ref scale))..ctor(num6, num6, num6);
				rotation = transform.rotation;
			}
			((Component)this).transform.position = transform.TransformPoint(center);
			((Component)this).transform.rotation = rotation;
			((Component)this).transform.localScale = Fit(scale);
		}

		private static float Component(Vector3 v, int index)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			return index switch
			{
				0 => v.x, 
				1 => v.y, 
				_ => v.z, 
			};
		}

		private static Quaternion CapsuleRotation(int direction)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			return (Quaternion)(direction switch
			{
				0 => Quaternion.Euler(0f, 0f, 90f), 
				2 => Quaternion.Euler(90f, 0f, 0f), 
				_ => Quaternion.identity, 
			});
		}

		private static Vector3 Fit(Vector3 scale)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			scale.x = Mathf.Max(Mathf.Abs(scale.x), 0.001f);
			scale.y = Mathf.Max(Mathf.Abs(scale.y), 0.001f);
			scale.z = Mathf.Max(Mathf.Abs(scale.z), 0.001f);
			return scale;
		}
	}
	internal static class WellScaler
	{
		internal struct TriggerSettings
		{
			public bool Enabled;

			public float X;

			public float Y;

			public float Z;
		}

		private const string VisualName = "Niko666_ReloadWellDebug";

		private static readonly Color VisualColor = new Color(0.1f, 0.85f, 1f);

		private static Material _debugMaterial;

		private static bool _noShaderLogged;

		private static bool _meshColliderLogged;

		private static bool _oddColliderLogged;

		private static int _problemCount;

		private static readonly HashSet<string> LoggedKeys = new HashSet<string>();

		private static readonly HashSet<string> LoggedNoWell = new HashSet<string>();

		private static readonly List<GameObject> Visuals = new List<GameObject>();

		private static readonly string[] CandidateShaders = new string[4] { "Unlit/Transparent", "Legacy Shaders/Transparent/Diffuse", "Particles/Alpha Blended", "Legacy Shaders/Transparent/VertexLit" };

		internal static void ProcessRoot(GameObject root, string source)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			try
			{
				FVRFireArmReloadTriggerWell[] componentsInChildren = root.GetComponentsInChildren<FVRFireArmReloadTriggerWell>(true);
				if (componentsInChildren == null || componentsInChildren.Length == 0)
				{
					ReportNoWell(root, source);
					return;
				}
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					ProcessWell(componentsInChildren[i], source);
				}
			}
			catch (Exception ex)
			{
				ReportProblem("Looking for the reload wells of " + ((Object)root).name + " failed", ex);
			}
		}

		internal static void ApplyToAllWells()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			try
			{
				FVRFireArmReloadTriggerWell[] array = Resources.FindObjectsOfTypeAll<FVRFireArmReloadTriggerWell>();
				if (array == null)
				{
					return;
				}
				foreach (FVRFireArmReloadTriggerWell val in array)
				{
					if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).gameObject == (Object)null))
					{
						Scene scene = ((Component)val).gameObject.scene;
						if (((Scene)(ref scene)).IsValid())
						{
							ProcessWell(val, "scene sweep");
							num++;
						}
					}
				}
				if (ReloadTriggerWellEnlarger.Cfg.Verbose)
				{
					ReloadTriggerWellEnlarger.LogInfo("Reload wells updated on " + num + " live well(s).");
				}
			}
			catch (Exception ex)
			{
				ReportProblem("Updating every reload well failed", ex);
			}
		}

		internal static void DropAllVisuals()
		{
			for (int i = 0; i < Visuals.Count; i++)
			{
				if ((Object)(object)Visuals[i] != (Object)null)
				{
					Object.Destroy((Object)(object)Visuals[i]);
				}
			}
			Visuals.Clear();
		}

		private static void ProcessWell(FVRFireArmReloadTriggerWell well, string source)
		{
			if ((Object)(object)well == (Object)null || (Object)(object)((Component)well).gameObject == (Object)null)
			{
				return;
			}
			GameObject gameObject = ((Component)well).gameObject;
			ReloadTriggerWellEnlarger.ConfigSnapshot cfg = ReloadTriggerWellEnlarger.Cfg;
			WellScaleMarker wellScaleMarker = gameObject.GetComponent<WellScaleMarker>();
			bool hasOverride;
			TriggerSettings settings = ResolveSettings(well, out hasOverride);
			if (settings.Enabled)
			{
				if ((Object)(object)wellScaleMarker == (Object)null)
				{
					wellScaleMarker = gameObject.AddComponent<WellScaleMarker>();
				}
				CaptureOriginals(wellScaleMarker);
				if (wellScaleMarker.States.Count == 0)
				{
					ReportNoResizableCollider(well);
					SyncVisual(wellScaleMarker, cfg);
					return;
				}
				Apply(wellScaleMarker, settings);
				wellScaleMarker.Managed = true;
				if (cfg.Verbose)
				{
					LogApplied(well, wellScaleMarker, settings, source, hasOverride);
				}
			}
			else if ((Object)(object)wellScaleMarker != (Object)null && wellScaleMarker.Managed)
			{
				Release(wellScaleMarker);
				if (cfg.Verbose)
				{
					ReloadTriggerWellEnlarger.LogInfo("Put the reload well of " + Describe(((Component)well).transform) + " back to the size the game shipped.");
				}
			}
			else if ((Object)(object)wellScaleMarker == (Object)null && cfg.ShowUnmanagedWells)
			{
				wellScaleMarker = gameObject.AddComponent<WellScaleMarker>();
				CaptureOriginals(wellScaleMarker);
			}
			SyncVisual(wellScaleMarker, cfg);
		}

		private static void Apply(WellScaleMarker marker, TriggerSettings settings)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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)
			//IL_00d5: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			Vector3 val2 = default(Vector3);
			for (int i = 0; i < marker.States.Count; i++)
			{
				WellColliderState wellColliderState = marker.States[i];
				Collider col = wellColliderState.Col;
				if ((Object)(object)col == (Object)null)
				{
					continue;
				}
				if (wellColliderState.IsBox)
				{
					BoxCollider val = (BoxCollider)col;
					((Vector3)(ref val2))..ctor(Safe(settings.X * wellColliderState.OriginalSize.x, wellColliderState.OriginalSize.x), Safe(settings.Y * wellColliderState.OriginalSize.y, wellColliderState.OriginalSize.y), Safe(settings.Z * wellColliderState.OriginalSize.z, wellColliderState.OriginalSize.z));
					if (!Same(val.size, val2))
					{
						val.size = val2;
					}
				}
				else if (wellColliderState.IsSphere)
				{
					SphereCollider val3 = (SphereCollider)col;
					float num = Safe(settings.X * wellColliderState.OriginalRadius, wellColliderState.OriginalRadius);
					if (val3.radius != num)
					{
						val3.radius = num;
					}
				}
				else if (wellColliderState.IsCapsule)
				{
					CapsuleCollider val4 = (CapsuleCollider)col;
					float num2 = Safe(settings.X * wellColliderState.OriginalRadius, wellColliderState.OriginalRadius);
					float num3 = Safe(settings.Y * wellColliderState.OriginalHeight, wellColliderState.OriginalHeight);
					if (val4.radius != num2)
					{
						val4.radius = num2;
					}
					if (val4.height != num3)
					{
						val4.height = num3;
					}
				}
			}
		}

		private static bool Same(Vector3 a, Vector3 b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (Mathf.Abs(a.x - b.x) < 1E-05f && Mathf.Abs(a.y - b.y) < 1E-05f)
			{
				return Mathf.Abs(a.z - b.z) < 1E-05f;
			}
			return false;
		}

		private static void Release(WellScaleMarker marker)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_0067: 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)
			marker.Managed = false;
			for (int i = 0; i < marker.States.Count; i++)
			{
				WellColliderState wellColliderState = marker.States[i];
				Collider col = wellColliderState.Col;
				if (!((Object)(object)col == (Object)null))
				{
					if (wellColliderState.IsBox)
					{
						((BoxCollider)col).size = wellColliderState.OriginalSize;
					}
					else if (wellColliderState.IsSphere)
					{
						((SphereCollider)col).radius = wellColliderState.OriginalRadius;
					}
					else if (wellColliderState.IsCapsule)
					{
						CapsuleCollider val = (CapsuleCollider)col;
						val.radius = wellColliderState.OriginalRadius;
						val.height = wellColliderState.OriginalHeight;
					}
				}
			}
			DropVisual(marker);
		}

		private static void CaptureOriginals(WellScaleMarker marker)
		{
			GameObject gameObject = ((Component)marker).gameObject;
			Collider[] components = gameObject.GetComponents<Collider>();
			if (components != null && components.Length != 0)
			{
				for (int i = 0; i < components.Length; i++)
				{
					Capture(marker, components[i]);
				}
				return;
			}
			Collider[] componentsInChildren = gameObject.GetComponentsInChildren<Collider>(true);
			if (componentsInChildren != null)
			{
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					Capture(marker, componentsInChildren[j]);
				}
			}
		}

		private static void Capture(WellScaleMarker marker, Collider col)
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)col == (Object)null || marker.Knows(col))
			{
				return;
			}
			BoxCollider val = (BoxCollider)(object)((col is BoxCollider) ? col : null);
			SphereCollider val2 = (SphereCollider)(object)((col is SphereCollider) ? col : null);
			CapsuleCollider val3 = (CapsuleCollider)(object)((col is CapsuleCollider) ? col : null);
			if ((Object)(object)val == (Object)null && (Object)(object)val2 == (Object)null && (Object)(object)val3 == (Object)null)
			{
				if (!_meshColliderLogged)
				{
					_meshColliderLogged = true;
					ReloadTriggerWellEnlarger.LogInfo("A " + ((object)col).GetType().Name + " on a reload well cannot be resized and was left alone (only box, sphere and capsule colliders can be).");
				}
				return;
			}
			WellColliderState wellColliderState = new WellColliderState();
			wellColliderState.Col = col;
			wellColliderState.IsBox = (Object)(object)val != (Object)null;
			wellColliderState.IsSphere = (Object)(object)val2 != (Object)null;
			wellColliderState.IsCapsule = (Object)(object)val3 != (Object)null;
			if (wellColliderState.IsBox)
			{
				wellColliderState.OriginalSize = val.size;
			}
			else if (wellColliderState.IsSphere)
			{
				wellColliderState.OriginalRadius = val2.radius;
			}
			else
			{
				wellColliderState.OriginalRadius = val3.radius;
				wellColliderState.OriginalHeight = val3.height;
			}
			marker.States.Add(wellColliderState);
		}

		private static TriggerSettings ResolveSettings(FVRFireArmReloadTriggerWell well, out bool hasOverride)
		{
			ReloadTriggerWellEnlarger.ConfigSnapshot cfg = ReloadTriggerWellEnlarger.Cfg;
			TriggerSettings result = new TriggerSettings
			{
				Enabled = cfg.Enabled,
				X = cfg.ScaleX,
				Y = cfg.ScaleY,
				Z = cfg.ScaleZ
			};
			hasOverride = false;
			string text = ResolveWeaponKey(well);
			if (string.IsNullOrEmpty(text))
			{
				return result;
			}
			if (cfg.Verbose && LoggedKeys.Add(text))
			{
				ReloadTriggerWellEnlarger.LogInfo("weapon key seen: " + text + "   (this is the key to use in Niko666.ReloadTriggerWellEnlarger.json)");
			}
			if (!ReloadTriggerWellEnlarger.WeaponOverrides.TryGetValue(text, out var value) || value == null)
			{
				return result;
			}
			hasOverride = true;
			if (value.Enabled.HasValue)
			{
				result.Enabled = cfg.Enabled && value.Enabled.Value;
			}
			if (value.ScaleXMultiplyAmount.HasValue)
			{
				result.X = Safe(value.ScaleXMultiplyAmount.Value, result.X);
			}
			if (value.ScaleYMultiplyAmount.HasValue)
			{
				result.Y = Safe(value.ScaleYMultiplyAmount.Value, result.Y);
			}
			if (value.ScaleZMultiplyAmount.HasValue)
			{
				result.Z = Safe(value.ScaleZMultiplyAmount.Value, result.Z);
			}
			return result;
		}

		private static string ResolveWeaponKey(FVRFireArmReloadTriggerWell well)
		{
			try
			{
				FVRFireArm componentInParent = ((Component)well).GetComponentInParent<FVRFireArm>();
				if ((Object)(object)componentInParent == (Object)null)
				{
					return null;
				}
				if ((Object)(object)((FVRPhysicalObject)componentInParent).ObjectWrapper != (Object)null && !string.IsNullOrEmpty(((FVRPhysicalObject)componentInParent).ObjectWrapper.ItemID))
				{
					return ((FVRPhysicalObject)componentInParent).ObjectWrapper.ItemID;
				}
				string text = ((Object)((Component)componentInParent).gameObject).name;
				if (string.IsNullOrEmpty(text))
				{
					return null;
				}
				if (text.EndsWith("(Clone)", StringComparison.Ordinal))
				{
					text = text.Substring(0, text.Length - "(Clone)".Length);
				}
				return text;
			}
			catch (Exception)
			{
				return null;
			}
		}

		private static void SyncVisual(WellScaleMarker marker, ReloadTriggerWellEnlarger.ConfigSnapshot cfg)
		{
			if ((Object)(object)marker == (Object)null)
			{
				return;
			}
			Collider val = null;
			if (marker.Managed)
			{
				val = marker.Primary();
			}
			else if (cfg.ShowUnmanagedWells)
			{
				val = marker.Primary();
			}
			int num = ((cfg.ShowTriggerColliders && (Object)(object)val != (Object)null) ? PrimitiveFor(val) : (-1));
			if (num < 0)
			{
				DropVisual(marker);
				if (!cfg.ShowTriggerColliders)
				{
					DropAllVisuals();
				}
				return;
			}
			if ((Object)(object)marker.Visual == (Object)null || marker.VisualPrimitive != num)
			{
				DropVisual(marker);
				marker.Visual = CreateVisual(num, val);
				marker.VisualPrimitive = (((Object)(object)marker.Visual == (Object)null) ? (-1) : num);
				if ((Object)(object)marker.Visual == (Object)null)
				{
					return;
				}
				Visuals.Add(marker.Visual);
			}
			if ((Object)(object)_debugMaterial != (Object)null)
			{
				SetDebugAlpha(_debugMaterial, cfg.DebugAlpha);
			}
		}

		private static int PrimitiveFor(Collider col)
		{
			if (col is CapsuleCollider)
			{
				return 1;
			}
			if (col is SphereCollider)
			{
				return 0;
			}
			if (col is BoxCollider)
			{
				return 3;
			}
			return -1;
		}

		private static GameObject CreateVisual(int primitive, Collider source)
		{
			try
			{
				Material debugMaterial = GetDebugMaterial(ReloadTriggerWellEnlarger.Cfg.DebugAlpha);
				if ((Object)(object)debugMaterial == (Object)null)
				{
					return null;
				}
				GameObject obj = GameObject.CreatePrimitive((PrimitiveType)primitive);
				((Object)obj).name = "Niko666_ReloadWellDebug";
				Collider component = obj.GetComponent<Collider>();
				if ((Object)(object)component != (Object)null)
				{
					component.enabled = false;
					Object.Destroy((Object)(object)component);
				}
				MeshRenderer component2 = obj.GetComponent<MeshRenderer>();
				if ((Object)(object)component2 != (Object)null)
				{
					((Renderer)component2).sharedMaterial = debugMaterial;
					((Renderer)component2).shadowCastingMode = (ShadowCastingMode)0;
					((Renderer)component2).receiveShadows = false;
				}
				obj.AddComponent<WellDebugVisual>().Target = source;
				return obj;
			}
			catch (Exception ex)
			{
				ReportProblem("Could not build the debug shape", ex);
				return null;
			}
		}

		private static void DropVisual(WellScaleMarker marker)
		{
			if ((Object)(object)marker == (Object)null || (Object)(object)marker.Visual == (Object)null)
			{
				if ((Object)(object)marker != (Object)null)
				{
					marker.VisualPrimitive = -1;
				}
			}
			else
			{
				Visuals.Remove(marker.Visual);
				Object.Destroy((Object)(object)marker.Visual);
				marker.Visual = null;
				marker.VisualPrimitive = -1;
			}
		}

		private static Material GetDebugMaterial(float alpha)
		{
			//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_0057: 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_0068: Expected O, but got Unknown
			//IL_006e: Expected O, but got Unknown
			if ((Object)(object)_debugMaterial != (Object)null)
			{
				SetDebugAlpha(_debugMaterial, alpha);
				return _debugMaterial;
			}
			Shader val = FindTransparentShader();
			if ((Object)(object)val == (Object)null)
			{
				if (!_noShaderLogged)
				{
					_noShaderLogged = true;
					ReloadTriggerWellEnlarger.LogInfo("No transparent shader is available in this game build, so the debug view stays empty. Everything else still works.");
				}
				return null;
			}
			Material val2 = new Material(val)
			{
				name = "Niko666_ReloadWellDebug",
				renderQueue = 3000
			};
			_debugMaterial = val2;
			SetDebugAlpha(val2, alpha);
			return _debugMaterial;
		}

		private static void SetDebugAlpha(Material material, float alpha)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			Color val = default(Color);
			((Color)(ref val))..ctor(VisualColor.r, VisualColor.g, VisualColor.b, alpha);
			if (material.HasProperty("_Color"))
			{
				material.color = val;
			}
			else if (material.HasProperty("_TintColor"))
			{
				material.SetColor("_TintColor", val);
			}
			else if (material.HasProperty("_MainTex"))
			{
				Texture mainTexture = material.mainTexture;
				Texture2D val2 = (Texture2D)(object)((mainTexture is Texture2D) ? mainTexture : null);
				if ((Object)(object)val2 == (Object)null)
				{
					material.mainTexture = (Texture)(object)CreateAlphaTexture(alpha);
					return;
				}
				val2.SetPixel(0, 0, val);
				val2.Apply();
			}
		}

		private static Texture2D CreateAlphaTexture(float alpha)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)5, false);
			val.SetPixel(0, 0, new Color(VisualColor.r, VisualColor.g, VisualColor.b, alpha));
			val.Apply();
			return val;
		}

		private static Shader FindTransparentShader()
		{
			for (int i = 0; i < CandidateShaders.Length; i++)
			{
				Shader val = Shader.Find(CandidateShaders[i]);
				if ((Object)(object)val != (Object)null && HasColorSlot(val))
				{
					ReloadTriggerWellEnlarger.LogInfo("Debug shapes are drawn with the shader " + ((Object)val).name + ".");
					return val;
				}
			}
			Object[] array = Resources.FindObjectsOfTypeAll(typeof(Material));
			if (array != null)
			{
				foreach (Object obj in array)
				{
					Material val2 = (Material)(object)((obj is Material) ? obj : null);
					if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.shader == (Object)null) && val2.shader.renderQueue >= 3000 && (val2.HasProperty("_Color") || val2.HasProperty("_TintColor")))
					{
						ReloadTriggerWellEnlarger.LogInfo("Debug shapes are drawn with the shader " + ((Object)val2.shader).name + " (borrowed from " + ((Object)val2).name + ").");
						return val2.shader;
					}
				}
			}
			return null;
		}

		private static bool HasColorSlot(Shader shader)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			Material val = null;
			try
			{
				val = new Material(shader);
				return val.HasProperty("_Color") || val.HasProperty("_TintColor") || val.HasProperty("_MainTex");
			}
			catch (Exception)
			{
				return false;
			}
			finally
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}

		private static void ReportNoWell(GameObject root, string source)
		{
			if (ReloadTriggerWellEnlarger.Cfg.Verbose)
			{
				string name = ((Object)root).name;
				if (LoggedNoWell.Add(name))
				{
					ReloadTriggerWellEnlarger.LogInfo("No reload well on " + name + " (" + source + "): nothing to resize on this object, which is normal for guns that take ammo some other way.");
				}
			}
		}

		private static void ReportNoResizableCollider(FVRFireArmReloadTriggerWell well)
		{
			if (!_oddColliderLogged)
			{
				_oddColliderLogged = true;
				ReloadTriggerWellEnlarger.LogInfo("The reload well of " + Describe(((Component)well).transform) + " has no collider that can be resized (a " + DescribeColliders(((Component)well).gameObject) + "), so it was left alone.");
			}
		}

		private static string DescribeColliders(GameObject go)
		{
			try
			{
				Collider[] componentsInChildren = go.GetComponentsInChildren<Collider>(true);
				if (componentsInChildren == null || componentsInChildren.Length == 0)
				{
					return "no collider at all";
				}
				string text = "";
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					if (i > 0)
					{
						text += ", ";
					}
					text += ((object)componentsInChildren[i]).GetType().Name;
					text += (componentsInChildren[i].isTrigger ? " (trigger)" : " (solid)");
				}
				return text;
			}
			catch (Exception)
			{
				return "unknown collider";
			}
		}

		private static void LogApplied(FVRFireArmReloadTriggerWell well, WellScaleMarker marker, TriggerSettings settings, string source, bool hasOverride)
		{
			ReloadTriggerWellEnlarger.LogInfo("Reload well of " + Describe(((Component)well).transform) + ": x" + settings.X + " y" + settings.Y + " z" + settings.Z + (hasOverride ? " (json override)" : "") + " " + DescribeStates(marker) + " [" + source + ", active=" + ((Component)well).gameObject.activeInHierarchy + "]");
		}

		private static string DescribeStates(WellScaleMarker marker)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			string text = "";
			for (int i = 0; i < marker.States.Count; i++)
			{
				WellColliderState wellColliderState = marker.States[i];
				Collider col = wellColliderState.Col;
				if (!((Object)(object)col == (Object)null))
				{
					if (text.Length > 0)
					{
						text += "; ";
					}
					if (wellColliderState.IsBox)
					{
						BoxCollider val = (BoxCollider)col;
						text = text + "box " + Fmt(wellColliderState.OriginalSize) + " -> " + Fmt(val.size);
					}
					else if (wellColliderState.IsSphere)
					{
						SphereCollider val2 = (SphereCollider)col;
						text = text + "sphere r " + wellColliderState.OriginalRadius.ToString("0.####") + " -> " + val2.radius.ToString("0.####");
					}
					else if (wellColliderState.IsCapsule)
					{
						CapsuleCollider val3 = (CapsuleCollider)col;
						text = text + "capsule r " + wellColliderState.OriginalRadius.ToString("0.####") + " h " + wellColliderState.OriginalHeight.ToString("0.####") + " -> r " + val3.radius.ToString("0.####") + " h " + val3.height.ToString("0.####");
					}
				}
			}
			return text;
		}

		private static string Fmt(Vector3 v)
		{
			return "(" + v.x.ToString("0.####") + ", " + v.y.ToString("0.####") + ", " + v.z.ToString("0.####") + ")";
		}

		internal static void ReportProblem(string message, Exception ex)
		{
			if (_problemCount < 5)
			{
				_problemCount++;
				if (ReloadTriggerWellEnlarger.Logger != null)
				{
					ReloadTriggerWellEnlarger.Logger.LogWarning((object)(message + ": " + ex));
				}
			}
		}

		private static float Safe(float value, float fallback)
		{
			if (float.IsNaN(value) || float.IsInfinity(value) || value == 0f)
			{
				return fallback;
			}
			return value;
		}

		private static string Describe(Transform t)
		{
			try
			{
				return ((Object)t.root).name + "/" + ((Object)t).name;
			}
			catch (Exception)
			{
				return "a reload well";
			}
		}
	}
}