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;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BuglerMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BuglerMod")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4630658f-0bc4-4c7c-ae68-670e5cc9430f")]
[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")]
[BepInPlugin("com.yourname.buglereplace", "Bugle Multi-Sound Replacer", "1.0.0")]
public class BuglerMod : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <LoadClipFromWWW>d__3 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public WWW www;
public int index;
public BuglerMod <>4__this;
public string fileName;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <LoadClipFromWWW>d__3(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
int num = <>1__state;
BuglerMod buglerMod = <>4__this;
switch (num)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = www;
<>1__state = 1;
return true;
case 1:
{
<>1__state = -1;
AudioClip audioClip = www.GetAudioClip(false, false, (AudioType)20);
if ((Object)(object)audioClip != (Object)null)
{
customBugleClips[index] = audioClip;
((BaseUnityPlugin)buglerMod).Logger.LogInfo((object)$"[BuglerMod] Loaded replacement for Bugle {index + 1} from {fileName}");
}
else
{
((BaseUnityPlugin)buglerMod).Logger.LogError((object)("[BuglerMod] Failed to load audio clip: " + fileName));
}
return false;
}
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static readonly Dictionary<int, AudioClip> customBugleClips = new Dictionary<int, AudioClip>();
private void Awake()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"[BuglerMod] Initializing Harmony patch...");
Harmony val = new Harmony("com.yourname.buglereplace");
Type type = AccessTools.TypeByName("BugleSFX");
if (type == null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"[BuglerMod] Could not find BugleSFX type!");
return;
}
MethodInfo method = type.GetMethod("Update", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
MethodInfo methodInfo = AccessTools.Method(typeof(BuglerMod), "UpdatePostfix", (Type[])null, (Type[])null);
if (method == null || methodInfo == null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"[BuglerMod] Failed to find method for patching.");
return;
}
val.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(methodInfo), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"[BuglerMod] Harmony patch applied successfully.");
LoadCustomClips();
}
private void LoadCustomClips()
{
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Expected O, but got Unknown
string path = Path.Combine(Paths.PluginPath, "EmpsTeam-Bugler");
foreach (KeyValuePair<int, string> item in new Dictionary<int, string>
{
{ 0, "Fanfare.wav" },
{ 1, "Reveille.wav" },
{ 2, "Taps.wav" },
{ 3, "YankeeDoodle.wav" }
})
{
string text = Path.Combine(path, item.Value);
if (!File.Exists(text))
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("[BuglerMod] Sound file not found: " + text));
continue;
}
WWW www = new WWW("file://" + text);
((MonoBehaviour)this).StartCoroutine(LoadClipFromWWW(item.Key, www, item.Value));
}
}
[IteratorStateMachine(typeof(<LoadClipFromWWW>d__3))]
private IEnumerator LoadClipFromWWW(int index, WWW www, string fileName)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <LoadClipFromWWW>d__3(0)
{
<>4__this = this,
index = index,
www = www,
fileName = fileName
};
}
private static void UpdatePostfix(object __instance)
{
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: 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 num = (bool)fieldInfo.GetValue(__instance);
AudioSource val = (AudioSource)fieldInfo3.GetValue(__instance);
int key = (int)fieldInfo4.GetValue(__instance);
if (num && (Object)(object)val != (Object)null && customBugleClips.TryGetValue(key, out var value) && (Object)(object)val.clip != (Object)(object)value)
{
val.clip = value;
val.Play();
}
}
}
}