Beispiel #1
0
        public static bool SaveHook(Func <bool> orig)
        {
            bool result = orig();

            AdvancedGameStatsManager.Save();
            return(result);
        }
Beispiel #2
0
 /// <summary>
 /// Disposes SaveAPI <see cref="Hook"/>s, unloads <see cref="AdvancedGameStatsManager"/> and nulls custom <see cref="SaveManager.SaveType"/>s
 /// </summary>
 public static void Unload()
 {
     if (!m_loaded)
     {
         return;
     }
     AdvancedGameSave    = null;
     AdvancedMidGameSave = null;
     saveHook?.Dispose();
     loadHook?.Dispose();
     resetHook?.Dispose();
     beginSessionHook?.Dispose();
     endSessionHook?.Dispose();
     clearAllStatsHook?.Dispose();
     deleteMidGameSaveHook?.Dispose();
     midgameSaveHook?.Dispose();
     invalidateSaveHook?.Dispose();
     revalidateSaveHook?.Dispose();
     frameDelayedInitizlizationHook?.Dispose();
     moveSessionStatsHook?.Dispose();
     prerequisiteHook?.Dispose();
     clearActiveGameDataHook?.Dispose();
     AdvancedGameStatsManager.Save();
     AdvancedGameStatsManager.Unload();
     BreachShopTool.Unload();
     m_loaded = false;
 }
Beispiel #3
0
 /// <summary>
 /// Loads <see cref="AdvancedGameStatsManager"/> from AdvancedGameSave <see cref="SaveManager.SaveType"/>
 /// </summary>
 public static void Load()
 {
     SaveManager.Init();
     if (!SaveManager.Load(DaveAPIManager.AdvancedGameSave, out m_instance, true, 0u, null, null))
     {
         m_instance = new AdvancedGameStatsManager();
     }
 }
Beispiel #4
0
        public static IEnumerator FrameDelayedInitizlizationHook(Func <Dungeon, MidGameSaveData, IEnumerator> orig, Dungeon self, MidGameSaveData data)
        {
            yield return(orig(self, data));

            AdvancedMidGameSaveData midgameSave;

            if (AdvancedGameStatsManager.VerifyAndLoadMidgameSave(out midgameSave, true))
            {
                midgameSave.LoadDataFromMidGameSave();
            }
            yield break;
        }
Beispiel #5
0
 public static void RevalidateSaveHook(Action orig)
 {
     AdvancedGameStatsManager.RevalidateMidgameSave(false);
     orig();
 }
Beispiel #6
0
 public static void InvalidateSaveHook(Action <bool> orig, bool savestats)
 {
     AdvancedGameStatsManager.InvalidateMidgameSave(false);
     orig(savestats);
 }
Beispiel #7
0
 public static void MidgameSaveHook(Action <GlobalDungeonData.ValidTilesets> orig, GlobalDungeonData.ValidTilesets tileset)
 {
     AdvancedGameStatsManager.DoMidgameSave();
     orig(tileset);
 }
Beispiel #8
0
 public static void ResetHook(Action orig)
 {
     AdvancedGameStatsManager.DANGEROUS_ResetAllStats();
     orig();
 }
Beispiel #9
0
 public static void LoadHook(Action orig)
 {
     orig();
     AdvancedGameStatsManager.Load();
 }
