Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Script to extract csv table from .param and .paramdef files
- # Open the .param file with this and make sure the .paramdef is in the same folder
- #
- # Keep in mind that due to QuickBMS' nature, float values will be truncated
- # and essentially useless in the finished table.
- #
- # Written by HenryEx
- #
- # script for QuickBMS http://quickbms.aluigi.org
- #setup a virtual memory file
- math TMP = CHUNKS
- math TMP *= 0x8000
- log MEMORY_FILE 0 0
- putvarchr MEMORY_FILE TMP 0 # improves the speed with pre-allocation
- log MEMORY_FILE 0 0 # reset the position and size of the file
- set MBEGIN string "\""
- put MBEGIN string MEMORY_FILE
- #make sure the right file was opened
- get PARAMEXT extension
- if PARAMEXT != "param"
- print "This is not a .param file! Exiting..."
- CleanExit
- endif
- # open the .param file again
- get PARAMFNAME filename
- open FDSE PARAMFNAME 0
- # get the appropriate .paramdef file
- set PARAMDEF string "paramdef"
- get PARAMNAME basename
- if PARAMNAME & "_PC"
- string PARAMNAME > "_PC"
- string PARAMNAME += PARAMDEF
- open FDSE PARAMNAME 1
- elif PARAMNAME & "_Pc"
- string PARAMNAME > "_Pc"
- string PARAMNAME += PARAMDEF
- open FDSE PARAMNAME 1
- elif PARAMNAME & "_Npc"
- string PARAMNAME > "_Npc"
- string PARAMNAME += PARAMDEF
- open FDSE PARAMNAME 1
- else
- open FDDE PARAMDEF 1
- endif
- #read .param header
- get FILESIZE0 long 0
- get OFFSET0 short 0 # offset of first (data) entry
- get DUMMY_A0 short 0
- get DUMMY_B0 short 0
- get ENTRIES0 short 0 # how many entries
- getdstring FILENAME0 0x20 0
- idstring 0 "\x00\x02\x00\x00"
- # value here SHOULD always be 00 02 00 00 in .param files
- #read .paramdef header
- get FILESIZE1 long 1
- get OFFSET1 short 1 # offset of first entry
- get DUMMY_A1 short 1
- get ENTRIES1 short 1 # how many entries
- get ENTRYSIZE1 short 1 # bytesize of 1 entry
- getdstring FILENAME1 0x20 1
- idstring 1 "\x00\x00\x68\x00"
- # value here SHOULD always be 00 00 68 00 in .paramdef files
- # set later file name and misc. standard strings / variables
- get FILENAME basename 0
- string FILENAME += ".csv"
- set CSV string "\";\"" # set the csv string to ";"
- set LINEBREAK binary "\"\x0D\x0A\"" # end with ", linebreak, start with "
- set OFFSET_NAME long 140
- set OFFSET_JNAME long 0
- set OFFSET_JDESC long 104
- set OFFSET_TYPE long 64
- # -------------------------
- # Parse the .paramdef file
- for i = 0 < 4 # write four header lines
- if i == 0 # first line, preface param names with ID# and jap. desc. columns
- put "ID" string MEMORY_FILE
- put CSV string MEMORY_FILE
- put "Description" string MEMORY_FILE
- else # for the other 3 lines, preface with two empty columns
- put CSV string MEMORY_FILE
- endif
- // Depending on which header line we write (i), we'll read & write a different field
- // 0 English name; 1 data type; 2 japanese name; 3 japanese description
- // Calculate the offset to the first and set string length per case
- set PDOFFSET1 long OFFSET1
- if i == 0
- math PDOFFSET1 += OFFSET_NAME
- set STRLEN long 32
- elif i == 1
- math PDOFFSET1 += OFFSET_TYPE
- set STRLEN long 8
- elif i == 2
- math PDOFFSET1 += OFFSET_JNAME
- set STRLEN long 64
- elif i == 3
- math PDOFFSET1 += OFFSET_JDESC
- set STRLEN long 0 # pointer, not a fixed string
- endif
- for j = 0 < ENTRIES1
- goto PDOFFSET1 1 #jump to current entry and field offset
- if i == 3 # this is a pointer, so we need to get the string first
- get OFFSET_C1 long 1
- set FIELD1 string "[blank]"
- if OFFSET_C1 > 0
- goto OFFSET_C1 1
- get FIELD1 string 1
- endif
- else # in the other cases, just get the fixed length string
- getdstring FIELD1 STRLEN 1
- endif
- put CSV string MEMORY_FILE # add end & separator to previous column
- put FIELD1 string MEMORY_FILE # write current field
- math PDOFFSET1 += ENTRYSIZE1 # set offset for next entry
- next j
- put LINEBREAK string MEMORY_FILE # if line is finished, write a linebreak
- next i
- # -------------------------
- # Parse the .param file
- set TOCPOS long 48
- for i = 0 < ENTRIES0 # this loop writes a whole line
- goto TOCPOS 0 # the first loop, we should already be here
- get ID long 0 # entry ID
- get OFFSET_D long 0 # pointer to current entry data
- get OFFSET_S long 0 # pointer to current entry comment string
- savepos TOCPOS 0 # save current position for next loop
- set COMMENT0 string "[blank]"
- if OFFSET_S > 0
- goto OFFSET_S 0
- get COMMENT0 string 0
- endif
- set BOOLS byte 0 # bit counter
- set ID string ID # convert ID number to string
- put ID string MEMORY_FILE # add the ID number as string (1st column)
- put CSV string MEMORY_FILE
- put COMMENT0 string MEMORY_FILE # add the japanese comment (2nd column)
- set CUR_PARAM long OFFSET_D # prepare parameter-to-be-read
- for j = 0 < ENTRIES1 # this loop writes each defined parameter
- // Calculate current paramdef offset
- set PDOFFSET0 long ENTRYSIZE1
- math PDOFFSET0 *= j
- math PDOFFSET0 += OFFSET1
- math PDOFFSET0 += OFFSET_TYPE # we now got the offset for the current param type
- goto PDOFFSET0 1
- getdstring CUR_TYPE 8 1
- math PDOFFSET0 += 76 # now the offset to the current param name
- goto PDOFFSET0 1
- getdstring CUR_NAME 32 1
- // Get the currently read parameter's length
- if CUR_TYPE & "32" # f32, s32, u32 etc
- set CUR_LEN byte 4
- elif CUR_TYPE & "16" # s16, u16
- set CUR_LEN byte 2
- elif CUR_TYPE & "8" # s8, u8
- set CUR_LEN byte 1
- else # we don't know the data type? shouldn't happen, abort!
- print "Encountered unexpected param type for parameter %CUR_NAME%! \nParameter type %CUR_TYPE% is not defined. \nExiting..."
- CleanExit
- endif
- // string CUR_TYPE -= -1
- goto CUR_PARAM 0
- if CUR_NAME & ":" # check the name if it's a bit flag
- string CUR_NAME | ":" # cut string to value behind colon
- set BLENGTH byte CUR_NAME
- math BOOLS += BLENGTH
- get BFLAG byte 0
- string FIELD0 b BFLAG # change to hex display (i hope)
- elif CUR_LEN == 1
- if CUR_TYPE & "s"
- get FIELD0 signed_byte 0
- else
- get FIELD0 byte 0
- endif
- elif CUR_LEN == 2
- if CUR_TYPE & "s"
- get FIELD0 signed_short 0
- else
- get FIELD0 short 0
- endif
- elif CUR_LEN == 4
- if CUR_TYPE & "f" # float value
- get FIELD0 float 0
- elif CUR_TYPE & "s"
- get FIELD0 signed_long 0
- else
- get FIELD0 long 0
- endif
- endif
- set FIELD0 string FIELD0
- put CSV string MEMORY_FILE # add end & separator to previous column
- put FIELD0 string MEMORY_FILE # write current field
- if BOOLS > 8 # we shouldn't go over one byte in bits
- print "Bitflag array error! Name of current bitflag array at offset %PDOFFSET0%. \nExiting..."
- CleanExit
- elif BOOLS == 8 # if one byte is full, reset counter and inc. offset
- set BOOLS byte 0
- math CUR_PARAM += 1
- elif BOOLS != 0 # if we just processed at least one bit, we started a bit array
- set CUR_LEN byte 0 # do nothing, basically
- else # in all other cases (not a bit array)
- math CUR_PARAM += CUR_LEN # adjust offset by length of this parameter
- endif
- next j
- put LINEBREAK string MEMORY_FILE # if line is finished, write a linebreak
- next i
- // write the finished table to the disk
- get MLENGTH asize MEMORY_FILE
- log FILENAME 0 MLENGTH MEMORY_FILE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement