Assign constant rather than dynamic blockIndices to modded RMBs #2718
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is aimed at fixing this rather severe issue with modded RMB files (those with non-vanilla blockNames) first described here: #2703. Because modded RMBs are assigned their blockIndices dynamically rather than deterministically, their blockIndices change when the player restarts the game or loads a save. This breaks all interiors associated with modded RMBs. This means that saves within buildings in modded RMBs are corrupted and cannot be loaded. It also means that questors assigned to buildings in modded RMBs disappear, potentially preventing players from completing quests -- including the main quest. Unfortunately this issue affects some of the most widely used mods, including Fixed Desert Architecture, Finding My Religion, Beautiful Cities/Villages, and Cities Overhauled.
This PR fixes the issue in the simplest possible manner by allowing modders to assign a constant blockIndex to modded RMBs. I replaced the AssignNextIndex method with the AssignNewIndex method, which looks up the Index value from the RMB.json file:
Here AssignNewIndex will always assign this non-vanilla RMB block, TEMPASB0.RMB, the constant index 2012, which is well above the highest vanilla blockIndex (1294).
This PR will require RMB modders to change the Index values in all of their non-vanilla RMBs and to claim unique RMB blockIndices in the Daggerfall Workshop Resource Register. This will not require much adjustment since this is already standard practice for all other assets that require a unique, constant value, like LocationIds, FactionIds, and texture archives. To the best of my knowledge, only Cliffworms, Wayton, and I have made modded new RMBs so far, and coordinating between us will be easy.
I have tested this PR on modded new blocks in Beautiful Cities/Beautiful Villages and can affirm that saves inside modded RMB buildings successfully load and questors appear correctly.
I made this PR as a minimal change. One downside of my approach is that it requires deserializing modded RMB.jsons twice, once to get the Index value in AssignNewIndex and once to get the rest of the data in GetDFBlockReplacementData. While I don't find that this noticeably increases load time at startup, a more adept coder might be able to reorganize the WorldDataReplacements class or BlocksFiles so that it deserializes modded RMB.jsons only once. Alternately, the simplest and least intrusive way might be to move the blockIndex into the RMB.json filename, the way location jsons have their region and regional index in their filename. In this solution TEMPASB0.RMB-2012.json would be the filename for blockIndex 2012, and AssignNewIndex could simply parse the filename instead of deserializing the json. I can implement this if it seems preferable to reviewers.
Finally, please note that I made AssignNewIndex public. This is so that mods (and here I'm particularly thinking of World of Daggerfall) can add new modded RMBs as well. Therefore, this PR replaces 2709.