Decompiled source of JetpackMusicFix v1.0.0

tracerx.JetpackMusicFix.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("tracerx.JetpackMusicFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("tracerx.JetpackMusicFix")]
[assembly: AssemblyTitle("tracerx.JetpackMusicFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace tracerx.JetpackMusicFix
{
	public class AudioSourceStateTracker : MonoBehaviour
	{
		public bool IsPaused { get; set; }

		public int OriginalClipSamples { get; set; }
	}
	[BepInPlugin("tracerx.JetpackMusicFix", "tracerx.JetpackMusicFix", "1.0.0")]
	public class tracerx_JetpackMusicFix : BaseUnityPlugin
	{
		public static tracerx_JetpackMusicFix Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			Logger.LogInfo((object)"tracerx.JetpackMusicFix v1.0.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("tracerx.JetpackMusicFix");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "tracerx.JetpackMusicFix";

		public const string PLUGIN_NAME = "tracerx.JetpackMusicFix";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace tracerx.JetpackMusicFix.Patches
{
	[HarmonyPatch(typeof(AudioSource))]
	internal class AudioSourcePatch
	{
		private const string JetpackAudioSource = "ThrusterAudioClose";

		[HarmonyPatch("Play", new Type[] { })]
		[HarmonyBefore(new string[] { "LC_SoundTool" })]
		[HarmonyPrefix]
		private static bool PlayPrefixPatch(AudioSource __instance)
		{
			if (((Object)__instance).name != "ThrusterAudioClose")
			{
				return true;
			}
			AudioSourceStateTracker audioSourceStateTracker = ((Component)__instance).GetComponent<AudioSourceStateTracker>();
			if ((Object)(object)audioSourceStateTracker == (Object)null)
			{
				audioSourceStateTracker = ((Component)__instance).gameObject.AddComponent<AudioSourceStateTracker>();
			}
			if (!audioSourceStateTracker.IsPaused)
			{
				return true;
			}
			__instance.UnPause();
			return false;
		}

		[HarmonyPatch("Play", new Type[] { typeof(ulong) })]
		[HarmonyBefore(new string[] { "LC_SoundTool" })]
		[HarmonyPrefix]
		private static bool PlayPrefixPatch(AudioSource __instance, ulong delay)
		{
			if (((Object)__instance).name != "ThrusterAudioClose")
			{
				return true;
			}
			AudioSourceStateTracker audioSourceStateTracker = ((Component)__instance).GetComponent<AudioSourceStateTracker>();
			if ((Object)(object)audioSourceStateTracker == (Object)null)
			{
				audioSourceStateTracker = ((Component)__instance).gameObject.AddComponent<AudioSourceStateTracker>();
			}
			if (!audioSourceStateTracker.IsPaused)
			{
				return true;
			}
			__instance.UnPause();
			return false;
		}

		[HarmonyPatch("Play", new Type[] { typeof(double) })]
		[HarmonyBefore(new string[] { "LC_SoundTool" })]
		[HarmonyPrefix]
		private static bool PlayPrefixPatch(AudioSource __instance, double delay)
		{
			if (((Object)__instance).name != "ThrusterAudioClose")
			{
				return true;
			}
			AudioSourceStateTracker audioSourceStateTracker = ((Component)__instance).GetComponent<AudioSourceStateTracker>();
			if ((Object)(object)audioSourceStateTracker == (Object)null)
			{
				audioSourceStateTracker = ((Component)__instance).gameObject.AddComponent<AudioSourceStateTracker>();
			}
			if (!audioSourceStateTracker.IsPaused)
			{
				return true;
			}
			__instance.UnPause();
			return false;
		}

		[HarmonyPatch("Pause")]
		[HarmonyPrefix]
		private static void PausePrefixPatch(AudioSource __instance)
		{
			if (!(((Object)__instance).name != "ThrusterAudioClose"))
			{
				AudioSourceStateTracker audioSourceStateTracker = ((Component)__instance).GetComponent<AudioSourceStateTracker>();
				if ((Object)(object)audioSourceStateTracker == (Object)null)
				{
					audioSourceStateTracker = ((Component)__instance).gameObject.AddComponent<AudioSourceStateTracker>();
				}
				audioSourceStateTracker.IsPaused = true;
			}
		}

		[HarmonyPatch("Stop", new Type[] { })]
		[HarmonyPrefix]
		private static bool StopPrefixPatch(AudioSource __instance)
		{
			if (((Object)__instance).name != "ThrusterAudioClose")
			{
				return true;
			}
			__instance.Pause();
			return false;
		}

		[HarmonyPatch("Stop", new Type[] { typeof(bool) })]
		[HarmonyPrefix]
		private static bool StopPrefixPatch(AudioSource __instance, bool stopOneShots)
		{
			if (((Object)__instance).name != "ThrusterAudioClose")
			{
				return true;
			}
			__instance.Pause();
			return false;
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static bool SetClipPrefixPatch(AudioSource __instance, AudioClip value)
		{
			if (((Object)__instance).name != "ThrusterAudioClose")
			{
				return true;
			}
			AudioSourceStateTracker audioSourceStateTracker = ((Component)__instance).GetComponent<AudioSourceStateTracker>();
			if ((Object)(object)audioSourceStateTracker == (Object)null)
			{
				audioSourceStateTracker = ((Component)__instance).gameObject.AddComponent<AudioSourceStateTracker>();
			}
			string name = ((Object)value).name;
			AudioClip clip = __instance.clip;
			if (name == ((clip != null) ? ((Object)clip).name : null) && value.samples == audioSourceStateTracker.OriginalClipSamples)
			{
				return false;
			}
			audioSourceStateTracker.IsPaused = false;
			string name2 = ((Object)value).name;
			AudioClip clip2 = __instance.clip;
			if (name2 != ((clip2 != null) ? ((Object)clip2).name : null))
			{
				audioSourceStateTracker.OriginalClipSamples = value.samples;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(JetpackItem))]
	internal class JetpackItemPatch
	{
		[HarmonyPatch("ItemActivate")]
		[HarmonyPrefix]
		private static void ItemActivatePrefixPatch(JetpackItem __instance)
		{
			AudioSourceStateTracker component = ((Component)__instance).GetComponent<AudioSourceStateTracker>();
			if ((Object)(object)component == (Object)null)
			{
				component = ((Component)__instance).gameObject.AddComponent<AudioSourceStateTracker>();
			}
			if (!__instance.jetpackAudio.loop)
			{
				__instance.jetpackAudio.loop = true;
			}
		}
	}
}