The Dink Network

Reply to A historic bug affecting magic-loading

If you don't have an account, just leave the password field blank.
Username:
Password:
Subject:
Antispam: Enter Dink Smallwood's last name (surname) below.
Formatting: :) :( ;( :P ;) :D >( : :s :O evil cat blood
Bold font Italic font hyperlink Code tags
Message:
 
 
August 24th, 06:35 AM
peasantmb.gif
yeoldetoast
Peasant They/Them Australia
Oh, NOW YOU'VE DONE IT! 
I was using CoPilot to investigate the possibility of improving JSON saving and loading when it mysteriously changed another line in the file pertaining to loading traditional binary save files. I was taken aback at first until I had a closer look. The affected section (this is from 1.08, but it's the same everywhere) was:

if (*pcur_magic != 0) 
{
   if (play.item[*pcur_magic].active == false)
   {
      *pcur_magic = 0;
      magic_script = 0;
       Msg("Loadgame error: Player doesn't have armed magic - changed to 0.");
   }


This is a safety check to ensure that the player does not attempt to equip non-existent magic upon loading a save by first checking to see if any magic was equipped, and then checking the validity of contents of that index of magic. You may have spotted it already, however the bug is in the 3rd line down where it looks to see if the magic section of the inventory has any magic in that specified index. Unfortunately, to do this, it checks play.item rather than play.mitem meaning it's checking weapons/normal items instead of magic, and then disarming the magic as per the corresponding weapon index.

You can test this for yourself by making a sample dmod equipped with only the fist in weapons/items and then adding multiple fireballs etc to the magic side and then equipping at least the second one, saving, restart/exiting, and then loading that save. Upon completing this, the chosen magic will not be re-equipped, and an error will be shown in the error log while loading.

This affects all known engine variants including UnDink. It was apparently noticed by SimonK during 1.08's development but ultimately went unaddressed. It may be mitigated somewhat by giving the player more weapons or AlkTree nuts etc.