Important information: this site is currently scheduled to go offline indefinitely by end of the year.

My quickBMS scripts

Coders and would-be coders alike, this is the place to talk about programming.
AlphaTwentyThree
double-veteran
double-veteran
Posts: 982
Joined: Mon Aug 24, 2009 10:55 pm
Has thanked: 76 times
Been thanked: 660 times

Re: My quickBMS scripts

Post by AlphaTwentyThree »

addCDXAheader.bms
Adds a PSX ADPCM header to a headerless file. These files can be played with the vgmstream plugin for Winamp afterwards.

Code: Select all

# add a PSX ADPCM header to a headerless file
# note: the format always has 37,800Hz and 2 channels

set MEMORY_FILE binary "\x52\x49\x46\x46\xe4\x4\xbe\x2\x43\x44\x58\x41\x66\x6d\x74\x20\x10\x0\x0\x0\x0\x0\x0\x0\x1\x55\x58\x41\x1\x0\x0\x00\x0\x0\x0\x0\x64\x61\x74\x61\xc0\x4\xbe\x2"

get SIZE asize
get NAME basename
string NAME += ".xa"
set RIFFSIZE SIZE
math RIFFSIZE += 0x24
putVarChr MEMORY_FILE 0x04 RIFFSIZE long
putVarChr MEMORY_FILE 0x28 SIZE long

append
log MEMORY_FILE 0 SIZE
append
math SIZE += 0x2c
log NAME 0 SIZE MEMORY_FILE
Last edited by AlphaTwentyThree on Mon Aug 23, 2010 4:52 pm, edited 2 times in total.
If you like what you see, why not click the little Thank You button? ;) It will definitely motivate me! :)
And here's Mr.Mouse's Facebook link: http://www.facebook.com/permalink.php?s ... 8469022795 - thanks ;)
AlphaTwentyThree
double-veteran
double-veteran
Posts: 982
Joined: Mon Aug 24, 2009 10:55 pm
Has thanked: 76 times
Been thanked: 660 times

Re: My quickBMS scripts

Post by AlphaTwentyThree »

Prototype *.p3d XMA2 extractor
This script extracts the XMA2 stream from Prototype Xbox 360 *.p3d files. The resulting file needs to be rebuilt to XMA1 (the -r option of xma_parse). Adding a 48kHz stereo header with my script results in toWAV-decodable files.

Code: Select all

# *.p3d to XMA2 extractor
# version 1.1

endian big
FindLoc AUDIO string "AudioFile" 0 ""
math AUDIO += 0x0e
goto AUDIO
get NAMEL long
getDstring NAME NAMEL
get ZERO byte
get KEYL long
getDstring KEY KEYL
get ZERO byte
get DUMMY long
get XMAL long
get XMA long
savepos OFFSET
get XMA2 long
get HEADSIZE long
get DATASIZE long
math OFFSET += DATASIZE
math OFFSET += HEADSIZE
math OFFSET += 0x14
get SIZE asize
math SIZE -= OFFSET
string NAME += ".uxma"

log NAME OFFSET SIZE
If you like what you see, why not click the little Thank You button? ;) It will definitely motivate me! :)
And here's Mr.Mouse's Facebook link: http://www.facebook.com/permalink.php?s ... 8469022795 - thanks ;)
AlphaTwentyThree
double-veteran
double-veteran
Posts: 982
Joined: Mon Aug 24, 2009 10:55 pm
Has thanked: 76 times
Been thanked: 660 times

Re: My quickBMS scripts

Post by AlphaTwentyThree »

RIFX_convert.bms

This script changes the RIFX header to various other headers. Those RIFX files are normally contained inside Wwise *.bnk containers.

Code: Select all

