Decompiled source of RE4Gameplay v0.30.0

BepInEx/plugins/RE4Company/RE4Company.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.UI;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.LowLevel;
using UnityEngine.Networking;
using UnityEngine.PlayerLoop;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;
using UnityEngine.TextCore;
using UnityEngine.TextCore.LowLevel;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RE4Company")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.30.0.0")]
[assembly: AssemblyInformationalVersion("0.30.0")]
[assembly: AssemblyProduct("RE4Company")]
[assembly: AssemblyTitle("RE4Company")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.30.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RE4Company
{
	public static class AimAlignment
	{
		public static void Apply(Re4Rig rig, GameObject weapon, Vector3 target, int weaponIndex = 0)
		{
			//IL_003a: 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_0049: 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_0066: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: 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)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: 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_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: 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_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: 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_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			bool flag = HeldWeaponRules.For(weaponIndex).GripBone == 16;
			Transform val = rig.Bone(flag ? 16 : 10);
			Transform val2 = rig.Bone(flag ? 10 : 16);
			if (!((Object)(object)val == (Object)null))
			{
				Quaternion val3 = Quaternion.LookRotation(Vector3.down, Vector3.right);
				Vector3 val4 = (((Object)(object)val2 != (Object)null) ? weapon.transform.InverseTransformPoint(val2.position) : Vector3.zero);
				Quaternion val5 = (((Object)(object)val2 != (Object)null) ? (Quaternion.Inverse(weapon.transform.rotation) * val2.rotation) : Quaternion.identity);
				Vector3 p = AimLaser.MuzzleLocal(weapon);
				Vector3 vector = HeldWeaponRules.Wrist(weaponIndex);
				Vector3 val6 = default(Vector3);
				((Vector3)(ref val6))..ctor(vector.X, vector.Y, vector.Z);
				Quaternion rotation = weapon.transform.rotation;
				Quaternion quaternion = AimMath.Align(N(val.position), N(target), N(p), N(val6), new Quaternion(rotation.x, rotation.y, rotation.z, rotation.w), weapon.transform.lossyScale.x);
				Quaternion val7 = default(Quaternion);
				((Quaternion)(ref val7))..ctor(quaternion.X, quaternion.Y, quaternion.Z, quaternion.W);
				val.rotation = (flag ? (val7 * Quaternion.Inverse(rotation) * val.rotation) : (val7 * val3));
				weapon.transform.rotation = val7;
				weapon.transform.position = val.position - weapon.transform.TransformVector(val6);
				if ((Object)(object)val2 != (Object)null)
				{
					Transform val8 = rig.Bone(flag ? 8 : 14);
					Vector3 val9 = (((Object)(object)val8 != (Object)null) ? val8.position : (((Component)rig).transform.position + ((Component)rig).transform.right));
					rig.Arm(flag, ((Component)rig).transform.InverseTransformPoint(weapon.transform.TransformPoint(val4)), ((Component)rig).transform.InverseTransformPoint(val9), val7 * val5);
				}
			}
			static Vector3 N(Vector3 val10)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				return new Vector3(val10.x, val10.y, val10.z);
			}
		}
	}
	public sealed class AimLaser
	{
		private GameObject? root;

		private GameObject? dot;

		private LineRenderer? beam;

		private Material? material;

		private static readonly Dictionary<GameObject, Vector3> muzzles = new Dictionary<GameObject, Vector3>();

		private static readonly RaycastHit[] hits = (RaycastHit[])(object)new RaycastHit[128];

		private void Create()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			root = new GameObject("RE4 aiming laser");
			Object.DontDestroyOnLoad((Object)(object)root);
			Shader val = Shader.Find("HDRP/Unlit") ?? Shader.Find("Unlit/Color");
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidOperationException("No supported unlit laser shader");
			}
			material = new Material(val)
			{
				name = "RE4 red laser"
			};
			if (material.HasProperty("_UnlitColor"))
			{
				material.SetColor("_UnlitColor", new Color(1f, 0.005f, 0.002f, 1f));
			}
			if (material.HasProperty("_Color"))
			{
				material.SetColor("_Color", Color.red);
			}
			if (material.HasProperty("_EmissiveColor"))
			{
				material.SetColor("_EmissiveColor", new Color(5f, 0.005f, 0f));
			}
			if (material.HasProperty("_EmissiveExposureWeight"))
			{
				material.SetFloat("_EmissiveExposureWeight", 0f);
			}
			if (((Object)val).name.StartsWith("HDRP/"))
			{
				HDMaterial.ValidateMaterial(material);
			}
			beam = root.AddComponent<LineRenderer>();
			((Renderer)beam).sharedMaterial = material;
			beam.useWorldSpace = true;
			beam.positionCount = 2;
			beam.startWidth = 0.004f;
			beam.endWidth = 0.002f;
			LineRenderer? obj = beam;
			Color startColor = (beam.endColor = Color.red);
			obj.startColor = startColor;
			beam.numCapVertices = 3;
			beam.alignment = (LineAlignment)0;
			((Renderer)beam).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)beam).receiveShadows = false;
			((Renderer)beam).lightProbeUsage = (LightProbeUsage)0;
			((Renderer)beam).reflectionProbeUsage = (ReflectionProbeUsage)0;
			dot = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)dot).name = "RE4 laser impact";
			Collider component = dot.GetComponent<Collider>();
			component.enabled = false;
			Object.Destroy((Object)(object)component);
			dot.transform.SetParent(root.transform, false);
			Renderer component2 = dot.GetComponent<Renderer>();
			component2.sharedMaterial = material;
			component2.shadowCastingMode = (ShadowCastingMode)0;
			component2.receiveShadows = false;
			component2.lightProbeUsage = (LightProbeUsage)0;
			component2.reflectionProbeUsage = (ReflectionProbeUsage)0;
			Plugin.Log("Muzzle-mounted aiming laser initialized.");
		}

		public static Vector3 MuzzleLocal(GameObject weapon)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: 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_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: 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_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			bool flag = (Object)(object)weapon.GetComponentInChildren<Re4Rig>() != (Object)null;
			if (!flag && muzzles.TryGetValue(weapon, out var value))
			{
				return value;
			}
			float num = float.NegativeInfinity;
			Vector3 val = Vector3.zero;
			int num2 = 0;
			List<Vector3> list = new List<Vector3>();
			SkinnedMeshRenderer[] componentsInChildren = weapon.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			foreach (SkinnedMeshRenderer val2 in componentsInChildren)
			{
				Mesh sharedMesh = val2.sharedMesh;
				Vector3[] source = sharedMesh.vertices;
				BoneWeight[] boneWeights = sharedMesh.boneWeights;
				Matrix4x4[] bind = sharedMesh.bindposes;
				Transform[] bones = val2.bones;
				foreach (int item in new HashSet<int>(val2.sharedMesh.triangles))
				{
					int index = item;
					Vector3 world;
					if (boneWeights.Length == source.Length && bones.Length != 0)
					{
						BoneWeight val3 = boneWeights[index];
						world = Vector3.zero;
						Add(((BoneWeight)(ref val3)).boneIndex0, ((BoneWeight)(ref val3)).weight0);
						Add(((BoneWeight)(ref val3)).boneIndex1, ((BoneWeight)(ref val3)).weight1);
						Add(((BoneWeight)(ref val3)).boneIndex2, ((BoneWeight)(ref val3)).weight2);
						Add(((BoneWeight)(ref val3)).boneIndex3, ((BoneWeight)(ref val3)).weight3);
					}
					else
					{
						world = ((Component)val2).transform.TransformPoint(source[index]);
					}
					Vector3 val4 = weapon.transform.InverseTransformPoint(world);
					num = Mathf.Max(num, val4.z);
					list.Add(val4);
					void Add(int bone, float weight)
					{
						//IL_0027: Unknown result type (might be due to invalid IL or missing references)
						//IL_004c: Unknown result type (might be due to invalid IL or missing references)
						//IL_0051: 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_005c: 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_0066: Unknown result type (might be due to invalid IL or missing references)
						if (weight > 0f && bone < bones.Length && (Object)(object)bones[bone] != (Object)null)
						{
							world += bones[bone].TransformPoint(((Matrix4x4)(ref bind[bone])).MultiplyPoint3x4(source[index])) * weight;
						}
					}
				}
			}
			foreach (Vector3 item2 in list)
			{
				if (item2.z >= num - 0.012f)
				{
					val += item2;
					num2++;
				}
			}
			Vector3 val5 = (Vector3)((num2 > 0) ? (val / (float)num2) : new Vector3(0f, 0f, 0.25f));
			if (num2 > 0)
			{
				val5.z = num + 0.005f;
			}
			foreach (GameObject item3 in new List<GameObject>(muzzles.Keys))
			{
				if ((Object)(object)item3 == (Object)null)
				{
					muzzles.Remove(item3);
				}
			}
			if (!flag)
			{
				muzzles[weapon] = val5;
			}
			return val5;
		}

		private static bool Trace(Vector3 origin, Vector3 direction, float distance, out Vector3 point)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_0018: 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_0055: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			point = origin + direction * distance;
			float num = distance;
			bool result = false;
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(origin, direction, ref val, distance, Controller.WorldMask, (QueryTriggerInteraction)1) && (Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<PlayerControllerB>() == (Object)null)
			{
				num = ((RaycastHit)(ref val)).distance;
				point = ((RaycastHit)(ref val)).point;
				result = true;
			}
			int num2 = Physics.RaycastNonAlloc(origin, direction, hits, num, -1, (QueryTriggerInteraction)2);
			for (int i = 0; i < num2; i++)
			{
				RaycastHit val2 = hits[i];
				Collider collider = ((RaycastHit)(ref val2)).collider;
				if ((Object)(object)collider == (Object)null || ((RaycastHit)(ref val2)).distance >= num || (Object)(object)((Component)collider).GetComponentInParent<PlayerControllerB>() != (Object)null)
				{
					continue;
				}
				bool num3 = (Object)(object)((Component)collider).GetComponentInParent<EnemyAI>() != (Object)null;
				int num4;
				if (!((Object)(object)((Component)collider).GetComponentInParent<Re4HangingTreasureTarget>() != (Object)null) && !((Object)(object)((Component)collider).GetComponentInParent<Re4CrateTarget>() != (Object)null) && !((Object)(object)((Component)collider).GetComponentInParent<Re4PickupTarget>() != (Object)null))
				{
					if (((Component)collider).CompareTag("PhysicsProp"))
					{
						GrabbableObject componentInParent = ((Component)collider).GetComponentInParent<GrabbableObject>();
						num4 = ((componentInParent != null && componentInParent.grabbable && !componentInParent.isHeld) ? 1 : 0);
					}
					else
					{
						num4 = 0;
					}
				}
				else
				{
					num4 = 1;
				}
				bool flag = (byte)num4 != 0;
				if (num3 || flag || (!collider.isTrigger && ((1 << ((Component)collider).gameObject.layer) & Controller.WorldMask) != 0))
				{
					num = ((RaycastHit)(ref val2)).distance;
					point = ((RaycastHit)(ref val2)).point;
					result = true;
				}
			}
			return result;
		}

		public static Vector3 Target(Camera camera, float range)
		{
			//IL_0006: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			Trace(((Component)camera).transform.position, ((Component)camera).transform.forward, range, out var point);
			return point;
		}

		public void Tick(Controller controller, GameObject? weapon)
		{
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: 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_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: 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_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: 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_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB player = Controller.Player;
			bool flag = (Object)(object)player != (Object)null && controller.Ready && controller.Armed && controller.Aiming && !ScopeView.Active && !controller.InputOverlay && Time.time >= controller.ReloadUntil && (Object)(object)weapon != (Object)null && weapon.activeInHierarchy;
			if (flag && (Object)(object)player != (Object)null)
			{
				ActorPose actorPose = Presentation.Get(player.actualClientId);
				flag = !actorPose.Acting || (!(actorPose.Action == "knife") && !(actorPose.Action == "kick"));
			}
			if (flag)
			{
				ActorPose actorPose2 = Presentation.Get(player.actualClientId);
				WeaponSpec weaponSpec = WeaponSpec.All[controller.State.Weapon];
				float num = ((weaponSpec.AnimationBank == "wep28") ? weaponSpec.Interval : ((float)OriginalMotion.Clip(weaponSpec.AnimationBank + "_fire").MaxFrame / 30f));
				if (Time.time - actorPose2.ShotAt < num)
				{
					flag = false;
				}
			}
			if (!flag)
			{
				if ((Object)(object)root != (Object)null)
				{
					root.SetActive(false);
				}
				return;
			}
			if ((Object)(object)root == (Object)null)
			{
				Create();
			}
			root.SetActive(true);
			float range = WeaponSpec.All[controller.State.Weapon].Range;
			Camera gameplayCamera = player.gameplayCamera;
			Trace(((Component)gameplayCamera).transform.position, ((Component)gameplayCamera).transform.forward, range, out var point);
			Vector3 val = weapon.transform.TransformPoint(MuzzleLocal(weapon));
			Vector3 val2 = point - val;
			float magnitude = ((Vector3)(ref val2)).magnitude;
			if (magnitude < 0.01f)
			{
				root.SetActive(false);
				return;
			}
			Vector3 point2;
			bool active = Trace(val, val2 / magnitude, magnitude + 0.015f, out point2);
			beam.SetPosition(0, val);
			beam.SetPosition(1, point2);
			dot.SetActive(active);
			dot.transform.position = point2 - ((Vector3)(ref val2)).normalized * 0.005f;
			dot.transform.localScale = Vector3.one * 0.018f;
		}

		public void Dispose()
		{
			if ((Object)(object)root != (Object)null)
			{
				Object.Destroy((Object)(object)root);
			}
			if ((Object)(object)material != (Object)null)
			{
				Object.Destroy((Object)(object)material);
			}
			muzzles.Clear();
		}
	}
	public static class AimMath
	{
		public static Quaternion Align(Vector3 hand, Vector3 target, Vector3 muzzle, Vector3 wrist, Quaternion rotation, float scale)
		{
			for (int i = 0; i < 8; i++)
			{
				Vector3 vector = new Vector3(muzzle.X - wrist.X, muzzle.Y - wrist.Y, 0f);
				Vector3 vector2 = hand + Vector3.Transform(vector * scale, rotation);
				Vector3 value = target - vector2;
				if (value.LengthSquared() < 0.0001f)
				{
					break;
				}
				Vector3 vector3 = Vector3.Transform(Vector3.UnitZ, rotation);
				Vector3 vector4 = Vector3.Normalize(value);
				float num = Math.Clamp(Vector3.Dot(vector3, vector4), -1f, 1f);
				Quaternion quaternion;
				if (num < -0.9999f)
				{
					Vector3 value2 = Vector3.Cross(vector3, Vector3.UnitY);
					if (value2.LengthSquared() < 0.001f)
					{
						value2 = Vector3.Cross(vector3, Vector3.UnitX);
					}
					quaternion = Quaternion.CreateFromAxisAngle(Vector3.Normalize(value2), MathF.PI);
				}
				else
				{
					quaternion = Quaternion.Normalize(new Quaternion(Vector3.Cross(vector3, vector4), 1f + num));
				}
				rotation = Quaternion.Normalize(quaternion * rotation);
			}
			return rotation;
		}
	}
	public static class ArmorRules
	{
		public static int Damage(int amount, bool equipped)
		{
			if (amount > 0 && equipped)
			{
				return Math.Max(1, (int)Math.Floor((double)amount * 0.7 + 0.5));
			}
			return amount;
		}
	}
	public static class ArsenalCombat
	{
		private sealed class Projectile
		{
			public ulong Client;

			public Vector3 Position;

			public Vector3 Velocity;

			public int Power;

			public WeaponShot? Shot;

			public string Mode = "";

			public float Expires;

			public float Detonate;
		}

		private static readonly List<Projectile> shots = new List<Projectile>();

		public static bool Fire(ulong client, PlayerControllerB player, Vector3 origin, Vector3 direction, WeaponSpec weapon, int power)
		{
			//IL_0051: 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_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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: 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_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: 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_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: 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_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			string mode = weapon.Mode;
			if (!mode.Contains("rocket"))
			{
				switch (mode)
				{
				case "mine":
				case "bolt":
				case "arrow":
					break;
				case "beam":
				{
					bool result = Director.Instance.CrateRay(origin, direction, weapon.Range, 0f, stopAtEnemy: false);
					EnemyAI[] array3 = Object.FindObjectsOfType<EnemyAI>();
					foreach (EnemyAI val3 in array3)
					{
						if (val3.isEnemyDead)
						{
							continue;
						}
						Vector3 val4 = ((Component)val3).transform.position + Vector3.up;
						if (!(Vector3.Distance(origin, val4) > weapon.Range))
						{
							Vector3 val5 = val4 - origin;
							if (!(Vector3.Dot(((Vector3)(ref val5)).normalized, direction) < 0.93f) && !Physics.Linecast(origin, val4, Controller.WorldMask, (QueryTriggerInteraction)1))
							{
								Hit(client, val3, power, direction, val4, "heavy");
								result = true;
							}
						}
					}
					Session.Instance.Broadcast(new Packet
					{
						Op = "beamfx",
						Point = origin,
						Text = UiDataJson.Write<Vector3>(direction * weapon.Range)
					});
					return result;
				}
				case "pierce":
				{
					bool flag = Director.Instance.CrateRay(origin, direction, weapon.Range, 0f, stopAtEnemy: false);
					float num = weapon.Range;
					RaycastHit val = default(RaycastHit);
					if (Physics.Raycast(origin, direction, ref val, num, Controller.WorldMask, (QueryTriggerInteraction)1))
					{
						num = ((RaycastHit)(ref val)).distance;
					}
					RaycastHit[] array = (from g in (from h in (from h in Physics.RaycastAll(origin, direction, num, -1, (QueryTriggerInteraction)2)
								orderby ((RaycastHit)(ref h)).distance
								select h).Where(delegate(RaycastHit h)
							{
								EnemyAI componentInParent = ((Component)((RaycastHit)(ref h)).collider).GetComponentInParent<EnemyAI>();
								return componentInParent != null && !componentInParent.isEnemyDead;
							})
							group h by ((Component)((RaycastHit)(ref h)).collider).GetComponentInParent<EnemyAI>()).Take(5)
						select g.First()).ToArray();
					RaycastHit[] array2 = array;
					for (int num2 = 0; num2 < array2.Length; num2++)
					{
						RaycastHit val2 = array2[num2];
						Hit(client, ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<EnemyAI>(), power, direction, ((RaycastHit)(ref val2)).point, "heavy");
					}
					if (!flag)
					{
						return array.Length != 0;
					}
					return true;
				}
				default:
					if (!Director.Instance.CrateRay(origin, direction, weapon.Range))
					{
						return Director.Instance.Shoot(client, origin, direction, weapon.Range, power, knife: false);
					}
					return true;
				}
			}
			shots.Add(new Projectile
			{
				Client = client,
				Position = origin + direction * 0.3f,
				Velocity = direction * (float)((mode == "arrow") ? 38 : 28),
				Power = power,
				Shot = WeaponShots.Current,
				Mode = mode,
				Expires = Time.time + 5f
			});
			Session.Instance.Broadcast(new Packet
			{
				Op = "trail",
				Point = origin,
				Text = UiDataJson.Write<Vector3>(direction),
				Amount = ((mode == "arrow") ? 1 : 0)
			});
			return false;
		}

		private static void Hit(ulong client, EnemyAI enemy, int power, Vector3 direction, Vector3 point, string kind)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			CombatImpact.Hit(client, enemy, power, direction, point, kind);
		}

		public static void Tick()
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: 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_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: 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_0187: 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)
			//IL_01c8: 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_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			if (!Session.Connected)
			{
				shots.Clear();
			}
			else
			{
				if (!Session.Host)
				{
					return;
				}
				Projectile[] array = shots.ToArray();
				foreach (Projectile projectile in array)
				{
					using (WeaponShots.Use(projectile.Shot))
					{
						if ((Object)(object)Session.FindPlayer(projectile.Client) == (Object)null)
						{
							shots.Remove(projectile);
							continue;
						}
						if (projectile.Detonate > 0f)
						{
							if (Time.time >= projectile.Detonate)
							{
								Blast(projectile);
								shots.Remove(projectile);
							}
							continue;
						}
						float num = Mathf.Min(Time.deltaTime, 0.1f);
						Vector3 val = projectile.Velocity * num;
						RaycastHit val2 = (from h in Physics.SphereCastAll(projectile.Position, 0.035f, ((Vector3)(ref val)).normalized, ((Vector3)(ref val)).magnitude, -1, (QueryTriggerInteraction)2)
							where (Object)(object)((Component)((RaycastHit)(ref h)).collider).GetComponentInParent<PlayerControllerB>() == (Object)null && (!((RaycastHit)(ref h)).collider.isTrigger || (Object)(object)((Component)((RaycastHit)(ref h)).collider).GetComponentInParent<EnemyAI>() != (Object)null || (Object)(object)((Component)((RaycastHit)(ref h)).collider).GetComponentInParent<Re4CrateTarget>() != (Object)null)
							orderby ((RaycastHit)(ref h)).distance
							select h).FirstOrDefault();
						if ((Object)(object)((RaycastHit)(ref val2)).collider != (Object)null)
						{
							projectile.Position = ((RaycastHit)(ref val2)).point;
							if (projectile.Mode == "arrow")
							{
								EnemyAI componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<EnemyAI>();
								if ((Object)(object)componentInParent != (Object)null)
								{
									Hit(projectile.Client, componentInParent, projectile.Power, ((Vector3)(ref projectile.Velocity)).normalized, ((RaycastHit)(ref val2)).point, "bullet");
								}
								if ((Object)(object)((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<Re4CrateTarget>() != (Object)null && Session.FindPlayer(projectile.Client) != null)
								{
									Director.Instance.CrateRay(projectile.Position - ((Vector3)(ref projectile.Velocity)).normalized * 0.1f, ((Vector3)(ref projectile.Velocity)).normalized, 0.5f);
								}
								shots.Remove(projectile);
							}
							else if (projectile.Mode == "mine" || projectile.Mode == "bolt")
							{
								projectile.Velocity = Vector3.zero;
								projectile.Detonate = Time.time + ((projectile.Mode == "mine") ? 2f : 0.8f);
							}
							else
							{
								Blast(projectile);
								shots.Remove(projectile);
							}
							continue;
						}
						projectile.Position += val;
						if (projectile.Mode == "arrow" || projectile.Mode == "bolt")
						{
							projectile.Velocity += Vector3.down * 4f * num;
						}
						if (Time.time >= projectile.Expires)
						{
							if (projectile.Mode != "arrow")
							{
								Blast(projectile);
							}
							shots.Remove(projectile);
						}
					}
				}
			}
		}

		private static void Blast(Projectile shot)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			using (WeaponShots.Use(shot.Shot?.At(shot.Position)))
			{
				Director.Instance.BlastCrates(shot.Position + Vector3.up * 0.05f, 4f);
				foreach (EnemyAI item in (from c in Physics.OverlapSphere(shot.Position, 4f, -1, (QueryTriggerInteraction)2)
					select ((Component)c).GetComponentInParent<EnemyAI>() into e
					where (Object)(object)e != (Object)null && !e.isEnemyDead
					select e).Distinct())
				{
					Vector3 val = ((Component)item).transform.position + Vector3.up;
					float num = Vector3.Distance(val, shot.Position);
					if (!Physics.Linecast(shot.Position + Vector3.up * 0.05f, val, Controller.WorldMask, (QueryTriggerInteraction)1))
					{
						ulong client = shot.Client;
						int power = (int)((float)shot.Power * Mathf.Lerp(1f, 0.2f, Mathf.Clamp01(num / 4f)));
						Vector3 val2 = val - shot.Position;
						Hit(client, item, power, ((Vector3)(ref val2)).normalized, val, "blast");
					}
				}
				Session.Instance.Broadcast(new Packet
				{
					Op = "blastfx",
					Point = shot.Position
				});
			}
		}
	}
	[Serializable]
	public sealed class ModelInfo
	{
		public string[] textures = Array.Empty<string>();

		public string[] opacityMasks = Array.Empty<string>();
	}
	public static class Assets
	{
		private static readonly Dictionary<string, AudioClip> sounds = new Dictionary<string, AudioClip>();

		private static readonly Dictionary<string, Texture2D> textures = new Dictionary<string, Texture2D>();

		private static readonly Dictionary<string, GameObject> models = new Dictionary<string, GameObject>();

		private static readonly Dictionary<string, Mesh> attachedMeshes = new Dictionary<string, Mesh>();

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

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

		private static AudioSource? localAudio;

		public const float PickupScale = 1.3600353f;

		public const float SfxGain = 0.5f;

		public static Material Material(Color color, Texture2D? texture = null, bool cutout = false)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_002e: 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)
			Shader obj = Shader.Find("HDRP/Lit") ?? Shader.Find("Standard") ?? Shader.Find("Unlit/Texture");
			Material val = new Material(obj);
			val.color = color;
			if (val.HasProperty("_BaseColor"))
			{
				val.SetColor("_BaseColor", color);
			}
			if (val.HasProperty("_Smoothness"))
			{
				val.SetFloat("_Smoothness", 0.22f);
			}
			if (val.HasProperty("_DoubleSidedEnable"))
			{
				val.SetFloat("_DoubleSidedEnable", 1f);
			}
			if (val.HasProperty("_DoubleSidedNormalMode"))
			{
				val.SetFloat("_DoubleSidedNormalMode", 1f);
			}
			if (val.HasProperty("_OpaqueCullMode"))
			{
				val.SetFloat("_OpaqueCullMode", 0f);
			}
			if (val.HasProperty("_CullMode"))
			{
				val.SetFloat("_CullMode", 0f);
			}
			if (val.HasProperty("_CullModeForward"))
			{
				val.SetFloat("_CullModeForward", 0f);
			}
			if ((Object)(object)texture != (Object)null)
			{
				val.mainTexture = (Texture)(object)texture;
				if (val.HasProperty("_BaseColorMap"))
				{
					val.SetTexture("_BaseColorMap", (Texture)(object)texture);
				}
			}
			if (val.HasProperty("_AlphaCutoffEnable"))
			{
				val.SetFloat("_AlphaCutoffEnable", (float)(cutout ? 1 : 0));
				val.SetFloat("_AlphaCutoff", 0.3f);
			}
			if (((Object)obj).name.StartsWith("HDRP/"))
			{
				HDMaterial.ValidateMaterial(val);
			}
			else if (cutout)
			{
				val.EnableKeyword("_ALPHATEST_ON");
				val.renderQueue = 2450;
			}
			Object.DontDestroyOnLoad((Object)(object)val);
			return val;
		}

		public static Texture2D Texture(string reference, string opacity = "")
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			string key = reference + "|" + opacity;
			if (textures.TryGetValue(key, out Texture2D value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			string path = Path.Combine(Plugin.AssetPath, "textures", reference + ".png");
			if (!File.Exists(path))
			{
				throw new FileNotFoundException("Original diffuse texture missing: " + reference);
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true);
			ImageConversion.LoadImage(val, File.ReadAllBytes(path));
			if (opacity.Length > 0)
			{
				Texture2D val2 = Texture(opacity);
				if (((Texture)val2).width != ((Texture)val).width || ((Texture)val2).height != ((Texture)val).height)
				{
					throw new InvalidDataException("Opacity mask dimensions differ: " + reference);
				}
				Color32[] pixels = val.GetPixels32();
				Color32[] pixels2 = val2.GetPixels32();
				for (int i = 0; i < pixels.Length; i++)
				{
					pixels[i].a = pixels2[i].a;
				}
				val.SetPixels32(pixels);
				val.Apply(true, false);
			}
			((Object)val).name = "RE4 " + reference;
			((Texture)val).wrapMode = (TextureWrapMode)0;
			((Texture)val).filterMode = (FilterMode)2;
			((Texture)val).anisoLevel = 4;
			Object.DontDestroyOnLoad((Object)(object)val);
			textures[key] = val;
			return val;
		}

		public static GameObject Weapon(int index)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			string model = WeaponSpec.All[index].Model;
			GameObject val = new GameObject("RE4 " + model);
			GameObject val2 = Model(model);
			val2.transform.SetParent(val.transform, false);
			HeldWeaponProfile heldWeaponProfile = HeldWeaponRules.For(index);
			val2.transform.localRotation = Quaternion.Euler(0f, heldWeaponProfile.Yaw, 0f) * Quaternion.LookRotation(Vector3.down, Vector3.right);
			if (HeldWeaponRules.OriginalMount(index))
			{
				return val;
			}
			SkinnedMeshRenderer component = val2.GetComponent<SkinnedMeshRenderer>();
			Vector3[] vertices = component.sharedMesh.vertices;
			int[] triangles = component.sharedMesh.triangles;
			bool flag = true;
			Bounds val3 = default(Bounds);
			int[] array = triangles;
			foreach (int num in array)
			{
				Vector3 val4 = val.transform.InverseTransformPoint(val2.transform.TransformPoint(vertices[num]));
				if (flag)
				{
					((Bounds)(ref val3))..ctor(val4, Vector3.zero);
					flag = false;
				}
				else
				{
					((Bounds)(ref val3)).Encapsulate(val4);
				}
			}
			float num2 = HeldWeaponRules.Scale(Mathf.Max(((Bounds)(ref val3)).size.x, Mathf.Max(((Bounds)(ref val3)).size.y, ((Bounds)(ref val3)).size.z)), heldWeaponProfile.Length);
			val2.transform.localScale = Vector3.one * num2;
			val2.transform.localPosition = -new Vector3(heldWeaponProfile.Grip.X, heldWeaponProfile.Grip.Y, heldWeaponProfile.Grip.Z) * num2;
			return val;
		}

		public static GameObject Knife()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_002d: 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)
			GameObject val = new GameObject("RE4 combat knife");
			GameObject obj = Model("knife");
			obj.transform.SetParent(val.transform, false);
			obj.transform.localRotation = Quaternion.identity;
			obj.transform.localPosition = new Vector3(0.704f, -1.50783f, -0.0344f);
			return val;
		}

		public static void SizeCharacter(GameObject root, float height)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			SkinnedMeshRenderer[] componentsInChildren = root.GetComponentsInChildren<SkinnedMeshRenderer>();
			if (componentsInChildren.Length != 0)
			{
				Bounds bounds = componentsInChildren[0].sharedMesh.bounds;
				SkinnedMeshRenderer[] array = componentsInChildren;
				foreach (SkinnedMeshRenderer val in array)
				{
					((Bounds)(ref bounds)).Encapsulate(val.sharedMesh.bounds);
				}
				float num = height / Mathf.Max(0.1f, ((Bounds)(ref bounds)).size.y);
				root.transform.localScale = Vector3.one * num;
				root.transform.localPosition = Vector3.up * ((0f - ((Bounds)(ref bounds)).min.y) * num);
			}
		}

		public static GameObject Leon()
		{
			return Character(PlayableCharacters.All[0]);
		}

		public static GameObject Character(PlayableCharacter character)
		{
			GameObject val = Model(character.Key);
			string[] parts = character.Parts;
			foreach (string name in parts)
			{
				Attach(val, name);
			}
			((Object)val).name = "Original RE4 " + character.Name;
			Re4Rig[] componentsInChildren = val.GetComponentsInChildren<Re4Rig>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].MotionBank = character.Bank;
			}
			return val;
		}

		public static GameObject Merchant()
		{
			GameObject val = Model("merchant");
			string[] array = new string[7] { "merchant_head", "merchant_cloak_left", "merchant_cloak_right", "merchant_pack", "merchant_goods", "merchant_right_hand", "merchant_left_hand" };
			foreach (string name in array)
			{
				Attach(val, name);
			}
			return val;
		}

		public static GameObject Jacket()
		{
			return Model("leon_jacket");
		}

		internal static GameObject Attach(GameObject body, string name)
		{
			GameObject val = Model(name);
			val.transform.SetParent(body.transform, false);
			Re4Rig master = body.GetComponent<Re4Rig>();
			Re4Rig component = val.GetComponent<Re4Rig>();
			SkinnedMeshRenderer component2 = val.GetComponent<SkinnedMeshRenderer>();
			if ((Object)(object)master == (Object)null || (Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null)
			{
				return val;
			}
			Dictionary<int, Transform> map = master.Ids.Select((int id, int index) => (id: id, index: index)).ToDictionary(((int id, int index) x) => x.id, ((int id, int index) x) => master.Bones[x.index]);
			if (component.Ids.Any((int id) => !map.ContainsKey(id)))
			{
				throw new InvalidDataException("Attachment bone not present in body skeleton: " + name);
			}
			Transform[] bones = component.Ids.Select((int id) => map[id]).ToArray();
			if (!attachedMeshes.TryGetValue(name, out Mesh value) || (Object)(object)value == (Object)null)
			{
				value = Object.Instantiate<Mesh>(component2.sharedMesh);
				((Object)value).name = name + " shared body skin";
				Matrix4x4[] original = body.GetComponent<SkinnedMeshRenderer>().sharedMesh.bindposes;
				Dictionary<int, int> indices = master.Ids.Select((int id, int i) => (id: id, i: i)).ToDictionary(((int id, int i) p) => p.id, ((int id, int i) p) => p.i);
				value.bindposes = component.Ids.Select((int id) => original[indices[id]]).ToArray();
				Object.DontDestroyOnLoad((Object)(object)value);
				attachedMeshes[name] = value;
			}
			component2.sharedMesh = value;
			component2.bones = bones;
			component2.rootBone = master.Bones[0];
			component.SharedRig = master;
			return val;
		}

		internal static GameObject Model(string name)
		{
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Expected O, but got Unknown
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Expected O, but got Unknown
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0520: Unknown result type (might be due to invalid IL or missing references)
			//IL_0525: Unknown result type (might be due to invalid IL or missing references)
			//IL_052f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0534: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			if (models.TryGetValue(name, out GameObject value) && (Object)(object)value != (Object)null)
			{
				GameObject obj = Object.Instantiate<GameObject>(value);
				obj.SetActive(true);
				return obj;
			}
			string text = Path.Combine(Plugin.AssetPath, "models", name + ".r4m");
			if (!File.Exists(text))
			{
				Plugin.Log("Missing original RE4 mesh: " + text);
				return Fallback(name);
			}
			using BinaryReader binaryReader = new BinaryReader(File.OpenRead(text));
			if (new string(binaryReader.ReadChars(4)) != "R4M1")
			{
				throw new InvalidDataException("Invalid mesh " + name);
			}
			int num = binaryReader.ReadInt32();
			int num2 = binaryReader.ReadInt32();
			int num3 = binaryReader.ReadInt32();
			if (num < 1 || num > 1000000 || num2 < 1 || num2 > 512 || num3 < 1 || num3 > 256)
			{
				throw new InvalidDataException("Invalid mesh sizes");
			}
			GameObject root = new GameObject(name);
			root.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)root);
			Transform[] array = (Transform[])(object)new Transform[num2];
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			int[] array2 = new int[num2];
			int[] array3 = new int[num2];
			for (int i = 0; i < num2; i++)
			{
				int num4 = binaryReader.ReadInt32();
				array2[i] = binaryReader.ReadInt32();
				array3[i] = num4;
				Transform transform = new GameObject("bone_" + num4).transform;
				transform.SetParent(root.transform, false);
				transform.localPosition = ReadVector(binaryReader);
				array[i] = transform;
				dictionary[num4] = i;
			}
			for (int j = 0; j < num2; j++)
			{
				if (dictionary.TryGetValue(array2[j], out var value2) && value2 != j)
				{
					array[j].SetParent(array[value2], false);
				}
			}
			Vector3[] array4 = (Vector3[])(object)new Vector3[num];
			Vector3[] array5 = (Vector3[])(object)new Vector3[num];
			Vector2[] array6 = (Vector2[])(object)new Vector2[num];
			BoneWeight[] array7 = (BoneWeight[])(object)new BoneWeight[num];
			for (int k = 0; k < num; k++)
			{
				array4[k] = ReadVector(binaryReader);
				int num5 = k;
				Vector3 val = ReadVector(binaryReader);
				array5[num5] = ((Vector3)(ref val)).normalized;
				array6[k] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
				int key = binaryReader.ReadInt32();
				int key2 = binaryReader.ReadInt32();
				int key3 = binaryReader.ReadInt32();
				float num6 = binaryReader.ReadSingle();
				float num7 = binaryReader.ReadSingle();
				float num8 = binaryReader.ReadSingle();
				float num9 = num6 + num7 + num8;
				if (num9 < 0.001f)
				{
					num6 = 1f;
					num9 = 1f;
				}
				int num10 = k;
				BoneWeight val2 = default(BoneWeight);
				((BoneWeight)(ref val2)).boneIndex0 = (dictionary.TryGetValue(key, out var value3) ? value3 : 0);
				((BoneWeight)(ref val2)).boneIndex1 = (dictionary.TryGetValue(key2, out var value4) ? value4 : 0);
				((BoneWeight)(ref val2)).boneIndex2 = (dictionary.TryGetValue(key3, out var value5) ? value5 : 0);
				((BoneWeight)(ref val2)).weight0 = num6 / num9;
				((BoneWeight)(ref val2)).weight1 = num7 / num9;
				((BoneWeight)(ref val2)).weight2 = num8 / num9;
				array7[num10] = val2;
			}
			Mesh val3 = new Mesh
			{
				name = "RE4 " + name,
				indexFormat = (IndexFormat)1,
				vertices = array4,
				normals = array5,
				uv = array6,
				boneWeights = array7,
				subMeshCount = num3
			};
			val3.bindposes = array.Select((Transform b) => b.worldToLocalMatrix * root.transform.localToWorldMatrix).ToArray();
			ModelInfo modelInfo = UiDataJson.Read<ModelInfo>(File.ReadAllText(Path.ChangeExtension(text, "json")), name);
			Material[] array8 = (Material[])(object)new Material[num3];
			for (int num11 = 0; num11 < num3; num11++)
			{
				int num12 = binaryReader.ReadInt32();
				int num13 = binaryReader.ReadInt32();
				if (num13 < 0 || num13 > 3000000)
				{
					throw new InvalidDataException("Bad triangle count");
				}
				int[] array9 = new int[num13];
				for (int num14 = 0; num14 < num13; num14++)
				{
					array9[num14] = binaryReader.ReadInt32();
				}
				val3.SetTriangles(array9, num11);
				Texture2D val4 = null;
				if (num12 < 0 || num12 >= modelInfo.textures.Length)
				{
					throw new InvalidDataException("Invalid texture binding: " + name);
				}
				string text2 = ((num12 < modelInfo.opacityMasks.Length) ? modelInfo.opacityMasks[num12] : "");
				val4 = Texture(modelInfo.textures[num12], text2);
				array8[num11] = Material(Color.white, val4, text2.Length > 0);
			}
			val3.RecalculateBounds();
			val3.RecalculateTangents();
			Object.DontDestroyOnLoad((Object)(object)val3);
			SkinnedMeshRenderer obj2 = root.AddComponent<SkinnedMeshRenderer>();
			obj2.sharedMesh = val3;
			((Renderer)obj2).sharedMaterials = array8;
			obj2.bones = array;
			obj2.rootBone = array[0];
			obj2.updateWhenOffscreen = true;
			((Renderer)obj2).localBounds = new Bounds(new Vector3(0f, 1f, 0f), Vector3.one * 4f);
			((Renderer)obj2).lightProbeUsage = (LightProbeUsage)1;
			((Renderer)obj2).reflectionProbeUsage = (ReflectionProbeUsage)1;
			if (WeaponSpec.All.Any((WeaponSpec w) => w.Model == name) || name.StartsWith("verified_") || name == "krauser_bow" || name == "merchant" || name.StartsWith("merchant_") || PlayableCharacters.All.Any((PlayableCharacter c) => name == c.Key || name.StartsWith(c.Key + "_")))
			{
				Re4Rig re4Rig = root.AddComponent<Re4Rig>();
				re4Rig.Bones = array;
				re4Rig.Ids = array3;
			}
			models[name] = root;
			GameObject obj3 = Object.Instantiate<GameObject>(root);
			obj3.SetActive(true);
			return obj3;
		}

		private static Vector3 ReadVector(BinaryReader reader)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
		}

		private static GameObject Fallback(string name)
		{
			//IL_0026: 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)
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3);
			Object.Destroy((Object)(object)obj.GetComponent<Collider>());
			obj.transform.localScale = new Vector3(0.06f, 0.1f, 0.3f);
			obj.GetComponent<Renderer>().sharedMaterial = Material(new Color(0.25f, 0.22f, 0.17f));
			return obj;
		}

		internal static Bounds PickupBounds(SkinnedMeshRenderer skin)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			Mesh sharedMesh = skin.sharedMesh;
			Vector3[] vertices = sharedMesh.vertices;
			Bounds result = default(Bounds);
			bool flag = true;
			for (int i = 0; i < sharedMesh.subMeshCount; i++)
			{
				Texture mainTexture = ((Renderer)skin).sharedMaterials[i].mainTexture;
				Texture2D val = (Texture2D)(object)((mainTexture is Texture2D) ? mainTexture : null);
				if ((Object)(object)val != (Object)null && !val.GetPixels32().Any((Color32 c) => c.a > 0))
				{
					continue;
				}
				int[] triangles = sharedMesh.GetTriangles(i);
				foreach (int num2 in triangles)
				{
					if (flag)
					{
						((Bounds)(ref result))..ctor(vertices[num2], Vector3.zero);
						flag = false;
					}
					else
					{
						((Bounds)(ref result)).Encapsulate(vertices[num2]);
					}
				}
			}
			if (!flag)
			{
				return result;
			}
			return sharedMesh.bounds;
		}

		public static GameObject Pickup(string kind)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			ItemModel itemModel = ItemCatalog.Get(kind);
			GameObject val = new GameObject("RE4 " + kind);
			GameObject val2 = Model(itemModel.world);
			val2.transform.SetParent(val.transform, false);
			SkinnedMeshRenderer[] componentsInChildren = val2.GetComponentsInChildren<SkinnedMeshRenderer>();
			Bounds val3 = PickupBounds(componentsInChildren[0]);
			foreach (SkinnedMeshRenderer item in componentsInChildren.Skip(1))
			{
				((Bounds)(ref val3)).Encapsulate(PickupBounds(item));
			}
			float num = ((itemModel.worldHeight > 0f) ? (itemModel.worldHeight / Mathf.Max(0.001f, ((Bounds)(ref val3)).size.y)) : 1f);
			val2.transform.localScale = Vector3.one * num;
			val2.transform.localPosition = new Vector3((0f - ((Bounds)(ref val3)).center.x) * num, (0f - ((Bounds)(ref val3)).min.y) * num, (0f - ((Bounds)(ref val3)).center.z) * num);
			BoxCollider obj = val.AddComponent<BoxCollider>();
			((Collider)obj).isTrigger = true;
			obj.center = Vector3.up * ((Bounds)(ref val3)).size.y * num * 0.5f;
			obj.size = ((Bounds)(ref val3)).size * num;
			val.transform.localScale = Vector3.one * 1.3600353f;
			return val;
		}

		public static AudioClip Sound(string bank, int index)
		{
			string text = $"{bank}_{index:000}";
			if (sounds.TryGetValue(text, out AudioClip value))
			{
				return value;
			}
			WaveData waveData = WaveData.Read(File.ReadAllBytes(Path.Combine(Plugin.AssetPath, "audio", text + ".wav")));
			value = AudioClip.Create(text, waveData.Samples.Length / waveData.Channels, waveData.Channels, waveData.Rate, false);
			if (!value.SetData(waveData.Samples, 0))
			{
				throw new InvalidDataException("Unity rejected PCM sample data");
			}
			sounds[text] = value;
			return value;
		}

		public static bool Play(string bank, int index, Vector3 position, float volume, bool local = false)
		{
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			volume *= 0.5f;
			string text = $"{bank}_{index:000}";
			try
			{
				AudioClip val = Sound(bank, index);
				if (local)
				{
					if ((Object)(object)localAudio == (Object)null)
					{
						GameObject val2 = new GameObject("RE4 local weapon audio");
						Object.DontDestroyOnLoad((Object)val2);
						localAudio = val2.AddComponent<AudioSource>();
						localAudio.playOnAwake = false;
						localAudio.spatialBlend = 0f;
						localAudio.spatialize = false;
						localAudio.dopplerLevel = 0f;
						localAudio.priority = 32;
						localAudio.bypassEffects = true;
						localAudio.bypassListenerEffects = true;
						localAudio.bypassReverbZones = true;
					}
					((Behaviour)localAudio).enabled = true;
					localAudio.mute = false;
					localAudio.volume = 1f;
					if ((Object)(object)Controller.Player?.itemAudio != (Object)null)
					{
						localAudio.outputAudioMixerGroup = Controller.Player.itemAudio.outputAudioMixerGroup;
					}
					localAudio.PlayOneShot(val, volume);
					if (reportedClips.Add(text))
					{
						Plugin.Log($"Playing local RE4 audio: {text}, {val.samples} frames at {val.frequency} Hz, spatializer disabled.");
					}
					return true;
				}
				GameObject val3 = new GameObject("RE4 sound " + text);
				val3.transform.position = position;
				AudioSource obj = val3.AddComponent<AudioSource>();
				obj.playOnAwake = false;
				obj.spatialize = false;
				obj.dopplerLevel = 0f;
				obj.clip = val;
				obj.volume = volume;
				obj.spatialBlend = 1f;
				obj.minDistance = 2f;
				obj.maxDistance = 35f;
				obj.rolloffMode = (AudioRolloffMode)1;
				obj.Play();
				Object.Destroy((Object)val3, val.length + 0.2f);
				return true;
			}
			catch (Exception ex)
			{
				if (audioErrors.Add(text))
				{
					Plugin.Log("Audio playback failed: " + text + ": " + ex.Message);
				}
				return false;
			}
		}
	}
	public sealed class Avatars
	{
		private sealed class Avatar
		{
			public GameObject Root;

			public string Character = "leon";

			public GameObject? Weapon;

			public GameObject? Knife;

			public int WeaponIndex = -1;

			public float GroundOffset;

			public float BodyHeight = 2.5f;

			public Re4Rig[] Rigs = Array.Empty<Re4Rig>();

			public Dictionary<Renderer, bool> Hidden = new Dictionary<Renderer, bool>();

			public Renderer[] Body = Array.Empty<Renderer>();

			public Renderer[] Head = Array.Empty<Renderer>();

			public Dictionary<Renderer, bool> VisorRenderers = new Dictionary<Renderer, bool>();

			public Camera? VisorCamera;

			public bool VisorWasEnabled;

			public bool VisorHidden;

			public AnimatorCullingMode NativeCulling;
		}

		private readonly Dictionary<PlayerControllerB, Avatar> players = new Dictionary<PlayerControllerB, Avatar>();

		private static Avatars? current;

		private static readonly Dictionary<ulong, Re4Rig> bodies = new Dictionary<ulong, Re4Rig>();

		internal static GameObject? LocalVisualRoot;

		internal static Renderer[] LocalBody = Array.Empty<Renderer>();

		public static bool LocalWeaponVisible { get; private set; }

		public static GameObject? LocalWeapon { get; private set; }

		public static Transform? LocalLightAnchor { get; private set; }

		public Avatars()
		{
			current = this;
		}

		internal static void RefreshNativePoses()
		{
			if (current == null)
			{
				return;
			}
			foreach (KeyValuePair<PlayerControllerB, Avatar> player in current.players)
			{
				PlayerControllerB key = player.Key;
				if ((Object)(object)key == (Object)null)
				{
					continue;
				}
				InteractionPolicy state = NativeInteractions.For(key);
				if (!state.UpperPose)
				{
					continue;
				}
				Re4Rig[] rigs = player.Value.Rigs;
				foreach (Re4Rig re4Rig in rigs)
				{
					if ((Object)(object)re4Rig != (Object)null && (Object)(object)re4Rig.SharedRig == (Object)null)
					{
						NativePoseBridge.Apply(key, re4Rig, state);
					}
				}
				if ((Object)(object)player.Value.Weapon != (Object)null)
				{
					player.Value.Weapon.SetActive(false);
				}
				if ((Object)(object)player.Value.Knife != (Object)null)
				{
					player.Value.Knife.SetActive(false);
				}
			}
		}

		public static Transform? Attachment(PlayerControllerB player, bool head)
		{
			Transform? obj;
			if (!OutfitMode.Enabled(player))
			{
				if (!bodies.TryGetValue(player.actualClientId, out Re4Rig value) || !((Object)(object)value != (Object)null))
				{
					return null;
				}
				obj = value.Bone(head ? 4 : 2);
				if (obj == null)
				{
					return ((Component)value).transform;
				}
			}
			else
			{
				obj = OutfitAvatars.Attachment(player, head);
			}
			return obj;
		}

		internal static Vector3 HandPoint(PlayerControllerB player)
		{
			//IL_0009: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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)
			if (OutfitMode.Enabled(player))
			{
				return OutfitAvatars.HandPoint(player);
			}
			if (current != null && current.players.TryGetValue(player, out Avatar value))
			{
				Transform val = value.Rigs.FirstOrDefault((Re4Rig r) => (Object)(object)r.SharedRig == (Object)null)?.Bone(10);
				if ((Object)(object)val != (Object)null)
				{
					return val.position;
				}
			}
			return Controller.CombatOrigin(player) + player.thisPlayerBody.forward * 0.35f;
		}

		public void Tick()
		{
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_0577: Unknown result type (might be due to invalid IL or missing references)
			//IL_057d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0609: Unknown result type (might be due to invalid IL or missing references)
			//IL_060e: Unknown result type (might be due to invalid IL or missing references)
			//IL_062f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0644: Unknown result type (might be due to invalid IL or missing references)
			//IL_0747: Unknown result type (might be due to invalid IL or missing references)
			//IL_074c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0872: Unknown result type (might be due to invalid IL or missing references)
			//IL_0840: Unknown result type (might be due to invalid IL or missing references)
			//IL_085b: Unknown result type (might be due to invalid IL or missing references)
			//IL_086b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0996: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a9b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a66: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a6d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a77: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a7c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0be5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bf4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c05: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c0c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c21: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c23: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c2d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c32: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c46: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c4d: Unknown result type (might be due to invalid IL or missing references)
			LocalVisualRoot = null;
			LocalBody = Array.Empty<Renderer>();
			LocalWeaponVisible = false;
			LocalWeapon = null;
			LocalLightAnchor = null;
			if (!Session.Connected || (Object)(object)StartOfRound.Instance == (Object)null)
			{
				Clear();
				return;
			}
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				if (!Plugin.LeonAvatars.Value && !OutfitMode.Enabled(val))
				{
					if (players.TryGetValue(val, out Avatar value))
					{
						Restore(val, value);
						players.Remove(val);
					}
					OutfitAvatars.Forget(val);
					continue;
				}
				if (OutfitMode.Enabled(val) && val.isPlayerControlled && !val.isPlayerDead)
				{
					if (players.TryGetValue(val, out Avatar value2))
					{
						Restore(val, value2);
						players.Remove(val);
					}
					OutfitAvatars.Present(val);
					if ((Object)(object)val == (Object)(object)Controller.Player)
					{
						LocalVisualRoot = OutfitAvatars.LocalRoot;
						OriginalCamera.ModelScale = 1.3600353f;
						LocalWeaponVisible = (Object)(object)OutfitAvatars.LocalWeapon != (Object)null;
						LocalWeapon = OutfitAvatars.LocalWeapon;
						LocalLightAnchor = OutfitAvatars.Attachment(val, head: false);
					}
					continue;
				}
				OutfitAvatars.Forget(val);
				if (!LeonSuit.IsLeon(val))
				{
					if (players.TryGetValue(val, out Avatar value3))
					{
						Restore(val, value3);
						players.Remove(val);
					}
					continue;
				}
				if (!val.isPlayerControlled || val.isPlayerDead)
				{
					if (players.TryGetValue(val, out Avatar value4))
					{
						value4.Root.SetActive(false);
					}
					continue;
				}
				PlayableCharacter character = PlayableCharacters.For(val);
				if (players.TryGetValue(val, out Avatar value5) && value5.Character != character.Key)
				{
					Restore(val, value5);
					players.Remove(val);
					if ((Object)(object)val == (Object)(object)Controller.Player)
					{
						OriginalCamera.Reset();
					}
				}
				Renderer[] componentsInChildren;
				if (!players.TryGetValue(val, out Avatar value6))
				{
					GameObject val2 = Assets.Character(character);
					Assets.SizeCharacter(val2, 2.5f);
					value6 = new Avatar
					{
						Root = val2,
						Character = character.Key,
						GroundOffset = val2.transform.position.y,
						Rigs = val2.GetComponentsInChildren<Re4Rig>()
					};
					players.Add(val, value6);
					value6.NativeCulling = val.playerBodyAnimator.cullingMode;
					val.playerBodyAnimator.cullingMode = (AnimatorCullingMode)0;
					value6.Body = val2.GetComponentsInChildren<Renderer>();
					value6.Head = (from r in val2.GetComponentsInChildren<Renderer>()
						where ((Object)r).name.StartsWith(character.Key + "_head") || ((Object)r).name.StartsWith(character.Key + "_face") || ((Object)r).name.StartsWith(character.Key + "_hair")
						select r).ToArray();
					SkinnedMeshRenderer[] array = (SkinnedMeshRenderer[])(object)new SkinnedMeshRenderer[3] { val.thisPlayerModel, val.thisPlayerModelLOD1, val.thisPlayerModelLOD2 };
					foreach (SkinnedMeshRenderer val3 in array)
					{
						if ((Object)(object)val3 != (Object)null)
						{
							value6.Hidden[(Renderer)(object)val3] = ((Renderer)val3).forceRenderingOff;
							((Renderer)val3).forceRenderingOff = true;
						}
					}
					if ((Object)(object)val == (Object)(object)Controller.Player)
					{
						if ((Object)(object)val.localVisor != (Object)null)
						{
							componentsInChildren = ((Component)val.localVisor).GetComponentsInChildren<Renderer>(true);
							foreach (Renderer val4 in componentsInChildren)
							{
								value6.VisorRenderers[val4] = val4.forceRenderingOff;
							}
						}
						value6.VisorCamera = val.visorCamera;
						value6.VisorWasEnabled = (Object)(object)val.visorCamera != (Object)null && ((Behaviour)val.visorCamera).enabled;
						Plugin.Log($"{character.Name} assembled with original model attachments; {value6.VisorRenderers.Count} local visor renderers tracked for shoulder view; hand-mounted combat rig enabled at {2.5f:0.00} game-unit standing height.");
					}
				}
				foreach (KeyValuePair<Renderer, bool> item in value6.Hidden)
				{
					if ((Object)(object)item.Key != (Object)null)
					{
						item.Key.forceRenderingOff = true;
					}
				}
				Re4Rig re4Rig = value6.Rigs.FirstOrDefault((Re4Rig r) => (Object)(object)r.SharedRig == (Object)null);
				if ((Object)(object)re4Rig != (Object)null)
				{
					bodies[val.actualClientId] = re4Rig;
				}
				bool flag = (Object)(object)val == (Object)(object)Controller.Player;
				if (flag)
				{
					LocalBody = value6.Body;
					LocalVisualRoot = value6.Root;
				}
				bool flag2 = true;
				bool flag3 = flag;
				foreach (KeyValuePair<Renderer, bool> visorRenderer in value6.VisorRenderers)
				{
					if ((Object)(object)visorRenderer.Key != (Object)null)
					{
						visorRenderer.Key.forceRenderingOff = flag3 || visorRenderer.Value;
					}
				}
				if ((Object)(object)value6.VisorCamera != (Object)null)
				{
					if (flag3)
					{
						((Behaviour)value6.VisorCamera).enabled = false;
					}
					else if (value6.VisorHidden)
					{
						((Behaviour)value6.VisorCamera).enabled = value6.VisorWasEnabled;
					}
				}
				value6.VisorHidden = flag3;
				bool forceRenderingOff = flag && Vector3.Distance(((Component)val.gameplayCamera).transform.position, Controller.CombatOrigin(val)) < 0.65f;
				componentsInChildren = value6.Head;
				for (int num = 0; num < componentsInChildren.Length; num++)
				{
					componentsInChildren[num].forceRenderingOff = forceRenderingOff;
				}
				value6.Root.SetActive(flag2);
				if ((Object)(object)val.thisPlayerModelArms != (Object)null && flag)
				{
					((Renderer)val.thisPlayerModelArms).forceRenderingOff = true;
				}
				value6.Root.transform.position = ((Component)val).transform.position + Vector3.up * value6.GroundOffset;
				value6.Root.transform.rotation = Quaternion.Euler(0f, val.thisPlayerBody.eulerAngles.y + 180f, 0f);
				ActorPose actorPose = Presentation.Get(val.actualClientId);
				if (flag)
				{
					actorPose.Climbing = val.isClimbingLadder;
				}
				actorPose.Airborne = !val.isClimbingLadder && (Object)(object)val.thisController != (Object)null && !val.thisController.isGrounded && (actorPose.Airborne || val.isFallingFromJump || val.isFallingNoJump);
				if (flag)
				{
					Controller instance = Controller.Instance;
					actorPose.Armed = instance.Armed && !instance.InputOverlay && !actorPose.Climbing;
					actorPose.Aiming = instance.Aiming;
					Presentation.Weapon(actorPose, instance.State.Weapon);
					actorPose.Loaded = ((instance.State.Grenade.Length <= 0) ? instance.State.Loaded[actorPose.Weapon] : 0);
					actorPose.Direction = ((Component)val.gameplayCamera).transform.forward;
				}
				bool flag4 = MercRestraints.Held(val.actualClientId) >= 0f;
				if (flag4)
				{
					actorPose = MercRestraints.Pose(val.actualClientId, actorPose);
				}
				InteractionPolicy state = NativeInteractions.For(val);
				if (state.UpperPose)
				{
					actorPose.Armed = false;
					actorPose.Aiming = false;
				}
				bool flag5 = NativeLeverPose.Active(val);
				if (flag5)
				{
					actorPose.Armed = false;
					actorPose.Aiming = false;
				}
				if ((Object)(object)value6.Weapon == (Object)null || value6.WeaponIndex != actorPose.Weapon)
				{
					if ((Object)(object)value6.Weapon != (Object)null)
					{
						Object.Destroy((Object)(object)value6.Weapon);
					}
					value6.Weapon = Assets.Weapon(actorPose.Weapon);
					value6.Weapon.transform.SetParent(value6.Root.transform, false);
					value6.Weapon.transform.localScale = (HeldWeaponRules.OriginalMount(actorPose.Weapon) ? Vector3.one : (Vector3.one * (1.3600353f / Mathf.Max(0.01f, value6.Root.transform.lossyScale.x))));
					value6.WeaponIndex = actorPose.Weapon;
				}
				WeaponHands.Apply(value6.Root, character.Key, actorPose);
				bool flag6 = !state.UpperPose && actorPose.Acting && actorPose.Action == "knife";
				if (flag6 && (Object)(object)value6.Knife == (Object)null)
				{
					value6.Knife = Assets.Knife();
					value6.Knife.transform.SetParent(value6.Root.transform, false);
				}
				value6.Weapon.SetActive(flag2 && actorPose.Armed && !flag6);
				if ((Object)(object)value6.Knife != (Object)null)
				{
					value6.Knife.SetActive(flag2 && flag6 && !flag5);
				}
				value6.BodyHeight = (flag ? Controller.BodyHeight(val) : Mathf.MoveTowards(value6.BodyHeight, Controller.BodyHeight(val), Time.deltaTime * 8f));
				float crouchDrop = MotionRules.CrouchDrop(value6.BodyHeight, value6.Root.transform.lossyScale.y);
				if (flag2)
				{
					Re4Rig[] rigs = value6.Rigs;
					foreach (Re4Rig re4Rig2 in rigs)
					{
						if (!((Object)(object)re4Rig2.SharedRig == (Object)null))
						{
							continue;
						}
						re4Rig2.Player(actorPose, flag6 ? value6.Knife : value6.Weapon, crouchDrop);
						if (re4Rig2.WeaponAimReady && (flag || HeldWeaponRules.OriginalMount(actorPose.Weapon)) && actorPose.Armed && actorPose.Aiming && !actorPose.Acting && !flag6 && !actorPose.Climbing && (!flag || Time.time >= Controller.Instance.ReloadUntil))
						{
							SourceGripAim.Actor(re4Rig2, value6.Weapon, flag ? AimLaser.Target(val.gameplayCamera, WeaponSpec.All[actorPose.Weapon].Range) : (Controller.CombatOrigin(val) + actorPose.Direction * 100f), actorPose);
						}
						if (flag4)
						{
							string text = CombatImpact.CaptureClip?.Invoke(val.actualClientId) ?? "";
							if (text.Length > 0)
							{
								float num2 = MercRestraints.Held(val.actualClientId) * 30f;
								re4Rig2.Scene(text, Mathf.Min(num2, (float)OriginalMotion.Clip(text).MaxFrame));
							}
							else if (!MercRestraints.Escaping(val.actualClientId))
							{
								float num3 = MercRestraints.Held(val.actualClientId);
								float num4 = Mathf.Max(1, OriginalMotion.Clip("player_neck_hold").MaxFrame);
								re4Rig2.Scene("player_neck_hold", num3 * 30f % num4);
							}
						}
						if (flag5)
						{
							NativeLeverPose.Apply(val, re4Rig2);
						}
						if (state.UpperPose)
						{
							NativePoseBridge.Apply(val, re4Rig2, state);
						}
						if (!state.UpperPose && !flag6 && !flag5 && !actorPose.Armed && !actorPose.Climbing && (Object)(object)val.currentlyHeldObjectServer != (Object)null && !(val.currentlyHeldObjectServer is KeyItem))
						{
							Transform val5 = (flag ? val.localItemHolder : val.serverItemHolder);
							Vector3 val6 = ((Component)re4Rig2).transform.InverseTransformPoint(val5.position);
							re4Rig2.Arm(right: true, val6, new Vector3(-0.65f, 1.2f, 0.1f), val5.rotation);
							if (val.twoHanded)
							{
								re4Rig2.Arm(right: false, val6 + Vector3.right * 0.15f, new Vector3(0.6f, 1.2f, 0.1f), val5.rotation);
							}
						}
					}
				}
				if (flag)
				{
					OriginalCamera.ModelScale = 1.3600353f;
					LocalLightAnchor = value6.Rigs.FirstOrDefault((Re4Rig r) => (Object)(object)r.SharedRig == (Object)null)?.Bone(2) ?? value6.Root.transform;
					LocalWeaponVisible = flag2 && actorPose.Armed;
					LocalWeapon = ((LocalWeaponVisible && !flag6) ? value6.Weapon : null);
				}
			}
			Controller.Instance.RefreshWeaponVisibility();
			allPlayerScripts = players.Keys.Where((PlayerControllerB p) => (Object)(object)p == (Object)null).ToArray();
			foreach (PlayerControllerB key in allPlayerScripts)
			{
				if ((Object)(object)players[key].Root != (Object)null)
				{
					Object.Destroy((Object)(object)players[key].Root);
				}
				players.Remove(key);
			}
		}

		private static void Restore(PlayerControllerB p, Avatar avatar)
		{
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)p != (Object)null)
			{
				NativeLeverPose.Forget(p);
				bodies.Remove(p.actualClientId);
			}
			foreach (KeyValuePair<Renderer, bool> item in avatar.Hidden)
			{
				if ((Object)(object)item.Key != (Object)null)
				{
					item.Key.forceRenderingOff = item.Value;
				}
			}
			foreach (KeyValuePair<Renderer, bool> visorRenderer in avatar.VisorRenderers)
			{
				if ((Object)(object)visorRenderer.Key != (Object)null)
				{
					visorRenderer.Key.forceRenderingOff = visorRenderer.Value;
				}
			}
			if ((Object)(object)avatar.VisorCamera != (Object)null && avatar.VisorHidden)
			{
				((Behaviour)avatar.VisorCamera).enabled = avatar.VisorWasEnabled;
			}
			if ((Object)(object)p != (Object)null && (Object)(object)p.playerBodyAnimator != (Object)null)
			{
				p.playerBodyAnimator.cullingMode = avatar.NativeCulling;
			}
			if ((Object)(object)p != (Object)null && (Object)(object)p.thisPlayerModelArms != (Object)null)
			{
				((Renderer)p.thisPlayerModelArms).forceRenderingOff = false;
			}
			Re4Rig[] rigs = avatar.Rigs;
			for (int i = 0; i < rigs.Length; i++)
			{
				NativePoseBridge.Forget(rigs[i]);
			}
			if ((Object)(object)avatar.Root != (Object)null)
			{
				Object.Destroy((Object)(object)avatar.Root);
			}
		}

		private void Clear()
		{
			OutfitAvatars.Clear();
			NativeLeverPose.Clear();
			bodies.Clear();
			foreach (KeyValuePair<PlayerControllerB, Avatar> player in players)
			{
				Restore(player.Key, player.Value);
			}
			players.Clear();
			LocalWeaponVisible = false;
			LocalWeapon = null;
			LocalLightAnchor = null;
		}

		public void Dispose()
		{
			Clear();
		}
	}
	public sealed class BindingEdits
	{
		private readonly Dictionary<string, string> values = new Dictionary<string, string>();

		public void Set(string id, string value)
		{
			values[id] = value;
		}

		public string Value(string id, string configured)
		{
			if (!values.TryGetValue(id, out string value))
			{
				return configured;
			}
			return value;
		}

		public void Reset(IEnumerable<KeyValuePair<string, string>> defaults)
		{
			values.Clear();
			foreach (KeyValuePair<string, string> @default in defaults)
			{
				values[@default.Key] = @default.Value;
			}
		}

		public void Commit(Action<string, string> save)
		{
			foreach (KeyValuePair<string, string> value in values)
			{
				save(value.Key, value.Value);
			}
			values.Clear();
		}

		public void Clear()
		{
			values.Clear();
		}
	}
	public static class BowMotionRules
	{
		public const int ReloadStart = 8;

		public static float ReleaseFrame(float age, float interval, int end)
		{
			return Math.Clamp(age / Math.Max(0.01f, interval), 0f, 1f) * (float)end;
		}

		public static float ReloadFrame(float progress, int end)
		{
			return (float)Math.Min(end, 8) + (float)(end - Math.Min(end, 8)) * Math.Clamp(progress, 0f, 1f);
		}

		public static bool CanCorrectAim(bool drawing, bool reloading, bool firing, float releaseProgress)
		{
			if (!drawing && !reloading)
			{
				if (firing)
				{
					return releaseProgress < 0.18f;
				}
				return true;
			}
			return false;
		}
	}
	public static class CameraMath
	{
		public static Vector3 Rebase(Vector3 history, Vector3 previousAnchor, Vector3 anchor)
		{
			return history + anchor - previousAnchor;
		}
	}
	public static class CampaignConsumables
	{
		public static bool Grenade(string kind)
		{
			switch (kind)
			{
			case "Hand grenade":
			case "Incendiary grenade":
			case "Flash grenade":
				return true;
			default:
				return false;
			}
		}

		public static bool Throwable(string kind)
		{
			return OriginalGrenadeRules.IsThrowable(kind);
		}

		public static string Model(string kind)
		{
			if (!OriginalPickupRules.Egg(kind))
			{
				return "held_grenade_" + ((kind == "Hand grenade") ? "hand" : ((kind == "Incendiary grenade") ? "incendiary" : "flash"));
			}
			return "pickup_" + ((kind == "Chicken egg") ? "chicken_egg" : ((kind == "Brown chicken egg") ? "brown_chicken_egg" : "gold_chicken_egg"));
		}

		public static int ItemId(string kind)
		{
			if (!(kind == "Hand grenade"))
			{
				if (!(kind == "Incendiary grenade"))
				{
					return 14;
				}
				return 2;
			}
			return 1;
		}
	}
	[Serializable]
	public sealed class GrenadeFrame
	{
		public int Id;

		public ulong Client;

		public string Kind = "";

		public Vector3 Position;

		public Vector3 Velocity;

		public Vector3 Rotation;

		public Vector3 Spin;

		public float Detonate;

		public float LastTick;

		public float Scale;

		public int Ticks;
	}
	public sealed class Director
	{
		private sealed class FireArea
		{
			public ulong Client;

			public Vector3 Point;

			public float Until;

			public float Next;

			public readonly HashSet<int> Caught = new HashSet<int>();
		}

		private sealed class FireVictim
		{
			public ulong Client;

			public EnemyAI Enemy;

			public Vector3 Point;

			public int Tick;

			public float Next;
		}

		private readonly Dictionary<int, GameObject> grenadeModels = new Dictionary<int, GameObject>();

		private readonly List<FireArea> fires = new List<FireArea>();

		private readonly List<FireVictim> fireVictims = new List<FireVictim>();

		private float outsideEggsAt;

		public static Director Instance;

		public WorldFrame World = new WorldFrame();

		private readonly Dictionary<int, GameObject> drops = new Dictionary<int, GameObject>();

		private readonly Dictionary<EnemyAI, float> nativeStaggers = new Dictionary<EnemyAI, float>();

		private bool landed;

		private float landingAt;

		private float nextSync;

		private int nextId;

		private readonly Dictionary<int, GameObject> crates = new Dictionary<int, GameObject>();

		private float serverOffset;

		private int IntactCrates => World.Crates.Count((CrateFrame c) => !c.Broken);

		private bool LootSpace => ExplorationRules.Budget(World.Loot.Count, IntactCrates);

		public bool ThrowGrenade(PlayerControllerB player, string kind, Vector3 direction)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_00a2: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: 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_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: 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_023e: 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_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			if (!Session.Host || (Object)(object)StartOfRound.Instance == (Object)null || StartOfRound.Instance.inShipPhase || StartOfRound.Instance.shipIsLeaving || !CampaignConsumables.Throwable(kind) || World.Grenades.Count