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 HeavyDSong;
using MelonLoader;
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: MelonInfo(typeof(Core), "HeavyDSong", "1.0.0", "Kuromi", null)]
[assembly: MelonGame("ReLUGames", "MIMESIS")]
[assembly: AssemblyTitle("ElefanSongSwap")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ElefanSongSwap")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a991d5c1-9066-484b-a9a5-7605f9cc8293")]
[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")]
namespace HeavyDSong;
public class Core : MelonMod
{
private const string TargetClipPrefix = "Sound_Monster_HeavyD_BoomBox_Beat";
private readonly List<AudioClip> songs = new List<AudioClip>();
private float timer;
public override void OnInitializeMelon()
{
string fullPath = Path.GetFullPath(Path.Combine(Application.dataPath, "../UserData/HeavyDSong"));
Directory.CreateDirectory(fullPath);
MelonCoroutines.Start(LoadSongs(fullPath));
}
private IEnumerator LoadSongs(string dir)
{
string[] files = Directory.GetFiles(dir);
foreach (string file in files)
{
AudioType type;
switch (Path.GetExtension(file).ToLowerInvariant())
{
case ".ogg":
type = (AudioType)14;
break;
case ".wav":
type = (AudioType)20;
break;
case ".mp3":
type = (AudioType)13;
break;
default:
continue;
}
UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip("file:///" + file.Replace('\\', '/'), type);
try
{
yield return req.SendWebRequest();
if ((int)req.result != 1)
{
((MelonBase)this).LoggerInstance.Warning("Cannot load " + Path.GetFileName(file) + ": " + req.error);
continue;
}
AudioClip clip = DownloadHandlerAudioClip.GetContent(req);
((Object)clip).name = Path.GetFileName(file);
songs.Add(clip);
}
finally
{
((IDisposable)req)?.Dispose();
}
}
if (songs.Count == 0)
{
((MelonBase)this).LoggerInstance.Warning("No songs found in " + dir);
}
else
{
((MelonBase)this).LoggerInstance.Msg("Loaded " + songs.Count + " song(s)");
}
}
public override void OnUpdate()
{
if (songs.Count == 0)
{
return;
}
timer += Time.unscaledDeltaTime;
if (timer < 0.3f)
{
return;
}
timer = 0f;
AudioSource[] array = Object.FindObjectsByType<AudioSource>((FindObjectsSortMode)0);
foreach (AudioSource val in array)
{
if (!((Object)(object)val == (Object)null) && val.isPlaying && !((Object)(object)val.clip == (Object)null) && ((Object)val.clip).name.StartsWith("Sound_Monster_HeavyD_BoomBox_Beat"))
{
val.clip = songs[Random.Range(0, songs.Count)];
val.Play();
}
}
}
}