Decompiled source of AtlyssAutoFishingAndChilling v1.0.4

plugins/AtlyssFishingAndChilling.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("AtlyssFishingAndChilling")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+da858c47ff3a18bcc1ac9f6c9a3fc1a67e377563")]
[assembly: AssemblyProduct("AtlyssFishingAndChilling")]
[assembly: AssemblyTitle("AtlyssFishingAndChilling")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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;
		}
	}
}
public class AutoFishingBehaviour : MonoBehaviour
{
	[CompilerGenerated]
	private sealed class <FishingLoop>d__8 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public AutoFishingBehaviour <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <FishingLoop>d__8(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>4__this.lastPos = ((Component)<>4__this.player).transform.position;
				break;
			case 1:
				<>1__state = -1;
				if (<>4__this.HasPlayerMoved())
				{
					<>4__this.isAutoFishing = false;
					return false;
				}
				if (!<>4__this.IsFishingToolActive())
				{
					<>4__this.isAutoFishing = false;
					return false;
				}
				if (<>4__this.profession._hasBite)
				{
					<>4__this.TryPullFishingLine();
					<>2__current = (object)new WaitForSeconds(1.5f);
					<>1__state = 2;
					return true;
				}
				break;
			case 2:
				<>1__state = -1;
				((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.RestartFishingWithDelay(0.25f));
				break;
			}
			<>2__current = (object)new WaitForSeconds(0.3f);
			<>1__state = 1;
			return true;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <RestartFishingWithDelay>d__11 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public float delay;

		public AutoFishingBehaviour <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <RestartFishingWithDelay>d__11(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSecondsRealtime(delay);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				<>4__this.TryStartFishing();
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private Player player;

	private PlayerProfession profession;

	private bool isAutoFishing = false;

	private Vector3 lastPos;

	private readonly Collider[] hits = (Collider[])(object)new Collider[8];

	private void Start()
	{
		player = ((Component)this).GetComponent<Player>();
		profession = ((Component)this).GetComponent<PlayerProfession>();
		if (!((Object)(object)player == (Object)null) && !((Object)(object)profession == (Object)null))
		{
		}
	}

	private void FixedUpdate()
	{
		if (!((Object)(object)player == (Object)null) && !((Object)(object)profession == (Object)null) && !isAutoFishing && IsFishingToolActive())
		{
			isAutoFishing = true;
			((MonoBehaviour)this).StartCoroutine(FishingLoop());
		}
	}

	private bool IsFishingToolActive()
	{
		if ((Object)(object)profession._scriptTool == (Object)null)
		{
			return false;
		}
		return ((Object)profession._scriptTool).name.IndexOf("fishing", StringComparison.OrdinalIgnoreCase) >= 0;
	}

	[IteratorStateMachine(typeof(<FishingLoop>d__8))]
	private IEnumerator FishingLoop()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <FishingLoop>d__8(0)
		{
			<>4__this = this
		};
	}

	private bool HasPlayerMoved()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = ((Component)player).transform.position - lastPos;
		float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
		if (sqrMagnitude > 0.0025f)
		{
			return true;
		}
		return false;
	}

	private void TryPullFishingLine()
	{
		profession.Cancel_ProfessionAction();
	}

