
    LjrI                       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 ddl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Z"dZ#dZ$dZ%dZ&dZ'd1d2dZ(d3dZ)d4dZ*d5d Z+d6d!Z,d6d"Z-d7d#Z.d8d$Z/d9d%Z0d:d&Z1d;d'Z2d<d=d(Z3d>d)Z4d?d@d*Z5dAd+Z6dBdCd,Z7dDd-Z8dEd.Z9dFd/Z:e;d0k(  r e< e:             y)Ga  Review producers/consumers of the active group gate used before HUD menus.

The stream at 0x0047e688 gates the grounded top-menu wrapper with two VM
commands:

* 0x6e compares command bytes with globals 0x00574544/0x00574543.
* 0xe6 branches on the active descriptor count at 0x004576e8.

This pass intentionally stays below "opener proof".  It asks whether those
globals are a normal-field ESC/X opener signal, or a more general active
object/descriptor control surface that the menu wrapper also uses.
    )annotationsN)Path)Any)offset_to_varead_sectionsva_to_offset)decode_stream   zHwanse2.exeoutwebiDEW iCEW ivE ivE iPwE iJ@ ix@ i9A i-C iC i##C i!#@ imA iG i|G iG ilM c                    | dS d| d| dS )N-0x0x )valuewidths     4tools/build_hud_active_group_gate_frontier_review.pyhxr   5   s#    -3;r%%z):%;;    c                V    t        j                  | dd      S t        |       d      S )N T)quote)htmlescapestr)r   s    r   hr   9   s%    ;;U]r$GGE
$GGr   c                ^    t        ||      }|t        dt        |       d      | |||z    S )NzVA z is outside raw sections)r   
ValueErrorr   )exesectionsvasizeoffsets        r   read_atr&   =   s=    (B'F~3r"vh&>?@@vv}%%r   c                    | D ]?  }t        |d         }|t        |d         z   }||cxk  r|k  s.n 1t        |d         c S  y)Nr#   raw_sizenamer   )intr   )r"   r#   sectionstartends        r   section_name_forr.   D   sT     (GDM"c'*-..Bwv''	(
 r   c                    t        j                  d|      }g }| j                  |      }|dk7  r:t        ||      }||j	                  |       | j                  ||dz         }|dk7  r:|S )N<Ir
   )structpackfindr   append)r!   r"   r   needlerefsposr#   s          r   all_refsr9   M   sl    [[u%FD
((6
C
)(C(>KKOhhvsQw'	 )
 Kr   c                T   g }t        j                  d|      }|D ]  }|j                  d      dk7  rt        |d         }|t        |d         z   }| j	                  |||      }|dk7  sPt        ||      }	|	|j                  |	       | j	                  ||dz   |      }|dk7  r; |S )Nr0   r)   .textrawr(   r1   r
   )r2   r3   getr*   r4   r   r5   )
