using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Drawing;
using DS4Library;
using System.Security.Principal;
namespace DS4Control
{
[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 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
{
get { return m_Time; }
}
public String Data
{
get { return m_Data; }
}
public bool Warning
{
get { return warning; }
}
}
public class MappingDoneEventArgs : EventArgs
{
protected int deviceNum = -1;
public MappingDoneEventArgs(int DeviceID)
{
deviceNum = DeviceID;
}
public int DeviceID
{
get { return 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 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);
}
public static void setButtonMouseSensitivity(int device, int data)
{
m_Config.buttonMouseSensitivity[device] = data;
}
public static int getButtonMouseSensitivity(int device)
{
return m_Config.buttonMouseSensitivity[device];
}
public static DS4Color loadColor(int device)
{
DS4Color color = new DS4Color();
color.red = m_Config.m_Leds[device][0];
color.green = m_Config.m_Leds[device][1];
color.blue = m_Config.m_Leds[device][2];
return color;
}
public static void saveColor(int device, byte red, byte green, byte blue)
{
m_Config.m_Leds[device][0] = red;
m_Config.m_Leds[device][1] = green;
m_Config.m_Leds[device][2] = blue;
}
public static byte loadRumbleBoost(int device)
{
return m_Config.rumble[device];
}
public static void saveRumbleBoost(int device, byte boost)
{
m_Config.rumble[device] = boost;
}
public static double getRainbow(int device)
{
return m_Config.rainbow[device];
}
public static void setRainbow(int device, double speed)
{
m_Config.rainbow[device] = speed;
}
public static bool getFlushHIDQueue(int device)
{
return m_Config.flushHIDQueue[device];
}
public static void setFlushHIDQueue(int device, bool setting)
{
m_Config.flushHIDQueue[device] = setting;
}
public static int getIdleDisconnectTimeout(int device)
{
return m_Config.idleDisconnectTimeout[device];
}
public static void setIdleDisconnectTimeout(int device, int seconds)
{
m_Config.idleDisconnectTimeout[device] = seconds;
}
public static byte getTouchSensitivity(int device)
{
return m_Config.touchSensitivity[device];
}
public static void setTouchSensitivity(int device, byte sen)
{
m_Config.touchSensitivity[device] = sen;
}
public static void setFlashWhenLowBattery(int device, bool flash)
{
m_Config.flashLedLowBattery[device] = flash;
}
public static bool getFlashWhenLowBattery(int device)
{
return m_Config.flashLedLowBattery[device];
}
public static void setFlashAt(int device, int when)
{
m_Config.flashAt[device] = when;
}
public static int getFlashAt(int device)
{
return m_Config.flashAt[device];
}
public static void setLedAsBatteryIndicator(int device, bool ledAsBattery)
{
m_Config.ledAsBattery[device] = ledAsBattery;
}
public static bool getLedAsBatteryIndicator(int device)
{
return m_Config.ledAsBattery[device];
}
public static void setChargingType(int device, int type)
{
m_Config.chargingType[device] = type;
}
public static int getChargingType(int device)
{
return m_Config.chargingType[device];
}
public static void setDinputOnly(int device, bool dinput)
{
m_Config.dinputOnly[device] = dinput;
}
public static bool getDinputOnly(int device)
{
return m_Config.dinputOnly[device];
}
public static void setStartTouchpadOff(int device, bool off)
{
m_Config.startTouchpadOff[device] = off;
}
public static bool getStartTouchpadOff(int device)
{
return m_Config.startTouchpadOff[device];
}
public static void setUseTPforControls(int device, bool data)
{
m_Config.useTPforControls[device] = data;
}
public static bool getUseTPforControls(int device)
{
return m_Config.useTPforControls[device];
}
public static void setUseExclusiveMode(bool exclusive)
{
m_Config.useExclusiveMode = exclusive;
}
public static bool getUseExclusiveMode()
{
return m_Config.useExclusiveMode;
}
public static void setLastChecked(DateTime data)
{
m_Config.lastChecked = data;
}
public static DateTime getLastChecked()
{
return m_Config.lastChecked;
}
public static void setCheckWhen(int data)
{
m_Config.CheckWhen = data;
}
public static int getCheckWhen()
{
return m_Config.CheckWhen;
}
public static void setNotifications(bool data)
{
m_Config.notifications = data;
}
public static bool getNotifications()
{
return m_Config.notifications;
}
public static void setDCBTatStop(bool data)
{
m_Config.disconnectBTAtStop = data;
}
public static bool getDCBTatStop()
{
return m_Config.disconnectBTAtStop;
}
public static void setSwipeProfiles(bool data)
{
m_Config.swipeProfiles = data;
}
public static bool getSwipeProfiles()
{
return m_Config.swipeProfiles;
}
public static void setDS4Mapping(bool data)
{
m_Config.ds4Mapping = data;
}
public static bool getDS4Mapping()
{
return m_Config.ds4Mapping;
}
public static void setQuickCharge(bool data)
{
m_Config.quickCharge = data;
}
public static bool getQuickCharge()
{
return m_Config.quickCharge;
}
public static void setFirstXinputPort(int data)
{
m_Config.firstXinputPort = data;
}
public static int getFirstXinputPort()
{
return m_Config.firstXinputPort;
}
public static void setCloseMini(bool data)
{
m_Config.closeMini = data;
}
public static bool getCloseMini()
{
return m_Config.closeMini;
}
public static void saveLowColor(int device, byte red, byte green, byte blue)
{
m_Config.m_LowLeds[device][0] = red;
m_Config.m_LowLeds[device][1] = green;
m_Config.m_LowLeds[device][2] = blue;
}
public static DS4Color loadLowColor(int device)
{
DS4Color color = new DS4Color();
color.red = m_Config.m_LowLeds[device][0];
color.green = m_Config.m_LowLeds[device][1];
color.blue = m_Config.m_LowLeds[device][2];
return color;
}
public static void saveChargingColor(int device, byte red, byte green, byte blue)
{
m_Config.m_ChargingLeds[device][0] = red;
m_Config.m_ChargingLeds[device][1] = green;
m_Config.m_ChargingLeds[device][2] = blue;
}
public static DS4Color loadChargingColor(int device)
{
DS4Color color = new DS4Color();
color.red = m_Config.m_ChargingLeds[device][0];
color.green = m_Config.m_ChargingLeds[device][1];
color.blue = m_Config.m_ChargingLeds[device][2];
return color;
}
public static void saveShiftColor(int device, byte red, byte green, byte blue)
{
m_Config.m_ShiftLeds[device][0] = red;
m_Config.m_ShiftLeds[device][1] = green;
m_Config.m_ShiftLeds[device][2] = blue;
}
public static DS4Color loadShiftColor(int device)
{
DS4Color color = new DS4Color();
color.red = m_Config.m_ShiftLeds[device][0];
color.green = m_Config.m_ShiftLeds[device][1];
color.blue = m_Config.m_ShiftLeds[device][2];
return color;
}
public static void setShiftColorOn(int device, bool on)
{
m_Config.shiftColorOn[device] = on;
}
public static bool getShiftColorOn(int device)
{
return m_Config.shiftColorOn[device];
}
public static void saveFlashColor(int device, byte red, byte green, byte blue)
{
m_Config.m_FlashLeds[device][0] = red;
m_Config.m_FlashLeds[device][1] = green;
m_Config.m_FlashLeds[device][2] = blue;
}
public static DS4Color loadFlashColor(int device)
{
DS4Color color = new DS4Color();
color.red = m_Config.m_FlashLeds[device][0];
color.green = m_Config.m_FlashLeds[device][1];
color.blue = m_Config.m_FlashLeds[device][2];
return color;
}
public static void setTapSensitivity(int device, byte sen)
{
m_Config.tapSensitivity[device] = sen;
}
public static byte getTapSensitivity(int device)
{
return m_Config.tapSensitivity[device];
}
public static void setDoubleTap(int device, bool on)
{
m_Config.doubleTap[device] = on;
}
public static bool getDoubleTap(int device)
{
return m_Config.doubleTap[device];
}
public static bool getTap(int device)
{
if (m_Config.tapSensitivity[device] == 0)
return false;
else
return true;
}
public static void setScrollSensitivity(int device, int sen)
{
m_Config.scrollSensitivity[device] = sen;
}
public static int getScrollSensitivity(int device)
{
return m_Config.scrollSensitivity[device];
}
public static void setLowerRCOn(int device, bool twoFingerRC)
{
m_Config.lowerRCOn[device] = twoFingerRC;
}
public static bool getLowerRCOn(int device)
{
return m_Config.lowerRCOn[device];
}
public static void setTouchpadJitterCompensation(int device, bool enabled)
{
m_Config.touchpadJitterCompensation[device] = enabled;
}
public static bool getTouchpadJitterCompensation(int device)
{
return m_Config.touchpadJitterCompensation[device];
}
public static void setStartMinimized(bool startMinimized)
{
m_Config.startMinimized = startMinimized;
}
public static bool getStartMinimized()
{
return m_Config.startMinimized;
}
public static void setFormWidth(int size)
{
m_Config.formWidth = size;
}
public static int getFormWidth()
{
return m_Config.formWidth;
}
public static void setFormHeight(int size)
{
m_Config.formHeight = size;
}
public static int getFormHeight()
{
return m_Config.formHeight;
}
public static double getL2Deadzone(int device)
{
return m_Config.l2Deadzone[device];
}
public static void setL2Deadzone(int device, byte value)
{
m_Config.l2Deadzone[device] = value;
}
public static double getR2Deadzone(int device)
{
return m_Config.r2Deadzone[device];
}
public static void setR2Deadzone(int device, byte value)
{
m_Config.r2Deadzone[device] = value;
}
public static double getSXDeadzone(int device)
{
return m_Config.SXDeadzone[device];
}
public static void setSXDeadzone(int device, double value)
{
m_Config.SXDeadzone[device] = value;
}
public static double getSZDeadzone(int device)
{
return m_Config.SZDeadzone[device];
}
public static void setSZDeadzone(int device, double value)
{
m_Config.SZDeadzone[device] = value;
}
public static byte getLSDeadzone(int device)
{
return m_Config.LSDeadzone[device];
}
public static void setLSDeadzone(int device, byte value)
{
m_Config.LSDeadzone[device] = value;
}
public static byte getRSDeadzone(int device)
{
return m_Config.RSDeadzone[device];
}
public static void setRSDeadzone(int device, byte value)
{
m_Config.RSDeadzone[device] = value;
}
public static int getLSCurve(int device)
{
return m_Config.lsCurve[device];
}
public static void setLSCurve(int device, int value)
{
m_Config.lsCurve[device] = value;
}
public static int getRSCurve(int device)
{
return m_Config.rsCurve[device];
}
public static void setRSCurve(int device, int value)
{
m_Config.rsCurve[device] = value;
}
public static bool getMouseAccel(int device)
{
return m_Config.mouseAccel[device];
}
public static void setMouseAccel(int device, bool value)
{
m_Config.mouseAccel[device] = value;
}
public static int getShiftModifier (int device)
{
return m_Config.shiftModifier[device];
}
public static void setShiftModifier(int device, int value)
{
m_Config.shiftModifier[device] = value;
}
public static string getLaunchProgram(int device)
{
return m_Config.launchProgram[device];
}
public static void setLaunchProgram(int device, string value)
{
m_Config.launchProgram[device] = value;
}
public static void setAProfile(int device, string filepath)
{
m_Config.profilePath[device] = appdatapath + @"\Profiles\" + filepath + ".xml";
}
public static string getAProfile(int device)
{
return m_Config.profilePath[device];
}
public static X360Controls getCustomButton(int device, DS4Controls controlName)
{
return m_Config.GetCustomButton(device, controlName);
}
public static ushort getCustomKey(int device, DS4Controls controlName)
{
return m_Config.GetCustomKey(device, controlName);
}
public static string getCustomMacro(int device, DS4Controls controlName)
{
return m_Config.GetCustomMacro(device, controlName);
}
public static string getCustomExtras(int device, DS4Controls controlName)
{
return m_Config.GetCustomExtras(device, controlName);
}
public static DS4KeyType getCustomKeyType(int device, DS4Controls controlName)
{
return m_Config.GetCustomKeyType(device, controlName);
}
public static bool getHasCustomKeysorButtons(int device)
{
return m_Config.customMapButtons[device].Count > 0
|| m_Config.customMapKeys[device].Count > 0;
}
public static bool getHasCustomExtras(int device)
{
return m_Config.customMapExtras[device].Count > 0;
}
public static Dictionary getCustomButtons(int device)
{
return m_Config.customMapButtons[device];
}
public static Dictionary getCustomKeys(int device)
{
return m_Config.customMapKeys[device];
}
public static Dictionary getCustomMacros(int device)
{
return m_Config.customMapMacros[device];
}
public static Dictionary getCustomExtras(int device)
{
return m_Config.customMapExtras[device];
}
public static Dictionary getCustomKeyTypes(int device)
{
return m_Config.customMapKeyTypes[device];
}
public static X360Controls getShiftCustomButton(int device, DS4Controls controlName)
{
return m_Config.GetShiftCustomButton(device, controlName);
}
public static ushort getShiftCustomKey(int device, DS4Controls controlName)
{
return m_Config.GetShiftCustomKey(device, controlName);
}
public static string getShiftCustomMacro(int device, DS4Controls controlName)
{
return m_Config.GetShiftCustomMacro(device, controlName);
}
public static string getShiftCustomExtras(int device, DS4Controls controlName)
{
return m_Config.GetShiftCustomExtras(device, controlName);
}
public static DS4KeyType getShiftCustomKeyType(int device, DS4Controls controlName)
{
return m_Config.GetShiftCustomKeyType(device, controlName);
}
public static bool getHasShiftCustomKeysorButtons(int device)
{
return m_Config.shiftCustomMapButtons[device].Count > 0
|| m_Config.shiftCustomMapKeys[device].Count > 0;
}
public static bool getHasShiftCustomExtras(int device)
{
return m_Config.shiftCustomMapExtras[device].Count > 0;
}
public static Dictionary getShiftCustomButtons(int device)
{
return m_Config.shiftCustomMapButtons[device];
}
public static Dictionary getShiftCustomKeys(int device)
{
return m_Config.shiftCustomMapKeys[device];
}
public static Dictionary getShiftCustomMacros(int device)
{
return m_Config.shiftCustomMapMacros[device];
}
public static Dictionary getShiftCustomExtras(int device)
{
return m_Config.shiftCustomMapExtras[device];
}
public static Dictionary getShiftCustomKeyTypes(int device)
{
return m_Config.shiftCustomMapKeyTypes[device];
}
public static bool Load()
{
return m_Config.Load();
}
public static void LoadProfile(int device, System.Windows.Forms.Control[] buttons, System.Windows.Forms.Control[] shiftbuttons, bool launchprogram, Control control)
{
m_Config.LoadProfile(device, buttons, shiftbuttons, launchprogram, control);
tempprofilename[device] = string.Empty;
}
public static void LoadProfile(int device, bool launchprogram, Control control)
{
m_Config.LoadProfile(device, null, null, launchprogram, control);
tempprofilename[device] = string.Empty;
}
public static void LoadTempProfile(int device, string name, bool launchprogram, Control control)
{
m_Config.LoadProfile(device, null, null, launchprogram, control, appdatapath + @"\Profiles\" + name + ".xml");
tempprofilename[device] = name;
}
public static bool Save()
{
return m_Config.Save();
}
public static void SaveProfile(int device, string propath, System.Windows.Forms.Control[] buttons, System.Windows.Forms.Control[] shiftbuttons)
{
m_Config.SaveProfile(device, propath, buttons, shiftbuttons);
}
private static byte applyRatio(byte b1, byte b2, double r)
{
if (r > 100)
r = 100;
else if (r < 0)
r = 0;
uint ratio = (uint)r;
if (b1 > b2)
{
ratio = 100 - (uint)r;
}
byte bmax = Math.Max(b1, b2);
byte bmin = Math.Min(b1, b2);
byte bdif = (byte)(bmax - bmin);
return (byte)(bmin + (bdif * ratio / 100));
}
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 static List GetProfileActions(int device)
{
return m_Config.profileActions[device];
}
public static void SetProfileAtions(int device, List pactions)
{
m_Config.profileActions[device] = pactions;
}
public static void SaveAction(string name, string controls, int mode, string details, bool edit, string ucontrols = "")
{
m_Config.SaveAction(name, controls, mode, details, edit, ucontrols);
}
public static void RemoveAction(string name)
{
m_Config.RemoveAction(name);
}
public static bool LoadActions()
{
return m_Config.LoadActions();
}
public static List GetActions()
{
return m_Config.actions;
}
public static int GetActionIndexOf(string name)
{
for (int i = 0; i < m_Config.actions.Count; i++)
if (m_Config.actions[i].name == name)
return i;
return -1;
}
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 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 = { true, true, true, true, true };
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 Boolean[] flashLedLowBattery = { false, false, false, false, false };
public Byte[] l2Deadzone = { 0, 0, 0, 0, 0}, r2Deadzone = { 0, 0, 0, 0, 0};
public String[] profilePath = { String.Empty, String.Empty, String.Empty, String.Empty, String.Empty };
public Byte[] rumble = { 100, 100, 100, 100, 100 };
public Byte[] touchSensitivity = { 100, 100, 100, 100, 100 };
public Byte[] LSDeadzone = { 0, 0, 0, 0, 0 }, RSDeadzone = { 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 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 int[] shiftModifier = { 0, 0, 0, 0, 0 };
public bool[] mouseAccel = { true, true, true, true, true };
public Byte[][] m_LowLeds = new Byte[][]
{
new Byte[] {0,0,0},
new Byte[] {0,0,0},
new Byte[] {0,0,0},
new Byte[] {0,0,0},
new Byte[] {0,0,0}
};
public Byte[][] m_Leds = new Byte[][]
{
new Byte[] {0,0,255},
new Byte[] {255,0,0},
new Byte[] {0,255,0},
new Byte[] {255,0,255},
new Byte[] {255,255,255}
};
public Byte[][] m_ChargingLeds = new Byte[][]
{
new Byte[] {0,0,0},
new Byte[] {0,0,0},
new Byte[] {0,0,0},
new Byte[] {0,0,0},
new Byte[] {0,0,0}
};
public Byte[][] m_ShiftLeds = new Byte[][]
{
new Byte[] {0,0,0},
new Byte[] {0,0,0},
new Byte[] {0,0,0},
new Byte[] {0,0,0},
new Byte[] {0,0,0}
};
public Byte[][] m_FlashLeds = new Byte[][]
{
new Byte[] {0,0,0},
new Byte[] {0,0,0},
new Byte[] {0,0,0},
new Byte[] {0,0,0},
new Byte[] {0,0,0}
};
public bool[] shiftColorOn = { false, false, false, false, false };
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 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 bool notifications = true;
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 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 BackingStore()
{
for (int i = 0; i < 5; i++)
{
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");
}
}
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 Boolean SaveProfile(int device, String propath, System.Windows.Forms.Control[] buttons, System.Windows.Forms.Control[] shiftbuttons)
{
Boolean 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][0].ToString() + "," + m_Leds[device][1].ToString() + "," + m_Leds[device][2].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, "lowBatteryFlash", null); xmlLowBatteryFlash.InnerText = flashLedLowBattery[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][0].ToString() + "," + m_LowLeds[device][1].ToString() + "," + m_LowLeds[device][2].ToString();
Node.AppendChild(xmlLowColor);
XmlNode xmlChargingColor = m_Xdoc.CreateNode(XmlNodeType.Element, "ChargingColor", null);
xmlChargingColor.InnerText = m_ChargingLeds[device][0].ToString() + "," + m_ChargingLeds[device][1].ToString() + "," + m_ChargingLeds[device][2].ToString();
Node.AppendChild(xmlChargingColor);
XmlNode xmlShiftColor = m_Xdoc.CreateNode(XmlNodeType.Element, "ShiftColor", null);
xmlShiftColor.InnerText = m_ShiftLeds[device][0].ToString() + "," + m_ShiftLeds[device][1].ToString() + "," + m_ShiftLeds[device][2].ToString();
Node.AppendChild(xmlShiftColor);
XmlNode xmlShiftColorOn = m_Xdoc.CreateNode(XmlNodeType.Element, "ShiftColorOn", null); xmlShiftColorOn.InnerText = shiftColorOn[device].ToString(); Node.AppendChild(xmlShiftColorOn);
XmlNode xmlFlashColor = m_Xdoc.CreateNode(XmlNodeType.Element, "FlashColor", null);
xmlFlashColor.InnerText = m_FlashLeds[device][0].ToString() + "," + m_FlashLeds[device][1].ToString() + "," + m_FlashLeds[device][2].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 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 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 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 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);
if (buttons != null)
{
foreach (var button in buttons)
{
// 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;
KeyType.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);
Macro.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();
Key.AppendChild(buttonNode);
extras = tag.Value.Split(',');
}
else if (button.Tag is KeyValuePair)
{
KeyValuePair tag = (KeyValuePair)button.Tag;
buttonNode.InnerText = tag.Key;
Button.AppendChild(buttonNode);
extras = tag.Value.Split(',');
}
else
{
KeyValuePair