Decompiled source of DigDug v1.0.0

DigDug.dll

Decompiled 8 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = "")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace DigDug;

[BepInPlugin("com.antigravity.valheim.digdug", "DigDug", "1.0.0")]
public class DigDugPlugin : BaseUnityPlugin
{
	public const string PluginGUID = "com.antigravity.valheim.digdug";

	public const string PluginName = "DigDug";

	public const string PluginVersion = "1.0.0";

	public static ManualLogSource Log;

	private Harmony harmony;

	private GameObject uiObject;

	private void Awake()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		DigDugConfig.Init(((BaseUnityPlugin)this).Config);
		DigDugReflection.Init();
		harmony = new Harmony("com.antigravity.valheim.digdug");
		harmony.PatchAll();
		uiObject = new GameObject("DigDugUI");
		uiObject.AddComponent<DigDugUI>();
		Object.DontDestroyOnLoad((Object)(object)uiObject);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"DigDug mod initialized successfully!");
	}

	private void OnDestroy()
	{
		if ((Object)(object)uiObject != (Object)null)
		{
			Object.Destroy((Object)(object)uiObject);
		}
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}
}
public static class DigDugConfig
{
	public static ConfigEntry<bool> EnableStaminaDrain;

	public static ConfigEntry<bool> IgnoreDurabilityLoss;

	public static ConfigEntry<bool> IgnoreStoneRequirement;

	public static ConfigEntry<float> StoneCostMultiplier;

	public static void Init(ConfigFile config)
	{
		EnableStaminaDrain = config.Bind<bool>("General", "EnableStaminaDrain", true, "If true, performing a batch dig/build will consume player stamina.");
		IgnoreDurabilityLoss = config.Bind<bool>("General", "IgnoreDurabilityLoss", false, "If true, pickaxes will not lose durability when batch digging.");
		IgnoreStoneRequirement = config.Bind<bool>("General", "IgnoreStoneRequirement", false, "If true, raising terrain will not consume stones from your inventory.");
		StoneCostMultiplier = config.Bind<float>("General", "StoneCostMultiplier", 1f, "Multiplier for the amount of stones required to raise terrain.");
	}
}
public static class DigDugPreview
{
	private static List<GameObject> previewObjs = new List<GameObject>();

	private static Material previewMat;

	private static GameObject GetOrCreatePreviewObject(int index)
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Expected O, but got Unknown
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		while (previewObjs.Count <= index)
		{
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
			BoxCollider component = val.GetComponent<BoxCollider>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			Renderer component2 = val.GetComponent<Renderer>();
			if ((Object)(object)previewMat == (Object)null)
			{
				Shader val2 = Shader.Find("Sprites/Default");
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = Shader.Find("Standard");
				}
				previewMat = new Material(val2);
				previewMat.color = new Color(0f, 0.45f, 1f, 0.35f);
			}
			component2.material = previewMat;
			val.SetActive(false);
			previewObjs.Add(val);
		}
		return previewObjs[index];
	}

	public static void UpdatePreview(Vector3 playerPos, Vector3 forward, Vector3 right, float depth, float length, float width, int mode, int direction)
	{
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0315: Unknown result type (might be due to invalid IL or missing references)
		//IL_0326: Unknown result type (might be due to invalid IL or missing references)
		//IL_033e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0350: Unknown result type (might be due to invalid IL or missing references)
		//IL_0351: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_036b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0370: Unknown result type (might be due to invalid IL or missing references)
		//IL_0389: Unknown result type (might be due to invalid IL or missing references)
		//IL_039a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0407: Unknown result type (might be due to invalid IL or missing references)
		//IL_0418: Unknown result type (might be due to invalid IL or missing references)
		//IL_0439: Unknown result type (might be due to invalid IL or missing references)
		//IL_044b: Unknown result type (might be due to invalid IL or missing references)
		//IL_044c: Unknown result type (might be due to invalid IL or missing references)
		//IL_044f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0454: Unknown result type (might be due to invalid IL or missing references)
		//IL_0459: Unknown result type (might be due to invalid IL or missing references)
		//IL_046b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0470: Unknown result type (might be due to invalid IL or missing references)
		//IL_0475: Unknown result type (might be due to invalid IL or missing references)
		//IL_048e: Unknown result type (might be due to invalid IL or missing references)
		//IL_049f: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
		float num = depth;
		if (mode != 2)
		{
			GameObject orCreatePreviewObject = GetOrCreatePreviewObject(0);
			orCreatePreviewObject.SetActive(true);
			for (int i = 1; i < previewObjs.Count; i++)
			{
				if ((Object)(object)previewObjs[i] != (Object)null)
				{
					previewObjs[i].SetActive(false);
				}
			}
			float num2 = width;
			switch (mode)
			{
			case 0:
				num2 = 1f;
				break;
			case 3:
				if (num > 0f)
				{
					num = 0f - num;
				}
				break;
			}
			float num3 = 0f;
			Vector3 val = playerPos + forward * direction switch
			{
				0 => length / 2f, 
				1 => (0f - length) / 2f, 
				_ => 0f, 
			};
			float num4 = playerPos.y - num / 2f;
			orCreatePreviewObject.transform.position = new Vector3(val.x, num4, val.z);
			orCreatePreviewObject.transform.rotation = Quaternion.LookRotation(forward, Vector3.up);
			orCreatePreviewObject.transform.localScale = new Vector3(num2, Mathf.Abs(num), length);
			return;
		}
		float num5 = 2f;
		if (length <= 2f * num5 || width <= 2f * num5)
		{
			GameObject orCreatePreviewObject2 = GetOrCreatePreviewObject(0);
			orCreatePreviewObject2.SetActive(true);
			for (int j = 1; j < previewObjs.Count; j++)
			{
				if ((Object)(object)previewObjs[j] != (Object)null)
				{
					previewObjs[j].SetActive(false);
				}
			}
			float num6 = 0f;
			Vector3 val2 = playerPos + forward * direction switch
			{
				0 => length / 2f, 
				1 => (0f - length) / 2f, 
				_ => 0f, 
			};
			float num7 = playerPos.y - num / 2f;
			orCreatePreviewObject2.transform.position = new Vector3(val2.x, num7, val2.z);
			orCreatePreviewObject2.transform.rotation = Quaternion.LookRotation(forward, Vector3.up);
			orCreatePreviewObject2.transform.localScale = new Vector3(width, Mathf.Abs(num), length);
			return;
		}
		for (int k = 0; k < 4; k++)
		{
			GetOrCreatePreviewObject(k).SetActive(true);
		}
		for (int l = 4; l < previewObjs.Count; l++)
		{
			if ((Object)(object)previewObjs[l] != (Object)null)
			{
				previewObjs[l].SetActive(false);
			}
		}
		float num8 = 0f;
		num8 = direction switch
		{
			0 => length / 2f, 
			1 => (0f - length) / 2f, 
			_ => 0f, 
		};
		float num9 = playerPos.y - num / 2f;
		Quaternion rotation = Quaternion.LookRotation(forward, Vector3.up);
		GameObject orCreatePreviewObject3 = GetOrCreatePreviewObject(0);
		Vector3 val3 = playerPos + forward * (num8 + length / 2f - num5 / 2f);
		orCreatePreviewObject3.transform.position = new Vector3(val3.x, num9, val3.z);
		orCreatePreviewObject3.transform.rotation = rotation;
		orCreatePreviewObject3.transform.localScale = new Vector3(width, Mathf.Abs(num), num5);
		GameObject orCreatePreviewObject4 = GetOrCreatePreviewObject(1);
		Vector3 val4 = playerPos + forward * (num8 - length / 2f + num5 / 2f);
		orCreatePreviewObject4.transform.position = new Vector3(val4.x, num9, val4.z);
		orCreatePreviewObject4.transform.rotation = rotation;
		orCreatePreviewObject4.transform.localScale = new Vector3(width, Mathf.Abs(num), num5);
		GameObject orCreatePreviewObject5 = GetOrCreatePreviewObject(2);
		Vector3 val5 = playerPos + forward * num8 - right * (width / 2f - num5 / 2f);
		orCreatePreviewObject5.transform.position = new Vector3(val5.x, num9, val5.z);
		orCreatePreviewObject5.transform.rotation = rotation;
		orCreatePreviewObject5.transform.localScale = new Vector3(num5, Mathf.Abs(num), length - 2f * num5);
		GameObject orCreatePreviewObject6 = GetOrCreatePreviewObject(3);
		Vector3 val6 = playerPos + forward * num8 + right * (width / 2f - num5 / 2f);
		orCreatePreviewObject6.transform.position = new Vector3(val6.x, num9, val6.z);
		orCreatePreviewObject6.transform.rotation = rotation;
		orCreatePreviewObject6.transform.localScale = new Vector3(num5, Mathf.Abs(num), length - 2f * num5);
	}

	public static void Hide()
	{
		foreach (GameObject previewObj in previewObjs)
		{
			if ((Object)(object)previewObj != (Object)null)
			{
				previewObj.SetActive(false);
			}
		}
	}

	public static void Destroy()
	{
		foreach (GameObject previewObj in previewObjs)
		{
			if ((Object)(object)previewObj != (Object)null)
			{
				Object.Destroy((Object)(object)previewObj);
			}
		}
		previewObjs.Clear();
		if ((Object)(object)previewMat != (Object)null)
		{
			Object.Destroy((Object)(object)previewMat);
			previewMat = null;
		}
	}
}
public class DigDugUI : MonoBehaviour
{
	private static Rect windowRect = new Rect(100f, 100f, 750f, 680f);

