HenryEx

RF4 Presents parser for QuickBMS

Sep 12th, 2020 (edited)
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. # Rune Factory 4 / Present files
  2. #
  3. # Written by HenryEx
  4. #
  5. # script for QuickBMS http://quickbms.aluigi.org
  6.  
  7. idstring "NLCL"
  8. get FLAGS long
  9. get HDUMMY1 long
  10. get HDUMMY2 long
  11.  
  12. # check flags so we don't operate on silly files
  13. if FLAGS != 0x 20130228
  14. print "[!] Unexpected flags!"
  15. CleanExit
  16. endif
  17.  
  18. open FDSE "rf3TxtItem_split2_1.eng" 1
  19. idstring 1 "TEXT"
  20. get NUM_NAMES long 1
  21.  
  22. #setup a virtual memory file
  23. math TMP = 1
  24. math TMP *= 0x8000
  25. log MEMORY_FILE 0 0
  26. putvarchr MEMORY_FILE TMP 0 # improves the speed with pre-allocation
  27. log MEMORY_FILE 0 0 # reset the position and size of the file
  28. set MBEGIN string "\""
  29. putct MBEGIN string -1 MEMORY_FILE
  30.  
  31.  
  32. get FILENAME basename
  33. string FILENAME += ".csv"
  34. get FILESIZE asize
  35. set CSV string "\";\"" # set the csv string to ";"
  36. set LINEBREAK binary "\"\x0D\x0A\"" # end with ", linebreak, start with "
  37.  
  38. get BLOCKNUM long
  39. get TOC_P long
  40.  
  41. # Set up CSV header
  42. putct "Set" string -1 MEMORY_FILE # data block, relates to like/dislike categories
  43. putct CSV string -1 MEMORY_FILE
  44. putct "ID" string -1 MEMORY_FILE # Item / Category ID
  45. putct CSV string -1 MEMORY_FILE
  46. putct "Name" string -1 MEMORY_FILE # Name for items, or "Category" for categories
  47. putct CSV string -1 MEMORY_FILE
  48. putct "Effect" string -1 MEMORY_FILE # effect in FP
  49. putct LINEBREAK string -1 MEMORY_FILE
  50.  
  51.  
  52. if BLOCKNUM > 1
  53.  
  54. for i = 1 < BLOCKNUM
  55.  
  56. xmath TOSPOS "TOC_P + (0x10 * i) + 4"
  57. xmath NEXT "i + 1"
  58. goto TOSPOS
  59. get OFF_BLOCK long
  60. if NEXT >= BLOCKNUM
  61. xmath LEN_BLOCK "TOC_P - OFF_BLOCK"
  62. else
  63. xmath TOSPOS "TOC_P + (0x10 * i) + 20"
  64. goto TOSPOS
  65. get NEXT_BLOCK long
  66. xmath LEN_BLOCK "NEXT_BLOCK - OFF_BLOCK"
  67. endif
  68.  
  69. goto OFF_BLOCK
  70. get NUM_ENTRY long
  71. xmath LEN_ENTRY "(LEN_BLOCK - 4) / NUM_ENTRY"
  72.  
  73. if LEN_ENTRY != 4
  74. print "[!] Unexpected entry length %LEN_ENTRY%! \n Data Block: %i%, Offset %OFF_BLOCK%, Block Length %LEN_BLOCK%, Entries %NUM_ENTRY%"
  75. CleanExit
  76. endif
  77.  
  78. for j = 0 < NUM_ENTRY
  79. get ITEMID short
  80. get IEFFECT signed_short
  81. xmath ISCATI "ITEMID & 0x8000"
  82. if ISCATI > 0
  83. xmath ISCATG "ITEMID & 0x0100"
  84. math ITEMID & 0xFF
  85. else
  86. math ISCATG = 0
  87. math ITEMID & 0x0FFF
  88. endif
  89.  
  90. if ITEMID > NUM_NAMES
  91. print "[!] Item ID %ITEMID% out of bounds. Exiting..."
  92. CleanExit
  93. endif
  94.  
  95. xmath PTR_NAME "(ITEMID * 8) + 8"
  96. goto PTR_NAME 1
  97. get LEN_NAME long 1
  98. get POS_NAME long 1
  99. goto POS_NAME 1
  100. getdstring INAME LEN_NAME 1
  101.  
  102. if ISCATI > 0
  103. string INAME = "[Item Type]"
  104. endif
  105.  
  106. if ISCATG > 0
  107. math ITEMID + 1
  108. string INAME = "[Category]"
  109. endif
  110.  
  111. putct i string -1 MEMORY_FILE
  112. putct CSV string -1 MEMORY_FILE
  113. putct ITEMID string -1 MEMORY_FILE
  114. putct CSV string -1 MEMORY_FILE
  115. putct INAME string -1 MEMORY_FILE
  116. putct CSV string -1 MEMORY_FILE
  117. putct IEFFECT string -1 MEMORY_FILE
  118. putct LINEBREAK string -1 MEMORY_FILE
  119. next j
  120.  
  121. putct LINEBREAK string -1 MEMORY_FILE
  122. next i
  123.  
  124. else
  125. print "[!] Script is not meant for one block files!"
  126. CleanExit
  127. endif
  128.  
  129. // write the finished table to the disk
  130. get MLENGTH asize MEMORY_FILE
  131. math MLENGTH - 1 # get rid of last trailing double quote
  132. log FILENAME 0 MLENGTH MEMORY_FILE
  133.  
  134. print "[---] SUCCESS! [---]"
  135.  
Add Comment
Please, Sign In to add comment