@@ -167,9 +167,9 @@ private IEnumerator ProcessPatch()
167167 PatchExtractor extractor = new PatchExtractor ( progress , logger , needsChecker , tagListParser , protoPatchBuilder , patchCompiler ) ;
168168
169169 // Have to convert to an array because we will be removing patches
170- UrlDir . UrlConfig [ ] allConfigs = GameDatabase . Instance . root . AllConfigs . ToArray ( ) ;
171- IEnumerable < IPatch > extractedPatches = allConfigs . Select ( urlConfig => extractor . ExtractPatch ( urlConfig ) ) ;
172- PatchList patchList = new PatchList ( mods , extractedPatches . Where ( patch => patch != null ) , progress ) ;
170+ IEnumerable < IPatch > extractedPatches =
171+ GameDatabase . Instance . root . AllConfigs . Select ( urlConfig => extractor . ExtractPatch ( urlConfig ) ) . Where ( patch => patch != null ) ;
172+ PatchList patchList = new PatchList ( mods , extractedPatches , progress ) ;
173173
174174 #endregion
175175
@@ -187,9 +187,11 @@ private IEnumerator ProcessPatch()
187187
188188 logger . Info ( "Starting patch thread" ) ;
189189
190+ IEnumerable < IProtoUrlConfig > databaseConfigs = null ;
191+
190192 ITaskStatus patchThread = BackgroundTask . Start ( delegate
191193 {
192- applier . ApplyPatches ( GameDatabase . Instance . root . AllConfigFiles . ToArray ( ) , patchList ) ;
194+ databaseConfigs = applier . ApplyPatches ( patchList ) ;
193195 } ) ;
194196
195197 float nextYield = Time . realtimeSinceStartup + yieldInterval ;
@@ -236,6 +238,22 @@ float updateTimeRemaining()
236238 FatalErrorHandler . HandleFatalError ( "The patch runner threw an exception" ) ;
237239 yield break ;
238240 }
241+ if ( databaseConfigs == null )
242+ {
243+ progress . Error ( "The patcher returned a null collection of configs" ) ;
244+ FatalErrorHandler . HandleFatalError ( "The patcher returned a null collection of configs" ) ;
245+ yield break ;
246+ }
247+
248+ foreach ( UrlDir . UrlFile file in GameDatabase . Instance . root . AllConfigFiles )
249+ {
250+ file . configs . Clear ( ) ;
251+ }
252+
253+ foreach ( IProtoUrlConfig protoConfig in databaseConfigs )
254+ {
255+ protoConfig . UrlFile . AddConfig ( protoConfig . Node ) ;
256+ }
239257
240258 logger . Info ( "Done patching" ) ;
241259 yield return null ;
@@ -1219,28 +1237,24 @@ private static ConfigNode RecurseNodeSearch(string path, NodeStack nodeStack, Pa
12191237 // @XXXXX
12201238 if ( root )
12211239 {
1222- IEnumerable < UrlDir . UrlConfig > urlConfigs = context . databaseRoot . GetConfigs ( nodeType ) ;
1223- if ( ! urlConfigs . Any ( ) )
1240+ bool foundNodeType = false ;
1241+ foreach ( IProtoUrlConfig urlConfig in context . databaseConfigs )
12241242 {
1225- context . logger . Warning ( "Can't find nodeType:" + nodeType ) ;
1226- return null ;
1227- }
1243+ ConfigNode node = urlConfig . Node ;
12281244
1229- if ( nodeName == null )
1230- {
1231- nodeStack = new NodeStack ( urlConfigs . First ( ) . config ) ;
1232- }
1233- else
1234- {
1235- foreach ( UrlDir . UrlConfig url in urlConfigs )
1245+ if ( node . name != nodeType ) continue ;
1246+
1247+ foundNodeType = true ;
1248+
1249+ if ( nodeName == null || ( node . GetValue ( "name" ) is string testNodeName && WildcardMatch ( testNodeName , nodeName ) ) )
12361250 {
1237- if ( url . config . HasValue ( "name" ) && WildcardMatch ( url . config . GetValue ( "name" ) , nodeName ) )
1238- {
1239- nodeStack = new NodeStack ( url . config ) ;
1240- break ;
1241- }
1251+ nodeStack = new NodeStack ( node ) ;
1252+ break ;
12421253 }
12431254 }
1255+
1256+ if ( ! foundNodeType ) context . logger . Warning ( "Can't find nodeType:" + nodeType ) ;
1257+ if ( nodeStack == null ) return null ;
12441258 }
12451259 else
12461260 {
@@ -1305,7 +1319,6 @@ private static ConfigNode.Value RecurseVariableSearch(string path, NodeStack nod
13051319
13061320 string subName = path . Substring ( 1 , nextSep - 1 ) ;
13071321 string nodeType , nodeName ;
1308- UrlDir . UrlConfig target = null ;
13091322
13101323 if ( subName . Contains ( "[" ) )
13111324 {
@@ -1317,32 +1330,27 @@ private static ConfigNode.Value RecurseVariableSearch(string path, NodeStack nod
13171330 {
13181331 // @NODETYPE/
13191332 nodeType = subName ;
1320- nodeName = string . Empty ;
1333+ nodeName = null ;
13211334 }
13221335
1323- IEnumerable < UrlDir . UrlConfig > urlConfigs = context . databaseRoot . GetConfigs ( nodeType ) ;
1324- if ( ! urlConfigs . Any ( ) )
1336+ bool foundNodeType = false ;
1337+ foreach ( IProtoUrlConfig urlConfig in context . databaseConfigs )
13251338 {
1326- context . logger . Warning ( "Can't find nodeType:" + nodeType ) ;
1327- return null ;
1328- }
1339+ ConfigNode node = urlConfig . Node ;
13291340
1330- if ( nodeName == string . Empty )
1331- {
1332- target = urlConfigs . First ( ) ;
1333- }
1334- else
1335- {
1336- foreach ( UrlDir . UrlConfig url in urlConfigs )
1341+ if ( node . name != nodeType ) continue ;
1342+
1343+ foundNodeType = true ;
1344+
1345+ if ( nodeName == null || ( node . GetValue ( "name" ) is string testNodeName && WildcardMatch ( testNodeName , nodeName ) ) )
13371346 {
1338- if ( url . config . HasValue ( "name" ) && WildcardMatch ( url . config . GetValue ( "name" ) , nodeName ) )
1339- {
1340- target = url ;
1341- break ;
1342- }
1347+ return RecurseVariableSearch ( path . Substring ( nextSep + 1 ) , new NodeStack ( node ) , context ) ;
13431348 }
13441349 }
1345- return target != null ? RecurseVariableSearch ( path . Substring ( nextSep + 1 ) , new NodeStack ( target . config ) , context ) : null ;
1350+
1351+ if ( ! foundNodeType ) context . logger . Warning ( "Can't find nodeType:" + nodeType ) ;
1352+
1353+ return null ;
13461354 }
13471355 if ( path . StartsWith ( "../" ) )
13481356 {
0 commit comments