Decompiled source of Resonance Field Generator v1.3.1

RFGPlugin.dll

Decompiled a year ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using On.RoR2;
using On.RoR2.Items;
using On.RoR2.UI;
using R2API;
using R2API.Utils;
using RoR2;
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.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("RFGPlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RFGPlugin")]
[assembly: AssemblyTitle("RFGPlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace RFGPlugin;

internal static class Log
{
	internal static ManualLogSource _logSource;

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

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

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

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

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

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

	internal static void LogWarning(object data)
	{
		_logSource.LogWarning(data);
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("nobleRadical.RFGPlugin", "RFGPlugin", "1.3.1")]
[R2APISubmoduleDependency(new string[] { "ItemAPI", "LanguageAPI", "RecalculateStatsAPI" })]
public class RFGPlugin : BaseUnityPlugin
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static hook_Init <>9__14_0;

		public static StatHookEventHandler <>9__14_1;

		public static hook_Heal <>9__14_2;

		internal void <Awake>b__14_0(orig_Init orig)
		{
			//IL_0003: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			Pair val = default(Pair);
			val.itemDef1 = Items.PersonalShield;
			val.itemDef2 = myItemDef;
			Pair val2 = val;
			ItemCatalog.itemRelationships[ItemRelationshipTypes.ContagiousItem] = CollectionExtensions.AddToArray<Pair>(ItemCatalog.itemRelationships[ItemRelationshipTypes.ContagiousItem], val2);
			orig.Invoke();
		}

		internal void <Awake>b__14_1(CharacterBody self, StatHookEventArgs args)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)self.inventory != (Object)null)
			{
				int itemCount = self.inventory.GetItemCount(myItemDef.itemIndex);
				float maxHealth = self.maxHealth;
				float maxShield = self.maxShield;
				float num = 0f;
				float num2 = 0f;
				num2 = 0.08f * (float)itemCount * maxHealth;
				num = 0.04f * (float)itemCount * maxHealth;
				if (maxHealth - num < 1f)
				{
					num = maxHealth - 1f;
				}
				args.baseHealthAdd += 0f - num;
				args.baseShieldAdd += num2;
			}
		}

		internal float <Awake>b__14_2(orig_Heal orig, HealthComponent self, float amt, ProcChainMask proc, bool nonRegen)
		{
			//IL_00a2: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)self.body != (Object)null)
			{
				CharacterBody componentInParent = ((Component)self).GetComponentInParent<CharacterBody>();
				if ((Object)(object)componentInParent.inventory != (Object)null)
				{
					int itemCount = componentInParent.inventory.GetItemCount(myItemDef.itemIndex);
					bool flag = componentInParent.inventory.GetItemCount(Items.ShieldOnly.itemIndex) > 0;
					if (itemCount > 0 && nonRegen)
					{
						componentInParent.outOfDangerStopwatch += HealFactor.Value * amt;
					}
					if (flag & componentInParent.outOfDanger)
					{
						self.CallCmdRechargeShieldFull();
					}
				}
			}
			orig.Invoke(self, amt, proc, nonRegen);
			return 0f;
		}
	}

	public const string PluginGUID = "nobleRadical.RFGPlugin";

	public const string PluginAuthor = "nobleRadical";

	public const string PluginName = "RFGPlugin";

	public const string PluginVersion = "1.3.1";

	private static ItemDef myItemDef;

	private Color purple = Color32.op_Implicit(new Color32((byte)135, (byte)0, byte.MaxValue, byte.MaxValue));

	public static PluginInfo PInfo { get; private set; }

	public static ConfigEntry<float> HealFactor { get; set; }

	public void Awake()
	{
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Expected O, but got Unknown
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Expected O, but got Unknown
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Expected O, but got Unknown
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Expected O, but got Unknown
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: 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_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Expected O, but got Unknown
		//IL_019b: 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_01a6: Expected O, but got Unknown
		Log.Init(((BaseUnityPlugin)this).Logger);
		PInfo = ((BaseUnityPlugin)this).Info;
		HealFactor = ((BaseUnityPlugin)this).Config.Bind<float>("base", "Healing Factor", 0.1f, "The amount that shield recharge delay is decreased for every health point healed.");
		myItemDef = ScriptableObject.CreateInstance<ItemDef>();
		((Object)myItemDef).name = "RFG";
		myItemDef.nameToken = "RFG_NAME";
		myItemDef.pickupToken = "RFG_PICKUP";
		myItemDef.descriptionToken = "RFG_DESC";
		myItemDef.loreToken = "RFG_LORE";
		myItemDef.deprecatedTier = (ItemTier)6;
		myItemDef.tags = (ItemTag[])(object)new ItemTag[1] { (ItemTag)3 };
		Assets.Init();
		Log.LogInfo(string.Join(", ", Assets.mainBundle.GetAllAssetNames()));
		myItemDef.pickupIconSprite = Assets.mainBundle.LoadAsset<Sprite>("Assets/texVoidShieldIconSmol.png");
		myItemDef.pickupModelPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/PersonalShield/PickupShieldGenerator.prefab").WaitForCompletion();
		myItemDef.canRemove = true;
		myItemDef.hidden = false;
		AddTokens();
		ItemDisplayRuleDict val = new ItemDisplayRuleDict((ItemDisplayRule[])null);
		ItemAPI.Add(new CustomItem(myItemDef, val));
		object obj = <>c.<>9__14_0;
		if (obj == null)
		{
			hook_Init val2 = delegate(orig_Init orig)
			{
				//IL_0003: 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_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				Pair val5 = default(Pair);
				val5.itemDef1 = Items.PersonalShield;
				val5.itemDef2 = myItemDef;
				Pair val6 = val5;
				ItemCatalog.itemRelationships[ItemRelationshipTypes.ContagiousItem] = CollectionExtensions.AddToArray<Pair>(ItemCatalog.itemRelationships[ItemRelationshipTypes.ContagiousItem], val6);
				orig.Invoke();
			};
			<>c.<>9__14_0 = val2;
			obj = (object)val2;
		}
		ContagiousItemManager.Init += (hook_Init)obj;
		object obj2 = <>c.<>9__14_1;
		if (obj2 == null)
		{
			StatHookEventHandler val3 = delegate(CharacterBody self, StatHookEventArgs args)
			{
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)self.inventory != (Object)null)
				{
					int itemCount2 = self.inventory.GetItemCount(myItemDef.itemIndex);
					float maxHealth = self.maxHealth;
					float maxShield = self.maxShield;
					float num = 0f;
					float num2 = 0f;
					num2 = 0.08f * (float)itemCount2 * maxHealth;
					num = 0.04f * (float)itemCount2 * maxHealth;
					if (maxHealth - num < 1f)
					{
						num = maxHealth - 1f;
					}
					args.baseHealthAdd += 0f - num;
					args.baseShieldAdd += num2;
				}
			};
			<>c.<>9__14_1 = val3;
			obj2 = (object)val3;
		}
		RecalculateStatsAPI.GetStatCoefficients += (StatHookEventHandler)obj2;
		object obj3 = <>c.<>9__14_2;
		if (obj3 == null)
		{
			hook_Heal val4 = delegate(orig_Heal orig, HealthComponent self, float amt, ProcChainMask proc, bool nonRegen)
			{
				//IL_00a2: 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_004e: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)self.body != (Object)null)
				{
					CharacterBody componentInParent = ((Component)self).GetComponentInParent<CharacterBody>();
					if ((Object)(object)componentInParent.inventory != (Object)null)
					{
						int itemCount = componentInParent.inventory.GetItemCount(myItemDef.itemIndex);
						bool flag = componentInParent.inventory.GetItemCount(Items.ShieldOnly.itemIndex) > 0;
						if (itemCount > 0 && nonRegen)
						{
							componentInParent.outOfDangerStopwatch += HealFactor.Value * amt;
						}
						if (flag & componentInParent.outOfDanger)
						{
							self.CallCmdRechargeShieldFull();
						}
					}
				}
				orig.Invoke(self, amt, proc, nonRegen);
				return 0f;
			};
			<>c.<>9__14_2 = val4;
			obj3 = (object)val4;
		}
		HealthComponent.Heal += (hook_Heal)obj3;
		HealthBar.UpdateBarInfos += new hook_UpdateBarInfos(HealthBar_UpdateBarInfos);
		HealthBar.OnEnable += new hook_OnEnable(HealthBar_OnEnable);
		HealthBar.OnInventoryChanged += new hook_OnInventoryChanged(HealthBar_OnInventoryChanged);
		Log.LogInfo("Awake done.");
	}

	private void HealthBar_OnInventoryChanged(orig_OnInventoryChanged orig, HealthBar self)
	{
		//IL_0039: 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)
		orig.Invoke(self);
		int itemCount = self.source.body.inventory.GetItemCount(myItemDef);
		if (itemCount > 0)
		{
			self.barInfoCollection.shieldBarInfo.color = purple;
		}
	}

	private void HealthBar_OnEnable(orig_OnEnable orig, HealthBar self)
	{
		//IL_0039: 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)
		orig.Invoke(self);
		int itemCount = self.source.body.inventory.GetItemCount(myItemDef);
		if (itemCount > 0)
		{
			self.barInfoCollection.shieldBarInfo.color = purple;
		}
	}

	private void HealthBar_UpdateBarInfos(orig_UpdateBarInfos orig, HealthBar self)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: 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_0042: Unknown result type (might be due to invalid IL or missing references)
		bool flag = ((self.barInfoCollection.shieldBarInfo.color == purple) ? true : false);
		orig.Invoke(self);
		if (flag)
		{
			self.barInfoCollection.shieldBarInfo.color = purple;
		}
	}

	private void AddTokens()
	{
		LanguageAPI.Add("RFG_NAME", "Resonance Field Generator");
		LanguageAPI.Add("RFG_PICKUP", "Trade health for a <style=cIsHealing>Regenerating Shield</style>. Recharge faster by healing. <style=cIsVoid>Corrupts all Personal Shield Generators.</style>");
		LanguageAPI.Add("RFG_DESC", $"Trade <style=cIsHealing>4%</style> <style=cStack>(+4% per stack)</style> health for <style=cIsHealing>8%</style> <style=cStack>(+8% per stack)</style> <style=cIsHealing>Regenerating Shield</style>. Each health point healed <style=cArtifact>Decreases recharge delay</style> by {HealFactor.Value} seconds. If Transcendence is active, healing while recharging shield fully recharges it. <style=cIsVoid>Corrupts all Personal Shield Generators.</style>");
		LanguageAPI.Add("RFG_LORE", "It's interesting to see how the void...\r\n\r\ninnovates...\r\n\r\non human designs.\r\n\r\n-Lost Journal, recovered from Petrichor V");
	}
}
public static class Assets
{
	public static AssetBundle mainBundle;

	public const string bundleName = "shieldbundle";

	public static string AssetBundlePath => Path.Combine(RFGPlugin.PInfo.Location, "..", "shieldbundle");

	public static void Init()
	{
		mainBundle = AssetBundle.LoadFromFile(AssetBundlePath);
		Log.LogInfo("RFG Assets Initialized.");
	}
}