Decompiled source of Yerbisius v0.3.10

plugins/Yerbisius/Yerbisius.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using ExitGames.Client.Photon;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace YerbisiusMod;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("woopsy.yerbisius", "Yerbisius", "0.3.10")]
public sealed class Plugin : BaseUnityPlugin, IOnEventCallback
{
	private const string RoomKey = "woopsy.yerbisius.state.v16";

	private const string HitKey = "woopsy.yerbisius.hit.v16";

	private const string HitMarker = "woopsy.yerbisius.hit.request.v16";

	private const byte HitEvent = 179;

	private const string WaveKey = "woopsy.yerbisius.waves.v16";

	private const float NpcScale = 1.03f;

	private const float RightOffset = 2.1f;

	private const float ForwardOffset = 0.65f;

	private const float FacingOffset = 0f;

	private string localWaves;

	private int? lastCurrency;

	private MethodInfo currencyGetter;

	private Harmony waveHarmony;

	private static Plugin waveOwner;

	private bool currencyWarning;

	private double lastHit = double.NaN;

	private float nextHitRequest;

	private string localHit;

	private bool callbackRegistered;

	private ConfigEntry<bool> show;

	private ConfigEntry<bool> wave;

	private ConfigEntry<bool> names;

	private ConfigEntry<bool> dance;

	private ConfigEntry<int> volume;

	private bool valuableRegistered;

	private bool valuableFailed;

	private static Plugin damageOwner;

	private Harmony damageHarmony;

	private Harmony impactHarmony;

	private static Plugin impactOwner;

	private static FieldInfo nativeImpactFlag;

	private readonly Random valuableVoiceRandom = new Random();

	private Object figurineValuePreset;

	private MethodInfo damageMethod;

	private int damageValueIndex = -1;

	private int damageFlagIndex = -1;

	private bool damageWarning;

	private float nextValuableScan;

	private GameObject valuableTemplates;

	private AssetBundle bundle;

	private GameObject prefab;

	private GameObject shopPrefab;

	private GameObject npc;

	private GameObject tag;

	private AudioClip clip;

	private AudioClip[] dialogue;

	private NPCDriver driver;

	private Component anchor;

	private Type radioType;

	private Type shopType;

	private Type runType;

	private MethodInfo isShopMethod;

	private float nextScan;

	private float readyAt;

	private float nextWarning;

	private float nextPublish;

	private float nextFont;

	private string published;

	private string applied;

	private int localVisit = int.MinValue;

	private object lastRoom;

	private bool wasShop;

	private bool wasHost;

	private TextMeshPro nameText;

	private static readonly CultureInfo CI = CultureInfo.InvariantCulture;

	internal static double Clock
	{
		get
		{
			if (!PhotonNetwork.InRoom || PhotonNetwork.OfflineMode)
			{
				return Time.unscaledTime;
			}
			return PhotonNetwork.Time;
		}
	}

	private bool Networked
	{
		get
		{
			if (PhotonNetwork.InRoom)
			{
				return !PhotonNetwork.OfflineMode;
			}
			return false;
		}
	}

	private bool Host
	{
		get
		{
			if (Networked)
			{
				return PhotonNetwork.IsMasterClient;
			}
			return true;
		}
	}

