Decompiled source of PatPat v1.0.0

plugins/net.lopymine.patpat.PatPat.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;

[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("net.lopymine.patpat.PatPat")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b5c6a7e7fb40247a0f476434e9bcd705a180fa68")]
[assembly: AssemblyProduct("net.lopymine.patpat.PatPat")]
[assembly: AssemblyTitle("PatPat")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[BepInPlugin("net.lopymine.patpat", "PatPat", "1.0.0")]
public class PatPatPeakMod : BaseUnityPlugin, IOnEventCallback
{
	private readonly Harmony _harmony = new Harmony("net.lopymine.patpat");

	public static ManualLogSource ModLogger;

	public static PatPatSoundManager SoundManager;

	public static PatPatTextureManager TextureManager;

	public static PatPatManager PatPatManager;

	private IInteractible _customInteractible;

	private static readonly int[] DISALLOWED_TYPES = new int[3] { 5, 7, 1 };

	private bool _combinationPressed;

	public static float patCooldown = 0f;

	public static float lastPatTime = 0f;

	private void Awake()
	{
		ModLogger = ((BaseUnityPlugin)this).Logger;
		_harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"PatPat v1.0.0 initializing...");
		string pluginFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "assets");
		PatPatConfig.Initialize(((BaseUnityPlugin)this).Config);
		SoundManager = new PatPatSoundManager();
		SoundManager.OnInitialize(pluginFolder, this);
		TextureManager = new PatPatTextureManager();
		TextureManager.OnInitialize(pluginFolder, this);
		PatPatManager = new PatPatManager();
		PhotonNetwork.AddCallbackTarget((object)this);
	}

	private void OnDestroy()
	{
		PhotonNetwork.RemoveCallbackTarget((object)this);
	}

	private void Update()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: 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_0160: 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_016e: Expected O, but got Unknown
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		patCooldown -= Time.deltaTime;
		if (patCooldown < 0f)
		{
			patCooldown = 0f;
		}
		bool combinationPressed = _combinationPressed;
		_combinationPressed = ((int)PatPatConfig.PatFirstKeybind.Value == 0 || Input.GetKey(PatPatConfig.PatFirstKeybind.Value)) && ((int)PatPatConfig.PatSecondKeybind.Value == 0 || Input.GetKey(PatPatConfig.PatSecondKeybind.Value));
		if (combinationPressed && !_combinationPressed)
		{
			patCooldown = 0f;
		}
		if (!_combinationPressed || patCooldown != 0f)
		{
			return;
		}
		DoInteractableRaycasts(out _customInteractible);
		if (_customInteractible == null)
		{
			return;
		}
		patCooldown = PatPatConfig.PatCooldown.Value;
		lastPatTime = Time.time;
		IInteractible customInteractible = _customInteractible;
		CharacterInteractible val = (CharacterInteractible)(object)((customInteractible is CharacterInteractible) ? customInteractible : null);
		if (!((Object)(object)Character.localCharacter == (Object)null) && !((Object)(object)val == (Object)null))
		{
			Character localCharacter = Character.localCharacter;
			if (!(localCharacter.data.currentStamina <= 0f) && !((Object)(object)val.character == (Object)(object)localCharacter))
			{
				localCharacter.AddStamina(0f - PatPatConfig.StaminaExchange.Value);
				object[] array = new object[2]
				{
					((MonoBehaviourPun)val.character).photonView.ViewID,
					((MonoBehaviourPun)Character.localCharacter).photonView.ViewID
				};
				RaiseEventOptions val2 = new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)1
				};
				PhotonNetwork.RaiseEvent(PatPatConfig.PatPacketId.Value, (object)array, val2, SendOptions.SendReliable);
			}
		}
	}

	private void DoInteractableRaycasts(out IInteractible interactableResult)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: 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)
		interactableResult = null;
		Camera main = Camera.main;
		if ((Object)(object)main == (Object)null)
		{
			return;
		}
		Ray val = default(Ray);
		((Ray)(ref val))..ctor(((Component)main).transform.position, ((Component)main).transform.forward);
		RaycastHit[] array = Physics.SphereCastAll(val, PatPatConfig.PatRaycastRadius.Value, PatPatConfig.PatRaycastDistance.Value, LayerMask.op_Implicit(HelperFunctions.GetMask((LayerType)6)), (QueryTriggerInteraction)2);
		if (array == null || array.Length == 0)
		{
			return;
		}
		Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
		RaycastHit[] array2 = array;
		for (int i = 0; i < array2.Length; i++)
		{
			RaycastHit val2 = array2[i];
			if (!((Object)(object)((RaycastHit)(ref val2)).collider == (Object)null) && !IsColliderPartOfSelf(((RaycastHit)(ref val2)).collider))
			{
				IInteractible componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<IInteractible>();
				if (componentInParent != null)
				{
					interactableResult = componentInParent;
					break;
				}
			}
		}
	}

	private bool IsColliderPartOfSelf(Collider collider)
	{
		if ((Object)(object)collider == (Object)null)
		{
			return false;
		}
		return ((Component)collider).transform.IsChildOf(((Component)Character.localCharacter).transform);
	}

	public void OnEvent(EventData data)
	{
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: 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)
		if (data == null || data.Code != PatPatConfig.PatPacketId.Value || !(data.CustomData is object[]))
		{
			return;
		}
		object[] array = (object[])data.CustomData;
		PatPatManager.PatPlayer((int)array[0]);
		if ((int)array[0] != ((MonoBehaviourPun)Character.localCharacter).photonView.ViewID)
		{
			return;
		}
		Character.localCharacter.AddStamina(PatPatConfig.StaminaExchange.Value);
		string characterName = ((Component)PhotonNetwork.GetPhotonView((int)array[1])).GetComponent<Character>().characterName;
		if (Random.Range(0, 300) != 1)
		{
			return;
		}
		CharacterAfflictions afflictions = Character.localCharacter.refs.afflictions;
		List<int> list = (from x in afflictions.currentStatuses.Select((float value, int index) => new { value, index })
			where x.value > 0f && !Extensions.Contains(DISALLOWED_TYPES, x.index)
			select x.index).ToList();
		float value2 = PatPatConfig.PatMoralBoost.Value;
		if (list.Count == 0)
		{
			if (Character.localCharacter.data.currentStamina == Character.localCharacter.GetMaxStamina())
			{
				return;
			}
			Character.localCharacter.AddStamina(value2 * 1.5f);
		}
		else
		{
			Array values = Enum.GetValues(typeof(STATUSTYPE));
			STATUSTYPE val = (STATUSTYPE)values.GetValue(list[Random.Range(0, list.Count - 1)]);
			afflictions.AdjustStatus(val, 0f - value2, false);
		}
		StaminaBar bar = GUIManager.instance.bar;
		((Behaviour)bar.moraleBoostText).enabled = true;
		((TMP_Text)bar.moraleBoostText).text = "Moral boost from " + characterName + "!";
		StartMoraleBoost((MonoBehaviour)(object)bar);
	}

	public static Coroutine StartMoraleBoost(MonoBehaviour instance)
	{
		MethodInfo methodInfo = AccessTools.Method(((object)instance).GetType(), "MoraleBoostRoutine", (Type[])null, (Type[])null);
		if (methodInfo == null)
		{
			throw new MissingMethodException("MoraleBoostRoutine not found");
		}
		IEnumerator enumerator = (IEnumerator)methodInfo.Invoke(instance, null);
		return instance.StartCoroutine(enumerator);
	}
}
public class PatPatAnimation : MonoBehaviour
{
	private const float BillboardHeightOffset = 1f;

