using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ComfyAutoPicker")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ComfyAutoPicker")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c912b20f-2bfa-439d-ab23-9a07f0f9ee70")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
namespace ComfyAutoPicker;
[BepInPlugin("EardwulfDoesMods.valheim.ComfyAutoPicker", "ComfyAutoPicker", "1.1.0")]
internal class Mod : BaseUnityPlugin
{
public class Patches
{
[HarmonyPatch(typeof(Pickable), "Awake")]
public static class PickableAwakePatch
{
public static void Postfix(Pickable __instance)
{
((Component)__instance).gameObject.AddComponent<ComfyAutoPicker>();
}
}
}
public const string PluginGuid = "EardwulfDoesMods.valheim.ComfyAutoPicker";
public const string PluginName = "ComfyAutoPicker";
public const string PluginVersion = "1.1.0";
private Harmony _harmony;
public void Awake()
{
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "EardwulfDoesMods.valheim.ComfyAutoPicker");
PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
}
public void Update()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: 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)
KeyboardShortcut value = PluginConfig.ToggleEnabledShortcut.Value;
if (Input.GetKey(((KeyboardShortcut)(ref value)).MainKey))
{
value = PluginConfig.ToggleEnabledShortcut.Value;
if (((KeyboardShortcut)(ref value)).Modifiers.All((Func<KeyCode, bool>)Input.GetKeyDown))
{
PluginConfig.IsModEnabled.Value = !PluginConfig.IsModEnabled.Value;
}
}
}
}
internal class ComfyAutoPicker : MonoBehaviour
{
private static readonly FieldRef<Pickable, bool> m_picked = AccessTools.FieldRefAccess<Pickable, bool>("m_picked");
private void Awake()
{
((MonoBehaviour)this).InvokeRepeating("CheckAndPick", 1f, 0.5f);
}
public void CheckAndPick()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: 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_0033: 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)
if (!PluginConfig.IsModEnabled.Value || Player.m_localPlayer == null)
{
return;
}
Vector3 val = ((Component)this).transform.position - ((Component)Player.m_localPlayer).transform.position;
if (!(((Vector3)(ref val)).sqrMagnitude < 0.64000005f))
{
return;
}
List<string> list = new List<string>
{
"Pickable_Barley", "Pickable_Barley_Wild", "Pickable_Flax", "Pickable_Flax_Wild", "Pickable_Carrot", "Pickable_SeedCarrot", "Pickable_Turnip", "Pickable_SeedTurnip", "Pickable_Onion", "Pickable_SeedOnion",
"CloudberryBush", "Pickable_Mushroom_JotunPuffs", "Pickable_Mushroom_Magecap"
};
Pickable componentInChildren = ((Component)this).GetComponentInChildren<Pickable>();
if (!m_picked.Invoke(componentInChildren))
{
if (!Object.op_Implicit((Object)(object)Player.m_localPlayer) || (((Humanoid)Player.m_localPlayer).m_rightItem != null && ((Humanoid)Player.m_localPlayer).m_rightItem.m_shared.m_name.Contains("$item_cultivator")))
{
((Terminal)Chat.m_instance).AddString("You cannot pick plants when you have a Cultivator Equipped");
}
else if (list.Contains(Utils.GetPrefabName(((Object)componentInChildren).name)) && !PrivateArea.CheckAccess(((Component)componentInChildren).transform.position, 0f, true, false))
{
((Terminal)Chat.m_instance).AddString("You are not on the ward for this area");
}
else if (list.Contains(Utils.GetPrefabName(((Object)componentInChildren).name)))
{
componentInChildren.Interact((Humanoid)(object)Player.m_localPlayer, false, false);
}
}
}
}
public static class PluginConfig
{
public static ConfigEntry<KeyboardShortcut> ToggleEnabledShortcut;
public static ConfigEntry<bool> IsModEnabled { get; private set; }
public static void BindConfig(ConfigFile config)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
IsModEnabled = config.Bind<bool>("Global", "IsModEnabled", true, "Globally enable or disable this mod");
ToggleEnabledShortcut = config.Bind<KeyboardShortcut>("Movement", "Enable/Disable Shortcut", new KeyboardShortcut((KeyCode)114, (KeyCode[])(object)new KeyCode[1] { (KeyCode)303 }), "Keyboard Shortcut to toggle on/off Auto Picking");
}
}