Decompiled source of DressGirlChaseMusic v1.0.0

Flaff.DressGirlChaseMusic.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
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("Flaff.DressGirlChaseMusic")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Flaff.DressGirlChaseMusic")]
[assembly: AssemblyTitle("Flaff.DressGirlChaseMusic")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace Flaff.DressGirlChaseMusic
{
	internal static class DressGirlChaseAudioManager
	{
		private sealed class Details
		{
			private readonly DressGirlAI dressGirl;

			private readonly AudioSource? audioSource;

			public DressGirlAI DressGirl => dressGirl;

			public Details(DressGirlAI dressGirl, AudioSource audioSource)
			{
				this.dressGirl = dressGirl;
				this.audioSource = audioSource;
			}

			public void StartAudio()
			{
				if ((Object)(object)audioSource == (Object)null)
				{
					logSource.LogWarning((object)"Cannot start chase audio: Audio source not found!");
				}
				else
				{
					audioSource.Play();
				}
			}

			public void StopAudio()
			{
				if ((Object)(object)audioSource == (Object)null)
				{
					logSource.LogWarning((object)"Cannot stop chase audio: Audio source not found!");
				}
				else
				{
					audioSource.Stop();
				}
			}
		}

		private static readonly List<Details> instances = new List<Details>();

		private static ManualLogSource logSource = null;

		private static AudioClip chaseMusic = null;

		private static bool initialized = false;

		public static bool Initialize(ManualLogSource logSource, AudioClip? chaseMusic)
		{
			if (initialized)
			{
				return false;
			}
			DressGirlChaseAudioManager.logSource = logSource;
			if ((Object)(object)chaseMusic == (Object)null)
			{
				logSource.LogFatal((object)"DressGirlChaseAudioManager: Failed to load chase music");
				return false;
			}
			DressGirlChaseAudioManager.chaseMusic = chaseMusic;
			initialized = true;
			return true;
		}

		public static void Cleanup()
		{
			instances.Clear();
			instances.TrimExcess();
		}

		public static bool CreateInstance(DressGirlAI dressGirl)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			if (!initialized)
			{
				logSource.LogWarning((object)"DressGirlChaseAudioManager: Cannot create dress girl chase audio instance - not initialized!");
				return false;
			}
			Details details;
			for (int i = 0; i < instances.Count; i++)
			{
				details = instances[i];
				if ((Object)(object)details.DressGirl == (Object)(object)dressGirl)
				{
					logSource.LogWarning((object)"DressGirlChaseAudioManager: A chase audio was already created for the specified dress girl!");
					return false;
				}
			}
			Transform parent = ((Component)((EnemyAI)dressGirl).creatureVoice).transform.parent;
			GameObject val = new GameObject
			{
				name = "Chase Audio"
			};
			val.transform.SetParent(parent);
			val.transform.localPosition = Vector3.zero;
			val.transform.localScale = Vector3.one;
			val.transform.localRotation = Quaternion.identity;
			AudioSource val2 = val.AddComponent<AudioSource>();
			val2.loop = true;
			val2.clip = chaseMusic;
			val2.dopplerLevel = 0f;
			val2.rolloffMode = (AudioRolloffMode)0;
			val2.minDistance = 2f;
			val2.maxDistance = 10f;
			val2.volume = 1.5f;
			val2.spatialBlend = 1f;
			val2.playOnAwake = false;
			val2.priority = 0;
			details = new Details(dressGirl, val2);
			instances.Add(details);
			return true;
		}

		public static void StartChaseMusic(DressGirlAI dressGirl)
		{
			for (int i = 0; i < instances.Count; i++)
			{
				Details details = instances[i];
				if ((Object)(object)details.DressGirl == (Object)(object)dressGirl)
				{
					details.StartAudio();
					break;
				}
			}
		}

		public static void StopChaseMusic(DressGirlAI dressGirl)
		{
			for (int i = 0; i < instances.Count; i++)
			{
				Details details = instances[i];
				if ((Object)(object)details.DressGirl == (Object)(object)dressGirl)
				{
					details.StopAudio();
					break;
				}
			}
		}
	}
	[BepInPlugin("dev.flaff.lethal_company.DancingMusicGirl", "DancingMusicGirl", "1.0.0")]
	internal sealed class EntryPoint : BaseUnityPlugin
	{
		private readonly Harmony patcher;

		public EntryPoint()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			patcher = new Harmony("dev.flaff.lethal_company.DancingMusicGirl");
		}

		private void Awake()
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Flaff.DressGirlChaseMusic.Assets.bundle");
			AssetBundle val = AssetBundle.LoadFromStream(stream);
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogFatal((object)"Failed to load asset bundle!");
			}
			else if (DressGirlChaseAudioManager.Initialize(((BaseUnityPlugin)this).Logger, val.LoadAsset<AudioClip>("assets/dress-girl-chase.mp3")))
			{
				patcher.PatchAll(typeof(HarmonyPatches));
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded successfully!");
			}
		}
	}
	[HarmonyPatch]
	internal static class HarmonyPatches
	{
		[HarmonyPatch(typeof(DressGirlAI), "Start")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		private static void Start(DressGirlAI __instance)
		{
			DressGirlChaseAudioManager.CreateInstance(__instance);
		}

		[HarmonyPatch(typeof(DressGirlAI), "BeginChasing")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		private static void BeginChasing(DressGirlAI __instance)
		{
			DressGirlChaseAudioManager.StartChaseMusic(__instance);
		}

		[HarmonyPatch(typeof(DressGirlAI), "StopChasing")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		private static void StopChasing(DressGirlAI __instance)
		{
			DressGirlChaseAudioManager.StopChaseMusic(__instance);
		}

		[HarmonyPatch(typeof(StartOfRound), "ShipHasLeft")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		private static void ShipHasLeft()
		{
			DressGirlChaseAudioManager.Cleanup();
		}
	}
	internal static class PluginInfo
	{
		public const string Version = "1.0.0";

		public const string Name = "DancingMusicGirl";

		public const string GUID = "dev.flaff.lethal_company.DancingMusicGirl";
	}
}