Decompiled source of Metal Gear Sneaking Theme v3.0.5

Metal_Gear_Sneaking_Theme.dll

Decompiled 4 months ago
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Metal_Gear_Sneaking_Theme;
using Metal_Gear_Sneaking_Theme.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Metal_Gear_Sneaking_Theme")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Metal_Gear_Sneaking_Theme")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("bd6240b3-724d-44cc-8792-3785d75b863d")]
[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")]
[HarmonyPatch(typeof(PlayerControllerB), "Update")]
internal class UpdatePatch
{
	[HarmonyPostfix]
	public static void StopSneakingTheme(ref bool ___isCrouching, ref float ___fallValue, PlayerControllerB __instance)
	{
		//IL_0087: 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)
		if (SneakingThemeBase.musicSource.isPlaying && !___isCrouching && ___fallValue < -20f)
		{
			SneakingThemeBase.musicSource.Stop();
		}
		if (!Object.op_Implicit((Object)(object)SpectatingPatch.spectating))
		{
			return;
		}
		if (SpectatingPatch.spectating.isPlayerDead)
		{
			if (SneakingThemeBase.musicSource.isPlaying)
			{
				SneakingThemeBase.musicSource.Stop();
				SneakingThemeBase.deathSource.Play();
			}
			return;
		}
		AnimatorStateInfo currentAnimatorStateInfo = SpectatingPatch.spectating.playerBodyAnimator.GetCurrentAnimatorStateInfo(0);
		if (CheckAnimation.checkAnimation(((AnimatorStateInfo)(ref currentAnimatorStateInfo)).fullPathHash))
		{
			if (SneakingThemeBase.musicSource.isPlaying && SpectatingPatch.counter > 5)
			{
				SneakingThemeBase.musicSource.Stop();
			}
			else
			{
				SpectatingPatch.counter++;
			}
			return;
		}
		SpectatingPatch.counter = 0;
		if (!SneakingThemeBase.musicSource.isPlaying)
		{
			SneakingThemeBase.musicSource.Play();
		}
	}
}
namespace Metal_Gear_Sneaking_Theme
{
	internal class CheckAnimation
	{
		public static bool checkAnimation(int val)
		{
			if (val != -1298381471 && val != -483816927 && val != 1917280335)
			{
				return true;
			}
			return false;
		}
	}
	[BepInPlugin("Pepeja-Metal_Gear_Sneaking_Theme", "Metal_Gear_Sneaking_Theme", "3.0.5")]
	public class SneakingThemeBase : BaseUnityPlugin
	{
		private const string modGUID = "Pepeja-Metal_Gear_Sneaking_Theme";

		private const string modName = "Metal_Gear_Sneaking_Theme";

		private const string modVersion = "3.0.5";

		private readonly Harmony harmony = new Harmony("Pepeja-Metal_Gear_Sneaking_Theme");

		private static SneakingThemeBase Instance;

		public static ManualLogSource mls;

		public static AudioSource musicSource;

		public static AudioSource deathSource;

		internal static AssetBundle Bundle;

		private void Awake()
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Pepeja-Metal_Gear_Sneaking_Theme");
			string location = ((BaseUnityPlugin)Instance).Info.Location;
			location = location.TrimEnd("Metal_Gear_Sneaking_Theme.dll".ToCharArray());
			Bundle = AssetBundle.LoadFromFile(location + "mgs2sfx");
			musicSource = (AudioSource)((Component)this).gameObject.AddComponent(typeof(AudioSource));
			deathSource = (AudioSource)((Component)this).gameObject.AddComponent(typeof(AudioSource));
			if ((Object)(object)Bundle != (Object)null)
			{
				mls.LogInfo((object)"Sneaking Theme successfully loaded.");
				musicSource.clip = Bundle.LoadAllAssets<AudioClip>().ToList()[1];
				musicSource.loop = true;
				deathSource.clip = Bundle.LoadAllAssets<AudioClip>().ToList()[0];
			}
			else
			{
				mls.LogError((object)"Sneaking Theme could not be loaded.");
			}
			harmony.PatchAll();
		}
	}
}
namespace Metal_Gear_Sneaking_Theme.Patches
{
	[HarmonyPatch(typeof(StartOfRound), "ReviveDeadPlayers")]
	internal class RevivePatch
	{
		[HarmonyPrefix]
		public static void RemoveSpectator()
		{
			if (Object.op_Implicit((Object)(object)SpectatingPatch.spectating))
			{
				SpectatingPatch.spectating = null;
				SpectatingPatch.counter = 10;
			}
		}
	}
	[HarmonyPatch(typeof(PatcherTool), "beginShockGame")]
	internal class ZapGunPatch
	{
		[HarmonyPostfix]
		public static void StopSneakingTheme()
		{
			if (SneakingThemeBase.musicSource.isPlaying)
			{
				SneakingThemeBase.musicSource.Stop();
			}
		}
	}
	[HarmonyPatch(typeof(HUDManager), "SetSpectatingTextToPlayer")]
	internal class SpectatingPatch
	{
		public static PlayerControllerB spectating;

