Decompiled source of MoreStatistics v1.1.4

plugins/MoreStatistics/MoreStatistics.dll

Decompiled 8 months ago
using System;
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 Microsoft.CodeAnalysis;
using On.RoR2.Stats;
using On.RoR2.UI;
using RoR2;
using RoR2.Stats;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("MoreStatistics")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9cfec70320050487367d16e594b8f69c0c7583bd")]
[assembly: AssemblyProduct("MoreStatistics")]
[assembly: AssemblyTitle("MoreStatistics")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MoreStatistics
{
	public static class Assets
	{
		public static AssetBundle mainBundle;

		public const string bundleName = "nullos.statstriptemplate";

		public const string assetBundleFolder = "assetbundles";

		public static string AssetBundlePath => Path.Combine(Path.GetDirectoryName(MoreStatistics.PInfo.Location), "assetbundles", "nullos.statstriptemplate");

		public static void Init()
		{
			mainBundle = AssetBundle.LoadFromFile(AssetBundlePath);
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.Nullos.MoreStatistics", "MoreStatistics", "1.1.3")]
	public class MoreStatistics : BaseUnityPlugin
	{
		public const string PluginGUID = "com.Nullos.MoreStatistics";

		public const string PluginName = "MoreStatistics";

		public const string PluginVersion = "1.1.3";

		private string[] statsToDisplay = new string[7] { "totalHealthHealed", "totalDistanceTraveled", "totalBloodPurchases", "totalLunarPurchases", "totalDronesPurchased", "totalTurretsPurchased", "totalEliteKills" };

		public string[] enemiesNames = new string[117]
		{
			"AcidLarvaBody", "AffixEarthHealerBody", "ArtifactShellBody", "Assassin2Body", "AssassinBody", "BackupDroneBody", "Bandit2Body", "BanditBody", "BeetleBody", "BeetleGuardAllyBody",
			"BeetleGuardBody", "BeetleGuardCrystalBody", "BeetleQueen2Body", "BellBody", "BisonBody", "BomberBody", "BrotherBody", "BrotherGlassBody", "BrotherHurtBody", "CaptainBody",
			"ClayBody", "ClayBossBody", "ClayBruiserBody", "ClayGrenadierBody", "CommandoBody", "CommandoPerformanceTestBody", "CrocoBody", "Drone1Body", "Drone2Body", "DroneCommanderBody",
			"ElectricWormBody", "EmergencyDroneBody", "EnforcerBody", "EngiBeamTurretBody", "EngiBody", "EngiTurretBody", "EngiWalkerTurretBody", "EquipmentDroneBody", "FlameDroneBody", "FlyingVerminBody",
			"GeepBody", "GipBody", "GolemBody", "GolemBodyInvincible", "GrandParentBody", "GravekeeperBody", "GreaterWispBody", "GupBody", "HANDBody", "HaulerBody",
			"HereticBody", "HermitCrabBody", "HuntressBody", "ImpBody", "ImpBossBody", "JellyfishBody", "LemurianBody", "LemurianBruiserBody", "LoaderBody", "LunarExploderBody",
			"LunarGolemBody", "LunarWispBody", "MageBody", "MagmaWormBody", "MegaConstructBody", "MegaDroneBody", "MercBody", "MiniMushroomBody", "MinorConstructAttachableBody", "MinorConstructBody",
			"MinorConstructOnKillBody", "MissileDroneBody", "NullifierAllyBody", "NullifierBody", "PaladinBody", "ParentBody", "ParentPodBody", "Pot2Body", "PotMobile2Body", "PotMobileBody",
			"RailgunnerBody", "RoboBallBossBody", "RoboBallGreenBuddyBody", "RoboBallMiniBody", "RoboBallRedBuddyBody", "ScavBody", "ScavLunar1Body", "ScavLunar2Body", "ScavLunar3Body", "ScavLunar4Body",
			"ShopkeeperBody", "SniperBody", "SquidTurretBody", "SulfurPodBody", "SuperRoboBallBossBody", "TimeCrystalBody", "TitanBody", "TitanGoldBody", "ToolbotBody", "TreebotBody",
			"Turret1Body", "UrchinTurretBody", "VagrantBody", "VerminBody", "VoidBarnacleBody", "VoidBarnacleNoCastBody", "VoidInfestorBody", "VoidJailerAllyBody", "VoidJailerBody", "VoidMegaCrabAllyBody",
			"VoidMegaCrabBody", "VoidRaidCrabBody", "VoidRaidCrabJointBody", "VoidSurvivorBody", "VultureBody", "WispBody", "WispSoulBody"
		};

		public string[] enemiesInteractions = new string[4] { "killsAgainst", "damageDealtTo", "damageTakenFrom", "killsAgainstElite" };

		public string[] statGameObjectLabels = new string[4] { "KillLabel", "DealtLabel", "TakenLabel", "EliteLabel" };

		public string[] statGameObjectValueLabels = new string[4] { "KillValueLabel", "DealtValueLabel", "TakenValueLabel", "EliteValueLabel" };

		public string[] statNameToken = new string[4] { "STATNAME_TOTALKILLS", "STATNAME_TOTALDAMAGEDEALT", "STATNAME_TOTALDAMAGETAKEN", "STATNAME_TOTALELITEKILLS" };

		public GameObject customStripPrefab;

		public static PluginInfo PInfo { get; private set; }

		private void OnEnable()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			GameEndReportPanelController.SetPlayerInfo += new hook_SetPlayerInfo(PlayerInfoHook);
			StatManager.OnGoldCollected += new hook_OnGoldCollected(PurchaseHook);
		}

		private void OnDisable()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			GameEndReportPanelController.SetPlayerInfo -= new hook_SetPlayerInfo(PlayerInfoHook);
			StatManager.OnGoldCollected -= new hook_OnGoldCollected(PurchaseHook);
		}

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			PInfo = ((BaseUnityPlugin)this).Info;
			Assets.Init();
			if ((Object)(object)Assets.mainBundle == (Object)null)
			{
				Log.Error("Bundle is null");
			}
			customStripPrefab = Assets.mainBundle.LoadAsset<GameObject>("StatStripTemplate");
			SceneExitController.onFinishExit += PerStageStats.OnFinishSceneExit;
		}

		private void PlayerInfoHook(orig_SetPlayerInfo orig, GameEndReportPanelController self, PlayerInfo playerInfo)
		{
			ClearStatStrips(self.statStrips);
			Log.Info($"Null check: {playerInfo.statSheet == null}");
			Log.Info($"Contains check: {self.statsToDisplay.Contains(statsToDisplay[0])}");
			if (!self.statsToDisplay.Contains(statsToDisplay[0]))
			{
				Log.Info("Stats added");
				self.statsToDisplay = self.statsToDisplay.Concat(statsToDisplay).ToArray();
			}
			orig.Invoke(self, playerInfo);
			List<string> enemiesNamesPlayerInteractedWith = GetEnemiesNamesPlayerInteractedWith(playerInfo.statSheet);
			int num = self.statStrips.Count;
			AllocateStatStrip(enemiesNamesPlayerInteractedWith.Count, self.statStrips, self.statContentArea);
			foreach (string item in enemiesNamesPlayerInteractedWith)
			{
				AssignStatToStrip(playerInfo.statSheet, item, self.statStrips[num]);
				num++;
			}
		}

		private List<string> GetEnemiesNamesPlayerInteractedWith(StatSheet statSheet)
		{
			List<string> list = new List<string>();
			string[] array = enemiesNames;
			foreach (string text in array)
			{
				string[] array2 = enemiesInteractions;
				foreach (string text2 in array2)
				{
					string text3 = text2 + "." + text;
					StatDef val = StatDef.Find(text3);
					string statDisplayValue = statSheet.GetStatDisplayValue(val);
					if (int.TryParse(statDisplayValue, out var result) && result != 0)
					{
						list.Add(text);
						break;
					}
				}
			}
			return list;
		}

		private void AllocateStatStrip(int count, List<GameObject> statStrips, RectTransform statContentArea)
		{
			count += statStrips.Count;
			while (statStrips.Count > count)
			{
				int index = statStrips.Count - 1;
				Object.Destroy((Object)(object)statStrips[index].gameObject);
				statStrips.RemoveAt(index);
			}
			while (statStrips.Count < count)
			{
				GameObject val = Object.Instantiate<GameObject>(customStripPrefab, (Transform)(object)statContentArea);
				val.SetActive(true);
				statStrips.Add(val);
			}
		}

		private void AssignStatToStrip(StatSheet srcStatSheet, string enemyName, GameObject destStatStrip)
		{
			GameObject val = BodyCatalog.FindBodyPrefab(enemyName);
			CharacterBody component = val.GetComponent<CharacterBody>();
			string baseNameToken = component.baseNameToken;
			((TMP_Text)((Component)destStatStrip.transform.Find("BodyName")).GetComponent<TextMeshProUGUI>()).text = Language.GetString(baseNameToken);
			Texture portraitIcon = component.portraitIcon;
			((Component)destStatStrip.transform.Find("PortraitIcon")).GetComponent<RawImage>().texture = portraitIcon;
			for (int i = 0; i < enemiesInteractions.Length; i++)
			{
				string text = enemiesInteractions[i];
				string text2 = text + "." + enemyName;
				StatDef val2 = StatDef.Find(text2);
				string arg = "0";
				ulong num = 0uL;
				if (srcStatSheet != null)
				{
					arg = srcStatSheet.GetStatDisplayValue(val2);
					num = srcStatSheet.GetStatPointValue(val2);
				}
				string @string = Language.GetString(statNameToken[i]);
				string text3 = string.Format(Language.GetString("STAT_NAME_VALUE_FORMAT"), @string, arg);
				((TMP_Text)((Component)destStatStrip.transform.Find(statGameObjectLabels[i])).GetComponent<TextMeshProUGUI>()).text = text3;
				string string2 = Language.GetString("STAT_POINTS_FORMAT");
				((TMP_Text)((Component)destStatStrip.transform.Find(statGameObjectValueLabels[i])).GetComponent<TextMeshProUGUI>()).text = string.Format(string2, TextSerialization.ToStringNumeric(num));
			}
		}

		private void ClearStatStrips(List<GameObject> statStrips)
		{
			while (statStrips.Count > 0)
			{
				int index = statStrips.Count - 1;
				Object.Destroy((Object)(object)statStrips[index].gameObject);
				statStrips.RemoveAt(index);
			}
		}

		private void Update()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown((KeyCode)283))
			{
				StatSheet currentStats = ((Component)PlayerCharacterMasterController.instances[0].master).GetComponent<PlayerStatsComponent>().currentStats;
				Log.Info("STAT SHEET\n");
				StatField[] fields = currentStats.fields;
				for (int i = 0; i < fields.Length; i++)
				{
					StatField val = fields[i];
					Log.Info($"{((StatField)(ref val)).name} : {val}");
				}
			}
			else if (Input.GetKeyDown((KeyCode)284))
			{
				StatDef.Register("testStat", (StatRecordType)0, (StatDataType)0, 0.0, (DisplayValueFormatterDelegate)null);
				((Component)PlayerCharacterMasterController.instances[0].master).GetComponent<PlayerStatsComponent>().currentStats = StatSheet.New();
			}
			else if (Input.GetKeyDown((KeyCode)285))
			{
				Log.Info("STAT FIELD TEMPLATE\n");
				StatField[] fieldsTemplate = StatSheet.fieldsTemplate;
				for (int j = 0; j < fieldsTemplate.Length; j++)
				{
					StatField val2 = fieldsTemplate[j];
					Log.Info($"{((StatField)(ref val2)).name} : {val2}");
				}
			}
		}

		private void PurchaseHook(orig_OnGoldCollected orig, CharacterMaster master, ulong amount)
		{
			orig.Invoke(master, amount);
			Log.Info("On gold hook");
		}

		public static void AddStatDefToStatSheet(CharacterMaster master)
		{
			StatDef.Register("morestatistics.perstage.goldcollected", (StatRecordType)0, (StatDataType)0, 1.0, (DisplayValueFormatterDelegate)null);
		}
	}
	public static class PerStageStats
	{
		public static string currentStageName;

		public static List<string> completedStages = new List<string>();

		public static void OnFinishSceneExit(SceneExitController sceneExitController)
		{
			//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)
			Scene activeScene = SceneManager.GetActiveScene();
			string name = ((Scene)(ref activeScene)).name;
			completedStages.Add(name);
		}
	}
}