Decompiled source of TheGunWorksNow v2.0.3

Mods/FunctionalShotgun.dll

Decompiled 2 weeks 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.Text;
using System.Text.RegularExpressions;
using FunctionalShotgun;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "TheGunWorksNow", "2.0.3", "you", null)]
[assembly: MelonGame(null, null)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public NullableAttribute(byte b)
		{
		}

		public NullableAttribute(byte[] b)
		{
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public NullableContextAttribute(byte b)
		{
		}
	}
}
namespace FunctionalShotgun
{
	internal static class Bridge
	{
		private sealed class Cand
		{
			public MethodInfo M;

			public object[] Args;

			public int Matched;
		}

		internal const BindingFlags All = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private static List<Type> _types;

		public static string LastErr = "";

		public static object LastRet;

		public static Type PlayerType;

		private static IEnumerable<Type> Types()
		{
			if (_types != null)
			{
				return _types;
			}
			_types = new List<Type>();
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				string name = assembly.GetName().Name;
				if (name.StartsWith("System") || name.StartsWith("Microsoft") || name.StartsWith("Mono.") || name.StartsWith("MelonLoader") || name.StartsWith("0Harmony") || name.StartsWith("Il2CppInterop"))
				{
					continue;
				}
				try
				{
					_types.AddRange(assembly.GetTypes());
				}
				catch (ReflectionTypeLoadException ex)
				{
					_types.AddRange(ex.Types.Where((Type t) => t != null));
				}
				catch
				{
				}
			}
			return _types;
		}

		public static List<Type> TypesWhere(Func<Type, bool> pred)
		{
			List<Type> list = new List<Type>();
			foreach (Type item in Types())
			{
				try
				{
					if (pred(item))
					{
						list.Add(item);
					}
				}
				catch
				{
				}
			}
			return list;
		}

		public static Type FindTypeByMember(params string[] memberNames)
		{
			foreach (string m in memberNames)
			{
				Type type = Types().FirstOrDefault((Type t) => typeof(Object).IsAssignableFrom(t) && t.GetMember(m, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Length != 0);
				if (type != null)
				{
					return type;
				}
			}
			return null;
		}

		public static Type FindTypeByName(string simpleName)
		{
			return Types().FirstOrDefault((Type t) => t.Name == simpleName && typeof(Object).IsAssignableFrom(t));
		}

		public static Type FindTypeAny(string simpleName)
		{
			return Types().FirstOrDefault((Type t) => t.Name == simpleName);
		}

		public static List<object> Instances(Type t)
		{
			List<object> list = new List<object>();
			if (t == null)
			{
				return list;
			}
			try
			{
				foreach (Object item in (Il2CppArrayBase<Object>)(object)Object.FindObjectsOfType(Il2CppType.From(t)))
				{
					if (item != (Object)null)
					{
						list.Add(Activator.CreateInstance(t, ((Il2CppObjectBase)item).Pointer));
					}
				}
			}
			catch (Exception ex)
			{
				Core.Log("Instances(" + t.Name + "): " + ex.Message);
			}
			return list;
		}

		public static List<object> InstancesAll(Type t)
		{
			List<object> list = new List<object>();
			if (t == null)
			{
				return list;
			}
			try
			{
				foreach (Object item in (Il2CppArrayBase<Object>)(object)Resources.FindObjectsOfTypeAll(Il2CppType.From(t)))
				{
					if (item != (Object)null)
					{
						list.Add(Activator.CreateInstance(t, ((Il2CppObjectBase)item).Pointer));
					}
				}
			}
			catch (Exception ex)
			{
				Core.Log("InstancesAll(" + t.Name + "): " + ex.Message);
			}
			return list;
		}

		public static object First(string typeName)
		{
			return Instances(FindTypeByName(typeName)).FirstOrDefault();
		}

		public static object Get(object o, string name)
		{
			if (o == null)
			{
				return null;
			}
			try
			{
				Type type = o.GetType();
				PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if (property != null && property.CanRead)
				{
					return property.GetValue(o);
				}
				FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null)
				{
					return field.GetValue(o);
				}
			}
			catch
			{
			}
			return null;
		}

