Decompiled source of Sandevistan v1.0.0

sandevistan.dll

Decompiled 4 hours ago
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using On.RoR2;
using R2API;
using RiskOfOptions;
using RiskOfOptions.Options;
using RoR2;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("sandevistan")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("sandevistan")]
[assembly: AssemblyTitle("sandevistan")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace sandevistan;

public enum SandyColor
{
	Green,
	Purple,
	Orange,
	Red,
	Blue,
	Pink,
	Yellow,
	Rainbow
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.mason.sandevistan", "Sandevistan", "0.9.1")]
public class SandevistanPlugin : BaseUnityPlugin
{
	private float activeUntil;

	private ConfigEntry<SandyColor> colorChoice;

	private void Awake()
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Expected O, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Expected O, but got Unknown
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Expected O, but got Unknown
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Expected O, but got Unknown
		colorChoice = ((BaseUnityPlugin)this).Config.Bind<SandyColor>("Visuals", "Color", SandyColor.Green, "Color of the tint and afterimages");
		ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)colorChoice));
		Texture2D val = new Texture2D(2, 2);
		string[] files = Directory.GetFiles(Paths.PluginPath, "sandy*.png*", SearchOption.AllDirectories);
		string[] array = files;
		foreach (string text in array)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Sandevistan picture found: [" + text + "]"));
		}
		if (files.Length != 0)
		{
			ImageConversion.LoadImage(val, File.ReadAllBytes(files[0]));
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"Sandevistan picture not found");
		}
		EquipmentDef equip = ScriptableObject.CreateInstance<EquipmentDef>();
		((Object)equip).name = "SANDEVISTAN";
		equip.nameToken = "SANDEVISTAN_NAME";
		equip.pickupToken = "SANDEVISTAN_PICKUP";
		equip.descriptionToken = "SANDEVISTAN_DESC";
		equip.loreToken = "SANDEVISTAN_LORE";
		equip.pickupIconSprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		equip.cooldown = 45f;
		equip.canDrop = true;
		equip.appearsInSinglePlayer = true;
		equip.appearsInMultiPlayer = false;
		LanguageAPI.Add("SANDEVISTAN_NAME", "Sandevistan");
		LanguageAPI.Add("SANDEVISTAN_PICKUP", "Stop enemies in their tracks.");
		LanguageAPI.Add("SANDEVISTAN_DESC", "Move fast while enemies are stopped for 6 seconds.");
		LanguageAPI.Add("SANDEVISTAN_LORE", "Faster than the eye can follow.");
		bool flag = ItemAPI.Add(new CustomEquipment(equip, new ItemDisplayRuleDict((ItemDisplayRule[])null)));
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Sandevistan equipment added: " + flag));
		EquipmentSlot.PerformEquipmentAction += (hook_PerformEquipmentAction)delegate(orig_PerformEquipmentAction orig, EquipmentSlot self, EquipmentDef used)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)used != (Object)(object)equip)
			{
				return orig.Invoke(self, used);
			}
			self.characterBody.AddTimedBuff(Buffs.CloakSpeed, 6f);
			foreach (CharacterBody readOnlyInstances in CharacterBody.readOnlyInstancesList)
			{
				if (readOnlyInstances.teamComponent.teamIndex != self.characterBody.teamComponent.teamIndex)
				{
					readOnlyInstances.AddTimedBuff(Buffs.Slow80, 6f);
					SetStateOnHurt component = ((Component)readOnlyInstances).GetComponent<SetStateOnHurt>();
					if (Object.op_Implicit((Object)(object)component) && component.canBeStunned)
					{
						component.SetStun(6f);
					}
				}
			}
			activeUntil = Time.time + 6f;
			((MonoBehaviour)this).StartCoroutine(Afterimages(self.characterBody));
			return true;
		};
	}

	private Color PickColor()
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		return (Color)(colorChoice.Value switch
		{
			SandyColor.Purple => new Color(0.6f, 0.1f, 1f), 
			SandyColor.Orange => new Color(1f, 0.5f, 0f), 
			SandyColor.Red => Color.red, 
			SandyColor.Blue => new Color(0f, 0.4f, 1f), 
			SandyColor.Pink => new Color(1f, 0.2f, 0.7f), 
			SandyColor.Yellow => Color.yellow, 
			SandyColor.Rainbow => Color.HSVToRGB(Time.time * 0.8f % 1f, 1f, 1f), 
			_ => new Color(0f, 1f, 0.4f), 
		});
	}

	private IEnumerator Afterimages(CharacterBody user)
	{
		while (Time.time < activeUntil && Object.op_Implicit((Object)(object)user) && Object.op_Implicit((Object)(object)user.modelLocator) && Object.op_Implicit((Object)(object)user.modelLocator.modelTransform))
		{
			Color color = PickColor();
			color.a = 0.35f;
			SkinnedMeshRenderer[] componentsInChildren = ((Component)user.modelLocator.modelTransform).GetComponentsInChildren<SkinnedMeshRenderer>();
			foreach (SkinnedMeshRenderer part in componentsInChildren)
			{
				Mesh mesh = new Mesh();
				part.BakeMesh(mesh);
				GameObject ghost = new GameObject("SandevistanGhost");
				ghost.transform.SetPositionAndRotation(((Component)part).transform.position, ((Component)part).transform.rotation);
				ghost.AddComponent<MeshFilter>().mesh = mesh;
				Material material = new Material(Shader.Find("Sprites/Default"));
				material.color = color;
				Material[] materials = (Material[])(object)new Material[mesh.subMeshCount];
				for (int j = 0; j < materials.Length; j++)
				{
					materials[j] = material;
				}
				((Renderer)ghost.AddComponent<MeshRenderer>()).materials = materials;
				Object.Destroy((Object)(object)ghost, 0.5f);
				Object.Destroy((Object)(object)mesh, 0.5f);
				Object.Destroy((Object)(object)material, 0.5f);
			}
			yield return (object)new WaitForSeconds(0.08f);
		}
	}

	private void OnGUI()
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: 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)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		if (Time.time >= activeUntil || !Object.op_Implicit((Object)(object)Run.instance))
		{
			return;
		}
		Color color = GUI.color;
		Color color2 = PickColor();
		float num = Time.time - (activeUntil - 6f);
		color2.a = 0.15f;
		if (num < 0.4f)
		{
			color2.a = Mathf.Lerp(0.5f, 0.15f, num / 0.4f);
		}
		GUI.color = color2;
		GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)Texture2D.whiteTexture);
		if (num < 0.6f)
		{
			color2.a = 0.8f * (1f - num / 0.6f);
			GUI.color = color2;
			for (int i = 0; i < 14; i++)
			{
				float num2 = (float)Screen.height * ((float)i + 0.5f) / 14f;
				float num3 = (float)Screen.width * (0.1f + (float)(i * 5 % 7) * 0.03f) * (num / 0.6f + 0.3f);
				float num4 = ((i % 2 == 0) ? 0f : ((float)Screen.width - num3));
				GUI.DrawTexture(new Rect(num4, num2, num3, 4f), (Texture)(object)Texture2D.whiteTexture);
			}
		}
		GUI.color = color;
	}
}