	private void Awake()
	{
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Expected O, but got Unknown
		show = ((BaseUnityPlugin)this).Config.Bind<bool>("NPC", "Enabled", true, "Host setting: spawn Yerbisius in the shop for all players with the mod.");
		wave = ((BaseUnityPlugin)this).Config.Bind<bool>("NPC", "Wave Animation", true, "Host setting: greeting, purchase waves and rare idle waves; applied next shop visit.");
		names = ((BaseUnityPlugin)this).Config.Bind<bool>("NPC", "Name Display", true, "Local setting: show the overhead name when looking at him.");
		dance = ((BaseUnityPlugin)this).Config.Bind<bool>("NPC", "Dance Animation", true, "Host setting: synchronized occasional dance, applied next shop visit.");
		volume = ((BaseUnityPlugin)this).Config.Bind<int>("Voice", "Voice Volume", 100, new ConfigDescription("Local positional voice volume percent.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), new object[0]));
		radioType = AccessTools.TypeByName("ShopRadio");
		shopType = AccessTools.TypeByName("ShopManager");
		runType = AccessTools.TypeByName("RunManager");
		Type type = AccessTools.TypeByName("SemiFunc");
		if (type != null)
		{
			isShopMethod = AccessTools.Method(type, "RunIsShop", Type.EmptyTypes, (Type[])null);
		}
		if (radioType == null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"ShopRadio type not found; NPC disabled.");
			((Behaviour)this).enabled = false;
			return;
		}
		bundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "yerbisiusassets"));
		if (!Object.op_Implicit((Object)(object)bundle))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Cannot load yerbisiusassets.");
			((Behaviour)this).enabled = false;
			return;
		}
		prefab = bundle.LoadAsset<GameObject>("yerbisius");
		shopPrefab = bundle.LoadAsset<GameObject>("yerbisius_shop");
		if (!Object.op_Implicit((Object)(object)shopPrefab))
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"Shop leg rig unavailable; using intact original model.");
		}
		clip = bundle.LoadAsset<AudioClip>("voice");
		if (!Object.op_Implicit((Object)(object)prefab) || !Object.op_Implicit((Object)(object)clip))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Asset bundle missing prefab or voice.");
			((Behaviour)this).enabled = false;
			return;
		}
		clip.LoadAudioData();
		dialogue = (AudioClip[])(object)new AudioClip[9];
		dialogue[0] = clip;
		for (int i = 1; i < dialogue.Length; i++)
		{
			dialogue[i] = bundle.LoadAsset<AudioClip>("dialogue_" + i);
			if (Object.op_Implicit((Object)(object)dialogue[i]))
			{
				dialogue[i].LoadAudioData();
			}
			else if (i <= 3 || i == 5 || i == 7 || i == 8)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Missing required dialogue_" + i + "; rebuild using the supplied WAVs."));
				((Behaviour)this).enabled = false;
				return;
			}
		}
		InstallValuableDamageVoice();
		InstallShopHitHooks();
		InstallPurchaseWave();
		TryRegisterValuable();
		PhotonNetwork.AddCallbackTarget((object)this);
		callbackRegistered = true;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Yerbisius 0.3.10 ready; host placement and shared timeline enabled.");
	}

	private void InstallPurchaseWave()
	{
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Expected O, but got Unknown
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Expected O, but got Unknown
		try
		{
			Type type = AccessTools.TypeByName("SemiFunc");
			currencyGetter = ((type == null) ? null : AccessTools.Method(type, "StatGetRunCurrency", Type.EmptyTypes, (Type[])null));
			if (currencyGetter == null || !currencyGetter.IsStatic || currencyGetter.ReturnType != typeof(int))
			{
				currencyGetter = null;
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Yerbisius: shop purchase wave unavailable; currency API not found.");
				return;
			}
			waveOwner = this;
			waveHarmony = new Harmony("woopsy.yerbisius.purchasewave");
			HarmonyMethod val = new HarmonyMethod(typeof(Plugin), "CurrencyChangedPostfix", (Type[])null);
			MethodInfo methodInfo = AccessTools.Method(type, "StatSetRunCurrency", new Type[1] { typeof(int) }, (Type[])null);
			if (methodInfo != null)
			{
				waveHarmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			Type type2 = AccessTools.TypeByName("PunManager");
			MethodInfo methodInfo2 = ((type2 == null) ? null : AccessTools.Method(type2, "SetRunStatSet", new Type[2]
			{
				typeof(string),
				typeof(int)
			}, (Type[])null));
			if (methodInfo2 != null)
			{
				waveHarmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Yerbisius purchase waves: native currency observer ready.");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Yerbisius purchase wave hook: " + ex.Message + "; balance polling remains available if getter was found."));
		}
	}

	public static void CurrencyChangedPostfix()
	{
		Plugin plugin = waveOwner;
		if (Object.op_Implicit((Object)(object)plugin))
		{
			plugin.ObserveShopCurrency();
		}
	}

	private void ObserveShopCurrency()
	{
		if (!Host || !wasShop || !Object.op_Implicit((Object)(object)anchor) || !Object.op_Implicit((Object)(object)driver) || currencyGetter == null || string.IsNullOrEmpty(applied))
		{
			lastCurrency = null;
			return;
		}
		try
		{
			int num = (int)currencyGetter.Invoke(null, null);
			if (num >= 0)
			{
				int? num2 = lastCurrency;
				lastCurrency = num;
				if (num2.HasValue && num < num2.Value)
				{
					QueuePurchaseWave();
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Yerbisius purchase wave queued: shop currency " + num2.Value + " -> " + num));
				}
			}
		}
		catch (Exception ex)
		{
			if (!currencyWarning)
			{
				currencyWarning = true;
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Yerbisius purchase wave currency read failed: " + ex.Message));
			}
		}
	}

	private string ReadWaves()
	{
		if (!Networked)
		{
			return localWaves;
		}
		if (!((Dictionary<object, object>)(object)((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties).TryGetValue((object)"woopsy.yerbisius.waves.v16", out object value))
		{
			return null;
		}
		return value as string;
	}

	private void QueuePurchaseWave()
	{
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Expected O, but got Unknown
		double now = driver.VisitElapsed;
		string text = localWaves;
		if (string.IsNullOrEmpty(text))
		{
			text = ReadWaves();
		}
		List<double> list = NPCDriver.DecodeWaves(text, applied);
		list.RemoveAll((double t) => t + (double)driver.PurchaseDuration < now - 2.0);
		double num = Math.Max(now + (Networked ? 0.35 : 0.05), 1.5 + (double)driver.WaveDuration + 0.15);
		if (list.Count > 0)
		{
			num = Math.Max(num, list[list.Count - 1] + (double)driver.PurchaseDuration + 0.15);
		}
		list.Add(num);
		List<string> list2 = new List<string>();
		foreach (double item in list)
		{
			list2.Add(item.ToString("R", CI));
		}
		localWaves = applied + "|" + string.Join(",", list2.ToArray());
		driver.SetPurchaseWaves(localWaves, applied);
		if (Networked)
		{
			Hashtable val = new Hashtable();
			val[(object)"woopsy.yerbisius.waves.v16"] = localWaves;
			PhotonNetwork.CurrentRoom.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
		}
	}

	private void InstallShopHitHooks()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Expected O, but got Unknown
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Expected O, but got Unknown
		//IL_01b0: Expected O, but got Unknown
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Expected O, but got Unknown
		impactOwner = this;
		impactHarmony = new Harmony("woopsy.yerbisius.shophits");
		try
		{
			Type type = AccessTools.TypeByName("AssetManager");
			MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "PhysImpactEffect", new Type[1] { typeof(Vector3) }, (Type[])null));
			if (methodInfo == null)
			{
				throw new InvalidOperationException("PhysImpactEffect(Vector3) not found.");
			}
			impactHarmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "NativeImpactPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Yerbisius: native impact spark observer installed.");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Yerbisius spark hook unavailable: " + ex.Message));
		}
		try
		{
			Type type2 = AccessTools.TypeByName("PhysGrabObjectImpactDetector");
			if (type2 == null)
			{
				throw new InvalidOperationException("Impact detector type not found.");
			}
			nativeImpactFlag = AccessTools.Field(type2, "impactHappened");
			if (nativeImpactFlag != null && nativeImpactFlag.FieldType != typeof(bool))
			{
				nativeImpactFlag = null;
			}
			int num = 0;
			string[] array = new string[2] { "OnCollisionEnter", "OnCollisionStay" };
			foreach (string text in array)
			{
				MethodInfo methodInfo2 = AccessTools.Method(type2, text, new Type[1] { typeof(Collision) }, (Type[])null);
				if (!(methodInfo2 == null))
				{
					try
					{
						impactHarmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(Plugin), "NativeCollisionPrefix", (Type[])null), new HarmonyMethod(typeof(Plugin), "NativeCollisionPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						num++;
					}
					catch (Exception ex2)
					{
						((BaseUnityPlugin)this).Logger.LogWarning((object)("Yerbisius native collision hook skipped " + text + ": " + ex2.Message));
					}
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Yerbisius: native collision observers=" + num + ", impact flag=" + (nativeImpactFlag != null) + "; direct hard-contact fallback enabled."));
		}
		catch (Exception ex3)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Yerbisius native collision observer unavailable: " + ex3.Message + "; direct hard-contact fallback enabled."));
		}
		try
		{
			Type type3 = AccessTools.TypeByName("ItemGun");
			if (type3 == null)
			{
				return;
			}
			MethodInfo[] methods = type3.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			MethodInfo[] array2 = methods;
			foreach (MethodInfo methodInfo3 in array2)
			{
				string name = methodInfo3.Name;
				if (methodInfo3.GetMethodBody() != null && (name.StartsWith("Shoot", StringComparison.Ordinal) || name.StartsWith("Bullet", StringComparison.Ordinal)))
				{
					try
					{
						impactHarmony.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "ObserveGunRaycasts", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
					}
					catch (Exception ex4)
					{
						((BaseUnityPlugin)this).Logger.LogDebug((object)("Yerbisius gun observer skipped " + name + ": " + ex4.Message));
					}
				}
			}
		}
		catch (Exception ex5)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Yerbisius gun hook unavailable: " + ex5.Message));
		}
	}

	public static void NativeImpactPostfix(Vector3 __0)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		Plugin plugin = impactOwner;
		if (Object.op_Implicit((Object)(object)plugin) && Object.op_Implicit((Object)(object)plugin.driver) && plugin.wasShop && plugin.driver.MatchesImpact(__0))
		{
			plugin.ReportHit();
		}
	}

	public static void NativeCollisionPrefix(Component __instance, Collision __0, out bool __state)
	{
		__state = true;
		Plugin plugin = impactOwner;
		if (!Object.op_Implicit((Object)(object)plugin) || !Object.op_Implicit((Object)(object)plugin.driver) || !plugin.wasShop || !Object.op_Implicit((Object)(object)__instance) || __0 == null)
		{
			return;
		}
		try
		{
			if (plugin.driver.TouchesSolid(__0))
			{
				if (nativeImpactFlag != null)
				{
					__state = (bool)nativeImpactFlag.GetValue(__instance);
				}
				plugin.driver.ObserveHardContact(__0, __instance);
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)plugin).Logger.LogDebug((object)("Yerbisius native contact observer: " + ex.Message));
		}
	}

	public static void NativeCollisionPostfix(Component __instance, Collision __0, bool __state)
	{
		Plugin plugin = impactOwner;
		if (!Object.op_Implicit((Object)(object)plugin) || !Object.op_Implicit((Object)(object)plugin.driver) || !plugin.wasShop || !Object.op_Implicit((Object)(object)__instance) || __0 == null || __state || nativeImpactFlag == null)
		{
			return;
		}
		try
		{
			if (plugin.driver.TouchesSolid(__0) && (bool)nativeImpactFlag.GetValue(__instance))
			{
				plugin.ReportHit();
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)plugin).Logger.LogDebug((object)("Yerbisius native impact observer: " + ex.Message));
		}
	}

	public static IEnumerable<CodeInstruction> ObserveGunRaycasts(IEnumerable<CodeInstruction> instructions)
	{
		foreach (CodeInstruction instruction in instructions)
		{
			MethodInfo original = instruction.operand as MethodInfo;
			if (original != null && original.DeclaringType == typeof(Physics) && original.Name == "Raycast" && original.ReturnType == typeof(bool))
			{
				ParameterInfo[] parameters = original.GetParameters();
				Type[] array = new Type[parameters.Length];
				for (int i = 0; i < parameters.Length; i++)
				{
					array[i] = parameters[i].ParameterType;
				}
				MethodInfo methodInfo = AccessTools.Method(typeof(Plugin), "ObservedRaycast", array, (Type[])null);
				if (methodInfo != null)
				{
					instruction.operand = methodInfo;
					instruction.opcode = OpCodes.Call;
				}
			}
			yield return instruction;
		}
	}

	private static bool ObserveRayResult(bool result, RaycastHit hit)
	{
		Plugin plugin = impactOwner;
		if (result && Object.op_Implicit((Object)(object)plugin) && Object.op_Implicit((Object)(object)plugin.driver) && plugin.wasShop && plugin.driver.IsSolidHit(((RaycastHit)(ref hit)).collider))
		{
			plugin.ReportHit();
		}
		return result;
	}

	public static bool ObservedRaycast(Vector3 origin, Vector3 direction, out RaycastHit hit, float distance, int mask, QueryTriggerInteraction query)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//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_0010: Unknown result type (might be due to invalid IL or missing references)
		bool result = Physics.Raycast(origin, direction, ref hit, distance, mask, query);
		return ObserveRayResult(result, hit);
	}

	public static bool ObservedRaycast(Vector3 origin, Vector3 direction, out RaycastHit hit, float distance, int mask)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: 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)
		bool result = Physics.Raycast(origin, direction, ref hit, distance, mask);
		return ObserveRayResult(result, hit);
	}

	public static bool ObservedRaycast(Vector3 origin, Vector3 direction, out RaycastHit hit, float distance)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: 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)
		bool result = Physics.Raycast(origin, direction, ref hit, distance);
		return ObserveRayResult(result, hit);
	}

	public static bool ObservedRaycast(Vector3 origin, Vector3 direction, out RaycastHit hit)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		bool result = Physics.Raycast(origin, direction, ref hit);
		return ObserveRayResult(result, hit);
	}

	public static bool ObservedRaycast(Ray ray, out RaycastHit hit, float distance, int mask, QueryTriggerInteraction query)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		bool result = Physics.Raycast(ray, ref hit, distance, mask, query);
		return ObserveRayResult(result, hit);
	}

	public static bool ObservedRaycast(Ray ray, out RaycastHit hit, float distance, int mask)
	{
		//IL_0000: 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)
		bool result = Physics.Raycast(ray, ref hit, distance, mask);
		return ObserveRayResult(result, hit);
	}

	public static bool ObservedRaycast(Ray ray, out RaycastHit hit, float distance)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		bool result = Physics.Raycast(ray, ref hit, distance);
		return ObserveRayResult(result, hit);
	}

	public static bool ObservedRaycast(Ray ray, out RaycastHit hit)
	{
		//IL_0000: 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)
		bool result = Physics.Raycast(ray, ref hit);
		return ObserveRayResult(result, hit);
	}

	private void InstallValuableDamageVoice()
	{
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Expected O, but got Unknown
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Expected O, but got Unknown
		try
		{
			Type type = AccessTools.TypeByName("PhysGrabObjectImpactDetector");
			if (type == null)
			{
				throw new InvalidOperationException("Impact detector type not found.");
			}
			MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo.Name != "BreakRPC")
				{
					continue;
				}
				int num = -1;
				int num2 = -1;
				ParameterInfo[] parameters = methodInfo.GetParameters();
				for (int j = 0; j < parameters.Length; j++)
				{
					ParameterInfo parameterInfo = parameters[j];
					string text = parameterInfo.Name.TrimStart('_');
					if (parameterInfo.ParameterType == typeof(float) && text.Equals("valueLost", StringComparison.OrdinalIgnoreCase))
					{
						num = j;
					}
					if (parameterInfo.ParameterType == typeof(bool) && text.Equals("loseValue", StringComparison.OrdinalIgnoreCase))
					{
						num2 = j;
					}
				}
				if (num >= 0 && num2 >= 0)
				{
					damageMethod = methodInfo;
					damageValueIndex = num;
					damageFlagIndex = num2;
					break;
				}
			}
			if (damageMethod == null)
			{
				throw new InvalidOperationException("Compatible BreakRPC signature not found.");
			}
			damageHarmony = new Harmony("woopsy.yerbisius.valuablevoice");
			damageOwner = this;
			damageHarmony.Patch((MethodBase)damageMethod, new HarmonyMethod(typeof(Plugin), "ValuableDamagePrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Yerbisius figurine damage voice hook installed.");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Yerbisius damage voice unavailable; native valuables unaffected: " + ex.Message));
		}
	}

	public static void ValuableDamagePrefix(Component __instance, object[] __args)
	{
		Plugin plugin = damageOwner;
		if (!Object.op_Implicit((Object)(object)plugin) || !Object.op_Implicit((Object)(object)__instance) || __args == null || !Object.op_Implicit((Object)(object)plugin.clip))
		{
			return;
		}
		try
		{
			if (plugin.damageValueIndex < 0 || plugin.damageFlagIndex < 0 || __args.Length <= Math.Max(plugin.damageValueIndex, plugin.damageFlagIndex) || !(__args[plugin.damageFlagIndex] is bool) || !(bool)__args[plugin.damageFlagIndex] || !(__args[plugin.damageValueIndex] is float) || (float)__args[plugin.damageValueIndex] <= 0f)
			{
				return;
			}
			FigurineDamageVoice componentInParent = __instance.GetComponentInParent<FigurineDamageVoice>();
			if (!Object.op_Implicit((Object)(object)componentInParent) || !((Component)componentInParent).gameObject.activeInHierarchy || Time.unscaledTime < componentInParent.NextVoice)
			{
				return;
			}
			List<AudioClip> list = new List<AudioClip>();
			int[] array = new int[3] { 0, 3, 7 };
			foreach (int num in array)
			{
				if (Object.op_Implicit((Object)(object)plugin.dialogue[num]))
				{
					list.Add(plugin.dialogue[num]);
				}
			}
			if (list.Count == 0)
			{
				return;
			}
			int num2;
			if (list.Count > 1 && componentInParent.LastVoiceIndex >= 0 && componentInParent.LastVoiceIndex < list.Count)
			{
				num2 = plugin.valuableVoiceRandom.Next(list.Count - 1);
				if (num2 >= componentInParent.LastVoiceIndex)
				{
					num2++;
				}
			}
			else
			{
				num2 = plugin.valuableVoiceRandom.Next(list.Count);
			}
			AudioClip val = list[num2];
			componentInParent.LastVoiceIndex = num2;
			componentInParent.NextVoice = Time.unscaledTime + Mathf.Max(2.5f, val.length + 0.15f);
			float num3 = Mathf.Clamp01((float)plugin.volume.Value / 100f);
			if (!(num3 <= 0f))
			{
				AudioSource val2 = componentInParent.Voice;
				if (!Object.op_Implicit((Object)(object)val2))
				{
					val2 = (componentInParent.Voice = ((Component)componentInParent).gameObject.AddComponent<AudioSource>());
					val2.playOnAwake = false;
					val2.loop = false;
					val2.spatialBlend = 1f;
					val2.rolloffMode = (AudioRolloffMode)0;
					val2.minDistance = 1.5f;
					val2.maxDistance = 15f;
					val2.dopplerLevel = 0f;
				}
				val2.Stop();
				val2.clip = val;
				val2.volume = num3;
				val2.Play();
			}
		}
		catch (Exception ex)
		{
			if (!plugin.damageWarning)
			{
				plugin.damageWarning = true;
				((BaseUnityPlugin)plugin).Logger.LogWarning((object)("Yerbisius figurine voice error: " + ex.Message));
			}
		}
	}

	private void TryRegisterValuable()
	{
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Expected O, but got Unknown
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0566: Unknown result type (might be due to invalid IL or missing references)
		//IL_0579: Unknown result type (might be due to invalid IL or missing references)
		//IL_0423: Unknown result type (might be due to invalid IL or missing references)
		//IL_042a: Unknown result type (might be due to invalid IL or missing references)
		//IL_042f: Unknown result type (might be due to invalid IL or missing references)
		//IL_058c: Unknown result type (might be due to invalid IL or missing references)
		//IL_045b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0460: Unknown result type (might be due to invalid IL or missing references)
		//IL_046c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0476: Unknown result type (might be due to invalid IL or missing references)
		//IL_047b: Unknown result type (might be due to invalid IL or missing references)
		//IL_05da: Unknown result type (might be due to invalid IL or missing references)
		//IL_05eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0537: Unknown result type (might be due to invalid IL or missing references)
		//IL_0694: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_0746: Unknown result type (might be due to invalid IL or missing references)
		//IL_0759: Unknown result type (might be due to invalid IL or missing references)
		//IL_076c: Unknown result type (might be due to invalid IL or missing references)
		//IL_078f: Unknown result type (might be due to invalid IL or missing references)
		//IL_079b: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_07b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_07cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_07f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0806: Unknown result type (might be due to invalid IL or missing references)
		//IL_080d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0814: Unknown result type (might be due to invalid IL or missing references)
		//IL_0819: Unknown result type (might be due to invalid IL or missing references)
		//IL_08e3: Unknown result type (might be due to invalid IL or missing references)
		if (valuableRegistered || valuableFailed || !Object.op_Implicit((Object)(object)prefab))
		{
			return;
		}
		Type type = AccessTools.TypeByName("REPOLib.Modules.Valuables");
		if (type == null)
		{
			return;
		}
		MethodInfo methodInfo = AccessTools.Method(type, "RegisterValuable", new Type[2]
		{
			typeof(GameObject),
			typeof(List<string>)
		}, (Type[])null);
		if (methodInfo == null)
		{
			valuableFailed = true;
			((BaseUnityPlugin)this).Logger.LogWarning((object)"Yerbisius collectible: incompatible REPOLib API; shop NPC unaffected.");
			return;
		}
		GameObject val = null;
		try
		{
			PropertyInfo propertyInfo = AccessTools.Property(type, "AllValuables");
			IEnumerable enumerable = ((propertyInfo == null) ? null : (propertyInfo.GetValue(null, null) as IEnumerable));
			if (enumerable == null)
			{
				return;
			}
			object obj = null;
			object obj2 = null;
			foreach (object item in enumerable)
			{
				if (item != null)
				{
					string text = Read(item, item.GetType(), "PrefabName") as string;
					if (text == "Valuable Manor Trophy")
					{
						obj = item;
						break;
					}
					if (text == "Valuable Trophy")
					{
						obj2 = item;
					}
				}
			}
			if (obj == null)
			{
				obj = obj2;
			}
			if (obj != null)
			{
				object obj3 = Read(obj, obj.GetType(), "Prefab");
				val = (GameObject)((obj3 is GameObject) ? obj3 : null);
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogDebug((object)("Yerbisius collectible waiting for vanilla presets: " + ex.Message));
			return;
		}
		if (!Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		GameObject val2 = null;
		try
		{
			Type type2 = AccessTools.TypeByName("ValuableObject");
			Type type3 = AccessTools.TypeByName("PhysGrabObject");
			if (type2 == null || type3 == null || !Object.op_Implicit((Object)(object)val.GetComponent(type2)) || !Object.op_Implicit((Object)(object)val.GetComponent(type3)) || !Object.op_Implicit((Object)(object)val.GetComponent<Rigidbody>()))
			{
				throw new InvalidOperationException("Trophy template is missing native physics or valuable components.");
			}
			valuableTemplates = new GameObject("Yerbisius Valuable Templates");
			valuableTemplates.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)valuableTemplates);
			val2 = Object.Instantiate<GameObject>(val, valuableTemplates.transform, false);
			((Object)val2).name = "Valuable Yerbisius Figurine";
			val2.transform.localPosition = Vector3.zero;
			val2.transform.localRotation = Quaternion.identity;
			val2.transform.localScale = Vector3.one;
			val2.SetActive(true);
			Component component = val2.GetComponent(type2);
			FieldInfo fieldInfo = AccessTools.Field(type2, "valuePreset");
			Object val3 = (Object)((fieldInfo == null) ? null : /*isinst with value type is only supported in some contexts*/);
			if (!Object.op_Implicit(val3))
			{
				throw new InvalidOperationException("Native valuable value preset missing.");
			}
			figurineValuePreset = Object.Instantiate(val3);
			figurineValuePreset.name = "Yerbisius $5000 Value";
			FieldInfo fieldInfo2 = AccessTools.Field(((object)figurineValuePreset).GetType(), "valueMin");
			FieldInfo fieldInfo3 = AccessTools.Field(((object)figurineValuePreset).GetType(), "valueMax");
			if (fieldInfo2 == null || fieldInfo3 == null)
			{
				throw new InvalidOperationException("Native valuable value range missing.");
			}
			fieldInfo2.SetValue(figurineValuePreset, Convert.ChangeType(5000, fieldInfo2.FieldType, CI));
			fieldInfo3.SetValue(figurineValuePreset, Convert.ChangeType(5000, fieldInfo3.FieldType, CI));
			fieldInfo.SetValue(component, figurineValuePreset);
			FieldInfo fieldInfo4 = AccessTools.Field(type2, "dollarValueOverride");
			if (fieldInfo4 != null)
			{
				fieldInfo4.SetValue(component, Convert.ChangeType(5000, fieldInfo4.FieldType, CI));
			}
			Bounds result = default(Bounds);
			bool initialized = false;
			Collider[] componentsInChildren = val2.GetComponentsInChildren<Collider>(true);
			foreach (Collider val4 in componentsInChildren)
			{
				if (val4.isTrigger || !val4.enabled)
				{
					continue;
				}
				BoxCollider val5 = (BoxCollider)(object)((val4 is BoxCollider) ? val4 : null);
				SphereCollider val6 = (SphereCollider)(object)((val4 is SphereCollider) ? val4 : null);
				CapsuleCollider val7 = (CapsuleCollider)(object)((val4 is CapsuleCollider) ? val4 : null);
				if (Object.op_Implicit((Object)(object)val5))
				{
					AddBounds(ref result, ref initialized, new Bounds(val5.center, val5.size), ((Component)val5).transform, val2.transform);
					continue;
				}
				if (Object.op_Implicit((Object)(object)val6))
				{
					AddBounds(ref result, ref initialized, new Bounds(val6.center, Vector3.one * val6.radius * 2f), ((Component)val6).transform, val2.transform);
					continue;
				}
				if (Object.op_Implicit((Object)(object)val7))
				{
					Vector3 val8 = Vector3.one * val7.radius * 2f;
					((Vector3)(ref val8))[val7.direction] = Mathf.Max(val7.height, val7.radius * 2f);
					AddBounds(ref result, ref initialized, new Bounds(val7.center, val8), ((Component)val7).transform, val2.transform);
					continue;
				}
				MeshCollider val9 = (MeshCollider)(object)((val4 is MeshCollider) ? val4 : null);
				if (Object.op_Implicit((Object)(object)val9) && Object.op_Implicit((Object)(object)val9.sharedMesh))
				{
					AddBounds(ref result, ref initialized, val9.sharedMesh.bounds, ((Component)val9).transform, val2.transform);
				}
			}
			if (!initialized || ((Bounds)(ref result)).size.x < 0.01f || ((Bounds)(ref result)).size.y < 0.01f || ((Bounds)(ref result)).size.z < 0.01f)
			{
				throw new InvalidOperationException("No usable trophy collider bounds.");
			}
			Renderer[] componentsInChildren2 = val2.GetComponentsInChildren<Renderer>(true);
			GameObject val10 = Object.Instantiate<GameObject>(prefab, val2.transform, false);
			((Object)val10).name = "Yerbisius Statue Model";
			val10.transform.localPosition = Vector3.zero;
			val10.transform.localRotation = Quaternion.identity;
			val10.transform.localScale = Vector3.one;
			Animator[] componentsInChildren3 = val10.GetComponentsInChildren<Animator>(true);
			foreach (Animator val11 in componentsInChildren3)
			{
				((Behaviour)val11).enabled = false;
			}
			AudioSource[] componentsInChildren4 = val10.GetComponentsInChildren<AudioSource>(true);
			foreach (AudioSource val12 in componentsInChildren4)
			{
				val12.playOnAwake = false;
				((Behaviour)val12).enabled = false;
			}
			Collider[] componentsInChildren5 = val10.GetComponentsInChildren<Collider>(true);
			foreach (Collider val13 in componentsInChildren5)
			{
				val13.enabled = false;
			}
			Bounds result2 = default(Bounds);
			bool initialized2 = false;
			Renderer[] componentsInChildren6 = val10.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val14 in componentsInChildren6)
			{
				if (val14 is MeshRenderer || val14 is SkinnedMeshRenderer)
				{
					AddBounds(ref result2, ref initialized2, val14.localBounds, ((Component)val14).transform, val10.transform);
				}
				SkinnedMeshRenderer val15 = (SkinnedMeshRenderer)(object)((val14 is SkinnedMeshRenderer) ? val14 : null);
				if (Object.op_Implicit((Object)(object)val15) && Object.op_Implicit((Object)(object)val15.sharedMesh))
				{
					for (int n = 0; n < val15.sharedMesh.blendShapeCount; n++)
					{
						val15.SetBlendShapeWeight(n, 0f);
					}
				}
			}
			if (!initialized2 || ((Bounds)(ref result2)).size.x < 0.01f || ((Bounds)(ref result2)).size.y < 0.01f || ((Bounds)(ref result2)).size.z < 0.01f)
			{
				throw new InvalidOperationException("No valid figurine mesh bounds.");
			}
			float num = 0.95f * Mathf.Min(((Bounds)(ref result)).size.x / ((Bounds)(ref result2)).size.x, Mathf.Min(((Bounds)(ref result)).size.y / ((Bounds)(ref result2)).size.y, ((Bounds)(ref result)).size.z / ((Bounds)(ref result2)).size.z));
			val10.transform.localScale = Vector3.one * num;
			val10.transform.localPosition = ((Bounds)(ref result)).center - ((Bounds)(ref result2)).center * num;
			Transform val16 = val2.transform.Find("Object");
			if (Object.op_Implicit((Object)(object)val16))
			{
				val10.transform.SetParent(val16, true);
			}
			Renderer[] array = componentsInChildren2;
			foreach (Renderer val17 in array)
			{
				if (val17 is MeshRenderer || val17 is SkinnedMeshRenderer)
				{
					val17.enabled = false;
				}
			}
			val2.AddComponent<FigurineDamageVoice>();
			object obj4 = methodInfo.Invoke(null, new object[2]
			{
				val2,
				new List<string> { "Valuables - Generic" }
			});
			if (obj4 == null)
			{
				throw new InvalidOperationException("REPOLib rejected the custom valuable.");
			}
			valuableRegistered = true;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Registered Valuable Yerbisius Figurine in generic spawn pool; native trophy physics retained; starting value $5000. Height=" + (((Bounds)(ref result2)).size.y * num).ToString("F2", CI)));
		}
		catch (Exception ex2)
		{
			valuableFailed = true;
			if (Object.op_Implicit((Object)(object)valuableTemplates))
			{
				Object.Destroy((Object)(object)valuableTemplates);
			}
			else if (Object.op_Implicit((Object)(object)val2))
			{
				Object.Destroy((Object)(object)val2);
			}
			if (Object.op_Implicit(figurineValuePreset))
			{
				Object.Destroy(figurineValuePreset);
			}
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Yerbisius collectible registration failed; shop NPC unaffected: " + ex2));
		}
	}

	private static void AddBounds(ref Bounds result, ref bool initialized, Bounds local, Transform from, Transform to)
	{
		//IL_0011: 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_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0058: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		for (int i = -1; i <= 1; i += 2)
		{
			for (int j = -1; j <= 1; j += 2)
			{
				for (int k = -1; k <= 1; k += 2)
				{
					Vector3 val = to.InverseTransformPoint(from.TransformPoint(((Bounds)(ref local)).center + Vector3.Scale(((Bounds)(ref local)).extents, new Vector3((float)i, (float)j, (float)k))));
					if (!initialized)
					{
						result = new Bounds(val, Vector3.zero);
						initialized = true;
					}
					else
					{
						((Bounds)(ref result)).Encapsulate(val);
					}
				}
			}
		}
	}

	private static object Read(object instance, Type type, string name)
	{
		if (type == null)
		{
			return null;
		}
		FieldInfo fieldInfo = AccessTools.Field(type, name);
		if (fieldInfo != null)
		{
			return fieldInfo.GetValue(instance);
		}
		PropertyInfo propertyInfo = AccessTools.Property(type, name);
		if (!(propertyInfo != null))
		{
			return null;
		}
		return propertyInfo.GetValue(instance, null);
	}

	private int Visit()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		object obj = Read(null, runType, "instance");
		if (obj == null || (obj is Object && !Object.op_Implicit((Object)obj)))
		{
			return int.MinValue;
		}
		object obj2 = Read(obj, runType, "levelsCompleted");
		if (!(obj2 is int))
		{
			return int.MinValue;
		}
		return (int)obj2;
	}

	private Component FindRadio()
	{
		//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)
		Object[] array = Object.FindObjectsOfType(radioType);
		foreach (Object val in array)
		{
			Component val2 = (Component)(object)((val is Component) ? val : null);
			if (Object.op_Implicit((Object)(object)val2) && val2.gameObject.activeInHierarchy)
			{
				Scene scene = val2.gameObject.scene;
				if (((Scene)(ref scene)).IsValid())
				{
					return val2;
				}
			}
		}
		return null;
	}

	internal static double Elapsed(double now, double then)
	{
		double num = now - then;
		if (PhotonNetwork.InRoom && !PhotonNetwork.OfflineMode)
		{
			if (num < -2147483.648)
			{
				num += 4294967.296;
			}
			if (num > 2147483.648)
			{
				num -= 4294967.296;
			}
		}
		return num;
	}

	private string RoomState()
	{
		if (!Networked)
		{
			return published;
		}
		if (!((Dictionary<object, object>)(object)((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties).TryGetValue((object)"woopsy.yerbisius.state.v16", out object value))
		{
			return null;
		}
		return value as string;
	}

	private void Send(string value)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		if (Networked)
		{
			Hashtable val = new Hashtable();
			val[(object)"woopsy.yerbisius.state.v16"] = value;
			PhotonNetwork.CurrentRoom.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
		}
	}

	private void ClearNpc()
	{
		if (Object.op_Implicit((Object)(object)npc))
		{
			npc.SetActive(false);
			Object.Destroy((Object)(object)npc);
		}
		npc = null;
		driver = null;
		tag = null;
		nameText = null;
		applied = null;
		lastCurrency = null;
		localWaves = null;
	}

	private void ResetVisit()
	{
		ClearNpc();
		anchor = null;
		published = null;
		localHit = null;
		lastHit = double.NaN;
		nextHitRequest = 0f;
		readyAt = Time.unscaledTime + 2f;
		nextPublish = 0f;
	}

	private void Update()
	{
		//IL_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0557: Unknown result type (might be due to invalid IL or missing references)
		//IL_056d: Unknown result type (might be due to invalid IL or missing references)
		//IL_059d: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_05be: Unknown result type (might be due to invalid IL or missing references)
		//IL_064f: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)prefab))
		{
			return;
		}
		if (!valuableRegistered && !valuableFailed && Time.unscaledTime >= nextValuableScan)
		{
			nextValuableScan = Time.unscaledTime + 1f;
			TryRegisterValuable();
		}
		object objA = (Networked ? PhotonNetwork.CurrentRoom : null);
		bool host = Host;
		if (!object.ReferenceEquals(objA, lastRoom))
		{
			ResetVisit();
			wasShop = false;
			lastRoom = objA;
			localVisit = int.MinValue;
		}
		if (Time.unscaledTime >= nextScan)
		{
			nextScan = Time.unscaledTime + 0.5f;
			Component val = ((isShopMethod != null && !(bool)isShopMethod.Invoke(null, null)) ? null : ((Object.op_Implicit((Object)(object)anchor) && anchor.gameObject.activeInHierarchy) ? anchor : FindRadio()));
			int num = Visit();
			if (!Object.op_Implicit((Object)(object)val))
			{
				if (wasShop && host)
				{
					Send("");
				}
				if (wasShop || Object.op_Implicit((Object)(object)npc))
				{
					ResetVisit();
				}
				wasShop = false;
				localVisit = num;
			}
			else
			{
				bool flag = !wasShop || (Object)(object)anchor != (Object)(object)val || localVisit != num;
				if (flag)
				{
					ResetVisit();
					wasShop = true;
					anchor = val;
					localVisit = num;
					if (host)
					{
						Send("");
					}
				}
				if (host && !wasHost && !flag)
				{
					string raw = RoomState();
					if (State.Parse(raw, out var state) && state.Visit == localVisit)
					{
						published = raw;
					}
				}
			}
			wasHost = host;
		}
		if (!wasShop || !Object.op_Implicit((Object)(object)anchor))
		{
			if (Object.op_Implicit((Object)(object)npc))
			{
				ClearNpc();
			}
			return;
		}
		if (host)
		{
			if (!show.Value)
			{
				if (published != "off" || Object.op_Implicit((Object)(object)npc))
				{
					published = "off";
					Send("");
					ClearNpc();
					nextPublish = Time.unscaledTime + 2f;
				}
				else if (Networked && !string.IsNullOrEmpty(RoomState()) && Time.unscaledTime >= nextPublish)
				{
					Send("");
					nextPublish = Time.unscaledTime + 2f;
				}
				return;
			}
			if (published == "off")
			{
				published = null;
				readyAt = Time.unscaledTime + 0.5f;
			}
			if (string.IsNullOrEmpty(published) && Time.unscaledTime >= readyAt && Time.unscaledTime >= nextPublish)
			{
				nextPublish = Time.unscaledTime + 1f;
				if (FindPlacement(anchor, out var result, out var angle))
				{
					State state2 = new State();
					state2.Visit = localVisit;
					state2.Position = result;
					state2.Yaw = angle;
					state2.Scale = 1.03f;
					state2.Epoch = Clock + 2.0;
					state2.Interval = 60f;
					state2.Wave = wave.Value;
					state2.Dance = dance.Value;
					State state3 = state2;
					published = state3.Encode();
					Send(published);
					nextPublish = Time.unscaledTime + 2f;
					((BaseUnityPlugin)this).Logger.LogInfo((object)string.Concat("Host placement: ", result, " yaw=", angle, " level=", localVisit, " scale=", 1.03f));
				}
				else if (Time.unscaledTime >= nextWarning)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"No clear floor on the selected counter side; retrying fixed extraction-side placement.");
					nextWarning = Time.unscaledTime + 10f;
				}
			}
			if (Networked && !string.IsNullOrEmpty(published) && RoomState() != published && Time.unscaledTime >= nextPublish)
			{
				Send(published);
				nextPublish = Time.unscaledTime + 2f;
			}
		}
		string text = (host ? published : RoomState());
		if (!State.Parse(text, out var state4) || state4.Visit != localVisit || Time.unscaledTime < readyAt)
		{
			if (Object.op_Implicit((Object)(object)npc))
			{
				ClearNpc();
			}
			return;
		}
		if (!Object.op_Implicit((Object)(object)npc) || applied != text)
		{
			ClearNpc();
			npc = Object.Instantiate<GameObject>(Object.op_Implicit((Object)(object)shopPrefab) ? shopPrefab : prefab, state4.Position, Quaternion.Euler(0f, state4.Yaw, 0f));
			((Object)npc).name = "Yerbisius";
			SceneManager.MoveGameObjectToScene(npc, anchor.gameObject.scene);
			npc.transform.localScale = Vector3.one * state4.Scale;
			driver = npc.AddComponent<NPCDriver>();
			driver.Volume = (float)volume.Value / 100f;
			driver.Initialize(dialogue, state4);
			driver.InstallCollision(ReportHit);
			applied = text;
			nextFont = 0f;
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Concat("Spawned synchronized Yerbisius at ", state4.Position, " (host=", host, ")."));
		}
		if (!Object.op_Implicit((Object)(object)driver))
		{
			return;
		}
		driver.Volume = (float)volume.Value / 100f;
		if (host)
		{
			if (string.IsNullOrEmpty(localWaves))
			{
				localWaves = ReadWaves();
			}
			driver.SetPurchaseWaves(localWaves, applied);
			ObserveShopCurrency();
		}
		else
		{
			lastCurrency = null;
			localWaves = null;
			driver.SetPurchaseWaves(ReadWaves(), applied);
		}
		string raw2 = (host ? localHit : ReadHit());
		if (TryHit(raw2, out var at))
		{
			driver.HitAt = at;
		}
		if (host && Networked && TryHit(ReadHit(), out at) && (double.IsNaN(lastHit) || Elapsed(at, lastHit) > 0.0))
		{
			lastHit = at;
			localHit = ReadHit();
			driver.HitAt = at;
		}
	}

	private string ReadHit()
	{
		if (!Networked)
		{
			return localHit;
		}
		if (!((Dictionary<object, object>)(object)((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties).TryGetValue((object)"woopsy.yerbisius.hit.v16", out object value))
		{
			return null;
		}
		return value as string;
	}

	private bool TryHit(string raw, out double at)
	{
		at = double.NaN;
		if (string.IsNullOrEmpty(applied) || string.IsNullOrEmpty(raw))
		{
			return false;
		}
		string text = applied + "|";
		if (!raw.StartsWith(text, StringComparison.Ordinal))
		{
			return false;
		}
		if (double.TryParse(raw.Substring(text.Length), NumberStyles.Float, CI, out at) && !double.IsNaN(at))
		{
			return !double.IsInfinity(at);
		}
		return false;
	}

	private void ReportHit()
	{
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Expected O, but got Unknown
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)npc) && wasShop && !string.IsNullOrEmpty(applied) && !(Time.unscaledTime < nextHitRequest))
		{
			nextHitRequest = Time.unscaledTime + 0.65f;
			if (Host)
			{
				AcceptHit();
				return;
			}
			object[] obj = new object[2] { "woopsy.yerbisius.hit.request.v16", applied };
			RaiseEventOptions val = new RaiseEventOptions();
			val.Receivers = (ReceiverGroup)2;
			PhotonNetwork.RaiseEvent((byte)179, (object)obj, val, SendOptions.SendReliable);
		}
	}

	public void OnEvent(EventData ev)
	{
		if (ev.Code == 179 && Host && Networked && Object.op_Implicit((Object)(object)npc) && wasShop && ev.CustomData is object[] array && array.Length == 2 && !(array[0] as string != "woopsy.yerbisius.hit.request.v16") && !(array[1] as string != applied) && PhotonNetwork.CurrentRoom.Players.ContainsKey(ev.Sender))
		{
			AcceptHit();
		}
	}

	private void AcceptHit()
	{
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Expected O, but got Unknown
		if (!Object.op_Implicit((Object)(object)driver) || !wasShop || string.IsNullOrEmpty(applied))
		{
			return;
		}
		double clock = Clock;
		if (TryHit(ReadHit(), out var at) && (double.IsNaN(lastHit) || Elapsed(at, lastHit) > 0.0))
		{
			lastHit = at;
		}
		if (double.IsNaN(lastHit) || !(Elapsed(clock, lastHit) < 1.1))
		{
			lastHit = clock + (Networked ? 0.2 : 0.0);
			localHit = applied + "|" + lastHit.ToString("R", CI);
			driver.HitAt = lastHit;
			if (Networked)
			{
				Hashtable val = new Hashtable();
				val[(object)"woopsy.yerbisius.hit.v16"] = localHit;
				PhotonNetwork.CurrentRoom.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Yerbisius hit accepted; flinch at " + lastHit.ToString("R", CI)));
		}
	}

	private bool FindPlacement(Component radio, out Vector3 result, out float angle)
	{
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: 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_00eb: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0310: Unknown result type (might be due to invalid IL or missing references)
		//IL_0315: 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_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
		Transform val = null;
		object obj = Read(null, shopType, "instance");
		if (obj != null && (!(obj is Object) || Object.op_Implicit((Object)obj)))
		{
			object obj2 = Read(obj, shopType, "extractionPoint");
			Component val2 = (Component)((obj2 is Component) ? obj2 : null);
			if (Object.op_Implicit((Object)(object)val2))
			{
				val = val2.transform;
			}
			GameObject val3 = (GameObject)((obj2 is GameObject) ? obj2 : null);
			if (Object.op_Implicit((Object)(object)val3))
			{
				val = val3.transform;
			}
		}
		if (!Object.op_Implicit((Object)(object)val))
		{
			val = radio.transform;
			if (Time.unscaledTime >= nextWarning)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"ShopManager.extractionPoint unavailable; using radio-relative placement.");
				nextWarning = Time.unscaledTime + 10f;
			}
		}
		Vector3 val4 = Vector3.ProjectOnPlane(val.forward, Vector3.up);
		Vector3 val5 = ((Vector3)(ref val4)).normalized;
		if (((Vector3)(ref val5)).sqrMagnitude < 0.1f)
		{
			val5 = Vector3.forward;
		}
		Vector3 val6 = -Vector3.Cross(Vector3.up, val5);
		Quaternion val7 = Quaternion.LookRotation(val5, Vector3.up);
		angle = ((Quaternion)(ref val7)).eulerAngles.y + 0f;
		float num = 1f;
		float[] array = new float[12]
		{
			0f, 0.35f, 0.75f, 1.1f, 0f, 0.35f, 0.75f, 1.1f, -0.35f, -0.7f,
			0f, 0.7f
		};
		float[] array2 = new float[12]
		{
			0f, 0f, 0f, 0f, 0.4f, 0.4f, 0.4f, 0.4f, 0f, 0f,
			-0.45f, -0.45f
		};
		RaycastHit val9 = default(RaycastHit);
		for (int i = 0; i < array.Length; i++)
		{
			float num2 = 2.1f + num * array[i];
			if (num2 * num < 0.2f)
			{
				continue;
			}
			Vector3 val8 = val.position + val6 * num2 + val5 * (0.65f + array2[i]);
			if (Physics.Raycast(val8 + Vector3.up * 1.2f, Vector3.down, ref val9, 5f, -1, (QueryTriggerInteraction)1) && !(Vector3.Dot(((RaycastHit)(ref val9)).normal, Vector3.up) < 0.8f) && !(Mathf.Abs(((RaycastHit)(ref val9)).point.y - val.position.y) > 2.5f))
			{
				float num3 = 1.03f;
				if (!Physics.CheckCapsule(((RaycastHit)(ref val9)).point + Vector3.up * (0.32f * num3 + 0.07f), ((RaycastHit)(ref val9)).point + Vector3.up * (1.73f * num3 + 0.07f), 0.29f * num3, -1, (QueryTriggerInteraction)1))
				{
					result = ((RaycastHit)(ref val9)).point + Vector3.up * 0.025f;
					((BaseUnityPlugin)this).Logger.LogInfo((object)string.Concat("Placement anchor: ", ((Object)val).name, " at ", val.position, "; right=", num2, ", front=", 0.65f + array2[i]));
					return true;
				}
			}
		}
		result = Vector3.zero;
		return false;
	}

	internal static Camera PlayerCamera()
	{
		Camera main = Camera.main;
		if (Object.op_Implicit((Object)(object)main) && ((Behaviour)main).isActiveAndEnabled)
		{
			return main;
		}
		Camera val = null;
		Camera[] allCameras = Camera.allCameras;
		foreach (Camera val2 in allCameras)
		{
			if (Object.op_Implicit((Object)(object)val2) && ((Behaviour)val2).isActiveAndEnabled && (Object)(object)val2.targetTexture == (Object)null && (!Object.op_Implicit((Object)(object)val) || val2.depth > val.depth))
			{
				val = val2;
			}
		}
		return val;
	}

	private TMP_FontAsset FindGameFont()
	{
		TMP_FontAsset val = null;
		TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
		foreach (TMP_FontAsset val2 in array)
		{
			if (Object.op_Implicit((Object)(object)val2) && ((Object)val2).name.IndexOf("Teko", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				if (((Object)val2).name.Equals("Teko-VariableFont_wght SDF 1", StringComparison.OrdinalIgnoreCase))
				{
					return val2;
				}
				if (!Object.op_Implicit((Object)(object)val))
				{
					val = val2;
				}
			}
		}
		return val;
	}

	private void LateUpdate()
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Expected O, but got Unknown
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_036c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0377: Unknown result type (might be due to invalid IL or missing references)
		//IL_037c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c3: 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_02cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0300: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)npc) || !Object.op_Implicit((Object)(object)driver))
		{
			return;
		}
		if (!Object.op_Implicit((Object)(object)tag) && Time.unscaledTime >= nextFont)
		{
			nextFont = Time.unscaledTime + 2f;
			TMP_FontAsset val = FindGameFont();
			if (Object.op_Implicit((Object)(object)val))
			{
				tag = new GameObject("Yerbisius Nameplate");
				tag.transform.SetParent(npc.transform, false);
				tag.transform.localPosition = new Vector3(0f, 2.1f, 0f);
				tag.transform.localScale = Vector3.one * 0.12f;
				nameText = tag.AddComponent<TextMeshPro>();
				((TMP_Text)nameText).font = val;
				((TMP_Text)nameText).text = "Yerbisius";
				((TMP_Text)nameText).fontSize = 3.1f;
				((TMP_Text)nameText).alignment = (TextAlignmentOptions)514;
				((Graphic)nameText).color = Color.white;
				((TMP_Text)nameText).outlineColor = Color32.op_Implicit(Color.black);
				((TMP_Text)nameText).outlineWidth = 0.16f;
				((TMP_Text)nameText).enableWordWrapping = false;
				((TMP_Text)nameText).rectTransform.sizeDelta = new Vector2(14f, 3f);
				((TMP_Text)nameText).ForceMeshUpdate(true, true);
				Bounds textBounds = ((TMP_Text)nameText).textBounds;
				float x = ((Bounds)(ref textBounds)).size.x;
				if (x > 0.001f)
				{
					tag.transform.localScale = Vector3.one * (0.68f / x);
				}
				tag.SetActive(false);
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Nameplate uses game font: " + ((Object)val).name));
			}
		}
		if (!Object.op_Implicit((Object)(object)tag))
		{
			return;
		}
		Camera val2 = PlayerCamera();
		bool flag = false;
		if (names.Value && Object.op_Implicit((Object)(object)val2))
		{
			Vector3 val3 = npc.transform.position + Vector3.up * (1.28f * npc.transform.localScale.y);
			Vector3 val4 = val3 - ((Component)val2).transform.position;
			float num = Vector3.Dot(val4, ((Component)val2).transform.forward);
			if (((Vector3)(ref val4)).sqrMagnitude < 100f && ((Vector3)(ref val4)).sqrMagnitude > 0.01f && num > 0f)
			{
				Vector3 val5 = val4 - ((Component)val2).transform.forward * num;
				if (((Vector3)(ref val5)).magnitude < 0.48f * npc.transform.localScale.y)
				{
					RaycastHit val6 = default(RaycastHit);
					flag = !Physics.Raycast(((Component)val2).transform.position, ((Vector3)(ref val4)).normalized, ref val6, Mathf.Max(0f, ((Vector3)(ref val4)).magnitude - 0.1f), -1, (QueryTriggerInteraction)1) || (Object.op_Implicit((Object)(object)((RaycastHit)(ref val6)).collider) && ((Component)((RaycastHit)(ref val6)).collider).transform.IsChildOf(npc.transform));
				}
			}
			if (flag)
			{
				tag.transform.rotation = Quaternion.LookRotation(((Component)val2).transform.forward, ((Component)val2).transform.up);
			}
		}
		if (tag.activeSelf != flag)
		{
			tag.SetActive(flag);
		}
	}

	private void OnDestroy()
	{
		if (callbackRegistered)
		{
			PhotonNetwork.RemoveCallbackTarget((object)this);
		}
		if ((Object)(object)waveOwner == (Object)(object)this)
		{
			waveOwner = null;
		}
		if (waveHarmony != null)
		{
			waveHarmony.UnpatchSelf();
		}
		if ((Object)(object)impactOwner == (Object)(object)this)
		{
			impactOwner = null;
		}
		if (impactHarmony != null)
		{
			impactHarmony.UnpatchSelf();
		}
		if ((Object)(object)damageOwner == (Object)(object)this)
		{
			damageOwner = null;
		}
		if (damageHarmony != null && damageMethod != null)
		{
			damageHarmony.Unpatch((MethodBase)damageMethod, (HarmonyPatchType)1, "woopsy.yerbisius.valuablevoice");
		}
		ClearNpc();
		if (Object.op_Implicit((Object)(object)bundle))
		{
			bundle.Unload(false);
		}
	}
}
public sealed class FigurineDamageVoice : MonoBehaviour
{
	[NonSerialized]
	public float NextVoice;

	[NonSerialized]
	public int LastVoiceIndex = -1;

	[NonSerialized]
	public AudioSource Voice;
}
public sealed class State
{
	public int Visit;

	public Vector3 Position;

	public float Yaw;

	public float Scale;

	public float Interval;

	public double Epoch;

	public bool Wave;

	public bool Dance;

	private static readonly CultureInfo CI = CultureInfo.InvariantCulture;

	public string Encode()
	{
		return string.Join("|", Visit.ToString(CI), Position.x.ToString("R", CI), Position.y.ToString("R", CI), Position.z.ToString("R", CI), Yaw.ToString("R", CI), Scale.ToString("R", CI), Epoch.ToString("R", CI), Interval.ToString("R", CI), Wave ? "1" : "0", Dance ? "1" : "0");
	}

	public static bool Parse(string raw, out State state)
	{
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		state = null;
		if (string.IsNullOrEmpty(raw))
		{
			return false;
		}
		string[] array = raw.Split('|');
		if (array.Length != 10)
		{
			return false;
		}
		if (!int.TryParse(array[0], NumberStyles.Integer, CI, out var result) || !float.TryParse(array[1], NumberStyles.Float, CI, out var result2) || !float.TryParse(array[2], NumberStyles.Float, CI, out var result3) || !float.TryParse(array[3], NumberStyles.Float, CI, out var result4) || !float.TryParse(array[4], NumberStyles.Float, CI, out var result5) || !float.TryParse(array[5], NumberStyles.Float, CI, out var result6) || !double.TryParse(array[6], NumberStyles.Float, CI, out var result7) || !float.TryParse(array[7], NumberStyles.Float, CI, out var result8))
		{
			return false;
		}
		float[] array2 = new float[6] { result2, result3, result4, result5, result6, result8 };
		foreach (float f in array2)
		{
			if (float.IsNaN(f) || float.IsInfinity(f))
			{
				return false;
			}
		}
		if (double.IsNaN(result7) || double.IsInfinity(result7) || result6 < 0.5f || result6 > 1.5f || result8 < 10f || result8 > 120f)
		{
			return false;
		}
		state = new State
		{
			Visit = result,
			Position = new Vector3(result2, result3, result4),
			Yaw = result5,
			Scale = result6,
			Epoch = result7,
			Interval = result8,
			Wave = (array[8] == "1"),
			Dance = (array[9] == "1")
		};
		return true;
	}
}
public sealed class NPCDriver : MonoBehaviour
{
	private sealed class Pose
	{
		public Transform Node;