	private Mesh? _quadMesh;

	private Material? _billboardMaterial;

	private Texture2D[]? _frames;

	private float _scale = 0.65f;

	private Vector3 _anchorPosition;

	private readonly float Duration = 0.35f;

	private float _duration;

	public Character character;

	public PatPatModelManager.PatPatModel model;

	public static PatPatAnimation? Create(Character character, PatPatModelManager.PatPatModel model, Texture2D[] frames)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Expected O, but got Unknown
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		if (frames == null || frames.Length == 0)
		{
			return null;
		}
		GameObject val = new GameObject("PatPatAnimation");
		PatPatAnimation patPatAnimation = val.AddComponent<PatPatAnimation>();
		patPatAnimation._anchorPosition = character.Center + Vector3.up * 1f;
		patPatAnimation._frames = frames;
		patPatAnimation._scale = 0.65f;
		patPatAnimation.character = character;
		patPatAnimation.model = model;
		patPatAnimation.Initialize();
		return patPatAnimation;
	}

	private void Initialize()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: 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_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_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: 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_00f7: 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_018d: Expected O, but got Unknown
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: 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_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: 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_0238: Unknown result type (might be due to invalid IL or missing references)
		_quadMesh = new Mesh();
		((Object)_quadMesh).name = "PatPat_Texture_Quad";
		_quadMesh.vertices = (Vector3[])(object)new Vector3[4]
		{
			new Vector3(-0.5f, -0.5f, 0f),
			new Vector3(0.5f, -0.5f, 0f),
			new Vector3(-0.5f, 0.5f, 0f),
			new Vector3(0.5f, 0.5f, 0f)
		};
		_quadMesh.uv = (Vector2[])(object)new Vector2[4]
		{
			new Vector2(0f, 0f),
			new Vector2(1f, 0f),
			new Vector2(0f, 1f),
			new Vector2(1f, 1f)
		};
		_quadMesh.triangles = new int[6] { 0, 2, 1, 2, 3, 1 };
		_quadMesh.RecalculateNormals();
		MeshFilter val = ((Component)this).gameObject.AddComponent<MeshFilter>();
		MeshRenderer val2 = ((Component)this).gameObject.AddComponent<MeshRenderer>();
		val.mesh = _quadMesh;
		Shader val3 = Shader.Find("Unlit/Texture") ?? Shader.Find("Sprites/Default") ?? Shader.Find("Standard");
		_billboardMaterial = new Material(val3 ?? Shader.Find("Standard"));
		ApplyMaterialAlphaSettings(_billboardMaterial);
		_billboardMaterial.mainTexture = (Texture)(object)_frames[0];
		((Renderer)val2).material = _billboardMaterial;
		((Component)this).transform.position = _anchorPosition;
		((Component)this).transform.localScale = new Vector3(0f - _scale, _scale, 1f);
		Camera main = Camera.main;
		if ((Object)(object)main != (Object)null)
		{
			Vector3 val4 = ((Component)main).transform.position - ((Component)this).transform.position;
			if (((Vector3)(ref val4)).sqrMagnitude > 1E-05f)
			{
				((Component)this).transform.rotation = Quaternion.LookRotation(val4, ((Component)main).transform.up);
			}
		}
	}

	public void Reset()
	{
		_duration = 0f;
		UpdatePanelFrame(0f);
	}

	private void Update()
	{
		//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_0057: 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_006d: 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_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: 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)
		if (_duration == Duration)
		{
			OnDestroy();
			return;
		}
		_duration += Time.deltaTime;
		if (_duration >= Duration)
		{
			_duration = Duration;
		}
		_anchorPosition = character.Center + Vector3.up * 1f;
		((Component)this).transform.position = _anchorPosition;
		Camera main = Camera.main;
		if ((Object)(object)main != (Object)null)
		{
			Vector3 val = ((Component)main).transform.position - ((Component)this).transform.position;
			if (((Vector3)(ref val)).sqrMagnitude > 1E-05f)
			{
				((Component)this).transform.rotation = Quaternion.LookRotation(val, ((Component)main).transform.up);
			}
		}
		((Component)this).transform.localScale = new Vector3(0f - _scale, _scale, 1f);
		float num = _duration / Duration;
		UpdatePanelFrame(num);
		if ((Object)(object)model != (Object)null)
		{
			model.UpdateScale(num, character);
		}
	}

	private void UpdatePanelFrame(float animationProgress)
	{
		if (!((Object)(object)_billboardMaterial == (Object)null) && _frames != null)
		{
			int num = Mathf.Clamp(Mathf.FloorToInt(animationProgress * (float)_frames.Length), 0, _frames.Length - 1);
			PatPatPeakMod.ModLogger.LogInfo((object)num);
			Texture2D val = _frames[num];
			if ((Object)(object)val != (Object)null)
			{
				_billboardMaterial.mainTexture = (Texture)(object)val;
			}
		}
	}

	private void ApplyMaterialAlphaSettings(Material mat)
	{
		if (!((Object)(object)mat == (Object)null))
		{
			mat.SetInt("_SrcBlend", 5);
			mat.SetInt("_DstBlend", 10);
			mat.SetInt("_ZWrite", 0);
			mat.DisableKeyword("_ALPHATEST_ON");
			mat.EnableKeyword("_ALPHABLEND_ON");
			mat.renderQueue = 3000;
		}
	}

	private void OnDestroy()
	{
		PatPatPeakMod.PatPatManager.RemoveExpired(((MonoBehaviourPun)character).photonView.ViewID);
		if ((Object)(object)_billboardMaterial != (Object)null)
		{
			Object.Destroy((Object)(object)_billboardMaterial);
		}
		if ((Object)(object)_quadMesh != (Object)null)
		{
			Object.Destroy((Object)(object)_quadMesh);
		}
		Object.Destroy((Object)(object)((Component)this).gameObject);
	}
}
public class PatPatConfig
{
	public static ConfigEntry<byte> PatPacketId;

