Decompiled source of CRUSH v1.0.0

doomahreal.ultrakill.CRUSH/CRUSH.dll

Decompiled 8 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
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 CRUSH;
using Configgy;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("CRUSH")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CRUSH")]
[assembly: AssemblyTitle("CRUSH")]
[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;
		}
	}
}
public static class FontLoader
{
	public static TMP_FontAsset font;

	public static void LoadFont(string filePath)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected O, but got Unknown
		if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
		{
			Debug.LogError((object)("Font file not found: " + filePath));
			return;
		}
		File.ReadAllBytes(filePath);
		font = TMP_FontAsset.CreateFontAsset(new Font(filePath));
	}
}
public class MFDOOM : MonoBehaviour
{
	public float floatSpeed = 1f;

	private MovementType movementMode = ((ConfigValueElement<MovementType>)(object)Plugin.fortnaught).Value;

	private TextMeshPro textMesh;

	private float fadeOutTimer = ((ConfigValueElement<float>)(object)Plugin.imrunningoutofnames).Value;

	private Vector2 sizenerd = ((ConfigValueElement<Vector2>)(object)Plugin.sigmaprime).Value;

	private Vector3 bounceDirection;

	private void Awake()
	{
		//IL_004a: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		textMesh = ((Component)this).GetComponent<TextMeshPro>();
		((Component)this).gameObject.AddComponent<AlwaysLookAtCamera>();
		((Component)this).gameObject.tag = "IgnorePushes";
		((Component)this).transform.localScale = new Vector3(0f - sizenerd.x, sizenerd.y, 1f);
		if (((ConfigValueElement<bool>)(object)Plugin.enableCustomFont).Value && (Object)(object)FontLoader.font != (Object)null)
		{
			((TMP_Text)textMesh).font = FontLoader.font;
		}
		((TMP_Text)textMesh).fontMaterial.SetFloat(ShaderUtilities.ID_OutlineWidth, ((ConfigValueElement<bool>)(object)Plugin.enableOutline).Value ? ((ConfigValueElement<float>)(object)Plugin.outlineThickness).Value : 0f);
		((TMP_Text)textMesh).fontMaterial.SetColor(ShaderUtilities.ID_OutlineColor, ((ConfigValueElement<bool>)(object)Plugin.enableOutline).Value ? ((ConfigValueElement<Color>)(object)Plugin.outlineColor).Value : Color.clear);
		if (movementMode == MovementType.FlyingAway)
		{
			bounceDirection = ((Random.value < 0.5f) ? Vector3.left : Vector3.right) + Vector3.up;
			((Vector3)(ref bounceDirection)).Normalize();
		}
	}

