using System; using System.Collections; using System.Collections.Generic; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("0.0.0.0")] namespace Robgob.ValheimVeinMining; [BepInPlugin("com.robgob.valheim.veinmining", "Valheim Vein Mining", "1.6.1")] public sealed class Plugin : BaseUnityPlugin { private sealed class Job { internal ZNetView View; internal HitData Hit; internal int Count; internal int Index; } public const string Guid = "com.robgob.valheim.veinmining"; public const string Name = "Valheim Vein Mining"; public const string Version = "1.6.1"; internal static Plugin Instance; private readonly List jobs = new List(); internal static ConfigEntry Key; internal static ConfigEntry Names; private void Awake() { //IL_0021: 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) Instance = this; Key = ((BaseUnityPlugin)this).Config.Bind("General", "ModifierKey", new KeyboardShortcut((KeyCode)308, (KeyCode[])(object)new KeyCode[0]), "Hold while striking."); Names = ((BaseUnityPlugin)this).Config.Bind("General", "TargetNameFragments", "Copper,Tin,Silver,MuddyScrapPile,IronScrap,Flametal,Chitin,Leviathan,Tree,Log,Beech,Birch,Oak,Fir,Pine,Ancient,Yggdrasil,Scorched,Stone", "Comma-separated prefab fragments."); new Harmony("com.robgob.valheim.veinmining").PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Valheim Vein Mining loaded. Hold Left Alt while striking a configured resource."); } internal void QueueDeposit(ZNetView view, HitData hit, int count) { jobs.Add(new Job { View = view, Hit = hit, Count = count, Index = 0 }); } private void Update() { //IL_0083: Unknown result type (might be due to invalid IL or missing references) for (int num = jobs.Count - 1; num >= 0; num--) { Job job = jobs[num]; if ((Object)(object)job.View == (Object)null || !job.View.IsValid()) { jobs.RemoveAt(num); } else { int num2 = Math.Min(job.Index + 3, job.Count); while (job.Index < num2) { job.View.InvokeRPC("RPC_Damage", new object[2] { Vein.Power(job.Hit, null, job.Hit.m_point), job.Index }); job.Index++; } if (job.Index >= job.Count) { jobs.RemoveAt(num); } } } } } internal static class Vein { internal static bool Busy; internal static bool Active(Component c, HitData hit) { if (Busy || (Object)(object)c == (Object)null || hit == null || !KeyDown()) { return false; } string text = ""; Transform val = c.transform; while ((Object)(object)val != (Object)null) { text = text + "/" + ((Object)val).name; val = val.parent; } string[] array = Plugin.Names.Value.Split(new char[1] { ',' }); foreach (string text2 in array) { if (text2.Trim().Length > 0 && text.IndexOf(text2.Trim(), StringComparison.OrdinalIgnoreCase) >= 0) { return true; } } return false; } internal static bool KeyDown() { //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_000d: 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_0023: Unknown result type (might be due to invalid IL or missing references) KeyboardShortcut value = Plugin.Key.Value; if (!Input.GetKey(((KeyboardShortcut)(ref value)).MainKey)) { KeyboardShortcut value2 = Plugin.Key.Value; return ((KeyboardShortcut)(ref value2)).IsPressed(); } return true; } internal static HitData Power(HitData source, Collider collider, Vector3 point) { //IL_000f: 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) HitData val = source.Clone(); val.m_hitCollider = collider; val.m_point = point; val.m_damage.m_pickaxe = Mathf.Max(val.m_damage.m_pickaxe, 1000000f); val.m_damage.m_chop = Mathf.Max(val.m_damage.m_chop, 1000000f); val.m_damage.m_damage = Mathf.Max(val.m_damage.m_damage, 1000000f); return val; } internal static void Whole(Component target, HitData hit, Action damage) { //IL_0026: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) if (!Active(target, hit)) { return; } Busy = true; try { Collider[] componentsInChildren = target.GetComponentsInChildren(true); if (componentsInChildren.Length == 0) { damage(Power(hit, null, target.transform.position)); return; } Collider[] array = componentsInChildren; foreach (Collider val in array) { if ((Object)(object)val != (Object)null && val.enabled) { Bounds bounds = val.bounds; damage(Power(hit, val, ((Bounds)(ref bounds)).center)); } } } finally { Busy = false; } } internal static void One(Component target, HitData hit) { if (Active(target, hit)) { hit.m_damage.m_pickaxe = 1000000f; hit.m_damage.m_chop = 1000000f; hit.m_damage.m_damage = 1000000f; } } internal static void Radius(Component target, HitData hit) { if (!((Object)(object)target == (Object)null) && hit != null && KeyDown()) { hit.m_radius = 100f; hit.m_damage.m_pickaxe = 1000000f; hit.m_damage.m_chop = 1000000f; hit.m_damage.m_damage = 1000000f; } } internal static bool AllMineRock5Areas(MineRock5 target, HitData hit) { if ((Object)(object)target == (Object)null || hit == null || !KeyDown()) { return true; } FieldInfo fieldInfo = AccessTools.Field(typeof(MineRock5), "m_hitAreas"); FieldInfo fieldInfo2 = AccessTools.Field(typeof(MineRock5), "m_nview"); IList list = ((fieldInfo == null) ? null : (fieldInfo.GetValue(target) as IList)); ZNetView val = (ZNetView)((fieldInfo2 == null) ? null : /*isinst with value type is only supported in some contexts*/); if (list == null || (Object)(object)val == (Object)null || !val.IsValid()) { return true; } Plugin.Instance.QueueDeposit(val, hit.Clone(), list.Count); return false; } } [HarmonyPatch(typeof(MineRock5), "Damage")] internal static class MR5 { private static bool Prefix(MineRock5 __instance, HitData hit) { return Vein.AllMineRock5Areas(__instance, hit); } } [HarmonyPatch(typeof(MineRock), "Damage")] internal static class MR { private static void Prefix(MineRock __instance, HitData hit) { if (Vein.KeyDown()) { hit.m_damage.m_pickaxe = 1000000f; hit.m_damage.m_damage = 1000000f; } } } [HarmonyPatch(typeof(TreeBase), "Damage")] internal static class TB { private static void Prefix(TreeBase __instance, HitData hit) { Vein.One((Component)(object)__instance, hit); } } [HarmonyPatch(typeof(TreeLog), "Damage")] internal static class TL { private static void Prefix(TreeLog __instance, HitData hit) { Vein.One((Component)(object)__instance, hit); } } [HarmonyPatch(typeof(Destructible), "Damage")] internal static class DS { private static void Prefix(Destructible __instance, HitData hit) { Vein.One((Component)(object)__instance, hit); } }