Skip to content

Commit c9cea91

Browse files
committed
Address Cell Patcher Coordinate Reversal and Improper Comparison
1 parent 98d6a9d commit c9cea91

2 files changed

Lines changed: 33 additions & 17 deletions

File tree

Mopy/bash/patcher/patchers/importers.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,12 @@ def importCellBlockData(cellBlock):
293293
if not cellBlock.cell.flags1.ignored:
294294
fid = cellBlock.cell.fid
295295
for attr in attrs:
296-
tempCellData[fid][attr] = cellBlock.cell.__getattribute__(
297-
attr)
296+
tempCellData[fid][attr] = (cellBlock.cell.__getattribute__(
297+
attr))
298298
for flg_ in flgs_:
299299
tempCellData[fid + ('flags',)][
300-
flg_] = cellBlock.cell.flags.__getattr__(flg_)
300+
flg_] = (cellBlock.cell.flags.__getattr__(flg_))
301+
301302
def checkMasterCellBlockData(cellBlock):
302303
"""
303304
Add attribute values from record(s) in master file(s).
@@ -317,7 +318,8 @@ def checkMasterCellBlockData(cellBlock):
317318
master_flag = cellBlock.cell.flags.__getattr__(flg_)
318319
if tempCellData[fid + ('flags',)][flg_] != master_flag:
319320
cellData[fid + ('flags',)][flg_] = \
320-
tempCellData[fid + ('flags',)][flg_]
321+
(tempCellData[fid + ('flags',)][flg_])
322+
321323
loadFactory = LoadFactory(False,MreRecord.type_class['CELL'],
322324
MreRecord.type_class['WRLD'])
323325
progress.setFull(len(self.srcs))
@@ -340,6 +342,7 @@ def checkMasterCellBlockData(cellBlock):
340342
# print bashTags
341343
tags = bashTags & set(self.recAttrs)
342344
if not tags: continue
345+
# adds tuples together, then takes the set
343346
attrs = set(chain.from_iterable(
344347
self.recAttrs[bashKey] for bashKey in tags))
345348
flgs_ = tuple(self.recFlags[bashKey] for bashKey in tags if
@@ -407,6 +410,18 @@ def scanModFile(self, modFile, progress): # scanModFile0
407410

408411
def buildPatch(self,log,progress): # buildPatch0
409412
"""Adds merged lists to patchfile."""
413+
414+
def regions_differ(patch_value, value_):
415+
"""
416+
Required for regions because comparing using `==` or `!=`
417+
results in false positives.
418+
"""
419+
sorted_patch_value = sorted(patch_value)
420+
sorted_value = sorted(value_)
421+
regions_compare = set(sorted_value).difference(
422+
sorted_patch_value)
423+
return (bool(regions_compare))
424+
410425
def handlePatchCellBlock(patchCellBlock):
411426
"""
412427
This function checks if an attribute or flag in CellData has
@@ -419,24 +434,24 @@ def handlePatchCellBlock(patchCellBlock):
419434
Modified cell Blocks are kept, the other are discarded.
420435
"""
421436
modified=False
422-
for attr,value in cellData[patchCellBlock.cell.fid].iteritems():
437+
for attr, value in cellData[patchCellBlock.cell.fid].viewitems():
423438
if attr == 'regions':
424-
if set(value).difference(set(patchCellBlock.cell.__getattribute__(attr))):
439+
if regions_differ(patchCellBlock.cell.__getattribute__(attr), value):
425440
patchCellBlock.cell.__setattr__(attr, value)
426441
modified = True
427-
else:
428-
if patchCellBlock.cell.__getattribute__(attr) != value:
429-
patchCellBlock.cell.__setattr__(attr, value)
430-
modified=True
442+
elif patchCellBlock.cell.__getattribute__(attr) != value:
443+
patchCellBlock.cell.__setattr__(attr, value)
444+
modified = True
431445
for flag, value in cellData[
432-
patchCellBlock.cell.fid + ('flags',)].iteritems():
446+
patchCellBlock.cell.fid + ('flags',)].viewitems():
433447
if patchCellBlock.cell.flags.__getattr__(flag) != value:
434448
patchCellBlock.cell.flags.__setattr__(flag, value)
435449
modified=True
436450
if modified:
437451
patchCellBlock.cell.setChanged()
438452
keep(patchCellBlock.cell.fid)
439453
return modified
454+
440455
if not self.isActive: return
441456
keep = self.patchFile.getKeeper()
442457
cellData, count = self.cellData, Counter()
@@ -446,10 +461,10 @@ def handlePatchCellBlock(patchCellBlock):
446461
for worldBlock in self.patchFile.WRLD.worldBlocks:
447462
keepWorld = False
448463
for cellBlock in worldBlock.cellBlocks:
449-
if cellBlock.cell.fid in cellData and handlePatchCellBlock(
450-
cellBlock):
451-
count[cellBlock.cell.fid[0]] += 1
452-
keepWorld = True
464+
if cellBlock.cell.fid in cellData:
465+
if handlePatchCellBlock(cellBlock):
466+
count[cellBlock.cell.fid[0]] += 1
467+
keepWorld = True
453468
if worldBlock.worldCellBlock:
454469
if worldBlock.worldCellBlock.cell.fid in cellData:
455470
if handlePatchCellBlock(worldBlock.worldCellBlock):

Mopy/bash/record_groups.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,12 @@ def getBsb(self):
482482
baseFid = cell.fid & 0x00FFFFFF
483483
return baseFid%10, baseFid%100//10
484484
#--Exterior cell
485+
# Grup Coord are reversed for Exteriors
485486
else:
486-
x,y = cell.posY,cell.posX
487+
x,y = cell.posX,cell.posY
487488
if x is None: x = 0
488489
if y is None: y = 0
489-
return (x//32, y//32), (x//8, y//8)
490+
return (y//32, x//32), (y//8, x//8)
490491

491492
def dump(self,out):
492493
"""Dumps group header and then records."""

0 commit comments

Comments
 (0)