Decompiled source of TournamentScoringMod v1.0.2

Mods/tournamentScoring.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Players;
using Il2CppRUMBLE.Utilities;
using Il2CppTMPro;
using MelonLoader;
using RumbleModdingAPI;
using UnityEngine;
using tournamentScore;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(main), "RUMBLE Tournament Scoring", "1.0.2", "davisg", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("tournamentScoring")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("tournamentScoring")]
[assembly: AssemblyTitle("tournamentScoring")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace tournamentScore;

public class main : MelonMod
{
	private int localPlayerMatchWins;

	private int remotePlayerMatchWins;

	private int localRoundsInLosses;

	private int remoteRoundsInLosses;

	private int localRoundWinsThisMatch;

	private int remoteRoundWinsThisMatch;

	private GameObject scoreboardGO;

	private TextMeshPro scoreboardText;

	private bool spawnCountdownActive;

	private float spawnTimer;

	private Vector3 pendingPosition;

	public override void OnLateInitializeMelon()
	{
		Calls.onMatchStarted += OnMatchStarted;
		Calls.onRoundEnded += OnRoundEnded;
		Calls.onMatchEnded += OnMatchEnded;
	}

	public override void OnUpdate()
	{
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown((KeyCode)114))
		{
			ResetScore();
		}
		if (spawnCountdownActive)
		{
			spawnTimer += Time.deltaTime;
			if (spawnTimer >= 5f && (Object)(object)scoreboardGO == (Object)null)
			{
				SpawnScoreboard();
			}
		}
		if ((Object)(object)scoreboardGO != (Object)null && (Object)(object)scoreboardText != (Object)null)
		{
			Camera val = Camera.main;
			if ((Object)(object)val != (Object)null)
			{
				scoreboardGO.transform.rotation = Quaternion.LookRotation(scoreboardGO.transform.position - ((Component)val).transform.position);
			}
		}
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		switch (sceneName)
		{
		case "Gym":
			ResetScore();
			if ((Object)(object)scoreboardGO != (Object)null)
			{
				scoreboardGO.SetActive(false);
			}
			spawnCountdownActive = false;
			break;
		case "Map0":
		case "Map1":
			pendingPosition = ((sceneName == "Map0") ? new Vector3(-10f, 5f, 0f) : new Vector3(12f, 5f, 0f));
			spawnTimer = 0f;
			spawnCountdownActive = true;
			break;
		}
	}

	private void SpawnScoreboard()
	{
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)scoreboardGO == (Object)null)
		{
			scoreboardGO = Create.NewText("0(0)-0(0)", 3f, Color.white, Vector3.zero, Quaternion.identity);
			GameObject obj = scoreboardGO;
			scoreboardText = ((obj != null) ? obj.GetComponent<TextMeshPro>() : null);
			if ((Object)(object)scoreboardText != (Object)null)
			{
				((TMP_Text)scoreboardText).alignment = (TextAlignmentOptions)514;
			}
			scoreboardGO.transform.position = pendingPosition;
			scoreboardGO.transform.localScale = Vector3.one * 5f;
			UpdateScoreboardText();
		}
		else
		{
			scoreboardGO.transform.position = pendingPosition;
			scoreboardGO.SetActive(true);
		}
		spawnCountdownActive = false;
	}

	private void OnMatchStarted()
	{
		localRoundWinsThisMatch = 0;
		remoteRoundWinsThisMatch = 0;
	}

	private void OnRoundEnded()
	{
		try
		{
			PlayerManager instance = Singleton<PlayerManager>.instance;
			Player obj = ((instance != null) ? instance.localPlayer : null);
			PlayerData val = ((obj != null) ? obj.Data : null);
			if (obj != null && val != null)
			{
				if (val.HealthPoints > 0)
				{
					localRoundWinsThisMatch++;
				}
				else
				{
					remoteRoundWinsThisMatch++;
				}
			}
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Error in OnRoundEnded: " + ex);
		}
	}

	private void OnMatchEnded()
	{
		try
		{
			bool num = localRoundWinsThisMatch > remoteRoundWinsThisMatch;
			bool flag = Players.IsHost();
			if (num)
			{
				localPlayerMatchWins++;
				if (flag)
				{
					remoteRoundsInLosses += remoteRoundWinsThisMatch;
				}
			}
			else
			{
				remotePlayerMatchWins++;
				if (!flag)
				{
					localRoundsInLosses += localRoundWinsThisMatch;
				}
			}
			UpdateScoreboardText();
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Error in OnMatchEnded: " + ex);
		}
	}

	private void UpdateScoreboardText()
	{
		if ((Object)(object)scoreboardText != (Object)null)
		{
			((TMP_Text)scoreboardText).text = $"{localPlayerMatchWins}({localRoundsInLosses})-{remotePlayerMatchWins}({remoteRoundsInLosses})";
		}
	}

	private void ResetScore()
	{
		localPlayerMatchWins = 0;
		remotePlayerMatchWins = 0;
		localRoundsInLosses = 0;
		remoteRoundsInLosses = 0;
		localRoundWinsThisMatch = 0;
		remoteRoundWinsThisMatch = 0;
		UpdateScoreboardText();
	}
}