Skip to content

Commit

Permalink
[KK,KKS,AI] Added GameApi.GameBeingSaved
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Dec 4, 2021
1 parent 3f4e2b9 commit afafe58
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/AIAPI/MainGame/GameAPI.Hooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ public static void LoadHook(string fileName)
[HarmonyPatch(typeof(SaveData), nameof(SaveData.SaveFile), typeof(string))]
public static void SaveHook(string path)
{
GameBeingSaved = true;
OnGameBeingSaved(path, "");
}

[HarmonyFinalizer]
[HarmonyPatch(typeof(SaveData), nameof(SaveData.SaveFile), typeof(string))]
public static void SaveHookPost()
{
GameBeingSaved = false;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(TitleLoadScene), "SetWorldData", typeof(WorldData), typeof(bool))]
public static void TitleLoadScene_SetWorldData(WorldData _worldData, bool isAuto)
Expand Down
5 changes: 5 additions & 0 deletions src/AIAPI/MainGame/GameApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public static partial class GameAPI
/// </summary>
public static bool InsideHScene { get; private set; }

/// <summary>
/// True if the game is in process of being saved.
/// </summary>
public static bool GameBeingSaved { get; private set; }

/// <summary>
/// Get all registered behaviours for the game.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions src/KKAPI/MainGame/GameAPI.Hooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,17 @@ public static void LoadHook(string path, string fileName)
[HarmonyPatch(typeof(SaveData), nameof(SaveData.Save), new[] { typeof(string), typeof(string) })]
public static void SaveHook(string path, string fileName)
{
GameBeingSaved = true;
OnGameBeingSaved(path, fileName);
}

[HarmonyFinalizer]
[HarmonyPatch(typeof(SaveData), nameof(SaveData.Save), new[] { typeof(string), typeof(string) })]
public static void SaveHookPost()
{
GameBeingSaved = false;
}

[HarmonyPostfix]
[HarmonyPatch(typeof(HSceneProc), "Start")]
public static void StartProcPost(BaseLoader __instance, ref IEnumerator __result)
Expand Down
7 changes: 6 additions & 1 deletion src/KKAPI/MainGame/GameApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public static partial class GameAPI
/// </summary>
public static bool InsideHScene { get; private set; }

/// <summary>
/// True if the game is in process of being saved.
/// </summary>
public static bool GameBeingSaved { get; private set; }

/// <summary>
/// Get all registered behaviours for the game.
/// </summary>
Expand Down Expand Up @@ -287,7 +292,7 @@ private static void OnGameBeingLoaded(string path, string fileName)
KoikatuAPI.Logger.LogError(e);
}
}

private static void OnGameBeingSaved(string path, string fileName)
{
var args = new GameSaveLoadEventArgs(path, fileName);
Expand Down
8 changes: 8 additions & 0 deletions src/KKSAPI/MainGame/GameAPI.Hooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ public static void LoadHook(string path, string fileName)
[HarmonyPatch(typeof(SaveData.WorldData), nameof(SaveData.WorldData.Save), new[] { typeof(string), typeof(string) })]
public static void SaveHook(string path, string fileName)
{
GameBeingSaved = true;
OnGameBeingSaved(path, fileName);
}

[HarmonyFinalizer]
[HarmonyPatch(typeof(SaveData.WorldData), nameof(SaveData.WorldData.Save), new[] { typeof(string), typeof(string) })]
public static void SaveHookPost()
{
GameBeingSaved = false;
}

[HarmonyPostfix]
[HarmonyPatch(typeof(HSceneProc), "Start")]
public static void StartProcPost(MonoBehaviour __instance, ref IEnumerator __result)
Expand Down
7 changes: 6 additions & 1 deletion src/KKSAPI/MainGame/GameApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public static partial class GameAPI
/// </summary>
public static bool InsideHScene { get; private set; }

/// <summary>
/// True if the game is in process of being saved.
/// </summary>
public static bool GameBeingSaved { get; private set; }

/// <summary>
/// Get all registered behaviours for the game.
/// </summary>
Expand Down Expand Up @@ -507,7 +512,7 @@ public static SaveData.Heroine GetCurrentHeroine()
var hFlag = GameObject.FindObjectOfType<HFlag>();
if (hFlag != null)
return hFlag.GetLeadingHeroine();

var talkScene = GetTalkScene();
if (talkScene != null)
{
Expand Down

0 comments on commit afafe58

Please sign in to comment.