Decompiled source of UltraYoshis v1.0.0

UltraYoshis.dll

Decompiled 2 months 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 BepInEx;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("UltraYoshis")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+11f0548e1f414258b6f69b2691820a53cf59e133")]
[assembly: AssemblyProduct("UltraYoshis")]
[assembly: AssemblyTitle("UltraYoshis")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.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;
		}
	}
	[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;
		}
	}
}
namespace UltraYoshiSkulls
{
	public enum Yoshi
	{
		RedSkull,
		BlueSkull,
		Soap,
		Torch,
		Book,
		Rocket
	}
	public static class YoshiExtensions
	{
		public static string PrefabName(this Yoshi yoshi)
		{
			return yoshi switch
			{
				Yoshi.RedSkull => "MyRedSkull", 
				Yoshi.BlueSkull => "MyBlueSkull", 
				Yoshi.Soap => "MySoap", 
				Yoshi.Torch => "MyTorch", 
				Yoshi.Book => "MyBook", 
				Yoshi.Rocket => "MyRocket", 
				_ => "", 
			};
		}
	}
	[BepInPlugin("io.selim.ultrayoshis", "Ultra Yoshis", "2.0.0")]
	public class UltraYoshiSkullsPlugin : BaseUnityPlugin
	{
		public static readonly Dictionary<Yoshi, GameObject> allYoshis = new Dictionary<Yoshi, GameObject>();

		public static readonly YoshiConfig Config = new YoshiConfig();

