
    KjMP                       U d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZmZmZmZmZmZmZmZmZmZ ddlmZ  ee      j3                         j4                  d	   Zed
z  Zedz  Zedz  Zi ddddddddddddddddedfddd d!d"d#d$d%d&d'edfd(d'edfd)d'edfd*d+d,d-i d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQiZdRe dS<   dTdUdVdWdXdYdZdWd[d\d]dWd^d\d_dWd`d\dadWdbdcdddWdedfdgdWdhdidjdWdkdcdldWdmdndodWdpdqdrdWdsdtdudWdvZ!ddwZ"ddxZ#ddyZ$ddzZ%dd{Z&dd|Z'dd}Z(dd~Z)e*dk(  r e+ e)             y)aO  Scan cross-domain mode/state intersections for remaining producer roots.

Several fronts are now stuck at the same kind of boundary:

* HUD menu: UI payload/cursor consumers are grounded, opener pending.
* Scene/Event: text/choice/root consumers are grounded, route producer pending.
* Field encounter: formation/resource consumers are grounded, walking producer
  pending.
* Map animation: dirty/redraw consumers are grounded, visible-motion producer
  pending.

This pass looks at the EXE function graph from above those surfaces.  It asks:
do input, field tick, descriptor/menu state, scene selected-root state, battle
formation/resource setup, and map-animation buffers meet in the same x86
function?  Promotion is deliberately strict.  Save/load restore and already
known VM helpers are useful evidence, but they are not live gameplay roots.
    )annotationsN)Counter)Path)Any)
