Decompiled source of Swash v1.0.1

Mods/Swash.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppRUMBLE.MoveSystem;
using MelonLoader;
using Microsoft.CodeAnalysis;
using RumbleModUI;
using Swash;
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), "Swash", "1.0.1", "SpooderCode", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Swash")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Swash")]
[assembly: AssemblyTitle("Swash")]
[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 Swash
{
	public class Class1 : MelonMod
	{
		[HarmonyPatch(typeof(Structure), "Kill")]
		public static class structurebreak
		{
			[HarmonyPrefix]
			public static void spawnEffectOnBreak(Structure __instance)
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_018e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0198: Unknown result type (might be due to invalid IL or missing references)
				//IL_014e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0158: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_0202: Unknown result type (might be due to invalid IL or missing references)
				//IL_020c: Unknown result type (might be due to invalid IL or missing references)
				//IL_016e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0178: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
				if (splashEnabled)
				{
					GameObject val = Object.Instantiate<GameObject>(watersplash, ((Component)__instance).gameObject.transform.position, Quaternion.identity);
					switch (((Object)((Component)__instance).gameObject).name)
					{
					case "Disc":
						val.transform.localScale = Vector3.one * 0.2f;
						break;
					case "RockCube":
						val.transform.localScale = Vector3.one * 0.5f;
						break;
					case "Wall":
						val.transform.localScale = Vector3.one * 0.65f;
						break;
					case "Pillar":
						val.transform.localScale = Vector3.one * 0.4f;
						break;
					case "Ball":
						val.transform.localScale = Vector3.one * 0.3f;
						break;
					case "LargeRock":
						val.transform.localScale = Vector3.one * 1f;
						break;
					case "SmallRock":
						val.transform.localScale = Vector3.one * 0.3f;
						break;
					}
					val.SetActive(true);
					Object.Destroy((Object)(object)val, 5f);
				}
			}
		}

		[HarmonyPatch(typeof(Structure), "Start")]
		public static class structurespawn
		{
			private static void Postfix(Structure __instance)
			{
				if (((Component)__instance).transform.childCount > 1)
				{
					applyMats(((Component)__instance).GetComponentInChildren<MeshRenderer>());
				}
				else
				{
					applyMats(((Component)__instance).GetComponent<MeshRenderer>());
				}
			}
		}

		[HarmonyPatch(typeof(Structure), "OnFetchFromPool")]
		public static class structurerespawn
		{
			private static void Postfix(Structure __instance)
			{
				if (((Component)__instance).transform.childCount > 1)
				{
					applyMats(((Component)__instance).GetComponentInChildren<MeshRenderer>());
				}
				else
				{
					applyMats(((Component)__instance).GetComponent<MeshRenderer>());
				}
			}
		}

		public static List<MeshRenderer> structures = new List<MeshRenderer>();

		public static GameObject watercube;

		public static GameObject watersplash;

		public static GameObject waterparticles;

		public static Mod SwashMod = new Mod();

		public static bool particlesEnabled = true;

		public static bool splashEnabled = true;

		public override void OnLateInitializeMelon()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			SwashMod.ModName = "Swash";
			SwashMod.ModVersion = "1.0.0";
			SwashMod.SetFolder("Swash");
			SwashMod.AddToList("Enable Particles", true, 0, "Turns on/off the water particles on strucures", new Tags());
			SwashMod.AddToList("Enable Splash", true, 1, "Turns on/off the splash effect when structures break", new Tags());
			SwashMod.GetFromFile();
			UI.instance.UI_Initialized += UIinit;
			SwashMod.ModSaved += Save;
			Save();
		}

		public void Save()
		{
			particlesEnabled = (bool)SwashMod.Settings[0].SavedValue;
			splashEnabled = (bool)SwashMod.Settings[1].SavedValue;
		}

		private void UIinit()
		{
			UI.instance.AddMod(SwashMod);
		}

		public Shader LoadMat(string path)
		{
			using Stream stream = ((MelonBase)this).MelonAssembly.Assembly.GetManifestResourceStream("Swash.Resources.swash");
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Il2CppAssetBundle val = Il2CppAssetBundleManager.LoadFromMemory(Il2CppStructArray<byte>.op_Implicit(array));
			Shader result = val.LoadAsset<Shader>(path);
			val.Unload(false);
			return result;
		}

		public GameObject LoadObj(string path)
		{
			using Stream stream = ((MelonBase)this).MelonAssembly.Assembly.GetManifestResourceStream("Swash.Resources.swash");
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Il2CppAssetBundle val = Il2CppAssetBundleManager.LoadFromMemory(Il2CppStructArray<byte>.op_Implicit(array));
			GameObject result = val.LoadAsset<GameObject>(path);
			val.Unload(false);
			return result;
		}

		public static void applyMats(MeshRenderer i)
		{
			if ((Object)(object)((Renderer)i).material.shader != (Object)(object)((Renderer)watercube.GetComponent<MeshRenderer>()).material.shader)
			{
				((Renderer)i).material = ((Renderer)watercube.GetComponent<MeshRenderer>()).material;
			}
			if (((Component)i).transform.childCount < 1)
			{
				if (particlesEnabled)
				{
					GameObject val = Object.Instantiate<GameObject>(waterparticles, ((Component)i).transform);
					val.SetActive(true);
				}
			}
			else if (((Component)i).transform.childCount > 0 && !particlesEnabled)
			{
				Object.Destroy((Object)(object)((Component)((Component)i).transform.GetChild(0)).gameObject);
			}
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if ((Object)(object)watercube == (Object)null)
			{
				watercube = Object.Instantiate<GameObject>(LoadObj("DebugCube"));
				watercube.SetActive(false);
				watersplash = Object.Instantiate<GameObject>(LoadObj("WaterSplash"));
				watersplash.SetActive(false);
				waterparticles = Object.Instantiate<GameObject>(LoadObj("WaterParticles"));
				waterparticles.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)watercube);
				Object.DontDestroyOnLoad((Object)(object)watersplash);
				Object.DontDestroyOnLoad((Object)(object)waterparticles);
			}
		}
	}
}