14#include "lcf/ldb/reader.h"
15#include "lcf/lmt/reader.h"
16#include "lcf/lmu/reader.h"
17#include "lcf/lsd/reader.h"
19#include "lcf/rpg/save.h"
29 for (
int i = 0;
fields[i] != NULL; i++)
37 for (
int i = 0;
fields[i] != NULL; i++)
50 static rpg::Actor
make(
bool is2k3) {
51 auto actor = rpg::Actor();
63 LcfReader::Chunk chunk_info;
65 while (!stream.Eof()) {
66 chunk_info.ID = stream.ReadInt();
67 if (chunk_info.ID == 0)
70 chunk_info.length = stream.ReadInt();
75 printf(
"0x%02x (size: %" PRIu32
", pos: 0x%" PRIx32
"): %s\n", chunk_info.ID, chunk_info.length, stream.Tell(), it->second->name);
77 const uint32_t off = stream.Tell();
78 it->second->ReadLcf(obj, stream, chunk_info.length);
79 const uint32_t bytes_read = stream.Tell() - off;
80 if (bytes_read != chunk_info.length) {
81 fprintf(stderr,
"%s: Corrupted Chunk 0x%02" PRIx32
" (size: %" PRIu32
", pos: 0x%" PRIx32
"): %s : Read %" PRIu32
" bytes! Reseting...\n",
82 Struct<S>::name, chunk_info.ID, chunk_info.length, off, it->second->name, bytes_read);
83 stream.Seek(off + chunk_info.length);
93typename std::enable_if<std::is_same<T, rpg::Save>::value ||
94 std::is_same<T, rpg::Database>::value>::type
100typename std::enable_if<!std::is_same<T, rpg::Save>::value &&
101 !std::is_same<T, rpg::Database>::value>::type
108 const bool db_is2k3 = stream.Is2k3();
112 for (
int i = 0;
fields[i] != NULL; i++) {
114 if (!db_is2k3 && field->
is2k3) {
117 if (field->
id < last)
118 std::cerr <<
"field order mismatch: " << field->
id
120 <<
" in struct " <<
name
125 stream.WriteInt(field->
id);
126 auto len = field->
LcfSize(obj, stream);
127 stream.WriteInt(len);
138 const bool db_is2k3 = stream.Is2k3();
141 for (
int i = 0;
fields[i] != NULL; i++) {
143 if (!db_is2k3 && field->
is2k3) {
150 result += LcfReader::IntSize(field->
id);
151 int size = field->
LcfSize(obj, stream);
152 result += LcfReader::IntSize(size);
155 result += LcfReader::IntSize(0);
161 IDReader::WriteXmlTag(obj,
name, stream);
162 for (
int i = 0;
fields[i] != NULL; i++) {
166 stream.EndElement(
name);
218 int count = stream.ReadInt();
220 for (
int i = 0; i < count; i++) {
221 IDReader::ReadID(vec[i], stream);
228 int count = vec.size();
229 stream.WriteInt(count);
230 for (
int i = 0; i < count; i++) {
231 IDReader::WriteID(vec[i], stream);
239 int count = vec.size();
240 result += LcfReader::IntSize(count);
241 for (
int i = 0; i < count; i++) {
242 result += IDReader::IDSize(vec[i]);
250 int count = vec.size();
251 for (
int i = 0; i < count; i++)
263 ref.resize(
ref.size() + 1);
void StartElement(XmlReader &stream, const char *name, const char **atts)
StructFieldXmlHandler(S &ref)
static void BeginXml(S &obj, XmlReader &stream)
static int LcfSize(const S &obj, LcfWriter &stream)
static void MakeFieldMap()
static const Field< S > * fields[]
static tag_map_type tag_map
static void WriteXml(const S &obj, XmlWriter &stream)
static field_map_type field_map
static void WriteLcf(const S &obj, LcfWriter &stream)
friend class StructFieldXmlHandler
static void ReadLcf(S &obj, LcfReader &stream)
static const char *const name
friend class StructVectorXmlHandler
void StartElement(XmlReader &stream, const char *name, const char **atts)
StructVectorXmlHandler(std::vector< S > &ref)
void EndElement(XmlReader &, const char *)
void StartElement(XmlReader &stream, const char *name, const char **)
void CharacterData(XmlReader &, const std::string &data)
const char *const Struct< rpg::Actor >::name
std::enable_if< std::is_same< T, rpg::Save >::value||std::is_same< T, rpg::Database >::value >::type conditional_zero_writer(LcfWriter &)
bool isPresentIfDefault(bool db_is2k3) const
virtual void WriteLcf(const S &obj, LcfWriter &stream) const =0
virtual bool IsDefault(const S &obj, const S &ref, bool is2k3) const =0
virtual void WriteXml(const S &obj, XmlWriter &stream) const =0
virtual int LcfSize(const S &obj, LcfWriter &stream) const =0
static rpg::Actor make(bool is2k3)