	public static ConfigEntry<float> PatCooldown;

	public static ConfigEntry<float> StaminaExchange;

	public static ConfigEntry<float> PatMoralBoost;

	public static ConfigEntry<float> PatRaycastDistance;

	public static ConfigEntry<float> PatRaycastRadius;

	public static ConfigEntry<float> PatStaminaCooldown;

	public static ConfigEntry<float> PatWeight;

	public static ConfigEntry<float> PatSoundVolume;

	public static ConfigEntry<KeyCode> PatFirstKeybind;

	public static ConfigEntry<KeyCode> PatSecondKeybind;

	public static void Initialize(ConfigFile config)
	{
		PatPacketId = config.Bind<byte>("PatPat", "PacketID", (byte)139, "Packet ID used for PatPat networking");
		PatCooldown = config.Bind<float>("PatPat", "Cooldown", 0.2f, "Cooldown between pat actions");
		StaminaExchange = config.Bind<float>("PatPat", "StaminaExchange", 0.02f, "Amount of stamina exchanged per pat");
		PatMoralBoost = config.Bind<float>("PatPat", "MoralBoost", 0.2f, "Morale boost gained from patting");
		PatRaycastDistance = config.Bind<float>("PatPat", "PatDistance", 10f, "Maximum distance for patting targets");
		PatRaycastRadius = config.Bind<float>("PatPat", "RaycastSphereRadius", 0.3f, "Raycast sphere radius for pat detection");
		PatStaminaCooldown = config.Bind<float>("PatPat", "StaminaCooldown", 0.5f, "Cooldown before stamina regeneration after pat");
		PatWeight = config.Bind<float>("PatPat", "PatWeight", 0.425f, "The pat weight");
		PatSoundVolume = config.Bind<float>("PatPat", "PatSoundVolume", 0.25f, "The volume of pat sound");
		PatFirstKeybind = config.Bind<KeyCode>("PatPat", "Pat1Keybind", (KeyCode)304, "First keybind for pat action");
		PatSecondKeybind = config.Bind<KeyCode>("PatPat", "Pat2Keybind", (KeyCode)324, "Second keybind for pat action");
	}
}
public class PatPatManager
{
	private class PatPatCharacterData
	{
		public PatPatAnimation? animation;

