Decompiled source of EnhancedLogistics v3.2.2
EnhancedLogistics.dll
Decompiled a month ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; 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.Configuration; using BepInEx.Logging; using EquinoxsModUtils; using EquinoxsModUtils.Additions; using HarmonyLib; using Microsoft.CodeAnalysis; using TechtonicaFramework.TechTree; 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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("EnhancedLogistics")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+cb1150d6c353b8829b73e848fc221a0754683ab0")] [assembly: AssemblyProduct("EnhancedLogistics")] [assembly: AssemblyTitle("EnhancedLogistics")] [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 EnhancedLogistics { [BepInPlugin("com.certifired.EnhancedLogistics", "EnhancedLogistics", "3.2.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class EnhancedLogisticsPlugin : BaseUnityPlugin { public struct SearchResult { public string name; public string category; public string description; public Sprite icon; public object reference; } private const string MyGUID = "com.certifired.EnhancedLogistics"; private const string PluginName = "EnhancedLogistics"; private const string VersionString = "3.2.2"; private static readonly Harmony Harmony = new Harmony("com.certifired.EnhancedLogistics"); public static ManualLogSource Log; public static EnhancedLogisticsPlugin Instance; public static DroneAssetLoader AssetLoader; public static ConfigEntry<KeyCode> SearchToggleKey; public static ConfigEntry<bool> EnableSearchUI; public static ConfigEntry<bool> SearchInventory; public static ConfigEntry<bool> SearchCrafting; public static ConfigEntry<bool> SearchTechTree; public static ConfigEntry<bool> SearchBuildMenu; public static ConfigEntry<bool> EnableStorageNetwork; public static ConfigEntry<int> MaxNetworkDistance; public static ConfigEntry<bool> AutoRouteItems; public static ConfigEntry<bool> ShowNetworkVisualization; public static ConfigEntry<bool> EnableBetterLogistics; public static ConfigEntry<float> InserterRangeMultiplier; public static ConfigEntry<float> InserterSpeedMultiplier; public static ConfigEntry<bool> SmartFiltering; public static ConfigEntry<int> DefaultFilterStackSize; public static ConfigEntry<bool> EnableDroneSystem; public static ConfigEntry<int> DroneCapacity; public static ConfigEntry<float> DroneSpeed; public static ConfigEntry<float> DroneRange; public static ConfigEntry<KeyCode> DroneMenuKey; public static ConfigEntry<float> DeliveryDroneSpeed; public static ConfigEntry<float> CombatDroneSpeed; public static ConfigEntry<float> CombatDroneDamage; public static ConfigEntry<float> CombatDroneFireRate; public static ConfigEntry<float> RepairDroneSpeed; public static ConfigEntry<float> RepairDroneRate; public static ConfigEntry<int> MaxDronesPerPort; public const string DronePortName = "Drone Port"; public const string CombatDronePortName = "Combat Drone Port"; public const string RepairDronePortName = "Repair Drone Port"; public const string DroneUnlockName = "Drone Technology"; public const string AdvancedDroneUnlockName = "Advanced Drone Systems"; public static Material CapturedMaterial; public static Shader CapturedShader; public static bool searchWindowOpen = false; public static string currentSearchQuery = ""; public static List<SearchResult> searchResults = new List<SearchResult>(); private Rect searchWindowRect; private Rect droneWindowRect; private bool windowsInitialized = false; private Vector2 searchScrollPos = Vector2.zero; private Vector2 droneScrollPos = Vector2.zero; private bool droneWindowOpen = false; private int searchCategory = 0; private string[] searchCategories = new string[5] { "All", "Items", "Recipes", "Tech", "Machines" }; private void Awake() { //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Expected O, but got Unknown //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Expected O, but got Unknown //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Expected O, but got Unknown //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Expected O, but got Unknown //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Expected O, but got Unknown //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_02f4: Expected O, but got Unknown //IL_0327: Unknown result type (might be due to invalid IL or missing references) //IL_0331: Expected O, but got Unknown //IL_0385: Unknown result type (might be due to invalid IL or missing references) //IL_038f: Expected O, but got Unknown //IL_03c2: Unknown result type (might be due to invalid IL or missing references) //IL_03cc: Expected O, but got Unknown //IL_03ff: Unknown result type (might be due to invalid IL or missing references) //IL_0409: Expected O, but got Unknown //IL_043c: Unknown result type (might be due to invalid IL or missing references) //IL_0446: Expected O, but got Unknown //IL_0479: Unknown result type (might be due to invalid IL or missing references) //IL_0483: Expected O, but got Unknown //IL_04b6: Unknown result type (might be due to invalid IL or missing references) //IL_04c0: Expected O, but got Unknown //IL_04e8: Unknown result type (might be due to invalid IL or missing references) //IL_04f2: Expected O, but got Unknown //IL_0565: Unknown result type (might be due to invalid IL or missing references) //IL_0574: Unknown result type (might be due to invalid IL or missing references) Instance = this; Log = ((BaseUnityPlugin)this).Logger; Log.LogInfo((object)"PluginName: EnhancedLogistics, VersionString: 3.2.2 is loading..."); SearchToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Search UI", "Toggle Key", (KeyCode)102, "Key to toggle the search UI (when not in text input)"); EnableSearchUI = ((BaseUnityPlugin)this).Config.Bind<bool>("Search UI", "Enable Search UI", true, "Enable the search functionality"); SearchInventory = ((BaseUnityPlugin)this).Config.Bind<bool>("Search UI", "Search Inventory", true, "Include inventory items in search"); SearchCrafting = ((BaseUnityPlugin)this).Config.Bind<bool>("Search UI", "Search Crafting", true, "Include crafting recipes in search"); SearchTechTree = ((BaseUnityPlugin)this).Config.Bind<bool>("Search UI", "Search Tech Tree", true, "Include tech tree unlocks in search"); SearchBuildMenu = ((BaseUnityPlugin)this).Config.Bind<bool>("Search UI", "Search Build Menu", true, "Include buildable machines in search"); EnableStorageNetwork = ((BaseUnityPlugin)this).Config.Bind<bool>("Storage Network", "Enable Storage Network", true, "Enable the storage network system"); MaxNetworkDistance = ((BaseUnityPlugin)this).Config.Bind<int>("Storage Network", "Max Network Distance", 100, new ConfigDescription("Maximum distance for storage network connections", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 500), Array.Empty<object>())); AutoRouteItems = ((BaseUnityPlugin)this).Config.Bind<bool>("Storage Network", "Auto Route Items", true, "Automatically route items between connected storage"); ShowNetworkVisualization = ((BaseUnityPlugin)this).Config.Bind<bool>("Storage Network", "Show Network Visualization", true, "Show visual connections between networked storage"); EnableBetterLogistics = ((BaseUnityPlugin)this).Config.Bind<bool>("Better Logistics", "Enable Better Logistics", true, "Enable enhanced logistics features"); InserterRangeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Better Logistics", "Inserter Range Multiplier", 1.5f, new ConfigDescription("Multiplier for inserter reach range", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 3f), Array.Empty<object>())); InserterSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Better Logistics", "Inserter Speed Multiplier", 1.5f, new ConfigDescription("Multiplier for inserter operation speed", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 3f), Array.Empty<object>())); SmartFiltering = ((BaseUnityPlugin)this).Config.Bind<bool>("Better Logistics", "Smart Filtering", true, "Enable smart item filtering for inserters"); DefaultFilterStackSize = ((BaseUnityPlugin)this).Config.Bind<int>("Better Logistics", "Default Filter Stack Size", 1, new ConfigDescription("Default stack size for filtered items", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>())); EnableDroneSystem = ((BaseUnityPlugin)this).Config.Bind<bool>("Drone System", "Enable Drone System", true, "Enable the drone delivery system"); DroneCapacity = ((BaseUnityPlugin)this).Config.Bind<int>("Drone System", "Drone Capacity", 32, new ConfigDescription("Number of items a drone can carry", (AcceptableValueBase)(object)new AcceptableValueRange<int>(8, 128), Array.Empty<object>())); DroneSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Drone System", "Drone Speed", 10f, new ConfigDescription("Drone movement speed (units/second)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 50f), Array.Empty<object>())); DroneRange = ((BaseUnityPlugin)this).Config.Bind<float>("Drone System", "Drone Range", 200f, new ConfigDescription("Maximum drone delivery range", (AcceptableValueBase)(object)new AcceptableValueRange<float>(50f, 500f), Array.Empty<object>())); DroneMenuKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Drone System", "Drone Menu Key", (KeyCode)106, "Key to open drone management menu"); DeliveryDroneSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Drone Types", "Delivery Drone Speed", 12f, new ConfigDescription("Movement speed for delivery drones", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 30f), Array.Empty<object>())); CombatDroneSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Drone Types", "Combat Drone Speed", 15f, new ConfigDescription("Movement speed for combat drones", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 40f), Array.Empty<object>())); CombatDroneDamage = ((BaseUnityPlugin)this).Config.Bind<float>("Drone Types", "Combat Drone Damage", 15f, new ConfigDescription("Damage per shot for combat drones", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 100f), Array.Empty<object>())); CombatDroneFireRate = ((BaseUnityPlugin)this).Config.Bind<float>("Drone Types", "Combat Drone Fire Rate", 2f, new ConfigDescription("Shots per second for combat drones", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 10f), Array.Empty<object>())); RepairDroneSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Drone Types", "Repair Drone Speed", 8f, new ConfigDescription("Movement speed for repair drones", (AcceptableValueBase)(object)new AcceptableValueRange<float>(3f, 20f), Array.Empty<object>())); RepairDroneRate = ((BaseUnityPlugin)this).Config.Bind<float>("Drone Types", "Repair Drone Rate", 10f, new ConfigDescription("Health restored per second by repair drones", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 50f), Array.Empty<object>())); MaxDronesPerPort = ((BaseUnityPlugin)this).Config.Bind<int>("Drone Types", "Max Drones Per Port", 3, new ConfigDescription("Maximum drones each port can deploy", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>())); Harmony.PatchAll(); LoadDroneAssetBundles(); RegisterDroneContent(); Events.GameDefinesLoaded += OnGameDefinesLoaded; Events.TechTreeStateLoaded += OnTechTreeStateLoaded; Events.GameLoaded += OnGameLoaded; Log.LogInfo((object)"PluginName: EnhancedLogistics, VersionString: 3.2.2 is loaded."); Log.LogInfo((object)$"Press Ctrl+{SearchToggleKey.Value} for Search, {DroneMenuKey.Value} for Drone Menu"); } private void LoadDroneAssetBundles() { string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); AssetLoader = new DroneAssetLoader(directoryName); string text = Path.Combine(directoryName, "Bundles"); if (!Directory.Exists(text)) { Log.LogInfo((object)("Bundles directory not found at " + text + " - drones will use primitive visuals")); return; } string[] array = new string[3] { "drones_voodooplay", "drones_scifi", "drones_simple" }; string[] array2 = array; foreach (string text2 in array2) { if (AssetLoader.LoadBundle(text2)) { Log.LogInfo((object)("Loaded drone asset bundle: " + text2)); } } } private void RegisterDroneContent() { //IL_0017: 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_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_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_0064: 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_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0076: 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_0086: 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_009c: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Expected O, but got Unknown //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: 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_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_010d: 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_0129: Expected O, but got Unknown //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013c: 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_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Expected O, but got Unknown //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0213: 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_021a: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_022c: 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) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Expected O, but got Unknown //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_029e: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: Unknown result type (might be due to invalid IL or missing references) //IL_02e6: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Unknown result type (might be due to invalid IL or missing references) //IL_0314: Expected O, but got Unknown //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_032f: Unknown result type (might be due to invalid IL or missing references) //IL_033a: Unknown result type (might be due to invalid IL or missing references) //IL_0345: Unknown result type (might be due to invalid IL or missing references) //IL_0347: Unknown result type (might be due to invalid IL or missing references) //IL_034c: Unknown result type (might be due to invalid IL or missing references) //IL_0353: Unknown result type (might be due to invalid IL or missing references) //IL_035e: Unknown result type (might be due to invalid IL or missing references) //IL_0366: Unknown result type (might be due to invalid IL or missing references) //IL_0371: Unknown result type (might be due to invalid IL or missing references) //IL_037c: Unknown result type (might be due to invalid IL or missing references) //IL_038d: Expected O, but got Unknown //IL_038e: Unknown result type (might be due to invalid IL or missing references) //IL_0393: Unknown result type (might be due to invalid IL or missing references) //IL_039e: Unknown result type (might be due to invalid IL or missing references) //IL_03a0: Unknown result type (might be due to invalid IL or missing references) //IL_03a5: Unknown result type (might be due to invalid IL or missing references) //IL_03ac: Unknown result type (might be due to invalid IL or missing references) //IL_03b7: Unknown result type (might be due to invalid IL or missing references) //IL_03c2: Unknown result type (might be due to invalid IL or missing references) //IL_03d0: Unknown result type (might be due to invalid IL or missing references) //IL_03e3: Unknown result type (might be due to invalid IL or missing references) //IL_03f5: Unknown result type (might be due to invalid IL or missing references) //IL_0408: Unknown result type (might be due to invalid IL or missing references) //IL_0418: Unknown result type (might be due to invalid IL or missing references) //IL_0425: Unknown result type (might be due to invalid IL or missing references) //IL_0435: Unknown result type (might be due to invalid IL or missing references) //IL_0446: Expected O, but got Unknown if (EnableDroneSystem.Value) { EMUAdditions.AddNewUnlock(new NewUnlockDetails { category = ModdedTabModule.ModdedCategory, coreTypeNeeded = (CoreType)3, coreCountNeeded = 150, description = "Unlock autonomous drone technology. Drones can deliver items between storage, patrol for threats, and assist with repairs.", displayName = "Drone Technology", requiredTier = (ResearchTier)1, treePosition = 0 }, false); EMUAdditions.AddNewUnlock(new NewUnlockDetails { category = ModdedTabModule.ModdedCategory, coreTypeNeeded = (CoreType)1, coreCountNeeded = 200, description = "Advanced drone AI and combat capabilities. Enables combat and repair drone ports.", displayName = "Advanced Drone Systems", requiredTier = (ResearchTier)1, treePosition = 0 }, false); PowerGeneratorDefinition val = ScriptableObject.CreateInstance<PowerGeneratorDefinition>(); val.usesFuel = false; val.isCrankDriven = false; EMUAdditions.AddNewMachine<PowerGeneratorInstance, PowerGeneratorDefinition>((MachineDefinition<PowerGeneratorInstance, PowerGeneratorDefinition>)(object)val, new NewResourceDetails { name = "Drone Port", description = "Deploys delivery drones that automatically transport items between connected storage. Requires power (30kW).", craftingMethod = (CraftingMethod)0, craftTierRequired = 0, headerTitle = "Modded", maxStackCount = 10, sortPriority = 300, unlockName = "Drone Technology", parentName = "Crank Generator" }, false); EMUAdditions.AddNewRecipe(new NewRecipeDetails { GUID = "com.certifired.EnhancedLogistics_droneport", craftingMethod = (CraftingMethod)0, craftTierRequired = 0, duration = 30f, unlockName = "Drone Technology", ingredients = new List<RecipeResourceInfo> { new RecipeResourceInfo("Steel Frame", 15), new RecipeResourceInfo("Copper Wire", 25), new RecipeResourceInfo("Processor Unit", 5), new RecipeResourceInfo("Iron Components", 20) }, outputs = new List<RecipeResourceInfo> { new RecipeResourceInfo("Drone Port", 1) }, sortPriority = 300 }, false); PowerGeneratorDefinition val2 = ScriptableObject.CreateInstance<PowerGeneratorDefinition>(); val2.usesFuel = false; val2.isCrankDriven = false; EMUAdditions.AddNewMachine<PowerGeneratorInstance, PowerGeneratorDefinition>((MachineDefinition<PowerGeneratorInstance, PowerGeneratorDefinition>)(object)val2, new NewResourceDetails { name = "Combat Drone Port", description = "Deploys combat drones that patrol and engage hostile targets. Requires power (60kW). Best paired with TurretDefense mod.", craftingMethod = (CraftingMethod)0, craftTierRequired = 0, headerTitle = "Modded", maxStackCount = 10, sortPriority = 301, unlockName = "Advanced Drone Systems", parentName = "Crank Generator" }, false); EMUAdditions.AddNewRecipe(new NewRecipeDetails { GUID = "com.certifired.EnhancedLogistics_combatdroneport", craftingMethod = (CraftingMethod)0, craftTierRequired = 0, duration = 45f, unlockName = "Advanced Drone Systems", ingredients = new List<RecipeResourceInfo> { new RecipeResourceInfo("Steel Frame", 20), new RecipeResourceInfo("Copper Wire", 40), new RecipeResourceInfo("Processor Unit", 8), new RecipeResourceInfo("Iron Components", 30) }, outputs = new List<RecipeResourceInfo> { new RecipeResourceInfo("Combat Drone Port", 1) }, sortPriority = 301 }, false); PowerGeneratorDefinition val3 = ScriptableObject.CreateInstance<PowerGeneratorDefinition>(); val3.usesFuel = false; val3.isCrankDriven = false; EMUAdditions.AddNewMachine<PowerGeneratorInstance, PowerGeneratorDefinition>((MachineDefinition<PowerGeneratorInstance, PowerGeneratorDefinition>)(object)val3, new NewResourceDetails { name = "Repair Drone Port", description = "Deploys repair drones that automatically fix damaged machines. Requires power (45kW). Best paired with SurvivalElements mod.", craftingMethod = (CraftingMethod)0, craftTierRequired = 0, headerTitle = "Modded", maxStackCount = 10, sortPriority = 302, unlockName = "Advanced Drone Systems", parentName = "Crank Generator" }, false); EMUAdditions.AddNewRecipe(new NewRecipeDetails { GUID = "com.certifired.EnhancedLogistics_repairdroneport", craftingMethod = (CraftingMethod)0, craftTierRequired = 0, duration = 45f, unlockName = "Advanced Drone Systems", ingredients = new List<RecipeResourceInfo> { new RecipeResourceInfo("Steel Frame", 15), new RecipeResourceInfo("Copper Wire", 30), new RecipeResourceInfo("Processor Unit", 6), new RecipeResourceInfo("Iron Components", 25) }, outputs = new List<RecipeResourceInfo> { new RecipeResourceInfo("Repair Drone Port", 1) }, sortPriority = 302 }, false); Log.LogInfo((object)"Drone ports registered!"); } } private void OnGameDefinesLoaded() { InitializeMaterials(); } private void OnTechTreeStateLoaded() { ConfigureUnlock("Drone Technology", (ResearchTier)256, 70); ConfigureUnlock("Advanced Drone Systems", (ResearchTier)8192, 70); Log.LogInfo((object)"Drone tech tree positions configured"); } private void ConfigureUnlock(string unlockName, ResearchTier tier, int position) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) try { Unlock unlockByName = Unlocks.GetUnlockByName(unlockName, false); if ((Object)(object)unlockByName == (Object)null) { Log.LogWarning((object)("Could not find unlock: " + unlockName)); return; } unlockByName.requiredTier = tier; unlockByName.treePosition = position; Sprite val = null; ResourceInfo resourceInfoByName = Resources.GetResourceInfoByName("Inserter", false); if ((Object)(object)((resourceInfoByName != null) ? resourceInfoByName.sprite : null) != (Object)null) { val = resourceInfoByName.sprite; } if ((Object)(object)val == (Object)null) { ResourceInfo resourceInfoByName2 = Resources.GetResourceInfoByName("Filter Inserter", false); if ((Object)(object)((resourceInfoByName2 != null) ? resourceInfoByName2.sprite : null) != (Object)null) { val = resourceInfoByName2.sprite; } } if ((Object)(object)val != (Object)null) { unlockByName.sprite = val; } Log.LogInfo((object)string.Format("Configured {0}: tier={1}, pos={2}, sprite={3}", unlockName, tier, position, ((Object)(object)unlockByName.sprite != (Object)null) ? "SET" : "NULL")); } catch (Exception ex) { Log.LogWarning((object)("Failed to configure unlock " + unlockName + ": " + ex.Message)); } } private void OnGameLoaded() { DroneManager.Initialize(); Log.LogInfo((object)"Drone system initialized"); } private void InitializeMaterials() { //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Expected O, but got Unknown try { MeshRenderer[] array = Object.FindObjectsOfType<MeshRenderer>(); MeshRenderer[] array2 = array; foreach (MeshRenderer val in array2) { object obj; if (val == null) { obj = null; } else { Material sharedMaterial = ((Renderer)val).sharedMaterial; obj = ((sharedMaterial != null) ? sharedMaterial.shader : null); } if (!((Object)obj == (Object)null)) { Shader shader = ((Renderer)val).sharedMaterial.shader; if (!((Object)shader).name.Contains("Error") && !((Object)shader).name.Contains("Hidden") && (((Object)shader).name.Contains("Lit") || ((Object)shader).name.Contains("Standard") || ((Object)shader).name.Contains("URP"))) { CapturedShader = shader; CapturedMaterial = new Material(((Renderer)val).sharedMaterial); ((Object)CapturedMaterial).name = "EnhancedLogistics_Drone"; Log.LogInfo((object)("Captured shader: " + ((Object)shader).name)); break; } } } } catch (Exception ex) { Log.LogWarning((object)("Material init error: " + ex.Message)); } } public static Material GetDroneMaterial(Color color) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) Material val = (((Object)(object)CapturedMaterial != (Object)null) ? new Material(CapturedMaterial) : ((!((Object)(object)CapturedShader != (Object)null)) ? new Material(Shader.Find("Standard") ?? Shader.Find("Diffuse")) : new Material(CapturedShader))); if (val.HasProperty("_BaseColor")) { val.SetColor("_BaseColor", color); } if (val.HasProperty("_Color")) { val.SetColor("_Color", color); } val.color = color; return val; } private void Update() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) if (EnableSearchUI.Value && Input.GetKey((KeyCode)306) && Input.GetKeyDown(SearchToggleKey.Value)) { searchWindowOpen = !searchWindowOpen; if (searchWindowOpen) { currentSearchQuery = ""; searchResults.Clear(); } } if (EnableDroneSystem.Value && Input.GetKeyDown(DroneMenuKey.Value)) { droneWindowOpen = !droneWindowOpen; } if (searchWindowOpen && Input.GetKeyDown((KeyCode)27)) { searchWindowOpen = false; } if (EnableDroneSystem.Value) { DroneManager.Update(); } } private void OnGUI() { //IL_0073: 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_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Expected O, but got Unknown //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Expected O, but got Unknown //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) if (!windowsInitialized || ((Rect)(ref searchWindowRect)).width == 0f) { float num = Mathf.Min(400f, (float)Screen.width * 0.4f); float num2 = Mathf.Min(500f, (float)Screen.height * 0.6f); searchWindowRect = new Rect(((float)Screen.width - num) / 2f, ((float)Screen.height - num2) / 2f, num, num2); float num3 = Mathf.Min(350f, (float)Screen.width * 0.25f); float num4 = Mathf.Min(400f, (float)Screen.height * 0.5f); droneWindowRect = new Rect((float)Screen.width * 0.01f, (float)Screen.height * 0.08f, num3, num4); windowsInitialized = true; } if (searchWindowOpen && EnableSearchUI.Value) { searchWindowRect = GUILayout.Window(88888, searchWindowRect, new WindowFunction(DrawSearchWindow), "Search (Ctrl+F to close)", Array.Empty<GUILayoutOption>()); ((Rect)(ref searchWindowRect)).x = Mathf.Clamp(((Rect)(ref searchWindowRect)).x, 0f, (float)Screen.width - ((Rect)(ref searchWindowRect)).width); ((Rect)(ref searchWindowRect)).y = Mathf.Clamp(((Rect)(ref searchWindowRect)).y, 0f, (float)Screen.height - ((Rect)(ref searchWindowRect)).height); } if (droneWindowOpen && EnableDroneSystem.Value) { droneWindowRect = GUILayout.Window(88889, droneWindowRect, new WindowFunction(DrawDroneWindow), "Drone Management", Array.Empty<GUILayoutOption>()); ((Rect)(ref droneWindowRect)).x = Mathf.Clamp(((Rect)(ref droneWindowRect)).x, 0f, (float)Screen.width - ((Rect)(ref droneWindowRect)).width); ((Rect)(ref droneWindowRect)).y = Mathf.Clamp(((Rect)(ref droneWindowRect)).y, 0f, (float)Screen.height - ((Rect)(ref droneWindowRect)).height); } } private void DrawSearchWindow(int id) { //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Invalid comparison between Unknown and I4 //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_018f: 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_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Expected O, but got Unknown //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Expected O, but got Unknown //IL_030b: Unknown result type (might be due to invalid IL or missing references) GUILayout.BeginVertical(Array.Empty<GUILayoutOption>()); GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); GUILayout.Label("Search:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }); GUI.SetNextControlName("SearchField"); string text = GUILayout.TextField(currentSearchQuery, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }); if (text != currentSearchQuery) { currentSearchQuery = text; PerformSearch(); } GUILayout.EndHorizontal(); if ((int)Event.current.type == 7 && GUI.GetNameOfFocusedControl() != "SearchField") { GUI.FocusControl("SearchField"); } GUILayout.Space(5f); GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); for (int i = 0; i < searchCategories.Length; i++) { GUI.color = ((searchCategory == i) ? Color.cyan : Color.white); if (GUILayout.Button(searchCategories[i], (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(25f) })) { searchCategory = i; PerformSearch(); } } GUI.color = Color.white; GUILayout.EndHorizontal(); GUILayout.Space(5f); GUILayout.Label($"Results: {searchResults.Count}", Array.Empty<GUILayoutOption>()); searchScrollPos = GUILayout.BeginScrollView(searchScrollPos, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(350f) }); foreach (SearchResult searchResult in searchResults) { GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>()); GUILayout.Box("", (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width(32f), GUILayout.Height(32f) }); GUILayout.BeginVertical(Array.Empty<GUILayoutOption>()); GUILayout.Label(searchResult.name, new GUIStyle(GUI.skin.label) { fontStyle = (FontStyle)1 }, Array.Empty<GUILayoutOption>()); GUILayout.Label("[" + searchResult.category + "] " + searchResult.description, new GUIStyle(GUI.skin.label) { fontSize = 10 }, Array.Empty<GUILayoutOption>()); GUILayout.EndVertical(); GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.Space(5f); GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); GUILayout.Label("Tip: Type to search items, recipes, tech, and machines", Array.Empty<GUILayoutOption>()); GUILayout.FlexibleSpace(); if (GUILayout.Button("Close", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) })) { searchWindowOpen = false; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUI.DragWindow(new Rect(0f, 0f, 10000f, 30f)); } private void PerformSearch() { searchResults.Clear(); if (!string.IsNullOrEmpty(currentSearchQuery) && currentSearchQuery.Length >= 2) { string query = currentSearchQuery.ToLower(); if (searchCategory == 0 || searchCategory == 1) { SearchResources(query); } if (searchCategory == 0 || searchCategory == 2) { SearchRecipes(query); } if (searchCategory == 0 || searchCategory == 3) { SearchTech(query); } if (searchCategory == 0 || searchCategory == 4) { SearchMachines(query); } searchResults = (from r in searchResults orderby r.name.ToLower().StartsWith(query) descending, r.name select r).Take(50).ToList(); } } private void SearchResources(string query) { if ((Object)(object)GameDefines.instance == (Object)null) { return; } try { foreach (ResourceInfo resource in GameDefines.instance.resources) { if (!((Object)(object)resource == (Object)null)) { string text = resource.displayName ?? ((Object)resource).name ?? ""; string text2 = resource.description ?? ""; if (text.ToLower().Contains(query) || text2.ToLower().Contains(query)) { searchResults.Add(new SearchResult { name = text, category = "Item", description = TruncateString(text2, 60), icon = resource.sprite, reference = resource }); } } } } catch (Exception ex) { Log.LogWarning((object)("Search resources error: " + ex.Message)); } } private void SearchRecipes(string query) { if ((Object)(object)GameDefines.instance == (Object)null) { return; } try { foreach (ResourceInfo resource in GameDefines.instance.resources) { if (!((Object)(object)resource == (Object)null)) { string text = resource.displayName ?? ((Object)resource).name ?? ""; if (text.ToLower().Contains(query)) { string text2 = ((object)(CraftingMethod)(ref resource.craftingMethod)).ToString(); searchResults.Add(new SearchResult { name = "Craft: " + text, category = "Recipe", description = TruncateString("Method: " + text2, 60), icon = resource.sprite, reference = resource }); } } } } catch (Exception ex) { Log.LogWarning((object)("Search recipes error: " + ex.Message)); } } private void SearchTech(string query) { if ((Object)(object)GameDefines.instance == (Object)null) { return; } try { foreach (Unlock unlock in GameDefines.instance.unlocks) { if ((Object)(object)unlock == (Object)null) { continue; } string text = unlock.displayName ?? ((Object)unlock).name ?? ""; string text2 = unlock.description ?? ""; if (text.ToLower().Contains(query) || text2.ToLower().Contains(query)) { bool flag = false; if (TechTreeState.instance != null) { flag = TechTreeState.instance.IsUnlockActive(((UniqueIdScriptableObject)unlock).uniqueId); } searchResults.Add(new SearchResult { name = text + (flag ? " [UNLOCKED]" : ""), category = "Tech", description = TruncateString(text2, 60), icon = unlock.sprite, reference = unlock }); } } } catch (Exception ex) { Log.LogWarning((object)("Search tech error: " + ex.Message)); } } private void SearchMachines(string query) { if ((Object)(object)GameDefines.instance == (Object)null) { return; } try { foreach (ResourceInfo resource in GameDefines.instance.resources) { if ((Object)(object)resource == (Object)null) { continue; } BuilderInfo val = (BuilderInfo)(object)((resource is BuilderInfo) ? resource : null); if (val != null) { string text = resource.displayName ?? ((Object)resource).name ?? ""; string text2 = resource.description ?? ""; if (text.ToLower().Contains(query) || text2.ToLower().Contains(query)) { searchResults.Add(new SearchResult { name = text, category = "Machine", description = TruncateString(text2, 60), icon = resource.sprite, reference = resource }); } } } } catch (Exception ex) { Log.LogWarning((object)("Search machines error: " + ex.Message)); } } private string TruncateString(string str, int maxLength) { if (string.IsNullOrEmpty(str)) { return ""; } if (str.Length <= maxLength) { return str; } return str.Substring(0, maxLength - 3) + "..."; } private void DrawDroneWindow(int id) { //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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_0157: 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_0174: 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_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Expected O, but got Unknown //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_02f6: Unknown result type (might be due to invalid IL or missing references) //IL_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_030a: Unknown result type (might be due to invalid IL or missing references) //IL_034b: Unknown result type (might be due to invalid IL or missing references) //IL_0350: Unknown result type (might be due to invalid IL or missing references) //IL_035a: Unknown result type (might be due to invalid IL or missing references) //IL_035f: Unknown result type (might be due to invalid IL or missing references) //IL_03a0: Unknown result type (might be due to invalid IL or missing references) //IL_03a5: Unknown result type (might be due to invalid IL or missing references) //IL_03af: Unknown result type (might be due to invalid IL or missing references) //IL_03b4: Unknown result type (might be due to invalid IL or missing references) //IL_0423: Unknown result type (might be due to invalid IL or missing references) GUILayout.BeginVertical(Array.Empty<GUILayoutOption>()); GUILayout.Label("Drone System v3.0", new GUIStyle(GUI.skin.label) { fontStyle = (FontStyle)1, fontSize = 14 }, Array.Empty<GUILayoutOption>()); GUILayout.Space(10f); GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>()); GUILayout.Label($"Active Drones: {DroneManager.AllDrones.Count}", Array.Empty<GUILayoutOption>()); GUILayout.Label($" - Delivery: {DroneManager.DeliveryDrones.Count}", Array.Empty<GUILayoutOption>()); GUILayout.Label($" - Combat: {DroneManager.CombatDrones.Count}", Array.Empty<GUILayoutOption>()); GUILayout.Label($" - Repair: {DroneManager.RepairDrones.Count}", Array.Empty<GUILayoutOption>()); GUILayout.Label($"Drone Ports: {DroneManager.DronePorts.Count}", Array.Empty<GUILayoutOption>()); GUILayout.Label($"Pending Deliveries: {DroneManager.PendingDeliveries.Count}", Array.Empty<GUILayoutOption>()); GUILayout.EndVertical(); GUILayout.Space(10f); GUILayout.Label("Active Drones:", Array.Empty<GUILayoutOption>()); droneScrollPos = GUILayout.BeginScrollView(droneScrollPos, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(150f) }); foreach (DroneController allDrone in DroneManager.AllDrones) { if (allDrone != null) { GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>()); Color textColor = ((allDrone.Type == DroneType.Combat) ? Color.red : ((allDrone.Type == DroneType.Repair) ? Color.green : Color.cyan)); GUIStyle val = new GUIStyle(GUI.skin.label); val.normal.textColor = textColor; GUIStyle val2 = val; GUILayout.Label($"#{allDrone.Id} [{allDrone.Type}]", val2, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(120f) }); GUILayout.Label(allDrone.State.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) }); GUILayout.EndHorizontal(); } } if (DroneManager.AllDrones.Count == 0) { GUILayout.Label("No active drones. Build Drone Ports to deploy drones!", Array.Empty<GUILayoutOption>()); } GUILayout.EndScrollView(); GUILayout.Space(10f); GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); if (GUILayout.Button("Test Delivery", Array.Empty<GUILayoutOption>()) && (Object)(object)Player.instance != (Object)null) { DroneManager.SpawnDrone(DroneType.Delivery, ((Component)Player.instance).transform.position + Vector3.up * 3f, null); } if (GUILayout.Button("Test Combat", Array.Empty<GUILayoutOption>()) && (Object)(object)Player.instance != (Object)null) { DroneManager.SpawnDrone(DroneType.Combat, ((Component)Player.instance).transform.position + Vector3.up * 3f, null); } if (GUILayout.Button("Test Repair", Array.Empty<GUILayoutOption>()) && (Object)(object)Player.instance != (Object)null) { DroneManager.SpawnDrone(DroneType.Repair, ((Component)Player.instance).transform.position + Vector3.up * 3f, null); } GUILayout.EndHorizontal(); if (GUILayout.Button("Clear All Drones", Array.Empty<GUILayoutOption>())) { DroneManager.ClearAllDrones(); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Close", Array.Empty<GUILayoutOption>())) { droneWindowOpen = false; } GUILayout.EndVertical(); GUI.DragWindow(new Rect(0f, 0f, 10000f, 30f)); } } public static class StorageNetwork { public static Dictionary<string, List<uint>> networkChannels = new Dictionary<string, List<uint>>(); public static Dictionary<uint, string> chestToNetwork = new Dictionary<uint, string>(); public static void RegisterChest(uint chestId, string networkId) { if (!networkChannels.ContainsKey(networkId)) { networkChannels[networkId] = new List<uint>(); } if (!networkChannels[networkId].Contains(chestId)) { networkChannels[networkId].Add(chestId); } chestToNetwork[chestId] = networkId; } public static void UnregisterChest(uint chestId) { if (!chestToNetwork.TryGetValue(chestId, out var value)) { return; } if (networkChannels.ContainsKey(value)) { networkChannels[value].Remove(chestId); if (networkChannels[value].Count == 0) { networkChannels.Remove(value); } } chestToNetwork.Remove(chestId); } public static List<uint> GetNetworkChests(string networkId) { if (networkChannels.TryGetValue(networkId, out var value)) { return value; } return new List<uint>(); } public static bool TryRouteItem(string networkId, int resourceId, int count, out uint targetChestId) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: 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_004e: 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_006f: Unknown result type (might be due to invalid IL or missing references) targetChestId = 0u; if (!EnhancedLogisticsPlugin.AutoRouteItems.Value) { return false; } List<uint> networkChests = GetNetworkChests(networkId); foreach (uint item in networkChests) { try { ChestInstance val = MachineManager.instance.Get<ChestInstance, ChestDefinition>((int)item, (MachineTypeEnum)3); if (val.commonInfo.instanceId != 0) { Inventory inventory = ((ChestInstance)(ref val)).GetInventory(); if (((Inventory)(ref inventory)).CanAddResources(resourceId, count, (List<NetworkInventorySlot>)null)) { targetChestId = item; return true; } } } catch { } } return false; } } public enum DroneType { Delivery, Combat, Repair } public enum DroneState { Idle, MovingToTarget, Working, Returning } public static class DroneManager { public static List<DroneController> AllDrones = new List<DroneController>(); public static List<DeliveryDrone> DeliveryDrones = new List<DeliveryDrone>(); public static List<CombatDrone> CombatDrones = new List<CombatDrone>(); public static List<RepairDrone> RepairDrones = new List<RepairDrone>(); public static List<DronePort> DronePorts = new List<DronePort>(); public static Queue<DeliveryTask> PendingDeliveries = new Queue<DeliveryTask>(); private static int nextDroneId = 1; private static bool initialized = false; public static void Initialize() { if (!initialized) { initialized = true; EnhancedLogisticsPlugin.Log.LogInfo((object)"DroneManager initialized"); } } public static void Update() { if (!initialized) { return; } foreach (DronePort item in DronePorts.ToList()) { if (item == null) { DronePorts.Remove(item); } else { item.UpdatePort(); } } foreach (DroneController item2 in AllDrones.ToList()) { if (item2 == null || (Object)(object)item2.gameObject == (Object)null) { AllDrones.Remove(item2); } else { item2.UpdateDrone(); } } DeliveryDrones.RemoveAll((DeliveryDrone d) => d == null || (Object)(object)d.gameObject == (Object)null); CombatDrones.RemoveAll((CombatDrone d) => d == null || (Object)(object)d.gameObject == (Object)null); RepairDrones.RemoveAll((RepairDrone d) => d == null || (Object)(object)d.gameObject == (Object)null); while (PendingDeliveries.Count > 0) { DeliveryDrone deliveryDrone = DeliveryDrones.FirstOrDefault((DeliveryDrone d) => d.State == DroneState.Idle); if (deliveryDrone == null) { break; } DeliveryTask task = PendingDeliveries.Dequeue(); deliveryDrone.AssignDeliveryTask(task); } } public static int GetNextId() { return nextDroneId++; } public static DroneController SpawnDrone(DroneType type, Vector3 position, DronePort ownerPort) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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) DroneController droneController = null; switch (type) { case DroneType.Delivery: { DeliveryDrone deliveryDrone = new DeliveryDrone(position, ownerPort); DeliveryDrones.Add(deliveryDrone); droneController = deliveryDrone; break; } case DroneType.Combat: { CombatDrone combatDrone = new CombatDrone(position, ownerPort); CombatDrones.Add(combatDrone); droneController = combatDrone; break; } case DroneType.Repair: { RepairDrone repairDrone = new RepairDrone(position, ownerPort); RepairDrones.Add(repairDrone); droneController = repairDrone; break; } } if (droneController != null) { AllDrones.Add(droneController); EnhancedLogisticsPlugin.Log.LogInfo((object)$"Spawned {type} drone #{droneController.Id} at {position}"); } return droneController; } public static void RegisterPort(DronePort port) { if (!DronePorts.Contains(port)) { DronePorts.Add(port); EnhancedLogisticsPlugin.Log.LogInfo((object)$"Registered {port.PortType} port"); } } public static void UnregisterPort(DronePort port) { DronePorts.Remove(port); foreach (DroneController item in AllDrones.Where((DroneController d) => d.HomePort == port).ToList()) { item.Destroy(); } } public static void QueueDelivery(uint sourceChestId, uint targetChestId, int resourceId, int count) { PendingDeliveries.Enqueue(new DeliveryTask { sourceChestId = sourceChestId, targetChestId = targetChestId, resourceId = resourceId, count = count }); } public static void ClearAllDrones() { foreach (DroneController item in AllDrones.ToList()) { item?.Destroy(); } AllDrones.Clear(); DeliveryDrones.Clear(); CombatDrones.Clear(); RepairDrones.Clear(); PendingDeliveries.Clear(); } public static List<Transform> GetActiveAliens() { List<Transform> list = new List<Transform>(); try { Type type = Type.GetType("TurretDefense.TurretDefensePlugin, TurretDefense"); if (type != null) { FieldInfo field = type.GetField("ActiveAliens", BindingFlags.Static | BindingFlags.Public); if (field != null && field.GetValue(null) is IList list2) { foreach (object item in list2) { Type type2 = item.GetType(); PropertyInfo property = type2.GetProperty("IsAlive"); MonoBehaviour val = (MonoBehaviour)((item is MonoBehaviour) ? item : null); if (val != null && (Object)(object)val != (Object)null) { bool flag = true; if (property != null) { flag = (bool)property.GetValue(item); } if (flag && (Object)(object)((Component)val).transform != (Object)null) { list.Add(((Component)val).transform); } } } } } } catch (Exception ex) { EnhancedLogisticsPlugin.Log.LogDebug((object)("Could not access TurretDefense aliens: " + ex.Message)); } return list; } } public class DeliveryTask { public uint sourceChestId; public uint targetChestId; public int resourceId; public int count; } public class DronePort { public DroneType PortType; public Vector3 Position; public uint MachineInstanceId; public List<DroneController> OwnedDrones = new List<DroneController>(); public float SpawnCooldown = 0f; public bool HasPower = true; public int MaxDrones => EnhancedLogisticsPlugin.MaxDronesPerPort.Value; public DronePort(DroneType type, Vector3 position, uint instanceId) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) PortType = type; Position = position; MachineInstanceId = instanceId; DroneManager.RegisterPort(this); } public void UpdatePort() { SpawnCooldown -= Time.deltaTime; if (SpawnCooldown <= 0f && HasPower && OwnedDrones.Count < MaxDrones) { SpawnDrone(); SpawnCooldown = 5f; } OwnedDrones.RemoveAll((DroneController d) => d == null || (Object)(object)d.gameObject == (Object)null); } public void SpawnDrone() { //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_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_001b: 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_002f: 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) Vector3 position = Position + Vector3.up * 3f + Random.insideUnitSphere * 0.5f; DroneController droneController = DroneManager.SpawnDrone(PortType, position, this); if (droneController != null) { OwnedDrones.Add(droneController); } } public void Destroy() { DroneManager.UnregisterPort(this); } } public abstract class DroneController { public int Id; public DroneType Type; public DroneState State = DroneState.Idle; public GameObject gameObject; public Vector3 Position; public Vector3 TargetPosition; public DronePort HomePort; public float StateTimer = 0f; protected GameObject bodyObj; protected GameObject[] propellers; protected float propellerSpeed = 1000f; protected float hoverHeight = 3f; protected float bobAmplitude = 0.15f; protected float bobSpeed = 2f; public abstract float Speed { get; } public abstract Color DroneColor { get; } public abstract void UpdateBehavior(); protected DroneController(DroneType type, Vector3 position, DronePort owner) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) Id = DroneManager.GetNextId(); Type = type; Position = position; HomePort = owner; CreateVisual(); } protected virtual void CreateVisual() { //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Expected O, but got Unknown //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: 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_0082: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown //IL_00c4: 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_0220: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_0308: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_032e: Unknown result type (might be due to invalid IL or missing references) //IL_04e3: Unknown result type (might be due to invalid IL or missing references) //IL_04ed: Unknown result type (might be due to invalid IL or missing references) //IL_04fe: Unknown result type (might be due to invalid IL or missing references) //IL_0508: Unknown result type (might be due to invalid IL or missing references) //IL_03ee: Unknown result type (might be due to invalid IL or missing references) //IL_03f0: Unknown result type (might be due to invalid IL or missing references) //IL_03fa: Unknown result type (might be due to invalid IL or missing references) //IL_03ff: Unknown result type (might be due to invalid IL or missing references) //IL_0427: Unknown result type (might be due to invalid IL or missing references) //IL_0381: Unknown result type (might be due to invalid IL or missing references) //IL_0549: Unknown result type (might be due to invalid IL or missing references) //IL_0553: Unknown result type (might be due to invalid IL or missing references) //IL_0558: Unknown result type (might be due to invalid IL or missing references) //IL_055a: Unknown result type (might be due to invalid IL or missing references) //IL_058a: Unknown result type (might be due to invalid IL or missing references) //IL_048d: Unknown result type (might be due to invalid IL or missing references) GameObject val = EnhancedLogisticsPlugin.AssetLoader?.GetDronePrefab(Type); if ((Object)(object)val != (Object)null) { gameObject = Object.Instantiate<GameObject>(val, Position, Quaternion.identity); ((Object)gameObject).name = $"Drone_{Type}_{Id}"; gameObject.transform.localScale = Vector3.one * 0.8f; propellers = (GameObject[])(object)new GameObject[0]; GameObject val2 = new GameObject("DroneLight"); val2.transform.SetParent(gameObject.transform); val2.transform.localPosition = Vector3.zero; Light val3 = val2.AddComponent<Light>(); val3.type = (LightType)2; val3.range = 3f; val3.intensity = 1f; val3.color = DroneColor; EnhancedLogisticsPlugin.Log.LogDebug((object)$"Created {Type} drone from prefab"); return; } gameObject = new GameObject($"Drone_{Type}_{Id}"); gameObject.transform.position = Position; bodyObj = GameObject.CreatePrimitive((PrimitiveType)0); ((Object)bodyObj).name = "Body"; bodyObj.transform.SetParent(gameObject.transform); bodyObj.transform.localPosition = Vector3.zero; bodyObj.transform.localScale = new Vector3(0.8f, 0.3f, 0.8f); Collider component = bodyObj.GetComponent<Collider>(); if ((Object)(object)component != (Object)null) { Object.Destroy((Object)(object)component); } Renderer component2 = bodyObj.GetComponent<Renderer>(); if ((Object)(object)component2 != (Object)null) { component2.material = EnhancedLogisticsPlugin.GetDroneMaterial(DroneColor); } propellers = (GameObject[])(object)new GameObject[4]; Vector3 val4 = default(Vector3); for (int i = 0; i < 4; i++) { float num = (float)i / 4f * (float)Math.PI * 2f + (float)Math.PI / 4f; ((Vector3)(ref val4))..ctor(Mathf.Cos(num) * 0.5f, 0.1f, Mathf.Sin(num) * 0.5f); GameObject val5 = GameObject.CreatePrimitive((PrimitiveType)2); ((Object)val5).name = $"Arm_{i}"; val5.transform.SetParent(gameObject.transform); val5.transform.localPosition = val4 * 0.5f; val5.transform.localRotation = Quaternion.Euler(0f, 0f, 90f) * Quaternion.Euler(0f, 57.29578f * num, 0f); val5.transform.localScale = new Vector3(0.05f, 0.3f, 0.05f); Collider component3 = val5.GetComponent<Collider>(); if ((Object)(object)component3 != (Object)null) { Object.Destroy((Object)(object)component3); } Renderer component4 = val5.GetComponent<Renderer>(); if ((Object)(object)component4 != (Object)null) { component4.material = EnhancedLogisticsPlugin.GetDroneMaterial(new Color(0.2f, 0.2f, 0.25f)); } propellers[i] = GameObject.CreatePrimitive((PrimitiveType)2); ((Object)propellers[i]).name = $"Propeller_{i}"; propellers[i].transform.SetParent(gameObject.transform); propellers[i].transform.localPosition = val4 + Vector3.up * 0.15f; propellers[i].transform.localScale = new Vector3(0.3f, 0.02f, 0.3f); Collider component5 = propellers[i].GetComponent<Collider>(); if ((Object)(object)component5 != (Object)null) { Object.Destroy((Object)(object)component5); } Renderer component6 = propellers[i].GetComponent<Renderer>(); if ((Object)(object)component6 != (Object)null) { component6.material = EnhancedLogisticsPlugin.GetDroneMaterial(new Color(0.15f, 0.15f, 0.2f, 0.7f)); } } GameObject val6 = GameObject.CreatePrimitive((PrimitiveType)0); ((Object)val6).name = "Indicator"; val6.transform.SetParent(gameObject.transform); val6.transform.localPosition = Vector3.down * 0.1f; val6.transform.localScale = Vector3.one * 0.15f; Collider component7 = val6.GetComponent<Collider>(); if ((Object)(object)component7 != (Object)null) { Object.Destroy((Object)(object)component7); } Renderer component8 = val6.GetComponent<Renderer>(); if ((Object)(object)component8 != (Object)null) { Color val7 = DroneColor * 2f; Material droneMaterial = EnhancedLogisticsPlugin.GetDroneMaterial(val7); if (droneMaterial.HasProperty("_EmissionColor")) { droneMaterial.EnableKeyword("_EMISSION"); droneMaterial.SetColor("_EmissionColor", val7); } component8.material = droneMaterial; } } public void UpdateDrone() { //IL_0044: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)gameObject == (Object)null) { return; } float deltaTime = Time.deltaTime; GameObject[] array = propellers; foreach (GameObject val in array) { if ((Object)(object)val != (Object)null) { val.transform.Rotate(Vector3.up, propellerSpeed * deltaTime); } } switch (State) { case DroneState.Idle: UpdateIdle(deltaTime); break; case DroneState.MovingToTarget: UpdateMoving(deltaTime); break; case DroneState.Working: UpdateWorking(deltaTime); break; case DroneState.Returning: UpdateReturning(deltaTime); break; } UpdateBehavior(); } protected virtual void UpdateIdle(float dt) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: 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_003e: 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) float num = Mathf.Sin(Time.time * bobSpeed + (float)Id) * bobAmplitude; gameObject.transform.position = Position + Vector3.up * num; gameObject.transform.Rotate(Vector3.up, Mathf.Sin(Time.time * 0.5f + (float)Id) * 5f * dt); } protected virtual void UpdateMoving(float dt) { //IL_0002: 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_0012: 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) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: 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_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: 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_00b1: 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_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011f: 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_012a: Unknown result type (might be due to invalid IL or missing references) Vector3 val = TargetPosition - Position; Vector3 normalized = ((Vector3)(ref val)).normalized; float num = Vector3.Distance(Position, TargetPosition); if (num < 1f) { Position = TargetPosition; OnArrivedAtTarget(); } else { Position += normalized * Speed * dt; if (((Vector3)(ref normalized)).sqrMagnitude > 0.001f) { Quaternion val2 = Quaternion.LookRotation(normalized, Vector3.up); gameObject.transform.rotation = Quaternion.Slerp(gameObject.transform.rotation, val2, dt * 5f); gameObject.transform.Rotate(Vector3.right, 10f); } } float num2 = Mathf.Sin(Time.time * bobSpeed + (float)Id) * bobAmplitude * 0.5f; gameObject.transform.position = Position + Vector3.up * num2; } protected virtual void UpdateWorking(float dt) { StateTimer -= dt; if (StateTimer <= 0f) { OnWorkComplete(); } } protected virtual void UpdateReturning(float dt) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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_0040: 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_004a: Unknown result type (might be due to invalid IL or missing references) //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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0090: 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_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: 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_0072: 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_00de: 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_00e9: Unknown result type (might be due to invalid IL or missing references) if (HomePort == null) { State = DroneState.Idle; return; } Vector3 val = HomePort.Position + Vector3.up * hoverHeight; Vector3 val2 = val - Position; Vector3 normalized = ((Vector3)(ref val2)).normalized; float num = Vector3.Distance(Position, val); if (num < 1.5f) { Position = val; State = DroneState.Idle; } else { Position += normalized * Speed * dt; } float num2 = Mathf.Sin(Time.time * bobSpeed + (float)Id) * bobAmplitude * 0.5f; gameObject.transform.position = Position + Vector3.up * num2; } protected abstract void OnArrivedAtTarget(); protected abstract void OnWorkComplete(); public void MoveTo(Vector3 target) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) TargetPosition = target; State = DroneState.MovingToTarget; } public void ReturnHome() { State = DroneState.Returning; } public void Destroy() { if ((Object)(object)gameObject != (Object)null) { Object.Destroy((Object)(object)gameObject); } DroneManager.AllDrones.Remove(this); } } public class DeliveryDrone : DroneController { public uint SourceChestId; public uint TargetChestId; public int CargoResourceId; public int CargoCount; public bool HasCargo = false; public override float Speed => EnhancedLogisticsPlugin.DeliveryDroneSpeed.Value; public override Color DroneColor => new Color(0.3f, 0.6f, 0.9f); public DeliveryDrone(Vector3 position, DronePort owner) : base(DroneType.Delivery, position, owner) { }//IL_0009: Unknown result type (might be due to invalid IL or missing references) public void AssignDeliveryTask(DeliveryTask task) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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_005d: 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_006d: Unknown result type (might be due to invalid IL or missing references) SourceChestId = task.sourceChestId; TargetChestId = task.targetChestId; CargoResourceId = task.resourceId; CargoCount = task.count; HasCargo = false; try { ChestInstance val = MachineManager.instance.Get<ChestInstance, ChestDefinition>((int)task.sourceChestId, (MachineTypeEnum)3); MoveTo(((GridInfo)(ref val.gridInfo)).Center + Vector3.up * hoverHeight); } catch { State = DroneState.Idle; } } public override void UpdateBehavior() { if (State == DroneState.Idle && DroneManager.PendingDeliveries.Count > 0) { DeliveryTask task = DroneManager.PendingDeliveries.Dequeue(); AssignDeliveryTask(task); } } protected override void OnArrivedAtTarget() { if (!HasCargo) { State = DroneState.Working; StateTimer = 1.5f; } else { State = DroneState.Working; StateTimer = 1.5f; } } protected override void OnWorkComplete() { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: 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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0098: 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_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) if (!HasCargo) { try { ChestInstance val = MachineManager.instance.Get<ChestInstance, ChestDefinition>((int)SourceChestId, (MachineTypeEnum)3); Inventory inventory = ((ChestInstance)(ref val)).GetInventory(); int num = Mathf.Min(CargoCount, EnhancedLogisticsPlugin.DroneCapacity.Value); int num2 = ((Inventory)(ref inventory)).TryRemoveResources(CargoResourceId, num); if (num2 > 0) { CargoCount = num2; HasCargo = true; ChestInstance val2 = MachineManager.instance.Get<ChestInstance, ChestDefinition>((int)TargetChestId, (MachineTypeEnum)3); MoveTo(((GridInfo)(ref val2.gridInfo)).Center + Vector3.up * hoverHeight); } else { ReturnHome(); } return; } catch { ReturnHome(); return; } } EnhancedLogisticsPlugin.Log.LogDebug((object)$"Delivery drone #{Id} delivered {CargoCount} items"); HasCargo = false; CargoCount = 0; ReturnHome(); } } public class CombatDrone : DroneController { public Transform CurrentTarget; public float AttackRange = 25f; public float FireCooldown = 0f; public float PatrolRadius = 30f; public Vector3 PatrolCenter; private LineRenderer laserLine; private float laserTimer = 0f; public override float Speed => EnhancedLogisticsPlugin.CombatDroneSpeed.Value; public override Color DroneColor => new Color(0.9f, 0.3f, 0.2f); public CombatDrone(Vector3 position, DronePort owner) : base(DroneType.Combat, position, owner) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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) PatrolCenter = position; CreateWeaponVisual(); } private void CreateWeaponVisual() { //IL_0031: 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_005b: 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_012a: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.CreatePrimitive((PrimitiveType)2); ((Object)val).name = "Gun"; val.transform.SetParent(gameObject.transform); val.transform.localPosition = Vector3.down * 0.25f; val.transform.localRotation = Quaternion.Euler(90f, 0f, 0f); val.transform.localScale = new Vector3(0.08f, 0.2f, 0.08f); Collider component = val.GetComponent<Collider>(); if ((Object)(object)component != (Object)null) { Object.Destroy((Object)(object)component); } Renderer component2 = val.GetComponent<Renderer>(); if ((Object)(object)component2 != (Object)null) { component2.material = EnhancedLogisticsPlugin.GetDroneMaterial(new Color(0.15f, 0.15f, 0.2f)); } laserLine = gameObject.AddComponent<LineRenderer>(); laserLine.startWidth = 0.05f; laserLine.endWidth = 0.02f; laserLine.positionCount = 2; ((Renderer)laserLine).material = EnhancedLogisticsPlugin.GetDroneMaterial(new Color(1f, 0.3f, 0.1f)); ((Renderer)laserLine).enabled = false; } public override void UpdateBehavior() { FireCooldown -= Time.deltaTime; laserTimer -= Time.deltaTime; if (laserTimer <= 0f && (Object)(object)laserLine != (Object)null) { ((Renderer)laserLine).enabled = false; } if (State == DroneState.Idle) { FindTarget(); if ((Object)(object)CurrentTarget == (Object)null) { PatrolAroundHome(); } } else if (State == DroneState.Working) { AttackTarget(); } } private void FindTarget() { //IL_004f: 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_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: 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_00c8: Unknown result type (might be due to invalid IL or missing references) List<Transform> activeAliens = DroneManager.GetActiveAliens(); if (activeAliens.Count == 0) { CurrentTarget = null; return; } float num = float.MaxValue; Transform val = null; foreach (Transform item in activeAliens) { if (!((Object)(object)item == (Object)null)) { float num2 = Vector3.Distance(Position, item.position); if (num2 < AttackRange && num2 < num) { num = num2; val = item; } } } if ((Object)(object)val != (Object)null) { CurrentTarget = val; MoveTo(val.position + Vector3.up * 2f); } } private void PatrolAroundHome() { //IL_0021: 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) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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) if (HomePort != null && Random.value < 0.01f) { Vector2 val = Random.insideUnitCircle * PatrolRadius; Vector3 target = HomePort.Position + new Vector3(val.x, hoverHeight, val.y); MoveTo(target); } } private void AttackTarget() { //IL_001f: 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_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: 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_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: 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_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)CurrentTarget == (Object)null) { State = DroneState.Idle; return; } float num = Vector3.Distance(Position, CurrentTarget.position); if (num > AttackRange * 1.5f) { CurrentTarget = null; State = DroneState.Idle; return; } if (FireCooldown <= 0f) { FireAtTarget(); FireCooldown = 1f / EnhancedLogisticsPlugin.CombatDroneFireRate.Value; } Vector3 val; if (num < AttackRange * 0.5f) { val = Position - CurrentTarget.position; Vector3 normalized = ((Vector3)(ref val)).normalized; Position += normalized * Speed * 0.5f * Time.deltaTime; } val = CurrentTarget.position - Position; Vector3 normalized2 = ((Vector3)(ref val)).normalized; if (((Vector3)(ref normalized2)).sqrMagnitude > 0.001f) { Quaternion val2 = Quaternion.LookRotation(normalized2, Vector3.up); gameObject.transform.rotation = Quaternion.Slerp(gameObject.transform.rotation, val2, Time.deltaTime * 8f); } } private void FireAtTarget() { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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_0068: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)CurrentTarget == (Object)null) { return; } if ((Object)(object)laserLine != (Object)null) { ((Renderer)laserLine).enabled = true; laserLine.SetPosition(0, Position + Vector3.down * 0.25f); laserLine.SetPosition(1, CurrentTarget.position); laserTimer = 0.1f; } try { Type type = System.Type.GetType("TurretDefense.TurretDefensePlugin, TurretDefense"); if (!(type != null)) { return; } Component component = ((Component)CurrentTarget).GetComponent("AlienShipController"); if (!((Object)(object)component != (Object)null)) { return; } MethodInfo method = ((object)component).GetType().GetMethod("TakeDamage"); if (method != null) { float num = EnhancedLogisticsPlugin.CombatDroneDamage.Value; bool flag = Random.value < 0.15f; if (flag) { num *= 2f; } method.Invoke(component, new object[2] { num, flag }); string arg = (flag ? " (CRITICAL!)" : ""); EnhancedLogisticsPlugin.Log.LogDebug((object)$"Combat drone dealt {num:F0} damage{arg}"); } } catch { } } protected override void OnArrivedAtTarget() { if ((Object)(object)CurrentTarget != (Object)null) { State = DroneState.Working; } else { State = DroneState.Idle; } } protected override void OnWorkComplete() { State = DroneState.Idle; CurrentTarget = null; } } public class RepairDrone : DroneController { public Transform RepairTarget; public float RepairRange = 20f; public float ScanCooldown = 0f; private LineRenderer repairBeam; public override float Speed => EnhancedLogisticsPlugin.RepairDroneSpeed.Value; public override Color DroneColor => new Color(0.3f, 0.9f, 0.4f); public RepairDrone(Vector3 position, DronePort owner) : base(DroneType.Repair, position, owner) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) CreateRepairVisual(); } private void CreateRepairVisual() { //IL_0031: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.CreatePrimitive((PrimitiveType)3); ((Object)val).name = "RepairTool"; val.transform.SetParent(gameObject.transform); val.transform.localPosition = Vector3.down * 0.25f; val.transform.localScale = new Vector3(0.1f, 0.15f, 0.1f); Collider component = val.GetComponent<Collider>(); if ((Object)(object)component != (Object)null) { Object.Destroy((Object)(object)component); } Renderer component2 = val.GetComponent<Renderer>(); if ((Object)(object)component2 != (Object)null) { component2.material = EnhancedLogisticsPlugin.GetDroneMaterial(new Color(0.8f, 0.7f, 0.2f)); } repairBeam = gameObject.AddComponent<LineRenderer>(); repairBeam.startWidth = 0.08f; repairBeam.endWidth = 0.03f; repairBeam.positionCount = 2; ((Renderer)repairBeam).material = EnhancedLogisticsPlugin.GetDroneMaterial(new Color(0.2f, 1f, 0.4f)); ((Renderer)repairBeam).enabled = false; } public override void UpdateBehavior() { ScanCooldown -= Time.deltaTime; if (State == DroneState.Idle) { if (ScanCooldown <= 0f) { FindDamagedMachine(); ScanCooldown = 2f; } } else if (State == DroneState.Working) { PerformRepair(); } } private void FindDamagedMachine() { //IL_00d0: 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_00e0: 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_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) try { Type type = System.Type.GetType("SurvivalElements.SurvivalElementsPlugin, SurvivalElements"); if (type != null) { FieldInfo field = type.GetField("DamagedMachines", BindingFlags.Static | BindingFlags.Public); if (field != null && field.GetValue(null) is IList list && list.Count > 0) { foreach (object item in list) { } } } } catch { } if ((Object)(object)RepairTarget == (Object)null && HomePort != null && Random.value < 0.02f) { Vector2 val = Random.insideUnitCircle * RepairRange; Vector3 target = HomePort.Position + new Vector3(val.x, hoverHeight, val.y); MoveTo(target); } } private void PerformRepair() { //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_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: 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) if ((Object)(object)RepairTarget == (Object)null) { State = DroneState.Idle; ((Renderer)repairBeam).enabled = false; } else if ((Object)(object)repairBeam != (Object)null) { ((Renderer)repairBeam).enabled = true; repairBeam.SetPosition(0, Position + Vector3.down * 0.25f); repairBeam.SetPosition(1, RepairTarget.position); } } protected override void OnArrivedAtTarget() { if ((Object)(object)RepairTarget != (Object)null) { State = DroneState.Working; StateTimer = 5f; } else { State = DroneState.Idle; } } protected override void OnWorkComplete() { State = DroneState.Idle; RepairTarget = null; if ((Object)(object)repairBeam != (Object)null) { ((Renderer)repairBeam).enabled = false; } ReturnHome(); } } [HarmonyPatch] internal static class LogisticsPatches { private static readonly Dictionary<uint, DronePort> dronePortInstances = new Dictionary<uint, DronePort>(); private static readonly Dictionary<string, int> portPowerConsumption = new Dictionary<string, int> { { "Drone Port", 30 }, { "Combat Drone Port", 60 }, { "Repair Drone Port", 45 } }; private static bool IsDronePort(ref PowerGeneratorInstance instance, out DroneType portType) { portType = DroneType.Delivery; if ((Object)(object)((PowerGeneratorInstance)(ref instance)).myDef == (Object)null) { return false; } switch (((ResourceInfo)((PowerGeneratorInstance)(ref instance)).myDef).displayName) { case "Drone Port": portType = DroneType.Delivery; return true; case "Combat Drone Port": portType = DroneType.Combat; return true; case "Repair Drone Port": portType = DroneType.Repair; return true; default: return false; } } [HarmonyPatch(typeof(PowerGeneratorInstance), "SimUpdate")] [HarmonyPostfix] private static void DronePortSimUpdate(ref PowerGeneratorInstance __instance) { //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) try { if (IsDronePort(ref __instance, out var portType)) { string displayName = ((ResourceInfo)((PowerGeneratorInstance)(ref __instance)).myDef).displayName; uint instanceId = __instance.commonInfo.instanceId; if (portPowerConsumption.TryGetValue(displayName, out var value)) { ref PowerInfo powerInfo = ref __instance.powerInfo; powerInfo.curPowerConsumption = value; powerInfo.isGenerator = false; } bool hasPower = true; GameObject refGameObj = __instance.commonInfo.refGameObj; if ((Object)(object)refGameObj != (Object)null && !dronePortInstances.ContainsKey(instanceId)) { Vector3 position = refGameObj.transform.position; DronePort value2 = new DronePort(portType, position, instanceId); dronePortInstances[instanceId] = value2; EnhancedLogisticsPlugin.Log.LogInfo((object)$"Initialized {portType} drone port at {position}"); } if (dronePortInstances.TryGetValue(instanceId, out var value3)) { value3.HasPower = hasPower; } } } catch (Exception ex) { EnhancedLogisticsPlugin.Log.LogError((object)("DronePortSimUpdate error: " + ex.Message)); } } [HarmonyPatch(typeof(GridManager), "RemoveObj", new Type[] { typeof(GenericMachineInstanceRef) })] [HarmonyPrefix] private static void OnMachineRemoved(GenericMachineInstanceRef machineRef) { try { if (((GenericMachineInstanceRef)(ref machineRef)).IsValid() && dronePortInstances.TryGetValue(((GenericMachineInstanceRef)(ref machineRef)).instanceId, out var value)) { value.Destroy(); dronePortInstances.Remove(((GenericMachineInstanceRef)(ref machineRef)).instanceId); EnhancedLogisticsPlugin.Log.LogInfo((object)$"Drone port {((GenericMachineInstanceRef)(ref machineRef)).instanceId} removed"); } } catch { } } [HarmonyPatch(typeof(InserterInstance), "SimUpdate")] [HarmonyPrefix] private static void SpeedUpInserter(InserterInstance __instance) { if (EnhancedLogisticsPlugin.EnableBetterLogistics.Value) { } } } public class DroneAssetLoader { private string basePath; private Dictionary<string, AssetBundle> loadedBundles = new Dictionary<string, AssetBundle>(); private Dictionary<string, Dictionary<string, GameObject>> cachedPrefabs = new Dictionary<string, Dictionary<string, GameObject>>(); private static readonly Dictionary<DroneType, (string bundle, string prefab)> DronePrefabMap = new Dictionary<DroneType, (string, string)> { { DroneType.Delivery, ("drones_simple", "drone blue") }, { DroneType.Combat, ("drones_voodooplay", "Drone") }, { DroneType.Repair, ("drones_simple", "drone green Variant") } }; public bool HasDronePrefabs => loadedBundles.Count > 0; public DroneAssetLoader(string pluginPath) { basePath = pluginPath; } public bool LoadBundle(string bundleName) { if (loadedBundles.ContainsKey(bundleName)) { return true; } string[] array = new string[4] { Path.Combine(basePath, "Bundles", bundleName), Path.Combine(basePath, bundleName), Path.Combine(basePath, "Bundles", bundleName + ".bundle"), Path.Combine(basePath, bundleName + ".bundle") }; string[] array2 = array; foreach (string text in array2) { if (!File.Exists(text)) { continue; } try { AssetBundle val = AssetBundle.LoadFromFile(text); if ((Object)(object)val != (Object)null) { loadedBundles[bundleName] = val; cachedPrefabs[bundleName] = new Dictionary<string, GameObject>(); EnhancedLogisticsPlugin.Log.LogDebug((object)("Loaded bundle: " + text)); string[] allAssetNames = val.GetAllAssetNames(); EnhancedLogisticsPlugin.Log.LogDebug((object)$"Bundle {bundleName} contains {allAssetNames.Length} assets"); return true; } } catch (Exception ex) { EnhancedLo