glacier-modding / RPKG-Tool

The RPKG tool allows for easy (un)packing of files from the Glacier Engine RPKG file format! Hitman 3 has the most support.
https://glaciermodding.org/rpkg/
Other
47 stars 9 forks source link

[BUG] Non-h3 textures crash RPKG #29

Closed paxcut closed 2 years ago

paxcut commented 2 years ago

Describe the bug Any attempt to obtain information about textures results in the gui crashing without any errors.

To Reproduce Open any rpkg that has TEXT files inside and left click on any. After a little while where nothing is happening the gui closes.

Expected behavior even if textures cant be shown, the app should not crash and if if crashes it should display some indication as to what went wrong.

Screenshots N/A

RPKG tool version: 2.17.2 and locally compiled version of latest code as well. Hitman Version: 2016 steam

Additional context I got the source code and did a debug build which didn't run until i added the three resourceLib dlls from the other project that are also included in the binary release. upon debugging i found what appears to be a serious error in the size of one variable. In particular looking at text.cpp line 293 we find variable text_texture_data_offset that gets a very large number (order 0x10000000) assigned to it.

After that, variable text_texture_data_size is assigned a relatively small number (order 0x1000) from which the first value is subtracted which seems wrong and yields a huge value for text_texture_data_size. this variable is used to allocate a vector in line (approx) 322. later in line (approx) 346 this huge data set is moved some 13 bytes which causes a memory access exception and a crash.

Also i noticed that for the texture i was checking the value of text_mips_count is set to zero and arrays of that size are used to access their first element which is invalid. Either allocate room for one element if size is zero or check for size before accessing array values.

My knowledge of texture programming is close to zero, so the changes i made to prevent crashes may be wrong, but the app no longer crashes and there are no indications of things being wrong, but i am not qualified to be the judge of that. Still, if anybody is interested I can post the code or even submit a PR.

I really like this tool and I am having a lot of fun with it. It is perfect for a newbie like me. Thank you. -Paxcut

Notexe commented 2 years ago

Hey, Thanks for the bug report. Currently the tool really only has support properly for Hitman 3 textures (And it's missing support for one or two of the texture types still). We do want to get texture support for Hitman 1 and 2 at some point but we do want to rewrite the entire tool due to the code being a mess so we will probably add support for the older games when we are doing that.

paxcut commented 2 years ago

your welcome,

I was not aware of the version limitations and I am glad to hear of the plans to update it to support the first two games texture wise. I still think that having the app crash after consuming so much memory that even my mouse freezes for 2 minutes is something that should be avoided but that's just my opinion of course. Thank you for your quick reply. I am liking your tool more and more. -Paxcut

AnthonyFuller commented 2 years ago

A workaround has been implemented with b2b44f1, it will be in the next release. You can download the nightly version here.

This workaround is that the texture will only load when you click on the Image Viewer tab (it will still crash for any textures that aren't from Hitman 3). We are aware that other textures will crash the tool but there is nothing we can do as there is no viable way to detect the version of the game the textures come from. The next major release should solve this.