Decompiled source of Calamity v1.0.0

Calamity.dll

Decompiled a day 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 System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Fields;
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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Calamity")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("Calamity")]
[assembly: AssemblyTitle("Calamity")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 Calamity
{
	public enum CalamityDesign
	{
		InvertedColours,
		RedGalaxy,
		None
	}
	public enum CalamityActivation
	{
		Timed,
		Toggle
	}
	public enum CalamitySound
	{
		Normal,
		None
	}
	[BepInPlugin("com.onkel.ultrakill.calamity", "Calamity Engine", "1.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.onkel.ultrakill.calamity";

		public const string PluginName = "Calamity Engine";

		public const string PluginVersion = "1.2.0";

		internal static EnumField<CalamityDesign> DesignField;

		internal static EnumField<CalamitySound> SoundField;

		internal static EnumField<CalamityActivation> ActivationField;

		private static Harmony harmony;

		internal static ManualLogSource Log;

		internal static ConfigEntry<KeyCode> ActivationKey;

		internal static ConfigEntry<float> Duration;

		internal static ConfigEntry<float> ExplosionSearchRadius;

		private static float calamityEndTime = -1f;

		public static CalamityActivation Activation => (ActivationField != null) ? ActivationField.value : CalamityActivation.Timed;

		public static CalamityDesign Design => (DesignField == null) ? CalamityDesign.RedGalaxy : DesignField.value;

		public static CalamitySound Sound => (SoundField != null) ? SoundField.value : CalamitySound.Normal;

		public static bool CalamityActive => Time.time < calamityEndTime;

		public static float RemainingTime => Mathf.Max(0f, calamityEndTime - Time.time);

		private void Awake()
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"[CALAMITY] Initialisiere Mod...");
			ActivationKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ActivationKey", (KeyCode)120, "Taste, die den Calamity-Zustand aktiviert.");
			Duration = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Duration", 5f, "Dauer des Calamity-Zustands in Sekunden.");
			ExplosionSearchRadius = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ExplosionSearchRadius", 100f, "Maximale Distanz zum Spieler, in der ein Gegner als Angreifer für die Explosion gesucht wird.");
			GameObject val = new GameObject("Calamity_Host");
			((Object)val).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)val);
			val.AddComponent<CalamityController>();
			SetupPluginConfigurator();
			harmony = new Harmony("com.onkel.ultrakill.calamity");
			harmony.PatchAll();
		}

		private void SetupPluginConfigurator()
		{
			PluginConfigurator val = PluginConfigurator.Create("Calamity Engine", "com.onkel.ultrakill.calamity");
			DesignField = new EnumField<CalamityDesign>(val.rootPanel, "Calamity Design", "calamityDesign", CalamityDesign.RedGalaxy);
			DesignField.SetEnumDisplayName(CalamityDesign.InvertedColours, "Inverted Colours");
			DesignField.SetEnumDisplayName(CalamityDesign.RedGalaxy, "Red Galaxy");
			DesignField.SetEnumDisplayName(CalamityDesign.None, "None");
			ActivationField = new EnumField<CalamityActivation>(val.rootPanel, "Activation", "calamityActivation", CalamityActivation.Timed);
			ActivationField.SetEnumDisplayName(CalamityActivation.Timed, $"{Duration.Value:0.#} Seconds");
			ActivationField.SetEnumDisplayName(CalamityActivation.Toggle, "Toggle");
			SoundField = new EnumField<CalamitySound>(val.rootPanel, "Sound", "calamitySound", CalamitySound.Normal);
			SoundField.SetEnumDisplayName(CalamitySound.Normal, "Normal");
			SoundField.SetEnumDisplayName(CalamitySound.None, "None");
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "icon.png");
			if (File.Exists(text))
			{
				val.SetIconWithURL(new Uri(text).AbsoluteUri);
			}
			else
			{
				Log.LogWarning((object)("[CALAMITY] icon.png nicht gefunden: " + text));
			}
		}

		internal static void Activate()
		{
			calamityEndTime = ((Activation == CalamityActivation.Toggle) ? float.PositiveInfinity : (Time.time + Duration.Value));
		}

		internal static void Deactivate()
		{
			calamityEndTime = -1f;
		}

		internal static void ApplyActivationMode()
		{
			if (Activation == CalamityActivation.Timed && float.IsPositiveInfinity(calamityEndTime))
			{
				calamityEndTime = Time.time + Duration.Value;
			}
		}
	}
	public class CalamityController : MonoBehaviour
	{
		private static readonly Color redShift = new Color(1f, 0.3f, 0.36f, 1f);

		private static readonly Color vignetteColor = new Color(0.12f, 0f, 0.03f, 1f);

		private const float nebulaAlpha = 0.5f;

		private const float vignetteAlpha = 0.9f;

		private const float fadeSpeed = 4f;

		private const float soundVolume = 1f;

		private Material multiplyMat;

		private Material nebulaMat;

		private Material starsMat;

		private Material vignetteMat;

		private Material invertMat;

		private AudioSource audioSource;

		private int soundStartSample;

		private float tintAmount;

		private bool wasActive;

		private void Awake()
		{
			SetupOverlayMaterial();
			SetupAudio();
			((MonoBehaviour)this).StartCoroutine(DrawOverlayAtEndOfFrame());
		}

		private void Update()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(Plugin.ActivationKey.Value) && (Object)(object)MonoSingleton<NewMovement>.Instance != (Object)null)
			{
				bool calamityActive = Plugin.CalamityActive;
				if (Plugin.Activation == CalamityActivation.Toggle && calamityActive)
				{
					Plugin.Deactivate();
				}
				else
				{
					Plugin.Activate();
					if (!calamityActive)
					{
						PlaySound();
						SendHud("WONDER OF U: CALAMITY");
					}
					Plugin.Log.LogInfo((object)((Plugin.Activation == CalamityActivation.Toggle) ? "[CALAMITY] Aktiviert (Toggle) – erneut drücken zum Ausschalten." : $"[CALAMITY] Aktiviert für {Plugin.Duration.Value}s."));
				}
			}
			Plugin.ApplyActivationMode();
			bool calamityActive2 = Plugin.CalamityActive;
			if (wasActive && !calamityActive2)
			{
				ProjectilePatch.ClearFlipped();
				SendHud("CALAMITY ENDED");
				Plugin.Log.LogInfo((object)"[CALAMITY] Beendet.");
			}
			wasActive = calamityActive2;
			tintAmount = Mathf.MoveTowards(tintAmount, calamityActive2 ? 1f : 0f, 4f * Time.unscaledDeltaTime);
		}

		private static void SendHud(string message)
		{
			HudMessageReceiver instance = MonoSingleton<HudMessageReceiver>.Instance;
			if ((Object)(object)instance != (Object)null)
			{
				instance.SendHudMessage(message, "", "", 0, false, false, true);
			}
		}

		private void SetupOverlayMaterial()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Expected O, but got Unknown
			Shader val = Shader.Find("Hidden/Internal-Colored");
			Shader val2 = Shader.Find("Sprites/Default") ?? Shader.Find("UI/Default");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Plugin.Log.LogError((object)"[CALAMITY] Overlay-Shader nicht gefunden – kein Overlay.");
				return;
			}
			multiplyMat = new Material(val)
			{
				hideFlags = (HideFlags)61
			};
			multiplyMat.SetInt("_SrcBlend", 2);
			multiplyMat.SetInt("_DstBlend", 0);
			multiplyMat.SetInt("_Cull", 0);
			multiplyMat.SetInt("_ZWrite", 0);
			multiplyMat.SetInt("_ZTest", 8);
			invertMat = new Material(val)
			{
				hideFlags = (HideFlags)61
			};
			invertMat.SetInt("_SrcBlend", 4);
			invertMat.SetInt("_DstBlend", 6);
			invertMat.SetInt("_Cull", 0);
			invertMat.SetInt("_ZWrite", 0);
			invertMat.SetInt("_ZTest", 8);
			nebulaMat = new Material(val2)
			{
				hideFlags = (HideFlags)61,
				mainTexture = (Texture)(object)GalaxyTextures.CreateNebula(256)
			};
			starsMat = new Material(val2)
			{
				hideFlags = (HideFlags)61,
				mainTexture = (Texture)(object)GalaxyTextures.CreateStars(512, 420)
			};
			vignetteMat = new Material(val2)
			{
				hideFlags = (HideFlags)61,
				mainTexture = (Texture)(object)GalaxyTextures.CreateVignette(128)
			};
		}

		private IEnumerator DrawOverlayAtEndOfFrame()
		{
			WaitForEndOfFrame endOfFrame = new WaitForEndOfFrame();
			while (true)
			{
				yield return endOfFrame;
				CalamityDesign design = Plugin.Design;
				if (!(tintAmount <= 0f) && !((Object)(object)multiplyMat == (Object)null) && design != CalamityDesign.None)
				{
					RenderTexture previous = RenderTexture.active;
					RenderTexture.active = null;
					if (design == CalamityDesign.InvertedColours)
					{
						DrawInverted(tintAmount);
						RenderTexture.active = previous;
						continue;
					}
					float a = tintAmount;
					float t = Time.unscaledTime;
					float aspect = (float)Screen.width / (float)Mathf.Max(1, Screen.height);
					GL.PushMatrix();
					GL.LoadOrtho();
					multiplyMat.SetPass(0);
					DrawQuad(Color.Lerp(Color.white, redShift, a), 0f, 0f, 1f, 1f);
					nebulaMat.SetPass(0);
					DrawQuad(new Color(1f, 1f, 1f, 0.5f * a), t * 0.015f, t * 0.006f, aspect * 1.2f, 1.2f);
					starsMat.SetPass(0);
					DrawQuad(new Color(1f, 0.9f, 0.92f, a * (0.8f + 0.2f * Mathf.Sin(t * 3.1f))), t * 0.03f, t * 0.01f, aspect, 1f);
					DrawQuad(new Color(1f, 0.75f, 0.8f, a * (0.7f + 0.3f * Mathf.Sin(t * 4.7f + 1f))), (0f - t) * 0.05f, t * 0.02f, aspect * 1.7f, 1.7f);
					vignetteMat.SetPass(0);
					Color v = vignetteColor;
					v.a = 0.9f * a;
					DrawQuad(v, 0f, 0f, 1f, 1f);
					GL.PopMatrix();
					RenderTexture.active = previous;
				}
			}
		}

		private void DrawInverted(float amount)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			bool sRGBWrite = GL.sRGBWrite;
			GL.sRGBWrite = false;
			GL.PushMatrix();
			GL.LoadOrtho();
			invertMat.SetPass(0);
			DrawQuad(new Color(amount, amount, amount, 1f), 0f, 0f, 1f, 1f);
			GL.PopMatrix();
			GL.sRGBWrite = sRGBWrite;
		}

		private static void DrawQuad(Color color, float u0, float v0, float uScale, float vScale)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			GL.Begin(7);
			GL.Color(color);
			GL.TexCoord2(u0, v0);
			GL.Vertex3(0f, 0f, 0f);
			GL.TexCoord2(u0, v0 + vScale);
			GL.Vertex3(0f, 1f, 0f);
			GL.TexCoord2(u0 + uScale, v0 + vScale);
			GL.Vertex3(1f, 1f, 0f);
			GL.TexCoord2(u0 + uScale, v0);
			GL.Vertex3(1f, 0f, 0f);
			GL.End();
		}

		private void SetupAudio()
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string path = Path.Combine(directoryName, "calamity.wav");
			if (!File.Exists(path))
			{
				Plugin.Log.LogInfo((object)"[CALAMITY] Kein calamity.wav gefunden – läuft ohne Sound.");
				return;
			}
			string error;
			AudioClip val = WavLoader.Load(path, out soundStartSample, out error);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)("[CALAMITY] WAV konnte nicht geladen werden: " + error));
				return;
			}
			audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
			audioSource.playOnAwake = false;
			audioSource.loop = false;
			audioSource.spatialBlend = 0f;
			audioSource.priority = 0;
			audioSource.bypassReverbZones = true;
			audioSource.dopplerLevel = 0f;
			audioSource.volume = 1f;
			audioSource.clip = val;
		}

		private void PlaySound()
		{
			if (Plugin.Sound != CalamitySound.None && !((Object)(object)audioSource == (Object)null) && !((Object)(object)audioSource.clip == (Object)null))
			{
				audioSource.Stop();
				audioSource.timeSamples = soundStartSample;
				audioSource.Play();
			}
		}
	}
	[HarmonyPatch(typeof(Projectile), "Update")]
	internal static class ProjectilePatch
	{
		private static readonly FieldRef<Projectile, Rigidbody> RbRef = AccessTools.FieldRefAccess<Projectile, Rigidbody>("rb");

		private static readonly HashSet<int> Flipped = new HashSet<int>();

		internal static void ClearFlipped()
		{
			Flipped.Clear();
		}

		[HarmonyPostfix]
		private static void Postfix(Projectile __instance)
		{
			//IL_0082: 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_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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.CalamityActive || __instance.friendly || __instance.playerBullet || __instance.parried || __instance.decorative)
			{
				return;
			}
			if (Flipped.Count > 4096)
			{
				Flipped.Clear();
			}
			if (Flipped.Add(((Object)__instance).GetInstanceID()))
			{
				Transform transform = ((Component)__instance).transform;
				transform.rotation = Quaternion.LookRotation(-transform.forward, transform.up);
				Rigidbody val = RbRef.Invoke(__instance) ?? ((Component)__instance).GetComponent<Rigidbody>();
				if ((Object)(object)val != (Object)null)
				{
					val.velocity *= -1f;
				}
				__instance.homingType = (HomingType)0;
				__instance.friendly = true;
				__instance.hittingPlayer = false;
			}
		}
	}
	[HarmonyPatch(typeof(NewMovement), "GetHurt")]
	internal static class PlayerDamagePatch
	{
		private const float SpawnCooldown = 0.2f;

		private static float lastSpawnTime = -10f;

		[HarmonyPrefix]
		private static bool Prefix(NewMovement __instance, bool explosion)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.CalamityActive)
			{
				return true;
			}
			if ((!explosion || !(Time.time - lastSpawnTime < 1f)) && Time.time - lastSpawnTime >= 0.2f)
			{
				EnemyIdentifier val = FindNearestEnemy(((Component)__instance).transform.position);
				if ((Object)(object)val != (Object)null)
				{
					SpawnExplosion(val);
					lastSpawnTime = Time.time;
				}
			}
			return false;
		}

		private static EnemyIdentifier FindNearestEnemy(Vector3 playerPos)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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)
			EnemyIdentifier result = null;
			float num = Plugin.ExplosionSearchRadius.Value * Plugin.ExplosionSearchRadius.Value;
			EnemyIdentifier[] array = Object.FindObjectsOfType<EnemyIdentifier>();
			foreach (EnemyIdentifier val in array)
			{
				if (!val.dead)
				{
					Vector3 val2 = ((Component)val).transform.position - playerPos;
					float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						result = val;
					}
				}
			}
			return result;
		}

		private static void SpawnExplosion(EnemyIdentifier target)
		{
			//IL_0059: 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_005e: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			DefaultReferenceManager instance = MonoSingleton<DefaultReferenceManager>.Instance;
			GameObject val = (((Object)(object)instance != (Object)null) ? instance.explosion : null);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[CALAMITY] Explosions-Prefab nicht gefunden.");
				return;
			}
			Vector3 val2 = (((Object)(object)target.overrideCenter != (Object)null) ? target.overrideCenter.position : ((Component)target).transform.position);
			Object.Instantiate<GameObject>(val, val2, Quaternion.identity);
		}
	}
	internal static class GalaxyTextures
	{
		private static readonly Color[] nebulaGradient = (Color[])(object)new Color[5]
		{
			new Color(0.03f, 0f, 0.02f),
			new Color(0.3f, 0.01f, 0.06f),
			new Color(0.75f, 0.06f, 0.14f),
			new Color(0.5f, 0.12f, 0.42f),
			new Color(1f, 0.55f, 0.62f)
		};

		public static Texture2D CreateNebula(int size)
		{
			//IL_0082: 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_00a7: 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)
			Texture2D val = NewTexture(size, (TextureWrapMode)0);
			Color[] array = (Color[])(object)new Color[size * size];
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float u = (float)j / (float)size;
					float v = (float)i / (float)size;
					float num = TileableFbm(u, v, 4f, 5, 17.3f);
					float num2 = TileableFbm(u, v, 9f, 4, 91.7f);
					num = Mathf.Clamp01((num - 0.25f) * 1.6f + (num2 - 0.5f) * 0.35f);
					Color val2 = SampleGradient(num);
					val2.a = Mathf.SmoothStep(0.15f, 1f, num);
					array[i * size + j] = val2;
				}
			}
			val.SetPixels(array);
			val.Apply(false, true);
			return val;
		}

		public static Texture2D CreateStars(int size, int count)
		{
			//IL_00e1: 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_00fa: 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)
			Texture2D val = NewTexture(size, (TextureWrapMode)0);
			Color[] array = (Color[])(object)new Color[size * size];
			Random random = new Random(1337);
			for (int i = 0; i < count; i++)
			{
				int num = random.Next(size);
				int num2 = random.Next(size);
				float num3 = 0.35f + (float)random.NextDouble() * 0.65f;
				float num4 = ((random.NextDouble() < 0.08) ? 2.5f : 1.1f);
				int num5 = Mathf.CeilToInt(num4);
				for (int j = -num5; j <= num5; j++)
				{
					for (int k = -num5; k <= num5; k++)
					{
						float num6 = Mathf.Sqrt((float)(k * k + j * j)) / num4;
						if (!(num6 > 1f))
						{
							int num7 = (num2 + j + size) % size * size + (num + k + size) % size;
							float num8 = num3 * (1f - num6) * (1f - num6);
							Color val2 = array[num7];
							array[num7] = new Color(1f, 1f, 1f, Mathf.Max(val2.a, num8));
						}
					}
				}
			}
			val.SetPixels(array);
			val.Apply(false, true);
			return val;
		}

		public static Texture2D CreateVignette(int size)
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = NewTexture(size, (TextureWrapMode)1);
			Color[] array = (Color[])(object)new Color[size * size];
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num = ((float)j + 0.5f) / (float)size * 2f - 1f;
					float num2 = ((float)i + 0.5f) / (float)size * 2f - 1f;
					float num3 = Mathf.Sqrt(num * num + num2 * num2) / 1.4142f;
					array[i * size + j] = new Color(1f, 1f, 1f, Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.45f, 1f, num3)));
				}
			}
			val.SetPixels(array);
			val.Apply(false, true);
			return val;
		}

		private static Texture2D NewTexture(int size, TextureWrapMode wrap)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			return new Texture2D(size, size, (TextureFormat)4, false)
			{
				wrapMode = wrap,
				filterMode = (FilterMode)1,
				hideFlags = (HideFlags)61
			};
		}

		private static Color SampleGradient(float t)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01(t) * (float)(nebulaGradient.Length - 1);
			int num2 = Mathf.Min((int)num, nebulaGradient.Length - 2);
			return Color.Lerp(nebulaGradient[num2], nebulaGradient[num2 + 1], num - (float)num2);
		}

		private static float TileableFbm(float u, float v, float frequency, int octaves, float seed)
		{
			float num = 0f;
			float num2 = 0.5f;
			float num3 = 0f;
			for (int i = 0; i < octaves; i++)
			{
				float num4 = frequency * (float)(1 << i);
				float num5 = Mathf.PerlinNoise(seed + u * num4, seed + v * num4);
				float num6 = Mathf.PerlinNoise(seed + (u - 1f) * num4, seed + v * num4);
				float num7 = Mathf.PerlinNoise(seed + u * num4, seed + (v - 1f) * num4);
				float num8 = Mathf.PerlinNoise(seed + (u - 1f) * num4, seed + (v - 1f) * num4);
				float num9 = Mathf.Lerp(Mathf.Lerp(num5, num6, u), Mathf.Lerp(num7, num8, u), v);
				num += num9 * num2;
				num3 += num2;
				num2 *= 0.5f;
			}
			return num / num3;
		}
	}
	internal static class WavLoader
	{
		private const float silenceThreshold = 0.01f;

		public static AudioClip Load(string path, out int firstAudibleSample, out string error)
		{
			firstAudibleSample = 0;
			error = null;
			byte[] array = File.ReadAllBytes(path);
			if (array.Length < 12 || Encoding.ASCII.GetString(array, 0, 4) != "RIFF" || Encoding.ASCII.GetString(array, 8, 4) != "WAVE")
			{
				error = "Keine gültige WAV-Datei (RIFF/WAVE-Header fehlt). Ist es evtl. eine umbenannte MP3/OGG?";
				return null;
			}
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			int num5 = -1;
			int num6 = 0;
			int num7 = 12;
			while (num7 + 8 <= array.Length)
			{
				string text = Encoding.ASCII.GetString(array, num7, 4);
				int num8 = BitConverter.ToInt32(array, num7 + 4);
				int num9 = num7 + 8;
				if (num8 < 0 || num9 + num8 > array.Length)
				{
					num8 = array.Length - num9;
				}
				if (text == "fmt ")
				{
					num = BitConverter.ToUInt16(array, num9);
					num2 = BitConverter.ToUInt16(array, num9 + 2);
					num3 = BitConverter.ToInt32(array, num9 + 4);
					num4 = BitConverter.ToUInt16(array, num9 + 14);
					if (num == 65534 && num8 >= 26)
					{
						num = BitConverter.ToUInt16(array, num9 + 24);
					}
				}
				else if (text == "data")
				{
					num5 = num9;
					num6 = num8;
				}
				num7 = num9 + num8 + (num8 & 1);
			}
			if (num5 < 0 || num2 <= 0 || num3 <= 0 || num4 <= 0)
			{
				error = "fmt- oder data-Chunk fehlt.";
				return null;
			}
			bool flag = num == 3 && num4 == 32;
			if (num != 1 && !flag)
			{
				error = "Nicht unterstütztes Format (Format-Tag " + num + ", " + num4 + " Bit). Bitte als PCM 16 Bit exportieren.";
				return null;
			}
			int num10 = num4 / 8;
			int num11 = num6 / num10 / num2;
			float[] array2 = new float[num11 * num2];
			for (int i = 0; i < array2.Length; i++)
			{
				int num12 = num5 + i * num10;
				if (flag)
				{
					array2[i] = BitConverter.ToSingle(array, num12);
					continue;
				}
				switch (num4)
				{
				case 8:
					array2[i] = (float)(array[num12] - 128) / 128f;
					break;
				case 16:
					array2[i] = (float)(short)(array[num12] | (array[num12 + 1] << 8)) / 32768f;
					break;
				case 24:
					array2[i] = (float)((array[num12] << 8) | (array[num12 + 1] << 16) | (array[num12 + 2] << 24)) / 2.1474836E+09f;
					break;
				case 32:
					array2[i] = (float)BitConverter.ToInt32(array, num12) / 2.1474836E+09f;
					break;
				}
			}
			for (int j = 0; j < array2.Length; j++)
			{
				if (Math.Abs(array2[j]) > 0.01f)
				{
					firstAudibleSample = j / num2;
					break;
				}
			}
			AudioClip val = AudioClip.Create(Path.GetFileNameWithoutExtension(path), num11, num2, num3, false);
			val.SetData(array2, 0);
			return val;
		}
	}
}