Level-5 Dark Cloud - .TM2 Extracting from .IMG [COMPLETED]

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
Dayuppy
Posts: 5
Joined: Tue May 12, 2020 8:07 am

Level-5 Dark Cloud - .TM2 Extracting from .IMG [COMPLETED]

Post by Dayuppy »

EDIT: I managed to get it to extract more files but the size must still be wrong. It fails to extract in some cases and I'm not sure the cause
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!



i01h07_-_drans.zip


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


i01h06e.zip
- 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.
Last edited by Dayuppy on Fri May 15, 2020 5:54 pm, edited 3 times in total.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Level-5 Dark Cloud - .TM2 Extracting from .IMG [PARTIALLY WORKING]

Post by aluigi »

Never use a "scanner" solution when you can extract the files by analyzing the format of the archive.

http://aluigi.org/bms/level5_img.bms
Dayuppy
Posts: 5
Joined: Tue May 12, 2020 8:07 am

Re: Level-5 Dark Cloud - .TM2 Extracting from .IMG [PARTIALLY WORKING]

Post by Dayuppy »

Thank you for the quick reply aluigi, your script seems to be working great with .img files of the type that I've posted however I just discovered that some .img files are slightly different. I've found a few that start with "IM2\0" now. I'm not sure how to add an OR operator in QuicKBMS if it exists to accept either idstring "IM2\0" or idstring "IMG\0"

Having the extracted files named properly is also amazing. Do you know of a way to append .TM2 to the end for the file extension?

Thanks in advance
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Level-5 Dark Cloud - .TM2 Extracting from .IMG [PARTIALLY WORKING]

Post by aluigi »

Script updated :)
Dayuppy
Posts: 5
Joined: Tue May 12, 2020 8:07 am

Re: Level-5 Dark Cloud - .TM2 Extracting from .IMG [PARTIALLY WORKING]

Post by Dayuppy »

Thanks again aluigi :)

The script managed to extract all 1,337 .img files successfully except for a single img file. I call that a success :)
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Level-5 Dark Cloud - .TM2 Extracting from .IMG [PARTIALLY WORKING]

Post by aluigi »

It's an invalid number of files specified in that archive.
I updated the script for recognizing these invalid archives and fixing the number of files.