Decompiled source of Color Screen v2.5.0

Mods/ColorScreen.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using ColorScreen;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Utilities;
using MelonLoader;
using MelonLoader.Preferences;
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), "Color Screen", "2.5.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("ColorScreen")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2d98cc8da9a66714ed3f43a9a7fa314a205320d0")]
[assembly: AssemblyProduct("ColorScreen")]
[assembly: AssemblyTitle("ColorScreen")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ColorScreen;

public static class BuildInfo
{
	public const string ModName = "Color Screen";

	public const string ModVersion = "2.5.0";

	public const string Author = "UlvakSkillz";
}
public class Main : MelonMod
{
	private string currentScene = "Loader";

	private bool gKeyReleased = true;

	private bool gScreenActive = false;

	private bool fKeyReleased = true;

	private bool fPlainActive = false;

	private static string wallColorText = "FF44EC";

	private static string floorColorText = "FF44EC";

	private Color wallColor = hexToColor(wallColorText);

	private Color floorColor = hexToColor(floorColorText);

	private Shader unlit;

	public override void OnInitializeMelon()
	{
		unlit = Shader.Find("Universal Render Pipeline/Unlit");
		Preferences.InitPrefs();
		((ModelModItem)UI.Register((MelonBase)(object)this, (MelonPreferences_Category[])(object)new MelonPreferences_Category[2]
		{
			Preferences.SettingsCategory,
			Preferences.SettingsCategory
		})).OnModSaved += Save;
	}

	private void Save()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		wallColor = hexToColor(Preferences.PrefWallColor.Value);
		floorColor = hexToColor(Preferences.PrefFloorColor.Value);
	}

	public static Color hexToColor(string hex)
	{
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		hex = hex.Replace("0x", "").Replace("#", "");
		if (hex.Length == 3)
		{
			hex = hex.Substring(0, 1) + hex.Substring(0, 1) + hex.Substring(1, 1) + hex.Substring(1, 1) + hex.Substring(2, 1) + hex.Substring(2, 1);
		}
		else if (hex.Length == 4)
		{
			hex = hex.Substring(0, 1) + hex.Substring(0, 1) + hex.Substring(1, 1) + hex.Substring(1, 1) + hex.Substring(2, 1) + hex.Substring(2, 1) + hex.Substring(3, 1) + hex.Substring(3, 1);
		}
		byte b = byte.MaxValue;
		byte b2 = byte.Parse(hex.Substring(0, 2), NumberStyles.HexNumber);
		byte b3 = byte.Parse(hex.Substring(2, 2), NumberStyles.HexNumber);
		byte b4 = byte.Parse(hex.Substring(4, 2), NumberStyles.HexNumber);
		return Color32.op_Implicit(new Color32(b2, b3, b4, b));
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		currentScene = sceneName;
	}

	public override void OnUpdate()
	{
		if (currentScene == "Loader" || !Preferences.PrefKeyboardInputAllowed.Value)
		{
			return;
		}
		if (Input.GetKeyDown((KeyCode)103) && gKeyReleased)
		{
			gKeyReleased = false;
			if (gScreenActive)
			{
				Object.Destroy((Object)(object)GameObject.Find("ColorScreen"));
				gScreenActive = false;
			}
			else
			{
				CreateWall();
				gScreenActive = true;
			}
		}
		if (Input.GetKeyUp((KeyCode)103) && !gKeyReleased)
		{
			gKeyReleased = true;
		}
		if (Input.GetKeyDown((KeyCode)102) && fKeyReleased)
		{
			fKeyReleased = false;
			if (fPlainActive)
			{
				Object.Destroy((Object)(object)GameObject.Find("ColorPlain"));
				fPlainActive = false;
			}
			else
			{
				CreatePlane();
				fPlainActive = true;
			}
		}
		if (Input.GetKeyUp((KeyCode)102) && !fKeyReleased)
		{
			fKeyReleased = true;
		}
	}

	private void CreateWall()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: 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_0102: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)val).name = "ColorScreen";
			Renderer component = val.GetComponent<Renderer>();
			((Object)component.material).name = "CubeMat";
			component.material.shader = unlit;
			component.material.color = wallColor;
			PlayerManager instance = Singleton<PlayerManager>.instance;
			Transform transform = val.transform;
			Quaternion rotation = ((Component)((Component)instance.localPlayer.Controller).gameObject.transform.GetChild(2).GetChild(0).GetChild(0)).transform.rotation;
			transform.rotation = Quaternion.Euler(0f, ((Quaternion)(ref rotation)).eulerAngles.y, 0f);
			val.transform.position = ((Component)((Component)instance.localPlayer.Controller).gameObject.transform.GetChild(2).GetChild(0).GetChild(0)).transform.position;
			val.transform.localScale = new Vector3(0.01f, 1000f, 1000f);
			val.SetActive(true);
		}
		catch (Exception ex)
		{
			MelonLogger.Error((object)ex);
		}
	}

	private void CreatePlane()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: 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_00c3: 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)
		try
		{
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)val).name = "ColorPlain";
			Renderer component = val.GetComponent<Renderer>();
			((Object)component.material).name = "CubeMat";
			component.material.shader = unlit;
			component.material.color = floorColor;
			val.transform.position = ((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).gameObject.transform.GetChild(2).GetChild(3).position;
			val.transform.position = new Vector3(val.transform.position.x, val.transform.position.y - 0.102f, val.transform.position.z);
			val.transform.localScale = new Vector3(1000f, 0.01f, 1000f);
			val.SetActive(true);
		}
		catch (Exception ex)
		{
			MelonLogger.Error((object)ex);
		}
	}

	public static void Log(string msg)
	{
		MelonLogger.Msg(msg);
	}
}
public abstract class ValueValidator<T>
{
	public abstract bool IsValid(object value);

