New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ldb writing #209

Merged
merged 2 commits into from Sep 4, 2017

Conversation

Projects
None yet
3 participants
@Ghabry
Member

Ghabry commented Aug 25, 2017

Like RPG::Save, RPG::Database has one 0-byte too much.
Merged RPG::Save & Database logic because I understood in the meanwhile how templates + type_traits work ;)

No idea if this is related to #196

Now lcf2xml is finally more usable \o/

Better diff:

+template<typename T>
+typename std::enable_if<std::is_same<T, RPG::Save>::value ||
+		std::is_same<T, RPG::Database>::value>::type
+conditional_zero_writer(LcfWriter&) {
+	// no-op
+};
+
+template<typename T>
+typename std::enable_if<!std::is_same<T, RPG::Save>::value &&
+						!std::is_same<T, RPG::Database>::value>::type
+conditional_zero_writer(LcfWriter& stream) {
+	stream.WriteInt(0);
+};
+
 template <class S>
 void Struct<S>::WriteLcf(const S& obj, LcfWriter& stream) {
 	S ref = S();
 	int last = -1;
 	for (int i = 0; fields[i] != NULL; i++) {
 		const Field<S>* field = fields[i];
 		if (field->id < last)
 			std::cerr << "field order mismatch: " << field->id
 					  << " after " << last
 					  << " in struct " << name
 					  << std::endl;
-		//printf("\n%s", field->name);
 		if (field->IsDefault(obj, ref)) {
-			//printf(" -> default");
 			continue;
 		}
 		stream.WriteInt(field->id);
 		stream.WriteInt(field->LcfSize(obj, stream));
 		field->WriteLcf(obj, stream);
 	}
+	// Writing a 0-byte after RPG::Database or RPG::Save breaks the parser in RPG_RT
+	conditional_zero_writer<S>(stream);
}
-
-template <>
-void Struct<RPG::Save>::WriteLcf(const RPG::Save& obj, LcfWriter& stream) {
-	RPG::Save ref = RPG::Save();
-	int last = -1;
-	for (int i = 0; fields[i] != NULL; i++) {
-		const Field<RPG::Save>* field = fields[i];
-		if (field->id < last)
-			std::cerr << "field order mismatch: " << field->id
-					  << " after " << last
-					  << " in struct " << name
-					  << std::endl;
-		//printf("\n%s", field->name);
-		if (field->IsDefault(obj, ref)) {
-			//printf(" -> default");
-			continue;
-		}
-		stream.WriteInt(field->id);
-		stream.WriteInt(field->LcfSize(obj, stream));
-		field->WriteLcf(obj, stream);
-	}
-	// stream.WriteInt(0); // This last byte broke savegames
-}

Ghabry added some commits Aug 25, 2017

Don't emit a 0-byte after writing the RPG::Database chunk. This resul…
…ts in a stream read error in RPG_RT.

Merged this with the RPG::Save part using a type_trait.

Probably related to #196 but not sure if this is the actual bug.

@carstene1ns carstene1ns merged commit cf129cd into EasyRPG:master Sep 4, 2017

4 checks passed

GNU/Linux Build finished.
Details
OSX Build finished.
Details
Windows Build finished.
Details
web Build finished.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment