Decompiled source of Rumble Match Found Notifier v1.0.5

Mods/Match Found Notifier.dll

Decompiled 4 months ago
using System;
using System.Diagnostics;
using System.Media;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;
using Match_Found_Notifier;
using MelonLoader;
using RUMBLE.Managers;
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(MatchFoundNotifierClass), "Rumble: Match Found Notifier Mod", "1.0.4", "UlvakSkillz", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: AssemblyTitle("Match Found Notifier")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Match Found Notifier")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("fa5a5f33-29dc-4eea-8c81-3674bc961d96")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Match_Found_Notifier;

public class MatchFoundNotifierClass : MelonMod
{
	private string currentScene = "";

	private static Thread soundThread;

	private static bool soundThreadActive;

	private bool matchFoundPlayed = false;

	private MatchmakingHandler matchmakingHandler;

	private bool gymInitRan = false;

	public override void OnUpdate()
	{
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Invalid comparison between Unknown and I4
		((MelonBase)this).OnUpdate();
		if (currentScene == "Gym" && !gymInitRan)
		{
			try
			{
				matchmakingHandler = GameObject.Find("--------------LOGIC--------------/Handelers/Matchmaking handler").GetComponent<MatchmakingHandler>();
				gymInitRan = true;
				return;
			}
			catch (Exception ex)
			{
				MelonLogger.Error("Error with Finding MatchmakingHandler");
				MelonLogger.Error(ex.Message);
				return;
			}
		}
		if (!(currentScene == "Gym") || !matchmakingHandler.IsMatchmaking || matchFoundPlayed)
		{
			return;
		}
		try
		{
			if ((int)matchmakingHandler.CurrentMatchmakeStatus == 9)
			{
				MelonLogger.Msg("Match Found!");
				PlayNotifications();
				matchFoundPlayed = true;
			}
		}
		catch (Exception ex2)
		{
			MelonLogger.Error("Error with Listening to Match Found");
			MelonLogger.Error(ex2.Message);
		}
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		((MelonMod)this).OnSceneWasLoaded(buildIndex, sceneName);
		currentScene = sceneName;
		matchFoundPlayed = false;
	}

	public void PlayNotifications()
	{
		PlayNotificationPhoto();
		PlayNotificationSound();
	}

	public void PlayNotificationPhoto()
	{
		string programPath = "UserData\\MatchFound\\NotificationPhoto.png";
		OpenExternalProgram(programPath, "");
	}

	public void PlayNotificationSound()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		string text = "UserData\\MatchFound\\NotificationSound.wav";
		try
		{
			if (soundThreadActive)
			{
				MelonLogger.Msg("Sound is already playing. Ignoring request.");
				return;
			}
			SoundPlayer player = new SoundPlayer(text);
			try
			{
				soundThreadActive = true;
				if (soundThread == null || !soundThread.IsAlive)
				{
					soundThread = new Thread((ThreadStart)delegate
					{
						player.PlaySync();
						soundThreadActive = false;
					});
					soundThread.Start();
				}
			}
			finally
			{
				if (player != null)
				{
					((IDisposable)player).Dispose();
				}
			}
		}
		catch (Exception ex)
		{
			MelonLogger.Msg("Error playing sound: " + ex.Message);
		}
	}

	private void OpenExternalProgram(string programPath, string parameters)
	{
		ProcessStartInfo startInfo = new ProcessStartInfo
		{
			FileName = programPath,
			Arguments = parameters,
			UseShellExecute = true
		};
		try
		{
			Process.Start(startInfo);
		}
		catch (Exception ex)
		{
			MelonLogger.Error("-Error opening external program: " + ex.Message);
		}
	}
}