EDIT2: I made a second variant of this script based on what I learned making the MDS extractor. This variant appears to be working correctly now.
EDIT3: aluigi created the final working script. Thank you!
I've been trying to create my very first BMS script but it fails to extract all the TM2 images in a file. I've attached an example archive of a file containing TM2 images.
First Variant
Code: Select all
for FILES = 0
FindLoc OFFSET string "TIM2"
goto OFFSET
idstring "TIM2"
get VER BYTE
get format BYTE
get numImages SHORT
get null LONGLONG
get total_size LONG
get clut_size LONG
get image_size LONG
set size LONG = get headerSize SHORT
get clutColors SHORT
get pictFormat BYTE
get mipMapTextures BYTE
get clutType BYTE
get imageType BYTE
get width SHORT
get height SHORT
get gsTex0 LONGLONG
get gsTex1 LONGLONG
get gsReg LONG
get gsTexClut LONG
math image_size += 1088 #added this to make sure the image is the right size, I don't know where this value comes from but it seems to work.
if null == 0 #assume we're in the right place if 8 bytes of data are all zeros
for i = 0 < numImages
log "" OFFSET image_size
FindLoc OFFSET string "TIM2"
next i
endif
next FILES
- EDIT: Seems to unpack correctly now after adding 1088 size number
Second Variant - Appears to be working correctly
Code: Select all
for FILES = 0
FindLoc OFFSET1 string "TIM2"
goto OFFSET1
idstring "TIM2"
get VER BYTE
get format BYTE
get numImages SHORT
get null LONGLONG
print "offset1: %offset1%"
FindLoc OFFSET2 string "TIM2"
goto OFFSET2
idstring "TIM2"
print "offset2: %offset2%"
set SIZE LONG OFFSET2
math SIZE -= OFFSET1 #Subtract OFFSET1 from OFFSET 2
if null == 0
Log "" OFFSET1 SIZE
endif
math OFFSET1 += SIZE
goto OFFSET1
print "SIZE %SIZE%"
next FILES
TIM2 struct information: https://tcrf.net/User:Kojin/TIM2_Information#Header
I have a feeling that I'm offsetting too far past the end of the each image as the filesizes for all my extracted images are exactly 1MB rather than 257kb for example which is what I get when I manually pull the image out using a hex editor.
The if null == 0 was added because the script was getting stuck when coming across an "=TIM2TIIITUI8MI" in the middle of another TM2 texture.
These images can be opened with XnView, Rainbow, Noesis, or Photoshop with a plugin.
Thanks in advance.