endian big
goto 0x14
get FORMAT short
get ZERO byte
get CH byte
get FREQ long
if FORMAT == 65534 # WAV
	set MEMORY_FILE binary "\x52\x49\x46\x46\x44\xde\x37\x00\x57\x41\x56\x45\x66\x6d\x74\x20\x10\x00\x00\x00\x01\x00\x02\x00\x80\xbb\x00\x00\x00\xee\x02\x00\x04\x00\x10\x00"
	get INFO long
	if INFO == 96000 # loop markers
		goto 0x48
		get SMPL long
		putVarChr MEMORY_FILE 0x24 SMPL long # append "smpl"
		set WOFFSET 0x28 # write offset (of memory file)
		for i = 0 < 15 # append reversed loop cues
			get TBR long
			reverseLong TBR
			putVarChr MEMORY_FILE WOFFSET TBR long
			math WOFFSET += 4
		next i
		set DATA 0x98
	elif INFO == 192000 # no loop markers
		set DATA 0x48
	endif
	goto DATA
	getDstring DATA 4
	#putVarChr MEMORY_FILE 
	set MEMORY_FILE binary "\x52\x49\x46\x46\x44\xde\x37\x00\x57\x41\x56\x45\x66\x6d\x74\x20\x10\x00\x00\x00\x01\x00\x02\x00\x80\xbb\x00\x00\x00\xee\x02\x00\x04\x00\x10\x00"
elif FORMAT == 65535 # OGG
	print "Wwise OGG file -> run through ww2ogg"
elif FORMAT == 2 # Wii DSP
	print "Wii ADPCM - to be implemented..."
elif FORMAT == 358 # XMA
	goto 0x4c
	get SEEKL long
	savepos MYOFF
	math MYOFF += SEEKL
	math MYOFF += 0x18 # XMAc.....JUNK
	goto MYOFF
	get JUNKL long
	savepos MYOFF
	math MYOFF += JUNKL
	goto MYOFF
	get DATA long
	get XSIZE long
	savepos OFFSET
	endian little
	get SIZE asize
	math SIZE -= OFFSET
	set RIFFSIZE SIZE
	math RIFFSIZE += 0x34

	set MEMORY_FILE binary "\x52\x49\x46\x46\xb8\x59\xa7\x00\x57\x41\x56\x45\x66\x6d\x74\x20\x20\x00\x00\x00\x65\x01\x10\x00\xd6\x10\x00\x00\x01\x00\x00\x03\xe3\x9a\x00\x00\x80\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x02\x00\x64\x61\x74\x61\x00\x58\xa7\x00"
	putVarChr MEMORY_FILE 0x04 RIFFSIZE long
	putVarChr MEMORY_FILE 0x24 FREQ long
	putVarChr MEMORY_FILE 0x31 CH byte
	putVarChr MEMORY_FILE 0x38 SIZE long

	append
	log MEMORY_FILE OFFSET SIZE
	append
	math SIZE += 0x3c
	get NAME basename
	string NAME += ".xma"
	log NAME 0 SIZE MEMORY_FILE
else
	print "Format yet unsupported by script."
	print "Please send this file to AlphaTwentyThree at Xentax!"
endif
Last edited by AlphaTwentyThree on Sun Dec 05, 2010 8:33 pm, edited 2 times in total.
If you like what you see, why not click the little Thank You button? ;) It will definitely motivate me! :)
And here's Mr.Mouse's Facebook link: http://www.facebook.com/permalink.php?s ... 8469022795 - thanks ;)
AlphaTwentyThree
double-veteran
double-veteran
Posts: 982
Joined: Mon Aug 24, 2009 10:55 pm
Has thanked: 76 times
Been thanked: 660 times

Re: My quickBMS scripts

Post by AlphaTwentyThree »

FSB_scan.bms

Simply scans a file for included FSB containers. The *.xxx files of many UT3-engine based games for example can't (yet) be extracted, so it's handy to scan them for FSB containers. And of course if you're too lazy to write your own bms script for a container but you only need the contents of the contained *.fsb files, this is the way to go. Currently supports FSB3 and FSB4.

Code: Select all

