Decompiled source of Combo Scorer 2 v1.0.0

Mods/ComboScorer2.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using ComboScorer2;
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), "ComboScorer2", "1.0.0", "Lopes", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 64, 93, 199)]
[assembly: MelonAuthorColor(255, 64, 93, 199)]
[assembly: VerifyLoaderVersion(0, 6, 6, true)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ComboScorer2")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ComboScorer2")]
[assembly: AssemblyTitle("ComboScorer2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ComboScorer2;

public class Class1 : MelonMod
{
	[CompilerGenerated]
	private sealed class <initPause>d__47 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public int sceneNumber;

		public Class1 <>4__this;

		private DateTime <timeToStart>5__1;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <initPause>d__47(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<timeToStart>5__1 = DateTime.Now.AddSeconds(1.0);
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			if (DateTime.Now < <timeToStart>5__1)
			{
				<>2__current = (object)new WaitForFixedUpdate();
				<>1__state = 1;
				return true;
			}
			if (sceneNumber == <>4__this.sceneCount)
			{
				<>4__this.initalized();
			}
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	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));
		}
	}

	[IteratorStateMachine(typeof(<initPause>d__47))]
	public IEnumerator initPause(int sceneNumber)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <initPause>d__47(0)
		{
			<>4__this = this,
			sceneNumber = sceneNumber
		};
	}

	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_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0322: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0474: Unknown result type (might be due to invalid IL or missing references)
		//IL_049e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0532: Unknown result type (might be due to invalid IL or missing references)
		//IL_055c: 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.FindChild("Visuals/Skelington/Bone_Pelvis/Bone_Spine_A/Bone_Chest/Bone_Shoulderblade_R/Bone_Shoulder_R/Bone_Lowerarm_R/Bone_HandAlpha_R");
		((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(2)).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;
	}
}