Decompiled source of KingItems v1.5.2

KingItems.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using EntityStates;
using EntityStates.ClayBruiser.Weapon;
using EntityStates.GolemMonster;
using EntityStates.TitanMonster;
using NS_KingModUtilities;
using On.EntityStates;
using On.EntityStates.ClayBruiser.Weapon;
using On.EntityStates.GolemMonster;
using On.EntityStates.TitanMonster;
using On.RoR2;
using On.RoR2.Orbs;
using On.RoR2.Projectile;
using On.RoR2.UI;
using R2API.Utils;
using RoR2;
using RoR2.Orbs;
using RoR2.Projectile;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.Rendering.PostProcessing;

[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("KingItems")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a5790920c755d57347597c47bdd484c8830f475b")]
[assembly: AssemblyProduct("KingItems")]
[assembly: AssemblyTitle("KingItems")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NS_KingItems;

public class TimeStopFreezeState : BaseState
{
	public float duration;

	public override void OnEnter()
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		((BaseState)this).OnEnter();
		Animator modelAnimator = ((EntityState)this).GetModelAnimator();
		if (Object.op_Implicit((Object)(object)modelAnimator))
		{
			((Behaviour)modelAnimator).enabled = false;
		}
		if (Object.op_Implicit((Object)(object)((EntityState)this).rigidbody) && !((EntityState)this).rigidbody.isKinematic)
		{
			((EntityState)this).rigidbody.velocity = Vector3.zero;
			if (Object.op_Implicit((Object)(object)((EntityState)this).rigidbodyMotor))
			{
				((EntityState)this).rigidbodyMotor.moveVector = Vector3.zero;
			}
		}
	}

	public override void OnExit()
	{
		Animator modelAnimator = ((EntityState)this).GetModelAnimator();
		if (Object.op_Implicit((Object)(object)modelAnimator))
		{
			((Behaviour)modelAnimator).enabled = true;
		}
		((EntityState)this).OnExit();
	}

	public override void FixedUpdate()
	{
		((EntityState)this).FixedUpdate();
		if (((EntityState)this).isAuthority && ((EntityState)this).fixedAge >= duration)
		{
			((EntityState)this).outer.SetNextStateToMain();
		}
	}

	public override InterruptPriority GetMinimumInterruptPriority()
	{
		return (InterruptPriority)7;
	}
}
public static class ItemsSounds
{
	public static readonly uint TimeResumeSFX = 3090400288u;

	public static readonly uint TimeStopSFX = 2383709427u;
}
public class DiosHead
{
	private static GameObject timeStopFX;

	private static CharacterBody characterBodyUsed = null;

	private static readonly float TIMESTOP_DURATION = 9f;

	private static readonly float TIMESTOP_STARTUP_DURATION = 2f;

	private static bool TIMESTOP_ACTIVE = false;

	private static bool TIMESTOP_FREEZE_PROJECTILES = false;

	private static bool TIMESTOP_FREEZE_SPAWNS = false;

	private static float FREEZE_TIMER = 0f;

	private static readonly float FREEZE_TIMER_INTERVAL = 1f;

	private static float TIMESTOP_STARTED_TIME = 0f;

	private static LTSeq currentSequence = null;

	private static readonly List<PostProcessLayer> deferredScenePostProcessLayers = new List<PostProcessLayer>();

	private static bool recachePostProcessNextUpdate = false;

	public static EquipmentDef CreateCustomEquipmentDef()
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Expected O, but got Unknown
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Expected O, but got Unknown
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Expected O, but got Unknown
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Expected O, but got Unknown
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Expected O, but got Unknown
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Expected O, but got Unknown
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Expected O, but got Unknown
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Expected O, but got Unknown
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: 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
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Expected O, but got Unknown
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Expected O, but got Unknown
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Expected O, but got Unknown
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Expected O, but got Unknown
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Expected O, but got Unknown
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Expected O, but got Unknown
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Expected O, but got Unknown
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Expected O, but got Unknown
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Expected O, but got Unknown
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Expected O, but got Unknown
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Expected O, but got Unknown
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Expected O, but got Unknown
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Expected O, but got Unknown
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Expected O, but got Unknown
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Expected O, but got Unknown
		ScriptableObject obj = ScriptableObject.CreateInstance(typeof(EquipmentDef));
		ScriptableObject obj2 = ((obj is EquipmentDef) ? obj : null);
		((Object)obj2).name = CreateName();
		((EquipmentDef)obj2).appearsInMultiPlayer = false;
		((EquipmentDef)obj2).appearsInSinglePlayer = true;
		((EquipmentDef)obj2).isBoss = false;
		((EquipmentDef)obj2).isLunar = false;
		((EquipmentDef)obj2).canDrop = true;
		((EquipmentDef)obj2).colorIndex = (ColorIndex)5;
		((EquipmentDef)obj2).enigmaCompatible = true;
		((EquipmentDef)obj2).pickupIconSprite = KingItemsAssets.Img_DiosHead;
		((EquipmentDef)obj2).pickupModelPrefab = KingItemsAssets.DiosHead;
		((EquipmentDef)obj2).loreToken = CreateItemLore();
		((EquipmentDef)obj2).descriptionToken = CreateItemComplexDescription();
		((EquipmentDef)obj2).pickupToken = CreateItemSimpleDescription();
		((EquipmentDef)obj2).nameToken = CreateNameToken();
		((EquipmentDef)obj2).cooldown = 300f;
		CombatDirector.Simulate += new hook_Simulate(CombatDirector_Simulate_Hook);
		ProjectileSimple.FixedUpdate += new hook_FixedUpdate(ProjectileSimple_FixedUpdate_Hook);
		Run.ShouldUpdateRunStopwatch += new hook_ShouldUpdateRunStopwatch(Run_ShouldUpdateRunStopwatch_Hook);
		OrbEffect.UpdateOrb += new hook_UpdateOrb(OrbEffect_UpdateOrb_Hook);
		OrbManager.FixedUpdate += new hook_FixedUpdate(OrbManager_FixedUpdate_Hook);
		SetStateOnHurt.SetFrozen += new hook_SetFrozen(SetStateOnHurt_SetFrozen_Hook);
		SetStateOnHurt.SetStun += new hook_SetStun(SetStateOnHurt_SetStun_Hook);
		SetStateOnHurt.SetPain += new hook_SetPain(SetStateOnHurt_SetPain_Hook);
		ProjectileImpactExplosion.FixedUpdate += new hook_FixedUpdate(ProjectileImpactExplosion_FixedUpdate_Hook);
		RigidbodyMotor.FixedUpdate += new hook_FixedUpdate(RigidbodyMotor_FixedUpdate_Hook);
		DelayBlast.FixedUpdate += new hook_FixedUpdate(DelayBlast_FixedUpdate_Hook);
		DestroyOnTimer.FixedUpdate += new hook_FixedUpdate(DestroyOnTimer_FixedUpdate_Hook);
		ChargeLaser.Update += new hook_Update(ChargeLaser_Update);
		ChargeLaser.FixedUpdate += new hook_FixedUpdate(ChargeLaser_FixedUpdate);
		ChargeMegaLaser.Update += new hook_Update(ChargeMegaLaser_Update_Hook);
		ChargeMegaLaser.FixedUpdate += new hook_FixedUpdate(ChargeMegaLaser_FixedUpdate_Hook);
		FireMegaLaser.FixedUpdate += new hook_FixedUpdate(FireMegaLaser_FixedUpdate_Hook);
		ChargeGoldMegaLaser.FixedUpdate += new hook_FixedUpdate(ChargeGoldMegaLaser_FixedUpdate_Hook);
		FireGoldMegaLaser.FixedUpdate += new hook_FixedUpdate(FireGoldMegaLaser_FixedUpdate_Hook);
		WormBodyPositionsDriver.FixedUpdateServer += new hook_FixedUpdateServer(WormBodyPositionsDriver_FixedUpdateServer_Hook);
		WormBodyPositions2.OnDeathStart += new hook_OnDeathStart(WormBodyPositions2_OnDeathStart_Hook);
		MinigunFire.FixedUpdate += new hook_FixedUpdate(MinigunFire_FixedUpdate_Hook);
		GenericCharacterDeath.OnEnter += new hook_OnEnter(GenericCharacterDeath_OnEnter_Hook);
		MainPlugin.s_updateAction = (Action)Delegate.Combine(MainPlugin.s_updateAction, new Action(IntervalFreeze_Update_Hook));
		MainPlugin.s_delegate_OnStageStarted = (VoidDelegate)Delegate.Combine((Delegate?)(object)MainPlugin.s_delegate_OnStageStarted, (Delegate?)new VoidDelegate(ResetTimeStopValues));
		return (EquipmentDef)(object)obj2;
	}

	private static Vector3 GenerateTimeStopFrozenVelocity(Rigidbody rb)
	{
		//IL_0031: 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)
		bool flag = false;
		AntiGravityForce component = ((Component)rb).GetComponent<AntiGravityForce>();
		if ((Object)(object)component != (Object)null)
		{
			flag = component.antiGravityCoefficient == 1f;
		}
		if (!rb.useGravity || flag)
		{
			return Vector3.zero;
		}
		return new Vector3(0f, 0.5f - (MainPlugin.IsInStage("moon2") ? 0.16f : 0f), 0f);
	}

	private static void RigidbodyMotor_FixedUpdate_Hook(orig_FixedUpdate orig, RigidbodyMotor self)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self);
		}
		else
		{
			self.rigid.velocity = GenerateTimeStopFrozenVelocity(self.rigid);
		}
	}

	public static string CreateName()
	{
		return "DiosHead";
	}

	public static string CreateNameToken()
	{
		return "Dio's Head";
	}

	public static string CreateItemComplexDescription()
	{
		return CreateItemSimpleDescription();
	}

	public static string CreateItemSimpleDescription()
	{
		return "Unleash Dio's Stand..." + MainPlugin.ColorText("Stopping Time", "#03f4fc") + " for 9 Seconds.";
	}

	public static string CreateItemLore()
	{
		return "Dio's signature power is its ability to stop time, allowing DIO and anyone with the same power, to act within the duration of stopped time.";
	}

	public static bool OnCustomEquipmentActivated(EquipmentSlot self)
	{
		if (!RoR2Application.isInSinglePlayer)
		{
			return false;
		}
		if ((((Object)(object)self != (Object)null) & ((Object)(object)self.characterBody != (Object)null)) && (Object)(object)self.characterBody.healthComponent != (Object)null && self.characterBody.healthComponent.alive && !TIMESTOP_ACTIVE)
		{
			TIMESTOP_ACTIVE = true;
			characterBodyUsed = self.characterBody;
			OnTimeStop_Start();
			return true;
		}
		return false;
	}

	public static void IntervalFreeze_Update_Hook()
	{
		if (recachePostProcessNextUpdate)
		{
			recachePostProcessNextUpdate = false;
			EnableDeferredScenePostProcessLayers();
		}
		if ((Object)(object)Run.instance != (Object)null && TIMESTOP_ACTIVE)
		{
			FREEZE_TIMER -= Time.deltaTime;
			if (FREEZE_TIMER <= 0f)
			{
				TimeStopFreezeAllEnemies();
				FREEZE_TIMER = FREEZE_TIMER_INTERVAL;
			}
			if ((Object)(object)characterBodyUsed == (Object)null && (Object)(object)timeStopFX == (Object)null)
			{
				MainPlugin.DebugLog("WTF? Time Stop Got Stuck, lets abort it just incase?!?");
				ForceEndTimeStop();
			}
		}
	}

	public static void TimeStopFreezeAllEnemies()
	{
		//IL_0017: 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_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)characterBodyUsed != (Object)null)
		{
			Vector3 position = ((Component)characterBodyUsed).transform.position;
			LayerIndex entityPrecise = LayerIndex.entityPrecise;
			TimeStopEnemies(Physics.OverlapSphere(position, float.MaxValue, LayerMask.op_Implicit(((LayerIndex)(ref entityPrecise)).mask)).ToArray(), characterBodyUsed, TIMESTOP_STARTED_TIME + (TIMESTOP_STARTUP_DURATION + TIMESTOP_DURATION + TIMESTOP_STARTUP_DURATION - 1f) - Time.time);
		}
	}

	public static void FXStart_OnUpdate(float timeRatio)
	{
		((ParameterOverride<float>)(object)timeStopFX.GetComponent<PostProcessVolume>().profile.GetSetting<ColorGrading>().hueShift).value = 0f + Mathf.Lerp(0f, 180f, timeRatio);
		((ParameterOverride<float>)(object)timeStopFX.GetComponent<PostProcessVolume>().profile.GetSetting<LensDistortion>().intensity).value = 0f + Mathf.Lerp(0f, 80f, timeRatio);
		NotifyTimeStopPostProcessChanged();
	}

	public static void FXStart_Middle_OnComplete()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		LeanTween.scale(timeStopFX, new Vector3(0f, 0f, 0f), TIMESTOP_STARTUP_DURATION / 2f).setOnComplete((Action)FXStart_End_OnComplete).setOnUpdate((Action<float>)FXStart_End_OnUpdate)
			.setEase((LeanTweenType)6);
	}

	public static void FXStart_End_OnComplete()
	{
		currentSequence = LeanTween.sequence(true);
		currentSequence.append(TIMESTOP_DURATION);
		currentSequence.append((Action)FXEnd);
	}

	public static void FXStart_End_OnUpdate(float timeRatio)
	{
		((ParameterOverride<float>)(object)timeStopFX.GetComponent<PostProcessVolume>().profile.GetSetting<ColorGrading>().saturation).value = Mathf.Lerp(0f, -75f, timeRatio);
		((ParameterOverride<float>)(object)timeStopFX.GetComponent<PostProcessVolume>().profile.GetSetting<LensDistortion>().intensity).value = 0f + Mathf.Lerp(80f, 0f, timeRatio);
		NotifyTimeStopPostProcessChanged();
	}

	public static void FXEnd()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)timeStopFX != (Object)null)
		{
			MainPlugin.PlaySoundEvent(timeStopFX, ItemsSounds.TimeResumeSFX, 100);
			LeanTween.scale(timeStopFX, new Vector3(15f, 15f, 15f), TIMESTOP_STARTUP_DURATION / 2f).setOnComplete((Action)FXEnd_Middle_OnComplete).setOnUpdate((Action<float>)FXEnd_OnUpdate);
		}
	}

	public static void FXEnd_OnUpdate(float timeRatio)
	{
		((ParameterOverride<float>)(object)timeStopFX.GetComponent<PostProcessVolume>().profile.GetSetting<LensDistortion>().intensity).value = 0f + Mathf.Lerp(0f, 80f, timeRatio);
		NotifyTimeStopPostProcessChanged();
	}

	public static void FXEnd_Middle_OnComplete()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		LeanTween.scale(timeStopFX, new Vector3(0f, 0f, 0f), TIMESTOP_STARTUP_DURATION / 2f).setOnComplete((Action)FXEnd_End_OnComplete).setOnUpdate((Action<float>)FXEnd_End_OnUpdate)
			.setEase((LeanTweenType)6);
		OnTimeStop_PreEnd();
	}

	public static void FXEnd_End_OnComplete()
	{
		OnTimeStop_End();
	}

	public static void FXEnd_End_OnUpdate(float timeRatio)
	{
		((ParameterOverride<float>)(object)timeStopFX.GetComponent<PostProcessVolume>().profile.GetSetting<ColorGrading>().saturation).value = Mathf.Lerp(-75f, 0f, timeRatio);
		((ParameterOverride<float>)(object)timeStopFX.GetComponent<PostProcessVolume>().profile.GetSetting<ColorGrading>().hueShift).value = 0f + Mathf.Lerp(180f, 0f, timeRatio);
		((ParameterOverride<float>)(object)timeStopFX.GetComponent<PostProcessVolume>().profile.GetSetting<LensDistortion>().intensity).value = 0f + Mathf.Lerp(80f, 0f, timeRatio);
		NotifyTimeStopPostProcessChanged();
	}

	private static bool TimeStopEnemies(Collider[] array, CharacterBody self, float ts_duration)
	{
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: 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)
		IEnumerable<Collider> enumerable = array.Where((Collider x) => (Object)(object)((Component)x).GetComponent<HurtBox>() != (Object)null);
		List<HurtBoxGroup> list = new List<HurtBoxGroup>();
		foreach (Collider item in enumerable)
		{
			HurtBox hurtBox2 = ((Component)item).GetComponentInChildren<HurtBox>();
			if ((Object)(object)hurtBox2 == (Object)null || (Object)(object)hurtBox2.healthComponent == (Object)(object)self.healthComponent || list.Where((HurtBoxGroup x) => (Object)(object)x == (Object)(object)hurtBox2.hurtBoxGroup).Count() > 0 || (hurtBox2.teamIndex == self.teamComponent.teamIndex && (int)FriendlyFireManager.friendlyFireMode == 0))
			{
				continue;
			}
			_ = hurtBox2;
			list.Add(hurtBox2.hurtBoxGroup);
			HealthComponent componentInChildren = ((Component)hurtBox2.healthComponent).gameObject.GetComponentInChildren<HealthComponent>();
			if (!((Object)(object)componentInChildren != (Object)null))
			{
				continue;
			}
			CharacterBody body = componentInChildren.body;
			if ((Object)(object)body != (Object)null)
			{
				EntityStateMachine component = ((Component)body).GetComponent<EntityStateMachine>();
				if ((Object)(object)component != (Object)null)
				{
					TimeStopFreezeState state = new TimeStopFreezeState
					{
						duration = ts_duration
					};
					component.SetState((EntityState)(object)state);
				}
			}
		}
		if (list == null)
		{
			return false;
		}
		return list.Count() > 0;
	}

	private static void CombatDirector_Simulate_Hook(orig_Simulate orig, CombatDirector self, float deltaTime)
	{
		if (!TIMESTOP_FREEZE_SPAWNS)
		{
			orig.Invoke(self, deltaTime);
		}
	}

	private static void ProjectileSimple_FixedUpdate_Hook(orig_FixedUpdate orig, ProjectileSimple self)
	{
		//IL_0019: 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 (TIMESTOP_FREEZE_PROJECTILES)
		{
			Rigidbody component = ((Component)self).GetComponent<Rigidbody>();
			if ((Object)(object)component != (Object)null)
			{
				component.velocity = GenerateTimeStopFrozenVelocity(component);
				component.angularVelocity = Vector3.zero;
			}
		}
		else
		{
			orig.Invoke(self);
		}
	}

	private static void OrbManager_FixedUpdate_Hook(orig_FixedUpdate orig, OrbManager self)
	{
		if (!TIMESTOP_FREEZE_PROJECTILES)
		{
			orig.Invoke(self);
		}
	}

	private static void OrbEffect_UpdateOrb_Hook(orig_UpdateOrb orig, OrbEffect self, float deltaTime)
	{
		if (!TIMESTOP_FREEZE_PROJECTILES)
		{
			orig.Invoke(self, deltaTime);
		}
	}

	private static bool Run_ShouldUpdateRunStopwatch_Hook(orig_ShouldUpdateRunStopwatch orig, Run self)
	{
		if (orig.Invoke(self))
		{
			return !TIMESTOP_ACTIVE;
		}
		return false;
	}

	private static void SetStateOnHurt_SetPain_Hook(orig_SetPain orig, SetStateOnHurt self)
	{
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self);
		}
	}

	private static void SetStateOnHurt_SetStun_Hook(orig_SetStun orig, SetStateOnHurt self, float duration)
	{
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self, duration);
		}
	}

	private static void SetStateOnHurt_SetFrozen_Hook(orig_SetFrozen orig, SetStateOnHurt self, float duration)
	{
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self, duration);
		}
	}

	private static void ProjectileImpactExplosion_FixedUpdate_Hook(orig_FixedUpdate orig, ProjectileImpactExplosion self)
	{
		if (!TIMESTOP_FREEZE_PROJECTILES)
		{
			orig.Invoke(self);
		}
	}

	private static void ChargeLaser_FixedUpdate(orig_FixedUpdate orig, ChargeLaser self)
	{
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self);
		}
	}

	private static void ChargeLaser_Update(orig_Update orig, ChargeLaser self)
	{
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self);
		}
	}

	private static void ChargeMegaLaser_FixedUpdate_Hook(orig_FixedUpdate orig, ChargeMegaLaser self)
	{
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self);
		}
	}

	private static void ChargeMegaLaser_Update_Hook(orig_Update orig, ChargeMegaLaser self)
	{
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self);
		}
	}

	private static void FireMegaLaser_FixedUpdate_Hook(orig_FixedUpdate orig, FireMegaLaser self)
	{
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self);
		}
	}

	private static void ChargeGoldMegaLaser_FixedUpdate_Hook(orig_FixedUpdate orig, ChargeGoldMegaLaser self)
	{
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self);
		}
	}

	private static void FireGoldMegaLaser_FixedUpdate_Hook(orig_FixedUpdate orig, FireGoldMegaLaser self)
	{
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self);
		}
	}

	private static void WormBodyPositions2_OnDeathStart_Hook(orig_OnDeathStart orig, WormBodyPositions2 self)
	{
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self);
		}
	}

	private static void WormBodyPositionsDriver_FixedUpdateServer_Hook(orig_FixedUpdateServer orig, WormBodyPositionsDriver self)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self);
		}
		else
		{
			self.chaserVelocity = Vector3.zero;
		}
	}

	private static void DelayBlast_FixedUpdate_Hook(orig_FixedUpdate orig, DelayBlast self)
	{
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self);
		}
	}

	private static void DestroyOnTimer_FixedUpdate_Hook(orig_FixedUpdate orig, DestroyOnTimer self)
	{
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self);
		}
	}

	private static void MinigunFire_FixedUpdate_Hook(orig_FixedUpdate orig, MinigunFire self)
	{
		if (!TIMESTOP_ACTIVE)
		{
			orig.Invoke(self);
		}
	}

	private static void GenericCharacterDeath_OnEnter_Hook(orig_OnEnter orig, GenericCharacterDeath self)
	{
		MainPlugin.DebugLog("GenericCharacterDeath_OnEnter_Hook();");
		if (TIMESTOP_ACTIVE)
		{
			CharacterBody characterBody = ((EntityState)self).outer.commonComponents.characterBody;
			if ((Object)(object)characterBody != (Object)null && (Object)(object)characterBody == (Object)(object)characterBodyUsed)
			{
				MainPlugin.DebugLog("GenericCharacterDeath_OnEnter_Hook() : Time User Died, end timestop!!!");
				ForceEndTimeStop();
			}
		}
		orig.Invoke(self);
	}

	private static void OnTimeStop_Start()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//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_00a4: Unknown result type (might be due to invalid IL or missing references)
		TIMESTOP_STARTED_TIME = Time.time;
		MainPlugin.CreateCameraShake(((Component)characterBodyUsed).transform.position, TIMESTOP_STARTUP_DURATION, 100f, 1f, 180f, 0f, true);
		timeStopFX = Object.Instantiate<GameObject>(KingItemsAssets.ZaWarudoEffect, ((Component)characterBodyUsed).transform.position, Quaternion.identity);
		DisableSceneCamPostProcessLayers();
		timeStopFX.transform.SetParent(((Component)characterBodyUsed).transform, true);
		ApplyTimeStopPostProcessLayer(timeStopFX);
		NotifyTimeStopPostProcessChanged();
		recachePostProcessNextUpdate = true;
		LeanTween.scale(timeStopFX, new Vector3(20f, 20f, 20f), TIMESTOP_STARTUP_DURATION / 2f).setOnComplete((Action)FXStart_Middle_OnComplete).setOnUpdate((Action<float>)FXStart_OnUpdate);
		MainPlugin.PlaySoundEvent(timeStopFX, ItemsSounds.TimeStopSFX, 100);
		MainPlugin.SetOverrideMusic(true, TIMESTOP_STARTUP_DURATION + TIMESTOP_DURATION + TIMESTOP_STARTUP_DURATION);
		((ParameterOverride<float>)(object)timeStopFX.GetComponent<PostProcessVolume>().profile.GetSetting<ColorGrading>().hueShift).value = 0f;
		((ParameterOverride<float>)(object)timeStopFX.GetComponent<PostProcessVolume>().profile.GetSetting<ColorGrading>().saturation).value = 0f;
		((ParameterOverride<float>)(object)timeStopFX.GetComponent<PostProcessVolume>().profile.GetSetting<LensDistortion>().intensity).value = 0f;
		TimeStopFreezeAllEnemies();
		TIMESTOP_FREEZE_PROJECTILES = true;
		TIMESTOP_FREEZE_SPAWNS = true;
		FREEZE_TIMER = 0f;
		ParticleSystem[] array = Object.FindObjectsOfType<ParticleSystem>();
		for (int i = 0; i < array.Length; i++)
		{
			array[i].Pause(true);
		}
	}

	private static void OnTimeStop_PreEnd()
	{
		TIMESTOP_FREEZE_PROJECTILES = false;
		TIMESTOP_FREEZE_SPAWNS = false;
		ProjectileSimple[] array = Object.FindObjectsOfType<ProjectileSimple>();
		foreach (ProjectileSimple val in array)
		{
			Reflection.InvokeMethod((object)val, "SetForwardSpeed", new object[1] { val.desiredForwardSpeed });
		}
		ParticleSystem[] array2 = Object.FindObjectsOfType<ParticleSystem>();
		foreach (ParticleSystem val2 in array2)
		{
			if (val2.isPaused)
			{
				val2.Play(true);
			}
		}
	}

	private static void OnTimeStop_End()
	{
		if ((Object)(object)timeStopFX != (Object)null)
		{
			Object.Destroy((Object)(object)timeStopFX);
		}
		if (currentSequence != null)
		{
			LeanTween.cancel(currentSequence.id);
		}
		ResetTimeStopValues();
	}

	public static void ResetTimeStopValues()
	{
		EnableDeferredScenePostProcessLayers();
		timeStopFX = null;
		TIMESTOP_ACTIVE = false;
		TIMESTOP_FREEZE_PROJECTILES = false;
		TIMESTOP_FREEZE_SPAWNS = false;
		FREEZE_TIMER = 0f;
		currentSequence = null;
	}

	public static void ForceEndTimeStop()
	{
		//IL_002e: 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_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)timeStopFX != (Object)null)
		{
			LeanTween.cancel(timeStopFX);
		}
		if ((Object)(object)characterBodyUsed != (Object)null)
		{
			Vector3 position = ((Component)characterBodyUsed).transform.position;
			LayerIndex entityPrecise = LayerIndex.entityPrecise;
			TimeStopEnemies(Physics.OverlapSphere(position, float.MaxValue, LayerMask.op_Implicit(((LayerIndex)(ref entityPrecise)).mask)).ToArray(), characterBodyUsed, 0f);
		}
		OnTimeStop_PreEnd();
		OnTimeStop_End();
	}

	private static void ApplyTimeStopPostProcessLayer(GameObject fx)
	{
		int layer = (fx.layer = LayerIndex.postProcess.intVal);
		Transform[] componentsInChildren = fx.GetComponentsInChildren<Transform>(true);
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			((Component)componentsInChildren[i]).gameObject.layer = layer;
		}
	}

	private static void NotifyTimeStopPostProcessChanged()
	{
		PostProcessVolume.DispatchVolumeSettingsChangedEvent();
	}

	private static void DisableSceneCamPostProcessLayers()
	{
		deferredScenePostProcessLayers.Clear();
		recachePostProcessNextUpdate = false;
		ReadOnlyCollection<CameraRigController> readOnlyInstancesList = CameraRigController.readOnlyInstancesList;
		for (int i = 0; i < readOnlyInstancesList.Count; i++)
		{
			CameraRigController val = readOnlyInstancesList[i];
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.sceneCam))
			{
				PostProcessLayer component = ((Component)val.sceneCam).GetComponent<PostProcessLayer>();
				if (Object.op_Implicit((Object)(object)component) && ((Behaviour)component).enabled)
				{
					((Behaviour)component).enabled = false;
					deferredScenePostProcessLayers.Add(component);
				}
			}
		}
	}

	private static void EnableDeferredScenePostProcessLayers()
	{
		recachePostProcessNextUpdate = false;
		for (int i = 0; i < deferredScenePostProcessLayers.Count; i++)
		{
			PostProcessLayer val = deferredScenePostProcessLayers[i];
			if (Object.op_Implicit((Object)(object)val))
			{
				((Behaviour)val).enabled = true;
				val.OnGlobalVolumesDirty();
				val.OnVolumeSettingsChanged();
			}
		}
		deferredScenePostProcessLayers.Clear();
	}
}
public class KaioEssence
{
	private const float m_buffDuration = 10f;

