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 AddAllFuel.Extensions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
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("AddAllFuel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AddAllFuel")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("52be6d2b-daf1-446a-88a5-1c2e02280b51")]
[assembly: AssemblyFileVersion("1.9.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.9.0.0")]
[module: UnverifiableCode]
namespace AddAllFuel
{
[BepInPlugin("bruceofthebow.valheim.AddAllFuel", "ComfyAddAllFuel", "1.9.0")]
public class AddAllFuel : BaseUnityPlugin
{
public const string PluginGuid = "bruceofthebow.valheim.AddAllFuel";
public const string PluginName = "ComfyAddAllFuel";
public const string PluginVersion = "1.9.0";
private static readonly bool _debug = true;
private static readonly List<string> ExcludeNames = new List<string> { "$item_finewood" };
private static ManualLogSource _logger;
private Harmony _harmony;
private void Awake()
{
PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
_logger = ((BaseUnityPlugin)this).Logger;
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "bruceofthebow.valheim.AddAllFuel");
}
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
public static ItemData FindCookableItem(Smelter __instance, Inventory inventory)
{
IEnumerable<string> enumerable = null;
enumerable = ((!PluginConfig.ExcludeFinewood.Value) ? __instance.m_conversion.Select((ItemConversion n) => n.m_from.m_itemData.m_shared.m_name) : (from n in __instance.m_conversion
where !ExcludeNames.Contains(n.m_from.m_itemData.m_shared.m_name)
select n.m_from.m_itemData.m_shared.m_name));
if (enumerable == null)
{
return null;
}
foreach (string item in enumerable)
{
ItemData val = ((inventory != null) ? inventory.GetItem(item, -1, false) : null);
if (val != null)
{
return val;
}
}
return null;
}
}
public class PluginConfig
{
public static ConfigEntry<bool> IsModEnabled { get; private set; }
public static ConfigEntry<bool> ExcludeFinewood { get; private set; }
public static ConfigEntry<KeyCode> AddAllModifier { get; private set; }
public static void BindConfig(ConfigFile config)
{
IsModEnabled = config.Bind<bool>("Global", "isModEnabled", true, "Globally enable or disable this mod.");
ExcludeFinewood = config.Bind<bool>("ExcludeFinewood", "excludeFinewood", true, "Filter finewood out of items to add to kilns");
AddAllModifier = config.Bind<KeyCode>("ModifierKey", "ModifierKey", (KeyCode)304, "Modifier key to hold for using add all feature.");
}
}
}
namespace AddAllFuel.Patches
{
[HarmonyPatch(typeof(CookingStation))]
internal static class CookingStationPatch
{
[HarmonyPrefix]
[HarmonyPatch("OnAddFuelSwitch")]
public static bool OnAddFuelSwitchPrefix(CookingStation __instance, ref bool __result, Switch sw, Humanoid user, ItemData item)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
if (!PluginConfig.IsModEnabled.Value || !Input.GetKey(PluginConfig.AddAllModifier.Value))
{
return true;
}
__result = false;
if (__instance.GetFuel() > (float)(__instance.m_maxFuel - 1))
{
((Character)user).Message((MessageType)2, "$msg_itsfull", 0, (Sprite)null);
return false;
}
item = user.GetInventory().GetItem(__instance.GetFuelName(), -1, false);
if (item == null)
{
((Character)user).Message((MessageType)2, "$msg_donthaveany " + __instance.GetFuelName(), 0, (Sprite)null);
return false;
}
int val = (int)((float)__instance.m_maxFuel - __instance.GetFuel());
int num = Math.Min(item.m_stack, val);
user.GetInventory().RemoveItem(item, num);
for (int i = 0; i < num; i++)
{
__instance.m_nview.InvokeRPC("RPC_AddFuel", Array.Empty<object>());
}
((Character)user).Message((MessageType)2, $"$msg_added {num} {__instance.GetFuelName()}", 0, (Sprite)null);
__result = true;
return false;
}
[HarmonyPrefix]
[HarmonyPatch("CookItem")]
public static bool OnAddFoodSwitchPrefix(CookingStation __instance, ref bool __result, Humanoid user, ItemData item)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
if (!PluginConfig.IsModEnabled.Value || !Input.GetKey(PluginConfig.AddAllModifier.Value))
{
return true;
}
__result = false;
if (!__instance.m_nview.HasOwner())
{
__instance.m_nview.ClaimOwnership();
}
foreach (ItemMessage incompatibleItem in __instance.m_incompatibleItems)
{
if (incompatibleItem.m_item.m_itemData.m_shared.m_name == item.m_shared.m_name)
{
((Character)user).Message((MessageType)2, incompatibleItem.m_message + " " + incompatibleItem.m_item.m_itemData.m_shared.m_name, 0, (Sprite)null);
return true;
}
}
if (!__instance.IsItemAllowed(item))
{
return false;
}
int num = __instance.GetFreeSlots();
if (item.m_stack < num)
{
num = item.m_stack;
}
user.GetInventory().RemoveItem(item, num);
for (int i = 0; i < num; i++)
{
__instance.m_nview.InvokeRPC("RPC_AddItem", new object[1] { ((Object)item.m_dropPrefab).name });
}
__result = true;
return false;
}
[HarmonyPrefix]
[HarmonyPatch("OnInteract")]
public static bool OnInteractPrefix(CookingStation __instance, Humanoid user)
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)__instance) || !Object.op_Implicit((Object)(object)user) || __instance.GetFreeSlots() > 0)
{
return true;
}
int doneItemCount = __instance.GetDoneItemCount();
if (doneItemCount == 0)
{
return true;
}
for (int i = 0; i < doneItemCount; i++)
{
__instance.m_nview.InvokeRPC("RPC_RemoveDoneItem", new object[1] { ((Component)user).transform.position });
}
return false;
}
}
[HarmonyPatch(typeof(Fireplace))]
public static class FireplacePatch
{
[HarmonyPrefix]
[HarmonyPatch("Interact")]
public static bool FireplaceInteractPrefix(ref Fireplace __instance, Humanoid user, bool hold, bool alt, ref bool __result)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
if (!PluginConfig.IsModEnabled.Value || !Input.GetKey(PluginConfig.AddAllModifier.Value))
{
return true;
}
__result = false;
if (hold)
{
return false;
}
if (!__instance.m_nview.HasOwner())
{
__instance.m_nview.ClaimOwnership();
}
string name = __instance.m_fuelItem.m_itemData.m_shared.m_name;
float num = Mathf.CeilToInt(__instance.m_nview.GetZDO().GetFloat("fuel", 0f));
if (num > __instance.m_maxFuel - 1f)
{
((Character)user).Message((MessageType)2, Localization.instance.Localize("$msg_cantaddmore", new string[1] { name }), 0, (Sprite)null);
return false;
}
Inventory inventory = user.GetInventory();
ItemData val = ((inventory != null) ? inventory.GetItem(name, -1, false) : null);
if (val == null)
{
((Character)user).Message((MessageType)2, "$msg_outof " + name, 0, (Sprite)null);
return false;
}
int val2 = (int)(__instance.m_maxFuel - num);
int num2 = Math.Min(val.m_stack, val2);
user.GetInventory().RemoveItem(val, num2);
__instance.m_nview.InvokeRPC("RPC_AddFuelAmount", new object[1] { (float)num2 });
((Character)user).Message((MessageType)2, Localization.instance.Localize("$msg_fireadding", new string[1] { name }), 0, (Sprite)null);
__result = true;
return false;
}
}
[HarmonyPatch(typeof(Smelter))]
public static class SmelterPatch
{
[HarmonyPrefix]
[HarmonyPatch("OnAddOre")]
public static bool SmelterOnAddOrePrefix(ref Smelter __instance, ref Switch sw, ref Humanoid user, ItemData item, ref bool __result)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
if (!PluginConfig.IsModEnabled.Value || !Input.GetKey(PluginConfig.AddAllModifier.Value))
{
return true;
}
__result = false;
if (__instance.GetQueueSize() >= __instance.m_maxOre)
{
((Character)user).Message((MessageType)2, "$msg_itsfull", 0, (Sprite)null);
return false;
}
if (item == null)
{
item = AddAllFuel.FindCookableItem(__instance, user.GetInventory());
}
if (item == null)
{
((Character)user).Message((MessageType)2, "$msg_noprocessableitems", 0, (Sprite)null);
return false;
}
if (!__instance.IsItemAllowed(item))
{
((Character)user).Message((MessageType)2, "$msg_wontwork", 0, (Sprite)null);
return false;
}
int val = __instance.m_maxOre - __instance.GetQueueSize();
int num = Math.Min(item.m_stack, val);
user.GetInventory().RemoveItem(item, num);
for (int i = 0; i < num; i++)
{
__instance.m_nview.InvokeRPC("RPC_AddOre", new object[1] { ((Object)item.m_dropPrefab).name });
}
((Character)user).Message((MessageType)2, $"$msg_added {num} {item.m_shared.m_name}", 0, (Sprite)null);
__result = true;
return false;
}
[HarmonyPrefix]
[HarmonyPatch("OnAddFuel")]
public static bool Prefix(ref Smelter __instance, ref bool __result, Switch sw, Humanoid user, ItemData item)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
if (!PluginConfig.IsModEnabled.Value || !Input.GetKey(PluginConfig.AddAllModifier.Value))
{
return true;
}
__result = false;
if (__instance.GetFuel() > (float)(__instance.m_maxFuel - 1))
{
((Character)user).Message((MessageType)2, "$msg_itsfull", 0, (Sprite)null);
return false;
}
item = user.GetInventory().GetItem(__instance.GetFuelName(), -1, false);
if (item == null)
{
((Character)user).Message((MessageType)2, "$msg_donthaveany " + __instance.GetFuelName(), 0, (Sprite)null);
return false;
}
int val = (int)((float)__instance.m_maxFuel - __instance.GetFuel());
int num = Math.Min(item.m_stack, val);
user.GetInventory().RemoveItem(item, num);
for (int i = 0; i < num; i++)
{
__instance.m_nview.InvokeRPC("RPC_AddFuel", Array.Empty<object>());
}
((Character)user).Message((MessageType)2, $"$msg_added {num} {__instance.GetFuelName()}", 0, (Sprite)null);
__result = true;
return false;
}
}
}
namespace AddAllFuel.Extensions
{
public static class CookingStationExtensions
{
public static string GetFuelName(this CookingStation cookingStation)
{
if ((Object)(object)cookingStation.m_fuelItem == (Object)null)
{
return null;
}
return cookingStation.m_fuelItem.m_itemData.m_shared.m_name;
}
public static int GetFreeSlots(this CookingStation cookingStation)
{
int num = 0;
for (int i = 0; i < cookingStation.m_slots.Length; i++)
{
if (!(cookingStation.m_nview.GetZDO().GetString("slot" + i, "") != ""))
{
num++;
}
}
return num;
}
public static int GetDoneItemCount(this CookingStation cookingStation)
{
int num = 0;
string text = default(string);
float num2 = default(float);
Status val = default(Status);
for (int i = 0; i < cookingStation.m_slots.Length; i++)
{
cookingStation.GetSlot(i, ref text, ref num2, ref val);
if (cookingStation.IsItemDone(text))
{
num++;
}
}
return num;
}
}
public static class SmelterExtensions
{
public static string GetFuelName(this Smelter smelter)
{
if ((Object)(object)smelter.m_fuelItem == (Object)null)
{
return null;
}
return smelter.m_fuelItem.m_itemData.m_shared.m_name;
}
}
}