{$CLEO .cs}
{$USE cleo+}
nop
script_name 'TOGLHYD'
wait 0
wait 0

if
    0AA2: 31@ = load_dynamic_library "CLEO+.cleo"
jf @ILoveMyGirlfriendJessica
if
    0AA4: 30@ = get_dynamic_library_procedure "GetCleoPlusVersion" library 31@
then
    0AA7: call_function_return 30@ num_params 0 pop 0 29@
end
0AA3: free_dynamic_library 31@
if
    29@ >= 0x1020000
jf @ILoveMyGirlfriendJessica


int iCar, i, iCounter, iState = 1

:Main
if
    iState == 0
then
    iState = 1
    if
        does_vehicle_exist iCar
    then
        set_car_hydraulics iCar 1
    end
end
   
wait 500

while true
    wait 0
    if
        is_player_playing $PLAYER_CHAR
    jf @Main
    if
        is_char_sitting_in_any_car $PLAYER_ACTOR
    jf @Main
    if and
        is_player_control_on $PLAYER_CHAR
        not is_player_in_remote_mode $PLAYER_CHAR
    jf @Main
    store_car_char_is_in_no_save i $PLAYER_ACTOR
    if
        i <> iCar
    then
        iCar = i
        jump @Main
    end
    if or   
        does_car_have_hydraulics iCar
        iState == 0
    jf @Main
    if
        is_button_just_pressed pad 0 button 1
    then
        if
            TIMERA > 500
        then
            iCounter = 0
        end
        iCounter += 1
        TIMERA = 0
    end
    if and
        TIMERA < 1000
        iCounter > 1
    then
        if
            is_button_pressed pad 0 button 18
        then
            iCounter = 0
            TIMERA = 1000
            write_memory 0xB7347C size 2 value 0x00 virtual_protect 0
            
            if
                iState == 1
            then
                print_help_formatted "Hydraulics OFF"
                iState = 0
            else
                print_help_formatted "Hydraulics ON"
                iState = 1
            end
            
            set_car_hydraulics iCar iState
            
            repeat
                write_memory 0xB7347C size 2 value 0x00 virtual_protect 0
                wait 0                
            until not is_button_pressed pad 0 button 18
        end
    end
end




:ILoveMyGirlfriendJessica
TIMERA = 0

repeat
    wait 0
    0AD1: print_formatted_now "Toggle Hydraulics: CLEO+ 1.2.0 or newer required. It's a plugin for CLEO. Please download and install it." time 200
    if and
        09E7: is_player_control_on $PLAYER_CHAR
        816B: not get_fading_status
    jf @ILoveMyGirlfriendJessica
until TIMERA > 10000

terminate_this_custom_script