Remove all use of lcf::Data globals
MODIFY
bench/readldb.cpp
bench/readldb.cpp
@@ -9,8 +9,8 @@ int main(int argc, char** argv) {
return 1;
}
const auto& infile = argv[1];
- auto rc = LDB_Reader::Load(infile, "");
- if (!rc) {
+ auto db = LDB_Reader::Load(infile, "");
+ if (db == nullptr) {
std::cerr << "Failed to load file : " << infile << std::endl;
return 1;
}

MODIFY
src/lcf/ldb/reader.h
src/lcf/ldb/reader.h
#include <string>
#include <vector>
-#include "lcf/rpg/actor.h"
-#include "lcf/rpg/skill.h"
-#include "lcf/rpg/item.h"
-#include "lcf/rpg/enemy.h"
-#include "lcf/rpg/troop.h"
-#include "lcf/rpg/attribute.h"
-#include "lcf/rpg/state.h"
-#include "lcf/rpg/terrain.h"
-#include "lcf/rpg/chipset.h"
-#include "lcf/rpg/animation.h"
-#include "lcf/rpg/terms.h"
-#include "lcf/rpg/system.h"
-#include "lcf/rpg/commonevent.h"
-#include "lcf/rpg/music.h"
-#include "lcf/rpg/sound.h"
-#include "lcf/rpg/class.h"
-#include "lcf/rpg/battlecommand.h"
-#include "lcf/rpg/battleranimation.h"
-#include "lcf/rpg/parameters.h"
-#include "lcf/rpg/equipment.h"
+#include <memory>
#include "lcf/rpg/database.h"
#include "lcf/saveopt.h"
@@ -49,42 +30,42 @@ namespace LDB_Reader {
/**
* Loads Database.
*/
- bool Load(const std::string& filename, const std::string& encoding);
+ std::unique_ptr<lcf::rpg::Database> Load(const std::string& filename, const std::string& encoding);
/**
* Saves Database.
*/
- bool Save(const std::string& filename, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
+ bool Save(const std::string& filename, const lcf::rpg::Database& db, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
/**
* Saves Database as XML.
*/
- bool SaveXml(const std::string& filename);
+ bool SaveXml(const std::string& filename, const lcf::rpg::Database& db);
/**
* Load Database as XML.
*/
- bool LoadXml(const std::string& filename);
+ std::unique_ptr<lcf::rpg::Database> LoadXml(const std::string& filename);
/**
* Loads Database.
*/
- bool Load(std::istream& filestream, const std::string& encoding);
+ std::unique_ptr<lcf::rpg::Database> Load(std::istream& filestream, const std::string& encoding);
/**
* Saves Database.
*/
- bool Save(std::ostream& filestream, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
+ bool Save(std::ostream& filestream, const lcf::rpg::Database& db, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
/**
* Saves Database as XML.
*/
- bool SaveXml(std::ostream& filestream);
+ bool SaveXml(std::ostream& filestream, const lcf::rpg::Database& db);
/**
* Load Database as XML.
*/
- bool LoadXml(std::istream& filestream);
+ std::unique_ptr<lcf::rpg::Database> LoadXml(std::istream& filestream);
}
} // namespace lcf

MODIFY
src/lcf/lmt/reader.h
src/lcf/lmt/reader.h
#define LCF_LMT_READER_H
#include <string>
-#include "lcf/reader_lcf.h"
-#include "lcf/writer_lcf.h"
-#include "lcf/writer_xml.h"
+#include <memory>
#include "lcf/rpg/treemap.h"
#include "lcf/saveopt.h"
@@ -27,42 +25,42 @@ namespace LMT_Reader {
/**
* Loads Map Tree.
*/
- bool Load(const std::string& filename, const std::string &encoding);
+ std::unique_ptr<lcf::rpg::TreeMap> Load(const std::string& filename, const std::string &encoding);
/**
* Saves Map Tree.
*/
- bool Save(const std::string& filename, const std::string &encoding, SaveOpt opt = SaveOpt::eNone);
+ bool Save(const std::string& filename, const lcf::rpg::TreeMap& tmap, bool is2k3, const std::string &encoding, SaveOpt opt = SaveOpt::eNone);
/**
* Saves Map Tree as XML.
*/
- bool SaveXml(const std::string& filename);
+ bool SaveXml(const std::string& filename, const lcf::rpg::TreeMap& tmap, bool is2k3);
/**
* Loads Map Tree as XML.
*/
- bool LoadXml(const std::string& filename);
+ std::unique_ptr<lcf::rpg::TreeMap> LoadXml(const std::string& filename);
/**
* Loads Map Tree.
*/
- bool Load(std::istream& filestream, const std::string &encoding);
+ std::unique_ptr<lcf::rpg::TreeMap> Load(std::istream& filestream, const std::string &encoding);
/**
* Saves Map Tree.
*/
- bool Save(std::ostream& filestream, const std::string &encoding, SaveOpt opt = SaveOpt::eNone);
+ bool Save(std::ostream& filestream, const lcf::rpg::TreeMap& tmap, bool is2k3, const std::string &encoding, SaveOpt opt = SaveOpt::eNone);
/**
* Saves Map Tree as XML.
*/
- bool SaveXml(std::ostream& filestream);
+ bool SaveXml(std::ostream& filestream, const lcf::rpg::TreeMap& tmap, bool is2k3);
/**
* Loads Map Tree as XML.
*/
- bool LoadXml(std::istream& filestream);
+ std::unique_ptr<lcf::rpg::TreeMap> LoadXml(std::istream& filestream);
}
} //namespace lcf

MODIFY
src/lcf/lmu/reader.h
src/lcf/lmu/reader.h
@@ -35,12 +35,12 @@ namespace LMU_Reader {
/**
* Saves map.
*/
- bool Save(const std::string& filename, const rpg::Map& map, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
+ bool Save(const std::string& filename, const rpg::Map& map, bool is2k3, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
/**
* Saves map as XML.
*/
- bool SaveXml(const std::string& filename, const rpg::Map& map);
+ bool SaveXml(const std::string& filename, const rpg::Map& map, bool is2k3);
/**
* Loads map as XML.
@@ -55,12 +55,12 @@ namespace LMU_Reader {
/**
* Saves map.
*/
- bool Save(std::ostream& filestream, const rpg::Map& map, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
+ bool Save(std::ostream& filestream, const rpg::Map& map, bool is2k3, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
/**
* Saves map as XML.
*/
- bool SaveXml(std::ostream& filestream, const rpg::Map& map);
+ bool SaveXml(std::ostream& filestream, const rpg::Map& map, bool is2k3);
/**
* Loads map as XML.

MODIFY
src/lcf/lsd/reader.h
src/lcf/lsd/reader.h
@@ -51,12 +51,12 @@ namespace LSD_Reader {
/**
* Saves Savegame.
*/
- bool Save(const std::string& filename, const rpg::Save& save, const std::string &encoding);
+ bool Save(const std::string& filename, const rpg::Save& save, bool is2k3, const std::string &encoding);
/*
* Saves Savegame as XML.
*/
- bool SaveXml(const std::string& filename, const rpg::Save& save);
+ bool SaveXml(const std::string& filename, const rpg::Save& save, bool is2k3);
/**
* Loads Savegame as XML.
@@ -71,12 +71,12 @@ namespace LSD_Reader {
/**
* Saves Savegame.
*/
- bool Save(std::ostream& filestream, const rpg::Save& save, const std::string &encoding);
+ bool Save(std::ostream& filestream, const rpg::Save& save, bool is2k3, const std::string &encoding);
/*
* Saves Savegame as XML.
*/
- bool SaveXml(std::ostream& filestream, const rpg::Save& save);
+ bool SaveXml(std::ostream& filestream, const rpg::Save& save, bool is2k3);
/**
* Loads Savegame as XML.

MODIFY
src/ldb_reader.cpp
src/ldb_reader.cpp
#include "lcf/ldb/reader.h"
#include "lcf/ldb/chunks.h"
-#include "lcf/data.h"
#include "lcf/reader_util.h"
#include "reader_struct.h"
@@ -23,108 +22,117 @@ void LDB_Reader::PrepareSave(rpg::Database& db) {
++db.system.save_count;
}
-bool LDB_Reader::Load(const std::string& filename, const std::string& encoding) {
+std::unique_ptr<lcf::rpg::Database> LDB_Reader::Load(const std::string& filename, const std::string& encoding) {
std::ifstream stream(filename.c_str(), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LDB file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
- return false;
+ return nullptr;
}
return LDB_Reader::Load(stream, encoding);
}
-bool LDB_Reader::Save(const std::string& filename, const std::string& encoding, SaveOpt opt) {
+bool LDB_Reader::Save(const std::string& filename, const lcf::rpg::Database& db, const std::string& encoding, SaveOpt opt) {
std::ofstream stream(filename.c_str(), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LDB file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
return false;
}
- return LDB_Reader::Save(stream, encoding, opt);
+ return LDB_Reader::Save(stream, db, encoding, opt);
}
-bool LDB_Reader::SaveXml(const std::string& filename) {
+bool LDB_Reader::SaveXml(const std::string& filename, const lcf::rpg::Database& db) {
std::ofstream stream(filename.c_str(), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LDB XML file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
return false;
}
- return LDB_Reader::SaveXml(stream);
+ return LDB_Reader::SaveXml(stream, db);
}
-bool LDB_Reader::LoadXml(const std::string& filename) {
+std::unique_ptr<lcf::rpg::Database> LDB_Reader::LoadXml(const std::string& filename) {
std::ifstream stream(filename.c_str(), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LDB XML file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
- return false;
+ return nullptr;
}
return LDB_Reader::LoadXml(stream);
}
-bool LDB_Reader::Load(std::istream& filestream, const std::string& encoding) {
+std::unique_ptr<lcf::rpg::Database> LDB_Reader::Load(std::istream& filestream, const std::string& encoding) {
LcfReader reader(filestream, encoding);
if (!reader.IsOk()) {
LcfReader::SetError("Couldn't parse database file.\n");
- return false;
+ return nullptr;
}
std::string header;
reader.ReadString(header, reader.ReadInt());
if (header.length() != 11) {
LcfReader::SetError("This is not a valid RPG2000 database.\n");
- return false;
+ return nullptr;
}
if (header != "LcfDataBase") {
fprintf(stderr, "Warning: This header is not LcfDataBase and might not be a valid RPG2000 database.\n");
}
- Data::data.ldb_header = header;
- TypeReader<rpg::Database>::ReadLcf(Data::data, reader, 0);
+ auto db = std::make_unique<lcf::rpg::Database>();
+ db->ldb_header = header;
+ TypeReader<rpg::Database>::ReadLcf(*db, reader, 0);
// Delayed initialization of some actor fields because they are engine
// dependent
- for (auto& actor: Data::actors) {
- actor.Setup(Data::system.ldb_id == 2003);
+ for (auto& actor: db->actors) {
+ actor.Setup(db->system.ldb_id == 2003);
}
- return true;
+ return db;
}
-bool LDB_Reader::Save(std::ostream& filestream, const std::string& encoding, SaveOpt opt) {
- LcfWriter writer(filestream, Data::system.ldb_id == 2003, encoding);
+bool LDB_Reader::Save(std::ostream& filestream, const lcf::rpg::Database& db, const std::string& encoding, SaveOpt opt) {
+ LcfWriter writer(filestream, db.system.ldb_id == 2003, encoding);
if (!writer.IsOk()) {
LcfReader::SetError("Couldn't parse database file.\n");
return false;
}
std::string header;
- if ( Data::data.ldb_header.empty() || !bool(opt & SaveOpt::ePreserveHeader)) {
+ if ( db.ldb_header.empty() || !bool(opt & SaveOpt::ePreserveHeader)) {
header = "LcfDataBase";
} else {
- header= Data::data.ldb_header;
+ header= db.ldb_header;
}
writer.WriteInt(header.size());
writer.Write(header);
- TypeReader<rpg::Database>::WriteLcf(Data::data, writer);
+ TypeReader<rpg::Database>::WriteLcf(db, writer);
return true;
}
-bool LDB_Reader::SaveXml(std::ostream& filestream) {
- XmlWriter writer(filestream, Data::system.ldb_id == 2003);
+bool LDB_Reader::SaveXml(std::ostream& filestream, const lcf::rpg::Database& db) {
+ XmlWriter writer(filestream, db.system.ldb_id == 2003);
if (!writer.IsOk()) {
LcfReader::SetError("Couldn't parse database file.\n");
return false;
}
writer.BeginElement("LDB");
- TypeReader<rpg::Database>::WriteXml(Data::data, writer);
+ TypeReader<rpg::Database>::WriteXml(db, writer);
writer.EndElement("LDB");
return true;
}
-bool LDB_Reader::LoadXml(std::istream& filestream) {
+std::unique_ptr<lcf::rpg::Database> LDB_Reader::LoadXml(std::istream& filestream) {
XmlReader reader(filestream);
if (!reader.IsOk()) {
LcfReader::SetError("Couldn't parse database file.\n");
- return false;
+ return nullptr;;
}
- reader.SetHandler(new RootXmlHandler<rpg::Database>(Data::data, "LDB"));
+ auto db = std::make_unique<lcf::rpg::Database>();
+ reader.SetHandler(new RootXmlHandler<rpg::Database>(*db, "LDB"));
reader.Parse();
- return true;
+
+ // Delayed initialization of some actor fields because they are engine
+ // dependent
+ for (auto& actor: db->actors) {
+ actor.Setup(db->system.ldb_id == 2003);
+ }
+
+ return db;
}
} // namespace lcf

MODIFY
src/lmt_reader.cpp
src/lmt_reader.cpp
#include "lcf/lmt/reader.h"
#include "lcf/lmt/chunks.h"
-#include "lcf/data.h"
#include "lcf/reader_util.h"
#include "reader_struct.h"
namespace lcf {
-bool LMT_Reader::Load(const std::string& filename, const std::string& encoding) {
+std::unique_ptr<lcf::rpg::TreeMap> LMT_Reader::Load(const std::string& filename, const std::string& encoding) {
std::ifstream stream(filename.c_str(), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LMT file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
- return false;
+ return nullptr;
}
return LMT_Reader::Load(stream, encoding);
}
-bool LMT_Reader::Save(const std::string& filename, const std::string& encoding, SaveOpt opt) {
+bool LMT_Reader::Save(const std::string& filename, const lcf::rpg::TreeMap& tmap, bool is2k3, const std::string& encoding, SaveOpt opt) {
std::ofstream stream(filename.c_str(), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LMT file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
return false;
}
- return LMT_Reader::Save(stream, encoding, opt);
+ return LMT_Reader::Save(stream, tmap, is2k3, encoding, opt);
}
-bool LMT_Reader::SaveXml(const std::string& filename) {
+bool LMT_Reader::SaveXml(const std::string& filename, const lcf::rpg::TreeMap& tmap, bool is2k3) {
std::ofstream stream(filename.c_str(), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LMT XML file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
return false;
}
- return LMT_Reader::SaveXml(stream);
+ return LMT_Reader::SaveXml(stream, tmap, is2k3);
}
-bool LMT_Reader::LoadXml(const std::string& filename) {
+std::unique_ptr<lcf::rpg::TreeMap> LMT_Reader::LoadXml(const std::string& filename) {
std::ifstream stream(filename.c_str(), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LMT XML file `%s' for reading : %s\n", filename.c_str(), strerror(errno));
- return false;
+ return nullptr;
}
return LMT_Reader::LoadXml(stream);
}
-bool LMT_Reader::Load(std::istream& filestream, const std::string &encoding) {
+std::unique_ptr<lcf::rpg::TreeMap> LMT_Reader::Load(std::istream& filestream, const std::string &encoding) {
LcfReader reader(filestream, encoding);
if (!reader.IsOk()) {
LcfReader::SetError("Couldn't parse map tree file.\n");
- return false;
+ return nullptr;
}
std::string header;
reader.ReadString(header, reader.ReadInt());
if (header.length() != 10) {
LcfReader::SetError("This is not a valid RPG2000 map tree.\n");
- return false;
+ return nullptr;
}
if (header != "LcfMapTree") {
fprintf(stderr, "Warning: This header is not LcfMapTree and might not be a valid RPG2000 map tree.\n");
}
- Data::treemap.lmt_header = std::move(header);
- TypeReader<rpg::TreeMap>::ReadLcf(Data::treemap, reader, 0);
- return true;
+ auto tmap = std::make_unique<lcf::rpg::TreeMap>();
+ tmap->lmt_header = std::move(header);
+ TypeReader<rpg::TreeMap>::ReadLcf(*tmap, reader, 0);
+ return tmap;
}
-bool LMT_Reader::Save(std::ostream& filestream, const std::string &encoding, SaveOpt opt) {
- LcfWriter writer(filestream, Data::system.ldb_id == 2003, encoding);
+bool LMT_Reader::Save(std::ostream& filestream, const lcf::rpg::TreeMap& tmap, bool is2k3, const std::string &encoding, SaveOpt opt) {
+ LcfWriter writer(filestream, is2k3, encoding);
if (!writer.IsOk()) {
LcfReader::SetError("Couldn't parse map tree file.\n");
return false;
}
std::string header;
- if ( Data::treemap.lmt_header.empty() || !bool(opt & SaveOpt::ePreserveHeader)) {
+ if ( tmap.lmt_header.empty() || !bool(opt & SaveOpt::ePreserveHeader)) {
header = "LcfMapTree";
} else {
- header= Data::treemap.lmt_header;
+ header= tmap.lmt_header;
}
writer.WriteInt(header.size());
writer.Write(header);
- TypeReader<rpg::TreeMap>::WriteLcf(Data::treemap, writer);
+ TypeReader<rpg::TreeMap>::WriteLcf(tmap, writer);
return true;
}
-bool LMT_Reader::SaveXml(std::ostream& filestream) {
- XmlWriter writer(filestream, Data::system.ldb_id == 2003);
+bool LMT_Reader::SaveXml(std::ostream& filestream, const lcf::rpg::TreeMap& tmap, bool is2k3) {
+ XmlWriter writer(filestream, is2k3);
if (!writer.IsOk()) {
LcfReader::SetError("Couldn't parse map tree file.\n");
return false;
}
writer.BeginElement("LMT");
- TypeReader<rpg::TreeMap>::WriteXml(Data::treemap, writer);
+ TypeReader<rpg::TreeMap>::WriteXml(tmap, writer);
writer.EndElement("LMT");
return true;
}
-bool LMT_Reader::LoadXml(std::istream& filestream) {
+std::unique_ptr<lcf::rpg::TreeMap> LMT_Reader::LoadXml(std::istream& filestream) {
XmlReader reader(filestream);
if (!reader.IsOk()) {
LcfReader::SetError("Couldn't parse map tree file.\n");
- return false;
+ return nullptr;
}
- reader.SetHandler(new RootXmlHandler<rpg::TreeMap>(Data::treemap, "LMT"));
+ auto tmap = std::make_unique<lcf::rpg::TreeMap>();
+ reader.SetHandler(new RootXmlHandler<rpg::TreeMap>(*tmap, "LMT"));
reader.Parse();
- return true;
+ return tmap;
}
} //namespace lcf

MODIFY
src/lmu_reader.cpp
src/lmu_reader.cpp
#include "lcf/lmu/chunks.h"
#include "lcf/reader_lcf.h"
#include "lcf/reader_util.h"
-#include "lcf/data.h"
#include "reader_struct.h"
namespace lcf {
@@ -33,22 +32,22 @@ std::unique_ptr<rpg::Map> LMU_Reader::Load(const std::string& filename, const st
return LMU_Reader::Load(stream, encoding);
}
-bool LMU_Reader::Save(const std::string& filename, const rpg::Map& save, const std::string& encoding, SaveOpt opt) {
+bool LMU_Reader::Save(const std::string& filename, const rpg::Map& save, bool is2k3, const std::string& encoding, SaveOpt opt) {
std::ofstream stream(filename.c_str(), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LMU file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
return false;
}
- return LMU_Reader::Save(stream, save, encoding, opt);
+ return LMU_Reader::Save(stream, save, is2k3, encoding, opt);
}
-bool LMU_Reader::SaveXml(const std::string& filename, const rpg::Map& save) {
+bool LMU_Reader::SaveXml(const std::string& filename, const rpg::Map& save, bool is2k3) {
std::ofstream stream(filename.c_str(), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LMU XML file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
return false;
}
- return LMU_Reader::SaveXml(stream, save);
+ return LMU_Reader::SaveXml(stream, save, is2k3);
}
std::unique_ptr<rpg::Map> LMU_Reader::LoadXml(const std::string& filename) {
@@ -82,8 +81,8 @@ std::unique_ptr<rpg::Map> LMU_Reader::Load(std::istream& filestream, const std::
return map;
}
-bool LMU_Reader::Save(std::ostream& filestream, const rpg::Map& map, const std::string& encoding, SaveOpt opt) {
- LcfWriter writer(filestream, Data::system.ldb_id == 2003, encoding);
+bool LMU_Reader::Save(std::ostream& filestream, const rpg::Map& map, bool is2k3, const std::string& encoding, SaveOpt opt) {
+ LcfWriter writer(filestream, is2k3, encoding);
if (!writer.IsOk()) {
LcfReader::SetError("Couldn't parse map file.\n");
return false;
@@ -101,8 +100,8 @@ bool LMU_Reader::Save(std::ostream& filestream, const rpg::Map& map, const std::
return true;
}
-bool LMU_Reader::SaveXml(std::ostream& filestream, const rpg::Map& map) {
- XmlWriter writer(filestream, Data::system.ldb_id == 2003);
+bool LMU_Reader::SaveXml(std::ostream& filestream, const rpg::Map& map, bool is2k3) {
+ XmlWriter writer(filestream, is2k3);
if (!writer.IsOk()) {
LcfReader::SetError("Couldn't parse map file.\n");
return false;

MODIFY
src/lsd_reader.cpp
src/lsd_reader.cpp
#include "lcf/lsd/chunks.h"
#include "lcf/rpg/save.h"
#include "lcf/reader_util.h"
-#include "lcf/data.h"
#include "reader_struct.h"
namespace lcf {
@@ -49,22 +48,22 @@ std::unique_ptr<rpg::Save> LSD_Reader::Load(const std::string& filename, const s
return LSD_Reader::Load(stream, encoding);
}
-bool LSD_Reader::Save(const std::string& filename, const rpg::Save& save, const std::string& encoding) {
+bool LSD_Reader::Save(const std::string& filename, const rpg::Save& save, bool is2k3, const std::string& encoding) {
std::ofstream stream(filename.c_str(), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LSD file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
return false;
}
- return LSD_Reader::Save(stream, save, encoding);
+ return LSD_Reader::Save(stream, save, is2k3, encoding);
}
-bool LSD_Reader::SaveXml(const std::string& filename, const rpg::Save& save) {
+bool LSD_Reader::SaveXml(const std::string& filename, const rpg::Save& save, bool is2k3) {
std::ofstream stream(filename.c_str(), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LSD XML file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
return false;
}
- return LSD_Reader::SaveXml(stream, save);
+ return LSD_Reader::SaveXml(stream, save, is2k3);
}
std::unique_ptr<rpg::Save> LSD_Reader::LoadXml(const std::string& filename) {
@@ -96,8 +95,8 @@ std::unique_ptr<rpg::Save> LSD_Reader::Load(std::istream& filestream, const std:
return std::unique_ptr<rpg::Save>(save);
}
-bool LSD_Reader::Save(std::ostream& filestream, const rpg::Save& save, const std::string &encoding) {
- LcfWriter writer(filestream, Data::system.ldb_id == 2003, encoding);
+bool LSD_Reader::Save(std::ostream& filestream, const rpg::Save& save, bool is2k3, const std::string &encoding) {
+ LcfWriter writer(filestream, is2k3, encoding);
if (!writer.IsOk()) {
LcfReader::SetError("Couldn't parse save file.\n");
return false;
@@ -110,8 +109,8 @@ bool LSD_Reader::Save(std::ostream& filestream, const rpg::Save& save, const std
return true;
}
-bool LSD_Reader::SaveXml(std::ostream& filestream, const rpg::Save& save) {
- XmlWriter writer(filestream, Data::system.ldb_id == 2003);
+bool LSD_Reader::SaveXml(std::ostream& filestream, const rpg::Save& save, bool is2k3) {
+ XmlWriter writer(filestream, is2k3);
if (!writer.IsOk()) {
LcfReader::SetError("Couldn't parse save file.\n");
return false;

MODIFY
src/reader_util.cpp
src/reader_util.cpp
#include <sstream>
#include <vector>
-#include "lcf/data.h"
#include "lcf/inireader.h"
#include "lcf/ldb/reader.h"
#include "lcf/reader_util.h"
@@ -98,55 +97,58 @@ std::string ReaderUtil::DetectEncoding(StringView data) {
std::vector<std::string> ReaderUtil::DetectEncodings(std::istream& filestream) {
#if LCF_SUPPORT_ICU
- std::ostringstream text;
+ // Populate db->terms and db->system or will empty by default even if load fails
+ auto db = LDB_Reader::Load(filestream, "");
- // Populate Data::terms and Data::system or will empty by default even if load fails
- LDB_Reader::Load(filestream, "");
+ if (!db) {
+ return {};
+ }
+ std::ostringstream text;
text <<
- Data::terms.menu_save <<
- Data::terms.menu_quit <<
- Data::terms.new_game <<
- Data::terms.load_game <<
- Data::terms.exit_game <<
- Data::terms.status <<
- Data::terms.row <<
- Data::terms.order <<
- Data::terms.wait_on <<
- Data::terms.wait_off <<
- Data::terms.level <<
- Data::terms.health_points <<
- Data::terms.spirit_points <<
- Data::terms.normal_status <<
- Data::terms.exp_short <<
- Data::terms.lvl_short <<
- Data::terms.hp_short <<
- Data::terms.sp_short <<
- Data::terms.sp_cost <<
- Data::terms.attack <<
- Data::terms.defense <<
- Data::terms.spirit <<
- Data::terms.agility <<
- Data::terms.weapon <<
- Data::terms.shield <<
- Data::terms.armor <<
- Data::terms.helmet <<
- Data::terms.accessory <<
- Data::terms.save_game_message <<
- Data::terms.load_game_message <<
- Data::terms.file <<
- Data::terms.exit_game_message <<
- Data::terms.yes <<
- Data::terms.no <<
- Data::system.boat_name <<
- Data::system.ship_name <<
- Data::system.airship_name <<
- Data::system.title_name <<
- Data::system.gameover_name <<
- Data::system.system_name <<
- Data::system.system2_name <<
- Data::system.battletest_background <<
- Data::system.frame_name;
+ db->terms.menu_save <<
+ db->terms.menu_quit <<
+ db->terms.new_game <<
+ db->terms.load_game <<
+ db->terms.exit_game <<
+ db->terms.status <<
+ db->terms.row <<
+ db->terms.order <<
+ db->terms.wait_on <<
+ db->terms.wait_off <<
+ db->terms.level <<
+ db->terms.health_points <<
+ db->terms.spirit_points <<
+ db->terms.normal_status <<
+ db->terms.exp_short <<
+ db->terms.lvl_short <<
+ db->terms.hp_short <<
+ db->terms.sp_short <<
+ db->terms.sp_cost <<
+ db->terms.attack <<
+ db->terms.defense <<
+ db->terms.spirit <<
+ db->terms.agility <<
+ db->terms.weapon <<
+ db->terms.shield <<
+ db->terms.armor <<
+ db->terms.helmet <<
+ db->terms.accessory <<
+ db->terms.save_game_message <<
+ db->terms.load_game_message <<
+ db->terms.file <<
+ db->terms.exit_game_message <<
+ db->terms.yes <<
+ db->terms.no <<
+ db->system.boat_name <<
+ db->system.ship_name <<
+ db->system.airship_name <<
+ db->system.title_name <<
+ db->system.gameover_name <<
+ db->system.system_name <<
+ db->system.system2_name <<
+ db->system.battletest_background <<
+ db->system.frame_name;
return ReaderUtil::DetectEncodings(text.str());
#else

MODIFY
tools/lcf2xml.cpp
tools/lcf2xml.cpp
#include <lcf/lmu/reader.h>
#include <lcf/lsd/reader.h>
#include <lcf/reader_util.h>
+#include <lcf/reader_lcf.h>
#ifndef _WIN32
#include <dirent.h>
@@ -49,14 +50,16 @@ std::string GetFilename(const std::string& str);
FileCategories GetFilecategory(const std::string& in_file);
FileTypes GetFiletype(const std::string& in_file, std::string& out_extension);
void PrintReaderError(const std::string data);
-int ReaderWriteToFile(const std::string& in, const std::string& out, FileTypes in_type);
+int ReaderWriteToFile(const std::string& in, const std::string& out, FileTypes in_type, bool is2k3);
int main(int argc, char** argv)
{
if (argc <= 1)
{
std::cerr << "LCF2XML - Converts RPG Maker 2000/2003 Files into XML and vice versa" << std::endl;
- std::cerr << "Usage: " << argv[0] << " file1 [... fileN]" << std::endl;
+ std::cerr << "Usage: " << argv[0] << "[--2k] [--2k3] file1 [... fileN]" << std::endl;
+ std::cerr << "\t--2k: Treat files as RPG 2000" << std::endl;
+ std::cerr << "\t--2k3: Treat files as RPG 2003 (default)" << std::endl;
return 1;
}
@@ -69,7 +72,16 @@ int main(int argc, char** argv)
std::string extension;
unsigned int errors = 0;
+ bool is2k3 = true;
for (int i = 1; i < argc; ++i) {
+ if (!std::strcmp(argv[i], "--2k")) {
+ is2k3 = false;
+ continue;
+ }
+ if (!std::strcmp(argv[i], "--2k3")) {
+ is2k3 = true;
+ continue;
+ }
if (category == FileCategory_Invalid) {
category = GetFilecategory(argv[i]);
if (category == FileCategory_Invalid) {
@@ -88,7 +100,7 @@ int main(int argc, char** argv)
outfile = GetFilename(*it);
type = GetFiletype(*it, extension);
outfile += extension;
- if (ReaderWriteToFile(*it, outfile, type) != 0) {
+ if (ReaderWriteToFile(*it, outfile, type, is2k3) != 0) {
errors++;
}
}
@@ -229,7 +241,7 @@ void PrintReaderError(const std::string data)
}
/** Takes data from in and writes converted data into out using liblcf. */
-int ReaderWriteToFile(const std::string& in, const std::string& out, FileTypes in_type)
+int ReaderWriteToFile(const std::string& in, const std::string& out, FileTypes in_type, bool is2k3)
{
std::string path = GetPath(in) + "/";
std::string encoding = "";
@@ -266,54 +278,58 @@ int ReaderWriteToFile(const std::string& in, const std::string& out, FileTypes i
{
case FileType_LCF_MapUnit:
{
- std::unique_ptr<lcf::rpg::Map> file = lcf::LMU_Reader::Load(in, encoding);
- LCFXML_ERROR(file.get() == NULL, "LMU load");
- LCFXML_ERROR(!lcf::LMU_Reader::SaveXml(out, *file), "LMU XML save");
+ auto file = lcf::LMU_Reader::Load(in, encoding);
+ LCFXML_ERROR(file == nullptr, "LMU load");
+ LCFXML_ERROR(!lcf::LMU_Reader::SaveXml(out, *file, is2k3), "LMU XML save");
break;
}
case FileType_LCF_SaveData:
{
- std::unique_ptr<lcf::rpg::Save> file = lcf::LSD_Reader::Load(in, encoding);
- LCFXML_ERROR(file.get() == NULL, "LSD load");
- LCFXML_ERROR(!lcf::LSD_Reader::SaveXml(out, *file), "LSD XML save");
+ auto file = lcf::LSD_Reader::Load(in, encoding);
+ LCFXML_ERROR(file == nullptr, "LSD load");
+ LCFXML_ERROR(!lcf::LSD_Reader::SaveXml(out, *file, is2k3), "LSD XML save");
break;
}
case FileType_LCF_Database:
{
- LCFXML_ERROR(!lcf::LDB_Reader::Load(in, encoding), "LDB load");
- LCFXML_ERROR(!lcf::LDB_Reader::SaveXml(out), "LDB XML save");
+ auto file = lcf::LDB_Reader::Load(in, encoding);
+ LCFXML_ERROR(file.get() == nullptr, "LDB load");
+ LCFXML_ERROR(!lcf::LDB_Reader::SaveXml(out, *file), "LDB XML save");
break;
}
case FileType_LCF_MapTree:
{
- LCFXML_ERROR(!lcf::LMT_Reader::Load(in, encoding), "LMT load");
- LCFXML_ERROR(!lcf::LMT_Reader::SaveXml(out), "LMT XML save");
+ auto file = lcf::LMT_Reader::Load(in, encoding);
+ LCFXML_ERROR(file == nullptr, "LMT load");
+ LCFXML_ERROR(!lcf::LMT_Reader::SaveXml(out, *file, is2k3), "LMT XML save");
break;
}
case FileType_XML_MapUnit:
{
- std::unique_ptr<lcf::rpg::Map> file = lcf::LMU_Reader::LoadXml(in);
- LCFXML_ERROR(file.get() == NULL, "LMU XML load");
- LCFXML_ERROR(!lcf::LMU_Reader::Save(out, *file, encoding), "LMU save");
+ auto file = lcf::LMU_Reader::LoadXml(in);
+ LCFXML_ERROR(file == nullptr, "LMU XML load");
+ LCFXML_ERROR(!lcf::LMU_Reader::Save(out, *file, is2k3, encoding), "LMU save");
break;
}
case FileType_XML_SaveData:
{
- std::unique_ptr<lcf::rpg::Save> file = lcf::LSD_Reader::LoadXml(in);
- LCFXML_ERROR(file.get() == NULL, "LSD XML load");
- LCFXML_ERROR(!lcf::LSD_Reader::Save(out, *file, encoding), "LSD save");
+ auto file = lcf::LSD_Reader::LoadXml(in);
+ LCFXML_ERROR(file == nullptr, "LSD XML load");
+ LCFXML_ERROR(!lcf::LSD_Reader::Save(out, *file, is2k3, encoding), "LSD save");
break;
}
case FileType_XML_Database:
{
- LCFXML_ERROR(!lcf::LDB_Reader::LoadXml(in), "LDB XML load");
- LCFXML_ERROR(!lcf::LDB_Reader::Save(out, encoding), "LDB save");
+ auto file = lcf::LDB_Reader::LoadXml(in);
+ LCFXML_ERROR(file == nullptr, "LDB XML load");
+ LCFXML_ERROR(!lcf::LDB_Reader::Save(out, *file, encoding), "LDB save");
break;
}
case FileType_XML_MapTree:
{
- LCFXML_ERROR(!lcf::LMT_Reader::LoadXml(in), "LMT XML load");
- LCFXML_ERROR(!lcf::LMT_Reader::Save(out, encoding), "LMT save");
+ auto file = lcf::LMT_Reader::LoadXml(in);
+ LCFXML_ERROR(file == nullptr, "LMT XML load");
+ LCFXML_ERROR(!lcf::LMT_Reader::Save(out, *file, is2k3, encoding), "LMT save");
break;
}
case FileType_Invalid:

MODIFY
tools/lcfstrings.cpp
tools/lcfstrings.cpp
#include <string>
#include <lcf/context.h>
-#include <lcf/data.h>
#include <lcf/ldb/reader.h>
#include <lcf/lmt/reader.h>
#include <lcf/lmu/reader.h>
@@ -121,11 +120,13 @@ int main(int argc, char** argv) {
bool rc = false;
if (HasExt(path, ".ldb")) {
- rc = lcf::LDB_Reader::Load(path, encoding);
- if (rc) Dump(lcf::Data::data);
+ auto file = lcf::LDB_Reader::Load(path, encoding);
+ rc = bool(file);
+ if (rc) Dump(*file);
} else if (HasExt(path, ".lmt")) {
- rc = !lcf::LMT_Reader::Load(path, encoding);
- if (rc) Dump(lcf::Data::treemap);
+ auto file = lcf::LMT_Reader::Load(path, encoding);
+ rc = bool(file);
+ if (rc) Dump(*file);
} else if (HasExt(path, ".lmu")) {
auto file = lcf::LMU_Reader::Load(path, encoding);
rc = bool(file);

Remove all use of lcf::Data globals