		public Vector3 Position;

		public Quaternion Rotation;
	}

	private sealed class Leg
	{
		public Transform Hip;

		public Transform Knee;

		public Transform Ankle;

		public Vector3 RestFoot;

		public Quaternion RestFootRotation;

		public float Upper;

		public float Lower;
	}

	private sealed class Binding
	{
		public SkinnedMeshRenderer Renderer;

		public int Mouth = -1;

		public int Blink = -1;
	}

	private const float MouthMaxWeight = 1f;

	private const double DanceStart = 10.0;

	private const double DanceInterval = 24.0;

	private const double DanceDuration = 7.0;

	private const double GreetingTime = 1.5;

	private const double RareWaveFirst = 100.0;

	private const double RareWaveInterval = 115.0;

	private const float WaveBlendSeconds = 0.25f;

	public float Volume = 1f;

	public double HitAt = double.NaN;

	private Action reportHit;

	private Type hurtType;

	private Type meleeType;

	private Type grabType;

	private Type playerType;

	private Type avatarType;

	private CapsuleCollider solid;

	private float flinchLength = 0.6f;

	private bool hasFlinch;

	private State state;

	private AudioSource voice;

	private Animator animator;

	private float idleLength = 3f;

	private float waveLength = 2f;

	private float mouth;

