using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using SortedBoomboxMusic.Patches;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BetterBoombox")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterBoombox")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9b736192-1a97-4922-b7b1-41576fd98695")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SortedBoomboxMusic
{
[BepInPlugin("r4dulf.SortedBoomboxMusic", "SortedBoomboxMusic", "0.0.1")]
public class SortedBoomboxMusic : BaseUnityPlugin
{
private const string modGUID = "r4dulf.SortedBoomboxMusic";
private const string modName = "SortedBoomboxMusic";
private const string modVersion = "0.0.1";
private readonly Harmony harmony = new Harmony("r4dulf.SortedBoomboxMusic");
private static SortedBoomboxMusic Instance;
internal ManualLogSource mls;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("r4dulf.SortedBoomboxMusic");
harmony.PatchAll(typeof(SortedBoomboxMusic));
harmony.PatchAll(typeof(BoomboxItemPatch));
mls.LogInfo((object)"BetterBoombox loaded!");
}
}
}
namespace SortedBoomboxMusic.Patches
{
[HarmonyPatch(typeof(BoomboxItem))]
internal class BoomboxItemPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void PatchRandomizer(ref Random ___musicRandomizer)
{
___musicRandomizer = new MusicSorter();
}
}
internal class MusicSorter : Random
{
public enum MusicSorterMode
{
Random,
Sequential,
Repeat
}
private int index = -1;
private MusicSorterMode mode = MusicSorterMode.Sequential;
public int CurrentIndex
{
get
{
return index;
}
set
{
index = Math.Max(0, value);
}
}
public MusicSorterMode CurrentMode
{
get
{
return mode;
}
set
{
mode = value;
}
}
public override int Next(int min, int max)
{
if (CurrentMode == MusicSorterMode.Sequential)
{
return CurrentIndex = Math.Max(0, (CurrentIndex + 1 < max) ? (CurrentIndex + 1) : 0);
}
if (CurrentMode == MusicSorterMode.Repeat)
{
return CurrentIndex;
}
return base.Next(min, max);
}
public void SetNextMode()
{
if (CurrentMode == MusicSorterMode.Sequential)
{
CurrentMode = MusicSorterMode.Random;
}
else if (CurrentMode == MusicSorterMode.Random)
{
CurrentMode = MusicSorterMode.Repeat;
}
else if (CurrentMode == MusicSorterMode.Repeat)
{
CurrentMode = MusicSorterMode.Sequential;
}
}
}
}