wetor / LuckSystem

Prototype's galgame (LucaSystem Engine) tools, Decompile and Compile LucaSystem's script file
Other
40 stars 7 forks source link

About CZ2 files #10

Closed hvpexe closed 8 months ago

hvpexe commented 10 months ago

Hello, I understand that Lucksystem currently does not support decompressing cz2 files due to some issues your team is facing. However, it's sad that the Loopers (Steam) uses this cz2 format for fonts, and the project may postpone if this font type cannot be decompressed.

I thought that you are quite busy, so I researched on my own. In the end, I went down a similar dead-end as you: the images in the cz2 file are compressed using the lzw algorithm with some modifications, and it's quite peculiar.

Below is my analysis (please note that I'm not specialized in reverse engineering):

You may have thoroughly understood the analysis I raised above but haven't been able to resolve it yet. I hope that some day in the future, your team can discover a decompressed mechanism for this file type. PS: this is font 明朝32.zip

wetor commented 10 months ago

After debugging, it was found that the index of the dictionary was not simply shifted one bit to the right (divided by 2), but it was even before 32595 without encountering any problems. However, an error occurred in the calculated index afterwards, resulting in LZW decompression error

uint16 159 (32595 th) Correct: 32847 uint16 11361 (32596 th) Correct: 8902 uint16 30274 (32597 th) Correct: 14180 uint16 52883 (32598 th) Correct: 15593 ... The correct data corresponding to these few bytes: image The logic is probably here: image

I think I can solve this problem as soon as today, otherwise it will be solved next weekend

hvpexe commented 10 months ago

Thank you so much, hoping you will successfully compress and decompress this file.

wetor commented 9 months ago

You can try using CZ0 or CZ1 format fonts (obtained and edited from other games). I remember we tested it before, and as long as the font size and corresponding info file are correct, regardless of the image format, they can be used normally

Regarding CZ2, there has been some progress in extraction, but there are still issues that may not be resolved in the short term. It is also impossible to achieve import before the extraction is complete. You should prioritize using self-made fonts in other formats

hvpexe commented 9 months ago

Actually, I have read your blog and discovered above method. Then we used cz1 with correct size to replace font.pak, and the result is not very promising. image

We will try testing further with cz0 by trial and error. PS: The default dialog text font size is 44 for English.

wetor commented 9 months ago

I thought for a moment, and if I don't succeed after trying CZ2 again, I will give up.

For Windows, using hooks is a simpler and more efficient method. Based on my research on CZ2, I think I can try implementing a hook program to directly load PNG image fonts

(The original purpose of both LucasSystemtool and this project was to solve the localization problem of console games)

wetor commented 9 months ago

https://github.com/wetor/LuckSystem/commit/604e858fc5a731d901fcb790671849d6f31e1bde

https://github.com/wetor/LuckSystem/releases/tag/v2.1.0

The extraction of CZ2 has been completed, but the code has not been optimized yet. The compression part may not be implemented temporarily.

Afterwards, I will try to replace the runtime font image with a hook method

The executable files of this game may have some compression and cannot be easily decompiled, so I spent a lot of time dynamically debugging and manually implementing the assembly code. For me, this is an interesting attempt

hvpexe commented 9 months ago

Wow, this is really a challenging work, truly appreciate your efforts. Looking forward to the results you will achieve in the next commits.