Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Quads Rainbows v0.3.1
plugins/Rainbows.dll
Decompiled 13 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using DHack.Shared; using HarmonyLib; using Microsoft.CodeAnalysis; using Newtonsoft.Json.Linq; using UnityEngine; using UnityEngine.Audio; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyMetadata("AI_Assisted_Creation", "This assembly was partially or fully created with the assistance of Generative AI (Claude Code).")] [assembly: AssemblyMetadata("AI_Model_Vendor", "Anthropic")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [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 Rainbows { internal static class Blessing { public const string EffectName = "Rainbows_SE_Blessing"; public const string DoubleName = "Rainbows_SE_DoubleBlessing"; public static readonly int Hash = StringExtensionMethods.GetStableHashCode("Rainbows_SE_Blessing"); public static readonly int DoubleHash = StringExtensionMethods.GetStableHashCode("Rainbows_SE_DoubleBlessing"); private static SE_Rainbow _effect; private static SE_Rainbow _double; private static Sprite _icon; private static Sprite _doubleIcon; public static void Register() { ObjectDB instance = ObjectDB.instance; if ((Object)(object)instance == (Object)null || instance.m_items.Count == 0) { return; } if ((Object)(object)_effect == (Object)null) { _effect = ScriptableObject.CreateInstance<SE_Rainbow>(); ((Object)_effect).name = "Rainbows_SE_Blessing"; ((StatusEffect)_effect).m_name = "$rainbows_blessing"; ((StatusEffect)_effect).m_icon = (_icon = MakeIcon(twice: false)); _double = ScriptableObject.CreateInstance<SE_DoubleRainbow>(); ((Object)_double).name = "Rainbows_SE_DoubleBlessing"; ((StatusEffect)_double).m_name = "$rainbows_double_blessing"; ((StatusEffect)_double).m_icon = (_doubleIcon = MakeIcon(twice: true)); } SE_Rainbow[] array = new SE_Rainbow[2] { _effect, _double }; foreach (SE_Rainbow e in array) { if (!instance.m_StatusEffects.Contains((StatusEffect)(object)e)) { instance.m_StatusEffects.RemoveAll((StatusEffect x) => (Object)(object)x == (Object)null || ((Object)x).name == ((Object)e).name); instance.m_StatusEffects.Add((StatusEffect)(object)e); } } } public static void Unregister() { ObjectDB instance = ObjectDB.instance; Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && (Object)(object)_effect != (Object)null) { ((Character)localPlayer).GetSEMan().RemoveStatusEffect(Hash, true); ((Character)localPlayer).GetSEMan().RemoveStatusEffect(DoubleHash, true); } if ((Object)(object)instance != (Object)null) { instance.m_StatusEffects.RemoveAll((StatusEffect e) => (Object)(object)e == (Object)null || (Object)(object)e == (Object)(object)_effect || (Object)(object)e == (Object)(object)_double); } if ((Object)(object)_effect != (Object)null) { Object.Destroy((Object)(object)_effect); } if ((Object)(object)_double != (Object)null) { Object.Destroy((Object)(object)_double); } Sprite[] array = (Sprite[])(object)new Sprite[2] { _icon, _doubleIcon }; foreach (Sprite val in array) { if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val.texture); Object.Destroy((Object)(object)val); } } _effect = null; _double = null; _icon = null; _doubleIcon = null; } public static void Give(Player player, bool doubled) { if (Plugin.Buff.Value && !((Object)(object)player == (Object)null) && !((Object)(object)ObjectDB.instance == (Object)null)) { Register(); SEMan sEMan = ((Character)player).GetSEMan(); sEMan.RemoveStatusEffect(Hash, true); sEMan.RemoveStatusEffect(DoubleHash, true); sEMan.AddStatusEffect(doubled ? DoubleHash : Hash, true, 0, 0f, (short)(-1)); } } public static bool Has(Player player) { if ((Object)(object)player != (Object)null) { if (!((Character)player).GetSEMan().HaveStatusEffect(Hash)) { return ((Character)player).GetSEMan().HaveStatusEffect(DoubleHash); } return true; } return false; } private static Sprite MakeIcon(bool twice) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0134: 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_0144: 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) Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false); Color val2 = default(Color); ((Color)(ref val2))..ctor(0f, 0f, 0f, 0f); for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { float num = (float)j - 32f + 0.5f; float num2 = (float)i - 14.08f; float num3 = Mathf.Sqrt(num * num + num2 * num2); float num4 = Mathf.InverseLerp(26f, 13f, num3); Color val3 = val2; if (num4 > 0f && num4 < 1f && num2 > -4f) { val3 = Sky.Spectrum(num4); val3.a = Mathf.Clamp01(Mathf.Min(num4, 1f - num4) * 8f); } if (twice && val3.a < 0.5f) { float num5 = Mathf.InverseLerp(36f, 28f, num3); if (num5 > 0f && num5 < 1f && num2 > -4f) { Color val4 = Sky.Spectrum(1f - num5); val4.a = Mathf.Clamp01(Mathf.Min(num5, 1f - num5) * 8f) * 0.7f; if (val4.a > val3.a) { val3 = val4; } } } val.SetPixel(j, i, val3); } } val.Apply(); return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f); } } public class SE_Rainbow : SE_Stats { protected virtual float Strength => 1f; protected virtual string Lead => Translations.T("rainbows_seen"); public override void Setup(Character character) { ((StatusEffect)this).m_ttl = Plugin.BuffMinutes.Value * 60f; base.m_staminaRegenMultiplier = 1f + 0.3f * Strength; base.m_healthRegenMultiplier = 1f + 0.2f * Strength; base.m_runStaminaDrainModifier = -0.2f * Strength; base.m_jumpStaminaUseModifier = -0.2f * Strength; ((SE_Stats)this).Setup(character); } public override string GetTooltipString() { return Lead + "\n" + Translations.T("rainbows_tooltip", (30f * Strength).ToString("0"), (20f * Strength).ToString("0"), (20f * Strength).ToString("0")); } } public class SE_DoubleRainbow : SE_Rainbow { protected override float Strength => 1.5f; protected override string Lead => Translations.T("rainbows_double"); } [BepInPlugin("com.quad.rainbows", "Rainbows", "0.3.1")] public class Plugin : BaseUnityPlugin { public const string Guid = "com.quad.rainbows"; public const string OldGuid = "com.dhack.rainbows"; public const string Name = "Rainbows"; public const string Version = "0.3.1"; internal static Plugin Instance; internal static ManualLogSource Log; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<bool> Chime; internal static ConfigEntry<bool> Buff; internal static ConfigEntry<float> Chance; internal static ConfigEntry<float> MinRainSeconds; internal static ConfigEntry<float> WaitMinutes; internal static ConfigEntry<float> ShowMinutes; internal static ConfigEntry<float> BuffMinutes; internal static ConfigEntry<float> Brightness; internal static ConfigEntry<float> Volume; internal static ConfigEntry<float> DoubleChance; internal static ServerSettings Synced; private Harmony _harmony; private void Awake() { //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Expected O, but got Unknown //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Expected O, but got Unknown //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Expected O, but got Unknown //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Expected O, but got Unknown //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Expected O, but got Unknown //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Expected O, but got Unknown //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Expected O, but got Unknown //IL_02a3: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: Expected O, but got Unknown //IL_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Expected O, but got Unknown Migration.FromOldGuid((BaseUnityPlugin)(object)this, "com.dhack.rainbows"); Translations.Load((BaseUnityPlugin)(object)this); Instance = this; Log = ((BaseUnityPlugin)this).Logger; Synced = new ServerSettings("com.quad.rainbows", ((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger); Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Rainbow", "Enabled", true, "Rainbows after the rain."); Chance = Synced.Add<float>(((BaseUnityPlugin)this).Config.Bind<float>("Rainbow", "Chance", 0.8f, new ConfigDescription("How often a good spell of rain ends in a rainbow (0 never, 1 always), when the sun is low enough to show one. In multiplayer the server's value applies.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()))); MinRainSeconds = Synced.Add<float>(((BaseUnityPlugin)this).Config.Bind<float>("Rainbow", "MinRainSeconds", 45f, new ConfigDescription("How long it must have rained (seconds) for the end of it to be worth a rainbow. In multiplayer the server's value applies.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 600f), Array.Empty<object>()))); WaitMinutes = Synced.Add<float>(((BaseUnityPlugin)this).Config.Bind<float>("Rainbow", "WaitMinutes", 8f, new ConfigDescription("If the sun is too high or too low when the rain ends, how long (minutes) to wait for it to come into place before giving up. In multiplayer the server's value applies.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()))); ShowMinutes = ((BaseUnityPlugin)this).Config.Bind<float>("Rainbow", "ShowMinutes", 3f, new ConfigDescription("How long the rainbow stays (minutes), if the sun does not move it out of the sky first.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 30f), Array.Empty<object>())); Brightness = ((BaseUnityPlugin)this).Config.Bind<float>("Rainbow", "Brightness", 1f, new ConfigDescription("How strong the colours are.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 2f), Array.Empty<object>())); DoubleChance = Synced.Add<float>(((BaseUnityPlugin)this).Config.Bind<float>("Rainbow", "DoubleChance", 0.3f, new ConfigDescription("How often a rainbow is a double one : a fainter second rainbow outside the first, its colours the other way round, and a stronger blessing. 0 never, 1 always. In multiplayer the server's value applies.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()))); Chime = ((BaseUnityPlugin)this).Config.Bind<bool>("Rainbow", "Chime", true, "A soft chime when a rainbow comes out."); Volume = ((BaseUnityPlugin)this).Config.Bind<float>("Rainbow", "ChimeVolume", 0.35f, new ConfigDescription("How loud the chime is.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); Buff = ((BaseUnityPlugin)this).Config.Bind<bool>("Blessing", "Enabled", true, "Look up at a rainbow and you get Rainbow's Blessing: stamina and health come back faster, and running and jumping cost less stamina. A double rainbow gives a stronger one."); BuffMinutes = Synced.Add<float>(((BaseUnityPlugin)this).Config.Bind<float>("Blessing", "Minutes", 5f, new ConfigDescription("How long the blessing lasts (minutes). In multiplayer the server's value applies.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 30f), Array.Empty<object>()))); _harmony = new Harmony("com.quad.rainbows"); _harmony.PatchAll(typeof(Plugin).Assembly); Blessing.Register(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Rainbows 0.3.1 loaded"); } private void Update() { Synced?.Update(); Tools.Update(); Sky.Tick(Time.deltaTime); } private void LateUpdate() { Sky.Follow(); } private void OnDestroy() { Synced?.Dispose(); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } Tools.Unregister(); Sky.Clear(); Blessing.Unregister(); Translations.Unload(); if ((Object)(object)Instance == (Object)(object)this) { Instance = null; } } } [HarmonyPatch(typeof(ZNetScene), "Awake")] internal static class ZNetScene_Awake { private static void Postfix() { Blessing.Register(); } } [HarmonyPatch(typeof(ObjectDB), "Awake")] internal static class ObjectDB_Awake { private static void Postfix() { Blessing.Register(); } } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] internal static class ObjectDB_CopyOtherDB { private static void Postfix() { Blessing.Register(); } } internal static class Sky { private const int Around = 220; private const int Across = 14; private const float MinSun = 4f; private const float MaxSun = 40f; private static GameObject _root; private static Mesh _mesh; private static Material _material; private static Vector3[] _local; private static float[] _weight; private static bool[] _outer; private static bool _double; private static Color[] _hue; private static Color[] _colors; private static AudioClip _chime; private static AudioMixerGroup _mixer; private static float _wetFor; private static float _waited; private static float _shownFor; private static float _fade; private static float _drawnStrength = -1f; private static Vector3 _drawnAnti; private static bool _waiting; private static bool _showing; private static bool _forced; private static bool _blessed; private static Vector3 _forcedSun; public static bool Showing => _showing; public static bool Double => _double; public static float Fade => _fade; public static Vector3 Anti { get; private set; } = Vector3.forward; public static float SunHeight { get; private set; } public static string Why { get; private set; } = ""; public static float WetFor => _wetFor; public static bool Waiting => _waiting; public static string Debug { get { //IL_005f: 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) if (!((Object)(object)_root == (Object)null)) { return string.Format("shader {0}, radius {1:0}, at {2}, active {3}, camera far {4:0}, verts {5}, alpha0 {6:0.00}", ((Object)(object)_material != (Object)null && (Object)(object)_material.shader != (Object)null) ? ((Object)_material.shader).name : "none", _root.transform.localScale.x, _root.transform.position, _root.activeInHierarchy, ((Object)(object)Camera.main != (Object)null) ? Camera.main.farClipPlane : 0f, _local?.Length, (_colors != null && _colors.Length != 0) ? _colors.Max((Color c) => c.a) : 0f); } return "no dome"; } } public static void Tick(float dt) { //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_00e5: 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_0295: Unknown result type (might be due to invalid IL or missing references) //IL_0304: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_0327: Unknown result type (might be due to invalid IL or missing references) //IL_0331: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (!Plugin.Enabled.Value || (Object)(object)localPlayer == (Object)null || (Object)(object)EnvMan.instance == (Object)null) { if (_showing) { Stop(); } _wetFor = 0f; _waiting = false; return; } bool isWet = EnvMan.instance.GetCurrentEnvironment().m_isWet; if (isWet) { _wetFor += dt; _waiting = false; } else { if (_wetFor >= Plugin.MinRainSeconds.Value && !_showing && Random.value <= Plugin.Chance.Value) { _waiting = true; _waited = 0f; } _wetFor = 0f; } if (_waiting) { _waited += dt; if (_waited > Plugin.WaitMinutes.Value * 60f) { _waiting = false; } } Vector3 val = Sun(); SunHeight = Mathf.Asin(Mathf.Clamp(val.y, -1f, 1f)) * 57.29578f; bool flag = (_forced || EnvMan.IsDay()) && SunHeight >= 4f && SunHeight <= 40f; Why = (isWet ? "raining" : ((!flag) ? $"sun at {SunHeight:0} degrees (needs {4f:0} to {40f:0}, in daylight)" : (((Character)localPlayer).InInterior() ? "indoors" : "ok"))); if (_waiting && !isWet && flag && !((Character)localPlayer).InInterior()) { Begin(localPlayer); } if (!_showing) { return; } _shownFor += dt; float num = Plugin.ShowMinutes.Value * 60f; float num2 = Mathf.Clamp01(_shownFor / 14f) * Mathf.Clamp01((num - _shownFor) / 20f); float num3 = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(2f, 7f, SunHeight)) * Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(42f, 36f, SunHeight)); float num4 = (((isWet && !_forced) || (!_forced && !EnvMan.IsDay())) ? 0f : (num2 * num3)); _fade = Mathf.MoveTowards(_fade, num4, dt / ((num4 < _fade) ? 4f : 8f)); Anti = -val; if (_shownFor > num || (_fade <= 0.001f && _shownFor > 20f)) { Stop(); return; } if (!_blessed && _fade > 0.45f && !((Character)localPlayer).InInterior() && (Object)(object)Camera.main != (Object)null && Vector3.Angle(((Component)Camera.main).transform.forward, new Vector3(Anti.x, Mathf.Max(Anti.y, 0.15f), Anti.z)) < 75f) { _blessed = true; Blessing.Give(localPlayer, _double); if (Plugin.Buff.Value) { ((Character)localPlayer).Message((MessageType)2, _double ? Translations.T("rainbows_double_blessing") : Translations.T("rainbows_blessing"), 0, (Sprite)null, false); } } Draw(); } private static Vector3 Sun() { //IL_0007: 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_0032: 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) if (_forced) { return _forcedSun; } Light dirLight = EnvMan.instance.m_dirLight; if (!((Object)(object)dirLight != (Object)null)) { return Vector3.up; } return -((Component)dirLight).transform.forward; } private static void Begin(Player player, bool? forceDouble = null) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) _waiting = false; _showing = true; _shownFor = 0f; _fade = 0f; _blessed = false; _drawnStrength = -1f; _double = forceDouble ?? (Random.value <= Plugin.DoubleChance.Value); Anti = -Sun(); Build(); if (!((Character)player).InInterior()) { ((Character)player).Message((MessageType)1, _double ? Translations.T("rainbows_double") : Translations.T("rainbows_comes_out"), 0, (Sprite)null, false); if (Plugin.Chime.Value) { Chime(); } } Plugin.Log.LogInfo((object)$"Rainbow: sun {SunHeight:0} degrees, rain lasted {_wetFor:0} s"); } public static void Force(float heightDegrees, bool twice) { //IL_001e: 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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_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_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: 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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) Vector3 val = (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform.forward : Vector3.forward); val.y = 0f; if (((Vector3)(ref val)).sqrMagnitude < 0.01f) { val = Vector3.forward; } float num = heightDegrees * ((float)Math.PI / 180f); Vector3 val2 = -((Vector3)(ref val)).normalized * Mathf.Cos(num) + Vector3.up * Mathf.Sin(num); _forcedSun = ((Vector3)(ref val2)).normalized; if (_showing) { Stop(); } _forced = true; _wetFor = 0f; Begin(Player.m_localPlayer, twice); _shownFor = 14f; _fade = 1f; } public static void Stop() { _showing = false; _forced = false; _fade = 0f; if ((Object)(object)_root != (Object)null) { _root.SetActive(false); } } public static void Clear() { Stop(); if ((Object)(object)_root != (Object)null) { Object.Destroy((Object)(object)_root); } if ((Object)(object)_mesh != (Object)null) { Object.Destroy((Object)(object)_mesh); } if ((Object)(object)_material != (Object)null) { Object.Destroy((Object)(object)_material); } if ((Object)(object)_chime != (Object)null) { Object.Destroy((Object)(object)_chime); } _root = null; _mesh = null; _material = null; _chime = null; _mixer = null; } public static string UseShader(string name) { Shader val = Shader.Find(name); if ((Object)(object)val == (Object)null || (Object)(object)_material == (Object)null) { return "not found"; } _material.shader = val; return ((Object)val).name; } public static Color Spectrum(float t) { //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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: 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_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) t = Mathf.Pow(Mathf.Clamp01(t), 1.3f); Color[] array = (Color[])(object)new Color[7] { new Color(1f, 0.05f, 0.04f), new Color(1f, 0.5f, 0.05f), new Color(1f, 0.92f, 0.2f), new Color(0.3f, 0.85f, 0.3f), new Color(0.2f, 0.65f, 1f), new Color(0.35f, 0.3f, 0.95f), new Color(0.6f, 0.25f, 0.85f) }; float num = Mathf.Clamp01(t) * (float)(array.Length - 1); int num2 = Mathf.Min((int)num, array.Length - 2); return Color.Lerp(array[num2], array[num2 + 1], num - (float)num2); } private static void Build() { //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Expected O, but got Unknown //IL_02a8: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Unknown result type (might be due to invalid IL or missing references) //IL_02bc: Unknown result type (might be due to invalid IL or missing references) //IL_02fa: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_030a: Unknown result type (might be due to invalid IL or missing references) //IL_031a: Expected O, but got Unknown //IL_031f: Unknown result type (might be due to invalid IL or missing references) //IL_0324: Unknown result type (might be due to invalid IL or missing references) //IL_0330: Expected O, but got Unknown //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_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_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_root != (Object)null && (Object)(object)_mesh != (Object)null) { _root.SetActive(true); return; } int num = 3300; _local = (Vector3[])(object)new Vector3[2 * num]; _outer = new bool[2 * num]; _weight = new float[_local.Length]; _hue = (Color[])(object)new Color[_local.Length]; _colors = (Color[])(object)new Color[_local.Length]; int[] array = new int[36960]; int num2 = 0; int num3 = 0; for (int i = 0; i < 2; i++) { float num4 = ((i == 0) ? 44f : 56f); float num5 = ((i == 0) ? 38f : 50f); int num6 = num2; for (int j = 0; j <= 14; j++) { float num7 = (float)j / 14f; float num8 = Mathf.Lerp(num4, num5, num7) * ((float)Math.PI / 180f); Color val = Spectrum((i == 0) ? num7 : (1f - num7)); float num9 = Mathf.Clamp01(Mathf.Sin(num7 * (float)Math.PI) * 1.7f) * ((i == 0) ? 1f : 0.4f); int num10 = 0; while (num10 < 220) { float num11 = (float)num10 / 220f * (float)Math.PI * 2f; _local[num2] = new Vector3(Mathf.Sin(num8) * Mathf.Cos(num11), Mathf.Sin(num8) * Mathf.Sin(num11), Mathf.Cos(num8)); _weight[num2] = num9; _hue[num2] = val; _outer[num2] = i == 1; num10++; num2++; } } for (int k = 0; k < 14; k++) { for (int l = 0; l < 220; l++) { int num12 = num6 + k * 220 + l; int num13 = num6 + k * 220 + (l + 1) % 220; int num14 = num12 + 220; int num15 = num13 + 220; array[num3++] = num12; array[num3++] = num14; array[num3++] = num13; array[num3++] = num13; array[num3++] = num14; array[num3++] = num15; } } } _mesh = new Mesh { name = "Rainbow" }; _mesh.vertices = _local; _mesh.triangles = array; _mesh.colors = _colors; _mesh.bounds = new Bounds(Vector3.zero, Vector3.one * 100000f); _mesh.MarkDynamic(); Shader val2 = Shader.Find("Sprites/Default") ?? Shader.Find("Legacy Shaders/Particles/Alpha Blended") ?? Shader.Find("Unlit/Color"); _material = new Material(val2) { name = "RainbowMaterial", renderQueue = 3100 }; _root = new GameObject("Rainbow") { layer = 0 }; Object.DontDestroyOnLoad((Object)(object)_root); _root.AddComponent<MeshFilter>().sharedMesh = _mesh; MeshRenderer val3 = _root.AddComponent<MeshRenderer>(); ((Renderer)val3).sharedMaterial = _material; ((Renderer)val3).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)val3).receiveShadows = false; } private static void Draw() { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0097: 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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0148: 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) if ((Object)(object)_root == (Object)null || (Object)(object)_mesh == (Object)null) { return; } Quaternion val = Quaternion.FromToRotation(Vector3.forward, Anti); _root.transform.rotation = val; float num = _fade * Plugin.Brightness.Value * 0.9f; bool flag = _drawnStrength < 0f; if (!flag && Mathf.Abs(num - _drawnStrength) < 0.003f && Vector3.Angle(Anti, _drawnAnti) < 0.05f) { return; } _drawnStrength = num; _drawnAnti = Anti; Vector3 val2 = Quaternion.Inverse(val) * Vector3.up; for (int i = 0; i < _local.Length; i++) { if (_outer[i] && !_double) { if (flag) { _colors[i].a = 0f; } } else { float num2 = Vector3.Dot(val2, _local[i]); float num3 = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0f, 0.16f, num2)); Color val3 = _hue[i]; val3.a = Mathf.Clamp01(_weight[i] * num3 * num); _colors[i] = val3; } } _mesh.colors = _colors; } public static void Follow() { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) if (_showing && !((Object)(object)_root == (Object)null)) { Camera main = Camera.main; if (!((Object)(object)main == (Object)null)) { float num = Mathf.Clamp(main.farClipPlane * 0.7f, 200f, 450f); _root.transform.position = ((Component)main).transform.position; _root.transform.localScale = Vector3.one * num; } } } private static void Chime() { //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Expected O, but got Unknown //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Expected O, but got Unknown //IL_0149: Expected O, but got Unknown if ((Object)(object)_chime == (Object)null) { float num = 2.4f; float[] data = new float[(int)(44100f * num)]; float[] array = new float[4] { 1046.5f, 1318.5f, 1568f, 2093f }; for (int i = 0; i < array.Length; i++) { int num2 = (int)((float)i * 0.22f * 44100f); for (int j = num2; j < data.Length; j++) { float num3 = (float)(j - num2) / 44100f; float num4 = Mathf.Exp((0f - num3) * 2.6f) * Mathf.Clamp01(num3 * 80f); float num5 = Mathf.Sin((float)Math.PI * 2f * array[i] * num3) + 0.3f * Mathf.Sin((float)Math.PI * 4f * array[i] * num3) * Mathf.Exp((0f - num3) * 4f); data[j] += num5 * num4 * 0.18f; } } int at = 0; _chime = AudioClip.Create("RainbowChime", data.Length, 1, 44100, false, (PCMReaderCallback)delegate(float[] block) { for (int k = 0; k < block.Length; k++) { block[k] = ((at < data.Length) ? data[at++] : 0f); } }, (PCMSetPositionCallback)delegate(int position) { at = position; }); } if ((Object)(object)_mixer == (Object)null && (Object)(object)ZNetScene.instance != (Object)null) { GameObject prefab = ZNetScene.instance.GetPrefab("sfx_chest_open"); object mixer; if (prefab == null) { mixer = null; } else { AudioSource componentInChildren = prefab.GetComponentInChildren<AudioSource>(true); mixer = ((componentInChildren != null) ? componentInChildren.outputAudioMixerGroup : null); } _mixer = (AudioMixerGroup)mixer; } GameObject val = new GameObject("RainbowChime"); AudioSource val2 = val.AddComponent<AudioSource>(); val2.clip = _chime; val2.spatialBlend = 0f; val2.volume = Plugin.Volume.Value; val2.outputAudioMixerGroup = _mixer; val2.Play(); Object.Destroy((Object)(object)val, 3.5f); } } internal static class Tools { private static BaseUnityPlugin _claudeTools; private static float _next; public static void Update() { if (Time.unscaledTime < _next) { return; } _next = Time.unscaledTime + 5f; PluginInfo value; BaseUnityPlugin val = (Chainloader.PluginInfos.TryGetValue("com.quad.claudetools", out value) ? value.Instance : null); if ((Object)(object)val == (Object)(object)_claudeTools) { return; } _claudeTools = val; if ((Object)(object)val == (Object)null) { return; } try { ((object)val).GetType().GetMethod("RegisterCommand", BindingFlags.Static | BindingFlags.Public)?.Invoke(null, new object[4] { "Rainbows", "rainbow", "rainbow status | now [sun height degrees] [double] | stop | blessing [double]: what the weather is doing; a rainbow now in front of the camera; end it; give the blessing", new Func<string[], Action<JObject>, Action<string>, IEnumerator>(Command) }); Plugin.Log.LogInfo((object)"Claude Tools found: rainbow command added"); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not add the rainbow command to Claude Tools: " + ex.Message)); } } public static void Unregister() { try { ((object)_claudeTools)?.GetType().GetMethod("UnregisterAll", BindingFlags.Static | BindingFlags.Public)?.Invoke(null, new object[1] { "Rainbows" }); } catch (Exception) { } } private static IEnumerator Command(string[] args, Action<JObject> output, Action<string> error) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { error("no player in the world"); yield break; } args = args.Skip(1).ToArray(); string text = ((args.Length != 0) ? args[0].ToLowerInvariant() : "status"); if (Array.IndexOf(new string[2] { "status", "shader" }, text) < 0 && !TestCommands.CheatsAllowed()) { error(TestCommands.Refusal("rainbow " + text)); yield break; } switch (text) { case "now": { float result; float num = ((args.Length > 1 && float.TryParse(args[1], NumberStyles.Float, CultureInfo.InvariantCulture, out result)) ? result : 18f); Sky.Force(Mathf.Clamp(num, 5f, 38f), args.Length > 2 && args[2].ToLowerInvariant() == "double"); break; } case "stop": Sky.Stop(); break; case "shader": output(new JObject { ["shader"] = JToken.op_Implicit(Sky.UseShader(string.Join(" ", args.Skip(1)))) }); yield break; case "blessing": Blessing.Give(localPlayer, args.Length > 1 && args[1].ToLowerInvariant() == "double"); break; } EnvSetup val = (((Object)(object)EnvMan.instance != (Object)null) ? EnvMan.instance.GetCurrentEnvironment() : null); output(new JObject { ["weather"] = JToken.op_Implicit(val?.m_name), ["wet"] = JToken.op_Implicit(val?.m_isWet ?? false), ["rainedFor"] = JToken.op_Implicit(Sky.WetFor), ["waitingForSun"] = JToken.op_Implicit(Sky.Waiting), ["sunHeight"] = JToken.op_Implicit(Sky.SunHeight), ["why"] = JToken.op_Implicit(Sky.Why), ["showing"] = JToken.op_Implicit(Sky.Showing), ["double"] = JToken.op_Implicit(Sky.Double), ["fade"] = JToken.op_Implicit(Sky.Fade), ["debug"] = JToken.op_Implicit(Sky.Debug), ["blessing"] = JToken.op_Implicit(Blessing.Has(localPlayer)), ["rainbowYaw"] = JToken.op_Implicit(Mathf.Atan2(Sky.Anti.x, Sky.Anti.z) * 57.29578f) }); } } } namespace DHack.Shared { internal static class Migration { private sealed class Notice : MonoBehaviour { public string Text; private float _next; private void Update() { if (!(Time.unscaledTime < _next) && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)MessageHud.instance == (Object)null)) { ((Character)Player.m_localPlayer).Message((MessageType)2, Text, 0, (Sprite)null, false); _next = Time.unscaledTime + 60f; } } } public static void FromOldGuid(BaseUnityPlugin plugin, string oldGuid) { BepInPlugin metadata = MetadataHelper.GetMetadata((object)plugin); string text = ((metadata != null) ? metadata.GUID : null); if (string.IsNullOrEmpty(oldGuid) || string.IsNullOrEmpty(text) || oldGuid == text) { return; } ManualLogSource val = Logger.CreateLogSource(text); try { bool flag = false; if (Directory.Exists(Paths.ConfigPath)) { string[] files = Directory.GetFiles(Paths.ConfigPath, oldGuid + ".*"); foreach (string text2 in files) { string fileName = Path.GetFileName(text2); if (!fileName.EndsWith(".cfg") && !fileName.EndsWith(".json") && !fileName.EndsWith(".txt")) { continue; } string text3 = Path.Combine(Paths.ConfigPath, text + fileName.Substring(oldGuid.Length)); if (!File.Exists(text3)) { File.Copy(text2, text3); val.LogInfo((object)("Settings moved over from " + fileName + " (the mod's id is now " + text + "; the old file is kept as a backup)")); if (fileName == oldGuid + ".cfg") { flag = true; } } } } if (flag) { plugin.Config.Reload(); } } catch (Exception ex) { val.LogWarning((object)("Couldn't move the settings over from " + oldGuid + ".cfg: " + ex.Message)); } finally { Logger.Sources.Remove((ILogSource)(object)val); } ((MonoBehaviour)plugin).StartCoroutine(StandDownIfTwin(plugin, oldGuid)); } private static IEnumerator StandDownIfTwin(BaseUnityPlugin plugin, string oldGuid) { yield return null; yield return null; if (!((Object)(object)plugin == (Object)null) && Chainloader.PluginInfos.TryGetValue(oldGuid, out var value) && !((Object)(object)value.Instance == (Object)null) && !((Object)(object)value.Instance == (Object)(object)plugin)) { BepInPlugin metadata = MetadataHelper.GetMetadata((object)plugin); string text = ((metadata != null) ? metadata.Name : null) ?? oldGuid; string text2 = (string.IsNullOrEmpty(value.Location) ? "an older copy" : value.Location); string text3 = text + ": two copies are installed, an old one (" + text2 + ") and this one. Both would run and do everything twice, so this one stands down. Delete the old copy, then restart the game."; Debug.LogError((object)("[" + text + "] " + text3)); Object.Destroy((Object)(object)plugin); GameObject val = new GameObject("Migration_TwoCopies_" + text); Object.DontDestroyOnLoad((Object)(object)val); val.AddComponent<Notice>().Text = text3; } } } internal static class Translations { public static readonly string[] Shipped = new string[9] { "English", "Russian", "German", "Chinese", "Portuguese_Brazilian", "Spanish", "French", "Polish", "Turkish" }; private static readonly Dictionary<string, Dictionary<string, string>> Languages = new Dictionary<string, Dictionary<string, string>>(StringComparer.OrdinalIgnoreCase); private static Dictionary<string, string> _english = new Dictionary<string, string>(); private static string _overrideDir; private static bool _hooked; private static readonly MethodInfo AddWord = AccessTools.Method(typeof(Localization), "AddWord", (Type[])null, (Type[])null); private static readonly FieldInfo Cache = AccessTools.Field(typeof(Localization), "m_cache"); public static void Load(BaseUnityPlugin plugin) { Languages.Clear(); Assembly assembly = ((object)plugin).GetType().Assembly; foreach (string item in from n in assembly.GetManifestResourceNames() where n.StartsWith("translations/") && n.EndsWith(".json") select n) { using StreamReader streamReader = new StreamReader(assembly.GetManifestResourceStream(item)); Languages[Path.GetFileNameWithoutExtension(item.Substring("translations/".Length))] = Parse(streamReader.ReadToEnd()); } _english = (Languages.TryGetValue("English", out var value) ? value : new Dictionary<string, string>()); _overrideDir = Path.Combine(Paths.ConfigPath, "translations", plugin.Info.Metadata.GUID); if (!_hooked) { Localization.OnLanguageChange = (Action)Delegate.Combine(Localization.OnLanguageChange, new Action(Apply)); _hooked = true; } Apply(); } public static void Unload() { if (_hooked) { Localization.OnLanguageChange = (Action)Delegate.Remove(Localization.OnLanguageChange, new Action(Apply)); _hooked = false; } } public static string T(string key, params object[] args) { string text = ((Localization.instance != null) ? Localization.instance.Localize("$" + key) : null); if (string.IsNullOrEmpty(text) || text == "[" + key + "]") { text = (_english.TryGetValue(key, out var value) ? value : key); } if (args == null || args.Length == 0) { return text; } try { return string.Format(text, args); } catch (FormatException) { string value2; return _english.TryGetValue(key, out value2) ? SafeFormat(value2, args) : text; } } private static string SafeFormat(string text, object[] args) { try { return string.Format(text, args); } catch (FormatException) { return text; } } private static void Apply() { Localization instance = Localization.instance; if (instance == null || AddWord == null) { return; } string selectedLanguage = instance.GetSelectedLanguage(); Dictionary<string, string> dictionary = new Dictionary<string, string>(_english); if (Languages.TryGetValue(selectedLanguage, out var value)) { foreach (KeyValuePair<string, string> item in value) { dictionary[item.Key] = item.Value; } } try { string path = Path.Combine(_overrideDir, selectedLanguage + ".json"); if (File.Exists(path)) { foreach (KeyValuePair<string, string> item2 in Parse(File.ReadAllText(path))) { dictionary[item2.Key] = item2.Value; } } } catch (Exception ex) { Debug.LogWarning((object)("Translations: couldn't read the player's " + selectedLanguage + " file: " + ex.Message)); } foreach (KeyValuePair<string, string> item3 in dictionary) { AddWord.Invoke(instance, new object[2] { item3.Key, item3.Value }); } object obj = Cache?.GetValue(instance); obj?.GetType().GetMethod("EvictAll")?.Invoke(obj, null); } private static Dictionary<string, string> Parse(string json) { Dictionary<string, string> dictionary = new Dictionary<string, string>(); foreach (Match item in Regex.Matches(json, "\"((?:[^\"\\\\]|\\\\.)*)\"\\s*:\\s*\"((?:[^\"\\\\]|\\\\.)*)\"")) { dictionary[Unescape(item.Groups[1].Value)] = Unescape(item.Groups[2].Value); } return dictionary; } private static string Unescape(string s) { return Regex.Replace(s, "\\\\(u[0-9a-fA-F]{4}|.)", delegate(Match m) { string value = m.Groups[1].Value; return value[0] switch { 'n' => "\n", 't' => "\t", 'u' => ((char)Convert.ToInt32(value.Substring(1), 16)).ToString(), _ => value, }; }); } } internal sealed class ServerSettings : IDisposable { private readonly string _send; private readonly string _ask; private readonly ConfigFile _config; private readonly ManualLogSource _log; private readonly List<ConfigEntryBase> _entries = new List<ConfigEntryBase>(); private readonly Dictionary<ConfigEntryBase, object> _own = new Dictionary<ConfigEntryBase, object>(); private readonly Dictionary<ConfigEntryBase, object> _server = new Dictionary<ConfigEntryBase, object>(); private ZRoutedRpc _registeredOn; private bool _applying; private bool _changePending; private float _nextChangeSend; private const float ChangeSendGap = 0.5f; public bool FromServer => _server.Count > 0; private static bool IsServer { get { if ((Object)(object)ZNet.instance != (Object)null) { return ZNet.instance.IsServer(); } return false; } } public ServerSettings(string guid, ConfigFile config, ManualLogSource log) { _send = guid + ".settings"; _ask = guid + ".settings.ask"; _config = config; _log = log; } public ConfigEntry<T> Add<T>(ConfigEntry<T> entry) { if (entry == null || _entries.Contains((ConfigEntryBase)(object)entry)) { return entry; } _entries.Add((ConfigEntryBase)(object)entry); entry.SettingChanged += OnChanged; return entry; } public void Update() { ZRoutedRpc instance = ZRoutedRpc.instance; if (instance != _registeredOn) { Unregister(); Restore(); _changePending = false; if (instance != null) { Register(instance); } } if (_changePending && Time.unscaledTime >= _nextChangeSend) { SendChange(); } } public void Dispose() { Unregister(); Restore(); foreach (ConfigEntryBase entry in _entries) { Unsubscribe(entry); } _entries.Clear(); } private void Register(ZRoutedRpc rpc) { Forget(rpc, _send); Forget(rpc, _ask); rpc.Register<ZPackage>(_send, (Action<long, ZPackage>)OnValues); rpc.Register(_ask, (Action<long>)OnAsk); rpc.m_onNewPeer = (Action<long>)Delegate.Combine(rpc.m_onNewPeer, new Action<long>(OnNewPeer)); _registeredOn = rpc; } private void Unregister() { if (_registeredOn != null) { ZRoutedRpc registeredOn = _registeredOn; registeredOn.m_onNewPeer = (Action<long>)Delegate.Remove(registeredOn.m_onNewPeer, new Action<long>(OnNewPeer)); Forget(_registeredOn, _send); Forget(_registeredOn, _ask); _registeredOn = null; } } private static void Forget(ZRoutedRpc rpc, string name) { if (AccessTools.Field(typeof(ZRoutedRpc), "m_functions")?.GetValue(rpc) is IDictionary dictionary) { dictionary.Remove(StringExtensionMethods.GetStableHashCode(name)); } } private void OnNewPeer(long peer) { if (IsServer) { Send(peer); } else if ((Object)(object)ZNet.instance != (Object)null) { ZNetPeer serverPeer = ZNet.instance.GetServerPeer(); if (serverPeer != null && serverPeer.m_uid == peer) { Ask(); } } } private void OnAsk(long sender) { if (IsServer) { Send(sender); } } private void Ask() { try { ZRoutedRpc instance = ZRoutedRpc.instance; if (instance != null) { instance.InvokeRoutedRPC(ZNet.instance.GetServerPeer().m_uid, _ask, Array.Empty<object>()); } } catch (Exception) { } } private void Send(long target) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown if (ZRoutedRpc.instance == null || _entries.Count == 0) { return; } ZPackage val = new ZPackage(); val.Write(_entries.Count); foreach (ConfigEntryBase entry in _entries) { val.Write(entry.Definition.Section); val.Write(entry.Definition.Key); val.Write(TomlTypeConverter.ConvertToString(entry.BoxedValue, entry.SettingType)); } ZRoutedRpc.instance.InvokeRoutedRPC(target, _send, new object[1] { val }); } private void OnValues(long sender, ZPackage pkg) { if (IsServer) { return; } ZNetPeer val = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetServerPeer() : null); if (val == null || val.m_uid != sender) { return; } try { int num = pkg.ReadInt(); List<string> list = new List<string>(); for (int i = 0; i < num; i++) { string section = pkg.ReadString(); string key = pkg.ReadString(); string text = pkg.ReadString(); ConfigEntryBase val2 = ((IEnumerable<ConfigEntryBase>)_entries).FirstOrDefault((Func<ConfigEntryBase, bool>)((ConfigEntryBase x) => x.Definition.Section == section && x.Definition.Key == key)); if (val2 != null) { object obj; try { obj = TomlTypeConverter.ConvertToValue(text, val2.SettingType); } catch (Exception) { continue; } if (!_own.ContainsKey(val2)) { _own[val2] = val2.BoxedValue; } _server[val2] = obj; if (!object.Equals(val2.BoxedValue, obj)) { Apply(val2, obj); list.Add(section + "/" + key + " = " + text); } } } ManualLogSource log = _log; if (log != null) { log.LogInfo((object)($"Settings from the server apply while you play here ({_server.Count})" + ((list.Count > 0) ? (": " + string.Join(", ", list.ToArray())) : ""))); } } catch (Exception ex2) { ManualLogSource log2 = _log; if (log2 != null) { log2.LogWarning((object)("Could not read the server's settings: " + ex2.Message)); } } } private void Apply(ConfigEntryBase e, object value) { bool saveOnConfigSet = _config.SaveOnConfigSet; _applying = true; try { _config.SaveOnConfigSet = false; e.BoxedValue = value; } finally { _config.SaveOnConfigSet = saveOnConfigSet; _applying = false; } } private void Restore() { if (_server.Count == 0) { return; } foreach (KeyValuePair<ConfigEntryBase, object> item in _own) { Apply(item.Key, item.Value); } _own.Clear(); _server.Clear(); ManualLogSource log = _log; if (log != null) { log.LogInfo((object)"Your own settings apply again"); } } private void OnChanged(object sender, EventArgs args) { if (_applying) { return; } ConfigEntryBase val = (ConfigEntryBase)((sender is ConfigEntryBase) ? sender : null); if (val == null) { return; } if (_server.TryGetValue(val, out var value)) { _own[val] = val.BoxedValue; Apply(val, value); } else if (IsServer) { _changePending = true; if (Time.unscaledTime >= _nextChangeSend) { SendChange(); } } } private void SendChange() { _changePending = false; _nextChangeSend = Time.unscaledTime + 0.5f; if (IsServer && ZNet.instance.GetPeers().Count > 0) { Send(0L); } } private void Unsubscribe(ConfigEntryBase e) { ((object)e).GetType().GetEvent("SettingChanged")?.RemoveEventHandler(e, new EventHandler(OnChanged)); } } internal static class TestCommands { public static bool CheatsAllowed() { if (!((Object)(object)ZNet.instance == (Object)null) && !ZNet.instance.IsServer()) { if ((Object)(object)Console.instance != (Object)null) { return ((Terminal)Console.instance).IsCheatsEnabled(); } return false; } return true; } public static string Refusal(string what) { return what + " changes the game, so as a test command it only works in single player, for the host, or with devcommands on (a server admin)"; } } }