Decompiled source of Slayer v1.0.2

plugins/Slayer.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 System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
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.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
namespace Slayer;

[BepInPlugin("neithar.Slayer", "Slayer", "1.0.2")]
[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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Invalid comparison between Unknown and I4
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (configEnableBonusDamage.Value)
			{
				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 * configDamageAmount.Value / 100f;
					((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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			if (!configPushBackResistanceToggle.Value)
			{
				return;
			}
			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 * configPushBackResistanceAmount.Value);
				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.2";

	public static SkillType SlayerType;

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

	private static ConfigEntry<float> configDamageAmount;

	private static ConfigEntry<bool> configEnableBonusDamage;

	private static ConfigEntry<float> configPushBackResistanceAmount;

	private static ConfigEntry<bool> configPushBackResistanceToggle;

	private void Awake()
	{
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Expected O, but got Unknown
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		configDamageAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Damage", "Value", 25f, "The percentage by which two-handed weapon damage is increased at level 100 ");
		configEnableBonusDamage = ((BaseUnityPlugin)this).Config.Bind<bool>("Damage Increase Enabled", "Value", true, "Enable or disable the damage increase");
		configPushBackResistanceAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Pushback Resistance Amount", "Value", 2f, "Percentage of pushback resistance gained with each level of the skill");
		configPushBackResistanceToggle = ((BaseUnityPlugin)this).Config.Bind<bool>("Pushback Resistance Enabled", "Value", true, "Enable or disable the pushback resistance");
		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));
	}
}