r!   r"   r   r7   r6   r+   r,   r-   r8   r#   s
             r   	text_refsr>   Y   s    D[[u%F 
1;;v')GEN#c'*-..hhvuc*Rih,B~B((637C0C	 Ri
1 Kr   c           	     `   g }|D ]  }|j                  d      dk7  rt        |d         }|t        |d         z   }t        |t        ||dz
              D ]T  }| |   dk7  rt	        ||      }|t        j                  d| |dz         d	   }	|dz   |	z   |k(  sD|j                  |       V  |S )
Nr)   r;   r<   r(         z<ir
   r   )r=   r*   rangemaxr   r2   unpack_fromr5   )
r!   r"   	target_vahitsr+   r,   r-   offcall_varels
             r   
call_sitesrJ   j   s    D %;;v')GEN#c'*-..E37 34 	%C3x4"8S1G$$T3a8;C{S I-G$	%% Kr   c                l   t        d |D              }t        |d         }|t        |d         z   }g }|}	 | j                  d||      }|dk  rn%t        ||      }||j	                  |       |dz   }>t        t        |            }g }	t        |      D ]  \  }
}t        ||      }||
dz   t        |      k  r||
dz      nt        |d         t        |d         z   }|
dz   t        |      k  rt        ||      n|}||}|	j	                  |||t        ||      t        d||z
        d        |	S )	Nc              3  J   K   | ]  }|j                  d       dk(  s|  yw)r)   r;   N)r=   ).0r+   s     r   	<genexpr>z"function_ranges.<locals>.<genexpr>~   s      RG7;;v3F'3QRs   ##r<   r(   s   Ur   r
   r#   )startVaendVastartOffendOffr$   )nextr*   r4   r   r5   sortedset	enumerater   lenrC   )r!   r"   text	raw_startraw_endstartsr8   hitr#   rowsindexstart_va	start_offnext_vanext_offs                  r   function_rangesrc   }   sf   RxRRDDK I#d:.//GF
C
hhW57(C(>MM"Ag  CK F!#D$V, 
x 84	',qy3v;'>&#CT
OVYZ^_iZjVkDk6;ai#f+6M<'2SZH# %i2Ax)34	

" Kr   c                d    | D ]+  }t        |d         |cxk  rt        |d         k  s'|c S  - y )NrO   rP   )r*   )	functionsr#   functions      r   owner_functionrg      sB     x	"#rBC0A,BBO C r   c                    | t         k(  ry| t        k(  ry| t        k(  ry| t        k(  ry| t        k(  ry| t
        k(  ry| t        k(  ry| t        k(  ryd	| cxk  rd
k  ry d| cxk  rdk  ry yy)NzVM opcode 0x6d handlerzVM opcode 0x6e handlerzVM opcode 0xe6 handler&field actor input/collision controllerfield collision response helperz&active descriptor rebuild/materializerzgeneric display VM rootztext/status display handleri  C i/C (field active-object/descriptor subsystemi @ iA zgeneric VM handler layerunclassified)GROUP_STORE_HANDLER_VAGROUP_BRANCH_HANDLER_VACOUNT_BRANCH_HANDLER_VAFIELD_ACTOR_CONTROLLER_VAFIELD_COLLISION_RESPONSE_VADESCRIPTOR_REBUILD_VADISPLAY_VM_ROOT_VATEXT_STATUS_HANDLER_VA)r_   s    r   classify_functionru      s    ))'**'**',,7..0((7%%()),X++9 ,X++) ,r   c                    t        ||      }|y| }g d}|D ])  \  }}}||z
  }	|	dk\  s||	|	t        |      z    |k(  s'|c S  y)Nunknown)
)   s   zdirect byte store imm8)rx   s   zdirect dword store imm32)r
      zread byte into AL)r
      write AL)rx   s   fzread word into AX)rx   s   fzwrite AX)rx   s   zindexed byte read)rx   s   fzword read/indexed operand)   s   fzindexed word read)r|   s   zindexed dword readr   zraw dword reference)r   rW   )
r!   r"   ref_varG   datachecksbackprefixlabelr,   s
             r   classify_ref_instructionr      sk    
x
(C
{DF  & fed
A:$uUS[%89VCL !r   c                    t        ||      }|yt        d||z
        }t        t        |       ||z         }| || j	                  d      S )Nr   r    )r   rC   minrW   hex)r!   r"   r#   beforeafterrG   r,   r-   s           r   context_bytesr      sQ    
x
$C
{3< E
c#he
$CuS>c""r   c                0   g }t        | ||      D ]  }t        ||      }|rt        |d         nd }|j                  |t	        |      t	        |      |t	        |      |t        |      ndt        | ||      t        ||      t        | ||      d	        |S )NrO   r   )	refVarefVaHextargetVaHexownerStartVaownerStartVaHex
ownerClassinstructionClassr+   contextBytes)	r>   rg   r*   r5   r   ru   r   r.   r   )r!   r"   re   rE   r]   refownerowner_starts           r   ref_rowsr      s    !#Dh	2 
y#./4c%	*+$sG!)} +#%k?@K@W/<]_$<S(C$P+Hc: -c8S A
	

  Kr   c                H   t        | |||d      }t        |      |j                  dd      |j                  dg       D cg c]U  }|j                  d      |j                  d      |j                  d      |j                  d	      |j                  d
      dW c}dS c c}w )Ni   )max_commands	max_bytesdecodedCommandCountr   commandsvaHex	opcodeHex
opcodeNamesummaryrawHex)r   r   r   r   r   )
startVaHexr   r   )r	   r   r=   )r!   r"   r_   r   decodedrows         r   command_digestr      s    C8,Z_`Gl&{{+@!D {{:r2	
  ) WW[1!ggl3779-''(+	
 	
s    ABc                 V   t         j                         } t        |       }t        | |      }t	        | ||t
              }t	        | ||t              }t	        | ||t              }||z   D cg c]  }d|d   v s|d   dk(  r| }}|D cg c]  }d|d   v s|d   dk(  r| }}||z   D cg c]  }|d   dv r| }	}t        | |t        d      }