		public PatPatModelManager.PatPatModel? model;

		public GameObject? soundGameObject;
	}

	private readonly Dictionary<int, PatPatCharacterData> data = new Dictionary<int, PatPatCharacterData>();

	public void PatPlayer(int pattedCharacterId)
	{
		GameObject soundGameObject;
		if (data.ContainsKey(pattedCharacterId))
		{
			PatPatCharacterData patPatCharacterData = data[pattedCharacterId];
			patPatCharacterData.animation?.Reset();
			patPatCharacterData.model?.Reset();
			soundGameObject = patPatCharacterData.soundGameObject;
		}
		else
		{
			Character component = ((Component)PhotonNetwork.GetPhotonView(pattedCharacterId)).GetComponent<Character>();
			PatPatModelManager.PatPatModel patPatModel = PatPatModelManager.CreatePattableModelIfDoesntExists(((Component)component).gameObject);
			if ((Object)(object)patPatModel == (Object)null)
			{
				return;
			}
			PatPatAnimation patPatAnimation = PatPatAnimation.Create(component, patPatModel, PatPatPeakMod.TextureManager.frames);
			if ((Object)(object)patPatAnimation == (Object)null)
			{
				return;
			}
			PatPatCharacterData patPatCharacterData2 = new PatPatCharacterData();
			patPatCharacterData2.animation = patPatAnimation;
			patPatCharacterData2.model = patPatModel;
			patPatCharacterData2.soundGameObject = ((Component)((Component)component).transform.Find("Scout").Find("Armature").Find("Hip")).gameObject;
			data[pattedCharacterId] = patPatCharacterData2;
			soundGameObject = patPatCharacterData2.soundGameObject;
		}
		if (!((Object)(object)soundGameObject == (Object)null))
		{
			PatPatPeakMod.SoundManager.PlayRandomPatSoundForObject(soundGameObject);
		}
	}

	public void RemoveExpired(int characterId)
	{
		if (data.ContainsKey(characterId))
		{
			data.Remove(characterId);
		}
	}
}
public static class PatPatModelManager
{
	public class PatPatModel : MonoBehaviour
	{
		[Serializable]
		public class SkinnedMeshRendererBind
		{
			public SkinnedMeshRenderer? renderer;

			public Transform[]? origBones;

			public Transform[]? duplicationBones;

			public Transform? originalRoot;

			public Transform? duplicationRoot;
		}

		[Serializable]
		public class MeshRendererBind
		{
			public MeshRenderer? originalRenderer;

			public Transform? originalTransform;

			public MeshRenderer? duplicationRenderer;

			public Transform? duplicationTransform;
		}

		private float currentYScale = 1f;

		private Vector3 currentPivot = Vector3.zero;

		internal bool IsCreated { get; private set; }

		internal Transform? VisualRoot { get; private set; }

		internal Dictionary<Transform, Transform>? OriginalToDuplication { get; private set; }

		internal List<SkinnedMeshRendererBind>? SkinnedMeshBinds { get; private set; }

		internal List<MeshRendererBind>? MeshBinds { get; private set; }

		internal HashSet<Transform>? BoneSet { get; private set; }

		internal Transform? HeadVisualGroupDuplicationRoot { get; private set; }

		public Transform? GetVisualRoot()
		{
			return VisualRoot;
		}

		internal void Setup(Transform visualRoot, Dictionary<Transform, Transform> map, List<SkinnedMeshRendererBind> skinnedMeshBinds, List<MeshRendererBind> meshBinds, HashSet<Transform> boneSet)
		{
			VisualRoot = visualRoot;
			OriginalToDuplication = map;
			SkinnedMeshBinds = skinnedMeshBinds;
			MeshBinds = meshBinds;
			IsCreated = true;
			BoneSet = boneSet;
			HeadVisualGroupDuplicationRoot = visualRoot.Find("Hip_visual/Mid_visual/AimJoint_visual/Torso_visual/Head_visual");
		}

		public void UpdateScale(float progress, Character character)
		{
			SetScale(GetAnimationValue(progress), character);
		}

		public static float GetAnimationValue(float progress)
		{
			progress = Clamp01(progress);
			float num = 1f - MathF.Pow(1f - progress, 2f);
			float num2 = PatPatConfig.PatWeight.Value / 1.5f;
			return 1f - num2 + num2 * (1f - MathF.Sin(num * MathF.PI));
		}

		private static float Clamp01(float value)
		{
			if (value < 0f)
			{
				return 0f;
			}
			if (value > 1f)
			{
				return 1f;
			}
			return value;
		}

		private void SetScale(float scale, Character character)
		{
			//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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			currentYScale = Mathf.Clamp(scale, 0.0001f, 10f);
			if (character.data.isGrounded)
			{
				currentPivot = character.data.groundPos;
			}
			else
			{
				currentPivot = ((Component)character.refs.ragdoll.partDict[(BodypartType)0]).transform.position;
			}
		}

