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 CDEV SmelterChests v0.1.1
plugins/CDEV.SmelterChests/CDEV.SmelterChests.dll
Decompiled 9 hours 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.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 BepInEx.Logging; using CDEV.SmelterChests.Compat; using CDEV.SmelterChests.UI; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_guiutils")] [assembly: IgnoresAccessChecksTo("assembly_utils")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("CDEV.SmelterChests")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.1.0")] [assembly: AssemblyInformationalVersion("0.1.1+efb24945142928ac03192750576c1d4fe797e026")] [assembly: AssemblyProduct("CDEV.SmelterChests")] [assembly: AssemblyTitle("CDEV.SmelterChests")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.1.1.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 CDEV.SmelterChests { internal static class Feeder { private sealed class SentAdds { internal ZDOID Id; internal int OreBase; internal readonly List<string> Ore = new List<string>(); internal float FuelBase; internal int Fuel; internal uint Revision; internal float Time; } private sealed class Request { internal ZDOID Id; internal string[] Prefabs; internal int Amount; internal float Time; internal int Token; internal Destination To; internal Vector2i Pos; internal string Refund; internal int RefundAmount; } private sealed class Pending { internal ZDOID Id; internal int Cell; internal string Before; internal string After; internal float Time; } internal enum Destination { Bag, Cell, Ground } private const float SettleAfterRevision = 2f; private const float GiveUpAfter = 6f; private const float RequestExpiry = 15f; private const float OverlayFor = 2.5f; private static SentAdds _sent; private static readonly List<Request> Requests = new List<Request>(); private static readonly List<Pending> Overlay = new List<Pending>(); private static readonly string[] Real = new string[10]; private static int _nextToken = 1; private static readonly string[] Shown = new string[10]; private static readonly bool[] ShownInFlight = new bool[10]; internal static void Clear() { _sent = null; Requests.Clear(); Overlay.Clear(); } internal static void Tick() { for (int num = Requests.Count - 1; num >= 0; num--) { Request request = Requests[num]; if (!(Time.time - request.Time <= 15f)) { Requests.RemoveAt(num); if (request.Refund != null && (Object)(object)Player.m_localPlayer != (Object)null) { Plugin.Log.LogWarning((object)("No answer from the station's owner (mod missing there?) - " + request.Refund + " given back.")); GiveToPlayer(Player.m_localPlayer, request.Refund, request.RefundAmount); } } } } internal static void Settle(Smelter smelter, ZDO zdo) { //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) if (_sent == null) { return; } if (_sent.Id != zdo.m_uid) { _sent = null; return; } float num = Time.time - _sent.Time; if ((smelter.GetQueueSize() >= _sent.OreBase + _sent.Ore.Count && smelter.GetFuel() >= _sent.FuelBase + (float)_sent.Fuel - 0.5f) || num > 6f || (zdo.DataRevision != _sent.Revision && num > 2f)) { _sent = null; } } private static SentAdds Sent(ZDO zdo) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) if (_sent == null || !(_sent.Id == zdo.m_uid)) { return null; } return _sent; } internal static int QueueSize(Smelter smelter, ZDO zdo) { int queueSize = smelter.GetQueueSize(); SentAdds sentAdds = Sent(zdo); if (sentAdds == null) { return queueSize; } return Mathf.Max(queueSize, sentAdds.OreBase + sentAdds.Ore.Count); } internal static float Fuel(Smelter smelter, ZDO zdo) { float fuel = smelter.GetFuel(); SentAdds sentAdds = Sent(zdo); if (sentAdds == null) { return fuel; } return Mathf.Max(fuel, sentAdds.FuelBase + (float)sentAdds.Fuel); } private static void RealCells(Smelter smelter, ZDO zdo, string[] into) { StationCells.Read(zdo, into); int queueSize = smelter.GetQueueSize(); int num = 0; foreach (string cell in into) { if (StationCells.IsOre(cell)) { num++; } } if (num == queueSize) { return; } int num2 = StationCells.Head(zdo); int num3 = 0; for (int j = 0; j < into.Length; j++) { int num4 = (num2 + j) % into.Length; if (StationCells.IsOre(into[num4])) { into[num4] = ((num3 < queueSize) ? ("o:" + SmelterState.QueuedAt(zdo, num3++)) : ""); } } while (num3 < queueSize) { int num5 = StationCells.NextEmpty(into, num2, -1); if (num5 >= 0) { into[num5] = "o:" + SmelterState.QueuedAt(zdo, num3++); continue; } break; } } internal static void Cells(Smelter smelter, ZDO zdo, string[] into, bool[] inFlight) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) RealCells(smelter, zdo, into); for (int i = 0; i < into.Length; i++) { inFlight[i] = false; } for (int num = Overlay.Count - 1; num >= 0; num--) { Pending pending = Overlay[num]; if (!(pending.Id != zdo.m_uid)) { if (into[pending.Cell] == pending.After || Time.time - pending.Time > 2.5f) { Overlay.RemoveAt(num); } else if (into[pending.Cell] == pending.Before) { into[pending.Cell] = pending.After; inFlight[pending.Cell] = pending.After != ""; } } } SentAdds sentAdds = Sent(zdo); if (sentAdds == null) { return; } int num2 = sentAdds.OreBase + sentAdds.Ore.Count - smelter.GetQueueSize(); int head = StationCells.Head(zdo); for (int j = Mathf.Max(0, sentAdds.Ore.Count - num2); j < sentAdds.Ore.Count; j++) { int num3 = StationCells.NextEmpty(into, head, -1); if (num3 >= 0) { into[num3] = "o:" + sentAdds.Ore[j]; inFlight[num3] = true; continue; } break; } } internal static int OreRoom(Smelter smelter, ZDO zdo) { Cells(smelter, zdo, Shown, ShownInFlight); int num = 0; string[] shown = Shown; foreach (string text in shown) { if (text == "") { num++; } } return Mathf.Min(num, Mathf.Max(0, smelter.m_maxOre - QueueSize(smelter, zdo))); } internal static int FuelRoom(Smelter smelter, ZDO zdo) { float num = Fuel(smelter, zdo); float num2 = smelter.m_maxFuel - 1; if (!(num > num2)) { return Mathf.FloorToInt(num2 - num) + 1; } return 0; } private static SentAdds Begin(Smelter smelter, ZDO zdo) { //IL_0011: 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) SentAdds sentAdds = Sent(zdo); if (sentAdds == null) { SentAdds obj = new SentAdds { Id = zdo.m_uid, OreBase = smelter.GetQueueSize(), FuelBase = smelter.GetFuel() }; _sent = obj; sentAdds = obj; } sentAdds.Revision = zdo.DataRevision; sentAdds.Time = Time.time; return sentAdds; } private static void Show(ZDO zdo, int cell, string before, string after) { //IL_000c: 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) Overlay.Add(new Pending { Id = zdo.m_uid, Cell = cell, Before = before, After = after, Time = Time.time }); } internal static bool IsOre(Smelter smelter, ItemData item) { if (item != null && (Object)(object)item.m_dropPrefab != (Object)null) { return smelter.IsItemAllowed(((Object)item.m_dropPrefab).name); } return false; } internal static bool IsFuel(Smelter smelter, ItemData item) { if (item != null && (Object)(object)smelter.m_fuelItem != (Object)null && smelter.m_maxFuel > 0) { return item.m_shared.m_name == smelter.m_fuelItem.m_itemData.m_shared.m_name; } return false; } internal static bool IsBar(Smelter smelter, ItemData item) { if (item == null || (Object)(object)item.m_dropPrefab == (Object)null) { return false; } foreach (ItemConversion item2 in smelter.m_conversion) { if ((Object)(object)item2.m_to != (Object)null && ((Object)((Component)item2.m_to).gameObject).name == ((Object)item.m_dropPrefab).name) { return true; } } return false; } private static string PrefabOf(ItemData item) { return ((Object)item.m_dropPrefab).name; } internal static int AddOre(Smelter smelter, Player player, Inventory inventory, ItemData item, int amount) { ZDO val = SmelterState.Zdo(smelter); if (val == null || !IsOre(smelter, item)) { return 0; } int num = Mathf.Min(new int[3] { amount, item.m_stack, OreRoom(smelter, val) }); if (num <= 0) { ((Character)player).Message((MessageType)2, "$msg_itsfull", 0, (Sprite)null, false); return 0; } string text = PrefabOf(item); string name = item.m_shared.m_name; Sprite icon = item.GetIcon(); bool cheated = item.m_cheated; inventory.RemoveItem(item, num); SentAdds sentAdds = Begin(smelter, val); for (int i = 0; i < num; i++) { sentAdds.Ore.Add(text); smelter.m_nview.InvokeRPC("RPC_AddOre", new object[2] { text, cheated }); } ((Character)player).Message((MessageType)1, "$msg_added " + name, num, icon, false); AddAnimation(smelter); return num; } private static void AddAnimation(Smelter smelter) { smelter.m_addedOreTime = Time.time; if (smelter.m_addOreAnimationDuration > 0f) { smelter.SetAnimation(true); } } internal static int AddFuel(Smelter smelter, Player player, Inventory inventory, ItemData item, int amount) { ZDO val = SmelterState.Zdo(smelter); if (val == null || !IsFuel(smelter, item)) { return 0; } int num = Mathf.Min(new int[3] { amount, item.m_stack, FuelRoom(smelter, val) }); if (num <= 0) { ((Character)player).Message((MessageType)2, "$msg_itsfull", 0, (Sprite)null, false); return 0; } string name = item.m_shared.m_name; Sprite icon = item.GetIcon(); inventory.RemoveItem(item, num); SentAdds sentAdds = Begin(smelter, val); for (int i = 0; i < num; i++) { sentAdds.Fuel++; smelter.m_nview.InvokeRPC("RPC_AddFuel", Array.Empty<object>()); } ((Character)player).Message((MessageType)1, "$msg_added " + name, num, icon, false); return num; } internal static bool PutOre(Smelter smelter, Player player, Inventory inventory, ItemData item, int cell) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) ZDO val = SmelterState.Zdo(smelter); if (val == null || !IsOre(smelter, item) || OreRoom(smelter, val) <= 0) { return false; } string text = PrefabOf(item); inventory.RemoveItem(item, 1); int token = _nextToken++; Requests.Add(new Request { Id = val.m_uid, Prefabs = new string[0], Amount = 1, Time = Time.time, Token = token, Refund = text, RefundAmount = 1 }); Show(val, cell, "", "o:" + text); SmelterState.RequestPutOre(smelter, cell, text, token); AddAnimation(smelter); return true; } internal static bool Replace(Smelter smelter, Player player, Inventory inventory, ItemData item, int cell, string old) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_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) ZDO val = SmelterState.Zdo(smelter); GameObject val2 = (((Object)(object)ObjectDB.instance != (Object)null && !string.IsNullOrEmpty(old)) ? ObjectDB.instance.GetItemPrefab(old) : null); if (val == null || (Object)(object)val2 == (Object)null || !IsOre(smelter, item) || PrefabOf(item) == old) { return false; } string text = PrefabOf(item); bool flag = item.m_stack == 1 && inventory == ((Humanoid)player).GetInventory(); Vector2i gridPos = item.m_gridPos; if (!flag && !((Humanoid)player).GetInventory().CanAddItem(val2, 1)) { ((Character)player).Message((MessageType)2, "$msg_noroom", 0, (Sprite)null, false); return false; } inventory.RemoveItem(item, 1); Requests.Add(new Request { Id = val.m_uid, Prefabs = new string[2] { old, text }, Amount = 1, Time = Time.time, Refund = text, RefundAmount = 1, To = (flag ? Destination.Cell : Destination.Bag), Pos = gridPos }); Show(val, cell, "o:" + old, "o:" + text); SmelterState.RequestReplace(smelter, cell, old, text); AddAnimation(smelter); return true; } internal static void Take(Smelter smelter, Player player, int cell, string content, int amount, Destination to, Vector2i pos) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) string text = StationCells.Key(content); string text2 = StationCells.PrefabOf(content); ZDO val = SmelterState.Zdo(smelter); if (val != null && text2 != null && Ask(smelter, player, text2, amount, to, pos)) { int num = StationCells.CountOf(content) - amount; Show(val, cell, content, (StationCells.IsBar(content) && num > 0) ? (text + ":" + num) : ""); SmelterState.RequestTake(smelter, cell, text, amount); } } internal static void TakeAll(Smelter smelter, Player player, string key, int amount, Destination to, Vector2i pos) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) string text = StationCells.PrefabOf(key); if (text != null && amount > 0 && Ask(smelter, player, text, amount, to, pos)) { SmelterState.RequestTakeAll(smelter, key, amount); } } internal static void TakeFuel(Smelter smelter, Player player, int amount, Destination to, Vector2i pos) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)smelter.m_fuelItem != (Object)null && Ask(smelter, player, ((Object)((Component)smelter.m_fuelItem).gameObject).name, amount, to, pos)) { SmelterState.RequestTakeFuel(smelter, amount); } } private static bool Ask(Smelter smelter, Player player, string prefab, int amount, Destination to, Vector2i pos) { //IL_0067: 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_009c: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) ZDO val = SmelterState.Zdo(smelter); GameObject val2 = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(prefab) : null); if (val == null || (Object)(object)val2 == (Object)null || amount <= 0) { return false; } if (to != Destination.Ground && !((Humanoid)player).GetInventory().CanAddItem(val2, amount)) { ((Character)player).Message((MessageType)2, "$msg_noroom", 0, (Sprite)null, false); return false; } Requests.Add(new Request { Id = val.m_uid, Prefabs = new string[1] { prefab }, Amount = amount, Time = Time.time, To = to, Pos = pos }); return true; } internal static void OnGive(Smelter smelter, string prefab, int amount) { //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_00b4: Unknown result type (might be due to invalid IL or missing references) ZDO val = SmelterState.Zdo(smelter); Player localPlayer = Player.m_localPlayer; if (val == null || (Object)(object)localPlayer == (Object)null || amount <= 0) { return; } int num = 0; int num2 = Requests.Count - 1; while (num2 >= 0 && num < amount) { Request request = Requests[num2]; if (!(request.Id != val.m_uid) && Array.IndexOf(request.Prefabs, prefab) >= 0) { int num3 = Mathf.Min(amount - num, request.Amount); num += num3; request.Amount -= num3; if (request.Amount <= 0 || request.Refund != null) { Requests.RemoveAt(num2); } Deliver(localPlayer, prefab, num3, request.To, request.Pos); } num2--; } } private static void Deliver(Player player, string prefab, int amount, Destination to, Vector2i pos) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) if (amount <= 0) { return; } switch (to) { case Destination.Ground: { Transform transform = ((Component)player).transform; StationStore.DropAt(transform.position + transform.forward + Vector3.up, prefab, amount); return; } case Destination.Cell: if (PlaceAt(((Humanoid)player).GetInventory(), prefab, amount, pos)) { return; } break; } GiveToPlayer(player, prefab, amount, message: false); } private static bool PlaceAt(Inventory inventory, string prefab, int amount, Vector2i pos) { //IL_0038: 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_004a: 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_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(prefab) : null); ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null); if ((Object)(object)val2 == (Object)null || pos.x < 0 || pos.y < 0 || pos.x >= inventory.GetWidth() || pos.y >= inventory.GetHeight()) { return false; } ItemData itemAt = inventory.GetItemAt(pos.x, pos.y); int maxStackSize = val2.m_itemData.m_shared.m_maxStackSize; if (itemAt != null && ((Object)(object)itemAt.m_dropPrefab == (Object)null || ((Object)itemAt.m_dropPrefab).name != prefab || itemAt.m_stack + amount > maxStackSize)) { return false; } ItemData val3 = val2.m_itemData.Clone(); val3.m_dropPrefab = val; val3.m_stack = amount; val3.m_worldLevel = (byte)Game.m_worldLevel; return inventory.AddItem(val3, amount, pos.x, pos.y, false); } internal static void OnAck(int token) { for (int num = Requests.Count - 1; num >= 0; num--) { if (Requests[num].Token == token) { Requests.RemoveAt(num); } } } internal static void GiveToPlayer(Player player, string prefab, int granted, bool message = true) { //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_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(prefab) : null); ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null); if (!((Object)(object)val2 == (Object)null) && granted > 0) { Inventory inventory = ((Humanoid)player).GetInventory(); if (!inventory.CanAddItem(val, granted) || !inventory.AddItem(val, granted)) { Transform transform = ((Component)player).transform; StationStore.DropAt(transform.position + transform.forward + Vector3.up, prefab, granted); message = true; } if (message) { ((Character)player).Message((MessageType)1, val2.m_itemData.m_shared.m_name, granted, val2.m_itemData.GetIcon(), false); } } } } internal static class ModConfig { internal static ConfigEntry<bool> Window; internal static ConfigEntry<string> Stations; internal static ConfigEntry<string> Chests; internal static ConfigEntry<string> ChestStations; internal static void Bind(ConfigFile config) { Window = config.Bind<bool>("General", "Window", false, "Use on a smelter or blast furnace opens the station's window (ore cells, fuel, Autostart, Keep bars inside). Off: Use adds ore and fuel as in vanilla, the station smelts on its own and drops its bars (or puts them into the front chest), and the attached chests, the snapping and the mirroring work as before."); Window.SettingChanged += delegate { SmelterPanel.CloseIfDisabled(); }; Stations = config.Bind<string>("General", "Stations", "smelter,blastfurnace", "Prefab names of the stations with cells, chests on three sides and (with Window on) the window, comma-separated. With the window, Alt + Use keeps the vanilla add. A station's hold (Autostart off) is honoured by the player who owns it, so keep this the same for everyone."); Stations.SettingChanged += delegate { SmelterState.ResetStations(); }; Chests = config.Bind<string>("General", "Chests", "piece_chest_wood,piece_chest,piece_chest_blackmetal", "Prefab names of the chests that work when attached to a station: standing in front of it (where the bars come out), the chest on the left gives ore, the one on the right fuel, the one in front takes the bars. Comma-separated. Worked by the station's owner, so keep this the same for everyone."); Chests.SettingChanged += delegate { StationChests.ResetChests(); }; ChestStations = config.Bind<string>("General", "ChestStations", "charcoal_kiln", "Prefab names of stations without the window that still take chests: a chest placed against any side feeds it and receives what it makes (the charcoal kiln: wood in, coal back). Comma-separated. Worked by the station's owner, so keep this the same for everyone."); ChestStations.SettingChanged += delegate { SmelterState.ResetStations(); }; } } [BepInPlugin("cdev.smelterchests", "CDEV.SmelterChests", "0.1.1")] public sealed class Plugin : BaseUnityPlugin { internal static ManualLogSource Log; private Harmony _harmony; private void Awake() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; ModConfig.Bind(((BaseUnityPlugin)this).Config); _harmony = new Harmony("cdev.smelterchests"); _harmony.PatchAll(Assembly.GetExecutingAssembly()); } private void Update() { Feeder.Tick(); SmelterPanel.Tick(); } private void OnDestroy() { SmelterPanel.DestroyAll(); StationBody.DestroyAll(); Feeder.Clear(); SmelterState.UnregisterAll(); StationChests.Clear(); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } internal static class SmelterState { internal const int OreCells = 10; private const string RpcSetAuto = "CDEV_SmelterWindow_SetAuto"; private const string RpcStart = "CDEV_SmelterWindow_Start"; private const string RpcSetKeep = "CDEV_SmelterWindow_SetKeep"; private const string RpcTake = "CDEV_SmelterWindow_Take"; private const string RpcTakeAll = "CDEV_SmelterWindow_TakeAll"; private const string RpcPutOre = "CDEV_SmelterWindow_PutOre"; private const string RpcMove = "CDEV_SmelterWindow_Move"; private const string RpcTakeFuel = "CDEV_SmelterWindow_TakeFuel"; private const string RpcReplace = "CDEV_SmelterWindow_Replace"; private const string RpcAck = "CDEV_SmelterWindow_Ack"; internal const string RpcGive = "CDEV_SmelterWindow_Give"; private static readonly int SetAutoHash = StringExtensionMethods.GetStableHashCode("CDEV_SmelterWindow_SetAuto"); private static readonly int AutoKey = StringExtensionMethods.GetStableHashCode("cdev.smelterwindow.autostart"); private static readonly int RunKey = StringExtensionMethods.GetStableHashCode("cdev.smelterwindow.running"); private static readonly int KeepKey = StringExtensionMethods.GetStableHashCode("cdev.smelterwindow.keep"); private static HashSet<int> _stations; private static HashSet<int> _chestStations; private static readonly string[] AllRpcs = new string[11] { "CDEV_SmelterWindow_SetAuto", "CDEV_SmelterWindow_Start", "CDEV_SmelterWindow_SetKeep", "CDEV_SmelterWindow_Take", "CDEV_SmelterWindow_TakeAll", "CDEV_SmelterWindow_PutOre", "CDEV_SmelterWindow_Move", "CDEV_SmelterWindow_TakeFuel", "CDEV_SmelterWindow_Replace", "CDEV_SmelterWindow_Give", "CDEV_SmelterWindow_Ack" }; internal static void ResetStations() { _stations = null; _chestStations = null; } private static HashSet<int> Parse(string list) { HashSet<int> hashSet = new HashSet<int>(); string[] array = (list ?? "").Split(new char[3] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text in array) { hashSet.Add(StringExtensionMethods.GetStableHashCode(text.Trim())); } return hashSet; } internal static bool IsChestOnly(Smelter smelter) { ZDO val = Zdo(smelter); if (val == null || smelter.m_maxOre <= 0) { return false; } if (_chestStations == null) { _chestStations = Parse(ModConfig.ChestStations.Value); } if (_chestStations.Contains(val.GetPrefab())) { return !IsHandled(smelter); } return false; } internal static bool TakesChests(Smelter smelter) { if (!IsHandled(smelter)) { return IsChestOnly(smelter); } return true; } internal static bool IsHandledPrefab(int prefab) { return Stations().Contains(prefab); } internal static bool IsChestOnlyPrefab(int prefab) { if (_chestStations == null) { _chestStations = Parse(ModConfig.ChestStations.Value); } if (_chestStations.Contains(prefab)) { return !IsHandledPrefab(prefab); } return false; } private static HashSet<int> Stations() { if (_stations != null) { return _stations; } _stations = Parse(ModConfig.Stations.Value); return _stations; } internal static ZDO Zdo(Smelter smelter) { ZNetView val = (((Object)(object)smelter != (Object)null) ? smelter.m_nview : null); if (!((Object)(object)val != (Object)null) || !val.IsValid()) { return null; } return val.GetZDO(); } internal static bool IsHandled(Smelter smelter) { ZDO val = Zdo(smelter); if (val != null && smelter.m_maxOre > 0) { return Stations().Contains(val.GetPrefab()); } return false; } internal static bool AutoStart(ZDO zdo) { return zdo.GetBool(AutoKey, true); } internal static bool Running(ZDO zdo) { return zdo.GetBool(RunKey, false); } internal static bool Keep(ZDO zdo) { return zdo.GetBool(KeepKey, false); } internal static bool IsHeld(Smelter smelter) { ZDO val = Zdo(smelter); if (val != null && IsHandled(smelter) && smelter.GetQueueSize() > 0 && !AutoStart(val)) { return !Running(val); } return false; } internal static string QueuedAt(ZDO zdo, int index) { return zdo.GetString("item" + index, ""); } internal static bool HoldTick(Smelter smelter) { ZDO val = Zdo(smelter); bool flag = smelter.m_nview.IsOwner(); StationChests.Remember(smelter); if (flag) { StationCells.Reconcile(smelter, val); if (!ModConfig.Window.Value) { WithoutWindow(smelter, val); } StationChests.Tick(smelter, val); StationStore.ApplySaved(smelter, val); } if (smelter.GetQueueSize() <= 0) { if (flag && Running(val)) { val.Set(RunKey, false); } return false; } if (AutoStart(val) || Running(val)) { return false; } smelter.UpdateRoof(); smelter.UpdateSmoke(); smelter.UpdateState(); if (flag) { smelter.GetDeltaTime(); if (smelter.m_maxFuel > 0 && smelter.GetFuel() <= 0f) { smelter.SpawnProcessed(); } } return true; } private static void WithoutWindow(Smelter smelter, ZDO zdo) { if (!AutoStart(zdo)) { zdo.Set(AutoKey, true); } if (Running(zdo)) { zdo.Set(RunKey, false); } if (Keep(zdo)) { zdo.Set(KeepKey, false); } if (StationCells.Bars(zdo) > 0 && (Object)(object)StationChests.Attached(smelter, StationChests.Side.Bars) == (Object)null) { StationCells.DropBars(smelter, zdo); } } internal static void RequestAutoStart(Smelter smelter, bool on) { Send(smelter, "CDEV_SmelterWindow_SetAuto", on); } internal static void RequestStart(Smelter smelter) { Send(smelter, "CDEV_SmelterWindow_Start"); } internal static void RequestKeep(Smelter smelter, bool on) { Send(smelter, "CDEV_SmelterWindow_SetKeep", on); } internal static void RequestTake(Smelter smelter, int cell, string key, int amount) { Send(smelter, "CDEV_SmelterWindow_Take", cell, key, amount); } internal static void RequestTakeAll(Smelter smelter, string key, int max) { Send(smelter, "CDEV_SmelterWindow_TakeAll", key, max); } internal static void RequestPutOre(Smelter smelter, int cell, string prefab, int token) { Send(smelter, "CDEV_SmelterWindow_PutOre", cell, prefab, token); } internal static void RequestMove(Smelter smelter, int from, string key, int to, int amount) { Send(smelter, "CDEV_SmelterWindow_Move", from, key, to * 10000 + Mathf.Clamp(amount, 0, 9999)); } internal static void RequestTakeFuel(Smelter smelter, int amount) { Send(smelter, "CDEV_SmelterWindow_TakeFuel", amount); } internal static void RequestReplace(Smelter smelter, int cell, string old, string prefab) { Send(smelter, "CDEV_SmelterWindow_Replace", cell, old, prefab); } private static void Send(Smelter smelter, string rpc, params object[] args) { if (Zdo(smelter) != null) { EnsureRegistered(smelter); smelter.m_nview.InvokeRPC(rpc, args); } } internal static void EnsureRegistered(Smelter smelter) { ZNetView nview = smelter.m_nview; if (!((Object)(object)nview == (Object)null) && !nview.m_functions.ContainsKey(SetAutoHash)) { nview.Register<bool>("CDEV_SmelterWindow_SetAuto", (Action<long, bool>)delegate(long sender, bool on) { OnSetAuto(smelter, on); }); nview.Register("CDEV_SmelterWindow_Start", (Action<long>)delegate { OnStart(smelter); }); nview.Register<bool>("CDEV_SmelterWindow_SetKeep", (Action<long, bool>)delegate(long sender, bool on) { OnSetKeep(smelter, on); }); nview.Register<int, string, int>("CDEV_SmelterWindow_Take", (Action<long, int, string, int>)delegate(long sender, int cell, string key, int amount) { OnTake(smelter, sender, cell, key, amount); }); nview.Register<string, int>("CDEV_SmelterWindow_TakeAll", (Action<long, string, int>)delegate(long sender, string key, int max) { OnTakeAll(smelter, sender, key, max); }); nview.Register<int, string, int>("CDEV_SmelterWindow_PutOre", (Action<long, int, string, int>)delegate(long sender, int cell, string prefab, int token) { OnPutOre(smelter, sender, cell, prefab, token); }); nview.Register<int, string, int>("CDEV_SmelterWindow_Move", (Action<long, int, string, int>)delegate(long sender, int from, string key, int toAndAmount) { OnMove(smelter, from, key, toAndAmount); }); nview.Register<int>("CDEV_SmelterWindow_TakeFuel", (Action<long, int>)delegate(long sender, int amount) { OnTakeFuel(smelter, sender, amount); }); nview.Register<int, string, string>("CDEV_SmelterWindow_Replace", (Action<long, int, string, string>)delegate(long sender, int cell, string old, string prefab) { OnReplace(smelter, sender, cell, old, prefab); }); nview.Register<string, int>("CDEV_SmelterWindow_Give", (Action<long, string, int>)delegate(long sender, string prefab, int amount) { Feeder.OnGive(smelter, prefab, amount); }); nview.Register<int>("CDEV_SmelterWindow_Ack", (Action<long, int>)delegate(long sender, int token) { Feeder.OnAck(token); }); } } internal static void UnregisterAll() { Smelter[] array = Object.FindObjectsByType<Smelter>((FindObjectsSortMode)0); foreach (Smelter val in array) { ZNetView nview = val.m_nview; if (!((Object)(object)nview == (Object)null) && nview.m_functions.ContainsKey(SetAutoHash)) { string[] allRpcs = AllRpcs; foreach (string text in allRpcs) { nview.Unregister(text); } } } } private static bool OwnerZdo(Smelter smelter, out ZDO zdo) { zdo = (((Object)(object)smelter != (Object)null) ? Zdo(smelter) : null); if (zdo != null && smelter.m_nview.IsOwner()) { return IsHandled(smelter); } return false; } private static void OnSetAuto(Smelter smelter, bool on) { if (OwnerZdo(smelter, out var zdo)) { if (!on) { zdo.Set(RunKey, false); } zdo.Set(AutoKey, on); } } private static void OnStart(Smelter smelter) { if (OwnerZdo(smelter, out var zdo) && smelter.GetQueueSize() > 0) { zdo.Set(RunKey, true); } } private static void OnSetKeep(Smelter smelter, bool on) { if (OwnerZdo(smelter, out var zdo)) { zdo.Set(KeepKey, on); } } private static void OnTake(Smelter smelter, long sender, int cell, string key, int amount) { if (OwnerZdo(smelter, out var zdo) && !string.IsNullOrEmpty(key)) { int num = StationCells.Take(smelter, zdo, cell, key, amount); if (num > 0) { smelter.m_nview.InvokeRPC(sender, "CDEV_SmelterWindow_Give", new object[2] { StationCells.PrefabOf(key), num }); } } } private static void OnTakeAll(Smelter smelter, long sender, string key, int max) { if (OwnerZdo(smelter, out var zdo) && !string.IsNullOrEmpty(key)) { int num = StationCells.TakeAll(smelter, zdo, key, max); if (num > 0) { smelter.m_nview.InvokeRPC(sender, "CDEV_SmelterWindow_Give", new object[2] { StationCells.PrefabOf(key), num }); } } } private static void OnPutOre(Smelter smelter, long sender, int cell, string prefab, int token) { if (!OwnerZdo(smelter, out var zdo) || string.IsNullOrEmpty(prefab)) { return; } StationCells.Reconcile(smelter, zdo); if (!smelter.IsItemAllowed(prefab)) { smelter.m_nview.InvokeRPC(sender, "CDEV_SmelterWindow_Give", new object[2] { prefab, 1 }); } else { StationCells.TargetCell = cell; try { smelter.RPC_AddOre(sender, prefab, false); } finally { StationCells.TargetCell = -1; } } smelter.m_nview.InvokeRPC(sender, "CDEV_SmelterWindow_Ack", new object[1] { token }); } private static void OnMove(Smelter smelter, int from, string key, int toAndAmount) { if (OwnerZdo(smelter, out var zdo)) { StationCells.Move(smelter, zdo, from, key, toAndAmount / 10000, toAndAmount % 10000); } } private static void OnReplace(Smelter smelter, long sender, int cell, string old, string prefab) { if (OwnerZdo(smelter, out var zdo) && !string.IsNullOrEmpty(prefab)) { bool flag = smelter.IsItemAllowed(prefab) && StationCells.Replace(smelter, zdo, cell, old, prefab); smelter.m_nview.InvokeRPC(sender, "CDEV_SmelterWindow_Give", new object[2] { flag ? old : prefab, 1 }); } } internal static bool RefuseOverflow(Smelter smelter, string prefab) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) if (!OwnerZdo(smelter, out var zdo)) { return false; } StationCells.Reconcile(smelter, zdo); if (StationCells.HasEmpty(zdo) && smelter.GetQueueSize() < smelter.m_maxOre) { return false; } Transform val = (((Object)(object)smelter.m_outputPoint != (Object)null) ? smelter.m_outputPoint : ((Component)smelter).transform); StationStore.DropAt(val.position, prefab); return true; } private static void OnTakeFuel(Smelter smelter, long sender, int amount) { if (OwnerZdo(smelter, out var _) && !((Object)(object)smelter.m_fuelItem == (Object)null) && amount > 0) { float fuel = smelter.GetFuel(); int num = Mathf.Min(amount, Mathf.FloorToInt(fuel)); if (num > 0) { smelter.SetFuel(fuel - (float)num); smelter.m_nview.InvokeRPC(sender, "CDEV_SmelterWindow_Give", new object[2] { ((Object)((Component)smelter.m_fuelItem).gameObject).name, num }); } } } } internal sealed class StationBody : MonoBehaviour, Hoverable, Interactable { private static readonly List<StationBody> All = new List<StationBody>(); private Smelter _smelter; private bool Active { get { if ((Object)(object)_smelter != (Object)null && (Object)(object)_smelter.m_addOreSwitch != (Object)null) { if (!SmelterState.IsHandled(_smelter)) { return SmelterState.IsChestOnly(_smelter); } return ModConfig.Window.Value; } return false; } } private bool InfoOnly { get { if ((Object)(object)_smelter != (Object)null && (Object)(object)_smelter.m_addOreSwitch != (Object)null && !Active) { return SmelterState.IsHandled(_smelter); } return false; } } internal static void Ensure(Smelter smelter) { if (!((Object)(object)smelter.m_addOreSwitch == (Object)null) && !((Object)(object)((Component)smelter).GetComponent<StationBody>() != (Object)null)) { StationBody stationBody = ((Component)smelter).gameObject.AddComponent<StationBody>(); stationBody._smelter = smelter; All.Add(stationBody); } } internal static void DestroyAll() { foreach (StationBody item in All) { if ((Object)(object)item != (Object)null) { Object.Destroy((Object)(object)item); } } All.Clear(); } private void OnDestroy() { All.Remove(this); } public string GetHoverText() { if (Active) { return _smelter.OnHoverAddOre(); } if (!InfoOnly) { return ""; } return WithoutKeyLines(_smelter.OnHoverAddOre()); } public string GetHoverName() { if (!Active && !InfoOnly) { return ""; } return _smelter.m_name; } private static string WithoutKeyLines(string text) { if (string.IsNullOrEmpty(text)) { return text; } string[] array = text.Split(new char[1] { '\n' }); StringBuilder stringBuilder = new StringBuilder(text.Length); string[] array2 = array; foreach (string text2 in array2) { if (text2.IndexOf("<color=yellow><b>", StringComparison.OrdinalIgnoreCase) < 0) { if (stringBuilder.Length > 0) { stringBuilder.Append('\n'); } stringBuilder.Append(text2); } } return stringBuilder.ToString(); } public float GetHoverOffset() { if (!((Object)(object)_smelter != (Object)null) || !((Object)(object)_smelter.m_addOreSwitch != (Object)null)) { return 0f; } return _smelter.m_addOreSwitch.GetHoverOffset(); } public bool Interact(Humanoid user, bool hold, bool alt) { if (!Active) { return false; } return _smelter.m_addOreSwitch.Interact(user, hold, alt); } public bool UseItem(Humanoid user, ItemData item) { if (Active) { return _smelter.m_addOreSwitch.UseItem(user, item); } return false; } } internal static class StationCells { internal const int Count = 10; private static readonly int CellsKey = StringExtensionMethods.GetStableHashCode("cdev.smelterwindow.cells"); private static readonly int HeadKey = StringExtensionMethods.GetStableHashCode("cdev.smelterwindow.head"); private static readonly int OldBarsKey = StringExtensionMethods.GetStableHashCode("cdev.smelterwindow.bars"); private static readonly int OldOutputKey = StringExtensionMethods.GetStableHashCode("cdev.smelterwindow.output"); private static readonly string[] Scratch = new string[10]; internal static int TargetCell = -1; private static int _smeltedCell = -1; internal static bool IsOre(string cell) { return cell?.StartsWith("o:") ?? false; } internal static bool IsBar(string cell) { return cell?.StartsWith("b:") ?? false; } internal static string Key(string cell) { if (IsOre(cell)) { return cell; } if (!IsBar(cell)) { return ""; } int num = cell.LastIndexOf(':'); if (num <= 1) { return cell; } return cell.Substring(0, num); } internal static string PrefabOf(string cell) { string text = Key(cell); if (text.Length <= 2) { return null; } return text.Substring(2); } internal static int CountOf(string cell) { if (IsOre(cell)) { return 1; } if (!IsBar(cell)) { return 0; } int num = cell.LastIndexOf(':'); if (num <= 1 || !int.TryParse(cell.Substring(num + 1), out var result)) { return 1; } return result; } private static string Bar(string prefab, int count) { if (count <= 0) { return ""; } return "b:" + prefab + ":" + count; } internal static void Read(ZDO zdo, string[] into) { for (int i = 0; i < 10; i++) { into[i] = ""; } string text = zdo.GetString(CellsKey, ""); if (!string.IsNullOrEmpty(text)) { string[] array = text.Split(new char[1] { ',' }); for (int j = 0; j < 10 && j < array.Length; j++) { into[j] = array[j]; } } } private static void Write(ZDO zdo, string[] cells) { zdo.Set(CellsKey, string.Join(",", cells)); } internal static int Bars(ZDO zdo) { Read(zdo, Scratch); int num = 0; string[] scratch = Scratch; foreach (string cell in scratch) { if (IsBar(cell)) { num++; } } return num; } internal static int Head(ZDO zdo) { return Mathf.Clamp(zdo.GetInt(HeadKey, 0), 0, 9); } private static int At(int head, int k) { return (head + k) % 10; } internal static int FrontCell(string[] cells, int head) { for (int i = 0; i < 10; i++) { int num = At(head, i); if (IsOre(cells[num])) { return num; } } return -1; } internal static int NextEmpty(string[] cells, int head, int preferred) { if (preferred >= 0 && preferred < 10 && cells[preferred] == "") { return preferred; } int num = -1; for (int i = 0; i < 10; i++) { if (IsOre(cells[At(head, i)])) { num = i; } } for (int j = 1; j <= 10; j++) { int num2 = At(head, num + j); if (cells[num2] == "") { return num2; } } return -1; } private static int FirstEmpty(string[] cells, int preferred) { if (preferred >= 0 && preferred < 10 && cells[preferred] == "") { return preferred; } for (int i = 0; i < 10; i++) { if (cells[i] == "") { return i; } } return -1; } internal static void Reconcile(Smelter smelter, ZDO zdo) { Read(zdo, Scratch); bool flag = MigrateOld(zdo, Scratch); int head = Head(zdo); int queueSize = smelter.GetQueueSize(); int num = 0; bool flag2 = true; for (int i = 0; i < 10; i++) { int num2 = At(head, i); if (IsOre(Scratch[num2])) { flag2 &= num < queueSize && PrefabOf(Scratch[num2]) == SmelterState.QueuedAt(zdo, num); num++; } } if (flag2 && num == queueSize) { if (flag) { Write(zdo, Scratch); } return; } num = 0; for (int j = 0; j < 10; j++) { int num3 = At(head, j); if (IsOre(Scratch[num3])) { Scratch[num3] = ((num < queueSize) ? ("o:" + SmelterState.QueuedAt(zdo, num++)) : ""); } } while (num < queueSize) { int num4 = NextEmpty(Scratch, head, -1); if (num4 < 0) { break; } Scratch[num4] = "o:" + SmelterState.QueuedAt(zdo, num++); } Write(zdo, Scratch); } private static bool MigrateOld(ZDO zdo, string[] cells) { bool result = false; int[] array = new int[2] { OldBarsKey, OldOutputKey }; foreach (int num in array) { string text = zdo.GetString(num, ""); if (string.IsNullOrEmpty(text)) { continue; } string[] array2 = text.Split(',', ';'); foreach (string text2 in array2) { int num2 = text2.LastIndexOf(':'); string text3 = ((num2 > 0) ? text2.Substring(0, num2) : text2); int result2; int count = ((num2 <= 0 || !int.TryParse(text2.Substring(num2 + 1), out result2)) ? 1 : result2); if (text3.Length > 0) { AddBars(cells, text3, count, -1); } } zdo.Set(num, ""); result = true; } return result; } private static void Commit(Smelter smelter, ZDO zdo, string[] cells, int frontCellBefore, string frontBefore) { Write(zdo, cells); int num = Head(zdo); int num2 = 0; for (int i = 0; i < 10; i++) { int num3 = At(num, i); if (IsOre(cells[num3])) { zdo.Set("item" + num2, PrefabOf(cells[num3])); num2++; } } zdo.Set(ZDOVars.s_queued, num2, false); if (num2 == 0 && num != 0) { zdo.Set(HeadKey, 0, false); num = 0; } int num4 = FrontCell(cells, num); if (frontCellBefore >= 0 && (num4 != frontCellBefore || PrefabOf(cells[num4]) != frontBefore)) { StationStore.SaveProgress(zdo, frontBefore, smelter.GetBakeTimer()); smelter.SetBakeTimer(0f); } } private static int Front(ZDO zdo, string[] cells, out string prefab) { int num = FrontCell(cells, Head(zdo)); prefab = ((num >= 0) ? PrefabOf(cells[num]) : null); return num; } internal static void AfterQueue(Smelter smelter, ZDO zdo, string prefab) { Read(zdo, Scratch); string prefab2; int frontCellBefore = Front(zdo, Scratch, out prefab2); int num = NextEmpty(Scratch, Head(zdo), TargetCell); if (num >= 0) { Scratch[num] = "o:" + prefab; Commit(smelter, zdo, Scratch, frontCellBefore, prefab2); } } internal static void BeforeRemoveFront(Smelter smelter, ZDO zdo) { Reconcile(smelter, zdo); Read(zdo, Scratch); _smeltedCell = FrontCell(Scratch, Head(zdo)); if (_smeltedCell >= 0) { Scratch[_smeltedCell] = ""; Write(zdo, Scratch); zdo.Set(HeadKey, (FrontCell(Scratch, 0) >= 0) ? ((_smeltedCell + 1) % 10) : 0, false); } } internal static int KeepBar(ZDO zdo, string barPrefab, int stack) { Read(zdo, Scratch); int num = AddBars(Scratch, barPrefab, stack, _smeltedCell); _smeltedCell = -1; if (num < stack) { Write(zdo, Scratch); } return stack - num; } internal static void ForgetSmelted() { _smeltedCell = -1; } private static int AddBars(string[] cells, string prefab, int count, int preferred) { int num = count; if (preferred >= 0 && preferred < 10 && cells[preferred] == "" && num > 0) { cells[preferred] = Bar(prefab, 1); num--; } for (int i = 0; i < 10; i++) { if (num <= 0) { break; } if (cells[i] == "") { cells[i] = Bar(prefab, 1); num--; } } return num; } internal static int Take(Smelter smelter, ZDO zdo, int cell, string key, int amount) { Reconcile(smelter, zdo); Read(zdo, Scratch); int num = ((cell >= 0 && cell < 10 && Key(Scratch[cell]) == key) ? cell : (-1)); int num2 = 9; while (num2 >= 0 && num < 0) { if (Key(Scratch[num2]) == key) { num = num2; } num2--; } if (num < 0 || amount <= 0) { return 0; } string prefab; int frontCellBefore = Front(zdo, Scratch, out prefab); int num3 = CountOf(Scratch[num]); int num4 = Mathf.Min(num3, amount); Scratch[num] = (IsBar(Scratch[num]) ? Bar(PrefabOf(Scratch[num]), num3 - num4) : ""); Commit(smelter, zdo, Scratch, frontCellBefore, prefab); return num4; } internal static int TakeAll(Smelter smelter, ZDO zdo, string key, int max) { Reconcile(smelter, zdo); Read(zdo, Scratch); string prefab; int frontCellBefore = Front(zdo, Scratch, out prefab); int num = 0; for (int i = 0; i < 10; i++) { if (num >= max) { break; } if (!(Key(Scratch[i]) != key)) { int num2 = CountOf(Scratch[i]); int num3 = Mathf.Min(num2, max - num); Scratch[i] = (IsBar(Scratch[i]) ? Bar(PrefabOf(Scratch[i]), num2 - num3) : ""); num += num3; } } if (num > 0) { Commit(smelter, zdo, Scratch, frontCellBefore, prefab); } return num; } internal static bool Replace(Smelter smelter, ZDO zdo, int cell, string old, string prefab) { Reconcile(smelter, zdo); Read(zdo, Scratch); if (cell < 0 || cell >= 10 || Scratch[cell] != "o:" + old) { return false; } string prefab2; int frontCellBefore = Front(zdo, Scratch, out prefab2); Scratch[cell] = "o:" + prefab; Commit(smelter, zdo, Scratch, frontCellBefore, prefab2); return true; } internal static void Move(Smelter smelter, ZDO zdo, int from, string key, int to, int amount) { Reconcile(smelter, zdo); Read(zdo, Scratch); if (from < 0 || from >= 10 || to < 0 || to >= 10 || from == to || amount <= 0 || Key(Scratch[from]) != key) { return; } string prefab; int frontCellBefore = Front(zdo, Scratch, out prefab); string prefab2 = PrefabOf(key); int num = CountOf(Scratch[from]); amount = Mathf.Min(amount, num); string text = Scratch[to]; if (text == "") { Scratch[to] = (IsBar(Scratch[from]) ? Bar(prefab2, amount) : Scratch[from]); Scratch[from] = (IsBar(Scratch[from]) ? Bar(prefab2, num - amount) : ""); } else { if (amount != num || !(Key(text) != key)) { return; } Scratch[to] = Scratch[from]; Scratch[from] = text; } Commit(smelter, zdo, Scratch, frontCellBefore, prefab); } internal static bool HasEmpty(ZDO zdo) { Read(zdo, Scratch); return FirstEmpty(Scratch, -1) >= 0; } internal static void MoveBarsInto(ZDO zdo, Inventory inventory) { Read(zdo, Scratch); bool flag = false; for (int i = 0; i < 10; i++) { if (IsBar(Scratch[i])) { string text = PrefabOf(Scratch[i]); GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(text) : null); int num = CountOf(Scratch[i]); int num2 = 0; while ((Object)(object)val != (Object)null && num2 < num && inventory.CanAddItem(val, 1) && inventory.AddItem(val, 1)) { num2++; } if (num2 > 0) { Scratch[i] = Bar(text, num - num2); flag = true; } if (num2 < num) { break; } } } if (flag) { Write(zdo, Scratch); } } internal static void DropBars(Smelter smelter, ZDO zdo) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) Read(zdo, Scratch); for (int i = 0; i < 10; i++) { if (IsBar(Scratch[i])) { StationStore.DropAt(((Component)smelter).transform.position + Vector3.up, PrefabOf(Scratch[i]), CountOf(Scratch[i])); Scratch[i] = ""; } } Write(zdo, Scratch); } } internal static class StationChests { internal enum Side { Ore = 0, Fuel = 1, Bars = 2, Door = 0 } private sealed class Shape { internal Vector3 Center; internal Vector3 Half; internal Vector3 Front; internal Vector3 Right; internal Vector3 Door; } private sealed class Found { internal float Time; internal readonly Container[] Chests = (Container[])(object)new Container[4]; } private const float Gap = 0.04f; private const float SnapRange = 1.6f; private const float FindRange = 7f; private const float CacheSeconds = 1f; private static readonly Dictionary<int, Shape> Shapes = new Dictionary<int, Shape>(); private static readonly Dictionary<int, Vector3> ChestSizes = new Dictionary<int, Vector3>(); private static readonly Dictionary<Smelter, Found> Cache = new Dictionary<Smelter, Found>(); private static readonly HashSet<Smelter> Known = new HashSet<Smelter>(); private static readonly List<Smelter> Stale = new List<Smelter>(); private static readonly Collider[] Hits = (Collider[])(object)new Collider[64]; private static HashSet<int> _chestPrefabs; private static int _pieceMask; private static readonly RaycastHit[] GroundHits = (RaycastHit[])(object)new RaycastHit[16]; private static int _groundMask; private const string Yes = "<voffset=0.1em><size=35%><color=#7FD86A>✔</color></size></voffset> "; private const string No = "<voffset=0.1em><size=35%><color=#E0605A>✖</color></size></voffset> "; private const float StationSnapRange = 2.2f; private const float TurnCost = 0.6f; private static readonly Collider[] ChestHits = (Collider[])(object)new Collider[64]; private static bool Combined(Smelter smelter) { return !SmelterState.IsHandled(smelter); } private static int Sides(Smelter smelter) { if (!Combined(smelter)) { return 3; } return 1; } internal static void ResetChests() { _chestPrefabs = null; } internal static void Clear() { Cache.Clear(); Known.Clear(); } private static HashSet<int> ChestPrefabs() { if (_chestPrefabs != null) { return _chestPrefabs; } _chestPrefabs = new HashSet<int>(); string[] array = (ModConfig.Chests.Value ?? "").Split(new char[3] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text in array) { _chestPrefabs.Add(StringExtensionMethods.GetStableHashCode(text.Trim())); } return _chestPrefabs; } private static bool IsChestPrefab(string name) { if (!string.IsNullOrEmpty(name)) { return ChestPrefabs().Contains(StringExtensionMethods.GetStableHashCode(name)); } return false; } internal static void Remember(Smelter smelter) { Known.Add(smelter); } private static Bounds LocalBounds(Transform root) { //IL_000f: 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_0095: 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_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_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_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0122: 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_014e: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) int num = LayerMask.NameToLayer("piece_nonsolid"); bool flag = false; Bounds result = default(Bounds); Collider[] componentsInChildren = ((Component)root).GetComponentsInChildren<Collider>(); Bounds bounds = default(Bounds); Vector3 val7 = default(Vector3); foreach (Collider val in componentsInChildren) { if (val.isTrigger || !val.enabled || ((Component)val).gameObject.layer == num) { continue; } Collider val2 = val; BoxCollider val3 = (BoxCollider)(object)((val2 is BoxCollider) ? val2 : null); if (val3 == null) { MeshCollider val4 = (MeshCollider)(object)((val2 is MeshCollider) ? val2 : null); if (val4 == null) { SphereCollider val5 = (SphereCollider)(object)((val2 is SphereCollider) ? val2 : null); if (val5 == null) { CapsuleCollider val6 = (CapsuleCollider)(object)((val2 is CapsuleCollider) ? val2 : null); if (val6 == null) { continue; } ((Bounds)(ref bounds))..ctor(val6.center, new Vector3(val6.radius * 2f, val6.height, val6.radius * 2f)); } else { ((Bounds)(ref bounds))..ctor(val5.center, Vector3.one * val5.radius * 2f); } } else { if (!((Object)(object)val4.sharedMesh != (Object)null)) { continue; } bounds = val4.sharedMesh.bounds; } } else { ((Bounds)(ref bounds))..ctor(val3.center, val3.size); } Vector3 min = ((Bounds)(ref bounds)).min; Vector3 max = ((Bounds)(ref bounds)).max; for (int j = 0; j < 8; j++) { ((Vector3)(ref val7))..ctor(((j & 1) == 0) ? min.x : max.x, ((j & 2) == 0) ? min.y : max.y, ((j & 4) == 0) ? min.z : max.z); Vector3 val8 = root.InverseTransformPoint(((Component)val).transform.TransformPoint(val7)); if (!flag) { ((Bounds)(ref result))..ctor(val8, Vector3.zero); flag = true; } else { ((Bounds)(ref result)).Encapsulate(val8); } } } return result; } private static Shape ShapeOf(Smelter smelter, ZDO zdo) { return ShapeOf(smelter, zdo.GetPrefab()); } private static Shape ShapeOf(Smelter smelter, int key) { //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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_002d: 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_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: 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_00dd: 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_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) if (Shapes.TryGetValue(key, out var value)) { return value; } Transform transform = ((Component)smelter).transform; Bounds val = LocalBounds(transform); Vector3 val2 = (((Object)(object)smelter.m_outputPoint != (Object)null) ? transform.InverseTransformPoint(smelter.m_outputPoint.position) : Vector3.forward); Vector3 val3 = NearestSide(val2 - ((Bounds)(ref val)).center); Vector3 door = (((Object)(object)smelter.m_addOreSwitch != (Object)null) ? NearestSide(transform.InverseTransformPoint(((Component)smelter.m_addOreSwitch).transform.position) - ((Bounds)(ref val)).center) : val3); value = new Shape { Center = new Vector3(((Bounds)(ref val)).center.x, 0f, ((Bounds)(ref val)).center.z), Half = ((Bounds)(ref val)).extents, Front = val3, Right = Vector3.Cross(Vector3.up, -val3), Door = door }; Shapes[key] = value; return value; } internal static bool MirrorAlongZ(Smelter smelter, int prefabKey) { return Mathf.Abs(ShapeOf(smelter, prefabKey).Front.x) > 0.5f; } private static Vector3 NearestSide(Vector3 toward) { //IL_0000: 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_0033: 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_0022: 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) if (!(Mathf.Abs(toward.x) >= Mathf.Abs(toward.z))) { return new Vector3(0f, 0f, Mathf.Sign(toward.z)); } return new Vector3(Mathf.Sign(toward.x), 0f, 0f); } private static Vector3 Axis(Smelter smelter, Shape shape, Side side) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) return Axis(Combined(smelter), shape, side); } private static Vector3 Axis(bool combined, Shape shape, Side side) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: 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_0027: Unknown result type (might be due to invalid IL or missing references) if (combined) { return shape.Door; } return (Vector3)(side switch { Side.Ore => -shape.Right, Side.Fuel => shape.Right, _ => shape.Front, }); } private static float HalfAlong(Shape shape, Vector3 axis) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) return Mathf.Abs(axis.x) * shape.Half.x + Mathf.Abs(axis.z) * shape.Half.z; } private static Vector3 ChestSize(GameObject chest, int key) { //IL_002f: 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_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_0029: Unknown result type (might be due to invalid IL or missing references) if (!ChestSizes.TryGetValue(key, out var value)) { Bounds val = LocalBounds(chest.transform); value = ((Bounds)(ref val)).size; ChestSizes[key] = value; } return value; } private static void SlotPose(Smelter smelter, Shape shape, Side side, float chestDepth, out Vector3 position, out Quaternion rotation) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0011: 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_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_003a: 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_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: 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) Vector3 val = Axis(smelter, shape, side); Vector3 val2 = shape.Center + val * (HalfAlong(shape, val) + chestDepth / 2f + 0.04f); Transform transform = ((Component)smelter).transform; position = transform.TransformPoint(new Vector3(val2.x, 0f, val2.z)); position.y = GroundAt(smelter, position); Vector3 val3 = transform.TransformDirection(val); val3.y = 0f; rotation = Quaternion.LookRotation(((Vector3)(ref val3)).normalized, Vector3.up); } private static float GroundAt(Smelter smelter, Vector3 at) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: 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) if (_groundMask == 0) { _groundMask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "terrain" }); } int num = Physics.RaycastNonAlloc(at + Vector3.up * 1f, Vector3.down, GroundHits, 3f, _groundMask, (QueryTriggerInteraction)1); float num2 = float.MinValue; for (int i = 0; i < num; i++) { Collider collider = ((RaycastHit)(ref GroundHits[i])).collider; if (!((Object)(object)collider == (Object)null) && !((Component)collider).transform.IsChildOf(((Component)smelter).transform) && !((Object)(object)((Component)collider).GetComponentInParent<Container>() != (Object)null)) { num2 = Mathf.Max(num2, ((RaycastHit)(ref GroundHits[i])).point.y); } } if (!(num2 > float.MinValue)) { return at.y; } return num2; } internal static bool TrySlot(Smelter smelter, Side side, GameObject chestPrefab, out Vector3 position, out Quaternion rotation) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0009: 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) position = default(Vector3); rotation = default(Quaternion); ZDO val = SmelterState.Zdo(smelter); if (val == null || (Object)(object)chestPrefab == (Object)null) { return false; } float z = ChestSize(chestPrefab, StringExtensionMethods.GetStableHashCode(((Object)chestPrefab).name)).z; SlotPose(smelter, ShapeOf(smelter, val), side, z, out position, out rotation); return true; } internal static Container Attached(Smelter smelter, Side side) { ZDO val = SmelterState.Zdo(smelter); if (val == null) { return null; } if (!Cache.TryGetValue(smelter, out var value)) { value = new Found { Time = -100f }; Cache[smelter] = value; } if (Time.time - value.Time > 1f) { value.Time = Time.time; Find(smelter, val, value.Chests); } Container val2 = value.Chests[(int)side]; if (!((Object)(object)val2 != (Object)null) || !((Object)(object)val2.m_nview != (Object)null) || !val2.m_nview.IsValid()) { return null; } return val2; } private static void Find(Smelter smelter, ZDO zdo, Container[] into) { //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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_0139: 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_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016e: 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_0172: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) Array.Clear(into, 0, into.Length); if (_pieceMask == 0) { _pieceMask = LayerMask.GetMask(new string[2] { "piece", "piece_nonsolid" }); } Shape shape = ShapeOf(smelter, zdo); Transform transform = ((Component)smelter).transform; float[] array = new float[4] { float.MaxValue, float.MaxValue, float.MaxValue, float.MaxValue }; int num = Sides(smelter); Vector3 val = transform.TransformPoint(shape.Center); int num2 = Physics.OverlapSphereNonAlloc(val, Mathf.Max(shape.Half.x, shape.Half.z) + 2.5f, Hits, _pieceMask); for (int i = 0; i < num2; i++) { Container val2 = (((Object)(object)Hits[i] != (Object)null) ? ((Component)Hits[i]).GetComponentInParent<Container>() : null); ZDO val3 = (((Object)(object)val2 != (Object)null && (Object)(object)val2.m_nview != (Object)null && val2.m_nview.IsValid()) ? val2.m_nview.GetZDO() : null); if (val3 == null || !ChestPrefabs().Contains(val3.GetPrefab())) { continue; } Vector3 val4 = transform.InverseTransformPoint(((Component)val2).transform.position) - shape.Center; if (Mathf.Abs(val4.y) > 1.5f) { continue; } for (int j = 0; j < num; j++) { Vector3 val5 = Axis(smelter, shape, (Side)j); Vector3 val6 = Vector3.Cross(Vector3.up, val5); float num3 = Vector3.Dot(val4, val5) - HalfAlong(shape, val5); float num4 = Mathf.Abs(Vector3.Dot(val4, val6)); if (!(num3 < -0.3f) && !(num3 > 1.6f) && !(num4 > HalfAlong(shape, val6) + 0.2f)) { float num5 = num3 + num4; if (num5 < array[j]) { array[j] = num5; into[j] = val2; } } } } } internal static string Describe(Smelter smelter) { string text = Translations.Text("$cdev_sw_chests"); if (Combined(smelter)) { return (((Object)(object)Attached(smelter, Side.Ore) != (Object)null) ? "<voffset=0.1em><size=35%><color=#7FD86A>✔</color></size></voffset> " : "<voffset=0.1em><size=35%><color=#E0605A>✖</color></size></voffset> ") + text; } for (int i = 0; i < 3; i++) { string text2 = Translations.Text(i switch { 1 => "$cdev_sw_rolefuel", 0 => "$cdev_sw_roleore", _ => "$cdev_sw_rolebars", }); text = text + ((i == 0) ? ": " : ", ") + (((Object)(object)Attached(smelter, (Side)i) != (Object)null) ? "<voffset=0.1em><size=35%><color=#7FD86A>✔</color></size></voffset> " : "<voffset=0.1em><size=35%><color=#E0605A>✖</color></size></voffset> ") + text2; } return text; } internal static void SnapGhost(Player player) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_011d: 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_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_021e: 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_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) GameObject placementGhost = player.m_placementGhost; Piece selectedPiece = player.GetSelectedPiece(); if ((Object)(object)placementGhost == (Object)null || !placementGhost.activeSelf || (Object)(object)selectedPiece == (Object)null) { return; } if (!IsChestPrefab(((Object)((Component)selectedPiece).gameObject).name)) { Smelter component = ((Component)selectedPiece).GetComponent<Smelter>(); if ((Object)(object)component != (Object)null) { SnapStation(placementGhost, selectedPiece, component); } } else { if (Known.Count == 0) { return; } Vector3 position = placementGhost.transform.position; float num = 1.6f; Vector3 val = default(Vector3); Quaternion val2 = default(Quaternion); bool flag = false; Stale.Clear(); foreach (Smelter item in Known) { ZDO val3 = SmelterState.Zdo(item); if (val3 == null) { Stale.Add(item); continue; } Vector3 val4 = ((Component)item).transform.position - position; if (((Vector3)(ref val4)).sqrMagnitude > 49f || !SmelterState.TakesChests(item)) { continue; } Shape shape = ShapeOf(item, val3); float z = ChestSize(((Component)selectedPiece).gameObject, StringExtensionMethods.GetStableHashCode(((Object)((Component)selectedPiece).gameObject).name)).z; for (int i = 0; i < Sides(item); i++) { if (!((Object)(object)Attached(item, (Side)i) != (Object)null)) { SlotPose(item, shape, (Side)i, z, out var position2, out var rotation); Vector3 val5 = position2 - position; val5.y = 0f; if (((Vector3)(ref val5)).magnitude < num && Mathf.Abs(position2.y - position.y) < 2f) { num = ((Vector3)(ref val5)).magnitude; val = position2; val2 = rotation; flag = true; } } } } foreach (Smelter item2 in Stale) { Known.Remove(item2); Cache.Remove(item2); } if (flag) { placementGhost.transform.SetPositionAndRotation(val, val2); } } } private static void SnapStation(GameObject ghost, Piece piece, Smelter prefab) { //IL_0067: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: 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_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_03d4: Unknown result type (might be due to invalid IL or missing references) //IL_03d6: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: 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_01f5: 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_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_0278: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_028f: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_02a3: Unknown result type (might be due to invalid IL or missing references) //IL_02aa: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: 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_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02d9: 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_02ec: Unknown result type (might be due to invalid IL or missing references) //IL_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_02fe: Unknown result type (might be due to invalid IL or missing references) //IL_0301: Unknown result type (might be due to invalid IL or missing references) //IL_0317: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_0323: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) //IL_032e: Unknown result type (might be due to invalid IL or missing references) //IL_033d: Unknown result type (might be due to invalid IL or missing references) //IL_033f: Unknown result type (might be due to invalid IL or missing references) //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_0346: Unknown result type (might be due to invalid IL or missing references) //IL_0366: Unknown result type (might be due to invalid IL or missing references) //IL_036d: Unknown result type (might be due to invalid IL or missing references) //IL_0381: Unknown result type (might be due to invalid IL or missing references) //IL_038e: Unknown result type (might be due to invalid IL or missing references) //IL_0390: Unknown result type (might be due to invalid IL or missing references) //IL_0392: 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) int stableHashCode = StringExtensionMethods.GetStableHashCode(((Object)((Component)piece).gameObject).name); bool flag = SmelterState.IsHandledPrefab(stableHashCode); if ((!flag && !SmelterState.IsChestOnlyPrefab(stableHashCode)) || prefab.m_maxOre <= 0) { return; } if (_pieceMask == 0) { _pieceMask = LayerMask.GetMask(new string[2] { "piece", "piece_nonsolid" }); } bool flag2 = !flag; Shape shape = ShapeOf(prefab, stableHashCode); Vector3 position = ghost.transform.position; Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor((ghost.transform.localScale.x < 0f) ? (-1f) : 1f, 1f, (ghost.transform.localScale.z < 0f) ? (-1f) : 1f); float y = ghost.transform.eulerAngles.y; float num = 2.2f; Vector3 val2 = default(Vector3); Quaternion val3 = default(Quaternion); bool flag3 = false; int num2 = Physics.OverlapSphereNonAlloc(position, 2.2f + Mathf.Max(shape.Half.x, shape.Half.z) + 1f, ChestHits, _pieceMask); for (int i = 0; i < num2; i++) { Container val4 = (((Object)(object)ChestHits[i] != (Object)null) ? ((Component)ChestHits[i]).GetComponentInParent<Container>() : null); ZDO val5 = (((Object)(object)val4 != (Object)null && (Object)(object)val4.m_nview != (Object)null && val4.m_nview.IsValid()) ? val4.m_nview.GetZDO() : null); if (val5 == null || !ChestPrefabs().Contains(val5.GetPrefab()) || ghost.transform.IsChildOf(((Component)val4).transform) || (flag2 && FeedsOreOrTakesBars(val4))) { continue; } Transform transform = ((Component)val4).transform; float y2 = transform.eulerAngles.y; Vector3 val6 = ChestSize(((Component)val4).gameObject, val5.GetPrefab()); for (int j = 0; j < 4; j++) { float num3 = y2 + (float)j * 90f; float num4 = 0.6f * Mathf.Round(Mathf.Abs(Mathf.DeltaAngle(num3, y)) / 90f); Quaternion val7 = Quaternion.Euler(0f, num3, 0f); Vector3 val8 = val7 * new Vector3(val.x * shape.Center.x, 0f, val.z * shape.Center.z); for (int k = 0; k < (flag2 ? 1 : 3); k++) { Vector3 val9 = Axis(flag2, shape, (Side)k); Vector3 val10 = val7 * new Vector3(val.x * val9.x, 0f, val.z * val9.z); float num5 = Mathf.Abs(Vector3.Dot(val10, transform.right)) * val6.x + Mathf.Abs(Vector3.Dot(val10, transform.forward)) * val6.z; Vector3 val11 = transform.position - val10 * (HalfAlong(shape, val9) + num5 / 2f + 0.04f) - val8; val11.y = transform.position.y; Vector3 val12 = val11 - position; val12.y = 0f; float num6 = ((Vector3)(ref val12)).magnitude + num4; if (num6 < num && Mathf.Abs(val11.y - position.y) < 2f && !Occupied(val11)) { num = num6; val2 = val11; val3 = val7; flag3 = true; } } } } if (flag3) { ghost.transform.SetPositionAndRotation(val2, val3); } } private static bool FeedsOreOrTakesBars(Container chest) { foreach (Smelter item in Known) { if (!((Object)(object)item == (Object)null) && SmelterState.Zdo(item) != null && !Combined(item) && ((Object)(object)Attached(item, Side.Ore) == (Object)(object)chest || (Object)(object)Attached(item, Side.Bars) == (Object)(object)chest)) { return true; } } return false; } private static bool Occupied(Vector3 position) { //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_002f: Unknown result type (might be due to invalid IL or missing references) foreach (Smelter item in Known) { if (!((Object)(object)item == (Object)null)) { Vector3 val = ((Component)item).transform.position - position; val.y = 0f; if (((Vector3)(ref val)).sqrMagnitude < 1.44f) { return true; } } } return false; } private static Container Writable(Smelter smelter, Side side) { Container val = Attached(smelter, side); if ((Object)(object)val == (Object)null || val.IsInUse()) { return null; } if (!val.m_nview.IsOwner()) { val.m_nview.ClaimOwnership(); return null; } val.Load(); return val; } internal static void Tick(Smelter smelter, ZDO zdo) { if (Combined(smelter)) { for (int i = 0; i < Sides(smelter); i++) { Container val = Writable(smelter, (Side)i); if ((Object)(object)val != (Object)null) { FeedOre(smelter, zdo, val); FeedFuel(smelter, val); } } } else { if (SmelterState.AutoStart(zdo)) { FeedOre(smelter, zdo, Writable(smelter, Side.Ore)); FeedFuel(smelter, Writable(smelter, Side.Fuel)); } MoveKeptBars(zdo, smelter); } } private static void FeedOre(Smelter smelter, ZDO zdo, Container chest) { int num = smelter.m_maxOre - smelter.GetQueueSize() - StationCells.Bars(zdo); if (num <= 0 || (Object)(object)chest == (Object)null) { return; } Inventory inventory = chest.GetInventory(); foreach (ItemData item in inventory.GetAllItemsInGridOrder()) { if (num <= 0) { break; } object obj; if (!((Object)(object)item.m_dropPrefab != (Object)null)) { ObjectDB instance = ObjectDB.instance; obj = ((instance != null) ? instance.GetItemPrefab(item.m_shared) : null); } else { obj = item.m_dropPrefab; } GameObject val = (GameObject)obj; string text = (((Object)(object)val != (Object)null) ? ((Object)val).name : null); if (text == null || !smelter.IsItemAllowed(text)) { continue; } int num2 = Mathf.Min(num, item.m_stack); bool cheated = item.m_cheated; int num3 = 0; for (int i = 0; i < num2; i++) { int queueSize = smelter.GetQueueSize(); smelter.RPC_AddOre(0L, text, cheated); if (smelter.GetQueueSize() <= queueSize) { break; } num3++; } if (num3 > 0) { inventory.RemoveItem(item, num3); } if (num3 < num2) { break; } num -= num3; } } private static void FeedFuel(Smelter smelter, Container chest) { if ((Object)(object)chest == (Object)null || (Object)(object)smelter.m_fuelItem == (Object)null || smelter.m_maxFuel <= 0) { return; } float fuel = smelter.GetFuel(); float num = smelter.m_maxFuel - 1; int num2 = ((!(fuel > num)) ? (Mathf.FloorToInt(num - fuel) + 1) : 0); if (num2 <= 0) { return; } Inventory inventory = chest.GetInventory(); string name = smelter.m_fuelItem.m_itemData.m_shared.m_name; int num3 = inventory.CountItems(name, -1, true); int num4 = Mathf.Min(num2, num3); if (num4 <= 0) { return; } int num5 = 0; for (int i = 0; i < num4; i++) { float fuel2 = smelter.GetFuel(); smelter.RPC_AddFuel(0L); if (smelter.GetFuel() <= fuel2) { break; } num5++; } if (num5 > 0) { inventory.RemoveItem(name, num5, -1, true); } } private static void MoveKeptBars(ZDO zdo, Smelter smelter) { if (StationCells.Bars(zdo) != 0) { Container val = Writable(smelter, Side.Bars); if (!((Object)(object)val == (Object)null)) { StationCells.MoveBarsInto(zdo, val.GetInventory()); } } } internal static bool StoreProduct(Smelter smelter, string barPrefab, int stack) { GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(barPrefab) : null); if ((Object)(object)val == (Object)null) { return false; } if (!Combined(smelter)) { return Store(Writable(smelter, Side.Bars), val, stack); } for (int i = 0; i < Sides(smelter); i++) { if (Store(Writable(smelter, (Side)i), val, stack)) { return true; } } return false; } private static bool Store(Container chest, GameObject go, int stack) { Inventory val = (((Object)(object)chest != (Object)null) ? chest.GetInventory() : null); if (val != null && val.CanAddItem(go, stack)) { return val.AddItem(go, stack); } return false; } } internal static class StationMirror { private static readonly int MirrorKey = StringExtensionMethods.GetStableHashCode("cdev.smelterwindow.mirror"); internal static bool Pending; internal static bool AltHeld() { if (!ZInput.GetButton("AltPlace")) { return ZInput.GetButton("JoyAltPlace"); } return true; } private static bool Mirrorable(GameObject prefab) { if ((Object)(object)prefab != (Object)null && (Object)(object)prefab.GetComponent<Smelter>() != (Object)null) { return SmelterState.IsHandledPrefab(StringExtensionMethods.GetStableHashCode(((Object)prefab).name)); } return false; } internal static void Ghost(Player player) { GameObject placementGhost = player.m_placementGhost; Piece selectedPiece = player.GetSelectedPiece(); if (!((Object)(object)placementGhost == (Object)null) && !((Object)(object)selectedPiece == (Object)null) && Mirrorable(((Component)selectedPiece).gameObject)) { SetMirrored(placementGhost.transform, AltHeld(), StationChests.MirrorAlongZ(((Component)selectedPiece).GetComponent<Smelter>(), StringExtensionMethods.GetStableHashCode(((Object)((Component)selectedPiece).gameObject).name))); } } internal static void BeforePlace(Piece piece) { Pending = (Object)(object)piece != (Object)null && Mirrorable(((Component)piece).gameObject) && AltHeld(); } internal static void Apply(Smelter smelter) { ZDO val = SmelterState.Zdo(smelter); if (val != null) { if (Pending && smelter.m_nview.IsOwner()) { Pending = false; val.Set(MirrorKey, true); } SetMirrored(((Component)smelter).transform, val.GetBool(MirrorKey, false), StationChests.MirrorAlongZ(smelter, val.GetPrefab())); } } private static void SetMirrored(Transform t, bool mirrored, bool alongZ) { //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_0026: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) Vector3 localScale = t.localScale; float num = Mathf.Abs(localScale.x) * ((mirrored && !alongZ) ? (-1f) : 1f); float num2 = Mathf.Abs(localScale.z) * ((mirrored && alongZ) ? (-1f) : 1f); if (!Mathf.Approximately(localScale.x, num) || !Mathf.Approximately(localScale.z, num2)) { t.localScale = new Vector3(num, localScale.y, num2); } } } internal static class StationStore { private const string SavedPrefix = "cdev.smelterwindow.saved."; internal static bool KeepProduct(Smelter smelter, string ore, int stack) { //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_00b9: 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_00eb: Unknown result type (might be due to invalid IL or missing references) ZDO val = SmelterState.Zdo(smelter); if (val == null || stack <= 0 || !smelter.m_nview.IsOwner() || !SmelterState.TakesChests(smelter)) { StationCells.ForgetSmelted(); return false; } ItemConversion itemConversion = smelter.GetItemConversion(ore); if (itemConversion == null || (Object)(object)itemConversion.m_to == (Object)null) { StationCells.ForgetSmelted(); return false; } string name = ((Object)((Component)itemConversion.m_to).gameObject).name; int num = stack; if (StationChests.StoreProduct(smelter, name, stack)) { num = 0; StationCells.ForgetSmelted(); } else { if (!SmelterState.IsHandled(smelter) || !SmelterState.Keep(val)) { StationCells.ForgetSmelted(); return false; } num -= StationCells.KeepBar(val, name, stack); } smelter.m_produceEffects.Create(((Component)smelter).transform.position, ((Component)smelter).transform.rotation, (Transform)null, 1f, -1, default(ZDOID)); if (num > 0) { Transform val2 = (((Object)(object)smelter.m_outputPoint != (Object)null) ? smelter.m_outputPoint : ((Component)smelter).transform); DropAt(val2.position, name, num); } return true; } internal static bool StoreStacked(Smelter smelter, string ore) { //IL_007a: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) if (!smelter.m_spawnStack || (Object)(object)smelter.m_nview == (Object)null || !smelter.m_nview.IsValid() || !smelter.m_nview.IsOwner() || !SmelterState.TakesChests(smelter)) { return false; } ItemConversion itemConversion = smelter.GetItemConversion(ore); if (itemConversion == null || (Object)(object)itemConversion.m_to == (Object)null || !StationChests.StoreProduct(smelter, ((Object)((Component)itemConversion.m_to).gameObject).name, 1)) { return false; } smelter.m_produceEffects.Create(((Component)smelter).transform.position, ((Component)smelter).transform.rotation, (Transform)null, 1f, -1, default(ZDOID)); return true; } internal static void DropAt(Vector3 at, string prefab, int count = 1) { //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0071: 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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(prefab) : null); ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null); if ((Object)(object)val2 == (Object)null) { Plugin.Log.LogWarning((object)$"{prefab} x{count} has no item prefab - not dropped."); return; } int num = Mathf.Max(1, val2.m_itemData.m_shared.m_maxStackSize); for (int num2 = count; num2 > 0; num2 -= num) { ItemDrop component = Object.Instantiate<GameObject>(val, at + Random.insideUnitSphere * 0.3f, Quaternion.Euler(0f, (float)Random.Range(0, 360), 0f)).GetComponent<ItemDrop>(); ItemDrop.OnCreateNew(component, false); component.SetStack(Mathf.Min(num2, num)); } } private static int SavedKey(string prefab) { return StringExtensionMethods.GetStableHashCode("cdev.smelterwindow.saved." + prefab); } internal static void SaveProgress(ZDO zdo, string prefab, float seconds) { if (!string.IsNullOrEmpty(prefab) && !(seconds <= 0f)) { int num = SavedKey(prefab); zdo.Set(num, zdo.GetFloat(num, 0f) + seconds); } } internal static float