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 AllfathersGrasp v0.1.5
plugins/AllfathersGrasp.dll
Decompiled 12 hours agousing System; using System.Collections.Generic; using System.Collections.ObjectModel; 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 System.Text; using AllfathersGrasp.Grasp; using AllfathersGrasp.Ui; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("AllfathersGrasp")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("A blocklist for auto-pickup. Click an item, click the button, and it stays on the ground.")] [assembly: AssemblyFileVersion("0.1.5.0")] [assembly: AssemblyInformationalVersion("0.1.5+ab607c16ddef36457651b1af3fd8978d33e489f9")] [assembly: AssemblyProduct("Allfather's Grasp")] [assembly: AssemblyTitle("AllfathersGrasp")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.1.5.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } public sealed class ConfigurationManagerAttributes { public int? Order; public bool? IsAdvanced; public Action<ConfigEntryBase> CustomDrawer; public bool? HideDefaultButton; public bool? HideSettingName; } namespace AllfathersGrasp { public static class ModConfig { public static ConfigEntry<bool> Enabled; public static ConfigEntry<ModLanguage> Language; public static ConfigEntry<string> Blocked; public static ConfigEntry<bool> Verbose; public static void Bind(ConfigFile cfg) { Enabled = cfg.Bind<bool>("1 - General", "Enabled", true, "Master switch. When off, auto-pickup behaves exactly as the game has it and the list below is ignored - it is not lost, it simply stops applying. / Hauptschalter. Aus heisst: das Aufheben verhaelt sich wie im Spiel und die Liste unten wird nicht beachtet - sie geht nicht verloren, sie wirkt nur nicht."); Language = cfg.Bind<ModLanguage>("1 - General", "Language", ModLanguage.Game, "Which language the mod speaks. Game follows Valheim. / Welche Sprache die Mod spricht. Game folgt Valheim."); Blocked = cfg.Bind<string>("2 - Blocklist", "Blocked", "", "Prefab names, separated by commas, that are never picked up automatically. Picking them up with E always works. Normally written by the panel in the inventory; editing it by hand works too, and is the way to block something you are not carrying right now. Example: Wood,Stone,Resin / Prefab-Namen, durch Komma getrennt, die nie automatisch aufgehoben werden. Mit E aufheben geht immer. Normalerweise schreibt das Panel im Inventar diese Zeile; von Hand editieren geht auch, und ist der Weg, etwas zu sperren, das man gerade nicht dabei hat."); Verbose = cfg.Bind<bool>("3 - Debug", "Verbose", false, "Write every block and release to the log. / Jede Sperre und jede Freigabe ins Log schreiben."); Language.SettingChanged += delegate { Texts.Setting = Language.Value; }; Texts.Setting = Language.Value; } } [BepInPlugin("sohneg.AllfathersGrasp", "Allfather's Grasp", "0.1.5")] [BepInProcess("valheim.exe")] public class AllfathersGraspPlugin : BaseUnityPlugin { public const string ModGuid = "sohneg.AllfathersGrasp"; public const string ModName = "Allfather's Grasp"; public const string ModVersion = "0.1.5"; public static ManualLogSource Log; public static AllfathersGraspPlugin Instance; private Harmony _harmony; private void Awake() { //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; Texts.Log = delegate(string message) { Log.LogWarning((object)message); }; Texts.GameLanguage = () => (Localization.instance == null) ? "" : Localization.instance.GetSelectedLanguage(); Texts.Load(); ModConfig.Bind(((BaseUnityPlugin)this).Config); Enforcer.Load(); _harmony = new Harmony("sohneg.AllfathersGrasp"); _harmony.PatchAll(); Log.LogInfo((object)"Allfather's Grasp 0.1.5 is awake."); } private void Update() { if ((Object)(object)ZNetScene.instance == (Object)null) { Enforcer.Forget(); GraspButton.Reset(); GraspPanel.Forget(); return; } try { GraspButton.Tick(); GraspPanel.Tick(); } catch (Exception ex) { Log.LogError((object)("Could not keep the button in step: " + ex)); } } private void OnGUI() { try { GraspPanel.Draw(); } catch (Exception ex) { GraspPanel.Close(); Log.LogError((object)("Could not draw the panel: " + ex)); } } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } public enum ModLanguage { Game, English, Deutsch } public static class Texts { public const string Fallback = "en"; private static readonly Dictionary<string, Dictionary<string, string[]>> Tables = new Dictionary<string, Dictionary<string, string[]>>(StringComparer.OrdinalIgnoreCase); private static readonly HashSet<string> Reported = new HashSet<string>(StringComparer.Ordinal); public static Func<string> GameLanguage; public static Action<string> Log; public static ModLanguage Setting = ModLanguage.Game; public static readonly string[] Available = new string[2] { "en", "de" }; public static void Load() { Tables.Clear(); Reported.Clear(); for (int i = 0; i < Available.Length; i++) { string text = Available[i]; Dictionary<string, string[]> dictionary = ReadEmbedded(text); if (dictionary != null) { Tables[text] = dictionary; } } } public static string Get(string key, params string[] values) { return GetIn(ActiveCode(), key, values); } public static string GetIn(string code, string key, params string[] values) { return Fill(Pick(code, key), values); } public static string ActiveCode() { return Setting switch { ModLanguage.English => "en", ModLanguage.Deutsch => "de", _ => FromGame(), }; } public static bool Has(string code) { if (code != null) { return Tables.ContainsKey(code); } return false; } public static ICollection<string> KeysOf(string code) { if (!Tables.TryGetValue(code ?? "", out var value)) { return new string[0]; } return value.Keys; } public static int VariantCount(string code, string key) { return VariantsOf(code, key).Length; } public static string[] VariantsOf(string code, string key) { if (!Tables.TryGetValue(code ?? "", out var value)) { return new string[0]; } if (!value.TryGetValue(key ?? "", out var value2)) { return new string[0]; } return value2; } private static string FromGame() { string a = ""; try { if (GameLanguage != null) { a = GameLanguage() ?? ""; } } catch { } if (!string.Equals(a, "German", StringComparison.OrdinalIgnoreCase)) { return "en"; } return "de"; } private static string Pick(string code, string key) { string[] array = Lookup(code, key); if (array == null || array.Length == 0) { return key ?? ""; } return array[0]; } private static string[] Lookup(string code, string key) { if (string.IsNullOrEmpty(key)) { return null; } if (Tables.TryGetValue(code ?? "", out var value) && value.TryGetValue(key, out var value2)) { return value2; } if (!string.Equals(code, "en", StringComparison.OrdinalIgnoreCase) && Tables.TryGetValue("en", out value) && value.TryGetValue(key, out value2)) { Report("Text '" + key + "' is missing from " + code + ".json, using en."); return value2; } Report("Text '" + key + "' is missing from every language file."); return null; } private static string Fill(string template, string[] values) { if (string.IsNullOrEmpty(template) || values == null || values.Length == 0) { return template ?? ""; } StringBuilder stringBuilder = new StringBuilder(template); for (int i = 0; i + 1 < values.Length; i += 2) { stringBuilder.Replace("{" + values[i] + "}", values[i + 1] ?? ""); } return stringBuilder.ToString(); } private static Dictionary<string, string[]> ReadEmbedded(string code) { string text = "AllfathersGrasp.Localization." + code + ".json"; try { Assembly executingAssembly = Assembly.GetExecutingAssembly(); using Stream stream = executingAssembly.GetManifestResourceStream(text); if (stream == null) { Report("Language file " + text + " is not embedded in this build."); return null; } using StreamReader streamReader = new StreamReader(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), detectEncodingFromByteOrderMarks: true); Dictionary<string, string[]> dictionary = Parse(streamReader.ReadToEnd()); if (dictionary == null || dictionary.Count == 0) { Report("Language file " + text + " could not be read."); return null; } return dictionary; } catch (Exception ex) { Report("Language file " + text + " could not be read: " + ex.GetType().Name + ": " + ex.Message); return null; } } public static Dictionary<string, string[]> Parse(string json) { if (string.IsNullOrEmpty(json)) { return null; } Dictionary<string, string[]> dictionary = new Dictionary<string, string[]>(StringComparer.Ordinal); List<string> list = new List<string>(); int i = 0; SkipSpace(json, ref i); if (i >= json.Length || json[i] != '{') { return null; } i++; while (i < json.Length) { SkipSpace(json, ref i); if (i >= json.Length || json[i] == '}') { break; } if (json[i] == ',') { i++; continue; } string text = ReadString(json, ref i); if (text == null) { break; } SkipSpace(json, ref i); if (i >= json.Length || json[i] != ':') { break; } i++; SkipSpace(json, ref i); if (i >= json.Length) { break; } list.Clear(); if (json[i] == '[') { i++; while (i < json.Length) { SkipSpace(json, ref i); if (i >= json.Length) { break; } if (json[i] == ']') { i++; break; } if (json[i] == ',') { i++; continue; } string text2 = ReadString(json, ref i); if (text2 == null) { break; } list.Add(text2); } } else { if (json[i] != '"') { for (; i < json.Length && json[i] != ',' && json[i] != '}'; i++) { } continue; } string text3 = ReadString(json, ref i); if (text3 != null) { list.Add(text3); } } if (list.Count > 0) { dictionary[text] = list.ToArray(); } } return dictionary; } private static void SkipSpace(string s, ref int i) { while (i < s.Length && char.IsWhiteSpace(s[i])) { i++; } } private static string ReadString(string s, ref int i) { SkipSpace(s, ref i); if (i >= s.Length || s[i] != '"') { return null; } i++; StringBuilder stringBuilder = new StringBuilder(); while (i < s.Length) { char c = s[i++]; switch (c) { case '"': return stringBuilder.ToString(); default: stringBuilder.Append(c); continue; case '\\': break; } if (i >= s.Length) { break; } char c2 = s[i++]; switch (c2) { case 'n': stringBuilder.Append('\n'); break; case 'r': stringBuilder.Append('\r'); break; case 't': stringBuilder.Append('\t'); break; case 'b': stringBuilder.Append('\b'); break; case 'f': stringBuilder.Append('\f'); break; case 'u': if (i + 4 <= s.Length) { if (int.TryParse(s.Substring(i, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var result)) { stringBuilder.Append((char)result); } i += 4; } break; default: stringBuilder.Append(c2); break; } } return null; } private static void Report(string message) { if (Reported.Add(message) && Log != null) { Log(message); } } } } namespace AllfathersGrasp.Ui { public static class GraspButton { [CompilerGenerated] private static class <>O { public static UnityAction <0>__OnClick; } private const float Width = 180f; private const float ReturnDelaySeconds = 0.35f; private static GameObject _go; private static TMP_Text[] _labels; private static UITooltip _tooltip; private static float _returnAt; private static int _caption = -1; public static RectTransform Rect { get; private set; } public static void Build(InventoryGui gui) { //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Expected O, but got Unknown //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Expected O, but got Unknown //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)gui == (Object)null || (Object)(object)gui.m_takeAllButton == (Object)null || (Object)(object)gui.m_player == (Object)null || ((Object)(object)_go != (Object)null && (Object)(object)_go.transform.parent == (Object)(object)gui.m_player)) { return; } _go = Object.Instantiate<GameObject>(((Component)gui.m_takeAllButton).gameObject, (Transform)(object)gui.m_player, false); ((Object)_go).name = "AllfathersGrasp_Button"; _go.SetActive(true); Localize[] componentsInChildren = _go.GetComponentsInChildren<Localize>(true); foreach (Localize val in componentsInChildren) { Object.Destroy((Object)(object)val); } Button component = _go.GetComponent<Button>(); if ((Object)(object)component != (Object)null) { ((UnityEventBase)component.onClick).RemoveAllListeners(); ButtonClickedEvent onClick = component.onClick; object obj = <>O.<0>__OnClick; if (obj == null) { UnityAction val2 = OnClick; <>O.<0>__OnClick = val2; obj = (object)val2; } ((UnityEvent)onClick).AddListener((UnityAction)obj); } _labels = _go.GetComponentsInChildren<TMP_Text>(true); _tooltip = _go.GetComponent<UITooltip>(); for (int j = 0; j < _labels.Length; j++) { if (!((Object)(object)_labels[j] == (Object)null)) { _labels[j].enableAutoSizing = true; _labels[j].fontSizeMin = 10f; _labels[j].overflowMode = (TextOverflowModes)1; } } Rect = (RectTransform)_go.transform; Rect.anchorMin = new Vector2(1f, 0f); Rect.anchorMax = new Vector2(1f, 0f); Rect.pivot = new Vector2(1f, 1f); Rect.anchoredPosition = new Vector2(0f, -6f); Rect.sizeDelta = new Vector2(180f, Rect.sizeDelta.y); _caption = -1; _returnAt = 0f; Tick(); } public static void Tick() { if ((Object)(object)_go == (Object)null) { return; } InventoryGui instance = InventoryGui.instance; if ((Object)(object)instance == (Object)null || instance.IsContainerOpen()) { _returnAt = Time.unscaledTime + 0.35f; } bool flag = (Object)(object)instance != (Object)null && Time.unscaledTime >= _returnAt; if (_go.activeSelf != flag) { _go.SetActive(flag); } if (!flag) { return; } ItemData val = (((Object)(object)instance != (Object)null) ? instance.m_dragItem : null); int num = ((val != null) ? 1 : 0); if (num == _caption) { return; } _caption = num; string text = Texts.Get((num == 1) ? "button.block" : "button.open"); if (_labels != null) { for (int i = 0; i < _labels.Length; i++) { if ((Object)(object)_labels[i] != (Object)null) { _labels[i].text = text; } } } if (!((Object)(object)_tooltip == (Object)null)) { _tooltip.m_topic = text; _tooltip.m_text = ((num == 1) ? Texts.Get("button.tip.block", "item", Spoken(val)) : Texts.Get("button.tip.open")); } } public static void Reset() { _go = null; Rect = null; _labels = null; _tooltip = null; _caption = -1; _returnAt = 0f; } private static void OnClick() { InventoryGui instance = InventoryGui.instance; if ((Object)(object)instance == (Object)null) { return; } ItemData dragItem = instance.m_dragItem; if (dragItem == null) { GraspPanel.Toggle(); return; } string text = PrefabNameOf(dragItem); if (!string.IsNullOrEmpty(text)) { Enforcer.List.Add(text); } instance.SetupDragItem((ItemData)null, (Inventory)null, 0); Tick(); } private static string PrefabNameOf(ItemData item) { if (item == null) { return null; } if ((Object)(object)item.m_dropPrefab != (Object)null) { return ((Object)item.m_dropPrefab).name; } if (item.m_shared == null) { return null; } return item.m_shared.m_name; } private static string Spoken(ItemData item) { if (item == null || item.m_shared == null) { return ""; } string name = item.m_shared.m_name; if (Localization.instance == null) { return name; } return Localization.instance.Localize(name); } } public static class GraspPanel { private struct Icon { public Texture Texture; public Rect Coords; } private const float Margin = 18f; private const float Tile = 56f; private const float Gap = 6f; private const float MinWidth = 320f; private static readonly Dictionary<string, Icon> Icons = new Dictionary<string, Icon>(); private static GUIStyle _title; private static GUIStyle _hint; private static GUIStyle _action; private static Texture2D _rule; private static Texture2D _tileBed; private static Texture2D _tileHot; private static int _styledFor = -1; private static float _lastWidth = 320f; public static bool IsOpen { get; private set; } public static void Toggle() { IsOpen = !IsOpen; } public static void Close() { IsOpen = false; } public static void Tick() { if (IsOpen) { InventoryGui instance = InventoryGui.instance; if (!InventoryGui.IsVisible() || (Object)(object)instance == (Object)null || instance.IsContainerOpen()) { Close(); } else { PanelBackdrop.Prepare(); } } } public static void Forget() { Close(); Icons.Clear(); _styledFor = -1; PanelFont.Forget(); } public static void Draw() { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) if (!IsOpen) { return; } InventoryGui instance = InventoryGui.instance; Blocklist list = Enforcer.List; if (!((Object)(object)instance == (Object)null) && list != null && InventoryGui.IsVisible() && !instance.IsContainerOpen()) { float num = WidthFor(instance); EnsureStyles(num); bool canRestore = list.CanRestore; bool flag = canRestore || list.Count > 0; Rect val = Place(instance, list.Count, num, flag); PanelBackdrop.Draw(PanelBackdrop.Snap(val)); float num2 = ((Rect)(ref val)).x + 18f; float num3 = ((Rect)(ref val)).width - 36f; float num4 = ((Rect)(ref val)).y + 18f; PanelText.Label(new Rect(num2, num4, num3, (float)_title.fontSize * 1.6f), Texts.Get("panel.title"), _title); num4 += (float)_title.fontSize * 1.7f; GUI.DrawTexture(new Rect(num2, num4, num3, 2f), (Texture)(object)_rule, (ScaleMode)0); num4 += 10f; string tile = DrawTiles(new Rect(num2, num4, num3, TileHeight(list.Count)), list); num4 += TileHeight(list.Count) + 10f; PanelText.Label(new Rect(num2, num4, num3, (float)_hint.fontSize * 3f), (list.Count == 0) ? Texts.Get("panel.empty") : Texts.Get("panel.hint"), _hint); num4 += (float)_hint.fontSize * 2.6f; bool onAction = false; if (flag) { onAction = DrawAction(new Rect(num2, num4, num3, (float)_action.fontSize * 2f), Texts.Get(canRestore ? "panel.undo" : "panel.clear")); } DrawDragged(val); Handle(val, list, tile, onAction, canRestore); } } private static void DrawDragged(Rect panel) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0099: 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_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) if (Event.current == null || (int)Event.current.type != 7) { return; } InventoryGui instance = InventoryGui.instance; ItemData val = (((Object)(object)instance != (Object)null) ? instance.m_dragItem : null); if (val == null || (Object)(object)instance.m_dragGo == (Object)null) { return; } Transform val2 = instance.m_dragGo.transform.Find("icon"); Rect val3 = ScreenRectOf((RectTransform)(object)((val2 is RectTransform) ? val2 : null)); if (((Rect)(ref val3)).width < 1f || ((Rect)(ref val3)).height < 1f) { Vector2 mousePosition = Event.current.mousePosition; ((Rect)(ref val3))..ctor(mousePosition.x - 28f, mousePosition.y - 28f, 56f, 56f); } if (!((Rect)(ref panel)).Overlaps(val3)) { return; } Sprite icon = val.GetIcon(); if (!((Object)(object)icon == (Object)null) && !((Object)(object)icon.texture == (Object)null)) { GUI.DrawTextureWithTexCoords(val3, (Texture)(object)icon.texture, CoordsOf(icon)); if (instance.m_dragAmount > 1) { TextAnchor alignment = _hint.alignment; Color textColor = _hint.normal.textColor; _hint.alignment = (TextAnchor)8; _hint.normal.textColor = PanelText.Ui(Color.white); PanelText.Label(new Rect(((Rect)(ref val3)).x, ((Rect)(ref val3)).y, ((Rect)(ref val3)).width - 2f, ((Rect)(ref val3)).height), instance.m_dragAmount.ToString(), _hint); _hint.alignment = alignment; _hint.normal.textColor = textColor; } } } private static Rect Place(InventoryGui gui, int count, float width, bool hasAction) { //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_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_00d5: Unknown result type (might be due to invalid IL or missing references) Rect val = ScreenRectOf(gui.m_player); float num = 36f + TitleHeight() + 12f + TileHeight(count) + 10f + HintHeight() + (hasAction ? ActionHeight() : 0f); Rect val2 = ScreenRectOf(GraspButton.Rect); float num2 = ((((Rect)(ref val2)).height > 1f) ? ((Rect)(ref val2)).yMax : (((Rect)(ref val)).yMax + 40f)); float x = ((Rect)(ref val)).x; float num3 = num2 + 8f; x = Mathf.Clamp(x, 8f, Mathf.Max(8f, (float)Screen.width - width - 8f)); num3 = Mathf.Clamp(num3, 8f, Mathf.Max(8f, (float)Screen.height - num - 8f)); return new Rect(x, num3, width, num); } private static Rect ScreenRectOf(RectTransform rect) { //IL_0082: 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) if ((Object)(object)rect == (Object)null) { return new Rect(0f, 0f, 0f, 0f); } Vector3[] array = (Vector3[])(object)new Vector3[4]; rect.GetWorldCorners(array); return new Rect(array[0].x, (float)Screen.height - array[2].y, array[2].x - array[0].x, array[2].y - array[0].y); } private static Rect CoordsOf(Sprite sprite) { //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_0057: Unknown result type (might be due to invalid IL or missing references) Rect textureRect = sprite.textureRect; return new Rect(((Rect)(ref textureRect)).x / (float)((Texture)sprite.texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)sprite.texture).height, ((Rect)(ref textureRect)).width / (float)((Texture)sprite.texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)sprite.texture).height); } private static string DrawTiles(Rect where, Blocklist list) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) if (list.Count == 0) { return null; } Vector2 val = (Vector2)((Event.current != null) ? Event.current.mousePosition : new Vector2(-1f, -1f)); int num = PerRow(((Rect)(ref where)).width); string result = null; Rect val2 = default(Rect); for (int i = 0; i < list.Count; i++) { int num2 = i / num; int num3 = i % num; ((Rect)(ref val2))..ctor(((Rect)(ref where)).x + (float)num3 * 62f, ((Rect)(ref where)).y + (float)num2 * 62f, 56f, 56f); bool flag = ((Rect)(ref val2)).Contains(val); if (flag) { result = list.Names[i]; } GUI.DrawTexture(val2, (Texture)(object)(flag ? _tileHot : _tileBed), (ScaleMode)0); DrawIcon(val2, list.Names[i]); } return result; } private static void DrawIcon(Rect tile, string name) { //IL_0062: 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_0050: Unknown result type (might be due to invalid IL or missing references) Icon icon = IconFor(name); Rect val = default(Rect); ((Rect)(ref val))..ctor(((Rect)(ref tile)).x + 4f, ((Rect)(ref tile)).y + 4f, ((Rect)(ref tile)).width - 8f, ((Rect)(ref tile)).height - 8f); if ((Object)(object)icon.Texture == (Object)null) { PanelText.Label(val, Short(name), _hint); } else { GUI.DrawTextureWithTexCoords(val, icon.Texture, icon.Coords); } } private static Icon IconFor(string name) { //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) if (Icons.TryGetValue(name, out var value)) { return value; } Icon icon = default(Icon); if ((Object)(object)ObjectDB.instance != (Object)null) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(name); ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null); Sprite val2 = (((Object)(object)val != (Object)null && val.m_itemData != null) ? val.m_itemData.GetIcon() : null); if ((Object)(object)val2 != (Object)null && (Object)(object)val2.texture != (Object)null) { icon.Texture = (Texture)(object)val2.texture; icon.Coords = CoordsOf(val2); } } Icons[name] = icon; return icon; } private static bool DrawAction(Rect where, string label) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0048: 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) bool flag = Event.current != null && ((Rect)(ref where)).Contains(Event.current.mousePosition); GUI.DrawTexture(where, (Texture)(object)(flag ? _tileHot : _tileBed), (ScaleMode)0); TextAnchor alignment = _action.alignment; _action.alignment = (TextAnchor)4; PanelText.Label(where, label, _action); _action.alignment = alignment; return flag; } private static void Handle(Rect panel, Blocklist list, string tile, bool onAction, bool undoable) { //IL_000a: 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) Event current = Event.current; if (current == null || (int)current.type != 0 || current.button != 0 || !((Rect)(ref panel)).Contains(current.mousePosition)) { return; } InventoryGui instance = InventoryGui.instance; ItemData val = (((Object)(object)instance != (Object)null) ? instance.m_dragItem : null); if (tile != null && val == null) { list.Remove(tile); } else if (onAction && val == null) { if (undoable) { list.Restore(); } else { list.Clear(); } } else if (val != null) { string text = (((Object)(object)val.m_dropPrefab != (Object)null) ? ((Object)val.m_dropPrefab).name : ((val.m_shared != null) ? val.m_shared.m_name : null)); if (!string.IsNullOrEmpty(text)) { list.Add(text); } if ((Object)(object)instance != (Object)null) { instance.SetupDragItem((ItemData)null, (Inventory)null, 0); } GraspButton.Tick(); } current.Use(); } private static int PerRow(float width) { return Mathf.Max(1, Mathf.FloorToInt((width + 6f) / 62f)); } private static float TileHeight(int count) { if (count == 0) { return 0f; } int num = PerRow(Mathf.Max(320f, _lastWidth) - 36f); int num2 = Mathf.CeilToInt((float)count / (float)num); return (float)num2 * 56f + (float)(num2 - 1) * 6f; } private static float WidthFor(InventoryGui gui) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) Rect val = ScreenRectOf(gui.m_player); return Mathf.Max(320f, ((Rect)(ref val)).width); } private static float TitleHeight() { if (_title == null) { return 32f; } return (float)_title.fontSize * 1.7f; } private static float HintHeight() { if (_hint == null) { return 36f; } return (float)_hint.fontSize * 2.6f; } private static float ActionHeight() { if (_action == null) { return 32f; } return (float)_action.fontSize * 2f; } private static void EnsureStyles(float panelWidth) { //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: 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_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) _lastWidth = panelWidth; int num = Mathf.Clamp(Mathf.RoundToInt(panelWidth / 24f), 11, 26); if (_styledFor != num || !((Object)(object)_rule != (Object)null)) { _styledFor = num; Font game = PanelFont.Game; _title = PanelText.Styled(game, Mathf.RoundToInt((float)num * 1.35f), PanelText.Ui(new Color(1f, 0.718f, 0.357f))); _hint = PanelText.Styled(game, Mathf.RoundToInt((float)num * 0.85f), PanelText.Ui(new Color(0.78f, 0.76f, 0.72f))); _hint.wordWrap = true; _action = PanelText.Styled(game, num, PanelText.Ui(new Color(1f, 1f, 1f))); _rule = PanelText.Solid(new Color(0.75f, 0.63f, 0.36f, 0.55f)); _tileBed = PanelText.Solid(new Color(0.04f, 0.04f, 0.05f, 0.55f)); _tileHot = PanelText.Solid(new Color(0.75f, 0.63f, 0.36f, 0.35f)); } } private static string Short(string name) { if (string.IsNullOrEmpty(name) || name.Length <= 7) { return name; } return name.Substring(0, 6) + "."; } } public static class PanelBackdrop { private const float Saturation = 0.25f; private const float Darkness = 0.63f; private const string WantedSprite = ""; private static Texture2D _plain; private static Texture _backdrop; private static Sprite _sprite; private static Texture2D _owned; private static float _saturatedFor = -1f; private static Rect _backdropCoords; private static bool _backdropSearched; private static Vector4 _backdropBorder; private static Rect _backdropRect; private static Color _backdropTint = Color.white; private static Texture2D Plain { get { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_003c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_plain != (Object)null) { return _plain; } _plain = new Texture2D(1, 1, (TextureFormat)4, false); _plain.SetPixel(0, 0, new Color(0.04f, 0.04f, 0.05f, 0.92f)); _plain.Apply(); ((Object)_plain).hideFlags = (HideFlags)61; return _plain; } } public static void Prepare() { FindBackdrop(); if (!((Object)(object)_sprite == (Object)null) && !Mathf.Approximately(_saturatedFor, Mathf.Clamp01(0.25f))) { ApplySaturation(); } } public static void Draw(Rect panel) { //IL_001a: 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_0020: 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_000d: 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_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_backdrop == (Object)null) { GUI.DrawTexture(panel, (Texture)(object)Plain, (ScaleMode)0); return; } Color color = GUI.color; GUI.color = _backdropTint; DrawSliced(panel); float num = Mathf.Clamp01(0.63f); if (num > 0f) { GUI.color = new Color(0f, 0f, 0f, num); DrawSliced(panel); } GUI.color = color; } public static Rect Snap(Rect rect) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) float num = Mathf.Round(((Rect)(ref rect)).x); float num2 = Mathf.Round(((Rect)(ref rect)).y); return new Rect(num, num2, Mathf.Round(((Rect)(ref rect)).xMax) - num, Mathf.Round(((Rect)(ref rect)).yMax) - num2); } private static void DrawSliced(Rect panel) { //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_0022: 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_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009f: 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_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: 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_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) Vector4 backdropBorder = _backdropBorder; float num = Mathf.Clamp((float)Screen.height / 1080f, 1f, 2.5f); panel = Snap(panel); float num2 = Mathf.Round(backdropBorder.x * num); float num3 = Mathf.Round(backdropBorder.y * num); float num4 = Mathf.Round(backdropBorder.z * num); float num5 = Mathf.Round(backdropBorder.w * num); if (num2 + num4 <= 0f || num5 + num3 <= 0f || num2 + num4 >= ((Rect)(ref panel)).width || num5 + num3 >= ((Rect)(ref panel)).height) { GUI.DrawTextureWithTexCoords(Snap(panel), _backdrop, _backdropCoords); return; } Rect backdropRect = _backdropRect; float x = backdropBorder.x; float y = backdropBorder.y; float z = backdropBorder.z; float w = backdropBorder.w; float num6 = ((Rect)(ref panel)).width - num2 - num4; float num7 = ((Rect)(ref panel)).height - num5 - num3; float num8 = ((Rect)(ref backdropRect)).width - x - z; float num9 = ((Rect)(ref backdropRect)).height - w - y; float x2 = ((Rect)(ref panel)).x; float num10 = ((Rect)(ref panel)).x + num2; float num11 = ((Rect)(ref panel)).xMax - num4; float y2 = ((Rect)(ref panel)).y; float num12 = ((Rect)(ref panel)).y + num5; float num13 = ((Rect)(ref panel)).yMax - num3; Patch(new Rect(x2, y2, num2, num5), 0f, num9 + y, x, w); Patch(new Rect(num10, y2, num6, num5), x, num9 + y, num8, w); Patch(new Rect(num11, y2, num4, num5), x + num8, num9 + y, z, w); Patch(new Rect(x2, num12, num2, num7), 0f, y, x, num9); Patch(new Rect(num10, num12, num6, num7), x, y, num8, num9); Patch(new Rect(num11, num12, num4, num7), x + num8, y, z, num9); Patch(new Rect(x2, num13, num2, num3), 0f, 0f, x, y); Patch(new Rect(num10, num13, num6, num3), x, 0f, num8, y); Patch(new Rect(num11, num13, num4, num3), x + num8, 0f, z, y); } private static void Patch(Rect dest, float sx, float sy, float sw, float sh) { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) if (!(((Rect)(ref dest)).width <= 0f) && !(((Rect)(ref dest)).height <= 0f) && !(sw <= 0f) && !(sh <= 0f)) { float num = _backdrop.width; float num2 = _backdrop.height; float num3 = Mathf.Min(0.5f, sw * 0.25f); float num4 = Mathf.Min(0.5f, sh * 0.25f); GUI.DrawTextureWithTexCoords(Snap(dest), _backdrop, new Rect((((Rect)(ref _backdropRect)).x + sx + num3) / num, (((Rect)(ref _backdropRect)).y + sy + num4) / num2, (sw - num3 * 2f) / num, (sh - num4 * 2f) / num2)); } } private static void FindBackdrop() { //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) if (_backdropSearched) { return; } InventoryGui instance = InventoryGui.instance; if ((Object)(object)instance == (Object)null) { return; } _backdropSearched = true; try { List<Image> list = Candidates(); Image val = null; int num = int.MinValue; string text = "".Trim(); for (int i = 0; i < list.Count; i++) { Sprite sprite = list[i].sprite; if (text.Length > 0) { if (string.Equals(((Object)sprite).name, text, StringComparison.OrdinalIgnoreCase)) { val = list[i]; break; } continue; } int num2 = Score(sprite); if (num2 > num) { num = num2; val = list[i]; } } if ((Object)(object)val == (Object)null) { AllfathersGraspPlugin.Log.LogWarning((object)((text.Length > 0) ? ("No game sprite named '" + text + "'. Run 'ae records sprites' to see the list.") : "Found no usable panel sprite; using a plain one.")); return; } Sprite sprite2 = val.sprite; Rect textureRect = sprite2.textureRect; _sprite = sprite2; _backdropTint = ((Graphic)val).color; _backdropBorder = sprite2.border; ApplySaturation(); AllfathersGraspPlugin.Log.LogInfo((object)("Tablet backdrop: using the game's '" + ((Object)sprite2).name + "' (" + (int)((Rect)(ref textureRect)).width + "x" + (int)((Rect)(ref textureRect)).height + ") from " + PathOf(((Component)val).transform) + ", tinted " + ((object)((Graphic)val).color/*cast due to .constrained prefix*/).ToString() + ", border " + ((object)sprite2.border/*cast due to .constrained prefix*/).ToString() + ", drawn in " + ((object)QualitySettings.activeColorSpace/*cast due to .constrained prefix*/).ToString() + " colour. 'ae records panel' lists the alternatives.")); } catch (Exception ex) { AllfathersGraspPlugin.Log.LogWarning((object)("Could not borrow the game's panel image (" + ex.Message + "); using a plain one.")); } } private static void ApplySaturation() { //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) float num = (_saturatedFor = Mathf.Clamp01(0.25f)); if ((Object)(object)_owned != (Object)null) { Object.Destroy((Object)(object)_owned); _owned = null; } if ((Object)(object)_sprite == (Object)null) { return; } if (num < 0.999f) { _owned = Grab(_sprite); if ((Object)(object)_owned != (Object)null) { Desaturate(_owned, num); } } if ((Object)(object)_owned != (Object)null) { _backdrop = (Texture)(object)_owned; _backdropRect = new Rect(0f, 0f, (float)((Texture)_owned).width, (float)((Texture)_owned).height); } else { _backdrop = (Texture)(object)_sprite.texture; _backdropRect = _sprite.textureRect; } _backdropCoords = new Rect(((Rect)(ref _backdropRect)).x / (float)_backdrop.width, ((Rect)(ref _backdropRect)).y / (float)_backdrop.height, ((Rect)(ref _backdropRect)).width / (float)_backdrop.width, ((Rect)(ref _backdropRect)).height / (float)_backdrop.height); } private static void Desaturate(Texture2D texture, float keep) { //IL_000d: 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_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0029: 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) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005f: 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) Color32[] pixels = texture.GetPixels32(); for (int i = 0; i < pixels.Length; i++) { Color32 val = pixels[i]; int grey = val.r * 77 + val.g * 150 + val.b * 29 >> 8; pixels[i] = new Color32(Mix(grey, val.r, keep), Mix(grey, val.g, keep), Mix(grey, val.b, keep), val.a); } texture.SetPixels32(pixels); texture.Apply(); } private static byte Mix(int grey, byte channel, float keep) { return (byte)Mathf.Clamp(Mathf.RoundToInt((float)grey + (float)(channel - grey) * keep), 0, 255); } private static Texture2D Grab(Sprite sprite) { //IL_0010: 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_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Expected O, but got Unknown //IL_00c6: Unknown result type (might be due to invalid IL or missing references) RenderTexture val = null; RenderTexture active = RenderTexture.active; try { Texture texture = (Texture)(object)sprite.texture; Rect textureRect = sprite.textureRect; int num = Mathf.Clamp(Mathf.FloorToInt(((Rect)(ref textureRect)).x), 0, texture.width - 1); int num2 = Mathf.Clamp(Mathf.FloorToInt(((Rect)(ref textureRect)).y), 0, texture.height - 1); int num3 = Mathf.Clamp(Mathf.FloorToInt(((Rect)(ref textureRect)).width), 1, texture.width - num); int num4 = Mathf.Clamp(Mathf.FloorToInt(((Rect)(ref textureRect)).height), 1, texture.height - num2); val = RenderTexture.GetTemporary(texture.width, texture.height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2); Graphics.Blit(texture, val); RenderTexture.active = val; Texture2D val2 = new Texture2D(num3, num4, (TextureFormat)4, false, false); val2.ReadPixels(new Rect((float)num, (float)num2, (float)num3, (float)num4), 0, 0); val2.Apply(); ((Texture)val2).wrapMode = (TextureWrapMode)1; ((Texture)val2).filterMode = (FilterMode)1; ((Object)val2).hideFlags = (HideFlags)61; return val2; } catch (Exception ex) { AllfathersGraspPlugin.Log.LogWarning((object)("Could not copy the panel sprite (" + ex.Message + "); using it as it is.")); return null; } finally { RenderTexture.active = active; if ((Object)(object)val != (Object)null) { RenderTexture.ReleaseTemporary(val); } } } private static int Score(Sprite sprite) { //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_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) string text = ((((Object)sprite).name != null) ? ((Object)sprite).name.ToLowerInvariant() : ""); int num = 0; if (text.IndexOf("woodpanel", StringComparison.Ordinal) >= 0) { num += 100000; } else if (text.IndexOf("panel", StringComparison.Ordinal) >= 0) { num += 50000; } if (text.IndexOf("mask", StringComparison.Ordinal) >= 0) { num -= 500000; } if (text.IndexOf("crafting", StringComparison.Ordinal) >= 0) { num += 8000; } Vector4 border = sprite.border; if (border.x + border.y + border.z + border.w > 0f) { num += 20000; } if (text.IndexOf("separator", StringComparison.Ordinal) >= 0) { num -= 80000; } if (text.IndexOf("button", StringComparison.Ordinal) >= 0) { num -= 80000; } if (text.IndexOf("checkbox", StringComparison.Ordinal) >= 0) { num -= 80000; } Rect textureRect = sprite.textureRect; float width = ((Rect)(ref textureRect)).width; textureRect = sprite.textureRect; float height = ((Rect)(ref textureRect)).height; if (width < 24f || height < 24f) { num -= 60000; } return num + (int)Mathf.Min(width * height / 20f, 30000f); } private static void Collect(Transform root, List<Image> into) { if ((Object)(object)root == (Object)null) { return; } Image[] componentsInChildren = ((Component)root).GetComponentsInChildren<Image>(true); for (int i = 0; i < componentsInChildren.Length; i++) { if (!((Object)(object)componentsInChildren[i] == (Object)null) && !((Object)(object)componentsInChildren[i].sprite == (Object)null) && !((Object)(object)componentsInChildren[i].sprite.texture == (Object)null) && !into.Contains(componentsInChildren[i])) { into.Add(componentsInChildren[i]); } } } private static List<Image> Candidates() { List<Image> list = new List<Image>(); InventoryGui instance = InventoryGui.instance; if ((Object)(object)instance == (Object)null) { return list; } Collect(((Component)instance).transform, list); Collect((Transform)(object)instance.m_crafting, list); Collect((Transform)(object)instance.m_player, list); Collect((Transform)(object)instance.m_container, list); Collect((Transform)(object)instance.m_info, list); return list; } private static string PathOf(Transform node) { if ((Object)(object)node == (Object)null) { return "?"; } string text = ((Object)node).name; Transform parent = node.parent; int num = 0; while ((Object)(object)parent != (Object)null && num < 6) { text = ((Object)parent).name + "/" + text; parent = parent.parent; num++; } return text; } public static string ListSprites(int limit) { List<Image> list = Candidates(); if (list.Count == 0) { return "The inventory does not exist yet - load into a world first."; } List<string> list2 = new List<string>(); List<int> list3 = new List<int>(); for (int i = 0; i < list.Count; i++) { string name = ((Object)list[i].sprite).name; if (!list2.Contains(name)) { list2.Add(name); list3.Add(Score(list[i].sprite)); } } if (list2.Count == 0) { return "No sprites found."; } StringBuilder stringBuilder = new StringBuilder(); for (int j = 0; j < limit; j++) { if (list2.Count <= 0) { break; } int index = 0; for (int k = 1; k < list3.Count; k++) { if (list3[k] > list3[index]) { index = k; } } if (stringBuilder.Length > 0) { stringBuilder.Append(", "); } stringBuilder.Append(list2[index]); list2.RemoveAt(index); list3.RemoveAt(index); } return stringBuilder.ToString(); } public static string DumpPanel(int limit) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) List<Image> list = Candidates(); if (list.Count == 0) { return "The inventory does not exist yet - load into a world first."; } List<Image> list2 = new List<Image>(list); list2.Sort((Image a, Image b) => Score(b.sprite).CompareTo(Score(a.sprite))); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(list.Count).Append(" image(s) under the inventory, drawn in ").Append(QualitySettings.activeColorSpace) .Append(" colour. Best guess first:"); List<string> list3 = new List<string>(); int num = 0; for (int num2 = 0; num2 < list2.Count; num2++) { if (num >= limit) { break; } Sprite sprite = list2[num2].sprite; if (!list3.Contains(((Object)sprite).name)) { list3.Add(((Object)sprite).name); num++; Rect textureRect = sprite.textureRect; stringBuilder.Append("\n").Append(num).Append(". ") .Append(((Object)sprite).name) .Append(" ") .Append((int)((Rect)(ref textureRect)).width) .Append("x") .Append((int)((Rect)(ref textureRect)).height) .Append(" border ") .Append(sprite.border) .Append(" tint ") .Append(Hex(((Graphic)list2[num2]).color)) .Append(" pixels ") .Append(Hex(Average(sprite))) .Append(" at ") .Append(PathOf(((Component)list2[num2]).transform)); } } return stringBuilder.ToString(); } private static string Hex(Color colour) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) return "#" + ColorUtility.ToHtmlStringRGBA(colour); } private static Color Average(Sprite sprite) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) Texture2D val = Grab(sprite); if ((Object)(object)val == (Object)null) { return new Color(0f, 0f, 0f, 0f); } try { Color32[] pixels = val.GetPixels32(); double num = 0.0; double num2 = 0.0; double num3 = 0.0; double num4 = 0.0; for (int i = 0; i < pixels.Length; i++) { double num5 = (double)(int)pixels[i].a / 255.0; if (!(num5 <= 0.02)) { num += (double)(int)pixels[i].r * num5; num2 += (double)(int)pixels[i].g * num5; num3 += (double)(int)pixels[i].b * num5; num4 += num5; } } if (num4 <= 0.0) { return new Color(0f, 0f, 0f, 0f); } return new Color((float)(num / num4 / 255.0), (float)(num2 / num4 / 255.0), (float)(num3 / num4 / 255.0), 1f); } finally { Object.Destroy((Object)(object)val); } } } public static class PanelFont { private static Font _font; private static bool _searched; public static Font Game { get { if (_searched) { return _font; } _searched = true; try { List<Font> list = new List<Font>(); Font[] array = Resources.FindObjectsOfTypeAll<Font>(); for (int i = 0; i < array.Length; i++) { if ((Object)(object)array[i] != (Object)null && !string.IsNullOrEmpty(((Object)array[i]).name)) { list.Add(array[i]); } } _font = Pick(list, allowItalic: false) ?? Pick(list, allowItalic: true); } catch (Exception ex) { AllfathersGraspPlugin.Log.LogInfo((object)("Using the default font for the panel (" + ex.Message + ").")); } return _font; } } public static void Forget() { _font = null; _searched = false; } private static Font Pick(List<Font> fonts, bool allowItalic) { for (int i = 0; i < fonts.Count; i++) { string text = ((Object)fonts[i]).name ?? ""; if ((text.IndexOf("Norse", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Averia", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Valheim", StringComparison.OrdinalIgnoreCase) >= 0) && (allowItalic || (text.IndexOf("Italic", StringComparison.OrdinalIgnoreCase) < 0 && text.IndexOf("Oblique", StringComparison.OrdinalIgnoreCase) < 0))) { return fonts[i]; } } return null; } } public static class PanelText { public static Color Ui(Color colour) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) if ((int)QualitySettings.activeColorSpace != 1) { return colour; } return ((Color)(ref colour)).gamma; } public static void Label(Rect where, string text, GUIStyle style) { //IL_002a: 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_0045: 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_0056: 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_00a8: 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_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) if (!string.IsNullOrEmpty(text) && style != null) { float num = Mathf.Max(1f, (float)style.fontSize / 16f); Color textColor = style.normal.textColor; style.normal.textColor = Ui(new Color(0f, 0f, 0f, textColor.a * 0.9f)); GUI.Label(new Rect(((Rect)(ref where)).x - num, ((Rect)(ref where)).y, ((Rect)(ref where)).width, ((Rect)(ref where)).height), text, style); GUI.Label(new Rect(((Rect)(ref where)).x + num, ((Rect)(ref where)).y, ((Rect)(ref where)).width, ((Rect)(ref where)).height), text, style); GUI.Label(new Rect(((Rect)(ref where)).x, ((Rect)(ref where)).y - num, ((Rect)(ref where)).width, ((Rect)(ref where)).height), text, style); GUI.Label(new Rect(((Rect)(ref where)).x, ((Rect)(ref where)).y + num, ((Rect)(ref where)).width, ((Rect)(ref where)).height), text, style); style.normal.textColor = textColor; GUI.Label(where, text, style); } } public static GUIStyle Styled(Font font, int size, Color colour) { //IL_000a: 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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown //IL_0032: Unknown result type (might be due to invalid IL or missing references) GUIStyle val = new GUIStyle(GUI.skin.label) { fontSize = size, richText = false, wordWrap = false, alignment = (TextAnchor)0 }; val.normal.textColor = colour; val.normal.background = null; if ((Object)(object)font != (Object)null) { val.font = font; } return val; } public static Texture2D Solid(Color colour) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Expected O, but got Unknown //IL_000d: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(1, 1, (TextureFormat)5, false); val.SetPixel(0, 0, colour); val.Apply(); ((Object)val).hideFlags = (HideFlags)61; return val; } } } namespace AllfathersGrasp.Patches { [HarmonyPatch(typeof(InventoryGui), "Awake")] internal static class InventoryGuiAwakePatch { [HarmonyPostfix] private static void Postfix(InventoryGui __instance) { GraspButton.Build(__instance); } } [HarmonyPatch(typeof(ItemDrop), "Awake")] internal static class ItemDropAwakePatch { [HarmonyPostfix] private static void Postfix(ItemDrop __instance) { Enforcer.Apply(__instance); } } } namespace AllfathersGrasp.Grasp { public sealed class Blocklist { private readonly List<string> _names = new List<string>(); private readonly HashSet<string> _lookup = new HashSet<string>(StringComparer.OrdinalIgnoreCase); private List<string> _undo; private readonly ReadOnlyCollection<string> _view; public IList<string> Names => _view; public int Count => _names.Count; public bool CanRestore => _undo != null; public event Action Changed; public Blocklist() { _view = new ReadOnlyCollection<string>(_names); } public static Blocklist Parse(string line) { Blocklist blocklist = new Blocklist(); if (string.IsNullOrEmpty(line)) { return blocklist; } string[] array = line.Split(new char[1] { ',' }); for (int i = 0; i < array.Length; i++) { blocklist.Insert(array[i]); } return blocklist; } public string ToConfigString() { return string.Join(",", _names.ToArray()); } public bool Contains(string name) { string text = Clean(name); if (text != null) { return _lookup.Contains(text); } return false; } public bool Add(string name) { if (!Insert(name)) { return false; } _undo = null; Raise(); return true; } public bool Remove(string name) { string text = Clean(name); if (text == null || !_lookup.Remove(text)) { return false; } for (int i = 0; i < _names.Count; i++) { if (string.Equals(_names[i], text, StringComparison.OrdinalIgnoreCase)) { _names.RemoveAt(i); break; } } _undo = null; Raise(); return true; } public void Clear() { if (_names.Count != 0) { _undo = new List<string>(_names); _names.Clear(); _lookup.Clear(); Raise(); } } public bool Restore() { if (_undo == null) { return false; } _names.Clear(); _lookup.Clear(); for (int i = 0; i < _undo.Count; i++) { _names.Add(_undo[i]); _lookup.Add(_undo[i]); } _undo = null; Raise(); return true; } private bool Insert(string name) { string text = Clean(name); if (text == null || !_lookup.Add(text)) { return false; } _names.Add(text); return true; } private static string Clean(string name) { if (name == null) { return null; } string text = name.Trim(); if (text.Length != 0) { return text; } return null; } private void Raise() { this.Changed?.Invoke(); } } public static class Enforcer { private static readonly HashSet<int> Ours = new HashSet<int>(); public static Blocklist List { get; private set; } public static void Load() { List = Blocklist.Parse(ModConfig.Blocked.Value); List.Changed += OnChanged; ModConfig.Blocked.SettingChanged += delegate { if (!(List.ToConfigString() == ModConfig.Blocked.Value)) { List.Changed -= OnChanged; List = Blocklist.Parse(ModConfig.Blocked.Value); List.Changed += OnChanged; ApplyAll(); } }; } public static bool Blocks(string prefabName) { if (ModConfig.Enabled.Value && List != null) { return List.Contains(prefabName); } return false; } public static string PrefabNameOf(ItemDrop drop) { if (!((Object)(object)drop == (Object)null)) { return drop.GetPrefabName(((Object)((Component)drop).gameObject).name); } return null; } public static void Apply(ItemDrop drop) { if ((Object)(object)drop == (Object)null) { return; } int instanceID = ((Object)drop).GetInstanceID(); if (Blocks(PrefabNameOf(drop))) { if (drop.m_autoPickup) { drop.m_autoPickup = false; Ours.Add(instanceID); Verbose("stays put: " + PrefabNameOf(drop)); } } else if (Ours.Remove(instanceID)) { drop.m_autoPickup = true; Verbose("picked up again: " + PrefabNameOf(drop)); } } public static void ApplyAll() { List<ItemDrop> s_instances = ItemDrop.s_instances; if (s_instances != null) { for (int i = 0; i < s_instances.Count; i++) { Apply(s_instances[i]); } } } public static void Forget() { Ours.Clear(); } private static void OnChanged() { ModConfig.Blocked.Value = List.ToConfigString(); ApplyAll(); } private static void Verbose(string message) { if (ModConfig.Verbose.Value) { AllfathersGraspPlugin.Log.LogInfo((object)message); } } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }