SHARE
TWEET

Ubisoft SMx Splitter

Nicknine Dec 21st, 2018 (edited) 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Ubisoft .SMx files - splits them up into single map SMx files
  2. # Script for QuickBMS: https://aluigi.altervista.org/quickbms.htm
  3.  
  4. # Detect endianness
  5. goto 0x08
  6. get ENDIAN_TEST long
  7. endian guess ENDIAN_TEST
  8. goto 0x00
  9.  
  10. get VERSION long
  11. get HEADER_SIZE long
  12. get SECTIONS long
  13. goto HEADER_SIZE
  14.  
  15. # Detect maps format version
  16. xmath MAJOR_VERSION "(VERSION & 0xFFFF0000) >> 16"
  17. xmath MINOR_VERSION "VERSION & 0x0000FFFF"
  18.  
  19. if MAJOR_VERSION >= 0x0A # First seen in Batman: Rise of Sin Tzu
  20.     if MAJOR_VERSION >= 0x16 # First seen in Splinter Cell: Double Agent
  21.         math MAP_VERSION = 3
  22.     else
  23.         math MAP_VERSION = 2
  24.     endif
  25. else
  26.     math MAP_VERSION = 1
  27. endif
  28.  
  29. # Detect padding
  30. if HEADER_SIZE > 0x0c
  31.     set PADDING_SIZE HEADER_SIZE
  32. else
  33.     set PADDING_SIZE long 0
  34. endif
  35.  
  36. for i = 0 < SECTIONS
  37.     get SEC_TYPE long
  38.     get ZERO long
  39.     get SEC_OFF long
  40.     get SEC_SIZE long
  41.     getdstring SEC_NAME 0x20
  42.  
  43.     if MAP_VERSION > 1
  44.         get SEC_DUMMY long
  45.     endif
  46.    
  47.     # Grab values from section header.
  48.     savepos HEADER_OFF
  49.     goto SEC_OFF
  50.     if MAP_VERSION < 3
  51.         get ZERO long
  52.         get SEC1_OFF long
  53.         get SEC1_NUM long
  54.         get SEC2_OFF long
  55.         get SEC2_NUM long
  56.         get SEC3_OFF long
  57.         get SEC3_NUM long
  58.         get EXTRA_OFF long
  59.         get EXTRA_SIZE long
  60.     else
  61.         get ZERO long
  62.         get SEC1_OFF long
  63.         get SEC1_NUM long
  64.         get SEC2_OFF long
  65.         get SEC2_NUM long
  66.         get SEC4_OFF long
  67.         get SEC4_NUM long
  68.         get SEC3_OFF long
  69.         get SEC3_NUM long
  70.         get EXTRA_OFF long
  71.         get EXTRA_SIZE long
  72.     endif
  73.    
  74.     # Make a new SMx header.
  75.     log MEMORY_FILE 0 0
  76.    
  77.     put VERSION long MEMORY_FILE
  78.     put HEADER_SIZE long MEMORY_FILE
  79.     put 1 long MEMORY_FILE
  80.    
  81.     # Allocate space for section table.
  82.     callfunction WRITE_PADDING 1
  83.     if MAP_VERSION < 2
  84.         putdstring "" 0x30 MEMORY_FILE
  85.     else
  86.         putdstring "" 0x34 MEMORY_FILE
  87.     endif
  88.    
  89.     callfunction WRITE_PADDING 1
  90.     savepos WRITE_SEC_OFF MEMORY_FILE
  91.    
  92.     # Write section header.
  93.     append
  94.     log MEMORY_FILE SEC_OFF SEC_SIZE
  95.     append
  96.    
  97.     # Write all internal sounds.
  98.     xmath SEC3_OFF_ABS "SEC3_OFF + SEC_OFF"
  99.     goto SEC3_OFF_ABS
  100.     for j = 0 < SEC3_NUM
  101.         get ID long
  102.         get TABLE_OFF long
  103.         get TABLE_NUM long
  104.         get TABLE2_OFF long
  105.         get TABLE2_NUM long
  106.        
  107.         math TABLE2_OFF + SEC3_OFF_ABS
  108.         savepos SEC3_HEADER_OFF
  109.         goto TABLE2_OFF
  110.         for k = 0 < TABLE2_NUM
  111.             get SUBID long
  112.             get SND_SIZE_PADDED long
  113.             get SND_SIZE long
  114.             get SND_OFFSET long
  115.            
  116.             # Fix offset in the target file.
  117.             xmath WRITE_OFF "TABLE2_OFF - SEC_OFF + WRITE_SEC_OFF + k * 0x10 + 0x0c"
  118.             get WRITE_VAL asize MEMORY_FILE
  119.             goto WRITE_OFF MEMORY_FILE
  120.             put WRITE_VAL long MEMORY_FILE
  121.            
  122.             append
  123.             log MEMORY_FILE SND_OFFSET SND_SIZE
  124.             append
  125.            
  126.             callfunction WRITE_PADDING 1
  127.         next k
  128.        
  129.         goto SEC3_HEADER_OFF
  130.     next j
  131.    
  132.     # Write the section table properly now that we know the offset.
  133.     goto HEADER_SIZE MEMORY_FILE
  134.     put SEC_TYPE long MEMORY_FILE
  135.     put ZERO long MEMORY_FILE
  136.     put WRITE_SEC_OFF long MEMORY_FILE
  137.     put SEC_SIZE long MEMORY_FILE
  138.     putdstring SEC_NAME 0x20 MEMORY_FILE
  139.    
  140.     if MAP_VERSION > 1
  141.         put SEC_DUMMY long MEMORY_FILE
  142.     endif
  143.    
  144.     get EXT extension
  145.     string NAME p "%s.%s" SEC_NAME EXT
  146.     get SIZE asize MEMORY_FILE
  147.     log NAME 0 SIZE MEMORY_FILE
  148.    
  149.     goto HEADER_OFF
  150. next i
  151.  
  152. startfunction WRITE_PADDING
  153.     if PADDING_SIZE != 0
  154.         get TMP_CUR_OFFSET asize MEMORY_FILE
  155.         xmath TMP_OFFSET "TMP_CUR_OFFSET x PADDING_SIZE"
  156.        
  157.         if TMP_OFFSET > TMP_CUR_OFFSET
  158.             math TMP_OFFSET - 1
  159.             putvarchr MEMORY_FILE TMP_OFFSET 0
  160.             math TMP_OFFSET + 1
  161.             goto TMP_OFFSET MEMORY_FILE
  162.         endif
  163.     endif
  164. 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