Decompiled source of NoBuildRestriction v420.0.2

BuildRestrictionTweaks/BuildRestrictionTweaks.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BuildRestrictionTweaks;

[BepInPlugin("aedenthorn.BuildRestrictionTweaks", "Build Restriction Tweaks", "0.5.0")]
public class BepInExPlugin : BaseUnityPlugin
{
	private enum PlacementStatus
	{
		Valid,
		Invalid,
		BlockedbyPlayer,
		NoBuildZone,
		PrivateZone,
		MoreSpace,
		NoTeleportArea,
		ExtensionMissingStation,
		WrongBiome,
		NeedCultivated,
		NeedDirt,
		NotInDungeon
	}

	[HarmonyPatch(typeof(Location), "IsInsideNoBuildLocation")]
	private static class Location_IsInsideNoBuildLocation_Patch
	{
		private static void Postfix(ref bool __result)
		{
			if (modEnabled.Value && (ignoreBuildZone.Value || alwaysValid.Value))
			{
				__result = false;
			}
		}
	}

	[HarmonyPatch(typeof(CraftingStation), "HaveBuildStationInRange")]
	private static class CraftingStation_HaveBuildStationInRange_Patch
	{
		private static void Postfix(ref CraftingStation __result, string name)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			if (modEnabled.Value && (ignoreMissingStation.Value || alwaysValid.Value) && !((Object)(object)__result != (Object)null))
			{
				if (Object.op_Implicit((Object)(object)craftingStationObject))
				{
					__result = craftingStationObject.GetComponent<CraftingStation>();
					return;
				}
				craftingStationObject = new GameObject();
				Object.DontDestroyOnLoad((Object)(object)craftingStationObject);
				__result = craftingStationObject.AddComponent<CraftingStation>();
			}
		}
	}

	[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
	private static class Player_UpdatePlacementGhost_Patch
	{
		private static void Postfix(Player __instance, GameObject ___m_placementGhost)
		{
			if (modEnabled.Value && !((Object)(object)___m_placementGhost == (Object)null))
			{
				PlacementStatus placementStatus = (PlacementStatus)(int)AccessTools.Field(typeof(Player), "m_placementStatus").GetValue(__instance);
				if ((placementStatus != 0 && placementStatus != PlacementStatus.PrivateZone && alwaysValid.Value) || (placementStatus == PlacementStatus.Invalid && ignoreInvalid.Value) || (placementStatus == PlacementStatus.BlockedbyPlayer && ignoreBlockedbyPlayer.Value) || (placementStatus == PlacementStatus.NoBuildZone && ignoreBuildZone.Value) || (placementStatus == PlacementStatus.MoreSpace && ignoreSpaceRestrictions.Value) || (placementStatus == PlacementStatus.NoTeleportArea && ignoreTeleportAreaRestrictions.Value) || (placementStatus == PlacementStatus.ExtensionMissingStation && ignoreMissingStationExtension.Value) || (placementStatus == PlacementStatus.WrongBiome && ignoreBiomeRestrictions.Value) || (placementStatus == PlacementStatus.NeedCultivated && ignoreCultivationRestrictions.Value) || (placementStatus == PlacementStatus.NeedDirt && ignoreDirtRestrictions.Value) || (placementStatus == PlacementStatus.NotInDungeon && ignoreDungeonRestrictions.Value))
				{
					AccessTools.Field(typeof(Player), "m_placementStatus").SetValue(__instance, 0);
					AccessTools.Method(typeof(Player), "SetPlacementGhostValid", (Type[])null, (Type[])null).Invoke(__instance, new object[1] { true });
				}
			}
		}
	}

	private static readonly bool isDebug = true;

	public static ConfigEntry<string> modKey;

	public static ConfigEntry<bool> modEnabled;

	public static ConfigEntry<int> nexusID;

	public static ConfigEntry<bool> alwaysValid;

	public static ConfigEntry<bool> ignoreInvalid;

	public static ConfigEntry<bool> ignoreBlockedbyPlayer;

	public static ConfigEntry<bool> ignoreBuildZone;

	public static ConfigEntry<bool> ignoreSpaceRestrictions;

	public static ConfigEntry<bool> ignoreTeleportAreaRestrictions;

	public static ConfigEntry<bool> ignoreMissingStation;

	public static ConfigEntry<bool> ignoreMissingStationExtension;

	public static ConfigEntry<bool> ignoreBiomeRestrictions;

	public static ConfigEntry<bool> ignoreCultivationRestrictions;

	public static ConfigEntry<bool> ignoreDirtRestrictions;

	public static ConfigEntry<bool> ignoreDungeonRestrictions;

	private static BepInExPlugin context;

	public static GameObject craftingStationObject;

	public static void Dbgl(string str = "", bool pref = true)
	{
		if (isDebug)
		{
			Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
		}
	}

	private void Awake()
	{
		context = this;
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
		nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 1606, "Nexus mod ID for updates");
		alwaysValid = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "AlwaysValid", false, "Remove all build restrictions.");
		ignoreBlockedbyPlayer = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "ignoreBlockedbyPlayer", false, "Ignore player blocking build.");
		ignoreInvalid = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "IgnoreInvalid", false, "Prevent misc build restrictions.");
		ignoreBuildZone = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "ignoreBuildZone", false, "Ignore zone restrictions.");
		ignoreSpaceRestrictions = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "ignoreSpaceRestrictions", false, "Ignore space restrictions.");
		ignoreTeleportAreaRestrictions = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "ignoreTeleportAreaRestrictions", false, "Ignore teleport area restrictions.");
		ignoreMissingStationExtension = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "ignoreMissingStationExtension", false, "Ignore missing station extension.");
		ignoreMissingStation = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "ignoreMissingStation", false, "Ignore missing station.");
		ignoreBiomeRestrictions = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "ignoreBiomeRestrictions", false, "Ignore biome restrictions.");
		ignoreCultivationRestrictions = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "ignoreCultivationRestrictions", false, "Ignore need for cultivated ground.");
		ignoreDirtRestrictions = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "ignoreDirtRestrictions", false, "Ignore need for dirt.");
		ignoreDungeonRestrictions = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "ignoreDungeonRestrictions", false, "Ignore indoor restrictions.");
		nexusID.Value = 1606;
		if (modEnabled.Value)
		{
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), MetadataHelper.GetMetadata((object)this).GUID);
		}
	}
}