Decompiled source of MatchInfo v1.1.4

Mods/MatchInfo.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using MatchInfo;
using MelonLoader;
using RUMBLE.Managers;
using RUMBLE.Networking.MatchFlow;
using RumbleModdingAPI;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(main), "MatchInfo", "1.1.4", "UlvakSkillz", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: AssemblyTitle("MatchInfo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MatchInfo")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f5e62496-0e7a-420d-81f3-34006cbabc29")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MatchInfo;

public class main : MelonMod
{
	private string FILEPATH = "UserData\\MatchInfo\\MatchInfo.txt";

	private List<string> fileText = new List<string>();

	private bool sceneChanged = false;

	private string currentScene = "";

	private bool init = false;

	private GameObject matchInfoGameObject;

	private GameObject player1GameObject;

	private GameObject player2GameObject;

	private GameObject vsGameObject;

	private GameObject player1BPGameObject;

	private GameObject player2BPGameObject;

	private GameObject player1MatchWinsGameObject;

	private GameObject player2MatchWinsGameObject;

	private TextMeshPro player1Component;

	private TextMeshPro player2Component;

	private TextMeshPro vsComponent;

	private TextMeshPro player1BPComponent;

	private TextMeshPro player2BPComponent;

	private TextMeshPro player1MatchWinsComponent;

	private TextMeshPro player2MatchWinsComponent;

	private GameObject gymMatchInfoGameObject;

	private GameObject gymMatchInfoTotalGameObject;

	private GameObject gymMatchInfoWinsGameObject;

	private GameObject gymMatchInfoLossesGameObject;

	private GameObject gymMatchInfoWinPercentGameObject;

	private TextMeshPro gymMatchInfoTitleComponent;

	private TextMeshPro gymMatchInfoTotalComponent;

	private TextMeshPro gymMatchInfoWinsComponent;

	private TextMeshPro gymMatchInfoLossesComponent;

	private TextMeshPro gymMatchInfoWinPercentComponent;

	private DateTime hideTime = DateTime.Now;

	private int waitedTicks = 0;

	private bool textActive = false;

	private bool matchActive = false;

	private bool ranWinLoss = true;

	private PlayerManager playerManager;

	private MatchHandler matchHandler;

	private int playerFileSpot = 0;

	public override void OnEarlyInitializeMelon()
	{
		string[] array = ReadFileText(FILEPATH);
		string[] array2 = array;
		foreach (string item in array2)
		{
			fileText.Add(item);
		}
	}

	public override void OnApplicationQuit()
	{
		File.WriteAllLines(FILEPATH, fileText);
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		currentScene = sceneName;
		sceneChanged = true;
	}

