Decompiled source of MoveRestrictor v2.3.0

Mods/MoveRestrictor.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Players;
using Il2CppRUMBLE.Players.Subsystems;
using Il2CppRUMBLE.Poses;
using Il2CppRUMBLE.Utilities;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using MoveRestrictor;
using UIFramework;
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(Main), "MoveRestrictor", "2.3.0", "UlvakSkillz", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 195, 0, 255)]
[assembly: MelonAuthorColor(255, 195, 0, 255)]
[assembly: VerifyLoaderVersion(0, 7, 2, true)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MoveRestrictor")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5986eed166e2cb27b6274368e8e4be174d330eb9")]
[assembly: AssemblyProduct("MoveRestrictor")]
[assembly: AssemblyTitle("MoveRestrictor")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MoveRestrictor;

public static class BuildInfo
{
	public const string ModName = "MoveRestrictor";

	public const string ModVersion = "2.3.0";

	public const string Author = "UlvakSkillz";
}
public class Main : MelonMod
{
	[HarmonyPatch(typeof(PlayerPoseSystem), "Initialize", new Type[] { typeof(PlayerController) })]
	public static class PlayerPoseSystemInitializePatch
	{
		private static void Postfix(ref PlayerPoseSystem __instance, PlayerController controller)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			if ((int)controller.controllerType == 1)
			{
				storedMoves.Clear();
				ChangeAvailableMoveSets(__instance);
			}
		}
	}

	private static List<PoseInputSource> storedMoves = new List<PoseInputSource>();

	public override void OnInitializeMelon()
	{
		Preferences.InitPrefs();
		((ModelModItem)UI.Register((MelonBase)(object)this, (MelonPreferences_Category[])(object)new MelonPreferences_Category[4]
		{
			Preferences.SettingsCategory,
			Preferences.StructuresCategory,
			Preferences.ModifiersCategory,
			Preferences.MovementCategory
		})).OnModSaved += Save;
	}

	public static void Save()
	{
		if (Preferences.AnyPrefsChanged())
		{
			ChangeAvailableMoveSets(Singleton<PlayerManager>.instance.localPlayer.Controller.PlayerPoseSystem);
			Preferences.StoreLastSavedPrefs();
		}
	}

	public static void ChangeAvailableMoveSets(PlayerPoseSystem __instance)
	{
		List<string> list = new List<string>();
		if (!Preferences.PrefSprintBlocked.Value)
		{
			list.Add("SprintingPoseSet");
		}
		if (!Preferences.PrefDiscBlocked.Value)
		{
			list.Add("PoseSetDisc");
		}
		if (!Preferences.PrefPillarBlocked.Value)
		{
			list.Add("PoseSetSpawnPillar");
		}
		if (!Preferences.PrefStraightBlocked.Value)
		{
			list.Add("PoseSetStraight");
		}
		if (!Preferences.PrefBallBlocked.Value)
		{
			list.Add("PoseSetBall");
		}
		if (!Preferences.PrefKickBlocked.Value)
		{
			list.Add("PoseSetKick");
		}
		if (!Preferences.PrefStompBlocked.Value)
		{
			list.Add("PoseSetStomp");
		}
		if (!Preferences.PrefWallBlocked.Value)
		{
			list.Add("PoseSetWall_Grounded");
		}
		if (!Preferences.PrefJumpBlocked.Value)
		{
			list.Add("PoseSetRockjump");
		}
		if (!Preferences.PrefUppercutBlocked.Value)
		{
			list.Add("PoseSetUppercut");
		}
		if (!Preferences.PrefCubeBlocked.Value)
		{
			list.Add("PoseSetSpawnCube");
		}
		if (!Preferences.PrefDashBlocked.Value)
		{
			list.Add("PoseSetDash");
		}
		if (!Preferences.PrefParryBlocked.Value)
		{
			list.Add("PoseSetParry");
		}
		if (!Preferences.PrefHoldLeftBlocked.Value)
		{
			list.Add("PoseSetHoldLeft");
		}
		if (!Preferences.PrefHoldRightBlocked.Value)
		{
			list.Add("PoseSetHoldRight");
		}
		if (!Preferences.PrefExplodeBlocked.Value)
		{
			list.Add("PoseSetExplode");
		}
		if (!Preferences.PrefFlickBlocked.Value)
		{
			list.Add("PoseSetFlick");
		}
		List<PoseInputSource> currentInputPoses = __instance.currentInputPoses;
		string text = "";
		for (int i = 0; i < currentInputPoses.Count; i++)
		{
			if (!list.Contains(((Object)currentInputPoses[i].poseSet).name))
			{
				text = text + ((text != "") ? ", " : "") + ((Object)currentInputPoses[i].poseSet).name;
				storedMoves.Add(currentInputPoses[i]);
				currentInputPoses.RemoveAt(i);
				i--;
				break;
			}
		}
		if (text != "")
		{
			Melon<Main>.Logger.Msg("Poses Removed: " + text);
		}
		text = "";
		for (int j = 0; j < storedMoves.Count; j++)
		{
			if (list.Contains(((Object)storedMoves[j].poseSet).name))
			{
				text = text + ((text != "") ? ", " : "") + ((Object)storedMoves[j].poseSet).name;
				currentInputPoses.Add(storedMoves[j]);
				storedMoves.RemoveAt(j);
				j--;
				break;
			}
		}
		if (text != "")
		{
			Melon<Main>.Logger.Msg("Poses Added: " + text);
		}
	}
}
public class Preferences
{
	private const string CONFIG_FILE = "config.cfg";

