cpk file unpack error [Amagami]

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
OneCombo
Posts: 67
Joined: Mon Jul 20, 2015 1:12 pm

cpk file unpack error [Amagami]

Post by OneCombo »

https://www.dropbox.com/s/31y94n7h88voy ... O.CPK?dl=0

This cpk file is psp game Amagami's script.

I need your help to unpack.

cpk.bms script doesn't work.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: cpk file unpack error [Amagami]

Post by aluigi »

That's a job for CriPakTools that supports also the encrypted archives:
https://github.com/esperknight/CriPakTo ... kTools.exe

Tested and works, if you have never used it create a new folder, put SCENARIO.CPK and the CriPakTools.exe in it, create a file.bat containing the following and launch it:
CriPakTools.exe SCENARIO.CPK ALL
OneCombo
Posts: 67
Joined: Mon Jul 20, 2015 1:12 pm

Re: cpk file unpack error [Amagami]

Post by OneCombo »

thank you for your kind.

as you know, cpk file need a CSV file.

because inside there are many files, but each file has different compression.

how to make CSV file?

there are many files in there.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: cpk file unpack error [Amagami]

Post by aluigi »

I don't know about this csv file, the extraction process is completed and the file there have an SCF\x1a magic that means it's a file format (model?), I don't see compression and in any case the cpk files use the CRILAYLA compression which is handled automatically by the script.
I'm sure that other users know about what you refer, I know only about the extraction :D
OneCombo
Posts: 67
Joined: Mon Jul 20, 2015 1:12 pm

Re: cpk file unpack error [Amagami]

Post by OneCombo »

Thank you :)

can you help?

https://www.dropbox.com/s/oo2ewuplo8xtp ... I.IMG?dl=0

I think like maybe this file is compressed.

Can you analyze this file?

Thank you.

Sorry, my English is poor....:(
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: cpk file unpack error [Amagami]

Post by aluigi »

Not sure at 100% but the following is the script that gives the best decompressed result:

Code: Select all

comtype lzss "11 5 2 2 0"
get SIZE long
savepos OFFSET
get ZSIZE asize
math ZSIZE - OFFSET
get NAME basename
clog NAME OFFSET ZSIZE SIZE
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: cpk file unpack error [Amagami]

Post by aluigi »

OneCombo
Posts: 67
Joined: Mon Jul 20, 2015 1:12 pm

Re: cpk file unpack error [Amagami]

Post by OneCombo »

Thank you very much !! :) :) :)

Is it possible reimport files?

if file size over, reimport it doesn't work. right?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: cpk file unpack error [Amagami]

Post by aluigi »

The "file size" rule is ever valid so new <= old.
Reimporting is perfectly possible but it's necessary to split the script in two parts because the original script does everything on the fly in memory.

So the first part is the decompression of AMAGAMI.IMG:

Code: Select all

comtype lzss "11 5 2 2 0"
get SIZE long
savepos OFFSET
get ZSIZE asize
math ZSIZE - OFFSET
clog "tmp.dat" OFFSET ZSIZE SIZE

While the second part is the extraction from the generated tmp.dat file:

Code: Select all

get SIZE long
get FILES long

for i = 0 < FILES
    get NAME_OFF long
    putarray 1 i NAME_OFF
next i

for i = 0 < FILES
    get OFFSET long
    putarray 0 i OFFSET
next i
    putarray 0 i SIZE

for i = 0 < FILES
    getarray NAME_OFF 1 i
    getarray OFFSET   0 i
    math i + 1
    getarray SIZE     0 i
    math SIZE - OFFSET

    goto NAME_OFF
    get NAME string
    string NAME + "."

    log NAME OFFSET SIZE
next

Now, you do not need to extract the files again because they are fine, but use the first script on AMAGAMI.IMG for generating tmp.dat

When you want to reimport the files run reimport.bat selecting the second script, tmp.dat and the folder where you previously extracted the files.

Now run reimport.bat with the first script, amagami.img and the folder where is located tmp.dat.
If you have problem with this specific step I can write a new script that doesn't need reimport.bat.

It's really very easy, it's more difficult to explain it than doing it.
OneCombo
Posts: 67
Joined: Mon Jul 20, 2015 1:12 pm

Re: cpk file unpack error [Amagami]

Post by OneCombo »

offset filesize filename
--------------------------------------

Error: file "tmp.dat"
the reimport option acts as a reimporter and so you cannot reinsert a
file if it's bigger than the original otherwise it will overwrite the
rest of the archive or cannot be loaded correctly:

new size: 2144096 uncompressed
old size: 2144092 uncompressed

- do you want to skip this file? (y/N/force)
y will continue with the next file
N (default) will terminate QuickBMS
force will force the reimporting of the file
force

Error: file "tmp.dat"
the reimport option acts as a reimporter and so you cannot reinsert a
file if it's bigger than the original otherwise it will overwrite the
rest of the archive or cannot be loaded correctly:

new size: 888668 (2144096 uncompressed)
old size: 888666 (2144096 uncompressed)

- do you want to skip this file? (y/N/force)
y will continue with the next file
N (default) will terminate QuickBMS
force will force the reimporting of the file
force
< 00000004 888668 tmp.dat

- 1 files reimported in 442 seconds
coverage file 0 0% 4 888672 . offset 00000004

Press ENTER or close the window to quit

-------------------------------------------

it shows like this window.

first, i select a first script.

second, select a amagami.img.

third, select a unpacked folder.

i tried the test. wrote 4 byte more.

and then i tried the second test.

tried uncompress edited amagami.img (wrote a 4 byte file)

offset filesize filename
--------------------------------------
00000000 0 -.dat
00000000 0 00000001.dat
00000000 242 \.dat
000000f2 4294967138 \.dat

- The following output file already exists:
.dat
Do you want to overwrite it?
y = overwrite (you can use also the 'o' key)
n = skip (default, just press ENTER)
a = overwrite all the files without asking
r = automatically rename the files with the same name
s = skip all the existent files without asking

r

Error: impossible to write 0xffffff62 bytes (total 0xffffff62)
Check your disk space

Last script line before the error or that produced the error:
26 log NAME OFFSET SIZE

Press ENTER or close the window to quit

---------------------------

what should i do??

sorry~!

when i localize this game, i'll probably over those file's size.

because it takes longer to translate into Korean.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: cpk file unpack error [Amagami]

Post by aluigi »

Here all the step works BUT I guess there is a problem with the recompression algorithm, that's possible because it's a specific setting that has been never used before.
In short, it will be fixed in the next version of quickbms.

In the meantime I show you how the scripts must be used from command-line since it's more easy to understand the process:

Extract:
quickbms 1.bms AMAGAMI.IMG
quickbms 2.bms tmp.dat new_folder

Edit your files in new_folder

Reimport:
quickbms -r -w 2.bms tmp.dat new_folder
quickbms -r -w 1.bms AMAGAMI.IMG

As already said, the recompression algorithm doesn't work so the edited AMAGAMI.IMG WILL NOT WORK.
OneCombo
Posts: 67
Joined: Mon Jul 20, 2015 1:12 pm

Re: cpk file unpack error [Amagami]

Post by OneCombo »

Thank you for your kind answer!

I waiting for QuickBms's update.

Have a great day!

If I have a question, Il'll be back! :)

Thank you!