SHARE
TWEET

EA SWVR demuxer

bnnm Apr 13th, 2018 25 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ########################################################################
  2. # EA SWVR demuxer (.av/flm/trk/mis/etc)
  3. #  (NASCAR Rumble (PS), Future Cop LAPD (PC/PS), Freekstyle (PS2/GC)
  4. #
  5. # Extracts "SWVR" subfiles, that contain sound or other data.
  6. # Other subfiles are ignored, which may contain minor sfx.
  7. ########################################################################
  8.  
  9. #config:
  10.  
  11. # 0=LE (PC, PSX, etc), 1=BE (GC, SAT, MAC, etc)
  12. set ENDIAN_CONFIG long 0
  13.  
  14. ###
  15.  
  16. #ids and sizes are LE or BE
  17. if ENDIAN_CONFIG == 0
  18.   endian LITTLE
  19. elif ENDIAN_CONFIG == 1
  20.   endian BIG  
  21. endif
  22.  
  23. get FILE_SIZE asize
  24. set OFFSET long 0
  25.  
  26. set FILE_COUNT long 0
  27. set IS_SWVR long 0
  28. log MEMORY_FILE 0 0  #reset
  29.  
  30.  
  31. do
  32.   goto OFFSET
  33.  
  34.   get BLOCK_ID long
  35.   get BLOCK_SIZE long
  36.  
  37.  
  38.   # needed?
  39.   if BLOCK_ID == 0 || BLOCK_SIZE == 0
  40.     math OFFSET += 0x4
  41.     continue
  42.   endif
  43.  
  44.   # FILLs do that up to 0x6000, but at 0x5FFC don't actually have size
  45.   if BLOCK_ID == 0x46494C4C # "FILL"
  46.       xmath REMAINDER "(OFFSET + 0x04) % 0x6000"
  47.       if REMAINDER == 0
  48.          set BLOCK_SIZE long 0x04
  49.       endif
  50.   endif
  51.  
  52.   # output previous swvr if exists
  53.   if BLOCK_ID == 0x53575652 #"SWVR"
  54.     callfunction WRITE_SWVR 1
  55.     set IS_SWVR long 1
  56.   endif
  57.  
  58.  
  59.   # append block if swvr, or only certain chunks if headerless (needed for vids)
  60.   append #on
  61.   if IS_SWVR == 1 ###&& BLOCK_ID != 0x46494C4C #FILL could be ignored
  62.     log MEMORY_FILE OFFSET BLOCK_SIZE
  63.   elif BLOCK_ID == 0x5641474D || BLOCK_ID == 0x56414742 || BLOCK_ID == 0x44535042 || BLOCK_ID == 0x4453504D  #VAGM/VAGB/DSPM/DSPB
  64.     log MEMORY_FILE OFFSET BLOCK_SIZE
  65.   endif
  66.   append #off
  67.  
  68.   math OFFSET += BLOCK_SIZE
  69.  
  70.  
  71. while OFFSET < FILE_SIZE
  72.  
  73.  
  74.  
  75. # write last file if needed
  76. callfunction WRITE_SWVR 1
  77.  
  78.  
  79. ##########################################
  80.  
  81. startfunction WRITE_SWVR
  82.   get SIZE asize MEMORY_FILE
  83.  
  84.   if SIZE != 0
  85.  
  86.     # get filename from swvr header, or ignore if headerless
  87.     goto 0 MEMORY_FILE
  88.     get SWVRBLOCK_ID long MEMORY_FILE
  89.     goto 0x10 MEMORY_FILE
  90.     get FILEBLOCK_ID long MEMORY_FILE
  91.  
  92.  
  93.     get FILE_NAME basename
  94.     if SWVRBLOCK_ID == 0x53575652 && FILEBLOCK_ID == 0x46494C45 # SWVR and FILE
  95.       getdstring INTERNAL_NAME 0x10 MEMORY_FILE
  96.       string NAME p=  "%s_%04i__%s" FILE_NAME FILE_COUNT INTERNAL_NAME
  97.     else
  98.       string NAME p= "%s_%04i.stream" FILE_NAME FILE_COUNT
  99.     endif
  100.  
  101.     #some filenames are cut
  102.     if NAME ext "strea"
  103.       string NAME += "m"
  104.     elif NAME ext "stre"
  105.       string NAME += "am"
  106.     elif NAME ext "str"
  107.       string NAME += "eam"
  108.     elif NAME ext "st"
  109.       string NAME += "ream"
  110.     endif
  111.  
  112.     log NAME 0 SIZE MEMORY_FILE
  113.     log MEMORY_FILE 0 0 #reset
  114.  
  115.     math FILE_COUNT += 1
  116.   endif
  117.  
  118. endfunction
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top