//
// exec demoseeking.cfg
// alias cl_hook_gamestart_all "demoseeking_game_started"
+// alias cl_hook_demostart "demoseeking_demo_started"
//
// Usage:
// 1. start a demo (ply/playdemo command or menu), and
// Variables:
//
// _demo_is_playing
-// Indicates whether a demo is currently playing. Set to 1 when playdemo
-// starts a demo.
+// Indicates whether a demo is currently playing. Should be set to 1 by
+// cl_hook_demostart when a demo starts playing.
// Note: the setup above is needed to reset this reliably.
// _current_demo_name
// The name of the latest played demo. Same as the argument passed to the
//
// Extras:
//
-// - The alias playdemo_hook is run when demo playback is started.
// - The alias seekdemo_hook_seek_end is run after a seek completed successfully.
// - The alias seekdemo_getseektime can be used by scripts to get the current
// playback time or seek target time. See its usage below.
set _demoseeking_speed_factor 10
// state initialization
-alias _demoseeking_init_vars "set _demoseeking_vars_loaded 1; set _demo_is_playing 0; set _current_demo_name \"\"; set _demoseeking_is_seeking 0; set _seekdemo_state idle; set _seekdemo_target 0; alias playdemo_hook \"\"; alias seekdemo_hook_seek_end"
+alias _demoseeking_init_vars "set _demoseeking_vars_loaded 1; set _demo_is_playing 0; set _current_demo_name \"\"; set _demoseeking_is_seeking 0; set _seekdemo_state idle; set _seekdemo_target 0; alias seekdemo_hook_seek_end"
alias _demoseeking_init_vars1 ""
_demoseeking_init_vars${_demoseeking_vars_loaded ?}
// Hook into game start to reset seekdemo state. This prevents reloading the
// last demo when seekdemo is accidentally called during an actual game.
+// Also hook into demo start to set _demo_is_playing properly.
alias demoseeking_game_started "set _demo_is_playing 0; set _current_demo_name \"\""
+alias demoseeking_demo_started "set _demo_is_playing 1"
+
+// Hook into "playdemo" command. This alias runs immediately after the actual
+// "playdemo" command runs. Needed for seekdemo to restart the demo when
+// seeking backwards.
+alias playdemo "set _current_demo_name \"$1\""
// usage: seekdemo_getseektime <varname>
// Populates <varname> with the current seek target time, if seeking. If not
set _seekdemo_getseektime_rpn_starting _seekdemo_target
set _seekdemo_getseektime_rpn_seeking _seekdemo_target
-// Hook into "playdemo" command. This alias runs immediately after the actual
-// "playdemo" command runs. Needed for seekdemo to restart the demo when
-// seeking backwards. Runs the playdemo_hook alias when a demo file is being
-// loaded.
-// ---
-// "cl_cmd rpn" fails while a map is loading, leaving the value of
-// _demoseeking_playdemo_success untouched, which means the playdemo command
-// succeeded.
-alias playdemo "set _demoseeking_playdemo_success 1; cl_cmd rpn /_demoseeking_playdemo_success 0 def; _demoseeking_playdemo_check \"$1\""
-alias _demoseeking_playdemo_check "_demoseeking_playdemo_check_$_demoseeking_playdemo_success \"$1\""
-alias _demoseeking_playdemo_check_0 "echo \"playdemo failed\""
-alias _demoseeking_playdemo_check_1 "set _demo_is_playing 1; set _current_demo_name \"$1\"; playdemo_hook"
-
// Hook into the "defer" command to restore state when "defer clear" is run
// while seeking. "defer clear" seems to be run by some csprogs.
// ---