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 MappingBeacons v1.0.4
plugins/ScoutingBeacons/ScoutingBeacons.dll
Decompiled 2 weeks 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.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using Splatform; 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.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: AssemblyCompany("SirCookie")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+804a17aa68036ec2ba0b6ebb671805886ce13caf")] [assembly: AssemblyProduct("ScoutingBeacons")] [assembly: AssemblyTitle("ScoutingBeacons")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.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; } } } namespace ScoutingBeacons { public class Beacon : MonoBehaviour { public struct Forecast { public int Ring; public int Cells; public double Seconds; public float Leftover; public bool Coast; public float NextCost; } private const string FuelKey = "sb_fuel"; private const string RingKey = "sb_ring"; private const string PaidKey = "sb_paid"; private const string ProgressKey = "sb_prog"; private const string LastKey = "sb_last"; private const string ActiveKey = "sb_active"; private const string CoastKey = "sb_coast"; private const float TickSeconds = 1f; private const string LitKey = "sb_lit"; private const string LitMessage = "The beacon is lit, hope remains."; private const string ChestButlerManualOnly = "psort_manual"; public static readonly List<Beacon> Instances = new List<Beacon>(); private ZNetView m_nview; private Container m_container; private BeaconTier m_tier; private float m_timer; private readonly List<Transform> m_wisps = new List<Transform>(); private const string KnownKey = "sb_known"; private byte[] m_known; private static readonly Color PastLimitColor = new Color(1f, 0.15f, 0.1f); private bool m_wispsRed; public bool JustLit { get; private set; } public BeaconTier Tier => m_tier ?? (m_tier = BeaconTiers.ForPiece(Utils.GetPrefabName(((Component)this).gameObject))); public Container Container => m_container; public Landmass Land => Landmass.For(((Component)this).transform.position); private ZDO Zdo { get { if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid()) { return null; } return m_nview.GetZDO(); } } public float Fuel { get { ZDO zdo = Zdo; if (zdo == null) { return 0f; } return zdo.GetFloat("sb_fuel", 0f); } } public int Ring { get { ZDO zdo = Zdo; if (zdo == null) { return 0; } return zdo.GetInt("sb_ring", 0); } } public bool Paid { get { ZDO zdo = Zdo; return ((zdo != null) ? zdo.GetInt("sb_paid", 0) : 0) == 1; } } public float Progress { get { ZDO zdo = Zdo; if (zdo == null) { return 0f; } return zdo.GetFloat("sb_prog", 0f); } } public bool Active { get { ZDO zdo = Zdo; return ((zdo != null) ? zdo.GetInt("sb_active", 0) : 0) == 1; } } public bool CoastReached { get { ZDO zdo = Zdo; return ((zdo != null) ? zdo.GetInt("sb_coast", 0) : 0) == 1; } } private void Awake() { m_nview = ((Component)this).GetComponent<ZNetView>(); m_container = ((Component)this).GetComponent<Container>(); Instances.Add(this); } private void OnDestroy() { Instances.Remove(this); } private void Update() { UpdateWisps(); if (Zdo != null && m_nview.IsOwner() && Tier != null) { m_timer += Time.deltaTime; if (!(m_timer < 1f)) { m_timer = 0f; Tick(); } } } private void Tick() { ZDO zdo = Zdo; if (Compat.ChestButlerInstalled && zdo.GetBool("psort_manual", false) != Settings.BlockAutoFeeding.Value) { zdo.Set("psort_manual", Settings.BlockAutoFeeding.Value); } double timeSeconds = ZNet.instance.GetTimeSeconds(); long num = zdo.GetLong("sb_last", 0L); zdo.Set("sb_last", (long)timeSeconds); if (num == 0L) { return; } double num2 = timeSeconds - (double)num; if (num2 <= 0.0) { return; } float num3 = Fuel; float num4 = Progress; int num5 = Ring; bool flag = Paid; bool flag2 = false; float squareMetresPerSecond = Tier.SquareMetresPerSecond; float num6 = Land.Width * Land.Width; for (int i = 0; i < 500; i++) { if (!Land.HasMoreAfter(num5)) { flag2 = true; break; } int num7 = num5 + 1; if (!flag) { float num8 = RingCost(num7); if (num3 < num8) { break; } num3 -= num8; flag = true; } double num9 = ((float)RingCells(num7) * num6 - num4) / squareMetresPerSecond; if (num2 < num9) { num4 += (float)(num2 * (double)squareMetresPerSecond); break; } num2 -= num9; num5 = num7; num4 = 0f; flag = false; } zdo.Set("sb_fuel", num3); zdo.Set("sb_ring", num5); zdo.Set("sb_paid", flag ? 1 : 0); zdo.Set("sb_prog", num4); zdo.Set("sb_coast", flag2 ? 1 : 0); zdo.Set("sb_active", (flag && !flag2) ? 1 : 0); } public bool IsKnown(int n) { if (m_known == null) { ZDO zdo = Zdo; m_known = ((zdo != null) ? zdo.GetByteArray("sb_known", (byte[])null) : null) ?? new byte[0]; } int num = n >> 3; if (n > 0 && num < m_known.Length) { return (m_known[num] & (1 << (n & 7))) != 0; } return false; } public float RingCost(int n) { if (!IsKnown(n)) { return Tier.RingCost(n); } return 0f; } public int RingCells(int n) { if (!IsKnown(n)) { return Land.CellsInRing(n); } return 0; } public void SnapshotKnownMap() { //IL_0081: Unknown result type (might be due to invalid IL or missing references) Minimap instance = Minimap.instance; if (!Object.op_Implicit((Object)(object)instance) || Zdo == null || Tier == null) { return; } int num = Tier.LimitRing * 2; byte[] array = new byte[num / 8 + 1]; int num2 = 0; for (int i = 1; i <= num && Land.HasMoreAfter(i - 1); i++) { bool flag = true; foreach (long item in Land.CellsOfRing(i)) { if (!instance.IsExplored(Land.CellCentre(item))) { flag = false; break; } } if (flag) { array[i >> 3] |= (byte)(1 << (i & 7)); num2++; } } Zdo.Set("sb_known", array); m_known = array; if (num2 > 0) { Logger.LogInfo((object)$"{Tier.DisplayName}: {num2} rings already on the builder's map, skipped"); } } public float OptimalExplored() { int limitRing = Tier.LimitRing; int num = 0; int num2 = 0; for (int i = 1; i <= limitRing; i++) { int num3 = Land.CellsInRing(i); num2 += num3; if (i <= Ring || IsKnown(i)) { num += num3; } } if (num2 != 0) { return (float)num / (float)num2; } return 1f; } public float FuelToFinishOptimal() { float num = 0f; int limitRing = Tier.LimitRing; for (int i = Ring + 1; i <= limitRing && Land.HasMoreAfter(i - 1); i++) { if (i != Ring + 1 || !Paid) { num += RingCost(i); } } return num; } public float FuelToLimit() { float num = 0f; for (int i = 1; i <= Tier.LimitRing; i++) { num += RingCost(i); } return num; } public float Feed(bool dropOthers) { //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: 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_00ce: Unknown result type (might be due to invalid IL or missing references) Inventory val = (Object.op_Implicit((Object)(object)m_container) ? m_container.GetInventory() : null); JustLit = false; if (val == null || Zdo == null) { return 0f; } if (!m_nview.IsOwner()) { m_nview.ClaimOwnership(); } float num = 0f; foreach (ItemData item in new List<ItemData>(val.GetAllItems())) { float num2 = Settings.FuelValue(item); if (num2 > 0f) { num += num2 * (float)item.m_stack; val.RemoveItem(item); } else if (dropOthers) { ItemDrop.DropItem(item, item.m_stack, ((Component)this).transform.position + ((Component)this).transform.forward * 1.5f + Vector3.up, Quaternion.identity); val.RemoveItem(item); } } if (num > 0f) { Zdo.Set("sb_fuel", Fuel + num); if (Zdo.GetLong("sb_last", 0L) == 0L) { Zdo.Set("sb_last", (long)ZNet.instance.GetTimeSeconds()); } m_timer = 1f; if (Zdo.GetInt("sb_lit", 0) == 0) { Zdo.Set("sb_lit", 1); JustLit = true; Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)2, "The beacon is lit, hope remains.", 0, (Sprite)null, false); } } } return num; } public float PendingFuel(out List<string> nonFuel) { nonFuel = new List<string>(); float num = 0f; Inventory val = (Object.op_Implicit((Object)(object)m_container) ? m_container.GetInventory() : null); if (val == null) { return 0f; } foreach (ItemData allItem in val.GetAllItems()) { float num2 = Settings.FuelValue(allItem); if (num2 > 0f) { num += num2 * (float)allItem.m_stack; } else { nonFuel.Add($"{allItem.m_stack} {Localization.instance.Localize(allItem.m_shared.m_name)}"); } } return num; } public Forecast Predict(float fuel) { Forecast result = new Forecast { Ring = Ring }; float num = Progress; float squareMetresPerSecond = Tier.SquareMetresPerSecond; float num2 = Land.Width * Land.Width; bool flag = Paid; for (int i = 0; i < 2000; i++) { if (!Land.HasMoreAfter(result.Ring)) { result.Coast = true; break; } int num3 = result.Ring + 1; float num4 = RingCost(num3); if (!flag) { if (fuel < num4) { result.NextCost = num4; break; } fuel -= num4; } int num5 = RingCells(num3); result.Seconds += ((float)num5 * num2 - num) / squareMetresPerSecond; result.Cells += num5; result.Ring = num3; num = 0f; flag = false; } result.Leftover = fuel; return result; } public int TransferMap() { //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_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) Minimap instance = Minimap.instance; if (!Object.op_Implicit((Object)(object)instance) || Tier == null) { return 0; } float width = Land.Width; float num = (float)Settings.CoastBuffer.Value * width; float num2 = width * 0.5f + num; float num3 = Mathf.Max(1f, Mathf.Min(width, instance.m_pixelSize) * 0.5f); HashSet<long> hashSet = new HashSet<long>(); int num6 = default(int); int num7 = default(int); foreach (long item in Land.CellsUpTo(Ring)) { Vector3 val = Land.CellCentre(item); for (float num4 = 0f - num2; num4 <= num2; num4 += num3) { for (float num5 = 0f - num2; num5 <= num2; num5 += num3) { instance.WorldToPixel(val + new Vector3(num4, 0f, num5), ref num6, ref num7); hashSet.Add(((long)num6 << 32) | (uint)num7); } } } int num8 = 0; foreach (long item2 in hashSet) { if (instance.Explore((int)(item2 >> 32), (int)item2)) { num8++; } } if (num8 > 0) { instance.m_fogTexture.Apply(); } return num8; } private void UpdateWisps() { //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) int num; int num2; if (Active) { num = (Object.op_Implicit((Object)(object)Plugin.WispTemplate) ? 1 : 0); if (num != 0 && Tier != null) { num2 = Tier.Wisps; goto IL_002e; } } else { num = 0; } num2 = 0; goto IL_002e; IL_002e: int num3 = num2; bool flag = num != 0 && Ring + 1 > Tier.LimitRing; if (flag != m_wispsRed) { m_wispsRed = flag; foreach (Transform wisp in m_wisps) { Object.Destroy((Object)(object)((Component)wisp).gameObject); } m_wisps.Clear(); } while (m_wisps.Count > num3) { Object.Destroy((Object)(object)((Component)m_wisps[m_wisps.Count - 1]).gameObject); m_wisps.RemoveAt(m_wisps.Count - 1); } while (m_wisps.Count < num3) { GameObject val = Object.Instantiate<GameObject>(Plugin.WispTemplate, ((Component)this).transform); if (flag) { Recolour(val, PastLimitColor); } val.SetActive(true); m_wisps.Add(val.transform); } float num4 = (flag ? (0.75f + 0.35f * Mathf.Sin(Time.time * 6f)) : 1f); for (int i = 0; i < m_wisps.Count; i++) { m_wisps[i].localScale = Plugin.WispTemplate.transform.localScale * num4; Light[] componentsInChildren = ((Component)m_wisps[i]).GetComponentsInChildren<Light>(); for (int j = 0; j < componentsInChildren.Length; j++) { componentsInChildren[j].intensity = 1.5f * num4; } float num5 = Time.time * 0.8f + (float)i * (float)Math.PI * 2f / (float)m_wisps.Count; m_wisps[i].position = ((Component)this).transform.position + new Vector3(Mathf.Cos(num5) * 1.4f, 2.2f + Mathf.Sin(Time.time * 1.7f + (float)i) * 0.25f, Mathf.Sin(num5) * 1.4f); } } private static void Recolour(GameObject wisp, Color color) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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_007f: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: 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) Light[] componentsInChildren = wisp.GetComponentsInChildren<Light>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].color = color; } ParticleSystem[] componentsInChildren2 = wisp.GetComponentsInChildren<ParticleSystem>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { MainModule main = componentsInChildren2[i].main; ((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(color); } Renderer[] componentsInChildren3 = wisp.GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { Material[] materials = componentsInChildren3[i].materials; foreach (Material val in materials) { if (val.HasProperty("_Color")) { val.color = color; } if (val.HasProperty("_TintColor")) { val.SetColor("_TintColor", color); } if (val.HasProperty("_EmissionColor")) { val.SetColor("_EmissionColor", color * 2f); } } } } public string GetHoverText(string vanilla) { string arg = (CoastReached ? "Coast reached" : (Active ? "Scouting" : "Needs fuel")); return vanilla + $"\n<size=80%>{arg} | ring {Ring} | fuel {Fuel:0.#}</size>"; } } public class BeaconPanel : MonoBehaviour { private class ButtonState { public RectTransform Rect; public Vector2 Pivot; public Vector2 Position; public Vector2 Size; public void Save() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: 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) //IL_001d: 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_002e: Unknown result type (might be due to invalid IL or missing references) Pivot = Rect.pivot; Position = Rect.anchoredPosition; Size = Rect.sizeDelta; } public void Restore() { //IL_0007: 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) //IL_0029: Unknown result type (might be due to invalid IL or missing references) Rect.pivot = Pivot; Rect.anchoredPosition = Position; Rect.sizeDelta = Size; } } private const float RefreshSeconds = 0.25f; private const float MarginX = 20f; private const float ButtonGap = 8f; private const float TitleGap = 16f; private const float SlotsGap = 10f; private const float TitleScale = 1.5f; private static BeaconPanel s_instance; private InventoryGui m_gui; private RectTransform m_root; private TMP_Text m_text; private float m_timer; private Button m_addFuelButton; private Button m_feedButton; private Beacon m_beacon; private bool m_saved; private Vector2 m_windowSize; private Vector2 m_gridPosition; private Vector2 m_titlePosition; private Vector2 m_titleSize; private float m_titleFont; private float m_titleMin; private float m_titleMax; private TextAlignmentOptions m_titleAlign; private bool m_titleAuto; private bool m_titleWrap; private ButtonState m_takeAll; private ButtonState m_stackAll; private const string Gold = "#FFD15A"; private const string Grey = "#BBBBBB"; private const string Red = "#FF6B5A"; private const string Amber = "#FFB347"; private const string Blue = "#7FC8FF"; public static void Ensure(InventoryGui gui) { //IL_0032: 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) if (!Object.op_Implicit((Object)(object)s_instance) && Object.op_Implicit((Object)(object)gui.m_container)) { GameObject val = new GameObject("ScoutingBeacons_Panel", new Type[1] { typeof(RectTransform) }); val.transform.SetParent((Transform)(object)gui.m_container, false); s_instance = val.AddComponent<BeaconPanel>(); s_instance.Build(gui); } } private void Build(InventoryGui gui) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0085: 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_00bd: 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_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: 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_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0150: 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_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Expected O, but got Unknown //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Expected O, but got Unknown m_gui = gui; m_root = (RectTransform)((Component)this).transform; RectTransform root = m_root; RectTransform root2 = m_root; Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(1f, 1f); root2.anchorMax = val; root.anchorMin = val; m_root.pivot = new Vector2(0f, 1f); m_root.anchoredPosition = new Vector2(12f, 0f); m_root.sizeDelta = new Vector2(430f, 340f); Image component = ((Component)gui.m_container).GetComponent<Image>(); Image val2 = ((Component)this).gameObject.AddComponent<Image>(); if (Object.op_Implicit((Object)(object)component)) { val2.sprite = component.sprite; val2.type = component.type; ((Graphic)val2).material = ((Graphic)component).material; ((Graphic)val2).color = ((Graphic)component).color; } else { ((Graphic)val2).color = new Color(0f, 0f, 0f, 0.75f); } GameObject val3 = Object.Instantiate<GameObject>(((Component)gui.m_containerName).gameObject, ((Component)this).transform, false); ((Object)val3).name = "text"; m_text = val3.GetComponent<TMP_Text>(); RectTransform val4 = (RectTransform)val3.transform; val4.anchorMin = Vector2.zero; val4.anchorMax = Vector2.one; val4.pivot = new Vector2(0.5f, 0.5f); val4.offsetMin = new Vector2(18f, 14f); val4.offsetMax = new Vector2(-18f, -14f); m_text.alignment = (TextAlignmentOptions)257; m_text.enableWordWrapping = true; m_text.richText = true; m_text.fontSize = 16f; m_text.enableAutoSizing = false; ((Graphic)m_text).color = Color.white; m_addFuelButton = CopyButton(gui, "Add all fuel", new UnityAction(OnAddAllFuel)); m_feedButton = CopyButton(gui, "Fuel the beacon", new UnityAction(OnFeed)); ((Component)this).gameObject.SetActive(false); } private static Button CopyButton(InventoryGui gui, string label, UnityAction onClick) { //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown if (!Object.op_Implicit((Object)(object)gui.m_takeAllButton)) { return null; } GameObject gameObject = ((Component)gui.m_takeAllButton).gameObject; GameObject val = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent, false); ((Object)val).name = "ScoutingBeacons_" + label.Replace(" ", ""); UIGamePad[] componentsInChildren = val.GetComponentsInChildren<UIGamePad>(true); foreach (UIGamePad val2 in componentsInChildren) { if (Object.op_Implicit((Object)(object)val2.m_hint) && val2.m_hint.transform.IsChildOf(val.transform)) { Object.Destroy((Object)(object)val2.m_hint); } Object.Destroy((Object)(object)val2); } TMP_Text componentInChildren = val.GetComponentInChildren<TMP_Text>(true); if (Object.op_Implicit((Object)(object)componentInChildren)) { componentInChildren.text = label; } Button component = val.GetComponent<Button>(); component.onClick = new ButtonClickedEvent(); ((UnityEvent)component.onClick).AddListener(onClick); val.SetActive(false); return component; } private void OnAddAllFuel() { Player localPlayer = Player.m_localPlayer; Inventory val = ((Object.op_Implicit((Object)(object)m_beacon) && Object.op_Implicit((Object)(object)m_beacon.Container)) ? m_beacon.Container.GetInventory() : null); if (!Object.op_Implicit((Object)(object)localPlayer) || val == null) { return; } Inventory inventory = ((Humanoid)localPlayer).GetInventory(); int num = 0; foreach (ItemData item in new List<ItemData>(inventory.GetAllItems())) { if (!item.m_equipped && !(Settings.FuelValue(item) <= 0f)) { int stack = item.m_stack; val.MoveItemToThis(inventory, item); num += stack - (inventory.ContainsItem(item) ? item.m_stack : 0); } } if (num == 0) { ((Character)localPlayer).Message((MessageType)2, "No fuel in your inventory", 0, (Sprite)null, false); } m_timer = 0f; } private void OnFeed() { if (Object.op_Implicit((Object)(object)m_beacon)) { float num = m_beacon.Feed(dropOthers: false); if (num > 0f && Object.op_Implicit((Object)(object)Player.m_localPlayer) && !m_beacon.JustLit) { ((Character)Player.m_localPlayer).Message((MessageType)2, $"+{num:0.#} fuel", 0, (Sprite)null, false); } m_timer = 0f; } } private void Layout() { //IL_0031: 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_0087: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: 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_0205: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0214: 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_0111: 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_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: 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_0157: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_0302: Unknown result type (might be due to invalid IL or missing references) //IL_0343: Unknown result type (might be due to invalid IL or missing references) //IL_034f: Unknown result type (might be due to invalid IL or missing references) //IL_035b: Unknown result type (might be due to invalid IL or missing references) //IL_0360: Unknown result type (might be due to invalid IL or missing references) //IL_036b: Unknown result type (might be due to invalid IL or missing references) //IL_0370: Unknown result type (might be due to invalid IL or missing references) //IL_0399: Unknown result type (might be due to invalid IL or missing references) //IL_03ab: Unknown result type (might be due to invalid IL or missing references) //IL_03c6: Unknown result type (might be due to invalid IL or missing references) //IL_03cf: Unknown result type (might be due to invalid IL or missing references) //IL_03db: Expected O, but got Unknown //IL_03e7: Unknown result type (might be due to invalid IL or missing references) //IL_03f0: Unknown result type (might be due to invalid IL or missing references) //IL_03ff: Expected O, but got Unknown //IL_041d: Unknown result type (might be due to invalid IL or missing references) //IL_042b: Unknown result type (might be due to invalid IL or missing references) //IL_0430: Unknown result type (might be due to invalid IL or missing references) //IL_0434: Unknown result type (might be due to invalid IL or missing references) //IL_0439: Unknown result type (might be due to invalid IL or missing references) //IL_043e: Unknown result type (might be due to invalid IL or missing references) //IL_0443: Unknown result type (might be due to invalid IL or missing references) //IL_0448: Unknown result type (might be due to invalid IL or missing references) //IL_0452: Unknown result type (might be due to invalid IL or missing references) //IL_0467: Unknown result type (might be due to invalid IL or missing references) //IL_046c: Unknown result type (might be due to invalid IL or missing references) //IL_0471: Unknown result type (might be due to invalid IL or missing references) //IL_0476: Unknown result type (might be due to invalid IL or missing references) //IL_047b: Unknown result type (might be due to invalid IL or missing references) //IL_047d: Unknown result type (might be due to invalid IL or missing references) //IL_047f: Unknown result type (might be due to invalid IL or missing references) //IL_0484: Unknown result type (might be due to invalid IL or missing references) RectTransform container = m_gui.m_container; RectTransform val = ((!Object.op_Implicit((Object)(object)m_gui.m_takeAllButton)) ? ((RectTransform)null) : ((RectTransform)((Component)m_gui.m_takeAllButton).transform)); RectTransform val2 = ((!Object.op_Implicit((Object)(object)m_gui.m_stackAllButton)) ? ((RectTransform)null) : ((RectTransform)((Component)m_gui.m_stackAllButton).transform)); RectTransform val3 = ((!Object.op_Implicit((Object)(object)m_gui.m_containerGrid)) ? ((RectTransform)null) : ((RectTransform)((Component)m_gui.m_containerGrid).transform)); RectTransform val4 = (Object.op_Implicit((Object)(object)m_gui.m_containerName) ? m_gui.m_containerName.rectTransform : null); if (Object.op_Implicit((Object)(object)container) && Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)val4) && Object.op_Implicit((Object)(object)m_addFuelButton) && Object.op_Implicit((Object)(object)m_feedButton)) { if (!m_saved) { m_windowSize = container.sizeDelta; m_gridPosition = val3.anchoredPosition; m_titlePosition = val4.anchoredPosition; TMP_Text containerName = m_gui.m_containerName; m_titleSize = val4.sizeDelta; m_titleFont = containerName.fontSize; m_titleAlign = containerName.alignment; m_titleAuto = containerName.enableAutoSizing; m_titleMin = containerName.fontSizeMin; m_titleMax = containerName.fontSizeMax; m_titleWrap = containerName.enableWordWrapping; m_takeAll = new ButtonState { Rect = val }; m_stackAll = new ButtonState { Rect = val2 }; m_takeAll.Save(); m_stackAll.Save(); m_saved = true; } m_takeAll.Restore(); container.sizeDelta = m_windowSize; val3.anchoredPosition = m_gridPosition; Rect rect = val.rect; Vector3 val5 = ((Transform)container).InverseTransformPoint(((Transform)val).TransformPoint(Vector2.op_Implicit(((Rect)(ref rect)).center))); RectTransform val6 = (Object.op_Implicit((Object)(object)m_gui.m_containerGrid.m_gridRoot) ? m_gui.m_containerGrid.m_gridRoot : val3); rect = val6.rect; float y = ((Transform)container).InverseTransformPoint(((Transform)val6).TransformPoint(new Vector3(0f, ((Rect)(ref rect)).yMax, 0f))).y; float x = m_takeAll.Size.x; float y2 = m_takeAll.Size.y; float num = y2 + 8f; TMP_Text containerName2 = m_gui.m_containerName; containerName2.enableAutoSizing = false; containerName2.enableWordWrapping = false; containerName2.fontSize = m_titleFont * 1.5f; containerName2.alignment = (TextAlignmentOptions)514; float x2 = containerName2.GetPreferredValues(containerName2.text).x; float num2 = 40f + 2f * x + 32f + x2; float num3 = val5.y - num - y2 / 2f - 10f; float num4 = y - num3; container.sizeDelta = new Vector2(Mathf.Max(m_windowSize.x, num2), m_windowSize.y + num4); val3.anchoredPosition = m_gridPosition - new Vector2(0f, num4); Rect rect2 = container.rect; float num5 = ((Rect)(ref rect2)).xMin + 20f; float num6 = ((Rect)(ref rect2)).xMax - 20f - x; Place(val, x, num5, val5.y); Place(val2, x, num5, val5.y - num); Place((RectTransform)((Component)m_addFuelButton).transform, x, num6, val5.y); Place((RectTransform)((Component)m_feedButton).transform, x, num6, val5.y - num); val4.sizeDelta = new Vector2(num6 - (num5 + x) - 32f, y2 * 2f + 8f); rect = val4.rect; Vector3 val7 = ((Transform)val4).TransformPoint(Vector2.op_Implicit(((Rect)(ref rect)).center)); Vector3 val8 = ((Transform)container).TransformPoint(new Vector3(((Rect)(ref rect2)).center.x, val5.y - num / 2f, 0f)); ((Transform)val4).position = ((Transform)val4).position + (val8 - val7); ((Component)m_addFuelButton).gameObject.SetActive(true); ((Component)m_feedButton).gameObject.SetActive(true); } } private void Place(RectTransform button, float width, float x, float y) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_004a: Unknown result type (might be due to invalid IL or missing references) button.sizeDelta = new Vector2(width, m_takeAll.Size.y); button.pivot = new Vector2(0f, 0.5f); ((Transform)button).position = ((Transform)m_gui.m_container).TransformPoint(new Vector3(x, y, 0f)); } private void RestoreLayout() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: 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_007d: 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) if (m_saved) { m_gui.m_container.sizeDelta = m_windowSize; if (Object.op_Implicit((Object)(object)m_gui.m_containerGrid)) { ((RectTransform)((Component)m_gui.m_containerGrid).transform).anchoredPosition = m_gridPosition; } TMP_Text containerName = m_gui.m_containerName; if (Object.op_Implicit((Object)(object)containerName)) { containerName.rectTransform.sizeDelta = m_titleSize; containerName.rectTransform.anchoredPosition = m_titlePosition; containerName.alignment = m_titleAlign; containerName.enableAutoSizing = m_titleAuto; containerName.fontSizeMin = m_titleMin; containerName.fontSizeMax = m_titleMax; containerName.fontSize = m_titleFont; containerName.enableWordWrapping = m_titleWrap; } m_takeAll.Restore(); m_stackAll.Restore(); if (Object.op_Implicit((Object)(object)m_addFuelButton)) { ((Component)m_addFuelButton).gameObject.SetActive(false); } if (Object.op_Implicit((Object)(object)m_feedButton)) { ((Component)m_feedButton).gameObject.SetActive(false); } m_saved = false; } } public static Beacon OpenBeacon(InventoryGui gui) { Container val = (Object.op_Implicit((Object)(object)gui) ? gui.m_currentContainer : null); if (!Object.op_Implicit((Object)(object)val)) { return null; } return ((Component)val).GetComponent<Beacon>(); } public static void Refresh(InventoryGui gui) { if (Object.op_Implicit((Object)(object)s_instance)) { Beacon beacon = (gui.IsContainerOpen() ? OpenBeacon(gui) : null); s_instance.Show(beacon); } } private void Show(Beacon beacon) { bool flag = Object.op_Implicit((Object)(object)beacon) && beacon.Tier != null; m_beacon = (flag ? beacon : null); if (((Component)this).gameObject.activeSelf != flag) { ((Component)this).gameObject.SetActive(flag); } if (!flag) { RestoreLayout(); return; } Layout(); m_timer -= Time.unscaledDeltaTime; if (!(m_timer > 0f)) { m_timer = 0.25f; m_text.text = Describe(beacon); if (Object.op_Implicit((Object)(object)m_feedButton)) { ((Selectable)m_feedButton).interactable = beacon.PendingFuel(out var _) > 0f; } } } private static string Clock(double seconds) { long num = (long)Math.Ceiling(seconds); return $"{num / 60:00}:{num % 60:00}"; } private static string Describe(Beacon b) { BeaconTier tier = b.Tier; float width = b.Land.Width; int limitRing = tier.LimitRing; List<string> nonFuel; float num = b.PendingFuel(out nonFuel); Beacon.Forecast forecast = b.Predict(b.Fuel); Beacon.Forecast forecast2 = b.Predict(b.Fuel + num); int num2 = BeaconTiers.All.IndexOf(tier) + 1; string text = (b.CoastReached ? "<color=#7FC8FF>coast reached</color>" : (b.Active ? "<color=#7CFC7C>exploring</color>" : "<color=#FF6B5A>waiting for fuel</color>")); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("<color=#FFD15A><b>" + tier.DisplayName + "</b></color> · " + text); stringBuilder.AppendLine(string.Format("<color={0}>Map beacon tier {1} · optimal range {2:0.##} km² · ", "#BBBBBB", num2, tier.LimitKm2.Value) + $"fuel ratio {tier.Efficiency.Value:0.##}</color>"); stringBuilder.AppendLine(); stringBuilder.AppendLine((num > 0f) ? $"Available Fuel: <b>{b.Fuel:0.#}</b> (+{num:0.#})" : $"Available Fuel: <b>{b.Fuel:0.#}</b>"); float num3 = b.FuelToFinishOptimal() - b.Fuel; if (b.Ring >= limitRing) { stringBuilder.AppendLine("Remaining fuel for optimal range: <color=#FFB347>Optimal range has been crossed</color>"); } else if (num3 <= 0f) { stringBuilder.AppendLine("Remaining fuel for optimal range: " + string.Format("<color={0}>Range will be exceeded by {1:0} stored fuel</color>", "#FFB347", 0f - num3)); } else if (num <= 0f) { stringBuilder.AppendLine("Remaining fuel for optimal range: " + $"<b>{num3:0}</b>"); } else if (num < num3) { stringBuilder.AppendLine("Remaining fuel for optimal range: " + $"<b>{num3 - num:0}</b> ({num:0} fuel present in inventory)"); } else { stringBuilder.AppendLine("Remaining fuel for optimal range: " + string.Format("<color={0}>Range will be exceeded by {1:0} fuel in inventory</color>", "#FFB347", num - num3)); } if (forecast.Seconds > 0.0) { stringBuilder.AppendLine(forecast.Coast ? ("Coast reached in: <b>" + Clock(forecast.Seconds) + "</b>") : ("Fuel depletion countdown: <b>" + Clock(forecast.Seconds) + "</b>")); } stringBuilder.AppendLine($"Current range from beacon: <b>{(float)b.Ring * width:0} m</b>"); stringBuilder.AppendLine($"Optimal zone progress: <b>{b.OptimalExplored() * 100f:0}%</b>"); float num4 = (float)limitRing * width; if (b.Ring > limitRing) { stringBuilder.AppendLine(string.Format("<color={0}>Limit overreach: {1:0} m past {2:0} m, ", "#FF6B5A", (float)b.Ring * width - num4, num4) + $"each ring costs {tier.RingCost(b.Ring + 1) / tier.RingCost(limitRing):0.#}× more</color>"); } else if (forecast2.Ring > limitRing) { stringBuilder.AppendLine(string.Format("<color={0}>Limit overreach: fuel carries past {1:0} m, costs rise steeply</color>", "#FFB347", num4)); } if (b.CoastReached) { stringBuilder.AppendLine("<color=#FF6B5A>Island fully explored: ocean on every side, no further exploration " + $"possible. More fuel won't help; {b.Fuel:0.#} fuel stays stored.</color>"); } else if (forecast2.Coast) { stringBuilder.AppendLine("<color=#7FC8FF>This fuel explores the whole island (ocean on every side at " + $"{(float)forecast2.Ring * width:0} m); {forecast2.Leftover:0.#} fuel will be left over.</color>"); } if (nonFuel.Count > 0) { stringBuilder.AppendLine(Settings.ConvertOnClose.Value ? ("<color=#FF6B5A>" + string.Join(", ", nonFuel) + " will be DROPPED (not fuel)</color>") : ("<color=#FFB347>" + string.Join(", ", nonFuel) + ": not fuel, stays in the beacon</color>")); } return stringBuilder.ToString(); } } public static class Compat { private static readonly string[][] AzuMods = new string[2][] { new string[3] { "Azumatt.AzuAutoStore", "AzuAutoStore.Util.Boxes", "AzuAutoStore" }, new string[3] { "Azumatt.AzuCraftyBoxes", "AzuCraftyBoxes.Util.Functions.Boxes", "AzuCraftyBoxes" } }; public const string OttoFuelGuid = "potto007.OttoFuel"; public const string ServersideQoLGuid = "ArgusMagnus.ServersideQoL"; public static bool ChestButlerInstalled => Chainloader.PluginInfos.ContainsKey("eksolutions.chestbutler"); private static bool IsBeacon(string prefabName) { if (prefabName != null) { return BeaconTiers.ForPiece(Utils.GetPrefabName(prefabName)) != null; } return false; } public static void PatchAzumatt(Harmony harmony) { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown string[][] azuMods = AzuMods; foreach (string[] array in azuMods) { if (!Chainloader.PluginInfos.ContainsKey(array[0])) { continue; } try { Type type = AccessTools.TypeByName(array[1]); MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "AddContainer", new Type[1] { typeof(Container) }, (Type[])null) : null); if (methodInfo == null) { Logger.LogWarning((object)(array[2] + " found but not the expected code; it may still use beacons")); continue; } harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Compat), "NoAzuBeacons", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Logger.LogInfo((object)(array[2] + ": beacons skipped while \"Block automatic feeding\" is on")); } catch (Exception ex) { Logger.LogWarning((object)("Couldn't adjust " + array[2] + ": " + ex.Message)); } } } private static bool NoAzuBeacons(Container __0) { if (Settings.BlockAutoFeeding.Value && Object.op_Implicit((Object)(object)__0)) { return !IsBeacon(((Object)((Component)__0).gameObject).name); } return true; } public static void PatchOttoFuel(Harmony harmony) { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown if (!Chainloader.PluginInfos.ContainsKey("potto007.OttoFuel")) { return; } try { Type type = AccessTools.TypeByName("OttoFuel.TastyUtils"); MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "GetNearbyContainers", (Type[])null, (Type[])null) : null); if (methodInfo == null || methodInfo.ReturnType != typeof(List<Container>)) { Logger.LogWarning((object)"OttoFuel found but not the expected code; it may take fuel out of beacons"); return; } harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Compat), "NoOttoFuelFromBeacons", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Logger.LogInfo((object)"OttoFuel: beacons skipped while \"Block automatic feeding\" is on"); } catch (Exception ex) { Logger.LogWarning((object)("Couldn't adjust OttoFuel: " + ex.Message)); } } private static void NoOttoFuelFromBeacons(List<Container> __result) { if (__result != null && Settings.BlockAutoFeeding.Value) { __result.RemoveAll((Container c) => Object.op_Implicit((Object)(object)c) && IsBeacon(((Object)((Component)c).gameObject).name)); } } public static void PatchServersideQoL(Harmony harmony) { //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Expected O, but got Unknown if (!Chainloader.PluginInfos.ContainsKey("ArgusMagnus.ServersideQoL")) { return; } try { Type type = AccessTools.TypeByName("ServersideQoL.Processors.ContainerRegistryProcessor"); Type type2 = AccessTools.TypeByName("ServersideQoL.Processor"); MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "GetStateCore", (Type[])null, (Type[])null) : null); MethodInfo methodInfo2 = ((type2 != null) ? AccessTools.Method(type2, "InitializePrefabInfoInternal", (Type[])null, (Type[])null) : null); if (methodInfo == null || methodInfo2 == null) { Logger.LogWarning((object)"ServersideQoL found but not the expected code; AutoStore may store into beacons"); return; } harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Compat), "NoAutoStoreIntoBeacons", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(Compat), "NoAutoSortOfBeacons", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Logger.LogInfo((object)"ServersideQoL: beacons excluded from AutoStore, AutoProcess and TameAssist while \"Block automatic feeding\" is on"); } catch (Exception ex) { Logger.LogWarning((object)("Couldn't adjust ServersideQoL: " + ex.Message)); } } private static void NoAutoStoreIntoBeacons(Container container, object __result) { if (__result != null && Object.op_Implicit((Object)(object)container) && Settings.BlockAutoFeeding.Value && IsBeacon(((Object)((Component)container).gameObject).name)) { SetRangeZero(__result, "AutoStorePickupRange"); SetRangeZero(__result, "AutoProcessFeedRange"); SetRangeZero(__result, "TameAssistFeedRange"); } } private static void SetRangeZero(object state, string name) { PropertyInfo propertyInfo = AccessTools.Property(state.GetType(), name); if (!(propertyInfo == null) && propertyInfo.CanWrite && !object.Equals(propertyInfo.GetValue(state), 0f)) { propertyInfo.SetValue(state, (propertyInfo.PropertyType == typeof(float)) ? ((object)0f) : ((object)0f)); } } private static bool NoAutoSortOfBeacons(object __instance, object prefabInfo, ref bool __result) { if (!Settings.BlockAutoFeeding.Value || __instance == null || __instance.GetType().FullName != "ServersideQoL.AutoStore.ContainerProcessor") { return true; } if (!IsBeacon(Traverse.Create(prefabInfo).Property("PrefabName", (object[])null).GetValue<string>())) { return true; } __result = false; return false; } } public class Landmass { private static readonly Dictionary<string, Landmass> s_cache = new Dictionary<string, Landmass>(); public readonly Vector3 Origin; public readonly float Width; private readonly HashSet<long> m_seen = new HashSet<long>(); private readonly SortedDictionary<int, List<long>> m_pending = new SortedDictionary<int, List<long>>(); private readonly List<List<long>> m_rings = new List<List<long>>(); private readonly Dictionary<long, int> m_ringOf = new Dictionary<long, int>(); private int m_builtTo = -1; public static Landmass For(Vector3 origin) { //IL_0010: 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_0051: Unknown result type (might be due to invalid IL or missing references) float value = Settings.RingWidth.Value; string key = $"{Mathf.RoundToInt(origin.x)}_{Mathf.RoundToInt(origin.z)}_{value}"; if (!s_cache.TryGetValue(key, out var value2)) { value2 = (s_cache[key] = new Landmass(origin, value)); } return value2; } private Landmass(Vector3 origin, float width) { //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) Origin = origin; Width = width; long num = Key(0, 0); m_seen.Add(num); m_rings.Add(new List<long> { num }); m_ringOf[num] = 0; m_builtTo = 0; Expand(0, 0); } private static long Key(int i, int j) { return ((long)i << 32) | (uint)j; } private static int I(long key) { return (int)(key >> 32); } private static int J(long key) { return (int)key; } public Vector3 CellCentre(long key) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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) return Origin + new Vector3((float)I(key) * Width, 0f, (float)J(key) * Width); } private int RingOf(int i, int j) { return Mathf.RoundToInt(Mathf.Sqrt((float)(i * i + j * j))); } private bool IsLand(int i, int j) { //IL_0001: 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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Invalid comparison between Unknown and I4 Vector3 val = Origin + new Vector3((float)i * Width, 0f, (float)j * Width); if (WorldGenerator.instance != null) { return (int)WorldGenerator.instance.GetBiome(val) != 256; } return true; } private void Expand(int i, int j) { for (int k = -1; k <= 1; k++) { for (int l = -1; l <= 1; l++) { if (k == 0 && l == 0) { continue; } long item = Key(i + k, j + l); if (m_seen.Add(item)) { int key = RingOf(i + k, j + l); if (!m_pending.TryGetValue(key, out var value)) { value = (m_pending[key] = new List<long>()); } value.Add(item); } } } } public void Build(int n) { while (m_builtTo < n) { int num = m_builtTo + 1; while (m_rings.Count <= num) { m_rings.Add(new List<long>()); } List<long> value; while (m_pending.TryGetValue(num, out value)) { m_pending.Remove(num); foreach (long item in value) { if (IsLand(I(item), J(item))) { m_rings[num].Add(item); m_ringOf[item] = num; Expand(I(item), J(item)); } } } List<int> list = new List<int>(); foreach (KeyValuePair<int, List<long>> item2 in m_pending) { if (item2.Key < num) { list.Add(item2.Key); continue; } break; } foreach (int item3 in list) { List<long> list2 = m_pending[item3]; m_pending.Remove(item3); foreach (long item4 in list2) { if (IsLand(I(item4), J(item4))) { m_rings[num].Add(item4); m_ringOf[item4] = num; Expand(I(item4), J(item4)); } } } m_builtTo = num; } } public int CellsInRing(int n) { Build(n); if (n >= m_rings.Count) { return 0; } return m_rings[n].Count; } public bool HasMoreAfter(int n) { Build(n + 1); if (CellsInRing(n + 1) > 0) { return true; } foreach (KeyValuePair<int, List<long>> item in m_pending) { if (item.Key > n + 1 && item.Value.Count > 0) { return true; } } return false; } public bool Scouted(Vector3 p, int n) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) Build(n); int num = Mathf.RoundToInt((p.x - Origin.x) / Width); int num2 = Mathf.RoundToInt((p.z - Origin.z) / Width); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (m_ringOf.TryGetValue(Key(num + i, num2 + j), out var value) && value <= n) { return true; } } } return false; } public IEnumerable<long> CellsOfRing(int n) { Build(n); if (n >= m_rings.Count) { return new List<long>(); } return m_rings[n]; } public IEnumerable<long> CellsUpTo(int n) { Build(n); for (int r = 0; r <= n && r < m_rings.Count; r++) { foreach (long item in m_rings[r]) { yield return item; } } } } public static class Markers { private const string RequestRpc = "ScoutingBeacons_RequestMarkers"; private const string ReplyRpc = "ScoutingBeacons_Markers"; private static readonly HashSet<string> s_unmatchedLogged = new HashSet<string>(); private static Beacon s_waiting; private static bool s_typesLogged; private static readonly List<ZDO> s_zdos = new List<ZDO>(); public const string PredictedSuffix = ""; private const float SameOreDistance = 24f; private const string GivenKey = "ScoutingBeacons_pins"; private static Player s_givenFor; private static readonly List<KeyValuePair<string, Vector3>> s_given = new List<KeyValuePair<string, Vector3>>(); public static void Register() { if (ZRoutedRpc.instance == null) { return; } ZRoutedRpc.instance.Register<ZPackage>("ScoutingBeacons_RequestMarkers", (Action<long, ZPackage>)OnRequest); ZRoutedRpc.instance.Register<ZPackage>("ScoutingBeacons_Markers", (Action<long, ZPackage>)OnReply); if (!Object.op_Implicit((Object)(object)ZNetScene.instance)) { return; } foreach (string key in Settings.OreMarkers.Keys) { if (!Object.op_Implicit((Object)(object)ZNetScene.instance.GetPrefab(key))) { Logger.LogWarning((object)("Ore marker '" + key + "' doesn't exist in this game, ignored")); } } } private static void LogLocationTypes() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) if (s_typesLogged || !Object.op_Implicit((Object)(object)ZoneSystem.instance)) { return; } s_typesLogged = true; SortedSet<string> sortedSet = new SortedSet<string>(); foreach (LocationInstance value in ZoneSystem.instance.m_locationInstances.Values) { string text = Name(value); if (text.Length > 0 && Settings.LocationLabel(text) == null && !Settings.IsKnownPoi(text) && Settings.TraderFor(text) == null && Settings.OreLocationLabel(text) == null) { sortedSet.Add(text); } } Logger.LogInfo((object)string.Format("Location types without a marker ({0}): {1}", sortedSet.Count, string.Join(", ", sortedSet))); } private static string Name(LocationInstance instance) { //IL_0000: 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) return instance.m_location?.m_prefabName ?? instance.m_location?.m_name ?? ""; } public static void Request(Beacon beacon) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) BeaconTier tier = beacon.Tier; if (tier != null && ZRoutedRpc.instance != null) { bool value = tier.MarkLocations.Value; bool value2 = tier.MarkOres.Value; if (value || value2) { s_waiting = beacon; ZPackage val = new ZPackage(); val.Write(((Component)beacon).transform.position); val.Write((float)(beacon.Ring + 2) * beacon.Land.Width); val.Write(value); val.Write(value2); ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "ScoutingBeacons_RequestMarkers", new object[1] { val }); } } } private static void OnRequest(long sender, ZPackage pkg) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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_0063: Expected O, but got Unknown //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsServer()) { return; } LogLocationTypes(); Vector3 centre = pkg.ReadVector3(); float radius = pkg.ReadSingle(); bool num = pkg.ReadBool(); bool flag = pkg.ReadBool(); List<KeyValuePair<string, Vector3>> list = new List<KeyValuePair<string, Vector3>>(); if (num) { FindLocations(centre, radius, list); } if (flag) { FindOres(centre, radius, list); FindOreLocations(centre, radius, list); } ZPackage val = new ZPackage(); val.Write(list.Count); foreach (KeyValuePair<string, Vector3> item in list) { val.Write(item.Key); val.Write(item.Value); } ZRoutedRpc.instance.InvokeRoutedRPC(sender, "ScoutingBeacons_Markers", new object[1] { val }); } private static bool Near(Vector3 a, Vector3 b, float radius) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) float num = a.x - b.x; float num2 = a.z - b.z; return num * num + num2 * num2 <= radius * radius; } private static void FindLocations(Vector3 centre, float radius, List<KeyValuePair<string, Vector3>> found) { //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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_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_008a: 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_009d: 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) //IL_012c: 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_0109: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: 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_00e4: Unknown result type (might be due to invalid IL or missing references) ZoneSystem instance = ZoneSystem.instance; if (!Object.op_Implicit((Object)(object)instance)) { return; } HashSet<Settings.Trader> hashSet = new HashSet<Settings.Trader>(); foreach (LocationInstance value in instance.m_locationInstances.Values) { Settings.Trader trader = Settings.TraderFor(Name(value)); if (trader != null && value.m_placed) { hashSet.Add(trader); } } foreach (LocationInstance value2 in instance.m_locationInstances.Values) { if (!Near(value2.m_position, centre, radius)) { continue; } string text = Name(value2); Settings.Trader trader2 = Settings.TraderFor(text); if (trader2 != null) { if (!trader2.Enabled.Value) { continue; } if (hashSet.Contains(trader2)) { if (value2.m_placed) { found.Add(new KeyValuePair<string, Vector3>(trader2.Label, value2.m_position)); } } else { found.Add(new KeyValuePair<string, Vector3>(trader2.Label + " (possible)", value2.m_position)); } } else { string text2 = Settings.LocationLabel(text); if (text2 != null) { found.Add(new KeyValuePair<string, Vector3>(text2, value2.m_position)); } else if (Settings.OreLocationLabel(text) == null && s_unmatchedLogged.Add(text)) { Logger.LogInfo((object)("Location '" + text + "' isn't marked (add it to 07 - Locations / Extra locations to pin it)")); } } } } private static void FindOreLocations(Vector3 centre, float radius, List<KeyValuePair<string, Vector3>> found) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) ZoneSystem instance = ZoneSystem.instance; if (!Object.op_Implicit((Object)(object)instance)) { return; } foreach (LocationInstance value in instance.m_locationInstances.Values) { if (Near(value.m_position, centre, radius)) { string text = Settings.OreLocationLabel(Name(value)); if (text != null) { found.Add(new KeyValuePair<string, Vector3>(text, value.m_position)); } } } } private static void FindOres(Vector3 centre, float radius, List<KeyValuePair<string, Vector3>> found) { //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) if (ZDOMan.instance == null) { return; } foreach (KeyValuePair<string, string> oreMarker in Settings.OreMarkers) { s_zdos.Clear(); int num = 0; while (!ZDOMan.instance.GetAllZDOsWithPrefabIterative(oreMarker.Key, s_zdos, ref num)) { } foreach (ZDO s_zdo in s_zdos) { if (Near(s_zdo.GetPosition(), centre, radius)) { found.Add(new KeyValuePair<string, Vector3>(oreMarker.Value, s_zdo.GetPosition())); } } } s_zdos.Clear(); if (Settings.PredictOres.Value) { PredictOres(centre, radius, found); } } private static void PredictOres(Vector3 centre, float radius, List<KeyValuePair<string, Vector3>> found) { //IL_0015: 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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_002d: 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_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_0045: 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_0052: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: 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) ZoneSystem instance = ZoneSystem.instance; if (!Object.op_Implicit((Object)(object)instance)) { return; } List<KeyValuePair<string, Vector3>> list = new List<KeyValuePair<string, Vector3>>(); Vector2s zone = ZoneSystem.GetZone(centre - new Vector3(radius, 0f, radius)); Vector2s zone2 = ZoneSystem.GetZone(centre + new Vector3(radius, 0f, radius)); Vector2s val = default(Vector2s); for (int i = zone.x; i <= zone2.x; i++) { for (int j = zone.y; j <= zone2.y; j++) { ((Vector2s)(ref val))..ctor(i, j); if (instance.IsZoneGenerated(val)) { continue; } list.Clear(); OrePredictor.Predict(val, Settings.OreMarkers, list); foreach (KeyValuePair<string, Vector3> item in list) { if (Near(item.Value, centre, radius)) { found.Add(new KeyValuePair<string, Vector3>(item.Key ?? "", item.Value)); } } } } } private static void OnReply(long sender, ZPackage pkg) { //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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_010f: 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_012b: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_0251: 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) Beacon beacon = s_waiting; Minimap instance = Minimap.instance; if (!Object.op_Implicit((Object)(object)beacon) || !Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)Player.m_localPlayer)) { return; } int num = pkg.ReadInt(); List<KeyValuePair<string, Vector3>> list = new List<KeyValuePair<string, Vector3>>(); int num2 = 0; bool flag = false; for (int i = 0; i < num; i++) { string label = pkg.ReadString(); Vector3 pos = pkg.ReadVector3(); if (!beacon.Land.Scouted(pos, beacon.Ring)) { continue; } bool flag2 = Settings.OreMarkers.ContainsValue(label) || Settings.OreLocations.ContainsValue(label); float merge = (flag2 ? 24f : 5f); if (list.Exists((KeyValuePair<string, Vector3> p) => p.Key == label && Near(p.Value, pos, merge)) || (Settings.KeepDeletedPins.Value && Given(label, pos, merge))) { continue; } if (HasPin(instance, label, pos, merge)) { Remember(label, pos); list.Add(new KeyValuePair<string, Vector3>(label, pos)); flag = true; continue; } bool flag3 = "".Length > 0 && label.EndsWith(""); string label2 = (flag3 ? label.Substring(0, label.Length - "".Length) : label); if (!flag3 || !HasPin(instance, label2, pos, merge)) { if (flag2 && !flag3 && "".Length > 0) { RemovePins(instance, label ?? "", pos, merge); } list.Add(new KeyValuePair<string, Vector3>(label, pos)); instance.AddPin(pos, (PinType)(flag2 ? 3 : 2), label, true, false, 0L, default(PlatformUserID)); Remember(label, pos); num2++; } } if (num2 > 0 || flag) { SaveGiven(); } if (num2 > 0) { ((Character)Player.m_localPlayer).Message((MessageType)1, $"{beacon.Tier.DisplayName}: {num2} new markers", 0, (Sprite)null, false); } } private static void LoadGiven() { //IL_00a1: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)s_givenFor == (Object)(object)localPlayer) { return; } s_givenFor = localPlayer; s_given.Clear(); if (!Object.op_Implicit((Object)(object)localPlayer) || !localPlayer.m_customData.TryGetValue("ScoutingBeacons_pins", out var value)) { return; } string[] array = value.Split(new char[1] { '\n' }); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(new char[1] { '|' }); if (array2.Length == 3 && int.TryParse(array2[1], out var result) && int.TryParse(array2[2], out var result2)) { s_given.Add(new KeyValuePair<string, Vector3>(array2[0], new Vector3((float)result, 0f, (float)result2))); } } } private static bool Given(string label, Vector3 pos, float distance) { //IL_000e: 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) LoadGiven(); return s_given.Exists((KeyValuePair<string, Vector3> g) => g.Key == label && Near(g.Value, pos, distance)); } private static void Remember(string label, Vector3 pos) { //IL_000b: 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_0026: Unknown result type (might be due to invalid IL or missing references) LoadGiven(); s_given.Add(new KeyValuePair<string, Vector3>(label, new Vector3(Mathf.Round(pos.x), 0f, Mathf.Round(pos.z)))); } private static void SaveGiven() { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer)) { return; } StringBuilder stringBuilder = new StringBuilder(); foreach (KeyValuePair<string, Vector3> item in s_given) { stringBuilder.Append(item.Key.Replace("|", "/")).Append('|').Append((int)item.Value.x) .Append('|') .Append((int)item.Value.z) .Append('\n'); } localPlayer.m_customData["ScoutingBeacons_pins"] = stringBuilder.ToString().TrimEnd(new char[1] { '\n' }); } private static void RemovePins(Minimap map, string label, Vector3 pos, float distance) { //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) foreach (PinData item in new List<PinData>(map.m_pins)) { if (item.m_name == label && Near(item.m_pos, pos, distance)) { map.RemovePin(item); } } } private static bool HasPin(Minimap map, string label, Vector3 pos, float distance) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) foreach (PinData pin in map.m_pins) { if (pin.m_name == label && Near(pin.m_pos, pos, distance)) { return true; } } return false; } } public class OreCheckCommand : ConsoleCommand { private const float Match = 3f; public override string Name => "sb_orecheck"; public override string Help => "Scouting Beacons: compare predicted ore with real ore around you [radius, default 300]"; public override bool IsCheat => true; public override void Run(string[] args) { //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Unknown result type (might be due to invalid IL or missing references) //IL_0277: 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_028c: Unknown result type (might be due to invalid IL or missing references) //IL_0308: Unknown result type (might be due to invalid IL or missing references) //IL_0297: 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_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_02bc: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; ZoneSystem zones = ZoneSystem.instance; if (!Object.op_Implicit((Object)(object)localPlayer) || !Object.op_Implicit((Object)(object)zones) || !Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsServer()) { Print("Run this in single player or as the host (needs the server's world data)."); return; } float result; float radius = ((args.Length != 0 && float.TryParse(args[0], out result)) ? result : 300f); Dictionary<string, string> ores = Settings.OreMarkers; List<string> source = (from n in (from v in zones.m_vegetation where v.m_enable && Object.op_Implicit((Object)(object)v.m_prefab) select ((Object)v.m_prefab).name into n where n.ToLower().Contains("copper") || n.ToLower().Contains("tin") || n.ToLower().Contains("silver") || n.ToLower().Contains("mud") || n.ToLower().Contains("obsidian") || n.ToLower().Contains("meteor") || n.ToLower().Contains("brain") || n.ToLower().Contains("flametal") || n.ToLower().Contains("ore") select n).Distinct() orderby n select n).ToList(); Print("Ore-like vegetation in this game: " + string.Join(", ", source.Select((string n) => (!ores.ContainsKey(n)) ? (n + " (not in list)") : n))); List<KeyValuePair<string, Vector3>> real = new List<KeyValuePair<string, Vector3>>(); List<ZDO> list = new List<ZDO>(); foreach (KeyValuePair<string, string> item in ores) { list.Clear(); int num = 0; while (!ZDOMan.instance.GetAllZDOsWithPrefabIterative(item.Key, list, ref num)) { } foreach (ZDO item2 in list) { if (Utils.DistanceXZ(item2.GetPosition(), ((Component)localPlayer).transform.position) <= radius) { real.Add(new KeyValuePair<string, Vector3>(item.Value, item2.GetPosition())); } } } Vector3 centre = ((Component)localPlayer).transform.position; Vector2s zone = ZoneSystem.GetZone(centre - new Vector3(radius, 0f, radius)); Vector2s zone2 = ZoneSystem.GetZone(centre + new Vector3(radius, 0f, radius)); List<KeyValuePair<string, Vector3>> predicted = new List<KeyValuePair<string, Vector3>>(); int num2 = 0; Vector2s val = default(Vector2s); for (int num3 = zone.x; num3 <= zone2.x; num3++) { for (int num4 = zone.y; num4 <= zone2.y; num4++) { ((Vector2s)(ref val))..ctor(num3, num4); if (zones.IsZoneGenerated(val) && !(Utils.DistanceXZ(ZoneSystem.GetZonePos(val), centre) > radius)) { num2++; OrePredictor.Predict(val, ores, predicted); } } } real = real.Where((KeyValuePair<string, Vector3> kv) => zones.IsZoneGenerated(ZoneSystem.GetZone(kv.Value)) && Utils.DistanceXZ(ZoneSystem.GetZonePos(ZoneSystem.GetZone(kv.Value)), centre) <= radius).ToList(); int num5 = predicted.Count((KeyValuePair<string, Vector3> p) => real.Any((KeyValuePair<string, Vector3> q) => q.Key == p.Key && Utils.DistanceXZ(q.Value, p.Value) <= 3f)); int num6 = real.Count((KeyValuePair<string, Vector3> q) => predicted.Any((KeyValuePair<string, Vector3> p) => p.Key == q.Key && Utils.DistanceXZ(q.Value, p.Value) <= 3f)); float num7 = ((predicted.Count == 0 || real.Count == 0) ? 0f : predicted.Select((KeyValuePair<string, Vector3> p) => (from q in real where q.Key == p.Key select Utils.DistanceXZ(q.Value, p.Value)).DefaultIfEmpty(999f).Min()).Average()); Print($"{num2} generated zones within {radius:0} m: {real.Count} real deposits, {predicted.Count} predicted."); Print($"Predicted spots with a real deposit within {3f} m: {num5}/{predicted.Count}. " + $"Real deposits predicted: {num6}/{real.Count}. Average distance to the nearest real one: {num7:0.0} m."); foreach (string label in real.Select((KeyValuePair<string, Vector3> q) => q.Key).Concat(predicted.Select((KeyValuePair<string, Vector3> p) => p.Key)).Distinct()) { Print($" {label}: real {real.Count((KeyValuePair<string, Vector3> q) => q.Key == label)}, predicted {predicted.Count((KeyValuePair<string, Vector3> p) => p.Key == label)}, " + $"matched {predicted.Count((KeyValuePair<string, Vector3> p) => p.Key == label && real.Any((KeyValuePair<string, Vector3> q) => q.Key == label && Utils.DistanceXZ(q.Value, p.Value) <= 3f))}"); } Print("(Mined-out deposits are gone from the world data, so they count as 'predicted but not real'.)"); } private static void Print(string text) { Console instance = Console.instance; if (instance != null) { instance.Print(text); } Logger.LogInfo((object)("[sb_orecheck] " + text)); } } public static class OrePredictor { private struct Area { public Vector3 Centre; public float Radius; } private class ZoneTerrain { private readonly WorldGenerator m_world; private readonly float m_minX; private readonly float m_minZ; private readonly Biome b0; private readonly Biome b1; private readonly Biome b2; private readonly Biome b3; private readonly Biome s0; private readonly Biome s1; private readonly Biome s2; private readonly Biome s3; private readonly float[] m_depth = new float[4]; public readonly BiomeArea BiomeArea; private readonly Dictionary<int, KeyValuePair<float, float>> m_vertices = new Dictionary<int, KeyValuePair<float, float>>(); public ZoneTerrain(WorldGenerator world, Vector3 centre) { //IL_0025: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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_00a8: 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) //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_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00df: 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_00f8: 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_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012c: 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_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) m_world = world; m_minX = centre.x - 32f; m_minZ = centre.z - 32f; float num = m_minX + 64f; float num2 = m_minZ + 64f; b0 = world.GetBiome(m_minX, m_minZ, 0.02f, false); b1 = world.GetBiome(num, m_minZ, 0.02f, false); b2 = world.GetBiome(m_minX, num2, 0.02f, false); b3 = world.GetBiome(num, num2, 0.02f, false); s0 = world.GetBiomeSector(m_minX, m_minZ, false).Biome; s1 = world.GetBiomeSector(num, m_minZ, false).Biome; s2 = world.GetBiomeSector(m_minX, num2, false).Biome; s3 = world.GetBiomeSector(num, num2, false).Biome; BiomeArea = (BiomeArea)((s0 != s1 || s0 != s2 || s0 != s3) ? 1 : 2); m_depth[0] = Mathf.Max(0f, 30f - Vertex(0, 0).Key); m_depth[1] = Mathf.Max(0f, 30f - Vertex(64, 0).Key); m_depth[2] = Mathf.Max(0f, 30f - Vertex(64, 64).Key); m_depth[3] = Mathf.Max(0f, 30f - Vertex(0, 64).Key); } public bool HaveBiome(Biome biome) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Invalid comparison between Unknown and I4 if ((s0 & biome) == 0 && (s1 & biome) == 0 && (s2 & biome) == 0) { return (s3 & biome) > 0; } return true; } private KeyValuePair<float, float> Vertex(int l, int k) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00db: 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_010d: 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_013e: 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_0149: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_015f: 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_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) l = Mathf.Clamp(l, 0, 64); k = Mathf.Clamp(k, 0, 64); int key = k * 65 + l; if (m_vertices.TryGetValue(key, out var value)) { return value; } float num = m_minX + (float)l; float num2 = m_minZ + (float)k; float key2; Color val = default(Color); if (b1 == b0 && b2 == b0 && b3 == b0) { key2 = m_world.GetBiomeHeight(b0, num, num2, ref val, false, true); } else { float num3 = DUtils.SmoothStep(0f, 1f, (float)k / 64f); float num4 = DUtils.SmoothStep(0f, 1f, (float)l / 64f); Color val2 = default(Color); float biomeHeight = m_world.GetBiomeHeight(b0, num, num2, ref val2, false, true); Color val3 = default(Color); float biomeHeight2 = m_world.GetBiomeHeight(b1, num, num2, ref val3, false, true); Color val4 = default(Color); float biomeHeight3 = m_world.GetBiomeHeight(b2, num, num2, ref val4, false, true); Color val5 = default(Color); float biomeHeight4 = m_world.GetBiomeHeight(b3, num, num2, ref val5, false, true); key2 = DUtils.Lerp(DUtils.Lerp(biomeHeight, biomeHeight2, num4), DUtils.Lerp(biomeHeight3, biomeHeight4, num4), num3); val = Color.Lerp(Color.Lerp(val2, val3, num4), Color.Lerp(val4, val5, num4), num3); } value = new KeyValuePair<float, float>(key2, val.a); m_vertices[key] = value; return value; } public float Height(float x, float z) { float num = x - m_minX; float num2 = z - m_minZ; int num3 = Mathf.FloorToInt(num); int num4 = Mathf.FloorToInt(num2); float num5 = num - (float)num3; float num6 = num2 - (float)num4; float num7 = Mathf.Lerp(Vertex(num3, num4).Key, Vertex(num3 + 1, num4).Key, num5); float num8 = Mathf.Lerp(Vertex(num3, num4 + 1).Key, Vertex(num3 + 1, num4 + 1).Key, num5); return Mathf.Lerp(num7, num8, num6); } public Vector3 Normal(float x, float z) { //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_004b: Unknown result type (might be due to invalid IL or missing references) float num = Height(x + 0.5f, z) - Height(x - 0.5f, z); float num2 = Height(x, z + 0.5f) - Height(x, z - 0.5f); Vector3 val = new Vector3(0f - num, 1f, 0f - num2); return ((Vector3)(ref val)).normalized; } public float VegetationMask(Vector3 p) { //IL_0001: 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) return Vertex(Mathf.FloorToInt(p.x - 0.5f - m_minX + 0.5f), Mathf.FloorToInt(p.z - 0.5f - m_minZ + 0.5f)).Value; } public float OceanDepth(Vector3 p) { //IL_0000: 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) float num = Mathf.Clamp01((p.x - m_minX) / 64f); float num2 = Mathf.Clamp01((p.z - m_minZ) / 64f); return Mathf.Lerp(Mathf.Lerp(m_depth[3], m_depth[2], num), Mathf.Lerp(m_depth[0], m_depth[1], num), num2); } public Biome Biome(Vector3 p) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0031: 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_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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_010f: 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_0023: 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) if (s0 == s1 && s0 == s2 && s0 == s3) { return s0; } float x = (p.x - m_minX) / 64f; float y = (p.z - m_minZ) / 64f; Dictionary<Biome, float> weights = new Dictionary<Biome, float>(); Add(s0, Weight(x, y, 0f, 0f)); Add(s1, Weight(x, y, 1f, 0f)); Add(s2, Weight(x, y, 0f, 1f)); Add(s3, Weight(x, y, 1f, 1f)); return weights.OrderByDescending((KeyValuePair<Biome, float> kv) => kv.Value).First().Key; void Add(Biome b, float w) { //IL_0006: 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) weights[b] = (weights.TryGetValue(b, out var value) ? value : 0f) + w; } } private static float Weight(float x, float y, float rx, float ry) { float num = Mathf.Sqrt((x - rx) * (x - rx) + (y - ry) * (y - ry)); float num2 = 1.414f - num; return num2 * num2 * num2; } } private const float ZoneSize = 64f; private const float WaterLevel = 30f; public static void Predict(Vector2s zone, Dictionary<string, string> ores, List<KeyValuePair<string, Vector3>> found) { //IL_0724: 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) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0020: 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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: 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_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_02c5: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Unknown result type (might be due to invalid IL or missing references) //IL_0334: Unknown result type (might be due to invalid IL or missing references) //IL_033b: Unknown result type (might be due to invalid IL or missing references) //IL_034d: Unknown result type (might be due to invalid IL or missing references) //IL_0354: Unknown result type (might be due to invalid IL or missing references) //IL_035b: Unknown result type (might be due to invalid IL or missing references) //IL_0360: Unknown result type (might be due to invalid IL or missing references) //IL_0369: Unknown result type (might be due to invalid IL or missing references) //IL_036f: Unknown result type (might be due to invalid IL or missing references) //IL_0371: Unknown result type (might be due to invalid IL or missing references) //IL_0376: Unknown result type (might be due to invalid IL or missing references) //IL_0383: Unknown result type (might be due to invalid IL or missing references) //IL_0389: Unknown result type (might be due to invalid IL or missing references) //IL_038e: Unknown result type (might be due to invalid IL or missing references) //IL_0394: Unknown result type (might be due to invalid IL or missing references) //IL_03e9: Unknown result type (might be due to invalid IL or missing references) //IL_0467: Unknown result type (might be due to invalid IL or missing references) //IL_0438: Unknown result type (might be due to invalid IL or missing references) //IL_0475: Unknown result type (might be due to invalid IL or missing references) //IL_0497: Unknown result type (might be due to invalid IL or missing references) //IL_04f8: Unknown result type (might be due to invalid IL or missing references) //IL_055b: Unknown result type (might be due to invalid IL or missing references) //IL_069d: Unknown result type (might be due to invalid IL or missing references) //IL_06cb: Unknown result type (might be due to invalid IL or missing references) //IL_05e9: Unknown result type (might be due to invalid IL or missing references) //IL_0604: Unknown result type (might be due to invalid IL or missing references) //IL_0609: Unknown result type (might be due to invalid IL or missing references) ZoneSystem instance = ZoneSystem.instance; WorldGenerator instance2 = WorldGenerator.instance; if (!Object.op_Implicit((Object)(object)instance) || instance2 == null) { return; } Vector3 zonePos = ZoneSystem.GetZonePos(zone); ZoneTerrain zoneTerrain = new ZoneTerrain(instance2, zonePos); List<Area> areas = ClearAreas(instance, zone); State state = Random.state; int seed = instance2.GetSeed(); List<float> list = new List<float>(); try { Vector3 val = default(Vector3); foreach (ZoneVegetation veg in instance.m_vegetation) { if (!veg.m_enable || !Object.op_Implicit((Object)(object)veg.m_prefab) || !ores.TryGetValue(((Object)veg.m_prefab).name, out var value) || !zoneTerrain.HaveBiome(veg.m_biome)) { continue; } Random.InitState(seed + zone.x * 4271 + zone.y * 9187 + StringExtensionMethods.GetStableHashCode(((Object)veg.m_prefab).name)); int num = 1; if (veg.m_max < 1f) { if (Random.value > veg.m_max) { continue; } } else { num = Random.Range((int)veg.m_min, (int)veg.m_max + 1); } float num2 = Mathf.Cos((float)Math.PI / 180f * veg.m_maxTilt); float num3 = Mathf.Cos((float)Math.PI / 180f * veg.m_minTilt); float num4 = 32f - veg.m_groupRadius; list.Clear(); int num5 = (veg.m_forcePlacement ? (num * 50) : num); int num6 = 0; for (int i = 0; i < num5; i++) { ((Vector3)(ref val))..ctor(Random.Range(zonePos.x - num4, zonePos.x + num4), 0f, Random.Range(zonePos.z - num4, zonePos.z + num4)); BiomeSector biomeSector = instance2.GetBiomeSector(val, false); if ((veg.AltBiomeParent != null && !biomeSector.AltBiomes.Any((AltBiome x) => x.m_name == veg.AltBiomeParent)) || biomeSector.AltBiomes.Any((AltBiome x) => x.m_blockVegetationNames.Contains(veg.m_name))) { continue; } int num7 = Random.Range(veg.m_groupSizeMin, veg.m_groupSizeMax + 1); bool flag = false; for (int num8 = 0; num8 < num7; num8++) { Vector3 val2 = ((num8 == 0) ? val : RandomPointInRadius(val, veg.m_groupRadius)); Random.Range(0, 360); Random.Range(veg.m_scaleMin, veg.m_scaleMax); Random.Range(0f - veg.m_randTilt, veg.m_randTilt); Random.Range(0f - veg.m_randTilt, veg.m_randTilt); val2.y = zoneTerrain.Height(val2.x, val2.z); Vector3 val3 = zoneTerrain.Normal(val2.x, val2.z); if ((veg.m_biome & zoneTerrain.Biome(val2)) == 0 || (veg.m_biomeArea & zoneTerrain.BiomeArea) == 0) { continue; } float num9 = val2.y - 30f; if (num9 < veg.m_minAltitude || num9 > veg.m_maxAltitude) { continue; } if (!veg.m_minVegetation.Equals(veg.m_maxVegetation)) { float num10 = zoneTerrain.VegetationMask(val2); if (num10 > veg.m_maxVegetation || num10 < veg.m_minVegetation) { continue; } } if (!veg.m_minOceanDepth.Equals(veg.m_maxOceanDepth)) { float num11 = zoneTerrain.OceanDepth(val2); if (num11 < veg.m_minOceanDepth || num11 > veg.m_maxOceanDepth) { continue; } } if (val3.y < num2 || val3.y > num3) { continue; } if (veg.m_terrainDeltaRadius > 0f) { float num12 = TerrainDelta(zoneTerrain, val2, veg.m_terrainDeltaRadius); if (num12 > veg.m_maxTerrainDelta || num12 < veg.m_minTerrainDelta) { continue; } } if (veg.m_minDistanceFromCenter > 0f || veg.m_maxDistanceFromCenter > 0f) { float num13 = Utils.L