Decompiled source of ScrollOfSuperiorSelfImmolation v1.0.5

SelfImmolation.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BlackMagicAPI.Enums;
using BlackMagicAPI.Helpers;
using BlackMagicAPI.Managers;
using BlackMagicAPI.Modules.Spells;
using Steamworks;
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("SelfImmolation")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SelfImmolation")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f7fa047c-7063-40e7-a39f-d85bfa69d3fc")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SelfImmolation;

[BepInPlugin("com.owls8.selfimmolation", "selfimmolation", "1.0.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class SelfImmolation : BaseUnityPlugin
{
	private static AssetBundle selfImmolationBundle;

	public static AudioClip explosionSound;

	public static GameObject explosionVFX;

	private void Awake()
	{
		LoadSelfImmolationAssets();
		BlackMagicManager.RegisterSpell((BaseUnityPlugin)(object)this, typeof(SelfImmolationData), typeof(SelfImmolationLogic));
	}

	private void LoadSelfImmolationAssets()
	{
		try
		{
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			string text = Path.Combine(directoryName, "explosion");
			if (File.Exists(text))
			{
				selfImmolationBundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)selfImmolationBundle != (Object)null)
				{
					explosionSound = selfImmolationBundle.LoadAsset<AudioClip>("explosionSFX");
					if ((Object)(object)explosionSound == (Object)null)
					{
						Debug.LogWarning((object)"[SelfImmolation] Could not find 'dong' audio clip in AssetBundle");
					}
					explosionVFX = selfImmolationBundle.LoadAsset<GameObject>("Explosion");
					if ((Object)(object)explosionVFX == (Object)null)
					{
						Debug.LogWarning((object)"[SelfImmolation] Could not find 'Explosion' prefab in AssetBundle");
					}
				}
				else
				{
					Debug.LogError((object)"[SelfImmolation] Failed to load AssetBundle");
				}
			}
			else
			{
				Debug.LogError((object)("[SelfImmolation] AssetBundle file does not exist at path: " + text));
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[SelfImmolation] Error loading AssetBundle: " + ex.Message));
		}
	}
}
internal class SelfImmolationData : SpellData
{
	public override SpellType SpellType => (SpellType)0;

	public override string Name => "Scroll of Superior Self Immolation";

	public override float Cooldown => 3f;

	public override Color GlowColor => Color.red;

	public override Texture2D GetMainTexture()
	{
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		string text = Path.Combine(directoryName, "SelfImmolation_Main.png");
		if (File.Exists(text))
		{
			return Utils.LoadTextureFromDisk(text);
		}
		return Utils.LoadTextureFromResources(Assembly.GetExecutingAssembly(), "BlackMagicAPI.Resources.Items.Item_Main.png");
	}

	public override Texture2D GetEmissionTexture()
	{
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		string text = Path.Combine(directoryName, "SelfImmolation_Emission.png");
		if (File.Exists(text))
		{
			return Utils.LoadTextureFromDisk(text);
		}
		return Utils.LoadTextureFromResources(Assembly.GetExecutingAssembly(), "BlackMagicAPI.Resources.Items.Item_Emission.png");
	}
}
internal class SelfImmolationLogic : SpellLogic
{
	public override void CastSpell(GameObject playerObj, PageController page, Vector3 spawnPos, Vector3 viewDirectionVector, int castingLevel)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: 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_003d: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		PlayerMovement component = playerObj.GetComponent<PlayerMovement>();
		if ((Object)(object)component == (Object)null)
		{
			return;
		}
		GameObject[] array = GameObject.FindGameObjectsWithTag("Player");
		Vector3 position = playerObj.transform.position;
		Vector3 forward = playerObj.transform.forward;
		string personaName = SteamFriends.GetPersonaName();
		PlayerMovement val = null;
		PlayerMovement[] array2 = Object.FindObjectsByType<PlayerMovement>((FindObjectsSortMode)0);
		PlayerMovement[] array3 = array2;
		foreach (PlayerMovement val2 in array3)
		{
			if (val2.playername == personaName)
			{
				val = val2;
				break;
			}
		}
		PlaySelfImmolationVFX(playerObj.GetComponent<PlayerMovement>());
		PlaySelfImmolationSound(playerObj.transform.position);
		float num = 45f;
		float num2 = 40f;
		float num3 = 100f;
		GameObject[] array4 = array;
		foreach (GameObject val3 in array4)
		{
			if ((Object)(object)val3 == (Object)(object)playerObj)
			{
				continue;
			}
			float num4 = Vector3.Distance(position, val3.transform.position);
			if (!(num4 <= num))
			{
				continue;
			}
			PlayerMovement component2 = val3.GetComponent<PlayerMovement>();
			if ((Object)(object)component2 != (Object)null)
			{
				if (num4 <= 15f)
				{
					component2.NonRpcDamagePlayer(999f, (GameObject)null, "selfimmolate");
					continue;
				}
				float num5 = (num4 - 15f) / num;
				float num6 = Mathf.Lerp(num3, num2, num5);
				component2.NonRpcDamagePlayer(num6, (GameObject)null, "selfimmolate");
			}
		}
		playerObj.GetComponent<PlayerInventory>().destroyHandItem();
		playerObj.GetComponent<PlayerMovement>().NonRpcDamagePlayer(999f, (GameObject)null, "selfimmolate");
	}

	private static void PlaySelfImmolationVFX(PlayerMovement caster)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)SelfImmolation.explosionVFX == (Object)null)
		{
			Debug.LogWarning((object)"Explosion VFX prefab is null.");
			return;
		}
		GameObject val = Object.Instantiate<GameObject>(SelfImmolation.explosionVFX, ((Component)caster).transform.position, Quaternion.identity);
		val.SetActive(true);
		Object.Destroy((Object)(object)val, 5f);
	}

	private static void PlaySelfImmolationSound(Vector3 position)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if ((Object)(object)SelfImmolation.explosionSound != (Object)null)
			{
				GameObject val = new GameObject("SelfImmolationAudio");
				val.transform.position = position;
				AudioSource val2 = val.AddComponent<AudioSource>();
				val2.clip = SelfImmolation.explosionSound;
				val2.volume = 0.8f;
				val2.spatialBlend = 1f;
				val2.rolloffMode = (AudioRolloffMode)1;
				val2.minDistance = 5f;
				val2.maxDistance = 50f;
				val2.Play();
				float num = SelfImmolation.explosionSound.length + 0.1f;
				Object.Destroy((Object)(object)val, num);
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[SelfImmolation] Error playing sound: " + ex.Message));
		}
	}
}