# FSB scanner
# ver. 1.1 by AlphaTwentyThree 07-07-2010
# scans for FSB3 and FSB4 containers

get BNAME basename
string BNAME += "_"
get FSIZE asize
set i 1
set XSIZE 0

for
	FindLoc OFFSET string "FSB" 0 ""
	if OFFSET != ""
		set SKIP 0
		goto OFFSET
		getDstring VER 4
		if VER == "FSB3"
			set HEADCORR 0x18
			elif VER == "FSB4"
			set HEADCORR 0x30
		else
			set SKIP 1
		endif
		if SKIP == 0   
			get FILES long
			get HEADER long
			math HEADER += HEADCORR
			get SIZE long
			if size > 0
				set TSIZE SIZE
				math TSIZE += XSIZE
				if TSIZE < FSIZE
					math SIZE += HEADER
					set NAME BNAME
					string NAME += i
					string NAME += ".fsb"
					log NAME OFFSET SIZE
					math i += 1
					math XSIZE += SIZE # size of extracted files
					math OFFSET += SIZE
					goto OFFSET
				endif
			endif
		endif
	else
		cleanexit
	endif
next
Note: The extracted files are named after their origin container.
Last edited by AlphaTwentyThree on Wed Jul 07, 2010 11:47 am, edited 4 times in total.
If you like what you see, why not click the little Thank You button? ;) It will definitely motivate me! :)
And here's Mr.Mouse's Facebook link: http://www.facebook.com/permalink.php?s ... 8469022795 - thanks ;)
AlphaTwentyThree
double-veteran
double-veteran
Posts: 982
Joined: Mon Aug 24, 2009 10:55 pm
Has thanked: 76 times
Been thanked: 660 times

Re: My quickBMS scripts

Post by AlphaTwentyThree »

addIMAADPCMheader.bms

Adds a standard IMA ADPCM header to a headerless file. Filesizes are adjusted automatically.

Code: Select all

set MEMORY_FILE binary "\x52\x49\x46\x46\x10\xe4\x03\x00\x57\x41\x56\x45\x66\x6d\x74\x20\x14\x0\x0\x0\x11\x0\x2\x0\x44\xac\x0\x0\xcc\xc1\x0\x0\x48\x0\x4\x0\x2\x0\x41\x0\x64\x61\x74\x61\xe8\xe3\x3\x0"

set FREQ 44100
set CH 2

get NAME basename
get SIZE asize
string NAME += ".wav"
set RIFFSIZE SIZE
math RIFFSIZE += 0x28
putVarChr MEMORY_FILE 0x04 RIFFSIZE long
putVarChr MEMORY_FILE 0x18 FREQ long
putVarChr MEMORY_FILE 0x24 CH byte
putVarChr MEMORY_FILE 0x2c SIZE long

append
log MEMORY_FILE 0 SIZE
append
math SIZE += 0x30
log NAME 0 SIZE MEMORY_FILE
Last edited by AlphaTwentyThree on Wed Aug 18, 2010 12:29 am, edited 2 times in total.
If you like what you see, why not click the little Thank You button? ;) It will definitely motivate me! :)
And here's Mr.Mouse's Facebook link: http://www.facebook.com/permalink.php?s ... 8469022795 - thanks ;)
AlphaTwentyThree
double-veteran
double-veteran
Posts: 982
Joined: Mon Aug 24, 2009 10:55 pm
Has thanked: 76 times
Been thanked: 660 times

Re: My quickBMS scripts

Post by AlphaTwentyThree »

Just corrected the FSB4 scanner. The IDENT variable apparently is the number of files in the FSB container... ;)
If you like what you see, why not click the little Thank You button? ;) It will definitely motivate me! :)
And here's Mr.Mouse's Facebook link: http://www.facebook.com/permalink.php?s ... 8469022795 - thanks ;)
AlphaTwentyThree
double-veteran
double-veteran
Posts: 982
Joined: Mon Aug 24, 2009 10:55 pm
Has thanked: 76 times
Been thanked: 660 times

