Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Veymoris Midgard Hoe v1.3.3
plugins/VeymorisMidgardHoe.dll
Decompiled a day ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_utils")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("VeymorisMidgardHoe")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.3.3.0")] [assembly: AssemblyInformationalVersion("1.3.3")] [assembly: AssemblyProduct("VeymorisMidgardHoe")] [assembly: AssemblyTitle("VeymorisMidgardHoe")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.3.3.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace VeymorisUltimateHoe { internal static class AreaClearer { private static readonly Collider[] Hits = (Collider[])(object)new Collider[2048]; public static string Clear(Vector3 center, float radius) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) HashSet<ZNetView> hashSet = new HashSet<ZNetView>(); int num = Physics.OverlapSphereNonAlloc(center, radius, Hits, -1, (QueryTriggerInteraction)2); for (int i = 0; i < num; i++) { Collider val = Hits[i]; if (Object.op_Implicit((Object)(object)val)) { ZNetView componentInParent = ((Component)val).GetComponentInParent<ZNetView>(); if (Object.op_Implicit((Object)(object)componentInParent) && componentInParent.IsValid() && IsClearable(((Component)componentInParent).gameObject)) { hashSet.Add(componentInParent); } } } int num2 = 0; int num3 = 0; foreach (ZNetView item in hashSet) { if (!Object.op_Implicit((Object)(object)item) || !item.IsValid()) { continue; } if (!PrivateArea.CheckAccess(((Component)item).transform.position, 0f, num3 == 0, false)) { num3++; continue; } if (!item.IsOwner()) { item.ClaimOwnership(); } ZNetScene.instance.Destroy(((Component)item).gameObject); num2++; } string text = ((num2 == 0) ? "Nothing to clear here" : string.Format("Cleared {0} object{1}", num2, (num2 == 1) ? "" : "s")); if (num3 > 0) { text += $"; {num3} protected by a ward"; } return text; } private static bool IsClearable(GameObject go) { if (Object.op_Implicit((Object)(object)go.GetComponent<Piece>()) || Object.op_Implicit((Object)(object)go.GetComponent<Plant>()) || Object.op_Implicit((Object)(object)go.GetComponent<Character>()) || Object.op_Implicit((Object)(object)go.GetComponent<Container>()) || Object.op_Implicit((Object)(object)go.GetComponent<ItemDrop>()) || Object.op_Implicit((Object)(object)go.GetComponent<Ship>()) || Object.op_Implicit((Object)(object)go.GetComponent<RuneStone>()) || Object.op_Implicit((Object)(object)go.GetComponent<Vegvisir>()) || Object.op_Implicit((Object)(object)go.GetComponent<Teleport>()) || Object.op_Implicit((Object)(object)go.GetComponent<LocationProxy>()) || Object.op_Implicit((Object)(object)go.GetComponentInParent<Location>()) || Object.op_Implicit((Object)(object)go.GetComponent<WearNTear>()) || Object.op_Implicit((Object)(object)go.GetComponent<SpawnArea>()) || Object.op_Implicit((Object)(object)go.GetComponent<CreatureSpawner>()) || Object.op_Implicit((Object)(object)go.GetComponent<OfferingBowl>())) { return false; } float radius; if (Object.op_Implicit((Object)(object)go.GetComponent<Pickable>())) { return !Planting.TryGetGrowRadius(Utils.GetPrefabName(go), out radius); } if (!Object.op_Implicit((Object)(object)go.GetComponent<TreeBase>()) && !Object.op_Implicit((Object)(object)go.GetComponent<TreeLog>()) && !Object.op_Implicit((Object)(object)go.GetComponent<MineRock>()) && !Object.op_Implicit((Object)(object)go.GetComponent<MineRock5>())) { return Object.op_Implicit((Object)(object)go.GetComponent<Destructible>()); } return true; } } internal sealed class ResetTerrainCommand : ConsoleCommand { public override string Name => "vuh_resetterrain"; public override string Help => "[radius] Reset the ground around you to how the world made it (default: brush radius). Can be undone."; public override void Run(string[] args) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer)) { Console.instance.Print("Join a world first."); return; } float result = HoeConfig.BrushRadius.Value; if (args.Length != 0 && !float.TryParse(args[0], NumberStyles.Float, CultureInfo.InvariantCulture, out result)) { Console.instance.Print("Usage: vuh_resetterrain [radius]"); return; } result = Mathf.Clamp(result, 0.5f, 100f); Vector3 position = ((Component)localPlayer).transform.position; UndoHistory.Push(TerrainEditor.Capture(position, result)); int num = TerrainEditor.Reset(position, result); Console.instance.Print((num > 0) ? $"Reset {result:0.#} m around you; {num} area(s) could not be reached." : $"Reset {result:0.#} m around you."); } } internal sealed class UndoTerrainCommand : ConsoleCommand { public override string Name => "vuh_undo"; public override string Help => "Undo your last terrain change made with the Veymoris Midgard Hoe or vuh_resetterrain."; public override void Run(string[] args) { Console.instance.Print(UndoHistory.Undo()); } } internal static class FarmGrid { private struct Crop { public Vector3 Pos; public float Radius; public float Extent; } private const float DefaultExtent = 0.25f; private static readonly Dictionary<string, float> ExtentByName = new Dictionary<string, float>(); private static readonly Collider[] Hits = (Collider[])(object)new Collider[256]; private static readonly List<Crop> Crops = new List<Crop>(); private static readonly HashSet<GameObject> Seen = new HashSet<GameObject>(); private static float Gap(float rA, float extA, float rB, float extB) { return Mathf.Max(rA + extB, rB + extA); } public static void UpdateGhost(Player player, GameObject ghost) { //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) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Invalid comparison between Unknown and I4 //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Invalid comparison between Unknown and I4 //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: 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_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012e: 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_0138: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Invalid comparison between Unknown and I4 //IL_0248: Unknown result type (might be due to invalid IL or missing references) //IL_0223: 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_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) if (!HoeConfig.EnableFarmGrid.Value || !Planting.IsPlantPiece(ghost)) { GridLines.Hide(); return; } PlacementStatus placementStatus = player.m_placementStatus; if ((int)placementStatus != 0 && (int)placementStatus != 9 && (int)placementStatus != 5) { GridLines.Hide(); return; } string prefabName = Utils.GetPrefabName(ghost); float radius; float num = (Planting.TryGetGrowRadius(prefabName, out radius) ? radius : 0.5f); float value; float num2 = (ExtentByName.TryGetValue(prefabName, out value) ? value : 0.25f); float value2 = HoeConfig.ExtraSpacing.Value; Vector3 val = ghost.transform.position; FindCrops(val, HoeConfig.GridSearchRadius.Value + num + 2f, ghost); int num3 = Nearest(val, -1, HoeConfig.GridSearchRadius.Value); Vector3 val2 = Vector3.right; float num4 = num + num2 + value2; if (num3 >= 0) { Crop crop = Crops[num3]; num4 = Gap(num, num2, crop.Radius, Mathf.Max(crop.Extent, 0.25f)) + value2; int num5 = Nearest(crop.Pos, num3, num4 * 2.5f); if (num5 >= 0) { Vector3 val3 = Crops[num5].Pos - crop.Pos; val3.y = 0f; if (((Vector3)(ref val3)).sqrMagnitude > 0.0001f) { val2 = ((Vector3)(ref val3)).normalized; } } Vector3 val4 = default(Vector3); ((Vector3)(ref val4))..ctor(0f - val2.z, 0f, val2.x); Vector3 val5 = val - crop.Pos; float num6 = Mathf.Round(Vector3.Dot(val5, val2) / num4) * num4; float num7 = Mathf.Round(Vector3.Dot(val5, val4) / num4) * num4; val = crop.Pos + val2 * num6 + val4 * num7; float y = default(float); if (Object.op_Implicit((Object)(object)ZoneSystem.instance) && ZoneSystem.instance.GetGroundHeight(val, ref y)) { val.y = y; } ghost.transform.position = val; } Piece component = ghost.GetComponent<Piece>(); PlacementStatus val6 = (PlacementStatus)0; if (Object.op_Implicit((Object)(object)component) && component.m_cultivatedGroundOnly) { Heightmap val7 = Heightmap.FindHeightmap(val); if (!Object.op_Implicit((Object)(object)val7) || !val7.IsCultivated(val)) { val6 = (PlacementStatus)9; } } if ((int)val6 == 0 && Crowded(val, num, num2)) { val6 = (PlacementStatus)5; } player.m_placementStatus = val6; player.SetPlacementGhostValid((int)val6 == 0); if (HoeConfig.ShowGridLines.Value && num3 >= 0) { GridLines.Show(val, val2, num4, HoeConfig.GridLineCells.Value); } else { GridLines.Hide(); } } private static void FindCrops(Vector3 center, float radius, GameObject ghost) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) Crops.Clear(); Seen.Clear(); int num = Physics.OverlapSphereNonAlloc(center, radius, Hits, -1, (QueryTriggerInteraction)2); for (int i = 0; i < num; i++) { Collider val = Hits[i]; if (!Object.op_Implicit((Object)(object)val) || (Object)(object)((Component)((Component)val).transform.root).gameObject == (Object)(object)ghost) { continue; } ZNetView componentInParent = ((Component)val).GetComponentInParent<ZNetView>(); if (!Object.op_Implicit((Object)(object)componentInParent) || !Seen.Add(((Component)componentInParent).gameObject)) { continue; } string prefabName = Utils.GetPrefabName(((Component)componentInParent).gameObject); if (!Planting.TryGetGrowRadius(prefabName, out var radius2)) { continue; } float num2 = 0f; if (Object.op_Implicit((Object)(object)((Component)componentInParent).GetComponent<Plant>())) { num2 = ColliderReach(((Component)componentInParent).gameObject); if (num2 > 0f) { ExtentByName[prefabName] = num2; } } Crops.Add(new Crop { Pos = ((Component)componentInParent).transform.position, Radius = radius2, Extent = num2 }); } } private static float ColliderReach(GameObject go) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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_0095: Unknown result type (might be due to invalid IL or missing references) float num = 0f; Vector3 position = go.transform.position; Collider[] componentsInChildren = go.GetComponentsInChildren<Collider>(); foreach (Collider val in componentsInChildren) { if (val.enabled) { Bounds bounds = val.bounds; float num2 = Mathf.Max(Mathf.Abs(((Bounds)(ref bounds)).min.x - position.x), Mathf.Abs(((Bounds)(ref bounds)).max.x - position.x)); float num3 = Mathf.Max(Mathf.Abs(((Bounds)(ref bounds)).min.z - position.z), Mathf.Abs(((Bounds)(ref bounds)).max.z - position.z)); num = Mathf.Max(num, Mathf.Sqrt(num2 * num2 + num3 * num3)); } } return Mathf.Min(num, 2f); } private static int Nearest(Vector3 from, int exclude, float maxDistance) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: 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_0024: Unknown result type (might be due to invalid IL or missing references) int result = -1; float num = maxDistance * maxDistance; for (int i = 0; i < Crops.Count; i++) { if (i != exclude) { Vector3 val = Crops[i].Pos - from; val.y = 0f; float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude; if (sqrMagnitude <= num) { num = sqrMagnitude; result = i; } } } return result; } private static bool Crowded(Vector3 pos, float myRadius, float myExtent) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) foreach (Crop crop in Crops) { Vector3 val = crop.Pos - pos; val.y = 0f; float num = ((crop.Extent > 0f) ? Gap(myRadius, myExtent, crop.Radius, crop.Extent) : Mathf.Max(myRadius, crop.Radius)); if (((Vector3)(ref val)).sqrMagnitude < num * num - 0.0004f) { return true; } } return false; } } internal sealed class LineSet { private static Material _material; private static Material _onTopMaterial; private static bool _noMaterial; private readonly string _name; private readonly float _width; private readonly bool _onTop; private GameObject _root; private readonly List<LineRenderer> _lines = new List<LineRenderer>(); public LineSet(string name, float width, bool onTop = false) { _name = name; _width = width; _onTop = onTop; } public void Hide() { if (Object.op_Implicit((Object)(object)_root) && _root.activeSelf) { _root.SetActive(false); } } public void Show(IList<List<Vector3>> polylines, Color color, bool followGround) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: 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_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) if (!EnsureMaterial()) { return; } if (!Object.op_Implicit((Object)(object)_root)) { _root = new GameObject(_name); Object.DontDestroyOnLoad((Object)(object)_root); } _root.SetActive(true); while (_lines.Count < polylines.Count) { _lines.Add(NewLine()); } float y = default(float); for (int i = 0; i < _lines.Count; i++) { LineRenderer val = _lines[i]; if (i >= polylines.Count || polylines[i].Count < 2) { ((Renderer)val).enabled = false; continue; } ((Renderer)val).enabled = true; Color startColor = (val.endColor = color); val.startColor = startColor; List<Vector3> list = polylines[i]; val.positionCount = list.Count; for (int j = 0; j < list.Count; j++) { Vector3 val3 = list[j]; if (followGround && Object.op_Implicit((Object)(object)ZoneSystem.instance) && ZoneSystem.instance.GetGroundHeight(val3, ref y)) { val3.y = y; } val3.y += 0.08f; val.SetPosition(j, val3); } } } public static List<Vector3> Segment(Vector3 a, Vector3 b, float spacing = 0.5f) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: 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) int num = Mathf.Max(2, Mathf.CeilToInt(Vector3.Distance(a, b) / spacing) + 1); List<Vector3> list = new List<Vector3>(num); for (int i = 0; i < num; i++) { list.Add(Vector3.Lerp(a, b, (float)i / (float)(num - 1))); } return list; } private LineRenderer NewLine() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("line"); val.transform.SetParent(_root.transform, false); LineRenderer obj = val.AddComponent<LineRenderer>(); obj.useWorldSpace = true; ((Renderer)obj).sharedMaterial = (_onTop ? OnTopMaterial() : _material); float startWidth = (obj.endWidth = _width); obj.startWidth = startWidth; ((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)obj).receiveShadows = false; return obj; } private static Material OnTopMaterial() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_0052: Expected O, but got Unknown if (Object.op_Implicit((Object)(object)_onTopMaterial)) { return _onTopMaterial; } Shader val = Shader.Find("Hidden/Internal-Colored"); if (!Object.op_Implicit((Object)(object)val)) { return _onTopMaterial = _material; } _onTopMaterial = new Material(val) { name = "VUH_LineOnTop", renderQueue = 4000 }; _onTopMaterial.SetInt("_SrcBlend", 5); _onTopMaterial.SetInt("_DstBlend", 10); _onTopMaterial.SetInt("_Cull", 0); _onTopMaterial.SetInt("_ZWrite", 0); _onTopMaterial.SetInt("_ZTest", 8); return _onTopMaterial; } private static bool EnsureMaterial() { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown if (Object.op_Implicit((Object)(object)_material)) { return true; } if (_noMaterial) { return false; } string[] array = new string[4] { "Sprites/Default", "Legacy Shaders/Particles/Alpha Blended", "Particles/Standard Unlit", "Hidden/Internal-Colored" }; for (int i = 0; i < array.Length; i++) { Shader val = Shader.Find(array[i]); if (Object.op_Implicit((Object)(object)val)) { _material = new Material(val) { name = "VUH_Line" }; return true; } } _noMaterial = true; Logger.LogWarning((object)"No shader found for drawing lines; grids and road previews won't be drawn (the tools still work)."); return false; } } internal static class BrushOutline { private static readonly LineSet Outer = new LineSet("VUH_BrushOuter", 0.05f, onTop: true); private static readonly LineSet Inner = new LineSet("VUH_BrushInner", 0.07f, onTop: true); private static readonly Color OuterColor = new Color(1f, 0.85f, 0.45f, 0.55f); private static readonly Color InnerColor = new Color(1f, 0.95f, 0.75f, 0.9f); private static Vector3 _center; private static float _inner; private static float _outer; private static float _drawnAt; private static bool _visible; public static void Hide() { if (_visible) { Outer.Hide(); Inner.Hide(); _visible = false; } } public static void Show(Vector3 cursor, float inner, float outer) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_008a: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: 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_00f7: Unknown result type (might be due to invalid IL or missing references) Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(Mathf.Floor(cursor.x + 0.5f), cursor.y, Mathf.Floor(cursor.z + 0.5f)); if (!_visible || val.x != _center.x || val.z != _center.z || !Mathf.Approximately(inner, _inner) || !Mathf.Approximately(outer, _outer) || !(Time.time - _drawnAt < 0.25f)) { _center = val; _inner = inner; _outer = outer; _drawnAt = Time.time; _visible = true; Outer.Show(new List<List<Vector3>> { Circle(val, outer) }, OuterColor, followGround: true); if (inner > 0.05f && inner < outer - 0.05f) { Inner.Show(new List<List<Vector3>> { Circle(val, inner) }, InnerColor, followGround: true); } else { Inner.Hide(); } } } private static List<Vector3> Circle(Vector3 center, float radius) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.Clamp(Mathf.CeilToInt(radius * 2f * MathF.PI / 0.4f), 24, 160); List<Vector3> list = new List<Vector3>(num + 1); for (int i = 0; i <= num; i++) { float num2 = (float)i * 2f * MathF.PI / (float)num; list.Add(center + new Vector3(Mathf.Cos(num2) * radius, 0f, Mathf.Sin(num2) * radius)); } return list; } } internal static class GridLines { private static readonly LineSet Set = new LineSet("VUH_FarmGridLines", 0.035f); private static readonly Color GridColor = new Color(0.75f, 1f, 0.55f, 0.55f); private static Vector3 _lastCenter; private static Vector3 _lastAxis; private static float _lastStep; private static int _lastCells = -1; private static bool _visible; public static void Hide() { if (_visible) { Set.Hide(); _visible = false; _lastCells = -1; } } public static void Show(Vector3 center, Vector3 axis, float step, int cells) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: 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_00a2: 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_00a6: Unknown result type (might be due to invalid IL or missing references) //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_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: 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) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: 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_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) if (!_visible || !(center == _lastCenter) || !(axis == _lastAxis) || !Mathf.Approximately(step, _lastStep) || cells != _lastCells) { _lastCenter = center; _lastAxis = axis; _lastStep = step; _lastCells = cells; _visible = true; Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(0f - axis.z, 0f, axis.x); float num = (float)cells * step; List<List<Vector3>> list = new List<List<Vector3>>(); for (int i = -cells; i <= cells; i++) { Vector3 val2 = center + val * ((float)i * step) - axis * num; list.Add(LineSet.Segment(val2, val2 + axis * num * 2f)); Vector3 val3 = center + axis * ((float)i * step) - val * num; list.Add(LineSet.Segment(val3, val3 + val * num * 2f)); } Set.Show(list, GridColor, followGround: true); } } } internal static class HoeConfig { public static ConfigEntry<float> BrushRadius; public static ConfigEntry<float> MinRadius; public static ConfigEntry<float> MaxRadius; public static ConfigEntry<float> RadiusStep; public static ConfigEntry<KeyboardShortcut> RadiusScrollModifier; public static ConfigEntry<KeyboardShortcut> RadiusUpKey; public static ConfigEntry<KeyboardShortcut> RadiusDownKey; public static ConfigEntry<float> RaiseAmount; public static ConfigEntry<int> RaiseStoneCost; public static ConfigEntry<bool> RaiseCostByArea; public const float RaiseCostReferenceRadius = 3f; public static ConfigEntry<KeyboardShortcut> UndoKey; public static ConfigEntry<int> UndoSteps; public static ConfigEntry<bool> EnablePlanting; public static ConfigEntry<bool> EnableFarmGrid; public static ConfigEntry<float> ExtraSpacing; public static ConfigEntry<float> GridSearchRadius; public static ConfigEntry<bool> ShowGridLines; public static ConfigEntry<int> GridLineCells; public static ConfigEntry<float> RoadShoulder; public static ConfigEntry<float> RoadMaxSlope; public static ConfigEntry<float> RoadMaxLength; public static ConfigEntry<bool> EnableClearArea; public static ConfigEntry<bool> EnableRocks; public static ConfigEntry<string> RockPrefabs; public static ConfigEntry<bool> RocksCostStone; public static ConfigEntry<float> RockStonePerMetre; public static ConfigEntry<string> Recipe; public static ConfigEntry<bool> UseStamina; public static ConfigEntry<bool> UseDurability; public static void Bind(ConfigFile cfg) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Expected O, but got Unknown //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Expected O, but got Unknown //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Expected O, but got Unknown //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Expected O, but got Unknown //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Expected O, but got Unknown //IL_02cf: Unknown result type (might be due to invalid IL or missing references) //IL_02d9: Expected O, but got Unknown //IL_0316: Unknown result type (might be due to invalid IL or missing references) //IL_0320: Expected O, but got Unknown //IL_034e: Unknown result type (might be due to invalid IL or missing references) //IL_0358: Expected O, but got Unknown //IL_0386: Unknown result type (might be due to invalid IL or missing references) //IL_0390: Expected O, but got Unknown //IL_03be: Unknown result type (might be due to invalid IL or missing references) //IL_03c8: Expected O, but got Unknown //IL_0466: Unknown result type (might be due to invalid IL or missing references) //IL_0470: Expected O, but got Unknown BrushRadius = cfg.Bind<float>("1 - Brush", "Brush Radius", 3f, new ConfigDescription("Radius in metres of every terrain tool. Also changed in game with the radius keys.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 30f), Array.Empty<object>())); MinRadius = cfg.Bind<float>("1 - Brush", "Min Radius", 1f, new ConfigDescription("Smallest radius the keys can set.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 30f), Array.Empty<object>())); MaxRadius = cfg.Bind<float>("1 - Brush", "Max Radius", 15f, new ConfigDescription("Largest radius the keys can set.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 30f), Array.Empty<object>())); RadiusStep = cfg.Bind<float>("1 - Brush", "Radius Step", 0.5f, new ConfigDescription("How much one scroll notch or key press changes the radius.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 5f), Array.Empty<object>())); RadiusScrollModifier = cfg.Bind<KeyboardShortcut>("1 - Brush", "Radius Scroll Modifier", new KeyboardShortcut((KeyCode)308, Array.Empty<KeyCode>()), "Hold this and scroll the mouse wheel to change the radius while holding the hoe."); RadiusUpKey = cfg.Bind<KeyboardShortcut>("1 - Brush", "Radius Up Key", new KeyboardShortcut((KeyCode)270, Array.Empty<KeyCode>()), "Press to grow the radius."); RadiusDownKey = cfg.Bind<KeyboardShortcut>("1 - Brush", "Radius Down Key", new KeyboardShortcut((KeyCode)269, Array.Empty<KeyCode>()), "Press to shrink the radius."); RaiseAmount = cfg.Bind<float>("2 - Shaping", "Raise/Lower Amount", 0.5f, new ConfigDescription("Metres the Raise and Lower tools move the ground per click, at the centre of the brush.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 4f), Array.Empty<object>())); RaiseStoneCost = cfg.Bind<int>("2 - Shaping", "Raise Stone Cost", 2, new ConfigDescription("Stone that Raise Ground costs per use with a 3 m brush (with area pricing off, at any size).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 50), Array.Empty<object>())); RaiseCostByArea = cfg.Bind<bool>("2 - Shaping", "Raise Cost Scales With Area", true, "Raise Ground's Stone cost grows with the area of the brush: twice the radius costs four times as much (at least 1). Off: a flat Raise Stone Cost at any size."); UndoKey = cfg.Bind<KeyboardShortcut>("3 - Undo", "Undo Key", new KeyboardShortcut((KeyCode)122, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "While holding the hoe, undo your last terrain change. Set to None to turn undo off. (Left Ctrl is crouch, so it makes a poor modifier.)"); UndoSteps = cfg.Bind<int>("3 - Undo", "Undo Steps", 10, new ConfigDescription("How many of your terrain changes are remembered.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 50), Array.Empty<object>())); EnablePlanting = cfg.Bind<bool>("5 - Planting", "Enable Planting", true, "Let the hoe plant the cultivator's seeds and saplings (including ones other mods add). Takes effect next time you equip the hoe."); EnableFarmGrid = cfg.Bind<bool>("5 - Planting", "Enable Farm Grid", true, "When planting with the hoe near other crops, snap to an evenly spaced grid so every plant has room to grow."); ExtraSpacing = cfg.Bind<float>("5 - Planting", "Extra Spacing", 0.05f, new ConfigDescription("Extra metres between grid points, on top of the room the game needs for each plant to grow (its grow radius plus its neighbour's size).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>())); GridSearchRadius = cfg.Bind<float>("5 - Planting", "Grid Search Radius", 4f, new ConfigDescription("How far from the cursor to look for crops to line the grid up with.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 15f), Array.Empty<object>())); ShowGridLines = cfg.Bind<bool>("5 - Planting", "Show Grid Lines", true, "Draw the grid on the ground while planting."); GridLineCells = cfg.Bind<int>("5 - Planting", "Grid Line Cells", 3, new ConfigDescription("How many grid cells to draw out from the cursor in each direction.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 8), Array.Empty<object>())); RoadShoulder = cfg.Bind<float>("6 - Roads", "Shoulder Width", 2f, new ConfigDescription("Metres on each side of a road over which it blends back into the ground.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>())); RoadMaxSlope = cfg.Bind<float>("6 - Roads", "Max Slope", 35f, new ConfigDescription("Steepest a road or ramp may climb, in degrees. Steeper stretches show red and won't build.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 60f), Array.Empty<object>())); RoadMaxLength = cfg.Bind<float>("6 - Roads", "Max Length", 150f, new ConfigDescription("Longest road you can build in one go, in metres. The whole road must be loaded, so keep it near you.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 400f), Array.Empty<object>())); EnableClearArea = cfg.Bind<bool>("7 - Clearing and Rocks (restart required)", "Enable Clear Area Tool", false, "Add the Clear Area tool, which removes trees, stumps, logs, bushes, rocks and wild pickables inside the brush. It can't be undone, so it's off by default."); EnableRocks = cfg.Bind<bool>("7 - Clearing and Rocks (restart required)", "Enable Rocks", true, "Add the game's own rocks to the hoe's Landscaping category, to place and remove."); RockPrefabs = cfg.Bind<string>("7 - Clearing and Rocks (restart required)", "Rock Prefabs", "rock4_forest,rock4_heath,rock4_coast,rock2_heath,rock1_mountain,rock2_mountain,rock3_mountain,highstone,widestone,rock_mistlands1,rock_mistlands2,Ashlands_rock2,HeathRockPillar,StoneblockSmall,Stoneblock,MemorialStone_Small,MemorialStone_Medium", "Game prefabs offered as placeable rocks, separated by commas. Names that don't exist are skipped (see the log)."); RocksCostStone = cfg.Bind<bool>("7 - Clearing and Rocks (restart required)", "Rocks Cost Stone", true, "Placing a rock costs Stone, given back when you remove it with the hoe."); RockStonePerMetre = cfg.Bind<float>("7 - Clearing and Rocks (restart required)", "Stone Per Metre", 2f, new ConfigDescription("Stone cost per metre of a rock's widest side (at least 1, at most 50).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 20f), Array.Empty<object>())); Recipe = cfg.Bind<string>("4 - Tool (restart required)", "Recipe", "Wood:5,Stone:2", "Crafting cost at the workbench, as Item:Amount pairs separated by commas (prefab names, e.g. Wood, Stone, Flint)."); UseStamina = cfg.Bind<bool>("4 - Tool (restart required)", "Use Stamina", true, "Whether using the hoe costs stamina."); UseDurability = cfg.Bind<bool>("4 - Tool (restart required)", "Use Durability", true, "Whether the hoe wears out with use."); } public static int RaiseCost(float radius) { int value = RaiseStoneCost.Value; if (!RaiseCostByArea.Value) { return value; } float num = radius / 3f; return Mathf.Max(1, Mathf.CeilToInt((float)value * num * num - 0.0001f)); } public static void SetRadius(float value) { float num = Mathf.Min(MinRadius.Value, MaxRadius.Value); float num2 = Mathf.Max(MinRadius.Value, MaxRadius.Value); BrushRadius.Value = Mathf.Round(Mathf.Clamp(value, num, num2) * 100f) / 100f; } } internal static class HoeContent { internal enum Shape { None, Raise, Lower } internal enum Kind { Brush, Reset, Clear, Road } internal sealed class ToolInfo { public Kind Kind; public Shape Shape; public float GhostRadius; public float Reach = 1f; public float Core = 1f; public PaintType? RoadPaint; } public const string Prefix = "VUH_"; public const string HoeName = "VUH_Hoe"; public const string TableName = "_VUH_HoePieceTable"; public const string ResetPieceName = "VUH_ResetTerrain"; public const string ClearPieceName = "VUH_ClearArea"; private const string CatShape = "Shape"; private const string CatPaint = "Paint"; private const string CatRoads = "Roads"; private static readonly Dictionary<string, ToolInfo> Tools = new Dictionary<string, ToolInfo>(); private static Piece _raisePiece; public static bool TryGetTool(GameObject go, out ToolInfo info) { info = null; if (!Object.op_Implicit((Object)(object)go)) { return false; } string prefabName = Utils.GetPrefabName(go); if (prefabName.StartsWith("VUH_", StringComparison.Ordinal)) { return Tools.TryGetValue(prefabName, out info); } return false; } public static bool TryGetTool(Piece piece, out ToolInfo info) { info = null; if (Object.op_Implicit((Object)(object)piece)) { return TryGetTool(((Component)piece).gameObject, out info); } return false; } public static bool IsHoldingHoe(Player player) { ItemData val = (Object.op_Implicit((Object)(object)player) ? ((Humanoid)player).GetRightItem() : null); if (Object.op_Implicit((Object)(object)val?.m_dropPrefab)) { return ((Object)val.m_dropPrefab).name == "VUH_Hoe"; } return false; } public static void Create() { try { CreatePieceTable(); CreateTools(); Rocks.Create("_VUH_HoePieceTable"); CreateHoe(); } catch (Exception arg) { Logger.LogError((object)string.Format("Could not create the {0}: {1}", "Veymoris Midgard Hoe", arg)); } finally { PrefabManager.OnVanillaPrefabsAvailable -= Create; } } private static void CreatePieceTable() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown CustomPieceTable val = new CustomPieceTable("_VUH_HoePieceTable", new PieceTableConfig { CanRemovePieces = true }); PieceManager.Instance.AddPieceTable(val); } private static void CreateHoe() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown ItemConfig val = new ItemConfig { Name = "Veymoris Midgard Hoe", Description = "Shape the land: raise, lower, flatten and smooth the ground, paint paths and fields, and undo your mistakes.", CraftingStation = "piece_workbench", PieceTable = "_VUH_HoePieceTable" }; foreach (RequirementConfig item in ParseRecipe(HoeConfig.Recipe.Value)) { val.AddRequirement(item); } CustomItem val2 = new CustomItem("VUH_Hoe", "Hoe", val); SharedData shared = val2.ItemDrop.m_itemData.m_shared; shared.m_maxQuality = 4; shared.m_durabilityPerLevel = 50f; if (!HoeConfig.UseStamina.Value) { shared.m_attack.m_attackStamina = 0f; } if (!HoeConfig.UseDurability.Value) { shared.m_useDurability = false; } ItemManager.Instance.AddItem(val2); } private static IEnumerable<RequirementConfig> ParseRecipe(string recipe) { string[] array = (recipe ?? "").Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text in array) { string[] array2 = text.Split(':'); if (array2.Length != 2 || !int.TryParse(array2[1].Trim(), out var result) || result <= 0) { Logger.LogWarning((object)("Ignoring recipe entry '" + text + "'; expected Item:Amount.")); } else { yield return new RequirementConfig(array2[0].Trim(), result, result, true); } } } private static void CreateTools() { AddTool("Raise", "Raise Ground", "Raise the ground inside the brush.", "Shape", new string[1] { "raise_v2" }, Shape.Raise, delegate(Settings s) { s.m_raise = true; s.m_raiseRadius = 1f; s.m_raisePower = 3f; s.m_smooth = true; s.m_smoothRadius = 1.3f; s.m_smoothPower = 3f; }); AddTool("Lower", "Lower Ground", "Dig the ground inside the brush down.", "Shape", new string[1] { "raise_v2" }, Shape.Lower, delegate(Settings s) { s.m_raise = true; s.m_raiseRadius = 1f; s.m_raisePower = 3f; s.m_smooth = true; s.m_smoothRadius = 1.3f; s.m_smoothPower = 3f; }); AddTool("Flatten", "Flatten", "Level the ground to the height you aim at.", "Shape", new string[1] { "mud_road_v2" }, Shape.None, delegate(Settings s) { s.m_level = true; s.m_levelRadius = 1f; }); AddTool("Smooth", "Smooth", "Soften bumps and edges inside the brush.", "Shape", new string[1] { "mud_road_v2" }, Shape.None, delegate(Settings s) { s.m_smooth = true; s.m_smoothRadius = 1f; s.m_smoothPower = 3f; }); AddTool("FlattenPaved", "Paved Floor (flat)", "Level the ground and pave it.", "Shape", new string[2] { "paved_road_v2", "mud_road_v2" }, Shape.None, delegate(Settings s) { s.m_level = true; s.m_levelRadius = 1f; Paint(s, (PaintType)2); }); AddTool("SmoothPaved", "Paved Path (smooth)", "Smooth the ground and pave it.", "Shape", new string[2] { "paved_road_v2", "mud_road_v2" }, Shape.None, delegate(Settings s) { s.m_smooth = true; s.m_smoothRadius = 1f; s.m_smoothPower = 3f; Paint(s, (PaintType)2); }); AddTool("FlattenField", "Field (flat)", "Level the ground and cultivate it for planting.", "Shape", new string[2] { "cultivate_v2", "mud_road_v2" }, Shape.None, delegate(Settings s) { s.m_level = true; s.m_levelRadius = 1f; Paint(s, (PaintType)1); }); AddTool("SmoothField", "Field (smooth)", "Smooth the ground and cultivate it for planting.", "Shape", new string[2] { "cultivate_v2", "mud_road_v2" }, Shape.None, delegate(Settings s) { s.m_smooth = true; s.m_smoothRadius = 1f; s.m_smoothPower = 3f; Paint(s, (PaintType)1); }); AddTool("DirtPath", "Dirt Path (flat)", "Level the ground and turn it to dirt.", "Shape", new string[2] { "path_v2", "mud_road_v2" }, Shape.None, delegate(Settings s) { s.m_level = true; s.m_levelRadius = 1f; Paint(s, (PaintType)0); }); AddTool("VUH_ResetTerrain".Substring("VUH_".Length), "Reset Terrain", "Put the ground inside the brush back the way the world made it: height and paint. Can be undone.", "Shape", new string[2] { "replant_v2", "mud_road_v2" }, Shape.None, delegate { }, Kind.Reset); if (HoeConfig.EnableClearArea.Value) { AddTool("VUH_ClearArea".Substring("VUH_".Length), "Clear Area", "Remove trees, stumps, logs, bushes, rocks and wild pickables inside the brush. Nothing drops, wards are respected, and it can't be undone.", "Shape", new string[2] { "replant_v2", "mud_road_v2" }, Shape.None, delegate { }, Kind.Clear); } AddRoad("Road", "Road", "Click points along the way, then click the last point again to build a road through them. Two points make a straight ramp.", null); AddRoad("RoadDirt", "Road (dirt)", "A road through the points you click, turned to dirt.", (PaintType)0); AddRoad("RoadPaved", "Road (paved)", "A road through the points you click, paved.", (PaintType)2); AddTool("PaintDirt", "Paint Dirt", "Paint the ground as dirt without changing its height.", "Paint", new string[2] { "path_v2", "mud_road_v2" }, Shape.None, delegate(Settings s) { Paint(s, (PaintType)0); }); AddTool("PaintPaved", "Paint Paving", "Pave the ground without changing its height.", "Paint", new string[2] { "paved_road_v2", "mud_road_v2" }, Shape.None, delegate(Settings s) { Paint(s, (PaintType)2); }); AddTool("PaintField", "Paint Cultivated", "Cultivate the ground without changing its height.", "Paint", new string[2] { "cultivate_v2", "mud_road_v2" }, Shape.None, delegate(Settings s) { Paint(s, (PaintType)1); }); AddTool("PaintGrass", "Paint Grass", "Return painted ground to grass without changing its height.", "Paint", new string[2] { "replant_v2", "mud_road_v2" }, Shape.None, delegate(Settings s) { Paint(s, (PaintType)3); }); AddTool("ClearGrass", "Clear Grass", "Stop grass and small plants growing inside the brush, without changing the ground.", "Paint", new string[2] { "path_v2", "mud_road_v2" }, Shape.None, delegate(Settings s) { Paint(s, (PaintType)4); }); } private static void AddRoad(string id, string name, string description, PaintType? paint) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Invalid comparison between Unknown and I4 //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) string text = (((int)paint.GetValueOrDefault() == 2) ? "paved_road_v2" : ((paint == (PaintType?)0) ? "path_v2" : "mud_road_v2")); AddTool(id, name, description, "Roads", new string[2] { text, "mud_road_v2" }, Shape.None, delegate { }, Kind.Road); if (Tools.TryGetValue("VUH_" + id, out var value)) { value.RoadPaint = paint; } } private static void Paint(Settings s, PaintType type) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) s.m_paintCleared = true; s.m_paintType = type; s.m_paintRadius = 1f; s.m_paintHeightCheck = false; if (s.m_paintStrength <= 0f) { s.m_paintStrength = 1f; } } private static void AddTool(string id, string name, string description, string category, string[] templates, Shape shape, Action<Settings> configure, Kind kind = Kind.Brush) { //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Expected O, but got Unknown //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Expected O, but got Unknown //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Expected O, but got Unknown string text = "VUH_" + id; GameObject val = FindTemplate(templates); if (!Object.op_Implicit((Object)(object)val)) { Logger.LogWarning((object)("No game terrain piece to build '" + name + "' from; skipping it.")); return; } GameObject val2 = PrefabManager.Instance.CreateClonedPrefab(text, val); TerrainOp component = val2.GetComponent<TerrainOp>(); float ghostRadius = Mathf.Max(0.5f, component.m_settings.GetRadius()); Settings settings = component.m_settings; settings.m_level = (settings.m_raise = (settings.m_smooth = (settings.m_paintCleared = (settings.m_square = false)))); settings.m_levelRadius = (settings.m_raiseRadius = (settings.m_smoothRadius = (settings.m_paintRadius = 0f))); settings.m_levelOffset = 0f; settings.m_raiseDelta = 0f; configure(settings); component.m_spawnOnPlaced = null; Piece component2 = val2.GetComponent<Piece>(); Sprite val3 = (Object.op_Implicit((Object)(object)component2) ? component2.m_icon : null); if (Object.op_Implicit((Object)(object)component2)) { component2.m_craftingStation = null; component2.m_resources = Array.Empty<Requirement>(); } PieceConfig val4 = new PieceConfig { Name = name, Description = description, PieceTable = "_VUH_HoePieceTable", Category = category, Icon = ((shape == Shape.Lower) ? (IconArt.MakeLowerIcon(val3) ?? LoadLowerIcon()) : val3) }; if (shape == Shape.Raise) { val4.AddRequirement(new RequirementConfig("Stone", HoeConfig.RaiseCost(HoeConfig.BrushRadius.Value), 0, false)); _raisePiece = component2; } PieceManager.Instance.AddPiece(new CustomPiece(val2, false, val4)); float radius = settings.GetRadius(); Tools[text] = new ToolInfo { Kind = kind, Shape = shape, GhostRadius = ghostRadius, Reach = ((radius > 0f) ? radius : 1f), Core = (settings.m_raise ? settings.m_raiseRadius : (settings.m_level ? settings.m_levelRadius : ((radius > 0f) ? radius : 1f))) }; } public static void UpdateRaiseCost() { if (!Object.op_Implicit((Object)(object)_raisePiece) || _raisePiece.m_resources == null) { return; } int amount = HoeConfig.RaiseCost(HoeConfig.BrushRadius.Value); Requirement[] resources = _raisePiece.m_resources; foreach (Requirement val in resources) { if (val != null && Object.op_Implicit((Object)(object)val.m_resItem) && !(((Object)val.m_resItem).name != "Stone")) { val.m_amount = amount; break; } } } public static bool IsRaise(Piece piece) { if (Object.op_Implicit((Object)(object)piece) && Object.op_Implicit((Object)(object)_raisePiece)) { return Utils.GetPrefabName(((Component)piece).gameObject) == ((Object)_raisePiece).name; } return false; } private static Sprite LoadLowerIcon() { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) using Stream stream = typeof(HoeContent).Assembly.GetManifestResourceStream("Veymoris.LowerGround.png"); using BinaryReader binaryReader = new BinaryReader(stream); Texture2D val = new Texture2D(2, 2); ImageConversion.LoadImage(val, binaryReader.ReadBytes((int)stream.Length)); Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); ((Object)obj).name = "VUH_LowerGround"; return obj; } private static GameObject FindTemplate(IEnumerable<string> names) { foreach (string name in names) { GameObject prefab = PrefabManager.Instance.GetPrefab(name); if (Object.op_Implicit((Object)(object)prefab) && Object.op_Implicit((Object)(object)prefab.GetComponent<TerrainOp>())) { return prefab; } } string[] array = new string[2] { "Hoe", "Cultivator" }; foreach (string text in array) { GameObject prefab2 = PrefabManager.Instance.GetPrefab(text); GameObject val = ((IEnumerable<GameObject>)((!Object.op_Implicit((Object)(object)prefab2)) ? null : prefab2.GetComponent<ItemDrop>()?.m_itemData.m_shared.m_buildPieces)?.m_pieces).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => Object.op_Implicit((Object)(object)p) && Object.op_Implicit((Object)(object)p.GetComponent<TerrainOp>()))); if (Object.op_Implicit((Object)(object)val)) { return val; } } return null; } } internal static class HoeInput { private static bool _readingWheel; private static float _wheel; private const string RadiusPrefix = "Brush radius: "; public static bool WheelSizesBrush { get; private set; } internal static bool ReadingWheel => _readingWheel; public static void Update() { //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) WheelSizesBrush = false; Player localPlayer = Player.m_localPlayer; int num; if (Object.op_Implicit((Object)(object)localPlayer)) { num = (HoeContent.IsHoldingHoe(localPlayer) ? 1 : 0); if (num != 0 && ((Character)localPlayer).InPlaceMode()) { goto IL_0037; } } else { num = 0; } GridLines.Hide(); BrushOutline.Hide(); RoadBuilder.Cancel(); goto IL_0037; IL_0037: if (num == 0) { return; } Planting.Sync(localPlayer); Rocks.EnsureIcons(); HoeContent.UpdateRaiseCost(); if (IsTyping()) { return; } bool flag = ((Character)localPlayer).InPlaceMode() && Object.op_Implicit((Object)(object)localPlayer.m_buildPieces) && Planting.IsPlantPiece(localPlayer.m_buildPieces.GetSelectedPiece()); if (((Character)localPlayer).InPlaceMode() && !flag) { float value = HoeConfig.RadiusStep.Value; float num2 = 0f; if (Held(HoeConfig.RadiusScrollModifier.Value)) { WheelSizesBrush = true; float num3 = ((localPlayer.m_scrollAmountThreshold > 0f) ? localPlayer.m_scrollAmountThreshold : 0.1f); _wheel += ReadWheel(); if (_wheel > num3) { num2 += value; _wheel = 0f; } else if (_wheel < 0f - num3) { num2 -= value; _wheel = 0f; } } else { _wheel = 0f; } if (Down(HoeConfig.RadiusUpKey.Value)) { num2 += value; } if (Down(HoeConfig.RadiusDownKey.Value)) { num2 -= value; } if (num2 != 0f) { HoeConfig.SetRadius(HoeConfig.BrushRadius.Value + num2); HoeContent.UpdateRaiseCost(); float value2 = HoeConfig.BrushRadius.Value; Piece piece = (Object.op_Implicit((Object)(object)localPlayer.m_buildPieces) ? localPlayer.m_buildPieces.GetSelectedPiece() : null); string text = string.Format("{0}{1:0.0} m", "Brush radius: ", value2); if (HoeContent.TryGetTool(piece, out var info) && info.Kind == HoeContent.Kind.Brush && info.Reach > info.Core + 0.01f) { text += $" (smoothed edge to {value2 * info.Reach:0.0} m)"; } if (HoeContent.IsRaise(piece)) { int num4 = HoeConfig.RaiseCost(value2); text += $", {num4} Stone"; } RadiusMessage(text); } } if (Down(HoeConfig.UndoKey.Value) && !RoadBuilder.StepBack()) { Message(flag ? PlantUndo.Undo() : UndoHistory.Undo()); } } private static bool Held(KeyboardShortcut s) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_001c: 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) if ((int)((KeyboardShortcut)(ref s)).MainKey == 0) { return false; } if (ZInput.instance == null) { return ((KeyboardShortcut)(ref s)).IsPressed(); } if (!ZInput.GetKey(((KeyboardShortcut)(ref s)).MainKey, false)) { return false; } foreach (KeyCode modifier in ((KeyboardShortcut)(ref s)).Modifiers) { if (!ZInput.GetKey(modifier, false)) { return false; } } return true; } private static bool Down(KeyboardShortcut s) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_001c: 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) if ((int)((KeyboardShortcut)(ref s)).MainKey == 0) { return false; } if (ZInput.instance == null) { return ((KeyboardShortcut)(ref s)).IsDown(); } if (!ZInput.GetKeyDown(((KeyboardShortcut)(ref s)).MainKey, false)) { return false; } foreach (KeyCode modifier in ((KeyboardShortcut)(ref s)).Modifiers) { if (!ZInput.GetKey(modifier, false)) { return false; } } return true; } private static float ReadWheel() { _readingWheel = true; try { return ZInput.GetMouseScrollWheel(); } finally { _readingWheel = false; } } public static void Message(string text) { Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)1, text, 0, (Sprite)null, false); } } private static void RadiusMessage(string text) { MessageHud instance = MessageHud.instance; if ((Object)(object)instance == (Object)null || instance.m_msgQeue == null) { Message(text); return; } MsgData[] array = instance.m_msgQeue.ToArray(); instance.m_msgQeue.Clear(); MsgData[] array2 = array; foreach (MsgData val in array2) { if (val == null || val.m_text == null || !val.m_text.StartsWith("Brush radius: ")) { instance.m_msgQeue.Enqueue(val); } } MsgData currentMsg = instance.currentMsg; if (instance.m_msgQeue.Count == 0 && currentMsg != null && currentMsg.m_text != null && currentMsg.m_text.StartsWith("Brush radius: ") && instance.m_msgQueueTimer < 3f && Object.op_Implicit((Object)(object)instance.m_messageText)) { currentMsg.m_text = text; instance.m_messageText.text = text; } else { Message(text); } } private static bool IsTyping() { if ((!Object.op_Implicit((Object)(object)Chat.instance) || !Chat.instance.HasFocus()) && !Console.IsVisible() && !TextInput.IsVisible() && !Menu.IsVisible() && !InventoryGui.IsVisible()) { return Minimap.IsOpen(); } return true; } } [HarmonyPatch(typeof(CharacterDrop), "Start")] internal static class BruteHoeDrop { private static void Postfix(CharacterDrop __instance) { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Expected O, but got Unknown if (!(Utils.GetPrefabName(((Component)__instance).gameObject) != "Greydwarf_Elite")) { ObjectDB instance = ObjectDB.instance; GameObject hoe = ((instance != null) ? instance.GetItemPrefab("VUH_Hoe") : null); if (Object.op_Implicit((Object)(object)hoe) && !__instance.m_drops.Any((Drop drop) => (Object)(object)drop.m_prefab == (Object)(object)hoe)) { __instance.m_drops = new List<Drop>(__instance.m_drops) { new Drop { m_prefab = hoe, m_chance = 0.05f, m_amountMin = 1, m_amountMax = 1, m_onePerPlayer = false, m_levelMultiplier = false, m_dontScale = true } }; } } } } [HarmonyPatch(typeof(Container), "AddDefaultItems")] internal static class BurialChamberHoeLoot { private static void Postfix(Container __instance) { if (!(Utils.GetPrefabName(((Component)__instance).gameObject) != "TreasureChest_forestcrypt") && !(Random.value >= 0.1f)) { ObjectDB instance = ObjectDB.instance; GameObject val = ((instance != null) ? instance.GetItemPrefab("VUH_Hoe") : null); if (Object.op_Implicit((Object)(object)val)) { ItemData val2 = val.GetComponent<ItemDrop>().m_itemData.Clone(); val2.m_dropPrefab = val; val2.m_quality = 2; val2.m_durability = val2.GetMaxDurability(); val2.m_cheated = CheatUtils.IsCheated(__instance.m_nview.GetZDO()) && !PlayerProfile.s_bypassCheatChecks; __instance.GetInventory().AddItem(val2); } } } } internal static class IconArt { public static Sprite MakeLowerIcon(Sprite raise) { //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Expected O, but got Unknown if (!Object.op_Implicit((Object)(object)raise) || !Object.op_Implicit((Object)(object)raise.texture)) { return null; } try { int width; int height; Color32[] array = ReadPixels(raise, out width, out height); List<(int, int)> list = new List<(int, int)>(); int num = -1; for (int i = 0; i <= height; i++) { bool flag = false; if (i < height) { for (int j = 0; j < width; j++) { if (flag) { break; } flag = array[i * width + j].a > 10; } } if (flag && num < 0) { num = i; } else if (!flag && num >= 0) { list.Add((num, i - 1)); num = -1; } } if (list.Count < 2) { return null; } (int, int) tuple = list[list.Count - 1]; int num2 = tuple.Item2 - tuple.Item1 + 1; int num3 = tuple.Item2 - list[0].Item1 + 1; if (num2 < 4 || (float)num2 > (float)num3 * 0.6f) { return null; } Color32[] array2 = (Color32[])array.Clone(); var (k, _) = tuple; for (; k <= tuple.Item2; k++) { int num4 = tuple.Item1 + tuple.Item2 - k; Array.Copy(array, num4 * width, array2, k * width, width); } Texture2D val = new Texture2D(width, height, (TextureFormat)4, false) { name = "VUH_LowerGround", filterMode = ((Texture)raise.texture).filterMode, wrapMode = (TextureWrapMode)1 }; val.SetPixels32(array2); val.Apply(false, true); Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)width, (float)height), new Vector2(0.5f, 0.5f), raise.pixelsPerUnit); ((Object)obj).name = "VUH_LowerGround"; return obj; } catch (Exception ex) { Logger.LogWarning((object)("Could not make the Lower Ground icon from the game's Raise Ground icon: " + ex.Message)); return null; } } public static Color32[] ReadPixels(Sprite sprite, out int width, out int height) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown Rect textureRect = sprite.textureRect; Texture2D texture = sprite.texture; width = Mathf.RoundToInt(((Rect)(ref textureRect)).width); height = Mathf.RoundToInt(((Rect)(ref textureRect)).height); RenderTexture temporary = RenderTexture.GetTemporary(((Texture)texture).width, ((Texture)texture).height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2); RenderTexture active = RenderTexture.active; try { Graphics.Blit((Texture)(object)texture, temporary); RenderTexture.active = temporary; Texture2D val = new Texture2D(width, height, (TextureFormat)4, false); val.ReadPixels(new Rect(((Rect)(ref textureRect)).x, ((Rect)(ref textureRect)).y, (float)width, (float)height), 0, 0); val.Apply(); Color32[] pixels = val.GetPixels32(); Object.Destroy((Object)val); return pixels; } finally { RenderTexture.active = active; RenderTexture.ReleaseTemporary(temporary); } } } [HarmonyPatch(typeof(TerrainOp), "Awake")] internal static class TerrainOp_Awake_Patch { private static bool Prefix(TerrainOp __instance) { //IL_009f: 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_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) if (TerrainOp.m_forceDisableTerrainOps) { return true; } if (!HoeContent.TryGetTool(((Component)__instance).gameObject, out var info)) { return true; } float value = HoeConfig.BrushRadius.Value; Settings settings = __instance.m_settings; settings.m_levelRadius *= value; settings.m_raiseRadius *= value; settings.m_smoothRadius *= value; settings.m_paintRadius *= value; if (info.Shape == HoeContent.Shape.Raise) { settings.m_raiseDelta = HoeConfig.RaiseAmount.Value; } else if (info.Shape == HoeContent.Shape.Lower) { settings.m_raiseDelta = 0f - HoeConfig.RaiseAmount.Value; } Vector3 position = ((Component)__instance).transform.position; switch (info.Kind) { case HoeContent.Kind.Reset: UndoHistory.Push(TerrainEditor.Capture(position, value)); if (TerrainEditor.Reset(position, value) > 0) { HoeInput.Message("Part of the ground could not be reset"); } break; case HoeContent.Kind.Clear: HoeInput.Message(AreaClearer.Clear(position, value)); break; default: { float radius = settings.GetRadius(); UndoHistory.Push(TerrainEditor.Capture(position, radius + 1f)); Vector3 val = (settings.m_rotation ? ((Component)__instance).transform.forward : Vector3.zero); foreach (TerrainComp item in TerrainEditor.Compilers(position, radius, create: true)) { if (TerrainEditor.Writable(item)) { item.DoOperation(position, val, settings); } } break; } case HoeContent.Kind.Road: break; } __instance.OnPlaced(); Object.Destroy((Object)(object)((Component)__instance).gameObject); return false; } } [HarmonyPatch(typeof(Player), "UpdatePlacementGhost")] internal static class Player_UpdatePlacementGhost_Patch { private static void Postfix(Player __instance) { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) GameObject placementGhost = __instance.m_placementGhost; HoeContent.ToolInfo info; if (!Object.op_Implicit((Object)(object)placementGhost) || (Object)(object)__instance != (Object)(object)Player.m_localPlayer || !HoeContent.IsHoldingHoe(__instance)) { GridLines.Hide(); BrushOutline.Hide(); } else if (HoeContent.TryGetTool(placementGhost, out info)) { GridLines.Hide(); float value = HoeConfig.BrushRadius.Value; float num = value * info.Reach / info.GhostRadius; placementGhost.transform.localScale = new Vector3(num, 1f, num); if (info.Kind == HoeContent.Kind.Road) { BrushOutline.Hide(); RoadBuilder.UpdatePreview(placementGhost.transform.position, Utils.GetPrefabName(placementGhost)); return; } RoadBuilder.Cancel(); if (placementGhost.activeSelf) { BrushOutline.Show(placementGhost.transform.position, value * info.Core, value * info.Reach); } else { BrushOutline.Hide(); } } else { BrushOutline.Hide(); RoadBuilder.Cancel(); FarmGrid.UpdateGhost(__instance, placementGhost); } } } [HarmonyPatch(typeof(ZInput), "Internal_GetMouseScrollWheel")] internal static class ZInput_GetMouseScrollWheel_Patch { private static void Postfix(ref float __result) { if (HoeInput.WheelSizesBrush && !HoeInput.ReadingWheel) { __result = 0f; } } } [HarmonyPatch(typeof(Player), "SetupPlacementGhost")] internal static class Player_SetupPlacementGhost_Patch { private static void Postfix() { GridLines.Hide(); BrushOutline.Hide(); } } [HarmonyPatch(typeof(ZNet), "Awake")] internal static class ZNet_Awake_Patch { private static void Prefix() { UndoHistory.Clear(); PlantUndo.Clear(); Planting.ResetSync(); } } internal static class Planting { private static readonly HashSet<string> PlantPieceNames = new HashSet<string>(); private static readonly Dictionary<string, float> RadiusByName = new Dictionary<string, float>(); private static int _syncedCultivatorCount = -1; public static bool IsPlantPiece(Piece piece) { if (Object.op_Implicit((Object)(object)piece)) { return PlantPieceNames.Contains(Utils.GetPrefabName(((Component)piece).gameObject)); } return false; } public static bool IsPlantPiece(GameObject go) { if (Object.op_Implicit((Object)(object)go)) { return PlantPieceNames.Contains(Utils.GetPrefabName(go)); } return false; } public static bool TryGetGrowRadius(string prefabName, out float radius) { return RadiusByName.TryGetValue(prefabName, out radius); } public static void ResetSync() { _syncedCultivatorCount = -1; } public static void Sync(Player player) { if (!HoeConfig.EnablePlanting.Value || !Object.op_Implicit((Object)(object)ObjectDB.instance)) { return; } PieceTable val = BuildTable("VUH_Hoe"); PieceTable val2 = BuildTable("Cultivator"); if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2) || val2.m_pieces.Count == _syncedCultivatorCount) { return; } int num = 0; foreach (GameObject piece in val2.m_pieces) { if (!Object.op_Implicit((Object)(object)piece) || Object.op_Implicit((Object)(object)piece.GetComponent<TerrainOp>()) || !Object.op_Implicit((Object)(object)piece.GetComponent<Piece>())) { continue; } PlantPieceNames.Add(((Object)piece).name); Plant component = piece.GetComponent<Plant>(); if (Object.op_Implicit((Object)(object)component)) { RadiusByName[((Object)piece).name] = component.m_growRadius; if (component.m_grownPrefabs != null) { GameObject[] grownPrefabs = component.m_grownPrefabs; foreach (GameObject val3 in grownPrefabs) { if (Object.op_Implicit((Object)(object)val3) && !RadiusByName.ContainsKey(((Object)val3).name)) { RadiusByName[((Object)val3).name] = component.m_growRadius; } } } } if (!val.m_pieces.Contains(piece)) { val.m_pieces.Add(piece); num++; } } _syncedCultivatorCount = val2.m_pieces.Count; if (num > 0) { Logger.LogInfo((object)$"Added {num} planting pieces to the hoe."); if (Object.op_Implicit((Object)(object)player)) { player.UpdateAvailablePiecesList(); } } } private static PieceTable BuildTable(string itemName) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(itemName); if (!Object.op_Implicit((Object)(object)itemPrefab)) { return null; } return itemPrefab.GetComponent<ItemDrop>()?.m_itemData.m_shared.m_buildPieces; } } [HarmonyPatch(typeof(Player), "UpdatePlacement")] internal static class Player_UpdatePlacement_Patch { private static void Prefix(Player __instance) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) PieceTable buildPieces = __instance.m_buildPieces; if (Object.op_Implicit((Object)(object)buildPieces) && HoeContent.IsHoldingHoe(__instance) && !(Utils.GetPrefabName(((Component)buildPieces).gameObject) != "_VUH_HoePieceTable")) { buildPieces.m_skill = (SkillType)(Planting.IsPlantPiece(buildPieces.GetSelectedPiece()) ? 106 : 0); } } } internal static class PlantUndo { private sealed class Planted { public ZDOID Id; public string PrefabName; public List<KeyValuePair<GameObject, int>> Refund; } private static readonly LinkedList<Planted> Steps = new LinkedList<Planted>(); internal static bool Recording; public static void Clear() { Steps.Clear(); } public static void Record(Piece piece) { //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) ZNetView component = ((Component)piece).GetComponent<ZNetView>(); if (!Object.op_Implicit((Object)(object)component) || !component.IsValid()) { return; } List<KeyValuePair<GameObject, int>> list = new List<KeyValuePair<GameObject, int>>(); Player localPlayer = Player.m_localPlayer; if (Object.op_Implicit((Object)(object)localPlayer) && !localPlayer.NoCostCheat() && piece.m_resources != null) { Requirement[] resources = piece.m_resources; foreach (Requirement val in resources) { if (val != null && Object.op_Implicit((Object)(object)val.m_resItem) && val.m_amount > 0) { list.Add(new KeyValuePair<GameObject, int>(((Component)val.m_resItem).gameObject, val.m_amount)); } } } Steps.AddLast(new Planted { Id = component.GetZDO().m_uid, PrefabName = Utils.GetPrefabName(((Component)piece).gameObject), Refund = list }); while (Steps.Count > HoeConfig.UndoSteps.Value) { Steps.RemoveFirst(); } } public static string Undo() { //IL_003a: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; while (Steps.Count > 0) { Planted value = Steps.Last.Value; Steps.RemoveLast(); GameObject val = (Object.op_Implicit((Object)(object)ZNetScene.instance) ? ZNetScene.instance.FindInstance(value.Id) : null); if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.GetComponent<Plant>()) || Utils.GetPrefabName(val) != value.PrefabName) { continue; } ZNetView component = val.GetComponent<ZNetView>(); if (!Object.op_Implicit((Object)(object)component) || !component.IsValid()) { continue; } if (!component.IsOwner()) { component.ClaimOwnership(); } ZNetScene.instance.Destroy(val); bool flag = false; if (Object.op_Implicit((Object)(object)localPlayer)) { foreach (KeyValuePair<GameObject, int> item in value.Refund) { flag |= Give(localPlayer, item.Key, item.Value); } } string text = $"{Steps.Count} left"; if (!flag) { return "Plant removed. " + text; } return "Plant removed; inventory full, seeds dropped at your feet. " + text; } return "No plants to undo"; } private static bool Give(Player player, GameObject itemPrefab, int amount) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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_004c: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) Inventory inventory = ((Humanoid)player).GetInventory(); if (inventory.CanAddItem(itemPrefab, amount) && inventory.AddItem(itemPrefab, amount)) { return false; } Vector3 val = ((Component)player).transform.position + ((Component)player).transform.forward * 0.5f + Vector3.up; ItemDrop component = Object.Instantiate<GameObject>(itemPrefab, val, Quaternion.identity).GetComponent<ItemDrop>(); if (Object.op_Implicit((Object)(object)component)) { component.SetStack(amount); } return true; } } [HarmonyPatch(typeof(Player), "PlacePiece")] internal static class Player_PlacePiece_Patch { private static void Prefix(Player __instance, Piece piece) { PlantUndo.Recording = (Object)(object)__instance == (Object)(object)Player.m_localPlayer && HoeContent.IsHoldingHoe(__instance) && Planting.IsPlantPiece(piece); } private static void Finalizer() { PlantUndo.Recording = false; } } [HarmonyPatch(typeof(Piece), "SetCreator")] internal static class Piece_SetCreator_Patch { private static void Postfix(Piece __instance) { if (PlantUndo.Recording) { PlantUndo.Record(__instance); } } } [BepInPlugin("com.veymoris.ultimatehoe", "Veymoris Midgard Hoe", "1.3.3")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string Guid = "com.veymoris.ultimatehoe"; public const string ModName = "Veymoris Midgard Hoe"; public const string Version = "1.3.3"; internal static Plugin Instance; private Harmony _harmony; private void Awake() { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown Instance = this; HoeConfig.Bind(((BaseUnityPlugin)this).Config); PrefabManager.OnVanillaPrefabsAvailable += HoeContent.Create; CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new ResetTerrainCommand()); CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new UndoTerrainCommand()); _harmony = new Harmony("com.veymoris.ultimatehoe"); _harmony.PatchAll(typeof(Plugin).Assembly); } private void Update() { HoeInput.Update(); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } internal static class RoadBuilder { private struct Plan { public List<Vector3> Center; public float Length; public float MaxSlopeDeg; public bool TooSteep; public bool TooLong; } private const float SampleSpacing = 0.5f; private const float FinishDistance = 1f; private static readonly List<Vector3> Points = new List<Vector3>(); private static string _tool; private static readonly LineSet Preview = new LineSet("VUH_RoadPreview", 0.06f); private static string _lastText; public static bool Active => Points.Count > 0; public static void Cancel() { if (Points.Count != 0 || _tool != null) { Points.Clear(); _tool = null; _lastText = null; Preview.Hide(); } } public static bool StepBack() { if (Points.Count == 0) { return false; } Points.RemoveAt(Points.Count - 1); HoeInput.Message((Points.Count == 0) ? "Road cancelled" : $"Removed a point ({Points.Count} left)"); if (Points.Count == 0) { Preview.Hide(); } return true; } public static bool Click(Player player, Vector3 point, HoeContent.ToolInfo tool, string toolName) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0084: 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_004d: Unknown result type (might be due to invalid IL or missing references) if (_tool != toolName) { Points.Clear(); _tool = toolName; } if (!PrivateArea.CheckAccess(point, 0f, true, false)) { return false; } if (Points.Count >= 1 && Horizontal(point, Points[Points.Count - 1]) < 1f) { if (Points.Count < 2) { HoeInput.Message("Click a second point first"); return false; } return Build(player, tool); } Points.Add(point); HoeInput.Message((Points.Count == 1) ? "Road started. Click more points, then click the last one again to build" : $"Point {Points.Count} added. Click it again to build"); return false; } public static void UpdatePreview(Vector3 cursor, string toolName) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_004c: 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_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) if (_tool != toolName) { Cancel(); _tool = toolName; } if (Points.Count == 0) { Preview.Hide(); return; } List<Vector3> list = new List<Vector3>(Points); bool flag = Horizontal(cursor, Points[Points.Count - 1]) < 1f; if (!flag) { list.Add(cursor); } if (list.Count < 2) { Preview.Hide(); return; } Plan plan = MakePlan(list); float value = HoeConfig.BrushRadius.Value; List<List<Vector3>> list2 = new List<List<Vector3>> { plan.Center, Offset(plan.Center, value), Offset(plan.Center, 0f - value) }; float value2 = HoeConfig.RoadShoulder.Value; if (value2 > 0.1f) { list2.Add(Offset(plan.Center, value + value2)); list2.Add(Offset(plan.Center, 0f - value - value2)); } Color color = ((plan.TooSteep || plan.TooLong) ? new Color(1f, 0.35f, 0.3f, 0.8f) : (flag ? new Color(1f, 0.9f, 0.3f, 0.85f) : new Color(0.55f, 0.9f, 1f, 0.75f))); Preview.Show(list2, color, followGround: false); string text = (plan.TooLong ? $" - too long (max {HoeConfig.RoadMaxLength.Value:0} m)" : (plan.TooSteep ? $" - too steep (max {HoeConfig.RoadMaxSlope.Value:0}°)" : (flag ? " - click to build" : ""))); string text2 = $"Road {plan.Length:0} m, {value * 2f:0.#} m wide, steepest {plan.MaxSlopeDeg:0}°{text}"; if (text2 != _lastText && Object.op_Implicit((Object)(object)MessageHud.instance)) { _lastText = text2; MessageHud.instance.ShowMessage((MessageType)2, text2, 0, (Sprite)null, false, true); } } private static bool Build(Player player, HoeContent.ToolInfo tool) { //IL_009c: 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_00e2: 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_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_010e: 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) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: 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_04a5: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_0293: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_03a8: Unknown result type (might be due to invalid IL or missing references) //IL_03be: Unknown result type (might be due to invalid IL or missing references) //IL_03d4: Unknown result type (might be due to invalid IL or missing references) //IL_03db: Unknown result type (might be due to invalid IL or missing references) //IL_02a8: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Unknown result type (might be due to invalid IL or missing references) //IL_03e6: Unknown result type (might be due to invalid IL or missing references) //IL_03ed: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_03f8: Unknown result type (might be due to invalid IL or missing references) //IL_03ff: Unknown result type (might be due to invalid IL or missing references) //IL_040a: Unknown result type (might be due to invalid IL or missing references) //IL_0411: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_0422: Unknown result type (might be due to invalid IL or missing references) //IL_043f: Unknown result type (might be due to invalid IL or missing references) //IL_0444: Unknown result type (might be due to invalid IL or missing references) Plan plan = MakePlan(Points); if (plan.TooLong) { HoeInput.Message($"Too long: {plan.Length:0} m (max {HoeConfig.RoadMaxLength.Value:0} m)"); return false; } if (plan.TooSteep) { HoeInput.Message($"Too steep: {plan.MaxSlopeDeg:0}° (max {HoeConfig.RoadMaxSlope.Value:0}°)"); return false; } float value = HoeConfig.BrushRadius.Value; float value2 = HoeConfig.RoadShoulder.Value; float num = value + value2; foreach (Vector3 item in plan.Center) { if (!PrivateArea.CheckAccess(item, num, true, false)) { HoeInput.Message("A ward protects part of the way"); return false; } } Vector3 val = plan.Center[0]; Vector3 val2 = plan.Center[0]; foreach (Vector3 item2 in plan.Center) { val = Vector3.Min(val, item2); val2 = Vector3.Max(val2, item2); } Vector3 val3 = (val + val2) * 0.5f; Vector2 val4 = new Vector2(val2.x - val.x, val2.z - val.z); float num2 = ((Vector2)(ref val4)).magnitude * 0.5f + num + 1f; TerrainEditor.Snapshot snap = TerrainEditor.Capture(val3, num2); int num3 = 0; int num4 = 0; Color? val5 = PaintColor(tool.RoadPaint); Vector3 val6 = default(Vector3); Vector3 val7 = default(Vector3); foreach (TerrainComp item3 in TerrainEditor.Compilers(val3, num2, create: true)) { if (!TerrainEditor.Writable(item3)) { num4++; continue; } Heightmap hmap = item3.m_hmap; int num5 = item3.m_width + 1; float scale = hmap.m_scale; Vector3 position = ((Component)hmap).transform.position; int num6 = item3.m_width / 2; int num7 = (item3.m_width + 1) / 2; bool flag = false; for (int i = 0; i < num5; i++) { for (int j = 0; j < num5; j++) { int num8 = i * num5 + j; ((Vector3)(ref val6))..ctor(position.x + (float)(j - num6) * scale, 0f, position.z + (float)(i - num6) * scale); if (val6.x >= val.x - num && val6.x <= val2.x + num && val6.z >= val.z - num && val6.z <= val2.z + num && Nearest(plan.Center, val6, out var distance, out var height) && distance <= num) { float height2 = hmap.GetHeight(j, i); float num9 = height - position.y; float num10 = ((distance <= value) ? num9 : Mathf.Lerp(num9, height2, Smooth((distance - value) / Mathf.Max(value2, 0.01f)))); float num11 = item3.m_levelDelta[num8] + item3.m_smoothDelta[num8] + (num10 - height2); if (num11 < -8f || num11 > 8f) { num3++; } item3.m_levelDelta[num8] = Mathf.Clamp(num11, -8f, 8f); item3.m_smoothDelta[num8] = 0f; item3.m_modifiedHeight[num8] = true; flag = true; } if (val5.HasValue && num8 < item3.m_paintMask.Length) { ((Vector3)(ref val7))..ctor(position.x + (float)(j - num7) * scale, 0f, position.z + (float)(i - num7) * scale); if (val7.x >= val.x - value && val7.x <= val2.x + value && val7.z >= val.z - value && val7.z <= val2.z + value && Nearest(plan.Center, val7, out var distance2, out var _) && distance2 <= value) { item3.m_paintMask[num8] = val5.Value; item3.m_modifiedPaint[num8] = true; flag = true; } } } } if (flag) { TerrainEditor.Commit(item3); } } ClutterSystem instance = ClutterSystem.instance; if (instance != null) { instance.ResetGrass(val3, num2); } UndoHistory.Push(snap); Cancel(); string text = $"Road built: {plan.Length:0} m"; if (num3 > 0) { text += ". Some spots hit the game's 8 m dig/raise limit"; } if (num4 > 0) { text += ". Part of it was too far away"; } HoeInput.Message(text); return true; } private static Color? PaintColor(PaintType? paint) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected I4, but got Unknown //IL_0025: 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_0030: Unknown result type (might be due to invalid IL or missing references) return paint switch { (PaintType)0L => Heightmap.m_paintMaskDirt, (PaintType)2L => Heightmap.m_paintMaskPaved, (PaintType)1L => Heightmap.m_paintMaskCultivated, _ => null, }; } private static Plan MakePlan(List<Vector3> pts) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: 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_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: 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_0058: Unknown result type (might be due to inv