Decompiled source of MonsterTeamSwap v1.0.2

MonsterTeamSwap.dll

Decompiled 7 months ago
using 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 HG.Reflection;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("MonsterTeamSwap")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Mod for Risk of Rain 2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MonsterTeamSwap")]
[assembly: AssemblyTitle("MonsterTeamSwap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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;
		}
	}
}
namespace System.Diagnostics.CodeAnalysis
{
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class AllowNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class DisallowNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class DoesNotReturnAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class DoesNotReturnIfAttribute : Attribute
	{
		public bool ParameterValue { get; }

		public DoesNotReturnIfAttribute(bool parameterValue)
		{
			ParameterValue = parameterValue;
		}
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MaybeNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MaybeNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public MaybeNullWhenAttribute(bool returnValue)
		{
			ReturnValue = returnValue;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MemberNotNullAttribute : Attribute
	{
		public string[] Members { get; }

		public MemberNotNullAttribute(string member)
		{
			Members = new string[1] { member };
		}

		public MemberNotNullAttribute(params string[] members)
		{
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MemberNotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public string[] Members { get; }

		public MemberNotNullWhenAttribute(bool returnValue, string member)
		{
			ReturnValue = returnValue;
			Members = new string[1] { member };
		}

		public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
		{
			ReturnValue = returnValue;
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class NotNullAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class NotNullIfNotNullAttribute : Attribute
	{
		public string ParameterName { get; }

		public NotNullIfNotNullAttribute(string parameterName)
		{
			ParameterName = parameterName;
		}
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class NotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public NotNullWhenAttribute(bool returnValue)
		{
			ReturnValue = returnValue;
		}
	}
}
namespace MonsterTeamSwap
{
	[BepInPlugin("com.DestroyedClone.MonsterTeamSwap", "Monster Team Swap", "1.0.2")]
	public class Class1 : BaseUnityPlugin
	{
		public static ConfigEntry<string> cfgNone;

		public static ConfigEntry<string> cfgNeutral;

		public static ConfigEntry<string> cfgPlayer;

		public static ConfigEntry<string> cfgMonster;

		public static ConfigEntry<string> cfgLunar;

		public static ConfigEntry<string> cfgVoid;

		public static ConfigEntry<bool> cfgArenaKill;

		public static ConfigEntry<bool> cfgVoidStaysVoid;

		public static List<CharacterMaster> arenaModifiedCharacterMasters = new List<CharacterMaster>();

		public static Dictionary<BodyIndex, TeamIndex> bodyIndex_to_teamIndex = new Dictionary<BodyIndex, TeamIndex>();

		internal static ManualLogSource _logger;

		internal static bool shouldStartTrackingArenaSpawns = false;

		public void Awake()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			_logger = ((BaseUnityPlugin)this).Logger;
			SetupConfig();
			DirectorCore.TrySpawnObject += new hook_TrySpawnObject(OverrideTeamSpawn);
			if (cfgArenaKill.Value)
			{
				ArenaMissionController.OnEnable += new hook_OnEnable(StartTracking);
				ArenaMissionController.OnDisable += new hook_OnDisable(StopTracking);
			}
		}

		private void StartTracking(orig_OnEnable orig, ArenaMissionController self)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			orig.Invoke(self);
			shouldStartTrackingArenaSpawns = true;
			ArenaMissionController.EndRound += new hook_EndRound(Arena_KillTracked);
		}

		private void StopTracking(orig_OnDisable orig, ArenaMissionController self)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			orig.Invoke(self);
			shouldStartTrackingArenaSpawns = false;
			arenaModifiedCharacterMasters.Clear();
			ArenaMissionController.EndRound -= new hook_EndRound(Arena_KillTracked);
		}

		private void Arena_KillTracked(orig_EndRound orig, ArenaMissionController self)
		{
			orig.Invoke(self);
			int num = 0;
			CharacterMaster[] array = arenaModifiedCharacterMasters.ToArray();
			foreach (CharacterMaster val in array)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					CharacterBody body = val.GetBody();
					if (body != null)
					{
						body.healthComponent.Suicide(((Component)self).gameObject, ((Component)self).gameObject, (DamageType)65536);
					}
					num++;
				}
			}
			arenaModifiedCharacterMasters.Clear();
		}

		public void SetupConfig()
		{
			string text = "Team Index Overrides";
			string text2 = "Exceptions";
			string text3 = "Add the names of Bodies you want to force switch the teams of.";
			cfgNone = ((BaseUnityPlugin)this).Config.Bind<string>(text, "None", "", text3 + " This is the name of a Team Index, not an exclusion list.");
			cfgNeutral = ((BaseUnityPlugin)this).Config.Bind<string>(text, "Neutral", "ImpBody,ImpBossBody", text3);
			cfgPlayer = ((BaseUnityPlugin)this).Config.Bind<string>(text, "Player", "", text3 + " Careful, without friendly fire you won't be able to damage them.");
			cfgMonster = ((BaseUnityPlugin)this).Config.Bind<string>(text, "Monster", "", text3);
			cfgLunar = ((BaseUnityPlugin)this).Config.Bind<string>(text, "Lunar", "LunarGolemBody,LunarWispBody,LunarExploderBody", text3);
			cfgVoid = ((BaseUnityPlugin)this).Config.Bind<string>(text, "Void", "NullifierBody,VoidJailerBody,VoidDevastatorBody,VoidBarnacleBody", text3);
			cfgVoidStaysVoid = ((BaseUnityPlugin)this).Config.Bind<bool>(text2, "Void Stays Void", true, "If something is already Void, such as those spawned by void camps, should it stay on the Void team?");
			cfgArenaKill = ((BaseUnityPlugin)this).Config.Bind<bool>(text2, "Kill Previously Monster On Void Fields Cell Clear", true, "If true, then anything spawned in the Void Fields that used to be on the Monster team will be killed when the cell kills off all the monsters.");
		}

		private GameObject OverrideTeamSpawn(orig_TrySpawnObject orig, DirectorCore self, DirectorSpawnRequest directorSpawnRequest)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Invalid comparison between Unknown and I4
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Invalid comparison between Unknown and I4
			if (Object.op_Implicit((Object)(object)directorSpawnRequest.spawnCard) && Object.op_Implicit((Object)(object)directorSpawnRequest.spawnCard.prefab))
			{
				CharacterMaster characterMaster = directorSpawnRequest.spawnCard.prefab.GetComponent<CharacterMaster>();
				if (Object.op_Implicit((Object)(object)characterMaster) && ((int)characterMaster.teamIndex != 4 || !cfgVoidStaysVoid.Value) && Object.op_Implicit((Object)(object)characterMaster.bodyPrefab))
				{
					BodyIndex bodyIndex = characterMaster.bodyPrefab.GetComponent<CharacterBody>().bodyIndex;
					if (bodyIndex_to_teamIndex.TryGetValue(bodyIndex, out var value))
					{
						if (shouldStartTrackingArenaSpawns && (int)characterMaster.teamIndex == 2)
						{
							directorSpawnRequest.onSpawnedServer = (Action<SpawnResult>)Delegate.Combine(directorSpawnRequest.onSpawnedServer, (Action<SpawnResult>)delegate(SpawnResult result)
							{
								//IL_0001: Unknown result type (might be due to invalid IL or missing references)
								//IL_0002: Unknown result type (might be due to invalid IL or missing references)
								//IL_0003: Unknown result type (might be due to invalid IL or missing references)
								if (result.success)
								{
									arenaModifiedCharacterMasters.Add(characterMaster);
								}
							});
						}
						directorSpawnRequest.teamIndexOverride = value;
					}
				}
			}
			return orig.Invoke(self, directorSpawnRequest);
		}

		[SystemInitializer(new Type[] { typeof(BodyCatalog) })]
		public static void SetupDictionary()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Invalid comparison between Unknown and I4
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			_logger.LogMessage((object)"Setting up!");
			TeamIndex val = (TeamIndex)(-1);
			string[] array = new string[6] { cfgNone.Value, cfgNeutral.Value, cfgPlayer.Value, cfgMonster.Value, cfgLunar.Value, cfgVoid.Value };
			foreach (string text in array)
			{
				_logger.LogMessage((object)$"Adding bodies to TeamIndex: {val}");
				string[] array2 = text.Split(new char[1] { ',' });
				if (array2.Length != 0)
				{
					string[] array3 = array2;
					foreach (string text2 in array3)
					{
						BodyIndex val2 = BodyCatalog.FindBodyIndex(text2);
						if ((int)val2 != -1)
						{
							bodyIndex_to_teamIndex.Add(val2, val);
							_logger.LogMessage((object)text2);
						}
					}
				}
				val = (TeamIndex)(sbyte)(val + 1);
			}
		}
	}
}