	public abstract object EnsureValid(object value);
}
public class HexColorValidator : ValueValidator
{
	private static readonly Regex hexRegex = new Regex("^[0-9a-fA-F]+$", RegexOptions.Compiled);

	private static readonly HashSet<int> validLengths = new HashSet<int> { 3, 4, 6, 8 };

	public override bool IsValid(object value)
	{
		return value is string input && IsValidHex(input);
	}

	public override object EnsureValid(object value)
	{
		if (!(value is string input) || !IsValidHex(input))
		{
			return "#C0B154";
		}
		return NormalizeToStandard(input);
	}

	private static string NormalizeToStandard(string input)
	{
		string text = Normalize(input);
		if (text.Length == 3 || text.Length == 4)
		{
			text = string.Concat(text.Select((char c) => $"{c}{c}"));
		}
		return "#" + text.ToUpper();
	}

	private static bool IsValidHex(string input)
	{
		string text = Normalize(input);
		if (string.IsNullOrEmpty(text) || !validLengths.Contains(text.Length))
		{
			return false;
		}
		return hexRegex.IsMatch(text);
	}

	private static string Normalize(string input)
	{
		if (string.IsNullOrEmpty(input))
		{
			return null;
		}
		input = input.Trim();
		if (input.StartsWith("#"))
		{
			input = input.Substring(1);
		}
		else if (input.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
		{
			input = input.Substring(2);
		}
		return input;
	}
}
public class Preferences
{
	private const string CONFIG_FILE = "config.cfg";

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

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

	internal static MelonPreferences_Category SettingsCategory;

	internal static MelonPreferences_Entry<string> PrefWallColor;

	internal static MelonPreferences_Entry<string> PrefFloorColor;

	internal static MelonPreferences_Entry<bool> PrefKeyboardInputAllowed;

	internal static void InitPrefs()
	{
		if (!Directory.Exists("UserData/ColorScreen/"))
		{
			Directory.CreateDirectory("UserData/ColorScreen/");
		}
		SettingsCategory = MelonPreferences.CreateCategory("ColorScreen", "Settings");
		SettingsCategory.SetFilePath(Path.Combine("UserData/ColorScreen/", "config.cfg"));
		PrefWallColor = SettingsCategory.CreateEntry<string>("WallColor", "FF44EC", "Wall Color", "Sets The Wall Color to the Supplied Color", false, false, (ValueValidator)(object)new HexColorValidator(), (string)null);
		PrefFloorColor = SettingsCategory.CreateEntry<string>("FloorColor", "FF44EC", "Floor Color", "Sets The Floor Color to the Supplied Color", false, false, (ValueValidator)(object)new HexColorValidator(), (string)null);
		PrefKeyboardInputAllowed = SettingsCategory.CreateEntry<bool>("KeyboardInputAllowed", true, "Keyboard Input Allowed", "Allows Keyboard Input for Summoning the Floor / Wall", false, false, (ValueValidator)null, (string)null);
		StoreLastSavedPrefs();
	}

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