	private static GUIStyle windowStyle;

	private static GUIStyle buttonStyle;

	private static GUIStyle textFieldStyle;

	private static GUIStyle labelStyle;

	private static GUIStyle headerStyle;

	private static GUIStyle costLabelStyle;

	private string depthStr = "4.0";

	private string lengthStr = "4.0";

	private string widthStr = "4.0";

	private int selectedMode = 1;

	private readonly string[] modeLabels = new string[4] { "Line", "Rectangle", "Trench", "Wall" };

	private int selectedDirection;

	private readonly string[] directionLabels = new string[3] { "Forward", "Backward", "Center" };

	private int selectedPaint;

	private readonly string[] paintLabels = new string[4] { "Dirt", "Paved", "Grass", "No Change" };

	private static Font nativeFont;

	private float leftArrowDownTime;

	private float rightArrowDownTime;

	public static DigDugUI Instance { get; private set; }

	public static bool IsVisible { get; private set; }

	private void Awake()
	{
		Instance = this;
		IsVisible = false;
	}

	private void OnDestroy()
	{
		DigDugPreview.Destroy();
	}

	public static void Show()
	{
		if (!((Object)(object)Player.m_localPlayer == (Object)null))
		{
			IsVisible = true;
			ToggleCursor(visible: true);
		}
	}

	public static void Hide()
	{
		IsVisible = false;
		ToggleCursor(visible: false);
		DigDugPreview.Hide();
	}

	private static void ToggleCursor(bool visible)
	{
		if (visible)
		{
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
		}
		else
		{
			Cursor.lockState = (CursorLockMode)1;
			Cursor.visible = false;
		}
	}

	private void HandleArrowKeyRotation(Player player)
	{
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		float num = 0f;
		if (Input.GetKeyDown((KeyCode)276))
		{
			num -= 1f;
			leftArrowDownTime = Time.time;
		}
		else if (Input.GetKey((KeyCode)276) && Time.time - leftArrowDownTime > 0.3f)
		{
			num -= 30f * Time.deltaTime;
		}
		if (Input.GetKeyDown((KeyCode)275))
		{
			num += 1f;
			rightArrowDownTime = Time.time;
		}
		else if (Input.GetKey((KeyCode)275) && Time.time - rightArrowDownTime > 0.3f)
		{
			num += 30f * Time.deltaTime;
		}
		if (Mathf.Abs(num) > 0.0001f)
		{
			Quaternion lookYaw = ((Character)player).GetLookYaw();
			Quaternion val = lookYaw * Quaternion.Euler(0f, num, 0f);
			((Character)player).SetLookDir(val * Vector3.forward, 0f);
			player.FaceLookDirection();
		}
	}

