Decompiled source of NoProcChainsArtifact v1.2.1

plugins/NoProcChainsArtifact.dll

Decompiled 3 weeks 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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExamplePlugin;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API;
using RiskOfOptions;
using RiskOfOptions.Options;
using RoR2;
using SS2;
using UnityEngine;

[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("NoProcChainsArtifact")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+768c7a279f3307af6c0ae3556b18bed28f10ec8b")]
[assembly: AssemblyProduct("NoProcChainsArtifact")]
[assembly: AssemblyTitle("NoProcChainsArtifact")]
[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 NoProcChainsArtifact
{
	public static class Assets
	{
		public static AssetBundle AssetBundle;

		public const string BundleName = "unchainedartifacticons";

		public static string AssetBundlePath => Path.Combine(Path.GetDirectoryName(NoProcChainsArtifact.PluginInfo.Location), "unchainedartifacticons");

		public static void Init()
		{
			AssetBundle = AssetBundle.LoadFromFile(AssetBundlePath);
		}
	}
	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);
		}
	}
	internal static class ModSupport
	{
		public static class RiskOfOptions
		{
			private static bool? _modexists;

			public static bool ModIsRunning
			{
				get
				{
					if (!_modexists.HasValue)
					{
						_modexists = Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");
					}
					return _modexists.Value;
				}
			}

			[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
			public static void AddOptions()
			{
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Expected O, but got Unknown
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Expected O, but got Unknown
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Expected O, but got Unknown
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Expected O, but got Unknown
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Expected O, but got Unknown
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Expected O, but got Unknown
				//IL_008c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Expected O, but got Unknown
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Expected O, but got Unknown
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b4: Expected O, but got Unknown
				ModSettingsManager.SetModIcon(Assets.AssetBundle.LoadAsset<Sprite>("RoOIcon.png"));
				ModSettingsManager.SetModDescription("Adds an artifact that prevents your items from proccing your on-hit items for you.");
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ArtifactOfTheUnchained.AllowEquipmentProcs));
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ArtifactOfTheUnchained.AllowSawmerangProcs));
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ArtifactOfTheUnchained.AllowElectricBoomerangProcs));
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ArtifactOfTheUnchained.AllowGenericMissileProcs));
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ArtifactOfTheUnchained.AllowFireworkProcs));
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ArtifactOfTheUnchained.AllowShurikenProcs));
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ArtifactOfTheUnchained.AllowEgoProcs));
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ArtifactOfTheUnchained.AllowGloopProcs));
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ArtifactOfTheUnchained.AllowAspectProcs));
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ArtifactOfTheUnchained.AllowProcCrits));
			}
		}

		internal static class Starstorm2
		{
			private static bool? _modexists;

			public static bool ModIsRunning
			{
				get
				{
					if (!_modexists.HasValue)
					{
						_modexists = Chainloader.PluginInfos.ContainsKey("com.TeamMoonstorm");
					}
					return _modexists.Value;
				}
			}

			internal static ItemDef ChirrFlowerItemDef
			{
				get
				{
					if (ModIsRunning)
					{
						return Items.FlowerTurret;
					}
					return null;
				}
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("LordVGames.NoProcChainsArtifact", "NoProcChainsArtifact", "1.2.1")]
	public class NoProcChainsArtifact : BaseUnityPlugin
	{
		public const string PluginGUID = "LordVGames.NoProcChainsArtifact";

		public const string PluginAuthor = "LordVGames";

		public const string PluginName = "NoProcChainsArtifact";

		public const string PluginVersion = "1.2.1";

		public List<ArtifactBase> Artifacts = new List<ArtifactBase>();

		public static PluginInfo PluginInfo { get; private set; }

		public void Awake()
		{
			PluginInfo = ((BaseUnityPlugin)this).Info;
			Log.Init(((BaseUnityPlugin)this).Logger);
			Assets.Init();
			foreach (Type item in from type in Assembly.GetExecutingAssembly().GetTypes()
				where !type.IsAbstract && type.IsSubclassOf(typeof(ArtifactBase))
				select type)
			{
				((ArtifactBase)Activator.CreateInstance(item)).Init(((BaseUnityPlugin)this).Config);
			}
		}
	}
	public class ArtifactOfTheUnchained : ArtifactBase
	{
		public static ConfigEntry<bool> AllowEquipmentProcs;

		public static ConfigEntry<bool> AllowSawmerangProcs;

		public static ConfigEntry<bool> AllowElectricBoomerangProcs;

		public static ConfigEntry<bool> AllowGenericMissileProcs;

		public static ConfigEntry<bool> AllowFireworkProcs;

		public static ConfigEntry<bool> AllowShurikenProcs;

		public static ConfigEntry<bool> AllowEgoProcs;

		public static ConfigEntry<bool> AllowGloopProcs;

		public static ConfigEntry<bool> AllowAspectProcs;

		public static ConfigEntry<bool> AllowProcCrits;

		public override string ArtifactLangTokenName => "NO_PROC_CHAINS";

		public override string ArtifactName => "Artifact of the Unchained";

		public override string ArtifactDescription => "All item effects cannot proc your on-hit item effects for you.";

		public override Sprite ArtifactEnabledIcon => Assets.AssetBundle.LoadAsset<Sprite>("NoProcChainsArtifactIcon_Enabled.png");

		public override Sprite ArtifactDisabledIcon => Assets.AssetBundle.LoadAsset<Sprite>("NoProcChainsArtifactIcon_Disabled.png");

		public override void Init(ConfigFile config)
		{
			CreateLang();
			CreateConfig(config);
			CreateArtifact();
			Hooks();
			if (ModSupport.RiskOfOptions.ModIsRunning)
			{
				ModSupport.RiskOfOptions.AddOptions();
			}
		}

		private void CreateConfig(ConfigFile config)
		{
			AllowEquipmentProcs = config.Bind<bool>(ArtifactName, "Allow equipments to proc items", true, "Should damage from equipments be allowed to proc your on-hit items? This works for all vanilla equipment except for Forgive Me Please and a few that have their own config option.");
			AllowSawmerangProcs = config.Bind<bool>(ArtifactName, "Allow Sawmerang to proc", true, "Should damage from Sawmerang be allowed to proc your on-hit items? WARNING: This will also disable the equipment's built-in bleed on hit!\nThis setting is completely separate from the general equipment procs setting, meaning you can let sawmerang proc while preventing all other equipments from proccing.");
			AllowElectricBoomerangProcs = config.Bind<bool>(ArtifactName, "Allow Electric Boomerang to proc", true, "Should damage from Electric Boomerang be allowed to proc your on-hit items? WARNING: This will also disable the item's built-in stun on hit!");
			AllowGenericMissileProcs = config.Bind<bool>(ArtifactName, "Allow Missiles to proc", false, "Should damage from any item that isn't ATG that fires missiles be allowed to proc your on-hit items? WARNING: This counts for Starstorm 2's Armed Backpack alongside Disposable Missile Launcher!");
			AllowFireworkProcs = config.Bind<bool>(ArtifactName, "Allow Fireworks to proc items", false, "Should damage from Fireworks be allowed to proc your on-hit items?");
			AllowShurikenProcs = config.Bind<bool>(ArtifactName, "Allow Shurikens to proc items", false, "Should damage from Shurikens be allowed to proc your on-hit items?");
			AllowEgoProcs = config.Bind<bool>(ArtifactName, "Allow Egocentrism to proc items", false, "Should damage from Egocentrism be allowed to proc your on-hit items?");
			AllowGloopProcs = config.Bind<bool>(ArtifactName, "Allow Genesis Loop to proc items", true, "Should damage from Genesis Loop be allowed to proc your on-hit items?");
			AllowAspectProcs = config.Bind<bool>(ArtifactName, "Allow attacks from elite aspects to proc items", true, "Should damage from malachite, perfected, gilded, and twisted elites' aspect attacks be allowed to proc your on-hit items? WARNING: Disabling this will also disable those attacks applying an aspect's guranteed debuff such as perfected's cripple!");
			AllowProcCrits = config.Bind<bool>(ArtifactName, "Allow item procs to crit", true, "Should damage from item procs be allowed to crit?");
		}

		public override void Hooks()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			CharacterMaster.OnBodyDamaged += new hook_OnBodyDamaged(CharacterMaster_OnBodyDamaged);
		}

		private void LogDamageInfo(DamageInfo damageInfo)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: 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_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			Log.Debug("");
			Log.Debug("");
			Log.Debug("");
			Log.Debug($"damageInfo.damageType.damageSource is {damageInfo.damageType.damageSource}");
			Log.Debug($"damageInfo.damageType.IsDamageSourceSkillBased is {((DamageTypeCombo)(ref damageInfo.damageType)).IsDamageSourceSkillBased}");
			Log.Debug($"attacker is {damageInfo.attacker}");
			Log.Debug($"canRejectForce is {damageInfo.canRejectForce}");
			Log.Debug($"crit is {damageInfo.crit}");
			Log.Debug($"damage is {damageInfo.damage}");
			Log.Debug($"damageColorIndex is {damageInfo.damageColorIndex}");
			Log.Debug($"damageType is {damageInfo.damageType}");
			Log.Debug($"damageType.damageType is {damageInfo.damageType.damageType}");
			Log.Debug($"damageType.damageTypeCombined is {damageInfo.damageType.damageTypeCombined}");
			Log.Debug($"damageType.damageTypeExtended is {damageInfo.damageType.damageTypeExtended}");
			Log.Debug($"dotIndex is {damageInfo.dotIndex}");
			Log.Debug($"force is {damageInfo.force}");
			Log.Debug($"inflictor is {damageInfo.inflictor}");
			Log.Debug($"position is {damageInfo.position}");
			Log.Debug($"procChainMask is {damageInfo.procChainMask}");
			Log.Debug($"procChainMask.mask is {damageInfo.procChainMask.mask}");
			Log.Debug($"procCoefficient is {damageInfo.procCoefficient}");
			Log.Debug($"rejected is {damageInfo.rejected}");
		}

		private bool ShouldChangeConfigurableItemCoefficient(DamageInfo damageInfo)
		{
			bool result = false;
			switch (((Object)damageInfo.inflictor).name)
			{
			case "StunAndPierceBoomerang(Clone)":
				if (!AllowElectricBoomerangProcs.Value)
				{
					result = true;
				}
				break;
			case "FireworkProjectile(Clone)":
				if (!AllowFireworkProcs.Value)
				{
					result = true;
				}
				break;
			case "ShurikenProjectile(Clone)":
				if (!AllowShurikenProcs.Value)
				{
					result = true;
				}
				break;
			case "LunarSunProjectile(Clone)":
				if (!AllowEgoProcs.Value)
				{
					result = true;
				}
				break;
			case "VagrantNovaItemBodyAttachment(Clone)":
				if (!AllowGloopProcs.Value)
				{
					result = true;
				}
				break;
			case "GoldGatController(Clone)":
			case "BeamSphere(Clone)":
			case "MeteorStorm(Clone)":
			case "VendingMachineProjectile(Clone)":
			case "FireballVehicle(Clone)":
				if (!AllowEquipmentProcs.Value)
				{
					result = true;
				}
				break;
			case "Sawmerang(Clone)":
				if (!AllowSawmerangProcs.Value)
				{
					result = true;
				}
				break;
			case "MissileProjectile(Clone)":
				if (damageInfo.procChainMask.mask != 0 || !AllowGenericMissileProcs.Value)
				{
					result = true;
				}
				break;
			case "LunarMissileProjectile(Clone)":
			case "PoisonOrbProjectile(Clone)":
			case "PoisonStakeProjectile(Clone)":
			case "AffixAurelionitePreStrikeProjectile(Clone)":
			case "AffixAurelioniteCenterProjectile(Clone)":
			case "BeadProjectileTrackingBomb(Clone)":
				if (!AllowAspectProcs.Value)
				{
					result = true;
				}
				break;
			}
			return result;
		}

		private bool ShouldChangeMonsterItemProcCoefficient(DamageInfo damageInfo)
		{
			bool result = false;
			switch (((Object)damageInfo.inflictor).name)
			{
			case "DaggerProjectile(Clone)":
			case "LampBulletPlayer(Clone)":
			case "IcicleAura(Clone)":
			case "RunicMeteorStrikeImpact(Clone)":
			case "BossMissileProjectile(Clone)":
			case "IfritPylonPlayerBody(Clone)":
			case "MushroomWard(Clone)":
			case "ThunderAuraStrike(Clone)":
			case "LunarShockwave(Clone)":
				result = true;
				break;
			}
			return result;
		}

		private bool IsDamageBrokenWithoutInflictor(DamageInfo damageInfo)
		{
			if (damageInfo.damageType.damageTypeCombined == 131328)
			{
				return true;
			}
			string name = ((Object)damageInfo.attacker).name;
			if (name == "SulfurPodBody(Clone)" || name == "ShrineBlood(Clone)")
			{
				return true;
			}
			return false;
		}

		private void CharacterMaster_OnBodyDamaged(orig_OnBodyDamaged orig, CharacterMaster self, DamageReport damageReport)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			if (!base.ArtifactEnabled)
			{
				orig.Invoke(self, damageReport);
				return;
			}
			if (!Object.op_Implicit((Object)(object)damageReport.attacker))
			{
				orig.Invoke(self, damageReport);
				return;
			}
			if (((Enum)damageReport.damageInfo.damageType.damageType).HasFlag((Enum)(object)(DamageType)67108864))
			{
				orig.Invoke(self, damageReport);
				return;
			}
			if (IsDamageBrokenWithoutInflictor(damageReport.damageInfo))
			{
				orig.Invoke(self, damageReport);
				return;
			}
			if (Object.op_Implicit((Object)(object)damageReport.damageInfo.inflictor) && ShouldChangeConfigurableItemCoefficient(damageReport.damageInfo))
			{
				if (!AllowProcCrits.Value)
				{
					damageReport.damageInfo.crit = false;
				}
				damageReport.damageInfo.procCoefficient = 0f;
				orig.Invoke(self, damageReport);
				return;
			}
			if (Object.op_Implicit((Object)(object)damageReport.attackerMaster.playerCharacterMasterController))
			{
				if (!((DamageTypeCombo)(ref damageReport.damageInfo.damageType)).IsDamageSourceSkillBased)
				{
					damageReport.damageInfo.procCoefficient = 0f;
				}
			}
			else if (damageReport.damageInfo.procChainMask.mask != 0)
			{
				damageReport.damageInfo.procCoefficient = 0f;
			}
			else if (!Object.op_Implicit((Object)(object)damageReport.damageInfo.inflictor))
			{
				if (Object.op_Implicit((Object)(object)ModSupport.Starstorm2.ChirrFlowerItemDef) && damageReport.attackerBody.inventory.GetItemCount(ModSupport.Starstorm2.ChirrFlowerItemDef) > 0)
				{
					DamageTypeCombo val = DamageTypeCombo.op_Implicit((DamageType)0);
					val.damageTypeExtended = (DamageTypeExtended)0;
					val.damageSource = (DamageSource)0;
					if (DamageTypeCombo.op_Implicit(damageReport.damageInfo.damageType) != DamageTypeCombo.op_Implicit(val))
					{
						damageReport.damageInfo.procCoefficient = 0f;
					}
				}
				else
				{
					damageReport.damageInfo.procCoefficient = 0f;
				}
			}
			else if (ShouldChangeMonsterItemProcCoefficient(damageReport.damageInfo))
			{
				damageReport.damageInfo.procCoefficient = 0f;
			}
			orig.Invoke(self, damageReport);
		}
	}
}
namespace ExamplePlugin
{
	public abstract class ArtifactBase
	{
		public ArtifactDef ArtifactDef;

