Decompiled source of Crack Rave v1.0.0
BepInEx/plugins/CrackRave/CrackRave.dll
Decompiled 21 minutes ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Mirror; using UnityEngine; using UnityEngine.Audio; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.Networking; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyVersion("0.0.0.0")] [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 CrackRave { [HarmonyPatch(typeof(ConsoleApp), "ServerRun")] internal static class ConsoleDanceBreakPatch { private static readonly MethodInfo Literal = AccessTools.Method(typeof(ConsoleApp), "Literal", new Type[1] { typeof(string) }, (Type[])null); [HarmonyPrefix] private static bool Prefix(ConsoleApp __instance, string command) { if (command == null || !command.Trim().Equals("DANCEBREAK", StringComparison.OrdinalIgnoreCase)) { return true; } Literal?.Invoke(__instance, new object[1] { "FACS> " + command }); Literal?.Invoke(__instance, new object[1] { "DANCE BREAK AUTHORIZED. Lights down, glowsticks out." }); RavePlugin.TriggerFromConsole(); return false; } } [HarmonyPatch(typeof(ConsoleApp), "ServerHelp")] internal static class ConsoleDanceBreakHelpPatch { private static readonly MethodInfo HelpItem = AccessTools.Method(typeof(ConsoleApp), "HelpItem", new Type[2] { typeof(string), typeof(string) }, (Type[])null); [HarmonyPostfix] private static void Postfix(ConsoleApp __instance) { HelpItem?.Invoke(__instance, new object[2] { "DANCEBREAK", "Start a dance break." }); } } public sealed class RaveEvent : WorldEvent { protected override void OnServerBegin() { Debug.Log((object)"[Rave] RaveEvent began from the event rotation."); RavePlugin.TriggerFromEvent(); } protected override void OnServerEnd() { Debug.Log((object)"[Rave] RaveEvent ended."); RavePlugin.EndFromEvent(); } public override bool ServerCanRun() { return !RavePlugin.IsRaving; } public override void ServerTick() { if (!RavePlugin.IsRaving) { ((WorldEvent)this).ServerRequestEnd(); } } } [HarmonyPatch(typeof(EventDirector), "Awake")] internal static class RaveEventRegistration { internal static RaveEvent Instance; [HarmonyPostfix] private static void Postfix(EventDirector __instance) { //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || (Object)(object)EventDirector.instance != (Object)(object)__instance) { return; } FieldInfo fieldInfo = AccessTools.Field(typeof(EventDirector), "events"); WorldEvent[] array = fieldInfo?.GetValue(__instance) as WorldEvent[]; if (array == null) { return; } for (int i = 0; i < array.Length; i++) { if (array[i] is RaveEvent) { return; } } if (array.Length >= 32) { Debug.LogWarning((object)"[Rave] event list is full; rave not added to the rotation."); return; } GameObject val = new GameObject("Rave Event"); val.transform.SetParent(((Component)__instance).transform, false); RaveEvent raveEvent = val.AddComponent<RaveEvent>(); Set((WorldEvent)(object)raveEvent, "idOverride", "Rave"); Set((WorldEvent)(object)raveEvent, "schedulable", true); Set((WorldEvent)(object)raveEvent, "weight", 1f); Set((WorldEvent)(object)raveEvent, "minDay", 4); Set((WorldEvent)(object)raveEvent, "cooldownDays", 3); Set((WorldEvent)(object)raveEvent, "earliestHour", 10); Set((WorldEvent)(object)raveEvent, "latestHour", 18); Set((WorldEvent)(object)raveEvent, "requiresWorkPhase", true); Set((WorldEvent)(object)raveEvent, "minPlayers", 1); Set((WorldEvent)(object)raveEvent, "canOverlap", true); Set((WorldEvent)(object)raveEvent, "canBeOverlapped", true); Set((WorldEvent)(object)raveEvent, "dayEvent", false); Array.Resize(ref array, array.Length + 1); array[^1] = (WorldEvent)(object)raveEvent; fieldInfo.SetValue(__instance, array); Instance = raveEvent; Debug.Log((object)("[Rave] registered in the random event rotation (#" + (array.Length - 1) + ").")); } private static void Set(WorldEvent evt, string name, object value) { AccessTools.Field(typeof(WorldEvent), name)?.SetValue(evt, value); } } public static class RaveLightShow { private static GameObject _root; private static RaveSignShow _signs; private static RaveCartLights _carts; public static void Begin(bool signs, bool carts) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown End(); _root = new GameObject("RaveLightShow"); if (signs) { _signs = _root.AddComponent<RaveSignShow>(); _signs.Init(); } if (carts) { _carts = _root.AddComponent<RaveCartLights>(); _carts.Init(); } } public static void End() { _signs = null; _carts = null; if ((Object)(object)_root != (Object)null) { Object.Destroy((Object)(object)_root); _root = null; } } } public sealed class RaveSignShow : MonoBehaviour { private sealed class SignGroup { public readonly List<Renderer> Renderers = new List<Renderer>(); public Vector3 Center; public int Count; } private static readonly Color[][] Profiles = new Color[3][] { (Color[])(object)new Color[3] { new Color(1f, 0.03f, 0.02f), new Color(0.55f, 0.05f, 1f), new Color(0.05f, 0.2f, 1f) }, (Color[])(object)new Color[3] { new Color(1f, 0.05f, 0.75f), new Color(1f, 0.85f, 0.02f), new Color(1f, 0.9f, 0.85f) }, (Color[])(object)new Color[3] { new Color(0.2f, 1f, 0.05f), new Color(0.02f, 0.9f, 1f), new Color(0.05f, 0.2f, 1f) } }; private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor"); private readonly MaterialPropertyBlock _block = new MaterialPropertyBlock(); private List<SignGroup> _groups; private float _start; public void Init() { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_006b: 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_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) Renderer[] array = Object.FindObjectsByType<Renderer>((FindObjectsInactive)1, (FindObjectsSortMode)0); Dictionary<string, SignGroup> dictionary = new Dictionary<string, SignGroup>(); foreach (Renderer val in array) { if (!((Object)(object)val == (Object)null) && IsSignRenderer(val)) { Vector3 position = ((Component)val).transform.position; string key = Mathf.RoundToInt(position.x * 2f) + "_" + Mathf.RoundToInt(position.y * 2f) + "_" + Mathf.RoundToInt(position.z * 2f); if (!dictionary.TryGetValue(key, out var value)) { value = (dictionary[key] = new SignGroup()); } value.Renderers.Add(val); SignGroup signGroup2 = value; signGroup2.Center += position; value.Count++; } } _groups = new List<SignGroup>(); foreach (SignGroup value2 in dictionary.Values) { value2.Center /= (float)Mathf.Max(1, value2.Count); _groups.Add(value2); } _groups.Sort(delegate(SignGroup a, SignGroup b) { int num = a.Center.z.CompareTo(b.Center.z); return (num == 0) ? a.Center.x.CompareTo(b.Center.x) : num; }); _start = Time.time; Debug.Log((object)("[Rave] sign groups: " + _groups.Count)); } private static bool IsSignRenderer(Renderer renderer) { bool flag = false; Material[] sharedMaterials = renderer.sharedMaterials; foreach (Material val in sharedMaterials) { if ((Object)(object)val != (Object)null && (((Object)val).name.IndexOf("EmissiveSign", StringComparison.OrdinalIgnoreCase) >= 0 || ((Object)val).name.IndexOf("Sign", StringComparison.OrdinalIgnoreCase) >= 0)) { flag = true; break; } } if (!flag) { return false; } Transform val2 = ((Component)renderer).transform; while ((Object)(object)val2 != (Object)null) { string name = ((Object)val2).name; if (name.IndexOf("Ghost", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("GolfCart", StringComparison.OrdinalIgnoreCase) >= 0) { return false; } val2 = val2.parent; } return true; } private void Update() { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: 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_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0167: 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_017c: Unknown result type (might be due to invalid IL or missing references) if (_groups != null && _groups.Count != 0) { float num = Time.time - _start; int num2 = (int)(num / 20f) % Profiles.Length; float num3 = num % 20f; int num4 = Mathf.Clamp((int)(num3 / 6.6666665f), 0, 2); Color[] obj = Profiles[num2]; Color val = obj[num4]; Color val2 = obj[(num4 + 1) % 3]; int count = _groups.Count; int num5 = Mathf.FloorToInt(num3 * 2f); float intensity = 3f; int num6; if (num3 < 8f) { num6 = num5; } else if (num3 < 12f) { num6 = 16; intensity = 2.4f + 1.6f * (0.5f + 0.5f * Mathf.Sin(num3 * 10f)); } else if (num3 < 16f) { num6 = 16 - Mathf.FloorToInt((num3 - 12f) * 2f); } else { int num7 = Mathf.FloorToInt((num3 - 16f) * 2f); num6 = 16 + ((num7 % 2 != 0) ? Mathf.Max(1, count / 2) : 0); intensity = 2.2f + 1.4f * ((num5 % 2 == 0) ? 1f : 0f); } num6 = (num6 % count + count) % count; int num8 = Mathf.Min(3, count); for (int i = 0; i < count; i++) { Color color = ((((i - num6) % count + count) % count < num8) ? val : val2); SetGroup(_groups[i], color, intensity); } } } private void SetGroup(SignGroup group, Color color, float intensity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) Color val = color * intensity; for (int i = 0; i < group.Renderers.Count; i++) { Renderer val2 = group.Renderers[i]; if (!((Object)(object)val2 == (Object)null)) { val2.GetPropertyBlock(_block); _block.SetColor(EmissionColor, val); val2.SetPropertyBlock(_block); } } } private void OnDestroy() { if (_groups == null) { return; } for (int i = 0; i < _groups.Count; i++) { SignGroup signGroup = _groups[i]; for (int j = 0; j < signGroup.Renderers.Count; j++) { if ((Object)(object)signGroup.Renderers[j] != (Object)null) { signGroup.Renderers[j].SetPropertyBlock((MaterialPropertyBlock)null); } } } } } public sealed class RaveCartLights : MonoBehaviour { private readonly List<CartPoliceBar> _bars = new List<CartPoliceBar>(); public void Init() { MeshRenderer[] array = Object.FindObjectsByType<MeshRenderer>((FindObjectsInactive)0, (FindObjectsSortMode)0); int num = 0; foreach (MeshRenderer val in array) { if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).GetComponent<CartPoliceBar>() != (Object)null || !HasFlashBulb((Renderer)(object)val)) { continue; } num++; if (UnderGolfCart(((Component)val).transform) && !UnderGhost(((Component)val).transform)) { CartPoliceBar cartPoliceBar = ((Component)val).gameObject.AddComponent<CartPoliceBar>(); if (cartPoliceBar.Init(val)) { _bars.Add(cartPoliceBar); } else { Object.Destroy((Object)(object)cartPoliceBar); } } } Debug.Log((object)("[Rave] cart police bars: " + _bars.Count + " of " + num + " flash-bulb renderer(s).")); } private static bool UnderGolfCart(Transform t) { while ((Object)(object)t != (Object)null) { if (((Object)t).name.IndexOf("GolfCart", StringComparison.OrdinalIgnoreCase) >= 0) { return true; } t = t.parent; } return false; } private static bool UnderGhost(Transform t) { while ((Object)(object)t != (Object)null) { if (((Object)t).name.IndexOf("Ghost", StringComparison.OrdinalIgnoreCase) >= 0 || (Object)(object)((Component)t).GetComponent<PlacementGhost>() != (Object)null) { return true; } t = t.parent; } return false; } private static bool HasFlashBulb(Renderer renderer) { Material[] sharedMaterials = renderer.sharedMaterials; for (int i = 0; i < sharedMaterials.Length; i++) { if ((Object)(object)sharedMaterials[i] != (Object)null && ((Object)sharedMaterials[i]).name.IndexOf("FlashBulb", StringComparison.OrdinalIgnoreCase) >= 0) { return true; } } return false; } private void OnDestroy() { for (int i = 0; i < _bars.Count; i++) { if ((Object)(object)_bars[i] != (Object)null) { Object.Destroy((Object)(object)_bars[i]); } } } } public sealed class CartPoliceBar : MonoBehaviour { private enum Phase { Unknown = -1, Dark, Red, Blue } private sealed class SlotBackup { public int Index; public Material Original; } private static readonly Color Red = new Color(1f, 0.02f, 0.02f) * 20f; private static readonly Color Blue = new Color(0.03f, 0.12f, 1f) * 36f; private static readonly Color Off = new Color(0.02f, 0.02f, 0.02f); private const float CycleSeconds = 1f; private const float OnSeconds = 0.42f; private readonly List<SlotBackup> _slots = new List<SlotBackup>(); private readonly List<Material> _materials = new List<Material>(); private MeshRenderer _renderer; private Phase _phase = Phase.Unknown; public bool Init(MeshRenderer renderer) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Expected O, but got Unknown //IL_00b8: Unknown result type (might be due to invalid IL or missing references) _renderer = renderer; Material[] sharedMaterials = ((Renderer)renderer).sharedMaterials; for (int i = 0; i < sharedMaterials.Length; i++) { Material val = sharedMaterials[i]; if (!((Object)(object)val == (Object)null) && ((Object)val).name.IndexOf("FlashBulb", StringComparison.OrdinalIgnoreCase) >= 0) { if (!val.HasProperty("_OnColor") || !val.HasProperty("_Step")) { Debug.LogWarning((object)("[Rave] police bar: '" + ((Object)val).name + "' has no _OnColor/_Step; skipped.")); continue; } Material val2 = new Material(val) { name = ((Object)val).name + " (RavePolice)" }; val2.SetFloat("_CycleSpeed", 0f); val2.SetFloat("_Step", 1f); val2.SetColor("_OnColor", Off); _materials.Add(val2); Material[] array = (Material[])sharedMaterials.Clone(); array[i] = val2; ((Renderer)renderer).sharedMaterials = array; _slots.Add(new SlotBackup { Index = i, Original = val }); } } if (_slots.Count == 0) { return false; } Debug.Log((object)("[Rave] police bar on '" + ((Object)renderer).name + "': " + _slots.Count + " flash-bulb slot(s).")); return true; } private void Update() { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: 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) if (_materials.Count == 0) { return; } float num = Mathf.Repeat(Time.time, 1f); Phase phase; Color val; if (num < 0.42f) { phase = Phase.Red; val = Red; } else if (num < 0.5f) { phase = Phase.Dark; val = Off; } else if (num < 0.91999996f) { phase = Phase.Blue; val = Blue; } else { phase = Phase.Dark; val = Off; } if (phase == _phase) { return; } _phase = phase; for (int i = 0; i < _materials.Count; i++) { if ((Object)(object)_materials[i] != (Object)null) { _materials[i].SetColor("_OnColor", val); } } } private void OnDestroy() { if ((Object)(object)_renderer != (Object)null) { for (int i = 0; i < _slots.Count; i++) { SlotBackup slotBackup = _slots[i]; Material[] sharedMaterials = ((Renderer)_renderer).sharedMaterials; if (slotBackup.Index < sharedMaterials.Length) { sharedMaterials[slotBackup.Index] = slotBackup.Original; ((Renderer)_renderer).sharedMaterials = sharedMaterials; } } } _slots.Clear(); for (int j = 0; j < _materials.Count; j++) { if ((Object)(object)_materials[j] != (Object)null) { Object.Destroy((Object)(object)_materials[j]); } } _materials.Clear(); } } [BepInPlugin("Grokent.CrackRave", "Rave", "1.0.0")] public sealed class RavePlugin : BaseUnityPlugin { public const string Guid = "Grokent.CrackRave"; public const string Version = "1.0.0"; internal static RavePlugin Instance; internal static ManualLogSource Log; private static readonly string[] TrackFiles = new string[6] { "sunrise-trance-01.ogg", "sunrise-trance-02.ogg", "hardhouse-folk-01.ogg", "hardhouse-folk-02.ogg", "get-cracking.ogg", "morale-will-be-raised.ogg" }; private static readonly float[] TrackLengths = new float[6] { 186.9f, 183.8f, 156.6f, 176.95f, 214.4f, 219.96f }; private const float CrossfadeSeconds = 3f; private ConfigEntry<float> _duration; private ConfigEntry<int> _stickCount; private ConfigEntry<bool> _blackout; private ConfigEntry<float> _musicVolume; private ConfigEntry<float> _throwMultiplier; private ConfigEntry<bool> _trails; private ConfigEntry<float> _trailThickness; private ConfigEntry<bool> _signShow; private ConfigEntry<bool> _cartLights; private ConfigEntry<bool> _verbose; private ConfigEntry<bool> _testHotkeys; private bool _active; private bool _handlersRegistered; private Coroutine _timer; private byte _track; private int _lastTrack = -1; private readonly List<GameObject> _sticks = new List<GameObject>(); private readonly List<HatItem> _hats = new List<HatItem>(); private readonly List<GameObject> _dressing = new List<GameObject>(); private GameObject _raveTable; private const float MusicMuteDb = -79.5f; private static bool _musicSuppressed; private static bool _musicSaved; private static float _musicSavedValue; private float _nextVolumePoll; private AudioSource _sourceA; private AudioSource _sourceB; private AudioSource _activeSource; private Coroutine _musicLoad; private Coroutine _crossfade; private Coroutine _fade; private Coroutine _trackRoutine; private int _requestedTrack = -1; private int _activeTrack = -1; private static string PluginDirectory => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); internal static bool IsRaving { get { if ((Object)(object)Instance != (Object)null) { return Instance._active; } return false; } } private void Awake() { //IL_01d0: Unknown result type (might be due to invalid IL or missing references) Instance = this; Log = ((BaseUnityPlugin)this).Logger; _duration = ((BaseUnityPlugin)this).Config.Bind<float>("Rave", "DurationSeconds", 360f, "Event length in seconds."); _stickCount = ((BaseUnityPlugin)this).Config.Bind<int>("Rave", "Glowsticks", 8, "Number of glowsticks to spawn."); _blackout = ((BaseUnityPlugin)this).Config.Bind<bool>("Rave", "Blackout", true, "Cut the lights for the event."); _musicVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Rave", "MusicVolume", 0.65f, "Trim applied on top of the game's music/master volume settings (0..1)."); _throwMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Rave", "ThrowMultiplier", 3f, "Glowstick throw velocity multiplier."); _trails = ((BaseUnityPlugin)this).Config.Bind<bool>("Rave", "GlowTrails", true, "Give thrown glowsticks a colored trail."); _trailThickness = ((BaseUnityPlugin)this).Config.Bind<float>("Rave", "TrailThickness", 0.09f, "Thickness of each glowstick trail strand."); _signShow = ((BaseUnityPlugin)this).Config.Bind<bool>("Rave", "SignLightShow", true, "Animate the room signs during the rave."); _cartLights = ((BaseUnityPlugin)this).Config.Bind<bool>("Rave", "CartPoliceLights", true, "Flash the golf-cart roof light bars red/blue in a police wig-wag."); _verbose = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "VerboseLogging", false, "Log event details."); _testHotkeys = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableTestHotkeys", false, "Enable F10 (start) and F9 (end) test hotkeys for development."); GlowstickVisual.ThrowMultiplier = _throwMultiplier.Value; GlowstickVisual.TrailsEnabled = _trails.Value; GlowstickVisual.TrailWidth = Mathf.Clamp(_trailThickness.Value, 0.02f, 0.2f); new Harmony("Grokent.CrackRave").PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Rave loaded. Runs from the random event rotation, the lab console, or test hotkeys."); } private static void WriteState(NetworkWriter writer, RaveStateMessage message) { writer.WriteByte(message.state); writer.WriteByte(message.track); } private static RaveStateMessage ReadState(NetworkReader reader) { return new RaveStateMessage { state = reader.ReadByte(), track = reader.ReadByte() }; } private static void WriteVisual(NetworkWriter writer, RaveVisualMessage message) { NetworkWriterExtensions.WriteUInt(writer, message.netId); writer.WriteByte(message.color); writer.WriteByte(message.kind); } private static RaveVisualMessage ReadVisual(NetworkReader reader) { return new RaveVisualMessage { netId = NetworkReaderExtensions.ReadUInt(reader), color = reader.ReadByte(), kind = reader.ReadByte() }; } private void EnsureHandlers() { if (!NetworkClient.active) { _handlersRegistered = false; } else if (!_handlersRegistered) { Writer<RaveStateMessage>.write = WriteState; Reader<RaveStateMessage>.read = ReadState; Writer<RaveVisualMessage>.write = WriteVisual; Reader<RaveVisualMessage>.read = ReadVisual; NetworkClient.RegisterHandler<RaveStateMessage>((Action<RaveStateMessage>)OnRaveState, false); NetworkClient.RegisterHandler<RaveVisualMessage>((Action<RaveVisualMessage>)OnRaveVisual, false); _handlersRegistered = true; ManualLogSource log = Log; if (log != null) { log.LogInfo((object)"[Rave] network handlers registered."); } } } private void Update() { EnsureHandlers(); PollMusicVolume(); if (!_testHotkeys.Value || Keyboard.current == null) { return; } if (((ButtonControl)Keyboard.current.f10Key).wasPressedThisFrame) { if (_active) { ManualLogSource log = Log; if (log != null) { log.LogInfo((object)"[Rave] already running; F9 ends it."); } } else if (NetworkServer.active) { bool flag = (Object)(object)RaveEventRegistration.Instance != (Object)null; bool flag2 = (Object)(object)EventDirector.instance != (Object)null; ManualLogSource log2 = Log; if (log2 != null) { log2.LogInfo((object)("[Rave] F10 test path: event=" + flag + " director=" + flag2)); } if (flag && flag2) { EventDirector.instance.ServerForceRun((WorldEvent)(object)RaveEventRegistration.Instance, false); } else { StartRave(); } } else { ManualLogSource log3 = Log; if (log3 != null) { log3.LogWarning((object)"[Rave] F10 only works on the host/server."); } } } if (((ButtonControl)Keyboard.current.f9Key).wasPressedThisFrame && _active) { if ((Object)(object)RaveEventRegistration.Instance != (Object)null && (Object)(object)EventDirector.instance != (Object)null) { EventDirector.instance.ServerEnd((WorldEvent)(object)RaveEventRegistration.Instance); } else { EndRave("F9"); } } } private void StartRave() { //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) if (_active || !NetworkServer.active) { return; } PlayerController[] array = Object.FindObjectsByType<PlayerController>((FindObjectsInactive)0, (FindObjectsSortMode)0); if (array.Length == 0) { ManualLogSource log = Log; if (log != null) { log.LogWarning((object)"[Rave] no player found; the event needs a player position."); } return; } _active = true; int num = Random.Range(0, TrackFiles.Length); if (TrackFiles.Length > 1 && num == _lastTrack) { num = (num + Random.Range(1, TrackFiles.Length)) % TrackFiles.Length; } _lastTrack = num; _track = (byte)num; SetBlackout(_blackout.Value); NetworkServer.SendToAll<RaveStateMessage>(new RaveStateMessage { state = 1, track = _track }, 0, false); if (IsLocalHost()) { StartMusic(_track); } EnsureTable(); SetMusicSuppressed(suppressed: true); RaveRadio.SetMuted(muted: true); SpawnSticks(((Component)array[0]).transform.position); SpawnHats(((Component)array[0]).transform.position); if (NetworkServer.active) { RaveTentacleShow.BeginServer(_duration.Value); } if (IsLocalHost()) { RaveTentacleShow.BeginLocal(); } RaveScannerShow.BeginServer(); if (IsLocalHost()) { RaveScannerShow.BeginLocal(); } _timer = ((MonoBehaviour)this).StartCoroutine(TimerRoutine()); _trackRoutine = ((MonoBehaviour)this).StartCoroutine(TrackRoutine()); ManualLogSource log2 = Log; if (log2 != null) { log2.LogInfo((object)("[Rave] started: " + _sticks.Count + " glowstick(s), " + _hats.Count + " necklace(s), track " + (_track + 1) + ".")); } } private IEnumerator TimerRoutine() { yield return (object)new WaitForSeconds(_duration.Value); _timer = null; if (_active) { EndRave("timer"); } } private void EndRave(string reason) { if (!_active) { return; } _active = false; if (_timer != null) { ((MonoBehaviour)this).StopCoroutine(_timer); _timer = null; } if (_trackRoutine != null) { ((MonoBehaviour)this).StopCoroutine(_trackRoutine); _trackRoutine = null; } NetworkServer.SendToAll<RaveStateMessage>(new RaveStateMessage { state = 0, track = _track }, 0, false); if (IsLocalHost()) { StopMusic(fade: true); } SetMusicSuppressed(suppressed: false); RaveRadio.SetMuted(muted: false); ReleaseTable(); for (int i = 0; i < _sticks.Count; i++) { if ((Object)(object)_sticks[i] != (Object)null) { NetworkServer.Destroy(_sticks[i]); } } _sticks.Clear(); PlayerHatWearer[] array = Object.FindObjectsByType<PlayerHatWearer>((FindObjectsInactive)0, (FindObjectsSortMode)0); for (int j = 0; j < _hats.Count; j++) { HatItem val = _hats[j]; if ((Object)(object)val == (Object)null) { continue; } bool flag = false; for (int k = 0; k < array.Length; k++) { if ((Object)(object)array[k] != (Object)null && (Object)(object)array[k].ServerWornHat == (Object)(object)val) { array[k].ServerDestroyWornHat(); flag = true; break; } } if (!flag) { NetworkServer.Destroy(((Component)val).gameObject); } } _hats.Clear(); SweepVisuals(); RaveLightShow.End(); RaveTentacleShow.End(server: true); RaveScannerShow.End(); SetBlackout(on: false); ManualLogSource log = Log; if (log != null) { log.LogInfo((object)("[Rave] ended (" + reason + ").")); } } private void EnsureTable() { //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: 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_0157: Unknown result type (might be due to invalid IL or missing references) PizzaPartyEvent[] array = Object.FindObjectsByType<PizzaPartyEvent>((FindObjectsInactive)1, (FindObjectsSortMode)0); if (array.Length == 0 || !(AccessTools.Field(typeof(PizzaPartyEvent), "dressing")?.GetValue(array[0]) is GameObject[] array2)) { return; } foreach (GameObject val in array2) { if (!((Object)(object)val == (Object)null) && !val.activeSelf && ((Object)val).name.IndexOf("Table", StringComparison.OrdinalIgnoreCase) >= 0) { val.SetActive(true); _dressing.Add(val); ManualLogSource log = Log; if (log != null) { log.LogInfo((object)("[Rave] enabled table dressing: " + ((Object)val).name)); } } } if (!((Object)(object)_raveTable == (Object)null) || array2.Length == 0) { return; } foreach (GameObject val2 in array2) { if (!((Object)(object)val2 == (Object)null) && ((Object)val2).name.IndexOf("Table", StringComparison.OrdinalIgnoreCase) >= 0) { _raveTable = Object.Instantiate<GameObject>(val2); ((Object)_raveTable).name = "Rave Glow Table"; Transform transform = _raveTable.transform; transform.SetParent(val2.transform.parent, true); float num = 2.15f; BoxCollider component = val2.GetComponent<BoxCollider>(); if ((Object)(object)component != (Object)null) { num = component.size.z * Mathf.Abs(val2.transform.lossyScale.z); } transform.position = val2.transform.position + val2.transform.forward * (num * 2f); transform.rotation = val2.transform.rotation; _raveTable.SetActive(true); ManualLogSource log2 = Log; if (log2 != null) { log2.LogInfo((object)"[Rave] spawned necklace table beside the pizza table."); } break; } } } private void ReleaseTable() { if ((Object)(object)_raveTable != (Object)null) { Object.Destroy((Object)(object)_raveTable); _raveTable = null; } for (int i = 0; i < _dressing.Count; i++) { if ((Object)(object)_dressing[i] != (Object)null && ((Object)_dressing[i]).name.IndexOf("Table", StringComparison.OrdinalIgnoreCase) >= 0) { _dressing[i].SetActive(false); } } _dressing.Clear(); } private static AudioMixer GetMixer() { SettingsManager val = Object.FindFirstObjectByType<SettingsManager>(); if (!((Object)(object)val == (Object)null)) { object? obj = AccessTools.Field(typeof(SettingsManager), "mixer")?.GetValue(val); return (AudioMixer)((obj is AudioMixer) ? obj : null); } return null; } private static float ReadMixerDb(AudioMixer mixer, string parameter, float fallback) { float result = default(float); if (!((Object)(object)mixer != (Object)null) || !mixer.GetFloat(parameter, ref result)) { return fallback; } return result; } private float EffectiveMusicVolume() { AudioMixer mixer = GetMixer(); float num = (_musicSuppressed ? _musicSavedValue : ReadMixerDb(mixer, "MusicVolume", 0f)); float num2 = ReadMixerDb(mixer, "MasterVolume", 0f); return _musicVolume.Value * Mathf.Pow(10f, (num + num2) / 20f); } private void PollMusicVolume() { if (!_active || !_musicSuppressed || Time.time < _nextVolumePoll) { return; } _nextVolumePoll = Time.time + 0.5f; AudioMixer mixer = GetMixer(); float num = default(float); if (!((Object)(object)mixer == (Object)null) && mixer.GetFloat("MusicVolume", ref num) && !(Mathf.Abs(num - -79.5f) < 0.01f)) { _musicSavedValue = num; _musicSaved = true; mixer.SetFloat("MusicVolume", -79.5f); ApplyMusicVolume(); ManualLogSource log = Log; if (log != null) { log.LogInfo((object)("[Rave] music volume changed: " + EffectiveMusicVolume().ToString("0.00") + ".")); } } } private void ApplyMusicVolume() { float volume = EffectiveMusicVolume(); if ((Object)(object)_activeSource != (Object)null && _activeSource.isPlaying) { _activeSource.volume = volume; } if (_crossfade == null && _fade == null) { if ((Object)(object)_sourceA != (Object)null && _sourceA.isPlaying) { _sourceA.volume = volume; } if ((Object)(object)_sourceB != (Object)null && _sourceB.isPlaying) { _sourceB.volume = volume; } } } private static void SetMusicSuppressed(bool suppressed) { if (_musicSuppressed == suppressed) { return; } AudioMixer mixer = GetMixer(); if ((Object)(object)mixer == (Object)null) { VerboseStatic("[Rave] no audio mixer found for music suppression."); return; } if (suppressed) { float musicSavedValue = default(float); if (mixer.GetFloat("MusicVolume", ref musicSavedValue)) { _musicSavedValue = musicSavedValue; _musicSaved = true; } mixer.SetFloat("MusicVolume", -79.5f); ManualLogSource log = Log; if (log != null) { log.LogInfo((object)("[Rave] game music muted (player music level " + _musicSavedValue.ToString("0.0") + " dB).")); } } else { if (_musicSaved) { mixer.SetFloat("MusicVolume", _musicSavedValue); _musicSaved = false; } ManualLogSource log2 = Log; if (log2 != null) { log2.LogInfo((object)"[Rave] game music restored."); } } _musicSuppressed = suppressed; if ((Object)(object)Instance != (Object)null) { Instance.ApplyMusicVolume(); } } private static void VerboseStatic(string message) { if ((Object)(object)Instance != (Object)null && Instance._verbose.Value) { ManualLogSource log = Log; if (log != null) { log.LogInfo((object)message); } } } private void SpawnSticks(Vector3 basePosition) { //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0145: 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_014f: Unknown result type (might be due to invalid IL or missing references) //IL_00df: 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_00ee: 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_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0183: 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_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_0166: 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_0175: 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_01b0: 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) GameObject val = FindPrefab("PF_Item_Flashlight") ?? FindPrefab("PF_Item_Lantern"); if ((Object)(object)val == (Object)null) { ManualLogSource log = Log; if (log != null) { log.LogError((object)"[Rave] could not find a flashlight/lantern prefab for glowsticks."); } return; } int num = Mathf.Max(1, _stickCount.Value); List<int> list = new List<int>(); for (int i = 0; i < RavePalette.Colors.Length; i++) { list.Add(i); } for (int num2 = list.Count - 1; num2 > 0; num2--) { int index = Random.Range(0, num2 + 1); int value = list[num2]; list[num2] = list[index]; list[index] = value; } List<Vector3> stickPoints; List<Vector3> hatPoints; bool flag = TryGetTablePoints(out stickPoints, out hatPoints); List<Vector3> list2 = (flag ? PickPoints(stickPoints, num) : null); RaycastHit val3 = default(RaycastHit); for (int j = 0; j < num; j++) { Vector3 val2; if (flag) { val2 = list2[j] + Vector3.up * 0.06f; } else { float num3 = MathF.PI * 2f * (float)j / (float)num; val2 = basePosition + new Vector3(Mathf.Cos(num3) * 1.15f, 0f, Mathf.Sin(num3) * 1.15f); val2 = ((!Physics.Raycast(val2 + Vector3.up * 2f, Vector3.down, ref val3, 6f, -1, (QueryTriggerInteraction)1)) ? (basePosition + new Vector3(Mathf.Cos(num3) * 1.15f, 0.6f, Mathf.Sin(num3) * 1.15f)) : (((RaycastHit)(ref val3)).point + Vector3.up * 0.35f)); } GameObject val4 = Object.Instantiate<GameObject>(val, val2, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f)); HeldItem component = val4.GetComponent<HeldItem>(); if (component != null) { component.ServerExemptFromSave(); } NetworkServer.Spawn(val4, (NetworkConnectionToClient)null); _sticks.Add(val4); byte b = (byte)list[j % list.Count]; NetworkIdentity component2 = val4.GetComponent<NetworkIdentity>(); if ((Object)(object)component2 != (Object)null) { NetworkServer.SendToAll<RaveVisualMessage>(new RaveVisualMessage { netId = component2.netId, color = b, kind = 0 }, 0, false); } if (IsLocalHost()) { GlowstickVisual.Attach(val4, b); } } ManualLogSource log2 = Log; if (log2 != null) { log2.LogInfo((object)("[Rave] glowsticks spawned " + (flag ? "on the pizza table" : "around the player"))); } } private void SpawnHats(Vector3 basePosition) { //IL_00b2: 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_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_0087: 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_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009b: 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_00df: 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) GameObject val = FindPrefab("PF_Hat_Party"); if ((Object)(object)val == (Object)null) { ManualLogSource log = Log; if (log != null) { log.LogError((object)"[Rave] could not find PF_Hat_Party."); } return; } int num = RavePalette.Colors.Length; List<Vector3> stickPoints; List<Vector3> hatPoints; bool flag = TryGetTablePoints(out stickPoints, out hatPoints); List<Vector3> list = GetRaveTablePoints(); if (list.Count == 0) { list = ((hatPoints.Count > 0) ? hatPoints : stickPoints); } List<Vector3> list2 = ((flag && list.Count > 0) ? PickPoints(list, num) : null); for (int i = 0; i < num; i++) { Vector3 val2; if (flag) { val2 = list2[i] + Vector3.up * 0.06f; } else { float num2 = MathF.PI * 2f * (float)i / (float)num; val2 = basePosition + new Vector3(Mathf.Cos(num2) * 1.15f, 0.6f, Mathf.Sin(num2) * 1.15f); } GameObject val3 = Object.Instantiate<GameObject>(val, val2, Quaternion.identity); NetworkServer.Spawn(val3, (NetworkConnectionToClient)null); HatItem component = val3.GetComponent<HatItem>(); if ((Object)(object)component == (Object)null) { ManualLogSource log2 = Log; if (log2 != null) { log2.LogWarning((object)"[Rave] spawned hat has no HatItem; skipping."); } NetworkServer.Destroy(val3); continue; } _hats.Add(component); byte b = (byte)i; NetworkIdentity component2 = val3.GetComponent<NetworkIdentity>(); if ((Object)(object)component2 != (Object)null) { NetworkServer.SendToAll<RaveVisualMessage>(new RaveVisualMessage { netId = component2.netId, color = b, kind = 1 }, 0, false); } if (IsLocalHost()) { NecklaceVisual.Attach(val3, b); } } ManualLogSource log3 = Log; if (log3 != null) { log3.LogInfo((object)("[Rave] necklaces spawned " + (flag ? "on the separate rave table" : "around the player"))); } } private List<Vector3> GetRaveTablePoints() { //IL_004b: Unknown result type (might be due to invalid IL or missing references) List<Vector3> list = new List<Vector3>(); if ((Object)(object)_raveTable == (Object)null) { return list; } Transform[] componentsInChildren = _raveTable.GetComponentsInChildren<Transform>(true); for (int i = 0; i < componentsInChildren.Length; i++) { if ((Object)(object)componentsInChildren[i] != (Object)null && ((Object)componentsInChildren[i]).name.StartsWith("PizzaSpawn", StringComparison.OrdinalIgnoreCase)) { list.Add(componentsInChildren[i].position); } } return list; } private static List<Vector3> PickPoints(List<Vector3> source, int count) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) List<Vector3> list = new List<Vector3>(source); for (int num = list.Count - 1; num > 0; num--) { int index = Random.Range(0, num + 1); Vector3 value = list[num]; list[num] = list[index]; list[index] = value; } if (list.Count >= count) { return list.GetRange(0, count); } return ExpandPoints(list, count, 0.16f); } private static bool TryGetTablePoints(out List<Vector3> stickPoints, out List<Vector3> hatPoints) { //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) stickPoints = new List<Vector3>(); hatPoints = new List<Vector3>(); PizzaPartyEvent[] array = Object.FindObjectsByType<PizzaPartyEvent>((FindObjectsInactive)1, (FindObjectsSortMode)0); if (array.Length == 0) { return false; } PizzaPartyEvent val = array[0]; PizzaPlace[] array2 = AccessTools.FieldRefAccess<PizzaPartyEvent, PizzaPlace[]>("pizzaPoints").Invoke(val); Transform[] array3 = AccessTools.FieldRefAccess<PizzaPartyEvent, Transform[]>("hatPoints").Invoke(val); if (array2 != null) { for (int i = 0; i < array2.Length; i++) { if ((Object)(object)array2[i].point != (Object)null) { stickPoints.Add(array2[i].point.position); } } } if (array3 != null) { for (int j = 0; j < array3.Length; j++) { if ((Object)(object)array3[j] != (Object)null) { hatPoints.Add(array3[j].position); } } } if (stickPoints.Count == 0 && hatPoints.Count > 0) { stickPoints.AddRange(hatPoints); } if (hatPoints.Count == 0 && stickPoints.Count > 0) { hatPoints.AddRange(stickPoints); } return stickPoints.Count > 0; } private static List<Vector3> ExpandPoints(List<Vector3> source, int count, float offset) { //IL_0014: 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) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) List<Vector3> list = new List<Vector3>(count); for (int i = 0; i < count; i++) { Vector3 val = source[i % source.Count]; int num = i / source.Count; if (num > 0) { val += new Vector3(offset * (float)num, 0f, 0f); } list.Add(val); } return list; } internal static void TriggerFromEvent() { if ((Object)(object)Instance != (Object)null) { Instance.StartRave(); } } internal static void EndFromEvent() { if ((Object)(object)Instance != (Object)null && Instance._active) { Instance.EndRave("event"); } } public static void TriggerFromConsole() { if ((Object)(object)Instance == (Object)null) { return; } if (Instance._active) { ManualLogSource log = Log; if (log != null) { log.LogInfo((object)"[Rave] dance break already active."); } } else { Instance.StartRave(); } } private static GameObject FindPrefab(string name) { foreach (KeyValuePair<uint, GameObject> prefab in NetworkClient.prefabs) { if ((Object)(object)prefab.Value != (Object)null && ((Object)prefab.Value).name == name) { return prefab.Value; } } GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>(); for (int i = 0; i < array.Length; i++) { if ((Object)(object)array[i] != (Object)null && ((Object)array[i]).name == name) { return array[i]; } } return null; } private static void DestroyVisual(GameObject go) { NetworkIdentity component = go.GetComponent<NetworkIdentity>(); if (NetworkServer.active && (Object)(object)component != (Object)null && component.netId != 0) { NetworkServer.Destroy(go); } else { Object.Destroy((Object)(object)go); } } private void SetBlackout(bool on) { PowerCutController[] array = Object.FindObjectsByType<PowerCutController>((FindObjectsInactive)0, (FindObjectsSortMode)0); if (array.Length != 0) { array[0].SetReason((PowerCutReason)1, on); } else { Verbose("[Rave] no PowerCutController found"); } } private void OnRaveState(RaveStateMessage message) { if (!NetworkClient.active) { return; } if (message.state == 1) { SetBlackout(_blackout.Value); if (_signShow.Value || _cartLights.Value) { RaveLightShow.Begin(_signShow.Value, _cartLights.Value); } RaveTentacleShow.BeginLocal(); RaveScannerShow.BeginLocal(); StartMusic(message.track); EnsureTable(); SetMusicSuppressed(suppressed: true); RaveRadio.SetMuted(muted: true); } else if (message.state == 2) { CrossfadeTo(message.track); } else { RaveLightShow.End(); RaveTentacleShow.End(server: false); RaveScannerShow.End(); SetBlackout(on: false); StopMusic(fade: true); SetMusicSuppressed(suppressed: false); RaveRadio.SetMuted(muted: false); ReleaseTable(); SweepVisuals(); } } private static void SweepVisuals() { NecklaceVisual[] array = Object.FindObjectsByType<NecklaceVisual>((FindObjectsInactive)1, (FindObjectsSortMode)0); for (int i = 0; i < array.Length; i++) { if ((Object)(object)array[i] != (Object)null) { DestroyVisual(((Component)array[i]).gameObject); } } GlowstickVisual[] array2 = Object.FindObjectsByType<GlowstickVisual>((FindObjectsInactive)1, (FindObjectsSortMode)0); for (int j = 0; j < array2.Length; j++) { if ((Object)(object)array2[j] != (Object)null) { DestroyVisual(((Component)array2[j]).gameObject); } } } private void OnRaveVisual(RaveVisualMessage message) { if (NetworkClient.active) { if (!NetworkClient.spawned.TryGetValue(message.netId, out var value) || (Object)(object)value == (Object)null) { Verbose("[Rave] visual message for missing netId " + message.netId); } else if (message.kind == 0) { GlowstickVisual.Attach(((Component)value).gameObject, message.color); } else { NecklaceVisual.Attach(((Component)value).gameObject, message.color); } } } private static bool IsLocalHost() { if (NetworkServer.listen) { return NetworkClient.active; } return true; } private void EnsureSources() { if ((Object)(object)_sourceA == (Object)null) { _sourceA = CreateSource("RaveMusicA"); } if ((Object)(object)_sourceB == (Object)null) { _sourceB = CreateSource("RaveMusicB"); } } private AudioSource CreateSource(string name) { //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) GameObject val = new GameObject(name); val.transform.SetParent(((Component)this).transform, false); AudioSource obj = val.AddComponent<AudioSource>(); obj.playOnAwake = false; obj.loop = true; obj.spatialBlend = 0f; obj.volume = 0f; return obj; } private void StartMusic(byte track) { if (NetworkClient.active && _requestedTrack != track) { StopMusic(fade: false); EnsureSources(); _requestedTrack = track; _activeTrack = track; _activeSource = _sourceA; _musicLoad = ((MonoBehaviour)this).StartCoroutine(LoadInto(_sourceA, track)); } } private IEnumerator LoadInto(AudioSource source, byte track) { AudioClip clip = null; yield return LoadClip(track, delegate(AudioClip c) { clip = c; }); if (!((Object)(object)clip == (Object)null) && !((Object)(object)source == (Object)null)) { source.clip = clip; source.volume = EffectiveMusicVolume(); source.Play(); _musicLoad = null; ManualLogSource log = Log; if (log != null) { log.LogInfo((object)("[Rave] music playing: " + TrackFiles[Mathf.Clamp((int)track, 0, TrackFiles.Length - 1)])); } } } private IEnumerator LoadClip(byte track, Action<AudioClip> result) { int num = Mathf.Clamp((int)track, 0, TrackFiles.Length - 1); string text = Path.Combine(PluginDirectory, "audio", TrackFiles[num]); if (!File.Exists(text)) { ManualLogSource log = Log; if (log != null) { log.LogError((object)("[Rave] music file missing: " + text)); } yield break; } string absoluteUri = new Uri(Path.GetFullPath(text)).AbsoluteUri; UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(absoluteUri, (AudioType)14); try { yield return request.SendWebRequest(); if ((int)request.result != 1) { ManualLogSource log2 = Log; if (log2 != null) { log2.LogError((object)("[Rave] music load failed: " + request.error)); } yield break; } AudioClip content = DownloadHandlerAudioClip.GetContent(request); if ((Object)(object)content == (Object)null) { ManualLogSource log3 = Log; if (log3 != null) { log3.LogError((object)"[Rave] music decode failed."); } yield break; } result?.Invoke(content); } finally { ((IDisposable)request)?.Dispose(); } } private void CrossfadeTo(byte track) { if (!NetworkClient.active || _requestedTrack == track) { return; } EnsureSources(); if ((Object)(object)_activeSource == (Object)null || !_activeSource.isPlaying) { _requestedTrack = -1; StartMusic(track); return; } AudioSource next = (((Object)(object)_activeSource == (Object)(object)_sourceA) ? _sourceB : _sourceA); if (_musicLoad != null) { ((MonoBehaviour)this).StopCoroutine(_musicLoad); _musicLoad = null; } if (_crossfade != null) { ((MonoBehaviour)this).StopCoroutine(_crossfade); _crossfade = null; } _requestedTrack = track; _activeTrack = track; _musicLoad = ((MonoBehaviour)this).StartCoroutine(LoadCrossfade(next, track)); } private IEnumerator LoadCrossfade(AudioSource next, byte track) { AudioClip clip = null; yield return LoadClip(track, delegate(AudioClip c) { clip = c; }); if ((Object)(object)clip == (Object)null || (Object)(object)next == (Object)null) { _musicLoad = null; yield break; } next.clip = clip; next.volume = 0f; next.Play(); _musicLoad = null; _crossfade = ((MonoBehaviour)this).StartCoroutine(CrossfadeRoutine(next)); } private IEnumerator CrossfadeRoutine(AudioSource next) { AudioSource old = _activeSource; float t = 0f; while (t < 3f && (Object)(object)next != (Object)null) { t += Time.deltaTime; float num = Mathf.Clamp01(t / 3f); float num2 = EffectiveMusicVolume(); next.volume = num2 * num; if ((Object)(object)old != (Object)null) { old.volume = num2 * (1f - num); } yield return null; } if ((Object)(object)old != (Object)null) { old.Stop(); old.clip = null; old.volume = EffectiveMusicVolume(); } if ((Object)(object)next != (Object)null) { next.volume = EffectiveMusicVolume(); } _activeSource = next; _activeTrack = _requestedTrack; _crossfade = null; } private void StopMusic(bool fade) { if (_musicLoad != null) { ((MonoBehaviour)this).StopCoroutine(_musicLoad); _musicLoad = null; } if (_crossfade != null) { ((MonoBehaviour)this).StopCoroutine(_crossfade); _crossfade = null; } if (_fade != null) { ((MonoBehaviour)this).StopCoroutine(_fade); _fade = null; } if ((Object)(object)_activeSource == (Object)null || !_activeSource.isPlaying) { StopSources(); return; } _requestedTrack = -1; if (fade) { _fade = ((MonoBehaviour)this).StartCoroutine(FadeOutRoutine()); } else { StopSources(); } } private void StopSources() { if ((Object)(object)_sourceA != (Object)null) { _sourceA.Stop(); _sourceA.clip = null; } if ((Object)(object)_sourceB != (Object)null) { _sourceB.Stop(); _sourceB.clip = null; } _activeTrack = -1; _activeSource = null; } private IEnumerator FadeOutRoutine() { AudioSource source = _activeSource; float start = (((Object)(object)source != (Object)null) ? source.volume : 0f); float time = 0f; while (time < 3f && (Object)(object)source != (Object)null) { time += Time.deltaTime; source.volume = Mathf.Lerp(start, 0f, time / 3f); yield return null; } StopSources(); _fade = null; } private IEnumerator TrackRoutine() { while (_active) { int num = Mathf.Clamp((int)_track, 0, TrackLengths.Length - 1); float num2 = TrackLengths[num]; yield return (object)new WaitForSeconds(Mathf.Max(1f, num2 - 3f - 0.2f)); if (!_active) { break; } int num3 = Random.Range(0, TrackFiles.Length); if (TrackFiles.Length > 1 && num3 == _track) { num3 = (num3 + 1) % TrackFiles.Length; } _track = (byte)num3; NetworkServer.SendToAll<RaveStateMessage>(new RaveStateMessage { state = 2, track = _track }, 0, false); if (IsLocalHost()) { CrossfadeTo(_track); } } } private void Verbose(string message) { if (_verbose != null && _verbose.Value) { ManualLogSource log = Log; if (log != null) { log.LogInfo((object)message); } } } } public struct RaveStateMessage : NetworkMessage { public byte state; public byte track; } public struct RaveVisualMessage : NetworkMessage { public uint netId; public byte color; public byte kind; } public static class RaveRadio { [HarmonyPatch(typeof(Radio), "ApplyVolume")] internal static class RadioVolumePatch { [HarmonyPostfix] private static void Postfix(Radio __instance) { if (Suppressed) { object? obj = SourceField?.GetValue(__instance); AudioSource val = (AudioSource)((obj is AudioSource) ? obj : null); if (val != null) { val.volume = 0f; } } } } internal static bool Suppressed; private static readonly FieldInfo SourceField = AccessTools.Field(typeof(Radio), "source"); private static readonly MethodInfo ApplyMethod = AccessTools.Method(typeof(Radio), "ApplyVolume", (Type[])null, (Type[])null); public static void SetMuted(bool muted) { Suppressed = muted; Radio[] array = Object.FindObjectsByType<Radio>((FindObjectsInactive)1, (FindObjectsSortMode)0); for (int i = 0; i < array.Length; i++) { if ((Object)(object)array[i] == (Object)null) { continue; } if (ApplyMethod != null) { ApplyMethod.Invoke(array[i], null); continue; } object? obj = SourceField?.GetValue(array[i]); AudioSource val = (AudioSource)((obj is AudioSource) ? obj : null); if (val != null && muted) { val.volume = 0f; } } Debug.Log((object)("[Rave] radios " + (muted ? "muted" : "restored") + " (" + array.Length + ").")); } } public static class RaveScannerShow { private static GameObject _serverRoot; private static GameObject _localRoot; public static void BeginServer() { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown if (NetworkServer.active && !((Object)(object)_serverRoot != (Object)null)) { ScannerRig val = ScannerRig.instance; if ((Object)(object)val == (Object)null) { val = Object.FindFirstObjectByType<ScannerRig>(); } if ((Object)(object)val == (Object)null) { Debug.Log((object)"[Rave] no ScannerRig in the scene; scanner show skipped."); return; } _serverRoot = new GameObject("RaveScannerAim"); _serverRoot.AddComponent<RaveScannerAim>().Init(val); Debug.Log((object)"[Rave] scanner aim director started."); } } public static void BeginLocal() { //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown if ((Object)(object)_localRoot != (Object)null) { return; } ScannerArm val = Object.FindFirstObjectByType<ScannerArm>(); if ((Object)(object)val == (Object)null) { Debug.Log((object)"[Rave] no ScannerArm in the scene; laser show skipped."); return; } object? obj = AccessTools.Field(typeof(ScannerArm), "lens")?.GetValue(val); Transform val2 = (Transform)((obj is Transform) ? obj : null); if ((Object)(object)val2 == (Object)null) { Debug.Log((object)"[Rave] scanner has no lens transform; laser show skipped."); return; } _localRoot = new GameObject("RaveScannerLaser"); _localRoot.AddComponent<RaveScannerLaser>().Init(val2); ScannerArm[] arms = Object.FindObjectsByType<ScannerArm>((FindObjectsInactive)0, (FindObjectsSortMode)0); _localRoot.AddComponent<RaveScannerNoise>().Init(arms); Debug.Log((object)"[Rave] scanner laser show started."); } public static void End() { if ((Object)(object)_serverRoot != (Object)null) { Object.Destroy((Object)(object)_serverRoot); _serverRoot = null; } if ((Object)(object)_localRoot != (Object)null) { Object.Destroy((Object)(object)_localRoot); _localRoot = null; } } } public sealed class RaveScannerAim : MonoBehaviour { private ScannerRig _rig; private float _time; private float _nextLog; public void Init(ScannerRig rig) { _rig = rig; } private void Update() { if (!((Object)(object)_rig == (Object)null) && NetworkServer.active) { float deltaTime = Time.deltaTime; float num = 24f * deltaTime; float num2 = Mathf.Cos(_time * 0.45f) * 0.055f * deltaTime; _rig.ServerDriveAim(num, num2, 0f, 0f, false); _time += deltaTime; if (Time.time >= _nextLog) { _nextLog = Time.time + 5f; Debug.Log((object)("[Rave] scanner aim az=" + _rig.Azimuth.ToString("0") + " lat=" + _rig.Latitude.ToString("0.00"))); } } } } public sealed class RaveScannerNoise : MonoBehaviour { private sealed class Saved { public BotMotorLoop Loop; public Vector2 Range; } private readonly List<Saved> _saved = new List<Saved>(); private static readonly FieldInfo RangeField = AccessTools.Field(typeof(BotMotorLoop), "volumeRange"); public void Init(ScannerArm[] arms) { for (int i = 0; i < arms.Length; i++) { if (!((Object)(object)arms[i] == (Object)null)) { object? obj = AccessTools.Field(typeof(ScannerArm), "rotateLoop")?.GetValue(arms[i]); Lower((BotMotorLoop)((obj is BotMotorLoop) ? obj : null)); object? obj2 = AccessTools.Field(typeof(ScannerArm), "liftLoop")?.GetValue(arms[i]); Lower((BotMotorLoop)((obj2 is BotMotorLoop) ? obj2 : null)); } } Debug.Log((object)("[Rave] scanner motor volume at 10% (" + _saved.Count + " loops).")); } private void Lower(BotMotorLoop loop) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)loop == (Object)null) && !(RangeField == null)) { Vector2 val = (Vector2)RangeField.GetValue(loop); _saved.Add(new Saved { Loop = loop, Range = val }); RangeField.SetValue(loop, val * 0.1f); } } private void OnDestroy() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < _saved.Count; i++) { Saved saved = _saved[i]; if ((Object)(object)saved.Loop != (Object)null) { RangeField.SetValue(saved.Loop, saved.Range); } } Debug.Log((object)("[Rave] scanner motor volume restored (" + _saved.Count + " loops).")); _saved.Clear(); } } public sealed class RaveScannerLaser : MonoBehaviour { private enum Pattern { Fan, Grid, FigureEight, Spread, Floor } private enum Tint { Rainbow, Green, Blue, White } private readonly struct Mode { public readonly Pattern Pattern; public readonly Tint Tint; public Mode(Tint tint, Pattern pattern) { Tint = tint; Pattern = pattern; } } private sealed class Beam { public LineRenderer Line; public Material Material; } private static readonly Mode[] Modes = new Mode[8] { new Mode(Tint.Rainbow, Pattern.Fan), new Mode(Tint.Green, Pattern.Grid), new Mode(Tint.Blue, Pattern.FigureEight), new Mode(Tint.White, Pattern.Spread), new Mode(Tint.Green, Pattern.Floor), new Mode(Tint.Blue, Pattern.Spread), new Mode(Tint.White, Pattern.Fan), new Mode(Tint.Green, Pattern.FigureEight) }; private static readonly float[] SpreadYaw = new float[6] { -85f, -62f, -40f, 40f, 62f, 85f }; private static readonly float[] SpreadPitch = new float[4] { -32f, -11f, 11f, 32f }; private const int FanBeams = 11; private const int GridSide = 5; private const int GridBeams = 25; private const int FloorBeams = 11; private const int TotalBeams = 30; private const float ModeSeconds = 9f; private Transform _lens; private Transform _orb; private Material _material; private readonly List<Beam> _beams = new List<Beam>(); private float _time; private int _lastMode = -1; private static readonly Color Green = new Color(0.06f, 1f, 0.18f); private static readonly Color Blue = new Color(0.1f, 0.3f, 1f); private static readonly Color White = new Color(1f, 1f, 1f); public void Init(Transform lens) { //IL_0071: 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_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Expected O, but got Unknown _lens = lens; _material = MakeLaserMaterial(); Debug.Log((object)("[Rave] laser material shader: " + (((Object)(object)_material != (Object)null && (Object)(object)_material.shader != (Object)null) ? ((Object)_material.shader).name : "missing"))); for (int i = 0; i < 30; i++) { GameObject val = new GameObject("Laser" + i); val.transform.SetParent(((Component)this).transform, false); LineRenderer val2 = val.AddComponent<LineRenderer>(); val2.useWorldSpace = true; val2.positionCount = 2; val2.startWidth = 0.055f; val2.endWidth = 0.022f; val2.numCapVertices = 2; val2.numCornerVertices = 2; val2.alignment = (LineAlignment)0; val2.textureMode = (LineTextureMode)0; ((Renderer)val2).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)val2).receiveShadows = false; Material material = (((Renderer)val2).sharedMaterial = new Material(_material)); ((Renderer)val2).enabled = false; _beams.Add(new Beam { Line = val2, Material = material }); } AddLensGlow(); } private void AddLensGlow() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: 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_0093: 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_00bc: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("LensGlow"); val.transform.SetParent(_lens, false); Light obj = val.AddComponent<Light>(); obj.type = (LightType)2; obj.color = new Color(0.35f, 0.9f, 1f); obj.range = 6f; obj.intensity = 3f; obj.shadows = (LightShadows)0; GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)0); Object.Destroy((Object)(object)val2.GetComponent<Collider>()); ((Object)val2).name = "LensOrb"; val2.transform.SetParent(((Component)this).transform, false); val2.transform.localScale = Vector3.one * 0.1f; ((Renderer)val2.GetComponent<MeshRenderer>()).sharedMaterial = GlowstickVisual.MakeMaterial(new Color(0.4f, 0.95f, 1f), emissive: true, null); _orb = val2.transform; } private void Update() { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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_006b: 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_010e: 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_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012e: 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_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_042d: Unknown result type (might be due to invalid IL or missing references) //IL_042e: Unknown result type (might be due to invalid IL or missing references) //IL_0433: Unknown result type (might be due to invalid IL or missing references) //IL_0438: Unknown result type (might be due to invalid IL or missing references) //IL_0448: Unknown result type (might be due to invalid IL or missing references) //IL_044a: Unknown result type (might be due to invalid IL or missing references) //IL_044f: 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_0289: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_029e: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02a4: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: Unknown result type (might be due to invalid IL or missing references) //IL_02aa: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_0318: Unknown result type (might be due to invalid IL or missing references) //IL_031a: Unknown result type (might be due to invalid IL or missing references) //IL_0321: 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_0328: Unknown result type (might be due to invalid IL or missing references) //IL_032d: Unknown result type (might be due to invalid IL or missing references) //IL_032e: Unknown result type (might be due to invalid IL or missing references) //IL_0333: Unknown result type (might be due to invalid IL or missing references) //IL_0338: Unknown result type (might be due to invalid IL or missing references) //IL_0339: 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_03df: Unknown result type (might be due to invalid IL or missing references) //IL_03e1: Unknown result type (might be due to invalid IL or missing references) //IL_03e8: Unknown result type (might be due to invalid IL or missing references) //IL_03ea: Unknown result type (might be due to invalid IL or missing references) //IL_03ef: Unknown result type (might be due to invalid IL or missing references) //IL_03f4: Unknown result type (might be due to invalid IL or missing references) //IL_03f5: 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_03ff: Unknown result type (might be due to invalid IL or missing references) //IL_0400: 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_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: 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_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_04cd: 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_04d9: Unknown result type (might be due to invalid IL or missing references) //IL_04de: Unknown result type (might be due to invalid IL or missing references) //IL_04e0: Unknown result type (might be due to invalid IL or missing references) //IL_04ef: Unknown result type (might be due to invalid IL or missing references) //IL_04f4: Unknown result type (might be due to invalid IL or missing references) //IL_0506: Unknown result type (might be due to invalid IL or missing references) //IL_050b: Unknown result type (might be due to invalid IL or missing references) //IL_0510: Unknown result type (might be due to invalid IL or missing references) //IL_0514: Unknown result type (might be due to invalid IL or missing references) //IL_0519: Unknown result type (might be due to invalid IL or missing references) //IL_051e: Unknown result type (might be due to invalid IL or missing references) //IL_051f: Unknown result type (might be due to invalid IL or missing references) //IL_052a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_lens == (Object)null) { return; } _time += Time.deltaTime; if ((Object)(object)_orb != (Object)null) { _orb.position = _lens.position + _lens.forward * 0.05f; _orb.rotation = _lens.rotation; } int num = Mathf.FloorToInt(_time / 9f) % Modes.Length; if (num != _lastMode) { _lastMode = num; Debug.Log((object)("[Rave] laser mode: " + Modes[num].Tint.ToString() + " " + Modes[num].Pattern)); } Mode mode = Modes[num]; Vector3 origin = _lens.position + _lens.forward * 0.15f; Vector3 forward = _lens.forward; Vector3 right = _lens.right; Vector3 up = _lens.up; int num2 = 0; switch (mode.Pattern) { case Pattern.Fan: { num2 = 11; for (int l = 0; l < num2; l++) { float num14 = ((num2 == 1) ? 0.5f : ((float)l / (float)(num2 - 1))); float num15 = Mathf.Lerp(-55f, 55f, num14) + Mathf.Sin(_time * 1.2f) * 12f; float num16 = Mathf.Sin(_time * 2.1f + (float)l * 0.8f) * 9f; Vector3 dir3 = Quaternion.AngleAxis(num15, up) * Quaternion.AngleAxis(num16, right) * forward; Draw(l, origin, dir3, BeamColor(mode.Tint, l)); } break; } case Pattern.Grid: { num2 = 25; for (int k = 0; k < num2; k++) { int num10 = k % 5; int num11 = k / 5; float num12 = (float)(num10 - 2) * 11f + Mathf.Sin(_time * 0.8f) * 9f; float num13 = (float)(num11 - 2) * 6.5f + Mathf.Cos(_time * 0.65f) * 5f; Vector3 dir2 = Quaternion.AngleAxis(num12, up) * Quaternion.AngleAxis(num13, right) * forward; Draw(k, origin, dir2, BeamColor(mode.Tint, k)); } break; } case Pattern.FigureEight: { num2 = 3; float num6 = _time * 1.25f; for (int j = 0; j < num2; j++) { float num7 = num6 + (float)j * 0.055f; float num8 = Mathf.Sin(num7) * 38f; float num9 = Mathf.Sin(num7 * 2f) * 20f; Vector3 dir = Quaternion.AngleAxis(num8, up) * Quaternion.AngleAxis(num9, right) * forward; Draw(j, origin, dir, BeamColor(mode.Tint, j)); } break; } case Pattern.Spread: { num2 = Mathf.Min(30, SpreadYaw.Length * SpreadPitch.Length); for (int m = 0; m < num2; m++) { float num17 = SpreadYaw[m % SpreadYaw.Length] + Mathf.Sin(_time * 0.7f + (float)m) * 8f; float num18 = SpreadPitch[m / SpreadYaw.Length] + Mathf.Cos(_time * 0.9f + (float)m * 0.4f) * 6f; Vector3 dir4 = Quaternion.AngleAxis(num17, up) * Quaternion.AngleAxis(num18, right) * forward; Draw(m, origin, dir4, BeamColor(mode.Tint, m)); } break; } case Pattern.Floor: { num2 = 11; Vector3 val = Vector3.ProjectOnPlane(forward, Vector3.up); if (((Vector3)(ref val)).sqrMagnitude < 0.0001f) { val = Vector3.ProjectOnPlane(right, Vector3.up); } ((Vector3)(ref val)).Normalize(); for (int i = 0; i < num2; i++) { float num3 = ((num2 == 1) ? 0.5f : ((float)i / (float)(num2 - 1))); float num4 = Mathf.Lerp(-80f, 80f, num3) + Mathf.Sin(_time * 0.6f) * 18f; float num5 = 32f + Mathf.Sin(_time * 0.9f + num3 * 2.5f) * 12f; Vector3 val2 = Quaternion.AngleAxis(num4, Vector3.up) * val; Vector3 val3 = val2 * Mathf.Cos(num5 * (MathF.PI / 180f)) + Vector3.down * Mathf.Sin(num5 * (MathF.PI / 180f)); val2 = ((Vector3)(ref val3)).normalized; Draw(i, origin, val2, BeamColor(mode.Tint, i)); } break; } } for (int n = num2; n < _beams.Count; n++) { ((Renderer)_beams[n].Line).enabled = false; } } private Color BeamColor(Tint tint, int index) { //IL_0016: 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) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) switch (tint) { case Tint.Green: return Green; case Tint.Blue: return Blue; case Tint.White: return White; default: { int num = (index + Mathf.FloorToInt(_time * 0.35f)) % RavePalette.Colors.Length; return RavePalette.Colors[num]; } } } private void Draw(int index, Vector3 origin, Vector3 dir, Color color) { //IL_000c: 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_000e: 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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0045: 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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) Beam beam = _beams[index]; Vector3 val = Raycast(origin, dir); beam.Line.SetPosition(0, origin); beam.Line.SetPosition(1, val); ((Renderer)beam.Line).enabled = true; beam.Material.SetColor("_BaseColor", color); beam.Material.SetColor("_Color", color); beam.Line.startColor = new Color(1f, 1f, 1f, 0.95f); beam.Line.endColor = new Color(1f, 1f, 1f, 0.08f); } private static Vector3 Raycast(Vector3 origin, Vector3 dir) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) RaycastHit val = default(RaycastHit); if (Physics.Raycast(origin, dir, ref val, 60f, -1, (QueryTriggerInteraction)1)) { return ((RaycastHit)(ref val)).point; } return origin + dir * 45f; } private static Material MakeLaserMaterial() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_0088: 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) Shader val = Shader.Find("Universal Render Pipeline/Particles/Unlit"); if ((Object)(object)val == (Object)null) { val = Shader.Find("Universal Render Pipeline/Unlit"); } Material val2; if ((Object)(object)val != (Object)null) { val2 = new Material(val); val2.SetFloat("_Surface", 1f); val2.SetFloat("_Blend", 2f); val2.SetFloat("_SrcBlend", 1f); val2.SetFloat("_DstBlend", 1f); val2.SetFloat("_ZWrite", 0f); val2.SetColor("_BaseColor", Color.white); val2.SetColor("_Color", Color.white); val2.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); val2.renderQueue = 3000; } else { val2 = GlowstickVisual.MakeTrailMaterial(); } return val2; } } public static class RaveTentacleShow { private sealed class TentacleStarter : MonoBehaviour { private TentacleEvent _evt; private EventDirector _director; private float _deadline; public void Setup(TentacleEvent evt, EventDirector director) { _evt = evt; _director = director; _deadline = Time.time + 10f; } private void Update() { if ((Object)(object)_evt == (Object)null || (Object)(object)_director == (Object)null) { Object.Destroy((Object)(object)this); } else if (((WorldEvent)_evt).IsRunning) { Object.Destroy((Object)(object)this); } else if (Time.time > _deadline) { Debug.Log((object)"[Rave] tentacle event could not start (no usable egg recesses?)."); Object.Destroy((Object)(object)this); } else if (((WorldEvent)_evt).ServerCanRun()) { _director.ServerForceRun((WorldEvent)(object)_evt, false); Debug.Log((object)"[Rave] tentacle event started non-aggressively."); Object.Destroy((Object)(object)this); } } } private static TentacleEvent _event; private static bool _serverStarted; private static GameObject _localRoot; public static void BeginServer(float duration) { //IL_0089: Unknown result type (might be due to invalid IL or missing references) if (!NetworkServer.active || _serverStarted) { return; } TentacleEvent[] array = Object.FindObjectsByType<TentacleEvent>((FindObjectsInactive)1, (FindObjectsSortMode)0); if (array.Length == 0) { Debug.Log((object)"[Rave] no TentacleEvent in scene; skipping tentacles."); return; } _event = array[0]; AccessTools.FieldRefAccess<TentacleEvent, bool>("grabEnabled").Invoke(_event) = false; AccessTools.FieldRefAccess<TentacleEvent, float>("lifetimeSeconds").Invoke(_event) = Mathf.Max(30f, duration); _serverStarted = true; EventDirector val = Object.FindFirstObjectByType<EventDirector>(); if ((Object)(object)val == (Object)null) { Debug.Log((object)"[Rave] no EventDirector; skipping tentacles."); } else { new GameObject("RaveTentacleStarter").AddComponent<TentacleStarter>().Setup(_event, val); } } public static void BeginLocal() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown if (NetworkClient.active && !((Object)(object)_localRoot != (Object)null)) { _localRoot = new GameObject("RaveTentacleGlow"); _localRoot.AddComponent<TentacleGlowManager>(); } } public static void End(bool server) { if (server && (Object)(object)_event != (Object)null && NetworkServer.active) { EventDirector val = Object.FindFirstObjectByType<EventDirector>(); if ((Object)(object)val != (Object)null) { val.ServerEnd((WorldEvent)(object)_event); } } _event = null; _serverStarted = false; if ((Object)(object)_localRoot != (Object)null) { Object.Destroy((Object)(object)_localRoot); _localRoot = null; } } } public sealed class TentacleGlowManager : MonoBehaviour { private float _nextScan; private int _counter; private readonly List<GameObject> _glows = new List<GameObject>(); private void Update() { //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown if (Time.time < _nextScan) { return; } _nextScan = Time.time + 0.5f; Tentacle[] array = Object.FindObjectsByType<Tentacle>((FindObjectsInactive)0, (FindObjectsSortMode)0); foreach (Tentacle val in array) { if (!((Object)(object)val == (Object)null) && !((Object)(object)val.Tip == (Object)null) && !((Object)(object)((Component)val).GetComponentInChildren<TipGlow>(true) != (Object)null)) { GameObject val2 = new GameObject("RaveTipGlow"); val2.transform.SetParent(val.Tip, false); val2.AddComponent<TipGlow>().Init(_counter++ % RavePalette.Colors.Length); _glows.Add(val2); } } } private void OnDestroy() { for (int i = 0; i < _glows.Count; i++) { if ((Object)(object)_glows[i] != (Object)null) { Object.Destroy((Object)(object)_glows[i]); } } _glows.Clear(); } } public sealed class TipGlow : MonoBehaviour { public void Init(int index) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0078: 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_017d: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: 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_00a3: 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_00d6: 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_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: 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_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) Color color = RavePalette.Colors[Mathf.Clamp(index, 0, RavePalette.Colors.Length - 1)]; Material sharedMaterial = GlowstickVisual.MakeMaterial(color, emissive: true, null); GameObject val = GameObject.CreatePrimitive((PrimitiveType)2); Object.Destroy((Object)(object)val.GetComponent<Collider>()); ((Object)val).name = "GlowRod"; val.transform.SetParent(((Component)this).transform, false); val.transform.localPosition = Vector3.zero; val.transform.localScale = new Vector3(0.003f, 0.018f, 0.003f); ((Renderer)val.GetComponent<MeshRenderer>()).sharedMaterial = sharedMaterial; if (GlowstickVisual.TrailsEnabled) { Vector3 lossyScale = ((Component)this).transform.lossyScale; float num = Mathf.Abs(val.transform.lossyScale.y) * 2f; if (num < 0.001f) { num = 0.2f; } GameObject val2 = new GameObject("TipTrails"); val2.transform.SetParent(((Component)this).transform, false); val2.transform.localScale = new Vector3(1f / Mathf.Max(0.0001f, Mathf.Abs(lossyScale.x)), 1f / Mathf.Max(0.0001f, Mathf.Abs(lossyScale.y)), 1f / Mathf.Max(0.0001f, Mathf.Abs(lossyScale.z))); GlowstickVisual.BuildTrailBundle(val2.transform, color, num, Mathf.Clamp(num * 0.16f, 0.012f, 0.08f)); } GameObject val3 = new GameObject("TipLight"); val3.transform.SetParent(((Component)this).transform, false); val3.transform.localPosition = Vector3.zero; Light obj = val3.AddComponent<Light>(); obj.type = (LightType)2; obj.color = color; obj.range = 8f; obj.intensity = 4f; obj.shadows = (LightShadows)0; } } public static class RavePalette { public static readonly string[] Names = new string[8] { "Cyan", "Magenta", "Lime", "Orange", "Yellow", "Red", "Blue", "Violet" }; public static readonly Color[] Colors = (Color[])(object)new Color[8] { new Color(0f, 0.85f, 1f), new Color(1f, 0.05f, 0.75f), new Color(0.25f, 1f, 0.05f), new Color(1f, 0.25f, 0.02f), new Color(1f, 0.85f, 0.02f), new Color(1f, 0.02f, 0.03f), new Color(0.05f, 0.25f, 1f), new Color(0.55f, 0.05f, 1f) }; } internal static class RaveIconSprites { private static Sprite[] _sprites; public static Sprite For(int index) { Ensure(); if (_sprites == null) { return null; } return _sprites[Mathf.Clamp(index, 0, _sprites.Length - 1)]; } private static void Ensure() { //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) if (_sprites != null) { return; } Assembly executingAssembly = Assembly.GetExecutingAssembly(); _sprites = (Sprite[])(object)new Sprite[RavePalette.Names.Length]; for (int i = 0; i < RavePalette.Names.Length; i++) { string text = "CrackRave.icons.glowstick-" + RavePalette.Names[i].ToLowerInvariant() + ".png"; try { using Stream stream = executingAssembly.GetManifestResourceStream(text); if (stream == null) { Debug.LogWarning((object)("[Rave] missing icon resource: " + text)); continue; } 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; } } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); if (!ImageConversion.LoadImage(val, array)) { Debug.LogWarning((object)("[Rave] icon decode failed: " + text)); continue; } ((Texture)val).filterMode = (FilterMode)1; ((Texture)val).wrapMode = (TextureWrapMode)1; ((Object)val).name = "GlowstickIcon_" + RavePalette.Names[i]; Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f); ((Object)val2).name = ((Object)val).name; _sprites[i] = val2; } catch (Exception ex) { Debug.LogWarning((object)("[Rave] icon load failed (" + text + "): " + ex.Message)); } } Debug.Log((object)("[Rave] glowstick icons loaded: " + Count())); } private static int Count() { int num = 0; if (_sprites != null) { for (int i = 0; i < _sprites.Length; i++) { if ((Object)(object)_sprites[i] != (Object)null) { num++; } } } return num; } } public sealed class GlowstickVisual : MonoBehaviour { private Material _body; private Light _light; private readonly List<TrailRenderer> _trails = new List<TrailRenderer>(); private int _color; private static Mesh _loopMesh; internal static float ThrowMultiplier = 3f; internal static bool TrailsEnabled = true; internal static float TrailWidth = 0.09f; internal static float TrailSpan = 0.55f; internal static int TrailStrands = 7; public string DisplayName => RavePalette.Names[_color] + " Glowstick"; public Sprite Icon => RaveIconSprites.For(_color); public static void Attach(GameObject root, byte colorIndex) { if (!((Object)(object)root == (Object)null)) { GlowstickVisual glowstickVisual = root.GetComponent<GlowstickVisual>(); if ((Object)(object)glowstickVisual == (Object)null) { glowstickVisual = root.AddComponent<GlowstickVisual>(); glowstickVisual.Build(root, colorIndex); } glowstickVisual.SetColor(colorIndex); } } private void Build(GameObject root, byte colorIndex) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_007c: 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_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Expected O, but got Unknown //IL_0120: Unknown result type (might be due to invalid IL or missing references) Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true); Material template = ((componentsInChildren.Length != 0) ? componentsInChildren[0].sharedMaterial : null); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = false; } Light[] componentsInChildren2 = root.GetComponentsInChildren<Light>(true); for (int j = 0; j < componentsInChildren2.Length; j++) { ((Behaviour)componentsInChildren2[j]).enabled = false; } GameObject val = new GameObject("GlowstickVisual"); val.transform.SetParent(root.transform, false); _body = MakeMaterial(RavePalette.Colors[colorIndex], emissive: true, template); Material material = MakeMaterial(new Color(0.025f, 0.028f, 0.034f), emissive: false, template); GameObject obj = GameObject.CreatePrimitive((PrimitiveType)2); Object.Destroy((Object)(object)obj.GetComponent<Collider>()); ((Object)obj).name = "Tube"; obj.transform.SetParent(val.transform, false); obj.transform.localScale = new Vector3(0.066f, 0.28f, 0.066f); ((Renderer)obj.GetComponent<MeshRenderer>()).sharedMaterial = _body; if (TrailsEnabled) { _trails.AddRange(BuildTrailBundle(root.transform, RavePalette.Colors[colorIndex], TrailSpan, TrailWidth)); } AddCap(val.transform, material, 0.306f); AddCap(val.transform, material, -0.306f); AddLoop(val.transform, material); GameObject val2 = new GameObject("GlowLight"); val2.transform.SetParent(val.transform, false); _light = val2.AddComponent<Light>(); _light.type = (LightType)2; _light.shadows = (LightShadows)0; _light.range = 15f; _light.intensity = 10f; SetColor(colorIndex); } private static void AddCap(Transform parent, Material material, float y) { //IL_003a: 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) GameObject obj = GameObject.CreatePrimitive((PrimitiveType)2); Object.Destroy((Object)(object)obj.GetComponent<Collider>()); ((Object)obj).name = "Cap"; obj.transform.SetParent(parent, false); obj.transform.localPosition = new Vector3(0f, y, 0f); obj.transform.localScale = new Vector3(0.074f, 0.026f, 0.074f); ((Renderer)obj.GetComponent<MeshRenderer>()).sharedMaterial = material; } private static void AddLoop(Transform parent, Material material) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003b: 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_005a: 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_0079: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_loopMesh == (Object)null) { _loopMesh = TorusMesh.Create(0.026f, 0.0045f, 20, 8); } GameObject val = new GameObject("Loop"); val.transform.SetParent(parent, false); val.transform.localPosition = new Vector3(0f, 0.365f, 0f); val.transform.localRotation = Quaternion.Euler(90f, 0f, 0f); val.AddComponent<MeshFilter>().sharedMesh = _loopMesh; ((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = material; } private void SetColor(byte colorIndex) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: 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_0053: 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) int num = (_color = Mathf.Clamp((int)colorIndex, 0, RavePalette.Colors.Length - 1)); Color color = RavePalette.Colors[num]; if ((Object)(object)_body != (Object)null) { SetMaterialColor(_body, color, emissive: true); } if ((Object)(object)_light != (Object)null) { _light.color = color; } for (int i = 0; i < _trails.Count; i++) { if ((Object)(object)_trails[i] != (Object)null) { _trails[i].colorGradient = MakeTrailGradient(color); } } } internal static Gradient MakeTrailGradient(Color color) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references)