Decompiled source of DefeatRespawner v0.0.4

plugins/DefeatRespawner.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
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 REPOLib.Modules;
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("SolarAaron")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DefeatRespawner")]
[assembly: AssemblyTitle("DefeatRespawner")]
[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 DefeatRespawner
{
	[BepInPlugin("SolarAaron.DefeatRespawner", "DefeatRespawner", "0.0.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class DefeatRespawner : BaseUnityPlugin
	{
		public static int NumOfMutations = 3;

		public static int MutationChance = 25;

		private ConfigEntry<int>? _configMutations;

		private ConfigEntry<int>? _configChance;

		internal static DefeatRespawner Instance { get; private set; } = null;


		internal static ManualLogSource Logger => Instance.BaseLogger;

		private ManualLogSource BaseLogger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			_configMutations = ((BaseUnityPlugin)this).Config.Bind<int>("General", "numOfRespawns", NumOfMutations, new ConfigDescription("Number of Respawns per enemy death (1 death -> # new enemies", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
			NumOfMutations = _configMutations.Value;
			_configChance = ((BaseUnityPlugin)this).Config.Bind<int>("General", "respawnChance", MutationChance, new ConfigDescription("Chance of Respawn happening per respawn", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			MutationChance = _configChance.Value;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		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.PatchAll();
			Logger.LogInfo((object)"Defeat Respawner: Patched!!");
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
	[HarmonyPatch(typeof(EnemyHealth), "Death")]
	public class EnemyHealthPatch
	{
		private static readonly List<int> enemies = new List<int>();

		private static readonly string[] bannedEnemies = new string[2] { "Gnome", "Banger" };

		private static void Postfix(EnemyHealth __instance)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			Enemy val = (Enemy)AccessTools.Field(typeof(EnemyHealth), "enemy").GetValue(__instance);
			int instanceID = ((Object)val).GetInstanceID();
			HashSet<LevelPoint> bannedPoints = new HashSet<LevelPoint>();
			if (enemies.Contains(instanceID))
			{
				return;
			}
			foreach (LevelPoint item in SemiFunc.LevelPointsGetAllCloseToPlayers())
			{
				foreach (LevelPoint item2 in SemiFunc.LevelPointGetWithinDistance(((Component)item).transform.position, 0f, 10f))
				{
					bannedPoints.Add(item2);
				}
			}
			foreach (LevelPoint item3 in SemiFunc.LevelPointGetWithinDistance(((Component)__instance).transform.position, 0f, 10f))
			{
				bannedPoints.Add(item3);
			}
			string enemyName = ((Component)val).GetComponentInParent<EnemyParent>().enemyName;
			EnemySetup val2 = default(EnemySetup);
			if (bannedEnemies.Contains(enemyName) || enemyName == null || !Enemies.TryGetEnemyByName(enemyName, ref val2))
			{
				return;
			}
			for (int i = 0; i < DefeatRespawner.NumOfMutations; i++)
			{
				if (Random.Range(0, 100) >= DefeatRespawner.MutationChance)
				{
					continue;
				}
				List<LevelPoint> list = (from arg in SemiFunc.LevelPointsGetAll()
					where !bannedPoints.Contains(arg) && !arg.inStartRoom
					select arg).ToList();
				ListExtension.Shuffle<LevelPoint>((IList<LevelPoint>)list);
				list.Add(null);
				LevelPoint val3 = list[0];
				if ((Object)(object)val3 == (Object)null)
				{
					List<LevelPoint> list2 = SemiFunc.LevelPointGetWithinDistance(((Component)val).transform.position, 1f, 10f);
					if (list2 != null && list2.Count > 0)
					{
						val3 = list2[0];
					}
					if ((Object)(object)val3 == (Object)null)
					{
						DefeatRespawner.Logger.LogError((object)"Level point not found for revived spawn.");
						continue;
					}
				}
				foreach (LevelPoint item4 in SemiFunc.LevelPointGetWithinDistance(((Component)val3).transform.position, 0f, 10f))
				{
					bannedPoints.Add(item4);
				}
				Enemies.SpawnEnemy(val2, ((Component)val3).transform.position, Quaternion.identity, false);
				SemiFunc.EnemyGetNearest(((Component)val3).transform.position, 2f, false);
				DefeatRespawner.Logger.LogInfo((object)$"Respawned: {enemyName} | ID: {instanceID} at {((Component)val3).transform.position}");
			}
		}
	}
}