t        | |t              }t        | |t              }t        |      t        |      t        |      t        |      t        |      t        |	      t        |      t        |      t        t              t        t              t        t               t        t"              dd	d
d}dd|t        t
              t        t              t        t              t        t$              t        t&              d|
|||	d d ||||D cg c]  }t        |       c}|d d D cg c]  }t        |       c}dg dg dd}|S c c}w c c}w c c}w c c}w c c}w )Nstorer   r{   r   >   rj   ri   rk      )r   FzEactive-group/descriptor gate grounded; opener producer still unprovena  0x574544/0x574543 are not a narrow ESC/X opener flag.  They are written by the 0x6d VM handler and by descriptor/display setup code, and consumed heavily by the field actor/collision subsystem.  0x4576e8 is the active descriptor count.  The 0x0047e688 gate is therefore a grounded active-object/display gate before the top menu wrapper, but it does not by itself identify the normal-field menu opener.)activeGroupARefCountactiveGroupBRefCountactiveDescriptorCountRefCountdirectGroupWriteCountdescriptorCountDirectWriteCountfieldGroupConsumerCountdescriptorRebuildCallCountdisplayVmRootCallCounttopMenuGateVaHextopMenuRejectLoopVaHextopMenuWrapperVaHextopMenuSequenceVaHexnormalFieldEscOpenerPromotedclassificationdecisionr
   z,hwanse-hud-active-group-gate-frontier-review)activeGroupAactiveGroupBactiveDescriptorCountactiveDescriptorOrderactiveDescriptorSlotTable<   x   )descriptorRebuilddisplayVmRoot)zxactive group globals are consumed inside the field actor/collision controller, so they are broader than menu-open state.zkdescriptor count 0x004576e8 is shared by save/object/battle/menu descriptor loops and is not unique to HUD.zZthe top-menu wrapper still has no direct pointer ref from a normal-field ESC/X input root.zvthe 0x0047e688 gate proves wrapper admission conditions, not the producer that schedules this wrapper from field mode.)zbtrace writers that attach or schedule the stream containing 0x0047e688/0x0047e6a0 from field mode.zdseparate descriptor/display setup calls that use 0x402321 from normal field vs intro/title contexts.zAdo not promote active group key writes alone as the ESC/X opener.)versionkindr   	addressespreWrapperGatedirectGroupWritesdescriptorCountDirectWritesfieldGroupConsumersactiveGroupARefsactiveGroupBRefsactiveDescriptorCountRefs	callSitesnegativeEvidencenextFrontier)EXE
read_bytesr   rc   r   ACTIVE_GROUP_A_VAACTIVE_GROUP_B_VAACTIVE_DESCRIPTOR_COUNT_VAr   TOP_MENU_PRE_WRAPPER_GATE_VArJ   rr   rs   rW   r   TOP_MENU_REJECT_LOOP_VATOP_MENU_WRAPPER_VATOP_MENU_SEQUENCE_VAACTIVE_DESCRIPTOR_ORDER_VAACTIVE_DESCRIPTOR_SLOT_TABLE_VA)r!   r"   re   group_a_rowsgroup_b_rows
count_rowsr   direct_group_writesdescriptor_count_direct_writesfield_group_consumersdescriptor_rebuild_contextdescriptor_rebuild_callsdisplay_vm_root_callsr   r#   reports                   r   build_reportr     sy   
..
CS!HX.IC96GHLC96GHL#x4NOJ $l2c,--5G1HJ1V 	 
 "&c,--5G1HJ1V 	&" &
 $l2| !
 
 	  "0X?[jk!l)#x9NO&sH6HI !$L 1 #L 1),Z!$%8!9+./M+N#&'<#=&)*B&C"%&;"<;<"$%<"=!"56 "#7 8(-a]!G2 >0101%'(B%C%'(B%C)+,K)L
 50'E4Sb9((%/3K!LR"R&!L/DTc/JKbfK


