Decompiled source of BaitIndex v1.0.2

BaitIndex.dll

Decompiled 11 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace HowToFish.BaitIndex;

public enum JournalViewMode
{
	Regular,
	SuperCreatures
}
[BepInProcess("How to Fish.exe")]
[BepInPlugin("com.howToFish.baitindex", "BaitIndex", "1.0.1")]
public sealed class BaitIndexPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "com.howToFish.baitindex";

	public const string PluginName = "BaitIndex";

	public const string PluginVersion = "1.0.1";

	public static JournalViewMode CurrentViewMode;

	private static readonly Dictionary<string, string> _guideBaitMap;

	public static BaitIndexPlugin Instance { get; private set; }

	public static ManualLogSource Log { get; private set; }

	public static ConfigEntry<bool> ModEnabled { get; private set; }

	public static ConfigEntry<bool> RevealUndiscovered { get; private set; }

	private static void Reg(string key, string bait)
	{
		if (!string.IsNullOrEmpty(key))
		{
			_guideBaitMap[key.Trim()] = bait;
		}
	}

	static BaitIndexPlugin()
	{
		CurrentViewMode = JournalViewMode.Regular;
		_guideBaitMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
		Reg("Brown Crab", "Free Lure");
		Reg("BrownCrab", "Free Lure");
		Reg("Овальный Краб", "Free Lure");
		Reg("Shrimp", "Free Lure");
		Reg("Креветка", "Free Lure");
		Reg("Mackerel", "Free Lure");
		Reg("Скумбрия", "Free Lure");
		Reg("Gar", "Free Lure");
		Reg("Панцирник", "Free Lure");
		Reg("Pike", "Free Lure");
		Reg("Пайк", "Free Lure");
		Reg("Rock Crab", "Hotdog");
		Reg("RockCrab", "Hotdog");
		Reg("Каменный Краб", "Hotdog");
		Reg("Lobster", "Hotdog");
		Reg("Омар", "Hotdog");
		Reg("Piranha", "Hotdog • Beginner Lure");
		Reg("Пиранья", "Hotdog • Beginner Lure");
		Reg("Salmon", "Beginner Lure");
		Reg("Лосось", "Beginner Lure");
		Reg("Perch", "Beginner Lure");
		Reg("Окунь", "Beginner Lure");
		Reg("Triggerfish", "Beginner Lure");
		Reg("TitanTriggerFish", "Beginner Lure");
		Reg("Спинорог", "Beginner Lure");
		Reg("Goldfish", "Beginner Lure");
		Reg("Золотая рыбка", "Beginner Lure");
		Reg("Cod", "Beginner Lure");
		Reg("Треска", "Beginner Lure");
		Reg("Goby", "Beginner Lure");
		Reg("Бычок", "Beginner Lure");
		Reg("Catfish", "Standard Lure");
		Reg("Сом", "Standard Lure");
		Reg("Clownfish", "Standard Lure");
		Reg("Рыба-клоун", "Standard Lure");
		Reg("Sea Urchin", "Standard Lure");
		Reg("SeaUrchin", "Standard Lure");
		Reg("Морской еж", "Standard Lure");
		Reg("Yellow Boxfish", "Standard Lure");
		Reg("YellowBoxFish", "Standard Lure");
		Reg("Кузовок", "Standard Lure");
		Reg("Needlefish", "Standard Lure");
		Reg("Рыба-игла", "Standard Lure");
		Reg("Angelfish", "Standard Lure");
		Reg("AngelFish", "Standard Lure");
		Reg("Скалярия", "Standard Lure");
		Reg("Bluegill", "Standard Lure");
		Reg("Синежаберник", "Standard Lure");
		Reg("Bowlfish", "Standard Lure");
		Reg("BowlAndFish", "Standard Lure");
		Reg("Рыба-шар", "Standard Lure");
		Reg("Seahorse", "Standard Lure");
		Reg("Морской конек", "Standard Lure");
		Reg("Bass", "Professional Lure");
		Reg("Басс", "Professional Lure");
		Reg("Eel", "Professional Lure");
		Reg("Угорь", "Professional Lure");
		Reg("Red Snapper", "Professional Lure");
		Reg("RedSnapper", "Professional Lure");
		Reg("Красный луциан", "Professional Lure");
		Reg("Sengarat", "Professional Lure");
		Reg("Сенгарат", "Professional Lure");
		Reg("Halibut", "Professional Lure");
		Reg("Палтус", "Professional Lure");
		Reg("Flying Fish", "Professional Lure");
		Reg("FlyingFish", "Professional Lure");
		Reg("Летучая рыба", "Professional Lure");
		Reg("Voxelfish", "Professional Lure");
		Reg("VoxelFish", "Professional Lure");
		Reg("Воксельная рыба", "Professional Lure");
		Reg("Parrotfish", "Professional Lure");
		Reg("Рыба-попугай", "Professional Lure");
		Reg("Dripper", "Professional Lure");
		Reg("DripFish", "Professional Lure");
		Reg("Дриппер", "Professional Lure");
		Reg("Tigerfish", "Professional Lure");
		Reg("Тигровая рыба", "Professional Lure");
		Reg("Sunfish", "Beginner Boss Lure");
		Reg("Рыба-луна", "Beginner Boss Lure");
		Reg("The Old Pike", "Beginner Boss Lure");
		Reg("TheOldPike", "Beginner Boss Lure");
		Reg("Старый пайк", "Beginner Boss Lure");
		Reg("Blue Shark", "Standard Boss Lure");
		Reg("BlueShark", "Standard Boss Lure");
		Reg("Голубая акула", "Standard Boss Lure");
		Reg("Tuna", "Professional Boss Lure");
		Reg("Тунец", "Professional Boss Lure");
		Reg("Pufferfish", "Carrot (NPC Quest)");
		Reg("Иглобрюх", "Carrot (NPC Quest)");
		Reg("Spider Crab", "Empty Beer Can");
		Reg("SpiderCrab", "Empty Beer Can");
		Reg("Краб-паук", "Empty Beer Can");
		Reg("Giant Piranha", "Modified Leech");
		Reg("GiantPiranha", "Modified Leech");
		Reg("Гигантская пиранья", "Modified Leech");
		Reg("Albatross", "Tuna (Meat)");
		Reg("Альбатрос", "Tuna (Meat)");
		Reg("Bowhead Whale", "Lava Event Boss");
		Reg("BowheadWhale", "Lava Event Boss");
		Reg("Гренландский кит", "Lava Event Boss");
		Reg("FootSnail", "Wild Fauna (Catch)");
		Reg("Улитка", "Wild Fauna (Catch)");
	}

	private void Awake()
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1. General", "Enabled", true, "Enable BaitIndex integration in the native Tab Journal.");
		RevealUndiscovered = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Display", "RevealUndiscovered", true, "Reveal required baits even for undiscovered fish.");
		try
		{
			Harmony val = new Harmony("com.howToFish.baitindex");
			val.PatchAll();
			Log.LogInfo((object)"BaitIndex v1.0.1 initialized! Official Guide Bait Index active.");
		}
		catch (Exception ex)
		{
			Log.LogError((object)("BaitIndex Harmony error: " + ex));
		}
	}

	public static string GetOfficialBaitString(Creature creature)
	{
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)creature == (Object)null)
		{
			return null;
		}
		string name = ((Object)creature).name;
		if (!string.IsNullOrEmpty(name) && _guideBaitMap.ContainsKey(name))
		{
			return _guideBaitMap[name];
		}
		try
		{
			string name2 = ((Item)creature).GetName();
			if (!string.IsNullOrEmpty(name2) && _guideBaitMap.ContainsKey(name2))
			{
				return _guideBaitMap[name2];
			}
		}
		catch
		{
		}
		if ((int)creature.BossType != 0 || creature.BossHpMultiplier > 1f)
		{
			string text = ((Object)creature).name.ToLower();
			if (text.Contains("crab"))
			{
				return "Empty Beer Can";
			}
			if (text.Contains("pike") || text.Contains("sunfish"))
			{
				return "Beginner Boss Lure";
			}
			if (text.Contains("shark"))
			{
				return "Standard Boss Lure";
			}
			if (text.Contains("tuna"))
			{
				return "Professional Boss Lure";
			}
			return "Boss Lure";
		}
		return "Standard Lure";
	}
}
[HarmonyPatch(typeof(JournalSlot), "SetCreature")]
public static class JournalSlot_SetCreature_Patch
{
	private static FieldInfo _worthField = typeof(JournalSlot).GetField("_worthText", BindingFlags.Instance | BindingFlags.NonPublic);

