Decompiled source of Active Fishing v0.1.18

Active_Fishing.dll

Decompiled 6 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Active_Fishing")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.17.0")]
[assembly: AssemblyInformationalVersion("0.1.17+461b58cb4c17e6e1f085e254ecd4c6c2913a803a")]
[assembly: AssemblyProduct("Active_Fishing")]
[assembly: AssemblyTitle("Active_Fishing")]
[assembly: AssemblyVersion("0.1.17.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 Active_Fishing
{
	[BepInPlugin("korCaptain.Active_Fishing", "Active Fishing", "0.1.18")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "korCaptain.Active_Fishing";

		public const string PluginName = "Active Fishing";

		public const string PluginVersion = "0.1.18";

		internal static ManualLogSource Log;

		internal static ConfigEntry<float> DifficultyScale;

		internal static ConfigEntry<int> MissPenalty;

		internal static ConfigEntry<int> MaxMisses;

		internal static ConfigEntry<string> FishTierOverride;

		internal static ConfigEntry<float> SfxVolume;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			DifficultyScale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DifficultyScale", 1f, new ConfigDescription("Minigame difficulty multiplier, lower is easier\n미니게임 난이도 배율, 낮을수록 쉬움", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 2f), Array.Empty<object>()));
			MissPenalty = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MissPenalty", 10, new ConfigDescription("Gauge percent lost on a missed click\n클릭에 실패했을 때 깎이는 게이지(%)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 50), Array.Empty<object>()));
			MaxMisses = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxMisses", 3, new ConfigDescription("Missed clicks until the fish gets away\n물고기를 놓치는 실패 클릭 횟수", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>()));
			FishTierOverride = ((BaseUnityPlugin)this).Config.Bind<string>("General", "FishTierOverride", "", "Region tier override per fish prefab (1-7), e.g. Fish1:1,Fish10:7\n물고기 프리팹별 지역 단계(1-7) 지정, 예: Fish1:1,Fish10:7");
			SfxVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "SfxVolume", 0.8f, new ConfigDescription("Volume of this mod's sound effects, 0 disables them\n이 모드 효과음 볼륨, 0이면 끔", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			_harmony = new Harmony("korCaptain.Active_Fishing");
			_harmony.PatchAll();
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal static class FightPose
	{
		private const float TurnAngle = 35f;

		private const float LeanAngle = 15f;

		private const float FishAngleMax = 60f;

		private const float BlendTime = 0.15f;

		private const float StepTime = 0.4f;

		private const float StepSpeed = 1.5f;

		private static readonly int Sideway = ZSyncAnimation.GetHash("sideway_speed");

		private static readonly int Blocking = ZSyncAnimation.GetHash("blocking");

		private static Player _owner;

		private static ZSyncAnimation _anim;

		private static Transform _spine;

		private static Quaternion _clean;

		private static Quaternion _written;

		private static DragWindow _drag;

		private static bool _active;

		private static bool _leaned;

		private static bool _waitRelease;

		private static int _side;

		private static int _holdSide;

		private static int _dragSide;

		private static float _blend;

		private static float _holdTime;

		private static float _stepTime;

		internal static void Hold(int side, float time, bool waitRelease = false)
		{
			_holdSide = side;
			_holdTime = time;
			_waitRelease = waitRelease;
			_dragSide = 0;
		}

		internal static void LateTick()
		{
			FishState state = FishingSession.State;
			if (state == FishState.Mash || state == FishState.Fight || state == FishState.Finish)
			{
				Drive(state, Time.deltaTime);
			}
			else
			{
				Release();
			}
			Lean();
		}

		internal static void Release()
		{
			if (_active)
			{
				_active = false;
				_holdTime = (_stepTime = 0f);
				_side = (_dragSide = 0);
				_waitRelease = false;
				_drag = default(DragWindow);
				if (Object.op_Implicit((Object)(object)_anim))
				{
					_anim.SetBool(Blocking, false);
				}
			}
		}

		internal static void Step(ZSyncAnimation anim, int hash, ref float value)
		{
			if (_active && _side != 0 && _stepTime > 0f && hash == Sideway && (Object)(object)anim == (Object)(object)_anim)
			{
				value = (float)_side * 1.5f;
			}
		}

		internal static bool TryTurn(Character character, out float yaw)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			yaw = 0f;
			if (!_active || (Object)(object)character != (Object)(object)_owner || !Object.op_Implicit((Object)(object)FishingSession.Fish))
			{
				return false;
			}
			Vector3 val = ((Component)FishingSession.Fish).transform.position - ((Component)_owner).transform.position;
			val.y = 0f;
			float num = Vector3.SignedAngle(((Character)_owner).GetLookYaw() * Vector3.forward, val, Vector3.up);
			yaw = Mathf.Clamp(num, -60f, 60f) + _blend * 35f;
			return true;
		}

		private static void Drive(FishState state, float dt)
		{
			if (!_active)
			{
				Attach(FishingSession.Owner);
			}
			if (_waitRelease && !FightSession.AttackHeld() && !FightSession.BlockHeld())
			{
				_waitRelease = false;
			}
			bool flag = false;
			int side = 0;
			if (_holdTime > 0f)
			{
				_holdTime -= dt;
				flag = true;
				side = _holdSide;
			}
			else
			{
				switch (state)
				{
				case FishState.Finish:
					flag = true;
					break;
				case FishState.Fight:
					flag = ReadPull(dt, out side);
					break;
				}
			}
			if (side != _side && side != 0)
			{
				_stepTime = 0.4f;
			}
			else
			{
				_stepTime -= dt;
			}
			_side = side;
			_blend = Mathf.MoveTowards(_blend, (float)side, dt / 0.15f);
			if (Object.op_Implicit((Object)(object)_anim))
			{
				_anim.SetBool(Blocking, flag);
			}
		}

		private static void Attach(Player owner)
		{
			if ((Object)(object)owner != (Object)(object)_owner)
			{
				_owner = owner;
				_anim = ((Character)owner).GetZAnim();
				Animator componentInChildren = ((Component)owner).GetComponentInChildren<Animator>();
				_spine = (Object.op_Implicit((Object)(object)componentInChildren) ? Utils.GetBoneTransform(componentInChildren, (HumanBodyBones)7) : null);
				_leaned = false;
				_blend = 0f;
			}
			_active = true;
		}

		private static bool ReadPull(float dt, out int side)
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			side = 0;
			bool flag = FightSession.BlockHeld();
			bool flag2 = FightSession.AttackHeld();
			if (_waitRelease || Hud.InRadial() || flag || !flag2)
			{
				_dragSide = 0;
				_drag = default(DragWindow);
				return flag && !_waitRelease && !Hud.InRadial();
			}
			float joyRightStickX = ZInput.GetJoyRightStickX();
			int side2;
			float time;
			float pixels;
			if (Mathf.Abs(joyRightStickX) >= 0.5f)
			{
				_dragSide = ((joyRightStickX > 0f) ? 1 : (-1));
			}
			else if (_drag.Add(dt, ZInput.GetMouseDelta(), out side2, out time, out pixels) && side2 != 0)
			{
				_dragSide = side2;
			}
			side = _dragSide;
			return side != 0;
		}

		private static void Lean()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)_spine))
			{
				if (!_active)
				{
					_blend = Mathf.MoveTowards(_blend, 0f, Time.unscaledDeltaTime / 0.15f);
				}
				if (_leaned && _spine.localRotation == _written)
				{
					_spine.localRotation = _clean;
				}
				_leaned = _blend != 0f && Object.op_Implicit((Object)(object)_owner);
				if (_leaned)
				{
					_clean = _spine.localRotation;
					_spine.rotation = Quaternion.AngleAxis(-15f * _blend, ((Component)_owner).transform.forward) * _spine.rotation;
					_written = _spine.localRotation;
				}
			}
		}
	}
	internal enum RoundPhase
	{
		Move,
		Act
	}
	internal struct DragWindow
	{
		private const float Span = 0.05f;

		private const float Speed = 120f;

		private float _x;

		private float _y;

		private float _time;

		internal bool Add(float dt, Vector2 delta, out int side, out float time, out float pixels)
		{
			//IL_0008: 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)
			_x += delta.x;
			_y += delta.y;
			time = (_time += dt);
			pixels = Mathf.Abs(_x);
			side = 0;
			if (_time < 0.05f)
			{
				return false;
			}
			if (pixels >= 120f * _time && pixels >= Mathf.Abs(_y))
			{
				side = ((_x > 0f) ? 1 : (-1));
			}
			this = default(DragWindow);
			return true;
		}
	}
	internal static class FightSession
	{
		internal const float MashIntro = 0.6f;

		private const float MoveTime = 1.2f;

		private const float FinishReel = 0.4f;

		private const float DragTime = 0.15f;

		private const float DragPixels = 40f;

		internal const float StickThreshold = 0.5f;

		private const float TensionWarn = 70f;

		private const float MashDamage = 0.3f;

		private static float _holdNeed;

		private static float _tensionAdd;

		private static float _mashGain;

		private static float _mashDecay;

		private static float _startLine;

		private static float _endLine;

		private static float _good;

		private static float _bad;

		private static float _goodPixels;

		private static float _hold;

		private static bool _armed;

		private static bool _stick;

		private static bool _centerDone;

		private static int _last;

		private static int _beforeLast;

		private static DragWindow _drag;

		internal static float Timer { get; private set; }

		internal static RoundPhase Phase { get; private set; }

		internal static bool FirstMove { get; private set; }

		internal static int Side { get; private set; }

		internal static float Mash { get; private set; }

		internal static float Tension { get; private set; }

		internal static float Progress { get; private set; }

		internal static float Window { get; private set; }

		internal static float Remaining { get; private set; }

		internal static int Rounds { get; private set; }

		internal static int Done { get; private set; }

		internal static int Fails { get; private set; }

		internal static bool Jumped { get; private set; }

		internal static int MaxHp { get; private set; }

		internal static float HpRatio => (Mash < 100f) ? (1f - 0.3f * Mash / 100f) : (0.7f * (float)(Rounds - Done) / (float)Mathf.Max(1, Rounds));

		internal static float LineTarget => _startLine - (_startLine - _endLine) * (float)Done / (float)Mathf.Max(1, Rounds);

		internal static void Reset()
		{
			Timer = (Mash = (Tension = (Remaining = 0f)));
			Rounds = (Done = (Fails = (Side = 0)));
			Jumped = false;
			ReleaseButtons();
		}

		internal static void Begin(float t, float q, float scale, int maxHp)
		{
			Reset();
			MaxHp = maxHp;
			float num = Mathf.Clamp01((0.5f * t + 0.5f * q) * scale);
			Rounds = Mathf.FloorToInt(3f + 3f * num + 0.5f);
			Window = Mathf.Lerp(2.2f, 1.4f, num);
			_holdNeed = Mathf.Lerp(0.5f, 0.9f, num);
			_tensionAdd = Mathf.Lerp(30f, 45f, num);
			_mashGain = Mathf.Lerp(12f, 8f, num);
			_mashDecay = Mathf.Lerp(10f, 15f, num);
			_centerDone = false;
			_last = (_beforeLast = 2);
			Plugin.Log.LogInfo((object)string.Format(CultureInfo.InvariantCulture, "[ActiveFishing] fight N={0} f={1:0.00}", Rounds, num));
		}

		internal static void ReleaseButtons()
		{
			_armed = (_stick = false);
			_good = (_bad = (_goodPixels = (_hold = (Progress = 0f))));
			_drag = default(DragWindow);
		}

		internal static void Update(float dt, MinigameUI ui)
		{
			Timer += dt;
			if (FishingSession.State == FishState.Mash)
			{
				UpdateMash(dt, ui);
			}
			else if (FishingSession.State == FishState.Fight)
			{
				UpdateRound(dt, ui);
			}
			else
			{
				UpdateFinish(dt, ui);
			}
		}

		private static void UpdateMash(float dt, MinigameUI ui)
		{
			float lineLength = FishingSession.LineLength;
			Remaining = Mathf.Max(0f, lineLength - EndLine(lineLength));
			if (!(Timer < 0.6f))
			{
				Mash = Mathf.Max(0f, Mash - _mashDecay * dt);
				if (!Hud.InRadial() && AttackDown())
				{
					Mash = Mathf.Min(100f, Mash + _mashGain);
					ui.Fight.MashClick();
					FightPose.Hold(0, 0.25f);
					FishingAudio.Play("mash");
				}
				if (!(Mash < 100f))
				{
					_startLine = lineLength;
					_endLine = EndLine(lineLength);
					FishingSession.Advance(FishState.Fight);
					StartMove(first: true, ui);
				}
			}
		}

		private static float EndLine(float start)
		{
			return Mathf.Min(2.5f, start * 0.6f);
		}

		private static void StartMove(bool first, MinigameUI ui)
		{
			Phase = RoundPhase.Move;
			Timer = 0f;
			FirstMove = first;
			ReleaseButtons();
			Side = PickSide();
			FishingAudio.Play((Side < 0) ? "fishleft" : ((Side > 0) ? "fishright" : "thrash"));
			ui.Fight.MoveStart();
		}

		private static int PickSide()
		{
			int num = 0;
			if (Done != Rounds - 1 || _centerDone)
			{
				do
				{
					float value = Random.value;
					num = ((value < 0.375f) ? (-1) : ((!(value < 0.625f)) ? 1 : 0));
				}
				while (num == _last && _last == _beforeLast);
			}
			_beforeLast = _last;
			_last = num;
			return num;
		}

		private static void UpdateRound(float dt, MinigameUI ui)
		{
			Remaining = Mathf.Max(0f, FishingSession.LineLength - _endLine);
			if (Phase == RoundPhase.Move)
			{
				if (!(Timer < 1.2f))
				{
					Phase = RoundPhase.Act;
					Timer = 0f;
					ReleaseButtons();
					ui.Fight.ActStart();
				}
				return;
			}
			int num = 0;
			if (Hud.InRadial())
			{
				ReleaseButtons();
			}
			else
			{
				num = ((Side == 0) ? JudgeHold(dt) : JudgeDrag(dt, -Side));
			}
			if (num > 0)
			{
				Success(ui);
			}
			else if (num < 0)
			{
				Fail("miss", ui);
			}
			else if (Timer >= Window)
			{
				Fail("late", ui);
			}
		}

		private static bool AttackDown()
		{
			return ZInput.GetButtonDown("Attack") || ZInput.GetButtonDown("JoyAttack");
		}

		internal static bool AttackHeld()
		{
			return ZInput.GetButton("Attack") || ZInput.GetButton("JoyAttack");
		}

		private static bool BlockDown()
		{
			return ZInput.GetButtonDown("Block") || ZInput.GetButtonDown("JoyBlock");
		}

		internal static bool BlockHeld()
		{
			return ZInput.GetButton("Block") || ZInput.GetButton("JoyBlock");
		}

		private static int JudgeDrag(float dt, int need)
		{
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			if (BlockDown())
			{
				return -1;
			}
			if (AttackDown())
			{
				ReleaseButtons();
				_armed = true;
			}
			if (!_armed)
			{
				return 0;
			}
			if (!AttackHeld())
			{
				ReleaseButtons();
				return 0;
			}
			float num = ZInput.GetJoyRightStickX() * (float)need;
			int side;
			float time;
			float pixels;
			if (num >= 0.5f)
			{
				_good += dt;
				_stick = true;
			}
			else if (num <= -0.5f)
			{
				_bad += dt;
			}
			else if (_drag.Add(dt, ZInput.GetMouseDelta(), out side, out time, out pixels))
			{
				if (side == need)
				{
					_good += time;
					_goodPixels += pixels;
				}
				else if (side == -need)
				{
					_bad += time;
				}
			}
			Progress = Mathf.Clamp01(_good / 0.15f);
			if (_good >= 0.15f && (_goodPixels >= 40f || _stick))
			{
				return 1;
			}
			return (_bad >= 0.15f && _bad > _good) ? (-1) : 0;
		}

		private static int JudgeHold(float dt)
		{
			if (AttackDown())
			{
				return -1;
			}
			if (BlockDown())
			{
				ReleaseButtons();
				_armed = true;
			}
			if (!_armed)
			{
				return 0;
			}
			if (!BlockHeld())
			{
				ReleaseButtons();
				return 0;
			}
			_hold += dt;
			Progress = Mathf.Clamp01(_hold / _holdNeed);
			return (_hold >= _holdNeed) ? 1 : 0;
		}

		private static void Success(MinigameUI ui)
		{
			Done++;
			if (Side == 0)
			{
				_centerDone = true;
			}
			if (Done < Rounds)
			{
				FishingSession.DrainStamina(0.6f);
				FightPose.Hold(-Side, 0.35f, waitRelease: true);
			}
			FishingAudio.Play((Side == 0) ? "reel" : "drag");
			ui.RoundResult(success: true, "hit");
			if (Done < Rounds)
			{
				StartMove(first: false, ui);
				return;
			}
			FishingSession.Advance(FishState.Finish);
			Timer = 0f;
			ReleaseButtons();
		}

		private static void Fail(string key, MinigameUI ui)
		{
			Fails++;
			Done = Mathf.Max(0, Done - 1);
			Tension = Mathf.Min(100f, Tension + _tensionAdd);
			FishingSession.DrainStamina(0.3f);
			ui.RoundResult(success: false, key);
			if (Tension >= 100f)
			{
				FishingSession.LineBreak();
				return;
			}
			FishingAudio.Play("miss");
			if (Tension >= 70f)
			{
				FishingAudio.Play("tension");
			}
			StartMove(first: false, ui);
		}

		private static void UpdateFinish(float dt, MinigameUI ui)
		{
			Remaining = Mathf.Max(0f, FishingSession.LineLength - _endLine);
			if (Jumped)
			{
				if (FishControl.JumpDone(dt))
				{
					FishingSession.Land();
				}
			}
			else if (!(Timer < 0.4f))
			{
				if (!FishingSession.HasRoom() || !FishControl.CanJump())
				{
					FishingSession.Land();
					return;
				}
				Jumped = true;
				FishControl.Jump();
				FishingAudio.Play("jump");
				ui.Fight.Jumped();
			}
		}
	}
	internal class FightUI
	{
		private static readonly string[] ImagePaths = new string[9] { "Lane", "Lane/FishIcon", "Mash/MashMouse", "Mash/MashMouse/MashMouseL", "Mash/MashGauge", "Prompt/Mouse", "Prompt/Mouse/MouseL", "Prompt/Mouse/MouseR", "Tension" };

		private static readonly string[] FilledPaths = new string[7] { "Mash/MashGauge/MashFill", "Prompt/HoldRing", "Prompt/DragArrowL", "Prompt/DragArrowR", "Prompt/TimeBar", "Tension/TensionFill", "Tension/TensionDanger" };

		private static readonly string[] TextPaths = new string[4] { "DistanceText", "Mash/MashText", "Prompt/PromptText", "Tension/TensionLabel" };

		private static readonly float[] SegmentBend = new float[4] { 8f, 12f, 16f, 20f };

		private static bool _warned;

		private readonly bool _isFallback;

		private readonly GameObject _root;

		private readonly GameObject _mash;

		private readonly GameObject _prompt;

		private readonly RectTransform _fishRect;

		private readonly RectTransform _mashMouse;

		private readonly RectTransform _tensionRect;

		private readonly Image _splash;

		private readonly Image _mashMouseL;

		private readonly Image _mashFill;

		private readonly Image _holdBg;

		private readonly Image _holdRing;

		private readonly Image _mouse;

		private readonly Image _mouseL;

		private readonly Image _mouseR;

		private readonly Image _arrowL;

		private readonly Image _arrowR;

		private readonly Image _arrowLBg;

		private readonly Image _arrowRBg;

		private readonly Image _timeBar;

		private readonly Image _tensionFill;

		private readonly Image _danger;

		private readonly Image[] _slots;

		private readonly Image[] _flowsL;

		private readonly Image[] _flowsR;

		private readonly Transform[] _segments = (Transform[])(object)new Transform[4];

		private readonly Text _distance;

		private readonly Text _mashText;

		private readonly Text _promptText;

		private readonly Text _tensionLabel;

		private readonly Vector2 _tensionHome;

		private float _time;

		private float _fishX;

		private float _facing;

		private float _splashTime;

		private float _splashRepeat;

		private float _iconPunch;

		private float _kick;

		private float _click;

		private float _pulse;

		private float _pop;

		private float _shake;

		private float _spring;

		private float _tension;

		private float _meters;

		private int _shownTenths;

		private string _mashKey;

		private string _promptKey;

		internal FightUI(Transform panel)
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Expected O, but got Unknown
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Expected O, but got Unknown
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			Transform val = panel.Find("Fight");
			string text = (Object.op_Implicit((Object)(object)val) ? Validate(val) : "no Fight group");
			if (text != null)
			{
				if (!_warned)
				{
					_warned = true;
					Plugin.Log.LogWarning((object)("[ActiveFishing] fight UI missing or invalid (" + text + "), using fallback"));
				}
				if (Object.op_Implicit((Object)(object)val))
				{
					val.SetParent((Transform)null, false);
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
				val = Fallback(panel);
				_isFallback = true;
			}
			_root = ((Component)val).gameObject;
			_mash = ((Component)val.Find("Mash")).gameObject;
			_prompt = ((Component)val.Find("Prompt")).gameObject;
			_fishRect = (RectTransform)val.Find("Lane/FishIcon");
			_mashMouse = (RectTransform)val.Find("Mash/MashMouse");
			_tensionRect = (RectTransform)val.Find("Tension");
			_tensionHome = _tensionRect.anchoredPosition;
			_splash = Find(val, "Lane/FishSplash");
			_slots = (Image[])(object)new Image[3]
			{
				Find(val, "Lane/SlotL"),
				Find(val, "Lane/SlotC"),
				Find(val, "Lane/SlotR")
			};
			_mashMouseL = Find(val, "Mash/MashMouse/MashMouseL");
			_mashFill = Find(val, "Mash/MashGauge/MashFill");
			_holdBg = Find(val, "Prompt/HoldRingBg");
			_holdRing = Find(val, "Prompt/HoldRing");
			_mouse = Find(val, "Prompt/Mouse");
			_mouseL = Find(val, "Prompt/Mouse/MouseL");
			_mouseR = Find(val, "Prompt/Mouse/MouseR");
			_arrowL = Find(val, "Prompt/DragArrowL");
			_arrowR = Find(val, "Prompt/DragArrowR");
			_arrowLBg = Find(val, "Prompt/DragArrowLBg");
			_arrowRBg = Find(val, "Prompt/DragArrowRBg");
			_flowsL = (Image[])(object)new Image[3]
			{
				Find(val, "Prompt/DragArrowL/Flow0"),
				Find(val, "Prompt/DragArrowL/Flow1"),
				Find(val, "Prompt/DragArrowL/Flow2")
			};
			_flowsR = (Image[])(object)new Image[3]
			{
				Find(val, "Prompt/DragArrowR/Flow0"),
				Find(val, "Prompt/DragArrowR/Flow1"),
				Find(val, "Prompt/DragArrowR/Flow2")
			};
			_timeBar = Find(val, "Prompt/TimeBar");
			_tensionFill = Find(val, "Tension/TensionFill");
			_danger = Find(val, "Tension/TensionDanger");
			string text2 = "Rod/Handle";
			for (int i = 0; i < _segments.Length; i++)
			{
				text2 = text2 + "/Seg" + i;
				_segments[i] = val.Find(text2);
			}
			RectTransform val2 = (RectTransform)val.Find("DistanceText");
			val2.anchoredPosition = new Vector2(-332f, -24f);
			val2.sizeDelta = new Vector2(96f, 44f);
			_distance = MinigameUI.AddText((Transform)(object)val2, 17, (FontStyle)0);
			_mashText = MinigameUI.AddText(val.Find("Mash/MashText"), 36, (FontStyle)1);
			_promptText = MinigameUI.AddText(val.Find("Prompt/PromptText"), 24, (FontStyle)1);
			_tensionLabel = MinigameUI.AddText(val.Find("Tension/TensionLabel"), 18, (FontStyle)0);
		}

		private static Image Find(Transform root, string path)
		{
			Transform val = root.Find(path);
			return Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<Image>() : null;
		}

		private static string Validate(Transform fight)
		{
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Invalid comparison between Unknown and I4
			if (!(fight is RectTransform) || !(fight.Find("Mash") is RectTransform) || !(fight.Find("Prompt") is RectTransform))
			{
				return "missing Fight, Mash or Prompt rect";
			}
			string[] imagePaths = ImagePaths;
			foreach (string text in imagePaths)
			{
				if (!(fight.Find(text) is RectTransform) || !Object.op_Implicit((Object)(object)Find(fight, text)))
				{
					return "missing image " + text;
				}
			}
			string[] filledPaths = FilledPaths;
			foreach (string text2 in filledPaths)
			{
				Image val = Find(fight, text2);
				if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.sprite) || (int)val.type != 3)
				{
					return text2 + " needs a sprite and Image.Type.Filled";
				}
			}
			string[] textPaths = TextPaths;
			foreach (string text3 in textPaths)
			{
				Transform val2 = fight.Find(text3);
				if (!(val2 is RectTransform) || Object.op_Implicit((Object)(object)((Component)val2).GetComponent<Graphic>()))
				{
					return "missing empty rect " + text3;
				}
			}
			return null;
		}

		private static Transform Fallback(Transform panel)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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)
			//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_0060: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Unknown result type (might be due to invalid IL or missing references)
			//IL_0472: Unknown result type (might be due to invalid IL or missing references)
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04df: Unknown result type (might be due to invalid IL or missing references)
			Vector2 zero = Vector2.zero;
			Vector2 center = new Vector2(0.5f, 0.5f);
			Vector2 top = new Vector2(0.5f, 1f);
			Vector2 left = new Vector2(0f, 0.5f);
			Vector2 pivot = default(Vector2);
			((Vector2)(ref pivot))..ctor(1f, 0.5f);
			Color yellow = Color.yellow;
			Color color = default(Color);
			((Color)(ref color))..ctor(1f, 0.82f, 0.25f);
			Color color2 = default(Color);
			((Color)(ref color2))..ctor(0f, 0f, 0f, 0.6f);
			RectTransform val = MinigameUI.Node("Fight", panel, top, top, top, new Vector2(0f, -34f), new Vector2(760f, 260f));
			Transform val2 = panel.Find("ResultText");
			((Transform)val).SetSiblingIndex(val2.GetSiblingIndex());
			RectTransform parent = Box(At("Lane", (Transform)(object)val, 0f, -24f, 560f, 48f), new Color(0.5f, 0.5f, 0.5f, 0.6f));
			Box(MinigameUI.Node("FishIcon", (Transform)(object)parent, center, center, center, zero, new Vector2(56f, 32f)), Color.cyan * 0.8f + Color.black * 0.2f);
			At("DistanceText", (Transform)(object)val, -330f, -24f, 110f, 28f);
			RectTransform parent2 = MinigameUI.Node("Mash", (Transform)(object)val, top, top, top, new Vector2(0f, -56f), new Vector2(560f, 120f));
			RectTransform parent3 = Box(At("MashMouse", (Transform)(object)parent2, 0f, -34f, 40f, 60f), Color.white);
			Half("MashMouseL", (Transform)(object)parent3, 0f, yellow);
			Fill("MashFill", (Transform)(object)Box(At("MashGauge", (Transform)(object)parent2, 0f, -80f, 420f, 20f), color2), color);
			At("MashText", (Transform)(object)parent2, 0f, -108f, 300f, 40f);
			RectTransform parent4 = MinigameUI.Node("Prompt", (Transform)(object)val, top, top, top, new Vector2(0f, -56f), new Vector2(560f, 120f));
			Box(MinigameUI.Node("HoldRing", (Transform)(object)parent4, top, top, left, new Vector2(-42f, -72f), new Vector2(84f, 8f)), color);
			parent3 = Box(At("Mouse", (Transform)(object)parent4, 0f, -34f, 40f, 60f), Color.white);
			Half("MouseL", (Transform)(object)parent3, 0f, yellow);
			Half("MouseR", (Transform)(object)parent3, 0.5f, yellow);
			Box(MinigameUI.Node("DragArrowL", (Transform)(object)parent4, top, top, pivot, new Vector2(-40f, -34f), new Vector2(160f, 44f)), color);
			Box(MinigameUI.Node("DragArrowR", (Transform)(object)parent4, top, top, left, new Vector2(40f, -34f), new Vector2(160f, 44f)), color);
			At("PromptText", (Transform)(object)parent4, 0f, -88f, 480f, 30f);
			Box(MinigameUI.Node("TimeBar", (Transform)(object)parent4, top, top, left, new Vector2(-150f, -110f), new Vector2(300f, 6f)), color);
			RectTransform parent5 = Box(At("Tension", (Transform)(object)val, 40f, -200f, 300f, 16f), color2);
			Fill("TensionFill", (Transform)(object)parent5, new Color(1f, 0.65f, 0.1f));
			Fill("TensionDanger", (Transform)(object)parent5, Color.red);
			MinigameUI.Node("TensionLabel", (Transform)(object)parent5, left, left, pivot, new Vector2(-10f, 0f), new Vector2(90f, 24f));
			return (Transform)(object)val;
			RectTransform At(string name, Transform parent6, float x, float y, float w, float h)
			{
				//IL_0004: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: 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_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				return MinigameUI.Node(name, parent6, top, top, center, new Vector2(x, y), new Vector2(w, h));
			}
			static RectTransform Box(RectTransform rect, Color color3)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				MinigameUI.Paint(rect, color3);
				return rect;
			}
			void Fill(string name, Transform parent6, Color color3)
			{
				//IL_0004: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				RectTransform val3 = MinigameUI.Stretch(name, parent6, zero);
				val3.pivot = left;
				MinigameUI.Paint(val3, color3);
			}
			void Half(string name, Transform parent6, float from, Color color3)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				Box(MinigameUI.Node(name, parent6, new Vector2(from, 0.5f), new Vector2(from + 0.5f, 1f), center, zero, zero), color3);
			}
		}

		internal void Begin()
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			_time = (_splashTime = (_splashRepeat = (_iconPunch = (_kick = (_click = (_pulse = (_pop = (_shake = (_spring = (_tension = 0f))))))))));
			_fishX = 0.5f;
			_facing = 1f;
			_meters = -1f;
			_shownTenths = -1;
			_mashKey = (_promptKey = "");
			Text distance = _distance;
			Text mashText = _mashText;
			string text = (_promptText.text = "");
			string text3 = (mashText.text = text);
			distance.text = text3;
			_tensionLabel.text = L.Get("tension");
			_tensionRect.anchoredPosition = _tensionHome;
			_root.SetActive(false);
		}

		internal void Show(bool visible, FishState state)
		{
			_root.SetActive(visible);
			_mash.SetActive(state == FishState.Mash);
			_prompt.SetActive(state != FishState.Mash);
		}

		internal void MashClick()
		{
			_click = 0.12f;
			_pulse = 0.15f;
		}

		internal void MoveStart()
		{
			_splashTime = 0.4f;
		}

		internal void ActStart()
		{
			_pop = 0.15f;
		}

		internal void Success()
		{
			_iconPunch = 0.2f;
			_kick = 0.3f;
		}

		internal void Fail()
		{
			_splashTime = 0.4f;
			_shake = 0.25f;
		}

		internal void Jumped()
		{
			_spring = 0.2f;
		}

		internal void Draw(FishState state, float dt)
		{
			_time += dt;
			_iconPunch = Mathf.Max(0f, _iconPunch - dt);
			_kick = Mathf.Max(0f, _kick - dt);
			_click = Mathf.Max(0f, _click - dt);
			_pulse = Mathf.Max(0f, _pulse - dt);
			_pop = Mathf.Max(0f, _pop - dt);
			_shake = Mathf.Max(0f, _shake - dt);
			_spring = Mathf.Max(0f, _spring - dt);
			Fish(state, dt);
			Distance(dt);
			if (state == FishState.Mash)
			{
				Mash();
			}
			else
			{
				Prompt(state);
			}
			Tension(dt);
			Rod(state);
		}

		private void Fish(FishState state, float dt)
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			bool flag = state == FishState.Mash;
			bool flag2 = state == FishState.Fight && FightSession.Phase == RoundPhase.Move;
			bool flag3 = state == FishState.Fight && FightSession.Phase == RoundPhase.Act;
			int side = FightSession.Side;
			float num = (flag ? 0.5f : ((float)(side * 2 + 3) / 6f));
			float fishX = _fishX;
			_fishX = Mathf.MoveTowards(_fishX, num, 2.5f * dt);
			if (_fishX != fishX)
			{
				_facing = Mathf.Sign(_fishX - fishX);
			}
			RectTransform fishRect = _fishRect;
			RectTransform fishRect2 = _fishRect;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(_fishX, 0.5f);
			fishRect2.anchorMax = val;
			fishRect.anchorMin = val;
			float num2 = 1f + 0.3f * _iconPunch / 0.2f;
			((Transform)_fishRect).localScale = new Vector3(_facing * num2, num2, 1f);
			float num3 = (flag ? (Mathf.Sin(_time * 30f) * 12f) : (flag2 ? (Mathf.Sin(_time * 30f) * 10f) : (Mathf.Sin(_time * 8f) * 4f)));
			((Transform)_fishRect).localEulerAngles = new Vector3(0f, 0f, num3);
			if (flag && (_splashRepeat -= dt) <= 0f)
			{
				_splashRepeat = 0.5f;
				_splashTime = 0.4f;
			}
			_splashTime = Mathf.Max(0f, _splashTime - dt);
			if (Object.op_Implicit((Object)(object)_splash))
			{
				float num4 = 1f - _splashTime / 0.4f;
				float num5 = 1f - num4;
				RectTransform rectTransform = ((Graphic)_splash).rectTransform;
				((Vector2)(ref val))..ctor(_fishX, 0.5f);
				rectTransform.anchorMax = val;
				rectTransform.anchorMin = val;
				((Transform)rectTransform).localScale = Vector3.one * (0.6f + 0.6f * (1f - num5 * num5 * num5));
				Alpha(_splash, (_splashTime > 0f) ? (num5 * num5) : 0f);
			}
			for (int i = 0; i < _slots.Length; i++)
			{
				Alpha(_slots[i], (flag3 && i == side + 1) ? 1f : 0.35f);
			}
		}

		private void Distance(float dt)
		{
			_meters = ((_meters < 0f) ? FightSession.Remaining : Mathf.MoveTowards(_meters, FightSession.Remaining, 4f * dt));
			int num = Mathf.RoundToInt(_meters * 10f);
			if (num != _shownTenths)
			{
				_shownTenths = num;
				_distance.text = string.Format(L.Get("dist"), (float)num / 10f);
			}
		}

		private void Mash()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			string key = ((FightSession.Timer < 1.4000001f) ? "mash_hint" : "mash");
			SetText(_mashText, ref _mashKey, key);
			SetFill(_mashFill, FightSession.Mash / 100f);
			RectTransform mashMouse = _mashMouse;
			Vector3 localScale = (((Transform)((Graphic)_mashText).rectTransform).localScale = Vector3.one * (1f + 0.25f * _click / 0.12f));
			((Transform)mashMouse).localScale = localScale;
			Alpha(_mashMouseL, Mathf.Max(_pulse / 0.15f, 0.5f + 0.5f * Mathf.Sin(_time * 12f)));
		}

		private void Prompt(FishState state)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			bool flag = state == FishState.Fight && FightSession.Phase == RoundPhase.Act;
			int num = -FightSession.Side;
			bool flag2 = flag && num == 0;
			bool flag3 = flag && num != 0;
			float progress = FightSession.Progress;
			_prompt.transform.localScale = Vector3.one * (1f + 0.15f * _pop / 0.15f);
			float num2 = 0.6f + 0.4f * Mathf.Sin(_time * 10f);
			Alpha(_mouse, flag ? 1f : 0f);
			Alpha(_mouseL, flag3 ? num2 : 0f);
			Alpha(_mouseR, flag2 ? num2 : 0f);
			Arrow(_arrowL, _arrowLBg, _flowsL, flag3 && num < 0, -1, progress);
			Arrow(_arrowR, _arrowRBg, _flowsR, flag3 && num > 0, 1, progress);
			Alpha(_holdBg, flag2 ? 0.35f : 0f);
			Alpha(_holdRing, flag2 ? 1f : 0f);
			SetFill(_holdRing, flag2 ? progress : 0f);
			float num3 = (flag ? Mathf.Clamp01(1f - FightSession.Timer / FightSession.Window) : 0f);
			SetFill(_timeBar, num3);
			Alpha(_timeBar, (!flag) ? 0f : ((num3 <= 0.3f) ? (0.5f + 0.5f * Mathf.Sin(_time * 20f)) : 1f));
			string key = "";
			if (flag)
			{
				bool flag4 = ZInput.IsGamepadActive();
				key = ((num > 0) ? (flag4 ? "drag_right_pad" : "drag_right") : ((num >= 0) ? (flag4 ? "reel_pad" : "reel") : (flag4 ? "drag_left_pad" : "drag_left")));
			}
			else if (state == FishState.Fight && FightSession.FirstMove)
			{
				key = "fight";
			}
			SetText(_promptText, ref _promptKey, key);
		}

		private void Arrow(Image arrow, Image back, Image[] flows, bool on, int dir, float progress)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			Alpha(back, on ? 0.35f : 0f);
			Alpha(arrow, on ? 1f : 0f);
			SetFill(arrow, on ? progress : 0f);
			Vector2 val2 = default(Vector2);
			for (int i = 0; i < flows.Length; i++)
			{
				Image val = flows[i];
				if (Object.op_Implicit((Object)(object)val))
				{
					float num = Mathf.Repeat(_time * 2f + (float)i / 3f, 1f);
					RectTransform rectTransform = ((Graphic)val).rectTransform;
					((Vector2)(ref val2))..ctor((dir > 0) ? num : (1f - num), 0.5f);
					rectTransform.anchorMax = val2;
					rectTransform.anchorMin = val2;
					((Transform)rectTransform).localScale = new Vector3((float)dir, 1f, 1f);
					Alpha(val, on ? (0.9f * Mathf.Sin((float)Math.PI * num)) : 0f);
				}
			}
		}

		private void Tension(float dt)
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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)
			_tension = Mathf.MoveTowards(_tension, FightSession.Tension / 100f, dt / 0.2f);
			SetFill(_tensionFill, _tension);
			SetFill(_danger, _tension);
			Alpha(_danger, (FightSession.Tension >= 70f) ? (0.55f + 0.45f * Mathf.Sin(_time * 12f)) : 0f);
			_tensionRect.anchoredPosition = _tensionHome + new Vector2(Mathf.Sin(_shake * 80f) * 6f * (_shake / 0.25f), 0f);
		}

		private void Rod(FishState state)
		{
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			float tension = FightSession.Tension;
			float num = ((FightSession.Side == 0) ? 1f : ((float)FightSession.Side));
			float num2;
			if (state != FishState.Mash)
			{
				num2 = (FightSession.Jumped ? (_spring / 0.2f) : ((state != FishState.Finish) ? (0.2f + 0.5f * tension / 100f + 0.3f * FightSession.Progress + 0.3f * _kick / 0.3f) : 1f));
			}
			else
			{
				num2 = 0.3f + 0.4f * FightSession.Mash / 100f;
				num = 1f;
			}
			for (int i = 0; i < _segments.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)_segments[i]))
				{
					float num3 = (0f - num) * num2 * SegmentBend[i];
					if (i == 0 && tension >= 80f)
					{
						num3 += Mathf.Sin(_time * 45f) * 1.5f;
					}
					_segments[i].localEulerAngles = new Vector3(0f, 0f, num3);
				}
			}
		}

		private static void SetText(Text text, ref string shownKey, string key)
		{
			if (!(key == shownKey))
			{
				shownKey = key;
				text.text = ((key.Length == 0) ? "" : L.Get(key));
			}
		}

		private void SetFill(Image image, float value)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (_isFallback)
			{
				((Transform)((Graphic)image).rectTransform).localScale = new Vector3(value, 1f, 1f);
			}
			else
			{
				image.fillAmount = value;
			}
		}

		private static void Alpha(Image image, float alpha)
		{
			if (Object.op_Implicit((Object)(object)image))
			{
				MinigameUI.SetAlpha(image, alpha);
			}
		}
	}
	internal static class FishControl
	{
		private const float SideAngle = 35f;

		private const float SwimDepth = 0.6f;

		private const float LineSpeed = 3f;

		private const float FinishLineSpeed = 6f;

		private const float BreakSlack = 3f;

		private const float JumpCatchMax = 0.7f;

		private static readonly float[] AngleSteps = new float[4] { 1f, 0.6f, 0.3f, 0f };

		private static Rigidbody _body;

		private static ZNetView _view;

		private static ItemDrop _drop;

		private static bool _autoPickup;

		private static bool _rose;

		private static Vector3 _axis;

		private static Vector3 _toOwner;

		private static float _jumpTime;

		internal static void Begin(Player owner, Fish fish)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			_body = ((Component)fish).GetComponent<Rigidbody>();
			_view = ((Component)fish).GetComponent<ZNetView>();
			_drop = ((Component)fish).GetComponent<ItemDrop>();
			if (Object.op_Implicit((Object)(object)_drop))
			{
				_autoPickup = _drop.m_autoPickup;
				_drop.m_autoPickup = false;
			}
			Vector3 val = Flat(((Component)fish).transform.position - ((Component)owner).transform.position);
			if (((Vector3)(ref val)).sqrMagnitude > 0.01f)
			{
				((Character)owner).SetLookDir(val, 0.35f);
			}
			else
			{
				val = Flat(((Component)owner).transform.forward);
			}
			_axis = ((Vector3)(ref val)).normalized;
		}

		internal static void End()
		{
			if (Object.op_Implicit((Object)(object)_drop))
			{
				_drop.m_autoPickup = _autoPickup;
			}
			_drop = null;
			_body = null;
			_view = null;
		}

		internal static void Tick(FishState state, float dt)
		{
			//IL_005a: 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_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			FishingFloat val = FishingSession.Float;
			Transform rodTop = FishingSession.RodTop;
			if (state != FishState.Mash && Object.op_Implicit((Object)(object)rodTop))
			{
				ref float reference = ref Vanilla.LineLength.Invoke(val);
				float num = ((state == FishState.Finish) ? 6f : 3f);
				reference = Mathf.MoveTowards(reference, FightSession.LineTarget, num * dt);
				reference = Mathf.Max(reference, Vector3.Distance(rodTop.position, ((Component)val).transform.position) - 3f);
			}
			if (!OwnsFish())
			{
				return;
			}
			Fish fish = FishingSession.Fish;
			Vanilla.FishWaypointFloat.Invoke(fish) = null;
			Vanilla.FishBlockChange.Invoke(fish) = Time.time + 1f;
			Vanilla.FishNextEscape.Invoke(fish) = Time.time + 2f;
			ref float reference2 = ref Vanilla.FishEscapeTime.Invoke(fish);
			if (state == FishState.Finish)
			{
				reference2 = 0f;
				_view.GetZDO().Set(ZDOVars.s_escape, 0f);
			}
			else if (reference2 < 0.3f)
			{
				reference2 = 3f;
				_view.GetZDO().Set(ZDOVars.s_escape, 3f);
			}
			switch (state)
			{
			case FishState.Mash:
				Hold(fish);
				return;
			case FishState.Fight:
				Aim(fish, 35f * (float)FightSession.Side);
				return;
			}
			if (FightSession.Jumped)
			{
				Steer(fish, ((Component)fish).transform.position + _toOwner * 2f);
			}
			else
			{
				Aim(fish, 0f);
			}
		}

		internal static bool CanJump()
		{
			return OwnsFish() && Object.op_Implicit((Object)(object)_body) && !FishingSession.Fish.IsOutOfWater();
		}

		internal static void Jump()
		{
			//IL_000d: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			Fish fish = FishingSession.Fish;
			Vector3 position = ((Component)fish).transform.position;
			Vector3 val = Flat(((Component)FishingSession.Owner).transform.position - position);
			_toOwner = ((((Vector3)(ref val)).sqrMagnitude > 0.01f) ? ((Vector3)(ref val)).normalized : (-_axis));
			Transform transform = ((Component)fish).transform;
			Quaternion rotation = (_body.rotation = Quaternion.LookRotation(_toOwner));
			transform.rotation = rotation;
			Steer(fish, position + _toOwner * 2f);
			Vanilla.FishJump(fish);
			_jumpTime = 0f;
			_rose = false;
		}

		internal static bool JumpDone(float dt)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			_jumpTime += dt;
			if (!Object.op_Implicit((Object)(object)_body))
			{
				return true;
			}
			float y = _body.linearVelocity.y;
			if (y > 0.1f)
			{
				_rose = true;
			}
			return _jumpTime >= 0.7f || (_rose && y <= 0f);
		}

		private static bool OwnsFish()
		{
			return Object.op_Implicit((Object)(object)_view) && _view.IsValid() && _view.IsOwner();
		}

		private static void Aim(Fish fish, float angle)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			float lineTarget = FightSession.LineTarget;
			if (lineTarget < 2f)
			{
				angle = 0f;
			}
			Vector3 position = ((Component)FishingSession.Owner).transform.position;
			float[] angleSteps = AngleSteps;
			foreach (float num in angleSteps)
			{
				Vector3 point = position + Quaternion.Euler(0f, angle * num, 0f) * _axis * lineTarget;
				if (Swimmable(fish, ref point))
				{
					Steer(fish, point);
					return;
				}
				if (angle == 0f)
				{
					break;
				}
			}
			Hold(fish);
		}

		private static bool Swimmable(Fish fish, ref Vector3 point)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			point.y = ((Component)fish).transform.position.y;
			float liquidLevel = Floating.GetLiquidLevel(point, 1f, (LiquidType)0);
			float num = default(float);
			if (!ZoneSystem.instance.GetSolidHeight(point, ref num, 1000) || liquidLevel - num < fish.m_minDepth)
			{
				return false;
			}
			point.y = liquidLevel - 0.6f;
			return true;
		}

		private static void Hold(Fish fish)
		{
			Vanilla.FishHaveWaypoint.Invoke(fish) = false;
		}

		private static void Steer(Fish fish, Vector3 target)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)fish).transform.position;
			Vector3 val = Flat(target - position);
			if (((Vector3)(ref val)).sqrMagnitude < 0.09f)
			{
				Hold(fish);
				return;
			}
			if (Vector2.Distance(Vector2.op_Implicit(target), Vector2.op_Implicit(position)) < 0.2f)
			{
				target.y = position.y - 0.25f;
			}
			Vanilla.FishWaypoint.Invoke(fish) = target;
			Vanilla.FishHaveWaypoint.Invoke(fish) = true;
		}

		private static Vector3 Flat(Vector3 v)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(v.x, 0f, v.z);
		}
	}
	internal static class FishingAudio
	{
		private static readonly Dictionary<string, AudioClip> Clips = new Dictionary<string, AudioClip>();

		private static readonly Dictionary<string, float> LastPlayed = new Dictionary<string, float>();

		private static readonly Dictionary<string, float> Gaps = new Dictionary<string, float>
		{
			{ "pull", 1f },
			{ "mash", 0.06f },
			{ "thrash", 0.3f },
			{ "fishleft", 0.3f },
			{ "fishright", 0.3f },
			{ "tension", 1.5f }
		};

		private static AudioSource _source;

		private static string _pending;

		private static float _pendingAt;

		internal static void Attach(GameObject host)
		{
			_source = host.AddComponent<AudioSource>();
			_source.spatialBlend = 0f;
			_source.playOnAwake = false;
			_source.loop = false;
			_source.priority = 64;
			_pending = null;
		}

		internal static void Play(string id, float delay = 0f)
		{
			if (delay > 0f)
			{
				_pending = id;
				_pendingAt = Time.time + delay;
				return;
			}
			try
			{
				float value = Plugin.SfxVolume.Value;
				if (value <= 0f || !Object.op_Implicit((Object)(object)_source))
				{
					return;
				}
				if (!Gaps.TryGetValue(id, out var value2))
				{
					value2 = 0.1f;
				}
				if (LastPlayed.TryGetValue(id, out var value3) && Time.time - value3 < value2)
				{
					return;
				}
				AudioClip val = Load(id);
				if (Object.op_Implicit((Object)(object)val))
				{
					LastPlayed[id] = Time.time;
					if (Object.op_Implicit((Object)(object)AudioMan.instance))
					{
						_source.outputAudioMixerGroup = AudioMan.instance.m_guiMixer;
					}
					_source.PlayOneShot(val, value);
				}
			}
			catch (Exception ex)
			{
				Mute(id, ex.Message);
			}
		}

		internal static void Tick()
		{
			if (_pending != null && !(Time.time < _pendingAt))
			{
				string pending = _pending;
				_pending = null;
				Play(pending);
			}
		}

		private static void Mute(string id, string reason)
		{
			if (!Clips.TryGetValue(id, out var value) || value != null)
			{
				Clips[id] = null;
				Plugin.Log.LogWarning((object)("[ActiveFishing] sfx " + id + " missing or invalid (" + reason + "), muted"));
			}
		}

		private static AudioClip Load(string id)
		{
			if (Clips.TryGetValue(id, out var value))
			{
				return value;
			}
			byte[] b;
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("sfx." + id + ".wav"))
			{
				if (stream == null)
				{
					Mute(id, "not embedded");
					return null;
				}
				MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				b = memoryStream.ToArray();
			}
			float[] samples;
			int rate;
			string text = ParseWav(b, out samples, out rate);
			if (text != null)
			{
				Mute(id, text);
				return null;
			}
			AudioClip val = AudioClip.Create("af_" + id, samples.Length, 1, rate, false);
			typeof(AudioClip).GetMethod("SetData", new Type[2]
			{
				typeof(float[]),
				typeof(int)
			}).Invoke(val, new object[2] { samples, 0 });
			((Object)val).hideFlags = (HideFlags)32;
			Clips[id] = val;
			return val;
		}

		private static string ParseWav(byte[] b, out float[] samples, out int rate)
		{
			samples = null;
			rate = 0;
			if (b.Length < 12 || Tag(b, 0) != "RIFF" || Tag(b, 8) != "WAVE")
			{
				return "not a WAV file";
			}
			int num = 12;
			while (num + 8 <= b.Length)
			{
				string text = Tag(b, num);
				int num2 = BitConverter.ToInt32(b, num + 4);
				int num3 = num + 8;
				if (num2 < 0 || num2 > b.Length - num3)
				{
					return "truncated chunk";
				}
				if (text == "fmt ")
				{
					if (num2 < 16 || BitConverter.ToInt16(b, num3) != 1 || BitConverter.ToInt16(b, num3 + 2) != 1 || BitConverter.ToInt16(b, num3 + 14) != 16)
					{
						return "need PCM 16-bit mono";
					}
					rate = BitConverter.ToInt32(b, num3 + 4);
				}
				else if (text == "data")
				{
					if (rate <= 0 || num2 < 2)
					{
						return "no fmt chunk or empty data";
					}
					samples = new float[num2 / 2];
					for (int i = 0; i < samples.Length; i++)
					{
						samples[i] = (float)BitConverter.ToInt16(b, num3 + i * 2) / 32768f;
					}
					return null;
				}
				num = num3 + num2 + (num2 & 1);
			}
			return "no data chunk";
		}

		private static string Tag(byte[] b, int offset)
		{
			return Encoding.ASCII.GetString(b, offset, 4);
		}
	}
	internal static class Vanilla
	{
		internal static readonly FieldRef<FishingFloat, float> LineLength = AccessTools.FieldRefAccess<FishingFloat, float>("m_lineLength");

		internal static readonly FieldRef<Character, bool> Blocking = AccessTools.FieldRefAccess<Character, bool>("m_blocking");

		internal static readonly FieldRef<Character, Quaternion> LookYaw = AccessTools.FieldRefAccess<Character, Quaternion>("m_lookYaw");

		internal static readonly Action<FishingFloat, Fish> SetCatch = (Action<FishingFloat, Fish>)Delegate.CreateDelegate(typeof(Action<FishingFloat, Fish>), AccessTools.Method(typeof(FishingFloat), "SetCatch", (Type[])null, (Type[])null));

		internal static readonly Func<Player, bool> TakeInput = (Func<Player, bool>)Delegate.CreateDelegate(typeof(Func<Player, bool>), AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null));

		internal static readonly FieldRef<Fish, Vector3> FishWaypoint = AccessTools.FieldRefAccess<Fish, Vector3>("m_waypoint");

		internal static readonly FieldRef<Fish, bool> FishHaveWaypoint = AccessTools.FieldRefAccess<Fish, bool>("m_haveWaypoint");

		internal static readonly FieldRef<Fish, FishingFloat> FishWaypointFloat = AccessTools.FieldRefAccess<Fish, FishingFloat>("m_waypointFF");

		internal static readonly FieldRef<Fish, float> FishEscapeTime = AccessTools.FieldRefAccess<Fish, float>("m_escapeTime");

		internal static readonly FieldRef<Fish, float> FishNextEscape = AccessTools.FieldRefAccess<Fish, float>("m_nextEscape");

		internal static readonly FieldRef<Fish, float> FishBlockChange = AccessTools.FieldRefAccess<Fish, float>("m_blockChange");

		internal static readonly Action<Fish> FishJump = (Action<Fish>)Delegate.CreateDelegate(typeof(Action<Fish>), AccessTools.Method(typeof(Fish), "Jump", (Type[])null, (Type[])null));
	}
	[HarmonyPatch]
	internal static class FishingPatches
	{
		[HarmonyPatch(typeof(FishingFloat), "FixedUpdate")]
		[HarmonyPostfix]
		private static void FloatFixedUpdate(FishingFloat __instance)
		{
			//IL_0053: 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)
			try
			{
				Player localPlayer = Player.m_localPlayer;
				if (!Object.op_Implicit((Object)(object)localPlayer))
				{
					return;
				}
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if (Object.op_Implicit((Object)(object)component) && component.IsValid() && component.IsOwner())
				{
					long num = component.GetZDO().GetLong(ZDOVars.s_rodOwner, 0L);
					ZDOID zDOID = ((Character)localPlayer).GetZDOID();
					if (num == ((ZDOID)(ref zDOID)).UserID)
					{
						FishingSession.OnFloatFixedUpdate(__instance, component);
					}
				}
			}
			catch (Exception e)
			{
				FishingSession.Fail(e, __instance);
			}
		}

		[HarmonyPatch(typeof(FishingFloat), "FixedUpdate")]
		[HarmonyPrefix]
		private static void FloatKeepStamina(FishingFloat __instance)
		{
			try
			{
				FishingSession.KeepFinishStamina(__instance);
			}
			catch (Exception e)
			{
				FishingSession.Fail(e, __instance);
			}
		}

		[HarmonyPatch(typeof(Player), "SetControls")]
		[HarmonyPrefix]
		private static void SetControls(Player __instance, ref bool attack, ref bool attackHold, ref bool secondaryAttack, ref bool secondaryAttackHold, ref bool block, ref bool blockHold)
		{
			try
			{
				if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && FishingSession.BlocksInput())
				{
					attack = (attackHold = (secondaryAttack = (secondaryAttackHold = (block = (blockHold = false)))));
					Vanilla.Blocking.Invoke((Character)(object)__instance) = false;
				}
			}
			catch (Exception e)
			{
				FishingSession.Fail(e, null);
			}
		}

		[HarmonyPatch(typeof(Player), "SetMouseLook")]
		[HarmonyPrefix]
		private static void SetMouseLook(Player __instance, ref Vector2 mouseLook)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && FishingSession.LocksLook())
				{
					mouseLook = Vector2.zero;
				}
			}
			catch (Exception e)
			{
				FishingSession.Fail(e, null);
			}
		}

		[HarmonyPatch(typeof(ZSyncAnimation), "SetFloat", new Type[]
		{
			typeof(int),
			typeof(float)
		})]
		[HarmonyPrefix]
		private static void SetFloat(ZSyncAnimation __instance, int hash, ref float value)
		{
			try
			{
				FightPose.Step(__instance, hash, ref value);
			}
			catch (Exception e)
			{
				FishingSession.Fail(e, null);
			}
		}

		[HarmonyPatch(typeof(Character), "UpdateRotation")]
		[HarmonyPrefix]
		private static void TurnBody(Character __instance, out Quaternion? __state)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			__state = null;
			try
			{
				if (FightPose.TryTurn(__instance, out var yaw))
				{
					ref Quaternion reference = ref Vanilla.LookYaw.Invoke(__instance);
					__state = reference;
					reference *= Quaternion.Euler(0f, yaw, 0f);
				}
			}
			catch (Exception e)
			{
				FishingSession.Fail(e, null);
			}
		}

		[HarmonyPatch(typeof(Character), "UpdateRotation")]
		[HarmonyFinalizer]
		private static void RestoreLook(Character __instance, Quaternion? __state)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (__state.HasValue)
			{
				Vanilla.LookYaw.Invoke(__instance) = __state.Value;
			}
		}
	}
	internal enum FishState
	{
		Idle,
		Intro,
		Active,
		Mash,
		Fight,
		Finish,
		Paused,
		Result
	}
	internal static class FishingSession
	{
		private const float IntroTime = 0.6f;

		private const float ClickCooldown = 0.15f;

		private const float ResultTime = 1f;

		private const float SuccessResultTime = 1.5f;

		private const float AttackLockTime = 0.5f;

		private const float FightMinLine = 6f;

		private const float HitMargin = 0.02f;

		internal const float PullWarnTime = 0.25f;

		internal const float PullMoveTime = 0.35f;

		private const float JumpMoveTime = 0.18f;

		private const float ArrowTailTime = 0.2f;

		private const int DefaultTier = 4;

		private static readonly int[] TierHp = new int[7] { 100, 150, 220, 300, 400, 520, 660 };

		private const float HpPerStar = 0.15f;

		private static readonly Dictionary<string, int> Tiers = new Dictionary<string, int>
		{
			{ "Fish1", 1 },
			{ "Fish2", 2 },
			{ "Fish5", 2 },
			{ "Fish6", 3 },
			{ "Fish4_cave", 4 },
			{ "Fish3", 4 },
			{ "Fish8", 4 },
			{ "Fish7", 5 },
			{ "Fish9", 6 },
			{ "Fish12", 6 },
			{ "Fish11", 7 },
			{ "Fish10", 7 }
		};

		private static FishingFloat _float;

		private static FishingFloat _failedFloat;

		private static ZNetView _nview;

		private static Fish _fish;

		private static Player _owner;

		private static Transform _rodTop;

		private static MinigameUI _ui;

		private static float _startLine;

		private static float _timer;

		private static float _legs;

		private static float _cooldown;

		private static float _xpTimer;

		private static float _period;

		private static float _pullInterval;

		private static float _pullStep;

		private static float _hitGain;

		private static float _pullIn;

		private static float _pullTime;

		private static float _pullFrom;

		private static float _pullTo;

		private static float _widthFrom;

		private static float _widthTo;

		private static float _widthStart;

		private static float _widthEnd;

		private static float _jumpTime;

		private static float _speed;

		private static float _speedMin;

		private static float _speedMax;

		private static bool _jumping;

		private static int _maxHp;

		private static float _tier01;

		private static float _quality01;

		private static FishState _resume;

		private static int _quality;

		private static int _xpGiven;

		private static bool _zoneUsed;

		private static bool _locked;

		private static float _lockUntil;

		private static bool _errorLogged;

		private static string _warnedOverride;

		internal static FishState State { get; private set; }

		internal static float Gauge { get; private set; }

		internal static int Misses { get; private set; }

		internal static float BobberX { get; private set; }

		internal static float ZoneX { get; private set; }

		internal static float ZoneW { get; private set; }

		internal static int PullDir { get; private set; }

		internal static Player Owner => _owner;

		internal static Fish Fish => _fish;

		internal static FishingFloat Float => _float;

		internal static Transform RodTop => _rodTop;

		internal static float LineLength => Vanilla.LineLength.Invoke(_float);

		internal static float Legs => _legs;

		internal static float LegTime => _period * 0.5f / _speed;

		internal static float PullIn => _pullIn;

		internal static float PullTime => _pullTime;

		internal static float PullFrom => _pullFrom;

		internal static float PullTo => _pullTo;

		internal static bool BobberInZone => BobberX >= ZoneX - 0.02f && BobberX <= ZoneX + ZoneW + 0.02f;

		internal static void OnFloatFixedUpdate(FishingFloat ff, ZNetView nview)
		{
			DropDeadSession();
			if (State == FishState.Idle)
			{
				if (!((Object)(object)ff == (Object)(object)_failedFloat) && !((Character)Player.m_localPlayer).IsDead())
				{
					Fish val = ff.GetCatch();
					if (Object.op_Implicit((Object)(object)val))
					{
						Start(ff, nview, val);
					}
				}
			}
			else if ((Object)(object)ff == (Object)(object)_float && Object.op_Implicit((Object)(object)_fish) && (Object)(object)ff.GetCatch() == (Object)(object)_fish)
			{
				FixedTick(Time.fixedDeltaTime);
			}
		}

		private static void FixedTick(float dt)
		{
			if (State == FishState.Active)
			{
				ApplyReel(dt);
				DrainStamina(0.4f * dt);
				GainSkill(dt);
			}
			else if (State == FishState.Mash)
			{
				DrainStamina(0.5f * dt);
				GainSkill(dt);
				FishControl.Tick(State, dt);
			}
			else if (State == FishState.Fight)
			{
				GainSkill(dt);
				FishControl.Tick(State, dt);
			}
			else if (State == FishState.Finish)
			{
				FishControl.Tick(State, dt);
			}
		}

		internal static bool LocksLook()
		{
			DropDeadSession();
			FishState fishState = ((State == FishState.Paused) ? _resume : State);
			return fishState == FishState.Mash || fishState == FishState.Fight || fishState == FishState.Finish;
		}

		internal static void Advance(FishState next)
		{
			State = next;
		}

		internal static void KeepFinishStamina(FishingFloat ff)
		{
			if (State == FishState.Finish && (Object)(object)ff == (Object)(object)_float && Object.op_Implicit((Object)(object)_owner) && !((Character)_owner).HaveStamina(0f))
			{
				((Character)_owner).AddStamina(0.01f);
			}
		}

		internal static bool BlocksInput()
		{
			DropDeadSession();
			if (State != FishState.Idle)
			{
				return true;
			}
			if (_locked && Time.time >= _lockUntil && !ZInput.GetButton("Attack") && !ZInput.GetButton("JoyAttack"))
			{
				_locked = false;
			}
			return _locked;
		}

		internal static void Fail(Exception e, FishingFloat ff)
		{
			if (!_errorLogged)
			{
				_errorLogged = true;
				Plugin.Log.LogError((object)("[ActiveFishing][FAIL] " + e));
			}
			FishingFloat val = (Object.op_Implicit((Object)(object)ff) ? ff : _float);
			if (Object.op_Implicit((Object)(object)val))
			{
				_failedFloat = val;
			}
			if (State != FishState.Idle && State != FishState.Result)
			{
				LogEnd("Interrupted");
			}
			Clear();
			_locked = false;
		}

		private static void DropDeadSession()
		{
			if (State != FishState.Idle && (!Object.op_Implicit((Object)(object)_ui) || !Object.op_Implicit((Object)(object)_owner) || (Object)(object)_owner != (Object)(object)Player.m_localPlayer))
			{
				Interrupt();
			}
		}

		private static void Start(FishingFloat ff, ZNetView nview, Fish fish)
		{
			_float = ff;
			_nview = nview;
			_fish = fish;
			_owner = Player.m_localPlayer;
			_rodTop = Utils.FindChild(((Component)_owner).transform, "_RodTop", (IterativeSearchType)0);
			_startLine = Vanilla.LineLength.Invoke(ff);
			ItemDrop component = ((Component)fish).GetComponent<ItemDrop>();
			_quality = Mathf.Clamp((!Object.op_Implicit((Object)(object)component)) ? 1 : component.m_itemData.m_quality, 1, 5);
			string prefabName = Utils.GetPrefabName(((Component)fish).gameObject);
			int tier = GetTier(prefabName);
			float num = (_tier01 = (float)(tier - 1) / 6f);
			float num2 = (_quality01 = (float)(_quality - 1) / 4f);
			float value = Plugin.DifficultyScale.Value;
			float num3 = Mathf.Clamp01((0.7f * num + 0.3f * num2) * value);
			float num4 = Mathf.Clamp01((0.4f * num + 0.6f * num2) * value);
			_widthStart = Mathf.Lerp(0.28f, 0.17f, num3);
			_widthEnd = Mathf.Lerp(0.16f, 0.09f, num3);
			_speedMin = Mathf.Lerp(0.7f, 0.9f, num3);
			_speedMax = Mathf.Lerp(1.15f, 1.35f, num3);
			_maxHp = Mathf.RoundToInt((float)TierHp[tier - 1] * (1f + 0.15f * (float)(_quality - 1)));
			_period = Mathf.Lerp(2.3f, 1.3f, num3);
			_hitGain = Mathf.Lerp(25f, 12.5f, num3);
			_pullInterval = Mathf.Lerp(4.5f, 1.8f, num4);
			_pullStep = Mathf.Lerp(0.12f, 0.25f, num4);
			Gauge = 0f;
			Misses = 0;
			BobberX = 0f;
			ZoneW = NextWidth();
			_speed = Random.Range(_speedMin, _speedMax);
			ZoneX = Random.value * (1f - ZoneW);
			PullDir = 0;
			_jumping = false;
			_timer = (_legs = (_cooldown = (_xpTimer = (_pullTime = 0f))));
			_xpGiven = 0;
			_zoneUsed = false;
			_pullIn = NextPull();
			FightSession.Reset();
			_ui = MinigameUI.Get();
			string text = L.GameName(fish.GetHoverName());
			if (_quality > 1)
			{
				text = text + " " + new string('★', _quality - 1);
			}
			_ui.Begin(text);
			_ui.Hooked();
			ClearVanillaMessage();
			State = FishState.Intro;
			FishingAudio.Play("hooked");
			Plugin.Log.LogInfo((object)string.Format(CultureInfo.InvariantCulture, "[ActiveFishing] start {0} Q{1} T{2} d={3:0.00} hp={4}", prefabName, _quality, tier, num3, _maxHp));
		}

		internal static void Update(float dt)
		{
			if (State == FishState.Idle)
			{
				return;
			}
			if (!Object.op_Implicit((Object)(object)_owner) || (Object)(object)_owner != (Object)(object)Player.m_localPlayer || ((Character)_owner).IsDead())
			{
				Interrupt();
				return;
			}
			if (State == FishState.Result)
			{
				_timer -= dt;
				if (_timer <= 0f)
				{
					End();
				}
				return;
			}
			if (!Object.op_Implicit((Object)(object)_float) || !Object.op_Implicit((Object)(object)_nview) || !_nview.IsValid())
			{
				if (Object.op_Implicit((Object)(object)_rodTop) && ((Component)_rodTop).gameObject.activeInHierarchy)
				{
					ShowEscaped(0.4f, "linebroke");
				}
				else
				{
					Interrupt();
				}
				return;
			}
			if (!Object.op_Implicit((Object)(object)_fish) || (Object)(object)_float.GetCatch() != (Object)(object)_fish)
			{
				if (State == FishState.Finish && !Object.op_Implicit((Object)(object)_fish))
				{
					Interrupt();
				}
				else
				{
					ShowEscaped(0f);
				}
				return;
			}
			if (State == FishState.Intro)
			{
				_timer += dt;
				if (_timer >= 0.6f)
				{
					State = FishState.Active;
				}
				return;
			}
			if (State == FishState.Finish)
			{
				FightSession.Update(dt, _ui);
				return;
			}
			bool flag = Vanilla.TakeInput(_owner);
			if (State == FishState.Paused)
			{
				if (flag)
				{
					State = _resume;
				}
			}
			else if (!flag)
			{
				_resume = State;
				State = FishState.Paused;
				FightSession.ReleaseButtons();
			}
			else if (State == FishState.Active)
			{
				Play(dt);
			}
			else
			{
				FightSession.Update(dt, _ui);
			}
		}

		private static void StartMash()
		{
			State = FishState.Mash;
			PullDir = 0;
			FightSession.Begin(_tier01, _quality01, Plugin.DifficultyScale.Value, _maxHp);
			FishControl.Begin(_owner, _fish);
			_ui.Full();
			FishingAudio.Play("fight");
		}

		private static void Play(float dt)
		{
			MoveBobber(dt);
			if (_jumping)
			{
				UpdateJump(dt);
			}
			else
			{
				UpdatePull(dt);
			}
			_cooldown -= dt;
			bool bobberInZone = BobberInZone;
			if (!bobberInZone)
			{
				_zoneUsed = false;
			}
			if ((!ZInput.GetButtonDown("Attack") && !ZInput.GetButtonDown("JoyAttack")) || Hud.InRadial() || _cooldown > 0f || (bobberInZone && _zoneUsed))
			{
				return;
			}
			_cooldown = 0.15f;
			if (bobberInZone)
			{
				_zoneUsed = true;
				Gauge = Mathf.Min(100f, Gauge + _hitGain);
				if (Gauge >= 99.99f)
				{
					StartMash();
					return;
				}
				JumpZone();
				_ui.Hit();
				FishingAudio.Play("hit");
			}
			else
			{
				Misses++;
				Gauge = Mathf.Max(0f, Gauge - (float)Plugin.MissPenalty.Value);
				if (Misses >= Plugin.MaxMisses.Value)
				{
					Release();
					return;
				}
				JumpZone();
				_ui.Miss();
				FishingAudio.Play("miss");
			}
		}

		private static void MoveBobber(float dt)
		{
			int num = (int)_legs;
			_legs += dt / LegTime;
			if ((int)_legs != num)
			{
				_speed = _speedMin + Mathf.Repeat(_speed - _speedMin + (_speedMax - _speedMin) * Random.Range(0.25f, 0.75f), _speedMax - _speedMin);
			}
			BobberX = Mathf.PingPong(_legs, 1f);
		}

		private static float NextWidth()
		{
			return Mathf.Lerp(_widthStart, _widthEnd, Gauge / 100f) * Random.Range(0.92f, 1.08f);
		}

		private static void JumpZone()
		{
			if (PullDir != 0)
			{
				PullDir = 0;
				_pullIn = NextPull();
				_pullTime = 0f;
			}
			float num = Mathf.Repeat(ZoneX / (1f - ZoneW) + Random.Range(0.3f, 0.7f), 1f);
			_widthFrom = ZoneW;
			_widthTo = NextWidth();
			_pullFrom = ZoneX;
			_pullTo = num * (1f - _widthTo);
			_jumpTime = 0f;
			_jumping = true;
		}

		private static void UpdateJump(float dt)
		{
			_jumpTime += dt;
			SlideZone(_jumpTime / 0.18f);
			if (_jumpTime >= 0.18f)
			{
				_jumping = false;
			}
		}

		private static void SlideZone(float progress)
		{
			float num = Mathf.SmoothStep(0f, 1f, progress);
			ZoneX = Mathf.Lerp(_pullFrom, _pullTo, num);
			ZoneW = Mathf.Lerp(_widthFrom, _widthTo, num);
		}

		private static float NextPull()
		{
			return _pullInterval * Random.Range(0.8f, 1.2f);
		}

		private static void UpdatePull(float dt)
		{
			_pullIn -= dt;
			if (PullDir == 0)
			{
				if (_pullIn > 0.25f)
				{
					return;
				}
				int num = ((!(Random.value < 0.5f)) ? 1 : (-1));
				float num2 = NextWidth();
				float num3 = 1f - num2;
				float num4 = ZoneX + (float)num * _pullStep;
				if (num4 < 0f || num4 > num3)
				{
					num = -num;
				}
				_pullFrom = ZoneX;
				_pullTo = Mathf.Clamp(ZoneX + (float)num * _pullStep, 0f, num3);
				_widthFrom = ZoneW;
				_widthTo = num2;
				_pullTime = 0f;
				PullDir = num;
			}
			if (!(_pullIn > 0f))
			{
				if (_pullTime == 0f)
				{
					FishingAudio.Play("pull");
				}
				_pullTime += dt;
				SlideZone(_pullTime / 0.35f);
				if (!(_pullTime < 0.55f))
				{
					PullDir = 0;
					_pullIn = NextPull() - _pullTime;
				}
			}
		}

		private static float PullSpeed(float skill)
		{
			return Mathf.Lerp(_float.m_pullLineSpeed, _float.m_pullLineSpeedMaxSkill, skill);
		}

		private static void ApplyReel(float dt)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			float skillFactor = ((Character)_owner).GetSkillFactor((SkillType)104);
			if (Object.op_Implicit((Object)(object)_rodTop))
			{
				float num = Mathf.Max(Mathf.Min(_startLine, 6f), _startLine * (1f - 0.4f * Gauge / 100f));
				float num2 = Vector3.Distance(_rodTop.position, ((Component)_float).transform.position);
				ref float reference = ref Vanilla.LineLength.Invoke(_float);
				if (reference > num && reference > num2 - 0.2f)
				{
					reference = Mathf.Max(num, reference - PullSpeed(skillFactor) * dt);
				}
			}
		}

		internal static void DrainStamina(float factor)
		{
			float num = _float.m_pullStaminaUse + _fish.m_staminaUse * (float)_quality;
			num = Mathf.Lerp(num, num * _float.m_pullStaminaUseMaxSkillMultiplier, ((Character)_owner).GetSkillFactor((SkillType)104));
			((Character)_owner).UseStamina(num * factor);
		}

		private static void GainSkill(float dt)
		{
			_xpTimer += dt * 2f;
			if (_xpTimer > 1f)
			{
				_xpTimer = 0f;
				_xpGiven++;
				((Character)_owner).RaiseSkill((SkillType)104, 1f);
			}
		}

		private static bool HasRoomFor(Fish fish)
		{
			ItemDrop component = ((Component)fish).GetComponent<ItemDrop>();
			Inventory inventory = ((Humanoid)_owner).GetInventory();
			if (!Object.op_Implicit((Object)(object)component) || inventory.HaveEmptySlot())
			{
				return true;
			}
			ItemData itemData = component.m_itemData;
			int num = 0;
			foreach (ItemData allItem in inventory.GetAllItems())
			{
				if (allItem.m_shared.m_name == itemData.m_shared.m_name && allItem.m_quality == itemData.m_quality && allItem.m_worldLevel == itemData.m_worldLevel && allItem.m_stack < allItem.m_shared.m_maxStackSize)
				{
					num += allItem.m_shared.m_maxStackSize - allItem.m_stack;
				}
			}
			return num >= itemData.m_stack;
		}

		internal static bool HasRoom()
		{
			return HasRoomFor(_fish);
		}

		internal static void Land()
		{
			bool flag = HasRoomFor(_fish);
			int num = Mathf.FloorToInt(2f * _startLine / PullSpeed(((Character)_owner).GetSkillFactor((SkillType)104)));
			if (flag && num > _xpGiven)
			{
				((Character)_owner).RaiseSkill((SkillType)104, (float)(num - _xpGiven));
			}
			string hoverName = _fish.GetHoverName();
			string fishName = L.GameName(hoverName);
			string catchText = FishingFloat.Catch(_fish, (Character)(object)_owner);
			ClearVanillaMessage();
			ShowExtraDrops(catchText, hoverName);
			Vanilla.SetCatch(_float, null);
			_fish.OnHooked((FishingFloat)null);
			_nview.Destroy();
			if (!flag)
			{
				ShowEscaped(0f, "noroom");
				return;
			}
			_ui.Caught(L.Caught(fishName));
			FishingAudio.Play("catch", 0.15f);
			ToResult("Success");
		}

		private static void ShowExtraDrops(string catchText, string fishToken)
		{
			int length = ("$msg_fishing_catched " + fishToken).Length;
			if (catchText.Length > length)
			{
				string[] array = catchText.Substring(length).Split(new char[1] { '&' }, StringSplitOptions.RemoveEmptyEntries);
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = L.GameName(array[i].Trim());
				}
				((Character)_owner).Message((MessageType)1, "+ " + string.Join(", ", array), 0, (Sprite)null, false);
			}
		}

		private static void ClearVanillaMessage()
		{
			((Character)_owner).Message((MessageType)2, "", 0, (Sprite)null, false);
		}

		private static void Release()
		{
			Vanilla.SetCatch(_float, null);
			_fish.OnHooked((FishingFloat)null);
			Game.instance.IncrementPlayerStat((PlayerStatType)159, 1f, false);
			ShowEscaped(0f);
		}

		internal static void LineBreak()
		{
			//IL_0015: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			_float.m_lineBreakEffect.Create(((Component)_float).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
			_fish.OnHooked((FishingFloat)null);
			Game.instance.IncrementPlayerStat((PlayerStatType)159, 1f, false);
			_nview.Destroy();
			ShowEscaped(0.4f, "linebroke");
		}

		private static void ShowEscaped(float soundDelay, string text = "escaped")
		{
			ClearVanillaMessage();
			_ui.Escaped(text);
			FishingAudio.Play("escape", soundDelay);
			ToResult("Escaped");
		}

		private static void ToResult(string outcome)
		{
			State = FishState.Result;
			_timer = ((outcome == "Success") ? 1.5f : 1f);
			PullDir = 0;
			LogEnd(outcome);
		}

		private static void Interrupt()
		{
			if (State != FishState.Result)
			{
				LogEnd("Interrupted");
			}
			End();
		}

		private static void End()
		{
			Clear();
			_locked = true;
			_lockUntil = Time.time + 0.5f;
		}

		private static void Clear()
		{
			State = FishState.Idle;
			PullDir = 0;
			FishControl.End();
			FightPose.Release();
			_float = null;
			_nview = null;
			_fish = null;
			_owner = null;
			_rodTop = null;
		}

		private static void LogEnd(string outcome)
		{
			Plugin.Log.LogInfo((object)string.Format(CultureInfo.InvariantCulture, "[ActiveFishing] end {0} gauge={1:0} misses={2} rounds={3}/{4} fails={5} tension={6:0}", outcome, Gauge, Misses, FightSession.Done, FightSession.Rounds, FightSession.Fails, FightSession.Tension));
		}

		private static int GetTier(string prefab)
		{
			string text = Plugin.FishTierOverride.Value ?? "";
			int value;
			int result = (Tiers.TryGetValue(prefab, out value) ? value : 4);
			bool flag = false;
			string[] array = text.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
			foreach (string text2 in array)
			{
				string[] array2 = text2.Split(new char[1] { ':' });
				if (array2.Length != 2 || array2[0].Trim().Length == 0 || !int.TryParse(array2[1].Trim(), out var result2) || result2 < 1 || result2 > 7)
				{
					flag = true;
				}
				else if (array2[0].Trim() == prefab)
				{
					result = result2;
				}
			}
			if (flag && text != _warnedOverride)
			{
				_warnedOverride = text;
				Plugin.Log.LogWarning((object)"[ActiveFishing] FishTierOverride has invalid entries (expected Name:1-7), ignored");
			}
			return result;
		}
	}
	internal class HpBar
	{
		private const float TrailDelay = 0.35f;

		private const float HitTime = 0.25f;

		private readonly GameObject _root;

		private readonly RectTransform _rect;

		private readonly Image _fill;

		private readonly Image _trail;

		private readonly Image _flash;

		private readonly Text _text;

		private readonly Vector2 _home;

		private float _shown;

		private float _trailShown;

		private float _wait;

		private float _hit;

		private int _shownHp;

		internal HpBar(Transform panel)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			Transform val = panel.Find("Hp");
			if (!Valid(val))
			{
				Plugin.Log.LogWarning((object)"[ActiveFishing] fish HP bar missing or invalid in the UI, using fallback");
				if (Object.op_Implicit((Object)(object)val))
				{
					val.SetParent((Transform)null, false);
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
				val = Fallback(panel);
			}
			_root = ((Component)val).gameObject;
			_rect = (RectTransform)val;
			_home = _rect.anchoredPosition;
			_fill = Find(val, "HpFill");
			_trail = Find(val, "HpTrail");
			_flash = Find(val, "HpFlash");
			_text = MinigameUI.AddText(val.Find("HpText"), 18, (FontStyle)1);
			Graphic[] componentsInChildren = _root.GetComponentsInChildren<Graphic>(true);
			foreach (Graphic val2 in componentsInChildren)
			{
				val2.raycastTarget = false;
			}
			Begin();
		}

		private static Image Find(Transform root, string path)
		{
			Transform val = root.Find(path);
			return Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<Image>() : null;
		}

		private static bool Valid(Transform hp)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Invalid comparison between Unknown and I4
			if (!(hp is RectTransform))
			{
				return false;
			}
			Image val = Find(hp, "HpFill");
			Transform val2 = hp.Find("HpText");
			return Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.sprite) && (int)val.type == 3 && val2 is RectTransform && !Object.op_Implicit((Object)(object)((Component)val2).GetComponent<Graphic>());
		}

		private static Transform Fallback(Transform panel)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 1f);
			RectTransform val2 = MinigameUI.Node("Hp", panel, val, val, new Vector2(0.5f, 0.5f), new Vector2(0f, 24f), new Vector2(560f, 22f));
			((Transform)val2).SetSiblingIndex(panel.Find("ResultText").GetSiblingIndex());
			MinigameUI.Paint(val2, new Color(0f, 0f, 0f, 0.65f));
			MinigameUI.Paint(MinigameUI.Stretch("HpTrail", (Transform)(object)val2, Vector2.zero), new Color(1f, 0.85f, 0.55f));
			MinigameUI.Paint(MinigameUI.Stretch("HpFill", (Transform)(object)val2, Vector2.zero), new Color(0.78f, 0.12f, 0.1f));
			MinigameUI.Stretch("HpText", (Transform)(object)val2, Vector2.zero);
			return (Transform)(object)val2;
		}

		internal void Begin()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			_shown = (_trailShown = 1f);
			_wait = (_hit = 0f);
			_shownHp = -1;
			_rect.anchoredPosition = _home;
			_root.SetActive(false);
		}

		internal void Show(bool visible)
		{
			_root.SetActive(visible);
		}

		internal void Draw(float dt)
		{
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01(FightSession.HpRatio);
			if (num < _shown - 0.001f)
			{
				_hit = 0.25f;
				_wait = 0.35f;
			}
			_shown = num;
			_wait -= dt;
			if (_trailShown < _shown)
			{
				_trailShown = _shown;
			}
			else if (_wait <= 0f)
			{
				_trailShown = Mathf.MoveTowards(_trailShown, _shown, 0.6f * dt);
			}
			_hit = Mathf.Max(0f, _hit - dt);
			SetFill(_fill, _shown);
			SetFill(_trail, _trailShown);
			float num2 = _hit / 0.25f;
			if (Object.op_Implicit((Object)(object)_flash))
			{
				Color color = ((Graphic)_flash).color;
				color.a = 0.8f * num2 * num2;
				((Graphic)_flash).color = color;
			}
			_rect.anchoredPosition = _home + new Vector2(Mathf.Sin(_hit * 90f) * 4f * num2, 0f);
			int num3 = Mathf.CeilToInt((float)FightSession.MaxHp * num - 0.001f);
			if (num3 != _shownHp)
			{
				_shownHp = num3;
				_text.text = string.Format(L.Get("hp"), num3, FightSession.MaxHp);
			}
		}

		private static void SetFill(Image image, float value)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)image))
			{
				if ((int)image.type == 3 && Object.op_Implicit((Object)(object)image.sprite))
				{
					image.fillAmount = value;
				}
				else
				{
					((Graphic)image).rectTransform.anchorMax = new Vector2(value, 1f);
				}
			}
		}
	}
	internal class MinigameFx
	{
		private const float TrackPx = 672f;

		private const float ArriveTime = 0.3f;

		private static readonly Color DirLeft = new Color(0.3f, 0.92f, 1f);

		private static readonly Color DirRight = new Color(1f, 0.7f, 0.24f);

		private static readonly float[] GhostAlpha = new float[3] { 0.3f, 0.18f, 0.09f };

		private readonly Transform _root;

		private readonly float _scale;

		private readonly List<Image> _all = new List<Image>();

		private readonly RectTransform _panel;

		private readonly RectTransform _bar;

		private readonly RectTransform _bobber;

		private readonly RectTransform _bracketL;

		private readonly RectTransform _bracketR;

		private readonly RectTransform _resultText;

		private readonly RectTransform _rays;

		private readonly RectTransform _zoneGhost;

		private readonly Image _trailL;

		private readonly Image _trailR;

		private readonly Image _streak;

		private readonly Image _ghostBracketL;

		private readonly Image _ghostBracketR;

		private readonly Image _impact;

		private readonly Image _splash;

		private readonly Image _ring;

		private readonly Image _ring2;

		private readonly Image _screenFlash;

		private readonly Image[] _ghosts;

		private readonly Image[] _chevrons;

		private readonly Image[] _rayImages;

		private readonly Image[] _shards;

		private float _time;

		private float _arrive;

		private float _catchTime;

		private float _fullTime;

		private int _pullDir;

		private bool _arrived;

		internal MinigameFx(Transform root, float alphaScale)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			_root = root;
			_scale = alphaScale;
			_panel = (RectTransform)root;
			_bar = Rect("Bar");
			_bobber = Rect("Bar/Track/Bobber");
			_bracketL = Rect("Bar/Track/Zone/BracketL");
			_bracketR = Rect("Bar/Track/Zone/BracketR");
			_resultText = Rect("ResultText");
			_rays = Rect("CatchBack/Rays");
			_zoneGhost = Rect("Bar/Track/ZoneGhost");
			_trailL = Optional("Bar/Track/TrailL");
			_trailR = Optional("Bar/Track/TrailR");
			_streak = Optional("Bar/Track/ZoneStreak");
			_ghostBracketL = Optional("Bar/Track/ZoneGhost/GhostBracketL");
			_ghostBracketR = Optional("Bar/Track/ZoneGhost/GhostBracketR");
			_impact = Optional("Bar/Track/ZoneImpact");
			_splash = Optional("Bar/Track/Splash");
			_ring = Optional("CatchBack/Ring");
			_ring2 = Optional("CatchBack/Ring2");
			_screenFlash = Optional("CatchFront/ScreenFlash");
			_ghosts = Pool("Bar/Track/Ghost", 3);
			_chevrons = Pool("Bar/Track/PullChevron", 3);
			_rayImages = Pool("CatchBack/Rays/Ray", 12);
			_shards = Pool("CatchFront/Shard", 16);
		}

		internal void Begin()
		{
			_time = (_arrive = (_catchTime = 0f));
			_pullDir = 0;
			_arrived = false;
			Clear();
		}

		internal void Full()
		{
			_fullTime = 0f;
		}

		internal void Caught()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			_catchTime = 0f;
			GameCamera instance = GameCamera.instance;
			if (Object.op_Implicit((Object)(object)instance))
			{
				instance.AddShake(((Component)instance).transform.position, 10f, 1.3f, false);
			}
		}

		internal void Clear()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c