Decompiled source of RailgunSonicBoom v1.0.2

Mods/RailgunEffect.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using RailgunEffect;
using RumbleModdingAPI;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Class1), "The Railgun Effect", "1.0.2", "SpooderCode", null)]
[assembly: MelonGame("", "")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("RailgunEffect")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RailgunEffect")]
[assembly: AssemblyTitle("RailgunEffect")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace RailgunEffect
{
	public class Class1 : MelonMod
	{
		private MelonPreferences_Category? ourFirstCategory;

		private MelonPreferences_Entry<bool>? sound;

		private MelonPreferences_Entry<bool>? vfx;

		private MelonPreferences_Entry<string>? ParticleCol;

		private MelonPreferences_Entry<string>? FlashCol;

		private MelonPreferences_Entry<string>? ShockwaveCol;

		private MelonPreferences_Entry<string>? ElectricityCol;

		public int Errors = 0;

		public float RailgunThreshold = 21f;

		public GameObject? explosion;

		public Rigidbody[] walls;

		public List<float> wallSpeeds = new List<float>(0);

		public List<Rigidbody> hitstopped = new List<Rigidbody>(0);

		public override void OnInitializeMelon()
		{
			ourFirstCategory = MelonPreferences.CreateCategory("Config");
			sound = ourFirstCategory.CreateEntry<bool>("Play Ding Sound", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			vfx = ourFirstCategory.CreateEntry<bool>("Show VFX", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			ParticleCol = ourFirstCategory.CreateEntry<string>("Particle Color", "#00EEFF", (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			FlashCol = ourFirstCategory.CreateEntry<string>("Flash Color", "#00EEFF", (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			ShockwaveCol = ourFirstCategory.CreateEntry<string>("Shockwave Color", "#00EEFF", (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			ElectricityCol = ourFirstCategory.CreateEntry<string>("Electricity Color", "#00EEFF", (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			ourFirstCategory.SetFilePath("UserData/Railgun.cfg");
			ourFirstCategory.SaveToFile(true);
		}

		public GameObject LoadAsset()
		{
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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)
			using Stream stream = ((MelonBase)this).MelonAssembly.Assembly.GetManifestResourceStream("RailgunEffect.Resources.railgun");
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Il2CppAssetBundle val = Il2CppAssetBundleManager.LoadFromMemory(Il2CppStructArray<byte>.op_Implicit(array));
			GameObject val2 = val.LoadAsset<GameObject>("Explosion");
			MainModule main = val2.GetComponent<ParticleSystem>().main;
			MainModule main2 = ((Component)val2.transform.Find("vfx_Shockwave_01")).GetComponent<ParticleSystem>().main;
			MainModule main3 = ((Component)val2.transform.Find("vfx_Shockwave_01/Flash")).GetComponent<ParticleSystem>().main;
			MainModule main4 = ((Component)val2.transform.Find("vfx_Electricity_01")).GetComponent<ParticleSystem>().main;
			MelonLogger.Msg("[RAILGUN] Finished loading Explosion!");
			Color val3 = default(Color);
			if (ColorUtility.TryParseHtmlString(ParticleCol.Value, ref val3))
			{
				main.startColor = MinMaxGradient.op_Implicit(val3);
			}
			if (ColorUtility.TryParseHtmlString(ShockwaveCol.Value, ref val3))
			{
				main2.startColor = MinMaxGradient.op_Implicit(val3);
			}
			if (ColorUtility.TryParseHtmlString(FlashCol.Value, ref val3))
			{
				main3.startColor = MinMaxGradient.op_Implicit(val3);
			}
			if (ColorUtility.TryParseHtmlString(ElectricityCol.Value, ref val3))
			{
				main4.startColor = MinMaxGradient.op_Implicit(val3);
			}
			val.Unload(false);
			return val2;
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (wallSpeeds.Count > 0)
			{
				wallSpeeds.Clear();
				hitstopped.Clear();
			}
			if (Scene.GetSceneName() == "Gym" && (Object)(object)explosion == (Object)null)
			{
				explosion = LoadAsset();
				explosion.GetComponent<AudioSource>().playOnAwake = sound.Value;
				Object.DontDestroyOnLoad((Object)(object)explosion);
			}
		}

		public override void OnFixedUpdate()
		{
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!(Scene.GetSceneName() == "Gym") && !(Scene.GetSceneName() == "Park") && !(Scene.GetSceneName() == "Map0") && !(Scene.GetSceneName() == "Map1"))
				{
					return;
				}
				if ((Object)(object)explosion == (Object)null)
				{
					explosion = LoadAsset();
					explosion.GetComponent<AudioSource>().playOnAwake = sound.Value;
					Object.DontDestroyOnLoad((Object)(object)explosion);
				}
				Rigidbody[] first = Il2CppArrayBase<Rigidbody>.op_Implicit(Structures.GetPoolWall().GetComponentsInChildren<Rigidbody>());
				Rigidbody[] second = Il2CppArrayBase<Rigidbody>.op_Implicit(Structures.GetPoolCube().GetComponentsInChildren<Rigidbody>());
				Rigidbody[] second2 = Il2CppArrayBase<Rigidbody>.op_Implicit(Structures.GetPoolLargeRock().GetComponentsInChildren<Rigidbody>());
				Rigidbody[] second3 = Il2CppArrayBase<Rigidbody>.op_Implicit(Structures.GetPoolPillar().GetComponentsInChildren<Rigidbody>());
				walls = first.Concat(second).ToArray();
				walls = walls.Concat(second2).ToArray();
				walls = walls.Concat(second3).ToArray();
				if (walls.Length > wallSpeeds.Count())
				{
					for (int i = 0; i < walls.Length - wallSpeeds.Count(); i++)
					{
						wallSpeeds.Add(0f);
					}
				}
				Rigidbody[] array = walls;
				foreach (Rigidbody val in array)
				{
					Vector3 velocity = val.velocity;
					float num = ((Vector3)(ref velocity)).magnitude - wallSpeeds[Array.IndexOf(walls, val)] * 2f;
					bool flag = false;
					if ((double)num < 0.1 && (double)num > -0.1)
					{
						flag = true;
					}
					if (flag && hitstopped.Contains(val))
					{
						velocity = val.velocity;
						if (((Vector3)(ref velocity)).magnitude > 18f && vfx.Value)
						{
							GameObject val2 = Object.Instantiate<GameObject>(explosion);
							val2.transform.SetParent(((Component)val).transform.parent);
							val2.transform.position = val.position;
							Object.Destroy((Object)(object)val2, 2f);
						}
					}
					velocity = val.velocity;
					if (((Vector3)(ref velocity)).magnitude != 0f)
					{
						List<float> list = wallSpeeds;
						int index = Array.IndexOf(walls, val);
						velocity = val.velocity;
						list[index] = ((Vector3)(ref velocity)).magnitude;
						if (hitstopped.Contains(val))
						{
							hitstopped.Remove(val);
						}
					}
					else if (!hitstopped.Contains(val))
					{
						hitstopped.Add(val);
					}
				}
			}
			catch (Exception)
			{
				Errors++;
			}
		}
	}
}