Decompiled source of REPO Perfect Dodge v1.0.0

BepInEx\plugins\REPODodge\REPODodge.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.Networking;

[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("REPODodge")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("REPODodge")]
[assembly: AssemblyTitle("REPODodge")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 REPOAdminPanel
{
	[BepInPlugin("REPODodge", "REPO Perfect Dodge", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ConfigEntry<float> configDodgeWindow;

		internal static ConfigEntry<bool> configEnabled;

		internal static float lastFPressTime;

		internal static Texture2D[] dodgeTextures;

		internal static float animTimer;

		internal static bool animPlaying;

		private const float AnimFPS = 12f;

		private const float HoldDuration = 2f;

		private const float FadeDuration = 0.5f;

		private static Rect animRect = new Rect(0f, 0f, 360f, 190f);

		private static AudioClip dodgeSound;

		internal static ManualLogSource Logger { get; private set; }

		internal static Plugin Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			configDodgeWindow = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DodgeWindow", 0.2f, "Time window (seconds) to press F before damage hits");
			configEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable dodge mechanic");
			LoadTextures();
			Harmony.CreateAndPatchAll(typeof(HurtPatch), (string)null);
			Logger.LogInfo((object)"Dodge mod loaded!");
		}

		private void LoadTextures()
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "dodge_frames");
			if (!Directory.Exists(text))
			{
				Logger.LogWarning((object)("dodge_frames not found at " + text));
				return;
			}
			string[] array = (from f in Directory.GetFiles(text, "*.png")
				orderby f
				select f).ToArray();
			if (array.Length == 0)
			{
				Logger.LogWarning((object)"No PNGs in dodge_frames");
				return;
			}
			List<Texture2D> list = new List<Texture2D>();
			string[] array2 = array;
			foreach (string path in array2)
			{
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (ImageConversion.LoadImage(val, File.ReadAllBytes(path)))
				{
					((Texture)val).filterMode = (FilterMode)1;
					list.Add(val);
				}
			}
			dodgeTextures = list.ToArray();
			Logger.LogInfo((object)$"Loaded {dodgeTextures.Length} dodge frames");
			animRect = new Rect(0f, 185f, 360f, 190f);
			LoadSound();
		}

		private void LoadSound()
		{
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "dodge_sound.mp3");
			if (!File.Exists(text))
			{
				return;
			}
			UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip("file:///" + text, (AudioType)13);
			((AsyncOperation)uwr.SendWebRequest()).completed += delegate
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Invalid comparison between Unknown and I4
				if ((int)uwr.result == 1)
				{
					dodgeSound = DownloadHandlerAudioClip.GetContent(uwr);
					Logger.LogInfo((object)"Loaded dodge sound");
				}
				uwr.Dispose();
			};
		}

		private void Update()
		{
			if (configEnabled.Value && Input.GetKeyDown((KeyCode)102))
			{
				lastFPressTime = Time.time;
			}
		}

		private void OnGUI()
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			if (!animPlaying || dodgeTextures == null || dodgeTextures.Length == 0)
			{
				return;
			}
			animTimer += Time.deltaTime;
			float num = (float)dodgeTextures.Length / 12f + 2f + 0.5f;
			if (animTimer >= num)
			{
				animPlaying = false;
				return;
			}
			int num2 = (int)(animTimer * 12f);
			int num3 = dodgeTextures.Length - 1;
			Texture2D val = ((num2 > num3) ? dodgeTextures[num3] : dodgeTextures[num2]);
			float num4 = (float)dodgeTextures.Length / 12f + 2f;
			float num5 = 1f;
			if (animTimer > num4)
			{
				num5 = 1f - (animTimer - num4) / 0.5f;
			}
			Color color = GUI.color;
			GUI.color = new Color(color.r, color.g, color.b, num5);
			GUI.DrawTexture(animRect, (Texture)(object)val);
			GUI.color = color;
		}

		internal static void TriggerDodgeEffect()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			animTimer = 0f;
			animPlaying = true;
			if ((Object)(object)dodgeSound != (Object)null)
			{
				AudioSource.PlayClipAtPoint(dodgeSound, Vector3.zero);
			}
		}
	}
	[HarmonyPatch]
	internal static class HurtPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerHealth), "Hurt")]
		private static bool Prefix(int damage)
		{
			if (!Plugin.configEnabled.Value)
			{
				return true;
			}
			if (damage <= 0)
			{
				return true;
			}
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
			{
				return true;
			}
			float num = Time.time - Plugin.lastFPressTime;
			if (num >= 0f && num <= Plugin.configDodgeWindow.Value)
			{
				Plugin.lastFPressTime = -999f;
				Plugin.Logger.LogInfo((object)$"Dodge! Negated {damage} damage");
				if (Plugin.dodgeTextures != null && Plugin.dodgeTextures.Length != 0)
				{
					Plugin.TriggerDodgeEffect();
				}
				return false;
			}
			return true;
		}
	}
}