Decompiled source of Quantum Entanglement Passive v1.0.0

Plugin.dll

Decompiled 2 days 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.Logging;
using EntityStates;
using EntityStates.Railgunner.Weapon;
using Microsoft.CodeAnalysis;
using On.EntityStates.Railgunner.Weapon;
using R2API;
using RoR2;
using RoR2.Skills;
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("Plugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Plugin")]
[assembly: AssemblyTitle("Plugin")]
[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 Plugin
{
	internal class CustomItems
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_ModifyBullet <>9__1_0;

			public static hook_FireBullet <>9__1_1;

			internal void <Init>b__1_0(orig_ModifyBullet orig, BaseFireSnipe self, BulletAttack bullet)
			{
				if (Object.op_Implicit((Object)(object)((EntityState)self).characterBody.inventory))
				{
					int itemCount = ((EntityState)self).characterBody.inventory.GetItemCount(ProcScalingPassive);
					if (itemCount > 0)
					{
						bullet.procCoefficient *= 1f + 0.01f * ((BaseState)self).critStat;
					}
				}
				orig.Invoke(self, bullet);
				bullet.isCrit = false;
			}

			internal void <Init>b__1_1(orig_FireBullet orig, FirePistol self, Ray bullet)
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				((BaseState)self).critStat = 0f;
				orig.Invoke(self, bullet);
			}
		}

		public static ItemDef ProcScalingPassive;

		public static void Init()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//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_00e2: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			ItemDef val = new ItemDef();
			((Object)val).name = "ProcChanceWithCrit";
			val._itemTierDef = null;
			val.deprecatedTier = (ItemTier)5;
			val.pickupModelPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Mystery/PickupMystery.prefab").WaitForCompletion();
			val.pickupIconSprite = Addressables.LoadAssetAsync<Sprite>((object)"RoR2/Base/Common/MiscIcons/texMysteryIcon.png").WaitForCompletion();
			val.nameToken = "ITEM_PROC_WITH_CRIT_NAME";
			val.pickupToken = "ITEM_PROC_WITH_CRIT_PICKUP";
			val.descriptionToken = "ITEM_PROC_WITH_CRIT_DESC";
			val.loreToken = "ITEM_PROC_WITH_CRIT_LORE";
			ItemTag[] array = new ItemTag[5];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			val.tags = (ItemTag[])(object)array;
			val.canRemove = false;
			val.hidden = true;
			ProcScalingPassive = val;
			ItemDisplayRuleDict val2 = new ItemDisplayRuleDict((ItemDisplayRule[])null);
			CustomItem val3 = new CustomItem(ProcScalingPassive, val2);
			ItemAPI.Add(val3);
			object obj = <>c.<>9__1_0;
			if (obj == null)
			{
				hook_ModifyBullet val4 = delegate(orig_ModifyBullet orig, BaseFireSnipe self, BulletAttack bullet)
				{
					if (Object.op_Implicit((Object)(object)((EntityState)self).characterBody.inventory))
					{
						int itemCount = ((EntityState)self).characterBody.inventory.GetItemCount(ProcScalingPassive);
						if (itemCount > 0)
						{
							bullet.procCoefficient *= 1f + 0.01f * ((BaseState)self).critStat;
						}
					}
					orig.Invoke(self, bullet);
					bullet.isCrit = false;
				};
				<>c.<>9__1_0 = val4;
				obj = (object)val4;
			}
			BaseFireSnipe.ModifyBullet += (hook_ModifyBullet)obj;
			object obj2 = <>c.<>9__1_1;
			if (obj2 == null)
			{
				hook_FireBullet val5 = delegate(orig_FireBullet orig, FirePistol self, Ray bullet)
				{
					//IL_000e: Unknown result type (might be due to invalid IL or missing references)
					((BaseState)self).critStat = 0f;
					orig.Invoke(self, bullet);
				};
				<>c.<>9__1_1 = val5;
				obj2 = (object)val5;
			}
			FirePistol.FireBullet += (hook_FireBullet)obj2;
		}
	}
	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);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("mohrbill.RailgunnerProcChancePassive", "RailgunnerProcChancePassive", "1.0.0")]
	public class Main : BaseUnityPlugin
	{
		public const string PluginGUID = "mohrbill.RailgunnerProcChancePassive";

		public const string PluginAuthor = "mohrbill";

		public const string PluginName = "RailgunnerProcChancePassive";

		public const string PluginVersion = "1.0.0";

		private Sprite LoadSpriteFromDisk()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "QuantumEntanglement.png");
			if (!File.Exists(text))
			{
				Log.Error("File not found at: " + text);
				return null;
			}
			Log.Error("File was found at: " + text);
			byte[] array = File.ReadAllBytes(text);
			Texture2D val = new Texture2D(2, 2);
			if (ImageConversion.LoadImage(val, array))
			{
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			}
			Log.Error("Failed to load texture from image data.");
			return null;
		}

		public void Awake()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Expected O, but got Unknown
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			Log.Init(((BaseUnityPlugin)this).Logger);
			CustomItems.Init();
			GameObject val = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC1/Railgunner/RailgunnerBody.prefab").WaitForCompletion();
			LanguageAPI.Add("RAILGUNNER_PASSIVE_PROCCHANCE_NAME", "Quantum Entanglement");
			LanguageAPI.Add("RAILGUNNER_PASSIVE_PROCCHANCE_DESCRIPTION", "All <style=cIsDamage>Critical Strike Chance</style> is converted into <style=cIsDamage>Proc Chance</style>.");
			PassiveItemSkillDef val2 = ScriptableObject.CreateInstance<PassiveItemSkillDef>();
			val2.passiveItem = CustomItems.ProcScalingPassive;
			((SkillDef)val2).icon = LoadSpriteFromDisk();
			((SkillDef)val2).skillDescriptionToken = "RAILGUNNER_PASSIVE_PROCCHANCE_DESCRIPTION";
			((SkillDef)val2).skillName = "RAILGUNNER_PASSIVE_PROCCHANCE_NAME";
			((SkillDef)val2).skillNameToken = "RAILGUNNER_PASSIVE_PROCCHANCE_NAME";
			ContentAddition.AddSkillDef((SkillDef)(object)val2);
			GenericSkill[] componentsInChildren = val.GetComponentsInChildren<GenericSkill>();
			foreach (GenericSkill val3 in componentsInChildren)
			{
				if (((Object)val3._skillFamily).name.Contains("Passive"))
				{
					SkillFamily skillFamily = val3._skillFamily;
					Array.Resize(ref skillFamily.variants, skillFamily.variants.Length + 1);
					Variant[] variants = skillFamily.variants;
					int num = variants.Length - 1;
					Variant val4 = new Variant
					{
						skillDef = (SkillDef)(object)val2
					};
					((Variant)(ref val4)).viewableNode = new Node(((SkillDef)val2).skillNameToken, false, (Node)null);
					variants[num] = val4;
				}
			}
		}
	}
}