
    .Lj<                    d   d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 ddl
mZmZmZmZ ddlmZmZmZ  ee      j)                         j*                  d   Zed	z  Zed
z  Zedz  ZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$d dZ%d!dZ&d"dZ'd#dZ(d$dZ)d%dZ*d&dZ+d'dZ,e-dk(  r e. e,             y)(a  Classify direct selector/selected-root writers around scene route execution.

The global mode/state frontier narrowed the next proof target to live writers of
0x004576da / 0x004576db / 0x0059de30.  This pass is intentionally small and
strict: it enumerates every direct EXE reference to those globals, separates
save/load restore from VM command handlers, and records what is grounded versus
what still does not promote to a live scene/event route producer.
    )annotationsN)Path)Any)find_functionfunction_rangeshx	text_refs)offset_to_varead_sectionsva_to_offset   zHwanse2.exeoutwebi8D i D ivE ivE i0Y i5-D im@ i3B i@ iɭ@ i@ c                V    t        j                  | dd      S t        |       d      S )N T)quote)htmlescapestr)values    8tools/build_selected_root_live_writer_frontier_review.pyhr   /   s%    ;;U]r$GGE
$GG    c                v    t        ||      }||dz   t        |       kD  ry t        j                  d| |      d   S )N   <Ir   )r   lenstructunpack_from)exesectionsvaoffs       r   u32r$   3   s?    
x
$C
{cAgC(dC-a00r   c                    t        j                  d|      }g }| j                  |      }|dk7  r:t        ||      }||j	                  |       | j                  ||dz         }|dk7  r:|S )Nr   r   )r   packfindr
   append)r    r!   r   needlerefsposr"   s          r   
dword_refsr-   :   sl    [[u%FD
((6
C
)(C(>KKOhhvsQw'	 )
 Kr   c           	        t        | ||      }|sy |d   }|t        z
  dz  }|t        z
  dz  }t        |      t        |      |t        k\  r|nd |t        k\  rt        |d      nd |t        k\  r|nd |t        k\  rt        |d      dS d dS )Nr   r      )
