Advertisement
HenryEx

QuickBMS param script

May 17th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.53 KB | None | 0 0
  1. # Script to extract csv table from .param and .paramdef files
  2. # Open the .param file with this and make sure the .paramdef is in the same folder
  3. #
  4. # Keep in mind that due to QuickBMS' nature, float values will be truncated
  5. # and essentially useless in the finished table.
  6. #
  7. # Written by HenryEx
  8. #
  9. # script for QuickBMS http://quickbms.aluigi.org
  10.  
  11. #setup a virtual memory file
  12. math TMP = CHUNKS
  13. math TMP *= 0x8000
  14. log MEMORY_FILE 0 0
  15. putvarchr MEMORY_FILE TMP 0 # improves the speed with pre-allocation
  16. log MEMORY_FILE 0 0 # reset the position and size of the file
  17. set MBEGIN string "\""
  18. put MBEGIN string MEMORY_FILE
  19.  
  20. #make sure the right file was opened
  21. get PARAMEXT extension
  22. if PARAMEXT != "param"
  23. print "This is not a .param file! Exiting..."
  24. CleanExit
  25. endif
  26.  
  27. # open the .param file again
  28. get PARAMFNAME filename
  29. open FDSE PARAMFNAME 0
  30.  
  31. # get the appropriate .paramdef file
  32. set PARAMDEF string "paramdef"
  33. get PARAMNAME basename
  34. if PARAMNAME & "_PC"
  35. string PARAMNAME > "_PC"
  36. string PARAMNAME += PARAMDEF
  37. open FDSE PARAMNAME 1
  38. elif PARAMNAME & "_Pc"
  39. string PARAMNAME > "_Pc"
  40. string PARAMNAME += PARAMDEF
  41. open FDSE PARAMNAME 1
  42. elif PARAMNAME & "_Npc"
  43. string PARAMNAME > "_Npc"
  44. string PARAMNAME += PARAMDEF
  45. open FDSE PARAMNAME 1
  46. else
  47. open FDDE PARAMDEF 1
  48. endif
  49.  
  50. #read .param header
  51. get FILESIZE0 long 0
  52. get OFFSET0 short 0 # offset of first (data) entry
  53. get DUMMY_A0 short 0
  54. get DUMMY_B0 short 0
  55. get ENTRIES0 short 0 # how many entries
  56. getdstring FILENAME0 0x20 0
  57. idstring 0 "\x00\x02\x00\x00"
  58. # value here SHOULD always be 00 02 00 00 in .param files
  59.  
  60. #read .paramdef header
  61. get FILESIZE1 long 1
  62. get OFFSET1 short 1 # offset of first entry
  63. get DUMMY_A1 short 1
  64. get ENTRIES1 short 1 # how many entries
  65. get ENTRYSIZE1 short 1 # bytesize of 1 entry
  66. getdstring FILENAME1 0x20 1
  67. idstring 1 "\x00\x00\x68\x00"
  68. # value here SHOULD always be 00 00 68 00 in .paramdef files
  69.  
  70. # set later file name and misc. standard strings / variables
  71. get FILENAME basename 0
  72. string FILENAME += ".csv"
  73. set CSV string "\";\"" # set the csv string to ";"
  74. set LINEBREAK binary "\"\x0D\x0A\"" # end with ", linebreak, start with "
  75. set OFFSET_NAME long 140
  76. set OFFSET_JNAME long 0
  77. set OFFSET_JDESC long 104
  78. set OFFSET_TYPE long 64
  79.  
  80.  
  81. # -------------------------
  82. # Parse the .paramdef file
  83.  
  84. for i = 0 < 4 # write four header lines
  85.  
  86. if i == 0 # first line, preface param names with ID# and jap. desc. columns
  87. put "ID" string MEMORY_FILE
  88. put CSV string MEMORY_FILE
  89. put "Description" string MEMORY_FILE
  90. else # for the other 3 lines, preface with two empty columns
  91. put CSV string MEMORY_FILE
  92. endif
  93.  
  94. // Depending on which header line we write (i), we'll read & write a different field
  95. // 0 English name; 1 data type; 2 japanese name; 3 japanese description
  96. // Calculate the offset to the first and set string length per case
  97. set PDOFFSET1 long OFFSET1
  98. if i == 0
  99. math PDOFFSET1 += OFFSET_NAME
  100. set STRLEN long 32
  101. elif i == 1
  102. math PDOFFSET1 += OFFSET_TYPE
  103. set STRLEN long 8
  104. elif i == 2
  105. math PDOFFSET1 += OFFSET_JNAME
  106. set STRLEN long 64
  107. elif i == 3
  108. math PDOFFSET1 += OFFSET_JDESC
  109. set STRLEN long 0 # pointer, not a fixed string
  110. endif
  111.  
  112. for j = 0 < ENTRIES1
  113.  
  114. goto PDOFFSET1 1 #jump to current entry and field offset
  115.  
  116. if i == 3 # this is a pointer, so we need to get the string first
  117. get OFFSET_C1 long 1
  118. set FIELD1 string "[blank]"
  119. if OFFSET_C1 > 0
  120. goto OFFSET_C1 1
  121. get FIELD1 string 1
  122. endif
  123. else # in the other cases, just get the fixed length string
  124. getdstring FIELD1 STRLEN 1
  125. endif
  126.  
  127. put CSV string MEMORY_FILE # add end & separator to previous column
  128. put FIELD1 string MEMORY_FILE # write current field
  129. math PDOFFSET1 += ENTRYSIZE1 # set offset for next entry
  130.  
  131. next j
  132.  
  133. put LINEBREAK string MEMORY_FILE # if line is finished, write a linebreak
  134.  
  135. next i
  136.  
  137.  
  138. # -------------------------
  139. # Parse the .param file
  140.  
  141. set TOCPOS long 48
  142.  
  143. for i = 0 < ENTRIES0 # this loop writes a whole line
  144.  
  145. goto TOCPOS 0 # the first loop, we should already be here
  146. get ID long 0 # entry ID
  147. get OFFSET_D long 0 # pointer to current entry data
  148. get OFFSET_S long 0 # pointer to current entry comment string
  149. savepos TOCPOS 0 # save current position for next loop
  150.  
  151. set COMMENT0 string "[blank]"
  152. if OFFSET_S > 0
  153. goto OFFSET_S 0
  154. get COMMENT0 string 0
  155. endif
  156.  
  157. set BOOLS byte 0 # bit counter
  158. set ID string ID # convert ID number to string
  159. put ID string MEMORY_FILE # add the ID number as string (1st column)
  160. put CSV string MEMORY_FILE
  161. put COMMENT0 string MEMORY_FILE # add the japanese comment (2nd column)
  162. set CUR_PARAM long OFFSET_D # prepare parameter-to-be-read
  163.  
  164. for j = 0 < ENTRIES1 # this loop writes each defined parameter
  165. // Calculate current paramdef offset
  166. set PDOFFSET0 long ENTRYSIZE1
  167. math PDOFFSET0 *= j
  168. math PDOFFSET0 += OFFSET1
  169.  
  170. math PDOFFSET0 += OFFSET_TYPE # we now got the offset for the current param type
  171. goto PDOFFSET0 1
  172. getdstring CUR_TYPE 8 1
  173. math PDOFFSET0 += 76 # now the offset to the current param name
  174. goto PDOFFSET0 1
  175. getdstring CUR_NAME 32 1
  176.  
  177. // Get the currently read parameter's length
  178. if CUR_TYPE & "32" # f32, s32, u32 etc
  179. set CUR_LEN byte 4
  180. elif CUR_TYPE & "16" # s16, u16
  181. set CUR_LEN byte 2
  182. elif CUR_TYPE & "8" # s8, u8
  183. set CUR_LEN byte 1
  184. else # we don't know the data type? shouldn't happen, abort!
  185. print "Encountered unexpected param type for parameter %CUR_NAME%! \nParameter type %CUR_TYPE% is not defined. \nExiting..."
  186. CleanExit
  187. endif
  188.  
  189. // string CUR_TYPE -= -1
  190. goto CUR_PARAM 0
  191.  
  192. if CUR_NAME & ":" # check the name if it's a bit flag
  193. string CUR_NAME | ":" # cut string to value behind colon
  194. set BLENGTH byte CUR_NAME
  195. math BOOLS += BLENGTH
  196. get BFLAG byte 0
  197. string FIELD0 b BFLAG # change to hex display (i hope)
  198. elif CUR_LEN == 1
  199. if CUR_TYPE & "s"
  200. get FIELD0 signed_byte 0
  201. else
  202. get FIELD0 byte 0
  203. endif
  204. elif CUR_LEN == 2
  205. if CUR_TYPE & "s"
  206. get FIELD0 signed_short 0
  207. else
  208. get FIELD0 short 0
  209. endif
  210. elif CUR_LEN == 4
  211. if CUR_TYPE & "f" # float value
  212. get FIELD0 float 0
  213. elif CUR_TYPE & "s"
  214. get FIELD0 signed_long 0
  215. else
  216. get FIELD0 long 0
  217. endif
  218. endif
  219.  
  220. set FIELD0 string FIELD0
  221. put CSV string MEMORY_FILE # add end & separator to previous column
  222. put FIELD0 string MEMORY_FILE # write current field
  223.  
  224. if BOOLS > 8 # we shouldn't go over one byte in bits
  225. print "Bitflag array error! Name of current bitflag array at offset %PDOFFSET0%. \nExiting..."
  226. CleanExit
  227. elif BOOLS == 8 # if one byte is full, reset counter and inc. offset
  228. set BOOLS byte 0
  229. math CUR_PARAM += 1
  230. elif BOOLS != 0 # if we just processed at least one bit, we started a bit array
  231. set CUR_LEN byte 0 # do nothing, basically
  232. else # in all other cases (not a bit array)
  233. math CUR_PARAM += CUR_LEN # adjust offset by length of this parameter
  234. endif
  235.  
  236. next j
  237.  
  238. put LINEBREAK string MEMORY_FILE # if line is finished, write a linebreak
  239.  
  240. next i
  241.  
  242. // write the finished table to the disk
  243. get MLENGTH asize MEMORY_FILE
  244. log FILENAME 0 MLENGTH MEMORY_FILE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement