Decompiled source of LivePeppinoReaction v1.1.0

doomahreal.ultrakill.livepeppinoreaction/LivePeppinoReaction.dll

Decompiled 2 months ago
using System;
using System.Collections;
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 Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("LivePeppinoReaction")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LivePeppinoReaction")]
[assembly: AssemblyTitle("LivePeppinoReaction")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LivePeppinoReaction
{
	[BepInPlugin("doomahreal.ultrakill.livepeppinoreaction", "Live Peppino Reaction", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private GameObject peppinoPrefab;

		private int transformChangeCount = 0;

		private int currentRankIndex = -1;

		private Vector3 lastPosition;

		private Quaternion lastRotation;

		private Vector3 lastScale;

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Live Peppino Reaction plugin loaded.");
			LoadPeppinoPrefab();
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void LoadPeppinoPrefab()
		{
			AssetBundle val = LoadPeppinoBundle();
			if ((Object)(object)val != (Object)null)
			{
				peppinoPrefab = val.LoadAsset<GameObject>("peppinoreaction");
				if ((Object)(object)peppinoPrefab == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load 'peppinoreaction' prefab from the asset bundle.");
					return;
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)"'peppinoreaction' prefab loaded successfully from the asset bundle.");
				SetLayerRecursively(peppinoPrefab.transform, LayerMask.NameToLayer("AlwaysOnTop"));
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load asset bundle. 'peppinoreaction' prefab cannot be loaded.");
			}
		}

		private void SetLayerRecursively(Transform obj, int layer)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			((Component)obj).gameObject.layer = layer;
			foreach (Transform item in obj)
			{
				Transform obj2 = item;
				SetLayerRecursively(obj2, layer);
			}
		}

		private AssetBundle LoadPeppinoBundle()
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string name = "LivePeppinoReaction.peppino.bundle";
			using Stream stream = executingAssembly.GetManifestResourceStream(name);
			if (stream == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load peppino.bundle from embedded resources.");
				return null;
			}
			AssetBundle val = AssetBundle.LoadFromStream(stream);
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load peppino.bundle from embedded resources.");
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"peppino.bundle loaded successfully from embedded resources.");
			}
			return val;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			if (((Scene)(ref scene)).buildIndex != 0 && !(((Scene)(ref scene)).name == "241a6a8caec7a13438a5ee786040de32") && !(((Scene)(ref scene)).name == "b3e7f2f8052488a45b35549efb98d902") && ((Scene)(ref scene)).IsValid() && (Object)(object)peppinoPrefab != (Object)null)
			{
				GameObject val = Object.Instantiate<GameObject>(peppinoPrefab);
				GameObject val2 = GameObject.Find("Player/Main Camera/HUD Camera/HUD/GunCanvas");
				if ((Object)(object)val2 != (Object)null)
				{
					val.transform.position = val2.transform.position;
					ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
					Vector3 position = val.transform.position;
					logger.LogInfo((object)("Position of peppino set to GunCanvas position: " + ((object)(Vector3)(ref position)).ToString()));
					val.transform.parent = val2.transform;
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Peppino set as child of GunCanvas.");
					ApplyTransformChanges(val.transform);
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"GunCanvas not found in the scene. Failed to position the prefab.");
				}
			}
		}

		private void ApplyTransformChanges(Transform obj)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			obj.localScale = new Vector3(1.5f, 1.5f, 1.5f);
			obj.rotation = Quaternion.Euler(0f, 150.1f, 0f);
			obj.localPosition = new Vector3(700f, 600f, 0f);
			transformChangeCount++;
			if (transformChangeCount < 2)
			{
				ApplyTransformChanges(obj);
			}
		}

		private void Update()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "b3e7f2f8052488a45b35549efb98d902" && ((Scene)(ref activeScene)).name != "241a6a8caec7a13438a5ee786040de32" && ((Scene)(ref activeScene)).buildIndex != 0)
			{
				int rankIndex = MonoSingleton<StyleHUD>.Instance.rankIndex;
				if (rankIndex != currentRankIndex)
				{
					currentRankIndex = rankIndex;
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Current Rank Index: " + currentRankIndex));
					ActivateChildrenBasedOnRankIndex(currentRankIndex);
				}
				GameObject val = GameObject.Find("peppinoreaction(Clone)");
				if ((Object)(object)val != (Object)null && HasTransformChanged(val.transform))
				{
					ApplyTransformChanges(val.transform);
				}
			}
		}

		private bool HasTransformChanged(Transform obj)
		{
			//IL_0002: 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)
			//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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			if (!(obj.localPosition != lastPosition))
			{
				Quaternion localRotation = obj.localRotation;
				if (!(Mathf.Abs(((Quaternion)(ref localRotation)).eulerAngles.x - 0f) > float.Epsilon))
				{
					localRotation = obj.localRotation;
					if (!(Mathf.Abs(((Quaternion)(ref localRotation)).eulerAngles.z - 0f) > float.Epsilon) && !(obj.localScale != lastScale))
					{
						return false;
					}
				}
			}
			lastPosition = obj.localPosition;
			lastRotation = obj.localRotation;
			lastScale = obj.localScale;
			return true;
		}

		private void ActivateChildrenBasedOnRankIndex(int rankIndex)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			GameObject val = GameObject.Find("peppinoreaction(Clone)");
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Instantiated peppinoPrefab not found in the scene.");
				return;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Found " + val.transform.childCount + " children of peppinoPrefab."));
			foreach (Transform item in val.transform)
			{
				Transform val2 = item;
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Child Name: " + ((Object)val2).name));
			}
			Transform val3 = val.transform.Find("static");
			if ((Object)(object)val3 != (Object)null)
			{
				((Component)val3).gameObject.SetActive(true);
				((MonoBehaviour)this).StartCoroutine(DeactivateAfterDelay(((Component)val3).gameObject, 0.75f));
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Static child not found in peppinoPrefab.");
			}
			((MonoBehaviour)this).StartCoroutine(ActivateChildAfterDelay(val, rankIndex));
		}

		private IEnumerator ActivateChildAfterDelay(GameObject instantiatedPeppino, int rankIndex)
		{
			yield return (object)new WaitForSeconds(0.75f);
			foreach (Transform item in instantiatedPeppino.transform)
			{
				Transform child = item;
				((Component)child).gameObject.SetActive(false);
			}
			Transform tvBackground = instantiatedPeppino.transform.Find("tv_background");
			if ((Object)(object)tvBackground != (Object)null)
			{
				((Component)tvBackground).gameObject.SetActive(true);
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"tv_background child not found in peppinoPrefab.");
			}
			switch (rankIndex)
			{
			case 0:
				((Component)instantiatedPeppino.transform.Find("idle 1")).gameObject.SetActive(true);
				break;
			case 1:
				((Component)instantiatedPeppino.transform.Find("destructive")).gameObject.SetActive(true);
				((Component)instantiatedPeppino.transform.Find("idle 1")).gameObject.SetActive(false);
				break;
			case 2:
				((Component)instantiatedPeppino.transform.Find("destructive")).gameObject.SetActive(false);
				((Component)instantiatedPeppino.transform.Find("brutal")).gameObject.SetActive(true);
				break;
			case 3:
				((Component)instantiatedPeppino.transform.Find("brutal")).gameObject.SetActive(false);
				((Component)instantiatedPeppino.transform.Find("anarchic")).gameObject.SetActive(true);
				break;
			case 4:
				((Component)instantiatedPeppino.transform.Find("anarchic")).gameObject.SetActive(false);
				((Component)instantiatedPeppino.transform.Find("supreme")).gameObject.SetActive(true);
				break;
			case 5:
				((Component)instantiatedPeppino.transform.Find("supreme")).gameObject.SetActive(false);
				((Component)instantiatedPeppino.transform.Find("sadistic")).gameObject.SetActive(true);
				break;
			case 6:
				((Component)instantiatedPeppino.transform.Find("sadistic")).gameObject.SetActive(false);
				((Component)instantiatedPeppino.transform.Find("shitstorm")).gameObject.SetActive(true);
				break;
			case 7:
				((Component)instantiatedPeppino.transform.Find("shitstorm")).gameObject.SetActive(false);
				((Component)instantiatedPeppino.transform.Find("ultrakill")).gameObject.SetActive(true);
				break;
			}
		}

		private IEnumerator DeactivateAfterDelay(GameObject gameObject, float delay)
		{
			yield return (object)new WaitForSeconds(delay);
			gameObject.SetActive(false);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LivePeppinoReaction";

		public const string PLUGIN_NAME = "LivePeppinoReaction";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}