Decompiled source of RosariesAndShellStaySafeFromSpikes v1.1.0

KeepRosariesAndShellShardsSafe.dll

Decompiled a month ago
using 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 HarmonyLib;
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("KeepRosariesAndShellShardsSafe")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KeepRosariesAndShellShardsSafe")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3ff33897-ce61-43aa-9de9-a4f8439fda39")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.yourname.KeepRosariesAndShellShardsSafe", "KeepRosariesAndShellShardsSafe", "1.1.0")]
public class KeepRosariesAndShellShardsSafe : BaseUnityPlugin
{
	private Harmony harmony;

	private static readonly string[] ProtectedNameParts = new string[4] { "shell", "shard", "rosary", "geo" };

	private void Awake()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Expected O, but got Unknown
		harmony = new Harmony("com.yourname.KeepRosariesAndShellShardsSafe");
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			try
			{
				Type[] types = assembly.GetTypes();
				foreach (Type type in types)
				{
					if (!typeof(MonoBehaviour).IsAssignableFrom(type))
					{
						continue;
					}
					IEnumerable<MethodInfo> enumerable = from m in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
						where m.Name == "Die" || m.Name == "Break" || m.Name == "Destroy"
						select m;
					foreach (MethodInfo item in enumerable)
					{
						harmony.Patch((MethodBase)item, new HarmonyMethod(typeof(KeepRosariesAndShellShardsSafe), "BlockDestruction", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					}
				}
			}
			catch
			{
			}
		}
	}

	private static bool BlockDestruction(object __instance)
	{
		if (__instance == null)
		{
			return true;
		}
		object obj = ((__instance is MonoBehaviour) ? __instance : null);
		GameObject val = ((obj != null) ? ((Component)obj).gameObject : null);
		if ((Object)(object)val == (Object)null)
		{
			return true;
		}
		string name = ((Object)val).name.ToLower();
		string text = "Untagged";
		try
		{
			text = val.tag;
		}
		catch
		{
		}
		bool flag = text.Equals("Geo", StringComparison.OrdinalIgnoreCase);
		bool flag2 = ProtectedNameParts.Any((string part) => name.Contains(part));
		if (flag && flag2)
		{
			Debug.Log((object)("[KeepRosariesAndShellShardsSafe] Protected object destruction attempt: " + ((Object)val).name + " (Tag: " + text + ")"));
			return false;
		}
		return true;
	}
}