	public static string s_buffName = CreateName() + "Buff";

	public const float s_buffScale = 0.85f;

	public static EquipmentDef CreateCustomEquipmentDef()
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		ScriptableObject obj = ScriptableObject.CreateInstance(typeof(EquipmentDef));
		ScriptableObject obj2 = ((obj is EquipmentDef) ? obj : null);
		((Object)obj2).name = CreateName();
		((EquipmentDef)obj2).appearsInMultiPlayer = true;
		((EquipmentDef)obj2).appearsInSinglePlayer = true;
		((EquipmentDef)obj2).isBoss = false;
		((EquipmentDef)obj2).isLunar = false;
		((EquipmentDef)obj2).canDrop = true;
		((EquipmentDef)obj2).colorIndex = (ColorIndex)5;
		((EquipmentDef)obj2).enigmaCompatible = true;
		((EquipmentDef)obj2).pickupIconSprite = KingItemsAssets.Img_KaioEssence;
		((EquipmentDef)obj2).loreToken = CreateItemLore();
		((EquipmentDef)obj2).descriptionToken = CreateItemComplexDescription();
		((EquipmentDef)obj2).pickupToken = CreateItemSimpleDescription();
		((EquipmentDef)obj2).nameToken = CreateNameToken();
		((EquipmentDef)obj2).cooldown = 60f;
		((EquipmentDef)obj2).pickupModelPrefab = KingItemsAssets.KaioEssence;
		return (EquipmentDef)(object)obj2;
	}

	public static string CreateName()
	{
		return "KaioEssence";
	}

	public static string CreateNameToken()
	{
		return "Kaio Essence";
	}

	public static string CreateItemComplexDescription()
	{
		string text = "";
		string text2 = "";
		string text3 = "";
		KaiokenTransformationState kaiokenReference = GetKaiokenReference();
		if (kaiokenReference != null)
		{
			text = KingUtil.MultToPercent(((TransformationState)kaiokenReference).GetDamagePercentBonus() * 0.85f).ToString("n0");
			text2 = KingUtil.MultToPercent(((TransformationState)kaiokenReference).GetAttackSpeedPercentBonus() * 0.85f).ToString("n0");
			text3 = KingUtil.MultToPercent(((TransformationState)kaiokenReference).GetMoveSpeedPercentBonus() * 0.85f).ToString("n0");
		}
		return "Grants a purified variant of the Kaioken, gaining bonus " + MainPlugin.ColorText(text + "% Damage, " + text2 + "% Attack Speed & " + text3 + "% Movement Speed", "#E5C962") + " for " + MainPlugin.ColorText(10f.ToString("n0"), "#FFFFFF") + " Seconds.";
	}

	public static string CreateItemSimpleDescription()
	{
		return "Grants a purified variant of the Kaioken, gaining bonus " + MainPlugin.ColorText("Damage, Attack Speed & Movement Speed", "#E5C962") + " for " + MainPlugin.ColorText(10f.ToString("n0"), "#FFFFFF") + " Seconds.";
	}

	public static string CreateItemLore()
	{
		return "Forged by the great Kai himself, a fragment of the Kaioken was formed, granting its user the benefits without repercussion...";
	}

	public static bool OnCustomEquipmentActivated(EquipmentSlot self)
	{
		//IL_007c: 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_0093: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)self.characterBody != (Object)null)
		{
			BonusStatHandler forBody = BonusStatHandler.GetForBody(self.characterBody);
			if ((Object)(object)forBody != (Object)null)
			{
				if (((NetworkBehaviour)self.characterBody).hasAuthority)
				{
					KaiokenTransformationState kaiokenReference = GetKaiokenReference();
					if (kaiokenReference != null)
					{
						if (!forBody.HasBonusStatBundle(s_buffName))
						{
							MainPlugin.PlaySoundEvent(((Component)self).gameObject, BaseSounds.aura_kaioken_start, 100);
						}
						BonusStatBundle val = default(BonusStatBundle);
						((BonusStatBundle)(ref val))..ctor(s_buffName, KingItemsAssets.KaioEssence_Aura, 10f);
						BonusStatBundle val2 = ((TransformationState)kaiokenReference).GenerateBonusStateBundle();
						List<BonusStat> allBonusStats = ((BonusStatBundle)(ref val2)).GetAllBonusStats();
						for (int i = 0; i < allBonusStats.Count; i++)
						{
							BonusStat val3 = allBonusStats[i];
							val3.MultValue *= 0.85f;
							((BonusStatBundle)(ref val)).AddBonusStat(ref val3);
						}
						forBody.AddBonusStatBundle(val, (ELifetimeType)0);
					}
				}
				else
				{
					NetworkHandler component = ((Component)self.characterBody).GetComponent<NetworkHandler>();
					if ((Object)(object)component != (Object)null)
					{
						component.CmdCallFunction(MainPlugin.GetAssemblyNameFromNamespace("NS_KingItems"), "KaioEssence", "ClientOnCustomEquipmentActivated", ((Component)self.characterBody).gameObject, true, true, false, true);
					}
				}
			}
		}
		return true;
	}

	public static KaiokenTransformationState GetKaiokenReference()
	{
		TransformationState obj = TransformationBank.FindLoadedTransformation("Kaioken x3");
		return (KaiokenTransformationState)(object)((obj is KaiokenTransformationState) ? obj : null);
	}

	public static void ClientOnCustomEquipmentActivated(GameObject characterBodyGO)
	{
		CharacterBody component = characterBodyGO.GetComponent<CharacterBody>();
		if ((Object)(object)component != (Object)null && ((NetworkBehaviour)component).hasAuthority)
		{
			OnCustomEquipmentActivated(component.equipmentSlot);
		}
	}
}
public class SenzuBean
{
	public static EquipmentDef CreateCustomEquipmentDef()
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		ScriptableObject obj = ScriptableObject.CreateInstance(typeof(EquipmentDef));
		ScriptableObject obj2 = ((obj is EquipmentDef) ? obj : null);
		((Object)obj2).name = CreateName();
		((EquipmentDef)obj2).appearsInMultiPlayer = true;
		((EquipmentDef)obj2).appearsInSinglePlayer = true;
		((EquipmentDef)obj2).isBoss = false;
		((EquipmentDef)obj2).isLunar = false;
		((EquipmentDef)obj2).canDrop = true;
		((EquipmentDef)obj2).colorIndex = (ColorIndex)5;
		((EquipmentDef)obj2).enigmaCompatible = true;
		((EquipmentDef)obj2).pickupIconSprite = KingItemsAssets.Img_SenzuBean;
		((EquipmentDef)obj2).pickupModelPrefab = KingItemsAssets.SenzuBean;
		((EquipmentDef)obj2).loreToken = CreateItemLore();
		((EquipmentDef)obj2).descriptionToken = CreateItemComplexDescription();
		((EquipmentDef)obj2).pickupToken = CreateItemSimpleDescription();
		((EquipmentDef)obj2).nameToken = CreateNameToken();
		((EquipmentDef)obj2).cooldown = 150f;
		return (EquipmentDef)(object)obj2;
	}

	public static string CreateName()
	{
		return "SenzuBean";
	}

	public static string CreateNameToken()
	{
		return "Senzu Bean";
	}

	public static string CreateItemComplexDescription()
	{
		return "Instantly replenish " + MainPlugin.ColorText("100% of your Maximum Health", "#00FF00") + "\nAdditionally, replenish " + MainPlugin.ColorText("100% of your Maximum Ki", "#03bcff");
	}

	public static string CreateItemSimpleDescription()
	{
		return "Instantly replenish " + MainPlugin.ColorText("All Health", "#00FF00") + " and " + MainPlugin.ColorText("All Ki", "#03bcff");
	}

	public static string CreateItemLore()
	{
		return "Senzu Beans are grown by Korin in Korin Tower.\nWhen eaten, the consumer's energy and physical health are restored to their fullest;\nthe effects are typically almost instantaneous for the recipient,\nmaking these beans a great asset both in and out of battle.";
	}

	public static bool OnCustomEquipmentActivated(EquipmentSlot self)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: 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)
		EffectData val = new EffectData();
		val.origin = ((Component)self).transform.position;
		val.SetNetworkedObjectReference(((Component)self).gameObject);
		EffectManager.SpawnEffect(LegacyResourcesAPI.Load<GameObject>("Prefabs/Effects/FruitHealEffect"), val, true);
		self.characterBody.healthComponent.HealFraction(1f, default(ProcChainMask));
		NetworkHandler component = ((Component)self.characterBody).GetComponent<NetworkHandler>();
		if ((Object)(object)component != (Object)null)
		{
			component.CmdRefillKi(100f);
		}
		return true;
	}
}
public class TrainingWeight
{
	private const string s_bsbName = "TrainingWeightBonus";

