Decompiled source of StandardDuplicator v1.0.0

ExamplePlugin.dll

Decompiled 30 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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.Logging;
using EntityStates;
using EntityStates.Drone;
using ExamplePlugin.MyEntityStates;
using HG.Reflection;
using Microsoft.CodeAnalysis;
using R2API;
using RoR2;
using RoR2.Items;
using RoR2.Skills;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ExamplePlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ExamplePlugin")]
[assembly: AssemblyTitle("ExamplePlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 ExamplePlugin
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.PidoveRamen.StandardDuplicator", "StandardDuplicator", "1.0.0")]
	public class CustomSkillTutorial : BaseUnityPlugin
	{
		public class newDuplicatorBehavior : BaseItemBodyBehavior
		{
			private CharacterMaster junkMaster;

			private static readonly float timeBetweenAdmiralResummons = 30f;

			private static readonly float timeBetweenAdmiralRetryResummons = 1f;

			private float junkResummonCooldown;

			private int previousStack;

			[ItemDefAssociation(useOnServer = true, useOnClient = false)]
			private static ItemDef GetItemDef()
			{
				return Items.Duplicator;
			}

			public void RespawnNow()
			{
				junkResummonCooldown = 0f;
			}

			public override void OnInventoryRefresh()
			{
				((BaseItemBodyBehavior)this).OnInventoryRefresh();
				CalculateNewItemDecayDuration(base.stack);
			}

			private void Start()
			{
				junkResummonCooldown = timeBetweenAdmiralRetryResummons;
			}

			private void FixedUpdate()
			{
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a2: 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)
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c0: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_00db: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e2: 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_00f5: 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_01e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0186: Unknown result type (might be due to invalid IL or missing references)
				int num = 1;
				CharacterMaster master = ((BaseItemBodyBehavior)this).body.master;
				if (!Object.op_Implicit((Object)(object)master))
				{
					return;
				}
				int deployableCount = master.GetDeployableCount(admiralSlot);
				if (deployableCount >= num)
				{
					return;
				}
				junkResummonCooldown -= Time.fixedDeltaTime;
				if (!(junkResummonCooldown <= 0f))
				{
					return;
				}
				junkResummonCooldown = timeBetweenAdmiralRetryResummons;
				CharacterMaster val = (junkMaster = new MasterSummon
				{
					masterPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC3/Drones/JunkDroneMaster.prefab").WaitForCompletion(),
					position = ((BaseItemBodyBehavior)this).body.transform.position + 2f * (Vector3.forward * 3f),
					summonerBodyObject = ((Component)((BaseItemBodyBehavior)this).body).gameObject,
					ignoreTeamMemberLimit = true,
					useAmbientLevel = true,
					propogateMinionOwnership = false,
					teamIndexOverride = (TeamIndex)1
				}.Perform());
				CharacterMaster component = ((Component)val).GetComponent<CharacterMaster>();
				CharacterDeathBehavior component2 = ((Component)val.GetBody()).GetComponent<CharacterDeathBehavior>();
				if (Object.op_Implicit((Object)(object)component2))
				{
					component2.deathState = new SerializableEntityStateType(typeof(MegaDroneDeathState));
				}
				if (Object.op_Implicit((Object)(object)component))
				{
					Deployable val2 = ((Component)component).GetComponent<Deployable>();
					if (!Object.op_Implicit((Object)(object)val2))
					{
						val2 = ((Component)component).gameObject.AddComponent<Deployable>();
					}
					master.AddDeployable(val2, admiralSlot);
				}
				if (Object.op_Implicit((Object)(object)val))
				{
					val.inventory.GiveEquipmentString("BossHunterConsumed");
					CharacterBody body = val.GetBody();
					body.baseNameToken = "Admiral Junksworth";
					body.skillLocator.primary.SetSkillOverride((object)body, treasureSkillDef, (SkillOverridePriority)3);
				}
				deployableCount = master.GetDeployableCount(admiralSlot);
				if (deployableCount < num)
				{
					junkResummonCooldown = timeBetweenAdmiralRetryResummons;
				}
				else
				{
					junkResummonCooldown = timeBetweenAdmiralResummons;
				}
			}

			private void CalculateNewItemDecayDuration(int stack)
			{
				if (stack != previousStack)
				{
					previousStack = stack;
					if (NetworkServer.active)
					{
						float itemDecayDurationServer = 80f + (float)(stack * 10);
						((BaseItemBodyBehavior)this).body.inventory.SetItemDecayDurationServer(itemDecayDurationServer);
					}
				}
			}

			private void OnDisable()
			{
				CalculateNewItemDecayDuration(0);
				if (Object.op_Implicit((Object)(object)junkMaster))
				{
					junkMaster.TrueKill();
					junkMaster = null;
				}
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static GetDeployableSameSlotLimit <0>__GuardLimit;
		}

		private static ItemDef myItemDef;

		public static SkillDef treasureSkillDef;

		public static DeployableSlot admiralSlot;

		private static int GuardLimit(CharacterMaster master, int mult)
		{
			return 1;
		}

		public void RegisterDeployableSlot()
		{
			//IL_001c: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			object obj = <>O.<0>__GuardLimit;
			if (obj == null)
			{
				GetDeployableSameSlotLimit val = GuardLimit;
				<>O.<0>__GuardLimit = val;
				obj = (object)val;
			}
			admiralSlot = DeployableAPI.RegisterDeployableSlot((GetDeployableSameSlotLimit)obj);
		}

		public void Awake()
		{
			//IL_000d: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: 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_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			RegisterDeployableSlot();
			GameObject val = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Commando/CommandoBody.prefab").WaitForCompletion();
			LanguageAPI.Add("JUNKSWORTH_NAME", "Junkworth's Treasure");
			LanguageAPI.Add("JUNKSWORTH_DESCRIPTION", "Drops treasure!");
			treasureSkillDef = ScriptableObject.CreateInstance<SkillDef>();
			treasureDrop.dropTable = Addressables.LoadAssetAsync<PickupDropTable>((object)"RoR2/Base/Common/dtTier3Item.asset").WaitForCompletion();
			treasureDrop.dropDelay = 1f;
			treasureSkillDef.activationState = new SerializableEntityStateType(typeof(treasureDrop));
			treasureSkillDef.activationStateMachineName = "Body";
			treasureSkillDef.baseMaxStock = 1;
			treasureSkillDef.baseRechargeInterval = 60f;
			treasureSkillDef.beginSkillCooldownOnSkillEnd = true;
			treasureSkillDef.canceledFromSprinting = false;
			treasureSkillDef.cancelSprintingOnActivation = true;
			treasureSkillDef.fullRestockOnAssign = true;
			treasureSkillDef.interruptPriority = (InterruptPriority)0;
			treasureSkillDef.isCombatSkill = true;
			treasureSkillDef.mustKeyPress = false;
			treasureSkillDef.rechargeStock = 1;
			treasureSkillDef.requiredStock = 1;
			treasureSkillDef.stockToConsume = 1;
			treasureSkillDef.icon = Addressables.LoadAssetAsync<Sprite>((object)"RoR2/DLC3/Items/Duplicator/texDuplicatorIcon.png").WaitForCompletion();
			treasureSkillDef.skillDescriptionToken = "Drops Legendary items, the amount increasing with difficulty over time!";
			treasureSkillDef.skillName = "Junksworth's Treasure";
			treasureSkillDef.skillNameToken = "Junkworth's Treasure";
			ContentAddition.AddSkillDef(treasureSkillDef);
			bool flag = default(bool);
			ContentAddition.AddEntityState<treasureDrop>(ref flag);
			Log.Init(((BaseUnityPlugin)this).Logger);
			GameObject followerPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC1/BossHunter/DisplayTricornUsed.prefab").WaitForCompletion();
			GameObject val2 = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC3/Drones/JunkDroneBody.prefab").WaitForCompletion();
			CharacterModel component = ((Component)val2.GetComponent<ModelLocator>().modelTransform).GetComponent<CharacterModel>();
			ItemDisplayRuleSet val3 = component.itemDisplayRuleSet;
			ItemDisplayRule val4 = new ItemDisplayRule
			{
				ruleType = (ItemDisplayRuleType)0,
				followerPrefab = followerPrefab,
				childName = "Head",
				localPos = new Vector3(3.264452E-17f, -1.395054f, -0.1339648f),
				localAngles = new Vector3(330f, -2f, 180f),
				localScale = new Vector3(4f, 4f, 4f)
			};
			if (!Object.op_Implicit((Object)(object)val3))
			{
				val3 = ScriptableObject.CreateInstance<ItemDisplayRuleSet>();
				val3.keyAssetRuleGroups = (KeyAssetRuleGroup[])(object)new KeyAssetRuleGroup[0];
				component.itemDisplayRuleSet = val3;
			}
			val3.keyAssetRuleGroups = val3.keyAssetRuleGroups.Append(new KeyAssetRuleGroup
			{
				keyAsset = (Object)(object)Addressables.LoadAssetAsync<EquipmentDef>((object)"RoR2/DLC1/BossHunter/BossHunterConsumed.asset").WaitForCompletion(),
				displayRuleGroup = new DisplayRuleGroup
				{
					rules = (ItemDisplayRule[])(object)new ItemDisplayRule[1] { val4 }
				}
			}).ToArray();
			val3.GenerateRuntimeValues();
			LanguageAPI.Add("ITEM_DUPLICATOR_PICKUP", "Gain a friend who drops temporary items. Picking up an item grants a temporary copy.");
			LanguageAPI.Add("ITEM_DUPLICATOR_DESC", "Gain <style=cIsHealth>Admiral Junksworth</style>, a Junk Drone that only drops Legendary Items. <style=cIsUtility>Picking up an item</style> gives you a <style=cIsTemporary>temporary copy</style> of itself. Temporary items last an additional <style=cIsDamage>10 <style=cStack>(+10 per stack)</style> seconds</style>.");
		}
	}
	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);
		}
	}
}
namespace ExamplePlugin.MyEntityStates
{
	public class treasureDrop : BaseSkillState
	{
		public static float forwardDropForce = 20f;