	private void Update()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: 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_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)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: 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_0065: 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_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		if (movementMode == MovementType.Normal)
		{
			Transform transform = ((Component)this).transform;
			transform.position += Vector3.up * floatSpeed * Time.deltaTime;
		}
		else if (movementMode == MovementType.FlyingAway)
		{
			Transform transform2 = ((Component)this).transform;
			transform2.position += (bounceDirection = Vector3.Lerp(bounceDirection, Vector3.zero, Time.deltaTime)) * floatSpeed * Time.deltaTime * 30f;
		}
		fadeOutTimer -= Time.deltaTime;
		if (fadeOutTimer <= 0f)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
		ApplyGradientColor();
	}

	private void ApplyGradientColor()
	{
		//IL_006c: 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_0033: 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_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		if (((ConfigValueElement<bool>)(object)Plugin.useGradient).Value)
		{
			((Graphic)textMesh).color = Color.white;
			((TMP_Text)textMesh).enableVertexGradient = true;
			((TMP_Text)textMesh).colorGradient = new VertexGradient(((ConfigValueElement<Color>)(object)Plugin.startGradientColor).Value, ((ConfigValueElement<Color>)(object)Plugin.startGradientColor).Value, ((ConfigValueElement<Color>)(object)Plugin.endGradientColor).Value, ((ConfigValueElement<Color>)(object)Plugin.endGradientColor).Value);
		}
		else
		{
			((Graphic)textMesh).color = ((ConfigValueElement<Color>)(object)Plugin.ilikemycheesedrippybruh).Value;
			((TMP_Text)textMesh).enableVertexGradient = false;
		}
	}

	public void SetText(float damage)
	{
		if ((float)Mathf.FloorToInt(damage * 10f) / 10f != 0f)
		{
			((TMP_Text)textMesh).text = damage.ToString("F1");
		}
		else
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}
}
namespace CRUSH
{
	public enum MovementType
	{
		Normal,
		FlyingAway
	}
	[BepInPlugin("doomahreal.ultrakill.CRUSH", "CRUSH", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static GameObject floatingTextPrefab;

		public static AudioClip bundledHitSound;

		public static AudioSource hitsnd_plr;

		public static AudioClip[] customHitSounds;

		private ConfigBuilder config;

		[Configgable("MAIN STUFF", "ENABLED:", 0, null)]
		public static ConfigToggle enabled = new ConfigToggle(true);

		[Configgable("MAIN STUFF", "ENABLE HIT SOUND", 1, null)]
		public static ConfigToggle enableHitSound = new ConfigToggle(false);

		[Configgable("MAIN STUFF", "SIZE OF DMG TEXT:", 2, null)]
		public static ConfigVector2 sigmaprime = new ConfigVector2(new Vector2(1f, 1f), (Func<Vector2, bool>)null);

		[Configgable("MAIN STUFF", "TEXT DURATION:", 3, null)]
		public static ConfigInputField<float> imrunningoutofnames = new ConfigInputField<float>(1.5f, (Func<float, bool>)null, (Func<string, ValueTuple<bool, float>>)null);

		[Configgable("MAIN STUFF", "TEXT MOVEMENT TYPE:", 4, null)]
		public static ConfigDropdown<MovementType> fortnaught = new ConfigDropdown<MovementType>(new MovementType[2]
		{
			MovementType.Normal,
			MovementType.FlyingAway
		}, (string[])null, 0);

		[Configgable("DMG TEXT COLOR SLIDERS", "SOLID COLOR:", 0, null)]
		public static ConfigColor ilikemycheesedrippybruh = new ConfigColor(Color.green);

		[Configgable("DMG TEXT COLOR SLIDERS", "USE GRADIENT COLOR", 0, null)]
		public static ConfigToggle useGradient = new ConfigToggle(false);

		[Configgable("DMG TEXT COLOR SLIDERS", "START COLOR", 0, null)]
		public static ConfigColor startGradientColor = new ConfigColor(Color.green);

		[Configgable("DMG TEXT COLOR SLIDERS", "END COLOR", 0, null)]
		public static ConfigColor endGradientColor = new ConfigColor(Color.yellow);

		[Configgable("CUSTOM FONT MAKER", "ENABLE CUSTOM FONT", 0, null)]
		public static ConfigToggle enableCustomFont = new ConfigToggle(false);

		[Configgable("CUSTOM FONT MAKER", null, 0, null)]
		public static ConfigButton fontButton = new ConfigButton((Action)OpenFontsFolder, "OPEN FONT FOLDER (ONLY SUPPORTS 1 .TTF FILE)");

		[Configgable("CUSTOM FONT MAKER", null, 0, null)]
		public static ConfigButton refreshFontButton = new ConfigButton((Action)RefreshFont, "REFRESH FONT");

		[Configgable("CUSTOM HIT SOUND", null, 0, null)]
		public static ConfigButton openHitsoundFolderButton = new ConfigButton((Action)SoundLoader.OpenHitsoundFolder, "OPEN HITSOUND FOLDER (SUPPORTS MULTIPLE SOUND FILES)");

		[Configgable("CUSTOM HIT SOUND", null, 0, null)]
		public static ConfigButton refreshHitsoundButton = new ConfigButton((Action)SoundLoader.RefreshHitSounds, "REFRESH HITSOUND");

		[Configgable("RANDOM PITCH", "ENABLE PITCH RANDOMIZATION", 0, null)]
		public static ConfigToggle enablePitchRandomization = new ConfigToggle(true);

		[Configgable("RANDOM PITCH", "MINIMUM PITCH", 0, null)]
		public static ConfigInputField<float> minPitch = new ConfigInputField<float>(0.8f, (Func<float, bool>)null, (Func<string, ValueTuple<bool, float>>)null);

		[Configgable("RANDOM PITCH", "MAXIMUM PITCH", 0, null)]
		public static ConfigInputField<float> maxPitch = new ConfigInputField<float>(1.2f, (Func<float, bool>)null, (Func<string, ValueTuple<bool, float>>)null);

		[Configgable("OUTLINES", "ENABLE OUTLINE", 0, null)]
		public static ConfigToggle enableOutline = new ConfigToggle(false);

		[Configgable("OUTLINES", "OUTLINE THICKNESS", 1, null)]
		public static ConfigInputField<float> outlineThickness = new ConfigInputField<float>(0.2f, (Func<float, bool>)null, (Func<string, ValueTuple<bool, float>>)null);

		[Configgable("OUTLINES", "OUTLINE COLOR", 2, null)]
		public static ConfigColor outlineColor = new ConfigColor(Color.black);

		private void Awake()
		{
			//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_008b: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Fonts");
			if (!Directory.Exists(path))
			{
				Directory.CreateDirectory(path);
			}
			string[] files = Directory.GetFiles(path, "*.ttf");
			if (((ConfigValueElement<bool>)(object)enableCustomFont).Value && files.Length != 0)
			{
				FontLoader.LoadFont(files[0]);
			}
			AssetBundle obj = AssetBundle.LoadFromMemory(ExtractResource("ULTRAKILLBepInExTemplate.ligmaballs.bundle"));
			floatingTextPrefab = obj.LoadAsset<GameObject>("cool_damage_text");
			bundledHitSound = obj.LoadAsset<AudioClip>("tf2_sigma");
			GameObject val = new GameObject("le epic hitsound");
			Object.DontDestroyOnLoad((Object)val);
			hitsnd_plr = val.AddComponent<AudioSource>();
			SoundLoader.RefreshHitSounds();
			new Harmony("doomahreal.ultrakill.CRUSH").PatchAll();
		}

		public static byte[] ExtractResource(string filename)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(filename);
			if (stream == null)
			{
				return null;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			return array;
		}

		public static void OpenFontsFolder()
		{
			Application.OpenURL(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Fonts"));
		}

		public static void RefreshFont()
		{
			string[] files = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Fonts"), "*.ttf");
			if (((ConfigValueElement<bool>)(object)enableCustomFont).Value && files.Length != 0)
			{
				FontLoader.LoadFont(files[0]);
			}
		}

		private void Start()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			config = new ConfigBuilder("doomahreal.ultrakill.CRUSH", "CRUSH");
			config.BuildAll();
		}
	}
	[HarmonyPatch(typeof(EnemyIdentifier), "DeliverDamage")]
	public static class DeliverDamagePatch
	{
		public static void Postfix(EnemyIdentifier __instance, GameObject target, Vector3 force, Vector3 hitPoint, float multiplier, bool tryForExplode, float critMultiplier, GameObject sourceWeapon, bool ignoreTotalDamageTakenMultiplier, bool fromExplosion)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.dead || !((ConfigValueElement<bool>)(object)Plugin.enabled).Value)
			{
				return;
			}
			Vector3 val = hitPoint + new Vector3(Random.Range(-0.5f, 0.5f), 2f, Random.Range(-0.5f, 0.5f));
			Object.Instantiate<GameObject>(Plugin.floatingTextPrefab, val, Quaternion.identity).GetComponent<MFDOOM>().SetText(multiplier);
			if (((ConfigValueElement<bool>)(object)Plugin.enableHitSound).Value)
			{
				AudioSource val2 = Object.Instantiate<AudioSource>(Plugin.hitsnd_plr);
				if (((ConfigValueElement<bool>)(object)Plugin.enablePitchRandomization).Value)
				{
					val2.pitch = Random.Range(((ConfigValueElement<float>)(object)Plugin.minPitch).Value, ((ConfigValueElement<float>)(object)Plugin.maxPitch).Value);
				}
				else
				{
					val2.pitch = 1f;
				}
				if (Plugin.customHitSounds.Length != 0)
				{
					val2.clip = Plugin.customHitSounds[Random.Range(0, Plugin.customHitSounds.Length)];
				}
				else
				{
					val2.clip = Plugin.bundledHitSound;
				}
				val2.Play();
				Object.Destroy((Object)(object)val2, val2.clip.length / val2.pitch);
			}
		}
	}
	public static class SoundLoader
	{
		private static string hitsoundDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Hitsounds");

		public static void OpenHitsoundFolder()
		{
			Application.OpenURL(hitsoundDirectory);
		}

		public static void RefreshHitSounds()
		{
			if (!Directory.Exists(hitsoundDirectory))
			{
				Directory.CreateDirectory(hitsoundDirectory);
			}
			MonoBehaviour val = Object.FindObjectOfType<MonoBehaviour>();
			val.StartCoroutine(LoadAudioClips(Directory.GetFiles(hitsoundDirectory, "*.*"), val));
		}

		public static AudioType GetAudioType(string file)
		{
			return (AudioType)(Path.GetExtension(file).ToLower() switch
			{
				".mp3" => 13, 
				".wav" => 20, 
				".ogg" => 14, 
				_ => 0, 
			});
		}

		private static IEnumerator LoadAudioClips(string[] audioFiles, MonoBehaviour context)
		{
			List<AudioClip> loadedClips = new List<AudioClip>();
			foreach (string text in audioFiles)
			{
				DownloadHandlerAudioClip dh = new DownloadHandlerAudioClip("file://" + text, GetAudioType(text));
				dh.compressed = true;
				UnityWebRequest wr = new UnityWebRequest("file://" + text, "GET", (DownloadHandler)(object)dh, (UploadHandler)null);
				try
				{
					yield return wr.SendWebRequest();
					if (wr.responseCode == 200)
					{
						AudioClip audioClip = dh.audioClip;
						if ((Object)(object)audioClip != (Object)null)
						{
							loadedClips.Add(audioClip);
						}
					}
				}
				finally
				{
					((IDisposable)wr)?.Dispose();
				}
			}
			Plugin.customHitSounds = loadedClips.ToArray();
			Plugin.hitsnd_plr.clip = ((Plugin.customHitSounds.Length == 0) ? Plugin.bundledHitSound : null);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}