Decompiled source of Heightmap Unlimited Remake v1.4.1

plugins/HeightmapUnlimited.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using JetBrains.Annotations;
using Jotunn;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Menthus, Digitalroot")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © Menthus and Digitalroot 2021 - 2023")]
[assembly: AssemblyDescription("Allows players to raise or lower terrain as much as they want! Now comes with config so you can set the limits yourself.")]
[assembly: AssemblyFileVersion("1.4.1.0")]
[assembly: AssemblyInformationalVersion("1.4.1+974e3c137e22257c3db83c67279e6f3dd010d432")]
[assembly: AssemblyProduct("Menthus's Heightmap Unlimited")]
[assembly: AssemblyTitle("HeightmapUnlimited")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/Digitalroot/Menthus123-HeightmapUnlimited")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.4.1.0")]
[module: UnverifiableCode]
namespace HeightmapUnlimited;

[BepInPlugin("Menthus.bepinex.plugins.HeightmapUnlimited", "HeightmapUnlimited", "1.4.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class HeightmapUnlimited : BaseUnityPlugin
{
	public const string Version = "1.4.1";

	public const string Name = "HeightmapUnlimited";

	public const string Guid = "Menthus.bepinex.plugins.HeightmapUnlimited";

	private Harmony _harmony;

	public static ConfigEntry<int> NexusId;

	public static ConfigEntry<float> MaxHeight;

	public static ConfigEntry<float> MinHeight;

	public static float Min()
	{
		return MinHeight.Value;
	}

	public static float MinAbs()
	{
		return Math.Abs(MinHeight.Value);
	}

	public static float Max()
	{
		return MaxHeight.Value;
	}

	[UsedImplicitly]
	public void Awake()
	{
		Logger.LogDebug((object)"[HeightmapUnlimited] Awake()");
		InitializeConfig();
		if (!IsHeadless())
		{
			_harmony = Harmony.CreateAndPatchAll(typeof(HeightmapUnlimited).Assembly, "Menthus.bepinex.plugins.HeightmapUnlimited");
		}
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}

	private void InitializeConfig()
	{
		//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_003b: 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: Expected O, but got Unknown
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Expected O, but got Unknown
		//IL_0094: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Expected O, but got Unknown
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Expected O, but got Unknown
		//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_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Expected O, but got Unknown
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Expected O, but got Unknown
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
		NexusId = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 359, new ConfigDescription("Nexus mod ID for updates", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = false,
			Browsable = false,
			ReadOnly = true
		} }));
		MaxHeight = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Max Height", 200f, new ConfigDescription("How high you can stack up relative to the heightmap's original position.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 200f), new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true,
			Browsable = true
		} }));
		MinHeight = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Min Height", -200f, new ConfigDescription("How far you can dig down relative to the heightmap's original position.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-200f, -1f), new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true,
			Browsable = true
		} }));
	}

	[UsedImplicitly]
	public static bool IsHeadless()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Invalid comparison between Unknown and I4
		return (int)SystemInfo.graphicsDeviceType == 4;
	}
}
[HarmonyPatch(typeof(TerrainComp))]
public class Heightmap_Patches
{
	[HarmonyTranspiler]
	[HarmonyPatch("LevelTerrain")]
	public static IEnumerable<CodeInstruction> TerrainCompLevelTerrainTranspiler(IEnumerable<CodeInstruction> instructions)
	{
		foreach (CodeInstruction instruction in instructions)
		{
			if (CodeInstructionExtensions.Is(instruction, OpCodes.Ldc_R4, (object)(-8f)))
			{
				yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(HeightmapUnlimited), "Min", (Type[])null, (Type[])null));
			}
			else if (CodeInstructionExtensions.Is(instruction, OpCodes.Ldc_R4, (object)8f))
			{
				yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(HeightmapUnlimited), "Max", (Type[])null, (Type[])null));
			}
			else
			{
				yield return instruction;
			}
		}
	}

	[HarmonyTranspiler]
	[HarmonyPatch("RaiseTerrain")]
	public static IEnumerable<CodeInstruction> TerrainCompRaiseTerrainTranspiler(IEnumerable<CodeInstruction> instructions)
	{
		foreach (CodeInstruction instruction in instructions)
		{
			if (CodeInstructionExtensions.Is(instruction, OpCodes.Ldc_R4, (object)(-8f)))
			{
				yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(HeightmapUnlimited), "Min", (Type[])null, (Type[])null));
			}
			else if (CodeInstructionExtensions.Is(instruction, OpCodes.Ldc_R4, (object)8f))
			{
				yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(HeightmapUnlimited), "Max", (Type[])null, (Type[])null));
			}
			else
			{
				yield return instruction;
			}
		}
	}

	[HarmonyTranspiler]
	[HarmonyPatch("ApplyToHeightmap")]
	public static IEnumerable<CodeInstruction> TerrainCompApplyToHeightmapTranspiler(IEnumerable<CodeInstruction> instructions)
	{
		int i = 0;
		foreach (CodeInstruction instruction in instructions)
		{
			if (CodeInstructionExtensions.Is(instruction, OpCodes.Ldc_R4, (object)(-8f)))
			{
				yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(HeightmapUnlimited), "Min", (Type[])null, (Type[])null));
			}
			else if (CodeInstructionExtensions.Is(instruction, OpCodes.Ldc_R4, (object)8f))
			{
				if (i == 0)
				{
					yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(HeightmapUnlimited), "MinAbs", (Type[])null, (Type[])null));
				}
				else
				{
					yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(HeightmapUnlimited), "Max", (Type[])null, (Type[])null));
				}
				i++;
			}
			else
			{
				yield return instruction;
			}
		}
	}
}