Files
praxisandClaude Fable 5.2 8a24c445b0 Content pipeline and operator tools
367 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

97 lines
5.8 KiB
Python

#!/usr/bin/env python3
"""Purchase a mapped Turtle rank through actual Forever UI; require backend ACK.
Only the designated disposable Warrior's current authenticated local session.
No SQL writes, packet injection, arbitrary Lua, invented spell IDs or GM learns.
"""
import argparse
import io
import json
from pathlib import Path
import struct
import subprocess
import time
from PIL import Image,ImageOps
import client_ui as ui
from client_session import Session
class AuditState:
def __init__(self,path):
self.path=path;self.offset=0;self.partial='';self.known=set();self.points=None;self.self_guid=None
def update(self):
with self.path.open() as source:
source.seek(self.offset);text=source.read(16777217);self.offset=source.tell()
if self.offset>16777216+256:raise RuntimeError('Session audit exceeds bounded input')
lines=(self.partial+text).split('\n');self.partial=lines.pop()
for line in lines:
if not line:continue
e=json.loads(line)
if e['event']=='capture_capped':raise RuntimeError('Audit capped; authoritative acknowledgement unavailable')
if e['event']=='initial_spells':self.known=set(map(int,e['spells']))
elif e['event']=='spell_change':
if int(e['old']):self.known.discard(int(e['old']))
if int(e['spell']):self.known.add(int(e['spell']))
elif e['event']=='sent' and e.get('profile')=='self':self.self_guid=int(e['guid'])
elif e['event']=='legacy' and int(e['guid'])==4509 and '1102' in e.get('fields',{}):self.points=int(e['fields']['1102'])
def rank(self,talent):return max((i+1 for i,spell in enumerate(talent['spells']) if spell and spell in self.known),default=0)
def title_is_visible(path):
with Image.open(path) as im:
if im.size!=(1920,1080):raise RuntimeError('Unverified UI geometry')
crop=ImageOps.autocontrast(im.crop((800,35,1120,75)).convert('L')).resize((1280,160))
b=io.BytesIO();crop.save(b,format='PNG')
text=subprocess.run(['tesseract','stdin','stdout','--psm','6'],input=b.getvalue(),capture_output=True,check=True).stdout.decode()
return 'talents' in text.lower()
def main():
p=argparse.ArgumentParser(description=__doc__)
p.add_argument('--talent',required=True,type=int);p.add_argument('--rank',required=True,type=int)
p.add_argument('--provider',action='store_true',help='Use the native frame with genuine Turtle provider layout, not the original DB2 nodes')
args=p.parse_args()
profile=json.loads((ui.ROOT/'docs/evidence/gameplay/turtle-warrior-talents.json').read_text())
if args.provider:
data=json.loads((ui.ROOT/'build/turtle-data/talents.json').read_text())
talents=[{**t,'spells':[r['id'] for r in t['ranks']],'node':t['id'],'entry':t['id']} for t in data['talents']]
else:talents=profile['talents']
talent=next((t for t in talents if t['id']==args.talent),None)
if not talent or not talent['node'] or not 1<=args.rank<=len(talent['spells']) or not talent['spells'][args.rank-1]:p.error('Talent/rank lacks a verified data definition')
pid=int((ui.ROOT/'runtime/relay.pid').read_text())
path=max((ui.ROOT/'runtime').glob('population-'+str(pid)+'-*.jsonl'),key=lambda p:p.stat().st_mtime)
state=AuditState(path);state.update()
if state.self_guid!=4509 or state.points is None:raise RuntimeError('Actual active session is not the designated disposable Warrior')
profile_points=state.points;before=state.rank(talent);cost=args.rank-before
if cost<=0 or cost>state.points:raise RuntimeError('Rank unchanged, lower, or exceeds actual Turtle points')
directory=ui.ROOT/'runtime/talent-ui';directory.mkdir(exist_ok=True,mode=0o700)
with Session() as s:
s.ensure_world(10);panel=directory/'panel.png';s.shot(panel)
if not title_is_visible(panel):ui.key(s.d,'n');s.shot(panel)
if not title_is_visible(panel):raise RuntimeError('Native talent panel title not verified; no click attempted')
# Actual tree coordinates are calibrated once for this build and geometry;
# node positions come from DB2, never from individual NPC/GUID exceptions.
if args.provider:
tabs=sorted((t for t in data['talent_tabs'] if t['classMask']&1),key=lambda t:t['order'])
group=next(i for i,t in enumerate(tabs) if t['id']==talent['tab'])
x=468+400*group+60*talent['column'];y=285+60*talent['row']
else:
x=round(468+(talent['native_position']['x']-1020)/10)
y=round(285+(talent['native_position']['y']-2130)/10)
for _ in range(cost):
ui.click_at(s.d,s.win,x,y)
# Real-client tracing showed5 down/up pairs without a released
# frame registered only1 click. Give the engine one bounded40ms
# release interval; backend ACK remains the success condition.
time.sleep(.04)
s.shot(directory/f'{args.talent}-{args.rank}-staged.png')
ui.click_at(s.d,s.win,960,727)
deadline=time.monotonic()+8
while time.monotonic()<deadline:
state.update()
if state.rank(talent)==args.rank and state.points==profile_points-cost:break
time.sleep(.1)
else:raise RuntimeError('Actual Turtle rank/point acknowledgement timed out; frontend staging is not success')
s.shot(directory/f'{args.talent}-{args.rank}-acknowledged.png')
record={'audit':path.name,'character_guid':4509,'talent':args.talent,'spell':talent['spells'][args.rank-1],'rank':args.rank,'before_rank':before,'remaining_points':state.points,'node':talent['node'],'entry':talent['entry'],'native_turtle_provider':args.provider}
(directory/f'{args.talent}-{args.rank}-result.json').write_text(json.dumps(record,indent=2)+'\n');print(json.dumps(record))
if __name__=='__main__':
with ui.timed('talent-ui-test'):main()