	private PlayableGraph motionGraph;

	private AnimationMixerPlayable mixer;

	private AnimationClipPlayable idlePlayable;

	private AnimationClipPlayable wavePlayable;

	private AnimationClipPlayable flinchPlayable;

	private List<double> purchaseWaves = new List<double>();

	private string cachedWaves;

	private static readonly float[] IdleYaws = new float[6] { -28f, 34f, 0f, 25f, -24f, 12f };

	private static readonly float[] IdlePitches = new float[6] { -2f, 3f, -17f, -13f, -11f, 5f };

	private readonly int[] danceOrder = new int[5] { 0, 1, 2, 3, 4 };

	private Transform danceBody;

	private Transform danceHead;

	private Transform upperR;

	private Transform lowerR;

	private Transform upperL;

	private Transform lowerL;

	private readonly List<Pose> danceOverrides = new List<Pose>();

	private Leg legR;

	private Leg legL;

	private Vector3 legForward;

	private Vector3 legRight;

	private bool legsReady;

	private float[] samples;

	private AudioClip[] lines;

	private string playingEvent;

	private int[] ambientLines;

	private int[] hurtLines;

	private readonly HashSet<string> heardEvents = new HashSet<string>();

	private readonly List<Binding> faces = new List<Binding>();

	public bool WavesEnabled
	{
		get
		{
			if (state != null)
			{
				return state.Wave;
			}
			return false;
		}
	}

