Decompiled source of CloneBending v1.0.0

Mods/CloneBending.dll

Decompiled 3 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 CloneBending;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppLIV.SDK.Unity;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.MoveSystem;
using Il2CppRUMBLE.Players;
using Il2CppRUMBLE.Players.Scaling;
using Il2CppRUMBLE.Players.Subsystems;
using Il2CppRUMBLE.Utilities;
using Il2CppRootMotion.FinalIK;
using MelonLoader;
using Microsoft.CodeAnalysis;
using RumbleModdingAPI;
using UnityEngine;
using UnityEngine.InputSystem.XR;
using UnityEngine.SpatialTracking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(MainClass), "CloneBending", "1.0.0", "Saveforth", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 246, 96, 223)]
[assembly: AssemblyTitle("CloneBending")]
[assembly: AssemblyDescription("Record a Clone")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Your Company")]
[assembly: AssemblyProduct("Your Product")]
[assembly: AssemblyCopyright("Copyright © Your Company Year")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[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 CloneBending
{
	public class MainClass : MelonMod
	{
		[HarmonyPatch(typeof(PlayerStackProcessor), "Execute", new Type[]
		{
			typeof(Stack),
			typeof(StackConfiguration)
		})]
		public static class stackPatch
		{
			public static void Postfix(Stack stack, StackConfiguration overrideConfig)
			{
				currentStack = stack;
				stackConfig = overrideConfig;
			}
		}

		private static Stack currentStack = null;

		private static string classSceneName = "";

		private static bool isRecording = false;

		private static bool isROnCooldown = false;

		private static bool isPOnCooldown = false;

		private static bool isRecorded = false;

		private static bool isPlaying = false;

		private LinkedList<float[]> handPositions = new LinkedList<float[]>();

		private LinkedList<Quaternion[]> allRotations = new LinkedList<Quaternion[]>();

		private int curFrame = 0;

		private LinkedList<float[]>.Enumerator handIt = default(LinkedList<float[]>.Enumerator);

		private LinkedList<Quaternion[]>.Enumerator rotIt = default(LinkedList<Quaternion[]>.Enumerator);

		private LinkedList<Stack>.Enumerator stackIt = default(LinkedList<Stack>.Enumerator);

		private LinkedList<Stack> recordedStacks = new LinkedList<Stack>();

		private GameObject rHand = null;

		private GameObject lHand = null;

		private GameObject head = null;

		private PlayerStackProcessor pSP = null;

		private GameObject clonePlayer = null;

		private GameObject indicator;

		private static StackConfiguration stackConfig;

		private PlayerController ogPC;

		private bool isCloneSetup = false;

		private GameObject playerForFollow;

		private LIV liv;

		private bool livSingle = false;

		private GameObject rPHand = null;

		private GameObject lPHand = null;

		private GameObject pHead = null;

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

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (sceneName == "Gym")
			{
				MelonLogger.Msg("[Clone Bending] " + Managers.GetPlayerManager().localPlayer.Data.GeneralData.PublicUsername + " Version 2");
				MelonCoroutines.Start(setup());
			}
			classSceneName = sceneName;
		}

		private IEnumerator setup()
		{
			yield return (object)new WaitForSeconds(10f);
			createClone();
			clonePlayer.SetActive(false);
		}

		public override void OnUpdate()
		{
			((MelonBase)this).OnUpdate();
			if (!(classSceneName == "Gym"))
			{
				return;
			}
			if ((RightController.GetJoystickClick() == 1f || Input.GetKeyDown((KeyCode)114)) && !isROnCooldown)
			{
				if (!isRecording)
				{
					MelonLogger.Msg("[CloneBending] Recording");
					handPositions.Clear();
					allRotations.Clear();
					recordedStacks.Clear();
					isRecording = true;
				}
				else
				{
					isRecorded = true;
					isRecording = false;
				}
				isROnCooldown = true;
				MelonCoroutines.Start(RecordCooldown(0));
			}
			if ((LeftController.GetJoystickClick() == 1f || Input.GetKeyDown((KeyCode)108)) && !isRecording && isRecorded && !isPOnCooldown)
			{
				MelonLogger.Msg("[CloneBending] Playing");
				curFrame = 0;
				isPlaying = true;
				isPOnCooldown = true;
				MelonCoroutines.Start(RecordCooldown(1));
			}
		}

		public override void OnFixedUpdate()
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: 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)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: 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_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: 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)
			((MelonBase)this).OnFixedUpdate();
			if (isRecording)
			{
				if (!indicator.active)
				{
					indicator.SetActive(true);
				}
				GameObject gameObject = ((Component)((Component)Players.GetLocalPlayer().Controller).gameObject.transform.GetChild(1)).gameObject;
				ogPC = Players.GetLocalPlayer().Controller;
				GameObject gameObject2 = ((Component)((Component)Players.GetLocalPlayer().Controller).gameObject.transform.GetChild(0)).gameObject;
				Transform child = gameObject.transform.GetChild(2);
				Transform child2 = gameObject.transform.GetChild(1);
				Transform child3 = gameObject.transform.GetChild(0).GetChild(0);
				handPositions.AddLast(new float[10]
				{
					((Component)child2).transform.position.x,
					((Component)child2).transform.position.y,
					((Component)child2).transform.position.z,
					((Component)child).transform.position.x,
					((Component)child).transform.position.y,
					((Component)child).transform.position.z,
					child3.position.x,
					child3.position.y,
					child3.position.z,
					gameObject2.transform.position.y
				});
				allRotations.AddLast((Quaternion[])(object)new Quaternion[3] { child2.localRotation, child.localRotation, child3.localRotation });
				if (handPositions.Count < 1)
				{
					currentStack = null;
				}
				recordedStacks.AddLast(currentStack);
				if ((Object)(object)currentStack != (Object)null)
				{
					currentStack = null;
				}
			}
			if (isPlaying)
			{
				playClone(curFrame);
				curFrame++;
			}
			else if (isCloneSetup && !(classSceneName == "Gym"))
			{
			}
		}

		private void createClone()
		{
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			clonePlayer = Object.Instantiate<GameObject>(((Component)Managers.GetPlayerManager().PlayerControllerPrefab).gameObject).gameObject;
			PlayerController component = clonePlayer.GetComponent<PlayerController>();
			rHand = ((Component)((Component)clonePlayer.gameObject.transform.GetChild(1)).gameObject.transform.GetChild(2)).gameObject;
			lHand = ((Component)((Component)clonePlayer.gameObject.transform.GetChild(1)).gameObject.transform.GetChild(1)).gameObject;
			head = ((Component)clonePlayer.transform.GetChild(1).GetChild(0).GetChild(0)).gameObject;
			((Behaviour)((Component)clonePlayer.transform.GetChild(1).GetChild(2)).GetComponent<TrackedPoseDriver>()).enabled = false;
			((Behaviour)((Component)clonePlayer.transform.GetChild(1).GetChild(1)).GetComponent<TrackedPoseDriver>()).enabled = false;
			((Behaviour)((Component)clonePlayer.transform.GetChild(1).GetChild(0).GetChild(0)).GetComponent<TrackedPoseDriver>()).enabled = false;
			((Behaviour)((Component)clonePlayer.transform.GetChild(6)).GetComponent<VRIK>()).enabled = true;
			((Component)clonePlayer.transform.GetChild(9)).gameObject.SetActive(false);
			pSP = ((Component)clonePlayer.transform).GetComponent<PlayerStackProcessor>();
			((PlayerControllerSubsystem)pSP).Initialize(component);
			pSP.activeStackHandles = ((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).gameObject.GetComponent<PlayerStackProcessor>().activeStackHandles;
			PlayerPoseSystem component2 = ((Component)clonePlayer.transform.GetChild(4)).GetComponent<PlayerPoseSystem>();
			PlayerMeasurement playerMeasurement = Players.GetLocalPlayer().Data.PlayerMeasurement;
			component.assignedPlayer.Data = Players.GetLocalPlayer().Data;
			component.assignedPlayer.Data.SetMeasurement(playerMeasurement, true);
			component.Initialize(component.AssignedPlayer);
			((Behaviour)((Component)clonePlayer.transform.GetChild(1).GetChild(2)).GetComponent<TrackedPoseDriver>()).enabled = false;
			((Behaviour)((Component)clonePlayer.transform.GetChild(1).GetChild(1)).GetComponent<TrackedPoseDriver>()).enabled = false;
			((Behaviour)((Component)clonePlayer.transform.GetChild(1).GetChild(0).GetChild(0)).GetComponent<TrackedPoseDriver>()).enabled = false;
			GameObject gameObject = ((Component)clonePlayer.transform.GetChild(1).GetChild(0).GetChild(0)).gameObject;
			((Behaviour)gameObject.GetComponent<Camera>()).enabled = false;
			((Behaviour)gameObject.GetComponent<AudioListener>()).enabled = false;
			Transform child = clonePlayer.transform.GetChild(4);
			component2 = ((Component)child).GetComponent<PlayerPoseSystem>();
			component2.currentInputPoses.Clear();
			MelonLogger.Msg("poses cleared");
			GameObject[] array = Il2CppArrayBase<GameObject>.op_Implicit(Object.FindObjectsOfType<GameObject>());
			List<GameObject> list = new List<GameObject>();
			GameObject[] array2 = array;
			foreach (GameObject val in array2)
			{
				if (((Object)val).name == "Health")
				{
					list.Add(val);
				}
			}
			list[0].transform.parent = clonePlayer.transform;
			playerForFollow = ((Component)((Component)Players.GetLocalPlayer().Controller).gameObject.transform.GetChild(1)).gameObject;
			((Component)clonePlayer.transform.GetChild(1)).gameObject.SetActive(false);
			((Component)clonePlayer.transform.GetChild(8)).gameObject.SetActive(true);
			liv = ((Component)clonePlayer.transform.GetChild(8)).gameObject.GetComponent<LIV>();
			((Behaviour)liv).enabled = false;
			lPHand = ((Component)clonePlayer.transform.GetChild(0).GetChild(2)).gameObject;
			rPHand = ((Component)clonePlayer.transform.GetChild(0).GetChild(3)).gameObject;
			pHead = ((Component)clonePlayer.transform.GetChild(0)).gameObject;
			lPHand.SetActive(false);
			rPHand.SetActive(false);
			pHead.SetActive(false);
			isCloneSetup = true;
		}

		private void playClone(int curFrame)
		{
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: 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_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_045a: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0490: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c8: 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_04eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0514: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			if (curFrame < handPositions.Count)
			{
				if (curFrame == 0)
				{
					rotIt = allRotations.GetEnumerator();
					handIt = handPositions.GetEnumerator();
					stackIt = recordedStacks.GetEnumerator();
					clonePlayer.SetActive(true);
					if (livSingle)
					{
						((Behaviour)liv).enabled = false;
					}
				}
				else if (!livSingle && curFrame == 5)
				{
					((Behaviour)liv).enabled = false;
					livSingle = true;
				}
				handIt.MoveNext();
				rotIt.MoveNext();
				stackIt.MoveNext();
				Vector3 eulerAngles = ((Quaternion)(ref rotIt.Current[0])).eulerAngles;
				((Vector3)(ref eulerAngles))..ctor(eulerAngles.x, eulerAngles.y, eulerAngles.z);
				Vector3 eulerAngles2 = ((Quaternion)(ref rotIt.Current[1])).eulerAngles;
				((Vector3)(ref eulerAngles2))..ctor(eulerAngles2.x, eulerAngles2.y, eulerAngles2.z);
				lHand.transform.SetPositionAndRotation(new Vector3(handIt.Current[0], handIt.Current[1], handIt.Current[2]), Quaternion.Euler(eulerAngles));
				rHand.transform.SetPositionAndRotation(new Vector3(handIt.Current[3], handIt.Current[4], handIt.Current[5]), Quaternion.Euler(eulerAngles2));
				head.transform.SetPositionAndRotation(new Vector3(handIt.Current[6], handIt.Current[7], handIt.Current[8]), rotIt.Current[2]);
				lPHand.transform.SetPositionAndRotation(new Vector3(handIt.Current[0], handIt.Current[1], handIt.Current[2]), Quaternion.Euler(eulerAngles));
				rPHand.transform.SetPositionAndRotation(new Vector3(handIt.Current[3], handIt.Current[4], handIt.Current[5]), Quaternion.Euler(eulerAngles2));
				clonePlayer.transform.position = new Vector3(clonePlayer.transform.position.x, handIt.Current[9], clonePlayer.transform.position.z);
				if ((Object)(object)stackIt.Current != (Object)null)
				{
					pSP.Execute(stackIt.Current, (StackConfiguration)null);
				}
			}
			else
			{
				MelonLogger.Msg("[CloneBending] Frame: " + curFrame);
				isPlaying = false;
				curFrame = 0;
				LinkedList<Quaternion[]>.Enumerator enumerator = allRotations.GetEnumerator();
				LinkedList<float[]>.Enumerator enumerator2 = handPositions.GetEnumerator();
				enumerator.MoveNext();
				enumerator2.MoveNext();
				Vector3 eulerAngles3 = ((Quaternion)(ref enumerator.Current[0])).eulerAngles;
				((Vector3)(ref eulerAngles3))..ctor(eulerAngles3.x, eulerAngles3.y, eulerAngles3.z);
				Vector3 eulerAngles4 = ((Quaternion)(ref enumerator.Current[1])).eulerAngles;
				((Vector3)(ref eulerAngles4))..ctor(eulerAngles4.x, eulerAngles4.y, eulerAngles4.z);
				lHand.transform.SetPositionAndRotation(new Vector3(enumerator2.Current[0], enumerator2.Current[1], enumerator2.Current[2]), Quaternion.Euler(eulerAngles3));
				rHand.transform.SetPositionAndRotation(new Vector3(enumerator2.Current[3], enumerator2.Current[4], enumerator2.Current[5]), Quaternion.Euler(eulerAngles4));
				head.transform.SetPositionAndRotation(new Vector3(enumerator2.Current[6], enumerator2.Current[7], enumerator2.Current[8]), enumerator.Current[2]);
				lPHand.transform.SetPositionAndRotation(new Vector3(enumerator2.Current[0], enumerator2.Current[1], enumerator2.Current[2]), Quaternion.Euler(eulerAngles3));
				rPHand.transform.SetPositionAndRotation(new Vector3(enumerator2.Current[3], enumerator2.Current[4], enumerator2.Current[5]), Quaternion.Euler(eulerAngles4));
				clonePlayer.transform.position = new Vector3(clonePlayer.transform.position.x, enumerator2.Current[9], clonePlayer.transform.position.z);
				MelonCoroutines.Start(finishPlaying());
			}
		}

		private IEnumerator finishPlaying()
		{
			yield return (object)new WaitForSeconds(1f);
			if (!isPlaying)
			{
				clonePlayer.SetActive(false);
			}
		}

		private IEnumerator RecordCooldown(int x)
		{
			if (isRecording)
			{
				indicator.SetActive(true);
			}
			else
			{
				indicator.SetActive(false);
			}
			yield return (object)new WaitForSeconds(2f);
			if (x == 0)
			{
				isROnCooldown = false;
			}
			else
			{
				isPOnCooldown = false;
			}
		}

		private void indicatorCircle()
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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)
			GameObject gameObject = ((Component)((Component)Players.GetLocalPlayer().Controller).gameObject.transform.GetChild(1)).gameObject;
			Transform child = gameObject.transform.GetChild(2);
			indicator = GameObject.CreatePrimitive((PrimitiveType)2);
			indicator.transform.parent = child;
			((Object)indicator).name = "Indicator";
			indicator.transform.localPosition = new Vector3(0.06f, 0.005f, 0.09f);
			indicator.transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, 90f));
			indicator.transform.localScale = new Vector3(0.02f, 0.004f, 0.02f);
			indicator.GetComponent<Renderer>().material.shader = Shader.Find("Universal Render Pipeline/Lit");
			indicator.SetActive(false);
		}
	}
}