Decompiled source of HuntressMomentum2 v2.0.3

HuntressMomentum.dll

Decompiled 2 months ago
using System;
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 BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using JetBrains.Annotations;
using On.RoR2;
using On.RoR2.UI;
using R2API;
using R2API.Utils;
using RoR2;
using RoR2.Skills;
using RoR2.UI;
using UnityEngine;
using UnityEngine.AddressableAssets;

[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("HuntressMomentum")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9cf0c5fdc52b48e162e269647f4987bd0742f881")]
[assembly: AssemblyProduct("HuntressMomentum")]
[assembly: AssemblyTitle("HuntressMomentum")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace HuntressMomentum;

[BepInPlugin("com.doctornoodlearms.huntressmomentum", "Huntress Momentum", "2.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public class SkillMomentum : SkillDef
	{
		public static bool assigned;

		public override BaseSkillInstanceData OnAssigned([NotNull] GenericSkill skillSlot)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			if (!assigned)
			{
				CharacterBody.FixedUpdate += new hook_FixedUpdate(CharacterBody_FixedUpdate);
				GlobalEventManager.onCharacterLevelUp += GlobalEventManager_onCharacterLevelUp;
				RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(RecalculateStatsAPI_GetStatCoefficients);
				GlobalEventManager.onServerDamageDealt += GlobalEventManager_onServerDamageDealt;
				Run.onRunDestroyGlobal += Run_onRunDestroyGlobal;
				assigned = true;
			}
			return ((SkillDef)this).OnAssigned(skillSlot);
		}

		public void CharacterBody_FixedUpdate(orig_FixedUpdate orig, CharacterBody self)
		{
			orig.Invoke(self);
			if (!((Object)(object)((self != null) ? self.skillLocator : null) != (Object)null) || !((Object)(object)self.skillLocator.FindSkillByDef(skill) != (Object)null) || !((Object)(object)((self != null) ? self.inventory : null) != (Object)null) || !self.isSprinting || self.GetBuffCount(momentum) >= MaxStacks.Value)
			{
				return;
			}
			buffTimer -= Time.deltaTime * timeScalar;
			if (buffTimer <= 0f)
			{
				buffTimer = BaseDuration.Value;
				self.AddBuff(momentum);
				if (self.GetBuffCount(momentum) >= MaxStacks.Value)
				{
					self.MarkAllStatsDirty();
				}
			}
		}

		public void GlobalEventManager_onCharacterLevelUp(CharacterBody body)
		{
			if ((Object)(object)body != (Object)null)
			{
				timeScalar = LevelDuration.Value * Mathf.Log(body.level) + 1f;
			}
		}

		public void RecalculateStatsAPI_GetStatCoefficients(CharacterBody self, StatHookEventArgs args)
		{
			if ((Object)(object)self != (Object)null && self.GetBuffCount(momentum) >= MaxStacks.Value)
			{
				args.critAdd += 100f;
			}
		}

		public void GlobalEventManager_onServerDamageDealt(DamageReport report)
		{
			if (!((Object)(object)report?.attackerBody == (Object)null) && report.attackerBody.GetBuffCount(momentum) >= MaxStacks.Value && report.damageInfo.crit)
			{
				while (report.attackerBody.HasBuff(momentum))
				{
					report.attackerBody.RemoveBuff(momentum);
				}
				report.attackerBody.MarkAllStatsDirty();
			}
		}

		public void Run_onRunDestroyGlobal(Run _)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			CharacterBody.FixedUpdate -= new hook_FixedUpdate(CharacterBody_FixedUpdate);
			GlobalEventManager.onCharacterLevelUp -= GlobalEventManager_onCharacterLevelUp;
			RecalculateStatsAPI.GetStatCoefficients -= new StatHookEventHandler(RecalculateStatsAPI_GetStatCoefficients);
			GlobalEventManager.onServerDamageDealt -= GlobalEventManager_onServerDamageDealt;
			Run.onRunDestroyGlobal -= Run_onRunDestroyGlobal;
			assigned = false;
		}
	}

	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static Func<Row, bool> <>9__22_1;

		public static hook_Rebuild <>9__22_0;

		internal void <RegisterSkill>b__22_0(orig_Rebuild orig, LoadoutPanelController self)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (self.currentDisplayData.bodyIndex != BodyCatalog.FindBodyIndex("HuntressBody"))
			{
				return;
			}
			Row val = ((IEnumerable<Row>)self.rows).FirstOrDefault((Func<Row, bool>)delegate(Row x)
			{
				object obj;
				if (x == null)
				{
					obj = null;
				}
				else
				{
					RectTransform rowPanelTransform = x.rowPanelTransform;
					if (rowPanelTransform == null)
					{
						obj = null;
					}
					else
					{
						Transform obj2 = ((Transform)rowPanelTransform).Find("LabelContainer");
						if (obj2 == null)
						{
							obj = null;
						}
						else
						{
							Transform obj3 = obj2.Find("SlotLabel");
							if (obj3 == null)
							{
								obj = null;
							}
							else
							{
								LanguageTextMeshController component = ((Component)obj3).GetComponent<LanguageTextMeshController>();
								obj = ((component != null) ? component.token : null);
							}
						}
					}
				}
				if (obj == null)
				{
					obj = "";
				}
				string text = (string)obj;
				return text == "LOADOUT_SKILL_MISC" || text.ToLower() == "passive";
			});
			if (val != null)
			{
				((Transform)val.rowPanelTransform).SetAsFirstSibling();
			}
		}

		internal bool <RegisterSkill>b__22_1(Row x)
		{
			object obj;
			if (x == null)
			{
				obj = null;
			}
			else
			{
				RectTransform rowPanelTransform = x.rowPanelTransform;
				if (rowPanelTransform == null)
				{
					obj = null;
				}
				else
				{
					Transform obj2 = ((Transform)rowPanelTransform).Find("LabelContainer");
					if (obj2 == null)
					{
						obj = null;
					}
					else
					{
						Transform obj3 = obj2.Find("SlotLabel");
						if (obj3 == null)
						{
							obj = null;
						}
						else
						{
							LanguageTextMeshController component = ((Component)obj3).GetComponent<LanguageTextMeshController>();
							obj = ((component != null) ? component.token : null);
						}
					}
				}
			}
			if (obj == null)
			{
				obj = "";
			}
			string text = (string)obj;
			return text == "LOADOUT_SKILL_MISC" || text.ToLower() == "passive";
		}
	}

	public const string pluginGUID = "com.doctornoodlearms.huntressmomentum";

	public const string pluginAuthor = "doctornoodlearms";

	public const string pluginName = "Huntress Momentum";

	public const string pluginVersion = "2.0.2";

	public static ManualLogSource Log;

	internal static PluginInfo pluginInfo;

	public static ConfigFile Config;

	private static AssetBundle _assetBundle;

	public static ConfigEntry<int> MaxStacks;

	public static ConfigEntry<float> BaseDuration;

	public static ConfigEntry<float> LevelDuration;

	public static BuffDef momentum;

	public static GenericSkill skillContainer;

	public static SkillDef skill;

	public static UnlockableDef unlockable;

	public static float buffTimer;

	public static float timeScalar;

	public static bool clearingBuff;

	public static AssetBundle AssetBundle
	{
		get
		{
			if ((Object)(object)_assetBundle == (Object)null)
			{
				_assetBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(pluginInfo.Location), "huntressmomentum"));
			}
			return _assetBundle;
		}
	}

	private void Awake()
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		pluginInfo = ((BaseUnityPlugin)this).Info;
		Log = ((BaseUnityPlugin)this).Logger;
		Config = new ConfigFile(Path.Combine(Paths.ConfigPath, "com.doctornoodlearms.huntressmomentum.cfg"), true);
		MaxStacks = Config.Bind<int>("Balance", "Required Stacks", 10, "Required stacks of momentum to guarantee crit.");
		BaseDuration = Config.Bind<float>("Balance", "Base Duration per Stack", 1f, "Required seconds needed to gain a stack.");
		LevelDuration = Config.Bind<float>("Balance", "Duration Multiplier per Level", 0.36f, "Momentum gain +% per level.");
		buffTimer = BaseDuration.Value;
		timeScalar = 1f;
		RegisterBuff();
		RegisterSkill();
	}

	public static void RegisterBuff()
	{
		momentum = ScriptableObject.CreateInstance<BuffDef>();
		((Object)momentum).name = "NOODLE_HUNTRESSBUFF_NAME";
		LanguageAPI.Add(((Object)momentum).name, "Momentum");
		momentum.canStack = true;
		momentum.isDebuff = false;
		momentum.isHidden = false;
		momentum.iconSprite = AssetBundle.LoadAsset<Sprite>("Assets/momentumBuff.png");
		ContentAddition.AddBuffDef(momentum);
	}

	public static void RegisterSkill()
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Expected O, but got Unknown
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Expected O, but got Unknown
		skill = (SkillDef)(object)ScriptableObject.CreateInstance<SkillMomentum>();
		((Object)skill).name = "Momentum";
		skill.icon = AssetBundle.LoadAsset<Sprite>("Assets/momentumSkill.png");
		skill.activationState = new SerializableEntityStateType("EntityStates.Idle");
		skill.activationStateMachineName = "Body";
		skill.baseMaxStock = 1;
		skill.baseRechargeInterval = 0f;
		skill.beginSkillCooldownOnSkillEnd = false;
		skill.isCombatSkill = false;
		skill.mustKeyPress = false;
		skill.skillNameToken = "NOODLE_HUNTRESSPASSIVE_NAME";
		skill.skillDescriptionToken = "NOODLE_HUNTRESSPASSIVE_DESC";
		skill.keywordTokens = new string[1] { "NOODLE_HUNTRESSPASSIVE_KEYWORD" };
		LanguageAPI.Add(skill.skillNameToken, "Momentum");
		LanguageAPI.Add(skill.skillDescriptionToken, $"<style=cIsUtility>Sprinting</style> gives stacks of <style=cIsUtility>Momentum</style>. At {MaxStacks.Value} stacks, the next attack is a <style=\"cIsDamage\">Critical Strike</style>.");
		LanguageAPI.Add(skill.keywordTokens[0], $"<style=cKeywordName>Momentum</style><style=cSub>At {MaxStacks.Value} stacks, the next attack is a <style=\"cIsDamage\">Critical Strike</style>.</style>");
		ContentAddition.AddSkillDef(skill);
		GameObject val = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Huntress/HuntressBody.prefab").WaitForCompletion();
		SkillFamily val2 = ScriptableObject.CreateInstance<SkillFamily>();
		((Object)val2).name = "HuntressBodyPassiveFamily";
		Variant[] array = new Variant[1];
		Variant val3 = new Variant
		{
			skillDef = skill,
			unlockableDef = null
		};
		((Variant)(ref val3)).viewableNode = new Node(skill.skillNameToken, false, (Node)null);
		array[0] = val3;
		val2.variants = (Variant[])(object)array;
		ContentAddition.AddSkillFamily(val2);
		skillContainer = val.AddComponent<GenericSkill>();
		skillContainer._skillFamily = val2;
		object obj = <>c.<>9__22_0;
		if (obj == null)
		{
			hook_Rebuild val4 = delegate(orig_Rebuild orig, LoadoutPanelController self)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				orig.Invoke(self);
				if (self.currentDisplayData.bodyIndex == BodyCatalog.FindBodyIndex("HuntressBody"))
				{
					Row val5 = ((IEnumerable<Row>)self.rows).FirstOrDefault((Func<Row, bool>)delegate(Row x)
					{
						object obj2;
						if (x == null)
						{
							obj2 = null;
						}
						else
						{
							RectTransform rowPanelTransform = x.rowPanelTransform;
							if (rowPanelTransform == null)
							{
								obj2 = null;
							}
							else
							{
								Transform obj3 = ((Transform)rowPanelTransform).Find("LabelContainer");
								if (obj3 == null)
								{
									obj2 = null;
								}
								else
								{
									Transform obj4 = obj3.Find("SlotLabel");
									if (obj4 == null)
									{
										obj2 = null;
									}
									else
									{
										LanguageTextMeshController component = ((Component)obj4).GetComponent<LanguageTextMeshController>();
										obj2 = ((component != null) ? component.token : null);
									}
								}
							}
						}
						if (obj2 == null)
						{
							obj2 = "";
						}
						string text = (string)obj2;
						return text == "LOADOUT_SKILL_MISC" || text.ToLower() == "passive";
					});
					if (val5 != null)
					{
						((Transform)val5.rowPanelTransform).SetAsFirstSibling();
					}
				}
			};
			<>c.<>9__22_0 = val4;
			obj = (object)val4;
		}
		LoadoutPanelController.Rebuild += (hook_Rebuild)obj;
	}
}