Decompiled source of Slayer v1.0.1

plugins/Slayer.dll

Decompiled 3 days 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 System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Slayer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Slayer")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
namespace Slayer;

[BepInPlugin("neithar.Slayer", "Slayer", "1.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class Slayer : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Character), "Damage")]
	public static class Slayer_Handler
	{
		private static void Prefix(Character __instance, HitData hit)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Invalid comparison between Unknown and I4
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			Character attacker = hit.GetAttacker();
			Player val = (Player)(object)((attacker is Player) ? attacker : null);
			if (val != null)
			{
				ItemData currentWeapon = ((Humanoid)val).GetCurrentWeapon();
				if (currentWeapon != null && (int)currentWeapon.m_shared.m_itemType == 14 && !(((DamageTypes)(ref hit.m_damage)).GetTotalDamage() <= 0f))
				{
					((Character)val).RaiseSkill(SlayerType, 0.5f);
				}
			}
		}
	}

	[HarmonyPatch(typeof(ItemData), "GetDamage", new Type[]
	{
		typeof(int),
		typeof(float)
	})]
	public static class Slayer_ItemDamage
	{
		private static void Postfix(ItemData __instance, ref DamageTypes __result)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && (int)__instance.m_shared.m_itemType == 14)
			{
				float skillFactor = ((Character)localPlayer).GetSkillFactor(SlayerType);
				float num = 1f + skillFactor * 0.5f;
				((DamageTypes)(ref __result)).Modify(num);
			}
		}
	}

	[HarmonyPatch(typeof(Character), "ApplyPushback", new Type[]
	{
		typeof(Vector3),
		typeof(float)
	})]
	public static class Slayer_PushbackResistance
	{
		private static void Prefix(Character __instance, ref Vector3 dir, ref float pushForce)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			Player val = (Player)(object)((__instance is Player) ? __instance : null);
			if (val != null && !((Object)(object)val != (Object)(object)Player.m_localPlayer) && ((Character)val).InAttack())
			{
				float skillFactor = ((Character)val).GetSkillFactor(SlayerType);
				float num = 1f - Mathf.Clamp01(skillFactor * 2f);
				pushForce *= num;
				if (num <= 0f)
				{
					pushForce = 0f;
					dir = Vector3.zero;
				}
			}
		}
	}

	public const string PluginGUID = "neithar.Slayer";

	public const string PluginName = "Slayer";

	public const string PluginVersion = "1.0.1";

	public static SkillType SlayerType;

	private string resourceName = "Slayer.Assets.krom_no_bg.png";

	private void Awake()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: 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)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Expected O, but got Unknown
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: 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)
		Texture2D val = LoadEmbeddedTexture(resourceName);
		if ((Object)(object)val == (Object)null)
		{
			Logger.LogError((object)"Texture load failed!");
			return;
		}
		Sprite icon = TextureToSprite(val);
		SkillConfig val2 = new SkillConfig
		{
			Identifier = "neithar.Slayer",
			Name = "Slayer",
			Description = "Deal more damage with two-handed and dual weapons",
			Icon = icon,
			IncreaseStep = 1f
		};
		SlayerType = SkillManager.Instance.AddSkill(val2);
		new Harmony("neithar.Slayer").PatchAll();
	}

	private Texture2D LoadEmbeddedTexture(string resourceName)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		using Stream stream = executingAssembly.GetManifestResourceStream(resourceName);
		if (stream == null)
		{
			Logger.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);
		if (!AssetUtils.LoadImage(val, array))
		{
			Logger.LogError((object)"Failed to load image data into texture");
			return null;
		}
		return val;
	}

	private Sprite TextureToSprite(Texture2D texture)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		return Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), new Vector2(0.5f, 0.5f));
	}
}