@@ -537,14 +537,17 @@ orderby ass.GetName().Version descending, a.path ascending
537537
538538 foreach ( AssemblyName mod in mods )
539539 {
540- ApplyPatch ( excludePaths , ":BEFORE[" + mod . Name + "]" ) ;
541- ApplyPatch ( excludePaths , ":FOR[" + mod . Name + "]" ) ;
542- ApplyPatch ( excludePaths , ":AFTER[" + mod . Name + "]" ) ;
540+ string upperModName = mod . Name . ToUpper ( ) ;
541+ ApplyPatch ( excludePaths , ":BEFORE[" + upperModName + "]" ) ;
542+ ApplyPatch ( excludePaths , ":FOR[" + upperModName + "]" ) ;
543+ ApplyPatch ( excludePaths , ":AFTER[" + upperModName + "]" ) ;
543544 }
544545
545546 // :Final node
546547 ApplyPatch ( excludePaths , ":FINAL" ) ;
547548
549+ PurgeUnused ( excludePaths ) ;
550+
548551 if ( errorCount > 0 )
549552 foreach ( String file in errorFiles . Keys )
550553 errors += errorFiles [ file ] + " error" + ( errorFiles [ file ] > 1 ? "s" : "" ) + " in GameData/" + file + "\n " ;
@@ -553,14 +556,24 @@ orderby ass.GetName().Version descending, a.path ascending
553556 status = "ModuleManager applied " + patchCount + " patches and found " + errorCount + " error" + ( errorCount != 1 ? "s" : "" ) ;
554557
555558#if DEBUG
559+ RunTestCases ( ) ;
560+ #endif
561+
562+ print ( "[ModuleManager] " + status + "\n " + errors ) ;
563+
564+ loaded = true ;
565+ }
566+
567+ private void RunTestCases ( )
568+ {
556569 print ( "[ModuleManager] Running tests..." ) ;
557570
558571 // Do MM testcases
559572 foreach ( UrlDir . UrlConfig expect in GameDatabase . Instance . GetConfigs ( "MMTEST_EXPECT" ) )
560573 {
561574 // So for each of the expects, we expect all the configs before that node to match exactly.
562575 UrlDir . UrlFile parent = expect . parent ;
563- if ( parent . configs . Count != expect . config . CountNodes + 1 )
576+ if ( parent . configs . Count != expect . config . CountNodes + 1 )
564577 {
565578 print ( "[ModuleManager] Test " + parent . name + " failed as expecte number of nodes differs expected:" + expect . config . CountNodes + " found: " + parent . configs . Count ) ;
566579 for ( int i = 0 ; i < parent . configs . Count ; ++ i )
@@ -569,7 +582,7 @@ orderby ass.GetName().Version descending, a.path ascending
569582 }
570583 continue ;
571584 }
572- for ( int i = 0 ; i < expect . config . CountNodes ; ++ i )
585+ for ( int i = 0 ; i < expect . config . CountNodes ; ++ i )
573586 {
574587 ConfigNode gotNode = parent . configs [ i ] . config ;
575588 ConfigNode expectNode = expect . config . nodes [ i ] ;
@@ -579,11 +592,23 @@ orderby ass.GetName().Version descending, a.path ascending
579592 }
580593 }
581594 }
582- #endif
595+ print ( "[ModuleManager] tests complete." ) ;
596+ }
583597
584- print ( "[ModuleManager] " + status + "\n " + errors ) ;
598+ private void PurgeUnused ( List < string > excludePaths )
599+ {
600+ foreach ( UrlDir . UrlConfig mod in GameDatabase . Instance . root . AllConfigs . ToArray ( ) )
601+ {
602+ int lastErrorCount = errorCount ;
585603
586- loaded = true ;
604+ string name = RemoveWS ( mod . type ) ;
605+
606+ if ( name [ 0 ] == '@' || ( name [ 0 ] == '$' ) || ( name [ 0 ] == '!' ) || name == "MMTEST" || name == "MMTEST_EXPECT" )
607+ {
608+
609+ mod . parent . configs . Remove ( mod ) ;
610+ }
611+ }
587612 }
588613
589614 private bool CompareRecursive ( ConfigNode expectNode , ConfigNode gotNode )
@@ -660,12 +685,12 @@ public void ApplyPatch(List<String> excludePaths, string Stage)
660685 // Ensure the stage is correct
661686 string upperName = name . ToUpper ( ) ;
662687
663- int stageIdx = upperName . IndexOf ( Stage . ToUpper ( ) ) ;
688+ int stageIdx = upperName . IndexOf ( Stage ) ;
664689 if ( stageIdx >= 0 )
665690 {
666691 name = name . Substring ( 0 , stageIdx ) + name . Substring ( stageIdx + Stage . Length ) ;
667692 }
668- else if ( ! ( Stage . ToUpper ( ) == ":FIRST"
693+ else if ( ! ( Stage == ":FIRST"
669694 && ! upperName . Contains ( ":BEFORE[" )
670695 && ! upperName . Contains ( ":FOR[" )
671696 && ! upperName . Contains ( ":AFTER[" )
@@ -768,7 +793,6 @@ private void CheckNeeds(List<String> excludePaths)
768793 print ( "[ModuleManager] Deleting Node in file " + mod . parent . url + " subnode: " + mod . type + " as it can't satisfy its NEEDS" ) ;
769794 continue ;
770795 }
771- Debug . LogWarning ( type ) ;
772796
773797 ConfigNode copy = new ConfigNode ( type ) ;
774798 ShallowCopy ( mod . config , copy ) ;
@@ -834,12 +858,11 @@ private void CheckNeeds(ConfigNode subMod, string url, List<string> path)
834858
835859 private static void ShallowCopy ( ConfigNode from , ConfigNode to )
836860 {
837- to . ClearData ( ) ;
861+ to . ClearData ( ) ;
838862 foreach ( ConfigNode . Value value in from . values )
839863 to . values . Add ( value ) ;
840864 foreach ( ConfigNode node in from . nodes )
841865 to . nodes . Add ( node ) ;
842- from . CopyTo ( to ) ;
843866 }
844867
845868 /// <summary>
0 commit comments