Decompiled source of OrangeCatCompanion v1.0.0

MyRepoMod.dll

Decompiled 2 hours 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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Windows.Speech;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MyRepoMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Мой мод для R.E.P.O.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MyRepoMod")]
[assembly: AssemblyTitle("MyRepoMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MyRepoMod
{
	[BepInPlugin("MyRepoMod", "MyRepoMod", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		internal static Plugin Instance;

		internal static AudioClip HardstyleClip;

		private static bool _audioLoadStarted;

		private static GameObject _persistentVoiceHost;

		private readonly Harmony _harmony = new Harmony("MyRepoMod");

		private void Awake()
		{
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			_harmony.PatchAll();
			CatAggroManager.ApplyNavigationPatches(_harmony);
			OrangeCatShopPatch.ApplyPhotonPoolPatch(_harmony);
			StartAudioLoadIfNeeded();
			EnsurePersistentVoiceListener();
		}

		internal static void EnsurePersistentVoiceListener()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			if (!((Object)(object)_persistentVoiceHost != (Object)null))
			{
				_persistentVoiceHost = new GameObject("MyRepoMod_PersistentVoiceListener");
				Object.DontDestroyOnLoad((Object)(object)_persistentVoiceHost);
				_persistentVoiceHost.AddComponent<CatVoiceListener>();
			}
		}

		internal static void StartAudioLoadIfNeeded()
		{
			if (!_audioLoadStarted && !((Object)(object)HardstyleClip != (Object)null) && !((Object)(object)Instance == (Object)null))
			{
				_audioLoadStarted = true;
				((MonoBehaviour)Instance).StartCoroutine(LoadHardstyleTrackCoroutine());
			}
		}

		private static string FindMp3Path()
		{
			string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty;
			string text = Paths.BepInExRootPath ?? string.Empty;
			string path2 = (string.IsNullOrEmpty(text) ? string.Empty : (Directory.GetParent(text)?.FullName ?? string.Empty));
			string path3 = Paths.GameRootPath ?? string.Empty;
			string[] array = new string[4]
			{
				Path.Combine(path3, "HardstyleKiller.mp3"),
				Path.Combine(path2, "HardstyleKiller.mp3"),
				Path.Combine(text, "HardstyleKiller.mp3"),
				Path.Combine(path, "HardstyleKiller.mp3")
			};
			string[] array2 = array;
			foreach (string text2 in array2)
			{
				if (!string.IsNullOrEmpty(text2) && File.Exists(text2))
				{
					return text2;
				}
			}
			return null;
		}

		private static IEnumerator LoadHardstyleTrackCoroutine()
		{
			string mp3Path = FindMp3Path();
			if (string.IsNullOrEmpty(mp3Path))
			{
				yield break;
			}
			string uri = new Uri(mp3Path).AbsoluteUri;
			UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(uri, (AudioType)13);
			try
			{
				yield return request.SendWebRequest();
				if ((int)request.result != 1)
				{
					Logger.LogError((object)("Ошибка загрузки HardstyleKiller.mp3 (" + mp3Path + "): " + request.error));
					yield break;
				}
				AudioClip clip = DownloadHandlerAudioClip.GetContent(request);
				if (!((Object)(object)clip != (Object)null))
				{
					yield break;
				}
				((Object)clip).name = "HardstyleKiller";
				HardstyleClip = clip;
				foreach (CatPoseController cat in CatPoseController.ActiveCats)
				{
					if ((Object)(object)cat != (Object)null)
					{
						cat.AttachBattleClip(clip);
					}
				}
			}
			finally
			{
				((IDisposable)request)?.Dispose();
			}
		}

		private void Update()
		{
			if (!Input.GetKeyDown((KeyCode)120))
			{
				return;
			}
			foreach (CatPoseController activeCat in CatPoseController.ActiveCats)
			{
				if ((Object)(object)activeCat != (Object)null)
				{
					activeCat.ForceAttackNearestValuableForTest();
				}
			}
		}
	}
	public class CatVoiceListener : MonoBehaviour
	{
		private KeywordRecognizer _recognizer;

		private float _nextHealthCheckTime;

		private readonly string[] _shooWords = new string[7] { "брысь", "кыш", "фу", "пошёл вон", "уйди", "shoo", "scat" };

		private bool _forceDirectMic;

		private int _selectedMicIndex;

		private string _activeMicName;

		private AudioClip _micClip;

		private int _lastMicSamplePos;

		private readonly float[] _sampleBuffer = new float[2048];

		private float _loudVoiceDuration;

		private float _lastTriggerTime = -10f;

		private static Type _recorderType;

		private static PropertyInfo _recorderLevelMeterProp;

		private static PropertyInfo _recorderRecordingEnabledProp;

		private static PropertyInfo _levelMeterAvgProp;

		private static PropertyInfo _levelMeterPeakProp;

		private static Type _voiceChatType;

		private static FieldInfo _voiceChatInstanceField;

		private static FieldInfo _voiceChatRecorderField;

		private static Component _cachedRecorder;

		private static float _nextRecorderSearchTime;

		private static bool _voiceReflectionInit;

		private const float ShoutAmpThreshold = 0.025f;

		private static void InitVoiceReflection()
		{
			if (_voiceReflectionInit)
			{
				return;
			}
			_voiceReflectionInit = true;
			_recorderType = AccessTools.TypeByName("Photon.Voice.Unity.Recorder");
			if (_recorderType != null)
			{
				_recorderLevelMeterProp = AccessTools.Property(_recorderType, "LevelMeter");
				_recorderRecordingEnabledProp = AccessTools.Property(_recorderType, "RecordingEnabled");
			}
			_voiceChatType = AccessTools.TypeByName("PlayerVoiceChat");
			if (!(_voiceChatType != null))
			{
				return;
			}
			_voiceChatInstanceField = AccessTools.Field(_voiceChatType, "instance");
			if (_recorderType != null)
			{
				_voiceChatRecorderField = _voiceChatType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((FieldInfo f) => f.FieldType == _recorderType);
			}
		}

		private Component GetActiveGameRecorder()
		{
			InitVoiceReflection();
			if (_recorderType == null)
			{
				return null;
			}
			if ((Object)(object)_cachedRecorder != (Object)null && (Object)(object)_cachedRecorder.gameObject != (Object)null && _cachedRecorder.gameObject.activeInHierarchy)
			{
				return _cachedRecorder;
			}
			if (Time.unscaledTime < _nextRecorderSearchTime)
			{
				return null;
			}
			_nextRecorderSearchTime = Time.unscaledTime + 1f;
			if (_voiceChatInstanceField != null && _voiceChatRecorderField != null)
			{
				object? value = _voiceChatInstanceField.GetValue(null);
				Component val = (Component)((value is Component) ? value : null);
				if ((Object)(object)val != (Object)null)
				{
					object? value2 = _voiceChatRecorderField.GetValue(val);
					Component val2 = (Component)((value2 is Component) ? value2 : null);
					if ((Object)(object)val2 != (Object)null)
					{
						_cachedRecorder = val2;
						return _cachedRecorder;
					}
				}
			}
			Object obj = Object.FindObjectOfType(_recorderType);
			_cachedRecorder = (Component)(object)((obj is Component) ? obj : null);
			return _cachedRecorder;
		}

		private bool TryReadGameVoiceAmplitude(out float avgAmp, out float peakAmp)
		{
			avgAmp = 0f;
			peakAmp = 0f;
			Component activeGameRecorder = GetActiveGameRecorder();
			if ((Object)(object)activeGameRecorder == (Object)null || _recorderLevelMeterProp == null)
			{
				return false;
			}
			if (!(_recorderRecordingEnabledProp == null))
			{
				object value = _recorderRecordingEnabledProp.GetValue(activeGameRecorder);
				bool flag = default(bool);
				int num;
				if (value is bool)
				{
					flag = (bool)value;
					num = 1;
				}
				else
				{
					num = 0;
				}
				if (((uint)num & (flag ? 1u : 0u)) == 0)
				{
					return false;
				}
			}
			object value2 = _recorderLevelMeterProp.GetValue(activeGameRecorder);
			if (value2 == null)
			{
				return false;
			}
			if (_levelMeterAvgProp == null)
			{
				_levelMeterAvgProp = AccessTools.Property(value2.GetType(), "CurrentAvgAmp");
			}
			if (_levelMeterPeakProp == null)
			{
				_levelMeterPeakProp = AccessTools.Property(value2.GetType(), "CurrentPeakAmp");
			}
			if (_levelMeterAvgProp != null && _levelMeterAvgProp.GetValue(value2) is float num2)
			{
				avgAmp = num2;
			}
			if (_levelMeterPeakProp != null && _levelMeterPeakProp.GetValue(value2) is float num3)
			{
				peakAmp = num3;
			}
			return true;
		}

		private void Start()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			InitVoiceReflection();
			if (PhraseRecognitionSystem.isSupported)
			{
				PhraseRecognitionSystem.OnError += new ErrorDelegate(OnSpeechSystemError);
				InitRecognizer();
			}
			else
			{
				StartDirectMicIfSafe(cycleToNextMic: false);
			}
		}

		private void InitRecognizer()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			try
			{
				DisposeRecognizerOnly();
				if ((int)PhraseRecognitionSystem.Status == 0)
				{
					PhraseRecognitionSystem.Restart();
				}
				_recognizer = new KeywordRecognizer(_shooWords, (ConfidenceLevel)2);
				((PhraseRecognizer)_recognizer).OnPhraseRecognized += new PhraseRecognizedDelegate(OnPhraseRecognized);
				((PhraseRecognizer)_recognizer).Start();
			}
			catch
			{
			}
		}

		private void StopDirectMicOnly()
		{
			if (!string.IsNullOrEmpty(_activeMicName) && (Object)(object)GetActiveGameRecorder() == (Object)null && Microphone.IsRecording(_activeMicName))
			{
				Microphone.End(_activeMicName);
			}
			_micClip = null;
		}

		private void StartDirectMicIfSafe(bool cycleToNextMic)
		{
			string[] devices = Microphone.devices;
			if (devices == null || devices.Length == 0)
			{
				return;
			}
			if (cycleToNextMic && devices.Length > 1)
			{
				_selectedMicIndex = (_selectedMicIndex + 1) % devices.Length;
			}
			else if (_selectedMicIndex < 0 || _selectedMicIndex >= devices.Length)
			{
				_selectedMicIndex = 0;
			}
			string text = devices[_selectedMicIndex];
			if (!_forceDirectMic && (Object)(object)GetActiveGameRecorder() != (Object)null)
			{
				_activeMicName = text;
				_micClip = null;
				return;
			}
			if (!string.IsNullOrEmpty(_activeMicName) && _activeMicName != text && Microphone.IsRecording(_activeMicName))
			{
				Microphone.End(_activeMicName);
			}
			_activeMicName = text;
			_micClip = Microphone.Start(_activeMicName, true, 1, 16000);
			_lastMicSamplePos = 0;
		}

		private void Update()
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Invalid comparison between Unknown and I4
			if (Input.GetKeyDown((KeyCode)109))
			{
				if ((Object)(object)GetActiveGameRecorder() != (Object)null && !_forceDirectMic)
				{
					_forceDirectMic = true;
					StartDirectMicIfSafe(cycleToNextMic: false);
				}
				else
				{
					StartDirectMicIfSafe(cycleToNextMic: true);
				}
			}
			if (PhraseRecognitionSystem.isSupported && Time.unscaledTime >= _nextHealthCheckTime)
			{
				_nextHealthCheckTime = Time.unscaledTime + 2f;
				if (_recognizer == null || !((PhraseRecognizer)_recognizer).IsRunning || (int)PhraseRecognitionSystem.Status != 1)
				{
					InitRecognizer();
				}
			}
			ProcessVoiceAmplitude();
		}

		private void ProcessVoiceAmplitude()
		{
			float num;
			float num2;
			if (!_forceDirectMic && TryReadGameVoiceAmplitude(out var avgAmp, out var peakAmp))
			{
				if ((Object)(object)_micClip != (Object)null)
				{
					_micClip = null;
				}
				num = avgAmp;
				num2 = peakAmp;
			}
			else
			{
				if ((Object)(object)_micClip == (Object)null)
				{
					StartDirectMicIfSafe(cycleToNextMic: false);
				}
				if ((Object)(object)_micClip == (Object)null || string.IsNullOrEmpty(_activeMicName))
				{
					return;
				}
				if (!Microphone.IsRecording(_activeMicName))
				{
					_micClip = Microphone.Start(_activeMicName, true, 1, 16000);
					_lastMicSamplePos = 0;
					return;
				}
				int position = Microphone.GetPosition(_activeMicName);
				if (position < 0 || position == _lastMicSamplePos)
				{
					return;
				}
				int samples = _micClip.samples;
				int num3 = ((position >= _lastMicSamplePos) ? (position - _lastMicSamplePos) : (samples - _lastMicSamplePos + position));
				if (num3 < 128)
				{
					return;
				}
				int num4 = Mathf.Min(num3, _sampleBuffer.Length);
				int num5 = (position - num4 + samples) % samples;
				_micClip.GetData(_sampleBuffer, num5);
				_lastMicSamplePos = position;
				float num6 = 0f;
				float num7 = 0f;
				for (int i = 0; i < num4; i++)
				{
					float num8 = _sampleBuffer[i];
					float num9 = Mathf.Abs(num8);
					if (num9 > num7)
					{
						num7 = num9;
					}
					num6 += num8 * num8;
				}
				num = Mathf.Sqrt(num6 / (float)num4);
				num2 = num7;
			}
			if (num >= 0.025f || num2 >= 0.060000002f)
			{
				_loudVoiceDuration += Time.unscaledDeltaTime;
				if (_loudVoiceDuration >= 0.04f && Time.unscaledTime - _lastTriggerTime >= 1.5f)
				{
					_lastTriggerTime = Time.unscaledTime;
					ScareNearbyCats();
				}
			}
			else
			{
				_loudVoiceDuration = 0f;
			}
		}

		private void OnSpeechSystemError(SpeechError errorCode)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource logger = Plugin.Logger;
			if (logger != null)
			{
				logger.LogError((object)$"[CatVoice] Ошибка системы речи Windows: {errorCode}");
			}
		}

		private void OnPhraseRecognized(PhraseRecognizedEventArgs args)
		{
			ScareNearbyCats();
		}

		private void ScareNearbyCats()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 localSpeakerPosition = CatPoseController.GetLocalSpeakerPosition();
			if (CatPoseController.ActiveCats.Count == 0)
			{
				return;
			}
			foreach (CatPoseController activeCat in CatPoseController.ActiveCats)
			{
				if (!((Object)(object)activeCat == (Object)null) && ((Component)activeCat).gameObject.activeInHierarchy)
				{
					float num = Vector3.Distance(((Component)activeCat).transform.position, localSpeakerPosition);
					if (num <= 15f)
					{
						activeCat.TriggerShooReaction(localSpeakerPosition);
					}
				}
			}
		}

		private void DisposeRecognizerOnly()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			if (_recognizer == null)
			{
				return;
			}
			try
			{
				if (((PhraseRecognizer)_recognizer).IsRunning)
				{
					((PhraseRecognizer)_recognizer).Stop();
				}
				((PhraseRecognizer)_recognizer).OnPhraseRecognized -= new PhraseRecognizedDelegate(OnPhraseRecognized);
				((PhraseRecognizer)_recognizer).Dispose();
			}
			catch
			{
			}
			_recognizer = null;
		}

		private void OnDestroy()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			PhraseRecognitionSystem.OnError -= new ErrorDelegate(OnSpeechSystemError);
			DisposeRecognizerOnly();
			StopDirectMicOnly();
		}
	}
	public static class CatAggroManager
	{
		private sealed class AggroEntry
		{
			public CatPoseController Cat;

			public float ExpiresAt;
		}

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

		private static Type _enemyType;

		public static void ApplyNavigationPatches(Harmony harmony)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			_enemyType = AccessTools.TypeByName("Enemy");
			Type type = AccessTools.TypeByName("EnemyNavMeshAgent");
			if (type != null)
			{
				MethodInfo methodInfo = AccessTools.Method(type, "SetDestination", new Type[1] { typeof(Vector3) }, (Type[])null);
				if (methodInfo != null)
				{
					HarmonyMethod val = new HarmonyMethod(typeof(CatAggroManager), "PrefixEnemySetDestination", (Type[])null);
					harmony.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
		}

		public static void RegisterAggro(Component enemy, CatPoseController cat, float duration = 3.5f)
		{
			if (!((Object)(object)enemy == (Object)null) && !((Object)(object)cat == (Object)null) && !cat.IsSitting && !(cat.currentHp < 50f))
			{
				int instanceID = ((Object)enemy).GetInstanceID();
				EnemyAggroMap[instanceID] = new AggroEntry
				{
					Cat = cat,
					ExpiresAt = Time.time + duration
				};
			}
		}

		public static void ClearAggroForCat(CatPoseController cat)
		{
			if ((Object)(object)cat == (Object)null)
			{
				return;
			}
			List<int> list = (from kvp in EnemyAggroMap
				where (Object)(object)kvp.Value.Cat == (Object)(object)cat
				select kvp.Key).ToList();
			foreach (int item in list)
			{
				EnemyAggroMap.Remove(item);
			}
		}

		public static bool TryGetAggroCat(Component enemy, out CatPoseController cat)
		{
			cat = null;
			if ((Object)(object)enemy == (Object)null)
			{
				return false;
			}
			int instanceID = ((Object)enemy).GetInstanceID();
			if (!EnemyAggroMap.TryGetValue(instanceID, out var value))
			{
				return false;
			}
			if (Time.time > value.ExpiresAt || (Object)(object)value.Cat == (Object)null || !((Component)value.Cat).gameObject.activeInHierarchy || value.Cat.IsSitting || value.Cat.currentHp < 50f)
			{
				EnemyAggroMap.Remove(instanceID);
				return false;
			}
			cat = value.Cat;
			return true;
		}

		private static void PrefixEnemySetDestination(Component __instance, ref Vector3 __0)
		{
			//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)
			if (!((Object)(object)__instance == (Object)null) && !(_enemyType == null))
			{
				Component componentInParent = __instance.GetComponentInParent(_enemyType);
				if ((Object)(object)componentInParent != (Object)null && TryGetAggroCat(componentInParent, out var cat))
				{
					__0 = ((Component)cat).transform.position;
				}
			}
		}
	}
	[HarmonyPatch]
	public static class OrangeCatShopPatch
	{
		private static GameObject _rawCatModel;

		private static GameObject _catPrefab;

		private static GameObject _hiddenContainer;

		internal static Item CatItem;

		private static bool _registeredInRepoLib;

		private const string ItemKey = "Item Orange Cat";

		private const string ResourcePath = "Items/OrangeCat";

		internal const int CatShopPriceK = 1;

		public static void ApplyPhotonPoolPatch(Harmony harmony)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			Type typeFromHandle = typeof(DefaultPool);
			MethodInfo methodInfo = AccessTools.Method(typeFromHandle, "Instantiate", new Type[3]
			{
				typeof(string),
				typeof(Vector3),
				typeof(Quaternion)
			}, (Type[])null);
			if (methodInfo != null)
			{
				HarmonyMethod val = new HarmonyMethod(typeof(OrangeCatShopPatch), "PrefixDefaultPoolInstantiate", (Type[])null);
				harmony.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private static void PrefixDefaultPoolInstantiate(string prefabId)
		{
			if (prefabId == "Items/OrangeCat" || prefabId == "OrangeCat")
			{
				TryRegisterCatItem();
				RegisterInPhotonPool();
			}
		}

		[HarmonyPatch(typeof(StatsManager), "Start")]
		[HarmonyPostfix]
		private static void RegisterOnStatsStart()
		{
			TryRegisterCatItem();
		}

		[HarmonyPatch(typeof(ShopManager), "GetAllItemsFromStatsManager")]
		[HarmonyPrefix]
		private static void EnsureCatRegisteredBeforeShop()
		{
			TryRegisterCatItem();
		}

		[HarmonyPatch(typeof(ShopManager), "GetAllItemsFromStatsManager")]
		[HarmonyPostfix]
		private static void GuaranteeCatInShop(ShopManager __instance)
		{
			if (!((Object)(object)CatItem == (Object)null) && !((Object)(object)__instance == (Object)null))
			{
				if (!__instance.potentialItems.Contains(CatItem))
				{
					__instance.potentialItems.Insert(0, CatItem);
				}
				((MonoBehaviour)__instance).StartCoroutine(EnsureCatSpawnedOnShopShelfRoutine());
			}
		}

		private static IEnumerator EnsureCatSpawnedOnShopShelfRoutine()
		{
			yield return (object)new WaitForSeconds(1f);
			if (CatPoseController.ActiveCats.Count > 0 || (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient) || !TryRegisterCatItem())
			{
				yield break;
			}
			ItemAttributes[] shelfItems = (from ia in Object.FindObjectsOfType<ItemAttributes>()
				where (Object)(object)ia != (Object)null && (Object)(object)ia.item != (Object)null && (Object)(object)ia.item != (Object)(object)CatItem
				select ia).ToArray();
			ItemAttributes slotDonor = ((IEnumerable<ItemAttributes>)shelfItems).FirstOrDefault((Func<ItemAttributes, bool>)((ItemAttributes ia) => (int)ia.item.itemType == 13)) ?? shelfItems.FirstOrDefault();
			Vector3 spawnPos;
			Quaternion spawnRot;
			if ((Object)(object)slotDonor != (Object)null)
			{
				spawnPos = ((Component)slotDonor).transform.position;
				spawnRot = ((Component)slotDonor).transform.rotation;
				PhotonView donorPv = ((Component)slotDonor).GetComponent<PhotonView>();
				if (PhotonNetwork.InRoom && (Object)(object)donorPv != (Object)null && donorPv.IsMine)
				{
					PhotonNetwork.Destroy(((Component)slotDonor).gameObject);
				}
				else
				{
					Object.Destroy((Object)(object)((Component)slotDonor).gameObject);
				}
			}
			else
			{
				Camera cam = Camera.main;
				spawnPos = (((Object)(object)cam != (Object)null) ? (((Component)cam).transform.position + ((Component)cam).transform.forward * 2f + Vector3.up * 0.25f) : (Vector3.up * 1f));
				spawnRot = Quaternion.identity;
			}
			GameObject spawnedCat;
			if (PhotonNetwork.InRoom)
			{
				RegisterInPhotonPool();
				spawnedCat = PhotonNetwork.Instantiate("Items/OrangeCat", spawnPos, spawnRot, (byte)0, (object[])null);
			}
			else
			{
				spawnedCat = Object.Instantiate<GameObject>(_catPrefab, spawnPos, spawnRot);
			}
			if ((Object)(object)spawnedCat != (Object)null)
			{
				spawnedCat.SetActive(true);
				ApplyCatItemAttributes(spawnedCat);
			}
		}

		internal static void ApplyCatItemAttributes(GameObject target)
		{
			if (!((Object)(object)target == (Object)null))
			{
				if ((Object)(object)CatItem == (Object)null)
				{
					TryRegisterCatItem();
				}
				ItemAttributes component = target.GetComponent<ItemAttributes>();
				if ((Object)(object)component != (Object)null && (Object)(object)CatItem != (Object)null)
				{
					component.item = CatItem;
					component.itemName = "Orange Cat";
					component.value = 1;
				}
			}
		}

		[HarmonyPatch(typeof(ItemAttributes), "Start")]
		[HarmonyPostfix]
		private static void FixCatShopPriceStart(ItemAttributes __instance)
		{
			if (IsCatItem(__instance))
			{
				__instance.value = 1;
			}
		}

		[HarmonyPatch(typeof(ItemAttributes), "GetValue")]
		[HarmonyPostfix]
		private static void FixCatShopPriceGetValue(ItemAttributes __instance)
		{
			if (IsCatItem(__instance))
			{
				__instance.value = 1;
			}
		}

		private static bool IsCatItem(ItemAttributes attrs)
		{
			if ((Object)(object)attrs == (Object)null)
			{
				return false;
			}
			if ((Object)(object)CatItem != (Object)null && (Object)(object)attrs.item == (Object)(object)CatItem)
			{
				return true;
			}
			return attrs.itemName == "Orange Cat" || ((Object)(object)attrs.item != (Object)null && ((Object)attrs.item).name == "Item Orange Cat");
		}

		public static bool TryRegisterCatItem()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			if (!LoadAndSetupPrefab())
			{
				return false;
			}
			if ((Object)(object)CatItem == (Object)null)
			{
				Value val = ScriptableObject.CreateInstance<Value>();
				val.valueMin = 1f;
				val.valueMax = 1f;
				PrefabRef val2 = new PrefabRef();
				((PrefabRef<GameObject>)(object)val2).SetPrefab(_catPrefab, "Items/OrangeCat");
				CatItem = ScriptableObject.CreateInstance<Item>();
				((Object)CatItem).name = "Item Orange Cat";
				CatItem.itemName = "Orange Cat";
				CatItem.itemType = (itemType)13;
				CatItem.value = val;
				CatItem.prefab = val2;
				CatItem.maxAmount = 10;
				CatItem.maxAmountInShop = 1;
			}
			ItemAttributes component = _catPrefab.GetComponent<ItemAttributes>();
			if ((Object)(object)component != (Object)null)
			{
				component.item = CatItem;
				component.itemName = CatItem.itemName;
				component.value = 1;
			}
			if (!_registeredInRepoLib)
			{
				RegisterWithRepoLib(component);
			}
			if ((Object)(object)StatsManager.instance != (Object)null && StatsManager.instance.itemDictionary != null)
			{
				StatsManager.instance.itemDictionary["Item Orange Cat"] = CatItem;
			}
			RegisterInPhotonPool();
			return true;
		}

		private static void RegisterWithRepoLib(ItemAttributes attrs)
		{
			Type type = AccessTools.TypeByName("REPOLib.Modules.Items");
			if (type == null)
			{
				return;
			}
			MethodInfo[] source = (from m in type.GetMethods(BindingFlags.Static | BindingFlags.Public)
				where m.Name == "RegisterItem"
				select m).ToArray();
			MethodInfo methodInfo = source.FirstOrDefault(delegate(MethodInfo m)
			{
				ParameterInfo[] parameters = m.GetParameters();
				return parameters.Length == 1 && parameters[0].ParameterType == typeof(ItemAttributes);
			});
			if (methodInfo != null && (Object)(object)attrs != (Object)null)
			{
				methodInfo.Invoke(null, new object[1] { attrs });
				_registeredInRepoLib = true;
				return;
			}
			MethodInfo methodInfo2 = source.FirstOrDefault(delegate(MethodInfo m)
			{
				ParameterInfo[] parameters = m.GetParameters();
				return parameters.Length == 1 && parameters[0].ParameterType == typeof(Item);
			});
			if (methodInfo2 != null && (Object)(object)CatItem != (Object)null)
			{
				methodInfo2.Invoke(null, new object[1] { CatItem });
				_registeredInRepoLib = true;
			}
		}

		private static void RegisterInPhotonPool()
		{
			if ((Object)(object)_catPrefab != (Object)null)
			{
				IPunPrefabPool prefabPool = PhotonNetwork.PrefabPool;
				DefaultPool val = (DefaultPool)(object)((prefabPool is DefaultPool) ? prefabPool : null);
				if (val != null)
				{
					val.ResourceCache["OrangeCat"] = _catPrefab;
					val.ResourceCache["Items/OrangeCat"] = _catPrefab;
				}
			}
		}

		private static GameObject GetCatModelFromBundle()
		{
			if ((Object)(object)_rawCatModel != (Object)null)
			{
				return _rawCatModel;
			}
			foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles())
			{
				if (!((Object)(object)allLoadedAssetBundle == (Object)null))
				{
					GameObject val = allLoadedAssetBundle.LoadAsset<GameObject>("OrangeCat");
					if ((Object)(object)val != (Object)null)
					{
						_rawCatModel = val;
						return _rawCatModel;
					}
				}
			}
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string text = Path.Combine(directoryName, "orangecatbundle");
			if (!File.Exists(text))
			{
				Plugin.Logger.LogError((object)("Файл AssetBundle не найден: " + text));
				return null;
			}
			AssetBundle val2 = AssetBundle.LoadFromFile(text);
			if ((Object)(object)val2 == (Object)null)
			{
				Plugin.Logger.LogError((object)"Не удалось загрузить orangecatbundle с диска!");
				return null;
			}
			_rawCatModel = val2.LoadAsset<GameObject>("OrangeCat");
			return _rawCatModel;
		}

		private static GameObject FindTemplatePrefab()
		{
			if ((Object)(object)StatsManager.instance != (Object)null && StatsManager.instance.itemDictionary != null)
			{
				Item val = ((IEnumerable<Item>)StatsManager.instance.itemDictionary.Values).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && (int)i.itemType == 3 && i.prefab != null && ((PrefabRef<GameObject>)(object)i.prefab).IsValid() && (Object)(object)((PrefabRef<GameObject>)(object)i.prefab).Prefab != (Object)null));
				if ((Object)(object)val != (Object)null)
				{
					return ((PrefabRef<GameObject>)(object)val.prefab).Prefab;
				}
				Item val2 = ((IEnumerable<Item>)StatsManager.instance.itemDictionary.Values).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && i.prefab != null && ((PrefabRef<GameObject>)(object)i.prefab).IsValid() && (Object)(object)((PrefabRef<GameObject>)(object)i.prefab).Prefab != (Object)null));
				if ((Object)(object)val2 != (Object)null)
				{
					return ((PrefabRef<GameObject>)(object)val2.prefab).Prefab;
				}
			}
			Item val3 = ((IEnumerable<Item>)Resources.FindObjectsOfTypeAll<Item>()).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && (int)i.itemType == 3 && i.prefab != null && ((PrefabRef<GameObject>)(object)i.prefab).IsValid() && (Object)(object)((PrefabRef<GameObject>)(object)i.prefab).Prefab != (Object)null));
			if ((Object)(object)val3 != (Object)null)
			{
				return ((PrefabRef<GameObject>)(object)val3.prefab).Prefab;
			}
			ItemAttributes val4 = ((IEnumerable<ItemAttributes>)Resources.FindObjectsOfTypeAll<ItemAttributes>()).FirstOrDefault((Func<ItemAttributes, bool>)((ItemAttributes ia) => (Object)(object)ia != (Object)null && (Object)(object)((Component)ia).gameObject != (Object)null && (Object)(object)((Component)ia).GetComponent<PhysGrabObject>() != (Object)null && (Object)(object)((Component)ia).GetComponent<PhotonView>() != (Object)null));
			if ((Object)(object)val4 != (Object)null)
			{
				return ((Component)val4).gameObject;
			}
			return null;
		}

		internal static void SetLayerRecursively(GameObject obj, int layer)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			if ((Object)(object)obj == (Object)null || layer < 0)
			{
				return;
			}
			obj.layer = layer;
			foreach (Transform item in obj.transform)
			{
				Transform val = item;
				if (!(((Object)val).name == "CatHpBarRoot"))
				{
					SetLayerRecursively(((Component)val).gameObject, layer);
				}
			}
		}

		private static Bounds CalculateLocalCatBounds(GameObject root, GameObject catVisual)
		{
			//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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: 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_0167: 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_0171: 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_00d2: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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_0112: 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_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: 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)
			SkinnedMeshRenderer componentInChildren = catVisual.GetComponentInChildren<SkinnedMeshRenderer>(true);
			if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.sharedMesh != (Object)null)
			{
				Bounds localBounds = ((Renderer)componentInChildren).localBounds;
				Vector3 val = ((Component)componentInChildren).transform.TransformPoint(((Bounds)(ref localBounds)).center);
				Vector3 val2 = root.transform.InverseTransformPoint(val);
				Vector3 val3 = Vector3.Scale(((Bounds)(ref localBounds)).size, ((Component)componentInChildren).transform.lossyScale);
				return new Bounds(val2, new Vector3(Mathf.Abs(val3.x), Mathf.Abs(val3.y), Mathf.Abs(val3.z)));
			}
			MeshFilter componentInChildren2 = catVisual.GetComponentInChildren<MeshFilter>(true);
			if ((Object)(object)componentInChildren2 != (Object)null && (Object)(object)componentInChildren2.sharedMesh != (Object)null)
			{
				Bounds bounds = componentInChildren2.sharedMesh.bounds;
				Vector3 val4 = ((Component)componentInChildren2).transform.TransformPoint(((Bounds)(ref bounds)).center);
				Vector3 val5 = root.transform.InverseTransformPoint(val4);
				Vector3 val6 = Vector3.Scale(((Bounds)(ref bounds)).size, ((Component)componentInChildren2).transform.lossyScale);
				return new Bounds(val5, new Vector3(Mathf.Abs(val6.x), Mathf.Abs(val6.y), Mathf.Abs(val6.z)));
			}
			return new Bounds(new Vector3(0f, 0.2f, -0.08f), new Vector3(0.32f, 0.42f, 0.75f));
		}

		private static void StripDonorBehaviorScripts(GameObject prefab)
		{
			MonoBehaviour[] componentsInChildren = prefab.GetComponentsInChildren<MonoBehaviour>(true);
			MonoBehaviour[] array = componentsInChildren;
			foreach (MonoBehaviour val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				string name = ((object)val).GetType().Name;
				if (!name.StartsWith("ItemUpgrade"))
				{
					switch (name)
					{
					default:
						if (!name.Contains("Upgrade"))
						{
							continue;
						}
						break;
					case "ItemToggle":
					case "ItemBattery":
					case "ItemEquippable":
					case "ItemMine":
					case "ItemGrenade":
					case "ItemDrone":
					case "ItemOrb":
					case "ItemRubberDuck":
						break;
					}
				}
				Object.DestroyImmediate((Object)(object)val);
			}
		}

		private static bool LoadAndSetupPrefab()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0144: 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_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: 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_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Expected O, but got Unknown
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_catPrefab != (Object)null)
			{
				RegisterInPhotonPool();
				return true;
			}
			GameObject catModelFromBundle = GetCatModelFromBundle();
			if ((Object)(object)catModelFromBundle == (Object)null)
			{
				Plugin.Logger.LogError((object)"Не удалось получить модель OrangeCat из бандла!");
				return false;
			}
			if ((Object)(object)_hiddenContainer == (Object)null)
			{
				_hiddenContainer = new GameObject("MyRepoMod_HiddenPrefabs");
				Object.DontDestroyOnLoad((Object)(object)_hiddenContainer);
				_hiddenContainer.SetActive(false);
			}
			GameObject val = FindTemplatePrefab();
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogError((object)"Не найден предмет-шаблон для создания кота!");
				return false;
			}
			_catPrefab = Object.Instantiate<GameObject>(val, _hiddenContainer.transform);
			((Object)_catPrefab).name = "OrangeCat";
			_catPrefab.SetActive(true);
			StripDonorBehaviorScripts(_catPrefab);
			Renderer[] componentsInChildren = _catPrefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren)
			{
				val2.enabled = false;
			}
			GameObject val3 = Object.Instantiate<GameObject>(catModelFromBundle, _catPrefab.transform);
			((Object)val3).name = "OrangeCatVisual";
			val3.transform.localPosition = Vector3.zero;
			val3.transform.localRotation = Quaternion.identity;
			val3.transform.localScale = Vector3.one;
			val3.SetActive(true);
			Collider[] componentsInChildren2 = val3.GetComponentsInChildren<Collider>(true);
			foreach (Collider val4 in componentsInChildren2)
			{
				Object.DestroyImmediate((Object)(object)val4);
			}
			Bounds val5 = CalculateLocalCatBounds(_catPrefab, val3);
			float y = ((Bounds)(ref val5)).min.y;
			float num = Mathf.Max(((Bounds)(ref val5)).size.y + 0.18f, 0.52f);
			Vector3 size = default(Vector3);
			((Vector3)(ref size))..ctor(Mathf.Max(((Bounds)(ref val5)).size.x + 0.28f, 0.56f), num, Mathf.Max(((Bounds)(ref val5)).size.z + 0.24f, 0.88f));
			Vector3 val6 = default(Vector3);
			((Vector3)(ref val6))..ctor(((Bounds)(ref val5)).center.x, y + num * 0.5f, ((Bounds)(ref val5)).center.z);
			PhysGrabObjectCollider[] componentsInChildren3 = _catPrefab.GetComponentsInChildren<PhysGrabObjectCollider>(true);
			if (componentsInChildren3.Length != 0)
			{
				for (int k = 0; k < componentsInChildren3.Length; k++)
				{
					PhysGrabObjectCollider val7 = componentsInChildren3[k];
					if (k == 0)
					{
						((Component)val7).gameObject.SetActive(true);
						((Behaviour)val7).enabled = true;
						((Component)val7).transform.localPosition = Vector3.zero;
						((Component)val7).transform.localRotation = Quaternion.identity;
						((Component)val7).transform.localScale = Vector3.one;
						Collider[] components = ((Component)val7).GetComponents<Collider>();
						foreach (Collider val8 in components)
						{
							Object.DestroyImmediate((Object)(object)val8);
						}
						BoxCollider val9 = ((Component)val7).gameObject.AddComponent<BoxCollider>();
						((Collider)val9).isTrigger = false;
						val9.center = val6;
						val9.size = size;
						FieldInfo[] fields = typeof(PhysGrabObjectCollider).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						foreach (FieldInfo fieldInfo in fields)
						{
							if (typeof(Collider).IsAssignableFrom(fieldInfo.FieldType))
							{
								fieldInfo.SetValue(val7, val9);
							}
						}
					}
					else
					{
						Collider[] components2 = ((Component)val7).GetComponents<Collider>();
						foreach (Collider val10 in components2)
						{
							Object.DestroyImmediate((Object)(object)val10);
						}
						Object.DestroyImmediate((Object)(object)val7);
					}
				}
			}
			else
			{
				GameObject val11 = new GameObject("GrabCollider");
				val11.transform.SetParent(_catPrefab.transform, false);
				BoxCollider val12 = val11.AddComponent<BoxCollider>();
				val12.center = val6;
				val12.size = size;
				val11.AddComponent<PhysGrabObjectCollider>();
			}
			int num2 = LayerMask.NameToLayer("PhysGrabObject");
			if (num2 < 0)
			{
				num2 = val.layer;
			}
			SetLayerRecursively(_catPrefab, num2);
			PhotonView component = _catPrefab.GetComponent<PhotonView>();
			if ((Object)(object)component != (Object)null)
			{
				component.OwnershipTransfer = (OwnershipOption)1;
			}
			Rigidbody component2 = _catPrefab.GetComponent<Rigidbody>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.useGravity = true;
				component2.isKinematic = false;
				component2.mass = 2f;
				component2.collisionDetectionMode = (CollisionDetectionMode)2;
				component2.interpolation = (RigidbodyInterpolation)1;
				component2.ResetCenterOfMass();
				component2.ResetInertiaTensor();
			}
			PhysGrabObject component3 = _catPrefab.GetComponent<PhysGrabObject>();
			if ((Object)(object)component3 != (Object)null)
			{
				component3.rb = component2;
				component3.centerPoint = val6;
			}
			CatPoseController catPoseController = _catPrefab.AddComponent<CatPoseController>();
			catPoseController.visualRoot = val3.transform;
			RegisterInPhotonPool();
			return true;
		}
	}
	public class CatPoseController : MonoBehaviour
	{
		public static readonly List<CatPoseController> ActiveCats = new List<CatPoseController>();

		public Transform visualRoot;

		public const float MaxHp = 350f;

		public const float LowHpFleeThreshold = 50f;

		public const float HpRegenPerSec = 5f;

		public const int MinStrikeDamage = 2;

		public const int MaxStrikeDamage = 5;

		public const float StrikeInterval = 0.65f;

		public const float ValuableAttackDuration = 3f;

		public const float ValuableMusicDuration = 3.5f;

		public const float CombatAngryHoldDuration = 2.5f;

		public const float MaxBattleAudioVolume = 0.22f;

		public const float ShooFleeDuration = 2.2f;

		public const float InteractableVisionRange = 9.5f;

		public const float MaxDistanceFromPlayerForInteractable = 6.5f;

		public float currentHp = 350f;

		private bool _isSitting = true;

		private float _sitBlend = 1f;

		private float _waddleTimer;

		private float _lastToggleTime = -10f;

		private float _nextNetSyncTime;

		private int _shooSequence;

		private string _lastAppliedRoomState = string.Empty;

		private float _shooFleeTimer;

		private Vector3 _shooScareOrigin;

		private Vector3 _shooTargetPoint;

		private float _nextShooPathScanTime;

		private Vector3 _lowHpFleeTarget;

		private float _nextLowHpFleeScanTime;

		private Rigidbody _targetInteractableRb;

		private Component _targetHingeComp;

		private Vector3 _interactableClosedPos;

		private Quaternion _interactableClosedRot;

		private float _interactableTimer;

		private float _nextInteractableScanTime;

		private readonly HashSet<int> _openedInteractableIds = new HashSet<int>();

		private Transform _targetPlayer;

		private Component _ownerAvatarComp;

		private string _ownerName = string.Empty;

		private Vector3 _wanderOffset;

		private float _nextWanderPickTime;

		private Vector3 _lastStuckCheckPos;

		private float _stuckTimer;

		private float _unstuckBackoffTimer;

		private Vector3 _unstuckBackoffNormal;

		private float _wallFollowLockUntil;

		private int _wallFollowSign = 1;

		private int _navMask;

		private Vector3 _groundNormal = Vector3.up;

		private bool _isGrounded;

		private float _nextJumpAllowedTime;

		private bool _isSpinAttacking;

		private float _combatAngryTimer;

		private float _oiiaSpinAngle;

		private float _nextHopTime;

		private float _nextStrikeTime;

		private float _lastHurtTime = -10f;

		private float _enemyScanTimer;

		private float _enemyLostTimer;

		private Component _nearestEnemy;

		private bool _isAttackingValuable;

		private float _valuableAttackTimer;

		private float _valuableMusicTimer;

		private Component _targetValuable;

		private float _valuableScanTimer;

		private bool _valuableDamagedThisAttack;

		private readonly HashSet<int> _processedValuableIds = new HashSet<int>();

		private AudioSource _battleAudioSource;

		private Transform _hpBarRoot;

		private Transform _hpBarFillPivot;

		private MeshRenderer _hpBarFillRenderer;

		private Material _hpBarFillMat;

		private TextMesh _ownerNameText;

		private PhysGrabObject _physGrab;

		private PhotonView _photonView;

		private Rigidbody _rb;

		private SkinnedMeshRenderer[] _skinnedRenderers;

		private Animator _animator;

		private Animation _legacyAnimation;

		private Vector3 _defaultVisualPos;

		private Quaternion _defaultVisualRot;

		private static Type _enemyType;

		private static Type _enemyHealthType;

		private static Type _hurtColliderType;

		private static Type _navMeshAgentType;

		private static Type _valuableObjectType;

		private static Type _impactDetectorType;

		private static Type _playerAvatarType;

		private static Type _grabberType;

		private static Type _hingeType;

		private static MethodInfo[] _enemyHurtMethods;

		private static MethodInfo _enemyDeathMethod;

		private static FieldInfo _enemyHealthField;

		private static FieldInfo _enemyMaxHealthField;

		private static FieldInfo _enemyCurrentStateField;

		private static FieldInfo _enemyTargetPlayerField;

		private static FieldInfo _enemyVisionField;

		private static MethodInfo _visionTriggerMethod;

		private static MethodInfo _enemySetChaseTargetMethod;

		private static MethodInfo _navSetDestinationMethod;

		private static PropertyInfo _navIsOnNavMeshProp;

		private static FieldInfo _valuableDollarCurrentField;

		private static MethodInfo _valuableDollarSetMethod;

		private static MethodInfo _impactBreakMethod;

		private static FieldInfo _playerGrabbingField;

		private static FieldInfo _grabDisableField;

		private static FieldInfo _grabberAvatarField;

		private static FieldInfo _grabberIsLocalField;

		private static FieldInfo _grabberInstanceField;

		private static FieldInfo _grabberGrabbedObjectField;

		private static FieldInfo _playerNameField;

		private static FieldInfo _playerAvatarInstanceField;

		private static FieldInfo _hingeClosedField;

		private static FieldInfo _hingeOpenField;

		private static MethodInfo _hingeOpenMethod;

		private static object _chaseStateEnumValue;

		private static bool _reflectionInitialized;

		public bool IsSitting => _isSitting;

		public bool IsSpinAttacking => _isSpinAttacking || _isAttackingValuable;

		private static void InitReflection()
		{
			if (_reflectionInitialized)
			{
				return;
			}
			_reflectionInitialized = true;
			_enemyType = AccessTools.TypeByName("Enemy");
			_enemyHealthType = AccessTools.TypeByName("EnemyHealth");
			_hurtColliderType = AccessTools.TypeByName("HurtCollider");
			_navMeshAgentType = AccessTools.TypeByName("UnityEngine.AI.NavMeshAgent");
			_valuableObjectType = AccessTools.TypeByName("ValuableObject");
			_impactDetectorType = AccessTools.TypeByName("PhysGrabObjectImpactDetector");
			_playerAvatarType = AccessTools.TypeByName("PlayerAvatar");
			_grabberType = AccessTools.TypeByName("PhysGrabber");
			_hingeType = AccessTools.TypeByName("PhysGrabHinge");
			if (_hingeType != null)
			{
				_hingeClosedField = AccessTools.Field(_hingeType, "closed") ?? AccessTools.Field(_hingeType, "isClosed");
				_hingeOpenField = AccessTools.Field(_hingeType, "open") ?? AccessTools.Field(_hingeType, "isOpen");
				_hingeOpenMethod = _hingeType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => (m.Name.Contains("Open") || m.Name.Contains("Unlock")) && m.GetParameters().Length == 0);
			}
			if (_enemyType != null)
			{
				_enemyCurrentStateField = AccessTools.Field(_enemyType, "CurrentState");
				if (_enemyCurrentStateField != null && _enemyCurrentStateField.FieldType.IsEnum)
				{
					try
					{
						_chaseStateEnumValue = Enum.Parse(_enemyCurrentStateField.FieldType, "Chase");
					}
					catch
					{
						_chaseStateEnumValue = null;
					}
				}
				if (_playerAvatarType != null)
				{
					_enemyTargetPlayerField = _enemyType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((FieldInfo f) => f.FieldType == _playerAvatarType);
					_enemySetChaseTargetMethod = _enemyType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name.Contains("Chase") && m.GetParameters().Length == 1 && m.GetParameters()[0].ParameterType == _playerAvatarType);
				}
				_enemyVisionField = AccessTools.Field(_enemyType, "Vision");
				if (_enemyVisionField != null)
				{
					_visionTriggerMethod = _enemyVisionField.FieldType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name.Contains("VisionTrigger") && m.GetParameters().Length >= 1 && m.GetParameters()[0].ParameterType == typeof(int));
				}
			}
			if (_enemyHealthType != null)
			{
				_enemyHurtMethods = (from m in _enemyHealthType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
					where (m.Name == "Hurt" || m.Name == "HurtOther" || m.Name == "HurtRPC") && m.GetParameters().Length >= 1 && m.GetParameters()[0].ParameterType == typeof(int)
					orderby m.GetParameters().Length
					select m).ToArray();
				_enemyDeathMethod = _enemyHealthType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name == "Death" || m.Name == "DeathRPC" || m.Name == "Kill");
				_enemyHealthField = AccessTools.Field(_enemyHealthType, "health") ?? _enemyHealthType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((FieldInfo f) => f.Name.ToLowerInvariant().Contains("health") && !f.Name.ToLowerInvariant().Contains("max") && f.FieldType == typeof(int));
				_enemyMaxHealthField = AccessTools.Field(_enemyHealthType, "healthMax");
			}
			if (_navMeshAgentType != null)
			{
				_navSetDestinationMethod = AccessTools.Method(_navMeshAgentType, "SetDestination", new Type[1] { typeof(Vector3) }, (Type[])null);
				_navIsOnNavMeshProp = AccessTools.Property(_navMeshAgentType, "isOnNavMesh");
			}
			if (_valuableObjectType != null)
			{
				_valuableDollarCurrentField = AccessTools.Field(_valuableObjectType, "dollarValueCurrent");
				_valuableDollarSetMethod = _valuableObjectType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name == "DollarValueSet" && m.GetParameters().Length == 1 && m.GetParameters()[0].ParameterType == typeof(float));
			}
			if (_impactDetectorType != null)
			{
				_impactBreakMethod = _impactDetectorType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name == "Break");
			}
			_playerGrabbingField = AccessTools.Field(typeof(PhysGrabObject), "playerGrabbing");
			_grabDisableField = AccessTools.Field(typeof(PhysGrabObject), "grabDisable");
			if (_grabberType != null)
			{
				_grabberAvatarField = AccessTools.Field(_grabberType, "playerAvatar");
				_grabberIsLocalField = AccessTools.Field(_grabberType, "isLocal");
				_grabberInstanceField = AccessTools.Field(_grabberType, "instance");
				_grabberGrabbedObjectField = _grabberType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((FieldInfo f) => f.FieldType == typeof(PhysGrabObject));
			}
			if (_playerAvatarType != null)
			{
				_playerNameField = AccessTools.Field(_playerAvatarType, "playerName");
				_playerAvatarInstanceField = AccessTools.Field(_playerAvatarType, "instance");
			}
		}

		public static Vector3 GetLocalSpeakerPosition()
		{
			//IL_006b: 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_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_0073: 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)
			InitReflection();
			if (_playerAvatarInstanceField != null)
			{
				object? value = _playerAvatarInstanceField.GetValue(null);
				Component val = (Component)((value is Component) ? value : null);
				if (val != null && (Object)(object)val != (Object)null)
				{
					return val.transform.position;
				}
			}
			if ((Object)(object)Camera.main != (Object)null)
			{
				return ((Component)Camera.main).transform.position;
			}
			return Vector3.zero;
		}

		private bool HasSimulationAuthority()
		{
			if (!PhotonNetwork.InRoom || (Object)(object)_photonView == (Object)null)
			{
				return true;
			}
			return _photonView.IsMine;
		}

		private bool CanLocalPlayerInteractWithCat()
		{
			//IL_01d6: 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)
			if (_grabberInstanceField != null && _grabberGrabbedObjectField != null)
			{
				object value = _grabberInstanceField.GetValue(null);
				if (value != null)
				{
					object? value2 = _grabberGrabbedObjectField.GetValue(value);
					PhysGrabObject val = (PhysGrabObject)((value2 is PhysGrabObject) ? value2 : null);
					if ((Object)(object)val != (Object)null && (Object)(object)val == (Object)(object)_physGrab)
					{
						return true;
					}
				}
			}
			if ((Object)(object)_physGrab != (Object)null && _playerGrabbingField != null && _playerGrabbingField.GetValue(_physGrab) is IList list)
			{
				bool flag = default(bool);
				foreach (object item in list)
				{
					Component val2 = (Component)((item is Component) ? item : null);
					if (val2 == null || (Object)(object)val2 == (Object)null)
					{
						continue;
					}
					int num;
					if (_grabberIsLocalField != null)
					{
						object value3 = _grabberIsLocalField.GetValue(val2);
						if (value3 is bool)
						{
							flag = (bool)value3;
							num = 1;
						}
						else
						{
							num = 0;
						}
					}
					else
					{
						num = 0;
					}
					if (((uint)num & (flag ? 1u : 0u)) != 0)
					{
						return true;
					}
					PhotonView componentInParent = val2.GetComponentInParent<PhotonView>();
					if (!((Object)(object)componentInParent != (Object)null) || !componentInParent.IsMine)
					{
						continue;
					}
					return true;
				}
			}
			if (!PhotonNetwork.InRoom && (Object)(object)_physGrab != (Object)null && _physGrab.grabbed)
			{
				return true;
			}
			Camera main = Camera.main;
			RaycastHit val3 = default(RaycastHit);
			if ((Object)(object)main != (Object)null && Physics.SphereCast(((Component)main).transform.position, 0.25f, ((Component)main).transform.forward, ref val3, 3f, -1, (QueryTriggerInteraction)2) && ((Object)(object)((RaycastHit)(ref val3)).transform == (Object)(object)((Component)this).transform || ((RaycastHit)(ref val3)).transform.IsChildOf(((Component)this).transform)))
			{
				return true;
			}
			return false;
		}

		private bool IsPhysObjectGrabbed(PhysGrabObject phys)
		{
			if ((Object)(object)phys == (Object)null)
			{
				return false;
			}
			if (phys.grabbed)
			{
				return true;
			}
			if (_playerGrabbingField != null && _playerGrabbingField.GetValue(phys) is IList { Count: >0 })
			{
				return true;
			}
			return false;
		}

		private bool IsGrabbedByAnyone()
		{
			return IsPhysObjectGrabbed(_physGrab);
		}

		private void OnEnable()
		{
			if (!ActiveCats.Contains(this))
			{
				ActiveCats.Add(this);
			}
		}

		private void OnDisable()
		{
			ActiveCats.Remove(this);
			CatAggroManager.ClearAggroForCat(this);
			StopBattleMusicImmediate();
		}

		private void Awake()
		{
			//IL_00f0: 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_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			InitReflection();
			Plugin.EnsurePersistentVoiceListener();
			if ((Object)(object)visualRoot == (Object)null)
			{
				Transform val = ((Component)this).transform.Find("OrangeCatVisual");
				visualRoot = (((Object)(object)val != (Object)null) ? val : ((Component)this).transform);
			}
			_physGrab = ((Component)this).GetComponent<PhysGrabObject>();
			_photonView = ((Component)this).GetComponent<PhotonView>();
			_rb = ((Component)this).GetComponent<Rigidbody>();
			_skinnedRenderers = ((Component)visualRoot).GetComponentsInChildren<SkinnedMeshRenderer>(true);
			_animator = ((Component)visualRoot).GetComponentInChildren<Animator>(true);
			_legacyAnimation = ((Component)visualRoot).GetComponentInChildren<Animation>(true);
			OrangeCatShopPatch.ApplyCatItemAttributes(((Component)this).gameObject);
			int num = LayerMask.NameToLayer("PhysGrabObject");
			if (num >= 0)
			{
				OrangeCatShopPatch.SetLayerRecursively(((Component)this).gameObject, num);
			}
			if ((Object)(object)_photonView != (Object)null)
			{
				_photonView.OwnershipTransfer = (OwnershipOption)1;
			}
			if ((Object)(object)_physGrab != (Object)null)
			{
				((Behaviour)_physGrab).enabled = true;
				if ((Object)(object)_rb != (Object)null)
				{
					_rb.isKinematic = false;
					_physGrab.rb = _rb;
				}
				if (_grabDisableField != null)
				{
					_grabDisableField.SetValue(_physGrab, false);
				}
			}
			PhysGrabObjectCollider[] componentsInChildren = ((Component)this).GetComponentsInChildren<PhysGrabObjectCollider>(true);
			foreach (PhysGrabObjectCollider val2 in componentsInChildren)
			{
				((Behaviour)val2).enabled = true;
				BoxCollider component = ((Component)val2).GetComponent<BoxCollider>();
				if ((Object)(object)component != (Object)null)
				{
					((Collider)component).enabled = true;
					((Collider)component).isTrigger = false;
				}
			}
			_defaultVisualPos = visualRoot.localPosition;
			_defaultVisualRot = visualRoot.localRotation;
			int num2 = LayerMask.NameToLayer("Player");
			int num3 = LayerMask.NameToLayer("Ignore Raycast");
			_navMask = -1;
			if (num >= 0)
			{
				_navMask &= ~(1 << num);
			}
			if (num2 >= 0)
			{
				_navMask &= ~(1 << num2);
			}
			if (num3 >= 0)
			{
				_navMask &= ~(1 << num3);
			}
			currentHp = 350f;
			_lastStuckCheckPos = ((Component)this).transform.position;
			SetupBattleAudioSource();
			DisableSmokeAndItemImpactEffects();
			PickNewWanderOffset();
			CreateWorldHpBar();
			ApplyBuiltInPose(1f);
		}

		private void DisableSmokeAndItemImpactEffects()
		{
			if (_impactDetectorType != null)
			{
				Component componentInChildren = ((Component)this).GetComponentInChildren(_impactDetectorType, true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					FieldInfo fieldInfo = AccessTools.Field(_impactDetectorType, "minImpactForce") ?? AccessTools.Field(_impactDetectorType, "impactForceThreshold");
					if (fieldInfo != null && fieldInfo.FieldType == typeof(float))
					{
						fieldInfo.SetValue(componentInChildren, 99999f);
					}
					FieldInfo[] fields = _impactDetectorType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (FieldInfo fieldInfo2 in fields)
					{
						if (fieldInfo2.FieldType == typeof(float))
						{
							string text = fieldInfo2.Name.ToLowerInvariant();
							if (text.Contains("impact") || text.Contains("threshold") || text.Contains("fragil"))
							{
								fieldInfo2.SetValue(componentInChildren, 99999f);
							}
						}
					}
				}
			}
			ParticleSystem[] componentsInChildren = ((Component)this).GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.Stop(true, (ParticleSystemStopBehavior)0);
				}
			}
			AudioSource[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<AudioSource>(true);
			foreach (AudioSource val2 in componentsInChildren2)
			{
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)_battleAudioSource)
				{
					val2.mute = true;
				}
			}
		}

		private void Start()
		{
			OrangeCatShopPatch.ApplyCatItemAttributes(((Component)this).gameObject);
			ApplyLiftableWeight();
			ApplyBuiltInPose(_isSitting ? 1f : 0f);
			Plugin.StartAudioLoadIfNeeded();
			if ((Object)(object)Plugin.HardstyleClip != (Object)null)
			{
				AttachBattleClip(Plugin.HardstyleClip);
			}
			PollRoomPropertiesSync();
		}

		private void UpdateOwnerFromInteractingPlayer()
		{
			Component val = null;
			if ((Object)(object)_physGrab != (Object)null && _playerGrabbingField != null && _playerGrabbingField.GetValue(_physGrab) is IList { Count: >0 } list)
			{
				object? obj = list[0];
				Component val2 = (Component)((obj is Component) ? obj : null);
				if ((Object)(object)val2 != (Object)null)
				{
					if (_grabberAvatarField != null)
					{
						object? value = _grabberAvatarField.GetValue(val2);
						val = (Component)((value is Component) ? value : null);
					}
					if ((Object)(object)val == (Object)null && _playerAvatarType != null)
					{
						val = val2.GetComponentInParent(_playerAvatarType);
					}
				}
			}
			if ((Object)(object)val == (Object)null && _playerAvatarInstanceField != null)
			{
				object? value2 = _playerAvatarInstanceField.GetValue(null);
				val = (Component)((value2 is Component) ? value2 : null);
			}
			if ((Object)(object)val != (Object)null)
			{
				_ownerAvatarComp = val;
				_targetPlayer = val.transform;
				string text = ExtractPlayerName(val);
				if (!string.IsNullOrWhiteSpace(text))
				{
					SetOwnerName(text);
				}
			}
			else if ((Object)(object)Camera.main != (Object)null)
			{
				_targetPlayer = ((Component)Camera.main).transform;
				if (!string.IsNullOrWhiteSpace(PhotonNetwork.NickName))
				{
					SetOwnerName(PhotonNetwork.NickName);
				}
			}
		}

		private Component GetAnyValidPlayerAvatar()
		{
			if (_playerAvatarType == null)
			{
				return null;
			}
			if ((Object)(object)_ownerAvatarComp != (Object)null && _ownerAvatarComp.gameObject.activeInHierarchy && _playerAvatarType.IsInstanceOfType(_ownerAvatarComp))
			{
				return _ownerAvatarComp;
			}
			_ownerAvatarComp = null;
			if (_playerAvatarInstanceField != null)
			{
				object? value = _playerAvatarInstanceField.GetValue(null);
				Component val = (Component)((value is Component) ? value : null);
				if (val != null && (Object)(object)val != (Object)null && _playerAvatarType.IsInstanceOfType(val))
				{
					_ownerAvatarComp = val;
					return val;
				}
			}
			Object obj = Object.FindObjectOfType(_playerAvatarType);
			Component val2 = (Component)(object)((obj is Component) ? obj : null);
			if ((Object)(object)val2 != (Object)null && _playerAvatarType.IsInstanceOfType(val2))
			{
				_ownerAvatarComp = val2;
				return val2;
			}
			return null;
		}

		private static string ExtractPlayerName(Component avatarComp)
		{
			if ((Object)(object)avatarComp == (Object)null)
			{
				return string.Empty;
			}
			if (_playerNameField != null && _playerNameField.GetValue(avatarComp) is string text && !string.IsNullOrWhiteSpace(text))
			{
				return text.Trim();
			}
			PhotonView componentInParent = avatarComp.GetComponentInParent<PhotonView>();
			if ((Object)(object)componentInParent != (Object)null && componentInParent.Owner != null && !string.IsNullOrWhiteSpace(componentInParent.Owner.NickName))
			{
				return componentInParent.Owner.NickName.Trim();
			}
			return PhotonNetwork.NickName ?? string.Empty;
		}

		private void SetOwnerName(string newName)
		{
			if (!string.IsNullOrWhiteSpace(newName) && !(_ownerName == newName))
			{
				_ownerName = newName;
				if ((Object)(object)_ownerNameText != (Object)null)
				{
					_ownerNameText.text = _ownerName;
					((Component)_ownerNameText).gameObject.SetActive(true);
				}
			}
		}

		private void BroadcastCatStateToRoom()
		{
			if (!PhotonNetwork.InRoom || (Object)(object)_photonView == (Object)null || PhotonNetwork.CurrentRoom == null)
			{
				return;
			}
			try
			{
				int num = 0;
				if ((Object)(object)_ownerAvatarComp != (Object)null)
				{
					PhotonView componentInParent = _ownerAvatarComp.GetComponentInParent<PhotonView>();
					if ((Object)(object)componentInParent != (Object)null)
					{
						num = componentInParent.ViewID;
					}
				}
				string text = (_ownerName ?? string.Empty).Replace("|", " ");
				string key = $"CatState_{_photonView.ViewID}";
				string value = (_lastAppliedRoomState = $"{(_isSitting ? 1 : 0)}|{text}|{num}|{Mathf.RoundToInt(currentHp)}|{(_isSpinAttacking ? 1 : 0)}|{(_isAttackingValuable ? 1 : 0)}|{_shooSequence}");
				Room currentRoom = PhotonNetwork.CurrentRoom;
				MethodInfo methodInfo = ((object)currentRoom).GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public).FirstOrDefault((MethodInfo m) => m.Name == "SetCustomProperties" && m.GetParameters().Length >= 1);
				if (!(methodInfo != null))
				{
					return;
				}
				Type parameterType = methodInfo.GetParameters()[0].ParameterType;
				if (Activator.CreateInstance(parameterType) is IDictionary dictionary)
				{
					dictionary[key] = value;
					ParameterInfo[] parameters = methodInfo.GetParameters();
					object[] array = new object[parameters.Length];
					array[0] = dictionary;
					for (int num2 = 1; num2 < parameters.Length; num2++)
					{
						array[num2] = (parameters[num2].HasDefaultValue ? parameters[num2].DefaultValue : null);
					}
					methodInfo.Invoke(currentRoom, array);
				}
			}
			catch
			{
			}
		}

		private void PollRoomPropertiesSync()
		{
			//IL_0216: 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_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: 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_0223: 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_022d: Unknown result type (might be due to invalid IL or missing references)
			if (!PhotonNetwork.InRoom || (Object)(object)_photonView == (Object)null || PhotonNetwork.CurrentRoom == null)
			{
				return;
			}
			Room currentRoom = PhotonNetwork.CurrentRoom;
			if (!(AccessTools.Property(((object)currentRoom).GetType(), "CustomProperties")?.GetValue(currentRoom) is IDictionary dictionary))
			{
				return;
			}
			string key = $"CatState_{_photonView.ViewID}";
			if (!dictionary.Contains(key) || !(dictionary[key] is string text) || text == _lastAppliedRoomState)
			{
				return;
			}
			_lastAppliedRoomState = text;
			string[] array = text.Split('|');
			if (array.Length < 7)
			{
				return;
			}
			bool isSitting = array[0] == "1";
			string text2 = array[1];
			int.TryParse(array[2], out var result);
			float.TryParse(array[3], out var result2);
			bool isSpinAttacking = array[4] == "1";
			bool isAttackingValuable = array[5] == "1";
			int.TryParse(array[6], out var result3);
			if (!string.IsNullOrWhiteSpace(text2))
			{
				SetOwnerName(text2);
			}
			if (result > 0)
			{
				PhotonView val = PhotonView.Find(result);
				if ((Object)(object)val != (Object)null)
				{
					_targetPlayer = ((Component)val).transform;
					if (_playerAvatarType != null)
					{
						_ownerAvatarComp = ((Component)val).GetComponentInChildren(_playerAvatarType, true) ?? ((Component)val).GetComponentInParent(_playerAvatarType);
					}
				}
			}
			if (result3 != _shooSequence)
			{
				_shooSequence = result3;
				_shooFleeTimer = 2.2f;
				_shooScareOrigin = (((Object)(object)_targetPlayer != (Object)null) ? _targetPlayer.position : (((Component)this).transform.position - ((Component)this).transform.forward));
				_shooTargetPoint = FindOpenFleeDestination(_shooScareOrigin);
				StopBattleMusicImmediate();
			}
			if (!HasSimulationAuthority())
			{
				_isSitting = isSitting;
				currentHp = result2;
				_isSpinAttacking = isSpinAttacking;
				_isAttackingValuable = isAttackingValuable;
				if (_isSitting)
				{
					StopBattleMusicImmediate();
				}
			}
		}

		private void SetupBattleAudioSource()
		{
			if (!((Object)(object)_battleAudioSource != (Object)null))
			{
				_battleAudioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
				_battleAudioSource.playOnAwake = false;
				_battleAudioSource.loop = true;
				_battleAudioSource.volume = 0f;
				_battleAudioSource.spatialBlend = 0.85f;
				_battleAudioSource.rolloffMode = (AudioRolloffMode)1;
				_battleAudioSource.minDistance = 3f;
				_battleAudioSource.maxDistance = 20f;
				_battleAudioSource.dopplerLevel = 0f;
				if ((Object)(object)Plugin.HardstyleClip != (Object)null)
				{
					_battleAudioSource.clip = Plugin.HardstyleClip;
				}
			}
		}

		public void AttachBattleClip(AudioClip clip)
		{
			if ((Object)(object)_battleAudioSource == (Object)null)
			{
				SetupBattleAudioSource();
			}
			if ((Object)(object)_battleAudioSource != (Object)null && (Object)(object)clip != (Object)null)
			{
				_battleAudioSource.clip = clip;
			}
		}

		private void StopBattleMusicImmediate()
		{
			_combatAngryTimer = 0f;
			_valuableMusicTimer = 0f;
			if ((Object)(object)_battleAudioSource != (Object)null)
			{
				if (_battleAudioSource.isPlaying)
				{
					_battleAudioSource.Stop();
				}
				_battleAudioSource.volume = 0f;
			}
		}

		private void UpdateBattleMusic()
		{
			if ((Object)(object)_battleAudioSource == (Object)null)
			{
				return;
			}
			if ((Object)(object)_battleAudioSource.clip == (Object)null && (Object)(object)Plugin.HardstyleClip != (Object)null)
			{
				_battleAudioSource.clip = Plugin.HardstyleClip;
			}
			if ((Object)(object)_battleAudioSource.clip == (Object)null)
			{
				return;
			}
			if (_isSitting || currentHp < 50f || _shooFleeTimer > 0f || IsGrabbedByAnyone())
			{
				StopBattleMusicImmediate();
				return;
			}
			bool flag = _isSpinAttacking && (Object)(object)_nearestEnemy != (Object)null && _nearestEnemy.gameObject.activeInHierarchy;
			bool flag2 = _isAttackingValuable && (Object)(object)_targetValuable != (Object)null && _targetValuable.gameObject.activeInHierarchy;
			if (flag)
			{
				_combatAngryTimer = 2.5f;
			}
			else if (_combatAngryTimer > 0f)
			{
				_combatAngryTimer -= Time.deltaTime;
			}
			if (flag2)
			{
				_valuableMusicTimer = 3.5f;
			}
			else if (_valuableMusicTimer > 0f)
			{
				_valuableMusicTimer -= Time.deltaTime;
			}
			if (flag || flag2 || _combatAngryTimer > 0f || _valuableMusicTimer > 0f)
			{
				if (!_battleAudioSource.isPlaying)
				{
					_battleAudioSource.Play();
				}
				_battleAudioSource.volume = Mathf.MoveTowards(_battleAudioSource.volume, 0.22f, Time.deltaTime * 4f);
			}
			else if (_battleAudioSource.isPlaying)
			{
				_battleAudioSource.volume = Mathf.MoveTowards(_battleAudioSource.volume, 0f, Time.deltaTime * 3.5f);
				if (_battleAudioSource.volume <= 0.002f)
				{
					_battleAudioSource.Stop();
					_battleAudioSource.volume = 0f;
				}
			}
		}

		private void CreateWorldHpBar()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_006e: 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_0090: Expected O, but got Unknown
			//IL_00b8: 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_018b: 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_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Expected O, but got Unknown
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: 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_01e1: Expected O, but got Unknown
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Expected O, but got Unknown
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_hpBarRoot != (Object)null))
			{
				Shader val = Shader.Find("Sprites/Default");
				if ((Object)(object)val == (Object)null)
				{
					val = Shader.Find("Unlit/Color");
				}
				GameObject val2 = new GameObject("CatHpBarRoot");
				val2.transform.SetParent(((Component)this).transform, false);
				val2.transform.localPosition = new Vector3(0f, 0.48f, 0f);
				_hpBarRoot = val2.transform;
				GameObject val3 = new GameObject("CatOwnerName");
				val3.transform.SetParent(_hpBarRoot, false);
				val3.transform.localPosition = new Vector3(0f, 0.042f, 0f);
				_ownerNameText = val3.AddComponent<TextMesh>();
				_ownerNameText.text = string.Empty;
				_ownerNameText.fontSize = 32;
				_ownerNameText.characterSize = 0.017f;
				_ownerNameText.anchor = (TextAnchor)7;
				_ownerNameText.alignment = (TextAlignment)1;
				_ownerNameText.fontStyle = (FontStyle)1;
				_ownerNameText.color = new Color(1f, 0.96f, 0.85f, 0.95f);
				val3.SetActive(false);
				GameObject val4 = GameObject.CreatePrimitive((PrimitiveType)5);
				((Object)val4).name = "HpBarBg";
				Object.DestroyImmediate((Object)(object)val4.GetComponent<Collider>());
				val4.transform.SetParent(_hpBarRoot, false);
				val4.transform.localPosition = Vector3.zero;
				val4.transform.localScale = new Vector3(0.48f, 0.058f, 1f);
				MeshRenderer component = val4.GetComponent<MeshRenderer>();
				if ((Object)(object)component != (Object)null && (Object)(object)val != (Object)null)
				{
					Material val5 = new Material(val);
					val5.color = new Color(0.08f, 0.08f, 0.08f, 0.85f);
					((Renderer)component).material = val5;
				}
				GameObject val6 = new GameObject("HpBarFillPivot");
				val6.transform.SetParent(_hpBarRoot, false);
				val6.transform.localPosition = new Vector3(-0.225f, 0f, -0.005f);
				_hpBarFillPivot = val6.transform;
				GameObject val7 = GameObject.CreatePrimitive((PrimitiveType)5);
				((Object)val7).name = "HpBarFill";
				Object.DestroyImmediate((Object)(object)val7.GetComponent<Collider>());
				val7.transform.SetParent(_hpBarFillPivot, false);
				val7.transform.localPosition = new Vector3(0.225f, 0f, 0f);
				val7.transform.localScale = new Vector3(0.45f, 0.038f, 1f);
				_hpBarFillRenderer = val7.GetComponent<MeshRenderer>();
				if ((Object)(object)_hpBarFillRenderer != (Object)null && (Object)(object)val != (Object)null)
				{
					_hpBarFillMat = new Material(val);
					_hpBarFillMat.color = new Color(0.2f, 0.92f, 0.35f, 0.95f);
					((Renderer)_hpBarFillRenderer).material = _hpBarFillMat;
				}
			}
		}

		private void UpdateWorldHpBar()
		{
			//IL_0034: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_hpBarRoot == (Object)null)
			{
				return;
			}
			Camera main = Camera.main;
			if ((Object)(object)main != (Object)null)
			{
				_hpBarRoot.rotation = Quaternion.LookRotation(_hpBarRoot.position - ((Component)main).transform.position, Vector3.up);
			}
			float num = Mathf.Clamp01(currentHp / 350f);
			if ((Object)(object)_hpBarFillPivot != (Object)null)
			{
				_hpBarFillPivot.localScale = new Vector3(Mathf.Max(0.001f, num), 1f, 1f);
			}
			if ((Object)(object)_hpBarFillMat != (Object)null)
			{
				if (_isSitting && currentHp < 350f)
				{
					_hpBarFillMat.color = new Color(0.25f, 0.8f, 1f, 0.95f);
				}
				else if (currentHp < 50f)
				{
					_hpBarFillMat.color = new Color(1f, 0.25f, 0.12f, 0.95f);
				}
				else
				{
					_hpBarFillMat.color = new Color(0.2f, 0.92f, 0.35f, 0.95f);
				}
			}
		}

		private void ApplyLiftableWeight()
		{
			if ((Object)(object)_rb != (Object)null)
			{
				_rb.mass = 2f;
				_rb.drag = 0.8f;
				_rb.angularDrag = 2.5f;
			}
		}

		private Quaternion GetUprightRotation()
		{
			//IL_0007: 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)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_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_006b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.ProjectOnPlane(((Component)this).transform.forward, Vector3.up);
			if (((Vector3)(ref val)).sqrMagnitude < 0.001f)
			{
				val = Vector3.ProjectOnPlane(((Component)this).transform.up, Vector3.up);
			}
			if (((Vector3)(ref val)).sqrMagnitude < 0.001f)
			{
				val = Vector3.forward;
			}
			return Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up);
		}

		private void SampleGroundSurface()
		{
			//IL_0007: 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)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)this).transform.position + Vector3.up * 0.25f;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.SphereCast(val, 0.14f, Vector3.down, ref val2, 0.55f, _navMask, (QueryTriggerInteraction)1))
			{
				_isGrounded = true;
				_groundNormal = ((Vector3.Angle(((RaycastHit)(ref val2)).normal, Vector3.up) <= 52f) ? ((RaycastHit)(ref val2)).normal : Vector3.up);
			}
			else
			{
				_isGrounded = false;
				_groundNormal = Vector3.up;
			}
		}

		private Quaternion GetSlopeAlignedRotation(Vector3 desiredForward)
		{
			//IL_0011: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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)
			Vector3 val = (_isGrounded ? _groundNormal : Vector3.up);
			Vector3 val2 = Vector3.ProjectOnPlane(desiredForward, val);
			if (((Vector3)(ref val2)).sqrMagnitude < 0.001f)
			{
				val2 = Vector3.ProjectOnPlane(((Component)this).transform.forward, val);
			}
			if (((Vector3)(ref val2)).sqrMagnitude < 0.001f)
			{
				val2 = Vector3.forward;
			}
			return Quaternion.LookRotation(((Vector3)(ref val2)).normalized, val);
		}

		private Vector3 ProjectMoveOntoSlope(Vector3 flatDir, float speed)
		{
			//IL_0036: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_002e: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: 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)
			if (!_isGrounded)
			{
				return new Vector3(flatDir.x * speed, _rb.velocity.y, flatDir.z * speed);
			}
			Vector3 val = Vector3.ProjectOnPlane(flatDir, _groundNormal);
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			float num = normalized.y * speed;
			num = ((!(normalized.y < -0.05f)) ? Mathf.Max(_rb.velocity.y, num) : Mathf.Min(num, -1.2f));
			return new Vector3(normalized.x * speed, num, normalized.z * speed);
		}

		private void SmoothSetPlanarVelocity(Vector3 targetVel, float accel = 18f)
		{
			//IL_0007: 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)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_002c: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 velocity = _rb.velocity;
			float num = Mathf.Lerp(velocity.x, targetVel.x, Time.fixedDeltaTime * accel);
			float num2 = Mathf.Lerp(velocity.z, targetVel.z, Time.fixedDeltaTime * accel);
			_rb.velocity = new Vector3(num, targetVel.y, num2);
		}

		private void TrySmartStepJump(Vector3 moveDir)
		{
			//IL_0041: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_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_00bd: 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_00da: 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_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			if (!_isGrounded || Time.time < _nextJumpAllowedTime || _unstuckBackoffTimer > 0f || (Object)(object)_rb == (Object)null)
			{
				return;
			}
			Vector3 val = ((Component)this).transform.position + Vector3.up * 0.14f;
			Vector3 val2 = ((Component)this).transform.position + Vector3.up * 0.52f;
			RaycastHit val3 = default(RaycastHit);
			if (Physics.Raycast(val, moveDir, ref val3, 0.58f, _navMask, (QueryTriggerInteraction)1))
			{
				float num = Vector3.Angle(((RaycastHit)(ref val3)).normal, Vector3.up);
				if (num > 58f && !Physics.Raycast(val2, moveDir, 0.68f, _navMask, (QueryTriggerInteraction)1) && HasGroundAhead(moveDir, 0.72f))
				{
					_nextJumpAllowedTime = Time.time + 0.95f;
					Vector3 velocity = _rb.velocity;
					_rb.velocity = new Vector3(velocity.x, 3.6f, velocity.z);
				}
			}
		}

		private void PickNewWanderOffset()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			float num = Random.Range(0f, 360f) * (MathF.PI / 180f);
			float num2 = Random.Range(1.3f, 2.9f);
			_wanderOffset = new Vector3(Mathf.Cos(num) * num2, 0f, Mathf.Sin(num) * num2);
			_nextWanderPickTime = Time.time + Random.Range(2.2f, 4.2f);
		}

		private bool HasLineOfSight(Vector3 targetWorldPos, Transform ignoreRoot = null)
		{
			//IL_0007: 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)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0037: 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)
			Vector3 val = ((Component)this).transform.position + Vector3.up * 0.35f;
			Vector3 val2 = targetWorldPos + Vector3.up * 0.35f;
			RaycastHit val3 = default(RaycastHit);
			if (Physics.Linecast(val, val2, ref val3, _navMask, (QueryTriggerInteraction)1))
			{
				if ((Object)(object)((RaycastHit)(ref val3)).transform == (Object)(object)((Component)this).transform || ((RaycastHit)(ref val3)).transform.IsChildOf(((Component)this).transform))
				{
					return true;
				}
				if ((Object)(object)ignoreRoot != (Object)null && ((Object)(object)((RaycastHit)(ref val3)).transform == (Object)(object)ignoreRoot || ((RaycastHit)(ref val3)).transform.IsChildOf(ignoreRoot)))
				{
					return true;
				}
				if ((Object)(object)((RaycastHit)(ref val3)).rigidbody != (Object)null)
				{
					return true;
				}
				return false;
			}
			return true;
		}

		private bool HasGroundAhead(Vector3 flatDir, float checkDistance)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			flatDir.y = 0f;
			if (((Vector3)(ref flatDir)).sqrMagnitude < 0.001f)
			{
				return true;
			}
			((Vector3)(ref flatDir)).Normalize();
			Vector3 val = ((Component)this).transform.position + flatDir * checkDistance + Vector3.up * 0.65f;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(val, Vector3.down, ref val2, 1.95f, _navMask, (QueryTriggerInteraction)1))
			{
				return ((RaycastHit)(ref val2)).point.y >= ((Component)this).transform.position.y - 1.15f;
			}
			return false;
		}

		private Vector3 FindOpenFleeDestination(Vector3 scareOrigin)
		{
			//IL_0007: 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)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a5: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: 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_00c7: 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_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)this).transform.position - scareOrigin;
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude < 0.001f)
			{
				val = -((Component)this).transform.forward;
			}
			((Vector3)(ref val)).Normalize();
			Vector3 val2 = ((Component)this).transform.position + Vector3.up * 0.32f;
			float num = 7.5f;
			Vector3 val3 = val;
			float num2 = -999f;
			RaycastHit val5 = default(RaycastHit);
			for (int i = 0; i < 12; i++)
			{
				float num3 = (float)i * 30f;
				Vector3 val4 = Quaternion.Euler(0f, num3, 0f) * Vector3.forward;
				if (HasGroundAhead(val4, 0.9f))
				{
					float num4 = num;
					if (Physics.SphereCast(val2, 0.22f, val4, ref val5, num, _navMask, (QueryTriggerInteraction)1))
					{
						num4 = Mathf.Max(0f, ((RaycastHit)(ref val5)).distance - 0.35f);
					}
					float num5 = Vector3.Dot(val4, val);
					float num6 = num4 * 1.4f + num5 * 2.8f;
					if (num6 > num2)
					{
						num2 = num6;
						val3 = val4;
					}
				}
			}
			float num7 = 4.5f;
			RaycastHit val6 = default(RaycastHit);
			if (Physics.SphereCast(val2, 0.22f, val3, ref val6, num7, _navMask, (QueryTriggerInteraction)1))
			{
				num7 = Mathf.Max(1f, ((RaycastHit)(ref val6)).distance - 0.45f);
			}
			return ((Component)this).transform.position + val3 * num7;
		}

		private Rigidbody FindNearbyClosedInteractable(out Component hingeComp, out Vector3 closedPos, out Quaternion closedRot)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type