Beispiel #10
0
 /// <summary>
 /// Call this method in your <see cref="ETGModule.Init"/> method. Adds SaveAPI <see cref="Hook"/>s, loads <see cref="AdvancedGameStatsManager"/> and setups the custom <see cref="SaveManager.SaveType"/>s
 /// </summary>
 /// <param name="prefix">Mod prefix for SaveTypes</param>
 public static void Setup(string prefix)
 {
     if (m_loaded)
     {
         return;
     }
     AdvancedGameSave = new SaveManager.SaveType
     {
         filePattern       = "Slot{0}." + prefix + "Save",
         encrypted         = true,
         backupCount       = 3,
         backupPattern     = "Slot{0}." + prefix + "Backup.{1}",
         backupMinTimeMin  = 45,
         legacyFilePattern = prefix + "GameStatsSlot{0}.txt"
     };
     AdvancedMidGameSave = new SaveManager.SaveType
     {
         filePattern       = "Active{0}." + prefix + "Game",
         legacyFilePattern = prefix + "ActiveSlot{0}.txt",
         encrypted         = true,
         backupCount       = 0,
         backupPattern     = "Active{0}." + prefix + "Backup.{1}",
         backupMinTimeMin  = 60
     };
     for (int i = 0; i < 3; i++)
     {
         SaveManager.SaveSlot saveSlot = (SaveManager.SaveSlot)i;
         SaveTools.SafeMove(Path.Combine(SaveManager.OldSavePath, string.Format(AdvancedGameSave.legacyFilePattern, saveSlot)), Path.Combine(SaveManager.OldSavePath,
                                                                                                                                             string.Format(AdvancedGameSave.filePattern, saveSlot)), false);
         SaveTools.SafeMove(Path.Combine(SaveManager.OldSavePath, string.Format(AdvancedGameSave.filePattern, saveSlot)), Path.Combine(SaveManager.OldSavePath,
                                                                                                                                       string.Format(AdvancedGameSave.filePattern, saveSlot)), false);
         SaveTools.SafeMove(SaveTools.PathCombine(SaveManager.SavePath, "01", string.Format(AdvancedGameSave.filePattern, saveSlot)), Path.Combine(SaveManager.SavePath,
                                                                                                                                                   string.Format(AdvancedGameSave.filePattern, saveSlot)), true);
     }
     AdvancedGameStatsManager.Load();
     saveHook = new Hook(
         typeof(GameStatsManager).GetMethod("Save", BindingFlags.Public | BindingFlags.Static),
         typeof(DaveAPIManager).GetMethod("SaveHook")
         );
     loadHook = new Hook(
         typeof(GameStatsManager).GetMethod("Load", BindingFlags.Public | BindingFlags.Static),
         typeof(DaveAPIManager).GetMethod("LoadHook")
         );
     resetHook = new Hook(
         typeof(GameStatsManager).GetMethod("DANGEROUS_ResetAllStats", BindingFlags.Public | BindingFlags.Static),
         typeof(DaveAPIManager).GetMethod("ResetHook")
         );
     beginSessionHook = new Hook(
         typeof(GameStatsManager).GetMethod("BeginNewSession", BindingFlags.Public | BindingFlags.Instance),
         typeof(DaveAPIManager).GetMethod("BeginSessionHook")
         );
     endSessionHook = new Hook(
         typeof(GameStatsManager).GetMethod("EndSession", BindingFlags.Public | BindingFlags.Instance),
         typeof(DaveAPIManager).GetMethod("EndSessionHook")
         );
     clearAllStatsHook = new Hook(
         typeof(GameStatsManager).GetMethod("ClearAllStatsGlobal", BindingFlags.Public | BindingFlags.Instance),
         typeof(DaveAPIManager).GetMethod("ClearAllStatsHook")
         );
     deleteMidGameSaveHook = new Hook(
         typeof(SaveManager).GetMethod("DeleteCurrentSlotMidGameSave", BindingFlags.Public | BindingFlags.Static),
         typeof(DaveAPIManager).GetMethod("DeleteMidGameSaveHook")
         );
     midgameSaveHook = new Hook(
         typeof(GameManager).GetMethod("DoMidgameSave", BindingFlags.Public | BindingFlags.Static),
         typeof(DaveAPIManager).GetMethod("MidgameSaveHook")
         );
     invalidateSaveHook = new Hook(
         typeof(GameManager).GetMethod("InvalidateMidgameSave", BindingFlags.Public | BindingFlags.Static),
         typeof(DaveAPIManager).GetMethod("InvalidateSaveHook")
         );
     revalidateSaveHook = new Hook(
         typeof(GameManager).GetMethod("RevalidateMidgameSave", BindingFlags.Public | BindingFlags.Static),
         typeof(DaveAPIManager).GetMethod("RevalidateSaveHook")
         );
     frameDelayedInitizlizationHook = new Hook(
         typeof(Dungeon).GetMethod("FrameDelayedMidgameInitialization", BindingFlags.NonPublic | BindingFlags.Instance),
         typeof(DaveAPIManager).GetMethod("FrameDelayedInitizlizationHook")
         );
     moveSessionStatsHook = new Hook(
         typeof(GameStatsManager).GetMethod("MoveSessionStatsToSavedSessionStats", BindingFlags.Public | BindingFlags.Instance),
         typeof(DaveAPIManager).GetMethod("MoveSessionStatsHook")
         );
     prerequisiteHook = new Hook(
         typeof(DungeonPrerequisite).GetMethod("CheckConditionsFulfilled", BindingFlags.Public | BindingFlags.Instance),
         typeof(DaveAPIManager).GetMethod("PrerequisiteHook")
         );
     clearActiveGameDataHook = new Hook(
         typeof(GameManager).GetMethod("ClearActiveGameData", BindingFlags.Public | BindingFlags.Instance),
         typeof(DaveAPIManager).GetMethod("ClearActiveGameDataHook")
         );
     BreachShopTool.DoSetup();
     m_loaded = true;
 }
Beispiel #11
0
 /// <summary>
 /// Makes a new Instance and deletes <see cref="AdvancedGameStatsManager"/> backups
 /// </summary>
 public static void DANGEROUS_ResetAllStats()
 {
     m_instance = new AdvancedGameStatsManager();
     SaveManager.DeleteAllBackups(DaveAPIManager.AdvancedGameSave, null);
 }