Decompiled source of JardsAdditions v1.6.0

plugins/JardsAdditions.dll

Decompiled 2 months 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 JardsAdditions.Patches.VanillaModifiers;
using Jotunn;
using Jotunn.Entities;
using Jotunn.Extensions;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("JardsAdditions")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JardsAdditions")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace JardsAdditions
{
	internal class Configuration
	{
		public ConfigEntry<Protected> PreventSkillLoss;

		public ConfigEntry<Protected> ProtectPlayerGraves;

		public ConfigEntry<float> PavedRoadSpeedMultiplier;

		public ConfigEntry<float> PavedRoadStaminaMultiplier;

		public ConfigEntry<bool> ApplyRunBuffsToStoneFloors;

		public ConfigEntry<float> HomeActionMultiplier;

		public ConfigEntry<bool> HarpoonIsHomeAction;

		public ConfigEntry<float> KnockbackMultiplier;

		public ConfigEntry<BloodstoneEffect> BloodstoneEffect;

		public ConfigEntry<float> BloodstoneDamagePercent;

		public ConfigEntry<float> BloodstoneVampirismPercent;

		public ConfigEntry<bool> WindRunWithModer;

		public ConfigEntry<bool> StonePortalNerfs;
	}
	[HarmonyPatch(typeof(Character))]
	internal class KnockbackModifiers
	{
		[HarmonyPatch("Damage")]
		[HarmonyPrefix]
		private static void MultiplyKnockback(ref HitData hit)
		{
			if (hit != null)
			{
				HitData obj = hit;
				obj.m_pushForce *= JardsAdditions.PluginConfig.KnockbackMultiplier.Value;
			}
		}
	}
	internal class PavedRoadHelpers
	{
		public static bool IsPaved(Heightmap h, Vector3 worldPos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			int num = default(int);
			int num2 = default(int);
			h.WorldToVertexMask(worldPos, ref num, ref num2);
			return h.m_paintMask.GetPixel(num, num2).b > 0.5f;
		}

		private static WearNTear GetSuitableWearNTear(GameObject gameObject, int levels = 1)
		{
			if ((Object)(object)gameObject == (Object)null)
			{
				return null;
			}
			WearNTear component = gameObject.GetComponent<WearNTear>();
			if ((Object)(object)component != (Object)null)
			{
				return component;
			}
			if (levels > 0)
			{
				return GetSuitableWearNTear(((Component)gameObject.transform.parent).gameObject, levels - 1);
			}
			return null;
		}

		public static bool TestCreatureIsOnPavedRoad(Character character)
		{
			//IL_0035: 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_0073: Invalid comparison between Unknown and I4
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Invalid comparison between Unknown and I4
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Invalid comparison between Unknown and I4
			if (character.IsOnGround() && (Object)(object)character.m_lastGroundCollider != (Object)null)
			{
				Heightmap component = ((Component)character.m_lastGroundCollider).GetComponent<Heightmap>();
				if ((Object)(object)component != (Object)null)
				{
					return IsPaved(component, ((Component)character).transform.position);
				}
				if (JardsAdditions.PluginConfig.ApplyRunBuffsToStoneFloors.Value)
				{
					WearNTear suitableWearNTear = GetSuitableWearNTear(((Component)character.m_lastGroundCollider).gameObject);
					if ((Object)(object)suitableWearNTear != (Object)null)
					{
						if ((int)suitableWearNTear.m_materialType != 1 && (int)suitableWearNTear.m_materialType != 4)
						{
							return (int)suitableWearNTear.m_materialType == 5;
						}
						return true;
					}
					return false;
				}
			}
			return false;
		}

		public static void ScaleCreatureRunSpeed(Character character, ref float result)
		{
			if (TestCreatureIsOnPavedRoad(character))
			{
				result *= JardsAdditions.PluginConfig.PavedRoadSpeedMultiplier.Value;
			}
		}

		public static void ScaleCreatureRunStamina(Character character, ref float result)
		{
			if (TestCreatureIsOnPavedRoad(character))
			{
				result *= JardsAdditions.PluginConfig.PavedRoadStaminaMultiplier.Value;
			}
		}
	}
	[HarmonyPatch(typeof(Character))]
	internal class PavedRoadModifiers_CharacterSpeed
	{
		[HarmonyPatch("GetRunSpeedFactor")]
		[HarmonyPostfix]
		private static void ScaleCharacterRunSpeed(ref Character __instance, ref float __result)
		{
			PavedRoadHelpers.ScaleCreatureRunSpeed(__instance, ref __result);
		}
	}
	[HarmonyPatch(typeof(Player))]
	internal class PavedRoadModifiers_PlayerSpeed
	{
		[HarmonyPatch("GetRunSpeedFactor")]
		[HarmonyPostfix]
		private static void ScalePlayerRunSpeed(ref Player __instance, ref float __result)
		{
			PavedRoadHelpers.ScaleCreatureRunSpeed((Character)(object)__instance, ref __result);
		}
	}
	[HarmonyPatch(typeof(SEMan))]
	internal class PavedRoadModifiers_PlayerStamina
	{
		[HarmonyPatch("ModifyRunStaminaDrain")]
		[HarmonyPostfix]
		private static void ScalePlayerRunStamina(ref SEMan __instance, float baseDrain, ref float drain, bool minZero = true)
		{
			PavedRoadHelpers.ScaleCreatureRunStamina(__instance.m_character, ref drain);
		}
	}
	internal class PortalHelpers
	{
		public static bool playerHasUnteleportables(Humanoid player)
		{
			if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)29))
			{
				return false;
			}
			ItemDrop component = ObjectDB.instance.GetItemPrefab("MoltenCore").GetComponent<ItemDrop>();
			ItemDrop component2 = ObjectDB.instance.GetItemPrefab("Eitr").GetComponent<ItemDrop>();
			foreach (ItemData item in player.m_inventory.m_inventory)
			{
				if (item.m_shared.m_name.Equals(component.m_itemData.m_shared.m_name) || item.m_shared.m_name.Equals(component2.m_itemData.m_shared.m_name))
				{
					return true;
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(TeleportWorld))]
	internal class PortalModifiers
	{
		[HarmonyPatch("UpdatePortal")]
		[HarmonyPostfix]
		private static void UpdatePortal(ref TeleportWorld __instance)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			Logger.LogInfo((object)"Checking...");
			if (__instance.m_nview.IsValid() && !((Object)(object)__instance.m_proximityRoot == (Object)null))
			{
				Player closestPlayer = Player.GetClosestPlayer(__instance.m_proximityRoot.position, __instance.m_activationRange);
				if (Object.op_Implicit((Object)(object)closestPlayer) && __instance.m_allowAllItems && PortalHelpers.playerHasUnteleportables((Humanoid)(object)closestPlayer))
				{
					Logger.LogInfo((object)"Unconnecting portals");
					__instance.m_target_found.SetActive(false);
				}
			}
		}

		[HarmonyPatch("Teleport")]
		[HarmonyPrefix]
		private static bool StopTeleport(ref TeleportWorld __instance, Player player)
		{
			Logger.LogInfo((object)"Teleporting...");
			if (__instance.m_allowAllItems && PortalHelpers.playerHasUnteleportables((Humanoid)(object)player))
			{
				Logger.LogInfo((object)"Blocking player");
				((Character)player).Message((MessageType)2, "$msg_noteleport", 0, (Sprite)null);
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Player))]
	internal class PortalRecipeModifiers
	{
		[HarmonyPatch("Awake")]
		[HarmonyPrefix]
		private static void ChangePortalItems()
		{
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Expected O, but got Unknown
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Expected O, but got Unknown
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Expected O, but got Unknown
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Expected O, but got Unknown
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Expected O, but got Unknown
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Expected O, but got Unknown
			Piece component = Array.Find(Resources.FindObjectsOfTypeAll<GameObject>(), (GameObject _) => ((Object)_).name.Equals("portal_stone")).GetComponent<Piece>();
			Piece component2 = Array.Find(Resources.FindObjectsOfTypeAll<GameObject>(), (GameObject _) => ((Object)_).name.Equals("portal_wood")).GetComponent<Piece>();
			CraftingStation component3 = Array.Find(Resources.FindObjectsOfTypeAll<GameObject>(), (GameObject _) => ((Object)_).name.Equals("piece_magetable")).GetComponent<CraftingStation>();
			CraftingStation component4 = Array.Find(Resources.FindObjectsOfTypeAll<GameObject>(), (GameObject _) => ((Object)_).name.Equals("piece_stonecutter")).GetComponent<CraftingStation>();
			ItemDrop component5 = ObjectDB.instance.GetItemPrefab("FlametalNew").GetComponent<ItemDrop>();
			ItemDrop component6 = ObjectDB.instance.GetItemPrefab("MoltenCore").GetComponent<ItemDrop>();
			ItemDrop component7 = ObjectDB.instance.GetItemPrefab("Grausten").GetComponent<ItemDrop>();
			ItemDrop component8 = ObjectDB.instance.GetItemPrefab("Eitr").GetComponent<ItemDrop>();
			ItemDrop component9 = ObjectDB.instance.GetItemPrefab("GreydwarfEye").GetComponent<ItemDrop>();
			if (JardsAdditions.PluginConfig.StonePortalNerfs.Value)
			{
				Requirement val = new Requirement();
				val.m_resItem = component5;
				val.m_amount = 20;
				val.m_recover = true;
				Requirement val2 = new Requirement();
				val2.m_resItem = component9;
				val2.m_amount = 10;
				val2.m_recover = true;
				Requirement val3 = new Requirement();
				val3.m_resItem = component7;
				val3.m_amount = 100;
				val3.m_recover = true;
				Requirement val4 = new Requirement();
				val4.m_resItem = component6;
				val4.m_amount = 10;
				val4.m_recover = true;
				component.m_resources = (Requirement[])(object)new Requirement[4] { val2, val3, val4, val };
				component.m_craftingStation = component3;
				component8.m_itemData.m_shared.m_teleportable = false;
			}
			else
			{
				Requirement val5 = new Requirement();
				val5.m_resItem = component9;
				val5.m_amount = 10;
				val5.m_recover = true;
				Requirement val6 = new Requirement();
				val6.m_resItem = component7;
				val6.m_amount = 30;
				val6.m_recover = true;
				Requirement val7 = new Requirement();
				val7.m_resItem = component6;
				val7.m_amount = 2;
				val7.m_recover = true;
				component.m_resources = (Requirement[])(object)new Requirement[3] { val5, val6, val7 };
				component.m_craftingStation = component4;
				component.m_description = "$piece_portal_stone_description";
				component2.m_description = "$piece_portal_description";
				component8.m_itemData.m_shared.m_teleportable = true;
			}
		}
	}
	[BepInPlugin("hu.jard.JardsAdditions", "Jard's Additions", "1.6.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[BepInIncompatibility("Basil_NoStamCosts")]
	internal class JardsAdditions : BaseUnityPlugin
	{
		public const string PluginGUID = "hu.jard.JardsAdditions";

		public const string PluginName = "Jard's Additions";

		public const string PluginVersion = "1.6.0";

		private AssetBundle LocalizationBundle;

		private AssetBundle VanityBundle;

		private AssetBundle CustomPieceBundle;

		internal static CustomItem gauntlets;

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

		public static Configuration PluginConfig = new Configuration();

		private void Awake()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			LoadConfig(ref PluginConfig);
			LoadAssets();
			LoadLocalization();
			PrefabManager.OnVanillaPrefabsAvailable += AddVanityItems;
			new Harmony("hu.jard.JardsAdditions").PatchAll();
			new Harmony("Basil_NoStamCosts").UnpatchSelf();
		}

		private void LoadConfig(ref Configuration config)
		{
			//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_000d: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Expected O, but got Unknown
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Expected O, but got Unknown
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Expected O, but got Unknown
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Expected O, but got Unknown
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Expected O, but got Unknown
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Expected O, but got Unknown
			ConfigurationManagerAttributes val = new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			};
			config.PreventSkillLoss = ((BaseUnityPlugin)this).Config.Bind<Protected>("PvP Protection", "PreventPvPSkillLoss", Protected.OnlyInWard, new ConfigDescription("Whether to prevent skill loss when killed by another player (enforced by server)", (AcceptableValueBase)null, new object[1] { val }));
			config.ProtectPlayerGraves = ((BaseUnityPlugin)this).Config.Bind<Protected>("PvP Protection", "ProtectPlayerGraves", Protected.OnlyInWard, new ConfigDescription("Whether to prevent grave access by other players (enforced by server)", (AcceptableValueBase)null, new object[1] { val }));
			config.PavedRoadStaminaMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Vanilla tweaks", "PavedRoadStaminaMultiplier", 0.4f, new ConfigDescription("Stamina multiplier when running on a paved road (enforced by server)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[1] { val }));
			config.PavedRoadSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Vanilla tweaks", "PavedRoadSpeedMultiplier", 1.15f, new ConfigDescription("Speed multiplier when running on a paved road (enforced by server)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, float.MaxValue), new object[1] { val }));
			config.ApplyRunBuffsToStoneFloors = ((BaseUnityPlugin)this).Config.Bind<bool>("Vanilla tweaks", "ApplyRunBuffsToStoneFloors", true, new ConfigDescription("Whether to apply speed and stamina multipliers when the player is running on a stone piece (stone floor, grausten floor, etc) (enforced by server)", (AcceptableValueBase)null, Array.Empty<object>()));
			config.KnockbackMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Vanilla tweaks", "KnockbackMultiplier", 1f, new ConfigDescription("Knockback multiplier (enforced by server)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, float.MaxValue), new object[1] { val }));
			config.BloodstoneEffect = ((BaseUnityPlugin)this).Config.Bind<BloodstoneEffect>("Vanilla tweaks", "BloodstoneEffect", BloodstoneEffect.Damage, new ConfigDescription("Modify the effect of the bloodstone enchantment (enforced by server)", (AcceptableValueBase)null, new object[1] { val }));
			config.BloodstoneDamagePercent = ((BaseUnityPlugin)this).Config.Bind<float>("Vanilla tweaks", "BloodstoneDamagePercent", 0.004f, new ConfigDescription("Percentage increase of damage per missing health point for bloodstone damage effect (enforced by server)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.002f, 0.01f), new object[1] { val }));
			config.BloodstoneVampirismPercent = ((BaseUnityPlugin)this).Config.Bind<float>("Vanilla tweaks", "BloodstoneVampirismPercent", 0.045f, new ConfigDescription("Percentage of health returned per missing health point for bloodstone vampirism effect (enforced by server)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[1] { val }));
			config.WindRunWithModer = ((BaseUnityPlugin)this).Config.Bind<bool>("Vanilla tweaks", "WindRunWithModer", true, new ConfigDescription("Whether Moder's power synergizes with the asksvin cape by controlling wind direction while wearing the cape (enforced by server)", (AcceptableValueBase)null, new object[1] { val }));
			config.StonePortalNerfs = ((BaseUnityPlugin)this).Config.Bind<bool>("Vanilla tweaks", "StonePortalNerfs", false, new ConfigDescription("Adjusts the recipe and behavior of stone portals to make them harder to transport and build in general (molten cores and eitr become unteleportable, even with stone portals). Intended for use with no-portal/low-portal worlds. (enforced by server)", (AcceptableValueBase)null, new object[1] { val }));
		}

		private void LoadAssets()
		{
			LocalizationBundle = AssetUtils.LoadAssetBundleFromResources("localization", Assembly.GetExecutingAssembly());
			VanityBundle = AssetUtils.LoadAssetBundleFromResources("vanity", Assembly.GetExecutingAssembly());
		}

		private void LoadLocalization()
		{
			TextAsset[] array = LocalizationBundle.LoadAllAssets<TextAsset>();
			foreach (TextAsset val in array)
			{
				Localization.AddJsonFile(((Object)val).name.Replace(".json", null), ((object)val).ToString());
			}
		}

		private void AddItemFrom(AssetBundle parentBundle, string prefabName)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			GameObject val = parentBundle.LoadAsset<GameObject>(prefabName);
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Wasn't able to load prefab '" + prefabName + "' from asset bundle '" + ((Object)parentBundle).name + "'. Export probably messed up."));
			}
			CustomItem val2 = new CustomItem(val, true);
			if (prefabName.Equals("ShieldJardGauntlets"))
			{
				gauntlets = val2;
			}
			ItemManager.Instance.AddItem(val2);
		}

		private void AddVanityItems()
		{
			AddItemFrom(VanityBundle, "ArmorJardChest");
			AddItemFrom(VanityBundle, "ArmorJardLegs");
			AddItemFrom(VanityBundle, "SwordJard");
			AddItemFrom(VanityBundle, "SwordJardOffset");
			AddItemFrom(VanityBundle, "ShieldJardGauntlets");
			AddItemFrom(VanityBundle, "CapeJard");
			AddItemFrom(VanityBundle, "HelmetDriver");
			AddItemFrom(VanityBundle, "CapeDriver");
			PrefabManager.OnVanillaPrefabsAvailable -= AddVanityItems;
		}
	}
	internal enum Protected
	{
		Yes,
		OnlyInWard,
		No
	}
	internal class PvpWardHelpers
	{
		public static bool checkIfLocationIsSafe(Vector3 position)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			bool result = false;
			foreach (PrivateArea allArea in PrivateArea.m_allAreas)
			{
				if (allArea.IsEnabled() && allArea.IsInside(position, 0f))
				{
					return true;
				}
			}
			return result;
		}

		public static bool getSafeAreas(Vector3 position, ref List<PrivateArea> areas)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			bool result = false;
			foreach (PrivateArea allArea in PrivateArea.m_allAreas)
			{
				if (allArea.IsEnabled() && allArea.IsInside(position, 0f))
				{
					areas.Add(allArea);
					result = true;
				}
			}
			return result;
		}
	}
	[HarmonyPatch(typeof(Skills))]
	public class ProtectSkills
	{
		[HarmonyPatch("OnDeath")]
		private static bool Prefix(ref Skills __instance)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Invalid comparison between Unknown and I4
			Player player = __instance.m_player;
			bool flag = default(bool);
			switch (JardsAdditions.PluginConfig.PreventSkillLoss.Value)
			{
			case Protected.Yes:
				flag = true;
				break;
			case Protected.OnlyInWard:
				flag = PvpWardHelpers.checkIfLocationIsSafe(((Component)player).transform.position);
				break;
			case Protected.No:
				flag = false;
				break;
			default:
				global::<PrivateImplementationDetails>.ThrowInvalidOperationException();
				break;
			}
			bool num = flag;
			bool flag2 = (int)((Character)player).m_lastHit.m_hitType == 2;
			return !(num && flag2);
		}
	}
	[HarmonyPatch(typeof(TombStone))]
	public class ProtectTombstone
	{
		[HarmonyPatch("GetHoverText")]
		[HarmonyPrefix]
		private static bool NoAccessHoverText(ref TombStone __instance, ref string __result)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.m_nview.IsValid())
			{
				bool flag = default(bool);
				switch (JardsAdditions.PluginConfig.ProtectPlayerGraves.Value)
				{
				case Protected.Yes:
					flag = true;
					break;
				case Protected.OnlyInWard:
					flag = PvpWardHelpers.checkIfLocationIsSafe(((Component)__instance).transform.position);
					break;
				case Protected.No:
					flag = false;
					break;
				default:
					global::<PrivateImplementationDetails>.ThrowInvalidOperationException();
					break;
				}
				if (flag && !__instance.IsOwner())
				{
					string text = __instance.m_text + " " + __instance.GetOwnerName();
					__result = Localization.instance.Localize(text + "\n$piece_noaccess");
					return false;
				}
			}
			return true;
		}

		[HarmonyPatch("Interact")]
		[HarmonyPrefix]
		private static bool BlockInteract(ref TombStone __instance)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			List<PrivateArea> areas = new List<PrivateArea>();
			bool flag = default(bool);
			switch (JardsAdditions.PluginConfig.ProtectPlayerGraves.Value)
			{
			case Protected.Yes:
				flag = true;
				break;
			case Protected.OnlyInWard:
				flag = PvpWardHelpers.getSafeAreas(((Component)__instance).transform.position, ref areas);
				break;
			case Protected.No:
				flag = false;
				break;
			default:
				global::<PrivateImplementationDetails>.ThrowInvalidOperationException();
				break;
			}
			if (flag && !__instance.IsOwner())
			{
				foreach (PrivateArea item in areas)
				{
					item.FlashShield(false);
				}
				return false;
			}
			return true;
		}
	}
}
namespace JardsAdditions.VanillaModifiers
{
	internal class StopJumpsHelpers
	{
		public static bool AreYouAQ3ABoomer()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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)
			ButtonDef buttonDef = ZInput.m_instance.GetButtonDef("Jump");
			if (buttonDef != null && (int)buttonDef.Source == 170)
			{
				InputBinding val = ((IEnumerable<InputBinding>)(object)buttonDef.ButtonAction.bindings).FirstOrDefault();
				Logger.LogInfo((object)ZInput.instance.MapKeyFromPath(((InputBinding)(ref val)).effectivePath));
				return ZInput.instance.MapKeyFromPath(((InputBinding)(ref val)).effectivePath).Equals("rightButton");
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Humanoid))]
	internal class StopJumpsInInventory
	{
		public static bool ItemFlag;

		[HarmonyPatch("UseItem")]
		[HarmonyPostfix]
		private static void PlayerUsedItem(bool fromInventoryGui)
		{
			Logger.LogInfo((object)"Doing item use");
			if (fromInventoryGui && StopJumpsHelpers.AreYouAQ3ABoomer())
			{
				ItemFlag = true;
			}
		}
	}
	[HarmonyPatch(typeof(Character))]
	internal class StopJumpIfRightClicked
	{
		[HarmonyPatch("Jump")]
		[HarmonyPrefix]
		private static bool StopJump(ref Character __instance)
		{
			Logger.LogInfo((object)"Doing jump");
			if (StopJumpsInInventory.ItemFlag && (Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				StopJumpsInInventory.ItemFlag = false;
				return false;
			}
			return true;
		}
	}
}
namespace JardsAdditions.Patches.VanillaModifiers
{
	internal enum BloodstoneEffect
	{
		Damage,
		Vampirism,
		DamageAndVampirism
	}
	[HarmonyPatch(typeof(Attack))]
	internal class BloodstoneDamageModifiers
	{
		private static bool ShouldModifyDamage()
		{
			if (JardsAdditions.PluginConfig.BloodstoneEffect.Value == BloodstoneEffect.Vampirism)
			{
				return true;
			}
			if ((double)JardsAdditions.PluginConfig.BloodstoneDamagePercent.Value != 0.02)
			{
				return true;
			}
			return false;
		}

