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.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.ChuMenschis.OnlyTrumpetSongs")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("com.github.ChuMenschis.OnlyTrumpetSongs")]
[assembly: AssemblyTitle("OnlyTrumpetSongs")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
[BepInPlugin("OnlyTrumpetSongs", "OnlyTrumpetSongs", "1.9.0")]
public class OnlyTrumpetSongs : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <LoadSongsCoroutine>d__18 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public OnlyTrumpetSongs <>4__this;
private string <soundPath>5__1;
private List<string> <files>5__2;
private string <globalSounds>5__3;
private List<string>.Enumerator <>s__4;
private string <file>5__5;
private UnityWebRequest <req>5__6;
private AudioClip <clip>5__7;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <LoadSongsCoroutine>d__18(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if ((uint)(num - -4) <= 1u || num == 1)
{
try
{
if (num == -4 || num == 1)
{
try
{
}
finally
{
<>m__Finally2();
}
}
}
finally
{
<>m__Finally1();
}
}
<soundPath>5__1 = null;
<files>5__2 = null;
<globalSounds>5__3 = null;
<>s__4 = default(List<string>.Enumerator);
<file>5__5 = null;
<req>5__6 = null;
<clip>5__7 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Invalid comparison between Unknown and I4
try
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<soundPath>5__1 = Path.Combine(<>4__this.pluginFolder, "Sounds");
if (!Directory.Exists(<soundPath>5__1))
{
<globalSounds>5__3 = Path.Combine(Paths.PluginPath, "Sounds");
if (Directory.Exists(<globalSounds>5__3))
{
<soundPath>5__1 = <globalSounds>5__3;
}
<globalSounds>5__3 = null;
}
if (!Directory.Exists(<soundPath>5__1))
{
Log.LogWarning((object)("Sounds folder not found: " + <soundPath>5__1));
return false;
}
<files>5__2 = Directory.GetFiles(<soundPath>5__1, "*.ogg").OrderBy(delegate(string f)
{
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(f);
string s = new string(fileNameWithoutExtension.TakeWhile(char.IsDigit).ToArray());
int result;
return int.TryParse(s, out result) ? result : int.MaxValue;
}).ThenBy<string, string>((string f) => f, StringComparer.OrdinalIgnoreCase)
.ToList();
<>s__4 = <files>5__2.GetEnumerator();
<>1__state = -3;
break;
case 1:
<>1__state = -4;
if ((int)<req>5__6.result != 1)
{
Log.LogError((object)("Failed to load '" + <file>5__5 + "': " + <req>5__6.error));
}
else
{
<clip>5__7 = DownloadHandlerAudioClip.GetContent(<req>5__6);
if (!((Object)(object)<clip>5__7 == (Object)null))
{
((Object)<clip>5__7).name = Path.GetFileNameWithoutExtension(<file>5__5);
CustomSongs.Add(<clip>5__7);
Log.LogInfo((object)("Loaded song: " + ((Object)<clip>5__7).name));
<clip>5__7 = null;
<>m__Finally2();
<req>5__6 = null;
<file>5__5 = null;
break;
}
Log.LogError((object)("Null clip for '" + <file>5__5 + "'"));
}
<>m__Finally2();
break;
}
if (<>s__4.MoveNext())
{
<file>5__5 = <>s__4.Current;
<req>5__6 = UnityWebRequestMultimedia.GetAudioClip("file://" + <file>5__5, (AudioType)14);
<>1__state = -4;
<>2__current = <req>5__6.SendWebRequest();
<>1__state = 1;
return true;
}
<>m__Finally1();
<>s__4 = default(List<string>.Enumerator);
IsInitialized = true;
Log.LogInfo((object)$"Loaded {CustomSongs.Count} custom songs.");
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;
((IDisposable)<>s__4).Dispose();
}
private void <>m__Finally2()
{
<>1__state = -3;
if (<req>5__6 != null)
{
((IDisposable)<req>5__6).Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
internal static ManualLogSource Log;
private Harmony harmony;
private string pluginFolder;
internal static readonly List<AudioClip> CustomSongs = new List<AudioClip>();
internal static bool IsInitialized = false;
internal static string CurrentSongName = "";
internal static float TitleStartTime = -999f;
private static Font customFont;
private static GUIStyle titleStyle;
public static ConfigEntry<int> cfgFontSize;
public static ConfigEntry<float> cfgFadeTime;
public static ConfigEntry<float> cfgVisibleTime;
public static ConfigEntry<string> cfgNextKey;
public static ConfigEntry<string> cfgPrevKey;
private void Awake()
{
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
pluginFolder = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
cfgFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("Display", "FontSize", 44, "Fontgröße des Song-Titels.");
cfgFadeTime = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "FadeTime", 0.5f, "Fade-in/out Dauer in Sekunden.");
cfgVisibleTime = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "VisibleTime", 3f, "Einblenddauer des Titels in Sekunden.");
cfgNextKey = ((BaseUnityPlugin)this).Config.Bind<string>("Controls", "NextSong", "MouseScrollUp", "Taste/Achse für nächster Song.");
cfgPrevKey = ((BaseUnityPlugin)this).Config.Bind<string>("Controls", "PrevSong", "MouseScrollDown", "Taste/Achse für vorheriger Song.");
harmony = new Harmony("OnlyTrumpetSongs");
harmony.PatchAll();
LoadFont();
((MonoBehaviour)this).StartCoroutine(LoadSongsCoroutine());
}
private void LoadFont()
{
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Expected O, but got Unknown
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Expected O, but got Unknown
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Expected O, but got Unknown
try
{
string text = Path.Combine(pluginFolder, "Fonts", "DarumadropOne-Regular.ttf");
if (!File.Exists(text))
{
string text2 = Path.Combine(Paths.PluginPath, "Fonts", "DarumadropOne-Regular.ttf");
if (File.Exists(text2))
{
text = text2;
}
}
if (File.Exists(text))
{
customFont = new Font(text);
Log.LogInfo((object)("Custom font loaded: " + text));
}
else
{
Log.LogWarning((object)"Custom font not found. Using default GUI font.");
}
GUIStyle val = new GUIStyle
{
font = (customFont ?? GUI.skin.label.font),
fontSize = cfgFontSize.Value
};
val.normal.textColor = Color.white;
val.alignment = (TextAnchor)7;
titleStyle = val;
}
catch (Exception ex)
{
Log.LogError((object)("Error loading font: " + ex));
GUIStyle val2 = new GUIStyle(GUI.skin.label)
{
fontSize = cfgFontSize.Value
};
val2.normal.textColor = Color.white;
val2.alignment = (TextAnchor)7;
titleStyle = val2;
}
}
private void OnGUI()
{
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: 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)
if (string.IsNullOrEmpty(CurrentSongName) || titleStyle == null)
{
return;
}
float num = Time.time - TitleStartTime;
if (!(num > cfgVisibleTime.Value))
{
if (titleStyle.fontSize != cfgFontSize.Value)
{
titleStyle.fontSize = cfgFontSize.Value;
}
float value = cfgFadeTime.Value;
float num2 = 1f;
if (num < value)
{
num2 = Mathf.Lerp(0f, 1f, num / value);
}
else if (num > cfgVisibleTime.Value - value)
{
num2 = Mathf.Lerp(1f, 0f, (num - (cfgVisibleTime.Value - value)) / value);
}
Color color = GUI.color;
GUI.color = new Color(1f, 1f, 1f, num2);
DrawOutline(new Rect(0f, (float)(Screen.height - 60), (float)Screen.width, 40f), CurrentSongName, titleStyle, Color.black, 2f);
GUI.color = color;
}
}
private void DrawOutline(Rect position, string text, GUIStyle style, Color outlineColor, float thickness)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
Color textColor = style.normal.textColor;
style.normal.textColor = outlineColor;
GUI.Label(new Rect(((Rect)(ref position)).x - thickness, ((Rect)(ref position)).y, ((Rect)(ref position)).width, ((Rect)(ref position)).height), text, style);
GUI.Label(new Rect(((Rect)(ref position)).x + thickness, ((Rect)(ref position)).y, ((Rect)(ref position)).width, ((Rect)(ref position)).height), text, style);
GUI.Label(new Rect(((Rect)(ref position)).x, ((Rect)(ref position)).y - thickness, ((Rect)(ref position)).width, ((Rect)(ref position)).height), text, style);
GUI.Label(new Rect(((Rect)(ref position)).x, ((Rect)(ref position)).y + thickness, ((Rect)(ref position)).width, ((Rect)(ref position)).height), text, style);
style.normal.textColor = textColor;
GUI.Label(position, text, style);
}
[IteratorStateMachine(typeof(<LoadSongsCoroutine>d__18))]
private IEnumerator LoadSongsCoroutine()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <LoadSongsCoroutine>d__18(0)
{
<>4__this = this
};
}
internal static bool CheckInput(string configValue)
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
if (string.Equals(configValue, "MouseScrollUp", StringComparison.OrdinalIgnoreCase))
{
return Input.GetAxis("Mouse ScrollWheel") > 0f;
}
if (string.Equals(configValue, "MouseScrollDown", StringComparison.OrdinalIgnoreCase))
{
return Input.GetAxis("Mouse ScrollWheel") < 0f;
}
try
{
return Input.GetKeyDown((KeyCode)Enum.Parse(typeof(KeyCode), configValue, ignoreCase: true));
}
catch
{
return false;
}
}
}
public class OnlyTrumpetSongsSync : MonoBehaviourPun
{
private BugleSFX bugle;
private int currentIndex = 0;
public void Init(BugleSFX sfx)
{
bugle = sfx;
if (OnlyTrumpetSongs.IsInitialized && OnlyTrumpetSongs.CustomSongs.Count > 0)
{
bugle.bugle = OnlyTrumpetSongs.CustomSongs.ToArray();
}
}
public void SendSetSongIndex(int newIndex)
{
if (Object.op_Implicit((Object)(object)((MonoBehaviourPun)this).photonView) && OnlyTrumpetSongs.IsInitialized && OnlyTrumpetSongs.CustomSongs.Count != 0)
{
newIndex = Mod(newIndex, OnlyTrumpetSongs.CustomSongs.Count);
AudioClip obj = OnlyTrumpetSongs.CustomSongs[newIndex];
string text = ((obj != null) ? ((Object)obj).name : null) ?? string.Empty;
((MonoBehaviourPun)this).photonView.RPC("RPC_SetSongByName", (RpcTarget)3, new object[1] { text });
}
}
[PunRPC]
private void RPC_SetSongByName(string songName)
{
string songName2 = songName;
if (!OnlyTrumpetSongs.IsInitialized || OnlyTrumpetSongs.CustomSongs.Count == 0)
{
return;
}
int num = OnlyTrumpetSongs.CustomSongs.FindIndex((AudioClip c) => (Object)(object)c != (Object)null && string.Equals(((Object)c).name, songName2, StringComparison.OrdinalIgnoreCase));
if (num < 0)
{
num = 0;
}
currentIndex = num;
if (bugle.bugle == null || bugle.bugle.Length == 0)
{
bugle.bugle = OnlyTrumpetSongs.CustomSongs.ToArray();
}
AudioClip val = OnlyTrumpetSongs.CustomSongs[currentIndex];
bugle.buglePlayer.clip = val;
bugle.buglePlayer.pitch = 1f;
bugle.buglePlayer.loop = true;
if (bugle.hold)
{
if (!bugle.buglePlayer.isPlaying)
{
bugle.buglePlayer.Play();
}
OnlyTrumpetSongs.CurrentSongName = ((Object)val).name;
OnlyTrumpetSongs.TitleStartTime = Time.time;
}
else if (bugle.buglePlayer.isPlaying)
{
bugle.buglePlayer.Stop();
}
}
public int GetCurrentIndex()
{
return currentIndex;
}
private static int Mod(int x, int m)
{
return (x % m + m) % m;
}
}
[HarmonyPatch(typeof(BugleSFX), "Start")]
internal class Patch_Bugle_Start
{
private static void Postfix(BugleSFX __instance)
{
OnlyTrumpetSongsSync onlyTrumpetSongsSync = ((Component)__instance).gameObject.GetComponent<OnlyTrumpetSongsSync>();
if ((Object)(object)onlyTrumpetSongsSync == (Object)null)
{
onlyTrumpetSongsSync = ((Component)__instance).gameObject.AddComponent<OnlyTrumpetSongsSync>();
}
onlyTrumpetSongsSync.Init(__instance);
if (OnlyTrumpetSongs.IsInitialized && OnlyTrumpetSongs.CustomSongs.Count > 0)
{
__instance.bugle = OnlyTrumpetSongs.CustomSongs.ToArray();
__instance.buglePlayer.clip = OnlyTrumpetSongs.CustomSongs[0];
__instance.buglePlayer.loop = true;
__instance.buglePlayer.pitch = 1f;
__instance.buglePlayer.Stop();
}
__instance.pitchMin = 1f;
__instance.pitchMax = 1f;
PhotonView component = ((Component)__instance).GetComponent<PhotonView>();
if ((Object)(object)component != (Object)null && component.IsMine)
{
onlyTrumpetSongsSync.SendSetSongIndex(0);
}
}
}
[HarmonyPatch(typeof(BugleSFX), "Update")]
internal class Patch_Bugle_Update
{
private static void Prefix(BugleSFX __instance)
{
if (!OnlyTrumpetSongs.IsInitialized || OnlyTrumpetSongs.CustomSongs.Count == 0)
{
return;
}
PhotonView component = ((Component)__instance).GetComponent<PhotonView>();
if ((Object)(object)component == (Object)null || !component.IsMine || !__instance.hold)
{
return;
}
OnlyTrumpetSongsSync component2 = ((Component)__instance).GetComponent<OnlyTrumpetSongsSync>();
if ((Object)(object)component2 == (Object)null)
{
return;
}
bool flag = OnlyTrumpetSongs.CheckInput(OnlyTrumpetSongs.cfgNextKey.Value);
bool flag2 = OnlyTrumpetSongs.CheckInput(OnlyTrumpetSongs.cfgPrevKey.Value);
if (flag || flag2)
{
int num = (flag ? 1 : (-1));
int newIndex = component2.GetCurrentIndex() + num;
component2.SendSetSongIndex(newIndex);
}
if (__instance.hold)
{
if (!__instance.buglePlayer.isPlaying && (Object)(object)__instance.buglePlayer.clip != (Object)null)
{
__instance.buglePlayer.Play();
}
}
else if (__instance.buglePlayer.isPlaying)
{
__instance.buglePlayer.Stop();
}
}
}
[HarmonyPatch(typeof(BugleSFX), "RPC_StartToot")]
internal class Patch_Bugle_RPC_StartToot
{
private static void Prefix(BugleSFX __instance, ref int clip)
{
OnlyTrumpetSongsSync component = ((Component)__instance).GetComponent<OnlyTrumpetSongsSync>();
if (!((Object)(object)component == (Object)null) && OnlyTrumpetSongs.IsInitialized && OnlyTrumpetSongs.CustomSongs.Count > 0)
{
int currentIndex = component.GetCurrentIndex();
if (currentIndex >= 0 && currentIndex < OnlyTrumpetSongs.CustomSongs.Count)
{
clip = currentIndex;
}
}
}
}
namespace BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}