367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
75 lines
6.2 KiB
Python
75 lines
6.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Reversible real original-UI armor swap using explicitly owned test items.
|
|
|
|
No item grants, SQL writes or simulated equipment state. Source item/slot and
|
|
exact original inventory baseline are checked; only original client /use actions.
|
|
"""
|
|
import argparse,json
|
|
from pathlib import Path
|
|
from client_session import Session
|
|
import client_ui as ui
|
|
from native_engine_character_test import ROOT,Controller,local_listeners
|
|
from native_test_guard import require_local_turtle_ports,require_authenticated_turtle_realm,require_native_gameplay_policy
|
|
from native_world_trace import WorldTrace
|
|
from local_tortoise import db
|
|
from native_vendor_buy_test import inventory,rows
|
|
|
|
def main():
|
|
p=argparse.ArgumentParser(description=__doc__)
|
|
for name in ('character','item','original','slot','root','health','max-health'):p.add_argument('--'+name,type=int,required=True)
|
|
p.add_argument('--merchant-closed',action='store_true',required=True,help='Required explicit confirmation of reviewed original UI state')
|
|
p.add_argument('--output',type=Path,required=True);a=p.parse_args();out=a.output.resolve()
|
|
if not out.is_relative_to(ROOT/'runtime') or out.exists() or not out.parent.is_dir() or not 0<a.character<2**32 or not 0<a.item<2**32 or not 0<a.original<2**32 or not 0<=a.slot<19 or not 23<=a.root<39 or not 0<a.health<=a.max_health<1000000:p.error('Require new runtime report and explicit bounded source fixture')
|
|
require_local_turtle_ports(local_listeners());c=Controller(int((ROOT/'runtime/native-client.pid').read_text()));require_authenticated_turtle_realm(c.rpc('inspect-wire-account'));require_native_gameplay_policy(c.rpc('inspect-native-channel-policy'))
|
|
baseline=inventory(a.character);before=rows(baseline)
|
|
one=lambda guid:[r for r in before if int(r[2])==guid]
|
|
if len(one(a.item))!=1 or one(a.item)[0][:2]!=['0',str(a.root)] or len(one(a.original))!=1 or one(a.original)[0][:2]!=['0',str(a.slot)]:raise RuntimeError('Owned fixture differs; no input')
|
|
character=db(f'SELECT health,money FROM tw_char.characters WHERE guid={a.character};')
|
|
if int(character.split('\t')[0])!=a.health:raise RuntimeError('Saved health differs; no input')
|
|
report=dict(pid=c.pid,external_gateway_running=False,baseline_inventory=baseline,baseline_character=character,restoration_pending=False,ui_review_required=True);changed=False;failure=None;old=ui.KEY_DELAY
|
|
def equipped():return db(f'SELECT item FROM tw_char.character_inventory WHERE guid={a.character} AND bag=0 AND slot={a.slot};')
|
|
with WorldTrace(c) as trace:
|
|
try:
|
|
with Session(c.pid) as s:
|
|
if s.state()!='world':raise RuntimeError('World required')
|
|
ui.KEY_DELAY=.03
|
|
# Merchant closure can also close auto-open bags. Use the
|
|
# previously verified original /use bag-slot action instead of
|
|
# assuming a still-visible item icon at fixed coordinates.
|
|
s.shot(out.with_name(out.stem+'-before.png'))
|
|
changed=True;report['restoration_pending']=True
|
|
s.macro(f'/use 0 {a.root-22}');s.macro('/s .save');c.wait(lambda:equipped()==str(a.item),8)
|
|
report['equipped_inventory']=inventory(a.character);report['equipped_character']=db(f'SELECT health,money FROM tw_char.characters WHERE guid={a.character};')
|
|
s.macro(f'/run print("GW armor equipped",GetInventoryItemID("player",{a.slot+1}),UnitHealth("player"),UnitHealthMax("player"))');s.shot(out.with_suffix('.png'))
|
|
except Exception as error:failure=type(error).__name__+': '+str(error)
|
|
finally:
|
|
try:
|
|
if changed:
|
|
with Session(c.pid) as s:
|
|
if s.state()!='world':raise RuntimeError('World lost; preserve fixture evidence')
|
|
ui.KEY_DELAY=.03
|
|
if equipped()==str(a.item):
|
|
actual=db(f'SELECT bag,slot FROM tw_char.character_inventory WHERE guid={a.character} AND item={a.original};')
|
|
if actual!=f'0\t{a.root}':raise RuntimeError('Original item moved unexpectedly; no blind input')
|
|
s.macro(f'/use 0 {a.root-22}');s.macro('/s .save');c.wait(lambda:equipped()==str(a.original),8)
|
|
elif equipped()!=str(a.original):raise RuntimeError('Unexpected equipped state; no blind restore')
|
|
report['restored_inventory']=inventory(a.character)
|
|
if report['restored_inventory']!=baseline:raise RuntimeError('Original inventory not restored')
|
|
current=db(f'SELECT health,money FROM tw_char.characters WHERE guid={a.character};');report['after_equipment_restore_character']=current
|
|
if current.split('\t')[1]!=character.split('\t')[1]:raise RuntimeError('Unexpected money change; fixture might have sold')
|
|
if int(current.split('\t')[0])!=a.health:
|
|
# Restore only recorded HP after genuine max-health
|
|
# changes from equipment; never a gameplay feature.
|
|
ui.key(s.d,'F1');s.macro(f'/s .modify hp {a.health} {a.max_health}');s.macro('/s .save');c.wait(lambda:db(f'SELECT health FROM tw_char.characters WHERE guid={a.character};')==str(a.health),8)
|
|
report['controlled_health_restoration']=True
|
|
report['restoration_pending']=False
|
|
s.macro(f'/run print("GW armor restored",GetInventoryItemID("player",{a.slot+1}),UnitHealth("player"),UnitHealthMax("player"))');s.shot(out.with_name(out.stem+'-restored.png'))
|
|
except Exception as error:report['restoration_error']=type(error).__name__+': '+str(error)
|
|
ui.KEY_DELAY=old
|
|
report.update(trace.report())
|
|
if failure:report['failure']=failure
|
|
out.write_text(json.dumps(report,indent=2)+'\n');out.chmod(0o600)
|
|
print(json.dumps({k:report.get(k) for k in ('pid','equipped_character','after_equipment_restore_character','controlled_health_restoration','restoration_pending','lost_metadata_rows','observer_error','failure','restoration_error')}))
|
|
return 0 if not failure and not report['restoration_pending'] and not trace.error else 2
|
|
if __name__=='__main__':raise SystemExit(main())
|