9!FD M_&p "MKs   )HH(HH!1H&c                    | d | }dj                  d |D              }t        |       |kD  r|dt        |       |z
   dz  }|S )Nr   c              3     K   | ]R  }d t        |d          dt        |d          dt        |d          dt        |d          dt        |d	          d
 T yw)<tr><td><code>r   </code></td><td><code>r   </code><br>r   	</td><td>r   </td><td><code>r   </code></td></tr>Nr   rM   r   s     r   rN   z#render_ref_table.<locals>.<genexpr>e  s       	s:'( )s,-./{1S=N;O:P Q'()* +s>*+, -		s   AAz<tr><td colspan='4'>... z more rows in JSON</td></tr>)joinrW   )r]   limitshownbodys       r   render_ref_tabler   c  s\    %LE77   D 4y5*3t9u+<*==YZZKr   c                R    dj                  d | j                  dg       D              S )Nr   c              3  0  K   | ]  }d t        |j                  d             dt        |j                  d             dt        |j                  d             dt        |j                  d             dt        |j                  d	             d
  yw)r   r   r   r   r   r   r   r   r   r   r   N)r   r=   r   s     r   rN   z'render_command_table.<locals>.<genexpr>t  s       	swww'() *sww{+,-[377<;P9Q8R S#$% &swwx()* +		s   BBr   )r   r=   )contexts    r   render_command_tabler   s  s-    77  ;;z2.  r   c                   | d   }t        j                  | d      }dj                  d |j                         D              }dj                  d | d   D              }dj                  d | d	   D              }d
t	        |d          d| dt        | d          dt        | d          dt        | d          dt        | d          d| d| d| d}dj                  d |j                         D              dz   S )Nr   F)ensure_asciir   c              3  b   K   | ]'  \  }}|d k7  rdt        |       dt        |       d ) yw)r   z<div class='card'><b>z
</b><span>z</span></div>Nr   )rM   keyr   s      r   rN   zrender_html.<locals>.<genexpr>  s;      C*  #xz!E(=Is   -/c              3  :   K   | ]  }d t        |       d  ywz<li>z</li>Nr   rM   items     r   rN   zrender_html.<locals>.<genexpr>  s     U$$qwiu-U   r   c              3  :   K   | ]  }d t        |       d  ywr   r   r   s     r   rN   zrender_html.<locals>.<genexpr>  s     Udd1T7)51Ur   r   a  <!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>HUD Active Group Gate Frontier Review</title>
<style>
  body { margin:0; font-family:system-ui,-apple-system,Segoe UI,sans-serif; background:#f6f2e8; color:#211b16; }
  main { max-width:1180px; margin:0 auto; padding:24px; }
  h1 { margin:0 0 8px; font-size:28px; }
  h2 { margin-top:26px; font-size:18px; }
  p, li { line-height:1.45; }
  code { font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; }
  .cards { display:grid; grid-template-columns:repeat(auto-fit,minmax(190px,1fr)); gap:10px; margin:18px 0; }
  .card { background:#fffaf0; border:1px solid #d7c7a3; border-radius:8px; padding:10px 12px; }
  .card b { display:block; color:#705324; font-size:12px; }
  .card span { display:block; margin-top:4px; overflow-wrap:anywhere; }
  table { width:100%; border-collapse:collapse; background:#fffdf7; border:1px solid #d8ccb3; table-layout:fixed; }
  th, td { border-bottom:1px solid #e4dac5; padding:7px 8px; text-align:left; vertical-align:top; font-size:12px; }
  th { background:#eee3ca; color:#4a3a20; }
  td:nth-child(1) { width:105px; }
  td:nth-child(2) { width:210px; }
  td:nth-child(3) { width:170px; }
  td:nth-child(4) { overflow-wrap:anywhere; }
  pre { white-space:pre-wrap; background:#211b16; color:#f4ead8; padding:14px; border-radius:8px; max-height:360px; overflow:auto; }
</style>
</head>
<body>
<main>
  <h1>HUD Active Group Gate Frontier Review</h1>
  <p>r   z</p>
  <div class="cards">z</div>
  <section>
    <h2>Pre-wrapper Gate Decode</h2>
    <table><thead><tr><th>VA</th><th>opcode</th><th>summary</th><th>raw</th></tr></thead><tbody>r   z</tbody></table>
  </section>
  <section>
    <h2>Direct Group Writes</h2>
    <table><thead><tr><th>ref</th><th>owner</th><th>instruction</th><th>bytes</th></tr></thead><tbody>r   z</tbody></table>
  </section>
  <section>
    <h2>Descriptor Count Direct Writes</h2>
    <table><thead><tr><th>ref</th><th>owner</th><th>instruction</th><th>bytes</th></tr></thead><tbody>r   z</tbody></table>
  </section>
  <section>
    <h2>Field Group Consumers</h2>
    <table><thead><tr><th>ref</th><th>owner</th><th>instruction</th><th>bytes</th></tr></thead><tbody>r   zQ</tbody></table>
  </section>
  <section>
    <h2>Negative Evidence</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_HUD_ACTIVE_GROUP_GATE_FRONTIER_REVIEW = z;
document.getElementById('json').textContent = JSON.stringify(window.HWANSE_HUD_ACTIVE_GROUP_GATE_FRONTIER_REVIEW, null, 2);
</script>
</body>
</html>

c              3  <   K   | ]  }|j                           y w)N)rstrip)rM   lines     r   rN   zrender_html.<locals>.<genexpr>  s     EtT[[]Es   )jsondumpsr   itemsr   r   r   
splitlines)r   r   payloadcards	negativesnext_frontierhtml_docs          r   render_htmlr    s   YGjje4GGG !--/ E
 U&AS:TUUIGGUf^>TUUM: 
 W a bvv|  ~N  wO  bP  aQ Qg hxx~  @S  yT  hU  gV Vg hxx~  @]  y^  h_  g` `g hxx~  @U  yV  hW  gX X	 
 	 
 7 8?i @{BHF 99Ex/B/B/DEELLr   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*hud_active_group_gate_frontier_review.jsonFrx   )r   indentr  zutf-8)encodingz*hud_active_group_gate_frontier_review.htmlz(hud_active_group_gate_frontier_review okr   )	r   OUTmkdirWEB
