Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of PlantCart v0.0.1
plugins/PlantCart.dll
Decompiled a week agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using PlantCart.Components; using PlantCart.Configs; using PlantCart.Helpers; using PlantCart.Models; using PlantCart.Types; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("PlantCart")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("PlantCart")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")] [assembly: AssemblyFileVersion("0.0.1")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.1.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace PlantCart { [BepInPlugin("DeathWizsh.PlantCart", "PlantCart", "0.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] internal class PlantCart : BaseUnityPlugin { public const string PluginGUID = "DeathWizsh.PlantCart"; public const string PluginName = "PlantCart"; public const string PluginVersion = "0.0.1"; public static PlantCart Instance; private AssetBundle assetBundle; public CustomPrefabs prefabs = new CustomPrefabs(); public static string currentTrader; public void Awake() { Instance = this; InitAssetBundle(); PluginConfig.Init(); PrefabManager.OnVanillaPrefabsAvailable += AddPieces; } private void AddPieces() { ItemHelper.CreateMaterial(prefabs.Plow, PluginConfig.rustedPlow); prefabs.PlantCart.AddComponent<Planter>(); PieceHelper.Create(prefabs.PlantCart, PluginConfig.piece1); currentTrader = PluginConfig.rustedPlow.trader.Value; GameObject prefab = PrefabManager.Instance.GetPrefab(currentTrader); Trader component = prefab.GetComponent<Trader>(); component.m_items.Add(UpdateHelper.CreateNewTradeItem()); PrefabManager.OnVanillaPrefabsAvailable -= AddPieces; } private void InitAssetBundle() { assetBundle = AssetUtils.LoadAssetBundleFromResources("plantcart_dw"); prefabs.PlantCart = assetBundle.LoadAsset<GameObject>("PlantCart_PC"); prefabs.Plow = assetBundle.LoadAsset<GameObject>("Plow_PC"); } } } namespace PlantCart.Types { internal class CraftingStationType { public static string None => "None"; public static string Disabled => "Disabled"; public static string Workbench => "Workbench"; public static string Forge => "Forge"; public static string Cauldron => "Cauldron"; public static string Stonecutter => "Stonecutter"; public static string ArtisanTable => "ArtisanTable"; public static string BlackForge => "BlackForge"; public static string GaldrTable => "GaldrTable"; } internal class GlobalKeyType { public static string DefeatedNothing => "DefeatedNothing"; public static string DefeatedNoBoss => "DefeatedNoBoss"; public static string DefeatedEikthyr => "defeated_eikthyr"; public static string DefeatedElder => "defeated_gdking"; public static string DefeatedBonemass => "defeated_bonemass"; public static string DefeatedModer => "defeated_dragon"; public static string DefeatedYagluth => "defeated_goblinking"; public static string DefeatedQueen => "defeated_queen"; public static string DefeatedFader => "defeated_fader"; public static string KilledBat => "killedBat"; public static string KilledTroll => "killedtroll"; public static string killedSurtling => "killed_surtling"; } internal enum RecipeUpdateType { ENABLE, RECIPE, CRAFTINGSTATION, MINREQUIREDSTATIONLEVEL, MINREQUIREDREPAIRLEVEL } internal class TraderType { public static string BogWitch => "BogWitch"; public static string Haldor => "Haldor"; public static string Hildir => "Hildir"; } } namespace PlantCart.Models { internal class CustomPrefabs { public GameObject PlantCart; public GameObject Plow; } internal class BuildPieceConfigOptions { public GameObject prefab; public string sectionName; public string recipeName; public bool enable = true; public string name; public string? description; public string? craftingStation; public string recipe; public int inventoryColumns = 3; public int inventoryRows = 1; public BuildPieceConfigOptions(GameObject prefab, string name, string recipe) { this.prefab = prefab; this.name = name; sectionName = name.Replace("'", "") ?? ""; this.recipe = recipe; recipeName = "Recipe_" + ((Object)prefab).name; } } internal class MaterialConfigOptions { public GameObject? prefab; public string? sectionName; public string? recipeName; public bool enable = true; public string? name; public string? description; public string? craftingStation; public int minStationLevel = 1; public string? recipe; public MaterialConfigOptions(GameObject prefab, string name, string recipe) { this.prefab = prefab; this.name = name; sectionName = name.Replace("'", "") ?? ""; this.recipe = recipe; recipeName = "Recipe_" + ((Object)prefab).name; } } internal class UpdateItemDataOptions { public string? name; public string? description; public bool? teleportable; } internal class UpdateRecipeOptions { public string? name = null; public bool? enable = null; public string? craftingStation = null; public string? requirements = null; public int? requiredStationLevel = null; public RecipeUpdateType updateType = RecipeUpdateType.RECIPE; public string? upgradeRequirements = null; public int? upgradeMultiplier = null; } internal class UpdateTraderOptions { public int? cost; public string? globalKey; public int? stack; public bool? teleportable; public string? trader; } } namespace PlantCart.Helpers { internal class ItemHelper { public static void CreateMaterial(GameObject prefab, MaterialConfig config) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown ItemConfig val = new ItemConfig(); val.Name = config.name.Value; val.Description = config.description.Value; ItemManager.Instance.AddItem(new CustomItem(prefab, true, val)); } } internal class PieceHelper { public static void Create(GameObject prefab, BuildPieceConfig config) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Expected O, but got Unknown try { PieceConfig val = new PieceConfig(); val.Enabled = config.enable.Value; val.Name = config.name.Value; val.Description = config.description.Value; val.CraftingStation = config.craftingStation.Value; val.PieceTable = PieceTables.Hammer; val.Category = PieceCategories.Misc; RequirementConfig[] asRequirementConfigArray = RecipeHelper.GetAsRequirementConfigArray(config.recipe.Value, null, null); if (asRequirementConfigArray == null || asRequirementConfigArray.Length == 0) { Logger.LogWarning((object)("Could not resolve recipe for: " + ((Object)prefab).name)); } else { val.Requirements = asRequirementConfigArray; } UpdateEnabled(prefab, config.enable.Value); UpdateName(prefab, config.name.Value); UpdateDescription(prefab, config.name.Value); UpdateCraftingStation(prefab, config.craftingStation.Value); UpdateRecipe(prefab, config.recipe.Value); UpdateInventorySize(prefab, config.inventoryColumns.Value, config.inventoryRows.Value); UpdateMass(prefab, config.cartMass.Value); PieceManager.Instance.AddPiece(new CustomPiece(prefab, true, val)); } catch (Exception ex) { Logger.LogError((object)("Could not create build piece: " + ex)); } } public static void UpdateEnabled(GameObject prefab, bool value) { try { if ((Object)(object)prefab == (Object)null) { throw new Exception("Prefab is null"); } Piece component = prefab.GetComponent<Piece>(); if ((Object)(object)component == (Object)null) { throw new Exception("Could not find Piece component"); } component.m_enabled = value; } catch (Exception ex) { Logger.LogError((object)("Could not update piece enabled: " + ex)); } } public static void UpdateName(GameObject prefab, string value) { try { if ((Object)(object)prefab == (Object)null) { throw new Exception("Prefab is null"); } Piece component = prefab.GetComponent<Piece>(); Vagon component2 = prefab.GetComponent<Vagon>(); if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null) { throw new Exception("Could not find Piece or Vagon component"); } component.m_name = value; component2.m_name = value; } catch (Exception ex) { Logger.LogError((object)("Could not update piece name: " + ex)); } } public static void UpdateDescription(GameObject prefab, string value) { try { if ((Object)(object)prefab == (Object)null) { throw new Exception("Prefab is null"); } Piece component = prefab.GetComponent<Piece>(); if ((Object)(object)component == (Object)null) { throw new Exception("Could not find Piece component"); } component.m_description = value; } catch (Exception ex) { Logger.LogError((object)("Could not update piece description: " + ex)); } } public static void UpdateCraftingStation(GameObject prefab, string value) { try { if ((Object)(object)prefab == (Object)null) { throw new Exception("Prefab is null"); } Piece component = prefab.GetComponent<Piece>(); if ((Object)(object)component == (Object)null) { throw new Exception("Could not find Piece component"); } string internalName = CraftingStations.GetInternalName(value); CraftingStation component2 = PrefabManager.Instance.GetPrefab(internalName).GetComponent<CraftingStation>(); if ((Object)(object)component2 == (Object)null) { throw new Exception("Could not find CraftingStation component"); } component.m_craftingStation = component2; } catch (Exception ex) { Logger.LogError((object)("Could not update piece crafting station: " + ex)); } } public static void UpdateRecipe(GameObject prefab, string value) { try { if ((Object)(object)prefab == (Object)null) { throw new Exception("Prefab is null"); } Piece component = prefab.GetComponent<Piece>(); if ((Object)(object)component == (Object)null) { throw new Exception("Could not find Piece component"); } Requirement[] asPieceRequirementArray = RecipeHelper.GetAsPieceRequirementArray(value, null, null); if (asPieceRequirementArray == null || asPieceRequirementArray.Length == 0) { Logger.LogWarning((object)("Could not resolve recipe for: " + ((Object)prefab).name)); } else { component.m_resources = asPieceRequirementArray; } } catch (Exception ex) { Logger.LogError((object)("Could not update piece recipe: " + ex)); } } public static void UpdateInventorySize(GameObject prefab, int width, int height) { try { if ((Object)(object)prefab == (Object)null) { throw new Exception("Prefab is null"); } if (width <= 0 || height <= 0) { Logger.LogWarning((object)"Container size cannot be smaller then 1x1!"); return; } Transform val = prefab.transform.Find("Container"); if ((Object)(object)val == (Object)null) { throw new Exception("Could not find Container object"); } Container component = ((Component)val).GetComponent<Container>(); if ((Object)(object)component == (Object)null) { throw new Exception("Could not find Container component"); } component.m_width = width; component.m_height = height; } catch (Exception ex) { Logger.LogError((object)("Could not update inventory size: " + ex)); } } public static void UpdateMass(GameObject prefab, float value) { try { if ((Object)(object)prefab == (Object)null) { throw new Exception("Prefab is null"); } Vagon component = prefab.GetComponent<Vagon>(); if ((Object)(object)component == (Object)null) { throw new Exception("Could not find Vagon component"); } component.m_baseMass = value; } catch (Exception ex) { Logger.LogError((object)("Could not update piece mass: " + ex)); } } } internal class RecipeHelper { private static readonly Regex _nukeWhiteSpaceRegex = new Regex("\\s+"); private static readonly Regex _recipeEntryRegex = new Regex("^([a-zA-Z0-9_]+:[0-9]+)$"); public static RequirementConfig[]? GetAsRequirementConfigArray(string configRecipe, string? upgradeRecipe, int? multiplier) { return GetAsRequirementConfigList(configRecipe, upgradeRecipe, multiplier)?.ToArray(); } public static Requirement[]? GetAsPieceRequirementArray(string configRecipe, string? upgradeRecipe, int? multiplier) { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown try { List<RequirementConfig> asRequirementConfigList = GetAsRequirementConfigList(configRecipe, upgradeRecipe, multiplier); List<Requirement> list = new List<Requirement>(); if (asRequirementConfigList == null) { return null; } foreach (RequirementConfig item in asRequirementConfigList) { GameObject prefab = PrefabManager.Instance.GetPrefab(item.Item); if ((Object)(object)prefab == (Object)null) { throw new Exception("Could not find item, please check config!"); } Requirement val = new Requirement(); val.m_resItem = prefab.GetComponent<ItemDrop>(); val.m_amount = item.Amount; val.m_recover = item.Recover; if (upgradeRecipe != null && multiplier.HasValue) { val.m_amountPerLevel = item.AmountPerLevel; } list.Add(val); } return list.ToArray(); } catch (Exception ex) { Logger.LogError((object)("Could not convert recipe to Piece.Requirement array: " + ex)); return null; } } public static List<RequirementConfig>? GetAsRequirementConfigList(string configRecipe, string? upgradeRecipe, int? multiplier) { //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown try { configRecipe = _nukeWhiteSpaceRegex.Replace(configRecipe, ""); if (upgradeRecipe != null) { upgradeRecipe = _nukeWhiteSpaceRegex.Replace(upgradeRecipe, ""); } if (!IsConfigRecipeValid(configRecipe, upgradeRecipe)) { Logger.LogWarning((object)"Config is not valid, please check the values"); return null; } List<RequirementConfig> list = new List<RequirementConfig>(); string[] array = configRecipe.Trim().Split(new char[1] { ',' }); string[] array2 = array; foreach (string text in array2) { RequirementConfig val = new RequirementConfig(); string[] array3 = text.Split(new char[1] { ':' }); val.Item = array3[0]; val.Amount = int.Parse(array3[1]); val.Recover = true; if (upgradeRecipe != null && !Utility.IsNullOrWhiteSpace(upgradeRecipe) && multiplier.HasValue) { string[] array4 = upgradeRecipe.Trim().Split(new char[1] { ',' }); string[] array5 = array4; foreach (string text2 in array5) { string[] array6 = text2.Split(new char[1] { ':' }); if (val.Item == array6[0]) { val.AmountPerLevel = int.Parse(array6[1]) * multiplier.Value; break; } } } list.Add(val); } return list; } catch (Exception ex) { Logger.LogError((object)("Could not convert recipe to RequirementConfig list: " + ex)); return null; } } public static bool IsConfigRecipeValid(string configRecipe, string? upgradeRecipe) { try { bool result = true; string[] array = configRecipe.Split(new char[1] { ',' }); string[] array2 = array; foreach (string text in array2) { if (!_recipeEntryRegex.IsMatch(text)) { result = false; Logger.LogWarning((object)("Cannot resolve " + text + " from the crafting recipe")); } } if (upgradeRecipe == null || Utility.IsNullOrWhiteSpace(upgradeRecipe)) { return result; } string[] array3 = upgradeRecipe.Split(new char[1] { ',' }); string[] array4 = array3; foreach (string text2 in array4) { if (!_recipeEntryRegex.IsMatch(text2)) { result = false; Logger.LogWarning((object)("Cannot resolve " + text2 + " from the upgrade recipe")); } } return result; } catch (Exception ex) { Logger.LogError((object)("Could not validate recipe due to an error: " + ex)); return false; } } public static void UpdateRecipe(UpdateRecipeOptions options) { try { CustomRecipe recipe = ItemManager.Instance.GetRecipe(options.name); if (recipe == null) { throw new Exception("Could not find recipe: " + options.name); } switch (options.updateType) { case RecipeUpdateType.ENABLE: if (!options.enable.HasValue) { throw new Exception("Enable is null"); } recipe.Recipe.m_enabled = options.enable.Value; break; case RecipeUpdateType.RECIPE: { if (options.requirements == null) { throw new Exception("Requirements is null"); } Requirement[] asPieceRequirementArray = GetAsPieceRequirementArray(options.requirements, options.upgradeRequirements, options.upgradeMultiplier); if (asPieceRequirementArray == null) { Logger.LogWarning((object)"Cannot update recipe, requirements is null"); } else { recipe.Recipe.m_resources = asPieceRequirementArray; } break; } case RecipeUpdateType.CRAFTINGSTATION: if (options.craftingStation == null || options.craftingStation == "") { throw new Exception("Craftingstation is null or empty string"); } if (options.craftingStation == "None") { recipe.Recipe.m_craftingStation = null; recipe.Recipe.m_enabled = true; } else if (options.craftingStation == "Disabled") { recipe.Recipe.m_craftingStation = null; recipe.Recipe.m_enabled = false; } else { string internalName = CraftingStations.GetInternalName(options.craftingStation); recipe.Recipe.m_enabled = true; recipe.Recipe.m_craftingStation = PrefabManager.Instance.GetPrefab(internalName).GetComponent<CraftingStation>(); } break; case RecipeUpdateType.MINREQUIREDSTATIONLEVEL: if (!options.requiredStationLevel.HasValue || options.requiredStationLevel < 1) { throw new Exception("Required station level is null or lower then 1"); } recipe.Recipe.m_minStationLevel = options.requiredStationLevel.Value; break; } } catch (Exception ex) { Logger.LogError((object)("Could not update recipe: " + ex)); } } } internal class UpdateHelper { public static void UpdateItemData(GameObject prefab, UpdateItemDataOptions options) { if ((Object)(object)prefab == (Object)null) { throw new Exception("Prefab is null"); } ItemData itemData = prefab.GetComponent<ItemDrop>().m_itemData; UpdateItemData(itemData, options); } public static void UpdateItemData(ItemData itemData, UpdateItemDataOptions options) { if (itemData == null) { throw new Exception("ItemData is null"); } if (options.name != null) { itemData.m_shared.m_name = options.name; } if (options.description != null) { itemData.m_shared.m_description = options.description; } if (options.teleportable.HasValue) { itemData.m_shared.m_teleportable = options.teleportable.Value; } } public static void UpdateTrader(UpdateTraderOptions options) { GameObject val = ZNetScene.instance.m_prefabs.Find((GameObject item) => ((Object)item).name == PlantCart.currentTrader); Trader component = val.GetComponent<Trader>(); TradeItem val2 = component.m_items.Find((TradeItem item) => (Object)(object)item.m_prefab == (Object)(object)PlantCart.Instance.prefabs.Plow.GetComponent<ItemDrop>()); if (val2 != null) { component.m_items.Remove(val2); } if (options.trader != null && options.trader != PlantCart.currentTrader) { GameObject val3 = ZNetScene.instance.m_prefabs.Find((GameObject item) => ((Object)item).name == options.trader); Trader component2 = val3.GetComponent<Trader>(); component2.m_items.Add(CreateNewTradeItem()); PlantCart.currentTrader = options.trader; } else { component.m_items.Add(CreateNewTradeItem()); } } public static TradeItem CreateNewTradeItem() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown TradeItem val = new TradeItem(); val.m_prefab = PlantCart.Instance.prefabs.Plow.GetComponent<ItemDrop>(); val.m_price = PluginConfig.rustedPlow.cost.Value; val.m_requiredGlobalKey = PluginConfig.rustedPlow.requiredGlobalKey.Value; val.m_stack = PluginConfig.rustedPlow.stack.Value; return val; } } } namespace PlantCart.Configs { internal class BuildPieceConfig { public static string[] craftingStationOptions = new string[9] { CraftingStationType.None, CraftingStationType.Disabled, CraftingStationType.Workbench, CraftingStationType.Forge, CraftingStationType.Stonecutter, CraftingStationType.Cauldron, CraftingStationType.ArtisanTable, CraftingStationType.BlackForge, CraftingStationType.GaldrTable }; public ConfigEntry<bool> enable; public ConfigEntry<string> name; public ConfigEntry<string> description; public ConfigEntry<string> craftingStation; public ConfigEntry<string> recipe; public ConfigEntry<int> inventoryColumns; public ConfigEntry<int> inventoryRows; public ConfigEntry<float> cartMass; public ConfigEntry<float> durabilityLoss; private int entryCount = 100; public void GenerateConfig(BuildPieceConfigOptions options) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown //IL_0079: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Expected O, but got Unknown //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Expected O, but got Unknown //IL_00ef: Expected O, but got Unknown //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Expected O, but got Unknown //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Expected O, but got Unknown //IL_0165: Expected O, but got Unknown //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Expected O, but got Unknown //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Expected O, but got Unknown //IL_01e4: Expected O, but got Unknown //IL_0213: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Expected O, but got Unknown //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Expected O, but got Unknown //IL_025a: Expected O, but got Unknown //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02c6: Expected O, but got Unknown //IL_02c6: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Expected O, but got Unknown //IL_02d0: Expected O, but got Unknown //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_031d: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Expected O, but got Unknown //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_0346: Expected O, but got Unknown //IL_0346: Expected O, but got Unknown //IL_0375: Unknown result type (might be due to invalid IL or missing references) //IL_038d: Unknown result type (might be due to invalid IL or missing references) //IL_0392: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_03ac: Expected O, but got Unknown //IL_03ac: Unknown result type (might be due to invalid IL or missing references) //IL_03b6: Expected O, but got Unknown //IL_03b6: Expected O, but got Unknown //IL_03e5: Unknown result type (might be due to invalid IL or missing references) //IL_03fd: Unknown result type (might be due to invalid IL or missing references) //IL_0402: Unknown result type (might be due to invalid IL or missing references) //IL_040a: Unknown result type (might be due to invalid IL or missing references) //IL_041c: Expected O, but got Unknown //IL_041c: Unknown result type (might be due to invalid IL or missing references) //IL_0426: Expected O, but got Unknown //IL_0426: Expected O, but got Unknown ConfigFile config = ((BaseUnityPlugin)PlantCart.Instance).Config; enable = config.Bind<bool>(new ConfigDefinition(options.sectionName, "Enable"), options.enable, new ConfigDescription("Wether the recipe for this piece is enabled", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); enable.SettingChanged += delegate { PieceHelper.UpdateEnabled(options.prefab, enable.Value); }; name = config.Bind<string>(new ConfigDefinition(options.sectionName, "Name"), options.name, new ConfigDescription("The name of this build piece", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); name.SettingChanged += delegate { PieceHelper.UpdateName(options.prefab, name.Value); }; description = config.Bind<string>(new ConfigDefinition(options.sectionName, "Description"), options.description, new ConfigDescription("The description of this build piece", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); description.SettingChanged += delegate { PieceHelper.UpdateDescription(options.prefab, description.Value); }; craftingStation = config.Bind<string>(new ConfigDefinition(options.sectionName, "Crafting station"), options.craftingStation, new ConfigDescription("The crafting station required to place this piece", (AcceptableValueBase)(object)new AcceptableValueList<string>(craftingStationOptions), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); craftingStation.SettingChanged += delegate { PieceHelper.UpdateCraftingStation(options.prefab, craftingStation.Value); }; recipe = config.Bind<string>(new ConfigDefinition(options.sectionName, "Recipe"), options.recipe, new ConfigDescription("The items required to place this build piece", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); recipe.SettingChanged += delegate { PieceHelper.UpdateRecipe(options.prefab, recipe.Value); }; inventoryColumns = config.Bind<int>(new ConfigDefinition(options.sectionName, "Inventory columns"), options.inventoryColumns, new ConfigDescription("The width (amount of slots) of the inventory", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); inventoryColumns.SettingChanged += delegate { PieceHelper.UpdateInventorySize(options.prefab, inventoryColumns.Value, inventoryRows.Value); }; inventoryRows = config.Bind<int>(new ConfigDefinition(options.sectionName, "Inventory rows"), options.inventoryRows, new ConfigDescription("The height (amount of slots) of the inventory", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); inventoryRows.SettingChanged += delegate { PieceHelper.UpdateInventorySize(options.prefab, inventoryColumns.Value, inventoryRows.Value); }; cartMass = config.Bind<float>(new ConfigDefinition(options.sectionName, "Cart mass"), 300f, new ConfigDescription("The mass of the cart, affects speed and control", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); cartMass.SettingChanged += delegate { PieceHelper.UpdateMass(options.prefab, cartMass.Value); }; durabilityLoss = config.Bind<float>(new ConfigDefinition(options.sectionName, "Durability loss"), 1f, new ConfigDescription("The amount of durability loss the cart takes on planting", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); } private int HandleOrder() { entryCount--; return (entryCount >= 0) ? entryCount : 0; } } internal class MaterialConfig { public static string[] craftingStationOptions = new string[9] { CraftingStationType.None, CraftingStationType.Disabled, CraftingStationType.Workbench, CraftingStationType.Forge, CraftingStationType.Stonecutter, CraftingStationType.Cauldron, CraftingStationType.ArtisanTable, CraftingStationType.BlackForge, CraftingStationType.GaldrTable }; public static string[] traderOptions = new string[3] { TraderType.BogWitch, TraderType.Haldor, TraderType.Hildir }; public ConfigEntry<string> name; public ConfigEntry<string> description; public ConfigEntry<string> trader; public ConfigEntry<int> cost; public ConfigEntry<int> stack; public ConfigEntry<bool> teleportable; public ConfigEntry<string> requiredGlobalKey; private int entryCount = 100; public void GenerateConfig(MaterialConfigOptions options) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown //IL_0079: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Expected O, but got Unknown //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Expected O, but got Unknown //IL_00ef: Expected O, but got Unknown //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Expected O, but got Unknown //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Expected O, but got Unknown //IL_015b: Expected O, but got Unknown //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Expected O, but got Unknown //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Expected O, but got Unknown //IL_01d4: Expected O, but got Unknown //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Expected O, but got Unknown //IL_023a: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Expected O, but got Unknown //IL_0244: Expected O, but got Unknown //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: Expected O, but got Unknown //IL_02a6: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Expected O, but got Unknown //IL_02b0: Expected O, but got Unknown //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_0304: Unknown result type (might be due to invalid IL or missing references) //IL_0316: Expected O, but got Unknown //IL_0316: Unknown result type (might be due to invalid IL or missing references) //IL_0320: Expected O, but got Unknown //IL_0320: Expected O, but got Unknown ConfigFile config = ((BaseUnityPlugin)PlantCart.Instance).Config; name = config.Bind<string>(new ConfigDefinition(options.sectionName, "Name"), options.name, new ConfigDescription("The name given to the item", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); name.SettingChanged += delegate { UpdateHelper.UpdateItemData(options.prefab, new UpdateItemDataOptions { name = name.Value }); }; description = config.Bind<string>(new ConfigDefinition(options.sectionName, "Description"), options.description, new ConfigDescription("The description given to the item", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); description.SettingChanged += delegate { UpdateHelper.UpdateItemData(options.prefab, new UpdateItemDataOptions { description = description.Value }); }; teleportable = config.Bind<bool>(new ConfigDefinition(options.sectionName, "Teleportable"), false, new ConfigDescription("Whether the item is teleportable", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); teleportable.SettingChanged += delegate { UpdateHelper.UpdateItemData(options.prefab, new UpdateItemDataOptions { teleportable = teleportable.Value }); }; trader = config.Bind<string>(new ConfigDefinition(options.sectionName, "Trader"), TraderType.Haldor, new ConfigDescription("The trader where this item is available", (AcceptableValueBase)(object)new AcceptableValueList<string>(traderOptions), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); trader.SettingChanged += delegate { UpdateHelper.UpdateTrader(new UpdateTraderOptions { trader = trader.Value }); }; cost = config.Bind<int>(new ConfigDefinition(options.sectionName, "Cost"), 300, new ConfigDescription("The amount this item cost at the trader", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); cost.SettingChanged += delegate { UpdateHelper.UpdateTrader(new UpdateTraderOptions { cost = cost.Value }); }; stack = config.Bind<int>(new ConfigDefinition(options.sectionName, "Stack"), 1, new ConfigDescription("The stack size of this item when buying from a trader", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); stack.SettingChanged += delegate { UpdateHelper.UpdateTrader(new UpdateTraderOptions { stack = stack.Value }); }; requiredGlobalKey = config.Bind<string>(new ConfigDefinition(options.sectionName, "Global Key"), GlobalKeyType.DefeatedModer, new ConfigDescription("The global key required for this item to show up at trader (boss killed)", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); requiredGlobalKey.SettingChanged += delegate { UpdateHelper.UpdateTrader(new UpdateTraderOptions { globalKey = requiredGlobalKey.Value }); }; } private int HandleOrder() { entryCount--; return (entryCount >= 0) ? entryCount : 0; } } internal static class PluginConfig { private static string piece1Name = "Plant Cart"; private static string piece1Recipe = "Wood:20, Copper:6, Silver:10, " + ((Object)PlantCart.Instance.prefabs.Plow).name + ":2"; public static BuildPieceConfig piece1 = new BuildPieceConfig(); public static string material1Name = "Rusted Plow"; public static MaterialConfig rustedPlow = new MaterialConfig(); public static void Init() { InitPiece1Config(); InitRustedPlowConfig(); } public static void InitPiece1Config() { try { BuildPieceConfigOptions options = new BuildPieceConfigOptions(PlantCart.Instance.prefabs.PlantCart, piece1Name, piece1Recipe) { description = "Plant crops effortlessly with a cart that sows seeds as you go.", craftingStation = CraftingStationType.Workbench }; piece1.GenerateConfig(options); } catch (Exception ex) { Logger.LogError((object)("Could not initialise " + piece1Name + " config: " + ex)); } } private static void InitRustedPlowConfig() { try { MaterialConfigOptions options = new MaterialConfigOptions(PlantCart.Instance.prefabs.Plow, material1Name, null) { description = "An old rusted plow, maybe it can be restored and used for something?", craftingStation = null }; rustedPlow.GenerateConfig(options); } catch (Exception ex) { Logger.LogError((object)("Could not initialise " + material1Name + " config: " + ex)); } } } } namespace PlantCart.Components { public class Planter : MonoBehaviour { private ZNetView netView; public Transform cartTransform; private Vector3 lastPosition; public float distanceThreshold = 1.1f; private List<string> m_allowedList = new List<string>(); private Dictionary<string, string> m_plantDict = new Dictionary<string, string>(); public void Awake() { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) netView = ((Component)this).gameObject.GetComponent<ZNetView>(); cartTransform = ((Component)this).transform; lastPosition = cartTransform.position; m_allowedList.Add("carrot"); m_allowedList.Add("turnip"); m_allowedList.Add("onion"); m_allowedList.Add("barley"); m_allowedList.Add("flax"); m_allowedList.Add("magecap"); m_allowedList.Add("jotunpuffs"); m_plantDict.Add("$item_carrotseeds", "sapling_carrot"); m_plantDict.Add("$item_carrot", "sapling_seedcarrot"); m_plantDict.Add("$item_turnipseeds", "sapling_turnip"); m_plantDict.Add("$item_turnip", "sapling_seedturnip"); m_plantDict.Add("$item_onionseeds", "sapling_onion"); m_plantDict.Add("$item_onion", "sapling_seedonion"); m_plantDict.Add("$item_barley", "sapling_barley"); m_plantDict.Add("$item_flax", "sapling_flax"); m_plantDict.Add("$item_magecap", "sapling_magecap"); m_plantDict.Add("$item_jotunpuffs", "sapling_jotunpuffs"); } public bool IsValidPlantPoint(RaycastHit raycast) { //IL_006d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)((RaycastHit)(ref raycast)).collider == (Object)null || (Object)(object)((Component)((RaycastHit)(ref raycast)).collider).gameObject == (Object)null || !((Object)((Component)((RaycastHit)(ref raycast)).collider).gameObject).name.Equals("terrain", StringComparison.OrdinalIgnoreCase)) { return false; } Heightmap component = ((Component)((RaycastHit)(ref raycast)).collider).gameObject.GetComponent<Heightmap>(); if ((Object)(object)component == (Object)null || !component.IsCultivated(((RaycastHit)(ref raycast)).point)) { return false; } return true; } public void Update() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0048: 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_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: 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_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02bb: Unknown result type (might be due to invalid IL or missing references) //IL_02bf: Unknown result type (might be due to invalid IL or missing references) try { if (netView.m_ghost) { return; } float num = Vector3.Distance(lastPosition, cartTransform.position); if (!(num >= distanceThreshold)) { return; } lastPosition = cartTransform.position; List<Transform> list = new List<Transform>(); list.Add(((Component)this).transform.Find("PlantPointLeft")); list.Add(((Component)this).transform.Find("PlantPointRight")); RaycastHit raycast = default(RaycastHit); RaycastHit raycast2 = default(RaycastHit); RaycastHit raycast3 = default(RaycastHit); Vector3 val5 = default(Vector3); float y = default(float); foreach (Transform item in list) { Vector3 val = item.position + item.up * 0.4f; Vector3 val2 = val + item.forward * -0.55f; Vector3 val3 = val + item.forward * 0.55f; Physics.Raycast(val, Vector3.down, ref raycast, 1f); Physics.Raycast(val2, Vector3.down, ref raycast2, 1f); Physics.Raycast(val3, Vector3.down, ref raycast3, 1f); if (!IsValidPlantPoint(raycast) || !IsValidPlantPoint(raycast2) || !IsValidPlantPoint(raycast3)) { continue; } Collider[] array = Physics.OverlapSphere(((RaycastHit)(ref raycast)).point, 0.5f, LayerMask.GetMask(new string[1] { "piece_nonsolid" })); if (array.Length != 0) { continue; } Container component = ((Component)((Component)this).transform.Find("Container")).GetComponent<Container>(); Inventory inventory = component.GetInventory(); List<ItemData> allItemsInGridOrder = inventory.GetAllItemsInGridOrder(); allItemsInGridOrder.Reverse(); List<ItemData> list2 = allItemsInGridOrder.Where((ItemData item) => m_allowedList.Any((string other) => item.m_shared.m_name.Contains(other))).ToList(); if (list2.Count == 0) { continue; } ItemData val4 = list2.First(); if (val4 == null) { continue; } string valueSafe = GeneralExtensions.GetValueSafe<string, string>(m_plantDict, val4.m_shared.m_name); if (valueSafe != null && !(valueSafe == "")) { ((Vector3)(ref val5))..ctor(item.position.x, item.position.y, item.position.z); if (ZoneSystem.instance.FindFloor(val5, ref y)) { val5.y = y; } GameObject val6 = Object.Instantiate<GameObject>(PrefabManager.Instance.GetPrefab(valueSafe), val5, item.rotation); Piece component2 = val6.GetComponent<Piece>(); component2.m_placeEffect.Create(val5, item.rotation, (Transform)null, 1f, -1); inventory.RemoveOneItem(val4); if (PluginConfig.piece1.durabilityLoss.Value > 0f) { WearNTear component3 = ((Component)this).gameObject.GetComponent<WearNTear>(); component3.ApplyDamage(PluginConfig.piece1.durabilityLoss.Value, (HitData)null); } } } } catch (Exception ex) { Logger.LogError((object)("Something went wrong in Planter update: " + ex)); } } } }