Decompiled source of BurgerKingSongPopup v1.2.0

BurgerKingSongPopup.dll

Decompiled 5 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Fields;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;

[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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BurgerKingSongPopup")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BurgerKingSongPopup")]
[assembly: AssemblyTitle("BurgerKingSongPopup")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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 BurgerKingSongPopup
{
	[BepInPlugin("com.scoutisdelicious.burgerkingsongpopup", "Burger King Song Popup", "1.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Class1 : BaseUnityPlugin
	{
		public const string PluginGuid = "com.scoutisdelicious.burgerkingsongpopup";

		public const string PluginName = "Burger King Song Popup";

		public const string PluginVersion = "1.2.0";

		internal static ManualLogSource Log;

		public static PluginConfigurator config;

		public static BoolField modEnabled;

		public static BoolField loopVideo;

		public static IntField videoCount;

		public static FloatSliderField videoAlpha;

		public static IntField maxVideosOnScreen;

		public static FloatSliderField videoScale;

		public static int activeVideoCount;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			new Harmony("com.scoutisdelicious.burgerkingsongpopup").PatchAll();
			SetupConfig();
			Log.LogMessage((object)"The Burger King has been summoned...");
		}

		private void SetupConfig()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Expected O, but got Unknown
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Expected O, but got Unknown
			config = PluginConfigurator.Create("Burger King Song Popup", "com.scoutisdelicious.burgerkingsongpopup");
			Sprite val = LoadIcon("icon.png");
			if ((Object)(object)val != (Object)null)
			{
				config.image = val;
			}
			modEnabled = new BoolField(config.rootPanel, "Mod Enabled", "modEnabled", true);
			loopVideo = new BoolField(config.rootPanel, "Loop Video", "loopVideo", true);
			videoCount = new IntField(config.rootPanel, "Popups Per Hit", "videoCount", 1, 1, 200);
			videoScale = new FloatSliderField(config.rootPanel, "Scale", "videoScale", new Tuple<float, float>(0.05f, 1f), 0.25f, 2);
			videoAlpha = new FloatSliderField(config.rootPanel, "Alpha", "videoAlpha", new Tuple<float, float>(0f, 1f), 1f, 2);
			maxVideosOnScreen = new IntField(config.rootPanel, "Max Videos On Screen (0 = Infinite)", "maxVideos", 0, 0, 9999999);
		}

		private Sprite LoadIcon(string fileName)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), fileName);
			if (!File.Exists(path))
			{
				return null;
			}
			byte[] array = File.ReadAllBytes(path);
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, array);
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}

		public static void SpawnVideoPopup()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Expected O, but got Unknown
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string text = Path.Combine(directoryName, "burgerking.mp4");
			if (!File.Exists(text))
			{
				Log.LogError((object)"you forgot the video dumbass or it isnt an mp4 or its mispelled");
				return;
			}
			GameObject popupRoot = new GameObject("BK_VideoPopup");
			popupRoot.AddComponent<VideoPopupTracker>();
			activeVideoCount++;
			Canvas val = popupRoot.AddComponent<Canvas>();
			val.renderMode = (RenderMode)0;
			val.sortingOrder = 9999;
			GameObject videoObj = new GameObject("VideoFrame");
			videoObj.transform.SetParent(popupRoot.transform, false);
			RawImage rawImage = videoObj.AddComponent<RawImage>();
			VideoPlayer val2 = videoObj.AddComponent<VideoPlayer>();
			((Graphic)rawImage).color = new Color(1f, 1f, 1f, videoAlpha.value);
			((Behaviour)rawImage).enabled = false;
			val2.source = (VideoSource)1;
			val2.url = text;
			val2.audioOutputMode = (VideoAudioOutputMode)2;
			val2.isLooping = loopVideo.value;
			val2.prepareCompleted += (EventHandler)delegate(VideoPlayer vp)
			{
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Expected O, but got Unknown
				//IL_007b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f6: Expected O, but got Unknown
				int width = (int)vp.width;
				int height = (int)vp.height;
				RenderTexture rt = new RenderTexture(width, height, 0);
				vp.targetTexture = rt;
				rawImage.texture = (Texture)(object)rt;
				RectTransform component = videoObj.GetComponent<RectTransform>();
				float num = (float)Screen.height * videoScale.value;
				float num2 = (float)width / (float)height;
				float num3 = num * num2;
				component.sizeDelta = new Vector2(num3, num);
				component.pivot = Vector2.zero;
				component.anchorMin = Vector2.zero;
				component.anchorMax = Vector2.zero;
				float num4 = Random.Range(0f, (float)Screen.width - num3);
				float num5 = Random.Range(0f, (float)Screen.height - num);
				component.anchoredPosition = new Vector2(num4, num5);
				vp.loopPointReached += (EventHandler)delegate
				{
					if (!loopVideo.value)
					{
						rt.Release();
						Object.Destroy((Object)(object)popupRoot);
					}
				};
				((Behaviour)rawImage).enabled = true;
				vp.Play();
			};
			val2.Prepare();
		}
	}
	internal class VideoPopupTracker : MonoBehaviour
	{
		private void OnDestroy()
		{
			Class1.activeVideoCount--;
		}
	}
	[HarmonyPatch(typeof(NewMovement), "GetHurt")]
	internal static class Patch_NewMovement_GetHurt
	{
		private static void Prefix(NewMovement __instance, out int __state)
		{
			__state = __instance.hp;
		}

		private static void Postfix(NewMovement __instance, int __state)
		{
			if (Class1.modEnabled == null || !Class1.modEnabled.value || __instance.hp >= __state || __instance.hp <= 0)
			{
				return;
			}
			int value = Class1.videoCount.value;
			for (int i = 0; i < value; i++)
			{
				if (Class1.maxVideosOnScreen.value > 0 && Class1.activeVideoCount >= Class1.maxVideosOnScreen.value)
				{
					break;
				}
				Class1.SpawnVideoPopup();
			}
		}
	}
}