Decompiled source of FishingZoneHighlighter v1.0.2

BepInEx/plugins/OldMarket.FishingZoneHighlighter.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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.IgnoreSymbolStoreSequencePoints)]
[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.2")]
public class FishingZoneHighlighterPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "oldmarket.fishingzonehighlighter";

	public const string PluginName = "Fishing Zone Highlighter";

	public const string PluginVersion = "1.0.2";

	internal static ConfigEntry<Key> ToggleKey;

	private void Awake()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		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)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;

	private bool _markersInitialized;

	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_0016: 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)
		//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)
		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_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: 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_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		GameObject obj = GameObject.CreatePrimitive((PrimitiveType)0);
		((Object)obj).name = "FishingZoneMarker";
		obj.layer = LayerMask.NameToLayer("Default");
		obj.transform.position = ((Component)zone).transform.position + Vector3.up * 2f;
		obj.transform.localScale = Vector3.one * 1f;
		obj.transform.SetParent(((Component)zone).transform, true);
		Collider component = obj.GetComponent<Collider>();
		if ((Object)(object)component != (Object)null)
		{
			Object.Destroy((Object)(object)component);
		}
		Renderer component2 = obj.GetComponent<Renderer>();
		if ((Object)(object)component2 != (Object)null)
		{
			SetupMarkerMaterial(component2, Color.magenta);
		}
		obj.SetActive(_markersVisible);
		return obj;
	}

	private void SetupMarkerMaterial(Renderer renderer, Color color)
	{
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if ((Object)(object)renderer == (Object)null)
			{
				return;
			}
			Material val = null;
			Renderer val2 = ((IEnumerable<Renderer>)Object.FindObjectsOfType<Renderer>()).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => (Object)(object)r != (Object)(object)renderer && (Object)(object)r.sharedMaterial != (Object)null));
			if ((Object)(object)val2 != (Object)null)
			{
				val = val2.sharedMaterial;
			}
			else if ((Object)(object)renderer.sharedMaterial != (Object)null)
			{
				val = renderer.sharedMaterial;
			}
			if (!((Object)(object)val == (Object)null))
			{
				Material val3 = new Material(val);
				if (val3.HasProperty("_MainTex"))
				{
					val3.SetTexture("_MainTex", (Texture)(object)Texture2D.whiteTexture);
				}
				if (val3.HasProperty("_BaseMap"))
				{
					val3.SetTexture("_BaseMap", (Texture)(object)Texture2D.whiteTexture);
				}
				Color val4 = color;
				val4.a = 1f;
				if (val3.HasProperty("_BaseColor"))
				{
					val3.SetColor("_BaseColor", val4);
				}
				else if (val3.HasProperty("_Color"))
				{
					val3.SetColor("_Color", val4);
				}
				Color val5 = color * 3f;
				val5.a = 1f;
				bool flag = false;
				if (val3.HasProperty("_EmissionColor"))
				{
					val3.EnableKeyword("_EMISSION");
					val3.SetColor("_EmissionColor", val5);
					flag = true;
				}
				if (!flag && val3.HasProperty("_EmissionColorLDR"))
				{
					val3.EnableKeyword("_EMISSION");
					val3.SetColor("_EmissionColorLDR", val5);
				}
				renderer.shadowCastingMode = (ShadowCastingMode)0;
				renderer.receiveShadows = false;
				if (val3.HasProperty("_Surface"))
				{
					val3.SetFloat("_Surface", 0f);
				}
				if (val3.HasProperty("_SrcBlend"))
				{
					val3.SetInt("_SrcBlend", 1);
				}
				if (val3.HasProperty("_DstBlend"))
				{
					val3.SetInt("_DstBlend", 0);
				}
				if (val3.HasProperty("_ZWrite"))
				{
					val3.SetInt("_ZWrite", 1);
				}
				val3.DisableKeyword("_ALPHATEST_ON");
				val3.DisableKeyword("_ALPHABlEND_ON");
				val3.DisableKeyword("_ALPHAPREMULTIPLY_ON");
				val3.renderQueue = 2000;
				renderer.material = val3;
			}
		}
		catch (Exception)
		{
		}
	}

	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();
	}
}