		public void Reset()
		{
			//IL_000c: 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)
			currentYScale = 1f;
			currentPivot = Vector3.zero;
		}

		private void LateUpdate()
		{
			//IL_0141: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: 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)
			//IL_025a: 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_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: 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_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: 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_0227: 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_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: 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_01e9: 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_0206: Unknown result type (might be due to invalid IL or missing references)
			if (!IsCreated || OriginalToDuplication == null)
			{
				return;
			}
			if (MeshBinds != null)
			{
				foreach (MeshRendererBind meshBind in MeshBinds)
				{
					SyncBind(meshBind);
				}
			}
			HashSet<Transform> hashSet = new HashSet<Transform>();
			foreach (Transform value2 in OriginalToDuplication.Values)
			{
				if ((Object)(object)value2 != (Object)null)
				{
					hashSet.Add(value2);
				}
			}
			Transform headVisualGroupDuplicationRoot = HeadVisualGroupDuplicationRoot;
			foreach (KeyValuePair<Transform, Transform> item in OriginalToDuplication)
			{
				Transform key = item.Key;
				Transform value = item.Value;
				if ((Object)(object)key == (Object)null || (Object)(object)value == (Object)null)
				{
					continue;
				}
				bool flag = (Object)(object)value.parent != (Object)null && hashSet.Contains(value.parent);
				bool flag2 = (Object)(object)headVisualGroupDuplicationRoot != (Object)null && ((Object)(object)value == (Object)(object)headVisualGroupDuplicationRoot || value.IsChildOf(headVisualGroupDuplicationRoot));
				if (currentYScale == 1f)
				{
					value.position = key.position;
					value.rotation = key.rotation;
					value.localScale = key.localScale;
				}
				else if (flag2)
				{
					if ((Object)(object)value == (Object)(object)headVisualGroupDuplicationRoot)
					{
						Vector3 val = key.position - currentPivot;
						((Vector3)(ref val))..ctor(val.x, val.y * currentYScale, val.z);
						value.position = currentPivot + val;
						value.rotation = key.rotation;
						value.localScale = new Vector3(key.localScale.x, key.localScale.y * currentYScale, key.localScale.z);
					}
					else
					{
						value.localPosition = key.localPosition;
						value.localRotation = key.localRotation;
						value.localScale = key.localScale;
					}
				}
				else
				{
					Vector3 val2 = key.position - currentPivot;
					((Vector3)(ref val2))..ctor(val2.x, val2.y * currentYScale, val2.z);
					value.position = currentPivot + val2;
					value.rotation = key.rotation;
					if (!flag)
					{
						value.localScale = new Vector3(key.localScale.x, key.localScale.y * currentYScale, key.localScale.z);
					}
					else
					{
						value.localScale = key.localScale;
					}
				}
			}
		}

		private void SyncBind(MeshRendererBind bind)
		{
			MeshRendererBind bind2 = bind;
			if (bind2 == null || (Object)(object)bind2.originalRenderer == (Object)null || (Object)(object)bind2.duplicationRenderer == (Object)null)
			{
				return;
			}
			GameObject gameObject = ((Component)bind2.originalRenderer).gameObject;
			GameObject duplication = ((Component)bind2.duplicationRenderer).gameObject;
			if (!((Object)(object)gameObject == (Object)null) && !((Object)(object)duplication == (Object)null))
			{
				bool activeInHierarchy = gameObject.activeInHierarchy;
				bool activeSelf = duplication.activeSelf;
				if (!activeInHierarchy)
				{
					SetDuplicationVisible(value: false);
					SetOriginalVisible(value: true);
				}
				else
				{
					SetDuplicationVisible(value: true);
					SetOriginalVisible(value: false);
				}
			}
			void SetDuplicationVisible(bool value)
			{
				duplication.SetActive(value);
			}
			void SetOriginalVisible(bool value)
			{
				((Renderer)bind2.originalRenderer).forceRenderingOff = !value;
			}
		}
	}

