Decompiled source of UltraMagnet v0.0.11

UltraMagnet/UltraMagnet.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using PluginConfig.API;
using PluginConfig.API.Decorators;
using PluginConfig.API.Fields;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("UltraMagnet")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UltraMagnet")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("75f6899f-9595-4ae3-95d9-6a38a5411b24")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace UltraMagnet;

[HarmonyPatch]
public static class Breakable_Patch
{
	[HarmonyPrefix]
	[HarmonyPatch(typeof(Breakable), "Start")]
	private static void patch_Start(Breakable __instance)
	{
		if (Object.op_Implicit((Object)(object)((Component)__instance).GetComponentInParent<Harpoon>()))
		{
			((Component)__instance).gameObject.SetActive(!ConfigManager.unbreakable.value);
		}
	}
}
[HarmonyPatch]
public static class Cannonball_Patch
{
	[HarmonyPrefix]
	[HarmonyPatch(typeof(Cannonball), "Start")]
	private static void patch_Start(Cannonball __instance)
	{
		if (ConfigManager.cannonballPatchPanel.value)
		{
			ComponentExtensions.GetOrAddComponent<MagnetScript>((Component)(object)__instance);
		}
	}
}
[HarmonyPatch]
public static class Coin_Patch
{
	private static MagnetScript script;

	[HarmonyPrefix]
	[HarmonyPatch(typeof(Coin), "Start")]
	private static void patch_Start(Coin __instance)
	{
		if (ConfigManager.coinPatchPanel.value)
		{
			script = ComponentExtensions.GetOrAddComponent<MagnetScript>((Component)(object)__instance);
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(Coin), "Update")]
	private static void patch_Update(Coin __instance)
	{
		if (script.isOnMagnet)
		{
			((MonoBehaviour)__instance).CancelInvoke("GetDeleted");
		}
		else
		{
			((MonoBehaviour)__instance).Invoke("GetDeleted", 5f);
		}
	}
}
public static class ConfigManager
{
	public static PluginConfigurator config;

	public static FloatField radius;

	public static FloatField hz;

	public static BoolField cannonballPatchPanel;

	public static BoolField coinPatchPanel;

	public static BoolField projectilePatchPanel;

	public static BoolField grenadePatchPanel;

	public static BoolField unbreakable;

	public static void Init()
	{
		//IL_0058: 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: Expected O, but got Unknown
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Expected O, but got Unknown
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Expected O, but got Unknown
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Expected O, but got Unknown
		//IL_00eb: 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_0110: Expected O, but got Unknown
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Expected O, but got Unknown
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Expected O, but got Unknown
		config = PluginConfigurator.Create("UltraMagnet", "ostia.UltraMagnet");
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		string text = Path.Combine(directoryName, "icon.png");
		config.SetIconWithURL("file://" + text);
		new ConfigHeader(config.rootPanel, "Patches", 24);
		cannonballPatchPanel = new BoolField(config.rootPanel, "Cannonball", "cannonballPatchPanel", true);
		coinPatchPanel = new BoolField(config.rootPanel, "Coin", "coinPatchPanel", true);
		projectilePatchPanel = new BoolField(config.rootPanel, "Projectile", "projectilePatchPanel", true);
		grenadePatchPanel = new BoolField(config.rootPanel, "Grenade", "grenadePatchPanel", true);
		new ConfigHeader(config.rootPanel, "Magnet", 24);
		unbreakable = new BoolField(config.rootPanel, "Unbreakable", "unbreakable", true);
		radius = new FloatField(config.rootPanel, "Radius", "radius", 1000f);
		hz = new FloatField(config.rootPanel, "hz", "field.hz", 80f, 0f, 85f);
	}
}
[HarmonyPatch]
public static class Grenade_Patch
{
	[HarmonyPrefix]
	[HarmonyPatch(typeof(Grenade), "Start")]
	private static void patch_Start(Grenade __instance)
	{
		if (ConfigManager.grenadePatchPanel.value)
		{
			ComponentExtensions.GetOrAddComponent<MagnetScript>((Component)(object)__instance);
		}
	}
}
public class MagnetScript : MonoBehaviour
{
	public List<Magnet> magnets = new List<Magnet>();

