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 PeachCastleFix v1.1.1
PeachCastleFix.dll
Decompiled 3 weeks agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: AssemblyCompany("PeachCastleFix")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("PeachCastleFix")] [assembly: AssemblyTitle("PeachCastleFix")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.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 PeachCastleFix { [BepInPlugin("themorningstar.peachcastlefix", "PeachCastleFix", "1.1.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string Guid = "themorningstar.peachcastlefix"; public const string Version = "1.1.1"; internal static ManualLogSource Log; internal static ConfigEntry<bool> FixNegativeScaleColliders; private void Awake() { //IL_0030: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; FixNegativeScaleColliders = ((BaseUnityPlugin)this).Config.Bind<bool>("Fixes", "FixNegativeScaleColliders", true, "Disable BoxColliders sitting under a negative-scale transform in PeachCastle modules. Unity force-abs()es these into reflected phantom collision (the 'walls clipping everywhere' pots in PaintingLuncheon). Disabling makes the affected decorative props walk-through, which beats invisible walls."); try { new Harmony("themorningstar.peachcastlefix").PatchAll(typeof(Plugin).Assembly); Log.LogInfo((object)"PeachCastleFix 1.1.1: Harmony patches applied."); } catch (Exception arg) { Log.LogError((object)$"PeachCastleFix PatchAll failed: {arg}"); } } } [HarmonyPatch(typeof(LevelGenerator), "GenerateDone")] internal static class LevelGenerator_GenerateDone_PeachCastleFix { private static readonly string[] AlcoveNames = new string[2] { "extra", "extra (2)" }; private static void Postfix(LevelGenerator __instance) { try { Transform val = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).transform : null); if ((Object)(object)val == (Object)null) { return; } int num = 0; int num2 = 0; foreach (Transform item in AllModules(val)) { if (((Object)item).name.Contains("PeachCastle")) { if (Plugin.FixNegativeScaleColliders.Value) { num += DisableNegativeScaleColliders(item); } if (((Object)item).name.Contains("StorageExtraction")) { num2++; HandleAlcoves(item); } } } if (num > 0 || num2 > 0) { Plugin.Log.LogInfo((object)$"[PeachCastleFix] GenerateDone pass: {num} negative-scale collider(s) disabled, {num2} extraction module(s) checked for alcove overhang."); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("[PeachCastleFix] GenerateDone pass failed: " + ex.Message)); } } private static IEnumerable<Transform> AllModules(Transform generatorRoot) { foreach (Transform item in generatorRoot) { Transform val = item; foreach (Transform item2 in val) { Transform val2 = item2; if (((Object)val2).name.StartsWith("Module")) { yield return val2; } } } } private static int DisableNegativeScaleColliders(Transform module) { //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) //IL_001f: 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_0077: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) int num = 0; BoxCollider[] componentsInChildren = ((Component)module).GetComponentsInChildren<BoxCollider>(true); foreach (BoxCollider val in componentsInChildren) { Vector3 lossyScale = ((Component)val).transform.lossyScale; if ((lossyScale.x < 0f || lossyScale.y < 0f || lossyScale.z < 0f) && ((Collider)val).enabled) { ((Collider)val).enabled = false; num++; Plugin.Log.LogInfo((object)$"[PeachCastleFix] Disabled negative-scale BoxCollider '{((Object)((Component)val).gameObject).name}' in '{((Object)module).name}' (lossyScale={lossyScale})."); } } return num; } private static void HandleAlcoves(Transform module) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) string[] alcoveNames = AlcoveNames; foreach (string text in alcoveNames) { Transform val = FindDirectOrDeep(module, text); if (!((Object)(object)val == (Object)null)) { float x = module.InverseTransformPoint(val.position).x; Plugin.Log.LogInfo((object)$"[PeachCastleFix] Room volume '{((Object)module).name}/{text}': module-local X={x:F1}."); } } } private static Transform? FindDirectOrDeep(Transform root, string name) { for (int i = 0; i < root.childCount; i++) { Transform child = root.GetChild(i); if (((Object)child).name == name) { return child; } Transform val = FindDirectOrDeep(child, name); if ((Object)(object)val != (Object)null) { return val; } } return null; } } [HarmonyPatch(typeof(ExtractionPoint), "Start")] internal static class ExtractionPoint_Start_PeachCastleFix { private const string ScopeA = "PeachCastle"; private const string ScopeB = "StorageExtraction"; private static readonly string[] TargetWallNames = new string[2] { "PeachCastle Pillar Wall 00 (2)", "PeachCastle Pillar Wall 00 (3)" }; private static readonly HashSet<int> _alreadyFixed = new HashSet<int>(); private static void Postfix(ExtractionPoint __instance) { //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) Transform val = FindModuleRoot(((Component)__instance).transform); if ((Object)(object)val == (Object)null) { return; } int instanceID = ((Object)((Component)val).gameObject).GetInstanceID(); if (!_alreadyFixed.Add(instanceID)) { return; } Plugin.Log.LogInfo((object)$"[PeachCastleFix] Fixing '{((Object)val).name}' (instanceID={instanceID})"); int num = 0; bool flag = false; string[] targetWallNames = TargetWallNames; foreach (string text in targetWallNames) { Transform val2 = FindDeepChild(val, text); if ((Object)(object)val2 == (Object)null) { flag = true; Plugin.Log.LogWarning((object)("[PeachCastleFix] Named target '" + text + "' not found — mod version may have renamed it. Check the diagnostic dump below.")); continue; } BoxCollider[] components = ((Component)val2).GetComponents<BoxCollider>(); foreach (BoxCollider val3 in components) { Plugin.Log.LogInfo((object)("[PeachCastleFix] Disabling BoxCollider on '" + text + "'" + $" | center={val3.center} size={val3.size}")); ((Collider)val3).enabled = false; num++; } } Plugin.Log.LogInfo((object)$"[PeachCastleFix] Named pass: {num} BoxCollider(s) disabled."); if (flag) { DumpAllColliders(val); } } private static Transform? FindModuleRoot(Transform t) { Transform val = t; while ((Object)(object)val != (Object)null) { if (((Object)val).name.Contains("PeachCastle") && ((Object)val).name.Contains("StorageExtraction")) { return val; } val = val.parent; } return null; } private static Transform? FindDeepChild(Transform root, string name) { for (int i = 0; i < root.childCount; i++) { Transform child = root.GetChild(i); if (((Object)child).name == name) { return child; } Transform val = FindDeepChild(child, name); if ((Object)(object)val != (Object)null) { return val; } } return null; } private static void DumpAllColliders(Transform moduleRoot) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: 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_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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_0060: 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_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: 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) BoxCollider[] componentsInChildren = ((Component)moduleRoot).GetComponentsInChildren<BoxCollider>(true); Plugin.Log.LogInfo((object)$"[PeachCastleFix] === Collider dump: {componentsInChildren.Length} BoxColliders in '{((Object)moduleRoot).name}' ==="); BoxCollider[] array = componentsInChildren; foreach (BoxCollider val in array) { Vector3 val2 = ((Component)val).transform.TransformPoint(val.center); Vector3 val3 = Vector3.Scale(val.size, ((Component)val).transform.lossyScale); bool flag = (Object)(object)((Component)val).GetComponent<Renderer>() != (Object)null; Plugin.Log.LogInfo((object)("[PeachCastleFix] '" + ((Object)((Component)val).gameObject).name + "'" + $" wPos=({val2.x:F1},{val2.y:F1},{val2.z:F1})" + $" lossySize=({Mathf.Abs(val3.x):F2},{Mathf.Abs(val3.y):F2},{Mathf.Abs(val3.z):F2})" + $" enabled={((Collider)val).enabled} rend={flag}")); } Plugin.Log.LogInfo((object)"[PeachCastleFix] === End dump ==="); } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { internal IgnoresAccessChecksToAttribute(string assemblyName) { } } }