Decompiled source of LC DressGirlExtendAudio v1.0.5

LC_DressGirlExtendAudio.dll

Decompiled 9 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LC_DressGirlExtendAudio.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("LC_DressGirlExtendAudio")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LC_DressGirlExtendAudio")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("672b4602-a3a5-4572-9785-a007665cf49e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LC_DressGirlExtendAudio
{
	[BepInPlugin("Elia.LC_DressGirlExtendAudio", "LC_DressGirlExtendAudio", "1.0.0")]
	public class DressGirlExtendAudioBase : BaseUnityPlugin
	{
		private const string modGUID = "Elia.LC_DressGirlExtendAudio";

		private const string modName = "LC_DressGirlExtendAudio";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Elia.LC_DressGirlExtendAudio");

		private static DressGirlExtendAudioBase Instance;

		internal static ManualLogSource mls;

		internal static Dictionary<string, List<AudioClip>> SoundSFX;

		internal static Dictionary<string, List<AssetBundle>> Bundle;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			SoundSFX = new Dictionary<string, List<AudioClip>>();
			Bundle = new Dictionary<string, List<AssetBundle>>();
			string text = ((BaseUnityPlugin)Instance).Info.Location.TrimEnd("LC_DressGirlExtendAudio.dll".ToCharArray());
			mls = Logger.CreateLogSource("Elia.LC_DressGirlExtendAudio");
			mls.LogInfo((object)"DressGirlExtendAudio mod is awaken.");
			harmony.PatchAll(typeof(DressGirlAIPatch));
			mls.LogInfo((object)"Patching start...");
			mls.LogInfo((object)("Audio Path:  " + text));
			SoundSFX.Add("DressGirlAI", new List<AudioClip>());
			Bundle.Add("DressGirlAI", new List<AssetBundle>());
			try
			{
				if (Directory.Exists(text))
				{
					string[] files = Directory.GetFiles(text, "*_song");
					string[] array = files;
					foreach (string text2 in array)
					{
						Bundle["DressGirlAI"].Add(AssetBundle.LoadFromFile(text2));
					}
				}
			}
			catch
			{
				Debug.Log((object)"Error loading Bundle...");
			}
			mls.LogInfo((object)Bundle["DressGirlAI"].ToString());
			mls.LogInfo((object)"DressGirlExtendAudio loading asset...");
			mls.LogInfo((object)("Asset target: " + text));
			if (Bundle.Count > 0)
			{
				try
				{
					foreach (AssetBundle item in Bundle["DressGirlAI"])
					{
						SoundSFX["DressGirlAI"].AddRange(item.LoadAllAssets<AudioClip>());
					}
				}
				catch
				{
					Debug.Log((object)"Error loading SoundSFX DressGirlAI...");
				}
				mls.LogInfo((object)string.Format("Successfully loaded asset bundle: \n   - Count: {0}", SoundSFX["DressGirlAI"].Count));
			}
			else
			{
				mls.LogError((object)"Failed to load asset bundle...");
			}
		}
	}
}
namespace LC_DressGirlExtendAudio.Patches
{
	[HarmonyPatch(typeof(DressGirlAI))]
	internal class DressGirlAIPatch
	{
		public static AudioClip[] audioList;

		internal static float currentTimeInSeconds;

		internal static ManualLogSource mls = DressGirlExtendAudioBase.mls;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void OverrideAudio(ref DressGirlAI __instance)
		{
			AudioClip[] dressGirlAudioList = getDressGirlAudioList(__instance);
			audioList = dressGirlAudioList;
			__instance.appearStaringSFX = audioList;
			Debug.Log((object)$"Start ok - Audio: ${audioList}");
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void appearStaringSFXPatch(ref DressGirlAI __instance)
		{
			if (audioList == null)
			{
				audioList = getDressGirlAudioList(__instance);
				__instance.appearStaringSFX = audioList;
			}
			else if (Time.time - currentTimeInSeconds > 60f)
			{
				__instance.skipWalkSFX = getRandomAudioClip(audioList);
				currentTimeInSeconds = Time.time;
			}
		}

		public static AudioClip getRandomAudioClip(AudioClip[] audioList)
		{
			Random random = new Random((int)Time.time);
			int num = random.Next(0, audioList.Length);
			return audioList[num];
		}

		public static AudioClip[] getDressGirlAudioList(DressGirlAI __instance)
		{
			AudioClip[] array = (AudioClip[])(object)new AudioClip[DressGirlExtendAudioBase.SoundSFX["DressGirlAI"].Count];
			Debug.Log((object)"Loading sondSFX");
			for (int i = 0; i < DressGirlExtendAudioBase.SoundSFX["DressGirlAI"].Count; i++)
			{
				Debug.Log((object)string.Format("Current i: {0} \n {1}", i, DressGirlExtendAudioBase.SoundSFX["DressGirlAI"][i]));
				array[i] = DressGirlExtendAudioBase.SoundSFX["DressGirlAI"][i];
			}
			audioList = array;
			return array;
		}
	}
}