Decompiled source of AlwaysWingsView v1.2.1

AlwaysWingsView.dll

Decompiled 5 hours 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 Microsoft.CodeAnalysis;
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("zabu")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace REPOJP.AutoTumbleWingsMode
{
	[BepInPlugin("jp.repo.auto.tumblewingsmode", "AutoTumbleWingsMode", "1.0.0")]
	public sealed class AutoTumbleWingsModePlugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <CoApplyWhenReady>d__10 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public string reason;

			public AutoTumbleWingsModePlugin <>4__this;

			private float <end>5__1;

			private PlayerAvatar <local>5__2;

			private object <logic>5__3;

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

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

			[DebuggerHidden]
			public <CoApplyWhenReady>d__10(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 <CoWingsKeepAlive>d__13 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public string mode;

			public AutoTumbleWingsModePlugin <>4__this;

			private WaitForSeconds <wait>5__1;

			private PlayerAvatar <local>5__2;

			private object <logic>5__3;

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

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

			[DebuggerHidden]
			public <CoWingsKeepAlive>d__13(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 (mode == "blue")
						{
							TrySetWings(<local>5__2, visualsActive: true, pink: false, "loopTick blue");
						}
						else
						{
							TrySetWings(<local>5__2, visualsActive: true, pink: true, "loopTick pink");
						}
					}
					<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 = "jp.repo.auto.tumblewingsmode";

		public const string PluginName = "AutoTumbleWingsMode";

		public const string PluginVersion = "1.0.0";

		private static ManualLogSource Log;

		private ConfigEntry<string> _mode;

		private Coroutine _wingsLoopCo;

		private string _activeMode = "off";

		private void Awake()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			_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>()));
			_mode.SettingChanged += delegate
			{
				ApplyModeBestEffort("configChanged");
			};
			SceneManager.sceneLoaded += OnSceneLoaded;
			((MonoBehaviour)this).StartCoroutine(CoApplyWhenReady("initial"));
			LogInfo("Loaded");
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			StopWingsLoop();
		}

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

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

		private void ApplyModeBestEffort(string reason)
		{
			string text = NormalizeMode(_mode.Value);
			PlayerAvatar val = null;
			try
			{
				val = PlayerAvatar.instance;
			}
			catch
			{
				val = null;
			}
			if (IsNullUnity(val))
			{
				return;
			}
			object obj2 = null;
			try
			{
				obj2 = val.upgradeTumbleWingsLogic;
			}
			catch
			{
				obj2 = null;
			}
			if (!IsNullUnity(obj2))
			{
				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__13))]
		private IEnumerator CoWingsKeepAlive(string mode)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <CoWingsKeepAlive>d__13(0)
			{
				<>4__this = this,
				mode = mode
			};
		}

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

		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 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)("[AutoTumbleWingsMode] " + message));
			ManualLogSource log = Log;
			if (log != null)
			{
				log.LogInfo((object)message);
			}
		}

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

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