Decompiled source of FixRezPopup v1.0.1

BepInEx/plugins/FixRezPopup.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FixRezPopup")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FixRezPopup")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("775FC646-659F-4FFA-B7EF-74A0D38077B9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[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 FixRezPopup
{
	[HarmonyPatch]
	[BepInPlugin("Fix.FixRezPopup", "FixRezPopup", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class FixPopup : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <WaitForInput>d__17 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Expected O, but got Unknown
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(0.5f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>2__current = (object)new WaitUntil((Func<bool>)IsUserInput);
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					ShowRezPopup();
					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();
			}
		}

		public const string PluginGUID = "Fix.FixRezPopup";

		public const string PluginName = "FixRezPopup";

		public const string PluginVersion = "1.0.1";

		private const string ResurrectionPluginGUID = "org.bepinex.plugins.resurrection";

		private static readonly Harmony H = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);

		private static bool _isHidden;

		private static Vector3 _origPosition;

		private static Transform PopupUI => UnifiedPopup.instance.popupUIParent.transform;

		private void OnDestroy()
		{
			H.UnpatchSelf();
		}

		private static void SavePosition()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			_origPosition = PopupUI.position;
		}

		private static void RestorePosition()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (UnifiedPopup.IsAvailable() && _isHidden)
			{
				PopupUI.position = _origPosition;
			}
		}

		private static void ShowRezPopup()
		{
			RestorePosition();
			_isHidden = false;
		}

		private static void HideRezPopup()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			SavePosition();
			PopupUI.position = new Vector3(100000f, 0f, 0f);
			_isHidden = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UnifiedPopup), "Hide")]
		private static void UnifiedPopup_Hide()
		{
			RestorePosition();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Player), "OnSpawned")]
		private static void Player_OnSpawned()
		{
			RestorePosition();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Humanoid), "OnRagdollCreated")]
		[HarmonyAfter(new string[] { "org.bepinex.plugins.resurrection" })]
		private static void Humanoid_OnRagdollCreated(Humanoid __instance)
		{
			if (UnifiedPopup.IsVisible() && UnifiedPopup.instance.popupStack.Peek() is CancelableTaskPopup)
			{
				HideRezPopup();
				((MonoBehaviour)Hud.instance).StartCoroutine(WaitForInput());
			}
		}

		[IteratorStateMachine(typeof(<WaitForInput>d__17))]
		private static IEnumerator WaitForInput()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitForInput>d__17(0);
		}

		private static bool IsUserInput()
		{
			if (!ZInput.GetButtonDown("Attack"))
			{
				return ZInput.GetButtonDown("JoyButtonB");
			}
			return true;
		}
	}
}