using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Reflection.Emit;
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 BepInEx.Logging;
using ComfyLib;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[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.10.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.10.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 ComfyLib
{
public static class ConfigFileExtensions
{
internal sealed class ConfigurationManagerAttributes
{
public Action<ConfigEntryBase> CustomDrawer;
public bool? Browsable;
public bool? HideDefaultButton;
public bool? HideSettingName;
public bool? IsAdvanced;
public int? Order;
public bool? ReadOnly;
}
private static readonly Dictionary<string, int> _sectionToSettingOrder = new Dictionary<string, int>();
private static int GetSettingOrder(string section)
{
if (!_sectionToSettingOrder.TryGetValue(section, out var value))
{
value = 0;
}
_sectionToSettingOrder[section] = value - 1;
return value;
}
public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false)
{
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Expected O, but got Unknown
return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, new object[1]
{
new ConfigurationManagerAttributes
{
Browsable = browsable,
CustomDrawer = null,
HideDefaultButton = hideDefaultButton,
HideSettingName = hideSettingName,
IsAdvanced = isAdvanced,
Order = GetSettingOrder(section),
ReadOnly = readOnly
}
}));
}
public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, Action<ConfigEntryBase> customDrawer = null, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false)
{
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Expected O, but got Unknown
return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1]
{
new ConfigurationManagerAttributes
{
Browsable = browsable,
CustomDrawer = customDrawer,
HideDefaultButton = hideDefaultButton,
HideSettingName = hideSettingName,
IsAdvanced = isAdvanced,
Order = GetSettingOrder(section),
ReadOnly = readOnly
}
}));
}
public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action settingChangedHandler)
{
configEntry.SettingChanged += delegate
{
settingChangedHandler();
};
}
public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<T> settingChangedHandler)
{
configEntry.SettingChanged += delegate(object _, EventArgs eventArgs)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
settingChangedHandler((T)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue);
};
}
public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<ConfigEntry<T>> settingChangedHandler)
{
configEntry.SettingChanged += delegate(object _, EventArgs eventArgs)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
settingChangedHandler((ConfigEntry<T>)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue);
};
}
}
}
namespace AddAllFuel
{
[BepInPlugin("bruceofthebow.valheim.AddAllFuel", "ComfyAddAllFuel", "1.10.0")]
public sealed class AddAllFuel : BaseUnityPlugin
{
public const string PluginGuid = "bruceofthebow.valheim.AddAllFuel";
public const string PluginName = "ComfyAddAllFuel";
public const string PluginVersion = "1.10.0";
private static ManualLogSource _logger;
private void Awake()
{
_logger = ((BaseUnityPlugin)this).Logger;
PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "bruceofthebow.valheim.AddAllFuel");
}
public static void LogInfo(object obj)
{
_logger.LogInfo((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}");
}
}
public static class FireplaceExtensions
{
public static string GetFuelItemName(this Fireplace fireplace)
{
if (!Object.op_Implicit((Object)(object)fireplace.m_fuelItem))
{
return string.Empty;
}
return fireplace.m_fuelItem.m_itemData.m_shared.m_name;
}
public static float GetFuel(this Fireplace fireplace)
{
ZNetView nview = fireplace.m_nview;
if (Object.op_Implicit((Object)(object)nview) && nview.IsValid())
{
return nview.m_zdo.GetFloat(ZDOVars.s_fuel, 0f);
}
return 0f;
}
}
public static class ShieldGeneratorExtensions
{
public static bool IsMatchingFuelItem(this ShieldGenerator shieldGenerator, string itemName)
{
foreach (ItemDrop fuelItem in shieldGenerator.m_fuelItems)
{
if (fuelItem.m_itemData.m_shared.m_name == itemName)
{
return true;
}
}
return false;
}
public static ItemData GetMatchingFuelItem(this ShieldGenerator shieldGenerator, Inventory inventory)
{
foreach (ItemDrop fuelItem in shieldGenerator.m_fuelItems)
{
ItemData item = inventory.GetItem(fuelItem.m_itemData.m_shared.m_name, -1, false);
if (item != null)
{
return item;
}
}
return null;
}
public static bool RepeatAddFuel(this ShieldGenerator shieldGenerator, Switch sw, Humanoid user, ItemData item, int count)
{
bool flag = false;
for (int i = 0; i < count; i++)
{
bool flag2 = shieldGenerator.OnAddFuel(sw, user, item);
if (!flag2)
{
return flag;
}
flag = flag || flag2;
}
return flag;
}
}
public static class SmelterManager
{
public static readonly HashSet<string> ExcludeCookableItems = new HashSet<string>();
public static void SetExcludeCookableItems(string[] itemNames)
{
ExcludeCookableItems.Clear();
ExcludeCookableItems.UnionWith(itemNames);
}
}
public static class CookingStationExtensions
{
public static string GetFuelItemName(this CookingStation cookingStation)
{
if (!Object.op_Implicit((Object)(object)cookingStation.m_fuelItem))
{
return string.Empty;
}
return cookingStation.m_fuelItem.m_itemData.m_shared.m_name;
}
public static bool TryGetFreeSlot(this CookingStation cookingStation, out int slotIndex)
{
ZDO zdo = cookingStation.m_nview.m_zdo;
for (int i = 0; i < cookingStation.m_slots.Length; i++)
{
if (!zdo.TryGetSlotString(i, out var value) || string.IsNullOrEmpty(value))
{
slotIndex = i;
return true;
}
}
slotIndex = 0;
return false;
}
public static int GetFreeSlotCount(this CookingStation cookingStation)
{
ZDO zdo = cookingStation.m_nview.m_zdo;
int num = 0;
for (int i = 0; i < cookingStation.m_slots.Length; i++)
{
if (!zdo.TryGetSlotString(i, out var value) || string.IsNullOrEmpty(value))
{
num++;
}
}
return num;
}
public static bool HaveDoneItemByStatus(this CookingStation cookingStation)
{
ZNetView nview = cookingStation.m_nview;
if (!nview.IsValid())
{
return false;
}
ZDO zdo = nview.m_zdo;
for (int i = 0; i < cookingStation.m_slots.Length; i++)
{
if (zdo.TryGetSlotStatusInt(i, out var value) && value != 0)
{
return true;
}
}
return false;
}
public static int GetDoneItemCount(this CookingStation cookingStation)
{
ZNetView nview = cookingStation.m_nview;
if (!nview.IsValid())
{
return 0;
}
ZDO zdo = nview.m_zdo;
int num = 0;
for (int i = 0; i < cookingStation.m_slots.Length; i++)
{
if (zdo.TryGetSlotStatusInt(i, out var value) && value != 0)
{
num++;
}
}
return num;
}
public static bool RepeatInteract(this CookingStation cookingStation, Humanoid user, int count)
{
bool flag = false;
for (int i = 0; i < count; i++)
{
bool flag2 = cookingStation.OnInteract(user);
if (!flag2)
{
return flag;
}
flag = flag || flag2;
}
return flag;
}
public static bool RepeatUseItem(this CookingStation cookingStation, Humanoid user, ItemData item, int count)
{
bool flag = false;
for (int i = 0; i < count; i++)
{
bool flag2 = cookingStation.OnUseItem(user, item);
if (!flag2)
{
return flag;
}
flag = flag || flag2;
}
return flag;
}
public static bool RepeatAddFuel(this CookingStation cookingStation, Switch sw, Humanoid user, ItemData item, int count)
{
bool flag = false;
for (int i = 0; i < count; i++)
{
bool flag2 = cookingStation.OnAddFuelSwitch(sw, user, item);
if (!flag2)
{
return flag;
}
flag = flag || flag2;
}
return flag;
}
}
public static class SmelterExtensions
{
public static string GetFuelItemName(this Smelter smelter)
{
if (!Object.op_Implicit((Object)(object)smelter.m_fuelItem))
{
return string.Empty;
}
return smelter.m_fuelItem.m_itemData.m_shared.m_name;
}
public static bool RepeatAddFuel(this Smelter smelter, Switch sw, Humanoid user, ItemData item, int count)
{
bool flag = false;
for (int i = 0; i < count; i++)
{
bool flag2 = smelter.OnAddFuel(sw, user, item);
if (!flag2)
{
return flag;
}
flag = flag || flag2;
}
return flag;
}
public static bool RepeatAddOre(this Smelter smelter, Switch sw, Humanoid user, ItemData item, int count)
{
bool flag = false;
for (int i = 0; i < count; i++)
{
bool flag2 = smelter.OnAddOre(sw, user, item);
if (!flag2)
{
return flag;
}
flag = flag || flag2;
}
return flag;
}
public static bool TryFindCookableItem(this Smelter smelter, Inventory inventory, out ItemData item)
{
foreach (ItemConversion item2 in smelter.m_conversion)
{
string name = item2.m_from.m_itemData.m_shared.m_name;
if (!SmelterManager.ExcludeCookableItems.Contains(name))
{
item = inventory.GetItem(name, -1, false);
if (item != null)
{
return true;
}
}
}
item = null;
return false;
}
}
public static class ZDOExtensions
{
public static readonly int[] SlotHashes = new int[10]
{
StringExtensionMethods.GetStableHashCode("slot0"),
StringExtensionMethods.GetStableHashCode("slot1"),
StringExtensionMethods.GetStableHashCode("slot2"),
StringExtensionMethods.GetStableHashCode("slot3"),
StringExtensionMethods.GetStableHashCode("slot4"),
StringExtensionMethods.GetStableHashCode("slot5"),
StringExtensionMethods.GetStableHashCode("slot6"),
StringExtensionMethods.GetStableHashCode("slot7"),
StringExtensionMethods.GetStableHashCode("slot8"),
StringExtensionMethods.GetStableHashCode("slot9")
};
public static readonly int[] SlotStatusHashes = new int[10]
{
StringExtensionMethods.GetStableHashCode("slotstatus0"),
StringExtensionMethods.GetStableHashCode("slotstatus1"),
StringExtensionMethods.GetStableHashCode("slotstatus2"),
StringExtensionMethods.GetStableHashCode("slotstatus3"),
StringExtensionMethods.GetStableHashCode("slotstatus4"),
StringExtensionMethods.GetStableHashCode("slotstatus5"),
StringExtensionMethods.GetStableHashCode("slotstatus6"),
StringExtensionMethods.GetStableHashCode("slotstatus7"),
StringExtensionMethods.GetStableHashCode("slotstatus8"),
StringExtensionMethods.GetStableHashCode("slotstatus9")
};
public static bool TryGetSlotString(this ZDO zdo, int slotIndex, out string value)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
if (ZDOExtraData.s_strings.TryGetValue(zdo.m_uid, out var value2) && value2.TryGetValue(SlotHashes[slotIndex], ref value))
{
return true;
}
value = null;
return false;
}
public static bool TryGetSlotFloat(this ZDO zdo, int slotIndex, out float value)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
if (ZDOExtraData.s_floats.TryGetValue(zdo.m_uid, out var value2) && value2.TryGetValue(SlotHashes[slotIndex], ref value))
{
return true;
}
value = 0f;
return false;
}
public static bool TryGetSlotStatusInt(this ZDO zdo, int slotIndex, out int value)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
if (ZDOExtraData.s_ints.TryGetValue(zdo.m_uid, out var value2) && value2.TryGetValue(SlotStatusHashes[slotIndex], ref value))
{
return true;
}
value = 0;
return false;
}
}
[HarmonyPatch(typeof(CookingStation))]
internal static class CookingStationPatch
{
[HarmonyPrefix]
[HarmonyPatch("GetFreeSlot")]
private static bool GetFreeSlotPrefix(CookingStation __instance, ref int __result)
{
if (PluginConfig.IsModEnabled.Value)
{
__result = (__instance.TryGetFreeSlot(out var slotIndex) ? slotIndex : (-1));
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("HaveDoneItem")]
private static bool HaveDoneItemPrefix(CookingStation __instance, ref bool __result)
{
if (PluginConfig.IsModEnabled.Value)
{
__result = __instance.HaveDoneItemByStatus();
return false;
}
return true;
}
[HarmonyTranspiler]
[HarmonyPatch("Awake")]
private static IEnumerable<CodeInstruction> AwakeTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
//IL_0002: 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: Expected O, but got Unknown
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Expected O, but got Unknown
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Expected O, but got Unknown
return new CodeMatcher(instructions, generator).Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[3]
{
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldftn, (object)AccessTools.Method(typeof(CookingStation), "OnAddFuelSwitch", (Type[])null, (Type[])null), (string)null),
new CodeMatch((OpCode?)OpCodes.Newobj, (object)null, (string)null)
}).ThrowIfInvalid("Could not patch CookingStation.Awake()! (on-add-fuel-switch)")
.Advance(3)
.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(CookingStationPatch), "OnAddFuelSwitchCallbackDelegate", (Type[])null, (Type[])null))
})
.InstructionEnumeration();
}
private static Callback OnAddFuelSwitchCallbackDelegate(Callback onAddFuelSwitchCallback, CookingStation smelter)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
if (!PluginConfig.IsModEnabled.Value)
{
return onAddFuelSwitchCallback;
}
return new Callback(OnRepeatAddFuelSwitch);
}
public static bool OnRepeatAddFuelSwitch(this CookingStation cookingStation, Switch sw, Humanoid user, ItemData item)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
if (!PluginConfig.IsModEnabled.Value || !ZInput.GetKey(PluginConfig.AddAllModifier.Value, true))
{
return cookingStation.OnAddFuelSwitch(sw, user, item);
}
string fuelItemName = cookingStation.GetFuelItemName();
if (item == null)
{
item = user.GetInventory().GetItem(fuelItemName, -1, false);
}
int count = 0;
if (item != null && item.m_shared.m_name == fuelItemName)
{
count = Mathf.Max(Mathf.Min(Mathf.RoundToInt((float)cookingStation.m_maxFuel - cookingStation.GetFuel()), item.m_stack), 0);
}
return cookingStation.RepeatAddFuel(sw, user, item, count);
}
[HarmonyPrefix]
[HarmonyPatch("OnAddFoodSwitch")]
private static bool OnAddFoodSwitchPrefix(CookingStation __instance, Humanoid user, ItemData item, ref bool __result)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
if (PluginConfig.IsModEnabled.Value && ZInput.GetKey(PluginConfig.AddAllModifier.Value, true))
{
__result = ((item == null) ? OnRepeatInteract(__instance, user) : OnRepeatUseItem(__instance, user, item));
return false;
}
return true;
}
public static bool OnRepeatUseItem(CookingStation cookingStation, Humanoid user, ItemData item)
{
int freeSlotCount = cookingStation.GetFreeSlotCount();
return cookingStation.RepeatUseItem(user, item, Mathf.Min(freeSlotCount, item.m_stack));
}
[HarmonyPrefix]
[HarmonyPatch("Interact")]
private static bool InteractPrefix(CookingStation __instance, Humanoid user, bool hold, ref bool __result)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
if (!hold && (Object)(object)__instance.m_addFoodSwitch == (Object)null && PluginConfig.IsModEnabled.Value && ZInput.GetKey(PluginConfig.AddAllModifier.Value, true))
{
__result = OnRepeatInteract(__instance, user);
return false;
}
return true;
}
public static bool OnRepeatInteract(CookingStation cookingStation, Humanoid user)
{
int doneItemCount = cookingStation.GetDoneItemCount();
if (doneItemCount > 0)
{
return cookingStation.RepeatInteract(user, doneItemCount);
}
int freeSlotCount = cookingStation.GetFreeSlotCount();
return cookingStation.RepeatInteract(user, freeSlotCount);
}
}
[HarmonyPatch(typeof(Fireplace))]
internal static class FireplacePatch
{
[HarmonyTranspiler]
[HarmonyPatch("Interact")]
private static IEnumerable<CodeInstruction> InteractTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
//IL_0002: 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_0027: Expected O, but got Unknown
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Expected O, but got Unknown
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Expected O, but got Unknown
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Expected O, but got Unknown
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Expected O, but got Unknown
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Expected O, but got Unknown
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Expected O, but got Unknown
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Expected O, but got Unknown
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Expected O, but got Unknown
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Expected O, but got Unknown
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Expected O, but got Unknown
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Expected O, but got Unknown
//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Expected O, but got Unknown
//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Expected O, but got Unknown
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Expected O, but got Unknown
//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0200: Expected O, but got Unknown
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Expected O, but got Unknown
Label label = default(Label);
return new CodeMatcher(instructions, generator).Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[10]
{
new CodeMatch((OpCode?)OpCodes.Ldloc_1, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Fireplace), "m_fuelItem"), (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(ItemDrop), "m_itemData"), (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(ItemData), "m_shared"), (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(SharedData), "m_name"), (string)null),
new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldc_I4_M1, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(Inventory), "RemoveItem", new Type[4]
{
typeof(string),
typeof(int),
typeof(int),
typeof(bool)
}, (Type[])null), (string)null)
}).ThrowIfInvalid("Could not patch Fireplace.Interact()! (remove-item)")
.CreateLabel(ref label)
.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[7]
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Ldarg_1, (object)null),
new CodeInstruction(OpCodes.Ldnull, (object)null),
new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(FireplacePatch), "AddFuelDelegate", (Type[])null, (Type[])null)),
new CodeInstruction(OpCodes.Brfalse, (object)label),
new CodeInstruction(OpCodes.Ldc_I4_1, (object)null),
new CodeInstruction(OpCodes.Ret, (object)null)
})
.InstructionEnumeration();
}
[HarmonyTranspiler]
[HarmonyPatch("UseItem")]
private static IEnumerable<CodeInstruction> UseItemTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
//IL_0002: 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: Expected O, but got Unknown
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Expected O, but got Unknown
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Expected O, but got Unknown
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Expected O, but got Unknown
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Expected O, but got Unknown
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Expected O, but got Unknown
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Expected O, but got Unknown
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Expected O, but got Unknown
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Expected O, but got Unknown
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Expected O, but got Unknown
Label label = default(Label);
return new CodeMatcher(instructions, generator).Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((OpCode?)OpCodes.Ldloc_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldarg_2, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(Inventory), "RemoveItem", new Type[2]
{
typeof(ItemData),
typeof(int)
}, (Type[])null), (string)null)
}).ThrowIfInvalid("Could not patch Fireplace.UseItem()! (remove-item)")
.CreateLabel(ref label)
.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[7]
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Ldarg_1, (object)null),
new CodeInstruction(OpCodes.Ldarg_2, (object)null),
new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(FireplacePatch), "AddFuelDelegate", (Type[])null, (Type[])null)),
new CodeInstruction(OpCodes.Brfalse, (object)label),
new CodeInstruction(OpCodes.Ldc_I4_1, (object)null),
new CodeInstruction(OpCodes.Ret, (object)null)
})
.InstructionEnumeration();
}
private static bool AddFuelDelegate(Fireplace fireplace, Humanoid user, ItemData item)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
if (PluginConfig.IsModEnabled.Value && ZInput.GetKey(PluginConfig.AddAllModifier.Value, true))
{
string fuelItemName = fireplace.GetFuelItemName();
if (item == null)
{
item = user.GetInventory().GetItem(fuelItemName, -1, false);
}
if (item == null || item.m_shared.m_name != fuelItemName)
{
return false;
}
int num = Mathf.CeilToInt(fireplace.m_maxFuel - fireplace.GetFuel());
num = Mathf.Max(Mathf.Min(num, item.m_stack), 0);
if (num <= 0)
{
return false;
}
if (!user.GetInventory().RemoveItem(item, num))
{
return false;
}
fireplace.AddFuel((float)num);
return true;
}
return false;
}
}
[HarmonyPatch(typeof(ShieldGenerator))]
internal static class ShieldGeneratorPatch
{
[HarmonyTranspiler]
[HarmonyPatch("Start")]
private static IEnumerable<CodeInstruction> StartTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
//IL_0002: 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: Expected O, but got Unknown
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Expected O, but got Unknown
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Expected O, but got Unknown
return new CodeMatcher(instructions, generator).Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[3]
{
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldftn, (object)AccessTools.Method(typeof(ShieldGenerator), "OnAddFuel", (Type[])null, (Type[])null), (string)null),
new CodeMatch((OpCode?)OpCodes.Newobj, (object)null, (string)null)
}).ThrowIfInvalid("Could not patch ShieldGenerator.Awake()! (on-add-fuel)")
.Advance(3)
.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ShieldGeneratorPatch), "OnAddFuelCallbackDelegate", (Type[])null, (Type[])null))
})
.InstructionEnumeration();
}
private static Callback OnAddFuelCallbackDelegate(Callback onAddFuelCallback, ShieldGenerator shieldGenerator)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
if (!PluginConfig.IsModEnabled.Value)
{
return onAddFuelCallback;
}
return new Callback(OnRepeatAddFuel);
}
public static bool OnRepeatAddFuel(this ShieldGenerator shieldGenerator, Switch sw, Humanoid user, ItemData item)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
if (!PluginConfig.IsModEnabled.Value || !ZInput.GetKey(PluginConfig.AddAllModifier.Value, true) || (item != null && !shieldGenerator.IsMatchingFuelItem(item.m_shared.m_name)))
{
return shieldGenerator.OnAddFuel(sw, user, item);
}
int count = 0;
if (item == null)
{
item = shieldGenerator.GetMatchingFuelItem(user.GetInventory());
}
if (item != null)
{
count = Mathf.Max(Mathf.Min(Mathf.CeilToInt((float)shieldGenerator.m_maxFuel - shieldGenerator.GetFuel()), item.m_stack), 0);
}
return shieldGenerator.RepeatAddFuel(sw, user, item, count);
}
}
[HarmonyPatch(typeof(Smelter))]
internal static class SmelterPatch
{
[HarmonyTranspiler]
[HarmonyPatch("Awake")]
private static IEnumerable<CodeInstruction> AwakeTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
//IL_0002: 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: Expected O, but got Unknown
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Expected O, but got Unknown
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Expected O, but got Unknown
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Expected O, but got Unknown
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Expected O, but got Unknown
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Expected O, but got Unknown
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Expected O, but got Unknown
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Expected O, but got Unknown
return new CodeMatcher(instructions, generator).Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[3]
{
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldftn, (object)AccessTools.Method(typeof(Smelter), "OnAddOre", (Type[])null, (Type[])null), (string)null),
new CodeMatch((OpCode?)OpCodes.Newobj, (object)null, (string)null)
}).ThrowIfInvalid("Could not patch Smelter.Awake()! (on-add-ore)")
.Advance(3)
.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SmelterPatch), "OnAddOreCallbackDelegate", (Type[])null, (Type[])null))
})
.MatchStartForward((CodeMatch[])(object)new CodeMatch[3]
{
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldftn, (object)AccessTools.Method(typeof(Smelter), "OnAddFuel", (Type[])null, (Type[])null), (string)null),
new CodeMatch((OpCode?)OpCodes.Newobj, (object)null, (string)null)
})
.ThrowIfInvalid("Could not patch Smelter.Awake()! (on-add-fuel)")
.Advance(3)
.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SmelterPatch), "OnAddFuelCallbackDelegate", (Type[])null, (Type[])null))
})
.InstructionEnumeration();
}
private static Callback OnAddOreCallbackDelegate(Callback onAddOreCallback, Smelter smelter)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
if (!PluginConfig.IsModEnabled.Value)
{
return onAddOreCallback;
}
return new Callback(OnRepeatAddOre);
}
public static bool OnRepeatAddOre(this Smelter smelter, Switch sw, Humanoid user, ItemData item)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
if (!PluginConfig.IsModEnabled.Value || !ZInput.GetKey(PluginConfig.AddAllModifier.Value, true))
{
return smelter.OnAddOre(sw, user, item);
}
int num = smelter.m_maxOre - smelter.GetQueueSize();
if (item == null)
{
item = smelter.FindCookableItem(user.GetInventory());
}
if (item != null)
{
num = Mathf.Max(Mathf.Min(num, item.m_stack), 0);
}
return smelter.RepeatAddOre(sw, user, item, num);
}
private static Callback OnAddFuelCallbackDelegate(Callback onAddFuelCallback, Smelter smelter)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
if (!PluginConfig.IsModEnabled.Value)
{
return onAddFuelCallback;
}
return new Callback(OnRepeatAddFuel);
}
public static bool OnRepeatAddFuel(this Smelter smelter, Switch sw, Humanoid user, ItemData item)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
if (!PluginConfig.IsModEnabled.Value || !ZInput.GetKey(PluginConfig.AddAllModifier.Value, true))
{
return smelter.OnAddFuel(sw, user, item);
}
string fuelItemName = smelter.GetFuelItemName();
if (item == null)
{
item = user.GetInventory().GetItem(fuelItemName, -1, false);
}
int count = 0;
if (item != null && item.m_shared.m_name == fuelItemName)
{
count = Mathf.Max(Mathf.Min(Mathf.RoundToInt((float)smelter.m_maxFuel - smelter.GetFuel()), item.m_stack), 0);
}
return smelter.RepeatAddFuel(sw, user, item, count);
}
[HarmonyPrefix]
[HarmonyPatch("FindCookableItem")]
private static bool FindCookableItemPrefix(Smelter __instance, Inventory inventory, ref ItemData __result)
{
if (PluginConfig.IsModEnabled.Value && SmelterManager.ExcludeCookableItems.Count > 0)
{
__instance.TryFindCookableItem(inventory, out __result);
return false;
}
return true;
}
}
public static class PluginConfig
{
public static readonly char[] CommaSplitter = new char[1] { ',' };
public static ConfigEntry<bool> IsModEnabled { get; private set; }
public static ConfigEntry<KeyCode> AddAllModifier { get; private set; }
public static ConfigEntry<bool> ExcludeFinewood { get; private set; }
public static ConfigEntry<string> SmelterCookableItemsToExclude { get; private set; }
public static void BindConfig(ConfigFile config)
{
IsModEnabled = config.BindInOrder("_Global", "isModEnabled", defaultValue: true, "Globally enable or disable this mod.");
AddAllModifier = config.BindInOrder<KeyCode>("ModifierKey", "ModifierKey", (KeyCode)304, "Modifier key to hold for using add all feature.");
SmelterCookableItemsToExclude = config.BindInOrder("Smelter", "cookableItemsToExclude", "$item_finewood", "Comma-separated list of item-names that Smelter stations will not use as cookable items.");
SmelterCookableItemsToExclude.OnSettingChanged<string>(OnSmelterCookableItemsToExcludeChanged);
OnSmelterCookableItemsToExcludeChanged(SmelterCookableItemsToExclude.Value);
}
private static void OnSmelterCookableItemsToExcludeChanged(string values)
{
SmelterManager.SetExcludeCookableItems(values.Split(CommaSplitter, StringSplitOptions.RemoveEmptyEntries));
}
}
}