	public bool isOnMagnet;

	private int magnetRotationDirection;

	private Rigidbody rb;

	public event Action<bool> onMagnet;

	private Magnet GetTargetMagnet()
	{
		//IL_0022: 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_0037: 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_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: 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_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		Magnet result = null;
		float num = float.PositiveInfinity;
		for (int i = 0; i < magnets.Count; i++)
		{
			Vector3 val = ((Component)magnets[i]).transform.position - ((Component)this).transform.position;
			float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
			if (sqrMagnitude < num)
			{
				num = sqrMagnitude;
				result = magnets[i];
				Vector3 val2 = new Vector3(rb.velocity.z, rb.velocity.y, 0f - rb.velocity.x);
				Vector3 normalized = ((Vector3)(ref val2)).normalized;
				if (Vector3.Dot(val, normalized) > 0f)
				{
					magnetRotationDirection = -1;
				}
				else
				{
					magnetRotationDirection = 1;
				}
			}
		}
		return result;
	}

	private void Start()
	{
		rb = ((Component)this).GetComponent<Rigidbody>();
	}

	private void LateUpdate()
	{
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: 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_00bf: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		if (magnets.Count > 0)
		{
			magnets.RemoveAll((Magnet magnet) => (Object)(object)magnet == (Object)null);
			if (magnets.Count != 0)
			{
				Magnet targetMagnet = GetTargetMagnet();
				if (Object.op_Implicit((Object)(object)targetMagnet))
				{
					isOnMagnet = true;
					Rigidbody obj = rb;
					Vector3 velocity = rb.velocity;
					Quaternion val = Quaternion.Euler(0f, ConfigManager.hz.value * (float)magnetRotationDirection, 0f);
					Vector3 val2 = ((Component)targetMagnet).transform.position - ((Component)this).transform.position;
					Vector3 val3 = val * ((Vector3)(ref val2)).normalized;
					val2 = rb.velocity;
					Vector3 val4 = val3 * ((Vector3)(ref val2)).magnitude;
					val2 = rb.velocity;
					obj.velocity = Vector3.RotateTowards(velocity, val4, float.PositiveInfinity, ((Vector3)(ref val2)).magnitude);
				}
			}
		}
		else
		{
			isOnMagnet = false;
		}
	}
}
[HarmonyPatch]
public static class Magnet_Patch
{
	[HarmonyPrefix]
	[HarmonyPatch(typeof(Magnet), "Start")]
	private static void patch_Start(Magnet __instance)
	{
		((Component)__instance).GetComponent<SphereCollider>().radius = ConfigManager.radius.value;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(Magnet), "OnTriggerEnter")]
	private static void patch_OnTriggerEnter(Magnet __instance, ref Collider other)
	{
		MagnetScript magnetScript = default(MagnetScript);
		if (((Component)other).TryGetComponent<MagnetScript>(ref magnetScript) && !magnetScript.magnets.Contains(__instance))
		{
			magnetScript.magnets.Add(__instance);
		}
	}
}
[BepInPlugin("ostia.UltraMagnet", "UltraMagnet", "0.0.11")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string PLUGIN_GUID = "ostia.UltraMagnet";

	public const string PLUGIN_NAME = "UltraMagnet";

	public const string PLUGIN_VERSION = "0.0.11";

	private static Harmony harmony = new Harmony("ostia.UltraMagnet");

	private void Awake()
	{
		ConfigManager.Init();
		harmony.PatchAll();
	}
}
[HarmonyPatch]
public static class Projectile_Patch
{
	[HarmonyPrefix]
	[HarmonyPatch(typeof(Projectile), "Start")]
	private static void patch_Start(Projectile __instance)
	{
		if (ConfigManager.projectilePatchPanel.value)
		{
			ComponentExtensions.GetOrAddComponent<MagnetScript>((Component)(object)__instance);
		}
	}
}