Decompiled source of AF TrackerRefine v1.0.0

AF_TrackerRefine.dll

Decompiled 34 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Kuraputi")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AF_TrackerRefine")]
[assembly: AssemblyTitle("AF_TrackerRefine")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
	[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 AF_TrackerRefine
{
	[BepInPlugin("Kuraputi.AF_TrackerRefine", "AF_TrackerRefine", "1.0.0")]
	public class AF_TrackerRefine : BaseUnityPlugin
	{
		internal static ConfigEntry<int> ScanRooms;

		internal static ConfigEntry<int> ValueBonus;

		internal static ConfigEntry<int> ExtractionBonus;

		internal static AF_TrackerRefine Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			BindConfig();
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		private void BindConfig()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			ScanRooms = ((BaseUnityPlugin)this).Config.Bind<int>("ValuableTracker", "ScanRooms", 2, new ConfigDescription("スキャンする範囲(半径の部屋数、0でエリア全体)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
			ValueBonus = ((BaseUnityPlugin)this).Config.Bind<int>("ValuableTracker", "ValueBonus", 10, new ConfigDescription("トラッカーで見つけた貴重品の値段の上乗せ(%)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			ExtractionBonus = ((BaseUnityPlugin)this).Config.Bind<int>("ExtractionTracker", "ExtractionBonus", 5, new ConfigDescription("道順を出した抽出場で稼いだお金の上乗せ(%、1%以上なら最低+1K)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		}

		internal void Patch()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0025: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
	[HarmonyPatch(typeof(ItemBattery), "Start")]
	internal static class BatteryPatch
	{
		private const int TrackerBars = 10;

		private static void Prefix(ItemBattery __instance)
		{
			if ((Object)(object)((Component)__instance).GetComponent<ItemTracker>() != (Object)null)
			{
				__instance.batteryBars = 10;
			}
		}
	}
	[HarmonyPatch(typeof(ExtractionPoint))]
	internal static class ExtractionBonusPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("StateComplete")]
		private static void Complete_Prefix(ExtractionPoint __instance, out int __state)
		{
			__state = Before(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch("StateComplete")]
		private static void Complete_Postfix(ExtractionPoint __instance, int __state)
		{
			After(__instance, __state);
		}

		[HarmonyPrefix]
		[HarmonyPatch("StateTaxReturn")]
		private static void TaxReturn_Prefix(ExtractionPoint __instance, out int __state)
		{
			__state = Before(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch("StateTaxReturn")]
		private static void TaxReturn_Postfix(ExtractionPoint __instance, int __state)
		{
			After(__instance, __state);
		}

		private static int Before(ExtractionPoint ep)
		{
			if (!ep.stateStart || ep.isShop || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return -1;
			}
			return SemiFunc.StatGetRunCurrency();
		}

		private static void After(ExtractionPoint ep, int before)
		{
			if (before < 0)
			{
				return;
			}
			int num = SemiFunc.StatGetRunCurrency() - before;
			if (num > 0 && ExtractionGuide.IsGuided(ep))
			{
				int value = AF_TrackerRefine.ExtractionBonus.Value;
				if (value > 0)
				{
					int num2 = Mathf.Max(1, Mathf.RoundToInt((float)(num * value) / 100f));
					SemiFunc.StatSetRunCurrency(SemiFunc.StatGetRunCurrency() + num2);
					CurrencyUI.instance.FetchCurrency();
					AF_TrackerRefine.Logger.LogInfo((object)$"[Tracker] Extraction bonus +{num2}K ({value}% of {num}K)");
				}
			}
		}
	}
	internal class ExtractionGuide : MonoBehaviour
	{
		private const float RefreshTime = 0.5f;

		private const float LineWidth = 0.6f;

		private static readonly Color IdleColor = new Color(0.2f, 1f, 0.95f, 0.85f);

		private static readonly Color ActiveColor = new Color(0.2f, 1f, 0.95f, 1f);

		private static readonly Color FadedColor = new Color(0.2f, 1f, 0.95f, 0.25f);

		private static ExtractionGuide? instance;

		private readonly Dictionary<ExtractionPoint, LineRenderer> lines = new Dictionary<ExtractionPoint, LineRenderer>();

		private readonly HashSet<ExtractionPoint> guided = new HashSet<ExtractionPoint>();

		private NavMeshPath path;

		private Material mat;

		private float timer;

		internal static bool Running => (Object)(object)instance != (Object)null;

		internal static bool IsGuided(ExtractionPoint ep)
		{
			if ((Object)(object)instance != (Object)null)
			{
				return instance.guided.Contains(ep);
			}
			return false;
		}

		internal static void Begin(Vector3[] targets)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)instance != (Object)null))
			{
				instance = new GameObject("AF_ExtractionGuide").AddComponent<ExtractionGuide>();
				instance.Setup(targets);
			}
		}

		private void Awake()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			path = new NavMeshPath();
			mat = new Material(Shader.Find("Sprites/Default"));
		}

		private void Setup(Vector3[] targets)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			ExtractionPoint[] source = Object.FindObjectsByType<ExtractionPoint>((FindObjectsSortMode)0);
			foreach (Vector3 target in targets)
			{
				ExtractionPoint val = source.OrderBy((ExtractionPoint p) => Vector3.Distance(((Component)p).transform.position, target)).FirstOrDefault();
				if (!((Object)(object)val == (Object)null) && !(Vector3.Distance(((Component)val).transform.position, target) > 1f) && !guided.Contains(val))
				{
					guided.Add(val);
					lines[val] = CreateLine(((Object)val).name);
				}
			}
		}

		private void OnDestroy()
		{
			instance = null;
			if ((Object)(object)mat != (Object)null)
			{
				Object.Destroy((Object)(object)mat);
			}
		}

		private void Update()
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			Map val = Map.Instance;
			if ((Object)(object)val == (Object)null || !val.Active || (Object)(object)PlayerController.instance == (Object)null)
			{
				return;
			}
			timer -= Time.deltaTime;
			if (timer > 0f)
			{
				return;
			}
			timer = 0.5f;
			bool flag = lines.Keys.Any((ExtractionPoint ep) => (Object)(object)ep != (Object)null && IsActive(ep));
			Vector3 position = ((Component)PlayerController.instance).transform.position;
			foreach (ExtractionPoint item in lines.Keys.ToList())
			{
				if ((Object)(object)item == (Object)null || IsFinished(item))
				{
					if (lines.TryGetValue(item, out LineRenderer value) && (Object)(object)value != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)value).gameObject);
					}
					lines.Remove(item);
				}
				else
				{
					Color color = ((!flag) ? IdleColor : (IsActive(item) ? ActiveColor : FadedColor));
					DrawPath(lines[item], position, ((Component)item).transform.position, color);
				}
			}
		}

		private static bool IsActive(ExtractionPoint ep)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			State currentState = ep.currentState;
			if ((int)currentState != 2 && (int)currentState != 4 && (int)currentState != 6)
			{
				return (int)currentState == 8;
			}
			return true;
		}

		internal static bool IsFinished(ExtractionPoint ep)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			State currentState = ep.currentState;
			if ((int)currentState != 3 && (int)currentState != 7)
			{
				return (int)currentState == 9;
			}
			return true;
		}

		private LineRenderer CreateLine(string name)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			Transform overLayerParent = Map.Instance.OverLayerParent;
			GameObject val = new GameObject("AF_Guide_" + name);
			val.transform.SetParent(overLayerParent, false);
			val.layer = ((Component)overLayerParent).gameObject.layer;
			LineRenderer val2 = val.AddComponent<LineRenderer>();
			val2.useWorldSpace = false;
			((Renderer)val2).material = mat;
			val2.widthMultiplier = 0.6f * Map.Instance.Scale;
			val2.numCornerVertices = 2;
			val2.numCapVertices = 2;
			((Renderer)val2).sortingOrder = 10;
			val2.positionCount = 0;
			return val2;
		}

		private void DrawPath(LineRenderer lr, Vector3 from, Vector3 to, Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			lr.startColor = color;
			lr.endColor = color;
			NavMeshHit val = default(NavMeshHit);
			NavMeshHit val2 = default(NavMeshHit);
			if (!NavMesh.SamplePosition(from, ref val, 3f, -1) || !NavMesh.SamplePosition(to, ref val2, 5f, -1) || !NavMesh.CalculatePath(((NavMeshHit)(ref val)).position, ((NavMeshHit)(ref val2)).position, -1, path) || (int)path.status == 2)
			{
				lr.positionCount = 0;
				return;
			}
			Vector3[] corners = path.corners;
			lr.positionCount = corners.Length;
			for (int i = 0; i < corners.Length; i++)
			{
				lr.SetPosition(i, ToMap(corners[i]));
			}
		}

		private static Vector3 ToMap(Vector3 world)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_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_003a: Unknown result type (might be due to invalid IL or missing references)
			Map val = Map.Instance;
			Vector3 result = val.OverLayerParent.InverseTransformPoint(world * val.Scale + val.OverLayerParent.position);
			result.y = 0f;
			return result;
		}
	}
	internal class ExtractionPing : MonoBehaviour
	{
		private const float ShowTime = 3f;

		private const int ResultUsed = -2;

		private const int ResultEmpty = -1;

		private ItemTracker tracker;

		private float showTimer;

		private bool pressed;

		private void Awake()
		{
			tracker = ((Component)this).GetComponent<ItemTracker>();
		}

		private void Update()
		{
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				if (tracker.itemToggle.toggleState && !pressed)
				{
					pressed = true;
					Activate();
					tracker.itemToggle.ToggleItem(false, -1);
				}
				else if (!tracker.itemToggle.toggleState)
				{
					pressed = false;
				}
			}
			if (showTimer > 0f)
			{
				showTimer -= Time.deltaTime;
				if (showTimer <= 0f)
				{
					((Component)tracker.display).gameObject.SetActive(false);
					((TMP_Text)tracker.displayText).text = "--";
				}
			}
		}

		private void Activate()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (ExtractionGuide.Running)
			{
				SendResult(-2, (Vector3[])(object)new Vector3[0]);
				return;
			}
			ItemBattery itemBattery = tracker.itemBattery;
			if (itemBattery.batteryLifeInt <= 0)
			{
				SendResult(-1, (Vector3[])(object)new Vector3[0]);
				return;
			}
			Vector3 pos = ((Component)this).transform.position;
			List<ExtractionPoint> list = (from ep in Object.FindObjectsByType<ExtractionPoint>((FindObjectsSortMode)0)
				where (Object)(object)ep != (Object)null && !ep.isShop && !ExtractionGuide.IsFinished(ep)
				orderby Vector3.Distance(pos, ((Component)ep).transform.position)
				select ep).Take(itemBattery.batteryLifeInt).ToList();
			if (list.Count == 0)
			{
				SendResult(0, (Vector3[])(object)new Vector3[0]);
				return;
			}
			itemBattery.RemoveFullBar(list.Count);
			AF_TrackerRefine.Logger.LogInfo((object)$"[Tracker] Extraction guide to {list.Count} points (battery -{list.Count})");
			SendResult(list.Count, list.Select((ExtractionPoint ep) => ((Component)ep).transform.position).ToArray());
		}

		private void SendResult(int count, Vector3[] targets)
		{
			//IL_0036: 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)
			if (SemiFunc.IsMultiplayer())
			{
				tracker.photonView.RPC("GuideRPC", (RpcTarget)0, new object[2] { count, targets });
			}
			else
			{
				GuideRPC(count, targets);
			}
		}

		[PunRPC]
		private void GuideRPC(int count, Vector3[] targets, PhotonMessageInfo _info = default(PhotonMessageInfo))
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(_info))
			{
				((Component)tracker.display).gameObject.SetActive(true);
				showTimer = 3f;
				if (count <= 0)
				{
					string text = count switch
					{
						-1 => "X", 
						-2 => "USED", 
						_ => "0", 
					};
					tracker.soundTargetLost.Play(((Component)tracker.display).transform.position, 1f, 1f, 1f, 1f);
					tracker.DisplayColorOverride(text, Color.red, 3f);
				}
				else
				{
					tracker.soundTargetFound.Play(((Component)tracker.display).transform.position, 1f, 1f, 1f, 1f);
					tracker.DisplayColorOverride(count.ToString(), tracker.colorTargetFound, 3f);
					ExtractionGuide.Begin(targets);
				}
			}
		}
	}
	[HarmonyPatch(typeof(ItemTracker))]
	internal static class TrackerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void Start_Postfix(ItemTracker __instance)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)((Component)__instance).GetComponent<TrackerScan>() != (Object)null) && !((Object)(object)((Component)__instance).GetComponent<ExtractionPing>() != (Object)null))
			{
				if ((int)__instance.trackerType == 0)
				{
					((Component)__instance).gameObject.AddComponent<TrackerScan>();
				}
				else
				{
					((Component)__instance).gameObject.AddComponent<ExtractionPing>();
				}
				__instance.photonView.RefreshRpcMonoBehaviourCache();
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("Update")]
		private static bool Update_Prefix(ItemTracker __instance)
		{
			__instance.PhysGrabOverrides();
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("FixedUpdate")]
		private static bool FixedUpdate_Prefix(ItemTracker __instance)
		{
			return false;
		}
	}
	internal class TrackerScan : MonoBehaviour
	{
		private const float ShowTime = 3f;

		private const float PercentPerValuable = 2f;

		private ItemTracker tracker;

		private float showTimer;

		private bool scanned;

		private void Awake()
		{
			tracker = ((Component)this).GetComponent<ItemTracker>();
		}

		private void Update()
		{
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				if (tracker.itemToggle.toggleState && !scanned)
				{
					scanned = true;
					Scan();
					tracker.itemToggle.ToggleItem(false, -1);
				}
				else if (!tracker.itemToggle.toggleState)
				{
					scanned = false;
				}
			}
			if (showTimer > 0f)
			{
				showTimer -= Time.deltaTime;
				if (showTimer <= 0f)
				{
					((Component)tracker.display).gameObject.SetActive(false);
					((TMP_Text)tracker.displayText).text = "--";
				}
			}
		}

		private void Scan()
		{
			//IL_0034: 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)
			ItemBattery itemBattery = tracker.itemBattery;
			if (itemBattery.batteryLife <= 0f)
			{
				SendResult(-1, new int[0]);
				return;
			}
			Vector3 pos = ((Component)this).transform.position;
			float radius = (float)AF_TrackerRefine.ScanRooms.Value * LevelGenerator.ModuleWidth * LevelGenerator.TileSize;
			List<ValuableObject> list = (from v in Object.FindObjectsByType<ValuableObject>((FindObjectsSortMode)0)
				where (Object)(object)v != (Object)null && !v.discovered && (Object)(object)v.physGrabObject != (Object)null
				where radius <= 0f || Vector3.Distance(pos, ((Component)v).transform.position) <= radius
				orderby Vector3.Distance(pos, ((Component)v).transform.position)
				select v).ToList();
			int num = Mathf.Min(list.Count, Mathf.FloorToInt(itemBattery.batteryLife / 2f));
			if (num == 0 && list.Count > 0)
			{
				SendResult(-1, new int[0]);
				return;
			}
			list = list.Take(num).ToList();
			List<int> list2 = new List<int>();
			foreach (ValuableObject item in list)
			{
				if (item.Discover((State)0))
				{
					AddBonus(item);
					list2.Add(item.photonView.ViewID);
				}
			}
			float num2 = (float)list2.Count * 2f;
			if (num2 > 0f)
			{
				itemBattery.batteryLife = Mathf.Max(0f, itemBattery.batteryLife - num2);
			}
			AF_TrackerRefine.Logger.LogInfo((object)$"[Tracker] Scan found {list2.Count} valuables (radius {radius}m, battery -{num2}% -> {itemBattery.batteryLife}%)");
			SendResult(list2.Count, list2.ToArray());
		}

		private static void AddBonus(ValuableObject v)
		{
			float num = 1f + (float)AF_TrackerRefine.ValueBonus.Value / 100f;
			if (!(num <= 1f))
			{
				v.dollarValueOriginal = Mathf.Round(v.dollarValueOriginal * num);
				v.dollarValueCurrent = Mathf.Round(v.dollarValueCurrent * num);
				if (SemiFunc.IsMultiplayer())
				{
					v.photonView.RPC("DollarValueSetRPC", (RpcTarget)1, new object[1] { v.dollarValueCurrent });
				}
			}
		}

		private void SendResult(int count, int[] ids)
		{
			//IL_0036: 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)
			if (SemiFunc.IsMultiplayer())
			{
				tracker.photonView.RPC("ScanResultRPC", (RpcTarget)0, new object[2] { count, ids });
			}
			else
			{
				ScanResultRPC(count, ids);
			}
		}

		[PunRPC]
		private void ScanResultRPC(int count, int[] ids, PhotonMessageInfo _info = default(PhotonMessageInfo))
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			if (!SemiFunc.MasterOnlyRPC(_info))
			{
				return;
			}
			((Component)tracker.display).gameObject.SetActive(true);
			if (count < 0)
			{
				tracker.soundTargetLost.Play(((Component)tracker.display).transform.position, 1f, 1f, 1f, 1f);
				tracker.DisplayColorOverride("X", Color.red, 3f);
			}
			else if (count == 0)
			{
				tracker.soundTargetLost.Play(((Component)tracker.display).transform.position, 1f, 1f, 1f, 1f);
				tracker.DisplayColorOverride("0", Color.red, 3f);
			}
			else
			{
				tracker.soundTargetFound.Play(((Component)tracker.display).transform.position, 1f, 1f, 1f, 1f);
				tracker.DisplayColorOverride(count.ToString(), tracker.colorTargetFound, 3f);
			}
			showTimer = 3f;
			if (SemiFunc.IsMasterClientOrSingleplayer() || tracker.itemToggle.playerTogglePhotonID != SemiFunc.PhotonViewIDPlayerAvatarLocal())
			{
				return;
			}
			foreach (int num in ids)
			{
				PhotonView val = PhotonView.Find(num);
				PhysGrabObject val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<PhysGrabObject>() : null);
				if ((Object)(object)val2 != (Object)null)
				{
					ValuableDiscover.instance.New(val2, (State)0, (ValuableDiscoverCustom)null);
				}
			}
		}
	}
}