loicfrance / mahoyo_tools

extract and reinject files into Witch of the Holy Night (Steam)
6 stars 0 forks source link

Not extracts .mzp with multiply entries (Titres). #1

Closed Dimoks closed 3 months ago

Dimoks commented 3 months ago

Problem with data02400.hfa. If you extract it using HunexFileArchiveTool, you can convert them to PNG using PS-HuneX_Tools. In this .mzps 25 - 37 entries.

The utilities are wonderful, they allow you to replace .cbg graphics in the archive, and the game works with them.

TypeError: only length-1 arrays can be converted to Python scalars

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\Distr\Games\Mahoutsukai_no_Yoru\tools.py", line 169, in <module>
    extract(archives=args.archives, path=args.paths, names=args.names)
  File "D:\Distr\Games\Mahoutsukai_no_Yoru\tools.py", line 119, in extract
    hfa_file[name].extract(file)
  File "D:\Distr\Games\Mahoutsukai_no_Yoru\mahoyo_tools\hfa.py", line 326, in extract
    return mzpImg.img_write(dest)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Distr\Games\Mahoutsukai_no_Yoru\mahoyo_tools\mzp.py", line 453, in img_write
    tile_pixels = self.get_tile(index)
                  ^^^^^^^^^^^^^^^^^^^^
  File "D:\Distr\Games\Mahoutsukai_no_Yoru\mahoyo_tools\mzp.py", line 389, in get_tile
    pixels: NDArray[np.uint8] = np_rgb565_unpack(rgb565, offsets)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Dimoks\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages
\Python312\site-packages\numpy\lib\_function_base_impl.py", line 2397, in __call__
    return self._call_as_normal(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Dimoks\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages
\Python312\site-packages\numpy\lib\_function_base_impl.py", line 2390, in _call_as_normal
    return self._vectorize_call(func=func, args=vargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
loicfrance commented 3 months ago

Thanks for the report. I think I fixed this issue, could you please confirm ?

I guess you want to edit the file and inject it back. For the injection, don't forget to specify the compression_level to 1 or 2. This will greatly reduce the compressed size compared to the default compression_level = 0 (for img7000, it goes from 33.8MB with level 0 to 609 kB with level 2). This however adds a lot of computation time. For debug purpose, you can probably use levels 0 or 1.

EDIT : the compression_level argument is only valid for mzp images

Dimoks commented 3 months ago

Now these files are extracts normally. Is it possible to specify compression_level when inserting any files, or is it only possible for mzp?

loicfrance commented 3 months ago

The choice of the compression level is only for mzp images which use the mzx compression. Cbg images also use a compression algorithm, but there is no choice to make, the file must be compressed a specific way. Some files (including scripts) are stored using the optional LenzuCompressor algorithm, for which I haven't implemented the compression yet (only decompression is implemented).

Dimoks commented 3 months ago

If you specify the compression in inject (file, compression_level 2) for all inserted files, will this not cause problems when inserting other files? There seemed to be no problems when inserting the cbg.

loicfrance commented 3 months ago

Yes, I don't have any filter on the keyword arguments (yet), so if you pass a keyword argument to the inject method that is not expected for this file, it will fail.

EDIT : I indeed forgot to mention in my first message that the compression_level argument was only for mzp images.