@@ -120,6 +120,7 @@ void ApplyItemsInternal(ItemTranslation translation, TranslationEmitter emitter)
120120 if ( method ? . HasBody == true )
121121 {
122122 var inst = method . Body . Instructions ;
123+ var listIndex = 0 ;
123124
124125 for ( var index = 0 ; index < inst . Count ; index ++ )
125126 {
@@ -128,38 +129,42 @@ void ApplyItemsInternal(ItemTranslation translation, TranslationEmitter emitter)
128129 if ( ins . OpCode != OpCodes . Newobj || ! ( ins . Operand is MemberRef m ) || ! m . DeclaringType . Name . Equals ( "TooltipLine" ) )
129130 continue ;
130131
131- if ( index - 1 <= 0 ) continue ;
132-
133132 ins = inst [ index - 1 ] ;
134133
135- if ( index - 2 > 0 && ins . OpCode . Equals ( OpCodes . Ldstr ) && inst [ index - 2 ] . OpCode . Equals ( OpCodes . Ldstr ) )
134+ if ( ins . OpCode . Equals ( OpCodes . Ldstr ) && inst [ index - 2 ] . OpCode . Equals ( OpCodes . Ldstr ) )
136135 {
137- inst [ index - 2 ] . Operand = translation . ModifyTooltips [ 0 ] ;
138- inst [ index - 1 ] . Operand = translation . ModifyTooltips [ 1 ] ;
136+ inst [ index - 2 ] . Operand = translation . ModifyTooltips [ listIndex ++ ] ;
137+ inst [ index - 1 ] . Operand = translation . ModifyTooltips [ listIndex ++ ] ;
139138 }
140- else if ( ins . OpCode . Equals ( OpCodes . Call ) && ins . Operand is MemberRef n && n . Name . Equals ( "Concat" ) )
139+ else if ( ins . OpCode . Equals ( OpCodes . Call ) && ins . Operand is MemberRef n && n . Name . Equals ( "Concat" ) ) // for thorium mod
141140 {
142- var index2 = index ;
143- var count = 0 ;
144- var listIndex = 0 ;
141+ int index2 = index , reversedListIndex = 0 , argumentCount = 0 ;
145142 var total = n . MethodSig . Params . Count + 1 ;
146- var list = translation . ModifyTooltips . AsEnumerable ( ) . Reverse ( ) . ToList ( ) ;
147- while ( -- index2 > 0 && count < total )
143+
144+ var reversedList = translation . ModifyTooltips . GetRange ( index , translation . ModifyTooltips . Count - index ) ;
145+ reversedList . Reverse ( ) ;
146+
147+ var ldstrList = new List < Instruction > ( ) ;
148+ while ( -- index2 > 0 && argumentCount < total )
148149 {
149150 ins = inst [ index2 ] ;
150151 if ( ins . OpCode . Equals ( OpCodes . Ldelem_Ref ) )
151152 {
152- count ++ ;
153+ argumentCount ++ ;
153154 }
154155 else if ( ins . OpCode . Equals ( OpCodes . Ldstr ) )
155156 {
156- ins . Operand = list [ listIndex ++ ] ;
157- count ++ ;
157+ argumentCount ++ ;
158+ ldstrList . Add ( ins ) ;
158159 }
159160 }
160- }
161-
162161
162+ foreach ( var ldstrInstruction in ldstrList )
163+ {
164+ ldstrInstruction . Operand = reversedList [ reversedListIndex ++ ] ;
165+ index ++ ;
166+ }
167+ }
163168 }
164169 }
165170
0 commit comments