@@ -54,13 +54,13 @@ internal static void EnsurePatched()
5454
5555 var builder = new DynamicPatchBuilder ( "max_hand_size" ) ;
5656 var transpilerPlayerArg0 =
57- DynamicPatchBuilder . FromMethod ( typeof ( MaxHandSizePatchInstaller ) , nameof ( PlayerArg0Transpiler ) ) ;
57+ FromMethodAfterBaseLib ( nameof ( PlayerArg0Transpiler ) ) ;
5858 var transpilerPlayerArg1 =
59- DynamicPatchBuilder . FromMethod ( typeof ( MaxHandSizePatchInstaller ) , nameof ( PlayerArg1Transpiler ) ) ;
59+ FromMethodAfterBaseLib ( nameof ( PlayerArg1Transpiler ) ) ;
6060 var transpilerStateMachine =
61- DynamicPatchBuilder . FromMethod ( typeof ( MaxHandSizePatchInstaller ) , nameof ( StateMachineTranspiler ) ) ;
61+ FromMethodAfterBaseLib ( nameof ( StateMachineTranspiler ) ) ;
6262 var cardOnPlayTranspiler =
63- DynamicPatchBuilder . FromMethod ( typeof ( MaxHandSizePatchInstaller ) , nameof ( CardOnPlayTranspiler ) ) ;
63+ FromMethodAfterBaseLib ( nameof ( CardOnPlayTranspiler ) ) ;
6464
6565 TryAddMethodPatch ( builder , typeof ( CardPileCmd ) ,
6666 nameof ( CardPileCmd . CheckIfDrawIsPossibleAndShowThoughtBubbleIfNot ) ,
@@ -130,6 +130,13 @@ internal static void EnsurePatched()
130130 }
131131 }
132132
133+ private static HarmonyMethod FromMethodAfterBaseLib ( string methodName )
134+ {
135+ var method = DynamicPatchBuilder . FromMethod ( typeof ( MaxHandSizePatchInstaller ) , methodName ) ;
136+ method . after = [ Const . BaseLibHarmonyId ] ;
137+ return method ;
138+ }
139+
133140 private static void TryAddMethodPatch (
134141 DynamicPatchBuilder builder ,
135142 Type targetType ,
@@ -213,33 +220,54 @@ private static bool IsMaxHandSizeToken(CodeInstruction ins)
213220#endif
214221 }
215222
223+ private static bool IsBaseLibBaseAmountToken ( IReadOnlyList < CodeInstruction > code , int index )
224+ {
225+ return index + 1 < code . Count
226+ && IsMaxHandSizeToken ( code [ index ] )
227+ && BaseLibMaxHandSizeBridge . IsBaseLibBaseAmountConsumer ( code [ index + 1 ] ) ;
228+ }
229+
216230 private static IEnumerable < CodeInstruction > PlayerArg0Transpiler ( IEnumerable < CodeInstruction > instructions )
217231 {
218- foreach ( var ins in instructions )
232+ var code = instructions . ToList ( ) ;
233+ for ( var i = 0 ; i < code . Count ; i ++ )
219234 {
220- if ( IsMaxHandSizeToken ( ins ) )
235+ if ( IsBaseLibBaseAmountToken ( code , i ) )
236+ {
237+ yield return code [ i ] ;
238+ continue ;
239+ }
240+
241+ if ( IsMaxHandSizeToken ( code [ i ] ) )
221242 {
222243 yield return new ( OpCodes . Ldarg_0 ) ;
223244 yield return new ( OpCodes . Call , GetMaxHandSizeMethod ) ;
224245 continue ;
225246 }
226247
227- yield return ins ;
248+ yield return code [ i ] ;
228249 }
229250 }
230251
231252 private static IEnumerable < CodeInstruction > PlayerArg1Transpiler ( IEnumerable < CodeInstruction > instructions )
232253 {
233- foreach ( var ins in instructions )
254+ var code = instructions . ToList ( ) ;
255+ for ( var i = 0 ; i < code . Count ; i ++ )
234256 {
235- if ( IsMaxHandSizeToken ( ins ) )
257+ if ( IsBaseLibBaseAmountToken ( code , i ) )
258+ {
259+ yield return code [ i ] ;
260+ continue ;
261+ }
262+
263+ if ( IsMaxHandSizeToken ( code [ i ] ) )
236264 {
237265 yield return new ( OpCodes . Ldarg_1 ) ;
238266 yield return new ( OpCodes . Call , GetMaxHandSizeMethod ) ;
239267 continue ;
240268 }
241269
242- yield return ins ;
270+ yield return code [ i ] ;
243271 }
244272 }
245273
@@ -258,6 +286,8 @@ private static IEnumerable<CodeInstruction> StateMachineTranspiler(IEnumerable<C
258286 {
259287 if ( ! IsMaxHandSizeToken ( code [ i ] ) )
260288 continue ;
289+ if ( IsBaseLibBaseAmountToken ( code , i ) )
290+ continue ;
261291
262292 code [ i ] = new ( OpCodes . Call , GetMaxHandSizeMethod ) ;
263293 code . InsertRange ( i , loadPlayer . Select ( ci => ci . Clone ( ) ) ) ;
@@ -282,6 +312,8 @@ private static IEnumerable<CodeInstruction> CardOnPlayTranspiler(IEnumerable<Cod
282312 {
283313 if ( ! IsMaxHandSizeToken ( code [ i ] ) )
284314 continue ;
315+ if ( IsBaseLibBaseAmountToken ( code , i ) )
316+ continue ;
285317
286318 code [ i ] = new ( OpCodes . Call , GetMaxHandSizeFromCardMethod ) ;
287319 code . InsertRange ( i , loadCard . Select ( ci => ci . Clone ( ) ) ) ;
@@ -392,7 +424,7 @@ private static bool GetPositionPrefix(int handSize, int cardIndex, ref Vector2 _
392424
393425 var halfSpread = GetInferredHalfSpread ( handSize ) ;
394426 var edgeLift = Math . Max ( 72f , 88f - ( handSize - 10 ) * 1.5f ) ;
395- var u = handSize <= 1 ? 0f : 2f * cardIndex / ( handSize - 1f ) - 1f ;
427+ var u = 2f * cardIndex / ( handSize - 1f ) - 1f ;
396428 var x = halfSpread * u ;
397429 var y = Math . Min ( 18f , - 64f + edgeLift * u * u ) ;
398430 __result = new ( x , y ) ;
@@ -413,7 +445,7 @@ private static bool GetAnglePrefix(int handSize, int cardIndex, ref float __resu
413445
414446 var halfSpread = GetInferredHalfSpread ( handSize ) ;
415447 var edgeLift = Math . Max ( 72f , 88f - ( handSize - 10 ) * 1.5f ) ;
416- var u = handSize <= 1 ? 0f : 2f * cardIndex / ( handSize - 1f ) - 1f ;
448+ var u = 2f * cardIndex / ( handSize - 1f ) - 1f ;
417449 var dyDu = 2f * edgeLift * u ;
418450 var dxDu = Math . Max ( 1f , halfSpread ) ;
419451 var angle = Mathf . RadToDeg ( Mathf . Atan2 ( dyDu , dxDu ) ) ;
0 commit comments