geode/loader/src/hooks/save.cpp

57 lines
1.5 KiB
C++
Raw Normal View History

2022-07-30 12:24:03 -04:00
#include <Geode/loader/Loader.hpp>
using namespace geode::prelude;
2022-07-30 12:24:03 -04:00
#include <Geode/modify/AppDelegate.hpp>
#include <Geode/modify/CCApplication.hpp>
namespace {
void saveModData() {
2023-12-23 05:32:44 -05:00
log::info("Saving mod data...");
log::pushNest();
2022-07-30 12:24:03 -04:00
2023-12-23 05:32:44 -05:00
auto begin = std::chrono::high_resolution_clock::now();
2022-07-30 12:24:03 -04:00
2023-12-23 05:32:44 -05:00
(void)Loader::get()->saveData();
2023-11-11 11:38:01 -05:00
2023-12-23 05:32:44 -05:00
auto end = std::chrono::high_resolution_clock::now();
auto time = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count();
log::info("Took {}s", static_cast<float>(time) / 1000.f);
2023-11-11 11:38:01 -05:00
2023-12-23 05:32:44 -05:00
log::popNest();
}
}
struct SaveLoader : Modify<SaveLoader, AppDelegate> {
GEODE_FORWARD_COMPAT_DISABLE_HOOKS("save moved to CCApplication::gameDidSave()")
void trySaveGame(bool p0) {
saveModData();
2023-12-23 05:32:44 -05:00
return AppDelegate::trySaveGame(p0);
}
};
2024-01-22 10:42:27 -05:00
#ifdef GEODE_IS_WINDOWS
struct FallbackSaveLoader : Modify<FallbackSaveLoader, CCApplication> {
GEODE_FORWARD_COMPAT_ENABLE_HOOKS("")
void gameDidSave() {
saveModData();
return CCApplication::gameDidSave();
}
};
2024-01-22 10:42:27 -05:00
2024-01-28 18:48:26 -05:00
#endif
#ifdef GEODE_IS_ANDROID
#include <Geode/modify/FileOperation.hpp>
// redirects the save path to what geode knows, in case launcher's fopen hook fails
struct FileOperationOverride : Modify<FileOperationOverride, FileOperation> {
gd::string getFilePath() {
2024-01-28 19:52:25 -05:00
return dirs::getSaveDir().string() + "/";
2024-01-28 18:48:26 -05:00
}
};
#endif