Skip to content

Commit

Permalink
Add Save-Load UI. Also backported to 1.1 and 1.2, because I'm nice.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Byass committed Jul 21, 2021
1 parent adfbe71 commit 1d4c79c
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 722 deletions.
Binary file modified 1.1-1.2/Assemblies/BetterLoading.dll
Binary file not shown.
Binary file modified 1.3/Assemblies/BetterLoading.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>BetterLoading</identifier>
<version>3.1.3.2</version>
<version>3.2.0.0</version>
<loadBefore>
<li>Core &gt;= 1.0</li>
<li>Startupimpact</li>
Expand Down
264 changes: 5 additions & 259 deletions Source/BetterLoadingMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using BetterLoading.Stage.SaveLoad;
using HarmonyLib;
using JetBrains.Annotations;
using RimWorld;
Expand Down Expand Up @@ -296,6 +297,10 @@ public static void OnGameLoadStart()
LoadingScreen = Object.FindObjectOfType<Root_Play>().gameObject
.AddComponent<LoadingScreen>();
InitLoadingScreenBG();

//Try and work out how many maps we have
LoadMaps.CountMaps();

LoadingScreen!.StartSaveLoad();
}

Expand All @@ -320,67 +325,6 @@ public static void OnClearPlayData()

#region Save Game Loading Patches

[HarmonyPatch(typeof(Game))]
[HarmonyPatch(nameof(Game.LoadGame))]
[UsedImplicitly]
public class LoadGamePatch
{
[UsedImplicitly]
public static void Prefix()
{
Resources.FindObjectsOfTypeAll<Root_Play>()[0].gameObject
.AddComponent<LoadingScreen>();
LogMsg("Loading Screen Manager :: Load Small Components :: Start");

LoadingScreen.Instance.shouldShow = true;
LoadingScreen.Instance.currentStage = EnumLoadingStage.LoadSmallComponents;
}
}

[HarmonyPatch(typeof(World))]
[HarmonyPatch(nameof(World.ExposeData))]
[UsedImplicitly]
public class LoadWorldPatch
{
[UsedImplicitly]
public static void Prefix()
{
if (LoadingScreen.Instance.currentStage == EnumLoadingStage.LoadSmallComponents)
{
LogMsg("Loading Screen Manager :: Load World Map :: Start");
LoadingScreen.Instance.currentStage = EnumLoadingStage.LoadWorldMap;
}
}
}

[HarmonyPatch(typeof(WorldGenerator))]
[HarmonyPatch(nameof(WorldGenerator.GenerateFromScribe))]
[UsedImplicitly]
public class GenerateWorldPatch
{
[UsedImplicitly]
public static void Prefix()
{
LogMsg("Loading Screen Manager :: Generate World Data :: Start");
LoadingScreen.Instance.currentStage = EnumLoadingStage.GenerateWorldData;
LoadingScreen.Instance.numWorldGeneratorsToRun = WorldGenerator.GenStepsInOrder.Count() - 2;
}
}

[HarmonyPatch(typeof(WorldGenerator))]
[HarmonyPatch(nameof(WorldGenerator.GenerateWithoutWorldData))]
[UsedImplicitly]
public class GenerateWorldPatch2
{
[UsedImplicitly]
public static void Prefix()
{
LogMsg("Loading Screen Manager :: Generate World Data :: Start");
LoadingScreen.Instance.currentStage = EnumLoadingStage.GenerateWorldData;
LoadingScreen.Instance.numWorldGeneratorsToRun = WorldGenerator.GenStepsInOrder.Count() - 2;
}
}

[HarmonyPatch(typeof(WorldGenStep))]
[HarmonyPatch(nameof(WorldGenStep.GenerateFromScribe))]
[UsedImplicitly]
Expand All @@ -407,204 +351,6 @@ public static void Prefix(WorldGenStep __instance)
}
}

[HarmonyPatch(typeof(World))]
[HarmonyPatch(nameof(World.FinalizeInit))]
[UsedImplicitly]
public class WorldFinalizePatch
{
[UsedImplicitly]
public static void Prefix()
{
LogMsg("Loading Screen Manager :: Finalize World Data :: Start");
LoadingScreen.Instance.currentStage = EnumLoadingStage.FinalizeWorld;
}
}

[HarmonyPatch(typeof(Map))]
[HarmonyPatch(nameof(Map.ExposeData))]
[UsedImplicitly]
public class MapExposePatch
{
[UsedImplicitly]
public static void Prefix(Map __instance)
{
if (LoadingScreen.Instance.currentStage >= EnumLoadingStage.FinalizeWorld &&
LoadingScreen.Instance.currentStage <= EnumLoadingStage.LoadMaps_LoadData)
{
LogMsg("Loading Screen Manager :: Load Map (Construct Components) :: Start");
LoadingScreen.Instance.currentStage = EnumLoadingStage.LoadMaps_ConstructComponents;
LoadingScreen.Instance.maps.Add(__instance);
}
}
}

[HarmonyPatch(typeof(Map))]
[HarmonyPatch("ExposeComponents")]
[UsedImplicitly]
public class MapLoadPatch
{
[UsedImplicitly]
public static void Prefix()
{
if (LoadingScreen.Instance.currentStage == EnumLoadingStage.LoadMaps_ConstructComponents)
{
LogMsg("Loading Screen Manager :: Load Map (Load Components) :: Start");
LoadingScreen.Instance.currentStage = EnumLoadingStage.LoadMaps_LoadComponents;
}
}
}

