Programming related discussions related to game research
Garo
Posts: 20 Joined: Wed Nov 18, 2020 5:54 pm
Post
by Garo » Mon Apr 12, 2021 11:12 am
I have an archive where data is stored like nodes, for each compressed file in this archive, there is a node-header, saying what kind of data it is. I want to log these compressed files' filename depending on the node type. So a file with the type of "TEX0", would have the extension ".gtx" and so on.
Here's the script I made for the archive.
Code: Select all
idstring "ANP 151 " endian big get FILES long get NAMESZ long for i = 0 < FILES getdstring NODE 4 goto 12 SEEK_CUR # this is where you do the node name parsing getdstring NAME NAMESZ get OFFSET longlong get SIZE longlong log NAME OFFSET SIZE next i
Heres the archive too.
I don't know why I can't attach an archive, but I renamed it from ".anp" to ".txt", so I could upload it.
aluigi
Site Admin
Posts: 12984 Joined: Wed Jul 30, 2014 9:32 pm
Post
by aluigi » Mon Apr 12, 2021 10:30 pm
Unfortunately there is no "switch/case"-like command in quickbms therefore the long sequence of "if/elif/else/endif" is the only option.
There are alternatives like storing the magic value and the relative in two arrays... but the script will look quite messy.
In my opinion the bestt alternative is storing the long list of "magic:extension;" in a MEMORY_FILE and searching them:
Code: Select all
set MEMORY_FILE string "TEX0:gxt;TEXT:txt;BLAH:blah;" # read the magic getdstring MAGIC 4 # search the magic string MAGIC + ":" goto 0 MEMORY_FILE findloc POS binary MAGIC MEMORY_FILE "" # set the extension if POS == "" set EXT string "dat" else math POS + 5 goto POS MEMORY_FILE getct EXT string ';' MEMORY_FILE endif print "Extension: %EXT%"