@@ -513,7 +513,11 @@ public ImportChartResult ImportChart([FromForm] int id, IFormFile file, [FromFor
513513 logger . LogWarning ( "BUG! shiftedConverted: {shiftedLen}, originalConverted: {originalLen}" , shiftedConverted . Split ( '\n ' ) . Length , originalConverted . Split ( '\n ' ) . Length ) ;
514514 }
515515
516- targetChart . MaxNotes = maiLibChart . AllNoteNum ;
516+ // Just use T_NUM_ALL value in ma2 file
517+ targetChart . MaxNotes = ParseTNumAllFromMa2 ( shiftedConverted ) ;
518+ // Fallback to maiLibChart if T_NUM_ALL not found
519+ if ( targetChart . MaxNotes == 0 ) targetChart . MaxNotes = maiLibChart . AllNoteNum ;
520+
517521 System . IO . File . WriteAllText ( Path . Combine ( Path . GetDirectoryName ( music . FilePath ) , targetChart . Path ) , shiftedConverted ) ;
518522 if ( debug )
519523 {
@@ -532,4 +536,25 @@ public ImportChartResult ImportChart([FromForm] int id, IFormFile file, [FromFor
532536 music . Refresh ( ) ;
533537 return new ImportChartResult ( errors , false ) ;
534538 }
539+
540+
541+ private static int ParseTNumAllFromMa2 ( string ma2Content )
542+ {
543+ var lines = ma2Content . Split ( '\n ' ) ;
544+ // 从后往前读取,因为 T_NUM_ALL 在文件最后
545+ for ( int i = lines . Length - 1 ; i >= 0 ; i -- )
546+ {
547+ var trimmedLine = lines [ i ] . Trim ( ) ;
548+ if ( trimmedLine . StartsWith ( "T_NUM_ALL" , StringComparison . OrdinalIgnoreCase ) )
549+ {
550+ var parts = trimmedLine . Split ( new char [ ] { ' ' , '\t ' } , StringSplitOptions . RemoveEmptyEntries ) ;
551+ if ( parts . Length >= 2 && int . TryParse ( parts [ 1 ] , out int tNumAll ) )
552+ {
553+ return tNumAll ;
554+ }
555+ }
556+ }
557+ // Fallback to 0 in case
558+ return 0 ;
559+ }
535560}
0 commit comments