using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using MilkshakeMod.Patches;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MilkshakeMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MilkshakeMod")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("fdbfbc33-d43c-4a65-92aa-de1421026a1b")]
[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 MilkshakeMod
{
[BepInPlugin("MilkshakeMod", "MilkshakeMod", "1.1.0")]
public class MilkshakeMod : BaseUnityPlugin
{
private const string modGUID = "MilkshakeMod";
private const string modName = "MilkshakeMod";
private const string modVersion = "1.1.0";
private const string assetBundleName = "milkshakemod";
private string FolderLocation;
private readonly Harmony harmony = new Harmony("MilkshakeMod");
internal static MilkshakeMod Instance;
internal static ManualLogSource ManualLogSource;
internal static List<AudioClip> AudioClips;
private static AssetBundle Bundle;
internal static readonly Dictionary<string, int> AudioClipNameAssetBundleIndex = new Dictionary<string, int>();
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
if (FolderLocation == null)
{
FolderLocation = ((BaseUnityPlugin)Instance).Info.Location.TrimEnd((((object)this).GetType().Name + ".dll").ToCharArray());
}
if (ManualLogSource == null)
{
ManualLogSource = Logger.CreateLogSource("MilkshakeMod");
}
Bundle = AssetBundle.LoadFromFile(FolderLocation + "milkshakemod");
if ((Object)(object)Bundle != (Object)null)
{
AudioClips = Bundle.LoadAllAssets<AudioClip>().ToList();
int num = 0;
foreach (AudioClip audioClip in AudioClips)
{
AudioClipNameAssetBundleIndex.Add(((Object)audioClip).name, num);
num++;
}
}
else
{
AudioClips = new List<AudioClip>();
ManualLogSource.LogError((object)"Failed to load asset bundle 'milkshakemod");
}
harmony.PatchAll(typeof(MilkshakeModPatch));
}
}
}
namespace MilkshakeMod.Patches
{
[HarmonyPatch(typeof(AudioSource), new Type[] { })]
internal class MilkshakeModPatch
{
[HarmonyPatch(typeof(ItemDropship), "__initializeVariables")]
[HarmonyPrefix]
private static void PatchItemDropship(ItemDropship __instance)
{
Transform val = ((Component)__instance).transform.Find("Music");
if (Object.op_Implicit((Object)(object)val))
{
ReplaceClip(((Component)val).GetComponent<AudioSource>());
Transform val2 = val.Find("Music (1)");
if (Object.op_Implicit((Object)(object)val2))
{
ReplaceClip(((Component)val2).GetComponent<AudioSource>());
}
}
}
private static void ReplaceClip(AudioSource audioSource)
{
string name = ((Object)audioSource.clip).name;
if (MilkshakeMod.AudioClipNameAssetBundleIndex.ContainsKey(name))
{
int num = MilkshakeMod.AudioClipNameAssetBundleIndex[name];
AudioClip val = MilkshakeMod.AudioClips[num];
((Object)val).name = $"MilkshakeMod-{name}-{num}";
audioSource.clip = val;
}
}
}
}