Jump to content

Recommended Posts

Posted (edited)

UPDATED AUG. 19, 2023

 

Hi!

image.png.394f9514df0980a60f808a9ce01817c7.png

 

Good news: In my last update, I thought the script wouldn't restart recordings when the game was under heavy load. Turns out that the reason it didn't work was a typo in the code. It works! Still not 100% of the times, but far more often than not. The audible alert works great as a reminder to restart the recording manually, if the auto fails. I found out that if you are armed with rockets, it will also change your rocket-mode (fire 1, 2, all), and I need to work out a fix for that.

 

Also the tacview_only mode is great. It deletes the recorded track file and it's mission folder, but leaves the tacview (*acmi) file. That's good if you are more interested in tactics than visuals when recording, because itt saves a lot of disk-space. Especially if the mission is long and has many objects.

 

Features:

  • Automatically resumes trackrecording when Il2-BOX shuts it down (most of the times)
  • Can be set up to use speech and/or sound, to remind you to check if recording is on (works great!)
  • tacview_only mode: For those long beastly missions, it can be set up to only let TACView files be recorded
    saves disk-space AND flightinfo
  • Extremely lightweight: Relies on inotify - so it does absolutely nothing when nothing is happening. Consumes almost no resources at all. You could set it as a startup-application, and never worry no more.

Weaknesses:

  • Still in it's infancy
  • I can't find a reliable way to send keystrokes to the game. It works most of the times. Still - it works great as a reminder for you to restart the recording manually.

 

INSTALL AND USAGE: It should be fairly self-explanatory - you may need to install a couple of tools on your machine:

 

Software-dependencies:
The following software needs to be installed on your
computer
	* xkvbd - mandatory
	* inotify-tools - mandatory
	* sox - optional, if you want to use the default alert sound
	* espeak - optional, if you wish to hear a spoken alert message

On Ubuntu do eg.
	sudo apt install xvkbd inotify-tools sox espeak

 

This should work for all Debian/Ubuntu-based distros - otherwise install as pr. your distros preferred method.

 

Download the attached script, unzip it and move it to a location of your choosing. Make sure it is executable:

$ chmod +x il2record.sh


Next edit the script, some variables has to be set up:

 

Spoiler
track_folder: "/INSERT/PATH/TO/IL-2 Sturmovik Battle of Stalingrad/data/Tracks"

size_max: '510M' # if a recording is bigger than this, it will be resumed when it stops

tacview_only: 'NO' # if set to yes, track files are deleted, and only the tacviewfile (*.acmi) survives

auto_restart_recording: 'YES' # set it to 'NO' and you'll have to restart yourself.

play_sound_when_restarting: 'YES' # plays a sound when the game stops recording

speak_when_restarting: 'YES' # speaks a message when the game stops recording

speak_message: 'check track recorder' # the message spoken

perform_sound_check: 'YES' # perform a soundcheck on startup to ensure sound is working

 


