Decompiled source of BBVisualInput v1.0.1

Mods/BBVisualInput.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BBModMenu;
using BBVisualInput;
using HarmonyLib;
using MelonLoader;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UIElements;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BBVisualInput")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BBVisualInput")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: MelonInfo(typeof(global::BBVisualInput.BBVisualInput), "Beton Brutal VisualInput", "1.0.0", "MiaouZart", null)]
[assembly: MelonGame("", "Beton Brutal")]
[assembly: MelonAdditionalDependencies(new string[] { "BBModMenu" })]
[assembly: Guid("7ed05d51-b09c-4f5b-966d-9172b4824fdb")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BBVisualInput;

public class BBVisualInput : MelonMod
{
	[HarmonyPatch(typeof(GameUI), "Awake")]
	private static class PatchGameUILightAwake
	{
		[HarmonyPrefix]
		private static void HarmonyPatchPrefixGameUi(GameUI __instance)
		{
			((Component)__instance).gameObject.AddComponent<BBInputVisualComponent>();
		}
	}
}
internal class BBInputVisualComponent : MonoBehaviour
{
	private VisualElement visualInputRoot;

	private Dictionary<string, VisualElement> keyElements = new Dictionary<string, VisualElement>();

	private bool _enable = true;

	private static Color textColor = new Color(0.945f, 0.894f, 0.78f, 1f);

	private float baseKeySize = 70f;

	private float baseFontSize = 30f;

	private float baseMarginBottom = 10f;

	private GameUI gameUI;

	private VisualElement HuDCustomMapVisualElement;

	private VisualElement HuDVisualElement;

	private ModMenu _modMenu;

	private InputAction inputAction;

	public void Start()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		Debug.Log((object)"InputVisual Loaded Plugin Start");
		visualInputRoot = new VisualElement();
		visualInputRoot.style.position = StyleEnum<Position>.op_Implicit((Position)1);
		visualInputRoot.style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit((TextAnchor)4);
		visualInputRoot.name = "InputVisualRoot";
		visualInputRoot.transform.position = new Vector3(0f, 0f, 0f);
		inputAction = PlayerInput.InputMap.FindAction(GameObject.Find("Input").GetComponent<PlayerInput>().moveAction.action.name, false);
		VisualElement val = CreateKeyRow(("Z", 0));
		VisualElement val2 = CreateKeyRow(("Q", 2), ("S", 1), ("D", 3));
		VisualElement val3 = CreateKeyRow(("Sprint", -1), ("Jump", -1), ("Sneak", -1));
		visualInputRoot.Add(val);
		visualInputRoot.Add(val2);
		visualInputRoot.Add(val3);
		gameUI = GameObject.Find("GameUI").GetComponent<GameUI>();
		List<UIScreen> list = typeof(GameUI).GetField("screens", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(gameUI) as List<UIScreen>;
		if (list != null)
		{
			UIScreen? obj = ((IEnumerable<UIScreen>)list).FirstOrDefault((Func<UIScreen, bool>)((UIScreen screen) => screen is HUDScreen));
			HUDScreen obj2 = (HUDScreen)(object)((obj is HUDScreen) ? obj : null);
			FieldInfo field = typeof(UIScreen).GetField("<Screen>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic);
			UIScreen? obj3 = ((IEnumerable<UIScreen>)list).FirstOrDefault((Func<UIScreen, bool>)((UIScreen screen) => screen is CustomMapHUDScreen));
			CustomMapHUDScreen obj4 = (CustomMapHUDScreen)(object)((obj3 is CustomMapHUDScreen) ? obj3 : null);
			if (field != null)
			{
				object? value = field.GetValue(obj2);
				VisualElement huDVisualElement = (VisualElement)((value is VisualElement) ? value : null);
				HuDVisualElement = huDVisualElement;
				VisualElement huDVisualElement2 = HuDVisualElement;
				if (huDVisualElement2 != null)
				{
					huDVisualElement2.Add(visualInputRoot);
				}
				object? value2 = field.GetValue(obj4);
				VisualElement huDCustomMapVisualElement = (VisualElement)((value2 is VisualElement) ? value2 : null);
				HuDCustomMapVisualElement = huDCustomMapVisualElement;
			}
		}
		ref ModMenu modMenu = ref _modMenu;
		UIScreen? obj5 = list?.FirstOrDefault((Func<UIScreen, bool>)((UIScreen screen) => screen is ModMenu));
		modMenu = (ModMenu)(object)((obj5 is ModMenu) ? obj5 : null);
		if (_modMenu == null)
		{
			Debug.Log((object)"ModMenu not found");
			return;
		}
		string text = "InputVisual";
		VisualElement val4 = _modMenu.AddSetting(text);
		Slider xSlider = _modMenu.CreateSlider(text, "XPositon", 0f, 100f, 2f, true);
		Slider ySlider = _modMenu.CreateSlider(text, "YPosition", 0f, 100f, 74f, true);
		Slider scaleSlider = _modMenu.CreateSlider(text, "Scale", 0.1f, 3f, 0.7f, false);
		Action updatePosition = delegate
		{
			//IL_001c: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			visualInputRoot.style.top = StyleLength.op_Implicit(Length.Percent(((BaseField<float>)(object)ySlider).value));
			visualInputRoot.style.left = StyleLength.op_Implicit(Length.Percent(((BaseField<float>)(object)xSlider).value));
			DisplayInSetting();
		};
		Action updateScale = delegate
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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)
			float value3 = ((BaseField<float>)(object)scaleSlider).value;
			foreach (VisualElement item in visualInputRoot.Children())
			{
				foreach (VisualElement item2 in item.Children())
				{
					item2.style.width = StyleLength.op_Implicit(baseKeySize * value3);
					item2.style.height = StyleLength.op_Implicit(baseKeySize * value3);
					if (item2.childCount > 0)
					{
						VisualElement obj6 = item2[0];
						Label val12 = (Label)(object)((obj6 is Label) ? obj6 : null);
						if (val12 != null)
						{
							((VisualElement)val12).style.fontSize = StyleLength.op_Implicit(baseFontSize * value3);
						}
					}
				}
				item.style.marginBottom = StyleLength.op_Implicit(baseMarginBottom * value3);
			}
		};
		INotifyValueChangedExtensions.RegisterValueChangedCallback<float>((INotifyValueChanged<float>)(object)xSlider, (EventCallback<ChangeEvent<float>>)delegate
		{
			updatePosition();
		});
		INotifyValueChangedExtensions.RegisterValueChangedCallback<float>((INotifyValueChanged<float>)(object)ySlider, (EventCallback<ChangeEvent<float>>)delegate
		{
			updatePosition();
		});
		INotifyValueChangedExtensions.RegisterValueChangedCallback<float>((INotifyValueChanged<float>)(object)scaleSlider, (EventCallback<ChangeEvent<float>>)delegate
		{
			updateScale();
		});
		VisualElement val5 = _modMenu.CreateGroup("Position");
		VisualElement val6 = _modMenu.CreateWrapper();
		val6.Add((VisualElement)(object)_modMenu.CreateLabel("X position"));
		val6.Add((VisualElement)(object)xSlider);
		VisualElement val7 = _modMenu.CreateWrapper();
		val7.Add((VisualElement)(object)_modMenu.CreateLabel("Y position"));
		val7.Add((VisualElement)(object)ySlider);
		VisualElement val8 = _modMenu.CreateWrapper();
		val8.Add((VisualElement)(object)_modMenu.CreateLabel("Scale"));
		val8.Add((VisualElement)(object)scaleSlider);
		VisualElement val9 = _modMenu.CreateGroup("Control");
		VisualElement val10 = _modMenu.CreateWrapper();
		val10.Add((VisualElement)(object)_modMenu.CreateLabel("Enable"));
		Toggle val11 = _modMenu.CreateToggle(text, "On", ((Behaviour)this).enabled);
		INotifyValueChangedExtensions.RegisterValueChangedCallback<bool>((INotifyValueChanged<bool>)(object)val11, (EventCallback<ChangeEvent<bool>>)delegate(ChangeEvent<bool> b)
		{
			((Behaviour)this).enabled = b.newValue;
			visualInputRoot.visible = ((Behaviour)this).enabled;
		});
		val10.Add((VisualElement)(object)val11);
		val5.Add(val6);
		val5.Add(val7);
		val5.Add(val8);
		val9.Add(val10);
		val4.Add(val5);
		val4.Add(val9);
		((Behaviour)this).enabled = ((BaseField<bool>)(object)val11).value;
		visualInputRoot.visible = ((Behaviour)this).enabled;
		updatePosition();
		updateScale();
	}

	private VisualElement CreateKeyRow(params (string keyText, int input)[] keys)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		VisualElement val = new VisualElement();
		val.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)2);
		val.style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)1);
		val.style.marginBottom = StyleLength.op_Implicit(baseMarginBottom);
		for (int i = 0; i < keys.Length; i++)
		{
			(string keyText, int input) tuple = keys[i];
			string item = tuple.keyText;
			int item2 = tuple.input;
			VisualElement val2 = ((item2 == -1) ? CreateKeyElement(item) : CreateKeyElement(inputAction.controls[item2].displayName));
			keyElements[item] = val2;
			val.Add(val2);
		}
		return val;
	}

	private VisualElement CreateKeyElement(string keyText)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Expected O, but got Unknown
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		VisualElement val = new VisualElement();
		val.style.height = StyleLength.op_Implicit(baseKeySize);
		val.style.marginLeft = StyleLength.op_Implicit(3f);
		val.style.marginRight = StyleLength.op_Implicit(3f);
		val.style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)1);
		val.style.alignItems = StyleEnum<Align>.op_Implicit((Align)2);
		val.style.backgroundColor = StyleColor.op_Implicit(ModMenu._BBBackGround);
		val.style.flexShrink = StyleFloat.op_Implicit(0f);
		val.style.borderTopLeftRadius = StyleLength.op_Implicit(5f);
		val.style.borderTopRightRadius = StyleLength.op_Implicit(5f);
		val.style.borderBottomLeftRadius = StyleLength.op_Implicit(5f);
		val.style.borderBottomRightRadius = StyleLength.op_Implicit(5f);
		Label val2 = new Label(keyText);
		((VisualElement)val2).style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit((TextAnchor)4);
		((VisualElement)val2).style.position = StyleEnum<Position>.op_Implicit((Position)0);
		((VisualElement)val2).style.fontSize = StyleLength.op_Implicit(baseFontSize);
		val.Add((VisualElement)(object)val2);
		return val;
	}

	private void Update()
	{
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: 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_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: 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_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: 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)
		if (((Behaviour)this).enabled)
		{
			if (gameUI.ActiveScreen.Name == "CustomMapHUD" && visualInputRoot.parent != HuDCustomMapVisualElement)
			{
				HuDCustomMapVisualElement.Add(visualInputRoot);
				visualInputRoot.style.backgroundColor = StyleColor.op_Implicit(new Color(0f, 0f, 0f, 0f));
			}
			if (gameUI.ActiveScreen.Name == "HUD" && visualInputRoot.parent != HuDVisualElement)
			{
				HuDVisualElement.Add(visualInputRoot);
				visualInputRoot.style.backgroundColor = StyleColor.op_Implicit(new Color(0f, 0f, 0f, 0f));
			}
			MainActions main = PlayerInput.InputMap.Main;
			Vector2 val = ((MainActions)(ref main)).Move.ReadValue<Vector2>();
			main = PlayerInput.InputMap.Main;
			bool isActive = ((MainActions)(ref main)).Sprint.IsPressed() || PlayerInput.SprintHeld;
			main = PlayerInput.InputMap.Main;
			bool isActive2 = ((MainActions)(ref main)).Sneak.IsPressed() || PlayerInput.SneakHeld;
			main = PlayerInput.InputMap.Main;
			bool isActive3 = ((MainActions)(ref main)).Jump.IsPressed() || PlayerInput.JumpHeld || GameModeManager.Instance.player.spaceDown;
			UpdateKeyElement("Z", val.y > 0.5f);
			UpdateKeyElement("S", val.y < -0.5f);
			UpdateKeyElement("Q", val.x < -0.5f);
			UpdateKeyElement("D", val.x > 0.5f);
			UpdateKeyElement("Sprint", isActive);
			UpdateKeyElement("Jump", isActive3);
			UpdateKeyElement("Sneak", isActive2);
		}
	}

	private void DisplayInSetting()
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		_modMenu.getRootVisualElement().Add(visualInputRoot);
		visualInputRoot.style.backgroundColor = StyleColor.op_Implicit(Color.white);
	}

	private void UpdateKeyElement(string key, bool isActive)
	{
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: 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_0037: 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_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		if (keyElements.TryGetValue(key, out var value))
		{
			if (isActive)
			{
				value.style.backgroundColor = StyleColor.op_Implicit(new Color(1f, 1f, 1f, 0.8f));
				value[0].style.color = StyleColor.op_Implicit(Color.black);
			}
			else
			{
				value.style.backgroundColor = StyleColor.op_Implicit(ModMenu._BBBackGround);
				value[0].style.color = StyleColor.op_Implicit(textColor);
			}
		}
	}
}