116 lines
5.2 KiB
Python
116 lines
5.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Check offered/active quest-menu types through both original native writers.
|
|
|
|
Source PrepareQuestMenu emits dialogue statuses2..5. The pinned native
|
|
Player menu producer uses type2 for details/acceptance and type4 for turn-in.
|
|
This includes the captured Tansy50315 regression: Source5 must not remain5.
|
|
"""
|
|
import argparse
|
|
from pathlib import Path
|
|
import struct
|
|
import subprocess
|
|
|
|
P = struct.pack
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('cli', type=Path)
|
|
parser.add_argument('--protocol-library', type=Path, required=True)
|
|
parser.add_argument('--build-dir', type=Path, required=True)
|
|
args = parser.parse_args()
|
|
root = Path(__file__).resolve().parents[1]
|
|
build = args.build_dir.resolve()
|
|
build.mkdir(parents=True, exist_ok=True)
|
|
driver = build / 'quest-menu-pure.cpp'
|
|
driver.write_text('''#include "gateway/gameplay.hpp"
|
|
#include "gateway/object_updates.hpp"
|
|
#include <iostream>
|
|
int main(){try {gateway::Bytes b;char c;while(std::cin.get(c))b.push_back(uint8_t(c));
|
|
gateway::Reader r(b);auto realm=r.le(2),map=r.le(4);
|
|
auto v=gateway::codec_gossip_menu(r.take(r.left()));
|
|
auto out=gateway::forever_gossip_menu(v,gateway::forever_creature_guid(v.guid,uint32_t(v.guid>>24)&0xFFFFFF,realm,map));
|
|
std::cout.write(reinterpret_cast<const char*>(out.data()),out.size());
|
|
}catch(const std::exception& e){std::cerr<<e.what();return 1;}}
|
|
''')
|
|
binary = build / 'quest-menu-pure'
|
|
subprocess.run(['c++', '-std=c++20', '-I' + str(root / 'include'), str(driver),
|
|
str(args.protocol_library.resolve()), '-lcrypto', '-lz', '-o', str(binary)],
|
|
check=True, capture_output=True)
|
|
|
|
|
|
def run(mode, data, accepted=True):
|
|
result = subprocess.run([str(args.cli.resolve()), mode], input=data, capture_output=True)
|
|
if accepted:
|
|
assert result.returncode == 0, result.stderr.decode(errors='replace')
|
|
else:
|
|
assert result.returncode != 0, 'Unsupported status was emitted as a native menu type'
|
|
return result.stdout
|
|
|
|
|
|
def packed_guid_end(data):
|
|
# Original ObjectGuid packed128 framing: two mask bytes, then present bytes.
|
|
return 2 + (data[0] | data[1] << 8).bit_count()
|
|
|
|
|
|
def menu_entries(data, gossip, broadcast_text=0):
|
|
at = packed_guid_end(data)
|
|
if gossip:
|
|
_, _, _, options, count = struct.unpack_from('<IIIII', data, at)
|
|
assert options == 0
|
|
at += 20
|
|
else:
|
|
_, _, count = struct.unpack_from('<III', data, at)
|
|
at += 12
|
|
entries = []
|
|
for _ in range(count):
|
|
quest, tuning, kind, info, *flags = struct.unpack_from('<IIIIIIII', data, at)
|
|
at += 32
|
|
title_bits = int.from_bytes(data[at:at + 2], 'big')
|
|
assert title_bits >> 12 == 0 # Native default repeatability/presentation flags.
|
|
length = title_bits >> 3 & 511
|
|
at += 2
|
|
title = data[at:at + length].decode()
|
|
at += length
|
|
assert tuning == info == 0 and flags == [0, 0, 0, 0]
|
|
entries.append((quest, kind, title))
|
|
if gossip:
|
|
# GossipMessage::Write writes RandomTextID and then BroadcastTextID presence.
|
|
trailer = P('<BI', 0x40, broadcast_text) if broadcast_text else b'\0'
|
|
assert data[at:] == trailer, 'Unexpected gossip text flags, title ID, or trailing bytes'
|
|
else:
|
|
bits = int.from_bytes(data[at:at + 2], 'big')
|
|
size = bits >> 5
|
|
at += 2
|
|
assert data[at:at + size] == b'Greeting' and at + size == len(data)
|
|
return entries
|
|
|
|
|
|
giver = 0xF13000C648273D00
|
|
native = bytes([11]) + b'\0' * 7 + bytes([48]) + b'\0' * 7
|
|
cases = [(2, 2), (3, 4), (4, 4), (5, 2)]
|
|
rows = [(50315 if source == 5 else 40000 + source, source, expected,
|
|
'Gadgetzan Times: BREAKING NEWS!' if source == 5 else f'Quest {source}')
|
|
for source, expected in cases]
|
|
source_rows = b''.join(P('<IIi', quest, source, 60) + title.encode() + b'\0'
|
|
for quest, source, _, title in rows)
|
|
source_list = P('<Q', giver) + b'Greeting\0' + P('<IIB', 0, 0, len(rows)) + source_rows
|
|
wrapped = P('<HI', 70, 0) + native + P('<HI', 0x185, 0) + source_list
|
|
expected = [(quest, kind, title) for quest, _, kind, title in rows]
|
|
assert menu_entries(run('--quest-packet', wrapped), False) == expected
|
|
gossip = P('<QIII', giver, 123, 0, len(rows)) + source_rows
|
|
for envelope, title in ((b'', 0), (P('<QI', 0, 0), 0), (P('<QI', 0, 2821), 2821)):
|
|
wire = P('<HI', 70, 0) + envelope + gossip
|
|
actual = run('--gossip-menu', wire)
|
|
assert menu_entries(actual, True, title) == expected
|
|
pure = subprocess.run([str(binary)], input=wire, capture_output=True, check=True).stdout
|
|
assert pure == actual, 'Protocol gossip writer differs from original native writer'
|
|
|
|
for status in (0, 1, 6, 7, 8, 100):
|
|
row = P('<IIi', 50315, status, 60) + b'Unsupported\0'
|
|
bad_list = P('<Q', giver) + b'Greeting\0' + P('<IIB', 0, 0, 1) + row
|
|
run('--quest-packet', P('<HI', 70, 0) + native + P('<HI', 0x185, 0) + bad_list, False)
|
|
bad_gossip = P('<HIQIII', 70, 0, giver, 123, 0, 1) + row
|
|
run('--gossip-menu', bad_gossip, False)
|
|
result = subprocess.run([str(binary)], input=bad_gossip, capture_output=True)
|
|
assert result.returncode != 0
|
|
|
|
print('4 Source menu statuses passed both writers with absent and resolved greetings; 6 unsupported statuses held.')
|