Decompiled source of CustomShiftstoneModels v1.0.2

Mods/ShifstoneModels.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Pools;
using Il2CppRUMBLE.Utilities;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using Microsoft.CodeAnalysis;
using ShifstoneModels;
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), "Custom Shiftstone Models", "1.0.2", "SpooderCode", null)]
[assembly: MelonGame("", "")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ShifstoneModels")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ShifstoneModels")]
[assembly: AssemblyTitle("ShifstoneModels")]
[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 ShifstoneModels
{
	public class Class1 : MelonMod
	{
		public Mesh LoadShifstone(string file, string objN)
		{
			try
			{
				Il2CppAssetBundle val = Il2CppAssetBundleManager.LoadFromFile("UserData/ShiftstoneModels/" + file);
				GameObject val2 = Object.Instantiate<GameObject>(val.LoadAsset<GameObject>(objN));
				val2.SetActive(false);
				val.Unload(false);
				return val2.GetComponent<MeshFilter>().mesh;
			}
			catch
			{
				try
				{
					Il2CppAssetBundle val3 = Il2CppAssetBundleManager.LoadFromFile("UserData/ShiftstoneModels/" + file + "m");
					GameObject val4 = Object.Instantiate<GameObject>(val3.LoadAsset<GameObject>(objN));
					val4.SetActive(false);
					val3.Unload(false);
					return val4.GetComponent<MeshFilter>().mesh;
				}
				catch
				{
					return null;
				}
			}
		}

		public Material[] LoadShifstoneMats(string file, string objN)
		{
			try
			{
				Il2CppAssetBundle val = Il2CppAssetBundleManager.LoadFromFile("UserData/ShiftstoneModels/" + file);
				GameObject val2 = Object.Instantiate<GameObject>(val.LoadAsset<GameObject>(objN));
				val2.SetActive(false);
				val.Unload(false);
				return Il2CppArrayBase<Material>.op_Implicit((Il2CppArrayBase<Material>)(object)((Renderer)val2.GetComponent<MeshRenderer>()).materials);
			}
			catch
			{
				return null;
			}
		}

		public RuntimeAnimatorController LoadShifstoneAnims(string file, string objN)
		{
			try
			{
				Il2CppAssetBundle val = Il2CppAssetBundleManager.LoadFromFile("UserData/ShiftstoneModels/" + file);
				GameObject val2 = Object.Instantiate<GameObject>(val.LoadAsset<GameObject>(objN));
				val2.SetActive(false);
				val.Unload(false);
				return val2.GetComponent<Animator>().runtimeAnimatorController;
			}
			catch
			{
				try
				{
					Il2CppAssetBundle val3 = Il2CppAssetBundleManager.LoadFromFile("UserData/ShiftstoneModels/" + file + "m");
					GameObject val4 = Object.Instantiate<GameObject>(val3.LoadAsset<GameObject>(objN));
					val4.SetActive(false);
					val3.Unload(false);
					return val4.GetComponent<Animator>().runtimeAnimatorController;
				}
				catch
				{
					return null;
				}
			}
		}

		public Transform[] LoadShifstoneChildren(string file, string objN)
		{
			try
			{
				Il2CppAssetBundle val = Il2CppAssetBundleManager.LoadFromFile("UserData/ShiftstoneModels/" + file);
				GameObject val2 = Object.Instantiate<GameObject>(val.LoadAsset<GameObject>(objN));
				val2.SetActive(false);
				val.Unload(false);
				if (val2.transform.GetChildCount() > 0)
				{
					List<Transform> list = new List<Transform>();
					for (int i = 0; i < val2.transform.GetChildCount(); i++)
					{
						list.Add(val2.transform.GetChild(i));
					}
					return list.ToArray();
				}
				return null;
			}
			catch
			{
				try
				{
					Il2CppAssetBundle val3 = Il2CppAssetBundleManager.LoadFromFile("UserData/ShiftstoneModels/" + file + "m");
					GameObject val4 = Object.Instantiate<GameObject>(val3.LoadAsset<GameObject>(objN));
					val4.SetActive(false);
					val3.Unload(false);
					if (val4.transform.GetChildCount() > 0)
					{
						List<Transform> list2 = new List<Transform>();
						for (int j = 0; j < val4.transform.GetChildCount(); j++)
						{
							list2.Add(val4.transform.GetChild(j));
						}
						return list2.ToArray();
					}
					return null;
				}
				catch
				{
					return null;
				}
			}
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (!(sceneName == "Loader"))
			{
				return;
			}
			string[] array = new string[8] { "CHARGE", "GUARD", "VOLATILE", "ADAMANT", "SURGE", "VIGOR", "FLOW", "STUBBORN" };
			string[] array2 = array;
			foreach (string text in array2)
			{
				Mesh val = LoadShifstone(text, text);
				Material[] array3 = LoadShifstoneMats(text, text);
				RuntimeAnimatorController val2 = LoadShifstoneAnims(text, text);
				Transform[] array4 = LoadShifstoneChildren(text, text);
				if (text != "CHARGE")
				{
					MelonLogger.Msg(text + " Loaded");
				}
				else
				{
					MelonLogger.Msg(text + " Loaded (WARNING: Due to a problem with RUMBLE, This stone will not have a custom model)");
				}
				string text2 = "";
				switch (text)
				{
				case "GUARD":
					text2 = "GuardStone";
					break;
				case "CHARGE":
					text2 = "ChargeStone";
					break;
				case "VOLATILE":
					text2 = "VolatileStone";
					break;
				case "ADAMANT":
					text2 = "AdamantStone";
					break;
				case "SURGE":
					text2 = "SurgeStone";
					break;
				case "VIGOR":
					text2 = "VigorStone";
					break;
				case "FLOW":
					text2 = "FlowStone";
					break;
				case "STUBBORN":
					text2 = "StubbornStone";
					break;
				}
				Enumerator<PooledMonoBehaviour> enumerator = Singleton<PoolManager>.instance.GetPool(text2).PooledObjects.GetEnumerator();
				while (enumerator.MoveNext())
				{
					PooledMonoBehaviour current = enumerator.Current;
					if ((Object)(object)val != (Object)null)
					{
						((Component)((Component)current).transform.GetChild(0)).GetComponent<MeshFilter>().mesh = val;
					}
					if (array3 != null)
					{
						((Renderer)((Component)((Component)current).transform.GetChild(0)).GetComponent<MeshRenderer>()).materials = Il2CppReferenceArray<Material>.op_Implicit(array3);
					}
					if (array4 != null)
					{
						Transform[] array5 = array4;
						foreach (Transform val3 in array5)
						{
							GameObject val4 = Object.Instantiate<GameObject>(((Component)val3).gameObject, ((Component)current).transform.GetChild(0));
						}
						foreach (MeshRenderer componentsInChild in ((Component)((Component)current).transform.GetChild(0)).GetComponentsInChildren<MeshRenderer>())
						{
							((Renderer)componentsInChild).materials = ((Renderer)((Component)((Component)current).transform.GetChild(0)).GetComponent<MeshRenderer>()).materials;
						}
					}
					if ((Object)(object)val2 != (Object)null)
					{
						((Component)((Component)current).transform.GetChild(0)).gameObject.AddComponent<Animator>();
						((Component)((Component)current).transform.GetChild(0)).GetComponent<Animator>().runtimeAnimatorController = val2;
					}
				}
			}
		}
	}
}