	private void Update()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Invalid comparison between Unknown and I4
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer != (Object)null)
		{
			ItemData currentWeapon = ((Humanoid)localPlayer).GetCurrentWeapon();
			if (currentWeapon != null && (int)currentWeapon.m_shared.m_skillType == 12)
			{
				HandleArrowKeyRotation(localPlayer);
			}
		}
		if (IsVisible)
		{
			if (Input.GetKeyDown((KeyCode)27))
			{
				Hide();
				return;
			}
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			UpdatePreviewObject();
		}
	}

	private void LateUpdate()
	{
		if (IsVisible)
		{
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
		}
	}

	private void UpdatePreviewObject()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: 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_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if (!((Object)(object)localPlayer == (Object)null))
		{
			ParseInputs(out var depth, out var length, out var width);
			Vector3 forward = ((Component)localPlayer).transform.forward;
			forward.y = 0f;
			((Vector3)(ref forward)).Normalize();
			Vector3 right = ((Component)localPlayer).transform.right;
			right.y = 0f;
			((Vector3)(ref right)).Normalize();
			DigDugPreview.UpdatePreview(((Component)localPlayer).transform.position, forward, right, depth, length, width, selectedMode, selectedDirection);
		}
	}

	private void ParseInputs(out float depth, out float length, out float width)
	{
		if (!float.TryParse(depthStr, out depth))
		{
			depth = 4f;
		}
		if (!float.TryParse(lengthStr, out length))
		{
			length = 4f;
		}
		if (!float.TryParse(widthStr, out width))
		{
			width = 4f;
		}
		depth = Mathf.Clamp(depth, -30f, 30f);
		length = Mathf.Clamp(length, 0.1f, 100f);
		width = Mathf.Clamp(width, 0.1f, 100f);
	}

	private void OnGUI()
	{
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Expected O, but got Unknown
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: 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_0020: Invalid comparison between Unknown and I4
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Invalid comparison between Unknown and I4
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Invalid comparison between Unknown and I4
		DrawHUDOverlay();
		if (IsVisible)
		{
			if (Event.current != null && (int)Event.current.type == 4 && ((int)Event.current.keyCode == 276 || (int)Event.current.keyCode == 275))
			{
				GUI.FocusControl((string)null);
			}
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			VerifyStyles();
			((Rect)(ref windowRect)).x = ((float)Screen.width - ((Rect)(ref windowRect)).width) / 2f;
			((Rect)(ref windowRect)).y = ((float)Screen.height - ((Rect)(ref windowRect)).height) / 2f;
			windowRect = GUI.Window(9923, windowRect, new WindowFunction(DrawWindow), "DIGDUG EXCAVATION", windowStyle);
		}
	}

	private void DrawWindow(int windowID)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ea: Expected O, but got Unknown
		//IL_05f1: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(25f);
		GUIStyle val = new GUIStyle(labelStyle);
		val.normal.textColor = new Color(0.92f, 0.73f, 0.16f, 1f);
		val.alignment = (TextAnchor)4;
		val.fontSize = 24;
		GUILayout.Label(GetFacingString(), val, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(35f) });
		GUILayout.Space(5f);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label("Mode:", labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(130f),
			GUILayout.Height(36f)
		});
		int num = selectedMode;
		selectedMode = GUILayout.SelectionGrid(selectedMode, modeLabels, 4, buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) });
		GUILayout.EndHorizontal();
		if (selectedMode != num)
		{
			if (selectedMode == 0)
			{
				depthStr = "2.0";
				lengthStr = "10.0";
				widthStr = "1.0";
			}
			else if (selectedMode == 1)
			{
				depthStr = "4.0";
				lengthStr = "4.0";
				widthStr = "4.0";
			}
			else if (selectedMode == 2)
			{
				depthStr = "4.0";
				lengthStr = "4.0";
				widthStr = "4.0";
			}
			else if (selectedMode == 3)
			{
				depthStr = "2.0";
				lengthStr = "4.0";
				widthStr = "4.0";
			}
		}
		GUILayout.Space(6f);
		ParseInputs(out var depth, out var length, out var width);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		string text = ((selectedMode == 3) ? "Height:" : "Depth:");
		GUILayout.Label(text, labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(130f),
			GUILayout.Height(36f)
		});
		depthStr = GUILayout.TextField(depthStr, textFieldStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) });
		GUILayout.EndHorizontal();
		GUILayout.Space(6f);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label("Length:", labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(130f),
			GUILayout.Height(36f)
		});
		lengthStr = GUILayout.TextField(lengthStr, textFieldStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) });
		GUILayout.EndHorizontal();
		GUILayout.Space(6f);
		if (selectedMode != 0)
		{
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUILayout.Label("Width:", labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(130f),
				GUILayout.Height(36f)
			});
			widthStr = GUILayout.TextField(widthStr, textFieldStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) });
			GUILayout.EndHorizontal();
			GUILayout.Space(6f);
		}
		if (selectedMode != 2)
		{
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUILayout.Label("Direction:", labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(130f),
				GUILayout.Height(36f)
			});
			selectedDirection = GUILayout.SelectionGrid(selectedDirection, directionLabels, 3, buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) });
			GUILayout.EndHorizontal();
			GUILayout.Space(6f);
		}
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label("Paint:", labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(130f),
			GUILayout.Height(36f)
		});
		selectedPaint = GUILayout.SelectionGrid(selectedPaint, paintLabels, 4, buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) });
		GUILayout.EndHorizontal();
		GUILayout.Space(6f);
		GUILayout.Space(10f);
		CalculateCosts(depth, length, width, out var area, out var swingCount, out var staminaCost, out var durabilityCost, out var stoneCost);
		GUILayout.BeginVertical(GUI.skin.box, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label($"Area: {area:F1} m² | Swings: {swingCount}", costLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (selectedMode == 3 || depth < 0f)
		{
			int stoneCount = GetStoneCount();
			bool flag = DigDugConfig.IgnoreStoneRequirement.Value || ((Object)(object)Player.m_localPlayer != (Object)null && Player.m_localPlayer.NoCostCheat());
			string arg = ((stoneCount >= stoneCost || flag) ? "lime" : "red");
			GUILayout.Label($"Stone Cost: <color={arg}>{stoneCost}</color> / {stoneCount} available", costLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		}
		string arg2 = "lime";
		float totalPickaxeDurability = GetTotalPickaxeDurability();
		if (totalPickaxeDurability < durabilityCost && !DigDugConfig.IgnoreDurabilityLoss.Value)
		{
			arg2 = "red";
		}
		GUILayout.Label($"Durability Cost: <color={arg2}>{durabilityCost:F0}</color> / {totalPickaxeDurability:F0} available", costLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label($"Stamina Cost: {staminaCost:F0}", costLabelStyle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.EndVertical();
		GUILayout.Space(10f);
		GUIStyle val2 = new GUIStyle(labelStyle);
		val2.normal.textColor = Color.white;
		val2.alignment = (TextAnchor)4;
		val2.fontSize = 28;
		val2.wordWrap = true;
		GUILayout.Label("Tip: Use Left/Right Arrow keys to rotate 1° (hold to rotate continuously)", val2, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Space(10f);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.FlexibleSpace();
		if (GUILayout.Button("Cancel", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(140f),
			GUILayout.Height(38f)
		}))
		{
			Hide();
		}
		GUILayout.Space(15f);
		string text2 = ((selectedMode == 3 || depth < 0f) ? "Build!" : "Dig!");
		if (GUILayout.Button(text2, buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(140f),
			GUILayout.Height(38f)
		}))
		{
			ExecuteDig(depth, length, width, area, swingCount, staminaCost, durabilityCost, stoneCost);
		}
		GUILayout.EndHorizontal();
		GUILayout.EndVertical();
	}

	private void CalculateCosts(float depth, float length, float width, out float area, out int swingCount, out float staminaCost, out float durabilityCost, out int stoneCost)
	{
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Invalid comparison between Unknown and I4
		float num = width;
		float num2 = Mathf.Abs(depth);
		if (selectedMode == 0)
		{
			num = 1f;
		}
		area = length * num;
		if (selectedMode == 2)
		{
			float num3 = 2f;
			if (length > 2f * num3 && num > 2f * num3)
			{
				float num4 = (length - 2f * num3) * (num - 2f * num3);
				area -= num4;
			}
		}
		swingCount = Mathf.Max(1, Mathf.RoundToInt(area / 12.5f * Mathf.Max(1f, num2)));
		staminaCost = 0f;
		durabilityCost = 0f;
		stoneCost = 0;
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer != (Object)null)
		{
			ItemData currentWeapon = ((Humanoid)localPlayer).GetCurrentWeapon();
			if (currentWeapon != null && (int)currentWeapon.m_shared.m_skillType == 12)
			{
				staminaCost = currentWeapon.m_shared.m_attack.m_attackStamina * (float)swingCount;
				durabilityCost = currentWeapon.m_shared.m_useDurabilityDrain * (float)swingCount;
			}
		}
		if (selectedMode == 3 || depth < 0f)
		{
			stoneCost = Mathf.Max(1, Mathf.RoundToInt(area / 12.5f * Mathf.Max(1f, num2) * 2f * DigDugConfig.StoneCostMultiplier.Value));
		}
	}

	private int GetStoneCount()
	{
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return 0;
		}
		return ((Humanoid)localPlayer).GetInventory().CountItems("$item_stone", -1, false);
	}

	private float GetTotalPickaxeDurability()
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Invalid comparison between Unknown and I4
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return 0f;
		}
		float num = 0f;
		foreach (ItemData allItem in ((Humanoid)localPlayer).GetInventory().GetAllItems())
		{
			if ((int)allItem.m_shared.m_skillType == 12)
			{
				num += allItem.m_durability;
			}
		}
		return num;
	}

	private void ExecuteDig(float depth, float length, float width, float area, int swingCount, float staminaCost, float durabilityCost, int stoneCost)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Invalid comparison between Unknown and I4
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_028d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0292: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Expected O, but got Unknown
		//IL_0364: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_036a: Unknown result type (might be due to invalid IL or missing references)
		//IL_036f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0374: Unknown result type (might be due to invalid IL or missing references)
		//IL_0378: Unknown result type (might be due to invalid IL or missing references)
		//IL_037d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0382: Unknown result type (might be due to invalid IL or missing references)
		//IL_0384: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_041b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0420: Unknown result type (might be due to invalid IL or missing references)
		//IL_049d: Unknown result type (might be due to invalid IL or missing references)
		//IL_049f: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0783: Unknown result type (might be due to invalid IL or missing references)
		//IL_0910: Unknown result type (might be due to invalid IL or missing references)
		//IL_08f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_08f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0924: Unknown result type (might be due to invalid IL or missing references)
		//IL_0943: Unknown result type (might be due to invalid IL or missing references)
		//IL_0948: Unknown result type (might be due to invalid IL or missing references)
		//IL_0954: Unknown result type (might be due to invalid IL or missing references)
		//IL_095c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0668: Unknown result type (might be due to invalid IL or missing references)
		//IL_066d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0684: Unknown result type (might be due to invalid IL or missing references)
		//IL_0686: Unknown result type (might be due to invalid IL or missing references)
		//IL_0866: Unknown result type (might be due to invalid IL or missing references)
		//IL_086d: Invalid comparison between Unknown and I4
		//IL_069c: Unknown result type (might be due to invalid IL or missing references)
		//IL_06a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return;
		}
		ItemData currentWeapon = ((Humanoid)localPlayer).GetCurrentWeapon();
		if (currentWeapon == null || (int)currentWeapon.m_shared.m_skillType != 12)
		{
			((Character)localPlayer).Message((MessageType)1, "You must equip a pickaxe to execute this operation!", 0, (Sprite)null);
			return;
		}
		bool flag = selectedMode == 3 || depth < 0f;
		GameObject val = null;
		Piece val2 = null;
		if (flag)
		{
			val = new GameObject("DigDug_DummyPiece");
			val.SetActive(false);
			val2 = val.AddComponent<Piece>();
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Stone");
			ItemDrop resItem = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null);
			val2.m_resources = (Requirement[])(object)new Requirement[1];
			val2.m_resources[0] = new Requirement();
			val2.m_resources[0].m_resItem = resItem;
			val2.m_resources[0].m_amount = stoneCost;
			val2.m_resources[0].m_amountPerLevel = 0;
			val2.m_resources[0].m_recover = true;
			if (selectedMode == 3)
			{
				GameObject prefab = ZNetScene.instance.GetPrefab("piece_stonecutter");
				val2.m_craftingStation = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<CraftingStation>() : null);
			}
			else
			{
				GameObject prefab2 = ZNetScene.instance.GetPrefab("piece_workbench");
				val2.m_craftingStation = (((Object)(object)prefab2 != (Object)null) ? prefab2.GetComponent<CraftingStation>() : null);
			}
			if (!localPlayer.NoCostCheat() && !DigDugConfig.IgnoreStoneRequirement.Value)
			{
				if ((Object)(object)val2.m_craftingStation != (Object)null)
				{
					string name = val2.m_craftingStation.m_name;
					if (!Object.op_Implicit((Object)(object)CraftingStation.HaveBuildStationInRange(name, ((Component)localPlayer).transform.position)))
					{
						string text = Localization.instance.Localize(name);
						((Character)localPlayer).Message((MessageType)1, "Missing station: " + text + " in range!", 0, (Sprite)null);
						Object.Destroy((Object)(object)val);
						return;
					}
				}
				if (!localPlayer.HaveRequirements(val2, (RequirementMode)0))
				{
					int stoneCount = GetStoneCount();
					((Character)localPlayer).Message((MessageType)1, $"Not enough stone! Required: {stoneCost}, you have: {stoneCount}", 0, (Sprite)null);
					Object.Destroy((Object)(object)val);
					return;
				}
			}
		}
		if (!DigDugConfig.IgnoreDurabilityLoss.Value)
		{
			float totalPickaxeDurability = GetTotalPickaxeDurability();
			if (totalPickaxeDurability < durabilityCost)
			{
				((Character)localPlayer).Message((MessageType)1, $"Your pickaxes are too damaged! Required durability: {durabilityCost:F0}, you have: {totalPickaxeDurability:F0}", 0, (Sprite)null);
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				return;
			}
		}
		Vector3 position = ((Component)localPlayer).transform.position;
		Vector3 forward = ((Component)localPlayer).transform.forward;
		forward.y = 0f;
		((Vector3)(ref forward)).Normalize();
		Vector3 right = ((Component)localPlayer).transform.right;
		right.y = 0f;
		((Vector3)(ref right)).Normalize();
		float num = width;
		float num2 = depth;
		if (selectedMode == 0)
		{
			num = 1f;
		}
		else if (selectedMode == 3)
		{
			num2 = 0f - depth;
		}
		float num3 = 0f;
		float num4 = 0f;
		float num5 = (0f - num) / 2f;
		float num6 = num / 2f;
		if (selectedDirection == 0)
		{
			num3 = 0f;
			num4 = length;
		}
		else if (selectedDirection == 1)
		{
			num3 = 0f - length;
			num4 = 0f;
		}
		else
		{
			num3 = (0f - length) / 2f;
			num4 = length / 2f;
		}
		float num7 = position.y - num2;
		HashSet<TerrainComp> hashSet = new HashSet<TerrainComp>();
		float num8 = 8f;
		for (float num9 = num3 - 4f; num9 <= num4 + 4f; num9 += num8)
		{
			for (float num10 = num5 - 4f; num10 <= num6 + 4f; num10 += num8)
			{
				Vector3 val3 = position + forward * num9 + right * num10;
				TerrainComp val4 = TerrainComp.FindTerrainCompiler(val3);
				if ((Object)(object)val4 != (Object)null)
				{
					hashSet.Add(val4);
				}
			}
		}
		HashSet<string> hashSet2 = new HashSet<string>();
		HashSet<TerrainComp> hashSet3 = new HashSet<TerrainComp>();
		Vector3 val5 = default(Vector3);
		foreach (TerrainComp item2 in hashSet)
		{
			Heightmap hmap = DigDugReflection.GetHmap(item2);
			if ((Object)(object)hmap == (Object)null)
			{
				continue;
			}
			int width2 = hmap.m_width;
			float scale = hmap.m_scale;
			Vector3 position2 = ((Component)hmap).transform.position;
			int num11 = width2 / 2;
			float[] levelDelta = DigDugReflection.GetLevelDelta(item2);
			float[] smoothDelta = DigDugReflection.GetSmoothDelta(item2);
			bool[] modifiedHeight = DigDugReflection.GetModifiedHeight(item2);
			Color[] paintMask = DigDugReflection.GetPaintMask(item2);
			bool[] modifiedPaint = DigDugReflection.GetModifiedPaint(item2);
			for (int i = 0; i <= width2; i++)
			{
				for (int j = 0; j <= width2; j++)
				{
					float num12 = position2.x + (float)(j - num11) * scale;
					float num13 = position2.z + (float)(i - num11) * scale;
					((Vector3)(ref val5))..ctor(num12, position.y, num13);
					Vector3 val6 = val5 - position;
					float num14 = Vector3.Dot(val6, forward);
					float num15 = Vector3.Dot(val6, right);
					float num16 = num3 - scale / 2f;
					float num17 = num4 + scale / 2f;
					float num18 = num5 - scale / 2f;
					float num19 = num6 + scale / 2f;
					if (!(num14 >= num16 - 0.1f) || !(num14 <= num17 + 0.1f) || !(num15 >= num18 - 0.1f) || !(num15 <= num19 + 0.1f))
					{
						continue;
					}
					if (selectedMode == 2)
					{
						float num20 = 2f;
						if (length > 2f * num20 && num > 2f * num20 && num14 >= num16 + num20 - 0.01f && num14 <= num17 - num20 + 0.01f && num15 >= num18 + num20 - 0.01f && num15 <= num19 - num20 + 0.01f)
						{
							continue;
						}
					}
					string item = ((Object)((Component)item2).gameObject).name + "_" + j + "_" + i;
					if (!hashSet2.Contains(item))
					{
						hashSet2.Add(item);
						int num21 = i * (width2 + 1) + j;
						float height = hmap.GetHeight(j, i);
						float num22 = num7 - height;
						num22 += smoothDelta[num21];
						smoothDelta[num21] = 0f;
						levelDelta[num21] += num22;
						levelDelta[num21] = Mathf.Clamp(levelDelta[num21], -30f, 30f);
						modifiedHeight[num21] = true;
						if (selectedPaint == 0)
						{
							Color paintMaskDirt = Heightmap.m_paintMaskDirt;
							paintMaskDirt.a = 0f;
							paintMask[num21] = paintMaskDirt;
							modifiedPaint[num21] = true;
						}
						else if (selectedPaint == 1)
						{
							Color paintMaskPaved = Heightmap.m_paintMaskPaved;
							paintMaskPaved.a = 0f;
							paintMask[num21] = paintMaskPaved;
							modifiedPaint[num21] = true;
						}
						else if (selectedPaint == 2)
						{
							Color paintMaskNothing = Heightmap.m_paintMaskNothing;
							paintMaskNothing.a = 1f;
							paintMask[num21] = paintMaskNothing;
							modifiedPaint[num21] = true;
						}
						hashSet3.Add(item2);
					}
				}
			}
		}
		foreach (TerrainComp item3 in hashSet3)
		{
			DigDugReflection.Save(item3);
			DigDugReflection.GetHmap(item3).Poke(false);
			if ((Object)(object)ClutterSystem.instance != (Object)null)
			{
				ClutterSystem.instance.ResetGrass(((Component)item3).transform.position, DigDugReflection.GetSize(item3));
			}
		}
		if (DigDugConfig.EnableStaminaDrain.Value)
		{
			((Character)localPlayer).UseStamina(staminaCost);
		}
		if (flag)
		{
			if (!localPlayer.NoCostCheat() && !DigDugConfig.IgnoreStoneRequirement.Value && (Object)(object)val2 != (Object)null)
			{
				localPlayer.ConsumeResources(val2.m_resources, 0, 1, 1);
			}
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)val);
			}
		}
		if (!DigDugConfig.IgnoreDurabilityLoss.Value)
		{
			float num23 = durabilityCost;
			float num24 = Mathf.Min(currentWeapon.m_durability, num23);
			currentWeapon.m_durability -= num24;
			num23 -= num24;
			if (num23 > 0f)
			{
				foreach (ItemData allItem in ((Humanoid)localPlayer).GetInventory().GetAllItems())
				{
					if ((int)allItem.m_shared.m_skillType == 12 && allItem != currentWeapon)
					{
						float num25 = Mathf.Min(allItem.m_durability, num23);
						allItem.m_durability -= num25;
						num23 -= num25;
						if (num23 <= 0f)
						{
							break;
						}
					}
				}
			}
		}
		((Character)localPlayer).RaiseSkill((SkillType)12, DigDugReflection.GetRaiseSkillAmount(currentWeapon.m_shared.m_attack) * (float)swingCount);
		if (currentWeapon.m_shared.m_hitTerrainEffect != null)
		{
			currentWeapon.m_shared.m_hitTerrainEffect.Create(position, Quaternion.identity, (Transform)null, 1f, -1);
		}
		float num26 = default(float);
		if (ZoneSystem.instance.GetGroundHeight(((Component)localPlayer).transform.position, ref num26) && Mathf.Abs(((Component)localPlayer).transform.position.y - num26) > 0.05f)
		{
			Vector3 position3 = ((Component)localPlayer).transform.position;
			position3.y = num26;
			((Character)localPlayer).TeleportTo(position3, ((Component)localPlayer).transform.rotation, false);
		}
		Hide();
	}

	private string GetFacingString()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return "Facing: Unknown";
		}
		Vector3 forward = ((Component)localPlayer).transform.forward;
		forward.y = 0f;
		((Vector3)(ref forward)).Normalize();
		float num = Mathf.Atan2(forward.x, forward.z) * 57.29578f;
		if (num < 0f)
		{
			num += 360f;
		}
		string text = "";
		text = ((num >= 337.5f || num < 22.5f) ? "North (N)" : ((num >= 22.5f && num < 67.5f) ? "North-East (NE)" : ((num >= 67.5f && num < 112.5f) ? "East (E)" : ((num >= 112.5f && num < 157.5f) ? "South-East (SE)" : ((num >= 157.5f && num < 202.5f) ? "South (S)" : ((num >= 202.5f && num < 247.5f) ? "South-West (SW)" : ((!(num >= 247.5f) || !(num < 292.5f)) ? "North-West (NW)" : "West (W)")))))));
		return $"Facing: {text} ({num:F0}°)";
	}

	private void DrawHUDOverlay()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Invalid comparison between Unknown and I4
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Expected O, but got Unknown
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: 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)
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return;
		}
		ItemData currentWeapon = ((Humanoid)localPlayer).GetCurrentWeapon();
		if (currentWeapon != null && (int)currentWeapon.m_shared.m_skillType == 12)
		{
			string facingString = GetFacingString();
			GUIStyle val = new GUIStyle();
			val.fontSize = 36;
			val.fontStyle = (FontStyle)1;
			val.normal.textColor = new Color(0.92f, 0.73f, 0.16f, 1f);
			val.alignment = (TextAnchor)4;
			Font val2 = GetNativeFont();
			if ((Object)(object)val2 != (Object)null)
			{
				val.font = val2;
			}
			GUIStyle val3 = new GUIStyle(val);
			val3.normal.textColor = Color.black;
			float num = 800f;
			float num2 = 60f;
			float num3 = ((float)Screen.width - num) / 2f;
			float num4 = 90f;
			GUI.Label(new Rect(num3 + 2f, num4 + 2f, num, num2), facingString, val3);
			GUI.Label(new Rect(num3, num4, num, num2), facingString, val);
		}
	}

	private static Font GetNativeFont()
	{
		if ((Object)(object)nativeFont == (Object)null)
		{
			Font[] array = Resources.FindObjectsOfTypeAll<Font>();
			foreach (Font val in array)
			{
				if (((Object)val).name == "AveriaSansLibre-Bold" || ((Object)val).name == "AveriaSerifLibre-Regular" || ((Object)val).name.Contains("Averia"))
				{
					nativeFont = val;
					break;
				}
			}
		}
		return nativeFont;
	}

	private static void VerifyStyles()
	{
		if (windowStyle == null || !((Object)(object)windowStyle.normal.background != (Object)null))
		{
			InitStyles();
		}
	}

	private static void InitStyles()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Expected O, but got Unknown
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Expected O, but got Unknown
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Expected O, but got Unknown
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Expected O, but got Unknown
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Expected O, but got Unknown
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Expected O, but got Unknown
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Expected O, but got Unknown
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Expected O, but got Unknown
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Expected O, but got Unknown
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_030f: Unknown result type (might be due to invalid IL or missing references)
		//IL_033c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_036e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0373: Unknown result type (might be due to invalid IL or missing references)
		//IL_0388: Unknown result type (might be due to invalid IL or missing references)
		//IL_039c: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ef: Expected O, but got Unknown
		//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0404: Expected O, but got Unknown
		//IL_040d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0417: Expected O, but got Unknown
		//IL_042b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0435: Expected O, but got Unknown
		//IL_0457: Unknown result type (might be due to invalid IL or missing references)
		//IL_0470: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ee: Expected O, but got Unknown
		//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0501: Expected O, but got Unknown
		//IL_0516: Unknown result type (might be due to invalid IL or missing references)
		//IL_0520: Expected O, but got Unknown
		Color textColor = default(Color);
		((Color)(ref textColor))..ctor(0.92f, 0.73f, 0.16f, 1f);
		new Color(0.85f, 0.7f, 0.2f, 1f);
		Color val = default(Color);
		((Color)(ref val))..ctor(0.88f, 0.63f, 0.28f, 1f);
		Font val2 = GetNativeFont();
		windowStyle = new GUIStyle();
		windowStyle.normal.background = CreateWoodPanelTexture(128, 128);
		windowStyle.normal.textColor = textColor;
		windowStyle.padding = new RectOffset(20, 20, 60, 20);
		windowStyle.alignment = (TextAnchor)1;
		windowStyle.fontSize = 26;
		windowStyle.fontStyle = (FontStyle)1;
		windowStyle.border = new RectOffset(6, 6, 6, 6);
		if ((Object)(object)val2 != (Object)null)
		{
			windowStyle.font = val2;
		}
		labelStyle = new GUIStyle();
		labelStyle.normal.textColor = val;
		labelStyle.fontSize = 18;
		labelStyle.fontStyle = (FontStyle)1;
		labelStyle.alignment = (TextAnchor)3;
		labelStyle.margin = new RectOffset(0, 5, 5, 5);
		if ((Object)(object)val2 != (Object)null)
		{
			labelStyle.font = val2;
		}
		headerStyle = new GUIStyle(labelStyle);
		headerStyle.fontSize = 24;
		headerStyle.alignment = (TextAnchor)4;
		headerStyle.normal.textColor = textColor;
		costLabelStyle = new GUIStyle(labelStyle);
		costLabelStyle.fontSize = 16;
		costLabelStyle.normal.textColor = new Color(0.7f, 0.7f, 0.7f, 1f);
		costLabelStyle.richText = true;
		costLabelStyle.margin = new RectOffset(5, 5, 2, 2);
		if ((Object)(object)val2 != (Object)null)
		{
			costLabelStyle.font = val2;
		}
		buttonStyle = new GUIStyle();
		buttonStyle.normal.background = CreateButtonTexture(64, 24, new Color(0.08f, 0.08f, 0.08f, 0.9f), new Color(0.27f, 0.23f, 0.2f, 1f));
		buttonStyle.hover.background = CreateButtonTexture(64, 24, new Color(0.12f, 0.12f, 0.12f, 0.9f), val);
		buttonStyle.active.background = CreateButtonTexture(64, 24, new Color(0.05f, 0.05f, 0.05f, 0.9f), val);
		buttonStyle.normal.textColor = val;
		buttonStyle.hover.textColor = Color.white;
		buttonStyle.active.textColor = val;
		buttonStyle.onNormal.background = CreateButtonTexture(64, 24, new Color(0.22f, 0.18f, 0.15f, 0.95f), val);
		buttonStyle.onHover.background = CreateButtonTexture(64, 24, new Color(0.26f, 0.22f, 0.19f, 0.95f), val);
		buttonStyle.onActive.background = CreateButtonTexture(64, 24, new Color(0.18f, 0.15f, 0.12f, 0.95f), val);
		buttonStyle.onNormal.textColor = Color.white;
		buttonStyle.onHover.textColor = Color.white;
		buttonStyle.onActive.textColor = Color.white;
		buttonStyle.alignment = (TextAnchor)4;
		buttonStyle.fontSize = 18;
		buttonStyle.fontStyle = (FontStyle)1;
		buttonStyle.margin = new RectOffset(4, 4, 4, 4);
		buttonStyle.padding = new RectOffset(12, 12, 8, 8);
		buttonStyle.border = new RectOffset(2, 2, 2, 2);
		if ((Object)(object)val2 != (Object)null)
		{
			buttonStyle.font = val2;
		}
		textFieldStyle = new GUIStyle();
		textFieldStyle.normal.background = CreateButtonTexture(64, 24, new Color(0.05f, 0.05f, 0.05f, 0.95f), new Color(0.2f, 0.18f, 0.15f, 1f));
		textFieldStyle.focused.background = CreateButtonTexture(64, 24, new Color(0.05f, 0.05f, 0.05f, 0.95f), val);
		textFieldStyle.normal.textColor = Color.white;
		textFieldStyle.focused.textColor = Color.white;
		textFieldStyle.padding = new RectOffset(12, 12, 8, 8);
		textFieldStyle.margin = new RectOffset(0, 0, 4, 4);
		textFieldStyle.fontSize = 18;
		textFieldStyle.border = new RectOffset(2, 2, 2, 2);
		if ((Object)(object)val2 != (Object)null)
		{
			textFieldStyle.font = val2;
		}
	}

	private static Texture2D CreateWoodPanelTexture(int width, int height)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(width, height);
		Color val2 = default(Color);
		((Color)(ref val2))..ctor(0.12f, 0.08f, 0.06f, 1f);
		Color val3 = default(Color);
		((Color)(ref val3))..ctor(0.38f, 0.25f, 0.18f, 0.98f);
		Color val4 = default(Color);
		((Color)(ref val4))..ctor(0.22f, 0.15f, 0.11f, 1f);
		Color[] array = (Color[])(object)new Color[width * height];
		for (int i = 0; i < height; i++)
		{
			for (int j = 0; j < width; j++)
			{
				bool flag = j == 0 || j == width - 1 || i == 0 || i == height - 1;
				bool flag2 = (j > 0 && j < 4) || (j >= width - 4 && j < width - 1) || (i > 0 && i < 4) || (i >= height - 4 && i < height - 1);
				if (flag)
				{
					array[i * width + j] = val2;
					continue;
				}
				if (flag2)
				{
					array[i * width + j] = val4;
					continue;
				}
				float num = Mathf.PerlinNoise((float)j * 0.15f, (float)i * 0.03f) * 0.06f - 0.03f;
				float num2 = Mathf.Sin((float)i * 1.5f + Mathf.PerlinNoise((float)j * 0.05f, (float)i * 0.05f) * 6f) * 0.02f;
				float num3 = Mathf.Clamp01(val3.r + num + num2);
				float num4 = Mathf.Clamp01(val3.g + num + num2);
				float num5 = Mathf.Clamp01(val3.b + num + num2);
				ref Color reference = ref array[i * width + j];
				reference = new Color(num3, num4, num5, val3.a);
			}
		}
		val.SetPixels(array);
		val.Apply();
		return val;
	}

	private static Texture2D CreateButtonTexture(int width, int height, Color bgColor, Color borderColor)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(width, height);
		Color[] array = (Color[])(object)new Color[width * height];
		for (int i = 0; i < height; i++)
		{
			for (int j = 0; j < width; j++)
			{
				bool flag = j == 0 || j == width - 1 || i == 0 || i == height - 1;
				array[i * width + j] = (flag ? borderColor : bgColor);
			}
		}
		val.SetPixels(array);
		val.Apply();
		return val;
	}
}
[HarmonyPatch]
public static class DigDugPatches
{
	private static float lastLogTime;

