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 Producers v1.0.2
plugins/Producers.dll
Decompiled 3 weeks ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Threading; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using ItemManager; using JetBrains.Annotations; using LocalizationManager; using Microsoft.CodeAnalysis; using PieceManager; using ServerSync; using TMPro; using UnityEngine; using UnityEngine.UI; using YamlDotNet.Core; using YamlDotNet.Core.Events; using YamlDotNet.Core.ObjectPool; using YamlDotNet.Core.Tokens; using YamlDotNet.Helpers; using YamlDotNet.Serialization; using YamlDotNet.Serialization.BufferedDeserialization; using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators; using YamlDotNet.Serialization.Callbacks; using YamlDotNet.Serialization.Converters; using YamlDotNet.Serialization.EventEmitters; using YamlDotNet.Serialization.NamingConventions; using YamlDotNet.Serialization.NodeDeserializers; using YamlDotNet.Serialization.NodeTypeResolvers; using YamlDotNet.Serialization.ObjectFactories; using YamlDotNet.Serialization.ObjectGraphTraversalStrategies; using YamlDotNet.Serialization.ObjectGraphVisitors; using YamlDotNet.Serialization.Schemas; using YamlDotNet.Serialization.TypeInspectors; using YamlDotNet.Serialization.TypeResolvers; using YamlDotNet.Serialization.Utilities; using YamlDotNet.Serialization.ValueDeserializers; [assembly: Guid("E74EB49A-461D-48EA-85BC-F462D60C98C4")] [assembly: ComVisible(false)] [assembly: AssemblyTrademark("")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyProduct("Producers")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyDescription("")] [assembly: AssemblyTitle("Producers")] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: AssemblyFileVersion("1.0.2")] [assembly: AssemblyCompany("Radamanto")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.2.0")] [module: <4b62541f-711c-4dbc-8914-60b3750494a9>RefSafetyRules(11)] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [<fa85c5cb-0719-4413-95af-0e2a6dafe515>Embedded] internal sealed class <fa85c5cb-0719-4413-95af-0e2a6dafe515>EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [<fa85c5cb-0719-4413-95af-0e2a6dafe515>Embedded] [CompilerGenerated] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class <a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>NullableAttribute : Attribute { public readonly byte[] NullableFlags; public <a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public <a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [<fa85c5cb-0719-4413-95af-0e2a6dafe515>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] [CompilerGenerated] internal sealed class <70054076-705f-405c-9cc4-ae3b93d2186f>NullableContextAttribute : Attribute { public readonly byte Flag; public <70054076-705f-405c-9cc4-ae3b93d2186f>NullableContextAttribute(byte P_0) { Flag = P_0; } } [<fa85c5cb-0719-4413-95af-0e2a6dafe515>Embedded] [CompilerGenerated] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class <4b62541f-711c-4dbc-8914-60b3750494a9>RefSafetyRulesAttribute : Attribute { public readonly int Version; public <4b62541f-711c-4dbc-8914-60b3750494a9>RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Producers { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] internal sealed class RD_BeeHive : MonoBehaviour { [HarmonyPatch(typeof(Container), "GetHoverName")] [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] private static class Container_GetHoverName_Patch { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static void Postfix(Container __instance, ref string __result) { RD_BeeHive rD_BeeHive = default(RD_BeeHive); if (((Component)__instance).TryGetComponent<RD_BeeHive>(ref rD_BeeHive)) { __result = rD_BeeHive._name; } } } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] [HarmonyPatch(typeof(Container), "GetHoverText")] private static class Container_GetHoverText_Patch { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static void Postfix(Container __instance, ref string __result) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) RD_BeeHive rD_BeeHive = default(RD_BeeHive); if (!((Component)__instance).TryGetComponent<RD_BeeHive>(ref rD_BeeHive)) { return; } string text = Localization.instance.Localize(rD_BeeHive._name); string text2 = Localization.instance.Localize("[<color=yellow><b>$KEY_Use</b></color>] $piece_container_open"); if (!PrivateArea.CheckAccess(((Component)rD_BeeHive).transform.position, 0f, false, false)) { __result = Localization.instance.Localize(rD_BeeHive._name + "\n$piece_noaccess"); return; } int honeyCount = rD_BeeHive.GetHoneyCount(); Inventory val = (((Object)(object)rD_BeeHive._container != (Object)null) ? rD_BeeHive._container.GetInventory() : null); if (val == null) { __result = string.Format("{0} ({1}/{2})\n{3}\n<color=red>{4}</color>", text, honeyCount, MaxHoney, text2, Localization.instance.Localize("$ve_beehive_no_consumable")); } else if (rD_BeeHive.IsFullForProduction(val)) { __result = string.Format("{0} ({1}/{2})\n{3}\n<color=red>{4}</color>", text, honeyCount, MaxHoney, text2, Localization.instance.Localize("$ve_beehive_full")); } else if (!HasEnoughConsumableForBatch(val)) { __result = string.Format("{0} ({1}/{2})\n{3}\n<color=red>{4}</color>", text, honeyCount, MaxHoney, text2, Localization.instance.Localize("$ve_beehive_no_consumable")); } else { __result = string.Format("{0} ({1}/{2})\n{3}\n<color=orange>{4}</color>", text, honeyCount, MaxHoney, text2, Localization.instance.Localize("$ve_beehive_working")); } } } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] [HarmonyPatch(typeof(ZNetScene), "Awake")] private static class ZNetScene_Awake_Patch { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static void Postfix(ZNetScene __instance) { if ((Object)(object)__instance == (Object)null) { return; } GameObject prefab = __instance.GetPrefab("RDP_beehive"); if (Object.op_Implicit((Object)(object)prefab)) { Piece component = prefab.GetComponent<Piece>(); if ((Object)(object)component != (Object)null) { component.m_waterPiece = false; component.m_noInWater = false; component.m_groundPiece = true; } if (!Object.op_Implicit((Object)(object)prefab.GetComponent<RD_BeeHive>())) { prefab.AddComponent<RD_BeeHive>(); } } } } [HarmonyPatch(typeof(ObjectDB), "Awake")] [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] private static class ObjectDB_Awake_Patch { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static void Postfix(ObjectDB __instance) { if (!((Object)(object)__instance == (Object)null)) { GameObject itemPrefab = __instance.GetItemPrefab("Honey"); if (!Object.op_Implicit((Object)(object)itemPrefab)) { _honeyItemPrefab = null; } else { _honeyItemPrefab = itemPrefab.GetComponent<ItemDrop>(); } } } } private const string BeeHivePrefabName = "RDP_beehive"; private const string HoneyPrefabName = "Honey"; private const string TokenWorking = "$ve_beehive_working"; private const string TokenNoConsumable = "$ve_beehive_no_consumable"; private const string TokenFull = "$ve_beehive_full"; private static readonly int ZdoStartTimeHash = StringExtensionMethods.GetStableHashCode("ve_beehive_starttime"); private static readonly int ZdoAccTimeHash = StringExtensionMethods.GetStableHashCode("ve_beehive_acctime"); [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] private static ItemDrop _honeyItemPrefab; private const float MaxOfflineSeconds = 18000f; private ZNetView _nview = null; private Piece _piece = null; private Container _container = null; private string _name = "$piece_container"; private bool _productionTickRunning; private static float SecPerBatch => Mathf.Max(0.1f, ProducersPlugin.CE_BeeHive_SecPerBatch.Value); private static int ConsumablePerBatch => Mathf.Max(1, ProducersPlugin.CE_BeeHive_ConsumablePerBatch.Value); private static int HoneyPerBatch => Mathf.Max(1, ProducersPlugin.CE_BeeHive_HoneyPerBatch.Value); private static int MaxHoney => Mathf.Max(1, ProducersPlugin.CE_BeeHive_MaxHoney.Value); private static string ConsumablePrefabName { get { string text = ProducersPlugin.CE_BeeHive_ConsumablePrefab?.Value; if (string.IsNullOrWhiteSpace(text)) { return "Dandelion"; } return text.Trim(); } } private void Awake() { _nview = ((Component)this).GetComponent<ZNetView>(); _piece = ((Component)this).GetComponent<Piece>(); _container = ((Component)this).GetComponent<Container>(); if ((Object)(object)_piece != (Object)null && !string.IsNullOrEmpty(_piece.m_name)) { _name = _piece.m_name; } if (!((Object)(object)_nview == (Object)null) && _nview.IsValid() && !((Object)(object)_container == (Object)null)) { Inventory inventory = _container.GetInventory(); if (inventory != null) { InitializePlacementData(); ((MonoBehaviour)this).InvokeRepeating("UpdateOwnershipTick", 1f, 1f); } } } private void UpdateOwnershipTick() { if ((Object)(object)_nview == (Object)null || !_nview.IsValid()) { if (_productionTickRunning) { ((MonoBehaviour)this).CancelInvoke("UpdateBeeHivePersistent"); _productionTickRunning = false; } } else if (_nview.IsOwner()) { if (!_productionTickRunning) { ((MonoBehaviour)this).InvokeRepeating("UpdateBeeHivePersistent", 1f, 1f); _productionTickRunning = true; } } else if (_productionTickRunning) { ((MonoBehaviour)this).CancelInvoke("UpdateBeeHivePersistent"); _productionTickRunning = false; } } private void UpdateBeeHivePersistent() { if (!_nview.IsValid() || !_nview.IsOwner()) { return; } Inventory inventory = _container.GetInventory(); if (inventory == null) { return; } if (!CanProduceOneBatchNow(inventory)) { ResetProductionClock(); return; } double deltaTime = GetDeltaTime(); float num = GetAccumulator() + (float)deltaTime; if (num > 18000f) { num = 18000f; } int num2 = Mathf.FloorToInt(num / SecPerBatch); if (num2 <= 0) { SetAccumulator(num); return; } int num3 = 0; for (int i = 0; i < num2; i++) { if (!CanProduceOneBatchNow(inventory)) { break; } if (!TryConsumeConsumable(inventory, ConsumablePerBatch)) { break; } if (!TryAddHoney(inventory, HoneyPerBatch)) { break; } num3++; } if (num3 <= 0) { ResetProductionClock(); return; } num -= (float)num3 * SecPerBatch; if (num < 0f) { num = 0f; } if (!CanProduceOneBatchNow(inventory)) { ResetProductionClock(); } else { SetAccumulator(num); } } private bool TryAddHoney(Inventory inventory, int amount) { if ((Object)(object)_honeyItemPrefab == (Object)null) { return false; } ItemData val = _honeyItemPrefab.m_itemData.Clone(); val.m_dropPrefab = ((Component)_honeyItemPrefab).gameObject; val.m_stack = amount; val.m_quality = 1; return inventory.AddItem(val); } private static bool CanStackHoney(Inventory inventory) { foreach (ItemData allItem in inventory.GetAllItems()) { if ((Object)(object)allItem.m_dropPrefab == (Object)null || ((Object)allItem.m_dropPrefab).name != "Honey" || allItem.m_stack >= allItem.m_shared.m_maxStackSize) { continue; } return true; } return false; } private bool TryConsumeConsumable(Inventory inventory, int amountNeeded) { if (amountNeeded <= 0) { return true; } int num = amountNeeded; string consumablePrefabName = ConsumablePrefabName; foreach (ItemData item in new List<ItemData>(inventory.GetAllItems())) { if (!((Object)(object)item.m_dropPrefab == (Object)null) && !(((Object)item.m_dropPrefab).name != consumablePrefabName)) { while (item.m_stack > 0 && num > 0) { inventory.RemoveOneItem(item); num--; } if (num <= 0) { return true; } } } return false; } private static bool HasEnoughConsumableForBatch(Inventory inventory) { int num = 0; string consumablePrefabName = ConsumablePrefabName; foreach (ItemData allItem in inventory.GetAllItems()) { if (!((Object)(object)allItem.m_dropPrefab == (Object)null) && !(((Object)allItem.m_dropPrefab).name != consumablePrefabName)) { num += allItem.m_stack; if (num >= ConsumablePerBatch) { return true; } } } return false; } private bool CanProduceOneBatchNow(Inventory inventory) { if (!HasEnoughConsumableForBatch(inventory)) { return false; } int honeyCount = GetHoneyCount(); int num = Mathf.Max(0, MaxHoney - honeyCount); if (num < HoneyPerBatch) { return false; } if (!inventory.HaveEmptySlot() && !CanStackHoney(inventory)) { return false; } if ((Object)(object)_honeyItemPrefab == (Object)null) { return false; } return true; } private bool IsFullForProduction(Inventory inventory) { int honeyCount = GetHoneyCount(); int num = Mathf.Max(0, MaxHoney - honeyCount); if (num < HoneyPerBatch) { return true; } if (!inventory.HaveEmptySlot() && !CanStackHoney(inventory)) { return true; } return false; } private void ResetProductionClock() { Producers_PersistentTimer.ResetProductionClock(_nview, ZdoStartTimeHash, ZdoAccTimeHash); } private double GetDeltaTime() { return Producers_PersistentTimer.GetDeltaTime(_nview, ZdoStartTimeHash); } private float GetAccumulator() { return Producers_PersistentTimer.GetAccumulator(_nview, ZdoAccTimeHash); } private void SetAccumulator(float t) { Producers_PersistentTimer.SetAccumulator(_nview, ZdoAccTimeHash, t); } private void InitializePlacementData() { if ((Object)(object)_piece != (Object)null) { _piece.m_waterPiece = false; _piece.m_noInWater = false; _piece.m_groundPiece = true; } Producers_PersistentTimer.InitializePersistentTimer(_nview, ZdoStartTimeHash, ZdoAccTimeHash); } private int GetHoneyCount() { Inventory val = (((Object)(object)_container != (Object)null) ? _container.GetInventory() : null); if (val == null) { return 0; } int num = 0; foreach (ItemData allItem in val.GetAllItems()) { if (!((Object)(object)allItem.m_dropPrefab == (Object)null) && !(((Object)allItem.m_dropPrefab).name != "Honey")) { num += allItem.m_stack; } } return num; } } [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] internal sealed class RD_BirdHouse : MonoBehaviour { [HarmonyPatch(typeof(Container), "GetHoverName")] [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] private static class Container_GetHoverName_Patch { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static void Postfix(Container __instance, ref string __result) { RD_BirdHouse rD_BirdHouse = default(RD_BirdHouse); if (((Component)__instance).TryGetComponent<RD_BirdHouse>(ref rD_BirdHouse)) { __result = rD_BirdHouse._name; } } } [HarmonyPatch(typeof(Container), "GetHoverText")] [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] private static class Container_GetHoverText_Patch { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static void Postfix(Container __instance, ref string __result) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) RD_BirdHouse rD_BirdHouse = default(RD_BirdHouse); if (!((Component)__instance).TryGetComponent<RD_BirdHouse>(ref rD_BirdHouse)) { return; } string text = Localization.instance.Localize(rD_BirdHouse._name); string text2 = Localization.instance.Localize("[<color=yellow><b>$KEY_Use</b></color>] $piece_container_open"); if (!PrivateArea.CheckAccess(((Component)rD_BirdHouse).transform.position, 0f, false, false)) { __result = Localization.instance.Localize(rD_BirdHouse._name + "\n$piece_noaccess"); return; } int featherCount = rD_BirdHouse.GetFeatherCount(); Inventory val = (((Object)(object)rD_BirdHouse._container != (Object)null) ? rD_BirdHouse._container.GetInventory() : null); if (val == null) { __result = string.Format("{0} ({1}/{2})\n{3}\n<color=red>{4}</color>", text, featherCount, MaxFeathers, text2, Localization.instance.Localize("$ve_birdhouse_no_consumable")); } else if (rD_BirdHouse.IsFullForProduction(val)) { __result = string.Format("{0} ({1}/{2})\n{3}\n<color=red>{4}</color>", text, featherCount, MaxFeathers, text2, Localization.instance.Localize("$ve_birdhouse_full")); } else if (!HasEnoughConsumableForBatch(val)) { __result = string.Format("{0} ({1}/{2})\n{3}\n<color=red>{4}</color>", text, featherCount, MaxFeathers, text2, Localization.instance.Localize("$ve_birdhouse_no_consumable")); } else { __result = string.Format("{0} ({1}/{2})\n{3}\n<color=orange>{4}</color>", text, featherCount, MaxFeathers, text2, Localization.instance.Localize("$ve_birdhouse_working")); } } } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] [HarmonyPatch(typeof(ZNetScene), "Awake")] private static class ZNetScene_Awake_Patch { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static void Postfix(ZNetScene __instance) { if ((Object)(object)__instance == (Object)null) { return; } GameObject prefab = __instance.GetPrefab("RDP_birdhouse"); if (Object.op_Implicit((Object)(object)prefab)) { Piece component = prefab.GetComponent<Piece>(); if ((Object)(object)component != (Object)null) { component.m_waterPiece = false; component.m_noInWater = false; component.m_groundPiece = false; } if (!Object.op_Implicit((Object)(object)prefab.GetComponent<RD_BirdHouse>())) { prefab.AddComponent<RD_BirdHouse>(); } } } } [HarmonyPatch(typeof(ObjectDB), "Awake")] [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] private static class ObjectDB_Awake_Patch { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static void Postfix(ObjectDB __instance) { if (!((Object)(object)__instance == (Object)null)) { GameObject itemPrefab = __instance.GetItemPrefab("Feathers"); if (!Object.op_Implicit((Object)(object)itemPrefab)) { _featherItemPrefab = null; } else { _featherItemPrefab = itemPrefab.GetComponent<ItemDrop>(); } } } } private const string BirdHousePrefabName = "RDP_birdhouse"; private const string FeatherPrefabName = "Feathers"; private const string TokenWorking = "$ve_birdhouse_working"; private const string TokenNoConsumable = "$ve_birdhouse_no_consumable"; private const string TokenFull = "$ve_birdhouse_full"; private static readonly int ZdoStartTimeHash = StringExtensionMethods.GetStableHashCode("ve_birdhouse_starttime"); private static readonly int ZdoAccTimeHash = StringExtensionMethods.GetStableHashCode("ve_birdhouse_acctime"); [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] private static ItemDrop _featherItemPrefab; private static string _cachedConsumablesRaw = string.Empty; private static HashSet<string> _cachedConsumablePrefabNames = new HashSet<string>(StringComparer.Ordinal); private const float MaxOfflineSeconds = 18000f; private ZNetView _nview = null; private Piece _piece = null; private Container _container = null; private string _name = "$piece_container"; private bool _productionTickRunning; private static float SecPerBatch => Mathf.Max(0.1f, ProducersPlugin.CE_BirdHouse_SecPerBatch.Value); private static int ConsumablePerBatch => Mathf.Max(1, ProducersPlugin.CE_BirdHouse_ConsumablePerBatch.Value); private static int FeathersPerBatch => Mathf.Max(1, ProducersPlugin.CE_BirdHouse_FeathersPerBatch.Value); private static int MaxFeathers => Mathf.Max(1, ProducersPlugin.CE_BirdHouse_MaxFeathers.Value); private static HashSet<string> GetValidConsumablePrefabNames() { string text = ProducersPlugin.CE_BirdHouse_ConsumablePrefabs?.Value ?? string.Empty; if (string.Equals(_cachedConsumablesRaw, text, StringComparison.Ordinal)) { return _cachedConsumablePrefabNames; } _cachedConsumablesRaw = text; _cachedConsumablePrefabNames = ParseConsumablePrefabNames(text); return _cachedConsumablePrefabNames; } private static HashSet<string> ParseConsumablePrefabNames(string raw) { HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal); if (string.IsNullOrWhiteSpace(raw)) { hashSet.Add("TurnipSeeds"); return hashSet; } string[] array = raw.Split(new char[1] { ',' }); string[] array2 = array; foreach (string text in array2) { string text2 = text.Trim(); if (!string.IsNullOrWhiteSpace(text2)) { hashSet.Add(text2); if (hashSet.Count >= 5) { break; } } } if (hashSet.Count == 0) { hashSet.Add("TurnipSeeds"); } return hashSet; } private static bool IsValidConsumablePrefab(string prefabName) { if (string.IsNullOrWhiteSpace(prefabName)) { return false; } return GetValidConsumablePrefabNames().Contains(prefabName); } private static bool HasEnoughConsumableDistributed(Inventory inventory, int amountNeeded) { if (amountNeeded <= 0) { return true; } int num = 0; foreach (ItemData allItem in inventory.GetAllItems()) { if (!((Object)(object)allItem.m_dropPrefab == (Object)null) && IsValidConsumablePrefab(((Object)allItem.m_dropPrefab).name)) { num += allItem.m_stack; if (num >= amountNeeded) { return true; } } } return false; } private static bool TryConsumeConsumableDistributed(Inventory inventory, int amountNeeded) { if (amountNeeded <= 0) { return true; } int num = amountNeeded; foreach (ItemData item in new List<ItemData>(inventory.GetAllItems())) { if (!((Object)(object)item.m_dropPrefab == (Object)null) && IsValidConsumablePrefab(((Object)item.m_dropPrefab).name)) { while (item.m_stack > 0 && num > 0) { inventory.RemoveOneItem(item); num--; } if (num <= 0) { return true; } } } return false; } private void Awake() { _nview = ((Component)this).GetComponent<ZNetView>(); _piece = ((Component)this).GetComponent<Piece>(); _container = ((Component)this).GetComponent<Container>(); if ((Object)(object)_piece != (Object)null && !string.IsNullOrEmpty(_piece.m_name)) { _name = _piece.m_name; } if (!((Object)(object)_nview == (Object)null) && _nview.IsValid() && !((Object)(object)_container == (Object)null)) { Inventory inventory = _container.GetInventory(); if (inventory != null) { InitializePlacementData(); ((MonoBehaviour)this).InvokeRepeating("UpdateOwnershipTick", 1f, 1f); } } } private void UpdateOwnershipTick() { if ((Object)(object)_nview == (Object)null || !_nview.IsValid()) { if (_productionTickRunning) { ((MonoBehaviour)this).CancelInvoke("UpdateBirdHousePersistent"); _productionTickRunning = false; } } else if (_nview.IsOwner()) { if (!_productionTickRunning) { ((MonoBehaviour)this).InvokeRepeating("UpdateBirdHousePersistent", 1f, 1f); _productionTickRunning = true; } } else if (_productionTickRunning) { ((MonoBehaviour)this).CancelInvoke("UpdateBirdHousePersistent"); _productionTickRunning = false; } } private void UpdateBirdHousePersistent() { if (!_nview.IsValid() || !_nview.IsOwner()) { return; } Inventory inventory = _container.GetInventory(); if (inventory == null) { return; } if (!CanProduceOneBatchNow(inventory)) { ResetProductionClock(); return; } double deltaTime = GetDeltaTime(); float num = GetAccumulator() + (float)deltaTime; if (num > 18000f) { num = 18000f; } int num2 = Mathf.FloorToInt(num / SecPerBatch); if (num2 <= 0) { SetAccumulator(num); return; } int num3 = 0; for (int i = 0; i < num2; i++) { if (!CanProduceOneBatchNow(inventory)) { break; } if (!TryConsumeConsumableDistributed(inventory, ConsumablePerBatch)) { break; } if (!TryAddFeathers(inventory, FeathersPerBatch)) { break; } num3++; } if (num3 <= 0) { ResetProductionClock(); return; } num -= (float)num3 * SecPerBatch; if (num < 0f) { num = 0f; } if (!CanProduceOneBatchNow(inventory)) { ResetProductionClock(); } else { SetAccumulator(num); } } private bool TryAddFeathers(Inventory inventory, int amount) { if ((Object)(object)_featherItemPrefab == (Object)null) { return false; } ItemData val = _featherItemPrefab.m_itemData.Clone(); val.m_dropPrefab = ((Component)_featherItemPrefab).gameObject; val.m_stack = amount; val.m_quality = 1; return inventory.AddItem(val); } private static bool CanStackFeathers(Inventory inventory) { foreach (ItemData allItem in inventory.GetAllItems()) { if ((Object)(object)allItem.m_dropPrefab == (Object)null || ((Object)allItem.m_dropPrefab).name != "Feathers" || allItem.m_stack >= allItem.m_shared.m_maxStackSize) { continue; } return true; } return false; } private static bool HasEnoughConsumableForBatch(Inventory inventory) { return HasEnoughConsumableDistributed(inventory, ConsumablePerBatch); } private bool CanProduceOneBatchNow(Inventory inventory) { if (!HasEnoughConsumableForBatch(inventory)) { return false; } int featherCount = GetFeatherCount(); int num = Mathf.Max(0, MaxFeathers - featherCount); if (num < FeathersPerBatch) { return false; } if (!inventory.HaveEmptySlot() && !CanStackFeathers(inventory)) { return false; } if ((Object)(object)_featherItemPrefab == (Object)null) { return false; } return true; } private bool IsFullForProduction(Inventory inventory) { int featherCount = GetFeatherCount(); int num = Mathf.Max(0, MaxFeathers - featherCount); if (num < FeathersPerBatch) { return true; } if (!inventory.HaveEmptySlot() && !CanStackFeathers(inventory)) { return true; } return false; } private void ResetProductionClock() { Producers_PersistentTimer.ResetProductionClock(_nview, ZdoStartTimeHash, ZdoAccTimeHash); } private double GetDeltaTime() { return Producers_PersistentTimer.GetDeltaTime(_nview, ZdoStartTimeHash); } private float GetAccumulator() { return Producers_PersistentTimer.GetAccumulator(_nview, ZdoAccTimeHash); } private void SetAccumulator(float t) { Producers_PersistentTimer.SetAccumulator(_nview, ZdoAccTimeHash, t); } private void InitializePlacementData() { if ((Object)(object)_piece != (Object)null) { _piece.m_waterPiece = false; _piece.m_noInWater = false; _piece.m_groundPiece = false; } Producers_PersistentTimer.InitializePersistentTimer(_nview, ZdoStartTimeHash, ZdoAccTimeHash); } private int GetFeatherCount() { Inventory val = (((Object)(object)_container != (Object)null) ? _container.GetInventory() : null); if (val == null) { return 0; } int num = 0; foreach (ItemData allItem in val.GetAllItems()) { if (!((Object)(object)allItem.m_dropPrefab == (Object)null) && !(((Object)allItem.m_dropPrefab).name != "Feathers")) { num += allItem.m_stack; } } return num; } } public static class Effect_Registry { public static void RegisterEffects() { GameObject val = PrefabManager.RegisterPrefab("rd_producers", "vfx_Place_beehive_rd_producers"); GameObject val2 = PrefabManager.RegisterPrefab("rd_producers", "sfx_build_hammer_wood_rd_producers"); GameObject val3 = PrefabManager.RegisterPrefab("rd_producers", "vfx_SawDust_rd_producers"); GameObject val4 = PrefabManager.RegisterPrefab("rd_producers", "sfx_wood_destroyed_rd_producers"); } } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] internal sealed class RD_FishTrap : MonoBehaviour { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] [HarmonyPatch(typeof(Container), "GetHoverName")] private static class Container_GetHoverName_Patch { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static void Postfix(Container __instance, ref string __result) { RD_FishTrap rD_FishTrap = default(RD_FishTrap); if (((Component)__instance).TryGetComponent<RD_FishTrap>(ref rD_FishTrap)) { __result = rD_FishTrap._name; } } } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] [HarmonyPatch(typeof(Container), "GetHoverText")] private static class Container_GetHoverText_Patch { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static void Postfix(Container __instance, ref string __result) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) RD_FishTrap rD_FishTrap = default(RD_FishTrap); if (!((Component)__instance).TryGetComponent<RD_FishTrap>(ref rD_FishTrap)) { return; } string text = Localization.instance.Localize(rD_FishTrap._name); string text2 = Localization.instance.Localize("[<color=yellow><b>$KEY_Use</b></color>] $piece_container_open"); int fishCount = rD_FishTrap.GetFishCount(); if (!PrivateArea.CheckAccess(((Component)rD_FishTrap).transform.position, 0f, false, false)) { __result = Localization.instance.Localize(rD_FishTrap._name + "\n$piece_noaccess"); return; } if (!IsValidWaterPlacement(((Component)rD_FishTrap).transform.position)) { __result = string.Format("{0} ({1}/{2})\n{3}\n<color=red>{4}</color>", text, fishCount, MaxFish, text2, Localization.instance.Localize("$ve_fishtrap_invalid_water")); return; } if (!rD_FishTrap.HasConfiguredFishForPlacedBiome()) { __result = string.Format("{0} ({1}/{2})\n{3}\n<color=red>{4}</color>", text, fishCount, MaxFish, text2, Localization.instance.Localize("$ve_fishtrap_wrong_biome")); return; } Inventory val = (((Object)(object)rD_FishTrap._container != (Object)null) ? rD_FishTrap._container.GetInventory() : null); if (val != null && rD_FishTrap.IsFullForProduction(val)) { __result = string.Format("{0} ({1}/{2})\n{3}\n<color=red>{4}</color>", text, fishCount, MaxFish, text2, Localization.instance.Localize("$ve_fishtrap_full")); } else if (!rD_FishTrap.HasValidBaitForPlacedBiome()) { __result = string.Format("{0} ({1}/{2})\n{3}\n<color=red>{4}</color>", text, fishCount, MaxFish, text2, Localization.instance.Localize("$ve_fishtrap_no_bait")); } else { __result = string.Format("{0} ({1}/{2})\n{3}\n<color=orange>{4}</color>", text, fishCount, MaxFish, text2, Localization.instance.Localize("$ve_fishtrap_working")); } } } [HarmonyPatch(typeof(WearNTear), "IsWet")] [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] private static class WearNTear_IsWet_FishTrap_Patch { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static void Postfix(WearNTear __instance, ref bool __result) { if (Object.op_Implicit((Object)(object)__instance) && !(Utils.GetPrefabName(((Component)__instance).gameObject) != "RDP_fishtrap")) { __result = false; } } } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] [HarmonyPatch(typeof(ObjectDB), "Awake")] private static class ObjectDB_Awake_Patch { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static void Postfix(ObjectDB __instance) { if ((Object)(object)__instance == (Object)null) { return; } RebuildBiomeFishConfig(); BaitConversions.Clear(); Fish val = default(Fish); foreach (ItemDrop allItem in __instance.GetAllItems((ItemType)21, "")) { if (!((Component)allItem).TryGetComponent<Fish>(ref val)) { continue; } foreach (BaitSetting bait in val.m_baits) { if ((Object)(object)bait.m_bait == (Object)null) { continue; } string itemStableKey = GetItemStableKey(bait.m_bait); if (!string.IsNullOrEmpty(itemStableKey)) { if (BaitConversions.TryGetValue(itemStableKey, out var value)) { value.AddFish(allItem); } else { BaitConversions[itemStableKey] = new BaitData(allItem); } } } } } } [HarmonyPatch(typeof(ZNetScene), "Awake")] [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] private static class ZNetScene_Awake_Patch { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static void Postfix(ZNetScene __instance) { if ((Object)(object)__instance == (Object)null) { return; } GameObject prefab = __instance.GetPrefab("RDP_fishtrap"); if (Object.op_Implicit((Object)(object)prefab)) { Piece component = prefab.GetComponent<Piece>(); if ((Object)(object)component != (Object)null) { component.m_waterPiece = false; component.m_noInWater = false; component.m_groundPiece = true; } if (!Object.op_Implicit((Object)(object)prefab.GetComponent<RD_FishTrap>())) { prefab.AddComponent<RD_FishTrap>(); } } } } [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] [HarmonyPatch(typeof(Player), "UpdatePlacementGhost")] private static class Player_UpdatePlacementGhost_Patch { [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(new byte[] { 1, 1, 2 })] private static readonly FieldRef<Player, GameObject> PlacementGhostRef = AccessTools.FieldRefAccess<Player, GameObject>("m_placementGhost"); private static readonly FieldRef<Player, PlacementStatus> PlacementStatusRef = AccessTools.FieldRefAccess<Player, PlacementStatus>("m_placementStatus"); private static void Postfix(Player __instance) { //IL_007a: Unknown result type (might be due to invalid IL or missing references) GameObject val = PlacementGhostRef.Invoke(__instance); if (!Object.op_Implicit((Object)(object)val)) { return; } Piece component = val.GetComponent<Piece>(); if (!((Object)(object)component == (Object)null) && !(Utils.GetPrefabName(((Component)component).gameObject) != "RDP_fishtrap")) { if (component.m_waterPiece) { component.m_waterPiece = false; } component.m_noInWater = false; component.m_groundPiece = true; if (!IsValidWaterPlacement(val.transform.position)) { PlacementStatusRef.Invoke(__instance) = (PlacementStatus)1; component.SetInvalidPlacementHeightlight(true); } } } } [HarmonyPatch(typeof(Player), "TryPlacePiece")] [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] private static class Player_TryPlacePiece_Patch { [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(new byte[] { 1, 1, 2 })] private static readonly FieldRef<Player, GameObject> PlacementGhostRef = AccessTools.FieldRefAccess<Player, GameObject>("m_placementGhost"); [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static bool Prefix(Player __instance, Piece piece, ref bool __result) { //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_004d: 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_0060: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)piece == (Object)null) { return true; } if (Utils.GetPrefabName(((Component)piece).gameObject) != "RDP_fishtrap") { return true; } GameObject val = PlacementGhostRef.Invoke(__instance); Vector3 position = (Object.op_Implicit((Object)(object)val) ? val.transform.position : ((Component)piece).transform.position); if (IsValidWaterPlacement(position)) { return true; } piece.SetInvalidPlacementHeightlight(true); ((Character)__instance).Message((MessageType)2, Localization.instance.Localize("$ve_fishtrap_invalid_water"), 0, (Sprite)null); __result = false; return false; } } [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] private sealed class BaitData { private readonly List<ItemData> _fishes = new List<ItemData>(); public BaitData(ItemDrop fish) { AddFish(fish); } public void AddFish(ItemDrop fish) { foreach (ItemData fish2 in _fishes) { if ((Object)(object)fish2.m_dropPrefab == (Object)(object)((Component)fish).gameObject) { return; } } ItemData val = fish.m_itemData.Clone(); val.m_dropPrefab = ((Component)fish).gameObject; _fishes.Add(val); } public bool SupportsBiome(Biome biome) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) foreach (ItemData fish in _fishes) { string fishPrefabName = (((Object)(object)fish.m_dropPrefab != (Object)null) ? ((Object)fish.m_dropPrefab).name : string.Empty); if (IsFishConfiguredForBiome(fishPrefabName, biome)) { return true; } } return false; } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(2)] public ItemData GetFish(Biome biome) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) List<ItemData> list = new List<ItemData>(); foreach (ItemData fish in _fishes) { string fishPrefabName = (((Object)(object)fish.m_dropPrefab != (Object)null) ? ((Object)fish.m_dropPrefab).name : string.Empty); if (IsFishConfiguredForBiome(fishPrefabName, biome)) { list.Add(fish); } } if (list.Count <= 0) { return null; } ItemData val = list[Random.Range(0, list.Count)].Clone(); val.m_stack = 1; return val; } } private const string TrapPrefabName = "RDP_fishtrap"; private const string TokenInvalidWater = "$ve_fishtrap_invalid_water"; private const string TokenWorking = "$ve_fishtrap_working"; private const string TokenWrongBiome = "$ve_fishtrap_wrong_biome"; private const string TokenNoBait = "$ve_fishtrap_no_bait"; private const string TokenFull = "$ve_fishtrap_full"; private static readonly int ZdoPlacedBiomeHash = StringExtensionMethods.GetStableHashCode("ve_fishtrap_biome"); private static readonly int ZdoStartTimeHash = StringExtensionMethods.GetStableHashCode("ve_fishtrap_starttime"); private static readonly int ZdoAccTimeHash = StringExtensionMethods.GetStableHashCode("ve_fishtrap_acctime"); private static readonly Dictionary<string, BaitData> BaitConversions = new Dictionary<string, BaitData>(StringComparer.Ordinal); private static readonly Dictionary<Biome, HashSet<string>> ConfiguredFishByBiome = new Dictionary<Biome, HashSet<string>>(); private const float MaxOfflineSeconds = 18000f; private const float MinWaterDepth = 0.5f; private const float MaxWaterDepth = 1.5f; private ZNetView _nview = null; private Piece _piece = null; private Container _container = null; private string _name = "$piece_container"; private bool _productionTickRunning; private static float SecPerUnit => Mathf.Max(0.1f, ProducersPlugin.CE_FishTrap_SecPerUnit.Value); private static int MaxFish => Mathf.Max(1, ProducersPlugin.CE_FishTrap_MaxFish.Value); private static float ChanceToIncreaseQuality => Mathf.Clamp01(ProducersPlugin.CE_FishTrap_ChanceToIncreaseQuality.Value); private void Awake() { _nview = ((Component)this).GetComponent<ZNetView>(); _piece = ((Component)this).GetComponent<Piece>(); _container = ((Component)this).GetComponent<Container>(); if ((Object)(object)_piece != (Object)null && !string.IsNullOrEmpty(_piece.m_name)) { _name = _piece.m_name; } if (!((Object)(object)_nview == (Object)null) && _nview.IsValid() && !((Object)(object)_container == (Object)null)) { Inventory inventory = _container.GetInventory(); if (inventory != null) { InitializePlacementData(); ((MonoBehaviour)this).InvokeRepeating("UpdateOwnershipTick", 1f, 1f); } } } private void UpdateOwnershipTick() { if ((Object)(object)_nview == (Object)null || !_nview.IsValid()) { if (_productionTickRunning) { ((MonoBehaviour)this).CancelInvoke("UpdateTrapPersistent"); _productionTickRunning = false; } } else if (_nview.IsOwner()) { if (!_productionTickRunning) { ((MonoBehaviour)this).InvokeRepeating("UpdateTrapPersistent", 1f, 1f); _productionTickRunning = true; } } else if (_productionTickRunning) { ((MonoBehaviour)this).CancelInvoke("UpdateTrapPersistent"); _productionTickRunning = false; } } private void UpdateTrapPersistent() { if (!_nview.IsValid() || !_nview.IsOwner()) { return; } Inventory inventory = _container.GetInventory(); if (inventory == null) { return; } if (!CanProduceOneUnitNow(inventory)) { ResetProductionClock(); return; } double deltaTime = GetDeltaTime(); float num = GetAccumulator() + (float)deltaTime; if (num > 18000f) { num = 18000f; } int num2 = Mathf.FloorToInt(num / SecPerUnit); if (num2 <= 0) { SetAccumulator(num); return; } int num3 = 0; for (int i = 0; i < num2; i++) { if (!CanProduceOneUnitNow(inventory)) { break; } if (!TryProduceOneFish()) { break; } num3++; } if (num3 <= 0) { ResetProductionClock(); return; } num -= (float)num3 * SecPerUnit; if (num < 0f) { num = 0f; } if (!CanProduceOneUnitNow(inventory)) { ResetProductionClock(); } else { SetAccumulator(num); } } private bool TryProduceOneFish() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) Inventory inventory = _container.GetInventory(); if (inventory == null) { return false; } if ((Object)(object)ObjectDB.instance == (Object)null) { return false; } Biome placedBiome = GetPlacedBiome(); if (!TryGetBaitConversion(inventory.GetAllItems(), placedBiome, out var bait, out var data)) { return false; } if (bait == null || data == null) { return false; } ItemData fish = data.GetFish(placedBiome); if (fish == null) { return false; } fish.m_quality = RollQuality(fish); if (!inventory.AddItem(fish)) { return false; } inventory.RemoveOneItem(bait); return true; } private static int RollQuality(ItemData item) { int num = Mathf.Max(1, item.m_shared.m_maxQuality); int result = 1; for (int i = 1; i < num; i++) { if (!(Random.value <= ChanceToIncreaseQuality)) { break; } result = i + 1; } return result; } private static string GetItemStableKey(ItemData item) { if ((Object)(object)item.m_dropPrefab != (Object)null && !string.IsNullOrEmpty(((Object)item.m_dropPrefab).name)) { return ((Object)item.m_dropPrefab).name; } return string.Empty; } private static string GetItemStableKey(ItemDrop item) { if ((Object)(object)item != (Object)null && !string.IsNullOrEmpty(((Object)item).name)) { return ((Object)item).name; } return string.Empty; } private static HashSet<string> ParsePrefabList([<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] string value) { HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal); if (string.IsNullOrWhiteSpace(value)) { return hashSet; } string[] array = value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] array2 = array; foreach (string text in array2) { string text2 = text.Trim(); if (!string.IsNullOrEmpty(text2)) { hashSet.Add(text2); } } return hashSet; } private static void RebuildBiomeFishConfig() { ConfiguredFishByBiome.Clear(); ConfiguredFishByBiome[(Biome)1] = ParsePrefabList(ProducersPlugin.CE_FishTrap_Biome_Meadows.Value); ConfiguredFishByBiome[(Biome)8] = ParsePrefabList(ProducersPlugin.CE_FishTrap_Biome_BlackForest.Value); ConfiguredFishByBiome[(Biome)2] = ParsePrefabList(ProducersPlugin.CE_FishTrap_Biome_Swamp.Value); ConfiguredFishByBiome[(Biome)4] = ParsePrefabList(ProducersPlugin.CE_FishTrap_Biome_Mountain.Value); ConfiguredFishByBiome[(Biome)16] = ParsePrefabList(ProducersPlugin.CE_FishTrap_Biome_Plains.Value); ConfiguredFishByBiome[(Biome)256] = ParsePrefabList(ProducersPlugin.CE_FishTrap_Biome_Ocean.Value); ConfiguredFishByBiome[(Biome)512] = ParsePrefabList(ProducersPlugin.CE_FishTrap_Biome_Mistlands.Value); ConfiguredFishByBiome[(Biome)32] = ParsePrefabList(ProducersPlugin.CE_FishTrap_Biome_AshLands.Value); ConfiguredFishByBiome[(Biome)64] = ParsePrefabList(ProducersPlugin.CE_FishTrap_Biome_DeepNorth.Value); } private static bool IsFishConfiguredForBiome(string fishPrefabName, Biome biome) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(fishPrefabName)) { return false; } HashSet<string> value; return ConfiguredFishByBiome.TryGetValue(biome, out value) && value.Contains(fishPrefabName); } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(2)] private bool TryGetBaitConversion([<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(1)] List<ItemData> items, Biome placedBiome, out ItemData bait, out BaitData data) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) bait = null; data = null; foreach (ItemData item in items) { string itemStableKey = GetItemStableKey(item); if (string.IsNullOrEmpty(itemStableKey) || !BaitConversions.TryGetValue(itemStableKey, out var value) || !value.SupportsBiome(placedBiome)) { continue; } bait = item; data = value; return true; } return false; } private bool HasValidBaitForPlacedBiome() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) Inventory val = (((Object)(object)_container != (Object)null) ? _container.GetInventory() : null); if (val == null) { return false; } ItemData bait; BaitData data; return TryGetBaitConversion(val.GetAllItems(), GetPlacedBiome(), out bait, out data); } private bool CanProduceOneUnitNow(Inventory inventory) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) if (!IsValidWaterPlacement(((Component)this).transform.position)) { return false; } if (!HasConfiguredFishForPlacedBiome()) { return false; } if (!HasValidBaitForPlacedBiome()) { return false; } int fishCount = GetFishCount(); int num = Mathf.Max(0, MaxFish - fishCount); if (num <= 0) { return false; } if (!inventory.HaveEmptySlot()) { return false; } if ((Object)(object)ObjectDB.instance == (Object)null) { return false; } Biome placedBiome = GetPlacedBiome(); if (!TryGetBaitConversion(inventory.GetAllItems(), placedBiome, out var bait, out var data)) { return false; } if (bait == null || data == null) { return false; } return true; } private bool IsFullForProduction(Inventory inventory) { int fishCount = GetFishCount(); int num = Mathf.Max(0, MaxFish - fishCount); if (num <= 0) { return true; } if (!inventory.HaveEmptySlot()) { return true; } return false; } private double GetDeltaTime() { return Producers_PersistentTimer.GetDeltaTime(_nview, ZdoStartTimeHash); } private float GetAccumulator() { return Producers_PersistentTimer.GetAccumulator(_nview, ZdoAccTimeHash); } private void SetAccumulator(float t) { Producers_PersistentTimer.SetAccumulator(_nview, ZdoAccTimeHash, t); } private void ResetProductionClock() { Producers_PersistentTimer.ResetProductionClock(_nview, ZdoStartTimeHash, ZdoAccTimeHash); } private int GetFishCount() { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Invalid comparison between Unknown and I4 Inventory val = (((Object)(object)_container != (Object)null) ? _container.GetInventory() : null); if (val == null) { return 0; } List<ItemData> allItems = val.GetAllItems(); int num = 0; foreach (ItemData item in allItems) { if ((int)item.m_shared.m_itemType == 21) { num += item.m_stack; } } return num; } private void InitializePlacementData() { //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_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected I4, but got Unknown if ((Object)(object)_piece != (Object)null) { _piece.m_waterPiece = false; _piece.m_noInWater = false; _piece.m_groundPiece = true; } if (_nview.IsOwner()) { ZDO zDO = _nview.GetZDO(); if (zDO.GetInt(ZdoPlacedBiomeHash, 0) == 0) { Biome val = Heightmap.FindBiome(((Component)this).transform.position); zDO.Set(ZdoPlacedBiomeHash, (int)val, false); } } Producers_PersistentTimer.InitializePersistentTimer(_nview, ZdoStartTimeHash, ZdoAccTimeHash); } private static bool IsValidWaterPlacement(Vector3 position) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ZoneSystem.instance == (Object)null) { return false; } float waterLevel = ZoneSystem.instance.m_waterLevel; float num = waterLevel - position.y; if (num < 0.5f) { return false; } if (num > 1.5f) { return false; } return true; } private Biome GetPlacedBiome() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected I4, but got Unknown //IL_005c: 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_0034: 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) if ((Object)(object)_nview == (Object)null || !_nview.IsValid()) { return Heightmap.FindBiome(((Component)this).transform.position); } return (Biome)_nview.GetZDO().GetInt(ZdoPlacedBiomeHash, (int)Heightmap.FindBiome(((Component)this).transform.position)); } private bool HasConfiguredFishForPlacedBiome() { //IL_0002: 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) Biome placedBiome = GetPlacedBiome(); foreach (KeyValuePair<string, BaitData> baitConversion in BaitConversions) { if (baitConversion.Value.SupportsBiome(placedBiome)) { return true; } } return false; } } [HarmonyPatch] internal static class Producers_Haldor_BlackList { [HarmonyPatch(typeof(Trader), "GetAvailableItems")] private static class Trader_GetAvailableItems_Patch { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static bool Prefix(Trader __instance, ref List<TradeItem> __result) { if (!ProducersPlugin.CE_BlockHaldorFishingRod.Value && !ProducersPlugin.CE_BlockHaldorFishingBait.Value) { return true; } List<TradeItem> list = new List<TradeItem>(); foreach (TradeItem item in __instance.m_items) { if (item != null && !IsBlockedTraderItem(item) && (string.IsNullOrEmpty(item.m_requiredGlobalKey) || ZoneSystem.instance.GetGlobalKey(item.m_requiredGlobalKey))) { list.Add(item); } } __result = list; return false; } } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(2)] private static bool IsBlockedTraderItem(TradeItem tradeItem) { object obj; if (tradeItem == null) { obj = null; } else { ItemDrop prefab = tradeItem.m_prefab; obj = ((prefab != null) ? ((Object)prefab).name : null); } string text = (string)obj; if (text == null) { return false; } if (1 == 0) { } bool result = ((text == "FishingRod") ? ProducersPlugin.CE_BlockHaldorFishingRod.Value : (text == "FishingBait" && ProducersPlugin.CE_BlockHaldorFishingBait.Value)); if (1 == 0) { } return result; } } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] internal static class Producers_PersistentTimer { internal static double GetDeltaTime(ZNetView nview, int startTimeHash) { if ((Object)(object)nview == (Object)null || !nview.IsValid() || !nview.IsOwner() || (Object)(object)ZNet.instance == (Object)null) { return 0.0; } DateTime time = ZNet.instance.GetTime(); ZDO zDO = nview.GetZDO(); long @long = zDO.GetLong(startTimeHash, time.Ticks); DateTime dateTime = new DateTime(@long); double num = (time - dateTime).TotalSeconds; if (num < 0.0) { num = 0.0; } zDO.Set(startTimeHash, time.Ticks); return num; } internal static float GetAccumulator(ZNetView nview, int accumulatorHash) { if ((Object)(object)nview == (Object)null || !nview.IsValid()) { return 0f; } return nview.GetZDO().GetFloat(accumulatorHash, 0f); } internal static void SetAccumulator(ZNetView nview, int accumulatorHash, float value) { if (!((Object)(object)nview == (Object)null) && nview.IsValid() && nview.IsOwner()) { nview.GetZDO().Set(accumulatorHash, value); } } internal static void ResetProductionClock(ZNetView nview, int startTimeHash, int accumulatorHash) { if (!((Object)(object)nview == (Object)null) && nview.IsValid() && nview.IsOwner()) { SetAccumulator(nview, accumulatorHash, 0f); if (!((Object)(object)ZNet.instance == (Object)null)) { nview.GetZDO().Set(startTimeHash, ZNet.instance.GetTime().Ticks); } } } internal static void InitializePersistentTimer(ZNetView nview, int startTimeHash, int accumulatorHash) { if ((Object)(object)nview == (Object)null || !nview.IsValid() || !nview.IsOwner()) { return; } ZDO zDO = nview.GetZDO(); if ((Object)(object)ZNet.instance != (Object)null) { long @long = zDO.GetLong(startTimeHash, 0L); if (@long == 0) { zDO.Set(startTimeHash, ZNet.instance.GetTime().Ticks); } } float @float = zDO.GetFloat(accumulatorHash, 0f); if (@float < 0f) { zDO.Set(accumulatorHash, 0f); } } } public static class Pieces_Registry { public static void RegisterPieces() { BuildPiece buildPiece = new BuildPiece("rd_producers", "RDP_beehive"); buildPiece.Crafting.Set(PieceManager.CraftingTable.Workbench); buildPiece.Category.Set("Crafting"); buildPiece.SpecialProperties.AdminOnly = false; buildPiece.RequiredItems.Add("QueenBee", 3, recover: true); buildPiece.RequiredItems.Add("Wood", 25, recover: true); MaterialReplacer.RegisterGameObjectForShaderSwap(buildPiece.Prefab, MaterialReplacer.ShaderType.UseUnityShader); BuildPiece buildPiece2 = new BuildPiece("rd_producers", "RDP_birdhouse"); buildPiece2.Crafting.Set(PieceManager.CraftingTable.Workbench); buildPiece2.Category.Set("Crafting"); buildPiece2.SpecialProperties.AdminOnly = false; buildPiece2.RequiredItems.Add("Wood", 10, recover: true); buildPiece2.RequiredItems.Add("BronzeNails", 5, recover: true); MaterialReplacer.RegisterGameObjectForShaderSwap(buildPiece2.Prefab, MaterialReplacer.ShaderType.UseUnityShader); BuildPiece buildPiece3 = new BuildPiece("rd_producers", "RDP_fishtrap"); buildPiece3.Crafting.Set(PieceManager.CraftingTable.Workbench); buildPiece3.Category.Set("Crafting"); buildPiece3.SpecialProperties.AdminOnly = false; buildPiece3.RequiredItems.Add("RoundLog", 20, recover: true); buildPiece3.RequiredItems.Add("Resin", 20, recover: true); buildPiece3.RequiredItems.Add("BronzeNails", 10, recover: true); MaterialReplacer.RegisterGameObjectForShaderSwap(buildPiece3.Prefab, MaterialReplacer.ShaderType.UseUnityShader); } } [BepInPlugin("radamanto.Producers", "Producers", "1.0.2")] [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] public class ProducersPlugin : BaseUnityPlugin { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] private class ConfigurationManagerAttributes { public bool? Browsable = false; } [CompilerGenerated] private sealed class <ReloadConfigAfterQuietPeriod>d__45 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] private object <>2__current; public float quietSeconds; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] public ProducersPlugin <>4__this; object IEnumerator<object>.Current { [DebuggerHidden] [return: <a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] [return: <a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] get { return <>2__current; } } [DebuggerHidden] public <ReloadConfigAfterQuietPeriod>d__45(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { switch (<>1__state) { default: return false; case 0: <>1__state = -1; break; case 1: <>1__state = -1; break; } if ((DateTime.UtcNow - <>4__this._lastCfgWriteUtc).TotalSeconds < (double)quietSeconds) { <>2__current = null; <>1__state = 1; return true; } try { if (<>4__this._configWatcher == null || !<>4__this._watcherReady) { return false; } <>4__this._configWatcher.EnableRaisingEvents = false; if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer()) { ((BaseUnityPlugin)<>4__this).Config.Reload(); <>4__this._ignoreEventsUntilUtc = DateTime.UtcNow.AddSeconds(1.0); ((BaseUnityPlugin)<>4__this).Config.Save(); } } catch { } finally { if (<>4__this._configWatcher != null) { <>4__this._configWatcher.EnableRaisingEvents = true; } <>4__this._reloadScheduled = false; } return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public const string ModGUID = "radamanto.Producers"; public const string ModName = "Producers"; public const string ModVersion = "1.0.2"; private readonly Harmony _harmony = new Harmony("radamanto.Producers"); private static bool _bootstrapped; internal static ConfigEntry<float> CE_BeeHive_SecPerBatch; internal static ConfigEntry<int> CE_BeeHive_ConsumablePerBatch; internal static ConfigEntry<string> CE_BeeHive_ConsumablePrefab; internal static ConfigEntry<int> CE_BeeHive_HoneyPerBatch; internal static ConfigEntry<int> CE_BeeHive_MaxHoney; internal static ConfigEntry<float> CE_BirdHouse_SecPerBatch; internal static ConfigEntry<int> CE_BirdHouse_ConsumablePerBatch; internal static ConfigEntry<int> CE_BirdHouse_FeathersPerBatch; internal static ConfigEntry<int> CE_BirdHouse_MaxFeathers; internal static ConfigEntry<string> CE_BirdHouse_ConsumablePrefabs; internal static ConfigEntry<float> CE_FishTrap_SecPerUnit; internal static ConfigEntry<int> CE_FishTrap_MaxFish; internal static ConfigEntry<float> CE_FishTrap_ChanceToIncreaseQuality; internal static ConfigEntry<string> CE_FishTrap_Biome_Meadows; internal static ConfigEntry<string> CE_FishTrap_Biome_BlackForest; internal static ConfigEntry<string> CE_FishTrap_Biome_Swamp; internal static ConfigEntry<string> CE_FishTrap_Biome_Mountain; internal static ConfigEntry<string> CE_FishTrap_Biome_Plains; internal static ConfigEntry<string> CE_FishTrap_Biome_Ocean; internal static ConfigEntry<string> CE_FishTrap_Biome_Mistlands; internal static ConfigEntry<string> CE_FishTrap_Biome_AshLands; internal static ConfigEntry<string> CE_FishTrap_Biome_DeepNorth; internal static ConfigEntry<bool> CE_BlockVanillaBeeHive; internal static ConfigEntry<bool> CE_BlockHaldorFishingRod; internal static ConfigEntry<bool> CE_BlockHaldorFishingBait; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] internal static ConfigSync ConfigSync; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] private static ConfigEntry<bool> _serverConfigLocked; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] private FileSystemWatcher _configWatcher; private DateTime _lastCfgWriteUtc = DateTime.MinValue; private bool _reloadScheduled; private bool _watcherReady; private DateTime _ignoreEventsUntilUtc = DateTime.MinValue; private void Awake() { Localizer.Load(); if (!_bootstrapped) { _bootstrapped = true; SetupServerSyncAndWatcher(); CE_BeeHive_SecPerBatch = Cfg("02 - BeeHive", "02.01 - SecondsPerCycle", 600f, "Seconds required to complete one production cycle."); CE_BeeHive_HoneyPerBatch = Cfg("02 - BeeHive", "02.02 - HoneyPerCycle", 1, "Honey produced per production cycle."); CE_BeeHive_ConsumablePerBatch = Cfg("02 - BeeHive", "02.03 - ConsumablePerCycle", 1, "Amount of the configured consumable prefab consumed per production cycle."); CE_BeeHive_MaxHoney = Cfg("02 - BeeHive", "02.04 - MaxHoney", 250, "Maximum honey stored inside the beehive container."); CE_BeeHive_ConsumablePrefab = Cfg("02 - BeeHive", "02.05 - ConsumablePrefab", "Dandelion", "Prefab name of the item consumed by the beehive production cycle. Only 1 item is supported."); CE_BirdHouse_SecPerBatch = Cfg("03 - BirdHouse", "03.01 - SecondsPerCycle", 300f, "Seconds required to complete one production cycle."); CE_BirdHouse_FeathersPerBatch = Cfg("03 - BirdHouse", "03.02 - FeathersPerCycle", 5, "Feathers produced per production cycle."); CE_BirdHouse_ConsumablePerBatch = Cfg("03 - BirdHouse", "03.03 - ConsumablePerCycle", 1, "Amount of valid consumable items consumed per production cycle."); CE_BirdHouse_MaxFeathers = Cfg("03 - BirdHouse", "03.04 - MaxFeathers", 250, "Maximum feathers stored inside the birdhouse container."); CE_BirdHouse_ConsumablePrefabs = Cfg("03 - BirdHouse", "03.05 - ConsumablePrefabs", "TurnipSeeds,CarrotSeeds,OnionSeeds", "Prefab names of valid consumable items for the birdhouse, separated by commas. Supports up to 5 items."); CE_FishTrap_SecPerUnit = Cfg("04 - FishTrap", "04.01 - SecondsPerFish", 600f, "Seconds required to produce one fish."); CE_FishTrap_MaxFish = Cfg("04 - FishTrap", "04.02 - MaxFish", 100, "Maximum fish stored inside the trap container."); CE_FishTrap_ChanceToIncreaseQuality = Cfg("04 - FishTrap", "04.03 - ChanceToIncreaseQuality", 0.2f, "Chance to increase fish quality by one step per roll. Range: 0.0 to 1.0."); CE_FishTrap_Biome_Meadows = Cfg("04 - FishTrap", "04.04 - MeadowsFish", "Fish1,Fish2", "Fish prefabs allowed in Meadows."); CE_FishTrap_Biome_BlackForest = Cfg("04 - FishTrap", "04.05 - BlackForestFish", "Fish1,Fish2,Fish5", "Fish prefabs allowed in BlackForest."); CE_FishTrap_Biome_Swamp = Cfg("04 - FishTrap", "04.06 - SwampFish", "Fish2,Fish6", "Fish prefabs allowed in Swamp."); CE_FishTrap_Biome_Mountain = Cfg("04 - FishTrap", "04.07 - MountainFish", "Fish4_cave", "Fish prefabs allowed in Mountain."); CE_FishTrap_Biome_Plains = Cfg("04 - FishTrap", "04.08 - PlainsFish", "Fish7,Fish8", "Fish prefabs allowed in Plains."); CE_FishTrap_Biome_Ocean = Cfg("04 - FishTrap", "04.09 - OceanFish", "Fish3,Fish8,Fish12", "Fish prefabs allowed in Ocean."); CE_FishTrap_Biome_Mistlands = Cfg("04 - FishTrap", "04.10 - MistlandsFish", "Fish9,Fish12", "Fish prefabs allowed in Mistlands."); CE_FishTrap_Biome_AshLands = Cfg("04 - FishTrap", "04.11 - AshLandsFish", "Fish11,Fish12", "Fish prefabs allowed in AshLands."); CE_FishTrap_Biome_DeepNorth = Cfg("04 - FishTrap", "04.12 - DeepNorthFish", "Fish10,Fish12", "Fish prefabs allowed in DeepNorth."); CE_BlockVanillaBeeHive = Cfg("05 - Vanilla BeeHive", "05.01 - BlockVanillaBeeHive", defaultValue: true, "Disables the vanilla beehive recipe and removes it from the hammer build menu."); CE_BlockHaldorFishingRod = Cfg("06 - FishingItems", "06.01 - BlockHaldorFishingRod", defaultValue: false, "Removes Fishing Rod from Haldor shop."); CE_BlockHaldorFishingBait = Cfg("06 - FishingItems", "06.02 - BlockHaldorFishingBait", defaultValue: false, "Removes Fishing Bait from Haldor shop."); Pieces_Registry.RegisterPieces(); Effect_Registry.RegisterEffects(); _harmony.PatchAll(); } } private void OnDestroy() { _configWatcher?.Dispose(); _configWatcher = null; } public static bool IsLocalPlayerAdmin() { return ConfigSync != null && ConfigSync.IsAdmin; } public void SetupServerSyncAndWatcher() { //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Expected O, but got Unknown bool flag = false; try { ((BaseUnityPlugin)this).Config.SaveOnConfigSet = false; ConfigSync = new ConfigSync(((BaseUnityPlugin)this).Info.Metadata.GUID) { DisplayName = ((BaseUnityPlugin)this).Info.Metadata.Name, CurrentVersion = ((BaseUnityPlugin)this).Info.Metadata.Version.ToString(), MinimumRequiredVersion = ((BaseUnityPlugin)this).Info.Metadata.Version.ToString() }; _serverConfigLocked = ((BaseUnityPlugin)this).Config.Bind<bool>("01 - General", "LockConfiguration", true, new ConfigDescription("If true, the server locks synchronized configs.", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Browsable = false } })); ConfigSync.AddLockingConfigEntry<bool>(_serverConfigLocked); SetupConfigWatcher(); flag = true; } catch { } finally { ((BaseUnityPlugin)this).Config.SaveOnConfigSet = true; if (flag && (Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer()) { ((BaseUnityPlugin)this).Config.Save(); } } } protected ConfigEntry<T> Cfg<[<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] T>(string section, string key, T defaultValue, string description, bool synced = true) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown return config(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synced); } private ConfigEntry<T> config<[<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] T>(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown ConfigDescription val = new ConfigDescription(description.Description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]"), description.AcceptableValues, description.Tags); ConfigEntry<T> val2 = ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, val); try { SyncedConfigEntry<T> syncedConfigEntry = ConfigSync?.AddConfigEntry<T>(val2); if (syncedConfigEntry != null) { syncedConfigEntry.SynchronizedConfig = synchronizedSetting; } } catch { } return val2; } private void SetupConfigWatcher() { try { _configWatcher?.Dispose(); string configPath = Paths.ConfigPath; string fileName = Path.GetFileName(((BaseUnityPlugin)this).Config.ConfigFilePath); _configWatcher = new FileSystemWatcher(configPath, fileName) { IncludeSubdirectories = false, NotifyFilter = (NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite | NotifyFilters.CreationTime) }; FileSystemEventHandler onChanged = [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] (object _, FileSystemEventArgs __) => { if (!(DateTime.UtcNow < _ignoreEventsUntilUtc)) { _lastCfgWriteUtc = DateTime.UtcNow; if (!_reloadScheduled) { _reloadScheduled = true; ((MonoBehaviour)this).StartCoroutine(ReloadConfigAfterQuietPeriod(0.75f)); } } }; _configWatcher.Changed += onChanged; _configWatcher.Created += onChanged; _configWatcher.Renamed += [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] (object _, RenamedEventArgs __) => { onChanged(_, __); }; _configWatcher.EnableRaisingEvents = true; _watcherReady = true; } catch { } } [IteratorStateMachine(typeof(<ReloadConfigAfterQuietPeriod>d__45))] private IEnumerator ReloadConfigAfterQuietPeriod(float quietSeconds) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <ReloadConfigAfterQuietPeriod>d__45(0) { <>4__this = this, quietSeconds = quietSeconds }; } } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] internal static class ProducersBlockedPiecesRegistry { internal static readonly HashSet<string> BlockedPrefabs = new HashSet<string> { "piece_beehive" }; internal static bool IsBlocked(string prefab) { if (!ProducersPlugin.CE_BlockVanillaBeeHive.Value) { return false; } return !string.IsNullOrEmpty(prefab) && BlockedPrefabs.Contains(prefab); } } [HarmonyPatch(typeof(ObjectDB), "Awake")] internal static class ProducersBlockedPieces_ObjectDB_Awake_Patch { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] private static void Postfix(ObjectDB __instance) { if (!ProducersPlugin.CE_BlockVanillaBeeHive.Value || (Object)(object)__instance == (Object)null || __instance.m_recipes == null) { return; } foreach (Recipe recipe in __instance.m_recipes) { if (!((Object)(object)recipe?.m_item == (Object)null) && ProducersBlockedPiecesRegistry.IsBlocked(((Object)((Component)recipe.m_item).gameObject).name)) { recipe.m_enabled = false; recipe.m_amount = 0; recipe.m_resources = (Requirement[])(object)new Requirement[0]; } } } } [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] [HarmonyPatch(typeof(PieceTable), "UpdateAvailable")] internal static class ProducersBlockedPieces_PieceTable_UpdateAvailable_Patch { private static readonly FieldRef<PieceTable, List<List<Piece>>> AvailablePiecesRef = AccessTools.FieldRefAccess<PieceTable, List<List<Piece>>>("m_availablePieces"); private static void Postfix(PieceTable __instance) { if (!ProducersPlugin.CE_BlockVanillaBeeHive.Value || (Object)(object)__instance == (Object)null) { return; } List<List<Piece>> list = AvailablePiecesRef.Invoke(__instance); if (list == null || list.Count == 0) { return; } foreach (List<Piece> item in list) { if (item != null && item.Count != 0) { item.RemoveAll((Piece piece) => !((Object)(object)piece == (Object)null) && ProducersBlockedPiecesRegistry.IsBlocked(((Object)((Component)piece).gameObject).name)); } } } } } namespace PieceManager { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] [PublicAPI] public static class MaterialReplacer { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] public enum ShaderType { PieceShader, VegetationShader, RockShader, RugShader, GrassShader, CustomCreature, UseUnityShader } private static readonly Dictionary<GameObject, bool> ObjectToSwap; private static readonly Dictionary<string, Material> OriginalMaterials; private static readonly Dictionary<GameObject, ShaderType> ObjectsForShaderReplace; private static readonly HashSet<Shader> CachedShaders; private static bool hasRun; static MaterialReplacer() { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown CachedShaders = new HashSet<Shader>(); hasRun = false; OriginalMaterials = new Dictionary<string, Material>(); ObjectToSwap = new Dictionary<GameObject, bool>(); ObjectsForShaderReplace = new Dictionary<GameObject, ShaderType>(); Harmony val = new Harmony("org.bepinex.helpers.PieceManager"); val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ZoneSystem), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(MaterialReplacer), "ReplaceAllMaterialsWithOriginal", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } public static void RegisterGameObjectForShaderSwap(GameObject go, ShaderType type) { if (!ObjectsForShaderReplace.ContainsKey(go)) { ObjectsForShaderReplace.Add(go, type); } } public static void RegisterGameObjectForMatSwap(GameObject go, bool isJotunnMock = false) { if (!((Object)(object)go == (Object)null) && !ObjectToSwap.ContainsKey(go)) { ObjectToSwap.Add(go, isJotunnMock); } } private static void GetAllMaterials() { Material[] array = Resources.FindObjectsOfTypeAll<Material>(); foreach (Material val in array) { OriginalMaterials[((Object)val).name] = val; } } [HarmonyPriority(700)] private static void ReplaceAllMaterialsWithOriginal() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 if ((int)SystemInfo.graphicsDeviceType == 4 || hasRun) { return; } if (OriginalMaterials.Count == 0) { GetAllMaterials(); } foreach (KeyValuePair<GameObject, bool> item in ObjectToSwap) { GameObject key = item.Key; bool value = item.Value; ProcessGameObjectMaterials(key, value); } AssetBundle[] array = Resources.FindObjectsOfTypeAll<AssetBundle>(); AssetBundle[] array2 = array; foreach (AssetBundle val in array2) { IEnumerable<Shader> enumerable3; try { IEnumerable<Shader> enumerable2; if (!val.isStreamedSceneAssetBundle || !Object.op_Implicit((Object)(object)val)) { IEnumerable<Shader> enumerable = val.LoadAllAssets<Shader>(); enumerable2 = enumerable; } else { enumerable2 = from shader in ((IEnumerable<string>)val.GetAllAssetNames()).Select((Func<string, Shader>)val.LoadAsset<Shader>) where (Object)(object)shader != (Object)null select shader; } enumerable3 = enumerable2; } catch (Exception) { continue; } if (enumerable3 == null) { continue; } foreach (Shader item2 in enumerable3) { CachedShaders.Add(item2); } } foreach (KeyValuePair<GameObject, ShaderType> item3 in ObjectsForShaderReplace) { GameObject key2 = item3.Key; ShaderType value2 = item3.Value; ProcessGameObjectShaders(key2, value2); } hasRun = true; } private static void ProcessGameObjectMaterials(GameObject go, bool isJotunnMock) { Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true); Renderer[] array = componentsInChildren; foreach (Renderer val in array) { Material[] sharedMaterials = val.sharedMaterials.Select([<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] (Material material) => ((Object)(object)material == (Object)null) ? null : ReplaceMaterial(material, isJotunnMock)).ToArray(); val.sharedMaterials = sharedMaterials; } } private static Material ReplaceMaterial(Material originalMaterial, bool isJotunnMock) { if ((Object)(object)originalMaterial == (Object)null) { return null; } string text = (isJotunnMock ? "JVLmock_" : "_REPLACE_"); if (!((Object)originalMaterial).name.StartsWith(text, StringComparison.Ordinal)) { return originalMaterial; } string text2 = ((Object)originalMaterial).name.Replace(" (Instance)", "").Replace(text, ""); if (OriginalMaterials.TryGetValue(text2, out var value)) { return value; } Debug.LogWarning((object)("No suitable material found to replace: " + text2)); return originalMaterial; } private static void ProcessGameObjectShaders(GameObject go, ShaderType shaderType) { Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true); Renderer[] array = componentsInChildren; foreach (Renderer val in array) { Material[] sharedMaterials = val.sharedMaterials; foreach (Material val2 in sharedMaterials) { if ((Object)(object)val2 != (Object)null) { val2.shader = GetShaderForType(val2.shader, shaderType, ((Object)val2.shader).name); } } } } private static Shader GetShaderForType(Shader orig, ShaderType shaderType, string originalShaderName) { return (Shader)(shaderType switch { ShaderType.PieceShader => FindShaderWithName(orig, "Custom/Piece"), ShaderType.VegetationShader => FindShaderWithName(orig, "Custom/Vegetation"), ShaderType.RockShader => FindShaderWithName(orig, "Custom/StaticRock"), ShaderType.RugShader => FindShaderWithName(orig, "Custom/Rug"), ShaderType.GrassShader => FindShaderWithName(orig, "Custom/Grass"), ShaderType.CustomCreature => FindShaderWithName(orig, "Custom/Creature"), ShaderType.UseUnityShader => FindShaderWithName(orig, ((Object)(object)FindShaderWithName(orig, originalShaderName) != (Object)null) ? originalShaderName : "ToonDeferredShading2017"), _ => FindShaderWithName(orig, "Standard"), }); } public static Shader FindShaderWithName(Shader origShader, string name) { foreach (Shader cachedShader in CachedShaders) { if (((Object)cachedShader).name == name) { return cachedShader; } } return origShader; } } [PublicAPI] public enum CraftingTable { None, [InternalName("piece_workbench")] Workbench, [InternalName("piece_cauldron")] Cauldron, [InternalName("forge")] Forge, [InternalName("piece_artisanstation")] ArtisanTable, [InternalName("piece_stonecutter")] StoneCutter, [InternalName("piece_magetable")] MageTable, [InternalName("blackforge")] BlackForge, [InternalName("piece_preptable")] FoodPreparationTable, [InternalName("piece_MeadCauldron")] MeadKetill, Custom } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] public class InternalName : Attribute { public readonly string internalName; public InternalName(string internalName) { this.internalName = internalName; } } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] [PublicAPI] [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] public class ExtensionList { public readonly List<ExtensionConfig> ExtensionStations = new List<ExtensionConfig>(); public void Set(CraftingTable table, int maxStationDistance = 5) { ExtensionStations.Add(new ExtensionConfig { Table = table, maxStationDistance = maxStationDistance }); } public void Set(string customTable, int maxStationDistance = 5) { ExtensionStations.Add(new ExtensionConfig { Table = CraftingTable.Custom, custom = customTable, maxStationDistance = maxStationDistance }); } } public struct ExtensionConfig { public CraftingTable Table; public float maxStationDistance; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] public string custom; } [PublicAPI] [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] public class CraftingStationList { public readonly List<CraftingStationConfig> Stations = new List<CraftingStationConfig>(); public void Set(CraftingTable table) { Stations.Add(new CraftingStationConfig { Table = table }); } public void Set(string customTable) { Stations.Add(new CraftingStationConfig { Table = CraftingTable.Custom, custom = customTable }); } } public struct CraftingStationConfig { public CraftingTable Table; public int level; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] public string custom; } [PublicAPI] public enum BuildPieceCategory { Misc = 0, Crafting = 1, BuildingWorkbench = 2, BuildingStonecutter = 3, Furniture = 4, All = 100, Custom = 99 } [PublicAPI] [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] public class RequiredResourcesList { public readonly List<Requirement> Requirements = new List<Requirement>(); public void Add(string item, int amount, bool recover) { Requirements.Add(new Requirement { itemName = item, amount = amount, recover = recover }); } } public struct Requirement { [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(1)] public string itemName; public int amount; public bool recover; } public struct SpecialProperties { [Description("Admins should be the only ones that can build this piece.")] public bool AdminOnly; [Description("Turns off generating a config for this build piece.")] public bool NoConfig; } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] [PublicAPI] public class BuildingPieceCategory { public BuildPieceCategory Category; public string custom = ""; public void Set(BuildPieceCategory category) { Category = category; } public void Set(string customCategory) { Category = BuildPieceCategory.Custom; custom = customCategory; } } [PublicAPI] [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] public class PieceTool { public readonly HashSet<string> Tools = new HashSet<string>(); public void Add(string tool) { Tools.Add(tool); } } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(1)] [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] [PublicAPI] public class BuildPiece { [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] internal class PieceConfig { public ConfigEntry<string> craft = null; public ConfigEntry<BuildPieceCategory> category = null; public ConfigEntry<string> customCategory = null; public ConfigEntry<string> tools = null; public ConfigEntry<CraftingTable> extensionTable = null; public ConfigEntry<string> customExtentionTable = null; public ConfigEntry<float> maxStationDistance = null; public ConfigEntry<CraftingTable> table = null; public ConfigEntry<string> customTable = null; } [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] private class ConfigurationManagerAttributes { [UsedImplicitly] public int? Order; [UsedImplicitly] public bool? Browsable; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] [UsedImplicitly] public string Category; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(new byte[] { 2, 1 })] [UsedImplicitly] public Action<ConfigEntryBase> CustomDrawer; } [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] private class SerializedRequirements { public readonly List<Requirement> Reqs; public SerializedRequirements(List<Requirement> reqs) { Reqs = reqs; } public SerializedRequirements(string reqs) { Reqs = reqs.Split(new char[1] { ',' }).Select([<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] (string r) => { string[] array = r.Split(new char[1] { ':' }); Requirement result = default(Requirement); result.itemName = array[0]; result.amount = ((array.Length <= 1 || !int.TryParse(array[1], out var result2)) ? 1 : result2); bool result3 = default(bool); result.recover = array.Length <= 2 || !bool.TryParse(array[2], out result3) || result3; return result; }).ToList(); } public override string ToString() { return string.Join(",", Reqs.Select([<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] (Requirement r) => $"{r.itemName}:{r.amount}:{r.recover}")); } [return: <a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] public static ItemDrop fetchByName(ObjectDB objectDB, string name) { GameObject itemPrefab = objectDB.GetItemPrefab(name); ItemDrop val = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null); if ((Object)(object)val == (Object)null) { Debug.LogWarning((object)(((!string.IsNullOrWhiteSpace(((Object)plugin).name)) ? ("[" + ((Object)plugin).name + "]") : "") + " The required item '" + name + "' does not exist.")); } return val; } public static Requirement[] toPieceReqs(SerializedRequirements craft) { Dictionary<string, Requirement> dictionary = craft.Reqs.Where((Requirement r) => r.itemName != "").ToDictionary((Func<Requirement, string>)([<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] (Requirement r) => r.itemName), (Func<Requirement, Requirement>)([<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] (Requirement r) => { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001e: 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) ItemDrop val = ResItem(r); return (val == null) ? ((Requirement)null) : new Requirement { m_amount = r.amount, m_resItem = val, m_recover = r.recover }; })); return dictionary.Values.Where([<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] (Requirement v) => v != null).ToArray(); [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(2)] static ItemDrop ResItem(Requirement r) { return fetchByName(ObjectDB.instance, r.itemName); } } } [CompilerGenerated] private sealed class <RunQueuedSnapshots>d__33 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] private object <>2__current; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] private WaitForEndOfFrame <eof>5__1; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] private GameObject <prefab>5__2; private float <intensity>5__3; private Quaternion? <rot>5__4; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] private Exception <ex>5__5; object IEnumerator<object>.Current { [DebuggerHidden] [return: <a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] [return: <a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(0)] get { return <>2__current; } } [DebuggerHidden] public <RunQueuedSnapshots>d__33(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <eof>5__1 = null; <prefab>5__2 = null; <ex>5__5 = null; <>1__state = -2; } private bool MoveNext() { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; <eof>5__1 = new WaitForEndOfFrame(); <>2__current = <eof>5__1; <>1__state = 2; return true; case 2: <>1__state = -1; break; case 3: <>1__state = -1; if (!Application.isBatchMode && Object.op_Implicit((Object)(object)<prefab>5__2)) { try { SnapshotPiece(<prefab>5__2, <intensity>5__3, <rot>5__4); } catch (Exception ex) { <ex>5__5 = ex; Debug.LogError((object)$"[PieceManager] Snapshot failed for '{((Object)<prefab>5__2).name}': {<ex>5__5}"); } } <prefab>5__2 = null; break; } if (_snapshotQueue.Count > 0) { (GameObject, float, Quaternion?) tuple = _snapshotQueue.Dequeue(); <prefab>5__2 = tuple.Item1; <intensity>5__3 = tuple.Item2; <rot>5__4 = tuple.Item3; <>2__current = <eof>5__1; <>1__state = 3; return true; } return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } internal static readonly List<BuildPiece> registeredPieces = new List<BuildPiece>(); [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(new byte[] { 1, 0, 1 })] private static readonly Queue<(GameObject prefab, float lightIntensity, Quaternion? camRot)> _snapshotQueue = new Queue<(GameObject, float, Quaternion?)>(); private static readonly Dictionary<Piece, BuildPiece> pieceMap = new Dictionary<Piece, BuildPiece>(); internal static Dictionary<BuildPiece, PieceConfig> pieceConfigs = new Dictionary<BuildPiece, PieceConfig>(); internal List<Conversion> Conversions = new List<Conversion>(); internal List<ItemConversion> conversions = new List<ItemConversion>(); [Description("Disables generation of the configs for your pieces. This is global, this turns it off for all pieces in your mod.")] public static bool ConfigurationEnabled = true; public readonly GameObject Prefab; [Description("Specifies the resources needed to craft the piece.\nUse .Add to add resources with their internal ID and an amount.\nUse one .Add for each resource type the building piece should need.")] public readonly RequiredResourcesList RequiredItems = new RequiredResourcesList(); [Description("Sets the category for the building piece.")] public readonly BuildingPieceCategory Category = new BuildingPieceCategory(); [Description("Specifies the tool needed to build your piece.\nUse .Add to add a tool.")] public readonly PieceTool Tool = new PieceTool(); [Description("Specifies the crafting station needed to build your piece.\nUse .Add to add a crafting station, using the CraftingTable enum and a minimum level for the crafting station.")] public CraftingStationList Crafting = new CraftingStationList(); [Description("Makes this piece a station extension")] public ExtensionList Extension = new ExtensionList(); [Description("Change the extended/special properties of your build piece.")] public SpecialProperties SpecialProperties; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] [Description("Specifies a config entry which toggles whether a recipe is active.")] public ConfigEntryBase RecipeIsActive = null; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] private LocalizeKey _name; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] private LocalizeKey _description; internal string[] activeTools = null; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] private static object configManager; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] private static Localization _english; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] internal static BaseUnityPlugin _plugin = null; private static bool hasConfigSync = true; [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] private static object _configSync; public LocalizeKey Name { get { LocalizeKey name = _name; if (name != null) { return name; } Piece component = Prefab.GetComponent<Piece>(); if (component.m_name.StartsWith("$")) { _name = new LocalizeKey(component.m_name); } else { string text = "$piece_" + ((Object)Prefab).name.Replace(" ", "_"); _name = new LocalizeKey(text).English(component.m_name); component.m_name = text; } return _name; } } public LocalizeKey Description { get { LocalizeKey description = _description; if (description != null) { return description; } Piece component = Prefab.GetComponent<Piece>(); if (component.m_description.StartsWith("$")) { _description = new LocalizeKey(component.m_description); } else { string text = "$piece_" + ((Object)Prefab).name.Replace(" ", "_") + "_description"; _description = new LocalizeKey(text).English(component.m_description); component.m_description = text; } return _description; } } private static Localization english => _english ?? (_english = LocalizationCache.ForLanguage("English")); internal static BaseUnityPlugin plugin { get { //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Expected O, but got Unknown if (_plugin != null) { return _plugin; } IEnumerable<TypeInfo> source; try { source = Assembly.GetExecutingAssembly().DefinedTypes.ToList(); } catch (ReflectionTypeLoadException ex) { source = from t in ex.Types where t != null select t.GetTypeInfo(); } _plugin = (BaseUnityPlugin)Chainloader.ManagerObject.GetComponent((Type)source.First([<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] (TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t))); return _plugin; } } [<a1a7462b-57a9-4c1a-8ab8-e1420c1ee06b>Nullable(2)] private static object configSync { [<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(2)] get { if (_configSync != null || !hasConfigSync) { return _configSync; } Type type = Assembly.GetExecutingAssembly().GetType("ServerSync.ConfigSync"); if ((object)type != null) { _configSync = Activator.CreateInstance(type, plugin.Info.Metadata.GUID + " PieceManager"); type.GetField("CurrentVersion").SetValue(_configSync, plugin.Info.Metadata.Version.ToString()); type.GetProperty("IsLocked").SetValue(_configSync, true); } else { hasConfigSync = false; } return _configSync; } } public BuildPiece(string assetBundleFileName, string prefabName, string folderName = "assets") : this(PiecePrefabManager.RegisterAssetBundle(assetBundleFileName, folderName), prefabName) { } public BuildPiece(AssetBundle bundle, string prefabName) { Prefab = PiecePrefabManager.RegisterPrefab(bundle, prefabName); registeredPieces.Add(this); } internal static void Patch_FejdStartup(FejdStartup __instance) { //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: 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_02e1: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Expected O, but got Unknown //IL_0389: Unknown result type (might be due to invalid IL or missing references) //IL_0393: Expected O, but got Unknown //IL_0431: Unknown result type (might be due to invalid IL or missing references) //IL_040b: Unknown result type (might be due to invalid IL or missing references) //IL_0410: Unknown result type (might be due to invalid IL or missing references) //IL_048c: Unknown result type (might be due to invalid IL or missing references) //IL_0496: Expected O, but got Unknown //IL_0606: Unknown result type (might be due to invalid IL or missing references) //IL_0610: Expected O, but got Unknown //IL_08ea: Unknown result type (might be due to invalid IL or missing references) //IL_08f4: Expected O, but got Unknown //IL_067b: Unknown result type (might be due to invalid IL or missing references) //IL_0685: Expected O, but got Unknown //IL_0721: Unknown result type (might be due to invalid IL or missing references) //IL_072b: Expected O, but got Unknown //IL_095f: Unknown result type (might be due to invalid IL or missing references) //IL_0969: Expected O, but got Unknown //IL_0b7e: Unknown result type (might be due to invalid IL or missing references) //IL_0b88: Expected O, but got Unknown //IL_0c18: Unknown result type (might be due to invalid IL or missing references) //IL_0c22: Expected O, but got Unknown Type configManagerType = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault([<70054076-705f-405c-9cc4-ae3b93d2186f>NullableContext(0)] (Assembly a) => a.GetName().Name == "ConfigurationManager")?.GetType("ConfigurationManager.ConfigurationManager"); configManager = ((configManagerType == null) ? null : Chainloader.ManagerObject.GetComponent(configManagerType)); foreach (BuildPiece registeredPiece in registeredPieces) { registeredPiece.activeTools = registeredPiece.Tool.Tools.DefaultIfEmpty("Hammer").ToArray(); if (registeredPiece.Category.Category != BuildPieceCategory.Custom) { registeredPiece.Prefab.GetComponent<Piece>().m_category = (PieceCategory)registeredPiece.Category.Category; } else { registeredPiece.Prefab.GetComponent<Piece>().m_category = PiecePrefabManager.GetCategory(registeredPiece.Category.custom); } } if (!ConfigurationEnabled) { return; } bool saveOnConfigSet = plugin.Config.SaveOnConfigSet; plugin.Config.SaveOnConfigSet = false; foreach (BuildPiece registeredPiece2 in registeredPieces) { BuildPiece piece = registeredPiece2; if (piece.SpecialProperties.NoConfig) { continue; } PieceConfig pieceConfig2 = (pieceConfigs[piece] = new PieceConfig()); PieceConfig cfg = pieceConfig2; Piece piecePrefab2