Decompiled source of ResultScreenTransitionFix v1.0.0

BepInEx/plugins/ResultScreenTransitionFix/ResultScreenTransitionFix.dll

Decompiled 23 minutes ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("ResultScreenTransitionFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ResultScreenTransitionFix")]
[assembly: AssemblyTitle("ResultScreenTransitionFix")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 RepoResultScreenFix
{
	[BepInPlugin("local.repo.resultscreenfix", "Result Screen Transition Fix", "1.0.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "local.repo.resultscreenfix";

		public const string PluginName = "Result Screen Transition Fix";

		public const string PluginVersion = "1.0.0";

		internal static ConfigEntry<float> MaxWaitSeconds { get; private set; }

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			MaxWaitSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaxWaitSeconds", 120f, new ConfigDescription("Maximum time in seconds to hold the level transition while ResultScreenUI finishes. Prevents an indefinite loading wait.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(30f, 600f), Array.Empty<object>()));
			new Harmony("local.repo.resultscreenfix").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Result Screen Transition Fix loaded.");
		}
	}
	internal static class ResultScreenTransitionState
	{
		internal static bool Finished;

		internal static bool Waiting;

		internal static float WaitStartedAt;

		internal static void Reset()
		{
			Finished = false;
			Waiting = false;
		}
	}
	[HarmonyPatch(typeof(GameDirector), "gameStateOutro")]
	internal static class GameDirectorOutroPatch
	{
		private static void Prefix(GameDirector __instance)
		{
			if (Traverse.Create((object)__instance).Field("gameStateStartImpulse").GetValue<bool>())
			{
				ResultScreenTransitionState.Reset();
			}
		}
	}
	[HarmonyPatch(typeof(ResultScreenUI), "FinishResultScreen")]
	internal static class ResultScreenFinishPatch
	{
		private static void Postfix()
		{
			ResultScreenTransitionState.Finished = true;
			ResultScreenTransitionState.Waiting = false;
		}
	}
	[HarmonyPatch(typeof(PlayerAvatar), "OutroDone")]
	internal static class PlayerAvatarOutroDonePatch
	{
		private static bool Prefix(PlayerAvatar __instance)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Invalid comparison between Unknown and I4
			if (Traverse.Create((object)__instance).Field("quitApplication").GetValue<bool>())
			{
				return true;
			}
			if ((Object)(object)NetworkManager.instance != (Object)null && Traverse.Create((object)NetworkManager.instance).Field("leavePhotonRoom").GetValue<bool>())
			{
				return true;
			}
			if ((Object)(object)ResultScreenUI.instance == (Object)null || (Object)(object)GameDirector.instance == (Object)null)
			{
				return true;
			}
			if (ResultScreenTransitionState.Finished)
			{
				return true;
			}
			if (!ResultScreenTransitionState.Waiting)
			{
				if ((int)GameDirector.instance.currentState != 4)
				{
					return true;
				}
				ResultScreenTransitionState.Waiting = true;
				ResultScreenTransitionState.WaitStartedAt = Time.realtimeSinceStartup;
			}
			if (Time.realtimeSinceStartup - ResultScreenTransitionState.WaitStartedAt < Plugin.MaxWaitSeconds.Value)
			{
				return false;
			}
			ResultScreenTransitionState.Finished = true;
			ResultScreenTransitionState.Waiting = false;
			return true;
		}
	}
}