Decompiled source of MatchStatusOverlay v1.0.1

Mods/MatchStatusOverlay.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Players;
using Il2CppRUMBLE.Players.Subsystems;
using Il2CppRUMBLE.Utilities;
using MelonLoader;
using Microsoft.CodeAnalysis;
using RumbleModdingAPI;
using RumbleWarCrimes;
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: MelonInfo(typeof(MatchStatusOverlay), "MatchStatusOverlay", "1.0.0", "ERROR", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 255, 0, 0)]
[assembly: MelonAuthorColor(255, 255, 0, 0)]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: VerifyLoaderVersion(0, 6, 2, true)]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b10c94a1-8a40-4701-bc5b-98eabb44dfea")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MatchStatusOverlay")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b5fac2a1ef0259e714f55d9b48b3f3c91ae4764a")]
[assembly: AssemblyProduct("MatchStatusOverlay")]
[assembly: AssemblyTitle("MatchStatusOverlay")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace RumbleWarCrimes
{
	public class MatchStatusOverlay : MelonMod
	{
		private GameObject localNameplateClone;

		private GameObject opponentNameplateClone;

		private GameObject localHealthClone;

		private GameObject renderParent;

		private RawImage localRawNameplateImage;

		private RawImage remoteRawNameplateImage;

		private RawImage localRawHealthImage;

		private RawImage remoteRawHealthImage;

		private RawImage rawHostIconImage;

		private RawImage rawTallyImage;

		private string currentScene = "Loader";

		private bool initializedCanvas = false;

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			currentScene = sceneName;
			if (sceneName.Contains("Map"))
			{
				MelonCoroutines.Start(InitializeWithPause());
			}
		}

		private IEnumerator InitializeWithPause()
		{
			yield return (object)new WaitForSeconds(3f);
			Initialize();
		}

		private void Initialize()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: 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_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: 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)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			renderParent = new GameObject("Match Status Overlay");
			if ((Object)(object)rawHostIconImage != (Object)null)
			{
				((Component)rawHostIconImage).gameObject.SetActive(false);
			}
			if (!initializedCanvas)
			{
				GameObject gameObject = UI.GetGameObject();
				GameObject val = new GameObject("LocalRawNameplateImage");
				localRawNameplateImage = val.AddComponent<RawImage>();
				val.transform.SetParent(gameObject.transform);
				GameObject val2 = new GameObject("RemoteRawNameplateImage");
				remoteRawNameplateImage = val2.AddComponent<RawImage>();
				val2.transform.SetParent(gameObject.transform);
				GameObject val3 = new GameObject("RawHostIconImage");
				rawHostIconImage = val3.AddComponent<RawImage>();
				using (Stream stream = ((MelonBase)this).MelonAssembly.Assembly.GetManifestResourceStream("MatchStatusOverlay.Resources.hosticon"))
				{
					byte[] array = new byte[stream.Length];
					stream.Read(array, 0, array.Length);
					Il2CppAssetBundle val4 = Il2CppAssetBundleManager.LoadFromMemory(Il2CppStructArray<byte>.op_Implicit(array));
					Texture2D texture = val4.LoadAsset<Texture2D>("host 1");
					rawHostIconImage.texture = (Texture)(object)texture;
				}
				val3.transform.SetParent(gameObject.transform);
				val3.transform.localScale = new Vector3(0.3f, 0.3f, 1f);
				RectTransform component = ((Component)localRawNameplateImage).GetComponent<RectTransform>();
				component.anchoredPosition = new Vector2(180f, -90f);
				component.anchorMax = new Vector2(0f, 1f);
				component.anchorMin = new Vector2(0f, 1f);
				component.sizeDelta = new Vector2(300f, 300f);
				val.transform.localScale = new Vector3(1.3f, 1.3f, 1f);
				RectTransform component2 = ((Component)remoteRawNameplateImage).GetComponent<RectTransform>();
				component2.anchoredPosition = new Vector2(-200f, -90f);
				component2.anchorMax = new Vector2(1f, 1f);
				component2.anchorMin = new Vector2(1f, 1f);
				component2.sizeDelta = new Vector2(300f, 300f);
				val2.transform.localScale = new Vector3(1.3f, 1.3f, 1f);
				initializedCanvas = true;
			}
			InitializeLocal();
			InitializeRemote();
			RectTransform component3 = ((Component)rawHostIconImage).GetComponent<RectTransform>();
			if (Singleton<PlayerManager>.instance.AllPlayers.Count < 2)
			{
				((Component)component3).gameObject.SetActive(false);
			}
			else if (Players.IsHost())
			{
				component3.anchoredPosition = new Vector2(400f, -100f);
				component3.anchorMax = new Vector2(0f, 1f);
				component3.anchorMin = new Vector2(0f, 1f);
				component3.sizeDelta = new Vector2(300f, 300f);
			}
			else
			{
				component3.anchoredPosition = new Vector2(-400f, -10f);
				component3.anchorMax = new Vector2(1f, 1f);
				component3.anchorMin = new Vector2(1f, 1f);
				component3.sizeDelta = new Vector2(300f, 300f);
			}
			StartFadingUI();
		}

		private void InitializeLocal()
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			PlayerController controller = Players.GetLocalPlayer().Controller;
			Transform obj = ((Component)controller).transform.Find("NameTag");
			GameObject val = ((obj != null) ? ((Component)obj).gameObject : null);
			if ((Object)(object)val == (Object)null)
			{
				MelonLogger.Msg("LocalNamePlate is null");
				return;
			}
			localNameplateClone = Object.Instantiate<GameObject>(val);
			localNameplateClone.transform.SetParent(renderParent.transform);
			localNameplateClone.SetActive(true);
			localNameplateClone.transform.position = new Vector3(0f, -1000f, 0f);
			InitializeRenderTextureUI(new Vector3(0f, -1000f, 1f), localRawNameplateImage);
			InitializeNameTag(localNameplateClone, controller);
		}

		private void InitializeRemote()
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			MelonLogger.Msg((object)Singleton<PlayerManager>.instance.AllPlayers.Count);
			if (Singleton<PlayerManager>.instance.AllPlayers.Count < 2)
			{
				((Component)remoteRawNameplateImage).gameObject.SetActive(false);
				return;
			}
			PlayerController controller = Singleton<PlayerManager>.instance.AllPlayers[1].Controller;
			if (!((Object)(object)controller == (Object)null))
			{
				Transform obj = ((Component)controller).transform.Find("NameTag");
				GameObject val = ((obj != null) ? ((Component)obj).gameObject : null);
				if (!((Object)(object)val == (Object)null))
				{
					opponentNameplateClone = Object.Instantiate<GameObject>(val);
					opponentNameplateClone.transform.SetParent(renderParent.transform);
					opponentNameplateClone.SetActive(true);
					opponentNameplateClone.transform.position = new Vector3(20f, -1000f, 0f);
					InitializeRenderTextureUI(new Vector3(20f, -1000f, 1f), remoteRawNameplateImage);
					InitializeNameTag(opponentNameplateClone, controller);
				}
			}
		}

		private void InitializeNameTag(GameObject nameplate, PlayerController controller)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			PlayerNameTag component = nameplate.GetComponent<PlayerNameTag>();
			if ((Object)(object)component != (Object)null)
			{
				((PlayerControllerSubsystem)component).parentController = controller;
				component.followTarget = null;
				((Component)component).transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
				component.UpdatePlayerBPText();
				component.UpdatePlayerNameTagColor();
				component.UpdatePlayerNameText();
				component.UpdatePlayerRankIcon();
				component.UpdatePlayerTitleText();
			}
			nameplate.SetActive(true);
		}

		private void InitializeHealth(GameObject health, PlayerController controller)
		{
			PlayerHealth component = health.GetComponent<PlayerHealth>();
			if ((Object)(object)component != (Object)null)
			{
				((PlayerControllerSubsystem)component).parentController = controller;
				((Component)((Component)component).transform.GetChild(1)).gameObject.SetActive(true);
			}
		}

		private void InitializeRenderTextureUI(Vector3 camPos, RawImage rawImage)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			GameObject val = new GameObject("RenderCam");
			Camera val2 = val.AddComponent<Camera>();
			val2.clearFlags = (CameraClearFlags)2;
			val2.backgroundColor = Color.clear;
			val.transform.SetParent(renderParent.transform);
			val.transform.position = camPos;
			val.transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
			RenderTexture val3 = new RenderTexture(512, 512, 16)
			{
				antiAliasing = 1,
				depth = 16,
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1
			};
			val3.Create();
			val2.targetTexture = val3;
			rawImage.texture = (Texture)(object)val3;
		}

		private IEnumerator FadeInUI(RawImage rawImage)
		{
			if (!((Object)(object)rawImage == (Object)null) && ((Component)rawImage).gameObject.activeInHierarchy)
			{
				CanvasRenderer canvasRenderer = ((Component)rawImage).GetComponent<CanvasRenderer>();
				float elapsedTime = 0f;
				while (elapsedTime < 3f)
				{
					elapsedTime += Time.deltaTime;
					float alpha = Mathf.Clamp01(elapsedTime / 3f);
					canvasRenderer.SetAlpha(alpha);
					yield return null;
				}
			}
		}

		private void StartFadingUI()
		{
			if ((Object)(object)localRawNameplateImage != (Object)null && ((Component)localRawNameplateImage).gameObject.activeInHierarchy)
			{
				MelonCoroutines.Start(FadeInUI(localRawNameplateImage));
			}
			if ((Object)(object)remoteRawNameplateImage != (Object)null && ((Component)remoteRawNameplateImage).gameObject.activeInHierarchy)
			{
				MelonCoroutines.Start(FadeInUI(remoteRawNameplateImage));
			}
			if ((Object)(object)rawHostIconImage != (Object)null && ((Component)rawHostIconImage).gameObject.activeInHierarchy)
			{
				MelonCoroutines.Start(FadeInUI(rawHostIconImage));
			}
			if ((Object)(object)rawTallyImage != (Object)null && ((Component)rawTallyImage).gameObject.activeInHierarchy)
			{
				MelonCoroutines.Start(FadeInUI(rawTallyImage));
			}
		}
	}
}