Decompiled source of CriticalBlock v1.2.1

CriticalBlock/CriticalBlock.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CriticalBlock;
using HarmonyLib;
using On.RoR2;
using On.RoR2.Items;
using R2API;
using RoR2;
using RoR2.Items;
using RoR2.Orbs;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("CriticalBlock")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CriticalBlock")]
[assembly: AssemblyTitle("CriticalBlock")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace CriticalBLock
{
	public abstract class SharedBase
	{
		public virtual bool lockEnabled { get; } = false;


		public abstract string ConfigName { get; }

		public virtual bool isEnabled { get; } = true;


		public abstract AssetBundle assetBundle { get; }

		public abstract void Hooks();

		public abstract void Lang();

		public virtual void Init()
		{
			ConfigManager.HandleConfigAttributes(GetType(), ConfigName, Config.MyConfig);
			Hooks();
			Lang();
		}

		public T Bind<T>(T defaultValue, string configName, string configDesc = "")
		{
			return ConfigManager.DualBindToConfig(ConfigName, Config.MyConfig, configName, defaultValue, configDesc);
		}

		public static float GetHyperbolic(float firstStack, float cap, float chance)
		{
			if (firstStack >= cap)
			{
				return cap * (chance / firstStack);
			}
			float num = chance / firstStack;
			float num2 = 100f * firstStack / (cap - firstStack);
			return cap * (1f - 100f / (num * num2 + 100f));
		}
	}
}
namespace CriticalBlock
{
	[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
	public class AutoConfigAttribute : Attribute
	{
		public string name;

		public string desc;

		public object defaultValue;

		public AutoConfigAttribute(string name, object defaultValue)
		{
			Init(name, string.Empty, defaultValue);
		}

		public AutoConfigAttribute(string name, string desc, object defaultValue)
		{
			Init(name, desc, defaultValue);
		}

		public void Init(string name, string desc, object defaultValue)
		{
			this.name = name;
			this.desc = desc;
			this.defaultValue = defaultValue;
		}
	}
	public static class Config
	{
		public static ConfigFile MyConfig;

		public static ConfigFile BackupConfig;

		public static void Init()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			MyConfig = new ConfigFile(Paths.ConfigPath + "\\RiskofBrainrot.CriticalBlock.cfg", true);
			BackupConfig = new ConfigFile(Paths.ConfigPath + "\\RiskofBrainrot.CriticalBlock.Backup.cfg", true);
			BackupConfig.Bind<string>(": DO NOT MODIFY THIS FILES CONTENTS :", ": DO NOT MODIFY THIS FILES CONTENTS :", ": DO NOT MODIFY THIS FILES CONTENTS :", ": DO NOT MODIFY THIS FILES CONTENTS :");
		}

		public static ConfigEntry<bool> CharacterEnableConfig(string section, string characterName, string description = "", bool enabledByDefault = true)
		{
			if (string.IsNullOrEmpty(description))
			{
				description = "Set to false to disable this character and as much of its code and content as possible";
			}
			return BindAndOptions(section, "Enable " + characterName, enabledByDefault, description, restartRequired: true);
		}

		public static ConfigEntry<T> BindAndOptions<T>(string section, string name, T defaultValue, string description = "", bool restartRequired = false)
		{
			return BindAndOptions(section, name, defaultValue, 0f, 20f, description, restartRequired);
		}

		public static ConfigEntry<T> BindAndOptions<T>(string section, string name, T defaultValue, float min, float max, string description = "", bool restartRequired = false)
		{
			if (string.IsNullOrEmpty(description))
			{
				description = name;
			}
			if (restartRequired)
			{
				description += " (restart required)";
			}
			ConfigEntry<T> val = MyConfig.Bind<T>(section, name, defaultValue, description);
			if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
			{
				TryRegisterOption<T>(val, min, max, restartRequired);
			}
			return val;
		}

		public static ConfigEntry<float> BindAndOptionsSlider(string section, string name, float defaultValue, string description, float min = 0f, float max = 20f, bool restartRequired = false)
		{
			return BindAndOptions(section, name, defaultValue, min, max, description, restartRequired);
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static void TryRegisterOption<T>(ConfigEntry<T> entry, float min, float max, bool restartRequired)
		{
		}

		public static bool GetKeyPressed(KeyboardShortcut entry)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyCode modifier in ((KeyboardShortcut)(ref entry)).Modifiers)
			{
				if (!Input.GetKey(modifier))
				{
					return false;
				}
			}
			return Input.GetKeyDown(((KeyboardShortcut)(ref entry)).MainKey);
		}
	}
	public class ConfigManager
	{
		internal static bool ConfigChanged;

		internal static bool VersionChanged;

		public static void HandleConfigAttributes(Type type, string section, ConfigFile config)
		{
			TypeInfo typeInfo = type.GetTypeInfo();
			FieldInfo[] fields = typeInfo.GetFields();
			foreach (FieldInfo fieldInfo in fields)
			{
				if (fieldInfo.IsStatic)
				{
					Type fieldType = fieldInfo.FieldType;
					AutoConfigAttribute customAttribute = fieldInfo.GetCustomAttribute<AutoConfigAttribute>();
					if (customAttribute != null)
					{
						string name = customAttribute.name;
						object defaultValue = customAttribute.defaultValue;
						string desc = customAttribute.desc;
						fieldInfo.SetValue(null, DualBindToConfig(fieldType, section, config, name, defaultValue, desc));
					}
				}
			}
		}

		private static object DualBindToConfig(Type t, string section, ConfigFile config, string configName, object defaultValue, string configDesc)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Expected O, but got Unknown
			if (string.IsNullOrWhiteSpace(section) || string.IsNullOrWhiteSpace(configName))
			{
				return defaultValue;
			}
			ConfigDescription val = new ConfigDescription(configDesc, (AcceptableValueBase)null, Array.Empty<object>());
			MethodInfo methodInfo = (from x in typeof(ConfigFile).GetMethods()
				where x.Name == "Bind"
				select x).First();
			methodInfo = methodInfo.MakeGenericMethod(t);
			ConfigEntryBase val2 = (ConfigEntryBase)methodInfo.Invoke(config, new object[3]
			{
				(object)new ConfigDefinition(section, configName),
				defaultValue,
				val
			});
			ConfigEntryBase val3 = (ConfigEntryBase)methodInfo.Invoke(Config.BackupConfig, new object[3]
			{
				(object)new ConfigDefinition(Regex.Replace(config.ConfigFilePath, "\\W", "") + " : " + section, configName),
				defaultValue,
				val
			});
			if (!ConfigEqual(val3.DefaultValue, val3.BoxedValue))
			{
				bool flag = true;
				Log.Warning("Syncing config to new version");
				val2.BoxedValue = val2.DefaultValue;
				val3.BoxedValue = val3.DefaultValue;
			}
			if (!ConfigEqual(val2.DefaultValue, val2.BoxedValue))
			{
				ConfigChanged = true;
			}
			return val2.BoxedValue;
		}

		public static T DualBindToConfig<T>(string section, ConfigFile config, string configName, T defaultValue, string configDesc)
		{
			return (T)DualBindToConfig(typeof(T), section, config, configName, defaultValue, configDesc);
		}

		private static bool ConfigEqual(object a, object b)
		{
			if (a.Equals(b))
			{
				return true;
			}
			if (float.TryParse(a.ToString(), out var result) && float.TryParse(b.ToString(), out var result2) && (double)Mathf.Abs(result - result2) < 0.0001)
			{
				return true;
			}
			return false;
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("RiskofBrainrot.CriticalBlock", "CriticalBlock", "1.1.0")]
	public class CriticalBlock : BaseUnityPlugin
	{
		public const string PluginGUID = "RiskofBrainrot.CriticalBlock";

		public const string PluginAuthor = "RiskofBrainrot";

		public const string PluginName = "CriticalBlock";

		public const string PluginVersion = "1.1.0";

		private static ItemDef blockBearItemDef;

		private static ItemDef blockGrenadeItemDef;

		public static ItemDef blockTeslaItemDef;

		private static ItemDef blockRAPItemDef;

		[AutoConfig("Base Block Chance (players only)", 1)]
		public int critBlockChance = 1;

		[AutoConfig("Bear block chance per stack", 10)]
		public int bearBlockChance = 10;

		[AutoConfig("Stun grenade block chance (first stack)", 5)]
		public int grenadeBlockChance = 5;

		[AutoConfig("Grenade damage coeff (first stack)", 1)]
		public int grenadeDamageBase = 1;

		[AutoConfig("Grenade damage coeff (additional stacks)", 0)]
		public int grenadeDamageStack = 0;

		[AutoConfig("Grenade radius (first stack)", 2)]
		public int grenadeRadiusBase = 2;

		[AutoConfig("Grenade radius (additional stacks)", 2)]
		public int grenadeRadiusStack = 2;

		[AutoConfig("RAP block chance (first stack)", 5)]
		public int rapBlockChanceBase = 5;

		[AutoConfig("RAP block chance (additional stacks)", 5)]
		public int rapBlockChanceStack = 5;

		[AutoConfig("RAP armor (first stack", 5)]
		public int rapArmorBase = 5;

		[AutoConfig("RAP armor (additional stack", 5)]
		public int rapArmorStack = 5;

		[AutoConfig("Titanic knurl block chance", 5)]
		public int knurlBlockChance = 5;

		[AutoConfig("Opal block damage reduction", 0.1f)]
		public float opalBlockDamageReduction = 0.1f;

		[AutoConfig("Elephant buff duration", 10)]
		public int elephantBuffDuration = 10;

		private static ItemDef LoadItemDef(string name)
		{
			return LegacyResourcesAPI.Load<ItemDef>("ItemDefs/" + name);
		}

		public static ItemDef RetierItem(string itemName, ItemTier tier = 5)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			ItemDef def = LoadItemDef(itemName);
			return RetierItem(def, tier);
		}

		public static ItemDef RetierItem(ItemDef def, ItemTier tier = 5)
		{
			//IL_000e: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)def != (Object)null)
			{
				def.tier = tier;
				def.deprecatedTier = tier;
			}
			return def;
		}

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			BlockBear();
			BlockGrenade();
			BlockTesla();
			BlockRAP();
			Hooks();
		}

		private void ChangeLangs()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			Log.Info("1");
			LanguageAPI.Add(ItemCatalog.GetItemDef(ItemCatalog.FindItemIndex("Knurl")).pickupToken, "Gain health, regen, and block chance.");
			Log.Info("2");
			LanguageAPI.Add(ItemCatalog.GetItemDef(ItemCatalog.FindItemIndex("OutOfCombatArmor")).pickupToken, "Block when out of danger and block harder.");
			Log.Info("3");
			LanguageAPI.Add(EquipmentCatalog.GetEquipmentDef(EquipmentCatalog.FindEquipmentIndex("GainArmor")).pickupToken, "Blocking attacks reduces damage more. Activate to block attacks for 10 seconds.");
			Log.Info("4");
		}

		private void BlockBear()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			blockBearItemDef = ScriptableObject.CreateInstance<ItemDef>();
			((Object)blockBearItemDef).name = "BLOCKBEAR";
			blockBearItemDef.nameToken = "BLOCKBEAR_NAME";
			blockBearItemDef.pickupToken = "BLOCKBEAR_PICKUP";
			blockBearItemDef.descriptionToken = "BLOCKBEAR_DESC";
			blockBearItemDef.loreToken = "BLOCKBEAR_LORE";
			blockBearItemDef._itemTierDef = Addressables.LoadAssetAsync<ItemTierDef>((object)"RoR2/Base/Common/Tier1Def.asset").WaitForCompletion();
			blockBearItemDef.pickupIconSprite = Addressables.LoadAssetAsync<Sprite>((object)"RoR2/Base/Bear/texBearIcon.png").WaitForCompletion();
			blockBearItemDef.pickupModelPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Bear/PickupBear.prefab").WaitForCompletion();
			blockBearItemDef.canRemove = true;
			blockBearItemDef.hidden = false;
			ItemDisplayRuleDict val = new ItemDisplayRuleDict((ItemDisplayRule[])null);
			LanguageAPI.Add(blockBearItemDef.nameToken, "Tougher Times");
			LanguageAPI.Add(blockBearItemDef.pickupToken, "Chance to block incoming damage.");
			LanguageAPI.Add(blockBearItemDef.descriptionToken, $"<style=cIsHealing>{bearBlockChance}%</style> <style=cStack>(+{bearBlockChance}% per stack)</style> chance to <style=cIsHealing>block</style> incoming damage, reducing it by half.");
			LanguageAPI.Add(blockBearItemDef.loreToken, "<style=cMono>\n//--AUTO-TRANSCRIPTION FROM ROOM 4211B OF UES [Redacted] --//</style>\n\n\"Why'd you sign up?\"\n\nWyatt's voice was bored. The mission to the Contact Light's last known location was taking longer than he expected.\n\nMalik was on the floor, cleaning her rifle. \"To get paid, mostly.\"\n\n\"And that's it?\"\n\nShe grunted in affirmation. She continued to wipe down the weapon.\n\n\"I'm here to find something.\" He continued. \"I shipped it a few years back, but I don't think it made it before the train went down. I'm guessing it's still in the Contact Light. So I'm gonna get it back.\"\n\nShe began to tighten the last remaining bolts. Her routine near completion, she moved her gaze to Wyatt. \"Seriously?\"\n\n\"Yep!\"\n\nMalik raised her brow. \"There were over 7 million security chests in the Contact Light. The chance of you finding a specific one is impossible.\" She began to unfold her legs as she propped her rifle in the corner. \"And according to the distress beacon, the Contact Light was destroyed in orbit. Your shipment is probably floating around in space. It's all gone, Wyatt.\"\n\nHe grinned. \"I think I'm gonna find it.\"\n\n\"You're terrible.\"\n");
			ItemAPI.Add(new CustomItem(blockBearItemDef, val));
			RetierItem("Bear", (ItemTier)5);
		}

		private void CreateBearTransformation(orig_Init orig)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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)
			Pair val = default(Pair);
			val.itemDef1 = Items.HealWhileSafe;
			val.itemDef2 = blockBearItemDef;
			Pair val2 = val;
			ItemCatalog.itemRelationships[ItemRelationshipTypes.ContagiousItem] = CollectionExtensions.AddToArray<Pair>(ItemCatalog.itemRelationships[ItemRelationshipTypes.ContagiousItem], val2);
			orig.Invoke();
		}

		private void BlockGrenade()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Expected O, but got Unknown
			blockGrenadeItemDef = ScriptableObject.CreateInstance<ItemDef>();
			((Object)blockGrenadeItemDef).name = "BLOCKGRENADE";
			blockGrenadeItemDef.nameToken = "BLOCKGRENADE_NAME";
			blockGrenadeItemDef.pickupToken = "BLOCKGRENADE_PICKUP";
			blockGrenadeItemDef.descriptionToken = "BLOCKGRENADE_DESC";
			blockGrenadeItemDef.loreToken = "BLOCKGRENADE_LORE";
			blockGrenadeItemDef._itemTierDef = Addressables.LoadAssetAsync<ItemTierDef>((object)"RoR2/Base/Common/Tier1Def.asset").WaitForCompletion();
			blockGrenadeItemDef.pickupIconSprite = Addressables.LoadAssetAsync<Sprite>((object)"RoR2/Base/StunChanceOnHit/texStunGrenadeIcon.png").WaitForCompletion();
			blockGrenadeItemDef.pickupModelPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/StunChanceOnHit/PickupStunGrenade.prefab").WaitForCompletion();
			blockGrenadeItemDef.canRemove = true;
			blockGrenadeItemDef.hidden = false;
			ItemDisplayRuleDict val = new ItemDisplayRuleDict((ItemDisplayRule[])null);
			LanguageAPI.Add(blockGrenadeItemDef.nameToken, "Stun Grenade");
			LanguageAPI.Add(blockGrenadeItemDef.pickupToken, "Blocking attacks stuns enemies.");
			LanguageAPI.Add(blockGrenadeItemDef.descriptionToken, $"< style = cIsUtility > {grenadeBlockChance} %</ style > < style = cStack > (+{grenadeBlockChance} % per stack) </ style > chance to block attacks. Blocking attacks < style = cIsUtility > stuns </ style > the attacker and enemies within {grenadeRadiusBase}< style = cStack > (+{grenadeRadiusStack} per stack) </ style > meters for < style = cIsUtility > 2 seconds </ style > and <style = cIsDamage> {grenadeDamageBase}00% damage.</style>.");
			LanguageAPI.Add(blockGrenadeItemDef.loreToken, "looore");
			ItemAPI.Add(new CustomItem(blockGrenadeItemDef, val));
			RetierItem("StunChanceOnHit", (ItemTier)5);
		}

		private void BlockTesla()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Expected O, but got Unknown
			blockTeslaItemDef = ScriptableObject.CreateInstance<ItemDef>();
			((Object)blockTeslaItemDef).name = "BLOCKTESLA";
			blockTeslaItemDef.nameToken = "BLOCKTESLA_NAME";
			blockTeslaItemDef.pickupToken = "BLOCKTESLA_PICKUP";
			blockTeslaItemDef.descriptionToken = "BLOCKTESLA_DESC";
			blockTeslaItemDef.loreToken = "BLOCKTESLA_LORE";
			blockTeslaItemDef._itemTierDef = Addressables.LoadAssetAsync<ItemTierDef>((object)"RoR2/Base/Common/Tier3Def.asset").WaitForCompletion();
			blockTeslaItemDef.pickupIconSprite = Addressables.LoadAssetAsync<Sprite>((object)"RoR2/Base/ShockNearby/texTeslaCoilIcon.png").WaitForCompletion();
			blockTeslaItemDef.pickupModelPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/ShockNearby/PickupTeslaCoil.prefab").WaitForCompletion();
			blockTeslaItemDef.canRemove = true;
			blockTeslaItemDef.hidden = false;
			ItemDisplayRuleDict val = new ItemDisplayRuleDict((ItemDisplayRule[])null);
			LanguageAPI.Add(blockTeslaItemDef.nameToken, "Unstable Tesla Coil");
			LanguageAPI.Add(blockTeslaItemDef.pickupToken, "Block attacks and shock enemies every 10 seconds.");
			LanguageAPI.Add(blockTeslaItemDef.descriptionToken, "Fire out <style=cIsDamage>lightning</style> that hits <style=cIsDamage>3</style> <style=cStack>(+2 per stack)</style> enemies for <style=cIsDamage>200%</style> base damage every <style=cIsDamage> when blocking an attack.</style>. The Tesla Coil switches on every <style=cIsDamage>10 seconds</style>, <style = cIsUtility> blocking all incoming attacks</style>.");
			LanguageAPI.Add(blockTeslaItemDef.nameToken, "Unstable Tesla Coil");
			LanguageAPI.Add(blockTeslaItemDef.loreToken, "<style=cMono>Tesla Presentation Software v1.14\r\nPowering on...\r\n10...\r\nIssuing welcome statement...\r\n9...</style>\r\nWelcome one and all!\r\n<style=cMono>8...</style>\r\nPlease take a seat.\r\n<style=cMono>7...</style>\r\nMake sure those behind you can see.\r\n<style=cMono>6...</style>\r\nThe presentation will start shortly.\r\n<style=cMono>5...</style>\r\nPlease obey the staff for your safety.\r\n<style=cMono>4...\r\nInitiating room mood lighting...\r\n3...</style>\r\nGet ready to behold...\r\n<style=cMono>2...</style>\r\nThe marvelous wonders...\r\n<style=cMono>1...</style>\r\nOf electricity!\r\n<style=cMono>Power anomaly detected...\r\nInitiating reboot procedure in 10...</style>\r\n");
			ItemAPI.Add(new CustomItem(blockTeslaItemDef, val));
			RetierItem("ShockNearby", (ItemTier)5);
		}

		private void BlockRAP()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			blockRAPItemDef = ScriptableObject.CreateInstance<ItemDef>();
			((Object)blockRAPItemDef).name = "BLOCKRAP";
			blockRAPItemDef.nameToken = "BLOCKRAP_NAME";
			blockRAPItemDef.pickupToken = "BLOCKRAP_PICKUP";
			blockRAPItemDef.descriptionToken = "BLOCKRAP_DESC";
			blockRAPItemDef.loreToken = "BLOCKRAP_LORE";
			blockRAPItemDef._itemTierDef = Addressables.LoadAssetAsync<ItemTierDef>((object)"RoR2/Base/Common/Tier1Def.asset").WaitForCompletion();
			blockRAPItemDef.pickupIconSprite = Addressables.LoadAssetAsync<Sprite>((object)"RoR2/Base/ArmorPlate/texRepulsionArmorPlateIcon.png").WaitForCompletion();
			blockRAPItemDef.pickupModelPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/ArmorPlate/PickupRepulsionArmorPlate.prefab").WaitForCompletion();
			blockRAPItemDef.canRemove = true;
			blockRAPItemDef.hidden = false;
			ItemDisplayRuleDict val = new ItemDisplayRuleDict((ItemDisplayRule[])null);
			LanguageAPI.Add(blockRAPItemDef.nameToken, "Repulsion Armor Plate.");
			LanguageAPI.Add(blockRAPItemDef.pickupToken, "Gain block chance and damage reduction.");
			LanguageAPI.Add(blockRAPItemDef.descriptionToken, $"< style = cIsUtility > {rapBlockChanceBase} %</ style > < style = cStack > (+{rapBlockChanceStack} % per stack) </ style > chance to block attacks. {rapArmorBase}< style = cStack > (+{rapArmorStack} per stack) </ style > < style = cIsUtility > armor.");
			LanguageAPI.Add(blockRAPItemDef.loreToken, "looore");
			ItemAPI.Add(new CustomItem(blockRAPItemDef, val));
			RetierItem("ArmorPlate", (ItemTier)5);
		}

		private void Hooks()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			HealthComponent.TakeDamageProcess += new hook_TakeDamageProcess(CritBlockTakeDamageProcess);
			EquipmentSlot.FireGainArmor += new hook_FireGainArmor(ChangeElephantDuration);
			RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(StatHooks);
			CharacterBody.OnInventoryChanged += new hook_OnInventoryChanged(AddTeslaBehavior);
			ContagiousItemManager.Init += new hook_Init(CreateBearTransformation);
		}

		private void StatHooks(CharacterBody sender, StatHookEventArgs args)
		{
			int buffCount = sender.GetBuffCount(Buffs.ElephantArmorBoost);
			if (buffCount > 0)
			{
				args.armorAdd += -500f;
			}
			int buffCount2 = sender.GetBuffCount(Buffs.OutOfCombatArmorBuff);
			if (buffCount2 > 0)
			{
				int itemCount = sender.inventory.GetItemCount(Items.OutOfCombatArmor);
				args.armorAdd += (float)(-100 * itemCount);
			}
			if (!((Object)(object)sender.inventory == (Object)null))
			{
				int itemCount2 = sender.inventory.GetItemCount(blockRAPItemDef);
				if (itemCount2 > 0)
				{
					itemCount2--;
					args.armorAdd += (float)(rapArmorBase + rapArmorStack * itemCount2);
				}
			}
		}

		private bool ChangeElephantDuration(orig_FireGainArmor orig, EquipmentSlot self)
		{
			self.characterBody.AddTimedBuff(Buffs.ElephantArmorBoost, (float)elephantBuffDuration);
			return true;
		}

		private void AddTeslaBehavior(orig_OnInventoryChanged orig, CharacterBody self)
		{
			orig.Invoke(self);
			if (NetworkServer.active && Object.op_Implicit((Object)(object)self.master))
			{
				BlockTeslaBehavior blockTeslaBehavior = self.AddItemBehavior<BlockTeslaBehavior>(self.inventory.GetItemCount(blockTeslaItemDef));
			}
		}

		public int CritBlockInventoryCheck(int blockChance, Inventory inv)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)inv == (Object)null)
			{
				return blockChance;
			}
			int itemCount = inv.GetItemCount(blockBearItemDef);
			int itemCount2 = inv.GetItemCount(blockGrenadeItemDef);
			int itemCount3 = inv.GetItemCount(ItemCatalog.GetItemDef(ItemCatalog.FindItemIndex("Knurl")));
			int itemCount4 = inv.GetItemCount(blockRAPItemDef);
			blockChance += bearBlockChance * itemCount;
			blockChance += grenadeBlockChance * itemCount2;
			blockChance += knurlBlockChance * itemCount3;
			if (itemCount4 > 0)
			{
				blockChance += rapBlockChanceBase + rapBlockChanceStack * (itemCount4 - 1);
			}
			return blockChance;
		}

		private void CritBlockTakeDamageProcess(orig_TakeDamageProcess orig, HealthComponent self, DamageInfo damageInfo)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			CharacterBody body = self.body;
			if ((Object)(object)body == (Object)null)
			{
				orig.Invoke(self, damageInfo);
				return;
			}
			if ((Object)(object)body.inventory == (Object)null)
			{
				orig.Invoke(self, damageInfo);
				return;
			}
			if (body.isPlayerControlled)
			{
				num += critBlockChance;
			}
			Inventory inventory = body.inventory;
			num = CritBlockInventoryCheck(num, inventory);
			if ((inventory.currentEquipmentIndex == EquipmentCatalog.FindEquipmentIndex("GainArmor") && body.HasBuff(BuffCatalog.FindBuffIndex("bdElephantArmorBoost"))) || body.HasBuff(BuffCatalog.FindBuffIndex("bdTeslaField")) || body.HasBuff(BuffCatalog.FindBuffIndex("bdOutOfCombatArmorBuff")) || Util.CheckRoll((float)num, 0f, (CharacterMaster)null))
			{
				DoCritBlock(self, damageInfo);
				DoCritBlockSynergies(body, damageInfo);
			}
			orig.Invoke(self, damageInfo);
		}

		private void DoCritBlockSynergies(CharacterBody body, DamageInfo damageInfo)
		{
			CharacterBody component = damageInfo.attacker.GetComponent<CharacterBody>();
			Inventory inventory = body.inventory;
			if ((Object)(object)component == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"No attacker!!");
			}
			int itemCount = inventory.GetItemCount(blockGrenadeItemDef);
			if (itemCount > 0)
			{
				DoGrenadeEffect(itemCount - 1, component, body);
			}
			int itemCount2 = inventory.GetItemCount(blockTeslaItemDef);
			if (itemCount2 > 0)
			{
				DoTeslaEffect(body);
			}
		}

		private void DoTeslaEffect(CharacterBody body)
		{
			BlockTeslaBehavior component = ((Component)body).GetComponent<BlockTeslaBehavior>();
			if ((Object)(object)component == (Object)null)
			{
				Log.Error("tesla behavior null!");
			}
			else
			{
				component.SetTeslaBlocked(b: true);
			}
		}

		private void DoGrenadeEffect(int grenadeCount, CharacterBody attacker, CharacterBody body)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_008a: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			BlastAttack val = new BlastAttack
			{
				baseDamage = body.damage * (float)(grenadeDamageBase + grenadeDamageStack * grenadeCount),
				radius = grenadeRadiusBase + grenadeRadiusStack * grenadeCount,
				procCoefficient = 0f,
				position = attacker.transform.position,
				attacker = ((Component)body).gameObject,
				baseForce = 0f,
				crit = Util.CheckRoll(body.crit, body.master),
				falloffModel = (FalloffModel)0,
				damageType = DamageTypeCombo.op_Implicit((DamageType)32),
				teamIndex = TeamComponent.GetObjectTeam(((Component)body).gameObject)
			};
			val.Fire();
		}

		private DamageInfo DoCritBlock(HealthComponent self, DamageInfo damageInfo)
		{
			//IL_001d: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			Inventory inventory = self.body.inventory;
			BlockEffect(self, damageInfo);
			float num = 0.5f;
			if (inventory.currentEquipmentIndex == EquipmentCatalog.FindEquipmentIndex("GainArmor"))
			{
				num *= 0.5f;
			}
			int itemCount = inventory.GetItemCount(ItemCatalog.GetItemDef(ItemCatalog.FindItemIndex("OutOfCombatArmor")));
			if (itemCount > 0)
			{
				num *= Mathf.Pow(1f - opalBlockDamageReduction, (float)itemCount);
			}
			damageInfo.damage *= num;
			return damageInfo;
		}

		private void BlockEffect(HealthComponent healthComponent, DamageInfo damageInfo)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			EffectData val = new EffectData
			{
				origin = damageInfo.position,
				rotation = Util.QuaternionSafeLookRotation((damageInfo.force != Vector3.zero) ? damageInfo.force : Random.onUnitSphere)
			};
			EffectManager.SpawnEffect(AssetReferences.bearEffectPrefab, val, true);
		}
	}
	public class BlockTeslaBehavior : ItemBehavior
	{
		private float teslaBuffRollTimer;

		private const float teslaRollInterval = 10f;

		private float teslaFireTimer;

		private float teslaResetListTimer;

		private float teslaResetListInterval = 0.5f;

		private const float teslaFireInterval = 1f / 12f;

		private bool teslaCrit;

		private bool teslaIsOn;

		private List<HealthComponent> previousTeslaTargetList = new List<HealthComponent>();

		private bool _grantingBuff;

		private bool teslaBlocked;

		private BuffDef grantedBuff => Buffs.TeslaField;

		private bool grantingBuff
		{
			get
			{
				return _grantingBuff;
			}
			set
			{
				if (_grantingBuff != value)
				{
					_grantingBuff = value;
					if (_grantingBuff)
					{
						base.body.AddBuff(grantedBuff);
					}
					else
					{
						base.body.RemoveBuff(grantedBuff);
					}
				}
			}
		}

		[ItemDefAssociation(useOnServer = true, useOnClient = false)]
		private static ItemDef GetItemDef()
		{
			return CriticalBlock.blockTeslaItemDef;
		}

		private void FixedUpdate()
		{
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Expected O, but got Unknown
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			teslaBuffRollTimer += Time.fixedDeltaTime;
			if (teslaBuffRollTimer >= 10f)
			{
				teslaBuffRollTimer = 0f;
				teslaCrit = base.body.RollCrit();
				grantingBuff = !grantingBuff;
			}
			if (grantingBuff)
			{
				teslaFireTimer += Time.fixedDeltaTime;
				teslaResetListTimer += Time.fixedDeltaTime;
				if (teslaResetListTimer >= teslaResetListInterval)
				{
					teslaResetListTimer -= teslaResetListInterval;
					previousTeslaTargetList.Clear();
				}
			}
			if (teslaBlocked)
			{
				teslaBlocked = false;
				LightningOrb val = new LightningOrb
				{
					origin = base.body.corePosition,
					damageValue = base.body.damage * 2f,
					isCrit = teslaCrit,
					bouncesRemaining = 2 * base.stack,
					teamIndex = base.body.teamComponent.teamIndex,
					attacker = ((Component)this).gameObject,
					procCoefficient = 0.3f,
					bouncedObjects = previousTeslaTargetList,
					lightningType = (LightningType)1,
					damageColorIndex = (DamageColorIndex)3,
					range = 35f
				};
				HurtBox val2 = val.PickNextTarget(((Component)this).transform.position);
				if (Object.op_Implicit((Object)(object)val2))
				{
					previousTeslaTargetList.Add(val2.healthComponent);
					((Orb)val).target = val2;
					OrbManager.instance.AddOrb((Orb)(object)val);
				}
			}
		}

		private void OnDisable()
		{
			if (Object.op_Implicit((Object)(object)base.body) && base.body.HasBuff(grantedBuff))
			{
				base.body.RemoveBuff(grantedBuff);
			}
		}

		public void SetTeslaBlocked(bool b)
		{
			teslaBlocked = b;
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
}