Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Misc.au3>
- #include <Constants.au3>
- #include <WindowsConstants.au3>
- ; Define swing parameters
- Local $swing_Angle = 94
- Local $swing_period = 12000 ; Duration of a full swing in milliseconds
- Local $steps = 1000 ; Number of steps per second / Precsion
- Local $pause_duration = 1000 ; Pause at the end of each half cycle in milliseconds
- Local $movement_duration = 350 ; Duration of movement for arrow keys in milliseconds. Key inputs are accumulated for that duration.
- Local $movement_multiplier = 100
- Local $random_jitter = 0.2; Add some jitter to the movement. 0 <= $random_jitter < 1
- ; Define your in-game sensitivity, DPI, and the desired rotation angle
- Local $sensitivity = 1.52
- Local $dpi = 3200
- Local $yawMultiplier = 0.022
- Local $zoomFactor = 1.0 ; Assuming no zoom
- Local $sensitivityScale = 1.0 ; Assuming default scaling
- Local $Pi = 3.14159265358979
- Func CalculateMouseMovement($angle, $sensitivity, $dpi, $yawMultiplier, $zoomFactor, $sensitivityScale)
- ; Calculate modulated sensitivity
- Local $modulatedSensitivity = $sensitivity * $sensitivityScale
- ; Calculate the required mouse movement (in pixels) to achieve the desired yaw angle
- Local $pixels = $angle / ($yawMultiplier * $modulatedSensitivity * $zoomFactor)
- Return $pixels
- EndFunc
- Local $swing_distance = CalculateMouseMovement($swing_Angle, $sensitivity, $dpi, $yawMultiplier, $zoomFactor, $sensitivityScale) ; Maximum swing distance in pixels
- ; Calculate swing speed in pixels per second
- Local $swing_speed = $swing_distance / ($swing_period / 1000) ; speed in pixels per second
- ; Initialize the toggle status
- Local $toggle = False
- Local $Local_toggle = True ; Additional Local toggle status
- Local $start_time = TimerInit() ; Initialize timer
- Local $last_update_time = TimerInit() ; Last time update
- Local $last_swing_direction = 0 ; Last swing direction: -1 = left, 1 = right
- Local $last_swing_sign = 0
- Local $last_movement_direction[2] = [0, 0] ; Last movement direction (x, y)
- Local $movements[0][3] ; Empty array for movements
- Local $swing_position = 1 ; Current swing position in pixels
- Local $isoutside = False
- Local $delta_time ; Declare delta_time Locally
- Local $accumulated_x = 0.0
- Local $accumulated_y = 0.0
- Local $Pi = 3.14159
- Local $Pi2 = 3.14159/2
- Local $hDLL = DllOpen("user32.dll")
- ; F7 key as toggle for swinging
- HotKeySet("{F7}", "ToggleSwing")
- ; End key as toggle for all movements
- HotKeySet("{END}", "ToggleLocal")
- ; Delete key to terminate the script
- HotKeySet("{DEL}", "TerminateScript")
- Func TerminateScript()
- Exit ; Terminate the script
- EndFunc
- Func ToggleSwing()
- $toggle = Not $toggle ; Toggle between True/False
- If $toggle Then
- $start_time = TimerInit() ; Reset timer
- $last_swing_direction = 0 ; Reset direction status
- $last_update_time = TimerInit() ; Reset time for delta-time
- EndIf
- EndFunc
- Func ToggleLocal()
- $Local_toggle = Not $Local_toggle ; Toggle everything on/off
- If Not $Local_toggle Then
- ; Stop all movements
- $toggle = False
- ReDim $movements[1][3]
- $movements[0][0] = 0
- $movements[0][1] = 0
- $movements[0][2] = 0
- EndIf
- EndFunc
- Local $VK_UP = "26" ; Virtual key code for up arrow key
- Local $VK_DOWN = "28" ; Virtual key code for down arrow key
- Local $VK_LEFT = "25" ; Virtual key code for left arrow key
- Local $VK_RIGHT = "27" ; Virtual key code for right arrow key
- Local $move_up = False
- Local $move_down = False
- Local $move_left = False
- Local $move_right = False
- ;HotKeySet to use those keys exclusively:
- HotKeySet("{UP}", "CheckKeys")
- HotKeySet("{DOWN}", "CheckKeys")
- HotKeySet("{LEFT}", "CheckKeys")
- HotKeySet("{RIGHT}", "CheckKeys")
- HotKeySet("{UP up}", "CheckKeys")
- HotKeySet("{DOWN up}", "CheckKeys")
- HotKeySet("{LEFT up}", "CheckKeys")
- HotKeySet("{RIGHT up}", "CheckKeys")
- Func CheckKeys()
- ; Check the status of the arrow keys
- If _isPressed($VK_UP, $hDLL) Then
- $move_up = True
- Else
- $move_up = False
- EndIf
- If _isPressed($VK_DOWN, $hDLL) Then
- $move_down = True
- Else
- $move_down = False
- EndIf
- If _isPressed($VK_LEFT, $hDLL) Then
- $move_left = True
- Else
- $move_left = False
- EndIf
- If _isPressed($VK_RIGHT, $hDLL) Then
- $move_right = True
- Else
- $move_right = False
- EndIf
- EndFunc
- Func AddMovement($x, $y)
- If $Local_toggle Then
- ; Calculate the end time for the new movement
- Local $end_time = TimerDiff($start_time) + $movement_duration
- ; Store the current size of the array
- Local $oldSize = UBound($movements, 1)
- ; Create a new array that is one row larger
- ReDim $movements[$oldSize + 1][3]
- ; Add the new movement
- $movements[$oldSize][0] = $x
- $movements[$oldSize][1] = $y
- $movements[$oldSize][2] = $end_time
- EndIf
- EndFunc
- Func CalculateMovement(ByRef $x_movement, ByRef $y_movement)
- ; Reset the movements
- $x_movement = 0
- $y_movement = 0
- ; Check the status of the arrow keys and continuously add movements
- If $move_up Then AddMovement(0, -1)
- If $move_down Then AddMovement(0, 1)
- If $move_left Then AddMovement(-1, 0)
- If $move_right Then AddMovement(1, 0)
- ; Iterate through the movements in the array
- Local $current_time = TimerDiff($start_time)
- For $i = 1 To UBound($movements) - 1
- If $current_time < $movements[$i][2] Then
- $x_movement += $movements[$i][0]
- $y_movement += $movements[$i][1]
- EndIf
- Next
- EndFunc
- Func DllMoveMouse($dx, $dy)
- ; Get the current mouse position
- Local $aPos = MouseGetPos()
- ; Calculate the new position
- Local $new_x = $aPos[0] + $dx
- Local $new_y = $aPos[1] + $dy
- ; Set the cursor to the new position
- DllCall("user32.dll", "int", "mouse_event", "int", 0x0001, "int", $dx, "int", $dy, "int", 0, "int", 0) ;to remain function
- DllCall("user32.dll", "int", "SetCursorPos", "int", $new_x, "int", $new_y) ;to keep some precision
- EndFunc
- Local $pause_start_time = 0
- Local $is_paused = False
- Local $current_pause_duration = 0
- Func CheckPause()
- ; Check if we are currently in a pause
- If $is_paused Then
- ; Calculate the elapsed time since the start of the pause
- Local $elapsed_time = TimerDiff($pause_start_time)
- ; End the pause if the pause duration is over
- If $elapsed_time >= $current_pause_duration Then
- $is_paused = False
- EndIf
- EndIf
- EndFunc
- Func StartPause($duration)
- ; Start a new pause with the given duration
- $pause_start_time = TimerInit()
- $current_pause_duration = $duration
- $is_paused = True
- EndFunc
- ; Function to move the mouse only when movement is significant
- Func ProcessMovement($dx, $dy)
- $accumulated_x += $dx
- $accumulated_y += $dy
- Local $move_x = Floor($accumulated_x)
- Local $move_y = Floor($accumulated_y)
- If Abs($move_x) >= 1 Or Abs($move_y) >= 1 Then
- DllMoveMouse($move_x, $move_y)
- $accumulated_x -= $move_x
- $accumulated_y -= $move_y
- EndIf
- EndFunc
- Local $direction = 1
- ; Initialize timer outside the loop
- Local $end = TimerInit()
- ; Main loop
- While True
- If TimerDiff($end) >= (1000 / $steps) Then
- ; Reset the timer
- $end = TimerInit()
- If $Local_toggle Then
- ; Calculate delta_time in milliseconds
- $delta_time = TimerDiff($last_update_time)
- $last_update_time = TimerInit()
- Local $current_time = TimerDiff($start_time)
- ; Check if a pause is active
- CheckPause()
- CheckKeys() ; Check the key status
- ; Independent arrow key movement
- Local $current_x_movement, $current_y_movement
- CalculateMovement($current_x_movement, $current_y_movement)
- ; Move the mouse according to arrow key movement
- If $current_x_movement <> 0 Or $current_y_movement <> 0 Then
- $current_x_movement += Random(-$random_jitter, $random_jitter, 0)
- $current_y_movement += Random(-$random_jitter, $random_jitter, 0)
- $current_x_movement *= ($movement_multiplier*$swing_speed/$steps) * $delta_time / 1000 *$movement_duration / 1000; Adjust speed with delta_time
- $current_y_movement *= ($movement_multiplier*$swing_speed/$steps) * $delta_time / 1000 *$movement_duration / 1000
- ProcessMovement($current_x_movement, $current_y_movement)
- ; Add current movement to the swing position if swinging is active
- If $toggle Then
- ; Add phase change to position
- $swing_position += $current_x_movement
- if Not $isoutside And Abs($swing_position) > $swing_distance/2 then
- $isoutside = True
- ElseIf $isoutside and $last_swing_sign <> Sign($swing_position) then
- $isoutside = False
- EndIf
- $last_swing_sign = Sign($swing_position)
- EndIf
- EndIf
- ; Reset movements
- If Abs($current_x_movement) >= $random_jitter Then
- ; Remove expired movements
- Local $new_movements[0][3] ; Start with an empty array for new movements
- Local $j = 0
- For $i = 0 To UBound($movements) - 1
- If $current_time < $movements[$i][2] Then
- ReDim $new_movements[$j + 1][3]
- $new_movements[$j][0] = $movements[$i][0]
- $new_movements[$j][1] = $movements[$i][1]
- $new_movements[$j][2] = $movements[$i][2]
- $j += 1
- EndIf
- Next
- $movements = $new_movements
- Else
- If Abs($current_y_movement) >= $random_jitter Then
- ; Remove expired movements
- Local $new_movements[0][3] ; Start with an empty array for new movements
- Local $j = 0
- For $i = 0 To UBound($movements) - 1
- If $current_time < $movements[$i][2] Then
- ReDim $new_movements[$j + 1][3]
- $new_movements[$j][0] = $movements[$i][0]
- $new_movements[$j][1] = $movements[$i][1]
- $new_movements[$j][2] = $movements[$i][2]
- $j += 1
- EndIf
- Next
- $movements = $new_movements
- EndIf
- ; Swing movement
- If $toggle And Not $is_paused Then
- Local $move_x = 0
- If Not $isoutside Then
- $move_x = ($swing_speed + Random(-$random_jitter, $random_jitter, 0)) * $direction * $delta_time / 1000 * (1-Clamp((Abs($swing_position)/($swing_distance/(2*0.98)))^3,0,0.98))
- Else
- $move_x = ($swing_speed + Random(-$random_jitter, $random_jitter, 0)) * $direction * $delta_time / 1000
- EndIf
- ; Ensure that the position moves even if Sin would make the change too small
- $swing_position += $move_x
- ; Constrain the swing position within the maximum swing distance
- If $swing_position > $swing_distance / 2 And $direction > 0 Then
- $direction = -1
- ElseIf $swing_position < -$swing_distance / 2 And $direction < 0 Then
- $direction = 1
- EndIf
- If $isoutside and $last_swing_sign <> Sign($swing_position) then
- $isoutside = False
- EndIf
- $last_swing_sign = Sign($swing_position)
- If $direction <> $last_swing_direction And $last_swing_direction <> 0 Then
- StartPause($pause_duration) ; Start a pause with the specified duration
- EndIf
- $last_swing_direction = $direction
- ; Move the mouse relative to the current position
- ProcessMovement($move_x, Random(-0.2, 0.2, 0))
- EndIf
- EndIf
- EndIf
- EndIf
- WEnd
- ; Remember to close the DLL when it's no longer needed
- Func Cleanup()
- DllClose($hDLL)
- EndFunc
- Cleanup() ; Close the DLL before exiting the script
- Func Sign($value)
- If $value > 0 Then
- Return 1
- ElseIf $value < 0 Then
- Return -1
- Else
- Return 0
- EndIf
- EndFunc
- Func Clamp($value, $min, $max)
- If $value < $min Then
- Return $min
- ElseIf $value > $max Then
- Return $max
- Else
- Return $value
- EndIf
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement