So, the other day I was playing QFG1, the VGA version, for the first time in a few years, and ran into a bug I'd never noticed before. I was in the kobold's cave, a bit low on mana, but still had enough to cast a spell. Except the game told me I didn't have enough mana for the spell when I tried to cast it. What the heck? So I gave up and left, restored my mana and continued on playing. But I never forgot about that odd bug. I completed the game, but came back to it after I was done to poke around a bit, and see if I could figure out what had happened.
My first discovery was that a couple of my spells cast in the kobold's cave cost twice the normal amount of mana. Out of curiosity, I decided to see if the EGA version had a similar quirk. This is where things got interesting. Not only did it have the same bug, but it happened with more spells. So I dug into the SCI Decompilation of QFG1EGA with SCI Companion and (
after wayyy too much time looking at the code and trying to figure out exactly where the bug was occurring) eventually discovered that there were 11 separate room scripts that had this bug. Best I could gather from comparing code between rooms where spells do something unique came down to the unique spell code being nested within a block of code that checked if the spell could be cast. The rooms where this bug didn't occur put the code that checked if the spell could be cast inside each of the spells coded for the room. I'm admittedly just a novice programmer, so I'm not exactly sure why this distinction made all the difference, but I found my solution and fixed up the scripts for the 11 rooms this bug occurred in. The VGA version is a bit of a different beast with a similar bug, but it seems to occur less frequently. I admittedly haven't fully figured out the bug for the VGA version yet, but I'm working on it.
I've posted my work (
forked from ErikOakford's SCI Decompilation) up on Github if anyone wants to take a look. It hasn't been fully tested yet but with the limited testing I did on my own, everything seems to be working fine with spells now. You can also download a zip of patch files for the room scripts there, but I'll attach it here as well. Also, I was working with v1.200 of QFG1EGA so I'm not sure how compatible it would be with any other version, or the original Hero's Quest release.
If anyone more knowledgeable with SCI than me has any insight into the bug, I'd love to hear it. The original code in theory looks like it should work, and it does look cleaner, but it just doesn't work the same.
Link to the Github repo!