3
3
using System . IO ;
4
4
using System . Linq ;
5
5
using System . Reflection ;
6
+ using BetterLoading . Stage . SaveLoad ;
6
7
using HarmonyLib ;
7
8
using JetBrains . Annotations ;
8
9
using RimWorld ;
@@ -296,6 +297,10 @@ public static void OnGameLoadStart()
296
297
LoadingScreen = Object . FindObjectOfType < Root_Play > ( ) . gameObject
297
298
. AddComponent < LoadingScreen > ( ) ;
298
299
InitLoadingScreenBG ( ) ;
300
+
301
+ //Try and work out how many maps we have
302
+ LoadMaps . CountMaps ( ) ;
303
+
299
304
LoadingScreen ! . StartSaveLoad ( ) ;
300
305
}
301
306
@@ -320,67 +325,6 @@ public static void OnClearPlayData()
320
325
321
326
#region Save Game Loading Patches
322
327
323
- [ HarmonyPatch ( typeof ( Game ) ) ]
324
- [ HarmonyPatch ( nameof ( Game . LoadGame ) ) ]
325
- [ UsedImplicitly ]
326
- public class LoadGamePatch
327
- {
328
- [ UsedImplicitly ]
329
- public static void Prefix ( )
330
- {
331
- Resources . FindObjectsOfTypeAll < Root_Play > ( ) [ 0 ] . gameObject
332
- . AddComponent < LoadingScreen > ( ) ;
333
- LogMsg ( "Loading Screen Manager :: Load Small Components :: Start" ) ;
334
-
335
- LoadingScreen . Instance . shouldShow = true ;
336
- LoadingScreen . Instance . currentStage = EnumLoadingStage . LoadSmallComponents ;
337
- }
338
- }
339
-
340
- [ HarmonyPatch ( typeof ( World ) ) ]
341
- [ HarmonyPatch ( nameof ( World . ExposeData ) ) ]
342
- [ UsedImplicitly ]
343
- public class LoadWorldPatch
344
- {
345
- [ UsedImplicitly ]
346
- public static void Prefix ( )
347
- {
348
- if ( LoadingScreen . Instance . currentStage == EnumLoadingStage . LoadSmallComponents )
349
- {
350
- LogMsg ( "Loading Screen Manager :: Load World Map :: Start" ) ;
351
- LoadingScreen . Instance . currentStage = EnumLoadingStage . LoadWorldMap ;
352
- }
353
- }
354
- }
355
-
356
- [ HarmonyPatch ( typeof ( WorldGenerator ) ) ]
357
- [ HarmonyPatch ( nameof ( WorldGenerator . GenerateFromScribe ) ) ]
358
- [ UsedImplicitly ]
359
- public class GenerateWorldPatch
360
- {
361
- [ UsedImplicitly ]
362
- public static void Prefix ( )
363
- {
364
- LogMsg ( "Loading Screen Manager :: Generate World Data :: Start" ) ;
365
- LoadingScreen . Instance . currentStage = EnumLoadingStage . GenerateWorldData ;
366
- LoadingScreen . Instance . numWorldGeneratorsToRun = WorldGenerator . GenStepsInOrder . Count ( ) - 2 ;
367
- }
368
- }
369
-
370
- [ HarmonyPatch ( typeof ( WorldGenerator ) ) ]
371
- [ HarmonyPatch ( nameof ( WorldGenerator . GenerateWithoutWorldData ) ) ]
372
- [ UsedImplicitly ]
373
- public class GenerateWorldPatch2
374
- {
375
- [ UsedImplicitly ]
376
- public static void Prefix ( )
377
- {
378
- LogMsg ( "Loading Screen Manager :: Generate World Data :: Start" ) ;
379
- LoadingScreen . Instance . currentStage = EnumLoadingStage . GenerateWorldData ;
380
- LoadingScreen . Instance . numWorldGeneratorsToRun = WorldGenerator . GenStepsInOrder . Count ( ) - 2 ;
381
- }
382
- }
383
-
384
328
[ HarmonyPatch ( typeof ( WorldGenStep ) ) ]
385
329
[ HarmonyPatch ( nameof ( WorldGenStep . GenerateFromScribe ) ) ]
386
330
[ UsedImplicitly ]
@@ -407,204 +351,6 @@ public static void Prefix(WorldGenStep __instance)
407
351
}
408
352
}
409
353
410
- [ HarmonyPatch ( typeof ( World ) ) ]
411
- [ HarmonyPatch ( nameof ( World . FinalizeInit ) ) ]
412
- [ UsedImplicitly ]
413
- public class WorldFinalizePatch
414
- {
415
- [ UsedImplicitly ]
416
- public static void Prefix ( )
417
- {
418
- LogMsg ( "Loading Screen Manager :: Finalize World Data :: Start" ) ;
419
- LoadingScreen . Instance . currentStage = EnumLoadingStage . FinalizeWorld ;
420
- }
421
- }
422
-
423
- [ HarmonyPatch ( typeof ( Map ) ) ]
424
- [ HarmonyPatch ( nameof ( Map . ExposeData ) ) ]
425
- [ UsedImplicitly ]
426
- public class MapExposePatch
427
- {
428
- [ UsedImplicitly ]
429
- public static void Prefix ( Map __instance )
430
- {
431
- if ( LoadingScreen . Instance . currentStage >= EnumLoadingStage . FinalizeWorld &&
432
- LoadingScreen . Instance . currentStage <= EnumLoadingStage . LoadMaps_LoadData )
433
- {
434
- LogMsg ( "Loading Screen Manager :: Load Map (Construct Components) :: Start" ) ;
435
- LoadingScreen . Instance . currentStage = EnumLoadingStage . LoadMaps_ConstructComponents ;
436
- LoadingScreen . Instance . maps . Add ( __instance ) ;
437
- }
438
- }
439
- }
440
-
441
- [ HarmonyPatch ( typeof ( Map ) ) ]
442
- [ HarmonyPatch ( "ExposeComponents" ) ]
443
- [ UsedImplicitly ]
444
- public class MapLoadPatch
445
- {
446
- [ UsedImplicitly ]
447
- public static void Prefix ( )
448
- {
449
- if ( LoadingScreen . Instance . currentStage == EnumLoadingStage . LoadMaps_ConstructComponents )
450
- {
451
- LogMsg ( "Loading Screen Manager :: Load Map (Load Components) :: Start" ) ;
452
- LoadingScreen . Instance . currentStage = EnumLoadingStage . LoadMaps_LoadComponents ;
453
- }
454
- }
455
- }
456
-
457
- [ HarmonyPatch ( typeof ( MapFileCompressor ) ) ]
458
- [ HarmonyPatch ( nameof ( MapFileCompressor . ExposeData ) ) ]
459
- [ UsedImplicitly ]
460
- public class MapLoadCompressedPatch
461
- {
462
- [ UsedImplicitly ]
463
- public static void Prefix ( )
464
- {
465
- if ( LoadingScreen . Instance . currentStage == EnumLoadingStage . LoadMaps_LoadComponents )
466
- {
467
- LogMsg ( "Loading Screen Manager :: Load Map (Load Objects) :: Start" ) ;
468
- LoadingScreen . Instance . currentStage = EnumLoadingStage . LoadMaps_LoadData ;
469
- }
470
- }
471
- }
472
-
473
- [ HarmonyPatch ( typeof ( CameraDriver ) ) ]
474
- [ HarmonyPatch ( nameof ( CameraDriver . Expose ) ) ]
475
- [ UsedImplicitly ]
476
- public class CameraLoadPatch
477
- {
478
- [ UsedImplicitly ]
479
- public static void Prefix ( )
480
- {
481
- if ( LoadingScreen . Instance . currentStage == EnumLoadingStage . LoadMaps_LoadData )
482
- {
483
- LogMsg ( "Loading Screen Manager :: Init Camera :: Start" ) ;
484
- LoadingScreen . Instance . currentStage = EnumLoadingStage . InitCamera ;
485
- }
486
- }
487
- }
488
-
489
- [ HarmonyPatch ( typeof ( ScribeLoader ) ) ]
490
- [ HarmonyPatch ( nameof ( ScribeLoader . FinalizeLoading ) ) ]
491
- [ UsedImplicitly ]
492
- public class ResolveSaveFileReferencesPatch
493
- {
494
- [ UsedImplicitly ]
495
- public static void Prefix ( )
496
- {
497
- if ( LoadingScreen . Instance . currentStage != EnumLoadingStage . InitCamera ) return ;
498
-
499
- LogMsg ( "Loading Screen Manager :: Resolve Cross-References :: Start" ) ;
500
- LoadingScreen . Instance . currentStage = EnumLoadingStage . ResolveSaveFileCrossReferences ;
501
- }
502
- }
503
-
504
- [ HarmonyPatch ( typeof ( Map ) ) ]
505
- [ HarmonyPatch ( nameof ( Map . FinalizeLoading ) ) ]
506
- [ UsedImplicitly ]
507
- public class MapFinalizeLoadPatch
508
- {
509
- [ UsedImplicitly ]
510
- public static void Prefix ( Map __instance )
511
- {
512
- LogMsg ( "Loading Screen Manager :: Spawn Things (Non-Buildings) :: Start" ) ;
513
- LoadingScreen . Instance . currentStage = EnumLoadingStage . SpawnThings_NonBuildings ;
514
- LoadingScreen . Instance . mapIndexSpawningItems ++ ;
515
-
516
- //Reflection, fuck yeah!
517
- // LoadingScreen.Instance.numObjectsToSpawnCurrentMap = __instance.compressor.ThingsToSpawnAfterLoad().Count() +
518
- // Traverse.Create(__instance).Field<List<Thing>>("loadedFullThings")
519
- // .Value.Count;
520
- // LoadingScreen.Instance.numObjectsSpawnedCurrentMap = 0;
521
- }
522
- }
523
-
524
- [ HarmonyPatch ( typeof ( GenSpawn ) ) ]
525
- [ HarmonyPatch ( nameof ( GenSpawn . Spawn ) ) ]
526
- [ HarmonyPatch ( new [ ]
527
- { typeof ( Thing ) , typeof ( IntVec3 ) , typeof ( Map ) , typeof ( Rot4 ) , typeof ( WipeMode ) , typeof ( bool ) } ) ]
528
- [ UsedImplicitly ]
529
- public class GenSpawnSpawnPatch
530
- {
531
- [ UsedImplicitly ]
532
- public static void Prefix ( )
533
- {
534
- if ( LoadingScreen . Instance . currentStage == EnumLoadingStage . SpawnThings_NonBuildings )
535
- LoadingScreen . Instance . numObjectsSpawnedCurrentMap ++ ;
536
- }
537
- }
538
-
539
- [ HarmonyPatch ( typeof ( GenSpawn ) ) ]
540
- [ HarmonyPatch ( nameof ( GenSpawn . SpawnBuildingAsPossible ) ) ]
541
- [ UsedImplicitly ]
542
- public class GenSpawnSpawnBuildingPatch
543
- {
544
- [ UsedImplicitly ]
545
- public static void Prefix ( Map __instance )
546
- {
547
- if ( LoadingScreen . Instance . currentStage == EnumLoadingStage . SpawnThings_NonBuildings )
548
- {
549
- LogMsg ( "Loading Screen Manager :: Spawn Things (Buildings) :: Start" ) ;
550
- LoadingScreen . Instance . currentStage = EnumLoadingStage . SpawnThings_Buildings ;
551
- }
552
-
553
- if ( LoadingScreen . Instance . currentStage == EnumLoadingStage . SpawnThings_Buildings )
554
- LoadingScreen . Instance . numObjectsSpawnedCurrentMap ++ ;
555
- }
556
- }
557
-
558
- [ HarmonyPatch ( typeof ( GenPlace ) ) ]
559
- [ HarmonyPatch ( nameof ( GenPlace . TryPlaceThing ) ) ]
560
- [ HarmonyPatch ( new [ ]
561
- {
562
- typeof ( Thing ) , typeof ( IntVec3 ) , typeof ( Map ) , typeof ( ThingPlaceMode ) , typeof ( Action < Thing , int > ) ,
563
- typeof ( Predicate < IntVec3 > )
564
- } ) ]
565
- [ UsedImplicitly ]
566
- public class GenPlaceTryPlacePatch
567
- {
568
- [ UsedImplicitly ]
569
- public static void Prefix ( )
570
- {
571
- if ( LoadingScreen . Instance . currentStage == EnumLoadingStage . SpawnThings_Buildings )
572
- {
573
- LogMsg ( "Loading Screen Manager :: Spawn Things (Back-Compat) :: Start" ) ;
574
- LoadingScreen . Instance . currentStage = EnumLoadingStage . SpawnThings_BackCompat ;
575
- }
576
-
577
- if ( LoadingScreen . Instance . currentStage == EnumLoadingStage . SpawnThings_BackCompat )
578
- LoadingScreen . Instance . numObjectsSpawnedCurrentMap ++ ;
579
- }
580
- }
581
-
582
- [ HarmonyPatch ( typeof ( Map ) ) ]
583
- [ HarmonyPatch ( nameof ( Map . FinalizeInit ) ) ]
584
- [ UsedImplicitly ]
585
- public class MapFinalizeInitPatch
586
- {
587
- [ UsedImplicitly ]
588
- public static void Prefix ( )
589
- {
590
- LogMsg ( "Loading Screen Manager :: Spawn Things (Rebuild/Recalc) :: Start" ) ;
591
- LoadingScreen . Instance . currentStage = EnumLoadingStage . SpawnThings_RebuildRecalc ;
592
- }
593
- }
594
-
595
- [ HarmonyPatch ( typeof ( Game ) ) ]
596
- [ HarmonyPatch ( nameof ( Game . FinalizeInit ) ) ]
597
- [ UsedImplicitly ]
598
- public class GameFinalizeInitPatch
599
- {
600
- [ UsedImplicitly ]
601
- public static void Prefix ( )
602
- {
603
- LogMsg ( "Loading Screen Manager :: Finalize Load :: Start" ) ;
604
- LoadingScreen . Instance . currentStage = EnumLoadingStage . FinalizeLoad ;
605
- }
606
- }
607
-
608
354
#endregion
609
355
}
610
356
}
0 commit comments