Decompiled source of DiscClicker v0.1.4

DiscClicker.dll

Decompiled 4 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using DiscClicker;
using HarmonyLib;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Players;
using Il2CppRUMBLE.Players.Subsystems;
using Il2CppRUMBLE.Utilities;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
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(global::DiscClicker.DiscClicker), "DiscClicker", "0.1.4", "SharpFireRuby", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: AssemblyTitle("DiscClicker")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DiscClicker")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ab921726-675b-4e05-99e3-10d0b4213cf9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DiscClicker;

public class InGameUiHandler : MelonMod
{
	public GameObject backBoard;

	public void CreateUi()
	{
		backBoard = Object.Instantiate<GameObject>(GameObject.Find("--------------LOGIC--------------/Heinhouser products/RegionSelector/Model/"));
		Object.DontDestroyOnLoad((Object)(object)backBoard);
		for (int i = 0; i < backBoard.transform.childCount; i++)
		{
			if (i != 2 && i != 7)
			{
				Object.Destroy((Object)(object)((Component)backBoard.transform.GetChild(i)).gameObject);
			}
		}
		Object.Destroy((Object)(object)((Component)backBoard.transform.GetChild(7).GetChild(0)).gameObject);
		((Object)backBoard).name = "DiscClickerUi";
		backBoard.SetActive(false);
	}

	public void MoveUi(float x, float y, float z, int xr, int yr, int zr, bool visible)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		backBoard.SetActive(visible);
		backBoard.transform.position = new Vector3(x, y, z);
		backBoard.transform.rotation = Quaternion.Euler((float)xr, (float)yr, (float)zr);
		backBoard.transform.localScale = Vector3.one * 2f;
	}

	public void MoveUi(bool visible)
	{
		backBoard.SetActive(visible);
	}

	public void UpdateUi(ulong uiDisplay)
	{
		((TMP_Text)((Component)backBoard.transform.GetChild(1).GetChild(0)).GetComponent<TextMeshProUGUI>()).text = uiDisplay.ToString();
	}
}
public static class BuildInfo
{
	public const string Name = "DiscClicker";

	public const string Author = "SharpFireRuby";

	public const string Version = "0.1.4";
}
public class DiscClicker : MelonMod
{
	[HarmonyPatch(typeof(PlayerBoxInteractionSystem), "OnPlayerBoxInteraction", new Type[]
	{
		typeof(PlayerBoxInteractionTrigger),
		typeof(PlayerBoxInteractionTrigger)
	})]
	public static class FistBumpDetection
	{
		private static bool playerFisted;

		private static void Postfix(PlayerBoxInteractionTrigger first, PlayerBoxInteractionTrigger second)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if (!firstCall)
			{
				firstCall = true;
				return;
			}
			firstCall = false;
			for (int i = 0; i < poolPlayerBoxAny.transform.childCount; i++)
			{
				GameObject gameObject = ((Component)poolPlayerBoxAny.transform.GetChild(i)).gameObject;
				if (!gameObject.active)
				{
					continue;
				}
				if (!startedPoolPlayerBoxAny.Contains(gameObject))
				{
					bool flag = IsHandLocalClosest(gameObject.transform.position, 1);
					bool flag2 = IsHandLocalClosest(gameObject.transform.position, 2);
					if (flag && flag2)
					{
						playerFisted = true;
						if (debug)
						{
							((MelonBase)Melon<DiscClicker>.Instance).LoggerInstance.Msg("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
						}
					}
					else
					{
						playerFisted = false;
					}
				}
				startedPoolPlayerBoxAny.Add(gameObject);
			}
			if (playerFisted)
			{
				fistCount++;
				fistCountTotal++;
			}
		}

