Decompiled source of DescendantsofTheClouds v2.1.0

plugins/DOTC.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using DOTC.Assets;
using DOTC.Hooks;
using DOTC.Items;
using DOTC.Util;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API;
using RoR2;
using RoR2.Orbs;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DOTC")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DOTC")]
[assembly: AssemblyTitle("DOTC")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DOTC
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.descendants.clouditems", "Descendants of The Clouds", "2.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_RecalculateStats <0>__OnRecalculateStats;

			public static hook_OnHitEnemy <1>__OnHitEnemy;

			public static hook_TakeDamage <2>__OnTakeDamage;

			public static hook_FixedUpdate <3>__OnFixedUpdate;

			public static hook_OnCharacterDeath <4>__OnCharacterDeath;

			public static hook_OnSkillActivated <5>__OnSkillActivated;

			public static hook_OnLanded <6>__OnLanded;
		}

		public const string PluginGUID = "com.descendants.clouditems";

		public const string PluginName = "Descendants of The Clouds";

		public const string PluginVersion = "2.0.0";

		private void Awake()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0060: 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)
			//IL_006b: Expected O, but got Unknown
			//IL_0080: 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_008b: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			AssetLoader.Init(((BaseUnityPlugin)this).Logger);
			ItemDefs.RegisterAll();
			object obj = <>O.<0>__OnRecalculateStats;
			if (obj == null)
			{
				hook_RecalculateStats val = StatsHook.OnRecalculateStats;
				<>O.<0>__OnRecalculateStats = val;
				obj = (object)val;
			}
			CharacterBody.RecalculateStats += (hook_RecalculateStats)obj;
			object obj2 = <>O.<1>__OnHitEnemy;
			if (obj2 == null)
			{
				hook_OnHitEnemy val2 = HitHook.OnHitEnemy;
				<>O.<1>__OnHitEnemy = val2;
				obj2 = (object)val2;
			}
			GlobalEventManager.OnHitEnemy += (hook_OnHitEnemy)obj2;
			object obj3 = <>O.<2>__OnTakeDamage;
			if (obj3 == null)
			{
				hook_TakeDamage val3 = DamageHook.OnTakeDamage;
				<>O.<2>__OnTakeDamage = val3;
				obj3 = (object)val3;
			}
			HealthComponent.TakeDamage += (hook_TakeDamage)obj3;
			object obj4 = <>O.<3>__OnFixedUpdate;
			if (obj4 == null)
			{
				hook_FixedUpdate val4 = UpdateHook.OnFixedUpdate;
				<>O.<3>__OnFixedUpdate = val4;
				obj4 = (object)val4;
			}
			CharacterBody.FixedUpdate += (hook_FixedUpdate)obj4;
			object obj5 = <>O.<4>__OnCharacterDeath;
			if (obj5 == null)
			{
				hook_OnCharacterDeath val5 = CombatHook.OnCharacterDeath;
				<>O.<4>__OnCharacterDeath = val5;
				obj5 = (object)val5;
			}
			GlobalEventManager.OnCharacterDeath += (hook_OnCharacterDeath)obj5;
			object obj6 = <>O.<5>__OnSkillActivated;
			if (obj6 == null)
			{
				hook_OnSkillActivated val6 = CombatHook.OnSkillActivated;
				<>O.<5>__OnSkillActivated = val6;
				obj6 = (object)val6;
			}
			CharacterBody.OnSkillActivated += (hook_OnSkillActivated)obj6;
			object obj7 = <>O.<6>__OnLanded;
			if (obj7 == null)
			{
				hook_OnLanded val7 = CombatHook.OnLanded;
				<>O.<6>__OnLanded = val7;
				obj7 = (object)val7;
			}
			CharacterMotor.OnLanded += (hook_OnLanded)obj7;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Descendants of The Clouds v2.0.0 loaded.");
		}
	}
}
namespace DOTC.Util
{
	internal static class Helpers
	{
		internal static int GetItemCount(CharacterBody body, ItemDef itemDef)
		{
			if (!Object.op_Implicit((Object)(object)body.inventory))
			{
				return 0;
			}
			return body.inventory.GetItemCountPermanent(itemDef);
		}

