using System;
using System.Collections.Generic;
using Rewired;
using UnityEngine;
namespace RoR2;
public static class DefaultControllerMaps
{
public delegate void LogFormatFunction(string inFormat, params object[] inParams);
public const string defaultKeyboardMapString = "00000000000-0000-0000-0000-000000000000false001-10false0100000true001-10false197000true011-10false0119000true011-10false1115000true041-10false032000true0181-10false0306000true051-10false0101000true061-10false0113000true091-10false0304000true0101-10false0114000true0191-10false09000true";
public const string defaultMouseMapString = "00000000000-0000-0000-0000-000000000000false07130false00000true08140false00000true028150false00000true02000false00000true03010false00000true";
public static readonly Guid gamepadTemplateGuid = new Guid("83b427e4-086f-47f3-bb06-be266abd1ca5");
public static readonly Guid xboneControllerGuid = new Guid("19002688-7406-4f4a-8340-8d25335406c8");
public static readonly Guid xbox360ControllerGuid = new Guid("d74a350e-fe8b-4e9e-bbcd-efff16d34115");
public static readonly Guid switchDualGuid = new Guid("521b808c-0248-4526-bc10-f1d16ee76bf1");
public static readonly Guid switchHandheldGuid = new Guid("1fbdd13b-0795-4173-8a95-a2a75de9d204");
public static readonly Guid switchProGuid = new Guid("7bf3154b-9db8-4d52-950f-cd0eed8a5819");
public static readonly Guid PS4Guid = new Guid("cd9718bf-a87a-44bc-8716-60a0def28a9f");
public static readonly Guid PS5Guid = new Guid("5286706d-19b4-4a45-b635-207ce78d8394");
public static readonly string xbox360ControllerName = "Xbox 360 Controller";
public static readonly string xboxOneControllerName = "Xbox One Controller";
public static readonly string dualshock4ControllerName = "Sony DualShock 4";
public static readonly string dualshock4ControllerNameAlt = "PlayStation Controller";
public static readonly string dualSenseController = "Sony DualSense";
public static readonly string switchControllerName = "Nintendo Controller";
public static readonly string switchProControllerName = "Nintendo Switch Pro Controller";
public static readonly string switchProControllerNameAlt = "Pro Controller";
public static readonly string stadiaControllerName = "Stadia Controller";
public static readonly KeyboardMap defaultKeyboardMap = (KeyboardMap)ControllerMap.CreateFromXml(ControllerType.Keyboard, "00000000000-0000-0000-0000-000000000000false001-10false0100000true001-10false197000true011-10false0119000true011-10false1115000true041-10false032000true0181-10false0306000true051-10false0101000true061-10false0113000true091-10false0304000true0101-10false0114000true0191-10false09000true");
public static readonly MouseMap defaultMouseMap = (MouseMap)ControllerMap.CreateFromXml(ControllerType.Mouse, "00000000000-0000-0000-0000-000000000000false07130false00000true08140false00000true028150false00000true02000false00000true03010false00000true");
private static Dictionary _DefaultJoystickMaps_Xml = new Dictionary();
private static bool _FilledDefaultJoystickMaps = false;
public static JoystickMap DefaultJoystickMap
{
get
{
FillDefaultJoystickMaps();
if (_DefaultJoystickMaps_Xml.ContainsKey(PlatformManager.DefaultControllerGuid))
{
string xmlString = _DefaultJoystickMaps_Xml[PlatformManager.DefaultControllerGuid];
return ControllerMap.CreateFromXml(ControllerType.Joystick, xmlString) as JoystickMap;
}
return null;
}
}
public static bool RewiredLoggingEnabled()
{
return false;
}
public static void RewiredLogLineForce(LogFormatFunction inLogFcn, string inFormat, params object[] inParams)
{
if (inParams != null && inParams.Length != 0)
{
inLogFcn(inFormat, inParams);
}
else
{
inLogFcn(inFormat);
}
}
public static void RewiredLogLine(LogFormatFunction inLogFcn, string inFormat, params object[] inParams)
{
}
public static void RewiredDebugLog(string inFormat, params object[] inParams)
{
RewiredLogLine(Debug.LogFormat, inFormat, inParams);
}
public static void RewiredDebugWarn(string inFormat, params object[] inParams)
{
RewiredLogLine(Debug.LogWarningFormat, inFormat, inParams);
}
public static void RewiredDebugError(string inFormat, params object[] inParams)
{
RewiredLogLineForce(Debug.LogErrorFormat, inFormat, inParams);
}
public static void RewiredDebugLogForce(string inFormat, params object[] inParams)
{
RewiredLogLineForce(Debug.LogFormat, inFormat, inParams);
}
public static void RewiredDebugWarnForce(string inFormat, params object[] inParams)
{
RewiredLogLineForce(Debug.LogWarningFormat, inFormat, inParams);
}
private static void FillDefaultJoystickMaps()
{
if (_FilledDefaultJoystickMaps)
{
return;
}
RewiredDebugLog("FillDefaultJoysticksMap");
if (ReInput.mapping != null)
{
JoystickMap joystickMapInstance = ReInput.mapping.GetJoystickMapInstance(gamepadTemplateGuid, 0, 0);
JoystickMap joystickMapInstance2 = ReInput.mapping.GetJoystickMapInstance(xboneControllerGuid, 0, 0);
JoystickMap joystickMapInstance3 = ReInput.mapping.GetJoystickMapInstance(xbox360ControllerGuid, 0, 0);
JoystickMap joystickMapInstance4 = ReInput.mapping.GetJoystickMapInstance(PS4Guid, 0, 0);
JoystickMap joystickMapInstance5 = ReInput.mapping.GetJoystickMapInstance(PS5Guid, 0, 0);
JoystickMap joystickMapInstance6 = ReInput.mapping.GetJoystickMapInstance(switchProGuid, 0, 0);
JoystickMap joystickMapInstance7 = ReInput.mapping.GetJoystickMapInstance(switchDualGuid, 0, 0);
JoystickMap joystickMapInstance8 = ReInput.mapping.GetJoystickMapInstance(switchHandheldGuid, 0, 0);
string value = joystickMapInstance.ToXmlString();
string value2 = joystickMapInstance2.ToXmlString();
string value3 = joystickMapInstance3.ToXmlString();
string value4 = joystickMapInstance4.ToXmlString();
string value5 = joystickMapInstance5.ToXmlString();
string value6 = joystickMapInstance6.ToXmlString();
string value7 = joystickMapInstance7.ToXmlString();
string value8 = joystickMapInstance8.ToXmlString();
_DefaultJoystickMaps_Xml.Add(gamepadTemplateGuid, value);
if (joystickMapInstance2.buttonMapCount > 0)
{
_DefaultJoystickMaps_Xml.Add(xboneControllerGuid, value2);
}
_DefaultJoystickMaps_Xml.Add(xbox360ControllerGuid, value3);
_DefaultJoystickMaps_Xml.Add(PS4Guid, value4);
_DefaultJoystickMaps_Xml.Add(PS5Guid, value5);
_DefaultJoystickMaps_Xml.Add(switchProGuid, value6);
_DefaultJoystickMaps_Xml.Add(switchDualGuid, value7);
_DefaultJoystickMaps_Xml.Add(switchHandheldGuid, value8);
_FilledDefaultJoystickMaps = true;
}
}
public static Dictionary GetDefaultJoystickMaps()
{
FillDefaultJoystickMaps();
Dictionary dictionary = new Dictionary();
foreach (KeyValuePair item in _DefaultJoystickMaps_Xml)
{
JoystickMap value = ControllerMap.CreateFromXml(ControllerType.Joystick, item.Value) as JoystickMap;
dictionary.Add(item.Key, value);
}
return dictionary;
}
public static KeyboardMap GetDefaultKeyboardMap()
{
return ControllerMap.CreateFromXml(ControllerType.Keyboard, "00000000000-0000-0000-0000-000000000000false001-10false0100000true001-10false197000true011-10false0119000true011-10false1115000true041-10false032000true0181-10false0306000true051-10false0101000true061-10false0113000true091-10false0304000true0101-10false0114000true0191-10false09000true") as KeyboardMap;
}
public static MouseMap GetDefaultMoustMap()
{
return ControllerMap.CreateFromXml(ControllerType.Mouse, "00000000000-0000-0000-0000-000000000000false07130false00000true08140false00000true028150false00000true02000false00000true03010false00000true") as MouseMap;
}
public static JoystickMap GetDefaultJoystickMap(Guid inControllerGuid)
{
FillDefaultJoystickMaps();
if (_DefaultJoystickMaps_Xml.ContainsKey(inControllerGuid))
{
string xmlString = _DefaultJoystickMaps_Xml[inControllerGuid];
return ControllerMap.CreateFromXml(ControllerType.Joystick, xmlString) as JoystickMap;
}
RewiredDebugWarn($"GetDefaultControllerMap: Failed to find guid {inControllerGuid}...");
if (inControllerGuid == xboneControllerGuid && _DefaultJoystickMaps_Xml.ContainsKey(xbox360ControllerGuid))
{
RewiredDebugWarn($"GetDefaultControllerMap: Failed to find guid {inControllerGuid}... returning Xbox360 mapping (XInput detected)");
string xmlString2 = _DefaultJoystickMaps_Xml[xbox360ControllerGuid];
return ControllerMap.CreateFromXml(ControllerType.Joystick, xmlString2) as JoystickMap;
}
if (inControllerGuid == xbox360ControllerGuid && _DefaultJoystickMaps_Xml.ContainsKey(xboneControllerGuid))
{
RewiredDebugWarn($"GetDefaultControllerMap: Failed to find guid {inControllerGuid}... returning Xbone mapping (XInput detected)");
string xmlString3 = _DefaultJoystickMaps_Xml[xboneControllerGuid];
return ControllerMap.CreateFromXml(ControllerType.Joystick, xmlString3) as JoystickMap;
}
if (_DefaultJoystickMaps_Xml.ContainsKey(PlatformManager.DefaultControllerGuid))
{
RewiredDebugWarn($"GetDefaultControllerMap: Failed to find guid {inControllerGuid}... returning default");
string xmlString4 = _DefaultJoystickMaps_Xml[PlatformManager.DefaultControllerGuid];
return ControllerMap.CreateFromXml(ControllerType.Joystick, xmlString4) as JoystickMap;
}
RewiredDebugError($"GetDefaultControllerMap: Failed to find guid {inControllerGuid}... nor default {PlatformManager.DefaultControllerGuid}. Returning null");
return null;
}
public static bool HardwareGuidsMatch(Guid inA, Guid inB)
{
if (inA == inB)
{
RewiredDebugLog("HardwareGuidsMatch: TRUE, direct match: {0} --> {1}", inA.ToString(), inB.ToString());
return true;
}
RewiredDebugLog("HardwareGuidsMatch: FALSE, no match: {0} --> {1}", inA.ToString(), inB.ToString());
return false;
}
public static Guid LocalHardwareGuidRemap(Guid inHardwareGuid)
{
Guid result = inHardwareGuid;
RewiredDebugLog("LocalHardwareGuidRemap: {0} --> {1}", inHardwareGuid.ToString(), result.ToString());
return result;
}
[ConCommand(commandName = "export_default_controller_maps", flags = ConVarFlags.None, helpText = "Prints all default Rewired ControllerMaps.")]
public static void CCExportDefaultControllerMaps(ConCommandArgs args)
{
}
}