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 LightUpYourLife v1.0.0
BepInEx/plugins/LightUpYourWorld/LightUpYourWorld.dll
Decompiled 18 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyFileVersion("0.1.2.0")] [assembly: AssemblyVersion("0.1.2.0")] namespace LightUpYourWorld; [BepInPlugin("valheim.lightupyourworld", "LightUpYourWorld", "0.1.2")] public sealed class LightUpYourWorldPlugin : BaseUnityPlugin { internal const string PluginId = "valheim.lightupyourworld"; internal static LightUpYourWorldPlugin Instance; private Harmony harmony; private ConfigEntry<KeyCode> openKey; private WorldLight target; private readonly ColourSession session = new ColourSession(); private bool visible; private bool captured; private bool previousVisible; private bool previousRequested; private bool wheelDragging; private CursorLockMode previousLock; private float hue; private float saturation; private float brightness; private float acceptAfter; private float blockUntil; private string targetName; private string message = ""; private Texture2D wheel; private GUIStyle title; private GUIStyle heading; private GUIStyle body; private GUIStyle button; private GUIStyle centered; private GUIStyle small; private bool favouritesMode; private int favouriteSlot; private int favouriteDirection; private float favouriteRepeat; private static readonly MethodInfo TakeInputMethod = AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null); private bool controller => ZInput.IsGamepadActive(); internal bool IsOpen => visible; internal bool BlocksGameplay { get { if (!visible) { return Time.unscaledTime < blockUntil; } return true; } } internal string HoverPrompt { get { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) if (!controller) { return "[<color=yellow><b>" + ((object)openKey.Value/*cast due to .constrained prefix*/).ToString() + "</b></color>] Change light colour"; } string binding = ((ZInput.instance != null) ? ZInput.instance.GetBoundKeyString("JoyLBumper", true) : ""); return string.Concat(str2: NativeBinding((ZInput.instance != null) ? ZInput.instance.GetBoundKeyString("JoyUse", true) : "", "Interact"), str0: NativeBinding(binding, "LB"), str1: " + ", str3: " Change light colour"); } } private static string NativeBinding(string binding, string fallback) { if (string.IsNullOrEmpty(binding)) { binding = fallback; } if (!binding.Contains("<sprite=")) { return "[<color=yellow><b>" + Localize(binding) + "</b></color>]"; } return binding; } internal static bool CanTakeInput(Player player) { if (Object.op_Implicit((Object)(object)player) && TakeInputMethod != null) { return (bool)TakeInputMethod.Invoke(player, null); } return false; } internal static string Localize(string key) { try { Type type = AccessTools.TypeByName("Localization"); PropertyInfo propertyInfo = ((type != null) ? type.GetProperty("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) : null); object obj = ((propertyInfo != null) ? propertyInfo.GetValue(null, null) : null); MethodInfo methodInfo = ((type != null) ? type.GetMethod("Localize", new Type[1] { typeof(string) }) : null); return (obj != null && methodInfo != null) ? ((string)methodInfo.Invoke(obj, new object[1] { key })) : key; } catch { return key; } } private void Awake() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown Instance = this; openKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "OpenColourMenu", (KeyCode)103, "Look at a placed torch, lamp or campfire and press this key. Controller: hold LB and press your normal Interact button."); harmony = new Harmony("valheim.lightupyourworld"); harmony.PatchAll(typeof(LightUpYourWorldPlugin).Assembly); CreateWheel(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"LightUpYourWorld 0.1.2 loaded. G / LB+Interact changes a placed light. No Dye Your Gear dependency."); } private void OnDestroy() { Close(); foreach (WorldLight source in WorldLight.Sources) { if (Object.op_Implicit((Object)(object)source)) { source.RestoreForUnload(); } } if (harmony != null) { harmony.UnpatchSelf(); } if (Object.op_Implicit((Object)(object)wheel)) { Object.Destroy((Object)(object)wheel); } Instance = null; } private void OnDisable() { Close(); } private void Update() { //IL_001d: 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_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Unknown result type (might be due to invalid IL or missing references) //IL_028e: Unknown result type (might be due to invalid IL or missing references) //IL_0293: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (!visible) { if (Object.op_Implicit((Object)(object)localPlayer) && Input.GetKeyDown(openKey.Value) && !BlocksGameplay && CanTakeInput(localPlayer) && !((Character)localPlayer).InPlaceMode()) { Open(WorldLight.Find(((Humanoid)localPlayer).GetHoverObject())); } } else if (!Object.op_Implicit((Object)(object)localPlayer) || !Object.op_Implicit((Object)(object)target) || !target.Ready || ((Character)localPlayer).IsDead() || ((Character)localPlayer).IsTeleporting() || Vector3.Distance(((Component)localPlayer).transform.position, ((Component)target).transform.position) > 8f || Menu.IsVisible() || InventoryGui.IsVisible() || TextInput.IsVisible() || Console.IsVisible() || (Object.op_Implicit((Object)(object)Chat.instance) && Chat.instance.HasFocus()) || Input.GetKeyDown((KeyCode)27) || ZInput.GetButtonDown("JoyMenu")) { Close(); } else { if (Time.unscaledTime < acceptAfter) { return; } if (ZInput.GetButtonDown("JoyButtonB")) { ZInput.ResetButtonStatus("JoyButtonB"); if (favouritesMode) { favouritesMode = false; } else if (session.Dirty) { CancelPreview(); } else { Close(); } return; } if (Input.GetKeyDown((KeyCode)9)) { favouritesMode = !favouritesMode; } if (ZInput.GetButtonDown("JoyButtonY")) { ZInput.ResetButtonStatus("JoyButtonY"); if (favouritesMode) { SaveFavourite(); } else { favouritesMode = true; } } if (Input.GetKeyDown((KeyCode)102)) { SaveFavourite(); } if (favouritesMode) { UpdateFavourites(); ConsumeDirections(); return; } float num = ZInput.GetJoyRightStickX(); float num2 = ZInput.GetJoyRightStickY(); if (Input.GetKey((KeyCode)276)) { num = -1f; } if (Input.GetKey((KeyCode)275)) { num = 1f; } if (Input.GetKey((KeyCode)273)) { num2 = -1f; } if (Input.GetKey((KeyCode)274)) { num2 = 1f; } if (Mathf.Abs(num) > 0.25f || Mathf.Abs(num2) > 0.25f) { Vector2 val = new Vector2(Mathf.Cos(hue * 2f * MathF.PI), 0f - Mathf.Sin(hue * 2f * MathF.PI)) * saturation; val += new Vector2(num, num2) * Mathf.Min(Time.unscaledDeltaTime, 0.05f) * 0.9f; if (((Vector2)(ref val)).sqrMagnitude > 1f) { ((Vector2)(ref val)).Normalize(); } saturation = ((Vector2)(ref val)).magnitude; if (saturation > 0.001f) { hue = Mathf.Repeat(Mathf.Atan2(0f - val.y, val.x) / (MathF.PI * 2f), 1f); } Preview(); } if (ZInput.GetButtonDown("JoyLBumper") || Input.GetKeyDown((KeyCode)45) || Input.GetKeyDown((KeyCode)269)) { brightness = Mathf.Clamp01(brightness - 0.05f); Preview(); } if (ZInput.GetButtonDown("JoyRBumper") || Input.GetKeyDown((KeyCode)61) || Input.GetKeyDown((KeyCode)270)) { brightness = Mathf.Clamp01(brightness + 0.05f); Preview(); } if (Input.GetKeyDown((KeyCode)13) || Input.GetKeyDown((KeyCode)271) || ZInput.GetButtonDown("JoyButtonA")) { Apply(); ZInput.ResetButtonStatus("JoyButtonA"); ZInput.ResetButtonStatus("JoyUse"); } if (Input.GetKeyDown((KeyCode)127) || ZInput.GetButtonDown("JoyButtonX")) { RestoreDefault(); ZInput.ResetButtonStatus("JoyButtonX"); } ConsumeDirections(); } } private static void ConsumeDirections() { string[] array = new string[7] { "JoyDPadLeft", "JoyDPadRight", "JoyDPadUp", "JoyDPadDown", "JoyHotbarLeft", "JoyHotbarRight", "JoyHotbarUse" }; for (int i = 0; i < array.Length; i++) { ZInput.ResetButtonStatus(array[i]); } } private void UpdateFavourites() { float joyLeftStickX = ZInput.GetJoyLeftStickX(); float joyLeftStickY = ZInput.GetJoyLeftStickY(); int num = ((Mathf.Max(Mathf.Abs(joyLeftStickX), Mathf.Abs(joyLeftStickY)) > 0.5f) ? ((!(Mathf.Abs(joyLeftStickX) > Mathf.Abs(joyLeftStickY))) ? ((joyLeftStickY < 0f) ? (-2) : 2) : ((!(joyLeftStickX < 0f)) ? 1 : (-1))) : 0); int num2 = 0; if (Input.GetKeyDown((KeyCode)276) || ZInput.GetButtonDown("JoyDPadLeft")) { num2 = -1; } else if (Input.GetKeyDown((KeyCode)275) || ZInput.GetButtonDown("JoyDPadRight")) { num2 = 1; } else if (Input.GetKeyDown((KeyCode)273) || ZInput.GetButtonDown("JoyDPadUp")) { num2 = -2; } else if (Input.GetKeyDown((KeyCode)274) || ZInput.GetButtonDown("JoyDPadDown")) { num2 = 2; } if (num2 != 0) { favouriteSlot = (favouriteSlot + num2 + 10) % 10; } else if (num != 0 && (num != favouriteDirection || Time.unscaledTime >= favouriteRepeat)) { favouriteSlot = (favouriteSlot + num + 10) % 10; favouriteRepeat = Time.unscaledTime + ((num != favouriteDirection) ? 0.4f : 0.18f); } favouriteDirection = num; if (ZInput.GetButtonDown("JoyButtonA") || Input.GetKeyDown((KeyCode)13)) { PreviewFavourite(); ZInput.ResetButtonStatus("JoyButtonA"); ZInput.ResetButtonStatus("JoyUse"); } if (ZInput.GetButtonDown("JoyButtonX") || Input.GetKeyDown((KeyCode)127)) { RemoveFavourite(); ZInput.ResetButtonStatus("JoyButtonX"); } } private void PreviewFavourite() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) if (!LightFavourites.TryGet(Player.m_localPlayer, favouriteSlot, out var colour)) { message = "Empty slot. Save your current colour first."; return; } Color.RGBToHSV(colour, ref hue, ref saturation, ref brightness); Preview(); favouritesMode = false; message = "Favourite " + (favouriteSlot + 1) + " previewed. Apply to save on this light."; } private void SaveFavourite() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) LightFavourites.Set(Player.m_localPlayer, favouriteSlot, Color.HSVToRGB(hue, saturation, brightness)); message = "Colour saved in favourite " + (favouriteSlot + 1) + "."; } private void RemoveFavourite() { LightFavourites.Remove(Player.m_localPlayer, favouriteSlot); message = "Favourite " + (favouriteSlot + 1) + " cleared. Light colour unchanged."; } private void LateUpdate() { foreach (WorldLight source in WorldLight.Sources) { if (Object.op_Implicit((Object)(object)source)) { source.Tick(); } } KeepCursor(); } internal void Open(WorldLight source) { //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) if (!visible && Object.op_Implicit((Object)(object)source)) { if (!source.CanEdit(Player.m_localPlayer, flash: true)) { ((Character)Player.m_localPlayer).Message((MessageType)2, "You cannot change this light here.", 0, (Sprite)null, false); return; } target = source; target.RefreshLights(); targetName = source.DisplayName; session.Open(source.Saved); LoadWheel(); message = ""; favouritesMode = false; favouriteSlot = LightFavourites.FirstEmpty(Player.m_localPlayer); favouriteDirection = 0; visible = true; wheelDragging = false; acceptAfter = Time.unscaledTime + 0.3f; previousLock = Cursor.lockState; previousVisible = Cursor.visible; previousRequested = ZCursor.IsRequested; captured = true; ZInput.ResetButtonStatus("JoyUse"); ZInput.ResetButtonStatus("JoyButtonA"); ZInput.ResetButtonStatus("JoyButtonX"); KeepCursor(); } } private void LoadWheel() { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) Color.RGBToHSV((session.Saved == 0) ? target.OriginalColour : WorldLight.Unpack(session.Saved), ref hue, ref saturation, ref brightness); brightness = Mathf.Clamp01(brightness); } private void Preview() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) int num = WorldLight.Pack(Color.HSVToRGB(hue, saturation, brightness)); session.Preview(num); target.Preview(num); message = ""; } private void Apply() { if (session.Dirty) { if (!Object.op_Implicit((Object)(object)target) || !target.Commit(session.Selected)) { message = "Could not save. Check distance and ward access."; return; } session.Applied(); message = "Light colour applied and saved."; } } private void RestoreDefault() { if (!Object.op_Implicit((Object)(object)target) || target.Saved != 0 || session.Dirty) { if (!Object.op_Implicit((Object)(object)target) || !target.Commit(0)) { message = "Could not reset. Check distance and ward access."; return; } session.Open(0); LoadWheel(); message = "Original light colours restored."; } } private void CancelPreview() { if (!Object.op_Implicit((Object)(object)target)) { Close(); return; } target.EndPreview(); session.Cancel(target.Saved); LoadWheel(); message = "Preview discarded."; } internal void Close() { //IL_0057: 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) bool num = visible; visible = false; wheelDragging = false; favouritesMode = false; if (Object.op_Implicit((Object)(object)target)) { target.EndPreview(); } target = null; if (captured) { if (previousRequested) { ZCursor.Show(); } else { ZCursor.Hide(); } ZCursor.LockState = previousLock; Cursor.lockState = previousLock; Cursor.visible = previousVisible; captured = false; } if (num) { blockUntil = Time.unscaledTime + 0.15f; } } internal void KeepCursor() { if (visible) { ZCursor.Show(); ZCursor.LockState = (CursorLockMode)0; Cursor.lockState = (CursorLockMode)0; Cursor.visible = !controller; } } private void Styles() { //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_0021: 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: Expected O, but got Unknown //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004c: 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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown //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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown //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_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Expected O, but got Unknown //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Expected O, but got Unknown //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Expected O, but got Unknown //IL_0126: Unknown result type (might be due to invalid IL or missing references) if (title == null) { title = new GUIStyle(GUI.skin.label) { fontSize = 34, fontStyle = (FontStyle)1, alignment = (TextAnchor)4 }; heading = new GUIStyle(GUI.skin.label) { fontSize = 25, fontStyle = (FontStyle)1, alignment = (TextAnchor)4, wordWrap = true }; body = new GUIStyle(GUI.skin.label) { fontSize = 21, wordWrap = true }; button = new GUIStyle(GUI.skin.button) { fontSize = 20, fontStyle = (FontStyle)1, wordWrap = true }; centered = new GUIStyle(body) { alignment = (TextAnchor)4 }; small = new GUIStyle(body) { fontSize = 18 }; GUIStyle[] array = (GUIStyle[])(object)new GUIStyle[5] { title, heading, body, centered, small }; for (int i = 0; i < array.Length; i++) { array[i].normal.textColor = Color.white; } } } private void OnGUI() { //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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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) //IL_007a: 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_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00de: 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) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) if (visible) { Styles(); float num = MenuLayout.Scale(Screen.width, Screen.height); Matrix4x4 matrix = GUI.matrix; Color color = GUI.color; GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one * num); float num2 = (float)Screen.width / num; float num3 = (float)Screen.height / num; Rect val = new Rect(num2 - 600f, (num3 - 890f) / 2f, 580f, 890f); GUI.color = new Color(0.065f, 0.08f, 0.1f, 0.98f); GUI.DrawTexture(val, (Texture)(object)Texture2D.whiteTexture); GUI.color = Color.white; GUI.BeginGroup(val); DrawMenu(); GUI.EndGroup(); Rect val2 = new Rect(20f, (num3 - 750f) / 2f, 280f, 750f); GUI.color = new Color(0.065f, 0.08f, 0.1f, 0.98f); GUI.DrawTexture(val2, (Texture)(object)Texture2D.whiteTexture); GUI.color = Color.white; GUI.BeginGroup(val2); DrawFavourites(); GUI.EndGroup(); GUI.color = color; GUI.matrix = matrix; } } private void DrawMenu() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Invalid comparison between Unknown and I4 //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Invalid comparison between Unknown and I4 //IL_0095: 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_0137: 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_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_0206: 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_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_0285: 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_02c7: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: 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_0381: Unknown result type (might be due to invalid IL or missing references) //IL_03ce: Unknown result type (might be due to invalid IL or missing references) //IL_0453: Unknown result type (might be due to invalid IL or missing references) //IL_0492: Unknown result type (might be due to invalid IL or missing references) GUI.Label(new Rect(20f, 12f, 540f, 50f), "LightUpYourWorld", title); GUI.Label(new Rect(25f, 68f, 530f, 55f), targetName, heading); Rect val = default(Rect); ((Rect)(ref val))..ctor(90f, 135f, 400f, 400f); GUI.DrawTexture(val, (Texture)(object)wheel, (ScaleMode)0, true); Event current = Event.current; if ((int)current.type == 0 && current.button == 0 && ((Rect)(ref val)).Contains(current.mousePosition)) { wheelDragging = true; SetFromMouse(current.mousePosition, val); current.Use(); } else if ((int)current.type == 3 && wheelDragging) { SetFromMouse(current.mousePosition, val); current.Use(); } else if ((int)current.type == 1 && wheelDragging) { wheelDragging = false; current.Use(); } Vector2 val2 = ((Rect)(ref val)).center + new Vector2(Mathf.Cos(hue * 2f * MathF.PI), 0f - Mathf.Sin(hue * 2f * MathF.PI)) * (saturation * 200f); GUI.color = Color.black; GUI.DrawTexture(new Rect(val2.x - 7f, val2.y - 7f, 14f, 14f), (Texture)(object)Texture2D.whiteTexture); GUI.color = Color.white; GUI.DrawTexture(new Rect(val2.x - 4f, val2.y - 4f, 8f, 8f), (Texture)(object)Texture2D.whiteTexture); GUI.Label(new Rect(30f, 550f, 160f, 32f), "Brightness", body); float num = GUI.HorizontalSlider(new Rect(200f, 560f, 345f, 25f), brightness, 0f, 1f); if (Mathf.Abs(num - brightness) > 0.0001f) { brightness = num; Preview(); } string text = (session.Dirty ? "Unsaved light preview" : ((session.Saved != 0) ? "Custom colour applied" : "Original light colours")); GUI.Label(new Rect(30f, 588f, 520f, 32f), text, centered); GUI.color = Color.HSVToRGB(hue, saturation, brightness); GUI.DrawTexture(new Rect(30f, 631f, 520f, 38f), (Texture)(object)Texture2D.whiteTexture); GUI.color = Color.white; bool enabled = GUI.enabled; GUI.enabled = session.Dirty; if (GUI.Button(new Rect(20f, 690f, 172f, 60f), (controller && !favouritesMode) ? "A · Apply" : "Apply colour", button)) { Apply(); } GUI.enabled = Object.op_Implicit((Object)(object)target) && (target.Saved != 0 || session.Dirty); if (GUI.Button(new Rect(204f, 690f, 172f, 60f), (controller && !favouritesMode) ? "X · Default" : "Restore default", button)) { RestoreDefault(); } GUI.enabled = enabled; if (GUI.Button(new Rect(388f, 690f, 172f, 60f), (!controller || favouritesMode) ? (session.Dirty ? "Cancel preview" : "Close") : (session.Dirty ? "B · Cancel" : "B · Close"), button)) { if (session.Dirty) { CancelPreview(); } else { Close(); } } GUI.Label(new Rect(30f, 761f, 520f, 40f), (message.Length > 0) ? message : "See the chosen light in the world. Apply saves it.", small); GUI.Label(new Rect(30f, 801f, 520f, 86f), controller ? "Right stick: colour · LB/RB: brightness\nA: apply · X: default · B: cancel / close\nY: favourites · Start: game menu" : "Click / drag the wheel; slider: brightness\nArrow keys: colour · +/-: brightness\nEnter: apply · Delete: default · Esc: close\nTab: favourites · F: save favourite", small); } private void DrawFavourites() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_010d: 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_02de: 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_0156: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_032b: Unknown result type (might be due to invalid IL or missing references) GUI.Label(new Rect(10f, 20f, 260f, 45f), "Favourite colours", heading); GUI.Label(new Rect(15f, 76f, 250f, 55f), (!controller) ? "10 slots saved with your character" : (favouritesMode ? "Choose a slot" : "Y · Open favourites"), centered); Rect val = default(Rect); for (int i = 0; i < 10; i++) { ((Rect)(ref val))..ctor((float)(20 + i % 2 * 125), (float)(120 + i / 2 * 64), 115f, 56f); Color colour; bool flag = LightFavourites.TryGet(Player.m_localPlayer, i, out colour); Color color = GUI.color; GUI.color = ((i == favouriteSlot) ? new Color(1f, 0.72f, 0.15f) : new Color(0.4f, 0.43f, 0.46f)); GUI.DrawTexture(val, (Texture)(object)Texture2D.whiteTexture); GUI.color = (Color)(flag ? colour : new Color(0.1f, 0.12f, 0.14f)); GUI.DrawTexture(new Rect(((Rect)(ref val)).x + 4f, ((Rect)(ref val)).y + 4f, ((Rect)(ref val)).width - 8f, ((Rect)(ref val)).height - 8f), (Texture)(object)Texture2D.whiteTexture); GUI.color = color; if (GUI.Button(val, "", GUIStyle.none)) { favouriteSlot = i; if (flag) { PreviewFavourite(); } } GUI.color = new Color(0f, 0f, 0f, 0.8f); GUI.DrawTexture(new Rect(((Rect)(ref val)).x + 4f, ((Rect)(ref val)).y + 24f, ((Rect)(ref val)).width - 8f, 28f), (Texture)(object)Texture2D.whiteTexture); GUI.color = color; GUI.Label(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y + 22f, ((Rect)(ref val)).width, 30f), i + 1 + (flag ? "" : " · Empty"), centered); } if (GUI.Button(new Rect(20f, 452f, 240f, 48f), (controller && favouritesMode) ? ("Y · Save in slot " + (favouriteSlot + 1)) : ("Save in slot " + (favouriteSlot + 1)), button)) { SaveFavourite(); } bool enabled = GUI.enabled; GUI.enabled = LightFavourites.TryGet(Player.m_localPlayer, favouriteSlot, out var _); if (GUI.Button(new Rect(20f, 510f, 240f, 48f), (controller && favouritesMode) ? "X · Clear favourite" : "Clear favourite", button)) { RemoveFavourite(); } GUI.enabled = enabled; GUI.Label(new Rect(20f, 584f, 240f, 150f), controller ? "In favourites:\nLeft stick / D-pad: slot\nA: preview · Y: save\nX: clear · B: return\nThen A applies to the light." : "Click a saved slot to preview its colour. Apply saves it on the light.\n\nSelect any slot, then Save to store or replace it.", small); } private void SetFromMouse(Vector2 position, Rect rect) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) Vector2 val = position - ((Rect)(ref rect)).center; saturation = Mathf.Clamp01(((Vector2)(ref val)).magnitude / (((Rect)(ref rect)).width * 0.5f)); if (((Vector2)(ref val)).sqrMagnitude > 0.001f) { hue = Mathf.Repeat(Mathf.Atan2(0f - val.y, val.x) / (MathF.PI * 2f), 1f); } Preview(); } private void CreateWheel() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) wheel = new Texture2D(400, 400, (TextureFormat)4, false); ((Object)wheel).name = "LightUpYourWorld_ColourWheel"; ((Texture)wheel).wrapMode = (TextureWrapMode)1; Color32[] array = (Color32[])(object)new Color32[160000]; float num = 199.5f; for (int i = 0; i < 400; i++) { for (int j = 0; j < 400; j++) { float num2 = ((float)j - num) / num; float num3 = ((float)i - num) / num; float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3); array[i * 400 + j] = (Color32)((num4 <= 1f) ? Color32.op_Implicit(Color.HSVToRGB(Mathf.Repeat(Mathf.Atan2(num3, num2) / (MathF.PI * 2f), 1f), num4, 1f)) : new Color32((byte)0, (byte)0, (byte)0, (byte)0)); } } wheel.SetPixels32(array); wheel.Apply(false, true); } } [HarmonyPatch(typeof(Piece), "Awake")] internal static class AttachLightPatch { private static void Postfix(Piece __instance) { WorldLight.Attach(__instance); } } [HarmonyPatch(typeof(Player), "Interact")] internal static class LightInteractionPatch { private static bool Prefix(Player __instance, GameObject __0, bool __1) { LightUpYourWorldPlugin instance = LightUpYourWorldPlugin.Instance; if (!Object.op_Implicit((Object)(object)instance) || (Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return true; } if (instance.BlocksGameplay) { return false; } if (!ZInput.GetButton("JoyLBumper")) { return true; } WorldLight worldLight = WorldLight.Find(__0); if (!Object.op_Implicit((Object)(object)worldLight)) { return true; } if (!__1) { instance.Open(worldLight); } return false; } } [HarmonyPatch(typeof(Player), "TakeInput")] internal static class PlayerInputPatch { private static void Postfix(ref bool __result) { if (Object.op_Implicit((Object)(object)LightUpYourWorldPlugin.Instance) && LightUpYourWorldPlugin.Instance.BlocksGameplay) { __result = false; } } } [HarmonyPatch(typeof(PlayerController), "TakeInput")] internal static class ControllerInputPatch { private static void Postfix(ref bool __result) { if (Object.op_Implicit((Object)(object)LightUpYourWorldPlugin.Instance) && LightUpYourWorldPlugin.Instance.BlocksGameplay) { __result = false; } } } [HarmonyPatch(typeof(HotkeyBar), "Update")] internal static class HotbarPatch { private static bool Prefix() { if (Object.op_Implicit((Object)(object)LightUpYourWorldPlugin.Instance)) { return !LightUpYourWorldPlugin.Instance.BlocksGameplay; } return true; } } [HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")] internal static class CursorPatch { private static void Postfix() { if (Object.op_Implicit((Object)(object)LightUpYourWorldPlugin.Instance)) { LightUpYourWorldPlugin.Instance.KeepCursor(); } } } [HarmonyPatch(typeof(Character), "Damage")] internal static class DamagePatch { private static void Prefix(Character __instance) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && Object.op_Implicit((Object)(object)LightUpYourWorldPlugin.Instance)) { LightUpYourWorldPlugin.Instance.Close(); } } } public sealed class WorldLight : MonoBehaviour { internal static readonly HashSet<WorldLight> Sources = new HashSet<WorldLight>(); private readonly Dictionary<Light, Color> originals = new Dictionary<Light, Color>(); private ZNetView view; private Piece piece; private int saved; private int applied = -1; private bool initialized; private bool preview; private int previewColour; private float nextRead; private bool refreshRequested = true; internal bool Ready { get { if (initialized && Object.op_Implicit((Object)(object)view) && view.IsValid()) { return originals.Count > 0; } return false; } } internal int Saved { get { if (!Ready) { return 0; } return LightColour.Normalize(view.GetZDO().GetInt("LightUpYourWorld.Colour", 0)); } } internal string DisplayName { get { if (!Object.op_Implicit((Object)(object)piece)) { return "Light"; } return LightUpYourWorldPlugin.Localize(piece.m_name); } } internal Color OriginalColour { get { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) foreach (KeyValuePair<Light, Color> original in originals) { if (Object.op_Implicit((Object)(object)original.Key)) { return original.Value; } } return Color.white; } } internal static WorldLight Find(GameObject obj) { if (!Object.op_Implicit((Object)(object)obj)) { return null; } Piece componentInParent = obj.GetComponentInParent<Piece>(); if (!Object.op_Implicit((Object)(object)componentInParent)) { return null; } ZNetView component = ((Component)componentInParent).GetComponent<ZNetView>(); if (!Object.op_Implicit((Object)(object)component) || !component.IsValid()) { return null; } WorldLight worldLight = ((Component)componentInParent).GetComponent<WorldLight>(); if (!Object.op_Implicit((Object)(object)worldLight) && Object.op_Implicit((Object)(object)((Component)componentInParent).GetComponentInChildren<Light>(true))) { worldLight = ((Component)componentInParent).gameObject.AddComponent<WorldLight>(); } if (!Object.op_Implicit((Object)(object)worldLight) || !worldLight.Ready) { return null; } return worldLight; } internal static void Attach(Piece owner) { if (Object.op_Implicit((Object)(object)owner)) { ZNetView component = ((Component)owner).GetComponent<ZNetView>(); if (Object.op_Implicit((Object)(object)component) && component.IsValid() && !Object.op_Implicit((Object)(object)((Component)owner).GetComponent<WorldLight>()) && Object.op_Implicit((Object)(object)((Component)owner).GetComponentInChildren<Light>(true))) { ((Component)owner).gameObject.AddComponent<WorldLight>(); } } } private void OnEnable() { Sources.Add(this); } private void OnDisable() { Sources.Remove(this); EndPreview(); } private void OnDestroy() { Sources.Remove(this); } private void Start() { piece = ((Component)this).GetComponent<Piece>(); view = ((Component)this).GetComponent<ZNetView>(); if (!Object.op_Implicit((Object)(object)piece) || !Object.op_Implicit((Object)(object)view) || !view.IsValid()) { ((Behaviour)this).enabled = false; } else { initialized = true; } } internal void RefreshLights() { //IL_004a: Unknown result type (might be due to invalid IL or missing references) if (!initialized) { return; } Light[] componentsInChildren = ((Component)this).GetComponentsInChildren<Light>(true); foreach (Light val in componentsInChildren) { if (Object.op_Implicit((Object)(object)val) && !((Object)(object)((Component)val).GetComponentInParent<Piece>() != (Object)(object)piece) && !originals.ContainsKey(val)) { originals.Add(val, val.color); applied = -1; } } } private void OnTransformChildrenChanged() { refreshRequested = true; } internal void Tick() { //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: 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) if (!initialized || !Object.op_Implicit((Object)(object)view) || !view.IsValid()) { return; } if (refreshRequested) { refreshRequested = false; RefreshLights(); } if (Time.unscaledTime >= nextRead) { saved = Saved; nextRead = Time.unscaledTime + 0.25f; } int num = (preview ? previewColour : saved); if (num == 0) { if (applied != 0) { foreach (KeyValuePair<Light, Color> original in originals) { if (Object.op_Implicit((Object)(object)original.Key)) { original.Key.color = original.Value; } } } } else { Color val = Unpack(num); foreach (KeyValuePair<Light, Color> original2 in originals) { if (Object.op_Implicit((Object)(object)original2.Key) && ((Component)original2.Key).gameObject.activeInHierarchy && original2.Key.color != val) { original2.Key.color = val; } } } applied = num; } internal static int Pack(Color colour) { //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_0006: 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_000d: 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) Color32 val = Color32.op_Implicit(colour); return LightColour.Pack(val.r, val.g, val.b); } internal static Color Unpack(int colour) { //IL_0017: 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) return Color32.op_Implicit(new Color32(LightColour.Red(colour), LightColour.Green(colour), LightColour.Blue(colour), byte.MaxValue)); } internal void Preview(int colour) { preview = true; previewColour = LightColour.Normalize(colour); Tick(); } internal void EndPreview() { preview = false; nextRead = 0f; Tick(); } internal bool CanEdit(Player player, bool flash) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0029: 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) if (Object.op_Implicit((Object)(object)player) && Ready && !((Character)player).IsDead() && Vector3.Distance(((Component)player).transform.position, ((Component)this).transform.position) <= 8f) { return PrivateArea.CheckAccess(((Component)this).transform.position, 0f, flash, false); } return false; } internal bool Commit(int colour) { if (!LightColour.IsValid(colour) || !CanEdit(Player.m_localPlayer, flash: true)) { return false; } view.ClaimOwnership(); if (!view.IsOwner()) { return false; } view.GetZDO().Set("LightUpYourWorld.Colour", colour); saved = colour; preview = false; nextRead = 0f; Tick(); return true; } internal void RestoreForUnload() { //IL_002d: Unknown result type (might be due to invalid IL or missing references) foreach (KeyValuePair<Light, Color> original in originals) { if (Object.op_Implicit((Object)(object)original.Key)) { original.Key.color = original.Value; } } } } internal static class LightColour { internal const string SaveKey = "LightUpYourWorld.Colour"; internal static int Pack(byte r, byte g, byte b) { return 0x1000000 | (r << 16) | (g << 8) | b; } internal static bool IsValid(int value) { if (value != 0) { return (value & -16777216) == 16777216; } return true; } internal static int Normalize(int value) { if (!IsValid(value)) { return 0; } return value; } internal static byte Red(int value) { return (byte)(value >> 16); } internal static byte Green(int value) { return (byte)(value >> 8); } internal static byte Blue(int value) { return (byte)value; } } internal sealed class ColourSession { internal int Saved { get; private set; } internal int Selected { get; private set; } internal bool Dirty { get; private set; } internal void Open(int saved) { int saved2 = (Selected = LightColour.Normalize(saved)); Saved = saved2; Dirty = false; } internal void Preview(int value) { Selected = LightColour.Normalize(value); Dirty = Selected != Saved; } internal void Applied() { Saved = Selected; Dirty = false; } internal void Cancel(int latestSaved) { Open(latestSaved); } } internal static class MenuLayout { internal static float Scale(float width, float height) { return Math.Min(height / 1100f, width / 1900f); } } internal static class LightFavourites { internal const int Slots = 10; private const string Prefix = "LightUpYourWorld.Favourite."; private static readonly FieldInfo CustomData = AccessTools.Field(typeof(Player), "m_customData"); private static Dictionary<string, string> Data(Player player) { if (!Object.op_Implicit((Object)(object)player) || !(CustomData != null)) { return null; } return CustomData.GetValue(player) as Dictionary<string, string>; } internal static bool TryGet(Player player, int slot, out Color colour) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_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) colour = Color.white; if (slot < 0 || slot >= 10) { return false; } Dictionary<string, string> dictionary = Data(player); if (dictionary == null || !dictionary.TryGetValue("LightUpYourWorld.Favourite." + slot, out var value) || value == null || value.Length != 6) { return false; } if (!int.TryParse(value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var result)) { return false; } colour = new Color((float)((result >> 16) & 0xFF) / 255f, (float)((result >> 8) & 0xFF) / 255f, (float)(result & 0xFF) / 255f, 1f); return true; } internal static void Set(Player player, int slot, Color colour) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) if (slot >= 0 && slot < 10) { Dictionary<string, string> dictionary = Data(player); if (dictionary != null) { Color32 val = Color32.op_Implicit(colour); dictionary["LightUpYourWorld.Favourite." + slot] = val.r.ToString("X2") + val.g.ToString("X2") + val.b.ToString("X2"); } } } internal static void Remove(Player player, int slot) { Dictionary<string, string> dictionary = Data(player); if (slot >= 0 && slot < 10) { dictionary?.Remove("LightUpYourWorld.Favourite." + slot); } } internal static int FirstEmpty(Player player) { for (int i = 0; i < 10; i++) { if (!TryGet(player, i, out var _)) { return i; } } return 0; } } [HarmonyPatch(typeof(Hud), "UpdateCrosshair")] internal static class NativeLightPrompt { private static readonly FieldInfo HoverLabel = AccessTools.Field(typeof(Hud), "m_hoverName"); private static PropertyInfo textProperty; private static void Postfix(Hud __instance, Player __0) { LightUpYourWorldPlugin instance = LightUpYourWorldPlugin.Instance; if (!Object.op_Implicit((Object)(object)instance) || instance.IsOpen || !Object.op_Implicit((Object)(object)__0) || (Object)(object)__0 != (Object)(object)Player.m_localPlayer || ((Character)__0).InPlaceMode() || !LightUpYourWorldPlugin.CanTakeInput(__0)) { return; } WorldLight worldLight = WorldLight.Find(((Humanoid)__0).GetHoverObject()); if (!Object.op_Implicit((Object)(object)worldLight) || HoverLabel == null) { return; } object value = HoverLabel.GetValue(__instance); if (value == null) { return; } if (textProperty == null) { textProperty = value.GetType().GetProperty("text"); } if (!(textProperty == null)) { string text = (textProperty.GetValue(value, null) as string) ?? ""; string hoverPrompt = instance.HoverPrompt; if (!text.Contains(hoverPrompt)) { textProperty.SetValue(value, ((text.Length > 0) ? text.TrimEnd() : worldLight.DisplayName) + "\n" + hoverPrompt, null); } } } }