Decompiled source of Crimson Moons Semblance v1.0.0

BepInEx/plugins/Crimson_Moons_Semblance/CrimsonMoonsSemblance.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using CrimsonMoonsSemblance;
using CrimsonMoonsSemblance.Scripts;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CrimsonMoonsSemblance")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CrimsonMoonsSemblance")]
[assembly: AssemblyTitle("CrimsonMoonsSemblance")]
[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;
		}
	}
}
[HarmonyPatch(typeof(HUDManager))]
internal class HudManagerPatch
{
	[HarmonyPostfix]
	[HarmonyPatch(typeof(HUDManager), "Update")]
	public static void Update()
	{
		try
		{
			if ((Object)(object)GameNetworkManager.Instance.localPlayerController.ItemSlots[GameNetworkManager.Instance.localPlayerController.currentItemSlot] != (Object)null)
			{
				if (GameNetworkManager.Instance.localPlayerController.ItemSlots[GameNetworkManager.Instance.localPlayerController.currentItemSlot].itemProperties.itemName == "Crimson Moon's Semblance")
				{
					float num = ((Component)GameNetworkManager.Instance.localPlayerController).GetComponent<PlayerScript>().BondOfLife;
					Plugin.meterContainer.SetActive(true);
					Plugin.meter.GetComponent<Image>().fillMethod = (FillMethod)0;
					Plugin.meter.GetComponent<Image>().fillAmount = num / 100f;
				}
				else
				{
					Plugin.meterContainer.SetActive(false);
				}
			}
			else
			{
				Plugin.meterContainer.SetActive(false);
			}
		}
		catch
		{
		}
	}
}
namespace CrimsonMoonsSemblance
{
	public class CSMInput : LcInputActions
	{
		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction AllIsAshKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction BalemoonRisingKey { get; set; }
	}
	[BepInPlugin("Entity378.CrimsonMoonsSemblance", "CrimsonMoonsSemblance", "1.0.0")]
	[BepInDependency("evaisa.lethallib", "0.14.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony harmony = new Harmony("Entity378.CrimsonMoonsSemblance");

		private const string GUID = "Entity378.CrimsonMoonsSemblance";

		private const string NAME = "CrimsonMoonsSemblance";

		private const string VERSION = "1.0.0";

		public static string assetsDir;

		public static AssetBundle bundle;

		public static GameObject CrimsonMoonsSemblanceMarkPrefab;

		public static Item CrimsonMoonsSemblanceItem;

		public static GameObject meterContainer;

		public static GameObject meter;

		public static GameObject frame;

		public static GameObject warningL;

		public static GameObject warningR;

		public static CSMInput InputActionsInstance = new CSMInput();

		private void Awake()
		{
			assetsDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "crimsonmoonssemblance");
			bundle = AssetBundle.LoadFromFile(assetsDir);
			AudioClip crimsonMoonsSemblanceSwingSFX = bundle.LoadAsset<AudioClip>("Assets/LethalCompany/CMS/ShovelSwing.ogg");
			AudioClip crimsonMoonsSemblanceReelUpSFX = bundle.LoadAsset<AudioClip>("Assets/LethalCompany/CMS/ShovelReelUp.ogg");
			AudioClip[] crimsonMoonsSemblanceHitSFX = (AudioClip[])(object)new AudioClip[2]
			{
				bundle.LoadAsset<AudioClip>("Assets/LethalCompany/CMS/ShovelHitDefault.ogg"),
				bundle.LoadAsset<AudioClip>("Assets/LethalCompany/CMS/ShovelHitDefault2.ogg")
			};
			CrimsonMoonsSemblanceItem = bundle.LoadAsset<Item>("Assets/LethalCompany/CMS/CrimsonMoonsSemblanceItem.asset");
			CrimsonMoonsSemblanceMarkPrefab = bundle.LoadAsset<GameObject>("Assets/LethalCompany/CMS/CrimsonMoonsSemblanceMark.prefab");
			CrimsonMoonsSemblanceScript crimsonMoonsSemblanceScript = CrimsonMoonsSemblanceItem.spawnPrefab.AddComponent<CrimsonMoonsSemblanceScript>();
			CrimsonMoonsSemblanceMarkPrefab.AddComponent<MarkScript>();
			((Component)CrimsonMoonsSemblanceMarkPrefab.transform.Find("CrimsonMoonsSemblanceMarkIcon")).gameObject.AddComponent<RotateMarkScript>();
			((GrabbableObject)crimsonMoonsSemblanceScript).itemProperties = CrimsonMoonsSemblanceItem;
			crimsonMoonsSemblanceScript.CrimsonMoonsSemblanceSwingSFX = crimsonMoonsSemblanceSwingSFX;
			crimsonMoonsSemblanceScript.CrimsonMoonsSemblanceReelUpSFX = crimsonMoonsSemblanceReelUpSFX;
			crimsonMoonsSemblanceScript.CrimsonMoonsSemblanceHitSFX = crimsonMoonsSemblanceHitSFX;
			NetworkPrefabs.RegisterNetworkPrefab(CrimsonMoonsSemblanceItem.spawnPrefab);
			Utilities.FixMixerGroups(CrimsonMoonsSemblanceItem.spawnPrefab);
			Items.RegisterScrap(CrimsonMoonsSemblanceItem, 10, (LevelTypes)(-1));
			Items.RegisterShopItem(CrimsonMoonsSemblanceItem, 378);
			harmony.PatchAll();
			SceneManager.sceneLoaded += OnSceneRelayLoaded;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"CMS: Loaded!");
		}