	private const string USER_DATA = "UserData/MoveRestrictor/";

	internal static Dictionary<MelonPreferences_Entry, object> LastSavedValues = new Dictionary<MelonPreferences_Entry, object>();

	internal static MelonPreferences_Category SettingsCategory;

	internal static MelonPreferences_Entry<bool> PrefEnabled;

	internal static MelonPreferences_Category StructuresCategory;

	internal static MelonPreferences_Entry<bool> PrefDiscBlocked;

	internal static MelonPreferences_Entry<bool> PrefPillarBlocked;

	internal static MelonPreferences_Entry<bool> PrefBallBlocked;

	internal static MelonPreferences_Entry<bool> PrefWallBlocked;

	internal static MelonPreferences_Entry<bool> PrefCubeBlocked;

	internal static MelonPreferences_Category ModifiersCategory;

	internal static MelonPreferences_Entry<bool> PrefStraightBlocked;

	internal static MelonPreferences_Entry<bool> PrefKickBlocked;

	internal static MelonPreferences_Entry<bool> PrefStompBlocked;

	internal static MelonPreferences_Entry<bool> PrefUppercutBlocked;

	internal static MelonPreferences_Entry<bool> PrefParryBlocked;

	internal static MelonPreferences_Entry<bool> PrefHoldLeftBlocked;

	internal static MelonPreferences_Entry<bool> PrefHoldRightBlocked;

	internal static MelonPreferences_Entry<bool> PrefExplodeBlocked;

	internal static MelonPreferences_Entry<bool> PrefFlickBlocked;

	internal static MelonPreferences_Category MovementCategory;

	internal static MelonPreferences_Entry<bool> PrefSprintBlocked;

	internal static MelonPreferences_Entry<bool> PrefJumpBlocked;

	internal static MelonPreferences_Entry<bool> PrefDashBlocked;

