Decompiled source of UlvakSkillz Match Found Notifier v1.0.1

Mods/Match Found Notifier.dll

Decompiled 2 years ago
using System;
using System.Diagnostics;
using System.IO;
using System.Media;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Match_Found_Notifier;
using MelonLoader;

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

	public override void OnUpdate()
	{
		((MelonBase)this).OnUpdate();
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		if (lastScene == "Gym" && (sceneName == "Map0" || sceneName == "Map1"))
		{
			PlayNotifications();
		}
		lastScene = sceneName;
	}

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

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

	public void PlayNotificationSound()
	{
		string text = "UserData\\MatchFound\\NotificationSound.wav";
		if (File.Exists(text))
		{
			PlaySound(text);
		}
		else
		{
			((MelonBase)this).LoggerInstance.Msg("Notification Sound file not found.");
		}
	}

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

	private static void PlaySound(string soundFilePath)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Expected O, but got Unknown
		try
		{
			SoundPlayer val = new SoundPlayer(soundFilePath);
			try
			{
				val.Play();
				val.PlaySync();
			}
			finally
			{
				((IDisposable)val)?.Dispose();
			}
		}
		catch (Exception ex)
		{
			Console.WriteLine("Error playing sound: " + ex.Message);
		}
	}
}