using System.Collections.Generic;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Crest;
using HarmonyLib;
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("HooksHangMore")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("raddude")]
[assembly: AssemblyProduct("HooksHangMore")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7fbc1d41-251b-4cf2-8ee9-13edaafcc6ee")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.0")]
[module: UnverifiableCode]
namespace HooksHangMore
{
[BepInPlugin("com.raddude82.hookshangmore", "HooksHangMore", "1.0.4")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class HHM_Plugin : BaseUnityPlugin
{
public const string PLUGIN_GUID = "com.raddude82.hookshangmore";
public const string PLUGIN_NAME = "HooksHangMore";
public const string PLUGIN_VERSION = "1.0.4";
public const string IDLE_FISHING_GUID = "com.isa_idlefishing.patch";
private static ManualLogSource _logger;
internal static HHM_Plugin Instance { get; private set; }
internal static bool IdleFishingFound { get; private set; }
internal static Dictionary<ShipItem, ShipItemHolder> AttachedItems { get; set; }
internal static void LogDebug(string message)
{
_logger.LogDebug((object)message);
}
internal static void LogInfo(string message)
{
_logger.LogInfo((object)message);
}
internal static void LogWarning(string message)
{
_logger.LogWarning((object)message);
}
internal static void LogError(string message)
{
_logger.LogError((object)message);
}
private void Awake()
{
if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this)
{
Object.Destroy((Object)(object)((Component)this).gameObject);
return;
}
Instance = this;
_logger = ((BaseUnityPlugin)this).Logger;
AttachedItems = new Dictionary<ShipItem, ShipItemHolder>();
foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
{
BepInPlugin metadata = pluginInfo.Value.Metadata;
if (metadata.GUID.Equals("com.isa_idlefishing.patch"))
{
LogInfo("com.isa_idlefishing.patch found");
IdleFishingFound = true;
}
}
Configs.InitializeConfigs();
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.raddude82.hookshangmore");
}
}
internal class FishingRodPatches
{
[HarmonyPatch(typeof(FishingRodFish))]
private class FishingRodFishPatches
{
[HarmonyBefore(new string[] { "com.isa_idlefishing.patch" })]
[HarmonyPostfix]
[HarmonyPatch("Update")]
public static void Postfix(FishingRodFish __instance, ShipItemFishingRod ___rod, SimpleFloatingObject ___floater, ConfigurableJoint ___bobberJoint, ref float ___fishTimer)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__instance.currentFish != (Object)null || ((ShipItem)___rod).health <= 0f || !HHM_Plugin.AttachedItems.ContainsKey((ShipItem)(object)___rod) || !((FloatingObjectBase)___floater).InWater)
{
return;
}
SoftJointLimit linearLimit = ___bobberJoint.linearLimit;
if (((SoftJointLimit)(ref linearLimit)).limit <= 1f || ((Component)__instance).gameObject.layer == 16)
{
return;
}
float num = ((!(GameState.distanceToLand < 500f)) ? (HHM_Plugin.IdleFishingFound ? 10f : 5.13f) : (HHM_Plugin.IdleFishingFound ? 20f : 6.67f));
___fishTimer -= Time.deltaTime;
float num2 = Vector3.Distance(((Component)__instance).transform.position, ((Component)___rod).transform.position);
float num3 = Mathf.InverseLerp(3f, 20f, num2) * 2.5f + 0.5f;
if (___fishTimer <= 0f)
{
___fishTimer = 1f;
num3 /= num;
if (Random.Range(0f, 100f) < num3)
{
__instance.CatchFish();
}
}
}
}
}
internal class ItemHolderPatches
{
[HarmonyPatch(typeof(ShipItem))]
private class ShipItemPatches
{
[HarmonyBefore(new string[] { "com.nandbrew.nandfixes" })]
[HarmonyPostfix]
[HarmonyPatch("OnLoad")]
public static void OnLoadShipItemHolder(ShipItem __instance)
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
if (__instance is ShipItemLampHook)
{
((Component)__instance).gameObject.AddComponent<ShipItemHolder>();
}
ShipItemBroom val = (ShipItemBroom)(object)((__instance is ShipItemBroom) ? __instance : null);
if (val != null)
{
HolderAttachable holderAttachable = ((Component)val).gameObject.AddComponent<HolderAttachable>();
holderAttachable.PositionOffset = BROOM_POSITION_OFFSET;
}
}
[HarmonyPrefix]
[HarmonyPatch("AllowOnItemClick")]
public static bool AllowOnItemClick(GoPointerButton lookedAtButton, ShipItem __instance, ref bool __result)
{
if ((Object)(object)((Component)__instance).GetComponent<HolderAttachable>() != (Object)null && (Object)(object)((Component)lookedAtButton).GetComponent<ShipItemHolder>() != (Object)null && !((Component)lookedAtButton).GetComponent<ShipItemHolder>().IsOccupied)
{
__result = true;
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("OnPickup")]
public static void OnShipItemPickup(ShipItem __instance)
{
if ((Object)(object)((Component)__instance).GetComponent<HolderAttachable>() != (Object)null && HHM_Plugin.AttachedItems.ContainsKey(__instance))
{
ShipItemHolder shipItemHolder = HHM_Plugin.AttachedItems[__instance];
if ((Object)(object)shipItemHolder != (Object)null && (Object)(object)shipItemHolder.AttachedItem == (Object)(object)__instance)
{
shipItemHolder.DetachItem();
}
}
}
}
[HarmonyPatch(typeof(ShipItemFishingRod), "OnLoad")]
private class ShipItemFishingRodPatches
{
public static void Postfix(ShipItemFishingRod __instance)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
HolderAttachable holderAttachable = ((Component)__instance).gameObject.AddComponent<HolderAttachable>();
holderAttachable.PositionOffset = ROD_POSITION_OFFSET;
holderAttachable.RotationOffset = ROD_ROTATION_OFFSET;
}
}
[HarmonyPatch(typeof(ShipItemChipLog), "OnLoad")]
private class ShipItemChipLogPatches
{
public static void Postfix(ShipItemChipLog __instance)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
HolderAttachable holderAttachable = ((Component)__instance).gameObject.AddComponent<HolderAttachable>();
holderAttachable.PositionOffset = CHIP_LOG_POSITION_OFFSET;
}
}
[HarmonyPatch(typeof(ShipItemQuadrant), "OnLoad")]
private class ShipItemQuadrantPatches
{
public static void Postfix(ShipItemQuadrant __instance)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
HolderAttachable holderAttachable = ((Component)__instance).gameObject.AddComponent<HolderAttachable>();
holderAttachable.PositionOffset = QUADRANT_POSITION_OFFSET;
holderAttachable.RotationOffset = QUADRANT_ROTATION_OFFSET;
}
}
[HarmonyPatch(typeof(ShipItemKnife))]
private class ShipItemKnifePatches
{
[HarmonyPostfix]
[HarmonyPatch("OnLoad")]
public static void AddComponent(ShipItemKnife __instance)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
HolderAttachable holderAttachable = ((Component)__instance).gameObject.AddComponent<HolderAttachable>();
holderAttachable.PositionOffset = KNIFE_POSITION_OFFSET;
holderAttachable.RotationOffset = KNIFE_ROTATION_OFFSET;
if (Configs.flipKnifeRotation.Value)
{
holderAttachable.PositionOffset = new Vector3(0f - holderAttachable.PositionOffset.x, 0f - holderAttachable.PositionOffset.y, holderAttachable.PositionOffset.z);
holderAttachable.RotationOffset = new Vector3(holderAttachable.RotationOffset.x - 180f, holderAttachable.RotationOffset.y, holderAttachable.RotationOffset.z);
}
}
[HarmonyPrefix]
[HarmonyPatch("AllowOnItemClick")]
public static bool AllowOnItemClick(GoPointerButton lookedAtButton, ref bool __result)
{
if (Object.op_Implicit((Object)(object)((Component)lookedAtButton).GetComponent<ShipItemHolder>()) && !((Component)lookedAtButton).GetComponent<ShipItemHolder>().IsOccupied)
{
__result = true;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(ShipItemLampHook))]
private class ShipItemLampHookPatches
{
[HarmonyPostfix]
[HarmonyPatch("OnPickup")]
public static void OnPickup(ShipItemLampHook __instance)
{
ShipItemHolder component = ((Component)__instance).GetComponent<ShipItemHolder>();
if (component.IsOccupied)
{
component.DetachItem();
}
}
[HarmonyPostfix]
[HarmonyPatch("OnEnterInventory")]
public static void OnEnterInventory(ShipItemLampHook __instance)
{
ShipItemHolder component = ((Component)__instance).GetComponent<ShipItemHolder>();
if (component.IsOccupied)
{
component.DetachItem();
}
}
[HarmonyPrefix]
[HarmonyPatch("OnItemClick")]
public static bool OnItemClick(PickupableItem heldItem, ShipItemLampHook __instance, bool ___occupied, ref bool __result)
{
ShipItemHolder component = ((Component)__instance).GetComponent<ShipItemHolder>();
if (component.IsOccupied || ___occupied)
{
__result = false;
return false;
}
ShipItem component2 = ((Component)heldItem).GetComponent<ShipItem>();
if ((Object)(object)((Component)component2).GetComponent<HolderAttachable>() != (Object)null && component2.sold)
{
component.AttachItem(component2);
((Component)component2).GetComponent<HolderAttachable>().ShipItemHolder = component;
__result = true;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(LookUI))]
private class LookUIPatches
{
[HarmonyPostfix]
[HarmonyPatch("ShowLookText")]
public static void ShowLookText(GoPointerButton button, TextMesh ___controlsText, GoPointer ___pointer, TextMesh ___textLicon, ref bool ___showingIcon)
{
ShipItemLampHook component = ((Component)button).GetComponent<ShipItemLampHook>();
if ((Object)(object)component != (Object)null && Object.op_Implicit((Object)(object)___pointer.GetHeldItem()) && (Object)(object)((Component)component).GetComponent<ShipItemHolder>() != (Object)null && ((Component)component).GetComponent<ShipItemHolder>().IsOccupied)
{
((Component)___textLicon).gameObject.SetActive(false);
___showingIcon = false;
___controlsText.text = "";
}
else if ((Object)(object)component != (Object)null && Object.op_Implicit((Object)(object)___pointer.GetHeldItem()) && (Object)(object)((Component)___pointer.GetHeldItem()).GetComponent<HolderAttachable>() != (Object)null && !((Component)component).GetComponent<ShipItemHolder>().IsOccupied)
{
((Component)___textLicon).gameObject.SetActive(true);
___showingIcon = true;
PickupableItem heldItem = ___pointer.GetHeldItem();
___controlsText.text = "attach " + ((heldItem == null) ? null : ((Component)heldItem).GetComponent<ShipItem>()?.name) + "\n";
}
}
}
private static readonly Vector3 ROD_POSITION_OFFSET = new Vector3(0.309f, 1.1f, -0.38f);
private static readonly Vector3 ROD_ROTATION_OFFSET = new Vector3(-40f, 180f, 0f);
private static readonly Vector3 BROOM_POSITION_OFFSET = new Vector3(0f, -0.25f, -0.11f);
private static readonly Vector3 CHIP_LOG_POSITION_OFFSET = new Vector3(0.002f, 0.25f, -0.12f);
private static readonly Vector3 QUADRANT_POSITION_OFFSET = new Vector3(-0.0155f, 0.164f, -0.115f);
private static readonly Vector3 QUADRANT_ROTATION_OFFSET = new Vector3(90f, -90f, 0f);
private static readonly Vector3 KNIFE_POSITION_OFFSET = new Vector3(0.05f, -0.115f, -0.182f);
private static readonly Vector3 KNIFE_ROTATION_OFFSET = new Vector3(270f, 270f, 0f);
}
public class HolderAttachable : MonoBehaviour
{
private ShipItem _shipItem;
private bool _disallowHangingOnTrigger;
private float _framesAfterAwake;
internal ShipItemHolder ShipItemHolder { private get; set; }
public Vector3 PositionOffset { get; set; }
public Vector3 RotationOffset { get; set; }
public bool IsAttached => (Object)(object)ShipItemHolder != (Object)null;
private void Awake()
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
_shipItem = ((Component)this).GetComponent<ShipItem>();
ShipItemHolder = null;
_disallowHangingOnTrigger = false;
_framesAfterAwake = 0f;
PositionOffset = Vector3.zero;
RotationOffset = Vector3.zero;
}
private void FixedUpdate()
{
if (_framesAfterAwake < 3f)
{
_framesAfterAwake += 1f;
}
}
public void LoadInInventory()
{
_disallowHangingOnTrigger = true;
}
public void OnTriggerEnter(Collider other)
{
ShipItemHolder component = ((Component)other).GetComponent<ShipItemHolder>();
if (_framesAfterAwake < 3f && _shipItem.sold && !Object.op_Implicit((Object)(object)((PickupableItem)_shipItem).held) && _shipItem.GetCurrentInventorySlot() == -1 && !_disallowHangingOnTrigger && ((Component)other).CompareTag("Hook") && (Object)(object)component != (Object)null && !component.IsOccupied)
{
component.AttachItem(_shipItem);
ShipItemHolder = component;
}
}
public void DetachHolder()
{
if ((Object)(object)ShipItemHolder != (Object)null)
{
ShipItemHolder = null;
}
}
public void OnDestroy()
{
ShipItemHolder?.DetachItem();
_disallowHangingOnTrigger = false;
}
}
public class ShipItemHolder : MonoBehaviour
{
private Transform _itemRigidBody;
private ShipItem _attachedItem;
public bool IsOccupied => (Object)(object)_attachedItem != (Object)null;
public ShipItem AttachedItem => _attachedItem;
private void Awake()
{
_itemRigidBody = ((Component)((ShipItem)((Component)((Component)this).transform).GetComponent<ShipItemLampHook>()).itemRigidbodyC).transform;
}
internal void AttachItem(ShipItem item)
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)item == (Object)null)
{
HHM_Plugin.LogError("ShipItem is null, cannot hang item");
return;
}
HolderAttachable component = ((Component)item).GetComponent<HolderAttachable>();
if ((Object)(object)component == (Object)null)
{
HHM_Plugin.LogError("HolderAttachable is null, cannot hang item");
return;
}
Vector3 positionOffset = component.PositionOffset;
Quaternion val = Quaternion.Euler(component.RotationOffset);
HHM_Plugin.AttachedItems.Add(item, this);
_attachedItem = item;
Vector3 position = _itemRigidBody.TransformPoint(positionOffset);
((Component)item.itemRigidbodyC).transform.position = position;
Quaternion rotation = _itemRigidBody.rotation * val;
((Component)item.itemRigidbodyC).transform.rotation = rotation;
item.itemRigidbodyC.attached = true;
HHM_Plugin.LogDebug($"Item localpos: {((Component)item.itemRigidbodyC).transform.localPosition}, Item parent: {((Component)item.itemRigidbodyC).transform.parent}");
}
internal void DetachItem()
{
if (!((Object)(object)_attachedItem == (Object)null))
{
_attachedItem.itemRigidbodyC.attached = false;
HHM_Plugin.AttachedItems.Remove(_attachedItem);
((Component)_attachedItem).GetComponent<HolderAttachable>().DetachHolder();
_attachedItem = null;
}
}
private void OnDestroy()
{
if (IsOccupied)
{
DetachItem();
}
}
}
internal class Configs
{
internal static ConfigEntry<bool> flipKnifeRotation;
internal static void InitializeConfigs()
{
ConfigFile config = ((BaseUnityPlugin)HHM_Plugin.Instance).Config;
flipKnifeRotation = config.Bind<bool>("Settings", "Knife hangs down", false, "Knife hangs down in the lamp hook instead of pointing up.");
}
}
}
namespace HooksHangMore.Patches
{
internal class QuadrantPatches
{
[HarmonyPatch(typeof(ShipItemQuadrant), "ExtraLateUpdate")]
private class ShipItemQuadrantPatches
{
public static void Postfix(ShipItemQuadrant __instance)
{
if (GameState.playing)
{
HolderAttachable component = ((Component)__instance).GetComponent<HolderAttachable>();
if ((Object)(object)component != (Object)null && component.IsAttached)
{
__instance.lockX = false;
}
else
{
__instance.lockX = true;
}
}
}
}
}
}