Decompiled source of MayoSpells v1.0.99

MayoSpells.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using BlackMagicAPI.Enums;
using BlackMagicAPI.Helpers;
using BlackMagicAPI.Managers;
using BlackMagicAPI.Modules.Spells;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MayoSpells")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MayoSpells")]
[assembly: AssemblyTitle("MayoSpells")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 MayoSpells
{
	[BepInPlugin("MayoSpells", "MayoSpells", "0.0.2")]
	[BepInProcess("MageArena.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class MySpellMod : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static MySpellMod Instance;

		public static string modsync = "all";

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"ModSync found! Initializing mod...");
			Instance = this;
			BlackMagicManager.RegisterSpell((BaseUnityPlugin)(object)this, typeof(DeathSpellData), typeof(DeathSpellLogic));
			BlackMagicManager.RegisterSpell((BaseUnityPlugin)(object)this, typeof(GrowSpellData), typeof(GrowthSpellLogic));
			BlackMagicManager.RegisterSpell((BaseUnityPlugin)(object)this, typeof(WindstrideSpellData), typeof(WindstrideSpellLogic));
			Logger.LogInfo((object)"Plugin MayoSpells is loaded!");
		}
	}
	internal class DeathSpellData : SpellData
	{
		public override SpellType SpellType => (SpellType)0;

		public override string Name => "Die";

		public override float Cooldown => 120f;

		public override Color GlowColor => Color.red;

		public override Texture2D? GetMainTexture()
		{
			return Utils.LoadTextureFromResources(Assembly.GetExecutingAssembly(), "MayoSpells.Resources.DeathspellMain.png");
		}

		public override Texture2D? GetEmissionTexture()
		{
			return Utils.LoadTextureFromResources(Assembly.GetExecutingAssembly(), "MayoSpells.Resources.DeathspellEmission.png");
		}
	}
	internal class DeathSpellLogic : SpellLogic
	{
		private static AudioClip spellSound;

		private static bool isLoading;

		public override void CastSpell(GameObject casterObj, PageController page, Vector3 spawnPos, Vector3 direction, int level)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0026: 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_002a: 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)
			float num = 100f;
			Vector3 val = casterObj.transform.position + Vector3.up * 1.5f;
			GameObject val2 = null;
			RaycastHit val3 = default(RaycastHit);
			if (Physics.Raycast(val, direction, ref val3, num))
			{
				PlayerMovement componentInParent = ((Component)((RaycastHit)(ref val3)).collider).GetComponentInParent<PlayerMovement>();
				if ((Object)(object)componentInParent != (Object)null && (Object)(object)((Component)componentInParent).gameObject != (Object)(object)casterObj)
				{
					val2 = ((Component)componentInParent).gameObject;
				}
			}
			GameObject val4 = (((Object)(object)val2 != (Object)null) ? val2 : casterObj);
			val4.GetComponent<PlayerMovement>().DamagePlayer(4000f, casterObj, "Deathspell");
			if ((Object)(object)spellSound != (Object)null)
			{
				PlaySpatialSoundAtPosition(val4.transform.position, spellSound);
			}
			else if (!isLoading)
			{
				isLoading = true;
				((MonoBehaviour)MySpellMod.Instance).StartCoroutine(LoadAndPlaySound(val4));
			}
		}

		private static void PlaySpatialSoundAtPosition(Vector3 position, AudioClip clip)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)clip == (Object)null))
			{
				GameObject val = new GameObject("DeathSpellAudio");
				val.transform.position = position;
				AudioSource val2 = val.AddComponent<AudioSource>();
				val2.clip = clip;
				val2.volume = 1.5f;
				val2.spatialBlend = 1f;
				val2.rolloffMode = (AudioRolloffMode)1;
				val2.minDistance = 5f;
				val2.maxDistance = 50f;
				val2.Play();
				Object.Destroy((Object)(object)val, clip.length + 0.1f);
			}
		}

		private static IEnumerator LoadAndPlaySound(GameObject soundTarget)
		{
			string pluginDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string path = Path.Combine(pluginDir, "Deathcast.wav");
			string uri = "file://" + path;
			UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(uri, (AudioType)20);
			try
			{
				yield return www.SendWebRequest();
				if ((int)www.result != 1)
				{
					MySpellMod.Logger.LogError((object)("Failed to load Deathcast.wav: " + www.error));
					yield break;
				}
				spellSound = DownloadHandlerAudioClip.GetContent(www);
				isLoading = false;
				PlaySpatialSoundAtPosition(soundTarget.transform.position, spellSound);
			}
			finally
			{
				((IDisposable)www)?.Dispose();
			}
		}
	}
	internal class GrowSpellData : SpellData
	{
		public override SpellType SpellType => (SpellType)0;

		public override string Name => "Erection";

		public override float Cooldown => 60f;

		public override Color GlowColor => Color.green;

		public override Texture2D? GetMainTexture()
		{
			return Utils.LoadTextureFromResources(Assembly.GetExecutingAssembly(), "MayoSpells.Resources.GrowMain.png");
		}

		public override Texture2D? GetEmissionTexture()
		{
			return Utils.LoadTextureFromResources(Assembly.GetExecutingAssembly(), "MayoSpells.Resources.GrowEmission.png");
		}
	}
	internal class GrowthSpellLogic : SpellLogic
	{
		private const float growScale = 2f;

		private const float growTime = 0.5f;

		private const float duration = 20f;

		private const float pitchLowered = 0.5f;

		private const float pitchNormal = 1f;

		private const float healthBoost = 100f;

		public override void CastSpell(GameObject casterObj, PageController page, Vector3 spawnPos, Vector3 direction, int level)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0020: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = casterObj.transform.position + Vector3.up * 1.5f;
			GameObject val2 = null;
			RaycastHit val3 = default(RaycastHit);
			if (Physics.Raycast(val, direction, ref val3, 100f))
			{
				PlayerMovement componentInParent = ((Component)((RaycastHit)(ref val3)).collider).GetComponentInParent<PlayerMovement>();
				if ((Object)(object)componentInParent != (Object)null && (Object)(object)((Component)componentInParent).gameObject != (Object)(object)casterObj)
				{
					val2 = ((Component)componentInParent).gameObject;
				}
			}
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = casterObj;
			}
			PlayerMovement component = val2.GetComponent<PlayerMovement>();
			if ((Object)(object)component == (Object)null)
			{
				MySpellMod.Logger.LogWarning((object)"[GrowthSpell] Target has no PlayerMovement.");
			}
			else
			{
				((MonoBehaviour)MySpellMod.Instance).StartCoroutine(GrowRoutine(component));
			}
		}

		private IEnumerator GrowRoutine(PlayerMovement player)
		{
			Transform target = ((Component)player).transform;
			Vector3 originalScale = target.localScale;
			Vector3 bigScale = originalScale * 2f;
			FieldInfo fi_playerHealth = typeof(PlayerMovement).GetField("playerHealth", BindingFlags.Instance | BindingFlags.NonPublic);
			if (fi_playerHealth == null)
			{
				MySpellMod.Logger.LogError((object)"[GrowthSpell] Failed to find 'playerHealth' field.");
				yield break;
			}
			float originalHealth = (float)fi_playerHealth.GetValue(player);
			fi_playerHealth.SetValue(player, originalHealth + 100f);
			MySpellMod.Logger.LogInfo((object)$"[GrowthSpell] Increased playerHealth from {originalHealth} to {originalHealth + 100f}");
			float t2 = 0f;
			while (t2 < 0.5f)
			{
				t2 += Time.deltaTime;
				target.localScale = Vector3.Lerp(originalScale, bigScale, t2 / 0.5f);
				yield return null;
			}
			target.localScale = bigScale;
			SetVoicePitch(((Component)player).gameObject, 0.5f);
			yield return (object)new WaitForSeconds(20f);
			t2 = 0f;
			while (t2 < 0.5f)
			{
				t2 += Time.deltaTime;
				target.localScale = Vector3.Lerp(bigScale, originalScale, t2 / 0.5f);
				yield return null;
			}
			target.localScale = originalScale;
			SetVoicePitch(((Component)player).gameObject, 1f);
			float currentHealth = (float)fi_playerHealth.GetValue(player);
			float restoredHealth = Mathf.Max(currentHealth - 100f, 1f);
			fi_playerHealth.SetValue(player, restoredHealth);
			MySpellMod.Logger.LogInfo((object)$"[GrowthSpell] Restored playerHealth to {restoredHealth}");
		}

		private void SetVoicePitch(GameObject player, float pitch)
		{
			AudioSource componentInChildren = player.GetComponentInChildren<AudioSource>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.pitch = pitch;
				MySpellMod.Logger.LogInfo((object)$"[GrowthSpell] Set voice pitch to {pitch}");
			}
			else
			{
				MySpellMod.Logger.LogWarning((object)"[GrowthSpell] No AudioSource found to set pitch.");
			}
		}
	}
	internal class WindstrideSpellData : SpellData
	{
		public override SpellType SpellType => (SpellType)0;

		public override string Name => "Wind Stride";

		public override float Cooldown => 45f;

		public override Color GlowColor => Color.cyan;

		public override Texture2D? GetMainTexture()
		{
			return Utils.LoadTextureFromResources(Assembly.GetExecutingAssembly(), "MayoSpells.Resources.Windstride_Main.png");
		}

		public override Texture2D? GetEmissionTexture()
		{
			return Utils.LoadTextureFromResources(Assembly.GetExecutingAssembly(), "MayoSpells.Resources.Windstride_Emission.png");
		}
	}
	internal class WindstrideSpellLogic : SpellLogic
	{
		private static AudioClip spellSound;

		private static bool isLoading;

		private const float speedBonus = 7f;

		private const float jumpBonus = 5f;

		private const float duration = 10f;

		public override void CastSpell(GameObject casterObj, PageController page, Vector3 spawnPos, Vector3 direction, int level)
		{
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			MySpellMod.Logger.LogInfo((object)"[Windstride] CastSpell triggered!");
			Component component = casterObj.GetComponent("PlayerMovement");
			if ((Object)(object)component == (Object)null)
			{
				MySpellMod.Logger.LogWarning((object)"[Windstride] Caster has no PlayerMovement component.");
				return;
			}
			Type type = ((object)component).GetType();
			FieldInfo field = type.GetField("stewspeedboost", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			FieldInfo field2 = type.GetField("stewjumpbonus", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null && field2 != null)
			{
				float num = (float)field.GetValue(component);
				float num2 = (float)field2.GetValue(component);
				field.SetValue(component, num + 7f);
				field2.SetValue(component, num2 + 5f);
				((MonoBehaviour)MySpellMod.Instance).StartCoroutine(RemoveBuffAfterDelay(component, field, field2));
			}
			else
			{
				MySpellMod.Logger.LogWarning((object)"[Windstride] Could not find runningSpeed, walkingSpeed or jumpSpeed fields.");
			}
			if ((Object)(object)spellSound != (Object)null)
			{
				PlaySpatialSoundAtPosition(casterObj.transform.position, spellSound);
			}
			else if (!isLoading)
			{
				isLoading = true;
				((MonoBehaviour)MySpellMod.Instance).StartCoroutine(LoadAndPlaySound(casterObj));
			}
		}

		private static IEnumerator RemoveBuffAfterDelay(object movement, FieldInfo runningSpeedField, FieldInfo jumpSpeedField)
		{
			yield return (object)new WaitForSeconds(10f);
			if (movement != null)
			{
				float currentRunningSpeed = (float)runningSpeedField.GetValue(movement);
				float currentJumpSpeed = (float)jumpSpeedField.GetValue(movement);
				runningSpeedField.SetValue(movement, currentRunningSpeed - 7f);
				jumpSpeedField.SetValue(movement, currentJumpSpeed - 5f);
				MySpellMod.Logger.LogInfo((object)"[Windstride] Buff expired.");
			}
		}

		private static void PlaySpatialSoundAtPosition(Vector3 position, AudioClip clip)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)clip == (Object)null))
			{
				GameObject val = new GameObject("WindstrideAudio");
				val.transform.position = position;
				AudioSource val2 = val.AddComponent<AudioSource>();
				val2.clip = clip;
				val2.volume = 1f;
				val2.spatialBlend = 1f;
				val2.rolloffMode = (AudioRolloffMode)1;
				val2.minDistance = 5f;
				val2.maxDistance = 50f;
				val2.Play();
				Object.Destroy((Object)(object)val, clip.length + 0.1f);
			}
		}

		private static IEnumerator LoadAndPlaySound(GameObject soundTarget)
		{
			string pluginDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string path = Path.Combine(pluginDir, "Windstride.wav");
			string uri = "file://" + path;
			UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(uri, (AudioType)20);
			try
			{
				yield return www.SendWebRequest();
				if ((int)www.result != 1)
				{
					MySpellMod.Logger.LogError((object)("[Windstride] Failed to load Windstride.wav: " + www.error));
					yield break;
				}
				spellSound = DownloadHandlerAudioClip.GetContent(www);
				isLoading = false;
				PlaySpatialSoundAtPosition(soundTarget.transform.position, spellSound);
			}
			finally
			{
				((IDisposable)www)?.Dispose();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MayoSpells";

		public const string PLUGIN_NAME = "MayoSpells";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}