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 PlaceableRadio v1.3.4
plugins/PlaceableRadio/PlaceableRadio.dll
Decompiled 2 months agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using UnityEngine; using UnityEngine.Networking; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyFileVersion("1.3.4")] [assembly: AssemblyVersion("1.3.4.0")] namespace PlaceableRadio; [BepInPlugin("com.beverlo_hills.placeableradio", "Placeable Radio", "1.3.4")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public sealed class RadioPlugin : BaseUnityPlugin { public const string ModGuid = "com.beverlo_hills.placeableradio"; public const string ModName = "Placeable Radio"; public const string ModVersion = "1.3.4"; public const string PrefabName = "piece_placeable_radio"; internal static ConfigEntry<string> TrackDirectory; internal static ConfigEntry<float> AudibleDistance; internal static ConfigEntry<float> Volume; internal static string PluginDirectory; internal static ManualLogSource ModLogger; private static Material RadioBaseMaterial; private void Awake() { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Expected O, but got Unknown ModLogger = ((BaseUnityPlugin)this).Logger; PluginDirectory = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) ?? Paths.PluginPath; TrackDirectory = ((BaseUnityPlugin)this).Config.Bind<string>("Audio", "TrackDirectory", "Tracks", "Folder containing track01, track02 and subsequent MP3, OGG or WAV files. Relative paths are resolved from the mod folder."); AudibleDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "AudibleDistance", 25f, new ConfigDescription("Maximum distance at which the radio can be heard.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 100f), Array.Empty<object>())); Volume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "Volume", 0.7f, new ConfigDescription("Local playback volume.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); PrefabManager.OnPrefabsRegistered += RegisterRadio; } private void RegisterRadio() { //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: 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_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Expected O, but got Unknown PieceTable hammerPieceTable = GetHammerPieceTable(); Requirement val = CreateRequirement("FineWood", 10); Requirement val2 = CreateRequirement("Bronze", 2); Requirement val3 = CreateRequirement("SurtlingCore", 1); CraftingStation craftingStation = GetCraftingStation("piece_workbench"); if ((Object)(object)hammerPieceTable == (Object)null || val == null || val2 == null || val3 == null || (Object)(object)craftingStation == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"Radio registration prerequisites were unavailable after prefab registration."); return; } GameObject val4 = PrefabManager.Instance.CreateEmptyPrefab("piece_placeable_radio", true); if ((Object)(object)val4 == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"Could not create the radio prefab."); return; } Piece val5 = val4.AddComponent<Piece>(); val5.m_name = "Radio"; val5.m_description = "A radio that plays music for nearby Vikings."; val5.m_enabled = true; val5.m_category = (PieceCategory)4; val5.m_usage = (UsageTagFlags)129; val5.m_craftingStation = craftingStation; val5.m_resources = (Requirement[])(object)new Requirement[3] { val, val2, val3 }; val5.m_notOnTiltingSurface = true; RadioBaseMaterial = FindValheimPieceMaterial(); BuildRadioModel(val4); val4.AddComponent<RadioBehaviour>(); val5.m_icon = RenderManager.Instance.Render(val4, RenderManager.IsometricRotation); PrefabManager.Instance.AddPrefab(new CustomPrefab(val4, false)); PrefabManager.Instance.RegisterToZNetScene(val4); if (!hammerPieceTable.m_pieces.Contains(val4)) { hammerPieceTable.m_pieces.Add(val4); } PrefabManager.OnPrefabsRegistered -= RegisterRadio; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered the placeable radio using Valheim 1.0 native build tags."); } private static PieceTable GetHammerPieceTable() { GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab("Hammer") : PrefabManager.Instance.GetPrefab("Hammer")); ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null); return ((Object)(object)val2 != (Object)null) ? val2.m_itemData.m_shared.m_buildPieces : null; } private static CraftingStation GetCraftingStation(string prefabName) { GameObject prefab = PrefabManager.Instance.GetPrefab(prefabName); return ((Object)(object)prefab != (Object)null) ? prefab.GetComponent<CraftingStation>() : null; } private static Requirement CreateRequirement(string itemName, int amount) { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Expected O, but got Unknown GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(itemName) : PrefabManager.Instance.GetPrefab(itemName)); ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null); if ((Object)(object)val2 == (Object)null) { ModLogger.LogError((object)("Could not resolve build material: " + itemName)); return null; } return new Requirement { m_resItem = val2, m_amount = amount, m_recover = true }; } private static Material FindValheimPieceMaterial() { GameObject prefab = PrefabManager.Instance.GetPrefab("piece_chest_wood"); if ((Object)(object)prefab == (Object)null) { ModLogger.LogWarning((object)"Could not find the vanilla wooden chest material source."); return null; } Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true); Renderer[] array = componentsInChildren; foreach (Renderer val in array) { if ((Object)(object)val.sharedMaterial != (Object)null && (Object)(object)val.sharedMaterial.shader != (Object)null) { return val.sharedMaterial; } } ModLogger.LogWarning((object)"The vanilla wooden chest has no usable material."); return null; } private static void BuildRadioModel(GameObject prefab) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_008a: 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_00a1: Expected O, but got Unknown //IL_00bc: Unknown result type (might be due to invalid IL or missing references) Renderer component = prefab.GetComponent<Renderer>(); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } MeshFilter component2 = prefab.GetComponent<MeshFilter>(); if ((Object)(object)component2 != (Object)null) { Object.DestroyImmediate((Object)(object)component2); } Collider component3 = prefab.GetComponent<Collider>(); if ((Object)(object)component3 != (Object)null) { Object.DestroyImmediate((Object)(object)component3); } BoxCollider val = prefab.AddComponent<BoxCollider>(); val.center = new Vector3(0f, 0.43f, 0f); val.size = new Vector3(1.26f, 0.86f, 0.48f); GameObject val2 = new GameObject("Visual"); val2.transform.SetParent(prefab.transform, false); val2.transform.localPosition = Vector3.zero; BuildDirectRadioMesh(val2); } private static void BuildDirectRadioMesh(GameObject visual) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: 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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_0104: 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_011d: Unknown result type (might be due to invalid IL or missing references) //IL_013e: 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_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0178: 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_0191: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_02b8: Unknown result type (might be due to invalid IL or missing references) //IL_02cc: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_030a: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_0323: Unknown result type (might be due to invalid IL or missing references) //IL_0344: Unknown result type (might be due to invalid IL or missing references) //IL_0358: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_037e: Unknown result type (might be due to invalid IL or missing references) //IL_0392: Unknown result type (might be due to invalid IL or missing references) //IL_0397: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: Unknown result type (might be due to invalid IL or missing references) //IL_03cc: Unknown result type (might be due to invalid IL or missing references) //IL_03d1: Unknown result type (might be due to invalid IL or missing references) //IL_03f2: Unknown result type (might be due to invalid IL or missing references) //IL_0406: 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) //IL_042c: Unknown result type (might be due to invalid IL or missing references) //IL_0440: Unknown result type (might be due to invalid IL or missing references) //IL_0454: Unknown result type (might be due to invalid IL or missing references) //IL_0475: 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_049d: Unknown result type (might be due to invalid IL or missing references) //IL_04be: Unknown result type (might be due to invalid IL or missing references) //IL_04d2: Unknown result type (might be due to invalid IL or missing references) //IL_04d7: Unknown result type (might be due to invalid IL or missing references) //IL_04f8: Unknown result type (might be due to invalid IL or missing references) //IL_050c: Unknown result type (might be due to invalid IL or missing references) //IL_0520: Unknown result type (might be due to invalid IL or missing references) //IL_052f: Unknown result type (might be due to invalid IL or missing references) //IL_0534: Unknown result type (might be due to invalid IL or missing references) //IL_0542: Expected O, but got Unknown //IL_0575: Unknown result type (might be due to invalid IL or missing references) //IL_057a: Unknown result type (might be due to invalid IL or missing references) //IL_0586: Unknown result type (might be due to invalid IL or missing references) //IL_058e: Unknown result type (might be due to invalid IL or missing references) //IL_0598: Expected O, but got Unknown //IL_05ae: Unknown result type (might be due to invalid IL or missing references) //IL_05b3: Unknown result type (might be due to invalid IL or missing references) //IL_05bf: Unknown result type (might be due to invalid IL or missing references) //IL_05c0: Unknown result type (might be due to invalid IL or missing references) //IL_05cd: Expected O, but got Unknown Color[] array = (Color[])(object)new Color[8] { new Color(0.34f, 0.16f, 0.045f), new Color(0.12f, 0.055f, 0.018f), new Color(0.025f, 0.024f, 0.021f), new Color(0.11f, 0.095f, 0.07f), new Color(0.72f, 0.48f, 0.12f), new Color(0.55f, 0.32f, 0.08f), new Color(0.65f, 0.045f, 0.015f), new Color(0.38f, 0.38f, 0.34f) }; List<Vector3> vertices = new List<Vector3>(); List<int> list = new List<int>(); List<Vector2> list2 = new List<Vector2>(); AddMeshBox(vertices, list, list2, new Vector3(0f, 0.39f, 0f), new Vector3(1.2f, 0.7f, 0.42f), Quaternion.identity, 0, array.Length); AddMeshBox(vertices, list, list2, new Vector3(0f, 0.755f, 0f), new Vector3(1.25f, 0.06f, 0.46f), Quaternion.identity, 1, array.Length); AddMeshBox(vertices, list, list2, new Vector3(0f, 0.035f, 0f), new Vector3(1.25f, 0.06f, 0.46f), Quaternion.identity, 1, array.Length); AddMeshBox(vertices, list, list2, new Vector3(0f, 0.4f, -0.222f), new Vector3(1.08f, 0.56f, 0.025f), Quaternion.identity, 2, array.Length); AddMeshBox(vertices, list, list2, new Vector3(-0.34f, 0.4f, -0.25f), new Vector3(0.34f, 0.34f, 0.035f), Quaternion.identity, 3, array.Length); AddMeshBox(vertices, list, list2, new Vector3(0.34f, 0.4f, -0.25f), new Vector3(0.34f, 0.34f, 0.035f), Quaternion.identity, 3, array.Length); for (int i = -2; i <= 2; i++) { AddMeshBox(vertices, list, list2, new Vector3(-0.34f, 0.4f + (float)i * 0.055f, -0.275f), new Vector3(0.3f, 0.014f, 0.012f), Quaternion.identity, 4, array.Length); AddMeshBox(vertices, list, list2, new Vector3(0.34f, 0.4f + (float)i * 0.055f, -0.275f), new Vector3(0.3f, 0.014f, 0.012f), Quaternion.identity, 4, array.Length); } AddMeshBox(vertices, list, list2, new Vector3(0f, 0.56f, -0.25f), new Vector3(0.22f, 0.16f, 0.035f), Quaternion.identity, 4, array.Length); AddMeshBox(vertices, list, list2, new Vector3(0f, 0.56f, -0.273f), new Vector3(0.17f, 0.105f, 0.018f), Quaternion.identity, 5, array.Length); AddMeshBox(vertices, list, list2, new Vector3(-0.065f, 0.29f, -0.275f), new Vector3(0.09f, 0.09f, 0.04f), Quaternion.identity, 4, array.Length); AddMeshBox(vertices, list, list2, new Vector3(0.065f, 0.29f, -0.275f), new Vector3(0.09f, 0.09f, 0.04f), Quaternion.identity, 4, array.Length); AddMeshBox(vertices, list, list2, new Vector3(0f, 0.16f, -0.275f), new Vector3(0.045f, 0.045f, 0.025f), Quaternion.identity, 6, array.Length); AddMeshBox(vertices, list, list2, new Vector3(-0.39f, 0.88f, 0.02f), new Vector3(0.07f, 0.26f, 0.075f), Quaternion.Euler(0f, 0f, -16f), 1, array.Length); AddMeshBox(vertices, list, list2, new Vector3(0.39f, 0.88f, 0.02f), new Vector3(0.07f, 0.26f, 0.075f), Quaternion.Euler(0f, 0f, 16f), 1, array.Length); AddMeshBox(vertices, list, list2, new Vector3(0f, 0.99f, 0.02f), new Vector3(0.78f, 0.075f, 0.075f), Quaternion.identity, 1, array.Length); AddMeshBox(vertices, list, list2, new Vector3(0.48f, 1.08f, 0.06f), new Vector3(0.025f, 0.6f, 0.025f), Quaternion.Euler(0f, 0f, -10f), 7, array.Length); Mesh val = new Mesh { name = "PlaceableRadio_DirectMesh" }; val.SetVertices(vertices); val.SetTriangles(list, 0); val.SetUVs(0, list2); val.RecalculateNormals(); val.RecalculateBounds(); Texture2D val2 = new Texture2D(array.Length, 1, (TextureFormat)4, false) { name = "PlaceableRadio_Palette", filterMode = (FilterMode)0, wrapMode = (TextureWrapMode)1 }; val2.SetPixels(array); val2.Apply(); Material val3 = new Material(RadioBaseMaterial) { name = "PlaceableRadio_AtlasMaterial", color = Color.white }; if (val3.HasProperty("_MainTex")) { val3.SetTexture("_MainTex", (Texture)(object)val2); } if (val3.HasProperty("_BaseMap")) { val3.SetTexture("_BaseMap", (Texture)(object)val2); } visual.AddComponent<MeshFilter>().sharedMesh = val; ((Renderer)visual.AddComponent<MeshRenderer>()).sharedMaterial = val3; } private static void AddMeshBox(List<Vector3> vertices, List<int> triangles, List<Vector2> uvs, Vector3 center, Vector3 size, Quaternion rotation, int paletteIndex, int paletteSize) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002b: 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_0037: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005d: 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_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: 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_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: 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_00e1: 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_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) Vector3 val = size * 0.5f; Vector3[] array = (Vector3[])(object)new Vector3[8] { new Vector3(0f - val.x, 0f - val.y, 0f - val.z), new Vector3(val.x, 0f - val.y, 0f - val.z), new Vector3(val.x, val.y, 0f - val.z), new Vector3(0f - val.x, val.y, 0f - val.z), new Vector3(0f - val.x, 0f - val.y, val.z), new Vector3(val.x, 0f - val.y, val.z), new Vector3(val.x, val.y, val.z), new Vector3(0f - val.x, val.y, val.z) }; int[,] array2 = new int[6, 4] { { 0, 3, 2, 1 }, { 4, 5, 6, 7 }, { 4, 7, 3, 0 }, { 1, 2, 6, 5 }, { 3, 7, 6, 2 }, { 4, 0, 1, 5 } }; Vector2 item = default(Vector2); ((Vector2)(ref item))..ctor(((float)paletteIndex + 0.5f) / (float)paletteSize, 0.5f); for (int i = 0; i < 6; i++) { int count = vertices.Count; for (int j = 0; j < 4; j++) { vertices.Add(center + rotation * array[array2[i, j]]); uvs.Add(item); } triangles.Add(count); triangles.Add(count + 1); triangles.Add(count + 2); triangles.Add(count); triangles.Add(count + 2); triangles.Add(count + 3); } } private static void CreateSpeaker(Transform parent, float x, float y, Color face, Color hub, Color trim) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_0074: 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_008d: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) CreatePrimitive(parent, (x < 0f) ? "LeftSpeaker" : "RightSpeaker", (PrimitiveType)2, new Vector3(x, y, -0.257f), new Vector3(0.32f, 0.025f, 0.32f), face, Quaternion.Euler(90f, 0f, 0f)); CreatePrimitive(parent, (x < 0f) ? "LeftSpeakerHub" : "RightSpeakerHub", (PrimitiveType)2, new Vector3(x, y, -0.279f), new Vector3(0.105f, 0.025f, 0.105f), hub, Quaternion.Euler(90f, 0f, 0f)); for (int i = -2; i <= 2; i++) { float num = ((i == -2 || i == 2) ? 0.2f : 0.27f); CreatePrimitive(parent, ((x < 0f) ? "Left" : "Right") + "Grille" + i, (PrimitiveType)3, new Vector3(x, y + (float)i * 0.055f, -0.294f), new Vector3(num, 0.014f, 0.012f), trim); } } private static void BakeRadioModel(GameObject visual) { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: 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_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Expected O, but got Unknown //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Expected O, but got Unknown //IL_01e4: Unknown result type (might be due to invalid IL or missing references) MeshFilter[] componentsInChildren = visual.GetComponentsInChildren<MeshFilter>(true); Dictionary<Color, List<CombineInstance>> dictionary = new Dictionary<Color, List<CombineInstance>>(); Dictionary<Color, Material> dictionary2 = new Dictionary<Color, Material>(); MeshFilter[] array = componentsInChildren; foreach (MeshFilter val in array) { Renderer component = ((Component)val).GetComponent<Renderer>(); if (!((Object)(object)val.sharedMesh == (Object)null) && !((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMaterial == (Object)null)) { Color color = component.sharedMaterial.color; if (!dictionary.TryGetValue(color, out var value)) { value = new List<CombineInstance>(); dictionary.Add(color, value); dictionary2.Add(color, component.sharedMaterial); } List<CombineInstance> list = value; CombineInstance item = default(CombineInstance); ((CombineInstance)(ref item)).mesh = val.sharedMesh; ((CombineInstance)(ref item)).subMeshIndex = 0; ((CombineInstance)(ref item)).transform = visual.transform.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix; list.Add(item); } } MeshFilter[] array2 = componentsInChildren; foreach (MeshFilter val2 in array2) { Object.DestroyImmediate((Object)(object)((Component)val2).gameObject); } int num = 0; foreach (KeyValuePair<Color, List<CombineInstance>> item2 in dictionary) { GameObject val3 = new GameObject("BakedPart" + num++); val3.transform.SetParent(visual.transform, false); Mesh val4 = new Mesh { name = "PlaceableRadio_BakedPart" + num }; val4.CombineMeshes(item2.Value.ToArray(), true, true); val4.RecalculateBounds(); MeshFilter val5 = val3.AddComponent<MeshFilter>(); val5.sharedMesh = val4; MeshRenderer val6 = val3.AddComponent<MeshRenderer>(); ((Renderer)val6).sharedMaterial = dictionary2[item2.Key]; } } private static GameObject CreatePrimitive(Transform parent, string objectName, PrimitiveType type, Vector3 position, Vector3 scale, Color color, Quaternion? rotation = null) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0031: 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_004b: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown //IL_00f9: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.CreatePrimitive(type); ((Object)val).name = objectName; val.transform.SetParent(parent, false); val.transform.localPosition = position; val.transform.localScale = scale; val.transform.localRotation = (Quaternion)(((??)rotation) ?? Quaternion.identity); Collider component = val.GetComponent<Collider>(); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } Renderer component2 = val.GetComponent<Renderer>(); if ((Object)(object)component2 != (Object)null && (Object)(object)RadioBaseMaterial != (Object)null) { Material sharedMaterial = new Material(RadioBaseMaterial) { name = "PlaceableRadio_" + objectName, color = color }; component2.sharedMaterial = sharedMaterial; } else if ((Object)(object)component2 != (Object)null && (Object)(object)component2.material != (Object)null) { component2.material.color = color; } return val; } } public sealed class RadioBehaviour : MonoBehaviour, Hoverable, Interactable { private const string RpcToggle = "PlaceableRadio_Toggle"; private const string RpcAdvance = "PlaceableRadio_Advance"; private static readonly int PoweredKey = StringExtensionMethods.GetStableHashCode("PlaceableRadio_Powered"); private static readonly int TrackIndexKey = StringExtensionMethods.GetStableHashCode("PlaceableRadio_TrackIndex"); private ZNetView _networkView; private AudioSource _audioSource; private Material _indicatorMaterial; private readonly List<string> _trackPaths = new List<string>(); private readonly List<AudioClip> _tracks = new List<AudioClip>(); private bool _lastPowered; private bool _stateKnown; private bool _tracksLoaded; private bool _awaitingAdvance; private int _lastTrackIndex = -1; private float _nextStateCheck; private void Awake() { _networkView = ((Component)this).GetComponent<ZNetView>(); _audioSource = ((Component)this).gameObject.AddComponent<AudioSource>(); _audioSource.playOnAwake = false; _audioSource.loop = false; _audioSource.spatialBlend = 1f; _audioSource.rolloffMode = (AudioRolloffMode)1; _audioSource.minDistance = 2f; _audioSource.maxDistance = RadioPlugin.AudibleDistance.Value; _audioSource.volume = RadioPlugin.Volume.Value; _audioSource.dopplerLevel = 0f; Transform val = ((Component)this).transform.Find("Visual"); if ((Object)(object)val != (Object)null) { Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>(true); foreach (Renderer val2 in componentsInChildren) { Material[] materials = val2.materials; foreach (Material val3 in materials) { if ((Object)(object)val3 != (Object)null && ((Object)val3).name.StartsWith("PlaceableRadio_Indicator", StringComparison.Ordinal)) { _indicatorMaterial = val3; break; } } if ((Object)(object)_indicatorMaterial != (Object)null) { break; } } } if ((Object)(object)_networkView != (Object)null) { _networkView.Register("PlaceableRadio_Toggle", (Action<long>)ToggleRpc); _networkView.Register<int>("PlaceableRadio_Advance", (Action<long, int>)AdvanceRpc); } } private IEnumerator Start() { DiscoverTracks(); if (_trackPaths.Count == 0) { RadioPlugin.ModLogger.LogWarning((object)("No radio tracks found. Add track01.mp3, track02.mp3 and subsequent files to: " + GetTrackDirectory())); } else { if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsDedicated()) { yield break; } foreach (string trackPath in _trackPaths) { AudioType audioType = GetAudioType(trackPath); UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(new Uri(trackPath).AbsoluteUri, audioType); try { yield return request.SendWebRequest(); if ((int)request.result != 1) { RadioPlugin.ModLogger.LogError((object)("Could not load radio track " + trackPath + ": " + request.error)); yield break; } AudioClip clip = DownloadHandlerAudioClip.GetContent(request); ((Object)clip).name = Path.GetFileNameWithoutExtension(trackPath); _tracks.Add(clip); } finally { ((IDisposable)request)?.Dispose(); } } _tracksLoaded = true; ApplyNetworkState(ReadPoweredState(), ReadTrackIndex()); } } private void Update() { if (!(Time.time < _nextStateCheck)) { _nextStateCheck = Time.time + 0.25f; _audioSource.maxDistance = RadioPlugin.AudibleDistance.Value; _audioSource.volume = RadioPlugin.Volume.Value; bool flag = ReadPoweredState(); int num = ReadTrackIndex(); if (!_stateKnown || flag != _lastPowered || num != _lastTrackIndex) { ApplyNetworkState(flag, num); } if (flag && _tracksLoaded && _tracks.Count > 1 && (Object)(object)_audioSource.clip != (Object)null && !_audioSource.isPlaying && !_awaitingAdvance) { _awaitingAdvance = true; _networkView.InvokeRPC("PlaceableRadio_Advance", new object[1] { _lastTrackIndex }); } } } public string GetHoverName() { return "Radio"; } public float GetHoverOffset() { return 0.8f; } public string GetHoverText() { string text = (ReadPoweredState() ? "Turn off" : "Turn on"); return Localization.instance.Localize("Radio\n[<color=yellow><b>$KEY_Use</b></color>] " + text); } public bool Interact(Humanoid user, bool hold, bool alt) { if (hold || (Object)(object)_networkView == (Object)null || !_networkView.IsValid()) { return false; } _networkView.InvokeRPC("PlaceableRadio_Toggle", Array.Empty<object>()); return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } private void ToggleRpc(long sender) { if (!((Object)(object)_networkView == (Object)null) && _networkView.IsValid() && _networkView.IsOwner()) { bool flag = !ReadPoweredState(); _networkView.GetZDO().Set(PoweredKey, flag); if (flag && ReadTrackIndex() >= _trackPaths.Count) { _networkView.GetZDO().Set(TrackIndexKey, 0, false); } ApplyNetworkState(flag, ReadTrackIndex()); } } private void AdvanceRpc(long sender, int completedTrackIndex) { if (!((Object)(object)_networkView == (Object)null) && _networkView.IsValid() && _networkView.IsOwner() && ReadPoweredState() && _trackPaths.Count >= 2) { int num = ReadTrackIndex(); if (num == completedTrackIndex) { int num2 = (num + 1) % _trackPaths.Count; _networkView.GetZDO().Set(TrackIndexKey, num2, false); ApplyNetworkState(powered: true, num2); } } } private bool ReadPoweredState() { return (Object)(object)_networkView != (Object)null && _networkView.IsValid() && _networkView.GetZDO().GetBool(PoweredKey, false); } private int ReadTrackIndex() { if ((Object)(object)_networkView == (Object)null || !_networkView.IsValid() || _trackPaths.Count == 0) { return 0; } int num = _networkView.GetZDO().GetInt(TrackIndexKey, 0); return (num >= 0 && num < _trackPaths.Count) ? num : 0; } private void ApplyNetworkState(bool powered, int trackIndex) { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_004d: 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_006f: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: 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) bool flag = trackIndex != _lastTrackIndex; _lastPowered = powered; _lastTrackIndex = trackIndex; _stateKnown = true; _awaitingAdvance = false; if ((Object)(object)_indicatorMaterial != (Object)null) { Color val = (powered ? new Color(1f, 0.18f, 0.04f) : new Color(0.25f, 0.03f, 0.02f)); _indicatorMaterial.color = val; if (_indicatorMaterial.HasProperty("_EmissionColor")) { _indicatorMaterial.SetColor("_EmissionColor", powered ? (val * 1.5f) : Color.black); } } if (_tracksLoaded && trackIndex >= 0 && trackIndex < _tracks.Count) { if (flag || (Object)(object)_audioSource.clip == (Object)null) { _audioSource.Stop(); _audioSource.clip = _tracks[trackIndex]; _audioSource.loop = _tracks.Count == 1; } if (powered && !_audioSource.isPlaying) { _audioSource.Play(); } else if (!powered && _audioSource.isPlaying) { _audioSource.Stop(); } } } private void DiscoverTracks() { _trackPaths.Clear(); string trackDirectory = GetTrackDirectory(); if (!Directory.Exists(trackDirectory)) { return; } string[] files = Directory.GetFiles(trackDirectory); foreach (string text in files) { if (TryGetTrackNumber(text, out var _)) { _trackPaths.Add(text); } } _trackPaths.Sort(delegate(string left, string right) { TryGetTrackNumber(left, out var trackNumber2); TryGetTrackNumber(right, out var trackNumber3); int num = trackNumber2.CompareTo(trackNumber3); return (num != 0) ? num : string.Compare(left, right, StringComparison.OrdinalIgnoreCase); }); } private static string GetTrackDirectory() { string value = RadioPlugin.TrackDirectory.Value; return Path.IsPathRooted(value) ? value : Path.Combine(RadioPlugin.PluginDirectory, value); } private static bool TryGetTrackNumber(string path, out int trackNumber) { trackNumber = 0; string text = Path.GetExtension(path).ToLowerInvariant(); if (text != ".mp3" && text != ".ogg" && text != ".wav") { return false; } string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path); if (!fileNameWithoutExtension.StartsWith("track", StringComparison.OrdinalIgnoreCase) || fileNameWithoutExtension.Length <= 5) { return false; } return int.TryParse(fileNameWithoutExtension.Substring(5), out trackNumber) && trackNumber > 0; } private static AudioType GetAudioType(string path) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) return (AudioType)(Path.GetExtension(path).ToLowerInvariant() switch { ".mp3" => 13, ".ogg" => 14, ".wav" => 20, _ => 0, }); } }