Decompiled source of CharacterStats v1.0.0

Character Stats.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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 UnityEngine;

[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("headclef")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+083b765b8776ea7b80a25c9835c2dc5fb287a646")]
[assembly: AssemblyProduct("Character Stats")]
[assembly: AssemblyTitle("Character Stats")]
[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 Character_Stats
{
	[BepInPlugin("headclef.CharacterStats", "Character Stats", "1.0.0")]
	public class Character_Stats : BaseUnityPlugin
	{
		private const string PluginGuid = "headclef.CharacterStats";

		private const string PluginName = "Character Stats";

		private const string PluginVersion = "1.0.0";

		private static readonly Dictionary<string, Dictionary<string, int>> _playerStats = new Dictionary<string, Dictionary<string, int>>();

		private static bool _statsReady;

		internal static Character_Stats Instance { get; private set; } = null;


		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		public static bool AreStatsReady => _statsReady;

		private void Awake()
		{
			//IL_0041: 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_0048: Expected O, but got Unknown
			//IL_004d: Expected O, but got Unknown
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

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

		public static int GetUpgradeLevel(string steamId, string upgradeKey)
		{
			if (_playerStats.TryGetValue(steamId, out Dictionary<string, int> value) && value.TryGetValue(upgradeKey, out var value2))
			{
				return value2;
			}
			return 0;
		}

		public static Dictionary<string, int> GetAllUpgrades(string steamId)
		{
			if (_playerStats.TryGetValue(steamId, out Dictionary<string, int> value))
			{
				return new Dictionary<string, int>(value);
			}
			return new Dictionary<string, int>();
		}

		public static IEnumerable<string> GetTrackedPlayers()
		{
			return _playerStats.Keys;
		}

		public static string? GetLocalSteamId()
		{
			return PlayerController.instance?.playerSteamID;
		}

		internal static void RefreshStats()
		{
			_playerStats.Clear();
			List<PlayerAvatar> list = SemiFunc.PlayerGetAll();
			if (list == null || list.Count == 0)
			{
				_statsReady = false;
				return;
			}
			foreach (PlayerAvatar item in list)
			{
				string text = SemiFunc.PlayerGetSteamID(item);
				Dictionary<string, int> dictionary = StatsManager.instance.FetchPlayerUpgrades(text);
				if (dictionary != null)
				{
					_playerStats[text] = new Dictionary<string, int>(dictionary);
					Logger.LogDebug((object)("Stats for " + text + ": " + string.Join(", ", dictionary)));
				}
			}
			_statsReady = true;
			Logger.LogInfo((object)$"Character stats refreshed for {_playerStats.Count} player(s).");
		}

		internal static void ClearStats()
		{
			_playerStats.Clear();
			_statsReady = false;
		}
	}
}
namespace Character_Stats.Patches
{
	[HarmonyPatch]
	internal static class StatReaderPatch
	{
		[CompilerGenerated]
		private sealed class <ReadStatsAfterSync>d__3 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 3;
					return true;
				case 3:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 4;
					return true;
				case 4:
					<>1__state = -1;
					Character_Stats.RefreshStats();
					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();
			}
		}

		[CompilerGenerated]
		private sealed class <ReadStatsDelayed>d__1 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Expected O, but got Unknown
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					goto IL_004f;
				case 1:
					<>1__state = -1;
					goto IL_004f;
				case 2:
					{
						<>1__state = -1;
						Character_Stats.RefreshStats();
						return false;
					}
					IL_004f:
					if (!SemiFunc.LevelGenDone())
					{
						<>2__current = (object)new WaitForSeconds(0.5f);
						<>1__state = 1;
						return true;
					}
					if (!SemiFunc.RunIsLevel())
					{
						return false;
					}
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 2;
					return true;
				}
			}

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

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

		[HarmonyPatch(typeof(GameDirector), "Start")]
		[HarmonyPostfix]
		private static void GameDirector_Start_Postfix()
		{
			Object.FindObjectOfType<MonoBehaviour>().StartCoroutine(ReadStatsDelayed());
		}

		[IteratorStateMachine(typeof(<ReadStatsDelayed>d__1))]
		private static IEnumerator ReadStatsDelayed()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ReadStatsDelayed>d__1(0);
		}

		[HarmonyPatch(typeof(PunManager), "ReceiveSyncData")]
		[HarmonyPostfix]
		private static void ReceiveSyncData_Postfix(bool finalChunk)
		{
			if (finalChunk)
			{
				Object.FindObjectOfType<MonoBehaviour>().StartCoroutine(ReadStatsAfterSync());
			}
		}

		[IteratorStateMachine(typeof(<ReadStatsAfterSync>d__3))]
		private static IEnumerator ReadStatsAfterSync()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ReadStatsAfterSync>d__3(0);
		}

		[HarmonyPatch(typeof(RunManager), "ResetProgress")]
		[HarmonyPostfix]
		private static void RunManager_ResetProgress_Postfix()
		{
			Character_Stats.ClearStats();
		}
	}
}