Decompiled source of MeridianPrimePrime v1.0.2

plugins/MeridianPrimePrime/MeridianPrimePrime.dll

Decompiled 4 days 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.Logging;
using EntityStates.Geode;
using EntityStates.Missions.GeodeSecretMission;
using HarmonyLib;
using MeridianPrimePrime.IL;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[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("MeridianPrimePrime")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+d5683c2e52a021b8812ae1f5257a066fff3f039b")]
[assembly: AssemblyProduct("MeridianPrimePrime")]
[assembly: AssemblyTitle("MeridianPrimePrime")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MeridianPrimePrime
{
	internal static class Compatibility
	{
		private const string GeodeShatterFixedVersion = "1.3.6";

		private static readonly Version ApplicationVersion;

		internal static readonly bool GeodeShatterFixed;

		static Compatibility()
		{
			ApplicationVersion = new Version(Application.version);
			GeodeShatterFixed = ApplicationVersion >= new Version("1.3.6");
		}
	}
	[BepInPlugin("itsschwer.MeridianPrimePrime", "MeridianPrimePrime", "1.0.2")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string GUID = "itsschwer.MeridianPrimePrime";

		public const string Author = "itsschwer";

		public const string Name = "MeridianPrimePrime";

		public const string Version = "1.0.2";

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			Logger.Sources.Remove((ILogSource)(object)((BaseUnityPlugin)this).Logger);
			Logger = Logger.CreateLogSource("itsschwer.MeridianPrimePrime");
			RemoveGeodeBuffFromAllPlayers.Apply();
			new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID).PatchAll();
			Logger.LogMessage((object)"~awake.");
		}
	}
}
namespace MeridianPrimePrime.IL
{
	internal static class RemoveGeodeBuffFromAllPlayers
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<Instruction, bool> <>9__0_2;

			public static Func<Instruction, bool> <>9__0_4;

			public static Func<Instruction, bool> <>9__0_5;

			public static Func<Instruction, bool> <>9__0_6;

			public static Manipulator <>9__0_0;

