Decompiled source of Wormhole v1.0.0

Wormhole.dll

Decompiled 5 months 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 BoplFixedMath;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PlatformApi;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyCompany("Wormhole")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Blackhole teleports player to whitehole")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+4d0204f90824dc5d2a35e5ce2b6e63b3bf8552c7")]
[assembly: AssemblyProduct("Wormhole")]
[assembly: AssemblyTitle("Wormhole")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Wormhole
{
	internal class Patches
	{
		internal static readonly HashSet<BlackHole> whiteHoles = new HashSet<BlackHole>();

		internal static readonly Dictionary<BlackHole, BlackHole> holePairs = new Dictionary<BlackHole, BlackHole>();

		private static readonly FieldInfo massField = GetField<BlackHole>("mass");

		private static readonly FieldInfo affectorLayerField = GetField<BlackHole>("affectorLayer");

		private static readonly FieldInfo playerLayerField = GetField<BlackHole>("playerLayer");

		private static readonly FieldInfo bodyField = GetField<PlayerCollision>("body");

		private static readonly FieldInfo physicsField = GetField<PlayerCollision>("physics");

		private static FieldInfo GetField<T>(string name)
		{
			return typeof(T).GetField(name, AccessTools.all);
		}

		private static Fix GetMass(BlackHole blackHole)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return (Fix)massField.GetValue(blackHole);
		}

		private static void ConnectToEmptyPair(BlackHole blackHole, bool isWhitehole)
		{
			foreach (KeyValuePair<BlackHole, BlackHole> holePair in holePairs)
			{
				if (!((Object)(object)holePair.Value != (Object)null) && whiteHoles.Contains(holePair.Key) != isWhitehole && !((Object)(object)holePair.Key == (Object)(object)blackHole))
				{
					holePairs[holePair.Key] = blackHole;
					holePairs[blackHole] = holePair.Key;
					break;
				}
			}
		}

		private static void RemoveConnection(BlackHole blackHole, bool tryReconnect)
		{
			try
			{
				BlackHole val = holePairs[blackHole];
				if ((Object)(object)val != (Object)null)
				{
					holePairs[val] = null;
					if (tryReconnect)
					{
						ConnectToEmptyPair(val, whiteHoles.Contains(val));
					}
				}
				holePairs[blackHole] = null;
			}
			catch (KeyNotFoundException)
			{
			}
		}

		internal static void SpawnPlayers_Postfix()
		{
			holePairs.Clear();
			whiteHoles.Clear();
		}

		private static bool TeleportPlayer(GameObject collidedObject, BlackHole pair)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			PlayerCollision component = collidedObject.GetComponent<PlayerCollision>();
			if ((Object)(object)component == (Object)null)
			{
				BoplBody component2 = collidedObject.GetComponent<BoplBody>();
				component2.position = pair.dCircle.position + Vec2.NormalizedSafe(component2.velocity) * pair.dCircle.radius;
				return false;
			}
			object? value = bodyField.GetValue(component);
			PlayerBody val = (PlayerBody)((value is PlayerBody) ? value : null);
			object? value2 = physicsField.GetValue(component);
			object? obj = ((value2 is PlayerPhysics) ? value2 : null);
			RopeBody ropeBody = val.ropeBody;
			if (ropeBody != null)
			{
				ropeBody.Dettach(true);
			}
			if (obj != null)
			{
				((PlayerPhysics)obj).UnGround(true, false);
			}
			val.position = pair.dCircle.position + Vec2.NormalizedSafe(val.Velocity) * pair.dCircle.radius;
			return false;
		}

		private static bool TeleportObject(GameObject collidedObject, BlackHole pair)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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)
			if ((Object)(object)collidedObject.GetComponent<SpikeAttack>() != (Object)null)
			{
				return true;
			}
			BoplBody component = collidedObject.GetComponent<BoplBody>();
			Vec2 val = Vec2.NormalizedSafe(component.velocity);
			component.position = pair.dCircle.position + val * pair.dCircle.radius * (pair.influenceRadiusMultiplier / (Fix)1.5);
			component.velocity /= pair.influenceRadiusMultiplier;
			return false;
		}

		private static bool TeleportPlatform(GameObject collidedObject, BlackHole pair)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			BoplBody component = collidedObject.GetComponent<BoplBody>();
			Vec2 val = pair.dCircle.position + Vec2.NormalizedSafe(component.velocity) * pair.dCircle.radius;
			PlatformApi.SetPos(collidedObject, val);
			PlatformApi.SetHome(collidedObject, val);
			return false;
		}

		private static void EatOtherHole(GameObject collidedObject, BlackHole blackHole, Fix mass)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			BlackHole component = collidedObject.GetComponent<BlackHole>();
			Fix mass2 = GetMass(component);
			if (mass > mass2 || (mass2 == mass && ((Renderer)blackHole.spriteRen).sortingOrder > ((Renderer)component.spriteRen).sortingOrder))
			{
				RemoveConnection(component, tryReconnect: false);
				whiteHoles.Remove(component);
				holePairs.Remove(component);
			}
		}

		internal static bool BlackHoleCollide_Prefix(BlackHole __instance, CollisionInformation collision)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			Fix mass = GetMass(__instance);
			if (mass < Fix.Zero)
			{
				return true;
			}
			GameObject gameObject = ((Component)collision.colliderPP.fixTrans).gameObject;
			if (collision.layer == (int)affectorLayerField.GetValue(__instance))
			{
				EatOtherHole(gameObject, __instance, mass);
				return true;
			}
			if (!holePairs.TryGetValue(__instance, out var value) || (Object)(object)value == (Object)null)
			{
				return true;
			}
			if (collision.layer == LayerMask.NameToLayer("wall"))
			{
				return TeleportPlatform(gameObject, value);
			}
			if (collision.layer == (int)playerLayerField.GetValue(__instance))
			{
				return TeleportPlayer(gameObject, value);
			}
			if (collision.colliderPP.monobehaviourCollider.inverseMass > Fix.Zero)
			{
				return TeleportObject(gameObject, value);
			}
			return true;
		}

		internal static void BlackHoleGrow_Postfix(BlackHole __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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_006d: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if (GetMass(__instance) >= Fix.Zero)
			{
				if (whiteHoles.Remove(__instance))
				{
					RemoveConnection(__instance, tryReconnect: true);
					ConnectToEmptyPair(__instance, isWhitehole: false);
					Object.Destroy((Object)(object)((Component)__instance).gameObject.GetComponent<LineRenderer>());
				}
			}
			else if (whiteHoles.Add(__instance))
			{
				LineRenderer obj = ((Component)__instance).gameObject.AddComponent<LineRenderer>();
				((Renderer)obj).material = new Material(Shader.Find("Hidden/Internal-Colored"));
				Color endColor = (obj.startColor = Color.black);
				obj.endColor = endColor;
				float endWidth = (obj.startWidth = 0.2f);
				obj.endWidth = endWidth;
				obj.positionCount = 2;
				RemoveConnection(__instance, tryReconnect: true);
				ConnectToEmptyPair(__instance, isWhitehole: true);
			}
		}

		internal static void BlackHoleInit_Postfix(BlackHole __instance)
		{
			holePairs.Add(__instance, null);
			ConnectToEmptyPair(__instance, isWhitehole: false);
		}

		internal static bool SmokeOnCollide_Prefix(CollisionInformation collision)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			BlackHole component = ((Component)collision.colliderPP.fixTrans).GetComponent<BlackHole>();
			if ((Object)(object)component == (Object)null)
			{
				return true;
			}
			if (holePairs.TryGetValue(component, out var value))
			{
				return (Object)(object)value == (Object)null;
			}
			return true;
		}
	}
	[BepInPlugin("com.almafa64.Wormhole", "Wormhole", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("BoplBattle.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal static Harmony harmony;

		internal static ManualLogSource logger;

		internal static GameObject sparkLightningPrefab;

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Expected O, but got Unknown
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Expected O, but got Unknown
			harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
			logger = ((BaseUnityPlugin)this).Logger;
			harmony.Patch((MethodBase)AccessTools.Method(typeof(GameSessionHandler), "SpawnPlayers", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Patches), "SpawnPlayers_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(BlackHole), "OnCollide", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Patches), "BlackHoleCollide_Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(BlackHole), "Grow", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Patches), "BlackHoleGrow_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(BlackHole), "Init", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Patches), "BlackHoleInit_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(SmokeGrenadeExplode2), "OnCollide", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Patches), "SmokeOnCollide_Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private void Start()
		{
			sparkLightningPrefab = Resources.FindObjectsOfTypeAll<GameObject>().First((GameObject e) => ((Object)e).name == "Chain_Lightning");
		}

		private void Update()
		{
			//IL_001e: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			foreach (BlackHole whiteHole in Patches.whiteHoles)
			{
				try
				{
					LineRenderer component = ((Component)whiteHole).GetComponent<LineRenderer>();
					component.SetPosition(0, Vector3.zero);
					component.SetPosition(1, Vector3.zero);
					BlackHole val = Patches.holePairs[whiteHole];
					if (!((Object)(object)val == (Object)null))
					{
						component.SetPosition(0, ((Component)((Component)val).transform).transform.position);
						component.SetPosition(1, ((Component)((Component)whiteHole).transform).transform.position);
					}
				}
				catch
				{
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Wormhole";

		public const string PLUGIN_NAME = "Wormhole";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}