	[IteratorStateMachine(typeof(<RestartFishingWithDelay>d__11))]
	private IEnumerator RestartFishingWithDelay(float delay)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <RestartFishingWithDelay>d__11(0)
		{
			<>4__this = this,
			delay = delay
		};
	}

	private void TryStartFishing()
	{
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: 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_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Invalid comparison between Unknown and I4
		if ((Object)(object)profession == (Object)null || (Object)(object)player == (Object)null)
		{
			return;
		}
		if ((Object)(object)profession._setResourceEntity != (Object)null)
		{
			ResourceEntity setResourceEntity = profession._setResourceEntity;
			if (setResourceEntity._isActive && CanUseToolOnResource(setResourceEntity))
			{
				((ScriptableConsumable)setResourceEntity._scriptableProfession._professionTool).Use_Consumable(player._statusEntity);
				return;
			}
		}
		PhysicsScene physicsScene = PhysicsSceneExtensions.GetPhysicsScene(((Component)player).gameObject.scene);
		int num = ((PhysicsScene)(ref physicsScene)).OverlapSphere(((Component)player).transform.position, 2.35f, hits, CastLayers.InteractableMask, (QueryTriggerInteraction)2);
		ResourceEntity val = default(ResourceEntity);
		for (int i = 0; i < num; i++)
		{
			if (!((Object)(object)hits[i] == (Object)null) && ((Component)hits[i]).gameObject.TryGetComponent<ResourceEntity>(ref val) && val._isActive && (int)player._pMove._currentMovementAction <= 0 && player._pInventory.Check_ItemQuantity((ScriptableItem)(object)val._scriptableProfession._professionTool) > 0 && ((ScriptableConsumable)val._scriptableProfession._professionTool).CanUseConsumable(player._statusEntity, true))
			{
				((ScriptableConsumable)val._scriptableProfession._professionTool).Use_Consumable(player._statusEntity);
				try
				{
					profession._setResourceEntity = val;
					break;
				}
				catch
				{
					break;
				}
			}
		}
	}

	private bool CanUseToolOnResource(ResourceEntity re)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Invalid comparison between Unknown and I4
		if ((Object)(object)re == (Object)null)
		{
			return false;
		}
		if (!re._isActive)
		{
			return false;
		}
		if ((int)player._pMove._currentMovementAction > 0)
		{
			return false;
		}
		if (player._pInventory.Check_ItemQuantity((ScriptableItem)(object)re._scriptableProfession._professionTool) <= 0)
		{
			return false;
		}
		if (!((ScriptableConsumable)re._scriptableProfession._professionTool).CanUseConsumable(player._statusEntity, true))
		{
			return false;
		}
		return true;
	}
}
namespace AtlyssFishingAndChillingMod
{
	[BepInPlugin("com.BLKNeko.AtlyssAutoFishingAndChilling", "com.BLKNeko.AtlyssAutoFishingAndChilling", "1.0.4")]
	public class AtlyssFishChillPlugin : BaseUnityPlugin
	{
		public const string MODUID = "com.BLKNeko.AtlyssAutoFishingAndChilling";

		public const string MODNAME = "com.BLKNeko.AtlyssAutoFishingAndChilling";

		public const string MODVERSION = "1.0.4";

		private readonly Harmony harmony = new Harmony("com.BLKNeko.AtlyssAutoFishingAndChilling");

		private static AtlyssFishChillPlugin Instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			Instance = this;
			mls = Logger.CreateLogSource("com.BLKNeko.AtlyssAutoFishingAndChilling");
			GameObject val = new GameObject("FishChillController");
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<ModInitializer>();
			Object.DontDestroyOnLoad((Object)(object)val);
		}
	}
	public class ModInitializer : MonoBehaviour
	{
		private bool attached = false;

		private int scanCounter;

		private void OnEnable()
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnDisable()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			attached = false;
		}

		private void FixedUpdate()
		{
			if (attached)
			{
				return;
			}
			scanCounter++;
			if (scanCounter <= 30)
			{
				return;
			}
			scanCounter = 0;
			Player[] array = Object.FindObjectsOfType<Player>();
			if (array == null || array.Length == 0)
			{
				return;
			}
			Player[] array2 = array;
			foreach (Player val in array2)
			{
				if ((Object)(object)val != (Object)null && ((NetworkBehaviour)val).isLocalPlayer && (Object)(object)((Component)val).GetComponent<AutoFishingBehaviour>() == (Object)null)
				{
					((Component)val).gameObject.AddComponent<AutoFishingBehaviour>();
					attached = true;
				}
			}
		}
	}
}