Decompiled source of WhatsThisButton v1.0.1

WhatsThisButton.dll

Decompiled 10 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("WhatsThisButton")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Adds rebinding options ingame that logs the values")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+81df9521a1cbe012a6b0aaa83f9dc8d1b5fac2ec")]
[assembly: AssemblyProduct("WhatsThisButton")]
[assembly: AssemblyTitle("WhatsThisButton")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace WhatsThisButton
{
	internal class GameTips
	{
		private static List<string> tipHeaders = new List<string>();

		private static List<string> tipBodys = new List<string>();

		private static string currentHeader = "";

		private static string currentBody = "";

		private static float lastMessageTime;

		public static void ShowTip(string header, string body)
		{
			int num = tipHeaders.FindIndex((string t) => t == header);
			int num2 = tipBodys.FindIndex((string t) => t == body);
			Plugin.StaticLogger.LogInfo((object)$"hasHeader {num}");
			Plugin.StaticLogger.LogInfo((object)$"hasBody {num2}");
			if ((num < 0 || num2 < 0 || num != num2) && (currentHeader != header || currentBody != body))
			{
				tipHeaders.Add(header);
				tipBodys.Add(body);
			}
		}

		public static void UpdateInternal()
		{
			lastMessageTime -= Time.deltaTime;
			if (!(lastMessageTime < 0f))
			{
				return;
			}
			currentHeader = "";
			currentBody = "";
			if (tipHeaders.Count > 0)
			{
				lastMessageTime = 2.5f;
				currentHeader = tipHeaders[0];
				currentBody = tipBodys[0];
				if ((Object)(object)HUDManager.Instance != (Object)null)
				{
					HUDManager.Instance.DisplayTip(currentHeader, currentBody, false, false, "WTFISB_Tip");
				}
				tipHeaders.RemoveAt(0);
				tipBodys.RemoveAt(0);
			}
		}
	}
	internal class Keybinds : LcInputActions
	{
		public InputAction Button => ((LcInputActions)this).Asset["Button"];

		public InputAction Value => ((LcInputActions)this).Asset["Value"];

		public override void CreateInputActions(in InputActionMapBuilder builder)
		{
			((LcInputActions)this).CreateInputActions(ref builder);
			builder.NewActionBinding().WithActionId("Button").WithActionType((InputActionType)1)
				.WithKbmPath("")
				.WithGamepadPath("")
				.WithBindingName("WTFITK (Button)")
				.Finish();
			builder.NewActionBinding().WithActionId("Value").WithActionType((InputActionType)0)
				.WithKbmPath("")
				.WithGamepadPath("")
				.WithBindingName("WTFITV (Value)")
				.Finish();
		}
	}
	internal class Patches
	{
		public static Keybinds keybinds;

		public static bool devMode;

		private static PlayerControllerB localPlayerController
		{
			get
			{
				StartOfRound instance = StartOfRound.Instance;
				if (!((Object)(object)instance != (Object)null))
				{
					return null;
				}
				return instance.localPlayerController;
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Start")]
		[HarmonyPostfix]
		private static void StartPostfix(PlayerControllerB __instance)
		{
			keybinds.Value.started += onValueStarted;
			keybinds.Value.performed += onValuePerformed;
			keybinds.Value.canceled += onValueCanceled;
			keybinds.Button.started += onButtonStarted;
			keybinds.Button.performed += onButtonPerformed;
			keybinds.Button.canceled += onButtonCanceled;
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		[HarmonyPrefix]
		private static void UpdatePrefix(PlayerControllerB __instance)
		{
			GameTips.UpdateInternal();
		}

		[HarmonyPatch(typeof(PlayerControllerB), "OnDisable")]
		[HarmonyPostfix]
		public static void OnDisablePostfix(PlayerControllerB __instance)
		{
			if ((Object)(object)__instance == (Object)(object)localPlayerController)
			{
				keybinds.Value.started -= onValueStarted;
				keybinds.Value.performed -= onValuePerformed;
				keybinds.Value.canceled -= onValueCanceled;
				keybinds.Button.started -= onButtonStarted;
				keybinds.Button.performed -= onButtonPerformed;
				keybinds.Button.canceled -= onButtonCanceled;
				keybinds.Value.Disable();
			}
		}

		private static void onValueStarted(CallbackContext context)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			logInfo(context, isValue: true, "onValueStarted");
		}

		private static void onValuePerformed(CallbackContext context)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			logInfo(context, isValue: true, "onValuePerformed");
		}

		private static void onValueCanceled(CallbackContext context)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			logInfo(context, isValue: true, "onValueCanceled");
		}

		private static void onButtonStarted(CallbackContext context)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			logInfo(context, isValue: false, "onButtonStarted");
		}

		private static void onButtonPerformed(CallbackContext context)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			logInfo(context, isValue: false, "onButtonPerformed");
		}

		private static void onButtonCanceled(CallbackContext context)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			logInfo(context, isValue: false, "onButtonCancelled");
		}

		private static void logInfo(CallbackContext context, bool isValue, string actionName)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//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_0077: Unknown result type (might be due to invalid IL or missing references)
			Plugin.StaticLogger.LogInfo((object)(actionName + " -----"));
			Plugin.StaticLogger.LogInfo((object)$"context.ReadValueAsObject(): {((CallbackContext)(ref context)).ReadValueAsObject()}");
			if (!isValue)
			{
				Plugin.StaticLogger.LogInfo((object)$"context.ReadValueAsButton(): {((CallbackContext)(ref context)).ReadValueAsButton()}");
			}
			string text = "";
			Enumerator<InputBinding> enumerator = ((CallbackContext)(ref context)).action.bindings.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					InputBinding current = enumerator.Current;
					text = text + ((InputBinding)(ref current)).effectivePath + "\n";
					Plugin.StaticLogger.LogInfo((object)("context.action.bindings[" + ((InputBinding)(ref current)).name + "].effectivePath: " + ((InputBinding)(ref current)).effectivePath));
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			GameTips.ShowTip(((CallbackContext)(ref context)).action.name, text);
		}
	}
	[BepInPlugin("WhatsThisButton", "WhatsThisButton", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		public static Texture2D texture;

		public static ManualLogSource StaticLogger;

		private void Awake()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			StaticLogger = ((BaseUnityPlugin)this).Logger;
			Patches.devMode = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Dev Mode", false, "Whether or not to print additional console output").Value;
			Patches.keybinds = new Keybinds();
			new Harmony("WhatsThisButton").PatchAll(typeof(Patches));
			StaticLogger.LogInfo((object)"Plugin WhatsThisButton is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "WhatsThisButton";

		public const string PLUGIN_NAME = "WhatsThisButton";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}