Decompiled source of ScanRarity v0.0.1

ScanRarity.dll

Decompiled 4 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ScanRarity")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ScanRarity")]
[assembly: AssemblyTitle("ScanRarity")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ScanRarity;

[HarmonyPatch(typeof(HUDManager), "UpdateScanNodes")]
public class HUDManagerPatch
{
	private static void Postfix(HUDManager __instance)
	{
		ScrapScanner.OnScanUpdate(__instance);
		if (Plugin.DisableVanillaScanDisplay.Value)
		{
			HideVanillaScrapLabels(__instance);
		}
	}

	private static void HideVanillaScrapLabels(HUDManager hud)
	{
		Dictionary<RectTransform, ScanNodeProperties> value = Traverse.Create((object)hud).Field("scanNodes").GetValue<Dictionary<RectTransform, ScanNodeProperties>>();
		if (value != null && hud.scanElements != null)
		{
			for (int i = 0; i < hud.scanElements.Length; i++)
			{
				RectTransform val = hud.scanElements[i];
				if (!((Object)(object)val == (Object)null) && value.TryGetValue(val, out var value2) && (Object)(object)value2 != (Object)null && value2.nodeType == 2 && ((Component)val).gameObject.activeSelf)
				{
					((Component)val).gameObject.SetActive(false);
				}
			}
		}
		if ((Object)(object)hud.scanInfoAnimator != (Object)null)
		{
			hud.scanInfoAnimator.SetBool("display", false);
		}
	}
}
public static class Localization
{
	public const string DefaultLanguage = "zh-CN";

	public const string FallbackLanguage = "en";

	public static string CurrentLanguage = "zh-CN";

	public static string ValueFormat = "{itemName} {value}";

	public static string DollarSign = "$";

	public static readonly Dictionary<string, string> ItemNames = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

	private static readonly Regex FieldRegex = new Regex("\"([A-Za-z0-9_]+)\"\\s*:\\s*\"((?:\\\\.|[^\"\\\\])*)\"", RegexOptions.Compiled);

	private static readonly Regex ItemRegex = new Regex("\"key\"\\s*:\\s*\"((?:\\\\.|[^\"\\\\])*)\"\\s*,\\s*\"value\"\\s*:\\s*\"((?:\\\\.|[^\"\\\\])*)\"", RegexOptions.Compiled);

	public static void Load(string language)
	{
		CurrentLanguage = (string.IsNullOrEmpty(language) ? "zh-CN" : language);
		ItemNames.Clear();
		ValueFormat = "{itemName} {value}";
		DollarSign = "$";
		if (!TryLoadFile(CurrentLanguage, out var json) && CurrentLanguage != "en")
		{
			Plugin.Log.LogWarning((object)("ScanRarity: language '" + CurrentLanguage + "' not found, falling back to 'en'"));
			TryLoadFile("en", out json);
		}
		if (json == null)
		{
			return;
		}
		try
		{
			string text = Parse(json);
			Plugin.Log.LogInfo((object)("ScanRarity: localization loaded '" + CurrentLanguage + "' (" + (text ?? "?") + ", " + ItemNames.Count + " item names)"));
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("ScanRarity: localization load error for '" + CurrentLanguage + "': " + ex.Message));
		}
	}

	private static string Parse(string json)
	{
		string result = null;
		foreach (Match item in FieldRegex.Matches(json))
		{
			string value = item.Groups[1].Value;
			string text = Unescape(item.Groups[2].Value);
			switch (value)
			{
			case "language_name":
				result = text;
				break;
			case "value_format":
				if (!string.IsNullOrEmpty(text))
				{
					ValueFormat = text;
				}
				break;
			case "dollar_sign":
				if (!string.IsNullOrEmpty(text))
				{
					DollarSign = text;
				}
				break;
			}
		}
		int num = json.IndexOf("\"items\"", StringComparison.Ordinal);
		string input = ((num >= 0) ? json.Substring(num) : "");
		foreach (Match item2 in ItemRegex.Matches(input))
		{
			string text2 = Unescape(item2.Groups[1].Value);
			string value2 = Unescape(item2.Groups[2].Value);
			if (!string.IsNullOrEmpty(text2))
			{
				ItemNames[text2] = value2;
			}
		}
		return result;
	}

	private static string Unescape(string s)
	{
		if (string.IsNullOrEmpty(s) || s.IndexOf('\\') < 0)
		{
			return s;
		}
		StringBuilder stringBuilder = new StringBuilder(s.Length);
		for (int i = 0; i < s.Length; i++)
		{
			char c = s[i];
			if (c == '\\' && i + 1 < s.Length)
			{
				i++;
				char c2 = s[i];
				switch (c2)
				{
				case 'n':
					stringBuilder.Append('\n');
					break;
				case 'r':
					stringBuilder.Append('\r');
					break;
				case 't':
					stringBuilder.Append('\t');
					break;
				case 'u':
				{
					if (i + 4 < s.Length && int.TryParse(s.Substring(i + 1, 4), NumberStyles.HexNumber, null, out var result))
					{
						stringBuilder.Append((char)result);
						i += 4;
					}
					else
					{
						stringBuilder.Append(c2);
					}
					break;
				}
				default:
					stringBuilder.Append(c2);
					break;
				}
			}
			else
			{
				stringBuilder.Append(c);
			}
		}
		return stringBuilder.ToString();
	}

	public static string TranslateItemName(string englishName)
	{
		if (string.IsNullOrEmpty(englishName))
		{
			return englishName;
		}
		if (ItemNames.TryGetValue(englishName, out var value) && !string.IsNullOrEmpty(value))
		{
			return value;
		}
		return englishName;
	}

	private static bool TryLoadFile(string language, out string json)
	{
		json = null;
		try
		{
			string directoryName = Path.GetDirectoryName(typeof(Localization).Assembly.Location);
			if (string.IsNullOrEmpty(directoryName))
			{
				return false;
			}
			string path = Path.Combine(directoryName, "languages", language + ".json");
			if (!File.Exists(path))
			{
				path = Path.Combine(directoryName, "languages", language, language + ".json");
			}
			if (!File.Exists(path))
			{
				return false;
			}
			json = File.ReadAllText(path);
			return true;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("ScanRarity: cannot read language file: " + ex.Message));
			return false;
		}
	}
}
[BepInPlugin("ScanRarity", "ScanRarity", "0.0.1")]
public class Plugin : BaseUnityPlugin
{
	public static Plugin Instance;