		public static float dropRadiusCoefficient = 0.6f;

		public static int maxItemCount = 10;

		public static int extraItemsPerTier = 1;

		public static float dropHeight = 7f;

		public static int minTier;

		public static float itemsToDropCoefficient = 0.7f;

		public static float cooldownCoefficientPerTier = 0.5f;

		public static PickupDropTable dropTable;

		public static float dropDelay;

		public static string itemSpawnLocationString;

		private Xoroshiro128Plus rng;

		private int itemsToDrop;

		private int itemsDropped;

		private Transform _muzzle;

		private int flooredDifficulty = 10;

		private int droneUpgradedItemCount;

		private bool noDrop;

		public override InterruptPriority GetMinimumInterruptPriority()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return (InterruptPriority)3;
		}

		public override void OnEnter()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			if (Object.op_Implicit((Object)(object)SceneInfo.instance) && (int)SceneInfo.instance.sceneDef.sceneType == 2)
			{
				bool flag = false;
				List<CombatDirector> instancesList = CombatDirector.instancesList;
				for (int i = 0; i < instancesList.Count; i++)
				{
					CombatDirector val = instancesList[i];
					if (Object.op_Implicit((Object)(object)val) && ((Behaviour)val).isActiveAndEnabled)
					{
						flag = true;
						break;
					}
				}
				if (!(flag | (BossGroup.GetTotalBossCount() > 0)))
				{
					noDrop = true;
					return;
				}
			}
			droneUpgradedItemCount = ((EntityState)this).characterBody.inventory.GetItemCountEffective(Items.DroneUpgradeHidden);
			if (NetworkServer.active)
			{
				rng = new Xoroshiro128Plus(Run.instance.treasureRng.nextUlong);
				flooredDifficulty = Mathf.FloorToInt(Run.instance.ambientLevel * itemsToDropCoefficient);
				itemsToDrop = Mathf.Clamp(flooredDifficulty, 1, maxItemCount);
				itemsToDrop += extraItemsPerTier * droneUpgradedItemCount;
			}
			ChildLocator modelChildLocator = ((EntityState)this).GetModelChildLocator();
			if (Object.op_Implicit((Object)(object)modelChildLocator))
			{
				_muzzle = modelChildLocator.FindChild(itemSpawnLocationString);
			}
			((BaseState)this).OnEnter();
			((EntityState)this).PlayCrossfade("Gesture, Override", "BombsAway", 0.2f);
		}

		private void DropTempItemServer(Vector3 velocity)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkServer.active)
			{
				Vector3 val = (Object.op_Implicit((Object)(object)_muzzle) ? _muzzle.position : ((EntityState)this).transform.position);
				if (Object.op_Implicit((Object)(object)dropTable))
				{
					PickupIndex pickupIndex = dropTable.GeneratePickup(rng).pickupIndex;
					UniquePickup val2 = default(UniquePickup);
					((UniquePickup)(ref val2))..ctor(pickupIndex);
					val2.decayValue = 1f;
					PickupDropletController.CreatePickupDroplet(val2, val, velocity);
				}
			}
		}

		public override void FixedUpdate()
		{
			((EntityState)this).FixedUpdate();
			if (((EntityState)this).fixedAge > dropDelay && ((EntityState)this).isAuthority)
			{
				((EntityState)this).outer.SetNextStateToMain();
			}
		}

		public override void OnExit()
		{
			//IL_00d8: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			if (!noDrop)
			{
				float num = ((EntityState)this).skillLocator.primary.CalculateFinalRechargeInterval();
				float num2 = 1f - Mathf.Pow(cooldownCoefficientPerTier, (float)droneUpgradedItemCount);
				((EntityState)this).skillLocator.primary.RunRecharge(num * num2);
				if (NetworkServer.active && !((EntityState)this).outer.destroying && ((EntityState)this).healthComponent.alive)
				{
					float num3 = (float)itemsToDrop * dropRadiusCoefficient;
					while (itemsDropped < itemsToDrop)
					{
						itemsDropped++;
						float num4 = MathF.PI * 2f * (float)itemsDropped / (float)Mathf.Max(1, itemsToDrop);
						Transform val = (Object.op_Implicit((Object)(object)_muzzle) ? _muzzle : ((EntityState)this).transform);
						Vector3 position = val.position;
						Vector3 forward = val.forward;
						Vector3 val2 = position + ((Vector3)(ref forward)).normalized * forwardDropForce;
						float num5 = val2.x + num3 * Mathf.Cos(num4);
						float num6 = val2.z + num3 * Mathf.Sin(num4);
						DropTempItemServer(new Vector3(((EntityState)this).transform.position.x - num5, dropHeight, ((EntityState)this).transform.position.z - num6));
					}
				}
			}
			((EntityState)this).OnExit();
		}
	}
}