Decompiled source of UltraPowerUps v1.1.0

plugins/UltraPowerUps/UltraPowerUps.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.AddressableAssets;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("UltraPowerUps")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UltraPowerUps")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("136bd50e-3918-4144-a995-73932febfa34")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace UltraPowerUps
{
	internal static class ColorExtensions
	{
		public static Color ChangeHSV(this Color color, float h, float s, float v)
		{
			//IL_0001: 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_001c: 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)
			float num = default(float);
			float num2 = default(float);
			float num3 = default(float);
			Color.RGBToHSV(color, ref num, ref num2, ref num3);
			return Color.HSVToRGB(num + h, num2 + s, num3 + v);
		}
	}
	[BepInPlugin("rougekill_ultrapowerups", "UltraPowerUps", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private static GameObject _holderObject;

		private static AssetBundle commonBundle;

		internal static Sprite defaultSprite;

		internal static ManualLogSource logger;

		public static GameObject HolderObject
		{
			get
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Expected O, but got Unknown
				if ((Object)(object)_holderObject == (Object)null)
				{
					_holderObject = new GameObject("Powerup Holder");
				}
				return _holderObject;
			}
		}

		private void Awake()
		{
			logger = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin " + ((BaseUnityPlugin)this).Info.Metadata.GUID + " is loaded!"));
		}

		private void Start()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			Harmony val = new Harmony("UltraPowerUps");
			val.PatchAll();
			PowerUpPickupBuilder.DualWieldPrefab = Addressables.LoadAssetAsync<GameObject>((object)"Assets/Prefabs/Levels/DualWieldPowerup.prefab").WaitForCompletion();
		}
	}
	public static class PowerUpManager
	{
		private static Dictionary<string, PowerUpInfo> powerups = new Dictionary<string, PowerUpInfo>();

		public static PowerUpInfo GetPowerUp(string id)
		{
			powerups.TryGetValue(id, out var value);
			return value;
		}

		public static void RegisterPowerUp(PowerUpInfo powerUp)
		{
			powerups[powerUp.ID] = powerUp;
		}

		public static GameObject CreatePowerUpPickup(PowerUpInfo info, Vector3 position)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			return ((Component)info.PickupBuilder.CreatePickup(position)).gameObject;
		}

		public static GameObject CreatePowerUpPickup(string id, Vector3 position)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			PowerUpInfo powerUp = GetPowerUp(id);
			if (powerUp == null)
			{
				throw new InvalidOperationException("Cannot create powerup because ID was unknown.");
			}
			return CreatePowerUpPickup(powerUp, position);
		}
	}
	public class PowerUpPickup : MonoBehaviour
	{
		public PowerUpInfo Info { get; set; }

		private void OnTriggerEnter(Collider other)
		{
			if (((Component)other).gameObject.tag == "Player")
			{
				PickedUp();
			}
		}

		private void PickedUp()
		{
			Info.Activate(out var _);
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}
	public class PowerUpPickupBuilder
	{
		internal static GameObject DualWieldPrefab { get; set; }

		public PowerUpInfo Info { get; }

		public PowerUpPickupBuilder(PowerUpInfo info)
		{
			Info = info;
		}

		public virtual PowerUpPickup CreatePickup(Vector3 position)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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)
			GameObject val = Object.Instantiate<GameObject>(DualWieldPrefab);
			Object.Destroy((Object)(object)val.GetComponent<DualWieldPickup>());
			val.transform.position = position;
			Renderer component = val.GetComponent<Renderer>();
			component.material.color = Info.Color;
			val.AddComponent<PowerUpPickup>();
			PowerUpPickup component2 = val.GetComponent<PowerUpPickup>();
			component2.Info = Info;
			SpriteRenderer componentInChildren = ((Component)val.transform).GetComponentInChildren<SpriteRenderer>();
			componentInChildren.sprite = Info.Icon;
			Light componentInChildren2 = ((Component)val.transform).GetComponentInChildren<Light>();
			componentInChildren2.color = Info.Color;
			componentInChildren2.intensity = Info.LightIntensity;
			return component2;
		}
	}
	public abstract class PowerUp : MonoBehaviour
	{
		public PowerUpInfo Info { get; internal set; }

		protected virtual void Start()
		{
			MonoSingleton<CameraController>.Instance.CameraShake(0.35f);
		}
	}
	public class PowerUpInfo
	{
		public string ID { get; set; } = Guid.NewGuid().ToString();


		public Color Color { get; set; } = Color.white;


		public Sprite Icon { get; set; } = Plugin.defaultSprite;


		public float LightIntensity { get; set; } = 10f;


		public PowerUpPickupBuilder PickupBuilder { get; set; }

		public Type BehaviourType { get; set; }

		public float DurationSeconds { get; set; } = 30f;


		public bool FPSOnly { get; set; } = true;


		public virtual bool Activate(out PowerUp component)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			if ((int)MonoSingleton<PlayerTracker>.Instance.playerType == 1 && FPSOnly)
			{
				MonoSingleton<CameraController>.Instance.CameraShake(0.35f);
				MonoSingleton<PlatformerMovement>.Instance.AddExtraHit(3);
				component = null;
				return false;
			}
			GameObject holderObject = Plugin.HolderObject;
			component = holderObject.GetComponent(BehaviourType) as PowerUp;
			if ((Object)(object)component != (Object)null)
			{
				return false;
			}
			component = (holderObject.AddComponent(BehaviourType) as PowerUp) ?? throw new Exception("The behaviour type is not a PowerUp!");
			component.Info = this;
			return true;
		}

		public virtual void Deactivate()
		{
			GameObject holderObject = Plugin.HolderObject;
			Component component = holderObject.GetComponent(BehaviourType);
			if (!((Object)(object)component == (Object)null))
			{
				Object.Destroy((Object)(object)component);
			}
		}

		public PowerUpInfo()
		{
			//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)
			PickupBuilder = new PowerUpPickupBuilder(this);
		}
	}
	public abstract class TimedPowerUp : PowerUp
	{
		internal static bool isDualWieldActive;

		protected PowerUpMeter meter;

		protected override void Start()
		{
			//IL_005e: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			base.Start();
			meter = MonoSingleton<PowerUpMeter>.Instance;
			if (!((Object)(object)meter == (Object)null))
			{
				meter.latestMaxJuice = base.Info.DurationSeconds;
				meter.juice = base.Info.DurationSeconds;
				meter.powerUpColor = base.Info.Color.ChangeHSV(0f, -0.1f, 0f);
			}
		}

		protected virtual void Update()
		{
			if (meter == null)
			{
				meter = MonoSingleton<PowerUpMeter>.Instance;
			}
			if (!((Object)(object)meter == (Object)null) && meter.juice <= 0f)
			{
				base.Info.Deactivate();
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "UltraPowerUps";

		public const string PLUGIN_NAME = "";

		public const string PLUGIN_VERSION = "";
	}
}
namespace UltraPowerUps.Patches
{
	[HarmonyPatch(typeof(DualWield), "EndPowerUp")]
	internal static class SetDualWieldActiveFalsePatch
	{
		private static void Prefix()
		{
			TimedPowerUp.isDualWieldActive = false;
		}
	}
	[HarmonyPatch(typeof(DualWield), "Start")]
	internal static class SetDualWieldActiveTruePatch
	{
		private static void Prefix()
		{
			TimedPowerUp.isDualWieldActive = true;
		}
	}
}