		internal static NetworkInstanceId GetNetId(CharacterBody body)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)body.networkIdentity))
			{
				return NetworkInstanceId.Invalid;
			}
			return body.networkIdentity.netId;
		}
	}
}
namespace DOTC.Items
{
	internal static class ItemDefs
	{
		internal static ItemDef UpdraftBoots;

		internal static ItemDef CloudCotton;

		internal static ItemDef PressureStabilizer;

		internal static ItemDef SkyCompass;

		internal static ItemDef Weathervane;

		internal static ItemDef CelestialSigil;

		internal static ItemDef AetheriumCore;

		internal static ItemDef StaticDischarge;

		internal static ItemDef SovereignsCrown;

		internal static ItemDef EyeOfTheStorm;

		internal static void RegisterAll()
		{
			UpdraftBoots = AssetLoader.CreateItem("UPDRAFT", "Updraft Boots", "Gain movement speed while airborne.", "Gain <style=cIsUtility>10%</style> <style=cStack>(+10% per stack)</style> movement speed while airborne.", "Boots enchanted to catch the wind. The wearer never truly falls.", "texUpdraftBootsIcon", "mdlUpdraftBootsIcon", (ItemTier)0, (ItemTag)3);
			CloudCotton = AssetLoader.CreateItem("CLOUDCOTTON", "Cloud Cotton", "Reduce gravity and decrease fall speed.", "Reduce gravity by <style=cIsUtility>8%</style> <style=cStack>(+4% per stack)</style>. Decrease fall speed.", "Fiber harvested from the clouds themselves. Impossibly light.", "texCloudCottonIcon", "mdlCloudCottonIcon", (ItemTier)0, (ItemTag)3);
			PressureStabilizer = AssetLoader.CreateItem("STABILIZER", "Pressure Stabilizer", "Reduce skill cooldowns when low health.", "Reduce skill cooldowns by <style=cIsUtility>4%</style> <style=cStack>(+4% per stack)</style> below 50% health.", "When the pressure is on, time moves differently.", "texPressureStabilizerIcon", "mdlPressureStabilizerIcon", (ItemTier)0, (ItemTag)3);
			SkyCompass = AssetLoader.CreateItem("COMPASS", "Sky Compass", "Reveal all interactables.", "Reveal all interactables within <style=cIsUtility>15m</style> <style=cStack>(+15m per stack)</style>.", "It always points toward what you seek.", "texSkyCompassIcon", "mdlSkyCompassIcon", (ItemTier)0, (ItemTag)3);
			Weathervane = AssetLoader.CreateItem("WEATHERVANE", "Weathervane", "Hitting enemies increases movement speed.", "Hitting enemies increases movement speed by <style=cIsUtility>25%</style> for <style=cIsUtility>3s</style> <style=cStack>(+1.5s per stack)</style>.", "Follow the wind. Strike like lightning. Never stop moving.", "texWeathervaneIcon", "mdlWeathervaneIcon", (ItemTier)1, (ItemTag)3);
			CelestialSigil = AssetLoader.CreateItem("CELSIGIL", "Celestial Sigil", "Jumping recharges special cooldown.", "Jumping recharges <style=cIsUtility>8%</style> <style=cStack>(+4% per stack)</style> of special cooldown.", "Each leap brings you closer to divinity.", "texCelestialSigilIcon", "mdlCelestialSigilIcon", (ItemTier)1, (ItemTag)3);
			AetheriumCore = AssetLoader.CreateItem("AETHER", "Aetherium Core", "Gain movement speed on kill.", "On kill, gain <style=cIsUtility>20%</style> movement speed for <style=cIsUtility>5s</style> <style=cStack>(+3s per stack)</style>.", "The heart of a cloud temple. It pulses with stolen momentum.", "texAetheriumCoreIcon", "mdlAetheriumCoreIcon", (ItemTier)1, (ItemTag)3);
			StaticDischarge = AssetLoader.CreateItem("STATIC", "Static Discharge", "Release chain lightning periodically.", "Every <style=cIsDamage>4 hits</style> release chain lightning for <style=cIsDamage>200%</style> <style=cStack>(+100% per stack)</style> damage.", "Build up static. Release it all at once.", "texStaticDischargeIcon", "mdlStaticDischargeIcon", (ItemTier)1, (ItemTag)1);
			SovereignsCrown = AssetLoader.CreateItem("CROWN", "Sovereign's Crown", "Enemies deal less damage, you deal more at high health.", "Enemies within <style=cIsUtility>30m</style> deal <style=cIsUtility>20%</style> less damage. You deal <style=cIsDamage>30%</style> more damage above 80% health.", "Worn by the last king of the clouds.", "texSovereignsCrownIcon", "mdlSovereignsCrownIcon", (ItemTier)2, (ItemTag)1, (ItemTag)3);
			EyeOfTheStorm = AssetLoader.CreateItem("EYESTORM", "Eye of the Storm", "Gain attack speed... BUT skills cost health.", "Gain <style=cIsDamage>100%</style> attack speed. <style=cIsHealth>BUT skills cost 20% max health instead of cooldowns.</style>", "In the center of chaos, there is perfect clarity.", "texEyeOfTheStormIcon", "mdlEyeOfTheStormIcon", (ItemTier)3, (ItemTag)1);
		}
	}
}
namespace DOTC.Hooks
{
	internal static class CombatHook
	{
		private const float AetherDurationBase = 5f;

