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 PlantThings v1.1.0
PlantThings.dll
Decompiled 2 years agousing 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 BepInEx; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; 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("PlantThings")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("PlantIt")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")] [assembly: AssemblyFileVersion("1.1.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.1.0.0")] namespace PlantThings { internal static class Category { private static readonly string _misc = "Misc."; private static readonly string _hanging = "Hanging"; private static readonly string _noPot = "No Pot"; private static readonly string _potted = "Potted"; public static readonly string[] ShovelCategories = new string[4] { _misc, _hanging, _noPot, _potted }; public static readonly string[] MiscPrefabs = new string[35] { "custompiece_fancypot", "custompiece_fancypotl", "custompiece_hangingpot_large", "custompiece_hangingpot_small", "custompiece_tcpot1", "custompiece_tcpot1l", "custompiece_tcpot2", "custompiece_tcpot2l", "custompiece_tcpot3", "custompiece_tcpot3l", "custompiece_tcpotrectangle", "custompiece_tcpotrectanglel", "custompiece_tcpotsquare", "custompiece_tcpotsquarel", "$custompiece_stump1", "$custompiece_stump2", "$custompiece_stump3", "$custompiece_stump4", "$custompiece_stump5", "$custompiece_stump6", "$custompiece_stump7", "$custompiece_log1", "$custompiece_log2", "$custompiece_log3", "$custompiece_log4", "$custompiece_log5", "$custompiece_stumptable", "$custompiece_grassblock_small", "$custompiece_grassblock_medium", "$custompiece_grassblock_large", "$custompiece_dirtblock_small", "$custompiece_dirtblock_medium", "$custompiece_dirtblock_large", "$custompiece_grassblock_small_test", "$custompiece_grassblock_small_test2" }; public static readonly string[] HangingPrefabs = new string[15] { "custompiece_vines3", "custompiece_vines4", "custompiece_vines5", "custompiece_vines6", "custompiece_vines7", "custompiece_vines10", "custompiece_vines11", "custompiece_vines12", "custompiece_vinesvanilla", "custompiece_vinesvanillabig", "custompiece_vinesvanillastretched", "custompiece_vines1.2", "custompiece_vines1", "custompiece_hangingplant", "custompiece_hangingplant1.2" }; public static readonly string[] NoPotPrefabs = new string[26] { "custompiece_vines8", "custompiece_vines9", "custompiece_barrelcactus", "custompiece_cactus1", "custompiece_cactus1.2", "custompiece_cactus2", "custompiece_desertlily", "custompiece_desertmarigold", "custompiece_evergladespalm", "custompiece_hibiscusflower", "custompiece_ivorycanepalm", "custompiece_ladypalm", "custompiece_pricklypear", "custompiece_venusflytrap", "custompiece_aeonium", "custompiece_aloe", "custompiece_bromeliad", "custompiece_ivy1", "custompiece_ivy1.2", "custompiece_cattail", "custompiece_kelp", "custompiece_kelpbig", "custompiece_rosevine", "custompiece_tallflowerbush", "custompiece_vines2", "$custompiece_blackpine" }; public static readonly string[] PottedPrefabs = new string[36] { "custompiece_birdofparadise", "custompiece_bonsai", "custompiece_coffeeplant", "custompiece_fiddleleaf", "custompiece_littlehouseplant", "custompiece_orchid", "custompiece_spikyplant", "custompiece_umbrellapalm", "custompiece_rubberfig", "custompiece_tallhouseplant", "custompiece_aeoniums", "custompiece_bamboo", "custompiece_coolpot", "custompiece_miscplant1", "custompiece_miscplant2", "custompiece_orchid2", "custompiece_pottedcactus1", "custompiece_pottedcactus2", "custompiece_smallpottedplant", "custompiece_weirdflowers", "$custompiece_s1_roundcactuspinkflowers", "$custompiece_s2_tallcactusredflower", "$custompiece_s3_pottedpricklypear", "$custompiece_s4_snakeplant", "$custompiece_s5_aloe", "$custompiece_s6_pachy", "$custompiece_s7_calisunset", "$custompiece_s8_towercactus", "$custompiece_s9_whiteflowers", "$custompiece_s10_fatboi", "$custompiece_s11_clehmannii", "$custompiece_s11_cLehmannii", "$custompiece_s12_splitrocks", "$custompiece_s13_roundcactusyellowflowers", "$custompiece_s14_roseaeonium", "$custompiece_s15_euphorbia" }; public static string GetCategory(string prefabName) { if (MiscPrefabs.Contains(prefabName)) { return _misc; } if (HangingPrefabs.Contains(prefabName)) { return _hanging; } if (NoPotPrefabs.Contains(prefabName)) { return _noPot; } if (PottedPrefabs.Contains(prefabName)) { return _potted; } return null; } } internal static class Name { private static readonly Dictionary<string, string> _displayNames = new Dictionary<string, string> { { "custompiece_fancypot", "Fancy Pot" }, { "custompiece_fancypotl", "Fancy Pot (L)" }, { "custompiece_hangingpot_large", "Hangin Pot (L)" }, { "custompiece_hangingpot_small", "Hanging Pot (S)" }, { "custompiece_tcpot1", "Clay Pot 1" }, { "custompiece_tcpot1l", "Clay Pot 1 (L)" }, { "custompiece_tcpot2", "Clay Pot 2" }, { "custompiece_tcpot2l", "Clay Pot 2 (L)" }, { "custompiece_tcpot3", "Clay Pot 3" }, { "custompiece_tcpot3l", "Clay Pot 3 (L)" }, { "custompiece_tcpotrectangle", "Clay Pot Rectangle" }, { "custompiece_tcpotrectanglel", "Clay Pot Rectangle (L)" }, { "custompiece_tcpotsquare", "Clay Pot Square" }, { "custompiece_tcpotsquarel", "Clay Pot Square (L)" }, { "$custompiece_stump1", "Stump 1" }, { "$custompiece_stump2", "Stump 2" }, { "$custompiece_stump3", "Stump 3" }, { "$custompiece_stump4", "Stump 4" }, { "$custompiece_stump5", "Stump 5" }, { "$custompiece_stump6", "Stump 6" }, { "$custompiece_stump7", "Stump 7" }, { "$custompiece_log1", "Log 1" }, { "$custompiece_log2", "Log 2" }, { "$custompiece_log3", "Log 3" }, { "$custompiece_log4", "Log 4" }, { "$custompiece_log5", "Log 5" }, { "$custompiece_stumptable", "Stump Table" }, { "$custompiece_grassblock_small", "Grassblock (S)" }, { "$custompiece_grassblock_medium", "Grassblock (M)" }, { "$custompiece_grassblock_large", "Grassblock (L)" }, { "$custompiece_dirtblock_small", "Dirtblock (S)" }, { "$custompiece_dirtblock_medium", "Dirtblock (M)" }, { "$custompiece_dirtblock_large", "Dirtblock (L)" }, { "$custompiece_grassblock_small_test", "Grassblock Test (S)" }, { "$custompiece_grassblock_small_test2", "Grassblock Test 2 (S)" }, { "custompiece_vines3", "Vines 3" }, { "custompiece_vines4", "Vines 4" }, { "custompiece_vines5", "Vines 5" }, { "custompiece_vines6", "Vines 6" }, { "custompiece_vines7", "Vines 7" }, { "custompiece_vines10", "Vines 10" }, { "custompiece_vines11", "Vines 11" }, { "custompiece_vines12", "Vines 12" }, { "custompiece_vinesvanilla", "Vines Vanilla" }, { "custompiece_vinesvanillabig", "Vines Vanilla (L)" }, { "custompiece_vinesvanillastretched", "Vines Vanilla Stretched" }, { "custompiece_vines1.2", "Vines 1.2" }, { "custompiece_vines1", "Vines 1" }, { "custompiece_hangingplant", "Hanging Plant" }, { "custompiece_hangingplant1.2", "Hanging Plant 2" }, { "custompiece_vines8", "Vines 8" }, { "custompiece_vines9", "Vines 9" }, { "custompiece_barrelcactus", "Barrel Cactus" }, { "custompiece_cactus1", "Cactus 1" }, { "custompiece_cactus1.2", "Cactus 1.2" }, { "custompiece_cactus2", "Cactus 2" }, { "custompiece_desertlily", "Desert Lily" }, { "custompiece_desertmarigold", "Desert Marigold" }, { "custompiece_evergladespalm", "Everglades Palm" }, { "custompiece_hibiscusflower", "Hibiscus Flower" }, { "custompiece_ivorycanepalm", "Ivory Cane Palm" }, { "custompiece_ladypalm", "Lady Palm" }, { "custompiece_pricklypear", "Prickly Pear" }, { "custompiece_venusflytrap", "Venus FLy Trap" }, { "custompiece_aeonium", "Aeonium" }, { "custompiece_aloe", "Aloe" }, { "custompiece_bromeliad", "Bromeliad" }, { "custompiece_ivy1", "Ivy 1" }, { "custompiece_ivy1.2", "Ivy 2" }, { "custompiece_cattail", "Cattail" }, { "custompiece_kelp", "Kelp" }, { "custompiece_kelpbig", "Kelp (L)" }, { "custompiece_rosevine", "Rosevine" }, { "custompiece_tallflowerbush", "Tall Flower Bush" }, { "custompiece_vines2", "Vines 2" }, { "$custompiece_blackpine", "Blackpine" }, { "custompiece_birdofparadise", "Bird of Paradise" }, { "custompiece_bonsai", "Bonsai" }, { "custompiece_coffeeplant", "Coffee Plant" }, { "custompiece_fiddleleaf", "Fiddleleaf" }, { "custompiece_littlehouseplant", "Little House Plant" }, { "custompiece_orchid", "Orchid" }, { "custompiece_spikyplant", "Spiky Plant" }, { "custompiece_umbrellapalm", "Umbrellapalm" }, { "custompiece_rubberfig", "Rubberfig" }, { "custompiece_tallhouseplant", "Tall House Plant" }, { "custompiece_aeoniums", "Aeoniums" }, { "custompiece_bamboo", "Bamboo" }, { "custompiece_coolpot", "Cool Pot" }, { "custompiece_miscplant1", "Misc Plant 1" }, { "custompiece_miscplant2", "Misc Plant 2" }, { "custompiece_orchid2", "Orchid 2" }, { "custompiece_pottedcactus1", "Potted Cactus 1" }, { "custompiece_pottedcactus2", "Potted Cactus 2" }, { "custompiece_smallpottedplant", "Small Potted Plant" }, { "custompiece_weirdflowers", "Weird Flowers" }, { "$custompiece_s1_roundcactuspinkflowers", "Round Cactus Pink Flowers" }, { "$custompiece_s2_tallcactusredflower", "Tall Cactus Red Flower" }, { "$custompiece_s3_pottedpricklypear", "Potted Prickly Pear" }, { "$custompiece_s4_snakeplant", "Snake Plant" }, { "$custompiece_s5_aloe", "Aloe" }, { "$custompiece_s6_pachy", "Pachy" }, { "$custompiece_s7_calisunset", "Calisunset" }, { "$custompiece_s8_towercactus", "Towercactus" }, { "$custompiece_s9_whiteflowers", "White Flowers" }, { "$custompiece_s10_fatboi", "Fat boi" }, { "$custompiece_s11_clehmannii", "Clehmannii" }, { "$custompiece_s11_cLehmannii", "Clehmannii" }, { "$custompiece_s12_splitrocks", "Split Rocks" }, { "$custompiece_s13_roundcactusyellowflowers", "Round Cactus Yellow Flowers" }, { "$custompiece_s14_roseaeonium", "Rose Aeonium" }, { "$custompiece_s15_euphorbia", "Euphorbia" } }; public static string GetName(string assetName) { if (_displayNames.ContainsKey(assetName)) { return _displayNames[assetName]; } return assetName; } } internal static class Requirements { public static Dictionary<string, int> WoodRequired = new Dictionary<string, int> { { "$custompiece_log1", 5 }, { "$custompiece_log2", 5 }, { "$custompiece_log3", 5 }, { "$custompiece_log4", 5 }, { "$custompiece_log5", 5 }, { "$custompiece_stumptable", 10 }, { "$custompiece_grassblock_medium", 5 }, { "$custompiece_grassblock_large", 10 }, { "$custompiece_dirtblock_medium", 5 }, { "$custompiece_dirtblock_large", 10 }, { "$custompiece_blackpine", 10 } }; } [BepInPlugin("bruce.valheim.comfymods.", "PlantThings", "1.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class PlantThings : BaseUnityPlugin { public const string PluginGUID = "bruce.valheim.comfymods."; public const string PluginName = "PlantThings"; public const string PluginVersion = "1.1.0"; private static AssetBundle assetplanter; private static readonly string _plantItPieceTable = "_PlantitPieceTable"; private static readonly string[] _prefabAssetBundleNames = new string[7] { "custompiece_plantsetfixedcolliders", "custompiece_plantset2", "plantset3", "stumpsandlogs", "misc", "pottedsucculents", "plantset4" }; private static Dictionary<string, AssetBundle> _assetBundles = new Dictionary<string, AssetBundle>(); private static Dictionary<string, string> _assetsByBundle = new Dictionary<string, string>(); private Harmony _harmony; private static ManualLogSource _logger; private void Awake() { _logger = ((BaseUnityPlugin)this).Logger; LoadAssets(); LoadTable(); AddPieces(); _harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "bruce.valheim.comfymods."); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private void LoadAssets() { assetplanter = AssetUtils.LoadAssetBundleFromResources("shovel", typeof(PlantThings).Assembly); string[] prefabAssetBundleNames = _prefabAssetBundleNames; foreach (string text in prefabAssetBundleNames) { AssetBundle val = AssetUtils.LoadAssetBundleFromResources(text, typeof(PlantThings).Assembly); if ((Object)(object)val == (Object)null) { LogWarning("PlantIt: could not load asset bundle " + text); } else { _assetBundles.Add(text, val); } } } private static void LoadTable() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown GameObject val = assetplanter.LoadAsset<GameObject>(_plantItPieceTable); CustomPieceTable val2 = new CustomPieceTable(val, new PieceTableConfig { CanRemovePieces = true, UseCategories = false, UseCustomCategories = true, CustomCategories = Category.ShovelCategories }); PieceManager.Instance.AddPieceTable(val2); LoadShovel(); } private static void LoadShovel() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown GameObject val = assetplanter.LoadAsset<GameObject>("$PlumgaPlantItShovel"); ItemConfig val2 = new ItemConfig(); val2.Amount = 1; val2.CraftingStation = "piece_workbench"; val2.RepairStation = "piece_workbench"; val2.MinStationLevel = 1; val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig { Item = "Wood", Amount = 1, AmountPerLevel = 1 } }; CustomItem val3 = new CustomItem(val, true, val2); ItemManager.Instance.AddItem(val3); } private static void AddPieces() { foreach (KeyValuePair<string, AssetBundle> assetBundle in _assetBundles) { string[] allAssetNames = assetBundle.Value.GetAllAssetNames(); foreach (string assetName in allAssetNames) { AddPiece(assetName, assetBundle.Value); } } } private static void AddPiece(string assetName, AssetBundle bundle) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Expected O, but got Unknown //IL_00d5: Unknown result type (might be due to invalid IL or missing references) string baseName = GetBaseName(assetName); GameObject val = bundle.LoadAsset<GameObject>(baseName); if ((Object)(object)val == (Object)null || Category.GetCategory(baseName) == null) { LogWarning("Piece " + baseName + " not added. GameObject not found."); return; } PieceConfig val2 = new PieceConfig(); val2.PieceTable = _plantItPieceTable; val2.Category = Category.GetCategory(baseName); val2.AllowedInDungeons = false; val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig { Item = "Wood", Amount = GetAmount(baseName), Recover = true } }; CustomPiece val3 = new CustomPiece(val, false, val2); val3.Piece.m_name = Name.GetName(baseName); val3.Piece.m_comfort = 0; val3.Piece.m_comfortGroup = (ComfortGroup)0; PieceManager.Instance.AddPiece(val3); } private static string GetBaseName(string bundleName) { string text = bundleName.Split(new char[1] { '/' }).LastOrDefault(); if (text == null) { return bundleName; } return text.Replace(".prefab", ""); } private static int GetAmount(string name) { if (Requirements.WoodRequired.Keys.Contains(name)) { return Requirements.WoodRequired[name]; } return 2; } public static void Log(string message) { _logger.LogInfo((object)(message ?? "")); } public static void LogWarning(string message) { _logger.LogWarning((object)(message ?? "")); } } } namespace PlantThings.Patches { [HarmonyPatch(typeof(Piece))] internal static class PiecePatch { private static string _plantThingsVerificationField = "PlantThings"; private static string _plantThingsVerificationValue = "Yes"; [HarmonyPostfix] [HarmonyPatch("SetCreator")] private static void SetCreatorPostfix(ref Piece __instance, long uid) { ZNetView val = default(ZNetView); if (!((Object)(object)__instance == (Object)null) && !((Object)(object)((Component)__instance).gameObject == (Object)null) && ((Component)__instance).gameObject.TryGetComponent<ZNetView>(ref val) && val.GetZDO() != null && Category.GetCategory(((Object)((Component)__instance).gameObject).name.Replace("(Clone)", "")) != null) { val.GetZDO().Set(_plantThingsVerificationField, _plantThingsVerificationValue); } } } }