Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of DroneUpgradeStation v1.0.2
DroneUpgradeStation/DroneUpgradeStation.dll
Decompiled 2 months agousing System; 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.Configuration; using BepInEx.Logging; using EntityStates; using EntityStates.DroneAssemblyStation; using EntityStates.DroneCombiner; using HG; using IL.EntityStates.DroneAssemblyStation; using LeTai.Asset.TranslucentImage; using Mono.Cecil.Cil; using MonoMod.Cil; using On.EntityStates.DroneAssemblyStation; using On.EntityStates.DroneCombiner; using On.RoR2.UI; using R2API; using RoR2; using RoR2.ExpansionManagement; using RoR2.UI; using UnityEngine; using UnityEngine.AddressableAssets; 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 = "")] [assembly: AssemblyCompany("DroneUpgradeStation")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("DroneUpgradeStation")] [assembly: AssemblyTitle("DroneUpgradeStation")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] namespace DroneUpgradeStation; public static class Configs { public static string defaultBlacklist = "TreasureCache, FreeChest, Firework, Squid, LowerPricedChests, ExtraShrineItem, Feather, JumpBoost, Duplicator, BarrageOnBoss, ExtraEquipment"; public static string defaultSceneList = "dampcavesimple, shipgraveyard, rootjungle, repurposedcrater, conduitcanyon, skymeadow, helminthroost"; public static ConfigEntry<bool> blacklistCannotCopy { get; private set; } public static ConfigEntry<string> blacklistExtraList { get; private set; } public static ConfigEntry<bool> bodyFlagMechanical { get; private set; } public static ConfigEntry<int> creditCost { get; private set; } public static ConfigEntry<int> maxSpawns { get; private set; } public static ConfigEntry<int> minStage { get; private set; } public static ConfigEntry<string> sceneList { get; private set; } public static ConfigEntry<int> weight { get; private set; } public static ConfigEntry<bool> spawnOnComputationalExchange { get; private set; } public static void Init(ConfigFile cfg) { blacklistCannotCopy = cfg.Bind<bool>("Functionality", "Blacklist CannotCopy Items", true, "Blacklist all items with the CannotCopy tag.\nOr, in other words, items that turrets don't inherit."); blacklistExtraList = cfg.Bind<string>("Functionality", "Blacklist Extra Items", defaultBlacklist, "Blacklist additional items of your choice by listing their internal names.\nMake sure to separate them with commas."); bodyFlagMechanical = cfg.Bind<bool>("Functionality", "Upgrade Mechanical Minions", true, "Allow all Mechanical minions to benefit from the interactable.\nSetting to false will only allow Drones to benefit."); creditCost = cfg.Bind<int>("Spawn Parameters", "Credit Cost", 30, "Set the director credit cost.\nFor reference, a regular Chest costs 15."); maxSpawns = cfg.Bind<int>("Spawn Parameters", "Max Spawns", 1, "Set the maximum amount of times it can spawn per stage. Set to negative for no limit."); minStage = cfg.Bind<int>("Spawn Parameters", "Minimum Stage", 1, "Set the earliest stage number it can spawn in."); sceneList = cfg.Bind<string>("Spawn Parameters", "Scene List", defaultSceneList, "List the internal names of the stages it'll spawn in.\nMake sure to separate them with commas."); weight = cfg.Bind<int>("Spawn Parameters", "Selection Weight", 4, "Set the odds of it being selected to spawn.\nBy default, it is as rare as Drone Combiner Stations, which is to say, pretty uncommon."); spawnOnComputationalExchange = cfg.Bind<bool>("Spawn Parameters", "Spawn on Computational Exchange", true, "A guaranteed Drone Upgrade Station will appear on Computational Exchange."); } } 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.*/)] [BepInPlugin("Samuel17.DroneUpgradeStation", "DroneUpgradeStation", "1.0.2")] public class Main : BaseUnityPlugin { public static InteractableSpawnCard iscDroneAssemblyStation = Addressables.LoadAssetAsync<InteractableSpawnCard>((object)"RoR2/DLC3/DroneAssemblyStation/iscDroneAssemblyStation.asset").WaitForCompletion(); public static Material matDroneAssemblyStation = Addressables.LoadAssetAsync<Material>((object)"RoR2/DLC3/DroneAssemblyStation/matDroneAssemblyStation.mat").WaitForCompletion(); public static GameObject droneAssemblyStationPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC3/DroneAssemblyStation/DroneAssemblyStation.prefab").WaitForCompletion(); public static ExplicitPickupDropTable blacklist = Addressables.LoadAssetAsync<ExplicitPickupDropTable>((object)"RoR2/DLC3/DroneAssemblyStation/ExcludedItemsDropTable.asset").WaitForCompletion(); public static GameObject pickerPanel = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC3/DroneAssemblyStation/AssemblyStationPickerPanelv2.prefab").WaitForCompletion(); public static ExpansionDef dlc3 = Addressables.LoadAssetAsync<ExpansionDef>((object)"RoR2/DLC3/DLC3.asset").WaitForCompletion(); public void Awake() { //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Expected O, but got Unknown //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_00db: Unknown result type (might be due to invalid IL or missing references) Log.Init(((BaseUnityPlugin)this).Logger); Configs.Init(((BaseUnityPlugin)this).Config); if (Configs.bodyFlagMechanical.Value) { bool hookFailed = true; AssemblingDroneState.OnEnter += (Manipulator)delegate(ILContext il) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown ILCursor val2 = new ILCursor(il); if (val2.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1] { (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, typeof(CharacterBody), "bodyFlags") })) { val2.RemoveRange(3); val2.EmitDelegate<Func<CharacterBody, bool>>((Func<CharacterBody, bool>)((CharacterBody body) => (body.bodyFlags & 2) > 0)); hookFailed = false; } if (hookFailed) { Log.Error("Drone Upgrade Station BodyFlag hook failed!"); } }; bool hook2Failed = true; AssemblingDroneState.TransferItem += (Manipulator)delegate(ILContext il) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown ILCursor val = new ILCursor(il); if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1] { (Instruction x) => ILPatternMatchingExt.MatchLdfld(x, typeof(CharacterBody), "bodyFlags") })) { val.RemoveRange(3); val.EmitDelegate<Func<CharacterBody, bool>>((Func<CharacterBody, bool>)((CharacterBody body) => (body.bodyFlags & 2) > 0)); hook2Failed = false; } if (hook2Failed) { Log.Error("Drone Upgrade Station BodyFlag hook (2/2) failed!"); } }; } DroneCombinerCombining.StartDroneCombineSequence += new hook_StartDroneCombineSequence(HandleItemsWhenCombining); AssemblingDroneState.FixedUpdate += new hook_FixedUpdate(HandleSFXPart1); AssemblingDroneState.OnExit += new hook_OnExit(HandleSFXPart2); ExpansionRequirementComponent component = droneAssemblyStationPrefab.GetComponent<ExpansionRequirementComponent>(); if (!Object.op_Implicit((Object)(object)component)) { component = droneAssemblyStationPrefab.AddComponent<ExpansionRequirementComponent>(); component.requiredExpansion = dlc3; } matDroneAssemblyStation.color = new Color(0.5019608f, 1f, 0f); if (Configs.spawnOnComputationalExchange.Value) { Stage.onStageStartGlobal += OnStageStartGlobal; } ((ResourceAvailability)(ref ItemCatalog.availability)).CallWhenAvailable((Action)HandleBlacklist); ((ResourceAvailability)(ref SceneCatalog.availability)).CallWhenAvailable((Action)HandleStages); OtherStuff(); ((SpawnCard)iscDroneAssemblyStation).directorCreditCost = Configs.creditCost.Value; iscDroneAssemblyStation.maxSpawnsPerStage = Configs.maxSpawns.Value; } private void HandleItemsWhenCombining(orig_StartDroneCombineSequence orig, DroneCombinerCombining self) { //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007b: 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_00a6: Unknown result type (might be due to invalid IL or missing references) if (NetworkServer.active) { CharacterBody toUpgrade = self.toUpgrade; CharacterBody toDestroy = self.toDestroy; if (Object.op_Implicit((Object)(object)toUpgrade) && Object.op_Implicit((Object)(object)toUpgrade.inventory) && Object.op_Implicit((Object)(object)toDestroy) && Object.op_Implicit((Object)(object)toDestroy.inventory)) { ReadOnlySpan<ItemIndex> nonZeroIndicesSpan = ((ItemCollection)(ref toDestroy.inventory.permanentItemStacks)).GetNonZeroIndicesSpan(); ReadOnlySpan<ItemIndex> readOnlySpan = nonZeroIndicesSpan; for (int i = 0; i < readOnlySpan.Length; i++) { ItemIndex val = readOnlySpan[i]; int itemCountPermanent = toUpgrade.inventory.GetItemCountPermanent(val); int itemCountPermanent2 = toDestroy.inventory.GetItemCountPermanent(val); if (itemCountPermanent < itemCountPermanent2) { toUpgrade.inventory.GiveItemPermanent(val, itemCountPermanent2 - itemCountPermanent); } } } } orig.Invoke(self); } private void HandleSFXPart1(orig_FixedUpdate orig, AssemblingDroneState self) { bool flag = ((EntityState)self).fixedAge < 1.5f; orig.Invoke(self); if (flag && ((EntityState)self).fixedAge >= 1.5f && Object.op_Implicit((Object)(object)((EntityState)self).gameObject)) { Util.PlaySound("Play_GG_INTER_DroneAssembly_Working", ((EntityState)self).gameObject); } } private void HandleSFXPart2(orig_OnExit orig, AssemblingDroneState self) { if (Object.op_Implicit((Object)(object)((EntityState)self).gameObject)) { Util.PlaySound("Play_GG_INTER_DroneAssembly_DroneReady", ((EntityState)self).gameObject); } orig.Invoke(self); } private void OnStageStartGlobal(Stage stage) { //IL_0066: 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_0079: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)SceneInfo.instance) && !((Object)(object)SceneInfo.instance.sceneDef != (Object)(object)SceneCatalog.FindSceneDef("computationalexchange"))) { Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(-47.6f, 121f, -50f); Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(5f, 165f, 0f); GameObject val3 = Object.Instantiate<GameObject>(droneAssemblyStationPrefab, val, Quaternion.Euler(val2)); val3.transform.eulerAngles = val2; NetworkServer.Spawn(val3); } } private void OtherStuff() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: 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) PurchaseInteraction component = droneAssemblyStationPrefab.GetComponent<PurchaseInteraction>(); if (Object.op_Implicit((Object)(object)component)) { droneAssemblyStationPrefab.RemoveComponent<PurchaseInteraction>(); } PickupPickerPanel.SetPickupOptions += new hook_SetPickupOptions(PickupPickerPanel_SetPickupOptions); RectTransform component2 = pickerPanel.GetComponent<RectTransform>(); if (Object.op_Implicit((Object)(object)component2)) { ((Transform)component2).localScale = new Vector3(0.75f, 0.75f, 0.75f); component2.anchorMax = new Vector2(1.1f, 1f); } ((Behaviour)pickerPanel.GetComponent<TranslucentImage>()).enabled = false; PickupPickerPanel component3 = pickerPanel.GetComponent<PickupPickerPanel>(); if (Object.op_Implicit((Object)(object)component3)) { component3.maxColumnCount = 12; GridLayoutGroup gridlayoutGroup = component3.gridlayoutGroup; if (Object.op_Implicit((Object)(object)gridlayoutGroup)) { ((Transform)((Component)gridlayoutGroup).GetComponent<RectTransform>()).localScale = new Vector3(0.8f, 0.8f, 0.8f); } } } private void HandleStages() { AddToStages(Configs.sceneList.Value); } private void AddToStages(string sceneList) { //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: 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_0071: 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_008a: 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_00aa: Expected O, but got Unknown //IL_00aa: 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_00b3: Expected O, but got Unknown //IL_00b7: Unknown result type (might be due to invalid IL or missing references) sceneList = new string((from c in sceneList.ToCharArray() where !char.IsWhiteSpace(c) select c).ToArray()); string[] array = sceneList.Split(','); string[] array2 = array; foreach (string text in array2) { SceneDef val = SceneCatalog.FindSceneDef(text); if (Object.op_Implicit((Object)(object)val)) { DirectorCardHolder val2 = new DirectorCardHolder { Card = new DirectorCard { minimumStageCompletions = Configs.minStage.Value - 1, preventOverhead = false, selectionWeight = Configs.weight.Value, spawnCard = (SpawnCard)(object)iscDroneAssemblyStation }, InteractableCategory = (InteractableCategory)8 }; Helpers.AddNewInteractableToStage(val2, DirectorAPI.GetStageEnumFromSceneDef(val), text); Log.Message("Drone Upgrade Station added to " + val.baseSceneName + "."); } } } private void HandleBlacklist() { //IL_0012: 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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: 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) if (Configs.blacklistCannotCopy.Value) { Enumerator<ItemIndex> enumerator = ItemCatalog.GetItemsWithTag((ItemTag)13).GetEnumerator(); try { while (enumerator.MoveNext()) { ItemIndex current = enumerator.Current; ItemDef itemDef = ItemCatalog.GetItemDef(current); if (Object.op_Implicit((Object)(object)itemDef)) { AddToBlacklist(itemDef); } } } finally { ((IDisposable)enumerator).Dispose(); } } BlacklistExtraItems(Configs.blacklistExtraList.Value); } private void AddToBlacklist(ItemDef itemDef) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) ref PickupDefEntry[] pickupEntries = ref blacklist.pickupEntries; PickupDefEntry val = new PickupDefEntry { pickupDef = (Object)(object)itemDef }; ArrayUtils.ArrayAppend<PickupDefEntry>(ref pickupEntries, ref val); } private void BlacklistExtraItems(string itemList) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: 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: Invalid comparison between Unknown and I4 //IL_0064: Unknown result type (might be due to invalid IL or missing references) itemList = new string((from c in itemList.ToCharArray() where !char.IsWhiteSpace(c) select c).ToArray()); string[] array = itemList.Split(','); string[] array2 = array; foreach (string text in array2) { ItemIndex val = ItemCatalog.FindItemIndex(text); if ((int)val != -1) { ItemDef itemDef = ItemCatalog.GetItemDef(val); if (Object.op_Implicit((Object)(object)itemDef)) { AddToBlacklist(itemDef); } } } } private void PickupPickerPanel_SetPickupOptions(orig_SetPickupOptions orig, PickupPickerPanel self, Option[] options) { //IL_0065: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) if (!((Object)self).name.StartsWith("AssemblyStationPickerPanelv2")) { orig.Invoke(self, options); return; } Transform val = ((Component)self).transform.Find("MainPanel"); if (val != null) { Transform val2 = val.Find("Juice/BG"); if (val2 != null) { Color color = ((Graphic)((Component)val2).GetComponent<Image>()).color; ((Graphic)((Component)val2).GetComponent<Image>()).color = new Color(color.r, color.g, color.b, 0.5f); } } int num = options.Length; int num2 = 12; int num3 = Mathf.CeilToInt(Mathf.Sqrt((float)num) + 2f); GridLayoutGroup componentInChildren = ((Component)((Component)self).transform).GetComponentInChildren<GridLayoutGroup>(); if (Object.op_Implicit((Object)(object)componentInChildren)) { componentInChildren.constraint = (Constraint)1; componentInChildren.constraintCount = 12; self.maxColumnCount = componentInChildren.constraintCount; self.automaticButtonNavigation = true; } orig.Invoke(self, options); if (val != null) { RectTransform component = ((Component)val).GetComponent<RectTransform>(); float num4 = (float)Mathf.Min(num3, num2) * (component.sizeDelta.x / 8f); num3 = ((num3 <= num2) ? num3 : (num3 + 1 + num3 - num2)); float num5 = (float)num3 * (component.sizeDelta.x / 8f); num5 = Mathf.Max(num5, 340f); num4 = Mathf.Max(num4, 340f); component.sizeDelta = new Vector2(num5, num4); } } } public static class Utils { public static void RemoveComponent<T>(this GameObject go) where T : Component { T val = default(T); if (go.TryGetComponent<T>(ref val)) { Object.Destroy((Object)(object)val); } } }