Decompiled source of ValueRace v0.2.0

REPO_ValueRace.dll

Decompiled 18 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Steamworks;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Xiaohai")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("REPO_ValueRace")]
[assembly: AssemblyTitle("REPO_ValueRace")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 REPO_ValueRace
{
	[BepInPlugin("Xiaohai.REPO_ValueRace", "REPO_ValueRace", "0.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		public GameObject mainUI;

		public GameObject playerDataUI;

		public static Plugin instance { get; private set; }

		public static ManualLogSource logger => ((BaseUnityPlugin)instance).Logger;

		internal Harmony? Harmony { get; set; }

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

		private void LoadAB()
		{
			string location = Assembly.GetExecutingAssembly().Location;
			string directoryName = Path.GetDirectoryName(location);
			string text = Path.Combine(directoryName, "ui");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			mainUI = val.LoadAsset<GameObject>("RaceRank.prefab");
			playerDataUI = val.LoadAsset<GameObject>("PlayerDataUI.prefab");
			if ((Object)(object)mainUI != (Object)null && (Object)(object)playerDataUI != (Object)null)
			{
				logger.LogInfo((object)"UI加载成功.");
			}
			else
			{
				logger.LogError((object)"UI加载失败.");
			}
		}

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

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

		private void Update()
		{
			if (Object.op_Implicit((Object)(object)ValueRaceUIManager.instance) && ValueRaceUIManager.instance.dateDone && Input.GetKeyDown((KeyCode)107))
			{
				ValueRaceUIManager.instance.ShowUI(3f);
			}
		}
	}
	public class ValueRaceUIManager : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <HideLater>d__10 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public float time;

			public ValueRaceUIManager <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <HideLater>d__10(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(time);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if (Object.op_Implicit((Object)(object)<>4__this.Bg))
					{
						<>4__this.bgCg = <>4__this.Bg.GetComponent<CanvasGroup>();
						if (!Object.op_Implicit((Object)(object)<>4__this.bgCg))
						{
							<>4__this.bgCg = <>4__this.Bg.AddComponent<CanvasGroup>();
						}
						<>4__this.bgCg.alpha = 0f;
						<>4__this.bgCg.blocksRaycasts = false;
						<>4__this.bgCg.interactable = false;
					}
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private Transform RankTf;

		private GameObject playerDataUI;

		private HashSet<GameObject> playerDataUIList = new HashSet<GameObject>();

		private GameObject Bg;

		private CanvasGroup bgCg;

		public static ValueRaceUIManager instance;

		private bool isChinese = false;

		public bool dateDone = false;

		private void Awake()
		{
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			instance = this;
			if (Object.op_Implicit((Object)(object)Plugin.instance.playerDataUI))
			{
				playerDataUI = Plugin.instance.playerDataUI;
			}
			if (SteamClient.IsValid)
			{
				string steamUILanguage = SteamUtils.SteamUILanguage;
				Plugin.logger.LogInfo((object)("Steam客户端有效,当前语言:" + steamUILanguage));
				if (steamUILanguage.Contains("chinese"))
				{
					isChinese = true;
				}
			}
			GameObject val = GameObject.Find("HUDCanvas");
			if ((Object)(object)val == (Object)null)
			{
				GameObject val2 = GameObject.Find("UI");
				if ((Object)(object)val2 != (Object)null)
				{
					Transform val3 = val2.transform.Find("HUD/HUDCanvas");
					if ((Object)(object)val3 != (Object)null)
					{
						val = ((Component)val3).gameObject;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Canvas[] source = Object.FindObjectsOfType<Canvas>(true);
				Canvas val4 = ((IEnumerable<Canvas>)source).FirstOrDefault((Func<Canvas, bool>)((Canvas c) => ((Object)c).name.Contains("HUD")));
				if ((Object)(object)val4 != (Object)null)
				{
					val = ((Component)val4).gameObject;
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				((Component)this).transform.SetParent(val.transform, false);
			}
			else
			{
				Plugin.logger.LogWarning((object)"未找到 HUDCanvas,排行榜UI未挂载到HUD");
			}
			RankTf = ((Component)this).transform.Find("BG/Rank");
			if ((Object)(object)RankTf == (Object)null)
			{
				Transform val5 = ((IEnumerable<Transform>)((Component)this).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name.Equals("Rank")));
				if ((Object)(object)val5 != (Object)null)
				{
					RankTf = val5;
				}
			}
			Transform obj = ((Component)this).transform.Find("BG/Title");
			Text val6 = ((obj != null) ? ((Component)obj).GetComponent<Text>() : null);
			Transform obj2 = ((Component)this).transform.Find("BG/Rank/Title/rank");
			Text val7 = ((obj2 != null) ? ((Component)obj2).GetComponent<Text>() : null);
			Transform obj3 = ((Component)this).transform.Find("BG/Rank/Title/name");
			Text val8 = ((obj3 != null) ? ((Component)obj3).GetComponent<Text>() : null);
			Transform obj4 = ((Component)this).transform.Find("BG/Rank/Title/value");
			Text val9 = ((obj4 != null) ? ((Component)obj4).GetComponent<Text>() : null);
			Transform obj5 = ((Component)this).transform.Find("BG/Rank/Title/damage");
			Text val10 = ((obj5 != null) ? ((Component)obj5).GetComponent<Text>() : null);
			Transform obj6 = ((Component)this).transform.Find("BG/Rank/Title/final");
			Text val11 = ((obj6 != null) ? ((Component)obj6).GetComponent<Text>() : null);
			if (!isChinese)
			{
				if ((Object)(object)val6 != (Object)null)
				{
					val6.text = "Rankings";
				}
				if ((Object)(object)val7 != (Object)null)
				{
					val7.text = "Rank";
				}
				if ((Object)(object)val8 != (Object)null)
				{
					val8.text = "Name";
				}
				if ((Object)(object)val9 != (Object)null)
				{
					RectTransform component = ((Component)val9).GetComponent<RectTransform>();
					component.sizeDelta = new Vector2(component.sizeDelta.x + 15f, component.sizeDelta.y);
					val9.text = "Harvest$";
				}
				if ((Object)(object)val10 != (Object)null)
				{
					RectTransform component2 = ((Component)val10).GetComponent<RectTransform>();
					component2.sizeDelta = new Vector2(component2.sizeDelta.x + 15f, component2.sizeDelta.y);
					val10.text = "Broken$";
				}
				if ((Object)(object)val11 != (Object)null)
				{
					val11.text = "  Net$";
				}
			}
			Transform val12 = ((Component)this).transform.Find("BG");
			if ((Object)(object)val12 == (Object)null)
			{
				val12 = ((IEnumerable<Transform>)((Component)this).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name.Equals("BG") || ((Object)t).name.Equals("bg") || ((Object)t).name.Equals("Bg")));
			}
			if ((Object)(object)val12 != (Object)null)
			{
				Bg = ((Component)val12).gameObject;
				bgCg = Bg.GetComponent<CanvasGroup>();
				if (!Object.op_Implicit((Object)(object)bgCg))
				{
					bgCg = Bg.AddComponent<CanvasGroup>();
				}
				bgCg.alpha = 0f;
				bgCg.blocksRaycasts = false;
				bgCg.interactable = false;
				Bg.SetActive(true);
			}
			else
			{
				Plugin.logger.LogWarning((object)"未找到排行榜根节点 BG,UI显示将被跳过");
			}
		}

		public void ShowUI(float time)
		{
			if (time <= 0f)
			{
				time = 3f;
			}
			if (!Object.op_Implicit((Object)(object)Bg))
			{
				Transform val = ((Component)this).transform.Find("BG");
				if ((Object)(object)val == (Object)null)
				{
					val = ((IEnumerable<Transform>)((Component)this).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name.Equals("BG") || ((Object)t).name.Equals("bg") || ((Object)t).name.Equals("Bg")));
				}
				if ((Object)(object)val != (Object)null)
				{
					Bg = ((Component)val).gameObject;
				}
			}
			GameObject val2 = GameObject.Find("HUDCanvas");
			if ((Object)(object)val2 == (Object)null)
			{
				GameObject val3 = GameObject.Find("UI");
				if ((Object)(object)val3 != (Object)null)
				{
					Transform val4 = val3.transform.Find("HUD/HUDCanvas");
					if ((Object)(object)val4 != (Object)null)
					{
						val2 = ((Component)val4).gameObject;
					}
				}
			}
			if ((Object)(object)val2 == (Object)null)
			{
				Canvas[] source = Object.FindObjectsOfType<Canvas>(true);
				Canvas val5 = ((IEnumerable<Canvas>)source).FirstOrDefault((Func<Canvas, bool>)((Canvas c) => ((Object)c).name.Contains("HUD")));
				if ((Object)(object)val5 != (Object)null)
				{
					val2 = ((Component)val5).gameObject;
				}
			}
			if ((Object)(object)val2 != (Object)null && (Object)(object)((Component)this).transform.parent != (Object)(object)val2.transform)
			{
				((Component)this).transform.SetParent(val2.transform, false);
			}
			if (!Object.op_Implicit((Object)(object)Bg))
			{
				Plugin.logger.LogWarning((object)"ShowUI 被调用但未找到 BG 节点,已跳过显示");
				return;
			}
			bgCg = Bg.GetComponent<CanvasGroup>();
			if (!Object.op_Implicit((Object)(object)bgCg))
			{
				bgCg = Bg.AddComponent<CanvasGroup>();
			}
			bgCg.alpha = 1f;
			bgCg.blocksRaycasts = true;
			bgCg.interactable = true;
			((MonoBehaviour)this).StopAllCoroutines();
			((MonoBehaviour)this).StartCoroutine(HideLater(time));
		}

		[IteratorStateMachine(typeof(<HideLater>d__10))]
		private IEnumerator HideLater(float time)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <HideLater>d__10(0)
			{
				<>4__this = this,
				time = time
			};
		}

		public void ClearRankUI()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			if ((Object)(object)RankTf == (Object)null)
			{
				return;
			}
			foreach (Transform item in RankTf)
			{
				Transform val = item;
				if (!(((Object)val).name == "Title"))
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
			playerDataUIList.Clear();
		}

		public void AddPlayerDataUI(string rank, string name, string value, string damage, string final)
		{
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)RankTf == (Object)null) && !((Object)(object)playerDataUI == (Object)null))
			{
				Transform obj = playerDataUI.transform.Find("RankText");
				Text val = ((obj != null) ? ((Component)obj).GetComponent<Text>() : null);
				Transform obj2 = playerDataUI.transform.Find("Name");
				Text val2 = ((obj2 != null) ? ((Component)obj2).GetComponent<Text>() : null);
				Transform obj3 = playerDataUI.transform.Find("Value");
				Text val3 = ((obj3 != null) ? ((Component)obj3).GetComponent<Text>() : null);
				Transform obj4 = playerDataUI.transform.Find("Damage");
				Text val4 = ((obj4 != null) ? ((Component)obj4).GetComponent<Text>() : null);
				Transform obj5 = playerDataUI.transform.Find("Final");
				Text val5 = ((obj5 != null) ? ((Component)obj5).GetComponent<Text>() : null);
				if ((Object)(object)val != (Object)null)
				{
					val.text = rank;
				}
				if ((Object)(object)val2 != (Object)null)
				{
					val2.text = name;
				}
				if ((Object)(object)val3 != (Object)null)
				{
					val3.text = value;
				}
				if ((Object)(object)val4 != (Object)null)
				{
					val4.text = damage;
				}
				if ((Object)(object)val5 != (Object)null)
				{
					val5.text = final;
				}
				GameObject val6 = Object.Instantiate<GameObject>(playerDataUI, RankTf);
				if (playerDataUIList.Count > 0)
				{
					RectTransform component = playerDataUIList.Last().GetComponent<RectTransform>();
					RectTransform component2 = val6.GetComponent<RectTransform>();
					Vector2 anchoredPosition = component2.anchoredPosition;
					component2.anchoredPosition = new Vector2(anchoredPosition.x, component.anchoredPosition.y - 25f);
				}
				playerDataUIList.Add(val6);
				if (playerDataUIList.Count > 11 && playerDataUIList.Count < 15)
				{
					float num = 1f - (float)(playerDataUIList.Count - 11) * 0.1f;
					RankTf.localScale = new Vector3(1f, num, 1f);
				}
			}
		}

		public void ApplyRankData(string[] ranks, string[] names, string[] values, string[] damages, string[] finals)
		{
			ClearRankUI();
			int num = Mathf.Min(new int[5]
			{
				(ranks != null) ? ranks.Length : 0,
				(names != null) ? names.Length : 0,
				(values != null) ? values.Length : 0,
				(damages != null) ? damages.Length : 0,
				(finals != null) ? finals.Length : 0
			});
			for (int i = 0; i < num; i++)
			{
				AddPlayerDataUI(ranks[i], names[i], values[i], damages[i], finals[i]);
			}
			dateDone = true;
		}
	}
	[HarmonyPatch]
	public static class Patch
	{
		[HarmonyPatch(typeof(ValuableObject))]
		public static class ValuableObject_Patch
		{
			[HarmonyPostfix]
			[HarmonyPatch("Awake")]
			public static void Awake_Postfix(ValuableObject __instance)
			{
				if (SemiFunc.IsMasterClientOrSingleplayer() && (Object)(object)((Component)__instance).gameObject.GetComponent<ValueRaceTracker>() == (Object)null)
				{
					((Component)__instance).gameObject.AddComponent<ValueRaceTracker>().Init(__instance);
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch("Update")]
			public static void Update_Postfix(ValuableObject __instance)
			{
				if (SemiFunc.IsMasterClientOrSingleplayer())
				{
					ValueRaceTracker valueRaceTracker = ((Component)__instance).gameObject.GetComponent<ValueRaceTracker>();
					if ((Object)(object)valueRaceTracker == (Object)null)
					{
						valueRaceTracker = ((Component)__instance).gameObject.AddComponent<ValueRaceTracker>();
						valueRaceTracker.Init(__instance);
					}
					valueRaceTracker.Tick();
				}
			}
		}

		[HarmonyPatch(typeof(RoundDirector))]
		public static class RoundDirector_Patch
		{
			[HarmonyPostfix]
			[HarmonyPatch("Awake")]
			public static void Awake_Postfix(RoundDirector __instance)
			{
				if ((Object)(object)__instance != (Object)null && (Object)(object)((Component)__instance).gameObject.GetComponent<ValueRaceNet>() == (Object)null)
				{
					((Component)__instance).gameObject.AddComponent<ValueRaceNet>();
					Plugin.logger.LogInfo((object)"已在RoundDirector上添加ValueRaceNet用于排行榜同步");
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch("ExtractionCompletedAllRPC")]
			public static void ExtractionCompletedAll_Postfix()
			{
				if (!SemiFunc.IsMasterClientOrSingleplayer())
				{
					return;
				}
				ComputeFinal();
				List<KeyValuePair<PlayerAvatar, float>> list = playerFinal.OrderByDescending<KeyValuePair<PlayerAvatar, float>, float>((KeyValuePair<PlayerAvatar, float> kv) => kv.Value).ToList();
				int count = list.Count;
				string[] array = new string[count];
				string[] array2 = new string[count];
				string[] array3 = new string[count];
				string[] array4 = new string[count];
				string[] array5 = new string[count];
				for (int i = 0; i < count; i++)
				{
					KeyValuePair<PlayerAvatar, float> keyValuePair = list[i];
					PlayerAvatar key = keyValuePair.Key;
					string text = (((Object)(object)key != (Object)null) ? key.playerName : "未知玩家");
					float value;
					float num = (playerGained.TryGetValue(key, out value) ? value : 0f);
					float value2;
					float num2 = (playerDamaged.TryGetValue(key, out value2) ? value2 : 0f);
					Plugin.logger.LogInfo((object)$"排名{i + 1}: 玩家{text} 最终总价值: {keyValuePair.Value:F2} (获得: {num:F2}, 破坏: {num2:F2})");
					array[i] = (i + 1).ToString();
					array2[i] = text;
					array3[i] = num.ToString("F0");
					array4[i] = num2.ToString("F0");
					array5[i] = (num - num2).ToString("F0");
				}
				lastRanks = array;
				lastNames = array2;
				lastValues = array3;
				lastDamages = array4;
				lastFinals = array5;
				hasRankData = true;
				RoundDirector instance = RoundDirector.instance;
				ValueRaceNet valueRaceNet = ((instance != null) ? ((Component)instance).gameObject.GetComponent<ValueRaceNet>() : null);
				if (!Object.op_Implicit((Object)(object)valueRaceNet))
				{
					RoundDirector instance2 = RoundDirector.instance;
					valueRaceNet = ((instance2 != null) ? ((Component)instance2).gameObject.AddComponent<ValueRaceNet>() : null);
				}
				if (SemiFunc.IsMultiplayer())
				{
					if (Object.op_Implicit((Object)(object)valueRaceNet) && (Object)(object)((MonoBehaviourPun)valueRaceNet).photonView != (Object)null)
					{
						((MonoBehaviourPun)valueRaceNet).photonView.RPC("RPC_SetRankData", (RpcTarget)3, new object[5] { array, array2, array3, array4, array5 });
					}
					else
					{
						Plugin.logger.LogWarning((object)"未找到用于同步的 ValueRaceNet 或 PhotonView。排行榜数据未广播。");
					}
				}
				else if (Object.op_Implicit((Object)(object)ValueRaceUIManager.instance))
				{
					ValueRaceUIManager.instance.ApplyRankData(array, array2, array3, array4, array5);
				}
			}
		}

		[HarmonyPatch(typeof(LevelGenerator))]
		public static class LevelGenerator_Patch
		{
			[HarmonyPostfix]
			[HarmonyPatch("GenerateDone")]
			public static void GenerateDone_Postfix()
			{
				if (SemiFunc.RunIsLevel())
				{
					if ((Object)(object)ValueRaceUIManager.instance != (Object)null)
					{
						GameObject val = Object.Instantiate<GameObject>(Plugin.instance.mainUI);
						if ((Object)(object)val != (Object)null)
						{
							Plugin.logger.LogInfo((object)"UI实例化成功");
							val.AddComponent<ValueRaceUIManager>();
							Object.DontDestroyOnLoad((Object)(object)val);
						}
					}
					if (SemiFunc.IsMasterClientOrSingleplayer())
					{
						playerGained.Clear();
						playerDamaged.Clear();
						playerFinal.Clear();
						extractionPointValueable.Clear();
						ValueRaceUIManager.instance.dateDone = false;
						hasRankData = false;
						lastRanks = null;
						lastNames = null;
						lastValues = null;
						lastDamages = null;
						lastFinals = null;
					}
				}
				else
				{
					if (!SemiFunc.RunIsShop())
					{
						return;
					}
					if (!Object.op_Implicit((Object)(object)ValueRaceUIManager.instance))
					{
						GameObject val2 = Object.Instantiate<GameObject>(Plugin.instance.mainUI);
						if ((Object)(object)val2 != (Object)null)
						{
							Plugin.logger.LogInfo((object)"商店场景:UI缺失,已重新实例化");
							val2.AddComponent<ValueRaceUIManager>();
							Object.DontDestroyOnLoad((Object)(object)val2);
						}
						else
						{
							Plugin.logger.LogWarning((object)"商店场景:UI实例化失败,无法显示排行榜界面");
						}
					}
					if (hasRankData)
					{
						ValueRaceUIManager.instance?.ApplyRankData(lastRanks, lastNames, lastValues, lastDamages, lastFinals);
					}
					ValueRaceUIManager.instance?.ShowUI(5f);
				}
			}
		}

		public static Dictionary<PlayerAvatar, float> playerGained = new Dictionary<PlayerAvatar, float>();

		public static Dictionary<PlayerAvatar, float> playerDamaged = new Dictionary<PlayerAvatar, float>();

		public static Dictionary<PlayerAvatar, float> playerFinal = new Dictionary<PlayerAvatar, float>();

		public static HashSet<ValuableObject> extractionPointValueable = new HashSet<ValuableObject>();

		public static string[] lastRanks;

		public static string[] lastNames;

		public static string[] lastValues;

		public static string[] lastDamages;

		public static string[] lastFinals;

		public static bool hasRankData;

		public static void AddGain(PlayerAvatar player, float value)
		{
			if (!((Object)(object)player == (Object)null))
			{
				if (playerGained.TryGetValue(player, out var value2))
				{
					playerGained[player] = value2 + value;
				}
				else
				{
					playerGained[player] = value;
				}
			}
		}

		public static void AddDamage(PlayerAvatar player, float value)
		{
			if (!((Object)(object)player == (Object)null))
			{
				if (playerDamaged.TryGetValue(player, out var value2))
				{
					playerDamaged[player] = value2 + value;
				}
				else
				{
					playerDamaged[player] = value;
				}
			}
		}

		public static void ComputeFinal()
		{
			playerFinal.Clear();
			foreach (PlayerAvatar item in playerGained.Keys.Union(playerDamaged.Keys))
			{
				float value;
				float num = (playerGained.TryGetValue(item, out value) ? value : 0f);
				float value2;
				float num2 = (playerDamaged.TryGetValue(item, out value2) ? value2 : 0f);
				playerFinal[item] = num - num2;
			}
		}
	}
	public class ValueRaceNet : MonoBehaviourPun
	{
		[PunRPC]
		public void RPC_SetRankData(string[] ranks, string[] names, string[] values, string[] damages, string[] finals)
		{
			Patch.lastRanks = ranks;
			Patch.lastNames = names;
			Patch.lastValues = values;
			Patch.lastDamages = damages;
			Patch.lastFinals = finals;
			Patch.hasRankData = true;
			if (Object.op_Implicit((Object)(object)ValueRaceUIManager.instance))
			{
				ValueRaceUIManager.instance.ApplyRankData(ranks, names, values, damages, finals);
			}
		}
	}
	public class ValueRaceTracker : MonoBehaviour
	{
		public Dictionary<PlayerAvatar, float> GrabDurations = new Dictionary<PlayerAvatar, float>();

		public float LastValue;

		public bool Extracted;

		public ValuableObject Obj { get; private set; }

		public void Init(ValuableObject obj)
		{
			Obj = obj;
			LastValue = (((Object)(object)Obj != (Object)null) ? Obj.dollarValueCurrent : 0f);
			Extracted = false;
		}

		public void Tick()
		{
			if (!SemiFunc.IsMasterClientOrSingleplayer() || (Object)(object)Obj == (Object)null)
			{
				return;
			}
			PhysGrabObject physGrabObject = Obj.physGrabObject;
			RoomVolumeCheck roomVolumeCheck = Obj.roomVolumeCheck;
			PlayerAvatar val = null;
			if ((Object)(object)physGrabObject != (Object)null)
			{
				val = physGrabObject.lastPlayerGrabbing;
			}
			if ((Object)(object)val != (Object)null && !Extracted)
			{
				if (GrabDurations.TryGetValue(val, out var value))
				{
					GrabDurations[val] = value + Time.deltaTime;
				}
				else
				{
					GrabDurations[val] = Time.deltaTime;
				}
			}
			if (!Extracted)
			{
				float dollarValueCurrent = Obj.dollarValueCurrent;
				if (dollarValueCurrent < LastValue)
				{
					PlayerAvatar val2 = null;
					if ((Object)(object)physGrabObject != (Object)null)
					{
						val2 = physGrabObject.lastPlayerGrabbing;
					}
					float num = LastValue - dollarValueCurrent;
					if (num > 0f && (Object)(object)val2 != (Object)null)
					{
						Patch.AddDamage(val2, num);
					}
					LastValue = dollarValueCurrent;
				}
				else
				{
					LastValue = dollarValueCurrent;
				}
			}
			if (Extracted || !((Object)(object)roomVolumeCheck != (Object)null) || !roomVolumeCheck.inExtractionPoint || Patch.extractionPointValueable.Contains(Obj))
			{
				return;
			}
			if (GrabDurations.Count > 0)
			{
				PlayerAvatar key = GrabDurations.OrderByDescending<KeyValuePair<PlayerAvatar, float>, float>((KeyValuePair<PlayerAvatar, float> kv) => kv.Value).First().Key;
				Patch.AddGain(key, Obj.dollarValueCurrent);
				Plugin.logger.LogInfo((object)$"玩家{key.playerName} 获得了价值{Obj.dollarValueCurrent} 的废料");
			}
			Patch.extractionPointValueable.Add(Obj);
			Extracted = true;
		}
	}
}