	public override void OnFixedUpdate()
	{
		//IL_0cdf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d04: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d43: Unknown result type (might be due to invalid IL or missing references)
		//IL_0d68: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Expected O, but got Unknown
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_0400: Unknown result type (might be due to invalid IL or missing references)
		//IL_067c: Unknown result type (might be due to invalid IL or missing references)
		//IL_06a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_06eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0710: Unknown result type (might be due to invalid IL or missing references)
		//IL_0735: Unknown result type (might be due to invalid IL or missing references)
		//IL_075a: Unknown result type (might be due to invalid IL or missing references)
		//IL_077f: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0813: Unknown result type (might be due to invalid IL or missing references)
		//IL_0838: Unknown result type (might be due to invalid IL or missing references)
		//IL_0dae: Unknown result type (might be due to invalid IL or missing references)
		//IL_0db4: Invalid comparison between Unknown and I4
		//IL_09de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a03: Unknown result type (might be due to invalid IL or missing references)
		//IL_0990: Unknown result type (might be due to invalid IL or missing references)
		//IL_09b5: Unknown result type (might be due to invalid IL or missing references)
		if (sceneChanged)
		{
			try
			{
				if (currentScene == "Gym" && !init)
				{
					if (waitedTicks == 120)
					{
						playerManager = Managers.GetPlayerManager();
						matchInfoGameObject = new GameObject();
						((Object)matchInfoGameObject).name = "MatchInfoMod";
						matchInfoGameObject.SetActive(false);
						player1GameObject = Object.Instantiate<GameObject>(Nr.GetGameObject());
						player1GameObject.transform.parent = matchInfoGameObject.transform;
						((Object)player1GameObject).name = "Player1Name";
						player1Component = player1GameObject.GetComponent<TextMeshPro>();
						((TMP_Text)player1Component).text = "Name";
						((TMP_Text)player1Component).fontSize = 5f;
						((TMP_Text)player1Component).color = new Color(1f, 1f, 1f, 1f);
						((TMP_Text)player1Component).outlineColor = Color32.op_Implicit(new Color(0f, 0f, 0f, 0.5f));
						((TMP_Text)player1Component).alignment = (TextAlignmentOptions)516;
						((TMP_Text)player1Component).enableWordWrapping = false;
						((TMP_Text)player1Component).outlineWidth = 0.1f;
						player2GameObject = Object.Instantiate<GameObject>(player1GameObject);
						player2GameObject.transform.parent = matchInfoGameObject.transform;
						((Object)player2GameObject).name = "Player2Name";
						player2Component = player2GameObject.GetComponent<TextMeshPro>();
						((TMP_Text)player2Component).alignment = (TextAlignmentOptions)513;
						vsGameObject = Object.Instantiate<GameObject>(player2GameObject);
						vsGameObject.transform.parent = matchInfoGameObject.transform;
						((Object)vsGameObject).name = "VSText";
						vsComponent = vsGameObject.GetComponent<TextMeshPro>();
						((TMP_Text)vsComponent).alignment = (TextAlignmentOptions)514;
						((TMP_Text)vsComponent).color = new Color(0f, 0f, 0f, 1f);
						((TMP_Text)vsComponent).text = "vs";
						((TMP_Text)vsComponent).fontSize = 3.5f;
						player1BPGameObject = Object.Instantiate<GameObject>(player2GameObject);
						player1BPGameObject.transform.parent = matchInfoGameObject.transform;
						((Object)player1BPGameObject).name = "Player1BP";
						player1BPComponent = player1BPGameObject.GetComponent<TextMeshPro>();
						((TMP_Text)player1BPComponent).alignment = (TextAlignmentOptions)514;
						((TMP_Text)player1BPComponent).text = "P1BP";
						((TMP_Text)player1BPComponent).fontSize = 4f;
						player2BPGameObject = Object.Instantiate<GameObject>(player2GameObject);
						player2BPGameObject.transform.parent = matchInfoGameObject.transform;
						((Object)player2BPGameObject).name = "Player2BP";
						player2BPComponent = player2BPGameObject.GetComponent<TextMeshPro>();
						((TMP_Text)player2BPComponent).alignment = (TextAlignmentOptions)514;
						((TMP_Text)player2BPComponent).text = "P2BP";
						((TMP_Text)player2BPComponent).fontSize = 4f;
						player1MatchWinsGameObject = Object.Instantiate<GameObject>(player1BPGameObject);
						player1MatchWinsGameObject.transform.parent = matchInfoGameObject.transform;
						((Object)player1MatchWinsGameObject).name = "P1Wins";
						player1MatchWinsComponent = player1MatchWinsGameObject.GetComponent<TextMeshPro>();
						((TMP_Text)player1MatchWinsComponent).alignment = (TextAlignmentOptions)514;
						((TMP_Text)player1MatchWinsComponent).text = "0 Wins";
						((TMP_Text)player1MatchWinsComponent).color = new Color(1f, 1f, 1f, 1f);
						player2MatchWinsGameObject = Object.Instantiate<GameObject>(player1MatchWinsGameObject);
						player2MatchWinsGameObject.transform.parent = matchInfoGameObject.transform;
						((Object)player2MatchWinsGameObject).name = "P2Wins";
						player2MatchWinsComponent = player2MatchWinsGameObject.GetComponent<TextMeshPro>();
						((TMP_Text)player2MatchWinsComponent).alignment = (TextAlignmentOptions)514;
						((TMP_Text)player2MatchWinsComponent).text = "0 Wins";
						gymMatchInfoGameObject = Object.Instantiate<GameObject>(player1GameObject);
						((Object)gymMatchInfoGameObject).name = "GymMatchInfo";
						gymMatchInfoTitleComponent = gymMatchInfoGameObject.GetComponent<TextMeshPro>();
						((TMP_Text)gymMatchInfoTitleComponent).alignment = (TextAlignmentOptions)513;
						((TMP_Text)gymMatchInfoTitleComponent).text = "Match History";
						((TMP_Text)gymMatchInfoTitleComponent).fontSize = 3.5f;
						gymMatchInfoTotalGameObject = Object.Instantiate<GameObject>(gymMatchInfoGameObject);
						gymMatchInfoTotalGameObject.transform.parent = gymMatchInfoGameObject.transform;
						((Object)gymMatchInfoTotalGameObject).name = "Total";
						gymMatchInfoTotalComponent = gymMatchInfoTotalGameObject.GetComponent<TextMeshPro>();
						((TMP_Text)gymMatchInfoTotalComponent).text = "Total: ";
						gymMatchInfoWinsGameObject = Object.Instantiate<GameObject>(gymMatchInfoTotalGameObject);
						gymMatchInfoWinsGameObject.transform.parent = gymMatchInfoGameObject.transform;
						((Object)gymMatchInfoWinsGameObject).name = "Wins";
						gymMatchInfoWinsComponent = gymMatchInfoWinsGameObject.GetComponent<TextMeshPro>();
						((TMP_Text)gymMatchInfoWinsComponent).text = "Wins: ";
						gymMatchInfoLossesGameObject = Object.Instantiate<GameObject>(gymMatchInfoTotalGameObject);
						gymMatchInfoLossesGameObject.transform.parent = gymMatchInfoGameObject.transform;
						((Object)gymMatchInfoLossesGameObject).name = "Losses";
						gymMatchInfoLossesComponent = gymMatchInfoLossesGameObject.GetComponent<TextMeshPro>();
						((TMP_Text)gymMatchInfoLossesComponent).text = "Losses: ";
						gymMatchInfoWinPercentGameObject = Object.Instantiate<GameObject>(gymMatchInfoTotalGameObject);
						gymMatchInfoWinPercentGameObject.transform.parent = gymMatchInfoGameObject.transform;
						((Object)gymMatchInfoWinPercentGameObject).name = "WinPercent";
						gymMatchInfoWinPercentComponent = gymMatchInfoWinPercentGameObject.GetComponent<TextMeshPro>();
						((TMP_Text)gymMatchInfoWinPercentComponent).text = "Win Rate: ";
						player1GameObject.transform.position = new Vector3(-0.75f, 1f, 0f);
						player1BPGameObject.transform.position = new Vector3(-1.25f, 0.5f, 0f);
						vsGameObject.transform.position = new Vector3(0f, 0.75f, 0f);
						player2GameObject.transform.position = new Vector3(0.75f, 1f, 0f);
						player2BPGameObject.transform.position = new Vector3(1.25f, 0.5f, 0f);
						player1MatchWinsGameObject.transform.position = new Vector3(-1.25f, 0f, 0f);
						player2MatchWinsGameObject.transform.position = new Vector3(1.25f, 0f, 0f);
						gymMatchInfoGameObject.transform.position = new Vector3(5.5236f, 2.75f, 11.3364f);
						gymMatchInfoGameObject.transform.rotation = Quaternion.Euler(0f, 30.5f, 0f);
						gymMatchInfoTotalGameObject.transform.localPosition = new Vector3(0.0334f, -0.3f, -0.0012f);
						gymMatchInfoWinsGameObject.transform.localPosition = new Vector3(0.0334f, -0.6f, -0.0012f);
						gymMatchInfoLossesGameObject.transform.localPosition = new Vector3(0.0334f, -0.9f, -0.0012f);
						gymMatchInfoWinPercentGameObject.transform.localPosition = new Vector3(0.0334f, -1.2f, -0.0012f);
						Object.DontDestroyOnLoad((Object)(object)matchInfoGameObject);
						Object.DontDestroyOnLoad((Object)(object)gymMatchInfoGameObject);
						init = true;
						MelonLogger.Msg("Initialized");
					}
					else
					{
						waitedTicks++;
					}
				}
				if (!init)
				{
					return;
				}
				if (currentScene == "Gym")
				{
					matchInfoGameObject.SetActive(false);
					CountWinLoss();
					gymMatchInfoGameObject.SetActive(true);
				}
				else
				{
					gymMatchInfoGameObject.SetActive(false);
				}
				if (currentScene == "Map0" || currentScene == "Map1")
				{
					try
					{
						if (currentScene == "Map0")
						{
							matchHandler = MatchHandler.GetGameObject().GetComponent<MatchHandler>();
						}
						else if (currentScene == "Map1")
						{
							matchHandler = MatchHandler.GetGameObject().GetComponent<MatchHandler>();
						}
					}
					catch
					{
						return;
					}
					if (Players.IsHost())
					{
						matchInfoGameObject.transform.position = new Vector3(-3f, 3f, 0f);
						matchInfoGameObject.transform.rotation = Quaternion.Euler(0f, -90f, 0f);
					}
					else
					{
						matchInfoGameObject.transform.position = new Vector3(3f, 3f, 0f);
						matchInfoGameObject.transform.rotation = Quaternion.Euler(0f, 90f, 0f);
					}
					((TMP_Text)player2Component).text = playerManager.AllPlayers[0].Data.GeneralData.PublicUsername;
					((TMP_Text)player2BPComponent).text = playerManager.AllPlayers[0].Data.GeneralData.BattlePoints + " BP";
					if (playerManager.AllPlayers.Count > 1)
					{
						((TMP_Text)player1Component).text = playerManager.AllPlayers[1].Data.GeneralData.PublicUsername;
						((TMP_Text)player1BPComponent).text = playerManager.AllPlayers[1].Data.GeneralData.BattlePoints + " BP";
						bool flag = false;
						for (int i = 0; i < fileText.Count; i += 3)
						{
							if (fileText[i] == playerManager.AllPlayers[1].Data.GeneralData.InternalUsername)
							{
								playerFileSpot = i;
								flag = true;
								break;
							}
						}
						if (!flag)
						{
							fileText.Add(playerManager.AllPlayers[1].Data.GeneralData.InternalUsername);
							fileText.Add("0");
							fileText.Add("0");
							playerFileSpot = fileText.Count - 3;
						}
						((TMP_Text)player1MatchWinsComponent).text = fileText[playerFileSpot + 2] + " Wins";
						((TMP_Text)player2MatchWinsComponent).text = fileText[playerFileSpot + 1] + " Wins";
						matchActive = true;
						ranWinLoss = false;
					}
					matchInfoGameObject.SetActive(true);
					hideTime = DateTime.Now.AddSeconds(7.0);
					textActive = true;
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Msg((object)ex);
				return;
			}
			sceneChanged = false;
		}
		if (textActive && hideTime <= DateTime.Now)
		{
			if (currentScene == "Map0")
			{
				matchInfoGameObject.transform.position = new Vector3(-1f, -0.5f, 20.5f);
				matchInfoGameObject.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
			}
			else if (currentScene == "Map1")
			{
				matchInfoGameObject.transform.position = new Vector3(0f, 5.25f, 11f);
				matchInfoGameObject.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
			}
			textActive = false;
		}
		if (!matchActive)
		{
			return;
		}
		try
		{
			if (ranWinLoss || playerManager.AllPlayers.Count != 2 || (int)matchHandler.CurrentMatchPhase != 4)
			{
				return;
			}
			bool flag2 = false;
			string text = "";
			if (currentScene == "Map0")
			{
				text = ((!Players.IsHost()) ? ((TMP_Text)MatchText.GetGameObject().GetComponent<TextMeshProUGUI>()).text : ((TMP_Text)MatchText.GetGameObject().GetComponent<TextMeshProUGUI>()).text);
			}
			else if (currentScene == "Map1")
			{
				text = ((!Players.IsHost()) ? ((TMP_Text)MatchText.GetGameObject().GetComponent<TextMeshProUGUI>()).text : ((TMP_Text)MatchText.GetGameObject().GetComponent<TextMeshProUGUI>()).text);
			}
			if (!(text == ""))
			{
				if ((text == "Victory!") ? true : false)
				{
					fileText[playerFileSpot + 1] = (int.Parse(fileText[playerFileSpot + 1]) + 1).ToString();
					((TMP_Text)player2MatchWinsComponent).text = fileText[playerFileSpot + 1] + " Wins";
				}
				else
				{
					fileText[playerFileSpot + 2] = (int.Parse(fileText[playerFileSpot + 2]) + 1).ToString();
					((TMP_Text)player1MatchWinsComponent).text = fileText[playerFileSpot + 2] + " Wins";
				}
				((TMP_Text)player2BPComponent).text = playerManager.AllPlayers[0].Data.GeneralData.BattlePoints + " BP";
				((TMP_Text)player1BPComponent).text = playerManager.AllPlayers[1].Data.GeneralData.BattlePoints + " BP";
				ranWinLoss = true;
			}
		}
		catch
		{
		}
	}

	public void CountWinLoss()
	{
		int num = 0;
		int num2 = 0;
		for (int i = 0; i < fileText.Count; i += 3)
		{
			num += int.Parse(fileText[i + 1]);
			num2 += int.Parse(fileText[i + 2]);
		}
		((TMP_Text)gymMatchInfoTotalComponent).text = "Total: " + (num + num2);
		((TMP_Text)gymMatchInfoWinsComponent).text = "Wins: " + num;
		((TMP_Text)gymMatchInfoLossesComponent).text = "Losses: " + num2;
		((TMP_Text)gymMatchInfoWinPercentComponent).text = "Win Rate: " + (float)(int)((float)num / (float)(num + num2) * 10000f) / 100f + "%";
		if (num + num2 == 0)
		{
			((TMP_Text)gymMatchInfoWinPercentComponent).text = "Win Rate: N/A";
		}
	}

	public static string[] ReadFileText(string inputFile)
	{
		if (File.Exists(inputFile))
		{
			try
			{
				List<string> list = new List<string>();
				return File.ReadAllLines(inputFile);
			}
			catch (Exception ex)
			{
				MelonLogger.Error((object)ex);
			}
		}
		else
		{
			MelonLogger.Error("File not Found: Check Game Folder for " + inputFile);
		}
		return null;
	}
}