Decompiled source of Combo Scorer v2.1.1

Mods/ComboScorer.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using ComboScorer;
using HarmonyLib;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Players.Subsystems;
using Il2CppRUMBLE.Poses;
using Il2CppRUMBLE.Utilities;
using Il2CppTMPro;
using MelonLoader;
using RumbleModdingAPI;
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(Class1), "ComboScorer", "2.1.0", "Revenoon", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: VerifyLoaderVersion(0, 6, 2, true)]
[assembly: AssemblyTitle("ComboScorer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ComboScorer")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6eee431e-cd8a-457f-8eb4-f4b840fdff57")]
[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 ComboScorer;

public class Class1 : MelonMod
{
	private bool init = false;

	private string currentScene = "Loader";

	private int sceneCount = 0;

	private GameObject textGameObject;

	private TextMeshPro hitIndicator;

	private GameObject comboDisplay;

	private TextMeshPro comboDisplayText;

	private GameObject leftPosition;

	private TextMeshPro leftPosText;

	private GameObject leftRotation;

	private TextMeshPro leftRotText;

	private GameObject rightPosition;

	private TextMeshPro rightPosText;

	private GameObject rightRotation;

	private TextMeshPro rightRotText;

	private int lPosScore;

	private int rPosScore;

	private int lRotScore;

	private int rRotScore;

	private int efficiencyScore = 0;

	private int comboLength;

	private bool isRecording = false;

	private bool allowedPose;

	private int mode = 1;

	private DateTime pause;

	private GameObject player;

	private string currentCombo = "";

	private Transform handLTransform;

	private Transform handRTransform;

	private Vector3 startLHandPosition;

	private Vector3 startRHandPosition;

	private Vector3 endLHandPosition;

	private Vector3 endRHandPosition;

	private float distanceL;

	private float distanceR;

	private float totalDistanceL;

	private float totalDistanceR;

	private Quaternion startLHandRotation;

	private Quaternion startRHandRotation;

	private Quaternion endLHandRotation;

	private Quaternion endRHandRotation;

	private float rotationL;

	private float rotationR = 0f;

	private float totalRotationL;

	private float totalRotationR;

	public override void OnLateInitializeMelon()
	{
		Calls.onMapInitialized += MapChange;
	}

	public void MapChange()
	{
		if (currentScene != "Loader")
		{
			MelonCoroutines.Start(initPause(sceneCount));
		}
	}

	public IEnumerator initPause(int sceneNumber)
	{
		DateTime timeToStart = DateTime.Now.AddSeconds(1.0);
		while (DateTime.Now < timeToStart)
		{
			yield return (object)new WaitForFixedUpdate();
		}
		if (sceneNumber == sceneCount)
		{
			initalized();
		}
	}

	public void initalized()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Unknown result type (might be due to invalid IL or missing references)
		//IL_0324: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_040c: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_055e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0588: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = Create.NewText("...", 0.5f, Color.white, Vector3.zero, Quaternion.Euler(0f, 0f, 0f));
		val.transform.parent = ((Component)Players.GetPlayerController()).transform.GetChild(5).GetChild(7).GetChild(0)
			.GetChild(2)
			.GetChild(0)
			.GetChild(2)
			.GetChild(0)
			.GetChild(0)
			.GetChild(0);
		((Object)val).name = "ComboScore";
		val.gameObject.transform.localPosition = new Vector3(0.032f, 0.1f, -0.001f);
		val.gameObject.transform.localRotation = Quaternion.Euler(11f, 272f, 4f);
		hitIndicator = val.GetComponent<TextMeshPro>();
		((TMP_Text)hitIndicator).outlineColor = Color32.op_Implicit(new Color(0f, 0f, 0f, 0.5f));
		((TMP_Text)hitIndicator).outlineWidth = 0.1f;
		((TMP_Text)hitIndicator).alignment = (TextAlignmentOptions)514;
		((TMP_Text)hitIndicator).enableWordWrapping = false;
		player = ((Component)((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).gameObject.transform.GetChild(1)).gameObject;
		handLTransform = player.transform.GetChild(1);
		handRTransform = player.transform.GetChild(2);
		if (currentScene == "Gym")
		{
			GameObject val2 = Create.NewText("Combo Scorer", 3f, Color.white, Vector3.zero, Quaternion.Euler(0f, 0f, 0f));
			((Object)val2).name = "Combo Display";
			val2.gameObject.transform.position = new Vector3(-2.23f, -2.42f, -15.5f);
			val2.gameObject.transform.rotation = Quaternion.Euler(0f, 306.4f, 0f);
			comboDisplayText = val2.GetComponent<TextMeshPro>();
			((TMP_Text)comboDisplayText).outlineColor = Color32.op_Implicit(new Color(0f, 0f, 0f, 0.5f));
			((TMP_Text)comboDisplayText).outlineWidth = 0.1f;
			((TMP_Text)comboDisplayText).alignment = (TextAlignmentOptions)514;
			((TMP_Text)comboDisplayText).enableWordWrapping = false;
			leftPosition = Object.Instantiate<GameObject>(val2);
			((Object)leftPosition).name = "Left Postion Display";
			leftPosition.transform.parent = val2.transform;
			leftPosText = leftPosition.GetComponent<TextMeshPro>();
			((TMP_Text)leftPosText).fontSize = 2f;
			((TMP_Text)leftPosText).text = "L Pos Loss: " + Environment.NewLine + "...";
			leftPosition.gameObject.transform.localPosition = new Vector3(-0.4f, -0.4f, 0f);
			leftPosition.gameObject.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
			leftRotation = Object.Instantiate<GameObject>(leftPosition);
			((Object)leftRotation).name = "Left Rotation Display";
			leftRotation.transform.parent = val2.transform;
			leftRotText = leftRotation.GetComponent<TextMeshPro>();
			((TMP_Text)leftRotText).text = "L Rot Loss: " + Environment.NewLine + "...";
			leftRotation.gameObject.transform.localPosition = new Vector3(-0.4f, -0.9f, 0f);
			leftRotation.gameObject.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
			rightPosition = Object.Instantiate<GameObject>(leftPosition);
			((Object)rightPosition).name = "Right Position Display";
			rightPosition.transform.parent = val2.transform;
			rightPosText = rightPosition.GetComponent<TextMeshPro>();
			((TMP_Text)rightPosText).text = "R Pos Loss: " + Environment.NewLine + "...";
			rightPosition.gameObject.transform.localPosition = new Vector3(0.4f, -0.4f, 0f);
			rightPosition.gameObject.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
			rightRotation = Object.Instantiate<GameObject>(leftPosition);
			((Object)rightRotation).name = "Right Rotation Display";
			rightRotation.transform.parent = val2.transform;
			rightRotText = rightRotation.GetComponent<TextMeshPro>();
			((TMP_Text)rightRotText).text = "R Rot Loss: " + Environment.NewLine + "...";
			rightRotation.gameObject.transform.localPosition = new Vector3(0.4f, -0.9f, 0f);
			rightRotation.gameObject.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
		}
		PosePatch.poseName = "";
		init = true;
	}

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

	public override void OnUpdate()
	{
		if (!init)
		{
			return;
		}
		int num = mode;
		int num2 = num;
		if (num2 == 0 || num2 != 1)
		{
			if (PosePatch.poseName != "" && PosePatch.poseName != "Poses_StructureX")
			{
				allowedPose = true;
			}
		}
		else if (PosePatch.poseName == "Poses_Straight_015" || PosePatch.poseName == "Poses_Uppercut_015" || PosePatch.poseName == "Poses_Kick_015")
		{
			allowedPose = true;
			if (PosePatch.poseName == "Poses_Straight_015")
			{
				currentCombo += "S";
			}
			else if (PosePatch.poseName == "Poses_Uppercut_015")
			{
				currentCombo += "U";
			}
			else if (PosePatch.poseName == "Poses_Kick_015")
			{
				currentCombo += "K";
			}
			else
			{
				MelonLogger.Msg("currentCombo recording failure.");
			}
		}
		recordHand();
	}

	private void recordHand()
	{
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: 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_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0267: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		if (!isRecording)
		{
			if (allowedPose)
			{
				((TMP_Text)hitIndicator).text = "...";
				if (currentScene == "Gym")
				{
					((TMP_Text)comboDisplayText).text = "...";
					((TMP_Text)leftPosText).text = "L Pos Loss: " + Environment.NewLine + "...";
					((TMP_Text)leftRotText).text = "L Rot Loss: " + Environment.NewLine + "...";
					((TMP_Text)rightPosText).text = "R Pos Loss: " + Environment.NewLine + "...";
					((TMP_Text)rightRotText).text = "R Rot Loss: " + Environment.NewLine + "...";
				}
				startLHandPosition = handLTransform.localPosition;
				startRHandPosition = handRTransform.localPosition;
				startLHandRotation = handLTransform.localRotation;
				startRHandRotation = handRTransform.localRotation;
				distanceL = 0f;
				distanceR = 0f;
				rotationL = 0f;
				rotationR = 0f;
				totalDistanceL = 0f;
				totalDistanceR = 0f;
				totalRotationL = 0f;
				totalRotationR = 0f;
				comboLength++;
				pause = DateTime.Now.AddSeconds(1.0);
				PosePatch.poseName = "";
				allowedPose = false;
				isRecording = true;
			}
			return;
		}
		endLHandPosition = handLTransform.localPosition;
		endRHandPosition = handRTransform.localPosition;
		endLHandRotation = handLTransform.localRotation;
		endRHandRotation = handRTransform.localRotation;
		totalDistanceL += Vector3.Distance(startLHandPosition, endLHandPosition);
		totalDistanceR += Vector3.Distance(startRHandPosition, endRHandPosition);
		totalRotationL += Quaternion.Angle(startLHandRotation, endLHandRotation);
		totalRotationR += Quaternion.Angle(startRHandRotation, endRHandRotation);
		startLHandPosition = endLHandPosition;
		startRHandPosition = endRHandPosition;
		startLHandRotation = endLHandRotation;
		startRHandRotation = endRHandRotation;
		if (allowedPose)
		{
			distanceL = totalDistanceL;
			distanceR = totalDistanceR;
			rotationL = totalRotationL;
			rotationR = totalRotationR;
			comboLength++;
			PosePatch.poseName = "";
			allowedPose = false;
			pause = DateTime.Now.AddSeconds(1.0);
		}
		if (pause <= DateTime.Now)
		{
			efficiencyScore = (int)Math.Round(10000f * (float)Math.Pow(1.0049999952316284, -0.2 * (double)(600f * (distanceL + distanceR) + 1f * (rotationL + rotationR))));
			if (comboLength == 1)
			{
				efficiencyScore = 0;
			}
			if (currentScene == "Gym")
			{
				((TMP_Text)comboDisplayText).text = currentCombo + ": " + efficiencyScore;
				((TMP_Text)leftPosText).text = "L Pos Loss: " + Environment.NewLine + (600f * distanceL / (600f * (distanceL + distanceR) + 1f * (rotationL + rotationR)) * (float)(10000 - efficiencyScore)).ToString("0") + " pts";
				((TMP_Text)leftRotText).text = "L Rot Loss: " + Environment.NewLine + (1f * rotationL / (600f * (distanceL + distanceR) + 1f * (rotationL + rotationR)) * (float)(10000 - efficiencyScore)).ToString("0") + " pts";
				((TMP_Text)rightPosText).text = "R Pos Loss: " + Environment.NewLine + (600f * distanceR / (600f * (distanceL + distanceR) + 1f * (rotationL + rotationR)) * (float)(10000 - efficiencyScore)).ToString("0") + " pts";
				((TMP_Text)rightRotText).text = "R Rot Loss: " + Environment.NewLine + (1f * rotationR / (600f * (distanceL + distanceR) + 1f * (rotationL + rotationR)) * (float)(10000 - efficiencyScore)).ToString("0") + " pts";
			}
			((TMP_Text)hitIndicator).text = efficiencyScore.ToString();
			currentCombo = "";
			comboLength = 0;
			isRecording = false;
		}
	}
}
[HarmonyPatch(typeof(PlayerPoseSystem), "OnPoseCompleted", new Type[] { typeof(PoseData) })]
public static class PosePatch
{
	public static string poseName;

	private static void Postfix(PoseData pose)
	{
		poseName = ((Object)pose).name;
	}
}