	public static ManualLogSource Log;

	private Harmony _harmony;

	public static ConfigEntry<bool> Enabled;

	public static ConfigEntry<float> BeaconDuration;

	public static ConfigEntry<float> BeaconHeight;

	public static ConfigEntry<bool> ShowValueText;

	public static ConfigEntry<bool> ShowDollarSign;

	public static ConfigEntry<string> Language;

	public static ConfigEntry<int> TextFontSize;

	public static ConfigEntry<float> TextVerticalOffset;

	public static ConfigEntry<bool> DisableVanillaScanDisplay;

	public static ConfigEntry<int> RarityRedThreshold;

	public static ConfigEntry<int> RarityGoldThreshold;

	public static ConfigEntry<int> RarityPurpleThreshold;

	public static ConfigEntry<int> RarityBlueThreshold;

	public static ConfigEntry<int> RarityGreenThreshold;

	private void Awake()
	{
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master switch for ScanRarity.");
		BeaconDuration = ((BaseUnityPlugin)this).Config.Bind<float>("General", "BeaconDuration", 8f, "Seconds the light pillar stays after an item is scanned.");
		BeaconHeight = ((BaseUnityPlugin)this).Config.Bind<float>("General", "BeaconHeight", 3f, "Height of the light pillar.");
		ShowValueText = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowValueText", true, "Show the scrap value above the pillar.");
		ShowDollarSign = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowDollarSign", false, "Prefix the value text with a $ sign.");
		Language = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Language", "zh-CN", "Language to use. Looks for a file in <plugin>/languages/<Language>/<Language>.json (or <plugin>/languages/<Language>.json). Built-in: en, zh-CN, ru. Add your own folder/file to customize.");
		TextFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("General", "TextFontSize", 72, "Font size of the value text.");
		TextVerticalOffset = ((BaseUnityPlugin)this).Config.Bind<float>("General", "TextVerticalOffset", 0.4f, "Vertical offset of the value text above the particles (Y axis).");
		DisableVanillaScanDisplay = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DisableVanillaScanDisplay", true, "Hide the vanilla scan HUD labels (item name + value) for scrap nodes; disable to restore vanilla scrap scan display.");
		RarityRedThreshold = ((BaseUnityPlugin)this).Config.Bind<int>("Rarity", "RedThreshold", 300, "Value >= this threshold -> Red (highest rarity).");
		RarityGoldThreshold = ((BaseUnityPlugin)this).Config.Bind<int>("Rarity", "GoldThreshold", 200, "Value >= this threshold -> Gold.");
		RarityPurpleThreshold = ((BaseUnityPlugin)this).Config.Bind<int>("Rarity", "PurpleThreshold", 130, "Value >= this threshold -> Purple.");
		RarityBlueThreshold = ((BaseUnityPlugin)this).Config.Bind<int>("Rarity", "BlueThreshold", 80, "Value >= this threshold -> Blue.");
		RarityGreenThreshold = ((BaseUnityPlugin)this).Config.Bind<int>("Rarity", "GreenThreshold", 40, "Value >= this threshold -> Green; below -> White.");
		_harmony = new Harmony("ScanRarity");
		_harmony.PatchAll();
		Localization.Load(Language.Value);
		Log.LogInfo((object)("ScanRarity 0.0.1 loaded (language: " + Localization.CurrentLanguage + ")"));
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}
}
public static class RarityColors
{
	public static readonly Color White = new Color(0.85f, 0.85f, 0.85f);

