Skip to content

Commit

Permalink
637: Default to ZERO_FID instead of DUMMY_FID
Browse files Browse the repository at this point in the history
Otherwise we will end up blowing up, e.g. for PACK in Oblivion. Kept
DummyFid itself around for the uses in record_groups.

Mopy/bash/game/oblivion/records.py:
Mark PACK\PLDT as MelOptStruct

We don't want to dump it out if it wasn't present, and since the FormID
is pretty much never going to be NULL, MelOptStruct is fine here.
Notably, the similar PTDT below was already using MelOptStruct.

Wrapped and py3ified affected lines and the rest of the melSet
definition.
  • Loading branch information
Infernio committed Aug 13, 2022
1 parent 56af6ff commit 7fb57e5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Mopy/bash/brec/basic_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from . import utils_constants
from .utils_constants import FID, null1, FixedString, int_unpacker, \
get_structs, DUMMY_FID
get_structs, ZERO_FID
from .. import bolt, exception
from ..bolt import decoder, encode, structs_cache, struct_calcsize, Rounder, \
sig_to_str, attrgetter_cache, struct_error
Expand Down Expand Up @@ -625,7 +625,7 @@ def mapFids(self, record, function, save_fids=False):
def static_size(self):
return self._static_size

def _parseElements(self, struct_formats, *elements, __zero_fid=DUMMY_FID):
def _parseElements(self, struct_formats, *elements, __zero_fid=ZERO_FID):
formAttrs = set()
lenEls = len(elements)
attrs, defaults, actions = [0] * lenEls, [0] * lenEls, [None] * lenEls
Expand All @@ -644,7 +644,7 @@ def _parseElements(self, struct_formats, *elements, __zero_fid=DUMMY_FID):
if callable(el_0):
if el_0 is FID:
formAttrs.add(element[1])
defaults[index] = __zero_fid # DummyFid
defaults[index] = __zero_fid
actions[index] = el_0
attrIndex = 1
self._action_dexes.add(index)
Expand Down
2 changes: 1 addition & 1 deletion Mopy/bash/brec/utils_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class _DummyFid(_Tes4Fid):
"""Used by setDefault (yak) - will blow on dump, make sure you replace
it with a proper FormId."""
def dump(self):
raise AbstractError(f'Dumping a dummy fid')
raise AbstractError('Dumping a dummy fid')
DUMMY_FID = _DummyFid(0)

# Random stuff ----------------------------------------------------------------
Expand Down
31 changes: 16 additions & 15 deletions Mopy/bash/game/oblivion/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -1630,26 +1630,27 @@ class MrePack(MelRecord):

melSet = MelSet(
MelEdid(),
MelTruncatedStruct(b'PKDT', [u'I', u'B', u'3s'], (_flags, 'flags'), 'aiType',
'unused1', old_versions={'HBs'}),
MelTruncatedStruct(b'PKDT', [u'I', u'B', u'3s'], (_flags, 'flags'),
'aiType', 'unused1', old_versions={'HBs'}),
MelUnion({
(0, 1, 2, 3, 4): MelStruct(b'PLDT', [u'i', u'I', u'i'], u'locType',
(FID, u'locId'), u'locRadius'),
5: MelStruct(b'PLDT', [u'i', u'I', u'i'], u'locType', u'locId', u'locRadius'),
(0, 1, 2, 3, 4): MelOptStruct(b'PLDT', ['i', 'I', 'i'], 'locType',
(FID, 'locId'), 'locRadius'),
5: MelOptStruct(b'PLDT', ['i', 'I', 'i'], 'locType', 'locId',
'locRadius'),
}, decider=PartialLoadDecider(
loader=MelSInt32(b'PLDT', u'locType'),
decider=AttrValDecider(u'locType'),
loader=MelSInt32(b'PLDT', 'locType'),
decider=AttrValDecider('locType'),
)),
MelStruct(b'PSDT', [u'2b', u'B', u'b', u'i'], u'month', u'day', u'date', u'time',
u'duration'),
MelStruct(b'PSDT', ['2b', 'B', 'b', 'i'], 'month', 'day', 'date',
'time', 'duration'),
MelUnion({
(0, 1): MelOptStruct(b'PTDT', [u'i', u'I', u'i'], u'targetType',
(FID, u'targetId'), u'targetCount'),
2: MelOptStruct(b'PTDT', [u'i', u'I', u'i'], u'targetType', u'targetId',
u'targetCount'),
(0, 1): MelOptStruct(b'PTDT', ['i', 'I', 'i'], 'targetType',
(FID, 'targetId'), 'targetCount'),
2: MelOptStruct(b'PTDT', ['i', 'I', 'i'], 'targetType', 'targetId',
'targetCount'),
}, decider=PartialLoadDecider(
loader=MelSInt32(b'PTDT', u'targetType'),
decider=AttrValDecider(u'targetType'),
loader=MelSInt32(b'PTDT', 'targetType'),
decider=AttrValDecider('targetType'),
)),
MelConditionsTes4(),
)
Expand Down

0 comments on commit 7fb57e5

Please sign in to comment.