entryVaHexhandlerVaHexgeneralDispatchIndexgeneralDispatchIndexHexsaveSelectorSliceIndexsaveSelectorSliceIndexHex)r-   GENERAL_DISPATCH_TABLE_VASAVE_SELECTOR_DISPATCH_SLICE_VAr   )r    r!   
handler_var+   entry_vaabsolute_indexsave_slice_indexs          r   dispatch_entry_forr<   F   s    c8Z0DAwH!::q@N #BBqHl:2:>W2W]a<DHa<a2na#8gk6>Ba6a"2gk@HLk@kR(8!%<  rv r   c                    | t         k(  r
|dv rddddS | t        k(  rddddS | t        k(  rd	dd
dS | t        k(  rddddS | t        k(  rddddS ddd| ddS )N>   	selectorA	selectorBselector-byte-writerzgrounded-vm-writer-primitivezgopcode handler copies stream operands +2/+3 into selector bytes, then switches to a fixed root pointer.)role	promotionevidencesave-load-restorezexcluded-save-loadz`restore path reads selector bytes and writes selectedRoot after loading persistent state blocks.selected-root-indexed-writerz\selectedRoot = dword table[index] where table comes from stream +4 and index from stream +1.%selected-root-direct-or-inline-writerz\mode 0 sets selectedRoot to inline stream+4; mode 1 sets selectedRoot to stream dword at +4.selected-root-executorzgrounded-consumer-not-producerzUif selectedRoot is nonzero, push continuation and set current stream to selectedRoot.zunclassified-refreview-requiredzdirect z reference outside known rows.)SELECTOR_BYTE_HANDLER_VASAVE_LOAD_RESTORE_VASELECTED_ROOT_INDEXED_WRITER_VASELECTED_ROOT_DIRECT_WRITER_VASELECTED_ROOT_EXECUTOR_VA)function_varef_vanames      r   classify_refrQ   W   s    ..--.; F 
 **'-z
 	

 5527v
 	

 44;7v
 	

 //,9o
 	
 #&dV#AB r   c                 V   t         j                         } t        |       }t        | |      }t	        | |t
              t	        | |t              t	        | |t              d}g }|j                         D ]  \  }}|D ]  }t        ||      }|rt        |d         n|}	|t        |      t        |	      |rt        t        |d               nd d}
|
j                  t        |	||             |j                  |
         dt        t              t!        | |t              g dddt        t"              t!        | |t"              d	gdd
t        t$              t!        | |t$              dgddt        t&              t!        | |t&              ddgdg}g }t)        |t*              }|Mt-        d      D ]?  }t/        j0                  d| ||dz  z         d   }|j                  |t        |      d       A |D 
cg c]  }
|
d   dk(  s|
 }}
|D 
cg c]  }
|
d   dv r|
 }}
|D 
cg c]  }
|
d   dk(  s|
 }}
|D 
cg c]  }
|
d   dk(  s|
 }}
t3        d |j5                         D              t7        |      t7        |      t9        d |D              t7        |      t7        |      t7        |      dk(  t7        |      dk(  ddd 
}d!d"d#|d$t        t
              d%d&t        t              d%d't        t              d%g||t        t*              |d(g d)g d*d+
S c c}
w c c}
w c c}
w c c}
w ),N)r>   r?   selectedRootstartVaendVa)rP   refVaHexfunctionVaHexfunctionEndVaHexzselector byte setter)z=case 0: push continuation stream+4; jump to dword[0x004dc518]zicase 1: selectorA=stream[+2], selectorB=stream[+3]; push continuation stream+4; jump to dword[0x004dc514]z9case 2/3: call save/load restore 0x00423319 with mode 0/1)labelr1   dispatch	semanticszselectedRoot indexed writerz-selectedRoot = streamTable[index]; advance +8zselectedRoot executorzNif selectedRoot != 0, push continuation and set current stream to selectedRootzselectedRoot direct writerz&mode 0: selectedRoot = inline stream+4z)mode 1: selectedRoot = stream dword at +4    r   r   r   )index	rootVaHexrA   r@   >   rE   rF   rD   rB   rH   c              3  2   K   | ]  }t        |        y w)N)r   ).0r+   s     r   	<genexpr>zbuild_report.<locals>.<genexpr>   s     JDc$iJs   c              3  ,   K   | ]  }|d    dk(    yw)rA   rG   N r`   rows     r   ra   zbuild_report.<locals>.<genexpr>   s     (aUXV8P)P(as   r/      Fzselector bytes and selectedRoot writer/executor VM primitives are grounded. This proves how a decoded stream can choose and execute a selected root, but it still does not prove which live field/scene route produces that stream in normal gameplay.)
directRefCountselectorByteWriterRefCountselectedRootWriterRefCountselectedRootExecutorFoundsaveLoadRestoreRefCountreviewRequiredCountselectorByteWriterGroundedselectedRootWriterGroundedrouteProducerPromoteddecisionz0hwanse-selected-root-live-writer-frontier-reviewz8tools/build_selected_root_live_writer_frontier_review.pyz?selected-root-writer-primitives-grounded-route-producer-pendingr>   )rP   vaHexr?   rS   )
tableVaHexfirst32)ze0x00406dbb is a real VM handler table entry and writes selectorA/B from stream operands in subcase 1.z=0x0040ad9b and 0x0040ae0e are selectedRoot writer primitives.z10x0040adc9 is the selectedRoot executor/consumer.zO0x00423319 remains a save/load restore bridge and is not a live route producer.)zcFind the live scene/field root that reaches the selector byte setter with a normal gameplay stream.zgProve a current stream/root in actual play is dispatched through the selectedRoot writer/executor path.zqConnect this selected-root layer upward to map transition, dialogue branch, or encounter setup producer evidence.)
kindsourcestatussummarywatchedGlobalshandlerRowsdirectReferenceRowsselectorRootTablenewEvidenceremainingProofs)EXE
read_bytesr   r   r	   SELECTOR_A_VASELECTOR_B_VASELECTED_ROOT_VAitemsr   intr   updaterQ   r)   rI   r<   rK   rM   rL   r   SELECTOR_ROOT_TABLE_VAranger   r   sumvaluesr   any)r    r!   	functionsrefs_by_namerowsrP   r+   rO   functionrN   re   handler_rowsselector_rootsroot_table_offr]   rootselector_byte_writer_refsselected_root_writerssave_load_rowsreview_requiredrw   s                        r   build_reportr   ~   s{   
..
CS!HX.IsHm<sHm<!#x1ABL "$D"((* 
d 
	F$Y7H6>#hy12FKvJ!#KBJBs8G+<'=$>PT	C JJ|K>?KK
	 ,78*3:RS			
 3>?*3:YZIJ		
 -89*3:STjk		
 2=>*3:XYBDop		
/L> N!(,BCN!2Y 	KE%%dC%!)1KLQOD!!E4"IJ	K 15 ^FG]8] ^ ^v;cc 	  &*PcS[<O-OcPNP&*Tsc+.>BS.SsTOTJL4G4G4IJJ&)*C&D&)*?&@%((a\`(a%a#&~#6"?3&)*C&D&I&)*?&@A&E!&TG$ CLS 2m+<= 2m+<=#b1A.BC

 $#34%


