using System;
using System.Diagnostics;
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 UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[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(CargoCarrier), "InsertItem")]
private static class CargoCarrierPatch
{
public static bool Prefix(ShipItem item)
{
return CanPickUp((PickupableItem)(object)item);
}
}
[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(LookUI), "ShowLookText")]
private static class ControlHintPrePatch
{
public static void Prefix(LookUI __instance, TextMesh ___controlsText)
{
___controlsText.text = "";
}
}
[HarmonyPatch(typeof(LookUI), "ShowLookText")]
private static class ControlHintPatch
{
public static void Postfix(LookUI __instance, GoPointer ___pointer, GoPointerButton button, TextMesh ___controlsText, TextMesh ___textLicon, TextMesh ___textRIcon, bool ___altIconsOn, bool ___showingIcon)
{
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Invalid comparison between Unknown and I4
//IL_032c: Unknown result type (might be due to invalid IL or missing references)
//IL_0331: Unknown result type (might be due to invalid IL or missing references)
//IL_030e: Unknown result type (might be due to invalid IL or missing references)
//IL_0313: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
//IL_0239: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
//IL_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0215: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
PickupableBoatMooringRope val = (PickupableBoatMooringRope)(object)((button is PickupableBoatMooringRope) ? button : null);
if (val != null && val.IsMoored())
{
___controlsText.text += "use";
AccessTools.Method(((object)__instance).GetType(), "ShowRicon", (Type[])null, (Type[])null).Invoke(__instance, new object[0]);
return;
}
ShipItem val2 = (ShipItem)(object)((button is ShipItem) ? button : null);
KeyCode val3;
if (val2 != null && (int)val2.category == 4)
{
if (val2 is ShipItemBed)
{
if (!CanPickUp((PickupableItem)(object)val2))
{
if (___altIconsOn)
{
___textLicon.text = "";
}
else
{
val3 = GameInput.GetKeyCode((InputName)8, ___altIconsOn, false);
___textLicon.text = ((object)(KeyCode)(ref val3)).ToString();
}
___controlsText.text = "use\nuse";
AccessTools.Method(((object)__instance).GetType(), "ShowRicon", (Type[])null, (Type[])null).Invoke(__instance, new object[0]);
}
else if (!CargoStorageUI.loadingCargoMode)
{
___controlsText.text += "use";
AccessTools.Method(((object)__instance).GetType(), "ShowRicon", (Type[])null, (Type[])null).Invoke(__instance, new object[0]);
}
}
else if (val2 is ShipItemLampHook && Object.op_Implicit((Object)(object)___pointer.GetHeldItem()) && ___pointer.GetHeldItem() is ShipItemHangable)
{
if (ShouldShowHighlight((PickupableItem)(object)val2, ___pointer))
{
___controlsText.text = "hang item\n";
return;
}
___controlsText.text = "";
AccessTools.Method(((object)__instance).GetType(), "HideIcons", (Type[])null, (Type[])null).Invoke(__instance, new object[0]);
}
else if (!CanPickUp((PickupableItem)(object)val2) && !Object.op_Implicit((Object)(object)___pointer.GetHeldItem()))
{
if (___altIconsOn)
{
if (CargoStorageUI.loadingCargoMode)
{
val3 = Main.pickupModifier.Value;
___textRIcon.text = ((object)(KeyCode)(ref val3)).ToString() + " + ";
}
val3 = Main.pickupModifier.Value;
___textLicon.text = ((object)(KeyCode)(ref val3)).ToString() + " + ";
return;
}
if (CargoStorageUI.loadingCargoMode)
{
val3 = Main.pickupModifier.Value;
string? text = ((object)(KeyCode)(ref val3)).ToString();
val3 = GameInput.GetKeyCode((InputName)9, ___altIconsOn, false);
___textRIcon.text = text + " + " + ((object)(KeyCode)(ref val3)).ToString();
}
val3 = Main.pickupModifier.Value;
string? text2 = ((object)(KeyCode)(ref val3)).ToString();
val3 = GameInput.GetKeyCode((InputName)8, ___altIconsOn, false);
___textLicon.text = text2 + " + " + ((object)(KeyCode)(ref val3)).ToString();
}
else if (___altIconsOn)
{
if (CargoStorageUI.loadingCargoMode)
{
___textRIcon.text = "";
}
___textLicon.text = "";
}
else
{
if (CargoStorageUI.loadingCargoMode)
{
val3 = GameInput.GetKeyCode((InputName)9, ___altIconsOn, false);
___textRIcon.text = ((object)(KeyCode)(ref val3)).ToString();
}
val3 = GameInput.GetKeyCode((InputName)8, ___altIconsOn, false);
___textLicon.text = ((object)(KeyCode)(ref val3)).ToString();
}
}
else if (___altIconsOn)
{
if (CargoStorageUI.loadingCargoMode)
{
___textRIcon.text = "";
}
___textLicon.text = "";
}
else
{
if (CargoStorageUI.loadingCargoMode)
{
val3 = GameInput.GetKeyCode((InputName)9, ___altIconsOn, false);
___textRIcon.text = ((object)(KeyCode)(ref val3)).ToString();
}
val3 = GameInput.GetKeyCode((InputName)8, ___altIconsOn, false);
___textLicon.text = ((object)(KeyCode)(ref val3)).ToString();
}
}
}
private static bool playerCrouching;
public static bool ShouldShowHighlight(PickupableItem target, GoPointer lookingPointer)
{
if (!CanPickUp(target))
{
if (target is ShipItemFoldable)
{
return true;
}
if (target is ShipItemBed)
{
return true;
}
ShipItemStove val = (ShipItemStove)(object)((target is ShipItemStove) ? target : null);
if (val != null && Object.op_Implicit((Object)(object)lookingPointer.GetHeldItem()))
{
if (Object.op_Implicit((Object)(object)((Component)lookingPointer.GetHeldItem()).GetComponent<CookableFood>()))
{
StoveCookTrigger[] slots = val.slots;
for (int i = 0; i < slots.Length; i++)
{
if ((Object)(object)slots[i].currentFood == (Object)null)
{
return true;
}
}
}
else if (lookingPointer.GetHeldItem() is ShipItemStoveFuel)
{
return true;
}
return false;
}
ShipItemLampHook val2 = (ShipItemLampHook)(object)((target is ShipItemLampHook) ? target : null);
if (val2 != null && Object.op_Implicit((Object)(object)lookingPointer.GetHeldItem()) && Object.op_Implicit((Object)(object)((Component)lookingPointer.GetHeldItem()).GetComponent<ShipItemHangable>()) && !(bool)Traverse.Create((object)val2).Field("occupied").GetValue())
{
return true;
}
return false;
}
return true;
}
public static bool CanPickUp(PickupableItem target)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Invalid comparison between Unknown and I4
if (Main.crouchPickup.Value && playerCrouching)
{
return true;
}
if (Input.GetKey(Main.pickupModifier.Value))
{
return true;
}
ShipItem val = (ShipItem)(object)((target is ShipItem) ? target : null);
if (val != null)
{
if (!Object.op_Implicit((Object)(object)val.currentActualBoat) || !Object.op_Implicit((Object)(object)val.currentWalkCol))
{
return true;
}
if ((int)val.category == 4)
{
if (val is ShipItemFoldable && (val.amount == 1f || !Main.lockMaps.Value))
{
return true;
}
return false;
}
}
return true;
}
}
[BepInPlugin("com.nandbrew.furniturefix", "Furniture Fix", "1.1.2")]
internal class Main : BaseUnityPlugin
{
public const string GUID = "com.nandbrew.furniturefix";
public const string NAME = "Furniture Fix";
public const string VERSION = "1.1.2";
internal static Main instance;
internal static ManualLogSource logSource;
internal static ConfigEntry<bool> crouchPickup;
internal static ConfigEntry<KeyCode> pickupModifier;
internal static ConfigEntry<bool> lockMaps;
private void Awake()
{
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);
lockMaps = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "Lock unrolled maps", true, (ConfigDescription)null);
}
}