45 lines
2.4 KiB
Python
45 lines
2.4 KiB
Python
"""Stage the published Classic 70291 PartyUpdate writer for the standalone 70334 codec."""
|
|
import hashlib
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
from tempfile import TemporaryDirectory
|
|
|
|
from codec_build_cache import write_changed
|
|
|
|
|
|
def prepare(forever, output):
|
|
packets = forever / 'src/server/game/Server/Packets'
|
|
upstream = '3b77f715f40e2052f9fe9aedb2cde5e77aeeaae5'
|
|
source_hashes = {
|
|
'PartyPackets.cpp': ('7ea6a56baa1e05bcc14aa7fdce76c98c1e0de935a1fe0f18289fe08aad099468',
|
|
'2d40bc2e176916b65949e2b4a53e1291df74096c36663528c1cf33bd631498ef'),
|
|
'PartyPackets.h': ('d70c5b14775c9ab1fef7b7b372b2bf54910cc65e0f538dd348114fc097e52bbd',
|
|
'2ec2d7c6212658569efd1e6efa3cf0a28423870de01dde1a8759fa0040ab32a0'),
|
|
}
|
|
patch = Path(__file__).resolve().parent / 'data/classic-party-update-70291.patch'
|
|
staged = output / 'party-70291'
|
|
staged.mkdir(exist_ok=True)
|
|
with TemporaryDirectory(dir=output) as scratch:
|
|
for name, (original, _) in source_hashes.items():
|
|
path = packets / name
|
|
if hashlib.sha256(path.read_bytes()).hexdigest() != original:
|
|
raise ValueError(f'Unexpected pinned Trinity source: {name}')
|
|
shutil.copyfile(path, Path(scratch) / name)
|
|
subprocess.run(['patch', '--batch', '--fuzz=0', '-s', '-p1', '-i', str(patch)], cwd=scratch, check=True)
|
|
for name, (_, expected) in source_hashes.items():
|
|
data = (Path(scratch) / name).read_bytes()
|
|
if hashlib.sha256(data).hexdigest() != expected:
|
|
raise ValueError(f'Classic PartyUpdate writer differs from {upstream}: {name}')
|
|
text = data.decode()
|
|
if name == 'PartyPackets.h':
|
|
# The standalone 70334 codec has one build and has no worldserver realm configuration.
|
|
selector = 'bool Classic70291 = ClassicOpcodes::IsBuild70291OrLater();'
|
|
if text.count(selector) != 1:
|
|
raise ValueError('Missing PartyUpdate realm-build selector')
|
|
text = text.replace(selector, 'bool Classic70291 = true;')
|
|
write_changed(staged / name, text)
|
|
return staged, {'upstream': upstream, 'build': 70334, 'upstream_inputs_and_outputs': source_hashes,
|
|
'compiled_files': {name: hashlib.sha256((staged / name).read_bytes()).hexdigest()
|
|
for name in source_hashes}}
|