| 1132 | } |
| 1133 | |
| 1134 | void Player::LoadSavegame(const std::string& save_name, int save_id) { |
| 1135 | Output::Debug("Loading Save {}", save_name); |
| 1136 | |
| 1137 | bool load_on_map = Scene::instance->type == Scene::Map; |
| 1138 | |
| 1139 | if (!load_on_map) { |
| 1140 | Main_Data::game_system->BgmFade(800); |
| 1141 | // We erase the screen now before loading the saved game. This prevents an issue where |
| 1142 | // if the save game has a different system graphic, the load screen would change before |
| 1143 | // transitioning out. |
| 1144 | Transition::instance().InitErase(Transition::TransitionFadeOut, Scene::instance.get(), 6); |
| 1145 | } |
| 1146 | |
| 1147 | auto title_scene = Scene::Find(Scene::Title); |
| 1148 | if (title_scene) { |
| 1149 | static_cast<Scene_Title*>(title_scene.get())->OnGameStart(); |
| 1150 | } |
| 1151 | |
| 1152 | auto save_stream = FileFinder::Save().OpenInputStream(save_name); |
| 1153 | if (!save_stream) { |
| 1154 | Output::Error("Error loading {}", save_name); |
| 1155 | return; |
| 1156 | } |
| 1157 | |
| 1158 | std::unique_ptr<lcf::rpg::Save> save = lcf::LSD_Reader::Load(save_stream, encoding); |
| 1159 | |
| 1160 | if (!save.get()) { |
| 1161 | Output::ErrorStr(lcf::LcfReader::GetError()); |
| 1162 | return; |
| 1163 | } |
| 1164 | |
| 1165 | std::stringstream verstr; |
| 1166 | int ver = save->easyrpg_data.version; |
| 1167 | if (ver == 0) { |
| 1168 | verstr << "RPG_RT or EasyRPG Player Pre-0.6.0"; |
| 1169 | } else if (ver >= 10000) { |
| 1170 | verstr << "Unknown Engine"; |
| 1171 | } else { |
| 1172 | verstr << "EasyRPG Player "; |
| 1173 | char verbuf[64]; |
| 1174 | snprintf(verbuf, std::size(verbuf), "%d.%d.%d", ver / 1000 % 10, ver / 100 % 10, ver / 10 % 10); |
| 1175 | verstr << verbuf; |
| 1176 | if (ver % 10 > 0) { |
| 1177 | verstr << "." << ver % 10; |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | Output::Debug("Savegame version {} ({})", ver, verstr.str()); |
| 1182 | |
| 1183 | if (ver > PLAYER_SAVEGAME_VERSION) { |
| 1184 | Output::Warning("This savegame was created with {} which is newer than the current version of EasyRPG Player ({})", |
| 1185 | verstr.str(), Version::STRING); |
| 1186 | } |
| 1187 | |
| 1188 | // Compatibility hacks for old EasyRPG Player saves. |
| 1189 | if (save->easyrpg_data.version == 0) { |
| 1190 | // Old savegames accidentally wrote animation_type as continuous for all events. |
| 1191 | save->party_location.animation_type = Game_Character::AnimType::AnimType_non_continuous; |
nothing calls this directly
no test coverage detected