Decompiled source of RumbleModUIPlus v1.0.2

Mods/RumbleModUIPlus.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using MelonLoader;
using RumbleModUI;
using RumbleModUIPlus;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(RumbleModUIPlusClass), "RumbleModUIPlus", "1.0.2", "ninjaguardian", "https://thunderstore.io/c/rumble/p/ninjaguardian/RumbleModUIPlus")]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 0, 160, 230)]
[assembly: MelonAuthorColor(255, 0, 160, 230)]
[assembly: MelonPlatformDomain(/*Could not decode attribute arguments.*/)]
[assembly: VerifyLoaderVersion("0.7.0", true)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("ninjaguardian (github)")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2025 ninjaguardian (github), This work is dedicated to the public domain under CC0 1.0.")]
[assembly: AssemblyDescription("Adds stuff for devs to RumbleModUI")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("RumbleModUIPlus")]
[assembly: AssemblyTitle("RumbleModUIPlus")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ninjaguardian/RumbleModUIPlus")]
[assembly: AssemblyVersion("1.0.2.0")]
namespace RumbleModUIPlus;

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

	public const string ModVersion = "1.0.2";

	public const string MLVersion = "0.7.0";
}
public class Mod : Mod
{
	protected const string DuplicateErrorMsg = "AddToList failed: Name not unique";

	private string _modFormatVersion;

	private static readonly string RumbleModTypeFullName = typeof(Mod).FullName;

	private static readonly string[] SpecialNames = new string[2] { "SaveModData", "GetFromFile" };

	public string ModFormatVersion
	{
		get
		{
			return _modFormatVersion ?? ((Mod)this).ModVersion;
		}
		set
		{
			_modFormatVersion = value;
		}
	}

	internal static bool WasCalledFromSpecial()
	{
		StackFrame[] frames = new StackTrace(1).GetFrames();
		if (frames == null || frames.Length == 0)
		{
			return false;
		}
		for (int i = 0; i < Math.Min(frames.Length, 20); i++)
		{
			if (IsMethodMatchingAny(frames[i]?.GetMethod(), SpecialNames))
			{
				return true;
			}
		}
		return false;
	}

	internal static bool IsMethodMatchingAny(MethodBase method, string[] targetNames)
	{
		if (method == null)
		{
			return false;
		}
		Type type = method.DeclaringType ?? method.ReflectedType;
		if (type != null && type.FullName == RumbleModTypeFullName)
		{
			string name = method.Name;
			for (int i = 0; i < targetNames.Length; i++)
			{
				if (name == targetNames[i])
				{
					return true;
				}
			}
		}
		string text = method.Name ?? string.Empty;
		for (int j = 0; j < targetNames.Length; j++)
		{
			if (text == $"DMD<{RumbleModTypeFullName}::{targetNames[j]}>")
			{
				return true;
			}
		}
		return false;
	}

	public ModSetting<string> AddDescriptionAtStart(string Name, string Value, string Description, Tags tags)
	{
		return AddDescriptionAtIndex(Name, Value, Description, tags, 0);
	}

	public ModSetting<string> AddDescriptionAtIndex(string Name, string Value, string Description, Tags tags, int Index)
	{
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		if (base.Settings.Count > 0 && base.Settings.Exists((ModSetting x) => x.Name == Name))
		{
			MelonLogger.Msg("AddToList failed: Name not unique: " + Name);
			return null;
		}
		ModSetting<string> obj = new ModSetting<string>
		{
			Name = Name,
			Description = Description
		};
		((ModSetting)obj).Value = Value;
		((ModSetting)obj).SavedValue = Value;
		((ModSetting)obj).LinkGroup = 0;
		((ModSetting)obj).ValueType = (AvailableTypes)0;
		ModSetting<string> val = obj;
		tags.DoNotSave = true;
		((Mod)this).AddTags((ModSetting)(object)val, tags);
		if (Index < 0 || Index > base.Settings.Count)
		{
			MelonLogger.Error($"Index {Index} is out of bounds for list with size {base.Settings.Count}. Falling back to Settings.Add");
			base.Settings.Add((ModSetting)(object)val);
		}
		else
		{
			base.Settings.Insert(Index, (ModSetting)(object)val);
		}
		return val;
	}

	public ModSetting<string> AddToListAtStart(string Name, string Value, string Description, Tags tags)
	{
		return AddToListAtIndex(Name, Value, Description, tags, 0);
	}

	public ModSetting<string> AddToListAtIndex(string Name, string Value, string Description, Tags tags, int Index)
	{
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		if (base.Settings.Count > 0 && base.Settings.Exists((ModSetting x) => x.Name == Name))
		{
			MelonLogger.Msg("AddToList failed: Name not unique: " + Name);
			return null;
		}
		ModSetting<string> obj = new ModSetting<string>
		{
			Name = Name,
			Description = Description
		};
		((ModSetting)obj).Value = Value;
		((ModSetting)obj).SavedValue = Value;
		((ModSetting)obj).LinkGroup = 0;
		((ModSetting)obj).ValueType = (AvailableTypes)1;
		ModSetting<string> val = obj;
		((Mod)this).AddTags((ModSetting)(object)val, tags);
		if (Index < 0 || Index > base.Settings.Count)
		{
			MelonLogger.Error($"Index {Index} is out of bounds for list with size {base.Settings.Count}. Falling back to Settings.Add");
			base.Settings.Add((ModSetting)(object)val);
		}
		else
		{
			base.Settings.Insert(Index, (ModSetting)(object)val);
		}
		return val;
	}

	public ModSetting<bool> AddToListAtStart(string Name, bool Value, int LinkGroup, string Description, Tags tags)
	{
		return AddToListAtIndex(Name, Value, LinkGroup, Description, tags, 0);
	}

	public ModSetting<bool> AddToListAtIndex(string Name, bool Value, int LinkGroup, string Description, Tags tags, int Index)
	{
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		if (base.Settings.Count > 0 && base.Settings.Exists((ModSetting x) => x.Name == Name))
		{
			MelonLogger.Msg("AddToList failed: Name not unique: " + Name);
			return null;
		}
		ModSetting<bool> obj = new ModSetting<bool>
		{
			Name = Name,
			Description = Description
		};
		((ModSetting)obj).Value = Value;
		((ModSetting)obj).SavedValue = Value;
		((ModSetting)obj).LinkGroup = LinkGroup;
		((ModSetting)obj).ValueType = (AvailableTypes)5;
		ModSetting<bool> val = obj;
		if (LinkGroup != 0)
		{
			((Mod)this).SetLinkGroup(LinkGroup, "Group");
			base.LinkGroups.Find((LinkGroup x) => x.Index == LinkGroup).Settings.Add((ModSetting)(object)val);
		}
		((Mod)this).AddTags((ModSetting)(object)val, tags);
		if (Index < 0 || Index > base.Settings.Count)
		{
			MelonLogger.Error($"Index {Index} is out of bounds for list with size {base.Settings.Count}. Falling back to Settings.Add");
			base.Settings.Add((ModSetting)(object)val);
		}
		else
		{
			base.Settings.Insert(Index, (ModSetting)(object)val);
		}
		return val;
	}

	public ModSetting<int> AddToListAtStart(string Name, int Value, string Description, Tags tags)
	{
		return AddToListAtIndex(Name, Value, Description, tags, 0);
	}

	public ModSetting<int> AddToListAtIndex(string Name, int Value, string Description, Tags tags, int Index)
	{
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		if (base.Settings.Count > 0 && base.Settings.Exists((ModSetting x) => x.Name == Name))
		{
			MelonLogger.Msg("AddToList failed: Name not unique: " + Name);
			return null;
		}
		ModSetting<int> obj = new ModSetting<int>
		{
			Name = Name,
			Description = Description
		};
		((ModSetting)obj).Value = Value;
		((ModSetting)obj).SavedValue = Value;
		((ModSetting)obj).LinkGroup = 0;
		((ModSetting)obj).ValueType = (AvailableTypes)2;
		ModSetting<int> val = obj;
		((Mod)this).AddTags((ModSetting)(object)val, tags);
		if (Index < 0 || Index > base.Settings.Count)
		{
			MelonLogger.Error($"Index {Index} is out of bounds for list with size {base.Settings.Count}. Falling back to Settings.Add");
			base.Settings.Add((ModSetting)(object)val);
		}
		else
		{
			base.Settings.Insert(Index, (ModSetting)(object)val);
		}
		return val;
	}

	public ModSetting<float> AddToListAtStart(string Name, float Value, string Description, Tags tags)
	{
		return AddToListAtIndex(Name, Value, Description, tags, 0);
	}

	public ModSetting<float> AddToListAtIndex(string Name, float Value, string Description, Tags tags, int Index)
	{
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		if (base.Settings.Count > 0 && base.Settings.Exists((ModSetting x) => x.Name == Name))
		{
			MelonLogger.Msg("AddToList failed: Name not unique: " + Name);
			return null;
		}
		ModSetting<float> obj = new ModSetting<float>
		{
			Name = Name,
			Description = Description
		};
		((ModSetting)obj).Value = Value;
		((ModSetting)obj).SavedValue = Value;
		((ModSetting)obj).LinkGroup = 0;
		((ModSetting)obj).ValueType = (AvailableTypes)3;
		ModSetting<float> val = obj;
		((Mod)this).AddTags((ModSetting)(object)val, tags);
		if (Index < 0 || Index > base.Settings.Count)
		{
			MelonLogger.Error($"Index {Index} is out of bounds for list with size {base.Settings.Count}. Falling back to Settings.Add");
			base.Settings.Add((ModSetting)(object)val);
		}
		else
		{
			base.Settings.Insert(Index, (ModSetting)(object)val);
		}
		return val;
	}

	public ModSetting<double> AddToListAtStart(string Name, double Value, string Description, Tags tags)
	{
		return AddToListAtIndex(Name, Value, Description, tags, 0);
	}

	public ModSetting<double> AddToListAtIndex(string Name, double Value, string Description, Tags tags, int Index)
	{
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		if (base.Settings.Count > 0 && base.Settings.Exists((ModSetting x) => x.Name == Name))
		{
			MelonLogger.Msg("AddToList failed: Name not unique: " + Name);
			return null;
		}
		ModSetting<double> obj = new ModSetting<double>
		{
			Name = Name,
			Description = Description
		};
		((ModSetting)obj).Value = Value;
		((ModSetting)obj).SavedValue = Value;
		((ModSetting)obj).LinkGroup = 0;
		((ModSetting)obj).ValueType = (AvailableTypes)4;
		ModSetting<double> val = obj;
		((Mod)this).AddTags((ModSetting)(object)val, tags);
		if (Index < 0 || Index > base.Settings.Count)
		{
			MelonLogger.Error($"Index {Index} is out of bounds for list with size {base.Settings.Count}. Falling back to Settings.Add");
			base.Settings.Add((ModSetting)(object)val);
		}
		else
		{
			base.Settings.Insert(Index, (ModSetting)(object)val);
		}
		return val;
	}
}
public class RumbleModUIPlusClass : MelonMod
{
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	private static class ModVersion_Getter_Patch
	{
		private static bool Prefix(Mod __instance, ref string __result)
		{
			if (__instance is Mod mod && Mod.WasCalledFromSpecial())
			{
				__result = mod.ModFormatVersion;
				return false;
			}
			return true;
		}
	}
}