		public abstract string ArtifactName { get; }

		public abstract string ArtifactLangTokenName { get; }

		public abstract string ArtifactDescription { get; }

		public abstract Sprite ArtifactEnabledIcon { get; }

		public abstract Sprite ArtifactDisabledIcon { get; }

		public bool ArtifactEnabled => RunArtifactManager.instance.IsArtifactEnabled(ArtifactDef);

		public abstract void Init(ConfigFile config);

		protected void CreateLang()
		{
			LanguageAPI.Add("ARTIFACT_" + ArtifactLangTokenName + "_NAME", ArtifactName);
			LanguageAPI.Add("ARTIFACT_" + ArtifactLangTokenName + "_DESCRIPTION", ArtifactDescription);
		}

		protected void CreateArtifact()
		{
			ArtifactDef = ScriptableObject.CreateInstance<ArtifactDef>();
			ArtifactDef.cachedName = "ARTIFACT_" + ArtifactLangTokenName;
			ArtifactDef.nameToken = "ARTIFACT_" + ArtifactLangTokenName + "_NAME";
			ArtifactDef.descriptionToken = "ARTIFACT_" + ArtifactLangTokenName + "_DESCRIPTION";
			ArtifactDef.smallIconSelectedSprite = ArtifactEnabledIcon;
			ArtifactDef.smallIconDeselectedSprite = ArtifactDisabledIcon;
			ContentAddition.AddArtifactDef(ArtifactDef);
		}

		public abstract void Hooks();
	}
}