	public static PatPatModel? CreatePattableModelIfDoesntExists(GameObject characterRoot)
	{
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Expected O, but got Unknown
		//IL_01cb: 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_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0479: Unknown result type (might be due to invalid IL or missing references)
		//IL_0480: Expected O, but got Unknown
		//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0504: Unknown result type (might be due to invalid IL or missing references)
		//IL_051c: 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_0572: Unknown result type (might be due to invalid IL or missing references)
		//IL_058a: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a2: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)characterRoot == (Object)null)
		{
			return null;
		}
		PatPatModel patPatModel = characterRoot.GetComponent<PatPatModel>();
		if ((Object)(object)patPatModel != (Object)null && patPatModel.IsCreated)
		{
			return patPatModel;
		}
		Transform val = characterRoot.transform.Find("Scout");
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		List<SkinnedMeshRenderer> list = new List<SkinnedMeshRenderer>(((Component)val).GetComponentsInChildren<SkinnedMeshRenderer>(true));
		List<MeshRenderer> list2 = new List<MeshRenderer>(((Component)val).GetComponentsInChildren<MeshRenderer>(true));
		if (list.Count == 0 && list2.Count == 0)
		{
			list.AddRange(characterRoot.GetComponentsInChildren<SkinnedMeshRenderer>(true));
			list2.AddRange(characterRoot.GetComponentsInChildren<MeshRenderer>(true));
			if (list.Count == 0)
			{
				return null;
			}
		}
		HashSet<Transform> hashSet = new HashSet<Transform>();
		foreach (SkinnedMeshRenderer item in list)
		{
			if ((Object)(object)item == (Object)null)
			{
				continue;
			}
			if (item.bones != null)
			{
				Transform[] bones = item.bones;
				foreach (Transform val2 in bones)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						hashSet.Add(val2);
					}
				}
			}
			if ((Object)(object)item.rootBone != (Object)null)
			{
				hashSet.Add(item.rootBone);
			}
		}
		if (hashSet.Count == 0)
		{
			return null;
		}
		HashSet<Transform> hashSet2 = new HashSet<Transform>(hashSet);
		if ((Object)(object)patPatModel == (Object)null)
		{
			patPatModel = characterRoot.AddComponent<PatPatModel>();
		}
		Transform transform = new GameObject("SeparatedVisualModel").transform;
		transform.SetParent(val.parent, false);
		transform.localScale = val.localScale;
		Dictionary<Transform, Transform> dictionary = new Dictionary<Transform, Transform>(hashSet.Count);
		foreach (Transform item2 in hashSet)
		{
			if (!((Object)(object)item2 == (Object)null))
			{
				GameObject val3 = new GameObject(((Object)item2).name + "_visual");
				Transform transform2 = val3.transform;
				transform2.position = item2.position;
				transform2.rotation = item2.rotation;
				transform2.localScale = item2.localScale;
				dictionary[item2] = transform2;
			}
		}
		foreach (KeyValuePair<Transform, Transform> item3 in dictionary)
		{
			Transform key = item3.Key;
			Transform value2 = item3.Value;
			if ((Object)(object)key.parent != (Object)null && dictionary.ContainsKey(key.parent))
			{
				value2.SetParent(dictionary[key.parent], true);
			}
			else
			{
				value2.SetParent(transform, true);
			}
		}
		List<PatPatModel.SkinnedMeshRendererBind> list3 = new List<PatPatModel.SkinnedMeshRendererBind>(list.Count);
		foreach (SkinnedMeshRenderer item4 in list)
		{
			if ((Object)(object)item4 == (Object)null)
			{
				continue;
			}
			PatPatModel.SkinnedMeshRendererBind skinnedMeshRendererBind = new PatPatModel.SkinnedMeshRendererBind();
			skinnedMeshRendererBind.renderer = item4;
			Transform[] array = item4.bones ?? Array.Empty<Transform>();
			skinnedMeshRendererBind.origBones = (Transform[]?)(object)new Transform[array.Length];
			skinnedMeshRendererBind.duplicationBones = (Transform[]?)(object)new Transform[array.Length];
			for (int j = 0; j < array.Length; j++)
			{
				skinnedMeshRendererBind.origBones[j] = array[j];
				if ((Object)(object)array[j] != (Object)null && dictionary.ContainsKey(array[j]))
				{
					skinnedMeshRendererBind.duplicationBones[j] = dictionary[array[j]];
				}
				else
				{
					skinnedMeshRendererBind.duplicationBones[j] = null;
				}
			}
			skinnedMeshRendererBind.originalRoot = item4.rootBone;
			skinnedMeshRendererBind.duplicationRoot = (((Object)(object)item4.rootBone != (Object)null && dictionary.ContainsKey(item4.rootBone)) ? dictionary[item4.rootBone] : null);
			item4.bones = skinnedMeshRendererBind.duplicationBones;
			if ((Object)(object)skinnedMeshRendererBind.duplicationRoot != (Object)null)
			{
				item4.rootBone = skinnedMeshRendererBind.duplicationRoot;
			}
			list3.Add(skinnedMeshRendererBind);
		}
		List<PatPatModel.MeshRendererBind> list4 = new List<PatPatModel.MeshRendererBind>(list2.Count);
		foreach (MeshRenderer item5 in list2)
		{
			MeshRenderer renderer = item5;
			if ((Object)(object)renderer == (Object)null)
			{
				continue;
			}
			MeshFilter component = ((Component)renderer).GetComponent<MeshFilter>();
			MeshRenderer duplicationRenderer;
			if (!((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMesh == (Object)null))
			{
				GameObject val4 = new GameObject(((Object)((Component)component).gameObject).name + "_visual");
				Transform transform3 = val4.transform;
				MeshFilter val5 = val4.AddComponent<MeshFilter>();
				val5.sharedMesh = component.sharedMesh;
				duplicationRenderer = val4.AddComponent<MeshRenderer>();
				((Renderer)duplicationRenderer).sharedMaterials = ((Renderer)renderer).sharedMaterials;
				((Renderer)duplicationRenderer).shadowCastingMode = ((Renderer)renderer).shadowCastingMode;
				((Renderer)duplicationRenderer).receiveShadows = ((Renderer)renderer).receiveShadows;
				((Renderer)duplicationRenderer).lightProbeUsage = ((Renderer)renderer).lightProbeUsage;
				((Renderer)duplicationRenderer).reflectionProbeUsage = ((Renderer)renderer).reflectionProbeUsage;
				((Renderer)duplicationRenderer).motionVectorGenerationMode = ((Renderer)renderer).motionVectorGenerationMode;
				Transform orCreateVisualParent = GetOrCreateVisualParent(((Component)renderer).transform.parent, transform, dictionary);
				transform3.SetParent(orCreateVisualParent, false);
				transform3.localPosition = ((Component)renderer).transform.localPosition;
				transform3.localRotation = ((Component)renderer).transform.localRotation;
				transform3.localScale = ((Component)renderer).transform.localScale;
				bool activeInHierarchy = ((Component)renderer).gameObject.activeInHierarchy;
				bool activeSelf = ((Component)duplicationRenderer).gameObject.activeSelf;
				if (!activeInHierarchy)
				{
					SetDuplicationVisible(value: false);
					SetOriginalVisible(value: true);
				}
				else
				{
					SetDuplicationVisible(value: true);
					SetOriginalVisible(value: false);
				}
				PatPatModel.MeshRendererBind meshRendererBind = new PatPatModel.MeshRendererBind();
				meshRendererBind.originalRenderer = renderer;
				meshRendererBind.originalTransform = ((Component)renderer).transform;
				meshRendererBind.duplicationRenderer = duplicationRenderer;
				meshRendererBind.duplicationTransform = transform3;
				list4.Add(meshRendererBind);
				if (!hashSet2.Contains(((Component)renderer).transform))
				{
					dictionary[((Component)renderer).transform] = transform3;
				}
			}
			void SetDuplicationVisible(bool value)
			{
				((Component)duplicationRenderer).gameObject.SetActive(value);
			}
			void SetOriginalVisible(bool value)
			{
				((Renderer)renderer).forceRenderingOff = !value;
			}
		}
		patPatModel.Setup(transform, dictionary, list3, list4, hashSet2);
		return patPatModel;
	}

	private static Transform GetOrCreateVisualParent(Transform original, Transform visualRoot, Dictionary<Transform, Transform> map)
	{
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Expected O, but got Unknown
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		if (map.TryGetValue(original, out Transform value))
		{
			return value;
		}
		if ((Object)(object)original.parent == (Object)null || ((Object)original).name == "Scout")
		{
			return visualRoot;
		}
		Transform orCreateVisualParent = GetOrCreateVisualParent(original.parent, visualRoot, map);
		GameObject val = new GameObject(((Object)original).name + "_visual");
		Transform transform = val.transform;
		transform.SetParent(orCreateVisualParent, false);
		transform.localPosition = original.localPosition;
		transform.localRotation = original.localRotation;
		transform.localScale = original.localScale;
		map[original] = transform;
		return transform;
	}
}
public class PatPatSoundManager
{
	[CompilerGenerated]
	private sealed class <LoadAudioClipsCoroutine>d__3 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public PatPatSoundManager <>4__this;

