Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of CustomizeMusic v1.0.0
BepInEx\plugins\HJM-CustomizeMusic\HJM.HachimiMusic.REPO.dll
Decompiled 2 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using ExitGames.Client.Photon; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using Photon.Realtime; using REPOLib.Modules; using TMPro; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("HJM.HachimiMusic.REPO")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("HJM.HachimiMusic.REPO")] [assembly: AssemblyTitle("HJM.HachimiMusic.REPO")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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; } } } namespace HJM.HachimiMusic.REPO { public static class BoomboxHud { private static readonly Color SleepyLavenderColor = new Color(0.82f, 0.68f, 1f, 1f); private static readonly Color InfinityAquaColor = new Color(1f / 3f, 1f, 1f, 1f); private static TextMeshProUGUI songText; private static TextMeshProUGUI lyricText; private static RectTransform lyricMaskRect; private static TextMeshProUGUI lyricHighlightText; private static TextMeshProUGUI volumeText; private static Transform lastEnergyParent; private static string cachedLyricForWidth; private static float cachedLyricWidth; private static string volumeMessage; private static float volumeUntil; public static void ShowVolume(int percent) { volumeMessage = $"音量: {percent}%"; volumeUntil = Time.unscaledTime + 3f; } public static void UpdateHud() { //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)EnergyUI.instance == (Object)null) { return; } EnsureTexts(); if ((Object)(object)songText == (Object)null || (Object)(object)lyricText == (Object)null || (Object)(object)volumeText == (Object)null) { return; } UpdatePositions(); HachimiBoombox hachimiBoombox = FindLocalRelevantBoombox(); if ((Object)(object)hachimiBoombox != (Object)null) { if (hachimiBoombox.IsPlaying && !string.IsNullOrEmpty(hachimiBoombox.CurrentTrackTitle)) { ((Component)songText).gameObject.SetActive(true); ((Graphic)songText).color = new Color(1f, 0.92f, 0.45f, 1f); ((TMP_Text)songText).text = "正在播放: " + hachimiBoombox.CurrentTrackTitle; if (hachimiBoombox.TryGetCurrentLyric(out var text, out var progress)) { ((Component)lyricText).gameObject.SetActive(true); ((TMP_Text)lyricText).text = text; bool flag = hachimiBoombox.CategoryKey == "困の音箱" || hachimiBoombox.CategoryKey == "infinity音箱"; if ((Object)(object)lyricMaskRect != (Object)null && (Object)(object)lyricHighlightText != (Object)null) { if (flag) { ((Component)lyricMaskRect).gameObject.SetActive(true); ((Graphic)lyricHighlightText).color = ((hachimiBoombox.CategoryKey == "infinity音箱") ? InfinityAquaColor : SleepyLavenderColor); ((TMP_Text)lyricHighlightText).text = text; if (cachedLyricForWidth != text) { cachedLyricForWidth = text; cachedLyricWidth = Mathf.Max(0f, ((TMP_Text)lyricText).GetPreferredValues(text).x + 2f); } float num = cachedLyricWidth * Mathf.Clamp01(progress); lyricMaskRect.sizeDelta = new Vector2(num, 64f); } else { ((Component)lyricMaskRect).gameObject.SetActive(false); } } } else { ((Component)lyricText).gameObject.SetActive(false); if ((Object)(object)lyricMaskRect != (Object)null) { ((Component)lyricMaskRect).gameObject.SetActive(false); } } } else { ((Component)songText).gameObject.SetActive(true); ((Graphic)songText).color = hachimiBoombox.AccentColor; ((TMP_Text)songText).text = "音响: " + hachimiBoombox.DisplayName; ((Component)lyricText).gameObject.SetActive(false); } } else { ((Component)songText).gameObject.SetActive(false); ((Component)lyricText).gameObject.SetActive(false); } if (!string.IsNullOrEmpty(volumeMessage) && Time.unscaledTime <= volumeUntil) { ((Component)volumeText).gameObject.SetActive(true); ((TMP_Text)volumeText).text = volumeMessage; } else { ((Component)volumeText).gameObject.SetActive(false); } } private static HachimiBoombox FindLocalRelevantBoombox() { foreach (HachimiBoombox activeBoombox in HachimiBoombox.ActiveBoomboxes) { if ((Object)(object)activeBoombox != (Object)null && activeBoombox.IsPlaying && activeBoombox.IsLocalRelevant()) { return activeBoombox; } } foreach (HachimiBoombox activeBoombox2 in HachimiBoombox.ActiveBoomboxes) { if ((Object)(object)activeBoombox2 != (Object)null && activeBoombox2.IsLocalRelevant()) { return activeBoombox2; } } return null; } private static void EnsureTexts() { //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) Transform parent = ((Component)EnergyUI.instance).transform.parent; if (!((Object)(object)parent == (Object)null) && (!((Object)(object)songText != (Object)null) || !((Object)(object)lyricText != (Object)null) || !((Object)(object)volumeText != (Object)null) || !((Object)(object)lastEnergyParent == (Object)(object)parent))) { lastEnergyParent = parent; TextMeshProUGUI component = ((Component)EnergyUI.instance).GetComponent<TextMeshProUGUI>(); if (!((Object)(object)component == (Object)null)) { songText = CreateHudLine("HachimiSongHUD", parent, component, 13f, new Color(1f, 0.92f, 0.45f, 1f)); lyricText = CreateHudLine("HachimiLyricHUD", parent, component, 12f, new Color(0.95f, 0.96f, 1f, 0.72f)); CreateLyricHighlightOverlay(lyricText, component, 12f); volumeText = CreateHudLine("HachimiVolumeHUD", parent, component, 11.5f, new Color(0.85f, 0.95f, 1f, 1f)); UpdatePositions(); } } } private static void CreateLyricHighlightOverlay(TextMeshProUGUI baseLyric, TextMeshProUGUI template, float fontSize) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: 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_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("HachimiLyricMask", new Type[2] { typeof(RectTransform), typeof(RectMask2D) }); val.transform.SetParent((Transform)(object)((TMP_Text)baseLyric).rectTransform, false); lyricMaskRect = val.GetComponent<RectTransform>(); lyricMaskRect.anchorMin = new Vector2(0f, 1f); lyricMaskRect.anchorMax = new Vector2(0f, 1f); lyricMaskRect.pivot = new Vector2(0f, 1f); lyricMaskRect.anchoredPosition = Vector2.zero; lyricMaskRect.sizeDelta = new Vector2(0f, 64f); ((Transform)lyricMaskRect).localScale = Vector3.one; GameObject val2 = new GameObject("HachimiLyricHighlight", new Type[1] { typeof(RectTransform) }); val2.transform.SetParent((Transform)(object)lyricMaskRect, false); lyricHighlightText = val2.AddComponent<TextMeshProUGUI>(); ((TMP_Text)lyricHighlightText).font = ((TMP_Text)template).font; ((TMP_Text)lyricHighlightText).fontSharedMaterial = ((TMP_Text)template).fontSharedMaterial; ((TMP_Text)lyricHighlightText).fontSize = fontSize; ((TMP_Text)lyricHighlightText).fontStyle = (FontStyles)1; ((Graphic)lyricHighlightText).color = SleepyLavenderColor; ((TMP_Text)lyricHighlightText).alignment = (TextAlignmentOptions)257; ((TMP_Text)lyricHighlightText).textWrappingMode = (TextWrappingModes)0; ((TMP_Text)lyricHighlightText).overflowMode = (TextOverflowModes)0; ((Graphic)lyricHighlightText).raycastTarget = false; RectTransform rectTransform = ((TMP_Text)lyricHighlightText).rectTransform; rectTransform.anchorMin = new Vector2(0f, 1f); rectTransform.anchorMax = new Vector2(0f, 1f); rectTransform.pivot = new Vector2(0f, 1f); rectTransform.anchoredPosition = Vector2.zero; rectTransform.sizeDelta = new Vector2(560f, 64f); ((Transform)rectTransform).localScale = Vector3.one; val.SetActive(false); } private static void UpdatePositions() { //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)songText == (Object)null || (Object)(object)lyricText == (Object)null || (Object)(object)volumeText == (Object)null || (Object)(object)EnergyUI.instance == (Object)null) { return; } TextMeshProUGUI component = ((Component)EnergyUI.instance).GetComponent<TextMeshProUGUI>(); Canvas componentInParent = ((Component)EnergyUI.instance).GetComponentInParent<Canvas>(); Canvas val = ((componentInParent != null) ? componentInParent.rootCanvas : null); if (!((Object)(object)component == (Object)null) && !((Object)(object)val == (Object)null)) { RectTransform component2 = ((Component)val).GetComponent<RectTransform>(); if (!((Object)(object)component2 == (Object)null)) { Vector3[] array = (Vector3[])(object)new Vector3[4]; component2.GetWorldCorners(array); float x = array[0].x; float num = array[3].x - array[0].x; float num2 = x + num * 0.015f; Vector3[] array2 = (Vector3[])(object)new Vector3[4]; ((TMP_Text)component).rectTransform.GetWorldCorners(array2); float x2 = array2[0].x; float y = array2[0].y; float num3 = array2[1].y - array2[0].y; float z = ((TMP_Text)component).transform.position.z; float num4 = Mathf.Max(num2, x2 - num3 * 1.05f); ((Transform)((TMP_Text)songText).rectTransform).position = new Vector3(num4, y - num3 * 0.06f, z); ((Transform)((TMP_Text)lyricText).rectTransform).position = new Vector3(num4, y - num3 * 0.6f, z); float num5 = (((Component)lyricText).gameObject.activeSelf ? 1.14f : 0.62f); ((Transform)((TMP_Text)volumeText).rectTransform).position = new Vector3(num4, y - num3 * num5, z); } } } private static TextMeshProUGUI CreateHudLine(string name, Transform parent, TextMeshProUGUI template, float fontSize, Color color) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) }); val.transform.SetParent(parent, false); TextMeshProUGUI obj = val.AddComponent<TextMeshProUGUI>(); ((TMP_Text)obj).font = ((TMP_Text)template).font; ((TMP_Text)obj).fontSharedMaterial = ((TMP_Text)template).fontSharedMaterial; ((TMP_Text)obj).fontSize = fontSize; ((TMP_Text)obj).fontStyle = (FontStyles)1; ((Graphic)obj).color = color; ((TMP_Text)obj).alignment = (TextAlignmentOptions)257; ((TMP_Text)obj).textWrappingMode = (TextWrappingModes)0; ((TMP_Text)obj).overflowMode = (TextOverflowModes)0; ((Graphic)obj).raycastTarget = false; RectTransform rectTransform = ((TMP_Text)obj).rectTransform; rectTransform.pivot = new Vector2(0f, 1f); rectTransform.anchorMin = ((TMP_Text)template).rectTransform.anchorMin; rectTransform.anchorMax = ((TMP_Text)template).rectTransform.anchorMax; rectTransform.sizeDelta = new Vector2(560f, 36f); ((Transform)rectTransform).localScale = Vector3.one; val.SetActive(false); return obj; } } public sealed class BoomboxVariantInfo { public string PrefabName; public string DisplayName; public string CategoryKey; public string Description; public string TexturePrefix; public Color AccentColor; public Color BodyTint; public bool IsInfinity; public itemSecretShopType SecretShopType; } public static class BoomboxPrefabBuilder { private sealed class CassetteMeshPart { public string Name; public int MatSlot; public Mesh Mesh; } public const string ItemName = "基米之声"; public const string PrefabName = "Item Hachimi Boombox"; public static readonly BoomboxVariantInfo[] Variants = new BoomboxVariantInfo[3] { new BoomboxVariantInfo { PrefabName = "Item Hachimi Boombox", DisplayName = "基米之声", CategoryKey = "基米之声", Description = "基米之声便携卡带:金色复古卡带,经典哈基米歌单,支持放进物品栏继续播放与实时歌词。", TexturePrefix = "hachimi", AccentColor = new Color(1f, 0.62f, 0.26f, 1f), BodyTint = new Color(1.18f, 0.94f, 0.58f, 1f), IsInfinity = false, SecretShopType = (itemSecretShopType)1 }, new BoomboxVariantInfo { PrefabName = "Item Sleepy Boombox", DisplayName = "困の音箱", CategoryKey = "困の音箱", Description = "困の音箱便携卡带:薰衣草淡紫卡带,专属困音歌单与淡紫滚动歌词。", TexturePrefix = "sleepy", AccentColor = new Color(1f, 0.47f, 0.66f, 1f), BodyTint = new Color(0.76f, 0.7f, 1.18f, 1f), IsInfinity = false, SecretShopType = (itemSecretShopType)0 }, new BoomboxVariantInfo { PrefabName = "Item Infinity Boombox", DisplayName = "infinity音箱", CategoryKey = "infinity音箱", Description = "infinity音箱便携卡带:深海科技蓝框 + 动态无尽流光卡带,专属歌单与 &b 滚动歌词。", TexturePrefix = "infinity", AccentColor = new Color(0.12f, 0.94f, 0.76f, 1f), BodyTint = new Color(0.75f, 1.12f, 1.18f, 1f), IsInfinity = true, SecretShopType = (itemSecretShopType)0 } }; private static bool registered; private static GameObject prefabContainer; public static readonly List<Item> RegisteredItems = new List<Item>(); private static List<CassetteMeshPart> cachedCassetteParts; public static Item RegisteredItem { get { if (RegisteredItems.Count <= 0) { return null; } return RegisteredItems[0]; } } public static BoomboxVariantInfo ResolveVariant(string objName) { if (!string.IsNullOrEmpty(objName)) { for (int i = 0; i < Variants.Length; i++) { if (objName.IndexOf(Variants[i].PrefabName, StringComparison.OrdinalIgnoreCase) >= 0) { return Variants[i]; } } } return Variants[0]; } public static void TryRegister() { //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown if (registered) { return; } if ((Object)(object)StatsManager.instance == (Object)null || StatsManager.instance.itemDictionary == null || StatsManager.instance.itemDictionary.Count == 0) { Plugin.Log.LogWarning((object)"StatsManager.instance.itemDictionary is not ready yet."); return; } Item val = FindTemplateItem(new List<Item>(StatsManager.instance.itemDictionary.Values).ToArray()); if ((Object)(object)val == (Object)null || val.prefab == null || (Object)(object)((PrefabRef<GameObject>)(object)val.prefab).Prefab == (Object)null) { Plugin.Log.LogError((object)"Could not find a suitable vanilla Item template prefab to clone."); return; } prefabContainer = new GameObject("HJM_PrefabContainer"); prefabContainer.SetActive(false); Object.DontDestroyOnLoad((Object)(object)prefabContainer); for (int i = 0; i < Variants.Length; i++) { RegisterSingleVariant(Variants[i], val); } registered = RegisteredItems.Count > 0; } private static void RegisterSingleVariant(BoomboxVariantInfo info, Item templateItem) { GameObject obj = Object.Instantiate<GameObject>(((PrefabRef<GameObject>)(object)templateItem.prefab).Prefab, prefabContainer.transform); ((Object)obj).name = info.PrefabName; obj.SetActive(true); StripTemplateScripts(obj); SetupItemScriptableObject(obj, templateItem, info); SetupToggleAndEquippable(obj); SetupBoomboxVisuals(obj, info, out var speaker, out var speaker2, out var light, out var light2); HachimiBoombox hachimiBoombox = obj.AddComponent<HachimiBoombox>(); hachimiBoombox.speaker1 = speaker; hachimiBoombox.speaker2 = speaker2; hachimiBoombox.light1 = light; hachimiBoombox.light2 = light2; ItemAttributes component = obj.GetComponent<ItemAttributes>(); if (Items.RegisterItem(component) != null) { RegisteredItems.Add(component.item); if (!StatsManager.instance.itemDictionary.ContainsKey(((Object)component.item).name)) { StatsManager.instance.itemDictionary.Add(((Object)component.item).name, component.item); } Plugin.Log.LogInfo((object)$"Registered '{info.DisplayName}' ({info.PrefabName}) successfully (price: {component.item.value.valueMin})."); } else { Plugin.Log.LogError((object)("Failed to register '" + info.DisplayName + "' via REPOLib.")); } } private static Item FindTemplateItem(Item[] items) { string[] array = new string[5] { "Item Tracker", "Item Valuable Tracker", "Item Extraction Tracker", "Item Walkie Talkie", "Item Rubber Duck" }; Item[] array2; foreach (string value in array) { array2 = items; foreach (Item val in array2) { if ((Object)(object)val != (Object)null && val.prefab != null && (Object)(object)((PrefabRef<GameObject>)(object)val.prefab).Prefab != (Object)null && ((Object)val).name.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0) { return val; } } } array2 = items; foreach (Item val2 in array2) { if ((Object)(object)val2 != (Object)null && val2.prefab != null && (Object)(object)((PrefabRef<GameObject>)(object)val2.prefab).Prefab != (Object)null && (Object)(object)((PrefabRef<GameObject>)(object)val2.prefab).Prefab.GetComponent<ItemEquippable>() != (Object)null) { return val2; } } return null; } private static void StripTemplateScripts(GameObject root) { Light[] componentsInChildren = root.GetComponentsInChildren<Light>(true); foreach (Light obj in componentsInChildren) { ((Behaviour)obj).enabled = false; obj.cullingMask = 0; } Renderer[] componentsInChildren2 = root.GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { componentsInChildren2[i].forceRenderingOff = true; } Type[] array = new Type[8] { typeof(ItemTracker), typeof(ItemWalkieTalkie), typeof(ItemRubberDuck), typeof(ItemBattery), typeof(ItemLight), typeof(ItemHealthPack), typeof(ItemDrone), typeof(ItemOrb) }; foreach (Type type in array) { Component[] componentsInChildren3 = root.GetComponentsInChildren(type, true); for (int j = 0; j < componentsInChildren3.Length; j++) { Object.DestroyImmediate((Object)(object)componentsInChildren3[j]); } } BatteryVisualLogic[] componentsInChildren4 = root.GetComponentsInChildren<BatteryVisualLogic>(true); for (int i = 0; i < componentsInChildren4.Length; i++) { Object.DestroyImmediate((Object)(object)((Component)componentsInChildren4[i]).gameObject); } } private static void SetupItemScriptableObject(GameObject root, Item templateItem, BoomboxVariantInfo info) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: 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) ItemAttributes component = root.GetComponent<ItemAttributes>(); Item val = ScriptableObject.CreateInstance<Item>(); ((Object)val).name = info.PrefabName; val.status = (Status)1; val.disabled = false; val.itemName = info.DisplayName; val.itemNameLocalized = null; val.description = info.Description; val.itemType = (itemType)13; val.itemSecretShopType = info.SecretShopType; val.emojiIcon = templateItem.emojiIcon; val.itemVolume = templateItem.itemVolume; val.colorPreset = templateItem.colorPreset; val.maxAmount = Plugin.ShopMaxAmount.Value; val.maxAmountInShop = Plugin.ShopMaxAmountInShop.Value; val.minPlayerCount = 1; val.maxPurchase = false; val.physicalItem = true; Value val2 = ScriptableObject.CreateInstance<Value>(); val2.valueMin = Plugin.ShopPrice.Value; val2.valueMax = Plugin.ShopPrice.Value; val.value = val2; component.item = val; Texture2D val3 = LoadEmbeddedTexture(info.TexturePrefix + "_icon.png", smoothFilter: true); component.icon = Sprite.Create(val3, new Rect(0f, 0f, (float)((Texture)val3).width, (float)((Texture)val3).height), new Vector2(0.5f, 0.5f)); ItemEquippable component2 = root.GetComponent<ItemEquippable>(); if ((Object)(object)component2 != (Object)null) { component2.ItemIcon = component.icon; } } private static void SetupToggleAndEquippable(GameObject root) { ItemToggle val = root.GetComponent<ItemToggle>(); if ((Object)(object)val == (Object)null) { val = root.AddComponent<ItemToggle>(); } val.playSound = true; val.autoTurnOffWhenEquipped = false; if ((Object)(object)root.GetComponent<ItemEquippable>() == (Object)null) { root.AddComponent<ItemEquippable>(); } } private static void SetupBoomboxVisuals(GameObject root, BoomboxVariantInfo info, out Transform speaker1, out Transform speaker2, out Light light1, out Light light2) { //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Expected O, but got Unknown //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Expected O, but got Unknown //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: Unknown result type (might be due to invalid IL or missing references) //IL_02f4: Unknown result type (might be due to invalid IL or missing references) //IL_02fa: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) MeshRenderer[] componentsInChildren = root.GetComponentsInChildren<MeshRenderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { ((Renderer)componentsInChildren[i]).enabled = false; } Shader baseShader = FindTemplateShader(root); if (TryBuildCassetteVisual(root, info, baseShader, out speaker1, out speaker2, out light1, out light2)) { return; } ValuableBoombox val = FindVanillaBoombox(); if ((Object)(object)val != (Object)null) { GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, root.transform); ((Object)val2).name = "BoomboxVisual"; val2.transform.localPosition = Vector3.zero; val2.transform.localRotation = Quaternion.identity; val2.transform.localScale = Vector3.one * 0.48f; Collider[] componentsInChildren2 = val2.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren2[i]); } Rigidbody[] componentsInChildren3 = val2.GetComponentsInChildren<Rigidbody>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren3[i]); } ValuableBoombox component = val2.GetComponent<ValuableBoombox>(); speaker1 = (((Object)(object)component != (Object)null) ? component.speaker1 : null); speaker2 = (((Object)(object)component != (Object)null) ? component.speaker2 : null); light1 = (((Object)(object)component != (Object)null) ? component.light1 : null); light2 = (((Object)(object)component != (Object)null) ? component.light2 : null); MonoBehaviour[] componentsInChildren4 = val2.GetComponentsInChildren<MonoBehaviour>(true); for (int i = 0; i < componentsInChildren4.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren4[i]); } ApplyBodyTint(val2, speaker1, speaker2, info.BodyTint, info.AccentColor); if ((Object)(object)speaker1 != (Object)null && (Object)(object)speaker2 != (Object)null && (Object)(object)light1 != (Object)null && (Object)(object)light2 != (Object)null) { return; } } GameObject val3 = new GameObject("BoomboxVisual"); val3.transform.SetParent(root.transform, false); GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3); ((Object)obj).name = "Body"; Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>()); obj.transform.SetParent(val3.transform, false); obj.transform.localScale = new Vector3(0.42f, 0.22f, 0.16f); Material material = new Material(Shader.Find("Standard")) { color = info.BodyTint * 0.22f }; obj.GetComponent<Renderer>().material = material; GameObject obj2 = GameObject.CreatePrimitive((PrimitiveType)3); ((Object)obj2).name = "Handle"; Object.DestroyImmediate((Object)(object)obj2.GetComponent<Collider>()); obj2.transform.SetParent(val3.transform, false); obj2.transform.localPosition = new Vector3(0f, 0.14f, 0f); obj2.transform.localScale = new Vector3(0.24f, 0.03f, 0.04f); obj2.GetComponent<Renderer>().material = material; speaker1 = CreateSpeaker(val3.transform, "Speaker1", new Vector3(-0.11f, 0f, 0.082f), info.AccentColor, out light1); speaker2 = CreateSpeaker(val3.transform, "Speaker2", new Vector3(0.11f, 0f, 0.082f), info.AccentColor, out light2); } private static void ApplyBodyTint(GameObject visualCopy, Transform speaker1, Transform speaker2, Color bodyTint, Color accentColor) { //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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) MeshRenderer[] componentsInChildren = visualCopy.GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val in componentsInChildren) { if ((Object)(object)val == (Object)null || ((Object)(object)speaker1 != (Object)null && (Object)(object)((Component)val).transform == (Object)(object)speaker1) || ((Object)(object)speaker2 != (Object)null && (Object)(object)((Component)val).transform == (Object)(object)speaker2)) { continue; } Material[] materials = ((Renderer)val).materials; foreach (Material val2 in materials) { if (!((Object)(object)val2 == (Object)null)) { if (val2.HasProperty("_Color")) { val2.color *= bodyTint; } if (val2.HasProperty("_EmissionColor")) { val2.EnableKeyword("_EMISSION"); val2.SetColor("_EmissionColor", accentColor * 0.08f); } } } } } private static Transform CreateSpeaker(Transform parent, string name, Vector3 localPos, Color accentColor, out Light light) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0047: 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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown //IL_00e6: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.CreatePrimitive((PrimitiveType)2); ((Object)val).name = name; Object.DestroyImmediate((Object)(object)val.GetComponent<Collider>()); val.transform.SetParent(parent, false); val.transform.localPosition = localPos; val.transform.localRotation = Quaternion.Euler(90f, 0f, 0f); val.transform.localScale = new Vector3(0.13f, 0.015f, 0.13f); Material val2 = new Material(Shader.Find("Standard")) { color = accentColor }; val2.EnableKeyword("_EMISSION"); val2.SetColor("_EmissionColor", Color.black); val.GetComponent<Renderer>().material = val2; GameObject val3 = new GameObject(name + "_Light"); val3.transform.SetParent(val.transform, false); val3.transform.localPosition = new Vector3(0f, 0.5f, 0f); light = val3.AddComponent<Light>(); light.type = (LightType)2; light.range = 3.5f; light.intensity = 0f; ((Behaviour)light).enabled = false; return val.transform; } private static Shader FindTemplateShader(GameObject root) { MeshRenderer[] componentsInChildren = root.GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val in componentsInChildren) { if ((Object)(object)val != (Object)null && (Object)(object)((Renderer)val).sharedMaterial != (Object)null && (Object)(object)((Renderer)val).sharedMaterial.shader != (Object)null) { return ((Renderer)val).sharedMaterial.shader; } } Shader val2 = Shader.Find("Universal Render Pipeline/Lit"); if (!((Object)(object)val2 != (Object)null)) { return Shader.Find("Standard"); } return val2; } private static bool TryBuildCassetteVisual(GameObject root, BoomboxVariantInfo info, Shader baseShader, out Transform speaker1, out Transform speaker2, out Light light1, out Light light2) { //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Expected O, but got Unknown //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Expected O, but got Unknown //IL_0346: Unknown result type (might be due to invalid IL or missing references) //IL_036e: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0489: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_0426: Unknown result type (might be due to invalid IL or missing references) //IL_0441: Unknown result type (might be due to invalid IL or missing references) //IL_03e9: Unknown result type (might be due to invalid IL or missing references) //IL_03fa: Unknown result type (might be due to invalid IL or missing references) //IL_040b: Unknown result type (might be due to invalid IL or missing references) speaker1 = null; speaker2 = null; light1 = null; light2 = null; List<CassetteMeshPart> list = LoadCassetteParts(); if (list == null || list.Count == 0) { return false; } Texture2D tex = LoadEmbeddedTexture(info.TexturePrefix + "_case.png", smoothFilter: true); Texture2D val = LoadEmbeddedTexture(info.TexturePrefix + "_glow.png", smoothFilter: true); Texture2D tex2 = LoadEmbeddedTexture(info.TexturePrefix + "_face.png", smoothFilter: true); Texture2D tex3 = LoadEmbeddedTexture(info.TexturePrefix + "_cyl1.png", smoothFilter: true); Texture2D tex4 = LoadEmbeddedTexture(info.TexturePrefix + "_cyl2.png", smoothFilter: true); Shader val2 = Shader.Find("Standard"); if ((Object)(object)val2 != (Object)null && val2.isSupported) { baseShader = val2; } Material[] array = (Material[])(object)new Material[4] { CreateTexturedMaterial(baseShader, tex, null, info.AccentColor, 0f, info.IsInfinity ? 0.36f : 0.3f), default(Material), default(Material), default(Material) }; if (array[0].HasProperty("_EmissionMap")) { array[0].SetTexture("_EmissionMap", (Texture)(object)val); } array[1] = CreateTexturedMaterial(baseShader, tex2, null, info.AccentColor, 0.02f, 0.3f); array[2] = CreateTexturedMaterial(baseShader, tex3, null, info.AccentColor, 0.04f, 0.35f); array[3] = CreateTexturedMaterial(baseShader, tex4, null, info.AccentColor, 0.04f, 0.35f); GameObject val3 = new GameObject("BoomboxVisual"); val3.transform.SetParent(root.transform, false); val3.transform.localPosition = Vector3.zero; val3.transform.localRotation = Quaternion.LookRotation(Vector3.left, Vector3.back); val3.transform.localScale = Vector3.one * 0.728f; for (int i = 0; i < list.Count; i++) { CassetteMeshPart cassetteMeshPart = list[i]; GameObject val4 = new GameObject(cassetteMeshPart.Name); val4.transform.SetParent(val3.transform, false); if (cassetteMeshPart.Name == "cylinder" || cassetteMeshPart.Name == "cylinder_1" || cassetteMeshPart.Name == "plane") { val4.transform.localPosition = new Vector3(0f, 0.006f, 0f); } else if (cassetteMeshPart.Name == "plane_1") { val4.transform.localPosition = new Vector3(0f, 0.005f, 0f); } val4.AddComponent<MeshFilter>().sharedMesh = cassetteMeshPart.Mesh; MeshRenderer obj = val4.AddComponent<MeshRenderer>(); int num = Mathf.Clamp(cassetteMeshPart.MatSlot, 0, array.Length - 1); ((Renderer)obj).sharedMaterial = array[num]; if (!(cassetteMeshPart.Name == "cube")) { if (cassetteMeshPart.Name == "cylinder") { speaker1 = val4.transform; } else if (cassetteMeshPart.Name == "cylinder_1") { speaker2 = val4.transform; } } } light1 = CreateCassetteLight(val3.transform, "CassetteLight1", new Vector3(0.02f, 0.08f, 0.2f)); light2 = CreateCassetteLight(val3.transform, "CassetteLight2", new Vector3(0.02f, 0.08f, -0.2f)); BoxCollider val5 = null; Collider[] componentsInChildren = root.GetComponentsInChildren<Collider>(true); foreach (Collider val6 in componentsInChildren) { if ((Object)(object)val6 == (Object)null || val6.isTrigger) { continue; } if ((Object)(object)val5 == (Object)null) { BoxCollider val7 = (BoxCollider)(object)((val6 is BoxCollider) ? val6 : null); if (val7 != null) { val5 = val7; if ((Object)(object)((Component)val7).transform != (Object)(object)root.transform) { ((Component)val7).transform.localPosition = Vector3.zero; ((Component)val7).transform.localRotation = Quaternion.identity; ((Component)val7).transform.localScale = Vector3.one; } val7.center = new Vector3(0f, 0f, -0.0315f); val7.size = new Vector3(0.6622f, 0.4144f, 0.0924f); continue; } } val6.enabled = false; } Rigidbody component = root.GetComponent<Rigidbody>(); if ((Object)(object)component != (Object)null) { component.centerOfMass = new Vector3(0f, -0.063f, -0.0315f); } return true; } private static Light CreateCassetteLight(Transform parent, string name, Vector3 localPos) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_0019: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); val.transform.SetParent(parent, false); val.transform.localPosition = localPos; Light obj = val.AddComponent<Light>(); obj.type = (LightType)2; obj.range = 1.2f; obj.shadows = (LightShadows)0; obj.intensity = 0f; ((Behaviour)obj).enabled = false; return obj; } private static Material CreateTexturedMaterial(Shader shader, Texture2D tex, Texture2D normalMap, Color accent, float emissionStrength, float smoothness) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) Material val = new Material(shader); if ((Object)(object)tex != (Object)null) { if (val.HasProperty("_BaseMap")) { val.SetTexture("_BaseMap", (Texture)(object)tex); } if (val.HasProperty("_MainTex")) { val.SetTexture("_MainTex", (Texture)(object)tex); } } if ((Object)(object)normalMap != (Object)null && val.HasProperty("_BumpMap")) { val.EnableKeyword("_NORMALMAP"); val.SetTexture("_BumpMap", (Texture)(object)normalMap); if (val.HasProperty("_BumpScale")) { val.SetFloat("_BumpScale", 1.15f); } } if (val.HasProperty("_BaseColor")) { val.SetColor("_BaseColor", Color.white); } if (val.HasProperty("_Color")) { val.color = Color.white; } if (val.HasProperty("_Metallic")) { val.SetFloat("_Metallic", 0.22f); } if (val.HasProperty("_Smoothness")) { val.SetFloat("_Smoothness", smoothness); } if (val.HasProperty("_Glossiness")) { val.SetFloat("_Glossiness", smoothness); } if (val.HasProperty("_EmissionColor")) { val.EnableKeyword("_EMISSION"); val.SetColor("_EmissionColor", accent * emissionStrength); } return val; } private static List<CassetteMeshPart> LoadCassetteParts() { //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Expected O, but got Unknown if (cachedCassetteParts != null) { return cachedCassetteParts; } byte[] array = ReadEmbeddedBytes("cassette_model.bin"); if (array == null || array.Length == 0) { return null; } List<CassetteMeshPart> list = new List<CassetteMeshPart>(); using (MemoryStream input = new MemoryStream(array)) { using BinaryReader binaryReader = new BinaryReader(input); int num = binaryReader.ReadInt32(); for (int i = 0; i < num; i++) { string text = binaryReader.ReadString(); int matSlot = binaryReader.ReadInt32(); int num2 = binaryReader.ReadInt32(); Vector3[] array2 = (Vector3[])(object)new Vector3[num2]; Vector3[] array3 = (Vector3[])(object)new Vector3[num2]; Vector2[] array4 = (Vector2[])(object)new Vector2[num2]; for (int j = 0; j < num2; j++) { array2[j] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle()); array3[j] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle()); array4[j] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle()); } int num3 = binaryReader.ReadInt32(); int[] array5 = new int[num3]; for (int k = 0; k < num3; k++) { array5[k] = binaryReader.ReadInt32(); } Mesh val = new Mesh { name = "Cassette_" + text }; val.vertices = array2; val.normals = array3; val.uv = array4; val.triangles = array5; val.RecalculateBounds(); Object.DontDestroyOnLoad((Object)(object)val); list.Add(new CassetteMeshPart { Name = text, MatSlot = matSlot, Mesh = val }); } } cachedCassetteParts = list; return cachedCassetteParts; } internal static Texture2D LoadEmbeddedTexture(string fileName, bool smoothFilter = false, bool isNormal = false) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown byte[] array = ReadEmbeddedBytes(fileName); if (array == null || array.Length == 0) { return null; } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false, isNormal); ((Texture)val).filterMode = (FilterMode)(smoothFilter ? 1 : 0); ((Texture)val).wrapMode = (TextureWrapMode)1; if (ImageConversion.LoadImage(val, array)) { Object.DontDestroyOnLoad((Object)(object)val); return val; } return null; } internal static byte[] ReadEmbeddedBytes(string fileName) { Assembly executingAssembly = Assembly.GetExecutingAssembly(); string[] manifestResourceNames = executingAssembly.GetManifestResourceNames(); foreach (string text in manifestResourceNames) { if (!text.EndsWith(fileName, StringComparison.OrdinalIgnoreCase)) { continue; } using Stream stream = executingAssembly.GetManifestResourceStream(text); if (stream == null) { return null; } byte[] array = new byte[stream.Length]; int num; for (int j = 0; j < array.Length; j += num) { num = stream.Read(array, j, array.Length - j); if (num <= 0) { break; } } return array; } return null; } private static ValuableBoombox FindVanillaBoombox() { try { GameObject[] array = Resources.LoadAll<GameObject>("Valuables"); foreach (GameObject val in array) { if (!((Object)(object)val == (Object)null)) { ValuableBoombox componentInChildren = val.GetComponentInChildren<ValuableBoombox>(true); if ((Object)(object)componentInChildren != (Object)null) { return componentInChildren; } } } } catch (Exception ex) { Plugin.Log.LogDebug((object)("FindVanillaBoombox fallback: " + ex.Message)); } return null; } } public class HachimiBoombox : MonoBehaviourPunCallbacks { public static readonly List<HachimiBoombox> ActiveBoomboxes = new List<HachimiBoombox>(); public Transform speaker1; public Transform speaker2; public Light light1; public Light light2; private BoomboxVariantInfo variantInfo; private readonly List<Material> shellMaterials = new List<Material>(); private PhysGrabObject physGrabObject; private ItemEquippable itemEquippable; private ItemToggle itemToggle; private GameObject audioHost; private AudioSource audioSource; private Vector3 speaker1BaseScale = Vector3.one; private Vector3 speaker2BaseScale = Vector3.one; private Material speaker1Mat; private Material speaker2Mat; private bool isPlaying; private int currentTrackIndex; private bool prevToggleState; private float trackStartTime; private bool waitingForClipLoad; private float boomboxVolume = 0.85f; private readonly float[] spectrum = new float[512]; private float bassAverage; private float beat; public string CategoryKey { get { if (variantInfo == null) { return "基米之声"; } return variantInfo.CategoryKey; } } public string DisplayName { get { if (variantInfo == null) { return "基米之声"; } return variantInfo.DisplayName; } } public Color AccentColor { get { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) if (variantInfo == null) { return new Color(1f, 0.8f, 0.25f, 1f); } return variantInfo.AccentColor; } } public string CurrentTrackTitle { get { TrackEntry track = TrackLibrary.GetTrack(CategoryKey, currentTrackIndex); if (track == null) { return string.Empty; } return track.Title; } } public string CurrentLyric { get { TryGetCurrentLyric(out var text, out var _); return text; } } public bool IsPlaying => isPlaying; private void Awake() { //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) ActiveBoomboxes.Add(this); variantInfo = BoomboxPrefabBuilder.ResolveVariant(((Object)((Component)this).gameObject).name); boomboxVolume = Mathf.Clamp(Plugin.Volume.Value, 0f, 2f); physGrabObject = ((Component)this).GetComponent<PhysGrabObject>(); itemEquippable = ((Component)this).GetComponent<ItemEquippable>(); itemToggle = ((Component)this).GetComponent<ItemToggle>(); if ((Object)(object)itemToggle != (Object)null) { itemToggle.autoTurnOffWhenEquipped = false; prevToggleState = itemToggle.toggleState; } if ((Object)(object)speaker1 != (Object)null) { speaker1BaseScale = speaker1.localScale; Renderer component = ((Component)speaker1).GetComponent<Renderer>(); if ((Object)(object)component != (Object)null) { speaker1Mat = component.material; } } if ((Object)(object)speaker2 != (Object)null) { speaker2BaseScale = speaker2.localScale; Renderer component2 = ((Component)speaker2).GetComponent<Renderer>(); if ((Object)(object)component2 != (Object)null) { speaker2Mat = component2.material; } } Transform val = ((Component)this).transform.Find("BoomboxVisual"); if ((Object)(object)val != (Object)null) { MeshRenderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val2 in componentsInChildren) { if (((Object)val2).name == "cube" || ((Object)val2).name == "cube_1") { shellMaterials.Add(((Renderer)val2).material); } } } if ((Object)(object)light1 != (Object)null) { ((Behaviour)light1).enabled = false; } if ((Object)(object)light2 != (Object)null) { ((Behaviour)light2).enabled = false; } CreateAudioHost(); } private void CreateAudioHost() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown audioHost = new GameObject($"HachimiAudioHost_{((Object)this).GetInstanceID()}"); audioSource = audioHost.AddComponent<AudioSource>(); audioSource.playOnAwake = false; audioSource.loop = false; audioSource.spatialBlend = 1f; audioSource.rolloffMode = (AudioRolloffMode)1; audioSource.minDistance = 2.5f; audioSource.maxDistance = 24f; audioSource.dopplerLevel = 0f; if ((Object)(object)AudioManager.instance != (Object)null && (Object)(object)AudioManager.instance.SoundMasterGroup != (Object)null) { audioSource.outputAudioMixerGroup = AudioManager.instance.SoundMasterGroup; } } private void OnDestroy() { ActiveBoomboxes.Remove(this); foreach (Material shellMaterial in shellMaterials) { if ((Object)(object)shellMaterial != (Object)null) { Object.Destroy((Object)(object)shellMaterial); } } if ((Object)(object)speaker1Mat != (Object)null) { Object.Destroy((Object)(object)speaker1Mat); } if ((Object)(object)speaker2Mat != (Object)null) { Object.Destroy((Object)(object)speaker2Mat); } if ((Object)(object)audioHost != (Object)null) { Object.Destroy((Object)(object)audioHost); } } private void Update() { if ((Object)(object)itemToggle != (Object)null && itemToggle.toggleState != prevToggleState) { prevToggleState = itemToggle.toggleState; OnToggleChanged(itemToggle.toggleState); } UpdateAudioHostPosition(); UpdateAudioPlayback(); UpdatePlaybackVisuals(); } private void UpdateAudioHostPosition() { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)audioHost == (Object)null) { return; } if ((Object)(object)itemEquippable != (Object)null && itemEquippable.IsEquipped()) { PlayerAvatar ownerPlayerAvatar = itemEquippable.GetOwnerPlayerAvatar(); if ((Object)(object)ownerPlayerAvatar != (Object)null) { audioHost.transform.position = ((Component)ownerPlayerAvatar).transform.position + Vector3.up * 1.1f; return; } } audioHost.transform.position = (((Object)(object)physGrabObject != (Object)null) ? physGrabObject.centerPoint : ((Component)this).transform.position); } private void UpdateAudioPlayback() { if ((Object)(object)audioSource == (Object)null) { return; } audioSource.volume = Mathf.Clamp(boomboxVolume, 0f, 2f); if (!isPlaying) { if (audioSource.isPlaying) { audioSource.Stop(); } } else { if (TrackLibrary.GetTrackCount(CategoryKey) == 0) { return; } if (waitingForClipLoad) { TrackEntry track = TrackLibrary.GetTrack(CategoryKey, currentTrackIndex); if (track != null && (Object)(object)track.Clip != (Object)null) { waitingForClipLoad = false; PlayClip(track); } } else if ((Object)(object)audioSource.clip != (Object)null && !audioSource.isPlaying && Time.unscaledTime - trackStartTime > 0.5f && SemiFunc.IsMasterClientOrSingleplayer()) { RequestSetTrack(TrackLibrary.WrapIndex(CategoryKey, currentTrackIndex + 1)); } } } private float PlaybackPulse() { if (SemiFunc.Photosensitivity()) { return 0.28f; } audioSource.GetSpectrumData(spectrum, 0, (FFTWindow)5); float num = (float)AudioSettings.outputSampleRate / (2f * (float)spectrum.Length); float num2 = 0f; for (int i = 1; i < spectrum.Length && (float)i * num <= 180f; i++) { num2 += spectrum[i] * spectrum[i]; } float num3 = Mathf.Sqrt(num2); float num4 = Mathf.Clamp01((num3 - bassAverage) / Mathf.Max(0.001f, bassAverage)); bassAverage = Mathf.Lerp(bassAverage, num3, 1f - Mathf.Exp(-3f * Time.deltaTime)); beat = Mathf.Max(num4, beat * Mathf.Exp(-8f * Time.deltaTime)); return beat; } private void UpdatePlaybackVisuals() { //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) bool flag = (Object)(object)physGrabObject != (Object)null && physGrabObject.grabbed; bool flag2 = (Object)(object)itemEquippable != (Object)null && itemEquippable.IsEquipped(); if (isPlaying && (Object)(object)audioSource != (Object)null && audioSource.isPlaying) { float num = PlaybackPulse(); float num2 = 1f + 0.018f * num; if ((Object)(object)speaker1 != (Object)null) { speaker1.localScale = speaker1BaseScale * num2; } if ((Object)(object)speaker2 != (Object)null) { speaker2.localScale = speaker2BaseScale * num2; } float num3 = 0.5f * Mathf.Lerp(0.19f, (variantInfo.TexturePrefix == "hachimi") ? 0.53f : 0.72f, num); Color accentColor = AccentColor; foreach (Material shellMaterial in shellMaterials) { shellMaterial.SetColor("_EmissionColor", Color.white * Mathf.Lerp(0.85f, 2.45f, num)); } if ((Object)(object)speaker1Mat != (Object)null) { speaker1Mat.SetColor("_EmissionColor", Color.Lerp(speaker1Mat.GetColor("_EmissionColor"), accentColor, Time.deltaTime * 15f)); } if ((Object)(object)speaker2Mat != (Object)null) { speaker2Mat.SetColor("_EmissionColor", Color.Lerp(speaker2Mat.GetColor("_EmissionColor"), accentColor, Time.deltaTime * 15f)); } if ((Object)(object)light1 != (Object)null) { ((Behaviour)light1).enabled = true; light1.color = accentColor; light1.intensity = Mathf.Lerp(light1.intensity, num3, Time.deltaTime * 15f); } if ((Object)(object)light2 != (Object)null) { ((Behaviour)light2).enabled = true; light2.color = accentColor; light2.intensity = Mathf.Lerp(light2.intensity, num3, Time.deltaTime * 15f); } if (!flag || flag2) { return; } { foreach (PhysGrabber item in physGrabObject.playerGrabbing) { if ((Object)(object)item != (Object)null && item.isLocal) { item.OverrideMinimumGrabDistance(1.15f); } } return; } } beat = (bassAverage = 0f); FadeOutLightsAndSpeakers(); } private void FadeOutLightsAndSpeakers() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)speaker1 != (Object)null) { speaker1.localScale = Vector3.Lerp(speaker1.localScale, speaker1BaseScale, Time.deltaTime * 6f); } if ((Object)(object)speaker2 != (Object)null) { speaker2.localScale = Vector3.Lerp(speaker2.localScale, speaker2BaseScale, Time.deltaTime * 6f); } if ((Object)(object)speaker1Mat != (Object)null) { speaker1Mat.SetColor("_EmissionColor", Color.Lerp(speaker1Mat.GetColor("_EmissionColor"), Color.black, Time.deltaTime * 6f)); } if ((Object)(object)speaker2Mat != (Object)null) { speaker2Mat.SetColor("_EmissionColor", Color.Lerp(speaker2Mat.GetColor("_EmissionColor"), Color.black, Time.deltaTime * 6f)); } foreach (Material shellMaterial in shellMaterials) { shellMaterial.SetColor("_EmissionColor", Color.Lerp(shellMaterial.GetColor("_EmissionColor"), Color.black, Time.deltaTime * 6f)); } if ((Object)(object)light1 != (Object)null && ((Behaviour)light1).enabled) { light1.intensity = Mathf.Lerp(light1.intensity, 0f, Time.deltaTime * 6f); if (light1.intensity < 0.02f) { ((Behaviour)light1).enabled = false; } } if ((Object)(object)light2 != (Object)null && ((Behaviour)light2).enabled) { light2.intensity = Mathf.Lerp(light2.intensity, 0f, Time.deltaTime * 6f); if (light2.intensity < 0.02f) { ((Behaviour)light2).enabled = false; } } } private void OnToggleChanged(bool newState) { if (newState) { isPlaying = true; if (SemiFunc.IsMasterClientOrSingleplayer()) { RequestSetTrack(currentTrackIndex); } else { PlayCurrentTrack(); } return; } isPlaying = false; waitingForClipLoad = false; if ((Object)(object)audioSource != (Object)null) { audioSource.Stop(); } } public override void OnPlayerEnteredRoom(Player newPlayer) { if (SemiFunc.IsMasterClientOrSingleplayer() && (Object)(object)((MonoBehaviourPun)this).photonView != (Object)null && ((MonoBehaviourPun)this).photonView.ViewID != 0) { if (isPlaying) { float num = (((Object)(object)audioSource != (Object)null && audioSource.isPlaying) ? audioSource.time : 0f); ((MonoBehaviourPun)this).photonView.RPC("RPC_SyncTrack", newPlayer, new object[4] { currentTrackIndex, TrackLibrary.CurrentSeed, num, boomboxVolume }); } else { ((MonoBehaviourPun)this).photonView.RPC("RPC_SetVolume", newPlayer, new object[1] { boomboxVolume }); } } } public void RequestAdjustVolume(float delta) { float num = Mathf.Clamp(Mathf.Round((boomboxVolume + delta) * 10f) / 10f, 0f, 2f); if (GameManager.Multiplayer() && (Object)(object)((MonoBehaviourPun)this).photonView != (Object)null && ((MonoBehaviourPun)this).photonView.ViewID != 0) { ((MonoBehaviourPun)this).photonView.RPC("RPC_SetVolume", (RpcTarget)0, new object[1] { num }); } else { ApplyVolume(num); } } [PunRPC] private void RPC_SetVolume(float vol) { ApplyVolume(vol); } private void ApplyVolume(float vol) { boomboxVolume = Mathf.Clamp(vol, 0f, 2f); if ((Object)(object)audioSource != (Object)null) { audioSource.volume = boomboxVolume; } if (IsLocalRelevant()) { BoomboxHud.ShowVolume(Mathf.RoundToInt(boomboxVolume * 100f)); } } public void RequestNextTrack(int delta) { if (isPlaying && TrackLibrary.GetTrackCount(CategoryKey) != 0) { RequestSetTrack(TrackLibrary.WrapIndex(CategoryKey, currentTrackIndex + delta)); } } public void RequestRandomTrack() { if (isPlaying && TrackLibrary.GetTrackCount(CategoryKey) != 0) { RequestSetTrack(TrackLibrary.GetRandomIndex(CategoryKey, currentTrackIndex)); } } private void RequestSetTrack(int trackIndex) { if (GameManager.Multiplayer() && (Object)(object)((MonoBehaviourPun)this).photonView != (Object)null && ((MonoBehaviourPun)this).photonView.ViewID != 0) { ((MonoBehaviourPun)this).photonView.RPC("RPC_SyncTrack", (RpcTarget)0, new object[4] { trackIndex, TrackLibrary.CurrentSeed, 0f, boomboxVolume }); } else { ApplyTrack(trackIndex, TrackLibrary.CurrentSeed, 0f, boomboxVolume); } } [PunRPC] private void RPC_SyncTrack(int trackIndex, int seed, float playbackTime, float volume) { ApplyTrack(trackIndex, seed, playbackTime, volume); } private void ApplyTrack(int trackIndex, int seed, float playbackTime, float volume) { boomboxVolume = Mathf.Clamp(volume, 0f, 2f); TrackLibrary.EnsureSeed(seed); currentTrackIndex = TrackLibrary.WrapIndex(CategoryKey, trackIndex); if (isPlaying) { PlayCurrentTrack(playbackTime); } } private void PlayCurrentTrack(float seekTime = 0f) { TrackEntry track = TrackLibrary.GetTrack(CategoryKey, currentTrackIndex); if (track != null) { if ((Object)(object)track.Clip == (Object)null) { waitingForClipLoad = true; TrackLibrary.RequestStreamClip(track); } else { PlayClip(track, seekTime); } } } public bool TryGetCurrentLyric(out string text, out float progress) { text = string.Empty; progress = 0f; if (!isPlaying || (Object)(object)audioSource == (Object)null || !audioSource.isPlaying) { return false; } return TrackLibrary.GetTrack(CategoryKey, currentTrackIndex)?.TryGetLyricStateAt(audioSource.time, out text, out progress) ?? false; } private void PlayClip(TrackEntry entry, float seekTime = 0f) { if (!((Object)(object)audioSource == (Object)null) && !((Object)(object)entry.Clip == (Object)null)) { audioSource.Stop(); audioSource.clip = entry.Clip; if (seekTime > 0.1f && seekTime < entry.Clip.length) { audioSource.time = seekTime; } audioSource.Play(); trackStartTime = Time.unscaledTime; } } public bool IsLocalHeld() { if ((Object)(object)physGrabObject == (Object)null || !physGrabObject.grabbed) { return false; } foreach (PhysGrabber item in physGrabObject.playerGrabbing) { if ((Object)(object)item != (Object)null && item.isLocal) { return true; } } return false; } public bool IsLocalOwnedInInventory() { if ((Object)(object)itemEquippable == (Object)null || !itemEquippable.IsEquipped()) { return false; } PlayerAvatar ownerPlayerAvatar = itemEquippable.GetOwnerPlayerAvatar(); if ((Object)(object)ownerPlayerAvatar != (Object)null) { return (Object)(object)ownerPlayerAvatar == (Object)(object)PlayerAvatar.instance; } return false; } public bool IsLocalRelevant() { if (!IsLocalHeld()) { return IsLocalOwnedInInventory(); } return true; } } [BepInPlugin("hjm.hachimimusic.repo", "自定义唱片 CustomizeMusic", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { private static class Patches { [HarmonyPatch(typeof(PhysGrabObject), "GrabTorqueGet")] [HarmonyPrefix] private static void CassetteHoldTarget(PhysGrabObject __instance, PhysGrabber player, ref Vector3 worldForward, ref Vector3 worldUp) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) HachimiBoombox hachimiBoombox = default(HachimiBoombox); if (!((Object)(object)player == (Object)null) && ((Component)__instance).TryGetComponent<HachimiBoombox>(ref hachimiBoombox) && __instance.playerGrabbing.Count == 1) { Vector3 val = Vector3.ProjectOnPlane(((Component)__instance).transform.position - ((Component)player).transform.position, Vector3.up); if (!(((Vector3)(ref val)).sqrMagnitude < 0.001f)) { Quaternion val2 = Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up) * Quaternion.Euler(10f, 0f, 0f); worldForward = val2 * Vector3.forward; worldUp = val2 * Vector3.up; } } } [HarmonyPatch(typeof(StatsManager), "LoadItemsFromFolder")] [HarmonyPostfix] private static void AfterLoadItems() { BoomboxPrefabBuilder.TryRegister(); } [HarmonyPatch(typeof(RunManager), "ChangeLevel")] [HarmonyPostfix] private static void OnLevelChanged() { TrackLibrary.ReshuffleForRun(); } } private static class SecretShopPatch { private static readonly MethodInfo ItemSpawnApplyMethod = AccessTools.Method(typeof(PunManager), "ItemSpawnApply", (Type[])null, (Type[])null); private static readonly Type ItemSpawnType = typeof(PunManager).GetNestedType("ItemSpawn", BindingFlags.Public | BindingFlags.NonPublic); private static readonly FieldInfo SpawnPrefabField = AccessTools.Field(ItemSpawnType, "prefab"); private static readonly FieldInfo SpawnPosField = AccessTools.Field(ItemSpawnType, "position"); private static readonly FieldInfo SpawnRotField = AccessTools.Field(ItemSpawnType, "rotation"); [HarmonyTargetMethod] private static MethodBase TargetMethod() { MethodInfo[] methods = typeof(PunManager).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (methodInfo.Name == "ShopPopulateItemVolumes" && methodInfo.GetParameters().Length == 1) { return methodInfo; } } return null; } [HarmonyPrefix] private static void Prefix(PunManager __instance, object _spawns) { //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) if (!SemiFunc.IsMasterClientOrSingleplayer() || (Object)(object)BoomboxPrefabBuilder.RegisteredItem == (Object)null || (Object)(object)ShopManager.instance == (Object)null) { return; } Item registeredItem = BoomboxPrefabBuilder.RegisteredItem; if (!ShopManager.instance.secretItemVolumes.TryGetValue((itemSecretShopType)1, out var value) || value == null || value.Count == 0 || ((Object)(object)StatsManager.instance != (Object)null && StatsManager.instance.itemsPurchased.TryGetValue(((Object)registeredItem).name, out var value2) && value2 >= registeredItem.maxAmount)) { return; } ItemVolume val = null; int index = -1; for (int i = 0; i < value.Count; i++) { if ((Object)(object)value[i] != (Object)null) { val = value[i]; index = i; break; } } if (!((Object)(object)val == (Object)null) && !(ItemSpawnType == null) && !(SpawnPrefabField == null) && !(SpawnPosField == null) && !(SpawnRotField == null) && registeredItem.prefab != null) { Quaternion val2 = ((Component)val).transform.rotation * registeredItem.spawnRotationOffset; if ((Object)(object)ShopManager.instance.itemRotateHelper != (Object)null) { ((Component)ShopManager.instance.itemRotateHelper).transform.parent = ((Component)val).transform; ((Component)ShopManager.instance.itemRotateHelper).transform.localRotation = registeredItem.spawnRotationOffset; val2 = ((Component)ShopManager.instance.itemRotateHelper).transform.rotation; ((Component)ShopManager.instance.itemRotateHelper).transform.parent = ((Component)ShopManager.instance).transform; } object obj = Activator.CreateInstance(ItemSpawnType); SpawnPrefabField?.SetValue(obj, registeredItem.prefab); SpawnPosField?.SetValue(obj, ((Component)val).transform.position); SpawnRotField?.SetValue(obj, val2); if (_spawns is IList list) { list.Add(obj); } else if (ItemSpawnApplyMethod != null) { ItemSpawnApplyMethod.Invoke(__instance, new object[1] { obj }); } if (ShopManager.instance.potentialSecretItems.TryGetValue((itemSecretShopType)1, out var value3)) { value3?.Remove(registeredItem); } value.RemoveAt(index); Object.Destroy((Object)(object)((Component)val).gameObject); Log.LogInfo((object)"Guaranteed Hachimi Boombox spawned in shop secret room (shop_attic)."); } } } public const string PluginGuid = "hjm.hachimimusic.repo"; public const string PluginName = "自定义唱片 CustomizeMusic"; public const string PluginVersion = "1.0.0"; private static readonly FieldInfo InputDisableTimerField = AccessTools.Field(typeof(PlayerController), "InputDisableTimer"); private static readonly FieldInfo GrabbedObjectField = AccessTools.Field(typeof(PhysGrabber), "grabbedPhysGrabObject"); private static readonly FieldInfo LookingAtObjectField = AccessTools.Field(typeof(PhysGrabber), "currentlyLookingAtPhysGrabObject"); internal static Plugin Instance; internal static ManualLogSource Log; internal static ConfigEntry<KeyCode> KeyRandomTrack; internal static ConfigEntry<KeyCode> KeyPrevTrack; internal static ConfigEntry<KeyCode> KeyNextTrack; internal static ConfigEntry<KeyCode> KeyVolumeDown; internal static ConfigEntry<KeyCode> KeyVolumeUp; internal static ConfigEntry<float> Volume; internal static ConfigEntry<int> ShopPrice; internal static ConfigEntry<int> ShopMaxAmount; internal static ConfigEntry<int> ShopMaxAmountInShop; private void Awake() { //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Expected O, but got Unknown //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) Instance = this; Log = ((BaseUnityPlugin)this).Logger; KeyRandomTrack = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "RandomTrackKey", (KeyCode)114, "Key to switch to a random track."); KeyPrevTrack = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "PreviousTrackKey", (KeyCode)280, "Key to switch to the previous track in the playlist."); KeyNextTrack = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "NextTrackKey", (KeyCode)281, "Key to switch to the next track in the playlist."); KeyVolumeDown = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "VolumeDownKey", (KeyCode)45, "Key to decrease boombox volume."); KeyVolumeUp = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "VolumeUpKey", (KeyCode)61, "Key to increase boombox volume."); Volume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "Volume", 0.85f, new ConfigDescription("Boombox playback volume (0.0 to 2.0).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>())); ShopPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Shop", "Price", 1000, "Price of the Hachimi Boombox in the shop."); ShopMaxAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Shop", "MaxAmount", 3, "Maximum total Hachimi Boomboxes."); ShopMaxAmountInShop = ((BaseUnityPlugin)this).Config.Bind<int>("Shop", "MaxAmountInShop", 1, "Maximum Hachimi Boomboxes in the shop at once."); string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); TrackLibrary.Initialize((MonoBehaviour)(object)this, directoryName); Harmony val = new Harmony("hjm.hachimimusic.repo"); val.PatchAll(typeof(Patches)); val.PatchAll(typeof(SecretShopPatch)); Log.LogInfo((object)"自定义唱片 CustomizeMusic v1.0.0 loaded."); } private void Update() { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) BoomboxHud.UpdateHud(); if (!((Object)(object)PlayerController.instance != (Object)null) || !(InputDisableTimerField != null) || !((float)InputDisableTimerField.GetValue(PlayerController.instance) > 0f)) { if (Input.GetKeyDown(KeyRandomTrack.Value)) { FindTargetBoombox()?.RequestRandomTrack(); } else if (Input.GetKeyDown(KeyPrevTrack.Value)) { FindTargetBoombox()?.RequestNextTrack(-1); } else if (Input.GetKeyDown(KeyNextTrack.Value)) { FindTargetBoombox()?.RequestNextTrack(1); } else if (Input.GetKeyDown(KeyVolumeDown.Value)) { FindTargetBoombox()?.RequestAdjustVolume(-0.1f); } else if (Input.GetKeyDown(KeyVolumeUp.Value)) { FindTargetBoombox()?.RequestAdjustVolume(0.1f); } } } private static HachimiBoombox FindTargetBoombox() { if ((Object)(object)PhysGrabber.instance != (Object)null) { object? obj = GrabbedObjectField?.GetValue(PhysGrabber.instance); PhysGrabObject val = (PhysGrabObject)((obj is PhysGrabObject) ? obj : null); if ((Object)(object)val != (Object)null) { HachimiBoombox component = ((Component)val).GetComponent<HachimiBoombox>(); if ((Object)(object)component != (Object)null) { return component; } } object? obj2 = LookingAtObjectField?.GetValue(PhysGrabber.instance); PhysGrabObject val2 = (PhysGrabObject)((obj2 is PhysGrabObject) ? obj2 : null); if ((Object)(object)val2 != (Object)null) { HachimiBoombox component2 = ((Component)val2).GetComponent<HachimiBoombox>(); if ((Object)(object)component2 != (Object)null) { return component2; } } } foreach (HachimiBoombox activeBoombox in HachimiBoombox.ActiveBoomboxes) { if ((Object)(object)activeBoombox != (Object)null && activeBoombox.IsLocalOwnedInInventory() && activeBoombox.IsPlaying) { return activeBoombox; } } foreach (HachimiBoombox activeBoombox2 in HachimiBoombox.ActiveBoomboxes) { if ((Object)(object)activeBoombox2 != (Object)null && activeBoombox2.IsLocalOwnedInInventory()) { return activeBoombox2; } } return null; } } public sealed class LyricLine { public float TimeSeconds; public string Text; } public sealed class TrackEntry { public string FilePath; public string FileName; public string Title; public AudioClip Clip; public bool IsLoading; public readonly List<LyricLine> Lyrics = new List<LyricLine>(); public string GetLyricAt(float timeSeconds) { TryGetLyricStateAt(timeSeconds, out var text, out var _); return text; } public bool TryGetLyricStateAt(float timeSeconds, out string text, out float progress) { text = string.Empty; progress = 0f; if (Lyrics.Count == 0) { return false; } int num = 0; int num2 = Lyrics.Count - 1; int num3 = -1; while (num <= num2) { int num4 = num + num2 >> 1; if (Lyrics[num4].TimeSeconds <= timeSeconds + 0.05f) { num3 = num4; num = num4 + 1; } else { num2 = num4 - 1; } } if (num3 < 0) { return false; } text = Lyrics[num3].Text; if (string.IsNullOrEmpty(text)) { return false; } float timeSeconds2 = Lyrics[num3].TimeSeconds; float num5 = ((num3 + 1 < Lyrics.Count) ? Mathf.Max(0.4f, Lyrics[num3 + 1].TimeSeconds - timeSeconds2) : 5f); if (num5 > 9f) { num5 = 9f; } progress = Mathf.Clamp01((timeSeconds - timeSeconds2) / num5); return true; } } public static class TrackLibrary { private sealed class PlaylistBucket { public readonly List<TrackEntry> All = new List<TrackEntry>(); public readonly List<TrackEntry> Shuffled = new List<TrackEntry>(); } public static readonly string[] CategoryKeys = new string[3] { "基米之声", "困の音箱", "infinity音箱" }; private static readonly Dictionary<string, PlaylistBucket> Buckets = new Dictionary<string, PlaylistBucket>(StringComparer.OrdinalIgnoreCase); private static readonly Dictionary<string, string> TitleMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); private static readonly Regex LrcTimeRegex = new Regex("\\[(\\d{1,3}):(\\d{1,2})(?:[\\.:](\\d{1,3}))?\\]", RegexOptions.Compiled); private static MonoBehaviour _runner; private static NetworkedEvent seedEvent; private static int currentSeed; private static bool hasSeed; private static bool loadingStarted; public static int CurrentSeed => currentSeed; public static bool IsLoaded { get; private set; } public static void Initialize(MonoBehaviour runner, string pluginDir) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown if (loadingStarted) { return; } loadingStarted = true; _runner = runner; seedEvent = new NetworkedEvent("HJM_HachimiMusic_Seed", (Action<EventData>)OnSeedEventReceived); string[] categoryKeys = CategoryKeys; foreach (string key in categoryKeys) { Buckets[key] = new PlaylistBucket(); } string text = Path.Combine(pluginDir, "CustomBoomboxMusic"); if (!Directory.Exists(text) && Directory.Exists(pluginDir)) { string[] directories = Directory.GetDirectories(pluginDir, "CustomBoomboxMusic", SearchOption.AllDirectories); if (directories.Length != 0) { text = directories[0]; } } string text2 = Path.Combine(pluginDir, "tracks.json"); if (!File.Exists(text2) && Directory.Exists(text)) { string text3 = Path.Combine(Path.GetDirectoryName(text) ?? pluginDir, "tracks.json"); if (File.Exists(text3)) { text2 = text3; } } LoadTrackTitles(text2); if (!Directory.Exists(text)) { Plugin.Log.LogWarning((object)("CustomBoomboxMusic directory not found: " + text)); IsLoaded = true; return; } int num = 0; categoryKeys = CategoryKeys; foreach (string text4 in categoryKeys) { string text5 = Path.Combine(text, text4); if (Directory.Exists(text5)) { num += ScanFolderIntoBucket(text5, Buckets[text4]); } } if (Directory.GetFiles(text, "*.ogg", SearchOption.TopDirectoryOnly).Length != 0) { num += ScanFolderIntoBucket(text, Buckets["基米之声"]); } ApplySeed(Environment.TickCount); IsLoaded = true; Plugin.Log.LogInfo((object)$"Indexed {num} .ogg tracks across 3 boomboxes (streaming on-demand)."); } private static int ScanFolderIntoBucket(string dir, PlaylistBucket bucket) { string[] files = Directory.GetFiles(dir, "*.ogg", SearchOption.TopDirectoryOnly); Array.Sort(files, (IComparer<string>?)StringComparer.OrdinalIgnoreCase); string[] array = files; foreach (string text in array) { string fileName = Path.GetFileName(text); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text); string value; string title = ((TitleMap.TryGetValue(fileName, out value) && !string.IsNullOrWhiteSpace(value)) ? value : fileNameWithoutExtension); TrackEntry trackEntry = new TrackEntry { FilePath = text, FileName = fileName, Title = title }; string text2 = Path.Combine(dir, fileNameWithoutExtension + ".lrc"); if (File.Exists(text2)) { ParseLrcFile(text2, trackEntry.Lyrics); } bucket.All.Add(trackEntry); } return files.Length; } private static void ParseLrcFile(string lrcPath, List<LyricLine> output) { try { string[] array = File.ReadAllLines(lrcPath, Encoding.UTF8); foreach (string text in array) { if (string.IsNullOrWhiteSpace(text)) { continue; } MatchCollection matchCollection = LrcTimeRegex.Matches(text); if (matchCollection.Count == 0) { continue; } int startIndex = matchCollection[matchCollection.Count - 1].Index + matchCollection[matchCollection.Count - 1].Length; string text2 = text.Substring(startIndex).Trim(); foreach (Match item in matchCollection) { if (!int.TryParse(item.Groups[1].Value, out var result) || !int.TryParse(item.Groups[2].Value, out var result2)) { continue; } float num = 0f; if (item.Groups[3].Success) { string value = item.Groups[3].Value; if (float.TryParse("0." + value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result3)) { num = result3; } } output.Add(new LyricLine { TimeSeconds = (float)result * 60f + (float)result2 + num, Text = text2 }); } } output.Sort((LyricLine a, LyricLine b) => a.TimeSeconds.CompareTo(b.TimeSeconds)); for (int num2 = output.Count - 1; num2 > 0; num2--) { if (Math.Abs(output[num2].TimeSeconds - output[num2 - 1].TimeSeconds) < 0.02f) { if (!string.IsNullOrEmpty(output[num2].Text)) { output[num2 - 1].Text = (string.IsNullOrEmpty(output[num2 - 1].Text) ? output[num2].Text : (output[num2 - 1].Text + "\n" + output[num2].Text)); } output.RemoveAt(num2); } } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Failed to parse LRC '" + lrcPath + "': " + ex.Message)); } } private static void LoadTrackTitles(string jsonPath) { if (!File.Exists(jsonPath)) { return; } try { foreach (Match item in Regex.Matches(File.ReadAllText(jsonPath), "\\{[^{}]*\\}", RegexOptions.Singleline)) { Match match = Regex.Match(item.Value, "\"title\"\\s*:\\s*\"((?:\\\\.|[^\"])*)\""); Match match2 = Regex.Match(item.Value, "\"file\"\\s*:\\s*\"((?:\\\\.|[^\"])*)\""); if (match.Success && match2.Success) { string key = Regex.Unescape(match2.Groups[1].Value); string value = Regex.Unescape(match.Groups[1].Value); TitleMap[key] = value; } } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Failed to parse tracks.json: " + ex.Message)); } } public static void RequestStreamClip(TrackEntry entry) { if (entry != null && !((Object)(object)entry.Clip != (Object)null) && !entry.IsLoading && !((Object)(object)_runner == (Object)null)) { entry.IsLoading = true; _runner.StartCoroutine(LoadSingleClipCoroutine(entry)); } } private static IEnumerator LoadSingleClipCoroutine(TrackEntry entry) { string absoluteUri = new Uri(entry.FilePath).AbsoluteUri; UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(absoluteUri, (AudioType)14); try { DownloadHandler downloadHandler = req.downloadHandler; DownloadHandlerAudioClip val = (DownloadHandlerAudioClip)(object)((downloadHandler is DownloadHandlerAudioClip) ? downloadHandler : null); if (val != null) { val.streamAudio = true; } yield return req.SendWebRequest(); entry.IsLoading = false; if ((int)req.result == 1) { AudioClip content = DownloadHandlerAudioClip.GetContent(req); if ((Object)(object)content != (Object)null) { ((Object)content).name = entry.Title; entry.Clip = content; } } else { Plugin.Log.LogWarning((object)("Failed to stream track '" + entry.FileName + "': " + req.error)); } } finally { ((IDisposable)req)?.Dispose(); } } public static void ReshuffleForRun() { //IL_003f: Unknown result type (might be due to invalid IL or missing references) if (SemiFunc.IsMasterClientOrSingleplayer()) { int hashCode = Guid.NewGuid().GetHashCode(); ApplySeed(hashCode); if (GameManager.Multiplayer() && seedEvent != null) { seedEvent.RaiseEvent((object)hashCode, NetworkingEvents.RaiseOthers, SendOptions.SendReliable); } } } private static void OnSeedEventReceived(EventData data) { if (data.CustomData is int seed) { ApplySeed(seed); } } public static void EnsureSeed(int seed) { if (!hasSeed || currentSeed != seed) { ApplySeed(seed); } } private static void ApplySeed(int seed) { currentSeed = seed; hasSeed = true; Random random = new Random(currentSeed); string[] categoryKeys = CategoryKeys; foreach (string key in categoryKeys) { if (Buckets.TryGetValue(key, out var value)) { value.Shuffled.Clear(); value.Shuffled.AddRange(value.All); for (int num = value.Shuffled.Count - 1; num > 0; num--) { int num2 = random.Next(num + 1); List<TrackEntry> shuffled = value.Shuffled; int index = num; List<TrackEntry> shuffled2 = value.Shuffled; int index2 = num2; TrackEntry value2 = value.Shuffled[num2]; TrackEntry value3 = value.Shuffled[num]; shuffled[index] = value2; shuffled2[index2] = value3; } } } } public static int GetTrackCount(string category) { if (string.IsNullOrEmpty(category) || !Buckets.TryGetValue(category, out var value)) { return 0; } if (value.Shuffled.Count <= 0) { return value.All.Count; } return value.Shuffled.Count; } public static TrackEntry GetTrack(string category, int index) { if (string.IsNullOrEmpty(category) || !Buckets.TryGetValue(category, out var value)) { return null; } List<TrackEntry> list = ((value.Shuffled.Count > 0) ? value.Shuffled : value.All); if (list.Count == 0) { return null; } int index2 = (index % list.Count + list.Count) % list.Count; return list[index2]; } public static int WrapIndex(string category, int index) { int trackCount = GetTrackCount(category); if (trackCount == 0) { return 0; } return (index % trackCount + trackCount) % trackCount; } public static int GetRandomIndex(string category, int currentIndex) { int trackCount = GetTrackCount(category); if (trackCount <= 1) { return 0; } int num = Random.Range(0, trackCount); if (num == currentIndex) { num = (num + 1) % trackCount; } return num; } } }