Decompiled source of KineticDive v1.0.2

KineticDive.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.Math;
using Pigeon.Movement;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyVersion("0.0.0.0")]
[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 KineticDiveMod
{
	[BepInPlugin("com.coloron.kineticdive", "Kinetic Dive", "1.0.1")]
	[MycoMod(/*Could not decode attribute arguments.*/)]
	public class KineticDivePlugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <SpeedBurstRoutine>d__13 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Player player;

			public float targetSpeed;

			public float duration;

			public KineticDivePlugin <>4__this;

			private float <time>5__1;

			private float <t>5__2;

			private float <ease>5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <SpeedBurstRoutine>d__13(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c7: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<time>5__1 = 0f;
					break;
				case 1:
					<>1__state = -1;
					<time>5__1 += Time.fixedDeltaTime;
					break;
				}
				if (<time>5__1 < duration)
				{
					<t>5__2 = 1f - <time>5__1 / duration;
					<ease>5__3 = ((<t>5__2 < 0.5f) ? (2f * <t>5__2 * <t>5__2) : (1f - Mathf.Pow(-2f * <t>5__2 + 2f, 2f) / 2f));
					<>4__this.ApplyTempMoveSpeed(player, targetSpeed * <ease>5__3);
					<>2__current = (object)new WaitForFixedUpdate();
					<>1__state = 1;
					return true;
				}
				<>4__this._speedCoroutine = null;
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public const string PluginGUID = "com.coloron.kineticdive";

		public const string PluginName = "Kinetic Dive";

		public const string PluginVersion = "1.0.1";

		public const int ModUpgradeID = 88889;

		public static KineticDivePlugin Instance;

		public static Upgrade CustomUpgradeInstance;

		public static Sprite AbilityIcon;

		private Coroutine _speedCoroutine;

		private void Awake()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading Kinetic Dive...");
			LoadExternalIcon();
			new Harmony("com.coloron.kineticdive").PatchAll();
			PlayerData.AddRegisterUpgradesCallback((Action)InitializeUpgrades);
		}

		private void LoadExternalIcon()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "kineticdive.png");
			if (!File.Exists(path))
			{
				return;
			}
			try
			{
				byte[] array = File.ReadAllBytes(path);
				Texture2D val = new Texture2D(2, 2);
				MethodInfo methodInfo = typeof(Texture2D).GetMethod("LoadImage", new Type[1] { typeof(byte[]) });
				if (methodInfo == null)
				{
					methodInfo = Assembly.Load("UnityEngine.ImageConversionModule")?.GetType("UnityEngine.ImageConversion")?.GetMethod("LoadImage", new Type[2]
					{
						typeof(Texture2D),
						typeof(byte[])
					});
				}
				methodInfo?.Invoke(val, new object[2] { val, array });
				AbilityIcon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Icon Load Failed: " + ex.Message));
			}
		}

		private static void InitializeUpgrades()
		{
			//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_005e: Unknown result type (might be due to invalid IL or missing references)
			IUpgradable val = PlayerData.FindGear("Bruiser");
			if (val != null)
			{
				CustomUpgradeParams val2 = CustomUpgradeParams.Create(val, 88889, "Kinetic Converter", "Converts kinetic energy into dive power. Damage increases the further you dive.", (Rarity)3, (Sprite)null);
				if ((Object)(object)AbilityIcon != (Object)null)
				{
					val2.icon = AbilityIcon;
				}
				ref UpgradeFlags flags = ref val2.flags;
				flags = (UpgradeFlags)((uint)flags | 0x2000u);
				CustomUpgradeInstance = PlayerData.CreateUpgrade("com.coloron.kineticdive", val2, (UpgradeProperty[])(object)new UpgradeProperty[1]
				{
					new UpgradeProperty_KineticUI()
				});
				ApplyCustomPattern(CustomUpgradeInstance);
			}
		}

		private static void ApplyCustomPattern(Upgrade upgrade)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)upgrade == (Object)null))
			{
				HexMap val = new HexMap(3, 3);
				val[0, 0].enabled = true;
				val[1, 0].enabled = true;
				val[1, 0].connections = (Direction)34;
				val[2, 0].enabled = true;
				SetPrivateField(upgrade, "pattern", val);
			}
		}

		public void TriggerSpeedBuff(Player p, float distMeters)
		{
			if (_speedCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(_speedCoroutine);
			}
			_speedCoroutine = ((MonoBehaviour)this).StartCoroutine(SpeedBurstRoutine(p, distMeters * 1f, 3f));
		}

		[IteratorStateMachine(typeof(<SpeedBurstRoutine>d__13))]
		private IEnumerator SpeedBurstRoutine(Player player, float targetSpeed, float duration)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <SpeedBurstRoutine>d__13(0)
			{
				<>4__this = this,
				player = player,
				targetSpeed = targetSpeed,
				duration = duration
			};
		}

		private void ApplyTempMoveSpeed(Player p, float amount)
		{
			try
			{
				FieldInfo field = typeof(Player).GetField("TempAddMoveSpeed", BindingFlags.Instance | BindingFlags.Public);
				field?.SetValue(p, (float)field.GetValue(p) + amount);
			}
			catch
			{
			}
		}

		public static bool SetPrivateField(object target, string name, object value)
		{
			Type type = target.GetType();
			FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			while (field == null && type.BaseType != null)
			{
				type = type.BaseType;
				field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (field != null)
			{
				field.SetValue(target, value);
				return true;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(NoseDiveUpgrade))]
	public static class KineticDivePatch
	{
		private static Vector3 _startPos;

		[HarmonyPatch("StartSlam")]
		[HarmonyPrefix]
		private static void StartSlam_Prefix()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.LocalPlayer != (Object)null)
			{
				_startPos = Player.LocalPlayer.PhysicsPosition;
			}
		}

		[HarmonyPatch("TriggerNoseDive")]
		[HarmonyPrefix]
		private static void TriggerNoseDive_Prefix(NoseDiveUpgrade __instance, Vector3 position, bool isTrueDive, ref float damageMultiplier)
		{
			//IL_006d: 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)
			if ((Object)(object)Player.LocalPlayer == (Object)null || (Object)(object)KineticDivePlugin.CustomUpgradeInstance == (Object)null || !isTrueDive)
			{
				return;
			}
			UpgradeInstance val = Player.LocalPlayer.ActiveUpgrades?.Find((UpgradeInstance u) => u.Upgrade.ID == KineticDivePlugin.CustomUpgradeInstance.ID);
			if (val != null)
			{
				float num = Vector3.Distance(_startPos, position);
				float damage = __instance.NoseDiveData.landDamage.damage;
				if (damage > 0f && num > 0.1f)
				{
					damageMultiplier *= (damage + num * 10f) / damage;
				}
				if (val.IsTurbocharged)
				{
					KineticDivePlugin.Instance.TriggerSpeedBuff(Player.LocalPlayer, num);
				}
			}
		}
	}
	[Serializable]
	public class UpgradeProperty_KineticUI : UpgradeProperty
	{
		[CompilerGenerated]
		private sealed class <GetStatData>d__0 : IEnumerator<StatData>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private StatData <>2__current;

			public Random rand;

			public IUpgradable gear;

			public UpgradeInstance upgrade;

			public UpgradeProperty_KineticUI <>4__this;

			StatData IEnumerator<StatData>.Current
			{
				[DebuggerHidden]
				get
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <GetStatData>d__0(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: 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)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = new StatData("<b>+10</b> damage per meter");
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if (upgrade != null && upgrade.IsTurbocharged)
					{
						<>2__current = new StatData("\n<color=red>Turbocharged</color>\nSpeed Boost: <b>+10%</b> per meter\nDuration: <b>3s</b>\n");
						<>1__state = 2;
						return true;
					}
					break;
				case 2:
					<>1__state = -1;
					break;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[IteratorStateMachine(typeof(<GetStatData>d__0))]
		public override IEnumerator<StatData> GetStatData(Random rand, IUpgradable gear, UpgradeInstance upgrade)
		{
			//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)
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <GetStatData>d__0(0)
			{
				<>4__this = this,
				rand = rand,
				gear = gear,
				upgrade = upgrade
			};
		}

		public override string GetTurbochargedInfo(Random rand, IUpgradable gear, UpgradeInstance upgrade)
		{
			return "<color=red><b>Turbocharged</b></color>\nSpeed Boost: <b>+10%</b> per meter\nDuration: <b>3s</b>";
		}

		public override void Apply(Player p, UpgradeInstance u, ref Random r)
		{
		}

		public override void Remove(Player p, Player pf, UpgradeInstance i, ref Random r)
		{
		}
	}
}