		public string folder;

		private int <i>5__2;

		private UnityWebRequest <uwr>5__3;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if (num == -3 || num == 1)
			{
				try
				{
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<uwr>5__3 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Invalid comparison between Unknown and I4
			try
			{
				int num = <>1__state;
				PatPatSoundManager patPatSoundManager = <>4__this;
				if (num != 0)
				{
					if (num != 1)
					{
						return false;
					}
					<>1__state = -3;
					if ((int)<uwr>5__3.result != 1)
					{
						PatPatPeakMod.ModLogger.LogWarning((object)("Audio load failed: " + <uwr>5__3.error));
						<>m__Finally1();
					}
					else
					{
						AudioClip content = DownloadHandlerAudioClip.GetContent(<uwr>5__3);
						if ((Object)(object)content != (Object)null)
						{
							patPatSoundManager._sounds[<i>5__2] = content;
						}
						<>m__Finally1();
						<uwr>5__3 = null;
					}
					goto IL_013d;
				}
				<>1__state = -1;
				patPatSoundManager._sounds = (AudioClip[])(object)new AudioClip[3];
				<i>5__2 = 0;
				goto IL_014f;
				IL_013d:
				<i>5__2++;
				goto IL_014f;
				IL_014f:
				if (<i>5__2 < 3)
				{
					string text = Path.Combine(folder, "pat" + <i>5__2 + ".ogg");
					if (!File.Exists(text))
					{
						PatPatPeakMod.ModLogger.LogWarning((object)("Audio file not found: " + text));
						goto IL_013d;
					}
					string text2 = "file://" + text;
					<uwr>5__3 = UnityWebRequestMultimedia.GetAudioClip(text2, (AudioType)14);
					<>1__state = -3;
					<>2__current = <uwr>5__3.SendWebRequest();
					<>1__state = 1;
					return true;
				}
				patPatSoundManager.audioLoadCoroutine = null;
				return false;
			}
			catch
			{
				//try-fault
				((IDisposable)this).Dispose();
				throw;
			}
		}

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

		private void <>m__Finally1()
		{
			<>1__state = -1;
			if (<uwr>5__3 != null)
			{
				((IDisposable)<uwr>5__3).Dispose();
			}
		}

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

	private AudioClip[] _sounds = (AudioClip[])(object)new AudioClip[3];

	private Coroutine? audioLoadCoroutine;

	public void OnInitialize(string pluginFolder, PatPatPeakMod patpat)
	{
		audioLoadCoroutine = ((MonoBehaviour)patpat).StartCoroutine(LoadAudioClipsCoroutine(Path.Combine(pluginFolder, "sounds")));
	}

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

	public void PlayRandomPatSoundForObject(GameObject gameObject)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Invalid comparison between Unknown and I4
		if (_sounds == null || _sounds.Length == 0)
		{
			return;
		}
		int num = Random.Range(0, _sounds.Length);
		AudioClip val = _sounds[num];
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		if ((int)val.loadState != 2)
		{
			PatPatPeakMod.ModLogger.LogWarning((object)"Clip not loaded!");
			return;
		}
		AudioSource val2 = gameObject.GetComponent<AudioSource>();
		if ((Object)(object)val2 == (Object)null)
		{
			val2 = gameObject.AddComponent<AudioSource>();
		}
		val2.playOnAwake = false;
		val2.loop = false;
		val2.spatialBlend = 1f;
		val2.rolloffMode = (AudioRolloffMode)0;
		val2.minDistance = 5f;
		val2.maxDistance = 20f;
		val2.volume = Math.Clamp(PatPatConfig.PatSoundVolume.Value, 0f, 1f);
		val2.PlayOneShot(val);
	}
}
public class PatPatTextureManager
{
	[CompilerGenerated]
	private sealed class <LoadFrameTexturesCoroutine>d__3 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public PatPatTextureManager <>4__this;