		private const float AetherDurationPerStack = 3f;

		private const float SigilRechargeBase = 0.08f;

		private const float SigilRechargePerStack = 0.04f;

		private const float EyeHealthCostFraction = 0.2f;

		internal static void OnCharacterDeath(orig_OnCharacterDeath orig, GlobalEventManager self, DamageReport report)
		{
			orig.Invoke(self, report);
			if (NetworkServer.active && !((Object)(object)report.attackerBody == (Object)null) && !((Object)(object)report.attackerBody.inventory == (Object)null))
			{
				ProcessAetheriumCoreKill(report.attackerBody);
			}
		}

		internal static void OnSkillActivated(orig_OnSkillActivated orig, CharacterBody body, GenericSkill skill)
		{
			orig.Invoke(body, skill);
			if (!((Object)(object)body == (Object)null) && !((Object)(object)body.inventory == (Object)null) && NetworkServer.active)
			{
				ProcessCelestialSigilSkill(body);
				ProcessEyeOfTheStormSkill(body, skill);
			}
		}

		internal static void OnLanded(orig_OnLanded orig, CharacterMotor motor)
		{
			orig.Invoke(motor);
			if (!((Object)(object)motor == (Object)null) && !((Object)(object)motor.body == (Object)null) && !((Object)(object)motor.body.inventory == (Object)null) && NetworkServer.active)
			{
				ProcessCelestialSigilLanding(motor.body);
			}
		}

		private static void ProcessAetheriumCoreKill(CharacterBody attacker)
		{
			//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_0018: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			int itemCount = Helpers.GetItemCount(attacker, ItemDefs.AetheriumCore);
			if (itemCount > 0)
			{
				NetworkInstanceId netId = Helpers.GetNetId(attacker);
				if (!(netId == NetworkInstanceId.Invalid))
				{
					float duration = 5f + 3f * (float)(itemCount - 1);
					StateTracker.SetAetherTimer(netId, duration);
				}
			}
		}

		private static void ProcessCelestialSigilSkill(CharacterBody body)
		{
			int itemCount = Helpers.GetItemCount(body, ItemDefs.CelestialSigil);
			if (itemCount > 0 && !((Object)(object)body.skillLocator == (Object)null) && !((Object)(object)body.skillLocator.special == (Object)null) && !((Object)(object)body.characterMotor == (Object)null) && !body.characterMotor.isGrounded)
			{
				float num = 0.08f + 0.04f * (float)(itemCount - 1);
				GenericSkill special = body.skillLocator.special;
				special.rechargeStopwatch += body.skillLocator.special.finalRechargeInterval * num;
			}
		}

