Skip to content

Instantly share code, notes, and snippets.

@shmerl
Last active November 10, 2024 12:06
Show Gist options
  • Save shmerl/2cec6273ba25dd1486dd to your computer and use it in GitHub Desktop.
Save shmerl/2cec6273ba25dd1486dd to your computer and use it in GitHub Desktop.
#!/bin/bash
# Run from location where you have audio
# from the <game-dir>/streammusic directory
mp3s=(
[0-5]*.wav
mus_{a,b,t}*.wav
evil_ending.wav
credits.wav
)
wavs=(
al_*.wav
mus_loadscreen.wav
)
mkdir -p fixed
for src in ${mp3s[@]}; do
target="fixed/${src%%.*}.mp3"
echo "fixing ${src} -> ${target}"
dd if=${src} of=${target} ibs=1 skip=58 obs=10M
done
for src in ${wavs[@]}; do
target="fixed/${src}"
echo "fixing ${src} -> ${target}"
dd if=${src} of=${target} ibs=1 skip=470 obs=10M
done
@geextahslex
Copy link

geextahslex commented Nov 10, 2024

for people with windows you can use this powershell script. Save with .ps1 extension. Set the correct paths. Place the script inside the target "streammusic" folder and run the script.

# Set the working directory to the folder containing the audio files
$sourceDir = "C:\Program Files (x86)\Star Wars Knights of the Old Republic\streammusic"
$fixedDir = "C:\kotor\fix"

# Create the 'fixed' directory if it doesn't exist
if (!(Test-Path -Path $fixedDir)) {
    New-Item -ItemType Directory -Path $fixedDir
}

# Define arrays for MP3 and WAV files
$mp3s = Get-ChildItem -Path $sourceDir -Filter "*.wav" | Where-Object { $_.Name -match "^[0-5]|mus_[abt]|evil_ending|credits" }
$wavs = Get-ChildItem -Path $sourceDir -Filter "*.wav" | Where-Object { $_.Name -match "^al_|mus_loadscreen" }

# Process mp3s (skip 58 bytes)
foreach ($src in $mp3s) {
    $target = "$fixedDir\$($src.BaseName).mp3"
    Write-Output "fixing $($src.Name) -> $($target)"
    $inStream = [System.IO.File]::OpenRead($src.FullName)
    $outStream = [System.IO.File]::Create($target)
    $inStream.Seek(58, 'Begin')
    $inStream.CopyTo($outStream)
    $inStream.Close()
    $outStream.Close()
}

# Process wavs (skip 470 bytes)
foreach ($src in $wavs) {
    $target = "$fixedDir\$($src.Name)"
    Write-Output "fixing $($src.Name) -> $($target)"
    $inStream = [System.IO.File]::OpenRead($src.FullName)
    $outStream = [System.IO.File]::Create($target)
    $inStream.Seek(470, 'Begin')
    $inStream.CopyTo($outStream)
    $inStream.Close()
    $outStream.Close()
}

@shmerl
Copy link
Author

shmerl commented Nov 10, 2024

Nice, that would be useful for those who don't have bash on Windows set up.

@geextahslex
Copy link

Indeed, I was confronted yesterday with this problem. You can take this code and put it somewhere for future kotor fans. I don't know github so well. Or just leave it as a coment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment