Decompiled source of artifact of dueling v0.9.0

PowerMultiply.dll

Decompiled 2 days 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 BepInEx;
using BepInEx.Logging;
using DevTools;
using On.RoR2;
using PowerMultiply.Artifacts;
using PowerMultiply.Assets;
using R2API;
using RoR2;
using RoR2.Artifacts;
using UnityEngine;

[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("PowerMultiply")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PowerMultiply")]
[assembly: AssemblyTitle("PowerMultiply")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DevTools
{
	public static class Devtools
	{
		private static Transform GetCharacterLocation()
		{
			return PlayerCharacterMasterController.instances[0].master.GetBodyObject().transform;
		}

		private static void DropLunarCoin()
		{
			//IL_000c: 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_0017: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			Transform characterLocation = GetCharacterLocation();
			PickupDropletController.CreatePickupDroplet(PickupCatalog.FindPickupIndex(MiscPickups.LunarCoin.miscPickupIndex), characterLocation.position, characterLocation.forward * 20f);
		}

		private static void SpawnFriendlyDoppleganger()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0046: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//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_008d: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			CharacterMaster master = PlayerCharacterMasterController.instances[0].master;
			MasterCopySpawnCard val = MasterCopySpawnCard.FromMaster(master, true, true, (Action<CharacterMaster>)null);
			((SpawnCard)val).DoSpawn(((Component)master).transform.position, Quaternion.AngleAxis((float)Random.Range(0, 360), Vector3.up), new DirectorSpawnRequest((SpawnCard)(object)val, new DirectorPlacementRule
			{
				placementMode = (PlacementMode)3,
				minDistance = 3f,
				maxDistance = 20f,
				spawnOnTarget = ((Component)master).transform
			}, Run.instance.treasureRng)
			{
				teamIndexOverride = (TeamIndex)1
			});
		}

		private static void SpawnEnemyDoppleganger()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0046: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//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_008d: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			CharacterMaster master = PlayerCharacterMasterController.instances[0].master;
			MasterCopySpawnCard val = MasterCopySpawnCard.FromMaster(master, true, true, (Action<CharacterMaster>)null);
			((SpawnCard)val).DoSpawn(((Component)master).transform.position, Quaternion.AngleAxis((float)Random.Range(0, 360), Vector3.up), new DirectorSpawnRequest((SpawnCard)(object)val, new DirectorPlacementRule
			{
				placementMode = (PlacementMode)4,
				minDistance = 3f,
				maxDistance = 20f,
				spawnOnTarget = ((Component)master).transform
			}, Run.instance.treasureRng)
			{
				teamIndexOverride = (TeamIndex)2
			});
		}

		public static void SpawnCommandPickup()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = PlayerCharacterMasterController.instances[0].master.GetBodyObject().transform;
			PickupDef val = CommandArtifactManager.myArtifact.CreatePickupDef();
			val.itemTier = (ItemTier)0;
			PickupDropletController.CreatePickupDroplet(val.pickupIndex, transform.position, transform.forward * 20f);
		}

		public static void onUpdate(ManualLogSource logger)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown((KeyCode)285))
			{
				DropLunarCoin();
			}
			if (Input.GetKeyDown((KeyCode)286))
			{
				SpawnFriendlyDoppleganger();
			}
			if (Input.GetKeyDown((KeyCode)287))
			{
				SpawnEnemyDoppleganger();
			}
			if (Input.GetKeyDown((KeyCode)288))
			{
				SpawnCommandPickup();
			}
			if (Input.GetKeyDown((KeyCode)289))
			{
			}
			if (Input.GetKeyDown((KeyCode)283))
			{
				Transform transform = PlayerCharacterMasterController.instances[0].master.GetBodyObject().transform;
				logger.LogInfo((object)$"Player pressed F2. Spawning our custom item at coordinates {transform.position}");
			}
		}
	}
}
namespace PowerMultiply
{
	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("Isaac_Cummings.PowerMultiply", "PowerMultiply", "0.9")]
	public class PowerMultiply : BaseUnityPlugin
	{
		public const string PluginGUID = "Isaac_Cummings.PowerMultiply";

		public const string PluginAuthor = "Isaac_Cummings";

		public const string PluginName = "PowerMultiply";

		public const string PluginVersion = "0.9";

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

		public static PluginInfo PInfo { get; private set; }

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			((BaseUnityPlugin)this).Logger.LogDebug((object)"Mod Awake! 2");
			PInfo = ((BaseUnityPlugin)this).Info;
			Asset.Init();
			ArtifactOfDeuling item = new ArtifactOfDeuling();
			Artifacts.Add(item);
		}

		private void Update()
		{
			Devtools.onUpdate(((BaseUnityPlugin)this).Logger);
		}
	}
}
namespace PowerMultiply.Utilities
{
	internal class ROR2
	{
		public static float InverseHyperbolicScaling(float baseValue, float additionalValue, float maxValue, int itemCount)
		{
			return baseValue + (maxValue - baseValue) * (1f - 1f / (1f + additionalValue * (float)(itemCount - 1)));
		}
	}
}
namespace PowerMultiply.Extensions
{
	public static class GameObjectExtensions
	{
		public static void LogAllComponents(this GameObject gameObject)
		{
			object[] components = gameObject.GetComponents<object>();
			object[] array = components;
			foreach (object obj in array)
			{
				Log.Debug(obj.ToString());
			}
		}
	}
}
namespace PowerMultiply.Assets
{
	public static class Asset
	{
		public static AssetBundle mainBundle;

