# 1bsr pgsr (Plants vs Zombies 2) (script 0.2.2) # experimental # script for QuickBMS http://quickbms.aluigi.org math DUMP_PGSR_AS_IS = 0 comtype zlib_noerror # automatically decompresses the data, the bnk files are compressed getdstring SIGN 4 goto 0 if SIGN == "pgsr" set NAME string "" callfunction pgsr_extract cleanexit endif set SMF_SIGN binary "\xd4\xfe\xad\xde" if SIGN == SMF_SIGN goto 4 get SIZE long savepos OFFSET get ZSIZE asize math ZSIZE - OFFSET # this solution does NOT allow reimport #clog TEMPORARY_FILE OFFSET ZSIZE SIZE #open "." TEMPORARY_FILE get NAME basename clog NAME OFFSET ZSIZE SIZE open "." NAME #cleanexit endif idstring "1bsr" goto 0x28 get FILES long get OFFSET long goto OFFSET for i = 0 < FILES getdstring NAME 0x80 get OFFSET long get SIZE long getdstring DUMMY 0x44 if DUMP_PGSR_AS_IS != 0 #log NAME OFFSET SIZE clog NAME OFFSET SIZE SIZE else callfunction pgsr_extract endif next i startfunction pgsr_extract set PGSR_NAME string NAME savepos BACKUP_OFFSET goto OFFSET savepos PGSR_OFFSET math PGSR_SIZE = SIZE idstring "pgsr" get VER long get ZERO long get ZERO long get TYPE long get PGSR_BASE long math OFFSET = 0 math ZSIZE = 0 math SIZE = 0 for x = 0 < 2 get TMP_OFFSET long get TMP_ZSIZE long get TMP_SIZE long get TMP_ZERO long if TMP_SIZE != 0 math OFFSET = TMP_OFFSET math ZSIZE = TMP_ZSIZE math SIZE = TMP_SIZE endif next x math OFFSET + PGSR_OFFSET getdstring DUMMY 0x10 get INFO_SIZE long get INFO_OFFSET long math INFO_OFFSET + PGSR_OFFSET xmath INFO_LIMIT "INFO_OFFSET + INFO_SIZE" goto INFO_OFFSET if TYPE == 3 # single file callfunction GET_NAME 1 string FNAME p "%s/%s" PGSR_NAME NAME if ZSIZE == SIZE #log FNAME OFFSET SIZE clog FNAME OFFSET SIZE SIZE else clog FNAME OFFSET ZSIZE SIZE endif elif TYPE <= 1 # multiple files math X_ZSIZE = ZSIZE math X_SIZE = SIZE set FOLDER string "" math LAST_OFFSET = -1 for savepos TMP if TMP >= INFO_LIMIT break endif callfunction GET_NAME 1 get DUNNO_VALUE long get OFFSET long get SIZE long if DUNNO_VALUE != 0 get DUMMY long get DUMMY long get DUMMY long get DUMMY long get DUMMY long # files located in compressed pgsr filesystems are not supported # they are dumped as-is, for 2 reasons: # - in this way you can reimport the file in the archive # - I should use a memory file which makes things more complex math OFFSET = 0 math SIZE = 0 endif if FOLDER == "" set FOLDER filepath NAME set NAME filename NAME endif if OFFSET != LAST_OFFSET math LAST_OFFSET = OFFSET math OFFSET + PGSR_OFFSET math OFFSET + PGSR_BASE string FNAME p "%s/%s/%s" PGSR_NAME FOLDER NAME math ZSIZE = SIZE if SIZE == 0 math ZSIZE = X_ZSIZE math SIZE = X_SIZE endif if ZSIZE == SIZE #log FNAME OFFSET SIZE clog FNAME OFFSET SIZE SIZE else clog FNAME OFFSET ZSIZE SIZE endif endif next else #log PGSR_NAME PGSR_OFFSET PGSR_SIZE clog PGSR_NAME PGSR_OFFSET PGSR_SIZE PGSR_SIZE endif goto BACKUP_OFFSET endfunction startfunction GET_NAME set NAME string "" math x = 0 do get TMP_BYTE long math TMP_BYTE & 0xff putvarchr NAME x TMP_BYTE math x + 1 while TMP_BYTE != 0 endfunction