I’m trying to correct a script error in a saved game.
The conventional wisdom to date IIRC is that the overriding priority is
hak > patch hak > module > override > EE ovr > bif
When a saved game is loaded, the original module is ignored, but overrides are applied as though the saved game is a module in the sequence above.
However, I’m finding that scripts in a patch hak do not override the saved game.
I checked that the patch hak was loading by executing a script in debug mode that was only in the patch hak.
If this is correct. it seems that the only way to override a script in a saved game is to inject it into a regular hak that the module already uses (which is hardly best practice!).
I’d expect nwn1 to be the same, in nwn2 land you can’t add a hak after the fact, you can add things to an existing hak. I’ve included a patch-hak with the release of things for just that reason. The hak can’t be empty, so I put in an empty text file. Then I can update the patch-hak as needed and people only have to download the patch-hak to get updates.
Indeed, that’s how I patch my Dark Energy module - with a regular hak, initially empty. Files added to it show up in saved games, overriding the module originals.
The problem I’m dealing with here is different. I’m playing an old module, whose author is not around. A long, long way into the action, I find a game-breaking bug which I can fixed by injecting a corrected script into any of its regular haks.
However, using a patch hak would be more elegant. This is an obscure feature of NWN1 that allows you to add a hak to every module, in a similar manner to an override. Problem is, just like an override, it appears to me that patch hak scripts do not take priority over module / saved scripts. I’m seeking confirmation because some sources say that they do.
So because it was me who said this is the loading order, I made short test under 1.69.
I used a functionality of NWNCX_Patch that runs additional script 70_mod_def_chat in OnChat event as this is the only script I had in override, so I put this script into patch hak, allowed it via nwnpatch.ini, then edited empty module DEMO_Containers and created 70_mod_def_chat with single line of SendMessageToPC(GetFirstPC(),“test chat”);
When I ran it with NWNCX and I wrote “g” nothing happened, and when I wrote some debugging commands like “rest” my character rested so this should mean that patch-hak overwrote the resource as expected.
However, when I removed the patch-hak or rather renamed it so it won’t load the result was the same.
I then went into toolset and when trying open the module it said the script doesn’t exist. When I opened module in nwnhak.exe I noticed the 70_mod_def_chat.nss has 0bytes and .ncs had 30k something - this indicates that the script I written was replaced by the script from patch-hak when saving module. (Which is normal behavior actually but toolset won’t warn you from resources from patch-hak unlike resources from hak).
Had to restart toolset completely to be able to re-create the script and tested this the opposite way. So first I created 70_mod_def_chat script with the single line and saved. Only after then I setup patch-hak and to my suprise I can confirm your finding and not only that.
From this test is seems that the loading order is different in toolset and in actual game.
Okay so it seems that the loading order is different in toolset and game client (didn’t test server yet). So this is not script specific it applies to all types of content (well tested with script and creature blueprint so I expect as much…).
Toolset: hak > patch hak > module > override > EE ovr > bif
Game client: hak > module > patch hak > override > EE ovr > bif (and texturepacks somewhere between as well…)
Also note that when editing modules in toolset with scripts in patch-hak toolset doesn’t inform you that the script is loaded from patch-hak or overwritten by patch-hak (white there is a warning in case of script with same name in regular hak). After saving module, the scripts with same names are overwritten by (patch)hak and that version is saved into module!
@meaglyn I see your point - obviously, patch hak impacts all modules globally, though it might have served as a quick fix. Since it doesn’t work in game, though, it’s a dead duck.
P.S. Editing .sav is slightly (only slightly) clunky, as nwhak won’t open it unless you specify *.sav, and won’t save as more than a 16 character name. Still probably the best method. If I decide to distribute my fix to players, I’ll probably offer both the .sav edit and the .hak edit methods.
Of course, I could just change the original author’s module, but that might be disrespectful, and wouldn’t help players who have saves reflecting many hours of play.
If the module has no hak then these are probably the only options. If there is a hak then you can put that file into it and distribute the fix within the modified hak. This should be pretty safe/drawback-less unless it is a hak shared by other modules like CEP and also script possibly shared by other modules such as vanilla resource scripts nw_ x0_ x2_ etc.
nwsync takes precedence over module resources. So far, it has only been set up to work on the client, but it is just another resman provider, and compiled scripts could be added to it. Not all of this is implemented yet, but I can imagine it allowing for easy patching of saves eventually - or even hosting entire modules out of nwsync, without a .mod file at all.