Decompiled source of RemoveLava v1.0.1

RemoveLava.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("RemoveLava")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RemoveLava")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("459621dc-9ca7-4b62-8469-1bb8c0965231")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace RemoveLava;

[BepInPlugin("org.ssmvc.removelava", "RemoveLava", "1.0.1")]
[BepInProcess("valheim.exe")]
public class RemoveLava : BaseUnityPlugin
{
	public const string PluginGUID = "org.ssmvc.removelava";

	public const string PluginName = "RemoveLava";

	public const string PluginVersion = "1.0.1";

	private static ManualLogSource _logger;

	private static Harmony _harmony;

	private void Awake()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Expected O, but got Unknown
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		_logger = ((BaseUnityPlugin)this).Logger;
		_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "org.ssmvc.removelava");
		new ConsoleCommand("removelava", "Remove Lava", new ConsoleEvent(RemoveLavaFunc), false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		new ConsoleCommand("floorislava", "Floor Is Lava", new ConsoleEvent(FloorIsLavaFunc), false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
	}

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

	public static void FloorIsLavaFunc(ConsoleEventArgs args)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		if (args.Length < 2)
		{
			return;
		}
		int num = Convert.ToInt32(args[1]);
		List<Heightmap> list = new List<Heightmap>();
		Heightmap.FindHeightmap(((Component)Player.m_localPlayer).transform.position, (float)num, list);
		foreach (Heightmap item in list)
		{
			TerrainComp andCreateTerrainCompiler = item.GetAndCreateTerrainCompiler();
			int num2 = 65;
			Console.WriteLine($"Adding Lava To Heightmap {((Component)item).transform.position}");
			FieldInfo? field = typeof(TerrainComp).GetField("m_modifiedPaint", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeof(TerrainComp).GetField("m_paintMask", BindingFlags.Instance | BindingFlags.NonPublic);
			bool[] array = (bool[])field?.GetValue(andCreateTerrainCompiler);
			Color[] array2 = (Color[])field2?.GetValue(andCreateTerrainCompiler);
			if (array == null || array2 == null)
			{
				continue;
			}
			for (int i = 0; i < num2; i++)
			{
				for (int j = 0; j < num2; j++)
				{
					Color paintMask = item.GetPaintMask(i, j);
					paintMask.a = 1f;
					int num3 = i * num2 + j;
					array[num3] = true;
					array2[num3] = paintMask;
				}
			}
			typeof(TerrainComp).GetMethod("Save", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(andCreateTerrainCompiler, null);
			item.Poke(false);
		}
	}

	public static void RemoveLavaFunc(ConsoleEventArgs args)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		if (args.Length < 2)
		{
			return;
		}
		int num = Convert.ToInt32(args[1]);
		List<Heightmap> list = new List<Heightmap>();
		Heightmap.FindHeightmap(((Component)Player.m_localPlayer).transform.position, (float)num, list);
		foreach (Heightmap item in list)
		{
			TerrainComp andCreateTerrainCompiler = item.GetAndCreateTerrainCompiler();
			int num2 = 65;
			Console.WriteLine($"Removing Lava From Heightmap {((Component)item).transform.position}");
			FieldInfo? field = typeof(TerrainComp).GetField("m_modifiedPaint", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeof(TerrainComp).GetField("m_paintMask", BindingFlags.Instance | BindingFlags.NonPublic);
			bool[] array = (bool[])field?.GetValue(andCreateTerrainCompiler);
			Color[] array2 = (Color[])field2?.GetValue(andCreateTerrainCompiler);
			if (array == null || array2 == null)
			{
				continue;
			}
			for (int i = 0; i < num2; i++)
			{
				for (int j = 0; j < num2; j++)
				{
					Color paintMask = item.GetPaintMask(i, j);
					paintMask.a = 0f;
					int num3 = i * num2 + j;
					array[num3] = true;
					array2[num3] = paintMask;
				}
			}
			typeof(TerrainComp).GetMethod("Save", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(andCreateTerrainCompiler, null);
			item.Poke(false);
		}
	}
}