Decompiled source of Dual Wield Skill v2.0.0

plugins/Dual Wield Skill.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Configgy;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Ultrakill Dual Wield Skill Mod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Ultrakill Dual Wield Skill Mod")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("118d6cb8-6e15-4c1e-8f93-e0833b89ea40")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DualWieldSkill;

[BepInPlugin("com.ReFraX.ultrakill.dualwieldskill", "Dual Wield Skill", "2.0.0")]
public class DualWieldMod : BaseUnityPlugin
{
	private ConfigEntry<float> cooldownConfig;

	private ConfigEntry<float> powerUpDurationConfig;

	[Configgable("", "Activate Dual-Wield", 0, null)]
	public static ConfigKeybind inputKeyConfig = new ConfigKeybind((KeyCode)98);

	private float nextUseTime = 0f;

	private Image activeIcon;

	private Image inactiveIcon;

	private Text cooldownText;

	private Text timerText;

	private Font customFont;

	private Canvas uiCanvas;

	private void Awake()
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Expected O, but got Unknown
		cooldownConfig = ((BaseUnityPlugin)this).Config.Bind<float>("", "Cooldown Time", 120f, "Cooldown time in seconds for the dual-wield power-up.");
		powerUpDurationConfig = ((BaseUnityPlugin)this).Config.Bind<float>("", "Power-Up Duration", 30f, "Duration in seconds for the dual-wield power-up.");
		ConfigBuilder val = new ConfigBuilder("Dual Wield Skill", (string)null);
		val.BuildAll();
		customFont = Resources.GetBuiltinResource<Font>("Arial.ttf");
	}

	private void CreateUICanvas()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("DualWieldCanvas");
		uiCanvas = val.AddComponent<Canvas>();
		uiCanvas.renderMode = (RenderMode)0;
		CanvasScaler val2 = val.AddComponent<CanvasScaler>();
		val2.uiScaleMode = (ScaleMode)1;
		val2.referenceResolution = new Vector2(1920f, 1080f);
		val2.screenMatchMode = (ScreenMatchMode)0;
		val2.matchWidthOrHeight = 0.5f;
		val.AddComponent<GraphicRaycaster>();
		Object.DontDestroyOnLoad((Object)(object)val);
	}

	private void Start()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Expected O, but got Unknown
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Expected O, but got Unknown
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Expected O, but got Unknown
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Expected O, but got Unknown
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_0330: Unknown result type (might be due to invalid IL or missing references)
		//IL_0347: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_035e: Expected O, but got Unknown
		//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0404: Unknown result type (might be due to invalid IL or missing references)
		//IL_041b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0432: Unknown result type (might be due to invalid IL or missing references)
		CreateUICanvas();
		GameObject val = new GameObject("CooldownUI");
		val.transform.SetParent(((Component)uiCanvas).transform, false);
		try
		{
			Sprite sprite = LoadEmbeddedResource("Dual_Wield_Skill.Assets.Dual Wield Skill Icon.png");
			Sprite sprite2 = LoadEmbeddedResource("Dual_Wield_Skill.Assets.Dual Wield Skill Icon Inactive.png");
			GameObject val2 = new GameObject("UIContainer");
			val2.transform.SetParent(val.transform, false);
			RectTransform val3 = val2.AddComponent<RectTransform>();
			val3.anchorMin = new Vector2(0f, 1f);
			val3.anchorMax = new Vector2(0f, 1f);
			val3.pivot = new Vector2(0f, 1f);
			val3.anchoredPosition = new Vector2(-900f, 550f);
			val3.sizeDelta = new Vector2(150f, 150f);
			GameObject val4 = new GameObject("InactiveIcon");
			val4.transform.SetParent(val2.transform, false);
			inactiveIcon = val4.AddComponent<Image>();
			inactiveIcon.sprite = sprite2;
			inactiveIcon.type = (Type)0;
			inactiveIcon.preserveAspect = true;
			GameObject val5 = new GameObject("ActiveIcon");
			val5.transform.SetParent(val2.transform, false);
			activeIcon = val5.AddComponent<Image>();
			activeIcon.sprite = sprite;
			activeIcon.type = (Type)3;
			activeIcon.fillMethod = (FillMethod)4;
			activeIcon.fillOrigin = 2;
			activeIcon.fillClockwise = true;
			activeIcon.preserveAspect = true;
			RectTransform[] array = (RectTransform[])(object)new RectTransform[2]
			{
				((Component)inactiveIcon).GetComponent<RectTransform>(),
				((Component)activeIcon).GetComponent<RectTransform>()
			};
			foreach (RectTransform val6 in array)
			{
				val6.anchorMin = new Vector2(0f, 1f);
				val6.anchorMax = new Vector2(0f, 1f);
				val6.pivot = new Vector2(0f, 1f);
				val6.anchoredPosition = Vector2.zero;
				val6.sizeDelta = new Vector2(100f, 100f);
			}
			GameObject val7 = new GameObject("SkillText");
			val7.transform.SetParent(val2.transform, false);
			cooldownText = val7.AddComponent<Text>();
			cooldownText.font = customFont;
			cooldownText.fontSize = 18;
			((Graphic)cooldownText).color = Color.white;
			cooldownText.alignment = (TextAnchor)0;
			cooldownText.text = "Dual Wield Skill";
			RectTransform component = ((Component)cooldownText).GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(0f, 1f);
			component.pivot = new Vector2(0f, 1f);
			component.anchoredPosition = new Vector2(0f, -105f);
			component.sizeDelta = new Vector2(150f, 30f);
			GameObject val8 = new GameObject("TimerText");
			val8.transform.SetParent(val2.transform, false);
			timerText = val8.AddComponent<Text>();
			timerText.font = customFont;
			timerText.fontSize = 24;
			((Graphic)timerText).color = Color.yellow;
			timerText.alignment = (TextAnchor)4;
			RectTransform component2 = ((Component)timerText).GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0f, 1f);
			component2.anchorMax = new Vector2(0f, 1f);
			component2.pivot = new Vector2(0f, 1f);
			component2.anchoredPosition = new Vector2(0f, -40f);
			component2.sizeDelta = new Vector2(100f, 30f);
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("Error setting up UI: " + ex.ToString()));
		}
	}

	private Sprite LoadEmbeddedResource(string resourceName)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		using Stream stream = executingAssembly.GetManifestResourceStream(resourceName);
		if (stream == null)
		{
			Debug.LogError((object)("Resource not found: " + resourceName));
			return null;
		}
		byte[] array = new byte[stream.Length];
		stream.Read(array, 0, array.Length);
		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));
	}

	private void Update()
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)activeIcon) && Object.op_Implicit((Object)(object)inactiveIcon) && Object.op_Implicit((Object)(object)timerText))
		{
			if (Input.GetKeyDown(((ConfigValueElement<KeyCode>)(object)inputKeyConfig).Value) && Time.time >= nextUseTime)
			{
				ActivateDualWield();
				nextUseTime = Time.time + cooldownConfig.Value;
			}
			float num = Mathf.Max(0f, nextUseTime - Time.time);
			if (num > 0f)
			{
				activeIcon.fillAmount = (cooldownConfig.Value - num) / cooldownConfig.Value;
				((Component)inactiveIcon).gameObject.SetActive(true);
				timerText.text = $"{num:F1}s";
			}
			else
			{
				activeIcon.fillAmount = 1f;
				((Component)inactiveIcon).gameObject.SetActive(false);
				timerText.text = "Ready!";
			}
		}
	}

	private void ActivateDualWield()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: 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)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: 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)
		if (Object.op_Implicit((Object)(object)MonoSingleton<GunControl>.Instance))
		{
			GameObject val = new GameObject();
			val.transform.SetParent(((Component)MonoSingleton<GunControl>.Instance).transform, true);
			val.transform.localRotation = Quaternion.identity;
			DualWield[] componentsInChildren = ((Component)MonoSingleton<GunControl>.Instance).GetComponentsInChildren<DualWield>();
			if (componentsInChildren != null && componentsInChildren.Length % 2 == 0)
			{
				val.transform.localScale = new Vector3(-1f, 1f, 1f);
			}
			else
			{
				val.transform.localScale = Vector3.one;
			}
			if (componentsInChildren == null || componentsInChildren.Length == 0)
			{
				val.transform.localPosition = Vector3.zero;
			}
			else if (componentsInChildren.Length % 2 == 0)
			{
				val.transform.localPosition = new Vector3((float)(componentsInChildren.Length / 2) * -1.5f, 0f, 0f);
			}
			else
			{
				val.transform.localPosition = new Vector3((float)((componentsInChildren.Length + 1) / 2) * 1.5f, 0f, 0f);
			}
			DualWield val2 = val.AddComponent<DualWield>();
			val2.delay = 0.05f;
			val2.juiceAmount = powerUpDurationConfig.Value;
			if (componentsInChildren != null && componentsInChildren.Length != 0)
			{
				val2.delay += (float)componentsInChildren.Length / 20f;
			}
		}
	}
}