Decompiled source of BingBongToMochi v0.1.0

plugins/com.github.FelineEntity.BingBingToMochi.dll

Decompiled 6 days ago
using System;
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 BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.FelineEntity.BingBingToMochi")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("com.github.FelineEntity.BingBingToMochi")]
[assembly: AssemblyTitle("BingBongToMochi")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BingBongToMochi
{
	[HarmonyPatch(typeof(Item))]
	public class ItemPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void Item_Start(Item __instance)
		{
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Invalid comparison between Unknown and I4
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Invalid comparison between Unknown and I4
			if (!((Object)__instance).name.Contains("BingBong"))
			{
				return;
			}
			MeshRenderer[] componentsInChildren = ((Component)__instance).gameObject.GetComponentsInChildren<MeshRenderer>();
			foreach (MeshRenderer val in componentsInChildren)
			{
				((Renderer)val).enabled = false;
			}
			Collider[] componentsInChildren2 = ((Component)__instance).gameObject.GetComponentsInChildren<Collider>();
			foreach (Collider val2 in componentsInChildren2)
			{
				Object.Destroy((Object)(object)val2);
			}
			GameObject val3 = Object.Instantiate<GameObject>(Plugin.MochiPrefab, ((Component)__instance).gameObject.transform);
			((Renderer)val3.GetComponent<MeshRenderer>()).materials[0].shader = Shader.Find("Universal Render Pipeline/Lit");
			((Renderer)val3.GetComponent<MeshRenderer>()).materials[1].shader = Shader.Find("Universal Render Pipeline/Lit");
			float num = 1f - (float)__instance.GetData<IntItemData>((DataEntryKey)1).Value * 0.2f;
			((Renderer)val3.GetComponent<MeshRenderer>()).materials[0].SetColor("_BaseColor", new Color(Mathf.Clamp01(num + 0.2f), num, num));
			val3.transform.localPosition = new Vector3(0f, -0.5f, 0.25f);
			val3.transform.localRotation = Quaternion.identity;
			val3.transform.localScale = new Vector3(5f, 5f, 5f);
			__instance.colliders = ((Component)__instance).gameObject.GetComponentsInChildren<Collider>();
			Plugin.Log.LogInfo((object)("Colliders: " + __instance.colliders.Length));
			if ((int)__instance.itemState == 2)
			{
				(byte, BackpackReference) value = __instance.backpackReference.Value;
				if (((BackpackReference)(ref value.Item2)).IsOnMyBack())
				{
					MeshRenderer[] componentsInChildren3 = ((Component)__instance).gameObject.GetComponentsInChildren<MeshRenderer>();
					foreach (MeshRenderer val4 in componentsInChildren3)
					{
						((Renderer)val4).enabled = false;
					}
				}
			}
			if ((int)__instance.itemState == 2)
			{
				Collider[] componentsInChildren4 = ((Component)__instance).gameObject.GetComponentsInChildren<Collider>();
				foreach (Collider val5 in componentsInChildren4)
				{
					val5.enabled = false;
				}
			}
		}

		[HarmonyPatch(typeof(ItemUIData), "GetIcon")]
		[HarmonyPostfix]
		public static void Item_GetIcon(ItemUIData __instance, ref Texture2D __result)
		{
			Plugin.Log.LogInfo((object)("Getting item name:" + __instance.itemName));
			if (__instance.itemName == "Bing Bong")
			{
				__result = Plugin.MochiTexture;
			}
		}

		[HarmonyPatch(typeof(ItemCooking), "UpdateCookedBehavior")]
		[HarmonyPostfix]
		public static void Item_SetCookedAmount(ItemCooking __instance)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			if (((Object)((ItemComponent)__instance).item).name.Contains("BingBong"))
			{
				float num = 1f - (float)((ItemComponent)__instance).item.GetData<IntItemData>((DataEntryKey)1).Value * 0.2f;
				MeshRenderer[] componentsInChildren = ((Component)__instance).gameObject.GetComponentsInChildren<MeshRenderer>();
				foreach (MeshRenderer val in componentsInChildren)
				{
					((Renderer)val).materials[0].SetColor("_BaseColor", new Color(Mathf.Clamp01(num + 0.2f), num, num));
				}
			}
		}

		[HarmonyPatch("GetName")]
		[HarmonyPostfix]
		public static void Item_Name(Item __instance, ref string __result)
		{
			__result = (((Object)__instance).name.Contains("BingBong") ? "MOCHI" : __result);
		}

		[HarmonyPatch("HideRenderers")]
		[HarmonyPostfix]
		public static void Item_HideRendered(Item __instance)
		{
			Plugin.Log.LogInfo((object)("Hiding rendered item:" + ((Object)__instance).name));
			if (((Object)__instance).name.Contains("BingBong"))
			{
				MeshRenderer[] componentsInChildren = ((Component)__instance).gameObject.GetComponentsInChildren<MeshRenderer>();
				foreach (MeshRenderer val in componentsInChildren)
				{
					((Renderer)val).enabled = false;
				}
			}
		}
	}
	[BepInPlugin("com.github.FelineEntity.BingBingToMochi", "BingBongToMochi", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static Harmony Harmony = new Harmony("com.github.FelineEntity.BingBingToMochi");

		public const string Id = "com.github.FelineEntity.BingBingToMochi";

		internal static ManualLogSource Log { get; private set; } = null;


		internal static Plugin Instance { get; private set; } = null;


		internal static AssetBundle Bundle { get; private set; } = null;


		internal static GameObject MochiPrefab { get; private set; } = null;


		internal static Material MochiMaterial { get; private set; } = null;


		internal static Texture2D MochiTexture { get; private set; } = null;


		public static string Name => "BingBongToMochi";

		public static string Version => "0.1.0";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
			Harmony.PatchAll(Assembly.GetExecutingAssembly());
			LoadAssets();
		}

		private void LoadAssets()
		{
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "mochipeak");
			Bundle = AssetBundle.LoadFromFile(text);
			MochiPrefab = Bundle.LoadAsset<GameObject>("Assets/Models/Mochi/mochiThrowablePrefab.prefab");
			MochiMaterial = Bundle.LoadAsset<Material>("Assets/Models/Mochi/Mochi.mat");
			MochiTexture = Bundle.LoadAsset<Texture2D>("Assets/Models/Mochi/mochistand.png");
			if ((Object)(object)MochiPrefab == (Object)null)
			{
				Log.LogInfo((object)"Mochi prefab loading failed. :(");
				return;
			}
			Log.LogInfo((object)"Mochi prefab loaded successfully!");
			Object.Instantiate<GameObject>(MochiPrefab);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}