Decompiled source of DroneCommand v1.2.2

DroneCommand.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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using On.RoR2.UI;
using R2API;
using RiskOfOptions;
using RiskOfOptions.Options;
using RoR2;
using RoR2.Artifacts;
using RoR2.UI;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.UI;

[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("DroneCommand")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e28f070335bc7e76dffd7ff53e7cbf5b40d20aa7")]
[assembly: AssemblyProduct("DroneCommand")]
[assembly: AssemblyTitle("DroneCommand")]
[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 DroneCommand
{
	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();
	}
	public static class Asset
	{
		public static AssetBundle mainBundle;

		public const string bundleName = "DroneCommandBundle";

		public static string AssetBundlePath => Path.Combine(Path.GetDirectoryName(typeof(DroneCommandPlugin).Assembly.Location), "DroneCommandBundle");

		public static void Init()
		{
			mainBundle = AssetBundle.LoadFromFile(AssetBundlePath);
		}
	}
	internal class DroneCommandArtifact : ArtifactBase
	{
		public static ConfigEntry<bool> sameTier;

		private Dictionary<DroneIndex, ItemIndex> droneToFakeItem = new Dictionary<DroneIndex, ItemIndex>();

		private Dictionary<ItemIndex, DroneIndex> fakeItemToDrone = new Dictionary<ItemIndex, DroneIndex>();

		private int fakeItemsPool = 50;

		private List<string> fakeItemNames = new List<string>();

		public override string ArtifactName => "Artifact of Drone Command";

		public override string ArtifactLangTokenName => "ARTIFACT_OF_DRONE_COMMAND";

		public override string ArtifactDescription => "Choose your drones.";

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

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

		public override void Init(ConfigFile config)
		{
			CreateConfig(config);
			CreateLang();
			CreateArtifact();
			Hooks();
			CreateFakeItemDefs();
		}

		private void CreateConfig(ConfigFile config)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			sameTier = config.Bind<bool>("Artifact: " + ArtifactName, "SameTier", true, "Only allow to pick drones from the same tier (boring)");
			if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
			{
				Sprite modIcon = Asset.mainBundle.LoadAsset<Sprite>("DroneCommandEnabled.png");
				ModSettingsManager.SetModIcon(modIcon);
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(sameTier));
			}
		}

		public override void Hooks()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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
			Interactor.PerformInteraction += new hook_PerformInteraction(HandleDrone);
			CharacterMaster.Start += new hook_Start(HandleEquipmentDrone);
			ItemCatalog.Init += new hook_Init(ResolveFakeItemDefs);
			PickupPickerPanel.SetPickupOptions += new hook_SetPickupOptions(OverrideColor);
			PickupPickerController.OnDisplayEnd += new hook_OnDisplayEnd(Cleanup);
		}

		private void Cleanup(orig_OnDisplayEnd orig, PickupPickerController self, NetworkUIPromptController networkUIPromptController, LocalUser localUser, CameraRigController cameraRigController)
		{
			orig.Invoke(self, networkUIPromptController, localUser, cameraRigController);
			if (((Object)((Component)self).transform).name.Contains("gofuckyourself"))
			{
				Object.Destroy((Object)(object)((Component)self).gameObject);
			}
		}

		private void OverrideColor(orig_SetPickupOptions orig, PickupPickerPanel self, Option[] options)
		{
			//IL_005c: 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)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self, options);
			if (((Object)((Component)self).transform).name.Contains("fuckingpanel"))
			{
				PickupPickerPanel component = CommandArtifactManager.commandCubePrefab.GetComponent<PickupPickerController>().panelPrefab.GetComponent<PickupPickerPanel>();
				Image[] coloredImages = component.coloredImages;
				Image[] coloredImages2 = self.coloredImages;
				for (int i = 0; i < coloredImages2.Length; i++)
				{
					((Graphic)coloredImages2[i]).color = ((Graphic)coloredImages[i]).color;
					Image obj = coloredImages2[i];
					((Graphic)obj).color = ((Graphic)obj).color * Color32.op_Implicit(new Color32((byte)41, (byte)101, byte.MaxValue, byte.MaxValue));
				}
				coloredImages = component.darkColoredImages;
				coloredImages2 = self.darkColoredImages;
				for (int j = 0; j < self.darkColoredImages.Length; j++)
				{
					((Graphic)coloredImages2[j]).color = ((Graphic)coloredImages[j]).color;
					Image obj2 = coloredImages2[j];
					((Graphic)obj2).color = ((Graphic)obj2).color * Color32.op_Implicit(new Color32((byte)41, (byte)101, byte.MaxValue, byte.MaxValue));
				}
			}
		}

		private void ResolveFakeItemDefs(orig_Init orig)
		{
			//IL_0022: 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_002b: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke();
			DroneDef[] droneDefs = DroneCatalog.droneDefs;
			for (int i = 0; i < droneDefs.Length; i++)
			{
				ItemIndex val = ItemCatalog.FindItemIndex(fakeItemNames[i]);
				DroneIndex droneIndex = droneDefs[i].droneIndex;
				DroneDef val2 = droneDefs[i];
				ItemDef itemDef = ItemCatalog.GetItemDef(val);
				((Object)itemDef).name = ((Object)val2).name;
				itemDef.nameToken = val2.nameToken;
				itemDef.pickupToken = val2.pickupToken;
				itemDef.descriptionToken = val2.descriptionToken;
				itemDef.pickupIconSprite = val2.iconSprite;
				droneToFakeItem.Add(droneIndex, val);
				fakeItemToDrone.Add(val, droneIndex);
			}
		}

		private void CreateFakeItemDefs()
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			for (int i = 0; i < fakeItemsPool; i++)
			{
				ItemDef val = ScriptableObject.CreateInstance<ItemDef>();
				((Object)val).name = $"FAKE_DRONE_{i}_NAME";
				val.nameToken = $"FAKE_DRONE_{i}_NAME";
				val.pickupToken = $"FAKE_DRONE_{i}_PICKUP";
				val.descriptionToken = $"FAKE_DRONE_{i}_DESC";
				val.loreToken = "yes i like femboys";
				val.hidden = true;
				val.canRemove = false;
				val.tags = (ItemTag[])(object)new ItemTag[1] { (ItemTag)9 };
				val.deprecatedTier = (ItemTier)5;
				ItemDisplayRuleDict val2 = new ItemDisplayRuleDict((ItemDisplayRule[])null);
				ItemAPI.Add(new CustomItem(val, val2));
				fakeItemNames.Add(((Object)val).name);
			}
		}

		private void HandleEquipmentDrone(orig_Start orig, CharacterMaster self)
		{
			//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)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Invalid comparison between Unknown and I4
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (base.ArtifactEnabled && (Object)(object)self.bodyPrefab.GetComponent<CharacterBody>() == (Object)(object)BodyPrefabs.EquipmentDroneBody)
			{
				EquipmentIndex currentEquipmentIndex = self.minionOwnership.ownerMaster.inventory.currentEquipmentIndex;
				if ((int)currentEquipmentIndex != -1)
				{
					self.inventory.SetEquipmentIndex(currentEquipmentIndex, false);
				}
			}
			orig.Invoke(self);
		}

		private DroneDef FindDrone(GameObject interactableObject)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			SummonMasterBehavior component = interactableObject.GetComponent<SummonMasterBehavior>();
			DroneVendorTerminalBehavior component2 = interactableObject.GetComponent<DroneVendorTerminalBehavior>();
			DroneDef result = null;
			if (Object.op_Implicit((Object)(object)component))
			{
				CharacterMaster component3 = component.masterPrefab.GetComponent<CharacterMaster>();
				result = DroneCatalog.FindDroneDefFromBody(component3.bodyPrefab);
			}
			if (Object.op_Implicit((Object)(object)component2))
			{
				DroneIndex droneIndex = PickupCatalog.GetPickupDef(component2.currentPickup.pickupIndex).droneIndex;
				result = DroneCatalog.GetDroneDef(droneIndex);
			}
			return result;
		}

		private void HandleDrone(orig_PerformInteraction orig, Interactor self, GameObject interactableObject)
		{
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Expected O, but got Unknown
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Expected O, but got Unknown
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: 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_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkServer.active && base.ArtifactEnabled)
			{
				bool flag = Object.op_Implicit((Object)(object)FindDrone(interactableObject));
				bool flag2 = false;
				PurchaseInteraction component = interactableObject.GetComponent<PurchaseInteraction>();
				if (Object.op_Implicit((Object)(object)component))
				{
					flag2 = !component.CanBeAffordedByInteractor(self);
				}
				if (flag && !flag2)
				{
					GameObject commandCubePrefab = CommandArtifactManager.commandCubePrefab;
					GameObject pickerObj = Object.Instantiate<GameObject>(commandCubePrefab, interactableObject.transform);
					((Object)pickerObj.transform).name = "gofuckyourself";
					PickupCatalog.itemTierToPickupIndex.TryGetValue((ItemTier)5, out var value);
					pickerObj.GetComponent<PickupIndexNetworker>().NetworkpickupState = new UniquePickup(value);
					Rigidbody component2 = pickerObj.GetComponent<Rigidbody>();
					component2.isKinematic = true;
					foreach (Transform item in pickerObj.transform)
					{
						Transform val = item;
						Object.Destroy((Object)(object)((Component)val).gameObject);
					}
					PickupPickerController component3 = pickerObj.GetComponent<PickupPickerController>();
					component3.onUniquePickupSelected = new UniquePickupUnityEvent();
					GameObject panelPrefab = PrefabAPI.InstantiateClone(component3.panelPrefab, "fuckingpanel");
					component3.panelPrefab = panelPrefab;
					DroneDef[] droneDefs = DroneCatalog.droneDefs;
					List<Option> list = new List<Option>();
					for (int i = 0; i < droneDefs.Length; i++)
					{
						if (droneDefs[i].tier == FindDrone(interactableObject).tier || !sameTier.Value)
						{
							droneToFakeItem.TryGetValue(droneDefs[i].droneIndex, out var value2);
							PickupIndex val2 = PickupCatalog.FindPickupIndex(value2);
							list.Add(new Option
							{
								pickup = new UniquePickup(val2),
								available = true
							});
						}
					}
					component3.SetOptionsServer(list.ToArray());
					NetworkServer.Spawn(pickerObj);
					component3.OnInteractionBegin(self);
					((UnityEvent<UniquePickup>)(object)component3.onUniquePickupSelected).AddListener((UnityAction<UniquePickup>)delegate(UniquePickup pickup)
					{
						//IL_0014: 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_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)
						//IL_0035: 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_0045: 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_009c: Unknown result type (might be due to invalid IL or missing references)
						//IL_009d: 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)
						if (NetworkServer.active)
						{
							ItemIndex itemIndex = PickupCatalog.GetPickupDef(pickup.pickupIndex).itemIndex;
							fakeItemToDrone.TryGetValue(itemIndex, out var value3);
							DroneDef droneDef = DroneCatalog.GetDroneDef(value3);
							PickupIndex val3 = PickupCatalog.FindPickupIndex(value3);
							SummonMasterBehavior component4 = interactableObject.GetComponent<SummonMasterBehavior>();
							DroneVendorTerminalBehavior component5 = interactableObject.GetComponent<DroneVendorTerminalBehavior>();
							if (Object.op_Implicit((Object)(object)component4))
							{
								component4.masterPrefab = droneDef.masterPrefab;
							}
							if (Object.op_Implicit((Object)(object)component5))
							{
								component5.currentPickup = new UniquePickup(val3);
							}
							Object.Destroy((Object)(object)pickerObj);
							orig.Invoke(self, interactableObject);
						}
					});
					return;
				}
			}
			orig.Invoke(self, interactableObject);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Slendykray.DroneCommand", "DroneCommand", "1.0.0")]
	public class DroneCommandPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "Slendykray.DroneCommand";

		public const string PluginAuthor = "Slendykray";

		public const string PluginName = "DroneCommand";

		public const string PluginVersion = "1.0.0";

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

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			Asset.Init();
			IEnumerable<Type> enumerable = from type in Assembly.GetExecutingAssembly().GetTypes()
				where !type.IsAbstract && type.IsSubclassOf(typeof(ArtifactBase))
				select type;
			foreach (Type item in enumerable)
			{
				ArtifactBase artifactBase = (ArtifactBase)Activator.CreateInstance(item);
				if (ValidateArtifact(artifactBase, Artifacts))
				{
					artifactBase.Init(((BaseUnityPlugin)this).Config);
				}
			}
		}

		public bool ValidateArtifact(ArtifactBase artifact, List<ArtifactBase> artifactList)
		{
			bool value = ((BaseUnityPlugin)this).Config.Bind<bool>("Artifact: " + artifact.ArtifactName, "Enable Artifact?", true, "Should this artifact appear for selection?").Value;
			if (value)
			{
				artifactList.Add(artifact);
			}
			return value;
		}
	}
	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);
		}
	}
}