Decompiled source of AshKnightArmor v1.1.2

plugins/AeehyehssReeper-AshKnightArmor/AshKnight.dll

Decompiled 17 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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 JetBrains.Annotations;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;
using UnityEngine.Audio;

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

public class AshClanka : MonoBehaviour
{
	public static GameObject prefabStep;

	public static GameObject prefabRun;

	public static GameObject prefabJump;

	public static GameObject prefabDodge;

	public static GameObject prefabLand;

	public static GameObject prefabBootStep;

	public static GameObject prefabBootRun;

	public static EffectData jumpData;

	public static EffectData dodgeData;

	private Player wearer;

	public void Start()
	{
		ConfigEntry<bool> clankArmor = AshKnight.ClankArmor;
		if ((clankArmor == null || clankArmor.Value) && !((Object)(object)prefabStep == (Object)null))
		{
			Transform root = ((Component)this).transform.root;
			object obj;
			if (root == null)
			{
				obj = null;
			}
			else
			{
				GameObject gameObject = ((Component)root).gameObject;
				obj = ((gameObject != null) ? gameObject.GetComponent<Player>() : null);
			}
			wearer = (Player)obj;
			if ((Object)(object)wearer != (Object)null)
			{
				MakePlayerClanky(wearer);
			}
		}
	}

	public void OnDisable()
	{
		ConfigEntry<bool> clankArmor = AshKnight.ClankArmor;
		if ((clankArmor == null || clankArmor.Value) && !((Object)(object)prefabStep == (Object)null))
		{
			if ((Object)(object)wearer != (Object)null)
			{
				UnclankPlayer(wearer);
			}
			wearer = null;
		}
	}

