hhyyrylainen / GodotPckTool

Standalone tool for extracting and creating Godot .pck files
MIT License
383 stars 31 forks source link

TOC padding is wrong #23

Closed sergeikrasnikov closed 1 year ago

sergeikrasnikov commented 1 year ago

The table of content padding calculation is wrong

In the file PckFile.cpp the lines 137--139

        const size_t pathToWriteSize =
            entry.Path.size() + (entry.Path.size() % PadPathsToMultipleWithNULLS);
        const size_t padding = pathToWriteSize - entry.Path.size();

The middle line should be entry.Path.size() + (PadPathsToMultipleWithNULLS - entry.Path.size() % PadPathsToMultipleWithNULLS)

For reference, see the function static int _get_pad(int p_alignment, int p_n) in editor_export_platform.cpp

hhyyrylainen commented 1 year ago

So the problem is that the padding amount is reverse of what it should be?

hhyyrylainen commented 1 year ago

Doing an excel file with various values, I noticed that the corrected math you suggested results in the correct padded lengths, but when the length is exactly right it ends up adding 4 extra padding bytes, though maybe that is actually required to have at least one terminating null?

I'll do a PR to test if the new math works fine or if there is potentially a problem.