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 HexWaterproofBuilding v1.3.1
plugins/HexWaterproofBuilding.dll
Decompiled 2 weeks 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 BepInEx; using BepInEx.Configuration; using HarmonyLib; using HexWaterproofBuilding.Core; using HexWaterproofBuilding.Discovery; using HexWaterproofBuilding.Rules; using HexWaterproofBuilding.Utils; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("HexWaterproofBuilding")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("HexWaterproofBuilding")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("69555090-1b3b-4323-9007-2b83a7a50186")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] namespace HexWaterproofBuilding { [BepInPlugin("hex.waterproofbuilding", "HexWaterproofBuilding", "1.3.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { private const string PluginGuid = "hex.waterproofbuilding"; private const string PluginName = "HexWaterproofBuilding"; private const string PluginVersion = "1.3.1"; private Harmony _harmony; private ConfigEntry<bool> _modEnabled; private ConfigEntry<bool> _extendedPlacementRangeEnabled; private ConfigEntry<bool> _extendedPlacementForVanillaPiecesEnabled; internal static Plugin Instance { get; private set; } internal bool IsModEnabled { get { if (_modEnabled != null) { return _modEnabled.Value; } return false; } } internal bool IsExtendedPlacementRangeEnabled { get { if (_extendedPlacementRangeEnabled != null) { return _extendedPlacementRangeEnabled.Value; } return false; } } internal bool IsExtendedPlacementForVanillaPiecesEnabled { get { if (_extendedPlacementForVanillaPiecesEnabled != null) { return _extendedPlacementForVanillaPiecesEnabled.Value; } return false; } } private void Awake() { //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown Instance = this; _modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable or disable the Waterproof Building mod."); _extendedPlacementRangeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Extended Placement Range", "Enabled", true, "Enable extended placement range for waterproof pieces."); _extendedPlacementForVanillaPiecesEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Extended Placement Range", "VanillaPiecesEnabled", false, "Enable extended placement range for vanilla building pieces."); _modEnabled.SettingChanged += OnModEnabledSettingChanged; _extendedPlacementRangeEnabled.SettingChanged += OnModEnabledSettingChanged; _extendedPlacementForVanillaPiecesEnabled.SettingChanged += OnModEnabledSettingChanged; Assembly executingAssembly = Assembly.GetExecutingAssembly(); _harmony = new Harmony("hex.waterproofbuilding"); _harmony.PatchAll(executingAssembly); if (IsModEnabled) { PrefabManager.OnVanillaPrefabsAvailable += WaterproofPieceRegistrar.RegisterPieces; } Logger.LogInfo((object)"HexWaterproofBuilding v1.3.1 loaded."); } private void OnDestroy() { ((BaseUnityPlugin)this).Logger.LogInfo((object)"HexWaterproofBuilding v1.3.1 unloaded."); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _harmony = null; if (_modEnabled != null) { _modEnabled.SettingChanged -= OnModEnabledSettingChanged; } if (_extendedPlacementRangeEnabled != null) { _extendedPlacementRangeEnabled.SettingChanged -= OnModEnabledSettingChanged; } if (_extendedPlacementForVanillaPiecesEnabled != null) { _extendedPlacementForVanillaPiecesEnabled.SettingChanged -= OnModEnabledSettingChanged; } PrefabManager.OnVanillaPrefabsAvailable -= WaterproofPieceRegistrar.RegisterPieces; Instance = null; } private void OnModEnabledSettingChanged(object sender, EventArgs args) { Logger.LogInfo((object)$"Mod enabled: {IsModEnabled}"); Logger.LogInfo((object)$"Extended placement range enabled: {IsExtendedPlacementRangeEnabled}"); Logger.LogInfo((object)$"Extended placement for vanilla pieces enabled: {IsExtendedPlacementForVanillaPiecesEnabled}"); Logger.LogWarning((object)"Changes require a restart to fully take effect."); } } } namespace HexWaterproofBuilding.Utils { internal static class PieceUtility { internal static bool IsWaterproofPiece(Piece piece) { if ((Object)(object)piece == (Object)null) { return false; } return ((Object)piece).name.Replace("(Clone)", "").StartsWith("Waterproof_"); } internal static bool CanUseExtendedPlacementForPiece(Piece piece) { if ((Object)(object)piece == (Object)null) { return false; } if (IsWaterproofPiece(piece)) { return true; } if (!FeatureFlags.CanUseExtendedPlacementForVanillaPieces()) { return false; } return IsVanillaBuildingPiece(piece); } private static bool IsVanillaBuildingPiece(Piece piece) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Invalid comparison between Unknown and I4 if ((Object)(object)piece == (Object)null) { return false; } string text = ((Object)piece).name.Replace("(Clone)", ""); if (text.StartsWith("Waterproof_")) { return false; } bool num = text == "piece_workbench"; bool flag = (int)piece.m_category == 2; return num || flag; } } internal static class FeatureFlags { internal static bool CanUseExtendedPlacement() { if ((Object)(object)Plugin.Instance != (Object)null && Plugin.Instance.IsModEnabled) { return Plugin.Instance.IsExtendedPlacementRangeEnabled; } return false; } internal static bool CanUseExtendedPlacementForVanillaPieces() { if (CanUseExtendedPlacement()) { return Plugin.Instance.IsExtendedPlacementForVanillaPiecesEnabled; } return false; } } } namespace HexWaterproofBuilding.Discovery { internal static class PrefabDiscovery { internal static IEnumerable<GameObject> GetPrefabs(Func<GameObject, bool> predicate) { Dictionary<string, Object> prefabs = Cache.GetPrefabs(typeof(GameObject)); foreach (KeyValuePair<string, Object> item in prefabs) { Object value = item.Value; GameObject val = (GameObject)(object)((value is GameObject) ? value : null); if (!((Object)(object)val == (Object)null) && (predicate == null || predicate(val))) { yield return val; } } } internal static Dictionary<string, int> GetHammerPieceIndexes() { Dictionary<string, int> dictionary = new Dictionary<string, int>(); Object prefab = Cache.GetPrefab(typeof(GameObject), "Hammer"); GameObject val = (GameObject)(object)((prefab is GameObject) ? prefab : null); if ((Object)(object)val == (Object)null) { return dictionary; } ItemDrop component = val.GetComponent<ItemDrop>(); if ((Object)(object)component == (Object)null || (Object)(object)component.m_itemData.m_shared.m_buildPieces == (Object)null || component.m_itemData.m_shared.m_buildPieces.m_pieces == null) { return dictionary; } List<GameObject> pieces = component.m_itemData.m_shared.m_buildPieces.m_pieces; for (int i = 0; i < pieces.Count; i++) { GameObject val2 = pieces[i]; if (!((Object)(object)val2 == (Object)null) && !dictionary.ContainsKey(((Object)val2).name)) { dictionary.Add(((Object)val2).name, i); } } return dictionary; } } } namespace HexWaterproofBuilding.Rules { internal static class WaterproofPrefabRules { private static readonly string LowerPrefabPrefix = "Waterproof".ToLower(); private static readonly string[] InvalidTokens = new string[6] { "stack", "spiral", "treasure", "dvergr", "old_", "turf" }; internal static bool IsValidPrefab(GameObject prefab) { //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Invalid comparison between Unknown and I4 //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Invalid comparison between Unknown and I4 if ((Object)(object)prefab == (Object)null) { return false; } Piece component = prefab.GetComponent<Piece>(); WearNTear component2 = prefab.GetComponent<WearNTear>(); if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null) { return false; } string lowerName = ((Object)prefab).name.ToLowerInvariant(); if (lowerName.StartsWith(LowerPrefabPrefix)) { return false; } if (InvalidTokens.Any((string token) => lowerName.Contains(token))) { return false; } if (((Object)component).name != "piece_workbench" && (int)component.m_category != 2) { return false; } if ((int)component2.m_materialType != 0) { return (int)component2.m_materialType == 3; } return true; } } } namespace HexWaterproofBuilding.Patches { [HarmonyPatch(typeof(Player), "CopyPiece")] internal static class PatchPlayerCopyPiece { private static readonly FieldRef<Player, int> RemoveRayMaskRef = AccessTools.FieldRefAccess<Player, int>("m_removeRayMask"); private static readonly FieldRef<Player, float> PlaceRotationDegreesRef = AccessTools.FieldRefAccess<Player, float>("m_placeRotationDegrees"); private static readonly FieldRef<Player, int> PlaceRotationRef = AccessTools.FieldRefAccess<Player, int>("m_placeRotation"); private static readonly FastInvokeHandler SetSelectedPieceRef = MethodInvoker.GetHandler(AccessTools.Method(typeof(Player), "SetSelectedPiece", new Type[1] { typeof(Piece) }, (Type[])null), false); [HarmonyPrefix] private static bool Prefix(Player __instance, ref bool __result) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || !FeatureFlags.CanUseExtendedPlacement()) { return true; } if ((Object)(object)GameCamera.instance == (Object)null || (Object)(object)((Component)GameCamera.instance).transform == (Object)null) { return true; } Transform transform = ((Component)GameCamera.instance).transform; RaycastHit val = default(RaycastHit); if (!Physics.Raycast(transform.position, transform.forward, ref val, 100f, RemoveRayMaskRef.Invoke(__instance)) || (Object)(object)((RaycastHit)(ref val)).collider == (Object)null) { __result = false; return false; } Piece val2 = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Piece>(); if ((Object)(object)val2 == (Object)null && (Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponent<Heightmap>() != (Object)null) { val2 = TerrainModifier.FindClosestModifierPieceInRange(((RaycastHit)(ref val)).point, 2.5f); } if (!PieceUtility.CanUseExtendedPlacementForPiece(val2)) { return true; } if (!(bool)SetSelectedPieceRef.Invoke((object)__instance, new object[1] { val2 })) { ((Character)__instance).Message((MessageType)2, "$msg_missingrequirement", 0, (Sprite)null); __result = false; return false; } float num = PlaceRotationDegreesRef.Invoke(__instance); if (num <= 0f) { __result = true; return false; } Quaternion rotation = ((Component)val2).transform.rotation; PlaceRotationRef.Invoke(__instance) = (int)Math.Round(((Quaternion)(ref rotation)).eulerAngles.y / num); __result = true; return false; } } [HarmonyPatch(typeof(Player), "PieceRayTest")] internal static class PatchPlayerPieceRayTest { private static readonly FieldRef<Player, GameObject> PlacementGhostRef = AccessTools.FieldRefAccess<Player, GameObject>("m_placementGhost"); private static readonly FieldRef<Player, int> PlaceRayMaskRef = AccessTools.FieldRefAccess<Player, int>("m_placeRayMask"); private static readonly FieldRef<Player, int> PlaceWaterRayMaskRef = AccessTools.FieldRefAccess<Player, int>("m_placeWaterRayMask"); private static readonly int WaterLayer = LayerMask.NameToLayer("Water"); private static bool Prefix(Player __instance, ref bool __result, out Vector3 point, out Vector3 normal, out Piece piece, out Heightmap heightmap, out Collider waterSurface, bool water) { //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_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: 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) point = Vector3.zero; normal = Vector3.zero; piece = null; heightmap = null; waterSurface = null; if ((Object)(object)__instance == (Object)null || !FeatureFlags.CanUseExtendedPlacement()) { return true; } GameObject val = PlacementGhostRef.Invoke(__instance); if ((Object)(object)val == (Object)null) { return true; } if (!PieceUtility.CanUseExtendedPlacementForPiece(val.GetComponent<Piece>())) { return true; } int num = (water ? PlaceWaterRayMaskRef.Invoke(__instance) : PlaceRayMaskRef.Invoke(__instance)); if ((Object)(object)GameCamera.instance == (Object)null) { return true; } Transform transform = ((Component)GameCamera.instance).transform; RaycastHit val2 = default(RaycastHit); if (!Physics.Raycast(transform.position, transform.forward, ref val2, 100f, num)) { __result = false; return false; } if ((Object)(object)((RaycastHit)(ref val2)).collider == (Object)null || (Object)(object)((RaycastHit)(ref val2)).collider.attachedRigidbody != (Object)null) { __result = false; return false; } point = ((RaycastHit)(ref val2)).point; normal = ((RaycastHit)(ref val2)).normal; piece = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<Piece>(); heightmap = ((Component)((RaycastHit)(ref val2)).collider).GetComponent<Heightmap>(); waterSurface = ((WaterLayer >= 0 && ((Component)((RaycastHit)(ref val2)).collider).gameObject.layer == WaterLayer) ? ((RaycastHit)(ref val2)).collider : null); __result = true; return false; } } [HarmonyPatch(typeof(Player), "RemovePiece")] internal static class PatchPlayerRemovePiece { private static readonly FieldRef<Player, int> RemoveRayMaskRef = AccessTools.FieldRefAccess<Player, int>("m_removeRayMask"); private static readonly FieldRef<Player, EffectList> RemoveEffectsRef = AccessTools.FieldRefAccess<Player, EffectList>("m_removeEffects"); private static readonly FieldRef<Player, ItemData> RightItemRef = AccessTools.FieldRefAccess<Player, ItemData>("m_rightItem"); private static readonly FieldRef<Character, ZSyncAnimation> ZanimRef = AccessTools.FieldRefAccess<Character, ZSyncAnimation>("m_zanim"); private static readonly FastInvokeHandler CheckCanRemovePieceRef = MethodInvoker.GetHandler(AccessTools.Method(typeof(Player), "CheckCanRemovePiece", (Type[])null, (Type[])null), false); private static readonly FastInvokeHandler FaceLookDirectionRef = MethodInvoker.GetHandler(AccessTools.Method(typeof(Player), "FaceLookDirection", (Type[])null, (Type[])null), false); private static bool Prefix(Player __instance, ref bool __result) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: 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_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: 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_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Expected O, but got Unknown if ((Object)(object)__instance == (Object)null || !FeatureFlags.CanUseExtendedPlacement()) { return true; } if ((Object)(object)GameCamera.instance == (Object)null || (Object)(object)((Component)GameCamera.instance).transform == (Object)null) { return true; } Vector3 position = ((Component)GameCamera.instance).transform.position; Vector3 forward = ((Component)GameCamera.instance).transform.forward; int num = RemoveRayMaskRef.Invoke(__instance); RaycastHit val = default(RaycastHit); if (!Physics.Raycast(position, forward, ref val, 100f, num)) { return true; } if ((Object)(object)((RaycastHit)(ref val)).collider == (Object)null) { return true; } Piece val2 = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Piece>(); Heightmap component = ((Component)((RaycastHit)(ref val)).collider).GetComponent<Heightmap>(); if ((Object)(object)val2 == (Object)null && (Object)(object)component != (Object)null) { val2 = TerrainModifier.FindClosestModifierPieceInRange(((RaycastHit)(ref val)).point, 2.5f); } if (!PieceUtility.CanUseExtendedPlacementForPiece(val2)) { return true; } if (!val2.m_canBeRemoved) { __result = false; return false; } Vector3 position2 = ((Component)val2).transform.position; Quaternion rotation = ((Component)val2).transform.rotation; Transform transform = ((Component)val2).transform; if (Location.IsInsideNoBuildLocation(position2)) { ((Character)__instance).Message((MessageType)2, "$msg_nobuildzone", 0, (Sprite)null); __result = false; return false; } if (!PrivateArea.CheckAccess(position2, 0f, true, false)) { ((Character)__instance).Message((MessageType)2, "$msg_privatezone", 0, (Sprite)null); __result = false; return false; } if (!(bool)CheckCanRemovePieceRef.Invoke((object)__instance, new object[1] { val2 })) { __result = false; return false; } ZNetView component2 = ((Component)val2).GetComponent<ZNetView>(); if ((Object)(object)component2 == (Object)null) { __result = false; return false; } if (!val2.CanBeRemoved()) { ((Character)__instance).Message((MessageType)2, "$msg_cantremovenow", 0, (Sprite)null); __result = false; return false; } IRemoved component3 = ((Component)val2).GetComponent<IRemoved>(); if (component3 != null) { component3.OnRemoved(); } WearNTear component4 = ((Component)val2).GetComponent<WearNTear>(); if ((Object)(object)component4 != (Object)null) { component4.Remove(false); } else { Character component5 = ((Component)val2).GetComponent<Character>(); if ((Object)(object)component5 != (Object)null) { component5.Damage(new HitData(1E+10f)); } else { ZLog.Log((object)("Removing non WNT object with hammer " + ((Object)val2).name)); component2.ClaimOwnership(); val2.DropResources((HitData)null); val2.m_placeEffect.Create(position2, rotation, transform, 1f, -1); RemoveEffectsRef.Invoke(__instance).Create(position2, Quaternion.identity, (Transform)null, 1f, -1); ZNetScene.instance.Destroy(((Component)val2).gameObject); } } ItemData val3 = RightItemRef.Invoke(__instance); if (val3 != null) { FaceLookDirectionRef.Invoke((object)__instance, Array.Empty<object>()); ZSyncAnimation val4 = ZanimRef.Invoke((Character)(object)__instance); if ((Object)(object)val4 != (Object)null) { val4.SetTrigger(val3.m_shared.m_attack.m_attackAnimation); } } __result = true; return false; } } [HarmonyPatch(typeof(Player), "UpdateWearNTearHover")] internal static class PatchPlayerUpdateWearNTearHover { private static readonly FieldRef<Player, int> RemoveRayMaskRef = AccessTools.FieldRefAccess<Player, int>("m_removeRayMask"); private static readonly FieldRef<Player, Piece> HoveringPieceRef = AccessTools.FieldRefAccess<Player, Piece>("m_hoveringPiece"); private static void Postfix(Player __instance) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || !FeatureFlags.CanUseExtendedPlacement() || !((Character)__instance).InPlaceMode() || (Object)(object)GameCamera.instance == (Object)null || (Object)(object)((Component)GameCamera.instance).transform == (Object)null) { return; } Vector3 position = ((Component)GameCamera.instance).transform.position; Vector3 forward = ((Component)GameCamera.instance).transform.forward; int num = RemoveRayMaskRef.Invoke(__instance); RaycastHit val = default(RaycastHit); if (!Physics.Raycast(position, forward, ref val, 100f, num) || (Object)(object)((RaycastHit)(ref val)).collider == (Object)null) { return; } Piece componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Piece>(); if (PieceUtility.CanUseExtendedPlacementForPiece(componentInParent)) { HoveringPieceRef.Invoke(__instance) = componentInParent; WearNTear component = ((Component)componentInParent).GetComponent<WearNTear>(); if (!((Object)(object)component == (Object)null)) { component.Highlight(); } } } } } namespace HexWaterproofBuilding.Core { internal static class Constants { internal const string WaterproofCategory = "Waterproof Building"; internal const string PrefabPrefix = "Waterproof"; internal const float ClosestRangeModifier = 2.5f; internal const float CharacterHitDataValue = 1E+10f; internal const float ExtendedHoverDistance = 100f; internal const float ExtendedPlacementDistance = 100f; internal const float ExtendedRemoveDistance = 100f; internal const float ExtendedCopyDistance = 100f; } internal static class ItemList { internal const string Resin = "Resin"; } internal static class WaterproofPieceRegistrar { private static bool _registered; internal static void RegisterPieces() { if (!_registered) { if ((Object)(object)Plugin.Instance == (Object)null || !Plugin.Instance.IsModEnabled) { PrefabManager.OnVanillaPrefabsAvailable -= RegisterPieces; return; } int num = CreateWaterproofPieces(PrefabDiscovery.GetHammerPieceIndexes()); _registered = true; PrefabManager.OnVanillaPrefabsAvailable -= RegisterPieces; Logger.LogInfo((object)$"Waterproof pieces registered. Count: {num}"); } } private static int CreateWaterproofPieces(Dictionary<string, int> hammerIndexes) { int num = 0; int value; foreach (GameObject item in (from prefab in PrefabDiscovery.GetPrefabs(WaterproofPrefabRules.IsValidPrefab) orderby (hammerIndexes != null && hammerIndexes.TryGetValue(((Object)prefab).name, out value)) ? value : int.MaxValue, ((Object)prefab).name select prefab).ToList()) { if (CreateWaterproofPiece(item)) { num++; } } return num; } private static bool CreateWaterproofPiece(GameObject vanillaPrefab) { //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Expected O, but got Unknown if ((Object)(object)vanillaPrefab == (Object)null) { return false; } Piece component = vanillaPrefab.GetComponent<Piece>(); if ((Object)(object)component == (Object)null) { Logger.LogWarning((object)(((Object)vanillaPrefab).name + " has no Piece component. Skipping.")); return false; } string text = "Waterproof_" + ((Object)vanillaPrefab).name; GameObject val = PrefabManager.Instance.CreateClonedPrefab(text, ((Object)vanillaPrefab).name); if ((Object)(object)val == (Object)null) { Logger.LogWarning((object)("Failed to clone prefab: " + ((Object)vanillaPrefab).name)); return false; } ApplyModifiersToCustomPrefab(val); PieceConfig val2 = BuildPieceConfig(text, component); CustomPiece val3 = new CustomPiece(val, true, val2); PieceManager.Instance.AddPiece(val3); Logger.LogInfo((object)("Registered waterproof building piece: " + text)); return true; } private static void ApplyModifiersToCustomPrefab(GameObject customPrefab) { if (!((Object)(object)customPrefab == (Object)null)) { WearNTear component = customPrefab.GetComponent<WearNTear>(); if ((Object)(object)component == (Object)null) { Logger.LogWarning((object)(((Object)customPrefab).name + " has no WearNTear component.")); } else { component.m_noRoofWear = false; } } } private static PieceConfig BuildPieceConfig(string customPrefabName, Piece vanillaPiece) { //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_000c: 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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown return new PieceConfig { Name = customPrefabName, Description = "A waterproof building piece that resists water damage.", PieceTable = PieceTables.Hammer, Category = "Waterproof Building", Requirements = BuildRequirementConfigs(vanillaPiece, new Dictionary<string, int> { { "Resin", 1 } }) }; } private static RequirementConfig[] BuildRequirementConfigs(Piece vanillaPiece, Dictionary<string, int> customRequirements, bool keepVanillaRequirements = true) { //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown List<RequirementConfig> list = new List<RequirementConfig>(); if (keepVanillaRequirements && (Object)(object)vanillaPiece != (Object)null && vanillaPiece.m_resources != null) { Requirement[] resources = vanillaPiece.m_resources; foreach (Requirement val in resources) { if (val != null && !((Object)(object)val.m_resItem == (Object)null)) { list.Add(new RequirementConfig(((Object)val.m_resItem).name, val.m_amount, val.m_amountPerLevel, val.m_recover)); } } } if (customRequirements != null) { foreach (KeyValuePair<string, int> customRequirement in customRequirements) { if (!list.Any((RequirementConfig requirement) => string.Equals(requirement.Item, customRequirement.Key, StringComparison.OrdinalIgnoreCase))) { list.Add(new RequirementConfig(customRequirement.Key, customRequirement.Value, 0, true)); } } } return list.ToArray(); } } }