Decompiled source of FishingZoneHighlighter v1.0.1

BepInEx/plugins/OldMarket.FishingZoneHighlighter.dll

Decompiled 3 days ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BoatMapPlayerMarker")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BoatMapPlayerMarker")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("94ffc8de-7eaa-4178-aeea-97b3eda1f4dc")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace OldMarket.FishingZoneHighlighter;

[BepInPlugin("oldmarket.fishingzonehighlighter", "Fishing Zone Highlighter", "1.0.1")]
public class FishingZoneHighlighterPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "oldmarket.fishingzonehighlighter";

	public const string PluginName = "Fishing Zone Highlighter";

	public const string PluginVersion = "1.0.1";

	internal static ConfigEntry<Key> ToggleKey;

	private void Awake()
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		ToggleKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Keybinds", "ToggleKey", (Key)102, "Key to toggle the display of the fishing zone marker");
		GameObject val = new GameObject("FishingZoneHighlighterController");
		Object.DontDestroyOnLoad((Object)(object)val);
		((Object)val).hideFlags = (HideFlags)61;
		val.AddComponent<FishingZoneHighlighterController>();
	}
}
public class FishingZoneHighlighterController : MonoBehaviour
{
	private readonly Dictionary<FishingZone, GameObject> _markers = new Dictionary<FishingZone, GameObject>();

	private const float MarkerHeight = 2f;

	private const float MarkerSize = 1f;

	private bool _markersVisible = false;

	private bool _markersInitialized = false;

	private void Awake()
	{
		Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

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

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

	private void Update()
	{
		HandleToggleInput();
		if (!_markersInitialized)
		{
			GameManager instance = GameManager.Instance;
			if ((Object)(object)instance != (Object)null && instance.IsWorldLoaded())
			{
				_markersInitialized = true;
				ScanFishingZones();
				UpdateMarkersActiveState();
			}
		}
	}

	private void HandleToggleInput()
	{
		//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_0025: Invalid comparison between Unknown and I4
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		Keyboard current = Keyboard.current;
		if (current == null)
		{
			return;
		}
		ConfigEntry<Key> toggleKey = FishingZoneHighlighterPlugin.ToggleKey;
		Key val = (Key)((toggleKey != null) ? ((int)toggleKey.Value) : 0);
		if ((int)val != 0)
		{
			KeyControl val2 = current[val];
			if (val2 != null && ((ButtonControl)val2).wasPressedThisFrame)
			{
				_markersVisible = !_markersVisible;
				UpdateMarkersActiveState();
			}
		}
	}

	private void ScanFishingZones()
	{
		FishingZone[] array = Object.FindObjectsOfType<FishingZone>(true);
		if (array == null || array.Length == 0)
		{
			return;
		}
		FishingZone[] array2 = array;
		foreach (FishingZone val in array2)
		{
			if (!((Object)(object)val == (Object)null) && !_markers.ContainsKey(val))
			{
				GameObject value = CreateMarkerForZone(val);
				_markers[val] = value;
			}
		}
	}

	private GameObject CreateMarkerForZone(FishingZone zone)
	{
		//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_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_004d: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Expected O, but got Unknown
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
		((Object)val).name = "FishingZoneMarker";
		val.layer = 0;
		val.transform.position = ((Component)zone).transform.position + Vector3.up * 2f;
		val.transform.localScale = Vector3.one * 1f;
		val.transform.SetParent(((Component)zone).transform, true);
		Collider component = val.GetComponent<Collider>();
		if ((Object)(object)component != (Object)null)
		{
			Object.Destroy((Object)(object)component);
		}
		Renderer component2 = val.GetComponent<Renderer>();
		if ((Object)(object)component2 != (Object)null)
		{
			Material val2 = new Material(component2.sharedMaterial);
			val2.color = new Color(0.2f, 1f, 1f, 1f);
			val2.EnableKeyword("_EMISSION");
			val2.SetColor("_EmissionColor", new Color(0.2f, 1f, 1f));
			component2.material = val2;
			component2.shadowCastingMode = (ShadowCastingMode)0;
			component2.receiveShadows = false;
		}
		val.SetActive(_markersVisible);
		return val;
	}

	private void UpdateMarkersActiveState()
	{
		foreach (KeyValuePair<FishingZone, GameObject> marker in _markers)
		{
			GameObject value = marker.Value;
			if ((Object)(object)value != (Object)null)
			{
				value.SetActive(_markersVisible);
			}
		}
	}

	private void ClearAllMarkers()
	{
		foreach (KeyValuePair<FishingZone, GameObject> marker in _markers)
		{
			if ((Object)(object)marker.Value != (Object)null)
			{
				Object.Destroy((Object)(object)marker.Value);
			}
		}
		_markers.Clear();
	}
}