using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
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("SlimeYuri_CustomBugle")]
[assembly: AssemblyDescription("可加载无限数量的 OGG、WAV 和 MP3 音频文件来替换喇叭的音效(菜单按C[默认]);This module enables you to load an unlimited number of OGG, WAV and MP3 audio files to replace the sound effects of Bugle.(C for menu[Default])")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SlimeYuri_CustomBugle")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4409cff3-398c-4a65-ba84-16595b826019")]
[assembly: AssemblyFileVersion("1.3.2.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.3.2.0")]
namespace SlimeYuri_CustomBugle;
[BepInPlugin("CustomBugle_SlimeYuri", "CustomBugle", "1.3.0")]
[BepInProcess("PEAK.exe")]
public class Peak_Project : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <LoadAudioClip>d__2 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public int index;
public string filePath;
public Peak_Project <>4__this;
private string <uri>5__1;
private string <extension>5__2;
private AudioType <audioType>5__3;
private string <>s__4;
private UnityWebRequest <uwr>5__5;
private AudioClip <clip>5__6;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <LoadAudioClip>d__2(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 1)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<uri>5__1 = null;
<extension>5__2 = null;
<>s__4 = null;
<uwr>5__5 = null;
<clip>5__6 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Invalid comparison between Unknown and I4
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Invalid comparison between Unknown and I4
try
{
switch (<>1__state)
{
default:
return false;
case 0:
{
<>1__state = -1;
<uri>5__1 = "file://" + filePath;
<extension>5__2 = Path.GetExtension(filePath).ToLower();
string text = <extension>5__2;
<>s__4 = text;
switch (<>s__4)
{
case ".mp3":
<audioType>5__3 = (AudioType)13;
break;
case ".wav":
<audioType>5__3 = (AudioType)20;
break;
case ".ogg":
<audioType>5__3 = (AudioType)14;
break;
default:
((BaseUnityPlugin)<>4__this).Logger.LogWarning((object)("[CustomBugle] 不支持的文件格式: " + <extension>5__2));
return false;
}
<>s__4 = null;
<uwr>5__5 = UnityWebRequestMultimedia.GetAudioClip(<uri>5__1, <audioType>5__3);
<>1__state = -3;
<>2__current = <uwr>5__5.SendWebRequest();
<>1__state = 1;
return true;
}
case 1:
<>1__state = -3;
if ((int)<uwr>5__5.result == 2 || (int)<uwr>5__5.result == 3)
{
((BaseUnityPlugin)<>4__this).Logger.LogError((object)("[CustomBugle] 加载失败: " + filePath + ", Error: " + <uwr>5__5.error));
}
else
{
<clip>5__6 = DownloadHandlerAudioClip.GetContent(<uwr>5__5);
if ((Object)(object)<clip>5__6 != (Object)null)
{
customBugleClips[index] = <clip>5__6;
((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)("[CustomBugle] 成功加载: " + filePath));
MusicNum = customBugleClips.Keys.Count((int key) => key >= 0);
Debug.LogError((object)$"有 {MusicNum}首歌曲");
RefactorIndex = customBugleClips.Keys.Count((int key) => key >= 0);
Debug.LogError((object)$" 重构因子{RefactorIndex}");
}
else
{
((BaseUnityPlugin)<>4__this).Logger.LogError((object)("[CustomBugle] 音频解码失败: " + filePath));
}
<clip>5__6 = null;
}
<>m__Finally1();
<uwr>5__5 = null;
return false;
}
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<uwr>5__5 != null)
{
((IDisposable)<uwr>5__5).Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
internal static float globalVolume = 0.35f;
private const float VOLUME_STEP = 0.05f;
private const float CLAMP_MIN = 0f;
private const float CLAMP_MAX = 1f;
private ConfigEntry<KeyCode> hotkey;
private Rect windowRect = new Rect((float)(Screen.width - 110), 10f, 100f, 60f);
private static bool openRandomPitch = true;
private static bool open = false;
private static Dictionary<int, AudioClip> customBugleClips = new Dictionary<int, AudioClip>();
private static float Counter = 0f;
private static int RefactorIndex = 10;
private static int MusicNum = 0;
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_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: 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);
val.PatchAll(typeof(Peak_Project));
((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++;
}
}
}
[IteratorStateMachine(typeof(<LoadAudioClip>d__2))]
private IEnumerator LoadAudioClip(int index, string filePath)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <LoadAudioClip>d__2(0)
{
<>4__this = this,
index = index,
filePath = filePath
};
}
[HarmonyPrefix]
[HarmonyPatch(typeof(BugleSFX), "Update")]
private static void UpdatePrefix(BugleSFX __instance)
{
float axis = Input.GetAxis("Mouse ScrollWheel");
__instance.volume = globalVolume;
if ((Mathf.Abs(axis) > float.Epsilon) & open)
{
globalVolume += axis * 0.05f;
globalVolume = Mathf.Clamp(globalVolume, 0f, 1f);
Debug.Log((object)$"[CustomBugle] 滚轮调整音量至: {globalVolume:F2}");
}
}
private static void UpdatePostfix(object __instance)
{
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Expected O, but got Unknown
Counter += Time.deltaTime;
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)
{
return;
}
bool flag = (bool)fieldInfo.GetValue(__instance);
AudioSource val = (AudioSource)fieldInfo3.GetValue(__instance);
int key2 = (int)fieldInfo4.GetValue(__instance);
if (!flag || !((Object)(object)val != (Object)null) || !customBugleClips.TryGetValue(key2, out var value) || !((Object)(object)val.clip != (Object)(object)value))
{
return;
}
val.clip = value;
if (!openRandomPitch)
{
val.pitch = 1f;
}
val.Play();
if (!(Counter > 0.2f) || MusicNum <= 4)
{
return;
}
Counter = 0f;
List<KeyValuePair<int, AudioClip>> list = customBugleClips.OrderBy((KeyValuePair<int, AudioClip> pair) => pair.Key).ToList();
Dictionary<int, AudioClip> dictionary = new Dictionary<int, AudioClip>();
int num = Random.Range(RefactorIndex - MusicNum, RefactorIndex - 4 + 1);
foreach (KeyValuePair<int, AudioClip> item in list)
{
int key3 = item.Key - num;
dictionary[key3] = item.Value;
}
customBugleClips = dictionary;
RefactorIndex = customBugleClips.Keys.Count((int key) => key >= 0);
foreach (int key4 in customBugleClips.Keys)
{
Debug.LogError((object)"以下是重构~");
Debug.LogError((object)key4);
Debug.LogError((object)customBugleClips[key4]);
}
Debug.LogError((object)$" 重构因子{RefactorIndex}");
}
private void Start()
{
hotkey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("快捷键", "hotkey", (KeyCode)99, "默认键位键盘C,改键位时复制上述支持的键位即可:The default key for the keyboard is C. When changing the key, you can copy the supported keys mentioned above.");
}
private void Update()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown(hotkey.Value))
{
open = !open;
}
}
private void OnGUI()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
if (open)
{
windowRect = GUILayout.Window(0, windowRect, new WindowFunction(WindowFun), "Manager", Array.Empty<GUILayoutOption>());
}
}
public void WindowFun(int id)
{
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.FlexibleSpace();
if (GUILayout.Button("X", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(22f) }))
{
open = false;
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
GUILayout.Label("音量:Volume", Array.Empty<GUILayoutOption>());
GUILayout.Label((int)(globalVolume * 100f) + "%", Array.Empty<GUILayoutOption>());
GUILayout.EndHorizontal();
GUILayout.HorizontalSlider(globalVolume, 0f, 1f, Array.Empty<GUILayoutOption>());
GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
openRandomPitch = GUILayout.Toggle(openRandomPitch, "点击我关闭随机音调:click me to diactive random Pitch", Array.Empty<GUILayoutOption>());
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
GUILayout.Label("ScrollUp向上滚轮__Volume++", Array.Empty<GUILayoutOption>());
GUILayout.Label("ScrollDown向下滚轮__Volume--", Array.Empty<GUILayoutOption>());
GUILayout.Label("进入ESC菜单来点选按钮", Array.Empty<GUILayoutOption>());
GUILayout.Label("Enter the ESC menu and select the button.", Array.Empty<GUILayoutOption>());
GUILayout.EndHorizontal();
GUI.DragWindow();
}
}