Decompiled source of TinyCart v1.0.0

plugins/TinyCart.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ScalerCore;
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("TinyCart")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TinyCart")]
[assembly: AssemblyTitle("TinyCart")]
[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 TinyCart
{
	[BepInPlugin("purplehaxttv.TinyCart", "Tiny Cart", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private sealed class Tracked
		{
			public GameObject Object;

			public float LastSeen;

			public bool Enemy;

			public bool Player;
		}

		public const string Guid = "purplehaxttv.TinyCart";

		private const float TickSeconds = 0.25f;

		private const float CartRescanSeconds = 2f;

		private const float ReshrinkCooldown = 2f;

		private static readonly FieldRef<PhysGrabCart, List<PhysGrabObject>> ItemsInCart = AccessTools.FieldRefAccess<PhysGrabCart, List<PhysGrabObject>>("itemsInCart");

		private static readonly FieldRef<EnemyHealth, int> HealthCurrent = AccessTools.FieldRefAccess<EnemyHealth, int>("healthCurrent");

		private static readonly FieldRef<EnemyHealth, bool> HealthDead = AccessTools.FieldRefAccess<EnemyHealth, bool>("dead");

		private static readonly FieldRef<PhysGrabCart, Transform> InCart = AccessTools.FieldRefAccess<PhysGrabCart, Transform>("inCart");

		private static ManualLogSource Log;

		private ConfigEntry<float> valuableScale;

		private ConfigEntry<bool> shrinkItems;

		private ConfigEntry<float> itemScale;

		private ConfigEntry<bool> lighterWhenSmall;

		private ConfigEntry<bool> growBack;

		private ConfigEntry<float> growBackDelay;

		private ConfigEntry<float> shrinkSpeed;

		private ConfigEntry<bool> activeInShop;

		private ConfigEntry<string> enemyNames;

		private ConfigEntry<float> enemyScale;

		private ConfigEntry<bool> enemyGrowBack;

		private ConfigEntry<bool> enemyGrowWhenHurt;

		private ConfigEntry<bool> shrinkPlayers;

		private ConfigEntry<float> playerScale;

		private ConfigEntry<bool> playerGrowWhenHurt;

		private ConfigEntry<bool> killEnemies;

		private ConfigEntry<string> sparedEnemies;

		private ConfigEntry<float> killReach;

		private ConfigEntry<bool> verbose;

		private readonly Dictionary<int, Tracked> tracked = new Dictionary<int, Tracked>();

		private readonly Dictionary<int, float> cooldownUntil = new Dictionary<int, float>();

		private readonly Dictionary<int, float> killRetryAt = new Dictionary<int, float>();

		private readonly List<int> scratch = new List<int>();

		private PhysGrabCart[] carts = (PhysGrabCart[])(object)new PhysGrabCart[0];

		private float nextTick;

		private float nextCartScan;

		private void Awake()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Expected O, but got Unknown
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Expected O, but got Unknown
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			((Component)this).transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			valuableScale = ((BaseUnityPlugin)this).Config.Bind<float>("Valuables", "Scale", 0.5f, new ConfigDescription("Size of a valuable while it sits in a cart (1 = normal size).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			lighterWhenSmall = ((BaseUnityPlugin)this).Config.Bind<bool>("Valuables", "Lighter when small", true, "Shrunk things also weigh less, so a full cart is easier to push.");
			shrinkItems = ((BaseUnityPlugin)this).Config.Bind<bool>("Items", "Shrink shop items", true, "Also shrink bought items (weapons, grenades, health packs and so on) in a cart.");
			itemScale = ((BaseUnityPlugin)this).Config.Bind<float>("Items", "Scale", 0.5f, new ConfigDescription("Size of a bought item while it sits in a cart.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			growBack = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Grow back when removed", true, "Things return to normal size after they have been out of every cart for the delay below. Off = they stay small for the rest of the level.");
			growBackDelay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Grow back delay", 1.5f, new ConfigDescription("Seconds something must be out of the cart before it grows back. Stops things flickering between sizes at the cart's edge.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 30f), Array.Empty<object>()));
			shrinkSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Shrink speed", 2f, new ConfigDescription("How fast the size change plays.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 10f), Array.Empty<object>()));
			activeInShop = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Active in shop", false, "Shrink things placed in the cart while in the shop.");
			enemyNames = ((BaseUnityPlugin)this).Config.Bind<string>("Enemies", "Enemies to shrink", "Duck=0.3,Apex Predator=0.3,Gnome", "Comma separated list of enemy names that shrink when they end up in a cart. Add =size to give one its own size, for example Duck=0.3; others use Scale below. Empty = no enemies. * = every enemy. Only matters for enemies the cart does not kill.");
			enemyScale = ((BaseUnityPlugin)this).Config.Bind<float>("Enemies", "Scale", 0.5f, new ConfigDescription("Size of a shrunk enemy.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			enemyGrowBack = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Grow back when out of cart", false, "Off = a shrunk enemy stays small for the rest of the level.");
			enemyGrowWhenHurt = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Grow back when hurt", false, "A shrunk enemy returns to normal size when it takes damage.");
			shrinkPlayers = ((BaseUnityPlugin)this).Config.Bind<bool>("Players", "Shrink players in cart", true, "A player standing or lying in a cart shrinks, and always grows back after leaving it.");
			playerScale = ((BaseUnityPlugin)this).Config.Bind<float>("Players", "Scale", 0.5f, new ConfigDescription("Size of a player while in a cart.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			playerGrowWhenHurt = ((BaseUnityPlugin)this).Config.Bind<bool>("Players", "Grow back when hurt", true, "A shrunk player returns to normal size when they take damage.");
			killEnemies = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "Kill enemies in cart", true, "An enemy that ends up in a cart dies, unless it is on the spared list below.");
			sparedEnemies = ((BaseUnityPlugin)this).Config.Bind<string>("Enemies", "Enemies spared", "Duck,Apex Predator,Gnome", "Comma separated list of enemy names the cart never kills. * = spare every enemy.");
			killReach = ((BaseUnityPlugin)this).Config.Bind<float>("Enemies", "Kill reach", 0.3f, new ConfigDescription("How far outside the cart's basket an enemy still counts as hit, in metres. 0 = only enemies inside the basket die.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1.5f), Array.Empty<object>()));
			verbose = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Verbose log", false, "Log every shrink and grow.");
			Log.LogInfo((object)"Tiny Cart 1.0.0 loaded");
		}

		private void Update()
		{
			float unscaledTime = Time.unscaledTime;
			if (unscaledTime < nextTick)
			{
				return;
			}
			nextTick = unscaledTime + 0.25f;
			try
			{
				Tick(unscaledTime);
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Tick failed: {arg}");
				nextTick = unscaledTime + 5f;
			}
		}

		private void Tick(float now)
		{
			if (!SemiFunc.IsMasterClientOrSingleplayer() || (Object)(object)LevelGenerator.Instance == (Object)null || !LevelGenerator.Instance.Generated)
			{
				if (tracked.Count > 0 && ((Object)(object)LevelGenerator.Instance == (Object)null || !LevelGenerator.Instance.Generated))
				{
					tracked.Clear();
					cooldownUntil.Clear();
					killRetryAt.Clear();
				}
				return;
			}
			if (now >= nextCartScan)
			{
				nextCartScan = now + 2f;
				carts = Object.FindObjectsByType<PhysGrabCart>((FindObjectsSortMode)0);
			}
			bool shrinkAllowed = activeInShop.Value || !SemiFunc.RunIsShop();
			PhysGrabCart[] array = carts;
			foreach (PhysGrabCart val in array)
			{
				if (!Object.op_Implicit((Object)(object)val) || !((Behaviour)val).isActiveAndEnabled)
				{
					continue;
				}
				KillTouching(val, now);
				List<PhysGrabObject> list = ItemsInCart.Invoke(val);
				if (list == null)
				{
					continue;
				}
				for (int j = 0; j < list.Count; j++)
				{
					PhysGrabObject val2 = list[j];
					if (!Object.op_Implicit((Object)(object)val2) || TryKill(((Component)val2).gameObject, now))
					{
						continue;
					}
					PlayerTumble component = ((Component)val2).GetComponent<PlayerTumble>();
					if (Object.op_Implicit((Object)(object)component))
					{
						if (Object.op_Implicit((Object)(object)component.playerAvatar))
						{
							SeenPlayer(component.playerAvatar, now, mayShrink: true);
						}
					}
					else
					{
						Seen(((Component)val2).gameObject, now, shrinkAllowed);
					}
				}
			}
			if (shrinkPlayers.Value)
			{
				ScanStandingPlayers(now);
			}
			scratch.Clear();
			foreach (KeyValuePair<int, Tracked> item in tracked)
			{
				Tracked value = item.Value;
				if (!Object.op_Implicit((Object)(object)value.Object))
				{
					scratch.Add(item.Key);
				}
				else if (!ScaleManager.IsScaled(value.Object))
				{
					scratch.Add(item.Key);
					cooldownUntil[item.Key] = now + 2f;
				}
				else if ((value.Player || (value.Enemy ? enemyGrowBack.Value : growBack.Value)) && now - value.LastSeen >= growBackDelay.Value)
				{
					Restore(value.Object);
					scratch.Add(item.Key);
					cooldownUntil[item.Key] = now + 2f;
				}
			}
			foreach (int item2 in scratch)
			{
				tracked.Remove(item2);
			}
		}

		private void ScanStandingPlayers(float now)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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)
			List<PlayerAvatar> list = SemiFunc.PlayerGetAll();
			if (list == null)
			{
				return;
			}
			foreach (PlayerAvatar item in list)
			{
				if (!Object.op_Implicit((Object)(object)item) || !((Component)item).gameObject.activeInHierarchy)
				{
					continue;
				}
				Vector3 point = ((Component)item).transform.position + Vector3.up * 0.05f;
				PhysGrabCart[] array = carts;
				foreach (PhysGrabCart val in array)
				{
					if (Object.op_Implicit((Object)(object)val) && ((Behaviour)val).isActiveAndEnabled && !val.isSmallCart)
					{
						Transform val2 = InCart.Invoke(val);
						if (Object.op_Implicit((Object)(object)val2) && OverFloor(point, val2, 1f))
						{
							SeenPlayer(item, now, OverFloor(point, val2, 0.7f));
							break;
						}
					}
				}
			}
		}

		private static bool OverFloor(Vector3 point, Transform box, float horizontalScale)
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_001c: 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_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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Quaternion.Inverse(box.rotation) * (point - box.position);
			Vector3 val2 = box.localScale * 0.5f;
			float num = 0f - Mathf.Abs(val2.y);
			if (Mathf.Abs(val.x) <= Mathf.Abs(val2.x) * horizontalScale && Mathf.Abs(val.z) <= Mathf.Abs(val2.z) * horizontalScale && val.y >= num - 0.25f)
			{
				return val.y <= num + 1.4f;
			}
			return false;
		}

		private void SeenPlayer(PlayerAvatar player, float now, bool mayShrink)
		{
			//IL_0063: 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_00af: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			if (!shrinkPlayers.Value)
			{
				return;
			}
			GameObject gameObject = ((Component)player).gameObject;
			int instanceID = ((Object)gameObject).GetInstanceID();
			if (tracked.TryGetValue(instanceID, out var value))
			{
				value.LastSeen = now;
			}
			else
			{
				if (!mayShrink)
				{
					return;
				}
				if (cooldownUntil.TryGetValue(instanceID, out var value2))
				{
					if (now < value2)
					{
						return;
					}
					cooldownUntil.Remove(instanceID);
				}
				if (ScaleManager.IsScaled(gameObject))
				{
					return;
				}
				ScaleOptions val = ScaleOptions.Default;
				val.Factor = playerScale.Value;
				val.Duration = 0f;
				val.Speed = shrinkSpeed.Value;
				val.RestoreSpeed = shrinkSpeed.Value;
				val.AllowedTargets = (ScaleTargets)1;
				val.SuppressImpactFlash = true;
				val.SuppressCameraShake = true;
				val.IgnoreBonkExpand = !playerGrowWhenHurt.Value;
				if (val.Factor >= 0.999f)
				{
					return;
				}
				if (!Apply(gameObject, val))
				{
					cooldownUntil[instanceID] = now + 2f;
					return;
				}
				tracked[instanceID] = new Tracked
				{
					Object = gameObject,
					LastSeen = now,
					Player = true
				};
				if (verbose.Value)
				{
					Log.LogInfo((object)("Shrunk player " + ((Object)player).name));
				}
			}
		}

		private static bool Apply(GameObject target, ScaleOptions options)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			bool nativeSync = ScaleManager.NativeSync;
			try
			{
				ScaleManager.NativeSync = false;
				return ScaleManager.ApplyIfNotScaled(target, options);
			}
			finally
			{
				ScaleManager.NativeSync = nativeSync;
			}
		}

		private void KillTouching(PhysGrabCart cart, float now)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			if (!killEnemies.Value)
			{
				return;
			}
			Transform val = InCart.Invoke(cart);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			Collider[] array = Physics.OverlapBox(val.position, val.localScale / 2f + Vector3.one * killReach.Value, val.rotation);
			for (int i = 0; i < array.Length; i++)
			{
				EnemyRigidbody componentInParent = ((Component)array[i]).GetComponentInParent<EnemyRigidbody>();
				if (Object.op_Implicit((Object)(object)componentInParent))
				{
					TryKill(((Component)componentInParent).gameObject, now);
				}
			}
		}

		private bool TryKill(GameObject target, float now)
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			if (!killEnemies.Value)
			{
				return false;
			}
			EnemyRigidbody component = target.GetComponent<EnemyRigidbody>();
			if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.enemy))
			{
				return false;
			}
			if (Listed(target, sparedEnemies.Value, out var _))
			{
				return false;
			}
			int instanceID = ((Object)target).GetInstanceID();
			if (killRetryAt.TryGetValue(instanceID, out var value) && now < value)
			{
				return true;
			}
			killRetryAt[instanceID] = now + 1f;
			EnemyHealth component2 = ((Component)component.enemy).GetComponent<EnemyHealth>();
			if (!Object.op_Implicit((Object)(object)component2))
			{
				return true;
			}
			int num = HealthCurrent.Invoke(component2);
			if (HealthDead.Invoke(component2) || num <= 0)
			{
				return true;
			}
			component2.Hurt(Math.Max(num, component2.health) + 1, Vector3.up);
			if (verbose.Value)
			{
				Log.LogInfo((object)("Cart killed " + EnemyLabel(target)));
			}
			return true;
		}

		private static string EnemyLabel(GameObject target)
		{
			EnemyParent componentInParent = target.GetComponentInParent<EnemyParent>();
			if (!Object.op_Implicit((Object)(object)componentInParent))
			{
				return ((Object)target).name;
			}
			return componentInParent.enemyName;
		}

		private void Seen(GameObject target, float now, bool shrinkAllowed)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			int instanceID = ((Object)target).GetInstanceID();
			if (tracked.TryGetValue(instanceID, out var value))
			{
				value.LastSeen = now;
			}
			else
			{
				if (!shrinkAllowed)
				{
					return;
				}
				if (cooldownUntil.TryGetValue(instanceID, out var value2))
				{
					if (now < value2)
					{
						return;
					}
					cooldownUntil.Remove(instanceID);
				}
				if (ScaleManager.IsScaled(target) || !Classify(target, out var options, out var enemy))
				{
					return;
				}
				bool nativeSync = ScaleManager.NativeSync;
				bool flag;
				try
				{
					ScaleManager.NativeSync = false;
					flag = ScaleManager.ApplyIfNotScaled(target, options);
				}
				finally
				{
					ScaleManager.NativeSync = nativeSync;
				}
				if (!flag)
				{
					cooldownUntil[instanceID] = now + 2f;
					return;
				}
				tracked[instanceID] = new Tracked
				{
					Object = target,
					LastSeen = now,
					Enemy = enemy
				};
				if (verbose.Value)
				{
					Log.LogInfo((object)$"Shrunk {((Object)target).name} to x{options.Factor}");
				}
			}
		}

		private void Restore(GameObject target)
		{
			bool nativeSync = ScaleManager.NativeSync;
			try
			{
				ScaleManager.NativeSync = false;
				ScaleManager.ForceRestore(target);
			}
			finally
			{
				ScaleManager.NativeSync = nativeSync;
			}
			if (verbose.Value)
			{
				Log.LogInfo((object)("Restored " + ((Object)target).name));
			}
		}

		private bool Classify(GameObject target, out ScaleOptions options, out bool enemy)
		{
			//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_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			options = ScaleOptions.Default;
			options.Duration = 0f;
			options.Speed = shrinkSpeed.Value;
			options.RestoreSpeed = shrinkSpeed.Value;
			options.SuppressImpactFlash = true;
			options.SuppressCameraShake = true;
			options.SuppressValueDropExpand = true;
			options.PreserveMass = !lighterWhenSmall.Value;
			enemy = false;
			if (Object.op_Implicit((Object)(object)target.GetComponent<PhysGrabCart>()) || Object.op_Implicit((Object)(object)target.GetComponent<PlayerTumble>()) || Object.op_Implicit((Object)(object)target.GetComponent<PlayerDeathHead>()))
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)target.GetComponent<ItemCartCannonMain>()) || Object.op_Implicit((Object)(object)target.GetComponent<ItemCartLaser>()))
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)target.GetComponent<EnemyRigidbody>()))
			{
				if (!Listed(target, enemyNames.Value, out var size))
				{
					return false;
				}
				enemy = true;
				options.Factor = ((size > 0f) ? Mathf.Clamp(size, 0.1f, 1f) : enemyScale.Value);
				options.AllowedTargets = (ScaleTargets)2;
				options.IgnoreBonkExpand = !enemyGrowWhenHurt.Value;
				options.PreserveMass = false;
				return true;
			}
			if (Object.op_Implicit((Object)(object)target.GetComponent<ValuableObject>()))
			{
				options.Factor = valuableScale.Value;
				options.AllowedTargets = (ScaleTargets)12;
				return options.Factor < 0.999f;
			}
			if (Object.op_Implicit((Object)(object)target.GetComponent<ItemAttributes>()))
			{
				if (!shrinkItems.Value)
				{
					return false;
				}
				options.Factor = itemScale.Value;
				options.AllowedTargets = (ScaleTargets)12;
				return options.Factor < 0.999f;
			}
			return false;
		}

		private static bool Listed(GameObject target, string list, out float size)
		{
			size = 0f;
			if (string.IsNullOrWhiteSpace(list))
			{
				return false;
			}
			EnemyParent componentInParent = target.GetComponentInParent<EnemyParent>();
			string text = (Object.op_Implicit((Object)(object)componentInParent) ? (componentInParent.enemyName ?? "") : "");
			string text2 = (Object.op_Implicit((Object)(object)componentInParent) ? ((Object)((Component)componentInParent).gameObject).name : ((Object)target).name);
			string[] array = list.Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				string text3 = array[i].Trim();
				float result = 0f;
				int num = text3.IndexOf('=');
				if (num >= 0)
				{
					float.TryParse(text3.Substring(num + 1).Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out result);
					text3 = text3.Substring(0, num).Trim();
				}
				if (text3.Length != 0)
				{
					if (text3 == "*")
					{
						size = result;
						return true;
					}
					if (text.IndexOf(text3, StringComparison.OrdinalIgnoreCase) >= 0)
					{
						size = result;
						return true;
					}
					if (text2.IndexOf(text3, StringComparison.OrdinalIgnoreCase) >= 0)
					{
						size = result;
						return true;
					}
				}
			}
			return false;
		}
	}
}