		private static void ProcessCelestialSigilLanding(CharacterBody body)
		{
			int itemCount = Helpers.GetItemCount(body, ItemDefs.CelestialSigil);
			if (itemCount > 0 && !((Object)(object)body.skillLocator == (Object)null) && !((Object)(object)body.skillLocator.special == (Object)null))
			{
				float num = 0.08f + 0.04f * (float)(itemCount - 1);
				GenericSkill special = body.skillLocator.special;
				special.rechargeStopwatch += body.skillLocator.special.finalRechargeInterval * num;
			}
		}

		private static void ProcessEyeOfTheStormSkill(CharacterBody body, GenericSkill skill)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			if (Helpers.GetItemCount(body, ItemDefs.EyeOfTheStorm) > 0 && !((Object)(object)body.healthComponent == (Object)null) && (!((Object)(object)body.skillLocator != (Object)null) || !((Object)(object)skill == (Object)(object)body.skillLocator.primary)))
			{
				body.healthComponent.TakeDamage(new DamageInfo
				{
					damage = body.healthComponent.fullHealth * 0.2f,
					attacker = ((Component)body).gameObject,
					position = body.transform.position,
					damageType = DamageTypeCombo.op_Implicit((DamageType)66),
					procCoefficient = 0f
				});
				skill.stock = Mathf.Max(skill.stock, 1);
			}
		}
	}
	internal static class DamageHook
	{
		private const float CrownDamageReductionRange = 30f;

		private const float CrownDamageReductionMultiplier = 0.8f;

		internal static void OnTakeDamage(orig_TakeDamage orig, HealthComponent self, DamageInfo damageInfo)
		{
			if ((Object)(object)self.body != (Object)null && (Object)(object)self.body.inventory != (Object)null && (Object)(object)damageInfo.attacker != (Object)null)
			{
				ApplyCrownDamageReduction(self.body, damageInfo);
			}
			orig.Invoke(self, damageInfo);
		}

		private static void ApplyCrownDamageReduction(CharacterBody victim, DamageInfo damageInfo)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (Helpers.GetItemCount(victim, ItemDefs.SovereignsCrown) > 0 && Vector3.Distance(victim.transform.position, damageInfo.attacker.transform.position) <= 30f)
			{
				damageInfo.damage *= 0.8f;
			}
		}
	}
	internal static class HitHook
	{
		private const float WeathervaneDurationBase = 3f;

		private const float WeathervaneDurationPerStack = 1.5f;

		private const int StaticDischargeHitThreshold = 4;

		private const float StaticDischargeDamageBase = 2f;

		private const float StaticDischargeDamagePerStack = 1f;

		private const int StaticDischargeBounces = 3;

		private const float StaticDischargeProcCoefficient = 0.3f;

		internal static void OnHitEnemy(orig_OnHitEnemy orig, GlobalEventManager self, DamageInfo damageInfo, GameObject victim)
		{
			orig.Invoke(self, damageInfo, victim);
			if (!((Object)(object)damageInfo.attacker == (Object)null) && NetworkServer.active)
			{
				CharacterBody component = damageInfo.attacker.GetComponent<CharacterBody>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component.inventory == (Object)null))
				{
					CharacterBody victimBody = (((Object)(object)victim != (Object)null) ? victim.GetComponent<CharacterBody>() : null);
					ProcessWeathervane(component, damageInfo);
					ProcessStaticDischarge(component, damageInfo, victimBody);
				}
			}
		}

		private static void ProcessWeathervane(CharacterBody attacker, DamageInfo damageInfo)
		{
			int itemCount = Helpers.GetItemCount(attacker, ItemDefs.Weathervane);
			if (itemCount > 0)
			{
				float num = 3f + 1.5f * (float)(itemCount - 1);
				attacker.AddTimedBuff(Buffs.WhipBoost, num);
			}
		}

		private static void ProcessStaticDischarge(CharacterBody attacker, DamageInfo damageInfo, CharacterBody victimBody)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			int itemCount = Helpers.GetItemCount(attacker, ItemDefs.StaticDischarge);
			if (itemCount <= 0 || (Object)(object)victimBody == (Object)null || (Object)(object)victimBody.mainHurtBox == (Object)null || (Object)(object)attacker.teamComponent == (Object)null)
			{
				return;
			}
			NetworkInstanceId netId = Helpers.GetNetId(attacker);
			if (!(netId == NetworkInstanceId.Invalid) && StateTracker.IncrementHitCount(netId) >= 4)
			{
				StateTracker.ResetHitCount(netId);
				float damageValue = attacker.damage * (2f + 1f * (float)(itemCount - 1));
				LightningOrb val = new LightningOrb
				{
					origin = damageInfo.position,
					damageValue = damageValue,
					isCrit = attacker.RollCrit(),
					bouncesRemaining = 3,
					teamIndex = attacker.teamComponent.teamIndex,
					attacker = damageInfo.attacker,
					procCoefficient = 0.3f,
					lightningType = (LightningType)1,
					damageColorIndex = (DamageColorIndex)3,
					range = 20f,
					target = victimBody.mainHurtBox
				};
				if ((Object)(object)OrbManager.instance != (Object)null)
				{
					OrbManager.instance.AddOrb((Orb)(object)val);
				}
			}
		}
	}
	internal static class StateTracker
	{
		private static readonly Dictionary<NetworkInstanceId, int> _hitCounts = new Dictionary<NetworkInstanceId, int>();

		private static readonly Dictionary<NetworkInstanceId, float> _aetherTimers = new Dictionary<NetworkInstanceId, float>();

		private static readonly Dictionary<NetworkInstanceId, float> _compassTimers = new Dictionary<NetworkInstanceId, float>();

		internal static int IncrementHitCount(NetworkInstanceId id)
		{
			//IL_0005: 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)
			_hitCounts.TryGetValue(id, out var value);
			int num = value + 1;
			_hitCounts[id] = num;
			return num;
		}

		internal static void ResetHitCount(NetworkInstanceId id)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			_hitCounts[id] = 0;
		}

		internal static void SetAetherTimer(NetworkInstanceId id, float duration)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			_aetherTimers[id] = duration;
		}

		internal static bool IsAetherSpeedActive(NetworkInstanceId id)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (_aetherTimers.TryGetValue(id, out var value))
			{
				return value > 0f;
			}
			return false;
		}

		internal static void TickAetherTimer(NetworkInstanceId id, float deltaTime)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (_aetherTimers.TryGetValue(id, out var value) && value > 0f)
			{
				_aetherTimers[id] = value - deltaTime;
			}
		}

		internal static bool ShouldUpdateCompass(NetworkInstanceId id, float deltaTime, float interval)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			_compassTimers.TryGetValue(id, out var value);
			value += deltaTime;
			if (value >= interval)
			{
				_compassTimers[id] = 0f;
				return true;
			}
			_compassTimers[id] = value;
			return false;
		}

		internal static void CleanupPlayer(NetworkInstanceId id)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			_hitCounts.Remove(id);
			_aetherTimers.Remove(id);
			_compassTimers.Remove(id);
		}

		internal static void CleanupAll()
		{
			_hitCounts.Clear();
			_aetherTimers.Clear();
			_compassTimers.Clear();
		}
	}
	internal static class StatsHook
	{
		private const float UpdraftMoveSpeedPerStack = 0.1f;

		private const float CrownHealthThreshold = 0.8f;

		private const float CrownDamageBonus = 1.3f;

		private const float EyeAttackSpeedMultiplier = 2f;

		private const float AetherMoveSpeedMultiplier = 1.2f;

		internal static void OnRecalculateStats(orig_RecalculateStats orig, CharacterBody body)
		{
			orig.Invoke(body);
			if (!((Object)(object)body == (Object)null) && !((Object)(object)body.inventory == (Object)null))
			{
				ApplyUpdraftBoots(body);
				ApplySovereignsCrownDamage(body);
				ApplyEyeOfTheStorm(body);
				ApplyAetheriumCoreSpeed(body);
			}
		}

		private static void ApplyUpdraftBoots(CharacterBody body)
		{
			int itemCount = Helpers.GetItemCount(body, ItemDefs.UpdraftBoots);
			if (itemCount > 0 && !((Object)(object)body.characterMotor == (Object)null) && !body.characterMotor.isGrounded)
			{
				body.moveSpeed *= 1f + 0.1f * (float)itemCount;
			}
		}

		private static void ApplySovereignsCrownDamage(CharacterBody body)
		{
			if (Helpers.GetItemCount(body, ItemDefs.SovereignsCrown) > 0 && !((Object)(object)body.healthComponent == (Object)null) && body.healthComponent.combinedHealthFraction > 0.8f)
			{
				body.damage *= 1.3f;
			}
		}

		private static void ApplyEyeOfTheStorm(CharacterBody body)
		{
			if (Helpers.GetItemCount(body, ItemDefs.EyeOfTheStorm) > 0)
			{
				body.attackSpeed *= 2f;
			}
		}

		private static void ApplyAetheriumCoreSpeed(CharacterBody body)
		{
			//IL_0010: 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_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)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (Helpers.GetItemCount(body, ItemDefs.AetheriumCore) > 0)
			{
				NetworkInstanceId netId = Helpers.GetNetId(body);
				if (!(netId == NetworkInstanceId.Invalid) && StateTracker.IsAetherSpeedActive(netId))
				{
					body.moveSpeed *= 1.2f;
				}
			}
		}
	}
	internal static class UpdateHook
	{
		private const float StabilizerCooldownReductionPerStack = 0.04f;

		private const float StabilizerHealthThreshold = 0.5f;

		private const float CompassRangePerStack = 15f;

		private const float CompassCheckInterval = 0.5f;

		private const float CottonFallDampenBase = 0.016f;

		private const float CottonFallDampenPerStack = 0.04f;

		internal static void OnFixedUpdate(orig_FixedUpdate orig, CharacterBody body)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_0049: 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)
			orig.Invoke(body);
			if (!((Object)(object)body == (Object)null) && !((Object)(object)body.inventory == (Object)null) && NetworkServer.active)
			{
				NetworkInstanceId netId = Helpers.GetNetId(body);
				if (!(netId == NetworkInstanceId.Invalid))
				{
					float fixedDeltaTime = Time.fixedDeltaTime;
					ProcessPressureStabilizer(body, fixedDeltaTime);
					ProcessSkyCompass(body, netId, fixedDeltaTime);
					ProcessCloudCottonGravity(body);
					StateTracker.TickAetherTimer(netId, fixedDeltaTime);
				}
			}
		}

		private static void ProcessPressureStabilizer(CharacterBody body, float deltaTime)
		{
			int itemCount = Helpers.GetItemCount(body, ItemDefs.PressureStabilizer);
			if (itemCount > 0 && !((Object)(object)body.healthComponent == (Object)null) && !(body.healthComponent.combinedHealthFraction >= 0.5f) && !((Object)(object)body.skillLocator == (Object)null))
			{
				float num = 0.04f * (float)itemCount * deltaTime;
				SkillLocator skillLocator = body.skillLocator;
				if ((Object)(object)skillLocator.primary != (Object)null && skillLocator.primary.stock < skillLocator.primary.maxStock)
				{
					GenericSkill primary = skillLocator.primary;
					primary.rechargeStopwatch += num;
				}
				if ((Object)(object)skillLocator.secondary != (Object)null && skillLocator.secondary.stock < skillLocator.secondary.maxStock)
				{
					GenericSkill secondary = skillLocator.secondary;
					secondary.rechargeStopwatch += num;
				}
				if ((Object)(object)skillLocator.utility != (Object)null && skillLocator.utility.stock < skillLocator.utility.maxStock)
				{
					GenericSkill utility = skillLocator.utility;
					utility.rechargeStopwatch += num;
				}
				if ((Object)(object)skillLocator.special != (Object)null && skillLocator.special.stock < skillLocator.special.maxStock)
				{
					GenericSkill special = skillLocator.special;
					special.rechargeStopwatch += num;
				}
			}
		}

		private static void ProcessSkyCompass(CharacterBody body, NetworkInstanceId netId, float deltaTime)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			int itemCount = Helpers.GetItemCount(body, ItemDefs.SkyCompass);
			if (itemCount <= 0 || !StateTracker.ShouldUpdateCompass(netId, deltaTime, 0.5f))
			{
				return;
			}
			float num = 15f * (float)itemCount;
			float num2 = num * num;
			Vector3 position = body.transform.position;
			foreach (PurchaseInteraction instances in InstanceTracker.GetInstancesList<PurchaseInteraction>())
			{
				if ((Object)(object)instances == (Object)null || !instances.available)
				{
					continue;
				}
				Vector3 val = ((Component)instances).transform.position - position;
				if (!(((Vector3)(ref val)).sqrMagnitude > num2))
				{
					Highlight component = ((Component)instances).GetComponent<Highlight>();
					if ((Object)(object)component != (Object)null)
					{
						component.highlightColor = (HighlightColor)0;
						component.isOn = true;
					}
				}
			}
		}

		private static void ProcessCloudCottonGravity(CharacterBody body)
		{
			//IL_007b: 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)
			int itemCount = Helpers.GetItemCount(body, ItemDefs.CloudCotton);
			if (itemCount > 0)
			{
				CharacterMotor characterMotor = body.characterMotor;
				if (!((Object)(object)characterMotor == (Object)null) && !(characterMotor.velocity.y >= 0f))
				{
					float num = 0.016f + 0.04f * (float)(itemCount - 1);
					num = Mathf.Min(num, 0.9f);
					characterMotor.velocity = new Vector3(characterMotor.velocity.x, characterMotor.velocity.y * (1f - num), characterMotor.velocity.z);
				}
			}
		}
	}
}
namespace DOTC.Assets
{
	internal static class AssetLoader
	{
		private static AssetBundle _bundle;

