Decompiled source of DestroyBingBong v1.0.0

plugins/com.github.serycodes.DestroyBingBong.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Zorro.Core;

[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("com.github.serycodes.DestroyBingBong")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("com.github.serycodes.DestroyBingBong")]
[assembly: AssemblyTitle("DestroyBingBong")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 DestroyBingBong
{
	[BepInPlugin("com.github.serycodes.DestroyBingBong", "DestroyBingBong", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private bool alreadyLoaded;

		public const string Id = "com.github.serycodes.DestroyBingBong";

		public static string Name => "DestroyBingBong";

		public static string Version => "1.0.0";

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin DestroyBingBong is loaded!");
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			SceneManager.sceneLoaded += OnSceneLoaded;
			LocalizationFix();
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode _)
		{
			if (!alreadyLoaded)
			{
				Logger.LogInfo((object)"Loaded the item Database");
				alreadyLoaded = true;
				ItemDatabase instance = SingletonAsset<ItemDatabase>.Instance;
				TweakItemValues(instance);
			}
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private static void TweakItemValues(ItemDatabase itemDatabase)
		{
			foreach (KeyValuePair<ushort, Item> item in itemDatabase.itemLookup)
			{
				Item value = item.Value;
				if (((Object)value).name == "BingBong")
				{
					Action_Consume val = ((Component)value).GetComponent<Action_Consume>();
					if ((Object)(object)val == (Object)null)
					{
						val = ((Component)value).gameObject.AddComponent<Action_Consume>();
					}
					((ItemAction)val).OnCastFinished = true;
					value.usingTimePrimary = 2f;
					value.UIData.hasMainInteract = true;
					value.UIData.mainInteractPrompt = "ACTION_DESTROYBINGBONG";
					ItemUseFeedback val2 = ((Component)value).GetComponent<ItemUseFeedback>();
					if ((Object)(object)val2 == (Object)null)
					{
						val2 = ((Component)value).gameObject.AddComponent<ItemUseFeedback>();
					}
					val2.useAnimation = "Eat";
					SFX_Instance[] array = Resources.FindObjectsOfTypeAll<SFX_Instance>();
					SFX_Instance val3 = Array.Find(array, (SFX_Instance sfx) => ((Object)sfx).name == "SFXI BingBong 2");
					if ((Object)(object)val3 != (Object)null)
					{
						SFX_Instance val4 = Object.Instantiate<SFX_Instance>(val3);
						val4.settings.volume = 100f;
						val2.sfxUsed = val4;
						Logger.LogInfo((object)("Found, cloned, and assigned SFX: " + ((Object)val3).name + " with volume set to 100"));
					}
					else
					{
						Logger.LogWarning((object)"Could not find SFXI BingBong 2");
					}
					Action_PlayAnimation val5 = ((Component)value).GetComponent<Action_PlayAnimation>();
					if ((Object)(object)val5 == (Object)null)
					{
						val5 = ((Component)value).gameObject.AddComponent<Action_PlayAnimation>();
					}
					val5.animationName = "PlayerEat";
					((ItemAction)val5).OnPressed = true;
					Action_DestroyBingBong action_DestroyBingBong = ((Component)value).GetComponent<Action_DestroyBingBong>();
					if ((Object)(object)action_DestroyBingBong == (Object)null)
					{
						action_DestroyBingBong = ((Component)value).gameObject.AddComponent<Action_DestroyBingBong>();
					}
					((ItemAction)action_DestroyBingBong).OnConsumed = true;
					Action_BingBongCastingEffects action_BingBongCastingEffects = ((Component)value).GetComponent<Action_BingBongCastingEffects>();
					if ((Object)(object)action_BingBongCastingEffects == (Object)null)
					{
						action_BingBongCastingEffects = ((Component)value).gameObject.AddComponent<Action_BingBongCastingEffects>();
					}
					((ItemAction)action_BingBongCastingEffects).OnPressed = true;
					((ItemAction)action_BingBongCastingEffects).OnCastFinished = true;
					((ItemAction)action_BingBongCastingEffects).OnCancelled = true;
				}
			}
		}

		private void LocalizationFix()
		{
			LocalizedText.mainTable["ACTION_DESTROYBINGBONG"] = new List<string>(1) { "DESTROY" };
		}
	}
	public class Action_DestroyBingBong : ItemAction
	{
		private bool hasTriggered;

		public override void RunAction()
		{
			Plugin.Logger.LogInfo((object)"Action_DestroyBingBong: RunAction called");
			if (!hasTriggered)
			{
				SpawnDestroyedParts();
				hasTriggered = true;
			}
		}

		private void SpawnDestroyedParts()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Logger.LogInfo((object)"Action_DestroyBingBong: Starting to spawn parts");
			Vector3 position = ((Component)this).transform.position;
			Plugin.Logger.LogInfo((object)$"Action_DestroyBingBong: Spawn position: {position}");
			Transform val = null;
			Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>();
			foreach (Transform val2 in componentsInChildren)
			{
				if (((Object)val2).name == "Bing Bong Plush")
				{
					Plugin.Logger.LogInfo((object)("Action_DestroyBingBong: Found Bing Bong Plush: " + ((Object)val2).name));
					val = val2;
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogInfo((object)"Action_DestroyBingBong: 'Bing Bong Plush' not found");
				return;
			}
			Plugin.Logger.LogInfo((object)$"Action_DestroyBingBong: Bing Bong Plush has {val.childCount} children");
			for (int j = 0; j < val.childCount; j++)
			{
				Transform child = val.GetChild(j);
				Plugin.Logger.LogInfo((object)("Action_DestroyBingBong: Spawning part: " + ((Object)child).name));
				SpawnPart(child, position);
			}
			Plugin.Logger.LogInfo((object)"Action_DestroyBingBong: Finished spawning parts");
		}

		private void SpawnPart(Transform originalPart, Vector3 spawnPosition)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(((Component)originalPart).gameObject, spawnPosition, originalPart.rotation);
			if ((Object)(object)val.GetComponent<MeshCollider>() == (Object)null)
			{
				BoxCollider val2 = val.AddComponent<BoxCollider>();
				Plugin.Logger.LogInfo((object)("Action_DestroyBingBong: Added BoxCollider for " + ((Object)originalPart).name));
			}
			Rigidbody component = val.GetComponent<Rigidbody>();
			if ((Object)(object)component == (Object)null)
			{
				component = val.AddComponent<Rigidbody>();
			}
		}
	}
	public class Action_BingBongCastingEffects : ItemAction
	{
		private bool effectsActive;

		private float castStartTime;

		private Camera? playerCamera;

		private Vector3 originalCameraPosition;

		private Quaternion originalCameraRotation;

		private GameObject? redOverlay;

		private Image? redImage;

		public override void RunAction()
		{
			if (base.OnPressed && !effectsActive)
			{
				StartCastingEffects();
			}
			else if ((base.OnCastFinished || base.OnCancelled) && effectsActive)
			{
				StopCastingEffects();
			}
		}

		private void StartCastingEffects()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Logger.LogInfo((object)"Action_BingBongCastingEffects: Starting casting effects");
			effectsActive = true;
			castStartTime = Time.time;
			playerCamera = Camera.main;
			if ((Object)(object)playerCamera == (Object)null)
			{
				playerCamera = Object.FindFirstObjectByType<Camera>();
			}
			if ((Object)(object)playerCamera != (Object)null)
			{
				originalCameraPosition = ((Component)playerCamera).transform.position;
				originalCameraRotation = ((Component)playerCamera).transform.rotation;
			}
			CreateRedOverlay();
			((MonoBehaviour)this).StartCoroutine(CastingEffectsCoroutine());
		}

		private void CreateRedOverlay()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			redOverlay = new GameObject("BingBongRedOverlay");
			Canvas val = redOverlay.AddComponent<Canvas>();
			val.renderMode = (RenderMode)0;
			val.sortingOrder = 1000;
			redOverlay.AddComponent<CanvasScaler>();
			redOverlay.AddComponent<GraphicRaycaster>();
			GameObject val2 = new GameObject("RedImage");
			val2.transform.SetParent(redOverlay.transform, false);
			redImage = val2.AddComponent<Image>();
			((Graphic)redImage).color = new Color(1f, 0f, 0f, 0f);
			RectTransform component = val2.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			Plugin.Logger.LogInfo((object)"Action_BingBongCastingEffects: Created red overlay");
		}

		private IEnumerator CastingEffectsCoroutine()
		{
			float castDuration = ((ItemActionBase)this).item.usingTimePrimary;
			Vector3 val = default(Vector3);
			Color color = default(Color);
			while (effectsActive && Time.time - castStartTime < castDuration)
			{
				float num = (Time.time - castStartTime) / castDuration;
				if ((Object)(object)playerCamera != (Object)null)
				{
					float num2 = num * 0.1f;
					((Vector3)(ref val))..ctor(Random.Range(0f - num2, num2), Random.Range(0f - num2, num2), 0f);
					((Component)playerCamera).transform.position = originalCameraPosition + val;
				}
				if ((Object)(object)redImage != (Object)null)
				{
					float num3 = 0.3f;
					((Color)(ref color))..ctor(1f, 0f, 0f, num * num3);
					((Graphic)redImage).color = color;
				}
				yield return null;
			}
			StopCastingEffects();
		}

		private void StopCastingEffects()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Logger.LogInfo((object)"Action_BingBongCastingEffects: Stopping casting effects");
			effectsActive = false;
			if ((Object)(object)playerCamera != (Object)null)
			{
				((Component)playerCamera).transform.position = originalCameraPosition;
				((Component)playerCamera).transform.rotation = originalCameraRotation;
			}
			if ((Object)(object)redOverlay != (Object)null)
			{
				Object.Destroy((Object)(object)redOverlay);
				redOverlay = null;
				redImage = null;
			}
		}

		private void OnDestroy()
		{
			StopCastingEffects();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.github.serycodes.DestroyBingBong";

		public const string PLUGIN_NAME = "com.github.serycodes.DestroyBingBong";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}