Swapped Analog Stick Layout (lefty)

Original Doom controls where run and look was with the left stick. Aim and fire was with the right stick. Other controls can be added for players that are left handed.
Version1.10
Authorred_dragon
Publish DateTue, 11 Aug 2015 - 22:57
Last UpdateSat, 19 Sep 2015 - 17:39
Downloads74
RATE


3

0

Release Notes: Added rumble feedback. Mask capture behavior on PS4 for double-click and long select. Restore long press functionality. Change swap selection on share double-click behavior. Corrected led colors and led selection persistence.
Code: Select all
/*
GPC Online Library
XB1 / PS4 / XB360 / Wii Pro Toggle Sticks Script
=============================================================================
Device:        Titan One (firmware rev. 2.27)
Author:        red_dragon
Game:          Any (most compatible)
System:        XBox One, DualShock 4, Wii U Pro or XBox 360
Controller:    XBox One, DualShock 4, Wii U Pro or XBox 360
Game Settings: Swapped Analog Stick Layout
Website:       www.consoletuner.com
Forum Post:    http://www.consoletuner.com/gpclib/?s=1029
Credit:        GTuner Pro, documentation, device monitor and plugins.
Comment:       Original Doom controls where run and look was with the left
               stick. Aim and fire was with the right stick.
Comment:       To make this smaller strip out support for unused controllers
               and put split them into different slots.
=============================================================================
CHANGELOG:
Version 1.00: Original code.
Version 1.01: Added slot# mod 4 to mimic controller player# led control.
              ex., program in slot 3 or 7 blinks controller 3.
Version 1.10: Added rumble feedback.
              Mask capture behavior on PS4 for double-click and long select.
              Restore long press functionality.
              Change swap selection on share double-click action.
              Corrected led colors and led selection persistence.
=============================================================================
TOGGLES:
Double press of PS4 'share', XB1 'View', or Wii 'minus' toggles functionality.
One blink indicate swap of analog sticks.
Two blinks indicate swap is inactive.
Double short press time limit indicated by constant variable.
=============================================================================
*/

define BLINK_LED = SPVAR_1;
define ACTIVE_STATE = SPVAR_2;
define BUTTON_EVENT = SPVAR_3;
define BUTTON_UP = SPVAR_4;
define QUICK_PRESS = SPVAR_5;
 
define RUMBLE_WAIT = 150;
 
define SHORT_PRESS_WAIT = 400;
define LONG_PRESS_WAIT = 650;
define REST_POSITION = 0;
 
int select_button = 1;
int select_val = 0;
int select_lval = 0;
 
int blink_led = LED_1;
int active_state = FALSE;
int controller = PIO_NONE;
int rumble_id = RUMBLE_B;
int l_rumble = 0;
 
init {
    set_pvar(QUICK_PRESS, 0);
    active_state = get_pvar(ACTIVE_STATE, FALSE, TRUE, active_state);
    set_blink_led();
}
 