	private const string s_bsbNameDebuff = "TrainingWeightBonusDebuff";

	private const string s_dataCountName = "TrainingWeight_Count";

	private const string s_dataTrainingValueName = "TrainingWeight_TrainingValue";

	private const float s_statDebuffPerItemPercent = 30f;

	private const float s_statMaxGainPerItemPercent = 50f;

	private const int s_trainingValueRequiredForMaxGainPerItem = 480;

	private const int s_trainingValueGainPerItem = 1;

	private static readonly Timer s_updateTrainingBuffTimer = new Timer(1f, (Action)null, (Action)null, (Action)null, false);

	private const int s_trainingLimit = 3;

	private const float s_expGainMultPerItem = 0.15f;

	private static DynamicArray<ItemIcon> s_inventoryIcons = new DynamicArray<ItemIcon>();

	public static ItemDef CreateCustomItemDef()
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: 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_0096: Expected O, but got Unknown
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Expected O, but got Unknown
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Expected O, but got Unknown
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Expected O, but got Unknown
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Expected O, but got Unknown
		ScriptableObject obj = ScriptableObject.CreateInstance(typeof(ItemDef));
		ScriptableObject obj2 = ((obj is ItemDef) ? obj : null);
		((Object)obj2).name = CreateName();
		((ItemDef)obj2).pickupIconSprite = KingItemsAssets.Img_TrainingWeight;
		((ItemDef)obj2).pickupModelPrefab = KingItemsAssets.TrainingWeight;
		((ItemDef)obj2).loreToken = CreateItemLore();
		((ItemDef)obj2).descriptionToken = CreateItemSimpleDescription();
		((ItemDef)obj2).pickupToken = CreateItemSimpleDescription();
		((ItemDef)obj2).nameToken = CreateNameToken();
		ItemTierDef val = Addressables.LoadAssetAsync<ItemTierDef>((object)"RoR2/Base/Common/LunarTierDef.asset").WaitForCompletion();
		Reflection.SetFieldValue<ItemTierDef>((object)obj2, "_itemTierDef", val);
		TransformationHandler.s_onTransformationExpGain_Delegate = (OnTransformationExpGain_DelegateDeclaration)Delegate.Combine((Delegate?)(object)TransformationHandler.s_onTransformationExpGain_Delegate, (Delegate?)new OnTransformationExpGain_DelegateDeclaration(OnTransformationExpGain_Hook));
		ItemIcon.SetItemIndex_SetItemIndexArgs += new hook_SetItemIndex_SetItemIndexArgs(ItemIcon_SetItemIndex_SetItemIndexArgs_Hook);
		TooltipController.SetTooltipProvider += new hook_SetTooltipProvider(TooltipController_SetTooltipProvider_Hook);
		TooltipController.LateUpdate += new hook_LateUpdate(TooltipController_LateUpdate_Hook);
		return (ItemDef)(object)obj2;
	}

	private static bool IsTrainingWeightItem(ItemIndex itemIndex)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		ItemDef itemDef = ItemCatalog.GetItemDef(itemIndex);
		if ((Object)(object)itemDef != (Object)null)
		{
			return ((Object)itemDef).name == CreateName();
		}
		return false;
	}

	private static TooltipProvider GetItemTooltipProvider(ItemIcon icon)
	{
		if ((Object)(object)icon == (Object)null)
		{
			return null;
		}
		if ((Object)(object)icon.tooltipProvider != (Object)null)
		{
			return icon.tooltipProvider;
		}
		return ((Component)icon).GetComponent<TooltipProvider>();
	}

	private static void ItemIcon_SetItemIndex_SetItemIndexArgs_Hook(orig_SetItemIndex_SetItemIndexArgs orig, ItemIcon self, SetItemIndexArgs args)
	{
		//IL_0014: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		orig.Invoke(self, args);
		TooltipProvider itemTooltipProvider = GetItemTooltipProvider(self);
		if ((Object)(object)itemTooltipProvider == (Object)null)
		{
			return;
		}
		if (IsTrainingWeightItem(args.newItemIndex))
		{
			s_inventoryIcons.AddElementUnique(self);
			ApplyTrainingWeightTooltip(self, CreateItemComplexDescription(null));
			return;
		}
		int num = s_inventoryIcons.FindFirstElementIndex((Predicate<ItemIcon>)((ItemIcon x) => (Object)(object)x == (Object)(object)self));
		if (num != -1)
		{
			itemTooltipProvider.overrideBodyText = null;
			s_inventoryIcons.RemoveElement(num);
		}
	}

	private static void TooltipController_SetTooltipProvider_Hook(orig_SetTooltipProvider orig, TooltipController self, TooltipProvider provider)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)provider != (Object)null)
		{
			ItemIcon component = ((Component)provider).GetComponent<ItemIcon>();
			if ((Object)(object)component != (Object)null && IsTrainingWeightItem(component.itemIndex))
			{
				provider.overrideBodyText = CreateItemComplexDescription(null);
			}
		}
		orig.Invoke(self, provider);
	}

	private static void TooltipController_LateUpdate_Hook(orig_LateUpdate orig, TooltipController self)
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		orig.Invoke(self);
		if ((Object)(object)self.owner == (Object)null || (Object)(object)self.owner.currentTooltipProvider == (Object)null || (Object)(object)self.bodyLabel == (Object)null)
		{
			return;
		}
		ItemIcon component = ((Component)self.owner.currentTooltipProvider).GetComponent<ItemIcon>();
		if ((Object)(object)component == (Object)null || !IsTrainingWeightItem(component.itemIndex))
		{
			return;
		}
		ItemInventoryDisplay componentInParent = ((Component)component).GetComponentInParent<ItemInventoryDisplay>();
		if ((Object)(object)componentInParent == (Object)null)
		{
			return;
		}
		Inventory fieldValue = Reflection.GetFieldValue<Inventory>((object)componentInParent, "inventory");
		if ((Object)(object)fieldValue == (Object)null)
		{
			return;
		}
		CharacterMaster component2 = ((Component)fieldValue).GetComponent<CharacterMaster>();
		if (!((Object)(object)component2 == (Object)null))
		{
			CharacterBody body = component2.GetBody();
			if (!((Object)(object)body == (Object)null))
			{
				string text = CreateItemComplexDescription(body);
				self.owner.currentTooltipProvider.overrideBodyText = text;
				((TMP_Text)self.bodyLabel).text = text;
			}
		}
	}

	private static void ApplyTrainingWeightTooltip(ItemIcon icon, string bodyText)
	{
		TooltipProvider itemTooltipProvider = GetItemTooltipProvider(icon);
		if ((Object)(object)itemTooltipProvider == (Object)null)
		{
			return;
		}
		itemTooltipProvider.overrideBodyText = bodyText;
		if (MPEventSystem.readOnlyInstancesList == null)
		{
			return;
		}
		foreach (MPEventSystem readOnlyInstances in MPEventSystem.readOnlyInstancesList)
		{
			if ((Object)(object)readOnlyInstances != (Object)null && (Object)(object)readOnlyInstances.currentTooltipProvider == (Object)(object)itemTooltipProvider && (Object)(object)readOnlyInstances.currentTooltip != (Object)null && (Object)(object)readOnlyInstances.currentTooltip.bodyLabel != (Object)null)
			{
				((TMP_Text)readOnlyInstances.currentTooltip.bodyLabel).text = bodyText;
			}
		}
	}

	public static string CreateName()
	{
		return "TrainingWeight";
	}

	public static string CreateNameToken()
	{
		return "Training Weight";
	}

	public static string CreateItemComplexDescription(CharacterBody characterBody)
	{
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		string text = "Lose " + 30f.ToString("n0") + "% of your total " + MainPlugin.ColorText("Damage, Attack Speed & Movement Speed", "#C7B96A") + " but permanently gain " + 50f.ToString("n0") + "% over time whilst in combat. \nIncreases " + MainPlugin.ColorText("Form Mastery Exp", "#FF5400") + " gain by " + KingUtil.MultToPercent(0.15f).ToString("n0") + "%. \n";
		if ((Object)(object)characterBody != (Object)null)
		{
			CustomDataHandler forBody = CustomDataHandler.GetForBody(characterBody);
			if ((Object)(object)forBody != (Object)null)
			{
				float num = CalculateTrainingBonusPercent(forBody.Get<int>("TrainingWeight_TrainingValue", 0));
				float num2 = 30f * (float)forBody.Get<int>("TrainingWeight_Count", 0);
				float num3 = num - num2;
				text = text + "Stats: " + ((num3 > 0f) ? "+" : "") + MainPlugin.ColorText(num3.ToString("n0") + "% \n", (num3 > 0f) ? MainPlugin.ColorToHex(Color.green) : MainPlugin.ColorToHex(Color.red));
			}
		}
		return text + MainPlugin.ColorText("Only " + 3 + " " + CreateNameToken() + "s can be trained at a time.", "#999999");
	}

	public static string CreateItemSimpleDescription()
	{
		return "Lose a portion of your total " + MainPlugin.ColorText("Stats", "#C7B96A") + " but gain additional bonus " + MainPlugin.ColorText("Stats", "#C7B96A") + " over time whilst in combat. \nIncreases " + MainPlugin.ColorText("Form Mastery Exp", "#FF5400") + " gain. \n" + MainPlugin.ColorText("Only " + 3 + " " + CreateNameToken() + "s can be trained at a time.", "#999999");
	}

	public static string CreateItemLore()
	{
		return "\"Yup! Kami told me to. It was part of my training. It's not much different than Master Roshi's style. You wear a big turtle shell to gain strength. It's pretty much the same principle here.\" - Goku";
	}

	public static bool CanTrain(CharacterBody characterBody, int itemCount)
	{
		if (itemCount <= 0)
		{
			return false;
		}
		if (characterBody.outOfCombat)
		{
			return false;
		}
		if (MainPlugin.IsInStage("bazaar"))
		{
			return false;
		}
		return true;
	}

	public static void OnItemUpdate(CharacterBody characterBody, int itemCount)
	{
		if ((Object)(object)characterBody == (Object)null || ((Object)(object)characterBody.inventory != (Object)null && characterBody.inventory.GetItemCountEffective(Items.InvadingDoppelganger) > 0))
		{
			return;
		}
		BonusStatHandler forBody = BonusStatHandler.GetForBody(characterBody);
		if ((Object)(object)forBody == (Object)null)
		{
			return;
		}
		CustomDataHandler forBody2 = CustomDataHandler.GetForBody(characterBody);
		if ((Object)(object)forBody2 == (Object)null)
		{
			return;
		}
		int num = forBody2.Get<int>("TrainingWeight_Count", 0);
		if (itemCount != num)
		{
			forBody2.Set<int>("TrainingWeight_Count", itemCount);
			OnItemCountChanged(characterBody, forBody, forBody2, num, itemCount);
			return;
		}
		if (!s_updateTrainingBuffTimer.IsRunning())
		{
			s_updateTrainingBuffTimer.Restart();
		}
		s_updateTrainingBuffTimer.Update(Time.deltaTime);
		if (s_updateTrainingBuffTimer.HasElapsed())
		{
			OnElapsedUpdate_TryTrain(characterBody, forBody, forBody2, itemCount);
			s_updateTrainingBuffTimer.Restart();
		}
	}

	private static void OnItemCountChanged(CharacterBody characterBody, BonusStatHandler bonusStatHandler, CustomDataHandler customDataHandler, int previousItemCount, int itemCount)
	{
		UpdateTrainingDebuffs(bonusStatHandler, itemCount);
	}

	private static void OnElapsedUpdate_TryTrain(CharacterBody characterBody, BonusStatHandler bonusStatHandler, CustomDataHandler customDataHandler, int itemCount)
	{
		if (CanTrain(characterBody, itemCount))
		{
			int num = customDataHandler.Get<int>("TrainingWeight_TrainingValue", 0);
			int num2 = Mathf.FloorToInt((float)(num / 480));
			int num3 = Math.Max(itemCount - num2, 3);
			if (MainPlugin.FASTER_TRAINING)
			{
				num3 *= 100;
			}
			int val = itemCount * 480;
			int val2 = num + num3;
			val2 = Math.Min(val2, val);
			customDataHandler.Set<int>("TrainingWeight_TrainingValue", val2);
			UpdateTrainingBuffs(bonusStatHandler, val2);
		}
	}

	private static void UpdateTrainingDebuffs(BonusStatHandler bsh, int itemCount)
	{
		if (itemCount > 0)
		{
			ApplyDebuffBSB(bsh, "TrainingWeightBonusDebuff", itemCount);
			return;
		}
		string text = "TrainingWeightBonusDebuff";
		bsh.RemoveBonusStatBundle(ref text);
	}

	private static void UpdateTrainingBuffs(BonusStatHandler bsh, int trainingValue)
	{
		ApplyBonusStats(bsh, trainingValue);
	}

	private static float CalculateTrainingBonusPercent(int trainingValue)
	{
		float num = (float)trainingValue / 480f;
		return 50f * num;
	}

	private static void ApplyBonusStats(BonusStatHandler bsh, int trainingValue)
	{
		//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)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: 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)
		if (trainingValue > 0)
		{
			BonusStatBundle val = default(BonusStatBundle);
			((BonusStatBundle)(ref val))..ctor("TrainingWeightBonus", (GameObject)null, 0f);
			float num = KingUtil.PercentToMult(CalculateTrainingBonusPercent(trainingValue));
			BonusStat val2 = new BonusStat("damage", 0f, num);
			((BonusStatBundle)(ref val)).AddBonusStat(ref val2);
			val2 = new BonusStat("moveSpeed", 0f, num);
			((BonusStatBundle)(ref val)).AddBonusStat(ref val2);
			val2 = new BonusStat("attackSpeed", 0f, num);
			((BonusStatBundle)(ref val)).AddBonusStat(ref val2);
			bsh.AddBonusStatBundle(val, (ELifetimeType)1);
		}
	}

	private static void ApplyDebuffBSB(BonusStatHandler bsh, string bsbName, int itemCount)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: 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_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: 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)
		BonusStatBundle val = default(BonusStatBundle);
		((BonusStatBundle)(ref val))..ctor(bsbName, (GameObject)null, 0f);
		float num = (0f - KingUtil.PercentToMult(30f)) * (float)itemCount;
		BonusStat val2 = new BonusStat("damage", 0f, num);
		((BonusStatBundle)(ref val)).AddBonusStat(ref val2);
		val2 = new BonusStat("moveSpeed", 0f, num);
		((BonusStatBundle)(ref val)).AddBonusStat(ref val2);
		val2 = new BonusStat("attackSpeed", 0f, num);
		((BonusStatBundle)(ref val)).AddBonusStat(ref val2);
		bsh.AddBonusStatBundle(val, (ELifetimeType)0);
	}

	private static void OnTransformationExpGain_Hook(Inventory inventory, ref float expGainMult)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		int num = MainPlugin.s_customItemManager.AccessRegisteredItems().FindFirstElementIndex((Predicate<RegisteredItem>)((RegisteredItem x) => x.itemDef.nameToken == CreateNameToken()));
		RegisteredItem val = MainPlugin.s_customItemManager.AccessRegisteredItems().AccessElement(num);
		if (val != null)
		{
			ItemIndex itemIndex = val.itemDef.itemIndex;
			if ((Object)(object)inventory != (Object)null)
			{
				int itemCountEffective = inventory.GetItemCountEffective(itemIndex);
				expGainMult += (float)itemCountEffective * 0.15f;
			}
		}
	}
}
public static class KingItemsAssets
{
	public static AssetBundle LocalAssetBundle;

