Advertisement
Guest User

Untitled

a guest
May 13th, 2017
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. # SCEI/Sony PS2 - .XWB/.XWH/.XWS(RXWS) splitter
  2. # v2 by bnnm (correctly parses stream sizes, XWS support)
  3.  
  4. set FILENAME_INFO 1 #config
  5.  
  6. ###############
  7.  
  8. set IS_XWS 1
  9.  
  10. get EXT extension
  11. if EXT != "XWS" && EXT != "xws"
  12. set IS_XWS 0
  13. open FDDE "XWH" 0
  14. open FDDE "XWB" 1
  15. endif
  16.  
  17.  
  18. #RXWS
  19. idstring "RXWS"
  20. get RXWS_SIZE long
  21. get DUMMY long
  22. get DUMMY long
  23.  
  24. #FORM
  25. idstring "FORM"
  26. get FORM_SIZE long
  27. get DUMMY long
  28. get DUMMY long
  29. savepos FORM1
  30. log MEMORY_FILE FORM1 FORM_SIZE #save FORM to memfile1 to read later
  31. get FORM_STREAMS long MEMORY_FILE
  32.  
  33. #FTXT
  34. xmath FTXT_OFFSET "FORM_SIZE + 0x10 + 0x10"
  35. goto FTXT_OFFSET
  36. idstring "FTXT"
  37. get FTXT_SIZE long
  38. get DUMMY long
  39. get DUMMY long
  40. savepos FTXT1
  41. log MEMORY_FILE2 FTXT1 FTXT_SIZE #save FTXT to memfile2 to read later
  42. get FTXT_STREAMS long MEMORY_FILE2
  43.  
  44. #BODY
  45. if IS_XWS == 1
  46. xmath BODY_OFFSET "FTXT_OFFSET + 0x10 + FTXT_SIZE"
  47. goto BODY_OFFSET
  48. idstring "BODY"
  49. get BODY_SIZE long
  50. else
  51. set BODY_OFFSET 0
  52. get BODY_SIZE asize 1
  53. endif
  54.  
  55.  
  56. xmath FORM_STREAMS_LESS1 "FORM_STREAMS - 1"
  57.  
  58. # split streams
  59. for I = 0 < FORM_STREAMS
  60.  
  61. #get stream header
  62. get FORM01 long MEMORY_FILE #codec+?+flags
  63. get FORM02 long MEMORY_FILE #vol/pan/etc
  64. get FORM03 long MEMORY_FILE #?+ch+sample rate
  65. get FORM04 long MEMORY_FILE #0
  66. get FORM05 long MEMORY_FILE #stream offset within BODY
  67. get FORM06 long MEMORY_FILE #loop end
  68. get FORM07 long MEMORY_FILE #loop start
  69.  
  70.  
  71. #get stream name
  72. get FTXT_NAME_OFF long MEMORY_FILE2
  73. savepos FTXT_TMP_OFF MEMORY_FILE2
  74. goto FTXT_NAME_OFF MEMORY_FILE2
  75. get FTXT_NAME string MEMORY_FILE2
  76. goto FTXT_TMP_OFF MEMORY_FILE2
  77.  
  78. #expected string max
  79. strlen NAME_LEN FTXT_NAME
  80. if NAME_LEN > 0x18
  81. print "big name found, fix me"
  82. exit
  83. endif
  84.  
  85.  
  86. # get stream offset/size
  87. if IS_XWS == 1
  88. xmath STREAM_OFFSET "BODY_OFFSET + 0x10 + FORM05"
  89. else
  90. set STREAM_OFFSET FORM05
  91. endif
  92.  
  93.  
  94. if I == FORM_STREAMS_LESS1
  95. xmath STREAM_SIZE "BODY_SIZE - STREAM_OFFSET"
  96. else
  97. savepos OFFSET MEMORY_FILE
  98. savepos NEXT_OFFSET MEMORY_FILE
  99. math NEXT_OFFSET += 0x10 #next FORM05
  100. goto NEXT_OFFSET MEMORY_FILE
  101. get NEXT_STREAM_OFFSET long MEMORY_FILE
  102. if IS_XWS == 1
  103. xmath NEXT_STREAM_OFFSET "BODY_OFFSET + 0x10 + NEXT_STREAM_OFFSET"
  104. endif
  105. goto OFFSET MEMORY_FILE
  106. xmath STREAM_SIZE "NEXT_STREAM_OFFSET - STREAM_OFFSET"
  107. endif
  108.  
  109.  
  110. if IS_XWS == 1
  111. callfunction SPLIT_XWS 1
  112. else
  113. callfunction SPLIT_XWB_XWH 1
  114. endif
  115. next I
  116.  
  117.  
  118. startfunction SPLIT_XWB_XWH
  119. set RXWS_SIZE 0x60
  120. set FORM_SIZE 0x20
  121. set FTXT_SIZE 0x20
  122.  
  123. #xwb split
  124. log MEMORY_FILE3 0 0
  125. log MEMORY_FILE3 STREAM_OFFSET STREAM_SIZE 1
  126.  
  127. if FILENAME_INFO == 1
  128. get BASE basename
  129. string XWBNAME p= "%s_%03i__%s.xwb" BASE I FTXT_NAME
  130. else
  131. string XWBNAME p= "%s.xwb" FTXT_NAME
  132. endif
  133. get SIZE asize MEMORY_FILE3
  134. log XWBNAME 0 SIZE MEMORY_FILE3
  135.  
  136.  
  137. #xwh split
  138. log MEMORY_FILE4 0 0
  139. goto 0 MEMORY_FILE4
  140.  
  141. append #on
  142.  
  143. putdstring "RXWS" 4 MEMORY_FILE4
  144. put RXWS_SIZE long MEMORY_FILE4
  145. put 0x200 long MEMORY_FILE4
  146. put 0x00800000 long MEMORY_FILE4 #split mark
  147.  
  148. putdstring "FORM" 4 MEMORY_FILE4
  149. put FORM_SIZE long MEMORY_FILE4
  150. put 0x100 long MEMORY_FILE4
  151. put 0 long MEMORY_FILE4
  152. put 1 long MEMORY_FILE4 #streams
  153. put FORM01 long MEMORY_FILE4
  154. put FORM02 long MEMORY_FILE4
  155. put FORM03 long MEMORY_FILE4
  156. put FORM04 long MEMORY_FILE4
  157. put 0 long MEMORY_FILE4 #new offset
  158. put FORM06 long MEMORY_FILE4
  159. put FORM07 long MEMORY_FILE4
  160.  
  161. putdstring "FTXT" 4 MEMORY_FILE4
  162. put FTXT_SIZE long MEMORY_FILE4
  163. put 0x100 long MEMORY_FILE4
  164. put 0 long MEMORY_FILE4
  165. put 1 long MEMORY_FILE4 #streams
  166. put 8 long MEMORY_FILE4 #name offset
  167. putdstring FTXT_NAME 0x18 MEMORY_FILE4
  168.  
  169. append #off
  170.  
  171. if FILENAME_INFO == 1
  172. get BASE basename
  173. string XWHNAME p= "%s_%03i__%s.xwh" BASE I FTXT_NAME
  174. else
  175. string XWHNAME p= "%s.xwh" FTXT_NAME
  176. endif
  177. set SIZE 0x70
  178. get SIZE asize MEMORY_FILE4
  179. log XWHNAME 0 SIZE MEMORY_FILE4
  180.  
  181. endfunction
  182.  
  183.  
  184. startfunction SPLIT_XWS
  185. xmath RXWS_SIZE "0x60 + 0x10 + STREAM_SIZE"
  186. set FORM_SIZE 0x20
  187. set FTXT_SIZE 0x20 ##not correct for shorter or longer names
  188.  
  189.  
  190. #xws split
  191. log MEMORY_FILE3 0 0
  192. goto 0 MEMORY_FILE3
  193.  
  194. append #on
  195.  
  196. putdstring "RXWS" 4 MEMORY_FILE3
  197. put RXWS_SIZE long MEMORY_FILE3
  198. put 0x200 long MEMORY_FILE3
  199. put 0x00800000 long MEMORY_FILE3 #split mark
  200.  
  201. putdstring "FORM" 4 MEMORY_FILE3
  202. put FORM_SIZE long MEMORY_FILE3
  203. put 0x100 long MEMORY_FILE3
  204. put 0 long MEMORY_FILE3
  205. put 1 long MEMORY_FILE3 #streams
  206. put FORM01 long MEMORY_FILE3
  207. put FORM02 long MEMORY_FILE3
  208. put FORM03 long MEMORY_FILE3
  209. put FORM04 long MEMORY_FILE3
  210. put 0 long MEMORY_FILE3 #new offset
  211. put FORM06 long MEMORY_FILE3
  212. put FORM07 long MEMORY_FILE3
  213.  
  214. putdstring "FTXT" 4 MEMORY_FILE3
  215. put FTXT_SIZE long MEMORY_FILE3
  216. put 0x100 long MEMORY_FILE3
  217. put 0 long MEMORY_FILE3
  218. put 1 long MEMORY_FILE3 #streams
  219. put 8 long MEMORY_FILE3 #name offset
  220. putdstring FTXT_NAME 0x18 MEMORY_FILE3
  221.  
  222. putdstring "BODY" 4 MEMORY_FILE3
  223. put STREAM_SIZE long MEMORY_FILE3
  224. put 0x100 long MEMORY_FILE3
  225. put 0 long MEMORY_FILE3
  226.  
  227. log MEMORY_FILE3 STREAM_OFFSET STREAM_SIZE 0
  228.  
  229. append #off
  230.  
  231. if FILENAME_INFO == 1
  232. get BASE basename
  233. string XWSNAME p= "%s_%03i__%s.xws" BASE I FTXT_NAME
  234. else
  235. string XWSNAME p= "%s.xws" FTXT_NAME
  236. endif
  237.  
  238. get SIZE asize MEMORY_FILE3
  239. log XWSNAME 0 SIZE MEMORY_FILE3
  240.  
  241. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement