| 4857 | } |
| 4858 | |
| 4859 | bool Game_Interpreter::CommandManiacControlGlobalSave(lcf::rpg::EventCommand const& com) { |
| 4860 | if (!Player::IsPatchManiac()) { |
| 4861 | return true; |
| 4862 | } |
| 4863 | |
| 4864 | int operation = com.parameters[0]; |
| 4865 | |
| 4866 | auto load_global_save = [&]() { |
| 4867 | Main_Data::global_save_opened = true; |
| 4868 | |
| 4869 | // Load |
| 4870 | auto lgs = FileFinder::Save().OpenFile("Save.lgs"); |
| 4871 | if (!lgs) { |
| 4872 | return; |
| 4873 | } |
| 4874 | |
| 4875 | lcf::LcfReader reader(lgs); |
| 4876 | std::string header; |
| 4877 | reader.ReadString(header, reader.ReadInt()); |
| 4878 | if (header.length() != 13 || header != "LcfGlobalSave") { |
| 4879 | Output::Debug("This is not a valid global save."); |
| 4880 | return; |
| 4881 | } |
| 4882 | |
| 4883 | lcf::LcfReader::Chunk chunk; |
| 4884 | |
| 4885 | while (!reader.Eof()) { |
| 4886 | chunk.ID = reader.ReadInt(); |
| 4887 | chunk.length = reader.ReadInt(); |
| 4888 | switch (chunk.ID) { |
| 4889 | case 1: { |
| 4890 | Game_Switches::Switches_t switches; |
| 4891 | reader.Read(switches, chunk.length); |
| 4892 | Main_Data::game_switches_global->SetData(std::move(switches)); |
| 4893 | break; |
| 4894 | } |
| 4895 | case 2: { |
| 4896 | Game_Variables::Variables_t variables; |
| 4897 | reader.Read(variables, chunk.length); |
| 4898 | Main_Data::game_variables_global->SetData(std::move(variables)); |
| 4899 | break; |
| 4900 | } |
| 4901 | default: |
| 4902 | reader.Skip(chunk, "CommandManiacControlGlobalSave"); |
| 4903 | } |
| 4904 | } |
| 4905 | }; |
| 4906 | |
| 4907 | if (operation == 0) { |
| 4908 | // Open |
| 4909 | load_global_save(); |
| 4910 | } else if (operation == 1) { |
| 4911 | // Close |
| 4912 | Main_Data::global_save_opened = false; |
| 4913 | } else if (operation == 2 || operation == 3) { |
| 4914 | // 2: Save (write to file) |
| 4915 | // 3: Save and Close |
| 4916 | if (!Main_Data::global_save_opened) { |