Decompiled source of AutomaticRematch v1.3.1

Mods/AutomaticRematch.dll

Decompiled 2 months 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 AutomaticRematch;
using HarmonyLib;
using Il2CppRUMBLE.Interactions.InteractionBase;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Networking.MatchFlow;
using Il2CppRUMBLE.Players.Subsystems;
using Il2CppRUMBLE.Utilities;
using MelonLoader;
using RumbleModUI;
using RumbleModdingAPI;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Main), "AutomaticRematch", "1.3.1", "UlvakSkillz", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 195, 0, 255)]
[assembly: MelonAuthorColor(255, 195, 0, 255)]
[assembly: VerifyLoaderVersion(0, 6, 6, true)]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AutomaticRematch")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a63b405792bd1f32cb0d967872d4019ca15f4229")]
[assembly: AssemblyProduct("AutomaticRematch")]
[assembly: AssemblyTitle("AutomaticRematch")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AutomaticRematch;

public class Main : MelonMod
{
	public static class BuildInfo
	{
		public const string ModName = "AutomaticRematch";

		public const string ModVersion = "1.3.1";

		public const string Description = "Automatically Presses Rematch Button if On";

		public const string Author = "UlvakSkillz";

		public const string Company = "";
	}

	[HarmonyPatch(typeof(PlayerBoxInteractionSystem), "ExecuteFistBumpReward", new Type[] { typeof(Vector3) })]
	public static class executeFistBumpReward
	{
		private static void Postfix(ref PlayerBoxInteractionSystem __instance, ref Vector3 interactionPosition)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			__instance = ((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).gameObject.GetComponent<PlayerBoxInteractionSystem>();
			if (!rematchOnFistbumpEnabled)
			{
				return;
			}
			float num = Vector3.Distance(interactionPosition, primaryHandIsRight ? ((Component)__instance.rightHandTrigger).transform.position : ((Component)__instance.leftHandTrigger).transform.position);
			float num2 = Vector3.Distance(interactionPosition, (!primaryHandIsRight) ? ((Component)__instance.rightHandTrigger).transform.position : ((Component)__instance.leftHandTrigger).transform.position);
			if (!inMatch)
			{
				if (Math.Abs(num - num2) < 0.01f)
				{
					Log("Distance Between Hands too close to same distance, skipping");
				}
				else if (num < num2)
				{
					Log("Rematch on Fistbump Rematching");
					((InteractionButton)GetRematchButton().GetComponent<RematchButton>()).RPC_OnToggleStateChanged(true);
				}
				else if (secondaryHandFunctionEnabled)
				{
					watchingPlayerCount = false;
					if (secondaryHandFunction)
					{
						Log("Rematch on Fistbump secondaryHandFunction Requeueing");
						GetRequeueButton().GetComponent<MatchHandlerInvoker>().Requeue(Singleton<PlayerManager>.instance.localPlayer);
					}
					else
					{
						Log("Rematch on Fistbump secondaryHandFunction Quiting");
						GetExitButton().GetComponent<MatchHandlerInvoker>().Quit(Singleton<PlayerManager>.instance.localPlayer);
					}
				}
				return;
			}
			Log("Fistbump Happened, Waiting for Sign");
			needsToRunFunction = true;
			if (num < num2)
			{
				functionToRun = 0;
			}
			else if (secondaryHandFunctionEnabled)
			{
				if (secondaryHandFunction)
				{
					functionToRun = 1;
				}
				else
				{
					functionToRun = 2;
				}
			}
		}
	}

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

		private object <>2__current;

		public Main <>4__this;

		private float <buttonValue>5__1;

		private int <>s__2;

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

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

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

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

		private bool MoveNext()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(<>4__this.timeToWait);
				<>1__state = 1;
				return true;
			case 1:
			{
				<>1__state = -1;
				<buttonValue>5__1 = 0f;
				int preventAutoRematchButton = <>4__this.preventAutoRematchButton;
				<>s__2 = preventAutoRematchButton;
				switch (<>s__2)
				{
				case 0:
					<buttonValue>5__1 = LeftController.GetTrigger();
					break;
				case 1:
					<buttonValue>5__1 = LeftController.GetPrimary();
					break;
				case 2:
					<buttonValue>5__1 = LeftController.GetSecondary();
					break;
				case 3:
					<buttonValue>5__1 = RightController.GetTrigger();
					break;
				case 4:
					<buttonValue>5__1 = RightController.GetPrimary();
					break;
				case 5:
					<buttonValue>5__1 = RightController.GetSecondary();
					break;
				}
				if (!<>4__this.preventAutoRematchButtonEnabled || <buttonValue>5__1 < 0.5f)
				{
					((InteractionButton)GetRematchButton().GetComponent<RematchButton>()).RPC_OnToggleStateChanged(true);
				}
				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 <WatchPlayerCount>d__24 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public Main <>4__this;

		private int <>s__1;

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

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

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

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

		private bool MoveNext()
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				Log("WatchPlayerCount Start");
				watchingPlayerCount = true;
				Log("Adding Watchers");
				((Component)GetExitButton().transform.FindChild("InteractionButton/Button")).GetComponent<InteractionButton>().OnPressed.AddListener(UnityAction.op_Implicit((Action)delegate
				{
					<>4__this.LeavingMatch();
				}));
				Log("Watcher Exit Button Added");
				((Component)GetRequeueButton().transform.FindChild("InteractionButton/Button")).GetComponent<InteractionButton>().OnPressed.AddListener(UnityAction.op_Implicit((Action)delegate
				{
					<>4__this.LeavingMatch();
				}));
				Log("Watcher Requeue Button Added");
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			if (watchingPlayerCount && Singleton<PlayerManager>.instance.AllPlayers.Count > 1)
			{
				<>2__current = (object)new WaitForFixedUpdate();
				<>1__state = 1;
				return true;
			}
			Log($"WatchPlayerCount -WHILE LOOP- Done. watchingPlayerCount: {watchingPlayerCount} | PlayerCount: {Singleton<PlayerManager>.instance.AllPlayers.Count}");
			if (watchingPlayerCount)
			{
				int onePlayerRemainFunction = <>4__this.onePlayerRemainFunction;
				<>s__1 = onePlayerRemainFunction;
				switch (<>s__1)
				{
				case 1:
					if (secondaryHandFunction)
					{
						Log("onePlayerRemainFunction - Secondary Hand Function Requeueing");
						GetRequeueButton().GetComponent<MatchHandlerInvoker>().Requeue(Singleton<PlayerManager>.instance.localPlayer);
					}
					else
					{
						Log("onePlayerRemainFunction - Secondary Hand Function Exiting");
						GetExitButton().GetComponent<MatchHandlerInvoker>().Quit(Singleton<PlayerManager>.instance.localPlayer);
					}
					break;
				case 2:
					Log("onePlayerRemainFunction - Requeueing");
					GetRequeueButton().GetComponent<MatchHandlerInvoker>().Requeue(Singleton<PlayerManager>.instance.localPlayer);
					break;
				case 3:
					Log("onePlayerRemainFunction - Exiting");
					GetExitButton().GetComponent<MatchHandlerInvoker>().Quit(Singleton<PlayerManager>.instance.localPlayer);
					break;
				default:
					MelonLogger.Error("1 Player Remain Function ERROR: Wrong Value Set in ModUI");
					break;
				case 0:
					break;
				}
			}
			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();
		}
	}

	private static string currentScene = "Loader";

	private Mod AutomaticRematch = new Mod();

	private bool autoPressEnabled = true;

	private float timeToWait = 0f;

	private bool preventAutoRematchButtonEnabled = true;

	private int preventAutoRematchButton = 0;

	private static bool rematchOnFistbumpEnabled = true;

	private static bool primaryHandIsRight = true;

	private static bool secondaryHandFunctionEnabled = true;

	private static bool secondaryHandFunction = true;

	private static bool inMatch = false;

	private static bool needsToRunFunction = false;

	private static int functionToRun = -1;

	private static bool watchingPlayerCount = false;

	private int onePlayerRemainFunction = 0;

	private static bool debug = true;

	private static void Log(string msg)
	{
		if (debug)
		{
			MelonLogger.Msg(msg);
		}
	}

	public override void OnLateInitializeMelon()
	{
		Calls.onMatchEnded += MatchEnded;
		Calls.onMatchStarted += matchStarted;
		UI.instance.UI_Initialized += UIInit;
	}

	private void matchStarted()
	{
		inMatch = true;
	}

	private void UIInit()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Expected O, but got Unknown
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Expected O, but got Unknown
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Expected O, but got Unknown
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Expected O, but got Unknown
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Expected O, but got Unknown
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Expected O, but got Unknown
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Expected O, but got Unknown
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Expected O, but got Unknown
		AutomaticRematch.ModName = "AutomaticRematch";
		AutomaticRematch.ModVersion = "1.3.1";
		AutomaticRematch.SetFolder("AutomaticRematch");
		AutomaticRematch.AddToList("Auto Rematch", true, 1, "Automatically Presses Rematch Button if On", new Tags());
		AutomaticRematch.AddToList("Time Before Pressing", 0f, "Time to Wait before it Presses Rematch", new Tags());
		AutomaticRematch.AddToList("Prevent Auto Rematch Button Enabled", true, 0, "Toggles Button to Stop Rematching On/Off", new Tags());
		AutomaticRematch.AddToList("Prevent Auto Rematch Button", 0, $"Sets What Button it Watches to Prevent Automatic Rematching{Environment.NewLine}0 : Left Controller Trigger{Environment.NewLine}1 : Left Controller Primary{Environment.NewLine}2 : Left Controller Secondary{Environment.NewLine}3 : Right Controller Trigger{Environment.NewLine}4 : Right Controller Primary{Environment.NewLine}5 : Right Controller Secondary", new Tags());
		AutomaticRematch.AddToList("Rematch on Fistbump Enabled", true, 1, "Automatically Presses Rematch Button on Primary Hand Fistbump if On", new Tags());
		AutomaticRematch.AddToList("Primary Hand", true, 0, "True: Right Hand Primary / Left Hand Secondary" + Environment.NewLine + "False: Left Hand Primary / Right Hand Secondary", new Tags());
		AutomaticRematch.AddToList("Secondary Hand Function Enabled", true, 0, "Automatically does the Secondary Hand Function on Secondary Hand Fistbump if On", new Tags());
		AutomaticRematch.AddToList("Secondary Hand Function", false, 0, "True: Automatically Presses Requeue Button" + Environment.NewLine + "False: Automatically Presses Exit", new Tags());
		AutomaticRematch.AddToList("1 Player Remaining Function", 0, $"Sets what to Do When 1 Player Remains after a Match{Environment.NewLine}0: Nothing{Environment.NewLine}1: Secondary Hand Function{Environment.NewLine}2: Requeue{Environment.NewLine}3 : Exit", new Tags());
		AutomaticRematch.GetFromFile();
		AutomaticRematch.ModSaved += Save;
		Save();
		UI.instance.AddMod(AutomaticRematch);
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		currentScene = sceneName;
		inMatch = false;
		watchingPlayerCount = false;
	}

	private void Save()
	{
		autoPressEnabled = (bool)AutomaticRematch.Settings[0].SavedValue;
		timeToWait = (float)AutomaticRematch.Settings[1].SavedValue;
		preventAutoRematchButtonEnabled = (bool)AutomaticRematch.Settings[2].SavedValue;
		preventAutoRematchButton = (int)AutomaticRematch.Settings[3].SavedValue;
		rematchOnFistbumpEnabled = (bool)AutomaticRematch.Settings[4].SavedValue;
		primaryHandIsRight = (bool)AutomaticRematch.Settings[5].SavedValue;
		secondaryHandFunctionEnabled = (bool)AutomaticRematch.Settings[6].SavedValue;
		secondaryHandFunction = (bool)AutomaticRematch.Settings[7].SavedValue;
		onePlayerRemainFunction = (int)AutomaticRematch.Settings[8].SavedValue;
	}

	private void MatchEnded()
	{
		Log("MatchEnded()");
		inMatch = false;
		if (autoPressEnabled)
		{
			Log("MatchEndedAutoPress()");
			MelonCoroutines.Start(MatchEndedAutoPress());
		}
		if (rematchOnFistbumpEnabled && needsToRunFunction)
		{
			Log("Running Function from Fistbump Prior");
			switch (functionToRun)
			{
			case 0:
				Log("Running Function Rematch");
				((InteractionButton)GetRematchButton().GetComponent<RematchButton>()).RPC_OnToggleStateChanged(true);
				break;
			case 1:
				Log("Running Function Requeue");
				GetRequeueButton().GetComponent<MatchHandlerInvoker>().Requeue(Singleton<PlayerManager>.instance.localPlayer);
				break;
			case 2:
				Log("Running Function Exit");
				GetExitButton().GetComponent<MatchHandlerInvoker>().Quit(Singleton<PlayerManager>.instance.localPlayer);
				needsToRunFunction = false;
				functionToRun = -1;
				return;
			default:
				MelonLogger.Error("ERROR WHAT FUNCTION TO RUN???: " + functionToRun);
				break;
			}
			needsToRunFunction = false;
			functionToRun = -1;
		}
		MelonCoroutines.Start(WatchPlayerCount());
	}

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

	private void LeavingMatch()
	{
		Log("LeavingMatch()");
		watchingPlayerCount = false;
	}

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

	private static GameObject GetRematchButton()
	{
		return Players.IsHost() ? GetHostRematchButton() : GetClientRematchButton();
	}

	private static GameObject GetRequeueButton()
	{
		return Players.IsHost() ? GetHostRequeueButton() : GetClientRequeueButton();
	}

	private static GameObject GetExitButton()
	{
		return Players.IsHost() ? GetHostExitButton() : GetClientExitButton();
	}

	private static GameObject GetHostRematchButton()
	{
		return (currentScene == "Map0") ? Button.GetGameObject() : Button.GetGameObject();
	}

	private static GameObject GetHostRequeueButton()
	{
		return (currentScene == "Map0") ? Requeuebutton.GetGameObject() : Requeuebutton.GetGameObject();
	}

	private static GameObject GetHostExitButton()
	{
		return (currentScene == "Map0") ? Exitmatchbutton.GetGameObject() : Exitmatchbutton.GetGameObject();
	}

	private static GameObject GetClientRematchButton()
	{
		return (currentScene == "Map0") ? Button.GetGameObject() : Button.GetGameObject();
	}

	private static GameObject GetClientRequeueButton()
	{
		return (currentScene == "Map0") ? Requeuebutton.GetGameObject() : Requeuebutton.GetGameObject();
	}

	private static GameObject GetClientExitButton()
	{
		return (currentScene == "Map0") ? Exitmatchbutton.GetGameObject() : Exitmatchbutton.GetGameObject();
	}
}