		private static ManualLogSource _log;

		private static readonly string[] _pathFormats = new string[10] { "assets/clouditems/{0}.{1}", "Assets/CloudItems/{2}.{1}", "assets/clouditems/{2}.{1}", "{2}", "assets/clouditems/{2}", "Assets/CloudItems/{2}", "assets/{2}", "Assets/{2}", "{0}", "assets/clouditems/{0}" };

		internal static void Init(ManualLogSource log)
		{
			_log = log;
			LoadBundle();
		}

		private static void LoadBundle()
		{
			try
			{
				string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				_log.LogInfo((object)("plugin directory: " + directoryName));
				string text = null;
				string[] files = Directory.GetFiles(directoryName);
				foreach (string text2 in files)
				{
					if (Path.GetFileName(text2).ToLower() == "clouditemsassets")
					{
						text = text2;
						_log.LogInfo((object)("correct bundle: " + text2));
						break;
					}
				}
				if (text == null)
				{
					_log.LogError((object)("cannot find clouditemsassets in " + directoryName));
					return;
				}
				_bundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)_bundle == (Object)null)
				{
					_log.LogWarning((object)"LoadFromFile returned nothing. trying to load it from memory");
					try
					{
						byte[] array = File.ReadAllBytes(text);
						_log.LogInfo((object)$"Read {array.Length} bytes");
						_bundle = AssetBundle.LoadFromMemory(array);
						if ((Object)(object)_bundle == (Object)null)
						{
							_log.LogError((object)"cannot load it from mem returned null. bundle is most likely corrupt");
						}
					}
					catch (Exception ex)
					{
						_log.LogError((object)("LoadFromMemory failed: " + ex.Message));
					}
				}
				if ((Object)(object)_bundle != (Object)null)
				{
					_log.LogInfo((object)$"Loaded {_bundle.GetAllAssetNames().Length} assets");
					files = _bundle.GetAllAssetNames();
					foreach (string text3 in files)
					{
						_log.LogInfo((object)("asset bundle   - " + text3));
					}
					_bundle.LoadAsset<Font>("Assets/CloudItems/Font.ttf");
				}
			}
			catch (Exception ex2)
			{
				_log.LogError((object)("asset bundle Exception: " + ex2.Message + "\n" + ex2.StackTrace));
			}
		}

		private static string[] BuildSearchPaths(string name, string extension)
		{
			string[] array = new string[_pathFormats.Length];
			for (int i = 0; i < _pathFormats.Length; i++)
			{
				array[i] = string.Format(_pathFormats[i], name.ToLower(), extension, name);
			}
			return array;
		}

		private static T LoadAsset<T>(string name, string extension) where T : Object
		{
			if ((Object)(object)_bundle == (Object)null)
			{
				return default(T);
			}
			string[] array = BuildSearchPaths(name, extension);
			foreach (string text in array)
			{
				T val = _bundle.LoadAsset<T>(text);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return default(T);
		}

		internal static Sprite LoadIcon(string textureName, ItemTier tier)
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected I4, but got Unknown
			//IL_0052: 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)
			if ((Object)(object)_bundle != (Object)null)
			{
				Sprite val = LoadAsset<Sprite>(textureName, "png");
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
				Texture2D val2 = LoadAsset<Texture2D>(textureName, "png");
				if ((Object)(object)val2 != (Object)null)
				{
					return Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f), 100f);
				}
				_log.LogWarning((object)("LoadIcon could not find " + textureName + ", using a placeholder"));
			}
			return LegacyResourcesAPI.Load<Sprite>((int)tier switch
			{
				0 => "Textures/ItemIcons/texMonsterToothIcon", 
				1 => "Textures/ItemIcons/texInfusionIcon", 
				2 => "Textures/ItemIcons/texDaggerIcon", 
				3 => "Textures/ItemIcons/texLunarPrimaryReplacementIcon", 
				_ => "Textures/MiscIcons/texMysteryIcon", 
			});
		}

		internal static GameObject LoadModel(string modelName, ItemTier tier)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected I4, but got Unknown
			if ((Object)(object)_bundle != (Object)null)
			{
				GameObject val = LoadAsset<GameObject>(modelName, "prefab");
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
				_log.LogWarning((object)("LoadModel could not find " + modelName + ", using placeholder"));
			}
			return LegacyResourcesAPI.Load<GameObject>((int)tier switch
			{
				0 => "Prefabs/PickupModels/PickupMonsterTooth", 
				1 => "Prefabs/PickupModels/PickupInfusion", 
				2 => "Prefabs/PickupModels/PickupDagger", 
				3 => "Prefabs/PickupModels/PickupLunarPrimaryReplacement", 
				_ => "Prefabs/PickupModels/PickupMystery", 
			});
		}

		internal static ItemDef CreateItem(string name, string displayName, string pickup, string description, string lore, string textureName, string modelName, ItemTier tier, params ItemTag[] tags)
		{
			//IL_000e: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected I4, but got Unknown
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Expected O, but got Unknown
			ItemDef val = ScriptableObject.CreateInstance<ItemDef>();
			((Object)val).name = name;
			val.tier = tier;
			val.tags = tags;
			val.canRemove = true;
			val.hidden = false;
			val.pickupIconSprite = LoadIcon(textureName, tier);
			val.pickupModelPrefab = LoadModel(modelName, tier);
			string text = "ITEM_" + name + "_";
			val.nameToken = text + "NAME";
			val.pickupToken = text + "PICKUP";
			val.descriptionToken = text + "DESC";
			val.loreToken = text + "LORE";
			ItemDef val2 = val;
			val2._itemTierDef = LegacyResourcesAPI.Load<ItemTierDef>((int)tier switch
			{
				0 => "ItemTierDefs/Tier1Def", 
				1 => "ItemTierDefs/Tier2Def", 
				2 => "ItemTierDefs/Tier3Def", 
				3 => "ItemTierDefs/LunarTierDef", 
				_ => null, 
			});
			LanguageAPI.Add(text + "NAME", displayName);
			LanguageAPI.Add(text + "PICKUP", pickup);
			LanguageAPI.Add(text + "DESC", description);
			LanguageAPI.Add(text + "LORE", lore);
			ItemAPI.Add(new CustomItem(val, (ItemDisplayRule[])(object)new ItemDisplayRule[0]));
			return val;
		}
	}
}