LostArtefacts / TR1X

Open source re-implementation of Tomb Raider 1 (1996), along with additional enhancements and bugfixes
https://lostartefacts.dev/
GNU General Public License v3.0
583 stars 36 forks source link

Memory fixes, high number of savegame slot fixes, and requestor fixes and rework #1389

Closed walkawayy closed 3 months ago

walkawayy commented 3 months ago

Checklist

Description

This PR fixes memory issues that occurred with savegames as well as a 64 savegame slot limit due to int32_t gf_param = gf_option & ((1 << 6) - 1); which was due to the bitflow operations in the gameflow. There is a second small commit to fix two small memory leaks in the gameflow as well.

The memory leak occurred if the number of savegame slots was over 16. Requestor's item_flags max value was 16 which was less than the default savegame amount in TR1X. Reworked much of the requestor code to account for this. Also reworked the item_texts to be safer.

The 64 slot limit was fixed by reworking the GAMEFLOW_OPTIONs to no longer use bit shifting. This PR introduces a new gameflow info struct that contains that information. It's a new global struct and changed the phasers, so they don't return. But it seemed necessary since some of the issue was only being able to return one value.

This will need heavily tested, but lmk if you think the code changes look good before I ask for testing help. I'm surprised we didn't have more issues reported because the memory was severely corrupted. Maybe it only really showed up badly when I started testing with a really high number of savegames.

Also, there is a memory leak in packer.c, but I was unable to fix it. The TEX_INFO *info = Memory_Alloc(sizeof(TEX_INFO)); are never freed, and there is some pointer to malloc'd pointer stuff going on in there.