using System;
using System.Diagnostics;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BedUnclaimer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BedUnclaimer")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1f9c577e-fa37-49af-b9e4-89c1c1995035")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace BedUnclaimer;
[BepInPlugin("org.ssmvc.bedunclaimer", "BedUnclaimer", "1.0.0")]
[BepInProcess("valheim.exe")]
public class BedUnclaimer : BaseUnityPlugin
{
[HarmonyPatch(typeof(Bed))]
private static class BedPatch
{
[HarmonyPostfix]
[HarmonyPatch("GetHoverText")]
public static void GetHoverTextPostfix(Bed __instance, ref string __result)
{
if (Enabled.Value && __instance.GetOwner() != 0L)
{
if (__instance.IsMine())
{
__result += Localization.instance.Localize("\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] UnClaim Bed");
}
else if (Player.m_localPlayer.GetPlayerID() == ((Component)__instance).GetComponent<Piece>().GetCreator() || Player.m_debugMode)
{
__result += Localization.instance.Localize("\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] UnClaim " + __instance.GetOwnerName() + "'s Bed");
}
}
}
[HarmonyPrefix]
[HarmonyPatch("Interact")]
public static bool InteractPrefix(Bed __instance, Humanoid human, bool repeat, bool alt)
{
if (!Enabled.Value || repeat || !alt || __instance.GetOwner() == 0L)
{
return true;
}
if (__instance.IsMine())
{
((Character)human).Message((MessageType)2, "UnClaimed bed.", 0, (Sprite)null);
__instance.SetOwner(0L, "");
}
else if (Player.m_localPlayer.GetPlayerID() == ((Component)__instance).GetComponent<Piece>().GetCreator() || Player.m_debugMode)
{
Console.WriteLine("UnClaimed " + __instance.GetOwnerName() + "'s bed.");
((Character)human).Message((MessageType)2, "UnClaimed " + __instance.GetOwnerName() + "'s bed.", 0, (Sprite)null);
__instance.SetOwner(0L, "");
}
return false;
}
}
public const string PluginGUID = "org.ssmvc.bedunclaimer";
public const string PluginName = "BedUnclaimer";
public const string PluginVersion = "1.0.0";
private static Harmony _harmony;
public static ConfigEntry<bool> Enabled { get; set; }
public void Awake()
{
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "org.ssmvc.bedunclaimer");
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("_Global", "isModEnabled", true, "Globally enable or disable this mod.");
}
public void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}