		public string folder;

		private int <i>5__2;

		private UnityWebRequest <uwr>5__3;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if (num == -3 || num == 1)
			{
				try
				{
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<uwr>5__3 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Invalid comparison between Unknown and I4
			try
			{
				int num = <>1__state;
				PatPatTextureManager patPatTextureManager = <>4__this;
				if (num != 0)
				{
					if (num != 1)
					{
						return false;
					}
					<>1__state = -3;
					if ((int)<uwr>5__3.result != 1)
					{
						PatPatPeakMod.ModLogger.LogWarning((object)("Frame load failed: " + <uwr>5__3.error));
						patPatTextureManager.frames[<i>5__2] = null;
						<>m__Finally1();
					}
					else
					{
						Texture2D content = DownloadHandlerTexture.GetContent(<uwr>5__3);
						patPatTextureManager.frames[<i>5__2] = content;
						<>m__Finally1();
						<uwr>5__3 = null;
					}
					goto IL_014d;
				}
				<>1__state = -1;
				patPatTextureManager.frames = (Texture2D[])(object)new Texture2D[5];
				<i>5__2 = 0;
				goto IL_015f;
				IL_015f:
				if (<i>5__2 < 5)
				{
					string text = Path.Combine(folder, "frame" + <i>5__2 + ".png");
					if (!File.Exists(text))
					{
						PatPatPeakMod.ModLogger.LogWarning((object)("Frame image not found: " + text));
						patPatTextureManager.frames[<i>5__2] = null;
						goto IL_014d;
					}
					string text2 = "file://" + text;
					<uwr>5__3 = UnityWebRequestTexture.GetTexture(text2);
					<>1__state = -3;
					<>2__current = <uwr>5__3.SendWebRequest();
					<>1__state = 1;
					return true;
				}
				patPatTextureManager.framesLoadCoroutine = null;
				return false;
				IL_014d:
				<i>5__2++;
				goto IL_015f;
			}
			catch
			{
				//try-fault
				((IDisposable)this).Dispose();
				throw;
			}
		}

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

		private void <>m__Finally1()
		{
			<>1__state = -1;
			if (<uwr>5__3 != null)
			{
				((IDisposable)<uwr>5__3).Dispose();
			}
		}

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

	public Texture2D[] frames = (Texture2D[])(object)new Texture2D[5];

	private Coroutine? framesLoadCoroutine;

	public void OnInitialize(string pluginFolder, PatPatPeakMod patpat)
	{
		framesLoadCoroutine = ((MonoBehaviour)patpat).StartCoroutine(LoadFrameTexturesCoroutine(Path.Combine(pluginFolder, "frames")));
	}

	[IteratorStateMachine(typeof(<LoadFrameTexturesCoroutine>d__3))]
	private IEnumerator LoadFrameTexturesCoroutine(string folder)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <LoadFrameTexturesCoroutine>d__3(0)
		{
			<>4__this = this,
			folder = folder
		};
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace PatPat.Patches
{
	[HarmonyPatch(typeof(Character))]
	internal class PatPatCharacterPatch
	{
		[HarmonyPatch("CanRegenStamina")]
		[HarmonyPrefix]
		private static bool NoRegenAfterPat(ref bool __result)
		{
			if (Time.time - PatPatPeakMod.lastPatTime < PatPatConfig.PatCooldown.Value)
			{
				__result = false;
				return false;
			}
			return true;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}