| 70 | } |
| 71 | |
| 72 | CSavedGameWrapper::CSavedGameWrapper(LPCSTR saved_game_name) |
| 73 | { |
| 74 | string_path file_name; |
| 75 | saved_game_full_name(saved_game_name, file_name); |
| 76 | R_ASSERT3(FS.exist(file_name), "There is no saved game ", file_name); |
| 77 | |
| 78 | u32 magic = 0; |
| 79 | |
| 80 | IReader* stream = FS.r_open(file_name); |
| 81 | if (!valid_saved_game(*stream, magic)) |
| 82 | { |
| 83 | FS.r_close(stream); |
| 84 | CALifeTimeManager time_manager(alife_section); |
| 85 | m_game_time = time_manager.game_time(); |
| 86 | m_actor_health = 1.f; |
| 87 | m_level_id = _LEVEL_ID(-1); |
| 88 | m_level_name = ""; |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | u32 source_count = stream->r_u32(); |
| 93 | void* source_data = xr_malloc(source_count); |
| 94 | if (magic == 0) |
| 95 | R_ASSERT(ZSTD_decompress(source_data, source_count, stream->pointer(), stream->length() - 3 * sizeof(u32)) == source_count); |
| 96 | else |
| 97 | rtc_decompress(source_data, source_count, stream->pointer(), stream->length() - 3 * sizeof(u32)); |
| 98 | FS.r_close(stream); |
| 99 | |
| 100 | IReader reader(source_data, source_count); |
| 101 | |
| 102 | { |
| 103 | CALifeTimeManager time_manager(alife_section); |
| 104 | time_manager.load(reader); |
| 105 | m_game_time = time_manager.game_time(); |
| 106 | } |
| 107 | |
| 108 | { |
| 109 | R_ASSERT2(reader.find_chunk(OBJECT_CHUNK_DATA), "Can't find chunk OBJECT_CHUNK_DATA!"); |
| 110 | #ifdef DEBUG |
| 111 | u32 count = |
| 112 | #endif |
| 113 | reader.r_u32(); |
| 114 | VERIFY(count > 0); |
| 115 | CSE_ALifeDynamicObject* object = CALifeObjectRegistry::get_object(reader); |
| 116 | VERIFY(object->ID == 0); |
| 117 | CSE_ALifeCreatureActor* actor = smart_cast<CSE_ALifeCreatureActor*>(object); |
| 118 | VERIFY(actor); |
| 119 | |
| 120 | m_actor_health = actor->g_Health(); |
| 121 | |
| 122 | IReader* R = reader.open_chunk(SPAWN_CHUNK_DATA); |
| 123 | R_ASSERT(R, "Spawn version mismatch - REBUILD SPAWN!"); |
| 124 | |
| 125 | string_path spawn_file_name; |
| 126 | { |
| 127 | IReader* sub_chunk = R->open_chunk(0); |
| 128 | if (!sub_chunk) |
| 129 | { |
nothing calls this directly
no test coverage detected