ADD_DESCRIPTOR_ROUTINE_VAREMOVE_DESCRIPTOR_ROUTINE_VAREBUILD_DESCRIPTOR_ROUTINE_VATOP_MENU_OBJECT_SEQUENCE_VA
call_sitesfind_functionfunction_rangeshxrefs_in_function	text_refs)read_sections   zHwanse2.exeoutwebzinput.currentMask)refiY inputzinput.edgeMask)r   iY r   zinput.pollDriver)callit-B r   zmenu.descriptorCount)r   ivE menuzmenu.descriptorOrder)r   ivE r   zmenu.descriptorRows)r   iPwE r   zmenu.rootTable)r   i-D r   zmenu.topObjectSequencer   r   zmenu.category)r   i@Y r   zmenu.cursor)r   iJY r   zmenu.enabledTable)r   i`Y r   zmenu.dispatchLatch)r   i(U r   zmenu.addDescriptorr   zmenu.removeDescriptorzmenu.rebuildDescriptorzscene.selectorA)r   ivE scenezscene.selectorB)r   ivE r   scene.selectedRoot)r   i0Y r   zscene.randomGateThreshold)r   iY r   zscene.randomGateCounter)r   iY r   zscene.textStatusConsumer)r   imA r   zfield.tickRoute)r   vA fieldzfield.activeObjectScriptRoute)r   i/C r   zfield.genericObjectScriptRunner)r   i!#@ r   zfield.liveLayer0Grid)r   iZY r   zfield.liveLayer1Flags)r   iX r   zfield.dirtyGrid)r   iWY r   zfield.mapWidth)r   iZY r   zfield.viewX)r   ivE r   zfield.viewY)r   ivE r   zencounter.sharedRng)r   i0wB 	encounterzencounter.rngSelectorHandler)r   ɼ@ r   zencounter.formationConsumer)r   i@ r   zencounter.resourceRunner)r   i/:B r   zencounter.mapResourceLoader)r   iDB r   zdict[str, tuple[str, int, str]]SYMBOLSzfield-movement-controllerzexcluded-known-consumerzinput/current mask, descriptor count, collision flags, viewport refs meet in the movement/collision controller. It is already excluded as the menu opener and not a battle/scene producer.classification	promotionreasonzsave-load-state-restorezexcluded-non-live-routezloads/restores 0x4576d8 state block, 0x457750 descriptor block, 0x59db60 flags, then restores 0x59de30 from selector bytes. It proves save/load restoration, not live scene/menu/encounter routing.zdescriptor-add-helperzexcluded-generic-stack-helperzegeneric descriptor stack add helper; it may call text/status consumer but is below the root producer.zdescriptor-rebuild-helperz[generic descriptor stack rebuild helper; useful support layer, not an opener/root selector.zdescriptor-remove-helperzQgeneric descriptor stack remove helper; this is cancel/stack maintenance support.zmenu-direction-input-helperzexcluded-menu-internalzLdirectional input dispatch to cursor helper after a menu/list object exists.zcancel-back-handlerzexcluded-cancel-backzESC/X edge handling that unwinds active descriptor state; this is cancel/back behavior, not normal opener or higher-level mode transition.zfield-tick-update-routez'excluded-known-route-no-direct-producerzper-frame field tick/update route; it calls update paths before redraw but has no direct live map-buffer mutation or encounter/menu/scene producer bridge.zmenu-internal-dispatcherzJconfirmed cursor/confirm/cancel dispatcher after menu object construction.zdisplay-vm-base-binderzexcluded-base-binderzJdisplay/object VM base pointer binder, not descriptor attachment producer.zgeneric-vm-rng-selectorzexcluded-primitivezbgeneric random selector primitive using descriptor context; not field encounter routing by itself.zscene-random-gatezexcluded-scene-random-gatezTscene/event random gate; previous field encounter scans exclude it as encounter RNG.)-C 3B iC i##C iA%C i;@ i@ r   A iA r   i0C c                V    t        j                  | dd      S t        |       d      S )N T)quote)htmlescapestr)values    0tools/build_global_mode_state_frontier_review.pyhr/      s%    ;;U]r$GGE
$GG    c                    i }i }t         j                         D ]/  \  }\  }}}|dk(  rt        | ||      ||<    t        | ||      ||<   1 ||fS )Nr   )r   itemsr   r   )exesectionsrefscallsnamekindva	_categorys           r.   collect_hitsr;      sd    !#D"$E'.}} 8##tR5="3"5DJ$S(B7E$K	8
 ;r0   c                    g }|j                         D ]>  \  }}t        | |      D ]*  }|j                  |t        |      t        |   d   d       , @ |S N   )r7   vaHexcategoryr2   r   appendr   r   )functionrefs_by_namerowsr7   r5   r   s         r.   row_refsrF      se    !#D"((* X
d#Hd3 	XCKK3WT]STEUVW	XX Kr0   c                    g }|j                         D ]>  \  }}t        | |      D ]*  }|j                  |t        |      t        |   d   d       , @ |S r=   rA   )rC   calls_by_namerE   r7   r6   r   s         r.   	row_callsrI      se    !#D$**, Ye$Xu5 	YDKK4gdmTUFVWX	YY Kr0   c                    | t         v r	t         |    S ||z   D ch c]  }|d   	 }}h d|k  rddh|z  sddddS d|v rd	|v r
d
|v rddddS d|v r
d|v rddddS d|v r
d	|v rddddS ddddS c c}w )Nr7   >   r   r   r   r   r   z#field-or-render-descriptor-consumerzexcluded-consumer-intersectionzinput/menu/field refs meet without scene/encounter/root evidence; this matches already known movement/render descriptor layers.r    r   r   zscene-menu-state-bridge-reviewreview-requiredzscene selected-root and descriptor/menu state meet. Promote only if this is live route execution, not save/load or generic stack helper.r   zfield-encounter-bridge-reviewzfield/tick and encounter primitives meet. This would be promotable only if resource/formation setup is selected from walking/map state.zrng-descriptor-context-reviewzcontext-onlyzRNG and descriptor state meet; previous scans usually classify these as generic VM/battle/status helpers unless field/map state is also present.zcross-domain-contextzPMultiple categories meet, but strict producer/root conditions are not satisfied.)KNOWN_CLASSIFICATIONS)r9   
categoriesr5   r6   rownamess         r.   classify_functionrP      s    	""$R(($(5L1SS[1E1!Z/';9OR\9\C9 X
 	

 *:!5:NRW:W>* a
 	

 j W
%:=* `
 	

 j Vz%9=' i
 	
 1#d 3 2s   A/c                 X   t         j                         } t        |       }t        | |      }t	        | |      \  }}i }t        |j                               t        |j                               z   D ])  }|D ]"  }t        ||      }|s||t        |d         <   $ + g }	t        |j                         d       D ]  }t        ||      }