	private static void MakePlayerClanky(Player player)
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Invalid comparison between Unknown and I4
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Invalid comparison between Unknown and I4
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Invalid comparison between Unknown and I4
		FootStep component = ((Component)player).GetComponent<FootStep>();
		if ((Object)(object)component == (Object)null || ((Character)player).m_jumpEffects == null || player.m_dodgeEffects == null)
		{
			return;
		}
		foreach (StepEffect effect in component.m_effects)
		{
			HashSet<GameObject> hashSet = new HashSet<GameObject>(effect.m_effectPrefabs);
			bool flag = false;
			MotionType motionType = effect.m_motionType;
			if (((int)motionType == 2 || (int)motionType == 8) ? (hashSet.Add(prefabRun) | hashSet.Add(prefabBootRun)) : (((int)motionType != 32) ? (hashSet.Add(prefabStep) | hashSet.Add(prefabBootStep)) : (hashSet.Add(prefabLand) | hashSet.Add(prefabBootRun))))
			{
				effect.m_effectPrefabs = hashSet.ToArray();
			}
		}
		HashSet<EffectData> hashSet2 = new HashSet<EffectData>(((Character)player).m_jumpEffects.m_effectPrefabs);
		bool num = hashSet2.Add(jumpData);
		HashSet<EffectData> hashSet3 = new HashSet<EffectData>(player.m_dodgeEffects.m_effectPrefabs);
		bool flag2 = hashSet3.Add(dodgeData);
		if (num)
		{
			((Character)player).m_jumpEffects.m_effectPrefabs = hashSet2.ToArray();
		}
		if (flag2)
		{
			player.m_dodgeEffects.m_effectPrefabs = hashSet3.ToArray();
		}
	}

	private static void UnclankPlayer(Player player)
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Invalid comparison between Unknown and I4
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Invalid comparison between Unknown and I4
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Invalid comparison between Unknown and I4
		FootStep component = ((Component)player).GetComponent<FootStep>();
		if ((Object)(object)component == (Object)null || ((Character)player).m_jumpEffects == null || player.m_dodgeEffects == null)
		{
			return;
		}
		foreach (StepEffect effect in component.m_effects)
		{
			HashSet<GameObject> hashSet = new HashSet<GameObject>(effect.m_effectPrefabs);
			bool flag = false;
			MotionType motionType = effect.m_motionType;
			if (((int)motionType == 2 || (int)motionType == 8) ? (hashSet.Remove(prefabRun) | hashSet.Remove(prefabBootRun)) : (((int)motionType != 32) ? (hashSet.Remove(prefabStep) | hashSet.Remove(prefabBootStep)) : (hashSet.Remove(prefabLand) | hashSet.Remove(prefabBootRun))))
			{
				effect.m_effectPrefabs = hashSet.ToArray();
			}
		}
		HashSet<EffectData> hashSet2 = new HashSet<EffectData>(((Character)player).m_jumpEffects.m_effectPrefabs);
		bool num = hashSet2.Remove(jumpData);
		HashSet<EffectData> hashSet3 = new HashSet<EffectData>(player.m_dodgeEffects.m_effectPrefabs);
		bool flag2 = hashSet3.Remove(dodgeData);
		if (num)
		{
			((Character)player).m_jumpEffects.m_effectPrefabs = hashSet2.ToArray();
		}
		if (flag2)
		{
			player.m_dodgeEffects.m_effectPrefabs = hashSet3.ToArray();
		}
	}
}
[BepInPlugin("com.aeehyehssreeper.ashknight", "AshKnight", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class AshKnight : BaseUnityPlugin
{
	[HarmonyPatch]
	public static class ZNetScenePatch
	{
		[HarmonyPatch(typeof(ZNetScene), "Awake")]
		[HarmonyPostfix]
		public static void Patch_ZNetSceneAwake(ZNetScene __instance)
		{
			__instance.m_prefabs.Add(AshClanka.prefabStep);
			__instance.m_prefabs.Add(AshClanka.prefabRun);
			__instance.m_prefabs.Add(AshClanka.prefabJump);
			__instance.m_prefabs.Add(AshClanka.prefabDodge);
			__instance.m_prefabs.Add(AshClanka.prefabLand);
			__instance.m_prefabs.Add(AshClanka.prefabBootStep);
			__instance.m_prefabs.Add(AshClanka.prefabBootRun);
		}
	}

	[HarmonyPatch]
	public static class AudioManPatch
	{
		private static void SetAudioMixerGroup(GameObject prefab, AudioMixerGroup group)
		{
			prefab.GetComponent<AudioSource>().outputAudioMixerGroup = group;
		}

		[HarmonyPatch(typeof(AudioMan), "Awake")]
		[HarmonyPostfix]
		public static void Patch_AudioManAwake(AudioMan __instance)
		{
			if (!((Object)(object)AshClanka.prefabStep == (Object)null))
			{
				AudioMixerGroup group = __instance.m_ambientMixer.audioMixer.FindMatchingGroups("Effects/SFX").FirstOrDefault();
				SetAudioMixerGroup(AshClanka.prefabStep, group);
				SetAudioMixerGroup(AshClanka.prefabRun, group);
				SetAudioMixerGroup(AshClanka.prefabDodge, group);
				SetAudioMixerGroup(AshClanka.prefabLand, group);
				SetAudioMixerGroup(AshClanka.prefabJump, group);
				SetAudioMixerGroup(AshClanka.prefabBootRun, group);
				SetAudioMixerGroup(AshClanka.prefabBootStep, group);
			}
		}
	}

	public const string PluginGUID = "com.aeehyehssreeper.ashknight";

	public const string PluginName = "AshKnight";

	public const string PluginVersion = "1.1.0";

	public static ConfigEntry<bool> ClankArmor;

	private Assembly assembly;

	private AssetBundle ashknight;

	private GameObject ashKnightHelmPrefab;

	private GameObject ashKnightBodyPrefab;

	private GameObject ashKnightLegsPrefab;

	private GameObject ashKnightHelmFumePrefab;

	private GameObject ashKnightBodyFumePrefab;

	private GameObject ashKnightLegsFumePrefab;

	private GameObject ashKnightHelmSilverPrefab;

	private GameObject ashKnightBodySilverPrefab;

	private GameObject ashKnightLegsSilverPrefab;

	public static int T1BodyHash;

	public static int T2BodyHash;

	public static int T3BodyHash;

	public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();

	private void AddToTrader()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: 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_0044: Expected O, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Expected O, but got Unknown
		try
		{
			TradeItem item = new TradeItem
			{
				m_prefab = ashKnightHelmPrefab.GetComponent<ItemDrop>(),
				m_price = 600
			};
			TradeItem item2 = new TradeItem
			{
				m_prefab = ashKnightBodyPrefab.GetComponent<ItemDrop>(),
				m_price = 999
			};
			TradeItem item3 = new TradeItem
			{
				m_prefab = ashKnightLegsPrefab.GetComponent<ItemDrop>(),
				m_price = 700
			};
			PrefabManager.Instance.GetPrefab("Haldor").GetComponent<Trader>().m_items.Add(item);
			Trader component = PrefabManager.Instance.GetPrefab("BogWitch").GetComponent<Trader>();
			component.m_items.Add(item);
			component.m_items.Add(item2);
			component.m_items.Add(item3);
		}
		catch (Exception)
		{
			Logger.LogWarning((object)"AshKnight failed to add items to traders, armor will have to be spawned in");
		}
		PrefabManager.OnVanillaPrefabsAvailable -= AddToTrader;
	}

	private void RegisterLocalization()
	{
	}

	private void Main()
	{
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Expected O, but got Unknown
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Expected O, but got Unknown
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Expected O, but got Unknown
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Expected O, but got Unknown
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Expected O, but got Unknown
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Expected O, but got Unknown
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Expected O, but got Unknown
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Expected O, but got Unknown
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0278: Unknown result type (might be due to invalid IL or missing references)
		//IL_0285: Expected O, but got Unknown
		//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cd: Expected O, but got Unknown
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02de: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Expected O, but got Unknown
		//IL_0338: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: Expected O, but got Unknown
		//IL_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_0348: Unknown result type (might be due to invalid IL or missing references)
		//IL_0353: Unknown result type (might be due to invalid IL or missing references)
		//IL_0360: Expected O, but got Unknown
		//IL_039e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a8: Expected O, but got Unknown
		//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b7: Expected O, but got Unknown
		//IL_03be: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c5: Expected O, but got Unknown
		//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d3: Expected O, but got Unknown
		//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_040a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0417: Expected O, but got Unknown
		//IL_0463: Unknown result type (might be due to invalid IL or missing references)
		//IL_046d: Expected O, but got Unknown
		//IL_046e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0473: Unknown result type (might be due to invalid IL or missing references)
		//IL_047e: Unknown result type (might be due to invalid IL or missing references)
		//IL_048b: Expected O, but got Unknown
		//IL_04d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e2: Expected O, but got Unknown
		//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0500: Expected O, but got Unknown
		//IL_054d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0557: Expected O, but got Unknown
		ashknight = AssetUtils.LoadAssetBundleFromResources("ashknight");
		ashKnightHelmPrefab = ashknight.LoadAsset<GameObject>("AshKnightHelm");
		ashKnightBodyPrefab = ashknight.LoadAsset<GameObject>("AshKnightBody");
		ashKnightLegsPrefab = ashknight.LoadAsset<GameObject>("AshKnightLegs");
		ashKnightHelmFumePrefab = ashknight.LoadAsset<GameObject>("AshKnightHelmFume");
		ashKnightBodyFumePrefab = ashknight.LoadAsset<GameObject>("AshKnightBodyFume");
		ashKnightLegsFumePrefab = ashknight.LoadAsset<GameObject>("AshKnightLegsFume");
		ashKnightHelmSilverPrefab = ashknight.LoadAsset<GameObject>("AshKnightHelmSilver");
		ashKnightBodySilverPrefab = ashknight.LoadAsset<GameObject>("AshKnightBodySilver");
		ashKnightLegsSilverPrefab = ashknight.LoadAsset<GameObject>("AshKnightLegsSilver");
		T1BodyHash = StringExtensionMethods.GetStableHashCode("AshKnightBody");
		T2BodyHash = StringExtensionMethods.GetStableHashCode("AshKnightBodySilver");
		T3BodyHash = StringExtensionMethods.GetStableHashCode("AshKnightBodyFume");
		AshClanka.prefabStep = ashknight.LoadAsset<GameObject>("sfx_reepus_footstepClank_ash");
		AshClanka.prefabRun = ashknight.LoadAsset<GameObject>("sfx_reepus_footstepClank2_ash");
		AshClanka.prefabDodge = ashknight.LoadAsset<GameObject>("sfx_reepus_dodge_ash");
		AshClanka.prefabLand = ashknight.LoadAsset<GameObject>("sfx_reepus_land_ash");
		AshClanka.prefabJump = ashknight.LoadAsset<GameObject>("sfx_reepus_jumpClank_ash");
		AshClanka.prefabBootStep = ashknight.LoadAsset<GameObject>("sfx_reepus_footstepBootWalk_ash");
		AshClanka.prefabBootRun = ashknight.LoadAsset<GameObject>("sfx_reepus_footstepBootRun_ash");
		AshClanka.jumpData = new EffectData
		{
			m_enabled = true,
			m_prefab = AshClanka.prefabJump
		};
		AshClanka.dodgeData = new EffectData
		{
			m_enabled = true,
			m_prefab = AshClanka.prefabDodge
		};
		CustomItem val = new CustomItem(ashKnightHelmPrefab, true);
		CustomItem val2 = new CustomItem(ashKnightBodyPrefab, true);
		CustomItem val3 = new CustomItem(ashKnightLegsPrefab, true);
		ItemManager.Instance.AddItem(val);
		ItemManager.Instance.AddItem(val2);
		ItemManager.Instance.AddItem(val3);
		CustomItem val4 = new CustomItem(ashKnightHelmSilverPrefab, true);
		CustomItem val5 = new CustomItem(ashKnightBodySilverPrefab, true);
		CustomItem val6 = new CustomItem(ashKnightLegsSilverPrefab, true);
		ItemManager.Instance.AddItem(val4);
		ItemManager.Instance.AddItem(val5);
		ItemManager.Instance.AddItem(val6);
		RecipeConfig val7 = new RecipeConfig
		{
			RepairStation = "forge",
			CraftingStation = "forge"
		};
		val7.Item = "AshKnightHelmSilver";
		val7.AddRequirement("Silver", 20, 5);
		val7.AddRequirement("WolfClaw", 2, 1);
		val7.AddRequirement("AshKnightHelm", 1, 0);
		ItemManager.Instance.AddRecipe(new CustomRecipe(val7));
		RecipeConfig val8 = new RecipeConfig
		{
			RepairStation = "forge",
			CraftingStation = "forge"
		};
		val8.Item = "AshKnightBodySilver";
		val8.AddRequirement("Silver", 20, 5);
		val8.AddRequirement("JuteRed", 15, 2);
		val8.AddRequirement("WolfHairBundle", 4, 1);
		val8.AddRequirement("AshKnightBody", 1, 0);
		ItemManager.Instance.AddRecipe(new CustomRecipe(val8));
		RecipeConfig val9 = new RecipeConfig
		{
			RepairStation = "forge",
			CraftingStation = "forge"
		};
		val9.Item = "AshKnightLegsSilver";
		val9.AddRequirement("Silver", 20, 5);
		val9.AddRequirement("WolfHairBundle", 2, 1);
		val9.AddRequirement("AshKnightLegs", 1, 0);
		ItemManager.Instance.AddRecipe(new CustomRecipe(val9));
		CustomItem val10 = new CustomItem(ashKnightHelmFumePrefab, true);
		CustomItem val11 = new CustomItem(ashKnightBodyFumePrefab, true);
		CustomItem val12 = new CustomItem(ashKnightLegsFumePrefab, true);
		ItemManager.Instance.AddItem(val10);
		ItemManager.Instance.AddItem(val11);
		ItemManager.Instance.AddItem(val12);
		RecipeConfig val13 = new RecipeConfig
		{
			RepairStation = "blackforge",
			CraftingStation = "blackforge"
		};
		val13.Item = "AshKnightHelmFume";
		val13.AddRequirement("FlametalNew", 20, 5);
		val13.AddRequirement("TrophyFallenValkyrie", 1, 0);
		val13.AddRequirement("AskHide", 3, 1);
		val13.AddRequirement("AshKnightHelmSilver", 1, 0);
		ItemManager.Instance.AddRecipe(new CustomRecipe(val13));
		RecipeConfig val14 = new RecipeConfig
		{
			RepairStation = "blackforge",
			CraftingStation = "blackforge"
		};
		val14.Item = "AshKnightBodyFume";
		val14.AddRequirement("FlametalNew", 20, 5);
		val14.AddRequirement("CelestialFeather", 5, 1);
		val14.AddRequirement("AskHide", 10, 3);
		val14.AddRequirement("AshKnightBodySilver", 1, 0);
		ItemManager.Instance.AddRecipe(new CustomRecipe(val14));
		RecipeConfig val15 = new RecipeConfig
		{
			RepairStation = "blackforge",
			CraftingStation = "blackforge"
		};
		val15.Item = "AshKnightLegsFume";
		val15.AddRequirement("FlametalNew", 20, 5);
		val15.AddRequirement("MorgenSinew", 2, 1);
		val15.AddRequirement("AskHide", 10, 3);
		val15.AddRequirement("AshKnightLegsSilver", 1, 0);
		ItemManager.Instance.AddRecipe(new CustomRecipe(val15));
	}

	private void Awake()
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		assembly = Assembly.GetExecutingAssembly();
		ClankArmor = ((BaseUnityPlugin)this).Config.Bind<bool>("Client config", "LocalBool", true, new ConfigDescription("Enable clanking movement sound effects on chest armor pieces.", (AcceptableValueBase)null, Array.Empty<object>()));
		Main();
		PrefabManager.OnVanillaPrefabsAvailable += AddToTrader;
		try
		{
			Harmony.CreateAndPatchAll(assembly, (string)null);
		}
		catch (Exception)
		{
			Logger.LogWarning((object)"AshKnight failed to patch onhit effects, stagger and knockback reduction will not work");
		}
	}
}
public static class PoseBoisAsh
{
	[HarmonyPatch(typeof(Character), "RPC_Damage")]
	public static class ReduceDamageTaken
	{
		[UsedImplicitly]
		private static void Prefix(Character __instance, HitData hit)
		{
			try
			{
				Player val = (Player)(object)((__instance is Player) ? __instance : null);
				if (val != null)
				{
					if (((Humanoid)val).m_visEquipment.m_currentChestItemHash == AshKnight.T3BodyHash)
					{
						hit.m_pushForce *= 0.55f;
						hit.m_staggerMultiplier *= 0.8f;
					}
					else if (((Humanoid)val).m_visEquipment.m_currentChestItemHash == AshKnight.T2BodyHash)
					{
						hit.m_pushForce *= 0.65f;
						hit.m_staggerMultiplier *= 0.9f;
					}
					else if (((Humanoid)val).m_visEquipment.m_currentChestItemHash == AshKnight.T1BodyHash)
					{
						hit.m_pushForce *= 0.75f;
					}
				}
			}
			catch (Exception)
			{
			}
		}
	}
}