Decompiled source of AlwaysWingsView v3.0.0

AlwaysWingsView.dll

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace REPOJP.AlwaysWingsView
{
	[BepInPlugin("REPOJP.AlwaysWingsView", "AlwaysWingsView", "2.1.0")]
	public sealed class AlwaysWingsViewPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(ItemUpgradePlayerTumbleWingsLogic), "LoopSound")]
		private static class ItemUpgradePlayerTumbleWingsLogic_LoopSound_Patch
		{
			private static void Postfix(ItemUpgradePlayerTumbleWingsLogic __instance)
			{
				if ((Object)(object)Instance == (Object)null)
				{
					return;
				}
				try
				{
					if (!Instance._muteWingLoopSound.Value)
					{
						return;
					}
				}
				catch
				{
					return;
				}
				string text = "off";
				try
				{
					text = NormalizeMode(Instance._mode.Value);
				}
				catch
				{
					text = "off";
				}
				if (text == "off" || IsNullUnity(__instance))
				{
					return;
				}
				PlayerAvatar val = null;
				try
				{
					val = PlayerAvatar.instance;
				}
				catch
				{
					val = null;
				}
				if (IsNullUnity(val))
				{
					return;
				}
				try
				{
					if (IsNullUnity(__instance.playerAvatar) || (Object)(object)__instance.playerAvatar != (Object)(object)val)
					{
						return;
					}
				}
				catch
				{
					return;
				}
				MuteWingLoopAudio(__instance);
			}
		}

		[HarmonyPatch(typeof(ItemUpgradePlayerTumbleWingsLogic), "FixedUpdate")]
		private static class ItemUpgradePlayerTumbleWingsLogic_FixedUpdate_Patch
		{
			private static void Prefix(ItemUpgradePlayerTumbleWingsLogic __instance, ref float __state)
			{
				__state = -1f;
				if (!ShouldAllowHostPinkFlight(__instance))
				{
					return;
				}
				try
				{
					__state = __instance.tumbleWingPinkTimer;
					if (__instance.tumbleWingPinkTimer > 0f)
					{
						__instance.tumbleWingPinkTimer = 0f;
					}
					if (__instance.tumbleWingTimer < 1f)
					{
						__instance.tumbleWingTimer = 1f;
					}
					if (!IsNullUnity(__instance.playerAvatar))
					{
						__instance.playerAvatar.upgradeTumbleWingsVisualsActive = true;
					}
				}
				catch (Exception ex)
				{
					LogWarn("Host pink flight prefix failed\n" + ex);
				}
			}

			private static void Postfix(ItemUpgradePlayerTumbleWingsLogic __instance, float __state)
			{
				if (__state < 0f)
				{
					return;
				}
				try
				{
					if (__state > 0f)
					{
						__instance.tumbleWingPinkTimer = __state;
					}
					if (!IsNullUnity(__instance.playerAvatar))
					{
						__instance.playerAvatar.upgradeTumbleWingsVisualsActive = true;
					}
					__instance.WingsSetPinkColors();
				}
				catch (Exception ex)
				{
					LogWarn("Host pink flight postfix failed\n" + ex);
				}
			}
		}

		[HarmonyPatch(typeof(ItemUpgradePlayerTumbleWingsLogic), "TurnOffWings")]
		private static class ItemUpgradePlayerTumbleWingsLogic_TurnOffWings_Patch
		{
			private static bool Prefix(ItemUpgradePlayerTumbleWingsLogic __instance)
			{
				if (!ShouldAllowHostPinkFlight(__instance))
				{
					return true;
				}
				try
				{
					__instance.tumbleWingTimer = 1f;
					if (!IsNullUnity(__instance.playerAvatar))
					{
						__instance.playerAvatar.upgradeTumbleWingsVisualsActive = true;
					}
					__instance.WingsSetPinkColors();
				}
				catch (Exception ex)
				{
					LogWarn("Host pink TurnOff suppression failed\n" + ex);
				}
				return false;
			}
		}

		[CompilerGenerated]
		private sealed class <CoApplyWhenReady>d__19 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public string reason;

			public AlwaysWingsViewPlugin <>4__this;

			private float <end>5__1;

			private PlayerAvatar <local>5__2;

			private ItemUpgradePlayerTumbleWingsLogic <logic>5__3;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<local>5__2 = null;
				<logic>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<end>5__1 = Time.realtimeSinceStartup + 20f;
					break;
				case 1:
					<>1__state = -1;
					<local>5__2 = null;
					break;
				}
				if (Time.realtimeSinceStartup < <end>5__1)
				{
					<local>5__2 = null;
					try
					{
						<local>5__2 = PlayerAvatar.instance;
					}
					catch
					{
						<local>5__2 = null;
					}
					if (!IsNullUnity(<local>5__2))
					{
						<logic>5__3 = null;
						try
						{
							<logic>5__3 = <local>5__2.upgradeTumbleWingsLogic;
						}
						catch
						{
							<logic>5__3 = null;
						}
						if (!IsNullUnity(<logic>5__3))
						{
							<>4__this.ApplyModeBestEffort(reason);
							return false;
						}
						<logic>5__3 = null;
					}
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				LogWarn("Apply skipped (timeout) reason=" + reason);
				return false;
			}

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

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

		[CompilerGenerated]
		private sealed class <CoNetworkStateSync>d__20 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public AlwaysWingsViewPlugin <>4__this;

			private WaitForSeconds <wait>5__1;

			private Exception <ex>5__2;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<wait>5__1 = null;
				<ex>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<wait>5__1 = new WaitForSeconds(1f);
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				try
				{
					<>4__this.ResetHostSupportConfirmationForCurrentState();
					<>4__this.SyncHostSupportRoomProperty();
					<>4__this.SyncPhotonPinkRequestProperty();
				}
				catch (Exception ex)
				{
					<ex>5__2 = ex;
					LogWarn("Photon state sync failed\n" + <ex>5__2);
				}
				<>2__current = <wait>5__1;
				<>1__state = 1;
				return true;
			}

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

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

		[CompilerGenerated]
		private sealed class <CoWingsKeepAlive>d__23 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public string mode;

			public AlwaysWingsViewPlugin <>4__this;

			private WaitForSeconds <wait>5__1;

			private PlayerAvatar <local>5__2;

			private ItemUpgradePlayerTumbleWingsLogic <logic>5__3;

			private bool <hostSupport>5__4;

			private bool <suspendFallback>5__5;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<wait>5__1 = null;
				<local>5__2 = null;
				<logic>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<wait>5__1 = new WaitForSeconds(0.5f);
					break;
				case 1:
					<>1__state = -1;
					<local>5__2 = null;
					break;
				}
				<local>5__2 = null;
				try
				{
					<local>5__2 = PlayerAvatar.instance;
				}
				catch
				{
					<local>5__2 = null;
				}
				if (!IsNullUnity(<local>5__2))
				{
					<logic>5__3 = null;
					try
					{
						<logic>5__3 = <local>5__2.upgradeTumbleWingsLogic;
					}
					catch
					{
						<logic>5__3 = null;
					}
					if (!IsNullUnity(<logic>5__3))
					{
						if (<>4__this._muteWingLoopSound.Value && NormalizeMode(<>4__this._mode.Value) != "off")
						{
							MuteWingLoopAudio(<logic>5__3);
						}
						else
						{
							UnmuteWingLoopAudio(<logic>5__3);
						}
						if (mode == "blue")
						{
							<>4__this._pinkFallbackSuspended = false;
							TrySetWings(<local>5__2, visualsActive: true, pink: false, "loopTick blue");
						}
						else
						{
							<hostSupport>5__4 = HasHostPinkFlightSupport();
							<suspendFallback>5__5 = !<hostSupport>5__4 && IsLocalPinkFlightFallbackSuspendActive(<local>5__2);
							if (<suspendFallback>5__5)
							{
								<>4__this._pinkFallbackSuspended = true;
							}
							else
							{
								if (<>4__this._pinkFallbackSuspended)
								{
									<>4__this._pinkFallbackSuspended = false;
									TrySetWings(<local>5__2, visualsActive: true, pink: true, "fallbackResume pink");
								}
								TrySetWings(<local>5__2, visualsActive: true, pink: true, <hostSupport>5__4 ? "loopTick pink hostSupport" : "loopTick pink fallbackIdle");
							}
						}
					}
					<logic>5__3 = null;
				}
				<>2__current = <wait>5__1;
				<>1__state = 1;
				return true;
			}

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

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

		public const string PluginGuid = "REPOJP.AlwaysWingsView";

		public const string PluginName = "AlwaysWingsView";

		public const string PluginVersion = "2.1.0";

		private const string RoomPropertyHostPinkFlightSupport = "REPOJP_AWV_HostPinkFlight";

		private const string PlayerPropertyPinkRequested = "REPOJP_AWV_PinkRequested";

		private static ManualLogSource Log;

		private static AlwaysWingsViewPlugin Instance;

		private ConfigEntry<string> _mode;

		private ConfigEntry<bool> _muteWingLoopSound;

		private Harmony _harmony;

		private Coroutine _wingsLoopCo;

		private Coroutine _networkSyncCo;

		private string _activeMode = "off";

		private bool _pinkFallbackSuspended;

		private bool _hostPinkFlightSupportConfirmedThisRoom;

		private string _hostPinkFlightSupportConfirmedRoomName = string.Empty;

		private void Awake()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			_mode = ((BaseUnityPlugin)this).Config.Bind<string>("General", "TumbleWingsMode", "blue", new ConfigDescription("Auto tumble wings mode. Values: off, blue, pink. 自動翼モード off blue pink のみ", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "off", "blue", "pink" }), Array.Empty<object>()));
			_muteWingLoopSound = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "MuteWingLoopSound", true, "Mute blue and pink wing loop sound without changing the display flow. 既存の羽表示処理を変えずに青羽とピンク羽のループ音のみ無音化");
			_harmony = new Harmony("REPOJP.AlwaysWingsView");
			_harmony.PatchAll(typeof(AlwaysWingsViewPlugin).Assembly);
			_mode.SettingChanged += delegate
			{
				SyncPhotonPinkRequestProperty();
				ApplyModeBestEffort("configChanged");
			};
			_muteWingLoopSound.SettingChanged += delegate
			{
				ApplyModeBestEffort("configChanged");
			};
			SceneManager.sceneLoaded += OnSceneLoaded;
			_networkSyncCo = ((MonoBehaviour)this).StartCoroutine(CoNetworkStateSync());
			((MonoBehaviour)this).StartCoroutine(CoApplyWhenReady("initial"));
			LogInfo("Loaded v2.1.0");
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			StopWingsLoop();
			if (_networkSyncCo != null)
			{
				((MonoBehaviour)this).StopCoroutine(_networkSyncCo);
				_networkSyncCo = null;
			}
			try
			{
				ClearPhotonPinkRequestProperty();
			}
			catch
			{
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			ResetHostSupportConfirmationForCurrentState();
			SyncPhotonPinkRequestProperty();
			((MonoBehaviour)this).StartCoroutine(CoApplyWhenReady("sceneLoaded:" + ((Scene)(ref scene)).name));
		}

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

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

		private void ApplyModeBestEffort(string reason)
		{
			string text = NormalizeMode(_mode.Value);
			PlayerAvatar val = null;
			try
			{
				val = PlayerAvatar.instance;
			}
			catch
			{
				val = null;
			}
			if (IsNullUnity(val))
			{
				return;
			}
			ItemUpgradePlayerTumbleWingsLogic val2 = null;
			try
			{
				val2 = val.upgradeTumbleWingsLogic;
			}
			catch
			{
				val2 = null;
			}
			if (!IsNullUnity(val2))
			{
				ResetHostSupportConfirmationForCurrentState();
				SyncHostSupportRoomProperty();
				SyncPhotonPinkRequestProperty();
				if (_muteWingLoopSound.Value && text != "off")
				{
					MuteWingLoopAudio(val2);
				}
				else
				{
					UnmuteWingLoopAudio(val2);
				}
				switch (text)
				{
				case "off":
					StopWingsLoop();
					TrySetWings(val, visualsActive: false, pink: true, "mode=off " + reason);
					_activeMode = "off";
					break;
				case "blue":
					StartWingsLoop(val, "blue", reason);
					break;
				case "pink":
					StartWingsLoop(val, "pink", reason);
					break;
				}
			}
		}

		private void StartWingsLoop(PlayerAvatar local, string mode, string reason)
		{
			StopWingsLoop();
			_activeMode = mode;
			if (mode == "blue")
			{
				TrySetWings(local, visualsActive: true, pink: false, "mode=blue oneshot " + reason);
			}
			else
			{
				TrySetWings(local, visualsActive: true, pink: true, "mode=pink oneshot " + reason);
			}
			_wingsLoopCo = ((MonoBehaviour)this).StartCoroutine(CoWingsKeepAlive(mode));
		}

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

		private void StopWingsLoop()
		{
			if (_wingsLoopCo != null)
			{
				((MonoBehaviour)this).StopCoroutine(_wingsLoopCo);
				_wingsLoopCo = null;
			}
			_pinkFallbackSuspended = false;
		}

		private static void TrySetWings(PlayerAvatar avatar, bool visualsActive, bool pink, string reason)
		{
			if (IsNullUnity(avatar))
			{
				return;
			}
			try
			{
				avatar.UpgradeTumbleWingsVisualsActive(visualsActive, pink);
			}
			catch (Exception ex)
			{
				LogError("Wings apply failed reason=" + reason + "\n" + ex);
			}
		}

		private static bool IsLocalPinkFlightFallbackSuspendActive(PlayerAvatar avatar)
		{
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Instance == (Object)null)
			{
				return false;
			}
			if (NormalizeMode(Instance._mode.Value) != "pink")
			{
				return false;
			}
			if (IsNullUnity(avatar))
			{
				return false;
			}
			PlayerAvatar val = null;
			try
			{
				val = PlayerAvatar.instance;
			}
			catch
			{
				val = null;
			}
			if (IsNullUnity(val) || (Object)(object)avatar != (Object)(object)val)
			{
				return false;
			}
			try
			{
				if (avatar.upgradeTumbleWings <= 0f)
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			PlayerTumble val2 = null;
			try
			{
				val2 = avatar.tumble;
			}
			catch
			{
				val2 = null;
			}
			if (IsNullUnity(val2))
			{
				return false;
			}
			try
			{
				if (!val2.isTumbling)
				{
					return false;
				}
				if (!val2.isPlayerInputTriggered && val2.tumbleOverride)
				{
					return false;
				}
				if ((Object)(object)val2.physGrabObject == (Object)null)
				{
					return false;
				}
				if (val2.physGrabObject.playerGrabbing.Count > 0)
				{
					return false;
				}
				if (SemiFunc.OnGroundCheck(((Component)val2).transform.position, 1f, val2.physGrabObject))
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			return true;
		}

		private static bool ShouldAllowHostPinkFlight(ItemUpgradePlayerTumbleWingsLogic logic)
		{
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Instance == (Object)null)
			{
				return false;
			}
			if (IsNullUnity(logic))
			{
				return false;
			}
			PlayerAvatar val = null;
			try
			{
				val = logic.playerAvatar;
			}
			catch
			{
				val = null;
			}
			if (IsNullUnity(val))
			{
				return false;
			}
			try
			{
				if (val.upgradeTumbleWings <= 0f)
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			if (!HasPinkFlightAuthorityForAvatar(val))
			{
				return false;
			}
			PlayerTumble val2 = null;
			try
			{
				val2 = val.tumble;
			}
			catch
			{
				val2 = null;
			}
			if (IsNullUnity(val2))
			{
				return false;
			}
			try
			{
				if (!val2.isTumbling)
				{
					return false;
				}
				if (!val2.isPlayerInputTriggered && val2.tumbleOverride)
				{
					return false;
				}
				if ((Object)(object)val2.physGrabObject == (Object)null)
				{
					return false;
				}
				if (val2.physGrabObject.playerGrabbing.Count > 0)
				{
					return false;
				}
				if (SemiFunc.OnGroundCheck(((Component)val2).transform.position, 1f, val2.physGrabObject))
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			return true;
		}

		private static bool HasPinkFlightAuthorityForAvatar(PlayerAvatar avatar)
		{
			if (IsNullUnity(avatar))
			{
				return false;
			}
			if (!SemiFunc.IsMultiplayer())
			{
				return NormalizeMode(Instance._mode.Value) == "pink";
			}
			if (!PhotonNetwork.InRoom)
			{
				return false;
			}
			if (!PhotonNetwork.IsMasterClient)
			{
				return false;
			}
			return GetAvatarPinkRequested(avatar);
		}

		private static bool GetAvatarPinkRequested(PlayerAvatar avatar)
		{
			if (IsNullUnity(avatar))
			{
				return false;
			}
			PhotonView val = null;
			try
			{
				val = ((Component)avatar).GetComponent<PhotonView>();
			}
			catch
			{
				val = null;
			}
			if ((Object)(object)val == (Object)null || val.Owner == null)
			{
				return false;
			}
			return TryGetBoolProperty(val.Owner.CustomProperties, "REPOJP_AWV_PinkRequested");
		}

		private void ResetHostSupportConfirmationForCurrentState()
		{
			if (!SemiFunc.IsMultiplayer() || !PhotonNetwork.InRoom || PhotonNetwork.CurrentRoom == null)
			{
				_hostPinkFlightSupportConfirmedThisRoom = false;
				_hostPinkFlightSupportConfirmedRoomName = string.Empty;
				return;
			}
			string text = PhotonNetwork.CurrentRoom.Name ?? string.Empty;
			if (!string.Equals(_hostPinkFlightSupportConfirmedRoomName, text, StringComparison.Ordinal))
			{
				_hostPinkFlightSupportConfirmedThisRoom = false;
				_hostPinkFlightSupportConfirmedRoomName = text;
			}
		}

		private static string GetCurrentPhotonRoomName()
		{
			if (!PhotonNetwork.InRoom || PhotonNetwork.CurrentRoom == null)
			{
				return string.Empty;
			}
			return PhotonNetwork.CurrentRoom.Name ?? string.Empty;
		}

		private static bool HasHostPinkFlightSupport()
		{
			if (!SemiFunc.IsMultiplayer())
			{
				return true;
			}
			if (!PhotonNetwork.InRoom)
			{
				if ((Object)(object)Instance != (Object)null)
				{
					Instance._hostPinkFlightSupportConfirmedThisRoom = false;
					Instance._hostPinkFlightSupportConfirmedRoomName = string.Empty;
				}
				return false;
			}
			if (PhotonNetwork.IsMasterClient)
			{
				return true;
			}
			Room currentRoom = PhotonNetwork.CurrentRoom;
			if (currentRoom == null)
			{
				if ((Object)(object)Instance != (Object)null)
				{
					Instance._hostPinkFlightSupportConfirmedThisRoom = false;
					Instance._hostPinkFlightSupportConfirmedRoomName = string.Empty;
				}
				return false;
			}
			string text = currentRoom.Name ?? string.Empty;
			if ((Object)(object)Instance != (Object)null)
			{
				if (!string.Equals(Instance._hostPinkFlightSupportConfirmedRoomName, text, StringComparison.Ordinal))
				{
					Instance._hostPinkFlightSupportConfirmedThisRoom = false;
					Instance._hostPinkFlightSupportConfirmedRoomName = text;
				}
				if (Instance._hostPinkFlightSupportConfirmedThisRoom)
				{
					return true;
				}
			}
			bool flag = TryGetBoolProperty(((RoomInfo)currentRoom).CustomProperties, "REPOJP_AWV_HostPinkFlight");
			if (flag && (Object)(object)Instance != (Object)null)
			{
				Instance._hostPinkFlightSupportConfirmedThisRoom = true;
				Instance._hostPinkFlightSupportConfirmedRoomName = text;
			}
			return flag;
		}

		private void SyncHostSupportRoomProperty()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			if (SemiFunc.IsMultiplayer() && PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient)
			{
				Room currentRoom = PhotonNetwork.CurrentRoom;
				if (currentRoom != null && !TryGetBoolProperty(((RoomInfo)currentRoom).CustomProperties, "REPOJP_AWV_HostPinkFlight"))
				{
					Hashtable val = new Hashtable();
					val[(object)"REPOJP_AWV_HostPinkFlight"] = true;
					currentRoom.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
				}
			}
		}

		private void SyncPhotonPinkRequestProperty()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			if (!SemiFunc.IsMultiplayer() || !PhotonNetwork.InRoom)
			{
				return;
			}
			Player localPlayer = PhotonNetwork.LocalPlayer;
			if (localPlayer != null)
			{
				bool flag = NormalizeMode(_mode.Value) == "pink";
				bool flag2 = TryGetBoolProperty(localPlayer.CustomProperties, "REPOJP_AWV_PinkRequested");
				if (flag2 != flag)
				{
					Hashtable val = new Hashtable();
					val[(object)"REPOJP_AWV_PinkRequested"] = flag;
					localPlayer.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
				}
			}
		}

		private void ClearPhotonPinkRequestProperty()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			if (SemiFunc.IsMultiplayer() && PhotonNetwork.InRoom)
			{
				Player localPlayer = PhotonNetwork.LocalPlayer;
				if (localPlayer != null && TryGetBoolProperty(localPlayer.CustomProperties, "REPOJP_AWV_PinkRequested"))
				{
					Hashtable val = new Hashtable();
					val[(object)"REPOJP_AWV_PinkRequested"] = false;
					localPlayer.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
				}
			}
		}

		private static bool TryGetBoolProperty(Hashtable props, string key)
		{
			if (props == null || string.IsNullOrEmpty(key) || !((Dictionary<object, object>)(object)props).ContainsKey((object)key))
			{
				return false;
			}
			object obj = props[(object)key];
			if (obj == null)
			{
				return false;
			}
			if (!(obj is bool result))
			{
				if (obj is byte)
				{
					return (byte)obj != 0;
				}
				if (obj is int)
				{
					return (int)obj != 0;
				}
				if (obj is string && bool.TryParse((string)obj, out var result2))
				{
					return result2;
				}
				return false;
			}
			return result;
		}

		private static void MuteWingLoopAudio(ItemUpgradePlayerTumbleWingsLogic logic)
		{
			if (IsNullUnity(logic))
			{
				return;
			}
			try
			{
				if ((Object)(object)logic.localAudioSource != (Object)null)
				{
					logic.localAudioSource.mute = true;
					if (logic.localAudioSource.isPlaying)
					{
						logic.localAudioSource.Stop();
					}
				}
			}
			catch (Exception ex)
			{
				LogWarn("localAudioSource mute failed\n" + ex);
			}
			try
			{
				if (logic.soundWingsLoop != null && (Object)(object)logic.soundWingsLoop.Source != (Object)null)
				{
					logic.soundWingsLoop.Source.mute = true;
					if (logic.soundWingsLoop.Source.isPlaying)
					{
						logic.soundWingsLoop.Source.Stop();
					}
				}
			}
			catch (Exception ex2)
			{
				LogWarn("soundWingsLoop mute failed\n" + ex2);
			}
		}

		private static void UnmuteWingLoopAudio(ItemUpgradePlayerTumbleWingsLogic logic)
		{
			if (IsNullUnity(logic))
			{
				return;
			}
			try
			{
				if ((Object)(object)logic.localAudioSource != (Object)null)
				{
					logic.localAudioSource.mute = false;
				}
			}
			catch (Exception ex)
			{
				LogWarn("localAudioSource unmute failed\n" + ex);
			}
			try
			{
				if (logic.soundWingsLoop != null && (Object)(object)logic.soundWingsLoop.Source != (Object)null)
				{
					logic.soundWingsLoop.Source.mute = false;
				}
			}
			catch (Exception ex2)
			{
				LogWarn("soundWingsLoop unmute failed\n" + ex2);
			}
		}

		private static string NormalizeMode(string raw)
		{
			if (string.IsNullOrWhiteSpace(raw))
			{
				return "blue";
			}
			return raw.Trim().ToLowerInvariant() switch
			{
				"off" => "off", 
				"blue" => "blue", 
				"pink" => "pink", 
				_ => "blue", 
			};
		}

		private static bool IsNullUnity(object obj)
		{
			if (obj == null)
			{
				return true;
			}
			Object val = (Object)((obj is Object) ? obj : null);
			if (val != null)
			{
				return val == (Object)null;
			}
			return false;
		}

		private static void LogInfo(string message)
		{
			Debug.Log((object)("[AlwaysWingsView] " + message));
			ManualLogSource log = Log;
			if (log != null)
			{
				log.LogInfo((object)message);
			}
		}

		private static void LogWarn(string message)
		{
			Debug.LogWarning((object)("[AlwaysWingsView] " + message));
			ManualLogSource log = Log;
			if (log != null)
			{
				log.LogWarning((object)message);
			}
		}

		private static void LogError(string message)
		{
			Debug.LogError((object)("[AlwaysWingsView] " + message));
			ManualLogSource log = Log;
			if (log != null)
			{
				log.LogError((object)message);
			}
		}
	}
}