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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using ShopUtils;
using ShopUtils.Language;
using ShopUtils.Network;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Networking;
using Zorro.Core.Serizalization;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Boombox")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Boombox")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3e7899cc-ef30-4c2d-a1da-62d9206dc4c2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Boombox;
public class BoomboxBehaviour : ItemInstanceBehaviour
{
public static List<AudioClip> clips = new List<AudioClip>();
private BatteryEntry batteryEntry;
private OnOffEntry onOffEntry;
private TimeEntry timeEntry;
private VolumeEntry volumeEntry;
private MusicEntry musicEntry;
private SFX_PlayOneShot Click;
private AudioSource Music;
private int currentIndex;
private void Awake()
{
Click = ((Component)((Component)this).transform.Find("SFX/Click")).GetComponent<SFX_PlayOneShot>();
Music = ((Component)this).GetComponent<AudioSource>();
}
public override void ConfigItem(ItemInstanceData data, PhotonView playerView)
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Expected O, but got Unknown
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Expected O, but got Unknown
if (!Boombox.InfiniteBattery && !data.TryGetEntry<BatteryEntry>(ref batteryEntry))
{
batteryEntry = new BatteryEntry
{
m_charge = Boombox.BatteryCapacity,
m_maxCharge = Boombox.BatteryCapacity
};
data.AddDataEntry((ItemDataEntry)(object)batteryEntry);
}
if (!data.TryGetEntry<OnOffEntry>(ref onOffEntry))
{
onOffEntry = new OnOffEntry
{
on = false
};
data.AddDataEntry((ItemDataEntry)(object)onOffEntry);
}
if (!data.TryGetEntry<TimeEntry>(ref timeEntry))
{
timeEntry = new TimeEntry
{
currentTime = 0f
};
data.AddDataEntry((ItemDataEntry)(object)timeEntry);
}
if (!data.TryGetEntry<MusicEntry>(ref musicEntry))
{
musicEntry = new MusicEntry
{
selectMusicIndex = 0
};
data.AddDataEntry((ItemDataEntry)(object)musicEntry);
}
if (!data.TryGetEntry<VolumeEntry>(ref volumeEntry))
{
volumeEntry = new VolumeEntry
{
volume = 5
};
data.AddDataEntry((ItemDataEntry)(object)volumeEntry);
}
musicEntry.UpdateMusicName();
}
private void Update()
{
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_0153: Unknown result type (might be due to invalid IL or missing references)
if (base.isHeldByMe && !Player.localPlayer.HasLockedInput())
{
if (Player.localPlayer.input.clickWasPressed)
{
if (clips.Count == 0)
{
HelmetText.Instance.SetHelmetText("No Music", 2f);
}
else
{
onOffEntry.on = !onOffEntry.on;
((ItemDataEntry)onOffEntry).SetDirty();
}
Click.Play();
}
if (Player.localPlayer.input.aimWasPressed)
{
if (clips.Count > 0)
{
musicEntry.selectMusicIndex++;
musicEntry.selectMusicIndex %= clips.Count;
musicEntry.UpdateMusicName();
((ItemDataEntry)musicEntry).SetDirty();
timeEntry.currentTime = 0f;
((ItemDataEntry)timeEntry).SetDirty();
}
Click.Play();
}
if (GlobalInputHandler.GetKeyUp(Boombox.VolumeUpKey.Value))
{
if (volumeEntry.volume <= 9)
{
volumeEntry.volume++;
((ItemDataEntry)volumeEntry).SetDirty();
}
Click.Play();
}
if (GlobalInputHandler.GetKeyUp(Boombox.VolumeDownKey.Value))
{
if (volumeEntry.volume >= 1)
{
volumeEntry.volume--;
((ItemDataEntry)volumeEntry).SetDirty();
}
Click.Play();
}
}
if (!Boombox.InfiniteBattery && batteryEntry.m_charge < 0f)
{
onOffEntry.on = false;
}
if (volumeEntry.GetVolume() != Music.volume)
{
Music.volume = volumeEntry.GetVolume();
}
bool on = onOffEntry.on;
if (on != Music.isPlaying || currentIndex != musicEntry.selectMusicIndex)
{
currentIndex = musicEntry.selectMusicIndex;
if (on)
{
if (checkMusic(musicEntry.selectMusicIndex))
{
Music.clip = clips[musicEntry.selectMusicIndex];
Music.time = timeEntry.currentTime;
Music.Play();
}
}
else
{
Music.Stop();
}
}
if (on)
{
if (!Boombox.InfiniteBattery)
{
BatteryEntry obj = batteryEntry;
obj.m_charge -= Time.deltaTime;
}
timeEntry.currentTime = Music.time;
}
}
public static bool checkMusic(int index)
{
return index <= clips.Count - 1;
}
}
public class VolumeEntry : ItemDataEntry, IHaveUIData
{
public int volume;
public int max_volume = 10;
private string VolumeLanguage = "{0}% Volume";
public VolumeEntry()
{
Languages.TryGetLanguage("BoomboxVolume", ref VolumeLanguage);
}
public override void Deserialize(BinaryDeserializer binaryDeserializer)
{
volume = binaryDeserializer.ReadInt();
}
public override void Serialize(BinarySerializer binarySerializer)
{
binarySerializer.WriteInt(volume);
}
public float GetVolume()
{
return (float)volume / 10f;
}
public string GetString()
{
return string.Format(VolumeLanguage, volume * 10);
}
}
public class MusicEntry : ItemDataEntry, IHaveUIData
{
private string MusicName;
public int selectMusicIndex;
public override void Deserialize(BinaryDeserializer binaryDeserializer)
{
selectMusicIndex = binaryDeserializer.ReadInt();
}
public override void Serialize(BinarySerializer binarySerializer)
{
binarySerializer.WriteInt(selectMusicIndex);
}
public void UpdateMusicName()
{
MusicName = string.Empty;
if (BoomboxBehaviour.clips.Count > 0 && BoomboxBehaviour.checkMusic(selectMusicIndex))
{
MusicName = getMusicName(((Object)BoomboxBehaviour.clips[selectMusicIndex]).name);
}
}
public string GetString()
{
return MusicName;
}
private string getMusicName(string name)
{
int length;
if ((length = name.LastIndexOf('.')) != -1)
{
name = name.Substring(0, length);
}
if (name.Length > 15)
{
name = name.Substring(0, 15);
name += "...";
}
return name;
}
}
public class MusicLoadManager : MonoBehaviour
{
private static MusicLoadManager instance;
public static Coroutine StartCoroutine(IEnumerator enumerator)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)instance == (Object)null)
{
instance = new GameObject("MusicLoader").AddComponent<MusicLoadManager>();
Object.DontDestroyOnLoad((Object)(object)instance);
}
return ((MonoBehaviour)instance).StartCoroutine(enumerator);
}
public static void StartLoadMusic()
{
StartCoroutine(LoadMusic());
}
private static IEnumerator LoadMusic()
{
string path = Path.Combine(Paths.PluginPath, "Custom Songs");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
string[] files = Directory.GetFiles(path);
foreach (string file in files)
{
AudioType audioType = GetAudioType(file);
if ((int)audioType == 0)
{
continue;
}
UnityWebRequest loader = UnityWebRequestMultimedia.GetAudioClip(file, audioType);
DownloadHandlerAudioClip val = (DownloadHandlerAudioClip)loader.downloadHandler;
val.streamAudio = false;
loader.SendWebRequest();
yield return (object)new WaitUntil((Func<bool>)(() => loader.isDone));
if (loader.error == null)
{
AudioClip content = DownloadHandlerAudioClip.GetContent(loader);
if (Object.op_Implicit((Object)(object)content) && (int)content.loadState == 2)
{
((Object)content).name = Path.GetFileName(file);
BoomboxBehaviour.clips.Add(content);
Boombox.log.LogInfo((object)("Music Loaded: " + ((Object)content).name));
}
}
}
}
private static AudioType GetAudioType(string path)
{
return (AudioType)(Path.GetExtension(path).ToLower() switch
{
".wav" => 20,
".ogg" => 14,
".mp3" => 13,
_ => 0,
});
}
}
[BepInPlugin("hyydsz-Boombox", "Boombox", "1.1.5")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Boombox : BaseUnityPlugin
{
public static ManualLogSource log;
public const string ModGUID = "hyydsz-Boombox";
public const string ModName = "Boombox";
public const string ModVersion = "1.1.5";
private readonly Harmony harmony = new Harmony("hyydsz-Boombox");
public static AssetBundle asset;
public static bool InfiniteBattery = false;
public static float BatteryCapacity = 250f;
public static ConfigEntry<KeyCode> VolumeUpKey;
public static ConfigEntry<KeyCode> VolumeDownKey;
private void Awake()
{
LoadConfig();
LoadBoombox();
LoadLangauge();
harmony.PatchAll();
}
private void Start()
{
MusicLoadManager.StartLoadMusic();
}
private void LoadConfig()
{
VolumeUpKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Config", "VolumeUp", (KeyCode)61, (ConfigDescription)null);
VolumeDownKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Config", "VolumeDown", (KeyCode)45, (ConfigDescription)null);
log = ((BaseUnityPlugin)this).Logger;
Networks.SetNetworkSync(new Dictionary<string, object>
{
{
"BoomboxInfiniteBattery",
((BaseUnityPlugin)this).Config.Bind<bool>("Config", "InfiniteBattery", false, (ConfigDescription)null).Value
},
{
"BoomboxBattery",
((BaseUnityPlugin)this).Config.Bind<float>("Config", "BatteryCapacity", 250f, (ConfigDescription)null).Value
}
}, (Action<Dictionary<string, string>>)delegate(Dictionary<string, string> dic)
{
InfiniteBattery = bool.Parse(dic["BoomboxInfiniteBattery"]);
BatteryCapacity = float.Parse(dic["BoomboxBattery"]);
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Boombox Load [InfiniteBattery: {InfiniteBattery}, BatteryCapacity: {BatteryCapacity}]");
});
}
private void LoadBoombox()
{
asset = QuickLoadAssetBundle("boombox");
Item val = asset.LoadAsset<Item>("Boombox");
val.itemObject.AddComponent<BoomboxBehaviour>();
Entries.RegisterAll();
Items.RegisterShopItem(val, (ShopItemCategory)7, ((BaseUnityPlugin)this).Config.Bind<int>("Config", "BoomboxPrice", 100, (ConfigDescription)null).Value);
Networks.RegisterItemPrice(val);
}
private void LoadLangauge()
{
Locale language = Languages.GetLanguage((LanguageEnum)0);
Languages.AddLanguage(language, "Boombox_ToolTips", "[LMB] 播放;[RMB] 切换音乐");
Languages.AddLanguage(language, "Boombox", "音响");
Languages.AddLanguage(language, "BoomboxVolume", "{0}% 音量");
Locale language2 = Languages.GetLanguage((LanguageEnum)1);
Languages.AddLanguage(language2, "Boombox_ToolTips", "[LMB] 播放;[RMB] 切換音樂");
Languages.AddLanguage(language2, "Boombox", "音響");
Languages.AddLanguage(language2, "BoomboxVolume", "{0}% 音量");
Locale language3 = Languages.GetLanguage((LanguageEnum)2);
Languages.AddLanguage(language3, "Boombox_ToolTips", "[LMB] Player;[RMB] Switch Music");
Languages.AddLanguage(language3, "Boombox", "Boombox");
Languages.AddLanguage(language3, "BoomboxVolume", "{0}% Volume");
Locale language4 = Languages.GetLanguage((LanguageEnum)3);
Languages.AddLanguage(language4, "Boombox_ToolTips", "[LMB] Jouer de la musique;[RMB] Changer de musique");
Languages.AddLanguage(language4, "Boombox", "Audio portable");
Languages.AddLanguage(language4, "BoomboxVolume", "{0}% Volume");
Locale language5 = Languages.GetLanguage((LanguageEnum)4);
Languages.AddLanguage(language5, "Boombox_ToolTips", "[LMB] Musik abspielen;[RMB] Musik wechseln");
Languages.AddLanguage(language5, "Boombox", "Boom Box");
Languages.AddLanguage(language5, "BoomboxVolume", "{0}% Volume");
Locale language6 = Languages.GetLanguage((LanguageEnum)5);
Languages.AddLanguage(language6, "Boombox_ToolTips", "[LMB] Riproduci musica;[RMB] Cambia musica");
Languages.AddLanguage(language6, "Boombox", "boom box");
Languages.AddLanguage(language6, "BoomboxVolume", "{0}% volume");
Locale language7 = Languages.GetLanguage((LanguageEnum)6);
Languages.AddLanguage(language7, "Boombox_ToolTips", "[LMB] 音楽を流す;[RMB] 音楽を切り替える");
Languages.AddLanguage(language7, "Boombox", "ポータブルオーディオ");
Languages.AddLanguage(language7, "BoomboxVolume", "{0}% 音量");
Locale language8 = Languages.GetLanguage((LanguageEnum)7);
Languages.AddLanguage(language8, "Boombox_ToolTips", "[LMB] Tocar música;[RMB] Mudar a Música");
Languages.AddLanguage(language8, "Boombox", "Sistema de áudio portátil");
Languages.AddLanguage(language8, "BoomboxVolume", "{0}% volume");
Locale language9 = Languages.GetLanguage((LanguageEnum)8);
Languages.AddLanguage(language9, "Boombox_ToolTips", "[LMB] Музыка;[RMB] Переключить музыку");
Languages.AddLanguage(language9, "Boombox", "Портативный звук");
Languages.AddLanguage(language9, "BoomboxVolume", "{0}% Громкость");
Locale language10 = Languages.GetLanguage((LanguageEnum)9);
Languages.AddLanguage(language10, "Boombox_ToolTips", "[LMB] Reproducir música;[RMB] Cambiar música");
Languages.AddLanguage(language10, "Boombox", "Traductor portátil");
Languages.AddLanguage(language10, "BoomboxVolume", "{0}% Volumen");
Locale language11 = Languages.GetLanguage((LanguageEnum)10);
Languages.AddLanguage(language11, "Boombox_ToolTips", "[LMB] Грати музику;[RMB] Перемкнути музику");
Languages.AddLanguage(language11, "Boombox", "Портувана аудіосистема");
Languages.AddLanguage(language11, "BoomboxVolume", "{0}% гучність");
Locale language12 = Languages.GetLanguage((LanguageEnum)11);
Languages.AddLanguage(language12, "Boombox_ToolTips", "[LMB] 음악 재생;[RMB] 음악 전환");
Languages.AddLanguage(language12, "Boombox", "휴대용 오디오");
Languages.AddLanguage(language12, "BoomboxVolume", "{0}% 볼륨");
Locale language13 = Languages.GetLanguage((LanguageEnum)12);
Languages.AddLanguage(language13, "Boombox_ToolTips", "[LMB] Spela musik;[RMB] Byt musik");
Languages.AddLanguage(language13, "Boombox", "Bärbart ljudsystem");
Languages.AddLanguage(language13, "BoomboxVolume", "{0}% volym");
}
public static AssetBundle QuickLoadAssetBundle(string name)
{
string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), name);
return AssetBundle.LoadFromFile(text);
}
}