Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # SCEI/Sony PS2 - .XWB/.XWH/.XWS(RXWS) splitter
- # v2 by bnnm (correctly parses stream sizes, XWS support)
- set FILENAME_INFO 1 #config
- ###############
- set IS_XWS 1
- get EXT extension
- if EXT != "XWS" && EXT != "xws"
- set IS_XWS 0
- open FDDE "XWH" 0
- open FDDE "XWB" 1
- endif
- #RXWS
- idstring "RXWS"
- get RXWS_SIZE long
- get DUMMY long
- get DUMMY long
- #FORM
- idstring "FORM"
- get FORM_SIZE long
- get DUMMY long
- get DUMMY long
- savepos FORM1
- log MEMORY_FILE FORM1 FORM_SIZE #save FORM to memfile1 to read later
- get FORM_STREAMS long MEMORY_FILE
- #FTXT
- xmath FTXT_OFFSET "FORM_SIZE + 0x10 + 0x10"
- goto FTXT_OFFSET
- idstring "FTXT"
- get FTXT_SIZE long
- get DUMMY long
- get DUMMY long
- savepos FTXT1
- log MEMORY_FILE2 FTXT1 FTXT_SIZE #save FTXT to memfile2 to read later
- get FTXT_STREAMS long MEMORY_FILE2
- #BODY
- if IS_XWS == 1
- xmath BODY_OFFSET "FTXT_OFFSET + 0x10 + FTXT_SIZE"
- goto BODY_OFFSET
- idstring "BODY"
- get BODY_SIZE long
- else
- set BODY_OFFSET 0
- get BODY_SIZE asize 1
- endif
- xmath FORM_STREAMS_LESS1 "FORM_STREAMS - 1"
- # split streams
- for I = 0 < FORM_STREAMS
- #get stream header
- get FORM01 long MEMORY_FILE #codec+?+flags
- get FORM02 long MEMORY_FILE #vol/pan/etc
- get FORM03 long MEMORY_FILE #?+ch+sample rate
- get FORM04 long MEMORY_FILE #0
- get FORM05 long MEMORY_FILE #stream offset within BODY
- get FORM06 long MEMORY_FILE #loop end
- get FORM07 long MEMORY_FILE #loop start
- #get stream name
- get FTXT_NAME_OFF long MEMORY_FILE2
- savepos FTXT_TMP_OFF MEMORY_FILE2
- goto FTXT_NAME_OFF MEMORY_FILE2
- get FTXT_NAME string MEMORY_FILE2
- goto FTXT_TMP_OFF MEMORY_FILE2
- #expected string max
- strlen NAME_LEN FTXT_NAME
- if NAME_LEN > 0x18
- print "big name found, fix me"
- exit
- endif
- # get stream offset/size
- if IS_XWS == 1
- xmath STREAM_OFFSET "BODY_OFFSET + 0x10 + FORM05"
- else
- set STREAM_OFFSET FORM05
- endif
- if I == FORM_STREAMS_LESS1
- xmath STREAM_SIZE "BODY_SIZE - STREAM_OFFSET"
- else
- savepos OFFSET MEMORY_FILE
- savepos NEXT_OFFSET MEMORY_FILE
- math NEXT_OFFSET += 0x10 #next FORM05
- goto NEXT_OFFSET MEMORY_FILE
- get NEXT_STREAM_OFFSET long MEMORY_FILE
- if IS_XWS == 1
- xmath NEXT_STREAM_OFFSET "BODY_OFFSET + 0x10 + NEXT_STREAM_OFFSET"
- endif
- goto OFFSET MEMORY_FILE
- xmath STREAM_SIZE "NEXT_STREAM_OFFSET - STREAM_OFFSET"
- endif
- if IS_XWS == 1
- callfunction SPLIT_XWS 1
- else
- callfunction SPLIT_XWB_XWH 1
- endif
- next I
- startfunction SPLIT_XWB_XWH
- set RXWS_SIZE 0x60
- set FORM_SIZE 0x20
- set FTXT_SIZE 0x20
- #xwb split
- log MEMORY_FILE3 0 0
- log MEMORY_FILE3 STREAM_OFFSET STREAM_SIZE 1
- if FILENAME_INFO == 1
- get BASE basename
- string XWBNAME p= "%s_%03i__%s.xwb" BASE I FTXT_NAME
- else
- string XWBNAME p= "%s.xwb" FTXT_NAME
- endif
- get SIZE asize MEMORY_FILE3
- log XWBNAME 0 SIZE MEMORY_FILE3
- #xwh split
- log MEMORY_FILE4 0 0
- goto 0 MEMORY_FILE4
- append #on
- putdstring "RXWS" 4 MEMORY_FILE4
- put RXWS_SIZE long MEMORY_FILE4
- put 0x200 long MEMORY_FILE4
- put 0x00800000 long MEMORY_FILE4 #split mark
- putdstring "FORM" 4 MEMORY_FILE4
- put FORM_SIZE long MEMORY_FILE4
- put 0x100 long MEMORY_FILE4
- put 0 long MEMORY_FILE4
- put 1 long MEMORY_FILE4 #streams
- put FORM01 long MEMORY_FILE4
- put FORM02 long MEMORY_FILE4
- put FORM03 long MEMORY_FILE4
- put FORM04 long MEMORY_FILE4
- put 0 long MEMORY_FILE4 #new offset
- put FORM06 long MEMORY_FILE4
- put FORM07 long MEMORY_FILE4
- putdstring "FTXT" 4 MEMORY_FILE4
- put FTXT_SIZE long MEMORY_FILE4
- put 0x100 long MEMORY_FILE4
- put 0 long MEMORY_FILE4
- put 1 long MEMORY_FILE4 #streams
- put 8 long MEMORY_FILE4 #name offset
- putdstring FTXT_NAME 0x18 MEMORY_FILE4
- append #off
- if FILENAME_INFO == 1
- get BASE basename
- string XWHNAME p= "%s_%03i__%s.xwh" BASE I FTXT_NAME
- else
- string XWHNAME p= "%s.xwh" FTXT_NAME
- endif
- set SIZE 0x70
- get SIZE asize MEMORY_FILE4
- log XWHNAME 0 SIZE MEMORY_FILE4
- endfunction
- startfunction SPLIT_XWS
- xmath RXWS_SIZE "0x60 + 0x10 + STREAM_SIZE"
- set FORM_SIZE 0x20
- set FTXT_SIZE 0x20 ##not correct for shorter or longer names
- #xws split
- log MEMORY_FILE3 0 0
- goto 0 MEMORY_FILE3
- append #on
- putdstring "RXWS" 4 MEMORY_FILE3
- put RXWS_SIZE long MEMORY_FILE3
- put 0x200 long MEMORY_FILE3
- put 0x00800000 long MEMORY_FILE3 #split mark
- putdstring "FORM" 4 MEMORY_FILE3
- put FORM_SIZE long MEMORY_FILE3
- put 0x100 long MEMORY_FILE3
- put 0 long MEMORY_FILE3
- put 1 long MEMORY_FILE3 #streams
- put FORM01 long MEMORY_FILE3
- put FORM02 long MEMORY_FILE3
- put FORM03 long MEMORY_FILE3
- put FORM04 long MEMORY_FILE3
- put 0 long MEMORY_FILE3 #new offset
- put FORM06 long MEMORY_FILE3
- put FORM07 long MEMORY_FILE3
- putdstring "FTXT" 4 MEMORY_FILE3
- put FTXT_SIZE long MEMORY_FILE3
- put 0x100 long MEMORY_FILE3
- put 0 long MEMORY_FILE3
- put 1 long MEMORY_FILE3 #streams
- put 8 long MEMORY_FILE3 #name offset
- putdstring FTXT_NAME 0x18 MEMORY_FILE3
- putdstring "BODY" 4 MEMORY_FILE3
- put STREAM_SIZE long MEMORY_FILE3
- put 0x100 long MEMORY_FILE3
- put 0 long MEMORY_FILE3
- log MEMORY_FILE3 STREAM_OFFSET STREAM_SIZE 0
- append #off
- if FILENAME_INFO == 1
- get BASE basename
- string XWSNAME p= "%s_%03i__%s.xws" BASE I FTXT_NAME
- else
- string XWSNAME p= "%s.xws" FTXT_NAME
- endif
- get SIZE asize MEMORY_FILE3
- log XWSNAME 0 SIZE MEMORY_FILE3
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement