Decompiled source of KickForParry v1.4.0

KickForParry.dll

Decompiled 6 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

[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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("KickForParry")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("KickForParry")]
[assembly: AssemblyTitle("KickForParry")]
[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 KickForParry
{
	public static class Loader
	{
		public static AssetBundle LoadLegs()
		{
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				string name = "KickForParry.kick.bundle";
				using Stream stream = executingAssembly.GetManifestResourceStream(name);
				if (stream == null)
				{
					Debug.LogError((object)"Resource 'kick.bundle' not found in embedded resources.");
					return null;
				}
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				return AssetBundle.LoadFromMemory(array);
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Error loading objector: " + ex.Message));
				return null;
			}
		}
	}
	[BepInPlugin("doomahreal.ultrakill.KickForParry", "KickForParry", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private AssetBundle LegsBundle;

		public static Mesh originalMesh;

		public static GameObject Leg;

		public static GameObject legInstance;

		public static Shader fixedshader;

		private void Awake()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			LegsBundle = Loader.LoadLegs();
			Leg = LegsBundle.LoadAsset<GameObject>("leg5.prefab");
			Harmony val = new Harmony("doomahreal.ultrakill.KickForParry");
			val.PatchAll();
			AsyncOperationHandle<Shader> val2 = Addressables.LoadAssetAsync<Shader>((object)"Assets/Shaders/Main/ULTRAKILL-vertexlit.shader");
			val2.Completed += OnShaderLoaded;
		}

		private void OnShaderLoaded(AsyncOperationHandle<Shader> handle)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			if ((int)handle.Status == 1)
			{
				fixedshader = handle.Result;
			}
			else
			{
				Debug.LogError((object)"Failed to load shader");
			}
		}
	}
	[HarmonyPatch(typeof(Punch))]
	[HarmonyPatch("Start")]
	public static class Punch_Start_Patch
	{
		private static void Postfix(Punch __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if ((int)__instance.type != 0)
			{
				return;
			}
			if ((Object)(object)Plugin.originalMesh == (Object)null)
			{
				Plugin.originalMesh = __instance.smr.sharedMesh;
			}
			Plugin.legInstance = Object.Instantiate<GameObject>(Plugin.Leg);
			Plugin.legInstance.transform.SetParent(((Component)__instance).transform.parent, false);
			Plugin.legInstance.transform.localPosition = new Vector3(125f, 0f, -40f);
			Plugin.legInstance.transform.localRotation = Quaternion.Euler(0f, 0f, 25f);
			Plugin.legInstance.SetActive(false);
			if ((Object)(object)Plugin.fixedshader != (Object)null)
			{
				Renderer[] componentsInChildren = Plugin.legInstance.GetComponentsInChildren<Renderer>();
				Renderer[] array = componentsInChildren;
				foreach (Renderer val in array)
				{
					Material[] materials = val.materials;
					foreach (Material val2 in materials)
					{
						val2.shader = Plugin.fixedshader;
					}
				}
			}
			else
			{
				Debug.LogError((object)"Shader not loaded yet");
			}
		}
	}
	[HarmonyPatch(typeof(Punch))]
	[HarmonyPatch("Parry")]
	public static class Parry_Patch
	{
		private static void Postfix(Punch __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			if ((int)__instance.type == 0)
			{
				((MonoBehaviour)__instance).StartCoroutine(RestoreMeshAfterDelay(__instance));
			}
		}

		private static IEnumerator RestoreMeshAfterDelay(Punch punchInstance)
		{
			punchInstance.smr.sharedMesh = null;
			Plugin.legInstance.SetActive(true);
			Animator animator = Plugin.legInstance.GetComponent<Animator>();
			if ((Object)(object)animator != (Object)null)
			{
				animator.Play("Kick", 0, 0.3333f);
			}
			else
			{
				Debug.LogError((object)"Animator component not found on legInstance");
			}
			yield return (object)new WaitForSeconds(1f);
			punchInstance.smr.sharedMesh = Plugin.originalMesh;
			Plugin.legInstance.SetActive(false);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "KickForParry";

		public const string PLUGIN_NAME = "KickForParry";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}