using System;
using System.Diagnostics;
using System.Linq;
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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DoorsDontBreak")]
[assembly: AssemblyTitle("DoorsDontBreak")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 Empress.NoBreakDoors
{
[BepInPlugin("empress.nobreakdoors", "No Break Doors", "1.2.1")]
public sealed class NoBreakDoorsPlugin : BaseUnityPlugin
{
public const string PluginGuid = "empress.nobreakdoors";
public const string PluginName = "No Break Doors";
public const string PluginVersion = "1.2.1";
internal static ConfigEntry<bool> ProtectAllHinges = null;
internal static ConfigEntry<string> NameFiltersCsv = null;
internal static ConfigEntry<string> TagFiltersCsv = null;
internal static string[] NameFilters = Array.Empty<string>();
internal static string[] TagFilters = Array.Empty<string>();
internal static NoBreakDoorsPlugin Instance { get; private set; } = null;
internal static ManualLogSource Logger => Instance._logger;
private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;
internal Harmony? Harmony { get; private set; }
private void Awake()
{
Instance = this;
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
ProtectAllHinges = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ProtectAllHinges", false, "If true, prevents ALL PhysGrabHinge objects from breaking or being destroyed.");
NameFiltersCsv = ((BaseUnityPlugin)this).Config.Bind<string>("Filters", "NameFilters", "door,hatch,gate", "Comma-separated list of name substrings (case-insensitive). Any object whose name or parent's name contains one of these is protected.");
TagFiltersCsv = ((BaseUnityPlugin)this).Config.Bind<string>("Filters", "TagFilters", "", "Comma-separated list of Unity tags to protect. Leave blank if your project doesn't define them. We use a safe string compare (no CompareTag) to avoid Unity log spam if the tag isn't defined.");
NameFilters = SplitCsv(NameFiltersCsv.Value);
TagFilters = SplitCsv(TagFiltersCsv.Value);
Patch();
Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} loaded. ProtectAllHinges={ProtectAllHinges.Value}");
}
private void OnDestroy()
{
Unpatch();
}
internal void Patch()
{
//IL_001a: 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_0021: Expected O, but got Unknown
//IL_0026: Expected O, but got Unknown
if (Harmony == null)
{
Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
Harmony val2 = val;
Harmony = val;
}
Harmony.CreateAndPatchAll(typeof(HingePatches), (string)null);
}
internal void Unpatch()
{
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
Harmony = null;
}
private static string[] SplitCsv(string csv)
{
return string.IsNullOrWhiteSpace(csv) ? Array.Empty<string>() : (from s in csv.Split(',')
select s.Trim() into s
where s.Length > 0
select s).ToArray();
}
internal static bool IsProtected(GameObject go)
{
if ((Object)(object)go == (Object)null)
{
return false;
}
if ((Object)(object)go.GetComponent<ProtectedDoorTag>() != (Object)null)
{
return true;
}
if (ProtectAllHinges.Value)
{
return true;
}
string[] tagFilters = TagFilters;
foreach (string text in tagFilters)
{
if (string.IsNullOrEmpty(text))
{
continue;
}
try
{
if (go.tag == text)
{
return true;
}
}
catch
{
}
}
Transform val = go.transform;
while ((Object)(object)val != (Object)null)
{
string name = ((Object)val).name;
if (!string.IsNullOrEmpty(name))
{
for (int j = 0; j < NameFilters.Length; j++)
{
if (name.IndexOf(NameFilters[j], StringComparison.OrdinalIgnoreCase) >= 0)
{
return true;
}
}
}
val = val.parent;
}
return false;
}
}
public sealed class NoBreakProtector : MonoBehaviour
{
private HingeJoint _joint = null;
private PhysGrabHinge _hinge = null;
private void Awake()
{
_hinge = ((Component)this).GetComponent<PhysGrabHinge>();
_joint = ((Component)this).GetComponent<HingeJoint>();
Apply();
}
private void OnEnable()
{
Apply();
}
private void FixedUpdate()
{
Apply();
}
private void Apply()
{
if (!((Object)(object)_joint == (Object)null))
{
if (((Joint)_joint).breakForce < 8.5070587E+37f)
{
((Joint)_joint).breakForce = 1.7014117E+38f;
}
if (((Joint)_joint).breakTorque < 8.5070587E+37f)
{
((Joint)_joint).breakTorque = 1.7014117E+38f;
}
}
}
}
[HarmonyPatch]
internal static class HingePatches
{
[HarmonyPostfix]
[HarmonyPriority(200)]
[HarmonyPatch(typeof(PhysGrabHinge), "Awake")]
private static void PhysGrabHinge_Awake_Postfix(PhysGrabHinge __instance)
{
try
{
GameObject gameObject = ((Component)__instance).gameObject;
if (NoBreakDoorsPlugin.IsProtected(gameObject))
{
if ((Object)(object)gameObject.GetComponent<ProtectedDoorTag>() == (Object)null)
{
gameObject.AddComponent<ProtectedDoorTag>();
}
HingeJoint component = ((Component)__instance).GetComponent<HingeJoint>();
if ((Object)(object)component != (Object)null)
{
((Joint)component).breakForce = 1.7014117E+38f;
((Joint)component).breakTorque = 1.7014117E+38f;
}
if ((Object)(object)gameObject.GetComponent<NoBreakProtector>() == (Object)null)
{
gameObject.AddComponent<NoBreakProtector>();
}
}
}
catch (Exception arg)
{
Debug.LogError((object)$"[NoBreakDoors] Awake postfix failed: {arg}");
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PhysGrabHinge), "DestroyHinge")]
private static bool PhysGrabHinge_DestroyHinge_Prefix(PhysGrabHinge __instance)
{
if (!NoBreakDoorsPlugin.IsProtected((__instance != null) ? ((Component)__instance).gameObject : null))
{
return true;
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PhysGrabHinge), "OnJointBreak")]
private static bool PhysGrabHinge_OnJointBreak_Prefix(PhysGrabHinge __instance, float breakForce)
{
if (!NoBreakDoorsPlugin.IsProtected((__instance != null) ? ((Component)__instance).gameObject : null))
{
return true;
}
HingeJoint component = ((Component)__instance).GetComponent<HingeJoint>();
if ((Object)(object)component != (Object)null)
{
((Joint)component).breakForce = 1.7014117E+38f;
((Joint)component).breakTorque = 1.7014117E+38f;
}
return false;
}
}
internal sealed class ProtectedDoorTag : MonoBehaviour
{
}
}