	public double VisitElapsed
	{
		get
		{
			if (state != null)
			{
				return Plugin.Elapsed(Plugin.Clock, state.Epoch);
			}
			return 0.0;
		}
	}

	public float WaveDuration => waveLength;

	public float PurchaseDuration => Mathf.Max(waveLength, (lines != null && Object.op_Implicit((Object)(object)lines[5])) ? lines[5].length : 0f);

	internal static List<double> DecodeWaves(string raw, string visit)
	{
		List<double> list = new List<double>();
		if (string.IsNullOrEmpty(raw) || string.IsNullOrEmpty(visit) || !raw.StartsWith(visit + "|", StringComparison.Ordinal))
		{
			return list;
		}
		string[] array = raw.Substring(visit.Length + 1).Split(',');
		foreach (string s in array)
		{
			if (double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && !double.IsNaN(result) && !double.IsInfinity(result) && result >= 0.0 && result < 172800.0)
			{
				list.Add(result);
			}
		}
		list.Sort();
		return list;
	}

	public void SetPurchaseWaves(string raw, string visit)
	{
		if (!(raw == cachedWaves))
		{
			cachedWaves = raw;
			purchaseWaves = DecodeWaves(raw, visit);
		}
	}

	private double WavePhase(double elapsed)
	{
		if (!WavesEnabled)
		{
			return -1.0;
		}
		foreach (double purchaseWave in purchaseWaves)
		{
			double num = purchaseWave;
			if (elapsed >= num && elapsed < num + (double)waveLength)
			{
				return elapsed - num;
			}
		}
		if (elapsed >= 1.5 && elapsed < 1.5 + (double)waveLength)
		{
			return elapsed - 1.5;
		}
		if (elapsed < 100.0)
		{
			return -1.0;
		}
		double num2 = 100.0 + Math.Floor((elapsed - 100.0) / 115.0) * 115.0;
		if (elapsed >= num2 + (double)waveLength)
		{
			return -1.0;
		}
		foreach (double purchaseWave2 in purchaseWaves)
		{
			double num3 = purchaseWave2;
			if (num3 < num2 + (double)waveLength && num3 + (double)waveLength > num2)
			{
				return -1.0;
			}
		}
		return elapsed - num2;
	}

