Beispiel #1
0
/**
 * 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 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);
}
/**
 * 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());
		}
	}
}
Beispiel #4
0
/**
 * 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;
	}
}
Beispiel #5
0
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;
	}
}
/**
 * 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);
}
Beispiel #7
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 = (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);
	}
}