Decompiled source of Engi Mechanical Spider Skill v1.1.1

plugins/EngiMechSpiders/EngiMechSpiders.dll

Decompiled 2 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 AncientScepter;
using BepInEx;
using BepInEx.Bootstrap;
using EnemiesReturns.Enemies.MechanicalSpider;
using EnemiesReturns.ModdedEntityStates.MechanicalSpider.Death;
using EngiMechSpiders.Modules;
using EntityStates;
using EntityStates.Engi.EngiWeapon;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API;
using R2API.Utils;
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("EngiMechSpiders")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f64d694dd3610c7767b6f3975f0956ba5f95dd00")]
[assembly: AssemblyProduct("EngiMechSpiders")]
[assembly: AssemblyTitle("EngiMechSpiders")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace EntityStates.Engi.EngiWeapon
{
	public class PlaceMechSpider : PlaceTurret
	{
		public static GameObject masterPrefab;

		public override void OnEnter()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			base.blueprintPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Engi/EngiWalkerTurretBlueprints.prefab").WaitForCompletion();
			base.wristDisplayPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Engi/EngiTurretWristDisplay.prefab").WaitForCompletion();
			base.turretMasterPrefab = masterPrefab;
			((PlaceTurret)this).OnEnter();
		}
	}
}
namespace EngiMechSpiders
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[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("com.Moffein.EngiMechSpiders", "EngiMechSpiders", "1.1.1")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class EngiMechSpiderPlugin : BaseUnityPlugin
	{
		internal static PluginInfo pluginInfo;

		public static SkillDef MechSpiderSkillDef;

		public static SkillDef MechSpiderScepterSkillDef;

		public static ItemDef MechSpiderStatItem;

		public static ItemDef MechSpiderScepterItem;

		private static BodyIndex MechSpiderBodyIndex;

		private static MasterIndex MechSpiderMasterIndex;

		private void Awake()
		{
			pluginInfo = ((BaseUnityPlugin)this).Info;
			CreateSkillDef();
			SetupScepter();
			CreateStatItem();
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(OnLoad));
			Tokens.LoadLanguage();
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("EngiMechSpiders.mechspiderskillbundle");
			AssetBundle val = AssetBundle.LoadFromStream(stream);
			MechSpiderSkillDef.icon = val.LoadAsset<Sprite>("skillMechSpider");
			if (Object.op_Implicit((Object)(object)MechSpiderScepterSkillDef))
			{
				MechSpiderScepterSkillDef.icon = val.LoadAsset<Sprite>("skillMechSpiderScepter");
			}
		}

		private void OnLoad()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			MechSpiderBodyIndex = BodyCatalog.FindBodyIndex("MechanicalSpiderBody");
			MechSpiderMasterIndex = MasterCatalog.FindMasterIndex("MechanicalSpiderMaster");
			PlaceMechSpider.masterPrefab = MasterCatalog.FindMasterPrefab("MechanicalSpiderMaster");
		}

		private void CreateSkillDef()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Expected O, but got Unknown
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			SkillDef val = ScriptableObject.CreateInstance<SkillDef>();
			val.skillName = "ENGI_SPECIAL_MECHSPIDER_NAME";
			val.skillNameToken = "ENGI_SPECIAL_MECHSPIDER_NAME";
			val.skillDescriptionToken = "ENGI_SPECIAL_MECHSPIDER_DESCRIPTION";
			val.keywordTokens = new string[0];
			((Object)val).name = val.skillName;
			val.activationState = new SerializableEntityStateType(typeof(PlaceMechSpider));
			val.activationStateMachineName = "Weapon";
			val.baseMaxStock = 2;
			val.baseRechargeInterval = 30f;
			val.beginSkillCooldownOnSkillEnd = false;
			val.canceledFromSprinting = false;
			val.cancelSprintingOnActivation = true;
			val.fullRestockOnAssign = true;
			val.interruptPriority = (InterruptPriority)1;
			val.isCombatSkill = false;
			val.mustKeyPress = false;
			val.rechargeStock = 1;
			val.requiredStock = 1;
			val.stockToConsume = 0;
			SkillFamily val2 = Addressables.LoadAssetAsync<SkillFamily>((object)"RoR2/Base/Engi/EngiBodySpecialFamily.asset").WaitForCompletion();
			Array.Resize(ref val2.variants, val2.variants.Length + 1);
			Variant[] variants = val2.variants;
			int num = val2.variants.Length - 1;
			Variant val3 = new Variant
			{
				skillDef = val,
				unlockableName = ""
			};
			((Variant)(ref val3)).viewableNode = new Node(val.skillNameToken, false, (Node)null);
			variants[num] = val3;
			ContentAddition.AddSkillDef(val);
			bool flag = default(bool);
			ContentAddition.AddEntityState(typeof(PlaceMechSpider), ref flag);
			MechSpiderSkillDef = val;
		}

		private void SetupScepter()
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			if (Chainloader.PluginInfos.ContainsKey("com.DestroyedClone.AncientScepter"))
			{
				SkillDef val = ScriptableObject.CreateInstance<SkillDef>();
				val.skillName = "ENGI_SPECIAL_MECHSPIDER_SCEPTER_NAME";
				val.skillNameToken = "ENGI_SPECIAL_MECHSPIDER_SCEPTER_NAME";
				val.skillDescriptionToken = "ENGI_SPECIAL_MECHSPIDER_SCEPTER_DESCRIPTION";
				val.keywordTokens = new string[0];
				((Object)val).name = val.skillName;
				val.activationState = new SerializableEntityStateType(typeof(PlaceMechSpider));
				val.activationStateMachineName = "Weapon";
				val.baseMaxStock = 2;
				val.baseRechargeInterval = 30f;
				val.beginSkillCooldownOnSkillEnd = false;
				val.canceledFromSprinting = false;
				val.cancelSprintingOnActivation = true;
				val.fullRestockOnAssign = true;
				val.interruptPriority = (InterruptPriority)1;
				val.isCombatSkill = false;
				val.mustKeyPress = false;
				val.rechargeStock = 1;
				val.requiredStock = 1;
				val.stockToConsume = 0;
				ContentAddition.AddSkillDef(val);
				MechSpiderScepterSkillDef = val;
				CreateScepterItem();
				RegisterScepter();
			}
		}

		private void CreateScepterItem()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			MechSpiderScepterItem = ScriptableObject.CreateInstance<ItemDef>();
			MechSpiderScepterItem.canRemove = false;
			((Object)MechSpiderScepterItem).name = "MoffeinEngiMechSpiderScepterItem";
			MechSpiderScepterItem.deprecatedTier = (ItemTier)5;
			MechSpiderScepterItem.descriptionToken = "Stat modifier for Mech Spiders summoned by Engi with Scepter.";
			MechSpiderScepterItem.nameToken = "MoffeinEngiMechSpiderScepterItem";
			MechSpiderScepterItem.pickupToken = "Stat modifier for Mech Spiders summoned by Engi with Scepter.";
			MechSpiderScepterItem.hidden = true;
			MechSpiderScepterItem.pickupIconSprite = null;
			ItemDef mechSpiderScepterItem = MechSpiderScepterItem;
			ItemTag[] array = new ItemTag[5];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			mechSpiderScepterItem.tags = (ItemTag[])(object)array;
			ItemDisplayRule[] array2 = (ItemDisplayRule[])(object)new ItemDisplayRule[0];
			ItemAPI.Add(new CustomItem(MechSpiderScepterItem, array2));
			RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(MechSpiderScepterItem_Stats);
		}

		private void MechSpiderScepterItem_Stats(CharacterBody sender, StatHookEventArgs args)
		{
			if (Object.op_Implicit((Object)(object)sender.inventory) && sender.inventory.GetItemCount(MechSpiderScepterItem) > 0)
			{
				args.damageMultAdd += 0.3f;
				args.healthMultAdd += 0.3f;
				args.regenMultAdd += 0.3f;
				args.armorAdd += 30f;
				args.moveSpeedMultAdd += 0.3f;
				args.attackSpeedMultAdd += 0.3f;
				args.critAdd += 0.3f;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private void RegisterScepter()
		{
			ItemBase<AncientScepterItem>.instance.RegisterScepterSkill(MechSpiderScepterSkillDef, "EngiBody", MechSpiderSkillDef);
		}

		private void CreateStatItem()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			MechSpiderStatItem = ScriptableObject.CreateInstance<ItemDef>();
			MechSpiderStatItem.canRemove = false;
			((Object)MechSpiderStatItem).name = "MoffeinEngiMechSpiderStatItem";
			MechSpiderStatItem.deprecatedTier = (ItemTier)5;
			MechSpiderStatItem.descriptionToken = "Stat modifier for Mech Spiders summoned by Engi.";
			MechSpiderStatItem.nameToken = "MoffeinEngiMechSpiderStatItem";
			MechSpiderStatItem.pickupToken = "Stat modifier for Mech Spiders summoned by Engi.";
			MechSpiderStatItem.hidden = true;
			MechSpiderStatItem.pickupIconSprite = null;
			ItemDef mechSpiderStatItem = MechSpiderStatItem;
			ItemTag[] array = new ItemTag[5];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			mechSpiderStatItem.tags = (ItemTag[])(object)array;
			ItemDisplayRule[] array2 = (ItemDisplayRule[])(object)new ItemDisplayRule[0];
			ItemAPI.Add(new CustomItem(MechSpiderStatItem, array2));
			RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(MechSpiderStatItem_Stats);
			CharacterBody.onBodyInventoryChangedGlobal += FixDeathState;
			CharacterMaster.AddDeployable += new hook_AddDeployable(CharacterMaster_AddDeployable);
			HealthComponent.TakeDamageProcess += new hook_TakeDamageProcess(HealthComponent_TakeDamageProcess);
		}

		private void HealthComponent_TakeDamageProcess(orig_TakeDamageProcess orig, HealthComponent self, DamageInfo damageInfo)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if (((DamageTypeCombo)(ref damageInfo.damageType)).IsDamageSourceSkillBased && Object.op_Implicit((Object)(object)damageInfo.attacker))
			{
				CharacterBody component = damageInfo.attacker.GetComponent<CharacterBody>();
				if (Object.op_Implicit((Object)(object)component) && component.bodyIndex == MechSpiderBodyIndex)
				{
					damageInfo.damage *= 2.5f;
				}
			}
			orig.Invoke(self, damageInfo);
		}

		private void FixDeathState(CharacterBody body)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			if (body.bodyIndex == MechSpiderBodyIndex && body.inventory.GetItemCount(MechSpiderStatItem) > 0)
			{
				CharacterDeathBehavior component = ((Component)body).GetComponent<CharacterDeathBehavior>();
				if (Object.op_Implicit((Object)(object)component) && ((SerializableEntityStateType)(ref component.deathState)).stateType != typeof(DeathNormal))
				{
					component.deathState = new SerializableEntityStateType(typeof(DeathNormal));
				}
			}
		}

		private void MechSpiderStatItem_Stats(CharacterBody sender, StatHookEventArgs args)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)sender.inventory) && sender.inventory.GetItemCount(MechSpiderStatItem) > 0)
			{
				args.baseRegenAdd += 1f;
				args.levelRegenAdd += 0.2f;
				args.baseMoveSpeedAdd += 1.15f;
				sender.bodyFlags = (BodyFlags)(sender.bodyFlags | 1);
			}
		}

		private void CharacterMaster_AddDeployable(orig_AddDeployable orig, CharacterMaster self, Deployable deployable, DeployableSlot slot)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Invalid comparison between Unknown and I4
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self, deployable, slot);
			if ((int)slot != 1 || !Object.op_Implicit((Object)(object)deployable))
			{
				return;
			}
			CharacterMaster component = ((Component)deployable).GetComponent<CharacterMaster>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return;
			}
			CharacterBody body = component.GetBody();
			if (!Object.op_Implicit((Object)(object)body) || body.bodyIndex != MechSpiderBodyIndex)
			{
				return;
			}
			CharacterBody component2 = MechanicalSpiderDroneBody.BodyPrefab.GetComponent<CharacterBody>();
			body.portraitIcon = component2.portraitIcon;
			Inventory inventory = component.inventory;
			if (!Object.op_Implicit((Object)(object)inventory))
			{
				return;
			}
			if (inventory.GetItemCount(MechSpiderStatItem) <= 0)
			{
				inventory.GiveItem(MechSpiderStatItem, 1);
			}
			if (inventory.GetItemCount(Items.MinionLeash) <= 0)
			{
				inventory.GiveItem(Items.MinionLeash, 1);
			}
			if (Object.op_Implicit((Object)(object)deployable.ownerMaster) && Object.op_Implicit((Object)(object)deployable.ownerMaster.inventory) && (Object)(object)MechSpiderScepterItem != (Object)null)
			{
				ItemIndex val = ItemCatalog.FindItemIndex("ITEM_ANCIENT_SCEPTER");
				if ((int)val != -1 && deployable.ownerMaster.inventory.GetItemCount(val) > 0)
				{
					inventory.GiveItem(MechSpiderScepterItem, 1);
				}
			}
		}
	}
}
namespace EngiMechSpiders.Modules
{
	public class Tokens
	{
		internal static string languageRoot => Path.Combine(assemblyDir, "language");

		internal static string assemblyDir => Path.GetDirectoryName(EngiMechSpiderPlugin.pluginInfo.Location);

		internal static void LoadLanguage()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			Language.SetFolders += new hook_SetFolders(fixme);
		}

		private static void fixme(orig_SetFolders orig, Language self, IEnumerable<string> newFolders)
		{
			if (Directory.Exists(languageRoot))
			{
				IEnumerable<string> second = Directory.EnumerateDirectories(Path.Combine(languageRoot), self.name);
				orig.Invoke(self, newFolders.Union(second));
			}
			else
			{
				orig.Invoke(self, newFolders);
			}
		}
	}
}