883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
307 lines
18 KiB
Python
307 lines
18 KiB
Python
"""Map/MapDifficulty hotfix-row boundary: pointer-only override, refusals,
|
|
MapDifficulty framing and package push recomputation. Synthetic rows only."""
|
|
import copy
|
|
import hashlib
|
|
import struct
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / 'ops'))
|
|
import map_row_compat as m # noqa: E402
|
|
import item_sparse_compat as composer # noqa: E402
|
|
|
|
NATIVE43 = {
|
|
'ID': 43, 'Directory': 'WailingCaverns', 'MapName_lang': 'Wailing Caverns',
|
|
'MapDescription0_lang': '', 'MapDescription1_lang': '', 'PvpShortDescription_lang': '',
|
|
'PvpLongDescription_lang': '', 'Corpse': [-740.5, -2214.25], 'MapType': 2, 'InstanceType': 1,
|
|
'ExpansionID': 0, 'AreaTableID': 718, 'LoadingScreenID': 25, 'TimeOfDayOverride': -1,
|
|
'ParentMapID': -1, 'CosmeticParentMapID': -1, 'TimeOffset': 0, 'MinimapIconScale': 1.0,
|
|
'CorpseMapID': 1, 'MaxPlayers': 5, 'WindSettingsID': 0, 'ZmpFileDataID': 0,
|
|
'WdtFileDataID': 791429, 'OceanLiquidTypeID': 2, 'NavigationMaxDistance': 0,
|
|
'PreloadFileDataID': 0, 'Flags': [1, 0, 0],
|
|
}
|
|
|
|
|
|
class MapRowCompatTest(unittest.TestCase):
|
|
def test_pointer_override_changes_only_wdt(self):
|
|
row = m.wdt_override_row(NATIVE43, 8567803, {8567803})
|
|
body = bytes.fromhex(row['wire_hex'])
|
|
original = m.encode(NATIVE43, m.MAP_SCHEMA)
|
|
self.assertEqual(len(body), len(original))
|
|
self.assertLessEqual(sum(a != b for a, b in zip(body, original)), 4)
|
|
decoded = m.decode(body, m.MAP_SCHEMA, 43)
|
|
self.assertEqual(decoded['WdtFileDataID'], 8567803)
|
|
self.assertEqual({k: v for k, v in decoded.items() if k != 'WdtFileDataID'},
|
|
{k: v for k, v in NATIVE43.items() if k != 'WdtFileDataID'})
|
|
self.assertEqual(row['sha256'], hashlib.sha256(body).hexdigest())
|
|
self.assertEqual(int(row['table_hash'], 16), 0xBD84CD62)
|
|
|
|
def test_refuses_absent_or_missing_wdt(self):
|
|
with self.assertRaises(ValueError):
|
|
m.wdt_override_row(NATIVE43, 8567803, {1})
|
|
with self.assertRaises(ValueError):
|
|
m.wdt_override_row(NATIVE43, 0, None)
|
|
with self.assertRaises(ValueError):
|
|
m.source_only_map_row(NATIVE43, {'InstanceType': 1}, 0)
|
|
|
|
def test_source_only_and_difficulty_framing(self):
|
|
source = dict(ID=820, Directory='MooCanyon', MapName_lang='Windhorn Canyon', InstanceType=1,
|
|
AreaTableID=5641, LoadingScreenID=25, MaxPlayers=5)
|
|
row = m.source_only_map_row(NATIVE43, source, 9000001, {9000001})
|
|
decoded = m.decode(bytes.fromhex(row['wire_hex']), m.MAP_SCHEMA, 820)
|
|
self.assertEqual((decoded['Directory'], decoded['WdtFileDataID'], decoded['CorpseMapID']),
|
|
('MooCanyon', 9000001, -1))
|
|
diff = m.map_difficulty_row(900001, 820, 1, 5)
|
|
body = bytes.fromhex(diff['wire_hex'])
|
|
self.assertEqual(len(body), 37) # '' + 4+2+4+1+4+1+4+4+4+4+4
|
|
self.assertEqual(int.from_bytes(body[1:5], 'little'), 900001) # inline ID first
|
|
self.assertEqual(int.from_bytes(body[-4:], 'little'), 820) # relation last
|
|
self.assertEqual(m.decode(body, m.MAP_DIFFICULTY_SCHEMA)['DifficultyID'], 1)
|
|
|
|
def test_merge_recomputes_push_and_refuses_duplicates(self):
|
|
base_row = m.wdt_override_row(NATIVE43, 8567803, None)
|
|
package = {'rows': [base_row], 'push_id': 0, 'pushes': []}
|
|
new = m.map_difficulty_row(900001, 820, 1, 5)
|
|
merged, _, _ = m.merge_rows(package, [new])
|
|
self.assertEqual(merged['push_id'], composer.package_payloads(merged['rows'])[0])
|
|
self.assertEqual(merged['pushes'], composer.package_pages(merged['rows']))
|
|
with self.assertRaises(ValueError):
|
|
m.merge_rows(merged, [new])
|
|
audit = m.audit_map_rows(merged['rows'], set(), {43: NATIVE43})
|
|
self.assertEqual(audit, [{'MapID': 43, 'native_wdt': 791429, 'wdt': 8567803, 'resident': False}])
|
|
|
|
def test_source_area_add_and_native_bit_only_replacement(self):
|
|
fields = m.AREA_TABLE_SCHEMA
|
|
native = {name: ('' if kind in ('string', 'locstring') else 0.0 if kind == 'float'
|
|
else [0] * count if count > 1 else 0)
|
|
for name, kind, _bits, _unsigned, count in fields}
|
|
native.update(ID=12, ZoneName='NativeZone', AreaName_lang='Native Area', AreaBit=1157,
|
|
PvpCombatWorldStateID=-1)
|
|
replacement = dict(native, ID=900)
|
|
aliases = {'AreaName_lang': 'AreaName', 'Ambient_multiplier': 'AmbientMultiplier'}
|
|
add = {aliases.get(name, name): copy.deepcopy(native[name]) for name, *_ in fields}
|
|
add.update(op='add', ID=2038, template_native_area=12, ZoneName='SourceZone',
|
|
AreaName='Source Area', AreaBit=796)
|
|
spec = {'source': 'patch-5.mpq', 'contract': 'synthetic-native-boundary',
|
|
'field_order': [aliases.get(name, name) for name, *_ in fields],
|
|
'adds': [add], 'bit_fixes': [dict(op='replace', ID=900, AreaBit=1066,
|
|
native_AreaBit=1157, note='source')],
|
|
'bit_clash_with_native_only_areas': []}
|
|
rows, _ = m.source_area_hotfix_rows(spec, {12: native, 900: replacement})
|
|
self.assertEqual([row['id'] for row in rows], [2038, 900])
|
|
self.assertEqual(m.decode(bytes.fromhex(rows[0]['wire_hex']), fields, 2038)['AreaBit'], 796)
|
|
old = m.encode(replacement, fields)
|
|
new = bytes.fromhex(rows[1]['wire_hex'])
|
|
offset = len('NativeZone') + len('Native Area') + 6
|
|
self.assertEqual(old[:offset] + old[offset + 2:], new[:offset] + new[offset + 2:])
|
|
self.assertEqual(m.decode(new, fields, 900)['AreaBit'], 1066)
|
|
self.assertEqual(replacement['AreaBit'], 1157)
|
|
|
|
def test_source_wmo_room_copy_keeps_signed_group_and_neutral_audio(self):
|
|
source = [111, 58, 2, 0xffffffff, 0xffffffff, 11, 50, 204, 0, 0, 2038]
|
|
source += [1] + [0] * 8
|
|
strings = b'\0Source Inn\0'
|
|
raw = (struct.pack('<4s4I', b'WDBC', 1, 20, 80, len(strings))
|
|
+ struct.pack('<20I', *source) + strings)
|
|
spec = {'chained_on': '-mapsZ48G', 'classes': ['C', 'D'],
|
|
'source_wmoareatable': {'fields': 20},
|
|
'wmoareatable_copy': [dict(new_wmoid=40000, old_wmoid=58,
|
|
source_row=source, source_path='world\\inn.wmo')]}
|
|
rows, _ = m.source_wmo_area_copy_rows(spec, raw, {149232}, {2038})
|
|
self.assertEqual(len(rows), 1)
|
|
row = rows[0]
|
|
self.assertEqual((row['id'], row['record']['AreaName_lang'], row['record']['WmoGroupID']),
|
|
(200000, 'Source Inn', -1))
|
|
decoded = m.decode(bytes.fromhex(row['wire_hex']), m.WMO_AREA_SCHEMA)
|
|
self.assertEqual((decoded['ID'], decoded['WmoID'], decoded['NameSetID'],
|
|
decoded['AreaTableID'], decoded['SoundProviderPref']),
|
|
(200000, 40000, 2, 2038, 0))
|
|
with self.assertRaises(ValueError):
|
|
m.source_wmo_area_copy_rows(spec, raw, {149232}, set())
|
|
|
|
# The next Source batch appends A/B roots after the retained C/D IDs.
|
|
spec.update(chained_on='-mapsZ49D', classes=['A', 'B'],
|
|
wmoid_block=[40000, 40148])
|
|
spec['wmoareatable_copy'][0]['new_wmoid'] = 40074
|
|
rows, _ = m.source_wmo_area_copy_rows(spec, raw, {149232, 205727},
|
|
{2038}, first_id=205728)
|
|
decoded = m.decode(bytes.fromhex(rows[0]['wire_hex']), m.WMO_AREA_SCHEMA)
|
|
self.assertEqual((decoded['ID'], decoded['WmoID'], decoded['WmoGroupID'],
|
|
decoded['AreaName_lang'], decoded['AreaTableID'], decoded['ZoneMusic']),
|
|
(205728, 40074, -1, 'Source Inn', 2038, 0))
|
|
with self.assertRaises(ValueError):
|
|
m.source_wmo_area_copy_rows(spec, raw, {205728}, {2038}, first_id=205728)
|
|
|
|
def test_source_dbc_and_source_only_rows(self):
|
|
strings = b'\0MooCanyon\0Windhorn Canyon\0'
|
|
record = [0] * 42
|
|
record[:5] = [820, 1, 1, 0, 11]
|
|
record[15], record[19], record[38] = 0, 5641, 525
|
|
raw = (struct.pack('<4s4I', b'WDBC', 1, 42, 168, len(strings))
|
|
+ struct.pack('<42I', *record) + strings)
|
|
source = m.source_map_dbc(raw)[820]
|
|
self.assertEqual((source['Directory'], source['MapName_lang'], source['LoadingScreenID']),
|
|
('MooCanyon', 'Windhorn Canyon', 525))
|
|
template = dict(NATIVE43, ID=33, LoadingScreenID=204, MaxPlayers=10)
|
|
row, diff = m.source_only_rows(source, template, 8571008, 6346, {8571008},
|
|
known_areas=set(), known_loading_screens={525})
|
|
decoded = m.decode(bytes.fromhex(row['wire_hex']), m.MAP_SCHEMA, 820)
|
|
self.assertEqual((decoded['AreaTableID'], decoded['LoadingScreenID'], decoded['MaxPlayers'],
|
|
decoded['WdtFileDataID']), (0, 525, 10, 8571008))
|
|
self.assertEqual((diff['id'], diff['record']['MapID'], diff['record']['DifficultyID']), (6346, 820, 1))
|
|
with self.assertRaises(ValueError):
|
|
m.source_only_rows(source, template, 8571008, 6346, {1})
|
|
|
|
|
|
def test_source_area_rows_for_source_only_maps(self):
|
|
import json
|
|
A = ROOT / 'runtime/rea-system-jobs-20261022/map-zone-definition-closure-20261024'
|
|
schema_path = ROOT / 'tests/fixtures/map-area-native-encoder-schema.json'
|
|
if not (A / 'native70334-AreaTable-full.json').exists():
|
|
self.skipTest('pinned native AreaTable export absent')
|
|
native = {r['ID']: r for r in json.loads((A / 'native70334-AreaTable-full.json').read_text())}
|
|
schema = json.loads(schema_path.read_text())['AreaTable']['fields']
|
|
names = [b'Windhorn Canyon'] + [b''] * 7
|
|
strings = b'\0' + b'\0'.join(names[:1]) + b'\0'
|
|
fields = [5641, 820, 0, 1535, 0x40, 0, 0, 0, 0, 0, 25] + [1] + [0] * 7 + [0, 0, 0, 0, 0, 0]
|
|
raw = struct.pack('<4s4I', b'WDBC', 1, 25, 100, len(strings)) + struct.pack('<25I', *fields) + strings
|
|
src = m.source_area_dbc(raw)
|
|
self.assertEqual(src[5641]['AreaName_lang'], 'Windhorn Canyon')
|
|
rows, held = m.owned_map_area_rows(src, {5641, 9999, 44}, native, schema, {820})
|
|
self.assertEqual([r['id'] for r in rows], [5641])
|
|
self.assertEqual(held, [{'AreaID': 9999, 'reason': 'no Source AreaTable row'}])
|
|
rec = rows[0]['record']
|
|
self.assertEqual((rec['ContinentID'], rec['ParentAreaID'], rec['AreaName_lang'], rec['ZoneName']),
|
|
(820, 0, 'Windhorn Canyon', 'WoWHybridArea_5641'))
|
|
self.assertEqual(int(rows[0]['table_hash'], 16), m.AREA_TABLE)
|
|
self.assertEqual(rows[0]['sha256'], hashlib.sha256(bytes.fromhex(rows[0]['wire_hex'])).hexdigest())
|
|
_, held = m.owned_map_area_rows(src, {5641}, native, schema, {819})
|
|
self.assertEqual(held[0]['AreaID'], 5641)
|
|
|
|
def test_area_table_id_update_changes_only_that_field(self):
|
|
row = m.wdt_override_row(NATIVE43, 8567803, {8567803})
|
|
new = m.with_area_table_id(row, 5641)
|
|
decoded = m.decode(bytes.fromhex(new['wire_hex']), m.MAP_SCHEMA, 43)
|
|
self.assertEqual(decoded['AreaTableID'], 5641)
|
|
self.assertEqual({k: v for k, v in decoded.items() if k != 'AreaTableID'},
|
|
{k: v for k, v in row['record'].items() if k != 'AreaTableID'})
|
|
|
|
class WorldMapRowCompatTest(unittest.TestCase):
|
|
# Native DB2Metadata/DB2StorageBase::WriteRecord framing, with nonzero
|
|
# values and negative sentinels to catch shifted or incorrectly signed
|
|
# fields. The expected bytes below are independent struct layouts.
|
|
def setUp(self):
|
|
self.spec = {'tables': {
|
|
'UiMap': [dict(op='add', ID=9001, Name='A New Isle', ParentUiMapID=1414, Flags=2,
|
|
System=0, Type=3, BountySetID=-1, BountyDisplayLocation=7,
|
|
VisibilityPlayerConditionID=-2, HelpTextPosition=-3, BkgAtlasID=4,
|
|
AlternateUiMapGroup=5, ContentTuningID=6, AdventureMapTextureKitID=8,
|
|
MapArtZoneTextPosition=-4)],
|
|
'UiMapAssignment': [dict(op='add', ID=90001, UiMin=[0., 0.], UiMax=[1., 1.],
|
|
Region=[-10., -20., -1000000., 30., 40., 1000000.],
|
|
UiMapID=9001, OrderIndex=-1, MapID=1, AreaID=5024,
|
|
WmoDoodadPlacementID=-2, WmoGroupID=-3, Unknown1125=-4)],
|
|
'UiMapXMapArt': [dict(op='replace', ID=2412, PhaseID=0, UiMapArtID=3015, UiMapID=1414)]}}
|
|
self.native = {'UiMap': {1414}, 'UiMapAssignment': {69032}, 'UiMapXMapArt': {2412}}
|
|
|
|
def test_worldmap_native_framing_and_same_id_replacement(self):
|
|
rows, audit = m.worldmap_rows(self.spec, self.native, {3015})
|
|
expected = [b'A New Isle\0' + struct.pack('<IIiBBiIibi iiib'.replace(' ', ''),
|
|
9001, 1414, 2, 0, 3, -1, 7, -2, -3, 4, 5, 6, 8, -4),
|
|
struct.pack('<10fIIiiiiii', 0., 0., 1., 1., -10., -20., -1000000.,
|
|
30., 40., 1000000., 90001, 9001, -1, 1, 5024, -2, -3, -4),
|
|
struct.pack('<iiI', 0, 3015, 1414)]
|
|
self.assertEqual([bytes.fromhex(r['wire_hex']) for r in rows], expected)
|
|
self.assertEqual([r['table_hash'] for r in rows], ['0x89927BF7', '0x5153A338', '0xADB3FC8C'])
|
|
self.assertEqual([a['bytes'] for a in audit], [len(b'A New Isle\0') + 44, 72, 12])
|
|
old = dict(rows[2], record=dict(rows[2]['record'], UiMapArtID=1000),
|
|
wire_hex=struct.pack('<iiI', 0, 1000, 1414).hex())
|
|
old['sha256'] = hashlib.sha256(bytes.fromhex(old['wire_hex'])).hexdigest()
|
|
merged, _, replaced = m.merge_rows({'rows': [old]}, rows, replace=True)
|
|
self.assertEqual(replaced, [(0xADB3FC8C, 2412)])
|
|
self.assertEqual(len(merged['rows']), 3)
|
|
self.assertEqual(merged['rows'][0]['wire_hex'], expected[2].hex())
|
|
self.assertEqual(merged['push_id'], composer.package_payloads(merged['rows'])[0])
|
|
|
|
def test_worldmap_identity_and_relationship_refusals(self):
|
|
for table, field, value in [('UiMap', 'op', 'replace'),
|
|
('UiMapXMapArt', 'op', 'add'),
|
|
('UiMap', 'ParentUiMapID', 9999),
|
|
('UiMapAssignment', 'UiMapID', 9999),
|
|
('UiMapXMapArt', 'UiMapArtID', 9999),
|
|
('UiMap', 'Type', 3.5)]:
|
|
spec = copy.deepcopy(self.spec)
|
|
spec['tables'][table][0][field] = value
|
|
with self.subTest(table=table, field=field), self.assertRaises(ValueError):
|
|
m.worldmap_rows(spec, self.native, {3015})
|
|
for art in (4096, 9001):
|
|
spec = copy.deepcopy(self.spec)
|
|
spec['tables']['UiMapXMapArt'][0]['UiMapArtID'] = art
|
|
with self.subTest(art=art), self.assertRaisesRegex(ValueError, 'compact reference bound'):
|
|
m.worldmap_rows(spec, self.native, {art})
|
|
spec = copy.deepcopy(self.spec)
|
|
spec['tables']['UiMap'].append(spec['tables']['UiMap'][0])
|
|
with self.assertRaises(ValueError):
|
|
m.worldmap_rows(spec, self.native, {3015})
|
|
|
|
def test_worldmap_assignment_bounds_and_array_widths(self):
|
|
for region in ([30., -20., -1000000., -10., 40., 1000000.],
|
|
[-10., -20., float('nan'), 30., 40., 1000000.],
|
|
[-10., -20., -1000000., 30., 40.]):
|
|
spec = copy.deepcopy(self.spec)
|
|
spec['tables']['UiMapAssignment'][0]['Region'] = region
|
|
with self.subTest(region=region), self.assertRaises(ValueError):
|
|
m.worldmap_rows(spec, self.native, {3015})
|
|
|
|
|
|
class TaxiNodesTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.node = dict(ID=82, Name='Ambershire', Pos=[-7576.0, 782.5, 40.0],
|
|
MapOffset=[0.0, 0.0], FlightMapOffset=[0.0, 0.0],
|
|
ContinentID=0, ConditionID=0, CharacterBitNumber=82,
|
|
Flags=1025, UiTextureKitID=0, MinimapAtlasMemberID=4689,
|
|
Facing=0.0, SpecialIconConditionID=0, VisibilityConditionID=0,
|
|
MountCreatureID=[0, 541], op='add', native_was=None)
|
|
|
|
def test_native_write_record_order_inline_id_and_replacement(self):
|
|
rows, audit = m.taxi_nodes_rows([self.node], {1}, {1, 82})
|
|
body = bytes.fromhex(rows[0]['wire_hex'])
|
|
expected = b'Ambershire\0' + struct.pack(
|
|
'<7fIHiHiiifII2i', -7576.0, 782.5, 40.0, 0.0, 0.0, 0.0, 0.0,
|
|
82, 0, 0, 82, 1025, 0, 4689, 0.0, 0, 0, 0, 541)
|
|
self.assertEqual(body, expected)
|
|
self.assertEqual(rows[0]['table_hash'], '0x50D91A78')
|
|
self.assertEqual(audit[0]['op'], 'add')
|
|
replacement = dict(self.node, op='replace', native_was='older name')
|
|
replaced, _ = m.taxi_nodes_rows([replacement], {82}, {82})
|
|
self.assertEqual(replaced[0]['wire_hex'], rows[0]['wire_hex'])
|
|
self.assertEqual(replaced[0]['id'], 82)
|
|
self.assertEqual(replaced[0]['policy'], 'source-taxi-node-replace-v1')
|
|
|
|
def test_identity_mounts_bitmask_and_extent_refusals(self):
|
|
mutations = [dict(ID=0), dict(op='replace'), dict(ContinentID=30),
|
|
dict(CharacterBitNumber=81), dict(Flags=1026),
|
|
dict(MountCreatureID=[541, 0]), dict(MountCreatureID=[0]),
|
|
dict(ConditionID=0.0), dict(Pos=[float('nan'), 0.0, 0.0]),
|
|
dict(Name=''), dict(Name='bad\0name')]
|
|
for change in mutations:
|
|
with self.subTest(change=change), self.assertRaises(ValueError):
|
|
m.taxi_nodes_rows([dict(self.node, **change)], {1}, {1, 82})
|
|
with self.assertRaises(ValueError):
|
|
m.taxi_nodes_rows([self.node, self.node], {1}, {1, 82})
|
|
with self.assertRaises(ValueError):
|
|
m.taxi_nodes_rows([self.node], {1}, {1, 82, 83})
|
|
|
|
def test_transport_flags_do_not_grant_faction_or_discovery(self):
|
|
transport = dict(self.node, Pos=[0.0, 0.0, 0.0], Flags=1024,
|
|
MountCreatureID=[2224, 541])
|
|
rows, _ = m.taxi_nodes_rows([transport], {1}, {1, 82})
|
|
self.assertEqual(rows[0]['record']['Flags'], 1024)
|
|
self.assertEqual(rows[0]['record']['CharacterBitNumber'], 82)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|