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 UnlockTree v0.2.2
plugins/UnlockTree.dll
Decompiled a day ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Managers; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using Newtonsoft.Json.Linq; 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: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace UnlockTree { [HarmonyPatch(typeof(InventoryGui), "Show")] internal static class InventoryButton { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static Func<Button, bool> <>9__5_1; public static Func<Button, bool> <>9__5_2; public static UnityAction <>9__5_3; public static Func<Selectable, RectTransform> <>9__5_5; public static Func<Image, bool> <>9__5_8; public static Func<Image, bool> <>9__5_9; internal bool <Postfix>b__5_1(Button b) { if (!<Postfix>g__Opens|5_0(b, "OnOpenTrophies") && !<Postfix>g__Opens|5_0(b, "OnOpenSkills") && !<Postfix>g__Opens|5_0(b, "OnOpenTexts")) { return <Postfix>g__Opens|5_0(b, "OnOpenAchievements"); } return true; } internal bool <Postfix>b__5_2(Button b) { return <Postfix>g__Opens|5_0(b, "OnOpenTrophies"); } internal void <Postfix>b__5_3() { InventoryGui.instance.Hide(); SagaWindow.Open(); } internal RectTransform <Postfix>b__5_5(Selectable b) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown return (RectTransform)((Component)b).transform; } internal bool <Postfix>b__5_8(Image i) { if ((Object)(object)((Component)i).gameObject != (Object)(object)_btn) { return Object.op_Implicit((Object)(object)i.sprite); } return false; } internal bool <Postfix>b__5_9(Image i) { if (!(((Object)i).name == "Image")) { return ((Object)i).name.ToLower().Contains("icon"); } return true; } } private static GameObject _btn; private static Sprite _icon; public static void Destroy() { if (Object.op_Implicit((Object)(object)_btn)) { Object.Destroy((Object)(object)_btn); } _btn = null; } private static Color? RowGold(List<RectTransform> line) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_01cf: 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_0082: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014c: 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_0178: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) foreach (RectTransform item in line) { if ((Object)(object)item == (Object)(RectTransform)_btn.transform) { continue; } Image[] componentsInChildren = ((Component)item).GetComponentsInChildren<Image>(true); foreach (Image val in componentsInChildren) { if (!Object.op_Implicit((Object)(object)val.sprite) || ((Object)val).name == "Background") { continue; } try { Texture2D texture = val.sprite.texture; Rect textureRect = val.sprite.textureRect; Color[] pixels = texture.GetPixels((int)((Rect)(ref textureRect)).x, (int)((Rect)(ref textureRect)).y, (int)((Rect)(ref textureRect)).width, (int)((Rect)(ref textureRect)).height); float num = 0f; float num2 = 0f; float num3 = 0f; float num4 = 0f; Color[] array = pixels; foreach (Color val2 in array) { if (val2.a > 0.8f) { num += val2.r; num2 += val2.g; num3 += val2.b; num4 += 1f; } } if (num4 < 20f) { continue; } Color val3 = new Color(num / num4, num2 / num4, num3 / num4) * ((Graphic)val).color; val3.a = ((Graphic)val).color.a; Plugin.Log.LogInfo((object)$"row icon colour from {((Object)item).name}/{((Object)val).name}: {val3}"); return val3; } catch { } } } return new Color(0.79f, 0.6f, 0.31f); } private static Sprite Icon() { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)_icon)) { return _icon; } using Stream stream = typeof(InventoryButton).Assembly.GetManifestResourceStream("button_icon.png"); if (stream == null) { return null; } byte[] array = new byte[stream.Length]; stream.Read(array, 0, array.Length); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); MethodInfo method = typeof(ImageConversion).GetMethod("LoadImage", new Type[3] { typeof(Texture2D), typeof(byte[]), typeof(bool) }); if (method == null || !(bool)method.Invoke(null, new object[3] { val, array, false })) { return null; } return _icon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); } private static void Postfix(InventoryGui __instance) { //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Expected O, but got Unknown //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Expected O, but got Unknown //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_0199: 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_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: 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_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0165: 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_0175: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Expected O, but got Unknown //IL_0315: Unknown result type (might be due to invalid IL or missing references) //IL_031f: Unknown result type (might be due to invalid IL or missing references) //IL_0324: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_02c1: Unknown result type (might be due to invalid IL or missing references) //IL_02c6: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Unknown result type (might be due to invalid IL or missing references) //IL_02f2: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_0554: Unknown result type (might be due to invalid IL or missing references) //IL_0559: Unknown result type (might be due to invalid IL or missing references) //IL_058d: Unknown result type (might be due to invalid IL or missing references) //IL_056f: Unknown result type (might be due to invalid IL or missing references) //IL_0574: Unknown result type (might be due to invalid IL or missing references) //IL_0576: Unknown result type (might be due to invalid IL or missing references) //IL_0578: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)_btn)) { return; } try { List<Button> list = (from b in ((Component)__instance).GetComponentsInChildren<Button>(true) where Opens(b, "OnOpenTrophies") || Opens(b, "OnOpenSkills") || Opens(b, "OnOpenTexts") || Opens(b, "OnOpenAchievements") select b).ToList(); Button val = ((IEnumerable<Button>)list).FirstOrDefault((Func<Button, bool>)((Button b) => Opens(b, "OnOpenTrophies"))) ?? list.FirstOrDefault(); if (!Object.op_Implicit((Object)(object)val)) { Plugin.Log.LogWarning((object)"inventory buttons not found; use the hotkey"); return; } _btn = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)val).transform.parent); ((Object)_btn).name = "UnlockTreeButton"; Button component = _btn.GetComponent<Button>(); for (int num = 0; num < ((UnityEventBase)component.onClick).GetPersistentEventCount(); num++) { ((UnityEventBase)component.onClick).SetPersistentListenerState(num, (UnityEventCallState)0); } ((UnityEventBase)component.onClick).RemoveAllListeners(); ButtonClickedEvent onClick = component.onClick; object obj = <>c.<>9__5_3; if (obj == null) { UnityAction val2 = delegate { InventoryGui.instance.Hide(); SagaWindow.Open(); }; <>c.<>9__5_3 = val2; obj = (object)val2; } ((UnityEvent)onClick).AddListener((UnityAction)obj); RectTransform val3 = (RectTransform)((Component)val).transform; Transform panel = ((Transform)val3).parent; Transform val4 = panel; Rect rect; while (Object.op_Implicit((Object)(object)val4.parent)) { rect = ((RectTransform)val4).rect; float width = ((Rect)(ref rect)).width; rect = val3.rect; if (!(width < ((Rect)(ref rect)).width * 4f)) { break; } val4 = val4.parent; } float y = panel.InverseTransformPoint(((Transform)val3).position).y; rect = val3.rect; float w = ((Rect)(ref rect)).width; rect = val3.rect; float h = ((Rect)(ref rect)).height; List<RectTransform> list2 = (from r in ((Component)val4).GetComponentsInChildren<Selectable>(true).Where(delegate(Selectable b) { //IL_0043: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)b) && (Object)(object)((Component)b).gameObject != (Object)(object)_btn && ((Component)b).gameObject.activeSelf && !Object.op_Implicit((Object)(object)((Component)b).GetComponentInParent<InventoryGrid>()) && Mathf.Abs(panel.InverseTransformPoint(((Component)b).transform.position).y - y) < h * 0.3f) { Rect rect2 = ((RectTransform)((Component)b).transform).rect; return ((Rect)(ref rect2)).width < w * 2f; } return false; }).Select((Func<Selectable, RectTransform>)((Selectable b) => (RectTransform)((Component)b).transform)) orderby panel.InverseTransformPoint(((Transform)r).position).x select r).ToList(); RectTransform val5 = (RectTransform)_btn.transform; if (list2.Count >= 2) { float x = panel.InverseTransformPoint(((Transform)list2[0]).position).x; float x2 = panel.InverseTransformPoint(((Transform)list2[list2.Count - 1]).position).x; list2.Insert(list2.Count - 1, val5); float num2 = (x2 - x) / (float)(list2.Count - 1); for (int num3 = 0; num3 < list2.Count; num3++) { Vector3 val6 = panel.InverseTransformPoint(((Transform)list2[num3]).position); ((Transform)list2[num3]).position = panel.TransformPoint(new Vector3(x + (float)num3 * num2, y, val6.z)); } } val5.anchoredPosition += Plugin.ButtonOffset.Value; _btn.transform.SetAsLastSibling(); Plugin.Log.LogInfo((object)string.Format("inventory row ({0}): {1}", list2.Count, string.Join(", ", list2.Select((RectTransform r) => ((Object)r).name + (((Object)(object)((Transform)r).parent == (Object)(object)panel) ? "" : " [other parent]"))))); StringBuilder stringBuilder = new StringBuilder(); Transform[] componentsInChildren = _btn.GetComponentsInChildren<Transform>(true); foreach (Transform val7 in componentsInChildren) { string[] obj2 = new string[7] { " [", ((Object)val7).name, ": img=", null, null, null, null }; Image component2 = ((Component)val7).GetComponent<Image>(); object obj3; if (component2 == null) { obj3 = null; } else { Sprite sprite = component2.sprite; obj3 = ((sprite != null) ? ((Object)sprite).name : null); } obj2[3] = (string)obj3; obj2[4] = " txt="; TMP_Text component3 = ((Component)val7).GetComponent<TMP_Text>(); obj2[5] = ((component3 != null) ? component3.text : null); obj2[6] = "]"; stringBuilder.Append(string.Concat(obj2)); } Plugin.Log.LogInfo((object)("button parts:" + stringBuilder)); TMP_Text[] componentsInChildren2 = _btn.GetComponentsInChildren<TMP_Text>(true); for (int num4 = 0; num4 < componentsInChildren2.Length; num4++) { componentsInChildren2[num4].text = Text.L("Unlock Tree", "Arbre de progression"); } UITooltip component4 = _btn.GetComponent<UITooltip>(); if (Object.op_Implicit((Object)(object)component4)) { component4.m_text = Text.L("Unlock Tree", "Arbre de progression"); } Image component5 = _btn.GetComponent<Image>(); List<Image> source = (from i in _btn.GetComponentsInChildren<Image>(true) where (Object)(object)((Component)i).gameObject != (Object)(object)_btn && Object.op_Implicit((Object)(object)i.sprite) select i).ToList(); Image val8 = ((IEnumerable<Image>)source).FirstOrDefault((Func<Image, bool>)((Image i) => ((Object)i).name == "Image" || ((Object)i).name.ToLower().Contains("icon"))) ?? source.LastOrDefault() ?? ((Object.op_Implicit((Object)(object)component5) && Object.op_Implicit((Object)(object)component5.sprite)) ? component5 : null); if (Object.op_Implicit((Object)(object)val8)) { Sprite val9 = Icon(); if (val9 != null) { Color color = ((Graphic)val8).color; Color? val10 = RowGold(list2); if (val10.HasValue) { Color valueOrDefault = val10.GetValueOrDefault(); color = valueOrDefault; } val8.sprite = val9; val8.preserveAspect = true; ((Graphic)val8).color = color; } } Plugin.Log.LogInfo((object)$"inventory button added next to '{((Object)val).name}' ({list.Count} buttons in the row)"); } catch (Exception ex) { Plugin.Log.LogWarning((object)("inventory button failed: " + ex)); } static bool Opens(Button b, string m) { return Enumerable.Range(0, ((UnityEventBase)b.onClick).GetPersistentEventCount()).Any((int i) => ((UnityEventBase)b.onClick).GetPersistentMethodName(i) == m); } } [CompilerGenerated] internal static bool <Postfix>g__Opens|5_0(Button b, string m) { return Enumerable.Range(0, ((UnityEventBase)b.onClick).GetPersistentEventCount()).Any((int i) => ((UnityEventBase)b.onClick).GetPersistentMethodName(i) == m); } } public enum Look { Shown, Unknown } public static class Themes { public static readonly (string key, string en, string fr)[] All = new(string, string, string)[5] { ("explore", "Exploration", "Exploration"), ("craft", "Crafting", "Artisanat"), ("build", "Building", "Construction"), ("combat", "Combat", "Combat"), ("food", "Food & farming", "Cuisine & culture") }; private static readonly HashSet<int> Weapons = new HashSet<int> { 3, 4, 14, 20, 22, 5 }; private static readonly HashSet<int> Armour = new HashSet<int> { 6, 7, 11, 17, 18 }; private static readonly HashSet<int> Ammo = new HashSet<int> { 9, 23 }; private static readonly HashSet<string> Gather = new HashSet<string> { "pick", "mine", "chop", "break", "loot", "fish", "drop", "spawn", "roam", "buy" }; private static readonly HashSet<string> FoodStations = new HashSet<string> { "piece_cauldron", "piece_cookingstation", "piece_cookingstation_iron", "piece_oven", "fermenter", "piece_preptable", "piece_MeadCauldron" }; public static HashSet<string> Of(Tree t, Node n) { HashSet<string> hashSet = new HashSet<string>(); List<string> list = (from h in n.Options.SelectMany((Option o) => o.How) select (string)h["t"]).ToList(); string text = n.Best?.How.Select((JObject h) => (string)h["t"]).FirstOrDefault(); switch (n.Kind) { case "biome": { (string, string, string)[] all = All; for (int num = 0; num < all.Length; num++) { (string, string, string) tuple = all[num]; hashSet.Add(tuple.Item1); } break; } case "gate": hashSet.Add("explore"); hashSet.Add("combat"); break; case "boss": case "mob": hashSet.Add("combat"); if (n.Kind == "boss") { hashSet.Add("explore"); } break; case "level": case "piece": case "station": hashSet.Add("build"); if (n.Kind != "piece") { hashSet.Add("craft"); } if (FoodStations.Contains(n.Station ?? n.Id)) { hashSet.Add("food"); } break; case "tool": hashSet.Add("craft"); hashSet.Add("explore"); break; case "item": { int itemType = n.ItemType; bool flag = list.Contains("craft") || list.Contains("convert"); if (Weapons.Contains(itemType) || Armour.Contains(itemType) || Ammo.Contains(itemType)) { hashSet.Add("combat"); if (flag) { hashSet.Add("craft"); } } else { switch (itemType) { case 2: hashSet.Add("food"); break; case 13: hashSet.Add("combat"); break; case 15: case 19: hashSet.Add("craft"); hashSet.Add("explore"); break; default: if ((text != null && Gather.Contains(text)) || !flag) { hashSet.Add("explore"); } if (flag) { hashSet.Add("craft"); } break; } } if (list.Contains("grow") || n.Options.Any((Option o) => o.Req.Any((string r) => FoodStations.Contains(r)))) { hashSet.Add("food"); } break; } default: hashSet.Add("explore"); break; } return hashSet; } } public class View { public string Theme; public Dictionary<string, Look> Shown = new Dictionary<string, Look>(); public Dictionary<string, string> Parent = new Dictionary<string, string>(); public Dictionary<string, List<string>> Kids = new Dictionary<string, List<string>>(); public List<string> Roots = new List<string>(); public int Done; public int Total; public static View Build(Tree t, Progress p, string theme, Dictionary<string, HashSet<string>> themes) { View view = new View { Theme = theme }; List<Node> list = t.Nodes.Values.Where((Node n) => n.Reachable && In(n.Id)).ToList(); Dictionary<string, string> dictionary = list.ToDictionary((Node n) => n.Id, Tp); view.Total = list.Count; view.Done = list.Count((Node n) => p.IsDone(n.Id)); foreach (Node item in list) { view.Shown[item.Id] = ((p.Of(item.Id) == State.Locked) ? Look.Unknown : Look.Shown); } foreach (string key in view.Shown.Keys) { string text = dictionary[key]; if (text != null && view.Shown.ContainsKey(text)) { view.Parent[key] = text; if (!view.Kids.TryGetValue(text, out var value)) { value = (view.Kids[text] = new List<string>()); } value.Add(key); } else { view.Roots.Add(key); } } foreach (List<string> value3 in view.Kids.Values) { value3.Sort(delegate(string a, string b) { int num = Key(a).CompareTo(Key(b)); if (num != 0) { return num; } int num2 = t.Nodes[a].Depth.CompareTo(t.Nodes[b].Depth); return (num2 == 0) ? string.CompareOrdinal(a, b) : num2; }); } view.Roots = (from r in view.Roots orderby (!(r == "biome:Ocean")) ? 1 : 0, (!(t.Nodes[r].Kind == "biome")) ? 1 : 0, t.Nodes[r].Depth select r).ToList(); return view; bool In(string id) { if (themes.TryGetValue(id, out var value2)) { return value2.Contains(theme); } return false; } int Key(string id) { return (t.Nodes[id].Kind == "biome") ? 1 : 0; } string Tp(Node n) { HashSet<string> hashSet = new HashSet<string>(); Node node = t.Get(n.Parent); while (node != null && hashSet.Add(node.Id)) { if (In(node.Id)) { return node.Id; } node = t.Get(node.Parent); } return null; } } } public static class Layout { public class Block { public string From; public float C; public float R; public int Cols; public int Rows; public List<string> Ids = new List<string>(); } private class Shape { public List<(string id, int c, int r)> Cells = new List<(string, int, int)>(); public List<Block> Blocks = new List<Block>(); public Dictionary<int, (int top, int bottom)> Cols = new Dictionary<int, (int, int)>(); public void Add(string id, int c, int r) { Cells.Add((id, c, r)); Cols[c] = (Cols.TryGetValue(c, out (int, int) value) ? (Math.Min(value.Item1, r), Math.Max(value.Item2, r)) : (r, r)); } public int Fit(Shape other, int gap) { int num = int.MinValue; foreach (KeyValuePair<int, (int, int)> col in other.Cols) { if (Cols.TryGetValue(col.Key, out (int, int) value)) { num = Math.Max(num, value.Item2 + 1 + gap - col.Value.Item1); } } if (num != int.MinValue) { return num; } if (Cols.Count != 0) { return Cols.Values.Min(((int top, int bottom) x) => x.top); } return 0; } public void Merge(Shape o, int dc, int dr) { foreach (var (id, num, num2) in o.Cells) { Add(id, num + dc, num2 + dr); } foreach (Block block in o.Blocks) { block.C += dc; block.R += dr; Blocks.Add(block); } } } public const float CW = 112f; public const float CH = 104f; private static Dictionary<string, float[]> _saved; public static List<Block> Blocks = new List<Block>(); private static string FilePath => Path.Combine(Paths.ConfigPath, "unlocktree.layout.json"); public static Dictionary<string, float[]> Saved { get { if (_saved != null) { return _saved; } try { string text = null; if (Plugin.DevMode.Value && File.Exists(FilePath)) { text = File.ReadAllText(FilePath); } else { using Stream stream = typeof(Layout).Assembly.GetManifestResourceStream("unlocktree.layout.json"); if (stream != null) { using StreamReader streamReader = new StreamReader(stream); text = streamReader.ReadToEnd(); } } if (text != null) { _saved = JsonConvert.DeserializeObject<Dictionary<string, float[]>>(text); } if (_saved != null && !_saved.ContainsKey("_v2")) { Plugin.Log.LogWarning((object)"old layout format (absolute positions) ignored"); _saved = null; } } catch (Exception ex) { Plugin.Log.LogWarning((object)("layout unreadable, using the automatic one: " + ex.Message)); } Dictionary<string, float[]> dictionary = _saved; if (dictionary == null) { Dictionary<string, float[]> dictionary2 = new Dictionary<string, float[]>(); dictionary2["_v2"] = new float[2] { 2f, 0f }; dictionary = dictionary2; } _saved = dictionary; return dictionary; } } private static void Save() { if (!Plugin.DevMode.Value) { return; } try { File.WriteAllText(FilePath, JsonConvert.SerializeObject((object)Saved, (Formatting)1)); } catch (Exception ex) { Plugin.Log.LogWarning((object)ex.Message); } } public static string Key(string theme, string id) { return theme + "|" + id; } public static string BlockKey(string from) { return "block:" + from; } public static (float c, float r) Offset(string theme, string id) { if (!Saved.TryGetValue(Key(theme, id), out var value)) { return (c: 0f, r: 0f); } return (c: value[0], r: value[1]); } public static void Move(string theme, string id, float dc, float dr) { (float c, float r) tuple = Offset(theme, id); float item = tuple.c; float item2 = tuple.r; item += dc; item2 += dr; if (Math.Abs(item) < 0.01f && Math.Abs(item2) < 0.01f) { Saved.Remove(Key(theme, id)); } else { Saved[Key(theme, id)] = new float[2] { item, item2 }; } Save(); } public static void ResetTheme(string theme) { foreach (string item in Saved.Keys.Where((string k) => k.StartsWith(theme + "|")).ToList()) { Saved.Remove(item); } Save(); } public static Dictionary<string, (float c, float r)> Place(View v) { Shape shape = new Shape(); foreach (string root in v.Roots) { Shape shape2 = Walk(root); shape.Merge(shape2, 0, (shape.Cells.Count != 0) ? Math.Max(shape.Fit(shape2, 1), 0) : 0); } Dictionary<string, (float, float)> dictionary = shape.Cells.ToDictionary(((string id, int c, int r) x) => x.id, ((string id, int c, int r) x) => ((float, float))(x.c, x.r)); Blocks = shape.Blocks; Dictionary<string, Block> blockOf = new Dictionary<string, Block>(); foreach (Block block2 in Blocks) { foreach (string id3 in block2.Ids) { blockOf[id3] = block2; } } Dictionary<string, (float c, float r)> cum = new Dictionary<string, (float, float)>(); Dictionary<string, (float, float)> dictionary2 = new Dictionary<string, (float, float)>(); foreach (KeyValuePair<string, (float, float)> item in dictionary) { (float, float) tuple = Cum(item.Key); dictionary2[item.Key] = (item.Value.Item1 + tuple.Item1, item.Value.Item2 + tuple.Item2); } foreach (Block block3 in Blocks) { (float, float) tuple2 = Cum(block3.From); (float, float) tuple3 = Offset(v.Theme, BlockKey(block3.From)); block3.C += tuple2.Item1 + tuple3.Item1; block3.R += tuple2.Item2 + tuple3.Item2; } return dictionary2; (float c, float r) Cum(string id) { if (cum.TryGetValue(id, out (float, float) value)) { return value; } (float, float) tuple4 = Offset(v.Theme, id); if (blockOf.TryGetValue(id, out var value2)) { (float, float) tuple5 = Offset(v.Theme, BlockKey(value2.From)); tuple4 = (tuple4.Item1 + tuple5.Item1, tuple4.Item2 + tuple5.Item2); } if (v.Parent.TryGetValue(id, out var value3)) { (float, float) tuple6 = Cum(value3); tuple4 = (tuple4.Item1 + tuple6.Item1, tuple4.Item2 + tuple6.Item2); } return cum[id] = tuple4; } Shape Walk(string id) { Shape shape3 = new Shape(); shape3.Add(id, 0, 0); List<string> value; List<string> obj = (v.Kids.TryGetValue(id, out value) ? value : new List<string>()); List<string> list = obj.Where((string k) => !v.Kids.ContainsKey(k) || v.Kids[k].Count == 0).ToList(); List<string> list2 = obj.Except(list).ToList(); if (list.Count > 0) { int count = list.Count; int num = Math.Min(3, (count + 4) / 5); int num2 = (count + num - 1) / num; Block block = new Block { From = id, C = 1f, R = 0f, Cols = num2, Rows = num }; for (int num3 = 0; num3 < list.Count; num3++) { shape3.Add(list[num3], 1 + num3 % num2, num3 / num2); block.Ids.Add(list[num3]); } if (list.Count > 1) { shape3.Blocks.Add(block); } } foreach (string item2 in list2) { Shape shape4 = Walk(item2); Shape shape5 = new Shape(); foreach (var (id2, num4, r) in shape4.Cells) { shape5.Add(id2, num4 + 1, r); } int dr = ((shape3.Cells.Count != 1) ? Math.Max(shape3.Fit(shape5, 0), 0) : 0); shape3.Merge(shape4, 1, dr); } return shape3; } } } public static class LiveBuilder { private static readonly (int bit, string name)[] Biomes = new(int, string)[9] { (1, "Meadows"), (8, "BlackForest"), (2, "Swamp"), (4, "Mountain"), (16, "Plains"), (256, "Ocean"), (512, "Mistlands"), (32, "AshLands"), (64, "DeepNorth") }; private static IEnumerable<string> Bits(int mask) { return from b in Biomes where (mask & b.bit) != 0 select b.name; } private static JObject H(string t, params (string k, object v)[] kv) { //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_0017: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) JObject val = new JObject { ["t"] = JToken.op_Implicit(t) }; for (int i = 0; i < kv.Length; i++) { var (text, obj) = kv[i]; if (obj != null) { val[text] = (JToken)((!(obj is IEnumerable<string> enumerable) || obj is string) ? ((object)JToken.FromObject(obj)) : ((object)new JArray((object)enumerable))); } } return val; } private static string Pretty(string prefab) { string input = Regex.Replace(prefab ?? "", "\\s*\\(\\d+\\)", ""); input = Regex.Replace(input, "(_frac|_new|_destructible)", "").Replace('_', ' '); input = Regex.Replace(input, "(?<=[a-z])(?=[A-Z])", " "); input = Regex.Replace(input, "(?<=[A-Za-z])\\d+\\b|\\b\\d+\\b", ""); List<string> list = new List<string>(); string[] array = input.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text in array) { if (list.Count == 0 || !string.Equals(list[list.Count - 1], text, StringComparison.OrdinalIgnoreCase)) { list.Add(text); } } input = string.Join(" ", list); if (input.Length <= 0) { return input; } return char.ToUpper(input[0]) + input.Substring(1); } private static string Label(string prefab, string token) { if (string.IsNullOrEmpty(token) || !token.StartsWith("$")) { return Pretty(prefab); } return token; } public static Tree Build(Tree shipped) { //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Expected I4, but got Unknown //IL_05a5: Unknown result type (might be due to invalid IL or missing references) //IL_05ac: Expected I4, but got Unknown //IL_0a61: Unknown result type (might be due to invalid IL or missing references) //IL_0a68: Expected I4, but got Unknown //IL_0b8b: Unknown result type (might be due to invalid IL or missing references) //IL_0bd0: Unknown result type (might be due to invalid IL or missing references) //IL_0c15: Unknown result type (might be due to invalid IL or missing references) //IL_0c54: Unknown result type (might be due to invalid IL or missing references) //IL_0c93: Unknown result type (might be due to invalid IL or missing references) //IL_0d5f: Unknown result type (might be due to invalid IL or missing references) //IL_0d9e: Unknown result type (might be due to invalid IL or missing references) Tree t = new Tree { Source = "live" }; ObjectDB instance = ObjectDB.instance; ZNetScene instance2 = ZNetScene.instance; ZoneSystem instance3 = ZoneSystem.instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance2 == (Object)null || (Object)(object)instance3 == (Object)null) { throw new Exception("game databases not ready"); } Dictionary<string, GameObject> prefabs = new Dictionary<string, GameObject>(); foreach (GameObject item8 in instance2.m_prefabs.Concat(instance2.m_nonNetViewPrefabs ?? new List<GameObject>())) { if (Object.op_Implicit((Object)(object)item8) && !prefabs.ContainsKey(((Object)item8).name)) { prefabs[((Object)item8).name] = item8; } } Dictionary<string, ItemDrop> items = new Dictionary<string, ItemDrop>(); foreach (GameObject item9 in instance.m_items) { if (Object.op_Implicit((Object)(object)item9)) { ItemDrop component = item9.GetComponent<ItemDrop>(); if (component != null && !items.ContainsKey(((Object)item9).name)) { items[((Object)item9).name] = component; } } } (int, string)[] biomes = Biomes; for (int i = 0; i < biomes.Length; i++) { string item = biomes[i].Item2; t.Make("biome:" + item, "biome", "$biome_" + item.ToLower()); } Dictionary<string, HashSet<string>> vegBiomes = new Dictionary<string, HashSet<string>>(); foreach (ZoneVegetation item10 in instance3.m_vegetation) { if (item10.m_enable && Object.op_Implicit((Object)(object)item10.m_prefab)) { AddBiomes(vegBiomes, ((Object)item10.m_prefab).name, Bits((int)item10.m_biome)); } } Dictionary<string, HashSet<string>> links = new Dictionary<string, HashSet<string>>(); foreach (var (a, val) in All<Destructible>()) { Link(a, val.m_spawnWhenDestroyed); } foreach (var (a2, val2) in All<TreeBase>()) { Link(a2, val2.m_logPrefab); Link(a2, val2.m_stubPrefab); } foreach (var (a3, val3) in All<TreeLog>()) { Link(a3, val3.m_subLogPrefab); } for (int j = 0; j < 6; j++) { foreach (KeyValuePair<string, HashSet<string>> item11 in links) { if (!vegBiomes.TryGetValue(item11.Key, out var value)) { continue; } foreach (string item12 in item11.Value.ToList()) { AddBiomes(vegBiomes, item12, value.ToList()); } } } Dictionary<string, Character> chars = All<Character>().ToDictionary(((string name, Character c) x) => x.name, ((string name, Character c) x) => x.c); Dictionary<string, string> setter = new Dictionary<string, string>(); foreach (KeyValuePair<string, Character> item13 in chars) { if (!string.IsNullOrEmpty(item13.Value.m_defeatSetGlobalKey) && !setter.ContainsKey(item13.Value.m_defeatSetGlobalKey)) { setter[item13.Value.m_defeatSetGlobalKey] = "mob:" + item13.Key; } } for (int num = 1; num <= 3; num++) { if (setter.TryGetValue("BossHildir" + num, out var value2)) { setter["Hildir" + num] = value2; } } Dictionary<string, List<(string biome, string key)>> spawnOpts = new Dictionary<string, List<(string, string)>>(); List<SpawnSystemList> list = new List<SpawnSystemList>(); foreach (var item14 in All<SpawnSystem>()) { SpawnSystem item2 = item14.c; list.AddRange(item2.m_spawnLists.Where((SpawnSystemList l) => Object.op_Implicit((Object)(object)l))); } list.AddRange(Resources.FindObjectsOfTypeAll<SpawnSystemList>()); foreach (SpawnSystemList item15 in list.Distinct()) { foreach (SpawnData spawner in item15.m_spawners) { int num2 = (int)spawner.m_biome; if (!spawner.m_enabled || !Object.op_Implicit((Object)(object)spawner.m_prefab) || num2 == -1 || num2 == 0 || num2 >= 65535) { continue; } foreach (string item16 in Bits(num2)) { if (!spawnOpts.TryGetValue(((Object)spawner.m_prefab).name, out List<(string, string)> value3)) { value3 = (spawnOpts[((Object)spawner.m_prefab).name] = new List<(string, string)>()); } if (!value3.Contains(("biome:" + item16, spawner.m_requiredGlobalKey ?? ""))) { value3.Add(("biome:" + item16, spawner.m_requiredGlobalKey ?? "")); } } } } Dictionary<string, List<(List<string> req, JObject how)>> placedOpts = new Dictionary<string, List<(List<string>, JObject)>>(); foreach (var (spawnerPrefab, val4) in All<CreatureSpawner>()) { if (Object.op_Implicit((Object)(object)val4.m_creaturePrefab)) { Placed(((Object)val4.m_creaturePrefab).name, spawnerPrefab, val4.m_requiredGlobalKey); } } foreach (var item17 in All<SpawnArea>()) { var (spawnerPrefab2, _) = item17; foreach (SpawnData prefab2 in item17.c.m_prefabs) { if (Object.op_Implicit((Object)(object)prefab2.m_prefab)) { Placed(((Object)prefab2.m_prefab).name, spawnerPrefab2, null); } } } Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>(); foreach (var (text, val5) in All<CharacterDrop>()) { if (Creature(text) == null) { continue; } dictionary[text] = (from d in val5.m_drops where Object.op_Implicit((Object)(object)d.m_prefab) select ((Object)d.m_prefab).name).ToList(); foreach (Drop drop in val5.m_drops) { if (Object.op_Implicit((Object)(object)drop.m_prefab) && drop.m_chance > 0f) { Item(((Object)drop.m_prefab).name)?.Add(new string[1] { "mob:" + text }, H("drop", ("chance", Math.Round(drop.m_chance * 100f, 1)), ("lo", drop.m_amountMin), ("hi", drop.m_amountMax))); } } } t.MobDrops = dictionary; HashSet<string> hashSet = new HashSet<string>(from val14 in instance.m_recipes where Object.op_Implicit((Object)(object)val14) && val14.m_enabled && Object.op_Implicit((Object)(object)val14.m_item) select ((Object)val14.m_item).name); Dictionary<string, Dictionary<string, int>> tools = new Dictionary<string, Dictionary<string, int>> { ["pickaxe"] = new Dictionary<string, int>(), ["chop"] = new Dictionary<string, int>() }; foreach (KeyValuePair<string, ItemDrop> item18 in items) { if (!hashSet.Contains(item18.Key)) { continue; } SharedData shared = item18.Value.m_itemData.m_shared; int num3 = (int)shared.m_itemType; if (num3 != 9 && num3 != 23) { if (shared.m_damages.m_pickaxe > 0f) { tools["pickaxe"][item18.Key] = shared.m_toolTier; } if (shared.m_damages.m_chop > 0f) { tools["chop"][item18.Key] = shared.m_toolTier; } } if (item18.Key.Contains("Bomb") && shared.m_toolTier > 3) { tools["pickaxe"][item18.Key] = shared.m_toolTier; } } foreach (GameObject value10 in prefabs.Values) { DamageModifiers? val6 = null; bool flag = false; string token = null; List<string> list3 = new List<string>(); MineRock component2 = value10.GetComponent<MineRock>(); int minToolTier; if (component2 != null) { minToolTier = component2.m_minToolTier; val6 = component2.m_damageModifiers; list3.AddRange(Drops(component2.m_dropItems)); token = component2.m_name; } else { MineRock5 component3 = value10.GetComponent<MineRock5>(); if (component3 != null) { minToolTier = component3.m_minToolTier; val6 = component3.m_damageModifiers; list3.AddRange(Drops(component3.m_dropItems)); token = component3.m_name; } else { TreeBase component4 = value10.GetComponent<TreeBase>(); if (component4 != null) { minToolTier = component4.m_minToolTier; val6 = component4.m_damageModifiers; flag = true; list3.AddRange(Drops(component4.m_dropWhenDestroyed)); } else { TreeLog component5 = value10.GetComponent<TreeLog>(); if (component5 != null) { minToolTier = component5.m_minToolTier; val6 = component5.m_damages; flag = true; list3.AddRange(Drops(component5.m_dropWhenDestroyed)); } else { Destructible component6 = value10.GetComponent<Destructible>(); if (component6 == null) { continue; } minToolTier = component6.m_minToolTier; val6 = component6.m_damages; if (Object.op_Implicit((Object)(object)component6.m_spawnWhenDestroyed) && items.ContainsKey(((Object)component6.m_spawnWhenDestroyed).name)) { list3.Add(((Object)component6.m_spawnWhenDestroyed).name); } } } } } DropOnDestroyed component7 = value10.GetComponent<DropOnDestroyed>(); if (component7 != null) { list3.AddRange(Drops(component7.m_dropWhenDestroyed)); } List<string> list4 = (from x in list3.Distinct() where Item(x) != null select x).ToList(); if (list4.Count == 0 || !vegBiomes.TryGetValue(((Object)value10).name, out var value4)) { continue; } List<string> first; string t2; if (flag || (val6.HasValue && Only(val6.Value, "chop"))) { first = new List<string> { Tool("chop", minToolTier) }; t2 = "chop"; } else if ((val6.HasValue && Only(val6.Value, "pickaxe")) || minToolTier > 0) { first = new List<string> { Tool("pickaxe", minToolTier) }; t2 = "mine"; } else { first = new List<string>(); t2 = "break"; } JObject how = H(t2, ("src", Label(((Object)value10).name, token))); foreach (string item19 in list4) { foreach (string item20 in value4) { t.Nodes[item19].Add(first.Concat(new string[1] { "biome:" + item20 }), how); } } } foreach (var (text2, val7) in All<Pickable>()) { if (!vegBiomes.TryGetValue(text2, out var value5)) { continue; } List<string> list5 = new List<string>(); if (Object.op_Implicit((Object)(object)val7.m_itemPrefab)) { list5.Add(((Object)val7.m_itemPrefab).name); } list5.AddRange(Drops(val7.m_extraDrops)); foreach (string item21 in list5.Distinct()) { if (Item(item21) == null) { continue; } foreach (string item22 in value5) { t.Nodes[item21].Add(new string[1] { "biome:" + item22 }, H("pick", ("src", Label(text2, val7.m_overrideName)))); } } } Dictionary<string, string> toolFor = new Dictionary<string, string>(); foreach (KeyValuePair<string, ItemDrop> item23 in items) { PieceTable buildPieces = item23.Value.m_itemData.m_shared.m_buildPieces; if (!Object.op_Implicit((Object)(object)buildPieces)) { continue; } foreach (GameObject piece in buildPieces.m_pieces) { if (Object.op_Implicit((Object)(object)piece) && !toolFor.ContainsKey(((Object)piece).name)) { toolFor[((Object)piece).name] = item23.Key; } } } Dictionary<string, List<string>> extOf = new Dictionary<string, List<string>>(); foreach (var (item3, val8) in All<StationExtension>()) { if (Object.op_Implicit((Object)(object)val8.m_craftingStation)) { if (!extOf.TryGetValue(((Object)val8.m_craftingStation).name, out var value6)) { value6 = (extOf[((Object)val8.m_craftingStation).name] = new List<string>()); } value6.Add(item3); } } foreach (var item24 in All<Smelter>()) { var (st, _) = item24; foreach (ItemConversion item25 in item24.c.m_conversion) { ItemDrop obj = item25.m_from; GameObject obj2 = ((obj != null) ? ((Component)obj).gameObject : null); ItemDrop to = item25.m_to; Convert(st, obj2, (to != null) ? ((Component)to).gameObject : null); } } foreach (var item26 in All<Fermenter>()) { var (st2, _) = item26; foreach (ItemConversion item27 in item26.c.m_conversion) { ItemDrop obj3 = item27.m_from; GameObject obj4 = ((obj3 != null) ? ((Component)obj3).gameObject : null); ItemDrop to2 = item27.m_to; Convert(st2, obj4, (to2 != null) ? ((Component)to2).gameObject : null); } } foreach (var item28 in All<CookingStation>()) { var (st3, _) = item28; foreach (ItemConversion item29 in item28.c.m_conversion) { ItemDrop obj5 = item29.m_from; GameObject obj6 = ((obj5 != null) ? ((Component)obj5).gameObject : null); ItemDrop to3 = item29.m_to; Convert(st3, obj6, (to3 != null) ? ((Component)to3).gameObject : null); } } foreach (var (text3, val9) in All<SapCollector>()) { if (Object.op_Implicit((Object)(object)val9.m_spawnItem)) { Node node = Item(((Object)val9.m_spawnItem).name); if (node != null && Piece(text3) != null) { node.Add(new string[1] { text3 }, H("produce", ("st", text3))); } } } foreach (var (text4, val10) in All<Beehive>()) { if (Object.op_Implicit((Object)(object)val10.m_honeyItem)) { Node node2 = Item(((Object)val10.m_honeyItem).name); if (node2 != null && Piece(text4) != null) { node2.Add(new string[1] { text4 }, H("produce", ("st", text4))); } } } foreach (var (text5, val11) in All<Plant>()) { if (Piece(text5) != null) { GameObject[] array = (GameObject[])(((object)val11.m_grownPrefabs) ?? ((object)new GameObject[0])); foreach (GameObject g in array) { Item(PickItem(g))?.Add(new string[1] { text5 }, H("grow", ("st", text5))); } } } foreach (var item30 in All<WispSpawner>()) { string item4 = item30.name; WispSpawner item5 = item30.c; Node node3 = Item(PickItem(item5.m_wispPrefab)); if (node3 != null && Piece(item4) != null) { node3.Add(new string[1] { item4 }, H("lure", ("st", item4))); } } foreach (KeyValuePair<string, ItemDrop> item31 in items) { Fish component8 = ((Component)item31.Value).GetComponent<Fish>(); if (Object.op_Implicit((Object)(object)component8) && Item(item31.Key) != null) { BaitSetting val12 = ((IEnumerable<BaitSetting>)component8.m_baits).FirstOrDefault((Func<BaitSetting, bool>)((BaitSetting b) => Object.op_Implicit((Object)(object)b.m_bait) && Item(((Object)b.m_bait).name) != null)); if (val12 != null) { t.Nodes[item31.Key].Add((Item("FishingRod") == null) ? new string[1] { ((Object)val12.m_bait).name } : new string[2] { "FishingRod", ((Object)val12.m_bait).name }, H("fish", ("bait", ((Object)val12.m_bait).name))); } } } foreach (var (prefab, val13) in All<Trader>()) { foreach (TradeItem item32 in val13.m_items) { if (Object.op_Implicit((Object)(object)item32.m_prefab)) { Node node4 = Item(((Object)item32.m_prefab).name); if (node4 != null && Item("Coins") != null) { List<string> list7 = GKey(item32.m_requiredGlobalKey); node4.Add(new string[1] { "Coins" }.Concat(list7), H("buy", ("src", Label(prefab, val13.m_name)), ("price", item32.m_price), ("after", list7))); } } } } foreach (Recipe recipe in instance.m_recipes) { Recipe r = recipe; if (!Object.op_Implicit((Object)(object)r) || !r.m_enabled || !Object.op_Implicit((Object)(object)r.m_item) || Item(((Object)r.m_item).name) == null) { continue; } List<Requirement> list8 = r.m_resources.Where((Requirement x) => Object.op_Implicit((Object)(object)x.m_resItem) && !x.m_upgraderResource && Item(((Object)x.m_resItem).name) != null).ToList(); string text6 = (Object.op_Implicit((Object)(object)r.m_craftingStation) ? Station(((Object)r.m_craftingStation).name, Math.Max(1, r.m_minStationLevel)) : null); Node node5 = t.Nodes[((Object)r.m_item).name]; if (r.m_requireOnlyOneIngredient) { foreach (Requirement item33 in list8) { node5.Add(new string[1] { ((Object)item33.m_resItem).name }.Concat((text6 != null) ? new string[1] { text6 } : new string[0]), How((IEnumerable<Requirement>)(object)new Requirement[1] { item33 })); } } else { List<string> list9 = list8.Select((Requirement x) => ((Object)x.m_resItem).name).ToList(); if (text6 != null) { list9.Add(text6); } node5.Add(list9, How(list8)); } JObject How(IEnumerable<Requirement> rs) { //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Expected O, but got Unknown return H("craft", ("st", Object.op_Implicit((Object)(object)r.m_craftingStation) ? ((Object)r.m_craftingStation).name : null), ("level", r.m_minStationLevel), ("amount", r.m_amount), ("res", (object)new JArray((object)rs.Select((Func<Requirement, JArray>)((Requirement x) => new JArray(new object[2] { ((Object)x.m_resItem).name, x.m_amount })))))); } } int num4 = 0; foreach (Node value11 in shipped.Nodes.Values) { foreach (Option option in value11.Options) { if (!option.How.Any((JObject h) => h["loc"] != null) && !option.How.Any((JObject h) => new string[4] { "summon", "offer", "story", "start" }.Contains((string)h["t"]))) { continue; } Node node6 = t.Get(value11.Id); if (node6 == null) { if (value11.Kind == "gate") { node6 = t.Make(value11.Id, "gate", value11.Token); } else if (value11.Kind == "item") { node6 = Item(value11.Id); } else if (value11.Kind == "mob" || value11.Kind == "boss") { node6 = Creature(value11.Prefab ?? value11.Id.Substring(4)); } if (node6 == null) { continue; } node6.En = value11.En; node6.Fr = value11.Fr; } foreach (string item34 in option.Req) { if (!t.Nodes.ContainsKey(item34)) { Node node7 = shipped.Get(item34); if (node7?.Kind == "item") { Item(item34); } else if (node7?.Kind == "mob" || node7?.Kind == "boss") { Creature(node7.Prefab ?? item34.Substring(4)); } } } if (!option.Req.All((string key) => t.Nodes.ContainsKey(key))) { continue; } foreach (JObject item35 in option.How.DefaultIfEmpty(null)) { node6.Add(option.Req, item35); } num4++; } } foreach (Node value12 in t.Nodes.Values) { Node node8 = shipped.Get(value12.Id); if (node8 != null) { value12.En = value12.En ?? node8.En; value12.Fr = value12.Fr ?? node8.Fr; } } Plugin.Log.LogInfo((object)$"live tree: {t.Nodes.Count} nodes, {num4} location options from the shipped tree"); return t; static void AddBiomes(Dictionary<string, HashSet<string>> map, string key, IEnumerable<string> bs) { if (!map.TryGetValue(key, out var value7)) { value7 = (map[key] = new HashSet<string>()); } value7.UnionWith(bs); } IEnumerable<(string name, T c)> All<T>() where T : Component { return from val14 in prefabs.Values select (name: ((Object)val14).name, c: val14.GetComponent<T>()) into x where (Object)(object)x.c != (Object)null select x; } void Convert(string text7, GameObject from, GameObject val14) { if (Object.op_Implicit((Object)(object)from) && Object.op_Implicit((Object)(object)val14) && Item(((Object)from).name) != null) { Node node9 = Item(((Object)val14).name); if (node9 != null && Piece(text7) != null) { node9.Add(new string[2] { ((Object)from).name, text7 }, H("convert", ("st", text7), ("src", ((Object)from).name))); } } } Node Creature(string p) { if (!chars.TryGetValue(p, out var value7)) { return null; } Node node9 = t.Make("mob:" + p, value7.m_boss ? "boss" : "mob", value7.m_name); node9.Prefab = p; if (node9.Options.Count > 0 || node9.Level == -1) { return node9; } node9.Level = -1; if (spawnOpts.TryGetValue(p, out List<(string, string)> value8)) { foreach (var item36 in value8) { string item6 = item36.Item1; string item7 = item36.Item2; List<string> list10 = new List<string> { item6 }; list10.AddRange(GKey(item7)); node9.Add(list10.OrderBy((string x) => x), H("roam", ("after", GKey(item7)))); } } if (!value7.m_boss && placedOpts.TryGetValue(p, out List<(List<string>, JObject)> value9)) { foreach (var (source, how2) in value9) { node9.Add(source.OrderBy((string x) => x), how2); } } return node9; } static List<string> Drops(DropTable dt) { return (from d in dt?.m_drops?.Where((DropData d) => Object.op_Implicit((Object)(object)d.m_item)) select ((Object)d.m_item).name).ToList() ?? new List<string>(); } List<string> GKey(string k) { if (string.IsNullOrEmpty(k) || !setter.TryGetValue(k, out var value7)) { return new List<string>(); } return new List<string> { value7 }; } static bool Immune(DamageModifier m) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 if ((int)m != 3) { return (int)m == 4; } return true; } Node Item(string p) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected I4, but got Unknown if (p != null && items.TryGetValue(p, out var value7)) { SharedData shared2 = value7.m_itemData.m_shared; Node node9 = t.Make(p, "item", shared2.m_name); node9.ItemType = (int)shared2.m_itemType; node9.Prefab = p; return node9; } return null; } void Link(string key, GameObject b) { if (Object.op_Implicit((Object)(object)b)) { AddBiomes(links, key, new string[1] { ((Object)b).name }); } } static bool Only(DamageModifiers m, string k) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0029: 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_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_005c: 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) return new Dictionary<string, DamageModifier> { ["blunt"] = m.m_blunt, ["slash"] = m.m_slash, ["pierce"] = m.m_pierce, ["chop"] = m.m_chop, ["pickaxe"] = m.m_pickaxe }.Where((KeyValuePair<string, DamageModifier> x) => x.Key != k).All((KeyValuePair<string, DamageModifier> x) => Immune(x.Value)); } static string PickItem(GameObject val14) { if (Object.op_Implicit((Object)(object)val14)) { Pickable component9 = val14.GetComponent<Pickable>(); if (component9 != null && Object.op_Implicit((Object)(object)component9.m_itemPrefab)) { return ((Object)component9.m_itemPrefab).name; } } return null; } Node Piece(string p) { //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Expected O, but got Unknown if (p == null || !prefabs.TryGetValue(p, out var value7) || !toolFor.ContainsKey(p)) { return null; } Piece component9 = value7.GetComponent<Piece>(); if (!Object.op_Implicit((Object)(object)component9)) { return null; } bool flag2 = (Object)(object)value7.GetComponent<CraftingStation>() != (Object)null; bool num5 = !t.Nodes.ContainsKey(p); Node node9 = t.Make(p, flag2 ? "station" : "piece", component9.m_name); node9.Prefab = p; if (num5) { List<Requirement> source = component9.m_resources.Where((Requirement val14) => Object.op_Implicit((Object)(object)val14.m_resItem) && Item(((Object)val14.m_resItem).name) != null).ToList(); List<string> list10 = source.Select((Requirement val14) => ((Object)val14.m_resItem).name).ToList(); if (Object.op_Implicit((Object)(object)component9.m_craftingStation)) { string text7 = Station(((Object)component9.m_craftingStation).name, 1); if (text7 != null) { list10.Add(text7); } } if (Item(toolFor[p]) != null) { list10.Add(toolFor[p]); } node9.Add(list10, H("build", ("tool", toolFor[p]), ("near", Object.op_Implicit((Object)(object)component9.m_craftingStation) ? ((Object)component9.m_craftingStation).name : null), ("res", (object)new JArray((object)((IEnumerable<Requirement>)source).Select((Func<Requirement, JArray>)((Requirement val14) => new JArray(new object[2] { ((Object)val14.m_resItem).name, val14.m_amount }))))))); } return node9; } void Placed(string mob, string text7, string gkey) { if (!vegBiomes.TryGetValue(text7, out var value7)) { return; } foreach (string item37 in value7) { List<string> list10 = new List<string> { "biome:" + item37 }; list10.AddRange(GKey(gkey)); if (!placedOpts.TryGetValue(mob, out List<(List<string>, JObject)> value8)) { value8 = (placedOpts[mob] = new List<(List<string>, JObject)>()); } value8.Add((list10, H("spawn", ("src", Label(text7, null)), ("after", GKey(gkey))))); } } string Station(string p, int lvl) { if (lvl <= 1) { if (Piece(p) == null) { return null; } return p; } string text7 = $"{p}@{lvl}"; object obj7; if (!t.Nodes.ContainsKey(text7)) { if (prefabs.TryGetValue(p, out var value7)) { Piece component9 = value7.GetComponent<Piece>(); if (component9 != null) { obj7 = component9.m_name; goto IL_0059; } } obj7 = null; goto IL_0059; } goto IL_00ae; IL_00ae: return text7; IL_0059: string token2 = (string)obj7; Node node9 = t.Make(text7, "level", token2); node9.Station = p; node9.Level = lvl; node9.Exts = (extOf.TryGetValue(p, out var value8) ? value8 : new List<string>()).Where((string e) => Piece(e) != null).ToList(); goto IL_00ae; } string Tool(string kind, int tier) { string text7 = $"tool:{kind}@{tier}"; if (!t.Nodes.ContainsKey(text7)) { Node node9 = t.Make(text7, "tool", null); node9.Tool = kind; node9.Tier = tier; foreach (KeyValuePair<string, int> item38 in tools[kind]) { if (item38.Value >= tier && Item(item38.Key) != null) { node9.Add(new string[1] { item38.Key }, H("tool", ("tier", item38.Value))); } } } return text7; } } } [BepInPlugin("okothings.unlocktree", "Unlock Tree", "0.2.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string Guid = "okothings.unlocktree"; public const string Version = "0.2.2"; internal static Plugin Instance; internal static ManualLogSource Log; internal static ConfigEntry<KeyboardShortcut> ToggleKey; internal static ConfigEntry<Vector2> ButtonOffset; internal static ConfigEntry<bool> DevMode; private Harmony _harmony; private void Awake() { //IL_002b: 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_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "ToggleKey", new KeyboardShortcut((KeyCode)288, Array.Empty<KeyCode>()), "Open / close the Unlock Tree window"); DevMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Dev", "DevMode", false, "Show the Arrange tool: lay out every node of every page by hand. The layout is saved to unlocktree.layout.json in this folder; deploy.sh ships it inside the mod"); ButtonOffset = ((BaseUnityPlugin)this).Config.Bind<Vector2>("General", "InventoryButtonOffset", Vector2.zero, "Move the inventory button if it overlaps another mod's button"); _harmony = new Harmony("okothings.unlocktree"); _harmony.PatchAll(typeof(Plugin).Assembly); Log.LogInfo((object)"Unlock Tree loaded"); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } SagaWindow.Close(); SagaWindow.Destroy(); InventoryButton.Destroy(); } private void Update() { //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) if ((Object)(object)Player.m_localPlayer == (Object)null) { SagaWindow.Close(); return; } KeyboardShortcut value = ToggleKey.Value; if (((KeyboardShortcut)(ref value)).IsDown() && !Console.IsVisible() && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !TextInput.IsVisible()) { SagaWindow.Toggle(); } else if (SagaWindow.IsOpen && Input.GetKeyDown((KeyCode)27) && !Ui.ConsumeEscape()) { SagaWindow.Close(); } } private void LateUpdate() { Ui.WasTyping = Ui.Typing; } } [HarmonyPatch(typeof(TextInput), "IsVisible")] internal static class TypingIsTextInput { private static void Postfix(ref bool __result) { __result |= Ui.Typing; } } [HarmonyPatch(typeof(Chat), "HasFocus")] internal static class TypingIsChatFocus { private static void Postfix(ref bool __result) { __result |= Ui.Typing; } } [HarmonyPatch(typeof(Menu), "Update")] internal static class KeepMenuClosed { private static bool Prefix() { if (!SagaWindow.IsOpen) { return !SagaWindow.ClosedThisFrame; } return false; } } public enum State { Done, Available, Locked } public class Progress { public readonly Dictionary<string, bool> Done = new Dictionary<string, bool>(); public readonly HashSet<string> Implied = new HashSet<string>(); public readonly Dictionary<string, State> St = new Dictionary<string, State>(); public int DoneCount; public int Total; private static T F<T>(object o, string field) { return (T)AccessTools.Field(o.GetType(), field).GetValue(o); } public static Progress Compute(Tree t) { Progress p = new Progress(); Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer)) { return p; } HashSet<string> mats = F<HashSet<string>>(localPlayer, "m_knownMaterial"); HashSet<string> hashSet = F<HashSet<string>>(localPlayer, "m_knownRecipes"); Dictionary<string, int> dictionary = F<Dictionary<string, int>>(localPlayer, "m_knownStations"); HashSet<string> hashSet2 = new HashSet<string>(F<HashSet<string>>(localPlayer, "m_knownBiome")); HashSet<string> trophies = F<HashSet<string>>(localPlayer, "m_trophies"); HashSet<string> hashSet3 = new HashSet<string>(); HashSet<string> hashSet4 = new HashSet<string>(); HashSet<string> hashSet5 = new HashSet<string>(); try { PlayerStats[] array = (PlayerStats[])(((object)Game.instance.GetPlayerProfile().m_playerStats) ?? ((object)new PlayerStats[0])); foreach (PlayerStats val in array) { if (val == null) { continue; } Dictionary<string, float>[] array2 = val.m_enemyStats ?? new Dictionary<string, float>[0]; foreach (Dictionary<string, float> dictionary2 in array2) { if (dictionary2 != null) { hashSet3.UnionWith(from x in dictionary2 where x.Value > 0f select x.Key); } } if (val.m_itemPickupStats != null) { hashSet4.UnionWith(val.m_itemPickupStats.Keys); } if (val.m_itemCraftStats != null) { hashSet4.UnionWith(val.m_itemCraftStats.Keys); } if (val.m_piecesPlacedStats != null) { hashSet5.UnionWith(val.m_piecesPlacedStats.Keys); } } } catch (Exception ex) { Plugin.Log.LogWarning((object)("player stats unavailable: " + ex.Message)); } Dictionary<string, int> dropSources = new Dictionary<string, int>(); Dictionary<string, List<string>> dictionary3 = new Dictionary<string, List<string>>(); foreach (GameObject prefab2 in ZNetScene.instance.m_prefabs) { if (!Object.op_Implicit((Object)(object)prefab2)) { continue; } CharacterDrop component = prefab2.GetComponent<CharacterDrop>(); if (component == null) { continue; } List<string> list = (from d in component.m_drops where Object.op_Implicit((Object)(object)d.m_prefab) select ((Object)d.m_prefab).name).Distinct().ToList(); dictionary3[((Object)prefab2).name] = list; foreach (string item in list) { dropSources[item] = ((!dropSources.TryGetValue(item, out var value)) ? 1 : (value + 1)); } } foreach (Node item2 in t.Nodes.Values.Where((Node x) => x.Reachable)) { bool flag = false; switch (item2.Kind) { case "item": flag = mats.Contains(item2.Token ?? "") || hashSet4.Contains(item2.Id); break; case "piece": flag = hashSet.Contains(item2.Token ?? "") || hashSet5.Contains(item2.Id); break; case "station": { flag = (dictionary.TryGetValue(item2.Token ?? "", out var value4) && value4 >= 1) || hashSet.Contains(item2.Token ?? "") || hashSet5.Contains(item2.Id); break; } case "level": { flag = dictionary.TryGetValue(item2.Token ?? "", out var value3) && value3 >= item2.Level; break; } case "biome": flag = hashSet2.Contains(item2.Id.Substring(6)); break; case "tool": flag = item2.Options.Any((Option o) => o.Req.Count > 0 && mats.Contains(Tok(o.Req[0]) ?? "-")); break; case "boss": case "mob": { GameObject prefab = ZNetScene.instance.GetPrefab(item2.Prefab); Character val2 = ((prefab != null) ? prefab.GetComponent<Character>() : null); flag = hashSet3.Contains(item2.Prefab) || (Object.op_Implicit((Object)(object)val2) && (hashSet3.Contains(val2.m_name) || World(val2.m_defeatSetGlobalKey))); if (!flag && dictionary3.TryGetValue(item2.Prefab ?? "", out var value2)) { flag = value2.Any((string x) => (x.StartsWith("Trophy") || dropSources[x] <= 2) && (mats.Contains(Tok(x) ?? "-") || trophies.Contains(x))); } break; } case "gate": flag = World(item2.Id.Substring(5)); break; } p.Done[item2.Id] = flag; } bool flag2 = true; while (flag2) { flag2 = false; foreach (Node value8 in t.Nodes.Values) { if (!p.Done.TryGetValue(value8.Id, out var value5) || !value5 || value8.Kind == "biome") { continue; } List<Option> list2 = value8.Options.Where((Option o) => o.Req.All((string r) => t.Get(r)?.Reachable ?? false)).ToList(); if (list2.Count == 0) { continue; } foreach (string item3 in list2.Skip(1).Aggregate(list2[0].Req, (IEnumerable<string> a, Option o) => a.Intersect(o.Req)).ToList()) { if (p.Done.TryGetValue(item3, out var value6) && !value6) { p.Done[item3] = true; p.Implied.Add(item3); flag2 = true; } } } } foreach (Node item4 in t.Nodes.Values.Where((Node x) => x.Reachable)) { bool flag3 = p.Done[item4.Id]; p.St[item4.Id] = ((!flag3) ? (item4.Options.Any((Option o) => o.Req.All((string r) => p.Done.TryGetValue(r, out var value7) && value7)) ? State.Available : State.Locked) : State.Done); p.Total++; if (flag3) { p.DoneCount++; } } return p; static string Tok(string text) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(text); if (!Object.op_Implicit((Object)(object)itemPrefab)) { return null; } return itemPrefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_name; } static bool World(string key) { if (!string.IsNullOrEmpty(key) && (Object)(object)ZoneSystem.instance != (Object)null) { return ZoneSystem.instance.GetGlobalKey(key); } return false; } } public bool IsDone(string id) { bool value; return Done.TryGetValue(id ?? "", out value) && value; } public State Of(string id) { if (!St.TryGetValue(id ?? "", out var value)) { return State.Locked; } return value; } } public static class Provider { private static Tree _shipped; private static Tree _tree; public static string Why = ""; public static Tree Shipped { get { if (_shipped == null) { _shipped = Tree.LoadShipped(); _shipped.Solve(); } return _shipped; } } public static Tree Current { get { if (_tree != null) { return _tree; } try { Tree live = LiveBuilder.Build(Shipped); live.Solve(); int num = live.Nodes.Values.Count((Node n) => n.Reachable); int num2 = Shipped.Nodes.Values.Count((Node n) => n.Reachable); List<string> list = Tree.Eras.Where(delegate(string e) { Node node = live.Get("biome:" + e); return node == null || !node.Reachable; }).ToList(); if (list.Count > 0) { Why = "live tree cannot reach " + string.Join(", ", list); } else if ((double)num < (double)num2 * 0.8) { Why = $"live tree reaches only {num} nodes (shipped: {num2})"; } else { _tree = live; Why = $"built live from the game: {num} nodes (shipped tree: {num2})"; } } catch (Exception ex) { Why = "live build failed: " + ex.Message; Plugin.Log.LogError((object)ex); } if (_tree == null) { _tree = Shipped; Why += " - using the shipped tree"; } Plugin.Log.LogInfo((object)("Unlock Tree: " + Why)); return _tree; } } public static void Reset() { _tree = null; } } public static class Text { public static bool Fr { get { if (Localization.instance != null) { return Localization.instance.GetSelectedLanguage() == "French"; } return false; } } public static string L(string en, string fr) { if (!Fr) { return en; } return fr; } private static string Loc(string token) { if (string.IsNullOrEmpty(token) || Localization.instance == null) { return null; } string text = Localization.instance.Localize(token.StartsWith("$") ? token : ("$" + token)); if (!string.IsNullOrEmpty(text) && !text.StartsWith("[")) { return text; } return null; } public static string Name(Tree t, string id) { Node node = t.Get(id); if (node == null) { return id; } return node.Kind switch { "tool" => ((node.Tool == "pickaxe") ? L("Pickaxe", "Pioche") : L("Axe", "Hache")) + L(" tier ", " niveau ") + node.Tier, "level" => (Loc(node.Token) ?? node.Station) + " " + node.Level, "biome" => Loc(node.Token) ?? (Fr ? node.Fr : node.En) ?? id, _ => Loc(node.Token) ?? (Fr ? node.Fr : node.En) ?? id, }; } public static string Src(JToken v) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Invalid comparison between Unknown and I4 if (v == null) { return ""; } if ((int)v.Type == 2) { return (string)v[(object)(Fr ? 1 : 0)]; } string text = (string)v; if (!text.StartsWith("$")) { return text; } return Loc(text) ?? text; } public static string Description(Tree t, string id) { ObjectDB instance = ObjectDB.instance; GameObject val = ((instance != null) ? instance.GetItemPrefab(id) : null); string text = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<ItemDrop>().m_itemData.m_shared.m_description : null); if (text == null) { ZNetScene instance2 = ZNetScene.instance; GameObject val2 = ((instance2 != null) ? instance2.GetPrefab(id) : null); if (val2 != null) { Piece component = val2.GetComponent<Piece>(); if (component != null) { text = component.m_description; } } } if (text == null) { return null; } return Loc(text); } public static string Way(Tree t, Option o) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0954: Unknown result type (might be due to invalid IL or missing references) //IL_03db: Unknown result type (might be due to invalid IL or missing references) //IL_03e2: Invalid comparison between Unknown and I4 //IL_09c5: Unknown result type (might be due to invalid IL or missing references) JObject h = (JObject)(((object)o.How.FirstOrDefault()) ?? ((object)new JObject())); string id = o.Req.FirstOrDefault((string r) => r.StartsWith("mob:")); string text = o.Req.FirstOrDefault((string r) => r.StartsWith("biome:")); int num = ((int?)h["level"]) ?? 1; int num2 = ((int?)h["amount"]) ?? 1; string text2; switch ((string)h["t"]) { case "craft": text2 = ((h["st"] != null && (int)h["st"].Type != 10) ? (L("Craft at ", "Fabriquer à : ") + N("st") + ((num > 1) ? L($" (level {num})", $" (niveau {num})") : "")) : L("Craft by hand", "Fabriquer à la main")); if (num2 > 1) { text2 += L($", makes {num2}", $", donne {num2}"); } break; case "build": text2 = L("Build with the ", "Construire avec : ") + N("tool"); break; case "drop": { double num3 = ((double?)h["chance"]) ?? 100.0; text2 = L("Dropped by ", "Lâché par ") + Name(t, id) + ((num3 < 100.0) ? $" ({num3}%)" : ""); break; } case "mine": text2 = L("Mine ", "Miner : ") + Src(h["src"]); break; case "chop": text2 = L("Chop ", "Abattre : ") + Src(h["src"]); break; case "break": text2 = L("Break ", "Casser : ") + Src(h["src"]); break; case "pick": text2 = L("Pick up ", "Ramasser : ") + Src(h["src"]); break; case "loot": text2 = L("Loot from ", "Butin de : ") + Src(h["src"]); break; case "spawn": text2 = ((h["src"] != null) ? (L("Spawns from ", "Apparaît depuis : ") + Src(h["src"])) : L("Lives there", "Vit sur place")); break; case "roam": text2 = L("Roams", "Rôde"); break; case "summon": text2 = L(string.Format("Summon by offering {0}× ", h["n"]), string.Format("Invoquer en offrant {0}× ", h["n"])) + N("item"); break; case "offer": text2 = L(string.Format("Open by offering {0}× ", h["n"]), string.Format("Ouvrir en offrant {0}× ", h["n"])) + N("item"); break; case "story": return L("Next biome after defeating ", "Biome suivant après avoir vaincu ") + N("boss"); case "start": return L("Where every journey starts", "Là où tout commence"); case "tool": text2 = L(string.Format("Any tool of tier {0}", h["tier"]), string.Format("Outil de niveau {0}", h["tier"])); break; case "convert": text2 = L("Process in a ", "Transformer dans : ") + N("st"); break; case "produce": text2 = L("Collected from a ", "Récolté sur : ") + N("st"); break; case "grow": text2 = L("Grows from a planted ", "Pousse depuis : ") + N("st"); break; case "lure": text2 = L("Lured to a ", "Attiré par : ") + N("st"); break; case "fish": text2 = L("Fish with ", "Pêcher avec : ") + N("bait"); break; case "buy": text2 = L(string.Format("Buy from {0} for {1} coins", Src(h["src"]), h["price"]), string.Format("Acheter à {0} pour {1} pièces", Src(h["src"]), h["price"])); break; case "level": text2 = L("Previous level plus one more upgrade", "Niveau précédent plus une amélioration"); break; default: text2 = L("Get it", "Obtenir"); break; } if (text != null) { text2 = text2 + L(" in ", ", ") + Name(t, text); } if (h["loc"] != null) { text2 = text2 + " (" + Src(h["loc"]) + ")"; } JToken obj = h["keys"]; foreach (JToken item in (JArray)(((object)((obj is JArray) ? obj : null)) ?? ((object)new JArray()))) { text2 = text2 + L(", door locked with ", ", porte fermée par ") + Name(t, (string)item); } JToken obj2 = h["after"]; foreach (JToken item2 in (JArray)(((object)((obj2 is JArray) ? obj2 : null)) ?? ((object)new JArray()))) { text2 = text2 + L(", after ", ", après ") + Name(t, (string)item2); } return text2; string N(string key) { if (h[key] == null) { return ""; } return Name(t, (string)h[key]); } } public static Dictionary<string, int> Amounts(Option o) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) Dictionary<string, int> dictionary = new Dictionary<string, int>(); foreach (JObject item in o.How) { JToken obj = item["res"]; foreach (JToken item2 in (JArray)(((object)((obj is JArray) ? obj : null)) ?? ((object)new JArray()))) { if (!dictionary.ContainsKey((string)item2[(object)0])) { dictionary[(string)item2[(object)0]] = (int)item2[(object)1]; } } string text = (string)item["t"]; if ((text == "summon" || text == "offer") && item["item"] != null) { dictionary[(string)item["item"]] = ((int?)item["n"]) ?? 1; } } return dictionary; } } public class Option { public List<string> Req = new List<string>(); public List<JObject> How = new List<JObject>(); } public class Node { public string Id; public string Kind; public string Token; public string En; public string Fr; public string Prefab; public string Station; public string Tool; public int ItemType = -1; public int Level; public int Tier; public List<string> Exts; public List<Option> Options = new List<Option>(); public int Depth = int.MaxValue; public int Era; public Option Best; public string Parent; public bool Reachable => Depth != int.MaxValue; public void Add(IEnumerable<string> req, JObject how) { List<string> r = req.ToList(); Option option = Options.FirstOrDefault((Option x) => x.Req.Count == r.Count && !x.Req.Except(r).Any()); if (option == null) { option = new Option { Req = r }; Options.Add(option); } if (how != null && option.How.Count < 12 && !option.How.Any((JObject h) => JToken.DeepEquals((JToken)(object)h, (JToken)(object)how))) { option.How.Add(how); } } } public class Tree { public static readonly string[] Eras = new string[8] { "Meadows", "BlackForest", "Swamp", "Mountain", "Plains", "Mistlands", "AshLands", "DeepNorth" }; public Dictionary<string, Node> Nodes = new Dictionary<string, Node>(); public string Source = "?"; public Dictionary<string, List<string>> Unlocks = new Dictionary<string, List<string>>(); public Dictionary<string, List<string>> MobDrops; public Node Get(string id) { if (id == null || !Nodes.TryGetValue(id, out var value)) { return null; } return value; } public Node Make(string id, string kind, string token) { if (!Nodes.TryGetValue(id, out var value)) { Dictionary<string, Node> nodes = Nodes; Node obj = new Node { Id = id, Kind = kind, Token = token }; value = obj; nodes[id] = obj; } return value; } public static Tree LoadShipped() { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Invalid comparison between Unknown and I4 //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Expected O, but got Unknown //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Expected O, but got Unknown using Stream stream = typeof(Tree).Assembly.GetManifestResourceStream("unlocktree.json"); using StreamReader streamReader = new StreamReader(stream); JObject obj = JObject.Parse(streamReader.ReadToEnd()); Tree tree = new Tree { Source = "shipped" }; foreach (JObject item2 in (IEnumerable<JToken>)obj["nodes"]) { JObject val = item2; Node node = tree.Make((string)val["id"], (string)val["kind"], (string)val["token"]); node.En = (string)val["en"]; node.Fr = (string)val["fr"]; node.Prefab = (string)val["prefab"]; node.ItemType = ((int?)val["itype"]) ?? (-1); node.Station = (string)val["station"]; node.Level = ((int?)val["level"]).GetValueOrDefault(); node.Tool = (string)val["tool"]; node.Tier = ((int?)val["tier"]).GetValueOrDefault(); JToken obj2 = val["exts"]; node.Exts = ((obj2 != null && (int)obj2.Type == 2) ? ((IEnumerable<JToken>)val["exts"]).Select((JToken x) => (string)x).ToList() : null); foreach (JObject item3 in (IEnumerable<JToken>)val["options"]) { JObject val2 = item3; Option option = new Option { Req = ((IEnumerable<JToken>)val2["r"]).Select((JToken x) => (string)x).ToList() }; foreach (JObject item4 in (IEnumerable<JToken>)val2["h"]) { JObject item = item4; option.How.Add(item); } node.Options.Add(option); } } return tree; } public void Solve() { foreach (Node value4 in Nodes.Values) { value4.Depth = int.MaxValue; value4.Best = null; value4.Parent = null; } for (int i = 0; i < 300; i++) { bool flag = false; foreach (Node value5 in Nodes.Values) { if (value5.Kind == "level") { LevelOptions(value5); } foreach (Option option in value5.Options) { int num = 0; bool flag2 = true; foreach (string item in option.Req) { int num2 = D(item); if (num2 == int.MaxValue) { flag2 = false; break; } num = Math.Max(num, num2 + 1); } if (flag2 && num < value5.Depth) { value5.Depth = num; value5.Best = option; flag = true; } } } if (!flag) { break; } } Dictionary<string, int> prio = new Dictionary<string, int> { { "biome", 4 }, { "boss", 3 }, { "gate", 3 }, { "level", 2 }, { "station", 2 }, { "tool", 1 } }; foreach (Node item2 in from x in Nodes.Values where x.Reachable orderby x.Depth select x) { if (item2.Kind == "biome") { string value = item2.Id.Substring(6); int num3 = Array.IndexOf(Eras, value); item2.Era = ((num3 >= 0) ? num3 : 0); continue; } List<string> list = item2.Best.Req.Where((string r) => Get(r)?.Reachable ?? false).ToList(); item2.Era = ((list.Count != 0) ? list.Max((string r) => Nodes[r].Era) : 0); if (list.Count > 0) { item2.Parent = (from r in list orderby Nodes[r].Era descending, Nodes[r].Depth descending, prio.TryGetValue(Nodes[r].Kind, out var value3) ? value3 : 0 descending select r).First(); } } foreach (Node item3 in Nodes.Values.Where((Node x) => x.Kind == "biome" && x.Reachable && x.Best != null)) { List<string> list2 = item3.Best.Req.Where((string r) => Get(r)?.Reachable ?? false).ToList(); if (list2.Count > 0) { item3.Parent = list2.OrderByDescending((string r) => Nodes[r].Depth).First(); } } Unlocks.Clear(); foreach (Node item4 in Nodes.Values.Where((Node x) => x.Reachable)) { foreach (Option option2 in item4.Options) { if (!option2.Req.All((string r) => Get(r)?.Reachable ?? false)) { continue; } foreach (string item5 in option2.Req.Distinct()) { if (!(item5 == item4.Id)) { if (!Unlocks.TryGetValue(item5, out var value2)) { value2 = (Unlocks[item5] = new List<string>()); } if (!value2.Contains(item4.Id)) { value2.Add(item4.Id); } } } } } int D(string id) { if (!Nodes.TryGetValue(id, out var value3)) { return int.MaxValue; } return value3.Depth; } } private void LevelOptions(Node n) { //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Expected O, but got Unknown //IL_0127: Expected O, but got Unknown if (n.Exts != null) { List<string> list = (from e in n.Exts where Nodes.ContainsKey(e) orderby Nodes[e].Depth select e).ToList(); int num = n.Level - 1; string text = ((num <= 1) ? n.Station : (n.Station + "@" + num)); List<JObject> list2 = n.Options.FirstOrDefault()?.How; n.Options.Clear(); if (list.Count >= num && Nodes.ContainsKey(text)) { n.Options.Add(new Option { Req = new List<string> { text, list[num - 1] }, How = (list2 ?? new List<JObject> { new JObject { ["t"] = JToken.op_Implicit("level"), ["level"] = JToken.op_Implicit(n.Level), ["exts"] = (JToken)new JArray((object)n.Exts) } }) }); } } } } internal static class Style { public static TMP_FontAsset Body; public static TMP_FontAsset Title; public static Sprite Panel; public static Sprite Slot; public static Material PanelMat; public static Color Gold = new Color(1f, 0.78f, 0.36f); public static Color Steel = new Color(0.62f, 0.78f, 0.9f); public static Color Dim = new Color(0.55f, 0.55f, 0.55f); public static Color Ink = new Color(0.92f, 0.88f, 0.8f); public static Color LockedC = new Color(0.3f, 0.3f, 0.3f, 0.9f); public static void Load() { if (Object.op_Implicit((Object)(object)Body)) { return; } TMP_FontAsset[] source = Resources.FindObjectsOfTypeAll<TMP_FontAsset>(); Body = ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => ((Object)f).name == "Valheim-AveriaSerifLibre")) ?? source.FirstOrDefault(); Title = ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => ((Object)f).name == "Valheim-Norsebold")) ?? Body; InventoryGui instance = InventoryGui.instance; if (!Object.op_Implicit((Object)(object)instance)) { return; } Image val = (Object.op_Implicit((Object)(object)instance.m_player) ? ((IEnumerable<Image>)((Component)instance.m_player).GetComponentsInChildren<Image>(true)).FirstOrDefault((Func<Image, bool>)delegate(Image i) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)i.sprite)) { Rect rect = ((Graphic)i).rectTransform.rect; return ((Rect)(ref rect)).width > 300f; } return false; }) : null); if (Object.op_Implicit((Object)(object)val)) { Panel = val.sprite; PanelMat = ((Graphic)val).material; } Image val2 = ((Object.op_Implicit((Object)(object)instance.m_playerGrid) && Object.op_Implicit((Object)(object)instance.m_playerGrid.m_elementPrefab)) ? instance.m_playerGrid.m_elementPrefab.GetComponent<Image>() : null); if (Object.op_Implicit((Object)(object)val2)) { Slot = val2.sprite; } } } public static class SagaWindow { private static GameObject _root; private static int _closedFrame = -1; public static bool IsOpen { get { if (Object.op_Implicit((Object)(object)_root)) { return _root.activeSelf; } return false; } } public static bool ClosedThisFrame => _closedFrame == Time.frameCount; public static void Toggle() { if (IsOpen) { Close(); } else { Open(); } } public static void Open() { if (!IsOpen) { if (!Object.op_Implicit((Object)(object)_root)) { _root = Ui.Create(); } _root.SetActive(true); GUIManager.BlockInput(true); Ui.Refresh(); } } public static void Destroy() { if (Object.op_Implicit((Object)(object)_root)) { Object.Destroy((Object)(object)_root); } _root = null; } public static void Close() { if (IsOpen) { Ui.ClearSearch(); _root.SetActive(false); _closedFrame = Time.frameCount; GUIManager.BlockInput(false); } } } internal static class Ui { private class LinkClicks : MonoBehaviour, IPointerClickHandler, IEventSystemHandler { public void OnPointerClick(PointerEventData e) { //IL_0009: 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) TMP_Text component = ((Component)this).GetComponent<TMP_Text>(); int num = TMP_TextUtilities.FindIntersectingLink(component, Vector2.op_Implicit(e.position), e.pressEventCamera); if (num >= 0) { Jump(((TMP_LinkInfo)(ref component.textInfo.linkInfo[num])).GetLinkID()); } } } private class Dragger : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler { public string Id; private Vector2 _grab; private string _key; private List<(RectTransform rt, Vector2 start)> _moving; public void OnBeginDrag(PointerEventData e) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Expected O, but got Unknown //IL_00f9: 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_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Expected O, but got Unknown //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Expected O, but got Unknown //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Expected O, but got Unknown RectTransformUtility.ScreenPointToLocalPointInRectangle(_content, e.position, e.pressEventCamera, ref _grab); Layout.Block block = Layout.Blocks.FirstOrDefault((Layout.Block b) => b.Ids.Contains(Id)); IEnumerable<string> collection; if (block != null) { _key = Layout.BlockKey(block.From); collection = block.Ids.SelectMany(Branch); } else { _key = Id; collection = Branch(Id); } HashSet<string> hashSet = new HashSet<string>(collection); _moving = new List<(RectTransform, Vector2)>(); foreach (Transform item in (Transform)_content) { Transform val = item; if (hashSet.Contains(((Object)val).name) || ((Object)val).name == "block:" + (block?.From ?? "-")) { _moving.Add(((RectTransform)val, ((RectTransform)val).anchoredPosition)); } } foreach (Transform item2 in ((Transform)_content).Find("edges")) { Transform t = item2; if (((Object)t).name == "block:" + (block?.From ?? "-") || hashSet.Any((string x) => ((Object)t).name == "block:" + x)) { _moving.Add(((RectTransform)t, ((RectTransform)t).anchoredPosition)); } } foreach (var item3 in _moving) { ((Transform)item3.rt).SetAsLastSibling(); } } private static IEnumerable<string> Branch(string id) { yield return id; if (!_view.Kids.TryGetValue(id, out var value)) { yield break; } foreach (string item in value) { foreach (string item2 in Branch(item)) { yield return item2; } } } public void OnDrag(PointerEventData e) { //IL_0006: 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_003a: 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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) Vector2 val = default(Vector2); RectTransformUtility.ScreenPointToLocalPointInRectangle(_content, e.position, e.pressEventCamera, ref val); foreach (var (val2, val3) in _moving) { val2.anchoredPosition = val3 + (val - _grab); } } public void OnEndDrag(PointerEventData e) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) Vector2 val = default(Vector2); RectTransformUtility.ScreenPointToLocalPointInRectangle(_content, e.position, e.pressEventCamera, ref val); Vector2 val2 = val - _grab; float num = Mathf.Round(val2.x / 112f * 2f) / 2f; float num2 = Mathf.Round((0f - val2.y) / 104f * 2f) / 2f; if (num != 0f || num2 != 0f) { Layout.Move(_theme, _key, num, num2); } Draw(); } } private const float W = 1180f; private const float H = 720f; private const float Side = 360f; private static RectTransform _content; private static RectTransform _viewport; private static RectTransform _detail; private static TMP_Text _title; private static TMP_Text _count; private static TMP_Text _detailText; private static TMP_Text _foot; private static Button _arrangeBtn; private static Button _resetBtn; private static readonly Dictionary<string, Button> _tabs = new Dictionary<string, Button>(); private static Tree _tree; private static Progress _prog; private static View _view; private static string _theme = "explore"; private static string _selected; private static Dictionary<string, HashSet<string>> _themes; private static Tree _themesFor; private static Dictionary<string, (float c, float r)> _pos; public static bool Arranging; private static InputField _search; private static RectTransform _results; private const int MaxResults = 10; public static bool WasTyping; private const float IconY = 42f; public static bool Typing { get { if (Object.op_Implicit((Object)(object)_search)) { return _search.isFocused; } return false; } } private static RectTransform Rect(string name, Transform parent) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) }); val.transform.SetParent(parent, false); return (RectTransform)val.transform; } private static RectTransform Place(RectTransform r, Vector2 aMin, Vector2 aMax, Vector2 oMin, Vector2 oMax) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_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) r.anchorMin = aMin; r.anchorMax = aMax; r.offsetMin = oMin; r.offsetMax = oMax; return r; } private static Image Img(RectTransform r, Color c, Sprite s = null) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) Image val = ((Component)r).gameObject.AddComponent<Image>(); ((Graphic)val).color = c; val.sprite = s; if (Object.op_Implicit((Object)(object)s)) { val.type = (Type)1; } return val; } private static TMP_Text Txt(RectTransform r, string s, float size, Color c, TextAlignmentOptions al = (TextAlignmentOptions)257, bool title = false) { //IL_0029: 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) TextMeshProUGUI obj = ((Component)r).gameObject.AddComponent<TextMeshProUGUI>(); ((TMP_Text)obj).font = (title ? Style.Title : Style.Body); ((TMP_Text)obj).fontSize = size; ((Graphic)obj).color = c; ((TMP_Text)obj).alignment = al; ((TMP_Text)obj).text = s; ((TMP_Text)obj).richText = true; ((Graphic)obj).raycastTarget = false; ((TMP_Text)obj).textWrappingMode = (TextWrappingModes)1; ((TMP_Text)obj).overflowMode = (TextOverflowModes)1; return (TMP_Text)(object)obj; } private static Button Btn(Transform parent, string label, float w, Action onClick) { //IL_0020: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Expected O, but got Unknown //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: 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_00cb: Unknown result type (might be due to invalid IL or missing references) RectTransform val = Rect("btn", parent); val.sizeDelta = new Vector2(w, 30f); LayoutElement obj = ((Component)val).gameObject.AddComponent<LayoutElement>(); obj.preferredWidth = w; obj.preferredHeight = 30f; Img(val, new Color(0f, 0f, 0f, 0.45f), Style.Slot); Button obj2 = ((Component)val).gameObject.AddComponent<Button>(); ((UnityEvent)obj2.onClick).AddListener((UnityAction)delegate { onClick(); }); Txt(Place(Rect("t", (Transform)(object)val), Vector2.zero, Vector2.one, new Vector2(6f, 0f), new Vector2(-6f, 0f)), label, 16f, Style.Ink, (TextAlignmentOptions)514); return obj2; } private static void SetBtn(Button b, bool on) { //IL_0038: 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) ((Graphic)((Component)b).GetComponent<Image>()).color = (on ? new Color(0.55f, 0.4f, 0.15f, 0.8f) : new Color(0f, 0f, 0f, 0.45f)); } public static GameObject Create() { //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references)