	public static readonly Color Green = new Color(0.25f, 1f, 0.4f);

	public static readonly Color Blue = new Color(0.3f, 0.55f, 1f);

	public static readonly Color Purple = new Color(0.8f, 0.3f, 1f);

	public static readonly Color Gold = new Color(1f, 0.8f, 0.15f);

	public static readonly Color Red = new Color(1f, 0.2f, 0.2f);

	public static Color GetRarityColor(int value)
	{
		//IL_000d: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		if (value >= Plugin.RarityRedThreshold.Value)
		{
			return Red;
		}
		if (value >= Plugin.RarityGoldThreshold.Value)
		{
			return Gold;
		}
		if (value >= Plugin.RarityPurpleThreshold.Value)
		{
			return Purple;
		}
		if (value >= Plugin.RarityBlueThreshold.Value)
		{
			return Blue;
		}
		if (value >= Plugin.RarityGreenThreshold.Value)
		{
			return Green;
		}
		return White;
	}
}
public class ScrapBeacon : MonoBehaviour
{
	private static readonly Dictionary<GrabbableObject, ScrapBeacon> _activeBeacons = new Dictionary<GrabbableObject, ScrapBeacon>();

	private GrabbableObject _target;

	private int _value;

	private string _itemName;

	private float _remaining;

	private float _updateTimer;

	private bool _visible = true;

	private GameObject _pillar;

	private GameObject _pillarCore;

	private GameObject _ring;

	private GameObject _glow;

	private ParticleSystem _particles;

	private TextMesh _valueText;

	private Color _rarityColor;

