# Xanadu Next
# script for QuickBMS http://quickbms.aluigi.org
#
# modified script by 누구야

get BASENAME basename
get EXTENSION extension
get FILESIZE asize
if EXTENSION != DIR
    open FDDE dir 0
endif
open FDDE arc 1

xmath FILES_OFFSET "FILESIZE - 4"
goto FILES_OFFSET
get FILES long
#xmath FILES "FILESIZE / 108"

open FDDE dirLIST 2
get LIST_SIZE asize 2
xmath LIST_FILES "LIST_SIZE / 32"

log MEMORY_FILE 0 0
log MEMORY_FILE2 0 0
log MEMORY_FILE3 0 0

goto 0
math OFFSET = 0
for i = 0 < FILES
    codepage 932

    getdstring NAME 100
    get SIZE long
    get COMP_TYPE long

    log MEMORY_FILE3 OFFSET SIZE 1

    goto 0 2
    for j = 0 < LIST_FILES
      getdstring INSERT_NAME 32 2
      if NAME == INSERT_NAME
        math j = LIST_FILES

        string LOAD_NAME = BASENAME
        string LOAD_NAME += \
        string LOAD_NAME += INSERT_NAME

        open FDSE LOAD_NAME 3
        get INSERT_SIZE asize 3

        if COMP_TYPE == 0
          log MEMORY_FILE3 0 0
          log MEMORY_FILE3 0 INSERT_SIZE 3
        elif COMP_TYPE == 1
          log MEMORY_FILE3 0 0
          comtype falcom_compress
          clog MEMORY_FILE3 0 INSERT_SIZE INSERT_SIZE 3
        endif

        get MEMORY3_SIZE asize MEMORY_FILE3
        print "%INSERT_NAME%	%MEMORY3_SIZE|x%"
      endif
    next j

    get MEMORY3_SIZE asize MEMORY_FILE3

    putdstring NAME 100 MEMORY_FILE
    put MEMORY3_SIZE long MEMORY_FILE
    put COMP_TYPE long MEMORY_FILE

    append
    log MEMORY_FILE2 0 MEMORY3_SIZE MEMORY_FILE3
    append

    math OFFSET += SIZE

next i


put FILES long MEMORY_FILE
get MEMORY1_SIZE asize MEMORY_FILE

string EXT_NAME0 = BASENAME
string EXT_NAME0 += ".dir"

log EXT_NAME0 0 MEMORY1_SIZE MEMORY_FILE


get MEMORY2_SIZE asize MEMORY_FILE2

string EXT_NAME1 = BASENAME
string EXT_NAME1 += ".arc"

log EXT_NAME1 0 MEMORY2_SIZE MEMORY_FILE2