		private static bool IsHandLocalClosest(Vector3 pos, int handChildIndex)
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			List<Transform> list = new List<Transform>();
			float num = float.MaxValue;
			if (debug)
			{
				((MelonBase)Melon<DiscClicker>.Instance).LoggerInstance.Msg(num + " float.MaxValue");
			}
			Transform val = null;
			int num2 = 0;
			Enumerator<Player> enumerator = Singleton<PlayerManager>.Instance.AllPlayers.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Player current = enumerator.Current;
				list.Add(((Component)current.Controller).gameObject.transform.GetChild(1).GetChild(handChildIndex));
				if (debug)
				{
					Instance loggerInstance = ((MelonBase)Melon<DiscClicker>.Instance).LoggerInstance;
					Vector3 position = ((Component)current.Controller).gameObject.transform.GetChild(1).GetChild(handChildIndex).position;
					loggerInstance.Msg(((object)(Vector3)(ref position)).ToString() + " " + handChildIndex);
				}
			}
			foreach (Transform item in list)
			{
				if (Vector3.Distance(pos, item.position) < num)
				{
					val = item;
					num2 = ((Object)val).GetHashCode();
					num = Vector3.Distance(pos, item.position);
					if (debug)
					{
						((MelonBase)Melon<DiscClicker>.Instance).LoggerInstance.Msg(((Object)val).name + " closestHand.name");
						((MelonBase)Melon<DiscClicker>.Instance).LoggerInstance.Msg(num2 + " closestHand.hash");
						((MelonBase)Melon<DiscClicker>.Instance).LoggerInstance.Msg(num + " closestDistance");
					}
				}
			}
			int hashCode = ((Object)((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).gameObject.transform.GetChild(1).GetChild(handChildIndex)).GetHashCode();
			if (debug)
			{
				((MelonBase)Melon<DiscClicker>.Instance).LoggerInstance.Msg(((Object)((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).gameObject.transform.GetChild(1).GetChild(handChildIndex)).name + " return.name");
				((MelonBase)Melon<DiscClicker>.Instance).LoggerInstance.Msg(hashCode + " return.hash");
			}
			return num2 == hashCode;
		}
	}

	[CompilerGenerated]
	private sealed class <AfterSceneLoad>d__19 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public DiscClicker <>4__this;

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

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

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

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

