wetor / LuckSystem

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

Bug for import image #4

Open masagrator opened 2 years ago

masagrator commented 2 years ago

When converting to CZ3, tool is using compressed size from source as some kind of limitation of how big 1 compressed image can be, which is not always correct. For Summer Pockets max size per each layer is 0xFEFD, and for some reason images converted by this tool with more than 1 layer are rendered as garbage by game except for first layer.

masagrator commented 2 years ago

Next issue - importing CZ1 is broken. it doesn't output full header. After fixing header image is broken when converting it back to PNG. example of original file, just convert it to PNG and convert it back. RB_TABLE_TENNIS_PAUSE.zip

If i see correctly, some informations are written as big endian instead of little endian, in indexes RGB (transparency is fine) is written too in wrong order.

masagrator commented 2 years ago

Fixed the issue with CZ3 layers.

If there is more than one layer, uncompressed size of first layer is 1 byte too high, and of last layer 1 byte too low.

After fixing this all images are rendered correctly in Summer Pockets. Using this simple Python script that is getting file path as first argument

import sys

file = open(sys.argv[1], "rb+")
if (file.read(4) != b"CZ3\x00"):
    print("Wrong FILE!")
    sys.exit()

header_size = int.from_bytes(file.read(4), byteorder="little")
file.seek(header_size-8, 1)
layer_count = int.from_bytes(file.read(4), byteorder="little")
if (layer_count == 1):
    print("File doesn't need correction!")
    sys.exit()
next_pointer = file.tell() + (8 * (layer_count-1))

file.seek(4, 1)
unc_size1 = int.from_bytes(file.read(4), byteorder="little", signed=False)
file.seek(-4, 1)
unc_size1 -= 1
file.write(unc_size1.to_bytes(4, "little", signed=False))

file.seek(next_pointer)
file.seek(4, 1)
unc_size2 = int.from_bytes(file.read(4), byteorder="little", signed=False)
file.seek(-4, 1)
unc_size2 += 1
file.write(unc_size2.to_bytes(4, "little", signed=False))

file.close()