		[HarmonyPatch("ModifyDamage")]
		[HarmonyPrefix]
		private static bool OverrideBloodDamage(ref Attack __instance, HitData hitData, float damageFactor)
		{
			if (ShouldModifyDamage())
			{
				if (__instance.m_damageMultiplier != 1f)
				{
					((DamageTypes)(ref hitData.m_damage)).Modify(__instance.m_damageMultiplier);
				}
				if (damageFactor != 1f)
				{
					((DamageTypes)(ref hitData.m_damage)).Modify(damageFactor);
				}
				((DamageTypes)(ref hitData.m_damage)).Modify(__instance.GetLevelDamageFactor());
				if (__instance.m_damageMultiplierByTotalHealthMissing > 0f)
				{
					((DamageTypes)(ref hitData.m_damage)).Modify(1f + (1f - ((Character)__instance.m_character).GetHealthPercentage()) * __instance.m_damageMultiplierByTotalHealthMissing);
				}
				if (JardsAdditions.PluginConfig.BloodstoneEffect.Value != BloodstoneEffect.Vampirism && __instance.m_damageMultiplierPerMissingHP > 0f)
				{
					float num = ((JardsAdditions.PluginConfig.BloodstoneDamagePercent.Value != 0.002f) ? JardsAdditions.PluginConfig.BloodstoneDamagePercent.Value : __instance.m_damageMultiplierPerMissingHP);
					if (num > 0f)
					{
						((DamageTypes)(ref hitData.m_damage)).Modify(1f + (((Character)__instance.m_character).GetMaxHealth() - ((Character)__instance.m_character).GetHealth()) * num);
					}
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Attack))]
	internal class BloodstoneAddVampirismPatches
	{
		public static float CalculateVampMultiplier(ItemData item)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			float num = ((JardsAdditions.PluginConfig.BloodstoneVampirismPercent.Value != item.m_shared.m_attack.m_damageMultiplierPerMissingHP) ? JardsAdditions.PluginConfig.BloodstoneVampirismPercent.Value : item.m_shared.m_attack.m_damageMultiplierPerMissingHP);
			DamageTypes damages = item.m_shared.m_damages;
			if (item.m_quality > 1)
			{
				((DamageTypes)(ref damages)).Add(item.m_shared.m_damagesPerLevel, item.m_quality - 1);
			}
			float num2 = ((DamageTypes)(ref damages)).GetTotalPhysicalDamage() / 140f;
			num2 = Mathf.Pow(num2, 2.5f);
			if (num2 < 1f)
			{
				num2 = 1f;
			}
			float num3 = default(float);
			ZoneSystem.instance.GetGlobalKey((GlobalKeys)1, ref num3);
			if (num3 == 0f)
			{
				num3 = 100f;
			}
			num3 /= 100f;
			return num * num2 * num3;
		}

