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 UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Erenshor-LevelupSound")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Erenshor-LevelupSound")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("bc4a8707-5e0e-4a26-a49e-439f28dbc304")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Erenshor_LevelupSound;
[BepInPlugin("Brad522.LevelupSound", "Levelup Sound Changer", "1.0.0")]
public class LevelupSound : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <GrabSFX>d__7 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public LevelupSound <>4__this;
public string path;
private UnityWebRequest <uwr>5__2;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <GrabSFX>d__7(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || (uint)(num - 1) <= 1u)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<uwr>5__2 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Invalid comparison between Unknown and I4
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
bool result;
try
{
int num = <>1__state;
LevelupSound levelupSound = <>4__this;
switch (num)
{
default:
result = false;
goto end_IL_0000;
case 0:
{
<>1__state = -1;
((BaseUnityPlugin)levelupSound).Logger.LogMessage((object)("Levelup Sound: Attempting to load audio file from: " + path));
AudioType audioTypeFromExtension = levelupSound.GetAudioTypeFromExtension(Path.GetExtension(path));
if ((int)audioTypeFromExtension == 0)
{
((BaseUnityPlugin)levelupSound).Logger.LogMessage((object)"Levelup Sound: Unsupported audio file type, cannot load sound.");
result = false;
}
else
{
<uwr>5__2 = UnityWebRequestMultimedia.GetAudioClip("file:///" + path, audioTypeFromExtension);
<>1__state = -3;
<>2__current = <uwr>5__2.SendWebRequest();
<>1__state = 1;
result = true;
}
goto end_IL_0000;
}
case 1:
<>1__state = -3;
if ((int)<uwr>5__2.result == 1)
{
lvlupSFX = DownloadHandlerAudioClip.GetContent(<uwr>5__2);
((BaseUnityPlugin)levelupSound).Logger.LogMessage((object)("Levelup Sound: Audio file loaded successfully: " + path));
if ((Object)(object)GameData.Misc == (Object)null)
{
((BaseUnityPlugin)levelupSound).Logger.LogMessage((object)"Levelup Sound: Waiting for GameData.Misc to be initialized...");
}
break;
}
((BaseUnityPlugin)levelupSound).Logger.LogMessage((object)("Levelup Sound: UWR failed: " + <uwr>5__2.error));
result = false;
<>m__Finally1();
goto end_IL_0000;
case 2:
<>1__state = -3;
break;
}
if ((Object)(object)GameData.Misc == (Object)null)
{
<>2__current = null;
<>1__state = 2;
result = true;
}
else
{
GameData.Misc.LvlUpSFX = lvlupSFX;
((BaseUnityPlugin)levelupSound).Logger.LogMessage((object)"Levelup Sound: Custom levelup sound changed.");
<>m__Finally1();
<uwr>5__2 = null;
result = false;
}
end_IL_0000:;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
return result;
}
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__2 != null)
{
((IDisposable)<uwr>5__2).Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
internal const string ModName = "LevelupSound";
internal const string ModVersion = "1.0.0";
internal const string ModDescription = "Levelup Sound Changer";
internal const string Author = "Brad522";
private const string ModGUID = "Brad522.LevelupSound";
public static AudioClip lvlupSFX;
public void Awake()
{
((BaseUnityPlugin)this).Logger.LogMessage((object)"Levelup Sound: Started");
string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
string[] supportedExtensions = new string[3] { ".wav", ".mp3", ".ogg" };
string text = Directory.EnumerateFiles(directoryName).FirstOrDefault((string file) => supportedExtensions.Contains(Path.GetExtension(file).ToLower()));
if (!string.IsNullOrEmpty(text))
{
((MonoBehaviour)this).StartCoroutine(GrabSFX(text));
}
else
{
((BaseUnityPlugin)this).Logger.LogMessage((object)"Levelup Sound: No supported audio file found in mod directory.");
}
}
[IteratorStateMachine(typeof(<GrabSFX>d__7))]
private IEnumerator GrabSFX(string path)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <GrabSFX>d__7(0)
{
<>4__this = this,
path = path
};
}
private AudioType GetAudioTypeFromExtension(string extension)
{
switch (extension.ToLower())
{
case ".wav":
return (AudioType)20;
case ".mp3":
return (AudioType)13;
case ".ogg":
return (AudioType)14;
default:
((BaseUnityPlugin)this).Logger.LogMessage((object)("Levelup Sound: Unsupported audio file type: " + extension));
return (AudioType)0;
}
}
}