Re: My quickBMS scripts

Post by AlphaTwentyThree »

Another correction for the FSB4 scanner, which iss now the FSB scanner. ;) Supports FSB3 and FSB4 now.
If you like what you see, why not click the little Thank You button? ;) It will definitely motivate me! :)
And here's Mr.Mouse's Facebook link: http://www.facebook.com/permalink.php?s ... 8469022795 - thanks ;)
AlphaTwentyThree
double-veteran
double-veteran
Posts: 982
Joined: Mon Aug 24, 2009 10:55 pm
Has thanked: 76 times
Been thanked: 660 times

Re: My quickBMS scripts

Post by AlphaTwentyThree »

Corrected and updated the file deinterleaver. Now also with header skip. =)
If you like what you see, why not click the little Thank You button? ;) It will definitely motivate me! :)
And here's Mr.Mouse's Facebook link: http://www.facebook.com/permalink.php?s ... 8469022795 - thanks ;)
AlphaTwentyThree
double-veteran
double-veteran
Posts: 982
Joined: Mon Aug 24, 2009 10:55 pm
Has thanked: 76 times
Been thanked: 660 times

Re: My quickBMS scripts

Post by AlphaTwentyThree »

change_freq.bms
Did it ever happen to you that you ripped a lot of files by hand or added a custom header when you realize that you've set the frequency wrong? Especially when working with GENH or when you've deleted all the headerless files you worked with before it can be really annoying. This script writes the defined frequency to a defined offset. Just set quickBMS to overwrite and there you go. Very simple. ;)

Code: Select all

set FREQ 22050 # new frequency
set OFFSET 0x0c # offset of old frequency
get SIZE asize
putVarChr MEMORY_FILE SIZE 0
log MEMORY_FILE 0 0
append
log MEMORY_FILE 0 SIZE
append
putVarChr MEMORY_FILE OFFSET FREQ long
get NAME basename
string NAME += "_new."
get EXT extension
string NAME += EXT
log NAME 0 SIZE MEMORY_FILE
And here is a scrip to divide a given frequency by 2 (needed on e.g. decoded wave files from Resident Evil 6 Xbox 360):

Code: Select all

set OFFSET 0x18
goto OFFSET
get FREQ long
math FREQ /= 2
get SIZE asize
putVarChr MEMORY_FILE SIZE 0
log MEMORY_FILE 0 0
append
log MEMORY_FILE 0 SIZE
append
putVarChr MEMORY_FILE OFFSET FREQ long
get NAME basename
string NAME += "_new.wav"
log NAME 0 SIZE MEMORY_FILE
Last edited by AlphaTwentyThree on Sat Jul 07, 2012 8:07 pm, edited 2 times in total.
If you like what you see, why not click the little Thank You button? ;) It will definitely motivate me! :)
And here's Mr.Mouse's Facebook link: http://www.facebook.com/permalink.php?s ... 8469022795 - thanks ;)
AlphaTwentyThree
double-veteran
double-veteran
Posts: 982
Joined: Mon Aug 24, 2009 10:55 pm
Has thanked: 76 times
Been thanked: 660 times

Re: My quickBMS scripts

Post by AlphaTwentyThree »

add6chXMAHeader.bms
Ever got sick of extracting and rebuilding the three stereo channel sets of multichannel XMA2 files? Here's a script that adds a multichannel XMA2 header to a headerless file, which is then decodable by toWAV.

Code: Select all