		[HarmonyPatch("OnAttackTrigger")]
		[HarmonyPrefix]
		private static void OnAttackTrigger(ref Attack __instance)
		{
			if (JardsAdditions.PluginConfig.BloodstoneEffect.Value != 0 && __instance.m_damageMultiplierPerMissingHP > 0f)
			{
				float num = CalculateVampMultiplier(__instance.m_weapon);
				float attackHealthReturnHit = (((Character)__instance.m_character).GetMaxHealth() - ((Character)__instance.m_character).GetHealth()) * num;
				__instance.m_attackHealthReturnHit = attackHealthReturnHit;
			}
		}
	}
	[HarmonyPatch(typeof(ItemData))]
	internal class BloodstoneTooltipPatches
	{
		[HarmonyPatch("GetTooltip", new Type[]
		{
			typeof(ItemData),
			typeof(int),
			typeof(bool),
			typeof(float),
			typeof(int)
		})]
		[HarmonyPostfix]
		private static void OverrideTooltipValues(ref string __result, ItemData item, int qualityLevel, bool crafting, float worldLevel, int stackOverride = -1)
		{
			LinkedList<string> linkedList = new LinkedList<string>(__result.Split(new char[1] { '\n' }));
			bool flag = false;
			for (LinkedListNode<string> linkedListNode = linkedList.First; linkedListNode != null; linkedListNode = linkedListNode.Next)
			{
				if (linkedListNode.Value.Contains("$item_damagemultiplierhp"))
				{
					if (JardsAdditions.PluginConfig.BloodstoneDamagePercent.Value != item.m_shared.m_attack.m_damageMultiplierPerMissingHP)
					{
						linkedListNode.Value = $"$item_damagemultiplierhp: <color=orange>{JardsAdditions.PluginConfig.BloodstoneDamagePercent.Value * 100f}%</color>";
						flag = true;
					}
					if (JardsAdditions.PluginConfig.BloodstoneEffect.Value != 0)
					{
						float num = BloodstoneAddVampirismPatches.CalculateVampMultiplier(item);
						string value = $"$item_vampirismhp: <color=orange>{num * 100f}%</color>";
						if (JardsAdditions.PluginConfig.BloodstoneEffect.Value == BloodstoneEffect.Vampirism)
						{
							linkedListNode.Value = value;
						}
						else
						{
							linkedList.AddAfter(linkedListNode, value);
						}
						flag = true;
					}
					break;
				}
			}
			if (!flag)
			{
				return;
			}
			__result = "";
			foreach (string item2 in linkedList)
			{
				__result = __result + "\n" + item2;
			}
		}
	}
	[HarmonyPatch(typeof(EnvMan))]
	internal class ModerPowerModifiers
	{
		[HarmonyPatch("UpdateWind")]
		[HarmonyPrefix]
		private static bool AskCapeWind(ref EnvMan __instance, long timeSec, float dt)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.GetCurrentEnvironment() != null && Object.op_Implicit((Object)(object)Player.m_localPlayer) && (Object)(object)Ship.GetLocalShip() == (Object)null && ((Character)Player.m_localPlayer).m_seman.HaveStatusEffect(StringExtensionMethods.GetStableHashCode("GP_Moder")) && ((Character)Player.m_localPlayer).m_seman.HaveStatusEffect(StringExtensionMethods.GetStableHashCode("WindRun")) && JardsAdditions.PluginConfig.WindRunWithModer.Value)
			{
				State state = Random.state;
				float num = 0f;
				float num2 = 0.5f;
				__instance.AddWindOctave(timeSec, 1, ref num, ref num2);
				__instance.AddWindOctave(timeSec, 2, ref num, ref num2);
				__instance.AddWindOctave(timeSec, 4, ref num, ref num2);
				__instance.AddWindOctave(timeSec, 8, ref num, ref num2);
				Random.state = state;
				num2 = Mathf.Lerp(__instance.GetCurrentEnvironment().m_windMin, __instance.GetCurrentEnvironment().m_windMax, num2);
				__instance.SetTargetWind(((Component)Player.m_localPlayer).transform.forward, num2);
				__instance.UpdateWindTransition(dt);
				return false;
			}
			return true;
		}
	}
}
namespace JardsAdditions.Patches.CustomPatches
{
	[HarmonyPatch(typeof(Humanoid))]
	internal class CapeColliderPatches
	{
		[HarmonyPatch("SetupVisEquipment")]
		[HarmonyPostfix]
		private static void ModifyColliderSize(ref Humanoid __instance)
		{
			if (__instance is Player)
			{
				Transform val = TransformExtensions.FindDeepChild(((Component)__instance).transform, "Hips", (IterativeSearchType)1);
				Transform val2 = TransformExtensions.FindDeepChild(((Component)val).transform, "Spine1", (IterativeSearchType)1);
				Transform val3 = TransformExtensions.FindDeepChild(((Component)val).transform, "Head", (IterativeSearchType)1);
				if (__instance.m_visEquipment.m_shoulderItem.Equals("CapeJard"))
				{
					AttemptAdjustWith(((Component)val).transform, "ClothCollider", 0.575f);
					AttemptAdjustWith(((Component)val).transform, "ClothColliderHips", 0.375f);
					AttemptAdjustWith(((Component)val).transform, "ClothColliderHipsCape", 0.375f);
					AttemptAdjustWith(((Component)val2).transform, "ClothCollider (3)", 0.55f);
					AttemptAdjustWith(((Component)val2).transform, "ClothColliderMid", 0.25f);
					AttemptAdjustWith(((Component)val2).transform, "ClothColliderMidCape", 0.25f);
					AttemptAdjustWith(((Component)val3).transform, "ClothColliderHead", 0f);
					AttemptAdjustWith(((Component)val3).transform, "ClothColliderHeadCape", 0f);
				}
				else
				{
					AttemptAdjustWith(((Component)val).transform, "ClothCollider", 0.8f);
					AttemptAdjustWith(((Component)val).transform, "ClothColliderHips", 0.45f);
					AttemptAdjustWith(((Component)val).transform, "ClothColliderHipsCape", 0.5f);
					AttemptAdjustWith(((Component)val2).transform, "ClothCollider (3)", 0.8f);
					AttemptAdjustWith(((Component)val2).transform, "ClothColliderMid", 0.45f);
					AttemptAdjustWith(((Component)val2).transform, "ClothColliderMidCape", 0.45f);
					AttemptAdjustWith(((Component)val3).transform, "ClothColliderHead", 0.38f);
					AttemptAdjustWith(((Component)val3).transform, "ClothColliderHeadCape", 0.5f);
				}
			}
		}

