Decompiled source of DSPMassCopyPaste v1.0.0

DSPMassCopyPaste.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using CommonAPI;
using CommonAPI.Systems;
using CommonAPI.Systems.ModLocalization;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("DSPMassCopyPaste")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+8d5145fba47ff387ed1d1ae7246a17bb20001652")]
[assembly: AssemblyProduct("DSPMassCopyPaste")]
[assembly: AssemblyTitle("DSPMassCopyPaste")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DSPMassCopyPaste
{
	[BepInPlugin("com.themeinsideamind.dsp.masscopypaste", "DSP Mass Copy Paste", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[CommonAPISubmoduleDependency(new string[] { "CustomKeyBindSystem", "LocalizationModule" })]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "com.themeinsideamind.dsp.masscopypaste";

		internal const string KeyName = "MassPasteBuildingSettings";

		private void Awake()
		{
			//IL_0002: 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_0014: 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)
			CustomKeyBindSystem.RegisterKeyBind<PressKeyBind>(new BuiltinKey
			{
				key = new CombineKey(118, (byte)3, (ECombineKeyAction)0, false),
				conflictGroup = 2052,
				name = "MassPasteBuildingSettings",
				canOverride = true
			});
			Strings.Register();
			Harmony.CreateAndPatchAll(typeof(Patches), "com.themeinsideamind.dsp.masscopypaste");
		}

		private void Update()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			Player mainPlayer = GameMain.mainPlayer;
			PlayerController val = ((mainPlayer != null) ? mainPlayer.controller : null);
			PlayerAction_Build val2 = val?.actionBuild;
			if (val2 == null)
			{
				return;
			}
			if ((int)val2.blueprintMode != 1)
			{
				Patches.Pending = Patches.PendingAction.None;
				MassPasteMode.OnCopyModeLeft(val2);
				if (!VFInput.inputing && CustomKeyBindSystem.GetKeyBind("MassPasteBuildingSettings").keyValue)
				{
					MassPasteMode.Enter(val);
				}
			}
			else if (!VFInput.inputing && CustomKeyBindSystem.GetKeyBind("MassPasteBuildingSettings").keyValue)
			{
				Patches.Pending = ((!MassPasteMode.Active) ? Patches.PendingAction.PasteSelection : Patches.PendingAction.Exit);
			}
		}
	}
	internal static class MassPasteMode
	{
		internal static bool Active;

		private static BlueprintData savedBlueprintClipboard;

		private static bool restorePending;

		internal static void Enter(PlayerController controller)
		{
			//IL_0013: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Invalid comparison between Unknown and I4
			if (GameMain.localPlanet?.factory == null || ((int)UIGame.viewMode != 0 && (int)UIGame.viewMode != 1))
			{
				return;
			}
			if ((int)BuildingParameters.clipboard.type == 0)
			{
				UIRealtimeTip.Popup(Localization.Translate("MassPaste_NothingCopied"), true, 0);
				return;
			}
			PlayerAction_Build actionBuild = controller.actionBuild;
			savedBlueprintClipboard = actionBuild.blueprintClipboard;
			restorePending = true;
			Active = true;
			controller.OpenBlueprintCopyMode(true);
			if ((int)actionBuild.blueprintMode != 1)
			{
				Active = false;
				restorePending = false;
				savedBlueprintClipboard = null;
				UIRealtimeTip.Popup(Localization.Translate("MassPaste_NeedsBlueprints"), true, 0);
			}
		}

		internal static void OnToolClosed(BuildTool_BlueprintCopy tool)
		{
			Active = false;
			RestoreClipboard(((BuildTool)tool).actionBuild);
		}

		internal static void OnCopyModeLeft(PlayerAction_Build actionBuild)
		{
			Active = false;
			if (!((BuildTool)actionBuild.blueprintCopyTool).active)
			{
				RestoreClipboard(actionBuild);
			}
		}

		private static void RestoreClipboard(PlayerAction_Build actionBuild)
		{
			if (restorePending)
			{
				restorePending = false;
				actionBuild.blueprintClipboard = savedBlueprintClipboard;
				savedBlueprintClipboard = null;
			}
		}
	}
	internal static class Patches
	{
		internal enum PendingAction
		{
			None,
			PasteSelection,
			Exit
		}

		internal static PendingAction Pending;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(BuildTool_BlueprintCopy), "Operating")]
		private static bool Operating_Prefix(BuildTool_BlueprintCopy __instance)
		{
			PendingAction pending = Pending;
			Pending = PendingAction.None;
			switch (pending)
			{
			case PendingAction.PasteSelection:
				MassPaste(__instance);
				return false;
			case PendingAction.Exit:
				((BuildTool)__instance)._Close();
				((BuildTool)__instance).actionBuild.Close();
				return false;
			default:
				return true;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(BuildTool_BlueprintCopy), "Operating")]
		private static void Operating_Postfix(BuildTool_BlueprintCopy __instance)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (MassPasteMode.Active && ((BuildTool)__instance).active && (int)__instance.currSelectMethod == 0 && (__instance.selectedObjIds.Count != 0 || __instance.hasReform))
			{
				if (__instance.selectedObjIds.Count > 0)
				{
					MassPaste(__instance);
				}
				__instance.ClearSelection();
				__instance.RefreshBlueprintData();
				__instance.DeterminePreviews();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(BuildTool_BlueprintCopy), "_OnOpen")]
		private static void OnOpen_Postfix()
		{
			if (MassPasteMode.Active)
			{
				((ManualBehaviour)UIRoot.instance.uiGame.blueprintCopyInspector)._Close();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(BuildTool_BlueprintCopy), "_OnClose")]
		private static void OnClose_Postfix(BuildTool_BlueprintCopy __instance)
		{
			MassPasteMode.OnToolClosed(__instance);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(BuildTool_BlueprintCopy), "UseToPasteNow")]
		private static bool UseToPasteNow_Prefix()
		{
			return !MassPasteMode.Active;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIGeneralTips), "_OnUpdate")]
		private static void UIGeneralTips_OnUpdate_Postfix(UIGeneralTips __instance)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			if (MassPasteMode.Active && (int)UIGame.viewMode == 1)
			{
				__instance.modeText.text = Localization.Translate("MassPaste_ModeName");
				((Component)__instance.promptText).gameObject.SetActive(true);
				__instance.promptText.text = Localization.Translate("MassPaste_ModeHint");
			}
		}

		private static void MassPaste(BuildTool_BlueprintCopy tool)
		{
			//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_0010: 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_00c3: 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)
			PlanetFactory factory = ((BuildTool)tool).factory;
			BuildingParameters clipboard = BuildingParameters.clipboard;
			if (factory == null || (int)clipboard.type == 0)
			{
				UIRealtimeTip.Popup(Localization.Translate("MassPaste_NothingCopied"), true, 0);
				return;
			}
			if (tool.selectedObjIds.Count == 0)
			{
				UIRealtimeTip.Popup(Localization.Translate("MassPaste_NothingSelected"), true, 0);
				return;
			}
			int[] array = new int[tool.selectedObjIds.Count];
			tool.selectedObjIds.CopyTo(array);
			int num = 0;
			int[] array2 = array;
			foreach (int num2 in array2)
			{
				if (((BuildingParameters)(ref clipboard)).PasteToFactoryObject(num2, factory))
				{
					if (num2 > 0)
					{
						factory.EntityAutoReplenishIfNeeded(num2, Vector2.zero, false);
					}
					factory.OnPasteBuildingSetting(num2);
					num++;
				}
			}
			if (num > 0)
			{
				VFAudio.Create("equip-1", GameMain.mainPlayer.transform, Vector3.zero, true, 4, -1, -1L);
				UIRealtimeTip.Popup((num == 1) ? Localization.Translate("MassPaste_PastedOne") : string.Format(Localization.Translate("MassPaste_PastedMany"), num), false, 0);
			}
			else
			{
				UIRealtimeTip.Popup(Localization.Translate("MassPaste_NoneAccepted"), true, 0);
			}
		}
	}
	internal static class Strings
	{
		internal const string ModeName = "MassPaste_ModeName";

		internal const string ModeHint = "MassPaste_ModeHint";

		internal const string NothingCopied = "MassPaste_NothingCopied";

		internal const string NothingSelected = "MassPaste_NothingSelected";

		internal const string NeedsBlueprints = "MassPaste_NeedsBlueprints";

		internal const string PastedOne = "MassPaste_PastedOne";

		internal const string PastedMany = "MassPaste_PastedMany";

		internal const string NoneAccepted = "MassPaste_NoneAccepted";

		internal static void Register()
		{
			LocalizationModule.RegisterTranslation("KEYMassPasteBuildingSettings", "Mass paste mode (paste building settings)", "批量粘贴模式(粘贴建筑设置)", "Mode collage en masse (coller les paramètres de bâtiment)");
			LocalizationModule.RegisterTranslation("MassPaste_ModeName", "Mass Paste Mode", "批量粘贴模式", "Mode collage en masse");
			LocalizationModule.RegisterTranslation("MassPaste_ModeHint", "Drag a box over buildings to paste the copied settings. Right-click to exit.", "框选建筑即可粘贴已复制的设置。右键退出。", "Tracez un cadre sur les bâtiments pour y coller les paramètres copiés. Clic droit pour quitter.");
			LocalizationModule.RegisterTranslation("MassPaste_NothingCopied", "Nothing copied. Copy a building's settings first.", "尚未复制任何设置。请先复制一个建筑的设置。", "Rien n'a été copié. Copiez d'abord les paramètres d'un bâtiment.");
			LocalizationModule.RegisterTranslation("MassPaste_NothingSelected", "Nothing selected.", "未选择任何建筑。", "Aucune sélection.");
			LocalizationModule.RegisterTranslation("MassPaste_NeedsBlueprints", "Mass paste mode needs blueprints to be researched.", "批量粘贴模式需要先研究蓝图。", "Le mode collage en masse nécessite la recherche des plans.");
			LocalizationModule.RegisterTranslation("MassPaste_PastedOne", "Pasted settings to 1 building", "已将设置粘贴到 1 个建筑", "Paramètres collés sur 1 bâtiment");
			LocalizationModule.RegisterTranslation("MassPaste_PastedMany", "Pasted settings to {0} buildings", "已将设置粘贴到 {0} 个建筑", "Paramètres collés sur {0} bâtiments");
			LocalizationModule.RegisterTranslation("MassPaste_NoneAccepted", "No selected building accepts the copied settings.", "所选建筑均无法应用已复制的设置。", "Aucun bâtiment sélectionné n'accepte les paramètres copiés.");
		}
	}
}