Decompiled source of KairenceAntiSeeker v0.1.0

KairenceAntiSeeker.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
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: AssemblyCompany("KairenceAntiSeeker")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("KairenceAntiSeeker")]
[assembly: AssemblyTitle("KairenceAntiSeeker")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace KairenceAntiSeeker;

[BepInPlugin("com.kairence.antiseeker", "KairenceAntiSeeker", "1.0.0")]
public class KairenceAntiSeekerPlugin : BaseUnityPlugin
{
	public static ManualLogSource ModLogger;

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Expected O, but got Unknown
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Expected O, but got Unknown
		ModLogger = ((BaseUnityPlugin)this).Logger;
		Harmony val = new Harmony("com.kairence.antiseeker");
		MethodInfo methodInfo = AccessTools.Method(typeof(Character), "Awake", (Type[])null, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(KairencePatches), "Prefix_Character_Awake", (Type[])null, (Type[])null);
		if (methodInfo != null && methodInfo2 != null)
		{
			val.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		MethodInfo methodInfo3 = AccessTools.Method(typeof(Ragdoll), "Awake", (Type[])null, (Type[])null);
		MethodInfo methodInfo4 = AccessTools.Method(typeof(KairencePatches), "Prefix_Ragdoll_Awake", (Type[])null, (Type[])null);
		if (methodInfo3 != null && methodInfo4 != null)
		{
			val.Patch((MethodBase)methodInfo3, new HarmonyMethod(methodInfo4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		ModLogger.LogWarning((object)"[KairenceAntiSeeker] System hooks registered successfully.");
	}
}
public static class KairencePatches
{
	public static bool Prefix_Character_Awake(Character __instance)
	{
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Expected O, but got Unknown
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Expected O, but got Unknown
		if ((Object)(object)__instance == (Object)null || (Object)(object)((Component)__instance).gameObject == (Object)null)
		{
			return true;
		}
		ReadOnlySpan<char> span = ((Object)((Component)__instance).gameObject).name.AsSpan();
		int num = span.IndexOf('(');
		ReadOnlySpan<char> span2 = ((num > 0) ? span.Slice(0, num).Trim() : span.Trim());
		if (MemoryExtensions.Equals(span2, "Seeker".AsSpan(), StringComparison.OrdinalIgnoreCase) || MemoryExtensions.Equals(span2, "SeekerBrute".AsSpan(), StringComparison.OrdinalIgnoreCase))
		{
			Renderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
			AudioSource[] componentsInChildren2 = ((Component)__instance).GetComponentsInChildren<AudioSource>(true);
			for (int j = 0; j < componentsInChildren2.Length; j++)
			{
				componentsInChildren2[j].mute = true;
				componentsInChildren2[j].Stop();
			}
			Collider[] componentsInChildren3 = ((Component)__instance).GetComponentsInChildren<Collider>(true);
			for (int k = 0; k < componentsInChildren3.Length; k++)
			{
				componentsInChildren3[k].enabled = false;
			}
			BaseAI component = ((Component)__instance).GetComponent<BaseAI>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
			MonsterAI component2 = ((Component)__instance).GetComponent<MonsterAI>();
			if ((Object)(object)component2 != (Object)null)
			{
				((Behaviour)component2).enabled = false;
			}
			__instance.m_faction = (Faction)0;
			__instance.m_name = string.Empty;
			__instance.m_deathEffects = new EffectList();
			__instance.m_hitEffects = new EffectList();
			if ((Object)(object)((Component)__instance).gameObject.GetComponent<KairenceSeekerTerminator>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<KairenceSeekerTerminator>();
			}
		}
		return true;
	}

	public static bool Prefix_Ragdoll_Awake(Ragdoll __instance)
	{
		if ((Object)(object)__instance == (Object)null || (Object)(object)((Component)__instance).gameObject == (Object)null)
		{
			return true;
		}
		ReadOnlySpan<char> span = ((Object)((Component)__instance).gameObject).name.AsSpan();
		if (span.IndexOf("Seeker".AsSpan(), StringComparison.OrdinalIgnoreCase) >= 0 && span.IndexOf("SeekerBrood".AsSpan(), StringComparison.OrdinalIgnoreCase) < 0 && span.IndexOf("SeekerQueen".AsSpan(), StringComparison.OrdinalIgnoreCase) < 0)
		{
			Renderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
			Object.Destroy((Object)(object)((Component)__instance).gameObject);
			return false;
		}
		return true;
	}
}
public class KairenceSeekerTerminator : MonoBehaviour
{
	private int _frameTicks;

	private void Update()
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		_frameTicks++;
		if (_frameTicks < 2)
		{
			return;
		}
		CharacterDrop component = ((Component)this).GetComponent<CharacterDrop>();
		if ((Object)(object)component != (Object)null)
		{
			component.SetDropsEnabled(false);
			List<KeyValuePair<GameObject, int>> list = component.GenerateDropList();
			if (list != null && list.Count > 0)
			{
				Vector3 val = ((Component)this).transform.position + Vector3.up * 0.5f;
				CharacterDrop.DropItems(list, val, 0.5f, false);
			}
		}
		ZNetView component2 = ((Component)this).GetComponent<ZNetView>();
		if ((Object)(object)component2 != (Object)null && component2.IsValid())
		{
			if (!component2.IsOwner())
			{
				component2.ClaimOwnership();
			}
			if ((Object)(object)ZNetScene.instance != (Object)null)
			{
				ZNetScene.instance.Destroy(((Component)this).gameObject);
			}
			else
			{
				component2.Destroy();
			}
		}
		else
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}
}