Decompiled source of TesticularTorsion v1.0.4

BepInEx/plugins/TesticularTorsion.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BlackMagicAPI.Enums;
using BlackMagicAPI.Managers;
using BlackMagicAPI.Modules.Spells;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("TesticularTorsion")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TesticularTorsion")]
[assembly: AssemblyTitle("TesticularTorsion")]
[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 TesticularTorsion
{
	[BepInPlugin("com.magearena.testiculartorsion", "Testicular Torsion", "1.0.0")]
	[BepInProcess("MageArena.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class TesticularTorsion : BaseUnityPlugin
	{
		internal class TesticularTorsionData : SpellData
		{
			public override SpellType SpellType => (SpellType)0;

			public override string Name => "Testicular Torsion";

			public override float Cooldown => 40f;

			public override Color GlowColor => Color.red;
		}

		internal class TesticularTorsionLogic : SpellLogic
		{
			public static class SpellVisualHelper
			{
				public class SpinningGlowingPentagram : MonoBehaviour
				{
					public Transform player;

					public float offsetDistance;

					public Vector3 yOffset;

					public float spinSpeed;

					public float glowSpeed = 3f;

					public Color baseColor = Color.red;

					public float level = 1f;

					public float size = 0.01f;

					private float time;

					private Material instanceMaterial;

					private float spinAngle;

					private float glowIntensity = 4f;

					private void Awake()
					{
						MeshRenderer componentInChildren = ((Component)this).GetComponentInChildren<MeshRenderer>();
						if ((Object)(object)componentInChildren != (Object)null)
						{
							instanceMaterial = ((Renderer)componentInChildren).material;
						}
					}

					private void Update()
					{
						//IL_0007: 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)
						//IL_0030: 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_004b: Unknown result type (might be due to invalid IL or missing references)
						//IL_005b: Unknown result type (might be due to invalid IL or missing references)
						//IL_0060: 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_0076: 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)
						//IL_0080: Unknown result type (might be due to invalid IL or missing references)
						//IL_008d: Unknown result type (might be due to invalid IL or missing references)
						//IL_0092: 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_00a4: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
						//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
						//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
						//IL_00d8: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
						//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
						//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
						//IL_0147: Unknown result type (might be due to invalid IL or missing references)
						//IL_014e: Unknown result type (might be due to invalid IL or missing references)
						((Component)this).transform.localScale = Vector3.one * (size + level / 100f);
						Vector3 val = player.right * yOffset.x + player.up * yOffset.y + player.forward * offsetDistance;
						((Component)this).transform.position = player.position + val;
						Quaternion val2 = Quaternion.LookRotation(player.forward, Vector3.up);
						spinAngle += spinSpeed * Time.deltaTime;
						Quaternion val3 = Quaternion.AngleAxis(spinAngle, Vector3.forward);
						((Component)this).transform.rotation = val2 * val3;
						if ((Object)(object)instanceMaterial != (Object)null)
						{
							time += Time.deltaTime * glowSpeed;
							float num = Mathf.PingPong(time, 1f) * (glowIntensity + level);
							instanceMaterial.SetColor("_UnlitColor", baseColor * num);
						}
					}
				}

				public static GameObject DrawPentagram(float level, float duration = 4f)
				{
					//IL_003c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0043: Expected O, but got Unknown
					//IL_005e: Unknown result type (might be due to invalid IL or missing references)
					GameObject val = Object.Instantiate<GameObject>(pentagramPrefab);
					MeshRenderer componentInChildren = val.GetComponentInChildren<MeshRenderer>();
					if ((Object)(object)componentInChildren != (Object)null)
					{
						Shader val2 = Shader.Find("HDRP/Unlit");
						if ((Object)(object)val2 != (Object)null)
						{
							Material val3 = new Material(val2);
							val3.SetColor("_UnlitColor", new Color(1f, 0f, 0f, 0.77f));
							val3.SetFloat("_SurfaceType", 0.3f);
							((Renderer)componentInChildren).material = val3;
							Debug.Log((object)"Applied a new, forced material to the spellobject.");
						}
						else
						{
							Debug.LogError((object)"Could not find HDRP/Unlit shader to create a working material!");
						}
					}
					else
					{
						Debug.LogError((object)"Instantiated spellobject does not have a MeshRenderer!");
					}
					return val;
				}
			}

			public override void CastSpell(GameObject playerObj, PageController page, Vector3 spawnPos, Vector3 direction, int level)
			{
				page.CoolDown = 40f - (float)level * 2f;
				List<PlayerMovement> hitplayers = new List<PlayerMovement>();
				List<float> playerspeeds = new List<float>();
				((MonoBehaviour)this).StartCoroutine(TesticularTorsionEffect(playerObj, hitplayers, playerspeeds, level));
			}

			private IEnumerator TesticularTorsionEffect(GameObject playerObj, List<PlayerMovement> hitplayers, List<float> playerspeeds, float level)
			{
				if ((Object)(object)playerObj == (Object)null)
				{
					yield break;
				}
				float offsetDistance = 2f;
				Vector3 yOffset = new Vector3(0f, 2f, 3f);
				float laserLength = 30f + level * 3f;
				float elapsedTime = 0f;
				float timer = 5f + level / 4f;
				GameObject pentagramObj = SpellVisualHelper.DrawPentagram(level);
				pentagramObj.transform.SetParent(playerObj.transform, false);
				Vector3 val = pentagramObj.transform.position + yOffset;
				Vector3 forward = pentagramObj.transform.forward;
				Vector3 pentagramPos = val + ((Vector3)(ref forward)).normalized * offsetDistance;
				pentagramObj.transform.position = pentagramPos;
				SpellVisualHelper.SpinningGlowingPentagram controller = pentagramObj.AddComponent<SpellVisualHelper.SpinningGlowingPentagram>();
				controller.baseColor = Color.red;
				controller.offsetDistance = offsetDistance;
				controller.yOffset = yOffset;
				controller.spinSpeed = 360f + level * 10f;
				controller.level = level;
				controller.player = playerObj.transform;
				float raycastOffsetDistance = 2.5f;
				float checkInterval = 0.1f;
				if ((Object)(object)magicalSpin != (Object)null)
				{
					Debug.Log((object)"About to play magcial sound");
					GameObject audioObject = new GameObject("MagicalSpinAudio");
					audioObject.transform.position = playerObj.transform.position;
					AudioSource audioSource = audioObject.AddComponent<AudioSource>();
					audioSource.clip = magicalSpin;
					audioSource.volume = 0.8f;
					audioSource.spatialBlend = 1f;
					audioSource.Play();
					Debug.Log((object)"Magical sound should be playing");
					Object.Destroy((Object)(object)audioObject, magicalSpin.length - (magicalSpin.length - timer) + 0.01f);
				}
				while (elapsedTime < timer)
				{
					Vector3 position = pentagramObj.transform.position;
					forward = pentagramObj.transform.forward;
					Vector3 raycastOrigin = position + ((Vector3)(ref forward)).normalized * raycastOffsetDistance;
					int hitCount = Physics.SphereCastNonAlloc(raycastOrigin, 2.33f, pentagramObj.transform.forward, sphereHits, laserLength);
					for (int i = 0; i < hitCount; i++)
					{
						RaycastHit hit = sphereHits[i];
						PlayerMovement hitPlayer = ((Component)((RaycastHit)(ref hit)).collider).gameObject.GetComponent<PlayerMovement>();
						if ((Object)(object)hitPlayer != (Object)null)
						{
							if (!hitplayers.Contains(hitPlayer))
							{
								hitplayers.Add(hitPlayer);
								PlayTesticularTorsionAudio(((Component)hitPlayer).transform.position);
								hitPlayer.NauseatedTimer = 5f + level / 2f;
								hitPlayer.ShakeCam(15f + level * 5f, 10f + level * 2f);
								((MonoBehaviour)this).StartCoroutine(Slow(hitPlayer, 7f + level / 2f, level));
								((MonoBehaviour)this).StartCoroutine(DisableJumping(hitPlayer, 7f + level / 2f, level));
							}
							hitPlayer.ShakeCam(3f, 2f);
							hitPlayer.NonRpcDamagePlayer(2f + level / 4f, playerObj, "Testicular Torsion");
						}
					}
					elapsedTime += checkInterval;
					yield return (object)new WaitForSeconds(checkInterval);
				}
				hitplayers.Clear();
				Object.Destroy((Object)(object)pentagramObj);
			}

			private IEnumerator DisableJumping(PlayerMovement hitPlayer, float timer, float level)
			{
				float checkinterval = 0.1f;
				float elapsedTime = 0f;
				if (!hitPlayer.canJump)
				{
					yield break;
				}
				hitPlayer.canJump = false;
				while (elapsedTime < timer)
				{
					if (hitPlayer.isDead)
					{
						hitPlayer.canJump = true;
						yield break;
					}
					elapsedTime += checkinterval;
					yield return (object)new WaitForSeconds(checkinterval);
				}
				hitPlayer.canJump = true;
			}

			private IEnumerator Slow(PlayerMovement hitPlayer, float timer, float level)
			{
				float checkinterval = 0.001f;
				float elapsedTime = 0f;
				if (!(hitPlayer.currentSpeed > 0f))
				{
					yield break;
				}
				while (elapsedTime < timer)
				{
					hitPlayer.currentSpeed = 4f;
					if (hitPlayer.isDead)
					{
						break;
					}
					elapsedTime += checkinterval;
					yield return (object)new WaitForSeconds(checkinterval);
				}
			}

			private static void PlayTesticularTorsionAudio(Vector3 position)
			{
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					Debug.Log((object)"About to play twist sound");
					if ((Object)(object)twist != (Object)null)
					{
						Debug.Log((object)"Twist sound should be playing");
						GameObject val = new GameObject("TesticularTorsionAudio");
						val.transform.position = position;
						AudioSource val2 = val.AddComponent<AudioSource>();
						val2.clip = tesicularTorsionBundle.LoadAsset<AudioClip>("twist.mp3");
						val2.volume = 0.8f;
						val2.spatialBlend = 1f;
						val2.rolloffMode = (AudioRolloffMode)1;
						val2.minDistance = 5f;
						val2.maxDistance = 50f;
						val2.Play();
						float num = twist.length + 0.1f;
						Object.Destroy((Object)(object)val, num);
					}
				}
				catch (Exception ex)
				{
					Debug.LogError((object)("[TesticularTorsion] Error playing dong sound: " + ex.Message));
				}
			}

			private void DrawInGameRay(Vector3 start, Vector3 direction, float length, Color color, float duration = 0.1f)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Expected O, but got Unknown
				//IL_001d: 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_002f: 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_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: Expected O, but got Unknown
				//IL_006d: 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)
				//IL_0070: 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)
				GameObject val = new GameObject("InGameRay");
				LineRenderer val2 = val.AddComponent<LineRenderer>();
				val2.positionCount = 2;
				val2.SetPosition(0, start);
				val2.SetPosition(1, start + ((Vector3)(ref direction)).normalized * length);
				float startWidth = (val2.endWidth = 0.05f);
				val2.startWidth = startWidth;
				((Renderer)val2).material = new Material(Shader.Find("Sprites/Default"));
				Color startColor = (val2.endColor = color);
				val2.startColor = startColor;
				Object.Destroy((Object)(object)val, duration);
			}
		}

		public static string modsync = "all";

		private static GameObject pentagramPrefab;

		public static AssetBundle tesicularTorsionBundle = null;

		public static AudioClip twist = null;

		public static RaycastHit[] sphereHits = (RaycastHit[])(object)new RaycastHit[16];

		public static AudioClip magicalSpin = null;

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin TesticularTorsion is loaded!");
			LoadTesticularTorsionAssets();
			BlackMagicManager.RegisterSpell((BaseUnityPlugin)(object)this, typeof(TesticularTorsionData), typeof(TesticularTorsionLogic));
			BlackMagicManager.RegisterDeathIcon((BaseUnityPlugin)(object)this, "Testicular Torsion", "Testicular_Torsion_Icon");
		}

		private void LoadTesticularTorsionAssets()
		{
			string text = Paths.PluginPath + "/TesticularTorsion/BepInEx/plugins/assets/testiculartorsion";
			Debug.Log((object)text);
			tesicularTorsionBundle = AssetBundle.LoadFromFile(text);
			twist = tesicularTorsionBundle.LoadAsset<AudioClip>("twist.mp3");
			magicalSpin = tesicularTorsionBundle.LoadAsset<AudioClip>("spin.mp3");
			Debug.Log((object)$"twist loaded: {(Object)(object)twist != (Object)null}");
			Debug.Log((object)$"magicalSpin loaded: {(Object)(object)magicalSpin != (Object)null}");
			pentagramPrefab = tesicularTorsionBundle.LoadAsset<GameObject>("spellobject");
			Object.DontDestroyOnLoad((Object)(object)pentagramPrefab);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "TesticularTorsion";

		public const string PLUGIN_NAME = "TesticularTorsion";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}