Decompiled source of BetterChefPrimary v1.0.2

plugins/BetterChefPrimary.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Chef;
using HG;
using Microsoft.CodeAnalysis;
using R2API;
using RoR2;
using RoR2.Projectile;
using RoR2.Skills;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BetterChefPrimary
{
	public class AddCleaverToTracker : MonoBehaviour
	{
		public void Start()
		{
			EntityStateMachine val = EntityStateMachine.FindByCustomName(((Component)this).GetComponent<ProjectileController>().owner, "IDEATHHD_BETTERCHEFPRIMARY_ESM");
			if (Object.op_Implicit((Object)(object)val) && val.state != null && val.state is BetterDiceMainStateMachine betterDiceMainStateMachine && ((EntityState)betterDiceMainStateMachine).isAuthority)
			{
				betterDiceMainStateMachine.AddCleaver(((Component)this).GetComponent<CleaverProjectile>());
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("iDeathHD.BetterChefPrimary", "BetterChefPrimary", "1.0.2")]
	public class BetterChefPrimary : BaseUnityPlugin
	{
		public const string PluginGUID = "iDeathHD.BetterChefPrimary";

		public const string PluginAuthor = "iDeathHD";

		public const string PluginName = "BetterChefPrimary";

		public const string PluginVersion = "1.0.2";

		internal static void AddBetterPrimary()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Chef/ChefBody.prefab").WaitForCompletion();
			LanguageAPI.Add("IDEATHHD_BETTERCHEFPRIMARY_BETTERDICE", "Better Dice");
			LanguageAPI.Add("IDEATHHD_BETTERCHEFPRIMARY_BETTERDICE_DESC", "Throw a cleaver through enemies for <style=cIsDamage>250% damage</style>. Dealing <style=cIsDamage>375% damage</style> on the return trip.");
			SkillLocator component = obj.GetComponent<SkillLocator>();
			SkillDef val = Object.Instantiate<SkillDef>(component.primary.skillFamily.variants[0].skillDef);
			val.mustKeyPress = false;
			val.hideStockCount = true;
			val.stockToConsume = 0;
			val.baseMaxStock = 1;
			val.dontAllowPastMaxStocks = true;
			val.rechargeStock = 0;
			val.requiredStock = 0;
			val.skillNameToken = "IDEATHHD_BETTERCHEFPRIMARY_BETTERDICE";
			((Object)val).name = val.skillNameToken;
			val.skillDescriptionToken = "IDEATHHD_BETTERCHEFPRIMARY_BETTERDICE_DESC";
			val.activationState = new SerializableEntityStateType(typeof(BetterDice));
			ContentAddition.AddSkillDef(val);
			bool flag = default(bool);
			ContentAddition.AddEntityState(typeof(BetterDice), ref flag);
			BetterDice.BoostedCleaverPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Chef/ChefDiceEnhanced.prefab").WaitForCompletion();
			BetterDice.BoostedCleaverPrefab.AddComponent<AddCleaverToTracker>();
			BetterDice.CleaverPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Chef/ChefCleaver.prefab").WaitForCompletion();
			BetterDice.CleaverPrefab.AddComponent<AddCleaverToTracker>();
			ref Variant[] variants = ref component.primary.skillFamily.variants;
			Variant val2 = new Variant
			{
				skillDef = val
			};
			((Variant)(ref val2)).viewableNode = new Node(val.skillNameToken, false, (Node)null);
			ArrayUtils.ArrayAppend<Variant>(ref variants, ref val2);
			BetterDiceMainStateMachine.ChefSkillDefs.BetterPrimary = val;
			EntityStateMachine val3 = obj.AddComponent<EntityStateMachine>();
			val3.customName = "IDEATHHD_BETTERCHEFPRIMARY_ESM";
			val3.initialStateType = new SerializableEntityStateType(typeof(BetterDiceMainStateMachine));
			val3.mainStateType = new SerializableEntityStateType(typeof(BetterDiceMainStateMachine));
			ContentAddition.AddEntityState(typeof(BetterDiceMainStateMachine), ref flag);
			ArrayUtils.ArrayAppend<EntityStateMachine>(ref obj.GetComponent<NetworkStateMachine>().stateMachines, ref val3);
		}

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			AddBetterPrimary();
		}
	}
	public class BetterDice : BaseState
	{
		public static GameObject CleaverPrefab;

		public static GameObject BoostedCleaverPrefab;

		public GameObject effectPrefab;

		public GameObject effectEnhancedPrefab;

		public float baseDuration = 2f;

		public float damageCoefficient = 1.2f;

		public float boostedDamageCoefficient = 1.2f;

		public float force = 20f;

		public string attackString;

		public static string returnString;

		public string yesChefAttackString;

		public static string yesChefReturnString;

		public float recoilAmplitude;

		public float bloom;

		public float recallAnimationTransitionTime = 0.2f;

		public float approximateCleaverDistance = 80f;

		internal float duration;

		internal ChefController chefController;

		internal bool hasBoost;

		internal void CacheOriginalFields()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			Dice val = new Dice();
			effectPrefab = val.effectPrefab;
			effectEnhancedPrefab = val.effectEnhancedPrefab;
			baseDuration = val.baseDuration;
			damageCoefficient = val.damageCoefficient;
			boostedDamageCoefficient = val.boostedDamageCoefficient;
			force = val.force;
			attackString = val.attackString;
			returnString = val.returnString;
			yesChefAttackString = val.yesChefAttackString;
			yesChefReturnString = val.yesChefReturnString;
			recoilAmplitude = val.recoilAmplitude;
			bloom = val.bloom;
			recallAnimationTransitionTime = val.recallAnimationTransitionTime;
			approximateCleaverDistance = val.approximateCleaverDistance;
		}

		internal void FireCleaverProjectile(Ray aimRay)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			if (!((EntityState)this).isAuthority)
			{
				return;
			}
			GameObject projectilePrefab;
			int[] array;
			if (hasBoost)
			{
				projectilePrefab = BoostedCleaverPrefab;
				array = new int[3] { 8, 4, 4 };
			}
			else
			{
				projectilePrefab = CleaverPrefab;
				array = new int[1] { 1 };
			}
			int num = array.Length;
			for (int i = 0; i < num; i++)
			{
				int num2 = array[i];
				float num3 = (float)(i % 2) * (0.5f / (float)num2);
				for (int j = 0; j < num2; j++)
				{
					FireProjectileInfo val = default(FireProjectileInfo);
					val.projectilePrefab = projectilePrefab;
					val.position = ((Ray)(ref aimRay)).origin;
					float num4 = (num3 + (float)j / (float)num2) * MathF.PI * 2f;
					float num5 = Mathf.Acos(0.02f + (float)i / (float)num);
					float num6 = Mathf.Sin(num5) * Mathf.Sin(num4);
					float num7 = Mathf.Cos(num5);
					float num8 = Mathf.Sin(num5) * Mathf.Cos(num4);
					Quaternion val2 = Quaternion.LookRotation(new Vector3(num6, num7, num8));
					val.rotation = Util.QuaternionSafeLookRotation(((Ray)(ref aimRay)).direction) * val2;
					val.owner = ((EntityState)this).gameObject;
					val.damage = base.damageStat * damageCoefficient;
					val.damageTypeOverride = DamageTypeCombo.op_Implicit((DamageType)0);
					val.force = force;
					val.crit = Util.CheckRoll(base.critStat, ((EntityState)this).characterBody.master);
					if (!NetworkServer.active && Object.op_Implicit((Object)(object)chefController))
					{
						chefController.CacheCleaverProjectileFireInfo(val);
					}
					ProjectileManager.instance.FireProjectile(val);
				}
			}
		}

		public override void OnEnter()
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			CacheOriginalFields();
			((BaseState)this).OnEnter();
			if (!Object.op_Implicit((Object)(object)chefController))
			{
				chefController = ((EntityState)this).GetComponent<ChefController>();
			}
			chefController.characterBody = ((EntityState)this).characterBody;
			chefController.spreadBloom = bloom;
			hasBoost = ((EntityState)this).characterBody.HasBuff(Buffs.Boosted);
			if (hasBoost)
			{
				damageCoefficient = boostedDamageCoefficient;
				if (NetworkServer.active)
				{
					((EntityState)this).characterBody.RemoveBuff(Buffs.Boosted);
				}
			}
			chefController.NetworkcatchDirtied = false;
			chefController.recallCleaver = false;
			Ray aimRay = ((BaseState)this).GetAimRay();
			TrajectoryAimAssist.ApplyTrajectoryAimAssist(ref aimRay, approximateCleaverDistance, ((EntityState)this).gameObject, 1f);
			duration = baseDuration / base.attackSpeedStat;
			((BaseState)this).StartAimMode(duration + 2f, false);
			PlayThrowCleaverAnimation();
			((BaseState)this).AddRecoil(-1f * recoilAmplitude, -1.5f * recoilAmplitude, -0.25f * recoilAmplitude, 0.25f * recoilAmplitude);
			DoMouthMuzzle();
			FireCleaverProjectile(aimRay);
		}

		internal void PlayThrowCleaverAnimation()
		{
			if (hasBoost)
			{
				((EntityState)this).PlayAnimation("Gesture, Override", "FireSliceAndDice", "FireSliceAndDice.playbackRate", duration, 0f);
				((EntityState)this).PlayAnimation("Gesture, Additive", "FireSliceAndDice", "FireSliceAndDice.playbackRate", duration, 0f);
				Util.PlaySound(yesChefAttackString, ((EntityState)this).gameObject);
			}
			else
			{
				((EntityState)this).PlayAnimation("Gesture, Override", "FireDice", "FireDice.playbackRate", duration, 0f);
				((EntityState)this).PlayAnimation("Gesture, Additive", "FireDice", "FireDice.playbackRate", duration, 0f);
				Util.PlaySound(attackString, ((EntityState)this).gameObject);
			}
		}

		internal void DoMouthMuzzle()
		{
			GameObject val = (hasBoost ? effectEnhancedPrefab : effectPrefab);
			if (Object.op_Implicit((Object)(object)val))
			{
				EffectManager.SimpleMuzzleFlash(val, ((Component)((EntityState)this).characterBody.aimOriginTransform).gameObject, "MouthMuzzle", false);
			}
		}

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

		public override void OnExit()
		{
			chefController.SetYesChefHeatState(false);
			if (NetworkServer.active)
			{
				((EntityState)this).characterBody.RemoveBuff(Buffs.boostedFireEffect);
			}
			if (((EntityState)this).isAuthority)
			{
				chefController.ClearSkillOverrides();
			}
			((EntityState)this).OnExit();
		}

		public override InterruptPriority GetMinimumInterruptPriority()
		{
			return (InterruptPriority)1;
		}
	}
	public class BetterDiceMainStateMachine : BaseState
	{
		public static class ChefSkillDefs
		{
			public static SkillDef BetterPrimary;
		}

		public const string EntityStateMachineCustomName = "IDEATHHD_BETTERCHEFPRIMARY_ESM";

		private List<CleaverProjectile> _activeCleavers = new List<CleaverProjectile>();

		public void AddCleaver(CleaverProjectile cleaverProjectile)
		{
			_activeCleavers.Add(cleaverProjectile);
		}

		public override void FixedUpdate()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Invalid comparison between Unknown and I4
			((EntityState)this).FixedUpdate();
			if ((Object)(object)((EntityState)this).skillLocator.primary.skillDef != (Object)(object)ChefSkillDefs.BetterPrimary)
			{
				return;
			}
			for (int num = _activeCleavers.Count - 1; num >= 0; num--)
			{
				CleaverProjectile val = _activeCleavers[num];
				if (Object.op_Implicit((Object)(object)val) && (int)val.NetworkboomerangState == 3)
				{
					val.NetworkboomerangState = (BoomerangState)2;
					_activeCleavers.RemoveAt(num);
				}
			}
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

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

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

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

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

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

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