Decompiled source of DemolishAll v1.0.3

DemolishAll.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SuperFantasyKingdom;
using SuperFantasyKingdom.Buildings;
using SuperFantasyKingdom.UI;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Localization;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("AWSSDK.CognitoIdentity")]
[assembly: IgnoresAccessChecksTo("AWSSDK.CognitoSync")]
[assembly: IgnoresAccessChecksTo("AWSSDK.Core")]
[assembly: IgnoresAccessChecksTo("AWSSDK.Kinesis")]
[assembly: IgnoresAccessChecksTo("AWSSDK.SecurityToken")]
[assembly: IgnoresAccessChecksTo("com.games-farm.platforms.wingdk.public.runtime")]
[assembly: IgnoresAccessChecksTo("com.rlabrecque.steamworks.net")]
[assembly: IgnoresAccessChecksTo("FMODUnity")]
[assembly: IgnoresAccessChecksTo("FMODUnityResonance")]
[assembly: IgnoresAccessChecksTo("GalaxyCSharp")]
[assembly: IgnoresAccessChecksTo("GamesFarm.Platforms.WinGDK.Private.Core")]
[assembly: IgnoresAccessChecksTo("GamesFarm.Platforms.WinGDK.Private.Runtime")]
[assembly: IgnoresAccessChecksTo("I18N.CJK")]
[assembly: IgnoresAccessChecksTo("I18N")]
[assembly: IgnoresAccessChecksTo("I18N.MidEast")]
[assembly: IgnoresAccessChecksTo("I18N.Other")]
[assembly: IgnoresAccessChecksTo("I18N.Rare")]
[assembly: IgnoresAccessChecksTo("I18N.West")]
[assembly: IgnoresAccessChecksTo("Mono.Security")]
[assembly: IgnoresAccessChecksTo("netstandard")]
[assembly: IgnoresAccessChecksTo("Newtonsoft.Json")]
[assembly: IgnoresAccessChecksTo("PrimeTween.Runtime")]
[assembly: IgnoresAccessChecksTo("Textus.SerializeReferenceUI")]
[assembly: IgnoresAccessChecksTo("UniTask.Addressables")]
[assembly: IgnoresAccessChecksTo("UniTask")]
[assembly: IgnoresAccessChecksTo("UniTask.DOTween")]
[assembly: IgnoresAccessChecksTo("UniTask.Linq")]
[assembly: IgnoresAccessChecksTo("UniTask.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.2D.Animation.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.2D.Common.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.2D.IK.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.2D.PixelPerfect")]
[assembly: IgnoresAccessChecksTo("Unity.2D.SpriteShape.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.2D.Tilemap.Extras")]
[assembly: IgnoresAccessChecksTo("Unity.Addressables")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.InternalAPIEngineBridge.001")]
[assembly: IgnoresAccessChecksTo("Unity.InternalAPIEngineBridge.013")]
[assembly: IgnoresAccessChecksTo("Unity.Localization")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Microsoft.GDK")]
[assembly: IgnoresAccessChecksTo("Unity.Microsoft.GDK.Tools")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipeline.Universal.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Universal.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Universal.Shaders")]
[assembly: IgnoresAccessChecksTo("Unity.ResourceManager")]
[assembly: IgnoresAccessChecksTo("Unity.ScriptableBuildPipeline")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("UnityEngine.AccessibilityModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.AIModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.AndroidJNIModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.AnimationModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.AssetBundleModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.AudioModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ClothModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ClusterInputModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ClusterRendererModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.CoreModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.CrashReportingModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.DirectorModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine")]
[assembly: IgnoresAccessChecksTo("UnityEngine.DSPGraphModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.GameCenterModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.GIModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.GridModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.HotReloadModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ImageConversionModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.IMGUIModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.InputLegacyModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.InputModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.JSONSerializeModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.LocalizationModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ParticleSystemModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.PerformanceReportingModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.Physics2DModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.PhysicsModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ProfilerModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.RuntimeInitializeOnLoadManagerInitializerModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ScreenCaptureModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.SharedInternalsModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.SpriteMaskModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.SpriteShapeModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.StreamingModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.SubstanceModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.SubsystemsModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.TerrainModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.TerrainPhysicsModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.TextCoreFontEngineModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.TextCoreTextEngineModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.TextRenderingModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.TilemapModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.TLSModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UIElementsModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UIElementsNativeModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UIModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UmbraModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UNETModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UnityAnalyticsCommonModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UnityAnalyticsModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UnityConnectModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UnityCurlModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UnityTestProtocolModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UnityWebRequestAssetBundleModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UnityWebRequestAudioModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UnityWebRequestModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UnityWebRequestTextureModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UnityWebRequestWWWModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.VehiclesModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.VFXModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.VideoModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.VirtualTexturingModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.VRModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.WindModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.XRModule")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyCompany("DemolishAll")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+155184cb19822b911a69e527ad08a87599b048d5")]
[assembly: AssemblyProduct("DemolishAll")]
[assembly: AssemblyTitle("DemolishAll")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DemolishAll
{
	[BepInPlugin("DemolishAll", "DemolishAll", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private Harmony _harmony = new Harmony("DemolishAll");

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin DemolishAll is loaded!");
			_harmony.PatchAll();
		}

		private void OnApplicationQuit()
		{
			_harmony.UnpatchSelf();
		}

		private void OnDestroy()
		{
			_harmony.UnpatchSelf();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "DemolishAll";

		public const string PLUGIN_NAME = "DemolishAll";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}
namespace DemolishAll.Patches
{
	[HarmonyPatch]
	public static class UIOverlayMessage_SetAccept_Patch
	{
		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(UIOverlayMessage), "SetAccept", new Type[]
		{
			typeof(ResourceAmount),
			typeof(UnityAction)
		})]
		public static Button SetAcceptCost(UIOverlayMessage instance, ResourceAmount cost, UnityAction action)
		{
			throw new NotImplementedException();
		}
	}
	[HarmonyPatch(typeof(BuildingCity), "Demolish")]
	public static class Patch_HouseDemolish_DespawnWorkers
	{
		private static void Postfix(BuildingCity __instance)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			List<Worker> worker = JobManager.Instance.GetWorker();
			if (worker == null)
			{
				return;
			}
			foreach (Worker item in worker.ToList())
			{
				if (!((Object)(object)item == (Object)null) && (Object)(object)__instance == (Object)(object)item.GetHome())
				{
					JobManager.Instance.UnregisterWorker(item);
					Object.Destroy((Object)(object)((Component)item).gameObject);
				}
			}
		}
	}
	[HarmonyPatch(typeof(UIBuildingOverlayElementDemolish), "Select")]
	public static class Patch_DemolishSelectGuard
	{
		private static bool Prefix(UIBuildingOverlayElementDemolish __instance)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			OverlayManager overlayManager = OverlayManager.Instance;
			if ((Object)(object)overlayManager == (Object)null || __instance == null)
			{
				return false;
			}
			overlayManager.CloseOverlay(false);
			UIOverlayMessage obj = overlayManager.OverlayMessage(true);
			obj.SetCancel("", (UnityAction)delegate
			{
				overlayManager.Cancel(true);
			});
			LocalizedString stringMessage = __instance.stringMessage;
			string message = ((stringMessage != null) ? stringMessage.GetLocalizedString() : null) ?? "Demolish this building?";
			obj.SetMessage(message);
			UIOverlayMessage_SetAccept_Patch.SetAcceptCost(action: (UnityAction)delegate
			{
				if (__instance != null)
				{
					__instance.Callback();
				}
			}, instance: obj, cost: new ResourceAmount((ResourceType)31, 1));
			return false;
		}
	}
	[HarmonyPatch(typeof(UIBuildingOverlay), "Open")]
	public static class Patch_Demolish
	{
		[CompilerGenerated]
		private sealed class <MoveNextFrame>d__4 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <MoveNextFrame>d__4(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00da: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_00cb: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					_moveScheduled = false;
					GameObject val = GameObject.Find("Canvas/UICanvasPP/Overlay/SizeSelection/Panel/Selection");
					if ((Object)(object)val == (Object)null)
					{
						Plugin.Logger.LogInfo((object)"Selection container not found.");
						return false;
					}
					Transform val2 = (from Transform t in (IEnumerable)val.transform
						where ((Object)t).name.StartsWith("OverlayElementDemolish")
						select t).LastOrDefault();
					if ((Object)(object)val2 == (Object)null)
					{
						Plugin.Logger.LogInfo((object)"OverlayElementDemolish(Clone) not found.");
						return false;
					}
					RectTransform val3 = (RectTransform)(object)((val2 is RectTransform) ? val2 : null);
					if (val3 != null)
					{
						Vector2 anchoredPosition = val3.anchoredPosition;
						anchoredPosition.y -= Y_OFFSET;
						val3.anchoredPosition = anchoredPosition;
					}
					else
					{
						Vector3 localPosition = val2.localPosition;
						localPosition.y -= 0.2f;
						val2.localPosition = localPosition;
					}
					return false;
				}
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static bool _moveScheduled = false;

		private static float Y_OFFSET = 50f;

		private static void Prefix(UIBuildingOverlay __instance, bool force)
		{
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			UIBuildingOverlayElementDemolish val = null;
			Building building = __instance.building;
			if ((Object)(object)building == (Object)null || !(building is BuildingCity) || building is BuildingCastle)
			{
				return;
			}
			List<UIBuildingOverlayElement> list = __instance.buttons;
			if (list == null)
			{
				list = (__instance.buttons = new List<UIBuildingOverlayElement>());
			}
			if (list.Any((UIBuildingOverlayElement b) => b is UIBuildingOverlayElementDemolish))
			{
				return;
			}
			UIBuildingOverlay[] array = Object.FindObjectsOfType<UIBuildingOverlay>(true);
			for (int i = 0; i < array.Length; i++)
			{
				List<UIBuildingOverlayElement> buttons = array[i].buttons;
				if (buttons != null)
				{
					UIBuildingOverlayElement? obj = ((IEnumerable<UIBuildingOverlayElement>)buttons).FirstOrDefault((Func<UIBuildingOverlayElement, bool>)((UIBuildingOverlayElement e) => e is UIBuildingOverlayElementDemolish));
					val = (UIBuildingOverlayElementDemolish)(object)((obj is UIBuildingOverlayElementDemolish) ? obj : null);
					if (val != null)
					{
						break;
					}
				}
			}
			if (val != null)
			{
				Plugin.Logger.LogInfo((object)"Found existing demolish");
				UIBuildingOverlayElementDemolish item = ClassExtensions.Clone<UIBuildingOverlayElementDemolish>(val);
				list.Add((UIBuildingOverlayElement)(object)item);
			}
			else
			{
				Plugin.Logger.LogInfo((object)"No demolish element found, creating a new one.");
				list.Add((UIBuildingOverlayElement)new UIBuildingOverlayElementDemolish());
			}
		}

		private static void Postfix(UIBuildingOverlay __instance, bool force)
		{
			if (!_moveScheduled)
			{
				_moveScheduled = true;
				((MonoBehaviour)OverlayManager.Instance).StartCoroutine(MoveNextFrame());
			}
		}

		[IteratorStateMachine(typeof(<MoveNextFrame>d__4))]
		private static IEnumerator MoveNextFrame()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <MoveNextFrame>d__4(0);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}