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 SuperHoe v1.0.0
SuperHoe.dll
Decompiled 5 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("SuperHoe")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("SuperHoe")] [assembly: AssemblyTitle("SuperHoe")] [assembly: AssemblyVersion("1.0.0.0")] [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 SuperHoe { internal static class Items { public const string PrefabName = "SuperHoe"; public const string VanillaHoePrefabName = "Hoe"; public static void RegisterSuperHoe() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Expected O, but got Unknown //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Expected O, but got Unknown //IL_0211: Unknown result type (might be due to invalid IL or missing references) ItemConfig val = new ItemConfig { Name = "Super Hoe", Description = "A hoe touched by something greater. Free to use, hungry for hills.", CraftingStation = "piece_workbench", Icon = null }; val.AddRequirement(new RequirementConfig("Wood", 5, 0, false)); CustomItem val2 = new CustomItem("SuperHoe", "Hoe", val); GameObject itemPrefab = val2.ItemPrefab; if ((Object)(object)itemPrefab == (Object)null) { Logger.LogError((object)"SuperHoe: failed to clone Hoe prefab - is Jotunn loaded before this mod, and did the vanilla Hoe prefab name change?"); return; } ItemDrop component = itemPrefab.GetComponent<ItemDrop>(); if ((Object)(object)component != (Object)null) { component.m_itemData.m_shared.m_buildPieces = null; component.m_itemData.m_shared.m_useDurability = false; GameObject prefab = PrefabManager.Instance.GetPrefab("Hoe"); ItemDrop val3 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ItemDrop>() : null); if ((Object)(object)val3 != (Object)null && val3.m_itemData.m_shared.m_icons != null && val3.m_itemData.m_shared.m_icons.Length != 0) { component.m_itemData.m_shared.m_icons = val3.m_itemData.m_shared.m_icons; } else { Logger.LogWarning((object)"SuperHoe: could not find the vanilla Hoe's icon to copy - it may still show as a placeholder."); } } itemPrefab.AddComponent<SuperHoeComponent>(); SuperHoeComponent.ApplyGlow(itemPrefab); Transform val4 = itemPrefab.transform.Find("attach"); if ((Object)(object)val4 == (Object)null) { Logger.LogWarning((object)"SuperHoe: no 'attach' child found on the cloned Hoe - light will only show on the dropped item, not in-hand."); val4 = itemPrefab.transform; } GameObject val5 = new GameObject("SuperHoeLight"); val5.transform.SetParent(val4, false); Light light = val5.AddComponent<Light>(); light.type = (LightType)2; light.range = ModConfig.LightRange.Value; light.intensity = ModConfig.LightIntensity.Value; light.color = new Color(1f, 0.82f, 0.55f); light.shadows = (LightShadows)2; ModConfig.LightRange.SettingChanged += delegate { light.range = ModConfig.LightRange.Value; }; ModConfig.LightIntensity.SettingChanged += delegate { light.intensity = ModConfig.LightIntensity.Value; }; ItemManager.Instance.AddItem(val2); PavingAction.RegisterLevelMarkerPrefab(); Logger.LogInfo((object)"SuperHoe: item registered."); } } internal static class ModConfig { public static ConfigEntry<float> PavingRadius; public static ConfigEntry<float> DestroyRadius; public static ConfigEntry<bool> DestroyEnabled; public static ConfigEntry<float> StaminaCostPerUse; public static ConfigEntry<string> ResourceItemPrefab; public static ConfigEntry<int> ResourceItemAmount; public static ConfigEntry<float> LightRange; public static ConfigEntry<float> LightIntensity; public static ConfigEntry<Color> GlowColor; public static ConfigEntry<float> GlowIntensity; public static ConfigEntry<KeyCode> LockModifierKey; public static void BindAll(ConfigFile config) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Expected O, but got Unknown //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Expected O, but got Unknown //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Expected O, but got Unknown //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Expected O, but got Unknown //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Expected O, but got Unknown //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Expected O, but got Unknown //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Expected O, but got Unknown //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Expected O, but got Unknown //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Expected O, but got Unknown //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Expected O, but got Unknown //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Expected O, but got Unknown //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Expected O, but got Unknown //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Expected O, but got Unknown //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Expected O, but got Unknown PavingRadius = config.Bind<float>("Server-synced", "Paving Radius", 3f, new ConfigDescription("Radius (meters) of the terrain leveling + cobblestone paint applied per paving swing.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); DestroyRadius = config.Bind<float>("Server-synced", "Destroy Radius", 3f, new ConfigDescription("Radius (meters) in which trees and rocks are destroyed per paving swing. Independent of Paving Radius.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); DestroyEnabled = config.Bind<bool>("Server-synced", "Destroy Trees And Rocks", true, new ConfigDescription("If disabled, paving only levels/paints terrain and never destroys trees or rocks.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); StaminaCostPerUse = config.Bind<float>("Server-synced", "Stamina Cost Per Use", 0f, new ConfigDescription("Stamina consumed per paving swing. 0 = free (default request).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50f), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); ResourceItemPrefab = config.Bind<string>("Server-synced", "Resource Item (prefab name)", "", new ConfigDescription("Vanilla item prefab name required per paving swing (e.g. 'Stone'). Leave blank for no resource cost (default request).", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); ResourceItemAmount = config.Bind<int>("Server-synced", "Resource Item Amount", 0, new ConfigDescription("How many of Resource Item are consumed per paving swing. Ignored if Resource Item is blank.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); LightRange = config.Bind<float>("Server-synced", "Light Range", 9f, new ConfigDescription("Radius of the light SuperHoe gives off. Vanilla torch is roughly 6, so 9 is the requested 1.5x. Tune to taste once you see it in-game.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 30f), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); LightIntensity = config.Bind<float>("Server-synced", "Light Intensity", 1.3f, new ConfigDescription("Brightness of SuperHoe's light. Approximate torch value - tune to taste.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); GlowColor = config.Bind<Color>("Client", "Glow Color", new Color(1f, 0.84f, 0.2f), "Tint of the item's golden glow. Cosmetic only, not synced."); GlowIntensity = config.Bind<float>("Client", "Glow Emission Intensity", 2f, new ConfigDescription("Strength of the emissive glow on the hoe head. Cosmetic only, not synced.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>())); LockModifierKey = config.Bind<KeyCode>("Client", "Height Lock Modifier Key", (KeyCode)304, "Hold this key while left-clicking to set (or reset) the locked reference height. Plain left-click paves toward the currently locked height. Personal preference, not synced."); } } internal static class PavingAction { public const string LevelMarkerPrefabName = "SuperHoe_LevelMarker"; private static GameObject _markerPrefabTemplate; public static void RegisterLevelMarkerPrefab() { //IL_00dd: Unknown result type (might be due to invalid IL or missing references) GameObject val = PrefabManager.Instance.CreateEmptyPrefab("SuperHoe_LevelMarker", true); if ((Object)(object)val == (Object)null) { Logger.LogError((object)"SuperHoe: failed to create the level marker prefab (name collision?)."); return; } MeshRenderer component = val.GetComponent<MeshRenderer>(); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } MeshFilter component2 = val.GetComponent<MeshFilter>(); if ((Object)(object)component2 != (Object)null) { Object.DestroyImmediate((Object)(object)component2); } Collider component3 = val.GetComponent<Collider>(); if ((Object)(object)component3 != (Object)null) { Object.DestroyImmediate((Object)(object)component3); } TerrainModifier modifier = val.AddComponent<TerrainModifier>(); modifier.m_playerModifiction = true; modifier.m_level = true; modifier.m_square = false; modifier.m_levelOffset = 0f; modifier.m_paintCleared = true; modifier.m_paintType = (PaintType)2; ApplyRadiusFromConfig(modifier); PrefabManager.Instance.AddPrefab(val); _markerPrefabTemplate = val; ModConfig.PavingRadius.SettingChanged += delegate { ApplyRadiusFromConfig(modifier); }; } private static void ApplyRadiusFromConfig(TerrainModifier modifier) { modifier.m_levelRadius = ModConfig.PavingRadius.Value; modifier.m_paintRadius = ModConfig.PavingRadius.Value; } public static bool PaveAt(Player player, Vector3 point, float targetHeight) { //IL_001b: 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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) float num = Mathf.Max(ModConfig.PavingRadius.Value, ModConfig.DestroyRadius.Value); if (!PrivateArea.CheckAccess(point, num, true, false)) { ((Character)player).Message((MessageType)2, "$msg_privatezone", 0, (Sprite)null, false); return false; } if (ModConfig.DestroyEnabled.Value) { RunDestroyPass(player, point); } Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(point.x, targetHeight, point.z); GameObject val2 = Object.Instantiate<GameObject>(_markerPrefabTemplate, val, Quaternion.identity); val2.SetActive(true); return true; } private static void RunDestroyPass(Player player, Vector3 point) { //IL_000c: 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_0186: Unknown result type (might be due to invalid IL or missing references) float value = ModConfig.DestroyRadius.Value; Collider[] array = Physics.OverlapSphere(point, value); HashSet<GameObject> hashSet = new HashSet<GameObject>(); Collider[] array2 = array; foreach (Collider val in array2) { GameObject val2 = (((Object)(object)val.attachedRigidbody != (Object)null) ? ((Component)val.attachedRigidbody).gameObject : ((Component)val).gameObject); TreeBase componentInParent = val2.GetComponentInParent<TreeBase>(); TreeLog componentInParent2 = val2.GetComponentInParent<TreeLog>(); MineRock5 componentInParent3 = val2.GetComponentInParent<MineRock5>(); MineRock componentInParent4 = val2.GetComponentInParent<MineRock>(); Destructible componentInParent5 = val2.GetComponentInParent<Destructible>(); Pickable componentInParent6 = val2.GetComponentInParent<Pickable>(); PickableItem componentInParent7 = val2.GetComponentInParent<PickableItem>(); GameObject val3 = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).gameObject : (((Object)(object)componentInParent2 != (Object)null) ? ((Component)componentInParent2).gameObject : (((Object)(object)componentInParent3 != (Object)null) ? ((Component)componentInParent3).gameObject : (((Object)(object)componentInParent4 != (Object)null) ? ((Component)componentInParent4).gameObject : (((Object)(object)componentInParent5 != (Object)null) ? ((Component)componentInParent5).gameObject : (((Object)(object)componentInParent6 != (Object)null) ? ((Component)componentInParent6).gameObject : (((Object)(object)componentInParent7 != (Object)null) ? ((Component)componentInParent7).gameObject : null))))))); if ((Object)(object)val3 == (Object)null || !hashSet.Add(val3)) { continue; } if ((Object)(object)componentInParent6 != (Object)null) { componentInParent6.Interact((Humanoid)(object)player, false, false); continue; } if ((Object)(object)componentInParent7 != (Object)null) { componentInParent7.Interact((Humanoid)(object)player, false, false); continue; } HitData val4 = BuildDestroyHit(player, val.ClosestPoint(point)); if ((Object)(object)componentInParent != (Object)null) { componentInParent.Damage(val4); } else if ((Object)(object)componentInParent2 != (Object)null) { componentInParent2.Damage(val4); } else if ((Object)(object)componentInParent3 != (Object)null) { componentInParent3.Damage(val4); } else if ((Object)(object)componentInParent4 != (Object)null) { componentInParent4.Damage(val4); } else if ((Object)(object)componentInParent5 != (Object)null) { componentInParent5.Damage(val4); } } } private static HitData BuildDestroyHit(Player player, Vector3 point) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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) HitData val = new HitData(); val.m_damage.m_chop = 9999f; val.m_damage.m_pickaxe = 9999f; val.m_damage.m_damage = 9999f; val.m_toolTier = 100; val.m_point = point; val.m_dir = Vector3.up; val.SetAttacker((Character)(object)player); return val; } } [HarmonyPatch(typeof(Player), "PlayerAttackInput")] internal static class PlayerAttackPatch { private static readonly Dictionary<ZDOID, float> LockedHeights = new Dictionary<ZDOID, float>(); private static bool Prefix(Player __instance, float dt) { ItemData value = Traverse.Create((object)__instance).Method("GetRightItem", Array.Empty<object>()).GetValue<ItemData>(); if (value == null || (Object)(object)value.m_dropPrefab == (Object)null || ((Object)value.m_dropPrefab).name != "SuperHoe") { return true; } if (ZInput.GetButtonDown("Attack")) { HandleClick(__instance); } return false; } private static void HandleClick(Player player) { //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_0026: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) if (!TryGetGroundPoint(player, out var point, out var terrainHeight)) { return; } ZDOID zDOID = ((Character)player).GetZDOID(); if (Input.GetKey(ModConfig.LockModifierKey.Value)) { LockedHeights[zDOID] = terrainHeight; ((Character)player).Message((MessageType)2, "Height locked.", 0, (Sprite)null, false); return; } if (!LockedHeights.TryGetValue(zDOID, out var value)) { value = terrainHeight; LockedHeights[zDOID] = value; } if (PayCost(player)) { PavingAction.PaveAt(player, point, value); } } private static bool PayCost(Player player) { float value = ModConfig.StaminaCostPerUse.Value; if (value > 0f) { if (!((Character)player).HaveStamina(value)) { ((Character)player).Message((MessageType)2, "$msg_notenoughstamina", 0, (Sprite)null, false); return false; } ((Character)player).UseStamina(value); } string value2 = ModConfig.ResourceItemPrefab.Value; int value3 = ModConfig.ResourceItemAmount.Value; if (!string.IsNullOrEmpty(value2) && value3 > 0) { Inventory inventory = ((Humanoid)player).GetInventory(); if (inventory.CountItems(value2, -1, true) < value3) { ((Character)player).Message((MessageType)2, "$msg_missingrequirement", 0, (Sprite)null, false); return false; } inventory.RemoveItem(value2, value3, -1, true); } return true; } private static bool TryGetGroundPoint(Player player, out Vector3 point, out float terrainHeight) { //IL_0002: 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_002b: 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_0052: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0086: 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) point = Vector3.zero; terrainHeight = 0f; Transform eye = ((Character)player).m_eye; if ((Object)(object)eye == (Object)null) { return false; } RaycastHit val = default(RaycastHit); if (!Physics.Raycast(eye.position, eye.forward, ref val, 50f)) { return false; } if (!Heightmap.GetHeight(((RaycastHit)(ref val)).point, ref terrainHeight)) { return false; } point = new Vector3(((RaycastHit)(ref val)).point.x, terrainHeight, ((RaycastHit)(ref val)).point.z); return true; } } [BepInPlugin("com.yourname.superhoe", "SuperHoe", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class SuperHoePlugin : BaseUnityPlugin { public const string PluginGUID = "com.yourname.superhoe"; public const string PluginName = "SuperHoe"; public const string PluginVersion = "1.0.0"; private readonly Harmony _harmony = new Harmony("com.yourname.superhoe"); private void Awake() { ModConfig.BindAll(((BaseUnityPlugin)this).Config); PrefabManager.OnVanillaPrefabsAvailable += Items.RegisterSuperHoe; _harmony.PatchAll(); Logger.LogInfo((object)"SuperHoe 1.0.0 loaded."); } private void OnDestroy() { PrefabManager.OnVanillaPrefabsAvailable -= Items.RegisterSuperHoe; _harmony.UnpatchSelf(); } } public class SuperHoeComponent : MonoBehaviour { private static readonly int EmissionColorId = Shader.PropertyToID("_EmissionColor"); private void Awake() { ApplyGlow(((Component)this).gameObject); ModConfig.GlowColor.SettingChanged += delegate { ApplyGlow(((Component)this).gameObject); }; ModConfig.GlowIntensity.SettingChanged += delegate { ApplyGlow(((Component)this).gameObject); }; } public static void ApplyGlow(GameObject root) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true); int num = 0; Renderer[] array = componentsInChildren; foreach (Renderer val in array) { Material[] materials = val.materials; foreach (Material val2 in materials) { if (val2.HasProperty(EmissionColorId)) { val2.EnableKeyword("_EMISSION"); Color val3 = ModConfig.GlowColor.Value * ModConfig.GlowIntensity.Value; val2.SetColor(EmissionColorId, val3); num++; } } } if (num == 0) { Logger.LogWarning((object)"SuperHoe: no material on the hoe mesh exposed _EmissionColor - glow was not applied. The vanilla Hoe's shader may use a different emission property name."); } } } }