Decompiled source of ReviveCountdown v1.0.0

ReviveCountdown.dll

Decompiled an hour ago
using System;
using System.Collections;
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 TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ReviveCountdown")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Host-only countdown revive: every dead player revives in place after an independent, configurable 1-300 second countdown in all levels, the service station and the truck lobby, except the arena.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ReviveCountdown")]
[assembly: AssemblyTitle("ReviveCountdown")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ReviveCountdown
{
	internal sealed class LocalizedConfig : IDisposable
	{
		internal sealed class Row
		{
			public string LegacySection;

			public string LegacyKey;

			public string EnSection;

			public string ZhSection;

			public string EnKey;

			public string ZhKey;

			public string EnDescription;

			public string ZhDescription;

			public ConfigDefinition Definition(bool zh)
			{
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Expected O, but got Unknown
				return new ConfigDefinition(zh ? ZhSection : EnSection, zh ? ZhKey : EnKey);
			}

			public string Description(bool zh)
			{
				if (!zh)
				{
					return EnDescription;
				}
				return ZhDescription;
			}
		}

		internal static readonly Row LanguageRow = new Row
		{
			LegacySection = "Interface",
			LegacyKey = "Language",
			EnSection = "0.Language",
			ZhSection = "0.语言",
			EnKey = "Language 语言",
			ZhKey = "Language 语言",
			EnDescription = "Select English or 简体中文 to switch this mod's configuration names, groups and descriptions immediately. Auto follows the game language (English fallback). No restart required.",
			ZhDescription = "选择 English 或 简体中文可立即切换本模组配置的分组、名称和说明,无需重启。Auto 跟随游戏语言,其他语言回退英文。"
		};

		internal static readonly Row EnabledRow = new Row
		{
			LegacySection = "General",
			LegacyKey = "Enabled",
			EnSection = "1.General",
			ZhSection = "1.常规",
			EnKey = "Enable mod",
			ZhKey = "启用模组",
			EnDescription = "Host only: this switch from the host's copy controls the whole room. When on, every dead player revives in place once their own countdown ends.",
			ZhDescription = "仅主机生效:房主这份配置的开关控制整个房间。开启后所有玩家死亡都会在各自倒计时结束后原地复活。"
		};

		internal static readonly Row DelayRow = new Row
		{
			LegacySection = "General",
			LegacyKey = "Delay",
			EnSection = "1.General",
			ZhSection = "1.常规",
			EnKey = "Revive delay (seconds)",
			ZhKey = "复活倒计时(秒)",
			EnDescription = "Seconds each dead player waits before reviving in place. Range 1-300, default 60. Every player has an independent timer that starts when they die.",
			ZhDescription = "每名玩家死亡后等待多少秒原地复活。范围 1–300,默认 60。倒计时在各自死亡时开始,互不影响。"
		};

		internal static readonly Row WipeRow = new Row
		{
			LegacySection = "General",
			LegacyKey = "BlockWipe",
			EnSection = "1.General",
			ZhSection = "1.常规",
			EnKey = "Pause team-wipe ending",
			ZhKey = "团灭时暂停换关",
			EnDescription = "When on, all players dying at once no longer ends the level, so everyone can wait for their own countdown. Turn off for vanilla behaviour: a full team wipe ends the level immediately and unfinished countdowns do not apply.",
			ZhDescription = "开启时,全员阵亡不会立即判负换关,大家会等各自的复活倒计时。关闭则保持原版:全员死亡立刻结束本关,尚未走完的倒计时不会生效。"
		};

		private readonly ConfigFile config;

		private readonly Func<bool> gameIsChinese;

		private readonly Action<string> warn;

		private readonly Dictionary<Row, ConfigEntryBase> entries = new Dictionary<Row, ConfigEntryBase>();

		public ConfigEntry<string> Language { get; }

		public ConfigEntry<bool> Enabled { get; }

		public ConfigEntry<int> Delay { get; }

		public ConfigEntry<bool> BlockTeamWipe { get; }

		public bool Chinese { get; private set; }

		public event Action Changed;

		public LocalizedConfig(ConfigFile config, Func<bool> gameIsChinese, Action<string> warn)
		{
			this.config = config;
			this.gameIsChinese = gameIsChinese;
			this.warn = warn;
			bool saveOnConfigSet = config.SaveOnConfigSet;
			config.SaveOnConfigSet = false;
			try
			{
				Language = Bind(LanguageRow, "Auto", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Auto", "English", "简体中文" }));
				Chinese = ResolveLanguage();
				Enabled = Bind(EnabledRow, fallback: true);
				Delay = Bind(DelayRow, 60, (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 300));
				BlockTeamWipe = Bind(WipeRow, fallback: true);
				Apply(notify: false);
				RemoveObsoleteEntries();
				config.Save();
			}
			finally
			{
				config.SaveOnConfigSet = saveOnConfigSet;
			}
			Language.SettingChanged += LanguageChanged;
		}

		private ConfigEntry<T> Bind<T>(Row row, T fallback, AcceptableValueBase range = null)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			string text = FindSaved(row);
			ConfigEntry<T> val = config.Bind<T>(row.Definition(Chinese), fallback, new ConfigDescription(row.Description(Chinese), range, Array.Empty<object>()));
			if (text != null)
			{
				((ConfigEntryBase)val).SetSerializedValue(text);
			}
			entries.Add(row, (ConfigEntryBase)(object)val);
			return val;
		}

		private string FindSaved(Row row)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			if (!(Member(config, "OrphanedEntries") is IDictionary dictionary))
			{
				return null;
			}
			ConfigDefinition[] array = (ConfigDefinition[])(object)new ConfigDefinition[3]
			{
				row.Definition(Chinese),
				row.Definition(!Chinese),
				new ConfigDefinition(row.LegacySection, row.LegacyKey)
			};
			foreach (ConfigDefinition key in array)
			{
				if (dictionary.Contains(key))
				{
					return dictionary[key] as string;
				}
			}
			return null;
		}

		private void RemoveObsoleteEntries()
		{
			if (!(Member(config, "OrphanedEntries") is IDictionary dictionary))
			{
				return;
			}
			List<object> list = new List<object>();
			foreach (DictionaryEntry item in dictionary)
			{
				object key = item.Key;
				ConfigDefinition key2 = (ConfigDefinition)((key is ConfigDefinition) ? key : null);
				if (key2 != null && entries.Keys.Any((Row row) => key2.Equals(row.Definition(zh: false)) || key2.Equals(row.Definition(zh: true)) || key2.Equals(new ConfigDefinition(row.LegacySection, row.LegacyKey))))
				{
					list.Add(item.Key);
				}
			}
			foreach (object item2 in list)
			{
				dictionary.Remove(item2);
			}
		}

		public void ConsumeLanguageDraft(IDictionary pending, IDictionary originals)
		{
			if (pending == null || !pending.Contains(Language))
			{
				return;
			}
			string text = pending[Language] as string;
			if (text != "Auto" && text != "English" && text != "简体中文")
			{
				return;
			}
			pending.Remove(Language);
			try
			{
				Language.Value = text;
				if (originals != null)
				{
					originals[Language] = Language.Value;
				}
			}
			catch
			{
				pending[Language] = text;
				throw;
			}
		}

		public string TranslateLabel(string value)
		{
			foreach (Row key in entries.Keys)
			{
				if (value == key.EnSection || value == key.ZhSection)
				{
					return Chinese ? key.ZhSection : key.EnSection;
				}
				if (value == key.EnKey || value == key.ZhKey)
				{
					return Chinese ? key.ZhKey : key.EnKey;
				}
				if (value == key.EnDescription || value == key.ZhDescription)
				{
					return key.Description(Chinese);
				}
			}
			return value;
		}

		private bool ResolveLanguage()
		{
			if (Language != null)
			{
				if (!(Language.Value == "简体中文"))
				{
					if (Language.Value == "Auto")
					{
						return gameIsChinese();
					}
					return false;
				}
				return true;
			}
			return false;
		}

		private void LanguageChanged(object sender, EventArgs args)
		{
			Apply(notify: true);
		}

		public void Tick()
		{
			if (ResolveLanguage() != Chinese)
			{
				Apply(notify: true);
			}
		}

		private void Apply(bool notify)
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			Chinese = ResolveLanguage();
			try
			{
				IDictionary dictionary = (Member(config, "Entries") as IDictionary) ?? throw new MissingFieldException("ConfigFile.Entries");
				foreach (KeyValuePair<Row, ConfigEntryBase> entry in entries)
				{
					ConfigEntryBase value = entry.Value;
					dictionary.Remove(value.Definition);
					SetBacking(value, "Definition", entry.Key.Definition(Chinese));
					SetBacking(value, "Description", (object)new ConfigDescription(entry.Key.Description(Chinese), value.Description.AcceptableValues, value.Description.Tags));
					dictionary.Add(value.Definition, value);
				}
				RemoveObsoleteEntries();
				config.Save();
				if (notify)
				{
					this.Changed?.Invoke();
				}
			}
			catch (Exception ex)
			{
				warn("Configuration localization failed: " + ex);
			}
		}

		internal static object Member(object instance, string name)
		{
			Type type = instance.GetType();
			while (type != null)
			{
				FieldInfo fieldInfo = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? type.GetField("<" + name + ">k__BackingField", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (fieldInfo != null)
				{
					return fieldInfo.GetValue(instance);
				}
				PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (property != null)
				{
					return property.GetValue(instance);
				}
				type = type.BaseType;
			}
			return null;
		}

		private static void SetBacking(object instance, string name, object value)
		{
			Type type = instance.GetType();
			while (type != null)
			{
				FieldInfo field = type.GetField("<" + name + ">k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field != null)
				{
					field.SetValue(instance, value);
					return;
				}
				type = type.BaseType;
			}
			throw new MissingFieldException(instance.GetType().Name, name);
		}

		public void Dispose()
		{
			Language.SettingChanged -= LanguageChanged;
		}
	}
	[BepInPlugin("com.yanyan.repo.revivecountdown", "Revive Countdown 复活倒计时", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Id = "com.yanyan.repo.revivecountdown";

		public const string Version = "1.0.0";

		internal static Plugin Instance;

		internal static ManualLogSource Log;

		private LocalizedConfig settings;

		private readonly ReviveTimer<PlayerAvatar> timer = new ReviveTimer<PlayerAvatar>();

		private Harmony harmony;

		private bool blockOwned;

		private float nextError;

		private void Awake()
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			settings = new LocalizedConfig(((BaseUnityPlugin)this).Config, GameIsChinese, delegate(string message)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)message);
			});
			settings.Enabled.SettingChanged += OnEnabledChanged;
			harmony = new Harmony("com.yanyan.repo.revivecountdown");
			RepoConfigBridge.Initialize(settings, harmony);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Revive Countdown 1.0.0 loaded. Host only: every dead player revives in place after the configured countdown.");
		}

		private void OnDestroy()
		{
			if (settings != null)
			{
				settings.Enabled.SettingChanged -= OnEnabledChanged;
				settings.Dispose();
			}
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			RepoConfigBridge.Shutdown();
			timer.Clear();
			SetAllDeadBlock(want: false);
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}

		private void OnEnabledChanged(object sender, EventArgs e)
		{
			if (!settings.Enabled.Value)
			{
				timer.Clear();
				SetAllDeadBlock(want: false);
			}
		}

		private static bool GameIsChinese()
		{
			try
			{
				return (SemiFunc.LocaleGetCode() ?? "en").StartsWith("zh", StringComparison.OrdinalIgnoreCase);
			}
			catch
			{
				return false;
			}
		}

		private void Update()
		{
			RepoConfigBridge.Tick();
			settings.Tick();
			try
			{
				Tick();
			}
			catch (Exception ex)
			{
				if (!(Time.unscaledTime < nextError))
				{
					nextError = Time.unscaledTime + 10f;
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Revive countdown skipped: " + ex));
				}
			}
		}

		private void Tick()
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Invalid comparison between Unknown and I4
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Invalid comparison between Unknown and I4
			if (!settings.Enabled.Value || !HostReady())
			{
				timer.Clear();
				SetAllDeadBlock(want: false);
				return;
			}
			bool flag = AllowedContext();
			SetAllDeadBlock(flag && settings.BlockTeamWipe.Value);
			if (!flag)
			{
				timer.Clear();
				return;
			}
			GameDirector instance = GameDirector.instance;
			if (!Object.op_Implicit((Object)(object)instance) || ((int)instance.currentState != 2 && (int)instance.currentState != 7))
			{
				return;
			}
			float time = Time.time;
			int value = settings.Delay.Value;
			List<PlayerAvatar> playerList = instance.PlayerList;
			for (int i = 0; i < playerList.Count; i++)
			{
				PlayerAvatar val = playerList[i];
				if (Object.op_Implicit((Object)(object)val))
				{
					bool deadSet = val.deadSet;
					if (timer.Observe(val, deadSet, time))
					{
						((BaseUnityPlugin)this).Logger.LogInfo((object)("ReviveCountdown: " + NameOf(val) + " died, countdown " + value + " s"));
					}
					if (deadSet && CanRevive(val) && timer.Due(val, time, value))
					{
						((BaseUnityPlugin)this).Logger.LogInfo((object)("ReviveCountdown: " + NameOf(val) + " reviving after " + timer.Elapsed(val, time).ToString("0.0") + " s"));
						val.Revive(false);
					}
				}
			}
			timer.Prune(playerList);
		}

		private static bool HostReady()
		{
			if (Object.op_Implicit((Object)(object)GameManager.instance))
			{
				return SemiFunc.IsMasterClientOrSingleplayer();
			}
			return false;
		}

		private static bool AllowedContext()
		{
			RunManager instance = RunManager.instance;
			if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)instance.levelCurrent))
			{
				return false;
			}
			if (SemiFunc.MenuLevel() || SemiFunc.RunIsArena())
			{
				return false;
			}
			if (!SemiFunc.RunIsLevel() && !SemiFunc.RunIsShop())
			{
				return SemiFunc.RunIsLobby();
			}
			return true;
		}

		private static bool CanRevive(PlayerAvatar player)
		{
			//IL_0053: 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)
			if (!Object.op_Implicit((Object)(object)player) || !player.deadSet)
			{
				return false;
			}
			PlayerDeathHead playerDeathHead = player.playerDeathHead;
			if (!Object.op_Implicit((Object)(object)playerDeathHead) || !playerDeathHead.setup || !playerDeathHead.triggered)
			{
				return false;
			}
			return (Object.op_Implicit((Object)(object)playerDeathHead.physGrabObject) ? playerDeathHead.physGrabObject.centerPoint : ((Component)playerDeathHead).transform.position).y <= 1000f;
		}

		private void SetAllDeadBlock(bool want)
		{
			RunManager instance = RunManager.instance;
			if (!Object.op_Implicit((Object)(object)instance))
			{
				blockOwned = false;
			}
			else if (want)
			{
				if (!instance.allPlayersDeadCheckDisabled)
				{
					instance.allPlayersDeadCheckDisabled = true;
					blockOwned = true;
				}
			}
			else if (blockOwned)
			{
				instance.allPlayersDeadCheckDisabled = false;
				blockOwned = false;
			}
		}

		private static string NameOf(PlayerAvatar player)
		{
			string text = null;
			try
			{
				text = player.playerName;
			}
			catch
			{
			}
			if (!string.IsNullOrEmpty(text))
			{
				return text;
			}
			return "player";
		}
	}
	internal static class RepoConfigBridge
	{
		private static LocalizedConfig settings;

		private static Func<IDictionary> pendingValues;

		private static Func<IDictionary> originalValues;

		private static Component currentPage;

		private static bool relabel;

		private static bool warned;

		public static void Initialize(LocalizedConfig value, Harmony harmony)
		{
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Expected O, but got Unknown
			settings = value;
			settings.Changed += LanguageChanged;
			Type type = AccessTools.TypeByName("REPOConfig.ConfigMenu");
			if (type == null)
			{
				return;
			}
			try
			{
				MethodInfo methodInfo = AccessTools.GetDeclaredMethods(type).Single((MethodInfo m) => m.Name == "CreateModEntries" && m.GetParameters().Length == 2);
				FieldInfo pendingField = AccessTools.Field(type, "changedEntryValues");
				FieldInfo originalField = AccessTools.Field(type, "originalEntryValues");
				if (pendingField != null && originalField != null)
				{
					pendingValues = () => pendingField.GetValue(null) as IDictionary;
					originalValues = () => originalField.GetValue(null) as IDictionary;
				}
				else
				{
					FieldInfo storeField = AccessTools.Field(type, "configEntryStore");
					Type type2 = AccessTools.TypeByName("REPOConfig.ConfigEntryStore");
					PropertyInfo pendingProperty = ((type2 == null) ? null : AccessTools.Property(type2, "ChangedEntryValues"));
					PropertyInfo originalProperty = ((type2 == null) ? null : AccessTools.Property(type2, "OriginalEntryValues"));
					if (storeField == null || pendingProperty == null || originalProperty == null)
					{
						throw new MissingFieldException("REPOConfig configuration dictionaries");
					}
					pendingValues = delegate
					{
						object value2 = storeField.GetValue(null);
						return (value2 == null) ? null : (pendingProperty.GetValue(value2) as IDictionary);
					};
					originalValues = delegate
					{
						object value2 = storeField.GetValue(null);
						return (value2 == null) ? null : (originalProperty.GetValue(value2) as IDictionary);
					};
				}
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(RepoConfigBridge), "PageCreated", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			catch (Exception e)
			{
				Warn(e);
			}
		}

		private static void PageCreated(object __0, ConfigEntryBase[] __1)
		{
			if (settings != null && __1.Any((ConfigEntryBase entry) => (object)entry == settings.Language) && !__1.Any((ConfigEntryBase entry) => entry.ConfigFile != ((ConfigEntryBase)settings.Language).ConfigFile))
			{
				currentPage = (Component)((__0 is Component) ? __0 : null);
				relabel = true;
			}
		}

		private static void LanguageChanged()
		{
			relabel = true;
		}

		public static void Tick()
		{
			if (settings == null)
			{
				return;
			}
			try
			{
				settings.ConsumeLanguageDraft(pendingValues?.Invoke(), originalValues?.Invoke());
				if (relabel && Object.op_Implicit((Object)(object)currentPage))
				{
					relabel = false;
					RelabelCurrentPage();
				}
			}
			catch (Exception e)
			{
				Warn(e);
			}
		}

		private static void RelabelCurrentPage()
		{
			TMP_Text[] componentsInChildren = currentPage.GetComponentsInChildren<TMP_Text>(true);
			foreach (TMP_Text val in componentsInChildren)
			{
				val.text = settings.TranslateLabel(val.text);
			}
		}

		private static void Warn(Exception e)
		{
			if (!warned)
			{
				warned = true;
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("REPOConfig live-label adapter unavailable: " + e.Message));
				}
			}
		}

		public static void Shutdown()
		{
			if (settings != null)
			{
				settings.Changed -= LanguageChanged;
			}
			settings = null;
			currentPage = null;
			pendingValues = (originalValues = null);
			relabel = false;
			warned = false;
		}
	}
	internal sealed class ReviveTimer<T> where T : class
	{
		private sealed class Entry
		{
			public float Since;

			public bool Waiting;

			public float RetryAt;
		}

		private readonly Dictionary<T, Entry> entries = new Dictionary<T, Entry>();

		private readonly HashSet<T> present = new HashSet<T>();

		private readonly List<T> drop = new List<T>();

		private readonly float retrySeconds;

		public int Count => entries.Count;

		public ReviveTimer(float retrySeconds = 2f)
		{
			this.retrySeconds = retrySeconds;
		}

		public bool Contains(T player)
		{
			return entries.ContainsKey(player);
		}

		public bool Observe(T player, bool dead, float now)
		{
			if (!dead)
			{
				entries.Remove(player);
				return false;
			}
			if (entries.ContainsKey(player))
			{
				return false;
			}
			entries[player] = new Entry
			{
				Since = now
			};
			return true;
		}

		public bool Due(T player, float now, float seconds)
		{
			if (!entries.TryGetValue(player, out var value))
			{
				return false;
			}
			if (value.Waiting)
			{
				if (now < value.RetryAt)
				{
					return false;
				}
				value.RetryAt = now + retrySeconds;
				return true;
			}
			if (now - value.Since < seconds)
			{
				return false;
			}
			value.Waiting = true;
			value.RetryAt = now + retrySeconds;
			return true;
		}

		public float Elapsed(T player, float now)
		{
			if (!entries.TryGetValue(player, out var value))
			{
				return 0f;
			}
			return now - value.Since;
		}

		public void Prune(IList<T> current)
		{
			if (entries.Count == 0)
			{
				return;
			}
			present.Clear();
			for (int i = 0; i < current.Count; i++)
			{
				if (current[i] != null)
				{
					present.Add(current[i]);
				}
			}
			drop.Clear();
			foreach (T key in entries.Keys)
			{
				if (!present.Contains(key))
				{
					drop.Add(key);
				}
			}
			for (int j = 0; j < drop.Count; j++)
			{
				entries.Remove(drop[j]);
			}
		}

		public void Clear()
		{
			entries.Clear();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}