t        ||      }t        |
|z   D ch c]  }|d   	 c}      }t        |      dk  rIt        |d         }t        |t        |      |
|      }|	j                  |t!        |      t!        t        |d               t        |d         ||
|d|        t#        d	 |	D              }t#        d
 |	D              }|	D cg c]  }|d   dk(  s| }}|	D cg c]  }|d   j%                  d      r| }}t'        d |	D        d       }t        |      t        |	      t        |      t        |      |d u|r|d   nd t)        d |	D              t)        d |	D              dt+        t        |j-                                     t+        t        |j-                                     dd}ddd|g d|	|dddddddddd d!dgg d"d#	S c c}w c c}w c c}w )$NstartVac                    t        | d         S )NrR   )int)items    r.   <lambda>zbuild_report.<locals>.<lambda>   s    c$y/>R r0   )keyr@   r>   endVasize)
functionVafunctionVaHexendVaHexrY   rM   r5   r6   c              3  &   K   | ]	  }|d      yw)r"   N .0rN   s     r.   	<genexpr>zbuild_report.<locals>.<genexpr>  s     @Cs;/@s   c              3  D   K   | ]  }d j                  |d           yw)+rM   N)joinr_   s     r.   ra   zbuild_report.<locals>.<genexpr>  s     #PCCHHS->$?#Ps    r"   rK   promotedc              3  2   K   | ]  }|d    dk(  s|  yw)rZ   r%   Nr^   r_   s     r.   ra   zbuild_report.<locals>.<genexpr>  s     PL0AZ0OPs   r[   c              3  ,   K   | ]  }|d    dk(    yw)rZ   r&   Nr^   r_   s     r.   ra   zbuild_report.<locals>.<genexpr>  s     -^RUc,.?:.M-^   c              3  ,   K   | ]  }|d    dk(    yw)rZ   r$   Nr^   r_   s     r.   ra   zbuild_report.<locals>.<genexpr>  s     ._SVs</@J/N._rh   Fu5  통합 교집합 스캔에서 새 live gameplay mode/state producer는 승격되지 않았다. 가장 강한 scene+menu 교집합인 0x00423319는 save/load restore 경로로 분리됐고, 0x0041d61b/0x0043022d/descriptor helpers/RNG primitive도 각각 내부 소비자 또는 generic helper로 배제된다.)touchedFunctionCountcrossDomainFunctionCountreviewRequiredCountpromotedProducerCountsaveLoadRestoreBridgeFoundsaveLoadRestoreBridgeVaHexmenuInternalDispatcherExcludedfieldMovementControllerExcludedglobalModeStateProducerPromotedpromotionCountscategoryComboCountsdecisionz(hwanse-global-mode-state-frontier-reviewz0tools/build_global_mode_state_frontier_review.pyz2cross-domain-frontier-scanned-no-producer-promoted)zA candidate must connect a live input/field/scene state transition to exact descriptor attachment, selected-root execution, battle formation/resource setup, or visible map-animation mutation.zSave/load restoration, generic descriptor stack add/remove/rebuild, cursor movement, text/status rendering, and RNG primitives are support layers and do not promote by themselves.zA single shared global such as descriptor count or selected-root is insufficient unless the caller/root shows live execution context.
0x00423319zsave/load restore writes selected-root from selector bytes after reading persistent blocks; useful boundary, not live route producer.)r[   r#   
0x0043022dz}field movement/collision controller has input+field+descriptor refs but no scene/encounter/top-menu materialization evidence.
0x0041d61bz2menu-internal dispatcher after menu object exists.z 0x00431fe8/0x00432323/0x00432541zZgeneric descriptor stack helper layer; not the producer that chooses which root to attach.)zwTrace callers above the generic object/display VM handlers that choose descriptor roots before add/rebuild helpers run.zsSearch for live writers of 0x004576da/0x004576db/0x0059de30 outside save/load restore and generic selector opcodes.z~For encounter, require one function/root to bridge field step/tick state with formation/resource setup, not merely shared RNG.zjFor map animation, require a live animated-map object/root that reaches tile-write handlers before redraw.)	r8   sourcestatussummarystrictPromotionCriteriacrossDomainRowsreviewRequiredRowsnegativePromotionsnextFrontier)EXE
read_bytesr   r   r;   listvaluesr   rT   sortedrF   rI   lenrP   setrB   r   r   
startswithnextanydictr2   )r3   r4   	functionsrD   rH   touchedhitshitrC   rE   r5   r6   rN   rM   r9   r!   promotion_countscategory_combo_countsreview_requiredre   save_restorer{   s                         r.   build_reportr      s	   
..
CS!HX.I".sH"=L-)+G\((*+d=3G3G3I.JJ = 	=C$Y4H4<HY/01	== "$D7>>+1RS 
,/(M2uES_EF
z?Q)$%*2s:eL !#Bs8G#456HV,-(	 !		

* @4@@##P4#PP&*Tsc+.>BS.SsTOT{&&z2 	H  PPRVWL !$G$'I"?3!$X&2$&>GSl?&CY]*--^Y]-^*^+.._Z^._+_+0'7'='='? @A#F+@+F+F+H$IJ.G* ;DF$

  - ". b
 ". Z
 ".N
 "Dv
$
=$ $_ F( Us   !J
J"%J"/J'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|xs d d| d| d| d S )!Nr{   rz   zcross-domain funcsrk   zreview requiredrl   zpromoted producersrm   zsave/load bridgern   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>N  s/     fX\XY[\/!vZ!v]Sfs   (*c              3  f  K   | ]  }d t        |d          dt        |d          dt        dj                  |d                dt        |d          dt        |d	          d
t        t        j                  |d   d             dt        t        j                  |d   d             d  yw)z<tr><td><code>r[   z</code><br>r!   z	</td><td>z + rM   r"   z<br><span class='note'>r#   z</span></td><td>r5   Fensure_asciir6   z
</td></tr>N)r/   rd   jsondumpsr_   s     r.   ra   zrender_html.<locals>.<genexpr>O  s      	 	s?+,-[3?O;P9Q8R SC-./0 1[!"##:1S];K:L MCKe<=> ?CLu=>? @		s   B/B1r}   c              3  :   K   | ]  }d t        |       d  ywz<li></li>Nr   r`   rU   s     r.   ra   zrender_html.<locals>.<genexpr>Y  s     [agYe,[   r|   c              3  ^   K   | ]%  }d t        |d          dt        |d          d ' yw)z
<li><code>r[   z</code> r#   r   Nr   r   s     r.   ra   zrender_html.<locals>.<genexpr>Z  s<       QtO,-.hqh7H6IOs   +-r   c              3  :   K   | ]  }d t        |       d  ywr   r   r   s     r.   ra   zrender_html.<locals>.<genexpr>^  s     PagYe,Pr   r   Fr   a  <!doctype html>
<html lang="ko">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Global Mode/State Frontier Review</title>
  <style>
    body { margin:0; background:#101318; color:#edf1f7; font-family:system-ui,sans-serif; }
    main { max-width:1320px; 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:1180px; 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; overflow-wrap:anywhere; }
    .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="hud_menu_mode_state_dispatcher_review.html">HUD mode/state</a>
    <a class="chip" href="../out/scene_event_vm_route_boundary_review.json">scene route JSON</a>
    <a class="chip" href="field_encounter_producer_boundary_review.html">encounter producer</a>
    <a class="chip" href="../out/map_animation_tick_route_review.json">map animation tick JSON</a>
    <a class="chip" href="../out/global_mode_state_frontier_review.json">JSON</a>
  </div>
  <h1>Global Mode/State Frontier Review</h1>
  <p>ru   z</p>
  <div class="summary">zB</div>
  <section>
    <h2>Strict Promotion Criteria</h2>
    <ul>z</ul>
  </section>
  <section>
    <h2>Cross-Domain Functions</h2>
    <table>
      <thead><tr><th>function</th><th>categories</th><th>promotion</th><th>refs</th><th>calls</th></tr></thead>
      <tbody>z3<tr><td colspan='5'>No cross-domain rows.</td></tr>zb</tbody>
    </table>
  </section>
  <section>
    <h2>Important Negative Promotions</h2>
    <ul>zB</ul>
  </section>
  <section>
    <h2>Next Frontier</h2>
    <ul>z</ul>
  </section>
  <section>
    <h2>Raw JSON</h2>
    <pre id="json"></pre>
  </section>
</main>
<script>
window.HWANSE_GLOBAL_MODE_STATE_FRONTIER_REVIEW = z;
document.getElementById('json').textContent = JSON.stringify(window.HWANSE_GLOBAL_MODE_STATE_FRONTIER_REVIEW, null, 2);
</script>
</body>
</html>
)rd   r   r   r/   )	reportr{   cards	card_htmlrE   criteria	negativesfrontierpayloads	            r.   render_htmlr   E  sr   YG	6(#$	w'ABC	G$9:;	w'>?@	W%ABCE f`effI77 	 +,	 	D ww[@Y9Z[[H /0 I wwP9OPPHjje4G%J 
 !{ #	 

  KKL M	
 
 	 

 3 4;) <AE Er0   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&global_mode_state_frontier_review.jsonFr>   )r   indent
zutf-8)encodingz&global_mode_state_frontier_review.htmlz$global_mode_state_frontier_review okr   )	r   OUTmkdirWEB
write_textr   r   r   print)r   s    r.   mainr     s    ^FIItIIItI33??

6a84? @  	33??F@S^e?f	
01r0   __main__)r-   r   returnr,   )r3   bytesr4   list[dict[str, Any]]r   z1tuple[dict[str, list[int]], dict[str, list[int]]])rC   dict[str, Any]rD   dict[str, list[int]]r   r   )rC   r   rH   r   r   r   )
r9   rT   rM   zset[str]r5   r   r6   r   r   zdict[str, str])r   r   )r   r   r   r,   )r   rT   ),__doc__
__future__r   r*   r   collectionsr   pathlibr   typingr   %build_hud_menu_opener_frontier_reviewr   r   r	   r
   r   r   r   r   r   r   probe_exe_scene_tablesr   __file__resolveparentsROOTr   r   r   r   __annotations__rL   r/   r;   rF   rI   rP   r   r   r   __name__
SystemExitr^   r0   r.   <module>r      s  " #        1 H~''*
]
Ul
Ul),5), 2), 5	), 7), 7), 6), 1), u&A6J), 0), .), 4), 5), 6#<fE),  f&BFK!)," v'DfM#),& 3'),( 3)),* 6+),,  !=-),. ;/),0  =1),4 45),6 $%B7),8 &'D9),: 8;),< 9=),> 3?),@ 2A),B /C),D /E),H <I),J #$EK),L "#DM),N  AO),P "#DQ),	( )\ 6. O 4. X 24y 64o 54e 8-` 0+ _ 4> o 5-^ 3+^ 4)v .1hq= @H FdN`F
 z
TV
 r0   