		private bool MoveNext()
		{
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = null;
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if (<>4__this.InGameUiCreated && <>4__this.currentScene != "Gym" && <>4__this.currentScene != "Park")
				{
					<>4__this.InGameUiHandler.MoveUi(visible: false);
				}
				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();
		}
	}

	[CompilerGenerated]
	private sealed class <AutoSave>d__22 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public DiscClicker <>4__this;

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

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

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

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

		private bool MoveNext()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				break;
			case 1:
				<>1__state = -1;
				<>4__this.discPointsCalc = (ulong)((float)<>4__this.discPointsLast + <>4__this.timeDistance * (float)<>4__this.discPointsPerSecond + (float)(fistCount * <>4__this.discFistMod));
				File.WriteAllText(<>4__this.defaultPath + "/DiscPoints.sav", <>4__this.discPointsCalc.ToString());
				fistCount = 0u;
				File.WriteAllText(<>4__this.defaultPath + "/FistTotal.sav", fistCountTotal.ToString());
				break;
			}
			<>2__current = (object)new WaitForSeconds(360f);
			<>1__state = 1;
			return true;
		}

		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 string currentScene;

	private string defaultPath = "UserData/DiscClickerSavs";

	private bool buttonSaved;

	private ulong discPointsLast;

	private uint discPointsPerSecond;

	private float timeDistance;

	private ulong discPointsCalc;

	private ulong discFistMod = 1uL;

	private bool fistBumped;

	public static uint fistCount;

	public static uint fistCountTotal;

	private static bool firstCall;

	private InGameUiHandler InGameUiHandler = new InGameUiHandler();

	private bool sceneInit = false;

	public bool InGameUiCreated = false;

	private static GameObject poolPlayerBoxAny;

	private static List<GameObject> startedPoolPlayerBoxAny = new List<GameObject>();

	private static bool debug = false;

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		currentScene = sceneName;
		if (currentScene == "Loader")
		{
			if (!Directory.Exists(defaultPath))
			{
				Directory.CreateDirectory(defaultPath);
			}
			((MelonBase)this).LoggerInstance.Msg(File.ReadAllText(defaultPath + "/DiscPoints.sav"));
			if (!File.Exists(defaultPath + "/DiscPoints.sav"))
			{
				File.Create(defaultPath + "/DiscPoints.sav");
			}
			else
			{
				discPointsLast = ulong.Parse(File.ReadAllText(defaultPath + "/DiscPoints.sav"));
			}
			if (!File.Exists(defaultPath + "/FistTotal.sav"))
			{
				File.Create(defaultPath + "/FistTotal.sav");
			}
			else
			{
				fistCountTotal = uint.Parse(File.ReadAllText(defaultPath + "/FistTotal.sav"));
			}
		}
		if (currentScene == "Loader")
		{
			return;
		}
		if (!sceneInit)
		{
			if (InGameUiCreated)
			{
				InGameUiHandler.MoveUi(visible: false);
			}
			discPointsCalc = (ulong)((float)discPointsLast + timeDistance * (float)discPointsPerSecond + (float)(fistCount * discFistMod));
			File.WriteAllText(defaultPath + "/DiscPoints.sav", discPointsCalc.ToString());
			fistCount = 0u;
			File.WriteAllText(defaultPath + "/FistTotal.sav", fistCountTotal.ToString());
			if (currentScene == "Gym")
			{
				if (!InGameUiCreated)
				{
					InGameUiHandler.CreateUi();
					InGameUiCreated = true;
					poolPlayerBoxAny = GameObject.Find("Game Instance/Pre-Initializable/PoolManager/Pool: PlayerBoxInteractionVFX (RUMBLE.Pools.PooledVisualEffect)");
				}
				InGameUiHandler.MoveUi(0.2f, 1.5f, 1.3f, 90, 220, 0, visible: true);
			}
			else if (currentScene == "Park")
			{
				InGameUiHandler.MoveUi(-29.3f, -1.5f, -7.5f, 90, 82, 0, visible: true);
			}
			else
			{
				InGameUiHandler.MoveUi(visible: false);
			}
		}
		MelonCoroutines.Start(AutoSave());
		MelonCoroutines.Start(AfterSceneLoad());
		sceneInit = true;
	}

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

	public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
	{
		if (InGameUiCreated)
		{
			InGameUiHandler.MoveUi(visible: false);
		}
		sceneInit = false;
	}

	public override void OnFixedUpdate()
	{
		if (currentScene == "Gym" || currentScene == "Park")
		{
			discPointsCalc = (ulong)((float)discPointsLast + timeDistance * (float)discPointsPerSecond + (float)(fistCount * discFistMod));
			InGameUiHandler.UpdateUi(discPointsCalc);
		}
		if (InGameUiCreated)
		{
			for (int i = 0; i < poolPlayerBoxAny.transform.childCount; i++)
			{
				GameObject gameObject = ((Component)poolPlayerBoxAny.transform.GetChild(i)).gameObject;
				if (!gameObject.active)
				{
					startedPoolPlayerBoxAny.Remove(gameObject);
				}
			}
		}
		if (debug)
		{
			if (RightController.GetSecondary() > 0f && !fistBumped)
			{
				fistBumped = true;
				fistCount++;
				fistCountTotal++;
			}
			else if (RightController.GetSecondary() <= 0f)
			{
				fistBumped = false;
			}
			if (LeftController.GetSecondary() > 0f && !buttonSaved)
			{
				buttonSaved = true;
				discPointsCalc = (ulong)((float)discPointsLast + timeDistance * (float)discPointsPerSecond + (float)(fistCount * discFistMod));
				File.WriteAllText(defaultPath + "/DiscPoints.sav", discPointsLast.ToString());
				fistCount = 0u;
				File.WriteAllText(defaultPath + "/FistTotal.sav", fistCountTotal.ToString());
			}
			else if (LeftController.GetSecondary() <= 0f)
			{
				buttonSaved = false;
				return;
			}
		}
		firstCall = false;
	}

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

	public override void OnDeinitializeMelon()
	{
		discPointsLast += (ulong)(timeDistance * (float)discPointsPerSecond) + fistCount * discFistMod;
		File.WriteAllText(defaultPath + "/DiscPoints.sav", discPointsLast.ToString());
		fistCount = 0u;
		File.WriteAllText(defaultPath + "/FistTotal.sav", fistCountTotal.ToString());
	}
}
public class CustomLogger : MelonMod
{
	public void LogCustom(string defaultPath, Array message)
	{
		if (!File.Exists(defaultPath + "/dev.txt"))
		{
			return;
		}
		foreach (object item in message)
		{
			((MelonBase)this).LoggerInstance.Msg((object)message);
		}
	}
}