For instance, if someone had a new game inside an auto save and a game where he is much further in another save, all areas would result as "not visited" (and possibly not yet reachable) in the other save, or you could have a new game where all areas result already visited if the situation is the opposite.
Unfortunately, CLEAR_ARRAY does not really forget the current values of the array, so VARIABLE_IS_SET would still return 1 after a CLEAR_ARRAY.
What I suggest is to use different arrays for each saved wmp file.
Here's a suggestion of how to fix that:
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ /////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ ///// \\\\\ ///// Part 5: Convert old Savegames \\\\\ ///// \\\\\ /////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ /////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\ BEGIN @5000 //If you want to uninstall this component, you have to make a backup of your savegame folder manually! //EDIT: after uninstalling the worldmap, you can install this component again in order to return to the original worldmap. You will lose all information about mod-added areas. DESIGNATED 3 REQUIRE_PREDICATE ENGINE_IS ~soa tob~ ~This mod can only be installed on BG2-based games~ NO_LOG_RECORD MKDIR save mpsave OUTER_SET j=0 //we'll use a different array for every saved worldmap file ACTION_FOR_EACH dir IN save mpsave BEGIN ACTION_CLEAR_ARRAY dir_array GET_DIRECTORY_ARRAY dir_array "%dir%" ~[0-9]+-.*~ ////////////////////////////////////// //SOA and TOB ACTION_PHP_EACH dir_array AS int => dir BEGIN /* ACTION_IF FILE_EXISTS ~%dir%/worldmap.wmp~ BEGIN OUTER_SPRINT worldmap worldmap.wmp END ACTION_IF FILE_EXISTS ~%dir%/worldm25.wmp~ BEGIN OUTER_SPRINT worldmap worldm25.wmp END*/ ACTION_FOR_EACH worldmap IN ~worldmap.wmp~ ~worldm25.wmp~ BEGIN ACTION_IF FILE_EXISTS ~%dir%/%worldmap%~ BEGIN ///////////////////////////////////////// //Store old flag and areanames in a table COPY + ~%dir%/%worldmap%~ ~%dir%~ READ_LONG 0xc mo READ_LONG mo + 0x20 na READ_LONG mo + 0x24 ao FOR (i = 0; i < na; ++i) BEGIN READ_ASCII ao + i * 0xf0 old_area READ_LONG ao + i * 0xf0 + 0x30 old_flag TO_LOWER old_area // PATCH_IF !VARIABLE_IS_SET $flags_array("%j%" "%old_area%") BEGIN //this caused flags from the auto-save (usually) to overwrite those of other saved games SET $flags_array("%j%" "%old_area%") = old_flag //this array will only contain info from THIS saved game // END END //for BUT_ONLY /////////////////////// //New savegame wmp file COPY_EXISTING + ~%worldmap%~ ~%dir%~ READ_LONG 0xc mo READ_LONG mo + 0x20 na READ_LONG mo + 0x24 ao FOR (i = 0; i < na; ++i) BEGIN READ_ASCII ao + i * 0xf0 new_area TO_LOWER new_area PATCH_IF VARIABLE_IS_SET $flags_array("%j%" "%new_area%") BEGIN WRITE_LONG ao + i * 0xf0 + 0x30 $flags_array("%j%" "%new_area%") END END //FOR & copy OUTER_SET ++j //update flags_array index END //FILE_EXISTS END //worldmap END //PHP_EACH END //dir
I've tested it and it appears to work as expected, and to keep the flags of each areas without mixing them up.
PS: This component clearly states that it can't be uninstalled, and that you must back up saved files manually. Well, actually there is a way to uninstall it. Strange as it seems, that way is to install it again, AFTER uninstalling the other components: that will copy back the old worldmap into the saved game, and keep all flags for all (vanilla only!) areas. So, visited areas will remain visited and so on. Mod-added area flags will instead be forgotten.