Add proof of concept .s3p to .2dx script

This commit is contained in:
Hazel 2024-08-30 20:32:55 -04:00
parent 570f9247c2
commit 58a2272b9a

83
s3p_to_2dx.sh Executable file
View File

@ -0,0 +1,83 @@
#!/bin/bash
# Set the directory containing sound files
# This is usually ./sound if youre running the script out of the games data directory
SOUND_DIR="please-set-this"
# Extract .ifs file and descend into its directory
extract_ifs() {
local ifs_file="$1"
echo "Extracting $ifs_file..."
ifstools "$ifs_file" || { echo "Failed to extract $ifs_file"; return 1; }
local extracted_dir="${ifs_file%.*}_ifs"
[ -d "$extracted_dir" ] && cd "$extracted_dir" || { echo "Directory $extracted_dir not found"; return 1; }
}
# Repack .ifs file and move it output to parent directory
repack_to_ifs() {
local ifs_dir=
echo "Repacking $ifs_dir to $output_name..."
# Get the current working directory name
dir_name=$(basename "$OLDPWD")
# Remove the "_ifs" suffix from the directory name if it exists
output_name="${dir_name%_ifs}"
ifstools "$output_name" || { echo "Failed to repack $dir_name"; return 1; }
mv "$output_name".ifs ..
}
# Extract and convert .s3p files
extract_convert_s3p() {
local s3p_file="$1"
echo "Processing $s3p_file..."
s3p_extract "$s3p_file" || { echo "Failed to extract $s3p_file"; return 1; }
local s3p_out_dir="${s3p_file}.out"
[ -d "$s3p_out_dir" ] && cd "$s3p_out_dir" || { echo "Directory $s3p_out_dir not found"; return 1; }
for wma_file in *.wma; do
[ -e "$wma_file" ] || continue
echo "Converting $wma_file..."
ffmpeg -loglevel error -i "$wma_file" -acodec adpcm_ms -b:a 256k "${wma_file%.*}.wav" && rm -f "$wma_file" # Write to /dev/null instead maybe? ffmpeg is loud asf
done
}
# Repack .wav files into .2dx
repack_to_2dx() {
echo "Repacking files to .2dx format..."
# Get the current working directory name
dir_name=$(basename "$OLDPWD")
# Remove the ".out" suffix from the directory name if it exists
output_name="${dir_name%.out}"
2dxBuild "$output_name".2dx || { echo "Failed to repack files"; return 1; }
mv "$output_name".2dx ..
cd ..
rm -rf *s3p* # This is kinda risky but whatever lol
}
# Iterate through directories and .ifs in $SOUND_DIR
process_sound_files() {
if [ ! -d "$SOUND_DIR" ]; then
echo "Directory $SOUND_DIR does not exist."
exit 1
fi
# Process directories for songs not contained in .ifs
for dir in "$SOUND_DIR"/*/; do
echo "Processing directory: $dir"
(cd "$dir" && extract_convert_s3p *.s3p && repack_to_2dx)
done
# Process .ifs files for songs contained in .ifs
for ifs_file in "$SOUND_DIR"/*.ifs; do
echo "Processing IFS file: $ifs_file"
(cd "$SOUND_DIR" && extract_ifs "$ifs_file" && extract_convert_s3p *.s3p && repack_to_2dx && repack_to_ifs)
done
}
# Execute the main function
process_sound_files