	private static FieldInfo _filterField = typeof(JournalSlot).GetField("_filter", BindingFlags.Instance | BindingFlags.NonPublic);

	private static FieldInfo _dripTextField = typeof(JournalSlot).GetField("_dripText", BindingFlags.Instance | BindingFlags.NonPublic);

	public static void Postfix(JournalSlot __instance, Creature creature)
	{
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Expected O, but got Unknown
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0301: Unknown result type (might be due to invalid IL or missing references)
		//IL_0318: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_038e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0353: Unknown result type (might be due to invalid IL or missing references)
		//IL_0363: Unknown result type (might be due to invalid IL or missing references)
		//IL_0373: Unknown result type (might be due to invalid IL or missing references)
		if (!BaitIndexPlugin.ModEnabled.Value || (Object)(object)__instance == (Object)null)
		{
			return;
		}
		if (_worthField == null)
		{
			_worthField = typeof(JournalSlot).GetField("_worthText", BindingFlags.Instance | BindingFlags.NonPublic);
		}
		if (_filterField == null)
		{
			_filterField = typeof(JournalSlot).GetField("_filter", BindingFlags.Instance | BindingFlags.NonPublic);
		}
		if (_dripTextField == null)
		{
			_dripTextField = typeof(JournalSlot).GetField("_dripText", BindingFlags.Instance | BindingFlags.NonPublic);
		}
		TextMeshProUGUI val = (TextMeshProUGUI)((_worthField != null) ? /*isinst with value type is only supported in some contexts*/: null);
		Transform val2 = (((Object)(object)val != (Object)null) ? ((TMP_Text)val).transform.parent : ((Component)__instance).transform);
		Transform val3 = val2.Find("BaitIndexText");
		TextMeshProUGUI val4 = null;
		if ((Object)(object)creature == (Object)null)
		{
			if ((Object)(object)val3 != (Object)null)
			{
				((Component)val3).gameObject.SetActive(false);
			}
			return;
		}
		try
		{
			MeshFilter val5 = (MeshFilter)((_filterField != null) ? /*isinst with value type is only supported in some contexts*/: null);
			DripText val6 = (DripText)((_dripTextField != null) ? /*isinst with value type is only supported in some contexts*/: null);
			bool flag = SaveManager.GetSavedCreature(creature)?.BeenKilled ?? false;
			bool flag2 = (int)creature.BossType != 0 || creature.BossHpMultiplier > 1f;
			bool flag3 = BaitIndexPlugin.CurrentViewMode == JournalViewMode.SuperCreatures;
			if ((Object)(object)val5 != (Object)null)
			{
				if (flag3 && !flag2 && (Object)(object)((Item)creature).DripMesh != (Object)null)
				{
					val5.mesh = ((Item)creature).DripMesh;
					if ((Object)(object)val6 != (Object)null)
					{
						val6.SetDrip(true);
					}
				}
				else
				{
					val5.mesh = ((Item)creature).Mesh;
					if ((Object)(object)val6 != (Object)null)
					{
						val6.SetDrip(false);
					}
				}
			}
			if ((Object)(object)val3 == (Object)null)
			{
				GameObject val7 = new GameObject("BaitIndexText");
				val7.transform.SetParent(val2, false);
				val4 = val7.AddComponent<TextMeshProUGUI>();
				if ((Object)(object)val != (Object)null)
				{
					((TMP_Text)val4).font = ((TMP_Text)val).font;
					((TMP_Text)val4).fontSharedMaterial = ((TMP_Text)val).fontSharedMaterial;
				}
				((TMP_Text)val4).fontSize = 13f;
				((TMP_Text)val4).fontStyle = (FontStyles)1;
				((TMP_Text)val4).alignment = (TextAlignmentOptions)514;
				((TMP_Text)val4).overflowMode = (TextOverflowModes)0;
				((TMP_Text)val4).richText = true;
				RectTransform rectTransform = ((TMP_Text)val4).rectTransform;
				rectTransform.anchorMin = new Vector2(0.5f, 0f);
				rectTransform.anchorMax = new Vector2(0.5f, 0f);
				rectTransform.pivot = new Vector2(0.5f, 1f);
				rectTransform.sizeDelta = new Vector2(185f, 26f);
				if ((Object)(object)val != (Object)null)
				{
					rectTransform.anchoredPosition = new Vector2(((TMP_Text)val).rectTransform.anchoredPosition.x, ((TMP_Text)val).rectTransform.anchoredPosition.y - 15f);
				}
				else
				{
					rectTransform.anchoredPosition = new Vector2(0f, -19f);
				}
			}
			else
			{
				val4 = ((Component)val3).GetComponent<TextMeshProUGUI>();
				((TMP_Text)val4).fontSize = 13f;
				((TMP_Text)val4).fontStyle = (FontStyles)1;
				((Component)val3).gameObject.SetActive(true);
			}
			if (!flag && !BaitIndexPlugin.RevealUndiscovered.Value)
			{
				((TMP_Text)val4).text = "<color=#888899>Bait: ???</color>";
				return;
			}
			string officialBaitString = BaitIndexPlugin.GetOfficialBaitString(creature);
			if (flag2)
			{
				((TMP_Text)val4).text = $"<color=#FF6B6B><b>Boss: {officialBaitString}</b></color>";
				return;
			}
			if (officialBaitString.Contains("Quest") || officialBaitString.Contains("Fauna") || officialBaitString.Contains("Beer") || officialBaitString.Contains("Leech") || officialBaitString.Contains("Tuna"))
			{
				((TMP_Text)val4).text = $"<color=#FFD54F><b>Special:</b></color> <color=#FFE082><b>{officialBaitString}</b></color>";
				return;
			}
			string text = (flag3 ? "Super: " : "Bait: ");
			string text2 = (flag3 ? "#FFD700" : "#FFD54F");
			string text3 = (flag3 ? "#FFE082" : "#8CD4FF");
			((TMP_Text)val4).text = $"<color={text2}><b>{text}</b></color><color={text3}><b>{officialBaitString}</b></color>";
		}
		catch (Exception ex)
		{
			if (BaitIndexPlugin.Log != null)
			{
				BaitIndexPlugin.Log.LogError((object)("JournalSlot_SetCreature_Patch error: " + ex));
			}
		}
	}
}
[HarmonyPatch(typeof(ThinkingUI), "Update")]
public static class ThinkingUI_Update_Patch
{
	private static float _lastToggleTime = 0f;