		public const string bundleName = "sword";

		public const string assetBundleFolder = "AssetBundles";

		public static string AssetBundlePath => Path.Combine(Path.GetDirectoryName(PowerMultiply.PInfo.Location), "AssetBundles", "sword");

		public static void Init()
		{
			mainBundle = AssetBundle.LoadFromFile(AssetBundlePath);
		}
	}
}
namespace PowerMultiply.Artifacts
{
	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();

		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);
			Init();
		}

		public abstract void Hooks();
	}
	public class ArtifactOfDeuling : ArtifactBase
	{
		public override string ArtifactName => "Artifact Of Dueling";

		public override string ArtifactLangTokenName => "ARTIFACT_OF_DUELING";

		public override string ArtifactDescription => "Winner takes all";

		public override Sprite ArtifactEnabledIcon => Asset.mainBundle.LoadAsset<Sprite>("sword");

		public override Sprite ArtifactDisabledIcon => Asset.mainBundle.LoadAsset<Sprite>("sword");

		public ArtifactOfDeuling()
		{
			CreateArtifact();
		}

		public override void Hooks()
		{
		}

		public override void Init()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			Log.Debug("Artifact initialized");
			CharacterDeathBehavior.OnDeath += new hook_OnDeath(OnDeath);
			SpawnCard.DoSpawn += new hook_DoSpawn(DoSpawn);
		}

		private SpawnResult DoSpawn(orig_DoSpawn orig, SpawnCard self, Vector3 position, Quaternion rotation, DirectorSpawnRequest spawnRequest)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			SpawnResult val = orig.Invoke(self, position, rotation, spawnRequest);
			if (!base.ArtifactEnabled)
			{
				return val;
			}
			if (val.success)
			{
				Inventory component = val.spawnedInstance.GetComponent<Inventory>();
				CharacterMaster component2 = val.spawnedInstance.GetComponent<CharacterMaster>();
				if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null)
				{
					return val;
				}
				uint teamLevel = TeamManager.instance.GetTeamLevel(component2.teamIndex);
				float num = Util.Hyperbolic((float)teamLevel);
				Log.Debug(num);
				if (Util.CheckRoll(30f, component2))
				{
					IEnumerable<ItemDef> source = ((IEnumerable<ItemDef>)(object)ItemCatalog.allItemDefs).Where((ItemDef item) => item.tags.Any((ItemTag tag) => (int)tag == 3 || (int)tag == 1 || (int)tag == 2));
					ItemDef[] array = source.Where((ItemDef item) => (int)item.tier == 0).ToArray();
					ItemDef[] array2 = source.Where((ItemDef item) => (int)item.tier == 1).ToArray();
					ItemDef[] array3 = source.Where((ItemDef item) => (int)item.tier == 2).ToArray();
					double num2 = Math.Ceiling(Random.Range(num / 100f, num));
					Debug.Log((object)("Giving " + num2 + " Items"));
					for (int i = 0; (double)i <= num2; i++)
					{
						int num3 = Random.Range(0, 100);
						ItemDef[] array4 = ((num3 > 98) ? array3 : ((num3 > 80) ? array2 : array));
						int num4 = Random.Range(0, array4.Length - 1);
						Log.Debug("Gave " + ((Object)array4[num4]).name);
						component.GiveItem(array4[num4], 1);
					}
				}
			}
			return val;
		}

		private void OnDeath(orig_OnDeath orig, CharacterDeathBehavior self)
		{
			//IL_00ed: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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)
			if (!base.ArtifactEnabled)
			{
				orig.Invoke(self);
				return;
			}
			Log.Debug("OnDeath");
			CharacterBody characterBody = self.deathStateMachine.commonComponents.characterBody;
			GameObject lastHitAttacker = characterBody.healthComponent.lastHitAttacker;
			CharacterBody val = ((lastHitAttacker != null) ? lastHitAttacker.GetComponent<CharacterBody>() : null);
			int num = characterBody.inventory.GetTotalItemCountOfTier((ItemTier)0) + characterBody.inventory.GetTotalItemCountOfTier((ItemTier)1) + characterBody.inventory.GetTotalItemCountOfTier((ItemTier)2) + characterBody.inventory.GetTotalItemCountOfTier((ItemTier)6) + characterBody.inventory.GetTotalItemCountOfTier((ItemTier)7) + characterBody.inventory.GetTotalItemCountOfTier((ItemTier)8);
			if ((Object)(object)val == (Object)null)
			{
				characterBody.inventory.CleanInventory();
			}
			else if (num > 0)
			{
				Log.Debug("Respawn");
				for (int i = 0; i < characterBody.inventory.itemAcquisitionOrder.Count; i++)
				{
					ItemIndex val2 = characterBody.inventory.itemAcquisitionOrder[i];
					ItemDef itemDef = ItemCatalog.GetItemDef(val2);
					Log.Debug(((Object)itemDef).name);
					if (!itemDef.hidden && Util.CheckRoll(30f, val.master))
					{
						PickupDropletController.CreatePickupDroplet(PickupCatalog.FindPickupIndex(val2), ((Component)self.deathStateMachine).transform.position, new Vector3(0f, 15f, 0f));
						characterBody.inventory.RemoveItem(itemDef, 1);
					}
				}
			}
			orig.Invoke(self);
		}
	}
}