/** * Reads MapInfo Rect. */ void RawStruct<RPG::Rect>::ReadLcf(RPG::Rect& ref, LcfReader& stream, uint32_t length) { assert(length == 16); stream.Read(ref.l); stream.Read(ref.t); stream.Read(ref.r); stream.Read(ref.b); }
/** * Reads Map Tree. */ void RawStruct<RPG::TreeMap>::ReadLcf(RPG::TreeMap& ref, LcfReader& stream, uint32_t /* length */) { Struct<RPG::MapInfo>::ReadLcf(ref.maps, stream); for (int i = stream.ReadInt(); i > 0; i--) ref.tree_order.push_back(stream.ReadInt()); ref.active_node = stream.ReadInt(); Struct<RPG::Start>::ReadLcf(ref.start, stream); }
/** * 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 Parameters. */ void RawStruct<RPG::Parameters>::ReadLcf(RPG::Parameters& ref, LcfReader& stream, uint32_t length) { int n = length / 6; stream.Read(ref.maxhp, n); stream.Read(ref.maxsp, n); stream.Read(ref.attack, n); stream.Read(ref.defense, n); stream.Read(ref.spirit, n); stream.Read(ref.agility, n); }
void Struct<S>::ReadLcf(std::vector<S>& vec, LcfReader& stream) { int count = stream.ReadInt(); vec.resize(count); for (int i = 0; i < count; i++) { IDReader::ReadID(vec[i], stream); TypeReader<S>::ReadLcf(vec[i], stream, 0); } }
/** * 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 Move Command. */ void RawStruct<RPG::MoveCommand>::ReadLcf(RPG::MoveCommand& ref, LcfReader& stream, uint32_t /* length */) { ref.command_id = stream.ReadInt(); switch (ref.command_id) { case RPG::MoveCommand::Code::switch_on: stream.Read(ref.parameter_a); break; case RPG::MoveCommand::Code::switch_off: stream.Read(ref.parameter_a); break; case RPG::MoveCommand::Code::change_graphic: stream.ReadString(ref.parameter_string, stream.ReadInt()); stream.Read(ref.parameter_a); break; case RPG::MoveCommand::Code::play_sound_effect: stream.ReadString(ref.parameter_string, stream.ReadInt()); stream.Read(ref.parameter_a); stream.Read(ref.parameter_b); stream.Read(ref.parameter_c); break; } }
void Flags<S>::ReadLcf(S& obj, LcfReader& stream, uint32_t length) { assert(length >= 1 && length <= max_size); uint8_t bitflag; for (int i = 0; flags[i] != NULL; i++) { if (i % 8 == 0) { if (i / 8 >= (int) length) break; stream.Read(bitflag); } bool S::*ref = flags[i]->ref; obj.*ref = ((bitflag >> (i % 8)) & 0x1) != 0; } }
void Struct<S>::ReadLcf(S& obj, LcfReader& stream) { MakeFieldMap(); LcfReader::Chunk chunk_info; while (!stream.Eof()) { chunk_info.ID = stream.ReadInt(); if (chunk_info.ID == 0) break; chunk_info.length = stream.ReadInt(); if (chunk_info.length == 0) continue; typename field_map_type::const_iterator it = field_map.find(chunk_info.ID); if (it != field_map.end()) { //printf("%s\n", it->second->name); it->second->ReadLcf(obj, stream, chunk_info.length); } else stream.Skip(chunk_info); } }
/** * Reads Event Command. */ void RawStruct<RPG::EventCommand>::ReadLcf(RPG::EventCommand& event_command, LcfReader& stream, uint32_t /* length */) { stream.Read(event_command.code); if (event_command.code != 0) { stream.Read(event_command.indent); stream.ReadString(event_command.string, stream.ReadInt()); for (int i = stream.ReadInt(); i > 0; i--) { event_command.parameters.push_back(stream.ReadInt()); } } }
/** * 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); } }