Decompiled source of DizzinessMod v1.5.1

DizzinessMod.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DizzinessMod
{
	public static class AfflictionsPeak
	{
		public const int INTERNAL_ASCENT_ID = 8;

		public const int UI_SLOT_INDEX = 3;

		private static bool _checked;

		private static bool _allThreeInstalled;

		public static string LocalizedTitle()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_0048: Expected I4, but got Unknown
			Language cURRENT_LANGUAGE = LocalizedText.CURRENT_LANGUAGE;
			return (int)cURRENT_LANGUAGE switch
			{
				0 => "Runaway", 
				1 => "La Fugitive", 
				2 => "La Fuggitiva", 
				3 => "Die Ausreißerin", 
				4 => "La Fugitiva", 
				5 => "La Fugitiva", 
				6 => "A Fugitiva", 
				7 => "Беженка", 
				8 => "Втікачка", 
				9 => "逃亡者", 
				10 => "逃亡者", 
				11 => "逃亡者", 
				12 => "도망자", 
				13 => "Uciekinierka", 
				14 => "Kaçak", 
				_ => "Runaway", 
			};
		}

		public static string LocalizedDescription()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_0048: Expected I4, but got Unknown
			Language cURRENT_LANGUAGE = LocalizedText.CURRENT_LANGUAGE;
			return (int)cURRENT_LANGUAGE switch
			{
				0 => "All three afflictions maxed out. The mountain fights back with everything it has.", 
				1 => "Les trois afflictions au maximum. La montagne riposte de toutes ses forces.", 
				2 => "Tutte e tre le afflizioni al massimo. La montagna reagisce con tutto quello che ha.", 
				3 => "Alle drei Leiden auf Maximum. Der Berg schlägt mit allem zurück, was er hat.", 
				4 => "Las tres aflicciones al máximo. La montaña contraataca con todo lo que tiene.", 
				5 => "Las tres aflicciones al máximo. La montaña contraataca con todo lo que tiene.", 
				6 => "As três aflições no máximo. A montanha revida com tudo o que tem.", 
				7 => "Все три недуга на максимуме. Гора даёт сдачи всем что у неё есть.", 
				8 => "Всі три недуги на максимумі. Гора дає відсіч усім, що має.", 
				9 => "三种病症全部拉满。山会用尽一切反击。", 
				10 => "三種病症全部拉滿。山會用盡一切反擊。", 
				11 => "3つの症状が最大値。山は全力で反撃してくる。", 
				12 => "세 가지 고통이 최대치. 산이 가진 모든 것으로 반격한다.", 
				13 => "Wszystkie trzy dolegliwości na maksa. Góra oddaje wszystkim, co ma.", 
				14 => "Üç rahatsızlık da maksimumda. Dağ elindekiyle sana geri veriyor.", 
				_ => "All three afflictions maxed out. The mountain fights back with everything it has.", 
			};
		}

		public static bool IsAllThreeInstalled()
		{
			if (_checked)
			{
				return _allThreeInstalled;
			}
			_checked = true;
			bool flag = HasType("BleedingMod.BleedingPlugin");
			bool flag2 = HasType("FatigueMod.FatiguePlugin");
			_allThreeInstalled = flag && flag2;
			ManualLogSource logger = DizzinessPlugin.Logger;
			if (logger != null)
			{
				logger.LogInfo((object)$"[Беженка] Cross-mod check: Bleeding={flag} Fatigue={flag2} → inject={_allThreeInstalled}");
			}
			return _allThreeInstalled;
		}

		private static bool HasType(string fullName)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				try
				{
					if (assembly.GetType(fullName) != null)
					{
						return true;
					}
				}
				catch
				{
				}
			}
			return false;
		}

		public static bool IsActive()
		{
			try
			{
				return Ascents.currentAscent == 8;
			}
			catch
			{
				return false;
			}
		}
	}
	[HarmonyPatch(typeof(BoardingPass), "Initialize")]
	internal static class BoardingPass_Initialize_Patch
	{
		private static bool _injected;

		[HarmonyPostfix]
		private static void Postfix(BoardingPass __instance)
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			if (_injected || !AfflictionsPeak.IsAllThreeInstalled())
			{
				return;
			}
			try
			{
				object ascentData = __instance.ascentData;
				if (ascentData == null || !(ascentData.GetType().GetField("ascents", BindingFlags.Instance | BindingFlags.Public)?.GetValue(ascentData) is IList { Count: >2 } list))
				{
					return;
				}
				object obj = list[2];
				if (obj != null)
				{
					Type type = obj.GetType();
					object obj2 = Activator.CreateInstance(type);
					SetField(obj2, "title", "TAMBI_RUNAWAY");
					SetField(obj2, "titleReward", "TAMBI_RUNAWAY_REWARD");
					SetField(obj2, "description", "TAMBI_RUNAWAY");
					SetField(obj2, "color", (object)new Color(0.55f, 0.02f, 0.75f, 1f));
					FieldInfo field = type.GetField("sashSprite", BindingFlags.Instance | BindingFlags.Public);
					if (field != null)
					{
						field.SetValue(obj2, field.GetValue(obj));
					}
					int index = Mathf.Min(3, list.Count);
					list.Insert(index, obj2);
					FieldInfo field2 = typeof(BoardingPass).GetField("maxAscent", BindingFlags.Instance | BindingFlags.NonPublic);
					if (field2 != null)
					{
						int num = (int)field2.GetValue(__instance);
						field2.SetValue(__instance, num + 1);
					}
					_injected = true;
					ManualLogSource logger = DizzinessPlugin.Logger;
					if (logger != null)
					{
						logger.LogInfo((object)"[Беженка] Ascent injected into BoardingPass.");
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger2 = DizzinessPlugin.Logger;
				if (logger2 != null)
				{
					logger2.LogError((object)("[Беженка] Injection failed: " + ex.Message));
				}
			}
		}

		private static void SetField(object target, string name, object value)
		{
			target.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.SetValue(target, value);
		}
	}
	[HarmonyPatch(typeof(BoardingPass), "StartGame")]
	internal static class BoardingPass_StartGame_Patch
	{
		[HarmonyPrefix]
		private static bool Prefix(BoardingPass __instance)
		{
			if (!AfflictionsPeak.IsAllThreeInstalled())
			{
				return true;
			}
			try
			{
				int num = (int)(typeof(BoardingPass).GetField("_ascentIndex", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance) ?? ((object)__instance.ascentIndex));
				int num2 = ((num <= 0) ? num : ((num != 1) ? (num - 1) : 8));
				if (RunSettings.IsCustomRun)
				{
					num2 = 0;
				}
				object? obj = typeof(BoardingPass).GetField("kiosk", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(__instance);
				object? obj2 = ((obj is AirportCheckInKiosk) ? obj : null);
				if (obj2 != null)
				{
					((AirportCheckInKiosk)obj2).StartGame(num2);
				}
				return false;
			}
			catch (Exception ex)
			{
				ManualLogSource logger = DizzinessPlugin.Logger;
				if (logger != null)
				{
					logger.LogError((object)("[Беженка] StartGame mapping failed: " + ex.Message));
				}
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(Character), "Awake")]
	internal static class Character_Awake_ForceHardcore_Patch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			if (AfflictionsPeak.IsActive())
			{
				TambiAfflictionOption.SetValue("Bleeding", 3);
				TambiAfflictionOption.SetValue("Dizziness", 3);
				TambiAfflictionOption.SetValue("Fatigue", 3);
			}
		}
	}
	[HarmonyPatch(typeof(BoardingPass), "UpdateAscent")]
	internal static class BoardingPass_UpdateAscent_Patch
	{
		[HarmonyPostfix]
		private static void Postfix(BoardingPass __instance)
		{
			if (!AfflictionsPeak.IsAllThreeInstalled())
			{
				return;
			}
			try
			{
				if ((int)(typeof(BoardingPass).GetField("_ascentIndex", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance) ?? ((object)__instance.ascentIndex)) == 1)
				{
					if ((Object)(object)__instance.ascentTitle != (Object)null)
					{
						__instance.ascentTitle.text = AfflictionsPeak.LocalizedTitle();
					}
					if ((Object)(object)__instance.ascentDesc != (Object)null)
					{
						__instance.ascentDesc.text = AfflictionsPeak.LocalizedDescription();
					}
					if ((Object)(object)__instance.reward != (Object)null)
					{
						__instance.reward.SetActive(false);
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger = DizzinessPlugin.Logger;
				if (logger != null)
				{
					logger.LogWarning((object)("[Беженка] UpdateAscent postfix failed: " + ex.Message));
				}
			}
		}
	}
	[HarmonyPatch(typeof(BarAffliction), "ChangeAffliction")]
	internal static class BarAffliction_ChangeAffliction_Patch
	{
		[HarmonyPrefix]
		private static bool Prefix(BarAffliction __instance, StaminaBar bar)
		{
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: 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_00f0: 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)
			if (((Object)((Component)__instance).gameObject).name != "DizzinessCustomBar")
			{
				return true;
			}
			Character observedCharacter = Character.observedCharacter;
			if ((Object)(object)observedCharacter == (Object)null)
			{
				((Component)__instance).gameObject.SetActive(false);
				return false;
			}
			DizzinessTracker component = ((Component)observedCharacter).GetComponent<DizzinessTracker>();
			if ((Object)(object)component == (Object)null)
			{
				((Component)__instance).gameObject.SetActive(false);
				return false;
			}
			if ((Object)(object)__instance.icon != (Object)null)
			{
				((Component)__instance.icon).gameObject.SetActive(true);
				if ((Object)(object)DizzinessPlugin.DizzinessIconSprite != (Object)null)
				{
					__instance.icon.sprite = DizzinessPlugin.DizzinessIconSprite;
					((Graphic)__instance.icon).color = Color.white;
				}
			}
			float dizzinessValue = component.dizzinessValue;
			float num = bar.fullBar.sizeDelta.x * dizzinessValue;
			if (dizzinessValue > 0.01f)
			{
				if (num < bar.minAfflictionWidth)
				{
					num = bar.minAfflictionWidth;
				}
				__instance.size = num;
				RectTransform component2 = ((Component)__instance).GetComponent<RectTransform>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.sizeDelta = new Vector2(num, component2.sizeDelta.y);
				}
				((Component)__instance).gameObject.SetActive(true);
			}
			else
			{
				__instance.size = 0f;
				RectTransform component3 = ((Component)__instance).GetComponent<RectTransform>();
				if ((Object)(object)component3 != (Object)null)
				{
					component3.sizeDelta = new Vector2(0f, component3.sizeDelta.y);
				}
				((Component)__instance).gameObject.SetActive(false);
			}
			return false;
		}
	}
	internal static class BleedingBridge
	{
		private static bool _searched;

		private static Type _trackerType;

		private static FieldInfo _isBleedingField;

		private static FieldInfo _levelField;

		private static void EnsureCached()
		{
			if (_searched)
			{
				return;
			}
			_searched = true;
			try
			{
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				for (int i = 0; i < assemblies.Length; i++)
				{
					Type type = assemblies[i].GetType("BleedingMod.BleedingTracker");
					if (!(type == null))
					{
						_trackerType = type;
						_isBleedingField = type.GetField("s_isBleeding", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
						_levelField = type.GetField("s_level", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
						ManualLogSource logger = DizzinessPlugin.Logger;
						if (logger != null)
						{
							logger.LogInfo((object)"[BleedingBridge] BleedingMod detected — synergy enabled.");
						}
						break;
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger2 = DizzinessPlugin.Logger;
				if (logger2 != null)
				{
					logger2.LogWarning((object)("BleedingBridge init failed: " + ex.Message));
				}
			}
		}

		public static int GetBleedLevel()
		{
			EnsureCached();
			if (_trackerType == null || _isBleedingField == null || _levelField == null)
			{
				return 0;
			}
			try
			{
				if (!(bool)_isBleedingField.GetValue(null))
				{
					return 0;
				}
				object value = _levelField.GetValue(null);
				return (value != null) ? ((int)value) : 0;
			}
			catch
			{
				return 0;
			}
		}
	}
	[HarmonyPatch(typeof(CharacterAfflictions), "AddStatus")]
	internal static class CharacterAfflictions_AddStatus_Patch
	{
		private const float INJURY_THRESHOLD = 0.08f;

		private const float DIZZY_PER_INJURY = 0.22f;

		private const float FLASH_INJURY_CAP = 0.25f;

		[HarmonyPostfix]
		private static void Postfix(CharacterAfflictions __instance, STATUSTYPE statusType, float amount, bool fromRPC, ref bool __result)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!__result || (int)statusType != 0 || amount < 0.08f || (Object)(object)__instance == (Object)null || (Object)(object)__instance.character == (Object)null || !__instance.character.IsLocal || DizzinessPlugin.IsDizzinessDisabled() || DizzinessPlugin.IsInExpeditionGrace() || SpiderCheck.IsGrabbedBySpider(__instance.character))
				{
					return;
				}
				DizzinessTracker component = ((Component)__instance.character).GetComponent<DizzinessTracker>();
				if (!((Object)(object)component == (Object)null))
				{
					bool num = DizzinessPlugin.cfgEnableRockImpact == null || DizzinessPlugin.cfgEnableRockImpact.Value;
					bool flag = DizzinessPlugin.cfgEnableBossImpact == null || DizzinessPlugin.cfgEnableBossImpact.Value;
					if (num || flag)
					{
						float gainMultiplier = DizzinessPlugin.GetGainMultiplier();
						float num2 = Mathf.Min(amount * 0.22f * gainMultiplier, 0.5f);
						component.dizzinessValue = Mathf.Min(1f, component.dizzinessValue + num2);
						DizzinessPlugin.Instance?.TriggerConcussionFlash(Mathf.Min(amount / 0.25f, 1f) * 0.7f);
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger = DizzinessPlugin.Logger;
				if (logger != null)
				{
					logger.LogWarning((object)("AddStatus dizzy hook failed: " + ex.Message));
				}
			}
		}
	}
	[HarmonyPatch(typeof(CharacterAfflictions), "get_statusSum")]
	internal static class CharacterAfflictions_statusSum_Patch
	{
		[HarmonyPostfix]
		private static void Postfix(CharacterAfflictions __instance, ref float __result)
		{
			if ((Object)(object)__instance.character == (Object)null)
			{
				return;
			}
			DizzinessTracker component = ((Component)__instance.character).GetComponent<DizzinessTracker>();
			if ((Object)(object)component == (Object)null || (Object)(object)__instance.character.data == (Object)null)
			{
				return;
			}
			if (__instance.character.data.fullyPassedOut)
			{
				component.statusSumSeenPassOut = true;
				__result += component.dizzinessValue;
				if (component.dizzinessValue >= 1f)
				{
					__result = Mathf.Max(__result, 1.01f);
				}
				return;
			}
			if (component.statusSumSeenPassOut)
			{
				component.statusSumSeenPassOut = false;
				component.recentlyPassedOut = true;
				try
				{
					float maxStamina = __instance.character.GetMaxStamina();
					if (maxStamina > 0.001f)
					{
						__instance.character.data.currentStamina = maxStamina;
					}
				}
				catch
				{
				}
			}
			__result += component.dizzinessValue;
		}
	}
	[HarmonyPatch(typeof(CharacterMovement), "GetMovementForce")]
	internal static class CharacterMovement_GetMovementForce_Patch
	{
		private const float MAX_SLOWDOWN = 0.29f;

		[HarmonyPostfix]
		private static void Postfix(CharacterMovement __instance, ref float __result)
		{
			if (__result <= 0f || (Object)(object)__instance == (Object)null)
			{
				return;
			}
			DizzinessTracker component = ((Component)__instance).GetComponent<DizzinessTracker>();
			if (!((Object)(object)component == (Object)null))
			{
				float dizzinessValue = component.dizzinessValue;
				if (!(dizzinessValue <= 0.001f))
				{
					__result *= 1f - 0.29f * dizzinessValue;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "Awake")]
	internal static class Character_Awake_Patch
	{
		[HarmonyPostfix]
		private static void Postfix(Character __instance)
		{
			if ((Object)(object)((Component)__instance).GetComponent<DizzinessTracker>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<DizzinessTracker>();
			}
			if ((Object)(object)((Component)__instance).GetComponent<DizzinessRpcReceiver>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<DizzinessRpcReceiver>();
			}
		}
	}
	public class DizzinessAudioEffect : MonoBehaviour
	{
		private const float RING_START_DV = 0.65f;

		private const float RING_MAX_AMP = 0.015f;

		private const float RING_FREQUENCY_HZ = 6800f;

		private const float LOWPASS_MAX_HZ = 22000f;

		private const float LOWPASS_MIN_HZ = 1400f;

		private const float LOWPASS_IMPACT_HZ = 500f;

		private AudioLowPassFilter _lowPass;

		private AudioSource _dummySrc;

		private double _phase;

		private float _currentAmp;

		private float _currentCutoff = 22000f;

		public static void EnsureAttached()
		{
			AudioListener val = Object.FindObjectOfType<AudioListener>();
			if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).gameObject.GetComponent<DizzinessAudioEffect>() != (Object)null))
			{
				((Component)val).gameObject.AddComponent<DizzinessAudioEffect>();
			}
		}

		private void Awake()
		{
			_lowPass = ((Component)this).gameObject.GetComponent<AudioLowPassFilter>();
			if ((Object)(object)_lowPass == (Object)null)
			{
				_lowPass = ((Component)this).gameObject.AddComponent<AudioLowPassFilter>();
			}
			_lowPass.cutoffFrequency = 22000f;
			_lowPass.lowpassResonanceQ = 1f;
			_dummySrc = ((Component)this).gameObject.GetComponent<AudioSource>();
			if ((Object)(object)_dummySrc == (Object)null)
			{
				_dummySrc = ((Component)this).gameObject.AddComponent<AudioSource>();
			}
			_dummySrc.clip = null;
			_dummySrc.loop = true;
			_dummySrc.volume = 1f;
			_dummySrc.spatialBlend = 0f;
			_dummySrc.playOnAwake = false;
			_dummySrc.Play();
		}

		private static float GetDv()
		{
			Character localCharacter = Character.localCharacter;
			if ((Object)(object)localCharacter == (Object)null)
			{
				return 0f;
			}
			DizzinessTracker component = ((Component)localCharacter).GetComponent<DizzinessTracker>();
			if (!((Object)(object)component != (Object)null))
			{
				return 0f;
			}
			return component.dizzinessValue;
		}

		private void Update()
		{
			bool num = DizzinessPlugin.cfgDisableEarRinging != null && DizzinessPlugin.cfgDisableEarRinging.Value;
			Character localCharacter = Character.localCharacter;
			float dv = GetDv();
			float visualDrive = DizzinessDrive.GetVisualDrive(localCharacter, dv);
			float num2 = (num ? 0f : DizzinessDrive.GetRingDrive(localCharacter, dv));
			float num3 = ((visualDrive > 0.02f) ? Mathf.Lerp(22000f, 1400f, visualDrive) : 22000f);
			if (DizzinessDrive.IsImpactMuffleActive())
			{
				float impactMuffleFactor = DizzinessDrive.GetImpactMuffleFactor();
				num3 = Mathf.Lerp(num3, 500f, impactMuffleFactor);
			}
			_currentCutoff = Mathf.Lerp(_currentCutoff, num3, Time.deltaTime * 3.5f);
			if ((Object)(object)_lowPass != (Object)null)
			{
				_lowPass.cutoffFrequency = _currentCutoff;
			}
			float num4 = ((num2 > 0.65f) ? (Mathf.Clamp01((num2 - 0.65f) / 0.35000002f) * 0.015f) : 0f);
			_currentAmp = Mathf.Lerp(_currentAmp, num4, Time.deltaTime * 2f);
		}

		private void OnAudioFilterRead(float[] data, int channels)
		{
			if (_currentAmp < 0.0005f)
			{
				return;
			}
			int outputSampleRate = AudioSettings.outputSampleRate;
			double num = (double)(6800f / (float)outputSampleRate) * 2.0 * Math.PI;
			float currentAmp = _currentAmp;
			for (int i = 0; i < data.Length; i += channels)
			{
				_phase += num;
				if (_phase > Math.PI * 2.0)
				{
					_phase -= Math.PI * 2.0;
				}
				float num2 = (float)Math.Sin(_phase) * currentAmp;
				for (int j = 0; j < channels; j++)
				{
					data[i + j] += num2;
				}
			}
		}
	}
	public static class DizzinessBarInjector
	{
		public static BarAffliction injectedBar;

		private static bool injectionFailed;

		public static void TryInjectBar()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Invalid comparison between Unknown and I4
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)injectedBar != (Object)null || injectionFailed)
			{
				return;
			}
			try
			{
				if ((Object)(object)GUIManager.instance == (Object)null)
				{
					return;
				}
				StaminaBar bar = GUIManager.instance.bar;
				if ((Object)(object)bar == (Object)null || bar.afflictions == null || bar.afflictions.Length == 0)
				{
					return;
				}
				BarAffliction val = null;
				BarAffliction[] afflictions = bar.afflictions;
				foreach (BarAffliction val2 in afflictions)
				{
					if ((Object)(object)val2 != (Object)null && (int)val2.afflictionType == 4)
					{
						val = val2;
						break;
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					DizzinessPlugin.Logger.LogWarning((object)"Crab template bar not found");
					injectionFailed = true;
					return;
				}
				GameObject val3 = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)val).transform.parent);
				((Object)val3).name = "DizzinessCustomBar";
				BarAffliction component = val3.GetComponent<BarAffliction>();
				if ((Object)(object)component == (Object)null)
				{
					Object.Destroy((Object)(object)val3);
					injectionFailed = true;
					return;
				}
				if ((Object)(object)DizzinessPlugin.DizzinessIconSprite != (Object)null && (Object)(object)component.icon != (Object)null)
				{
					component.icon.sprite = DizzinessPlugin.DizzinessIconSprite;
					((Graphic)component.icon).color = Color.white;
				}
				Image[] componentsInChildren = ((Component)component).GetComponentsInChildren<Image>(true);
				foreach (Image val4 in componentsInChildren)
				{
					if (!((Object)(object)component.icon != (Object)null) || !((Object)(object)val4 == (Object)(object)component.icon))
					{
						Color dizzinessColor = DizzinessPlugin.DizzinessColor;
						dizzinessColor.a = ((Graphic)val4).color.a;
						((Graphic)val4).color = dizzinessColor;
					}
				}
				component.size = 0f;
				val3.SetActive(false);
				FieldInfo field = typeof(StaminaBar).GetField("afflictions", BindingFlags.Instance | BindingFlags.Public);
				if (field == null)
				{
					Object.Destroy((Object)(object)val3);
					injectionFailed = true;
					return;
				}
				BarAffliction[] array = (BarAffliction[])field.GetValue(bar);
				BarAffliction[] array2 = (BarAffliction[])(object)new BarAffliction[array.Length + 1];
				Array.Copy(array, array2, array.Length);
				array2[array.Length] = component;
				field.SetValue(bar, array2);
				injectedBar = component;
				DizzinessPlugin.Logger.LogInfo((object)$"Independent bar injected. New array size: {array2.Length}");
			}
			catch (Exception arg)
			{
				DizzinessPlugin.Logger.LogError((object)$"Bar injection failed: {arg}");
				injectionFailed = true;
			}
		}
	}
	public class DizzinessCameraEffect : MonoBehaviour
	{
		private Camera _cam;

		private float _swayPhase;

		private float _currentRoll;

		private float _currentFovDelta;

		private Vector3 _currentJitter;

		private void Awake()
		{
			_cam = ((Component)this).GetComponent<Camera>();
		}

		private static float GetDizziness()
		{
			Character localCharacter = Character.localCharacter;
			DizzinessTracker dizzinessTracker = (((Object)(object)localCharacter != (Object)null) ? ((Component)localCharacter).GetComponent<DizzinessTracker>() : null);
			if (!((Object)(object)dizzinessTracker != (Object)null))
			{
				return 0f;
			}
			return dizzinessTracker.dizzinessValue;
		}

		private void Update()
		{
			//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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			float dizziness = GetDizziness();
			float staminaDeficit = DizzinessDrive.GetStaminaDeficit(Character.localCharacter);
			bool flag = (DizzinessPlugin.cfgDisableCameraSway != null && DizzinessPlugin.cfgDisableCameraSway.Value) || (DizzinessPlugin.cfgVisualIntensity != null && DizzinessPlugin.cfgVisualIntensity.Value <= 0.001f);
			if ((dizziness < 0.05f && staminaDeficit < 0.95f) || flag)
			{
				_currentRoll = Mathf.MoveTowards(_currentRoll, 0f, Time.deltaTime * 4f);
				_currentFovDelta = Mathf.MoveTowards(_currentFovDelta, 0f, Time.deltaTime * 4f);
				_currentJitter = Vector3.MoveTowards(_currentJitter, Vector3.zero, Time.deltaTime * 0.05f);
				return;
			}
			float num = Mathf.Clamp01((DizzinessPlugin.cfgVisualIntensity != null) ? DizzinessPlugin.cfgVisualIntensity.Value : 1f);
			_swayPhase += Time.deltaTime * (0.5f + dizziness * 1.5f);
			float num2 = dizziness * dizziness * 3f * num;
			_currentRoll = Mathf.Sin(_swayPhase * MathF.PI * 2f) * num2;
			_currentFovDelta = Mathf.Sin(_swayPhase * MathF.PI * 1.7f) * dizziness * 1.5f * num;
			float num3 = ((dizziness <= 0.5f) ? (dizziness * 2f) : ((1f - dizziness) * 2f));
			float num4 = 0.012f * num3 * num;
			if (staminaDeficit >= 0.95f)
			{
				num4 += 0.055f * num;
				_currentRoll += Mathf.Sin(Time.time * 8f) * 1.4f * num;
				_currentFovDelta += Mathf.Sin(Time.time * 11f) * 2f * num;
			}
			_currentJitter = new Vector3(Random.Range(-1f, 1f) * num4, Random.Range(-1f, 1f) * num4, 0f);
		}

		private void OnPreCull()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_cam == (Object)null) && (Mathf.Abs(_currentRoll) > 0.001f || Mathf.Abs(_currentFovDelta) > 0.001f || ((Vector3)(ref _currentJitter)).sqrMagnitude > 1E-05f))
			{
				Camera cam = _cam;
				cam.fieldOfView += _currentFovDelta;
				Transform transform = ((Component)this).transform;
				transform.Rotate(0f, 0f, _currentRoll, (Space)1);
				transform.localPosition += _currentJitter;
			}
		}

		private void OnPostRender()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_cam == (Object)null) && (Mathf.Abs(_currentRoll) > 0.001f || Mathf.Abs(_currentFovDelta) > 0.001f || ((Vector3)(ref _currentJitter)).sqrMagnitude > 1E-05f))
			{
				Transform transform = ((Component)this).transform;
				transform.localPosition -= _currentJitter;
				transform.Rotate(0f, 0f, 0f - _currentRoll, (Space)1);
				Camera cam = _cam;
				cam.fieldOfView -= _currentFovDelta;
			}
		}
	}
	public static class DizzinessDrive
	{
		public static float s_impactMuffleUntil = -1f;

		public const float IMPACT_MUFFLE_DURATION = 1.6f;

		private const float STAMINA_CONTRIB_START = 0.8f;

		public static float GetStaminaDeficit(Character c)
		{
			if ((Object)(object)c == (Object)null || (Object)(object)c.data == (Object)null)
			{
				return 0f;
			}
			try
			{
				float maxStamina = c.GetMaxStamina();
				if (maxStamina <= 0.001f)
				{
					return 0f;
				}
				float currentStamina = c.data.currentStamina;
				return Mathf.Clamp01(1f - currentStamina / maxStamina);
			}
			catch
			{
				return 0f;
			}
		}

		private static float StaminaContribution(Character c)
		{
			float staminaDeficit = GetStaminaDeficit(c);
			if (staminaDeficit <= 0.8f)
			{
				return 0f;
			}
			return (staminaDeficit - 0.8f) / 0.19999999f;
		}

		public static float GetVisualDrive(Character c, float dv)
		{
			return Mathf.Max(dv, StaminaContribution(c));
		}

		public static float GetRingDrive(Character c, float dv)
		{
			return Mathf.Max(dv, StaminaContribution(c) / 3f);
		}

		public static bool IsImpactMuffleActive()
		{
			return Time.time < s_impactMuffleUntil;
		}

		public static float GetImpactMuffleFactor()
		{
			if (!IsImpactMuffleActive())
			{
				return 0f;
			}
			return Mathf.Clamp01((s_impactMuffleUntil - Time.time) / 1.6f);
		}

		public static void TriggerImpactMuffle()
		{
			s_impactMuffleUntil = Time.time + 1.6f;
		}
	}
	public class DizzinessOverlayUI : MonoBehaviour
	{
		private const float DEATH_FREEZE_DURATION = 3f;

		private static DizzinessOverlayUI _instance;

		private Canvas _canvas;

		private RawImage _vignetteImg;

		private RawImage _hazeImg;

		private RawImage _grainImg;

		private Texture2D _white1x1;

		private float _grainScrollX;

		private float _grainScrollY;

		private bool _wasDead;

		private float _deathFreezeUntil = -1f;

		private float _deathFrozenDrive;

		private float _smoothedDrive;

		private float _lastLogTime;

		public static void EnsureCreated()
		{
			//IL_0013: 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_001e: Expected O, but got Unknown
			if (!((Object)(object)_instance != (Object)null))
			{
				GameObject val = new GameObject("DizzinessOverlayUI");
				Object.DontDestroyOnLoad((Object)val);
				_instance = val.AddComponent<DizzinessOverlayUI>();
				ManualLogSource logger = DizzinessPlugin.Logger;
				if (logger != null)
				{
					logger.LogInfo((object)"[Overlay] Canvas created.");
				}
			}
		}

		private void Awake()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: 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_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			_instance = this;
			_canvas = ((Component)this).gameObject.AddComponent<Canvas>();
			_canvas.renderMode = (RenderMode)0;
			_canvas.sortingOrder = -100;
			((Component)this).gameObject.AddComponent<CanvasScaler>().uiScaleMode = (ScaleMode)0;
			_white1x1 = new Texture2D(1, 1);
			_white1x1.SetPixel(0, 0, Color.white);
			_white1x1.Apply();
			_vignetteImg = MakeFullscreenImage("Vignette");
			_hazeImg = MakeFullscreenImage("Haze");
			_grainImg = MakeFullscreenImage("Grain");
			_vignetteImg.texture = (Texture)(object)(((Object)(object)DizzinessPlugin.Instance != (Object)null) ? DizzinessPlugin.Instance.GetVignetteTex() : _white1x1);
			_hazeImg.texture = (Texture)(object)_white1x1;
			_grainImg.texture = (Texture)(object)(((Object)(object)DizzinessPlugin.Instance != (Object)null) ? DizzinessPlugin.Instance.GetGrainTex() : _white1x1);
			if ((Object)(object)_grainImg.texture != (Object)null)
			{
				_grainImg.uvRect = new Rect(0f, 0f, (float)Screen.width / 128f, (float)Screen.height / 128f);
			}
			((Graphic)_vignetteImg).color = new Color(0f, 0f, 0f, 0f);
			((Graphic)_hazeImg).color = new Color(1f, 1f, 1f, 0f);
			((Graphic)_grainImg).color = new Color(1f, 1f, 1f, 0f);
		}

		private RawImage MakeFullscreenImage(string name)
		{
			//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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(((Component)this).transform, false);
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.anchorMin = Vector2.zero;
			obj.anchorMax = Vector2.one;
			obj.offsetMin = Vector2.zero;
			obj.offsetMax = Vector2.zero;
			RawImage obj2 = val.AddComponent<RawImage>();
			((Graphic)obj2).raycastTarget = false;
			return obj2;
		}

		private static float ComputeDrive(out float rawDv)
		{
			rawDv = 0f;
			Character localCharacter = Character.localCharacter;
			if ((Object)(object)localCharacter == (Object)null)
			{
				return 0f;
			}
			DizzinessTracker component = ((Component)localCharacter).GetComponent<DizzinessTracker>();
			rawDv = (((Object)(object)component != (Object)null) ? component.dizzinessValue : 0f);
			return DizzinessDrive.GetVisualDrive(localCharacter, rawDv);
		}

		private void Update()
		{
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			Character localCharacter = Character.localCharacter;
			bool flag = (Object)(object)localCharacter != (Object)null && (Object)(object)localCharacter.data != (Object)null && localCharacter.data.dead;
			if (flag && !_wasDead)
			{
				_deathFrozenDrive = ComputeDrive(out var _);
				_deathFreezeUntil = Time.time + 3f;
			}
			_wasDead = flag;
			float num = Mathf.Clamp01((DizzinessPlugin.cfgVisualIntensity != null) ? DizzinessPlugin.cfgVisualIntensity.Value : 1f);
			bool num2 = (DizzinessPlugin.cfgDisableVignette != null && DizzinessPlugin.cfgDisableVignette.Value) || num <= 0.001f;
			float rawDv2;
			float num3 = ComputeDrive(out rawDv2);
			if (flag && Time.time < _deathFreezeUntil)
			{
				float num4 = 1f - (_deathFreezeUntil - Time.time) / 3f;
				num3 = Mathf.Max(num3, _deathFrozenDrive * (1f - num4));
			}
			else if (flag)
			{
				num3 = 0f;
			}
			_smoothedDrive = Mathf.MoveTowards(_smoothedDrive, num3, Time.unscaledDeltaTime * 0.9f);
			float smoothedDrive = _smoothedDrive;
			if (num2 || smoothedDrive <= 0.4f)
			{
				SetAlpha(_vignetteImg, 0f);
				SetAlpha(_hazeImg, 0f);
				SetAlpha(_grainImg, 0f);
				return;
			}
			float num5 = (smoothedDrive - 0.4f) / 0.6f;
			float num6 = (num5 * 0.36f + num5 * num5 * 0.36f) * num;
			float a = num5 * num5 * 0.13f * num;
			if (Time.time - _lastLogTime > 1f)
			{
				_lastLogTime = Time.time;
				ManualLogSource logger = DizzinessPlugin.Logger;
				if (logger != null)
				{
					logger.LogInfo((object)$"[Overlay] dv={rawDv2:F2} drive={smoothedDrive:F2} vigA={num6:F3} imgSet={(Object)(object)_vignetteImg != (Object)null && (Object)(object)_vignetteImg.texture != (Object)null}");
				}
			}
			float a2 = 0f;
			if (smoothedDrive > 0.9f)
			{
				a2 = (smoothedDrive - 0.9f) / 0.100000024f * 0.05f * num;
			}
			SetAlpha(_vignetteImg, num6);
			SetAlpha(_hazeImg, a);
			SetAlpha(_grainImg, a2);
			if ((Object)(object)_grainImg != (Object)null && (Object)(object)_grainImg.texture != (Object)null)
			{
				_grainScrollX = (_grainScrollX + Time.unscaledDeltaTime * 0.32f) % 1f;
				_grainScrollY = (_grainScrollY + Time.unscaledDeltaTime * 0.21f) % 1f;
				_grainImg.uvRect = new Rect(_grainScrollX, _grainScrollY, (float)Screen.width / 128f, (float)Screen.height / 128f);
			}
		}

		private static void SetAlpha(RawImage img, float a)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)img == (Object)null))
			{
				Color color = ((Graphic)img).color;
				color.a = a;
				((Graphic)img).color = color;
			}
		}
	}
	[BepInPlugin("com.tambistudios.dizziness", "Dizziness From Speed", "1.5.1")]
	public class DizzinessPlugin : BaseUnityPlugin
	{
		public const string MOD_GUID = "com.tambistudios.dizziness";

		public const string MOD_NAME = "Dizziness From Speed";

		public const string MOD_VERSION = "1.5.1";

		public static DizzinessPlugin Instance;

		public static ManualLogSource Logger;

		public static ConfigEntry<bool> debugMode;

		public static ConfigEntry<float> cfgVisualIntensity;

		public static ConfigEntry<bool> cfgDisableCameraSway;

		public static ConfigEntry<bool> cfgDisableVignette;

		public static ConfigEntry<bool> cfgDisableEarRinging;

		public static ConfigEntry<bool> cfgEnableRockImpact;

		public static ConfigEntry<bool> cfgEnableBossImpact;

		public static ConfigEntry<bool> cfgEnableBleedSynergy;

		public const float MIN_SPEED_THRESHOLD = 7f;

		public const float REST_SPEED_THRESHOLD = 7f;

		public const float DIZZINESS_GAIN_BASE = 0.0012f;

		public const float MAX_GAIN_PER_SEC = 0.3f;

		public const float REST_DURATION = 12f;

		public const float RECOVERY_PER_SEC = 0.05f;

		public const float GROUND_CHECK_RAY_LENGTH = 1.5f;

		public const float BUGLE_RADIUS = 30f;

		public const float BUGLE_RECOVERY_PER_SEC = 0.05f;

		public const float DYNAMITE_CLOSE_RADIUS = 5f;

		public const float DYNAMITE_FAR_RADIUS = 20f;

		public const float PASSOUT_RECOVERY_THRESHOLD = 0.2f;

		public static readonly Color DizzinessColor = new Color(0f, 0.80784315f, 0.81960785f, 1f);

		public static Sprite DizzinessIconSprite;

		public const string CUSTOM_BAR_NAME = "DizzinessCustomBar";

		private Texture2D _guiTex;

		private Texture2D _vignetteTex;

		private Texture2D _grainTex;

		private float _grainOffsetX;

		private float _grainOffsetY;

		private float _concussionFlash;

		private float _smoothedDrive;

		private float _lastGuiTime;

		public const float EXPEDITION_GRACE_SECONDS = 10f;

		private void Awake()
		{
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			debugMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableDebugKeys", false, "Enables F5 (teleport 100m up), F7 (set dizziness 50%) and on-screen debug HUD.");
			cfgVisualIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("Visuals", "VisualIntensity", 1f, "Scales ALL dizziness visual effects (vignette, camera sway, concussion flash). 0 = disabled, 1 = full. Use lower values if you're motion-sick sensitive.");
			cfgDisableCameraSway = ((BaseUnityPlugin)this).Config.Bind<bool>("Visuals", "DisableCameraSway", false, "Fully disable the camera roll + FOV sway. Overrides VisualIntensity for camera only.");
			cfgDisableVignette = ((BaseUnityPlugin)this).Config.Bind<bool>("Visuals", "DisableVignette", false, "Fully disable the dark edges + haze overlay. Overrides VisualIntensity for the vignette only.");
			cfgDisableEarRinging = ((BaseUnityPlugin)this).Config.Bind<bool>("Audio", "DisableEarRinging", false, "Disable the muffled + high-pitched tinnitus effect that kicks in above 50% dizziness.");
			cfgEnableRockImpact = ((BaseUnityPlugin)this).Config.Bind<bool>("Triggers", "EnableRockImpact", true, "Getting hit by falling rocks / icicles adds dizziness. (deprecated, always on)");
			cfgEnableBossImpact = ((BaseUnityPlugin)this).Config.Bind<bool>("Triggers", "EnableBossImpact", true, "Being knocked around by bosses adds dizziness. (deprecated, always on)");
			cfgEnableBleedSynergy = ((BaseUnityPlugin)this).Config.Bind<bool>("Synergy", "EnableBleedSynergy", true, "Heavy bleeding builds passive dizziness. (deprecated, always on)");
			LoadIconSprite();
			_vignetteTex = GenerateVignette(128);
			_grainTex = GenerateGrain(256);
			try
			{
				new Harmony("com.tambistudios.dizziness").PatchAll();
				IEnumerable<MethodBase> allPatchedMethods = Harmony.GetAllPatchedMethods();
				int num = 0;
				foreach (MethodBase item in allPatchedMethods)
				{
					_ = item;
					num++;
				}
				Logger.LogInfo((object)string.Format("[{0} {1}] Loaded. Harmony patches active: {2}", "Dizziness From Speed", "1.2.0", num));
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"Harmony patch failed: {arg}");
			}
		}

		private static void LoadIconSprite()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("DizzinessMod.Assets.dizziness_icon.png");
				if (stream == null)
				{
					Logger.LogWarning((object)"Embedded icon not found in resources!");
					return;
				}
				using MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				((Texture)val).wrapMode = (TextureWrapMode)1;
				((Texture)val).filterMode = (FilterMode)1;
				if (ImageConversion.LoadImage(val, memoryStream.ToArray()))
				{
					DizzinessIconSprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
					Logger.LogInfo((object)$"Icon loaded: {((Texture)val).width}x{((Texture)val).height}");
				}
				else
				{
					Logger.LogWarning((object)"ImageConversion.LoadImage failed — icon will be missing.");
				}
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"LoadIconSprite failed: {arg}");
			}
		}

		public static float GetEtcDamageMultiplier()
		{
			try
			{
				return Ascents.etcDamageMultiplier;
			}
			catch
			{
				return 1f;
			}
		}

		public static bool IsDizzinessDisabled()
		{
			return IsDizzinessDisabledByOption();
		}

		public static bool IsInExpeditionGrace()
		{
			return Time.timeSinceLevelLoad < 10f;
		}

		public static bool IsInLobby()
		{
			try
			{
				return !GameHandler.IsInGameplayScene;
			}
			catch
			{
				return false;
			}
		}

		public static float GetGainMultiplier()
		{
			return TambiAfflictionOption.GetValue("Dizziness") switch
			{
				0 => 0f, 
				1 => 1f, 
				2 => 3f, 
				3 => 5f, 
				_ => 3f, 
			};
		}

		public static bool IsDizzinessDisabledByOption()
		{
			return TambiAfflictionOption.GetValue("Dizziness") == 0;
		}

		private static Texture2D GenerateVignette(int size)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
			((Texture)val).filterMode = (FilterMode)1;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			float num = (float)size * 0.5f;
			Color32[] array = (Color32[])(object)new Color32[size * size];
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num2 = ((float)j - num) / num;
					float num3 = ((float)i - num) / num;
					float num4 = Mathf.Clamp01((Mathf.Sqrt(num2 * num2 + num3 * num3) - 0.35f) / 0.65f);
					num4 *= num4;
					array[i * size + j] = new Color32((byte)0, (byte)0, (byte)0, (byte)(num4 * 255f));
				}
			}
			val.SetPixels32(array);
			val.Apply(false);
			return val;
		}

		private static Texture2D GenerateGrain(int size)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
			((Texture)val).filterMode = (FilterMode)1;
			((Texture)val).wrapMode = (TextureWrapMode)0;
			Color32[] array = (Color32[])(object)new Color32[size * size];
			Random random = new Random(1337);
			for (int i = 0; i < array.Length; i++)
			{
				byte b = (byte)random.Next(0, 256);
				array[i] = new Color32(b, b, b, byte.MaxValue);
			}
			val.SetPixels32(array);
			val.Apply(false);
			return val;
		}

		internal Texture2D GetVignetteTex()
		{
			return _vignetteTex;
		}

		internal Texture2D GetGrainTex()
		{
			return _grainTex;
		}

		internal void TriggerConcussionFlash(float strength)
		{
			_concussionFlash = Mathf.Max(_concussionFlash, 0.5f + strength * 0.7f);
		}

		private void Update()
		{
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (_concussionFlash > 0f)
			{
				_concussionFlash = Mathf.Max(0f, _concussionFlash - Time.deltaTime * 1.4f);
			}
			Character localCharacter = Character.localCharacter;
			if ((Object)(object)localCharacter != (Object)null && (Object)(object)((Component)localCharacter).GetComponent<DizzinessTracker>() == (Object)null)
			{
				((Component)localCharacter).gameObject.AddComponent<DizzinessTracker>();
				if ((Object)(object)((Component)localCharacter).GetComponent<DizzinessRpcReceiver>() == (Object)null)
				{
					((Component)localCharacter).gameObject.AddComponent<DizzinessRpcReceiver>();
				}
				Logger.LogInfo((object)"DizzinessTracker attached (fallback).");
			}
			DizzinessBarInjector.TryInjectBar();
			Camera main = Camera.main;
			if ((Object)(object)main != (Object)null && (Object)(object)((Component)main).GetComponent<DizzinessCameraEffect>() == (Object)null)
			{
				((Component)main).gameObject.AddComponent<DizzinessCameraEffect>();
			}
			DizzinessAudioEffect.EnsureAttached();
			DizzinessOverlayUI.EnsureCreated();
			if (!debugMode.Value || !((Object)(object)localCharacter != (Object)null))
			{
				return;
			}
			if (Input.GetKeyDown((KeyCode)286))
			{
				Rigidbody playerRigidbody = DizzinessTracker.GetPlayerRigidbody(localCharacter);
				if ((Object)(object)playerRigidbody != (Object)null)
				{
					Transform transform = ((Component)playerRigidbody).transform;
					transform.position += Vector3.up * 100f;
					Logger.LogInfo((object)"[F5] Teleported +100m up.");
				}
			}
			if (Input.GetKeyDown((KeyCode)288))
			{
				DizzinessTracker component = ((Component)localCharacter).GetComponent<DizzinessTracker>();
				if ((Object)(object)component != (Object)null)
				{
					component.dizzinessValue = 0.5f;
					Logger.LogInfo((object)"[F7] Forced dizziness = 0.5");
				}
			}
		}

		private void OnGUI()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Expected O, but got Unknown
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Event.current.type == 7)
			{
				if ((Object)(object)_guiTex == (Object)null)
				{
					_guiTex = new Texture2D(1, 1);
					_guiTex.SetPixel(0, 0, Color.white);
					_guiTex.Apply();
				}
				Color color = GUI.color;
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(0f, 0f, (float)Screen.width, (float)Screen.height);
				float num = Mathf.Clamp01((cfgVisualIntensity != null) ? cfgVisualIntensity.Value : 1f);
				if (_concussionFlash > 0f && num > 0.001f)
				{
					float num2 = _concussionFlash / 1.2f;
					GUI.color = new Color(1f, 0.95f, 0.85f, num2 * 0.75f * num);
					GUI.DrawTexture(val, (Texture)(object)_guiTex);
				}
				GUI.color = color;
			}
			if (!debugMode.Value)
			{
				return;
			}
			Character localCharacter = Character.localCharacter;
			if ((Object)(object)localCharacter == (Object)null)
			{
				return;
			}
			DizzinessTracker component = ((Component)localCharacter).GetComponent<DizzinessTracker>();
			if ((Object)(object)component != (Object)null)
			{
				GUIStyle val2 = new GUIStyle();
				val2.fontSize = 18;
				val2.normal.textColor = Color.white;
				float num3 = 0f;
				Rigidbody playerRigidbody = DizzinessTracker.GetPlayerRigidbody(localCharacter);
				if ((Object)(object)playerRigidbody != (Object)null)
				{
					Vector3 linearVelocity = playerRigidbody.linearVelocity;
					num3 = ((Vector3)(ref linearVelocity)).magnitude;
				}
				float etcDamageMultiplier = GetEtcDamageMultiplier();
				float gainMultiplier = GetGainMultiplier();
				string text = (IsDizzinessDisabled() ? "DISABLED" : $"x{gainMultiplier:F0}");
				float statusSum = localCharacter.refs.afflictions.statusSum;
				float maxStamina = localCharacter.GetMaxStamina();
				float currentStamina = localCharacter.data.currentStamina;
				GUI.Label(new Rect(20f, 100f, 700f, 30f), $"Speed: {num3:F1}   Dizziness: {component.dizzinessValue:F3}   etcMult: {etcDamageMultiplier:F2} ({text})", val2);
				GUI.Label(new Rect(20f, 122f, 700f, 30f), $"Ground: {component.isGrounded}   Climb: {component.isClimbing}   Resting: {component.IsResting}   RestTimer: {component.restTimer:F2}/{12f}", val2);
				GUI.Label(new Rect(20f, 144f, 700f, 30f), $"FullyOut: {localCharacter.data.fullyPassedOut}   Sum: {statusSum:F2}   MaxStam: {maxStamina:F2}   CurStam: {currentStamina:F2}", val2);
			}
		}
	}
	public class DizzinessRpcReceiver : MonoBehaviourPun
	{
		[PunRPC]
		public void Dizziness_RPC_Sync(float value)
		{
			DizzinessTracker component = ((Component)this).GetComponent<DizzinessTracker>();
			if ((Object)(object)component != (Object)null && (Object)(object)component.character != (Object)null && !component.character.IsLocal)
			{
				component.dizzinessValue = Mathf.Clamp01(value);
			}
		}
	}
	public class DizzinessTracker : MonoBehaviour
	{
		public Character character;

		public float dizzinessValue;

		public float restTimer;

		public bool isGrounded;

		public bool isClimbing;

		public bool recentlyPassedOut;

		public bool wasFullyPassedOut;

		public bool statusSumSeenPassOut;

		private bool _wasGrounded;

		private float _peakFallSpeed;

		private float _passOutStart = -1f;

		private Vector3 _prevVelocity;

		private bool _prevVelValid;

		private float _collisionCooldown;

		private Quaternion _prevCamRot;

		private bool _prevCamRotValid;

		private float lastSyncSent;

		private const float SYNC_INTERVAL = 0.2f;

		private Rigidbody _cachedRb;

		private static FieldInfo _groundedField;

		private static bool _groundedFieldSearched;

		private static FieldInfo[] _climbingFields;

		private static bool _climbingFieldsSearched;

		private const float EXPEDITION_GRACE_SECONDS = 10f;

		private const float PASSIVE_DRAIN_PER_SEC = 0.05f;

		public bool IsResting
		{
			get
			{
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				if (isClimbing)
				{
					return false;
				}
				Rigidbody playerRigidbody = GetPlayerRigidbody(character);
				if ((Object)(object)playerRigidbody == (Object)null)
				{
					return false;
				}
				Vector3 linearVelocity = playerRigidbody.linearVelocity;
				return ((Vector3)(ref linearVelocity)).magnitude < 7f;
			}
		}

		public static Rigidbody GetPlayerRigidbody(Character c)
		{
			if ((Object)(object)c == (Object)null)
			{
				return null;
			}
			DizzinessTracker component = ((Component)c).GetComponent<DizzinessTracker>();
			if ((Object)(object)component != (Object)null)
			{
				if ((Object)(object)component._cachedRb != (Object)null)
				{
					return component._cachedRb;
				}
				component._cachedRb = ((Component)c).GetComponentInChildren<Rigidbody>();
				return component._cachedRb;
			}
			return ((Component)c).GetComponentInChildren<Rigidbody>();
		}

		private void Awake()
		{
			character = ((Component)this).GetComponent<Character>();
		}

		private void Update()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)character == (Object)null || !character.IsLocal)
			{
				return;
			}
			bool wasGrounded = _wasGrounded;
			isGrounded = DetectGrounded();
			isClimbing = DetectClimbing();
			Rigidbody playerRigidbody = GetPlayerRigidbody(character);
			if ((Object)(object)playerRigidbody != (Object)null && !isGrounded)
			{
				float y = playerRigidbody.linearVelocity.y;
				if (y < -3f)
				{
					_peakFallSpeed = Mathf.Max(_peakFallSpeed, 0f - y);
				}
			}
			if (isGrounded && !wasGrounded)
			{
				if (_peakFallSpeed > 6f && dizzinessValue > 0.3f && !SpiderCheck.IsGrabbedBySpider(character))
				{
					DizzinessDrive.TriggerImpactMuffle();
				}
				if ((character.data.fullyPassedOut || wasFullyPassedOut) && !SpiderCheck.IsGrabbedBySpider(character))
				{
					try
					{
						float num = dizzinessValue * 0.5f;
						if (num > 0.01f)
						{
							character.refs.afflictions.AddStatus((STATUSTYPE)0, num, false, true, true, false);
							DizzinessPlugin.Logger.LogInfo((object)$"Passout landing: dv {dizzinessValue:F2} → +{num:F2} Injury");
						}
					}
					catch (Exception ex)
					{
						ManualLogSource logger = DizzinessPlugin.Logger;
						if (logger != null)
						{
							logger.LogWarning((object)("Passout landing injury failed: " + ex.Message));
						}
					}
				}
				_peakFallSpeed = 0f;
			}
			_wasGrounded = isGrounded;
			bool fullyPassedOut = character.data.fullyPassedOut;
			if (fullyPassedOut && !wasFullyPassedOut)
			{
				_passOutStart = Time.time;
			}
			if (!fullyPassedOut)
			{
				_passOutStart = -1f;
			}
			if (fullyPassedOut && _passOutStart > 0f)
			{
				bool flag = false;
				try
				{
					flag = PhotonNetwork.InRoom && PhotonNetwork.CurrentRoom != null && PhotonNetwork.CurrentRoom.PlayerCount > 1;
				}
				catch
				{
					flag = false;
				}
				float num2 = (flag ? 8f : 6f);
				if (Time.time - _passOutStart >= num2 && dizzinessValue > 0f)
				{
					dizzinessValue = Mathf.Max(0f, dizzinessValue - 0.15f * Time.deltaTime);
					MaybeSendSync();
				}
			}
			if (wasFullyPassedOut && !fullyPassedOut)
			{
				float maxStamina = character.GetMaxStamina();
				if (maxStamina > 0.001f)
				{
					character.data.currentStamina = maxStamina;
				}
				dizzinessValue = 0f;
				MaybeSendSync();
				recentlyPassedOut = true;
				DizzinessPlugin.Logger.LogInfo((object)"Recovered from pass-out: stamina + dizziness reset.");
			}
			wasFullyPassedOut = fullyPassedOut;
			if (recentlyPassedOut && dizzinessValue < 0.1f)
			{
				recentlyPassedOut = false;
			}
			ApplyBugleEffect();
			if (DizzinessPlugin.IsDizzinessDisabled())
			{
				if (dizzinessValue > 0f)
				{
					dizzinessValue = Mathf.Max(0f, dizzinessValue - 0.05f * Time.deltaTime);
					MaybeSendSync();
				}
			}
			else
			{
				UpdateLocalDizziness();
				MaybeSendSync();
			}
		}

		private void ApplyBugleEffect()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			if (dizzinessValue <= 0f)
			{
				return;
			}
			BugleSFX[] array = Object.FindObjectsOfType<BugleSFX>();
			if (array == null || array.Length == 0)
			{
				return;
			}
			Vector3 position = ((Component)this).transform.position;
			bool flag = false;
			BugleSFX[] array2 = array;
			foreach (BugleSFX val in array2)
			{
				if ((Object)(object)val != (Object)null && val.hold && Vector3.Distance(position, ((Component)val).transform.position) <= 30f)
				{
					flag = true;
					break;
				}
			}
			if (flag)
			{
				dizzinessValue = Mathf.Max(0f, dizzinessValue - 0.05f * Time.deltaTime);
			}
		}

		private bool DetectGrounded()
		{
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			if (!_groundedFieldSearched && (Object)(object)character.data != (Object)null)
			{
				_groundedFieldSearched = true;
				FieldInfo field = ((object)character.data).GetType().GetField("isGrounded", BindingFlags.Instance | BindingFlags.Public);
				if (field != null && field.FieldType == typeof(bool))
				{
					_groundedField = field;
					DizzinessPlugin.Logger.LogInfo((object)"Ground detect: using character.data.isGrounded");
				}
			}
			if (_groundedField != null && (Object)(object)character.data != (Object)null)
			{
				try
				{
					return (bool)_groundedField.GetValue(character.data);
				}
				catch
				{
				}
			}
			Rigidbody playerRigidbody = GetPlayerRigidbody(character);
			if ((Object)(object)playerRigidbody == (Object)null)
			{
				return false;
			}
			return Physics.Raycast(((Component)playerRigidbody).transform.position + Vector3.up * 0.5f, Vector3.down, 1.5f, -1, (QueryTriggerInteraction)1);
		}

		private bool DetectClimbing()
		{
			if (!_climbingFieldsSearched && (Object)(object)character.data != (Object)null)
			{
				_climbingFieldsSearched = true;
				Type type = ((object)character.data).GetType();
				string[] obj = new string[3] { "isClimbing", "isRopeClimbing", "isVineClimbing" };
				List<FieldInfo> list = new List<FieldInfo>();
				string[] array = obj;
				foreach (string text in array)
				{
					FieldInfo field = type.GetField(text, BindingFlags.Instance | BindingFlags.Public);
					if (field != null && field.FieldType == typeof(bool))
					{
						list.Add(field);
						DizzinessPlugin.Logger.LogInfo((object)("Climb detect: found character.data." + text));
					}
				}
				_climbingFields = list.ToArray();
			}
			if (_climbingFields == null || (Object)(object)character.data == (Object)null)
			{
				return false;
			}
			try
			{
				FieldInfo[] climbingFields = _climbingFields;
				for (int j = 0; j < climbingFields.Length; j++)
				{
					if ((bool)climbingFields[j].GetValue(character.data))
					{
						return true;
					}
				}
			}
			catch
			{
			}
			return false;
		}

		private void UpdateLocalDizziness()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			bool flag = SpiderCheck.IsGrabbedBySpider(character);
			bool flag2 = Time.timeSinceLevelLoad < 10f || DizzinessPlugin.IsInLobby();
			bool flag3 = false;
			if (IsResting)
			{
				restTimer += Time.deltaTime;
			}
			else
			{
				restTimer = 0f;
			}
			Rigidbody playerRigidbody = GetPlayerRigidbody(character);
			Vector3 val;
			if ((Object)(object)playerRigidbody != (Object)null)
			{
				val = playerRigidbody.linearVelocity;
				float magnitude = ((Vector3)(ref val)).magnitude;
				if (!isGrounded && !character.data.fullyPassedOut && magnitude > 9.33f && !flag && !flag2)
				{
					float gainMultiplier = DizzinessPlugin.GetGainMultiplier();
					float num = magnitude - 9.33f;
					float num2 = num * num * 0.000395f * gainMultiplier;
					dizzinessValue = Mathf.Min(1f, dizzinessValue + num2 * Time.deltaTime);
					flag3 = true;
				}
			}
			if (!flag && DizzinessPlugin.cfgEnableBleedSynergy != null && DizzinessPlugin.cfgEnableBleedSynergy.Value)
			{
				int bleedLevel = BleedingBridge.GetBleedLevel();
				if (bleedLevel >= 2)
				{
					float num3 = ((bleedLevel == 3) ? 0.025f : 0.01f);
					dizzinessValue = Mathf.Min(1f, dizzinessValue + num3 * Time.deltaTime);
					flag3 = true;
				}
			}
			if ((Object)(object)playerRigidbody != (Object)null && !flag && !flag2 && _collisionCooldown <= 0f)
			{
				Vector3 linearVelocity = playerRigidbody.linearVelocity;
				if (_prevVelValid)
				{
					val = linearVelocity - _prevVelocity;
					float magnitude2 = ((Vector3)(ref val)).magnitude;
					if (magnitude2 > 14.4f && !isGrounded)
					{
						float gainMultiplier2 = DizzinessPlugin.GetGainMultiplier();
						float num4 = Mathf.Min((magnitude2 - 14.4f) * 0.005f * gainMultiplier2, 0.25f);
						dizzinessValue = Mathf.Min(1f, dizzinessValue + num4);
						_collisionCooldown = 0.25f;
						flag3 = true;
					}
				}
				_prevVelocity = linearVelocity;
				_prevVelValid = true;
			}
			if (_collisionCooldown > 0f)
			{
				_collisionCooldown -= Time.deltaTime;
			}
			Camera main = Camera.main;
			if ((Object)(object)main != (Object)null && !flag && !flag2)
			{
				Quaternion rotation = ((Component)main).transform.rotation;
				if (_prevCamRotValid && Time.deltaTime > 0.0001f)
				{
					float num5 = Quaternion.Angle(_prevCamRot, rotation) / Time.deltaTime;
					if (num5 > 480f)
					{
						float num6 = Mathf.Min((num5 - 480f) * 3E-05f, 0.02f);
						dizzinessValue = Mathf.Min(1f, dizzinessValue + num6 * Time.deltaTime);
						flag3 = true;
					}
				}
				_prevCamRot = rotation;
				_prevCamRotValid = true;
			}
			if (!flag3 && dizzinessValue > 0f && !character.data.fullyPassedOut)
			{
				if (isGrounded)
				{
					restTimer += Time.deltaTime;
					if (restTimer >= 3f)
					{
						dizzinessValue = Mathf.Max(0f, dizzinessValue - 0.08f * Time.deltaTime);
					}
				}
				else if (isClimbing)
				{
					restTimer += Time.deltaTime;
					if (restTimer >= 5f)
					{
						dizzinessValue = Mathf.Max(0f, dizzinessValue - 0.08f * Time.deltaTime);
					}
				}
				else
				{
					restTimer = 0f;
				}
			}
			else
			{
				restTimer = 0f;
			}
		}

		public void AddFromExplosion(Vector3 explosionPos)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (DizzinessPlugin.IsDizzinessDisabled() || SpiderCheck.IsGrabbedBySpider(character) || DizzinessPlugin.IsInExpeditionGrace())
			{
				return;
			}
			float num = Vector3.Distance(((Component)this).transform.position, explosionPos);
			if (!(num >= 20f))
			{
				float num2;
				if (num <= 5f)
				{
					num2 = 1f;
				}
				else
				{
					float num3 = (num - 5f) / 15f;
					num2 = 1f - num3;
				}
				float gainMultiplier = DizzinessPlugin.GetGainMultiplier();
				num2 *= gainMultiplier * 0.3f;
				dizzinessValue = Mathf.Min(1f, dizzinessValue + num2);
				DizzinessPlugin.Logger.LogInfo((object)$"Dynamite at dist {num:F1}m → dizziness +{num2:F2} (now {dizzinessValue:F2})");
				float strength = ((gainMultiplier > 0.001f) ? (num2 / (gainMultiplier * 0.3f)) : 0f);
				DizzinessPlugin.Instance?.TriggerConcussionFlash(strength);
			}
		}

		private void MaybeSendSync()
		{
			if (Time.time - lastSyncSent < 0.2f)
			{
				return;
			}
			lastSyncSent = Time.time;
			PhotonView component = ((Component)character).GetComponent<PhotonView>();
			if ((Object)(object)component == (Object)null || !PhotonNetwork.InRoom)
			{
				return;
			}
			try
			{
				component.RPC("Dizziness_RPC_Sync", (RpcTarget)1, new object[1] { dizzinessValue });
			}
			catch (Exception ex)
			{
				DizzinessPlugin.Logger.LogWarning((object)("RPC send failed: " + ex.Message));
			}
		}
	}
	[HarmonyPatch]
	internal static class Dynamite_RPC_Explode_Patch
	{
		private static MethodBase TargetMethod()
		{
			return AccessTools.Method(typeof(Dynamite), "RPC_Explode", (Type[])null, (Type[])null);
		}

		[HarmonyPostfix]
		private static void Postfix(Dynamite __instance)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Character localCharacter = Character.localCharacter;
				if ((Object)(object)localCharacter != (Object)null)
				{
					DizzinessTracker component = ((Component)localCharacter).GetComponent<DizzinessTracker>();
					if ((Object)(object)component != (Object)null)
					{
						component.AddFromExplosion(((Component)__instance).transform.position);
					}
				}
			}
			catch (Exception ex)
			{
				DizzinessPlugin.Logger.LogWarning((object)("Dynamite explode patch failed: " + ex.Message));
			}
		}
	}
	internal static class SpiderCheck
	{
		private const float WEB_THRESHOLD = 0.025f;

		public static bool IsGrabbedBySpider(Character c)
		{
			if ((Object)(object)c == (Object)null || c.refs == null || (Object)(object)c.refs.afflictions == (Object)null)
			{
				return false;
			}
			try
			{
				return c.refs.afflictions.GetCurrentStatus((STATUSTYPE)11) > 0.025f;
			}
			catch
			{
				return false;
			}
		}
	}
	public class TambiAfflictionOption : CustomOptionBase
	{
		private static readonly Dictionary<string, int> _values = new Dictionary<string, int>();

		public string modName;

		public string[] labels = new string[4] { "OFF", "LOW", "NORM", "HIGH" };

		public int defaultValue = 2;

		public Button button;

		public LocalizedText buttonText;

		public LocalizedText label;

		public Image buttonImage;

		public Color offColor;

		public Color defaultColor;

		public Color adjustedColor;

		public static int GetValue(string mod)
		{
			if (!_values.TryGetValue(mod, out var value))
			{
				return 2;
			}
			return value;
		}

		public static void SetValue(string mod, int value)
		{
			_values[mod] = value;
		}

		public static float GetMultiplier(string mod)
		{
			return GetValue(mod) switch
			{
				0 => 0f, 
				1 => 0.5f, 
				2 => 1f, 
				3 => 2f, 
				_ => 1f, 
			};
		}

		private void OnEnable()
		{
			if (!_values.ContainsKey(modName))
			{
				_values[modName] = defaultValue;
			}
			Refresh();
		}

		public override void OnClick()
		{
			((CustomOptionBase)this).OnClick();
			int value = GetValue(modName);
			value = (value + 1) % labels.Length;
			_values[modName] = value;
			Refresh();
		}

		public override void RestoreDefault()
		{
			_values[modName] = defaultValue;
			Refresh();
		}

		private void Refresh()
		{
			//IL_006f: 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)
			int value = GetValue(modName);
			if ((Object)(object)buttonText != (Object)null)
			{
				buttonText.autoSet = true;
				buttonText.SetIndex(labels[Mathf.Clamp(value, 0, labels.Length - 1)]);
			}
			if ((Object)(object)buttonImage != (Object)null)
			{
				((Graphic)buttonImage).color = ((value == defaultValue) ? defaultColor : adjustedColor);
			}
			if ((Object)(object)label != (Object)null)
			{
				label.SetText(modName);
			}
		}
	}
	[HarmonyPatch(typeof(CustomOptionsWindow), "Initialize")]
	internal static class TambiOptionInjector
	{
		private const string MOD_NAME = "Dizziness";

		private static bool _injected;

		[HarmonyPostfix]
		private static void Postfix(CustomOptionsWindow __instance)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Invalid comparison between Unknown and I4
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Expected O, but got Unknown
			if (_injected)
			{
				return;
			}
			try
			{
				CustomOptionMulti[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<CustomOptionMulti>(true);
				CustomOptionMulti val = null;
				CustomOptionMulti[] array = componentsInChildren;
				foreach (CustomOptionMulti val2 in array)
				{
					if ((int)val2.settingType == 400 || (int)val2.settingType == 300)
					{
						val = val2;
						break;
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				GameObject val3 = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)val).transform.parent);
				((Object)val3).name = "TambiOption_Dizziness";
				CustomOptionMulti component = val3.GetComponent<CustomOptionMulti>();
				if ((Object)(object)component == (Object)null)
				{
					Object.Destroy((Object)(object)val3);
					return;
				}
				Button button = component.button;
				LocalizedText buttonText = component.buttonText;
				LocalizedText label = component.label;
				Image buttonImage = component.buttonImage;
				Color offColor = component.offColor;
				Color defaultColor = component.defaultColor;
				Color adjustedColor = component.adjustedColor;
				string[] labels = component.labels;
				MonoBehaviour[] componentsInChildren2 = val3.GetComponentsInChildren<MonoBehaviour>(true);
				foreach (MonoBehaviour val4 in componentsInChildren2)
				{
					if (!((Object)(object)val4 == (Object)null))
					{
						if (val4 is EventTrigger)
						{
							Object.DestroyImmediate((Object)(object)val4);
						}
						else if (val4 is CustomOptionBase)
						{
							Object.DestroyImmediate((Object)(object)val4);
						}
						else if (val4 is CustomOptionTooltip)
						{
							Object.DestroyImmediate((Object)(object)val4);
						}
					}
				}
				TambiAfflictionOption tambiAfflictionOption = val3.AddComponent<TambiAfflictionOption>();
				tambiAfflictionOption.modName = "Dizziness";
				tambiAfflictionOption.button = button;
				tambiAfflictionOption.buttonText = buttonText;
				tambiAfflictionOption.label = label;
				tambiAfflictionOption.buttonImage = buttonImage;
				tambiAfflictionOption.offColor = offColor;
				tambiAfflictionOption.defaultColor = defaultColor;
				tambiAfflictionOption.adjustedColor = adjustedColor;
				tambiAfflictionOption.defaultValue = 2;
				if (labels != null && labels.Length != 0)
				{
					tambiAfflictionOption.labels = labels;
				}
				if ((Object)(object)button != (Object)null)
				{
					((UnityEventBase)button.onClick).RemoveAllListeners();
					((UnityEvent)button.onClick).AddListener(new UnityAction(((CustomOptionBase)tambiAfflictionOption).OnClick));
				}
				if ((Object)(object)label != (Object)null)
				{
					label.autoSet = false;
					label.index = "";
					label.SetText("Dizziness");
				}
				val3.SetActive(true);
				((Component)tambiAfflictionOption).SendMessage("Refresh", (SendMessageOptions)1);
				_injected = true;
				ManualLogSource logger = DizzinessPlugin.Logger;
				if (logger != null)
				{
					logger.LogInfo((object)"[TambiOption] Dizziness option injected.");
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger2 = DizzinessPlugin.Logger;
				if (logger2 != null)
				{
					logger2.LogWarning((object)("[TambiOption] Injection failed: " + ex.Message));
				}
			}
		}
	}
}