Decompiled source of AutomaticRematch v1.3.0

Mods/AutomaticRematch.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.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;

[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.0", "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.0";

		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)
				{
					return;
				}
				if (num < num2)
				{
					GameObject val = (Players.IsHost() ? GetHostRematchButton() : GetClientRematchButton());
					((InteractionButton)val.GetComponent<RematchButton>()).RPC_OnToggleStateChanged(true);
				}
				else if (secondaryHandFunctionEnabled)
				{
					if (secondaryHandFunction)
					{
						GameObject val2 = (Players.IsHost() ? GetHostRequeueButton() : GetClientRequeueButton());
						val2.GetComponent<MatchHandlerInvoker>().Requeue(Singleton<PlayerManager>.instance.localPlayer);
					}
					else
					{
						GameObject val3 = (Players.IsHost() ? GetHostExitButton() : GetClientExitButton());
						val3.GetComponent<MatchHandlerInvoker>().Quit(Singleton<PlayerManager>.instance.localPlayer);
					}
				}
				return;
			}
			needsToRunFunction = true;
			if (num < num2)
			{
				functionToRun = 0;
			}
			else if (secondaryHandFunctionEnabled)
			{
				if (secondaryHandFunction)
				{
					functionToRun = 1;
				}
				else
				{
					functionToRun = 2;
				}
			}
		}
	}

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

		private object <>2__current;

		public Main <>4__this;

		private GameObject <myButton>5__1;

		private float <buttonValue>5__2;

		private int <>s__3;

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

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

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

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

		private bool MoveNext()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<myButton>5__1 = (Players.IsHost() ? GetHostRematchButton() : GetClientRematchButton());
				<>2__current = (object)new WaitForSeconds(<>4__this.timeToWait);
				<>1__state = 1;
				return true;
			case 1:
			{
				<>1__state = -1;
				<buttonValue>5__2 = 0f;
				int preventAutoRematchButton = <>4__this.preventAutoRematchButton;
				<>s__3 = preventAutoRematchButton;
				switch (<>s__3)
				{
				case 0:
					<buttonValue>5__2 = LeftController.GetTrigger();
					break;
				case 1:
					<buttonValue>5__2 = LeftController.GetPrimary();
					break;
				case 2:
					<buttonValue>5__2 = LeftController.GetSecondary();
					break;
				case 3:
					<buttonValue>5__2 = RightController.GetTrigger();
					break;
				case 4:
					<buttonValue>5__2 = RightController.GetPrimary();
					break;
				case 5:
					<buttonValue>5__2 = RightController.GetSecondary();
					break;
				}
				if (!<>4__this.preventAutoRematchButtonEnabled || <buttonValue>5__2 < 0.5f)
				{
					((InteractionButton)<myButton>5__1.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();
		}
	}

	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 void Log(string msg)
	{
		MelonLogger.Msg(msg);
	}

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

	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
		AutomaticRematch.ModName = "AutomaticRematch";
		AutomaticRematch.ModVersion = "1.3.0";
		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.GetFromFile();
		AutomaticRematch.ModSaved += Save;
		Save();
		UI.instance.AddMod(AutomaticRematch);
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		currentScene = sceneName;
		inMatch = 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;
	}

	private void matchEnded()
	{
		inMatch = false;
		if (autoPressEnabled)
		{
			MelonCoroutines.Start(MatchEndedAutoPress());
		}
		if (rematchOnFistbumpEnabled && needsToRunFunction)
		{
			switch (functionToRun)
			{
			case 0:
			{
				GameObject val3 = (Players.IsHost() ? GetHostRematchButton() : GetClientRematchButton());
				((InteractionButton)val3.GetComponent<RematchButton>()).RPC_OnToggleStateChanged(true);
				break;
			}
			case 1:
			{
				GameObject val2 = (Players.IsHost() ? GetHostRequeueButton() : GetClientRequeueButton());
				val2.GetComponent<MatchHandlerInvoker>().Requeue(Singleton<PlayerManager>.instance.localPlayer);
				break;
			}
			case 2:
			{
				GameObject val = (Players.IsHost() ? GetHostExitButton() : GetClientExitButton());
				val.GetComponent<MatchHandlerInvoker>().Quit(Singleton<PlayerManager>.instance.localPlayer);
				break;
			}
			default:
				MelonLogger.Error("ERROR WHAT FUNCTION TO RUN???: " + functionToRun);
				break;
			}
			needsToRunFunction = false;
			functionToRun = -1;
		}
	}

	private void matchStarted()
	{
		inMatch = true;
	}

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

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

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

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

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

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

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