	public static Sprite Img_DiosHead;

	public static Sprite Img_KaioEssence;

	public static Sprite Img_SenzuBean;

	public static Sprite Img_TrainingWeight;

	public static Sprite Tex_DioHead;

	public static Material COL_KaioEssence;

	public static Material Mat_DiosHead;

	public static GameObject KaioEssence_Aura;

	public static GameObject DiosHead;

	public static GameObject KaioEssence;

	public static GameObject SenzuBean;

	public static GameObject TrainingWeight;

	public static GameObject ZaWarudoEffect;

	public static void PopulateAssets()
	{
		MainPlugin.DebugLog("KingItemsAssets::PopulateAssets() Started!");
		AssetLoader.LoadAssetBundle("KingItems.items_assetbundle", ref LocalAssetBundle);
		AssetLoader.LoadSoundBank("KingItems.items_soundbank.bnk");
		LoadAllAssetsFromAssetBundle();
		MainPlugin.DebugLog("KingItemsAssets::PopulateAssets() Complete!");
	}

	private static void LoadAllAssetsFromAssetBundle()
	{
		AssetLoader.LoadAsset(ref Img_DiosHead, "Img_DiosHead", LocalAssetBundle);
		AssetLoader.LoadAsset(ref Img_KaioEssence, "Img_KaioEssence", LocalAssetBundle);
		AssetLoader.LoadAsset(ref Img_SenzuBean, "Img_SenzuBean", LocalAssetBundle);
		AssetLoader.LoadAsset(ref Img_TrainingWeight, "Img_TrainingWeight", LocalAssetBundle);
		AssetLoader.LoadAsset(ref Tex_DioHead, "Tex_DioHead", LocalAssetBundle);
		AssetLoader.LoadAsset(ref COL_KaioEssence, "COL_KaioEssence", LocalAssetBundle);
		AssetLoader.LoadAsset(ref Mat_DiosHead, "Mat_DiosHead", LocalAssetBundle);
		AssetLoader.LoadAsset(ref KaioEssence_Aura, "KaioEssence_Aura", LocalAssetBundle);
		AssetLoader.LoadAsset(ref DiosHead, "DiosHead", LocalAssetBundle);
		AssetLoader.LoadAsset(ref KaioEssence, "KaioEssence", LocalAssetBundle);
		AssetLoader.LoadAsset(ref SenzuBean, "SenzuBean", LocalAssetBundle);
		AssetLoader.LoadAsset(ref TrainingWeight, "TrainingWeight", LocalAssetBundle);
		AssetLoader.LoadAsset(ref ZaWarudoEffect, "ZaWarudoEffect", LocalAssetBundle);
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.Kingpinush.KingItems", "KingItems", "1.5.2")]
public class KingItemsMainPlugin : BaseUnityPlugin
{
	public const string MOD_NAME = "KingItems";

	public const string MOD_UID = "com.Kingpinush.KingItems";

	private void Awake()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Expected O, but got Unknown
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Expected O, but got Unknown
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Expected O, but got Unknown
		KingItemsAssets.PopulateAssets();
		MainPlugin.s_customItemManager.RegisterCustomEquipment(SenzuBean.CreateCustomEquipmentDef(), new OnCustomEquipmentUse_DelegateDeclaration(SenzuBean.OnCustomEquipmentActivated));
		MainPlugin.s_customItemManager.RegisterCustomItem(TrainingWeight.CreateCustomItemDef(), new OnCustomItemUpdate_DelegateDeclaration(TrainingWeight.OnItemUpdate));
		MainPlugin.s_customItemManager.RegisterCustomEquipment(KaioEssence.CreateCustomEquipmentDef(), new OnCustomEquipmentUse_DelegateDeclaration(KaioEssence.OnCustomEquipmentActivated));
		MainPlugin.s_customItemManager.RegisterCustomEquipment(DiosHead.CreateCustomEquipmentDef(), new OnCustomEquipmentUse_DelegateDeclaration(DiosHead.OnCustomEquipmentActivated));
	}
}