		public static bool Set(object o, string name, object v)
		{
			if (o == null)
			{
				return false;
			}
			Type type = o.GetType();
			PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null && property.CanWrite)
			{
				property.SetValue(o, Convert.ChangeType(v, property.PropertyType));
				return true;
			}
			FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(o, Convert.ChangeType(v, field.FieldType));
				return true;
			}
			return false;
		}

		public static bool Has(object o, string name)
		{
			if (o == null)
			{
				return false;
			}
			Type type = o.GetType();
			try
			{
				return type.GetProperty(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) != null || type.GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) != null || type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Any((MethodInfo m) => m.Name == name);
			}
			catch
			{
				return false;
			}
		}

		public static string Str(object o)
		{
			try
			{
				return (o == null) ? "" : (o.ToString() ?? "");
			}
			catch
			{
				return "";
			}
		}

		public static bool TryPos(object o, out Vector3 pos)
		{
			//IL_0001: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//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)
			pos = Vector3.zero;
			Component val = (Component)((o is Component) ? o : null);
			if ((Object)(object)val != (Object)null)
			{
				pos = val.transform.position;
				return true;
			}
			GameObject val2 = (GameObject)((o is GameObject) ? o : null);
			if ((Object)(object)val2 != (Object)null)
			{
				pos = val2.transform.position;
				return true;
			}
			return false;
		}

		public static bool Call(object o, string name, params object[] args)
		{
			if (o == null)
			{
				return false;
			}
			MethodInfo methodInfo = o.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo x) => x.Name == name);
			if (methodInfo == null)
			{
				return false;
			}
			try
			{
				ParameterInfo[] parameters = methodInfo.GetParameters();
				object[] array = new object[parameters.Length];
				for (int num = 0; num < parameters.Length; num++)
				{
					Type parameterType = parameters[num].ParameterType;
					if (num < args.Length && args[num] != null)
					{
						array[num] = ConvertArg(args[num], parameterType);
					}
					else
					{
						array[num] = (parameterType.IsValueType ? Activator.CreateInstance(parameterType) : null);
					}
				}
				methodInfo.Invoke(methodInfo.IsStatic ? null : o, array);
				return true;
			}
			catch (Exception ex)
			{
				Core.Log("Call " + name + " failed: " + (ex.InnerException ?? ex).Message);
				return false;
			}
		}

		private static object ConvertArg(object v, Type t)
		{
			if (t.IsEnum)
			{
				if (!(v is string value))
				{
					return Enum.ToObject(t, v);
				}
				return Enum.Parse(t, value);
			}
			if (t.IsAssignableFrom(v.GetType()))
			{
				return v;
			}
			return Convert.ChangeType(v, t);
		}

		private static Cand Build(MethodInfo m, object[] pool)
		{
			ParameterInfo[] parameters = m.GetParameters();
			object[] array = new object[parameters.Length];
			bool[] array2 = new bool[pool.Length];
			int num = 0;
			for (int i = 0; i < parameters.Length; i++)
			{
				Type type = parameters[i].ParameterType;
				if (type.IsByRef)
				{
					type = type.GetElementType();
				}
				int num2 = -1;
				for (int j = 0; j < pool.Length; j++)
				{
					if (num2 >= 0)
					{
						break;
					}
					if (!array2[j] && pool[j] != null && type.IsInstanceOfType(pool[j]))
					{
						num2 = j;
					}
				}
				for (int k = 0; k < pool.Length; k++)
				{
					if (num2 >= 0)
					{
						break;
					}
					if (!array2[k] && pool[k] != null && type.IsPrimitive && pool[k].GetType().IsPrimitive && type == typeof(bool) == pool[k] is bool)
					{
						num2 = k;
					}
				}
				if (num2 >= 0)
				{
					array2[num2] = true;
					num++;
					array[i] = (type.IsInstanceOfType(pool[num2]) ? pool[num2] : Convert.ChangeType(pool[num2], type));
				}
				else if (parameters[i].HasDefaultValue && parameters[i].DefaultValue != null && !(parameters[i].DefaultValue is DBNull))
				{
					array[i] = parameters[i].DefaultValue;
				}
				else
				{
					array[i] = (type.IsValueType ? Activator.CreateInstance(type) : null);
				}
			}
			return new Cand
			{
				M = m,
				Args = array,
				Matched = num
			};
		}

		public static bool CallBest(object o, string name, params object[] pool)
		{
			LastErr = "";
			LastRet = null;
			if (pool == null)
			{
				pool = new object[0];
			}
			if (o == null)
			{
				LastErr = "no target";
				return false;
			}
			List<Cand> list = new List<Cand>();
			MethodInfo[] methods = o.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo in methods)
			{
				if (!(methodInfo.Name != name) && !methodInfo.ContainsGenericParameters)
				{
					try
					{
						list.Add(Build(methodInfo, pool));
					}
					catch (Exception ex)
					{
						LastErr = name + ": " + ex.Message;
					}
				}
			}
			if (list.Count == 0)
			{
				if (LastErr == "")
				{
					LastErr = "no method " + name;
				}
				return false;
			}
			int num = pool.Count((object x) => x != null);
			foreach (Cand item in from x in list
				orderby x.Matched descending, x.Args.Length
				select x)
			{
				if (num <= 0 || item.Matched != 0 || item.Args.Length == 0)
				{
					try
					{
						LastRet = item.M.Invoke(item.M.IsStatic ? null : o, item.Args);
						return true;
					}
					catch (Exception ex2)
					{
						LastErr = name + ": " + (ex2.InnerException ?? ex2).Message;
					}
				}
			}
			if (LastErr == "")
			{
				LastErr = name + ": no matching overload";
			}
			return false;
		}

		public static bool CallAny(object[] targets, string name, params object[] pool)
		{
			foreach (object obj in targets)
			{
				if (obj != null && CallBest(obj, name, pool))
				{
					return true;
				}
			}
			return false;
		}

		public static string CallNet(object[] targets, string baseName, params object[] pool)
		{
			string[] array = ((!IsHost()) ? new string[3]
			{
				"echo_" + baseName,
				"svr_" + baseName,
				baseName
			} : new string[3]
			{
				"svr_" + baseName,
				"echo_" + baseName,
				baseName
			});
			foreach (object obj in targets)
			{
				if (obj == null)
				{
					continue;
				}
				string[] array2 = array;
				foreach (string text in array2)
				{
					if (CallBest(obj, text, pool))
					{
						return text;
					}
				}
			}
			return null;
		}

		public static bool IsHost()
		{
			Type type = FindTypeAny("InstanceFinder");
			if (type == null)
			{
				return false;
			}
			string[] array = new string[3] { "IsServerStarted", "IsServer", "IsHostStarted" };
			foreach (string name in array)
			{
				try
				{
					PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (property != null)
					{
						object value = property.GetValue(null);
						if (value is bool && (bool)value)
						{
							return true;
						}
					}
				}
				catch
				{
				}
			}
			return false;
		}

		public static bool IsOwner(object o)
		{
			object obj = Get(o, "IsOwner");
			bool flag = default(bool);
			int num;
			if (obj is bool)
			{
				flag = (bool)obj;
				num = 1;
			}
			else
			{
				num = 0;
			}
			return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
		}

		public static object LocalOf(Type t)
		{
			List<object> list = Instances(t);
			object obj = list.FirstOrDefault(IsOwner);
			if (obj == null)
			{
				if (list.Count != 1)
				{
					return null;
				}
				obj = list[0];
			}
			return obj;
		}

		public static object Comp(object owner, Type t, bool inChildren)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			Component val = (Component)((owner is Component) ? owner : null);
			if ((Object)(object)val == (Object)null && owner is GameObject)
			{
				val = (Component)(object)((GameObject)owner).transform;
			}
			if ((Object)(object)val == (Object)null || t == null)
			{
				return null;
			}
			try
			{
				Component val2 = (inChildren ? val.GetComponentInChildren(Il2CppType.From(t), true) : val.GetComponentInParent(Il2CppType.From(t)));
				return ((Object)(object)val2 == (Object)null) ? null : Activator.CreateInstance(t, ((Il2CppObjectBase)val2).Pointer);
			}
			catch (Exception ex)
			{
				Core.Log("Comp(" + t.Name + "): " + ex.Message);
				return null;
			}
		}

		public static List<object> Enumerate(object list)
		{
			List<object> list2 = new List<object>();
			if (list == null)
			{
				return list2;
			}
			try
			{
				if (list is IEnumerable enumerable)
				{
					foreach (object item in enumerable)
					{
						list2.Add(item);
					}
					return list2;
				}
				Type type = list.GetType();
				PropertyInfo? obj = type.GetProperty("Count") ?? type.GetProperty("Length");
				MethodInfo method = type.GetMethod("get_Item");
				int num = Convert.ToInt32(obj.GetValue(list));
				for (int i = 0; i < num; i++)
				{
					list2.Add(method.Invoke(list, new object[1] { i }));
				}
			}
			catch (Exception ex)
			{
				Core.Log("Enumerate: " + ex.Message);
			}
			return list2;
		}

		public static object OwnerPlayer(object o)
		{
			if (o == null || PlayerType == null)
			{
				return null;
			}
			if (PlayerType.IsInstanceOfType(o))
			{
				return o;
			}
			return Comp(o, PlayerType, inChildren: false);
		}

		public static bool IsLocal(object o)
		{
			if (o == null)
			{
				return false;
			}
			if (IsOwner(o))
			{
				return true;
			}
			object obj = Comp(o, PlayerType, inChildren: false);
			if (obj != null)
			{
				return IsOwner(obj);
			}
			return false;
		}

		public static string Sig(MethodInfo m)
		{
			try
			{
				return ((m.DeclaringType != null) ? m.DeclaringType.Name : "?") + "." + m.Name + "(" + string.Join(", ", from p in m.GetParameters()
					select p.ParameterType.Name + " " + p.Name) + ") -> " + m.ReturnType.Name;
			}
			catch
			{
				return m.Name;
			}
		}
	}
	public class Core : MelonMod
	{
		private class GunSt
		{
			public int Ammo = -1;

			public bool Reloading;

			public bool Safe;

			public float ReloadDone;

			public float NextShot;

			public int LoadCount = 1;
		}

		private class PH
		{
			public int N;

			public float T;
		}

		private class Bul
		{
			public GameObject Go;

			public LineRenderer Lr;

			public Vector3 A;

			public Vector3 Dir;

			public float Dist;

			public float T;

			public float Speed;

			public float Len;

			public bool Hit;
		}

		private class Fl
		{
			public GameObject Go;

			public object Comp;

			public Light U;

			public float T;

			public float Life;

			public float I0;
		}

		private class Spk
		{
			public GameObject Go;

			public LineRenderer Lr;

			public Vector3 P;

			public Vector3 V;

			public float T;

			public float Life;

			public float Grav;

			public float Drag;

			public float W0;

			public float W1;

			public float Trail;

			public Color C0;

			public Color C1;
		}

		private static Core I;

		private static MelonPreferences_Entry<int> PPellets;

		private static MelonPreferences_Entry<int> PMag;

		private static MelonPreferences_Entry<int> PRemoteBoost;

		private static MelonPreferences_Entry<float> PDamage;

		private static MelonPreferences_Entry<float> PHead;

		private static MelonPreferences_Entry<float> PRange;

		private static MelonPreferences_Entry<float> PSpread;

		private static MelonPreferences_Entry<float> PFireDelay;

		private static MelonPreferences_Entry<float> PReload;

		private static MelonPreferences_Entry<float> PStun;

		private static MelonPreferences_Entry<float> PVolume;

		private static MelonPreferences_Entry<int> PKillAfter;

		private static MelonPreferences_Entry<bool> PInfinite;

		private static MelonPreferences_Entry<bool> PHurtPlayers;

		private static MelonPreferences_Entry<bool> PSuppressClick;

		private static MelonPreferences_Entry<bool> PHud;

		private static MelonPreferences_Entry<bool> PTracers;

		private static MelonPreferences_Entry<bool> PFirecracker;

		private static MelonPreferences_Entry<float> PCloseRange;

		private static MelonPreferences_Entry<float> PCloseMult;

		private static MelonPreferences_Entry<float> PFalloff;

		private static MelonPreferences_Entry<float> PFlashInt;

		private static MelonPreferences_Entry<float> PFlashRange;

		private static MelonPreferences_Entry<float> PBulletSpeed;

		private static MelonPreferences_Entry<float> PBulletLen;

		private static MelonPreferences_Entry<float> PFxScale;

		private static MelonPreferences_Entry<float> PFxSeconds;

		private static MelonPreferences_Entry<float> PFlashDist;

		private static MelonPreferences_Entry<float> PShakeSec;

		private static MelonPreferences_Entry<float> PShakeDeg;

		private static MelonPreferences_Entry<int> PBeads;

		private static MelonPreferences_Entry<int> PSparks;

		private static MelonPreferences_Entry<int> PImpactSparks;

		private static MelonPreferences_Entry<int> PBlood;

		private static MelonPreferences_Entry<float> PSparkSec;

		private static MelonPreferences_Entry<float> PRecoilDeg;

		private static MelonPreferences_Entry<float> PRecoilBack;

		private static MelonPreferences_Entry<float> PPixelSec;

		private static MelonPreferences_Entry<float> PPixelSize;

		private static MelonPreferences_Entry<float> PPelletRadius;

		private static MelonPreferences_Entry<bool> PImpactSmoke;

		private static MelonPreferences_Entry<bool> PDryLocal;

		private static MelonPreferences_Entry<bool> PSilenceDead;

		private static bool _menuOpen;

		private static bool _cFree;

		private static bool _cNoCd;

		private static bool _cMag;

		private static bool _cHurt = true;

		private static bool _cInstant;

		private static MelonPreferences_Entry<float> PBeadHold;

		private static MelonPreferences_Entry<float> PBeadFade;

		private static MelonPreferences_Entry<float> PImpactScale;

		private static MelonPreferences_Entry<float> PImpactSec;

		private static MelonPreferences_Entry<bool> PStartSafe;

		private static MelonPreferences_Entry<bool> PNeedShells;

		private static MelonPreferences_Entry<bool> PAddShop;

		private static MelonPreferences_Entry<int> PShellCost;

		private static MelonPreferences_Entry<int> PShellsPerCase;

		private static MelonPreferences_Entry<string> PFont;

		private static MelonPreferences_Entry<string> PExtraClick;

		private static MelonPreferences_Entry<int> PCloseKillPellets;

		private static object _gun;

		private static float _nextPatchTry;

		private static float _nextAssetScan;

		private static bool _patched;

		private static readonly Dictionary<int, GunSt> _gst = new Dictionary<int, GunSt>();

		private static object _kitFire;

		private static object _kitImpact;

		private static object _kitReload;

		private static AudioClip _clipFire;

		private static AudioClip _clipReload;

		private static float _aiReload = -1f;

		private static Material _tracerMat;

		private static readonly Dictionary<int, int> _aiHits = new Dictionary<int, int>();

		private static MethodInfo _pressReload;

		private static bool _prSearched;

		private static bool _loggedDamageFail;

		private static object _clickKit;

		private static float _clickVol = 1f;

		private static float _muteUntil;

		private static object _gateKit;

		private static float _gateOrig = -1f;

		private static float _gateScan;

		private static float _gateSet = -1f;

		private static bool _gateErr;

		private static int _diagN;

		private static int _buyLog;

		private static bool _justFired;

		private static float _lastLocalShot = -10f;

		private static int _dryLogs;

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

		private static float _sweepUntil;

		private static bool _clickLogged;

		private static bool _stopLogged;

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

		private static int _sendLogs;

		private static readonly Dictionary<int, bool> _fleshCache = new Dictionary<int, bool>();

		private static int _hitboxLogs;

		private static readonly Dictionary<int, PH> _ph = new Dictionary<int, PH>();

		private static int _killLogs;

		private static int _hostKillLogs;

		private static readonly List<object> _aiCache = new List<object>();

		private static readonly Dictionary<int, float> _deadAt = new Dictionary<int, float>();

		private static readonly HashSet<int> _hushed = new HashSet<int>();

		private static float _aiScan;

		private static float _deadScan;

		private static int _hushLogs;

		private static int _remoteLogs;

		private static readonly Dictionary<int, float> _remoteLast = new Dictionary<int, float>();

		private const string ShopName = "shotgun ammo";

		private static object _mineItem;

		private static bool _lookupLogged;

		private static bool _shopHooked;

		private static float _shopNext;

		private static string _shopId = "";

		private static readonly HashSet<int> _itemSnap = new HashSet<int>();

		private static float _despawnFrom = -1f;

		private static float _despawnUntil;

		private static bool _despawnDone;

		private static int _traceN;

		private static object _buyer;

		private static object _standIn;

		private static float _standInAt;

		private static string _saveKey = "(no save yet)";

		private static Dictionary<string, int> _shellsBySave;

		private static bool _saveHooked;

		private static float _saveHookNext;

		private static float _lastDeath;

		private static bool _deadSeen;

		private static float _deadPoll;

		private static bool _deathHooked;

		private static float _deathHookNext;

		private static float _gunScan;

		private GUIStyle _hud;

		private GUIStyle _hudSmall;

		private static Font _font;

		private static float _fontScan;

		private static GameObject _hudGo;

		private static object _hudTmp;

		private static bool _hudFail;

		private static bool _hudReady;

		private static float _hudRetry;

		private static string _hudLast;

		private static readonly Rect _menuRect = new Rect(70f, 70f, 390f, 250f);

		private static readonly string[] BadWords = new string[9] { "reload", "click", "empty", "swing", "cock", "pump", "dry", "melee", "chain" };

		private static readonly List<Bul> _buls = new List<Bul>();

		private static object _fireFx;

		private static float _fxScan;

		private static bool _fxLogged;

		private static bool _poolLogged;

		private static Type _tFL;

		private static float _flInt = -1f;

		private static float _flRange;

		private static float _flScan;

		private static Color _flCol = new Color(1f, 0.72f, 0.35f);

		private static readonly List<Fl> _fls = new List<Fl>();

		private static readonly Regex _smokeRx = new Regex("smoke|dust|fog|cloud|puff|haze|mist", RegexOptions.IgnoreCase);

		private static bool _fxNamesLogged;

		private static readonly List<Spk> _spk = new List<Spk>();

		private static readonly Stack<Spk> _spkFree = new Stack<Spk>();

		private static Material _sparkMat;

		private static float _shakeStart = -10f;

		private static Quaternion _shakeApplied = Quaternion.identity;

		private static Quaternion _shakeSet = Quaternion.identity;

		private static bool _shakeHave;

		private static float _recPitch;

		private static float _recYaw;

		private static int Mag
		{
			get
			{
				if (!_cMag)
				{
					return Math.Max(1, PMag.Value);
				}
				return 999;
			}
		}

		private static GunSt G
		{
			get
			{
				int key = 0;
				object gun = _gun;
				Object val = (Object)((gun is Object) ? gun : null);
				if (val != (Object)null)
				{
					key = val.GetInstanceID();
				}
				if (!_gst.TryGetValue(key, out var value))
				{
					value = new GunSt();
					value.Safe = PStartSafe != null && PStartSafe.Value;
					_gst[key] = value;
				}
				return value;
			}
		}

		private static string ShellFile => Path.Combine(MelonEnvironment.UserDataDirectory, "FunctionalShotgun_shells.txt");

		public static void Log(string s)
		{
			MelonLogger.Msg(s);
		}

		public override void OnInitializeMelon()
		{
			I = this;
			MelonPreferences_Category obj = MelonPreferences.CreateCategory("FunctionalShotgun");
			PPellets = obj.CreateEntry<int>("PelletCount", 12, "Pellets per shot", (string)null, false, false, (ValueValidator)null, (string)null);
			PDamage = obj.CreateEntry<float>("DamagePerPellet", 14f, "Damage per pellet", (string)null, false, false, (ValueValidator)null, (string)null);
			PHead = obj.CreateEntry<float>("HeadshotMultiplier", 1.5f, "Headshot damage multiplier", (string)null, false, false, (ValueValidator)null, (string)null);
			PRange = obj.CreateEntry<float>("Range", 80f, "Max range in metres", (string)null, false, false, (ValueValidator)null, (string)null);
			PSpread = obj.CreateEntry<float>("SpreadWide", 0.13f, "Pellet spread - the wider, the bigger the area a shot can hit (0.075 is about 4 degrees)", (string)null, false, false, (ValueValidator)null, (string)null);
			PFireDelay = obj.CreateEntry<float>("FireDelaySeconds", 0.85f, "Seconds between shots", (string)null, false, false, (ValueValidator)null, (string)null);
			PMag = obj.CreateEntry<int>("MagazineSize", 2, "Shells before a reload", (string)null, false, false, (ValueValidator)null, (string)null);
			PInfinite = obj.CreateEntry<bool>("InfiniteAmmo", false, "Never run out of shells", (string)null, false, false, (ValueValidator)null, (string)null);
			PReload = obj.CreateEntry<float>("ReloadSeconds", 0f, "Reload time (0 = use the Abandoned One's reload time)", (string)null, false, false, (ValueValidator)null, (string)null);
			PHurtPlayers = obj.CreateEntry<bool>("HurtPlayers", false, "Pellets damage other players", (string)null, false, false, (ValueValidator)null, (string)null);
			PStun = obj.CreateEntry<float>("StunMonsterSeconds", 1.2f, "Seconds a monster is stunned per volley that hits it (0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			PKillAfter = obj.CreateEntry<int>("KillMonsterAfterHits", 0, "Host only: kill a monster after this many pellet hits (0 = never)", (string)null, false, false, (ValueValidator)null, (string)null);
			PSuppressClick = obj.CreateEntry<bool>("SilenceDryFireClick", true, "Silence the joke gun's own no-ammo click while the gun has shells (and for other players' shots)", (string)null, false, false, (ValueValidator)null, (string)null);
			PVolume = obj.CreateEntry<float>("Volume", 1f, "Gun sound volume multiplier", (string)null, false, false, (ValueValidator)null, (string)null);
			PRemoteBoost = obj.CreateEntry<int>("RemoteSoundBoost", 3, "How many times louder other players' gunfire is (1-6)", (string)null, false, false, (ValueValidator)null, (string)null);
			PHud = obj.CreateEntry<bool>("ShowAmmoHud", true, "Show shells / reload text while holding the gun", (string)null, false, false, (ValueValidator)null, (string)null);
			PTracers = obj.CreateEntry<bool>("Tracers", true, "Draw pellet tracers", (string)null, false, false, (ValueValidator)null, (string)null);
			PCloseRange = obj.CreateEntry<float>("CloseKillRange", 7f, "Metres: inside this range enough pellets kill the target outright", (string)null, false, false, (ValueValidator)null, (string)null);
			PCloseKillPellets = obj.CreateEntry<int>("CloseKillPellets", 3, "Pellets that must hit one target inside CloseKillRange to kill it", (string)null, false, false, (ValueValidator)null, (string)null);
			PCloseMult = obj.CreateEntry<float>("CloseDamageMultiplier", 5f, "Damage multiplier at point blank (fades to 1x at FalloffRange)", (string)null, false, false, (ValueValidator)null, (string)null);
			PFalloff = obj.CreateEntry<float>("FalloffRange", 30f, "Metres at which the point-blank bonus has faded out", (string)null, false, false, (ValueValidator)null, (string)null);
			PFlashInt = obj.CreateEntry<float>("FlashIntensity", 3f, "Muzzle light intensity (used when the game's own muzzle light can't be copied)", (string)null, false, false, (ValueValidator)null, (string)null);
			PFlashRange = obj.CreateEntry<float>("FlashRange", 14f, "Muzzle light range", (string)null, false, false, (ValueValidator)null, (string)null);
			PBulletSpeed = obj.CreateEntry<float>("BulletSpeed", 170f, "Visual bullet speed (m/s)", (string)null, false, false, (ValueValidator)null, (string)null);
			PBulletLen = obj.CreateEntry<float>("BulletLength", 1.8f, "Visual bullet streak length (m)", (string)null, false, false, (ValueValidator)null, (string)null);
			PFirecracker = obj.CreateEntry<bool>("UseFirecrackerEffect", true, "Reuse the firecrackers' explosion particles for the muzzle flash and impacts", (string)null, false, false, (ValueValidator)null, (string)null);
			PFxScale = obj.CreateEntry<float>("FlashScaleV2", 1.8f, "Size of the reused firecracker flash (1 = the firecracker's normal size)", (string)null, false, false, (ValueValidator)null, (string)null);
			PFlashDist = obj.CreateEntry<float>("FlashDistance", 4f, "How far in front of you (towards where you aim) the flash appears, metres", (string)null, false, false, (ValueValidator)null, (string)null);
			PBeads = obj.CreateEntry<int>("BeadCountV2", 34, "Fast yellow bullet beads that rip past when you fire (0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			PSparks = obj.CreateEntry<int>("MuzzleSparks", 22, "Slower sparks that spray out of the barrel and burn out (0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			PSparkSec = obj.CreateEntry<float>("MuzzleSparkSeconds", 0.55f, "Roughly how long the barrel sparks live before they fade away", (string)null, false, false, (ValueValidator)null, (string)null);
			PImpactSparks = obj.CreateEntry<int>("ImpactSparks", 6, "Sparks thrown off where each pellet hits (0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			PPixelSec = obj.CreateEntry<float>("PixelSecondsV2", 0.55f, "Roughly how long the yellow pixels fly before they fade away", (string)null, false, false, (ValueValidator)null, (string)null);
			PPixelSize = obj.CreateEntry<float>("PixelSize", 1f, "Size multiplier for all the little pixels (1 = normal)", (string)null, false, false, (ValueValidator)null, (string)null);
			PBlood = obj.CreateEntry<int>("BloodParticles", 4, "Blood specks per hit on a monster or player (0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			PRecoilDeg = obj.CreateEntry<float>("RecoilDegrees", 2.6f, "How far the camera kicks up when you fire (0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			PRecoilBack = obj.CreateEntry<float>("RecoilRecoverSpeed", 13f, "How fast the camera settles back after the kick (higher = quicker)", (string)null, false, false, (ValueValidator)null, (string)null);
			PSilenceDead = obj.CreateEntry<bool>("SilenceDeadMonsters", true, "Game bug fix: shut up dead monsters still revving chainsaws / playing radio chatter", (string)null, false, false, (ValueValidator)null, (string)null);
			PShakeSec = obj.CreateEntry<float>("ShakeSeconds", 0.5f, "Camera shake length when you fire (0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			PShakeDeg = obj.CreateEntry<float>("ShakeDegrees", 1.6f, "Camera shake strength in degrees", (string)null, false, false, (ValueValidator)null, (string)null);
			PBeadHold = obj.CreateEntry<float>("BeadHoldSeconds", 0.1f, "Seconds the yellow beads stay fully bright", (string)null, false, false, (ValueValidator)null, (string)null);
			PBeadFade = obj.CreateEntry<float>("BeadFadeSeconds", 0.1f, "Seconds the yellow beads then take to fade out", (string)null, false, false, (ValueValidator)null, (string)null);
			PImpactScale = obj.CreateEntry<float>("ImpactExplosionScaleV2", 1f, "Size of the firecracker pop where pellets hit", (string)null, false, false, (ValueValidator)null, (string)null);
			PDryLocal = obj.CreateEntry<bool>("KeepDryClicksLocal", true, "An empty / blocked click is not sent to other players (so they never see a phantom shot)", (string)null, false, false, (ValueValidator)null, (string)null);
			PImpactSmoke = obj.CreateEntry<bool>("ImpactSmoke", false, "Keep the firecracker smoke on pellet hits (off = just the pop)", (string)null, false, false, (ValueValidator)null, (string)null);
			PPelletRadius = obj.CreateEntry<float>("PelletRadius", 0.07f, "Pellet thickness in metres for hitting monsters/players (0 = thin ray)", (string)null, false, false, (ValueValidator)null, (string)null);
			PImpactSec = obj.CreateEntry<float>("ImpactExplosionSeconds", 0.2f, "How long the tiny hit explosions last", (string)null, false, false, (ValueValidator)null, (string)null);
			PStartSafe = obj.CreateEntry<bool>("StartWithSafetyOn", false, "Safety starts switched on (U toggles it while holding the gun)", (string)null, false, false, (ValueValidator)null, (string)null);
			PNeedShells = obj.CreateEntry<bool>("NeedShellsToReload", true, "Reloading uses shells bought at the supplier (false = unlimited free shells)", (string)null, false, false, (ValueValidator)null, (string)null);
			PAddShop = obj.CreateEntry<bool>("AddShopItem", true, "Add 'shotgun ammo' to the ECD supplier's shop", (string)null, false, false, (ValueValidator)null, (string)null);
			PShellCost = obj.CreateEntry<int>("ShellCaseCost2", 8000, "Price of one shell case at the supplier", (string)null, false, false, (ValueValidator)null, (string)null);
			PShellsPerCase = obj.CreateEntry<int>("ShellsPerCase", 2, "Shells you get per case bought", (string)null, false, false, (ValueValidator)null, (string)null);
			PFont = obj.CreateEntry<string>("HudFontName", "", "Part of a font name to force for the on-screen text (empty = copy the game's UI font)", (string)null, false, false, (ValueValidator)null, (string)null);
			PExtraClick = obj.CreateEntry<string>("ExtraClickClipNames", "", "Comma separated clip names to also silence (see 'Playing during shot' lines in the log)", (string)null, false, false, (ValueValidator)null, (string)null);
			PFxSeconds = obj.CreateEntry<float>("FlashSeconds", 0.1f, "How long the firecracker flash is visible, in seconds", (string)null, false, false, (ValueValidator)null, (string)null);
			LoadShells();
			((MelonBase)this).LoggerInstance.Msg("TheGunWorksNow 2.0.3 loaded. Equip the shotgun and left click.");
		}

		private void TryPatch()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			if (_patched || Time.realtimeSinceStartup < _nextPatchTry)
			{
				return;
			}
			_nextPatchTry = Time.realtimeSinceStartup + 3f;
			Type type = Bridge.FindTypeByName("FFShotgun");
			if (type == null)
			{
				return;
			}
			_patched = true;
			int num = 0;
			HarmonyMethod val = new HarmonyMethod(typeof(Core).GetMethod("UsedPostfix", BindingFlags.Static | BindingFlags.NonPublic));
			HarmonyMethod val2 = new HarmonyMethod(typeof(Core).GetMethod("UsePrefix", BindingFlags.Static | BindingFlags.NonPublic));
			HarmonyMethod val3 = new HarmonyMethod(typeof(Core).GetMethod("EchoPrefix", BindingFlags.Static | BindingFlags.NonPublic));
			HarmonyMethod val4 = new HarmonyMethod(typeof(Core).GetMethod("EquipPostfix", BindingFlags.Static | BindingFlags.NonPublic));
			HarmonyMethod val5 = new HarmonyMethod(typeof(Core).GetMethod("RemotePrefix", BindingFlags.Static | BindingFlags.NonPublic));
			HarmonyMethod val6 = new HarmonyMethod(typeof(Core).GetMethod("RemotePostfix", BindingFlags.Static | BindingFlags.NonPublic));
			MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo in methods)
			{
				try
				{
					if (methodInfo.Name == "OnEquipmentUsed")
					{
						((MelonBase)this).HarmonyInstance.Patch((MethodBase)methodInfo, val2, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						num++;
						Log("Hooked " + methodInfo.Name);
					}
					else if (methodInfo.Name == "echo_TryShoot")
					{
						((MelonBase)this).HarmonyInstance.Patch((MethodBase)methodInfo, val3, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						num++;
						Log("Hooked " + methodInfo.Name + " (dry clicks stay local)");
					}
					else if (methodInfo.Name == "local_OnEquip")
					{
						((MelonBase)this).HarmonyInstance.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val4, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						num++;
						Log("Hooked " + methodInfo.Name);
					}
					else if (methodInfo.Name.StartsWith("RpcLogic___obr_TryShoot") || methodInfo.Name.StartsWith("RpcReader___Observers_obr_TryShoot") || methodInfo.Name == "obr_TryShoot" || methodInfo.Name == "svr_TryShoot" || methodInfo.Name.StartsWith("RpcLogic___svr_TryShoot"))
					{
						((MelonBase)this).HarmonyInstance.Patch((MethodBase)methodInfo, val5, val6, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						num++;
						Log("Hooked " + methodInfo.Name);
					}
				}
				catch (Exception ex)
				{
					Log("Hook failed " + methodInfo.Name + ": " + ex.Message);
				}
			}
			Log("Shotgun hooks installed: " + num + " (expected 4)");
		}

		private static void SetClickVolume(object gun, bool mute)
		{
		}

		private static void ClickGate()
		{
			try
			{
				if (!PSuppressClick.Value)
				{
					return;
				}
				if (_gateKit == null || (Object)/*isinst with value type is only supported in some contexts*/ == (Object)null)
				{
					if (Time.realtimeSinceStartup < _gateScan)
					{
						return;
					}
					_gateScan = Time.realtimeSinceStartup + 1f;
					Type type = Bridge.FindTypeByName("FFShotgun");
					if (type == null)
					{
						return;
					}
					object obj = _gun ?? Bridge.Instances(type).FirstOrDefault() ?? Bridge.InstancesAll(type).FirstOrDefault();
					if (obj == null)
					{
						return;
					}
					_gateKit = Bridge.Get(obj, "noAmmoClick");
					if (_gateKit == null)
					{
						return;
					}
					object obj2 = Bridge.Get(_gateKit, "volume");
					_gateOrig = ((obj2 is float && (float)obj2 > 0f) ? ((float)obj2) : 0.3f);
					Log("Dry-fire click kit found (volume " + _gateOrig + "); it will be silenced except when your shotgun is empty.");
				}
				float num = ((_gun != null && GunActive() && !G.Reloading && !G.Safe && !PInfinite.Value && G.Ammo == 0) ? _gateOrig : 0f);
				if (Mathf.Abs(num - _gateSet) > 0.0001f)
				{
					Bridge.Set(_gateKit, "volume", num);
					_gateSet = num;
				}
			}
			catch (Exception ex)
			{
				if (!_gateErr)
				{
					_gateErr = true;
					Log("ClickGate: " + ex.Message);
				}
			}
		}

		private static bool WillFire(object gun)
		{
			try
			{
				object obj = Bridge.Get(gun, "ffPlayer") ?? Bridge.Get(gun, "Actor");
				if (obj != null && !Bridge.IsOwner(obj))
				{
					return false;
				}
				if (G.Safe)
				{
					return true;
				}
				if (G.Reloading || Time.time < G.NextShot)
				{
					return false;
				}
				return PInfinite.Value || G.Ammo != 0;
			}
			catch
			{
				return false;
			}
		}

		private static bool EchoPrefix(object __instance)
		{
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			UsePrefix(__instance);
			try
			{
				if (PDryLocal == null || !PDryLocal.Value)
				{
					return true;
				}
				object obj = Bridge.Get(__instance, "ffPlayer") ?? Bridge.Get(__instance, "Actor");
				if (obj != null && !Bridge.IsOwner(obj))
				{
					return true;
				}
				if (G.Ammo < 0)
				{
					G.Ammo = ((!PNeedShells.Value) ? Math.Max(1, Mag) : 0);
				}
				if (!_menuOpen && !G.Safe && !G.Reloading && Time.time >= G.NextShot && (PInfinite.Value || G.Ammo > 0))
				{
					return true;
				}
				if (Time.time - _lastLocalShot < 0.25f)
				{
					return false;
				}
				bool flag = !_menuOpen && !G.Safe && !G.Reloading && !PInfinite.Value && G.Ammo <= 0;
				if (flag && I != null)
				{
					Component val = (Component)((__instance is Component) ? __instance : null);
					I.PlaySound(Bridge.Get(__instance, "noAmmoClick"), null, ((Object)(object)val != (Object)null) ? val.transform.position : (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform.position : Vector3.zero));
				}
				if (_dryLogs++ < 4)
				{
					Log("Click without a shot kept local (" + (flag ? "empty" : (G.Safe ? "safety on" : (G.Reloading ? "reloading" : "cooldown"))) + ") - other players won't see it.");
				}
				return false;
			}
			catch
			{
				return true;
			}
		}

		private static void UsePrefix(object __instance)
		{
			try
			{
				object obj = Bridge.Get(__instance, "ffPlayer") ?? Bridge.Get(__instance, "Actor");
				if (obj == null || Bridge.IsOwner(obj))
				{
					_gun = __instance;
				}
			}
			catch
			{
			}
			if (PSuppressClick.Value)
			{
				if (_diagN++ < 6)
				{
					Log("UsePrefix: willFire=" + WillFire(__instance) + " ammo=" + G.Ammo + " reloading=" + G.Reloading + " safe=" + G.Safe + " nextShot-in=" + (G.NextShot - Time.time));
				}
				if (WillFire(__instance))
				{
					SetClickVolume(__instance, mute: true);
					_muteUntil = Time.time + 1.2f;
					StartSweep(__instance);
				}
			}
		}

		private static void CollectClickClips(object gun)
		{
			try
			{
				object kit = Bridge.Get(gun, "noAmmoClick");
				if (kit == null)
				{
					if (!_clickLogged)
					{
						_clickLogged = true;
						Log("CollectClickClips: this gun has no noAmmoClick kit.");
					}
					return;
				}
				int count = _clickNames.Count;
				for (int i = 0; i < 8; i++)
				{
					if (Bridge.CallBest(kit, "GetRandomSound"))
					{
						object lastRet = Bridge.LastRet;
						AudioClip val = (AudioClip)((lastRet is AudioClip) ? lastRet : null);
						if ((Object)(object)val != (Object)null)
						{
							_clickNames.Add(((Object)val).name);
						}
					}
				}
				FieldInfo[] fields = kit.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo f in fields)
				{
					AddClipsFrom(SafeGet(() => f.GetValue(kit)));
				}
				PropertyInfo[] properties = kit.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (PropertyInfo pr in properties)
				{
					if (pr.GetIndexParameters().Length == 0)
					{
						AddClipsFrom(SafeGet(() => pr.GetValue(kit, null)));
					}
				}
				if (!_clickLogged || _clickNames.Count != count)
				{
					_clickLogged = true;
					Log("Click kit clips: " + ((_clickNames.Count == 0) ? "(none found, using name matching)" : string.Join(", ", _clickNames)));
				}
			}
			catch (Exception ex)
			{
				if (!_clickLogged)
				{
					_clickLogged = true;
					Log("CollectClickClips: " + ex.Message);
				}
			}
		}

		private static object SafeGet(Func<object> f)
		{
			try
			{
				return f();
			}
			catch
			{
				return null;
			}
		}

		private static void AddClipsFrom(object v)
		{
			if (v == null)
			{
				return;
			}
			AudioClip val = (AudioClip)((v is AudioClip) ? v : null);
			if ((Object)(object)val != (Object)null)
			{
				_clickNames.Add(((Object)val).name);
			}
			else
			{
				if (v is string || v is float || v is int || v is bool)
				{
					return;
				}
				try
				{
					foreach (object item in Bridge.Enumerate(v))
					{
						AudioClip val2 = (AudioClip)((item is AudioClip) ? item : null);
						if ((Object)(object)val2 != (Object)null)
						{
							_clickNames.Add(((Object)val2).name);
						}
					}
				}
				catch
				{
				}
			}
		}

		private static void StartSweep(object gun)
		{
			CollectClickClips(gun);
			_sweepUntil = Time.time + 0.7f;
			SweepClicks();
		}

		private static bool IsClickName(string n)
		{
			if (string.IsNullOrEmpty(n))
			{
				return false;
			}
			if (_clickNames.Contains(n))
			{
				return true;
			}
			string text = n.ToLowerInvariant();
			if (!text.Contains("click") && !text.Contains("dryfire") && !text.Contains("dry_fire"))
			{
				return text.Contains("empty");
			}
			return true;
		}

		private static void SweepClicks()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				object gun = _gun;
				Transform val = (((Object)((gun is Component) ? gun : null) != (Object)null) ? ((Component)_gun).transform : null);
				string text = (PExtraClick.Value ?? "").ToLowerInvariant();
				foreach (object item in Bridge.InstancesAll(typeof(AudioSource)))
				{
					AudioSource val2 = (AudioSource)((item is AudioSource) ? item : null);
					if ((Object)(object)val2 == (Object)null || !val2.isPlaying)
					{
						continue;
					}
					AudioClip clip = val2.clip;
					if ((Object)(object)clip == (Object)null)
					{
						continue;
					}
					string name = ((Object)clip).name;
					bool flag = (Object)(object)val != (Object)null && ((Component)val2).transform.IsChildOf(val);
					if (_seenPlaying.Count < 30 && _seenPlaying.Add(name + "|" + ((Object)((Component)val2).gameObject).name))
					{
						Log("Playing during shot: clip '" + name + "' on '" + ((Object)((Component)val2).gameObject).name + "'" + (flag ? " (on the gun)" : ""));
					}
					bool flag2 = IsClickName(name) || flag;
					if (!flag2 && text.Length > 0)
					{
						string[] array = text.Split(',');
						for (int i = 0; i < array.Length; i++)
						{
							string text2 = array[i].Trim();
							if (text2.Length > 0 && name.ToLowerInvariant().Contains(text2))
							{
								flag2 = true;
							}
						}
					}
					if (flag2)
					{
						val2.Stop();
						if (!_stopLogged)
						{
							_stopLogged = true;
							Log("Stopped the joke gun's click (" + name + ").");
						}
					}
				}
			}
			catch
			{
			}
		}

		public override void OnLateUpdate()
		{
			if (Time.time < _sweepUntil)
			{
				SweepClicks();
			}
			UpdateShake();
		}

		private static void UsedPostfix(object __instance)
		{
			if (I != null)
			{
				I.TryFire(__instance);
				if (PSuppressClick.Value && (_justFired || G.Safe || G.Ammo > 0))
				{
					_justFired = false;
					StartSweep(__instance);
				}
			}
		}

		private static void EquipPostfix(object __instance)
		{
			_gun = __instance;
			if (G.Ammo < 0)
			{
				G.Ammo = ((!PNeedShells.Value) ? Math.Max(1, Mag) : 0);
			}
		}

		private static bool RemotePrefix(object __instance, MethodBase __originalMethod, out bool __state)
		{
			__state = false;
			try
			{
				if (I != null)
				{
					I.RemoteShot(__instance, (__originalMethod != null) ? __originalMethod.Name : "?");
				}
				object obj = Bridge.Get(__instance, "ffPlayer") ?? Bridge.Get(__instance, "Actor");
				bool flag = obj != null && Bridge.IsOwner(obj);
				if (PSuppressClick.Value && (!flag || Time.time < _muteUntil))
				{
					SetClickVolume(__instance, mute: true);
					__state = true;
					StartSweep(__instance);
				}
			}
			catch (Exception ex)
			{
				Log("RemoteShot: " + ex.Message);
			}
			return true;
		}

		private static void RemotePostfix(object __instance, bool __state)
		{
			if (__state && !(Time.time < _muteUntil))
			{
				SetClickVolume(__instance, mute: false);
			}
		}

		private object OwnerOf(object gun)
		{
			return Bridge.Get(gun, "ffPlayer") ?? Bridge.Get(gun, "Actor");
		}

		private void TryFire(object gun)
		{
			try
			{
				object obj = OwnerOf(gun);
				if (_menuOpen || (obj != null && !Bridge.IsOwner(obj)))
				{
					return;
				}
				if (obj == null)
				{
					object obj2 = Bridge.Get(gun, "IsEquipped");
					if (!(obj2 is bool) || !(bool)obj2)
					{
						return;
					}
					obj = Bridge.LocalOf(Bridge.FindTypeByName("FFPlayer"));
				}
				_gun = gun;
				if (G.Ammo < 0)
				{
					G.Ammo = ((!PNeedShells.Value) ? Math.Max(1, Mag) : 0);
				}
				float time = Time.time;
				if (time < G.NextShot || G.Reloading || G.Safe || (!PInfinite.Value && G.Ammo <= 0))
				{
					return;
				}
				G.NextShot = (_cNoCd ? 0f : (time + Mathf.Max(0.05f, PFireDelay.Value)));
				if (!PInfinite.Value)
				{
					G.Ammo--;
				}
				_lastLocalShot = Time.time;
				Fire(obj);
				try
				{
					bool flag = Bridge.CallBest(gun, "svr_TryShoot");
					if (_sendLogs++ < 6)
					{
						Log("Shot announced to other players: " + flag + (flag ? "" : (" (" + Bridge.LastErr + ")")));
					}
				}
				catch (Exception ex)
				{
					if (_sendLogs++ < 6)
					{
						Log("Announce failed: " + ex.Message);
					}
				}
			}
			catch (Exception ex2)
			{
				Log("TryFire: " + ex2);
			}
		}

		private void Fire(object ffPlayer)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if (!((Object)(object)main == (Object)null))
			{
				Transform transform = ((Component)main).transform;
				Vector3 position = transform.position;
				Vector3 val = position + transform.forward * 0.9f + transform.right * 0.18f - transform.up * 0.12f;
				FindAssets();
				_justFired = true;
				PlaySound(_kitFire, _clipFire, val);
				MuzzleFlash(val, transform.forward);
				Beads(val + transform.forward * 0.8f, transform.forward);
				StartShake();
				StartRecoil();
				Component val2 = (Component)((ffPlayer is Component) ? ffPlayer : null);
				Transform selfT = (((Object)(object)val2 != (Object)null) ? val2.transform : null);
				HashSet<int> aiThisShot = new HashSet<int>();
				Dictionary<int, int> closeHits = new Dictionary<int, int>();
				HashSet<int> killed = new HashSet<int>();
				int num = Math.Max(1, PPellets.Value);
				for (int i = 0; i < num; i++)
				{
					Vector3 val3 = transform.forward + Random.insideUnitSphere * PSpread.Value;
					Vector3 normalized = ((Vector3)(ref val3)).normalized;
					Pellet(position, normalized, val, selfT, ffPlayer, aiThisShot, closeHits, killed, i);
				}
			}
		}

		private void Pellet(Vector3 origin, Vector3 dir, Vector3 muzzle, Transform selfT, object ffPlayer, HashSet<int> aiThisShot, Dictionary<int, int> closeHits, HashSet<int> killed, int index)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_005c: 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)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(5f, PRange.Value);
			if (!CastPellet(origin, dir, num, selfT, out var bh))
			{
				Bullet(muzzle, origin + dir * Mathf.Min(num, 60f), hit: false);
				return;
			}
			Bullet(muzzle, ((RaycastHit)(ref bh)).point, hit: true);
			if (index % 2 == 0)
			{
				ImpactFx(((RaycastHit)(ref bh)).point + ((RaycastHit)(ref bh)).normal * 0.05f, ((RaycastHit)(ref bh)).normal);
				PlaySound(_kitImpact, null, ((RaycastHit)(ref bh)).point);
			}
			ApplyHit(((RaycastHit)(ref bh)).collider, ffPlayer, aiThisShot, closeHits, killed, ((RaycastHit)(ref bh)).distance, ((RaycastHit)(ref bh)).point, ((RaycastHit)(ref bh)).normal, dir, index);
		}

		private static bool FleshCached(Collider col)
		{
			int instanceID = ((Object)col).GetInstanceID();
			if (_fleshCache.TryGetValue(instanceID, out var value))
			{
				return value;
			}
			if (_fleshCache.Count > 3000)
			{
				_fleshCache.Clear();
			}
			value = IsFlesh(col);
			_fleshCache[instanceID] = value;
			return value;
		}

		private bool CastPellet(Vector3 origin, Vector3 dir, float range, Transform selfT, out RaycastHit bh)
		{
			//IL_0002: 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)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_00e6: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			bh = default(RaycastHit);
			float num = float.MaxValue;
			bool flag = false;
			Il2CppStructArray<RaycastHit> val = Physics.RaycastAll(origin, dir, range, -1, (QueryTriggerInteraction)2);
			for (int i = 0; i < ((Il2CppArrayBase<RaycastHit>)(object)val).Length; i++)
			{
				RaycastHit val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[i];
				Collider collider = ((RaycastHit)(ref val2)).collider;
				if (!((Object)(object)collider == (Object)null) && !(((RaycastHit)(ref val2)).distance <= 0.02f) && !(((RaycastHit)(ref val2)).distance >= num) && (!((Object)(object)selfT != (Object)null) || !((Component)collider).transform.IsChildOf(selfT)) && ((!collider.isTrigger && ((Component)collider).gameObject.layer != 2) || FleshCached(collider) || (collider.isTrigger && ClosedDoor(collider))))
				{
					num = ((RaycastHit)(ref val2)).distance;
					bh = val2;
					flag = true;
				}
			}
			float value = PPelletRadius.Value;
			if (value > 0.001f)
			{
				Il2CppStructArray<RaycastHit> val3 = Physics.SphereCastAll(origin, value, dir, range, -1, (QueryTriggerInteraction)2);
				for (int j = 0; j < ((Il2CppArrayBase<RaycastHit>)(object)val3).Length; j++)
				{
					RaycastHit val4 = ((Il2CppArrayBase<RaycastHit>)(object)val3)[j];
					Collider collider2 = ((RaycastHit)(ref val4)).collider;
					if (!((Object)(object)collider2 == (Object)null) && !(((RaycastHit)(ref val4)).distance <= 0.02f) && !(((RaycastHit)(ref val4)).distance >= num) && (!((Object)(object)selfT != (Object)null) || !((Component)collider2).transform.IsChildOf(selfT)) && FleshCached(collider2))
					{
						num = ((RaycastHit)(ref val4)).distance;
						bh = val4;
						flag = true;
					}
				}
			}
			if (flag && _hitboxLogs < 8 && (Object)(object)((RaycastHit)(ref bh)).collider != (Object)null && (((RaycastHit)(ref bh)).collider.isTrigger || ((Component)((RaycastHit)(ref bh)).collider).gameObject.layer == 2) && FleshCached(((RaycastHit)(ref bh)).collider))
			{
				_hitboxLogs++;
				Log("Pellet hit a hitbox the old version ignored: '" + ((Object)((Component)((RaycastHit)(ref bh)).collider).gameObject).name + "' (trigger=" + ((RaycastHit)(ref bh)).collider.isTrigger + ", layer " + ((Component)((RaycastHit)(ref bh)).collider).gameObject.layer + ")");
			}
			return flag;
		}

		private static bool ClosedDoor(Collider col)
		{
			try
			{
				Type type = Bridge.FindTypeByName("FairyDoor");
				if (type == null)
				{
					return false;
				}
				object obj = Bridge.Comp(col, type, inChildren: false);
				if (obj == null)
				{
					return false;
				}
				object obj2 = Bridge.Get(obj, "Open");
				object obj3 = Bridge.Get(obj, "Opening");
				return obj2 is bool && !(bool)obj2 && (!(obj3 is bool) || !(bool)obj3);
			}
			catch
			{
				return false;
			}
		}

		private void ApplyHit(Collider col, object ffPlayer, HashSet<int> aiThisShot, Dictionary<int, int> closeHits, HashSet<int> killed, float dist, Vector3 hitPos, Vector3 hitNormal, Vector3 dir, int index)
		{
			//IL_00e5: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			Type t = Bridge.FindTypeByName("FairyConditionLink");
			Type t2 = Bridge.FindTypeByName("FairyCondition");
			Type t3 = Bridge.FindTypeByName("FFAICore") ?? Bridge.FindTypeByName("FairyAICore");
			Type t4 = Bridge.FindTypeByName("FFPlayer");
			Type t5 = Bridge.FindTypeByName("FairyObject");
			object obj = Bridge.Comp(col, t, inChildren: false);
			object obj2 = ((obj != null) ? Bridge.Get(obj, "LinkedToCondition") : null);
			bool flag = false;
			if (obj != null)
			{
				object obj3 = Bridge.Get(obj, "head");
				flag = obj3 is bool && (bool)obj3;
			}
			if (obj2 == null)
			{
				obj2 = Bridge.Comp(col, t2, inChildren: false);
			}
			object obj4 = Bridge.Comp(col, t5, inChildren: false);
			if (obj2 == null && obj4 != null)
			{
				obj2 = Bridge.Get(obj4, "Condition");
			}
			object obj5 = Bridge.Comp(col, t4, inChildren: false);
			object obj6 = Bridge.Comp(col, t3, inChildren: false);
			if (index % 3 == 0 && (obj6 != null || obj5 != null || obj != null))
			{
				BloodFx(hitPos, -dir, hitNormal);
			}
			if (obj5 != null)
			{
				if (_cHurt)
				{
					HitPlayer(obj5, obj2, aiThisShot, ffPlayer);
				}
				return;
			}
			float num = Mathf.Clamp01(dist / Mathf.Max(1f, PFalloff.Value));
			float num2 = Mathf.Lerp(Mathf.Max(1f, PCloseMult.Value), 1f, num);
			if (obj2 != null)
			{
				DealDamage(obj2, PDamage.Value * (flag ? PHead.Value : 1f) * num2, ffPlayer);
			}
			if (obj6 != null)
			{
				HitMonster(obj6, aiThisShot);
			}
			if (obj2 == null || !(dist <= PCloseRange.Value) || PCloseKillPellets.Value <= 0)
			{
				return;
			}
			Object val = (Object)(((obj6 ?? obj2) is Object) ? (obj6 ?? obj2) : null);
			int num3 = ((val != (Object)null) ? val.GetInstanceID() : 0);
			if (num3 != 0 && !killed.Contains(num3))
			{
				closeHits.TryGetValue(num3, out var value);
				value = (closeHits[num3] = value + 1);
				if (value >= PCloseKillPellets.Value)
				{
					killed.Add(num3);
					Execute(obj2, obj6);
				}
			}
		}

		private void HitPlayer(object victim, object cond, HashSet<int> volley, object attacker)
		{
			try
			{
				Object val = (Object)((victim is Object) ? victim : null);
				int num = ((val != (Object)null) ? val.GetInstanceID() : 0);
				if (num == 0 || !volley.Add(-num))
				{
					return;
				}
				if (!_ph.TryGetValue(num, out var value))
				{
					value = new PH();
					_ph[num] = value;
				}
				if (Time.time - value.T > 90f)
				{
					value.N = 0;
				}
				value.T = Time.time;
				value.N++;
				object obj = cond ?? Bridge.Get(victim, "Condition") ?? Bridge.Comp(victim, Bridge.FindTypeByName("FairyCondition"), inChildren: true);
				object[] targets = new object[2] { victim, obj };
				if (value.N == 1)
				{
					if (!InvokeByWords(targets, "Bleeding", new string[1] { "bleed" }, new string[8] { "stop", "remove", "heal", "cure", "clear", "cancel", "reduce", "end" }, new string[10] { "get_", "set_", "On", "Rpc", "can", "Can", "is", "Is", "has", "Has" }))
					{
						Log("Shot player #1: no bleeding method found - small damage instead.");
						if (obj != null)
						{
							DealDamage(obj, 12f, attacker);
						}
					}
				}
				else if (value.N == 2)
				{
					if (!InvokeByWords(targets, "Downed", new string[4] { "downed", "incapacit", "knockdown", "setdown" }, new string[8] { "stop", "revive", "undown", "load", "count", "up", "cure", "heal" }, new string[10] { "get_", "set_", "On", "Rpc", "can", "Can", "is", "Is", "has", "Has" }))
					{
						Log("Shot player #2: no downed method found - heavy damage instead.");
						object obj2 = ((obj != null) ? Bridge.Get(obj, "hp") : null);
						if (obj != null)
						{
							DealDamage(obj, ((obj2 is float) ? ((float)obj2) : 100f) * 0.9f, attacker);
						}
					}
				}
				else
				{
					value.N = 0;
					Log("Shot player #3: killing.");
					if (obj != null)
					{
						Execute(obj, null);
					}
				}
			}
			catch (Exception ex)
			{
				Log("HitPlayer: " + ex.Message);
			}
		}

		private static bool InvokeByWords(object[] targets, string label, string[] must, string[] not, string[] notStart)
		{
			try
			{
				bool host = Bridge.IsHost();
				List<KeyValuePair<object, MethodInfo>> list = new List<KeyValuePair<object, MethodInfo>>();
				foreach (object obj in targets)
				{
					if (obj == null)
					{
						continue;
					}
					MethodInfo[] methods = obj.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (MethodInfo methodInfo in methods)
					{
						string n = methodInfo.Name;
						string l = n.ToLowerInvariant();
						if (must.Any((string x) => l.Contains(x)) && !not.Any((string x) => l.Contains(x)) && !notStart.Any((string x) => n.StartsWith(x)))
						{
							ParameterInfo[] parameters = methodInfo.GetParameters();
							if (parameters.Length <= 1 && (parameters.Length != 1 || !(parameters[0].ParameterType != typeof(float)) || !(parameters[0].ParameterType != typeof(bool)) || !(parameters[0].ParameterType != typeof(int))))
							{
								list.Add(new KeyValuePair<object, MethodInfo>(obj, methodInfo));
							}
						}
					}
				}
				Func<string, int> rank = delegate(string text)
				{
					if (!host)
					{
						if (!text.StartsWith("echo_") && !text.StartsWith("svr_"))
						{
							if (!text.StartsWith("sv_"))
							{
								if (!text.StartsWith("obr_"))
								{
									return 1;
								}
								return 3;
							}
							return 2;
						}
						return 0;
					}
					return (!text.StartsWith("sv_") && !text.StartsWith("svr_")) ? ((!text.StartsWith("echo_")) ? ((!text.StartsWith("obr_")) ? 1 : 3) : 2) : 0;
				};
				foreach (KeyValuePair<object, MethodInfo> item in list.OrderBy((KeyValuePair<object, MethodInfo> c) => rank(c.Value.Name)))
				{
					try
					{
						ParameterInfo[] parameters2 = item.Value.GetParameters();
						object[] parameters3 = null;
						if (parameters2.Length == 1)
						{
							parameters3 = new object[1] { (parameters2[0].ParameterType == typeof(float)) ? ((object)60f) : ((parameters2[0].ParameterType == typeof(bool)) ? ((object)true) : ((object)1)) };
						}
						item.Value.Invoke(item.Key, parameters3);
						Log(label + ": called " + item.Key.GetType().Name + "." + item.Value.Name);
						return true;
					}
					catch (Exception ex)
					{
						Log(label + ": " + item.Value.Name + " failed: " + ex.Message);
					}
				}
				Log(label + ": candidates tried: " + list.Count);
			}
			catch (Exception ex2)
			{
				Log("InvokeByWords: " + ex2.Message);
			}
			return false;
		}

		private void Execute(object cond, object ai)
		{
			bool flag = false;
			if (Bridge.IsHost())
			{
				if (ai != null)
				{
					flag = Bridge.CallBest(ai, "Die");
				}
				if (!flag)
				{
					flag = Bridge.CallBest(cond, "Kill");
				}
				if (!flag)
				{
					flag = Bridge.CallBest(cond, "Die");
				}
			}
			if (!flag)
			{
				object obj = Bridge.Get(cond, "hp");
				float num = ((obj is float) ? ((float)obj) : 1000f) + 1000f;
				flag = Bridge.CallBest(cond, "echo_SubtractHp", num);
				if (!Bridge.IsHost())
				{
					StringBuilder stringBuilder = new StringBuilder();
					object[] array = new object[2] { ai, cond };
					foreach (object obj2 in array)
					{
						if (obj2 == null)
						{
							continue;
						}
						string[] array2 = new string[8] { "echo_Die", "svr_Die", "echo_Kill", "svr_Kill", "echo_Death", "svr_Death", "echo_SetDead", "svr_SetDead" };
						foreach (string text in array2)
						{
							if (Bridge.CallBest(obj2, text))
							{
								stringBuilder.Append(obj2.GetType().Name + "." + text + " ");
							}
						}
						array2 = new string[3] { "svr_SubtractHp", "svr_Damage", "echo_Damage" };
						foreach (string text2 in array2)
						{
							if (Bridge.CallBest(obj2, text2, num))
							{
								stringBuilder.Append(obj2.GetType().Name + "." + text2 + " ");
							}
						}
					}
					if (_killLogs++ < 6)
					{
						Log("Client kill requests sent: " + ((stringBuilder.Length > 0) ? stringBuilder.ToString() : ("(none accepted) echo_SubtractHp=" + flag)));
					}
					flag = true;
				}
			}
			if (!flag && !_loggedDamageFail)
			{
				_loggedDamageFail = true;
				Log("Kill failed: " + Bridge.LastErr);
			}
		}

		private void DealDamage(object cond, float dmg, object attacker)
		{
			bool flag = false;
			if (Bridge.IsHost())
			{
				flag = Bridge.CallBest(cond, "Damage", dmg, attacker);
			}
			if (!flag)
			{
				flag = Bridge.CallBest(cond, "echo_SubtractHp", dmg);
			}
			if (!flag && !_loggedDamageFail)
			{
				_loggedDamageFail = true;
				Log("Damage failed: " + Bridge.LastErr);
			}
		}

		private void HitMonster(object ai, HashSet<int> aiThisShot)
		{
			Object val = (Object)((ai is Object) ? ai : null);
			int num = ((val != (Object)null) ? val.GetInstanceID() : 0);
			if ((num == 0 || aiThisShot.Add(num)) && PStun.Value > 0f && !(Bridge.IsHost() ? Bridge.CallBest(ai, "sv_Stun", PStun.Value) : Bridge.CallBest(ai, "echo_stun", PStun.Value)))
			{
				Bridge.CallBest(ai, Bridge.IsHost() ? "echo_stun" : "sv_Stun", PStun.Value);
			}
			if (PKillAfter.Value > 0 && Bridge.IsHost() && num != 0)
			{
				_aiHits.TryGetValue(num, out var value);
				value++;
				_aiHits[num] = value;
				if (value >= PKillAfter.Value)
				{
					Bridge.CallBest(ai, "Die");
					_aiHits.Remove(num);
				}
			}
		}

		private static Transform NearestRemotePlayer(Vector3 from)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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)
			try
			{
				Transform result = null;
				float num = float.MaxValue;
				foreach (object item in Bridge.Instances(Bridge.FindTypeByName("FFPlayer")))
				{
					Component val = (Component)((item is Component) ? item : null);
					if (!((Object)(object)val == (Object)null) && !Bridge.IsOwner(item))
					{
						Vector3 val2 = val.transform.position - from;
						float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
						if (sqrMagnitude < num)
						{
							num = sqrMagnitude;
							result = val.transform;
						}
					}
				}
				return result;
			}
			catch
			{
				return null;
			}
		}

		private void PlayRemote(object kit, AudioClip fallback, Vector3 pos)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_005d: 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)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				AudioClip val = null;
				if (kit != null && Bridge.CallBest(kit, "GetRandomSound"))
				{
					object lastRet = Bridge.LastRet;
					val = (AudioClip)((lastRet is AudioClip) ? lastRet : null);
				}
				if ((Object)(object)val == (Object)null)
				{
					val = fallback;
				}
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				Camera main = Camera.main;
				if ((Object)(object)main != (Object)null)
				{
					Vector3 position = ((Component)main).transform.position;
					Vector3 val2 = pos - position;
					if (((Vector3)(ref val2)).magnitude > 7f)
					{
						pos = position + ((Vector3)(ref val2)).normalized * 7f;
					}
				}
				int num = Mathf.Clamp(PRemoteBoost.Value, 1, 6);
				for (int i = 0; i < num; i++)
				{
					AudioSource.PlayClipAtPoint(val, pos, 1f);
				}
			}
			catch (Exception ex)
			{
				Log("PlayRemote: " + ex.Message);
			}
		}

		private void HostFinishClientShot(Vector3 origin, Vector3 fwd, Transform shooter)
		{
			//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_00bc: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (PCloseKillPellets.Value <= 0)
				{
					return;
				}
				Type type = Bridge.FindTypeByName("FFAICore") ?? Bridge.FindTypeByName("FairyAICore");
				if (type == null)
				{
					return;
				}
				Type t = Bridge.FindTypeByName("FairyObject");
				Type t2 = Bridge.FindTypeByName("FairyCondition");
				float num = Mathf.Max(2f, PCloseRange.Value);
				RaycastHit val3 = default(RaycastHit);
				foreach (object item in Bridge.Instances(type))
				{
					Component val = (Component)((item is Component) ? item : null);
					if ((Object)(object)val == (Object)null || !val.gameObject.activeInHierarchy)
					{
						continue;
					}
					Vector3 val2 = val.transform.position + Vector3.up * 1f - origin;
					float magnitude = ((Vector3)(ref val2)).magnitude;
					if (magnitude > num || magnitude < 0.2f || Vector3.Angle(fwd, val2) > 11f)
					{
						continue;
					}
					if (Physics.Raycast(origin, ((Vector3)(ref val2)).normalized, ref val3, magnitude, -5, (QueryTriggerInteraction)1))
					{
						Collider collider = ((RaycastHit)(ref val3)).collider;
						if ((Object)(object)collider != (Object)null && (Object)(object)((Component)collider).transform.root != (Object)(object)val.transform.root && (!((Object)(object)shooter != (Object)null) || !((Component)collider).transform.IsChildOf(shooter)))
						{
							continue;
						}
					}
					object obj = null;
					object obj2 = Bridge.Comp(val, t, inChildren: false);
					if (obj2 != null)
					{
						obj = Bridge.Get(obj2, "Condition");
					}
					if (obj == null)
					{
						obj = Bridge.Comp(val, t2, inChildren: true);
					}
					if (_hostKillLogs++ < 8)
					{
						Log("Host finishing the client's shot: killing '" + ((Object)val.gameObject).name + "' at " + magnitude.ToString("0.0") + " m.");
					}
					Execute(obj, item);
				}
			}
			catch (Exception ex)
			{
				Log("HostFinishClientShot: " + ex.Message);
			}
		}

		private void VisualPellets(Vector3 origin, Vector3 fwd, Vector3 muzzle, Transform shooter)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				float num = Mathf.Max(5f, PRange.Value);
				int num2 = Math.Max(1, PPellets.Value);
				for (int i = 0; i < num2; i++)
				{
					Vector3 val = fwd + Random.insideUnitSphere * PSpread.Value;
					Vector3 normalized = ((Vector3)(ref val)).normalized;
					if (!CastPellet(origin, normalized, num, shooter, out var bh))
					{
						Bullet(muzzle, origin + normalized * Mathf.Min(num, 60f), hit: false);
						continue;
					}
					Bullet(muzzle, ((RaycastHit)(ref bh)).point, hit: true);
					if (i % 2 == 0)
					{
						ImpactFx(((RaycastHit)(ref bh)).point + ((RaycastHit)(ref bh)).normal * 0.05f, ((RaycastHit)(ref bh)).normal);
						PlaySound(_kitImpact, null, ((RaycastHit)(ref bh)).point);
					}
					if (i % 3 == 0 && FleshCached(((RaycastHit)(ref bh)).collider))
					{
						BloodFx(((RaycastHit)(ref bh)).point, -normalized, ((RaycastHit)(ref bh)).normal);
					}
				}
			}
			catch (Exception ex)
			{
				if (!_fxLogged)
				{
					_fxLogged = true;
					Log("VisualPellets: " + ex.Message);
				}
			}
		}

		private static bool IsFlesh(Collider col)
		{
			try
			{
				if ((Object)(object)col == (Object)null)
				{
					return false;
				}
				if (Bridge.Comp(col, Bridge.FindTypeByName("FairyConditionLink"), inChildren: false) != null)
				{
					return true;
				}
				if (Bridge.Comp(col, Bridge.FindTypeByName("FFAICore") ?? Bridge.FindTypeByName("FairyAICore"), inChildren: false) != null)
				{
					return true;
				}
				if (Bridge.Comp(col, Bridge.FindTypeByName("FFPlayer"), inChildren: false) != null)
				{
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		private static bool IsDeadActor(object ai)
		{
			try
			{
				string[] array = new string[3] { "IsDead", "Dead", "isDead" };
				foreach (string name in array)
				{
					object obj = Bridge.Get(ai, name);
					if (obj is bool && (bool)obj)
					{
						return true;
					}
				}
				array = new string[2] { "IsAlive", "Alive" };
				foreach (string name2 in array)
				{
					object obj2 = Bridge.Get(ai, name2);
					if (obj2 is bool && !(bool)obj2)
					{
						return true;
					}
				}
				object obj3 = Bridge.Get(ai, "Condition");
				if (obj3 == null)
				{
					object obj4 = Bridge.Comp((ai is Component) ? ai : null, Bridge.FindTypeByName("FairyObject"), inChildren: false);
					if (obj4 != null)
					{
						obj3 = Bridge.Get(obj4, "Condition");
					}
				}
				if (obj3 == null)
				{
					obj3 = Bridge.Comp((ai is Component) ? ai : null, Bridge.FindTypeByName("FairyCondition"), inChildren: true);
				}
				if (obj3 == null)
				{
					return false;
				}
				array = new string[3] { "IsDead", "Dead", "isDead" };
				foreach (string name3 in array)
				{
					object obj5 = Bridge.Get(obj3, name3);
					if (obj5 is bool && (bool)obj5)
					{
						return true;
					}
				}
				array = new string[2] { "IsAlive", "Alive" };
				foreach (string name4 in array)
				{
					object obj6 = Bridge.Get(obj3, name4);
					if (obj6 is bool && !(bool)obj6)
					{
						return true;
					}
				}
				object obj7 = Bridge.Get(obj3, "hp") ?? Bridge.Get(obj3, "Hp") ?? Bridge.Get(obj3, "health");
				if (obj7 is float)
				{
					return (float)obj7 <= 0f;
				}
				if (obj7 is int)
				{
					return (int)obj7 <= 0;
				}
			}
			catch
			{
			}
			return false;
		}

		private static void SilenceDead()
		{
			if (PSilenceDead == null || !PSilenceDead.Value)
			{
				return;
			}
			try
			{
				float realtimeSinceStartup = Time.realtimeSinceStartup;
				if (realtimeSinceStartup >= _aiScan)
				{
					_aiScan = realtimeSinceStartup + 4f;
					Type type = Bridge.FindTypeByName("FFAICore") ?? Bridge.FindTypeByName("FairyAICore");
					_aiCache.Clear();
					if (type != null)
					{
						_aiCache.AddRange(Bridge.Instances(type));
					}
				}
				if (_aiCache.Count == 0 || realtimeSinceStartup < _deadScan)
				{
					return;
				}
				_deadScan = realtimeSinceStartup + 0.4f;
				for (int num = _aiCache.Count - 1; num >= 0; num--)
				{
					object obj = _aiCache[num];
					Component val = (Component)((obj is Component) ? obj : null);
					if ((Object)(object)val == (Object)null || (Object)(object)val.gameObject == (Object)null)
					{
						_aiCache.RemoveAt(num);
					}
					else
					{
						int instanceID = ((Object)val.gameObject).GetInstanceID();
						float value;
						if (!IsDeadActor(_aiCache[num]))
						{
							_deadAt.Remove(instanceID);
							if (_hushed.Remove(instanceID))
							{
								foreach (AudioSource componentsInChild in val.GetComponentsInChildren<AudioSource>(true))
								{
									((Behaviour)componentsInChild).enabled = true;
								}
							}
						}
						else if (!_deadAt.TryGetValue(instanceID, out value))
						{
							_deadAt[instanceID] = realtimeSinceStartup;
						}
						else if (!(realtimeSinceStartup - value < 1.5f))
						{
							List<string> list = new List<string>();
							foreach (AudioSource componentsInChild2 in val.GetComponentsInChildren<AudioSource>(true))
							{
								if ((Object)(object)componentsInChild2 == (Object)null)
								{
									continue;
								}
								if (componentsInChild2.isPlaying)
								{
									if (list.Count < 4 && (Object)(object)componentsInChild2.clip != (Object)null)
									{
										list.Add(((Object)componentsInChild2.clip).name);
									}
									componentsInChild2.Stop();
								}
								if (((Behaviour)componentsInChild2).enabled)
								{
									((Behaviour)componentsInChild2).enabled = false;
								}
							}
							if (_hushed.Add(instanceID) && _hushLogs++ < 10)
							{
								Log("Shut up the dead '" + ((Object)val.gameObject).name + "'" + ((list.Count > 0) ? (" (was still playing: " + string.Join(", ", list) + ")") : "") + ".");
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				if (_hushLogs++ < 3)
				{
					Log("SilenceDead: " + ex.Message);
				}
			}
		}

		private void RemoteShot(object gun, string via)
		{
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: 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_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: 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_0182: 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_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Component val = (Component)((gun is Component) ? gun : null);
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				int instanceID = ((Object)val.gameObject).GetInstanceID();
				float time = Time.time;
				if (_remoteLast.TryGetValue(instanceID, out var value) && time - value < 0.3f)
				{
					return;
				}
				object obj = OwnerOf(gun);
				bool flag = ((obj != null) ? Bridge.IsOwner(obj) : Bridge.IsOwner(gun));
				if (_remoteLogs < 12)
				{
					_remoteLogs++;
					Log("shot seen via " + via + ": mine=" + flag + " playerKnown=" + (obj != null) + " gun='" + ((Object)val.gameObject).name + "'");
				}
				if (flag)
				{
					return;
				}
				_remoteLast[instanceID] = time;
				Transform val2 = (((Object)((obj is Component) ? obj : null) != (Object)null) ? ((Component)obj).transform : NearestRemotePlayer(val.transform.position));
				Vector3 val3 = val.transform.forward;
				Vector3 val4 = val.transform.position;
				if ((Object)(object)val2 != (Object)null)
				{
					Vector3 forward = val2.forward;
					forward.y = 0f;
					if (((Vector3)(ref forward)).sqrMagnitude > 0.01f)
					{
						((Vector3)(ref forward)).Normalize();
						if (Vector3.Dot(val3, forward) < 0.3f)
						{
							val3 = forward;
						}
						Vector3 val5 = val4 - val2.position;
						if (((Vector3)(ref val5)).sqrMagnitude > 9f)
						{
							val4 = val2.position + Vector3.up * 1.5f;
						}
					}
				}
				Vector3 val6 = val4 + val3 * 0.6f;
				FindAssets();
				PlayRemote(_kitFire, _clipFire, val6);
				MuzzleFlash(val6, val3);
				Beads(val6 + val3 * 0.8f, val3);
				VisualPellets(val4, val3, val6, val2);
				if (Bridge.IsHost())
				{
					HostFinishClientShot(((Object)(object)val2 != (Object)null) ? (val2.position + Vector3.up * 1.5f) : val4, val3, val2);
				}
			}
			catch (Exception ex)
			{
				Log("RemoteShot: " + ex.Message);
			}
		}

		private static object NewArray(object oldArr, List<object> items)
		{
			Type type = oldArr.GetType();
			Array array = Array.CreateInstance(type.GetGenericArguments()[0], items.Count);
			for (int i = 0; i < items.Count; i++)
			{
				array.SetValue(items[i], i);
			}
			return Activator.CreateInstance(type, array);
		}

		private static object FindShopItemByName(object trader, string name)
		{
			foreach (object item in Bridge.Enumerate(Bridge.Get(trader, "shopItems")))
			{
				if (item != null && Bridge.Str(Bridge.Get(item, "itemName")).ToLowerInvariant() == name)
				{
					return item;
				}
			}
			return null;
		}

		private static void ShopTick()
		{
			if (!PAddShop.Value || Time.realtimeSinceStartup < _shopNext)
			{
				return;
			}
			_shopNext = Time.realtimeSinceStartup + 1.5f;
			try
			{
				Type type = Bridge.FindTypeByName("FFTrader");
				if (type == null)
				{
					return;
				}
				object obj = Bridge.Instances(type).FirstOrDefault();
				if (obj == null)
				{
					return;
				}
				HookShop(type);
				object obj2 = Bridge.Get(obj, "shopItems");
				if (obj2 == null)
				{
					return;
				}
				object obj3 = FindShopItemByName(obj, "shotgun ammo");
				if (obj3 == null)
				{
					Type type2 = type.GetNestedTypes(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((Type x) => x.Name == "ShopItem") ?? Bridge.FindTypeByName("ShopItem");
					if (type2 == null)
					{
						Log("Shop: ShopItem type not found.");
						_shopNext += 30f;
						return;
					}
					List<object> list = Bridge.Enumerate(obj2);
					object obj4 = null;
					object obj5 = null;
					foreach (object item in list)
					{
						string text = Bridge.Str(Bridge.Get(item, "itemName")).ToLowerInvariant();
						if (text == "gun")
						{
							obj4 = item;
						}
						if (text == "glowstick")
						{
							obj5 = item;
						}
					}
					obj3 = Activator.CreateInstance(type2);
					SetP(obj3, "itemName", "shotgun ammo");
					SetP(obj3, "itemCost", PShellCost.Value);
					SetP(obj3, "OriginalItemName", "shotgun ammo");
					SetP(obj3, "OriginalCost", PShellCost.Value);
					SetP(obj3, "itemDescription", "Shotgun shells. " + PShellsPerCase.Value + " per case.\n\nPress R with the shotgun in hand to load one.");
					SetP(obj3, "saleAllowed", false);
					SetP(obj3, "isHidden", false);
					object obj6 = ((obj4 != null) ? Bridge.Get(obj4, "itemSprite") : null);
					if (obj6 != null)
					{
						SetP(obj3, "itemSprite", obj6);
					}
					object obj7 = ((obj5 != null) ? Bridge.Get(obj5, "prefab") : null);
					if (obj7 != null)
					{
						SetP(obj3, "prefab", obj7);
					}
					List<object> list2 = new List<object>(list);
					list2.Add(obj3);
					SetP(obj, "shopItems", NewArray(obj2, list2));
					_shopId = Bridge.Str(Bridge.Get(obj3, "ShopId"));
					foreach (object item2 in list)
					{
						Log("Shop item '" + Bridge.Str(Bridge.Get(item2, "itemName")) + "' id='" + Bridge.Str(Bridge.Get(item2, "ShopId")) + "'");
					}
					_mineItem = obj3;
					Log("Shop: added 'shotgun ammo' (" + PShellCost.Value + ") - shop id '" + _shopId + "', prefab " + ((obj7 != null) ? "set" : "MISSING") + ".");
				}
				else if (_shopId.Length == 0)
				{
					_shopId = Bridge.Str(Bridge.Get(obj3, "ShopId"));
				}
				_mineItem = obj3;
				if (!_lookupLogged)
				{
					_lookupLogged = true;
					Bridge.CallBest(obj, "FindShopItemById", _shopId);
					object lastRet = Bridge.LastRet;
					Bridge.CallBest(obj, "FindShopItem", "shotgun ammo");
					object lastRet2 = Bridge.LastRet;
					Log("Shop lookup check: byId=" + (lastRet != null) + " byName=" + (lastRet2 != null));
				}
				AddShopButtonIfNeeded(obj, obj3);
			}
			catch (Exception ex)
			{
				Log("ShopTick: " + ex.Message);
				_shopNext += 20f;
			}
		}

		private static void AddShopButtonIfNeeded(object trader, object mine)
		{
			Type type = Bridge.FindTypeByName("FFDataDeck");
			Type type2 = Bridge.FindTypeByName("FFUIShopItem");
			Type type3 = Bridge.FindTypeByName("FFShopBuyBtn");
			if (type == null || type2 == null || type3 == null)
			{
				return;
			}
			object obj = Bridge.Instances(type).FirstOrDefault();
			if (obj == null)
			{
				return;
			}
			object obj2 = Bridge.Get(obj, "InitializedShop") ?? Bridge.Get(obj, "_InitializedShop_k__BackingField");
			if (!(obj2 is bool) || !(bool)obj2)
			{
				return;
			}
			object obj3 = Bridge.Get(obj, "_uiShopItems");
			if (obj3 == null)
			{
				return;
			}
			List<object> list = Bridge.Enumerate(obj3);
			foreach (object item in list)
			{
				object obj4 = Bridge.Get(item, "ItemData");
				if (obj4 != null && Bridge.Str(Bridge.Get(obj4, "itemName")).ToLowerInvariant() == "shotgun ammo")
				{
					return;
				}
			}
			if (list.Count == 0)
			{
				return;
			}
			object obj5 = list[list.Count - 1];
			Component val = (Component)((obj5 is Component) ? obj5 : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			object obj6 = Bridge.Get(obj, "layoutParent");
			Transform val2 = (Transform)((obj6 is Transform) ? obj6 : null);
			Transform val3 = val.transform;
			if ((Object)(object)val2 != (Object)null)
			{
				while ((Object)(object)val3.parent != (Object)null && (Object)(object)val3.parent != (Object)(object)val2)
				{
					val3 = val3.parent;
				}
				if ((Object)(object)val3.parent != (Object)(object)val2)
				{
					val3 = val.transform;
				}
			}
			else if ((Object)(object)val3.parent != (Object)null && Bridge.Comp(val3.parent, type3, inChildren: true) != null)
			{
				val3 = val3.parent;
			}
			GameObject val4 = Object.Instantiate<GameObject>(((Component)val3).gameObject, val3.parent);
			object obj7 = Bridge.Comp(val4, type2, inChildren: true);
			if (obj7 == null || !Bridge.CallBest(obj7, "SetAsItem", mine, obj))
			{
				Log("Shop: could not build the shop row: " + Bridge.LastErr);
				Object.Destroy((Object)(object)val4);
				return;
			}
			object obj8 = Bridge.Comp(val4, type3, inChildren: true);
			if (obj8 != null)
			{
				try
				{
					SetP(obj8, "shopItem", obj7);
				}
				catch
				{
				}
			}
			List<object> list2 = new List<object>(list);
			list2.Add(obj7);
			try
			{
				SetP(obj, "_uiShopItems", NewArray(obj3, list2));
			}
			catch
			{
			}
			Log("Shop: built a shop row for 'shotgun ammo' (copied '" + ((Object)val3).name + "', buy button " + ((obj8 != null) ? "found" : "NOT found") + ").");
		}

		private static void HookShop(Type tTrader)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			if (_shopHooked)
			{
				return;
			}
			_shopHooked = true;
			HarmonyMethod val = new HarmonyMethod(typeof(Core).GetMethod("BuyPre", BindingFlags.Static | BindingFlags.NonPublic));
			HarmonyMethod val2 = new HarmonyMethod(typeof(Core).GetMethod("BuyPost", BindingFlags.Static | BindingFlags.NonPublic));
			HarmonyMethod val3 = new HarmonyMethod(typeof(Core).GetMethod("PaidPost", BindingFlags.Static | BindingFlags.NonPublic));
			HarmonyMethod val4 = new HarmonyMethod(typeof(Core).GetMethod("TracePre", BindingFlags.Static | BindingFlags.NonPublic));
			HarmonyMethod val5 = new HarmonyMethod(typeof(Core).GetMethod("LookupPost", BindingFlags.Static | BindingFlags.NonPublic));
			string[] array = new string[2] { "FFShopBuyBtn", "FFUIShopItem" };
			MethodInfo[] methods;
			foreach (string text in array)
			{
				Type type = Bridge.FindTypeByName(text);
				if (type == null)
				{
					continue;
				}
				methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.Name == "OnLeftClick")
					{
						try
						{
							((MelonBase)I).HarmonyInstance.Patch((MethodBase)methodInfo, val4, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
							Log("Tracing " + text + "." + methodInfo.Name);
						}
						catch (Exception ex)
						{
							Log("Trace failed: " + ex.Message);
						}
					}
				}
			}
			methods = tTrader.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo2 in methods)
			{
				try
				{
					if (methodInfo2.Name == "BuyItem" || methodInfo2.Name == "sv_BuyItem" || methodInfo2.Name == "svr_BuyItem")
					{
						((MelonBase)I).HarmonyInstance.Patch((MethodBase)methodInfo2, val4, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log("Tracing " + methodInfo2.Name);
					}
					if (methodInfo2.Name == "FindShopItemById" || methodInfo2.Name == "FindShopItem")
					{
						((MelonBase)I).HarmonyInstance.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, val5, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log("Lookup fallback on " + methodInfo2.Name);
					}
					if (methodInfo2.Name.StartsWith("RpcLogic___svr_BuyItem"))
					{
						((MelonBase)I).HarmonyInstance.Patch((MethodBase)methodInfo2, val, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log("Hooked " + methodInfo2.Name);
					}
					else if (methodInfo2.Name.StartsWith("RpcLogic___obr_PostPurchase"))
					{
						((MelonBase)I).HarmonyInstance.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, val3, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log("Hooked " + methodInfo2.Name);
					}
				}
				catch (Exception ex2)
				{
					Log("Hook failed " + methodInfo2.Name + ": " + ex2.Message);
				}
			}
		}

		private static void TracePre(object __instance, object[] __args, MethodBase __originalMethod)
		{
			try
			{
				if (_traceN++ > 60)
				{
					return;
				}
				string text = "";
				if (__args != null)
				{
					foreach (object obj in __args)
					{
						object obj2 = ((obj != null) ? Bridge.Get(obj, "itemName") : null);
						text = text + ((obj2 != null) ? ("ShopItem:" + Bridge.Str(obj2)) : Bridge.Str(obj)) + " | ";
					}
				}
				string text2 = "";
				object obj3 = Bridge.Get(__instance, "ItemData") ?? Bridge.Get(Bridge.Get(__instance, "shopItem"), "ItemData");
				if (obj3 != null)
				{