Bms script to unpack .tpk files from NFS games (PS2)

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
Alpha1001
Posts: 37
Joined: Tue Nov 06, 2018 10:11 am

Bms script to unpack .tpk files from NFS games (PS2)

Post by Alpha1001 »

Hi guys, I would like to know if someone can make for me a bms script to dump the files of this archive https://drive.google.com/file/d/1YgENZo ... sp=sharing
This is a tpk archive from NFS Carbon and I'm trying to make mods to this game, but first I need to dump the files inside many .tpk archives.
The TOC of this tpk begins at 0xD0 and the first file in the 0x3C80, but in the TOC is 0xC0391F00, what is a confused value and I don't have idea how to dump the files using the infos of the TOC.
Someone know how to get the proper offset from the TOC, e.g, how to get 0x3C80 from 0xC0391F00?
The first file is a compressed HUFF file
rabatini
Posts: 179
Joined: Tue Jan 18, 2022 12:21 am

Re: Bms script to unpack .tpk files from NFS games (PS2)

Post by rabatini »

Have you already tried this script?
http://aluigi.org/bms/nfsu_bun.bms
Alpha1001
Posts: 37
Joined: Tue Nov 06, 2018 10:11 am

Re: Bms script to unpack .tpk files from NFS games (PS2)

Post by Alpha1001 »

Yeah, but this bms script don't work with Tpk files, the nfsu_bun.bms works only with the ZZDATA archives, HUFF, JDLZ and COMP, the Tpk archives are different, unfortunatelly.
DKDave
Posts: 136
Joined: Mon Nov 23, 2020 6:01 pm

Re: Bms script to unpack .tpk files from NFS games (PS2)

Post by DKDave »

From looking at the sample, the "proper" TOC actually begins at 0xf64, with 0x18 bytes per entry. Each entry seems to start with the same value as in the first TOC at 0xd4.

In the TOC, it looks like you have something like: unknown value, data offset, compressed size, uncompressed size, then a couple of other values. Note that the files are not in any particular order either, so the first one in the TOC is offset 0x5a700.

There are two different compressed types - "HUFF" and "JDLZ". I only looked at the HUFF blocks, but I couldn't find a QuickBMS compression type that worked, although I'm not sure what the final decompressed file is supposed to look like ...
Alpha1001
Posts: 37
Joined: Tue Nov 06, 2018 10:11 am

Re: Bms script to unpack .tpk files from NFS games (PS2)

Post by Alpha1001 »

Hi, thanks, I think that I can dump some files now, really the files are not any particular order. Is a little strange some values, but the offset values and size values it seems ok.
Alpha1001
Posts: 37
Joined: Tue Nov 06, 2018 10:11 am

Re: Bms script to unpack .tpk files from NFS games (PS2)

Post by Alpha1001 »

Hi DKDAVE, thank you very much by your explanation about the format. I've managed to create now a tool to dump and repack the files from Tpk archive, thanks your explanation! There is another Tpk archive with an structure a little different, soon later I would like to request your help with the format, but for now I will try to do something mods in the files.
Once more time, thank you!
Alpha1001
Posts: 37
Joined: Tue Nov 06, 2018 10:11 am

Re: Bms script to unpack .tpk files from NFS games (PS2)

Post by Alpha1001 »

Hey DKDAVE, I've made some tests and after rebuild the Tpk archive and update the values as offset and dize from 0xf64, the game won't crash but instead of textures, the game shows a background screen. I believe that is because of the unknown values from 0xD0, that values it seems offset, but I can't understand how to compute it. It seems there is really 2 TOC in this archive.
Some tip?
Alpha1001
Posts: 37
Joined: Tue Nov 06, 2018 10:11 am

Re: Bms script to unpack .tpk files from NFS games (PS2)

Post by Alpha1001 »

Do you have some idea, Aluigi?
rabatini
Posts: 179
Joined: Tue Jan 18, 2022 12:21 am

Re: Bms script to unpack .tpk files from NFS games (PS2)

Post by rabatini »

You´ve to post your script here.
or the new tpk file format.
To aluigi or some expert guys take a look.
Is kind dificult figure out without even see an example.
rabatini
Posts: 179
Joined: Tue Jan 18, 2022 12:21 am

Re: Bms script to unpack .tpk files from NFS games (PS2)

Post by rabatini »

Alpha1001 wrote:Here the link again https://drive.google.com/file/d/1YgENZo ... sp=sharing

Hey DKDAVE, I've made some tests and after rebuild the Tpk archive and update the values as offset and dize from 0xf64, the game won't crash but instead of textures, the game shows a background screen. I believe that is because of the unknown values from 0xD0, that values it seems offset, but I can't understand how to compute it. It seems there is really 2 TOC in this archive.
Some tip?


you quote that you have managed extract and rebuild the file, it is a bms script?
How are you rebuilding those files?
are you repacking using reimporter2?
this kind of information is missing.

Or you simple need to aluigi or some other guy to take a look in the file again, because your extractor is not working proprely?
Alpha1001
Posts: 37
Joined: Tue Nov 06, 2018 10:11 am

Re: Bms script to unpack .tpk files from NFS games (PS2)

Post by Alpha1001 »

Hi, I managed to rebuild properly the archive now, I am using a tool made by me to dump and rebuild. I managed to find out the problem, this game has a duplicated TOC in another file, so is needed to fix the TOC and paste It in the duplicated TOC. After some days I have found this duplicated TOC and now the game works fine.
But now there is another problem, the comoressed HUFF and the JDLZ files, I can decompress the HUFF and the JDLZ files using an bms script made by Aluigi, but the script won't recompress again and I need to recompress this files to test some changes in the textures.
I've tried to use the reimport.bat in Quickbms but won't works, so I would like to know if the Aluigi or another guy can make an script to recompress the HUFF and JDLZ files used in the NFS games. Unfortunatelly, I don't understand about compress formats.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Bms script to unpack .tpk files from NFS games (PS2)

Post by aluigi »

This is the script for that TPK format:
http://aluigi.org/bms/nfsps2_tpk.bms

Reimporting is not possible and even editing the entry by hand would be painful (probably you have to set the type to "RAWW")
Alpha1001
Posts: 37
Joined: Tue Nov 06, 2018 10:11 am

Re: Bms script to unpack .tpk files from NFS games (PS2)

Post by Alpha1001 »

Thanks Aluigi, but I didn't understood about the "set the type to RAWW". In the RAWW mode the script will try to compress?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Bms script to unpack .tpk files from NFS games (PS2)

Post by aluigi »

I mean that the only way to disable compression would be to manually editing each file entry and using the "RAWW" type.
It's not really something that can be done by hand because probably other fields must be changed accordingly (compressed and decompressed size of both the main entry and file entry for sure), so it's just an information.