Decompiled source of MarketStall v1.0.6
MarketStall.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.Cryptography; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Threading; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using JetBrains.Annotations; using MarketStall.Managers; using MarketStall.MarketStall; using MarketStall.UI; using MarketStall.Utility; using Microsoft.CodeAnalysis; using PieceManager; using ServerSync; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; using YamlDotNet.Core; using YamlDotNet.Core.Events; 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: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("MarketStall")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyProduct("MarketStall")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("E0E2F92E-557C-4A05-9D89-AA92A0BD75C4")] [assembly: AssemblyFileVersion("1.0.6")] [assembly: AssemblyCompany("RustyMods")] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.6.0")] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [<b3af0bd9-6bc7-4469-9902-b0856d22fd5e>Embedded] internal sealed class <b3af0bd9-6bc7-4469-9902-b0856d22fd5e>EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [<b3af0bd9-6bc7-4469-9902-b0856d22fd5e>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class <1bf4d302-402c-47c4-8f96-a8d71031beb7>NullableAttribute : Attribute { public readonly byte[] NullableFlags; public <1bf4d302-402c-47c4-8f96-a8d71031beb7>NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public <1bf4d302-402c-47c4-8f96-a8d71031beb7>NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] [CompilerGenerated] [<b3af0bd9-6bc7-4469-9902-b0856d22fd5e>Embedded] internal sealed class <b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContextAttribute : Attribute { public readonly byte Flag; public <b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace PieceManager { [PublicAPI] [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] public static class MaterialReplacer { [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>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 (!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([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (Material material) => ReplaceMaterial(material, isJotunnMock)).ToArray(); val.sharedMaterials = sharedMaterials; } } private static Material ReplaceMaterial(Material originalMaterial, bool isJotunnMock) { 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; } } } namespace MarketStall { [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] [BepInPlugin("RustyMods.MarketStall", "MarketStall", "1.0.6")] public class MarketStallPlugin : BaseUnityPlugin { [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] public enum Toggle { On = 1, Off = 0 } [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] public enum MessageColor { White, Orange, Yellow, Red, Green } [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] private class ConfigurationManagerAttributes { [UsedImplicitly] public int? Order = null; [UsedImplicitly] public bool? Browsable = null; [UsedImplicitly] [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] public string Category = null; [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(new byte[] { 2, 1 })] [UsedImplicitly] public Action<ConfigEntryBase> CustomDrawer = null; } [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] private class AcceptableShortcuts : AcceptableValueBase { public AcceptableShortcuts() : base(typeof(KeyboardShortcut)) { } public override object Clamp(object value) { return value; } public override bool IsValid(object value) { return true; } public override string ToDescriptionString() { return "# Acceptable values: " + string.Join(", ", UnityInput.Current.SupportedKeyCodes); } } internal const string ModName = "MarketStall"; internal const string ModVersion = "1.0.6"; internal const string Author = "RustyMods"; private const string ModGUID = "RustyMods.MarketStall"; private static string ConfigFileName = "RustyMods.MarketStall.cfg"; private static string ConfigFileFullPath; internal static string ConnectionError; private readonly Harmony _harmony = new Harmony("RustyMods.MarketStall"); public static readonly ManualLogSource MarketStallLogger; public static readonly ConfigSync ConfigSync; private static ConfigEntry<Toggle> _serverConfigLocked; public static ConfigEntry<string> _Currency; public static ConfigEntry<int> _MaxSales; public static ConfigEntry<Toggle> _UseSalesTax; public static ConfigEntry<float> _Fee; public static ConfigEntry<int> _MinimumFee; public static ConfigEntry<Toggle> _TransparentBackground; public static ConfigEntry<int> _MessageIncrement; public static ConfigEntry<MessageColor> _MessageColor; public void Awake() { Localizer.Load(); InitConfigs(); LoadAssets.InitAssetBundle(); MarketStallPieces.InitPieces(); Assembly executingAssembly = Assembly.GetExecutingAssembly(); _harmony.PatchAll(executingAssembly); SetupWatcher(); } public void Update() { Patches.UpdateMarketGUI(); } private void OnDestroy() { ((BaseUnityPlugin)this).Config.Save(); } private void InitConfigs() { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Expected O, but got Unknown //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Expected O, but got Unknown //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Expected O, but got Unknown //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Expected O, but got Unknown _serverConfigLocked = config("1 - General", "Lock Configuration", Toggle.On, "If on, the configuration is locked and can be changed by server admins only."); ConfigSync.AddLockingConfigEntry<Toggle>(_serverConfigLocked); _Currency = config("2 - Settings", "Currency", "Coins", "Set the prefab name of the currency. ex: Coins"); _MaxSales = config("2 - Settings", "Max Sales", 20, new ConfigDescription("Amount of items allowed to put up for sale at the same time", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 200), Array.Empty<object>())); _UseSalesTax = config("3 - Sales Tax", "Enabled", Toggle.On, "If on, sales tax is applied to market"); _Fee = config("3 - Sales Tax", "Fee Percentage", 5f, new ConfigDescription("Set the selling fee, a percentage added to the total cost", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); _MinimumFee = config("3 - Sales Tax", "Minimum Fee", 1, new ConfigDescription("Minimum required fee to put an item up for sale", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 200), Array.Empty<object>())); _TransparentBackground = config("1 - General", "Transparent Background", Toggle.Off, "If on, market background is transparent"); _MessageIncrement = config("1 - General", "Message Position", 20, new ConfigDescription("Set the position of heads up message, higher number lowers placement", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 40), Array.Empty<object>()), synchronizedSetting: false); _MessageColor = config("1 - General", "Message Color", MessageColor.Orange, "Set the color of the pop-up message", synchronizedSetting: false); } private void SetupWatcher() { FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName); fileSystemWatcher.Changed += ReadConfigValues; fileSystemWatcher.Created += ReadConfigValues; fileSystemWatcher.Renamed += ReadConfigValues; fileSystemWatcher.IncludeSubdirectories = true; fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject; fileSystemWatcher.EnableRaisingEvents = true; } private void ReadConfigValues(object sender, FileSystemEventArgs e) { if (!File.Exists(ConfigFileFullPath)) { return; } try { MarketStallLogger.LogDebug((object)"ReadConfigValues called"); ((BaseUnityPlugin)this).Config.Reload(); } catch { MarketStallLogger.LogError((object)("There was an issue loading your " + ConfigFileName)); MarketStallLogger.LogError((object)"Please check your config entries for spelling and format!"); } } private ConfigEntry<T> config<[<1bf4d302-402c-47c4-8f96-a8d71031beb7>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); SyncedConfigEntry<T> syncedConfigEntry = ConfigSync.AddConfigEntry<T>(val2); syncedConfigEntry.SynchronizedConfig = synchronizedSetting; return val2; } private ConfigEntry<T> config<[<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] T>(string group, string name, T value, string description, bool synchronizedSetting = true) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting); } static MarketStallPlugin() { string configPath = Paths.ConfigPath; char directorySeparatorChar = Path.DirectorySeparatorChar; ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName; ConnectionError = ""; MarketStallLogger = Logger.CreateLogSource("MarketStall"); ConfigSync = new ConfigSync("RustyMods.MarketStall") { DisplayName = "MarketStall", CurrentVersion = "1.0.6", MinimumRequiredVersion = "1.0.6" }; _serverConfigLocked = null; _Currency = null; _MaxSales = null; _UseSalesTax = null; _Fee = null; _MinimumFee = null; _TransparentBackground = null; _MessageIncrement = null; _MessageColor = null; } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] public static class RegisterAndCheckVersion { [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] private static void Prefix(ZNetPeer peer, ref ZNet __instance) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown MarketStallPlugin.MarketStallLogger.LogDebug((object)"Registering version RPC handler"); peer.m_rpc.Register<ZPackage>("MarketStall_VersionCheck", (Action<ZRpc, ZPackage>)RpcHandlers.RPC_MarketStall_Version); MarketStallPlugin.MarketStallLogger.LogInfo((object)"Invoking version check"); ZPackage val = new ZPackage(); val.Write("1.0.6"); val.Write(RpcHandlers.ComputeHashForMod().Replace("-", "")); peer.m_rpc.Invoke("MarketStall_VersionCheck", new object[1] { val }); } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] public static class VerifyClient { private static bool Prefix(ZRpc rpc, ZPackage pkg, ref ZNet __instance) { if (!__instance.IsServer() || RpcHandlers.ValidatedPeers.Contains(rpc)) { return true; } MarketStallPlugin.MarketStallLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") never sent version or couldn't due to previous disconnect, disconnecting")); rpc.Invoke("Error", new object[1] { 3 }); return false; } private static void Postfix(ZNet __instance) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "MarketStallRequestAdminSync", new object[1] { (object)new ZPackage() }); } } [HarmonyPatch(typeof(FejdStartup), "ShowConnectError")] public class ShowConnectionError { [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] private static void Postfix(FejdStartup __instance) { if (__instance.m_connectionFailedPanel.activeSelf) { __instance.m_connectionFailedError.fontSizeMax = 25f; __instance.m_connectionFailedError.fontSizeMin = 15f; TMP_Text connectionFailedError = __instance.m_connectionFailedError; connectionFailedError.text = connectionFailedError.text + "\n" + MarketStallPlugin.ConnectionError; } } } [HarmonyPatch(typeof(ZNet), "Disconnect")] public static class RemoveDisconnectedPeerFromVerified { [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] private static void Prefix(ZNetPeer peer, ref ZNet __instance) { if (__instance.IsServer()) { MarketStallPlugin.MarketStallLogger.LogInfo((object)("Peer (" + peer.m_rpc.m_socket.GetHostName() + ") disconnected, removing from validated list")); RpcHandlers.ValidatedPeers.Remove(peer.m_rpc); } } } [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] public static class RpcHandlers { public static readonly List<ZRpc> ValidatedPeers = new List<ZRpc>(); public static void RPC_MarketStall_Version(ZRpc rpc, ZPackage pkg) { string text = pkg.ReadString(); string text2 = pkg.ReadString(); string text3 = ComputeHashForMod().Replace("-", ""); MarketStallPlugin.MarketStallLogger.LogInfo((object)("Version check, local: 1.0.6, remote: " + text)); if (text2 != text3 || text != "1.0.6") { MarketStallPlugin.ConnectionError = "MarketStall Installed: 1.0.6 " + text3 + "\n Needed: " + text + " " + text2; if (ZNet.instance.IsServer()) { MarketStallPlugin.MarketStallLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") has incompatible version, disconnecting...")); rpc.Invoke("Error", new object[1] { 3 }); } } else if (!ZNet.instance.IsServer()) { MarketStallPlugin.MarketStallLogger.LogInfo((object)"Received same version from server!"); } else { MarketStallPlugin.MarketStallLogger.LogInfo((object)("Adding peer (" + rpc.m_socket.GetHostName() + ") to validated list")); ValidatedPeers.Add(rpc); } } public static string ComputeHashForMod() { using SHA256 sHA = SHA256.Create(); byte[] array = sHA.ComputeHash(File.ReadAllBytes(Assembly.GetExecutingAssembly().Location)); StringBuilder stringBuilder = new StringBuilder(); byte[] array2 = array; foreach (byte b in array2) { stringBuilder.Append(b.ToString("X2")); } return stringBuilder.ToString(); } } } namespace MarketStall.Utility { [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] public static class LoadAssets { public static AssetBundle _assets; public static void InitAssetBundle() { _assets = GetAssetBundle("marketstallbundle2"); } private static AssetBundle GetAssetBundle(string fileName) { Assembly executingAssembly = Assembly.GetExecutingAssembly(); string name = executingAssembly.GetManifestResourceNames().Single([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (string str) => str.EndsWith(fileName)); using Stream stream = executingAssembly.GetManifestResourceStream(name); return AssetBundle.LoadFromStream(stream); } } [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] public static class Methods { private static GameObject Coins; public static GameObject TryGetPrefab(string input, string defaultItem = "Coins") { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(input); if (Object.op_Implicit((Object)(object)itemPrefab)) { return itemPrefab; } if (!Object.op_Implicit((Object)(object)Coins)) { Coins = ObjectDB.instance.GetItemPrefab(defaultItem); } return Coins; } public static void ShowMessage(Humanoid player, string message, [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] Sprite sprite = null) { ((Character)player).Message((MessageType)2, new string('\n', MarketStallPlugin._MessageIncrement.Value) + "<color=" + GetColor(MarketStallPlugin._MessageColor.Value) + ">" + Localization.instance.Localize(message) + "</color>", 0, sprite); } private static string GetColor(MarketStallPlugin.MessageColor color) { if (1 == 0) { } string result = color switch { MarketStallPlugin.MessageColor.White => "white", MarketStallPlugin.MessageColor.Orange => "orange", MarketStallPlugin.MessageColor.Red => "red", MarketStallPlugin.MessageColor.Green => "green", MarketStallPlugin.MessageColor.Yellow => "yellow", _ => "white", }; if (1 == 0) { } return result; } } public static class Patches { [HarmonyPatch(typeof(Piece), "DropResources")] private static class MarketStallDropResources { [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] private static void Postfix(Piece __instance) { if (!Object.op_Implicit((Object)(object)__instance) || ((Object)__instance).name.Replace("(Clone)", "") != "MarketStall") { return; } List<MarketData.MarketTradeItem> marketData = Market.GetMarketData(__instance.m_nview); int @int = __instance.m_nview.GetZDO().GetInt(Market._MarketValue, 0); GameObject val = Methods.TryGetPrefab(MarketStallPlugin._Currency.Value); int maxStackSize = val.GetComponent<ItemDrop>().m_itemData.m_shared.m_maxStackSize; int num = @int; while (num > 0) { if (num > maxStackSize) { marketData.Add(new MarketData.MarketTradeItem { m_prefab = ((Object)val).name, m_price = 0, m_currency = "", m_stack = maxStackSize, m_quality = 1, m_crafter = "" }); num -= maxStackSize; } else { marketData.Add(new MarketData.MarketTradeItem { m_prefab = ((Object)val).name, m_price = 0, m_currency = "", m_stack = num, m_quality = 1, m_crafter = "" }); num = 0; } } if (marketData.Count <= 0 || (Object)(object)CacheAssets.CargoCrate == (Object)null) { return; } if (marketData.Count > 4) { int num2 = Mathf.CeilToInt((float)marketData.Count / 4f); for (int i = 0; i < num2; i++) { SpawnCargoCrate(marketData, __instance, i); } } else { SpawnCargoCrate(marketData, __instance); } } } [HarmonyPatch(typeof(Player), "OnInventoryChanged")] private static class OnInventoryChangePatch { [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] private static void Postfix(Player __instance) { if (Marketplace.IsMarketVisible() && Marketplace.MarketTypeIs != 0) { Marketplace.UpdateSellMarket(Marketplace.CurrentMarket, (Humanoid)(object)__instance); } } } [HarmonyPatch(typeof(TextInput), "IsVisible")] private static class TextInputIsVisiblePatch { [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] private static void Postfix(TextInput __instance, ref bool __result) { if (Object.op_Implicit((Object)(object)__instance)) { __result |= Marketplace.IsMarketVisible(); } } } [HarmonyPatch(typeof(StoreGui), "IsVisible")] private static class StoreGUIIsVisiblePatch { private static void Postfix(ref bool __result) { __result |= Marketplace.IsMarketVisible(); } } [HarmonyPatch(typeof(InventoryGui), "Hide")] private static class InventoryGUIHidePatch { private static bool Prefix() { return !Marketplace.IsMarketVisible(); } } [HarmonyPatch(typeof(PlayerController), "FixedUpdate")] private static class PlayerControllerPatch { private static bool Prefix() { return !Marketplace.IsMarketVisible(); } } [HarmonyPatch(typeof(Piece), "CanBeRemoved")] private static class MarketStallRemoved { [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] [UsedImplicitly] private static void Postfix(Piece __instance, ref bool __result) { string prefabName = Utils.GetPrefabName(((Component)__instance).gameObject); if (prefabName == "MarketStall" && !__instance.IsCreator()) { __result = false; } } } [HarmonyPatch(typeof(ZoneSystem), "Start")] private static class ZoneSystemStartPatch { private static void Postfix() { Filters.InitServerIgnoreList(); } } [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] private static void SpawnCargoCrate(List<MarketData.MarketTradeItem> PieceMarketData, Piece __instance, int i = 0) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) GameObject val = Object.Instantiate<GameObject>(CacheAssets.CargoCrate, ((Component)__instance).transform.position, Quaternion.identity); if ((Object)(object)val == (Object)null) { return; } Container val2 = default(Container); ItemDrop val4 = default(ItemDrop); ItemDrop val6 = default(ItemDrop); for (int j = i * 4; j < PieceMarketData.Count; j++) { MarketData.MarketTradeItem marketTradeItem = PieceMarketData[j]; GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(marketTradeItem.m_prefab); if (!Object.op_Implicit((Object)(object)itemPrefab)) { continue; } if (val.TryGetComponent<Container>(ref val2)) { if (!val2.GetInventory().AddItem(itemPrefab, marketTradeItem.m_stack)) { GameObject val3 = Object.Instantiate<GameObject>(itemPrefab, ((Component)__instance).transform.position, Quaternion.identity); if (val3.TryGetComponent<ItemDrop>(ref val4)) { val4.m_itemData.m_stack = marketTradeItem.m_stack; val4.m_itemData.m_quality = marketTradeItem.m_quality; val4.m_itemData.m_crafterName = marketTradeItem.m_crafter; } } } else { GameObject val5 = Object.Instantiate<GameObject>(itemPrefab, ((Component)__instance).transform.position, Quaternion.identity); if (val5.TryGetComponent<ItemDrop>(ref val6)) { val6.m_itemData.m_stack = marketTradeItem.m_stack; val6.m_itemData.m_quality = marketTradeItem.m_quality; val6.m_itemData.m_crafterName = marketTradeItem.m_crafter; } } } } public static void UpdateMarketGUI() { if (Input.GetKeyDown((KeyCode)27) && Marketplace.IsMarketVisible()) { Marketplace.ToggleMarketGUI(); } } } [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] public static class Filters { public static readonly CustomSyncedValue<List<string>> ServerIgnoreList = new CustomSyncedValue<List<string>>(MarketStallPlugin.ConfigSync, "MarketStallServerIgnoreList", new List<string>()); private static readonly string MarketFolderPath; private static readonly string IgnoreListPath; public static void InitServerIgnoreList() { if (!Object.op_Implicit((Object)(object)ZNet.instance)) { return; } if (ZNet.instance.IsServer()) { MarketStallPlugin.MarketStallLogger.LogDebug((object)"Server: Initializing ignore list"); if (!Directory.Exists(MarketFolderPath)) { Directory.CreateDirectory(MarketFolderPath); } if (!File.Exists(IgnoreListPath)) { File.WriteAllLines(IgnoreListPath, GetDefaultIgnoreList()); } ServerIgnoreList.Value = ValidateIgnoreList(); FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(MarketFolderPath) { Filter = "*.yml", EnableRaisingEvents = true, IncludeSubdirectories = true, SynchronizingObject = ThreadingHelper.SynchronizingObject, NotifyFilter = NotifyFilters.LastWrite }; fileSystemWatcher.Changed += OnFilterChange; fileSystemWatcher.Created += OnFilterChange; } else { MarketStallPlugin.MarketStallLogger.LogDebug((object)"Client: Awaiting server ignore list"); ServerIgnoreList.ValueChanged += OnServerIgnoreListChange; } } private static void OnServerIgnoreListChange() { MarketStallPlugin.MarketStallLogger.LogDebug((object)"Client: Received server ignore list"); } private static void OnFilterChange(object sender, FileSystemEventArgs e) { ServerIgnoreList.Value = ValidateIgnoreList(); } private static List<string> ValidateIgnoreList() { List<string> list = new List<string>(); ItemDrop val = default(ItemDrop); foreach (string item in File.ReadAllLines(IgnoreListPath).ToList()) { if (!item.StartsWith("#")) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(item); if ((Object)(object)itemPrefab == (Object)null) { MarketStallPlugin.MarketStallLogger.LogDebug((object)("Failed to find prefab: " + item)); } else if (!itemPrefab.TryGetComponent<ItemDrop>(ref val)) { MarketStallPlugin.MarketStallLogger.LogDebug((object)("Failed to find prefab item drop Component: " + item)); } else { list.Add(val.m_itemData.m_shared.m_name); } } } return list; } private static List<string> GetDefaultIgnoreList() { return new List<string> { "#Add Item names below to block prefabs: ", "SwordCheat", "Coins" }; } static Filters() { string configPath = Paths.ConfigPath; char directorySeparatorChar = Path.DirectorySeparatorChar; MarketFolderPath = configPath + directorySeparatorChar + "MarketStall"; string marketFolderPath = MarketFolderPath; directorySeparatorChar = Path.DirectorySeparatorChar; IgnoreListPath = marketFolderPath + directorySeparatorChar + "IgnoreList.yml"; } } } namespace MarketStall.UI { public static class CacheAssets { [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] public static GameObject CargoCrate; [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] [return: <1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] public static GameObject GetDestroyedLootPrefab(ZNetScene instance) { if (!Object.op_Implicit((Object)(object)instance)) { return null; } GameObject prefab = ZNetScene.instance.GetPrefab("Karve"); Container componentInChildren = prefab.GetComponentInChildren<Container>(); if (!Object.op_Implicit((Object)(object)componentInChildren)) { return null; } GameObject destroyedLootPrefab = componentInChildren.m_destroyedLootPrefab; if (!Object.op_Implicit((Object)(object)destroyedLootPrefab)) { return null; } return destroyedLootPrefab; } } [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] public static class Marketplace { [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] public enum MarketType { Buy, Sell } [HarmonyPatch(typeof(InventoryGui), "Awake")] [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] private static class SetMarketplaceEffects { [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] private static void Postfix(InventoryGui __instance) { if (Object.op_Implicit((Object)(object)__instance)) { SetMarketGUI(__instance); } } } private static GameObject MarketGUI = null; private static GameObject m_BuyItem = null; private static GameObject m_SellItem = null; private static RectTransform ListRoot = null; private static GameObject MerchantRevenue = null; private static Text RevenueText = null; public static Text RevenueValue = null; private static Text MarketTitle = null; private static Image MarketBackground = null; private static GameObject MarketStar = null; public static ZNetView CurrentMarket = null; public static MarketType MarketTypeIs; private static int price = 1; private static void UpdateRevenue(ZNetView znv) { float num = znv.GetZDO().GetInt(Market._MarketValue, 0); RevenueValue.text = num.ToString("0"); } public static void ToggleMarketGUI() { MarketGUI.SetActive(!IsMarketVisible()); } public static void ShowGUI(ZNetView znv, bool isCreator) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) MarketGUI.SetActive(true); znv.ClaimOwnership(); if (znv.IsValid()) { CurrentMarket = znv; OpenMarket(znv, (Humanoid)(object)Player.m_localPlayer, isCreator); MerchantRevenue.SetActive(isCreator); if (isCreator) { UpdateRevenue(znv); } ((Graphic)MarketBackground).color = ((MarketStallPlugin._TransparentBackground.Value == MarketStallPlugin.Toggle.On) ? Color.clear : Color.white); InventoryGui.instance.Show((Container)null, 1); string @string = znv.GetZDO().GetString(Market._MarketName, ""); MarketTitle.text = Localization.instance.Localize(@string + " $market_label"); } } private static void OpenMarket(ZNetView znv, Humanoid user, bool isCreator) { if (!((Object)(object)znv == (Object)null) && znv.IsValid()) { if (isCreator) { UpdateSellMarket(znv, user); } else { UpdateBuyMarket(znv, user); } } } public static bool IsMarketVisible() { return Object.op_Implicit((Object)(object)MarketGUI) && MarketGUI.activeInHierarchy; } public static void UpdateSellMarket(ZNetView znv, Humanoid user, string filter = "") { //IL_02c7: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Expected O, but got Unknown DestroyMarketItems(); MarketTypeIs = MarketType.Sell; List<ItemData> inventory = user.GetInventory().m_inventory; ItemDrop currencyComponent = default(ItemDrop); InputField val4 = default(InputField); Button val5 = default(Button); foreach (ItemData data in inventory) { if (Filters.ServerIgnoreList.Value.Contains(data.m_shared.m_name)) { continue; } string text = Localization.instance.Localize(data.m_shared.m_name); if (!text.ToLower().Contains(filter.ToLower())) { continue; } GameObject val = Object.Instantiate<GameObject>(m_SellItem, (Transform)(object)ListRoot); GameObject val2 = Methods.TryGetPrefab(MarketStallPlugin._Currency.Value); if (!val2.TryGetComponent<ItemDrop>(ref currencyComponent)) { continue; } Transform val3 = Utils.FindChild(val.transform, "$part_stars_root", (IterativeSearchType)0); ((Component)Utils.FindChild(val.transform, "$part_item_icon", (IterativeSearchType)0)).GetComponent<Image>().sprite = data.GetIcon(); ((Component)Utils.FindChild(val.transform, "$part_item_stack", (IterativeSearchType)0)).GetComponent<Text>().text = data.m_stack.ToString(CultureInfo.CurrentCulture); ((Component)Utils.FindChild(val.transform, "$part_item_name", (IterativeSearchType)0)).GetComponent<Text>().text = text; ((Component)Utils.FindChild(val.transform, "$part_price_icon", (IterativeSearchType)0)).GetComponent<Image>().sprite = currencyComponent.m_itemData.GetIcon(); if (data.m_quality > 1) { for (int i = 0; i < data.m_quality; i++) { Object.Instantiate<GameObject>(MarketStar, val3); } } if (((Component)Utils.FindChild(val.transform, "$part_price", (IterativeSearchType)0)).TryGetComponent<InputField>(ref val4)) { val4.characterLimit = currencyComponent.m_itemData.m_shared.m_maxStackSize.ToString().Length; ((UnityEvent<string>)(object)val4.onValueChanged).AddListener((UnityAction<string>)SetPrice); } if (!((Component)Utils.FindChild(val.transform, "$part_sell_button", (IterativeSearchType)0)).TryGetComponent<Button>(ref val5)) { continue; } ((UnityEvent)val5.onClick).AddListener((UnityAction)delegate { ItemDrop item = default(ItemDrop); if (Object.op_Implicit((Object)(object)data.m_dropPrefab) && data.m_dropPrefab.TryGetComponent<ItemDrop>(ref item)) { int count = Market.GetMarketData(CurrentMarket).Count; if (count >= MarketStallPlugin._MaxSales.Value) { Methods.ShowMessage(user, "<color=red>$maximum_items</color>"); } else if (SellItem(user, item, data, data.m_stack, price, currencyComponent, znv)) { UpdateSellMarket(znv, user); price = 1; } } }); } } private static void SetPrice(string input) { try { price = int.Parse(input); } catch { price = 1; } } private static bool SellItem(Humanoid user, ItemDrop item, ItemData data, int stack, int cost, ItemDrop currency, ZNetView znv) { Inventory inventory = user.GetInventory(); string text = Localization.instance.Localize(currency.m_itemData.m_shared.m_name); string arg = Localization.instance.Localize(item.m_itemData.m_shared.m_name); if (MarketStallPlugin._Fee.Value > 0f && MarketStallPlugin._UseSalesTax.Value == MarketStallPlugin.Toggle.On) { int num = Mathf.Max(Mathf.CeilToInt((float)cost * (MarketStallPlugin._Fee.Value / 100f)), MarketStallPlugin._MinimumFee.Value); if (!inventory.HaveItem(currency.m_itemData.m_shared.m_name, true)) { Methods.ShowMessage(user, $"$require_a_fee {num} {text}", item.m_itemData.GetIcon()); return false; } ItemData item2 = inventory.GetItem(currency.m_itemData.m_shared.m_name, -1, false); if (item2.m_stack < num) { Methods.ShowMessage(user, $"$not_enough {text}: {num}/{item2.m_stack}", item.m_itemData.GetIcon()); return false; } inventory.RemoveItem(currency.m_itemData.m_shared.m_name, num, -1, true); Methods.ShowMessage(user, $"$market_placed {arg} $market_x {stack} $market_for_a_fee {num}", item.m_itemData.GetIcon()); } inventory.RemoveItem(item.m_itemData.m_shared.m_name, stack, data.m_quality, true); Market.AddMarketItem(item, currency, data, stack, cost, znv); return true; } private static void UpdateBuyMarket(ZNetView znv, Humanoid user, string filter = "") { //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Expected O, but got Unknown DestroyMarketItems(); MarketTypeIs = MarketType.Buy; List<MarketData.MarketTradeItem> list = (from x in Market.GetMarketData(znv) orderby x.m_price select x).ToList(); ItemDrop currencyItemDrop = default(ItemDrop); foreach (MarketData.MarketTradeItem item in list) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(item.m_prefab); ItemDrop prefabItemDrop = itemPrefab.GetComponent<ItemDrop>(); string text = Localization.instance.Localize(prefabItemDrop.m_itemData.m_shared.m_name); if (!text.ToLower().Contains(filter.ToLower())) { continue; } GameObject val = Object.Instantiate<GameObject>(m_BuyItem, (Transform)(object)ListRoot); GameObject itemPrefab2 = ObjectDB.instance.GetItemPrefab(item.m_currency); if (!itemPrefab2.TryGetComponent<ItemDrop>(ref currencyItemDrop)) { continue; } Transform val2 = Utils.FindChild(val.transform, "$part_stars_root", (IterativeSearchType)0); ((Component)Utils.FindChild(val.transform, "$part_item_icon", (IterativeSearchType)0)).GetComponent<Image>().sprite = prefabItemDrop.m_itemData.GetIcon(); ((Component)Utils.FindChild(val.transform, "$part_item_name", (IterativeSearchType)0)).GetComponent<Text>().text = text; ((Component)Utils.FindChild(val.transform, "$part_price_icon", (IterativeSearchType)0)).GetComponent<Image>().sprite = currencyItemDrop.m_itemData.GetIcon(); ((Component)Utils.FindChild(val.transform, "$part_price", (IterativeSearchType)0)).GetComponent<Text>().text = ((item.m_price == 0) ? Localization.instance.Localize("$market_free") : item.m_price.ToString(CultureInfo.CurrentCulture)); ((UnityEvent)((Component)Utils.FindChild(val.transform, "$part_buy_button", (IterativeSearchType)0)).GetComponent<Button>().onClick).AddListener((UnityAction)delegate { if (BuyItem(user, prefabItemDrop, item, currencyItemDrop, znv)) { UpdateBuyMarket(znv, user); } }); ((Component)Utils.FindChild(val.transform, "$part_item_stack", (IterativeSearchType)0)).GetComponent<Text>().text = item.m_stack.ToString(CultureInfo.CurrentCulture); if (item.m_quality > 1) { for (int i = 0; i < item.m_quality; i++) { Object.Instantiate<GameObject>(MarketStar, val2); } } } } private static bool BuyItem(Humanoid user, ItemDrop item, MarketData.MarketTradeItem data, ItemDrop currency, ZNetView znv) { string text = Localization.instance.Localize(currency.m_itemData.m_shared.m_name); if (!user.GetInventory().HaveItem(currency.m_itemData.m_shared.m_name, true)) { Methods.ShowMessage(user, "$market_you_need " + text + " $market_to_purchase", currency.m_itemData.GetIcon()); return false; } string arg = Localization.instance.Localize(item.m_itemData.m_shared.m_name); int stack = user.GetInventory().GetItem(currency.m_itemData.m_shared.m_name, -1, false).m_stack; if (stack < data.m_price) { Methods.ShowMessage(user, "$you_do_not_have_enough " + text + " $market_to_purchase", currency.m_itemData.GetIcon()); return false; } if (!user.GetInventory().HaveEmptySlot()) { Methods.ShowMessage(user, "$your_inventory_is_full"); return false; } ItemData val = user.GetInventory().AddItem(((Object)item).name, data.m_stack, data.m_quality, item.m_itemData.m_variant, 0L, data.m_crafter, false); if (val == null) { return false; } IDeserializer deserializer = new DeserializerBuilder().Build(); Dictionary<string, string> customData = deserializer.Deserialize<Dictionary<string, string>>(data.m_customData); val.m_customData = customData; Methods.ShowMessage(user, $"$market_you_purchased {arg} $market_for {data.m_price} {text}", item.m_itemData.GetIcon()); user.GetInventory().RemoveItem(currency.m_itemData.m_shared.m_name, data.m_price, -1, true); return Market.BuyMarketItem(znv, data); } private static void DestroyMarketItems() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown foreach (Transform item in (Transform)ListRoot) { Transform val = item; Object.Destroy((Object)(object)((Component)val).gameObject); } } private static void SetMarketGUI(InventoryGui instance) { //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Expected O, but got Unknown //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Expected O, but got Unknown //IL_0302: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)instance)) { MarketGUI = Object.Instantiate<GameObject>(LoadAssets._assets.LoadAsset<GameObject>("Market_GUI"), ((Component)instance).transform); m_BuyItem = Object.Instantiate<GameObject>(LoadAssets._assets.LoadAsset<GameObject>("Market_Item")); m_SellItem = Object.Instantiate<GameObject>(LoadAssets._assets.LoadAsset<GameObject>("Market_Sell")); MarketStar = Object.Instantiate<GameObject>(LoadAssets._assets.LoadAsset<GameObject>("Market_Star")); MarketGUI.SetActive(false); ListRoot = ((Component)Utils.FindChild(MarketGUI.transform, "$part_Content", (IterativeSearchType)0)).GetComponent<RectTransform>(); Transform val = instance.m_trophiesPanel.transform.Find("TrophiesFrame/Closebutton"); Button component = ((Component)val).GetComponent<Button>(); ButtonSfx component2 = ((Component)val).GetComponent<ButtonSfx>(); GameObject gameObject = ((Component)Utils.FindChild(MarketGUI.transform, "$part_CloseButton", (IterativeSearchType)0)).gameObject; gameObject.gameObject.AddComponent<ButtonSfx>().m_sfxPrefab = component2.m_sfxPrefab; Button val2 = default(Button); if (gameObject.TryGetComponent<Button>(ref val2)) { ((Selectable)val2).transition = (Transition)2; ((Selectable)val2).spriteState = ((Selectable)component).spriteState; ((UnityEvent)val2.onClick).AddListener(new UnityAction(HideGUI)); } Transform val3 = Utils.FindChild(m_SellItem.transform, "$part_sell_button", (IterativeSearchType)0); ((Component)val3).gameObject.AddComponent<ButtonSfx>().m_sfxPrefab = component2.m_sfxPrefab; ((Component)val3).GetComponentInChildren<Text>().text = Localization.instance.Localize("$market_sell"); Button val4 = default(Button); if (((Component)val3).TryGetComponent<Button>(ref val4)) { ((Selectable)val4).transition = (Transition)2; ((Selectable)val4).spriteState = ((Selectable)component).spriteState; } Transform val5 = Utils.FindChild(m_BuyItem.transform, "$part_buy_button", (IterativeSearchType)0); ((Component)val5).gameObject.AddComponent<ButtonSfx>().m_sfxPrefab = component2.m_sfxPrefab; ((Component)val5).GetComponentInChildren<Text>().text = Localization.instance.Localize("$market_buy"); Button val6 = default(Button); if (((Component)val5).TryGetComponent<Button>(ref val6)) { ((Selectable)val6).transition = (Transition)2; ((Selectable)val6).spriteState = ((Selectable)component).spriteState; } MerchantRevenue = ((Component)Utils.FindChild(MarketGUI.transform, "$part_seller", (IterativeSearchType)0)).gameObject; RevenueText = ((Component)Utils.FindChild(MerchantRevenue.transform, "$part_revenue", (IterativeSearchType)0)).GetComponent<Text>(); RevenueValue = ((Component)Utils.FindChild(MerchantRevenue.transform, "$part_money_value", (IterativeSearchType)0)).GetComponent<Text>(); MarketTitle = ((Component)Utils.FindChild(MarketGUI.transform, "$part_title", (IterativeSearchType)0)).GetComponent<Text>(); GameObject gameObject2 = ((Component)Utils.FindChild(MerchantRevenue.transform, "$part_money_button", (IterativeSearchType)0)).gameObject; gameObject2.AddComponent<ButtonSfx>().m_sfxPrefab = component2.m_sfxPrefab; Button val7 = default(Button); if (gameObject2.TryGetComponent<Button>(ref val7)) { ((UnityEvent)val7.onClick).AddListener(new UnityAction(CollectRevenue)); ((Selectable)val7).transition = (Transition)2; ((Selectable)val7).spriteState = ((Selectable)component).spriteState; } RevenueText.text = Localization.instance.Localize("$revenue_label"); MarketTitle.text = Localization.instance.Localize("$market_label"); Transform val8 = Utils.FindChild(MarketGUI.transform, "$part_filter", (IterativeSearchType)0); InputField val9 = default(InputField); if (((Component)val8).TryGetComponent<InputField>(ref val9)) { ((UnityEvent<string>)(object)val9.onValueChanged).AddListener((UnityAction<string>)OnFilterChange); } Image component3 = ((Component)instance.m_trophiesPanel.transform.Find("TrophiesFrame/border (1)")).GetComponent<Image>(); MarketBackground = ((Component)MarketGUI.transform.Find("Panel")).GetComponent<Image>(); ((Graphic)MarketBackground).material = ((Graphic)component3).material; ((Graphic)((Component)val8).GetComponent<Image>()).material = ((Graphic)component3).material; Font font = GetFont("Norse"); Font font2 = GetFont("Norsebold"); Text[] componentsInChildren = MarketGUI.GetComponentsInChildren<Text>(); Text[] componentsInChildren2 = m_BuyItem.GetComponentsInChildren<Text>(); Text[] componentsInChildren3 = m_SellItem.GetComponentsInChildren<Text>(); AddFonts(componentsInChildren, font2, font); AddFonts(componentsInChildren2, font2, font); AddFonts(componentsInChildren3, font2, font); } } [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(2)] private static void AddFonts([<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(1)] Text[] array, Font NorseBold, Font NorseFont) { foreach (Text val in array) { val.font = ((((Object)val).name == "$part_title") ? NorseBold : NorseFont); } } [return: <1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] private static Font GetFont(string name) { Font[] source = Resources.FindObjectsOfTypeAll<Font>(); return ((IEnumerable<Font>)source).FirstOrDefault((Func<Font, bool>)([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (Font x) => ((Object)x).name == name)); } private static void HideGUI() { MarketGUI.SetActive(false); } private static void CollectRevenue() { if (Market.CollectValue(CurrentMarket)) { UpdateSellMarket(CurrentMarket, (Humanoid)(object)Player.m_localPlayer); } } private static void OnFilterChange(string input) { if (MarketTypeIs == MarketType.Buy) { UpdateBuyMarket(CurrentMarket, (Humanoid)(object)Player.m_localPlayer, input); } else { UpdateSellMarket(CurrentMarket, (Humanoid)(object)Player.m_localPlayer, input); } } } } namespace MarketStall.Managers { [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] [PublicAPI] [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] public class Localizer { private static readonly Dictionary<string, Dictionary<string, Func<string>>> PlaceholderProcessors; private static readonly Dictionary<string, Dictionary<string, string>> loadedTexts; private static readonly ConditionalWeakTable<Localization, string> localizationLanguage; private static readonly List<WeakReference<Localization>> localizationObjects; [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] private static BaseUnityPlugin _plugin; private static readonly List<string> fileExtensions; private static BaseUnityPlugin plugin { get { //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Expected O, but got Unknown if (_plugin == null) { 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([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t))); } return _plugin; } } private static void UpdatePlaceholderText(Localization localization, string key) { localizationLanguage.TryGetValue(localization, out var value); string text = loadedTexts[value][key]; if (PlaceholderProcessors.TryGetValue(key, out var value2)) { text = value2.Aggregate(text, [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (string current, KeyValuePair<string, Func<string>> kv) => current.Replace("{" + kv.Key + "}", kv.Value())); } localization.AddWord(key, text); } public static void AddPlaceholder<T>(string key, string placeholder, ConfigEntry<T> config, [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(new byte[] { 2, 1, 1 })] Func<T, string> convertConfigValue = null) { if (convertConfigValue == null) { convertConfigValue = [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] [return: <1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(1)] (T val) => val.ToString(); } if (!PlaceholderProcessors.ContainsKey(key)) { PlaceholderProcessors[key] = new Dictionary<string, Func<string>>(); } config.SettingChanged += [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (object _, EventArgs _) => { UpdatePlaceholder(); }; if (loadedTexts.ContainsKey(Localization.instance.GetSelectedLanguage())) { UpdatePlaceholder(); } void UpdatePlaceholder() { PlaceholderProcessors[key][placeholder] = () => convertConfigValue(config.Value); UpdatePlaceholderText(Localization.instance, key); } } public static void AddText(string key, string text) { List<WeakReference<Localization>> list = new List<WeakReference<Localization>>(); foreach (WeakReference<Localization> localizationObject in localizationObjects) { if (localizationObject.TryGetTarget(out var target)) { Dictionary<string, string> dictionary = loadedTexts[localizationLanguage.GetOrCreateValue(target)]; if (!target.m_translations.ContainsKey(key)) { dictionary[key] = text; target.AddWord(key, text); } } else { list.Add(localizationObject); } } foreach (WeakReference<Localization> item in list) { localizationObjects.Remove(item); } } public static void Load() { LoadLocalization(Localization.instance, Localization.instance.GetSelectedLanguage()); } private static void LoadLocalization(Localization __instance, string language) { if (!localizationLanguage.Remove(__instance)) { localizationObjects.Add(new WeakReference<Localization>(__instance)); } localizationLanguage.Add(__instance, language); Dictionary<string, string> dictionary = new Dictionary<string, string>(); foreach (string item in from f in Directory.GetFiles(Path.GetDirectoryName(Paths.PluginPath), plugin.Info.Metadata.Name + ".*", SearchOption.AllDirectories) where fileExtensions.IndexOf(Path.GetExtension(f)) >= 0 select f) { string text = Path.GetFileNameWithoutExtension(item).Split(new char[1] { '.' })[1]; if (dictionary.ContainsKey(text)) { Debug.LogWarning((object)("Duplicate key " + text + " found for " + plugin.Info.Metadata.Name + ". The duplicate file found at " + item + " will be skipped.")); } else { dictionary[text] = item; } } byte[] array = LoadTranslationFromAssembly("English"); if (array == null) { throw new Exception("Found no English localizations in mod " + plugin.Info.Metadata.Name + ". Expected an embedded resource translations/English.json or translations/English.yml."); } Dictionary<string, string> dictionary2 = new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(Encoding.UTF8.GetString(array)); if (dictionary2 == null) { throw new Exception("Localization for mod " + plugin.Info.Metadata.Name + " failed: Localization file was empty."); } string text2 = null; if (language != "English") { if (dictionary.ContainsKey(language)) { text2 = File.ReadAllText(dictionary[language]); } else { byte[] array2 = LoadTranslationFromAssembly(language); if (array2 != null) { text2 = Encoding.UTF8.GetString(array2); } } } if (text2 == null && dictionary.ContainsKey("English")) { text2 = File.ReadAllText(dictionary["English"]); } if (text2 != null) { foreach (KeyValuePair<string, string> item2 in new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(text2) ?? new Dictionary<string, string>()) { dictionary2[item2.Key] = item2.Value; } } loadedTexts[language] = dictionary2; foreach (KeyValuePair<string, string> item3 in dictionary2) { UpdatePlaceholderText(__instance, item3.Key); } } static Localizer() { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Expected O, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown PlaceholderProcessors = new Dictionary<string, Dictionary<string, Func<string>>>(); loadedTexts = new Dictionary<string, Dictionary<string, string>>(); localizationLanguage = new ConditionalWeakTable<Localization, string>(); localizationObjects = new List<WeakReference<Localization>>(); fileExtensions = new List<string> { ".json", ".yml" }; Harmony val = new Harmony("org.bepinex.helpers.LocalizationManager"); val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Localization), "LoadCSV", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "LoadLocalization", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } [return: <1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] private static byte[] LoadTranslationFromAssembly(string language) { foreach (string fileExtension in fileExtensions) { byte[] array = ReadEmbeddedFileBytes("translations." + language + fileExtension); if (array != null) { return array; } } return null; } [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(2)] public static byte[] ReadEmbeddedFileBytes([<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(1)] string resourceFileName, Assembly containingAssembly = null) { using MemoryStream memoryStream = new MemoryStream(); if ((object)containingAssembly == null) { containingAssembly = Assembly.GetCallingAssembly(); } string text = containingAssembly.GetManifestResourceNames().FirstOrDefault([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (string str) => str.EndsWith(resourceFileName, StringComparison.Ordinal)); if (text != null) { containingAssembly.GetManifestResourceStream(text)?.CopyTo(memoryStream); } return (memoryStream.Length == 0L) ? null : memoryStream.ToArray(); } } public static class MarketStallPieces { public static void InitPieces() { BuildPiece.ConfigurationEnabled = true; BuildPiece buildPiece = new BuildPiece("marketstallbundle2", "MarketStall"); buildPiece.Name.English("Market Stall"); buildPiece.Description.English("Personal marketplace"); buildPiece.RequiredItems.Add("FineWood", 20, recover: true); buildPiece.RequiredItems.Add("Wood", 20, recover: true); buildPiece.RequiredItems.Add("Thunderstone", 1, recover: true); buildPiece.RequiredItems.Add("Bronze", 5, recover: true); buildPiece.Category.Set(BuildPieceCategory.Misc); buildPiece.Crafting.Set(CraftingTable.None); MaterialReplacer.RegisterGameObjectForMatSwap(buildPiece.Prefab); PieceEffectManager.PrefabsToSet.Add(buildPiece.Prefab); buildPiece.Prefab.AddComponent<Market>(); BuildPiece buildPiece2 = new BuildPiece("marketstallbundle2", "MarketStall_Small"); buildPiece2.Name.English("Market Stall Mini"); buildPiece2.Description.English("Personal marketplace"); buildPiece2.RequiredItems.Add("FineWood", 20, recover: true); buildPiece2.RequiredItems.Add("Wood", 20, recover: true); buildPiece2.RequiredItems.Add("Thunderstone", 1, recover: true); buildPiece2.RequiredItems.Add("Bronze", 5, recover: true); buildPiece2.Category.Set(BuildPieceCategory.Misc); buildPiece2.Crafting.Set(CraftingTable.None); MaterialReplacer.RegisterGameObjectForMatSwap(buildPiece2.Prefab); PieceEffectManager.PrefabsToSet.Add(buildPiece2.Prefab); buildPiece2.Prefab.AddComponent<Market>(); } } [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] public static class PieceEffectManager { [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] [HarmonyPatch(typeof(ZNetScene), "Awake")] private static class SetPiecesEffects { [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] private static void Postfix(ZNetScene __instance) { if (Object.op_Implicit((Object)(object)__instance)) { AddEffects(__instance); CacheAssets.CargoCrate = CacheAssets.GetDestroyedLootPrefab(__instance); } } } public static readonly List<GameObject> PrefabsToSet = new List<GameObject>(); private static void AddEffects(ZNetScene instance) { if (!Object.op_Implicit((Object)(object)instance)) { return; } foreach (GameObject item in PrefabsToSet) { GameObject prefab = instance.GetPrefab(((Object)item).name); if (Object.op_Implicit((Object)(object)prefab)) { SetPieceScript(instance, prefab, "vfx_Place_stone_wall_2x1", "sfx_build_hammer_stone"); } } } private static void SetPieceScript(ZNetScene scene, GameObject prefab, string placementEffectName1, string placementEffectName2) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //IL_0041: 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_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown GameObject prefab2 = scene.GetPrefab(placementEffectName1); GameObject prefab3 = scene.GetPrefab(placementEffectName2); if (Object.op_Implicit((Object)(object)prefab2) && Object.op_Implicit((Object)(object)prefab3)) { EffectList val = new EffectList(); val.m_effectPrefabs = (EffectData[])(object)new EffectData[2] { new EffectData { m_prefab = prefab2, m_enabled = true, m_variant = -1, m_attach = false, m_inheritParentRotation = false, m_inheritParentScale = false, m_randomRotation = false, m_scale = false, m_childTransform = "" }, new EffectData { m_prefab = prefab3, m_enabled = true, m_variant = -1, m_attach = false, m_inheritParentRotation = false, m_inheritParentScale = false, m_randomRotation = false, m_scale = false, m_childTransform = "" } }; EffectList placeEffect = val; Piece component = prefab.GetComponent<Piece>(); component.m_placeEffect = placeEffect; component.m_groundPiece = false; component.m_allowAltGroundPlacement = false; component.m_cultivatedGroundOnly = false; component.m_waterPiece = false; component.m_clipGround = true; component.m_clipEverything = false; component.m_noInWater = false; component.m_notOnWood = false; component.m_notOnTiltingSurface = false; component.m_inCeilingOnly = false; component.m_notOnFloor = false; component.m_noClipping = false; component.m_onlyInTeleportArea = false; component.m_allowedInDungeons = false; component.m_spaceRequirement = 0f; component.m_repairPiece = false; component.m_canBeRemoved = true; component.m_allowRotatedOverlap = false; component.m_vegetationGroundOnly = false; } } } [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, Custom } [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] public class InternalName : Attribute { public readonly string internalName; public InternalName(string internalName) { this.internalName = internalName; } } [PublicAPI] [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] [<1bf4d302-402c-47c4-8f96-a8d71031beb7>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; [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] public string custom; } [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] [PublicAPI] [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>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; [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] public string custom; } [PublicAPI] public enum BuildPieceCategory { Misc = 0, Crafting = 1, Building = 2, Furniture = 3, All = 100, Custom = 99 } [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] [PublicAPI] 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 { [<1bf4d302-402c-47c4-8f96-a8d71031beb7>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; } [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] [<1bf4d302-402c-47c4-8f96-a8d71031beb7>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] [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] public class PieceTool { public readonly HashSet<string> Tools = new HashSet<string>(); public void Add(string tool) { Tools.Add(tool); } } [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(0)] [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(1)] [PublicAPI] public class BuildPiece { [<1bf4d302-402c-47c4-8f96-a8d71031beb7>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; } [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] private class ConfigurationManagerAttributes { [UsedImplicitly] public int? Order; [UsedImplicitly] public bool? Browsable; [UsedImplicitly] [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] public string Category; [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(new byte[] { 2, 1 })] [UsedImplicitly] public Action<ConfigEntryBase> CustomDrawer; } [<1bf4d302-402c-47c4-8f96-a8d71031beb7>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([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>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([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (Requirement r) => $"{r.itemName}:{r.amount}:{r.recover}")); } public static Requirement[] toPieceReqs(SerializedRequirements craft) { Dictionary<string, Requirement> dictionary = craft.Reqs.Where((Requirement r) => r.itemName != "").ToDictionary((Func<Requirement, string>)([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (Requirement r) => r.itemName), (Func<Requirement, Requirement>)([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>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 val2 = ResItem(r); return (val2 == null) ? ((Requirement)null) : new Requirement { m_amount = r.amount, m_resItem = val2, m_recover = r.recover }; })); return dictionary.Values.Where([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (Requirement v) => v != null).ToArray(); [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(2)] static ItemDrop ResItem(Requirement r) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(r.itemName); ItemDrop val = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null); if ((Object)(object)val == (Object)null) { Debug.LogWarning((object)("The required item '" + r.itemName + "' does not exist.")); } return val; } } } internal static readonly List<BuildPiece> registeredPieces = new List<BuildPiece>(); internal static Dictionary<BuildPiece, PieceConfig> pieceConfigs = new Dictionary<BuildPiece, PieceConfig>(); [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; [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] private LocalizeKey _name; [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] private LocalizeKey _description; internal string[] activeTools = null; [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] private static object configManager; [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] private static Localization _english; [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] internal static BaseUnityPlugin _plugin = null; private static bool hasConfigSync = true; [<1bf4d302-402c-47c4-8f96-a8d71031beb7>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([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t))); return _plugin; } } [<1bf4d302-402c-47c4-8f96-a8d71031beb7>Nullable(2)] private static object configSync { [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>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_0282: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Expected O, but got Unknown //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_0334: Expected O, but got Unknown //IL_03d2: Unknown result type (might be due to invalid IL or missing references) //IL_03ac: Unknown result type (might be due to invalid IL or missing references) //IL_03b1: Unknown result type (might be due to invalid IL or missing references) //IL_042d: Unknown result type (might be due to invalid IL or missing references) //IL_0437: Expected O, but got Unknown //IL_05a7: Unknown result type (might be due to invalid IL or missing references) //IL_05b1: Expected O, but got Unknown //IL_088b: Unknown result type (might be due to invalid IL or missing references) //IL_0895: Expected O, but got Unknown //IL_061c: Unknown result type (might be due to invalid IL or missing references) //IL_0626: Expected O, but got Unknown //IL_06c2: Unknown result type (might be due to invalid IL or missing references) //IL_06cc: Expected O, but got Unknown //IL_0900: Unknown result type (might be due to invalid IL or missing references) //IL_090a: Expected O, but got Unknown Type configManagerType = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>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 (!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 piecePrefab = piece.Prefab.GetComponent<Piece>(); string pieceName = piecePrefab.m_name; string englishName = new Regex("[=\\n\\t\\\\\"\\'\\[\\]]*").Replace(english.Localize(pieceName), "").Trim(); string localizedName = Localization.instance.Localize(pieceName).Trim(); int order = 0; cfg.category = config(englishName, "Build Table Category", piece.Category.Category, new ConfigDescription("Build Category where " + localizedName + " is available.", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = (order -= 1), Category = localizedName } })); ConfigurationManagerAttributes customTableAttributes = new ConfigurationManagerAttributes { Order = (order -= 1), Browsable = (cfg.category.Value == BuildPieceCategory.Custom), Category = localizedName }; cfg.customCategory = config(englishName, "Custom Build Category", piece.Category.custom, new ConfigDescription("", (AcceptableValueBase)null, new object[1] { customTableAttributes })); cfg.category.SettingChanged += BuildTableConfigChanged; cfg.customCategory.SettingChanged += BuildTableConfigChanged; if (cfg.category.Value == BuildPieceCategory.Custom) { piecePrefab.m_category = PiecePrefabManager.GetCategory(cfg.customCategory.Value); } else { piecePrefab.m_category = (PieceCategory)cfg.category.Value; } cfg.tools = config(englishName, "Tools", string.Join(", ", piece.activeTools), new ConfigDescription("Comma separated list of tools where " + localizedName + " is available.", (AcceptableValueBase)null, new object[1] { customTableAttributes })); piece.activeTools = (from s in cfg.tools.Value.Split(new char[1] { ',' }) select s.Trim()).ToArray(); cfg.tools.SettingChanged += [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (object _, EventArgs _) => { Inventory[] source = (from c in Player.s_players.Select([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (Player p) => ((Humanoid)p).GetInventory()).Concat(from c in Object.FindObjectsOfType<Container>() select c.GetInventory()) where c != null select c).ToArray(); Dictionary<string, List<PieceTable>> dictionary = (from kv in (from i in (from p in ObjectDB.instance.m_items select p.GetComponent<ItemDrop>() into c where Object.op_Implicit((Object)(object)c) && Object.op_Implicit((Object)(object)((Component)c).GetComponent<ZNetView>()) select c).Concat(ItemDrop.s_instances) select new KeyValuePair<string, ItemData>(Utils.GetPrefabName(((Component)i).gameObject), i.m_itemData)).Concat(from i in source.SelectMany([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (Inventory i) => i.GetAllItems()) select new KeyValuePair<string, ItemData>(((Object)i.m_dropPrefab).name, i)) where Object.op_Implicit((Object)(object)kv.Value.m_shared.m_buildPieces) group kv by kv.Key).ToDictionary([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (IGrouping<string, KeyValuePair<string, ItemData>> g) => g.Key, [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (IGrouping<string, KeyValuePair<string, ItemData>> g) => g.Select([<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (KeyValuePair<string, ItemData> kv) => kv.Value.m_shared.m_buildPieces).Distinct().ToList()); string[] array5 = piece.activeTools; foreach (string key in array5) { if (dictionary.TryGetValue(key, out var value3)) { foreach (PieceTable item3 in value3) { item3.m_pieces.Remove(piece.Prefab); } } } piece.activeTools = (from s in cfg.tools.Value.Split(new char[1] { ',' }) select s.Trim()).ToArray(); if (Object.op_Implicit((Object)(object)ObjectDB.instance)) { string[] array6 = piece.activeTools; foreach (string key2 in array6) { if (dictionary.TryGetValue(key2, out var value4)) { foreach (PieceTable item4 in value4) { if (!item4.m_pieces.Contains(piece.Prefab)) { item4.m_pieces.Add(piece.Prefab); } } } } if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && Object.op_Implicit((Object)(object)Player.m_localPlayer.m_buildPieces)) { ((Humanoid)Player.m_localPlayer).SetPlaceMode(Player.m_localPlayer.m_buildPieces); } } }; StationExtension pieceExtensionComp; List<ConfigurationManagerAttributes> hideWhenNoneAttributes2; if (piece.Extension.ExtensionStations.Count > 0) { pieceExtensionComp = piece.Prefab.GetOrAddComponent<StationExtension>(); PieceConfig pieceConfig3 = cfg; string group = englishName; CraftingTable table = piece.Extension.ExtensionStations.First().Table; string text = "Crafting station that " + localizedName + " extends."; object[] array = new object[1]; ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes(); int num = order - 1; order = num; configurationManagerAttributes.Order = num; array[0] = configurationManagerAttributes; pieceConfig3.extensionTable = config(group, "Extends Station", table, new ConfigDescription(text, (AcceptableValueBase)null, array)); cfg.customExtentionTable = config(englishName, "Custom Extend Station", piece.Extension.ExtensionStations.First().custom ?? "", new ConfigDescription("", (AcceptableValueBase)null, new object[1] { customTableAttributes })); PieceConfig pieceConfig4 = cfg; string group2 = englishName; float maxStationDistance = piece.Extension.ExtensionStations.First().maxStationDistance; string text2 = "Distance from the station that " + localizedName + " can be placed."; object[] array2 = new object[1]; ConfigurationManagerAttributes configurationManagerAttributes2 = new ConfigurationManagerAttributes(); num = order - 1; order = num; configurationManagerAttributes2.Order = num; array2[0] = configurationManagerAttributes2; pieceConfig4.maxStationDistance = config(group2, "Max Station Distance", maxStationDistance, new ConfigDescription(text2, (AcceptableValueBase)null, array2)); hideWhenNoneAttributes2 = new List<ConfigurationManagerAttributes>(); cfg.extensionTable.SettingChanged += ExtensionTableConfigChanged; cfg.customExtentionTable.SettingChanged += ExtensionTableConfigChanged; cfg.maxStationDistance.SettingChanged += ExtensionTableConfigChanged; ConfigurationManagerAttributes configurationManagerAttributes3 = new ConfigurationManagerAttributes(); num = order - 1; order = num; configurationManagerAttributes3.Order = num; configurationManagerAttributes3.Browsable = cfg.extensionTable.Value != CraftingTable.None; ConfigurationManagerAttributes item = configurationManagerAttributes3; hideWhenNoneAttributes2.Add(item); } List<ConfigurationManagerAttributes> hideWhenNoneAttributes; if (piece.Crafting.Stations.Count > 0) { hideWhenNoneAttributes = new List<ConfigurationManagerAttributes>(); PieceConfig pieceConfig5 = cfg; string group3 = englishName; CraftingTable table2 = piece.Crafting.Stations.First().Table; string text3 = "Crafting station where " + localizedName + " is available."; object[] array3 = new object[1]; ConfigurationManagerAttributes configurationManagerAttributes4 = new ConfigurationManagerAttributes(); int num = order - 1; order = num; configurationManagerAttributes4.Order = num; array3[0] = configurationManagerAttributes4; pieceConfig5.table = config(group3, "Crafting Station", table2, new ConfigDescription(text3, (AcceptableValueBase)null, array3)); cfg.customTable = config(englishName, "Custom Crafting Station", piece.Crafting.Stations.First().custom ?? "", new ConfigDescription("", (AcceptableValueBase)null, new object[1] { customTableAttributes })); cfg.table.SettingChanged += TableConfigChanged; cfg.customTable.SettingChanged += TableConfigChanged; ConfigurationManagerAttributes configurationManagerAttributes5 = new ConfigurationManagerAttributes(); num = order - 1; order = num; configurationManagerAttributes5.Order = num; configurationManagerAttributes5.Browsable = cfg.table.Value != CraftingTable.None; ConfigurationManagerAttributes item2 = configurationManagerAttributes5; hideWhenNoneAttributes.Add(item2); } cfg.craft = itemConfig("Crafting Costs", new SerializedRequirements(piece.RequiredItems.Requirements).ToString(), "Item costs to craft " + localizedName); cfg.craft.SettingChanged += [<b6c25812-dd59-4e70-adc3-5bbb842cd4c2>NullableContext(0)] (object _, EventArgs _) => { if (Object.op_Implicit((Object)(object)ObjectDB.instance) && (Object)(object)ObjectDB.instance.GetItemPrefab("Wood") != (Object)null) { Requirement[] resources = SerializedRequirements.toPieceReqs(new SerializedRequirements(cfg.craft.Value)); piecePrefab.m_resources = resources; Piece[] array4 = Object.FindObjectsOfType<Piece>(); foreach (Piece val in array4) { if (val.m_name == pieceName) { val.m_resources = resources; } } } }; void BuildTableConfigChanged(object o, EventArgs e) { //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) if (registeredPieces.Count > 0) { if (cfg.category.Value == BuildPieceCategory.Custom) { piecePrefab.m_category = PiecePrefabManager.GetCategory(cfg.customCategory.Value); } else { piecePrefab.m_category = (PieceCategory)cfg.category.Value; } if (Object.op_Implicit((Object)(object)Hud.instance)) { PiecePrefabManager.CreateCategoryTabs(); } } customTableAttributes.Browsable = cfg.category.Value == BuildPieceCategory.Custom; ReloadConfigDisplay(); } void ExtensionTableConfigChanged(object o, EventArgs e) { if (piece.RequiredItems.Requirements.Count > 0) { CraftingTable value2 = cfg.extensionTable.Value; CraftingTable craftingTable = value2; if (craftingTable == CraftingTable.Custom) { StationExtension obj2 = pieceExtensionComp; GameObject prefab2 = ZNetScene.instance.GetPrefab(cfg.customExtentionTable.Value); obj2.m_craftingStation = ((prefab2 != null) ? prefab2.GetComponent<CraftingStation>() : null); } else { pieceExtensionComp.m_craftingStation = ZNetScene.instance.GetPrefab(((InternalName)typeof(CraftingTable).GetMember(cfg.extensionTable.Value.ToString())[0].GetCustomAttributes(typeof(InternalName)).First()).internalName).GetComponent<CraftingStation>(); } pieceExtensionComp.m_maxStationDistance = cfg.maxStationDistance.Value; } customTableAttributes.Browsable = cfg.extensionTable.Value == CraftingTable.Custom; foreach (ConfigurationManagerAttributes item5 in hideWhenNoneAttributes2) { item5.Browsable = cfg.extensionTable.Value != CraftingTable.None; } ReloadConfigDisplay(); plugin.Config.Save(); } void TableConfigChanged(object o, EventArgs e) { if (piece.RequiredItems.Requirements.Count > 0) { switch (cfg.table.Value) { case CraftingTable.None: piecePrefab.m_craftingStation = null; break; case CraftingTable.Custom: { Piece obj = piecePrefab; GameObject prefab = ZNetScene.instance.GetPrefab(cfg.customTable.Value); obj.m_craftingStation = ((prefab != null) ? prefab.GetComponent<CraftingStation>() : null); break; } default: piecePrefab.m_craftingStation = ZNetScene.instance.GetPrefab(((InternalName)typeof(CraftingTable).GetMember(cfg.table.Value.ToString())[0].GetCustomAttributes(typeof(InternalName)).First()).internalName).GetComponent<CraftingStation>(); break; } } customTableAttributes.Browsable = cfg.table.Value == CraftingTable.Custom; foreach (ConfigurationManagerAttributes item6 in hideWhenNoneAttributes) { item6.Browsable = cfg.table.Value != CraftingTable.None; } ReloadConfigDisplay(); plugin.Config.Save(); } ConfigEntry<string> itemConfig(string name, string value, string desc) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown ConfigurationManagerAttributes configurationManagerAttributes6 = new ConfigurationManagerAttributes { CustomDrawer = DrawConfigTable, Order = (order -= 1), Category = localizedName }; return config(englishName, name, value, new ConfigDescription(desc, (AcceptableValueBase)null, new object[1] { configurationManagerAttributes6 })); } } if (saveOnConfigSet) { plugin.Config.SaveOnConfigSet = true; plugin.Config.Save(); } void ReloadConfigDisplay() { configManagerType?.GetMethod("BuildSettingList").Invoke(configManager, Array.Empty<object>()); } } [HarmonyPriority(700)] internal static void Patch_ObjectDBInit(ObjectDB __instance) { if ((Object)(object)__instance.GetItemPrefab("Wood") == (Object)null) { return; } foreach (BuildPiece registeredPiece in registeredPieces) { pieceConfigs.TryGetValue(registeredPiece, out var value); registeredPiece.Prefab.GetComponent<Piece>().m_resources = SerializedRequirements.toPieceReqs((value == null) ? new SerializedRequirements(registeredPiece.RequiredItems.Requirements) : new SerializedRequirements(value.craft.Value)); foreach (ExtensionConfig extensionStation in registeredPiece.Extension.ExtensionStations) { switch ((value == null || registeredPiece.Extension.ExtensionStations.Count > 0) ? extensionStation.Table : value.extensionTable.Value) { case CraftingTable.None: registeredPiece.Prefab.GetComponent<StationExtension>().m_craftingStation = null; break; case CraftingTable.Custom: { GameObject prefab = ZNetScene.instance.GetPrefab((value == null || registeredPiece.Extension.ExtensionStations.Count > 0) ? extensionStation.custom : value.customExtentionTable.Value); if (prefab != null) { registeredPiece.Prefab.GetComponent<StationExtension>().m_craftingStation = prefab.GetComponent<CraftingStation>(); } else { Debug.LogWarning((object)("Custom crafting station '" + ((value == null || registeredPiece.Extension.ExtensionStations.Count > 0) ? extensionStation.custom : value.customExtentionTable.Value) + "' does not exist")); } break; } default: if (value != null && value.table.Value == CraftingTable.None) { registeredPiece.Prefab.GetComponent<StationExtension>().m_craftingStation = null; } else { registeredPiece.Prefab.GetComponent<StationExtension>().m_craftingStation = ZNetScene.instance.GetPrefab(((InternalName)typeof(CraftingTable).GetMember(((value == null || registeredPiece.Extension.ExtensionStations.Count > 0) ? extensionStation.Table : value.extensionTable.Value).ToString())[0].GetCustomAttributes(typeof(InternalName)).First()).internalName).GetComponent<CraftingStation>(); } break; } } foreach (CraftingStationConfig station in registeredPiece.Crafting.Stations) { switch ((value == null || registeredPiece.Crafting.Stations.Count > 0) ? station.Table : value.table.Value) { case CraftingTable.None: registeredPiece.Prefab.GetComponent<Piece>().m_craftingStation = null; break; case CraftingTable.Custom: { GameObject prefab2 = ZNetScene.instance.GetPrefab((value == null || registeredPiece.Crafting.Stations.Count > 0) ? station.custom : value.customTable.Value); if (prefab2 != null) { registeredPiece.Prefab.GetComponent<Piece>().m_craftingStation = prefab2.GetComponent<CraftingStation>(); } else { Debug.LogWarning((object)("Custom crafting station '" + ((value == null || registeredPiece.Crafting.Stations.Count > 0) ? station.custom : value.customTable.Value) + "' does not exist")); } break; } default: if (value != null && value.table.Value == CraftingTable.None) { registeredPiece.Prefab.GetComponent<Piece>().m_craftingStation = null; } else { registeredPiece.Prefab.GetComponent<Piece>().m_craftingStation = ZNetScene.instance.GetPrefab(((InternalName)typeof(CraftingTable).GetMember(((value == null || registeredPiece.Crafting.Stations.Count > 0) ? station.Table : value.table.Value).ToString())[0].GetCustomAttributes(typeof(InternalName)).First()).internalName).GetComponent<CraftingStation>(); } break; } } } } public void Snapshot(float lightIntensity = 1.3f, Quaternion? cameraRotation = null) { SnapshotPiece(Prefab, lightIntensity, cameraRotation); } internal void SnapshotPiece(GameObject prefab, float lightIntensity = 1.3f, Quaternion? cameraRotation = null) { //IL_0055: Unknown result type (might be due t