using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Drawing;
using System.Security.Principal;
namespace DS4Windows
{
[Flags]
public enum DS4KeyType : byte { None = 0, ScanCode = 1, Toggle = 2, Unbound = 4, Macro = 8, HoldMacro = 16, RepeatMacro = 32 }; //Increment by exponents of 2*, starting at 2^0
public enum Ds3PadId : byte { None = 0xFF, One = 0x00, Two = 0x01, Three = 0x02, Four = 0x03, All = 0x04 };
public enum DS4Controls : byte { None, LXNeg, LXPos, LYNeg, LYPos, RXNeg, RXPos, RYNeg, RYPos, L1, L2, L3, R1, R2, R3, Square, Triangle, Circle, Cross, DpadUp, DpadRight, DpadDown, DpadLeft, PS, TouchLeft, TouchUpper, TouchMulti, TouchRight, Share, Options, GyroXPos, GyroXNeg, GyroZPos, GyroZNeg, SwipeLeft, SwipeRight, SwipeUp, SwipeDown };
public enum X360Controls : byte { None, LXNeg, LXPos, LYNeg, LYPos, RXNeg, RXPos, RYNeg, RYPos, LB, LT, LS, RB, RT, RS, X, Y, B, A, DpadUp, DpadRight, DpadDown, DpadLeft, Guide, Back, Start, LeftMouse, RightMouse, MiddleMouse, FourthMouse, FifthMouse, WUP, WDOWN, MouseUp, MouseDown, MouseLeft, MouseRight, Unbound };
public class DS4ControlSettings
{
public DS4Controls control;
//public string extras = "0,0,0,0,0,0,0,0";
public string extras = null;
public DS4KeyType keyType = DS4KeyType.None;
public enum ActionType : byte { Default, Key, Button, Macro };
public ActionType actionType = ActionType.Default;
public object action = null;
public ActionType shiftActionType = ActionType.Default;
public object shiftAction = null;
public int shiftTrigger = 0;
//public string shiftExtras = "0,0,0,0,0,0,0,0";
public string shiftExtras = null;
public DS4KeyType shiftKeyType = DS4KeyType.None;
public DS4ControlSettings(DS4Controls ctrl)
{
control = ctrl;
}
public void Reset()
{
//extras = "0,0,0,0,0,0,0,0";
extras = null;
keyType = DS4KeyType.None;
actionType = ActionType.Default;
action = null;
shiftActionType = ActionType.Default;
shiftAction = null;
shiftTrigger = 0;
//shiftExtras = "0,0,0,0,0,0,0,0";
shiftExtras = null;
shiftKeyType = DS4KeyType.None;
}
internal void UpdateSettings(bool shift, object act, string exts, DS4KeyType kt, int trigger = 0)
{
if (!shift)
{
if (act is int || act is ushort)
actionType = ActionType.Key;
else if (act is string || act is X360Controls)
actionType = ActionType.Button;
else if (act is int[])
actionType = ActionType.Macro;
else
actionType = ActionType.Default;
action = act;
extras = exts;
keyType = kt;
}
else
{
if (act is int || act is ushort)
shiftActionType = ActionType.Key;
else if (act is string || act is X360Controls)
shiftActionType = ActionType.Button;
else if (act is int[])
shiftActionType = ActionType.Macro;
else
shiftActionType = ActionType.Default;
shiftAction = act;
shiftExtras = exts;
shiftKeyType = kt;
shiftTrigger = trigger;
}
}
}
public class DebugEventArgs : EventArgs
{
protected DateTime m_Time = DateTime.Now;
protected String m_Data = String.Empty;
protected bool warning = false;
public DebugEventArgs(String Data, bool warn)
{
m_Data = Data;
warning = warn;
}
public DateTime Time => m_Time;
public String Data => m_Data;
public bool Warning => warning;
}
public class MappingDoneEventArgs : EventArgs
{
protected int deviceNum = -1;
public MappingDoneEventArgs(int DeviceID)
{
deviceNum = DeviceID;
}
public int DeviceID => deviceNum;
}
public class ReportEventArgs : EventArgs
{
protected Ds3PadId m_Pad = Ds3PadId.None;
protected Byte[] m_Report = new Byte[64];
public ReportEventArgs()
{
}
public ReportEventArgs(Ds3PadId Pad)
{
m_Pad = Pad;
}
public Ds3PadId Pad
{
get { return m_Pad; }
set { m_Pad = value; }
}
public Byte[] Report
{
get { return m_Report; }
}
}
public class Global
{
protected static BackingStore m_Config = new BackingStore();
protected static Int32 m_IdleTimeout = 600000;
static string exepath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName;
public static string appdatapath;
public static string[] tempprofilename = new string[5] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
public static bool[] tempprofileDistance = new bool[5] { false, false, false, false, false };
public static X360Controls[] defaultButtonMapping = { X360Controls.None, X360Controls.LXNeg, X360Controls.LXPos,
X360Controls.LYNeg, X360Controls.LYPos, X360Controls.RXNeg, X360Controls.RXPos, X360Controls.RYNeg, X360Controls.RYPos,
X360Controls.LB, X360Controls.LT, X360Controls.LS, X360Controls.RB, X360Controls.RT, X360Controls.RS, X360Controls.X,
X360Controls.Y, X360Controls.B, X360Controls.A, X360Controls.DpadUp, X360Controls.DpadRight, X360Controls.DpadDown,
X360Controls.DpadLeft, X360Controls.Guide, X360Controls.None, X360Controls.None, X360Controls.None, X360Controls.None,
X360Controls.Back, X360Controls.Start, X360Controls.None, X360Controls.None, X360Controls.None, X360Controls.None,
X360Controls.None, X360Controls.None, X360Controls.None, X360Controls.None
};
public static void SaveWhere(string path)
{
appdatapath = path;
m_Config.m_Profile = appdatapath + "\\Profiles.xml";
m_Config.m_Actions = appdatapath + "\\Actions.xml";
}
///
/// Check if Admin Rights are needed to write in Appliplation Directory
///
///
public static bool AdminNeeded()
{
try
{
File.WriteAllText(exepath + "\\test.txt", "test");
File.Delete(exepath + "\\test.txt");
return false;
}
catch (UnauthorizedAccessException)
{
return true;
}
}
public static bool IsAdministrator()
{
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
public static event EventHandler ControllerStatusChange; // called when a controller is added/removed/battery or touchpad mode changes/etc.
public static void ControllerStatusChanged(object sender)
{
if (ControllerStatusChange != null)
ControllerStatusChange(sender, EventArgs.Empty);
}
//general values
public static bool UseExclusiveMode
{
set { m_Config.useExclusiveMode = value; }
get { return m_Config.useExclusiveMode; }
}
public static DateTime LastChecked
{
set { m_Config.lastChecked = value; }
get { return m_Config.lastChecked; }
}
public static int CheckWhen
{
set { m_Config.CheckWhen = value; }
get { return m_Config.CheckWhen; }
}
public static int Notifications
{
set { m_Config.notifications = value; }
get { return m_Config.notifications; }
}
public static bool DCBTatStop
{
set { m_Config.disconnectBTAtStop = value; }
get { return m_Config.disconnectBTAtStop; }
}
public static bool SwipeProfiles
{
set { m_Config.swipeProfiles = value; }
get { return m_Config.swipeProfiles; }
}
public static bool DS4Mapping
{
set { m_Config.ds4Mapping = value; }
get { return m_Config.ds4Mapping; }
}
public static bool QuickCharge
{
set { m_Config.quickCharge = value; }
get { return m_Config.quickCharge; }
}
public static int FirstXinputPort
{
set { m_Config.firstXinputPort = value; }
get { return m_Config.firstXinputPort; }
}
public static bool CloseMini
{
set { m_Config.closeMini = value; }
get { return m_Config.closeMini; }
}
public static bool StartMinimized
{
set { m_Config.startMinimized = value; }
get { return m_Config.startMinimized; }
}
public static int FormWidth
{
set { m_Config.formWidth = value; }
get { return m_Config.formWidth;}
}
public static int FormHeight
{
set { m_Config.formHeight = value; }
get { return m_Config.formHeight; }
}
public static bool DownloadLang
{
set { m_Config.downloadLang = value; }
get { return m_Config.downloadLang; }
}
public static bool FlashWhenLate
{
set { m_Config.flashWhenLate = value; }
get { return m_Config.flashWhenLate; }
}
public static int FlashWhenLateAt
{
set { m_Config.flashWhenLateAt = value; }
get { return m_Config.flashWhenLateAt; }
}
public static int getFlashWhenLateAt()
{
return m_Config.flashWhenLateAt;
}
public static bool UseWhiteIcon
{
set { m_Config.useWhiteIcon = value; }
get { return m_Config.useWhiteIcon; }
}
//controller/profile specfic values
public static int[] ButtonMouseSensitivity => m_Config.buttonMouseSensitivity;
public static byte[] RumbleBoost => m_Config.rumble;
public static double[] Rainbow => m_Config.rainbow;
public static bool[] FlushHIDQueue => m_Config.flushHIDQueue;
public static bool getFlushHIDQueue(int index)
{
return m_Config.flushHIDQueue[index];
}
public static int[] IdleDisconnectTimeout => m_Config.idleDisconnectTimeout;
public static int getIdleDisconnectTimeout(int index)
{
return m_Config.idleDisconnectTimeout[index];
}
public static byte[] TouchSensitivity => m_Config.touchSensitivity;
public static byte[] getTouchSensitivity()
{
return m_Config.touchSensitivity;
}
public static byte getTouchSensitivity(int index)
{
return m_Config.touchSensitivity[index];
}
public static byte[] FlashType => m_Config.flashType;
public static byte getFlashType(int index)
{
return m_Config.flashType[index];
}
public static int[] FlashAt => m_Config.flashAt;
public static int getFlashAt(int index)
{
return m_Config.flashAt[index];
}
public static bool[] LedAsBatteryIndicator => m_Config.ledAsBattery;
public static bool getLedAsBatteryIndicator(int index)
{
return m_Config.ledAsBattery[index];
}
public static int[] ChargingType => m_Config.chargingType;
public static int getChargingType(int index)
{
return m_Config.chargingType[index];
}
public static bool[] DinputOnly => m_Config.dinputOnly;
public static bool[] StartTouchpadOff => m_Config.startTouchpadOff;
public static bool[] UseTPforControls => m_Config.useTPforControls;
public static bool getUseTPforControls(int index)
{
return m_Config.useTPforControls[index];
}
public static bool[] UseSAforMouse => m_Config.useSAforMouse;
public static bool isUsingSAforMouse(int index)
{
return m_Config.useSAforMouse[index];
}
public static string[] SATriggers => m_Config.sATriggers;
public static int[] GyroSensitivity => m_Config.gyroSensitivity;
public static int[] GyroInvert => m_Config.gyroInvert;
public static DS4Color[] MainColor => m_Config.m_Leds;
public static DS4Color[] LowColor => m_Config.m_LowLeds;
public static DS4Color[] ChargingColor => m_Config.m_ChargingLeds;
public static DS4Color[] CustomColor => m_Config.m_CustomLeds;
public static bool[] UseCustomLed => m_Config.useCustomLeds;
public static DS4Color[] FlashColor => m_Config.m_FlashLeds;
public static byte[] TapSensitivity => m_Config.tapSensitivity;
public static bool[] DoubleTap => m_Config.doubleTap;
public static int[] ScrollSensitivity => m_Config.scrollSensitivity;
public static int[] getScrollSensitivity()
{
return m_Config.scrollSensitivity;
}
public static int getScrollSensitivity(int index)
{
return m_Config.scrollSensitivity[index];
}
public static bool[] LowerRCOn => m_Config.lowerRCOn;
public static bool[] TouchpadJitterCompensation => m_Config.touchpadJitterCompensation;
public static byte[] L2Deadzone => m_Config.l2Deadzone;
public static byte getL2Deadzone(int index)
{
return m_Config.l2Deadzone[index];
}
public static byte[] R2Deadzone => m_Config.r2Deadzone;
public static byte getR2Deadzone(int index)
{
return m_Config.r2Deadzone[index];
}
public static double[] SXDeadzone => m_Config.SXDeadzone;
public static double getSXDeadzone(int index)
{
return m_Config.SXDeadzone[index];
}
public static double[] SZDeadzone => m_Config.SZDeadzone;
public static double getSZDeadzone(int index)
{
return m_Config.SZDeadzone[index];
}
public static int[] LSDeadzone => m_Config.LSDeadzone;
public static int getLSDeadzone(int index)
{
return m_Config.LSDeadzone[index];
}
public static int[] RSDeadzone => m_Config.RSDeadzone;
public static int getRSDeadzone(int index)
{
return m_Config.RSDeadzone[index];
}
public static int[] LSAntiDeadzone => m_Config.LSAntiDeadzone;
public static int getLSAntiDeadzone(int index)
{
return m_Config.LSAntiDeadzone[index];
}
public static int[] RSAntiDeadzone => m_Config.RSAntiDeadzone;
public static int getRSAntiDeadzone(int index)
{
return m_Config.RSAntiDeadzone[index];
}
public static int[] L2AntiDeadzone => m_Config.l2AntiDeadzone;
public static int getL2AntiDeadzone(int index)
{
return m_Config.l2AntiDeadzone[index];
}
public static int[] R2AntiDeadzone => m_Config.r2AntiDeadzone;
public static int getR2AntiDeadzone(int index)
{
return m_Config.r2AntiDeadzone[index];
}
public static int[] LSCurve => m_Config.lsCurve;
public static int getLSCurve(int index)
{
return m_Config.lsCurve[index];
}
public static int[] RSCurve => m_Config.rsCurve;
public static int getRSCurve(int index)
{
return m_Config.rsCurve[index];
}
public static double[] L2Sens => m_Config.l2Sens;
public static double getL2Sens(int index)
{
return m_Config.l2Sens[index];
}
public static double[] R2Sens => m_Config.r2Sens;
public static double getR2Sens(int index)
{
return m_Config.r2Sens[index];
}
public static double[] SXSens => m_Config.SXSens;
public static double getSXSens(int index)
{
return m_Config.SXSens[index];
}
public static double[] SZSens => m_Config.SZSens;
public static double getSZSens(int index)
{
return m_Config.SZSens[index];
}
public static double[] LSSens => m_Config.LSSens;
public static double getLSSens(int index)
{
return m_Config.LSSens[index];
}
public static double[] RSSens => m_Config.RSSens;
public static double getRSSens(int index)
{
return m_Config.RSSens[index];
}
public static bool[] MouseAccel => m_Config.mouseAccel;
public static string[] LaunchProgram => m_Config.launchProgram;
public static string[] ProfilePath => m_Config.profilePath;
public static bool[] DistanceProfiles = m_Config.distanceProfiles;
public static List[] ProfileActions => m_Config.profileActions;
public static int getProfileActionCount(int index)
{
return m_Config.profileActionCount[index];
}
public static void calculateProfileActionCount(int index)
{
m_Config.profileActionCount[index] = m_Config.profileActions[index].Count;
}
public static List getProfileActions(int index)
{
return m_Config.profileActions[index];
}
public static void UpdateDS4CSetting (int deviceNum, string buttonName, bool shift, object action, string exts, DS4KeyType kt, int trigger = 0)
{
m_Config.UpdateDS4CSetting(deviceNum, buttonName, shift, action, exts, kt, trigger);
m_Config.containsCustomAction[deviceNum] = m_Config.HasCustomActions(deviceNum);
m_Config.containsCustomExtras[deviceNum] = m_Config.HasCustomExtras(deviceNum);
}
public static void UpdateDS4Extra(int deviceNum, string buttonName, bool shift, string exts)
{
m_Config.UpdateDS4CExtra(deviceNum, buttonName, shift, exts);
m_Config.containsCustomAction[deviceNum] = m_Config.HasCustomActions(deviceNum);
m_Config.containsCustomExtras[deviceNum] = m_Config.HasCustomExtras(deviceNum);
}
public static object GetDS4Action(int deviceNum, string buttonName, bool shift) => m_Config.GetDS4Action(deviceNum, buttonName, shift);
public static object GetDS4Action(int deviceNum, DS4Controls control, bool shift) => m_Config.GetDS4Action(deviceNum, control, shift);
public static DS4KeyType GetDS4KeyType(int deviceNum, string buttonName, bool shift) => m_Config.GetDS4KeyType(deviceNum, buttonName, shift);
public static string GetDS4Extra(int deviceNum, string buttonName, bool shift) => m_Config.GetDS4Extra(deviceNum, buttonName, shift);
public static int GetDS4STrigger(int deviceNum, string buttonName) => m_Config.GetDS4STrigger(deviceNum, buttonName);
public static int GetDS4STrigger(int deviceNum, DS4Controls control) => m_Config.GetDS4STrigger(deviceNum, control);
public static List getDS4CSettings(int device) => m_Config.ds4settings[device];
public static DS4ControlSettings getDS4CSetting(int deviceNum, string control) => m_Config.getDS4CSetting(deviceNum, control);
public static DS4ControlSettings getDS4CSetting(int deviceNum, DS4Controls control) => m_Config.getDS4CSetting(deviceNum, control);
public static bool HasCustomAction(int deviceNum) => m_Config.HasCustomActions(deviceNum);
public static bool HasCustomExtras(int deviceNum) => m_Config.HasCustomExtras(deviceNum);
public static bool containsCustomAction(int deviceNum)
{
return m_Config.containsCustomAction[deviceNum];
}
public static bool containsCustomExtras(int deviceNum)
{
return m_Config.containsCustomExtras[deviceNum];
}
public static void SaveAction(string name, string controls, int mode, string details, bool edit, string extras = "")
{
m_Config.SaveAction(name, controls, mode, details, edit, extras);
Mapping.actionDone.Add(new Mapping.ActionState());
}
public static void RemoveAction(string name)
{
m_Config.RemoveAction(name);
}
public static bool LoadActions() => m_Config.LoadActions();
public static List GetActions() => m_Config.actions;
public static int GetActionIndexOf(string name)
{
for (int i = 0, actionCount = m_Config.actions.Count; i < actionCount; i++)
if (m_Config.actions[i].name == name)
return i;
return -1;
}
public static int GetProfileActionIndexOf(int device, string name)
{
int index = -1;
m_Config.profileActionIndexDict[device].TryGetValue(name, out index);
return index;
}
public static SpecialAction GetAction(string name)
{
foreach (SpecialAction sA in m_Config.actions)
if (sA.name == name)
return sA;
return new SpecialAction("null", "null", "null", "null");
}
public static SpecialAction GetProfileAction(int device, string name)
{
SpecialAction sA = null;
m_Config.profileActionDict[device].TryGetValue(name, out sA);
return sA;
}
public static void calculateProfileActionDicts(int device)
{
m_Config.profileActionDict[device].Clear();
m_Config.profileActionIndexDict[device].Clear();
foreach (string actionname in m_Config.profileActions[device])
{
m_Config.profileActionDict[device].Add(actionname, Global.GetAction(actionname));
m_Config.profileActionIndexDict[device].Add(actionname, Global.GetActionIndexOf(actionname));
}
}
public static X360Controls getX360ControlsByName(string key)
{
return m_Config.getX360ControlsByName(key);
}
public static string getX360ControlString(X360Controls key)
{
return m_Config.getX360ControlString(key);
}
public static DS4Controls getDS4ControlsByName(string key)
{
return m_Config.getDS4ControlsByName(key);
}
public static X360Controls getDefaultX360ControlBinding(DS4Controls dc)
{
return defaultButtonMapping[(int)dc];
}
/*public static X360Controls getCustomButton(int device, DS4Controls controlName) => m_Config.GetCustomButton(device, controlName);
public static ushort getCustomKey(int device, DS4Controls controlName) => m_Config.GetCustomKey(device, controlName);
public static string getCustomMacro(int device, DS4Controls controlName) => m_Config.GetCustomMacro(device, controlName);
public static string getCustomExtras(int device, DS4Controls controlName) => m_Config.GetCustomExtras(device, controlName);
public static DS4KeyType getCustomKeyType(int device, DS4Controls controlName) => m_Config.GetCustomKeyType(device, controlName);
public static bool getHasCustomKeysorButtons(int device) => m_Config.customMapButtons[device].Count > 0
|| m_Config.customMapKeys[device].Count > 0;
public static bool getHasCustomExtras(int device) => m_Config.customMapExtras[device].Count > 0;
public static Dictionary getCustomButtons(int device) => m_Config.customMapButtons[device];
public static Dictionary getCustomKeys(int device) => m_Config.customMapKeys[device];
public static Dictionary getCustomMacros(int device) => m_Config.customMapMacros[device];
public static Dictionary getCustomExtras(int device) => m_Config.customMapExtras[device];
public static Dictionary getCustomKeyTypes(int device) => m_Config.customMapKeyTypes[device];
public static X360Controls getShiftCustomButton(int device, DS4Controls controlName) => m_Config.GetShiftCustomButton(device, controlName);
public static ushort getShiftCustomKey(int device, DS4Controls controlName) => m_Config.GetShiftCustomKey(device, controlName);
public static string getShiftCustomMacro(int device, DS4Controls controlName) => m_Config.GetShiftCustomMacro(device, controlName);
public static string getShiftCustomExtras(int device, DS4Controls controlName) => m_Config.GetShiftCustomExtras(device, controlName);
public static DS4KeyType getShiftCustomKeyType(int device, DS4Controls controlName) => m_Config.GetShiftCustomKeyType(device, controlName);
public static bool getHasShiftCustomKeysorButtons(int device) => m_Config.shiftCustomMapButtons[device].Count > 0
|| m_Config.shiftCustomMapKeys[device].Count > 0;
public static bool getHasShiftCustomExtras(int device) => m_Config.shiftCustomMapExtras[device].Count > 0;
public static Dictionary getShiftCustomButtons(int device) => m_Config.shiftCustomMapButtons[device];
public static Dictionary getShiftCustomKeys(int device) => m_Config.shiftCustomMapKeys[device];
public static Dictionary getShiftCustomMacros(int device) => m_Config.shiftCustomMapMacros[device];
public static Dictionary getShiftCustomExtras(int device) => m_Config.shiftCustomMapExtras[device];
public static Dictionary getShiftCustomKeyTypes(int device) => m_Config.shiftCustomMapKeyTypes[device]; */
public static bool Load() => m_Config.Load();
public static void LoadProfile(int device, bool launchprogram, ControlService control)
{
m_Config.LoadProfile(device, launchprogram, control);
tempprofilename[device] = string.Empty;
tempprofileDistance[device] = false;
}
public static void LoadTempProfile(int device, string name, bool launchprogram, ControlService control)
{
m_Config.LoadProfile(device, launchprogram, control, appdatapath + @"\Profiles\" + name + ".xml");
tempprofilename[device] = name;
tempprofileDistance[device] = name.ToLower().Contains("distance");
}
public static bool Save()
{
return m_Config.Save();
}
public static void SaveProfile(int device, string propath)
{
m_Config.SaveProfile(device, propath);
}
private static byte applyRatio(byte b1, byte b2, double r)
{
if (r > 100)
r = 100;
else if (r < 0)
r = 0;
r /= 100f;
return (byte)Math.Round((b1 * (1 - r) + b2 *r),0);
}
public static DS4Color getTransitionedColor(DS4Color c1, DS4Color c2, double ratio)
{//;
//Color cs = Color.FromArgb(c1.red, c1.green, c1.blue);
c1.red = applyRatio(c1.red, c2.red, ratio);
c1.green = applyRatio(c1.green, c2.green, ratio);
c1.blue = applyRatio(c1.blue, c2.blue, ratio);
return c1;
}
private static Color applyRatio(Color c1, Color c2, uint r)
{
float ratio = r / 100f;
float hue1 = c1.GetHue();
float hue2 = c2.GetHue();
float bri1 = c1.GetBrightness();
float bri2 = c2.GetBrightness();
float sat1 = c1.GetSaturation();
float sat2 = c2.GetSaturation();
float hr = hue2 - hue1;
float br = bri2 - bri1;
float sr = sat2 - sat1;
Color csR;
if (bri1 == 0)
csR = HuetoRGB(hue2,sat2,bri2 - br*ratio);
else
csR = HuetoRGB(hue2 - hr * ratio, sat2 - sr * ratio, bri2 - br * ratio);
return csR;
}
public static Color HuetoRGB(float hue, float sat, float bri)
{
float C = (1-Math.Abs(2*bri)-1)* sat;
float X = C * (1 - Math.Abs((hue / 60) % 2 - 1));
float m = bri - C / 2;
float R, G, B;
if (0 <= hue && hue < 60)
{ R = C; G = X; B = 0;}
else if (60 <= hue && hue < 120)
{R = X; G = C; B = 0; }
else if (120 <= hue && hue < 180)
{ R = 0; G = C; B = X; }
else if (180 <= hue && hue < 240)
{ R = 0; G = X; B = C; }
else if (240 <= hue && hue < 300)
{ R = X; G = 0; B = C; }
else if (300 <= hue && hue < 360)
{ R = C; G = 0; B = X; }
else
{ R = 255; G = 0; B = 0; }
R += m; G += m; B += m;
R *= 255; G *= 255; B *= 255;
return Color.FromArgb((int)R, (int)G, (int)B);
}
}
public class BackingStore
{
//public String m_Profile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool" + "\\Profiles.xml";
public String m_Profile = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + "\\Profiles.xml";
public String m_Actions = Global.appdatapath + "\\Actions.xml";
protected XmlDocument m_Xdoc = new XmlDocument();
//fifth value used to for options, not fifth controller
public int[] buttonMouseSensitivity = { 25, 25, 25, 25, 25 };
public bool[] flushHIDQueue = { false, false, false, false, false };
public int[] idleDisconnectTimeout = { 0, 0, 0, 0, 0 };
public Boolean[] touchpadJitterCompensation = { true, true, true, true, true };
public Boolean[] lowerRCOn = { false, false, false, false, false };
public Boolean[] ledAsBattery = { false, false, false, false, false };
public Byte[] flashType = { 0, 0, 0, 0, 0 };
public String[] profilePath = { String.Empty, String.Empty, String.Empty, String.Empty, String.Empty };
// Cache properties instead of performing a string comparison every frame
public bool[] distanceProfiles = { false, false, false, false, false };
public Byte[] rumble = { 100, 100, 100, 100, 100 };
public Byte[] touchSensitivity = { 100, 100, 100, 100, 100 };
public Byte[] l2Deadzone = { 0, 0, 0, 0, 0 }, r2Deadzone = { 0, 0, 0, 0, 0 };
public int[] LSDeadzone = { 0, 0, 0, 0, 0 }, RSDeadzone = { 0, 0, 0, 0, 0 };
public int[] LSAntiDeadzone = { 0, 0, 0, 0, 0 }, RSAntiDeadzone = { 0, 0, 0, 0, 0 };
public int[] l2AntiDeadzone = { 0, 0, 0, 0, 0 }, r2AntiDeadzone = { 0, 0, 0, 0, 0 };
public double[] SXDeadzone = { 0.25, 0.25, 0.25, 0.25, 0.25 }, SZDeadzone = { 0.25, 0.25, 0.25, 0.25, 0.25 };
public double[] l2Sens = { 1, 1, 1, 1, 1 }, r2Sens = { 1, 1, 1, 1, 1 };
public double[] LSSens = { 1, 1, 1, 1, 1 }, RSSens = { 1, 1, 1, 1, 1 };
public double[] SXSens = { 1, 1, 1, 1, 1 }, SZSens = { 1, 1, 1, 1, 1 };
public Byte[] tapSensitivity = { 0, 0, 0, 0, 0 };
public bool[] doubleTap = { false, false, false, false, false };
public int[] scrollSensitivity = { 0, 0, 0, 0, 0 };
public double[] rainbow = { 0, 0, 0, 0, 0 };
public int[] flashAt = { 0, 0, 0, 0, 0 };
public bool[] mouseAccel = { true, true, true, true, true };
public DS4Color[] m_LowLeds = new DS4Color[]
{
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black)
};
public DS4Color[] m_Leds = new DS4Color[]
{
new DS4Color(Color.Blue),
new DS4Color(Color.Red),
new DS4Color(Color.Green),
new DS4Color(Color.Pink),
new DS4Color(Color.White)
};
public DS4Color[] m_ChargingLeds = new DS4Color[]
{
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black)
};
public DS4Color[] m_FlashLeds = new DS4Color[]
{
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black)
};
public bool[] useCustomLeds = new bool[] { false, false, false, false };
public DS4Color[] m_CustomLeds = new DS4Color[]
{
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black)
};
public int[] chargingType = { 0, 0, 0, 0, 0 };
public string[] launchProgram = { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
public bool[] dinputOnly = { false, false, false, false, false };
public bool[] startTouchpadOff = { false, false, false, false, false };
public bool[] useTPforControls = { false, false, false, false, false };
public bool[] useSAforMouse = { false, false, false, false, false };
public string[] sATriggers = { "", "", "", "", "" };
public int[] lsCurve = { 0, 0, 0, 0, 0 };
public int[] rsCurve = { 0, 0, 0, 0, 0 };
public Boolean useExclusiveMode = false;
public Int32 formWidth = 782;
public Int32 formHeight = 550;
public Boolean startMinimized = false;
public DateTime lastChecked;
public int CheckWhen = 1;
public int notifications = 2;
public bool disconnectBTAtStop = false;
public bool swipeProfiles = true;
public bool ds4Mapping = true;
public bool quickCharge = false;
public int firstXinputPort = 1;
public bool closeMini = false;
public List actions = new List();
public List[] ds4settings = { new List(), new List(), new List(), new List(), new List() };
/*public Dictionary[] customMapKeyTypes = { null, null, null, null, null };
public Dictionary[] customMapKeys = { null, null, null, null, null };
public Dictionary[] customMapMacros = { null, null, null, null, null };
public Dictionary[] customMapButtons = { null, null, null, null, null };
public Dictionary[] customMapExtras = { null, null, null, null, null };
public Dictionary[] shiftCustomMapKeyTypes = { null, null, null, null, null };
public Dictionary[] shiftCustomMapKeys = { null, null, null, null, null };
public Dictionary[] shiftCustomMapMacros = { null, null, null, null, null };
public Dictionary[] shiftCustomMapButtons = { null, null, null, null, null };
public Dictionary[] shiftCustomMapExtras = { null, null, null, null, null };*/
public List[] profileActions = { null, null, null, null, null };
public int[] profileActionCount = { 0, 0, 0, 0, 0 };
public Dictionary[] profileActionDict = { new Dictionary(), new Dictionary(), new Dictionary(), new Dictionary(), new Dictionary() };
public Dictionary[] profileActionIndexDict = { new Dictionary(), new Dictionary(), new Dictionary(), new Dictionary(), new Dictionary() };
public bool downloadLang = true;
public bool useWhiteIcon;
public bool flashWhenLate = true;
public int flashWhenLateAt = 20;
// Cache whether profile has custom action
public bool[] containsCustomAction = { false, false, false, false, false };
// Cache whether profile has custom extras
public bool[] containsCustomExtras = { false, false, false, false, false };
public int[] gyroSensitivity = { 100, 100, 100, 100, 100 };
public int[] gyroInvert = { 0, 0, 0, 0, 0 };
public BackingStore()
{
for (int i = 0; i < 5; i++)
{
foreach (DS4Controls dc in Enum.GetValues(typeof(DS4Controls)))
if (dc != DS4Controls.None)
ds4settings[i].Add(new DS4ControlSettings(dc));
/*customMapKeyTypes[i] = new Dictionary();
customMapKeys[i] = new Dictionary();
customMapMacros[i] = new Dictionary();
customMapButtons[i] = new Dictionary();
customMapExtras[i] = new Dictionary();
shiftCustomMapKeyTypes[i] = new Dictionary();
shiftCustomMapKeys[i] = new Dictionary();
shiftCustomMapMacros[i] = new Dictionary();
shiftCustomMapButtons[i] = new Dictionary();
shiftCustomMapExtras[i] = new Dictionary();*/
profileActions[i] = new List();
profileActions[i].Add("Disconnect Controller");
profileActionCount[i] = profileActions[i].Count;
}
}
/*public X360Controls GetCustomButton(int device, DS4Controls controlName)
{
if (customMapButtons[device].ContainsKey(controlName))
return customMapButtons[device][controlName];
else return X360Controls.None;
}
public UInt16 GetCustomKey(int device, DS4Controls controlName)
{
if (customMapKeys[device].ContainsKey(controlName))
return customMapKeys[device][controlName];
else return 0;
}
public string GetCustomMacro(int device, DS4Controls controlName)
{
if (customMapMacros[device].ContainsKey(controlName))
return customMapMacros[device][controlName];
else return "0";
}
public string GetCustomExtras(int device, DS4Controls controlName)
{
if (customMapExtras[device].ContainsKey(controlName))
return customMapExtras[device][controlName];
else return "0";
}
public DS4KeyType GetCustomKeyType(int device, DS4Controls controlName)
{
try
{
if (customMapKeyTypes[device].ContainsKey(controlName))
return customMapKeyTypes[device][controlName];
else return 0;
}
catch { return 0; }
}
public X360Controls GetShiftCustomButton(int device, DS4Controls controlName)
{
if (shiftCustomMapButtons[device].ContainsKey(controlName))
return shiftCustomMapButtons[device][controlName];
else return X360Controls.None;
}
public UInt16 GetShiftCustomKey(int device, DS4Controls controlName)
{
if (shiftCustomMapKeys[device].ContainsKey(controlName))
return shiftCustomMapKeys[device][controlName];
else return 0;
}
public string GetShiftCustomMacro(int device, DS4Controls controlName)
{
if (shiftCustomMapMacros[device].ContainsKey(controlName))
return shiftCustomMapMacros[device][controlName];
else return "0";
}
public string GetShiftCustomExtras(int device, DS4Controls controlName)
{
if (customMapExtras[device].ContainsKey(controlName))
return customMapExtras[device][controlName];
else return "0";
}
public DS4KeyType GetShiftCustomKeyType(int device, DS4Controls controlName)
{
try
{
if (shiftCustomMapKeyTypes[device].ContainsKey(controlName))
return shiftCustomMapKeyTypes[device][controlName];
else return 0;
}
catch { return 0; }
}*/
public bool SaveProfile(int device, string propath)
{
bool Saved = true;
string path = Global.appdatapath + @"\Profiles\" + Path.GetFileNameWithoutExtension(propath) + ".xml";
try
{
XmlNode Node;
XmlNode xmlControls = m_Xdoc.SelectSingleNode("/DS4Windows/Control");
XmlNode xmlShiftControls = m_Xdoc.SelectSingleNode("/DS4Windows/ShiftControl");
m_Xdoc.RemoveAll();
Node = m_Xdoc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
m_Xdoc.AppendChild(Node);
Node = m_Xdoc.CreateComment(string.Format(" DS4Windows Configuration Data. {0} ", DateTime.Now));
m_Xdoc.AppendChild(Node);
Node = m_Xdoc.CreateWhitespace("\r\n");
m_Xdoc.AppendChild(Node);
Node = m_Xdoc.CreateNode(XmlNodeType.Element, "DS4Windows", null);
XmlNode xmlFlushHIDQueue = m_Xdoc.CreateNode(XmlNodeType.Element, "flushHIDQueue", null); xmlFlushHIDQueue.InnerText = flushHIDQueue[device].ToString(); Node.AppendChild(xmlFlushHIDQueue);
XmlNode xmlIdleDisconnectTimeout = m_Xdoc.CreateNode(XmlNodeType.Element, "idleDisconnectTimeout", null); xmlIdleDisconnectTimeout.InnerText = idleDisconnectTimeout[device].ToString(); Node.AppendChild(xmlIdleDisconnectTimeout);
XmlNode xmlColor = m_Xdoc.CreateNode(XmlNodeType.Element, "Color", null);
xmlColor.InnerText = m_Leds[device].red.ToString() + "," + m_Leds[device].green.ToString() + "," + m_Leds[device].blue.ToString();
Node.AppendChild(xmlColor);
XmlNode xmlRumbleBoost = m_Xdoc.CreateNode(XmlNodeType.Element, "RumbleBoost", null); xmlRumbleBoost.InnerText = rumble[device].ToString(); Node.AppendChild(xmlRumbleBoost);
XmlNode xmlLedAsBatteryIndicator = m_Xdoc.CreateNode(XmlNodeType.Element, "ledAsBatteryIndicator", null); xmlLedAsBatteryIndicator.InnerText = ledAsBattery[device].ToString(); Node.AppendChild(xmlLedAsBatteryIndicator);
XmlNode xmlLowBatteryFlash = m_Xdoc.CreateNode(XmlNodeType.Element, "FlashType", null); xmlLowBatteryFlash.InnerText = flashType[device].ToString(); Node.AppendChild(xmlLowBatteryFlash);
XmlNode xmlFlashBatterAt = m_Xdoc.CreateNode(XmlNodeType.Element, "flashBatteryAt", null); xmlFlashBatterAt.InnerText = flashAt[device].ToString(); Node.AppendChild(xmlFlashBatterAt);
XmlNode xmlTouchSensitivity = m_Xdoc.CreateNode(XmlNodeType.Element, "touchSensitivity", null); xmlTouchSensitivity.InnerText = touchSensitivity[device].ToString(); Node.AppendChild(xmlTouchSensitivity);
XmlNode xmlLowColor = m_Xdoc.CreateNode(XmlNodeType.Element, "LowColor", null);
xmlLowColor.InnerText = m_LowLeds[device].red.ToString() + "," + m_LowLeds[device].green.ToString() + "," + m_LowLeds[device].blue.ToString();
Node.AppendChild(xmlLowColor);
XmlNode xmlChargingColor = m_Xdoc.CreateNode(XmlNodeType.Element, "ChargingColor", null);
xmlChargingColor.InnerText = m_ChargingLeds[device].red.ToString() + "," + m_ChargingLeds[device].green.ToString() + "," + m_ChargingLeds[device].blue.ToString();
Node.AppendChild(xmlChargingColor);
XmlNode xmlFlashColor = m_Xdoc.CreateNode(XmlNodeType.Element, "FlashColor", null);
xmlFlashColor.InnerText = m_FlashLeds[device].red.ToString() + "," + m_FlashLeds[device].green.ToString() + "," + m_FlashLeds[device].blue.ToString();
Node.AppendChild(xmlFlashColor);
XmlNode xmlTouchpadJitterCompensation = m_Xdoc.CreateNode(XmlNodeType.Element, "touchpadJitterCompensation", null); xmlTouchpadJitterCompensation.InnerText = touchpadJitterCompensation[device].ToString(); Node.AppendChild(xmlTouchpadJitterCompensation);
XmlNode xmlLowerRCOn = m_Xdoc.CreateNode(XmlNodeType.Element, "lowerRCOn", null); xmlLowerRCOn.InnerText = lowerRCOn[device].ToString(); Node.AppendChild(xmlLowerRCOn);
XmlNode xmlTapSensitivity = m_Xdoc.CreateNode(XmlNodeType.Element, "tapSensitivity", null); xmlTapSensitivity.InnerText = tapSensitivity[device].ToString(); Node.AppendChild(xmlTapSensitivity);
XmlNode xmlDouble = m_Xdoc.CreateNode(XmlNodeType.Element, "doubleTap", null); xmlDouble.InnerText = doubleTap[device].ToString(); Node.AppendChild(xmlDouble);
XmlNode xmlScrollSensitivity = m_Xdoc.CreateNode(XmlNodeType.Element, "scrollSensitivity", null); xmlScrollSensitivity.InnerText = scrollSensitivity[device].ToString(); Node.AppendChild(xmlScrollSensitivity);
XmlNode xmlLeftTriggerMiddle = m_Xdoc.CreateNode(XmlNodeType.Element, "LeftTriggerMiddle", null); xmlLeftTriggerMiddle.InnerText = l2Deadzone[device].ToString(); Node.AppendChild(xmlLeftTriggerMiddle);
XmlNode xmlRightTriggerMiddle = m_Xdoc.CreateNode(XmlNodeType.Element, "RightTriggerMiddle", null); xmlRightTriggerMiddle.InnerText = r2Deadzone[device].ToString(); Node.AppendChild(xmlRightTriggerMiddle);
XmlNode xmlL2AD = m_Xdoc.CreateNode(XmlNodeType.Element, "L2AntiDeadZone", null); xmlL2AD.InnerText = l2AntiDeadzone[device].ToString(); Node.AppendChild(xmlL2AD);
XmlNode xmlR2AD = m_Xdoc.CreateNode(XmlNodeType.Element, "R2AntiDeadZone", null); xmlR2AD.InnerText = r2AntiDeadzone[device].ToString(); Node.AppendChild(xmlR2AD);
XmlNode xmlButtonMouseSensitivity = m_Xdoc.CreateNode(XmlNodeType.Element, "ButtonMouseSensitivity", null); xmlButtonMouseSensitivity.InnerText = buttonMouseSensitivity[device].ToString(); Node.AppendChild(xmlButtonMouseSensitivity);
XmlNode xmlRainbow = m_Xdoc.CreateNode(XmlNodeType.Element, "Rainbow", null); xmlRainbow.InnerText = rainbow[device].ToString(); Node.AppendChild(xmlRainbow);
XmlNode xmlLSD = m_Xdoc.CreateNode(XmlNodeType.Element, "LSDeadZone", null); xmlLSD.InnerText = LSDeadzone[device].ToString(); Node.AppendChild(xmlLSD);
XmlNode xmlRSD = m_Xdoc.CreateNode(XmlNodeType.Element, "RSDeadZone", null); xmlRSD.InnerText = RSDeadzone[device].ToString(); Node.AppendChild(xmlRSD);
XmlNode xmlLSAD = m_Xdoc.CreateNode(XmlNodeType.Element, "LSAntiDeadZone", null); xmlLSAD.InnerText = LSAntiDeadzone[device].ToString(); Node.AppendChild(xmlLSAD);
XmlNode xmlRSAD = m_Xdoc.CreateNode(XmlNodeType.Element, "RSAntiDeadZone", null); xmlRSAD.InnerText = RSAntiDeadzone[device].ToString(); Node.AppendChild(xmlRSAD);
XmlNode xmlSXD = m_Xdoc.CreateNode(XmlNodeType.Element, "SXDeadZone", null); xmlSXD.InnerText = SXDeadzone[device].ToString(); Node.AppendChild(xmlSXD);
XmlNode xmlSZD = m_Xdoc.CreateNode(XmlNodeType.Element, "SZDeadZone", null); xmlSZD.InnerText = SZDeadzone[device].ToString(); Node.AppendChild(xmlSZD);
XmlNode xmlSens = m_Xdoc.CreateNode(XmlNodeType.Element, "Sensitivity", null);
xmlSens.InnerText = $"{LSSens[device]}|{RSSens[device]}|{l2Sens[device]}|{r2Sens[device]}|{SXSens[device]}|{SZSens[device]}";
Node.AppendChild(xmlSens);
XmlNode xmlChargingType = m_Xdoc.CreateNode(XmlNodeType.Element, "ChargingType", null); xmlChargingType.InnerText = chargingType[device].ToString(); Node.AppendChild(xmlChargingType);
XmlNode xmlMouseAccel = m_Xdoc.CreateNode(XmlNodeType.Element, "MouseAcceleration", null); xmlMouseAccel.InnerText = mouseAccel[device].ToString(); Node.AppendChild(xmlMouseAccel);
//XmlNode xmlShiftMod = m_Xdoc.CreateNode(XmlNodeType.Element, "ShiftModifier", null); xmlShiftMod.InnerText = shiftModifier[device].ToString(); Node.AppendChild(xmlShiftMod);
XmlNode xmlLaunchProgram = m_Xdoc.CreateNode(XmlNodeType.Element, "LaunchProgram", null); xmlLaunchProgram.InnerText = launchProgram[device].ToString(); Node.AppendChild(xmlLaunchProgram);
XmlNode xmlDinput = m_Xdoc.CreateNode(XmlNodeType.Element, "DinputOnly", null); xmlDinput.InnerText = dinputOnly[device].ToString(); Node.AppendChild(xmlDinput);
XmlNode xmlStartTouchpadOff = m_Xdoc.CreateNode(XmlNodeType.Element, "StartTouchpadOff", null); xmlStartTouchpadOff.InnerText = startTouchpadOff[device].ToString(); Node.AppendChild(xmlStartTouchpadOff);
XmlNode xmlUseTPforControls = m_Xdoc.CreateNode(XmlNodeType.Element, "UseTPforControls", null); xmlUseTPforControls.InnerText = useTPforControls[device].ToString(); Node.AppendChild(xmlUseTPforControls);
XmlNode xmlUseSAforMouse = m_Xdoc.CreateNode(XmlNodeType.Element, "UseSAforMouse", null); xmlUseSAforMouse.InnerText = useSAforMouse[device].ToString(); Node.AppendChild(xmlUseSAforMouse);
XmlNode xmlSATriggers = m_Xdoc.CreateNode(XmlNodeType.Element, "SATriggers", null); xmlSATriggers.InnerText = sATriggers[device].ToString(); Node.AppendChild(xmlSATriggers);
XmlNode xmlGyroSensitivity = m_Xdoc.CreateNode(XmlNodeType.Element, "GyroSensitivity", null); xmlGyroSensitivity.InnerText = gyroSensitivity[device].ToString(); Node.AppendChild(xmlGyroSensitivity);
XmlNode xmlGyroInvert = m_Xdoc.CreateNode(XmlNodeType.Element, "GyroInvert", null); xmlGyroInvert.InnerText = gyroInvert[device].ToString(); Node.AppendChild(xmlGyroInvert);
XmlNode xmlLSC = m_Xdoc.CreateNode(XmlNodeType.Element, "LSCurve", null); xmlLSC.InnerText = lsCurve[device].ToString(); Node.AppendChild(xmlLSC);
XmlNode xmlRSC = m_Xdoc.CreateNode(XmlNodeType.Element, "RSCurve", null); xmlRSC.InnerText = rsCurve[device].ToString(); Node.AppendChild(xmlRSC);
XmlNode xmlProfileActions = m_Xdoc.CreateNode(XmlNodeType.Element, "ProfileActions", null); xmlProfileActions.InnerText = string.Join("/", profileActions[device]); Node.AppendChild(xmlProfileActions);
XmlNode NodeControl = m_Xdoc.CreateNode(XmlNodeType.Element, "Control", null);
XmlNode Key = m_Xdoc.CreateNode(XmlNodeType.Element, "Key", null);
XmlNode Macro = m_Xdoc.CreateNode(XmlNodeType.Element, "Macro", null);
XmlNode KeyType = m_Xdoc.CreateNode(XmlNodeType.Element, "KeyType", null);
XmlNode Button = m_Xdoc.CreateNode(XmlNodeType.Element, "Button", null);
XmlNode Extras = m_Xdoc.CreateNode(XmlNodeType.Element, "Extras", null);
XmlNode NodeShiftControl = m_Xdoc.CreateNode(XmlNodeType.Element, "ShiftControl", null);
XmlNode ShiftKey = m_Xdoc.CreateNode(XmlNodeType.Element, "Key", null);
XmlNode ShiftMacro = m_Xdoc.CreateNode(XmlNodeType.Element, "Macro", null);
XmlNode ShiftKeyType = m_Xdoc.CreateNode(XmlNodeType.Element, "KeyType", null);
XmlNode ShiftButton = m_Xdoc.CreateNode(XmlNodeType.Element, "Button", null);
XmlNode ShiftExtras = m_Xdoc.CreateNode(XmlNodeType.Element, "Extras", null);
foreach (DS4ControlSettings dcs in ds4settings[device])
{
if (dcs.action != null)
{
XmlNode buttonNode;
string keyType = string.Empty;
if (dcs.action is string)
if (dcs.action.ToString() == "Unbound")
keyType += DS4KeyType.Unbound;
if (dcs.keyType.HasFlag(DS4KeyType.HoldMacro))
keyType += DS4KeyType.HoldMacro;
else if (dcs.keyType.HasFlag(DS4KeyType.Macro))
keyType += DS4KeyType.Macro;
if (dcs.keyType.HasFlag(DS4KeyType.Toggle))
keyType += DS4KeyType.Toggle;
if (dcs.keyType.HasFlag(DS4KeyType.ScanCode))
keyType += DS4KeyType.ScanCode;
if (keyType != string.Empty)
{
buttonNode = m_Xdoc.CreateNode(XmlNodeType.Element, dcs.control.ToString(), null);
buttonNode.InnerText = keyType;
KeyType.AppendChild(buttonNode);
}
buttonNode = m_Xdoc.CreateNode(XmlNodeType.Element, dcs.control.ToString(), null);
if (dcs.action is IEnumerable || dcs.action is int[] || dcs.action is ushort[])
{
int[] ii = (int[])dcs.action;
buttonNode.InnerText = string.Join("/", ii);
Macro.AppendChild(buttonNode);
}
else if (dcs.action is int || dcs.action is ushort || dcs.action is byte)
{
buttonNode.InnerText = dcs.action.ToString();
Key.AppendChild(buttonNode);
}
else if (dcs.action is string)
{
buttonNode.InnerText = dcs.action.ToString();
Button.AppendChild(buttonNode);
}
else if (dcs.action is X360Controls)
{
buttonNode.InnerText = getX360ControlString((X360Controls)dcs.action);
Button.AppendChild(buttonNode);
}
}
bool hasvalue = false;
if (!string.IsNullOrEmpty(dcs.extras))
foreach (string s in dcs.extras.Split(','))
if (s != "0")
{
hasvalue = true;
break;
}
if (hasvalue)
{
XmlNode extraNode = m_Xdoc.CreateNode(XmlNodeType.Element, dcs.control.ToString(), null);
extraNode.InnerText = dcs.extras;
Extras.AppendChild(extraNode);
}
if (dcs.shiftAction != null && dcs.shiftTrigger > 0)
{
XmlElement buttonNode;
string keyType = string.Empty;
if (dcs.shiftAction is string)
if (dcs.shiftAction.ToString() == "Unbound")
keyType += DS4KeyType.Unbound;
if (dcs.shiftKeyType.HasFlag(DS4KeyType.HoldMacro))
keyType += DS4KeyType.HoldMacro;
if (dcs.shiftKeyType.HasFlag(DS4KeyType.Macro))
keyType += DS4KeyType.Macro;
if (dcs.shiftKeyType.HasFlag(DS4KeyType.Toggle))
keyType += DS4KeyType.Toggle;
if (dcs.shiftKeyType.HasFlag(DS4KeyType.ScanCode))
keyType += DS4KeyType.ScanCode;
if (keyType != string.Empty)
{
buttonNode = m_Xdoc.CreateElement(dcs.control.ToString());
buttonNode.InnerText = keyType;
ShiftKeyType.AppendChild(buttonNode);
}
buttonNode = m_Xdoc.CreateElement(dcs.control.ToString());
buttonNode.SetAttribute("Trigger", dcs.shiftTrigger.ToString());
if (dcs.shiftAction is IEnumerable || dcs.shiftAction is int[] || dcs.shiftAction is ushort[])
{
int[] ii = (int[])dcs.shiftAction;
buttonNode.InnerText = string.Join("/", ii);
ShiftMacro.AppendChild(buttonNode);
}
else if (dcs.shiftAction is int || dcs.shiftAction is ushort || dcs.shiftAction is byte)
{
buttonNode.InnerText = dcs.shiftAction.ToString();
ShiftKey.AppendChild(buttonNode);
}
else if (dcs.shiftAction is string || dcs.shiftAction is X360Controls)
{
buttonNode.InnerText = dcs.shiftAction.ToString();
ShiftButton.AppendChild(buttonNode);
}
}
hasvalue = false;
if (!string.IsNullOrEmpty(dcs.shiftExtras))
foreach (string s in dcs.shiftExtras.Split(','))
if (s != "0")
{
hasvalue = true;
break;
}
if (hasvalue)
{
XmlNode extraNode = m_Xdoc.CreateNode(XmlNodeType.Element, dcs.control.ToString(), null);
extraNode.InnerText = dcs.shiftExtras;
ShiftExtras.AppendChild(extraNode);
}
}
Node.AppendChild(NodeControl);
if (Button.HasChildNodes)
NodeControl.AppendChild(Button);
if (Macro.HasChildNodes)
NodeControl.AppendChild(Macro);
if (Key.HasChildNodes)
NodeControl.AppendChild(Key);
if (Extras.HasChildNodes)
NodeControl.AppendChild(Extras);
if (KeyType.HasChildNodes)
NodeControl.AppendChild(KeyType);
if (NodeControl.HasChildNodes)
Node.AppendChild(NodeControl);
Node.AppendChild(NodeShiftControl);
if (ShiftButton.HasChildNodes)
NodeShiftControl.AppendChild(ShiftButton);
if (ShiftMacro.HasChildNodes)
NodeShiftControl.AppendChild(ShiftMacro);
if (ShiftKey.HasChildNodes)
NodeShiftControl.AppendChild(ShiftKey);
if (ShiftKeyType.HasChildNodes)
NodeShiftControl.AppendChild(ShiftKeyType);
if (ShiftExtras.HasChildNodes)
NodeShiftControl.AppendChild(ShiftExtras);
/*else if (xmlControls != null)
{
Node.AppendChild(xmlControls);
}*/
/*if (shiftModifier[device] > 0)
{
XmlNode NodeShiftControl = m_Xdoc.CreateNode(XmlNodeType.Element, "ShiftControl", null);
XmlNode ShiftKey = m_Xdoc.CreateNode(XmlNodeType.Element, "Key", null);
XmlNode ShiftMacro = m_Xdoc.CreateNode(XmlNodeType.Element, "Macro", null);
XmlNode ShiftKeyType = m_Xdoc.CreateNode(XmlNodeType.Element, "KeyType", null);
XmlNode ShiftButton = m_Xdoc.CreateNode(XmlNodeType.Element, "Button", null);
XmlNode ShiftExtras = m_Xdoc.CreateNode(XmlNodeType.Element, "Extras", null);
if (shiftbuttons != null)
{
foreach (var button in shiftbuttons)
{
// Save even if string (for xbox controller buttons)
if (button.Tag != null)
{
XmlNode buttonNode;
string keyType = String.Empty;
if (button.Tag is KeyValuePair)
if (((KeyValuePair)button.Tag).Key == "Unbound")
keyType += DS4KeyType.Unbound;
if (button.Font.Strikeout)
keyType += DS4KeyType.HoldMacro;
if (button.Font.Underline)
keyType += DS4KeyType.Macro;
if (button.Font.Italic)
keyType += DS4KeyType.Toggle;
if (button.Font.Bold)
keyType += DS4KeyType.ScanCode;
if (keyType != String.Empty)
{
buttonNode = m_Xdoc.CreateNode(XmlNodeType.Element, button.Name, null);
buttonNode.InnerText = keyType;
ShiftKeyType.AppendChild(buttonNode);
}
string[] extras;
buttonNode = m_Xdoc.CreateNode(XmlNodeType.Element, button.Name, null);
if (button.Tag is KeyValuePair, string> || button.Tag is KeyValuePair || button.Tag is KeyValuePair)
{
KeyValuePair tag = (KeyValuePair)button.Tag;
int[] ii = tag.Key;
buttonNode.InnerText = string.Join("/", ii);
ShiftMacro.AppendChild(buttonNode);
extras = tag.Value.Split(',');
}
else if (button.Tag is KeyValuePair || button.Tag is KeyValuePair || button.Tag is KeyValuePair)
{
KeyValuePair tag = (KeyValuePair)button.Tag;
buttonNode.InnerText = tag.Key.ToString();
ShiftKey.AppendChild(buttonNode);
extras = tag.Value.Split(',');
}
else if (button.Tag is KeyValuePair)
{
KeyValuePair tag = (KeyValuePair)button.Tag;
buttonNode.InnerText = tag.Key;
ShiftButton.AppendChild(buttonNode);
extras = tag.Value.Split(',');
}
else
{
KeyValuePair