	internal static void InitPrefs()
	{
		if (!Directory.Exists("UserData/MoveRestrictor/"))
		{
			Directory.CreateDirectory("UserData/MoveRestrictor/");
		}
		SettingsCategory = MelonPreferences.CreateCategory("MoveRestrictor", "Settings");
		SettingsCategory.SetFilePath(Path.Combine("UserData/MoveRestrictor/", "config.cfg"));
		PrefEnabled = SettingsCategory.CreateEntry<bool>("Enabled", true, "Enabled", "Toggles the Mod On/Off", false, false, (ValueValidator)null, (string)null);
		StructuresCategory = MelonPreferences.CreateCategory("Structures", "Structures");
		StructuresCategory.SetFilePath(Path.Combine("UserData/MoveRestrictor/", "config.cfg"));
		PrefDiscBlocked = StructuresCategory.CreateEntry<bool>("DiscBlocked", false, "Disc Blocked", "Turns Off Disc", false, false, (ValueValidator)null, (string)null);
		PrefPillarBlocked = StructuresCategory.CreateEntry<bool>("PillarBlocked", false, "Pillar Blocked", "Turns Off Pillar", false, false, (ValueValidator)null, (string)null);
		PrefBallBlocked = StructuresCategory.CreateEntry<bool>("BallBlocked", false, "Ball Blocked", "Turns Off Ball", false, false, (ValueValidator)null, (string)null);
		PrefWallBlocked = StructuresCategory.CreateEntry<bool>("WallBlocked", false, "Wall Blocked", "Turns Off Wall", false, false, (ValueValidator)null, (string)null);
		PrefCubeBlocked = StructuresCategory.CreateEntry<bool>("CubeBlocked", false, "Cube Blocked", "Turns Off Cube", false, false, (ValueValidator)null, (string)null);
		ModifiersCategory = MelonPreferences.CreateCategory("Modifiers", "Modifiers");
		ModifiersCategory.SetFilePath(Path.Combine("UserData/MoveRestrictor/", "config.cfg"));
		PrefStraightBlocked = ModifiersCategory.CreateEntry<bool>("StraightBlocked", false, "Straight Blocked", "Turns Off Straight", false, false, (ValueValidator)null, (string)null);
		PrefKickBlocked = ModifiersCategory.CreateEntry<bool>("KickBlocked", false, "Kick Blocked", "Turns Off Kick", false, false, (ValueValidator)null, (string)null);
		PrefStompBlocked = ModifiersCategory.CreateEntry<bool>("StompBlocked", false, "Stomp Blocked", "Turns Off Stomp", false, false, (ValueValidator)null, (string)null);
		PrefUppercutBlocked = ModifiersCategory.CreateEntry<bool>("UppercutBlocked", false, "Uppercut Blocked", "Turns Off Uppercut", false, false, (ValueValidator)null, (string)null);
		PrefParryBlocked = ModifiersCategory.CreateEntry<bool>("ParryBlocked", false, "Parry Blocked", "Turns Off Parry", false, false, (ValueValidator)null, (string)null);
		PrefHoldLeftBlocked = ModifiersCategory.CreateEntry<bool>("HoldLeftBlocked", false, "Hold Left Blocked", "Turns Off Left Hand Hold", false, false, (ValueValidator)null, (string)null);
		PrefHoldRightBlocked = ModifiersCategory.CreateEntry<bool>("HoldRightBlocked", false, "Hold Right Blocked", "Turns Off Right Hand Hold", false, false, (ValueValidator)null, (string)null);
		PrefExplodeBlocked = ModifiersCategory.CreateEntry<bool>("ExplodeBlocked", false, "Explode Blocked", "Turns Off Explode", false, false, (ValueValidator)null, (string)null);
		PrefFlickBlocked = ModifiersCategory.CreateEntry<bool>("FlickBlocked", false, "Flick Blocked", "Turns Off Flick", false, false, (ValueValidator)null, (string)null);
		MovementCategory = MelonPreferences.CreateCategory("Movement", "Movement");
		MovementCategory.SetFilePath(Path.Combine("UserData/MoveRestrictor/", "config.cfg"));
		PrefSprintBlocked = MovementCategory.CreateEntry<bool>("SprintBlocked", false, "Sprint Blocked", "Turns Off Sprint", false, false, (ValueValidator)null, (string)null);
		PrefJumpBlocked = MovementCategory.CreateEntry<bool>("JumpBlocked", false, "Jump Blocked", "Turns Off Jump", false, false, (ValueValidator)null, (string)null);
		PrefDashBlocked = MovementCategory.CreateEntry<bool>("DashBlocked", false, "Dash Blocked", "Turns Off Dash", false, false, (ValueValidator)null, (string)null);
		StoreLastSavedPrefs();
	}

	internal static void StoreLastSavedPrefs()
	{
		List<MelonPreferences_Entry> list = new List<MelonPreferences_Entry>();
		list.AddRange(SettingsCategory.Entries);
		list.AddRange(StructuresCategory.Entries);
		list.AddRange(ModifiersCategory.Entries);
		list.AddRange(MovementCategory.Entries);
		foreach (MelonPreferences_Entry item in list)
		{
			LastSavedValues[item] = item.BoxedValue;
		}
	}

	public static bool AnyPrefsChanged()
	{
		foreach (KeyValuePair<MelonPreferences_Entry, object> lastSavedValue in LastSavedValues)
		{
			if (!lastSavedValue.Key.BoxedValue.Equals(lastSavedValue.Value))
			{
				return true;
			}
		}
		return false;
	}
}