bool LoadPersistedData(void) { CharacterData *characterData; int floor = 0; bool useWorkerApp = false; if(!persist_exists(PERSISTED_IS_DATA_SAVED) || !persist_read_bool(PERSISTED_IS_DATA_SAVED)) return false; if(!IsPersistedDataCurrent()) { WARNING_LOG("Persisted data does not match current version, clearing."); ClearPersistedData(); return false; } ProfileLogStart("LoadPersistedData"); INFO_LOG("Loading persisted data."); characterData = GetCharacter(); persist_read_data(PERSISTED_CHARACTER_DATA, characterData, sizeof(CharacterData)); floor = persist_read_int(PERSISTED_CURRENT_FLOOR); SetCurrentFloor(floor); persist_read_data(PERSISTED_ITEM_DATA, GetItemsOwned(), GetSizeOfItemsOwned()); SetStatPointsPurchased(persist_read_int(PERSISTED_STAT_POINTS_PURCHASED)); SetVibration(persist_read_bool(PERSISTED_VIBRATION)); SetFastMode(persist_read_bool(PERSISTED_FAST_MODE)); if(persist_exists(PERSISTED_USE_OLD_ASSETS)) SetUseOldAssets(persist_read_bool(PERSISTED_USE_OLD_ASSETS)); useWorkerApp = persist_read_bool(PERSISTED_WORKER_APP); if(useWorkerApp) { AttemptToLaunchWorkerApp(); } else { // If the user has launched the worker app outside of MiniDungeon, // they want it on. if(WorkerIsRunning()) SetWorkerApp(true); } SetWorkerCanLaunch(persist_read_bool(PERSISTED_WORKER_CAN_LAUNCH)); if(persist_read_bool(PERSISTED_IN_COMBAT)) { int currentMonster = persist_read_int(PERSISTED_MONSTER_TYPE); int currentMonsterHealth = persist_read_int(PERSISTED_MONSTER_HEALTH); ResumeBattle(currentMonster, currentMonsterHealth); } ProfileLogStop("LoadPersistedData"); if(characterData->level == 0) { // Something bad happened to the data, possible due to a watch crash ERROR_LOG("Persisted data was broken somehow, clearing"); ClearPersistedData(); return false; } return true; }
bool LoadPersistedData(void) { CharacterData *characterData; int floor = 0; if(!persist_exists(PERSISTED_IS_DATA_SAVED) || !persist_read_bool(PERSISTED_IS_DATA_SAVED)) return false; if(!IsPersistedDataCurrent()) { WARNING_LOG("Persisted data does not match current version, clearing."); ClearPersistedData(); return false; } INFO_LOG("Loading persisted data."); characterData = GetCharacter(); persist_read_data(PERSISTED_CHARACTER_DATA, characterData, sizeof(CharacterData)); floor = persist_read_int(PERSISTED_CURRENT_FLOOR); SetCurrentFloor(floor); uint8_t * itemsOwned = malloc(sizeof(uint8_t) * ITEM_TYPE_COUNT); persist_read_data(PERSISTED_ITEM_DATA, itemsOwned, sizeof(itemsOwned)); SetItemOwned(itemsOwned); free(itemsOwned); SetStatPointsPurchased(persist_read_int(PERSISTED_STAT_POINTS_PURCHASED)); SetVibration(persist_read_bool(PERSISTED_VIBRATION)); SetFastMode(persist_read_bool(PERSISTED_FAST_MODE)); SetEasyMode(persist_read_bool(PERSISTED_EASY_MODE)); CardSave saves[NB_TYPE_CARDS]; persist_read_data(PERSISTED_CARD_DECK, saves, sizeof(saves)); SetCardSave(saves); SetEntriesSize(persist_read_int(PERSISTED_ENTRIES_SIZE)); if(persist_read_bool(PERSISTED_IN_COMBAT)) { persist_read_data(PERSISTED_MONSTER_TYPE, GetCurMonster(), sizeof(MonsterInfo)); ResumeBattle(); } if(characterData->level == 0) { // Something bad happened to the data, possible due to a watch crash ERROR_LOG("Persisted data was broken somehow, clearing"); ClearPersistedData(); return false; } return true; }