using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FastFill")]
[assembly: AssemblyDescription("Valheim mod that changes the speed of 'fill up' actions like adding wood to a kiln")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("marcelbpunkt")]
[assembly: AssemblyProduct("FastFill")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e940d1ff-d815-4ec6-942e-a9c66e5e1547")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.2.0")]
namespace FastFill
{
[BepInPlugin("madmarty28.FastFill", "FastFill", "1.0.2")]
[BepInProcess("valheim.exe")]
public class FastFill : BaseUnityPlugin
{
public const string MOD_ID = "madmarty28.FastFill";
public const string MOD_NAME = "FastFill";
public const string MOD_VERSION = "1.0.2";
public const string VALHEIM_EXE = "valheim.exe";
public const string HOLD_REPEAT_INTERVAL_NAME = "holdRepeatInterval";
public const float ORIGINAL_HOLD_REPEAT_INTERVAL = 0.2f;
public const float DEFAULT_HOLD_REPEAT_INTERVAL = 0.05f;
private static readonly AcceptableValueRange<float> VALUE_RANGE = new AcceptableValueRange<float>(0f, 0.2f);
private const string CFG_FILE_NAME = "madmarty28.FastFill.cfg";
private static readonly string CFG_FILE_FULL_PATH;
public static ManualLogSource logger;
private readonly Harmony harmony = new Harmony("madmarty28.FastFill");
private static ConfigEntry<float> patchedHoldRepeatInterval;
public static float GetPatchedHoldRepeatInterval(Humanoid user)
{
return patchedHoldRepeatInterval.Value;
}
private static void displayChatMessage(string text)
{
if (Object.op_Implicit((Object)(object)Chat.instance))
{
Chat instance = Chat.instance;
FieldInfo? field = typeof(Chat).GetField("m_hideTimer", BindingFlags.Instance | BindingFlags.NonPublic);
((Terminal)instance).AddString(text);
field.SetValue(instance, 0f);
}
}
public static bool Prefix(string patchedClass, Humanoid character, bool hold, ref float ___m_holdRepeatInterval)
{
if (hold)
{
logger.LogDebug((object)($"{patchedClass}: Trying to set hold repeat interval from {___m_holdRepeatInterval}" + $" to {GetPatchedHoldRepeatInterval(character)} seconds."));
___m_holdRepeatInterval = GetPatchedHoldRepeatInterval(character);
}
return true;
}
private void Awake()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
ConfigDescription val = new ConfigDescription("Time in seconds after which another item is inserted while holding the 'Use' key\n(e.g. another piece of wood is inserted into a kiln). Must be between 0 and 0.2 (both inclusive)\nwhere 0 will only insert one single item no matter how long the player holds 'Use'.", (AcceptableValueBase)(object)VALUE_RANGE, (object[])null);
patchedHoldRepeatInterval = ((BaseUnityPlugin)this).Config.Bind<float>("General", "holdRepeatInterval", 0.05f, val);
SetupWatcher();
harmony.PatchAll();
}
private void OnDestroy()
{
((BaseUnityPlugin)this).Config.Save();
}
private void SetupWatcher()
{
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, "madmarty28.FastFill.cfg");
fileSystemWatcher.Changed += ReadConfigValues;
fileSystemWatcher.Created += ReadConfigValues;
fileSystemWatcher.Renamed += ReadConfigValues;
fileSystemWatcher.IncludeSubdirectories = true;
fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
fileSystemWatcher.EnableRaisingEvents = true;
}
private void ReadConfigValues(object sender, FileSystemEventArgs e)
{
if (!File.Exists(CFG_FILE_FULL_PATH))
{
return;
}
try
{
logger.LogDebug((object)"Attempting to reload configuration...");
((BaseUnityPlugin)this).Config.Reload();
}
catch
{
logger.LogError((object)"There was an issue loading madmarty28.FastFill.cfg");
}
}
static FastFill()
{
string configPath = Paths.ConfigPath;
char directorySeparatorChar = Path.DirectorySeparatorChar;
CFG_FILE_FULL_PATH = configPath + directorySeparatorChar + "madmarty28.FastFill.cfg";
logger = Logger.CreateLogSource("FastFill");
patchedHoldRepeatInterval = null;
}
}
[HarmonyPatch(typeof(Player), "Interact")]
internal class Player_Interact_Patch
{
private static bool Prefix(bool hold, ref float ___m_lastHoverInteractTime, Player __instance)
{
if (hold)
{
FastFill.logger.LogDebug((object)($"Player: Trying to set hold repeat interval from {0.2f} to " + $"{FastFill.GetPatchedHoldRepeatInterval((Humanoid)(object)__instance)} seconds."));
___m_lastHoverInteractTime -= 0.2f - FastFill.GetPatchedHoldRepeatInterval((Humanoid)(object)__instance);
}
return true;
}
}
[HarmonyPatch(typeof(Fireplace), "Interact")]
internal class Fireplace_Interact_Patch
{
private static bool Prefix(Humanoid user, bool hold, ref float ___m_holdRepeatInterval)
{
return FastFill.Prefix("Fireplace", user, hold, ref ___m_holdRepeatInterval);
}
}
[HarmonyPatch(typeof(Switch), "Interact")]
internal class Switch_Interact_Patch
{
private static bool Prefix(Humanoid character, bool hold, ref float ___m_holdRepeatInterval)
{
return FastFill.Prefix("Switch", character, hold, ref ___m_holdRepeatInterval);
}
}
[HarmonyPatch(typeof(Turret), "Interact")]
internal class Turret_interact_Patch
{
private static bool Prefix(Humanoid character, bool hold, ref float ___m_holdRepeatInterval)
{
return FastFill.Prefix("Turret", character, hold, ref ___m_holdRepeatInterval);
}
}
[HarmonyPatch(typeof(CookingStation), "Interact")]
internal class CookingStation_Interact_Patch
{
private static bool Prefix(Humanoid user, ref bool hold, ref CookingStation __instance)
{
return true;
}
}
}
namespace FastFill.Properties
{
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resources
{
private static ResourceManager resourceMan;
private static CultureInfo resourceCulture;
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static ResourceManager ResourceManager
{
get
{
if (resourceMan == null)
{
resourceMan = new ResourceManager("FastFill.Properties.Resources", typeof(Resources).Assembly);
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal Resources()
{
}
}
}