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 PaintBrush v0.2.0
PaintBrush.dll
Decompiled 3 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using PaintBrush.Brush; using PaintBrush.Core; using PaintBrush.History; using PaintBrush.Painting; using PaintBrush.UI; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: IgnoresAccessChecksTo("")] [assembly: AssemblyCompany("PaintBrush")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Paint your buildings: a paint brush, taken out with one key, colours built pieces in any shade and strength, and clears them back to vanilla. Only players with the mod see the paint.")] [assembly: AssemblyFileVersion("0.2.0.0")] [assembly: AssemblyInformationalVersion("0.2.0+833ea68409d0b2257a9de668df605a023c9e03f4")] [assembly: AssemblyProduct("PaintBrush")] [assembly: AssemblyTitle("PaintBrush")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.2.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] [DebuggerDisplay("Count = {System.Collections.ICollection.Count}")] [CompilerGenerated] internal sealed class <>z__ReadOnlyArray<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T> { int ICollection.Count => _items.Length; bool ICollection.IsSynchronized => false; object ICollection.SyncRoot => this; object IList.this[int index] { get { return _items[index]; } set { throw new NotSupportedException(); } } bool IList.IsFixedSize => true; bool IList.IsReadOnly => true; int IReadOnlyCollection<T>.Count => _items.Length; T IReadOnlyList<T>.this[int index] => _items[index]; int ICollection<T>.Count => _items.Length; bool ICollection<T>.IsReadOnly => true; T IList<T>.this[int index] { get { return _items[index]; } set { throw new NotSupportedException(); } } public <>z__ReadOnlyArray(T[] items) { _items = items; } IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)_items).GetEnumerator(); } void ICollection.CopyTo(Array array, int index) { ((ICollection)_items).CopyTo(array, index); } int IList.Add(object value) { throw new NotSupportedException(); } void IList.Clear() { throw new NotSupportedException(); } bool IList.Contains(object value) { return ((IList)_items).Contains(value); } int IList.IndexOf(object value) { return ((IList)_items).IndexOf(value); } void IList.Insert(int index, object value) { throw new NotSupportedException(); } void IList.Remove(object value) { throw new NotSupportedException(); } void IList.RemoveAt(int index) { throw new NotSupportedException(); } IEnumerator<T> IEnumerable<T>.GetEnumerator() { return ((IEnumerable<T>)_items).GetEnumerator(); } void ICollection<T>.Add(T item) { throw new NotSupportedException(); } void ICollection<T>.Clear() { throw new NotSupportedException(); } bool ICollection<T>.Contains(T item) { return ((ICollection<T>)_items).Contains(item); } void ICollection<T>.CopyTo(T[] array, int arrayIndex) { ((ICollection<T>)_items).CopyTo(array, arrayIndex); } bool ICollection<T>.Remove(T item) { throw new NotSupportedException(); } int IList<T>.IndexOf(T item) { return ((IList<T>)_items).IndexOf(item); } void IList<T>.Insert(int index, T item) { throw new NotSupportedException(); } void IList<T>.RemoveAt(int index) { throw new NotSupportedException(); } } 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 PaintBrush { [BepInPlugin("javidahmed64592.paintbrush", "Paint Brush", "0.2.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class PaintBrushPlugin : BaseUnityPlugin { public const string PluginGUID = "javidahmed64592.paintbrush"; public const string PluginName = "Paint Brush"; public const string PluginVersion = "0.2.0"; private Harmony _harmony; private void Awake() { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown PhantomBrush.BindConfig(((BaseUnityPlugin)this).Config); PaintTextures.BindConfig(((BaseUnityPlugin)this).Config); ConnectedPieces.BindConfig(((BaseUnityPlugin)this).Config); PaintHistory.BindConfig(((BaseUnityPlugin)this).Config); Translations.Load(); BrushPrefabs.Register(); _harmony = new Harmony("javidahmed64592.paintbrush"); _harmony.PatchAll(); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private void Update() { Player localPlayer = Player.m_localPlayer; PhantomBrush.Update(localPlayer); BrushState.Sync(localPlayer); BrushModel.Update(localPlayer); if ((Object)(object)localPlayer == (Object)null) { PaintHistory.Reset(); } else if (BrushTools.Selected(localPlayer) != BrushTool.None) { PaintHistory.UpdateKeys(localPlayer); } PaintPreview.Update(localPlayer); PaintedPieces.Update(); PaintPanel.Update(localPlayer); } } } namespace PaintBrush.UI { internal static class BrushKeyHints { private sealed class Hint { public string[] Keys; public Func<BrushTool, string> Label; public CanvasGroup Group; public TextMeshProUGUI LabelText; public string ShownLabel; } private sealed class VanillaHint { public GameObject Item; public TextMeshProUGUI Label; public string OriginalText; public bool Changed; } private const string ContainerName = "PaintBrush_KeyHints"; private const string UndoKey = "@undo"; private const string RedoKey = "@redo"; private const float LabelFontSize = 16f; private const float KeyHeight = 32f; private const float RowSpacing = 16f; private const float Gap = 16f; private static readonly List<Hint> Hints = new List<Hint>(3) { new Hint { Keys = new string[1] { "@undo" }, Label = (BrushTool _) => (!PaintHistory.CanUndo) ? null : "$paintbrush_hint_undo" }, new Hint { Keys = new string[1] { "@redo" }, Label = (BrushTool _) => (!PaintHistory.CanRedo) ? null : "$paintbrush_hint_redo" }, new Hint { Keys = new string[2] { "Left Alt", "$KEY_Attack" }, Label = (BrushTool tool) => tool switch { BrushTool.Paint => "$paintbrush_hint_paint_connected", BrushTool.Clear => "$paintbrush_hint_clear_connected", _ => null, } } }; private static readonly string[] AllLabels = new string[4] { "$paintbrush_hint_undo", "$paintbrush_hint_redo", "$paintbrush_hint_paint_connected", "$paintbrush_hint_clear_connected" }; private static readonly string[] VanillaNames = new string[8] { "Place", "Remove", "BuildMenu", "AltPlace", "Snap", "Copy", "rotate", "Favorite" }; private static readonly Dictionary<string, VanillaHint> Vanilla = new Dictionary<string, VanillaHint>(); private static RectTransform _keyboard; private static GameObject _container; private static RectTransform _stack; private static bool _createFailed; private static bool _layoutDirty; internal static void AfterUpdateHints(KeyHints keyHints) { if (_keyboard != null && (Object)(object)_keyboard == (Object)null) { Reset(); } BrushTool brushTool = BrushTools.Selected(Player.m_localPlayer); if (brushTool == BrushTool.None || !((Object)(object)keyHints.m_buildHints != (Object)null) || !keyHints.m_buildHints.activeInHierarchy || ZInput.IsGamepadActive()) { Restore(); SetContainerActive(active: false); } else { if ((Object)(object)_keyboard == (Object)null && (_createFailed || !Create(keyHints))) { return; } Set("Place", active: true, brushTool switch { BrushTool.Paint => "$paintbrush_hint_paint", BrushTool.Clear => "$paintbrush_hint_clear", _ => "$paintbrush_hint_pick", }); Set("Remove", active: false, null); Set("BuildMenu", active: true, "$paintbrush_hint_menu"); Set("AltPlace", brushTool == BrushTool.Pick, "$paintbrush_hint_pick_vanilla"); Set("Snap", active: false, null); Set("Copy", active: false, null); Set("rotate", active: false, null); Set("Favorite", active: false, null); bool num = !Hud.IsPieceSelectionVisible(); SetContainerActive(num); if (!num) { return; } foreach (Hint hint in Hints) { string text = hint.Label(brushTool); hint.Group.alpha = ((text != null) ? 1f : 0f); if (text != null && text != hint.ShownLabel) { hint.ShownLabel = text; ((TMP_Text)hint.LabelText).text = Localization.instance.Localize(text); } } if (_layoutDirty) { LayoutRebuilder.ForceRebuildLayoutImmediate(_stack); _layoutDirty = false; } Align(); } } private static bool Create(KeyHints keyHints) { //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_034d: Unknown result type (might be due to invalid IL or missing references) //IL_0357: Expected O, but got Unknown Transform val = keyHints.m_buildHints.transform.Find("Keyboard"); Transform val2 = (((Object)(object)val != (Object)null) ? val.Find("Copy") : null); Transform val3 = (((Object)(object)val2 != (Object)null) ? val2.Find("Text") : null); Transform val4 = (((Object)(object)val2 != (Object)null) ? val2.Find("Text (1)") : null); Transform val5 = (((Object)(object)val2 != (Object)null) ? val2.Find("key_bkg") : null); HorizontalLayoutGroup val6 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<HorizontalLayoutGroup>() : null); if ((Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null || (Object)(object)val5 == (Object)null || (Object)(object)val6 == (Object)null) { _createFailed = true; Logger.LogWarning((object)"Vanilla build key hints layout not as expected, not changing the brush's key hints."); return false; } Vanilla.Clear(); string[] vanillaNames = VanillaNames; foreach (string text in vanillaNames) { Transform val7 = val.Find(text); if (!((Object)(object)val7 == (Object)null)) { Transform obj = val7.Find("Text"); TextMeshProUGUI val8 = ((obj != null) ? ((Component)obj).GetComponent<TextMeshProUGUI>() : null); Vanilla[text] = new VanillaHint { Item = ((Component)val7).gameObject, Label = val8, OriginalText = (((Object)(object)val8 != (Object)null) ? ((TMP_Text)val8).text : null) }; } } RectTransform component = new GameObject("PaintBrush_KeyHints", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>(); ((Transform)component).SetParent(keyHints.m_buildHints.transform, false); RectTransform val9 = CreateStack(component); string text2 = LongestLabel(); foreach (Hint hint in Hints) { GameObject val10 = Object.Instantiate<GameObject>(((Component)val2).gameObject, (Transform)(object)val9, false); ((Object)val10).name = "PaintBrush_Hint"; val10.SetActive(true); for (int num = val10.transform.childCount - 1; num >= 0; num--) { Object.DestroyImmediate((Object)(object)((Component)val10.transform.GetChild(num)).gameObject); } hint.LabelText = AddText(val3, val10.transform, text2); ((TMP_Text)hint.LabelText).alignment = (TextAlignmentOptions)516; hint.ShownLabel = null; Transform val11 = CreateKeyGroup(val10.transform, val6); string[] array = ExpandShortcuts(hint.Keys); for (int j = 0; j < array.Length; j++) { if (j > 0) { AddText(val4, val11, "+"); } GameObject obj2 = Object.Instantiate<GameObject>(((Component)val5).gameObject, val11, false); obj2.SetActive(true); ((TMP_Text)obj2.GetComponentInChildren<TextMeshProUGUI>()).text = Localization.instance.Localize(array[j]); } hint.Group = val10.GetComponent<CanvasGroup>() ?? val10.AddComponent<CanvasGroup>(); } LayoutRebuilder.ForceRebuildLayoutImmediate(val9); EqualiseWidths(); foreach (Hint hint2 in Hints) { ((TMP_Text)hint2.LabelText).text = ""; } _container = ((Component)component).gameObject; _stack = val9; _keyboard = (RectTransform)val; _layoutDirty = true; return true; } private static void Align() { //IL_003e: 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_008b: Unknown result type (might be due to invalid IL or missing references) Vector3[] array = (Vector3[])(object)new Vector3[4]; _keyboard.GetWorldCorners(array); HorizontalLayoutGroup component = ((Component)_keyboard).GetComponent<HorizontalLayoutGroup>(); float num = (((Object)(object)component != (Object)null) ? ((float)((LayoutGroup)component).padding.right * ((Transform)_keyboard).lossyScale.x) : 0f); ((Transform)_stack).position = new Vector3(array[2].x - num, array[2].y + 16f * ((Transform)_keyboard).lossyScale.y, array[2].z); } private static RectTransform CreateStack(RectTransform parent) { //IL_0018: 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) RectTransform component = new GameObject("PaintBrush_KeyHints_Stack", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>(); ((Transform)component).SetParent((Transform)(object)parent, false); component.pivot = new Vector2(1f, 0f); VerticalLayoutGroup obj = ((Component)component).gameObject.AddComponent<VerticalLayoutGroup>(); ((HorizontalOrVerticalLayoutGroup)obj).spacing = 16f; ((LayoutGroup)obj).childAlignment = (TextAnchor)8; ((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true; ((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false; ContentSizeFitter obj2 = ((Component)component).gameObject.AddComponent<ContentSizeFitter>(); obj2.horizontalFit = (FitMode)2; obj2.verticalFit = (FitMode)2; return component; } private static Transform CreateKeyGroup(Transform row, HorizontalLayoutGroup template) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("Keys", new Type[1] { typeof(RectTransform) }); val.transform.SetParent(row, false); HorizontalLayoutGroup obj = val.AddComponent<HorizontalLayoutGroup>(); ((HorizontalOrVerticalLayoutGroup)obj).spacing = ((HorizontalOrVerticalLayoutGroup)template).spacing; ((LayoutGroup)obj).childAlignment = (TextAnchor)3; ((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = ((HorizontalOrVerticalLayoutGroup)template).childControlWidth; ((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = ((HorizontalOrVerticalLayoutGroup)template).childControlHeight; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false; ((RectTransform)val.transform).sizeDelta = new Vector2(0f, 32f); LayoutElement obj2 = val.AddComponent<LayoutElement>(); float minHeight = (obj2.preferredHeight = 32f); obj2.minHeight = minHeight; return val.transform; } private static void EqualiseWidths() { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_00a1: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < 2; i++) { float num = 0f; foreach (Hint hint in Hints) { num = Mathf.Max(num, LayoutUtility.GetPreferredWidth((RectTransform)((Component)hint.Group).transform.GetChild(i))); } if (i == 0 && Hints.Count > 0) { TextMeshProUGUI labelText = Hints[0].LabelText; string[] allLabels = AllLabels; foreach (string text in allLabels) { num = Mathf.Max(num, ((TMP_Text)labelText).GetPreferredValues(Localization.instance.Localize(text)).x); } } foreach (Hint hint2 in Hints) { GameObject gameObject = ((Component)((Component)hint2.Group).transform.GetChild(i)).gameObject; LayoutElement obj = gameObject.GetComponent<LayoutElement>() ?? gameObject.AddComponent<LayoutElement>(); obj.minWidth = num; obj.preferredWidth = num; } } } private static string LongestLabel() { string text = ""; string[] allLabels = AllLabels; foreach (string text2 in allLabels) { string text3 = Localization.instance.Localize(text2); if (text3.Length > text.Length) { text = text3; } } return text; } private static TextMeshProUGUI AddText(Transform template, Transform parent, string text) { GameObject obj = Object.Instantiate<GameObject>(((Component)template).gameObject, parent, false); obj.SetActive(true); LayoutElement component = obj.GetComponent<LayoutElement>(); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } TextMeshProUGUI component2 = obj.GetComponent<TextMeshProUGUI>(); ((TMP_Text)component2).enableAutoSizing = false; ((TMP_Text)component2).fontSize = 16f; ((TMP_Text)component2).textWrappingMode = (TextWrappingModes)0; ((TMP_Text)component2).text = text; return component2; } private static string[] ExpandShortcuts(string[] keys) { //IL_004a: 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) //IL_004f: 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_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) List<string> list = new List<string>(); foreach (string text in keys) { if (!(text == "@undo") && !(text == "@redo")) { list.Add(text); continue; } KeyboardShortcut val = ((text == "@undo") ? PaintHistory.UndoKey : PaintHistory.RedoKey); foreach (KeyCode modifier in ((KeyboardShortcut)(ref val)).Modifiers) { list.Add(KeyName(modifier)); } list.Add(KeyName(((KeyboardShortcut)(ref val)).MainKey)); } return list.ToArray(); } private unsafe static string KeyName(KeyCode key) { //IL_0000: 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_0024: Expected I4, but got Unknown return (key - 303) switch { 3 => "Left Ctrl", 2 => "Right Ctrl", 1 => "Left Shift", 0 => "Right Shift", 5 => "Left Alt", 4 => "Right Alt", _ => ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString(), }; } private static void Set(string name, bool active, string label) { if (!Vanilla.TryGetValue(name, out var value) || (Object)(object)value.Item == (Object)null) { return; } if (value.Item.activeSelf != active) { value.Item.SetActive(active); value.Changed = true; } if (!((Object)(object)value.Label == (Object)null) && active && label != null) { string text = Localization.instance.Localize(label); if (((TMP_Text)value.Label).text != text) { ((TMP_Text)value.Label).text = text; value.Changed = true; } } } private static void Restore() { foreach (VanillaHint value in Vanilla.Values) { if (value.Changed && !((Object)(object)value.Item == (Object)null)) { value.Item.SetActive(true); if ((Object)(object)value.Label != (Object)null) { ((TMP_Text)value.Label).text = value.OriginalText; } value.Changed = false; } } } private static void SetContainerActive(bool active) { if ((Object)(object)_container != (Object)null && _container.activeSelf != active) { _container.SetActive(active); _layoutDirty |= active; } } private static void Reset() { _keyboard = null; _container = null; _stack = null; _createFailed = false; Vanilla.Clear(); foreach (Hint hint in Hints) { hint.Group = null; hint.LabelText = null; hint.ShownLabel = null; } } } internal sealed class DragArea : MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IDragHandler, IBeginDragHandler { public Action<Vector2> Changed; public void OnPointerDown(PointerEventData eventData) { Report(eventData); } public void OnBeginDrag(PointerEventData eventData) { Report(eventData); } public void OnDrag(PointerEventData eventData) { Report(eventData); } private void Report(PointerEventData eventData) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown //IL_0017: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) if ((int)eventData.button == 0) { RectTransform val = (RectTransform)((Component)this).transform; Vector2 val2 = default(Vector2); if (RectTransformUtility.ScreenPointToLocalPointInRectangle(val, eventData.position, eventData.pressEventCamera, ref val2)) { Rect rect = val.rect; Changed?.Invoke(new Vector2(Mathf.Clamp01((val2.x - ((Rect)(ref rect)).xMin) / ((Rect)(ref rect)).width), Mathf.Clamp01((val2.y - ((Rect)(ref rect)).yMin) / ((Rect)(ref rect)).height))); } } } } internal sealed class Swatch : MonoBehaviour, IPointerClickHandler, IEventSystemHandler, IPointerEnterHandler, IPointerExitHandler { private static readonly Color Normal = new Color(0f, 0f, 0f, 0.9f); private static readonly Color Hover = new Color(1f, 0.72f, 0.36f, 1f); public Action<InputButton> Clicked; public Image Image; public Outline Outline; public void OnPointerClick(PointerEventData eventData) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) Clicked?.Invoke(eventData.button); } public void OnPointerEnter(PointerEventData eventData) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Outline != (Object)null) { ((Shadow)Outline).effectColor = Hover; } } public void OnPointerExit(PointerEventData eventData) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Outline != (Object)null) { ((Shadow)Outline).effectColor = Normal; } } public static void Style(Outline outline) { //IL_0001: 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) ((Shadow)outline).effectColor = Normal; ((Shadow)outline).effectDistance = new Vector2(2f, -2f); } } internal static class MenuTitle { private const string TitleName = "PaintBrush_MenuTitle"; private const string BetterHoeGuid = "javidahmed64592.betterhoe"; private static readonly Color TitleColor = new Color(1f, 0.72f, 0.36f); private static TextMeshProUGUI _title; private static bool _changed; internal static void AfterUpdateTagButtons(BuildUi buildUi) { RectTransform tabContainer = buildUi.m_tabContainer; if ((Object)(object)tabContainer == (Object)null || (Object)(object)((Transform)tabContainer).parent == (Object)null) { return; } bool flag = BrushPrefabs.IsBrushTable(buildUi.m_currentBuildTool); if (flag) { SetActive(((Transform)tabContainer).parent.Find("InputHelp"), active: false); SetActive(((Transform)tabContainer).parent.Find("TabBorder"), active: true); _changed = true; if ((Object)(object)_title == (Object)null) { _title = CreateTitle(tabContainer); } } else if (_changed) { _changed = false; if (!Chainloader.PluginInfos.ContainsKey("javidahmed64592.betterhoe")) { SetActive(((Transform)tabContainer).parent.Find("InputHelp"), active: true); } } if ((Object)(object)_title != (Object)null && ((Component)_title).gameObject.activeSelf != flag) { ((Component)_title).gameObject.SetActive(flag); } } private static void SetActive(Transform item, bool active) { if ((Object)(object)item != (Object)null && ((Component)item).gameObject.activeSelf != active) { ((Component)item).gameObject.SetActive(active); } } private static TextMeshProUGUI CreateTitle(RectTransform tabs) { //IL_002b: 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_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_00ba: Unknown result type (might be due to invalid IL or missing references) TextMeshProUGUI componentInChildren = ((Component)tabs).GetComponentInChildren<TextMeshProUGUI>(true); if ((Object)(object)componentInChildren == (Object)null) { return null; } RectTransform component = new GameObject("PaintBrush_MenuTitle", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>(); ((Transform)component).SetParent(((Transform)tabs).parent, false); component.anchorMin = tabs.anchorMin; component.anchorMax = tabs.anchorMax; component.pivot = tabs.pivot; component.anchoredPosition = tabs.anchoredPosition; component.sizeDelta = tabs.sizeDelta; TextMeshProUGUI obj = ((Component)component).gameObject.AddComponent<TextMeshProUGUI>(); ((TMP_Text)obj).font = ((TMP_Text)componentInChildren).font; ((TMP_Text)obj).fontSharedMaterial = ((TMP_Text)componentInChildren).fontSharedMaterial; ((TMP_Text)obj).fontSize = ((TMP_Text)componentInChildren).fontSize * 1.25f; ((TMP_Text)obj).enableAutoSizing = false; ((Graphic)obj).color = TitleColor; ((TMP_Text)obj).alignment = (TextAlignmentOptions)514; ((TMP_Text)obj).textWrappingMode = (TextWrappingModes)0; ((Graphic)obj).raycastTarget = false; ((TMP_Text)obj).text = Localization.instance.Localize("$paintbrush_menu_title"); return obj; } } internal static class PaintPanel { private sealed class SliderRow { public RawImage Track; public Texture2D Gradient; public RectTransform Handle; public InputField Field; public int Max; public Func<int> Get; public Action<int> Set; public Func<float, Color> ColorAt; } private const float Width = 1004f; private const float Height = 272f; private const float Gap = 18f; private const float Shift = 290f; private const float SquareSize = 250f; private const int SquareResolution = 64; private const int GradientResolution = 64; private static readonly Color LabelColor = new Color(1f, 0.72f, 0.36f); private static readonly Color TextColor = new Color(0.85f, 0.78f, 0.65f); private static readonly Color EmptySlot = new Color(0.12f, 0.09f, 0.07f, 0.9f); private static readonly Color Wood = new Color(0.45f, 0.32f, 0.2f); private static readonly List<SliderRow> Rows = new List<SliderRow>(); private static readonly List<InputField> Fields = new List<InputField>(); private static readonly Swatch[] PaletteSwatches = new Swatch[16]; private static readonly Swatch[] RecentSwatches = new Swatch[8]; private static RectTransform _root; private static bool _failed; private static bool _updating; private static bool _blocking; private static Texture2D _squareTexture; private static Texture2D _hueTexture; private static Sprite _white; private static Sprite _ring; private static RectTransform _squareKnob; private static RectTransform _hueMarker; private static InputField _hex; private static Image _current; private static RawImage _vanilla; private static RawImage _painted; private static RectTransform _shiftedView; private static int _shownVersion = -1; private static float _shownHue = -1f; private static Texture _shownSample; private static Color32 _sampleAverage; public static void Update(Player player) { BuildUi val = (((Object)(object)Hud.instance != (Object)null) ? Hud.instance.m_buildUi : null); if (!((Object)(object)player != (Object)null) || !((Object)(object)val != (Object)null) || !Hud.IsPieceSelectionVisible() || !BrushPrefabs.IsBrushTable(val.m_currentBuildTool)) { if ((Object)(object)_root != (Object)null && ((Component)_root).gameObject.activeSelf) { ((Component)_root).gameObject.SetActive(false); } ShiftGrid(null); SetBlocking(block: false); } else if (!((Object)(object)_root == (Object)null) || (!_failed && Create(val))) { if (!((Component)_root).gameObject.activeSelf) { ((Component)_root).gameObject.SetActive(true); _shownVersion = -1; } Position(val); Refresh(); SetBlocking(AnyFieldFocused()); } } private static void SetBlocking(bool block) { if (block != _blocking) { _blocking = block; GUIManager.BlockInput(block); } } private static bool AnyFieldFocused() { foreach (InputField field in Fields) { if ((Object)(object)field != (Object)null && field.isFocused) { return true; } } return false; } private static void ShiftGrid(RectTransform view) { //IL_0021: 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_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_shiftedView == (Object)(object)view)) { if ((Object)(object)_shiftedView != (Object)null) { RectTransform shiftedView = _shiftedView; shiftedView.offsetMax += new Vector2(0f, 290f); } _shiftedView = view; if ((Object)(object)view != (Object)null) { view.offsetMax -= new Vector2(0f, 290f); } } } private static void Position(BuildUi ui) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005e: 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_006a: 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) RectTransform pieceView = ui.m_pieceView; if (!((Object)(object)pieceView == (Object)null)) { ShiftGrid(pieceView); RectTransform val = (RectTransform)((Transform)_root).parent; Vector3[] array = (Vector3[])(object)new Vector3[4]; pieceView.GetWorldCorners(array); Vector3 val2 = ((Transform)val).InverseTransformPoint(array[1]); RectTransform root = _root; float x = val2.x; Rect rect = val.rect; float num = x - ((Rect)(ref rect)).xMin; float y = val2.y; rect = val.rect; root.anchoredPosition = new Vector2(num, y - ((Rect)(ref rect)).yMax + 290f); } } private static void Refresh() { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_028f: 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_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_026f: 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_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_0300: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_0362: Unknown result type (might be due to invalid IL or missing references) //IL_034f: Unknown result type (might be due to invalid IL or missing references) Texture texture = null; bool cutout = false; Piece lastAimed = PaintPreview.LastAimed; if ((Object)(object)lastAimed != (Object)null) { PaintedPieces.SampleTexture(lastAimed, out texture, out cutout); } if (BrushState.Version == _shownVersion && (Object)(object)texture == (Object)(object)_shownSample) { return; } if ((Object)(object)texture != (Object)(object)_shownSample) { _shownSample = texture; _sampleAverage = (((Object)(object)texture != (Object)null) ? PaintTextures.AverageColor(texture, cutout) : Color32.op_Implicit(Wood)); } _shownVersion = BrushState.Version; _updating = true; try { Color32 color = BrushState.Color; if (!Mathf.Approximately(_shownHue, BrushState.Hue)) { _shownHue = BrushState.Hue; FillSquare(_shownHue); } _squareKnob.anchoredPosition = new Vector2(BrushState.Saturation * 250f, (0f - (1f - BrushState.Value)) * 250f); _hueMarker.anchoredPosition = new Vector2(_hueMarker.anchoredPosition.x, (0f - (1f - BrushState.Hue)) * 250f); foreach (SliderRow row in Rows) { for (int i = 0; i < 64; i++) { row.Gradient.SetPixel(i, 0, row.ColorAt((float)i / 63f)); } row.Gradient.Apply(); Rect rect = ((Graphic)row.Track).rectTransform.rect; float width = ((Rect)(ref rect)).width; row.Handle.anchoredPosition = new Vector2((float)row.Get() / (float)row.Max * width, row.Handle.anchoredPosition.y); if (!row.Field.isFocused) { row.Field.text = row.Get().ToString(CultureInfo.InvariantCulture); } } if (!_hex.isFocused) { _hex.text = BrushState.ToHex(color); } ((Graphic)_current).color = Color32.op_Implicit(color); if ((Object)(object)texture != (Object)null) { _vanilla.texture = texture; ((Graphic)_vanilla).color = Color.white; _painted.texture = (Texture)(object)PaintTextures.GetPreview(texture, cutout, BrushState.Paint); ((Graphic)_painted).color = Color.white; } else { _vanilla.texture = (Texture)(object)Texture2D.whiteTexture; ((Graphic)_vanilla).color = Wood; _painted.texture = (Texture)(object)Texture2D.whiteTexture; ((Graphic)_painted).color = Color.Lerp(Wood, Color32.op_Implicit(color), (float)BrushState.Strength / 100f); } for (int j = 0; j < PaletteSwatches.Length; j++) { Color32? val = BrushState.Palette[j]; ((Graphic)PaletteSwatches[j].Image).color = Color32.op_Implicit((Color32)(((??)val) ?? Color32.op_Implicit(EmptySlot))); } for (int k = 0; k < RecentSwatches.Length; k++) { bool flag = k < BrushState.Recent.Count; ((Graphic)RecentSwatches[k].Image).color = (flag ? Color32.op_Implicit(BrushState.Recent[k]) : EmptySlot); } } finally { _updating = false; } } private static void FillSquare(float hue) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { _squareTexture.SetPixel(j, i, Color.HSVToRGB(hue, (float)j / 63f, (float)i / 63f)); } } _squareTexture.Apply(); } private static bool Create(BuildUi ui) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) Transform val = ((Component)ui).transform.Find("bar/SelectionWindow"); if ((Object)(object)val == (Object)null) { _failed = true; Logger.LogWarning((object)"Build menu layout not as expected, the paint brush colour picker is unavailable."); return false; } Rows.Clear(); Fields.Clear(); _shownVersion = -1; _shownHue = -1f; _shownSample = null; if (_white == null) { _white = Sprite.Create(Texture2D.whiteTexture, new Rect(0f, 0f, 4f, 4f), new Vector2(0.5f, 0.5f)); } if (_ring == null) { _ring = MakeRing(); } _root = Box(val, "PaintBrush_Panel", 0f, 0f, 1004f, 272f); CreatePicker(); CreateSliders(); CreatePreview(); CreateSwatches(); return true; } private static void CreatePicker() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) _squareTexture = new Texture2D(64, 64, (TextureFormat)4, false) { wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)1 }; RawImage obj = Raw((Transform)(object)_root, "Square", 0f, 0f, 250f, 250f, (Texture)(object)_squareTexture); ((Component)obj).gameObject.AddComponent<DragArea>().Changed = delegate(Vector2 p) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) BrushState.SetHsv(BrushState.Hue, p.x, p.y); }; _squareKnob = ((Graphic)Image(((Component)obj).transform, "Knob", 0f, 0f, 16f, 16f, Color.white, _ring)).rectTransform; _squareKnob.pivot = new Vector2(0.5f, 0.5f); ((Graphic)((Component)_squareKnob).GetComponent<Image>()).raycastTarget = false; _hueTexture = new Texture2D(1, 180, (TextureFormat)4, false) { wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)1 }; for (int num = 0; num < ((Texture)_hueTexture).height; num++) { _hueTexture.SetPixel(0, num, Color.HSVToRGB((float)num / (float)(((Texture)_hueTexture).height - 1), 1f, 1f)); } _hueTexture.Apply(); RawImage obj2 = Raw((Transform)(object)_root, "Hue", 262f, 0f, 22f, 250f, (Texture)(object)_hueTexture); ((Component)obj2).gameObject.AddComponent<DragArea>().Changed = delegate(Vector2 p) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) BrushState.SetHsv(Mathf.Min(p.y, 0.999f), BrushState.Saturation, BrushState.Value); }; Image obj3 = Image(((Component)obj2).transform, "Marker", -5f, 0f, 32f, 4f, Color.white, _white); ((Graphic)obj3).raycastTarget = false; ((Graphic)obj3).rectTransform.pivot = new Vector2(0f, 0.5f); Swatch.Style(((Component)obj3).gameObject.AddComponent<Outline>()); _hueMarker = ((Graphic)obj3).rectTransform; } private static void CreateSliders() { //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_02aa: Unknown result type (might be due to invalid IL or missing references) AddRow("R", 0f, 255, () => BrushState.Color.r, delegate(int v) { SetChannel(0, v); }, (float t) => WithChannel(0, t)); AddRow("G", 44f, 255, () => BrushState.Color.g, delegate(int v) { SetChannel(1, v); }, (float t) => WithChannel(1, t)); AddRow("B", 88f, 255, () => BrushState.Color.b, delegate(int v) { SetChannel(2, v); }, (float t) => WithChannel(2, t)); AddRow("$paintbrush_panel_strength", 132f, 100, () => BrushState.Strength, BrushState.SetStrength, (float t) => Color.Lerp(Color32.op_Implicit(_sampleAverage), Color32.op_Implicit(BrushState.Color), t)); Label((Transform)(object)_root, "$paintbrush_panel_hex", 318f, 184f, 78f, 32f, LabelColor, 18); _hex = Field((Transform)(object)_root, 400f, 184f, 110f, 32f, (ContentType)4, 7); ((UnityEvent<string>)(object)_hex.onEndEdit).AddListener((UnityAction<string>)delegate(string text) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) if (!_updating && BrushState.TryParseHex(text, out var color)) { BrushState.SetColor(color); } else { _shownVersion = -1; } }); _current = Image((Transform)(object)_root, "Current", 522f, 184f, 154f, 32f, Color.white, _white); ((Graphic)_current).raycastTarget = false; Swatch.Style(((Component)_current).gameObject.AddComponent<Outline>()); Label((Transform)(object)_root, "$paintbrush_panel_hint", 318f, 232f, 358f, 24f, TextColor, 14); } private static void AddRow(string label, float y, int max, Func<int> get, Action<int> set, Func<float, Color> colorAt) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) Label((Transform)(object)_root, label, 318f, y, 78f, 32f, LabelColor, 18); Texture2D val = new Texture2D(64, 1, (TextureFormat)4, false) { wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)1 }; RawImage val2 = Raw((Transform)(object)_root, "Track", 400f, y + 5f, 200f, 22f, (Texture)(object)val); Swatch.Style(((Component)val2).gameObject.AddComponent<Outline>()); ((Component)val2).gameObject.AddComponent<DragArea>().Changed = delegate(Vector2 p) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) set(Mathf.RoundToInt(p.x * (float)max)); }; Image val3 = Image(((Component)val2).transform, "Handle", 0f, 11f, 6f, 30f, Color.white, _white); ((Graphic)val3).raycastTarget = false; ((Graphic)val3).rectTransform.pivot = new Vector2(0.5f, 0.5f); Swatch.Style(((Component)val3).gameObject.AddComponent<Outline>()); InputField val4 = Field((Transform)(object)_root, 612f, y, 64f, 32f, (ContentType)2, 3); ((UnityEvent<string>)(object)val4.onValueChanged).AddListener((UnityAction<string>)delegate(string text) { if (!_updating && int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result)) { set(Mathf.Clamp(result, 0, max)); } }); ((UnityEvent<string>)(object)val4.onEndEdit).AddListener((UnityAction<string>)delegate { _shownVersion = -1; }); Rows.Add(new SliderRow { Track = val2, Gradient = val, Handle = ((Graphic)val3).rectTransform, Field = val4, Max = max, Get = get, Set = set, ColorAt = colorAt }); } private static void SetChannel(int channel, int value) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) Color32 color = BrushState.Color; byte b = (byte)Mathf.Clamp(value, 0, 255); switch (channel) { case 0: color.r = b; break; case 1: color.g = b; break; default: color.b = b; break; } BrushState.SetColor(color); } private static Color WithChannel(int channel, float t) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) Color result = Color32.op_Implicit(BrushState.Color); ((Color)(ref result))[channel] = t; return result; } private static void CreatePreview() { //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) _vanilla = Raw((Transform)(object)_root, "Vanilla", 712f, 0f, 140f, 88f, (Texture)(object)Texture2D.whiteTexture); _painted = Raw((Transform)(object)_root, "Painted", 862f, 0f, 140f, 88f, (Texture)(object)Texture2D.whiteTexture); Swatch.Style(((Component)_vanilla).gameObject.AddComponent<Outline>()); Swatch.Style(((Component)_painted).gameObject.AddComponent<Outline>()); ((Graphic)_vanilla).raycastTarget = false; ((Graphic)_painted).raycastTarget = false; Label((Transform)(object)_root, "$paintbrush_panel_vanilla", 712f, 92f, 140f, 20f, TextColor, 14).alignment = (TextAnchor)4; Label((Transform)(object)_root, "$paintbrush_panel_painted", 862f, 92f, 140f, 20f, TextColor, 14).alignment = (TextAnchor)4; } private static void CreateSwatches() { //IL_001e: 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) Label((Transform)(object)_root, "$paintbrush_panel_palette", 712f, 116f, 290f, 20f, LabelColor, 16); for (int i = 0; i < PaletteSwatches.Length; i++) { int index = i; Swatch swatch = MakeSwatch(712f + (float)(i % 8) * 36f, 140f + (float)(i / 8) * 36f); swatch.Clicked = delegate(InputButton button) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) OnPaletteClick(index, button); }; PaletteSwatches[i] = swatch; } Label((Transform)(object)_root, "$paintbrush_panel_recent", 712f, 214f, 290f, 20f, LabelColor, 16); for (int num = 0; num < RecentSwatches.Length; num++) { int index2 = num; Swatch swatch2 = MakeSwatch(712f + (float)num * 36f, 238f); swatch2.Clicked = delegate(InputButton button) { //IL_0000: 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) if ((int)button == 0 && index2 < BrushState.Recent.Count) { BrushState.SetColor(BrushState.Recent[index2]); } }; RecentSwatches[num] = swatch2; } } private static void OnPaletteClick(int index, InputButton button) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) if ((int)button == 1) { BrushState.SetPaletteSlot(index, null); } else if ((int)button == 0) { Color32? val = BrushState.Palette[index]; if (Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303) || !val.HasValue) { BrushState.SetPaletteSlot(index, BrushState.Color); } else { BrushState.SetColor(val.Value); } } } private static Swatch MakeSwatch(float x, float y) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) Image val = Image((Transform)(object)_root, "Swatch", x, y, 30f, 30f, EmptySlot, _white); Outline outline = ((Component)val).gameObject.AddComponent<Outline>(); Swatch.Style(outline); Swatch swatch = ((Component)val).gameObject.AddComponent<Swatch>(); swatch.Image = val; swatch.Outline = outline; return swatch; } private static RectTransform Box(Transform parent, string name, float x, float y, float width, float height) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0069: 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) RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>(); ((Transform)component).SetParent(parent, false); component.anchorMin = new Vector2(0f, 1f); component.anchorMax = new Vector2(0f, 1f); component.pivot = new Vector2(0f, 1f); component.anchoredPosition = new Vector2(x, 0f - y); component.sizeDelta = new Vector2(width, height); return component; } private static RawImage Raw(Transform parent, string name, float x, float y, float width, float height, Texture texture) { RawImage obj = ((Component)Box(parent, name, x, y, width, height)).gameObject.AddComponent<RawImage>(); obj.texture = texture; return obj; } private static Image Image(Transform parent, string name, float x, float y, float width, float height, Color color, Sprite sprite) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) Image obj = ((Component)Box(parent, name, x, y, width, height)).gameObject.AddComponent<Image>(); obj.sprite = sprite; ((Graphic)obj).color = color; return obj; } private static Text Label(Transform parent, string token, float x, float y, float width, float height, Color color, int size) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) Text val = ((Component)Box(parent, "Label", x, y, width, height)).gameObject.AddComponent<Text>(); GUIManager.Instance.ApplyTextStyle(val, GUIManager.Instance.AveriaSerifBold, color, size, true); val.alignment = (TextAnchor)3; val.horizontalOverflow = (HorizontalWrapMode)0; val.verticalOverflow = (VerticalWrapMode)1; ((Graphic)val).raycastTarget = false; val.text = Localization.instance.Localize(token); return val; } private static InputField Field(Transform parent, float x, float y, float width, float height, ContentType type, int limit) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: 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) GameObject obj = GUIManager.Instance.CreateInputField(parent, new Vector2(0f, 1f), new Vector2(0f, 1f), Vector2.zero, type, "", 16, width, height); RectTransform val = (RectTransform)obj.transform; val.pivot = new Vector2(0f, 1f); val.sizeDelta = new Vector2(width, height); val.anchoredPosition = new Vector2(x, 0f - y); InputField component = obj.GetComponent<InputField>(); component.characterLimit = limit; Graphic[] array = (Graphic[])(object)new Graphic[2] { (Graphic)component.textComponent, component.placeholder }; foreach (Graphic val2 in array) { if (!((Object)(object)val2 == (Object)null)) { RectTransform rectTransform = val2.rectTransform; rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.one; rectTransform.offsetMin = new Vector2(6f, 1f); rectTransform.offsetMax = new Vector2(-6f, -1f); Text val3 = (Text)(object)((val2 is Text) ? val2 : null); if (val3 != null) { val3.alignment = (TextAnchor)4; val3.verticalOverflow = (VerticalWrapMode)1; } } } Fields.Add(component); return component; } private static Sprite MakeRing() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: 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) Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(15.5f, 15.5f); for (int i = 0; i < 32; i++) { for (int j = 0; j < 32; j++) { float num = Vector2.Distance(new Vector2((float)j, (float)i), val2); float num2 = Mathf.Clamp01(3f - Mathf.Abs(num - 11f)); float num3 = Mathf.Clamp01(5f - Mathf.Abs(num - 11f)); Color val3 = Color.Lerp(Color.black, Color.white, num2); val3.a = Mathf.Max(num2, num3 * 0.8f); val.SetPixel(j, i, val3); } } val.Apply(); return Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f)); } } } namespace PaintBrush.Patches { [HarmonyPatch(typeof(BuildUi), "UpdatePieceButtons")] internal static class BuildUi_UpdatePieceButtons_Patch { [HarmonyPrefix] private static void Prefix() { BrushPrefabs.SetToolsAsRepair(repair: false); } [HarmonyFinalizer] private static void Finalizer() { BrushPrefabs.SetToolsAsRepair(repair: true); } } [HarmonyPatch(typeof(BuildUi), "UpdateTagButtons")] internal static class BuildUi_UpdateTagButtons_Patch { [HarmonyPostfix] [HarmonyPriority(200)] private static void Postfix(BuildUi __instance) { MenuTitle.AfterUpdateTagButtons(__instance); } } [HarmonyPatch(typeof(Humanoid), "SetupVisEquipment")] internal static class Humanoid_SetupVisEquipment_Patch { [HarmonyPrefix] private static void Prefix(Humanoid __instance, out ItemData __state) { ItemData item = PhantomBrush.Item; __state = null; if (item != null && __instance.GetRightItem() == item) { __state = item; __instance.m_rightItem = null; } } [HarmonyPostfix] private static void Postfix(Humanoid __instance, ItemData __state) { if (__state == null) { return; } __instance.m_rightItem = __state; Player val = (Player)(object)((__instance is Player) ? __instance : null); if (val != null) { VisEquipment visEquipment = ((Humanoid)val).m_visEquipment; if (visEquipment != null) { visEquipment.SetRightItem(StringExtensionMethods.GetStableHashCode(((Object)__state.m_dropPrefab).name), __state.m_quality); } } } } [HarmonyPatch(typeof(Inventory), "ContainsItem")] internal static class Inventory_ContainsItem_Patch { [HarmonyPrefix] private static bool Prefix(ItemData item, ref bool __result) { if (PhantomBrush.Item != null && item == PhantomBrush.Item) { __result = true; return false; } return true; } } [HarmonyPatch(typeof(Inventory), "GetAllPieceTables")] internal static class Inventory_GetAllPieceTables_Patch { [HarmonyPostfix] private static void Postfix(List<PieceTable> tables) { PieceTable val = PhantomBrush.Item?.m_shared?.m_buildPieces; if ((Object)(object)val != (Object)null && !tables.Contains(val)) { tables.Add(val); } } } [HarmonyPatch(typeof(KeyHints), "UpdateHints")] internal static class KeyHints_UpdateHints_Patch { [HarmonyPostfix] private static void Postfix(KeyHints __instance) { BrushKeyHints.AfterUpdateHints(__instance); } } [HarmonyPatch(typeof(Piece), "Awake")] internal static class Piece_Awake_Patch { [HarmonyPostfix] private static void Postfix(Piece __instance) { PaintedPieces.OnPieceAwake(__instance); } } [HarmonyPatch(typeof(Piece), "OnDestroy")] internal static class Piece_OnDestroy_Patch { [HarmonyPrefix] private static void Prefix(Piece __instance) { PaintedPieces.OnPieceDestroy(__instance); } } [HarmonyPatch(typeof(Player), "Repair")] internal static class Player_Repair_Patch { [HarmonyPrefix] private static bool Prefix(Player __instance, ItemData toolItem, Piece repairPiece) { return !BrushTools.TryUse(__instance, toolItem, repairPiece); } } [HarmonyPatch(typeof(WearNTear), "Highlight")] internal static class WearNTear_Highlight_Patch { [HarmonyPrefix] private static bool Prefix(WearNTear __instance) { return !PaintPreview.HidesHighlight(__instance); } } } namespace PaintBrush.Painting { internal static class ConnectedPieces { private const float Margin = 0.15f; private static readonly Collider[] Hits = (Collider[])(object)new Collider[512]; private static readonly List<Collider> Colliders = new List<Collider>(); private static int _mask; private static ConfigEntry<int> _maxPieces; internal static int MaxPieces { get { if (_maxPieces == null) { return 1000; } return Mathf.Max(1, _maxPieces.Value); } } public static void BindConfig(ConfigFile config) { _maxPieces = config.Bind<int>("Painting", "Max Connected Pieces", 1000, "The most pieces Alt+Click paints or clears in one go, so a click on a large build can't freeze the game."); } internal static List<Piece> Find(Piece start, out bool limited) { //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) if (_mask == 0) { _mask = LayerMask.GetMask(new string[4] { "piece", "piece_nonsolid", "Default", "Default_small" }); } int maxPieces = MaxPieces; limited = false; List<Piece> list = new List<Piece>(1) { start }; HashSet<Piece> hashSet = new HashSet<Piece> { start }; for (int i = 0; i < list.Count; i++) { Piece val = list[i]; if ((Object)(object)val == (Object)null) { continue; } Colliders.Clear(); ((Component)val).GetComponentsInChildren<Collider>(false, Colliders); foreach (Collider collider in Colliders) { if (!IsSolid(collider)) { continue; } GetBox(collider, out var center, out var halfSize, out var rotation); int num = Physics.OverlapBoxNonAlloc(center, halfSize, Hits, rotation, _mask); for (int j = 0; j < num; j++) { if (!IsSolid(Hits[j])) { continue; } Piece componentInParent = ((Component)Hits[j]).GetComponentInParent<Piece>(); if ((Object)(object)componentInParent == (Object)null || !hashSet.Add(componentInParent)) { continue; } ZNetView component = ((Component)componentInParent).GetComponent<ZNetView>(); if (component != null && component.IsValid()) { if (list.Count >= maxPieces) { limited = true; Colliders.Clear(); return list; } list.Add(componentInParent); } } } } Colliders.Clear(); return list; } private static bool IsSolid(Collider collider) { if ((Object)(object)collider != (Object)null && collider.enabled && !collider.isTrigger) { return (Object)(object)collider.attachedRigidbody == (Object)null; } return false; } private static void GetBox(Collider collider, out Vector3 center, out Vector3 halfSize, out Quaternion rotation) { //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: 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_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) BoxCollider val = (BoxCollider)(object)((collider is BoxCollider) ? collider : null); if (val != null) { Transform transform = ((Component)val).transform; Vector3 lossyScale = transform.lossyScale; center = transform.TransformPoint(val.center); rotation = transform.rotation; halfSize = new Vector3(Mathf.Abs(lossyScale.x * val.size.x), Mathf.Abs(lossyScale.y * val.size.y), Mathf.Abs(lossyScale.z * val.size.z)) * 0.5f; } else { Bounds bounds = collider.bounds; center = ((Bounds)(ref bounds)).center; rotation = Quaternion.identity; halfSize = ((Bounds)(ref bounds)).extents; } halfSize += Vector3.one * 0.15f; } } internal sealed class GhostPaint : MonoBehaviour { private static readonly List<GhostPaint> Live = new List<GhostPaint>(); private List<(Renderer Renderer, int Index, Material Original, Material Painted)> _painted; private PaintColor _paint; public static void Show(GameObject target, PaintColor paint) { if ((Object)(object)target == (Object)null) { return; } GhostPaint ghostPaint = default(GhostPaint); if (!target.TryGetComponent<GhostPaint>(ref ghostPaint)) { if (paint.IsNone) { return; } ghostPaint = target.AddComponent<GhostPaint>(); } ghostPaint.Set(paint); } public static void Sweep() { for (int num = Live.Count - 1; num >= 0; num--) { GhostPaint ghostPaint = Live[num]; if ((Object)(object)ghostPaint == (Object)null) { ghostPaint.Clear(); Live.RemoveAt(num); } } } private void Set(PaintColor paint) { if (paint == _paint && _painted != null) { return; } Clear(); if (!paint.IsNone) { _paint = paint; _painted = PaintedPieces.PaintObject(((Component)this).gameObject, paint); if (!Live.Contains(this)) { Live.Add(this); } } } private void Clear() { if (_painted != null) { PaintedPieces.UnpaintObject(_painted, _paint); _painted = null; } _paint = PaintColor.None; } private void OnDestroy() { Clear(); Live.Remove(this); } } internal readonly struct PaintColor : IEquatable<PaintColor> { public readonly byte R; public readonly byte G; public readonly byte B; public readonly byte Strength; public static PaintColor None => default(PaintColor); public bool IsNone => Strength == 0; public Color32 Color => new Color32(R, G, B, byte.MaxValue); public PaintColor(byte r, byte g, byte b, byte strength) { R = r; G = g; B = b; Strength = strength; } public int Pack() { if (!IsNone) { return (R << 24) | (G << 16) | (B << 8) | Strength; } return 0; } public static PaintColor Unpack(int value) { PaintColor result = new PaintColor((byte)(value >> 24), (byte)(value >> 16), (byte)(value >> 8), (byte)value); if (!result.IsNone) { return result; } return None; } public static PaintColor FromPercent(Color32 color, int percent) { //IL_0023: 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_002f: Unknown result type (might be due to invalid IL or missing references) if (percent <= 0) { return None; } int num = Mathf.Clamp(Mathf.RoundToInt((float)percent * 2.55f), 1, 255); return new PaintColor(color.r, color.g, color.b, (byte)num); } public bool Equals(PaintColor other) { return Pack() == other.Pack(); } public override bool Equals(object obj) { if (obj is PaintColor other) { return Equals(other); } return false; } public override int GetHashCode() { return Pack(); } public static bool operator ==(PaintColor left, PaintColor right) { return left.Equals(right); } public static bool operator !=(PaintColor left, PaintColor right) { return !left.Equals(right); } } internal static class PaintedPieces { private sealed class Slot { public Renderer Renderer; public int Index; public Material Original; public Material Painted; public bool Counted; } private sealed class State { public Piece Piece; public PaintColor Stored; public PaintColor? Preview; public PaintColor Shown; public bool ShownIsPreview; public bool Flagged; public readonly List<Slot> Slots = new List<Slot>(); } private readonly struct MaterialInfo { public readonly bool Paintable; public readonly Texture Texture; public readonly bool Cutout; public MaterialInfo(bool paintable, Texture texture, bool cutout) { Paintable = paintable; Texture = texture; Cutout = cutout; } } private const int ChecksPerFrame = 300; private static readonly int MainTex = Shader.PropertyToID("_MainTex"); private static readonly int PaintedFlag = Shader.PropertyToID("_PaintBrushPainted"); private static readonly string[] SkippedShaders = new string[18] { "Snow", "Particle", "Unlit", "Distortion", "Water", "Decal", "TextMeshPro", "Flow", "Lighting", "Invis", "Sprites", "Blob", "Tar", "UI", "Cloud", "Heightmap", "Grass", "Skybox" }; private static readonly Dictionary<Piece, State> States = new Dictionary<Piece, State>(); private static readonly Dictionary<int, MaterialInfo> Materials = new Dictionary<int, MaterialInfo>(); private static readonly List<Renderer> RendererBuffer = new List<Renderer>(); private static int _cursor; public static PaintColor StoredPaint(Piece piece) { if (!((Object)(object)piece != (Object)null)) { return PaintColor.None; } return PaintStore.Read(piece.m_nview); } public static bool CanPaint(Piece piece) { Texture texture; bool cutout; if ((Object)(object)piece != (Object)null && piece.IsPlacedByPlayer() && (Object)(object)piece.m_nview != (Object)null && piece.m_nview.IsValid()) { return SampleTexture(piece, out texture, out cutout); } return false; } public static bool SampleTexture(Piece piece, out Texture texture, out bool cutout) { texture = null; cutout = false; if ((Object)(object)piece == (Object)null) { return false; } GatherRenderers((Component)(object)piece); foreach (Renderer item in RendererBuffer) { Material[] sharedMaterials = item.sharedMaterials; for (int i = 0; i < sharedMaterials.Length; i++) { MaterialInfo materialInfo = Info(PaintMaterials.Original(sharedMaterials[i])); if (materialInfo.Paintable) { texture = materialInfo.Texture; cutout = materialInfo.Cutout; return true; } } } return false; } public static void OnPieceAwake(Piece piece) { PaintColor stored = StoredPaint(piece); if (!stored.IsNone) { State state = GetState(piece); state.Stored = stored; Refresh(state); } } public static void OnPieceDestroy(Piece piece) { if (States.TryGetValue(piece, out var value)) { ClearSlots(value); States.Remove(piece); } } public static void OnPaintWritten(Piece piece, PaintColor paint) { State state = GetState(piece); state.Stored = paint; Refresh(state); } public static void SetPreview(Piece piece, PaintColor? preview) { if ((Object)(object)piece == (Object)null) { return; } if (!States.TryGetValue(piece, out var value)) { if (!preview.HasValue) { return; } value = GetState(piece); value.Stored = StoredPaint(piece); } value.Preview = preview; Refresh(value); } public static void Update() { PaintMaterials.FreeUnused(); GhostPaint.Sweep(); List<Piece> s_allPieces = Piece.s_allPieces; if (s_allPieces == null || s_allPieces.Count == 0) { return; } int num = Mathf.Min(300, s_allPieces.Count); for (int i = 0; i < num; i++) { if (_cursor >= s_allPieces.Count) { _cursor = 0; } Piece val = s_allPieces[_cursor++]; if ((Object)(object)val == (Object)null) { continue; } PaintColor paintColor = StoredPaint(val); State value; bool flag = States.TryGetValue(val, out value); if (flag ? (value.Stored != paintColor) : (!paintColor.IsNone)) { if (value == null) { value = GetState(val); } value.Stored = paintColor; Refresh(value); } else if (flag && !SlotsIntact(value)) { Repaint(value); } } } private static State GetState(Piece piece) { if (!States.TryGetValue(piece, out var value)) { value = new State { Piece = piece }; States[piece] = value; } return value; } private static void Refresh(State state) { PaintColor paintColor = state.Preview ?? state.Stored; bool hasValue = state.Preview.HasValue; if (paintColor == state.Shown && hasValue == state.ShownIsPreview && (paintColor.IsNone || state.Slots.Count > 0)) { Forget(state); } else { Repaint(state); } } private static void Repaint(State state) { PaintColor paintColor = state.Preview ?? state.Stored; bool hasValue = state.Preview.HasValue; ClearSlots(state); state.Shown = paintColor; state.ShownIsPreview = hasValue; if (!paintColor.IsNone) { PaintSlots(state, paintColor, hasValue); } SetFlag(state, state.Slots.Count > 0); Forget(state); } private static void SetFlag(State state, bool painted) { if (state.Flagged != painted && !((Object)(object)MaterialMan.instance == (Object)null) && !((Object)(object)state.Piece == (Object)null)) { state.Flagged = painted; if (painted) { MaterialMan.instance.SetValue<float>(((Component)state.Piece).gameObject, PaintedFlag, 1f, false); } else { MaterialMan.instance.ResetValue(((Component)state.Piece).gameObject, PaintedFlag); } } } private static void Forget(State state) { if (state.Stored.IsNone && !state.Preview.HasValue && state.Slots.Count == 0) { States.Remove(state.Piece); } } private static bool SlotsIntact(State state) { foreach (Slot slot in state.Slots) { if (!((Object)(object)slot.Renderer == (Object)null)) { Material[] sharedMaterials = slot.Renderer.sharedMaterials; if (slot.Index >= sharedMaterials.Length || (Object)(object)sharedMaterials[slot.Index] != (Object)(object)slot.Painted) { return false; } } } return true; } private static void PaintSlots(State state, PaintColor paint, bool preview) { GatherRenderers((Component)(object)state.Piece); foreach (Renderer item in RendererBuffer) { Material[] sharedMaterials = item.sharedMaterials; bool flag = false; for (int i = 0; i < sharedMaterials.Length; i++) { Material val = PaintMaterials.Original(sharedMaterials[i]); MaterialInfo materialInfo = Info(val); if (materialInfo.Paintable) { Material val2 = (preview ? PaintMaterials.Preview(val, materialInfo.Texture, materialInfo.Cutout, paint) : PaintMaterials.Acquire(val, materialInfo.Texture, materialInfo.Cutout, paint)); state.Slots.Add(new Slot { Renderer = item, Index = i, Original = val, Painted = val2, Counted = !preview }); sharedMaterials[i] = val2; flag = true; } } if (flag) { item.sharedMaterials = sharedMaterials; } } } private static void ClearSlots(State state) { foreach (Slot slot in state.Slots) { if ((Object)(object)slot.Renderer != (Object)null) { Material[] sharedMaterials = slot.Renderer.sharedMaterials; if (slot.Index < sharedMaterials.Length && PaintMaterials.IsCopy(sharedMaterials[slot.Index])) { sharedMaterials[slot.Index] = slot.Original; slot.Renderer.sharedMaterials = sharedMaterials; } } if (slot.Counted) { PaintMaterials.Release(slot.Original, state.Shown); } } state.Slots.Clear(); } internal static List<(Renderer Renderer, int Index, Material Original, Material Painted)> PaintObject(GameObject root, PaintColor paint) { List<(Renderer, int, Material, Material)> list = new List<(Renderer, int, Material, Material)>(); GatherRenderers((Component)(object)root.transform); foreach (Renderer item in RendererBuffer) { Material[] sharedMaterials = item.sharedMaterials; bool flag = false; for (int i = 0; i < sharedMaterials.Length; i++) { Material val = PaintMaterials.Original(sharedMaterials[i]); MaterialInfo materialInfo = Info(val); if (materialInfo.Paintable) { Material val2 = PaintMaterials.Acquire(val, materialInfo.Texture, materialInfo.Cutout, paint); list.Add((item, i, val, val2)); sharedMaterials[i] = val2; flag = true; } } if (flag) { item.sharedMaterials = sharedMaterials; } } return list; } internal static void UnpaintObject(List<(Renderer Renderer, int Index, Material Original, Material Painted)> painted, PaintColor paint) { foreach (var (val, num, val2, _) in painted) { if ((Object)(object)val != (Object)null) { Material[] sharedMaterials = val.sharedMaterials; if (num < sharedMaterials.Length && PaintMaterials.IsCopy(sharedMaterials[num])) { sharedMaterials[num] = val2; val.sharedMaterials = sharedMaterials; } } PaintMaterials.Release(val2, paint); } } private static void GatherRenderers(Component root) { RendererBuffer.Clear(); root.GetComponentsInChildren<Renderer>(true, RendererBuffer); for (int num = RendererBuffer.Count - 1; num >= 0; num--) { Renderer val = RendererBuffer[num]; if (!(val is MeshRenderer) && !(val is SkinnedMeshRenderer)) { RendererBuffer.RemoveAt(num); } } } private static MaterialInfo Info(Material material) { if ((Object)(object)material == (Object)null) { return default(MaterialInfo); } int instanceID = ((Object)material).GetInstanceID(); if (!Materials.TryGetValue(instanceID, out var value)) { value = Examine(material); Materials[instanceID] = value; } return value; } private static MaterialInfo Examine(Material material) { string text = (((Object)(object)material.shader != (Object)null) ? ((Object)material.shader).name : ""); string[] skippedShaders = SkippedShaders; foreach (string value in skippedShaders) { if (text.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0) { return default(MaterialInfo); } } if (!material.HasProperty(MainTex) || material.renderQueue >= 2950) { return default(MaterialInfo); } Texture texture = material.GetTexture(MainTex); if ((Object)(object)texture == (Object)null) { return default(MaterialInfo); } bool cutout = material.IsKeywordEnabled("_ALPHATEST_ON") || material.renderQueue >= 2450 || (material.HasProperty("_Mode") && Mathf.Approximately(material.GetFloat("_Mode"), 1f)); return new MaterialInfo(paintable: true, texture, cutout); } } internal static class PaintMaterials { private sealed class Entry { public Material Material; public Texture Source; public PaintColor Paint; public int Users; public float UnusedSince; } private static readonly int MainTex = Shader.PropertyToID("_MainTex"); private const float KeepUnused = 10f; private static readonly List<(int Material, int Paint)> Unused = new List<(int, int)>(); private static readonly Dictionary<(int Material, int Paint), Entry> Painted = new Dictionary<(int, int), Entry>(); private static readonly Dictionary<int, Material> Previews = new Dictionary<int, Material>(); private static readonly Dictionary<int, Material> Originals = new Dictionary<int, Material>(); public static Material Original(Material material) { if (!((Object)(object)material != (Object)null) || !Originals.TryGetValue(((Object)material).GetInstanceID(), out var value) || !((Object)(object)value != (Object)null)) { return material; } return value; } public static bool IsCopy(Material material) { if ((Object)(object)material != (Object)null) { return Originals.ContainsKey(((Object)material).GetInstanceID()); } return false; } public static Material Acquire(Material original, Texture source, bool cutout, PaintColor paint) { (int, int) key = (((Object)original).GetInstanceID(), paint.Pack()); if (!Painted.TryGetValue(key, out var value) || (Object)(object)value.Material == (Object)null) { value = new Entry { Material = Copy(original, (Texture)(object)PaintTextures.Acquire(source, cutout, paint)), Source = source, Paint = paint }; Painted[key] = value; } value.Users++; return value.Material; } public static void Release(Material original, PaintColor paint) { if (!((Object)(object)original == (Object)null)) { (int, int) tuple = (((Object)original).GetInstanceID(), paint.Pack()); if (Painted.TryGetValue(tuple, out var value) && --value.Users <= 0) { value.UnusedSince = Time.time; Unused.Add(tuple); } } } public static void FreeUnused() { for (int num = Unused.Count - 1; num >= 0; num--) { (int, int) key = Unused[num]; if (!Painted.TryGetValue(key, out var value) || value.Users > 0) { Unused.RemoveAt(num); } else if (!(Time.time - value.UnusedSince < 10f)) { Unused.RemoveAt(num); Painted.Remove(key); PaintTextures.Release(value.Source, value.Paint); if ((Object)(object)value.Material != (Object)null) { Originals.Remove(((Object)value.Material).GetInstanceID()); Object.Destroy((Object)(object)value.Material); } } } } public static Material Preview(Material original, Texture source, bool cutout, PaintColor paint) { Texture2D preview = PaintTextures.GetPreview(source, cutout, paint); int instanceID = ((Object)original).GetInstanceID(); if (!Previews.TryGetValue(instanceID, out var value) || (Object)(object)value == (Object)null) { value = Copy(original, (Texture)(object)preview); Previews[instanceID] = value; } else { value.SetTexture(MainTex, (Texture)(object)preview); } return value; } private static Material Copy(Material original, Texture texture) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown Material val = new Material(original) { name = ((Object)original).name }; val.SetTexture(MainTex, texture); Originals[((Object)val).GetInstanceID()] = original; return val; } } internal static class PaintStore { private static readonly int Key = StringExtensionMethods.GetStableHashCode("PaintBrush_Paint"); public static PaintColor Read(ZNetView view) { if (!((Object)(object)view != (Object)null) || !view.IsValid()) { return PaintColor.None; } return PaintColor.Unpack(view.GetZDO().GetInt(Key, 0)); } public static void Write(ZNetView view, PaintColor paint) { if (!((Object)(object)view == (Object)null) && view.IsValid()) { view.ClaimOwnership(); view.GetZDO().Set(Key, paint.Pack(), false); } } } internal static class PaintTextures { private sealed class Source { public Color32[] Pixels; public int Width; public int Height; public float InverseAverage; } private sealed class Painted { public Texture2D Texture; public int Users; } private sealed class Preview { public Texture2D Texture; public int Paint; } private const int PreviewSize = 512; private const int SourceCacheSize = 8; private const float Knee = 110f; private const float AboveKnee = 0.4f; private const float MaxRelative = 1.6f; private static readonly Dictionary<(int Texture, int Paint), Painted> PaintedTextures = new Dictionary<(int, int), Painted>(); private static readonly Dictionary<int, Preview> PreviewTextures = new Dictionary<int, Preview>(); private static readonly Dictionary<(int Texture, int Size, bool Cutout), Source> Sources = new Dictionary<(int, int, bool), Source>(); private static readonly LinkedList<(int Texture, int Size, bool Cutout)> SourceOrder = new LinkedList<(int, int, bool)>(); private static ConfigEntry<int> _maxSize; private static int MaxSize { get { if (_maxSize == null) { return 1024; } return _maxSize.Value; } } public static void BindConfig(ConfigFile config) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown _maxSize = config.Bind<int>("Graphics", "Paint Texture Size", 1024, new ConfigDescription("The largest size of a painted texture. Larger textures are scaled down to this, which saves memory but makes painted pieces a little blurrier than vanilla ones up close.", (AcceptableValueBase)(object)new AcceptableValueList<int>(new int[3] { 512, 1024, 2048 }), Array.Empty<object>())); } public static Texture2D Acquire(Texture source, bool cutout, PaintColor paint) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown (int, int) key = (((Object)source).GetInstanceID(), paint.Pack()); if (!PaintedTextures.TryGetValue(key, out var value) || (Object)(object)value.Texture == (Object)null) { Source source2 = GetSource(source, MaxSize, cutout); Texture2D val = new Texture2D(source2.Width, source2.Height, (TextureFormat)4, true, false) { name = ((Object)source).name + "_painted" }; CopySettings(source, val); val.SetPixels32(Paint(source2, paint)); val.Apply(true, false); val.Compress(false); val.Apply(false, true); value = new Painted { Texture = val }; PaintedTextures[key] = value; } value.Users++; return value.Texture; } public static void Release(Texture source, PaintColor paint) { if ((Object)(object)source == (Object)null) { return; } (int, int) key = (((Object)source).GetInstanceID(), paint.Pack()); if (PaintedTextures.TryGetValue(key, out var value) && --value.Users <= 0) { PaintedTextures.Remove(key); if ((Object)(object)value.Texture != (Object)null) { Object.Destroy((Object)(object)value.Texture); } } } public static Texture2D GetPreview(Texture source, bool cutout, PaintColor paint) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown int instanceID = ((Object)source).GetInstanceID(); if (!PreviewTextures.TryGetValue(instanceID, out var value) || (Object)(object)value.Texture == (Object)null) { Source source2 = GetSource(source, 512, cutout); value = new Preview { Texture = new Texture2D(source2.Width, source2.Height, (TextureFormat)4, true, false) { name = ((Object)source).name + "_preview" }, Paint = -1 }; CopySettings(source, value.Texture); PreviewTextures[instanceID] = value; } if (value.Paint != paint.Pack()) { Source source3 = GetSource(source, 512, cutout); value.Texture.SetPixels32(Paint(source3, paint)); value.Texture.Apply(true); value.Paint = paint.Pack(); } return value.Texture; } public static Color32 AverageColor(Texture source, bool cutout) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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_0057: 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_00a2: 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) Source source2 = GetSource(source, 512, cutout); long num = 0L; long num2 = 0L; long num3 = 0L; long num4 = 0L; Color32[] pixels = source2.Pixels; foreach (Color32 val in pixels) { if (!cutout || val.a >= 128) { num += val.r; num2 += val.g; num3 += val.b; num4++; } } if (num4 != 0L) { return new Color32((byte)(num / num4), (byte)(num2 / num4), (byte)(num3 / num4), byte.MaxValue); } return new Color32((byte)128, (byte)128, (byte)128, byte.MaxValue); } private static Color32[] Paint(Source source, PaintColor paint) { //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) Color32[] pixels = source.Pixels; Color32[] array = (Color32[])(object)new Color32[pixels.Length]; if (paint.IsNone) { Array.Copy(pixels, array, pixels.Length); return array; } float num = (float)(int)paint.Strength / 255f; float num2 = 1f - num; float num3 = Tame(paint); float num4 = (float)(int)paint.R * num3 * num; float num5 = (float)(int)paint.G * num3 * num; float num6 = (float)(int)paint.B * num3 * num; float inverseAverage = source.InverseAverage; for (int i = 0; i < pixels.Length; i++) { Color32 val = pixels[i]; float num7 = Luminance(val) * inverseAverage; if (num7 > 1.6f) { num7 = 1.6f; } array[i] = new Color32(ToByte((float)(int)val.r * num2 + num4 * num7), ToByte((float)(int)val.g * num2 + num5 * num7), ToByte((float)(int)val.b * num2 + num6 * num7), val.a); } return array; } public static float Tame(PaintColor paint) { float num = 0.2126f * (float)(int)paint.R + 0.7152f * (float)(int)paint.G + 0.0722f * (float)(int)paint.B; if (!(num <= 110f)) { return (110f + (num - 110f) * 0.4f) / num; } return 1f; } private static byte ToByte(float value) { if (!(value >= 255f)) { if (value <= 0f) { return 0; } return (byte)(value + 0.5f); } return byte.MaxValue; } private static float Luminance(Color32 pixel) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0012: 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) return 0.2126f * (float)(int)pixel.r + 0.7152f * (float)(int)pixel.g + 0.0722f * (float)(int)pixel.b; } private static void CopySettings(Texture source, Texture2D target) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) ((Texture)target).wrapModeU = source.wrapModeU; ((Texture)target).wrapModeV = source.wrapModeV; ((Texture)target).filterMode = source.filterMode; ((Texture)target).anisoLevel = source.anisoLevel; } private static Source GetSource(Texture texture, int maxSize, bool cutout) { (int, int, bool) tuple = (((Object)texture).GetInstanceID(), maxSize, cutout); if (Sources.TryGetValue(tuple, out var value)) { SourceOrder.Remove(tuple); SourceOrder.AddFirst(tuple); return value; } value = Read(texture, maxSize, cutout); Sources[tuple] = value; SourceOrder.AddFirst(tuple); while (SourceOrder.Count > 8) { Sources.Remove(SourceOrder.Last.Value); SourceOrder.RemoveLast(); } return value; } private static Source Read(Texture texture, int maxSize, bool cutout) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.Max(1, texture.width); int num2 = Mathf.Max(1, texture.height); while (num > maxSize || num2 > maxSize) { num = Mathf.Max(1, num / 2); num2 = Mathf.Max(1, num2 / 2); } RenderTexture temporary = RenderTexture.GetTemporary(num, num2, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2); RenderTexture active = RenderTexture.active; Texture2D val = new Texture2D(num, num2, (TextureFormat)4, false, false); try { Graphics.Blit(texture, temporary); RenderTexture.active = temporary; val.ReadPixels(new Rect(0f, 0f, (float)num, (float)num2), 0, 0); val.Apply(false); } finally { RenderTexture.active = active; RenderTexture.ReleaseTemporary(temporary); } Color32[] pixels = val.GetPixels32(); Object.Destroy((Object)(object)val); double num3 = 0.0; int num4 = 0; Color32[] array = pixels; foreach (Color32 val2 in array) { if (!cutout || val2.a >= 128) { num3 += (double)Luminance(val2); num4++; } } float num5 = ((num4 > 0) ? ((float)(num3 / (double)num4)) : 128f); return new Source { Pixels = pixels, Width = num, Height = num2, InverseAverage = 1f / Mathf.Max(num5, 8f) }; } } } namespace PaintBrush.History { internal static class PaintHistory { internal readonly struct Change { public readonly ZDOID Piece; public readonly PaintColor Before; public readonly PaintColor After; public Change(ZDOID piece, PaintColor before, PaintColor after) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) Piece = piece; Before = before; After = after; } } private const int MaxSplashes = 12; private static ConfigEntry<KeyboardShortcut> _undoKey; private static ConfigEntry<KeyboardShortcut> _redoKey; private static ConfigEntry<int> _size; private static readonly LinkedList<List<Change>> Undos = new LinkedList<List<Change>>(); private static readonly Stack<List<Change>> Redos = new Stack<List<Change>>(); internal static KeyboardShortcut UndoKey => _undoKey.Value; internal static KeyboardShortcut RedoKey => _redoKey.Value; internal static bool CanUndo => Undos.Count > 0; internal static bool CanRedo => Redos.Count > 0; public static void BindConfig(ConfigFile config) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown _undoKey = config.Bind<KeyboardShortcut>("Keybinds", "Undo", new KeyboardShortcut((KeyCode)122, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Undoes the last painting or clearing done with the brush."); _redoKey = config.Bind<KeyboardShortcut>("Keybinds", "Redo", new KeyboardShortcut((KeyCode)121, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Redoes the last painting or clearing you undid."); _size = config.Bind<int>("Undo", "History Size", 50, new ConfigDescription("How many paint actions can be undone.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 500), Array.Empty<object>())); } public static void Reset() { Undos.Clear(); Redos.Clear(); } public static void Record(List<Change> changes) { if (changes.Count != 0) { Undos.AddLast(changes); Redos.Clear(); while (Undos.Count > _size.Value) { Undos.RemoveFirst(); } } } public static void UpdateKeys(Player player) { //IL_000f: 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) if (!Keys.Blocked() && !Hud.IsPieceSelectionVisible()) { if (Keys.IsDown(UndoKey)) { Step(player, undo: true); } else if (Keys.IsDown(RedoKey)) { Step(player, undo: false); } } } private static void Replay(Player player, List<(Piece Piece, PaintColor Paint, PaintColor Old)> targets) { //IL_004d: 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_0052: Unknown result type (mi