- 1 !_ QTs*   2L L
L L!.L!8L&L&c                   | d   }d| d   fd|d   fd|d   fd|d   fd	|d
   fg}dj                  d |D              }dj                  d | d   D              }dj                  d | d   D              }dj                  d | d   D              }dj                  d | d   D              }t        j                  | d      }dt        |d          d| d| d| d| d| d| dS ) Nrw   rv   zdirect refsrg   zselector writer refsrh   zselectedRoot writersri   zreview requiredrl   r   c              3  X   K   | ]"  \  }}d t        |       dt        |       d $ yw)z<div class='card'><b>z
</b><span>z</span></div>Nr   )r`   kvs      r   ra   zrender_html.<locals>.<genexpr>   s/     fX\XY[\/!vZ!v]Sfs   (*c              3  R  K   | ]  }d t        |d          dt        |d          dt        |j                  d      xs i j                  d             dt        t        j                  |j                  d      d	             d
dj	                  d |d   D               d  yw)<tr><td>rY   
<br><code>r1   </code></td><td><code>rZ   r0   </code><br>Fensure_ascii	</td><td>r   c              3  :   K   | ]  }d t        |       d  yw)z<div>z</div>Nr   r`   items     r   ra   z(render_html.<locals>.<genexpr>.<genexpr>   s     L4qwiv.L   r[   z
</td></tr>N)r   getjsondumpsjoinrd   s     r   ra   zrender_html.<locals>.<genexpr>   s       	Wz!C,?*@)A B
+1r66|DEFkRSTXT^T^_b_f_fgq_r  BG  UH  SI  RJ JwwL3{;KLLM N	s   B%B'ry   c              3     K   | ]a  }d t        |d          dt        |d          dt        |d          dt        |d          dt        |d	          d
t        |d          d c yw)r   rP   r   rV   r   rW   r   rA   r   rB   z<br><span class='note'>rC   z</span></td></tr>Nr   rd   s     r   ra   zrender_html.<locals>.<genexpr>  s       	V~j3z?);(< =s?+,-[3v;8H I[!"##:1S_;M:N O	s   A'A)rz   c              3  :   K   | ]  }d t        |       d  ywz<li>z</li>Nr   r   s     r   ra   zrender_html.<locals>.<genexpr>  s     T$$qwiu-Tr   r}   c              3  :   K   | ]  }d t        |       d  ywr   r   r   s     r   ra   zrender_html.<locals>.<genexpr>  s     OagYe,Or   r|   Fr   a{  <!doctype html>
<html lang="ko">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Selected Root Live Writer Frontier</title>
  <style>
    body { margin:0; background:#101318; color:#edf1f7; font-family:system-ui,sans-serif; }
    main { max-width:1280px; margin:0 auto; padding:24px; }
    a { color:#8ecbff; }
    .nav { display:flex; flex-wrap:wrap; gap:8px; margin-bottom:16px; }
    .chip { border:1px solid #334155; border-radius:999px; padding:6px 10px; text-decoration:none; background:#161b22; }
    .summary { display:grid; grid-template-columns:repeat(auto-fit,minmax(180px,1fr)); gap:12px; margin:16px 0; }
    .card { border:1px solid #2b3544; border-radius:8px; padding:12px; background:#161b22; }
    .card b { display:block; color:#9fb1c9; font-size:12px; text-transform:uppercase; }
    .card span { display:block; margin-top:8px; font-size:18px; overflow-wrap:anywhere; }
    section { border:1px solid #273244; border-radius:10px; padding:16px; margin:16px 0; background:#141922; overflow:auto; }
    table { border-collapse:collapse; width:100%; min-width:980px; font-size:13px; }
    th,td { border-bottom:1px solid #283342; padding:8px; text-align:left; vertical-align:top; }
    th { color:#b9c7dc; background:#111722; }
    code { color:#dbeafe; }
    .note { display:block; margin-top:6px; color:#9fb1c9; line-height:1.35; }
    pre { white-space:pre-wrap; background:#0b0f14; border:1px solid #253044; border-radius:8px; padding:12px; max-height:420px; overflow:auto; }
  </style>
</head>
<body>
<main>
  <div class="nav">
    <a class="chip" href="index.html">index</a>
    <a class="chip" href="static_analysis_remaining_work.html">remaining work</a>
    <a class="chip" href="global_mode_state_frontier_review.html">mode/state frontier</a>
    <a class="chip" href="scene_event_text_consumer_trace_review.html">text consumer</a>
    <a class="chip" href="selected_scene_text_root_consumer_review.html">selected root consumer</a>
    <a class="chip" href="../out/selected_root_live_writer_frontier_review.json">JSON</a>
  </div>
  <h1>Selected Root Live Writer Frontier</h1>
  <p>rp   z</p>
  <div class="summary">z5</div>
  <section>
    <h2>New Evidence</h2>
    <ul>z</ul>
  </section>
  <section>
    <h2>Handler Rows</h2>
    <table><thead><tr><th>handler</th><th>dispatch entry</th><th>semantics</th></tr></thead><tbody>z</tbody></table>
  </section>
  <section>
    <h2>Direct References</h2>
    <table><thead><tr><th>global/ref</th><th>function</th><th>classification</th></tr></thead><tbody>zP</tbody></table>
  </section>
  <section>
    <h2>Remaining Proofs</h2>
    <ul>z</ul>
  </section>
  <section>
    <h2>Raw JSON</h2>
    <pre id="json"></pre>
  </section>
</main>
<script>
window.HWANSE_SELECTED_ROOT_LIVE_WRITER_FRONTIER_REVIEW = z;
document.getElementById('json').textContent = JSON.stringify(window.HWANSE_SELECTED_ROOT_LIVE_WRITER_FRONTIER_REVIEW, null, 2);
</script>
</body>
</html>
)r   r   r   r   )	reportrw   cards	card_htmlr   ref_rows	remainingrC   payloads	            r   render_htmlr      sw   YG	6(#$	 012	)E!FG	)E!FG	G$9:;E f`effI77  -( L ww  /0 H T&AR:STTIwwO9NOOHjje4G$H 
 !{ #	 

 d eqcq rf goeo p	 
 ; <C) DyA Ar   c                 2   t               } t        j                  d       t        j                  d       t        dz  j	                  t        j                  | dd      dz   d	       t        d
z  j	                  t        |       d	       t        d       y)NT)exist_okz.selected_root_live_writer_frontier_review.jsonFr/   )r   indent
zutf-8)encodingz.selected_root_live_writer_frontier_review.htmlz,selected_root_live_writer_frontier_review okr   )	r   OUTmkdirWEB
write_textr   r   r   print)r   s    r   mainr   S  s    ^FIItIIItI;;GG

6a84? H  	;;GGTZH[fmGn	
89r   __main__)r   r   returnr   )r    bytesr!   list[dict[str, Any]]r"   r   r   z
int | None)r    r   r!   r   r   r   r   z	list[int])r    r   r!   r   r8   r   r   zdict[str, Any] | None)rN   r   rO   r   rP   r   r   dict[str, Any])r   r   )r   r   r   r   )r   r   )/__doc__
__future__r   r   r   r   pathlibr   typingr   %build_hud_menu_opener_frontier_reviewr   r   r   r	   probe_exe_scene_tablesr
   r   r   __file__resolveparentsROOTr~   r   r   r6   r7   r   r   r   r   rI   rJ   rK   rM   rL   r   r$   r-   r<   rQ   r   r   r   __name__
SystemExitrc   r   r   <module>r      s    #       M L H~''*
]
Ul
Ul& ",  # % ! ", & !+ H1	"$Nqh^B
 z
TV
 r   