	public static void GetOrCreate(GrabbableObject target, int value)
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)target == (Object)null)
		{
			return;
		}
		if (_activeBeacons.TryGetValue(target, out var value2))
		{
			if (!((Object)(object)value2 == (Object)null))
			{
				value2.Refresh(value);
				return;
			}
			_activeBeacons.Remove(target);
		}
		ScrapBeacon scrapBeacon = new GameObject("ScanRarityBeacon").AddComponent<ScrapBeacon>();
		scrapBeacon._target = target;
		scrapBeacon.Init(value);
		_activeBeacons[target] = scrapBeacon;
	}

	private void Init(int value)
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		_value = value;
		_itemName = (((Object)(object)_target != (Object)null && (Object)(object)_target.itemProperties != (Object)null) ? _target.itemProperties.itemName : null);
		_remaining = Plugin.BeaconDuration.Value;
		_rarityColor = RarityColors.GetRarityColor(value);
		BuildParticles();
		if (Plugin.ShowValueText.Value)
		{
			BuildText();
		}
	}

	public void Refresh(int newValue)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		if (newValue != _value)
		{
			_value = newValue;
			_rarityColor = RarityColors.GetRarityColor(newValue);
			ApplyColor();
		}
		_remaining = Plugin.BeaconDuration.Value;
		if (_remaining >= 1f)
		{
			ApplyAlpha(1f);
		}
	}

	private static Material CreateColoredMaterial(Color color)
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Expected O, but got Unknown
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		Shader val = Shader.Find("Sprites/Default");
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("Unlit/Color");
		}
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("Standard");
		}
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("Diffuse");
		}
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		Material val2 = new Material(val);
		if (val2.HasProperty("_Color"))
		{
			val2.color = color;
		}
		return val2;
	}

	private void BuildPillar()
	{
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Unknown result type (might be due to invalid IL or missing references)
		float value = Plugin.BeaconHeight.Value;
		_pillar = GameObject.CreatePrimitive((PrimitiveType)2);
		((Object)_pillar).name = "PillarHalo";
		Object.Destroy((Object)(object)_pillar.GetComponent<Collider>());
		_pillar.transform.SetParent(((Component)this).transform, false);
		_pillar.transform.localPosition = new Vector3(0f, value * 0.5f, 0f);
		_pillar.transform.localScale = new Vector3(0.16f, value * 0.5f, 0.16f);
		Material val = CreateColoredMaterial(new Color(_rarityColor.r, _rarityColor.g, _rarityColor.b, 0.16f));
		if ((Object)(object)val != (Object)null)
		{
			((Renderer)_pillar.GetComponent<MeshRenderer>()).material = val;
		}
		_pillarCore = GameObject.CreatePrimitive((PrimitiveType)2);
		((Object)_pillarCore).name = "PillarCore";
		Object.Destroy((Object)(object)_pillarCore.GetComponent<Collider>());
		_pillarCore.transform.SetParent(((Component)this).transform, false);
		_pillarCore.transform.localPosition = new Vector3(0f, value * 0.5f, 0f);
		_pillarCore.transform.localScale = new Vector3(0.055f, value * 0.5f, 0.055f);
		Material val2 = CreateColoredMaterial(new Color(_rarityColor.r, _rarityColor.g, _rarityColor.b, 0.85f));
		if ((Object)(object)val2 != (Object)null)
		{
			((Renderer)_pillarCore.GetComponent<MeshRenderer>()).material = val2;
		}
		_ring = GameObject.CreatePrimitive((PrimitiveType)2);
		((Object)_ring).name = "Ring";
		Object.Destroy((Object)(object)_ring.GetComponent<Collider>());
		_ring.transform.SetParent(((Component)this).transform, false);
		_ring.transform.localPosition = new Vector3(0f, 0.04f, 0f);
		_ring.transform.localScale = new Vector3(0.6f, 0.05f, 0.6f);
		Material val3 = CreateColoredMaterial(new Color(_rarityColor.r, _rarityColor.g, _rarityColor.b, 0.55f));
		if ((Object)(object)val3 != (Object)null)
		{
			((Renderer)_ring.GetComponent<MeshRenderer>()).material = val3;
		}
	}

	private void BuildGlow()
	{
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		_glow = GameObject.CreatePrimitive((PrimitiveType)0);
		((Object)_glow).name = "Glow";
		Object.Destroy((Object)(object)_glow.GetComponent<Collider>());
		_glow.transform.SetParent(((Component)this).transform, false);
		_glow.transform.localPosition = new Vector3(0f, 0.15f, 0f);
		_glow.transform.localScale = new Vector3(0.55f, 0.55f, 0.55f);
		Material val = CreateColoredMaterial(new Color(_rarityColor.r, _rarityColor.g, _rarityColor.b, 0.32f));
		if ((Object)(object)val != (Object)null)
		{
			((Renderer)_glow.GetComponent<MeshRenderer>()).material = val;
		}
	}

	private void BuildParticles()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: 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)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Expected O, but got Unknown
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Expected O, but got Unknown
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0233: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_0285: Unknown result type (might be due to invalid IL or missing references)
		//IL_028a: Unknown result type (might be due to invalid IL or missing references)
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("RarityParticles");
		val.transform.SetParent(((Component)this).transform, false);
		val.transform.localPosition = new Vector3(0f, 0.15f, 0f);
		_particles = val.AddComponent<ParticleSystem>();
		MainModule main = _particles.main;
		((MainModule)(ref main)).loop = true;
		((MainModule)(ref main)).duration = 5f;
		((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(1.3f);
		((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f);
		((MainModule)(ref main)).startSize = new MinMaxCurve(0.05f, 0.13f);
		((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(_rarityColor.r, _rarityColor.g, _rarityColor.b, 0.9f));
		((MainModule)(ref main)).maxParticles = 100;
		((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0f);
		((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0;
		((MainModule)(ref main)).playOnAwake = true;
		EmissionModule emission = _particles.emission;
		((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(35f);
		ShapeModule shape = _particles.shape;
		((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)10;
		((ShapeModule)(ref shape)).radius = 0.35f;
		((ShapeModule)(ref shape)).arc = 360f;
		VelocityOverLifetimeModule velocityOverLifetime = _particles.velocityOverLifetime;
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = new MinMaxCurve(2.5f, 4.5f);
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)0;
		SizeOverLifetimeModule sizeOverLifetime = _particles.sizeOverLifetime;
		((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
		AnimationCurve val2 = new AnimationCurve((Keyframe[])(object)new Keyframe[3]
		{
			new Keyframe(0f, 0.2f),
			new Keyframe(0.5f, 1f),
			new Keyframe(1f, 0.1f)
		});
		((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, val2);
		ColorOverLifetimeModule colorOverLifetime = _particles.colorOverLifetime;
		((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
		Gradient val3 = new Gradient();
		val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[3]
		{
			new GradientColorKey(_rarityColor, 0f),
			new GradientColorKey(_rarityColor, 0.7f),
			new GradientColorKey(Color.white, 1f)
		}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
		{
			new GradientAlphaKey(0.9f, 0f),
			new GradientAlphaKey(0.9f, 0.6f),
			new GradientAlphaKey(0f, 1f)
		});
		((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val3);
		ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
		Material val4 = CreateColoredMaterial(Color.white);
		if ((Object)(object)val4 != (Object)null)
		{
			((Renderer)component).material = val4;
		}
		component.renderMode = (ParticleSystemRenderMode)0;
	}

	private void BuildText()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("ValueText");
		val.transform.SetParent(((Component)this).transform, false);
		val.transform.localPosition = new Vector3(0f, Plugin.BeaconHeight.Value + Plugin.TextVerticalOffset.Value, 0f);
		_valueText = val.AddComponent<TextMesh>();
		_valueText.text = FormatValue();
		_valueText.fontSize = Plugin.TextFontSize.Value;
		_valueText.characterSize = 0.055f;
		_valueText.anchor = (TextAnchor)4;
		_valueText.alignment = (TextAlignment)1;
		_valueText.color = _rarityColor;
		Font builtinResource = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
		if ((Object)(object)builtinResource == (Object)null)
		{
			builtinResource = Resources.GetBuiltinResource<Font>("Arial.ttf");
		}
		_valueText.font = builtinResource;
	}

	private string FormatValue()
	{
		string newValue = (Plugin.ShowDollarSign.Value ? (Localization.DollarSign + _value) : _value.ToString());
		string newValue2 = (string.IsNullOrEmpty(_itemName) ? "" : Localization.TranslateItemName(_itemName));
		return Localization.ValueFormat.Replace("{itemName}", newValue2).Replace("{value}", newValue).Trim();
	}

	private void ApplyColor()
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: 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_0057: Unknown result type (might be due to invalid IL or missing references)
		//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_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: 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_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_pillar != (Object)null)
		{
			Material material = ((Renderer)_pillar.GetComponent<MeshRenderer>()).material;
			if ((Object)(object)material != (Object)null)
			{
				Color color = material.color;
				material.color = new Color(_rarityColor.r, _rarityColor.g, _rarityColor.b, color.a);
			}
		}
		if ((Object)(object)_pillarCore != (Object)null)
		{
			Material material2 = ((Renderer)_pillarCore.GetComponent<MeshRenderer>()).material;
			if ((Object)(object)material2 != (Object)null)
			{
				Color color2 = material2.color;
				material2.color = new Color(_rarityColor.r, _rarityColor.g, _rarityColor.b, color2.a);
			}
		}
		if ((Object)(object)_ring != (Object)null)
		{
			Material material3 = ((Renderer)_ring.GetComponent<MeshRenderer>()).material;
			if ((Object)(object)material3 != (Object)null)
			{
				Color color3 = material3.color;
				material3.color = new Color(_rarityColor.r, _rarityColor.g, _rarityColor.b, color3.a);
			}
		}
		if ((Object)(object)_glow != (Object)null)
		{
			Material material4 = ((Renderer)_glow.GetComponent<MeshRenderer>()).material;
			if ((Object)(object)material4 != (Object)null)
			{
				material4.color = new Color(_rarityColor.r, _rarityColor.g, _rarityColor.b, material4.color.a);
			}
		}
		if ((Object)(object)_particles != (Object)null)
		{
			MainModule main = _particles.main;
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(_rarityColor.r, _rarityColor.g, _rarityColor.b, 0.9f));
		}
		if ((Object)(object)_valueText != (Object)null)
		{
			_valueText.text = FormatValue();
			_valueText.color = _rarityColor;
		}
	}

	private void ApplyAlpha(float a)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_pillar != (Object)null)
		{
			Material material = ((Renderer)_pillar.GetComponent<MeshRenderer>()).material;
			if ((Object)(object)material != (Object)null)
			{
				material.color = new Color(material.color.r, material.color.g, material.color.b, 0.16f * a);
			}
		}
		if ((Object)(object)_pillarCore != (Object)null)
		{
			Material material2 = ((Renderer)_pillarCore.GetComponent<MeshRenderer>()).material;
			if ((Object)(object)material2 != (Object)null)
			{
				material2.color = new Color(material2.color.r, material2.color.g, material2.color.b, 0.85f * a);
			}
		}
		if ((Object)(object)_ring != (Object)null)
		{
			Material material3 = ((Renderer)_ring.GetComponent<MeshRenderer>()).material;
			if ((Object)(object)material3 != (Object)null)
			{
				material3.color = new Color(material3.color.r, material3.color.g, material3.color.b, 0.55f * a);
			}
		}
		if ((Object)(object)_glow != (Object)null)
		{
			Material material4 = ((Renderer)_glow.GetComponent<MeshRenderer>()).material;
			if ((Object)(object)material4 != (Object)null)
			{
				material4.color = new Color(material4.color.r, material4.color.g, material4.color.b, 0.32f * a);
			}
		}
		if ((Object)(object)_valueText != (Object)null)
		{
			_valueText.color = new Color(_valueText.color.r, _valueText.color.g, _valueText.color.b, a);
		}
		if ((Object)(object)_particles != (Object)null)
		{
			EmissionModule emission = _particles.emission;
			((EmissionModule)(ref emission)).enabled = a > 0.01f;
		}
	}

	private void SetVisible(bool visible)
	{
		if ((Object)(object)_pillar != (Object)null)
		{
			_pillar.SetActive(visible);
		}
		if ((Object)(object)_pillarCore != (Object)null)
		{
			_pillarCore.SetActive(visible);
		}
		if ((Object)(object)_ring != (Object)null)
		{
			_ring.SetActive(visible);
		}
		if ((Object)(object)_glow != (Object)null)
		{
			_glow.SetActive(visible);
		}
		if ((Object)(object)_particles != (Object)null)
		{
			((Component)_particles).gameObject.SetActive(visible);
		}
		if ((Object)(object)_valueText != (Object)null)
		{
			((Component)_valueText).gameObject.SetActive(visible);
		}
	}

	private void Update()
	{
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_target == (Object)null)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		bool flag = _target.isHeld || _target.isPocketed || _target.isHeldByEnemy || (Object)(object)_target.playerHeldBy != (Object)null;
		if (flag != _visible)
		{
			_visible = !flag;
			SetVisible(_visible);
		}
		if (flag)
		{
			return;
		}
		((Component)this).transform.position = ((Component)_target).transform.position;
		_remaining -= Time.deltaTime;
		if (_remaining <= 0f)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		if (_remaining < 1f)
		{
			ApplyAlpha(Mathf.Clamp01(_remaining));
		}
		_updateTimer -= Time.deltaTime;
		if (_updateTimer <= 0f)
		{
			_updateTimer = 0.1f;
			FaceCamera();
		}
	}

	private void FaceCamera()
	{
		if (!((Object)(object)_valueText == (Object)null))
		{
			Camera main = Camera.main;
			if (!((Object)(object)main == (Object)null))
			{
				Transform transform = ((Component)_valueText).transform;
				transform.LookAt(((Component)main).transform);
				transform.Rotate(0f, 180f, 0f);
			}
		}
	}

	private void OnDestroy()
	{
		if ((Object)(object)_target != (Object)null)
		{
			_activeBeacons.Remove(_target);
		}
	}
}
public static class ScrapScanner
{
	private static float _scanCooldown;

	public static void OnScanUpdate(HUDManager hud)
	{
		if (!Plugin.Enabled.Value)
		{
			return;
		}
		_scanCooldown -= Time.deltaTime;
		if (_scanCooldown > 0f)
		{
			return;
		}
		_scanCooldown = 0.15f;
		if (Traverse.Create((object)hud).Field("playerPingingScan").GetValue<float>() < 0f)
		{
			return;
		}
		List<ScanNodeProperties> value = Traverse.Create((object)hud).Field("nodesOnScreen").GetValue<List<ScanNodeProperties>>();
		if (value == null || value.Count == 0)
		{
			return;
		}
		for (int i = 0; i < value.Count; i++)
		{
			ScanNodeProperties val = value[i];
			if (!((Object)(object)val == (Object)null) && val.nodeType == 2)
			{
				GrabbableObject componentInParent = ((Component)val).GetComponentInParent<GrabbableObject>();
				if (!((Object)(object)componentInParent == (Object)null) && !((Object)(object)componentInParent.itemProperties == (Object)null) && componentInParent.itemProperties.isScrap)
				{
					int value2 = ((val.scrapValue > 0) ? val.scrapValue : componentInParent.scrapValue);
					ScrapBeacon.GetOrCreate(componentInParent, value2);
				}
			}
		}
	}
}