Decompiled source of Slayer v1.0.3

plugins/Slayer.dll

Decompiled 19 hours 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;

internal static class SlayerDamage
{
	[HarmonyPatch(typeof(ItemData), "GetDamage", new Type[]
	{
		typeof(int),
		typeof(float)
	})]
	private static class DamagePatch
	{
		private static void Postfix(ItemData __instance, ref DamageTypes __result)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (SlayerConfig.DamageEnabled.Value)
			{
				Player localPlayer = Player.m_localPlayer;
				if (!((Object)(object)localPlayer == (Object)null) && SlayerWeapons.IsSlayerWeapon(__instance))
				{
					float skillFactor = ((Character)localPlayer).GetSkillFactor(Slayer.SlayerType);
					float num = 1f + skillFactor * SlayerConfig.DamageAmount.Value / 100f;
					((DamageTypes)(ref __result)).Modify(num);
				}
			}
		}
	}

	public static void Initialize()
	{
		Slayer.DebugLog("Damage system initialized.");
	}
}
internal static class SlayerExperience
{
	[HarmonyPatch(typeof(Character), "Damage")]
	private static class ExperiencePatch
	{
		private static void Prefix(Character __instance, HitData hit)
		{
			//IL_005c: 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 && SlayerWeapons.IsSlayerWeapon(currentWeapon) && !(((DamageTypes)(ref hit.m_damage)).GetTotalDamage() <= 0f))
				{
					((Character)val).RaiseSkill(Slayer.SlayerType, 0.5f);
				}
			}
		}
	}

	public static void Initialize()
	{
		Slayer.DebugLog("Experience system initialized.");
	}
}
internal static class SlayerPushback
{
	[HarmonyPatch(typeof(Character), "ApplyPushback", new Type[]
	{
		typeof(Vector3),
		typeof(float)
	})]
	private static class PushbackPatch
	{
		private static void Prefix(Character __instance, ref Vector3 dir, ref float pushForce)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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 (!SlayerConfig.PushbackResistanceEnabled.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(Slayer.SlayerType);
				float num = 1f - Mathf.Clamp01(skillFactor * SlayerConfig.PushbackResistanceAmount.Value);
				pushForce *= num;
				if (num <= 0f)
				{
					pushForce = 0f;
					dir = Vector3.zero;
				}
			}
		}
	}

	public static void Initialize()
	{
		Slayer.DebugLog("Pushback system initialized.");
	}
}
internal static class SlayerStagger
{
	[HarmonyPatch(typeof(Character), "AddStaggerDamage")]
	private static class AddStaggerDamagePatch
	{
		[HarmonyPrefix]
		private static void Prefix(Character __instance, ref float damage, Vector3 forceDirection, HitData hit)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Invalid comparison between Unknown and I4
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			if (!SlayerConfig.StaggerDamageEnabled.Value || hit == null)
			{
				return;
			}
			Character attacker = hit.GetAttacker();
			if ((Object)(object)attacker == (Object)null)
			{
				return;
			}
			Player val = (Player)(object)((attacker is Player) ? attacker : null);
			if (!((Object)(object)val == (Object)null))
			{
				ItemData currentWeapon = ((Humanoid)val).GetCurrentWeapon();
				if (currentWeapon != null && SlayerWeapons.IsSlayerWeapon(currentWeapon) && (int)currentWeapon.m_shared.m_itemType == 14)
				{
					float skillFactor = ((Character)val).GetSkillFactor(Slayer.SlayerType);
					float num = skillFactor * SlayerConfig.StaggerDamageAmount.Value / 100f;
					float num2 = damage;
					damage *= 1f + num;
					bool flag = false;
				}
			}
		}
	}

	public static void Initialize()
	{
		Slayer.DebugLog("Stagger damage system initialized.");
	}
}
[BepInPlugin("neithar.Slayer", "Slayer", "1.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class Slayer : BaseUnityPlugin
{
	public const string PluginGUID = "neithar.Slayer";

	public const string PluginName = "Slayer";

	public const string PluginVersion = "1.0.2";

	public static SkillType SlayerType;

	public const bool DebugLogging = false;

	private void Awake()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		SlayerConfig.Initialize((BaseUnityPlugin)(object)this);
		CreateSkill();
		new Harmony("neithar.Slayer").PatchAll();
		SlayerDamage.Initialize();
		SlayerPushback.Initialize();
		SlayerExperience.Initialize();
		DebugLog("Slayer initialized.");
	}

	public static void DebugLog(string message)
	{
		bool flag = false;
	}

	private void CreateSkill()
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Expected O, but got Unknown
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = LoadEmbeddedTexture("Slayer.Assets.krom_no_bg.png");
		if ((Object)(object)val == (Object)null)
		{
			Logger.LogError((object)"Texture load failed!");
			return;
		}
		Sprite icon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		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);
	}

	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;
	}
}
internal static class SlayerConfig
{
	public static ConfigEntry<float> DamageAmount;

	public static ConfigEntry<bool> DamageEnabled;

	public static ConfigEntry<float> PushbackResistanceAmount;

	public static ConfigEntry<bool> PushbackResistanceEnabled;

	public static ConfigEntry<float> StaggerDamageAmount;

	public static ConfigEntry<bool> StaggerDamageEnabled;

	public static void Initialize(BaseUnityPlugin plugin)
	{
		DamageAmount = plugin.Config.Bind<float>("Damage", "Value", 25f, "The percentage by which two-handed weapon damage is increased at level 100");
		DamageEnabled = plugin.Config.Bind<bool>("Damage Increase Enabled", "Value", true, "Enable or disable the damage increase");
		PushbackResistanceAmount = plugin.Config.Bind<float>("Pushback Resistance Amount", "Value", 2f, "Percentage of pushback resistance gained with each level of the skill");
		PushbackResistanceEnabled = plugin.Config.Bind<bool>("Pushback Resistance Enabled", "Value", true, "Enable or disable the pushback resistance");
		StaggerDamageEnabled = plugin.Config.Bind<bool>("Stagger Damage", "Enabled", true, "Enable Slayer's bonus stagger damage.");
		StaggerDamageAmount = plugin.Config.Bind<float>("Stagger Damage", "Bonus", 50f, "Maximum stagger damage bonus at Slayer skill level 100.");
	}
}
internal static class SlayerWeapons
{
	public static bool IsSlayerWeapon(ItemData weapon)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Invalid comparison between Unknown and I4
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Expected I4, but got Unknown
		if (weapon == null)
		{
			return false;
		}
		if ((int)weapon.m_shared.m_itemType != 14)
		{
			return false;
		}
		SkillType skillType = weapon.m_shared.m_skillType;
		SkillType val = skillType;
		switch (val - 1)
		{
		case 0:
		case 2:
		case 3:
		case 6:
			return true;
		default:
			return false;
		}
	}
}