			internal void <Apply>b__0_0(ILContext il)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Expected O, but got Unknown
				//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00df: Unknown result type (might be due to invalid IL or missing references)
				<>c__DisplayClass0_0 CS$<>8__locals0 = new <>c__DisplayClass0_0();
				ILCursor val = new ILCursor(il);
				CS$<>8__locals0.iter = null;
				CS$<>8__locals0.curr = null;
				Func<Instruction, bool>[] array = new Func<Instruction, bool>[6]
				{
					(Instruction x) => ILPatternMatchingExt.MatchBr(x, ref CS$<>8__locals0.iter),
					(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 0),
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, ref CS$<>8__locals0.curr),
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<PlayerCharacterMasterController>(x, "get_networkUser"),
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<NetworkUser>(x, "GetCurrentBody"),
					(Instruction x) => ILPatternMatchingExt.MatchStloc(x, 1)
				};
				if (val.TryGotoNext((MoveType)2, array))
				{
					val.Emit(OpCodes.Ldloc_1);
					val.Emit(OpCodes.Brfalse, CS$<>8__locals0.iter.Target);
					return;
				}
				string text = "RemoveGeodeBuffFromAllPlayers> Cannot hook: failed to match IL instructions.";
				if (Compatibility.GeodeShatterFixed)
				{
					Plugin.Logger.LogWarning((object)(text + " This warning can safely be ignored if playing on or after patch RoR2v1.3.6 [Seekers of the Storm Roadmap Phase 1 — Items & Elites], as the null check is now implemented in vanilla."));
				}
				else
				{
					Plugin.Logger.LogError((object)text);
				}
			}

			internal bool <Apply>b__0_2(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdloc(x, 0);
			}

			internal bool <Apply>b__0_4(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallOrCallvirt<PlayerCharacterMasterController>(x, "get_networkUser");
			}

			internal bool <Apply>b__0_5(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallOrCallvirt<NetworkUser>(x, "GetCurrentBody");
			}

			internal bool <Apply>b__0_6(Instruction x)
			{
				return ILPatternMatchingExt.MatchStloc(x, 1);
			}
		}

		[CompilerGenerated]
		private sealed class <>c__DisplayClass0_0
		{
			public ILLabel iter;

			public MethodReference curr;

			internal bool <Apply>b__1(Instruction x)
			{
				return ILPatternMatchingExt.MatchBr(x, ref iter);
			}

			internal bool <Apply>b__3(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallOrCallvirt(x, ref curr);
			}
		}

		internal static void Apply()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			MethodInfo? method = typeof(GeodeShatter).GetMethod("RemoveGeodeBuffFromAllPlayers", BindingFlags.Instance | BindingFlags.NonPublic);
			object obj = <>c.<>9__0_0;
			if (obj == null)
			{
				Manipulator val = delegate(ILContext il)
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000d: Expected O, but got Unknown
					//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
					//IL_00df: Unknown result type (might be due to invalid IL or missing references)
					ILCursor val2 = new ILCursor(il);
					ILLabel iter = null;
					MethodReference curr = null;
					Func<Instruction, bool>[] array = new Func<Instruction, bool>[6]
					{
						(Instruction x) => ILPatternMatchingExt.MatchBr(x, ref iter),
						(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 0),
						(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, ref curr),
						(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<PlayerCharacterMasterController>(x, "get_networkUser"),
						(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<NetworkUser>(x, "GetCurrentBody"),
						(Instruction x) => ILPatternMatchingExt.MatchStloc(x, 1)
					};
					if (val2.TryGotoNext((MoveType)2, array))
					{
						val2.Emit(OpCodes.Ldloc_1);
						val2.Emit(OpCodes.Brfalse, iter.Target);
					}
					else
					{
						string text = "RemoveGeodeBuffFromAllPlayers> Cannot hook: failed to match IL instructions.";
						if (Compatibility.GeodeShatterFixed)
						{
							Plugin.Logger.LogWarning((object)(text + " This warning can safely be ignored if playing on or after patch RoR2v1.3.6 [Seekers of the Storm Roadmap Phase 1 — Items & Elites], as the null check is now implemented in vanilla."));
						}
						else
						{
							Plugin.Logger.LogError((object)text);
						}
					}
				};
				<>c.<>9__0_0 = val;
				obj = (object)val;
			}
			new ILHook((MethodBase)method, (Manipulator)obj);
		}
	}
}
namespace MeridianPrimePrime.Harmony
{
	[HarmonyPatch]
	internal static class GeodeSecretMissionReward
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(GeodeSecretMissionRewardState), "DropRewards")]
		private static void GeodeSecretMissionRewardState_DropRewards(GeodeSecretMissionRewardState __instance)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((GeodeSecretMissionEntityStates)__instance).geodeSecretMissionController.rewardSpawnLocation.transform.position;
			Quaternion identity = Quaternion.identity;
			Plugin.Logger.LogDebug((object)string.Format("{0} @ {1}", "GeodeSecretMissionReward", position));
			foreach (NetworkUser readOnlyInstances in NetworkUser.readOnlyInstancesList)
			{
				if (readOnlyInstances.master.IsDeadAndOutOfLivesServer())
				{
					readOnlyInstances.master.Respawn(position, identity, false);
				}
				try
				{
					LeashMinions(readOnlyInstances.master, position, 10f, identity);
				}
				catch (Exception ex)
				{
					Plugin.Logger.LogError((object)ex);
				}
			}
			RelocateBrokenDrones(position + Vector3.down * 2.6f, 6f);
		}

		private static void LeashMinions(CharacterMaster master, Vector3 position, float withinRadius, Quaternion rotation)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			MinionGroup val = MinionGroup.FindGroup(((NetworkBehaviour)master).netId);
			if (val == null || val.members == null)
			{
				return;
			}
			int num = 0;
			MinionOwnership[] members = val.members;
			foreach (MinionOwnership obj in members)
			{
				object obj2;
				if (obj == null)
				{
					obj2 = null;
				}
				else
				{
					CharacterMaster component = ((Component)obj).GetComponent<CharacterMaster>();
					obj2 = ((component != null) ? component.GetBody() : null);
				}
				CharacterBody val2 = (CharacterBody)obj2;
				if ((Object)(object)val2 != (Object)null)
				{
					Vector2 val3 = Random.insideUnitCircle * withinRadius;
					TeleportHelper.TeleportBody(val2, position + new Vector3(val3.x, 0f, val3.y), false);
					GameObject teleportEffectPrefab = Run.instance.GetTeleportEffectPrefab(((Component)val2).gameObject);
					if ((Object)(object)teleportEffectPrefab != (Object)null)
					{
						EffectManager.SimpleEffect(teleportEffectPrefab, position, rotation, true);
					}
					num++;
				}
			}
			Plugin.Logger.LogDebug((object)$"Leash-teleported {num} minion(s) for {((Object)master).name} (out of {val.members.Length})");
		}

		private static void RelocateBrokenDrones(Vector3 position, float radius)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			IList<PurchaseInteraction> list = (from purchaseInteraction in InstanceTracker.GetInstancesList<PurchaseInteraction>()
				where purchaseInteraction.displayNameToken.Contains("DRONE")
				select purchaseInteraction).ToList();
			if (list.Count <= 0)
			{
				return;
			}
			Quaternion val = Quaternion.AngleAxis(360f / (float)list.Count, Vector3.up);
			Vector3 val2 = Vector3.forward * radius;
			foreach (PurchaseInteraction item in list)
			{
				((Component)item).transform.position = position + val2;
				val2 = val * val2;
			}
			Plugin.Logger.LogDebug((object)$"Relocated {list.Count} broken drone(s)");
		}
	}
}