Decompiled source of kpdhbugle v1.0.0

kpdhBugle.dll

Decompiled a week ago
using System;
using System.Collections;
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 HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Peak_Project")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Peak_Project")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4409cff3-398c-4a65-ba84-16595b826019")]
[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 Peak_Project;

[BepInPlugin("CustomBugle_SlimeYuri", "CustomBugle", "1.1.0")]
[BepInProcess("PEAK.exe")]
public class Peak_Project : BaseUnityPlugin
{
	private static readonly Dictionary<int, AudioClip> customBugleClips = new Dictionary<int, AudioClip>();

	private void Awake()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[CustomBugle] 启动中");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"BepInEx:HelloWorld");
		Harmony val = new Harmony("CustomBugle_SlimeYuri");
		Type type = AccessTools.TypeByName("BugleSFX");
		if (type == null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"[CustomBugle] 没有找到音频文件SFX!");
			return;
		}
		MethodInfo method = type.GetMethod("Update", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		MethodInfo methodInfo = AccessTools.Method(typeof(Peak_Project), "UpdatePostfix", (Type[])null, (Type[])null);
		if (method == null || methodInfo == null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"[CustomBugle] 没有找到补丁运行方法");
			return;
		}
		val.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(methodInfo), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[CustomBugle] Harmony patch 成功运行");
		LoadCustomClips();
	}

	private void LoadCustomClips()
	{
		string path = Path.Combine(Paths.PluginPath, "Slime_Silly-CustomBugle");
		string[] files = Directory.GetFiles(path);
		int num = 0;
		string[] array = files;
		foreach (string text in array)
		{
			string text2 = Path.GetExtension(text).ToLower();
			if (text2 == ".wav" || text2 == ".mp3" || text2 == ".ogg")
			{
				((MonoBehaviour)this).StartCoroutine(LoadAudioClip(num, text));
				num++;
			}
		}
	}

	private IEnumerator LoadAudioClip(int index, string filePath)
	{
		string uri = "file://" + filePath;
		string extension = Path.GetExtension(filePath).ToLower();
		AudioType audioType;
		switch (extension)
		{
		case ".mp3":
			audioType = (AudioType)13;
			break;
		case ".wav":
			audioType = (AudioType)20;
			break;
		case ".ogg":
			audioType = (AudioType)14;
			break;
		default:
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[CustomBugle] 不支持的文件格式: " + extension));
			yield break;
		}
		UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip(uri, audioType);
		try
		{
			yield return uwr.SendWebRequest();
			if ((int)uwr.result == 2 || (int)uwr.result == 3)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("[CustomBugle] 加载失败: " + filePath + ", Error: " + uwr.error));
				yield break;
			}
			AudioClip clip = DownloadHandlerAudioClip.GetContent(uwr);
			if ((Object)(object)clip != (Object)null)
			{
				customBugleClips[index] = clip;
				((BaseUnityPlugin)this).Logger.LogInfo((object)("[CustomBugle] 成功加载: " + filePath));
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("[CustomBugle] 音频解码失败: " + filePath));
			}
		}
		finally
		{
			((IDisposable)uwr)?.Dispose();
		}
	}

	private static void UpdatePostfix(object __instance)
	{
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Expected O, but got Unknown
		Type type = __instance.GetType();
		FieldInfo fieldInfo = AccessTools.Field(type, "hold");
		FieldInfo fieldInfo2 = AccessTools.Field(type, "bugle");
		FieldInfo fieldInfo3 = AccessTools.Field(type, "buglePlayer");
		FieldInfo fieldInfo4 = AccessTools.Field(type, "currentClip");
		if (!(fieldInfo == null) && !(fieldInfo2 == null) && !(fieldInfo3 == null) && !(fieldInfo4 == null))
		{
			bool flag = (bool)fieldInfo.GetValue(__instance);
			AudioSource val = (AudioSource)fieldInfo3.GetValue(__instance);
			int key = (int)fieldInfo4.GetValue(__instance);
			if (flag && (Object)(object)val != (Object)null && customBugleClips.TryGetValue(key, out var value) && (Object)(object)val.clip != (Object)(object)value)
			{
				val.clip = value;
				val.Play();
			}
		}
	}
}