	[HarmonyPrefix]
	[HarmonyPatch(typeof(Player), "SetControls")]
	public static void Player_SetControls_Prefix(Player __instance, ref bool block, ref bool blockHold)
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Invalid comparison between Unknown and I4
		if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || InventoryGui.IsVisible() || Minimap.IsOpen() || Menu.IsVisible() || Console.IsVisible() || StoreGui.IsVisible() || TextInput.IsVisible() || Hud.InRadial() || Hud.IsPieceSelectionVisible())
		{
			return;
		}
		ItemData currentWeapon = ((Humanoid)__instance).GetCurrentWeapon();
		if (currentWeapon != null && (int)currentWeapon.m_shared.m_skillType == 12 && block)
		{
			block = false;
			blockHold = false;
			if (!DigDugUI.IsVisible)
			{
				DigDugPlugin.Log.LogInfo((object)"DigDug: Pickaxe block (Right-click) detected! Triggering UI.");
				DigDugUI.Show();
			}
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(Player), "TakeInput")]
	public static bool Player_TakeInput_Prefix(ref bool __result)
	{
		if (DigDugUI.IsVisible)
		{
			__result = false;
			return false;
		}
		return true;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PlayerController), "TakeInput")]
	public static bool PlayerController_TakeInput_Prefix(ref bool __result, bool look)
	{
		if (DigDugUI.IsVisible)
		{
			__result = false;
			return false;
		}
		return true;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
	public static bool GameCamera_UpdateMouseCapture_Prefix()
	{
		if (DigDugUI.IsVisible)
		{
			if (Time.time - lastLogTime > 2f)
			{
				DigDugPlugin.Log.LogInfo((object)"DigDug: Bypassing UpdateMouseCapture and forcing cursor unlock.");
				lastLogTime = Time.time;
			}
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			return false;
		}
		return true;
	}
}
public static class DigDugReflection
{
	public delegate void LevelTerrainDelegate(TerrainComp instance, Vector3 worldPos, float radius, bool square);