		private void OnSceneRelayLoaded(Scene scene, LoadSceneMode loadMode)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0058: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			if (((Scene)(ref scene)).name == "SampleSceneRelay")
			{
				GameObject val = GameObject.Find("IngamePlayerHUD");
				meterContainer = new GameObject("BondOfLifeMeterContainer");
				meterContainer.AddComponent<CanvasGroup>();
				RectTransform val2 = meterContainer.AddComponent<RectTransform>();
				((Transform)val2).parent = val.transform;
				((Transform)val2).localScale = Vector3.one;
				val2.anchoredPosition = Vector2.zero;
				((Transform)val2).localPosition = Vector2.op_Implicit(new Vector2(0f, -235f));
				val2.sizeDelta = Vector2.one;
				meter = AddImageToHUD("BoL-MeterFull", scene);
				frame = AddImageToHUD("BoL-MeterEmpty", scene);
				warningL = AddImageToHUD("BoL-Icon", scene);
				warningR = AddImageToHUD("BoL-Icon", scene);
				GameObject[] array = (GameObject[])(object)new GameObject[4] { meter, frame, warningL, warningR };
				GameObject[] array2 = array;
				foreach (GameObject val3 in array2)
				{
					val3.transform.parent = meterContainer.transform;
					val3.transform.localPosition = Vector2.op_Implicit(Vector2.zero);
				}
				meter.GetComponent<Image>().type = (Type)3;
				meter.GetComponent<Image>().fillMethod = (FillMethod)1;
				Transform transform = warningL.transform;
				transform.localPosition += new Vector3(-115f, 0f);
				Transform transform2 = warningR.transform;
				transform2.localPosition += new Vector3(115f, 0f);
			}
		}

		private GameObject AddImageToHUD(string imageName, Scene scene)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			Sprite val = bundle.LoadAsset<Sprite>("Assets/LethalCompany/CMS/" + imageName + ".png");
			GameObject val2 = new GameObject(imageName);
			SceneManager.MoveGameObjectToScene(val2, scene);
			GameObject val3 = GameObject.Find("IngamePlayerHUD");
			RectTransform val4 = val2.AddComponent<RectTransform>();
			((Transform)val4).parent = val3.transform;
			((Transform)val4).localScale = Vector2.op_Implicit(Vector2.one);
			val4.anchoredPosition = Vector2.zero;
			((Transform)val4).localPosition = Vector2.op_Implicit(Vector2.zero);
			Rect rect = val.rect;
			float num = ((Rect)(ref rect)).width / 2.5f;
			rect = val.rect;
			val4.sizeDelta = new Vector2(num, ((Rect)(ref rect)).height / 2.5f);
			Image val5 = val2.AddComponent<Image>();
			val5.sprite = val;
			CanvasRenderer val6 = val2.AddComponent<CanvasRenderer>();
			return val2;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "CrimsonMoonsSemblance";

		public const string PLUGIN_NAME = "CrimsonMoonsSemblance";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace CrimsonMoonsSemblance.Scripts
{
	internal class CrimsonMoonsSemblanceScript : Shovel
	{
		public List<EnemyAI> enemyList = new List<EnemyAI>();

		public AudioClip[] CrimsonMoonsSemblanceHitSFX;

		public AudioClip CrimsonMoonsSemblanceSwingSFX;

		public AudioClip CrimsonMoonsSemblanceReelUpSFX;

		public override void Start()
		{
			((GrabbableObject)this).isInFactory = true;
			((GrabbableObject)this).grabbable = true;
			((GrabbableObject)this).grabbableToEnemies = false;
			((GrabbableObject)this).mainObjectRenderer = ((Component)this).GetComponent<MeshRenderer>();
			base.shovelAudio = ((Component)this).GetComponent<AudioSource>();
			base.shovelHitForce = 1;
			base.reelUp = CrimsonMoonsSemblanceReelUpSFX;
			base.swing = CrimsonMoonsSemblanceSwingSFX;
			base.hitSFX = CrimsonMoonsSemblanceHitSFX;
			((GrabbableObject)this).Start();
		}

		public override void SetControlTipsForItem()
		{
			HUDManager.Instance.ChangeControlTipMultiple(((GrabbableObject)this).itemProperties.toolTips, false, ((GrabbableObject)this).itemProperties);
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((Shovel)this).ItemActivate(used, buttonDown);
		}

		public override void EquipItem()
		{
			((GrabbableObject)this).EquipItem();
			PlayerScript component = ((Component)((GrabbableObject)this).playerHeldBy).GetComponent<PlayerScript>();
			component.UpdateHUD();
		}

		public override void GrabItem()
		{
			((GrabbableObject)this).GrabItem();
			PlayerScript component = ((Component)((GrabbableObject)this).playerHeldBy).GetComponent<PlayerScript>();
			component.BondDamage(component.BondOfLife, ((GrabbableObject)this).playerHeldBy);
			base.shovelHitForce = component.BondOfLife / 10 + 1;
			component.EmebrefireCheck();
			component.PassiveUltGainStatus = true;
			((MonoBehaviour)this).StartCoroutine(component.PassiveUltGain());
			component.UpdateHUD();
		}

		public override void DiscardItem()
		{
			PlayerScript component = ((Component)((GrabbableObject)this).playerHeldBy).GetComponent<PlayerScript>();
			component.BondHeal(component.BondOfLife, ((GrabbableObject)this).playerHeldBy);
			component.PassiveUltGainStatus = false;
			base.shovelHitForce = 1;
			component.EmebrefireCheck();
			((Shovel)this).DiscardItem();
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if ((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null && (Object)(object)((GrabbableObject)this).playerHeldBy.ItemSlots[((GrabbableObject)this).playerHeldBy.currentItemSlot] != (Object)null && ((GrabbableObject)this).playerHeldBy.ItemSlots[((GrabbableObject)this).playerHeldBy.currentItemSlot].itemProperties.itemName == "Crimson Moon's Semblance" && !((GrabbableObject)this).playerHeldBy.isGrabbingObjectAnimation && !((GrabbableObject)this).playerHeldBy.isTypingChat && !((GrabbableObject)this).playerHeldBy.inTerminalMenu && !((GrabbableObject)this).playerHeldBy.inSpecialInteractAnimation && (Object)(object)((GrabbableObject)this).playerHeldBy.hoveringOverTrigger == (Object)null)
			{
				SetupKeyCallbacks();
			}
			else
			{
				StopKeyCallbacks();
			}
		}

		public void SetupKeyCallbacks()
		{
			Plugin.InputActionsInstance.AllIsAshKey.performed += UseAllIsAsh;
			Plugin.InputActionsInstance.BalemoonRisingKey.performed += UseBalemoonRising;
		}

		public void StopKeyCallbacks()
		{
			Plugin.InputActionsInstance.AllIsAshKey.performed -= UseAllIsAsh;
			Plugin.InputActionsInstance.BalemoonRisingKey.performed -= UseBalemoonRising;
		}

		public void UseAllIsAsh(CallbackContext AllIsAshContext)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_00c3: 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)
			if (!((CallbackContext)(ref AllIsAshContext)).performed)
			{
				return;
			}
			PlayerScript component = ((Component)((GrabbableObject)this).playerHeldBy).GetComponent<PlayerScript>();
			Vector3 position = ((Component)this).transform.position;
			int i = 0;
			if (!component.CanMark)
			{
				return;
			}
			for (Collider[] array = Physics.OverlapSphere(position, component.RangeE); i < array.Length; i++)
			{
				EnemyAI componentInParent = ((Component)array[i]).gameObject.GetComponentInParent<EnemyAI>();
				if ((Object)(object)componentInParent != (Object)null && !componentInParent.isEnemyDead && !enemyList.Contains(componentInParent))
				{
					enemyList.Add(componentInParent);
					Debug.Log((object)("CMS: Enemy " + ((Object)componentInParent).name + " has been hitted with All Is Ash!"));
					componentInParent.HitEnemyOnLocalClient(0, default(Vector3), ((GrabbableObject)this).playerHeldBy, true, -2);
				}
			}
			((MonoBehaviour)this).StartCoroutine(component.MarkCooldownE());
			enemyList.Clear();
		}

		public void UseBalemoonRising(CallbackContext BalemoonRisingContext)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			if (!((CallbackContext)(ref BalemoonRisingContext)).performed)
			{
				return;
			}
			PlayerScript component = ((Component)((GrabbableObject)this).playerHeldBy).GetComponent<PlayerScript>();
			Vector3 position = ((Component)this).transform.position;
			int i = 0;
			if (!component.UltOffCooldown || component.UltEnergy != 100)
			{
				return;
			}
			for (Collider[] array = Physics.OverlapSphere(position, component.RangeQ); i < array.Length; i++)
			{
				EnemyAI componentInParent = ((Component)array[i]).gameObject.GetComponentInParent<EnemyAI>();
				if ((Object)(object)componentInParent != (Object)null && !componentInParent.isEnemyDead && !enemyList.Contains(componentInParent))
				{
					enemyList.Add(componentInParent);
					Debug.Log((object)("CMS: Enemy " + ((Object)componentInParent).name + " has been hitted with Balemoon Rising!"));
					componentInParent.HitEnemyOnLocalClient(1, default(Vector3), ((GrabbableObject)this).playerHeldBy, true, -3);
				}
			}
			component.UltHeal();
			((MonoBehaviour)this).StartCoroutine(component.MarkCooldownQ());
			enemyList.Clear();
		}
	}
	internal class MarkScript : MonoBehaviour
	{
		public bool AlreadyStarted = true;

		public bool RemoveMark = false;

		private void Update()
		{
			if (!AlreadyStarted)
			{
				AlreadyStarted = true;
				((MonoBehaviour)this).StartCoroutine(MarkDuration(((Component)this).gameObject));
			}
			if (RemoveMark)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		private static IEnumerator MarkDuration(GameObject gameObject)
		{
			yield return (object)new WaitForSeconds(30f);
			try
			{
				Object.Destroy((Object)(object)gameObject);
			}
			catch
			{
				Debug.Log((object)"CMS: The mark has already been removed");
			}
		}
	}
	internal class PlayerScript : MonoBehaviour
	{
		public int BondOfLife = 0;

		public int UltEnergy = 0;

		public bool CanMark = true;

		public bool UltOffCooldown = true;

		public bool ResetE = false;

		public bool Emberfire = false;

		public bool EmberfireGrace = false;

		public bool EmberfireGraceUsed = false;

		public int CurrentCooldownE = 0;

		public int CurrentCooldownQ = 0;

		public float RangeE = 7.5f;

		public float RangeQ = 10f;

		public int BondOfLifeIncrease = 20;

		public int BondOfLifeDecrease = 10;

		public int CooldownE = 30;

		public int CooldownQ = 15;

		public int UltGain = 12;

		public bool PassiveUltGainStatus = false;

		public int PassiveUltGainValue = 1;

		public int PassiveUltGainIntervall = 21;

		public string AllIsAshKey;

		public string BalemoonRisingKey;

		private PlayerControllerB Player;

		private void Start()
		{
			Player = ((Component)this).GetComponent<PlayerControllerB>();
			SetInputString();
		}

		public void EmebrefireCheck()
		{
			if (EmberfireGraceUsed)
			{
				Debug.Log((object)"CMS: Emberfire immortality effect is active");
			}
			else if (BondOfLife == 100)
			{
				Emberfire = true;
				EmberfireGrace = true;
				Debug.Log((object)"CMS: Emberfire is active");
			}
			else
			{
				Emberfire = false;
				EmberfireGrace = false;
				Debug.Log((object)"CMS: Emberfire is not active");
			}
		}

		public void UpdateDMG(PlayerControllerB currentPlayer)
		{
			if ((Object)(object)currentPlayer.ItemSlots[currentPlayer.currentItemSlot] != (Object)null)
			{
				Item itemProperties = currentPlayer.ItemSlots[currentPlayer.currentItemSlot].itemProperties;
				if (itemProperties.itemName == "Crimson Moon's Semblance")
				{
					Shovel component = ((Component)currentPlayer.ItemSlots[currentPlayer.currentItemSlot]).GetComponent<Shovel>();
					component.shovelHitForce = BondOfLife / 10 + 1;
					Debug.Log((object)("CMS: Weapon DMG = " + component.shovelHitForce));
					EmebrefireCheck();
				}
			}
		}

		public void SetBondOfLife(int bondOfLife)
		{
			Player = ((Component)this).GetComponent<PlayerControllerB>();
			if (((NetworkBehaviour)Player).IsOwner)
			{
				BondOfLife = Mathf.Clamp(bondOfLife, 0, 100);
				Debug.Log((object)("CMS: Applying Bond Of Life, Current Bond Of Life = " + BondOfLife));
				BondDamage(bondOfLife, Player);
				UpdateDMG(Player);
			}
		}

		public void AddBondOfLife(int bondOfLifeIncrease)
		{
			Player = ((Component)this).GetComponent<PlayerControllerB>();
			BondOfLife = Mathf.Clamp(BondOfLife + bondOfLifeIncrease, 0, 100);
			Debug.Log((object)("CMS: Applying Bond Of Life, Current Bond Of Life = " + BondOfLife));
			BondDamage(bondOfLifeIncrease, Player);
			UpdateDMG(Player);
		}

		public void RemoveBondOfLife(int bondOfLifeDecrease)
		{
			Player = ((Component)this).GetComponent<PlayerControllerB>();
			BondOfLife = Mathf.Clamp(BondOfLife - bondOfLifeDecrease, 0, 100);
			Debug.Log((object)("CMS: Removing Bond Of Life, Current Bond Of Life = " + BondOfLife));
			BondHeal(bondOfLifeDecrease, Player);
			UpdateDMG(Player);
		}

		public void BondDamage(int health, PlayerControllerB currentPlayer)
		{
			currentPlayer.health = Mathf.Clamp(currentPlayer.health - health, 1, 100);
			Debug.Log((object)("CMS: Player Health = " + currentPlayer.health));
			HUDManager.Instance.selfRedCanvasGroup.alpha = (float)(100 - Player.health) / 100f;
			if (((NetworkBehaviour)currentPlayer).IsServer)
			{
				currentPlayer.DamagePlayerClientRpc(0, currentPlayer.health);
			}
			else
			{
				currentPlayer.DamagePlayerServerRpc(0, currentPlayer.health);
			}
		}

		public void BondHeal(int health, PlayerControllerB currentPlayer)
		{
			currentPlayer.health = Mathf.Clamp(currentPlayer.health + health, 1, 100);
			Debug.Log((object)("CMS: Player Health = " + currentPlayer.health));
			HUDManager.Instance.selfRedCanvasGroup.alpha = (float)(100 - currentPlayer.health) / 100f;
			if (((NetworkBehaviour)currentPlayer).IsServer)
			{
				currentPlayer.DamagePlayerClientRpc(0, currentPlayer.health);
			}
			else
			{
				currentPlayer.DamagePlayerServerRpc(0, currentPlayer.health);
			}
		}

		public void AddUltProgress(int ultGain)
		{
			UltEnergy = Mathf.Clamp(UltEnergy + ultGain, 0, 100);
			if (UltEnergy == 100)
			{
				UltOffCooldown = true;
			}
			UpdateHUD();
			Debug.Log((object)("CMS: Balemoon Rising Energy = " + UltEnergy));
		}

		public void UltHeal()
		{
			Player = ((Component)this).GetComponent<PlayerControllerB>();
			Player.health = (int)Mathf.Clamp((float)Player.health + (float)BondOfLife * 1.5f, 1f, 100f);
			BondOfLife = 0;
			Debug.Log((object)("CMS: Removing Bond Of Life, Current Bond Of Life = " + BondOfLife));
			Debug.Log((object)("CMS: Player Health = " + Player.health));
			HUDManager.Instance.selfRedCanvasGroup.alpha = (float)(100 - Player.health) / 100f;
			if (((NetworkBehaviour)Player).IsServer)
			{
				Player.DamagePlayerClientRpc(0, Player.health);
			}
			else
			{
				Player.DamagePlayerServerRpc(0, Player.health);
			}
			UpdateDMG(Player);
		}

		public void UpdateHUD()
		{
			Player = ((Component)this).GetComponent<PlayerControllerB>();
			if (!((NetworkBehaviour)Player).IsOwner || !((Object)(object)Player.ItemSlots[Player.currentItemSlot] != (Object)null))
			{
				return;
			}
			Item itemProperties = Player.ItemSlots[Player.currentItemSlot].itemProperties;
			if (itemProperties.itemName == "Crimson Moon's Semblance")
			{
				SetInputString();
				itemProperties.toolTips[0] = "All Is Ash: [" + AllIsAshKey + "]";
				if (CurrentCooldownE != 0)
				{
					itemProperties.toolTips[1] = "[" + AllIsAshKey + "] Cooldown : " + CurrentCooldownE;
					HUDManager.Instance.ChangeControlTipMultiple(itemProperties.toolTips, false, itemProperties);
				}
				else
				{
					itemProperties.toolTips[1] = "[" + AllIsAshKey + "] Cooldown : Ready";
					HUDManager.Instance.ChangeControlTipMultiple(itemProperties.toolTips, false, itemProperties);
				}
				itemProperties.toolTips[2] = "Balemoon Rising: [" + BalemoonRisingKey + "]";
				if (CurrentCooldownQ != 0)
				{
					itemProperties.toolTips[3] = "[" + BalemoonRisingKey + "] Cooldown : " + CurrentCooldownQ;
					HUDManager.Instance.ChangeControlTipMultiple(itemProperties.toolTips, false, itemProperties);
				}
				else if (UltEnergy != 100)
				{
					itemProperties.toolTips[3] = "[" + BalemoonRisingKey + "] Energy : " + UltEnergy + "% (Not Ready)";
					HUDManager.Instance.ChangeControlTipMultiple(itemProperties.toolTips, false, itemProperties);
				}
				else
				{
					itemProperties.toolTips[3] = "[" + BalemoonRisingKey + "] Energy : " + UltEnergy + "% (Ready)";
					HUDManager.Instance.ChangeControlTipMultiple(itemProperties.toolTips, false, itemProperties);
				}
			}
		}

		public void SetInputString()
		{
			AllIsAshKey = InputActionRebindingExtensions.GetBindingDisplayString(Plugin.InputActionsInstance.AllIsAshKey, (DisplayStringOptions)0, (string)null);
			BalemoonRisingKey = InputActionRebindingExtensions.GetBindingDisplayString(Plugin.InputActionsInstance.BalemoonRisingKey, (DisplayStringOptions)0, (string)null);
			AllIsAshKey = AllIsAshKey.Substring(0, AllIsAshKey.IndexOf(" |"));
			BalemoonRisingKey = BalemoonRisingKey.Substring(0, BalemoonRisingKey.IndexOf(" |"));
		}

		public IEnumerator PassiveUltGain()
		{
			while (PassiveUltGainStatus)
			{
				yield return (object)new WaitForSeconds((float)PassiveUltGainIntervall);
				AddUltProgress(PassiveUltGainValue);
				Debug.Log((object)("CMS: Passively gained " + PassiveUltGainValue + " energy for Balemoon Rising"));
			}
		}

		public IEnumerator ActivateEmeberfireGrace(bool hitted = false)
		{
			Player = ((Component)this).GetComponent<PlayerControllerB>();
			if (EmberfireGraceUsed)
			{
				yield break;
			}
			Debug.Log((object)"CMS: Emberfire immortality effect has been activated");
			EmberfireGraceUsed = true;
			yield return (object)new WaitForSeconds(3f);
			if (hitted)
			{
				BondOfLife = 40;
				Player.health = Mathf.Clamp(Player.health - BondOfLife, 1, 100);
				HUDManager.Instance.selfRedCanvasGroup.alpha = (float)(100 - Player.health) / 100f;
				if (((NetworkBehaviour)Player).IsServer)
				{
					Player.DamagePlayerClientRpc(0, Player.health);
				}
				else
				{
					Player.DamagePlayerServerRpc(0, Player.health);
				}
			}
			EmberfireGraceUsed = false;
			Debug.Log((object)"CMS: Emberfire immortality effect has been disabled");
			EmebrefireCheck();
			UpdateDMG(Player);
		}

		public IEnumerator MarkCooldownE()
		{
			Player = ((Component)this).GetComponent<PlayerControllerB>();
			if (((NetworkBehaviour)Player).IsOwner)
			{
				CanMark = false;
				CurrentCooldownE = CooldownE;
				UpdateHUD();
				while (CurrentCooldownE > 0 && !ResetE)
				{
					yield return (object)new WaitForSeconds(1f);
					CurrentCooldownE--;
					UpdateHUD();
				}
				UpdateHUD();
				CanMark = true;
			}
		}

		public IEnumerator MarkCooldownQ()
		{
			Player = ((Component)this).GetComponent<PlayerControllerB>();
			if (((NetworkBehaviour)Player).IsOwner)
			{
				UltOffCooldown = false;
				ResetE = true;
				CanMark = true;
				UltEnergy = 0;
				CurrentCooldownQ = CooldownQ;
				UpdateHUD();
				while (CurrentCooldownQ > 0)
				{
					yield return (object)new WaitForSeconds(1f);
					CurrentCooldownQ--;
					UpdateHUD();
				}
				UpdateHUD();
				UltOffCooldown = true;
				ResetE = false;
			}
		}
	}
	internal class RotateMarkScript : MonoBehaviour
	{
		private void LateUpdate()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.LookAt(((Component)GameNetworkManager.Instance.localPlayerController.gameplayCamera).transform.position, Vector3.up);
		}
	}
}
namespace CrimsonMoonsSemblance.Patch
{
	[HarmonyPatch(typeof(EnemyAI))]
	internal class EnemyAIPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("HitEnemy")]
		private static void HitEnemyPatch(ref EnemyAI __instance, PlayerControllerB playerWhoHit, int hitID)
		{
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance != (Object)null) || !((Object)(object)playerWhoHit != (Object)null) || !((Object)(object)playerWhoHit == (Object)(object)StartOfRound.Instance.localPlayerController) || !((Object)(object)playerWhoHit.ItemSlots[playerWhoHit.currentItemSlot] != (Object)null))
			{
				return;
			}
			GrabbableObject val = playerWhoHit.ItemSlots[playerWhoHit.currentItemSlot];
			PlayerScript component = ((Component)playerWhoHit).GetComponent<PlayerScript>();
			if (!(val.itemProperties.itemName == "Crimson Moon's Semblance") || __instance.isEnemyDead)
			{
				return;
			}
			if (component.Emberfire)
			{
				if (hitID == -2)
				{
					Debug.Log((object)"CMS: Emberfire used on the enemy damaged by All Is Ash");
					component.AddBondOfLife(component.BondOfLifeIncrease);
				}
				else if (Object.op_Implicit((Object)(object)((Component)__instance).transform.Find("CrimsonMoonsSemblanceMark(Clone)")))
				{
					Debug.Log((object)"CMS: Emberfire used on the enemy damaged by an Attack with Mark");
					component.AddBondOfLife(component.BondOfLifeIncrease);
				}
				else if (component.BondOfLife >= 0)
				{
					Debug.Log((object)"CMS: Emberfire used on the enemy damaged by an Attack whitout Mark");
					component.RemoveBondOfLife(component.BondOfLifeDecrease);
				}
				((MonoBehaviour)__instance).StartCoroutine(component.ActivateEmeberfireGrace());
				KillEnemyCMS(__instance);
			}
			else
			{
				switch (hitID)
				{
				case -2:
					if (Object.op_Implicit((Object)(object)((Component)__instance).transform.Find("CrimsonMoonsSemblanceMark(Clone)")))
					{
						Debug.Log((object)"CMS: Mark found on the enemy after damaging him with All Is Ash");
						((Component)((Component)__instance).transform.Find("CrimsonMoonsSemblanceMark(Clone)")).GetComponent<MarkScript>().RemoveMark = true;
						GameObject val2 = Object.Instantiate<GameObject>(Plugin.CrimsonMoonsSemblanceMarkPrefab, ((Component)__instance).transform.position, Quaternion.Euler(0f, 0f, 0f));
						val2.transform.parent = ((Component)((Component)__instance).GetComponent<EnemyAI>()).transform;
					}
					else
					{
						Debug.Log((object)"CMS: Mark not found on enemy after damaging him with All Is Ash");
						GameObject val3 = Object.Instantiate<GameObject>(Plugin.CrimsonMoonsSemblanceMarkPrefab, ((Component)__instance).transform.position, Quaternion.Euler(0f, 0f, 0f));
						val3.transform.parent = ((Component)((Component)__instance).GetComponent<EnemyAI>()).transform;
					}
					break;
				default:
					if (Object.op_Implicit((Object)(object)((Component)__instance).transform.Find("CrimsonMoonsSemblanceMark(Clone)")))
					{
						Debug.Log((object)"CMS: Mark found on the enemy after damaging him with a Normal Attack");
						((Component)((Component)__instance).transform.Find("CrimsonMoonsSemblanceMark(Clone)")).GetComponent<MarkScript>().RemoveMark = true;
						component.AddBondOfLife(component.BondOfLifeIncrease);
					}
					else if (component.BondOfLife > 0)
					{
						Debug.Log((object)"CMS: Mark not found on enemy after damaging him with a Normal Attack");
						component.RemoveBondOfLife(component.BondOfLifeDecrease);
					}
					break;
				case -3:
					break;
				}
			}
			if (hitID != -3)
			{
				component.AddUltProgress(component.UltGain);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("KillEnemy")]
		private static void KillEnemyPatch(EnemyAI __instance)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Invalid comparison between Unknown and I4
			try
			{
				((Component)((Component)__instance).transform.Find("CrimsonMoonsSemblanceMark(Clone)")).GetComponent<MarkScript>().RemoveMark = true;
			}
			catch
			{
				Debug.Log((object)"CMS: Mark not found on the killed enemy");
			}
			if (!((Object)(object)__instance.creatureAnimator != (Object)null))
			{
				return;
			}
			AnimatorControllerParameter[] parameters = __instance.creatureAnimator.parameters;
			foreach (AnimatorControllerParameter val in parameters)
			{
				if ((int)val.type == 4)
				{
					__instance.creatureAnimator.SetBool(val.name, false);
				}
			}
			try
			{
				__instance.creatureAnimator.SetTrigger("KillEnemy");
				__instance.creatureAnimator.SetBool("Dead", true);
			}
			catch
			{
				Debug.Log((object)"CMS: creatureAnimator.SetBool() not found");
			}
			__instance.creatureSFX.Stop();
			__instance.creatureVoice.Stop();
		}

		private static void KillEnemyCMS(EnemyAI enemy)
		{
			Debug.Log((object)("Kill enemy called! destroy: " + enemy.enemyType.destroyOnDeath));
			if (enemy.enemyType.destroyOnDeath)
			{
				if (((NetworkBehaviour)enemy).IsServer)
				{
					Debug.Log((object)"Kill enemy called on server, destroy true");
					enemy.KillEnemy(true);
				}
				else
				{
					enemy.KillEnemyServerRpc(true);
				}
			}
			else
			{
				enemy.KillEnemy(false);
				if (((NetworkBehaviour)enemy).NetworkObject.IsSpawned)
				{
					enemy.KillEnemyServerRpc(false);
				}
			}
		}
	}
	[HarmonyPatch(typeof(IngamePlayerSettings))]
	internal class IngamePlayerSettingsPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("SaveChangedSettings")]
		private static void SaveChangedSettingsPatch()
		{
			try
			{
				((Component)StartOfRound.Instance.localPlayerController).GetComponent<PlayerScript>().UpdateHUD();
			}
			catch
			{
				Debug.Log((object)"CMS: Saving changed settings in the Main Menu");
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("AllowPlayerDeath")]
		private static bool AllowPlayerDeathPatch(ref PlayerControllerB __instance)
		{
			PlayerScript component = ((Component)__instance).GetComponent<PlayerScript>();
			if (component.EmberfireGrace && !component.EmberfireGraceUsed)
			{
				((MonoBehaviour)__instance).StartCoroutine(component.ActivateEmeberfireGrace(hitted: true));
				return false;
			}
			if (component.EmberfireGraceUsed)
			{
				return false;
			}
			if (!StartOfRound.Instance.allowLocalPlayerDeath)
			{
				return false;
			}
			if ((Object)(object)__instance.playersManager.testRoom == (Object)null)
			{
				if (StartOfRound.Instance.timeSinceRoundStarted < 2f)
				{
					return false;
				}
				if (!__instance.playersManager.shipDoorsEnabled)
				{
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		public static void StartPatch()
		{
			List<PlayerControllerB> list = (from PlayerControllerB e in Resources.FindObjectsOfTypeAll(typeof(PlayerControllerB))
				where (Object)(object)e != (Object)null
				select e).ToList();
			foreach (PlayerControllerB item in list)
			{
				if ((Object)(object)((Component)item).GetComponent<PlayerScript>() == (Object)null)
				{
					((Component)item).gameObject.AddComponent<PlayerScript>();
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("ReviveDeadPlayers")]
		public static void ReviveDeadPlayersPatch()
		{
			List<PlayerControllerB> list = (from PlayerControllerB e in Resources.FindObjectsOfTypeAll(typeof(PlayerControllerB))
				where (Object)(object)e != (Object)null
				select e).ToList();
			foreach (PlayerControllerB item in list)
			{
				if (!((Object)(object)((Component)item).GetComponent<PlayerScript>() != (Object)null) || !((Object)(object)item == (Object)(object)StartOfRound.Instance.localPlayerController))
				{
					continue;
				}
				GrabbableObject[] itemSlots = item.ItemSlots;
				foreach (GrabbableObject val in itemSlots)
				{
					if ((Object)(object)val != (Object)null && val.itemProperties.itemName == "Crimson Moon's Semblance")
					{
						PlayerScript component = ((Component)item).gameObject.GetComponent<PlayerScript>();
						component.SetBondOfLife(component.BondOfLife);
					}
				}
			}
		}
	}
}