Now open a terminal and run the script before launching the game (actually, if you forget, you can just ALT-TAB out of the game and start the script, it doesn't matter - just do it before your trackrecording grows so big that Il-2 GB shuts it down)

But this is all explained in more depth within the file - the code is here, but you can also download the attached zip.
 

Spoiler
#!/bin/bash

# Created 2023 by Roshko <acebone@gmail.com>
# Feel free to modify the script if you have some cool ideas
# please share your cool ideas with the community if you do so.
#
# Software-dependencies:
# The following software needs to be installed on your
# computer

# * xkvbd - mandatory
# * inotify-tools - mandatory
# * sox - optional, if you want to use the default alert sound
# * espeak - optional, if you wish to hear a spoken alert message
#
# On Ubuntu do eg.
#  sudo apt install xvkbd inotify-tools sox espeak

version=1.04a

# Make sure only one script is running
other_instance=`pidof -o %PPID -x $0`
if [ "$other_instance" ]; then kill -s 9 -p "$other_instance"; fi

# =========
# SETTINGS
# =========

# track_folder: Tell the script where to look for tracks ()

track_folder="/INSERT/PATH/TO/IL-2 Sturmovik Battle of Stalingrad/data/Tracks"

# size_max: if track file is larger than this
#   a restart of recording is attempted
#  ... for testing: 100K (or some other small size)
#  use M (not Mb) for megabyte eg.: 450M
#  use K (not Kb) for kilobyte eg.: 57K
# Recommended value: 500M

size_max=510M

# alert_only_mode (yes|no):
#  If you only want to be warned that
#  recording has been stopped, no
#  automatic restart of recording,
#  set it to yes
# Recommended value: no

alert_only_mode=no

# alert_when_restarting_rec (yes|no):
#  Play a sound alert when a recording is
#  stopped by the game. Sometimes restart
#  fails, the alert will remind you restart
#  recording manually
# Recommended value: yes

alert_when_restarting_rec=yes

# alert_sound_file (/path/to/file|default):
#  Specify the alert sound you want to hear.
#  accepted values are either a valid filepath
#  or the word default (no file needed)
# Example value (requires sox): default
# Tip: the soundfile "phone-outgoing-busy.oga" is quite
# nice, and should be present somewhere on Gnome-systems

alert_sound_file="/usr/share/sounds/freedesktop/stereo/phone-outgoing-busy.oga"

# spoken_alert (yes|no):
#   Requires espeak
#   If you are stressed mid-battle,
#   it can be nice with a voice
#   telling you why an alarm is going off.
#   Same as in jets!
#  Recommended value: yes

spoken_alert=yes
spoken_alert_message="check track recorder"

# perform_sound_check (yes|no):
#  If 'yes', a sound check is performed at startup
# Recommended value: yes

perform_sound_check=yes

# tacview_only (yes|no)
#   Will delete trackfiles but keep Tacview (*.acmi) files.
#   you can use this, if want to review your mission in Tacview
#   but worry that the track files will fill up your disk.
#   yes = turn it on (delete track files)
#   anything else = turn it off (keep track files)
# Recommended value: no

tacview_only=no

# =====================
# END OF SETTINGS
# you shouldn't be editing anything below this
# line, unless you know what you are doing
# =====================

settings_vars="track_folder size_max tacview_only alert_only_mode alert_when_restarting_rec alert_sound_file spoken_alert spoken_alert_message perform_sound_check"
settings_vars_noformat="track_folder spoken_alert_message alert_sound_file"

# ==========
# FUNCTIONS
# ==========

function restart_recording
{
	xvkbd -text "\Cr" -window "Il-2 Sturmovik" 2> /dev/null;
	# prevent (or minimize the risk of) Ctrl not being keyupped
	xvkbd -text "\C" -window "Il-2 Sturmovik" 2> /dev/null;
}

function play_sound {
	if [[ ${soundfile^^} == "DEFAULT" || ! -f "$alert_sound_file" ]]; then
		play -q -r 48000 -n -b 16 -c 2 synth .2 sin 430+860 vol -12dB 2> /dev/null
		play -q -r 48000 -n -b 16 -c 2 synth .2 sin 430+860 vol -12dB 2> /dev/null
		play -q -r 48000 -n -b 16 -c 2 synth .2 sin 430+860 vol -12dB 2> /dev/null
	else
		play -q "$alert_sound_file" 2> /dev/null
	fi
}

function sound_check {
	if [[ $spoken_alert == YES ]]; then
		espeak "sound check"
	fi

	alert_by_sound
}

function play_alert_sound {
		if [[ $alert_when_restarting_rec == YES ]]; then
			play_sound
		fi
		if [[ $spoken_alert == YES ]]; then
			local msg="$spoken_alert_message"
			if [[ $1 ]]; then
				msg="$1"
			fi
			espeak "$msg"
		fi
}

function alert_by_sound {
	play_alert_sound; #play_alert_sound;# sleep .6; play_alert_sound
}

function print_settings {
	local mark
	for x in $settings_vars; do
		case ${!x} in
		"YES")
			mark=$GREEN
		;;
		"NO")
			mark=$RED
		;;
		*)
			mark=$NC
		;;
		esac
		echo -e "$MARK$x$NC: ${mark}'${!x}'${NC}";
	done
}

function purge_trackfiles {
	wd=`pwd`
	cd "$track_folder"

	local trackfile=$1
	local trackfolder=${trackfile%.*}/

	output_message "Deleting track file: $trackfile"
	rm -f "$trackfile"

	# The game will sometimes have mixed cases in the foldername (yup!)
	shopt -s nocaseglob #enable
	for folder in */; do # */
		if [ "${folder,,}" == "${trackfolder,,}" ]; then
			output_message "Deleting track folder: $trackfolder"
			rm -rf "$trackfolder"
		fi
	done
	shopt -u nocaseglob # disable
}

function output_message {

	echo --------------------------
	echo -e "$1"
}


# setup colors
BLACK='\033[0;30m';     DARKGRAY='\033[1;30m';   RED='\033[0;31m';       LIGHTRED='\033[1;31m';
GREEN='\033[0;32m';     LIGHTGREEN='\033[1;32m'; ORANGE='\033[0;33m';    YELLOW='\033[1;33m';
BLUE='\033[0;34m';      LIGHTBLUE='\033[1;34m';  PURPLE='\033[0;35m';    LIGHTPURPLE='\033[1;35m';
CYAN='\033[0;36m';      LIGHTCYAN='\033[1;36m';  LIGHTGRAY='\033[0;37m'; WHITE='\033[1;37m';
NC='\033[0m';           BOLD=$WHITE;             MARK=$WHITE;           WARN=$RED; OK=$GREEN

function sanitize_settings {
	for x in $settings_vars; do
		if [[ " $settings_vars_noformat " != *" $x "* ]]; then
			export $x="${!x^^}";
		fi
	done
}

# =========
# SETUP
# =========
script_pathname="$0"
script_name=$(basename -- "$0")

sanitize_settings

# Convert $size_max to bytes
size_max_bytes=`numfmt --from iec --format "%8.4f" $size_max | awk '{print int($1+0.5)}'`

# start UI

echo -e "=================================
  Welcome to ${MARK}${script_name^^}${NC} v$version
