mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-12-25 08:01:49 +01:00
Move if statements around and replace some foreach loops
This commit is contained in:
parent
7bb6a6cdbc
commit
fd2eb0f006
@ -768,7 +768,8 @@ namespace DS4Windows
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
static bool[] held = new bool[4];
|
static bool[] held = new bool[4];
|
||||||
static int[] oldmouse = new int[4] { -1, -1, -1, -1 };
|
static int[] oldmouse = new int[4] { -1, -1, -1, -1 };
|
||||||
public static void MapCustom(int device, DS4State cState, DS4State MappedState, DS4StateExposed eState, Mouse tp, ControlService ctrl)
|
public static void MapCustom(int device, DS4State cState, DS4State MappedState, DS4StateExposed eState,
|
||||||
|
Mouse tp, ControlService ctrl)
|
||||||
{
|
{
|
||||||
/* TODO: This method is slow sauce. Find ways to speed up action execution */
|
/* TODO: This method is slow sauce. Find ways to speed up action execution */
|
||||||
MappedState.LX = 127;
|
MappedState.LX = 127;
|
||||||
@ -1290,7 +1291,8 @@ namespace DS4Windows
|
|||||||
{
|
{
|
||||||
return shift ? false : GetDS4Action(device, dc, false) == null;
|
return shift ? false : GetDS4Action(device, dc, false) == null;
|
||||||
}
|
}
|
||||||
public static async void MapCustomAction(int device, DS4State cState, DS4State MappedState, DS4StateExposed eState, Mouse tp, ControlService ctrl)
|
public static async void MapCustomAction(int device, DS4State cState, DS4State MappedState,
|
||||||
|
DS4StateExposed eState, Mouse tp, ControlService ctrl)
|
||||||
{
|
{
|
||||||
/* TODO: This method is slow sauce. Find ways to speed up action execution */
|
/* TODO: This method is slow sauce. Find ways to speed up action execution */
|
||||||
try
|
try
|
||||||
@ -1329,8 +1331,10 @@ namespace DS4Windows
|
|||||||
{
|
{
|
||||||
triggeractivated = false;
|
triggeractivated = false;
|
||||||
bool subtriggeractivated = true;
|
bool subtriggeractivated = true;
|
||||||
foreach (DS4Controls dc in action.trigger)
|
//foreach (DS4Controls dc in action.trigger)
|
||||||
|
for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
|
||||||
{
|
{
|
||||||
|
DS4Controls dc = action.trigger[i];
|
||||||
if (!getBoolMapping(device, dc, cState, eState, tp))
|
if (!getBoolMapping(device, dc, cState, eState, tp))
|
||||||
{
|
{
|
||||||
subtriggeractivated = false;
|
subtriggeractivated = false;
|
||||||
@ -1351,8 +1355,10 @@ namespace DS4Windows
|
|||||||
{
|
{
|
||||||
triggeractivated = false;
|
triggeractivated = false;
|
||||||
bool subtriggeractivated = true;
|
bool subtriggeractivated = true;
|
||||||
foreach (DS4Controls dc in action.trigger)
|
//foreach (DS4Controls dc in action.trigger)
|
||||||
|
for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
|
||||||
{
|
{
|
||||||
|
DS4Controls dc = action.trigger[i];
|
||||||
if (!getBoolMapping(device, dc, cState, eState, tp))
|
if (!getBoolMapping(device, dc, cState, eState, tp))
|
||||||
{
|
{
|
||||||
subtriggeractivated = false;
|
subtriggeractivated = false;
|
||||||
@ -1368,8 +1374,10 @@ namespace DS4Windows
|
|||||||
{
|
{
|
||||||
triggeractivated = false;
|
triggeractivated = false;
|
||||||
bool subtriggeractivated = true;
|
bool subtriggeractivated = true;
|
||||||
foreach (DS4Controls dc in action.trigger)
|
//foreach (DS4Controls dc in action.trigger)
|
||||||
|
for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
|
||||||
{
|
{
|
||||||
|
DS4Controls dc = action.trigger[i];
|
||||||
if (!getBoolMapping(device, dc, cState, eState, tp))
|
if (!getBoolMapping(device, dc, cState, eState, tp))
|
||||||
{
|
{
|
||||||
subtriggeractivated = false;
|
subtriggeractivated = false;
|
||||||
@ -1387,21 +1395,27 @@ namespace DS4Windows
|
|||||||
oldnowKeyAct[device] = DateTime.MinValue;
|
oldnowKeyAct[device] = DateTime.MinValue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
foreach (DS4Controls dc in action.trigger)
|
|
||||||
{
|
{
|
||||||
|
//foreach (DS4Controls dc in action.trigger)
|
||||||
|
for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
|
||||||
|
{
|
||||||
|
DS4Controls dc = action.trigger[i];
|
||||||
if (!getBoolMapping(device, dc, cState, eState, tp))
|
if (!getBoolMapping(device, dc, cState, eState, tp))
|
||||||
{
|
{
|
||||||
triggeractivated = false;
|
triggeractivated = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool utriggeractivated = true;
|
bool utriggeractivated = true;
|
||||||
int uTriggerCount = action.uTrigger.Count;
|
int uTriggerCount = action.uTrigger.Count;
|
||||||
if (action.typeID == SpecialAction.ActionTypeId.Key && uTriggerCount > 0)
|
if (action.typeID == SpecialAction.ActionTypeId.Key && uTriggerCount > 0)
|
||||||
{
|
{
|
||||||
foreach (DS4Controls dc in action.uTrigger)
|
//foreach (DS4Controls dc in action.uTrigger)
|
||||||
|
for (int i = 0, arlen = action.uTrigger.Count; i < arlen; i++)
|
||||||
{
|
{
|
||||||
|
DS4Controls dc = action.uTrigger[i];
|
||||||
if (!getBoolMapping(device, dc, cState, eState, tp))
|
if (!getBoolMapping(device, dc, cState, eState, tp))
|
||||||
{
|
{
|
||||||
utriggeractivated = false;
|
utriggeractivated = false;
|
||||||
@ -1411,8 +1425,13 @@ namespace DS4Windows
|
|||||||
if (action.pressRelease) utriggeractivated = !utriggeractivated;
|
if (action.pressRelease) utriggeractivated = !utriggeractivated;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (triggeractivated && action.typeID == SpecialAction.ActionTypeId.Program)
|
bool actionFound = false;
|
||||||
|
if (triggeractivated)
|
||||||
{
|
{
|
||||||
|
if (action.typeID == SpecialAction.ActionTypeId.Program)
|
||||||
|
{
|
||||||
|
actionFound = true;
|
||||||
|
|
||||||
if (!actionDone[index].dev[device])
|
if (!actionDone[index].dev[device])
|
||||||
{
|
{
|
||||||
actionDone[index].dev[device] = true;
|
actionDone[index].dev[device] = true;
|
||||||
@ -1422,15 +1441,19 @@ namespace DS4Windows
|
|||||||
Process.Start(action.details);
|
Process.Start(action.details);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (triggeractivated && action.typeID == SpecialAction.ActionTypeId.Profile)
|
else if (action.typeID == SpecialAction.ActionTypeId.Profile)
|
||||||
{
|
{
|
||||||
|
actionFound = true;
|
||||||
|
|
||||||
if (!actionDone[index].dev[device] && string.IsNullOrEmpty(tempprofilename[device]))
|
if (!actionDone[index].dev[device] && string.IsNullOrEmpty(tempprofilename[device]))
|
||||||
{
|
{
|
||||||
actionDone[index].dev[device] = true;
|
actionDone[index].dev[device] = true;
|
||||||
untriggeraction[device] = action;
|
untriggeraction[device] = action;
|
||||||
untriggerindex[device] = index;
|
untriggerindex[device] = index;
|
||||||
foreach (DS4Controls dc in action.trigger)
|
//foreach (DS4Controls dc in action.trigger)
|
||||||
|
for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
|
||||||
{
|
{
|
||||||
|
DS4Controls dc = action.trigger[i];
|
||||||
DS4ControlSettings dcs = getDS4CSetting(device, dc);
|
DS4ControlSettings dcs = getDS4CSetting(device, dc);
|
||||||
if (dcs.action != null)
|
if (dcs.action != null)
|
||||||
{
|
{
|
||||||
@ -1439,8 +1462,8 @@ namespace DS4Windows
|
|||||||
else if (dcs.actionType == DS4ControlSettings.ActionType.Macro)
|
else if (dcs.actionType == DS4ControlSettings.ActionType.Macro)
|
||||||
{
|
{
|
||||||
int[] keys = (int[])dcs.action;
|
int[] keys = (int[])dcs.action;
|
||||||
for (int i = 0, keysLen = keys.Length; i < keysLen; i++)
|
for (int j = 0, keysLen = keys.Length; j < keysLen; j++)
|
||||||
InputMethods.performKeyRelease((ushort)keys[i]);
|
InputMethods.performKeyRelease((ushort)keys[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1448,21 +1471,30 @@ namespace DS4Windows
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (triggeractivated && action.typeID == SpecialAction.ActionTypeId.Macro)
|
else if (action.typeID == SpecialAction.ActionTypeId.Macro)
|
||||||
{
|
{
|
||||||
|
actionFound = true;
|
||||||
|
|
||||||
if (!actionDone[index].dev[device])
|
if (!actionDone[index].dev[device])
|
||||||
{
|
{
|
||||||
DS4KeyType keyType = action.keyType;
|
DS4KeyType keyType = action.keyType;
|
||||||
actionDone[index].dev[device] = true;
|
actionDone[index].dev[device] = true;
|
||||||
foreach (DS4Controls dc in action.trigger)
|
//foreach (DS4Controls dc in action.trigger)
|
||||||
|
for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
|
||||||
|
{
|
||||||
|
DS4Controls dc = action.trigger[i];
|
||||||
resetToDefaultValue(dc, MappedState);
|
resetToDefaultValue(dc, MappedState);
|
||||||
|
}
|
||||||
|
|
||||||
PlayMacro(device, macroControl, String.Join("/", action.macro), DS4Controls.None, keyType);
|
PlayMacro(device, macroControl, String.Join("/", action.macro), DS4Controls.None, keyType);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
EndMacro(device, macroControl, String.Join("/", action.macro), DS4Controls.None);
|
EndMacro(device, macroControl, String.Join("/", action.macro), DS4Controls.None);
|
||||||
}
|
}
|
||||||
else if (triggeractivated && action.typeID == SpecialAction.ActionTypeId.Key)
|
else if (action.typeID == SpecialAction.ActionTypeId.Key)
|
||||||
{
|
{
|
||||||
|
actionFound = true;
|
||||||
|
|
||||||
if (uTriggerCount == 0 || (uTriggerCount > 0 && untriggerindex[device] == -1 && !actionDone[index].dev[device]))
|
if (uTriggerCount == 0 || (uTriggerCount > 0 && untriggerindex[device] == -1 && !actionDone[index].dev[device]))
|
||||||
{
|
{
|
||||||
actionDone[index].dev[device] = true;
|
actionDone[index].dev[device] = true;
|
||||||
@ -1486,22 +1518,10 @@ namespace DS4Windows
|
|||||||
InputMethods.performKeyPress(key);
|
InputMethods.performKeyPress(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (uTriggerCount > 0 && utriggeractivated && action.typeID == SpecialAction.ActionTypeId.Key)
|
else if (action.typeID == SpecialAction.ActionTypeId.DisconnectBT)
|
||||||
{
|
|
||||||
if (untriggerindex[device] > -1 && !actionDone[index].dev[device])
|
|
||||||
{
|
|
||||||
actionDone[index].dev[device] = true;
|
|
||||||
untriggerindex[device] = -1;
|
|
||||||
ushort key;
|
|
||||||
ushort.TryParse(action.details, out key);
|
|
||||||
if (action.keyType.HasFlag(DS4KeyType.ScanCode))
|
|
||||||
InputMethods.performSCKeyRelease(key);
|
|
||||||
else
|
|
||||||
InputMethods.performKeyRelease(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (triggeractivated && action.typeID == SpecialAction.ActionTypeId.DisconnectBT)
|
|
||||||
{
|
{
|
||||||
|
actionFound = true;
|
||||||
|
|
||||||
DS4Device d = ctrl.DS4Controllers[device];
|
DS4Device d = ctrl.DS4Controllers[device];
|
||||||
if (!d.isCharging())
|
if (!d.isCharging())
|
||||||
{
|
{
|
||||||
@ -1511,8 +1531,10 @@ namespace DS4Windows
|
|||||||
d.DisconnectBT();
|
d.DisconnectBT();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (DS4Controls dc in action.trigger)
|
//foreach (DS4Controls dc in action.trigger)
|
||||||
|
for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
|
||||||
{
|
{
|
||||||
|
DS4Controls dc = action.trigger[i];
|
||||||
DS4ControlSettings dcs = getDS4CSetting(device, dc);
|
DS4ControlSettings dcs = getDS4CSetting(device, dc);
|
||||||
if (dcs.action != null)
|
if (dcs.action != null)
|
||||||
{
|
{
|
||||||
@ -1521,16 +1543,18 @@ namespace DS4Windows
|
|||||||
else if (dcs.actionType == DS4ControlSettings.ActionType.Macro)
|
else if (dcs.actionType == DS4ControlSettings.ActionType.Macro)
|
||||||
{
|
{
|
||||||
int[] keys = (int[])dcs.action;
|
int[] keys = (int[])dcs.action;
|
||||||
for (int i = 0, keysLen = keys.Length; i < keysLen; i++)
|
for (int j = 0, keysLen = keys.Length; j < keysLen; j++)
|
||||||
InputMethods.performKeyRelease((ushort)keys[i]);
|
InputMethods.performKeyRelease((ushort)keys[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (triggeractivated && action.typeID == SpecialAction.ActionTypeId.BatteryCheck)
|
else if (action.typeID == SpecialAction.ActionTypeId.BatteryCheck)
|
||||||
{
|
{
|
||||||
|
actionFound = true;
|
||||||
|
|
||||||
string[] dets = action.details.Split('|');
|
string[] dets = action.details.Split('|');
|
||||||
if (dets.Length == 1)
|
if (dets.Length == 1)
|
||||||
dets = action.details.Split(',');
|
dets = action.details.Split(',');
|
||||||
@ -1555,8 +1579,12 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
actionDone[index].dev[device] = true;
|
actionDone[index].dev[device] = true;
|
||||||
}
|
}
|
||||||
else if (!triggeractivated && action.typeID == SpecialAction.ActionTypeId.BatteryCheck)
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
|
if (action.typeID == SpecialAction.ActionTypeId.BatteryCheck)
|
||||||
|
{
|
||||||
|
actionFound = true;
|
||||||
if (actionDone[index].dev[device])
|
if (actionDone[index].dev[device])
|
||||||
{
|
{
|
||||||
fadetimer[device] = 0;
|
fadetimer[device] = 0;
|
||||||
@ -1571,8 +1599,38 @@ namespace DS4Windows
|
|||||||
actionDone[index].dev[device] = false;
|
actionDone[index].dev[device] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (action.typeID != SpecialAction.ActionTypeId.Key &&
|
||||||
|
action.typeID != SpecialAction.ActionTypeId.XboxGameDVR &&
|
||||||
|
action.typeID != SpecialAction.ActionTypeId.MultiAction)
|
||||||
|
{
|
||||||
|
// Ignore
|
||||||
|
actionFound = true;
|
||||||
|
actionDone[index].dev[device] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!actionFound)
|
||||||
|
{
|
||||||
|
if (uTriggerCount > 0 && utriggeractivated && action.typeID == SpecialAction.ActionTypeId.Key)
|
||||||
|
{
|
||||||
|
actionFound = true;
|
||||||
|
|
||||||
|
if (untriggerindex[device] > -1 && !actionDone[index].dev[device])
|
||||||
|
{
|
||||||
|
actionDone[index].dev[device] = true;
|
||||||
|
untriggerindex[device] = -1;
|
||||||
|
ushort key;
|
||||||
|
ushort.TryParse(action.details, out key);
|
||||||
|
if (action.keyType.HasFlag(DS4KeyType.ScanCode))
|
||||||
|
InputMethods.performSCKeyRelease(key);
|
||||||
|
else
|
||||||
|
InputMethods.performKeyRelease(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (action.typeID == SpecialAction.ActionTypeId.XboxGameDVR || action.typeID == SpecialAction.ActionTypeId.MultiAction)
|
else if (action.typeID == SpecialAction.ActionTypeId.XboxGameDVR || action.typeID == SpecialAction.ActionTypeId.MultiAction)
|
||||||
{
|
{
|
||||||
|
actionFound = true;
|
||||||
|
|
||||||
/*if (getCustomButton(device, action.trigger[0]) != X360Controls.Unbound)
|
/*if (getCustomButton(device, action.trigger[0]) != X360Controls.Unbound)
|
||||||
getCustomButtons(device)[action.trigger[0]] = X360Controls.Unbound;
|
getCustomButtons(device)[action.trigger[0]] = X360Controls.Unbound;
|
||||||
if (getCustomMacro(device, action.trigger[0]) != "0")
|
if (getCustomMacro(device, action.trigger[0]) != "0")
|
||||||
@ -1683,10 +1741,13 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
actionDone[index].dev[device] = false;
|
actionDone[index].dev[device] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
catch { return; }
|
catch { return; }
|
||||||
|
|
||||||
if (untriggeraction[device] != null)
|
if (untriggeraction[device] != null)
|
||||||
@ -1707,10 +1768,13 @@ namespace DS4Windows
|
|||||||
{
|
{
|
||||||
if ((action.controls == action.ucontrols && !actionDone[index].dev[device]) || //if trigger and end trigger are the same
|
if ((action.controls == action.ucontrols && !actionDone[index].dev[device]) || //if trigger and end trigger are the same
|
||||||
action.controls != action.ucontrols)
|
action.controls != action.ucontrols)
|
||||||
|
{
|
||||||
if (!string.IsNullOrEmpty(tempprofilename[device]))
|
if (!string.IsNullOrEmpty(tempprofilename[device]))
|
||||||
{
|
{
|
||||||
foreach (DS4Controls dc in action.uTrigger)
|
//foreach (DS4Controls dc in action.uTrigger)
|
||||||
|
for (int i = 0, arlen = action.uTrigger.Count; i < arlen; i++)
|
||||||
{
|
{
|
||||||
|
DS4Controls dc = action.uTrigger[i];
|
||||||
actionDone[index].dev[device] = true;
|
actionDone[index].dev[device] = true;
|
||||||
DS4ControlSettings dcs = getDS4CSetting(device, dc);
|
DS4ControlSettings dcs = getDS4CSetting(device, dc);
|
||||||
if (dcs.action != null)
|
if (dcs.action != null)
|
||||||
@ -1720,8 +1784,8 @@ namespace DS4Windows
|
|||||||
else if (dcs.actionType == DS4ControlSettings.ActionType.Macro)
|
else if (dcs.actionType == DS4ControlSettings.ActionType.Macro)
|
||||||
{
|
{
|
||||||
int[] keys = (int[])dcs.action;
|
int[] keys = (int[])dcs.action;
|
||||||
for (int i = 0, keysLen=keys.Length; i < keysLen; i++)
|
for (int j = 0, keysLen = keys.Length; j < keysLen; j++)
|
||||||
InputMethods.performKeyRelease((ushort)keys[i]);
|
InputMethods.performKeyRelease((ushort)keys[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1729,10 +1793,13 @@ namespace DS4Windows
|
|||||||
LoadProfile(device, false, ctrl);
|
LoadProfile(device, false, ctrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
actionDone[index].dev[device] = false;
|
actionDone[index].dev[device] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static async void PlayMacro(int device, bool[] macrocontrol, string macro, DS4Controls control, DS4KeyType keyType)
|
private static async void PlayMacro(int device, bool[] macrocontrol, string macro, DS4Controls control, DS4KeyType keyType)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user