1- using BfevLibrary . Common ;
1+ using System . Net . Http . Headers ;
2+ using BfevLibrary . Common ;
23using BfevLibrary . Parsers ;
34
45namespace BfevLibrary . Core ;
56
67public class EntryPoint : IBfevDataBlock
78{
89 public List < short > SubFlowEventIndices { get ; set ; }
10+
11+ public RadixTree < VariableDef > ? Variables { get ; set ; }
12+
913 public short EventIndex { get ; set ; }
1014
11- public EntryPoint ( ) { }
15+ public EntryPoint ( )
16+ {
17+ }
18+
1219 public EntryPoint ( BfevReader reader )
1320 {
1421 Read ( reader ) ;
@@ -17,36 +24,63 @@ public EntryPoint(BfevReader reader)
1724 public IBfevDataBlock Read ( BfevReader reader )
1825 {
1926 long subFlowEventIndicesPtr = reader . ReadInt64 ( ) ;
20- reader . BaseStream . Position += 8 + 8 ; // unused (in botw) VariableDef pointers (ulong, ulong)
27+ long variableDefNamesPtr = reader . ReadInt64 ( ) ;
28+ long variableDefsPtr = reader . ReadInt64 ( ) ;
2129 ushort subFlowEventIndicesCount = reader . ReadUInt16 ( ) ;
22- reader . BaseStream . Position += 2 ; // unused (in botw) VariableDef count (ushort)
30+ ushort variableDefCount = reader . ReadUInt16 ( ) ;
2331 EventIndex = reader . ReadInt16 ( ) ;
2432 reader . BaseStream . Position += 2 ; // padding
25- SubFlowEventIndices = reader . ReadObjectsPtr ( new short [ subFlowEventIndicesCount ] , reader . ReadInt16 , subFlowEventIndicesPtr ) . ToList ( ) ;
33+
34+ SubFlowEventIndices = reader . ReadObjectsPtr (
35+ new short [ subFlowEventIndicesCount ] , reader . ReadInt16 , subFlowEventIndicesPtr ) . ToList ( ) ;
36+
37+ Variables = reader . ReadObjectPtr ( ( ) => new RadixTree < VariableDef > ( reader ) , variableDefNamesPtr ) ;
38+ Variables ? . LinkToArray (
39+ reader . ReadObjectsPtr ( new VariableDef [ variableDefCount ] , ( ) => new VariableDef ( reader ) , variableDefsPtr )
40+ ) ;
41+
42+ reader . Align ( 8 ) ;
2643 return this ;
2744 }
2845
2946 public void Write ( BfevWriter writer )
3047 {
3148 Action insertSubFlowEventIndicesPtr = writer . ReservePtrIf ( SubFlowEventIndices . Count > 0 , register : true ) ;
32- writer . Write ( 0L ) ; // Unused (in botw) VariableDef pointer (ulong)
33- writer . WriteNullPtr ( register : true ) ; // Unused (in botw) VariableDef dict pointer (ulong)
49+ Action insertVariableDefDictPtr = writer . ReservePtrIf ( Variables is { Count : > 0 } , register : true ) ;
50+ Action insertVariableDefsPtr = writer . ReservePtrIf ( Variables is { Count : > 0 } , register : true ) ;
3451 writer . Write ( ( ushort ) SubFlowEventIndices . Count ) ;
35- writer . Write ( ( ushort ) 0 ) ; // Unused (in botw) VariableDefs count
52+ writer . Write ( ( ushort ) ( Variables ? . Count ?? 0 ) ) ;
3653 writer . Write ( EventIndex ) ;
37- writer . Write ( ( ushort ) 0 ) ; // Padding
38- writer . ReserveBlockWriter ( "EntryPointArrayDataBlock" , ( ) => {
54+ writer . Align ( 8 ) ;
55+
56+ writer . ReserveBlockWriter ( "EntryPointExtraDataBlock" , ( ) => {
3957 if ( SubFlowEventIndices . Count > 0 ) {
4058 insertSubFlowEventIndicesPtr ( ) ;
41- for ( int i = 0 ; i < SubFlowEventIndices . Count ; i ++ ) {
42- writer . Write ( SubFlowEventIndices [ i ] ) ;
59+ foreach ( short s16 in SubFlowEventIndices ) {
60+ writer . Write ( s16 ) ;
4361 }
62+
4463 writer . Align ( 8 ) ;
4564 }
4665
47- // Not really sure what this is for, based
48- // off evfl by leoetlino (evfl/entry_point.py)
49- writer . Seek ( 24 , SeekOrigin . Current ) ;
66+ if ( Variables is not { Count : > 0 } ) {
67+ return ;
68+ }
69+
70+ insertVariableDefDictPtr ( ) ;
71+ writer . WriteRadixTree ( Variables . Keys . ToArray ( ) ) ;
72+ writer . Align ( 8 ) ;
73+
74+ insertVariableDefsPtr ( ) ;
75+ foreach ( VariableDef variableDef in Variables . Values ) {
76+ variableDef . Write ( writer ) ;
77+ }
78+
79+ writer . WriteReserved ( "VariableDefData" , alignment : 8 ) ;
80+
81+ // The size for each entry point is sizeof(event_idx_array)
82+ // rounded up to the nearest multiple of 8 + 0x18 bytes.
83+ writer . Seek ( 0x18 , SeekOrigin . Current ) ;
5084 } ) ;
5185 }
52- }
86+ }
0 commit comments