using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using SailwindModdingHelper;
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("FurnitureFix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FurnitureFix")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("de674450-efd4-40ef-bb4a-45bbcc4dcc5d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FurnitureFix;
internal class FurniturePatches
{
[HarmonyPatch(typeof(PlayerCrouching), "Update")]
private static class PlayerCrouchingPatch
{
public static void Postfix(bool ___crouching)
{
playerCrouching = ___crouching;
}
}
[HarmonyPatch(typeof(GoPointerButton), "Look")]
private static class ItemLookPatch
{
public static bool Prefix(GoPointerButton __instance, GoPointer lookingPointer)
{
PickupableItem val = (PickupableItem)(object)((__instance is PickupableItem) ? __instance : null);
if (val == null)
{
return true;
}
return ShouldShowHighlight(val, lookingPointer);
}
}
[HarmonyPatch(typeof(GoPointer), "PickUpItem")]
private static class BedPickupPatch
{
public static bool Prefix(PickupableItem item)
{
if (item is ShipItemBed && !CanPickUp(item))
{
((GoPointerButton)item).OnAltActivate();
return false;
}
return CanPickUp(item);
}
}
[HarmonyPatch(typeof(ShipItem))]
private static class ShipItemPatches
{
[HarmonyPatch("Awake")]
[HarmonyPrefix]
public static void Prefix(ShipItem __instance, bool ___big)
{
if (!___big)
{
((Component)__instance).gameObject.AddComponent<ShipItemInventory>();
}
}
[HarmonyPatch("OnEnterInventory")]
[HarmonyPrefix]
public static void OnEnterInventory(ShipItem __instance)
{
((Component)__instance).GetComponent<ShipItemInventory>().inInventory = true;
Main.logSource.LogInfo((object)"enter inventory");
}
[HarmonyPatch("OnLeaveInventory")]
[HarmonyPrefix]
public static void OnLeaveInventory(ShipItem __instance)
{
((Component)__instance).GetComponent<ShipItemInventory>().inInventory = false;
}
}
private static readonly string[] furnitureNames = new string[9] { "table", "chair", "shelf", "shelves", "stove", "lamp hook", "lamp hanger", "painting", "bed" };
private static bool playerCrouching;
public static bool ShouldShowHighlight(PickupableItem target, GoPointer lookingPointer)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Expected O, but got Unknown
if (CanPickUp(target))
{
return true;
}
ShipItemStove val = (ShipItemStove)(object)((target is ShipItemStove) ? target : null);
if (val != null && Object.op_Implicit((Object)(object)((Component)lookingPointer.GetHeldItem()).GetComponent<CookableFood>()) && Object.op_Implicit((Object)(StoveCookTrigger)Extensions.InvokePrivateMethod((object)val, "GetFreeSlot", Array.Empty<object>())))
{
return true;
}
if (target is ShipItemBed)
{
return true;
}
ShipItemLampHook val2 = (ShipItemLampHook)(object)((target is ShipItemLampHook) ? target : null);
if (val2 != null && (Object)(object)lookingPointer.GetHeldItem() != (Object)null && (Object)(object)((Component)lookingPointer.GetHeldItem()).GetComponent<ShipItemHangable>() != (Object)null && !Extensions.GetPrivateField<bool>((object)val2, "occupied"))
{
return true;
}
return false;
}
public static bool CanPickUp(PickupableItem target)
{
if (furnitureNames.Any(((Object)target).name.Contains))
{
if (!Object.op_Implicit((Object)(object)GameState.currentBoat))
{
return true;
}
if (Main.instance.crouchPickup.Value && playerCrouching)
{
return true;
}
if (GameInput.GetKey((InputName)17))
{
return true;
}
if (target is ShipItem && (Object)(object)((Component)target).GetComponent<ShipItemInventory>() != (Object)null && ((Component)target).GetComponent<ShipItemInventory>().inInventory)
{
return true;
}
return false;
}
return true;
}
}
[BepInPlugin("com.nandbrew.furniturefix", "Furniture Fix", "1.0.4")]
[BepInDependency("com.app24.sailwindmoddinghelper", "2.0.0")]
internal class Main : BaseUnityPlugin
{
public const string GUID = "com.nandbrew.furniturefix";
public const string NAME = "Furniture Fix";
public const string VERSION = "1.0.4";
internal static Main instance;
internal static ManualLogSource logSource;
internal ConfigEntry<bool> crouchPickup;
internal ConfigEntry<KeyCode> pickupModifier;
private void Awake()
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
instance = this;
logSource = ((BaseUnityPlugin)this).Logger;
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.nandbrew.furniturefix");
crouchPickup = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "Allow crouch pickup", true, (ConfigDescription)null);
pickupModifier = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Options", "Pickup modifier", (KeyCode)308, (ConfigDescription)null);
GameInput.SetKeyMap((InputName)17, pickupModifier.Value, true);
}
}
internal class ShipItemInventory : MonoBehaviour
{
public bool inInventory;
}