Decompiled source of AutoPhone v1.0.1

GWYF.AutoPhone.dll

Decompiled 15 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 BepInEx;
using BepInEx.Logging;
using Mirror;
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: AssemblyCompany("GWYF.AutoPhone")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+3ea0761173a791d5fd7817926d25acc0b2ea7026")]
[assembly: AssemblyProduct("GWYF.AutoPhone")]
[assembly: AssemblyTitle("GWYF.AutoPhone")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace GWYF.AutoPhone;

[BepInProcess("Gamble With Your Friends.exe")]
[BepInPlugin("GWYF.Epoch.AutoPhone", "Auto Phone!", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <WaitForClientsAndTrigger>d__4 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public Plugin <>4__this;

		private float <timeout>5__1;

		private float <elapsed>5__2;

		private bool <anyReady>5__3;

		private Dictionary<int, NetworkConnectionToClient>.ValueCollection.Enumerator <>s__4;

		private NetworkConnectionToClient <conn>5__5;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>s__4 = default(Dictionary<int, NetworkConnectionToClient>.ValueCollection.Enumerator);
			<conn>5__5 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				if (!NetworkServer.active)
				{
					Logger.LogInfo((object)"[AutoPhone] Not the server – skipping.");
					return false;
				}
				Logger.LogInfo((object)"[AutoPhone] Waiting for at least one ready client...");
				<timeout>5__1 = 30f;
				<elapsed>5__2 = 0f;
				goto IL_013d;
			case 1:
				<>1__state = -1;
				goto IL_013d;
			case 2:
				{
					<>1__state = -1;
					<>4__this.TriggerAllPhoneBooths();
					return false;
				}
				IL_013d:
				if (<elapsed>5__2 < <timeout>5__1)
				{
					<anyReady>5__3 = false;
					<>s__4 = NetworkServer.connections.Values.GetEnumerator();
					try
					{
						while (<>s__4.MoveNext())
						{
							<conn>5__5 = <>s__4.Current;
							if (<conn>5__5 != null && ((NetworkConnection)<conn>5__5).isReady)
							{
								<anyReady>5__3 = true;
								break;
							}
							<conn>5__5 = null;
						}
					}
					finally
					{
						((IDisposable)<>s__4).Dispose();
					}
					<>s__4 = default(Dictionary<int, NetworkConnectionToClient>.ValueCollection.Enumerator);
					if (!<anyReady>5__3)
					{
						<elapsed>5__2 += Time.deltaTime;
						<>2__current = null;
						<>1__state = 1;
						return true;
					}
				}
				if (<elapsed>5__2 >= <timeout>5__1)
				{
					Logger.LogWarning((object)"[AutoPhone] Timed out waiting for a ready client. Triggering anyway.");
				}
				else
				{
					Logger.LogInfo((object)$"[AutoPhone] Client ready after ~{<elapsed>5__2:F1}s. Triggering PhoneBooths.");
				}
				<>2__current = (object)new WaitForSeconds(0.5f);
				<>1__state = 2;
				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();
		}
	}

	internal static ManualLogSource Logger;

	private void Awake()
	{
		Logger = ((BaseUnityPlugin)this).Logger;
		SceneManager.sceneLoaded += OnSceneLoaded;
		Logger.LogInfo((object)"[AutoPhone] Plugin is loaded!");
	}

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

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		Logger.LogInfo((object)("[AutoPhone] Scene loaded: " + ((Scene)(ref scene)).name + ". Will wait for clients before triggering PhoneBooths."));
		((MonoBehaviour)this).StartCoroutine(WaitForClientsAndTrigger());
	}

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

	private void TriggerAllPhoneBooths()
	{
		PhoneBooth[] array = Object.FindObjectsByType<PhoneBooth>((FindObjectsSortMode)0);
		if (array.Length == 0)
		{
			Logger.LogInfo((object)"[AutoPhone] No PhoneBooths found in scene.");
			return;
		}
		MethodInfo method = typeof(PhoneBooth).GetMethod("ServerFirstInteraction", BindingFlags.Instance | BindingFlags.NonPublic);
		if (method == null)
		{
			Logger.LogError((object)"[AutoPhone] Could not find ServerFirstInteraction. Dumping PhoneBooth methods:");
			MethodInfo[] methods = typeof(PhoneBooth).GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo in methods)
			{
				Logger.LogInfo((object)("  [" + methodInfo.DeclaringType?.Name + "] " + methodInfo.Name));
			}
			return;
		}
		Logger.LogInfo((object)$"[AutoPhone] Triggering ServerFirstInteraction on {array.Length} PhoneBooth(s).");
		PhoneBooth[] array2 = array;
		foreach (PhoneBooth val in array2)
		{
			if (!((Object)(object)val == (Object)null))
			{
				Logger.LogInfo((object)("[AutoPhone] Triggering: " + ((Object)((Component)val).gameObject).name));
				method.Invoke(val, null);
			}
		}
	}
}
public static class MyPluginInfo
{
	public const string PLUGIN_GUID = "GWYF.Epoch.AutoPhone";

	public const string PLUGIN_NAME = "Auto Phone!";

	public const string PLUGIN_VERSION = "1.0.1";
}