Extracting .PCK files?

Discussion in 'NDS - ROM Hacking and Translations' started by Zarxrax, Feb 3, 2011.

Feb 3, 2011

Extracting .PCK files? by Zarxrax at 9:19 PM (8,917 Views / 0 Likes) 12 replies

  1. Zarxrax
    OP

    Member Zarxrax GBAtemp Fan

    Joined:
    Oct 5, 2005
    Messages:
    355
    Country:
    United States
    I would like to extract the English and Japanese scripts from the game Little Charo, but it looks like I'll need some help. After I unpacked the rom, I saw that the data files are stored in a .PCK format. I found some tool thats supposed to extract PCK archives, but it doesn't work on these.
    If I open up the scripts in a text editor I can see bits of the script here and there, but its mostly just gibberish.
     
  2. jjjewel

    Member jjjewel GBAtemp Maniac

    Joined:
    Dec 17, 2009
    Messages:
    1,004
    Country:
    United States
    The scripts in .pck files are compressed.

    The file with the same name as .pck file but with file extension .tbl contains addresses of the sub-files in .pck. You need to unpack the files first and then decompress them. (Ex. for _out_en.pck, look for the table file in _out_en.tbl.)

    (If your tool can unpack and repack the sub-files, you can try BatchLZ77 for compression/decompression. Otherwise, this might need a custom tool.)

    BatchLZ77 link
    http://code.google.com/p/darthnemesis/down...mp;can=2&q=
     
  3. Zarxrax
    OP

    Member Zarxrax GBAtemp Fan

    Joined:
    Oct 5, 2005
    Messages:
    355
    Country:
    United States
    Hey, I wanted to say thanks.
    For some reason, I never saw your reply earlier, though I kept checking this thread for a few days O.o

    There are indeed tbl files for each of the pck files.
    Any idea as to how I might unpack the sub-files that you mentioned?
     
  4. jjjewel

    Member jjjewel GBAtemp Maniac

    Joined:
    Dec 17, 2009
    Messages:
    1,004
    Country:
    United States
    First, did you check the file in IdxRes folder? Some of the .dat files contain English and Japanese text encoded in Unicode. (Ex. Try IdxRes_EngResult.dat.)

    Then for the .pck files, a program called CrystalTile2 will be handy. So try to get it first. (Any version should be fine.)

    I'll give a an example of out_en.pck and out_en.tbl then.
    - First, open both files in CrystalTile2.
    - Look at _out_en.tbl. You'll see 00000000 at hex address 0004, and then 1E270000 at hex address 0008, and so on. These are your addresses where you have to decompress your _out_en.pck.
    - Read each number at every 4 bytes backward to get the address, for example you will get 00000000, 0000271E, 000038B7, ...
    - Now go to your _out_en.pck. Point your mouse on the exact address you get from the previous step. (Ex. for the first one, point your mouse at hex address 00000000 at the beginning of the file.) Then go to Tools menu and select LZ77/Huffman Extract (U) and save as some filename. The program will ask if you want to open the extract file, choose ok. (Otherwise, locate the file and open it.)
    - The file here will be encoded in UTF-8. (You can view the text in CrystalTile2. In my version, it's under TBL/Code Page/Unicode (UTF-8))
    - Then repeat the steps for the next address. (0000271E, 000038B7, ...)

    This method will be very time consuming though.

    If you know some programming, or know someone who can write a program for you, it will be a lot easier. Just read addresses at every 4 bytes from .tbl file and extract each part of the file from .pck. After that you can use BatchLZ77 to decompress the files, or some programmer might even be able to add decompresser in the extraction process.

    By the way, I'm not sure if _out_en.pck contains anything you want. By randomly extracting them, I only see messages that say "This file doesn't have English translation." and such. So, if you do it manually, try checking what you get first. There might not be anything worth extracting in there.

    (Edited for some misspellings. [​IMG])
     
  5. Zarxrax
    OP

    Member Zarxrax GBAtemp Fan

    Joined:
    Oct 5, 2005
    Messages:
    355
    Country:
    United States
    Thanks for the help!
    Its difficult for me, but I'll see if I can write a program to do this.
     
  6. Zarxrax
    OP

    Member Zarxrax GBAtemp Fan

    Joined:
    Oct 5, 2005
    Messages:
    355
    Country:
    United States
    I feel like I'm sooo close to getting this now.
    I wrote a program to get the values from the table, and it worked.
    So then I thought I would try making the program split the data file according to the values, but this is where I'm having trouble.

    Once my files are split, I put them into the batchLZ77, and... it doesn't work. It just outputs empty decompressed files.
    So, I'm not really sure where I'm going wrong. It could be that I'm splitting the files totally incorrectly, or it could be that I've just got an off-by-1 error somewhere. Either way, I don't know how to debug it to see what I'm doing wrong.

    Here's my code, maybe you could take a look over it, if you can understand it?
    It's in C#

    http://pastebin.com/YCregGR0
     
  7. Tricky Upgrade

    Newcomer Tricky Upgrade Member

    Joined:
    Aug 14, 2010
    Messages:
    27
    Location:
    Mozambique
    Country:
    Mozambique
    Saw your code and I think you should store the data in a byte array (that will make it easier to get the correct position). Basically what you do is this:
    - Create two byte arrays (one for the .tbl file and other for the .pck file)
    - Read the address in the .tbl array (you can use the BitConverter class)
    - Create another byte array (for the file that the .tbl address points to)
    - Copy the contents from the .pck array to the one you just created
    - And finally write the copied contentes to a file, after this use BatchLZ77 to decompress the file

    I don't know how the .tbl determines the end of a file but you can subtract the current address from the next one to get the length of the file.

    PS: I can't debug your code since I don't have the files

    Edit: Your reading the addresses in the wrong way, the first four bytes are null so you'll want to read 4 bytes from 0x4 (which will leave you in address 0x8) and so on... and replace sizeof(int) with sizeof(byte)
     
  8. Zarxrax
    OP

    Member Zarxrax GBAtemp Fan

    Joined:
    Oct 5, 2005
    Messages:
    355
    Country:
    United States
    Aha, your comment helped me to see what I was doing wrong!

    I had stupidly written the line "int buffer = b2.ReadByte();"
    Using an int type rather than a byte, it was writing 4 bytes at a time into my output files (3 of them empty).
    So I fixed that, and now the output it almost perfect.

    My output files are nowhere near the filesize of the input, so I've probably got some stupid mistake in there which is keeping it from reading all the way to the end. I'll take a look at that later on, and then I should hopefully be finished with this, finally!

    Edit: yep, I had another issue using int instead of byte. I'm now able to extract all the data.
    Now to just sort through it and see if I can find what I need!
     
  9. Zarxrax
    OP

    Member Zarxrax GBAtemp Fan

    Joined:
    Oct 5, 2005
    Messages:
    355
    Country:
    United States
    Alright now, decompression with LZ77...
    There are 2 options... type 10, and type 11.
    What is the difference and how do I know what to choose? Output of both seems identical.

    And then, when viewing the files as utf8, I can read both english and Japanese in the output, but there is still a lot of garbage data. Is this normal?
     
  10. Phoenix Goddess

    Member Phoenix Goddess The Ninja's Protégée

    Joined:
    Apr 25, 2009
    Messages:
    3,809
    Location:
    Away from civilization.
    Country:
    United States
    You can usually check the beginning of a file to find out if it's Type 10 or Type 11, it'll have a 10 or 11.

    But you can also drag and drop one onto decompress and see if that'll work with BatchLZ77.
     
  11. Zarxrax
    OP

    Member Zarxrax GBAtemp Fan

    Joined:
    Oct 5, 2005
    Messages:
    355
    Country:
    United States
    Well I guess it autodetects or something? Because the one I select doesnt seem to matter.
     
  12. jjjewel

    Member jjjewel GBAtemp Maniac

    Joined:
    Dec 17, 2009
    Messages:
    1,004
    Country:
    United States
    Does it work now? Each of your output's first byte should have a value 0x10. And you can use the default type (Type 10) for BatchLZ77.

    When you extract, first you get the table addresses, such as 00000000, 0000271E, 000038B7, ...
    So you extract the first part of .pck from 00000000 to 0000271D. (The end of your first file will be 1 byte before the next address, and so on.)

    I don't know C#, so I don't know what went wrong. But you can try extracting a few files first. BatchLZ77 will auto-detect it if you extract it wrong. (I didn't try to extract the file and test though. I don't think there will be any problem. But feel free to post here if you encounter problems. I can try to take a look.)

    And the game will store some control codes in the scripts too. So, garbage data are common. (They are actually not garbage, but they are not the part of text that you need. [​IMG])
     
  13. Zarxrax
    OP

    Member Zarxrax GBAtemp Fan

    Joined:
    Oct 5, 2005
    Messages:
    355
    Country:
    United States
    Yep I got it all extracted like I needed.
    Now I just need to organize it and figure which text belongs with which parts of the game.

    Thanks for the help everyone [​IMG]
     

Share This Page