Decompiled source of UnlimitedTownBuilding v1.2.2

UnlimitedTownBuilding.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("UnlimitedTownBuilding")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCompany("Glowstick")]
[assembly: AssemblyProduct("UnlimitedTownBuilding")]
[assembly: AssemblyCopyright("Copyright © Glowstick 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5450fe0-edcf-483f-b9ea-4b1ef9d36da7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace UnlimitedTownBuilding;

[BepInPlugin("Glowstick.UnlimitedTownBuilding", "UnlimitedTownBuilding", "1.2.0")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(BuildingResourcesManager), "GetCanDeployNewBuilding")]
	public class BuildingResourcesManager_GetCanDeployNewBuilding
	{
		private static void Prefix(BuildingResourcesManager __instance)
		{
			__instance.m_specializedBuildingCount = 0;
			__instance.m_houseCount = 0;
		}
	}

	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	public class OrientOnTerrain_HasEnoughRoom
	{
		private static void Prefix(OrientOnTerrain __instance)
		{
			if (ignoreColliders.Value)
			{
				__instance.m_detectionScript.Disable();
			}
		}
	}

	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	public class OrientOnTerrain_IsValid
	{
		private static void Prefix(OrientOnTerrain __instance)
		{
			if (ignoreColliders.Value)
			{
				__instance.m_placementValid = true;
			}
		}
	}

	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	public class BuildingResourcesManager_CanBaseBuildInCurrentScene
	{
		private static void Prefix(BuildingResourcesManager __instance)
		{
			__instance.m_canBaseBuildInCurrentScene = true;
		}
	}

	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	public class Building_IsHouse
	{
		private static void Prefix(Building __instance)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			__instance.BuildingType = (BuildingTypes)2;
		}
	}

	[HarmonyPatch(typeof(BuildingResourcesManager), "GetResourceValue")]
	public class BuildingResourcesManager_GetResourceValue
	{
		private static void Prefix(BuildingResourcesManager __instance)
		{
			if (infiniteResources.Value)
			{
				__instance.m_resources[0].Value = 99999;
				__instance.m_resources[1].Value = 99999;
				__instance.m_resources[2].Value = 99999;
				__instance.m_resources[3].Value = 99999;
			}
			else
			{
				__instance.m_resources[0].Value = 0;
				__instance.m_resources[1].Value = 0;
				__instance.m_resources[2].Value = 0;
				__instance.m_resources[3].Value = 0;
			}
		}
	}

	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	public class BuildingResourcesManager_HousingValue
	{
		private static void Prefix(BuildingResourcesManager __instance)
		{
			__instance.m_housingValue = 999;
			__instance.m_specializedBuildingCount = 15;
			__instance.m_activeSpecializedBuildingCount = 15;
			__instance.m_fullyUpgradedSpecializedBuildingCount = 15;
			__instance.m_resourceProducingBuildingCount = 15;
			__instance.m_activeResourceProducingBuildingCount = 15;
		}
	}

	[HarmonyPatch(typeof(AreaManager), "IsAreaExpired")]
	public class AreaManager_IsAreaExpired
	{
		private static void Postfix(ref bool __result)
		{
			__result = false;
		}
	}

	[HarmonyPatch(typeof(Building), "ActivateLevelVisuals", new Type[] { })]
	public class Building_ActivateLevelVisuals
	{
		private static void Prefix(Building __instance)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Invalid comparison between Unknown and I4
			if (!instantConstruction.Value)
			{
				return;
			}
			int num = 5;
			while (num >= 0 && (int)__instance.CurrentPhase.ConstructionType == 0)
			{
				if (__instance.m_currentBasicPhaseIndex < 0)
				{
					__instance.m_currentBasicPhaseIndex = 0;
				}
				else
				{
					__instance.m_currentBasicPhaseIndex++;
				}
				num--;
			}
			__instance.m_remainingConstructionTime = 0f;
		}
	}

	[HarmonyPatch(typeof(Building), "StartUpgrade")]
	public class Building_StartUpgrade
	{
		private static void Postfix(Building __instance)
		{
			if (instantConstruction.Value)
			{
				__instance.m_remainingConstructionTime = 0f;
				__instance.m_currentUpgradePhaseIndex = __instance.m_pendingUpgradePhaseIndex;
				__instance.m_pendingUpgradePhaseIndex = -1;
				__instance.UpdateConstruction(0f);
			}
		}
	}

	public const string GUID = "Glowstick.UnlimitedTownBuilding";

	public const string NAME = "UnlimitedTownBuilding";

	public const string VERSION = "1.2.0";

	internal static ManualLogSource Log;

	public static ConfigEntry<bool> ignoreColliders;

	public static ConfigEntry<bool> infiniteResources;

	public static ConfigEntry<KeyCode> destroyKey;

	public static ConfigEntry<bool> bypassDestroyConfirmation;

	public static ConfigEntry<bool> instantConstruction;

	public static Building buildingToDestroy { get; private set; }

	internal void Awake()
	{
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		Log.LogMessage((object)"Hello world from UnlimitedTownBuilding 1.2.0!");
		ignoreColliders = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Ignore Colliders", true, "Ignore colliders when placing buildings, when off it will be hard to place buildings outside new sirocco.");
		infiniteResources = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Infinite Resources", false, "Infinite resources when placing buildings. WARNING: If you turn this off you will have all your resources set to 0.");
		destroyKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "Destroy Key", (KeyCode)127, "Keybind to remove buildings.");
		bypassDestroyConfirmation = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Bypass Destroy Confirmation", false, "Bypass the confirmation dialog when destroying buildings.");
		instantConstruction = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Instant Construction", false, "Buildings construct and upgrade instantly.");
		new Harmony("Glowstick.UnlimitedTownBuilding").PatchAll();
	}

	internal void Update()
	{
		//IL_0006: 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_0030: Unknown result type (might be due to invalid IL or missing references)
		RaycastHit hit = default(RaycastHit);
		if (Input.GetKeyDown(destroyKey.Value) && Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), ref hit))
		{
			DestroyUnityObject(hit);
		}
	}

	public static void DestroyUnityObject(RaycastHit hit)
	{
		//IL_0025: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Expected O, but got Unknown
		Building[] array = Resources.FindObjectsOfTypeAll<Building>();
		Building val = null;
		float num = float.MaxValue;
		Building[] array2 = array;
		foreach (Building val2 in array2)
		{
			float num2 = Vector3.Distance(((Component)val2).transform.position, ((RaycastHit)(ref hit)).point);
			if (num2 < num && num2 < 30f)
			{
				val = val2;
				num = num2;
			}
		}
		if (!((Object)(object)val != (Object)null))
		{
			return;
		}
		buildingToDestroy = val;
		CharacterManager instance = CharacterManager.Instance;
		Character firstLocalCharacter = instance.GetFirstLocalCharacter();
		CharacterUI characterUI = firstLocalCharacter.CharacterUI;
		if ((Object)(object)characterUI != (Object)null)
		{
			if (bypassDestroyConfirmation.Value)
			{
				DestroyBuilding();
			}
			else
			{
				characterUI.MessagePanel.Show("Destroy building " + ((Item)val).DisplayName + "?", "Confirm", new UnityAction(DestroyBuilding), (UnityAction)null, false, -1f, (UnityAction)null);
			}
		}
	}

	private static void DestroyBuilding()
	{
		Log.LogMessage((object)("Destroying building " + ((Object)buildingToDestroy).name));
		BuildingResourcesManager.Instance.UnregisterBuiding(buildingToDestroy);
		ItemManager.Instance.SendDestroyItem(((Item)buildingToDestroy).UID);
		Object.Destroy((Object)(object)((Component)buildingToDestroy).gameObject);
	}
}