using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Unity.IL2CPP;
using Fishing;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Riverboat.Players;
using Riverboat.UI;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HabitatInfo")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HabitatInfo")]
[assembly: AssemblyTitle("HabitatInfo")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace HabitatInfo
{
[BepInPlugin("com.habitat.info", "HabitatInfo", "1.0.3")]
public class Plugin : BasePlugin
{
public static Plugin? Instance;
public static string CurrentTags = "";
public override void Load()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
Instance = this;
((BasePlugin)this).Log.LogInfo((object)"HabitatInfo loaded!");
Harmony val = new Harmony("com.habitat.info");
val.PatchAll();
}
public static string CleanTagName(string raw)
{
raw = Regex.Unescape(raw);
raw = Regex.Replace(raw, "<.*?>", "");
string[] array = new string[5] { " - ", " — ", " – ", " — ", " ÔÇô " };
string[] array2 = array;
foreach (string value in array2)
{
int num = raw.IndexOf(value);
if (num >= 0)
{
raw = raw.Substring(0, num);
break;
}
}
return raw.TrimEnd('-', ' ').Trim();
}
public static string LoadTagsFromArea(FishingArea area)
{
try
{
MethodInfo method = typeof(FishingArea).GetMethod("get_EnvironmentTags", BindingFlags.Instance | BindingFlags.Public);
if (method != null)
{
object obj = method.Invoke(area, null);
if (obj != null)
{
Type type = obj.GetType();
int num = (int)(type.GetProperty("Count")?.GetValue(obj) ?? ((object)0));
PropertyInfo property = type.GetProperty("Item");
List<string> list = new List<string>();
for (int i = 0; i < num; i++)
{
object obj2 = property?.GetValue(obj, new object[1] { i });
if (obj2 == null || obj2.GetType().GetProperty("TagIcon", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj2) == null)
{
continue;
}
string text = null;
try
{
string text2 = obj2.GetType().GetMethod("GetLocalizedName", BindingFlags.Instance | BindingFlags.Public)?.Invoke(obj2, null)?.ToString();
if (!string.IsNullOrEmpty(text2))
{
text = CleanTagName(text2);
}
}
catch
{
}
if (string.IsNullOrEmpty(text))
{
text = obj2.GetType().GetProperty("tagName", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj2)?.ToString();
}
if (!string.IsNullOrEmpty(text))
{
list.Add(text);
}
}
if (list.Count > 0)
{
return string.Join(" | ", list);
}
}
}
}
catch
{
}
return "";
}
public static bool IsLocalPlayer(PlayerCasting instance)
{
try
{
PropertyInfo property = typeof(PlayerCasting).GetProperty("IsLocalPlayer", BindingFlags.Instance | BindingFlags.Public);
if (property != null)
{
return (bool)(property.GetValue(instance) ?? ((object)false));
}
}
catch
{
}
return false;
}
}
[HarmonyPatch(typeof(PlayerCasting), "Update")]
public class PlayerCastingUpdatePatch
{
private static bool _wasInWater;
private static void Postfix(PlayerCasting __instance)
{
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!Plugin.IsLocalPlayer(__instance))
{
return;
}
if (!__instance.HasBobber() && _wasInWater)
{
_wasInWater = false;
Plugin.CurrentTags = "";
GameNotification instance = GameNotification.Instance;
if (instance != null)
{
instance.HideNotification();
}
return;
}
Bobber bobber = __instance.Bobber;
if ((Object)(object)bobber == (Object)null)
{
return;
}
bool flag = bobber.IsInWater();
if (flag && !_wasInWater)
{
_wasInWater = true;
FishingManager val = Object.FindObjectOfType<FishingManager>();
if ((Object)(object)val != (Object)null)
{
FishingArea val2 = val.FindFishingArea(((Component)bobber).transform.position);
if ((Object)(object)val2 != (Object)null)
{
Plugin.CurrentTags = Plugin.LoadTagsFromArea(val2);
}
}
string text = (string.IsNullOrEmpty(Plugin.CurrentTags) ? "Loading habitat..." : Plugin.CurrentTags);
GameNotification instance2 = GameNotification.Instance;
if (instance2 != null)
{
instance2.ShowPersistentNotification(text);
}
}
else if (!flag && _wasInWater)
{
_wasInWater = false;
Plugin.CurrentTags = "";
GameNotification instance3 = GameNotification.Instance;
if (instance3 != null)
{
instance3.HideNotification();
}
}
}
catch
{
}
}
}
}