Skip to content

Instantly share code, notes, and snippets.

@dejayc
Created November 3, 2022 21:35
Show Gist options
  • Save dejayc/ac71fa954e65399629d8b277425b84fa to your computer and use it in GitHub Desktop.
Save dejayc/ac71fa954e65399629d8b277425b84fa to your computer and use it in GitHub Desktop.
Locks the camera behind one's character in the game Exanima
#include <Misc.au3>
#comments-start
--------------------------------------------------------------------------------
This script allows an Exanima player to lock the camera behind their character,
updating the camera as necessary when the character changes orientation or
position. Via keypress, it can be enabled and disabled, as well as temporarily
disabled by pressing shift. The scripts starts with camera lock disabled.
Default keys:
e - toggle camera lock
g - activate camera lock
G - deactivate camera lock
SHIFT - temporarily deactivate camera lock while SHIFT is pressed
o - increase by 10ms the delay duration between updates to camera position
O - decrease by 10ms the delay duration between updates to camera position
> - briefly display a dialog that shows whether camera lock is enabled, and
the current delay duration between updates to camera position
Note that even though this script attempts to only send the keystrokes that
emulate camera locking when Exanima is the active application, in some cases,
AutoIt will continue to send these keystrokes, and swallow the hotkeys defined
above, even when other applications have foremost activation focus. For this
reason, it's highly recommended that camera lock be disabled via keypress prior
to switching from Exanima to any other application.
The shift key allows camera locking to be disabled for as long as shift is
pressed. This allows players to move the mouse cursor, even when camera lock
is enabled, to wind up an attack swing or interact with 2D GUI panels.
By default, the camera updates its position once every 30ms. You can increase
or decrease that duration by pressing the appropriate keys defined above.
Smaller durations result in faster camera updates that feel snappier. Larger
durations result in slower camera updates that can give players more time to
execute tactics without needing to press the shift key as often.
Note that sometimes AutoIt scripts that intercept the shift key, like this
script, can result in the operating system getting stuck in a weird state where
special modifier keys like SHIFT, CTRL, and ALT seem to be permanently pressed.
Unfortunately, there is no workaround for when this situation happens other
than to restart the computer.
--------------------------------------------------------------------------------
#comments-end
Local $loopStepMs = 10
Local $refreshStepIncMs = 10
Local $refreshStepMs = 30
Local $refreshTimerMs = $refreshStepMs
Local $isOn = False
Local $keyModeActivate = "g"
Local $keyModeDeactivate = "G"
Local $keyModeToggle = "e"
Local $keyInc = "o"
Local $keyDec = "O"
Local $keyQuery = ">"
Local $keySendCameraUpdate = "v"
EnableOnKeyDec()
EnableOnKeyInc()
EnableOnKeyModeActivate()
EnableOnKeyModeDeactivate()
EnableOnKeyModeToggle()
EnableOnKeyQuery()
$dll = DllOpen("user32.dll")
Func DisableOnKeyDec()
HotKeySet( $keyDec )
EndFunc
Func DisableOnKeyInc()
HotKeySet( $keyInc )
EndFunc
Func DisableOnKeyModeActivate()
HotKeySet( $keyModeActivate )
EndFunc
Func DisableOnKeyModeDeactivate()
HotKeySet( $keyModeDeactivate )
EndFunc
Func DisableOnKeyModeToggle()
HotKeySet( $keyModeToggle )
EndFunc
Func DisableOnKeyQuery()
HotKeySet( $keyQuery )
EndFunc
Func EnableOnKeyDec()
HotKeySet( $keyDec, "OnKeyDec" )
EndFunc
Func EnableOnKeyInc()
HotKeySet( $keyInc, "OnKeyInc" )
EndFunc
Func EnableOnKeyModeActivate()
HotKeySet( $keyModeActivate, "OnKeyModeActivate" )
EndFunc
Func EnableOnKeyModeDeactivate()
HotKeySet( $keyModeDeactivate, "OnKeyModeDeactivate" )
EndFunc
Func EnableOnKeyModeToggle()
HotKeySet( $keyModeToggle, "OnKeyModeToggle" )
EndFunc
Func EnableOnKeyQuery()
HotKeySet( $keyQuery, "OnKeyQuery" )
EndFunc
Func OnKeyDec()
If WinActive( "Exanima" ) Then
$refreshStepMs -= $refreshStepIncMs
if $refreshStepMs < $refreshStepIncMs Then
$refreshStepMs = $refreshStepIncMs
EndIf
Else
DisableOnKeyDec()
Send( $keyDec )
EnableOnKeyDec()
EndIf
EndFunc
Func OnKeyInc()
If WinActive( "Exanima" ) Then
$refreshStepMs += $refreshStepIncMs
Else
DisableOnKeyInc()
Send( $keyInc )
EnableOnKeyInc()
EndIf
EndFunc
Func OnKeyModeActivate()
If WinActive( "Exanima" ) Then
$isOn = True
Else
DisableOnKeyModeActivate()
Send( $keyModeActivate )
EnableOnKeyModeActivate()
EndIf
EndFunc
Func OnKeyModeDeactivate()
If WinActive( "Exanima" ) Then
$isOn = False
Else
DisableOnKeyModeDeactivate()
Send( $keyModeDeactivate )
EnableOnKeyModeDeactivate()
EndIf
EndFunc
Func OnKeyModeToggle()
If WinActive( "Exanima" ) Then
$isOn = Not $isOn
Else
DisableOnKeyModeToggle()
Send( $keyModeToggle )
EnableOnKeyModeToggle()
EndIf
EndFunc
Func OnKeyQuery()
If WinActive( "Exanima" ) Then
Local $label = "Off"
if $isOn Then
$label = "On"
EndIf
MsgBox( 0, "ExanimaCameraLock", "Camera lock is " & $label & ": " & $refreshStepMs & "ms update rate", 1.25 )
Else
DisableOnKeyQuery()
Send( $keyQuery )
EnableOnKeyQuery()
EndIf
EndFunc
Func DoLoop()
If $isOn And WinActive( "Exanima" ) Then
$refreshTimerMs = $refreshTimerMs - $loopStepMs
If $refreshTimerMs <= 0 Then
$refreshTimerMs = $refreshStepMs
If Not _IsPressed("10", $dll) Then
Send( $keySendCameraUpdate )
EndIf
EndIF
EndIf
EndFunc
While 1
Sleep( $loopStepMs )
DoLoop()
WEnd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment