Skip to content

Commit a3a93e5

Browse files
committed
Address Cell Patcher Coordinate Reversal and Improper Comparison
1 parent 3318e87 commit a3a93e5

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
@@ -289,11 +289,12 @@ def importCellBlockData(cellBlock):
289289
if not cellBlock.cell.flags1.ignored:
290290
fid = cellBlock.cell.fid
291291
for attr in attrs:
292-
tempCellData[fid][attr] = cellBlock.cell.__getattribute__(
293-
attr)
292+
tempCellData[fid][attr] = (cellBlock.cell.__getattribute__(
293+
attr))
294294
for flg_ in flgs_:
295295
tempCellData[fid + ('flags',)][
296-
flg_] = cellBlock.cell.flags.__getattr__(flg_)
296+
flg_] = (cellBlock.cell.flags.__getattr__(flg_))
297+
297298
def checkMasterCellBlockData(cellBlock):
298299
"""
299300
Add attribute values from record(s) in master file(s).
@@ -313,7 +314,8 @@ def checkMasterCellBlockData(cellBlock):
313314
master_flag = cellBlock.cell.flags.__getattr__(flg_)
314315
if tempCellData[fid + ('flags',)][flg_] != master_flag:
315316
cellData[fid + ('flags',)][flg_] = \
316-
tempCellData[fid + ('flags',)][flg_]
317+
(tempCellData[fid + ('flags',)][flg_])
318+
317319
loadFactory = LoadFactory(False,MreRecord.type_class['CELL'],
318320
MreRecord.type_class['WRLD'])
319321
progress.setFull(len(self.srcs))
@@ -336,6 +338,7 @@ def checkMasterCellBlockData(cellBlock):
336338
# print bashTags
337339
tags = bashTags & set(self.recAttrs)
338340
if not tags: continue
341+
# adds tuples together, then takes the set
339342
attrs = set(chain.from_iterable(
340343
self.recAttrs[bashKey] for bashKey in tags))
341344
flgs_ = tuple(self.recFlags[bashKey] for bashKey in tags if
@@ -403,6 +406,18 @@ def scanModFile(self, modFile, progress): # scanModFile0
403406

404407
def buildPatch(self,log,progress): # buildPatch0
405408
"""Adds merged lists to patchfile."""
409+
410+
def regions_differ(patch_value, value_):
411+
"""
412+
Required for regions because comparing using `==` or `!=`
413+
results in false positives.
414+
"""
415+
sorted_patch_value = sorted(patch_value)
416+
sorted_value = sorted(value_)
417+
regions_compare = set(sorted_value).difference(
418+
sorted_patch_value)
419+
return (bool(regions_compare))
420+
406421
def handlePatchCellBlock(patchCellBlock):
407422
"""
408423
This function checks if an attribute or flag in CellData has
@@ -415,24 +430,24 @@ def handlePatchCellBlock(patchCellBlock):
415430
Modified cell Blocks are kept, the other are discarded.
416431
"""
417432
modified=False
418-
for attr,value in cellData[patchCellBlock.cell.fid].iteritems():
433+
for attr, value in cellData[patchCellBlock.cell.fid].viewitems():
419434
if attr == 'regions':
420-
if set(value).difference(set(patchCellBlock.cell.__getattribute__(attr))):
435+
if regions_differ(patchCellBlock.cell.__getattribute__(attr), value):
421436
patchCellBlock.cell.__setattr__(attr, value)
422437
modified = True
423-
else:
424-
if patchCellBlock.cell.__getattribute__(attr) != value:
425-
patchCellBlock.cell.__setattr__(attr, value)
426-
modified=True
438+
elif patchCellBlock.cell.__getattribute__(attr) != value:
439+
patchCellBlock.cell.__setattr__(attr, value)
440+
modified = True
427441
for flag, value in cellData[
428-
patchCellBlock.cell.fid + ('flags',)].iteritems():
442+
patchCellBlock.cell.fid + ('flags',)].viewitems():
429443
if patchCellBlock.cell.flags.__getattr__(flag) != value:
430444
patchCellBlock.cell.flags.__setattr__(flag, value)
431445
modified=True
432446
if modified:
433447
patchCellBlock.cell.setChanged()
434448
keep(patchCellBlock.cell.fid)
435449
return modified
450+
436451
if not self.isActive: return
437452
keep = self.patchFile.getKeeper()
438453
cellData, count = self.cellData, Counter()
@@ -442,10 +457,10 @@ def handlePatchCellBlock(patchCellBlock):
442457
for worldBlock in self.patchFile.WRLD.worldBlocks:
443458
keepWorld = False
444459
for cellBlock in worldBlock.cellBlocks:
445-
if cellBlock.cell.fid in cellData and handlePatchCellBlock(
446-
cellBlock):
447-
count[cellBlock.cell.fid[0]] += 1
448-
keepWorld = True
460+
if cellBlock.cell.fid in cellData:
461+
if handlePatchCellBlock(cellBlock):
462+
count[cellBlock.cell.fid[0]] += 1
463+
keepWorld = True
449464
if worldBlock.worldCellBlock:
450465
if worldBlock.worldCellBlock.cell.fid in cellData:
451466
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)