	private float WaveClearance(double elapsed)
	{
		if (!WavesEnabled)
		{
			return 1f;
		}
		if (WavePhase(elapsed) >= 0.0)
		{
			return 0f;
		}
		double num = Math.Min(Math.Abs(elapsed - 1.5), Math.Abs(elapsed - 1.5 - (double)waveLength));
		foreach (double purchaseWave in purchaseWaves)
		{
			double num2 = purchaseWave;
			num = Math.Min(num, Math.Min(Math.Abs(elapsed - num2), Math.Abs(elapsed - num2 - (double)waveLength)));
		}
		if (elapsed >= 99.0)
		{
			double num3 = 100.0 + Math.Floor((elapsed - 100.0) / 115.0) * 115.0;
			num = Math.Min(num, Math.Min(Math.Abs(elapsed - num3 - (double)waveLength), Math.Abs(elapsed - num3 - 115.0)));
		}
		return Mathf.SmoothStep(0f, 1f, Mathf.Clamp01((float)(num / 0.4)));
	}

	private Leg FindLeg(Transform[] nodes, string side)
	{
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: 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)
		Leg leg = new Leg();
		foreach (Transform val in nodes)
		{
			if (((Object)val).name == "YerbHip_" + side)
			{
				leg.Hip = val;
			}
			if (((Object)val).name == "YerbKnee_" + side)
			{
				leg.Knee = val;
			}
			if (((Object)val).name == "YerbAnkle_" + side)
			{
				leg.Ankle = val;
			}
		}
		if (!Object.op_Implicit((Object)(object)leg.Hip) || !Object.op_Implicit((Object)(object)leg.Knee) || !Object.op_Implicit((Object)(object)leg.Ankle) || (Object)(object)leg.Knee.parent != (Object)(object)leg.Hip || (Object)(object)leg.Ankle.parent != (Object)(object)leg.Knee || (Object)(object)leg.Hip.parent != (Object)(object)danceBody)
		{
			return null;
		}
		Vector3 localPosition = leg.Knee.localPosition;
		leg.Upper = ((Vector3)(ref localPosition)).magnitude;
		Vector3 localPosition2 = leg.Ankle.localPosition;
		leg.Lower = ((Vector3)(ref localPosition2)).magnitude;
		if (leg.Upper < 0.1f || leg.Lower < 0.1f)
		{
			return null;
		}
		leg.RestFoot = ((Component)this).transform.InverseTransformPoint(leg.Ankle.position);
		leg.RestFootRotation = Quaternion.Inverse(((Component)this).transform.rotation) * leg.Ankle.rotation;
		return leg;
	}

	private void SetupLegs(Transform[] nodes)
	{
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: 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)
		if (!Object.op_Implicit((Object)(object)danceBody))
		{
			return;
		}
		legR = FindLeg(nodes, "R");
		legL = FindLeg(nodes, "L");
		Transform val = null;
		foreach (Transform val2 in nodes)
		{
			if (((Object)val2).name == "YerbLegForward")
			{
				val = val2;
			}
		}
		if (legR == null || legL == null || !Object.op_Implicit((Object)(object)val))
		{
			Debug.LogWarning((object)"Yerbisius: original rigid legs retained; articulated shop rig unavailable.");
			return;
		}
		Vector3 val3 = Vector3.ProjectOnPlane(((Component)this).transform.InverseTransformDirection(danceBody.TransformDirection(val.localPosition)), Vector3.up);
		legForward = ((Vector3)(ref val3)).normalized;
		if (!(((Vector3)(ref legForward)).sqrMagnitude < 0.5f))
		{
			Vector3 val4 = Vector3.Cross(Vector3.up, legForward);
			legRight = ((Vector3)(ref val4)).normalized;
			legsReady = true;
			Debug.Log((object)"Yerbisius: articulated hips, knees and ankles ready.");
		}
	}

	private void ResetLeg(Leg l)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		if (l != null)
		{
			l.Hip.localRotation = Quaternion.identity;
			l.Knee.localRotation = Quaternion.identity;
			l.Ankle.localRotation = Quaternion.identity;
		}
	}

	private void PoseLeg(Leg l, float side, float stride, float lift, float spread, float w)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: 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_0019: 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_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: 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_006c: 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_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: 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_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: 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_0193: 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_01a6: 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_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0207: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = l.RestFoot + (legForward * stride + legRight * side * spread + Vector3.up * lift) * w;
		Vector3 val2 = danceBody.InverseTransformPoint(((Component)this).transform.TransformPoint(val));
		Vector3 localPosition = l.Hip.localPosition;
		Vector3 val3 = val2 - localPosition;
		if (!(((Vector3)(ref val3)).sqrMagnitude < 0.0001f))
		{
			Vector3 normalized = ((Vector3)(ref val3)).normalized;
			float num = Mathf.Clamp(((Vector3)(ref val3)).magnitude, Mathf.Abs(l.Upper - l.Lower) + 0.001f, l.Upper + l.Lower - 0.0001f);
			Vector3 val4 = danceBody.InverseTransformDirection(((Component)this).transform.TransformDirection(legForward));
			Vector3 val5 = Vector3.ProjectOnPlane(val4, normalized);
			val4 = ((Vector3)(ref val5)).normalized;
			if (!(((Vector3)(ref val4)).sqrMagnitude < 0.01f))
			{
				float num2 = (l.Upper * l.Upper - l.Lower * l.Lower + num * num) / (2f * num);
				float num3 = Mathf.Sqrt(Mathf.Max(0f, l.Upper * l.Upper - num2 * num2));
				Vector3 val6 = localPosition + normalized * num2 + val4 * num3;
				Vector3 val7 = localPosition + normalized * num;
				Quaternion val8 = Quaternion.FromToRotation(l.Knee.localPosition, val6 - localPosition);
				Quaternion val9 = Quaternion.FromToRotation(l.Ankle.localPosition, val7 - val6);
				l.Hip.localRotation = val8;
				l.Knee.localRotation = Quaternion.Inverse(val8) * val9;
				Quaternion val10 = Quaternion.Inverse(danceBody.rotation) * ((Component)this).transform.rotation * l.RestFootRotation;
				l.Ankle.localRotation = Quaternion.Inverse(val9) * val10;
			}
		}
	}

	private void ApplyFootwork(int kind, float beat, float w)
	{
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		if (legsReady)
		{
			float num = Mathf.Sin(beat);
			float num2 = Mathf.Sin(beat * 0.5f);
			float num3 = 0f;
			float stride = 0f;
			float lift = 0f;
			float lift2 = 0f;
			float spread = 0.02f;
			switch (kind)
			{
			case 0:
				num3 = 0.045f * num;
				stride = 0f - num3;
				lift = 0.035f * Mathf.Max(0f, num);
				lift2 = 0.035f * Mathf.Max(0f, 0f - num);
				spread = 0.04f;
				break;
			case 1:
				spread = 0.045f;
				num3 = 0.035f * num2;
				stride = 0f - num3;
				lift = 0.035f * Mathf.Max(0f, num2);
				lift2 = 0.035f * Mathf.Max(0f, 0f - num2);
				break;
			case 2:
				num3 = 0.055f * num2;
				stride = 0f - num3;
				lift = 0.055f * Mathf.Max(0f, num);
				lift2 = 0.055f * Mathf.Max(0f, 0f - num);
				break;
			case 3:
				num3 = 0.075f * num;
				stride = 0f - num3;
				lift = 0.045f * Mathf.Max(0f, num);
				lift2 = 0.045f * Mathf.Max(0f, 0f - num);
				spread = 0.035f + 0.025f * Mathf.Abs(num2);
				break;
			case 4:
				spread = 0.065f;
				break;
			}
			float num4 = ((Vector3.Dot(legR.RestFoot - legL.RestFoot, legRight) >= 0f) ? 1f : (-1f));
			PoseLeg(legR, num4, num3, lift, spread, w);
			PoseLeg(legL, 0f - num4, stride, lift2, spread, w);
		}
	}

	private void ApplyIdleLook(double elapsed)
	{
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_0298: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)danceBody) || !Object.op_Implicit((Object)(object)danceHead) || elapsed < 0.0)
		{
			return;
		}
		bool flag = state.Dance && elapsed >= 10.0 && (elapsed - 10.0) % 24.0 < 7.0;
		double num = (double.IsNaN(HitAt) ? (-1.0) : Plugin.Elapsed(Plugin.Clock, HitAt));
		float num2 = WaveClearance(elapsed);
		if (!flag && !(num2 <= 0f) && (!(num >= 0.0) || !(num < (double)flinchLength)))
		{
			double num3 = elapsed % 9.5;
			int num4 = (int)Math.Floor(elapsed / 9.5);
			float num5 = (float)num3;
			float num6 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(Mathf.Min((num5 - 1.25f) / 1.75f, (8f - num5) / 1.8f))) * num2;
			float weight = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(Mathf.Min((num5 - 0.55f) / 1.2f, (8.65f - num5) / 1.6f))) * num2;
			int num7 = num4 % IdleYaws.Length;
			float num8 = IdleYaws[num7];
			float num9 = IdlePitches[num7];
			if (legsReady && Vector3.Dot(legForward, Vector3.forward) < 0f)
			{
				num9 = 0f - num9;
			}
			float num10 = num8 * (legsReady ? 0.48f : 0.27f);
			float num11 = (legsReady ? (num9 * 0.12f) : 0f);
			float num12 = (legsReady ? (Mathf.Sin(num5 * 0.75f) * 0.009f) : 0f);
			OffsetPose(danceBody, new Vector3(num11, num10, (0f - num8) * 0.045f), new Vector3(num12, legsReady ? (-0.018f) : 0f, 0f), num6);
			OffsetPose(danceHead, new Vector3(num9 - num11, num8 - num10, Mathf.Sin(num5 * 0.85f) * 1.5f), Vector3.zero, weight);
			OffsetPose(upperR, new Vector3(1.6f, 0f, 1.3f), Vector3.zero, num6);
			OffsetPose(upperL, new Vector3(-1.6f, 0f, -1.3f), Vector3.zero, num6);
			if (legsReady && num6 > 0.001f)
			{
				PoseLeg(legR, 1f, 0f, 0f, 0f, 1f);
				PoseLeg(legL, -1f, 0f, 0f, 0f, 1f);
			}
		}
	}

	private void RestoreDance()
	{
		//IL_002a: 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)
		foreach (Pose danceOverride in danceOverrides)
		{
			if (Object.op_Implicit((Object)(object)danceOverride.Node))
			{
				danceOverride.Node.localPosition = danceOverride.Position;
				danceOverride.Node.localRotation = danceOverride.Rotation;
			}
		}
		danceOverrides.Clear();
		if (legsReady)
		{
			ResetLeg(legR);
			ResetLeg(legL);
		}
	}

	private void OffsetPose(Transform t, Vector3 euler, Vector3 move, float weight)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: 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_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_005f: 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_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)t))
		{
			danceOverrides.Add(new Pose
			{
				Node = t,
				Position = t.localPosition,
				Rotation = t.localRotation
			});
			t.localRotation *= Quaternion.Slerp(Quaternion.identity, Quaternion.Euler(euler), weight);
			t.localPosition += move * weight;
		}
	}

	private void ApplyStrongFlinch()
	{
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: 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_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)danceBody) || double.IsNaN(HitAt))
		{
			return;
		}
		double num = Plugin.Elapsed(Plugin.Clock, HitAt);
		if (!(num < 0.0) && !(num >= (double)flinchLength))
		{
			float num2 = (float)num / flinchLength;
			float num3 = ((num2 < 0.18f) ? Mathf.SmoothStep(0f, 1f, num2 / 0.18f) : (1f - Mathf.SmoothStep(0f, 1f, (num2 - 0.18f) / 0.82f)));
			Vector3 val = (legsReady ? ((Component)this).transform.TransformDirection(legForward) : ((Component)this).transform.forward);
			Vector3 val2 = Vector3.Cross(Vector3.up, val);
			Vector3 normalized = ((Vector3)(ref val2)).normalized;
			danceOverrides.Add(new Pose
			{
				Node = danceBody,
				Position = danceBody.localPosition,
				Rotation = danceBody.localRotation
			});
			Transform obj = danceBody;
			obj.position -= val * (0.14f * num3);
			danceBody.rotation = Quaternion.AngleAxis(-18f * num3, normalized) * danceBody.rotation;
			if (legsReady)
			{
				PoseLeg(legR, 1f, 0f, 0f, 0f, 1f);
				PoseLeg(legL, -1f, 0f, 0f, 0f, 1f);
			}
		}
	}

	private void DanceArm(Transform upper, Transform lower, float beat, float weight)
	{
		//IL_0012: 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_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)upper) && Object.op_Implicit((Object)(object)lower))
		{
			float num = ((upper.localPosition.x >= 0f) ? 1f : (-1f));
			float num2 = Mathf.Sin(beat);
			OffsetPose(upper, new Vector3(-24f - 20f * num2, num * 14f * num2, num * (37f + 25f * num2)), Vector3.zero, weight);
			OffsetPose(lower, new Vector3(-45f - 20f * Mathf.Cos(beat), 0f, num * (12f + 17f * num2)), Vector3.zero, weight);
		}
	}

	private float Side(Transform t)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)t) || !(t.localPosition.x >= 0f))
		{
			return -1f;
		}
		return 1f;
	}

	private void DiscoArm(Transform upper, Transform lower, float lift, float w)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		float num = Side(upper);
		OffsetPose(upper, new Vector3(-18f - 35f * lift, 0f, num * (22f + 100f * lift)), Vector3.zero, w);
		OffsetPose(lower, new Vector3(-15f - 40f * (1f - lift), 0f, num * 8f), Vector3.zero, w);
	}

	private void RobotArm(Transform upper, Transform lower, float step, float w)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: 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)
		float num = Side(upper);
		OffsetPose(upper, new Vector3(-35f + 30f * step, 0f, num * 55f), Vector3.zero, w);
		OffsetPose(lower, new Vector3(-75f + 20f * step, 0f, num * 15f * step), Vector3.zero, w);
	}

	private void ShuffleArm(Transform upper, Transform lower, float swing, float w)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		float num = Side(upper);
		OffsetPose(upper, new Vector3(42f * swing, 0f, num * 18f), Vector3.zero, w);
		OffsetPose(lower, new Vector3(-27f - 15f * swing, 0f, 0f), Vector3.zero, w);
	}

	private void TwerkArm(Transform upper, Transform lower, float w)
	{
		//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_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)
		float num = Side(upper);
		OffsetPose(upper, new Vector3(-20f, 0f, num * 18f), Vector3.zero, w);
		OffsetPose(lower, new Vector3(-28f, 0f, num * 9f), Vector3.zero, w);
	}

	private void ApplyDance(double elapsed)
	{
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0325: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0348: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unkno