set MEMORY_FILE binary "\x52\x49\x46\x46\x14\xdd\x44\x1\x57\x41\x56\x45\x58\x4d\x41\x32\x34\x0\x0\x0\x4\x3\x0\xff\x0\xc\x34\x80\x0\xa3\x88\x80\x0\x0\xbb\x80\x10\xd6\x0\x0\x0\x0\x74\x41\x0\x1\x0\x0\x0\xb6\xa8\x0\x0\xb6\xa4\xc6\x0\x0\x1\x45\x2\x0\x2\x1\x2\x0\x8\x4\x2\x0\x80\x40\x41\x4c\x49\x47\x64\x7"
endian big
putVarChr MEMORY_FILE 0x7b4 0x78327374 long
putVarChr MEMORY_FILE 0x7b8 0x3c byte
putVarChr MEMORY_FILE 0x7c4 0x0A000100 long
putVarChr MEMORY_FILE 0x7ca 0xb4c2 short
putVarChr MEMORY_FILE 0x7d0 0xFFFF0100 long
putVarChr MEMORY_FILE 0x7e6 0x803f1600 long
putVarChr MEMORY_FILE 0x7ec 0x8026 short
putVarChr MEMORY_FILE 0x7f0 0x2601 short
putVarChr MEMORY_FILE 0x7f4 0x303f short
putVarChr MEMORY_FILE 0x7f8 0x64617461 long # data
endian little

set FREQ 48000
set BLOCKSIZE 0x3000

get NAME basename
get SIZE asize
string NAME += ".xma"
set RIFFSIZE SIZE
math RIFFSIZE += 0x7F8

putVarChr MEMORY_FILE 0x04 RIFFSIZE long
reverseLong FREQ
putVarChr MEMORY_FILE 0x20 FREQ long
reverseLong BLOCKSIZE
putVarChr MEMORY_FILE 0x2C BLOCKSIZE long
putVarChr MEMORY_FILE 0x7FC SIZE long

append
log MEMORY_FILE 0 SIZE
append
math SIZE += 0x800
log NAME 0 SIZE MEMORY_FILE
Note: I didn't set the memory to the actual header as most of it consists of zeroes.
Last edited by AlphaTwentyThree on Wed Aug 18, 2010 12:28 am, edited 2 times in total.
If you like what you see, why not click the little Thank You button? ;) It will definitely motivate me! :)
And here's Mr.Mouse's Facebook link: http://www.facebook.com/permalink.php?s ... 8469022795 - thanks ;)
User avatar
aluigi
VVIP member
VVIP member
Posts: 1916
Joined: Thu Dec 08, 2005 12:26 pm
Location: www.ZENHAX.com
Has thanked: 4 times
Been thanked: 664 times
Contact:

Re: My quickBMS scripts

Post by aluigi »

a tip for making the MEMORY_FILE visually shorter:
replace any \x00 with \0
AlphaTwentyThree
double-veteran
double-veteran
Posts: 982
Joined: Mon Aug 24, 2009 10:55 pm
Has thanked: 76 times
Been thanked: 660 times

Re: My quickBMS scripts

Post by AlphaTwentyThree »

aluigi wrote:a tip for making the MEMORY_FILE visually shorter:
replace any \x00 with \0
Right, thanks. ;)
If you like what you see, why not click the little Thank You button? ;) It will definitely motivate me! :)
And here's Mr.Mouse's Facebook link: http://www.facebook.com/permalink.php?s ... 8469022795 - thanks ;)
OrangeC
double-veteran
double-veteran
Posts: 868
Joined: Sun Apr 20, 2008 2:58 am
Has thanked: 5 times
Been thanked: 41 times

Re: My quickBMS scripts

Post by OrangeC »

so im guessing this is the first multichannel xma2 header? ;)
AlphaTwentyThree
double-veteran
double-veteran
Posts: 982
Joined: Mon Aug 24, 2009 10:55 pm
Has thanked: 76 times
Been thanked: 660 times

Re: My quickBMS scripts

Post by AlphaTwentyThree »

OrangeC wrote:so im guessing this is the first multichannel xma2 header? ;)
Well it's quite old but I never took a closer look at it because my scripting skills with quickBMS were about zero at that point of time. It's from Ace Combat 6, maybe you remember the old thread where most of the XMA2 questions were solved. ;) But yeah I guess it's the first working program to process multichannel XMA2 files. :)
If you like what you see, why not click the little Thank You button? ;) It will definitely motivate me! :)
And here's Mr.Mouse's Facebook link: http://www.facebook.com/permalink.php?s ... 8469022795 - thanks ;)
AlphaTwentyThree
double-veteran
double-veteran
Posts: 982
Joined: Mon Aug 24, 2009 10:55 pm
Has thanked: 76 times
Been thanked: 660 times