	public delegate void SaveDelegate(TerrainComp instance);

	public static LevelTerrainDelegate LevelTerrain;

	public static SaveDelegate Save;

	private static FieldInfo f_hmap;

	private static FieldInfo f_size;

	private static FieldInfo f_levelDelta;

	private static FieldInfo f_smoothDelta;

	private static FieldInfo f_modifiedHeight;

	private static FieldInfo f_paintMask;

	private static FieldInfo f_modifiedPaint;

	private static FieldInfo f_raiseSkillAmount;

	public static void Init()
	{
		MethodInfo method = AccessTools.Method(typeof(TerrainComp), "LevelTerrain", new Type[3]
		{
			typeof(Vector3),
			typeof(float),
			typeof(bool)
		}, (Type[])null);
		LevelTerrain = (LevelTerrainDelegate)Delegate.CreateDelegate(typeof(LevelTerrainDelegate), method);
		MethodInfo method2 = AccessTools.Method(typeof(TerrainComp), "Save", (Type[])null, (Type[])null);
		Save = (SaveDelegate)Delegate.CreateDelegate(typeof(SaveDelegate), method2);
		f_hmap = AccessTools.Field(typeof(TerrainComp), "m_hmap");
		f_size = AccessTools.Field(typeof(TerrainComp), "m_size");
		f_levelDelta = AccessTools.Field(typeof(TerrainComp), "m_levelDelta");
		f_smoothDelta = AccessTools.Field(typeof(TerrainComp), "m_smoothDelta");
		f_modifiedHeight = AccessTools.Field(typeof(TerrainComp), "m_modifiedHeight");
		f_paintMask = AccessTools.Field(typeof(TerrainComp), "m_paintMask");
		f_modifiedPaint = AccessTools.Field(typeof(TerrainComp), "m_modifiedPaint");
		f_raiseSkillAmount = AccessTools.Field(typeof(Attack), "m_raiseSkillAmount");
	}

	public static Heightmap GetHmap(TerrainComp instance)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		return (Heightmap)f_hmap.GetValue(instance);
	}

	public static float GetSize(TerrainComp instance)
	{
		return (float)f_size.GetValue(instance);
	}

	public static float[] GetLevelDelta(TerrainComp instance)
	{
		return (float[])f_levelDelta.GetValue(instance);
	}

	public static float[] GetSmoothDelta(TerrainComp instance)
	{
		return (float[])f_smoothDelta.GetValue(instance);
	}

	public static bool[] GetModifiedHeight(TerrainComp instance)
	{
		return (bool[])f_modifiedHeight.GetValue(instance);
	}

	public static Color[] GetPaintMask(TerrainComp instance)
	{
		return (Color[])f_paintMask.GetValue(instance);
	}

	public static bool[] GetModifiedPaint(TerrainComp instance)
	{
		return (bool[])f_modifiedPaint.GetValue(instance);
	}

	public static float GetRaiseSkillAmount(Attack attack)
	{
		return (float)f_raiseSkillAmount.GetValue(attack);
	}
}