Decompiled source of OmtrtaFishRadarFix v1.0.0

plugins/OmtrtaFishRadarFix.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using OneMapToRuleThemAll;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("OmtrtaFishRadarFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("OmtrtaFishRadarFix")]
[assembly: AssemblyTitle("OmtrtaFishRadarFix")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace OmtrtaFishRadarFix
{
	[BepInPlugin("cybrp.omtrta_fish_radar_fix", "OMTRTA Fish Radar Fix", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "cybrp.omtrta_fish_radar_fix";

		public const string PluginName = "OMTRTA Fish Radar Fix";

		public const string PluginVersion = "1.0.0";

		private void Awake()
		{
			//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_0021: Expected O, but got Unknown
			Harmony.CreateAndPatchAll(typeof(FishAwakePatch), (string)null);
			GameObject val = new GameObject("OmtrtaFishRadarFix_Scanner");
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<FishRadarScanner>().Begin(((BaseUnityPlugin)this).Logger);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"OMTRTA Fish Radar Fix 1.0.0 loaded");
		}
	}
	[HarmonyPatch(typeof(Fish), "Awake")]
	internal static class FishAwakePatch
	{
		private static void Postfix(Fish __instance)
		{
			FishRadarAttach.TryAttach(__instance);
		}
	}
	internal sealed class FishRadarScanner : MonoBehaviour
	{
		private ManualLogSource _log;

		public void Begin(ManualLogSource log)
		{
			_log = log;
			((MonoBehaviour)this).StartCoroutine(ScanWhenReady());
		}

		private IEnumerator ScanWhenReady()
		{
			while ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				yield return null;
			}
			yield return (object)new WaitForSeconds(2f);
			int num = FishRadarAttach.ScanExistingFish();
			ManualLogSource log = _log;
			if (log != null)
			{
				log.LogInfo((object)$"[OMTRTA Fish Radar Fix] initial scan attached radar to {num} fish");
			}
		}
	}
	internal static class FishRadarAttach
	{
		internal static void TryAttach(Fish fish)
		{
			if (!((Object)(object)fish == (Object)null))
			{
				GameObject gameObject = ((Component)fish).gameObject;
				if (!((Object)(object)gameObject == (Object)null))
				{
					AttachIfTracked(gameObject);
				}
			}
		}

		internal static int ScanExistingFish()
		{
			int num = 0;
			Fish[] array = Object.FindObjectsByType<Fish>((FindObjectsSortMode)0);
			foreach (Fish val in array)
			{
				if (!((Object)(object)val == (Object)null) && AttachIfTracked(((Component)val).gameObject))
				{
					num++;
				}
			}
			return num;
		}

		private static bool AttachIfTracked(GameObject go)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			if (!RadarConfig.ClientActive)
			{
				return false;
			}
			IdentificationResult val = WorldObjectIdentification.IdentifyCreature(go);
			if (!((IdentificationResult)(ref val)).IsTracked || val.RadarKeyword == null)
			{
				return false;
			}
			if ((Object)(object)go.GetComponent<RadarPinComponent>() != (Object)null)
			{
				return false;
			}
			go.AddComponent<RadarPinComponent>().Initialize(val.RadarKeyword);
			return true;
		}
	}
}