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 System.Threading;
using MelonLoader;
using RUMBLE.Managers;
using RUMBLE.Players;
using RUMBLE.Players.Subsystems;
using RumbleSoundsOnSceneChange;
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(AdditionalSounds), "Additional Sounds", "1.0.5", "UlvakSkillz", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: AssemblyTitle("RumbleSoundsOnSceneChange")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RumbleSoundsOnSceneChange")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ec0b0af5-fe4b-4046-b655-6fafa96924e1")]
[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 RumbleSoundsOnSceneChange;
public class AdditionalSounds : MelonMod
{
private string[] FilePaths = new string[13];
private string lastScene = "";
private string currentScene = "";
private static Thread[] threads = new Thread[4];
private static bool[] threadActive = new bool[threads.Length];
private bool playedTooLowSound = false;
private bool tooLowSoundListen = false;
private bool playedTooHighSound = false;
private bool tooHighSoundListen = false;
private float tooLowRespawnHeight = 0f;
private float tooLowHeight = 0f;
private float tooHighRespawnHeight = 0f;
private float tooHighHeight = 0f;
private GameObject player;
private PlayerManager playerManager;
private Player localPlayer;
private int localPlayerHealth = -1;
private bool finishedHealingAfterDeath = false;
private bool checkHeartbeat = false;
public override void OnInitializeMelon()
{
((MelonBase)this).OnInitializeMelon();
FilePaths[0] = "UserData\\AdditionalSounds\\GameLoadSound.wav";
FilePaths[1] = "UserData\\AdditionalSounds\\EnterGymFromLoaderSound.wav";
FilePaths[2] = "UserData\\AdditionalSounds\\EnterGymFromParkSound.wav";
FilePaths[3] = "UserData\\AdditionalSounds\\EnterGymFromMatchmakingSound.wav";
FilePaths[4] = "UserData\\AdditionalSounds\\EnterParkSound.wav";
FilePaths[5] = "UserData\\AdditionalSounds\\EnterMatchmakingFromGymSound.wav";
FilePaths[6] = "UserData\\AdditionalSounds\\EnterMatchmakingFromMatchmakingSound.wav";
FilePaths[7] = "UserData\\AdditionalSounds\\TooLowSound.wav";
FilePaths[8] = "UserData\\AdditionalSounds\\TooHighSound.wav";
FilePaths[9] = "UserData\\AdditionalSounds\\SelfDamagedSound.wav";
FilePaths[10] = "UserData\\AdditionalSounds\\EnemyDamagedSound.wav";
FilePaths[11] = "UserData\\AdditionalSounds\\SelfHealSound.wav";
FilePaths[12] = "UserData\\AdditionalSounds\\LowHealthSound.wav";
threadActive[0] = false;
threadActive[1] = false;
MelonLogger.Msg("Initialized");
}
public override void OnUpdate()
{
((MelonBase)this).OnUpdate();
if (!(currentScene != "") || !(currentScene != "Loader"))
{
return;
}
if ((Object)(object)player == (Object)null)
{
try
{
player = GameObject.Find("Health/Local");
if (currentScene == "Map0" || currentScene == "Map1")
{
PlayerHealth component2 = ((Component)GameObject.Find("Health/Remote").transform.parent).GetComponent<PlayerHealth>();
((UnityEvent<short>)(object)component2.onDamageTaken).AddListener(UnityAction<short>.op_Implicit((Action<short>)delegate
{
PlaySoundIfFileExists(FilePaths[10], 2);
}));
}
GameObject val = GameObject.Find("Game Instance/Initializable/PlayerManager");
playerManager = val.gameObject.GetComponent<PlayerManager>();
localPlayer = playerManager.localPlayer;
localPlayerHealth = localPlayer.Data.HealthPoints;
return;
}
catch (Exception ex)
{
MelonLogger.Msg("Error: " + ex.Message);
MelonLogger.Msg(ex.StackTrace);
return;
}
}
if (tooLowSoundListen)
{
CheckForTooLow();
}
if (tooHighSoundListen)
{
CheckForTooHigh();
}
checkLocalHealth();
}
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
((MelonMod)this).OnSceneWasLoaded(buildIndex, sceneName);
lastScene = currentScene;
currentScene = sceneName;
finishedHealingAfterDeath = false;
localPlayerHealth = -1;
switch (currentScene)
{
case "Loader":
PlaySoundIfFileExists(FilePaths[0], 0);
break;
case "Gym":
tooLowRespawnHeight = 0f;
tooLowHeight = -10f;
tooHighRespawnHeight = 2f;
tooHighHeight = 23.5f;
switch (lastScene)
{
case "Loader":
PlaySoundIfFileExists(FilePaths[1], 0);
break;
case "Park":
PlaySoundIfFileExists(FilePaths[2], 0);
break;
case "Map0":
case "Map1":
PlaySoundIfFileExists(FilePaths[3], 0);
break;
}
break;
case "Park":
tooLowRespawnHeight = -5.5f;
tooLowHeight = -10f;
tooHighRespawnHeight = 2f;
tooHighHeight = 26.5f;
PlaySoundIfFileExists(FilePaths[4], 0);
break;
case "Map0":
case "Map1":
if (currentScene == "Map0")
{
tooLowRespawnHeight = 0f;
tooLowHeight = -5f;
tooHighRespawnHeight = 3.5f;
tooHighHeight = 12.5f;
}
else if (currentScene == "Map1")
{
tooLowRespawnHeight = 0f;
tooLowHeight = -1f;
tooHighRespawnHeight = 3f;
tooHighHeight = 12.75f;
}
switch (lastScene)
{
case "Gym":
PlaySoundIfFileExists(FilePaths[5], 0);
break;
case "Map0":
case "Map1":
PlaySoundIfFileExists(FilePaths[6], 0);
break;
}
break;
}
tooLowSoundListen = true;
tooHighSoundListen = true;
}
private void checkLocalHealth()
{
if (localPlayer.Data.HealthPoints == 0)
{
finishedHealingAfterDeath = false;
}
else if (localPlayerHealth == 20)
{
finishedHealingAfterDeath = true;
checkHeartbeat = true;
}
else
{
if (!finishedHealingAfterDeath || localPlayerHealth == -1)
{
localPlayerHealth = localPlayer.Data.HealthPoints;
return;
}
if (localPlayer.Data.HealthPoints <= 8)
{
PlaySoundIfFileExists(FilePaths[12], 3);
}
}
if (localPlayer.Data.HealthPoints == localPlayerHealth)
{
return;
}
if (finishedHealingAfterDeath)
{
if (localPlayer.Data.HealthPoints < localPlayerHealth)
{
PlaySoundIfFileExists(FilePaths[9], 0);
}
else if (localPlayer.Data.HealthPoints > localPlayerHealth)
{
PlaySoundIfFileExists(FilePaths[11], 0);
}
}
localPlayerHealth = localPlayer.Data.HealthPoints;
}
private void CheckForTooLow()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
if (player.transform.position.y >= tooLowRespawnHeight && playedTooLowSound)
{
playedTooLowSound = false;
}
else if (player.transform.position.y <= tooLowHeight && !playedTooLowSound)
{
playedTooLowSound = true;
PlaySoundIfFileExists(FilePaths[7], 1);
}
}
private void CheckForTooHigh()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
if (player.transform.position.y <= tooHighRespawnHeight && playedTooHighSound)
{
playedTooHighSound = false;
}
else if (player.transform.position.y >= tooHighHeight && !playedTooHighSound)
{
playedTooHighSound = true;
PlaySoundIfFileExists(FilePaths[8], 1);
}
}
private void PlaySoundIfFileExists(string soundFilePath, int threadToPlayOn)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Expected O, but got Unknown
if (File.Exists(soundFilePath))
{
if (threadActive[threadToPlayOn])
{
return;
}
try
{
SoundPlayer player = new SoundPlayer(soundFilePath);
try
{
threadActive[threadToPlayOn] = true;
if (threads[threadToPlayOn] == null || !threads[threadToPlayOn].IsAlive)
{
threads[threadToPlayOn] = new Thread((ThreadStart)delegate
{
player.PlaySync();
threadActive[threadToPlayOn] = false;
});
threads[threadToPlayOn].Start();
}
return;
}
finally
{
if (player != null)
{
((IDisposable)player).Dispose();
}
}
}
catch (Exception ex)
{
MelonLogger.Msg("Error playing sound: " + ex.Message);
return;
}
}
MelonLogger.Msg("Sound File Doesn't Exist: " + soundFilePath);
}
}