using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using Minigame;
using Minigame.Fishing;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("smrkn")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+980813636f46c850c0f0aadcdc123d5ab94aef18")]
[assembly: AssemblyProduct("Auto Fisher")]
[assembly: AssemblyTitle("AutoFisher")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/csh/lens-island-autofisher")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 AutoFisher
{
[BepInPlugin("com.smrkn.auto-fisher", "Auto Fisher", "0.1.1")]
public class Plugin : BaseUnityPlugin
{
private ConfigEntry<bool> _isEnabled;
private bool _inGameScene;
private bool _waitingForBite;
private bool _eventsSubscribed;
private const float ReactionTime = 0.1f;
private void Awake()
{
_isEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("AutoFisher", "Enabled", true, "Enable/disable fishing automation");
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
bool flag;
switch (((Scene)(ref scene)).name)
{
case "MainMenu":
case "LoadingScreen":
case "Boot":
case "Intro":
flag = true;
break;
default:
flag = false;
break;
}
_inGameScene = !flag;
CleanupAutomation();
if (_inGameScene)
{
SetupAutomation();
}
}
private void SetupAutomation()
{
if (_isEnabled.Value && !_eventsSubscribed)
{
((MonoBehaviour)this).StartCoroutine(WaitForFishingController());
}
}
private IEnumerator WaitForFishingController()
{
yield return (object)new WaitUntil((Func<bool>)(() => Object.op_Implicit((Object)(object)FishingController.Instance)));
if (!_eventsSubscribed)
{
((BaseUnityPlugin)this).Logger.LogDebug((object)"FishingController instance found, subscribing to events");
FishingController.GameStateChange += new GameStateChangeHandler(HandleStateChange);
FishingController.IndicateFishingCrit += new FishingCritHandler(HandleFishingCrit);
_eventsSubscribed = true;
}
}
private void CleanupAutomation()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
_waitingForBite = false;
if (_eventsSubscribed && (Object)(object)FishingController.Instance != (Object)null)
{
FishingController.GameStateChange -= new GameStateChangeHandler(HandleStateChange);
FishingController.IndicateFishingCrit -= new FishingCritHandler(HandleFishingCrit);
}
_eventsSubscribed = false;
}
private void HandleStateChange(MinigameState state)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected I4, but got Unknown
((BaseUnityPlugin)this).Logger.LogDebug((object)$"Fishing state changed to: {state}");
switch ((int)state)
{
case 1:
((BaseUnityPlugin)this).Logger.LogDebug((object)"Fishing minigame setup detected");
break;
case 2:
if (!_waitingForBite)
{
((BaseUnityPlugin)this).Logger.LogDebug((object)"Fishing pregame state - player needs to click when fish bites");
_waitingForBite = true;
((MonoBehaviour)this).StartCoroutine(MonitorForBite());
}
break;
case 3:
((BaseUnityPlugin)this).Logger.LogDebug((object)"Fishing minigame active - automation ready");
_waitingForBite = false;
break;
case 4:
((BaseUnityPlugin)this).Logger.LogInfo((object)"Fishing minigame won!");
break;
case 5:
((BaseUnityPlugin)this).Logger.LogWarning((object)"Fishing minigame lost - this should not happen with automation");
break;
case 6:
((BaseUnityPlugin)this).Logger.LogDebug((object)"Fishing minigame was canceled");
break;
case 0:
((BaseUnityPlugin)this).Logger.LogDebug((object)"Fishing minigame ended");
break;
}
}
private IEnumerator MonitorForBite()
{
if (!_waitingForBite)
{
yield break;
}
while (_waitingForBite && (int)FishingController.GameState == 2)
{
FishingRod activeRod = FishingRod.ActiveRod;
if (activeRod != null && (int)(activeRod.line?.state).GetValueOrDefault() == 5)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Bite detected, starting minigame!");
FishingController.Instance.hooked = true;
_waitingForBite = false;
break;
}
yield return (object)new WaitForSeconds(0.05f);
}
}
private void HandleFishingCrit(FishingCritType critType)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Invalid comparison between Unknown and I4
//IL_0016: 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_0039: Invalid comparison between Unknown and I4
if (_isEnabled.Value && (int)FishingController.GameState == 3)
{
if ((int)critType == 0)
{
((BaseUnityPlugin)this).Logger.LogDebug((object)"Simulating fishing input");
((MonoBehaviour)this).StartCoroutine(DelayedResponse());
}
else if ((int)critType == 1)
{
((BaseUnityPlugin)this).Logger.LogDebug((object)"Skipping bad click window");
}
}
}
private IEnumerator DelayedResponse()
{
yield return (object)new WaitForSeconds(0.1f);
if ((int)FishingController.GameState == 3)
{
SimulatePlayerInput();
}
}
private void SimulatePlayerInput()
{
try
{
Player instance = Singleton<Player>.Instance;
LenState_Base obj = ((instance != null) ? instance.currentState : null);
Lenstate_Fishing val = (Lenstate_Fishing)(object)((obj is Lenstate_Fishing) ? obj : null);
if (val != null)
{
val.Reel();
}
else
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Player is not in fishing state when trying to reel");
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Failed to simulate player input: " + ex.Message));
}
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
CleanupAutomation();
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.smrkn.auto-fisher";
public const string PLUGIN_NAME = "Auto Fisher";
public const string PLUGIN_VERSION = "0.1.1";
}
}