Decompiled source of ParryImages v1.3.0

plugins/ParryImages.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using Configgy;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ParryImages")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ParryImages")]
[assembly: AssemblyCopyright("Copyright © Nobody 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d6025689-10a2-4e6f-b98a-6e2aa6442186")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.1.0.0")]
[BepInPlugin("com.harryzawg.UltraKill.ParryImages", "ParryImages", "1.3.0")]
public class ParryImages : BaseUnityPlugin
{
	[HarmonyPatch(typeof(TimeController), "ParryFlash")]
	private static class ReplaceParryFlash
	{
		[CompilerGenerated]
		private sealed class <CheckIfParry>d__1 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <CheckIfParry>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Expected O, but got Unknown
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: 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_0093: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitUntil((Func<bool>)(() => Time.timeScale == 0f));
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					Transform arm = GetArm();
					if ((Object)(object)arm == (Object)null)
					{
						return false;
					}
					Vector3 localEulerAngles = arm.localEulerAngles;
					if (((ConfigValueElement<bool>)(object)DebugToggle).Value)
					{
						((BaseUnityPlugin)Instance).Logger.LogInfo((object)$"[ParryImages] UA rotation (timestop): x={localEulerAngles.x:F2}, y={localEulerAngles.y:F2}, z={localEulerAngles.z:F2}");
					}
					if (IsArmRotationOkay(localEulerAngles))
					{
						if (((ConfigValueElement<bool>)(object)DebugToggle).Value)
						{
							((BaseUnityPlugin)Instance).Logger.LogInfo((object)"[ParryImages] No parry, skipping image");
						}
						return false;
					}
					if (LoadedImages.Count > 0)
					{
						CurrentImg = LoadedImages[Random.Range(0, LoadedImages.Count)];
					}
					else
					{
						CurrentImg = null;
					}
					Show = true;
					ImgOpacity = ((ConfigValueElement<float>)(object)OpacitySlider).Value;
					string value = ((ConfigValueElement<string>)(object)ParryDisplayMode).Value;
					if (value == "Flash")
					{
						<>2__current = Hide(0.25f);
						<>1__state = 2;
						return true;
					}
					if (value == "Fade Out")
					{
						<>2__current = FadeOut();
						<>1__state = 3;
						return true;
					}
					break;
				}
				case 2:
					<>1__state = -1;
					break;
				case 3:
					<>1__state = -1;
					break;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <FadeOut>d__5 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private float <StartOpacity>5__2;

			private float <FadeDir>5__3;

			private float <Timer>5__4;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <FadeOut>d__5(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<StartOpacity>5__2 = ImgOpacity;
					<FadeDir>5__3 = ((ConfigValueElement<float>)(object)FadeDurSlider).Value;
					<Timer>5__4 = 0f;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (<Timer>5__4 < <FadeDir>5__3)
				{
					<Timer>5__4 += Time.unscaledDeltaTime;
					ImgOpacity = Mathf.Lerp(<StartOpacity>5__2, 0f, <Timer>5__4 / <FadeDir>5__3);
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				ImgOpacity = 0f;
				Show = false;
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <Hide>d__4 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public float duration;

			private float <Timer>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Hide>d__4(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<Timer>5__2 = 0f;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (<Timer>5__2 < duration)
				{
					<Timer>5__2 += Time.unscaledDeltaTime;
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				Show = false;
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static bool Prefix(TimeController __instance)
		{
			__instance.parryFlashEnabled = false;
			__instance.TrueStop(0.25f);
			MonoSingleton<CameraController>.Instance.CameraShake(0.5f);
			MonoSingleton<RumbleManager>.Instance.SetVibration(RumbleProperties.ParryFlash);
			((MonoBehaviour)__instance).StartCoroutine(CheckIfParry());
			return false;
		}

		[IteratorStateMachine(typeof(<CheckIfParry>d__1))]
		private static IEnumerator CheckIfParry()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <CheckIfParry>d__1(0);
		}

		private static bool IsArmRotationOkay(Vector3 rot)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			float num = 0.2f;
			float num2 = rot.x % 360f;
			if (num2 < 0f)
			{
				num2 += 360f;
			}
			float num3 = rot.y % 360f;
			if (num3 < 0f)
			{
				num3 += 360f;
			}
			float num4 = rot.z % 360f;
			if (num4 < 0f)
			{
				num4 += 360f;
			}
			bool num5 = Mathf.Abs(Mathf.DeltaAngle(num2, 359.88f)) < num;
			bool flag = Mathf.Abs(Mathf.DeltaAngle(num3, 270.68f)) < num;
			bool flag2 = Mathf.Abs(Mathf.DeltaAngle(num4, 178.39f)) < num;
			return num5 && flag && flag2;
		}

		private static Transform GetArm()
		{
			GameObject val = GameObject.Find("Player");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			return FindArmature(val.transform);
			static Transform FindArmature(Transform t)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Expected O, but got Unknown
				foreach (Transform item in t)
				{
					Transform val2 = item;
					if (((Object)val2).name == "Arm Blue(Clone)")
					{
						Transform val3 = val2.Find("Feedbacker");
						if ((Object)(object)val3 == (Object)null)
						{
							return null;
						}
						Transform val4 = val3.Find("Armature");
						if ((Object)(object)val4 != (Object)null && val4.childCount > 0)
						{
							return val4.GetChild(0);
						}
					}
					Transform val5 = FindArmature(val2);
					if ((Object)(object)val5 != (Object)null)
					{
						return val5;
					}
				}
				return null;
			}
		}

		[IteratorStateMachine(typeof(<Hide>d__4))]
		private static IEnumerator Hide(float duration)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Hide>d__4(0)
			{
				duration = duration
			};
		}

		[IteratorStateMachine(typeof(<FadeOut>d__5))]
		private static IEnumerator FadeOut()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <FadeOut>d__5(0);
		}
	}

	private static List<Texture2D> LoadedImages = new List<Texture2D>();

	private static Texture2D CurrentImg;

	private static bool Show = false;

	private static float ImgOpacity = 0.6f;

	[Configgable("", "Enabled", 0, null)]
	private static ConfigToggle EnabledToggle = new ConfigToggle(true);

	[Configgable("Images", "Reload Images", 0, null)]
	public static ConfigButton ReloadButton = new ConfigButton((Action)ReloadImages, (string)null);

	[Configgable("Images", "Open ParryImages Folder", 0, null)]
	public static ConfigButton OpenImagesFolder = new ConfigButton((Action)delegate
	{
		string text = Path.Combine(Paths.PluginPath, "ParryImages");
		if (!Directory.Exists(text))
		{
			Directory.CreateDirectory(text);
			string path = Path.Combine(text, "Read-Me.txt");
			string contents = "Place any .jpg, .jpeg, .png, or .bmp in this folder, and when you parry it will flash your image on the screen\nOnce your images are in the folder, go into the Configgy settings and press Reload Images inside of Images to load your images into the game";
			File.WriteAllText(path, contents);
		}
		Application.OpenURL(text);
		((BaseUnityPlugin)Instance).Logger.LogInfo((object)("[ParryImages] Opening " + text));
	}, (string)null);

	[Configgable("Image Settings", "Effect", 0, null)]
	private static ConfigDropdown<string> ParryDisplayMode = new ConfigDropdown<string>(new string[2] { "Flash", "Fade Out" }, "Flash", (string[])null);

	[Configgable("Image Settings", "Fade Out Duration", 0, null)]
	private static FloatSlider FadeDurSlider = new FloatSlider(1.2f, 0.3f, 10f);

	[Configgable("Image Settings", "Opacity", 0, null)]
	private static FloatSlider OpacitySlider = new FloatSlider(0.6f, 0f, 1f);

	[Configgable("Other", "Debug", 0, null)]
	private static ConfigToggle DebugToggle = new ConfigToggle(false);

	public static ParryImages Instance { get; private set; }

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		LoadImages();
		new Harmony("com.harryzawg.UltraKill.ParryImages").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[ParryImages] ParryImages was loaded!");
		new ConfigBuilder("ParryImages", (string)null).BuildAll();
	}

	private void OnGUI()
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		if (((ConfigValueElement<bool>)(object)EnabledToggle).Value && Show && (Object)(object)CurrentImg != (Object)null)
		{
			if (((ConfigValueElement<string>)(object)ParryDisplayMode).Value == "Flash")
			{
				ImgOpacity = ((ConfigValueElement<float>)(object)OpacitySlider).Value;
			}
			GUI.color = new Color(1f, 1f, 1f, ImgOpacity);
			GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)CurrentImg);
			GUI.color = Color.white;
		}
	}

	private static void LoadImages()
	{
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Expected O, but got Unknown
		LoadedImages.Clear();
		string text = Path.Combine(Paths.PluginPath, "ParryImages");
		if (!Directory.Exists(text))
		{
			((BaseUnityPlugin)Instance).Logger.LogWarning((object)"[ParryImages] Could not find ParryImages Directory! Will create...");
			Directory.CreateDirectory(text);
			string path = Path.Combine(text, "Read-Me.txt");
			string contents = "Place any .jpg, .jpeg, .png, or .bmp in this folder, and when you parry it will flash your image on the screen\nOnce your images are in the folder, go into the Configgy settings and press Reload Images inside of Images to load your images into the game";
			File.WriteAllText(path, contents);
		}
		string[] array = (from f in Directory.GetFiles(text)
			where f.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".png", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase)
			select f).ToArray();
		foreach (string text2 in array)
		{
			try
			{
				byte[] array2 = File.ReadAllBytes(text2);
				Texture2D val = new Texture2D(2, 2);
				if (ImageConversion.LoadImage(val, array2))
				{
					LoadedImages.Add(val);
					if (((ConfigValueElement<bool>)(object)DebugToggle).Value)
					{
						((BaseUnityPlugin)Instance).Logger.LogInfo((object)("[ParryImages] Loaded " + Path.GetFileName(text2)));
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)Instance).Logger.LogWarning((object)("[ParryImages] Couldn't load image " + text2 + ": " + ex.Message));
			}
		}
		if (LoadedImages.Count == 0)
		{
			((BaseUnityPlugin)Instance).Logger.LogError((object)"[ParryImages] No images were found in the ParryImages folder!");
		}
	}

	private static void ReloadImages()
	{
		((BaseUnityPlugin)Instance).Logger.LogInfo((object)"[ParryImages] Reloading images...");
		LoadImages();
	}
}
namespace ParryImagesInfo;

public class HarmonyPatches
{
	private static Harmony instance;

	public const string InstanceId = "com.harryzawg.UltraKill.ParryImages";

	public static bool IsPatched { get; private set; }

	internal static void ApplyHarmonyPatches()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		if (!IsPatched)
		{
			if (instance == null)
			{
				instance = new Harmony("com.harryzawg.UltraKill.ParryImages");
			}
			instance.PatchAll(Assembly.GetExecutingAssembly());
			IsPatched = true;
		}
	}

	internal static void RemoveHarmonyPatches()
	{
		if (instance != null && IsPatched)
		{
			instance.UnpatchSelf();
			IsPatched = false;
		}
	}
}
internal class PluginInfo
{
	public const string GUID = "com.harryzawg.UltraKill.ParryImages";

	public const string Name = "ParryImages";

	public const string Version = "1.3.0";
}