================================="

if [[ $other_instance ]]; then
	echo -e "${WARN}ALREADY RUNNING $script_name ($other_instance) HAS BEEN TERMINATED ${NC}"
fi

# Make sure that only one script is running

# Check if the specified track-folder exists and has the correct name
if [[ ! -d "$track_folder" || ! "$track_folder" =~ Tracks$ ]]
then
    echo -e "${WARN}============================================${NC}
ERROR in track_folder:
${BOLD}$track_folder${NC}

is ${WARN}missing${NC} or ${WARN}not a track folder${NC}.
* ${BOLD}MUST BE A VALID PATH${NC}
* ${BOLD}MUST END WITH data/Tracks${NC}

Edit ${BOLD}`realpath \"$script_pathname\"`${NC}
and set track_folder correctly
${WARN}============================================${NC}"
echo exiting ...
	exit

fi

# Check if mode is tacview_only, and if so
# warn the user, and offer a chance to opt out
if [[ $tacview_only == YES ]]; then
	echo -e "${WARN}============================================${NC}
$script_name is running in ${MARK}tacview_only mode${NC}.
This will ${WARN}delete recorded tracks${NC}
and only ${OK}leave the *.acmi files${NC} used for Tacview.
${WARN}============================================${NC}
Do you want to continue in tacview_only mode (y/N)?"

	read -n 1 -s answer
	case $answer in
		[yY] ) tacview_only=YES;;
		* ) tacview_only=NO;;
	esac
	echo
fi

if [[ $alert_only_mode == YES ]]; then
	echo -e "${WARN}============================================
WARNING:${NC} alert_only_mode ${WARN}is set to YES${NC}
You will have to restart recording manually
when the alarm goes off.
${WARN}============================================${NC}
Do you want to stay in alert_only_mode (y/N)?"

	read -n 1 -s answer
	case $answer in
		[nN] ) alert_only_mode=NO
		;;
	esac
	echo
fi

echo -e "${BOLD}Settings:${NC}"
print_settings
echo -e "${BOLD}--${NC}"

echo -e "Closing this terminal will ${OK}terminate${NC} $script_name"
echo -e "Hit ${OK}CTRL+C${NC} to quit $script_name"

echo -e "${BOLD}--${NC}"

# soundcheck
if [[ $perform_sound_check == YES && ($alert_when_restarting_rec == YES || $spoken_alert == YES) ]]; then
	echo "Sound check ..."
	sound_check
	echo "Sound check finished"
fi

if [[ $tacview_only == YES ]]; then
	mode="${WARN}TACVIEW${NC}"
    tmpcolor=${WARN}
else
	mode="${OK}NORMAL${NC}"
    tmpcolor=${OK}
fi

echo -e "$script_name is ${tmpcolor}monitoring${NC} your track folder in $mode mode ..."

# =========
# LOGIC
# =========

# Monitor track_folder for files closed for writing
while true; do
	# \.acmi$
	inotifywait -e close_write "$track_folder" --format="%f" --include '\.trk$' 2> /dev/null | while read track_file; do
	    size_current=$(du -b "$track_folder/$track_file" | cut -f1)
	    # is the track file larger than size_max?
	    if [ $size_current -ge $size_max_bytes ]; then
	        if [ $alert_only_mode != YES ]; then
	        	restart_recording
	        fi
			alert_by_sound
	    fi
        if [[ ${tacview_only^^} == YES ]]; then
        	purge_trackfiles "$track_file"
        fi
	done
done

 

 

Changelog:

v. 1.04a

  • Fixed small problem with tacview_only mode. Tracks' missionfolder was not deleted, now it is. 

v. 1.04

  • Different lettercasing in track names and mission folder names is now ignored

v. 1.03

  • Numerous fixes and tidy-ups
  • tacview_only mode enabled now - it seems to work just dandy
  • The script now makes sure that no other instances of the script is running.

v. 1.02a

  • fixed stupid typo that prevented the script from working at all

 v. 1.02

  • Restored the ability to restart trackfiles, which I accidentally deleted
  • switched to espeak for speech-synthesis, sounds better.
  • added possibility to play alert-sound without any soundfile needed
  • created check for other instance of the script, you won't have two versions running
    and sending keys to the game
  • disabled tacview_only option, it turns out that trackfolders can contain uppercase, while tracks are lowercase and vice versa. Need to test the code for that.

  v. 1.01

  • More reliable restart of recording, still not 100%
  • Code cleanup
  • Added speech and soundcheck
  • better output at startup

v. 1.0

  • added code to an otherwise barren text file

 

Inspired by:

I am using Il-2 Great Battles on Linux, and sadly  SAS_Storebrors Il-2 Great Battles recorder won't easily run under Wine.

 

Download:

The script won't ruin anything, still - use it on your own liability. It is provided in good faith, and I can't be held responsible for anything that happens as a consequence of using the script

 

 

 

 

il2record_1-04a.zip

Edited by Roshko
update to v1.04
  • Roshko changed the title to Linux: Tool to record tracks forever "il2record.sh"

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...