wetor / LuckSystem

Prototype's galgame (LucaSystem Engine) tools, Decompile and Compile LucaSystem's script file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About CZ2 files

hvpexe opened this issue · comments

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):

  • Taking the example of the file 明朝32, the compressed image data starts from offset 446h. I noticed that almost UInt16 values after that are even numbers
    image

  • So I made adjustments to the lzw algorithm in LucaSystemTool (I used the old tool because it already had a base implementation for cz2) as follows:
    image
    image

  • And this is result:
    明朝32

  • I believe this chaos begins at offset 102ECh, at which point Uint16 has a value of 159, which is the first odd value. This corresponds to the 32595th value in the List compressed. At this stage, I can't think of anything else to overcome the issue.

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

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

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

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

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.

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)

604e858

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

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