@@ -88,16 +88,40 @@ public static bool TryGetSummonedCustomRole(Player player, out object summonedCu
8888 return false ;
8989 }
9090
91- if ( SummonedCustomRole ? . GetProperty ( "List" , BindingFlags . Public | BindingFlags . Static ) ? . GetValue ( null ) is not
92- IEnumerable list )
91+ object listObj = SummonedCustomRole ? . GetProperty ( "List" , BindingFlags . Public | BindingFlags . Static ) ? . GetValue ( null ) ;
92+
93+ if ( listObj is not IEnumerable list )
9394 return false ;
9495
95- foreach ( object scr in list )
96+ object [ ] entries = list . Cast < object > ( ) . ToArray ( ) ;
97+ LogManager . Debug ( $ "Found SummonedCustomRole.List with { entries . Length } entries.") ;
98+
99+ foreach ( object entry in entries )
96100 {
97- object scrPlayer = scr . GetType ( ) . GetProperty ( "Player" ) ? . GetValue ( scr ) ;
98- PropertyInfo playerIdProp = scrPlayer ? . GetType ( ) . GetProperty ( "PlayerId" ) ;
99- if ( playerIdProp == null || playerIdProp . GetValue ( scrPlayer ) ? . Equals ( player . PlayerId ) != true ) continue ;
100- summonedCustomRole = scr ;
101+ object candidate = entry ;
102+ PropertyInfo valueProp = entry . GetType ( ) . GetProperty ( "Value" ) ;
103+ if ( valueProp != null )
104+ {
105+ object value = valueProp . GetValue ( entry ) ;
106+ if ( value != null )
107+ candidate = value ;
108+ }
109+
110+ LogManager . Debug ( $ "Examining entry candidate: { candidate } ") ;
111+
112+ object scrPlayer = candidate . GetType ( ) . GetProperty ( "Player" ) ? . GetValue ( candidate ) ;
113+ LogManager . Debug ( $ "Player property value: { scrPlayer } ") ;
114+ if ( scrPlayer is null )
115+ continue ;
116+
117+ PropertyInfo playerIdProp = scrPlayer . GetType ( ) . GetProperty ( "PlayerId" ) ;
118+ LogManager . Debug ( $ "PlayerId property: { playerIdProp } ") ;
119+ object idObj = playerIdProp ? . GetValue ( scrPlayer ) ;
120+ LogManager . Debug ( $ "Found PlayerId value: { idObj } ") ;
121+
122+ if ( idObj is not int foundId || foundId != player . PlayerId ) continue ;
123+ summonedCustomRole = candidate ;
124+ LogManager . Debug ( $ "Matched SummonedCustomRole for PlayerId { player . PlayerId } : { candidate } ") ;
101125 return true ;
102126 }
103127
0 commit comments