write_textr  r  r  print)r   s    r   mainr    s    ^FIItIIItI77CC

6a84? D  	77CCKPVDWbiCj	
45r   __main__)r   )r   z
int | Noner   r*   returnr   )r   r   r  r   )
r!   bytesr"   list[dict[str, Any]]r#   r*   r$   r*   r  r  )r"   r  r#   r*   r  r   )r!   r  r"   r  r   r*   r  	list[int])r!   r  r"   r  rE   r*   r  r  )r!   r  r"   r  r  r  )re   r  r#   r*   r  zdict[str, Any] | None)r_   r*   r  r   )r!   r  r"   r  r}   r*   r  r   )r      )r!   r  r"   r  r#   r*   r   r*   r   r*   r  r   )
r!   r  r"   r  re   r  rE   r*   r  r  )r  )
r!   r  r"   r  r_   r*   r   r*   r  dict[str, Any])r  r  )P   )r]   r  r   r*   r  r   )r   r  r  r   )r   r  r  r   )r  r*   )=__doc__
__future__r   r   r  r2   pathlibr   typingr   probe_exe_scene_tablesr   r   r   'summarize_object_payload_442c75_callersr	   __file__resolveparentsROOTr   r  r  r   r   r   r   r   rm   rn   ro   rp   rq   rr   rs   rt   r   r   r   r   r   r   r&   r.   r9   r>   rJ   rc   rg   ru   r   r   r   r   r   r   r   r  r  __name__
SystemExitr   r   r   <module>r-     sJ   #      L L A H~''*
]
Ul
Ul  ' ' ", # $ $ & ( "  # ) $   ! <H&	"&!H0!0#*$Xv 	MM`
 z
TV
 r   