	private static MethodInfo _updateJournalMethod = typeof(ThinkingUI).GetMethod("UpdateJournal", BindingFlags.Instance | BindingFlags.NonPublic);

	private static MethodInfo _setProgressTextsMethod = typeof(ThinkingUI).GetMethod("SetProgressTexts", BindingFlags.Instance | BindingFlags.NonPublic);

	public static void Postfix(ThinkingUI __instance)
	{
		if (!BaitIndexPlugin.ModEnabled.Value || (Object)(object)__instance == (Object)null || !PlayerThinking.IsThinking || !(Time.unscaledTime - _lastToggleTime > 0.25f))
		{
			return;
		}
		bool flag = false;
		try
		{
			if (Input.GetKeyDown((KeyCode)113) || Input.GetKeyDown((KeyCode)101) || Input.GetKeyDown((KeyCode)32))
			{
				flag = true;
			}
		}
		catch
		{
		}
		if (flag)
		{
			_lastToggleTime = Time.unscaledTime;
			ToggleJournalMode(__instance);
		}
	}

	public static void ToggleJournalMode(ThinkingUI ui)
	{
		BaitIndexPlugin.CurrentViewMode = ((BaitIndexPlugin.CurrentViewMode == JournalViewMode.Regular) ? JournalViewMode.SuperCreatures : JournalViewMode.Regular);
		if (!((Object)(object)ui != (Object)null))
		{
			return;
		}
		if (_updateJournalMethod == null)
		{
			_updateJournalMethod = typeof(ThinkingUI).GetMethod("UpdateJournal", BindingFlags.Instance | BindingFlags.NonPublic);
		}
		if (_setProgressTextsMethod == null)
		{
			_setProgressTextsMethod = typeof(ThinkingUI).GetMethod("SetProgressTexts", BindingFlags.Instance | BindingFlags.NonPublic);
		}
		try
		{
			if (_updateJournalMethod != null && _updateJournalMethod.Invoke(ui, null) is IEnumerator enumerator)
			{
				((MonoBehaviour)ui).StartCoroutine(enumerator);
			}
			if (_setProgressTextsMethod != null)
			{
				_setProgressTextsMethod.Invoke(ui, null);
			}
		}
		catch
		{
		}
	}
}
[HarmonyPatch(typeof(ThinkingUI), "SetProgressTexts")]
public static class ThinkingUI_SetProgressTexts_Patch
{
	private static FieldInfo _progressTextField = typeof(ThinkingUI).GetField("_progressText", BindingFlags.Instance | BindingFlags.NonPublic);

