using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Threading; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using BlueprintTweaks.BlueprintBrowserUIChanges; using BlueprintTweaks.BlueprintDataSaveEdit; using BlueprintTweaks.BrowserRememberFolder; using BlueprintTweaks.DragToMoveBlueprints; using BlueprintTweaks.FactoryUndo; using BlueprintTweaks.FactoryUndo.Nebula; using BlueprintTweaks.GlobalPatch; using BlueprintTweaks.KeepBPName; using BlueprintTweaks.Nebula; using BlueprintTweaks.Patches; using CommonAPI; using CommonAPI.Systems; using CommonAPI.Systems.ModLocalization; using HarmonyLib; using NebulaAPI; using NebulaAPI.GameState; using NebulaAPI.Interfaces; using NebulaAPI.Networking; using NebulaAPI.Packets; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("BlueprintTweaks")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+bea75e70a80ddddc8e37b3062edab6f7534f7966")] [assembly: AssemblyProduct("BlueprintTweaks")] [assembly: AssemblyTitle("BlueprintTweaks")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] namespace BlueprintTweaks { [HarmonyPatch] public static class BuildTool_BlueprintPastePatch { [HarmonyPatch(typeof(BuildTool_BlueprintPaste), "CheckBuildConditions")] [HarmonyTranspiler] public static IEnumerable Transpiler(IEnumerable instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Expected O, but got Unknown //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Expected O, but got Unknown //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).End().MatchBack(false, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldflda, (object)AccessTools.Field(typeof(BuildTool_BlueprintPaste), "cursorTarget"), (string)null) }); CodeMatcher val2 = val.Clone().MatchForward(false, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(BuildPreview), "condition"), (string)null) }); object operand = val2.Operand; val.Advance(1); while (!CodeInstructionExtensions.IsStloc(val.Instruction, (LocalBuilder)null)) { val.RemoveInstruction(); } val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, operand) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate>((Func)((BuildTool_BlueprintPaste tool, BuildPreview preview) => ((Vector3)(ref preview.lpos)).normalized * Mathf.Min(((BuildTool)tool).planet.realRadius * 0.025f, 20f))) }); return val.InstructionEnumeration(); } } [HarmonyPatch] public static class PlayerControllerPatch { [HarmonyPatch(typeof(PlayerController), "OpenBlueprintCopyMode")] [HarmonyPatch(typeof(PlayerController), "OpenBlueprintPasteMode")] [HarmonyPatch(typeof(BuildTool_BlueprintCopy), "DetermineActive")] [HarmonyPatch(typeof(BuildTool_BlueprintPaste), "CheckBuildConditionsPrestage")] [HarmonyPatch(typeof(BuildTool_BlueprintPaste), "DetermineActive")] [HarmonyTranspiler] public static IEnumerable RemoveGasGiantBlocks(IEnumerable instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Expected O, but got Unknown //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(PlanetData), "gasItems"), (string)null) }).Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Pop, (object)null) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldc_I4_0, (object)null) }) .MatchForward(true, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(PlanetData), "gasItems"), (string)null) }) .Advance(2) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Pop, (object)null) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldc_I4_0, (object)null) }); return val.InstructionEnumeration(); } [HarmonyPatch(typeof(BuildTool_BlueprintCopy), "UpdateRaycast")] [HarmonyPatch(typeof(BuildTool_BlueprintPaste), "UpdateRaycast")] [HarmonyTranspiler] public static IEnumerable ChangeCastDistance(IEnumerable instructions) { //IL_0002: 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_002b: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)800f, (string)null) }).SetInstruction(Transpilers.EmitDelegate>((Func)(() => GameCamera.instance.blueprintPoser.planetRadius * 2.4f))); return val.InstructionEnumeration(); } [HarmonyPatch(typeof(PlayerController), "OpenBlueprintPasteMode")] [HarmonyPrefix] public static bool CheckBpForGasGiants(PlayerController __instance, BlueprintData blueprint) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Invalid comparison between Unknown and I4 if (GameMain.history.blueprintLimit == 0) { return false; } if (blueprint == null) { blueprint = __instance.actionBuild.blueprintClipboard; } if (BlueprintData.IsNullOrEmpty(blueprint)) { return false; } if (BlueprintTweaksPlugin.genesisBookIsInstalled) { PlanetData localPlanet = __instance.gameData.localPlanet; if (localPlanet == null || (int)localPlanet.type != 5) { return true; } } else if (__instance.gameData.localPlanet?.gasItems == null || __instance.gameData.localPlanet.gasItems.Length == 0) { return true; } BlueprintBuilding[] buildings = blueprint.buildings; foreach (BlueprintBuilding val in buildings) { ItemProto val2 = ((ProtoSet)(object)LDB.items).Select((int)val.itemId); if (!val2.BuildInGas) { UIRealtimeTip.Popup(Localization.Translate("CantPasteThisInGasGiantWarn"), true, 0); return false; } } return true; } [HarmonyPatch(typeof(PlayerController), "OpenBlueprintCopyMode")] [HarmonyPatch(typeof(PlayerController), "OpenBlueprintPasteMode")] [HarmonyPostfix] public static void OnBPOpenOnGasGiants(PlayerController __instance) { GameCamera.instance.blueprintPoser.planetRadius = __instance.gameData.localPlanet.realRadius; } } [BepInPlugin("org.kremnev8.plugin.BlueprintTweaks", "Blueprint Tweaks", "1.6.12")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [CommonAPISubmoduleDependency(new string[] { "ProtoRegistry", "CustomKeyBindSystem", "PickerExtensionsSystem", "LocalizationModule" })] public class BlueprintTweaksPlugin : BaseUnityPlugin, IMultiplayerMod { public const string MODNAME = "BlueprintTweaks"; public const string MODGUID = "org.kremnev8.plugin.BlueprintTweaks"; public const string MOD_DISP_NAME = "Blueprint Tweaks"; public const string VERSION = "1.6.12"; public const string GENESIS_BOOK_MODGUID = "org.LoShin.GenesisBook"; public const string DRAG_REMOVE = "DragRemove"; public const string PASTE_LOCKED = "PasteLocked"; public const string FACTORY_UNDO = "FactoryUndo"; public static ManualLogSource logger; public static ResourceData resource; internal static ConfigFile configFile; private static Harmony harmony; public static DragRemoveBuildTool tool; public static bool gotPluginInfo; public static bool genesisBookIsInstalled; public static ConfigEntry cameraToggleEnabled; public static ConfigEntry addPasteButtonEnabled; public static ConfigEntry recipeChangeEnabled; public static ConfigEntry changeTierEnabled; public static ConfigEntry logisticCargoChangeEnabled; public static ConfigEntry beltHintsChangeEnable; public static ConfigEntry keepBlueprintDesc; public static ConfigEntry keepBrowserPath; public static ConfigEntry forcePasteEnabled; public static ConfigEntry axisLockEnabled; public static ConfigEntry gridControlFeature; public static ConfigEntry blueprintMirroring; public static ConfigEntry dragRemove; public static ConfigEntry pasteLocked; public static ConfigEntry moveWithDragNDrop; public static ConfigEntry factoryUndo; public static ConfigEntry resetFunctionsOnMenuExit; public static ConfigEntry canBlueprintOnGasGiants; public static ConfigEntry excludeStations; public static ConfigEntry undoExcludeStations; public static ConfigEntry undoMaxHistory; public static ConfigEntry showUndoClearedMessage; private static bool appliedBlueprintDataPatch = false; internal static List modKeybinds = new List(); public string Version => "1.6.12"; private void Awake() { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown logger = ((BaseUnityPlugin)this).Logger; configFile = ((BaseUnityPlugin)this).Config; LoadConfigs(); ((BaseUnityPlugin)this).Config.Save(); string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); resource = new ResourceData("BlueprintTweaks", "blueprinttweaks", directoryName); resource.LoadAssetBundle("blueprinttweaks"); ProtoRegistry.AddResource(resource); string text = Path.Combine(directoryName, "Locale"); LocalizationModule.LoadTranslationsFromFolder(text); harmony = new Harmony("org.kremnev8.plugin.BlueprintTweaks"); if (factoryUndo.Value) { UndoManager.Init(); } UIBlueprintInspectorPatch.Init(); BlueprintUtilsPatch2.Init(); RegisterKeyBinds(); NebulaModAPI.RegisterPackets(Assembly.GetExecutingAssembly()); if (factoryUndo.Value) { HarmonyRegisterExtension.PatchAll(harmony, "FactoryUndo"); } if (keepBrowserPath.Value) { harmony.PatchAll(typeof(BlueprintTweaks.BrowserRememberFolder.UIBlueprintBrowser_Patch)); } if (moveWithDragNDrop.Value) { harmony.PatchAll(typeof(BuildTool_Copy_Patch)); harmony.PatchAll(typeof(BlueprintTweaks.DragToMoveBlueprints.UIBlueprintBrowser_Patch)); } if (keepBlueprintDesc.Value) { harmony.PatchAll(typeof(BlueprintTweaks.KeepBPName.UIBlueprintInspectorPatch)); } if (pasteLocked.Value) { HarmonyRegisterExtension.PatchAll(harmony, "PasteLocked"); } if (addPasteButtonEnabled.Value) { harmony.PatchAll(typeof(UIBlueprintBrowserPatch)); } if (blueprintMirroring.Value) { harmony.PatchAll(typeof(BlueprintUtilsPatch2)); } if (dragRemove.Value) { HarmonyRegisterExtension.PatchAll(harmony, "DragRemove"); } if (changeTierEnabled.Value) { harmony.PatchAll(typeof(UIBlueprintComponentItemPatch)); } if (canBlueprintOnGasGiants.Value) { harmony.PatchAll(typeof(PlayerControllerPatch)); harmony.PatchAll(typeof(BuildTool_BlueprintPastePatch)); } if (axisLockEnabled.Value || gridControlFeature.Value) { harmony.PatchAll(typeof(GridSnappingPatches)); harmony.PatchAll(typeof(BuildTool_BlueprintPaste_Patch)); ApplyBlueprintDataPatch(); } if (cameraToggleEnabled.Value) { harmony.PatchAll(typeof(CameraFixPatch)); } if (recipeChangeEnabled.Value || gridControlFeature.Value) { harmony.PatchAll(typeof(UIBlueprintInspectorPatch)); } _ = forcePasteEnabled.Value; harmony.PatchAll(typeof(BuildTool_BlueprintPaste_Patch_3)); logger.LogInfo((object)"Blueprint tweaks mod is initialized!"); } private void LoadConfigs() { cameraToggleEnabled = ((BaseUnityPlugin)this).Config.Bind("Interface", "cameraToggle", true, "Allows toggling camera between 3rd person and god view\nAll values are applied on restart"); addPasteButtonEnabled = ((BaseUnityPlugin)this).Config.Bind("Interface", "addBluprintPasteButton", true, "If enabled new button will be added to Blueprint Browser. Pressing it will paste curretly selected blueprint\nAll values are applied on restart"); recipeChangeEnabled = ((BaseUnityPlugin)this).Config.Bind("Interface", "recipeChange", true, "Add recipe change panel to blueprint inspectors\nAll values are applied on restart"); logisticCargoChangeEnabled = ((BaseUnityPlugin)this).Config.Bind("Interface", "changeLogisticCargo", true, "Allows changing cargo requested/provided by logistic stations"); changeTierEnabled = ((BaseUnityPlugin)this).Config.Bind("Interface", "changeTier", true, "Allows using change tier functionality\nAll values are applied on restart"); beltHintsChangeEnable = ((BaseUnityPlugin)this).Config.Bind("Interface", "beltHintChange", true, "Add belt hint change panel to blueprint inspectors\nAll values are applied on restart"); keepBlueprintDesc = ((BaseUnityPlugin)this).Config.Bind("Interface", "keepBlueprintDescription", true, "When pasting blueprint string into existing blueprint you can hold shift to keep description and icons"); keepBrowserPath = ((BaseUnityPlugin)this).Config.Bind("Interface", "keepBroserPath", true, "Preserve last open Blueprint Browser directory. Also when creating new blueprints, they will be saved in the last open directory"); forcePasteEnabled = ((BaseUnityPlugin)this).Config.Bind("Features", "forcePaste", true, "Allow to force paste using Shift+Click"); axisLockEnabled = ((BaseUnityPlugin)this).Config.Bind("Features", "axisLock", true, "Allows using Latitude/Longtitude axis locks\nAll values are applied on restart"); gridControlFeature = ((BaseUnityPlugin)this).Config.Bind("Features", "gridControl", true, "Allows changing grid size and its offset\nAll values are applied on restart"); blueprintMirroring = ((BaseUnityPlugin)this).Config.Bind("Features", "blueprintMirroring", true, "Allows mirroring Blueprints\nAll values are applied on restart"); dragRemove = ((BaseUnityPlugin)this).Config.Bind("Features", "dragRemove", true, "Allows using drag remove function\nAll values are applied on restart"); pasteLocked = ((BaseUnityPlugin)this).Config.Bind("Features", "PasteLockedRecipes", true, "Allow pasting assemblers with recipes which have not been unlocked yet. Assemblers with recipes that are not unlocked will not work."); moveWithDragNDrop = ((BaseUnityPlugin)this).Config.Bind("Features", "moveBPWithDragNDrop", true, "Allow moving blueprints using drag and drop"); factoryUndo = ((BaseUnityPlugin)this).Config.Bind("Features", "factoryUndo", true, "Enable Factory Undo feature. Allows to undo/redo most building actions. Will force dragRemove to true"); resetFunctionsOnMenuExit = ((BaseUnityPlugin)this).Config.Bind("Misc", "resetOnExit", true, "If enabled when you exit build mode, some functions (Axis/Grid lock, Mirror) will reset their state"); canBlueprintOnGasGiants = ((BaseUnityPlugin)this).Config.Bind("Misc", "bpOnGasGiants", true, "Allow using Blueprints on Gas Giants\nAll values are applied on restart"); excludeStations = ((BaseUnityPlugin)this).Config.Bind("Misc", "excludeStations", true, "When using drag remove tool, logistic stations (and miners Mk.II) will not get removed. This is a safeguard against errors which occur most of the time when you try to mass dismantle logistic stations."); undoMaxHistory = ((BaseUnityPlugin)this).Config.Bind("Misc", "undoMaxHistory", 50, "Defines undo history size. When history reaches it's capacity, old entries will get removed. When using Nebula host controls the used value"); undoExcludeStations = ((BaseUnityPlugin)this).Config.Bind("Misc", "undoExcludeStations", true, "When enabled factory undo will not undo/redo actions with logistic stations."); showUndoClearedMessage = ((BaseUnityPlugin)this).Config.Bind("Misc", "showUndoClearedMessage", true, "Should a message informing you that undo history has been cleared be shown whenever you leave a planet?"); ConfigFileExtension.MigrateConfig(((BaseUnityPlugin)this).Config, "General", "Interface", new string[4] { "cameraToggle", "recipeChange", "changeLogisticCargo", "changeTier" }); ConfigFileExtension.MigrateConfig(((BaseUnityPlugin)this).Config, "General", "Features", new string[5] { "forcePaste", "axisLock", "gridControl", "gridControl", "blueprintFoundations" }); ConfigFileExtension.MigrateConfig(((BaseUnityPlugin)this).Config, "General", "Misc", new string[1] { "bpOnGasGiants" }); if (factoryUndo.Value) { dragRemove.Value = true; } } private static void RegisterKeyBinds() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_004a: 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_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0108: 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_013f: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_016a: 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_0194: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: 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_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_0260: 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_028d: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: Unknown result type (might be due to invalid IL or missing references) if (cameraToggleEnabled.Value) { modKeybinds.Add(CustomKeyBindSystem.RegisterKeyBindWithReturn(new BuiltinKey { key = new CombineKey(106, (byte)0, (ECombineKeyAction)0, false), conflictGroup = 3071, name = "ToggleBPGodModeDesc", canOverride = true })); } if (forcePasteEnabled.Value) { modKeybinds.Add((PressKeyBind)(object)CustomKeyBindSystem.RegisterKeyBindWithReturn(new BuiltinKey { key = new CombineKey(0, (byte)1, (ECombineKeyAction)0, false), conflictGroup = 2052, name = "ForceBPPlace", canOverride = true })); } if (axisLockEnabled.Value) { modKeybinds.Add(CustomKeyBindSystem.RegisterKeyBindWithReturn(new BuiltinKey { key = new CombineKey(103, (byte)2, (ECombineKeyAction)0, false), conflictGroup = 2052, name = "LockLongAxis", canOverride = true })); modKeybinds.Add(CustomKeyBindSystem.RegisterKeyBindWithReturn(new BuiltinKey { key = new CombineKey(116, (byte)2, (ECombineKeyAction)0, false), conflictGroup = 2052, name = "LockLatAxis", canOverride = true })); } if (gridControlFeature.Value) { modKeybinds.Add(CustomKeyBindSystem.RegisterKeyBindWithReturn(new BuiltinKey { key = new CombineKey(98, (byte)2, (ECombineKeyAction)0, false), conflictGroup = 2052, name = "SetLocalOffset", canOverride = true })); } if (blueprintMirroring.Value) { modKeybinds.Add(CustomKeyBindSystem.RegisterKeyBindWithReturn(new BuiltinKey { key = new CombineKey(103, (byte)1, (ECombineKeyAction)0, false), conflictGroup = 2052, name = "MirrorLongAxis", canOverride = true })); modKeybinds.Add(CustomKeyBindSystem.RegisterKeyBindWithReturn(new BuiltinKey { key = new CombineKey(116, (byte)1, (ECombineKeyAction)0, false), conflictGroup = 2052, name = "MirrorLatAxis", canOverride = true })); } if (factoryUndo.Value) { CustomKeyBindSystem.RegisterKeyBind(new BuiltinKey { key = new CombineKey(122, (byte)2, (ECombineKeyAction)0, false), conflictGroup = 2052, name = "FactoryUndo", canOverride = true }); CustomKeyBindSystem.RegisterKeyBind(new BuiltinKey { key = new CombineKey(122, (byte)1, (ECombineKeyAction)0, false), conflictGroup = 2052, name = "FactoryRedo", canOverride = true }); } } private void Update() { if (!gotPluginInfo) { if (Chainloader.PluginInfos.ContainsKey("org.LoShin.GenesisBook")) { genesisBookIsInstalled = true; } gotPluginInfo = true; } if (!GameMain.isRunning || GameMain.localPlanet == null) { return; } if (factoryUndo.Value) { if (CustomKeyBindSystem.GetKeyBind("FactoryUndo").keyValue) { UndoManager.TryUndo(); } if (CustomKeyBindSystem.GetKeyBind("FactoryRedo").keyValue) { UndoManager.TryRedo(); } } if (cameraToggleEnabled.Value && CustomKeyBindSystem.GetKeyBind("ToggleBPGodModeDesc").keyValue) { CameraFixPatch.mode = !CameraFixPatch.mode; } if (axisLockEnabled.Value && CustomKeyBindSystem.GetKeyBind("LockLongAxis").keyValue) { GridSnappingPatches.LockLongitude(); } if (axisLockEnabled.Value && CustomKeyBindSystem.GetKeyBind("LockLatAxis").keyValue) { GridSnappingPatches.LockLatitude(); } if (gridControlFeature.Value && CustomKeyBindSystem.GetKeyBind("SetLocalOffset").keyValue) { GridSnappingPatches.SetOffset(); } _ = forcePasteEnabled.Value; if (blueprintMirroring.Value && CustomKeyBindSystem.GetKeyBind("MirrorLongAxis").keyValue) { BlueprintUtilsPatch2.mirrorLong = !BlueprintUtilsPatch2.mirrorLong; BlueprintUtilsPatch2.UpdateBlueprintDisplay(); } if (blueprintMirroring.Value && CustomKeyBindSystem.GetKeyBind("MirrorLatAxis").keyValue) { BlueprintUtilsPatch2.mirrorLat = !BlueprintUtilsPatch2.mirrorLat; BlueprintUtilsPatch2.UpdateBlueprintDisplay(); } } public static void RegisterCustomBlueprintDataSerializer(string key) where T : ICustomBlueprintDataSerializer, new() { ApplyBlueprintDataPatch(); if (BlueprintData_Patch_2.customSerializers.ContainsKey(key)) { logger.LogError((object)("Failed to register custom blueprint data serializer with key '" + key + "' and type " + typeof(T).FullName + ", because the key has been already taken!")); } else { T val = new T(); BlueprintData_Patch_2.customSerializers.Add(key, val); logger.LogInfo((object)("Registered custom blueprint data serializer with key '" + key + "'")); } } private static void ApplyBlueprintDataPatch() { if (!appliedBlueprintDataPatch) { harmony.PatchAll(typeof(BlueprintData_Patch_2)); appliedBlueprintDataPatch = true; } } public bool CheckVersion(string hostVersion, string clientVersion) { return hostVersion.Equals(clientVersion); } } public class CustomWindowData { public UIBlueprintPanel[] panels; public RectTransform mainPane; } public abstract class UIBlueprintPanel : MonoBehaviour { [HideInInspector] public UIBlueprintInspector inspector; [HideInInspector] public RectTransform panelTrs; public abstract int verticalSize { get; } public virtual void Create(UIBlueprintInspector inspector) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown this.inspector = inspector; panelTrs = (RectTransform)((Component)this).transform; } public void RefreshUI() { if (inspector.blueprint != null && inspector.blueprint.isValid) { OnUpdate(); } } public virtual void OnOpen() { } public virtual void OnUpdate() { } } public class UIBlueprintRecipeItem : MonoBehaviour { [HideInInspector] public UIRecipesPanel panel; public RectTransform rectTrans; public UIButton button; public Image iconImage; private int recipeId; private ERecipeType recipeFilter; private const int kMargin = 0; private const int kWidth = 46; private const int kHeight = 46; private const int kColCount = 8; public int position { get { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) return Mathf.RoundToInt(rectTrans.anchoredPosition.x / 46f) + Mathf.RoundToInt((0f - rectTrans.anchoredPosition.y) / 46f) * 8; } set { //IL_0015: Unknown result type (might be due to invalid IL or missing references) rectTrans.anchoredPosition = new Vector2((float)(value % 8 * 46), (float)(-(value / 8 * 46))); } } public void Create(UIRecipesPanel panel) { this.panel = panel; button.onClick += OnClick; } public void Free() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) button.onClick -= OnClick; recipeId = 0; button.tips.itemId = 0; button.data = 0; iconImage.sprite = null; ((Graphic)iconImage).color = Color.clear; } public void Open() { ((Component)this).gameObject.SetActive(true); } public void Close() { button.tips.itemId = 0; button.data = 0; recipeId = 0; ((Component)this).gameObject.SetActive(false); } public int SetDisplay(int newIndex, int recipeID) { //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_00b0: 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_00ca: 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_0140: Unknown result type (might be due to invalid IL or missing references) position = newIndex; if (recipeId != recipeID) { recipeId = recipeID; button.data = recipeId; RecipeProto val = ((ProtoSet)(object)LDB.recipes).Select(recipeID); button.tips.itemId = 0; button.tips.tipTitle = ""; button.tips.tipText = ""; if (val != null) { button.tips.itemId = val.Results[0]; recipeFilter = val.Type; iconImage.sprite = val.iconSprite; ((Graphic)iconImage).color = Color.white; } else if (recipeID < 0) { recipeFilter = (ERecipeType)(byte)(-recipeID); string arg = Localization.Translate($"{recipeFilter}RecipeKind"); button.tips.tipTitle = string.Format(Localization.Translate("SelectEmptyRecipeTitle"), arg); button.tips.tipText = string.Format(Localization.Translate("SelectEmptyRecipeText"), arg); iconImage.sprite = UIRecipesPanel.noRecipeIcon; ((Graphic)iconImage).color = Color.white; } else { iconImage.sprite = null; ((Graphic)iconImage).color = Color.clear; } } return (newIndex / 8 + 1) * 46; } private void OnClick(int obj) { //IL_0006: 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_003a: Unknown result type (might be due to invalid IL or missing references) VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 1, -1, -1L); Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(-300f, 238f); UIRecipePicker.Close(); UIRecipePicker.Popup(val, (Action)delegate(RecipeProto proto) { if (proto != null) { panel.ChangeRecipe(recipeId, proto); } }, recipeFilter); } } public class UIBPComponentPanel : UIBlueprintPanel { public override int verticalSize { get { if (inspector.componentCount == 0) { return 22; } return 22 + ((inspector.componentCount - 1) / 8 + 1) * 46; } } public override void Create(UIBlueprintInspector inspector) { base.Create(inspector); panelTrs = inspector.group2; } } public class UIBPReformsPanel : UIBlueprintPanel { public override int verticalSize { get { if (inspector.blueprint.reformData.reformCount == 0) { return 0; } return 68; } } public override void Create(UIBlueprintInspector inspector) { base.Create(inspector); panelTrs = inspector.group4; } } public class UIBPStringCopyPanel : UIBlueprintPanel { public override int verticalSize => 110; public override void Create(UIBlueprintInspector inspector) { base.Create(inspector); panelTrs = inspector.group3; } } public class UIHintItem : MonoBehaviour { [HideInInspector] public UIHintsPanel panel; public RectTransform rectTrans; public UIButton button; public Image iconImage; public Text countText; private HintData currentHint; private const int kMargin = 0; private const int kWidth = 46; private const int kHeight = 46; private const int kColCount = 8; public int position { get { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) return Mathf.RoundToInt(rectTrans.anchoredPosition.x / 46f) + Mathf.RoundToInt((0f - rectTrans.anchoredPosition.y) / 46f) * 8; } set { //IL_0015: Unknown result type (might be due to invalid IL or missing references) rectTrans.anchoredPosition = new Vector2((float)(value % 8 * 46), (float)(-(value / 8 * 46))); } } public void Create(UIHintsPanel panel) { this.panel = panel; button.onClick += OnClick; } public void Free() { //IL_0052: Unknown result type (might be due to invalid IL or missing references) button.onClick -= OnClick; currentHint = default(HintData); button.tips.itemId = 0; button.data = 0; iconImage.sprite = null; ((Graphic)iconImage).color = Color.clear; countText.text = ""; } public void Open() { ((Component)this).gameObject.SetActive(true); } public void Close() { button.tips.itemId = 0; button.data = 0; currentHint = default(HintData); ((Component)this).gameObject.SetActive(false); } public int SetDisplay(int newIndex, HintData newHint) { //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) position = newIndex; if (!object.Equals(currentHint, newHint)) { currentHint = newHint; button.data = currentHint.signalId; Sprite val = LDB.signals.IconSprite(currentHint.signalId); if ((Object)(object)val != (Object)null) { button.tips.itemId = currentHint.signalId; iconImage.sprite = val; ((Graphic)iconImage).color = Color.white; } else { iconImage.sprite = null; ((Graphic)iconImage).color = Color.clear; } countText.text = ((newHint.value != 0) ? newHint.value.ToString() : ""); } return (newIndex / 8 + 1) * 46; } private void OnClick(int obj) { //IL_0006: 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) VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 1, -1, -1L); Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(-300f, 238f); UISignalPicker.Close(); UINumberPickerExtension.Popup(val, (Action)delegate(int signalId, int value) { if (value < 0) { value = 0; } panel.ChangeHint(currentHint.signalId, new HintData(signalId, value)); }, currentHint.value, currentHint.signalId, (Func)null); } } public struct HintData { public int signalId; public int value; public HintData(int signalId, int value) { this.signalId = signalId; this.value = value; } } public class UIHintsPanel : UIBlueprintPanel { public List hintsItems = new List(); public List tmpHintList = new List(); public int hintsCount; public UIHintItem prefab; public override int verticalSize { get { if (hintsCount == 0) { return 22; } return 22 + ((hintsCount - 1) / 8 + 1) * 46; } } public override void OnUpdate() { tmpHintList.Clear(); BlueprintBuilding[] buildings = inspector.blueprint.buildings; foreach (BlueprintBuilding val in buildings) { int itemId = val.itemId; ItemProto val2 = ((ProtoSet)(object)LDB.items).Select(itemId); if (val2 == null || !val2.prefabDesc.isBelt || val.parameters == null || val.parameters.Length < 1) { continue; } int signalId = val.parameters[0]; if (signalId != 0) { int count = 0; if (val.parameters.Length >= 2) { count = val.parameters[1]; } if (!tmpHintList.Any((HintData data) => data.signalId == signalId && data.value == count)) { tmpHintList.Add(new HintData(signalId, count)); } } } int num = 0; foreach (HintData tmpHint in tmpHintList) { SetItem(num, tmpHint); num++; } ClearComponentItems(num); } public void SetItem(int index, HintData itemId) { if (index >= 0 && index <= 256) { while (index >= hintsItems.Count) { UIHintItem uIHintItem = Object.Instantiate(prefab, ((Component)prefab).transform.parent); uIHintItem.Create(this); hintsItems.Add(uIHintItem); } hintsItems[index].SetDisplay(index, itemId); hintsItems[index].Open(); } } public void ClearComponentItems(int activeCount = 0) { for (int i = activeCount; i < hintsItems.Count; i++) { hintsItems[i].Close(); } hintsCount = activeCount; } public void ChangeHint(int oldSignalId, HintData newSignal) { //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Invalid comparison between Unknown and I4 BlueprintBuilding[] buildings = inspector.blueprint.buildings; foreach (BlueprintBuilding val in buildings) { int itemId = val.itemId; ItemProto val2 = ((ProtoSet)(object)LDB.items).Select(itemId); if (val2.prefabDesc.isBelt && val.parameters != null && val.parameters.Length >= 1 && val.parameters[0] == oldSignalId) { val.parameters[0] = newSignal.signalId; if (val.parameters.Length >= 2) { val.parameters[1] = newSignal.value; } else if (newSignal.value != 0) { val.parameters = new int[2] { newSignal.signalId, newSignal.value }; } } } if ((int)inspector.usage == 2) { inspector.pasteBuildTool.ResetStates(); } inspector.Refresh(true, true, true, false); } } public class UIKeybindHintsPanel : UIBlueprintPanel { public ConfigEntry isCollapsed; public int currentSize = 22; public Text collapseText; public Text hintText; public override int verticalSize => currentSize; private void Awake() { isCollapsed = BlueprintTweaksPlugin.configFile.Bind("Runtime", "KeyBindHints_IsCollapsed", true, "This is a runtime option. You don't need to change it here, it can be altered ingame!"); } public override void OnOpen() { OnUpdate(); } public unsafe override void OnUpdate() { //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) currentSize = 22; string text = Localization.Translate("KeyHintsCollapseText"); string text2 = (isCollapsed.Value ? "▶" : "▼"); collapseText.text = text2 + " " + text; if (isCollapsed.Value) { hintText.text = ""; return; } StringBuilder stringBuilder = new StringBuilder(); foreach (PressKeyBind modKeybind in BlueprintTweaksPlugin.modKeybinds) { CombineKey val = modKeybind.defaultBind.key; if (!((CombineKey)(ref VFInput.override_keys[modKeybind.defaultBind.id])).IsNull()) { val = VFInput.override_keys[modKeybind.defaultBind.id]; } string text3 = "KEY" + modKeybind.defaultBind.name; stringBuilder.Append(string.Format(Localization.Translate("KeyHintsPress"), ((object)(*(CombineKey*)(&val))/*cast due to .constrained prefix*/).ToString(), Localization.Translate(text3))); stringBuilder.Append('\n'); currentSize += 22; } hintText.text = stringBuilder.ToString(); } public void OnCollapseClicked() { isCollapsed.Value = !isCollapsed.Value; inspector.Refresh(true, true, true, false); } } public class UIRecipesPanel : UIBlueprintPanel { public List recipeItems = new List(); public List tmpRecipeList = new List(); public int recipeCount; public UIBlueprintRecipeItem prefab; public static Sprite noRecipeIcon; public override int verticalSize { get { if (recipeCount == 0) { return 22; } return 22 + ((recipeCount - 1) / 8 + 1) * 46; } } private void Awake() { noRecipeIcon = Resources.Load("ui/textures/sprites/icons/select-recipe"); } public override void OnUpdate() { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unsupported input type for neg. //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected I4, but got Unknown tmpRecipeList.Clear(); BlueprintBuilding[] buildings = inspector.blueprint.buildings; foreach (BlueprintBuilding val in buildings) { int num = val.recipeId; if (num == 0) { ItemProto val2 = ((ProtoSet)(object)LDB.items).Select((int)val.itemId); if (val2.prefabDesc != null) { num = 0 - val2.prefabDesc.assemblerRecipeType; if (val2.prefabDesc.isLab && val.parameters.Length != 0 && val.parameters[0] != 2) { num = -15; } } } if (num != 0 && !tmpRecipeList.Contains(num)) { tmpRecipeList.Add(num); } } int num2 = 0; foreach (int tmpRecipe in tmpRecipeList) { SetItem(num2, tmpRecipe); num2++; } ClearComponentItems(num2); } public void SetItem(int index, int recipeId) { if (index >= 0 && index <= 256) { while (index >= recipeItems.Count) { UIBlueprintRecipeItem uIBlueprintRecipeItem = Object.Instantiate(prefab, ((Component)prefab).transform.parent); uIBlueprintRecipeItem.Create(this); recipeItems.Add(uIBlueprintRecipeItem); } recipeItems[index].SetDisplay(index, recipeId); recipeItems[index].Open(); } } public void ClearComponentItems(int activeCount = 0) { for (int i = activeCount; i < recipeItems.Count; i++) { recipeItems[i].Close(); } recipeCount = activeCount; } public void ChangeRecipe(int oldRecipe, RecipeProto newRecipe) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Invalid comparison between Unknown and I4 //IL_0056: 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_007e: Invalid comparison between Unknown and I4 BlueprintBuilding[] buildings = inspector.blueprint.buildings; if (oldRecipe < 0) { ERecipeType val = (ERecipeType)(byte)(-oldRecipe); BlueprintBuilding[] array = buildings; foreach (BlueprintBuilding val2 in array) { if (val2.recipeId != 0) { continue; } ItemProto val3 = ((ProtoSet)(object)LDB.items).Select((int)val2.itemId); if (val3.prefabDesc != null) { if (val3.prefabDesc.assemblerRecipeType == val) { val2.recipeId = ((Proto)newRecipe).ID; } else if (val3.prefabDesc.isLab && (int)val == 15 && val2.parameters.Length != 0 && val2.parameters[0] != 2) { val2.recipeId = ((Proto)newRecipe).ID; val2.parameters[0] = 1; } } } } else { BlueprintBuilding[] array2 = buildings; foreach (BlueprintBuilding val4 in array2) { if (val4.recipeId == oldRecipe) { val4.recipeId = ((Proto)newRecipe).ID; } } } if ((int)inspector.usage == 2) { inspector.pasteBuildTool.ResetStates(); } inspector.Refresh(true, true, true, false); } } [HarmonyPatch] public static class UIBlueprintComponentItemPatch { [HarmonyPatch(typeof(UIBlueprintComponentItem), "_OnRegEvent")] [HarmonyPostfix] public static void AddEvent(UIBlueprintComponentItem __instance) { __instance.button.onClick += GetAction(__instance.inspector); } [HarmonyPatch(typeof(UIBlueprintComponentItem), "_OnUnregEvent")] [HarmonyPostfix] public static void RemoveEvent(UIBlueprintComponentItem __instance) { __instance.button.onClick -= GetAction(__instance.inspector); } public static Action GetAction(UIBlueprintInspector inspector) { return OnClick; void OnClick(int itemId) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) UIItemPickerExtension.Popup(new Vector2(-300f, 238f), (Action)delegate(ItemProto proto) { if (proto != null) { SetBuildings(inspector, itemId, proto); } }, (Func)((ItemProto proto) => proto.Upgrades?.Contains(itemId) ?? false)); } } public static void SetBuildings(UIBlueprintInspector inspector, int oldItemId, ItemProto newItem) { //IL_0042: 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_0059: Invalid comparison between Unknown and I4 //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Invalid comparison between Unknown and I4 //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Invalid comparison between Unknown and I4 BlueprintBuilding[] buildings = inspector.blueprint.buildings; foreach (BlueprintBuilding val in buildings) { if (val.itemId == oldItemId) { val.itemId = (short)((Proto)newItem).ID; val.modelIndex = (short)newItem.ModelIndex; } } if ((int)inspector.usage == 0 || (int)inspector.usage == 2) { if ((int)inspector.usage == 2) { inspector.pasteBuildTool.ResetStates(); } } else if ((int)inspector.usage == 1) { _ = ((BuildTool)inspector.copyBuildTool).active; } inspector.Refresh(true, true, true, false); } } [HarmonyPatch] public static class UIBlueprintInspectorPatch { public static Dictionary panelData = new Dictionary(); public static List panelPrefabs = new List(); public static void Init() { if (BlueprintTweaksPlugin.gridControlFeature.Value) { panelPrefabs.Add("assets/blueprinttweaks/ui/panels/grid-size-panel.prefab"); } panelPrefabs.Add("assets/blueprinttweaks/ui/panels/component-panel.prefab#ReformOverride"); panelPrefabs.Add("assets/blueprinttweaks/ui/panels/component-panel.prefab"); if (BlueprintTweaksPlugin.recipeChangeEnabled.Value) { panelPrefabs.Add("assets/blueprinttweaks/ui/panels/recipe-panel.prefab"); } if (BlueprintTweaksPlugin.logisticCargoChangeEnabled.Value) { panelPrefabs.Add("Assets/BlueprintTweaks/UI/panels/transport-panel.prefab"); } if (BlueprintTweaksPlugin.beltHintsChangeEnable.Value) { panelPrefabs.Add("Assets/BlueprintTweaks/UI/panels/hints-group.prefab"); } panelPrefabs.Add("assets/blueprinttweaks/ui/panels/string-copy-panel.prefab"); panelPrefabs.Add("Assets/BlueprintTweaks/UI/panels/keybind-hints-panel.prefab"); } [HarmonyPatch(typeof(UIBlueprintBrowser), "_OnCreate")] [HarmonyPostfix] public static void OnCreateBrowser(UIBlueprintBrowser __instance) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0029: 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_0044: Expected O, but got Unknown //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) RectTransform val = (RectTransform)((Component)__instance).transform; val.sizeDelta = new Vector2(val.sizeDelta.x + 22f, val.sizeDelta.y); RectTransform val2 = (RectTransform)((Transform)val).Find("inspector-group-bg"); val2.sizeDelta = new Vector2(val2.sizeDelta.x + 22f, val2.sizeDelta.y); } [HarmonyPatch(typeof(UIBlueprintInspector), "_OnCreate")] [HarmonyPostfix] public static void OnCreateInspector(UIBlueprintInspector __instance) { //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: 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_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Expected O, but got Unknown if (panelData == null || panelData.ContainsKey(__instance)) { return; } GameObject val = BlueprintTweaksPlugin.resource.bundle.LoadAsset("assets/blueprinttweaks/ui/bp-panel-scroll.prefab"); GameObject val2 = Object.Instantiate(val, (Transform)(object)__instance.rectTrans, false); GameObject gameObject = ((Component)val2.transform.Find("Viewport/pane")).gameObject; ((Transform)__instance.group1).SetParent(gameObject.transform, false); ((Transform)__instance.group2).SetParent(gameObject.transform, false); ((Transform)__instance.group3).SetParent(gameObject.transform, false); ((Transform)__instance.group4).SetParent(gameObject.transform, false); RectTransform rectTrans = __instance.rectTrans; rectTrans.sizeDelta = new Vector2(rectTrans.sizeDelta.x + 16f, rectTrans.sizeDelta.y); UIBlueprintPanel[] array = new UIBlueprintPanel[panelPrefabs.Count]; for (int i = 0; i < panelPrefabs.Count; i++) { string text = panelPrefabs[i]; string text2 = ""; string[] array2 = text.Split(new char[1] { '#' }); if (array2.Length == 2) { text = array2[0]; text2 = array2[1]; } GameObject val3 = BlueprintTweaksPlugin.resource.bundle.LoadAsset(text); GameObject val4 = Object.Instantiate(val3, gameObject.transform, false); UIBlueprintPanel uIBlueprintPanel = val4.GetComponent(); if (text2 == "ReformOverride") { Object.DestroyImmediate((Object)(object)uIBlueprintPanel); uIBlueprintPanel = val4.AddComponent(); } uIBlueprintPanel.Create(__instance); array[i] = uIBlueprintPanel; } ((Component)__instance.group1).transform.SetAsLastSibling(); CustomWindowData value = new CustomWindowData { panels = array, mainPane = (RectTransform)gameObject.transform }; panelData.Add(__instance, value); } [HarmonyPatch(typeof(UIBlueprintInspector), "_OnOpen")] [HarmonyPostfix] public static void OnOpen(UIBlueprintInspector __instance) { if (panelData != null && panelData.ContainsKey(__instance)) { UIBlueprintPanel[] panels = panelData[__instance].panels; UIBlueprintPanel[] array = panels; foreach (UIBlueprintPanel uIBlueprintPanel in array) { uIBlueprintPanel.OnOpen(); } } } [HarmonyPatch(typeof(UIBlueprintInspector), "Refresh")] [HarmonyPostfix] public static void OnRefresh(UIBlueprintInspector __instance, bool refreshComponent) { //IL_0042: 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_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0092: 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) if (panelData == null || !panelData.ContainsKey(__instance)) { return; } UIBlueprintPanel[] panels = panelData[__instance].panels; RectTransform mainPane = panelData[__instance].mainPane; int num = (int)__instance.group1.sizeDelta.y; int num2 = (((int)__instance.usage == 0) ? 18 : 24); int num3 = num + num2; UIBlueprintPanel[] array = panels; foreach (UIBlueprintPanel uIBlueprintPanel in array) { try { uIBlueprintPanel.RefreshUI(); int verticalSize = uIBlueprintPanel.verticalSize; uIBlueprintPanel.panelTrs.anchoredPosition = new Vector2(uIBlueprintPanel.panelTrs.anchoredPosition.x, (float)(-num3)); num3 += verticalSize + num2; ((Component)uIBlueprintPanel).gameObject.SetActive(true); } catch (Exception arg) { ((Component)uIBlueprintPanel).gameObject.SetActive(false); BlueprintTweaksPlugin.logger.LogWarning((object)$"Failed to update {((object)uIBlueprintPanel).GetType().Name}:\n{arg}"); } } __instance.group3.anchoredPosition = new Vector2(__instance.group3.anchoredPosition.x, (float)(-num3)); mainPane.sizeDelta = new Vector2(mainPane.sizeDelta.x, (float)(num3 + 200)); } } [HarmonyPatch] public static class CameraFixPatch { public static bool mode; [HarmonyPatch(typeof(GameCamera), "Logic")] [HarmonyTranspiler] private static IEnumerable FixCamera(IEnumerable instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Expected O, but got Unknown //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(PlayerController), "actionBuild"), (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(PlayerAction_Build), "get_blueprintMode", (Type[])null, (Type[])null), (string)null) }).MatchForward(true, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_4, (object)null, (string)null) }).SetInstruction(Transpilers.EmitDelegate>((Func)(() => (!mode) ? 1 : 4))); return val.InstructionEnumeration(); } [HarmonyPatch(typeof(PlayerMove_Drift), "GameTick")] [HarmonyPatch(typeof(PlayerMove_Fly), "GameTick")] [HarmonyPatch(typeof(PlayerMove_Walk), "GameTick")] [HarmonyTranspiler] private static IEnumerable FixMovement(IEnumerable instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[4] { new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(PlayerController), "actionBuild"), (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(PlayerAction_Build), "get_blueprintMode", (Type[])null, (Type[])null), (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Cgt_Un, (object)null, (string)null) }).Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate>((Func)((bool isBp) => isBp && mode)) }); return val.InstructionEnumeration(); } } public class DragRemoveBuildTool : BuildTool { public bool castTerrain; public bool castGround; public Vector3 castGroundPos = Vector3.zero; public Vector3 castGroundPosSnapped = Vector3.zero; public int castObjectId; public Vector3 castObjectPos; public bool cursorValid; public Vector3 cursorTarget; public Vector3 startGroundPosSnapped = Vector3.zero; public Vector3 lastGroundPosSnapped = Vector3.zero; public BPGratBox selectGratBox = BPGratBox.zero; public BPGratBox lastSelectGratBox = BPGratBox.zero; public BPGratBox selectArcBox = BPGratBox.zero; public HashSet selectObjIds; public BuildPreview[] bpPool; public AnimData[] animPool; public ComputeBuffer animBuffer; public int bpCursor = 1; private int bpPoolCapacity; private int[] bpRecycle; private int bpRecycleCursor; private List _tmp_int_list; public bool isSelecting; private UIMessageBox dismantleQueryBox; private bool waitingForPlayerInput; public int segment => base.planet.aux.activeGrid?.segment ?? 200; public override void _OnInit() { selectObjIds = new HashSet(); SetDisplayPreviewCapacity(256); waitingForPlayerInput = false; } public override void _OnFree() { selectObjIds = null; FreeBuildPreviews(); waitingForPlayerInput = false; } public override void _OnOpen() { //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_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) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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_004b: 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_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) ClearSelection(); ResetBuildPreviews(); castTerrain = false; castGround = false; castGroundPos = Vector3.zero; startGroundPosSnapped = (lastGroundPosSnapped = (castGroundPosSnapped = Vector3.zero)); lastSelectGratBox = (selectGratBox = (selectArcBox = BPGratBox.zero)); castObjectId = 0; castObjectPos = Vector3.zero; cursorValid = false; cursorTarget = Vector3.zero; isSelecting = false; waitingForPlayerInput = false; } public override void _OnClose() { //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_001b: 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_0021: 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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: 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_0032: 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_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) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0047: 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_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) DismantleQueryRemove(); ClearSelection(); ResetBuildPreviews(); startGroundPosSnapped = (lastGroundPosSnapped = (castGroundPosSnapped = Vector3.zero)); lastSelectGratBox = (selectGratBox = (selectArcBox = BPGratBox.zero)); castObjectId = 0; castObjectPos = Vector3.zero; cursorValid = false; cursorTarget = Vector3.zero; waitingForPlayerInput = false; } public override void _OnTick(long time) { UpdateRaycast(); Operating(); if (((BuildTool)this).active) { ((BuildTool)this).UpdatePreviewModels(((BuildTool)this).actionBuild.model); } } public override bool DetermineActive() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) if ((int)((BuildTool)this).actionBuild.blueprintMode != 0) { return false; } if (((BuildTool)this).controller.cmd.mode == -1) { return ((BuildTool)this).actionBuild.dismantleTool.cursorType == 2; } return false; } public void UpdateRaycast() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: 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_001f: 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_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_0373: Unknown result type (might be due to invalid IL or missing references) //IL_036b: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0378: 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_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Invalid comparison between Unknown and I4 //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Invalid comparison between Unknown and I4 //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: 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_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: 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_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00de: 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_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: 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_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: 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_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Invalid comparison between Unknown and I4 //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_0262: 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_0278: Unknown result type (might be due to invalid IL or missing references) //IL_0280: 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_0286: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_028f: Unknown result type (might be due to invalid IL or missing references) //IL_029b: 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_02b6: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Unknown result type (might be due to invalid IL or missing references) //IL_02cc: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Unknown result type (might be due to invalid IL or missing references) //IL_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0198: 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_0333: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_0327: Unknown result type (might be due to invalid IL or missing references) castTerrain = false; castGround = false; castGroundPos = Vector3.zero; castGroundPosSnapped = Vector3.zero; castObjectId = 0; castObjectPos = Vector3.zero; cursorValid = false; cursorTarget = Vector3.zero; if (!VFInput.onGUI && VFInput.inScreen) { RaycastHit val = default(RaycastHit); castGround = Physics.Raycast(base.mouseRay, ref val, 800f, 8720, (QueryTriggerInteraction)2); if (castGround) { Layer val2 = (Layer)((Component)((RaycastHit)(ref val)).collider).gameObject.layer; castTerrain = (int)val2 == 9 || (int)val2 == 4; castGroundPos = (((BuildTool)this).controller.cmd.test = (((BuildTool)this).controller.cmd.target = ((RaycastHit)(ref val)).point)); castGroundPosSnapped = ((BuildTool)this).actionBuild.planetAux.Snap(castGroundPos, castTerrain); castGroundPosSnapped = ((Vector3)(ref castGroundPosSnapped)).normalized * (base.planet.realRadius + 0.2f); ((BuildTool)this).controller.cmd.test = castGroundPosSnapped; Vector3 normalized = ((Vector3)(ref castGroundPosSnapped)).normalized; if (Physics.Raycast(new Ray(castGroundPosSnapped + normalized * 10f, -normalized), ref val, 20f, 8720, (QueryTriggerInteraction)2)) { ((BuildTool)this).controller.cmd.test = ((RaycastHit)(ref val)).point; } cursorTarget = castGroundPosSnapped; cursorValid = true; } int castAllCount = ((BuildTool)this).controller.cmd.raycast.castAllCount; RaycastData[] castAll = ((BuildTool)this).controller.cmd.raycast.castAll; int num = 0; for (int i = 0; i < castAllCount; i++) { if ((int)castAll[i].objType == 0 || (int)castAll[i].objType == 3) { num = (((int)castAll[i].objType == 0) ? castAll[i].objId : (-castAll[i].objId)); break; } } if (num != 0) { castObjectId = num; castObjectPos = ((BuildTool)this).GetObjectPose(num).position; cursorTarget = castObjectPos; ((BuildTool)this).controller.cmd.test = castObjectPos; castGroundPosSnapped = (castGroundPos = castObjectPos); castGroundPosSnapped = ((Vector3)(ref castGroundPosSnapped)).normalized * (base.planet.realRadius + 0.2f); ((BuildTool)this).controller.cmd.test = castGroundPosSnapped; Vector3 normalized2 = ((Vector3)(ref castGroundPosSnapped)).normalized; if (Physics.Raycast(new Ray(castGroundPosSnapped + normalized2 * 10f, -normalized2), ref val, 20f, 8720, (QueryTriggerInteraction)2)) { ((BuildTool)this).controller.cmd.test = ((RaycastHit)(ref val)).point; } cursorTarget = castGroundPosSnapped; cursorValid = true; } } ((BuildTool)this).controller.cmd.state = (cursorValid ? 1 : 0); ((BuildTool)this).controller.cmd.target = (cursorValid ? cursorTarget : Vector3.zero); } public void Operating() { //IL_0050: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0070: 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_007c: 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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: 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_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0157: 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_0130: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: 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_0105: 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_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) if (waitingForPlayerInput) { return; } if (!isSelecting && VFInput.blueprintCopyOperate0.onDown && cursorValid) { isSelecting = true; startGroundPosSnapped = castGroundPosSnapped; lastGroundPosSnapped = startGroundPosSnapped; InitSelectGratBox(); VFInput.UseMouseLeft(); } Vector3 val = castGroundPosSnapped - startGroundPosSnapped; bool flag = ((Vector3)(ref val)).sqrMagnitude > 0.01f; bool flag2 = VFInput.blueprintCopyOperate0.onDown || VFInput.blueprintCopyOperate1.onDown; if (isSelecting && ((flag2 && cursorValid) || (VFInput.blueprintCopyOperate0.onUp && castObjectId != 0 && !flag))) { CheckDismantle(); if (waitingForPlayerInput) { return; } ResetBuildPreviews(); isSelecting = false; VFInput.UseMouseLeft(); VFInput.UseEnterConfirm(); } else if (isSelecting && VFInput.rtsCancel.onUp) { isSelecting = false; startGroundPosSnapped = castGroundPosSnapped; lastGroundPosSnapped = startGroundPosSnapped; ClearSelection(); ResetBuildPreviews(); } if (isSelecting) { DetermineSelectGratBox(); if (lastSelectGratBox != selectGratBox) { DetermineAddSelection(); lastSelectGratBox = selectGratBox; } } else { startGroundPosSnapped = castGroundPosSnapped; ReDeterminePreviews(); } if (flag) { ReDeterminePreviews(); } } public void CheckDismantle() { //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_004c: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: 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) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Expected O, but got Unknown //IL_00ba: Expected O, but got Unknown //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Expected O, but got Unknown //IL_0141: Expected O, but got Unknown //IL_01a8: 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_01be: Expected O, but got Unknown //IL_01be: Expected O, but got Unknown foreach (int selectObjId in selectObjIds) { PrefabDesc prefabDesc = ((BuildTool)this).GetPrefabDesc(selectObjId); if (!BuildTool_Dismantle.showDemolishContainerQuery || selectObjId <= 0) { continue; } EntityData val = base.factory.entityPool[selectObjId]; if (prefabDesc.isStorage) { int storageId = val.storageId; if (!base.factory.factoryStorage.TryTakeBackItems_Storage(((BuildTool)this).player.package, storageId)) { dismantleQueryBox = UIMessageBox.Show(Localization.Translate("拆除储物仓标题"), Localization.Translate("拆除储物仓文字"), Localization.Translate("否"), Localization.Translate("是"), 0, new Response(DismantleQueryCancel), new Response(DismantleQueryConfirm)); waitingForPlayerInput = true; return; } } if (prefabDesc.isTank) { int tankId = val.tankId; if (!base.factory.factoryStorage.TryTakeBackItems_Tank(((BuildTool)this).player.package, tankId)) { dismantleQueryBox = UIMessageBox.Show(Localization.Translate("拆除储液罐标题"), Localization.Translate("拆除储液罐文字"), Localization.Translate("否"), Localization.Translate("是"), 0, new Response(DismantleQueryCancel), new Response(DismantleQueryConfirm)); waitingForPlayerInput = true; return; } } if (prefabDesc.isStation) { int stationId = val.stationId; if (base.factory.transport.stationPool[stationId] != null) { dismantleQueryBox = UIMessageBox.Show(Localization.Translate("拆除物流站标题"), Localization.Translate("拆除物流站文字"), Localization.Translate("否"), Localization.Translate("是"), 0, new Response(DismantleQueryCancel), new Response(DismantleQueryConfirm)); waitingForPlayerInput = true; return; } } } DismantleAction(); } public void DismantleAction() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) RemoveHelper.SwitchDelete(base.factory, selectObjIds.ToList()); VFAudio.Create("demolish-large", (Transform)null, GameMain.mainPlayer.position, true, 5, -1, -1L); ClearSelection(); isSelecting = false; waitingForPlayerInput = false; } public void DismantleQueryCancel() { ClearSelection(); dismantleQueryBox = null; waitingForPlayerInput = false; } public void DismantleQueryConfirm() { DismantleAction(); dismantleQueryBox = null; } public void DismantleQueryRemove() { if ((Object)(object)dismantleQueryBox != (Object)null) { dismantleQueryBox.OnButton1Click(); dismantleQueryBox = null; } waitingForPlayerInput = false; } private void InitSelectGratBox() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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_00be: 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) BlueprintUtils.GetMinimumGratBox(((Vector3)(ref startGroundPosSnapped)).normalized, ref selectGratBox); selectArcBox = selectGratBox; if (selectArcBox.y >= 1.5707864f) { selectArcBox.y = (selectArcBox.w = (float)Math.PI / 2f); selectArcBox.z = selectArcBox.x + (float)Math.PI * 200f; } else if (selectArcBox.y <= -1.5707864f) { selectArcBox.y = (selectArcBox.w = -(float)Math.PI / 2f); selectArcBox.z = selectArcBox.x + (float)Math.PI * 200f; } lastSelectGratBox = selectGratBox; } public void DetermineSelectGratBox() { //IL_0011: 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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_02e9: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) //IL_0317: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Unknown result type (might be due to invalid IL or missing references) if (!cursorValid) { return; } float longitudeRad = BlueprintUtils.GetLongitudeRad(((Vector3)(ref castGroundPosSnapped)).normalized); float longitudeRad2 = BlueprintUtils.GetLongitudeRad(((Vector3)(ref lastGroundPosSnapped)).normalized); float latitudeRad = BlueprintUtils.GetLatitudeRad(((Vector3)(ref castGroundPosSnapped)).normalized); bool flag = latitudeRad >= 1.5707864f || latitudeRad <= -1.5707864f; float num = (flag ? 0f : (longitudeRad - longitudeRad2)); num = Mathf.Repeat(num + (float)Math.PI, (float)Math.PI * 2f) - (float)Math.PI; ((BPGratBox)(ref selectArcBox)).endLongitudeRad = ((BPGratBox)(ref selectArcBox)).endLongitudeRad + num; ((BPGratBox)(ref selectArcBox)).endLatitudeRad = latitudeRad; selectGratBox = selectArcBox; selectGratBox.x = ((selectArcBox.x < selectArcBox.z) ? selectArcBox.x : selectArcBox.z); selectGratBox.z = ((selectArcBox.x > selectArcBox.z) ? selectArcBox.x : selectArcBox.z); if (selectArcBox.x < selectArcBox.z) { if (selectGratBox.z > selectGratBox.x + (float)Math.PI * 2f - 1E-05f - 4E-06f) { selectGratBox.z = selectGratBox.x + (float)Math.PI * 2f - 1E-05f - 4E-06f; } selectGratBox.z = Mathf.Repeat(selectGratBox.z + (float)Math.PI, (float)Math.PI * 2f) - (float)Math.PI; } else { if (selectGratBox.x < selectGratBox.z - (float)Math.PI * 2f + 1E-05f + 4E-06f) { selectGratBox.x = selectGratBox.z - (float)Math.PI * 2f + 1E-05f + 4E-06f; } selectGratBox.x = Mathf.Repeat(selectGratBox.x + (float)Math.PI, (float)Math.PI * 2f) - (float)Math.PI; } selectGratBox.y = ((selectArcBox.y < selectArcBox.w) ? selectArcBox.y : selectArcBox.w); selectGratBox.w = ((selectArcBox.y > selectArcBox.w) ? selectArcBox.y : selectArcBox.w); float num2 = BlueprintUtils.GetLongitudeRadPerGrid((Mathf.Abs(castGroundPosSnapped.y) < Mathf.Abs(startGroundPosSnapped.y)) ? ((Vector3)(ref castGroundPosSnapped)).normalized : ((Vector3)(ref startGroundPosSnapped)).normalized, 200) * 0.33f; ((BPGratBox)(ref selectGratBox)).Extend(num2, 0.002f); if (!flag) { lastGroundPosSnapped = castGroundPosSnapped; } } public void DetermineAddSelection() { //IL_00fb: 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) int num = 200; PlanetData localPlanet = GameMain.localPlanet; object obj; if (localPlanet == null) { obj = null; } else { PlanetAuxData aux = localPlanet.aux; obj = ((aux != null) ? aux.activeGrid : null); } if (obj != null) { num = GameMain.localPlanet.aux.activeGrid.segment; } selectObjIds.Clear(); if (Mathf.Abs(selectArcBox.x - selectArcBox.z) < 0.01f && Mathf.Abs(selectArcBox.y - selectArcBox.w) < 0.01f && castObjectId != 0) { if (ShouldAddObject(castObjectId)) { selectObjIds.Add(castObjectId); } } else { EntityData[] entityPool = base.factory.entityPool; int entityCursor = base.factory.entityCursor; for (int i = 1; i < entityCursor; i++) { int num2 = i; if (entityPool[i].id == i && ((BPGratBox)(ref selectGratBox)).InGratBox(entityPool[i].pos) && ShouldAddObject(num2)) { selectObjIds.Add(num2); } } PrebuildData[] prebuildPool = base.factory.prebuildPool; int prebuildCursor = base.factory.prebuildCursor; for (int j = 1; j < prebuildCursor; j++) { int num3 = -j; if (prebuildPool[j].id == j && ((BPGratBox)(ref selectGratBox)).InGratBox(prebuildPool[j].pos) && ShouldAddObject(num3)) { selectObjIds.Add(num3); } } } DetermineChainSelection(); DetermineMorePreviews(); DeterminePreviews(); } public bool ShouldAddObject(int objId) { PrefabDesc prefabDesc = ((BuildTool)this).GetPrefabDesc(objId); if (prefabDesc.isStation) { return !BlueprintTweaksPlugin.excludeStations.Value; } if (prefabDesc.isInserter) { return ((BuildTool)this).actionBuild.dismantleTool.filterInserter; } if (prefabDesc.isBelt) { return ((BuildTool)this).actionBuild.dismantleTool.filterBelt; } return ((BuildTool)this).actionBuild.dismantleTool.filterFacility; } public void DetermineChainSelection() { if (!VFInput._chainReaction) { return; } if (_tmp_int_list == null) { _tmp_int_list = new List(); } _tmp_int_list.Clear(); bool flag = default(bool); int num2 = default(int); int num3 = default(int); foreach (int selectObjId in selectObjIds) { int num = ((BuildTool)this).GetPrefabDesc(selectObjId).slotPoses.Length; if (num <= 0) { continue; } for (int i = 0; i < num; i++) { base.factory.ReadObjectConn(selectObjId, i, ref flag, ref num2, ref num3); if (num2 != 0) { _tmp_int_list.Add(num2); } } } foreach (int item in _tmp_int_list) { if (ShouldAddObject(item)) { selectObjIds.Add(item); } } _tmp_int_list.Clear(); } public void ClearSelection() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_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_0023: Unknown result type (might be due to invalid IL or missing references) selectObjIds.Clear(); lastSelectGratBox = (selectGratBox = (selectArcBox = BPGratBox.zero)); } public void ReDeterminePreviews() { ResetBuildPreviews(); foreach (int selectObjId in selectObjIds) { BuildPreview buildPreview = GetBuildPreview(selectObjId); AddBPGPUIModel(buildPreview); } if (castObjectId != 0) { BuildPreview buildPreview2 = GetBuildPreview(castObjectId); AddBPGPUIModel(buildPreview2); } SyncAnimBuffer(); base.planet.factoryModel.bpgpuiManager.animBuffer = animBuffer; base.planet.factoryModel.bpgpuiManager.SyncAllGPUBuffer(); } private bool ObjectIsBeltOrInserter(int objId) { if (objId == 0) { return false; } ItemProto val = ((ProtoSet)(object)LDB.items).Select((int)((objId > 0) ? base.factory.entityPool[objId].protoId : base.factory.prebuildPool[-objId].protoId)); if (val != null) { if (!val.prefabDesc.isBelt) { return val.prefabDesc.isInserter; } return true; } return false; } private void DetermineMorePreviews() { //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Invalid comparison between Unknown and I4 HashSet hashSet = new HashSet(); bool flag2 = default(bool); int num = default(int); int num2 = default(int); int num3 = default(int); int num4 = default(int); int num5 = default(int); int num6 = default(int); foreach (int selectObjId in selectObjIds) { PrefabDesc prefabDesc = ((BuildTool)this).GetPrefabDesc(selectObjId); bool isBelt = prefabDesc.isBelt; if (prefabDesc.isInserter) { continue; } if (isBelt) { bool flag = false; for (int i = 0; i < 2; i++) { base.factory.ReadObjectConn(selectObjId, i, ref flag2, ref num, ref num2); if (num != 0 && !ObjectIsBeltOrInserter(num)) { flag = true; break; } } if (flag) { for (int j = 0; j < 16; j++) { base.factory.ReadObjectConn(selectObjId, j, ref flag2, ref num3, ref num2); if (num3 != 0 && !selectObjIds.Contains(num3) && !hashSet.Contains(num3) && ObjectIsBeltOrInserter(num3)) { hashSet.Add(num3); } } } for (int k = 0; k < 4; k++) { base.factory.ReadObjectConn(selectObjId, k, ref flag2, ref num4, ref num2); if (num4 == 0 || !base.factory.ObjectIsBelt(num4) || selectObjIds.Contains(num4) || hashSet.Contains(num4)) { continue; } for (int l = 0; l < 2; l++) { base.factory.ReadObjectConn(num4, l, ref flag2, ref num5, ref num2); if (num5 != 0 && !selectObjIds.Contains(num5) && !hashSet.Contains(num5) && !ObjectIsBeltOrInserter(num5)) { hashSet.Add(num4); break; } } } } else { if ((int)prefabDesc.addonType == 1) { continue; } for (int m = 0; m < 16; m++) { base.factory.ReadObjectConn(selectObjId, m, ref flag2, ref num6, ref num2); if (num6 != 0 && !selectObjIds.Contains(num6) && !hashSet.Contains(num6) && ObjectIsBeltOrInserter(num6)) { hashSet.Add(num6); } } } } selectObjIds.UnionWith(hashSet); } public void DeterminePreviews() { HashSet hashSet = new HashSet(selectObjIds); for (int i = 1; i < bpCursor; i++) { BuildPreview val = bpPool[i]; if (val == null || val.bpgpuiModelId <= 0) { continue; } if (!selectObjIds.Contains(val.objId)) { if (val.bpgpuiModelInstIndex >= 0) { base.planet.factoryModel.bpgpuiManager.RemoveBuildPreviewModel(val.desc.modelIndex, val.bpgpuiModelInstIndex, false); } RemoveBuildPreview(i); } else { hashSet.Remove(val.objId); } } foreach (int item in hashSet) { BuildPreview buildPreview = GetBuildPreview(item); AddBPGPUIModel(buildPreview); } if (castObjectId != 0) { BuildPreview buildPreview2 = GetBuildPreview(castObjectId); AddBPGPUIModel(buildPreview2); } SyncAnimBuffer(); base.planet.factoryModel.bpgpuiManager.animBuffer = animBuffer; base.planet.factoryModel.bpgpuiManager.SyncAllGPUBuffer(); } public override void UpdatePreviewModels(BuildModel model) { //IL_008e: 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_00c0: 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_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) for (int i = 1; i < bpCursor; i++) { BuildPreview val = bpPool[i]; if (val == null || val.bpgpuiModelId <= 0 || !val.isConnNode) { continue; } if (val.objId > 0) { base.factory.cargoTraffic.SetBeltSelected(base.factory.entityPool[val.objId].beltId); } else { uint beltSpeed = (uint)val.desc.beltSpeed; if (val.outputObjId == 0 || val.inputObjId == 0 || val.coverbp != null) { model.connRenderer.AddBlueprintBeltMajorPoint(val.lpos, val.lrot, beltSpeed); } else { model.connRenderer.AddBlueprintBeltPoint(val.lpos, val.lrot, beltSpeed); } } model.connRenderer.AddXSign(val.lpos, val.lrot); } } public void AddBPGPUIModel(BuildPreview preview) { //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_0094: 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_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: 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_00ea: 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_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_022b: 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_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_02ce: Unknown result type (might be due to invalid IL or missing references) //IL_02d4: Unknown result type (might be due to invalid IL or missing references) if (preview == null || preview.bpgpuiModelId <= 0 || !preview.needModel) { return; } ModelProto val = ((ProtoSet)(object)LDB.models).Select(preview.desc.modelIndex); Color32 copyErrorColor = Configs.builtin.copyErrorColor; if (val.RendererType == 2) { bool flag = default(bool); bool flag2 = default(bool); ((BuildTool)this).GetInserterT1T2(preview.objId, ref flag, ref flag2); if (preview.objId > 0) { animPool[preview.bpgpuiModelId] = base.factory.entityAnimPool[preview.objId]; } animPool[preview.bpgpuiModelId].state = (uint)((copyErrorColor.r << 24) + (copyErrorColor.g << 16) + (copyErrorColor.b << 8) + copyErrorColor.a); base.planet.factoryModel.bpgpuiManager.AddBuildPreviewModel(preview.desc.modelIndex, ref preview.bpgpuiModelInstIndex, preview.bpgpuiModelId, preview.lpos, preview.lrot, preview.lpos2, preview.lrot2, flag ? 1 : 0, flag2 ? 1 : 0, false); return; } if (val.RendererType == 3) { bool flag3 = default(bool); int num = default(int); int num2 = default(int); base.factory.ReadObjectConn(preview.objId, 14, ref flag3, ref num, ref num2); if (preview.objId > 0) { animPool[preview.bpgpuiModelId] = base.factory.entityAnimPool[preview.objId]; } animPool[preview.bpgpuiModelId].state = (uint)((copyErrorColor.r << 24) + (copyErrorColor.g << 16) + (copyErrorColor.b << 8) + copyErrorColor.a); base.planet.factoryModel.bpgpuiManager.AddBuildPreviewModel(preview.desc.modelIndex, ref preview.bpgpuiModelInstIndex, preview.bpgpuiModelId, preview.lpos, preview.lrot, (num != 0) ? 1u : 0u, false); return; } if (preview.objId > 0) { animPool[preview.bpgpuiModelId] = base.factory.entityAnimPool[preview.objId]; } animPool[preview.bpgpuiModelId].state = (uint)((copyErrorColor.r << 24) + (copyErrorColor.g << 16) + (copyErrorColor.b << 8) + copyErrorColor.a); if (preview.objId > 0 && preview.desc.isEjector) { animPool[preview.bpgpuiModelId].power = base.factory.factorySystem.ejectorPool[base.factory.entityPool[preview.objId].ejectorId].localDir.z; } base.planet.factoryModel.bpgpuiManager.AddBuildPreviewModel(preview.desc.modelIndex, ref preview.bpgpuiModelInstIndex, preview.bpgpuiModelId, preview.lpos, preview.lrot, false); } public void GeneratePreviewByObjId(BuildPreview preview, int objId) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0032: 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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: 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_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_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0135: 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_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) ItemProto itemProto = ((BuildTool)this).GetItemProto(objId); PrefabDesc prefabDesc = ((BuildTool)this).GetPrefabDesc(objId); if (prefabDesc == null || itemProto == null) { preview.ResetAll(); return; } Pose objectPose = ((BuildTool)this).GetObjectPose(objId); Pose val = (prefabDesc.isInserter ? ((BuildTool)this).GetObjectPose2(objId) : objectPose); preview.item = itemProto; preview.desc = prefabDesc; preview.lpos = objectPose.position; preview.lrot = objectPose.rotation; preview.lpos2 = objectPose.position; preview.lrot2 = objectPose.rotation; preview.objId = objId; preview.genNearColliderArea2 = 0f; if (preview.desc.lodCount > 0 && preview.desc.lodMeshes != null && (Object)(object)preview.desc.lodMeshes[0] != (Object)null) { preview.needModel = true; } else { preview.needModel = false; } preview.isConnNode = prefabDesc.isBelt; if (prefabDesc.isBelt) { bool flag = default(bool); int num = default(int); int num2 = default(int); for (int i = 0; i < 4; i++) { base.factory.ReadObjectConn(objId, i, ref flag, ref num, ref num2); if (num != 0) { if (flag) { preview.outputObjId = num; } else if (preview.inputObjId == 0) { preview.inputObjId = num; } else { preview.coverbp = preview; } } } } if (prefabDesc.isInserter) { preview.lpos2 = val.position; preview.lrot2 = val.rotation; } } public void ResetBuildPreviews() { if (base.planet != null && (Object)(object)base.planet.factoryModel != (Object)null && base.planet.factoryModel.bpgpuiManager != null) { base.planet.factoryModel.bpgpuiManager.Reset(); } for (int i = 0; i < bpPool.Length; i++) { if (bpPool[i] != null) { bpPool[i].ResetAll(); } } Array.Clear(animPool, 0, bpPoolCapacity); Array.Clear(bpRecycle, 0, bpPoolCapacity); bpCursor = 1; bpRecycleCursor = 0; animBuffer.SetData((Array)animPool); } public void FreeBuildPreviews() { if (base.planet != null && (Object)(object)base.planet.factoryModel != (Object)null && base.planet.factoryModel.bpgpuiManager != null) { base.planet.factoryModel.bpgpuiManager.Reset(); } for (int i = 0; i < bpPool.Length; i++) { if (bpPool[i] != null) { bpPool[i].Free(); bpPool[i] = null; } } animPool = null; bpPool = null; bpCursor = 1; bpPoolCapacity = 0; bpRecycle = null; bpRecycleCursor = 0; if (animBuffer != null) { animBuffer.Release(); animBuffer = null; } } private void SetDisplayPreviewCapacity(int newCapacity) { //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Expected O, but got Unknown BuildPreview[] array = bpPool; AnimData[] sourceArray = animPool; bpPool = (BuildPreview[])(object)new BuildPreview[newCapacity]; animPool = (AnimData[])(object)new AnimData[newCapacity]; bpRecycle = new int[newCapacity]; if (array != null) { Array.Copy(array, bpPool, (newCapacity > bpPoolCapacity) ? bpPoolCapacity : newCapacity); Array.Copy(sourceArray, animPool, (newCapacity > bpPoolCapacity) ? bpPoolCapacity : newCapacity); } bpPoolCapacity = newCapacity; ComputeBuffer obj = animBuffer; if (obj != null) { obj.Release(); } animBuffer = new ComputeBuffer(newCapacity, 20, (ComputeBufferType)0); } public void RemoveBuildPreview(int id) { if (bpPool[id] != null && bpPool[id].bpgpuiModelInstIndex >= 0) { animPool[id].time = 0f; animPool[id].prepare_length = 0f; animPool[id].working_length = 0f; animPool[id].state = 0u; animPool[id].power = 0f; bpPool[id].ResetAll(); int[] array = bpRecycle; array[bpRecycleCursor++] = id; } } public BuildPreview GetBuildPreview(int objId) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Expected O, but got Unknown if (bpRecycleCursor > 0) { int[] array = bpRecycle; int num = array[--bpRecycleCursor]; BuildPreview val = bpPool[num]; if (val == null) { val = new BuildPreview(); bpPool[num] = val; } GeneratePreviewByObjId(val, objId); animPool[num] = default(AnimData); val.previewIndex = num; val.bpgpuiModelId = num; return val; } int num2 = bpCursor++; if (num2 == bpPoolCapacity) { SetDisplayPreviewCapacity(bpPoolCapacity * 2); } BuildPreview val2 = bpPool[num2]; if (val2 == null) { val2 = new BuildPreview(); bpPool[num2] = val2; } GeneratePreviewByObjId(val2, objId); animPool[num2] = default(AnimData); val2.previewIndex = num2; val2.bpgpuiModelId = num2; return val2; } public void SyncAnimBuffer() { ComputeBuffer obj = animBuffer; if (obj != null) { obj.SetData((Array)animPool); } } public override void EscLogic() { //IL_001a: 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) bool flag = !VFInput.onGUI && VFInput.inScreen && !VFInput.inputing; bool flag2 = VFInput.escKey.onDown || VFInput.escape; bool flag3 = !VFInput._godModeMechaMove && VFInput.rtsCancel.onDown && flag; if (flag3 || flag2) { ((BuildTool)this).player.SetHandItems(0, 0, 0); ((BuildTool)this)._Close(); ((BuildTool)this).actionBuild.Close(); } if (flag2) { VFInput.UseEscape(); } if (flag3) { VFInput.UseMouseRight(); } } } [RegisterPatch("DragRemove")] public static class BuildToolDismantlePatch { [HarmonyPatch(typeof(BuildTool_Dismantle), "DetermineActive")] [HarmonyPrefix] public static bool CheckActive(BuildTool_Dismantle __instance, ref bool __result) { if (__instance.cursorType != 2) { return true; } __result = false; return false; } [HarmonyPatch(typeof(BuildTool_Dismantle), "_OnClose")] [HarmonyPrefix] public static void OnCloseBefore(BuildTool_Dismantle __instance, ref int __state) { __state = __instance.cursorType; } [HarmonyPatch(typeof(BuildTool_Dismantle), "_OnClose")] [HarmonyPostfix] public static void OnCloseAfter(BuildTool_Dismantle __instance, int __state) { if (__state == 2) { __instance.cursorType = 2; } } } [RegisterPatch("DragRemove")] public static class PlayerAction_BuildPatch { [HarmonyPatch(typeof(PlayerAction_Build), "Init")] [HarmonyPostfix] public static void InitTool(PlayerAction_Build __instance) { BuildTool[] tools = __instance.tools; BuildTool[] array = (BuildTool[])(object)new BuildTool[tools.Length + 1]; tools.CopyTo(array, 0); BlueprintTweaksPlugin.tool = new DragRemoveBuildTool(); array[^1] = (BuildTool)(object)BlueprintTweaksPlugin.tool; __instance.tools = array; } } [RegisterPatch("DragRemove")] public static class UIBuildingGridPatch2 { private static readonly int cursorGratBox = Shader.PropertyToID("_CursorGratBox"); private static readonly int zMin = Shader.PropertyToID("_ZMin"); private static readonly int tintColor = Shader.PropertyToID("_TintColor"); private static readonly int reformMode = Shader.PropertyToID("_ReformMode"); [HarmonyPatch(typeof(UIBuildingGrid), "Update")] [HarmonyPriority(0)] [HarmonyPostfix] public static void UpdateGrid(UIBuildingGrid __instance) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Invalid comparison between Unknown and I4 //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) Player mainPlayer = GameMain.mainPlayer; PlanetFactory val = GameMain.localPlanet?.factory; if (val != null && (int)GameMain.localPlanet.type != 5) { PlayerAction_Build val2 = ((mainPlayer != null) ? mainPlayer.controller.actionBuild : null); if (val2 != null && (int)val2.blueprintMode == 0 && ((BuildTool)BlueprintTweaksPlugin.tool).active && BlueprintTweaksPlugin.tool.isSelecting) { __instance.material.SetColor(tintColor, __instance.dismantleColor); __instance.material.SetFloat(reformMode, 0f); __instance.material.SetFloat(zMin, -0.5f); __instance.material.SetVector(cursorGratBox, (Vector4)BlueprintTweaksPlugin.tool.selectGratBox); } } } } [RegisterPatch("DragRemove")] public static class UIBuildMenuPatch { public static UIButton dragSelectButton; public static UIBuildMenu menu; [HarmonyPatch(typeof(UIBuildMenu), "_OnCreate")] [HarmonyPostfix] public static void AddUIButton(UIBuildMenu __instance) { //IL_0034: 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) menu = __instance; GameObject val = BlueprintTweaksPlugin.resource.bundle.LoadAsset("Assets/BlueprintTweaks/UI/drag-remove-button.prefab"); GameObject val2 = Object.Instantiate(val, __instance.uxGroup.transform, false); ((RectTransform)val2.transform).anchoredPosition = new Vector2(-78f, 11f); val2.SetActive(false); dragSelectButton = val2.GetComponent(); dragSelectButton.onClick += OnDragSelectClick; } [HarmonyPatch(typeof(UIBuildMenu), "UpdateUXPanel")] [HarmonyPostfix] public static void UpdateUI(UIBuildMenu __instance) { ((Component)dragSelectButton).gameObject.SetActive(__instance.isDismantleMode); dragSelectButton.highlighted = __instance.dismantleTool.cursorType == 2; } [HarmonyPatch(typeof(UIBuildMenu), "UpdateUXPanelHotKey")] [HarmonyPostfix] public static void UpdateHotKeys(UIBuildMenu __instance) { if (__instance.isDismantleMode && Input.GetKeyDown((KeyCode)284)) { OnDragSelectClick(0); } } private static void OnDragSelectClick(int obj) { if (menu.isDismantleMode) { menu.dismantleTool.cursorType = 2; } menu.UpdateUXPanel(); } } [RegisterPatch("DragRemove")] public static class RemoveHelper { public static bool excludeStationOverride; public static bool ShouldExcludeStations { get { if (!excludeStationOverride) { return BlueprintTweaksPlugin.excludeStations.Value; } return true; } } private static void GenerateUndoData(PlanetFactory factory, List targetIds) { //IL_0053: 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_0075: Unknown result type (might be due to invalid IL or missing references) if (NebulaModAPI.IsMultiplayerActive && NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient) { return; } try { List objectIds = targetIds.Where(delegate(int objId) { if (objId < 0) { int modelIndex = factory.prebuildPool[-objId].modelIndex; ModelProto val2 = ((ProtoSet)(object)LDB.models).Select(modelIndex); if (val2 == null) { return false; } if (val2.prefabDesc.isStation) { return !ShouldExcludeStations; } return true; } if (objId > 0) { int modelIndex2 = factory.entityPool[objId].modelIndex; ModelProto val3 = ((ProtoSet)(object)LDB.models).Select(modelIndex2); if (val3 == null) { return false; } if (val3.prefabDesc.isStation) { return !ShouldExcludeStations; } return true; } return false; }).ToList(); Vector3 position; BlueprintData val = UndoUtils.GenerateBlueprint(objectIds, out position); if (val.buildings.Length != 0 && !((Vector3)(ref position)).Equals(Vector3.zero)) { PlayerUndo currentPlayerData = UndoManager.GetCurrentPlayerData(); currentPlayerData.AddUndoItem(new UndoDismantle(currentPlayerData, objectIds, val, (Vector3[])(object)new Vector3[1] { position }, 0f)); } } catch (Exception ex) { BlueprintTweaksPlugin.logger.LogWarning((object)("Failed to generate undo for drag dismantle: " + ex.Message + ", stacktrace:\n" + ex.StackTrace)); } } public static void SwitchDelete(PlanetFactory factory, List objectIds) { if (objectIds.Count <= 0) { return; } if (NebulaModAPI.IsMultiplayerActive) { IMultiplayerSession multiplayerSession = NebulaModAPI.MultiplayerSession; int planetId = ((multiplayerSession.Factories.TargetPlanet != -2) ? multiplayerSession.Factories.TargetPlanet : (factory.planet?.id ?? (-1))); if (multiplayerSession.LocalPlayer.IsHost || !multiplayerSession.Factories.IsIncomingRequest.Value) { multiplayerSession.Network.SendPacket(new RemoveRequestPacket(planetId, objectIds.ToArray(), Array.Empty(), (multiplayerSession.Factories.PacketAuthor == -1) ? multiplayerSession.LocalPlayer.Id : multiplayerSession.Factories.PacketAuthor, variant: false, ShouldExcludeStations)); } if (!multiplayerSession.LocalPlayer.IsHost && !multiplayerSession.Factories.IsIncomingRequest.Value) { return; } } RegularDeleteEntities(factory, objectIds); } public static void RegularDeleteEntities(PlanetFactory factory, List targetIds) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown Player mainPlayer = GameMain.mainPlayer; PlayerAction_Build actionBuild = mainPlayer.controller.actionBuild; using (UndoManager.IgnoreAllEvents.On()) { HighStopwatch val = new HighStopwatch(); val.Begin(); foreach (int targetId in targetIds) { try { if (!((BuildTool)actionBuild.noneTool).GetPrefabDesc(targetId).isStation || !ShouldExcludeStations) { DoDismantleObject(actionBuild, targetId); } } catch (Exception ex) { BlueprintTweaksPlugin.logger.LogWarning((object)$"Error while dismantling entity {targetId}, message: {ex.Message}, stacktrace:\n{ex.StackTrace}"); } } double duration = val.duration; BlueprintTweaksPlugin.logger.LogDebug((object)$"Took {duration} s to delete entities"); } } [HarmonyPatch(typeof(PlayerAction_Build), "DoDismantleObject")] [HarmonyReversePatch(/*Could not decode attribute arguments.*/)] public static bool DoDismantleObject(PlayerAction_Build instance, int objId) { return true; } } public enum MajorAxis { XAXIS, ZAXIS } [HarmonyPatch] public static class BlueprintUtilsPatch2 { public delegate float RefAction(ref Vector4 area, ref float latValueOut, bool longAxis, bool latAxis, float yaw); public delegate void RectRefAction(ref float xPos, ref float yPos, int yawCount); public delegate float MirrorFunc(ref Vector4 area, bool longAxis, int yawCount); public delegate float ApplyFunc(float value, int yawCount); public static bool mirrorLat; public static bool mirrorLong; public static Dictionary buildingsAxis = new Dictionary(); public static Dictionary buildingsOffsets = new Dictionary(); public static void Init() { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0066: 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_00a9: Unknown result type (might be due to invalid IL or missing references) buildingsAxis.Add(52, MajorAxis.XAXIS); buildingsAxis.Add(121, MajorAxis.XAXIS); buildingsAxis.Add(64, MajorAxis.XAXIS); buildingsOffsets.Add(64, new Vector2(0f, -1f)); buildingsAxis.Add(376, MajorAxis.XAXIS); buildingsOffsets.Add(376, new Vector2(0f, -1f)); buildingsAxis.Add(69, MajorAxis.XAXIS); buildingsOffsets.Add(54, new Vector2(-1f, 0f)); buildingsOffsets.Add(118, new Vector2(-1f, 0f)); } public static void UpdateBlueprintDisplay() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Invalid comparison between Unknown and I4 Player mainPlayer = GameMain.mainPlayer; if (!((Object)(object)((mainPlayer != null) ? mainPlayer.controller : null) == (Object)null) && (int)GameMain.mainPlayer.controller.actionBuild.blueprintMode == 2) { GameMain.mainPlayer.controller.actionBuild.blueprintPasteTool.ForceDetermineBP(); } } [HarmonyPatch(typeof(BuildTool_BlueprintPaste), "_OnClose")] [HarmonyPrefix] public static void Close() { if (BlueprintTweaksPlugin.resetFunctionsOnMenuExit.Value) { mirrorLat = false; mirrorLong = false; } } [HarmonyPatch(typeof(BlueprintUtils), "TransitionWidthAndHeight")] [HarmonyPrefix] public static void MirrorObjects(float _yaw, ref float _width, ref float _height) { if (mirrorLat) { _width *= -1f; } if (mirrorLong) { _height *= -1f; } } public static void MirrorReformRect(ref float xPos, ref float yPos, int yawCount) { if (mirrorLat) { if (yawCount == 1 || yawCount == 3) { yPos *= -1f; } else { xPos *= -1f; } } if (mirrorLong) { if (yawCount == 1 || yawCount == 3) { xPos *= -1f; } else { yPos *= -1f; } } } public static float ApplyMirrorLat(float latValue, int yawCount) { if (!mirrorLong && !mirrorLat) { return latValue; } if (mirrorLong && mirrorLat) { return latValue * -1f; } if (yawCount == 1 || yawCount == 3) { if (!mirrorLong) { return latValue * -1f; } return latValue; } if (!mirrorLong) { return latValue; } return latValue * -1f; } public static float ApplyMirrorLong(float longValue, int yawCount) { if (!mirrorLong && !mirrorLat) { return longValue; } if (mirrorLong && mirrorLat) { return longValue * -1f; } if (yawCount == 1 || yawCount == 3) { if (!mirrorLat) { return longValue * -1f; } return longValue; } if (!mirrorLat) { return longValue; } return longValue * -1f; } public static float MirrorRotation(float yaw) { if (mirrorLat && mirrorLong) { return yaw + 180f; } if (mirrorLat) { return 0f - yaw; } if (mirrorLong) { return 0f - yaw + 180f; } return yaw; } public static float MirrorAreaLong(ref Vector4 area, bool longAxis, int yawCount) { if (mirrorLat && yawCount != 1 && yawCount != 3) { longAxis = !longAxis; } if (mirrorLong && (yawCount == 1 || yawCount == 3)) { longAxis = !longAxis; } if (!longAxis) { return area.x; } return area.z; } public static float MirrorAreaLat(ref Vector4 area, bool latAxis, int yawCount) { if (mirrorLat && (yawCount == 1 || yawCount == 3)) { latAxis = !latAxis; } if (mirrorLong && yawCount != 1 && yawCount != 3) { latAxis = !latAxis; } if (!latAxis) { return area.y; } return area.w; } public static float MirrorArea(ref Vector4 area, ref float latValueOut, bool longAxis, bool latAxis, float yaw) { int num = Mathf.FloorToInt(yaw / 90f); if (mirrorLat) { if (num == 1 || num == 3) { latAxis = !latAxis; } else { longAxis = !longAxis; } } if (mirrorLong) { if (num == 1 || num == 3) { longAxis = !longAxis; } else { latAxis = !latAxis; } } float result = (longAxis ? area.z : area.x); latValueOut = (latAxis ? area.w : area.y); return result; } [HarmonyPatch(typeof(BlueprintUtils), "RefreshBuildPreview")] [HarmonyTranspiler] private static IEnumerable RefreshPreviews(IEnumerable instructions, ILGenerator generator) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, generator); val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(Mathf), "FloorToInt", (Type[])null, (Type[])null), (string)null) }).Advance(1); object operand = val.Operand; RefreshPreviewsPatchStepReformMirror(val, operand); RefreshPreviewsPatchStep1(val, operand); RefreshPreviewsPatchStep2(val); RefreshPreviewsPatchStep3(val); RefreshPreviewsPatchStep4(val); RefreshPreviewsPatchStep3b(val); RefreshPreviewsPatchStep4b(val); RefreshPreviewsPatchStep5(val); return val.InstructionEnumeration(); } private static void RefreshPreviewsPatchStepReformMirror(CodeMatcher matcher, object yawCountVar) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Expected O, but got Unknown //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Expected O, but got Unknown //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Expected O, but got Unknown //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Expected O, but got Unknown //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Expected O, but got Unknown //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Expected O, but got Unknown //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Expected O, but got Unknown //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Expected O, but got Unknown //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Expected O, but got Unknown //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Expected O, but got Unknown //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Expected O, but got Unknown //IL_02c1: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Expected O, but got Unknown //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_0327: Expected O, but got Unknown //IL_033b: Unknown result type (might be due to invalid IL or missing references) //IL_0341: Expected O, but got Unknown //IL_0354: Unknown result type (might be due to invalid IL or missing references) //IL_035a: Expected O, but got Unknown //IL_0395: Unknown result type (might be due to invalid IL or missing references) //IL_039b: Expected O, but got Unknown //IL_03a9: Unknown result type (might be due to invalid IL or missing references) //IL_03af: Expected O, but got Unknown //IL_03d5: Unknown result type (might be due to invalid IL or missing references) //IL_03db: Expected O, but got Unknown //IL_03f0: Unknown result type (might be due to invalid IL or missing references) //IL_03f6: Expected O, but got Unknown matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(BPReformRect), "y"), (string)null) }); while (matcher.Opcode != OpCodes.Stloc_S) { matcher.Advance(1); } object operand = matcher.Operand; matcher.Advance(1); while (matcher.Opcode != OpCodes.Stloc_S) { matcher.Advance(1); } object operand2 = matcher.Operand; matcher.MatchForward(true, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldelema, (object)typeof(Vector4), (string)null), new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null) }); matcher.Advance(-1); object operand3 = matcher.Operand; matcher.Advance(1); object operand4 = matcher.Operand; for (int i = 0; i < 2; i++) { while (matcher.Opcode != OpCodes.Ldfld) { matcher.RemoveInstruction(); } matcher.RemoveInstruction(); } matcher.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, operand3) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, operand4) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, yawCountVar) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate((MirrorFunc)MirrorAreaLat) }); matcher.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloca_S, operand) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloca_S, operand2) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, yawCountVar) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate((RectRefAction)MirrorReformRect) }); matcher.MatchForward(true, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null) }); object operand5 = matcher.Operand; matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ldloc_S, operand5, (string)null) }); matcher.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, yawCountVar) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate((ApplyFunc)ApplyMirrorLat) }); matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ldloc_S, operand3, (string)null) }).Advance(-2); object operand6 = matcher.Operand; for (int j = 0; j < 2; j++) { while (matcher.Opcode != OpCodes.Ldfld) { matcher.RemoveInstruction(); } matcher.RemoveInstruction(); } matcher.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, operand3) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, operand6) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, yawCountVar) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate((MirrorFunc)MirrorAreaLong) }); matcher.MatchForward(true, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null) }); object operand7 = matcher.Operand; matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ldloc_S, operand7, (string)null) }); matcher.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, yawCountVar) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate((ApplyFunc)ApplyMirrorLong) }); } private static void RefreshPreviewsPatchStep1(CodeMatcher matcher, object yawCountVar) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Expected O, but got Unknown //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Expected O, but got Unknown //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Expected O, but got Unknown //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Expected O, but got Unknown //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Expected O, but got Unknown //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Expected O, but got Unknown //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Expected O, but got Unknown matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(BuildPreview), "bpgpuiModelId"), (string)null) }); matcher.MatchForward(true, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldelema, (object)typeof(Vector4), (string)null), new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null) }); matcher.Advance(-1); object operand = matcher.Operand; matcher.Advance(1); object operand2 = matcher.Operand; for (int i = 0; i < 2; i++) { while (matcher.Opcode != OpCodes.Ldfld) { matcher.RemoveInstruction(); } matcher.RemoveInstruction(); } object operand3 = matcher.Operand; while (matcher.Opcode != OpCodes.Stloc_S) { matcher.RemoveInstruction(); } object operand4 = matcher.Operand; matcher.RemoveInstruction().InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, operand) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, operand2) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, yawCountVar) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate((MirrorFunc)MirrorAreaLong) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, operand) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, operand3) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, yawCountVar) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate((MirrorFunc)MirrorAreaLat) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Stloc_S, operand4) }); } private static void RefreshPreviewsPatchStep2(CodeMatcher matcher) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(BlueprintUtils), "TransitionWidthAndHeight", (Type[])null, (Type[])null), (string)null) }).Advance(-3).RemoveInstruction() .RemoveInstruction() .RemoveInstruction() .SetInstruction(Transpilers.EmitDelegate>((Func)delegate(float yaw, BlueprintBuilding building) { //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0047: 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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: 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_007d: Unknown result type (might be due to invalid IL or missing references) float num = building.localOffset_x; float num2 = building.localOffset_y; if (((mirrorLat && !mirrorLong) || (!mirrorLat && mirrorLong)) && buildingsOffsets.ContainsKey(building.modelIndex)) { Vector2 v = buildingsOffsets[building.modelIndex]; float num3 = MirrorBuildingRotation(building.yaw, building); v = v.Rotate(num3 + (float)(mirrorLong ? 180 : 0)); num += v.x; num2 += v.y; } return BlueprintUtils.TransitionWidthAndHeight(yaw, num, num2); })); } private static void RefreshPreviewsPatchStep3(CodeMatcher matcher) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(BlueprintBuilding), "yaw"), (string)null) }).Advance(-1); object operand = matcher.Operand; matcher.Advance(2).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, operand) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate>((Func)MirrorBuildingRotation) }) .Advance(2); } private static void RefreshPreviewsPatchStep4(CodeMatcher matcher) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(BlueprintBuilding), "yaw2"), (string)null) }).Advance(-1); object operand = matcher.Operand; matcher.Advance(2).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, operand) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate>((Func)MirrorBuildingRotation) }); } private static void RefreshPreviewsPatchStep3b(CodeMatcher matcher) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(BlueprintBuilding), "yaw"), (string)null) }).Advance(-1); object operand = matcher.Operand; matcher.Advance(2).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, operand) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate>((Func)MirrorBuildingRotation) }) .Advance(2); } private static void RefreshPreviewsPatchStep4b(CodeMatcher matcher) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(BlueprintBuilding), "yaw2"), (string)null) }).Advance(-1); object operand = matcher.Operand; matcher.Advance(2).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, operand) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate>((Func)MirrorBuildingRotation) }); } private static void RefreshPreviewsPatchStep5(CodeMatcher matcher) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Expected O, but got Unknown //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Expected O, but got Unknown //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Expected O, but got Unknown matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(BlueprintBuilding), "index"), (string)null) }); object operand = matcher.Operand; matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(BuildPreview), "desc"), (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(PrefabDesc), "isInserter"), (string)null) }).Advance(-1); object operand2 = matcher.Operand; matcher.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, operand2) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_S, operand) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate>((Action)delegate(BuildPreview preview, BlueprintBuilding building) { if (preview.desc.isInserter) { EntityInputsAndOutputs(preview, useSlots: true); } if (preview.desc.isBelt) { EntityInputsAndOutputs(preview, useSlots: false); } if (preview.desc.isStation) { MirrorStationData(preview, building); } }) }); } public static float MirrorBuildingRotation(float yaw, BlueprintBuilding building) { if (buildingsAxis.ContainsKey(building.modelIndex) && buildingsAxis[building.modelIndex] == MajorAxis.XAXIS) { return MirrorRotation(yaw + 90f) - 90f; } return MirrorRotation(yaw); } private static Pose[] GetSlotsOrPorts(this PrefabDesc desc, bool useSlots) { if (!useSlots) { return desc.portPoses; } return desc.slotPoses; } private static void EntityInputsAndOutputs(BuildPreview preview, bool useSlots) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: 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_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0169: 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_0179: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: 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_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: 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_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_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: 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_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) Vector3 val4; if (preview.input != null && !preview.input.desc.isBelt && !preview.input.desc.isInserter && preview.inputFromSlot < preview.input.desc.GetSlotsOrPorts(useSlots).Length) { Quaternion val = Quaternion.Inverse(preview.input.lrot); Vector3 val2 = preview.lpos - preview.input.lpos; val2 = val * val2; Quaternion value = val * preview.lrot; Pose[] slotsOrPorts = preview.input.desc.GetSlotsOrPorts(useSlots); for (int i = 0; i < slotsOrPorts.Length; i++) { Pose val3 = slotsOrPorts[i]; val4 = val3.position - val2; if (((Vector3)(ref val4)).sqrMagnitude < 0.1f && val3.rotation.Approximately(value)) { if (preview.inputFromSlot != i) { preview.inputFromSlot = i; } break; } } } if (preview.output == null || preview.output.desc.isBelt || preview.output.desc.isInserter || preview.outputToSlot >= preview.output.desc.GetSlotsOrPorts(useSlots).Length) { return; } Quaternion val5 = Quaternion.Inverse(preview.output.lrot); Vector3 val6 = preview.lpos2 - preview.output.lpos; val6 = val5 * val6; Quaternion value2 = val5 * (preview.lrot2 * Quaternion.Euler(0f, -180f, 0f)); Pose[] slotsOrPorts2 = preview.output.desc.GetSlotsOrPorts(useSlots); for (int j = 0; j < slotsOrPorts2.Length; j++) { Pose val7 = slotsOrPorts2[j]; val4 = val7.position - val6; if (((Vector3)(ref val4)).sqrMagnitude < 0.1f && val7.rotation.Approximately(value2)) { if (preview.outputToSlot != j) { preview.outputToSlot = j; } break; } } } public static Vector2 RotateXZ(Vector3 inVec, float angleRad) { //IL_0000: 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_001c: 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_003a: Unknown result type (might be due to invalid IL or missing references) float num = inVec.x * Mathf.Cos(angleRad) - inVec.z * Mathf.Sin(angleRad); float num2 = inVec.x * Mathf.Sin(angleRad) + inVec.z * Mathf.Cos(angleRad); return new Vector2(num, num2); } private static void MirrorStationData(BuildPreview preview, BlueprintBuilding building) { //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0163: 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) //IL_016a: Unknown result type (might be due to invalid IL or missing references) if (preview.desc.isCollectStation || building.parameters == null || building.parameters.Length == 0) { return; } if (!mirrorLat && !mirrorLong) { for (int i = 0; i < preview.desc.portPoses.Length; i++) { int num = 192 + i * 4; preview.parameters[num] = building.parameters[num]; preview.parameters[num + 1] = building.parameters[num + 1]; } return; } float num2 = MirrorBuildingRotation(building.yaw, building); float angleRad = building.yaw * ((float)Math.PI / 180f); bool flag = mirrorLat; bool flag2 = mirrorLong; float num3 = Mathf.Abs(Mathf.DeltaAngle(building.yaw, num2)); if (num3 == 180f) { flag = !mirrorLat; flag2 = !mirrorLong; } Vector2 val2 = default(Vector2); for (int j = 0; j < preview.desc.portPoses.Length; j++) { Vector3 position = preview.desc.portPoses[j].position; Vector2 val = RotateXZ(position, angleRad); int num4 = 192 + j * 4; ((Vector2)(ref val2))..ctor(flag ? (0f - val.x) : val.x, flag2 ? (0f - val.y) : val.y); for (int k = 0; k < preview.desc.portPoses.Length; k++) { Vector3 position2 = preview.desc.portPoses[k].position; Vector2 val3 = RotateXZ(position2, angleRad); Vector2 val4 = val2 - val3; if (((Vector2)(ref val4)).sqrMagnitude < 0.1f) { int num5 = 192 + k * 4; preview.parameters[num4] = building.parameters[num5]; preview.parameters[num4 + 1] = building.parameters[num5 + 1]; } } } } } public class GridData { public bool shouldShap; public Vector2 snapGrid = new Vector2(1f, 1f); public Vector2 snapOffset = Vector2.zero; } [HarmonyPatch] public static class GridSnappingPatches { public static float lockLongitude; public static float lockLatitude; public static bool isLockedLongitude; public static bool isLockedLatitude; public static GridData currentGridData = new GridData(); public static Vector3 GetGroundCastPos() { //IL_0007: 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_0040: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) if (GameMain.mainPlayer == null) { return Vector3.zero; } BuildTool activeTool = GameMain.mainPlayer.controller.actionBuild.activeTool; if (activeTool == null || VFInput.onGUI || !VFInput.inScreen) { return Vector3.zero; } int num = 8720; RaycastHit val = default(RaycastHit); if (!Physics.Raycast(activeTool.mouseRay, ref val, 800f, num, (QueryTriggerInteraction)2)) { return Vector3.zero; } return ((RaycastHit)(ref val)).point; } public static void LockLongitude() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) if (!isLockedLongitude) { Vector3 groundCastPos = GetGroundCastPos(); if (!((Vector3)(ref groundCastPos)).Equals(Vector3.zero)) { BlueprintUtils.GetLongitudeLatitudeRad(((Vector3)(ref groundCastPos)).normalized, ref lockLongitude, ref lockLatitude); isLockedLongitude = true; isLockedLatitude = false; } } else { isLockedLongitude = false; } } public static void LockLatitude() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) if (!isLockedLatitude) { Vector3 groundCastPos = GetGroundCastPos(); if (!((Vector3)(ref groundCastPos)).Equals(Vector3.zero)) { BlueprintUtils.GetLongitudeLatitudeRad(((Vector3)(ref groundCastPos)).normalized, ref lockLongitude, ref lockLatitude); isLockedLatitude = true; isLockedLongitude = false; } } else { isLockedLatitude = false; } } public static void SetOffset() { //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_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) if (currentGridData.shouldShap) { currentGridData.shouldShap = false; } else if (GameMain.localPlanet.aux != null) { Vector3 groundCastPos = GetGroundCastPos(); if (!((Vector3)(ref groundCastPos)).Equals(Vector3.zero)) { BlueprintUtils.GetLongitudeLatitudeRad(((Vector3)(ref groundCastPos)).normalized, ref lockLongitude, ref lockLatitude); currentGridData.shouldShap = true; GameMain.localPlanet.aux.CalculateOffset(groundCastPos, currentGridData); } } } public static Vector3 SnapModified(this PlanetAuxData auxData, Vector3 pos, bool onTerrain) { //IL_009a: 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_0028: 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_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0093: 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) if (auxData.activeGridIndex < auxData.customGrids.Count) { Vector3 val = auxData.customGrids[auxData.activeGridIndex].SnapModifiedInternal(pos); float num = auxData.planet.realRadius + 0.2f; if (!onTerrain) { num = Mathf.Max(auxData.planet.radius, Mathf.Floor((float)(((double)((Vector3)(ref pos)).magnitude - (double)auxData.planet.radius) / 1.33333325386047)) * 1.333333f + auxData.planet.radius) + 0.2f; } pos = val * num; } return pos; } public static Vector3 SnapModifiedInternal(this PlanetGrid grid, Vector3 pos) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) ((Vector3)(ref pos)).Normalize(); float latitudeRad = BlueprintUtils.GetLatitudeRad(pos); float longitudeRad = BlueprintUtils.GetLongitudeRad(pos); float num = latitudeRad / ((float)Math.PI * 2f) * (float)grid.segment; float num2 = PlanetGrid.DetermineLongitudeSegmentCount(Mathf.FloorToInt(Mathf.Max(0f, Mathf.Abs(num) - 0.1f)), grid.segment); float value = longitudeRad / 6.283185f * num2; float num3 = SnapWithOffset(num, currentGridData, 1); float num4 = SnapWithOffset(value, currentGridData, 0); float num5 = num3 / (float)grid.segment * ((float)Math.PI * 2f); float num6 = num4 / num2 * ((float)Math.PI * 2f); return BlueprintUtils.GetDir(num6, num5); } public static void CalculateOffset(this PlanetAuxData auxData, Vector3 pos, GridData gridData) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: 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) if (auxData.activeGridIndex < auxData.customGrids.Count) { PlanetGrid val = auxData.customGrids[auxData.activeGridIndex]; ((Vector3)(ref pos)).Normalize(); float latitudeRad = BlueprintUtils.GetLatitudeRad(pos); float longitudeRad = BlueprintUtils.GetLongitudeRad(pos); float num = latitudeRad / ((float)Math.PI * 2f) * (float)val.segment; float num2 = PlanetGrid.DetermineLongitudeSegmentCount(Mathf.FloorToInt(Mathf.Max(0f, Mathf.Abs(num) - 0.1f)), val.segment); float value = longitudeRad / 6.283185f * num2; float num3 = Snap(num) * 5f; float num4 = Snap(value) * 5f; gridData.snapOffset = new Vector2(num4 % gridData.snapGrid.x, num3 % gridData.snapGrid.y); } } public static float Snap(float value) { return Mathf.Round(value * 5f) / 5f; } public static float SnapWithOffset(float value, GridData gridData, int index) { if (!gridData.shouldShap) { return Snap(value); } float num = ((Vector2)(ref gridData.snapOffset))[index]; float num2 = Mathf.Round((value * 5f - num) / ((Vector2)(ref gridData.snapGrid))[index]); return num2 / 5f * ((Vector2)(ref gridData.snapGrid))[index] + num / 5f; } [HarmonyPatch(typeof(BuildTool_BlueprintPaste), "_OnClose")] [HarmonyPrefix] public static void Close() { if (BlueprintTweaksPlugin.resetFunctionsOnMenuExit.Value) { isLockedLongitude = false; isLockedLatitude = false; currentGridData.shouldShap = false; } } [HarmonyPatch(typeof(BuildTool_BlueprintPaste), "UpdateRaycast")] [HarmonyTranspiler] public static IEnumerable PasteSnap(IEnumerable instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Expected O, but got Unknown //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((Func)((CodeInstruction x) => CodeInstructionExtensions.IsLdloc(x, (LocalBuilder)null)), (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(BuildTool_BlueprintPaste), "castGroundPos"), (string)null) }).Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldarg_0, (object)null) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate>((Action)delegate(BuildTool_BlueprintPaste tool) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) float num = tool.blueprint.dragBoxSize_x; float num2 = tool.blueprint.dragBoxSize_y; currentGridData.snapGrid = new Vector2(num, num2); float num3 = 0f; float num4 = 0f; BlueprintUtils.GetLongitudeLatitudeRad(((Vector3)(ref tool.castGroundPos)).normalized, ref num3, ref num4); if (isLockedLongitude) { num3 = lockLongitude; } if (isLockedLatitude) { num4 = lockLatitude; } tool.castGroundPos = BlueprintUtils.GetDir(num3, num4) * ((Vector3)(ref tool.castGroundPos)).magnitude; }) }); val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(PlanetAuxData), "Snap", new Type[2] { typeof(Vector3), typeof(bool) }, (Type[])null), (string)null) }).SetInstruction(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(GridSnappingPatches), "SnapModified", (Type[])null, (Type[])null))); return val.InstructionEnumeration(); } [HarmonyPatch(typeof(BuildTool_Click), "UpdateRaycast")] [HarmonyTranspiler] public static IEnumerable ClickSnap(IEnumerable instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((Func)((CodeInstruction x) => CodeInstructionExtensions.IsLdloc(x, (LocalBuilder)null)), (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(BuildTool_Click), "castGroundPos"), (string)null) }).Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldarg_0, (object)null) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate>((Action)delegate(BuildTool_Click tool) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0098: 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) currentGridData.snapGrid = tool.handPrefabDesc.blueprintBoxSize; currentGridData.snapGrid.x = Mathf.Round(currentGridData.snapGrid.x); currentGridData.snapGrid.y = Mathf.Round(currentGridData.snapGrid.y); float num = 0f; float num2 = 0f; BlueprintUtils.GetLongitudeLatitudeRad(((Vector3)(ref tool.castGroundPos)).normalized, ref num, ref num2); if (isLockedLongitude) { num = lockLongitude; } if (isLockedLatitude) { num2 = lockLatitude; } tool.castGroundPos = BlueprintUtils.GetDir(num, num2) * ((Vector3)(ref tool.castGroundPos)).magnitude; }) }); MethodInfo methodInfo = AccessTools.Method(typeof(PlanetAuxData), "Snap", new Type[2] { typeof(Vector3), typeof(bool) }, (Type[])null); val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Callvirt, (object)methodInfo, (string)null) }).Repeat((Action)delegate(CodeMatcher codeMatcher) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown codeMatcher.SetInstruction(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(GridSnappingPatches), "SnapModified", (Type[])null, (Type[])null))); }, (Action)null); return val.InstructionEnumeration(); } [HarmonyPatch(typeof(BuildTool_Reform), "UpdateRaycastAndReform")] [HarmonyTranspiler] public static IEnumerable ClickReform(IEnumerable instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((Func)((CodeInstruction x) => CodeInstructionExtensions.IsLdloc(x, (LocalBuilder)null)), (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(BuildTool_Reform), "castGroundPos"), (string)null) }).Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldarg_0, (object)null) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate>((Action)delegate(BuildTool_Reform tool) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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_005a: 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) currentGridData.snapGrid = new Vector2((float)tool.brushSize, (float)tool.brushSize); float num = 0f; float num2 = 0f; BlueprintUtils.GetLongitudeLatitudeRad(((Vector3)(ref tool.castGroundPos)).normalized, ref num, ref num2); if (isLockedLongitude) { num = lockLongitude; } if (isLockedLatitude) { num2 = lockLatitude; } tool.castGroundPos = BlueprintUtils.GetDir(num, num2) * ((Vector3)(ref tool.castGroundPos)).magnitude; }) }); return val.InstructionEnumeration(); } } public class UIBlueprintSizePanel : UIBlueprintPanel { public InputField longField; public InputField latField; public Transform anchorTrans; private List anchorButtons; private bool inited; public override int verticalSize => 136; public override void OnUpdate() { longField.text = inspector.blueprint.dragBoxSize_x.ToString(); latField.text = inspector.blueprint.dragBoxSize_y.ToString(); if (anchorButtons == null) { return; } foreach (UIButton anchorButton in anchorButtons) { if (inspector.blueprint.areas.Length > 1) { ((Selectable)anchorButton.button).interactable = anchorButton.data < 3; } else if (inspector.blueprint.areas[0].height == 1) { ((Selectable)anchorButton.button).interactable = (anchorButton.data > 5 && anchorButton.data < 15) || anchorButton.data == 2; } else if (inspector.blueprint.areas[0].width == 1) { ((Selectable)anchorButton.button).interactable = anchorButton.data > 15 || anchorButton.data == 2; } else { ((Selectable)anchorButton.button).interactable = anchorButton.data < 5; } if (((Selectable)anchorButton.button).interactable) { int correctAnchorType = GetCorrectAnchorType(anchorButton.data); anchorButton.highlighted = inspector.blueprint.anchorType == correctAnchorType; } else { anchorButton.highlighted = false; } } } private static int GetCorrectAnchorType(int value) { if (value > 15) { value -= 20; } else if (value > 5) { value -= 10; } return value; } private void OnEnable() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown if (inited) { return; } anchorButtons = new List(anchorTrans.childCount); foreach (Transform anchorTran in anchorTrans) { Transform val = anchorTran; UIButton component = ((Component)val).GetComponent(); component.onClick += SetAnchor; anchorButtons.Add(component); } ((Component)longField.textComponent).gameObject.SetActive(false); ((Component)latField.textComponent).gameObject.SetActive(false); ((MonoBehaviour)this).Invoke("FixInvisible", 0.2f); } private void FixInvisible() { ((Component)longField.textComponent).gameObject.SetActive(true); ((Component)latField.textComponent).gameObject.SetActive(true); inited = true; } public void SetLongtitude(string value) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Invalid comparison between Unknown and I4 int dragBoxSize_x = int.Parse(value); inspector.blueprint.dragBoxSize_x = dragBoxSize_x; if ((int)inspector.usage == 2) { inspector.pasteBuildTool.ResetDragboxSize(false, false); } } public void SetLatitude(string value) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Invalid comparison between Unknown and I4 int dragBoxSize_y = int.Parse(value); inspector.blueprint.dragBoxSize_y = dragBoxSize_y; if ((int)inspector.usage == 2) { inspector.pasteBuildTool.ResetDragboxSize(false, false); } } public void SetAnchor(int type) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Invalid comparison between Unknown and I4 type = GetCorrectAnchorType(type); inspector.blueprint.anchorType = type; if ((int)inspector.usage == 2) { inspector.pasteBuildTool.anchorType = type; inspector.pasteBuildTool.ResetStates(); } inspector.Refresh(true, true, true, false); } } public class StationData { public int slotId; public int itemId; public ELogisticStorage local; public ELogisticStorage remote; } public class UIBlueprintStationItem : MonoBehaviour { [HideInInspector] public UIStationPanel panel; public RectTransform rectTrans; public UIButton button; public Image iconImage; public Text localText; public Text remoteText; private int stationId; private bool isStellar; private StationData currentItem; public int position { get { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) return Mathf.RoundToInt(rectTrans.anchoredPosition.x / 184f) + Mathf.RoundToInt((0f - rectTrans.anchoredPosition.y) / 46f) * 2; } set { //IL_0018: Unknown result type (might be due to invalid IL or missing references) rectTrans.anchoredPosition = new Vector2((float)(value % 2 * 184), (float)(-(value / 2 * 46))); } } public void Create(UIStationPanel panel) { this.panel = panel; button.onClick += OnClick; } public void Free() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) button.onClick -= OnClick; stationId = 0; button.tips.itemId = 0; button.data = 0; iconImage.sprite = null; ((Graphic)iconImage).color = Color.clear; } public void Open() { ((Component)this).gameObject.SetActive(true); } public void Close() { button.tips.itemId = 0; button.data = 0; stationId = 0; currentItem = null; ((Component)this).gameObject.SetActive(false); } private static string GetLogisticText(ELogisticStorage logic, bool isStellar, bool careStellar) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Invalid comparison between Unknown and I4 //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Invalid comparison between Unknown and I4 //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Invalid comparison between Unknown and I4 //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Invalid comparison between Unknown and I4 //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Invalid comparison between Unknown and I4 //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Invalid comparison between Unknown and I4 if (careStellar) { if (!isStellar) { if ((int)logic != 1) { if ((int)logic == 2) { return Localization.Translate("本地需求"); } return Localization.Translate("本地仓储"); } return Localization.Translate("本地供应"); } if ((int)logic != 1) { if ((int)logic == 2) { return Localization.Translate("星际需求"); } return Localization.Translate("星际仓储"); } return Localization.Translate("星际供应"); } if ((int)logic != 1) { if ((int)logic == 2) { return Localization.Translate("需求"); } return Localization.Translate("仓储"); } return Localization.Translate("供应"); } public void SetStation(int newStationId, bool isStellar) { stationId = newStationId; this.isStellar = isStellar; } public void SetDisplay(int newIndex, StationData newItem) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) position = newIndex; if (currentItem == null || currentItem.slotId != newItem.slotId || currentItem.itemId != newItem.itemId) { currentItem = newItem; localText.text = GetLogisticText(currentItem.local, isStellar: false, isStellar); remoteText.text = (isStellar ? GetLogisticText(currentItem.remote, isStellar: true, careStellar: true) : ""); ItemProto val = ((ProtoSet)(object)LDB.items).Select(currentItem.itemId); if (val != null) { button.tips.itemId = currentItem.itemId; iconImage.sprite = val.iconSprite; ((Graphic)iconImage).color = Color.white; } else { iconImage.sprite = null; ((Graphic)iconImage).color = Color.clear; } } } private void OnClick(int obj) { //IL_0006: 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) VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 1, -1, -1L); Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(-300f, 238f); UIItemPicker.Close(); UIItemPicker.Popup(val, (Action)delegate(ItemProto proto) { if (proto != null) { panel.ChangeItem(stationId, currentItem.slotId, proto); } }); } } public class UIStationPanel : UIBlueprintPanel { public List items = new List(); public int recipeCount; public UIBlueprintStationItem prefab; public override int verticalSize { get { if (recipeCount == 0) { return 22; } return 22 + ((recipeCount - 1) / 2 + 1) * 46; } } public override void OnUpdate() { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: 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_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) int activeCount = 0; BlueprintBuilding[] buildings = inspector.blueprint.buildings; foreach (BlueprintBuilding val in buildings) { int itemId = val.itemId; ItemProto val2 = ((ProtoSet)(object)LDB.items).Select(itemId); if (val2 == null || !val2.prefabDesc.isStation || val2.prefabDesc.isCollectStation) { continue; } int[] parameters = val.parameters; if (parameters == null || parameters.Length < 2048) { continue; } for (int j = 0; j < val2.prefabDesc.stationMaxItemKinds; j++) { if (parameters[j * 6] > 0) { int itemId2 = parameters[j * 6]; ELogisticStorage local = (ELogisticStorage)parameters[j * 6 + 1]; ELogisticStorage remote = (ELogisticStorage)parameters[j * 6 + 2]; StationData data = new StationData { itemId = itemId2, local = local, remote = remote, slotId = j }; SetItem(activeCount++, val.index, val2.prefabDesc.isStellarStation, data); } } } ClearComponentItems(activeCount); } public void SetItem(int index, int stationId, bool isStellar, StationData data) { if (index >= 0 && index <= 256) { while (index >= items.Count) { UIBlueprintStationItem uIBlueprintStationItem = Object.Instantiate(prefab, ((Component)prefab).transform.parent); uIBlueprintStationItem.Create(this); items.Add(uIBlueprintStationItem); } items[index].SetStation(stationId, isStellar); items[index].SetDisplay(index, data); items[index].Open(); } } public void ClearComponentItems(int activeCount = 0) { for (int i = activeCount; i < items.Count; i++) { items[i].Close(); } recipeCount = activeCount; } public void ChangeItem(int stationId, int slotId, ItemProto newItem) { //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Invalid comparison between Unknown and I4 if (stationId < 0 || stationId >= inspector.blueprint.buildings.Length) { return; } BlueprintBuilding val = inspector.blueprint.buildings[stationId]; int itemId = val.itemId; ItemProto val2 = ((ProtoSet)(object)LDB.items).Select(itemId); if (!val2.prefabDesc.isStation || val2.prefabDesc.isCollectStation) { return; } int[] parameters = val.parameters; if (parameters != null && parameters.Length >= 2048) { if (parameters[slotId * 6] > 0) { parameters[slotId * 6] = ((Proto)newItem).ID; } if ((int)inspector.usage == 2) { inspector.pasteBuildTool.ResetStates(); } inspector.Refresh(true, true, true, false); } } } public static class Extensions { public static bool Approximately(this Quaternion quatA, Quaternion value, float acceptableRange = 0.01f) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) return 1f - Mathf.Abs(Quaternion.Dot(quatA, value)) < acceptableRange; } public static Vector2 Rotate(this Vector2 v, float degrees) { //IL_0016: 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_0035: Unknown result type (might be due to invalid IL or missing references) float num = degrees * ((float)Math.PI / 180f); float num2 = Mathf.Sin(num); float num3 = Mathf.Cos(num); float x = v.x; float y = v.y; return new Vector2(num3 * x - num2 * y, num2 * x + num3 * y); } public static bool IsOnEdgeOfGratBox(this BPGratBox box, Vector3 pos, int segmentCount) { //IL_0007: 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_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: 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_002f: Unknown result type (might be due to invalid IL or missing references) ((Vector3)(ref pos)).Normalize(); float y = pos.y; if (y > 0.999999f) { return box.w >= 1.5707864f; } if (y < -0.999999f) { return box.y <= -1.5707864f; } float latitudeRad = Mathf.Asin(y); float longitudeRad = Mathf.Atan2(pos.x, 0f - pos.z); return box.IsOnEdgeOfGratBox(longitudeRad, latitudeRad, segmentCount); } public static bool IsOnEdgeOfGratBox(this BPGratBox box, float longitudeRad, float latitudeRad, int segmentCount) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) float latitudeRadPerGrid = BlueprintUtils.GetLatitudeRadPerGrid(segmentCount); float longitudeRadPerGrid = BlueprintUtils.GetLongitudeRadPerGrid(latitudeRad, segmentCount); BPGratBox val = default(BPGratBox); ((BPGratBox)(ref val))..ctor(box.x + longitudeRadPerGrid, box.y + latitudeRadPerGrid, box.z - longitudeRadPerGrid, box.w - latitudeRadPerGrid); return !((BPGratBox)(ref val)).InGratBox(longitudeRad, latitudeRad); } } [Serializable] public class FixedSizeStack : ICollection, IEnumerable, IReadOnlyCollection, IEnumerable { [Serializable] private struct Enumerator : IEnumerator, IDisposable, IEnumerator { private FixedSizeStack _stack; private int _index; private long _version; private T _currentElement; public T Current { get { if (_index == -2) { throw new InvalidOperationException("Enumeration Not Started"); } if (_index == -1) { throw new InvalidOperationException("Enumeration Ended"); } return _currentElement; } } object IEnumerator.Current => Current; internal Enumerator(FixedSizeStack stack) { _stack = stack; _version = _stack._version; _index = -2; _currentElement = default(T); } public void Dispose() { _index = -1; } public bool MoveNext() { if (_version != _stack._version) { throw new InvalidOperationException("Version Conflict"); } if (_index == -2) { _index = 0; bool flag = _index >= 0; if (flag) { _currentElement = _stack[_index]; } return flag; } if (_index == -1) { return false; } bool flag2 = ++_index < _stack.Count(); _currentElement = ((!flag2) ? default(T) : _stack[_index]); return flag2; } void IEnumerator.Reset() { if (_version != _stack._version) { throw new InvalidOperationException("Version Conflict"); } _index = -2; _currentElement = default(T); } } private T[] _data; private int _pointer; private int _count; private long _version; private object _syncRoot; public int Count => _count; public object SyncRoot { get { if (_syncRoot == null) { Interlocked.CompareExchange(ref _syncRoot, new object(), (object)null); } return _syncRoot; } } public bool IsSynchronized => false; public int Size => _data.Length; public T this[int index] { get { int num = _pointer - index; if (num < 0) { num += Size; } return _data[num]; } } public FixedSizeStack(int size) { _data = new T[size]; _pointer = _data.GetLowerBound(0); _version = 0L; } private void _IncrementPointer() { if (_pointer++ == _data.GetUpperBound(0)) { _pointer = _data.GetLowerBound(0); } } private void _DecrementPointer() { if (_pointer-- == _data.GetLowerBound(0)) { _pointer = _data.GetUpperBound(0); } } public bool Contains(T item) { return _data.Contains(item); } public void CopyTo(Array array, int index) { if (array.Rank != 1) { throw new ArgumentException($"Array with dimension of {array.Rank} is not supported!"); } if (array.GetLowerBound(0) != 0) { throw new ArgumentException("Array with non zero lower bound is not supported!"); } if (index < 0 || index > array.Length) { throw new ArgumentOutOfRangeException($"{index} is out of range. Index has to be greater than zero and less than {array.Length}"); } if (array.Length - index < _count) { throw new ArgumentException("Invalid off length"); } try { Array.Copy(_data, 0, array, index, _count); Array.Reverse(array, index, _count); } catch (ArrayTypeMismatchException) { throw new ArgumentException($"Invalid array type! Expected type {typeof(T)}."); } } public void Clear() { _data = new T[Size]; } public T Pop() { T result = _data[_pointer]; _data[_pointer] = default(T); _DecrementPointer(); _version++; if (_count > _data.GetLowerBound(0)) { _count--; } return result; } public void Push(T item) { _IncrementPointer(); _data[_pointer] = item; _version++; if (_count <= _data.GetUpperBound(0)) { _count++; } } public T Peek() { return _data[_pointer]; } public IEnumerator GetEnumerator() { return new Enumerator(this); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } public class NebulaIncomingRequestToggle : IDisposable { private IDisposable toggle; public NebulaIncomingRequestToggle() { if (NebulaModAPI.IsMultiplayerActive) { toggle = NebulaModAPI.MultiplayerSession.Factories.IsIncomingRequest.On(); } } public void Dispose() { if (NebulaModAPI.IsMultiplayerActive) { toggle?.Dispose(); } } } public sealed class ToggleSwitch : IToggle { public readonly struct Toggle : IDisposable { private readonly ToggleSwitch value; private readonly int count; public Toggle(ToggleSwitch value, int count) { this.value = value; this.count = count; Interlocked.Add(ref value.onCount, count); } public void Dispose() { Interlocked.Add(ref value.onCount, -count); } } private int onCount; public bool Value => onCount > 0; public static implicit operator bool(ToggleSwitch toggle) { return toggle.Value; } public Toggle On(bool conditional) { return new Toggle(this, conditional ? 1 : 0); } public IDisposable On() { return new Toggle(this, 1); } } } namespace BlueprintTweaks.Patches { [HarmonyPatch] public static class BuildTool_BlueprintPaste_Patch { [HarmonyPatch(typeof(BuildTool_BlueprintPaste), "DeterminAnchorType")] [HarmonyPostfix] public static void OnChangedAnchor(BuildTool_BlueprintPaste __instance, bool __result) { if (__result) { __instance.blueprint.anchorType = __instance.anchorType; __instance.uiInspector.Refresh(true, true, true, false); } } [HarmonyPatch(typeof(PlayerController), "OpenBlueprintPasteMode")] [HarmonyPostfix] public static void OnOpenBlueprint(PlayerController __instance) { BuildTool_BlueprintPaste blueprintPasteTool = __instance.actionBuild.blueprintPasteTool; if (blueprintPasteTool.blueprint != null) { blueprintPasteTool.anchorType = blueprintPasteTool.blueprint.anchorType; } } [HarmonyPatch(typeof(BuildTool_BlueprintPaste), "_OnOpen")] [HarmonyTranspiler] private static IEnumerable DontResetAnchorOnOpen(IEnumerable instructions) { //IL_0017: 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_0037: Expected O, but got Unknown //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown FieldInfo fieldInfo = AccessTools.Field(typeof(BuildTool_BlueprintPaste), "anchorType"); CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)fieldInfo, (string)null) }).RemoveInstructions(3); return val.InstructionEnumeration(); } } } namespace BlueprintTweaks.PasteLocked { [RegisterPatch("PasteLocked")] public static class AssemblerComponent_Patch { [HarmonyPatch(typeof(AssemblerComponent), "InternalUpdate")] [HarmonyPrefix] public static bool CheckAssemblerRecipe(ref AssemblerComponent __instance) { if (!__instance.recipeIsLocked) { __instance.recipeIsLocked = GameMain.history.RecipeUnlocked(__instance.recipeId); } return __instance.recipeIsLocked; } [HarmonyPatch(typeof(AssemblerComponent), "SetRecipe")] [HarmonyPostfix] public static void OnSetRecipe(ref AssemblerComponent __instance) { if (__instance.recipeId > 0) { __instance.recipeIsLocked = GameMain.history.RecipeUnlocked(__instance.recipeId); } } } [RegisterPatch("PasteLocked")] public static class BuildingParameters_Patch { [HarmonyPatch(typeof(BuildingParameters), "CanPasteToFactoryObject")] [HarmonyPatch(typeof(BuildingParameters), "PasteToFactoryObject")] [HarmonyTranspiler] public static IEnumerable AllowPastingLockedRecipes(IEnumerable instructions) { //IL_0002: 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: Expected O, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(GameHistoryData), "RecipeUnlocked", (Type[])null, (Type[])null), (string)null) }).Repeat((Action)delegate(CodeMatcher codeMatcher) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown codeMatcher.Advance(-1).SetOpcodeAndAdvance(OpCodes.Nop).SetOpcodeAndAdvance(OpCodes.Nop) .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Nop, (object)null)) .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Ldc_I4_1, (object)null)); }, (Action)null); val.Start().MatchForward(false, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(GameHistoryData), "ItemUnlocked", (Type[])null, (Type[])null), (string)null) }).Repeat((Action)delegate(CodeMatcher codeMatcher) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown codeMatcher.Advance(-1).SetOpcodeAndAdvance(OpCodes.Nop).SetOpcodeAndAdvance(OpCodes.Nop) .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Nop, (object)null)) .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Ldc_I4_1, (object)null)); }, (Action)null); return val.InstructionEnumeration(); } [HarmonyPatch(typeof(BuildingParameters), "ApplyPrebuildParametersToEntity")] [HarmonyTranspiler] public static IEnumerable AllowBuildingWithLockedRecipes(IEnumerable instructions) { //IL_0002: 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: Expected O, but got Unknown //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Expected O, but got Unknown //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Expected O, but got Unknown //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(GameHistoryData), "RecipeUnlocked", (Type[])null, (Type[])null), (string)null) }).Repeat((Action)delegate(CodeMatcher codeMatcher) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown codeMatcher.Advance(-1).SetOpcodeAndAdvance(OpCodes.Nop).SetOpcodeAndAdvance(OpCodes.Nop) .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Ldc_I4_1, (object)null)); }, (Action)null); val.Start().MatchForward(false, (CodeMatch[])(object)new CodeMatch[4] { new CodeMatch((OpCode?)OpCodes.Ldarg_3, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldelem_I4, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(GameHistoryData), "ItemUnlocked", (Type[])null, (Type[])null), (string)null) }).Advance(-1) .SetOpcodeAndAdvance(OpCodes.Nop) .SetOpcodeAndAdvance(OpCodes.Nop) .SetOpcodeAndAdvance(OpCodes.Nop) .SetOpcodeAndAdvance(OpCodes.Nop) .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Ldc_I4_1, (object)null)); return val.InstructionEnumeration(); } } [RegisterPatch("PasteLocked")] public static class LabComponent_Patch { [HarmonyPatch(typeof(LabComponent), "InternalUpdateAssemble")] [HarmonyPrefix] public static bool CheckAssemblerRecipe(ref LabComponent __instance) { if (!__instance.recipeIsLocked) { __instance.recipeIsLocked = GameMain.history.RecipeUnlocked(__instance.recipeId); } return __instance.recipeIsLocked; } [HarmonyPatch(typeof(LabComponent), "SetFunction")] [HarmonyPostfix] public static void OnSetRecipe(ref LabComponent __instance) { if (__instance.recipeId > 0) { __instance.recipeIsLocked = GameMain.history.RecipeUnlocked(__instance.recipeId); } } } [RegisterPatch("PasteLocked")] public static class UIAssemblerWindow_Patch { [HarmonyPatch(typeof(UIAssemblerWindow), "_OnUpdate")] [HarmonyPostfix] public static void OnUIUpdate(UIAssemblerWindow __instance) { //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_0028: 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) if (__instance.assemblerId != 0 && __instance.factory != null) { AssemblerComponent val = __instance.factorySystem.assemblerPool[__instance.assemblerId]; if (!val.recipeIsLocked) { __instance.stateText.text = Localization.Translate("recipeLockedWarn"); ((Graphic)__instance.stateText).color = __instance.workStoppedColor; } } } } [RegisterPatch("PasteLocked")] public static class UILabWindow_Patch { [HarmonyPatch(typeof(UILabWindow), "_OnUpdate")] [HarmonyPostfix] public static void OnUIUpdate(UILabWindow __instance) { //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_0028: 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) if (__instance.labId != 0 && __instance.factory != null) { LabComponent val = __instance.factorySystem.labPool[__instance.labId]; if (!val.recipeIsLocked) { __instance.stateText.text = Localization.Translate("recipeLockedWarn"); ((Graphic)__instance.stateText).color = __instance.workStoppedColor; } } } } } namespace BlueprintTweaks.KeepBPName { [HarmonyPatch] public static class UIBlueprintInspectorPatch { public static string shortDesc; public static string desc; public static EIconLayout layout; public static int icon0; public static int icon1; public static int icon2; public static int icon3; public static int icon4; [HarmonyPatch(typeof(UIBlueprintInspector), "OnPasteClick")] [HarmonyPrefix] public static void OnPasteClickPrefix(UIBlueprintInspector __instance, out bool __state) { //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) string systemCopyBuffer = GUIUtility.systemCopyBuffer; if (__instance.blueprint == null || string.IsNullOrEmpty(systemCopyBuffer)) { __state = false; return; } __state = CustomKeyBindSystem.GetKeyBind("ForceBPPlace").keyValue; shortDesc = __instance.blueprint.shortDesc; desc = __instance.blueprint.desc; layout = __instance.blueprint.layout; icon0 = __instance.blueprint.icon0; icon1 = __instance.blueprint.icon1; icon2 = __instance.blueprint.icon2; icon3 = __instance.blueprint.icon3; icon4 = __instance.blueprint.icon4; } [HarmonyPatch(typeof(UIBlueprintInspector), "OnPasteClick")] [HarmonyPostfix] public static void OnPasteClickPostfix(UIBlueprintInspector __instance, bool __state) { //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) if (__state) { __instance.blueprint.shortDesc = shortDesc; __instance.blueprint.desc = desc; __instance.blueprint.layout = layout; __instance.blueprint.icon0 = icon0; __instance.blueprint.icon1 = icon1; __instance.blueprint.icon2 = icon2; __instance.blueprint.icon3 = icon3; __instance.blueprint.icon4 = icon4; __instance.Refresh(false, true, true, false); } } } } namespace BlueprintTweaks.InstallCheck { [BepInPlugin("org.kremnev8.plugin.BlueprintTweaksInstallCheck", "Blueprint Tweaks Installation Checker", "1.6.12")] public class InstallationChecker : BaseUnityPlugin { public const string MODNAME = "Blueprint Tweaks Installation Checker"; public const string MODGUID = "org.kremnev8.plugin.BlueprintTweaksInstallCheck"; public const string LDBTOOLGUID = "me.xiaoye97.plugin.Dyson.LDBTool"; public static bool preloaderInstalled; public static bool ldbToolInstalled; public static bool nebulaAPIInstalled; public static bool assetBundleFound; public static bool installationIsValid; private void Awake() { Type type = AccessTools.TypeByName("BlueprintData"); FieldInfo field = type.GetField("anchorType"); preloaderInstalled = field != null; if (Chainloader.PluginInfos.ContainsKey("me.xiaoye97.plugin.Dyson.LDBTool")) { ldbToolInstalled = true; } if (Chainloader.PluginInfos.ContainsKey("dsp.nebula-multiplayer-api")) { nebulaAPIInstalled = true; } string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); assetBundleFound = File.Exists(directoryName + "/blueprinttweaks"); installationIsValid = preloaderInstalled && ldbToolInstalled && nebulaAPIInstalled && assetBundleFound; Harmony.CreateAndPatchAll(typeof(UIMainMenuPatch), (string)null); if (installationIsValid) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Check successful. Installation is correct!"); } else { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Check failed. Mod is installed incorrectly!"); } } } public static class UIMainMenuPatch { [HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")] [HarmonyPostfix] public static void OnMainMenuOpen() { if (!InstallationChecker.installationIsValid) { string text = "Mod installation is incorrect because:\n"; if (!InstallationChecker.preloaderInstalled) { text += " - Preloader patch has not been detected\n"; } if (!InstallationChecker.assetBundleFound) { text += " - Asset Bundle in installation folder is missing!\n"; } if (!InstallationChecker.ldbToolInstalled) { text += " - Plugin \"LDB Tool\" is missing\n"; } if (!InstallationChecker.nebulaAPIInstalled) { text += " - Plugin \"Nebula Multiplayer Mod API\" is missing\n"; } text += "Please check your installation, make sure you followed installation instructions correctly.\nIf you are using a mod manager make sure that all dependencies have been downloaded!\nIf nothing helps you can message me via Discord: Kremnev8#3756"; UIMessageBox.Show("BlueprintTweaks mod installation is incorrect!", text, "Ok", 3); } } } } namespace BlueprintTweaks.GlobalPatch { [HarmonyPatch] public class BuildTool_BlueprintPaste_Patch_3 { [HarmonyPatch(typeof(BuildTool_BlueprintPaste), "OnCameraPostRender")] [HarmonyPrefix] public static bool CheckNull(BuildTool_BlueprintPaste __instance) { return ((BuildTool)__instance).active; } } } namespace BlueprintTweaks.FactoryUndo { [RegisterPatch("FactoryUndo")] public static class BuildTools_Patch { [HarmonyPatch(typeof(BuildTool_Addon), "CreatePrebuilds")] [HarmonyPostfix] public static void OnPathAddonBuilt(BuildTool_Addon __instance) { if (!UndoManager.IgnoreAllEvents.Value && (!NebulaModAPI.IsMultiplayerActive || !NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)) { IEnumerable objectIds = ((BuildTool)__instance).buildPreviews.Select((BuildPreview preview) => preview.objId); PlayerUndo currentPlayerData = UndoManager.GetCurrentPlayerData(); currentPlayerData.AddUndoItem(new UndoAddon(currentPlayerData, objectIds)); } } [HarmonyPatch(typeof(BuildTool_Click), "CreatePrebuilds")] [HarmonyPostfix] public static void OnClickBuilt(BuildTool_Click __instance) { if (!UndoManager.IgnoreAllEvents.Value && (!NebulaModAPI.IsMultiplayerActive || !NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)) { IEnumerable objectIds = ((BuildTool)__instance).buildPreviews.Select((BuildPreview preview) => preview.objId); PlayerUndo currentPlayerData = UndoManager.GetCurrentPlayerData(); currentPlayerData.AddUndoItem(new UndoBuild(currentPlayerData, objectIds)); } } [HarmonyPatch(typeof(BuildTool_BlueprintPaste), "CreatePrebuilds")] [HarmonyPostfix] public static void OnPaste(BuildTool_BlueprintPaste __instance) { if (!UndoManager.IgnoreAllEvents.Value && (!NebulaModAPI.IsMultiplayerActive || !NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)) { List list = new List(__instance.bpCursor); for (int i = 0; i < __instance.bpCursor; i++) { BuildPreview val = __instance.bpPool[i]; list.Add(val.objId); } Vector3[] array = (Vector3[])(object)new Vector3[__instance.dotsCursor]; Array.Copy(__instance.dotsSnapped, array, __instance.dotsCursor); PlayerUndo currentPlayerData = UndoManager.GetCurrentPlayerData(); UndoBlueprint action = new UndoBlueprint(currentPlayerData, list, __instance.blueprint, array, __instance.yaw); currentPlayerData.AddUndoItem(action); } } [HarmonyPatch(typeof(BuildTool_Inserter), "CreatePrebuilds")] [HarmonyTranspiler] public static IEnumerable Transpiler(IEnumerable instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).End().MatchBack(false, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(BuildTool), "buildPreviews"), (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)null, (string)null) }).Advance(1) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate>((Action)delegate(BuildTool_Inserter tool) { if (!UndoManager.IgnoreAllEvents.Value && (!NebulaModAPI.IsMultiplayerActive || !NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)) { IEnumerable objectIds = ((BuildTool)tool).buildPreviews.Select((BuildPreview preview) => preview.objId); PlayerUndo currentPlayerData = UndoManager.GetCurrentPlayerData(); currentPlayerData.AddUndoItem(new UndoBuild(currentPlayerData, objectIds)); } }) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldarg_0, (object)null) }); return val.InstructionEnumeration(); } [HarmonyPatch(typeof(BuildTool_Path), "CreatePrebuilds")] [HarmonyPostfix] public static void OnClickBuildPath(BuildTool __instance) { if (!UndoManager.IgnoreAllEvents.Value && (!NebulaModAPI.IsMultiplayerActive || !NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)) { IEnumerable objectIds = __instance.buildPreviews.Select((BuildPreview preview) => preview.objId); PlayerUndo currentPlayerData = UndoManager.GetCurrentPlayerData(); currentPlayerData.AddUndoItem(new UndoBuild(currentPlayerData, objectIds)); } } } [RegisterPatch("FactoryUndo")] public static class BuildTool_Dismantle_Patch { private static HashSet objectIds = new HashSet(); [HarmonyPatch(typeof(BuildTool_Dismantle), "DismantleAction")] [HarmonyPrefix] public static void OnDismantle(BuildTool_Dismantle __instance) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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 (UndoManager.IgnoreAllEvents.Value || (NebulaModAPI.IsMultiplayerActive && NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)) { return; } List list = DetermineDismantle(__instance).ToList(); if (list.Count > 0) { Vector3 position; BlueprintData val = UndoUtils.GenerateBlueprint(list, out position); if (val.buildings.Length != 0 && !((Vector3)(ref position)).Equals(Vector3.zero)) { PlayerUndo currentPlayerData = UndoManager.GetCurrentPlayerData(); currentPlayerData.AddUndoItem(new UndoDismantle(currentPlayerData, list, val, (Vector3[])(object)new Vector3[1] { position }, 0f)); } } } [HarmonyPatch(typeof(BuildTool_Dismantle), "DismantleAction")] [HarmonyReversePatch(/*Could not decode attribute arguments.*/)] public static HashSet DetermineDismantle(BuildTool_Dismantle tool) { Transpiler(null); return new HashSet(); static IEnumerable Transpiler(IEnumerable instructions) { //IL_0002: 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_005b: Expected O, but got Unknown //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Expected O, but got Unknown //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Expected O, but got Unknown //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Expected O, but got Unknown //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Expected O, but got Unknown //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Expected O, but got Unknown //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Expected O, but got Unknown //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Expected O, but got Unknown //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Expected O, but got Unknown //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).Start().InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate((Action)delegate { objectIds.Clear(); }) }); Label? label = default(Label?); val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[5] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(BuildTool_Dismantle), "cursorType"), (string)null), new CodeMatch((Func)((CodeInstruction i) => CodeInstructionExtensions.Branches(i, ref label)), (string)null), new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(BuildTool_Dismantle), "dismantleQueryObjectIds"), (string)null) }).Repeat((Action)delegate(CodeMatcher codeMatcher) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Expected O, but got Unknown codeMatcher.Advance(4).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Pop, (object)null) }).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate>>((Func>)(() => objectIds)) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ret, (object)null) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldarg_0, (object)null) }); }, (Action)null); val.Start().MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(PlayerAction_Build), "DoDismantleObject", (Type[])null, (Type[])null), (string)null) }).Repeat((Action)delegate(CodeMatcher codeMatcher) { codeMatcher.SetInstructionAndAdvance(Transpilers.EmitDelegate>((Func)delegate(PlayerAction_Build build, int objectId) { objectIds.Add(objectId); return false; })); }, (Action)null); val.Start().MatchForward(false, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(BuildTool), "buildPreviews"), (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(List), "Clear", (Type[])null, (Type[])null), (string)null) }).Advance(1) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Pop, (object)null) }) .RemoveInstructions(2) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate>>((Func>)(() => objectIds)) }) .Advance(1); val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ret, (object)null, (string)null) }).Repeat((Action)delegate(CodeMatcher codeMatcher) { codeMatcher.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate>>((Func>)(() => objectIds)) }).Advance(1); }, (Action)null); return val.InstructionEnumeration(); } } } [RegisterPatch("FactoryUndo")] public static class BuildTool_Upgrade_Patch { internal static HashSet upgradeIds = new HashSet(); internal static List upgradeList = new List(); internal static bool RecordUpgrades; [HarmonyPatch(typeof(BuildTool_Upgrade), "UpgradeAction")] [HarmonyPrefix] public static void OnUpgradePre(BuildTool_Upgrade __instance) { if (!UndoManager.IgnoreAllEvents.Value && (!NebulaModAPI.IsMultiplayerActive || !NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)) { upgradeIds.Clear(); upgradeList.Clear(); RecordUpgrades = true; } } [HarmonyPatch(typeof(BuildTool_Upgrade), "UpgradeAction")] [HarmonyPostfix] public static void OnUpgradePost(BuildTool_Upgrade __instance) { if (!UndoManager.IgnoreAllEvents.Value && (!NebulaModAPI.IsMultiplayerActive || !NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)) { RecordUpgrades = false; if (upgradeList.Count > 0) { PlayerUndo currentPlayerData = UndoManager.GetCurrentPlayerData(); currentPlayerData.AddUndoItem(new UndoUpgrade(currentPlayerData, upgradeList)); } } } [HarmonyPatch(typeof(PlayerAction_Build), "DoUpgradeObject")] [HarmonyPrefix] public static void OnDoUpgragePre(PlayerAction_Build __instance, int objId, int grade, int upgrade) { if (UndoManager.IgnoreAllEvents.Value || (NebulaModAPI.IsMultiplayerActive && NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient) || !RecordUpgrades || objId == 0 || upgradeIds.Contains(objId)) { return; } upgradeIds.Add(objId); ItemProto itemProto = ((BuildTool)__instance.noneTool).GetItemProto(objId); if (itemProto != null && itemProto.canUpgrade) { int grade2 = itemProto.Grade; ItemProto val = itemProto; if (grade > 0) { val = itemProto.GetGradeItem(grade); } else if (upgrade != 0) { val = itemProto.GetUpgradeItem(upgrade); } upgradeList.Add(new UpgradeData(objId, grade2, val.Grade)); } } [HarmonyPatch(typeof(PlayerAction_Build), "DoUpgradeObject")] [HarmonyPostfix] public static void OnDoUpgragePost(PlayerAction_Build __instance, int objId, bool __result) { if ((!NebulaModAPI.IsMultiplayerActive || !NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient) && !__result) { upgradeList.RemoveAll((UpgradeData data) => data.objId == objId); } } } [RegisterPatch("FactoryUndo")] public static class GameData_Patch { [HarmonyPatch(typeof(GameData), "LeavePlanet")] [HarmonyPostfix] public static void OnDoUpgragePost() { //IL_0058: Unknown result type (might be due to invalid IL or missing references) if (NebulaModAPI.IsMultiplayerActive) { IMultiplayerSession multiplayerSession = NebulaModAPI.MultiplayerSession; if (multiplayerSession.LocalPlayer.IsClient) { multiplayerSession.Network.SendPacket(new ClearUndoRequestPacket(multiplayerSession.LocalPlayer.Id)); if (BlueprintTweaksPlugin.showUndoClearedMessage.Value) { UIRealtimeTip.Popup(Localization.Translate("UndoClearedMessage"), false, 0); VFAudio.Create("cancel-0", (Transform)null, Vector3.zero, true, 4, -1, -1L); } return; } } PlayerUndo playerData = UndoManager.GetPlayerData(UndoManager.GetLocalUserId()); playerData.ResetUndo(); } } [RegisterPatch("FactoryUndo")] public static class PlayerActionBuild_Patch { [HarmonyPatch(typeof(PlayerAction_Build), "NotifyBuilt")] [HarmonyPostfix] public static void OnNotifyBuilt(int preObjId, int postObjId) { if (NebulaModAPI.IsMultiplayerActive && NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient) { return; } foreach (PlayerUndo value in UndoManager.undos.Values) { foreach (IUndoAction notifyBuildListener in value.notifyBuildListeners) { notifyBuildListener.NotifyBuild(preObjId, postObjId); } for (int i = 0; i < value.notifyBuildListeners.Count; i++) { IUndoAction undoAction = value.notifyBuildListeners[i]; if (!undoAction.HasAnyPrebuilds()) { value.notifyBuildListeners.RemoveAt(i); value.notifyDismantleListeners.Add(undoAction); i--; } } } } [HarmonyPatch(typeof(PlayerAction_Build), "NotifyDismantled")] [HarmonyPostfix] public static void OnNotifyDismantled(int objId) { if ((NebulaModAPI.IsMultiplayerActive && NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient) || UndoManager.IgnoreAllEvents.Value) { return; } foreach (PlayerUndo value in UndoManager.undos.Values) { foreach (IUndoAction notifyDismantleListener in value.notifyDismantleListeners) { notifyDismantleListener.NotifyDismantled(objId); } value.notifyDismantleListeners.RemoveAll((IUndoAction action) => action.IsEmpty()); } } } public class PlayerUndo { public readonly ushort playerId; public FixedSizeStack undoStack; public FixedSizeStack redoStack; public List notifyBuildListeners = new List(); public List notifyDismantleListeners = new List(); public PlayerUndo(ushort playerId) { undoStack = new FixedSizeStack(BlueprintTweaksPlugin.undoMaxHistory.Value); redoStack = new FixedSizeStack(BlueprintTweaksPlugin.undoMaxHistory.Value); this.playerId = playerId; } internal void ResetUndo() { //IL_006d: Unknown result type (might be due to invalid IL or missing references) undoStack.Clear(); redoStack.Clear(); notifyBuildListeners.Clear(); notifyDismantleListeners.Clear(); if ((!NebulaModAPI.IsMultiplayerActive || !NebulaModAPI.MultiplayerSession.Factories.IsIncomingRequest.Value) && BlueprintTweaksPlugin.showUndoClearedMessage.Value) { UIRealtimeTip.Popup(Localization.Translate("UndoClearedMessage"), false, 0); VFAudio.Create("cancel-0", (Transform)null, Vector3.zero, true, 4, -1, -1L); } } internal void AddUndoItem(IUndoAction action) { undoStack.Push(action); notifyBuildListeners.Add(action); notifyDismantleListeners.Add(action); foreach (IUndoAction item in redoStack) { notifyBuildListeners.Remove(item); notifyDismantleListeners.Remove(item); } redoStack.Clear(); } internal bool TryUndo(PlanetFactory factory, out string message, out bool sound) { sound = false; message = ""; if (undoStack.Count <= 0) { sound = true; message = "UndoHistoryEmptyMessage"; return true; } if (GameMain.localPlanet?.factory == null) { return false; } Player mainPlayer = GameMain.mainPlayer; if ((Object)(object)((mainPlayer != null) ? mainPlayer.controller : null) == (Object)null) { return false; } PlayerAction_Build actionBuild = GameMain.mainPlayer.controller.actionBuild; IUndoAction undoAction = undoStack.Pop(); bool flag = false; try { flag = undoAction.Undo(factory, actionBuild); } catch (Exception ex) { BlueprintTweaksPlugin.logger.LogWarning((object)("Failed to undo, message: " + ex.Message + ", stacktrace:\n" + ex.StackTrace)); } if (flag) { message = "UndoSuccessText"; redoStack.Push(undoAction); } else { message = "UndoFailureText"; sound = true; notifyBuildListeners.Remove(undoAction); notifyDismantleListeners.Remove(undoAction); } return true; } internal bool TryRedo(PlanetFactory factory, out string message, out bool sound) { sound = false; message = ""; if (redoStack.Count <= 0) { sound = true; message = "RedoHistoryEmptyMessage"; return true; } if (GameMain.localPlanet?.factory == null) { return false; } Player mainPlayer = GameMain.mainPlayer; if ((Object)(object)((mainPlayer != null) ? mainPlayer.controller : null) == (Object)null) { return false; } PlayerAction_Build actionBuild = GameMain.mainPlayer.controller.actionBuild; IUndoAction undoAction = redoStack.Pop(); bool flag = false; try { flag = undoAction.Redo(factory, actionBuild); } catch (Exception ex) { BlueprintTweaksPlugin.logger.LogWarning((object)("Failed to redo, message: " + ex.Message + ", stacktrace:\n" + ex.StackTrace)); } if (flag) { message = "RedoSuccessText"; undoStack.Push(undoAction); } else { sound = true; message = "RedoFailureText"; notifyBuildListeners.Remove(undoAction); notifyDismantleListeners.Remove(undoAction); } return true; } } public interface IUndoAction { void NotifyBuild(int preObjId, int postObjId); void NotifyDismantled(int objId); bool Undo(PlanetFactory factory, PlayerAction_Build actionBuild); bool Redo(PlanetFactory factory, PlayerAction_Build actionBuild); bool HasAnyPrebuilds(); bool IsEmpty(); } public abstract class UndoAction : IUndoAction { protected PlayerUndo undoData; public abstract void NotifyBuild(int preObjId, int postObjId); public abstract void NotifyDismantled(int objId); public abstract bool Undo(PlanetFactory factory, PlayerAction_Build actionBuild); public abstract bool Redo(PlanetFactory factory, PlayerAction_Build actionBuild); public abstract bool HasAnyPrebuilds(); public abstract bool IsEmpty(); protected UndoAction(PlayerUndo undoData) { this.undoData = undoData; } } public class UndoAddon : UndoBuild { public UndoAddon(PlayerUndo undoData, IEnumerable objectIds) : base(undoData, objectIds) { } public override bool Redo(PlanetFactory factory, PlayerAction_Build actionBuild) { //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Invalid comparison between Unknown and I4 //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Invalid comparison between Unknown and I4 //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) if (previews == null) { return false; } if (previews.Count <= 0) { return false; } BuildTool_Addon addonTool = actionBuild.addonTool; ((BuildTool)(object)addonTool).InitTool(); ((BuildTool)addonTool).buildPreviews.Clear(); ((BuildTool)addonTool).buildPreviews.AddRange(previews); bool flag; using (UndoManager.IgnoreAllEvents.On()) { addonTool.ActiveColliders(); if ((int)addonTool.handPrefabDesc.addonType == 1) { Array.Clear(addonTool.potentialBeltCursorArray, 0, addonTool.potentialBeltCursorArray.Length); for (int i = 0; i < ((BuildTool)addonTool).buildPreviews.Count; i++) { addonTool.FindPotentialBelt(i); addonTool.SnapToBelt(i); addonTool.SnapToBeltAutoAdjust(i); } Array.Clear(addonTool.potentialBeltCursorArray, 0, addonTool.potentialBeltCursorArray.Length); for (int j = 0; j < ((BuildTool)addonTool).buildPreviews.Count; j++) { addonTool.FindPotentialBeltStrict(j); } } else if ((int)addonTool.handPrefabDesc.addonType == 2) { BuildPreview val = previews[0]; int buildingsInAreaNonAlloc = factory.planet.physics.nearColliderLogic.GetBuildingsInAreaNonAlloc(previews[0].lpos, 2f, ref UndoBuild.tmpIds, false); if (buildingsInAreaNonAlloc > 0) { for (int k = 0; k < buildingsInAreaNonAlloc; k++) { int num = UndoBuild.tmpIds[k]; Pose objectPose = ((BuildTool)actionBuild.noneTool).GetObjectPose(num); PrefabDesc prefabDesc = ((BuildTool)actionBuild.noneTool).GetPrefabDesc(num); if (prefabDesc != null && prefabDesc.isStorage) { float num2 = prefabDesc.colliders[0].pos.y + prefabDesc.colliders[0].ext.y; Vector3 val2 = (((Vector3)(ref objectPose.position)).magnitude + num2) * ((Vector3)(ref objectPose.position)).normalized; Vector3 val3 = previews[0].lpos - val2; if (((Vector3)(ref val3)).magnitude < 0.1f) { val.inputObjId = num; addonTool.castObjectId = num; val.inputFromSlot = 13; val.inputToSlot = 0; break; } } } } } flag = addonTool.CheckBuildConditions(); if (flag) { addonTool.CreatePrebuilds(); } objectIds.Clear(); foreach (BuildPreview buildPreview in ((BuildTool)addonTool).buildPreviews) { objectIds.Add(buildPreview.objId); } if (objectIds.Count > 0) { if (!undoData.notifyBuildListeners.Contains(this)) { undoData.notifyBuildListeners.Add(this); } if (!undoData.notifyDismantleListeners.Contains(this)) { undoData.notifyDismantleListeners.Add(this); } } } previews.Clear(); previews = null; return flag; } } public class UndoBlueprint : UndoBuild { protected BlueprintData blueprint; protected Vector3[] dotsSnapped; protected float yaw; public UndoBlueprint(PlayerUndo undoData, IEnumerable objectIds, BlueprintData blueprint, Vector3[] dotsSnapped, float yaw) : base(undoData, objectIds) { this.blueprint = blueprint; this.dotsSnapped = dotsSnapped; this.yaw = yaw; } public override bool Undo(PlanetFactory factory, PlayerAction_Build actionBuild) { using (UndoManager.IgnoreAllEvents.On()) { RemoveHelper.excludeStationOverride = BlueprintTweaksPlugin.undoExcludeStations.Value; RemoveHelper.SwitchDelete(factory, objectIds); RemoveHelper.excludeStationOverride = false; } undoData.notifyBuildListeners.Remove(this); return true; } public override bool Redo(PlanetFactory factory, PlayerAction_Build actionBuild) { //IL_007f: 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_0114: Unknown result type (might be due to invalid IL or missing references) //IL_011b: 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_0110: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) if (blueprint == null) { return false; } if (dotsSnapped == null || dotsSnapped.Length == 0) { return false; } BuildTool_BlueprintPaste blueprintPasteTool = actionBuild.blueprintPasteTool; BlueprintData obj = blueprintPasteTool.blueprint; BlueprintData val = ((obj != null) ? obj.Clone() : null); string blueprintPath = blueprintPasteTool.blueprintPath; ((BuildTool)blueprintPasteTool)._OnOpen(); ((BuildTool)(object)blueprintPasteTool).InitTool(); blueprintPasteTool.yaw = yaw; Array.Clear(blueprintPasteTool.dotsSnapped, 0, blueprintPasteTool.dotsSnapped.Length); for (int i = 0; i < dotsSnapped.Length; i++) { blueprintPasteTool.dotsSnapped[i] = dotsSnapped[i]; } blueprintPasteTool.dotsCursor = dotsSnapped.Length; blueprintPasteTool.blueprint = blueprint; blueprintPasteTool.cursorValid = true; blueprintPasteTool.GenerateBlueprintGratBoxes(); blueprintPasteTool.DeterminePreviewsPrestage(true, false); bool result = false; using (UndoManager.IgnoreAllEvents.On()) { if (blueprintPasteTool.CheckBuildConditionsPrestage()) { blueprintPasteTool.ActiveColliders(actionBuild.model); bool flag = blueprintPasteTool.CheckBuildConditions(); blueprintPasteTool.DeactiveColliders(actionBuild.model); blueprintPasteTool.result = (EBlueprintPasteResult)(flag ? (blueprintPasteTool.result & -5) : (blueprintPasteTool.result | 4)); if (flag) { blueprintPasteTool.CreatePrebuilds(); result = true; } } } objectIds.Clear(); for (int j = 0; j < blueprintPasteTool.bpCursor; j++) { BuildPreview val2 = blueprintPasteTool.bpPool[j]; objectIds.Add(val2.objId); } if (objectIds.Count > 0) { if (!undoData.notifyBuildListeners.Contains(this)) { undoData.notifyBuildListeners.Add(this); } if (!undoData.notifyDismantleListeners.Contains(this)) { undoData.notifyDismantleListeners.Add(this); } } blueprintPasteTool.ResetStates(); blueprintPasteTool.blueprint = val; blueprintPasteTool.blueprintPath = blueprintPath; return result; } } public class UndoBuild : UndoAction { protected static int[] tmpIds = new int[20]; public static BuildingParameters undoClipboard = BuildingParameters.zero; protected List objectIds; protected List previews; protected static Dictionary tmpPreviews = new Dictionary(); public UndoBuild(PlayerUndo undoData, int objectId) : base(undoData) { objectIds = new List { objectId }; } public UndoBuild(PlayerUndo undoData, IEnumerable objectIds) : base(undoData) { this.objectIds = new List(objectIds); } public override void NotifyBuild(int preObjId, int postObjId) { int num = objectIds.FindIndex((int i) => preObjId == i); if (num >= 0) { objectIds[num] = postObjId; } } public override void NotifyDismantled(int objId) { objectIds.Remove(objId); } public override bool HasAnyPrebuilds() { return objectIds.Any((int i) => i < 0); } public override bool IsEmpty() { if (objectIds != null) { return objectIds.Count == 0; } return true; } public override bool Undo(PlanetFactory factory, PlayerAction_Build actionBuild) { bool result = SaveBuildData(factory, actionBuild); using (UndoManager.IgnoreAllEvents.On()) { foreach (int objectId in objectIds) { if (objectId != 0) { PrefabDesc prefabDesc = ((BuildTool)actionBuild.noneTool).GetPrefabDesc(objectId); if (prefabDesc == null || !prefabDesc.isStation || !BlueprintTweaksPlugin.undoExcludeStations.Value) { actionBuild.DoDismantleObject(objectId); } } } } undoData.notifyBuildListeners.Remove(this); undoData.notifyDismantleListeners.Remove(this); return result; } protected bool SaveBuildData(PlanetFactory factory, PlayerAction_Build actionBuild) { bool result = false; previews = new List(objectIds.Count); tmpPreviews.Clear(); foreach (int objectId in objectIds) { if (objectId > 0) { ref EntityData reference = ref factory.entityPool[objectId]; if (reference.id == objectId) { BuildPreview item = InitPreviewFromObject(factory, actionBuild, reference.id); previews.Add(item); result = true; } } else if (objectId < 0) { ref PrebuildData reference2 = ref factory.prebuildPool[-objectId]; if (reference2.id == -objectId) { BuildPreview item2 = InitPreviewFromObject(factory, actionBuild, -reference2.id); previews.Add(item2); result = true; } } } tmpPreviews.Clear(); return result; } private static BuildPreview InitPreviewFromObject(PlanetFactory factory, PlayerAction_Build actionBuild, int objectId, bool checkConn = true) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: 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_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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_007f: 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_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_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_0097: 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_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Expected O, but got Unknown BuildPreview val; if (tmpPreviews.ContainsKey(objectId)) { val = tmpPreviews[objectId]; } else { val = new BuildPreview(); val.ResetAll(); tmpPreviews.Add(objectId, val); } val.item = ((BuildTool)actionBuild.noneTool).GetItemProto(objectId); val.desc = ((BuildTool)actionBuild.noneTool).GetPrefabDesc(objectId); Pose objectPose = ((BuildTool)actionBuild.noneTool).GetObjectPose(objectId); Pose objectPose2 = ((BuildTool)actionBuild.noneTool).GetObjectPose2(objectId); val.lpos = objectPose.position; val.lrot = objectPose.rotation; val.lpos2 = objectPose2.position; val.lrot2 = objectPose2.rotation; ((BuildingParameters)(ref undoClipboard)).CopyFromFactoryObject(objectId, factory, true, false); val.recipeId = undoClipboard.recipeId; val.filterId = undoClipboard.filterId; val.parameters = undoClipboard.parameters; if (undoClipboard.parameters != null) { val.paramCount = undoClipboard.parameters.Length; } if (!checkConn) { return val; } bool flag = default(bool); int num = default(int); int num2 = default(int); factory.ReadObjectConn(objectId, 0, ref flag, ref num, ref num2); if (num != 0) { if (tmpPreviews.ContainsKey(num)) { val.output = tmpPreviews[num]; val.outputFromSlot = 0; val.outputToSlot = 1; } else { BuildPreview value = (val.output = new BuildPreview()); val.outputFromSlot = 0; val.outputToSlot = 1; val.objId = num; tmpPreviews.Add(num, value); } } return val; } public override bool Redo(PlanetFactory factory, PlayerAction_Build actionBuild) { //IL_0046: 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_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: 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_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_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) if (previews == null) { return false; } BuildTool_Click clickTool = actionBuild.clickTool; ((BuildTool)(object)clickTool).InitTool(); if (previews.Count == 1) { BuildPreview val = previews[0]; if (val.desc.multiLevel) { Vector3 val2 = val.lpos - val.lrot * val.desc.lapJoint; int buildingsInAreaNonAlloc = factory.planet.physics.nearColliderLogic.GetBuildingsInAreaNonAlloc(val2, 0.25f, ref tmpIds, false); if (buildingsInAreaNonAlloc > 0) { for (int i = 0; i < buildingsInAreaNonAlloc; i++) { int num = tmpIds[i]; Pose objectPose = ((BuildTool)actionBuild.noneTool).GetObjectPose(num); PrefabDesc prefabDesc = ((BuildTool)actionBuild.noneTool).GetPrefabDesc(num); if (prefabDesc != null && val.desc.modelIndex == prefabDesc.modelIndex) { Vector3 val3 = objectPose.position - val2; if (((Vector3)(ref val3)).magnitude < 0.1f) { val.inputObjId = num; val.inputFromSlot = 15; val.inputToSlot = 14; break; } } } } } } ((BuildTool)clickTool).buildPreviews.Clear(); ((BuildTool)clickTool).buildPreviews.AddRange(previews.Where((BuildPreview preview) => !preview.desc.isStation || !BlueprintTweaksPlugin.undoExcludeStations.Value)); bool flag; using (UndoManager.IgnoreAllEvents.On()) { clickTool.CheckInserters(); flag = clickTool.CheckBuildConditions(); if (flag) { clickTool.CreatePrebuilds(); } objectIds.Clear(); foreach (BuildPreview buildPreview in ((BuildTool)clickTool).buildPreviews) { objectIds.Add(buildPreview.objId); } if (objectIds.Count > 0) { if (!undoData.notifyBuildListeners.Contains(this)) { undoData.notifyBuildListeners.Add(this); } if (!undoData.notifyDismantleListeners.Contains(this)) { undoData.notifyDismantleListeners.Add(this); } } } previews.Clear(); previews = null; return flag; } } public class UndoDismantle : UndoBlueprint { public UndoDismantle(PlayerUndo undoData, IEnumerable objectIds, BlueprintData blueprint, Vector3[] dotsSnapped, float yaw) : base(undoData, objectIds, blueprint, dotsSnapped, yaw) { } public override bool Undo(PlanetFactory factory, PlayerAction_Build actionBuild) { return base.Redo(factory, actionBuild); } public override bool Redo(PlanetFactory factory, PlayerAction_Build actionBuild) { return base.Undo(factory, actionBuild); } } public struct UpgradeData { public int objId; public int oldGrade; public int newGrade; public UpgradeData(int objId, int oldGrade, int newGrade) { this.objId = objId; this.oldGrade = oldGrade; this.newGrade = newGrade; } } public class UndoUpgrade : UndoAction { public List targets; public UndoUpgrade(PlayerUndo undoData, IEnumerable targets) : base(undoData) { this.targets = new List(targets); } public override void NotifyBuild(int preObjId, int postObjId) { } public override void NotifyDismantled(int objId) { targets.RemoveAll((UpgradeData data) => data.objId == objId); } public override bool HasAnyPrebuilds() { return false; } public override bool IsEmpty() { if (targets != null) { return targets.Count == 0; } return false; } public override bool Undo(PlanetFactory factory, PlayerAction_Build actionBuild) { bool result = true; using (UndoManager.IgnoreAllEvents.On()) { int num = default(int); foreach (UpgradeData target in targets) { if (!actionBuild.DoUpgradeObject(target.objId, target.oldGrade, 0, ref num)) { result = false; if (num == 1) { BlueprintTweaksPlugin.logger.LogDebug((object)$"Can't upgrade {target.objId} to {target.oldGrade}, not enough items"); } } } return result; } } public override bool Redo(PlanetFactory factory, PlayerAction_Build actionBuild) { bool result = true; using (UndoManager.IgnoreAllEvents.On()) { int num = default(int); foreach (UpgradeData target in targets) { if (!actionBuild.DoUpgradeObject(target.objId, target.newGrade, 0, ref num)) { result = false; if (num == 1) { BlueprintTweaksPlugin.logger.LogDebug((object)$"Can't upgrade {target.objId} to {target.newGrade}, not enough items"); } } } return result; } } } public static class UndoManager { public static Dictionary undos = new Dictionary(); public static ToggleSwitch IgnoreAllEvents = new ToggleSwitch(); public static void Init() { if (NebulaModAPI.NebulaIsInstalled) { NebulaModAPI.OnPlayerJoinedGame = (Action)Delegate.Combine(NebulaModAPI.OnPlayerJoinedGame, new Action(OnPlayerJoined)); NebulaModAPI.OnPlayerLeftGame = (Action)Delegate.Combine(NebulaModAPI.OnPlayerLeftGame, new Action(OnPlayerLeft)); NebulaModAPI.OnMultiplayerGameStarted = (Action)Delegate.Combine(NebulaModAPI.OnMultiplayerGameStarted, new Action(OnGameStarted)); } ushort localUserId = GetLocalUserId(); undos.Add(localUserId, new PlayerUndo(localUserId)); } public static ushort GetLocalUserId() { if (NebulaModAPI.IsMultiplayerActive) { return NebulaModAPI.MultiplayerSession.LocalPlayer.Id; } return 1; } public static PlayerUndo GetPlayerData(int playerId) { return undos[(ushort)playerId]; } public static PlayerUndo GetCurrentPlayerData() { if (NebulaModAPI.IsMultiplayerActive) { IFactoryManager factories = NebulaModAPI.MultiplayerSession.Factories; if (factories.IsIncomingRequest.Value) { ushort key = (ushort)factories.PacketAuthor; return undos[key]; } } return undos[GetLocalUserId()]; } public static void OnPlayerJoined(IPlayerData player) { undos.Add(player.PlayerId, new PlayerUndo(player.PlayerId)); } public static void OnPlayerLeft(IPlayerData player) { undos.Remove(player.PlayerId); } public static void OnGameStarted() { IMultiplayerSession multiplayerSession = NebulaModAPI.MultiplayerSession; if (multiplayerSession.LocalPlayer.IsHost) { undos.Clear(); ushort localUserId = GetLocalUserId(); undos.Add(localUserId, new PlayerUndo(localUserId)); } } public static void TryUndo() { PlanetFactory factory = GameMain.localPlanet.factory; string message; bool sound; if (NebulaModAPI.IsMultiplayerActive) { IMultiplayerSession multiplayerSession = NebulaModAPI.MultiplayerSession; if (multiplayerSession.LocalPlayer.IsHost) { if (undos[GetLocalUserId()].TryUndo(factory, out message, out sound)) { UIRealtimeTip.Popup(Localization.Translate(message), sound, 0); } } else { multiplayerSession.Network.SendPacket(new UndoRequestPacket(GameMain.localPlanet?.id ?? (-1), multiplayerSession.LocalPlayer.Id)); } } else if (undos[GetLocalUserId()].TryUndo(factory, out message, out sound)) { UIRealtimeTip.Popup(Localization.Translate(message), sound, 0); } } public static void TryRedo() { PlanetFactory factory = GameMain.localPlanet.factory; string message; bool sound; if (NebulaModAPI.IsMultiplayerActive) { IMultiplayerSession multiplayerSession = NebulaModAPI.MultiplayerSession; if (multiplayerSession.LocalPlayer.IsHost) { if (undos[GetLocalUserId()].TryRedo(factory, out message, out sound)) { UIRealtimeTip.Popup(Localization.Translate(message), sound, 0); } } else { multiplayerSession.Network.SendPacket(new RedoRequestPacket(GameMain.localPlanet?.id ?? (-1), multiplayerSession.LocalPlayer.Id)); } } else if (undos[GetLocalUserId()].TryRedo(factory, out message, out sound)) { UIRealtimeTip.Popup(Localization.Translate(message), sound, 0); } } } public static class UndoUtils { public static void CheckInserters(this BuildTool_Click tool) { foreach (BuildPreview buildPreview in ((BuildTool)tool).buildPreviews) { if (buildPreview.desc.isInserter) { tool.MatchInserter(buildPreview); } } } public static void InitTool(this BuildTool tool) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown PlayerAction_Build actionBuild = tool.controller.actionBuild; if (actionBuild.model == null) { actionBuild.model = new BuildModel(); actionBuild.model.Init(actionBuild); } actionBuild.model.Open(); tool.SetFactoryReferences(); if (tool.tmpPackage == null) { tool.tmpPackage = new StorageComponent(tool.player.package.size); } if (tool.tmpPackage.size != tool.player.package.size) { tool.tmpPackage.SetSize(tool.player.package.size); } Array.Copy(tool.player.package.grids, tool.tmpPackage.grids, tool.tmpPackage.size); tool._Init(GameMain.data); } public static BlueprintData GenerateBlueprint(List objectIds, out Vector3 position) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_00dc: 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_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) position = Vector3.zero; Player mainPlayer = GameMain.mainPlayer; if ((Object)(object)((mainPlayer != null) ? mainPlayer.controller : null) == (Object)null) { return BlueprintData.CreateNew(); } if (GameMain.localPlanet == null) { return BlueprintData.CreateNew(); } BuildTool_BlueprintCopy blueprintCopyTool = GameMain.mainPlayer.controller.actionBuild.blueprintCopyTool; BlueprintData blueprint = blueprintCopyTool.blueprint; BlueprintData blueprint2 = ((blueprint != null) ? blueprint.Clone() : null); string blueprintPath = blueprintCopyTool.blueprintPath; using (UndoManager.IgnoreAllEvents.On()) { ((BuildTool)(object)blueprintCopyTool).InitTool(); blueprintCopyTool.selectedObjIds.Clear(); foreach (int objectId in objectIds) { blueprintCopyTool.selectedObjIds.Add(objectId); } blueprintCopyTool.blueprint = BlueprintData.CreateNew(); blueprintCopyTool.GenerateGratBox(); blueprintCopyTool.GenerateBlueprintData(); Vector2 minLongLat = GetMinLongLat(objectIds, blueprintCopyTool); float realRadius = GameMain.localPlanet.realRadius; position = BlueprintUtils.GetDir(minLongLat.x, minLongLat.y) * realRadius; position = ((BuildTool)blueprintCopyTool).actionBuild.planetAux.Snap(position, true); } BlueprintData blueprint3 = blueprintCopyTool.blueprint; blueprintCopyTool.blueprint = blueprint2; blueprintCopyTool.blueprintPath = blueprintPath; return blueprint3; } private static Vector2 GetMinLongLat(List objectIds, BuildTool_BlueprintCopy copy) { //IL_00da: 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_00a2: Unknown result type (might be due to invalid IL or missing references) float num = 10f; float num2 = 10f; float num3 = 0f; float num4 = 0f; foreach (int objectId in objectIds) { if (objectId > 0) { ref EntityData reference = ref ((BuildTool)copy).factory.entityPool[objectId]; if (reference.id == objectId) { BlueprintUtils.GetLongitudeLatitudeRad(((Vector3)(ref reference.pos)).normalized, ref num4, ref num3); if (num4 < num2) { num2 = num4; } if (num3 < num) { num = num3; } } } else { if (objectId >= 0) { continue; } ref PrebuildData reference2 = ref ((BuildTool)copy).factory.prebuildPool[-objectId]; if (reference2.id == -objectId) { BlueprintUtils.GetLongitudeLatitudeRad(((Vector3)(ref reference2.pos)).normalized, ref num4, ref num3); if (num4 < num2) { num2 = num4; } if (num3 < num) { num = num3; } } } } return new Vector2(num2, num); } } } namespace BlueprintTweaks.FactoryUndo.Nebula { public class ActionResultPacket { [RegisterPacketProcessor] public class ActionResultProcessor : BasePacketProcessor { public override void ProcessPacket(ActionResultPacket packet, INebulaConnection conn) { UIRealtimeTip.Popup(Localization.Translate(packet.message), packet.sound, 0); } } public string message { get; set; } public bool sound { get; set; } public ActionResultPacket() { } public ActionResultPacket(string message, bool sound) { this.message = message; this.sound = sound; } } public class ClearUndoRequestPacket { [RegisterPacketProcessor] public class ClearUndoRequestProcessor : BasePacketProcessor { public override void ProcessPacket(ClearUndoRequestPacket packet, INebulaConnection conn) { if (!NebulaModAPI.MultiplayerSession.LocalPlayer.IsHost) { return; } try { PlayerUndo playerData = UndoManager.GetPlayerData(packet.AuthorId); using (NebulaModAPI.MultiplayerSession.Factories.IsIncomingRequest.On()) { playerData.ResetUndo(); } } catch (KeyNotFoundException) { BlueprintTweaksPlugin.logger.LogWarning((object)$"Failed to reset player id {packet.AuthorId} undos"); } } } public int AuthorId { get; set; } public ClearUndoRequestPacket() { } public ClearUndoRequestPacket(int authorId) { AuthorId = authorId; } } public class RedoRequestPacket : IFactoryPacket { [RegisterPacketProcessor] public class RedoRequestHandler : RemoteFactoryProcessor { public override void ProcessPacket(PlanetFactory factory, PlayerAction_Build actionBuild, RedoRequestPacket packet, INebulaConnection conn) { if (UndoManager.undos[(ushort)packet.AuthorId].TryRedo(factory, out var message, out var sound)) { conn.SendPacket(new ActionResultPacket(message, sound)); } } } public int PlanetId { get; set; } public int AuthorId { get; set; } public RedoRequestPacket() { } public RedoRequestPacket(int planetId, int playerId) { AuthorId = playerId; PlanetId = planetId; } } public interface IFactoryPacket { int PlanetId { get; } int AuthorId { get; } } public abstract class RemoteFactoryProcessor : BasePacketProcessor where T : IFactoryPacket { public abstract void ProcessPacket(PlanetFactory factory, PlayerAction_Build actionBuild, T packet, INebulaConnection conn); public override void ProcessPacket(T packet, INebulaConnection conn) { PlanetData val = GameMain.galaxy.PlanetById(packet.PlanetId); if (val.factory == null) { return; } PlayerAction_Build val2 = (((Object)(object)GameMain.mainPlayer.controller != (Object)null) ? GameMain.mainPlayer.controller.actionBuild : null); BuildTool_BlueprintPaste blueprintPasteTool = val2.blueprintPasteTool; BuildTool_None noneTool = val2.noneTool; IFactoryManager factories = NebulaModAPI.MultiplayerSession.Factories; if (blueprintPasteTool != null) { factories.TargetPlanet = packet.PlanetId; factories.PacketAuthor = packet.AuthorId; PlanetFactory factory = null; bool flag = GameMain.localPlanet?.id != val.id; if (flag) { factory = ((BuildTool)blueprintPasteTool).factory; factories.AddPlanetTimer(packet.PlanetId); } factories.EventFactory = val.factory; ((BuildTool)blueprintPasteTool).factory = val.factory; ((BuildTool)noneTool).factory = val.factory; val2.factory = val.factory; using (factories.IsIncomingRequest.On()) { ProcessPacket(val.factory, val2, packet, conn); } if (flag) { ((BuildTool)blueprintPasteTool).factory = factory; ((BuildTool)noneTool).factory = factory; val2.factory = factory; } GameMain.mainPlayer.mecha.buildArea = Configs.freeMode.mechaBuildArea; factories.EventFactory = null; factories.TargetPlanet = -2; factories.PacketAuthor = -1; } } } public class UndoRequestPacket : IFactoryPacket { [RegisterPacketProcessor] public class UndoRequestHandler : RemoteFactoryProcessor { public override void ProcessPacket(PlanetFactory factory, PlayerAction_Build actionBuild, UndoRequestPacket packet, INebulaConnection conn) { if (UndoManager.undos[(ushort)packet.AuthorId].TryUndo(factory, out var message, out var sound)) { conn.SendPacket(new ActionResultPacket(message, sound)); } } } public int PlanetId { get; set; } public int AuthorId { get; set; } public UndoRequestPacket() { } public UndoRequestPacket(int planetId, int playerId) { AuthorId = playerId; PlanetId = planetId; } } } namespace BlueprintTweaks.DragToMoveBlueprints { [HarmonyPatch] public static class UIBlueprintBrowser_Patch { private static int dragThreshold = 4; private static Vector2 dragMouseBegin; private static RectTransform commonTools; private static UIDragBlueprint drag; private static Camera canvasCamera; [HarmonyPatch(typeof(UIBlueprintBrowser), "_OnCreate")] [HarmonyPostfix] public static void OnCreate() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown commonTools = (RectTransform)((Component)UIRoot.instance.uiGame).transform.Find("Common Tools"); GameObject val = BlueprintTweaksPlugin.resource.bundle.LoadAsset("Assets/BlueprintTweaks/UI/Browser/UIDragBlueprint.prefab"); GameObject val2 = Object.Instantiate(val, (Transform)(object)commonTools); drag = val2.GetComponent(); } [HarmonyPatch(typeof(UIBlueprintBrowser), "_OnUpdate")] [HarmonyPostfix] public static void OnUpdate(UIBlueprintBrowser __instance) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_007f: 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_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_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) Vector2 val = default(Vector2); if (drag.isActive || !UIRoot.ScreenPointIntoRect(Input.mousePosition, __instance.contentTrans, ref val)) { return; } int num = Mathf.FloorToInt((val.x - 5f) / 110f); int num2 = Mathf.FloorToInt((0f - val.y - 5f) / 120f); int num3 = num + num2 * 8; if (num < 0 || num >= 8 || num3 < 0 || num3 >= __instance.fileItems.Count) { return; } if (Input.GetMouseButtonDown(0)) { dragMouseBegin = Vector2.op_Implicit(Input.mousePosition); } if (Input.GetMouseButton(0)) { Vector2 val2 = Vector2.op_Implicit(Input.mousePosition) - dragMouseBegin; if (Mathf.Abs(val2.x) + Mathf.Abs(val2.y) > (float)dragThreshold && ((ManualBehaviour)__instance.fileItems[num3]).inited) { drag.SetHand(__instance.fileItems[num3]); } } } public static bool MouseInRect(this RectTransform rectTransform) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)canvasCamera == (Object)null) { canvasCamera = UIRoot.instance.overlayCanvas.worldCamera; } Vector2 val = Vector2.op_Implicit(Input.mousePosition); return RectTransformUtility.RectangleContainsScreenPoint(rectTransform, val, canvasCamera); } internal static string GetMoveTarget(UIBlueprintBrowser browser) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)drag.displayFile == (Object)null || drag.displayFile.fullPath.Equals("")) { return ""; } Vector2 val = default(Vector2); if (UIRoot.ScreenPointIntoRect(Input.mousePosition, browser.contentTrans, ref val)) { int num = Mathf.FloorToInt((val.x - 5f) / 110f); int num2 = Mathf.FloorToInt((0f - val.y - 5f) / 120f); if (num >= 0 && num < 8) { int num3 = num + num2 * 8; if (num3 >= 0 && num3 < browser.fileItems.Count) { UIBlueprintFileItem val2 = browser.fileItems[num3]; if (val2.isDirectory) { return val2.fullPath; } } } } try { UIBlueprintAddrItem val3 = browser.addrItems.First((UIBlueprintAddrItem item) => item.rectTrans.MouseInRect()); return val3.fullPath; } catch (InvalidOperationException) { } return ""; } internal static void CheckDragEnd(UIBlueprintBrowser browser) { string moveTarget = GetMoveTarget(browser); if (!moveTarget.Equals("")) { MoveToDir(browser, moveTarget); } } private static void MoveToDir(UIBlueprintBrowser browser, string targetPath) { string fullPath = drag.displayFile.fullPath; string text = fullPath.Split(new char[1] { '/' }).Last(); string text2 = CommonUtils.SlashDirectory(targetPath) + text; if (!drag.displayFile.isDirectory) { try { File.Move(fullPath, text2); } catch (IOException ex) { if (File.Exists(text2)) { UIMessageBox.Show(Localization.Translate("FileAlreadyExistsTitle"), Localization.Translate("FileAlreadyExistsDesc"), Localization.Translate("确定"), 1); } BlueprintTweaksPlugin.logger.LogWarning((object)("Error moving files: " + ex.Message)); return; } } else if (drag.displayFile.isDirectory) { if (targetPath.Equals(drag.displayFile.fullPath)) { return; } try { Directory.Move(fullPath, text2); } catch (IOException ex2) { if (Directory.Exists(text2)) { UIMessageBox.Show(Localization.Translate("FileAlreadyExistsTitle"), Localization.Translate("FileAlreadyExistsDesc"), Localization.Translate("确定"), 1); } BlueprintTweaksPlugin.logger.LogWarning((object)("Error moving files: " + ex2.Message)); return; } } browser.SetCurrentDirectory(browser.currentDirectoryInfo.FullName); } } public class UIDragBlueprint : MonoBehaviour { public RectTransform feedbackTrans; public Text feedbackText; private RectTransform rtrans; private UIBlueprintFileItem internalFile; private string lastPath; public UIBlueprintBrowser browser; public UIBlueprintFileItem displayFile; public bool isActive; private void Awake() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown browser = UIRoot.instance.uiGame.blueprintBrowser; rtrans = (RectTransform)((Component)this).transform; ((Component)feedbackTrans).gameObject.SetActive(false); SetActive(active: false); } private void Update() { //IL_003a: 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_0056: Expected O, but got Unknown //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0082: 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_009f: Invalid comparison between Unknown and I4 //IL_014a: Unknown result type (might be due to invalid IL or missing references) if (GameMain.mainPlayer == null || (Object)(object)displayFile == (Object)null || !isActive) { return; } if (!Input.GetMouseButton(0)) { UIBlueprintBrowser_Patch.CheckDragEnd(browser); SetActive(active: false); return; } Vector2 val = default(Vector2); if (UIRoot.ScreenPointIntoRect(Input.mousePosition, (RectTransform)((Transform)rtrans).parent, ref val)) { val.x = Mathf.Round(val.x); val.y = Mathf.Round(val.y); rtrans.anchoredPosition = val; PlayerController controller = GameMain.mainPlayer.controller; if ((int)controller.cmd.type == 5 && (controller.cmd.state > 0 || controller.cmd.mode == 3)) { SetActive(active: false); } } string moveTarget = UIBlueprintBrowser_Patch.GetMoveTarget(browser); if (moveTarget.Equals("")) { ((Component)feedbackTrans).gameObject.SetActive(false); } else if (!moveTarget.Equals(lastPath)) { ((Component)feedbackTrans).gameObject.SetActive(true); feedbackText.text = Localization.Translate("MoveBlueprintTip") + " " + GetRelativePath(moveTarget); feedbackTrans.sizeDelta = new Vector2(feedbackText.preferredWidth, 30f); } lastPath = moveTarget; } public static string GetRelativePath(string fullpath) { string text = CommonUtils.SlashDirectory(GameConfig.blueprintFolder); int length = text.Length; fullpath = CommonUtils.SlashDirectory(fullpath); if (fullpath.Equals(text, StringComparison.OrdinalIgnoreCase)) { return "/"; } if (fullpath.Length <= length) { return ""; } string text2 = fullpath.Substring(0, length); string result = fullpath.Substring(length, fullpath.Length - length); if (!text2.Equals(text, StringComparison.OrdinalIgnoreCase)) { return ""; } if (Directory.Exists(fullpath)) { return result; } return ""; } public void SetActive(bool active) { isActive = active; ((Component)this).gameObject.SetActive(active); if ((Object)(object)displayFile != (Object)null) { ((Component)displayFile).gameObject.SetActive(active); } if ((Object)(object)internalFile != (Object)null) { ((Component)internalFile).gameObject.SetActive(!active && ((ManualBehaviour)internalFile).inited); } if ((Object)(object)browser != (Object)null) { browser.browserScroll.vertical = !active; } } public void SetHand(UIBlueprintFileItem newItem) { //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: 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_0101: Expected O, but got Unknown //IL_007f: 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_0085: 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_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)newItem == (Object)null || newItem.fullPath.Equals("")) { SetActive(active: false); return; } if ((Object)(object)displayFile == (Object)null) { displayFile = Object.Instantiate(browser.fileItemPrefab, ((Component)this).transform); ((ManualBehaviour)displayFile)._Create(); ((ManualBehaviour)displayFile)._Init((object)null); ((ManualBehaviour)displayFile)._OnUnregEvent(); RectTransform val = (RectTransform)((Component)displayFile).gameObject.transform; val.sizeDelta *= 0.8f; ((Behaviour)((Component)displayFile).GetComponent()).enabled = false; } displayFile.SetItemLayout(0, newItem.isDirectory, newItem.fullPath, newItem.shortName); displayFile.rectTrans.anchoredPosition = Vector2.zero; internalFile = newItem; Vector2 val2 = default(Vector2); if (UIRoot.ScreenPointIntoRect(Input.mousePosition, (RectTransform)((Transform)rtrans).parent, ref val2)) { val2.x = Mathf.Round(val2.x); val2.y = Mathf.Round(val2.y); rtrans.anchoredPosition = val2; } SetActive(active: true); } } } namespace BlueprintTweaks.Nebula { public class RemoveRequestPacket : IFactoryPacket { [RegisterPacketProcessor] public class RemoveRequestHandler : RemoteFactoryProcessor { public override void ProcessPacket(PlanetFactory factory, PlayerAction_Build actionBuild, RemoveRequestPacket packet, INebulaConnection conn) { RemoveHelper.excludeStationOverride = packet.ExcludeStations; RemoveHelper.SwitchDelete(factory, packet.ObjIds.ToList()); RemoveHelper.excludeStationOverride = false; } } public int PlanetId { get; set; } public int[] ObjIds { get; set; } public int[] EdgeObjIds { get; set; } public int AuthorId { get; set; } public bool UseEdgeVariant { get; set; } public bool ExcludeStations { get; set; } public RemoveRequestPacket() { } public RemoveRequestPacket(int planetId, int[] objIds, int[] edgeObjIds, int authorId, bool variant, bool excludeStations) { AuthorId = authorId; PlanetId = planetId; ObjIds = objIds; EdgeObjIds = edgeObjIds; UseEdgeVariant = variant; ExcludeStations = excludeStations; } } public struct ItemPackageL { public int stack; public int item; public int inc; public ItemPackageL(int _item, int _stack, int _inc) { stack = _stack; item = _item; inc = _inc; } } public class ReturnItemsPacket { [RegisterPacketProcessor] public class ReturnItemsHandler : BasePacketProcessor { public override void ProcessPacket(ReturnItemsPacket packet, INebulaConnection conn) { List data = packet.GetData(); foreach (ItemPackageL item in data) { int num = GameMain.mainPlayer.TryAddItemToPackage(item.item, item.stack, item.stack, true, 0, false); UIItemup.Up(item.item, num); } } } public int dataCount { get; set; } public byte[] data { get; set; } public ReturnItemsPacket() { } public ReturnItemsPacket(Dictionary counts, Dictionary incCounts) { IWriterProvider binaryWriter = NebulaModAPI.GetBinaryWriter(); try { dataCount = counts.Count((KeyValuePair pair) => pair.Value > 0); foreach (KeyValuePair count in counts) { if (count.Value > 0) { binaryWriter.BinaryWriter.Write(count.Key); binaryWriter.BinaryWriter.Write(count.Value); binaryWriter.BinaryWriter.Write(incCounts[count.Key]); } } data = binaryWriter.CloseAndGetBytes(); } finally { ((IDisposable)binaryWriter)?.Dispose(); } } public List GetData() { List list = new List(dataCount); IReaderProvider binaryReader = NebulaModAPI.GetBinaryReader(data); try { for (int i = 0; i < dataCount; i++) { int item = binaryReader.BinaryReader.ReadInt32(); int stack = binaryReader.BinaryReader.ReadInt32(); int inc = binaryReader.BinaryReader.ReadInt32(); list.Add(new ItemPackageL(item, stack, inc)); } return list; } finally { ((IDisposable)binaryReader)?.Dispose(); } } } } namespace BlueprintTweaks.BrowserRememberFolder { [HarmonyPatch] public static class BuildTool_Copy_Patch { [HarmonyPatch(typeof(BuildTool_BlueprintCopy), "_OnOpen")] [HarmonyTranspiler] public static IEnumerable DontClearOpenPath(IEnumerable instructions) { //IL_0002: 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: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ldstr, (object)null, (string)null) }).SetInstruction(Transpilers.EmitDelegate>((Func)delegate { string openPath = UIRoot.instance.uiGame.blueprintBrowser.openPath; return BlueprintData.GenerateNewFileName(openPath); })); return val.InstructionEnumeration(); } } [HarmonyPatch] public static class UIBlueprintBrowser_Patch { [HarmonyPatch(typeof(UIBlueprintBrowser), "SetCurrentDirectory")] [HarmonyPostfix] public static void OnOpenDirectory(UIBlueprintBrowser __instance, string fullpath) { __instance.openPath = fullpath; } [HarmonyPatch(typeof(UIBlueprintBrowser), "_OnOpen")] [HarmonyTranspiler] public static IEnumerable DontClearOpenPath(IEnumerable instructions) { //IL_0002: 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: Expected O, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldstr, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)null, (string)null) }).SetOpcodeAndAdvance(OpCodes.Nop).SetInstructionAndAdvance(new CodeInstruction(OpCodes.Nop, (object)null)) .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Nop, (object)null)); return val.InstructionEnumeration(); } } } namespace BlueprintTweaks.BlueprintDataSaveEdit { public interface ICustomBlueprintDataSerializer { void Export(BlueprintData blueprint, BinaryWriter writer); void Import(BlueprintData blueprint, BinaryReader reader); } [HarmonyPatch] public static class BlueprintData_Patch_2 { private const byte INITIAL_VERSION = 1; private const byte CUSTOM_COLORS_VERSION = 2; private const byte ANCHOR_TYPE_VERSION = 3; private const byte CURRENT_DATA_VERSION = 4; internal static Dictionary customSerializers = new Dictionary(); [HarmonyPatch(typeof(BlueprintData), "Export")] [HarmonyPostfix] public static void Export(BlueprintData __instance, BinaryWriter w) { w.Write((byte)4); w.Write((byte)0); w.Write((byte)__instance.anchorType); w.Write((byte)__instance.autoReformMode); bool flag = customSerializers.Count > 0; w.Write(flag); if (flag) { InvokeCustomSerializers(__instance, w); } } [HarmonyPatch(typeof(BlueprintData), "Import")] [HarmonyPostfix] public static void Import(BlueprintData __instance, BinaryReader r) { //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0087: 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_009a: 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) if (r.BaseStream.Position == r.BaseStream.Length) { return; } byte b = r.ReadByte(); if ((b < 3) ? (b >= 1) : (r.ReadByte() == 1)) { if (b >= 1) { MigrateFoundationData(__instance, r); } if (b >= 2 && r.ReadBoolean()) { for (int i = 0; i < 16; i++) { Color32 val = Color32.op_Implicit(new Color(r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle())); __instance.reformData.customReformColors[i] = (uint)((val.r << 24) | (val.g << 16) | (val.b << 8) | val.a); } } } if (b >= 3) { __instance.anchorType = r.ReadByte(); } if (b >= 4) { __instance.autoReformMode = r.ReadByte(); if (r.ReadBoolean()) { HandleCustomData(__instance, r); } } } private static void MigrateFoundationData(BlueprintData __instance, BinaryReader r) { int num = r.ReadInt32(); BlueprintTweaksPlugin.logger.LogWarning((object)$"Blueprint has {num} old foundations, performing migration."); Dictionary dictionary = new Dictionary(); for (int i = 0; i < num; i++) { r.ReadByte(); byte b = (byte)r.ReadInt32(); if (b < __instance.areas.Length) { BlueprintArea val = __instance.areas[b]; if (!dictionary.TryGetValue(b, out var value)) { value = (dictionary[b] = new byte[val.width * val.height]); } int num2 = r.ReadInt32(); int num3 = r.ReadInt32(); byte b2 = (byte)((num2 << 5) + (num3 & 0x1F)); float num4 = r.ReadSingle(); float num5 = r.ReadSingle(); int num6 = Mathf.RoundToInt(num4); int num7 = Mathf.RoundToInt(num5); int areaSegments = val.areaSegments; if (num7 >= areaSegments * 5) { num7 -= areaSegments * 5; } int num8 = num6 * val.width + num7; value[num8] = b2; } } List list = new List(32); uint[] array2 = null; for (int j = 0; j < __instance.areas.Length; j++) { if (dictionary.ContainsKey(j)) { BlueprintArea val2 = __instance.areas[j]; byte[] array3 = dictionary[j]; BlueprintUtils.GenerateReformRect(ref list, ref array2, array3, val2.width, val2.height, (byte)j); } } BlueprintTweaksPlugin.logger.LogWarning((object)$"Optimized reform count: {list.Count}"); __instance.reformData.rects = list.ToArray(); } private static void InvokeCustomSerializers(BlueprintData __instance, BinaryWriter w) { foreach (KeyValuePair customSerializer in customSerializers) { using MemoryStream memoryStream = new MemoryStream(); using BinaryWriter writer = new BinaryWriter(memoryStream); try { customSerializer.Value.Export(__instance, writer); } catch (Exception arg) { BlueprintTweaksPlugin.logger.LogWarning((object)$"Exception while executing {customSerializer.Key} custom blueprint data serializer: \n{arg}"); goto end_IL_0025; } byte[] array = memoryStream.ToArray(); if (array.Length > 32767) { BlueprintTweaksPlugin.logger.LogWarning((object)"Error: Custom blueprint serializer wrote more than 32767 bytes! This is not supported."); continue; } w.Write(value: true); w.Write(customSerializer.Key); w.Write((short)array.Length); w.Write(array); end_IL_0025:; } w.Write(value: false); } private static void HandleCustomData(BlueprintData __instance, BinaryReader r) { while (r.ReadBoolean()) { string text = r.ReadString(); short num = r.ReadInt16(); if (num == 0) { continue; } byte[] buffer = r.ReadBytes(num); if (!customSerializers.ContainsKey(text)) { BlueprintTweaksPlugin.logger.LogWarning((object)("Blueprint contains serialized data for " + text + ", but such serializer is not registered!")); continue; } ICustomBlueprintDataSerializer customBlueprintDataSerializer = customSerializers[text]; using MemoryStream input = new MemoryStream(buffer); using BinaryReader reader = new BinaryReader(input); try { customBlueprintDataSerializer.Import(__instance, reader); } catch (Exception arg) { BlueprintTweaksPlugin.logger.LogWarning((object)$"Exception while executing {text} custom blueprint data serializer: \n{arg}"); } } } } } namespace BlueprintTweaks.BlueprintBrowserUIChanges { [HarmonyPatch] public static class UIBlueprintBrowserPatch { public static UIBlueprintFileItem lastClickedFile; [HarmonyPatch(typeof(UIBlueprintBrowser), "_OnCreate")] [HarmonyPostfix] public static void OnCreate(UIBlueprintBrowser __instance) { //IL_0010: 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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_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_005a: 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_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0089: 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_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Expected O, but got Unknown //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Expected O, but got Unknown //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Expected O, but got Unknown __instance.addrTrans.offsetMin = new Vector2(280f, -36f); RectTransform val = (RectTransform)((Component)__instance.upLevelButton).transform; val.anchoredPosition += new Vector2(45f, 0f); RectTransform val2 = (RectTransform)((Component)__instance.newFolderButton).transform; val2.anchoredPosition += new Vector2(45f, 0f); RectTransform val3 = (RectTransform)((Component)__instance.newFileButton).transform; val3.anchoredPosition += new Vector2(45f, 0f); GameObject gameObject = ((Component)__instance.cutButton).gameObject; GameObject val4 = Object.Instantiate(gameObject, gameObject.transform.parent, true); RectTransform val5 = (RectTransform)val4.transform; val5.anchoredPosition = new Vector2(82f, 2f); val5.sizeDelta = new Vector2(40f, 40f); RectTransform val6 = (RectTransform)((Transform)val5).Find("icon"); Sprite sprite = BlueprintTweaksPlugin.resource.bundle.LoadAsset("Assets/BlueprintTweaks/Icons/paste-icon.png"); ((Component)val6).GetComponent().sprite = sprite; UIButton component = ((Component)val5).GetComponent(); component.tips.tipTitle = "BPBrowserPasteButtonTipTitle"; component.tips.tipText = "BPBrowserPasteButtonTipDesc"; Button component2 = ((Component)val5).GetComponent