|
26 | 26 | #include <cassert> |
27 | 27 | #include "game_interpreter.h" |
28 | 28 | #include "async_handler.h" |
29 | | -#include "audio.h" |
30 | 29 | #include "game_dynrpg.h" |
31 | 30 | #include "filefinder.h" |
32 | 31 | #include "game_destiny.h" |
33 | 32 | #include "game_map.h" |
34 | 33 | #include "game_event.h" |
35 | | -#include "game_enemyparty.h" |
36 | | -#include "game_ineluki.h" |
37 | 34 | #include "game_player.h" |
38 | 35 | #include "game_targets.h" |
39 | 36 | #include "game_switches.h" |
40 | 37 | #include "game_variables.h" |
41 | 38 | #include "game_party.h" |
42 | 39 | #include "game_actors.h" |
| 40 | +#include "game_strings.h" |
43 | 41 | #include "game_system.h" |
44 | 42 | #include "game_message.h" |
45 | 43 | #include "game_pictures.h" |
|
70 | 68 | #include "transition.h" |
71 | 69 | #include "baseui.h" |
72 | 70 | #include "algo.h" |
73 | | -#include "rand.h" |
74 | 71 |
|
75 | 72 | using namespace Game_Interpreter_Shared; |
76 | 73 |
|
@@ -4908,91 +4905,21 @@ bool Game_Interpreter::CommandManiacControlGlobalSave(lcf::rpg::EventCommand con |
4908 | 4905 |
|
4909 | 4906 | int operation = com.parameters[0]; |
4910 | 4907 |
|
4911 | | - auto load_global_save = [&]() { |
4912 | | - Main_Data::global_save_opened = true; |
4913 | | - |
4914 | | - // Load |
4915 | | - auto lgs = FileFinder::Save().OpenFile("Save.lgs"); |
4916 | | - if (!lgs) { |
4917 | | - return; |
4918 | | - } |
4919 | | - |
4920 | | - lcf::LcfReader reader(lgs); |
4921 | | - std::string header; |
4922 | | - reader.ReadString(header, reader.ReadInt()); |
4923 | | - if (header.length() != 13 || header != "LcfGlobalSave") { |
4924 | | - Output::Debug("This is not a valid global save."); |
4925 | | - return; |
4926 | | - } |
4927 | | - |
4928 | | - lcf::LcfReader::Chunk chunk; |
4929 | | - |
4930 | | - while (!reader.Eof()) { |
4931 | | - chunk.ID = reader.ReadInt(); |
4932 | | - chunk.length = reader.ReadInt(); |
4933 | | - switch (chunk.ID) { |
4934 | | - case 1: { |
4935 | | - Game_Switches::Switches_t switches; |
4936 | | - reader.Read(switches, chunk.length); |
4937 | | - Main_Data::game_switches_global->SetData(std::move(switches)); |
4938 | | - break; |
4939 | | - } |
4940 | | - case 2: { |
4941 | | - Game_Variables::Variables_t variables; |
4942 | | - reader.Read(variables, chunk.length); |
4943 | | - Main_Data::game_variables_global->SetData(std::move(variables)); |
4944 | | - break; |
4945 | | - } |
4946 | | - default: |
4947 | | - reader.Skip(chunk, "CommandManiacControlGlobalSave"); |
4948 | | - } |
4949 | | - } |
4950 | | - }; |
4951 | | - |
4952 | 4908 | if (operation == 0) { |
4953 | | - // Open |
4954 | | - load_global_save(); |
| 4909 | + // Open: Fill Global Save with data from Save.lgs |
| 4910 | + // Does nothing when already opened |
| 4911 | + ManiacPatch::GlobalSave::Load(); |
4955 | 4912 | } else if (operation == 1) { |
4956 | 4913 | // Close |
4957 | | - Main_Data::global_save_opened = false; |
| 4914 | + // Marks the file as closed and does nothing |
| 4915 | + ManiacPatch::GlobalSave::Close(); |
4958 | 4916 | } else if (operation == 2 || operation == 3) { |
4959 | 4917 | // 2: Save (write to file) |
4960 | 4918 | // 3: Save and Close |
4961 | | - if (!Main_Data::global_save_opened) { |
4962 | | - return true; |
4963 | | - } |
4964 | | - |
4965 | | - auto savelgs_name = FileFinder::Save().FindFile("Save.lgs"); |
4966 | | - if (savelgs_name.empty()) { |
4967 | | - savelgs_name = "Save.lgs"; |
4968 | | - } |
4969 | | - |
4970 | | - auto lgs_out = FileFinder::Save().OpenOutputStream(savelgs_name); |
4971 | | - if (!lgs_out) { |
4972 | | - Output::Warning("Maniac ControlGlobalSave: Saving failed"); |
4973 | | - return true; |
4974 | | - } |
4975 | | - |
4976 | | - lcf::LcfWriter writer(lgs_out, lcf::EngineVersion::e2k3); |
4977 | | - writer.WriteInt(13); |
4978 | | - const std::string header = "LcfGlobalSave"; |
4979 | | - writer.Write(header); |
4980 | | - writer.WriteInt(1); |
4981 | | - writer.WriteInt(Main_Data::game_switches_global->GetSize()); |
4982 | | - writer.Write(Main_Data::game_switches_global->GetData()); |
4983 | | - writer.WriteInt(2); |
4984 | | - writer.WriteInt(Main_Data::game_variables_global->GetSize() * sizeof(int32_t)); |
4985 | | - writer.Write(Main_Data::game_variables_global->GetData()); |
4986 | | - |
4987 | | - AsyncHandler::SaveFilesystem(); |
4988 | | - |
4989 | | - if (operation == 3) { |
4990 | | - Main_Data::global_save_opened = false; |
4991 | | - } |
| 4919 | + ManiacPatch::GlobalSave::Save(operation == 3); |
4992 | 4920 | } else if (operation == 4 || operation == 5) { |
4993 | | - if (!Main_Data::global_save_opened) { |
4994 | | - load_global_save(); |
4995 | | - } |
| 4921 | + // Reload the file when it was already closed |
| 4922 | + ManiacPatch::GlobalSave::Load(); |
4996 | 4923 |
|
4997 | 4924 | int type = com.parameters[2]; |
4998 | 4925 | int game_state_idx = ValueOrVariableBitfield(com.parameters[1], 0, com.parameters[3]); |
|
0 commit comments