11using System . Collections ;
2- using System . Globalization ;
3- using System . Reflection ;
4- using System . Text . RegularExpressions ;
5- using BepInEx . Logging ;
62using KSP . Game ;
73using KSP . Game . Flow ;
84using PatchManager . Core . Cache ;
128using PatchManager . SassyPatching . Execution ;
139using PatchManager . Shared ;
1410using PatchManager . Shared . Interfaces ;
15- using SpaceWarp ;
1611using SpaceWarp . API . Mods ;
17- using SpaceWarp . API . Versions ;
1812using UnityEngine ;
1913using UnityEngine . AddressableAssets ;
2014using UnityEngine . ResourceManagement . AsyncOperations ;
@@ -33,25 +27,13 @@ internal static class PatchingManager
3327 private static Dictionary < string , List < ( string name , string text ) > > _createdAssets = new ( ) ;
3428
3529 internal static int TotalPatchCount ;
36- private static readonly Regex VersionPreprocessRegex = new Regex ( @"[^0-9.]" ) ;
37- public static void GenerateUniverse ( )
30+ public static void GenerateUniverse ( HashSet < string > singleFileModIds )
3831 {
3932 var loadedPlugins = PluginList . AllEnabledAndActivePlugins . Select ( x => x . Guid ) . ToList ( ) ;
40- UniverseLogMessage ( $ " { string . Join ( ", " , loadedPlugins ) } " ) ;
41- Universe = new ( RegisterPatcher , UniverseLogError , UniverseLogMessage , RegisterGenerator ,
33+ loadedPlugins . AddRange ( singleFileModIds ) ;
34+ Universe = new ( RegisterPatcher , Logging . LogError , Logging . LogMessage , RegisterGenerator ,
4235 loadedPlugins ) ;
4336 _initialLibraryCount = Universe . AllLibraries . Count ;
44-
45- void UniverseLogError ( string error )
46- {
47- Debug . Log ( $ "[PatchManager.Universe] [ERR]: { error } ") ;
48- }
49-
50- void UniverseLogMessage ( string message )
51- {
52-
53- Debug . Log ( $ "[PatchManager.Universe] [MSG]: { message } ") ;
54- }
5537 }
5638
5739 private static void RegisterPatcher ( ITextPatcher patcher )
@@ -69,6 +51,7 @@ private static void RegisterPatcher(ITextPatcher patcher)
6951
7052 Patchers . Add ( patcher ) ;
7153 }
54+
7255 private static void RegisterGenerator ( ITextAssetGenerator generator )
7356 {
7457 for ( var index = 0 ; index < Generators . Count ; index ++ )
@@ -144,6 +127,9 @@ public static void ImportModPatches(string modName, string modFolder)
144127 }
145128 }
146129
130+ public static void ImportSinglePatch ( FileInfo fileInfo )
131+ => Universe . LoadSinglePatchFile ( fileInfo , new DirectoryInfo ( BepInEx . Paths . GameRootPath ) ) ;
132+
147133 public static void RegisterPatches ( )
148134 {
149135 Logging . LogInfo ( $ "Registering all patches!") ;
@@ -207,6 +193,7 @@ private static AsyncOperationHandle<IList<TextAsset>> RebuildCache(string label)
207193 Assets = new List < string > { name }
208194 } ) ;
209195 }
196+
210197 createdAsset . Clear ( ) ;
211198 _createdAssets . Remove ( label ) ;
212199 }
@@ -226,6 +213,7 @@ private static AsyncOperationHandle<IList<TextAsset>> RebuildCache(string label)
226213 {
227214 return ;
228215 }
216+
229217 archiveFiles [ asset . name ] = patchedText ;
230218 labelCacheEntry . Assets . Add ( asset . name ) ;
231219 assetsCacheEntries . Add ( asset . name , new CacheEntry
@@ -259,6 +247,7 @@ void SaveArchive()
259247
260248 Console . WriteLine ( $ "Cache for label '{ label } ' rebuilt.") ;
261249 }
250+
262251 if ( handle . Status == AsyncOperationStatus . Failed && ! unchanged )
263252 {
264253 SaveArchive ( ) ;
@@ -278,21 +267,6 @@ void SaveArchive()
278267 return handle ;
279268 }
280269
281- private static bool IsUsefulKey ( string key )
282- {
283- key = key . Replace ( ".bundle" , "" ) . Replace ( ".json" , "" ) ;
284- if ( int . TryParse ( key , NumberStyles . Number , CultureInfo . InvariantCulture , out _ ) )
285- {
286- return false ;
287- }
288- if ( key . Length == 32 )
289- {
290- return ! key . All ( x => "0123456789abcdef" . Contains ( x ) ) ;
291- }
292-
293- return ! key . EndsWith ( ".prefab" ) && ! key . EndsWith ( ".png" ) ;
294- }
295-
296270 public static void CreateNewAssets ( Action resolve , Action < string > reject )
297271 {
298272 foreach ( var generator in Generators )
@@ -317,34 +291,40 @@ public static void CreateNewAssets(Action resolve, Action<string> reject)
317291
318292 public static void RebuildAllCache ( Action resolve , Action < string > reject )
319293 {
320-
321-
322294 var distinctKeys = Universe . LoadedLabels . Concat ( _createdAssets . Keys ) . Distinct ( ) . ToList ( ) ;
323295
324296 LoadingBarPatch . InjectPatchManagerTips = true ;
297+
325298 GenericFlowAction CreateIndexedFlowAction ( int idx )
326299 {
327300 return new GenericFlowAction (
328301 $ "Patch Manager: { distinctKeys [ idx ] } ",
329- ( resolve2 , reject2 ) =>
302+ ( resolve2 , _ ) =>
330303 {
331304 var handle = RebuildCache ( distinctKeys [ idx ] ) ;
332305 var killTips = false ;
333306 if ( idx + 1 < distinctKeys . Count )
334- GameManager . Instance . LoadingFlow . _flowActions . Insert ( GameManager . Instance . LoadingFlow . _flowIndex + 1 ,
335- CreateIndexedFlowAction ( idx + 1 ) ) ;
307+ {
308+ GameManager . Instance . LoadingFlow . _flowActions . Insert (
309+ GameManager . Instance . LoadingFlow . _flowIndex + 1 ,
310+ CreateIndexedFlowAction ( idx + 1 )
311+ ) ;
312+ }
336313 else
337314 {
338315 killTips = true ;
339316 }
340- CoroutineUtil . Instance . DoCoroutine ( WaitForCacheRebuildSingleHandle ( handle , resolve2 , killTips ) ) ;
317+
318+ CoroutineUtil . Instance . DoCoroutine ( WaitForCacheRebuildSingleHandle ( handle , resolve2 , killTips ) ) ;
341319 } ) ;
342320 }
343321
344322 if ( distinctKeys . Count > 0 )
345323 {
346- GameManager . Instance . LoadingFlow . _flowActions . Insert ( GameManager . Instance . LoadingFlow . _flowIndex + 1 ,
347- CreateIndexedFlowAction ( 0 ) ) ;
324+ GameManager . Instance . LoadingFlow . _flowActions . Insert (
325+ GameManager . Instance . LoadingFlow . _flowIndex + 1 ,
326+ CreateIndexedFlowAction ( 0 )
327+ ) ;
348328 }
349329
350330 resolve ( ) ;
0 commit comments