		private static void AttemptAdjustWith(Transform parent, string colliderToTry, float radius)
		{
			if (Object.op_Implicit((Object)(object)parent) && Object.op_Implicit((Object)(object)parent.Find(colliderToTry)))
			{
				((Component)parent.Find(colliderToTry)).GetComponent<CapsuleCollider>().radius = radius;
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid))]
	internal class ShieldAnimationPatches
	{
		private static AnimationClip originalBlock;

		private static EffectList originalBlockEffects;

		private static EffectList gauntletBlockEffects;

		[HarmonyPatch("SetupAnimationState")]
		[HarmonyPrefix]
		private static bool CustomBlockAnimation(ref Humanoid __instance)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			if (__instance.m_leftItem != null && __instance.m_visEquipment.m_leftItem.Equals("ShieldJardGauntlets"))
			{
				if (__instance.m_rightItem != null)
				{
					__instance.SetAnimationState(__instance.m_rightItem.m_shared.m_animationState);
					AnimatorOverrideController val = null;
					val = (AnimatorOverrideController)(typeof(AnimatorOverrideController).IsInstanceOfType(((Character)__instance).m_zanim.m_animator.runtimeAnimatorController) ? ((object)/*isinst with value type is only supported in some contexts*/) : ((object)new AnimatorOverrideController(((Character)__instance).m_zanim.m_animator.runtimeAnimatorController)));
					if ((Object)(object)originalBlock == (Object)null)
					{
						originalBlock = val["Block idle"];
					}
					val["Block idle"] = val["Sword And Shield Idle"];
					((Character)__instance).m_zanim.m_animator.runtimeAnimatorController = (RuntimeAnimatorController)(object)val;
					return false;
				}
				__instance.SetAnimationState((AnimationState)0);
				return false;
			}
			if (typeof(AnimatorOverrideController).IsInstanceOfType(((Character)__instance).m_zanim.m_animator.runtimeAnimatorController) && (Object)(object)originalBlock != (Object)null)
			{
				RuntimeAnimatorController runtimeAnimatorController = ((Character)__instance).m_zanim.m_animator.runtimeAnimatorController;
				((AnimatorOverrideController)((runtimeAnimatorController is AnimatorOverrideController) ? runtimeAnimatorController : null))["Block idle"] = originalBlock;
			}
			return true;
		}

		[HarmonyPatch("BlockAttack")]
		[HarmonyPrefix]
		private static void ReplaceBlockEffect(ref Humanoid __instance)
		{
			if (originalBlockEffects == null && __instance.GetCurrentBlocker() != null && __instance.m_visEquipment.m_leftItem.Equals("ShieldJardGauntlets"))
			{
				originalBlockEffects = __instance.GetCurrentBlocker().m_shared.m_blockEffect;
				if (gauntletBlockEffects == null)
				{
					gauntletBlockEffects = JardsAdditions.gauntlets.ItemPrefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_blockEffect;
				}
				__instance.GetCurrentBlocker().m_shared.m_blockEffect = gauntletBlockEffects;
			}
		}

		[HarmonyPatch("BlockAttack")]
		[HarmonyPostfix]
		private static void RestoreBlockEffect(ref Humanoid __instance)
		{
			if (originalBlockEffects != null && __instance.GetCurrentBlocker() != null)
			{
				__instance.GetCurrentBlocker().m_shared.m_blockEffect = originalBlockEffects;
				originalBlockEffects = null;
			}
		}
	}
}