using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("EasySweeper")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Hold the use button to keep sweeping with the broom.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+cd685046a5c6332da9451d6034e1e50e8f01a287")]
[assembly: AssemblyProduct("Easy Sweeper")]
[assembly: AssemblyTitle("EasySweeper")]
[assembly: AssemblyVersion("0.1.0.0")]
namespace EasySweeper;
[BepInPlugin("com.skeptic043.sailwind.easysweeper", "Easy Sweeper", "0.1.0")]
public class Plugin : BaseUnityPlugin
{
public const string Guid = "com.skeptic043.sailwind.easysweeper";
public const string PluginName = "Easy Sweeper";
public const string Version = "0.1.0";
private static FieldRef<ShipItemBroom, Cleaner> cleanerRef;
private static float nextStroke;
private void Awake()
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Expected O, but got Unknown
try
{
MethodInfo methodInfo = AccessTools.Method(typeof(GoPointerButton), "OnAltHeld", Type.EmptyTypes, (Type[])null) ?? throw new MissingMethodException("GoPointerButton.OnAltHeld() was not found.");
RequireField(typeof(Cleaner), "activated");
RequireField(typeof(ShipItem), "sold");
cleanerRef = AccessTools.FieldRefAccess<ShipItemBroom, Cleaner>("cleaner");
new Harmony("com.skeptic043.sailwind.easysweeper").Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Easy Sweeper could not patch the game and is inactive: " + ex.Message));
}
}
private static void RequireField(Type type, string name)
{
if (AccessTools.Field(type, name)?.FieldType != typeof(bool))
{
throw new MissingFieldException(type.Name, name);
}
}
private static void Postfix(GoPointerButton __instance)
{
ShipItemBroom val = (ShipItemBroom)(object)((__instance is ShipItemBroom) ? __instance : null);
if (val != null && ((ShipItem)val).sold)
{
Cleaner val2 = cleanerRef.Invoke(val);
if (StrokeTimer.ShouldRequest(val2.activated, Time.time, ref nextStroke))
{
val2.activated = true;
}
}
}
}
internal static class StrokeTimer
{
internal const float StrokeSeconds = 0.28f;
internal static bool ShouldRequest(bool strokeQueued, float now, ref float nextStroke)
{
if (!strokeQueued && now < nextStroke)
{
return false;
}
nextStroke = now + 0.28f;
return !strokeQueued;
}
}