		public void Awake()
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			Config.Awake();
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "custompropsbundle"));
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"FAILED TO LOAD ASSETBUNDLE!");
				return;
			}
			foreach (Yoshi value in Enum.GetValues(typeof(Yoshi)))
			{
				GameObject val2 = val.LoadAsset<GameObject>(value.PrefabName());
				if ((Object)(object)val2 != (Object)null)
				{
					allYoshis.Add(value, val2);
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not find prefab '" + value.PrefabName() + "' in the bundle."));
				}
			}
			new Harmony("io.selim.ultrayoshis").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Ultra Yoshi Skulls Loaded!");
		}

		public static void CreateYoshi(Yoshi yoshiType, Transform masterTransform, Vector3 position, Quaternion rotation, Vector3 scale)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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)
			if (allYoshis.ContainsKey(yoshiType))
			{
				GameObject obj = Object.Instantiate<GameObject>(allYoshis[yoshiType], masterTransform);
				obj.SetActive(true);
				obj.transform.localRotation = rotation;
				obj.transform.localPosition = position;
				obj.transform.localScale = scale;
			}
		}
	}
	[HarmonyPatch(typeof(Skull), "Awake")]
	internal static class SkullPatch
	{
		private static void Postfix(Skull __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Invalid comparison between Unknown and I4
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			ItemIdentifier component = ((Component)__instance).GetComponent<ItemIdentifier>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			ItemType itemType = component.itemType;
			Yoshi yoshiType;
			if ((int)itemType == 2)
			{
				if (UltraYoshiSkullsPlugin.Config.IsRedSkullDisabled)
				{
					return;
				}
				yoshiType = Yoshi.RedSkull;
			}
			else
			{
				if ((int)itemType != 1 || UltraYoshiSkullsPlugin.Config.IsBlueSkullDisabled)
				{
					return;
				}
				yoshiType = Yoshi.BlueSkull;
			}
			ModifyMaterial value;
			try
			{
				value = Traverse.Create((object)__instance).Field<ModifyMaterial>("mod").Value;
			}
			catch
			{
				return;
			}
			Renderer value2;
			try
			{
				Traverse obj2 = Traverse.Create((object)value);
				obj2.Method("SetValues", Array.Empty<object>()).GetValue();
				value2 = obj2.Field<Renderer>("rend").Value;
			}
			catch
			{
				return;
			}
			if (Object.op_Implicit((Object)(object)value2))
			{
				value2.enabled = false;
				UltraYoshiSkullsPlugin.CreateYoshi(yoshiType, ((Component)value2).transform, new Vector3(0f, 0f, -0.06f), Quaternion.Euler(110f, 0f, 0f), new Vector3(0.01f, 0.01f, 0.01f));
			}
		}
	}
	[HarmonyPatch(typeof(Soap), "Start")]
	internal static class SoapPatch
	{
		private static void Postfix(Soap __instance)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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)
			if (!UltraYoshiSkullsPlugin.Config.IsSoapDisabled)
			{
				Renderer componentInChildren = ((Component)__instance).GetComponentInChildren<Renderer>();
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					componentInChildren.enabled = false;
					UltraYoshiSkullsPlugin.CreateYoshi(Yoshi.Soap, ((Component)__instance).transform, new Vector3(0f, -0.4f, 0f), Quaternion.Euler(0f, 180f, 0f), new Vector3(0.05f, 0.05f, 0.05f));
				}
			}
		}
	}
	[HarmonyPatch(typeof(Readable), "Awake")]
	internal static class BookPatch
	{
		private static void Postfix(Readable __instance)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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)
			if (!UltraYoshiSkullsPlugin.Config.IsBookDisabled)
			{
				Renderer componentInChildren = ((Component)__instance).GetComponentInChildren<Renderer>();
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					componentInChildren.enabled = false;
					UltraYoshiSkullsPlugin.CreateYoshi(Yoshi.Book, ((Component)__instance).transform, new Vector3(0f, 0f, 0f), Quaternion.Euler(-90f, 180f, 0f), new Vector3(0.05f, 0.05f, 0.05f));
				}
			}
		}
	}
	[HarmonyPatch(typeof(Torch), "Start")]
	internal static class TorchPatch
	{
		private static void Postfix(Torch __instance)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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)
			if (!UltraYoshiSkullsPlugin.Config.IsTorchDisabled)
			{
				Renderer componentInChildren = (Renderer)(object)((Component)__instance).gameObject.GetComponentInChildren<MeshRenderer>();
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					componentInChildren.enabled = false;
					UltraYoshiSkullsPlugin.CreateYoshi(Yoshi.Torch, ((Component)__instance).transform, new Vector3(0f, -0.5f, 0f), Quaternion.Euler(0f, 90f, -0.6f), new Vector3(0.05f, 0.05f, 0.05f));
				}
			}
		}
	}
	[HarmonyPatch(typeof(Grenade), "Awake")]
	internal static class GrenadePatch
	{
		private static void Postfix(Grenade __instance)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			if (UltraYoshiSkullsPlugin.Config.IsRocketDisabled || !__instance.rocket)
			{
				return;
			}
			Renderer[] componentsInChildren = (Renderer[])(object)((Component)__instance).gameObject.GetComponentsInChildren<MeshRenderer>();
			Renderer[] array = componentsInChildren;
			if (array.Length != 0)
			{
				componentsInChildren = array;
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].enabled = false;
				}
				UltraYoshiSkullsPlugin.CreateYoshi(Yoshi.Rocket, ((Component)__instance).transform, new Vector3(0f, 0f, 0f), Quaternion.Euler(90f, 90f, 90f), new Vector3(0.25f, 0.25f, 0.25f));
			}
		}
	}
	public class YoshiConfig
	{
		private PluginConfigurator config;

		private BoolField redSkull;

		private BoolField blueSkull;

		private BoolField soap;

		private BoolField torch;

		private BoolField book;

		private BoolField rocket;

		public bool IsRedSkullDisabled => !redSkull.value;

		public bool IsBlueSkullDisabled => !blueSkull.value;

		public bool IsSoapDisabled => !soap.value;

		public bool IsTorchDisabled => !torch.value;

		public bool IsBookDisabled => !book.value;

		public bool IsRocketDisabled => !rocket.value;

		public void Awake()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			config = PluginConfigurator.Create("Ultra Yoshis", "io.selim.ultrayoshis");
			redSkull = new BoolField(config.rootPanel, "Replace Red Skulls with PinkYoshi", "yoshi.redskull", true);
			blueSkull = new BoolField(config.rootPanel, "Replace Blue Skulls with BlueYoshi", "yoshi.blueskull", true);
			soap = new BoolField(config.rootPanel, "Replace Soap with Yoshi", "yoshi.soap", true);
			torch = new BoolField(config.rootPanel, "Replace Torches with GoldenYoshi", "yoshi.torch", true);
			book = new BoolField(config.rootPanel, "Replace Books with Yoshi", "yoshi.book", true);
			rocket = new BoolField(config.rootPanel, "Replace Rockets with GreyYoshi", "yoshi.rocket", true);
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "io.selim.ultrayoshis";

		public const string PLUGIN_NAME = "UltraYoshis";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}