/** * Reads Move Commands. */ void RawStruct<std::vector<RPG::MoveCommand> >::ReadLcf(std::vector<RPG::MoveCommand>& ref, LcfReader& stream, uint32_t length) { unsigned long startpos = stream.Tell(); unsigned long endpos = startpos + length; do { RPG::MoveCommand command; RawStruct<RPG::MoveCommand>::ReadLcf(command, stream, 0); ref.push_back(command); } while (stream.Tell() != endpos); }
/** * Reads event commands. */ void RawStruct<std::vector<RPG::EventCommand> >::ReadLcf( std::vector<RPG::EventCommand>& event_commands, LcfReader& stream, uint32_t length) { // Event Commands is a special array // Has no size information. Is terminated by 4 times 0x00. unsigned long startpos = stream.Tell(); unsigned long endpos = startpos + length; for (;;) { uint8_t ch; stream.Read(ch); if (ch == 0) { stream.Seek(3, LcfReader::FromCurrent); break; } stream.Ungetch(ch); RPG::EventCommand command; RawStruct<RPG::EventCommand>::ReadLcf(command, stream, 0); event_commands.push_back(command); } assert(stream.Tell() == endpos); }
/** * Reads event commands. */ void RawStruct<std::vector<RPG::EventCommand> >::ReadLcf( std::vector<RPG::EventCommand>& event_commands, LcfReader& stream, uint32_t length) { // Event Commands is a special array // Has no size information. Is terminated by 4 times 0x00. unsigned long startpos = stream.Tell(); unsigned long endpos = startpos + length; for (;;) { uint8_t ch = (uint8_t)stream.Peek(); if (ch == 0) { stream.Seek(4, LcfReader::FromCurrent); break; } if (stream.Tell() >= endpos) { stream.Seek(endpos, LcfReader::FromStart); fprintf(stderr, "Event command corrupted at %" PRIu32 "\n", stream.Tell()); for (;;) { // Try finding the real end of the event command (4 0-bytes) int i = 0; for (; i < 4; ++i) { stream.Read(ch); if (ch != 0) { break; } } if (i == 4 || stream.Eof()) { break; } } break; } RPG::EventCommand command; RawStruct<RPG::EventCommand>::ReadLcf(command, stream, 0); event_commands.push_back(command); } }