	private static FieldInfo _dripProgressTextField = typeof(ThinkingUI).GetField("_dripProgressText", BindingFlags.Instance | BindingFlags.NonPublic);

	public static void Postfix(ThinkingUI __instance)
	{
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: 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)
		if (!BaitIndexPlugin.ModEnabled.Value || (Object)(object)__instance == (Object)null)
		{
			return;
		}
		try
		{
			if (_progressTextField == null)
			{
				_progressTextField = typeof(ThinkingUI).GetField("_progressText", BindingFlags.Instance | BindingFlags.NonPublic);
			}
			if (_dripProgressTextField == null)
			{
				_dripProgressTextField = typeof(ThinkingUI).GetField("_dripProgressText", BindingFlags.Instance | BindingFlags.NonPublic);
			}
			TextMeshProUGUI val = (TextMeshProUGUI)((_progressTextField != null) ? /*isinst with value type is only supported in some contexts*/: null);
			TextMeshProUGUI val2 = (TextMeshProUGUI)((_dripProgressTextField != null) ? /*isinst with value type is only supported in some contexts*/: null);
			bool flag = BaitIndexPlugin.CurrentViewMode == JournalViewMode.SuperCreatures;
			int num = GameInfo.KilledCreaturesCount(false);
			int num2 = GameInfo.KilledCreaturesCount(true);
			int allCreatureCount = GameInfo.AllCreatureCount;
			if ((Object)(object)val != (Object)null)
			{
				((TMP_Text)val).alignment = (TextAlignmentOptions)514;
				((TMP_Text)val).rectTransform.anchoredPosition = new Vector2(245f, ((TMP_Text)val).rectTransform.anchoredPosition.y);
				((TMP_Text)val).rectTransform.sizeDelta = new Vector2(850f, 48f);
				((TMP_Text)val).fontSize = 17.5f;
				((TMP_Text)val).fontStyle = (FontStyles)1;
				((TMP_Text)val).overflowMode = (TextOverflowModes)0;
				string text = ((!flag) ? "<color=#FFD700><b>[▶ REGULAR FISH]</b></color>" : "<color=#888888>[REGULAR FISH]</color>");
				string text2 = (flag ? "<color=#FFD700><b>[▶ SUPER CREATURES]</b></color>" : "<color=#888888>[SUPER CREATURES]</color>");
				((TMP_Text)val).text = $"{text} <color=#FFD700><b>{num} / {allCreatureCount}</b></color>      <color=#8CD4FF><b>[Q ⇄]</b></color>      {text2} <color=#FFD700><b>{num2} / {allCreatureCount}</b></color>";
			}
			if ((Object)(object)val2 != (Object)null)
			{
				((TMP_Text)val2).text = "";
			}
		}
		catch
		{
		}
	}
}