using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("UnlimitedHammer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UnlimitedHammer")]
[assembly: AssemblyTitle("UnlimitedHammer")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace UnlimitedHammer
{
[BepInPlugin("DogEggz.unlimitedhammer", "Unlimited hammer", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
private Harmony harmony;
internal static ConfigEntry<bool> ModEnabled { get; private set; }
internal static bool IsModEnabled
{
get
{
if (ModEnabled != null)
{
return ModEnabled.Value;
}
return true;
}
}
private void Awake()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Mod enabled", true, "Toggle all Unlimited hammer changes on or off.");
harmony = new Harmony("DogEggz.unlimitedhammer");
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
private void OnDestroy()
{
Harmony obj = harmony;
if (obj != null)
{
obj.UnpatchSelf();
}
}
}
internal static class ExtraNailableItems
{
private static readonly HashSet<string> Names = new HashSet<string>(StringComparer.Ordinal) { "137 model ship junk (big)", "138 model ship junk (small)", "190 flower pot", "191 flower pot 1", "192 flower pot 2", "193 flower pot 3", "194 flower pot 4 (small)", "195 flower pot 5 (small)" };
public static bool Contains(ShipItem item)
{
if ((Object)(object)item == (Object)null)
{
return false;
}
return Names.Contains(NormalizeName(((Object)((Component)item).transform).name));
}
private static string NormalizeName(string itemName)
{
if (string.IsNullOrEmpty(itemName))
{
return string.Empty;
}
itemName = itemName.Trim();
while (itemName.EndsWith("(Clone)", StringComparison.Ordinal))
{
itemName = itemName.Substring(0, itemName.Length - "(Clone)".Length).Trim();
}
return itemName;
}
}
[HarmonyPatch(typeof(ShipItemHammer), "CanNail")]
internal static class ShipItemHammerCanNailPatch
{
private static void Postfix(ShipItem item, ref bool __result)
{
if (Plugin.IsModEnabled && !__result && !((Object)(object)item == (Object)null) && item.sold)
{
__result = ExtraNailableItems.Contains(item);
}
}
}
[HarmonyPatch(typeof(ShipItemHammer), "NailItem")]
internal static class ShipItemHammerNailItemPatch
{
private static bool Prefix(ShipItem item)
{
if (!Plugin.IsModEnabled)
{
return true;
}
if ((Object)(object)item == (Object)null)
{
return false;
}
item.nailed = true;
UISoundPlayer.instance.PlayUISound((UISounds)11, 1f, 0.6f);
Debug.Log((object)("Nailed " + item.name));
return false;
}
}
[HarmonyPatch(typeof(LookUI), "ShowLookText")]
internal static class LookUIHammerPercentPatch
{
private const float NailDurationSeconds = 2f;
private static readonly FieldInfo CurrentlyNailedItemField = AccessTools.Field(typeof(ShipItemHammer), "currentlyNailedItem");
private static readonly FieldInfo NailTimerField = AccessTools.Field(typeof(ShipItemHammer), "nailTimer");
private static void Postfix(GoPointerButton button, GoPointer ___pointer, TextMesh ___hintText)
{
if (!Plugin.IsModEnabled || (Object)(object)button == (Object)null || (Object)(object)___pointer == (Object)null || (Object)(object)___hintText == (Object)null)
{
return;
}
ShipItem component = ((Component)button).GetComponent<ShipItem>();
if ((Object)(object)component == (Object)null || component.nailed)
{
return;
}
PickupableItem heldItem = ___pointer.GetHeldItem();
ShipItemHammer val = (((Object)(object)heldItem == (Object)null) ? null : ((Component)heldItem).GetComponent<ShipItemHammer>());
if (!((Object)(object)val == (Object)null) && ((ShipItem)val).sold && !((Object)/*isinst with value type is only supported in some contexts*/ != (Object)(object)component))
{
float num = ((NailTimerField?.GetValue(val) is float num2) ? num2 : 0f);
if (!(num <= 0f))
{
int num3 = Mathf.Clamp(Mathf.FloorToInt(num / 2f * 100f), 0, 100);
string text = $"<color=white>{num3}%</color>";
___hintText.text = (string.IsNullOrEmpty(___hintText.text) ? text : (___hintText.text + "\n" + text));
}
}
}
}
}