[HarmonyPatch(typeof(MapFileCompressor))]
[HarmonyPatch(nameof(MapFileCompressor.ExposeData))]
[UsedImplicitly]
public class MapLoadCompressedPatch
{
[UsedImplicitly]
public static void Prefix()
{
if (LoadingScreen.Instance.currentStage == EnumLoadingStage.LoadMaps_LoadComponents)
{
LogMsg("Loading Screen Manager :: Load Map (Load Objects) :: Start");
LoadingScreen.Instance.currentStage = EnumLoadingStage.LoadMaps_LoadData;
}
}
}

[HarmonyPatch(typeof(CameraDriver))]
[HarmonyPatch(nameof(CameraDriver.Expose))]
[UsedImplicitly]
public class CameraLoadPatch
{
[UsedImplicitly]
public static void Prefix()
{
if (LoadingScreen.Instance.currentStage == EnumLoadingStage.LoadMaps_LoadData)
{
LogMsg("Loading Screen Manager :: Init Camera :: Start");
LoadingScreen.Instance.currentStage = EnumLoadingStage.InitCamera;
}
}
}

[HarmonyPatch(typeof(ScribeLoader))]
[HarmonyPatch(nameof(ScribeLoader.FinalizeLoading))]
[UsedImplicitly]
public class ResolveSaveFileReferencesPatch
{
[UsedImplicitly]
public static void Prefix()
{
if (LoadingScreen.Instance.currentStage != EnumLoadingStage.InitCamera) return;

LogMsg("Loading Screen Manager :: Resolve Cross-References :: Start");
LoadingScreen.Instance.currentStage = EnumLoadingStage.ResolveSaveFileCrossReferences;
}
}

[HarmonyPatch(typeof(Map))]
[HarmonyPatch(nameof(Map.FinalizeLoading))]
[UsedImplicitly]
public class MapFinalizeLoadPatch
{
[UsedImplicitly]
public static void Prefix(Map __instance)
{
LogMsg("Loading Screen Manager :: Spawn Things (Non-Buildings) :: Start");
LoadingScreen.Instance.currentStage = EnumLoadingStage.SpawnThings_NonBuildings;
LoadingScreen.Instance.mapIndexSpawningItems++;

//Reflection, fuck yeah!
// LoadingScreen.Instance.numObjectsToSpawnCurrentMap = __instance.compressor.ThingsToSpawnAfterLoad().Count() +
// Traverse.Create(__instance).Field<List<Thing>>("loadedFullThings")
// .Value.Count;
// LoadingScreen.Instance.numObjectsSpawnedCurrentMap = 0;
}
}

[HarmonyPatch(typeof(GenSpawn))]
[HarmonyPatch(nameof(GenSpawn.Spawn))]
[HarmonyPatch(new[]
{typeof(Thing), typeof(IntVec3), typeof(Map), typeof(Rot4), typeof(WipeMode), typeof(bool)})]
[UsedImplicitly]
public class GenSpawnSpawnPatch
{
[UsedImplicitly]
public static void Prefix()
{
if (LoadingScreen.Instance.currentStage == EnumLoadingStage.SpawnThings_NonBuildings)
LoadingScreen.Instance.numObjectsSpawnedCurrentMap++;
}
}

[HarmonyPatch(typeof(GenSpawn))]
[HarmonyPatch(nameof(GenSpawn.SpawnBuildingAsPossible))]
[UsedImplicitly]
public class GenSpawnSpawnBuildingPatch
{
[UsedImplicitly]
public static void Prefix(Map __instance)
{
if (LoadingScreen.Instance.currentStage == EnumLoadingStage.SpawnThings_NonBuildings)
{
LogMsg("Loading Screen Manager :: Spawn Things (Buildings) :: Start");
LoadingScreen.Instance.currentStage = EnumLoadingStage.SpawnThings_Buildings;
}

if (LoadingScreen.Instance.currentStage == EnumLoadingStage.SpawnThings_Buildings)
LoadingScreen.Instance.numObjectsSpawnedCurrentMap++;
}
}

[HarmonyPatch(typeof(GenPlace))]
[HarmonyPatch(nameof(GenPlace.TryPlaceThing))]
[HarmonyPatch(new[]
{
typeof(Thing), typeof(IntVec3), typeof(Map), typeof(ThingPlaceMode), typeof(Action<Thing, int>),
typeof(Predicate<IntVec3>)
})]
[UsedImplicitly]
public class GenPlaceTryPlacePatch
{
[UsedImplicitly]
public static void Prefix()
{
if (LoadingScreen.Instance.currentStage == EnumLoadingStage.SpawnThings_Buildings)
{
LogMsg("Loading Screen Manager :: Spawn Things (Back-Compat) :: Start");
LoadingScreen.Instance.currentStage = EnumLoadingStage.SpawnThings_BackCompat;
}

if (LoadingScreen.Instance.currentStage == EnumLoadingStage.SpawnThings_BackCompat)
LoadingScreen.Instance.numObjectsSpawnedCurrentMap++;
}
}

[HarmonyPatch(typeof(Map))]
[HarmonyPatch(nameof(Map.FinalizeInit))]
[UsedImplicitly]
public class MapFinalizeInitPatch
{
[UsedImplicitly]
public static void Prefix()
{
LogMsg("Loading Screen Manager :: Spawn Things (Rebuild/Recalc) :: Start");
LoadingScreen.Instance.currentStage = EnumLoadingStage.SpawnThings_RebuildRecalc;
}
}

[HarmonyPatch(typeof(Game))]
[HarmonyPatch(nameof(Game.FinalizeInit))]
[UsedImplicitly]
public class GameFinalizeInitPatch
{
[UsedImplicitly]
public static void Prefix()
{
LogMsg("Loading Screen Manager :: Finalize Load :: Start");
LoadingScreen.Instance.currentStage = EnumLoadingStage.FinalizeLoad;
}
}

#endregion
}
}
Loading

0 comments on commit 1d4c79c

Please sign in to comment.