using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using ComfyLib; using HarmonyLib; using Jotunn.Managers; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("PotteryBarn")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("PotteryBarn")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("cda4d928-01d6-4d77-af0d-9caff7369336")] [assembly: AssemblyFileVersion("1.21.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.21.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace PotteryBarn { public static class PluginConfig { public static ConfigEntry IsModEnabled { get; private set; } public static void BindConfig(ConfigFile config) { IsModEnabled = config.BindInOrder("_Global", "isModEnabled", defaultValue: true, "Globally enable or disable this mod (restart required)."); } } public static class PieceExtensions { public static Piece SetCanBeRemoved(this Piece piece, bool canBeRemoved) { piece.m_canBeRemoved = canBeRemoved; return piece; } public static Piece SetCategory(this Piece piece, PieceCategory pieceCategory) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) piece.m_category = pieceCategory; return piece; } public static Piece SetComfort(this Piece piece, int comfort) { piece.m_comfort = comfort; return piece; } public static Piece SetCraftingStation(this Piece piece, CraftingStation craftingStation) { piece.m_craftingStation = craftingStation; return piece; } public static Piece SetGroundOnly(this Piece piece, bool groundOnly) { piece.m_groundOnly = groundOnly; return piece; } public static Piece SetName(this Piece piece, string name) { piece.m_name = name; return piece; } public static Piece SetResources(this Piece piece, params Requirement[] requirements) { piece.m_resources = requirements; return piece; } public static Piece SetTargetNonPlayerBuilt(this Piece piece, bool canTarget) { piece.m_targetNonPlayerBuilt = canTarget; return piece; } public static Piece ModifyResource(this Piece piece, string resourceName, int? amount = null, int? amountPerLevel = null, bool? recover = null) { if (!amount.HasValue && !amountPerLevel.HasValue && !recover.HasValue) { throw new InvalidOperationException("At least one of the optional parameters must be specified!"); } Requirement resource = piece.GetResource(resourceName); if (amount.HasValue) { resource.m_amount = amount.Value; } if (amountPerLevel.HasValue) { resource.m_amountPerLevel = amountPerLevel.Value; } if (recover.HasValue) { resource.m_recover = recover.Value; } return piece; } public static Requirement GetResource(this Piece piece, string resourceName) { Requirement[] resources = piece.m_resources; foreach (Requirement val in resources) { if (((Object)val.m_resItem).name == resourceName) { return val; } } throw new InvalidOperationException("No matching resource '" + resourceName + "' for Piece " + piece.m_name + "."); } } public static class PieceRequirementExtensions { public static Requirement SetAmount(this Requirement requirement, int amount) { requirement.m_amount = amount; return requirement; } public static Requirement SetRecover(this Requirement requirement, bool recover) { requirement.m_recover = recover; return requirement; } } public static class PieceTableExtensions { public static PieceTable AddPiece(this PieceTable pieceTable, Piece piece) { if (!pieceTable.m_pieces.Contains(((Component)piece).gameObject)) { pieceTable.m_pieces.Add(((Component)piece).gameObject); } return pieceTable; } } public static class CreativeShop { public static readonly PotteryPieceList CultivatorPieces = new PotteryPieceList().AddPiece("GlowingMushroom", PieceConstants.Workstation.None, new List(2) { ("MushroomBlue", 1), ("MushroomYellow", 3) }).AddPiece("marker01", PieceConstants.Workstation.None, new List(1) { ("Stone", 5) }); public static readonly PotteryPieceList HammerPieces = new PotteryPieceList().AddPiece("Ashlands_Fortress_Floor", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("Grausten", 4) }).AddPiece("Ashlands_Fortress_Gate", "piece_stonecutter", new List(2) { ("MushroomBlue", 2), ("Grausten", 15) }).AddPiece("Ashlands_Fortress_Gate_Door", "blackforge", new List(3) { ("MushroomBlue", 2), ("FlametalNew", 6), ("Bronze", 6) }) .AddPiece("Ashlands_Fortress_Wall_Spikes", "blackforge", new List(3) { ("MushroomBlue", 1), ("FlametalNew", 2), ("Bronze", 2) }) .AddPiece("Ashlands_Wall_2x2", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("Grausten", 6) }) .AddPiece("Ashlands_Wall_2x2_cornerR", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("Grausten", 6) }) .AddPiece("Ashlands_Wall_2x2_cornerR_top", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("Grausten", 6) }) .AddPiece("Ashlands_Wall_2x2_edge", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("Grausten", 6) }) .AddPiece("Ashlands_Wall_2x2_edge_top", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("Grausten", 6) }) .AddPiece("Ashlands_Wall_2x2_edge2", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("Grausten", 6) }) .AddPiece("Ashlands_Wall_2x2_edge2_top", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("Grausten", 6) }) .AddPiece("Ashlands_Wall_2x2_top", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("Grausten", 6) }) .AddPiece("asksvin_carrion", "piece_workbench", new List(4) { ("MushroomBlue", 1), ("AsksvinCarrionNeck", 1), ("AsksvinCarrionRibcage", 1), ("AsksvinCarrionSkull", 1) }) .AddPiece("asksvin_carrion2", "piece_workbench", new List(4) { ("MushroomBlue", 1), ("AsksvinCarrionNeck", 1), ("AsksvinCarrionRibcage", 1), ("AsksvinCarrionSkull", 1) }) .AddPiece("blackmarble_altar_crystal_broken", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("Crystal", 8) }) .AddPiece("blackmarble_post01", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("BlackMarble", 15) }) .AddPiece("Charred_altar_bellfragment", "piece_stonecutter", new List(4) { ("MushroomBlue", 3), ("BellFragment", 3), ("Grausten", 5), ("Crystal", 5) }) .AddPiece("CharredBanner1", "piece_workbench", new List(3) { ("MushroomBlue", 1), ("Blackwood", 4), ("JuteRed", 2) }) .AddPiece("CharredBanner2", "piece_workbench", new List(3) { ("MushroomBlue", 1), ("Blackwood", 3), ("JuteRed", 1) }) .AddPiece("CharredBanner3", "piece_workbench", new List(3) { ("MushroomBlue", 1), ("Blackwood", 2), ("JuteRed", 1) }) .AddPiece("CreepProp_egg_hanging01", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("RoyalJelly", 20) }) .AddPiece("CreepProp_entrance1", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("RoyalJelly", 20) }) .AddPiece("CreepProp_hanging01", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("RoyalJelly", 10) }) .AddPiece("CreepProp_wall01", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("RoyalJelly", 10) }) .AddPiece("dverger_demister", "piece_workbench", new List(3) { ("MushroomBlue", 2), ("Iron", 2), ("Wisp", 20) }) .AddPiece("dverger_demister_large", "piece_workbench", new List(3) { ("MushroomBlue", 10), ("Iron", 4), ("Wisp", 50) }) .AddPiece("dvergrprops_barrel", "piece_workbench", new List(3) { ("MushroomBlue", 1), ("YggdrasilWood", 15), ("Copper", 4) }) .AddPiece("dvergrprops_bed", "piece_workbench", new List(4) { ("MushroomBlue", 1), ("YggdrasilWood", 4), ("Copper", 2), ("LoxPelt", 2) }) .AddPiece("dvergrprops_chair", "piece_workbench", new List(3) { ("MushroomBlue", 1), ("YggdrasilWood", 2), ("Copper", 1) }) .AddPiece("dvergrprops_crate", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("YggdrasilWood", 4) }) .AddPiece("dvergrprops_crate_long", "piece_workbench", new List(3) { ("MushroomBlue", 1), ("YggdrasilWood", 4), ("Copper", 1) }) .AddPiece("dvergrprops_hooknchain", "blackforge", new List(2) { ("MushroomBlue", 1), ("Chain", 10) }) .AddPiece("dvergrprops_shelf", "piece_workbench", new List(3) { ("MushroomBlue", 1), ("YggdrasilWood", 6), ("Copper", 2) }) .AddPiece("dvergrprops_stool", "piece_workbench", new List(3) { ("MushroomBlue", 1), ("YggdrasilWood", 2), ("Copper", 1) }) .AddPiece("dvergrprops_table", "piece_workbench", new List(3) { ("MushroomBlue", 1), ("YggdrasilWood", 4), ("Copper", 2) }) .AddPiece("dvergrtown_creep_door", "piece_workbench", new List(2) { ("MushroomBlue", 2), ("RoyalJelly", 20) }) .AddPiece("dvergrtown_slidingdoor", "piece_workbench", new List(3) { ("MushroomBlue", 2), ("BlackMarble", 6), ("Copper", 6) }) .AddPiece("dvergrtown_wood_crane", "blackforge", new List(3) { ("MushroomBlue", 2), ("YggdrasilWood", 20), ("Copper", 4) }) .AddPiece("dvergrtown_wood_support", "blackforge", new List(2) { ("MushroomBlue", 2), ("YggdrasilWood", 20) }) .AddPiece("fader_bellholder", "blackforge", new List(2) { ("MushroomBlue", 1), ("FlametalNew", 5) }) .AddPiece("goblin_banner", "piece_workbench", new List(4) { ("MushroomBlue", 1), ("LeatherScraps", 6), ("Bloodbag", 2), ("BoneFragments", 4) }) .AddPiece("goblin_fence", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("BoneFragments", 8) }) .AddPiece("goblin_pole", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("BoneFragments", 8) }) .AddPiece("goblin_pole_small", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("BoneFragments", 4) }) .AddPiece("goblin_roof_45d", "piece_workbench", new List(3) { ("MushroomBlue", 1), ("DeerHide", 2), ("BoneFragments", 8) }) .AddPiece("goblin_roof_45d_corner", "piece_workbench", new List(3) { ("MushroomBlue", 1), ("DeerHide", 2), ("BoneFragments", 8) }) .AddPiece("goblin_roof_cap", "piece_workbench", new List(3) { ("MushroomBlue", 2), ("DeerHide", 6), ("BoneFragments", 12) }) .AddPiece("goblin_stairs", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("BoneFragments", 4) }) .AddPiece("goblin_stepladder", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("BoneFragments", 4) }) .AddPiece("goblin_woodwall_1m", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("BoneFragments", 4) }) .AddPiece("goblin_woodwall_2m", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("BoneFragments", 8) }) .AddPiece("goblin_woodwall_2m_ribs", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("BoneFragments", 8) }) .AddPiece("goblinking_totemholder", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("BoneFragments", 4) }) .AddPiece("GraveStone_CharredTwitcherNest", "piece_stonecutter", new List(3) { ("MushroomBlue", 1), ("Grausten", 5), ("CharcoalResin", 1) }) .AddPiece("GraveStone_Elite_CharredTwitcherNest", "piece_stonecutter", new List(3) { ("MushroomBlue", 1), ("Grausten", 5), ("CharcoalResin", 1) }) .AddPiece("MountainKit_brazier", "forge", new List(3) { ("MushroomBlue", 1), ("Coal", 2), ("Bronze", 2) }) .AddPiece("MountainKit_brazier_blue", "forge", new List(3) { ("MushroomBlue", 1), ("Coal", 2), ("Bronze", 2) }) .AddPiece("MountainKit_brazier_purple", "forge", new List(3) { ("MushroomBlue", 1), ("Coal", 2), ("Bronze", 2) }) .AddPiece("MountainKit_wood_gate", "piece_workbench", new List(3) { ("MushroomBlue", 1), ("Wood", 10), ("Iron", 3) }) .AddPiece("piece_pot1_red", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("CharcoalResin", 1) }) .AddPiece("piece_pot2_red", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("CharcoalResin", 1) }) .AddPiece("piece_pot3_red", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("CharcoalResin", 1) }) .AddPiece("Skull1", "piece_workbench", new List(2) { ("MushroomBlue", 1), ("TrophySkeleton", 1) }) .AddPiece("Skull2", "piece_workbench", new List(3) { ("MushroomBlue", 2), ("BoneFragments", 50), ("TrophySkeleton", 1) }) .AddPiece("StatueCorgi", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("Stone", 10) }) .AddPiece("StatueDeer", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("Stone", 10) }) .AddPiece("StatueEvil", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("Stone", 10) }) .AddPiece("StatueHare", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("Stone", 10) }) .AddPiece("StatueSeed", "piece_stonecutter", new List(2) { ("MushroomBlue", 1), ("Stone", 10) }) .AddPiece("stonechest", "piece_stonecutter", new List(2) { ("MushroomBlue", 2), ("Stone", 20) }) .AddPiece("trader_wagon_destructable", "piece_workbench", new List(4) { ("MushroomBlue", 5), ("YggdrasilWood", 30), ("BronzeNails", 40), ("Tar", 10) }) .AddPiece("TreasureChest_dvergr_loose_stone", "piece_stonecutter", new List(2) { ("MushroomBlue", 2), ("BlackMarble", 20) }) .AddPiece("TreasureChest_dvergrtower", "piece_workbench", new List(3) { ("MushroomBlue", 2), ("YggdrasilWood", 10), ("Copper", 2) }) .AddPiece("TreasureChest_dvergrtown", "piece_workbench", new List(3) { ("MushroomBlue", 2), ("YggdrasilWood", 10), ("Copper", 2) }) .AddPiece("volture_strawpile", "piece_workbench", new List(3) { ("MushroomBlue", 1), ("Barley", 20), ("CharredBone", 10) }); } public static class PieceConstants { public static class Item { public const string AsksvinCarrionNeck = "AsksvinCarrionNeck"; public const string AsksvinCarrionRibcage = "AsksvinCarrionRibcage"; public const string AsksvinCarrionSkull = "AsksvinCarrionSkull"; public const string Barley = "Barley"; public const string BellFragment = "BellFragment"; public const string BlackMarble = "BlackMarble"; public const string Blackwood = "Blackwood"; public const string Bloodbag = "Bloodbag"; public const string BoneFragments = "BoneFragments"; public const string Bronze = "Bronze"; public const string BronzeNails = "BronzeNails"; public const string Chain = "Chain"; public const string CharcoalResin = "CharcoalResin"; public const string CharredBone = "CharredBone"; public const string Coal = "Coal"; public const string Copper = "Copper"; public const string Crystal = "Crystal"; public const string DeerHide = "DeerHide"; public const string ElderBark = "ElderBark"; public const string FineWood = "FineWood"; public const string FlametalNew = "FlametalNew"; public const string Grausten = "Grausten"; public const string GreydwarfEye = "GreydwarfEye"; public const string Iron = "Iron"; public const string JuteBlue = "JuteBlue"; public const string JuteRed = "JuteRed"; public const string Lantern = "Lantern"; public const string LeatherScraps = "LeatherScraps"; public const string LoxPelt = "LoxPelt"; public const string MushroomBlue = "MushroomBlue"; public const string MushroomYellow = "MushroomYellow"; public const string PotShardGreen = "Pot_Shard_Green"; public const string PotShardRed = "Pot_Shard_Red"; public const string ProustitePowder = "ProustitePowder"; public const string Resin = "Resin"; public const string RoyalJelly = "RoyalJelly"; public const string Stone = "Stone"; public const string SurtlingCore = "SurtlingCore"; public const string Tar = "Tar"; public const string TrophySeeker = "TrophySeeker"; public const string TrophySkeleton = "TrophySkeleton"; public const string Wisp = "Wisp"; public const string WolfClaw = "WolfClaw"; public const string WolfPelt = "WolfPelt"; public const string Wood = "Wood"; public const string YggdrasilWood = "YggdrasilWood"; } public static class Workstation { public static readonly string None = string.Empty; public const string BlackForge = "blackforge"; public const string Forge = "forge"; public const string Stonecutter = "piece_stonecutter"; public const string Workbench = "piece_workbench"; } } public sealed class PotteryPieceList : IEnumerable, IEnumerable { public readonly Dictionary Pieces = new Dictionary(); public PotteryPieceList AddPiece(string piecePrefab, string craftingStation, ICollection pieceResources) { Pieces[piecePrefab] = new PotteryPiece(piecePrefab, craftingStation, pieceResources); return this; } public bool Contains(string prefabName) { return Pieces.ContainsKey(prefabName); } public IEnumerator GetEnumerator() { return Pieces.Values.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } public sealed record PotteryPiece(string PiecePrefab, string CraftingStation, ICollection PieceResources); public sealed class PieceResourceList : List { public PieceResourceList Add(string resourceName, int resourceAmount) { Add(new PieceResource(resourceName, resourceAmount)); return this; } } public sealed record PieceResource(string Name, int Amount) { public static implicit operator PieceResource((string, int) tuple) { return new PieceResource(tuple.Item1, tuple.Item2); } } public static class VanillaShop { public static readonly PotteryPieceList CultivatorPieces = new PotteryPieceList().AddPiece("vines", PieceConstants.Workstation.None, new List(1) { ("Wood", 2) }); public static readonly PotteryPieceList BuildingPieces = new PotteryPieceList().AddPiece("Ashlands_floor_large", "piece_stonecutter", new List(1) { ("Grausten", 50) }).AddPiece("Ashlands_StairsBroad", "piece_stonecutter", new List(1) { ("Grausten", 24) }).AddPiece("ashwood_arch_top", "piece_workbench", new List(1) { ("Blackwood", 2) }) .AddPiece("blackmarble_2x2_enforced", "blackforge", new List(2) { ("BlackMarble", 8), ("Copper", 2) }) .AddPiece("blackmarble_base_2", "piece_stonecutter", new List(1) { ("BlackMarble", 8) }) .AddPiece("blackmarble_column_3", "piece_stonecutter", new List(1) { ("BlackMarble", 16) }) .AddPiece("blackmarble_floor_large", "piece_stonecutter", new List(1) { ("BlackMarble", 50) }) .AddPiece("blackmarble_head_big01", "blackforge", new List(1) { ("BlackMarble", 8) }) .AddPiece("blackmarble_head_big02", "blackforge", new List(1) { ("BlackMarble", 8) }) .AddPiece("blackmarble_head01", "blackforge", new List(1) { ("Copper", 2) }) .AddPiece("blackmarble_head02", "blackforge", new List(1) { ("Copper", 2) }) .AddPiece("blackmarble_out_2", "piece_stonecutter", new List(1) { ("BlackMarble", 8) }) .AddPiece("blackmarble_slope_1x2", "piece_stonecutter", new List(1) { ("BlackMarble", 3) }) .AddPiece("blackmarble_tile_floor_1x1", "piece_stonecutter", new List(1) { ("BlackMarble", 2) }) .AddPiece("blackmarble_tile_floor_2x2", "piece_stonecutter", new List(1) { ("BlackMarble", 4) }) .AddPiece("blackmarble_tile_wall_2x4", "piece_stonecutter", new List(1) { ("BlackMarble", 8) }) .AddPiece("dvergrprops_banner", "piece_workbench", new List(2) { ("YggdrasilWood", 2), ("JuteBlue", 4) }) .AddPiece("dvergrprops_curtain", "piece_workbench", new List(2) { ("YggdrasilWood", 2), ("JuteBlue", 4) }) .AddPiece("dvergrprops_lantern_standing", "blackforge", new List(1) { ("Lantern", 1) }) .AddPiece("dvergrprops_wood_beam", "piece_workbench", new List(1) { ("YggdrasilWood", 12) }) .AddPiece("dvergrprops_wood_floor", "piece_workbench", new List(1) { ("YggdrasilWood", 2) }) .AddPiece("dvergrprops_wood_pole", "blackforge", new List(2) { ("YggdrasilWood", 8), ("Copper", 4) }) .AddPiece("dvergrprops_wood_stair", "piece_workbench", new List(1) { ("YggdrasilWood", 2) }) .AddPiece("dvergrprops_wood_wall", "blackforge", new List(2) { ("YggdrasilWood", 16), ("Copper", 8) }) .AddPiece("dvergrtown_stair_corner_wood_left", "blackforge", new List(2) { ("YggdrasilWood", 5), ("Copper", 2) }) .AddPiece("metalbar_1x2", "piece_stonecutter", new List(1) { ("Copper", 4) }) .AddPiece("piece_dvergr_pole", "blackforge", new List(2) { ("YggdrasilWood", 2), ("Copper", 1) }) .AddPiece("piece_dvergr_wood_door", "blackforge", new List(2) { ("YggdrasilWood", 8), ("Copper", 8) }) .AddPiece("piece_dvergr_wood_wall", "blackforge", new List(2) { ("YggdrasilWood", 10), ("Copper", 5) }) .AddPiece("root07", PieceConstants.Workstation.None, new List(1) { ("ElderBark", 1) }) .AddPiece("root08", PieceConstants.Workstation.None, new List(1) { ("ElderBark", 2) }) .AddPiece("root11", PieceConstants.Workstation.None, new List(1) { ("ElderBark", 2) }) .AddPiece("root12", PieceConstants.Workstation.None, new List(1) { ("ElderBark", 2) }); public static readonly PotteryPieceList FurniturePieces = new PotteryPieceList().AddPiece("piece_pot1_cracked", "piece_workbench", new List(3) { ("Pot_Shard_Green", 4), ("CharcoalResin", 1), ("ProustitePowder", 1) }).AddPiece("piece_pot2_cracked", "piece_workbench", new List(3) { ("Pot_Shard_Green", 5), ("CharcoalResin", 1), ("ProustitePowder", 1) }).AddPiece("piece_pot3_cracked", "piece_workbench", new List(3) { ("Pot_Shard_Green", 3), ("CharcoalResin", 1), ("ProustitePowder", 1) }); public static readonly PotteryPieceList MiscPieces = new PotteryPieceList().AddPiece("portal", "piece_stonecutter", new List(3) { ("Stone", 30), ("SurtlingCore", 2), ("GreydwarfEye", 10) }).AddPiece("CastleKit_brazier", "forge", new List(3) { ("Bronze", 5), ("Coal", 2), ("WolfClaw", 3) }); } public static class PotteryManager { public static readonly Regex PrefabNameRegex = new Regex("([a-z])([A-Z])"); public static readonly string HammerPieceTable = "_HammerPieceTable"; public static readonly string CultivatorPieceTable = "_CultivatorPieceTable"; public static PieceCategory BuildingCategory; public static PieceCategory FurnitureCategory; public static PieceCategory MiscCategory; public static PieceCategory ComfyCreativeCategory; public static readonly Quaternion PrefabIconRenderRotation = Quaternion.Euler(0f, -37.5f, 0f); public static readonly Dictionary VanillaPieces = new Dictionary(); public static readonly Dictionary ShopPieces = new Dictionary(); public static readonly Dictionary VanillaPieceResources = new Dictionary(); public static readonly Dictionary CraftingStationCache = new Dictionary(); public static readonly DropTable EmptyDropTable = new DropTable(); public const int IsPlacedByPotteryBarnHash = -868975970; public static bool IsPlacingPiece { get; set; } = false; public static PieceTable GetHammerPieceTable() { return PieceManager.Instance.GetPieceTable(HammerPieceTable); } public static PieceTable GetCultivatorPieceTable() { return PieceManager.Instance.GetPieceTable(CultivatorPieceTable); } public static void AddPieces() { PieceManager.OnPiecesRegistered -= AddPieces; SetupCategories(PieceManager.Instance); AddHammerPieces(GetHammerPieceTable()); AddCultivatorPieces(GetCultivatorPieceTable()); } public static void SetupCategories(PieceManager pieceManager) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) BuildingCategory = (PieceCategory)2; FurnitureCategory = (PieceCategory)4; MiscCategory = (PieceCategory)0; ComfyCreativeCategory = pieceManager.AddPieceCategory("ComfyCreative"); } public static void AddHammerPieces(PieceTable hammerPieceTable) { //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) hammerPieceTable.AddPiece(GetExistingPiece("turf_roof").SetName("turf_roof")); hammerPieceTable.AddPiece(GetExistingPiece("turf_roof_top").SetName("turf_roof_top")); hammerPieceTable.AddPiece(GetExistingPiece("turf_roof_wall").SetName("turf_roof_wall")); hammerPieceTable.AddPiece(GetExistingPiece("ArmorStand_Female").SetName("ArmorStand_Female").SetComfort(0)); hammerPieceTable.AddPiece(GetExistingPiece("ArmorStand_Male").SetName("ArmorStand_Male")); Piece existingPiece = GetExistingPiece("stone_floor"); int? amount = 12; bool? recover = true; hammerPieceTable.AddPiece(existingPiece.ModifyResource("Stone", amount, null, recover)); Piece existingPiece2 = GetExistingPiece("wood_ledge"); int? amount2 = 1; recover = true; hammerPieceTable.AddPiece(existingPiece2.ModifyResource("Wood", amount2, null, recover)); AddPotteryPieces(hammerPieceTable, BuildingCategory, VanillaShop.BuildingPieces, VanillaPieces); AddPotteryPieces(hammerPieceTable, FurnitureCategory, VanillaShop.FurniturePieces, VanillaPieces); AddPotteryPieces(hammerPieceTable, MiscCategory, VanillaShop.MiscPieces, VanillaPieces); AddPotteryPieces(hammerPieceTable, ComfyCreativeCategory, CreativeShop.HammerPieces, ShopPieces); } public static void AddCultivatorPieces(PieceTable cultivatorPieceTable) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) AddPotteryPieces(cultivatorPieceTable, MiscCategory, VanillaShop.CultivatorPieces, VanillaPieces); AddPotteryPieces(cultivatorPieceTable, ComfyCreativeCategory, CreativeShop.CultivatorPieces, ShopPieces); } public static void AddPotteryPieces(PieceTable pieceTable, PieceCategory pieceCategory, PotteryPieceList potteryPieces, Dictionary pieceByNameCache) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) foreach (PotteryPiece potteryPiece in potteryPieces) { Piece orAddPiece = GetOrAddPiece(potteryPiece.PiecePrefab); orAddPiece.SetCategory(pieceCategory).SetResources(CreatePieceRequirements(potteryPiece.PieceResources)).SetCraftingStation(GetCraftingStation(potteryPiece.CraftingStation)) .SetCanBeRemoved(canBeRemoved: true); pieceTable.AddPiece(orAddPiece); pieceByNameCache.Add(potteryPiece.PiecePrefab, orAddPiece); } } public static Piece GetExistingPiece(string prefabName) { return PrefabManager.Instance.GetPrefab(prefabName).GetComponent(); } public static Piece GetOrAddPiece(string prefabName) { //IL_007a: Unknown result type (might be due to invalid IL or missing references) GameObject prefab = PrefabManager.Instance.GetPrefab(prefabName); Piece val = default(Piece); if (prefab.TryGetComponent(ref val)) { if (!VanillaPieceResources.ContainsKey(((Object)val).name)) { VanillaPieceResources.Add(((Object)val).name, val.m_resources); } } else { val = prefab.AddComponent(); val.m_name = FormatPrefabName(((Object)prefab).name); SetPlacementRestrictions(val); } val.m_description = ((Object)prefab).name; if (!Object.op_Implicit((Object)(object)val.m_icon)) { val.m_icon = LoadOrRenderIcon(prefab, PrefabIconRenderRotation); } if (!val.m_enabled) { val.m_enabled = true; } return val; } public static Requirement[] CreatePieceRequirements(ICollection pieceResources) { return pieceResources.Select(CreatePieceRequirement).ToArray(); } public static Requirement CreatePieceRequirement(PieceResource pieceResource) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown return new Requirement { m_resItem = PrefabManager.Instance.GetPrefab(pieceResource.Name).GetComponent(), m_amount = pieceResource.Amount }; } public static CraftingStation GetCraftingStation(string prefabName) { if (string.IsNullOrEmpty(prefabName)) { return null; } if (!CraftingStationCache.TryGetValue(prefabName, out var value)) { value = PrefabManager.Instance.GetPrefab(prefabName).GetComponent(); CraftingStationCache.Add(prefabName, value); } return value; } public static Piece SetPlacementRestrictions(Piece piece) { piece.m_repairPiece = false; piece.m_groundOnly = false; piece.m_groundPiece = false; piece.m_cultivatedGroundOnly = false; piece.m_waterPiece = false; piece.m_noInWater = false; piece.m_notOnWood = false; piece.m_notOnTiltingSurface = false; piece.m_inCeilingOnly = false; piece.m_notOnFloor = false; piece.m_onlyInTeleportArea = false; piece.m_allowedInDungeons = false; piece.m_clipEverything = true; return piece; } public static string FormatPrefabName(string prefabName) { return PrefabNameRegex.Replace(prefabName, "$1 $2").TrimStart(new char[1] { ' ' }).Replace('_', ' ') .Replace(" ", " "); } public static bool IsShopPiece(Piece piece) { return ShopPieces.ContainsKey(Utils.GetPrefabName(((Object)piece).name)); } public static bool IsVanillaPiece(Piece piece) { return VanillaPieces.ContainsKey(Utils.GetPrefabName(((Object)piece).name)); } public static Sprite LoadOrRenderIcon(GameObject prefab, Quaternion renderRotation) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Expected O, but got Unknown RenderRequest val = new RenderRequest(prefab) { Rotation = renderRotation }; return RenderManager.Instance.Render(val); } public static void SetupPiece(Piece piece) { bool flag = IsShopPiece(piece); bool flag2 = IsVanillaPiece(piece); if (!flag && !flag2) { return; } if (flag) { piece.m_canBeRemoved = piece.IsCreator(); } if (flag2) { piece.m_canBeRemoved = true; } if (IsPlacingPiece) { piece.SetIsPlacedByPotteryBarn(isPlacedByPotteryBarn: true); } else if (!piece.IsPlacedByPotteryBarn()) { if (VanillaPieceResources.TryGetValue(Utils.GetPrefabName(((Object)piece).name), out var value)) { piece.m_resources = value; } else { piece.m_resources = Array.Empty(); } return; } DropOnDestroyed val = default(DropOnDestroyed); if (((Component)piece).TryGetComponent(ref val)) { val.m_dropWhenDestroyed = EmptyDropTable; } Destructible val2 = default(Destructible); if (((Component)piece).TryGetComponent(ref val2) && Object.op_Implicit((Object)(object)val2.m_spawnWhenDestroyed)) { CustomFieldUtils.SetDestructibleFields(val2, "vfx_SawDust"); } } public static void PlacePieceDoAttackPreDelegate(GameObject clonedObject) { Piece piece = default(Piece); if (clonedObject.TryGetComponent(ref piece)) { SetupPiece(piece); } Container val = default(Container); if (clonedObject.TryGetComponent(ref val)) { val.GetInventory().RemoveAll(); } } public static void SetIsPlacedByPotteryBarn(this Piece piece, bool isPlacedByPotteryBarn) { if (Object.op_Implicit((Object)(object)piece.m_nview) && piece.m_nview.IsValid()) { piece.m_nview.m_zdo.Set(-868975970, true); } } public static bool IsPlacedByPotteryBarn(this Piece piece) { if (Object.op_Implicit((Object)(object)piece.m_nview) && piece.m_nview.IsValid()) { return piece.m_nview.m_zdo.GetBool(-868975970, false); } return false; } } public static class CustomFieldUtils { public const int HasFieldsHash = -310439593; public const int HasFieldsDestructibleHash = 949312639; public const int DestructibleSpawnWhenDestroyedHash = -1786945712; public static void SetDestructibleFields(Destructible destructible, string spawnWhenDestroyed) { ZDO zdo = destructible.m_nview.m_zdo; zdo.Set(-310439593, true); zdo.Set(949312639, true); zdo.Set(-1786945712, spawnWhenDestroyed); destructible.m_nview.LoadFields(); } } public static class PlacementGhostUtils { public static bool HasActiveComponents(GameObject gameObject) { MonsterAI val = default(MonsterAI); AnimalAI val2 = default(AnimalAI); Tameable val3 = default(Tameable); Ragdoll val4 = default(Ragdoll); Humanoid val5 = default(Humanoid); if (!gameObject.TryGetComponent(ref val) && !gameObject.TryGetComponent(ref val2) && !gameObject.TryGetComponent(ref val3) && !gameObject.TryGetComponent(ref val4)) { return gameObject.TryGetComponent(ref val5); } return true; } public static void DestroyActiveComponents(GameObject gameObject) { MonsterAI val = default(MonsterAI); if (gameObject.TryGetComponent(ref val)) { Object.DestroyImmediate((Object)(object)val); } AnimalAI val2 = default(AnimalAI); if (gameObject.TryGetComponent(ref val2)) { Object.DestroyImmediate((Object)(object)val2); } Tameable val3 = default(Tameable); if (gameObject.TryGetComponent(ref val3)) { Object.DestroyImmediate((Object)(object)val3); } Ragdoll val4 = default(Ragdoll); if (gameObject.TryGetComponent(ref val4)) { Object.DestroyImmediate((Object)(object)val4); } Humanoid val5 = default(Humanoid); if (gameObject.TryGetComponent(ref val5)) { val5.m_defaultItems = Array.Empty(); val5.m_randomWeapon = Array.Empty(); val5.m_randomArmor = Array.Empty(); val5.m_randomShield = Array.Empty(); val5.m_randomSets = Array.Empty(); val5.m_randomItems = Array.Empty(); } } } [HarmonyPatch(typeof(EffectList))] internal static class EffectListPatch { [HarmonyTranspiler] [HarmonyPatch("Create")] private static IEnumerable CreateTranspiler(IEnumerable instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Expected O, but got Unknown //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown return new CodeMatcher(instructions, (ILGenerator)null).Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Ldloc_2, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(EffectData), "m_enabled"), (string)null) }).ThrowIfInvalid("Could not patch EffectList.Create()! (effect-data-enabled)") .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Ldloc_2, (object)null), new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(EffectListPatch), "CheckEffectDataDelegate", (Type[])null, (Type[])null)) }) .InstructionEnumeration(); } private static void CheckEffectDataDelegate(EffectData effectData) { if (PluginConfig.IsModEnabled.Value && effectData.m_enabled && !Object.op_Implicit((Object)(object)effectData.m_prefab)) { effectData.m_enabled = false; } } } [HarmonyPatch(typeof(Piece))] internal static class PiecePatch { [HarmonyPostfix] [HarmonyPatch("Awake")] private static void AwakePostfix(Piece __instance) { if (!PotteryManager.IsPlacingPiece) { PotteryManager.SetupPiece(__instance); } } [HarmonyPrefix] [HarmonyPatch("DropResources")] private static void DropResourcesPrefix(Piece __instance) { Container val = default(Container); if (((Component)__instance).TryGetComponent(ref val)) { val.DropAllItems(); } } } [HarmonyPatch(typeof(Player))] internal static class PlayerPatch { [HarmonyTranspiler] [HarmonyPatch("SetupPlacementGhost")] private static IEnumerable SetupPlacementGhostTranspiler(IEnumerable instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Expected O, but got Unknown //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Expected O, but got Unknown //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Expected O, but got Unknown return new CodeMatcher(instructions, (ILGenerator)null).Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Call, (object)ReflectionUtils.GetGenericMethod(typeof(Object), "Instantiate", 1, new Type[1] { typeof(Type) }).MakeGenericMethod(typeof(GameObject)), (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(Player), "m_placementGhost"), (string)null) }).ThrowIfInvalid("Could not patch Player.SetupPlacementGhost()! (placement-ghost)") .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(PlayerPatch), "SetupPlacementGhostInstantiateDelegate", (Type[])null, (Type[])null))) .InstructionEnumeration(); } private static GameObject SetupPlacementGhostInstantiateDelegate(GameObject selectedPrefab) { bool flag = false; if (PluginConfig.IsModEnabled.Value && PlacementGhostUtils.HasActiveComponents(selectedPrefab)) { flag = selectedPrefab.activeSelf; selectedPrefab.SetActive(false); } GameObject val = Object.Instantiate(selectedPrefab); if (PluginConfig.IsModEnabled.Value && flag) { selectedPrefab.SetActive(true); PlacementGhostUtils.DestroyActiveComponents(val); val.SetActive(true); } return val; } [HarmonyPrefix] [HarmonyPatch("SetupPlacementGhost")] private static void SetupPlacementGhostPrefix() { PotteryManager.IsPlacingPiece = true; } [HarmonyPostfix] [HarmonyPatch("SetupPlacementGhost")] private static void SetupPlacementGhostPostfix() { PotteryManager.IsPlacingPiece = false; } [HarmonyPostfix] [HarmonyPatch("CheckCanRemovePiece")] private static void CheckCanRemovePostfix(Piece piece, ref bool __result) { if (__result) { if (PotteryManager.IsShopPiece(piece)) { __result = piece.IsCreator(); } else if (PotteryManager.IsVanillaPiece(piece)) { __result = piece.IsPlacedByPlayer(); } } } [HarmonyTranspiler] [HarmonyPatch("PlacePiece")] private static IEnumerable PlacePieceTranspiler(IEnumerable instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Expected O, but got Unknown List