Decompiled source of TarExtractor v0.2.0

TarExtractor.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Microsoft.CodeAnalysis;
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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("TarExtractor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Adds a buildable Tar Extractor that passively collects Tar from Plains tar pits.")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0+c271a1b19e833022612090ef0e77b4b4f0804f77")]
[assembly: AssemblyProduct("TarExtractor")]
[assembly: AssemblyTitle("TarExtractor")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TarExtractorMod
{
	internal static class PlacementState
	{
		internal static bool Blocked;

		internal const string Message = "$msg_tarextractor_needstarpit";
	}
	[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
	internal static class Player_UpdatePlacementGhost_Patch
	{
		private static void Postfix(Player __instance)
		{
			//IL_002b: 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)
			GameObject placementGhost = __instance.m_placementGhost;
			if ((Object)(object)placementGhost == (Object)null || (Object)(object)placementGhost.GetComponent<TarExtractor>() == (Object)null)
			{
				PlacementState.Blocked = false;
				return;
			}
			if (TarPit.IsInTarPit(placementGhost.transform.position))
			{
				PlacementState.Blocked = false;
				return;
			}
			PlacementState.Blocked = true;
			__instance.m_placementStatus = (PlacementStatus)1;
			__instance.SetPlacementGhostValid(false);
		}
	}
	[HarmonyPatch(typeof(Player), "UpdatePlacement")]
	internal static class Player_UpdatePlacement_Patch
	{
		private static void Prefix(Player __instance, bool __0)
		{
			if (__0 && PlacementState.Blocked && ((Character)__instance).InPlaceMode() && (ZInput.GetButtonDown("Attack") || ZInput.GetButtonDown("JoyPlace")))
			{
				((Character)__instance).Message((MessageType)2, "$msg_tarextractor_needstarpit", 0, (Sprite)null, false);
			}
		}
	}
	[HarmonyPatch(typeof(Player), "PlacePiece")]
	internal static class Player_PlacePiece_Patch
	{
		private static bool Prefix(Player __instance, Piece __0, Vector3 __1)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__0 == (Object)null || (Object)(object)((Component)__0).GetComponent<TarExtractor>() == (Object)null)
			{
				return true;
			}
			if (TarPit.IsInTarPit(__1))
			{
				return true;
			}
			((Character)__instance).Message((MessageType)2, "$msg_tarextractor_needstarpit", 0, (Sprite)null, false);
			return false;
		}
	}
	[BepInPlugin("javidahmed64592.tarextractor", "Tar Extractor", "0.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class TarExtractorPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "javidahmed64592.tarextractor";

		public const string PluginName = "Tar Extractor";

		public const string PluginVersion = "0.2.0";

		internal const string PrefabName = "piece_tarextractor";

		private const string SapExtractorPrefab = "piece_sapcollector";

		private static readonly Color TarTint = new Color(0.44f, 0.36f, 0.32f, 1f);

		private static readonly Color TarGlow = new Color(0.025f, 0.005f, 0.035f, 1f);

		internal const string NotEmptyEffectName = "NotEmptyEffect";

		private const string GrowthPrefab = "BlobTar";

		private const string GrowthOozePath = "Visual/particles/wetsplsh";

		private const string TranslationResourcePrefix = "TarExtractor.Translations.";

		internal static ManualLogSource Log;

		internal static ConfigEntry<float> SecondsPerTar;

		internal static ConfigEntry<int> MaxTar;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_002e: 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_003b: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			SecondsPerTar = ((BaseUnityPlugin)this).Config.Bind<float>("Tar Extractor", "Seconds Per Tar", 60f, new ConfigDescription("Seconds it takes the Tar Extractor to produce 1 Tar.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			MaxTar = ((BaseUnityPlugin)this).Config.Bind<int>("Tar Extractor", "Max Tar", 200, new ConfigDescription("Maximum amount of Tar a Tar Extractor can hold.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			AddLocalization();
			PrefabManager.OnVanillaPrefabsAvailable += AddTarExtractor;
			_harmony = new Harmony("javidahmed64592.tarextractor");
			_harmony.PatchAll();
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private static void AddLocalization()
		{
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
			foreach (string text in manifestResourceNames)
			{
				if (text.StartsWith("TarExtractor.Translations.") && text.EndsWith(".json"))
				{
					string text2 = text.Substring("TarExtractor.Translations.".Length, text.Length - "TarExtractor.Translations.".Length - ".json".Length);
					using StreamReader streamReader = new StreamReader(executingAssembly.GetManifestResourceStream(text));
					localization.AddJsonFile(text2, streamReader.ReadToEnd());
				}
			}
		}

		private void AddTarExtractor()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			PrefabManager.OnVanillaPrefabsAvailable -= AddTarExtractor;
			PieceConfig val = new PieceConfig();
			val.Name = "$piece_tarextractor";
			val.Description = "$piece_tarextractor_description";
			val.PieceTable = "Hammer";
			val.Category = "Crafting";
			val.CraftingStation = "piece_workbench";
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[3]
			{
				new RequirementConfig("YggdrasilWood", 10, 0, true),
				new RequirementConfig("BlackMetal", 5, 0, true),
				new RequirementConfig("DvergrNeedle", 1, 0, true)
			};
			PieceConfig val2 = val;
			CustomPiece val3 = new CustomPiece("piece_tarextractor", "piece_sapcollector", val2);
			ConvertToTarExtractor(val3.PiecePrefab);
			PieceManager.Instance.AddPiece(val3);
		}

		private static void ConvertToTarExtractor(GameObject prefab)
		{
			Piece component = prefab.GetComponent<Piece>();
			LogFields("Piece", component, "connect");
			Component component2 = prefab.GetComponent("SapCollector");
			LogFields("SapCollector", component2, null);
			if ((Object)(object)component2 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component2);
			}
			else
			{
				Log.LogWarning((object)"No SapCollector component found on the cloned prefab - the vanilla component may have been renamed. Check the diagnostic output above.");
			}
			ClearConnectionRequirement(component);
			prefab.AddComponent<TarExtractor>();
			TintRenderers(prefab);
			RecolorEffects(prefab);
			ReplaceLightWithOoze(prefab);
			Transform val = FindChild(prefab.transform, "NotEmptyEffect");
			if ((Object)(object)val != (Object)null)
			{
				((Component)val).gameObject.SetActive(false);
			}
			else
			{
				Log.LogWarning((object)"No 'NotEmptyEffect' found on the cloned prefab - effects stay always on.");
			}
		}

		private static void RecolorEffects(GameObject prefab)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			ParticleSystem[] componentsInChildren = prefab.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem obj in componentsInChildren)
			{
				MainModule main = obj.main;
				((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(TarGlow);
				ColorOverLifetimeModule colorOverLifetime = obj.colorOverLifetime;
				if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
				{
					((ColorOverLifetimeModule)(ref colorOverLifetime)).color = WhiteKeepAlpha(((ColorOverLifetimeModule)(ref colorOverLifetime)).color);
				}
			}
			Renderer[] componentsInChildren2 = prefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren2)
			{
				Material[] sharedMaterials = val.sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if (!((Object)(object)sharedMaterials[j] == (Object)null) && sharedMaterials[j].HasProperty("_EmissionColor"))
					{
						if (val is ParticleSystemRenderer)
						{
							sharedMaterials[j] = new Material(sharedMaterials[j]);
						}
						sharedMaterials[j].SetColor("_EmissionColor", TarGlow);
					}
				}
				val.sharedMaterials = sharedMaterials;
			}
		}

		private static MinMaxGradient WhiteKeepAlpha(MinMaxGradient source)
		{
			//IL_0002: 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_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected I4, but got Unknown
			//IL_0034: 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_0043: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystemGradientMode mode = ((MinMaxGradient)(ref source)).mode;
			return (MinMaxGradient)((int)mode switch
			{
				0 => new MinMaxGradient(new Color(1f, 1f, 1f, ((MinMaxGradient)(ref source)).color.a)), 
				2 => new MinMaxGradient(new Color(1f, 1f, 1f, ((MinMaxGradient)(ref source)).colorMin.a), new Color(1f, 1f, 1f, ((MinMaxGradient)(ref source)).colorMax.a)), 
				1 => new MinMaxGradient(WhiteKeepAlpha(((MinMaxGradient)(ref source)).gradient)), 
				3 => new MinMaxGradient(WhiteKeepAlpha(((MinMaxGradient)(ref source)).gradientMin), WhiteKeepAlpha(((MinMaxGradient)(ref source)).gradientMax)), 
				_ => source, 
			});
		}

		private static Gradient WhiteKeepAlpha(Gradient source)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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)
			Gradient val = new Gradient();
			val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(Color.white, 0f),
				new GradientColorKey(Color.white, 1f)
			}, source.alphaKeys);
			val.mode = source.mode;
			return val;
		}

		private static void ReplaceLightWithOoze(GameObject prefab)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			Light componentInChildren = prefab.GetComponentInChildren<Light>(true);
			if ((Object)(object)componentInChildren == (Object)null)
			{
				Log.LogWarning((object)"No light found on the cloned prefab - the ooze effect is not added.");
				return;
			}
			Transform parent = ((Component)componentInChildren).transform.parent;
			Vector3 localPosition = ((Component)componentInChildren).transform.localPosition;
			Object.DestroyImmediate((Object)(object)((Component)componentInChildren).gameObject);
			GameObject prefab2 = PrefabManager.Instance.GetPrefab("BlobTar");
			Transform val = (((Object)(object)prefab2 != (Object)null) ? prefab2.transform.Find("Visual/particles/wetsplsh") : null);
			if ((Object)(object)val == (Object)null)
			{
				Log.LogWarning((object)"Could not find 'Visual/particles/wetsplsh' on 'BlobTar' - no ooze effect.");
				return;
			}
			GameObject obj = Object.Instantiate<GameObject>(((Component)val).gameObject, parent, false);
			((Object)obj).name = "tar_ooze";
			obj.transform.localPosition = localPosition;
			obj.SetActive(true);
			ParticleSystem component = obj.GetComponent<ParticleSystem>();
			ShapeModule shape = component.shape;
			((ShapeModule)(ref shape)).radius = ((ShapeModule)(ref shape)).radius * 0.25f;
			EmissionModule emission = component.emission;
			((EmissionModule)(ref emission)).rateOverTimeMultiplier = ((EmissionModule)(ref emission)).rateOverTimeMultiplier * 0.3f;
			MainModule main = component.main;
			((MainModule)(ref main)).startSizeMultiplier = ((MainModule)(ref main)).startSizeMultiplier * 0.4f;
			((MainModule)(ref main)).startSpeedMultiplier = ((MainModule)(ref main)).startSpeedMultiplier * 0.5f;
		}

		internal static Transform FindChild(Transform root, string name)
		{
			Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (((Object)val).name == name)
				{
					return val;
				}
			}
			return null;
		}

		private static void ClearConnectionRequirement(Piece piece)
		{
			FieldInfo[] fields = typeof(Piece).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				if (fieldInfo.Name.IndexOf("mustconnect", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					object value = ((fieldInfo.FieldType == typeof(bool)) ? ((object)false) : null);
					fieldInfo.SetValue(piece, value);
					Log.LogInfo((object)("Cleared Piece." + fieldInfo.Name + " on the Tar Extractor prefab."));
				}
			}
		}

		private static void TintRenderers(GameObject prefab)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (val is ParticleSystemRenderer || val is TrailRenderer)
				{
					continue;
				}
				Material[] sharedMaterials = val.sharedMaterials;
				Material[] array = (Material[])(object)new Material[sharedMaterials.Length];
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if (!((Object)(object)sharedMaterials[j] == (Object)null))
					{
						array[j] = new Material(sharedMaterials[j]);
						if (array[j].HasProperty("_Color"))
						{
							array[j].color = TarTint;
						}
					}
				}
				val.sharedMaterials = array;
			}
		}

		private static void LogFields(string label, object target, string nameFilter)
		{
			if (target == null)
			{
				return;
			}
			Log.LogInfo((object)("[diagnostic] " + label + " fields:"));
			FieldInfo[] fields = target.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				if (nameFilter == null || fieldInfo.Name.IndexOf(nameFilter, StringComparison.OrdinalIgnoreCase) >= 0)
				{
					Log.LogInfo((object)$"    {fieldInfo.FieldType.Name} {fieldInfo.Name} = {fieldInfo.GetValue(target)}");
				}
			}
		}
	}
	public class TarExtractor : MonoBehaviour, Hoverable, Interactable
	{
		private const string LevelKey = "TarExtractor_level";

		private const string LastTickKey = "TarExtractor_lastTick";

		private ZNetView _nview;

		private GameObject _notEmptyEffect;

		private void Awake()
		{
			_nview = ((Component)this).GetComponent<ZNetView>();
			if (!((Object)(object)_nview == (Object)null) && _nview.IsValid())
			{
				Transform val = TarExtractorPlugin.FindChild(((Component)this).transform, "NotEmptyEffect");
				_notEmptyEffect = (((Object)(object)val != (Object)null) ? ((Component)val).gameObject : null);
				((MonoBehaviour)this).InvokeRepeating("UpdateTick", Random.Range(0f, 2f), 2f);
				((MonoBehaviour)this).InvokeRepeating("UpdateEffects", 0f, 1f);
			}
		}

		private void UpdateEffects()
		{
			if (!((Object)(object)_notEmptyEffect == (Object)null) && _nview.IsValid())
			{
				bool flag = _nview.GetZDO().GetInt("TarExtractor_level", 0) > 0;
				if (_notEmptyEffect.activeSelf != flag)
				{
					_notEmptyEffect.SetActive(flag);
				}
			}
		}

		private void UpdateTick()
		{
			if (!_nview.IsValid() || !_nview.IsOwner())
			{
				return;
			}
			ZDO zDO = _nview.GetZDO();
			long ticks = ZNet.instance.GetTime().Ticks;
			long num = zDO.GetLong("TarExtractor_lastTick", 0L);
			int num2 = zDO.GetInt("TarExtractor_level", 0);
			int value = TarExtractorPlugin.MaxTar.Value;
			if (num2 > value)
			{
				num2 = value;
				zDO.Set("TarExtractor_level", num2);
			}
			if (num == 0L || num2 >= value)
			{
				zDO.Set("TarExtractor_lastTick", ticks);
				return;
			}
			long num3 = (long)(Mathf.Max(1f, TarExtractorPlugin.SecondsPerTar.Value) * 10000000f);
			long num4 = (ticks - num) / num3;
			if (num4 > 0)
			{
				int num5 = (int)Math.Min(value, num2 + num4);
				zDO.Set("TarExtractor_level", num5);
				zDO.Set("TarExtractor_lastTick", (num5 >= value) ? ticks : (num + num4 * num3));
			}
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			if (hold || (Object)(object)_nview == (Object)null || !_nview.IsValid())
			{
				return false;
			}
			_nview.ClaimOwnership();
			UpdateTick();
			ZDO zDO = _nview.GetZDO();
			int num = zDO.GetInt("TarExtractor_level", 0);
			if (num <= 0)
			{
				((Character)user).Message((MessageType)2, "$piece_tarextractor_empty", 0, (Sprite)null, false);
				return true;
			}
			zDO.Set("TarExtractor_level", 0);
			zDO.Set("TarExtractor_lastTick", ZNet.instance.GetTime().Ticks);
			UpdateEffects();
			SpawnTar(num);
			((Character)user).Message((MessageType)2, "$piece_tarextractor_extracted", 0, (Sprite)null, false);
			return true;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			return false;
		}

		public string GetHoverText()
		{
			if ((Object)(object)_nview == (Object)null || !_nview.IsValid())
			{
				return string.Empty;
			}
			int num = _nview.GetZDO().GetInt("TarExtractor_level", 0);
			int value = TarExtractorPlugin.MaxTar.Value;
			return Localization.instance.Localize($"$piece_tarextractor ({num}/{value})\n" + "[<color=yellow><b>$KEY_Use</b></color>] $piece_tarextractor_extract");
		}

		public string GetHoverName()
		{
			return Localization.instance.Localize("$piece_tarextractor");
		}

		public float GetHoverOffset()
		{
			return 0f;
		}

		private void SpawnTar(int amount)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Tar");
			if ((Object)(object)itemPrefab == (Object)null)
			{
				TarExtractorPlugin.Log.LogError((object)"Could not find the 'Tar' item prefab.");
				return;
			}
			int num = Mathf.Max(1, itemPrefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_maxStackSize);
			Vector3 val = ((Component)this).transform.position + Vector3.up * 1.2f + ((Component)this).transform.forward * 0.8f;
			while (amount > 0)
			{
				int num2 = Mathf.Min(amount, num);
				Vector3 val2 = val + Random.insideUnitSphere * 0.25f;
				GameObject obj = Object.Instantiate<GameObject>(itemPrefab, val2, Quaternion.identity);
				obj.GetComponent<ItemDrop>().SetStack(num2);
				Rigidbody component = obj.GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null)
				{
					component.linearVelocity = Vector3.up * 2f;
				}
				amount -= num2;
			}
		}
	}
	internal static class TarPit
	{
		private const string LocationPrefix = "TarPit";

		private const float RefreshInterval = 2f;

		private static Location[] _cache = (Location[])(object)new Location[0];

		private static float _lastRefresh = -100f;

		internal static bool IsInTarPit(Vector3 position)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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)
			Refresh();
			Location[] cache = _cache;
			foreach (Location val in cache)
			{
				if (!((Object)(object)val == (Object)null))
				{
					Vector3 val2 = ((Component)val).transform.position - position;
					val2.y = 0f;
					if (((Vector3)(ref val2)).magnitude <= val.m_exteriorRadius)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static void Refresh()
		{
			if (Time.time - _lastRefresh < 2f)
			{
				return;
			}
			_lastRefresh = Time.time;
			List<Location> list = new List<Location>();
			Location[] array = Object.FindObjectsByType<Location>((FindObjectsSortMode)0);
			foreach (Location val in array)
			{
				if (((Object)val).name.StartsWith("TarPit"))
				{
					list.Add(val);
				}
			}
			_cache = list.ToArray();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}