main {
    controller = get_controller();
    if (controller != PIO_NONE) {
        if (controller == PIO_AUTO) {
            controller = test_controller();
        }
        if (controller == PIO_XB1) {
            select_button = XB1_VIEW;
            active_state = update_toggle();
            if (active_state) {
                swap_values(XB1_LX, XB1_RX);
                swap_values(XB1_LY, XB1_RY);
                swap_values(XB1_LS, XB1_RS);
            }
        } else if (controller == PIO_PS4) {
            select_button = PS4_SHARE;
            active_state = update_toggle();
            if (active_state) {
                swap_values(PS4_LX, PS4_RX);
                swap_values(PS4_LY, PS4_RY);
                swap_values(PS4_L3, PS4_R3);
            }
        } else if (controller == PIO_XB360) {
            select_button = XB360_BACK;
            active_state = update_toggle();
            if (active_state) {
                swap_values(XB360_LX, XB360_RX);
                swap_values(XB360_LY, XB360_RY);
                swap_values(XB360_LS, XB360_RS);
            }
        } else if (controller == PIO_WII) {
            select_button = WII_MINUS;
            active_state = update_toggle();
            if (active_state) {
                swap_values(WII_LX, WII_RX);
                swap_values(WII_LY, WII_RY);
                swap_values(WII_ONE, WII_TWO);
            }
        }
    } else {
        if (active_state) {
            set_pvar(ACTIVE_STATE, FALSE);
        }
    }
}
combo async_quick_reset {
    wait(SHORT_PRESS_WAIT);
    block(select_button, SHORT_PRESS_WAIT);
    if (get_pvar(QUICK_PRESS, 0, 1, 0) == 1) {
        combo_run(relay_short_press);
    }
    set_pvar(QUICK_PRESS, 0);
}
combo relay_short_press {
    set_val(select_button, 100);
    wait(SHORT_PRESS_WAIT);
    set_val(select_button, 0);
}
combo rumble {
    wait(RUMBLE_WAIT);
    set_rumble(rumble_id, 100);
    wait(RUMBLE_WAIT);
    set_rumble(rumble_id, 0);
}
combo rumble_1 {
    set_ledx(blink_led, 1);
    call(rumble);
    set_ledx(blink_led, 0);
    set_led(blink_led, 1);
}
combo rumble_2 {
    set_ledx(blink_led, 2);
    call(rumble);
    call(rumble);
    set_ledx(blink_led, 0);
    set_led(blink_led, 1);
}
function set_blink_led() {
    blink_led = get_slot() - 1;
    blink_led = (blink_led % 4) + 1;
    if (blink_led == 1) {
        blink_led = LED_1;
    } else if (blink_led == 2) {
        blink_led = LED_2;
    } else if (blink_led == 3) {
        blink_led = LED_3;
    } else if (blink_led == 4) {
        blink_led = LED_4;
    } else {
        blink_led = LED_NONE;
    }
    set_pvar(BLINK_LED, blink_led);
    notify_user(active_state);
}
function notify_user(enabled_state) {
    blink_led = get_pvar(BLINK_LED, LED_NONE, LED_4, blink_led);
    if (enabled_state) {
        combo_run(rumble_1);
    } else {
        combo_run(rumble_2);
    }
}
function update_toggle() {
    active_state = get_pvar(ACTIVE_STATE, FALSE, TRUE, active_state);
    block(select_button, LONG_PRESS_WAIT);
    select_val = get_val(select_button);
    select_lval = get_lval(select_button);
 
    if (select_lval == 0) {
        if (select_val == 0) {// button up
            set_pvar(BUTTON_UP, TRUE);
            if (get_pvar(BUTTON_EVENT, FALSE, TRUE, FALSE)) {
                // short press
                set_pvar(BUTTON_EVENT, FALSE);
                if (get_pvar(QUICK_PRESS, 0, 1, 0) == 1) {
                    set_pvar(QUICK_PRESS, 0);
                    active_state = !active_state;
                    set_pvar(ACTIVE_STATE, active_state);
                    notify_user(active_state);
                } else {
                    set_pvar(QUICK_PRESS, 1);
                }
            } else {
                combo_run(async_quick_reset);
            }
        }
    } else {
        if (select_val == 0) {// button down
            if (get_pvar(BUTTON_UP, FALSE, TRUE, FALSE)) {
                set_pvar(BUTTON_UP, FALSE);
                set_pvar(BUTTON_EVENT, TRUE);
            }
        } else {// held button - long press
            if (get_pvar(BUTTON_EVENT, FALSE, TRUE, TRUE)) {
                set_pvar(BUTTON_EVENT, FALSE);
                set_val(select_button, 100);
                set_pvar(QUICK_PRESS, 0);
            }
        }
    }
    return active_state;
}
function swap_values(id_1, id_2) {
    if ((get_val(id_1) != REST_POSITION) || (get_val(id_2) != REST_POSITION)) {
        swap(id_1, id_2);
    }
}
function test_controller() {
    if(ps4_touchpad(PS4T_P1) || ps4_touchpad(PS4T_P2)) {
        return PIO_PS4;
    } else if (get_val(WII_ACCNZ) != get_lval(WII_ACCZ)) {
        return PIO_WII;
    } else {
        set_rumble(RUMBLE_LT, 1);
        l_rumble = get_rumble(RUMBLE_LT);
        if (l_rumble == 1) {
            set_rumble(RUMBLE_LT, 0);
            return PIO_XB1;
        }
    }
    return PIO_XB360;
}