		public static int counter = 10;

		[HarmonyPostfix]
		public static void PlayMusic(PlayerControllerB playerScript)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)playerScript != (Object)null && !playerScript.isPlayerDead)
			{
				counter = 0;
				spectating = playerScript;
				AnimatorStateInfo currentAnimatorStateInfo = playerScript.playerBodyAnimator.GetCurrentAnimatorStateInfo(0);
				if (!CheckAnimation.checkAnimation(((AnimatorStateInfo)(ref currentAnimatorStateInfo)).fullPathHash) && !SneakingThemeBase.musicSource.isPlaying)
				{
					SneakingThemeBase.musicSource.Play();
				}
				else if (SneakingThemeBase.musicSource.isPlaying)
				{
					SneakingThemeBase.musicSource.Stop();
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
	internal class ConnectPatch
	{
		public static string username;

		[HarmonyPostfix]
		public static void getUsername(ref string ___playerUsername)
		{
			if (username == null)
			{
				username = ___playerUsername;
			}
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager), "DisconnectProcess")]
	internal class DisconnectPatch
	{
		[HarmonyPostfix]
		public static void StopSneakingTheme()
		{
			if (SneakingThemeBase.musicSource.isPlaying)
			{
				SneakingThemeBase.musicSource.Stop();
			}
			ConnectPatch.username = null;
			SpectatingPatch.spectating = null;
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
	internal class KillPlayerPatch
	{
		public static bool allowDeath;

		[HarmonyPrefix]
		public static void checkDeath(PlayerControllerB __instance)
		{
			allowDeath = __instance.AllowPlayerDeath();
		}

		[HarmonyPostfix]
		public static void StopSneakingTheme(ref string ___playerUsername)
		{
			if (SneakingThemeBase.musicSource.isPlaying && allowDeath && ___playerUsername == ConnectPatch.username)
			{
				SneakingThemeBase.musicSource.Stop();
				SneakingThemeBase.deathSource.Play();
			}
		}
	}
	[HarmonyPatch(typeof(InteractTrigger), "ladderClimbAnimation")]
	internal class LadderClimbPatch
	{
		[HarmonyPostfix]
		public static void StopSneakingTheme()
		{
			if (SneakingThemeBase.musicSource.isPlaying)
			{
				SneakingThemeBase.musicSource.Stop();
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "Crouch")]
	internal class CrouchPatch
	{
		[HarmonyPostfix]
		public static void PlaySneakingTheme(ref bool ___isCrouching)
		{
			if (___isCrouching)
			{
				SneakingThemeBase.musicSource.Play();
			}
			else if (!___isCrouching && SneakingThemeBase.musicSource.isPlaying)
			{
				SneakingThemeBase.musicSource.Stop();
			}
		}
	}
}