using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using HarmonyLib;
using InControl;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CoopKBnM")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CoopKBnM")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("825bc8e2-2faf-496c-803c-3f3e31eba1a0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace CoopKBnM;
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("kleirof.etg.coopkbnm", "Coop KB&M", "0.7.7")]
public class CoopKBnMModule : BaseUnityPlugin
{
public enum BraveOptionsOptionType
{
PLAYER_ONE_KEYBOARD_PORT = 256,
PLAYER_ONE_MOUSE_PORT,
SHARE_ONE_KEYBOARD_MODE,
PLAYER_ONE_MOUSE_SENSITIVITY,
PLAYER_TWO_MOUSE_SENSITIVITY
}
public const string GUID = "kleirof.etg.coopkbnm";
public const string NAME = "Coop KB&M";
public const string VERSION = "0.7.7";
public const string TEXT_COLOR = "#FFFFCC";
public static bool isCoopViewLoaded = false;
private static bool isInitializingOptions = false;
private static GameObject masterControlsOptionsScrollablePanelObject;
private static GameObject optionsMenuPanelDaveObject;
private static GameObject rawInputObject;
private static GameObject editKeyboardBindingsButtonPanelCopyObject;
private static GameObject playerOneKeyboardPortArrowSelectorPanelObject;
private static GameObject playerOneMousePortArrowSelectorPanelObject;
private static GameObject shareOneKeyboardPanelObject;
public static GameObject playerOneMouseSensitivityPanelObject;
public static GameObject playerTwoMouseSensitivityPanelObject;
private static GameObject systemMouseLabelPanelTipPanelObject;
private static GameObject shareOneKeyBoardWarningPanelObject;
public static int currentPlayerOneKeyboardPort = 0;
public static int currentPlayerOneMousePort = 0;
public static bool isShareOneKeyboardMode = false;
public static bool restrictKeyboardInputPort = true;
public static bool restrictMouseInputPort = true;
public static float normalizedPlayerOneMouseSensitivity = 0.4f;
public static float normalizedPlayerTwoMouseSensitivity = 0.4f;
public void Start()
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
ETGModMainBehaviour.WaitForGameManagerStart((Action<GameManager>)GMStart);
Harmony.CreateAndPatchAll(typeof(CoopKBnMPatches), (string)null);
rawInputObject = new GameObject("Raw Input Object");
Object.DontDestroyOnLoad((Object)(object)rawInputObject);
rawInputObject.AddComponent<RawInputHandler>();
if (Chainloader.PluginInfos.TryGetValue("kleirof.etg.coopview", out var _))
{
isCoopViewLoaded = true;
}
}
private void Update()
{
if ((Object)(object)masterControlsOptionsScrollablePanelObject == (Object)null && !isInitializingOptions)
{
((MonoBehaviour)this).StartCoroutine(InitializeOptions());
}
}
private IEnumerator InitializeOptions()
{
isInitializingOptions = true;
while (true)
{
if ((Object)(object)optionsMenuPanelDaveObject == (Object)null)
{
optionsMenuPanelDaveObject = GameObject.Find("OptionsMenuPanelDave");
}
if ((Object)(object)optionsMenuPanelDaveObject == (Object)null)
{
yield return null;
continue;
}
FullOptionsMenuController fullOptionsMenuController = optionsMenuPanelDaveObject.GetComponent<FullOptionsMenuController>();
if ((Object)(object)fullOptionsMenuController == (Object)null)
{
yield return null;
continue;
}
if (!fullOptionsMenuController.IsVisible)
{
yield return null;
continue;
}
if ((Object)(object)masterControlsOptionsScrollablePanelObject == (Object)null)
{
masterControlsOptionsScrollablePanelObject = GameObject.Find("MasterControlsOptionsScrollablePanel");
}
if ((Object)(object)masterControlsOptionsScrollablePanelObject != (Object)null)
{
break;
}
yield return null;
}
while ((Object)(object)editKeyboardBindingsButtonPanelCopyObject == (Object)null)
{
GameObject editKeyboardBindingsButtonPanelObject = GameObject.Find("EditKeyboardBindingsButtonPanel");
if ((Object)(object)editKeyboardBindingsButtonPanelObject != (Object)null)
{
GameObject origEditKeyboardBindingsButtonObject = ((Component)editKeyboardBindingsButtonPanelObject.transform.Find("PanelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasy/EditKeyboardBindingsButton")).gameObject;
editKeyboardBindingsButtonPanelCopyObject = Object.Instantiate<GameObject>(editKeyboardBindingsButtonPanelObject, editKeyboardBindingsButtonPanelObject.transform.parent);
((Object)editKeyboardBindingsButtonPanelCopyObject).name = "EditKeyboardBindingsButtonPanelCopy";
GameObject editKeyboardBindingsButtonObject = ((Component)editKeyboardBindingsButtonPanelCopyObject.transform.Find("PanelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasy/EditKeyboardBindingsButton")).gameObject;
editKeyboardBindingsButtonObject.GetComponent<dfButton>().Text = (((int)GameManager.Options.CurrentLanguage == 11) ? "2P Coop KB&M 编辑按键" : "2P Coop KB&M Edit Keyboard Bindings");
editKeyboardBindingsButtonObject.GetComponent<dfButton>().HoverTextColor = new Color32(byte.MaxValue, (byte)163, (byte)52, byte.MaxValue);
origEditKeyboardBindingsButtonObject.GetComponent<dfButton>().Text = (((int)GameManager.Options.CurrentLanguage == 11) ? "1P Coop KB&M 编辑按键" : "1P Coop KB&M Edit Keyboard Bindings");
origEditKeyboardBindingsButtonObject.GetComponent<dfButton>().HoverTextColor = new Color32(byte.MaxValue, (byte)163, (byte)52, byte.MaxValue);
((dfControl)editKeyboardBindingsButtonPanelObject.GetComponent<dfPanel>()).ZOrder = 4;
((dfControl)editKeyboardBindingsButtonPanelCopyObject.GetComponent<dfPanel>()).ZOrder = 10;
}
if ((Object)(object)editKeyboardBindingsButtonPanelCopyObject == (Object)null)
{
yield return null;
}
}
while ((Object)(object)playerOneKeyboardPortArrowSelectorPanelObject == (Object)null)
{
GameObject controllerTypeArrowSelectorPanelObject = GameObject.Find("ControllerTypeArrowSelectorPanel");
if ((Object)(object)controllerTypeArrowSelectorPanelObject != (Object)null)
{
playerOneKeyboardPortArrowSelectorPanelObject = Object.Instantiate<GameObject>(controllerTypeArrowSelectorPanelObject, controllerTypeArrowSelectorPanelObject.transform.parent);
((Object)playerOneKeyboardPortArrowSelectorPanelObject).name = "PlayerOneKeyboardPortArrowSelectorPanel";
GameObject optionsArrowSelectorLabelObject = ((Component)playerOneKeyboardPortArrowSelectorPanelObject.transform.Find("PanelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasy/OptionsArrowSelectorLabel")).gameObject;
optionsArrowSelectorLabelObject.GetComponent<dfLabel>().Text = (((int)GameManager.Options.CurrentLanguage == 11) ? "1P Coop KB&M 键盘接口" : "1P Coop KB&M Keyboard Port");
playerOneKeyboardPortArrowSelectorPanelObject.GetComponent<BraveOptionsMenuItem>().optionType = (BraveOptionsOptionType)256;
playerOneKeyboardPortArrowSelectorPanelObject.GetComponent<BraveOptionsMenuItem>().DetermineAvailableOptions();
playerOneKeyboardPortArrowSelectorPanelObject.GetComponent<BraveOptionsMenuItem>().m_selectedIndex = currentPlayerOneKeyboardPort;
playerOneKeyboardPortArrowSelectorPanelObject.GetComponent<BraveOptionsMenuItem>().HandleValueChanged();
((dfControl)playerOneKeyboardPortArrowSelectorPanelObject.GetComponent<dfPanel>()).ZOrder = 4;
}
if ((Object)(object)playerOneKeyboardPortArrowSelectorPanelObject == (Object)null)
{
yield return null;
}
}
while ((Object)(object)shareOneKeyboardPanelObject == (Object)null)
{
GameObject allowUnknownControllersObject = ((Component)masterControlsOptionsScrollablePanelObject.transform.Find("AllowUnknownControllers")).gameObject;
if ((Object)(object)allowUnknownControllersObject != (Object)null)
{
shareOneKeyboardPanelObject = Object.Instantiate<GameObject>(allowUnknownControllersObject, allowUnknownControllersObject.transform.parent);
((Object)shareOneKeyboardPanelObject).name = "ShareOneKeyboard";
GameObject checkboxLabelObject = ((Component)shareOneKeyboardPanelObject.transform.Find("Panel/CheckboxLabel")).gameObject;
shareOneKeyboardPanelObject.GetComponent<BraveOptionsMenuItem>().m_selectedIndex = (isShareOneKeyboardMode ? 1 : 0);
shareOneKeyboardPanelObject.GetComponent<BraveOptionsMenuItem>().HandleValueChanged();
shareOneKeyboardPanelObject.GetComponent<BraveOptionsMenuItem>().optionType = (BraveOptionsOptionType)258;
dfLabel label = checkboxLabelObject.GetComponent<dfLabel>();
Vector2 origSize = label.obtainRenderer().MeasureString(label.Text);
label.Text = (((int)GameManager.Options.CurrentLanguage == 11) ? "Coop KB&M 共享一个键盘" : "Coop KB&M Share One Keyboard");
Vector2 size = label.obtainRenderer().MeasureString(label.Text);
GameObject panelObject = ((Component)shareOneKeyboardPanelObject.transform.Find("Panel")).gameObject;
dfPanel panel = panelObject.GetComponent<dfPanel>();
Vector2 panelSize = ((dfControl)panel).Size;
((dfControl)panel).SuspendLayout();
((dfControl)panel).Size = new Vector2(panelSize.x + size.x - origSize.x, panelSize.y);
((dfControl)panel).ResumeLayout();
((dfControl)shareOneKeyboardPanelObject.GetComponent<dfPanel>()).ZOrder = 2;
}
if ((Object)(object)shareOneKeyboardPanelObject == (Object)null)
{
yield return null;
}
}
while ((Object)(object)playerOneMousePortArrowSelectorPanelObject == (Object)null)
{
GameObject controllerTypeArrowSelectorPanelObject3 = GameObject.Find("ControllerTypeArrowSelectorPanel");
if ((Object)(object)controllerTypeArrowSelectorPanelObject3 != (Object)null)
{
playerOneMousePortArrowSelectorPanelObject = Object.Instantiate<GameObject>(controllerTypeArrowSelectorPanelObject3, controllerTypeArrowSelectorPanelObject3.transform.parent);
((Object)playerOneMousePortArrowSelectorPanelObject).name = "PlayerOneMousePortArrowSelectorPanel";
GameObject optionsArrowSelectorLabelObject2 = ((Component)playerOneMousePortArrowSelectorPanelObject.transform.Find("PanelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasy/OptionsArrowSelectorLabel")).gameObject;
optionsArrowSelectorLabelObject2.GetComponent<dfLabel>().Text = (((int)GameManager.Options.CurrentLanguage == 11) ? "1P Coop KB&M 鼠标接口" : "1P Coop KB&M Mouse Port");
playerOneMousePortArrowSelectorPanelObject.GetComponent<BraveOptionsMenuItem>().optionType = (BraveOptionsOptionType)257;
playerOneMousePortArrowSelectorPanelObject.GetComponent<BraveOptionsMenuItem>().DetermineAvailableOptions();
playerOneMousePortArrowSelectorPanelObject.GetComponent<BraveOptionsMenuItem>().m_selectedIndex = currentPlayerOneMousePort;
playerOneMousePortArrowSelectorPanelObject.GetComponent<BraveOptionsMenuItem>().HandleValueChanged();
((dfControl)playerOneMousePortArrowSelectorPanelObject.GetComponent<dfPanel>()).ZOrder = 5;
}
if ((Object)(object)playerOneMousePortArrowSelectorPanelObject == (Object)null)
{
yield return null;
}
}
while ((Object)(object)playerOneMouseSensitivityPanelObject == (Object)null)
{
GameObject controllerTypeArrowSelectorPanelObject4 = GameObject.Find("ControllerTypeArrowSelectorPanel");
GameObject screenShakeOptionPanelObject2 = GameObject.Find("ScreenShakeOptionPanel");
if ((Object)(object)controllerTypeArrowSelectorPanelObject4 != (Object)null && (Object)(object)screenShakeOptionPanelObject2 != (Object)null)
{
playerOneMouseSensitivityPanelObject = Object.Instantiate<GameObject>(screenShakeOptionPanelObject2, controllerTypeArrowSelectorPanelObject4.transform.parent);
((Object)playerOneMouseSensitivityPanelObject).name = "PlayerOneMouseSensitivityPanel";
GameObject musicVolumeLabelObject2 = ((Component)playerOneMouseSensitivityPanelObject.transform.Find("PanelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasy/MusicVolumeLabel")).gameObject;
musicVolumeLabelObject2.GetComponent<dfLabel>().Text = (((int)GameManager.Options.CurrentLanguage == 11) ? "1P Coop KB&M 鼠标灵敏度" : "1P Coop KB&M Mouse Sensitivity");
playerOneMouseSensitivityPanelObject.GetComponent<BraveOptionsMenuItem>().optionType = (BraveOptionsOptionType)259;
((Component)playerOneMouseSensitivityPanelObject.transform.Find("PanelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasy/MusicVolumeProgressBar")).GetComponent<dfProgressBar>().Value = normalizedPlayerOneMouseSensitivity;
playerOneMouseSensitivityPanelObject.GetComponent<BraveOptionsMenuItem>().m_actualFillbarValue = normalizedPlayerOneMouseSensitivity;
playerOneMouseSensitivityPanelObject.GetComponent<BraveOptionsMenuItem>().HandleValueChanged();
((dfControl)playerOneMouseSensitivityPanelObject.GetComponent<dfPanel>()).ZOrder = 7;
}
if ((Object)(object)playerOneMouseSensitivityPanelObject == (Object)null)
{
yield return null;
}
}
while ((Object)(object)playerTwoMouseSensitivityPanelObject == (Object)null)
{
GameObject controllerTypeArrowSelectorPanelObject2 = GameObject.Find("ControllerTypeArrowSelectorPanel");
GameObject screenShakeOptionPanelObject = GameObject.Find("ScreenShakeOptionPanel");
if ((Object)(object)controllerTypeArrowSelectorPanelObject2 != (Object)null && (Object)(object)screenShakeOptionPanelObject != (Object)null)
{
playerTwoMouseSensitivityPanelObject = Object.Instantiate<GameObject>(screenShakeOptionPanelObject, controllerTypeArrowSelectorPanelObject2.transform.parent);
((Object)playerTwoMouseSensitivityPanelObject).name = "PlayerTwoMouseSensitivityPanel";
GameObject musicVolumeLabelObject = ((Component)playerTwoMouseSensitivityPanelObject.transform.Find("PanelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasy/MusicVolumeLabel")).gameObject;
musicVolumeLabelObject.GetComponent<dfLabel>().Text = (((int)GameManager.Options.CurrentLanguage == 11) ? "2P Coop KB&M 鼠标灵敏度" : "2P Coop KB&M Mouse Sensitivity");
playerTwoMouseSensitivityPanelObject.GetComponent<BraveOptionsMenuItem>().optionType = (BraveOptionsOptionType)260;
((Component)playerTwoMouseSensitivityPanelObject.transform.Find("PanelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasy/MusicVolumeProgressBar")).GetComponent<dfProgressBar>().Value = normalizedPlayerTwoMouseSensitivity;
playerTwoMouseSensitivityPanelObject.GetComponent<BraveOptionsMenuItem>().m_actualFillbarValue = normalizedPlayerTwoMouseSensitivity;
playerTwoMouseSensitivityPanelObject.GetComponent<BraveOptionsMenuItem>().HandleValueChanged();
((dfControl)playerTwoMouseSensitivityPanelObject.GetComponent<dfPanel>()).ZOrder = 15;
}
if ((Object)(object)playerTwoMouseSensitivityPanelObject == (Object)null)
{
yield return null;
}
}
while ((Object)(object)systemMouseLabelPanelTipPanelObject == (Object)null)
{
GameObject playerOneLabelPanelObject2 = GameObject.Find("PlayerOneLabelPanel");
if ((Object)(object)playerOneLabelPanelObject2 != (Object)null)
{
systemMouseLabelPanelTipPanelObject = Object.Instantiate<GameObject>(playerOneLabelPanelObject2, playerOneLabelPanelObject2.transform.parent);
((Object)systemMouseLabelPanelTipPanelObject).name = "SystemMouseLabelPanelTipPanel";
GameObject labelObject2 = ((Component)systemMouseLabelPanelTipPanelObject.transform.Find("PanelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasy/Label")).gameObject;
labelObject2.GetComponent<dfLabel>().Text = (((int)GameManager.Options.CurrentLanguage == 11) ? ("提示:使用快捷键 " + RawInputHandler.shortcutKeyString + " \n来暂时启用系统光标") : ("Tip: Use shortcut key " + RawInputHandler.shortcutKeyString + " \nto temporarily enable the system cursor"));
((dfControl)labelObject2.GetComponent<dfLabel>()).Color = new Color32((byte)0, byte.MaxValue, (byte)0, byte.MaxValue);
GameObject panelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasyObject2 = ((Component)systemMouseLabelPanelTipPanelObject.transform.Find("PanelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasy")).gameObject;
Vector3 position2 = panelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasyObject2.transform.localPosition;
panelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasyObject2.transform.localPosition = new Vector3(position2.x, position2.y + 0.14f, position2.z);
((dfControl)systemMouseLabelPanelTipPanelObject.GetComponent<dfPanel>()).ZOrder = 0;
}
if ((Object)(object)systemMouseLabelPanelTipPanelObject == (Object)null)
{
yield return null;
}
}
while ((Object)(object)shareOneKeyBoardWarningPanelObject == (Object)null)
{
GameObject playerOneLabelPanelObject = GameObject.Find("PlayerOneLabelPanel");
if ((Object)(object)playerOneLabelPanelObject != (Object)null)
{
shareOneKeyBoardWarningPanelObject = Object.Instantiate<GameObject>(playerOneLabelPanelObject, playerOneLabelPanelObject.transform.parent);
((Object)shareOneKeyBoardWarningPanelObject).name = "ShareOneKeyBoardWarningPanel";
GameObject labelObject = ((Component)shareOneKeyBoardWarningPanelObject.transform.Find("PanelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasy/Label")).gameObject;
labelObject.GetComponent<dfLabel>().Text = (((int)GameManager.Options.CurrentLanguage == 11) ? "警告:开启“共享一个键盘”会让2P中与1P相同\n的按键绑定删除" : "Warning: Enabling 'Share One Keyboard' will cause \nthe same key binding as 1P to be deleted in 2P");
((dfControl)labelObject.GetComponent<dfLabel>()).Color = new Color32(byte.MaxValue, (byte)0, (byte)0, byte.MaxValue);
GameObject panelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasyObject = ((Component)shareOneKeyBoardWarningPanelObject.transform.Find("PanelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasy")).gameObject;
Vector3 position = panelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasyObject.transform.localPosition;
panelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasyObject.transform.localPosition = new Vector3(position.x, position.y + 0.11f, position.z);
((dfControl)shareOneKeyBoardWarningPanelObject.GetComponent<dfPanel>()).ZOrder = 3;
}
if ((Object)(object)shareOneKeyBoardWarningPanelObject == (Object)null)
{
yield return null;
}
}
dfList<dfControl> controls = ((dfControl)GameObject.Find("MasterControlsOptionsScrollablePanel").GetComponent<dfScrollPanel>()).controls;
int i = 0;
while (i < controls.Count - 1)
{
int num;
if (((dfControl)((Component)controls[i]).gameObject.GetComponent<dfPanel>()).CanFocus)
{
int l = i + 1;
while (l < controls.Count - 1 && !((dfControl)((Component)controls[l]).gameObject.GetComponent<dfPanel>()).CanFocus)
{
num = l + 1;
l = num;
}
if (l < controls.Count - 1)
{
((Component)controls[i]).gameObject.GetComponent<BraveOptionsMenuItem>().down = controls[l];
}
}
num = i + 1;
i = num;
}
int j = controls.Count - 1;
while (j > 0)
{
int num;
if (((dfControl)((Component)controls[j]).gameObject.GetComponent<dfPanel>()).CanFocus)
{
int k = j - 1;
while (k > 0 && !((dfControl)((Component)controls[k]).gameObject.GetComponent<dfPanel>()).CanFocus)
{
num = k - 1;
k = num;
}
if (k > 0)
{
((Component)controls[j]).gameObject.GetComponent<BraveOptionsMenuItem>().up = controls[k];
}
}
num = j - 1;
j = num;
}
int indexCanSelect = 0;
while (indexCanSelect < controls.Count && !controls[indexCanSelect].CanFocus)
{
int num = indexCanSelect + 1;
indexCanSelect = num;
}
if (controls.Count > 0 && indexCanSelect < controls.Count && ((dfControl)optionsMenuPanelDaveObject.GetComponent<FullOptionsMenuController>().TabControls).IsVisible)
{
GameObject.Find("ConfirmButton").GetComponent<UIKeyControls>().down = controls[indexCanSelect];
GameObject.Find("CancelButton").GetComponent<UIKeyControls>().down = controls[indexCanSelect];
GameObject.Find("ResetDefaultsButton").GetComponent<UIKeyControls>().down = controls[indexCanSelect];
((Component)controls[indexCanSelect]).gameObject.GetComponent<BraveOptionsMenuItem>().up = (dfControl)(object)GameObject.Find("ConfirmButton").GetComponent<dfButton>();
controls[indexCanSelect].Focus(true);
}
isInitializingOptions = false;
}
public static void Log(string text, string color = "FFFFFF")
{
ETGModConsole.Log((object)("<color=" + color + ">" + text + "</color>"), false);
}
public void GMStart(GameManager g)
{
Log("Coop KB&M v0.7.7 started successfully.", "#FFFFCC");
}
}
public static class CoopKBnMPatches
{
[HarmonyILManipulator]
[HarmonyPatch(typeof(FoyerCharacterSelectFlag), "Update")]
public static void FoyerCharacterSelectFlagUpdatePatch(ILContext ctx)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchLdfld<FoyerCharacterSelectFlag>(x, "m_active")
}))
{
val.EmitDelegate<Func<bool, bool>>((Func<bool, bool>)((bool orig) => false));
}
}
[HarmonyILManipulator]
[HarmonyPatch(typeof(BraveInput), "AssignActionsDevice")]
public static void AssignActionsDevicePatch(ILContext ctx)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchCallvirt<PlayerActionSet>(x, "set_Device"),
(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
(Instruction x) => ILPatternMatchingExt.MatchLdfld<BraveInput>(x, "m_playerID")
}))
{
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Func<bool, BraveInput, bool>>((Func<bool, BraveInput, bool>)((bool orig, BraveInput self) => orig && ((PlayerActionSet)self.m_activeGungeonActions).Device != null));
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(BraveInput), "AssignActionsDevice")]
public static void AssignActionsDevice_Post()
{
((MonoBehaviour)GameManager.Instance).StartCoroutine(ReassignKeyboardAndMouse());
}
private static IEnumerator ReassignKeyboardAndMouse()
{
yield return null;
yield return null;
Dictionary<int, int> map = GameManager.Options.PlayerIDtoDeviceIndexMap;
if (map.Count <= 1 || BraveInput.m_instances.Count <= 1)
{
CoopKBnMModule.restrictKeyboardInputPort = false;
CoopKBnMModule.restrictMouseInputPort = false;
yield break;
}
if (InputManager.Devices.Count > 0)
{
if (map[0] != InputManager.Devices.Count && map[1] != InputManager.Devices.Count)
{
CoopKBnMModule.restrictKeyboardInputPort = false;
CoopKBnMModule.restrictMouseInputPort = false;
yield break;
}
if (map[0] != InputManager.Devices.Count || map[1] != InputManager.Devices.Count)
{
CoopKBnMModule.restrictKeyboardInputPort = false;
CoopKBnMModule.restrictMouseInputPort = false;
yield break;
}
}
CoopKBnMModule.restrictKeyboardInputPort = true;
CoopKBnMModule.restrictMouseInputPort = true;
if (CoopKBnMModule.isShareOneKeyboardMode)
{
CoopKBnMModule.restrictKeyboardInputPort = false;
}
BraveInput keyboardBraveInput = ((CoopKBnMModule.currentPlayerOneKeyboardPort != 0) ? BraveInput.m_instances[1] : BraveInput.m_instances[0]);
BraveInput mouseBraveInput = ((CoopKBnMModule.currentPlayerOneMousePort != 0) ? BraveInput.m_instances[1] : BraveInput.m_instances[0]);
GungeonActions keyboardActions = keyboardBraveInput.m_activeGungeonActions;
if (keyboardActions != RawInputHandler.firstKeyboardActionSet)
{
RawInputHandler.firstKeyboardActionSet = keyboardActions;
}
GungeonActions mouseActions = mouseBraveInput.m_activeGungeonActions;
if (mouseActions != RawInputHandler.firstMouseActionSet)
{
RawInputHandler.firstMouseActionSet = mouseActions;
}
}
[HarmonyILManipulator]
[HarmonyPatch(typeof(PlayerAction), "UpdateBindings")]
public static void UpdateBindingsPatch(ILContext ctx)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(ctx);
if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCallvirt<BindingSource>(x, "GetValue")
}))
{
return;
}
val.Emit(OpCodes.Ldloc_S, (byte)8);
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Func<float, BindingSource, PlayerAction, float>>((Func<float, BindingSource, PlayerAction, float>)delegate(float orig, BindingSource bindingSource, PlayerAction self)
{
if (bindingSource is KeyBindingSource && CoopKBnMModule.restrictKeyboardInputPort)
{
return RawInputHandler.GetValue((KeyBindingSource)(object)((bindingSource is KeyBindingSource) ? bindingSource : null), self.Device, RawInputHandler.IsFirstKeyboard(self));
}
return (bindingSource is MouseBindingSource && CoopKBnMModule.restrictMouseInputPort) ? RawInputHandler.GetValue((MouseBindingSource)(object)((bindingSource is MouseBindingSource) ? bindingSource : null), self.Device, RawInputHandler.IsFirstMouse(self)) : orig;
});
}
[HarmonyPrefix]
[HarmonyPatch(typeof(BraveOptionsMenuItem), "DetermineAvailableOptions")]
public static bool DetermineAvailableOptions_Pre(BraveOptionsMenuItem __instance)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Invalid comparison between Unknown and I4
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Invalid comparison between Unknown and I4
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Invalid comparison between Unknown and I4
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Invalid comparison between Unknown and I4
BraveOptionsOptionType optionType = __instance.optionType;
BraveOptionsOptionType val = optionType;
if ((int)val != 256)
{
if ((int)val == 257)
{
List<string> list = (((int)GameManager.Options.CurrentLanguage == 11) ? new List<string> { "鼠标 1", "鼠标 2" } : new List<string> { "Mouse 1", "Mouse 2" });
__instance.labelOptions = list.ToArray();
}
}
else
{
List<string> list2 = (((int)GameManager.Options.CurrentLanguage == 11) ? new List<string> { "键盘 1", "键盘 2" } : new List<string> { "Keyboard 1", "Keyboard 2" });
__instance.labelOptions = list2.ToArray();
}
return true;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(BraveOptionsMenuItem), "HandleLeftRightArrowValueChanged")]
public static void HandleLeftRightArrowValueChanged_Post(BraveOptionsMenuItem __instance)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Invalid comparison between Unknown and I4
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Invalid comparison between Unknown and I4
BraveOptionsOptionType optionType = __instance.optionType;
BraveOptionsOptionType val = optionType;
if ((int)val != 256)
{
if ((int)val == 257)
{
CoopKBnMModule.currentPlayerOneMousePort = __instance.m_selectedIndex;
((MonoBehaviour)GameManager.Instance).StartCoroutine(ReassignKeyboardAndMouse());
float normalizedPlayerOneMouseSensitivity = CoopKBnMModule.normalizedPlayerOneMouseSensitivity;
CoopKBnMModule.normalizedPlayerOneMouseSensitivity = CoopKBnMModule.normalizedPlayerTwoMouseSensitivity;
CoopKBnMModule.normalizedPlayerTwoMouseSensitivity = normalizedPlayerOneMouseSensitivity;
if ((Object)(object)CoopKBnMModule.playerOneMouseSensitivityPanelObject != (Object)null)
{
((Component)CoopKBnMModule.playerOneMouseSensitivityPanelObject.transform.Find("PanelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasy/MusicVolumeProgressBar")).GetComponent<dfProgressBar>().Value = CoopKBnMModule.normalizedPlayerOneMouseSensitivity;
}
if ((Object)(object)CoopKBnMModule.playerTwoMouseSensitivityPanelObject != (Object)null)
{
((Component)CoopKBnMModule.playerTwoMouseSensitivityPanelObject.transform.Find("PanelEnsmallenerThatmakesDavesLifeHardandBrentsLifeEasy/MusicVolumeProgressBar")).GetComponent<dfProgressBar>().Value = CoopKBnMModule.normalizedPlayerTwoMouseSensitivity;
}
RawInputHandler.playerOneMouseSensitivity = Mathf.Clamp(4f * CoopKBnMModule.normalizedPlayerOneMouseSensitivity + 0.4f, 0.4f, 4.4f);
RawInputHandler.playerTwoMouseSensitivity = Mathf.Clamp(4f * CoopKBnMModule.normalizedPlayerTwoMouseSensitivity + 0.4f, 0.4f, 4.4f);
RawInputHandler.mousePortReady = true;
}
}
else
{
CoopKBnMModule.currentPlayerOneKeyboardPort = __instance.m_selectedIndex;
((MonoBehaviour)GameManager.Instance).StartCoroutine(ReassignKeyboardAndMouse());
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(BraveOptionsMenuItem), "HandleCheckboxValueChanged")]
public static bool HandleCheckboxValueChanged_Pre(BraveOptionsMenuItem __instance)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Invalid comparison between Unknown and I4
BraveOptionsOptionType optionType = __instance.optionType;
BraveOptionsOptionType val = optionType;
if ((int)val == 258)
{
CoopKBnMModule.isShareOneKeyboardMode = __instance.m_selectedIndex != 0;
RawInputHandler.RemoveDuplicateBindings();
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(BraveOptionsMenuItem), "HandleFillbarValueChanged")]
public static bool HandleFillbarValueChanged_Pre(BraveOptionsMenuItem __instance)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Invalid comparison between Unknown and I4
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Invalid comparison between Unknown and I4
BraveOptionsOptionType optionType = __instance.optionType;
BraveOptionsOptionType val = optionType;
if ((int)val != 259)
{
if ((int)val == 260)
{
RawInputHandler.playerTwoMouseSensitivity = Mathf.Clamp(4f * __instance.m_actualFillbarValue + 0.4f, 0.4f, 4.4f);
CoopKBnMModule.normalizedPlayerTwoMouseSensitivity = __instance.m_actualFillbarValue;
}
}
else
{
RawInputHandler.playerOneMouseSensitivity = Mathf.Clamp(4f * __instance.m_actualFillbarValue + 0.4f, 0.4f, 4.4f);
CoopKBnMModule.normalizedPlayerOneMouseSensitivity = __instance.m_actualFillbarValue;
}
return true;
}
[HarmonyILManipulator]
[HarmonyPatch(typeof(BraveOptionsMenuItem), "DoSelectedAction")]
public static void DoSelectedActionPatch(ILContext ctx)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchStsfld<FullOptionsMenuController>(x, "CurrentBindingPlayerTargetIndex")
}))
{
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Func<int, BraveOptionsMenuItem, int>>((Func<int, BraveOptionsMenuItem, int>)((int orig, BraveOptionsMenuItem self) => (!(((Object)self).name == "EditKeyboardBindingsButtonPanel")) ? 1 : 0));
}
}
[HarmonyILManipulator]
[HarmonyPatch(typeof(KeyboardBindingMenuOption), "InitializeKeyboard")]
public static void InitializeKeyboardPatch(ILContext ctx)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCallvirt<GameManager>(x, "get_CurrentGameType")
}))
{
val.EmitDelegate<Func<int, int>>((Func<int, int>)((int orig) => 0));
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(KeyboardBindingMenuOption), "EnterAssignmentMode")]
public static void EnterAssignmentMode_Post(KeyboardBindingMenuOption __instance, bool isAlternateKey)
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
GungeonActions activeActions = __instance.GetBestInputInstance().ActiveActions;
PlayerAction actionFromType = activeActions.GetActionFromType(__instance.ActionType);
BindingListenOptions bindingOptions = actionFromType.ListenOptions;
bindingOptions.OnBindingFound = delegate(PlayerAction action, BindingSource binding)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Expected O, but got Unknown
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
if (binding == (BindingSource)new KeyBindingSource((Key[])(object)new Key[1] { (Key)13 }))
{
action.StopListeningForBinding();
((Component)GameUIRoot.Instance.PauseMenuPanel).GetComponent<PauseMenuController>().OptionsMenu.ClearModalKeyBindingDialog((dfControl)null, (dfControlEventArgs)null);
return false;
}
if (binding == (BindingSource)new KeyBindingSource((Key[])(object)new Key[1] { (Key)78 }))
{
action.StopListeningForBinding();
((Component)GameUIRoot.Instance.PauseMenuPanel).GetComponent<PauseMenuController>().OptionsMenu.ClearModalKeyBindingDialog((dfControl)null, (dfControlEventArgs)null);
return false;
}
if (__instance.IsControllerMode && binding is KeyBindingSource)
{
return false;
}
if (CoopKBnMModule.isShareOneKeyboardMode && BraveInput.m_instances.Count > 1 && action.Owner == BraveInput.GetInstanceForPlayer(1).ActiveActions && ((PlayerActionSet)BraveInput.GetInstanceForPlayer(0).ActiveActions).HasBinding(binding))
{
return false;
}
if (CoopKBnMModule.isShareOneKeyboardMode && BraveInput.m_instances.Count > 1 && action.Owner == BraveInput.GetInstanceForPlayer(0).ActiveActions && ((PlayerActionSet)BraveInput.GetInstanceForPlayer(1).ActiveActions).HasBinding(binding))
{
int count = ((PlayerActionSet)BraveInput.GetInstanceForPlayer(1).ActiveActions).Actions.Count;
for (int i = 0; i < count; i++)
{
((PlayerActionSet)BraveInput.GetInstanceForPlayer(1).ActiveActions).Actions[i].HardRemoveBinding(binding);
}
}
action.StopListeningForBinding();
if (!__instance.m_parentOptionsMenu.ActionIsMultibindable(__instance.ActionType, activeActions))
{
__instance.m_parentOptionsMenu.ClearBindingFromAllControls(FullOptionsMenuController.CurrentBindingPlayerTargetIndex, binding);
}
action.SetBindingOfTypeByNumber(binding, binding.BindingSourceType, isAlternateKey ? 1 : 0, bindingOptions.OnBindingAdded);
((Component)GameUIRoot.Instance.PauseMenuPanel).GetComponent<PauseMenuController>().OptionsMenu.ToggleKeyBindingDialogState(binding);
__instance.Initialize();
return false;
};
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GungeonActions), "ReinitializeDefaults")]
public static void ReinitializeDefaults_Post()
{
RawInputHandler.RemoveDuplicateBindings();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GungeonActions), "InitializeSwappedTriggersPreset")]
public static void InitializeSwappedTriggersPreset_Post()
{
RawInputHandler.RemoveDuplicateBindings();
}
[HarmonyPrefix]
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
public static bool Get_MousePosition_Pre(ref Vector3 __result)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
__result = Vector2.op_Implicit(RawInputHandler.firstMousePosition);
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(MouseBindingSource), "PositiveScrollWheelIsActive")]
public static bool PositiveScrollWheelIsActive_Pre(float threshold, ref bool __result)
{
float num = Mathf.Max(0f, (float)RawInputHandler.GetPublicWheel() * MouseBindingSource.ScaleZ);
__result = num > threshold;
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(MouseBindingSource), "NegativeScrollWheelIsActive")]
public static bool NegativeScrollWheelIsActive_Pre(float threshold, ref bool __result)
{
float num = Mathf.Min((float)RawInputHandler.GetPublicWheel() * MouseBindingSource.ScaleZ, 0f);
__result = num < 0f - threshold;
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Input), "GetAxis")]
public static bool GetAxis_Pre(string axisName, ref float __result)
{
if (axisName == "Mouse ScrollWheel")
{
__result = RawInputHandler.GetPublicSmoothWheelValue();
return false;
}
return true;
}
[HarmonyILManipulator]
[HarmonyPatch(typeof(GameCursorController), "DrawCursor")]
public static void DrawCursorPatch(ILContext ctx)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCall<GameCursorController>(x, "get_showMouseCursor")
}))
{
val.EmitDelegate<Func<bool, bool>>((Func<bool, bool>)((bool orig) => orig && !RawInputHandler.ShowTwoMouseCursor));
}
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCallvirt<BraveInput>(x, "IsKeyboardAndMouse")
}))
{
val.EmitDelegate<Func<bool, bool>>((Func<bool, bool>)((bool orig) => orig && !CoopKBnMModule.restrictMouseInputPort));
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameCursorController), "DrawCursor")]
public static void DrawCursor_Post(GameCursorController __instance)
{
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: 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_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: 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_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Unknown result type (might be due to invalid IL or missing references)
if (!GameManager.HasInstance)
{
return;
}
Texture2D val = __instance.normalCursor;
int currentCursorIndex = GameManager.Options.CurrentCursorIndex;
if (currentCursorIndex >= 0 && currentCursorIndex < __instance.cursors.Length)
{
val = __instance.cursors[currentCursorIndex];
}
if (GameCursorController.showMouseCursor && RawInputHandler.ShowTwoMouseCursor)
{
Vector2 val2 = ((CoopKBnMModule.currentPlayerOneMousePort != 0) ? RawInputHandler.secondMousePosition : RawInputHandler.firstMousePosition);
val2.y = (float)Screen.height - val2.y;
Vector2 val3 = new Vector2((float)((Texture)val).width, (float)((Texture)val).height) * (float)((!((Object)(object)Pixelator.Instance != (Object)null)) ? 3 : ((int)Pixelator.Instance.ScaleTileScale));
Rect val4 = default(Rect);
((Rect)(ref val4))..ctor(val2.x + 0.5f - val3.x / 2f, val2.y + 0.5f - val3.y / 2f, val3.x, val3.y);
Graphics.DrawTexture(val4, (Texture)(object)val);
if (!CoopKBnMModule.isCoopViewLoaded)
{
Vector2 val5 = ((CoopKBnMModule.currentPlayerOneMousePort != 0) ? RawInputHandler.firstMousePosition : RawInputHandler.secondMousePosition);
val5.y = (float)Screen.height - val5.y;
Vector2 val6 = new Vector2((float)((Texture)val).width, (float)((Texture)val).height) * (float)((!((Object)(object)Pixelator.Instance != (Object)null)) ? 3 : ((int)Pixelator.Instance.ScaleTileScale));
Rect val7 = default(Rect);
((Rect)(ref val7))..ctor(val5.x + 0.5f - val6.x / 2f, val5.y + 0.5f - val6.y / 2f, val6.x, val6.y);
Graphics.DrawTexture(val7, (Texture)(object)val, new Rect(0f, 0f, 1f, 1f), 0, 0, 0, 0, new Color(0.402f, 0.111f, 0.32f));
}
}
}
[HarmonyILManipulator]
[HarmonyPatch(typeof(PlayerController), "DetermineAimPointInWorld")]
public static void DetermineAimPointInWorldPatch(ILContext ctx)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[4]
{
(Instruction x) => ILPatternMatchingExt.MatchCall<Input>(x, "get_mousePosition"),
(Instruction x) => ILPatternMatchingExt.Match(x, OpCodes.Stloc_S),
(Instruction x) => ILPatternMatchingExt.Match(x, OpCodes.Ldloca_S),
(Instruction x) => ILPatternMatchingExt.MatchLdfld<Vector3>(x, "x")
}))
{
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Func<float, PlayerController, float>>((Func<float, PlayerController, float>)delegate(float orig, PlayerController self)
{
if (CoopKBnMModule.restrictMouseInputPort)
{
if (self.IsPrimaryPlayer)
{
if (CoopKBnMModule.currentPlayerOneMousePort == 0)
{
return RawInputHandler.firstMousePosition.x;
}
return RawInputHandler.secondMousePosition.x;
}
if (CoopKBnMModule.currentPlayerOneMousePort == 0)
{
return RawInputHandler.secondMousePosition.x;
}
return RawInputHandler.firstMousePosition.x;
}
return orig;
});
}
if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[4]
{
(Instruction x) => ILPatternMatchingExt.MatchCall<Input>(x, "get_mousePosition"),
(Instruction x) => ILPatternMatchingExt.Match(x, OpCodes.Stloc_S),
(Instruction x) => ILPatternMatchingExt.Match(x, OpCodes.Ldloca_S),
(Instruction x) => ILPatternMatchingExt.MatchLdfld<Vector3>(x, "y")
}))
{
return;
}
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Func<float, PlayerController, float>>((Func<float, PlayerController, float>)delegate(float orig, PlayerController self)
{
if (CoopKBnMModule.restrictMouseInputPort)
{
if (self.IsPrimaryPlayer)
{
if (CoopKBnMModule.currentPlayerOneMousePort == 0)
{
return RawInputHandler.firstMousePosition.y;
}
return RawInputHandler.secondMousePosition.y;
}
if (CoopKBnMModule.currentPlayerOneMousePort == 0)
{
return RawInputHandler.secondMousePosition.y;
}
return RawInputHandler.firstMousePosition.y;
}
return orig;
});
}
[HarmonyPostfix]
[HarmonyPatch(typeof(FullOptionsMenuController), "ToggleToPanel")]
public static void ToggleToPanel_Post(FullOptionsMenuController __instance, dfScrollPanel targetPanel, bool doFocus)
{
if ((Object)(object)targetPanel == (Object)(object)__instance.TabControls)
{
int i;
for (i = 0; i < ((dfControl)targetPanel).Controls.Count && !((dfControl)targetPanel).Controls[i].CanFocus; i++)
{
}
if (((dfControl)targetPanel).Controls.Count > 0 && i < ((dfControl)targetPanel).Controls.Count)
{
((Component)__instance.PrimaryCancelButton).GetComponent<UIKeyControls>().down = ((dfControl)targetPanel).Controls[i];
((Component)__instance.PrimaryConfirmButton).GetComponent<UIKeyControls>().down = ((dfControl)targetPanel).Controls[i];
((Component)__instance.PrimaryResetDefaultsButton).GetComponent<UIKeyControls>().down = ((dfControl)targetPanel).Controls[i];
((Component)((dfControl)targetPanel).Controls[i]).GetComponent<BraveOptionsMenuItem>().up = (dfControl)(object)__instance.PrimaryConfirmButton;
((dfControl)targetPanel).Controls[i].Focus(true);
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(BraveOptionsMenuItem), "Awake")]
public static void BraveOptionsMenuItemAwake_Post(BraveOptionsMenuItem __instance)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Invalid comparison between Unknown and I4
if ((int)__instance.optionType == 8)
{
__instance.labelOptions = new string[2] { "Borderless", "Windowed" };
}
}
[HarmonyILManipulator]
[HarmonyPatch(typeof(BraveOptionsMenuItem), "HandleLeftRightArrowValueChanged")]
public static void HandleLeftRightArrowValueChangedPatch(ILContext ctx)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCallvirt<GameOptions>(x, "set_CurrentPreferredFullscreenMode")
}))
{
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Action<BraveOptionsMenuItem>>((Action<BraveOptionsMenuItem>)delegate(BraveOptionsMenuItem self)
{
GameManager.Options.CurrentPreferredFullscreenMode = (PreferredFullscreenMode)((self.m_selectedIndex == 0) ? 1 : 2);
});
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(BraveOptionsMenuItem), "GetIndexFromFullscreenMode")]
public static bool GetIndexFromFullscreenMode_Pre(PreferredFullscreenMode fMode, ref int __result)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0004: Invalid comparison between Unknown and I4
__result = (((int)fMode == 2) ? 1 : 0);
return false;
}
[HarmonyILManipulator]
[HarmonyPatch(typeof(BraveOptionsMenuItem), "Update")]
public static void BraveOptionsMenuItemUpdatePatch(ILContext ctx)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCallvirt<GameOptions>(x, "get_CurrentPreferredFullscreenMode")
}))
{
val.EmitDelegate<Func<PreferredFullscreenMode, PreferredFullscreenMode>>((Func<PreferredFullscreenMode, PreferredFullscreenMode>)((PreferredFullscreenMode orig) => (PreferredFullscreenMode)0));
}
}
[HarmonyILManipulator]
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
public static void Set_CurrentVisualPreset_Post(ILContext ctx)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
ILCursor val = new ILCursor(ctx);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchStfld<GameOptions>(x, "m_visualPresetMode"),
(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
(Instruction x) => ILPatternMatchingExt.MatchLdfld<GameOptions>(x, "m_visualPresetMode")
}))
{
val.EmitDelegate<Func<VisualPresetMode, VisualPresetMode>>((Func<VisualPresetMode, VisualPresetMode>)((VisualPresetMode orig) => (VisualPresetMode)1));
}
}
}
internal static class KeyCodeMaps
{
public enum Keys
{
Modifiers = -65536,
None = 0,
Back = 8,
Tab = 9,
Clear = 12,
Enter = 13,
Shift = 16,
Control = 17,
Alt = 18,
Pause = 19,
Capital = 20,
CapsLock = 20,
Escape = 27,
Space = 32,
PageUp = 33,
PageDown = 34,
End = 35,
Home = 36,
Left = 37,
Up = 38,
Right = 39,
Down = 40,
Print = 42,
PrintScreen = 44,
Insert = 45,
Delete = 46,
D0 = 48,
D1 = 49,
D2 = 50,
D3 = 51,
D4 = 52,
D5 = 53,
D6 = 54,
D7 = 55,
D8 = 56,
D9 = 57,
A = 65,
B = 66,
C = 67,
D = 68,
E = 69,
F = 70,
G = 71,
H = 72,
I = 73,
J = 74,
K = 75,
L = 76,
M = 77,
N = 78,
O = 79,
P = 80,
Q = 81,
R = 82,
S = 83,
T = 84,
U = 85,
V = 86,
W = 87,
X = 88,
Y = 89,
Z = 90,
NumPad0 = 96,
NumPad1 = 97,
NumPad2 = 98,
NumPad3 = 99,
NumPad4 = 100,
NumPad5 = 101,
NumPad6 = 102,
NumPad7 = 103,
NumPad8 = 104,
NumPad9 = 105,
Multiply = 106,
Add = 107,
Separator = 108,
Subtract = 109,
Decimal = 110,
Divide = 111,
F1 = 112,
F2 = 113,
F3 = 114,
F4 = 115,
F5 = 116,
F6 = 117,
F7 = 118,
F8 = 119,
F9 = 120,
F10 = 121,
F11 = 122,
F12 = 123,
F13 = 124,
F14 = 125,
F15 = 126,
F16 = 127,
F17 = 128,
F18 = 129,
F19 = 130,
F20 = 131,
F21 = 132,
F22 = 133,
F23 = 134,
F24 = 135,
NumLock = 144,
Scroll = 145,
OemSemicolon = 186,
Oem1 = 186,
Oemplus = 187,
Oemcomma = 188,
OemMinus = 189,
OemPeriod = 190,
OemQuestion = 191,
Oem2 = 191,
Oemtilde = 192,
Oem3 = 192,
OemOpenBrackets = 219,
Oem4 = 219,
OemPipe = 220,
Oem5 = 220,
OemCloseBrackets = 221,
Oem6 = 221,
OemQuotes = 222,
Oem7 = 222,
Oem8 = 223,
OemBackslash = 226,
KeyCode = 65535
}
public static Dictionary<KeyCode, Keys> KeyCodeToKeysMap = new Dictionary<KeyCode, Keys>
{
{
(KeyCode)97,
Keys.A
},
{
(KeyCode)98,
Keys.B
},
{
(KeyCode)99,
Keys.C
},
{
(KeyCode)100,
Keys.D
},
{
(KeyCode)101,
Keys.E
},
{
(KeyCode)102,
Keys.F
},
{
(KeyCode)103,
Keys.G
},
{
(KeyCode)104,
Keys.H
},
{
(KeyCode)105,
Keys.I
},
{
(KeyCode)106,
Keys.J
},
{
(KeyCode)107,
Keys.K
},
{
(KeyCode)108,
Keys.L
},
{
(KeyCode)109,
Keys.M
},
{
(KeyCode)110,
Keys.N
},
{
(KeyCode)111,
Keys.O
},
{
(KeyCode)112,
Keys.P
},
{
(KeyCode)113,
Keys.Q
},
{
(KeyCode)114,
Keys.R
},
{
(KeyCode)115,
Keys.S
},
{
(KeyCode)116,
Keys.T
},
{
(KeyCode)117,
Keys.U
},
{
(KeyCode)118,
Keys.V
},
{
(KeyCode)119,
Keys.W
},
{
(KeyCode)120,
Keys.X
},
{
(KeyCode)121,
Keys.Y
},
{
(KeyCode)122,
Keys.Z
},
{
(KeyCode)48,
Keys.D0
},
{
(KeyCode)49,
Keys.D1
},
{
(KeyCode)50,
Keys.D2
},
{
(KeyCode)51,
Keys.D3
},
{
(KeyCode)52,
Keys.D4
},
{
(KeyCode)53,
Keys.D5
},
{
(KeyCode)54,
Keys.D6
},
{
(KeyCode)55,
Keys.D7
},
{
(KeyCode)56,
Keys.D8
},
{
(KeyCode)57,
Keys.D9
},
{
(KeyCode)282,
Keys.F1
},
{
(KeyCode)283,
Keys.F2
},
{
(KeyCode)284,
Keys.F3
},
{
(KeyCode)285,
Keys.F4
},
{
(KeyCode)286,
Keys.F5
},
{
(KeyCode)287,
Keys.F6
},
{
(KeyCode)288,
Keys.F7
},
{
(KeyCode)289,
Keys.F8
},
{
(KeyCode)290,
Keys.F9
},
{
(KeyCode)291,
Keys.F10
},
{
(KeyCode)292,
Keys.F11
},
{
(KeyCode)293,
Keys.F12
},
{
(KeyCode)306,
Keys.Control
},
{
(KeyCode)305,
Keys.Control
},
{
(KeyCode)304,
Keys.Shift
},
{
(KeyCode)303,
Keys.Shift
},
{
(KeyCode)308,
Keys.Alt
},
{
(KeyCode)307,
Keys.Alt
},
{
(KeyCode)32,
Keys.Space
},
{
(KeyCode)13,
Keys.Enter
},
{
(KeyCode)8,
Keys.Back
},
{
(KeyCode)27,
Keys.Escape
},
{
(KeyCode)9,
Keys.Tab
},
{
(KeyCode)301,
Keys.Capital
},
{
(KeyCode)127,
Keys.Delete
},
{
(KeyCode)277,
Keys.Insert
},
{
(KeyCode)278,
Keys.Home
},
{
(KeyCode)279,
Keys.End
},
{
(KeyCode)280,
Keys.PageUp
},
{
(KeyCode)281,
Keys.PageDown
},
{
(KeyCode)273,
Keys.Up
},
{
(KeyCode)274,
Keys.Down
},
{
(KeyCode)276,
Keys.Left
},
{
(KeyCode)275,
Keys.Right
},
{
(KeyCode)59,
Keys.OemSemicolon
},
{
(KeyCode)47,
Keys.OemQuestion
},
{
(KeyCode)92,
Keys.OemPipe
},
{
(KeyCode)91,
Keys.OemOpenBrackets
},
{
(KeyCode)93,
Keys.OemCloseBrackets
},
{
(KeyCode)39,
Keys.OemQuotes
},
{
(KeyCode)96,
Keys.Oemtilde
},
{
(KeyCode)45,
Keys.OemMinus
},
{
(KeyCode)61,
Keys.Oemplus
},
{
(KeyCode)44,
Keys.Oemcomma
},
{
(KeyCode)46,
Keys.OemPeriod
},
{
(KeyCode)256,
Keys.NumPad0
},
{
(KeyCode)257,
Keys.NumPad1
},
{
(KeyCode)258,
Keys.NumPad2
},
{
(KeyCode)259,
Keys.NumPad3
},
{
(KeyCode)260,
Keys.NumPad4
},
{
(KeyCode)261,
Keys.NumPad5
},
{
(KeyCode)262,
Keys.NumPad6
},
{
(KeyCode)263,
Keys.NumPad7
},
{
(KeyCode)264,
Keys.NumPad8
},
{
(KeyCode)265,
Keys.NumPad9
},
{
(KeyCode)267,
Keys.Divide
},
{
(KeyCode)268,
Keys.Multiply
},
{
(KeyCode)269,
Keys.Subtract
},
{
(KeyCode)270,
Keys.Add
},
{
(KeyCode)271,
Keys.Enter
},
{
(KeyCode)266,
Keys.Decimal
},
{
(KeyCode)316,
Keys.PrintScreen
},
{
(KeyCode)302,
Keys.Scroll
},
{
(KeyCode)19,
Keys.Pause
}
};
public static Dictionary<KeyCode, string> KeyCodeToStringMap = new Dictionary<KeyCode, string>
{
{
(KeyCode)97,
"A"
},
{
(KeyCode)98,
"B"
},
{
(KeyCode)99,
"C"
},
{
(KeyCode)100,
"D"
},
{
(KeyCode)101,
"E"
},
{
(KeyCode)102,
"F"
},
{
(KeyCode)103,
"G"
},
{
(KeyCode)104,
"H"
},
{
(KeyCode)105,
"I"
},
{
(KeyCode)106,
"J"
},
{
(KeyCode)107,
"K"
},
{
(KeyCode)108,
"L"
},
{
(KeyCode)109,
"M"
},
{
(KeyCode)110,
"N"
},
{
(KeyCode)111,
"O"
},
{
(KeyCode)112,
"P"
},
{
(KeyCode)113,
"Q"
},
{
(KeyCode)114,
"R"
},
{
(KeyCode)115,
"S"
},
{
(KeyCode)116,
"T"
},
{
(KeyCode)117,
"U"
},
{
(KeyCode)118,
"V"
},
{
(KeyCode)119,
"W"
},
{
(KeyCode)120,
"X"
},
{
(KeyCode)121,
"Y"
},
{
(KeyCode)122,
"Z"
},
{
(KeyCode)48,
"0"
},
{
(KeyCode)49,
"1"
},
{
(KeyCode)50,
"2"
},
{
(KeyCode)51,
"3"
},
{
(KeyCode)52,
"4"
},
{
(KeyCode)53,
"5"
},
{
(KeyCode)54,
"6"
},
{
(KeyCode)55,
"7"
},
{
(KeyCode)56,
"8"
},
{
(KeyCode)57,
"9"
},
{
(KeyCode)282,
"F1"
},
{
(KeyCode)283,
"F2"
},
{
(KeyCode)284,
"F3"
},
{
(KeyCode)285,
"F4"
},
{
(KeyCode)286,
"F5"
},
{
(KeyCode)287,
"F6"
},
{
(KeyCode)288,
"F7"
},
{
(KeyCode)289,
"F8"
},
{
(KeyCode)290,
"F9"
},
{
(KeyCode)291,
"F10"
},
{
(KeyCode)292,
"F11"
},
{
(KeyCode)293,
"F12"
},
{
(KeyCode)306,
"Ctrl"
},
{
(KeyCode)305,
"Ctrl"
},
{
(KeyCode)304,
"Shift"
},
{
(KeyCode)303,
"Shift"
},
{
(KeyCode)308,
"Alt"
},
{
(KeyCode)307,
"Alt"
},
{
(KeyCode)32,
"Space"
},
{
(KeyCode)13,
"Enter"
},
{
(KeyCode)8,
"Backspace"
},
{
(KeyCode)27,
"Escape"
},
{
(KeyCode)9,
"Tab"
},
{
(KeyCode)301,
"CapsLock"
},
{
(KeyCode)127,
"Delete"
},
{
(KeyCode)277,
"Insert"
},
{
(KeyCode)278,
"Home"
},
{
(KeyCode)279,
"End"
},
{
(KeyCode)280,
"PageUp"
},
{
(KeyCode)281,
"PageDown"
},
{
(KeyCode)273,
"Up"
},
{
(KeyCode)274,
"Down"
},
{
(KeyCode)276,
"Left"
},
{
(KeyCode)275,
"Right"
},
{
(KeyCode)59,
";"
},
{
(KeyCode)47,
"/"
},
{
(KeyCode)92,
"\\"
},
{
(KeyCode)91,
"["
},
{
(KeyCode)93,
"]"
},
{
(KeyCode)39,
"'"
},
{
(KeyCode)96,
"`"
},
{
(KeyCode)45,
"-"
},
{
(KeyCode)61,
"="
},
{
(KeyCode)44,
","
},
{
(KeyCode)46,
"."
},
{
(KeyCode)256,
"Num0"
},
{
(KeyCode)257,
"Num1"
},
{
(KeyCode)258,
"Num2"
},
{
(KeyCode)259,
"Num3"
},
{
(KeyCode)260,
"Num4"
},
{
(KeyCode)261,
"Num5"
},
{
(KeyCode)262,
"Num6"
},
{
(KeyCode)263,
"Num7"
},
{
(KeyCode)264,
"Num8"
},
{
(KeyCode)265,
"Num9"
},
{
(KeyCode)267,
"Num/"
},
{
(KeyCode)268,
"Num*"
},
{
(KeyCode)269,
"Num-"
},
{
(KeyCode)270,
"Num+"
},
{
(KeyCode)271,
"NumEnter"
},
{
(KeyCode)266,
"Num."
},
{
(KeyCode)316,
"PrintScreen"
},
{
(KeyCode)302,
"Scroll"
},
{
(KeyCode)19,
"Pause"
}
};
public static Dictionary<Keys, KeyCode> KeysToKeyCodeMap = new Dictionary<Keys, KeyCode>
{
{
Keys.A,
(KeyCode)97
},
{
Keys.B,
(KeyCode)98
},
{
Keys.C,
(KeyCode)99
},
{
Keys.D,
(KeyCode)100
},
{
Keys.E,
(KeyCode)101
},
{
Keys.F,
(KeyCode)102
},
{
Keys.G,
(KeyCode)103
},
{
Keys.H,
(KeyCode)104
},
{
Keys.I,
(KeyCode)105
},
{
Keys.J,
(KeyCode)106
},
{
Keys.K,
(KeyCode)107
},
{
Keys.L,
(KeyCode)108
},
{
Keys.M,
(KeyCode)109
},
{
Keys.N,
(KeyCode)110
},
{
Keys.O,
(KeyCode)111
},
{
Keys.P,
(KeyCode)112
},
{
Keys.Q,
(KeyCode)113
},
{
Keys.R,
(KeyCode)114
},
{
Keys.S,
(KeyCode)115
},
{
Keys.T,
(KeyCode)116
},
{
Keys.U,
(KeyCode)117
},
{
Keys.V,
(KeyCode)118
},
{
Keys.W,
(KeyCode)119
},
{
Keys.X,
(KeyCode)120
},
{
Keys.Y,
(KeyCode)121
},
{
Keys.Z,
(KeyCode)122
},
{
Keys.D0,
(KeyCode)48
},
{
Keys.D1,
(KeyCode)49
},
{
Keys.D2,
(KeyCode)50
},
{
Keys.D3,
(KeyCode)51
},
{
Keys.D4,
(KeyCode)52
},
{
Keys.D5,
(KeyCode)53
},
{
Keys.D6,
(KeyCode)54
},
{
Keys.D7,
(KeyCode)55
},
{
Keys.D8,
(KeyCode)56
},
{
Keys.D9,
(KeyCode)57
},
{
Keys.F1,
(KeyCode)282
},
{
Keys.F2,
(KeyCode)283
},
{
Keys.F3,
(KeyCode)284
},
{
Keys.F4,
(KeyCode)285
},
{
Keys.F5,
(KeyCode)286
},
{
Keys.F6,
(KeyCode)287
},
{
Keys.F7,
(KeyCode)288
},
{
Keys.F8,
(KeyCode)289
},
{
Keys.F9,
(KeyCode)290
},
{
Keys.F10,
(KeyCode)291
},
{
Keys.F11,
(KeyCode)292
},
{
Keys.F12,
(KeyCode)293
},
{
Keys.Control,
(KeyCode)306
},
{
Keys.Shift,
(KeyCode)304
},
{
Keys.Alt,
(KeyCode)308
},
{
Keys.Space,
(KeyCode)32
},
{
Keys.Enter,
(KeyCode)13
},
{
Keys.Back,
(KeyCode)8
},
{
Keys.Escape,
(KeyCode)27
},
{
Keys.Tab,
(KeyCode)9
},
{
Keys.Capital,
(KeyCode)301
},
{
Keys.Delete,
(KeyCode)127
},
{
Keys.Insert,
(KeyCode)277
},
{
Keys.Home,
(KeyCode)278
},
{
Keys.End,
(KeyCode)279
},
{
Keys.PageUp,
(KeyCode)280
},
{
Keys.PageDown,
(KeyCode)281
},
{
Keys.Up,
(KeyCode)273
},
{
Keys.Down,
(KeyCode)274
},
{
Keys.Left,
(KeyCode)276
},
{
Keys.Right,
(KeyCode)275
},
{
Keys.OemSemicolon,
(KeyCode)59
},
{
Keys.OemQuestion,
(KeyCode)47
},
{
Keys.OemPipe,
(KeyCode)92
},
{
Keys.OemOpenBrackets,
(KeyCode)91
},
{
Keys.OemCloseBrackets,
(KeyCode)93
},
{
Keys.OemQuotes,
(KeyCode)39
},
{
Keys.Oemtilde,
(KeyCode)96
},
{
Keys.OemMinus,
(KeyCode)45
},
{
Keys.Oemplus,
(KeyCode)61
},
{
Keys.Oemcomma,
(KeyCode)44
},
{
Keys.OemPeriod,
(KeyCode)46
},
{
Keys.NumPad0,
(KeyCode)256
},
{
Keys.NumPad1,
(KeyCode)257
},
{
Keys.NumPad2,
(KeyCode)258
},
{
Keys.NumPad3,
(KeyCode)259
},
{
Keys.NumPad4,
(KeyCode)260
},
{
Keys.NumPad5,
(KeyCode)261
},
{
Keys.NumPad6,
(KeyCode)262
},
{
Keys.NumPad7,
(KeyCode)263
},
{
Keys.NumPad8,
(KeyCode)264
},
{
Keys.NumPad9,
(KeyCode)265
},
{
Keys.Divide,
(KeyCode)267
},
{
Keys.Multiply,
(KeyCode)268
},
{
Keys.Subtract,
(KeyCode)269
},
{
Keys.Add,
(KeyCode)270
},
{
Keys.Decimal,
(KeyCode)266
},
{
Keys.PrintScreen,
(KeyCode)316
},
{
Keys.Scroll,
(KeyCode)302
},
{
Keys.Pause,
(KeyCode)19
}
};
}
public class RawInputHandler : MonoBehaviour
{
public struct RAWINPUTHEADER
{
public uint dwType;
public uint dwSize;
public IntPtr hDevice;
public IntPtr wParam;
}
public struct RAWMOUSE
{
public ushort usFlags;
public ushort _;
public ushort usButtonFlags;
public short usButtonData;
public uint ulRawButtons;
public int lLastX;
public int lLastY;
public uint ulExtraInformation;
}
public struct RAWKEYBOARD
{
public ushort MakeCode;
public ushort Flags;
public ushort Reserved;
public ushort VKey;
public uint Message;
public uint ExtraInformation;
}
public struct RAWINPUTDEVICE
{
public ushort usUsagePage;
public ushort usUsage;
public uint dwFlags;
public IntPtr hwndTarget;
}
private struct WNDCLASS
{
public uint style;
public WNDPROC lpfn;
public int cbClsExtra;
public int cbWndExtra;
public IntPtr hInstance;
public IntPtr hIcon;
public IntPtr hCursor;
public IntPtr hbrBackground;
public IntPtr lpszMenuName;
public string lpszClassName;
}
private delegate IntPtr WNDPROC(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
public class SmoothWheel
{
private float smoothScrollValue = 0f;
private float gravity = 15f;
private float sensitivity = 15f;
public SmoothWheel(float gravity = 15f, float sensitivity = 15f)
{
this.gravity = gravity;
this.sensitivity = sensitivity;
}
public float GetSmoothWheelValue(float rawScrollValue)
{
if (Mathf.Abs(rawScrollValue) > 10f)
{
smoothScrollValue = Mathf.Lerp(smoothScrollValue, rawScrollValue, Time.unscaledDeltaTime * sensitivity);
}
else
{
smoothScrollValue = Mathf.Lerp(smoothScrollValue, 0f, Time.unscaledDeltaTime * gravity);
}
if (Mathf.Abs(smoothScrollValue) < 3f)
{
smoothScrollValue = 0f;
}
smoothScrollValue = Mathf.Clamp(smoothScrollValue / 120f, -1f, 1f);
return smoothScrollValue;
}
}
public struct MouseStatus
{
public bool leftButtonDown;
public bool leftButtonUp;
public bool leftButton;
public bool rightButtonDown;
public bool rightButtonUp;
public bool rightButton;
public bool middleButtonDown;
public bool middleButtonUp;
public bool middleButton;
public int rawX;
public int rawY;
public int wheel;
}
private const int WM_INPUT = 255;
private const int RIM_INPUT = 268435459;
private const int RIDEV_INPUTSINK = 256;
private const uint MOD_CONTROL = 2u;
private const uint MOD_SHIFT = 4u;
private const uint MOD_ALT = 1u;
private const uint WS_POPUP = 2147483648u;
private const uint WS_EX_TOOLWINDOW = 128u;
private const uint WM_DESTROY = 2u;
private const uint WM_ShortcutKey = 786u;
private const int SW_HIDE = 0;
private static IntPtr _windowHandle;
private static WNDPROC _windowProc;
private static IntPtr rawBuffer;
public static HashSet<KeyCode> firstKeyboardCurrentFrameKeysDown = new HashSet<KeyCode>();
public static HashSet<KeyCode> firstKeyboardPressedKeys = new HashSet<KeyCode>();
public static HashSet<KeyCode> firstKeyboardCurrentFrameKeysUp = new HashSet<KeyCode>();
public static HashSet<KeyCode> secondKeyboardCurrentFrameKeysDown = new HashSet<KeyCode>();
public static HashSet<KeyCode> secondKeyboardPressedKeys = new HashSet<KeyCode>();
public static HashSet<KeyCode> secondKeyboardCurrentFrameKeysUp = new HashSet<KeyCode>();
public static Vector2 firstMousePosition;
public static Vector2 secondMousePosition;
private static IntPtr firstKeyboardDevice = IntPtr.Zero;
private static IntPtr firstMouseDevice = IntPtr.Zero;
public static GungeonActions firstKeyboardActionSet;
public static GungeonActions firstMouseActionSet;
public static float playerOneMouseSensitivity = 2f;
public static float playerTwoMouseSensitivity = 2f;
public static string shortcutKeyString = "Alt + Shift + X";
private const int shortcutKeyId = 101;
public static bool temporarilyEnableSystemMouse = true;
public bool lastInputIsMouse = false;
public bool lastInputIsKeyboard = false;
private static Camera mainCamera;
public static float playerOneMouseSensitivityMultiplier = 1f;
public static float playerTwoMouseSensitivityMultiplier = 1f;
public static bool mousePortReady = false;
public static SmoothWheel firstMouseSmoothWheel = new SmoothWheel();
public static SmoothWheel secondMouseSmoothWheel = new SmoothWheel();
public static MouseStatus firstMouseStatus;
public static MouseStatus secondMouseStatus;
private static Camera MainCamera
{
get
{
if ((Object)(object)mainCamera == (Object)null)
{
mainCamera = Camera.main;
}
return mainCamera;
}
}
public static bool ShowTwoMouseCursor
{
get
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Invalid comparison between Unknown and I4
if (GameCursorController.CursorOverride.Value)
{
return false;
}
if (GameManager.Instance.IsLoadingLevel)
{
return false;
}
if (GameManager.IsReturningToBreach)
{
return false;
}
if (GameManager.Instance.IsPaused)
{
return false;
}
if (Minimap.Instance.IsFullscreen)
{
return false;
}
if ((int)GameManager.Instance.CurrentGameType == 1)
{
if (CoopKBnMModule.restrictMouseInputPort)
{
return true;
}
return false;
}
return false;
}
}
public static bool ShowPublicCursor
{
get
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Invalid comparison between Unknown and I4
if (!GameCursorController.showMouseCursor)
{
return false;
}
if ((int)GameManager.Instance.CurrentGameType == 1 && GameManager.Instance.IsPaused)
{
return true;
}
return false;
}
}
[DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
[DllImport("user32.dll")]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr CreateWindowEx(uint dwExStyle, string lpClassName, string lpWindowName, uint dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool DestroyWindow(IntPtr hWnd);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool RegisterClass(ref WNDCLASS lpWndClass);
[DllImport("user32.dll")]
private static extern IntPtr DefWindowProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool RegisterRawInputDevices(RAWINPUTDEVICE[] pRawInputDevice, uint uiNumDevices, uint cbSize);
[DllImport("user32.dll")]
private static extern int GetRawInputData(IntPtr hRawInput, uint uiCommand, IntPtr pData, ref uint pDataSize, uint cbSizeHeader);
[DllImport("user32.dll")]
private static extern bool SetCursorPos(int X, int Y);
private void Start()
{
//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)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
ETGModMainBehaviour.WaitForGameManagerStart((Action<GameManager>)GMStart);
firstMousePosition = new Vector2((float)(Screen.width / 2), (float)(Screen.height / 2));
secondMousePosition = new Vector2((float)(Screen.width / 2), (float)(Screen.height / 2));
}
private IEnumerator InitializeRawInput()
{
yield return null;
yield return null;
yield return null;
InitializeMessageHandler();
SetGlobalShortcutKey();
}
public void GMStart(GameManager g)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Invalid comparison between Unknown and I4
if (GameManager.Options != null && (int)GameManager.Options.CurrentPreferredFullscreenMode == 0)
{
GameManager.Options.CurrentPreferredFullscreenMode = (PreferredFullscreenMode)1;
BraveOptionsMenuItem.HandleScreenDataChanged(Screen.width, Screen.height);
}
((MonoBehaviour)this).StartCoroutine(InitializeRawInput());
}
private void OnApplicationQuit()
{
UnregisterHotKey(_windowHandle, 101);
ReleaseMessageHandler();
}
private void LateUpdate()
{
firstKeyboardCurrentFrameKeysDown.Clear();
secondKeyboardCurrentFrameKeysDown.Clear();
firstKeyboardCurrentFrameKeysUp.Clear();
secondKeyboardCurrentFrameKeysUp.Clear();
firstMouseStatus.leftButtonDown = false;
firstMouseStatus.leftButtonUp = false;
firstMouseStatus.rightButtonDown = false;
firstMouseStatus.rightButtonUp = false;
firstMouseStatus.middleButtonDown = false;
firstMouseStatus.middleButtonUp = false;
firstMouseStatus.wheel = 0;
firstMouseStatus.rawX = 0;
firstMouseStatus.rawY = 0;
secondMouseStatus.leftButtonDown = false;
secondMouseStatus.leftButtonUp = false;
secondMouseStatus.rightButtonDown = false;
secondMouseStatus.rightButtonUp = false;
secondMouseStatus.middleButtonDown = false;
secondMouseStatus.middleButtonUp = false;
secondMouseStatus.wheel = 0;
secondMouseStatus.rawX = 0;
secondMouseStatus.rawY = 0;
if (!Application.isFocused)
{
firstKeyboardPressedKeys.Clear();
secondKeyboardPressedKeys.Clear();
firstMouseStatus.leftButton = false;
firstMouseStatus.rightButton = false;
firstMouseStatus.middleButton = false;
secondMouseStatus.leftButton = false;
secondMouseStatus.rightButton = false;
secondMouseStatus.middleButton = false;
temporarilyEnableSystemMouse = true;
Cursor.lockState = (CursorLockMode)0;
}
else if (Input.anyKeyDown)
{
temporarilyEnableSystemMouse = false;
}
if (Input.GetKeyDown((KeyCode)311) || Input.GetKeyDown((KeyCode)312))
{
temporarilyEnableSystemMouse = true;
}
if (!temporarilyEnableSystemMouse && GameManager.HasInstance)
{
Cursor.lockState = (CursorLockMode)1;
return;
}
Cursor.lockState = (CursorLockMode)0;
Cursor.visible = true;
}
private static void RegisterDevices()
{
RAWINPUTDEVICE[] array = new RAWINPUTDEVICE[4];
array[0].usUsagePage = 1;
array[0].usUsage = 2;
array[0].dwFlags = 0u;
array[0].hwndTarget = _windowHandle;
array[1].usUsagePage = 1;
array[1].usUsage = 2;
array[1].dwFlags = 0u;
array[1].hwndTarget = _windowHandle;
array[2].usUsagePage = 1;
array[2].usUsage = 6;
array[2].dwFlags = 0u;
array[2].hwndTarget = _windowHandle;
array[3].usUsagePage = 1;
array[3].usUsage = 6;
array[3].dwFlags = 0u;
array[3].hwndTarget = _windowHandle;
if (!RegisterRawInputDevices(array, (uint)array.Length, (uint)Marshal.SizeOf(typeof(RAWINPUTDEVICE))))
{
Console.WriteLine("Failed to register raw input devices.");
}
}
public static void InitializeMessageHandler()
{
rawBuffer = Marshal.AllocHGlobal(64);
_windowProc = WindowProc;
WNDCLASS wNDCLASS = default(WNDCLASS);
wNDCLASS.style = 0u;
wNDCLASS.lpfn = _windowProc;
wNDCLASS.lpszClassName = "RawInputWindowClass";
wNDCLASS.hInstance = GetModuleHandle(null);
WNDCLASS lpWndClass = wNDCLASS;
RegisterClass(ref lpWndClass);
_windowHandle = CreateWindowEx(128u, "RawInputWindowClass", "RawInputWindow", 2147483648u, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, GetModuleHandle(null), IntPtr.Zero);
if (_windowHandle != IntPtr.Zero)
{
ShowWindow(_windowHandle, 0);
}
if (_windowHandle == IntPtr.Zero)
{
ETGModConsole.Log((object)"Failed to create raw input window.", false);
}
RegisterDevices();
}
public static void ReleaseMessageHandler()
{
if (_windowHandle != IntPtr.Zero)
{
DestroyWindow(_windowHandle);
}
Marshal.FreeHGlobal(rawBuffer);
}
private static IntPtr WindowProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
{
switch (msg)
{
case 2u:
return IntPtr.Zero;
case 786u:
{
int num = wParam.ToInt32();
HandleShortcutKeyPressed(num);
return IntPtr.Zero;
}
case 255u:
ProcessRawInput(lParam);
return DefWindowProc(hWnd, msg, wParam, lParam);
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
}
public static void SetGlobalShortcutKey()
{
uint fsModifiers = 5u;
uint vk = 88u;
if (!RegisterHotKey(_windowHandle, 101, fsModifiers, vk))
{
ETGModConsole.Log((object)("Failed to register shortcut key " + shortcutKeyString + "."), false);
shortcutKeyString = "None";
}
}
private static void HandleShortcutKeyPressed(int shortcutKeyId)
{
if (shortcutKeyId == 101)
{
temporarilyEnableSystemMouse = true;
}
}
private static void ProcessRawInput(IntPtr lParam)
{
//IL_08b3: Unknown result type (might be due to invalid IL or missing references)
//IL_087e: Unknown result type (might be due to invalid IL or missing references)
//IL_0930: Unknown result type (might be due to invalid IL or missing references)
//IL_093d: Unknown result type (might be due to invalid IL or missing references)
//IL_0912: Unknown result type (might be due to invalid IL or missing references)
//IL_091f: Unknown result type (might be due to invalid IL or missing references)
//IL_08c9: Unknown result type (might be due to invalid IL or missing references)
//IL_08d6: Unknown result type (might be due to invalid IL or missing references)
//IL_0894: Unknown result type (might be due to invalid IL or missing references)
//IL_08a1: Unknown result type (might be due to invalid IL or missing references)
//IL_0279: Unknown result type (might be due to invalid IL or missing references)
//IL_027e: Unknown result type (might be due to invalid IL or missing references)
//IL_0239: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
//IL_04db: Unknown result type (might be due to invalid IL or missing references)
//IL_0496: Unknown result type (might be due to invalid IL or missing references)
//IL_049b: Unknown result type (might be due to invalid IL or missing references)
//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
//IL_0380: Unknown result type (might be due to invalid IL or missing references)
//IL_0385: Unknown result type (might be due to invalid IL or missing references)
//IL_077f: Unknown result type (might be due to invalid IL or missing references)
//IL_078f: Unknown result type (might be due to invalid IL or missing references)
//IL_079f: Unknown result type (might be due to invalid IL or missing references)
uint pDataSize = 0u;
if (GetRawInputData(lParam, 268435459u, IntPtr.Zero, ref pDataSize, (uint)Marshal.SizeOf(typeof(RAWINPUTHEADER))) != 0)
{
Console.WriteLine("Failed to get input data size.");
}
else
{
if (pDataSize > 64)
{
return;
}
if (GetRawInputData(lParam, 268435459u, rawBuffer, ref pDataSize, (uint)Marshal.SizeOf(typeof(RAWINPUTHEADER))) != pDataSize)
{
Console.WriteLine("GetRawInputData does not return correct size.");
return;
}
RAWINPUTHEADER rAWINPUTHEADER = (RAWINPUTHEADER)Marshal.PtrToStructure(rawBuffer, typeof(RAWINPUTHEADER));
if (rAWINPUTHEADER.dwType == 0)
{
IntPtr ptr = new IntPtr(rawBuffer.ToInt64() + Marshal.SizeOf(typeof(RAWINPUTHEADER)));
RAWMOUSE rAWMOUSE = (RAWMOUSE)Marshal.PtrToStructure(ptr, typeof(RAWMOUSE));
if (firstMouseDevice == IntPtr.Zero)
{
firstMouseDevice = rAWINPUTHEADER.hDevice;
}
if (rAWMOUSE.lLastX != 0 || rAWMOUSE.lLastY != 0)
{
if (rAWINPUTHEADER.hDevice == firstMouseDevice)
{
firstMouseStatus.rawX = rAWMOUSE.lLastX;
firstMouseStatus.rawY = rAWMOUSE.lLastY;
firstMousePosition.x += (float)firstMouseStatus.rawX * playerOneMouseSensitivity * playerOneMouseSensitivityMultiplier;
firstMousePosition.y -= (float)firstMouseStatus.rawY * playerOneMouseSensitivity * playerOneMouseSensitivityMultiplier;
if ((Object)(object)MainCamera != (Object)null)
{
firstMousePosition = new Vector2(Mathf.Clamp(firstMousePosition.x, (float)((Screen.width - MainCamera.pixelWidth) / 2), (float)((Screen.width + MainCamera.pixelWidth) / 2)), Mathf.Clamp(firstMousePosition.y, (float)((Screen.height - MainCamera.pixelHeight) / 2), (float)((Screen.height + MainCamera.pixelHeight) / 2)));
}
else
{
firstMousePosition = new Vector2(Mathf.Clamp(firstMousePosition.x, 0f, (float)Screen.width), Mathf.Clamp(firstMousePosition.y, 0f, (float)Screen.height));
}
}
else
{
secondMouseStatus.rawX = rAWMOUSE.lLastX;
secondMouseStatus.rawY = rAWMOUSE.lLastY;
if (ShowTwoMouseCursor)
{
secondMousePosition.x += (float)secondMouseStatus.rawX * playerTwoMouseSensitivity * playerTwoMouseSensitivityMultiplier;
secondMousePosition.y -= (float)secondMouseStatus.rawY * playerTwoMouseSensitivity * playerTwoMouseSensitivityMultiplier;
if ((Object)(object)MainCamera != (Object)null)
{
secondMousePosition = new Vector2(Mathf.Clamp(secondMousePosition.x, (float)((Screen.width - MainCamera.pixelWidth) / 2), (float)((Screen.width + MainCamera.pixelWidth) / 2)), Mathf.Clamp(secondMousePosition.y, (float)((Screen.height - MainCamera.pixelHeight) / 2), (float)((Screen.height + MainCamera.pixelHeight) / 2)));
}
else
{
secondMousePosition = new Vector2(Mathf.Clamp(secondMousePosition.x, 0f, (float)Screen.width), Mathf.Clamp(secondMousePosition.y, 0f, (float)Screen.height));
}
}
else
{
firstMousePosition.x += (float)secondMouseStatus.rawX * playerTwoMouseSensitivity * playerOneMouseSensitivityMultiplier;
firstMousePosition.y -= (float)secondMouseStatus.rawY * playerTwoMouseSensitivity * playerOneMouseSensitivityMultiplier;
if ((Object)(object)MainCamera != (Object)null)
{
firstMousePosition = new Vector2(Mathf.Clamp(firstMousePosition.x, (float)((Screen.width - MainCamera.pixelWidth) / 2), (float)((Screen.width + MainCamera.pixelWidth) / 2)), Mathf.Clamp(firstMousePosition.y, (float)((Screen.height - MainCamera.pixelHeight) / 2), (float)((Screen.height + MainCamera.pixelHeight) / 2)));
}
else
{
firstMousePosition = new Vector2(Mathf.Clamp(firstMousePosition.x, 0f, (float)Screen.width), Mathf.Clamp(firstMousePosition.y, 0f, (float)Screen.height));
}
}
}
}
if (((uint)rAWMOUSE.usButtonFlags & (true ? 1u : 0u)) != 0)
{
if (rAWINPUTHEADER.hDevice == firstMouseDevice)
{
firstMouseStatus.leftButtonDown = true;
firstMouseStatus.leftButton = true;
}
else
{
secondMouseStatus.leftButtonDown = true;
secondMouseStatus.leftButton = true;
}
}
if ((rAWMOUSE.usButtonFlags & 2u) != 0)
{
if (rAWINPUTHEADER.hDevice == firstMouseDevice)
{
firstMouseStatus.leftButtonUp = true;
firstMouseStatus.leftButton = false;
}
else
{
secondMouseStatus.leftButtonUp = true;
secondMouseStatus.leftButton = false;
}
}
if ((rAWMOUSE.usButtonFlags & 4u) != 0)
{
if (rAWINPUTHEADER.hDevice == firstMouseDevice)
{
firstMouseStatus.rightButtonDown = true;
firstMouseStatus.rightButton = true;
}
else
{
secondMouseStatus.rightButtonDown = true;
secondMouseStatus.rightButton = true;
}
}
if ((rAWMOUSE.usButtonFlags & 8u) != 0)
{
if (rAWINPUTHEADER.hDevice == firstMouseDevice)
{
firstMouseStatus.rightButtonUp = true;
firstMouseStatus.rightButton = false;
}
else
{
secondMouseStatus.rightButtonUp = true;
secondMouseStatus.rightButton = false;
}
}
if ((rAWMOUSE.usButtonFlags & 0x10u) != 0)
{
if (rAWINPUTHEADER.hDevice == firstMouseDevice)
{
firstMouseStatus.middleButtonDown = true;
firstMouseStatus.middleButton = true;
}
else
{
secondMouseStatus.middleButtonDown = true;
secondMouseStatus.middleButton = true;
}
}
if ((rAWMOUSE.usButtonFlags & 0x20u) != 0)
{
if (rAWINPUTHEADER.hDevice == firstMouseDevice)
{
firstMouseStatus.middleButtonUp = true;
firstMouseStatus.middleButton = false;
}
else
{
secondMouseStatus.middleButtonUp = true;
secondMouseStatus.middleButton = false;
}
}
if ((rAWMOUSE.usButtonFlags & 0x400u) != 0)
{
if (rAWINPUTHEADER.hDevice == firstMouseDevice)
{
firstMouseStatus.wheel = rAWMOUSE.usButtonData;
}
else
{
secondMouseStatus.wheel = rAWMOUSE.usButtonData;
}
if (!ShowTwoMouseCursor)
{
((PlayerActionSet)BraveInput.PrimaryPlayerInstance.ActiveActions).LastInputType = (BindingSourceType)3;
((PlayerActionSet)BraveInput.PrimaryPlayerInstance.ActiveActions).LastDeviceClass = (InputDeviceClass)2;
((PlayerActionSet)BraveInput.PrimaryPlayerInstance.ActiveActions).LastDeviceStyle = (InputDeviceStyle)0;
((PlayerActionSet)BraveInput.PrimaryPlayerInstance.ActiveActions).LastInputTypeChangedTick = InputManager.currentTick;
}
}
}
else
{
if (rAWINPUTHEADER.dwType != 1)
{
return;
}
IntPtr ptr2 = new IntPtr(rawBuffer.ToInt64() + Marshal.SizeOf(typeof(RAWINPUTHEADER)));
RAWKEYBOARD rAWKEYBOARD = (RAWKEYBOARD)Marshal.PtrToStructure(ptr2, typeof(RAWKEYBOARD));
if (firstKeyboardDevice == IntPtr.Zero)
{
firstKeyboardDevice = rAWINPUTHEADER.hDevice;
}
if (!KeyCodeMaps.KeysToKeyCodeMap.TryGetValue((KeyCodeMaps.Keys)rAWKEYBOARD.VKey, out var value))
{
return;
}
if ((rAWKEYBOARD.Flags & 1) == 0)
{
if (rAWINPUTHEADER.hDevice == firstKeyboardDevice)
{
if (!firstKeyboardPressedKeys.Contains(value))
{
firstKeyboardCurrentFrameKeysDown.Add(value);
firstKeyboardPressedKeys.Add(value);
}
}
else if (!secondKeyboardPressedKeys.Contains(value))
{
secondKeyboardCurrentFrameKeysDown.Add(value);
secondKeyboardPressedKeys.Add(value);
}
}
else if ((rAWKEYBOARD.Flags & 1) == 1)
{
if (rAWINPUTHEADER.hDevice == firstKeyboardDevice)
{
firstKeyboardPressedKeys.Remove(value);
firstKeyboardCurrentFrameKeysUp.Add(value);
}
else
{
secondKeyboardPressedKeys.Remove(value);
secondKeyboardCurrentFrameKeysUp.Add(value);
}
}
}
}
}
public static bool GetKey(KeyCode key, bool isFirstKeyboard)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
if (isFirstKeyboard)
{
return firstKeyboardPressedKeys.Contains(key);
}
return secondKeyboardPressedKeys.Contains(key);
}
public static bool GetIsPressed(KeyInfo self, bool isFirstKeyboard)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
int num = self.keyCodes.Length;
for (int i = 0; i < num; i++)
{
if (GetKey(self.keyCodes[i], isFirstKeyboard))
{
return true;
}
}
return false;
}
public static bool GetIsPressed(KeyCombo self, bool isFirstKeyboard)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
if (self.includeSize == 0)
{
return false;
}
bool flag = true;
for (int i = 0; i < self.includeSize; i++)
{
int includeInt = ((KeyCombo)(ref self)).GetIncludeInt(i);
flag = flag && GetIsPressed(KeyInfo.KeyList[includeInt], isFirstKeyboard);
}
for (int j = 0; j < self.excludeSize; j++)
{
int excludeInt = ((KeyCombo)(ref self)).GetExcludeInt(j);
if (((KeyInfo)(ref KeyInfo.KeyList[excludeInt])).IsPressed)
{
return false;
}
}
return flag;
}
public static bool GetState(KeyBindingSource self, InputDevice inputDevice, bool isFirstKeyboard)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return GetIsPressed(self.Control, isFirstKeyboard);
}
public static float GetValue(KeyBindingSource self, InputDevice inputDevice, bool isFirstKeyboard)
{
return (!GetState(self, inputDevice, isFirstKeyboard)) ? 0f : 1f;
}
public static bool IsFirstKeyboard(PlayerAction action)
{
return action.Owner == firstKeyboardActionSet;
}
public static void RemoveDuplicateBindings()
{
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Invalid comparison between Unknown and I4
if (!CoopKBnMModule.isShareOneKeyboardMode || BraveInput.m_instances.Count <= 1)
{
return;
}
foreach (PlayerAction action in ((PlayerActionSet)BraveInput.GetInstanceForPlayer(0).ActiveActions).Actions)
{
foreach (BindingSource binding in action.Bindings)
{
if (((PlayerActionSet)BraveInput.GetInstanceForPlayer(1).ActiveActions).HasBinding(binding) && (int)binding.DeviceClass == 1)
{
int count = ((PlayerActionSet)BraveInput.GetInstanceForPlayer(1).ActiveActions).Actions.Count;
for (int i = 0; i < count; i++)
{
((PlayerActionSet)BraveInput.GetInstanceForPlayer(1).ActiveActions).Actions[i].HardRemoveBinding(binding);
}
}
}
}
}
public static float GetValue(MouseBindingSource self, InputDevice inputDevice, bool isFirstMouse)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: 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_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Expected I4, but got Unknown
int num = MouseBindingSource.buttonTable[self.Control];
if (num >= 0)
{
return (!GetMouseButton(num, isFirstMouse)) ? 0f : 1f;
}
Mouse control = self.Control;
Mouse val = control;
return (val - 4) switch
{
0 => 0f - Mathf.Min((float)GetRawX(isFirstMouse) * MouseBindingSource.ScaleX, 0f),
1 => Mathf.Max(0f, (float)GetRawX(isFirstMouse) * MouseBindingSource.ScaleX),
2 => 0f - Mathf.Min((float)GetRawY(isFirstMouse) * MouseBindingSource.ScaleY, 0f),
3 => Mathf.Max(0f, (float)GetRawY(isFirstMouse) * MouseBindingSource.ScaleY),
4 => Mathf.Max(0f, (float)GetWheel(isFirstMouse) * MouseBindingSource.ScaleZ),
5 => 0f - Mathf.Min((float)GetWheel(isFirstMouse) * MouseBindingSource.ScaleZ, 0f),
_ => 0f,
};
}
private static bool GetMouseButton(int button, bool isFirstMouse)
{
if (isFirstMouse)
{
return button switch
{
0 => firstMouseStatus.leftButton,
1 => firstMouseStatus.rightButton,
2 => firstMouseStatus.middleButton,
_ => false,
};
}
return button switch
{
0 => secondMouseStatus.leftButton,
1 => secondMouseStatus.rightButton,
2 => secondMouseStatus.middleButton,
_ => false,
};
}
private static int GetRawX(bool isFirstMouse)
{
if (isFirstMouse)
{
return firstMouseStatus.rawX;
}
return secondMouseStatus.rawX;
}
private static int GetRawY(bool isFirstMouse)
{
if (isFirstMouse)
{
return firstMouseStatus.rawY;
}
return secondMouseStatus.rawY;
}
private static int GetWheel(bool isFirstMouse)
{
if (isFirstMouse)
{
return firstMouseStatus.wheel;
}
return secondMouseStatus.wheel;
}
public static bool IsFirstMouse(PlayerAction action)
{
return action.Owner == firstMouseActionSet;
}
public static int GetPublicWheel()
{
if (firstMouseStatus.wheel != 0)
{
return firstMouseStatus.wheel;
}
if (secondMouseStatus.wheel != 0)
{
return secondMouseStatus.wheel;
}
return 0;
}
public static float GetPublicSmoothWheelValue()
{
if (firstMouseStatus.wheel != 0)
{
return firstMouseSmoothWheel.GetSmoothWheelValue(firstMouseStatus.wheel);
}
if (secondMouseStatus.wheel != 0)
{
return secondMouseSmoothWheel.GetSmoothWheelValue(secondMouseStatus.wheel);
}
return 0f;
}
}