Re: My quickBMS scripts

Post by AlphaTwentyThree »

STR_audio_extract.bms
Extracts the audio data from Playstation *.str video files as *.xa file (playable with the vgmstream plugin for Winamp).
Note: You'll need to RAW-copy the *.str files with IsoBuster before they can be processed.
UPDATE: new revision with multistream support! :)

Code: Select all

# (c) 2012-02-15 by AlphaTwentyThree of XeNTaX

callfunction detectstreams 1
set SIMPLE 1
if STREAMS > 1
	set SIMPLE 0
endif

for i = 0 < STREAMS
	callfunction getstreamsize 1
	math SSIZE *= 0x930
	if SSIZE != 0
		putVarChr MEMORY_FILE SSIZE 0
		log MEMORY_FILE 0 0
		get FSIZE asize
		set OFFSET 0
		append
		DO
			set IDENT OFFSET
			math IDENT += 0x11
			goto IDENT
			get STREAM byte
			get DAT byte
			if DAT == 0x64 # audio marker
				if SIMPLE == 1
					log MEMORY_FILE OFFSET 0x930
				else
					if STREAM == i
						log MEMORY_FILE OFFSET 0x930
					endif
				endif
			endif
			math OFFSET += 0x930
		WHILE OFFSET < FSIZE
		append
		
		callfunction CDXA 1
		get NAME basename
		if SIMPLE == 0
			string NAME += "_"
			string NAME += i
		endif
		string NAME += ".xa"
		get SIZE asize MEMORY_FILE2
		log NAME 0 SIZE MEMORY_FILE2
	endif
next i
	
startfunction detectstreams
	get FSIZE asize
	set STREAMS 0
	DO # brute-force run though whole file
		set IDENT OFFSET
		math IDENT += 0x11
		goto IDENT
		get STREAM byte
		if STREAM > STREAMS
			set STREAMS STREAM
		endif
		math OFFSET += 0x930
	WHILE OFFSET < FSIZE
endfunction

startfunction getstreamsize
	set SSIZE 0
	get FSIZE asize
	set OFFSET 0
	DO
		set IDENT OFFSET
		math IDENT += 0x11
		goto IDENT
		get STREAM byte
		if STREAM == i
			math SSIZE += 1
		endif
		math OFFSET += 0x930
	WHILE OFFSET < FSIZE
endfunction

startfunction CDXA
	log MEMORY_FILE2 0 0
	set MEMORY_FILE2 binary "\x52\x49\x46\x46\xe4\x04\xbe\x02\x43\x44\x58\x41\x66\x6d\x74\x20\x10\x0\x0\x0\x0\x0\x0\x0\x1\x55\x58\x41\x1\x0\x0\x0\x0\x0\x0\x0\x64\x61\x74\x61\xc0\x4\xbe\x2"
	get SIZE asize MEMORY_FILE
	append
	log MEMORY_FILE2 0 SIZE MEMORY_FILE
	append
	set RIFFSIZE SIZE
	math RIFFSIZE -= 8
	set DSIZE SIZE
	math DSIZE -= 0x2c
	putVarChr MEMORY_FILE2 0x04 RIFFSIZE long
	putVarChr MEMORY_FILE2 0x28 DSIZE long
endfunction
Last edited by AlphaTwentyThree on Wed Feb 15, 2012 4:22 pm, edited 8 times in total.
If you like what you see, why not click the little Thank You button? ;) It will definitely motivate me! :)
And here's Mr.Mouse's Facebook link: http://www.facebook.com/permalink.php?s ... 8469022795 - thanks ;)
Post Reply