Decompiled source of HabitatInfo v1.0.0

HabitatInfo.dll

Decompiled 18 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
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.0")]
	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 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)
							{
								string 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 "";
		}
	}
	[HarmonyPatch(typeof(PlayerCasting), "Update")]
	public class PlayerCastingUpdatePatch
	{
		private static bool _wasInWater;

		private static void Postfix(PlayerCasting __instance)
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				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
			{
			}
		}
	}
}