From ba602929ef5573942d73721596e07a6a19d0d57c Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Fri, 6 Apr 2012 21:04:30 +0200 Subject: [PATCH 01/48] Adding basic save functions to all record types. --- components/CMakeLists.txt | 2 +- components/esm/defs.hpp | 13 +++++ components/esm/esm_common.hpp | 102 +++++++++++++++++++++++++++++++++ components/esm/esm_reader.hpp | 96 +------------------------------ components/esm/esm_writer.cpp | 28 +++++++++ components/esm/esm_writer.hpp | 71 +++++++++++++++++++++++ components/esm/loadacti.cpp | 9 +++ components/esm/loadacti.hpp | 2 + components/esm/loadalch.cpp | 12 ++++ components/esm/loadalch.hpp | 2 + components/esm/loadappa.cpp | 9 +++ components/esm/loadappa.hpp | 2 + components/esm/loadarmo.cpp | 27 +++++++++ components/esm/loadarmo.hpp | 3 + components/esm/loadbody.cpp | 6 ++ components/esm/loadbody.hpp | 2 + components/esm/loadbook.cpp | 15 +++++ components/esm/loadbook.hpp | 2 + components/esm/loadbsgn.cpp | 10 ++++ components/esm/loadbsgn.hpp | 2 + components/esm/loadcell.cpp | 67 ++++++++++++++++++++++ components/esm/loadcell.hpp | 4 ++ components/esm/loadclas.cpp | 7 +++ components/esm/loadclas.hpp | 2 + components/esm/loadclot.cpp | 17 ++++++ components/esm/loadclot.hpp | 2 + components/esm/loadcont.cpp | 22 +++++++ components/esm/loadcont.hpp | 3 + components/esm/loadcrea.cpp | 16 ++++++ components/esm/loadcrea.hpp | 2 + components/esm/loadcrec.hpp | 9 +++ components/esm/loaddial.cpp | 11 ++++ components/esm/loaddial.hpp | 2 + components/esm/loaddoor.cpp | 12 ++++ components/esm/loaddoor.hpp | 2 + components/esm/loadench.cpp | 5 ++ components/esm/loadench.hpp | 2 + components/esm/loadfact.cpp | 17 ++++++ components/esm/loadfact.hpp | 2 + components/esm/loadglob.cpp | 13 +++++ components/esm/loadglob.hpp | 2 + components/esm/loadgmst.cpp | 10 ++++ components/esm/loadgmst.hpp | 2 + components/esm/loadinfo.cpp | 39 +++++++++++++ components/esm/loadinfo.hpp | 2 + components/esm/loadingr.cpp | 10 ++++ components/esm/loadingr.hpp | 2 + components/esm/loadland.cpp | 26 +++++++++ components/esm/loadland.hpp | 4 ++ components/esm/loadlevlist.cpp | 12 ++++ components/esm/loadlevlist.hpp | 2 + components/esm/loadligh.cpp | 13 +++++ components/esm/loadligh.hpp | 2 + components/esm/loadlocks.cpp | 24 ++++++++ components/esm/loadlocks.hpp | 10 ++++ components/esm/loadltex.cpp | 5 ++ components/esm/loadltex.hpp | 2 + components/esm/loadmgef.cpp | 19 ++++++ components/esm/loadmgef.hpp | 2 + components/esm/loadmisc.cpp | 8 +++ components/esm/loadmisc.hpp | 2 + components/esm/loadnpc.cpp | 30 ++++++++++ components/esm/loadnpc.hpp | 3 + components/esm/loadnpcc.hpp | 4 ++ components/esm/loadpgrd.cpp | 23 ++++++++ components/esm/loadpgrd.hpp | 2 + components/esm/loadrace.cpp | 7 +++ components/esm/loadrace.hpp | 2 + components/esm/loadregn.cpp | 14 +++++ components/esm/loadregn.hpp | 2 + components/esm/loadscpt.cpp | 16 ++++++ components/esm/loadscpt.hpp | 2 + components/esm/loadskil.cpp | 6 ++ components/esm/loadskil.hpp | 2 + components/esm/loadsndg.cpp | 6 ++ components/esm/loadsndg.hpp | 2 + components/esm/loadsoun.cpp | 5 ++ components/esm/loadsoun.hpp | 2 + components/esm/loadspel.cpp | 6 ++ components/esm/loadspel.hpp | 2 + components/esm/loadsscr.cpp | 5 ++ components/esm/loadsscr.hpp | 2 + components/esm/loadstat.cpp | 4 ++ components/esm/loadstat.hpp | 2 + components/esm/loadweap.cpp | 9 +++ components/esm/loadweap.hpp | 2 + 86 files changed, 894 insertions(+), 96 deletions(-) create mode 100644 components/esm/esm_common.hpp create mode 100644 components/esm/esm_writer.cpp create mode 100644 components/esm/esm_writer.hpp diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index b48c50640..83ebcefe1 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -35,7 +35,7 @@ add_component_dir (esm_store ) add_component_dir (esm - attr defs esm_reader loadacti loadalch loadappa loadarmo loadbody loadbook loadbsgn loadcell + attr defs esm_reader esm_writer loadacti loadalch loadappa loadarmo loadbody loadbook loadbsgn loadcell loadclas loadclot loadcont loadcrea loadcrec loaddial loaddoor loadench loadfact loadglob loadgmst loadinfo loadingr loadland loadlevlist loadligh loadlocks loadltex loadmgef loadmisc loadnpcc loadnpc loadpgrd loadrace loadregn loadscpt loadskil loadsndg loadsoun loadspel loadsscr loadstat diff --git a/components/esm/defs.hpp b/components/esm/defs.hpp index 917c1031f..a33247906 100644 --- a/components/esm/defs.hpp +++ b/components/esm/defs.hpp @@ -2,6 +2,7 @@ #define _ESM_DEFS_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -47,6 +48,11 @@ struct SpellList while (esm.isNextSub("NPCS")) list.push_back(esm.getHString()); } + void save(ESMWriter &esm) + { + for (std::vector::iterator it = list.begin(); it != list.end(); ++it) + esm.writeHNString("NPCS", *it); + } }; /** Defines a spell effect. Shared between SPEL (Spells), ALCH @@ -92,6 +98,13 @@ struct EffectList list.push_back(s); } } + void save(ESMWriter &esm) + { + for (std::vector::iterator it = list.begin(); it != list.end(); ++it) + { + esm.writeHNT("ENAM", *it, 24); + } + } }; } diff --git a/components/esm/esm_common.hpp b/components/esm/esm_common.hpp new file mode 100644 index 000000000..abe0250df --- /dev/null +++ b/components/esm/esm_common.hpp @@ -0,0 +1,102 @@ +#ifndef _ESM_COMMON_H +#define _ESM_COMMON_H + +#include + +namespace ESM +{ +enum Version + { + VER_12 = 0x3f99999a, + VER_13 = 0x3fa66666 + }; + +enum FileType + { + FT_ESP = 0, // Plugin + FT_ESM = 1, // Master + FT_ESS = 32 // Savegame + }; + +// Used to mark special files. The original ESM files are given +// special treatment in a few places, most noticably in loading and +// filtering out "dirtly" GMST entries correctly. +enum SpecialFile + { + SF_Other, + SF_Morrowind, + SF_Tribunal, + SF_Bloodmoon + }; + +/* A structure used for holding fixed-length strings. In the case of + LEN=4, it can be more efficient to match the string as a 32 bit + number, therefore the struct is implemented as a union with an int. + */ +template +union NAME_T +{ + char name[LEN]; + int32_t val; + + bool operator==(const char *str) + { + for(int i=0; i NAME; +typedef NAME_T<32> NAME32; +typedef NAME_T<64> NAME64; +typedef NAME_T<256> NAME256; + +#pragma pack(push) +#pragma pack(1) +/// File header data for all ES files +struct HEDRstruct +{ + /* File format version. This is actually a float, the supported + versions are 1.2 and 1.3. These correspond to: + 1.2 = 0x3f99999a and 1.3 = 0x3fa66666 + */ + int version; + int type; // 0=esp, 1=esm, 32=ess + NAME32 author; // Author's name + NAME256 desc; // File description + int records; // Number of records? Not used. +}; + +// Defines another files (esm or esp) that this file depends upon. +struct MasterData +{ + std::string name; + uint64_t size; +}; + +// Data that is only present in save game files +struct SaveData +{ + float pos[6]; // Player position and rotation + NAME64 cell; // Cell name + float unk2; // Unknown value - possibly game time? + NAME32 player; // Player name +}; +#pragma pack(pop) +} + +#endif diff --git a/components/esm/esm_reader.hpp b/components/esm/esm_reader.hpp index 0420f37cd..6e5592cf7 100644 --- a/components/esm/esm_reader.hpp +++ b/components/esm/esm_reader.hpp @@ -16,103 +16,9 @@ #include #include +#include "esm_common.hpp" namespace ESM { - -enum Version - { - VER_12 = 0x3f99999a, - VER_13 = 0x3fa66666 - }; - -enum FileType - { - FT_ESP = 0, // Plugin - FT_ESM = 1, // Master - FT_ESS = 32 // Savegame - }; - -// Used to mark special files. The original ESM files are given -// special treatment in a few places, most noticably in loading and -// filtering out "dirtly" GMST entries correctly. -enum SpecialFile - { - SF_Other, - SF_Morrowind, - SF_Tribunal, - SF_Bloodmoon - }; - -/* A structure used for holding fixed-length strings. In the case of - LEN=4, it can be more efficient to match the string as a 32 bit - number, therefore the struct is implemented as a union with an int. - */ -template -union NAME_T -{ - char name[LEN]; - int32_t val; - - bool operator==(const char *str) - { - for(int i=0; i NAME; -typedef NAME_T<32> NAME32; -typedef NAME_T<64> NAME64; -typedef NAME_T<256> NAME256; - -#pragma pack(push) -#pragma pack(1) -/// File header data for all ES files -struct HEDRstruct -{ - /* File format version. This is actually a float, the supported - versions are 1.2 and 1.3. These correspond to: - 1.2 = 0x3f99999a and 1.3 = 0x3fa66666 - */ - int version; - int type; // 0=esp, 1=esm, 32=ess - NAME32 author; // Author's name - NAME256 desc; // File description - int records; // Number of records? Not used. -}; - -// Defines another files (esm or esp) that this file depends upon. -struct MasterData -{ - std::string name; - uint64_t size; -}; - -// Data that is only present in save game files -struct SaveData -{ - float pos[6]; // Player position and rotation - NAME64 cell; // Cell name - float unk2; // Unknown value - possibly game time? - NAME32 player; // Player name -}; -#pragma pack(pop) - - /* This struct defines a file 'context' which can be saved and later restored by an ESMReader instance. It will save the position within a file, and when restored will let you read from that position as diff --git a/components/esm/esm_writer.cpp b/components/esm/esm_writer.cpp new file mode 100644 index 000000000..da040c664 --- /dev/null +++ b/components/esm/esm_writer.cpp @@ -0,0 +1,28 @@ +#include "esm_writer.hpp" + +namespace ESM +{ + +void ESMWriter::writeHNString(const std::string& name, const std::string& data) +{ + writeName(name); + writeHString(data); +} + +void ESMWriter::writeHString(const std::string& data) +{ + writeT(data.size()-1); + write(data.c_str(), data.size()-1); +} + +void ESMWriter::writeName(const std::string& name) +{ + write(name.c_str(), name.size()-1); +} + +void ESMWriter::write(const char* data, int size) +{ + m_stream.write(data, size); +} + +} diff --git a/components/esm/esm_writer.hpp b/components/esm/esm_writer.hpp new file mode 100644 index 000000000..5adf32049 --- /dev/null +++ b/components/esm/esm_writer.hpp @@ -0,0 +1,71 @@ +#ifndef _ESM_WRITER_H +#define _ESM_WRITER_H + +#include +#include + +#include "esm_common.hpp" + +namespace ESM { + +class ESMWriter +{ +public: + void writeHNString(const std::string& name, const std::string& data); + void writeHNOString(const std::string& name, const std::string& data) + { + if (!data.empty()) + writeHNString(name, data); + } + + template + void writeHNT(const std::string& name, const T& data) + { + writeName(name); + writeT(data); + } + + template + void writeHNT(const std::string& name, const T& data, int size) + { + assert(sizeof(T) == size); + writeHNT(name, data); + } + + template + void writeHT(const T& data) + { + writeT((unsigned int)sizeof(T)); + writeT(data); + } + + template + void writeHT(const T& data, int size) + { + assert(sizeof(T) == size); + writeHT(data); + } + + template + void writeT(const T& data) + { + write((char*)&data, sizeof(T)); + } + + template + void writeT(const T& data, int size) + { + assert(sizeof(T) == size); + writeT(data); + } + + void writeHString(const std::string& data); + void writeName(const std::string& data); + void write(const char* data, int size); + +private: + std::ostream m_stream; +}; + +} +#endif diff --git a/components/esm/loadacti.cpp b/components/esm/loadacti.cpp index 40c9b635c..a5e59a006 100644 --- a/components/esm/loadacti.cpp +++ b/components/esm/loadacti.cpp @@ -8,4 +8,13 @@ void Activator::load(ESMReader &esm) name = esm.getHNString("FNAM"); script = esm.getHNOString("SCRI"); } +void Activator::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); + esm.writeHNString("FNAM", name); + if (!script.empty()) + { + esm.writeHNString("SCRI", script); + } +} } diff --git a/components/esm/loadacti.hpp b/components/esm/loadacti.hpp index 783559e11..3f968bc7c 100644 --- a/components/esm/loadacti.hpp +++ b/components/esm/loadacti.hpp @@ -2,6 +2,7 @@ #define _ESM_ACTI_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -11,6 +12,7 @@ struct Activator std::string name, script, model; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadalch.cpp b/components/esm/loadalch.cpp index d3bc36a77..7db9ef9ac 100644 --- a/components/esm/loadalch.cpp +++ b/components/esm/loadalch.cpp @@ -11,4 +11,16 @@ void Potion::load(ESMReader &esm) esm.getHNT(data, "ALDT", 12); effects.load(esm); } +void Potion::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); + if (!icon.empty()) + esm.writeHNString("TEXT", icon); + if (!script.empty()) + esm.writeHNString("SCRI", script); + if (!name.empty()) + esm.writeHNString("FNAM", name); + esm.writeHNT("ALDT", data, 12); + effects.save(esm); +} } diff --git a/components/esm/loadalch.hpp b/components/esm/loadalch.hpp index c21e5dea0..b447fe50c 100644 --- a/components/esm/loadalch.hpp +++ b/components/esm/loadalch.hpp @@ -2,6 +2,7 @@ #define _ESM_ALCH_H #include "esm_reader.hpp" +#include "esm_writer.hpp" #include "defs.hpp" namespace ESM @@ -25,6 +26,7 @@ struct Potion EffectList effects; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadappa.cpp b/components/esm/loadappa.cpp index c76ad5350..17cc22087 100644 --- a/components/esm/loadappa.cpp +++ b/components/esm/loadappa.cpp @@ -10,4 +10,13 @@ void Apparatus::load(ESMReader &esm) script = esm.getHNOString("SCRI"); icon = esm.getHNString("ITEX"); } +void Apparatus::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); + esm.writeHNString("FNAM", name); + esm.writeHNT("AADT", data, 16); + if (!script.empty()) + esm.writeHNString("SCRI", script); + esm.writeHNString("ITEX", icon); +} } diff --git a/components/esm/loadappa.hpp b/components/esm/loadappa.hpp index 2caca32b3..ff105a307 100644 --- a/components/esm/loadappa.hpp +++ b/components/esm/loadappa.hpp @@ -2,6 +2,7 @@ #define _ESM_APPA_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -32,6 +33,7 @@ struct Apparatus std::string model, icon, script, name; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadarmo.cpp b/components/esm/loadarmo.cpp index ddc25e176..14cb056bf 100644 --- a/components/esm/loadarmo.cpp +++ b/components/esm/loadarmo.cpp @@ -11,6 +11,19 @@ void PartReferenceList::load(ESMReader &esm) esm.getHT(pr.part); // The INDX byte pr.male = esm.getHNOString("BNAM"); pr.female = esm.getHNOString("CNAM"); + parts.push_back(pr); + } +} + +void PartReferenceList::save(ESMWriter &esm) +{ + for (std::vector::iterator it = parts.begin(); it != parts.end(); ++it) + { + esm.writeHT(it->part); + if (!it->male.empty()) + esm.writeHNString("BNAM", it->male); + if (!it->female.empty()) + esm.writeHNString("CNAM", it->female); } } @@ -25,4 +38,18 @@ void Armor::load(ESMReader &esm) enchant = esm.getHNOString("ENAM"); } +void Armor::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); + esm.writeHNString("FNAM", name); + if (!script.empty()) + esm.writeHNString("SCRI", script); + esm.writeHNT("AODT", data, 24); + if (!icon.empty()) + esm.writeHNString("ITEX", icon); + parts.save(esm); + if (!enchant.empty()) + esm.writeHNString("ENAM", enchant); +} + } diff --git a/components/esm/loadarmo.hpp b/components/esm/loadarmo.hpp index 16b6b1d3a..5026696c2 100644 --- a/components/esm/loadarmo.hpp +++ b/components/esm/loadarmo.hpp @@ -2,6 +2,7 @@ #define _ESM_ARMO_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -50,6 +51,7 @@ struct PartReferenceList std::vector parts; void load(ESMReader &esm); + void save(ESMWriter &esm); }; struct Armor @@ -82,6 +84,7 @@ struct Armor std::string name, model, icon, script, enchant; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadbody.cpp b/components/esm/loadbody.cpp index 1c72b0fe0..72d56eac3 100644 --- a/components/esm/loadbody.cpp +++ b/components/esm/loadbody.cpp @@ -9,5 +9,11 @@ void BodyPart::load(ESMReader &esm) name = esm.getHNString("FNAM"); esm.getHNT(data, "BYDT", 4); } +void BodyPart::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); + esm.writeHNString("FNAM", name); + esm.writeHNT("BYDT", data, 4); +} } diff --git a/components/esm/loadbody.hpp b/components/esm/loadbody.hpp index de3db40fc..46cb1d899 100644 --- a/components/esm/loadbody.hpp +++ b/components/esm/loadbody.hpp @@ -2,6 +2,7 @@ #define _ESM_BODY_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -52,6 +53,7 @@ struct BodyPart std::string model, name; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadbook.cpp b/components/esm/loadbook.cpp index ffa958e14..829b7d297 100644 --- a/components/esm/loadbook.cpp +++ b/components/esm/loadbook.cpp @@ -13,5 +13,20 @@ void Book::load(ESMReader &esm) text = esm.getHNOString("TEXT"); enchant = esm.getHNOString("ENAM"); } +void Book::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); + if (!name.empty()) + esm.writeHNString("FNAM", name); + esm.writeHNT("BKDT", data, 20); + if (!script.empty()) + esm.writeHNString("SCRI", script); + if (!icon.empty()) + esm.writeHNString("ITEX", icon); + if (!text.empty()) + esm.writeHNString("TEXT", text); + if (!enchant.empty()) + esm.writeHNString("ENAM", enchant); +} } diff --git a/components/esm/loadbook.hpp b/components/esm/loadbook.hpp index 3a4ab441e..a46135cc0 100644 --- a/components/esm/loadbook.hpp +++ b/components/esm/loadbook.hpp @@ -2,6 +2,7 @@ #define _ESM_BOOK_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -22,6 +23,7 @@ struct Book std::string name, model, icon, script, enchant, text; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadbsgn.cpp b/components/esm/loadbsgn.cpp index 976cb7d20..9488f355f 100644 --- a/components/esm/loadbsgn.cpp +++ b/components/esm/loadbsgn.cpp @@ -11,5 +11,15 @@ void BirthSign::load(ESMReader &esm) powers.load(esm); } +void BirthSign::save(ESMWriter &esm) +{ + esm.writeHNString("FNAM", name); + if (!texture.empty()) + esm.writeHNString("TNAM", texture); + if (!description.empty()) + esm.writeHNString("DESC", description); + + powers.save(esm); +} } diff --git a/components/esm/loadbsgn.hpp b/components/esm/loadbsgn.hpp index 53964b02c..d00664bff 100644 --- a/components/esm/loadbsgn.hpp +++ b/components/esm/loadbsgn.hpp @@ -3,6 +3,7 @@ #include "defs.hpp" #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -15,6 +16,7 @@ struct BirthSign SpellList powers; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 158cc0867..8b3d09183 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -6,6 +6,49 @@ namespace ESM { +void CellRef::save(ESMWriter &esm) +{ + esm.writeHNT("FRMR", refnum); + esm.writeHNString("NAME", refID); + + if (scale != 1.0) + esm.writeHNT("XSCL", scale); + + esm.writeHNOString("ANAM", owner); + esm.writeHNOString("BNAM", glob); + esm.writeHNOString("SXOL", soul); + + esm.writeHNOString("CNAM", faction); + if (factIndex != -1) + esm.writeHNT("INDX", factIndex); + + if (charge != -1.0) + esm.writeHNT("XCHG", charge); + + if (intv != 0) + esm.writeHNT("INTV", intv); + if (nam9 != 0) + esm.writeHNT("NAM9", nam9); + + if (teleport) + { + esm.writeHNT("DODT", doorDest); + esm.writeHNOString("DNAM", destCell); + } + + if (lockLevel != 0) + esm.writeHNT("FLTV", lockLevel); + esm.writeHNOString("KNAM", key); + esm.writeHNOString("TNAM", trap); + + if (unam != 0) + esm.writeHNT("UNAM", unam); + if (fltv != 0) + esm.writeHNT("FLTV", fltv); + + esm.writeHNT("DATA", pos, 24); +} + void Cell::load(ESMReader &esm) { // Ignore this for now, it might mean we should delete the entire @@ -50,6 +93,30 @@ void Cell::load(ESMReader &esm) esm.skipRecord(); } +void Cell::save(ESMWriter &esm) +{ + esm.writeHNT("DATA", data, 12); + if (data.flags & Interior) + { + if (water != 0) + esm.writeHNT("WHGT", water); + if (data.flags & QuasiEx) + { + if (!region.empty()) + esm.writeHNString("RGNN", region); + } + else + esm.writeHNT("AMBI", ambi, 16); + } + else + { + if (!region.empty()) + esm.writeHNString("RGNN", region); + if (mapColor != 0) + esm.writeHNT("NAM5", mapColor); + } +} + void Cell::restore(ESMReader &esm) const { esm.restoreContext(context); diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index 8070f9c03..8d461369c 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -2,6 +2,7 @@ #define _ESM_CELL_H #include "esm_reader.hpp" +#include "esm_writer.hpp" #include "defs.hpp" namespace ESM { @@ -71,6 +72,8 @@ public: // Position and rotation of this object within the cell Position pos; + + void save(ESMWriter &esm); }; /* Cells hold data about objects, creatures, statics (rocks, walls, @@ -118,6 +121,7 @@ struct Cell int mapColor; void load(ESMReader &esm); + void save(ESMWriter &esm); bool isExterior() const { diff --git a/components/esm/loadclas.cpp b/components/esm/loadclas.cpp index b15852cc2..05cbfe709 100644 --- a/components/esm/loadclas.cpp +++ b/components/esm/loadclas.cpp @@ -25,5 +25,12 @@ void Class::load(ESMReader &esm) description = esm.getHNOString("DESC"); } +void Class::save(ESMWriter &esm) +{ + esm.writeHNString("FNAM", name); + esm.writeHNT("CLDT", data, 60); + if (!description.empty()) + esm.writeHNString("DESC", description); +} } diff --git a/components/esm/loadclas.hpp b/components/esm/loadclas.hpp index 08412c838..a89481a7a 100644 --- a/components/esm/loadclas.hpp +++ b/components/esm/loadclas.hpp @@ -2,6 +2,7 @@ #define _ESM_CLAS_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -61,6 +62,7 @@ struct Class CLDTstruct data; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadclot.cpp b/components/esm/loadclot.cpp index 1d6c9d4a1..b1c678348 100644 --- a/components/esm/loadclot.cpp +++ b/components/esm/loadclot.cpp @@ -16,5 +16,22 @@ void Clothing::load(ESMReader &esm) enchant = esm.getHNOString("ENAM"); } +void Clothing::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); + if (!name.empty()) + esm.writeHNString("FNAM", name); + esm.writeHNT("CTDT", data, 12); + + if (!script.empty()) + esm.writeHNString("SCRI", script); + if (!icon.empty()) + esm.writeHNString("ITEX", icon); + + parts.save(esm); + + if (!enchant.empty()) + esm.writeHNString("ENAM", enchant); +} } diff --git a/components/esm/loadclot.hpp b/components/esm/loadclot.hpp index 8fa06e7e4..77ef3786a 100644 --- a/components/esm/loadclot.hpp +++ b/components/esm/loadclot.hpp @@ -2,6 +2,7 @@ #define _ESM_CLOT_H #include "esm_reader.hpp" +#include "esm_writer.hpp" #include "loadarmo.hpp" namespace ESM @@ -41,6 +42,7 @@ struct Clothing std::string name, model, icon, enchant, script; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadcont.cpp b/components/esm/loadcont.cpp index 14699ccc5..ba90e52ce 100644 --- a/components/esm/loadcont.cpp +++ b/components/esm/loadcont.cpp @@ -13,6 +13,14 @@ void InventoryList::load(ESMReader &esm) } } +void InventoryList::save(ESMWriter &esm) +{ + for (std::vector::iterator it = list.begin(); it != list.end(); ++it) + { + esm.writeHNT("NPCO", *it, 36); + } +} + void Container::load(ESMReader &esm) { model = esm.getHNString("MODL"); @@ -30,4 +38,18 @@ void Container::load(ESMReader &esm) inventory.load(esm); } +void Container::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); + if (!name.empty()) + esm.writeHNString("FNAM", name); + esm.writeHNT("CNDT", weight, 4); + esm.writeHNT("FLAG", flags, 4); + + if (!script.empty()) + esm.writeHNString("SCRI", script); + + inventory.save(esm); +} + } diff --git a/components/esm/loadcont.hpp b/components/esm/loadcont.hpp index 4614c4230..bf6994f9a 100644 --- a/components/esm/loadcont.hpp +++ b/components/esm/loadcont.hpp @@ -2,6 +2,7 @@ #define _ESM_CONT_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -21,6 +22,7 @@ struct InventoryList std::vector list; void load(ESMReader &esm); + void save(ESMWriter &esm); }; struct Container @@ -39,6 +41,7 @@ struct Container InventoryList inventory; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index 651d9a318..0cab2761e 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -37,4 +37,20 @@ void Creature::load(ESMReader &esm, const std::string& id) esm.skipRecord(); } +void Creature::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); + if (!original.empty()) + esm.writeHNString("CNAM", original); + if (!name.empty()) + esm.writeHNString("FNAM", name); + if (!script.empty()) + esm.writeHNString("SCRI", script); + esm.writeHNT("NPDT", data, 96); + esm.writeHNT("FLAG", flags); + if (scale != 1.0) + esm.writeHNT("XSCL", scale); + inventory.save(esm); +} + } diff --git a/components/esm/loadcrea.hpp b/components/esm/loadcrea.hpp index 3c334ebbd..2f5f4061d 100644 --- a/components/esm/loadcrea.hpp +++ b/components/esm/loadcrea.hpp @@ -2,6 +2,7 @@ #define _ESM_CREA_H #include "esm_reader.hpp" +#include "esm_writer.hpp" #include "loadcont.hpp" namespace ESM @@ -64,6 +65,7 @@ struct Creature std::string mId; void load(ESMReader &esm, const std::string& id); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadcrec.hpp b/components/esm/loadcrec.hpp index 4d38d4a23..056f572ae 100644 --- a/components/esm/loadcrec.hpp +++ b/components/esm/loadcrec.hpp @@ -2,6 +2,7 @@ #define _ESM_CREC_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -15,6 +16,10 @@ struct LoadCREC { esm.skipRecord(); } + + void save(ESMWriter &esm) + { + } }; /// Changes an item list / container @@ -24,6 +29,10 @@ struct LoadCNTC { esm.skipRecord(); } + + void save(ESMWriter &esm) + { + } }; } #endif diff --git a/components/esm/loaddial.cpp b/components/esm/loaddial.cpp index d2283d351..bdee27586 100644 --- a/components/esm/loaddial.cpp +++ b/components/esm/loaddial.cpp @@ -22,4 +22,15 @@ void Dialogue::load(ESMReader &esm) esm.fail("Unknown sub record size"); } +void Dialogue::save(ESMWriter &esm) +{ + if (type != Deleted) + esm.writeHNT("DATA", type); + else + { + esm.writeHNT("DATA", (int)1); + esm.writeHNT("DELE", (int)1); + } +} + } diff --git a/components/esm/loaddial.hpp b/components/esm/loaddial.hpp index 1f18a49d0..a19b0c7ad 100644 --- a/components/esm/loaddial.hpp +++ b/components/esm/loaddial.hpp @@ -4,6 +4,7 @@ #include #include "esm_reader.hpp" +#include "esm_writer.hpp" #include "loadinfo.hpp" namespace ESM @@ -30,6 +31,7 @@ struct Dialogue std::vector mInfo; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loaddoor.cpp b/components/esm/loaddoor.cpp index d3cc69bd4..513eac753 100644 --- a/components/esm/loaddoor.cpp +++ b/components/esm/loaddoor.cpp @@ -11,5 +11,17 @@ void Door::load(ESMReader &esm) openSound = esm.getHNOString("SNAM"); closeSound = esm.getHNOString("ANAM"); } +void Door::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); + if (!name.empty()) + esm.writeHNString("FNAM", name); + if (!script.empty()) + esm.writeHNString("SCRI", script); + if (!openSound.empty()) + esm.writeHNString("SNAM", openSound); + if (!closeSound.empty()) + esm.writeHNString("ANAM", closeSound); +} } diff --git a/components/esm/loaddoor.hpp b/components/esm/loaddoor.hpp index 2c0db4064..1234ac7f9 100644 --- a/components/esm/loaddoor.hpp +++ b/components/esm/loaddoor.hpp @@ -2,6 +2,7 @@ #define _ESM_DOOR_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -11,6 +12,7 @@ struct Door std::string name, model, script, openSound, closeSound; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadench.cpp b/components/esm/loadench.cpp index b2787492d..6157463cf 100644 --- a/components/esm/loadench.cpp +++ b/components/esm/loadench.cpp @@ -8,5 +8,10 @@ void Enchantment::load(ESMReader &esm) esm.getHNT(data, "ENDT", 16); effects.load(esm); } +void Enchantment::save(ESMWriter &esm) +{ + esm.writeHNT("ENDT", data, 16); + effects.save(esm); +} } diff --git a/components/esm/loadench.hpp b/components/esm/loadench.hpp index 449589e25..609166983 100644 --- a/components/esm/loadench.hpp +++ b/components/esm/loadench.hpp @@ -2,6 +2,7 @@ #define _ESM_ENCH_H #include "esm_reader.hpp" +#include "esm_writer.hpp" #include "defs.hpp" namespace ESM @@ -34,6 +35,7 @@ struct Enchantment EffectList effects; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadfact.cpp b/components/esm/loadfact.cpp index 346ad2a2e..fdbedcbd0 100644 --- a/components/esm/loadfact.cpp +++ b/components/esm/loadfact.cpp @@ -27,5 +27,22 @@ void Faction::load(ESMReader &esm) reactions.push_back(r); } } +void Faction::save(ESMWriter &esm) +{ + esm.writeHNString("FNAM", name); + + for (int i = 0; !ranks[i].empty(); i++) + { + esm.writeHNString("RNAM", ranks[i]); + } + + esm.writeHNT("FADT", data, 240); + + for (std::vector::iterator it = reactions.begin(); it != reactions.end(); ++it) + { + esm.writeHNString("ANAM", it->faction); + esm.writeHNT("INTV", it->reaction); + } +} } diff --git a/components/esm/loadfact.hpp b/components/esm/loadfact.hpp index 85874aa78..686554da3 100644 --- a/components/esm/loadfact.hpp +++ b/components/esm/loadfact.hpp @@ -2,6 +2,7 @@ #define _ESM_FACT_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -53,6 +54,7 @@ struct Faction std::string ranks[10]; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadglob.cpp b/components/esm/loadglob.cpp index c946b3fa0..cf43de957 100644 --- a/components/esm/loadglob.cpp +++ b/components/esm/loadglob.cpp @@ -21,4 +21,17 @@ void Global::load(ESMReader &esm) esm.getHNT(value, "FLTV"); } +void Global::save(ESMWriter &esm) +{ + switch(type) + { + case VT_Short: esm.writeHNString("FNAM", "s"); break; + case VT_Int: esm.writeHNString("FNAM", "l"); break; + case VT_Float: esm.writeHNString("FNAM", "f"); break; + default: return; + } + + esm.writeHNT("FLTV", value); +} + } diff --git a/components/esm/loadglob.hpp b/components/esm/loadglob.hpp index 5028679dd..669475fe7 100644 --- a/components/esm/loadglob.hpp +++ b/components/esm/loadglob.hpp @@ -2,6 +2,7 @@ #define _ESM_GLOB_H #include "esm_reader.hpp" +#include "esm_writer.hpp" #include "defs.hpp" namespace ESM @@ -17,6 +18,7 @@ struct Global VarType type; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadgmst.cpp b/components/esm/loadgmst.cpp index 677642e31..21c2d1fb1 100644 --- a/components/esm/loadgmst.cpp +++ b/components/esm/loadgmst.cpp @@ -168,5 +168,15 @@ void GameSetting::load(ESMReader &esm) && isDirtyBloodmoon())) dirty = true; } +void GameSetting::save(ESMWriter &esm) +{ + switch(type) + { + case VT_String: esm.writeHNString("STRV", str); break; + case VT_Int: esm.writeHNT("INTV", i); break; + case VT_Float: esm.writeHNT("FLTV", f); break; + default: break; + } +} } diff --git a/components/esm/loadgmst.hpp b/components/esm/loadgmst.hpp index 01fbc3067..dc0400a4e 100644 --- a/components/esm/loadgmst.hpp +++ b/components/esm/loadgmst.hpp @@ -2,6 +2,7 @@ #define _ESM_GMST_H #include "esm_reader.hpp" +#include "esm_writer.hpp" #include "defs.hpp" namespace ESM @@ -83,6 +84,7 @@ struct GameSetting bool isDirtyBloodmoon(); void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadinfo.cpp b/components/esm/loadinfo.cpp index 0f08b3c8a..c240aba87 100644 --- a/components/esm/loadinfo.cpp +++ b/components/esm/loadinfo.cpp @@ -130,4 +130,43 @@ void DialInfo::load(ESMReader &esm) esm.skipRecord(); } +void DialInfo::save(ESMWriter &esm) +{ + esm.writeHNString("INAM", id); + esm.writeHNString("PNAM", prev); + esm.writeHNString("NNAM", next); + esm.writeHNT("DATA", data, 12); + esm.writeHNOString("ONAM", actor); + esm.writeHNOString("RNAM", race); + esm.writeHNOString("CNAM", clas); + esm.writeHNOString("FNAM", npcFaction); + esm.writeHNOString("ANAM", cell); + esm.writeHNOString("DNAM", pcFaction); + esm.writeHNOString("SNAM", sound); + esm.writeHNOString("NAME", response); + + for (std::vector::iterator it = selects.begin(); it != selects.end(); ++it) + { + esm.writeHNString("SCVR", it->selectRule); + switch(it->type) + { + case VT_Int: esm.writeHNT("INTV", it->i); break; + case VT_Float: esm.writeHNT("FLTV", it->f); break; + default: break; + } + } + + if (!resultScript.empty()) + esm.writeHNString("BNAM", resultScript); + + switch(questStatus) + { + case QS_Name: esm.writeHNT("QSTN",'\1'); break; + case QS_Finished: esm.writeHNT("QSTF", '\1'); break; + case QS_Restart: esm.writeHNT("QSTR", '\1'); break; + case QS_Deleted: esm.writeHNT("DELE", '\1'); break; + default: break; + } +} + } diff --git a/components/esm/loadinfo.hpp b/components/esm/loadinfo.hpp index c47af341e..6f2d5ab25 100644 --- a/components/esm/loadinfo.hpp +++ b/components/esm/loadinfo.hpp @@ -2,6 +2,7 @@ #define _ESM_INFO_H #include "esm_reader.hpp" +#include "esm_writer.hpp" #include "defs.hpp" namespace ESM @@ -98,6 +99,7 @@ struct DialInfo }; void load(ESMReader &esm); + void save(ESMWriter &esm); }; /* diff --git a/components/esm/loadingr.cpp b/components/esm/loadingr.cpp index 471f71780..b71f6f13d 100644 --- a/components/esm/loadingr.cpp +++ b/components/esm/loadingr.cpp @@ -11,5 +11,15 @@ void Ingredient::load(ESMReader &esm) script = esm.getHNOString("SCRI"); icon = esm.getHNOString("ITEX"); } +void Ingredient::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); + esm.writeHNString("FNAM", name); + esm.writeHNT("IRDT", data, 56); + if (!script.empty()) + esm.writeHNString("SCRI", script); + if (!icon.empty()) + esm.writeHNString("ITEX", script); +} } diff --git a/components/esm/loadingr.hpp b/components/esm/loadingr.hpp index af9599ed0..040118bbf 100644 --- a/components/esm/loadingr.hpp +++ b/components/esm/loadingr.hpp @@ -2,6 +2,7 @@ #define _ESM_INGR_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -25,6 +26,7 @@ struct Ingredient std::string name, model, icon, script; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index 96afdf831..4d3a4a0ed 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -3,6 +3,17 @@ namespace ESM { +void Land::LandData::save(ESMWriter &esm) +{ + // TODO: Make this actually work. + + //esm.writeHNT("VNML", normals, sizeof(VNML)); + esm.writeHNT("VHGT", heights, sizeof(VHGT)); + esm.writeHNT("WNAM", 0, 81); + esm.writeHNT("VCLR", colours, 3*LAND_NUM_VERTS); + esm.writeHNT("VTEX", textures, 512); +} + Land::Land() : flags(0) , X(0) @@ -71,6 +82,21 @@ void Land::load(ESMReader &esm) landData = NULL; } +void Land::save(ESMWriter &esm) +{ + esm.writeHString("INTV"); + esm.writeT(X); + esm.writeT(Y); + + esm.writeHNT("DATA", flags); + + if (hasData && !dataLoaded) + loadData(); // I think it might be a good idea to have + // the data loaded before trying to save it + if (dataLoaded) + landData->save(esm); +} + void Land::loadData() { if (dataLoaded) diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index ebc314a28..ba506b63b 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -2,6 +2,7 @@ #define _ESM_LAND_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -65,11 +66,14 @@ struct Land bool usingColours; char colours[3 * LAND_NUM_VERTS]; + + void save(ESMWriter &esm); }; LandData *landData; void load(ESMReader &esm); + void save(ESMWriter &esm); /** * Actually loads data diff --git a/components/esm/loadlevlist.cpp b/components/esm/loadlevlist.cpp index d1bff7972..811964775 100644 --- a/components/esm/loadlevlist.cpp +++ b/components/esm/loadlevlist.cpp @@ -30,5 +30,17 @@ void LeveledListBase::load(ESMReader &esm) esm.getHNT(li.level, "INTV"); } } +void LeveledListBase::save(ESMWriter &esm) +{ + esm.writeHNT("DATA", flags); + esm.writeHNT("NNAM", chanceNone); + esm.writeHNT("INDX", list.size()); + + for (std::vector::iterator it = list.begin(); it != list.end(); ++it) + { + esm.writeHNString("INAM", it->id); + esm.writeHNT("INTV", it->level); + } +} } diff --git a/components/esm/loadlevlist.hpp b/components/esm/loadlevlist.hpp index 4affce539..ff20ce9d1 100644 --- a/components/esm/loadlevlist.hpp +++ b/components/esm/loadlevlist.hpp @@ -2,6 +2,7 @@ #define _ESM_LEVLISTS_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -43,6 +44,7 @@ struct LeveledListBase std::vector list; void load(ESMReader &esm); + void save(ESMWriter &esm); }; struct CreatureLevList: LeveledListBase diff --git a/components/esm/loadligh.cpp b/components/esm/loadligh.cpp index 721a818f7..b7530eb6c 100644 --- a/components/esm/loadligh.cpp +++ b/components/esm/loadligh.cpp @@ -13,5 +13,18 @@ void Light::load(ESMReader &esm) script = esm.getHNOString("SCRI"); sound = esm.getHNOString("SNAM"); } +void Light::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); + if (!name.empty()) + esm.writeHNString("FNAM", name); + if (!icon.empty()) + esm.writeHNString("ITEX", icon); + esm.writeHNT("LHDT", data, 24); + if (!script.empty()) + esm.writeHNString("SCRI", script); + if (!sound.empty()) + esm.writeHNString("SNAM", sound); +} } diff --git a/components/esm/loadligh.hpp b/components/esm/loadligh.hpp index 178258a05..aecd8b99b 100644 --- a/components/esm/loadligh.hpp +++ b/components/esm/loadligh.hpp @@ -2,6 +2,7 @@ #define _ESM_LIGH_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -41,6 +42,7 @@ struct Light std::string sound, script, model, icon, name; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadlocks.cpp b/components/esm/loadlocks.cpp index 79e882d94..b9f1d35ca 100644 --- a/components/esm/loadlocks.cpp +++ b/components/esm/loadlocks.cpp @@ -17,14 +17,38 @@ void Tool::load(ESMReader &esm) if (n == "RIDT") { + type = Type_Repair; // Swap t.data.quality and t.data.uses for repair items (sigh) float tmp = *((float*) &data.uses); data.uses = *((int*) &data.quality); data.quality = tmp; } + else if (n == "LKDT") + type = Type_Pick; + else if (n == "PBDT") + type = Type_Probe; script = esm.getHNOString("SCRI"); icon = esm.getHNOString("ITEX"); } +void Tool::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); + esm.writeHNString("FNAM", name); + + switch(type) + { + case Type_Repair: esm.writeHString("RIDT"); break; + case Type_Pick: esm.writeHString("LKDT"); break; + case Type_Probe: esm.writeHString("PBDT"); break; + } + + esm.writeT(data, 16); + if (!script.empty()) + esm.writeHNString("SCRI", script); + if (!icon.empty()) + esm.writeHNString("ITEX", icon); +} + } diff --git a/components/esm/loadlocks.hpp b/components/esm/loadlocks.hpp index a1e537a4c..1c2a709f1 100644 --- a/components/esm/loadlocks.hpp +++ b/components/esm/loadlocks.hpp @@ -2,6 +2,7 @@ #define _ESM_LOCKS_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -13,6 +14,13 @@ namespace ESM struct Tool { + enum Type + { + Type_Pick, + Type_Probe, + Type_Repair + }; + struct Data { float weight; @@ -25,9 +33,11 @@ struct Tool }; // Size = 16 Data data; + Type type; std::string name, model, icon, script; void load(ESMReader &esm); + void save(ESMWriter &esm); }; struct Probe: Tool diff --git a/components/esm/loadltex.cpp b/components/esm/loadltex.cpp index 08b1cf6dc..b4820d9ec 100644 --- a/components/esm/loadltex.cpp +++ b/components/esm/loadltex.cpp @@ -8,5 +8,10 @@ void LandTexture::load(ESMReader &esm) esm.getHNT(index, "INTV"); texture = esm.getHNString("DATA"); } +void LandTexture::save(ESMWriter &esm) +{ + esm.writeHNT("INTV", index); + esm.writeHNString("DATA", texture); +} } diff --git a/components/esm/loadltex.hpp b/components/esm/loadltex.hpp index fa4cac10a..d171c8e11 100644 --- a/components/esm/loadltex.hpp +++ b/components/esm/loadltex.hpp @@ -2,6 +2,7 @@ #define _ESM_LTEX_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -28,6 +29,7 @@ struct LandTexture int index; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadmgef.cpp b/components/esm/loadmgef.cpp index 2eda67b61..8de37f065 100644 --- a/components/esm/loadmgef.cpp +++ b/components/esm/loadmgef.cpp @@ -23,5 +23,24 @@ void MagicEffect::load(ESMReader &esm) description = esm.getHNOString("DESC"); } +void MagicEffect::save(ESMWriter &esm) +{ + esm.writeHNT("INDX", index); + esm.writeHNT("MEDT", data, 36); + + esm.writeHNOString("ITEX", icon); + esm.writeHNOString("PTEX", particle); + esm.writeHNOString("BSND", boltSound); + esm.writeHNOString("CSND", castSound); + esm.writeHNOString("HSND", hitSound); + esm.writeHNOString("ASND", areaSound); + + esm.writeHNOString("CVFX", casting); + esm.writeHNOString("BVFX", bolt); + esm.writeHNOString("HVFX", hit); + esm.writeHNOString("AVFX", area); + + esm.writeHNOString("DESC", description); +} } diff --git a/components/esm/loadmgef.hpp b/components/esm/loadmgef.hpp index b0b330aeb..ed0b03d0b 100644 --- a/components/esm/loadmgef.hpp +++ b/components/esm/loadmgef.hpp @@ -2,6 +2,7 @@ #define _ESM_MGEF_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -46,6 +47,7 @@ struct MagicEffect int index; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadmisc.cpp b/components/esm/loadmisc.cpp index 0206661c4..cf5cf92ae 100644 --- a/components/esm/loadmisc.cpp +++ b/components/esm/loadmisc.cpp @@ -11,5 +11,13 @@ void Miscellaneous::load(ESMReader &esm) script = esm.getHNOString("SCRI"); icon = esm.getHNOString("ITEX"); } +void Miscellaneous::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); + esm.writeHNOString("FNAM", name); + esm.writeHNT("MCDT", data, 12); + esm.writeHNOString("SCRI", script); + esm.writeHNOString("ITEX", icon); +} } diff --git a/components/esm/loadmisc.hpp b/components/esm/loadmisc.hpp index 7e151f797..9aaa3c1be 100644 --- a/components/esm/loadmisc.hpp +++ b/components/esm/loadmisc.hpp @@ -2,6 +2,7 @@ #define _ESM_MISC_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -26,6 +27,7 @@ struct Miscellaneous std::string name, model, icon, script; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadnpc.cpp b/components/esm/loadnpc.cpp index 5b0e90c84..6cb6b64c7 100644 --- a/components/esm/loadnpc.cpp +++ b/components/esm/loadnpc.cpp @@ -23,9 +23,15 @@ void NPC::load(ESMReader &esm, const std::string& id) esm.getSubNameIs("NPDT"); esm.getSubHeader(); if (esm.getSubSize() == 52) + { + npdtType = 52; esm.getExact(&npdt52, 52); + } else if (esm.getSubSize() == 12) + { + npdtType = 12; esm.getExact(&npdt12, 12); + } else esm.fail("NPC_NPDT must be 12 or 52 bytes long"); @@ -44,5 +50,29 @@ void NPC::load(ESMReader &esm, const std::string& id) esm.skipRecord(); } +void NPC::save(ESMWriter &esm) +{ + esm.writeHNOString("MODL", model); + esm.writeHNOString("FNAM", name); + esm.writeHNString("RNAM", race); + esm.writeHNString("CNAM", cls); + esm.writeHNString("ANAM", faction); + esm.writeHNString("BNAM", head); + esm.writeHNString("KNAM", hair); + esm.writeHNOString("SCRI", script); + + if (npdtType == 52) + esm.writeHNT("NPDT", npdt52, 52); + else if (npdtType == 12) + esm.writeHNT("NPDT", npdt12, 12); + + esm.writeHNT("FLAG", flags); + + inventory.save(esm); + spells.save(esm); + + if (hasAI) + esm.writeHNT("AIDT", AI); +} } diff --git a/components/esm/loadnpc.hpp b/components/esm/loadnpc.hpp index 62a99e763..3e094a197 100644 --- a/components/esm/loadnpc.hpp +++ b/components/esm/loadnpc.hpp @@ -2,6 +2,7 @@ #define _ESM_NPC_H #include "esm_reader.hpp" +#include "esm_writer.hpp" #include "loadcont.hpp" #include "defs.hpp" @@ -83,6 +84,7 @@ struct NPC #pragma pack(pop) + char npdtType; NPDTstruct52 npdt52; NPDTstruct12 npdt12; // Use this if npdt52.gold == -10 @@ -101,6 +103,7 @@ struct NPC // Implementation moved to load_impl.cpp void load(ESMReader &esm, const std::string& id); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadnpcc.hpp b/components/esm/loadnpcc.hpp index 592d5b57f..a65f6a6b3 100644 --- a/components/esm/loadnpcc.hpp +++ b/components/esm/loadnpcc.hpp @@ -2,6 +2,7 @@ #define _ESM_NPCC_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -76,6 +77,9 @@ struct LoadNPCC { esm.skipRecord(); } + void save(ESMWriter &esm) + { + } }; } #endif diff --git a/components/esm/loadpgrd.cpp b/components/esm/loadpgrd.cpp index dc63ce335..572378dad 100644 --- a/components/esm/loadpgrd.cpp +++ b/components/esm/loadpgrd.cpp @@ -67,5 +67,28 @@ void Pathgrid::load(ESMReader &esm) } } } +void Pathgrid::save(ESMWriter &esm) +{ + esm.writeHNT("DATA", data, 12); + esm.writeHNString("NAME", cell); + + if (!points.empty()) + { + esm.writeHString("PGRP"); + for (PointList::iterator it = points.begin(); it != points.end(); ++it) + { + esm.writeT(*it); + } + } + + if (!edges.empty()) + { + esm.writeHString("PGRC"); + for (std::vector::iterator it = edges.begin(); it != edges.end(); ++it) + { + esm.writeT(it->v1); + } + } +} } diff --git a/components/esm/loadpgrd.hpp b/components/esm/loadpgrd.hpp index 6e2c6e134..ec339240f 100644 --- a/components/esm/loadpgrd.hpp +++ b/components/esm/loadpgrd.hpp @@ -2,6 +2,7 @@ #define _ESM_PGRD_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -42,6 +43,7 @@ struct Pathgrid EdgeList edges; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadrace.cpp b/components/esm/loadrace.cpp index ce64f5f72..04752add1 100644 --- a/components/esm/loadrace.cpp +++ b/components/esm/loadrace.cpp @@ -10,5 +10,12 @@ void Race::load(ESMReader &esm) powers.load(esm); description = esm.getHNOString("DESC"); } +void Race::save(ESMWriter &esm) +{ + esm.writeHNString("FNAM", name); + esm.writeHNT("RADT", data, 140); + powers.save(esm); + esm.writeHNOString("DESC", description); +} } diff --git a/components/esm/loadrace.hpp b/components/esm/loadrace.hpp index d4506dbef..15fa43984 100644 --- a/components/esm/loadrace.hpp +++ b/components/esm/loadrace.hpp @@ -2,6 +2,7 @@ #define _ESM_RACE_H #include "esm_reader.hpp" +#include "esm_writer.hpp" #include "defs.hpp" namespace ESM @@ -58,6 +59,7 @@ struct Race SpellList powers; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadregn.cpp b/components/esm/loadregn.cpp index f31c9a827..d67922b4d 100644 --- a/components/esm/loadregn.cpp +++ b/components/esm/loadregn.cpp @@ -25,5 +25,19 @@ void Region::load(ESMReader &esm) soundList.push_back(sr); } } +void Region::save(ESMWriter &esm) +{ + esm.writeHNString("FNAM", name); + + esm.writeHNT("WEAT", data); + + esm.writeHNOString("BNAM", sleepList); + + esm.writeHNT("CNAM", mapColor); + for (std::vector::iterator it = soundList.begin(); it != soundList.end(); ++it) + { + esm.writeHNT("SNAM", *it); + } +} } diff --git a/components/esm/loadregn.hpp b/components/esm/loadregn.hpp index 1748b3d28..81b8bc51d 100644 --- a/components/esm/loadregn.hpp +++ b/components/esm/loadregn.hpp @@ -2,6 +2,7 @@ #define _ESM_REGN_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -41,6 +42,7 @@ struct Region std::vector soundList; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadscpt.cpp b/components/esm/loadscpt.cpp index 9c0176725..86d1d8e29 100644 --- a/components/esm/loadscpt.cpp +++ b/components/esm/loadscpt.cpp @@ -38,5 +38,21 @@ void Script::load(ESMReader &esm) // Script text scriptText = esm.getHNOString("SCTX"); } +void Script::save(ESMWriter &esm) +{ + esm.writeHNT("SCHD", data, 52); + + if (!varNames.empty()) + { + esm.writeHString("SCVR"); + for (std::vector::iterator it = varNames.begin(); it != varNames.end(); ++it) + { + esm.writeT(it->c_str(), it->size()); + } + } + + esm.writeHNT("SCDT", &scriptData[0], scriptData.size()); + esm.writeHNOString("SCDT", scriptText); +} } diff --git a/components/esm/loadscpt.hpp b/components/esm/loadscpt.hpp index 3ce3d9636..55cfb053a 100644 --- a/components/esm/loadscpt.hpp +++ b/components/esm/loadscpt.hpp @@ -2,6 +2,7 @@ #define _ESM_SCPT_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -50,6 +51,7 @@ public: std::string scriptText; // Uncompiled script void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadskil.cpp b/components/esm/loadskil.cpp index aa7103efc..adce2f361 100644 --- a/components/esm/loadskil.cpp +++ b/components/esm/loadskil.cpp @@ -67,4 +67,10 @@ void Skill::load(ESMReader &esm) esm.getHNT(data, "SKDT", 24); description = esm.getHNOString("DESC"); } +void Skill::save(ESMWriter &esm) +{ + esm.writeHNT("INDX", index); + esm.writeHNT("SKDT", data, 24); + esm.writeHNOString("DESC", description); +} } diff --git a/components/esm/loadskil.hpp b/components/esm/loadskil.hpp index 836f70205..8cc90b063 100644 --- a/components/esm/loadskil.hpp +++ b/components/esm/loadskil.hpp @@ -4,6 +4,7 @@ #include #include "esm_reader.hpp" +#include "esm_writer.hpp" #include "defs.hpp" namespace ESM { @@ -67,6 +68,7 @@ struct Skill static const boost::array skillIds; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadsndg.cpp b/components/esm/loadsndg.cpp index b7b568132..10f010f48 100644 --- a/components/esm/loadsndg.cpp +++ b/components/esm/loadsndg.cpp @@ -10,5 +10,11 @@ void SoundGenerator::load(ESMReader &esm) creature = esm.getHNOString("CNAM"); sound = esm.getHNOString("SNAM"); } +void SoundGenerator::save(ESMWriter &esm) +{ + esm.writeHNT("DATA", type, 4); + esm.writeHNOString("CNAM", creature); + esm.writeHNOString("SNAM", sound); +} } diff --git a/components/esm/loadsndg.hpp b/components/esm/loadsndg.hpp index 2953369c4..e9e20c212 100644 --- a/components/esm/loadsndg.hpp +++ b/components/esm/loadsndg.hpp @@ -2,6 +2,7 @@ #define _ESM_SNDG_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -30,6 +31,7 @@ struct SoundGenerator std::string creature, sound; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadsoun.cpp b/components/esm/loadsoun.cpp index cd47f0f17..a160f3d1c 100644 --- a/components/esm/loadsoun.cpp +++ b/components/esm/loadsoun.cpp @@ -14,5 +14,10 @@ void Sound::load(ESMReader &esm) << endl; */ } +void Sound::save(ESMWriter &esm) +{ + esm.writeHNString("FNAM", sound); + esm.writeHNT("DATA", data, 3); +} } diff --git a/components/esm/loadsoun.hpp b/components/esm/loadsoun.hpp index 775a664be..9f0bdf509 100644 --- a/components/esm/loadsoun.hpp +++ b/components/esm/loadsoun.hpp @@ -2,6 +2,7 @@ #define _ESM_SOUN_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -17,6 +18,7 @@ struct Sound std::string sound; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadspel.cpp b/components/esm/loadspel.cpp index c3c928ce6..a87dfb620 100644 --- a/components/esm/loadspel.cpp +++ b/components/esm/loadspel.cpp @@ -9,5 +9,11 @@ void Spell::load(ESMReader &esm) esm.getHNT(data, "SPDT", 12); effects.load(esm); } +void Spell::save(ESMWriter &esm) +{ + esm.writeHNOString("FNAM", name); + esm.writeHNT("SPDT", data, 12); + effects.save(esm); +} } diff --git a/components/esm/loadspel.hpp b/components/esm/loadspel.hpp index c97d037cd..971bf23a4 100644 --- a/components/esm/loadspel.hpp +++ b/components/esm/loadspel.hpp @@ -2,6 +2,7 @@ #define _ESM_SPEL_H #include "esm_reader.hpp" +#include "esm_writer.hpp" #include "defs.hpp" namespace ESM @@ -38,6 +39,7 @@ struct Spell EffectList effects; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadsscr.cpp b/components/esm/loadsscr.cpp index f4e79271c..f1099e67b 100644 --- a/components/esm/loadsscr.cpp +++ b/components/esm/loadsscr.cpp @@ -9,5 +9,10 @@ void StartScript::load(ESMReader &esm) esm.skipHSub(); script = esm.getHNString("NAME"); } +void StartScript::save(ESMWriter &esm) +{ + esm.writeHNString("DATA", "NIET"); + esm.writeHNString("NAME", script); +} } diff --git a/components/esm/loadsscr.hpp b/components/esm/loadsscr.hpp index d18bde101..2cc7eccf9 100644 --- a/components/esm/loadsscr.hpp +++ b/components/esm/loadsscr.hpp @@ -2,6 +2,7 @@ #define _ESM_SSCR_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -20,6 +21,7 @@ struct StartScript // Load a record and add it to the list void load(ESMReader &esm); + void save(ESMWriter &esm); }; } diff --git a/components/esm/loadstat.cpp b/components/esm/loadstat.cpp index 654bf290a..2252e9b03 100644 --- a/components/esm/loadstat.cpp +++ b/components/esm/loadstat.cpp @@ -7,5 +7,9 @@ void Static::load(ESMReader &esm) { model = esm.getHNString("MODL"); } +void Static::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); +} } diff --git a/components/esm/loadstat.hpp b/components/esm/loadstat.hpp index 4f3121d18..a5b82c46d 100644 --- a/components/esm/loadstat.hpp +++ b/components/esm/loadstat.hpp @@ -2,6 +2,7 @@ #define _ESM_STAT_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -22,6 +23,7 @@ struct Static std::string model; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif diff --git a/components/esm/loadweap.cpp b/components/esm/loadweap.cpp index 1910631bc..6cc7fa02d 100644 --- a/components/esm/loadweap.cpp +++ b/components/esm/loadweap.cpp @@ -12,5 +12,14 @@ void Weapon::load(ESMReader &esm) icon = esm.getHNOString("ITEX"); enchant = esm.getHNOString("ENAM"); } +void Weapon::save(ESMWriter &esm) +{ + esm.writeHNString("MODL", model); + esm.writeHNOString("FNAM", name); + esm.writeHNT("WPDT", data, 32); + esm.writeHNOString("SCRI", script); + esm.writeHNOString("ITEX", icon); + esm.writeHNOString("ENAM", enchant); +} } diff --git a/components/esm/loadweap.hpp b/components/esm/loadweap.hpp index 8bd3b147c..8e7947bf3 100644 --- a/components/esm/loadweap.hpp +++ b/components/esm/loadweap.hpp @@ -2,6 +2,7 @@ #define _ESM_WEAP_H #include "esm_reader.hpp" +#include "esm_writer.hpp" namespace ESM { @@ -56,6 +57,7 @@ struct Weapon std::string name, model, icon, enchant, script; void load(ESMReader &esm); + void save(ESMWriter &esm); }; } #endif From 7c1e417f9a4514b1e35cce760ccb58e7d8d2f128 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Fri, 6 Apr 2012 21:14:52 +0200 Subject: [PATCH 02/48] Niceify-ing it (Yes, that's a word) --- components/esm/loadacti.cpp | 5 +---- components/esm/loadalch.cpp | 9 +++------ components/esm/loadappa.cpp | 3 +-- components/esm/loadarmo.cpp | 15 +++++---------- components/esm/loadbook.cpp | 15 +++++---------- components/esm/loadbsgn.cpp | 6 ++---- components/esm/loadcell.cpp | 9 +++------ components/esm/loadclas.cpp | 3 +-- components/esm/loadclot.cpp | 12 ++++-------- components/esm/loadcont.cpp | 6 ++---- components/esm/loadcrea.cpp | 9 +++------ components/esm/loaddoor.cpp | 12 ++++-------- components/esm/loadinfo.cpp | 3 +-- components/esm/loadingr.cpp | 6 ++---- components/esm/loadligh.cpp | 12 ++++-------- components/esm/loadlocks.cpp | 6 ++---- 16 files changed, 43 insertions(+), 88 deletions(-) diff --git a/components/esm/loadacti.cpp b/components/esm/loadacti.cpp index a5e59a006..b62a46158 100644 --- a/components/esm/loadacti.cpp +++ b/components/esm/loadacti.cpp @@ -12,9 +12,6 @@ void Activator::save(ESMWriter &esm) { esm.writeHNString("MODL", model); esm.writeHNString("FNAM", name); - if (!script.empty()) - { - esm.writeHNString("SCRI", script); - } + esm.writeHNOString("SCRI", script); } } diff --git a/components/esm/loadalch.cpp b/components/esm/loadalch.cpp index 7db9ef9ac..e5d3d8e27 100644 --- a/components/esm/loadalch.cpp +++ b/components/esm/loadalch.cpp @@ -14,12 +14,9 @@ void Potion::load(ESMReader &esm) void Potion::save(ESMWriter &esm) { esm.writeHNString("MODL", model); - if (!icon.empty()) - esm.writeHNString("TEXT", icon); - if (!script.empty()) - esm.writeHNString("SCRI", script); - if (!name.empty()) - esm.writeHNString("FNAM", name); + esm.writeHNOString("TEXT", icon); + esm.writeHNOString("SCRI", script); + esm.writeHNOString("FNAM", name); esm.writeHNT("ALDT", data, 12); effects.save(esm); } diff --git a/components/esm/loadappa.cpp b/components/esm/loadappa.cpp index 17cc22087..6eb164ec2 100644 --- a/components/esm/loadappa.cpp +++ b/components/esm/loadappa.cpp @@ -15,8 +15,7 @@ void Apparatus::save(ESMWriter &esm) esm.writeHNString("MODL", model); esm.writeHNString("FNAM", name); esm.writeHNT("AADT", data, 16); - if (!script.empty()) - esm.writeHNString("SCRI", script); + esm.writeHNOString("SCRI", script); esm.writeHNString("ITEX", icon); } } diff --git a/components/esm/loadarmo.cpp b/components/esm/loadarmo.cpp index 14cb056bf..aecfc7e92 100644 --- a/components/esm/loadarmo.cpp +++ b/components/esm/loadarmo.cpp @@ -20,10 +20,8 @@ void PartReferenceList::save(ESMWriter &esm) for (std::vector::iterator it = parts.begin(); it != parts.end(); ++it) { esm.writeHT(it->part); - if (!it->male.empty()) - esm.writeHNString("BNAM", it->male); - if (!it->female.empty()) - esm.writeHNString("CNAM", it->female); + esm.writeHNOString("BNAM", it->male); + esm.writeHNOString("CNAM", it->female); } } @@ -42,14 +40,11 @@ void Armor::save(ESMWriter &esm) { esm.writeHNString("MODL", model); esm.writeHNString("FNAM", name); - if (!script.empty()) - esm.writeHNString("SCRI", script); + esm.writeHNOString("SCRI", script); esm.writeHNT("AODT", data, 24); - if (!icon.empty()) - esm.writeHNString("ITEX", icon); + esm.writeHNOString("ITEX", icon); parts.save(esm); - if (!enchant.empty()) - esm.writeHNString("ENAM", enchant); + esm.writeHNOString("ENAM", enchant); } } diff --git a/components/esm/loadbook.cpp b/components/esm/loadbook.cpp index 829b7d297..ed21d71e1 100644 --- a/components/esm/loadbook.cpp +++ b/components/esm/loadbook.cpp @@ -16,17 +16,12 @@ void Book::load(ESMReader &esm) void Book::save(ESMWriter &esm) { esm.writeHNString("MODL", model); - if (!name.empty()) - esm.writeHNString("FNAM", name); + esm.writeHNOString("FNAM", name); esm.writeHNT("BKDT", data, 20); - if (!script.empty()) - esm.writeHNString("SCRI", script); - if (!icon.empty()) - esm.writeHNString("ITEX", icon); - if (!text.empty()) - esm.writeHNString("TEXT", text); - if (!enchant.empty()) - esm.writeHNString("ENAM", enchant); + esm.writeHNOString("SCRI", script); + esm.writeHNOString("ITEX", icon); + esm.writeHNOString("TEXT", text); + esm.writeHNOString("ENAM", enchant); } } diff --git a/components/esm/loadbsgn.cpp b/components/esm/loadbsgn.cpp index 9488f355f..de76e1949 100644 --- a/components/esm/loadbsgn.cpp +++ b/components/esm/loadbsgn.cpp @@ -14,10 +14,8 @@ void BirthSign::load(ESMReader &esm) void BirthSign::save(ESMWriter &esm) { esm.writeHNString("FNAM", name); - if (!texture.empty()) - esm.writeHNString("TNAM", texture); - if (!description.empty()) - esm.writeHNString("DESC", description); + esm.writeHNOString("TNAM", texture); + esm.writeHNOString("DESC", description); powers.save(esm); } diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 8b3d09183..f6db5c70c 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -100,18 +100,15 @@ void Cell::save(ESMWriter &esm) { if (water != 0) esm.writeHNT("WHGT", water); + if (data.flags & QuasiEx) - { - if (!region.empty()) - esm.writeHNString("RGNN", region); - } + esm.writeHNOString("RGNN", region); else esm.writeHNT("AMBI", ambi, 16); } else { - if (!region.empty()) - esm.writeHNString("RGNN", region); + esm.writeHNOString("RGNN", region); if (mapColor != 0) esm.writeHNT("NAM5", mapColor); } diff --git a/components/esm/loadclas.cpp b/components/esm/loadclas.cpp index 05cbfe709..e13442dcf 100644 --- a/components/esm/loadclas.cpp +++ b/components/esm/loadclas.cpp @@ -29,8 +29,7 @@ void Class::save(ESMWriter &esm) { esm.writeHNString("FNAM", name); esm.writeHNT("CLDT", data, 60); - if (!description.empty()) - esm.writeHNString("DESC", description); + esm.writeHNOString("DESC", description); } } diff --git a/components/esm/loadclot.cpp b/components/esm/loadclot.cpp index b1c678348..cd884d206 100644 --- a/components/esm/loadclot.cpp +++ b/components/esm/loadclot.cpp @@ -19,19 +19,15 @@ void Clothing::load(ESMReader &esm) void Clothing::save(ESMWriter &esm) { esm.writeHNString("MODL", model); - if (!name.empty()) - esm.writeHNString("FNAM", name); + esm.writeHNOString("FNAM", name); esm.writeHNT("CTDT", data, 12); - if (!script.empty()) - esm.writeHNString("SCRI", script); - if (!icon.empty()) - esm.writeHNString("ITEX", icon); + esm.writeHNOString("SCRI", script); + esm.writeHNOString("ITEX", icon); parts.save(esm); - if (!enchant.empty()) - esm.writeHNString("ENAM", enchant); + esm.writeHNOString("ENAM", enchant); } } diff --git a/components/esm/loadcont.cpp b/components/esm/loadcont.cpp index ba90e52ce..176c4ec05 100644 --- a/components/esm/loadcont.cpp +++ b/components/esm/loadcont.cpp @@ -41,13 +41,11 @@ void Container::load(ESMReader &esm) void Container::save(ESMWriter &esm) { esm.writeHNString("MODL", model); - if (!name.empty()) - esm.writeHNString("FNAM", name); + esm.writeHNOString("FNAM", name); esm.writeHNT("CNDT", weight, 4); esm.writeHNT("FLAG", flags, 4); - if (!script.empty()) - esm.writeHNString("SCRI", script); + esm.writeHNOString("SCRI", script); inventory.save(esm); } diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index 0cab2761e..f5ffb694f 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -40,12 +40,9 @@ void Creature::load(ESMReader &esm, const std::string& id) void Creature::save(ESMWriter &esm) { esm.writeHNString("MODL", model); - if (!original.empty()) - esm.writeHNString("CNAM", original); - if (!name.empty()) - esm.writeHNString("FNAM", name); - if (!script.empty()) - esm.writeHNString("SCRI", script); + esm.writeHNOString("CNAM", original); + esm.writeHNOString("FNAM", name); + esm.writeHNOString("SCRI", script); esm.writeHNT("NPDT", data, 96); esm.writeHNT("FLAG", flags); if (scale != 1.0) diff --git a/components/esm/loaddoor.cpp b/components/esm/loaddoor.cpp index 513eac753..45af407e1 100644 --- a/components/esm/loaddoor.cpp +++ b/components/esm/loaddoor.cpp @@ -14,14 +14,10 @@ void Door::load(ESMReader &esm) void Door::save(ESMWriter &esm) { esm.writeHNString("MODL", model); - if (!name.empty()) - esm.writeHNString("FNAM", name); - if (!script.empty()) - esm.writeHNString("SCRI", script); - if (!openSound.empty()) - esm.writeHNString("SNAM", openSound); - if (!closeSound.empty()) - esm.writeHNString("ANAM", closeSound); + esm.writeHNOString("FNAM", name); + esm.writeHNOString("SCRI", script); + esm.writeHNOString("SNAM", openSound); + esm.writeHNOString("ANAM", closeSound); } } diff --git a/components/esm/loadinfo.cpp b/components/esm/loadinfo.cpp index c240aba87..63b3fe3a2 100644 --- a/components/esm/loadinfo.cpp +++ b/components/esm/loadinfo.cpp @@ -156,8 +156,7 @@ void DialInfo::save(ESMWriter &esm) } } - if (!resultScript.empty()) - esm.writeHNString("BNAM", resultScript); + esm.writeHNOString("BNAM", resultScript); switch(questStatus) { diff --git a/components/esm/loadingr.cpp b/components/esm/loadingr.cpp index b71f6f13d..b8b8aea06 100644 --- a/components/esm/loadingr.cpp +++ b/components/esm/loadingr.cpp @@ -16,10 +16,8 @@ void Ingredient::save(ESMWriter &esm) esm.writeHNString("MODL", model); esm.writeHNString("FNAM", name); esm.writeHNT("IRDT", data, 56); - if (!script.empty()) - esm.writeHNString("SCRI", script); - if (!icon.empty()) - esm.writeHNString("ITEX", script); + esm.writeHNOString("SCRI", script); + esm.writeHNOString("ITEX", script); } } diff --git a/components/esm/loadligh.cpp b/components/esm/loadligh.cpp index b7530eb6c..2b1d37461 100644 --- a/components/esm/loadligh.cpp +++ b/components/esm/loadligh.cpp @@ -16,15 +16,11 @@ void Light::load(ESMReader &esm) void Light::save(ESMWriter &esm) { esm.writeHNString("MODL", model); - if (!name.empty()) - esm.writeHNString("FNAM", name); - if (!icon.empty()) - esm.writeHNString("ITEX", icon); + esm.writeHNOString("FNAM", name); + esm.writeHNOString("ITEX", icon); esm.writeHNT("LHDT", data, 24); - if (!script.empty()) - esm.writeHNString("SCRI", script); - if (!sound.empty()) - esm.writeHNString("SNAM", sound); + esm.writeHNOString("SCRI", script); + esm.writeHNOString("SNAM", sound); } } diff --git a/components/esm/loadlocks.cpp b/components/esm/loadlocks.cpp index b9f1d35ca..ff01aac37 100644 --- a/components/esm/loadlocks.cpp +++ b/components/esm/loadlocks.cpp @@ -44,10 +44,8 @@ void Tool::save(ESMWriter &esm) } esm.writeT(data, 16); - if (!script.empty()) - esm.writeHNString("SCRI", script); - if (!icon.empty()) - esm.writeHNString("ITEX", icon); + esm.writeHNOString("SCRI", script); + esm.writeHNOString("ITEX", icon); } From b81ac363fc520b09f1109a0c328bff8b53649601 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Fri, 6 Apr 2012 21:28:58 +0200 Subject: [PATCH 03/48] Write names with a small sanity check --- components/esm/esm_writer.cpp | 1 + components/esm/loadland.cpp | 2 +- components/esm/loadlocks.cpp | 6 +++--- components/esm/loadpgrd.cpp | 4 ++-- components/esm/loadscpt.cpp | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/components/esm/esm_writer.cpp b/components/esm/esm_writer.cpp index da040c664..b4690807c 100644 --- a/components/esm/esm_writer.cpp +++ b/components/esm/esm_writer.cpp @@ -17,6 +17,7 @@ void ESMWriter::writeHString(const std::string& data) void ESMWriter::writeName(const std::string& name) { + assert((name.size() == 4 && name.c_str()[3] != '\0') || (name.size() == 5 && name.c_str()[4] == '\0')); write(name.c_str(), name.size()-1); } diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index 4d3a4a0ed..9aa02e478 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -84,7 +84,7 @@ void Land::load(ESMReader &esm) void Land::save(ESMWriter &esm) { - esm.writeHString("INTV"); + esm.writeName("INTV"); esm.writeT(X); esm.writeT(Y); diff --git a/components/esm/loadlocks.cpp b/components/esm/loadlocks.cpp index ff01aac37..f49de1bc8 100644 --- a/components/esm/loadlocks.cpp +++ b/components/esm/loadlocks.cpp @@ -38,9 +38,9 @@ void Tool::save(ESMWriter &esm) switch(type) { - case Type_Repair: esm.writeHString("RIDT"); break; - case Type_Pick: esm.writeHString("LKDT"); break; - case Type_Probe: esm.writeHString("PBDT"); break; + case Type_Repair: esm.writeName("RIDT"); break; + case Type_Pick: esm.writeName("LKDT"); break; + case Type_Probe: esm.writeName("PBDT"); break; } esm.writeT(data, 16); diff --git a/components/esm/loadpgrd.cpp b/components/esm/loadpgrd.cpp index 572378dad..41dd34174 100644 --- a/components/esm/loadpgrd.cpp +++ b/components/esm/loadpgrd.cpp @@ -74,7 +74,7 @@ void Pathgrid::save(ESMWriter &esm) if (!points.empty()) { - esm.writeHString("PGRP"); + esm.writeName("PGRP"); for (PointList::iterator it = points.begin(); it != points.end(); ++it) { esm.writeT(*it); @@ -83,7 +83,7 @@ void Pathgrid::save(ESMWriter &esm) if (!edges.empty()) { - esm.writeHString("PGRC"); + esm.writeName("PGRC"); for (std::vector::iterator it = edges.begin(); it != edges.end(); ++it) { esm.writeT(it->v1); diff --git a/components/esm/loadscpt.cpp b/components/esm/loadscpt.cpp index 86d1d8e29..291259bc0 100644 --- a/components/esm/loadscpt.cpp +++ b/components/esm/loadscpt.cpp @@ -44,7 +44,7 @@ void Script::save(ESMWriter &esm) if (!varNames.empty()) { - esm.writeHString("SCVR"); + esm.writeName("SCVR"); for (std::vector::iterator it = varNames.begin(); it != varNames.end(); ++it) { esm.writeT(it->c_str(), it->size()); From 47013799ea43d6262f63588506d823633a213ba3 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Fri, 6 Apr 2012 22:25:33 +0200 Subject: [PATCH 04/48] Fleshing out the esm writer a bit --- components/esm/esm_writer.cpp | 38 ++++++++++++++++++++++++++++++++++- components/esm/esm_writer.hpp | 13 ++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/components/esm/esm_writer.cpp b/components/esm/esm_writer.cpp index b4690807c..1875ae330 100644 --- a/components/esm/esm_writer.cpp +++ b/components/esm/esm_writer.cpp @@ -3,6 +3,42 @@ namespace ESM { +void ESMWriter::setVersion(Version ver) +{ + m_header.version = ver; +} + +void ESMWriter::setType(FileType type) +{ + m_header.type = type; +} + +void ESMWriter::setAuthor(const std::string& auth) +{ + strcpy(auth.c_str(), m_header.author, 32); +} + +void ESMWriter::setDescription(const std::string& desc) +{ + strcpy(desc.c_str(), m_header.desc, 256); +} + +void ESMWriter::save(const std::string& file) +{ + std::ostream os(file, "wb"); + save(os); +} + +void ESMWriter::save(std::ostream& file) +{ + // TODO: Saving +} + +void ESMWriter::close() +{ + // TODO: Saving +} + void ESMWriter::writeHNString(const std::string& name, const std::string& data) { writeName(name); @@ -17,7 +53,7 @@ void ESMWriter::writeHString(const std::string& data) void ESMWriter::writeName(const std::string& name) { - assert((name.size() == 4 && name.c_str()[3] != '\0') || (name.size() == 5 && name.c_str()[4] == '\0')); + assert((name.size() == 4 && name[3] != '\0') || (name.size() == 5 && name[4] == '\0')); write(name.c_str(), name.size()-1); } diff --git a/components/esm/esm_writer.hpp b/components/esm/esm_writer.hpp index 5adf32049..21cb42de9 100644 --- a/components/esm/esm_writer.hpp +++ b/components/esm/esm_writer.hpp @@ -11,6 +11,16 @@ namespace ESM { class ESMWriter { public: + void setVersion(Version ver); + void setType(FileType type); + + void setAuthor(const std::string& author); + void setDescription(const std::string& desc); + + void save(const std::string& file); + void save(std::ostream& file); + void close(); + void writeHNString(const std::string& name, const std::string& data); void writeHNOString(const std::string& name, const std::string& data) { @@ -65,6 +75,9 @@ public: private: std::ostream m_stream; + + HEDRstruct m_header; + SaveData m_saveData; }; } From 0fd48c42295c7c8d1bfc0ecb2be85eaa2d270209 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Sun, 8 Apr 2012 11:51:52 +0200 Subject: [PATCH 05/48] Extended the esmtool a bit and prepared all records for saving. --- apps/esmtool/esmtool.cpp | 899 +++++++++++++++++++++--------- components/esm/esm_writer.cpp | 46 +- components/esm/esm_writer.hpp | 14 +- components/esm/loadacti.hpp | 5 +- components/esm/loadalch.hpp | 5 +- components/esm/loadappa.hpp | 5 +- components/esm/loadarmo.hpp | 5 +- components/esm/loadbody.hpp | 5 +- components/esm/loadbook.hpp | 5 +- components/esm/loadbsgn.hpp | 5 +- components/esm/loadcell.hpp | 5 +- components/esm/loadclas.hpp | 5 +- components/esm/loadclot.hpp | 5 +- components/esm/loadcont.hpp | 5 +- components/esm/loadcrea.cpp | 5 +- components/esm/loadcrea.hpp | 8 +- components/esm/loadcrec.hpp | 17 +- components/esm/loaddial.hpp | 5 +- components/esm/loaddoor.hpp | 5 +- components/esm/loadench.hpp | 5 +- components/esm/loadfact.hpp | 5 +- components/esm/loadglob.hpp | 5 +- components/esm/loadgmst.hpp | 5 +- components/esm/loadinfo.hpp | 5 +- components/esm/loadingr.hpp | 5 +- components/esm/loadland.hpp | 5 +- components/esm/loadlevlist.hpp | 11 +- components/esm/loadligh.hpp | 5 +- components/esm/loadlocks.hpp | 17 +- components/esm/loadltex.hpp | 5 +- components/esm/loadmgef.hpp | 5 +- components/esm/loadmisc.hpp | 5 +- components/esm/loadnpc.cpp | 5 +- components/esm/loadnpc.hpp | 8 +- components/esm/loadnpcc.hpp | 5 +- components/esm/loadpgrd.hpp | 5 +- components/esm/loadrace.hpp | 5 +- components/esm/loadregn.hpp | 5 +- components/esm/loadscpt.hpp | 5 +- components/esm/loadskil.hpp | 5 +- components/esm/loadsndg.hpp | 5 +- components/esm/loadsoun.hpp | 5 +- components/esm/loadspel.hpp | 5 +- components/esm/loadsscr.hpp | 5 +- components/esm/loadstat.hpp | 5 +- components/esm/loadweap.hpp | 5 +- components/esm/record.hpp | 70 +++ components/esm/records.hpp | 54 +- components/esm_store/reclists.hpp | 3 +- 49 files changed, 950 insertions(+), 387 deletions(-) create mode 100644 components/esm/record.hpp diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index f417d5c60..ea9a388a5 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -1,8 +1,10 @@ #include +#include #include #include +#include #include #define ESMTOOL_VERSION 1.1 @@ -16,19 +18,33 @@ namespace bpo = boost::program_options; void printRaw(ESMReader &esm); void loadCell(Cell &cell, ESMReader &esm, bool quiet); +struct ESMData +{ + std::string author; + std::string description; + ESMReader::MasterList masters; + + std::list records; +}; + // Based on the legacy struct struct Arguments { unsigned int raw_given; unsigned int quiet_given; unsigned int loadcells_given; + + std::string mode; std::string encoding; std::string filename; + std::string outname; + + ESMData data; }; bool parseOptions (int argc, char** argv, Arguments &info) { - bpo::options_description desc("Inspect and extract from Morrowind ES files (ESM, ESP, ESS)\nSyntax: esmtool [options] file \nAllowed options"); + bpo::options_description desc("Inspect and extract from Morrowind ES files (ESM, ESP, ESS)\nSyntax: esmtool [options] mode infile [outfile]\nAllowed options"); desc.add_options() ("help,h", "print help message.") @@ -38,11 +54,11 @@ bool parseOptions (int argc, char** argv, Arguments &info) ("loadcells,C", "Browse through contents of all cells.") ( "encoding,e", bpo::value(&(info.encoding))-> - default_value("win1252"), - "Character encoding used in ESMTool:\n" - "\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages\n" - "\n\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages\n" - "\n\twin1252 - Western European (Latin) alphabet, used by default") + default_value("win1252"), + "Character encoding used in ESMTool:\n" + "\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages\n" + "\n\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages\n" + "\n\twin1252 - Western European (Latin) alphabet, used by default") ; std::string finalText = "\nIf no option is given, the default action is to parse all records in the archive\nand display diagnostic information."; @@ -51,11 +67,12 @@ bool parseOptions (int argc, char** argv, Arguments &info) bpo::options_description hidden("Hidden Options"); hidden.add_options() + ( "mode,m", bpo::value(), "esmtool mode") ( "input-file,i", bpo::value< vector >(), "input file") ; bpo::positional_options_description p; - p.add("input-file", -1); + p.add("mode", 1).add("input-file", 2); // there might be a better way to do this bpo::options_description all; @@ -77,6 +94,12 @@ bool parseOptions (int argc, char** argv, Arguments &info) std::cout << "ESMTool version " << ESMTOOL_VERSION << std::endl; return false; } + if (!variables.count("mode")) + { + std::cout << "No mode specified!" << std::endl << std::endl + << desc << finalText << std::endl; + return false; + } if ( !variables.count("input-file") ) { @@ -86,14 +109,18 @@ bool parseOptions (int argc, char** argv, Arguments &info) } // handling gracefully the user adding multiple files - if (variables["input-file"].as< vector >().size() > 1) - { - std::cout << "\nERROR: more than one ES file specified\n\n"; - std::cout << desc << finalText << std::endl; - return false; - } +/* if (variables["input-file"].as< vector >().size() > 1) + { + std::cout << "\nERROR: more than one ES file specified\n\n"; + std::cout << desc << finalText << std::endl; + return false; + }*/ + + info.mode = variables["mode"].as(); info.filename = variables["input-file"].as< vector >()[0]; + if (variables["input-file"].as< vector >().size() > 1) + info.outname = variables["input-file"].as< vector >()[1]; info.raw_given = variables.count ("raw"); info.quiet_given = variables.count ("quiet"); @@ -122,288 +149,612 @@ bool parseOptions (int argc, char** argv, Arguments &info) return true; } +int load(Arguments& info); +int clone(Arguments& info); int main(int argc, char**argv) { - Arguments info; - if(!parseOptions (argc, argv, info)) - return 1; + Arguments info; + if(!parseOptions (argc, argv, info)) + return 1; - ESMReader esm; - esm.setEncoding(info.encoding); - - string filename = info.filename; - cout << "\nFile: " << filename << endl; - - try { - - if(info.raw_given) + if (info.mode == "dump") + return load(info); + else if (info.mode == "clone") + return clone(info); + else { - cout << "RAW file listing:\n"; - - esm.openRaw(filename); - - printRaw(esm); - - return 0; + cout << "Invalid or no mode specified, dying horribly. Have a nice day." << endl; + return 1; } - bool quiet = info.quiet_given; - bool loadCells = info.loadcells_given; - - esm.open(filename); - - cout << "Author: " << esm.getAuthor() << endl; - cout << "Description: " << esm.getDesc() << endl; - cout << "File format version: " << esm.getFVer() << endl; - cout << "Special flag: " << esm.getSpecial() << endl; - cout << "Masters:\n"; - ESMReader::MasterList m = esm.getMasters(); - for(unsigned int i=0;i skipped; + + try { + + if(info.raw_given) + { + cout << "RAW file listing:\n"; + + esm.openRaw(filename); + + printRaw(esm); + + return 0; + } + + bool quiet = (info.quiet_given || info.mode == "clone"); + bool loadCells = (info.loadcells_given || info.mode == "clone"); + bool save = (info.mode == "clone"); + + esm.open(filename); + + info.data.author = esm.getAuthor(); + info.data.description = esm.getDesc(); + info.data.masters = esm.getMasters(); + + cout << "Author: " << esm.getAuthor() << endl; + cout << "Description: " << esm.getDesc() << endl; + cout << "File format version: " << esm.getFVer() << endl; + cout << "Special flag: " << esm.getSpecial() << endl; + cout << "Masters:\n"; + ESMReader::MasterList m = esm.getMasters(); + for(unsigned int i=0;i::iterator it = info.data.records.begin(); it != info.data.records.end();) + { + delete *it; + info.data.records.erase(it++); + } + return 1; + } + + return 0; +} + +#include + +int clone(Arguments& info) +{ + if (info.outname.empty()) + { + cout << "You need to specify an output name" << endl; + return 1; + } + + if (load(info) != 0) + { + cout << "Failed to load, aborting." << endl; + return 1; + } + + cout << "Loaded " << info.data.records.size() << " records:" << endl; + + std::map records; + + for (std::list::iterator it = info.data.records.begin(); it != info.data.records.end();) + { + Record* rec = *it; + NAME n; + n.val = rec->getName(); + records[n.toString()]++; + + delete rec; + info.data.records.erase(it++); + } + + for (std::map::iterator it = records.begin(); it != records.end(); ++it) + { + std::string n = it->first; + cout << n << ": " << it->second << " records." << endl; + } + + return 0; +} diff --git a/components/esm/esm_writer.cpp b/components/esm/esm_writer.cpp index 1875ae330..57517b0f5 100644 --- a/components/esm/esm_writer.cpp +++ b/components/esm/esm_writer.cpp @@ -1,4 +1,6 @@ #include "esm_writer.hpp" +#include +#include namespace ESM { @@ -15,22 +17,31 @@ void ESMWriter::setType(FileType type) void ESMWriter::setAuthor(const std::string& auth) { - strcpy(auth.c_str(), m_header.author, 32); + strncpy((char*)&m_header.author, auth.c_str(), 32); } void ESMWriter::setDescription(const std::string& desc) { - strcpy(desc.c_str(), m_header.desc, 256); + strncpy((char*)&m_header.desc, desc.c_str(), 256); } void ESMWriter::save(const std::string& file) { - std::ostream os(file, "wb"); - save(os); + std::ofstream fs(file.c_str(), std::ios_base::out | std::ios_base::trunc); + save(fs); + fs.close(); } void ESMWriter::save(std::ostream& file) { + m_stream = &file; + + startRecord("TES3"); + writeT(0); + writeT(0); + + endRecord(); + // TODO: Saving } @@ -39,6 +50,28 @@ void ESMWriter::close() // TODO: Saving } +void ESMWriter::startRecord(const std::string& name) +{ + writeName(name); + RecordData rec; + rec.position = m_stream->tellp(); + rec.size = 0; + m_records.push_back(rec); + writeT(0); +} + +void ESMWriter::endRecord() +{ + std::streampos cur = m_stream->tellp(); + RecordData rec = m_records.back(); + m_records.pop_back(); + + m_stream->seekp(rec.position); + m_stream->write((char*)&rec.size, sizeof(int)); + + m_stream->seekp(cur); +} + void ESMWriter::writeHNString(const std::string& name, const std::string& data) { writeName(name); @@ -59,7 +92,10 @@ void ESMWriter::writeName(const std::string& name) void ESMWriter::write(const char* data, int size) { - m_stream.write(data, size); + if (!m_records.empty()) + m_records.back().size += size; + + m_stream->write(data, size); } } diff --git a/components/esm/esm_writer.hpp b/components/esm/esm_writer.hpp index 21cb42de9..3999e987d 100644 --- a/components/esm/esm_writer.hpp +++ b/components/esm/esm_writer.hpp @@ -2,6 +2,7 @@ #define _ESM_WRITER_H #include +#include #include #include "esm_common.hpp" @@ -10,6 +11,12 @@ namespace ESM { class ESMWriter { + struct RecordData + { + std::streampos position; + int size; + }; + public: void setVersion(Version ver); void setType(FileType type); @@ -68,13 +75,16 @@ public: assert(sizeof(T) == size); writeT(data); } - + + void startRecord(const std::string& name); + void endRecord(); void writeHString(const std::string& data); void writeName(const std::string& data); void write(const char* data, int size); private: - std::ostream m_stream; + std::vector m_records; + std::ostream* m_stream; HEDRstruct m_header; SaveData m_saveData; diff --git a/components/esm/loadacti.hpp b/components/esm/loadacti.hpp index 3f968bc7c..083c8fc67 100644 --- a/components/esm/loadacti.hpp +++ b/components/esm/loadacti.hpp @@ -1,18 +1,21 @@ #ifndef _ESM_ACTI_H #define _ESM_ACTI_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" namespace ESM { -struct Activator +struct Activator : public Record { std::string name, script, model; void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_ACTI; } }; } #endif diff --git a/components/esm/loadalch.hpp b/components/esm/loadalch.hpp index b447fe50c..5adc44ee2 100644 --- a/components/esm/loadalch.hpp +++ b/components/esm/loadalch.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_ALCH_H #define _ESM_ALCH_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" #include "defs.hpp" @@ -12,7 +13,7 @@ namespace ESM * Alchemy item (potions) */ -struct Potion +struct Potion : public Record { struct ALDTstruct { @@ -27,6 +28,8 @@ struct Potion void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_ALCH; } }; } #endif diff --git a/components/esm/loadappa.hpp b/components/esm/loadappa.hpp index ff105a307..8321778db 100644 --- a/components/esm/loadappa.hpp +++ b/components/esm/loadappa.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_APPA_H #define _ESM_APPA_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -11,7 +12,7 @@ namespace ESM * Alchemist apparatus */ -struct Apparatus +struct Apparatus : public Record { enum AppaType { @@ -34,6 +35,8 @@ struct Apparatus void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_APPA; } }; } #endif diff --git a/components/esm/loadarmo.hpp b/components/esm/loadarmo.hpp index 5026696c2..1b2cb8653 100644 --- a/components/esm/loadarmo.hpp +++ b/components/esm/loadarmo.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_ARMO_H #define _ESM_ARMO_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -54,7 +55,7 @@ struct PartReferenceList void save(ESMWriter &esm); }; -struct Armor +struct Armor : public Record { enum Type { @@ -85,6 +86,8 @@ struct Armor void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_ARMO; } }; } #endif diff --git a/components/esm/loadbody.hpp b/components/esm/loadbody.hpp index 46cb1d899..90605e39d 100644 --- a/components/esm/loadbody.hpp +++ b/components/esm/loadbody.hpp @@ -1,13 +1,14 @@ #ifndef _ESM_BODY_H #define _ESM_BODY_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" namespace ESM { -struct BodyPart +struct BodyPart : public Record { enum MeshPart { @@ -54,6 +55,8 @@ struct BodyPart void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_BODY; } }; } #endif diff --git a/components/esm/loadbook.hpp b/components/esm/loadbook.hpp index a46135cc0..a5a891a58 100644 --- a/components/esm/loadbook.hpp +++ b/components/esm/loadbook.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_BOOK_H #define _ESM_BOOK_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -11,7 +12,7 @@ namespace ESM * Books, magic scrolls, notes and so on */ -struct Book +struct Book : public Record { struct BKDTstruct { @@ -24,6 +25,8 @@ struct Book void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_BOOK; } }; } #endif diff --git a/components/esm/loadbsgn.hpp b/components/esm/loadbsgn.hpp index d00664bff..b094b2e49 100644 --- a/components/esm/loadbsgn.hpp +++ b/components/esm/loadbsgn.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_BSGN_H #define _ESM_BSGN_H +#include "record.hpp" #include "defs.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -8,7 +9,7 @@ namespace ESM { -struct BirthSign +struct BirthSign : public Record { std::string name, description, texture; @@ -17,6 +18,8 @@ struct BirthSign void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_BSGN; } }; } #endif diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index 8d461369c..f03c541b7 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_CELL_H #define _ESM_CELL_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" #include "defs.hpp" @@ -84,7 +85,7 @@ public: (using ESMReader::getContext()) and jumping back into place whenever we need to load a given cell. */ -struct Cell +struct Cell : public Record { enum Flags { @@ -123,6 +124,8 @@ struct Cell void load(ESMReader &esm); void save(ESMWriter &esm); + int getName() { return REC_CELL; } + bool isExterior() const { return !(data.flags & Interior); diff --git a/components/esm/loadclas.hpp b/components/esm/loadclas.hpp index a89481a7a..084f1edb1 100644 --- a/components/esm/loadclas.hpp +++ b/components/esm/loadclas.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_CLAS_H #define _ESM_CLAS_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -13,7 +14,7 @@ namespace ESM // These flags tells us which items should be auto-calculated for this // class -struct Class +struct Class : public Record { enum AutoCalc { @@ -63,6 +64,8 @@ struct Class void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_CLAS; } }; } #endif diff --git a/components/esm/loadclot.hpp b/components/esm/loadclot.hpp index 77ef3786a..4d0ec06cd 100644 --- a/components/esm/loadclot.hpp +++ b/components/esm/loadclot.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_CLOT_H #define _ESM_CLOT_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" #include "loadarmo.hpp" @@ -12,7 +13,7 @@ namespace ESM * Clothing */ -struct Clothing +struct Clothing : public Record { enum Type { @@ -43,6 +44,8 @@ struct Clothing void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_CLOT; } }; } #endif diff --git a/components/esm/loadcont.hpp b/components/esm/loadcont.hpp index bf6994f9a..7d8952e38 100644 --- a/components/esm/loadcont.hpp +++ b/components/esm/loadcont.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_CONT_H #define _ESM_CONT_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -25,7 +26,7 @@ struct InventoryList void save(ESMWriter &esm); }; -struct Container +struct Container : public Record { enum Flags { @@ -42,6 +43,8 @@ struct Container void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_CONT; } }; } #endif diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index f5ffb694f..7b84a7f29 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -2,10 +2,13 @@ namespace ESM { -void Creature::load(ESMReader &esm, const std::string& id) +void Creature::setID(const std::string& id) { mId = id; +} +void Creature::load(ESMReader &esm) +{ model = esm.getHNString("MODL"); original = esm.getHNOString("CNAM"); name = esm.getHNOString("FNAM"); diff --git a/components/esm/loadcrea.hpp b/components/esm/loadcrea.hpp index 2f5f4061d..3035003cf 100644 --- a/components/esm/loadcrea.hpp +++ b/components/esm/loadcrea.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_CREA_H #define _ESM_CREA_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" #include "loadcont.hpp" @@ -13,7 +14,7 @@ namespace ESM * */ -struct Creature +struct Creature : public Record { // Default is 0x48? enum Flags @@ -64,8 +65,11 @@ struct Creature std::string mId; - void load(ESMReader &esm, const std::string& id); + void setID(const std::string& id); + void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_CREA; } }; } #endif diff --git a/components/esm/loadcrec.hpp b/components/esm/loadcrec.hpp index 056f572ae..0a575921a 100644 --- a/components/esm/loadcrec.hpp +++ b/components/esm/loadcrec.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_CREC_H #define _ESM_CREC_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -10,29 +11,33 @@ namespace ESM { */ /// Changes a creature -struct LoadCREC +struct LoadCREC : public Record { - void load(ESMReader &esm) + void load(ESMReader &esm) { esm.skipRecord(); } - void save(ESMWriter &esm) + void save(ESMWriter &esm) { } + + int getName() { return REC_CREC; } }; /// Changes an item list / container -struct LoadCNTC +struct LoadCNTC : public Record { - void load(ESMReader &esm) + void load(ESMReader &esm) { esm.skipRecord(); } - void save(ESMWriter &esm) + void save(ESMWriter &esm) { } + + int getName() { return REC_CNTC; } }; } #endif diff --git a/components/esm/loaddial.hpp b/components/esm/loaddial.hpp index a19b0c7ad..92818598e 100644 --- a/components/esm/loaddial.hpp +++ b/components/esm/loaddial.hpp @@ -3,6 +3,7 @@ #include +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" #include "loadinfo.hpp" @@ -15,7 +16,7 @@ namespace ESM * the INFO records following the DIAL. */ -struct Dialogue +struct Dialogue : public Record { enum Type { @@ -32,6 +33,8 @@ struct Dialogue void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_DIAL; } }; } #endif diff --git a/components/esm/loaddoor.hpp b/components/esm/loaddoor.hpp index 1234ac7f9..e8b3be970 100644 --- a/components/esm/loaddoor.hpp +++ b/components/esm/loaddoor.hpp @@ -1,18 +1,21 @@ #ifndef _ESM_DOOR_H #define _ESM_DOOR_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" namespace ESM { -struct Door +struct Door : public Record { std::string name, model, script, openSound, closeSound; void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_DOOR; } }; } #endif diff --git a/components/esm/loadench.hpp b/components/esm/loadench.hpp index 609166983..1cb417c9f 100644 --- a/components/esm/loadench.hpp +++ b/components/esm/loadench.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_ENCH_H #define _ESM_ENCH_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" #include "defs.hpp" @@ -12,7 +13,7 @@ namespace ESM * Enchantments */ -struct Enchantment +struct Enchantment : public Record { enum Type { @@ -36,6 +37,8 @@ struct Enchantment void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_ENCH; } }; } #endif diff --git a/components/esm/loadfact.hpp b/components/esm/loadfact.hpp index 686554da3..f62c92e19 100644 --- a/components/esm/loadfact.hpp +++ b/components/esm/loadfact.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_FACT_H #define _ESM_FACT_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -24,7 +25,7 @@ struct RankData int factReaction; // Reaction from faction members }; -struct Faction +struct Faction : public Record { std::string id, name; @@ -55,6 +56,8 @@ struct Faction void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_FACT; } }; } #endif diff --git a/components/esm/loadglob.hpp b/components/esm/loadglob.hpp index 669475fe7..8a6991490 100644 --- a/components/esm/loadglob.hpp +++ b/components/esm/loadglob.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_GLOB_H #define _ESM_GLOB_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" #include "defs.hpp" @@ -12,13 +13,15 @@ namespace ESM * Global script variables */ -struct Global +struct Global : public Record { unsigned value; VarType type; void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_GLOB; } }; } #endif diff --git a/components/esm/loadgmst.hpp b/components/esm/loadgmst.hpp index dc0400a4e..0854ea2aa 100644 --- a/components/esm/loadgmst.hpp +++ b/components/esm/loadgmst.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_GMST_H #define _ESM_GMST_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" #include "defs.hpp" @@ -13,7 +14,7 @@ namespace ESM * */ -struct GameSetting +struct GameSetting : public Record { std::string id; @@ -85,6 +86,8 @@ struct GameSetting void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_GMST; } }; } #endif diff --git a/components/esm/loadinfo.hpp b/components/esm/loadinfo.hpp index 6f2d5ab25..36c31a422 100644 --- a/components/esm/loadinfo.hpp +++ b/components/esm/loadinfo.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_INFO_H #define _ESM_INFO_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" #include "defs.hpp" @@ -15,7 +16,7 @@ namespace ESM * and form a linked list of dialogue items. */ -struct DialInfo +struct DialInfo : public Record { enum Gender { @@ -100,6 +101,8 @@ struct DialInfo void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_INFO; } }; /* diff --git a/components/esm/loadingr.hpp b/components/esm/loadingr.hpp index 040118bbf..8536d5b02 100644 --- a/components/esm/loadingr.hpp +++ b/components/esm/loadingr.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_INGR_H #define _ESM_INGR_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -11,7 +12,7 @@ namespace ESM * Alchemy ingredient */ -struct Ingredient +struct Ingredient : public Record { struct IRDTstruct { @@ -27,6 +28,8 @@ struct Ingredient void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_INGR; } }; } #endif diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index ba506b63b..6a14891f1 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_LAND_H #define _ESM_LAND_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -10,7 +11,7 @@ namespace ESM * Landscape data. */ -struct Land +struct Land : public Record { Land(); ~Land(); @@ -75,6 +76,8 @@ struct Land void load(ESMReader &esm); void save(ESMWriter &esm); + int getName() { return REC_LAND; } + /** * Actually loads data */ diff --git a/components/esm/loadlevlist.hpp b/components/esm/loadlevlist.hpp index ff20ce9d1..c8591d7d2 100644 --- a/components/esm/loadlevlist.hpp +++ b/components/esm/loadlevlist.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_LEVLISTS_H #define _ESM_LEVLISTS_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -15,7 +16,7 @@ namespace ESM * several files. */ -struct LeveledListBase +struct LeveledListBase : public Record { enum Flags { @@ -45,6 +46,14 @@ struct LeveledListBase void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() + { + if (recName[0] == 'C') + return REC_LEVC; + + return REC_LEVI; + } }; struct CreatureLevList: LeveledListBase diff --git a/components/esm/loadligh.hpp b/components/esm/loadligh.hpp index aecd8b99b..75a78ae5f 100644 --- a/components/esm/loadligh.hpp +++ b/components/esm/loadligh.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_LIGH_H #define _ESM_LIGH_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -12,7 +13,7 @@ namespace ESM * and torches. */ -struct Light +struct Light : public Record { enum Flags { @@ -43,6 +44,8 @@ struct Light void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_LIGH; } }; } #endif diff --git a/components/esm/loadlocks.hpp b/components/esm/loadlocks.hpp index 1c2a709f1..c92a56ea7 100644 --- a/components/esm/loadlocks.hpp +++ b/components/esm/loadlocks.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_LOCKS_H #define _ESM_LOCKS_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -12,7 +13,7 @@ namespace ESM * items (REPA). These have nearly identical data structures. */ -struct Tool +struct Tool : public Record { enum Type { @@ -38,16 +39,26 @@ struct Tool void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() + { + if (type == Type_Probe) + return REC_PROB; + else if (type == Type_Repair) + return REC_REPA; + else + return REC_LOCK; + } }; struct Probe: Tool { - + Probe() { type = Type_Probe; } }; struct Repair: Tool { - + Repair() { type = Type_Repair; } }; } diff --git a/components/esm/loadltex.hpp b/components/esm/loadltex.hpp index d171c8e11..994e12024 100644 --- a/components/esm/loadltex.hpp +++ b/components/esm/loadltex.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_LTEX_H #define _ESM_LTEX_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -23,13 +24,15 @@ namespace ESM * texture, and see if it affects the game. */ -struct LandTexture +struct LandTexture : public Record { std::string id, texture; int index; void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_LTEX; } }; } #endif diff --git a/components/esm/loadmgef.hpp b/components/esm/loadmgef.hpp index ed0b03d0b..1c95be2bc 100644 --- a/components/esm/loadmgef.hpp +++ b/components/esm/loadmgef.hpp @@ -1,13 +1,14 @@ #ifndef _ESM_MGEF_H #define _ESM_MGEF_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" namespace ESM { -struct MagicEffect +struct MagicEffect : public Record { enum Flags { @@ -48,6 +49,8 @@ struct MagicEffect void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_MGEF; } }; } #endif diff --git a/components/esm/loadmisc.hpp b/components/esm/loadmisc.hpp index 9aaa3c1be..3d6cdb526 100644 --- a/components/esm/loadmisc.hpp +++ b/components/esm/loadmisc.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_MISC_H #define _ESM_MISC_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -12,7 +13,7 @@ namespace ESM * carried, bought and sold. It also includes keys. */ -struct Miscellaneous +struct Miscellaneous : public Record { struct MCDTstruct { @@ -28,6 +29,8 @@ struct Miscellaneous void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_MISC; } }; } #endif diff --git a/components/esm/loadnpc.cpp b/components/esm/loadnpc.cpp index 6cb6b64c7..34b5e69ed 100644 --- a/components/esm/loadnpc.cpp +++ b/components/esm/loadnpc.cpp @@ -3,10 +3,13 @@ namespace ESM { -void NPC::load(ESMReader &esm, const std::string& id) +void NPC::setID(const std::string& id) { mId = id; +} +void NPC::load(ESMReader &esm) +{ npdt52.gold = -10; model = esm.getHNOString("MODL"); diff --git a/components/esm/loadnpc.hpp b/components/esm/loadnpc.hpp index 3e094a197..3f8a60304 100644 --- a/components/esm/loadnpc.hpp +++ b/components/esm/loadnpc.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_NPC_H #define _ESM_NPC_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" #include "loadcont.hpp" @@ -12,7 +13,7 @@ namespace ESM { * NPC definition */ -struct NPC +struct NPC : public Record { // Services enum Services @@ -102,8 +103,11 @@ struct NPC std::string mId; // Implementation moved to load_impl.cpp - void load(ESMReader &esm, const std::string& id); + void setID(const std::string& id); + void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_NPC_; } }; } #endif diff --git a/components/esm/loadnpcc.hpp b/components/esm/loadnpcc.hpp index a65f6a6b3..46d1bf9d2 100644 --- a/components/esm/loadnpcc.hpp +++ b/components/esm/loadnpcc.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_NPCC_H #define _ESM_NPCC_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -71,7 +72,7 @@ namespace ESM { * will be harder than reading it. */ -struct LoadNPCC +struct LoadNPCC : public Record { void load(ESMReader &esm) { @@ -80,6 +81,8 @@ struct LoadNPCC void save(ESMWriter &esm) { } + + int getName() { return REC_NPCC; } }; } #endif diff --git a/components/esm/loadpgrd.hpp b/components/esm/loadpgrd.hpp index ec339240f..db423204c 100644 --- a/components/esm/loadpgrd.hpp +++ b/components/esm/loadpgrd.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_PGRD_H #define _ESM_PGRD_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -10,7 +11,7 @@ namespace ESM /* * Path grid. */ -struct Pathgrid +struct Pathgrid : public Record { struct DATAstruct { @@ -44,6 +45,8 @@ struct Pathgrid void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_PGRD; } }; } #endif diff --git a/components/esm/loadrace.hpp b/components/esm/loadrace.hpp index 15fa43984..5c0593786 100644 --- a/components/esm/loadrace.hpp +++ b/components/esm/loadrace.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_RACE_H #define _ESM_RACE_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" #include "defs.hpp" @@ -12,7 +13,7 @@ namespace ESM * Race definition */ -struct Race +struct Race : public Record { struct SkillBonus { @@ -60,6 +61,8 @@ struct Race void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_RACE; } }; } #endif diff --git a/components/esm/loadregn.hpp b/components/esm/loadregn.hpp index 81b8bc51d..90444b5ad 100644 --- a/components/esm/loadregn.hpp +++ b/components/esm/loadregn.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_REGN_H #define _ESM_REGN_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -11,7 +12,7 @@ namespace ESM * Region data */ -struct Region +struct Region : public Record { #pragma pack(push) #pragma pack(1) @@ -43,6 +44,8 @@ struct Region void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_REGN; } }; } #endif diff --git a/components/esm/loadscpt.hpp b/components/esm/loadscpt.hpp index 55cfb053a..bf6082704 100644 --- a/components/esm/loadscpt.hpp +++ b/components/esm/loadscpt.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_SCPT_H #define _ESM_SCPT_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -11,7 +12,7 @@ namespace ESM * Script definitions */ -class Script +class Script : public Record { public: struct SCHDstruct @@ -52,6 +53,8 @@ public: void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_SCPT; } }; } #endif diff --git a/components/esm/loadskil.hpp b/components/esm/loadskil.hpp index 8cc90b063..68ada6020 100644 --- a/components/esm/loadskil.hpp +++ b/components/esm/loadskil.hpp @@ -3,6 +3,7 @@ #include +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" #include "defs.hpp" @@ -14,7 +15,7 @@ namespace ESM { * */ -struct Skill +struct Skill : public Record { struct SKDTstruct { @@ -69,6 +70,8 @@ struct Skill void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_SKIL; } }; } #endif diff --git a/components/esm/loadsndg.hpp b/components/esm/loadsndg.hpp index e9e20c212..33b89726f 100644 --- a/components/esm/loadsndg.hpp +++ b/components/esm/loadsndg.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_SNDG_H #define _ESM_SNDG_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -11,7 +12,7 @@ namespace ESM * Sound generator. This describes the sounds a creature make. */ -struct SoundGenerator +struct SoundGenerator : public Record { enum Type { @@ -32,6 +33,8 @@ struct SoundGenerator void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_SNDG; } }; } #endif diff --git a/components/esm/loadsoun.hpp b/components/esm/loadsoun.hpp index 9f0bdf509..05663ba22 100644 --- a/components/esm/loadsoun.hpp +++ b/components/esm/loadsoun.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_SOUN_H #define _ESM_SOUN_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -12,13 +13,15 @@ struct SOUNstruct unsigned char volume, minRange, maxRange; }; -struct Sound +struct Sound : public Record { SOUNstruct data; std::string sound; void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_SOUN; } }; } #endif diff --git a/components/esm/loadspel.hpp b/components/esm/loadspel.hpp index 971bf23a4..674f7e35d 100644 --- a/components/esm/loadspel.hpp +++ b/components/esm/loadspel.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_SPEL_H #define _ESM_SPEL_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" #include "defs.hpp" @@ -8,7 +9,7 @@ namespace ESM { -struct Spell +struct Spell : public Record { enum SpellType { @@ -40,6 +41,8 @@ struct Spell void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_SPEL; } }; } #endif diff --git a/components/esm/loadsscr.hpp b/components/esm/loadsscr.hpp index 2cc7eccf9..2249b08ee 100644 --- a/components/esm/loadsscr.hpp +++ b/components/esm/loadsscr.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_SSCR_H #define _ESM_SSCR_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -15,13 +16,15 @@ namespace ESM reference. */ -struct StartScript +struct StartScript : public Record { std::string script; // Load a record and add it to the list void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_SSCR; } }; } diff --git a/components/esm/loadstat.hpp b/components/esm/loadstat.hpp index a5b82c46d..3ebbd4813 100644 --- a/components/esm/loadstat.hpp +++ b/components/esm/loadstat.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_STAT_H #define _ESM_STAT_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -18,12 +19,14 @@ namespace ESM { * you decode the CELL blocks, if you want to test this hypothesis. */ -struct Static +struct Static : public Record { std::string model; void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_STAT; } }; } #endif diff --git a/components/esm/loadweap.hpp b/components/esm/loadweap.hpp index 8e7947bf3..4d464a7ee 100644 --- a/components/esm/loadweap.hpp +++ b/components/esm/loadweap.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_WEAP_H #define _ESM_WEAP_H +#include "record.hpp" #include "esm_reader.hpp" #include "esm_writer.hpp" @@ -11,7 +12,7 @@ namespace ESM * Weapon definition */ -struct Weapon +struct Weapon : public Record { enum Type { @@ -58,6 +59,8 @@ struct Weapon void load(ESMReader &esm); void save(ESMWriter &esm); + + int getName() { return REC_WEAP; } }; } #endif diff --git a/components/esm/record.hpp b/components/esm/record.hpp new file mode 100644 index 000000000..666a6c15b --- /dev/null +++ b/components/esm/record.hpp @@ -0,0 +1,70 @@ +#ifndef _ESM_RECORD_H +#define _ESM_RECORD_H + +namespace ESM +{ + +enum RecNameInts +{ + REC_ACTI = 0x49544341, + REC_ALCH = 0x48434c41, + REC_APPA = 0x41505041, + REC_ARMO = 0x4f4d5241, + REC_BODY = 0x59444f42, + REC_BOOK = 0x4b4f4f42, + REC_BSGN = 0x4e475342, + REC_CELL = 0x4c4c4543, + REC_CLAS = 0x53414c43, + REC_CLOT = 0x544f4c43, + REC_CNTC = 0x43544e43, + REC_CONT = 0x544e4f43, + REC_CREA = 0x41455243, + REC_CREC = 0x43455243, + REC_DIAL = 0x4c414944, + REC_DOOR = 0x524f4f44, + REC_ENCH = 0x48434e45, + REC_FACT = 0x54434146, + REC_GLOB = 0x424f4c47, + REC_GMST = 0x54534d47, + REC_INFO = 0x4f464e49, + REC_INGR = 0x52474e49, + REC_LAND = 0x444e414c, + REC_LEVC = 0x4356454c, + REC_LEVI = 0x4956454c, + REC_LIGH = 0x4847494c, + REC_LOCK = 0x4b434f4c, + REC_LTEX = 0x5845544c, + REC_MGEF = 0x4645474d, + REC_MISC = 0x4353494d, + REC_NPC_ = 0x5f43504e, + REC_NPCC = 0x4343504e, + REC_PGRD = 0x44524750, + REC_PROB = 0x424f5250, + REC_RACE = 0x45434152, + REC_REGN = 0x4e474552, + REC_REPA = 0x41504552, + REC_SCPT = 0x54504353, + REC_SKIL = 0x4c494b53, + REC_SNDG = 0x47444e53, + REC_SOUN = 0x4e554f53, + REC_SPEL = 0x4c455053, + REC_SSCR = 0x52435353, + REC_STAT = 0x54415453, + REC_WEAP = 0x50414557 +}; + +class ESMReader; +class ESMWriter; + +class Record +{ +public: + virtual void load(ESMReader& esm) = 0; + virtual void save(ESMWriter& esm) = 0; + + virtual int getName() = 0; +}; + +} + +#endif diff --git a/components/esm/records.hpp b/components/esm/records.hpp index 704a11609..e05f74f5d 100644 --- a/components/esm/records.hpp +++ b/components/esm/records.hpp @@ -1,6 +1,7 @@ #ifndef _ESM_RECORDS_H #define _ESM_RECORDS_H +#include "record.hpp" #include "loadacti.hpp" #include "loadalch.hpp" #include "loadappa.hpp" @@ -45,57 +46,4 @@ // Special records which are not loaded from ESM #include "attr.hpp" - -namespace ESM { - -// Integer versions of all the record names, used for faster lookup -enum RecNameInts - { - REC_ACTI = 0x49544341, - REC_ALCH = 0x48434c41, - REC_APPA = 0x41505041, - REC_ARMO = 0x4f4d5241, - REC_BODY = 0x59444f42, - REC_BOOK = 0x4b4f4f42, - REC_BSGN = 0x4e475342, - REC_CELL = 0x4c4c4543, - REC_CLAS = 0x53414c43, - REC_CLOT = 0x544f4c43, - REC_CNTC = 0x43544e43, - REC_CONT = 0x544e4f43, - REC_CREA = 0x41455243, - REC_CREC = 0x43455243, - REC_DIAL = 0x4c414944, - REC_DOOR = 0x524f4f44, - REC_ENCH = 0x48434e45, - REC_FACT = 0x54434146, - REC_GLOB = 0x424f4c47, - REC_GMST = 0x54534d47, - REC_INFO = 0x4f464e49, - REC_INGR = 0x52474e49, - REC_LAND = 0x444e414c, - REC_LEVC = 0x4356454c, - REC_LEVI = 0x4956454c, - REC_LIGH = 0x4847494c, - REC_LOCK = 0x4b434f4c, - REC_LTEX = 0x5845544c, - REC_MGEF = 0x4645474d, - REC_MISC = 0x4353494d, - REC_NPC_ = 0x5f43504e, - REC_NPCC = 0x4343504e, - REC_PGRD = 0x44524750, - REC_PROB = 0x424f5250, - REC_RACE = 0x45434152, - REC_REGN = 0x4e474552, - REC_REPA = 0x41504552, - REC_SCPT = 0x54504353, - REC_SKIL = 0x4c494b53, - REC_SNDG = 0x47444e53, - REC_SOUN = 0x4e554f53, - REC_SPEL = 0x4c455053, - REC_SSCR = 0x52435353, - REC_STAT = 0x54415453, - REC_WEAP = 0x50414557 - }; -} #endif diff --git a/components/esm_store/reclists.hpp b/components/esm_store/reclists.hpp index d7a4100aa..bc3b676a2 100644 --- a/components/esm_store/reclists.hpp +++ b/components/esm_store/reclists.hpp @@ -104,7 +104,8 @@ namespace ESMS void load(ESMReader &esm, const std::string &id) { std::string id2 = toLower (id); - list[id2].load(esm, id2); + list[id2].setID(id2); + list[id2].load(esm); } // Find the given object ID, or return NULL if not found. From fc8c75ab892aa51478c3bc7fce728707c3e0cb12 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Sun, 8 Apr 2012 17:04:52 +0200 Subject: [PATCH 06/48] Esmtool can now clone an esm file in such a way that it can read it back again afterwards. --- apps/esmtool/esmtool.cpp | 102 +++++++++++++++++++++++++++------ components/esm/esm_reader.hpp | 1 + components/esm/esm_writer.cpp | 99 +++++++++++++++++++++++++------- components/esm/esm_writer.hpp | 36 +++++++----- components/esm/loadarmo.cpp | 2 +- components/esm/loadfact.cpp | 2 +- components/esm/loadland.cpp | 5 +- components/esm/loadlevlist.cpp | 2 +- components/esm/loadlocks.cpp | 11 ++-- components/esm/loadpgrd.cpp | 6 +- components/esm/loadregn.cpp | 5 +- components/esm/loadscpt.cpp | 8 ++- components/esm/record.hpp | 8 +++ 13 files changed, 220 insertions(+), 67 deletions(-) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index ea9a388a5..97f1aa2a5 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -22,6 +22,8 @@ struct ESMData { std::string author; std::string description; + int version; + int type; ESMReader::MasterList masters; std::list records; @@ -221,7 +223,7 @@ int load(Arguments& info) try { - if(info.raw_given) + if(info.raw_given && info.mode == "dump") { cout << "RAW file listing:\n"; @@ -233,7 +235,7 @@ int load(Arguments& info) } bool quiet = (info.quiet_given || info.mode == "clone"); - bool loadCells = (info.loadcells_given || info.mode == "clone"); + bool loadCells = (info.loadcells_given);// || info.mode == "clone"); bool save = (info.mode == "clone"); esm.open(filename); @@ -241,15 +243,23 @@ int load(Arguments& info) info.data.author = esm.getAuthor(); info.data.description = esm.getDesc(); info.data.masters = esm.getMasters(); + info.data.version = esm.getVer(); + info.data.type = esm.getType(); - cout << "Author: " << esm.getAuthor() << endl; - cout << "Description: " << esm.getDesc() << endl; - cout << "File format version: " << esm.getFVer() << endl; - cout << "Special flag: " << esm.getSpecial() << endl; - cout << "Masters:\n"; - ESMReader::MasterList m = esm.getMasters(); - for(unsigned int i=0;isetId(id); + if (save) info.data.records.push_back(rec); else @@ -720,6 +733,7 @@ int load(Arguments& info) } #include +#include int clone(Arguments& info) { @@ -735,26 +749,82 @@ int clone(Arguments& info) return 1; } - cout << "Loaded " << info.data.records.size() << " records:" << endl; + int recordCount = info.data.records.size(); + + int digitCount = 1; // For a nicer output + if (recordCount > 9) ++digitCount; + if (recordCount > 99) ++digitCount; + if (recordCount > 999) ++digitCount; + if (recordCount > 9999) ++digitCount; + if (recordCount > 99999) ++digitCount; + if (recordCount > 999999) ++digitCount; + + cout << "Loaded " << recordCount << " records:" << endl << endl; std::map records; - for (std::list::iterator it = info.data.records.begin(); it != info.data.records.end();) + for (std::list::iterator it = info.data.records.begin(); it != info.data.records.end(); ++it) { Record* rec = *it; NAME n; n.val = rec->getName(); records[n.toString()]++; - - delete rec; - info.data.records.erase(it++); } + int i = 0; for (std::map::iterator it = records.begin(); it != records.end(); ++it) { std::string n = it->first; - cout << n << ": " << it->second << " records." << endl; + float amount = it->second; + cout << setw(digitCount) << amount << " " << n << " "; + + if (++i % 3 == 0) + cout << endl; } + + if (i % 3 != 0) + cout << endl; + + cout << endl << "Saving records to: " << info.outname << "..." << endl; + + ESMWriter esm; + esm.setAuthor(info.data.author); + esm.setDescription(info.data.description); + esm.setVersion(info.data.version); + esm.setType(info.data.type); + + for (ESMReader::MasterList::iterator it = info.data.masters.begin(); it != info.data.masters.end(); ++it) + esm.addMaster(it->name, it->size); + + std::fstream save(info.outname.c_str(), std::fstream::out | std::fstream::binary); + esm.save(save); + + int saved = 0; + for (std::list::iterator it = info.data.records.begin(); it != info.data.records.end() && i > 0; ++it) + { + Record* rec = *it; + + NAME n; + n.val = rec->getName(); + + esm.startRecord(n.toString(), 0); + std::string id = rec->getId(); + esm.writeHNOString("NAME", id); + rec->save(esm); + esm.endRecord(n.toString()); + + saved++; + int perc = ((int)saved / (float)recordCount)*100; + if (perc % 10 == 0) + { + cerr << "\r" << perc << "%"; + } + } + + cout << "\rDone!" << endl; + + esm.close(); + save.close(); return 0; } diff --git a/components/esm/esm_reader.hpp b/components/esm/esm_reader.hpp index 6e5592cf7..3e69aa528 100644 --- a/components/esm/esm_reader.hpp +++ b/components/esm/esm_reader.hpp @@ -61,6 +61,7 @@ public: int getVer() { return mCtx.header.version; } float getFVer() { if(mCtx.header.version == VER_12) return 1.2; else return 1.3; } int getSpecial() { return mSpf; } + int getType() { return mCtx.header.type; } const std::string getAuthor() { return mCtx.header.author.toString(); } const std::string getDesc() { return mCtx.header.desc.toString(); } const SaveData &getSaveData() { return mSaveData; } diff --git a/components/esm/esm_writer.cpp b/components/esm/esm_writer.cpp index 57517b0f5..14e28f6ba 100644 --- a/components/esm/esm_writer.cpp +++ b/components/esm/esm_writer.cpp @@ -2,15 +2,27 @@ #include #include +bool count = true; + namespace ESM { -void ESMWriter::setVersion(Version ver) +int ESMWriter::getVersion() +{ + return m_header.version; +} + +void ESMWriter::setVersion(int ver) { m_header.version = ver; } -void ESMWriter::setType(FileType type) +int ESMWriter::getType() +{ + return m_header.type; +} + +void ESMWriter::setType(int type) { m_header.type = type; } @@ -25,75 +37,118 @@ void ESMWriter::setDescription(const std::string& desc) strncpy((char*)&m_header.desc, desc.c_str(), 256); } +void ESMWriter::addMaster(const std::string& name, uint64_t size) +{ + MasterData d; + d.name = name; + d.size = size; + m_masters.push_back(d); +} + void ESMWriter::save(const std::string& file) { std::ofstream fs(file.c_str(), std::ios_base::out | std::ios_base::trunc); save(fs); - fs.close(); } void ESMWriter::save(std::ostream& file) { m_stream = &file; - startRecord("TES3"); - writeT(0); - writeT(0); + startRecord("TES3", 0); - endRecord(); + m_header.records = 0; + writeHNT("HEDR", m_header, 300); - // TODO: Saving + for (std::list::iterator it = m_masters.begin(); it != m_masters.end(); ++it) + { + writeHNString("MAST", it->name); + writeHNT("DATA", it->size); + } + + endRecord("TES3"); } void ESMWriter::close() { - // TODO: Saving + m_stream->flush(); + + if (!m_records.empty()) + throw "Unclosed record remaining"; } -void ESMWriter::startRecord(const std::string& name) +void ESMWriter::startRecord(const std::string& name, uint32_t flags) { writeName(name); RecordData rec; + rec.name = name; rec.position = m_stream->tellp(); rec.size = 0; + writeT(0); // Size goes here + writeT(0); // Unused header? + writeT(flags); m_records.push_back(rec); - writeT(0); + + assert(m_records.back().size == 0); } -void ESMWriter::endRecord() +void ESMWriter::startSubRecord(const std::string& name) +{ + writeName(name); + RecordData rec; + rec.name = name; + rec.position = m_stream->tellp(); + rec.size = 0; + writeT(0); // Size goes here + m_records.push_back(rec); + + assert(m_records.back().size == 0); +} + +void ESMWriter::endRecord(const std::string& name) { - std::streampos cur = m_stream->tellp(); RecordData rec = m_records.back(); + assert(rec.name == name); m_records.pop_back(); m_stream->seekp(rec.position); - m_stream->write((char*)&rec.size, sizeof(int)); - m_stream->seekp(cur); + count = false; + write((char*)&rec.size, sizeof(int)); + count = true; + + m_stream->seekp(0, std::ios::end); + } void ESMWriter::writeHNString(const std::string& name, const std::string& data) { - writeName(name); + startSubRecord(name); writeHString(data); + endRecord(name); } void ESMWriter::writeHString(const std::string& data) { - writeT(data.size()-1); - write(data.c_str(), data.size()-1); + if (data.size() == 0) + write("\0", 1); + else + write(data.c_str(), data.size()); } void ESMWriter::writeName(const std::string& name) { - assert((name.size() == 4 && name[3] != '\0') || (name.size() == 5 && name[4] == '\0')); - write(name.c_str(), name.size()-1); + assert((name.size() == 4 && name[3] != '\0')); + write(name.c_str(), name.size()); } void ESMWriter::write(const char* data, int size) { - if (!m_records.empty()) - m_records.back().size += size; + if (count && !m_records.empty()) + { + for (std::list::iterator it = m_records.begin(); it != m_records.end(); ++it) + it->size += size; + } m_stream->write(data, size); } diff --git a/components/esm/esm_writer.hpp b/components/esm/esm_writer.hpp index 3999e987d..4439693c4 100644 --- a/components/esm/esm_writer.hpp +++ b/components/esm/esm_writer.hpp @@ -2,7 +2,7 @@ #define _ESM_WRITER_H #include -#include +#include #include #include "esm_common.hpp" @@ -13,17 +13,22 @@ class ESMWriter { struct RecordData { + std::string name; std::streampos position; int size; }; public: - void setVersion(Version ver); - void setType(FileType type); - + int getVersion(); + void setVersion(int ver); + int getType(); + void setType(int type); +// void setEncoding(const std::string& encoding); // Write strings as UTF-8? void setAuthor(const std::string& author); void setDescription(const std::string& desc); + void addMaster(const std::string& name, uint64_t size); + void save(const std::string& file); void save(std::ostream& file); void close(); @@ -38,18 +43,20 @@ public: template void writeHNT(const std::string& name, const T& data) { - writeName(name); + startSubRecord(name); writeT(data); + endRecord(name); } template void writeHNT(const std::string& name, const T& data, int size) { - assert(sizeof(T) == size); - writeHNT(name, data); + startSubRecord(name); + writeT(data, size); + endRecord(name); } - template + /*template void writeHT(const T& data) { writeT((unsigned int)sizeof(T)); @@ -61,7 +68,7 @@ public: { assert(sizeof(T) == size); writeHT(data); - } + }*/ template void writeT(const T& data) @@ -72,18 +79,19 @@ public: template void writeT(const T& data, int size) { - assert(sizeof(T) == size); - writeT(data); + write((char*)&data, size); } - void startRecord(const std::string& name); - void endRecord(); + void startRecord(const std::string& name, uint32_t flags); + void startSubRecord(const std::string& name); + void endRecord(const std::string& name); void writeHString(const std::string& data); void writeName(const std::string& data); void write(const char* data, int size); private: - std::vector m_records; + std::list m_masters; + std::list m_records; std::ostream* m_stream; HEDRstruct m_header; diff --git a/components/esm/loadarmo.cpp b/components/esm/loadarmo.cpp index aecfc7e92..ca5865083 100644 --- a/components/esm/loadarmo.cpp +++ b/components/esm/loadarmo.cpp @@ -19,7 +19,7 @@ void PartReferenceList::save(ESMWriter &esm) { for (std::vector::iterator it = parts.begin(); it != parts.end(); ++it) { - esm.writeHT(it->part); + esm.writeHNT("INDX", it->part); esm.writeHNOString("BNAM", it->male); esm.writeHNOString("CNAM", it->female); } diff --git a/components/esm/loadfact.cpp b/components/esm/loadfact.cpp index fdbedcbd0..2a927ad28 100644 --- a/components/esm/loadfact.cpp +++ b/components/esm/loadfact.cpp @@ -31,7 +31,7 @@ void Faction::save(ESMWriter &esm) { esm.writeHNString("FNAM", name); - for (int i = 0; !ranks[i].empty(); i++) + for (int i = 0; i < 10; i++) { esm.writeHNString("RNAM", ranks[i]); } diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index 9aa02e478..222772041 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -84,15 +84,18 @@ void Land::load(ESMReader &esm) void Land::save(ESMWriter &esm) { - esm.writeName("INTV"); + esm.startSubRecord("INTV"); esm.writeT(X); esm.writeT(Y); + esm.endRecord("INTV"); esm.writeHNT("DATA", flags); + /* TODO: Land! if (hasData && !dataLoaded) loadData(); // I think it might be a good idea to have // the data loaded before trying to save it + */ if (dataLoaded) landData->save(esm); } diff --git a/components/esm/loadlevlist.cpp b/components/esm/loadlevlist.cpp index 811964775..f63a72025 100644 --- a/components/esm/loadlevlist.cpp +++ b/components/esm/loadlevlist.cpp @@ -38,7 +38,7 @@ void LeveledListBase::save(ESMWriter &esm) for (std::vector::iterator it = list.begin(); it != list.end(); ++it) { - esm.writeHNString("INAM", it->id); + esm.writeHNString(recName, it->id); esm.writeHNT("INTV", it->level); } } diff --git a/components/esm/loadlocks.cpp b/components/esm/loadlocks.cpp index f49de1bc8..b3d53f458 100644 --- a/components/esm/loadlocks.cpp +++ b/components/esm/loadlocks.cpp @@ -36,14 +36,15 @@ void Tool::save(ESMWriter &esm) esm.writeHNString("MODL", model); esm.writeHNString("FNAM", name); + std::string typeName; switch(type) { - case Type_Repair: esm.writeName("RIDT"); break; - case Type_Pick: esm.writeName("LKDT"); break; - case Type_Probe: esm.writeName("PBDT"); break; + case Type_Repair: typeName = "RIDT"; break; + case Type_Pick: typeName = "LKDT"; break; + case Type_Probe: typeName = "PBDT"; break; } - - esm.writeT(data, 16); + + esm.writeHNT(typeName, data, 16); esm.writeHNOString("SCRI", script); esm.writeHNOString("ITEX", icon); } diff --git a/components/esm/loadpgrd.cpp b/components/esm/loadpgrd.cpp index 41dd34174..ebdb6e837 100644 --- a/components/esm/loadpgrd.cpp +++ b/components/esm/loadpgrd.cpp @@ -74,20 +74,22 @@ void Pathgrid::save(ESMWriter &esm) if (!points.empty()) { - esm.writeName("PGRP"); + esm.startSubRecord("PGRP"); for (PointList::iterator it = points.begin(); it != points.end(); ++it) { esm.writeT(*it); } + esm.endRecord("PGRP"); } if (!edges.empty()) { - esm.writeName("PGRC"); + esm.startSubRecord("PGRC"); for (std::vector::iterator it = edges.begin(); it != edges.end(); ++it) { esm.writeT(it->v1); } + esm.endRecord("PGRC"); } } diff --git a/components/esm/loadregn.cpp b/components/esm/loadregn.cpp index d67922b4d..f9e4a151e 100644 --- a/components/esm/loadregn.cpp +++ b/components/esm/loadregn.cpp @@ -29,7 +29,10 @@ void Region::save(ESMWriter &esm) { esm.writeHNString("FNAM", name); - esm.writeHNT("WEAT", data); + if (esm.getVersion() == VER_12) + esm.writeHNT("WEAT", data, sizeof(data) - 2); + else + esm.writeHNT("WEAT", data); esm.writeHNOString("BNAM", sleepList); diff --git a/components/esm/loadscpt.cpp b/components/esm/loadscpt.cpp index 291259bc0..ecb58cc31 100644 --- a/components/esm/loadscpt.cpp +++ b/components/esm/loadscpt.cpp @@ -44,15 +44,17 @@ void Script::save(ESMWriter &esm) if (!varNames.empty()) { - esm.writeName("SCVR"); + esm.startSubRecord("SCVR"); for (std::vector::iterator it = varNames.begin(); it != varNames.end(); ++it) { esm.writeT(it->c_str(), it->size()); + esm.writeT('\0'); } + esm.endRecord("SCVR"); } - esm.writeHNT("SCDT", &scriptData[0], scriptData.size()); - esm.writeHNOString("SCDT", scriptText); + esm.writeHNString("SCDT", std::string(&scriptData[0], scriptData.size())); + esm.writeHNOString("SCTX", scriptText); } } diff --git a/components/esm/record.hpp b/components/esm/record.hpp index 666a6c15b..d273b175a 100644 --- a/components/esm/record.hpp +++ b/components/esm/record.hpp @@ -1,6 +1,8 @@ #ifndef _ESM_RECORD_H #define _ESM_RECORD_H +#include + namespace ESM { @@ -62,7 +64,13 @@ public: virtual void load(ESMReader& esm) = 0; virtual void save(ESMWriter& esm) = 0; + std::string getId() { return m_id; } + void setId(const std::string& in) { m_id = in; } + virtual int getName() = 0; + +protected: + std::string m_id; }; } From 23f81e63ddc64cc84424c7f0122ce3d5373edef5 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Sun, 8 Apr 2012 17:14:56 +0200 Subject: [PATCH 07/48] Nicer help text and error for not selecting a valid mode. --- apps/esmtool/esmtool.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index 97f1aa2a5..a8eeaee7f 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -46,7 +46,7 @@ struct Arguments bool parseOptions (int argc, char** argv, Arguments &info) { - bpo::options_description desc("Inspect and extract from Morrowind ES files (ESM, ESP, ESS)\nSyntax: esmtool [options] mode infile [outfile]\nAllowed options"); + bpo::options_description desc("Inspect and extract from Morrowind ES files (ESM, ESP, ESS)\nSyntax: esmtool [options] mode infile [outfile]\nAllowed modes:\n dump\t Dumps all readable data from the input file\n clone\t Clones the input file to the output file.\n\nAllowed options"); desc.add_options() ("help,h", "print help message.") @@ -103,6 +103,14 @@ bool parseOptions (int argc, char** argv, Arguments &info) return false; } + info.mode = variables["mode"].as(); + if (!(info.mode == "dump" || info.mode == "clone")) + { + std::cout << std::endl << "ERROR: invalid mode \"" << info.mode << "\"" << std::endl << std::endl + << desc << finalText << std::endl; + return false; + } + if ( !variables.count("input-file") ) { std::cout << "\nERROR: missing ES file\n\n"; @@ -118,8 +126,6 @@ bool parseOptions (int argc, char** argv, Arguments &info) return false; }*/ - info.mode = variables["mode"].as(); - info.filename = variables["input-file"].as< vector >()[0]; if (variables["input-file"].as< vector >().size() > 1) info.outname = variables["input-file"].as< vector >()[1]; @@ -814,7 +820,7 @@ int clone(Arguments& info) esm.endRecord(n.toString()); saved++; - int perc = ((int)saved / (float)recordCount)*100; + int perc = (saved / (float)recordCount)*100; if (perc % 10 == 0) { cerr << "\r" << perc << "%"; From 1d48781567f756608f82192020176d16ab9d0ffd Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Sun, 8 Apr 2012 17:52:55 +0200 Subject: [PATCH 08/48] Forgot about the cell refs, oops --- apps/esmtool/esmtool.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index a8eeaee7f..dd9ed648c 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -1,5 +1,6 @@ #include #include +#include #include @@ -15,9 +16,6 @@ using namespace ESM; // Create a local alias for brevity namespace bpo = boost::program_options; -void printRaw(ESMReader &esm); -void loadCell(Cell &cell, ESMReader &esm, bool quiet); - struct ESMData { std::string author; @@ -27,6 +25,7 @@ struct ESMData ESMReader::MasterList masters; std::list records; + std::map > cellRefs; }; // Based on the legacy struct @@ -157,6 +156,9 @@ bool parseOptions (int argc, char** argv, Arguments &info) return true; } +void printRaw(ESMReader &esm); +void loadCell(Cell &cell, ESMReader &esm, Arguments& info); + int load(Arguments& info); int clone(Arguments& info); @@ -179,8 +181,11 @@ int main(int argc, char**argv) return 0; } -void loadCell(Cell &cell, ESMReader &esm, bool quiet) +void loadCell(Cell &cell, ESMReader &esm, Arguments& info) { + bool quiet = (info.quiet_given || info.mode == "clone"); + bool save = (info.mode == "clone"); + // Skip back to the beginning of the reference list cell.restore(esm); @@ -189,6 +194,9 @@ void loadCell(Cell &cell, ESMReader &esm, bool quiet) if(!quiet) cout << " References:\n"; while(cell.getNextRef(esm, ref)) { + if (save) + info.data.cellRefs[&cell].push_back(ref); + if(quiet) continue; cout << " Refnum: " << ref.refnum << endl; @@ -241,7 +249,7 @@ int load(Arguments& info) } bool quiet = (info.quiet_given || info.mode == "clone"); - bool loadCells = (info.loadcells_given);// || info.mode == "clone"); + bool loadCells = (info.loadcells_given || info.mode == "clone"); bool save = (info.mode == "clone"); esm.open(filename); @@ -367,7 +375,7 @@ int load(Arguments& info) cout << " Region: " << b.region << endl; } if(loadCells) - loadCell(b, esm, quiet); + loadCell(b, esm, info); break; } case REC_CLAS: @@ -738,7 +746,6 @@ int load(Arguments& info) return 0; } -#include #include int clone(Arguments& info) @@ -817,6 +824,16 @@ int clone(Arguments& info) std::string id = rec->getId(); esm.writeHNOString("NAME", id); rec->save(esm); + + if (n.val == REC_CELL && !info.data.cellRefs[rec].empty()) + { + std::list& refs = info.data.cellRefs[rec]; + for (std::list::iterator it = refs.begin(); it != refs.end(); ++it) + { + it->save(esm); + } + } + esm.endRecord(n.toString()); saved++; From f0c32ba7d3baf5f4a3c4adb6bc791dc074c384f5 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Sun, 8 Apr 2012 18:01:54 +0200 Subject: [PATCH 09/48] Fixed saving cell ref data with wrong name --- components/esm/loadcell.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index f6db5c70c..920fa8ad9 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -16,7 +16,7 @@ void CellRef::save(ESMWriter &esm) esm.writeHNOString("ANAM", owner); esm.writeHNOString("BNAM", glob); - esm.writeHNOString("SXOL", soul); + esm.writeHNOString("XSOL", soul); esm.writeHNOString("CNAM", faction); if (factIndex != -1) From 290d09de64768fbc052bc15d92191d620e852d0a Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Sun, 8 Apr 2012 18:32:40 +0200 Subject: [PATCH 10/48] Switching creature and npc to using the same id storage as the rest of the records --- apps/esmtool/esmtool.cpp | 1 - apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/npc.cpp | 2 +- components/esm/loadcrea.cpp | 5 ----- components/esm/loadcrea.hpp | 3 --- components/esm/loadnpc.cpp | 5 ----- components/esm/loadnpc.hpp | 3 +-- components/esm/record.hpp | 2 +- components/esm_store/reclists.hpp | 2 +- 9 files changed, 5 insertions(+), 20 deletions(-) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index dd9ed648c..06348e949 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -410,7 +410,6 @@ int load(Arguments& info) { rec = new Creature(); Creature& b = *(Creature*)rec; - b.setID(id); b.load(esm); if(quiet) break; cout << " Name: " << b.name << endl; diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 7270fd22b..8a5b149ff 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -65,7 +65,7 @@ namespace MWClass ESMS::LiveCellRef *ref = ptr.get(); - return ref->base->mId; + return ref->base->getId(); } void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 83a94d27d..04ac31f98 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -88,7 +88,7 @@ namespace MWClass ESMS::LiveCellRef *ref = ptr.get(); - return ref->base->mId; + return ref->base->getId(); } void Npc::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index 7b84a7f29..259d37b4a 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -2,11 +2,6 @@ namespace ESM { -void Creature::setID(const std::string& id) -{ - mId = id; -} - void Creature::load(ESMReader &esm) { model = esm.getHNString("MODL"); diff --git a/components/esm/loadcrea.hpp b/components/esm/loadcrea.hpp index 3035003cf..348c14b23 100644 --- a/components/esm/loadcrea.hpp +++ b/components/esm/loadcrea.hpp @@ -63,9 +63,6 @@ struct Creature : public Record // Defined in loadcont.hpp InventoryList inventory; - std::string mId; - - void setID(const std::string& id); void load(ESMReader &esm); void save(ESMWriter &esm); diff --git a/components/esm/loadnpc.cpp b/components/esm/loadnpc.cpp index 34b5e69ed..b689ba5e8 100644 --- a/components/esm/loadnpc.cpp +++ b/components/esm/loadnpc.cpp @@ -3,11 +3,6 @@ namespace ESM { -void NPC::setID(const std::string& id) -{ - mId = id; -} - void NPC::load(ESMReader &esm) { npdt52.gold = -10; diff --git a/components/esm/loadnpc.hpp b/components/esm/loadnpc.hpp index 3f8a60304..13ee9ef6d 100644 --- a/components/esm/loadnpc.hpp +++ b/components/esm/loadnpc.hpp @@ -100,10 +100,9 @@ struct NPC : public Record std::string name, model, race, cls, faction, script, hair, head; // body parts - std::string mId; + //std::string mId; // Implementation moved to load_impl.cpp - void setID(const std::string& id); void load(ESMReader &esm); void save(ESMWriter &esm); diff --git a/components/esm/record.hpp b/components/esm/record.hpp index d273b175a..dfecab7b9 100644 --- a/components/esm/record.hpp +++ b/components/esm/record.hpp @@ -64,7 +64,7 @@ public: virtual void load(ESMReader& esm) = 0; virtual void save(ESMWriter& esm) = 0; - std::string getId() { return m_id; } + std::string getId() const { return m_id; } void setId(const std::string& in) { m_id = in; } virtual int getName() = 0; diff --git a/components/esm_store/reclists.hpp b/components/esm_store/reclists.hpp index bc3b676a2..22bb55b52 100644 --- a/components/esm_store/reclists.hpp +++ b/components/esm_store/reclists.hpp @@ -104,7 +104,7 @@ namespace ESMS void load(ESMReader &esm, const std::string &id) { std::string id2 = toLower (id); - list[id2].setID(id2); + list[id2].setId(id2); list[id2].load(esm); } From f16a9ce5ed26bfad1cfe55e480abeb56bd970113 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Thu, 12 Apr 2012 14:00:58 +0200 Subject: [PATCH 11/48] Working on making output identical to input. --- apps/esmtool/esmtool.cpp | 146 +++++++++++++++++++++++----------- components/esm/esm_writer.cpp | 23 ++++++ components/esm/esm_writer.hpp | 25 +++--- components/esm/loadclas.cpp | 2 +- components/esm/loadfact.cpp | 7 +- components/esm/loadrace.cpp | 2 +- components/esm/loadscpt.cpp | 15 ++-- 7 files changed, 150 insertions(+), 70 deletions(-) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index 06348e949..002758bed 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -19,13 +19,13 @@ namespace bpo = boost::program_options; struct ESMData { std::string author; - std::string description; + string description; int version; int type; ESMReader::MasterList masters; - std::list records; - std::map > cellRefs; + list records; + map > cellRefs; }; // Based on the legacy struct @@ -35,17 +35,17 @@ struct Arguments unsigned int quiet_given; unsigned int loadcells_given; - std::string mode; - std::string encoding; - std::string filename; - std::string outname; + string mode; + string encoding; + string filename; + string outname; ESMData data; }; bool parseOptions (int argc, char** argv, Arguments &info) { - bpo::options_description desc("Inspect and extract from Morrowind ES files (ESM, ESP, ESS)\nSyntax: esmtool [options] mode infile [outfile]\nAllowed modes:\n dump\t Dumps all readable data from the input file\n clone\t Clones the input file to the output file.\n\nAllowed options"); + bpo::options_description desc("Inspect and extract from Morrowind ES files (ESM, ESP, ESS)\nSyntax: esmtool [options] mode infile [outfile]\nAllowed modes:\n dump\t Dumps all readable data from the input file.\n clone\t Clones the input file to the output file.\n comp\t Compares the given files.\n\nAllowed options"); desc.add_options() ("help,h", "print help message.") @@ -54,7 +54,7 @@ bool parseOptions (int argc, char** argv, Arguments &info) ("quiet,q", "Supress all record information. Useful for speed tests.") ("loadcells,C", "Browse through contents of all cells.") - ( "encoding,e", bpo::value(&(info.encoding))-> + ( "encoding,e", bpo::value(&(info.encoding))-> default_value("win1252"), "Character encoding used in ESMTool:\n" "\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages\n" @@ -62,14 +62,14 @@ bool parseOptions (int argc, char** argv, Arguments &info) "\n\twin1252 - Western European (Latin) alphabet, used by default") ; - std::string finalText = "\nIf no option is given, the default action is to parse all records in the archive\nand display diagnostic information."; + string finalText = "\nIf no option is given, the default action is to parse all records in the archive\nand display diagnostic information."; // input-file is hidden and used as a positional argument bpo::options_description hidden("Hidden Options"); hidden.add_options() - ( "mode,m", bpo::value(), "esmtool mode") - ( "input-file,i", bpo::value< vector >(), "input file") + ( "mode,m", bpo::value(), "esmtool mode") + ( "input-file,i", bpo::value< vector >(), "input file") ; bpo::positional_options_description p; @@ -87,70 +87,70 @@ bool parseOptions (int argc, char** argv, Arguments &info) if (variables.count ("help")) { - std::cout << desc << finalText << std::endl; + cout << desc << finalText << endl; return false; } if (variables.count ("version")) { - std::cout << "ESMTool version " << ESMTOOL_VERSION << std::endl; + cout << "ESMTool version " << ESMTOOL_VERSION << endl; return false; } if (!variables.count("mode")) { - std::cout << "No mode specified!" << std::endl << std::endl - << desc << finalText << std::endl; + cout << "No mode specified!" << endl << endl + << desc << finalText << endl; return false; } - info.mode = variables["mode"].as(); - if (!(info.mode == "dump" || info.mode == "clone")) + info.mode = variables["mode"].as(); + if (!(info.mode == "dump" || info.mode == "clone" || info.mode == "comp")) { - std::cout << std::endl << "ERROR: invalid mode \"" << info.mode << "\"" << std::endl << std::endl - << desc << finalText << std::endl; + cout << endl << "ERROR: invalid mode \"" << info.mode << "\"" << endl << endl + << desc << finalText << endl; return false; } if ( !variables.count("input-file") ) { - std::cout << "\nERROR: missing ES file\n\n"; - std::cout << desc << finalText << std::endl; + cout << "\nERROR: missing ES file\n\n"; + cout << desc << finalText << endl; return false; } // handling gracefully the user adding multiple files -/* if (variables["input-file"].as< vector >().size() > 1) +/* if (variables["input-file"].as< vector >().size() > 1) { - std::cout << "\nERROR: more than one ES file specified\n\n"; - std::cout << desc << finalText << std::endl; + cout << "\nERROR: more than one ES file specified\n\n"; + cout << desc << finalText << endl; return false; }*/ - info.filename = variables["input-file"].as< vector >()[0]; - if (variables["input-file"].as< vector >().size() > 1) - info.outname = variables["input-file"].as< vector >()[1]; + info.filename = variables["input-file"].as< vector >()[0]; + if (variables["input-file"].as< vector >().size() > 1) + info.outname = variables["input-file"].as< vector >()[1]; info.raw_given = variables.count ("raw"); info.quiet_given = variables.count ("quiet"); info.loadcells_given = variables.count ("loadcells"); // Font encoding settings - info.encoding = variables["encoding"].as(); + info.encoding = variables["encoding"].as(); if (info.encoding == "win1250") { - std::cout << "Using Central and Eastern European font encoding." << std::endl; + cout << "Using Central and Eastern European font encoding." << endl; } else if (info.encoding == "win1251") { - std::cout << "Using Cyrillic font encoding." << std::endl; + cout << "Using Cyrillic font encoding." << endl; } else { if(info.encoding != "win1252") { - std::cout << info.encoding << " is not a valid encoding option." << std::endl; + cout << info.encoding << " is not a valid encoding option." << endl; info.encoding = "win1252"; } - std::cout << "Using default (English) font encoding." << std::endl; + cout << "Using default (English) font encoding." << endl; } return true; @@ -161,6 +161,7 @@ void loadCell(Cell &cell, ESMReader &esm, Arguments& info); int load(Arguments& info); int clone(Arguments& info); +int comp(Arguments& info); int main(int argc, char**argv) { @@ -172,6 +173,8 @@ int main(int argc, char**argv) return load(info); else if (info.mode == "clone") return clone(info); + else if (info.mode == "comp") + return comp(info); else { cout << "Invalid or no mode specified, dying horribly. Have a nice day." << endl; @@ -231,9 +234,9 @@ int load(Arguments& info) esm.setEncoding(info.encoding); string filename = info.filename; - cout << "\nFile: " << filename << endl; + cout << "Loading file: " << filename << endl; - std::list skipped; + list skipped; try { @@ -734,7 +737,7 @@ int load(Arguments& info) { cout << "\nERROR:\n\n " << e.what() << endl; - for (std::list::iterator it = info.data.records.begin(); it != info.data.records.end();) + for (list::iterator it = info.data.records.begin(); it != info.data.records.end();) { delete *it; info.data.records.erase(it++); @@ -773,9 +776,9 @@ int clone(Arguments& info) cout << "Loaded " << recordCount << " records:" << endl << endl; - std::map records; + map records; - for (std::list::iterator it = info.data.records.begin(); it != info.data.records.end(); ++it) + for (list::iterator it = info.data.records.begin(); it != info.data.records.end(); ++it) { Record* rec = *it; NAME n; @@ -784,9 +787,9 @@ int clone(Arguments& info) } int i = 0; - for (std::map::iterator it = records.begin(); it != records.end(); ++it) + for (map::iterator it = records.begin(); it != records.end(); ++it) { - std::string n = it->first; + string n = it->first; float amount = it->second; cout << setw(digitCount) << amount << " " << n << " "; @@ -808,11 +811,11 @@ int clone(Arguments& info) for (ESMReader::MasterList::iterator it = info.data.masters.begin(); it != info.data.masters.end(); ++it) esm.addMaster(it->name, it->size); - std::fstream save(info.outname.c_str(), std::fstream::out | std::fstream::binary); + fstream save(info.outname.c_str(), fstream::out | fstream::binary); esm.save(save); int saved = 0; - for (std::list::iterator it = info.data.records.begin(); it != info.data.records.end() && i > 0; ++it) + for (list::iterator it = info.data.records.begin(); it != info.data.records.end() && i > 0; ++it) { Record* rec = *it; @@ -820,14 +823,18 @@ int clone(Arguments& info) n.val = rec->getName(); esm.startRecord(n.toString(), 0); - std::string id = rec->getId(); - esm.writeHNOString("NAME", id); + string id = rec->getId(); + + if (n.val == REC_GLOB || n.val == REC_CLAS || n.val == REC_FACT || n.val == REC_RACE) + esm.writeHNCString("NAME", id); + else + esm.writeHNOString("NAME", id); rec->save(esm); if (n.val == REC_CELL && !info.data.cellRefs[rec].empty()) { - std::list& refs = info.data.cellRefs[rec]; - for (std::list::iterator it = refs.begin(); it != refs.end(); ++it) + list& refs = info.data.cellRefs[rec]; + for (list::iterator it = refs.begin(); it != refs.end(); ++it) { it->save(esm); } @@ -848,5 +855,52 @@ int clone(Arguments& info) esm.close(); save.close(); + return 0; +} + +int comp(Arguments& info) +{ + if (info.filename.empty() || info.outname.empty()) + { + cout << "You need to specify two input files" << endl; + return 1; + } + + Arguments fileOne; + Arguments fileTwo; + + fileOne.raw_given = 0; + fileTwo.raw_given = 0; + + fileOne.mode = "clone"; + fileTwo.mode = "clone"; + + fileOne.encoding = info.encoding; + fileTwo.encoding = info.encoding; + + fileOne.filename = info.filename; + fileTwo.filename = info.outname; + + if (load(fileOne) != 0) + { + cout << "Failed to load " << info.filename << ", aborting comparison." << endl; + return 1; + } + + if (load(fileTwo) != 0) + { + cout << "Failed to load " << info.outname << ", aborting comparison." << endl; + return 1; + } + + if (fileOne.data.records.size() != fileTwo.data.records.size()) + { + cout << "Not equal, different amount of records." << endl; + return 1; + } + + + + return 0; } diff --git a/components/esm/esm_writer.cpp b/components/esm/esm_writer.cpp index 14e28f6ba..4e0a6f460 100644 --- a/components/esm/esm_writer.cpp +++ b/components/esm/esm_writer.cpp @@ -53,12 +53,14 @@ void ESMWriter::save(const std::string& file) void ESMWriter::save(std::ostream& file) { + m_recordCount = 0; m_stream = &file; startRecord("TES3", 0); m_header.records = 0; writeHNT("HEDR", m_header, 300); + m_headerPos = m_stream->tellp() - (std::streampos)4; for (std::list::iterator it = m_masters.begin(); it != m_masters.end(); ++it) { @@ -71,6 +73,10 @@ void ESMWriter::save(std::ostream& file) void ESMWriter::close() { + std::cout << "Writing amount of saved records (" << m_recordCount - 1 << ")" << std::endl; + m_stream->seekp(m_headerPos); + writeT(m_recordCount-1); + m_stream->seekp(0, std::ios::end); m_stream->flush(); if (!m_records.empty()) @@ -79,6 +85,8 @@ void ESMWriter::close() void ESMWriter::startRecord(const std::string& name, uint32_t flags) { + m_recordCount++; + writeName(name); RecordData rec; rec.name = name; @@ -128,6 +136,21 @@ void ESMWriter::writeHNString(const std::string& name, const std::string& data) endRecord(name); } + void ESMWriter::writeHNString(const std::string& name, const std::string& data, int size) +{ + assert(data.size() <= size); + startSubRecord(name); + writeHString(data); + + if (data.size() < size) + { + for (int i = data.size(); i < size; ++i) + write("\0",1); + } + + endRecord(name); +} + void ESMWriter::writeHString(const std::string& data) { if (data.size() == 0) diff --git a/components/esm/esm_writer.hpp b/components/esm/esm_writer.hpp index 4439693c4..337af9e5e 100644 --- a/components/esm/esm_writer.hpp +++ b/components/esm/esm_writer.hpp @@ -34,6 +34,15 @@ public: void close(); void writeHNString(const std::string& name, const std::string& data); + void writeHNString(const std::string& name, const std::string& data, int size); + void writeHNCString(const std::string& name, const std::string& data) + { + startSubRecord(name); + writeHString(data); + if (data.size() > 0 && data[data.size()-1] != '\0') + write("\0", 1); + endRecord(name); + } void writeHNOString(const std::string& name, const std::string& data) { if (!data.empty()) @@ -56,20 +65,6 @@ public: endRecord(name); } - /*template - void writeHT(const T& data) - { - writeT((unsigned int)sizeof(T)); - writeT(data); - } - - template - void writeHT(const T& data, int size) - { - assert(sizeof(T) == size); - writeHT(data); - }*/ - template void writeT(const T& data) { @@ -93,6 +88,8 @@ private: std::list m_masters; std::list m_records; std::ostream* m_stream; + std::streampos m_headerPos; + int m_recordCount; HEDRstruct m_header; SaveData m_saveData; diff --git a/components/esm/loadclas.cpp b/components/esm/loadclas.cpp index e13442dcf..6e6de4e71 100644 --- a/components/esm/loadclas.cpp +++ b/components/esm/loadclas.cpp @@ -27,7 +27,7 @@ void Class::load(ESMReader &esm) } void Class::save(ESMWriter &esm) { - esm.writeHNString("FNAM", name); + esm.writeHNCString("FNAM", name); esm.writeHNT("CLDT", data, 60); esm.writeHNOString("DESC", description); } diff --git a/components/esm/loadfact.cpp b/components/esm/loadfact.cpp index 2a927ad28..1a151cbe1 100644 --- a/components/esm/loadfact.cpp +++ b/components/esm/loadfact.cpp @@ -29,11 +29,14 @@ void Faction::load(ESMReader &esm) } void Faction::save(ESMWriter &esm) { - esm.writeHNString("FNAM", name); + esm.writeHNCString("FNAM", name); for (int i = 0; i < 10; i++) { - esm.writeHNString("RNAM", ranks[i]); + if (ranks[i].empty()) + break; + + esm.writeHNString("RNAM", ranks[i], 32); } esm.writeHNT("FADT", data, 240); diff --git a/components/esm/loadrace.cpp b/components/esm/loadrace.cpp index 04752add1..8c82bd38a 100644 --- a/components/esm/loadrace.cpp +++ b/components/esm/loadrace.cpp @@ -12,7 +12,7 @@ void Race::load(ESMReader &esm) } void Race::save(ESMWriter &esm) { - esm.writeHNString("FNAM", name); + esm.writeHNCString("FNAM", name); esm.writeHNT("RADT", data, 140); powers.save(esm); esm.writeHNOString("DESC", description); diff --git a/components/esm/loadscpt.cpp b/components/esm/loadscpt.cpp index ecb58cc31..658f97a49 100644 --- a/components/esm/loadscpt.cpp +++ b/components/esm/loadscpt.cpp @@ -40,19 +40,22 @@ void Script::load(ESMReader &esm) } void Script::save(ESMWriter &esm) { - esm.writeHNT("SCHD", data, 52); - + std::string varNameString; if (!varNames.empty()) { - esm.startSubRecord("SCVR"); for (std::vector::iterator it = varNames.begin(); it != varNames.end(); ++it) { - esm.writeT(it->c_str(), it->size()); - esm.writeT('\0'); + varNameString.append(*it); + //varNameString.append("\0"); } - esm.endRecord("SCVR"); + + data.stringTableSize = varNameString.size(); } + esm.writeHNT("SCHD", data, 52); + + esm.writeHNOString("SCVR", varNameString); + esm.writeHNString("SCDT", std::string(&scriptData[0], scriptData.size())); esm.writeHNOString("SCTX", scriptText); } From a74aeace73ddd41ca80a2506f2944f46beefba2c Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Sat, 14 Apr 2012 00:14:04 +0200 Subject: [PATCH 12/48] Can now save strings with proper encoding, byte-perfect clones up until land records --- apps/esmtool/esmtool.cpp | 20 ++- components/esm/defs.hpp | 216 ++++++++++++++++++++++++++++++++- components/esm/esm_writer.cpp | 37 +++++- components/esm/esm_writer.hpp | 14 ++- components/esm/loadacti.cpp | 6 +- components/esm/loadalch.cpp | 8 +- components/esm/loadappa.cpp | 8 +- components/esm/loadarmo.cpp | 10 +- components/esm/loadbody.cpp | 4 +- components/esm/loadbook.cpp | 10 +- components/esm/loadbsgn.cpp | 6 +- components/esm/loadcell.cpp | 2 +- components/esm/loadclot.cpp | 10 +- components/esm/loadcont.cpp | 6 +- components/esm/loadcrea.cpp | 13 +- components/esm/loadcrea.hpp | 3 + components/esm/loaddoor.cpp | 10 +- components/esm/loadingr.cpp | 8 +- components/esm/loadlevlist.cpp | 2 +- components/esm/loadligh.cpp | 10 +- components/esm/loadlocks.cpp | 16 ++- components/esm/loadltex.cpp | 2 +- components/esm/loadmgef.cpp | 20 +-- components/esm/loadmisc.cpp | 8 +- components/esm/loadnpc.cpp | 29 ++--- components/esm/loadnpc.hpp | 15 +-- components/esm/loadregn.cpp | 4 +- components/esm/loadscpt.cpp | 22 ++-- components/esm/loadsoun.cpp | 2 +- components/esm/loadspel.cpp | 2 +- components/esm/loadstat.cpp | 2 +- components/esm/loadweap.cpp | 10 +- components/esm/record.hpp | 4 + components/to_utf8/to_utf8.cpp | 164 +++++++++++++++++++++++++ components/to_utf8/to_utf8.hpp | 1 + 35 files changed, 570 insertions(+), 134 deletions(-) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index 002758bed..2eab0bc1a 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -282,7 +282,9 @@ int load(Arguments& info) while(esm.hasMoreRecs()) { NAME n = esm.getRecName(); - esm.getRecHeader(); + uint32_t flags; + esm.getRecHeader(flags); + string id = esm.getHNOString("NAME"); if(!quiet) cout << "\nRecord: " << n.toString() @@ -726,6 +728,8 @@ int load(Arguments& info) { rec->setId(id); + rec->setFlags((int)flags); + if (save) info.data.records.push_back(rec); else @@ -803,6 +807,7 @@ int clone(Arguments& info) cout << endl << "Saving records to: " << info.outname << "..." << endl; ESMWriter esm; + esm.setEncoding(info.encoding); esm.setAuthor(info.data.author); esm.setDescription(info.data.description); esm.setVersion(info.data.version); @@ -822,13 +827,22 @@ int clone(Arguments& info) NAME n; n.val = rec->getName(); - esm.startRecord(n.toString(), 0); + esm.startRecord(n.toString(), rec->getFlags()); string id = rec->getId(); - if (n.val == REC_GLOB || n.val == REC_CLAS || n.val == REC_FACT || n.val == REC_RACE) + if (n.val == REC_GLOB || n.val == REC_CLAS || n.val == REC_FACT || n.val == REC_RACE || n.val == REC_SOUN + || n.val == REC_REGN || n.val == REC_BSGN || n.val == REC_LTEX || n.val == REC_STAT || n.val == REC_DOOR + || n.val == REC_MISC || n.val == REC_WEAP || n.val == REC_CONT || n.val == REC_SPEL || n.val == REC_CREA + || n.val == REC_BODY || n.val == REC_LIGH || n.val == REC_ENCH || n.val == REC_NPC_ || n.val == REC_ARMO + || n.val == REC_CLOT || n.val == REC_REPA || n.val == REC_ACTI || n.val == REC_APPA || n.val == REC_LOCK + || n.val == REC_PROB || n.val == REC_INGR || n.val == REC_BOOK || n.val == REC_ALCH || n.val == REC_LEVI + || n.val == REC_LEVC) esm.writeHNCString("NAME", id); + else if (n.val == REC_CELL) + esm.writeHNString("NAME", id); else esm.writeHNOString("NAME", id); + rec->save(esm); if (n.val == REC_CELL && !info.data.cellRefs[rec].empty()) diff --git a/components/esm/defs.hpp b/components/esm/defs.hpp index a33247906..caf81aad1 100644 --- a/components/esm/defs.hpp +++ b/components/esm/defs.hpp @@ -51,7 +51,7 @@ struct SpellList void save(ESMWriter &esm) { for (std::vector::iterator it = list.begin(); it != list.end(); ++it) - esm.writeHNString("NPCS", *it); + esm.writeHNString("NPCS", *it, 32); } }; @@ -83,6 +83,139 @@ struct ENAMstruct // Struct size should be 24 bytes }; + +struct AIDTstruct +{ + // These are probabilities + char hello, u1, fight, flee, alarm, u2, u3, u4; + // The last u's might be the skills that this NPC can train you + // in? + int services; // See the Services enum +}; // 12 bytes + +struct DODTstruct +{ + float pos[3]; + float rot[3]; +}; + +struct AI_Package +{ + void load(ESMReader& esm) + { + getData(esm); + cndt = esm.getHNOString("CNDT"); + } + + void save(ESMWriter& esm) + { + esm.startSubRecord(getName()); + saveData(esm); + esm.endRecord(getName()); + + esm.writeHNOCString("CNDT", cndt); + } + + std::string cndt; + + virtual void getData(ESMReader&) = 0; + virtual void saveData(ESMWriter&) = 0; + + virtual std::string getName() const = 0; + virtual int size() const = 0; +}; + +struct AI_Wstruct : AI_Package +{ + struct Data + { + short distance, duration; + char timeofday; + char idle[8]; + char unknown; + }; + + Data data; + + void getData(ESMReader& esm) { esm.getHExact(&data, sizeof(data)); } + void saveData(ESMWriter& esm) { esm.writeT(data); } + + std::string getName() const { return "AI_W"; } + int size() const { return sizeof(AI_Wstruct); } +}; + +struct AI_Tstruct : AI_Package +{ + struct Data + { + float pos[3]; + int unknown; + }; + + Data data; + + void getData(ESMReader& esm) { esm.getHExact(&data, sizeof(data)); } + void saveData(ESMWriter& esm) { esm.writeT(data); } + + std::string getName() const { return "AI_T"; } + int size() const { return sizeof(AI_Tstruct); } +}; + +struct AI_Fstruct : AI_Package +{ + struct Data + { + float pos[3]; + short duration; + NAME32 id; + short unknown; + }; + + Data data; + + void getData(ESMReader& esm) { esm.getHExact(&data, sizeof(data)); } + void saveData(ESMWriter& esm) { esm.writeT(data); } + + std::string getName() const { return "AI_F"; } + int size() const { return sizeof(AI_Fstruct); } +}; + +struct AI_Estruct : AI_Package +{ + struct Data + { + float pos[3]; + short duration; + NAME32 id; + short unknown; + }; + + Data data; + + void getData(ESMReader& esm) { esm.getHExact(&data, sizeof(data)); } + void saveData(ESMWriter& esm) { esm.writeT(data); } + + std::string getName() const { return "AI_E"; } + int size() const { return sizeof(AI_Estruct); } +}; + +struct AI_Astruct : AI_Package +{ + struct Data + { + NAME32 name; + char unknown; + }; + + Data data; + + void getData(ESMReader& esm) { esm.getHExact(&data, sizeof(data)); } + void saveData(ESMWriter& esm) { esm.writeT(data); } + + std::string getName() const { return "AI_A"; } + int size() const { return sizeof(AI_Astruct); } +}; + #pragma pack(pop) struct EffectList @@ -107,5 +240,86 @@ struct EffectList } }; +struct AIData +{ + struct Travelstruct + { + DODTstruct dodt; + std::string dnam; + }; + + AIDTstruct aidt; + bool hasAI; + std::vector packages; + std::vector travel; + + void load(ESMReader &esm) + { + if (esm.isNextSub("AIDT")) + { + esm.getHExact(&aidt, sizeof(aidt)); + hasAI = true; + } + else + hasAI = false; + +#define LOAD_IF_FOUND(x) \ + if (esm.isNextSub(#x)) \ + { \ + found = true; \ + x##struct *t = new x##struct(); \ + t->load(esm); \ + packages.push_back(t); \ + } + + bool found = true; + while (esm.hasMoreSubs() && found) + { + found = false; + + if (esm.isNextSub("DODT")) + { + found = true; + Travelstruct t; + esm.getHExact(&t.dodt, sizeof(t.dodt)); + t.dnam = esm.getHNOString("DNAM"); + travel.push_back(t); + } + + LOAD_IF_FOUND(AI_W); + LOAD_IF_FOUND(AI_T); + LOAD_IF_FOUND(AI_F); + LOAD_IF_FOUND(AI_E); + LOAD_IF_FOUND(AI_A); + } + } + + void save(ESMWriter &esm) + { + if (hasAI) + esm.writeHNT("AIDT", aidt); + + for (std::vector::iterator it = travel.begin(); it != travel.end(); ++it) + { + esm.writeHNT("DODT", it->dodt); + esm.writeHNOCString("DNAM", it->dnam); + } + + for (std::vector::iterator it = packages.begin(); it != packages.end(); ++it) + { + (*it)->save(esm); + } + } + + ~AIData() + { + for (std::vector::iterator it = packages.begin(); it != packages.end();) + { + delete *it; + packages.erase(it++); + } + } +}; + } #endif diff --git a/components/esm/esm_writer.cpp b/components/esm/esm_writer.cpp index 4e0a6f460..ef8a9c1b8 100644 --- a/components/esm/esm_writer.cpp +++ b/components/esm/esm_writer.cpp @@ -136,7 +136,7 @@ void ESMWriter::writeHNString(const std::string& name, const std::string& data) endRecord(name); } - void ESMWriter::writeHNString(const std::string& name, const std::string& data, int size) +void ESMWriter::writeHNString(const std::string& name, const std::string& data, int size) { assert(data.size() <= size); startSubRecord(name); @@ -156,7 +156,23 @@ void ESMWriter::writeHString(const std::string& data) if (data.size() == 0) write("\0", 1); else - write(data.c_str(), data.size()); + { + char *ptr = ToUTF8::getBuffer(data.size()+1); + strncpy(ptr, &data[0], data.size()); + ptr[data.size()] = '\0'; + + // Convert to UTF8 and return + std::string ascii = ToUTF8::getASCII(m_encoding); + + write(ascii.c_str(), ascii.size()); + } +} + +void ESMWriter::writeHCString(const std::string& data) +{ + writeHString(data); + if (data.size() > 0 && data[data.size()-1] != '\0') + write("\0", 1); } void ESMWriter::writeName(const std::string& name) @@ -176,4 +192,21 @@ void ESMWriter::write(const char* data, int size) m_stream->write(data, size); } +void ESMWriter::setEncoding(const std::string& encoding) +{ + if (encoding == "win1250") + { + m_encoding = ToUTF8::WINDOWS_1250; + } + else if (encoding == "win1251") + { + m_encoding = ToUTF8::WINDOWS_1251; + } + else + { + // Default Latin encoding + m_encoding = ToUTF8::WINDOWS_1252; + } +} + } diff --git a/components/esm/esm_writer.hpp b/components/esm/esm_writer.hpp index 337af9e5e..6eb34a97c 100644 --- a/components/esm/esm_writer.hpp +++ b/components/esm/esm_writer.hpp @@ -6,6 +6,7 @@ #include #include "esm_common.hpp" +#include "../to_utf8/to_utf8.hpp" namespace ESM { @@ -23,7 +24,7 @@ public: void setVersion(int ver); int getType(); void setType(int type); -// void setEncoding(const std::string& encoding); // Write strings as UTF-8? + void setEncoding(const std::string& encoding); // Write strings as UTF-8? void setAuthor(const std::string& author); void setDescription(const std::string& desc); @@ -38,9 +39,7 @@ public: void writeHNCString(const std::string& name, const std::string& data) { startSubRecord(name); - writeHString(data); - if (data.size() > 0 && data[data.size()-1] != '\0') - write("\0", 1); + writeHCString(data); endRecord(name); } void writeHNOString(const std::string& name, const std::string& data) @@ -48,6 +47,11 @@ public: if (!data.empty()) writeHNString(name, data); } + void writeHNOCString(const std::string& name, const std::string& data) + { + if (!data.empty()) + writeHNCString(name, data); + } template void writeHNT(const std::string& name, const T& data) @@ -81,6 +85,7 @@ public: void startSubRecord(const std::string& name); void endRecord(const std::string& name); void writeHString(const std::string& data); + void writeHCString(const std::string& data); void writeName(const std::string& data); void write(const char* data, int size); @@ -89,6 +94,7 @@ private: std::list m_records; std::ostream* m_stream; std::streampos m_headerPos; + ToUTF8::FromType m_encoding; int m_recordCount; HEDRstruct m_header; diff --git a/components/esm/loadacti.cpp b/components/esm/loadacti.cpp index b62a46158..9b08ad266 100644 --- a/components/esm/loadacti.cpp +++ b/components/esm/loadacti.cpp @@ -10,8 +10,8 @@ void Activator::load(ESMReader &esm) } void Activator::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); - esm.writeHNString("FNAM", name); - esm.writeHNOString("SCRI", script); + esm.writeHNCString("MODL", model); + esm.writeHNCString("FNAM", name); + esm.writeHNOCString("SCRI", script); } } diff --git a/components/esm/loadalch.cpp b/components/esm/loadalch.cpp index e5d3d8e27..969fb0aae 100644 --- a/components/esm/loadalch.cpp +++ b/components/esm/loadalch.cpp @@ -13,10 +13,10 @@ void Potion::load(ESMReader &esm) } void Potion::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); - esm.writeHNOString("TEXT", icon); - esm.writeHNOString("SCRI", script); - esm.writeHNOString("FNAM", name); + esm.writeHNCString("MODL", model); + esm.writeHNOCString("TEXT", icon); + esm.writeHNOCString("SCRI", script); + esm.writeHNOCString("FNAM", name); esm.writeHNT("ALDT", data, 12); effects.save(esm); } diff --git a/components/esm/loadappa.cpp b/components/esm/loadappa.cpp index 6eb164ec2..55dc8dc88 100644 --- a/components/esm/loadappa.cpp +++ b/components/esm/loadappa.cpp @@ -12,10 +12,10 @@ void Apparatus::load(ESMReader &esm) } void Apparatus::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); - esm.writeHNString("FNAM", name); + esm.writeHNCString("MODL", model); + esm.writeHNCString("FNAM", name); esm.writeHNT("AADT", data, 16); - esm.writeHNOString("SCRI", script); - esm.writeHNString("ITEX", icon); + esm.writeHNOCString("SCRI", script); + esm.writeHNCString("ITEX", icon); } } diff --git a/components/esm/loadarmo.cpp b/components/esm/loadarmo.cpp index ca5865083..c79e1fed2 100644 --- a/components/esm/loadarmo.cpp +++ b/components/esm/loadarmo.cpp @@ -38,13 +38,13 @@ void Armor::load(ESMReader &esm) void Armor::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); - esm.writeHNString("FNAM", name); - esm.writeHNOString("SCRI", script); + esm.writeHNCString("MODL", model); + esm.writeHNCString("FNAM", name); + esm.writeHNOCString("SCRI", script); esm.writeHNT("AODT", data, 24); - esm.writeHNOString("ITEX", icon); + esm.writeHNOCString("ITEX", icon); parts.save(esm); - esm.writeHNOString("ENAM", enchant); + esm.writeHNOCString("ENAM", enchant); } } diff --git a/components/esm/loadbody.cpp b/components/esm/loadbody.cpp index 72d56eac3..376320fb5 100644 --- a/components/esm/loadbody.cpp +++ b/components/esm/loadbody.cpp @@ -11,8 +11,8 @@ void BodyPart::load(ESMReader &esm) } void BodyPart::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); - esm.writeHNString("FNAM", name); + esm.writeHNCString("MODL", model); + esm.writeHNCString("FNAM", name); esm.writeHNT("BYDT", data, 4); } diff --git a/components/esm/loadbook.cpp b/components/esm/loadbook.cpp index ed21d71e1..9dba83808 100644 --- a/components/esm/loadbook.cpp +++ b/components/esm/loadbook.cpp @@ -15,13 +15,13 @@ void Book::load(ESMReader &esm) } void Book::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); - esm.writeHNOString("FNAM", name); + esm.writeHNCString("MODL", model); + esm.writeHNOCString("FNAM", name); esm.writeHNT("BKDT", data, 20); - esm.writeHNOString("SCRI", script); - esm.writeHNOString("ITEX", icon); + esm.writeHNOCString("SCRI", script); + esm.writeHNOCString("ITEX", icon); esm.writeHNOString("TEXT", text); - esm.writeHNOString("ENAM", enchant); + esm.writeHNOCString("ENAM", enchant); } } diff --git a/components/esm/loadbsgn.cpp b/components/esm/loadbsgn.cpp index de76e1949..3b7bae9f7 100644 --- a/components/esm/loadbsgn.cpp +++ b/components/esm/loadbsgn.cpp @@ -13,9 +13,9 @@ void BirthSign::load(ESMReader &esm) } void BirthSign::save(ESMWriter &esm) { - esm.writeHNString("FNAM", name); - esm.writeHNOString("TNAM", texture); - esm.writeHNOString("DESC", description); + esm.writeHNCString("FNAM", name); + esm.writeHNOCString("TNAM", texture); + esm.writeHNOCString("DESC", description); powers.save(esm); } diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 920fa8ad9..57d951658 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -108,7 +108,7 @@ void Cell::save(ESMWriter &esm) } else { - esm.writeHNOString("RGNN", region); + esm.writeHNOCString("RGNN", region); if (mapColor != 0) esm.writeHNT("NAM5", mapColor); } diff --git a/components/esm/loadclot.cpp b/components/esm/loadclot.cpp index cd884d206..37a445c19 100644 --- a/components/esm/loadclot.cpp +++ b/components/esm/loadclot.cpp @@ -18,16 +18,16 @@ void Clothing::load(ESMReader &esm) } void Clothing::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); - esm.writeHNOString("FNAM", name); + esm.writeHNCString("MODL", model); + esm.writeHNOCString("FNAM", name); esm.writeHNT("CTDT", data, 12); - esm.writeHNOString("SCRI", script); - esm.writeHNOString("ITEX", icon); + esm.writeHNOCString("SCRI", script); + esm.writeHNOCString("ITEX", icon); parts.save(esm); - esm.writeHNOString("ENAM", enchant); + esm.writeHNOCString("ENAM", enchant); } } diff --git a/components/esm/loadcont.cpp b/components/esm/loadcont.cpp index 176c4ec05..125ec72d4 100644 --- a/components/esm/loadcont.cpp +++ b/components/esm/loadcont.cpp @@ -40,12 +40,12 @@ void Container::load(ESMReader &esm) void Container::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); - esm.writeHNOString("FNAM", name); + esm.writeHNCString("MODL", model); + esm.writeHNOCString("FNAM", name); esm.writeHNT("CNDT", weight, 4); esm.writeHNT("FLAG", flags, 4); - esm.writeHNOString("SCRI", script); + esm.writeHNOCString("SCRI", script); inventory.save(esm); } diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index 259d37b4a..c4f9dca48 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -16,6 +16,8 @@ void Creature::load(ESMReader &esm) esm.getHNOT(scale, "XSCL"); inventory.load(esm); + spells.load(esm); + aiData.load(esm); // More subrecords: @@ -37,15 +39,18 @@ void Creature::load(ESMReader &esm) void Creature::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); - esm.writeHNOString("CNAM", original); - esm.writeHNOString("FNAM", name); - esm.writeHNOString("SCRI", script); + esm.writeHNCString("MODL", model); + esm.writeHNOCString("CNAM", original); + esm.writeHNOCString("FNAM", name); + esm.writeHNOCString("SCRI", script); esm.writeHNT("NPDT", data, 96); esm.writeHNT("FLAG", flags); if (scale != 1.0) esm.writeHNT("XSCL", scale); + inventory.save(esm); + spells.save(esm); + aiData.save(esm); } } diff --git a/components/esm/loadcrea.hpp b/components/esm/loadcrea.hpp index 348c14b23..355065aeb 100644 --- a/components/esm/loadcrea.hpp +++ b/components/esm/loadcrea.hpp @@ -5,6 +5,7 @@ #include "esm_reader.hpp" #include "esm_writer.hpp" #include "loadcont.hpp" +#include "defs.hpp" namespace ESM { @@ -54,6 +55,7 @@ struct Creature : public Record }; // 96 bytes NPDTstruct data; + AIData aiData; int flags; float scale; @@ -62,6 +64,7 @@ struct Creature : public Record // Defined in loadcont.hpp InventoryList inventory; + SpellList spells; void load(ESMReader &esm); void save(ESMWriter &esm); diff --git a/components/esm/loaddoor.cpp b/components/esm/loaddoor.cpp index 45af407e1..fe00ceb50 100644 --- a/components/esm/loaddoor.cpp +++ b/components/esm/loaddoor.cpp @@ -13,11 +13,11 @@ void Door::load(ESMReader &esm) } void Door::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); - esm.writeHNOString("FNAM", name); - esm.writeHNOString("SCRI", script); - esm.writeHNOString("SNAM", openSound); - esm.writeHNOString("ANAM", closeSound); + esm.writeHNCString("MODL", model); + esm.writeHNOCString("FNAM", name); + esm.writeHNOCString("SCRI", script); + esm.writeHNOCString("SNAM", openSound); + esm.writeHNOCString("ANAM", closeSound); } } diff --git a/components/esm/loadingr.cpp b/components/esm/loadingr.cpp index b8b8aea06..d539f8d7e 100644 --- a/components/esm/loadingr.cpp +++ b/components/esm/loadingr.cpp @@ -13,11 +13,11 @@ void Ingredient::load(ESMReader &esm) } void Ingredient::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); - esm.writeHNString("FNAM", name); + esm.writeHNCString("MODL", model); + esm.writeHNCString("FNAM", name); esm.writeHNT("IRDT", data, 56); - esm.writeHNOString("SCRI", script); - esm.writeHNOString("ITEX", script); + esm.writeHNOCString("SCRI", script); + esm.writeHNOCString("ITEX", icon); } } diff --git a/components/esm/loadlevlist.cpp b/components/esm/loadlevlist.cpp index f63a72025..e0d514088 100644 --- a/components/esm/loadlevlist.cpp +++ b/components/esm/loadlevlist.cpp @@ -38,7 +38,7 @@ void LeveledListBase::save(ESMWriter &esm) for (std::vector::iterator it = list.begin(); it != list.end(); ++it) { - esm.writeHNString(recName, it->id); + esm.writeHNCString(recName, it->id); esm.writeHNT("INTV", it->level); } } diff --git a/components/esm/loadligh.cpp b/components/esm/loadligh.cpp index 2b1d37461..ce2ffe61f 100644 --- a/components/esm/loadligh.cpp +++ b/components/esm/loadligh.cpp @@ -15,12 +15,12 @@ void Light::load(ESMReader &esm) } void Light::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); - esm.writeHNOString("FNAM", name); - esm.writeHNOString("ITEX", icon); + esm.writeHNCString("MODL", model); + esm.writeHNOCString("FNAM", name); + esm.writeHNOCString("ITEX", icon); esm.writeHNT("LHDT", data, 24); - esm.writeHNOString("SCRI", script); - esm.writeHNOString("SNAM", sound); + esm.writeHNOCString("SCRI", script); + esm.writeHNOCString("SNAM", sound); } } diff --git a/components/esm/loadlocks.cpp b/components/esm/loadlocks.cpp index b3d53f458..6b0dc3cc8 100644 --- a/components/esm/loadlocks.cpp +++ b/components/esm/loadlocks.cpp @@ -33,8 +33,8 @@ void Tool::load(ESMReader &esm) } void Tool::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); - esm.writeHNString("FNAM", name); + esm.writeHNCString("MODL", model); + esm.writeHNCString("FNAM", name); std::string typeName; switch(type) @@ -44,9 +44,17 @@ void Tool::save(ESMWriter &esm) case Type_Probe: typeName = "PBDT"; break; } - esm.writeHNT(typeName, data, 16); + Data write = data; + if (type == Type_Repair) + { + float tmp = *((float*) &write.uses); + write.uses = *((int*) &write.quality); + write.quality = tmp; + } + + esm.writeHNT(typeName, write, 16); esm.writeHNOString("SCRI", script); - esm.writeHNOString("ITEX", icon); + esm.writeHNOCString("ITEX", icon); } diff --git a/components/esm/loadltex.cpp b/components/esm/loadltex.cpp index b4820d9ec..7c3d95b71 100644 --- a/components/esm/loadltex.cpp +++ b/components/esm/loadltex.cpp @@ -11,7 +11,7 @@ void LandTexture::load(ESMReader &esm) void LandTexture::save(ESMWriter &esm) { esm.writeHNT("INTV", index); - esm.writeHNString("DATA", texture); + esm.writeHNCString("DATA", texture); } } diff --git a/components/esm/loadmgef.cpp b/components/esm/loadmgef.cpp index 8de37f065..282bcf52a 100644 --- a/components/esm/loadmgef.cpp +++ b/components/esm/loadmgef.cpp @@ -28,17 +28,17 @@ void MagicEffect::save(ESMWriter &esm) esm.writeHNT("INDX", index); esm.writeHNT("MEDT", data, 36); - esm.writeHNOString("ITEX", icon); - esm.writeHNOString("PTEX", particle); - esm.writeHNOString("BSND", boltSound); - esm.writeHNOString("CSND", castSound); - esm.writeHNOString("HSND", hitSound); - esm.writeHNOString("ASND", areaSound); + esm.writeHNOCString("ITEX", icon); + esm.writeHNOCString("PTEX", particle); + esm.writeHNOCString("BSND", boltSound); + esm.writeHNOCString("CSND", castSound); + esm.writeHNOCString("HSND", hitSound); + esm.writeHNOCString("ASND", areaSound); - esm.writeHNOString("CVFX", casting); - esm.writeHNOString("BVFX", bolt); - esm.writeHNOString("HVFX", hit); - esm.writeHNOString("AVFX", area); + esm.writeHNOCString("CVFX", casting); + esm.writeHNOCString("BVFX", bolt); + esm.writeHNOCString("HVFX", hit); + esm.writeHNOCString("AVFX", area); esm.writeHNOString("DESC", description); } diff --git a/components/esm/loadmisc.cpp b/components/esm/loadmisc.cpp index cf5cf92ae..6d5aa3f5e 100644 --- a/components/esm/loadmisc.cpp +++ b/components/esm/loadmisc.cpp @@ -13,11 +13,11 @@ void Miscellaneous::load(ESMReader &esm) } void Miscellaneous::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); - esm.writeHNOString("FNAM", name); + esm.writeHNCString("MODL", model); + esm.writeHNOCString("FNAM", name); esm.writeHNT("MCDT", data, 12); - esm.writeHNOString("SCRI", script); - esm.writeHNOString("ITEX", icon); + esm.writeHNOCString("SCRI", script); + esm.writeHNOCString("ITEX", icon); } } diff --git a/components/esm/loadnpc.cpp b/components/esm/loadnpc.cpp index b689ba5e8..d250ad455 100644 --- a/components/esm/loadnpc.cpp +++ b/components/esm/loadnpc.cpp @@ -37,27 +37,20 @@ void NPC::load(ESMReader &esm) inventory.load(esm); spells.load(esm); - - if (esm.isNextSub("AIDT")) - { - esm.getHExact(&AI, sizeof(AI)); - hasAI = true; - } - else - hasAI = false; + aiData.load(esm); esm.skipRecord(); } void NPC::save(ESMWriter &esm) { - esm.writeHNOString("MODL", model); - esm.writeHNOString("FNAM", name); - esm.writeHNString("RNAM", race); - esm.writeHNString("CNAM", cls); - esm.writeHNString("ANAM", faction); - esm.writeHNString("BNAM", head); - esm.writeHNString("KNAM", hair); - esm.writeHNOString("SCRI", script); + esm.writeHNOCString("MODL", model); + esm.writeHNOCString("FNAM", name); + esm.writeHNCString("RNAM", race); + esm.writeHNCString("CNAM", cls); + esm.writeHNCString("ANAM", faction); + esm.writeHNCString("BNAM", head); + esm.writeHNCString("KNAM", hair); + esm.writeHNOCString("SCRI", script); if (npdtType == 52) esm.writeHNT("NPDT", npdt52, 52); @@ -68,9 +61,7 @@ void NPC::save(ESMWriter &esm) inventory.save(esm); spells.save(esm); - - if (hasAI) - esm.writeHNT("AIDT", AI); + aiData.save(esm); } } diff --git a/components/esm/loadnpc.hpp b/components/esm/loadnpc.hpp index 13ee9ef6d..042d803b7 100644 --- a/components/esm/loadnpc.hpp +++ b/components/esm/loadnpc.hpp @@ -74,15 +74,6 @@ struct NPC : public Record int gold; // ?? not certain }; // 12 bytes - struct AIDTstruct - { - // These are probabilities - char hello, u1, fight, flee, alarm, u2, u3, u4; - // The last u's might be the skills that this NPC can train you - // in? - int services; // See the Services enum - }; // 12 bytes - #pragma pack(pop) char npdtType; @@ -93,12 +84,10 @@ struct NPC : public Record InventoryList inventory; SpellList spells; - - AIDTstruct AI; - bool hasAI; + AIData aiData; std::string name, model, race, cls, faction, script, - hair, head; // body parts + hair, head; // body parts //std::string mId; diff --git a/components/esm/loadregn.cpp b/components/esm/loadregn.cpp index f9e4a151e..7a8c5b5b9 100644 --- a/components/esm/loadregn.cpp +++ b/components/esm/loadregn.cpp @@ -27,14 +27,14 @@ void Region::load(ESMReader &esm) } void Region::save(ESMWriter &esm) { - esm.writeHNString("FNAM", name); + esm.writeHNCString("FNAM", name); if (esm.getVersion() == VER_12) esm.writeHNT("WEAT", data, sizeof(data) - 2); else esm.writeHNT("WEAT", data); - esm.writeHNOString("BNAM", sleepList); + esm.writeHNOCString("BNAM", sleepList); esm.writeHNT("CNAM", mapColor); for (std::vector::iterator it = soundList.begin(); it != soundList.end(); ++it) diff --git a/components/esm/loadscpt.cpp b/components/esm/loadscpt.cpp index 658f97a49..5fdedf4f0 100644 --- a/components/esm/loadscpt.cpp +++ b/components/esm/loadscpt.cpp @@ -42,21 +42,25 @@ void Script::save(ESMWriter &esm) { std::string varNameString; if (!varNames.empty()) - { for (std::vector::iterator it = varNames.begin(); it != varNames.end(); ++it) - { varNameString.append(*it); - //varNameString.append("\0"); - } - - data.stringTableSize = varNameString.size(); - } esm.writeHNT("SCHD", data, 52); - esm.writeHNOString("SCVR", varNameString); + if (!varNames.empty()) + { + esm.startSubRecord("SCVR"); + for (std::vector::iterator it = varNames.begin(); it != varNames.end(); ++it) + { + esm.writeHCString(*it); + } + esm.endRecord("SCVR"); + } + + esm.startSubRecord("SCDT"); + esm.write(&scriptData[0], data.scriptDataSize); + esm.endRecord("SCDT"); - esm.writeHNString("SCDT", std::string(&scriptData[0], scriptData.size())); esm.writeHNOString("SCTX", scriptText); } diff --git a/components/esm/loadsoun.cpp b/components/esm/loadsoun.cpp index a160f3d1c..49afaee7f 100644 --- a/components/esm/loadsoun.cpp +++ b/components/esm/loadsoun.cpp @@ -16,7 +16,7 @@ void Sound::load(ESMReader &esm) } void Sound::save(ESMWriter &esm) { - esm.writeHNString("FNAM", sound); + esm.writeHNCString("FNAM", sound); esm.writeHNT("DATA", data, 3); } diff --git a/components/esm/loadspel.cpp b/components/esm/loadspel.cpp index a87dfb620..4fe3e2789 100644 --- a/components/esm/loadspel.cpp +++ b/components/esm/loadspel.cpp @@ -11,7 +11,7 @@ void Spell::load(ESMReader &esm) } void Spell::save(ESMWriter &esm) { - esm.writeHNOString("FNAM", name); + esm.writeHNOCString("FNAM", name); esm.writeHNT("SPDT", data, 12); effects.save(esm); } diff --git a/components/esm/loadstat.cpp b/components/esm/loadstat.cpp index 2252e9b03..65e2d724f 100644 --- a/components/esm/loadstat.cpp +++ b/components/esm/loadstat.cpp @@ -9,7 +9,7 @@ void Static::load(ESMReader &esm) } void Static::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); + esm.writeHNCString("MODL", model); } } diff --git a/components/esm/loadweap.cpp b/components/esm/loadweap.cpp index 6cc7fa02d..557013d62 100644 --- a/components/esm/loadweap.cpp +++ b/components/esm/loadweap.cpp @@ -14,12 +14,12 @@ void Weapon::load(ESMReader &esm) } void Weapon::save(ESMWriter &esm) { - esm.writeHNString("MODL", model); - esm.writeHNOString("FNAM", name); + esm.writeHNCString("MODL", model); + esm.writeHNOCString("FNAM", name); esm.writeHNT("WPDT", data, 32); - esm.writeHNOString("SCRI", script); - esm.writeHNOString("ITEX", icon); - esm.writeHNOString("ENAM", enchant); + esm.writeHNOCString("SCRI", script); + esm.writeHNOCString("ITEX", icon); + esm.writeHNOCString("ENAM", enchant); } } diff --git a/components/esm/record.hpp b/components/esm/record.hpp index dfecab7b9..6154cbd48 100644 --- a/components/esm/record.hpp +++ b/components/esm/record.hpp @@ -67,10 +67,14 @@ public: std::string getId() const { return m_id; } void setId(const std::string& in) { m_id = in; } + int getFlags() const { return (m_flags & 0x1 ? 0x00002000 : 0) | (m_flags & 0x2 ? 0x00000400 : 0); } + void setFlags(int in) { m_flags = (in & 0x00002000 ? 0x1 : 0) | (in & 0x00000400 ? 0x2 : 0); } + virtual int getName() = 0; protected: std::string m_id; + char m_flags; }; } diff --git a/components/to_utf8/to_utf8.cpp b/components/to_utf8/to_utf8.cpp index 3fbbeb733..3f5f9f61d 100644 --- a/components/to_utf8/to_utf8.cpp +++ b/components/to_utf8/to_utf8.cpp @@ -193,3 +193,167 @@ std::string ToUTF8::getUtf8(ToUTF8::FromType from) return std::string(&output[0], outlen); } +static size_t getLength2(const char *arr, const char* input, bool &ascii) +{ + ascii = true; + size_t len = 0; + const char* ptr = input; + unsigned char inp = *ptr; + + // Do away with the ascii part of the string first (this is almost + // always the entire string.) + while(inp && inp < 128) + inp = *(++ptr); + len += (ptr-input); + + // If we're not at the null terminator at this point, then there + // were some non-ascii characters to deal with. Go to slow-mode for + // the rest of the string. + if(inp) + { + ascii = false; + while(inp) + { + len += 1; + // Find the translated length of this character in the + // lookup table. + switch(inp) + { + case 0xe2: len -= 2; break; + case 0xc2: + case 0xcb: + case 0xc4: + case 0xc6: + case 0xc3: + case 0xd0: + case 0xd1: + case 0xd2: + case 0xc5: len -= 1; break; + } + + inp = *(++ptr); + } + } + return len; +} + +#include +#include + +static void copyFromArray2(const char *arr, char*& chp, char* &out) +{ + unsigned char ch = *(chp++); + // Optimize for ASCII values + if(ch < 128) + { + *(out++) = ch; + return; + } + + int len = 1; + switch (ch) + { + case 0xe2: len = 3; break; + case 0xc2: + case 0xcb: + case 0xc4: + case 0xc6: + case 0xc3: + case 0xd0: + case 0xd1: + case 0xd2: + case 0xc5: len = 2; break; + } + + if (len == 1) // There is no 1 length utf-8 glyph that is not 0x20 (empty space) + { + *(out++) = ch; + return; + } + + unsigned char ch2 = *(chp++); + unsigned char ch3 = '\0'; + if (len == 3) + ch3 = *(chp++); + + for (int i = 128; i < 256; i++) + { + unsigned char b1 = arr[i*6 + 1], b2 = arr[i*6 + 2], b3 = arr[i*6 + 3]; + if (b1 == ch && b2 == ch2 && (len != 3 || b3 == ch3)) + { + *(out++) = (char)i; + return; + } + } + + std::cout << "Could not find glyph " << std::hex << (int)ch << " " << (int)ch2 << " " << (int)ch3 << std::endl; + + *(out++) = ch; // Could not find glyph, just put whatever +} + +std::string ToUTF8::getASCII(ToUTF8::FromType to) +{ + // Pick translation array + const char *arr; + switch (to) + { + case ToUTF8::WINDOWS_1252: + { + arr = ToUTF8::windows_1252; + break; + } + case ToUTF8::WINDOWS_1250: + { + arr = ToUTF8::windows_1250; + break; + } + case ToUTF8::WINDOWS_1251: + { + arr = ToUTF8::windows_1251; + break; + } + default: + { + assert(0); + } + } + + // Double check that the input string stops at some point (it might + // contain zero terminators before this, inside its own data, which + // is also ok.) + char* input = &buf[0]; + assert(input[size] == 0); + + // TODO: The rest of this function is designed for single-character + // input encodings only. It also assumes that the input the input + // encoding shares its first 128 values (0-127) with ASCII. These + // conditions must be checked again if you add more input encodings + // later. + + // Compute output length, and check for pure ascii input at the same + // time. + bool ascii; + size_t outlen = getLength2(arr, input, ascii); + + // If we're pure ascii, then don't bother converting anything. + if(ascii) + return std::string(input, outlen); + + // Make sure the output is large enough + resize(output, outlen); + char *out = &output[0]; + + // Translate + while(*input) + copyFromArray2(arr, input, out); + + // Make sure that we wrote the correct number of bytes + assert((out-&output[0]) == (int)outlen); + + // And make extra sure the output is null terminated + assert(output.size() > outlen); + assert(output[outlen] == 0); + + // Return a string + return std::string(&output[0], outlen); +} diff --git a/components/to_utf8/to_utf8.hpp b/components/to_utf8/to_utf8.hpp index 4cbee1019..1a6a077be 100644 --- a/components/to_utf8/to_utf8.hpp +++ b/components/to_utf8/to_utf8.hpp @@ -21,6 +21,7 @@ namespace ToUTF8 // Convert the previously written buffer to UTF8 from the given code // page. std::string getUtf8(FromType from); + std::string getASCII(FromType to); } #endif From 0c9dfcc0179dfd35984087667cfb22f15b6d60e3 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Sun, 29 Apr 2012 09:26:03 +0200 Subject: [PATCH 13/48] Some changes --- apps/esmtool/esmtool.cpp | 6 ++++-- components/esm/loadland.cpp | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index 2eab0bc1a..abbf5ca0e 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -41,6 +41,8 @@ struct Arguments string outname; ESMData data; + ESMReader reader; + ESMWriter writer; }; bool parseOptions (int argc, char** argv, Arguments &info) @@ -230,7 +232,7 @@ void printRaw(ESMReader &esm) int load(Arguments& info) { - ESMReader esm; + ESMReader& esm = info.reader; esm.setEncoding(info.encoding); string filename = info.filename; @@ -806,7 +808,7 @@ int clone(Arguments& info) cout << endl << "Saving records to: " << info.outname << "..." << endl; - ESMWriter esm; + ESMWriter& esm = info.writer; esm.setEncoding(info.encoding); esm.setAuthor(info.data.author); esm.setDescription(info.data.description); diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index 222772041..512363fa0 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -91,13 +91,17 @@ void Land::save(ESMWriter &esm) esm.writeHNT("DATA", flags); - /* TODO: Land! - if (hasData && !dataLoaded) + // TODO: Land! + bool wasLoaded = dataLoaded; + if (hasData) loadData(); // I think it might be a good idea to have // the data loaded before trying to save it - */ + if (dataLoaded) landData->save(esm); + + if (!wasLoaded) + unloadData(); } void Land::loadData() From 1627206d5624de89833b13075f0899048e0a2cf1 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 2 May 2012 13:59:03 -0700 Subject: [PATCH 14/48] Remove an unused method Best not to design something we don't yet know what's needed from it. --- apps/openmw/mwsound/soundmanager.cpp | 12 ------------ apps/openmw/mwsound/soundmanager.hpp | 3 --- 2 files changed, 15 deletions(-) diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 9eefc7a28..903249c8d 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -401,18 +401,6 @@ namespace MWSound return isPlaying(ptr, soundId); } - void SoundManager::updateObject(MWWorld::Ptr ptr) - { - const ESM::Position &pos = ptr.getCellRef().pos; - const Ogre::Vector3 objpos(pos.pos[0], pos.pos[1], pos.pos[2]); - SoundMap::iterator snditer = mActiveSounds.begin(); - while(snditer != mActiveSounds.end()) - { - if(snditer->second.first == ptr) - snditer->first->setPosition(objpos); - snditer++; - } - } void SoundManager::updateRegionSound(float duration) { diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index e1816cd1f..4b0801f7f 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -131,9 +131,6 @@ namespace MWSound bool getSoundPlaying(MWWorld::Ptr reference, const std::string& soundId) const; ///< Is the given sound currently playing on the given object? - void updateObject(MWWorld::Ptr reference); - ///< Update the position of all sounds connected to the given object. - void update(float duration); }; } From 76c4aa41bb4a528197a0fb25d74a374e077cb631 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Mon, 11 Jun 2012 20:02:03 +0200 Subject: [PATCH 15/48] More land and cell work --- components/esm/loadcell.cpp | 15 +++++++--- components/esm/loadcell.hpp | 1 + components/esm/loadland.cpp | 58 +++++++++++++++++++++++-------------- components/esm/loadland.hpp | 14 +++++++-- 4 files changed, 60 insertions(+), 28 deletions(-) diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 57d951658..34bcaf34c 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -9,7 +9,7 @@ namespace ESM void CellRef::save(ESMWriter &esm) { esm.writeHNT("FRMR", refnum); - esm.writeHNString("NAME", refID); + esm.writeHNCString("NAME", refID); if (scale != 1.0) esm.writeHNT("XSCL", scale); @@ -33,7 +33,7 @@ void CellRef::save(ESMWriter &esm) if (teleport) { esm.writeHNT("DODT", doorDest); - esm.writeHNOString("DNAM", destCell); + esm.writeHNOCString("DNAM", destCell); } if (lockLevel != 0) @@ -60,6 +60,7 @@ void Cell::load(ESMReader &esm) // Water level water = 0; + NAM0 = 0; if (data.flags & Interior) { @@ -87,6 +88,8 @@ void Cell::load(ESMReader &esm) region = esm.getHNOString("RGNN"); esm.getHNOT(mapColor, "NAM5"); } + if (esm.isNextSub("NAM0")) + esm.getHT(NAM0); // Save position of the cell references and move on context = esm.getContext(); @@ -112,6 +115,9 @@ void Cell::save(ESMWriter &esm) if (mapColor != 0) esm.writeHNT("NAM5", mapColor); } + + if (NAM0 != 0) + esm.writeHNT("NAM0", NAM0); } void Cell::restore(ESMReader &esm) const @@ -141,9 +147,10 @@ bool Cell::getNextRef(ESMReader &esm, CellRef &ref) // Number of references in the cell? Maximum once in each cell, // but not always at the beginning, and not always right. In other // words, completely useless. + if (esm.isNextSub("NAM0")) { - int i; - esm.getHNOT(i, "NAM0"); + esm.skipHSubSize(4); + //esm.getHNOT(NAM0, "NAM0"); } esm.getHNT(ref.refnum, "FRMR"); diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index f03c541b7..a485ceb1f 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -120,6 +120,7 @@ struct Cell : public Record AMBIstruct ambi; float water; // Water level int mapColor; + int NAM0; void load(ESMReader &esm); void save(ESMWriter &esm); diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index 512363fa0..0a6fa6397 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -7,11 +7,18 @@ void Land::LandData::save(ESMWriter &esm) { // TODO: Make this actually work. - //esm.writeHNT("VNML", normals, sizeof(VNML)); + esm.writeHNT("VNML", normals, sizeof(VNML)); esm.writeHNT("VHGT", heights, sizeof(VHGT)); - esm.writeHNT("WNAM", 0, 81); - esm.writeHNT("VCLR", colours, 3*LAND_NUM_VERTS); - esm.writeHNT("VTEX", textures, 512); + //esm.writeHNT("WNAM", 0, 81); + esm.startSubRecord("WNAM"); + for (int i = 0; i < 81; i++) + esm.writeT((char)0x80, 1); + esm.endRecord("WNAM"); + + if (dataTypes & Land::DATA_VCLR) + esm.writeHNT("VCLR", colours, 3*LAND_NUM_VERTS); + if (dataTypes & Land::DATA_VTEX) + esm.writeHNT("VTEX", textures, 512); } Land::Land() @@ -19,7 +26,8 @@ Land::Land() , X(0) , Y(0) , mEsm(NULL) - , hasData(false) +// , hasData(false) + , dataTypes(0) , dataLoaded(false) , landData(NULL) { @@ -30,7 +38,6 @@ Land::~Land() delete landData; } - void Land::load(ESMReader &esm) { mEsm = &esm; @@ -47,36 +54,37 @@ void Land::load(ESMReader &esm) context = esm.getContext(); hasData = false; - int cnt = 0; // Skip these here. Load the actual data when the cell is loaded. if (esm.isNextSub("VNML")) { esm.skipHSubSize(12675); - cnt++; + dataTypes |= DATA_VNML; } if (esm.isNextSub("VHGT")) { esm.skipHSubSize(4232); - cnt++; + dataTypes |= DATA_VHGT; } if (esm.isNextSub("WNAM")) { esm.skipHSubSize(81); + dataTypes |= DATA_WNAM; } if (esm.isNextSub("VCLR")) { esm.skipHSubSize(12675); + dataTypes |= DATA_VCLR; } if (esm.isNextSub("VTEX")) { esm.skipHSubSize(512); - cnt++; + dataTypes |= DATA_VTEX; } // We need all three of VNML, VHGT and VTEX in order to use the - // landscape. - hasData = (cnt == 3); + // landscape. (Though Morrowind seems to accept terrain without VTEX/VCLR entries) + hasData = dataTypes & (DATA_VNML|DATA_VHGT|DATA_WNAM); dataLoaded = false; landData = NULL; @@ -101,7 +109,7 @@ void Land::save(ESMWriter &esm) landData->save(esm); if (!wasLoaded) - unloadData(); + unloadData(); // Don't need to keep the data loaded if it wasn't already } void Land::loadData() @@ -117,6 +125,8 @@ void Land::loadData() { mEsm->restoreContext(context); + memset(landData->normals, 0, LAND_NUM_VERTS * 3); + //esm.getHNExact(landData->normals, sizeof(VNML), "VNML"); if (mEsm->isNextSub("VNML")) { @@ -151,16 +161,19 @@ void Land::loadData() }else{ landData->usingColours = false; } - //TODO fix magic numbers - uint16_t vtex[512]; - mEsm->getHNExact(&vtex, 512, "VTEX"); + if (mEsm->isNextSub("VTEX")) + { + //TODO fix magic numbers + uint16_t vtex[512]; + mEsm->getHExact(&vtex, 512); - int readPos = 0; //bit ugly, but it works - for ( int y1 = 0; y1 < 4; y1++ ) - for ( int x1 = 0; x1 < 4; x1++ ) - for ( int y2 = 0; y2 < 4; y2++) - for ( int x2 = 0; x2 < 4; x2++ ) - landData->textures[(y1*4+y2)*16+(x1*4+x2)] = vtex[readPos++]; + int readPos = 0; //bit ugly, but it works + for ( int y1 = 0; y1 < 4; y1++ ) + for ( int x1 = 0; x1 < 4; x1++ ) + for ( int y2 = 0; y2 < 4; y2++) + for ( int x2 = 0; x2 < 4; x2++ ) + landData->textures[(y1*4+y2)*16+(x1*4+x2)] = vtex[readPos++]; + } } else { @@ -172,6 +185,7 @@ void Land::loadData() } } + landData->dataTypes = dataTypes; dataLoaded = true; } diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index 6a14891f1..1cbe4db12 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -26,9 +26,18 @@ struct Land : public Record ESM_Context context; bool hasData; - + int dataTypes; bool dataLoaded; + enum + { + DATA_VNML = 1, + DATA_VHGT = 2, + DATA_WNAM = 4, + DATA_VCLR = 8, + DATA_VTEX = 16 + }; + // number of vertices per side static const int LAND_SIZE = 65; @@ -62,11 +71,12 @@ struct Land : public Record { float heightOffset; float heights[LAND_NUM_VERTS]; - //float normals[LAND_NUM_VERTS * 3]; + VNML normals; uint16_t textures[LAND_NUM_TEXTURES]; bool usingColours; char colours[3 * LAND_NUM_VERTS]; + int dataTypes; void save(ESMWriter &esm); }; From 597b88e95a23f7b5d50da00e4f29ab488fdc9219 Mon Sep 17 00:00:00 2001 From: greye Date: Tue, 18 Sep 2012 19:30:19 +0400 Subject: [PATCH 16/48] update saving AI packages --- components/esm/aipackage.cpp | 27 +++++++++++++++++++++++++++ components/esm/aipackage.hpp | 2 +- components/esm/loadcrea.cpp | 3 +++ components/esm/loadgmst.hpp | 2 -- components/esm/loadnpc.cpp | 9 +++++++++ components/esm_store/reclists.hpp | 2 +- 6 files changed, 41 insertions(+), 4 deletions(-) diff --git a/components/esm/aipackage.cpp b/components/esm/aipackage.cpp index ba07a6889..7cc9cd2e5 100644 --- a/components/esm/aipackage.cpp +++ b/components/esm/aipackage.cpp @@ -40,5 +40,32 @@ namespace ESM void AIPackageList::save(ESMWriter &esm) { + typedef std::vector::iterator PackageIter; + for (PackageIter it = mList.begin(); it != mList.end(); ++it) { + switch (it->mType) { + case AI_Wander: + esm.writeHNT("AI_W", it->mWander, sizeof(it->mWander)); + break; + + case AI_Travel: + esm.writeHNT("AI_T", it->mTravel, sizeof(it->mTravel)); + break; + + case AI_Activate: + esm.writeHNT("AI_A", it->mActivate, sizeof(it->mActivate)); + break; + + case AI_Escort: + case AI_Follow: { + const char *name = (it->mType == AI_Escort) ? "AI_E" : "AI_F"; + esm.writeHNT(name, it->mTarget, sizeof(it->mTarget)); + esm.writeHNOCString("CNDT", it->mCellName); + break; + } + + default: + break; + } + } } } diff --git a/components/esm/aipackage.hpp b/components/esm/aipackage.hpp index 1699be5ef..0efc3b61e 100644 --- a/components/esm/aipackage.hpp +++ b/components/esm/aipackage.hpp @@ -35,7 +35,7 @@ namespace ESM struct AITravel { float mX, mY, mZ; - long mUnk; + int mUnk; }; struct AITarget diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index 083032839..2af6aeb05 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -47,6 +47,9 @@ void Creature::save(ESMWriter &esm) mInventory.save(esm); mSpells.save(esm); + if (mHasAI) { + esm.writeHNT("AIDT", mAiData, sizeof(mAiData)); + } mAiPackage.save(esm); } diff --git a/components/esm/loadgmst.hpp b/components/esm/loadgmst.hpp index 18c881521..c9dc8d5c1 100644 --- a/components/esm/loadgmst.hpp +++ b/components/esm/loadgmst.hpp @@ -15,8 +15,6 @@ namespace ESM struct GameSetting : public Record { - std::string mId; - // One of these is used depending on the variable type std::string mStr; int mI; diff --git a/components/esm/loadnpc.cpp b/components/esm/loadnpc.cpp index b6e7728df..ee2833ca1 100644 --- a/components/esm/loadnpc.cpp +++ b/components/esm/loadnpc.cpp @@ -81,6 +81,15 @@ void NPC::save(ESMWriter &esm) mInventory.save(esm); mSpells.save(esm); + if (mHasAI) { + esm.writeHNT("AIDT", mAiData, sizeof(mAiData)); + } + + typedef std::vector::iterator DestIter; + for (DestIter it = mTransport.begin(); it != mTransport.end(); ++it) { + esm.writeHNT("DODT", it->mPos, sizeof(it->mPos)); + esm.writeHNOCString("DNAM", it->mCellName); + } mAiPackage.save(esm); } diff --git a/components/esm_store/reclists.hpp b/components/esm_store/reclists.hpp index 823e4258c..bf98bf1d7 100644 --- a/components/esm_store/reclists.hpp +++ b/components/esm_store/reclists.hpp @@ -226,7 +226,7 @@ namespace ESMS std::string id2 = toLower (id); X& ref = list[id2]; - ref.mId = id; + ref.setId(id); ref.load(esm); } From e69880f77eae0a8668e1b6c160a107c3bad8e734 Mon Sep 17 00:00:00 2001 From: greye Date: Thu, 20 Sep 2012 20:33:30 +0400 Subject: [PATCH 17/48] almost perfect byte copies, has redundant data --- apps/esmtool/esmtool.cpp | 14 +++++-- components/esm/esm_writer.cpp | 2 +- components/esm/loadcell.cpp | 66 ++++++++++++++++++------------ components/esm/loadcell.hpp | 2 + components/esm/loadinfo.cpp | 20 ++++----- components/esm/loadingr.cpp | 3 +- components/esm/loadland.cpp | 77 ++++++++++++++++++++++++++++------- components/esm/loadland.hpp | 4 ++ components/esm/loadmgef.cpp | 4 +- components/esm/loadpgrd.cpp | 2 +- components/esm/loadsndg.cpp | 4 +- components/esm/loadsscr.cpp | 5 +-- components/esm/loadsscr.hpp | 1 + 13 files changed, 140 insertions(+), 64 deletions(-) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index 36ad95a31..cd0e8e1c1 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -714,6 +714,15 @@ int load(Arguments& info) << " Value: " << w.mData.mValue << endl; break; } + case REC_SSCR: + { + rec = new StartScript(); + StartScript &sscr = *(StartScript *) rec; + sscr.load(esm); + if (quiet) break; + cout << "Start script: " << sscr.mScript << endl; + break; + } default: if (find(skipped.begin(), skipped.end(), n.val) == skipped.end()) { @@ -832,16 +841,15 @@ int clone(Arguments& info) esm.startRecord(n.toString(), rec->getFlags()); string id = rec->getId(); + // TODO wrap this with std::set if (n.val == REC_GLOB || n.val == REC_CLAS || n.val == REC_FACT || n.val == REC_RACE || n.val == REC_SOUN || n.val == REC_REGN || n.val == REC_BSGN || n.val == REC_LTEX || n.val == REC_STAT || n.val == REC_DOOR || n.val == REC_MISC || n.val == REC_WEAP || n.val == REC_CONT || n.val == REC_SPEL || n.val == REC_CREA || n.val == REC_BODY || n.val == REC_LIGH || n.val == REC_ENCH || n.val == REC_NPC_ || n.val == REC_ARMO || n.val == REC_CLOT || n.val == REC_REPA || n.val == REC_ACTI || n.val == REC_APPA || n.val == REC_LOCK || n.val == REC_PROB || n.val == REC_INGR || n.val == REC_BOOK || n.val == REC_ALCH || n.val == REC_LEVI - || n.val == REC_LEVC) + || n.val == REC_LEVC || n.val == REC_SNDG || n.val == REC_CELL || n.val == REC_DIAL) esm.writeHNCString("NAME", id); - else if (n.val == REC_CELL) - esm.writeHNString("NAME", id); else esm.writeHNOString("NAME", id); diff --git a/components/esm/esm_writer.cpp b/components/esm/esm_writer.cpp index ef8a9c1b8..5bb9e286d 100644 --- a/components/esm/esm_writer.cpp +++ b/components/esm/esm_writer.cpp @@ -64,7 +64,7 @@ void ESMWriter::save(std::ostream& file) for (std::list::iterator it = m_masters.begin(); it != m_masters.end(); ++it) { - writeHNString("MAST", it->name); + writeHNCString("MAST", it->name); writeHNT("DATA", it->size); } diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 8fe1c82f6..c83c5f400 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -18,12 +18,12 @@ void CellRef::save(ESMWriter &esm) esm.writeHNT("XSCL", mScale); } - esm.writeHNOString("ANAM", mOwner); - esm.writeHNOString("BNAM", mGlob); - esm.writeHNOString("XSOL", mSoul); + esm.writeHNOCString("ANAM", mOwner); + esm.writeHNOCString("BNAM", mGlob); + esm.writeHNOCString("XSOL", mSoul); - esm.writeHNOString("CNAM", mFaction); - if (mFactIndex != -1) { + esm.writeHNOCString("CNAM", mFaction); + if (mFactIndex != -2) { esm.writeHNT("INDX", mFactIndex); } @@ -31,7 +31,7 @@ void CellRef::save(ESMWriter &esm) esm.writeHNT("XCHG", mCharge); } - if (mIntv != 0) { + if (mIntv != -1) { esm.writeHNT("INTV", mIntv); } if (mNam9 != 0) { @@ -44,13 +44,13 @@ void CellRef::save(ESMWriter &esm) esm.writeHNOCString("DNAM", mDestCell); } - if (mLockLevel != 0) { + if (mLockLevel != -1) { esm.writeHNT("FLTV", mLockLevel); } - esm.writeHNOString("KNAM", mKey); - esm.writeHNOString("TNAM", mTrap); + esm.writeHNOCString("KNAM", mKey); + esm.writeHNOCString("TNAM", mTrap); - if (mUnam != 0) { + if (mUnam != -1) { esm.writeHNT("UNAM", mUnam); } if (mFltv != 0) { @@ -58,6 +58,9 @@ void CellRef::save(ESMWriter &esm) } esm.writeHNT("DATA", mPos, 24); + if (mNam0 != 0) { + esm.writeHNT("NAM0", mNam0); + } } void Cell::load(ESMReader &esm) @@ -71,7 +74,7 @@ void Cell::load(ESMReader &esm) esm.getHNT(mData, "DATA", 12); // Water level - mWater = 0; + mWater = -1; mNAM0 = 0; if (mData.mFlags & Interior) @@ -82,6 +85,7 @@ void Cell::load(ESMReader &esm) int waterl; esm.getHT(waterl); mWater = (float) waterl; + mWaterInt = true; } else if (esm.isNextSub("WHGT")) esm.getHT(mWater); @@ -114,11 +118,18 @@ void Cell::save(ESMWriter &esm) esm.writeHNT("DATA", mData, 12); if (mData.mFlags & Interior) { - if (mWater != 0) - esm.writeHNT("WHGT", mWater); + if (mWater != -1) { + if (mWaterInt) { + int water = + (mWater >= 0) ? (int) (mWater + 0.5) : (int) (mWater - 0.5); + esm.writeHNT("INTV", water); + } else { + esm.writeHNT("WHGT", mWater); + } + } if (mData.mFlags & QuasiEx) - esm.writeHNOString("RGNN", mRegion); + esm.writeHNOCString("RGNN", mRegion); else esm.writeHNT("AMBI", mAmbi, 16); } @@ -157,15 +168,6 @@ bool Cell::getNextRef(ESMReader &esm, CellRef &ref) if (!esm.hasMoreSubs()) return false; - // Number of references in the cell? Maximum once in each cell, - // but not always at the beginning, and not always right. In other - // words, completely useless. - if (esm.isNextSub("NAM0")) - { - esm.skipHSubSize(4); - //esm.getHNOT(NAM0, "NAM0"); - } - esm.getHNT(ref.mRefnum, "FRMR"); ref.mRefID = esm.getHNString("NAME"); @@ -179,13 +181,13 @@ bool Cell::getNextRef(ESMReader &esm, CellRef &ref) ref.mSoul = esm.getHNOString("XSOL"); ref.mFaction = esm.getHNOString("CNAM"); - ref.mFactIndex = -1; + ref.mFactIndex = -2; esm.getHNOT(ref.mFactIndex, "INDX"); ref.mCharge = -1.0; esm.getHNOT(ref.mCharge, "XCHG"); - ref.mIntv = 0; + ref.mIntv = -1; ref.mNam9 = 0; esm.getHNOT(ref.mIntv, "INTV"); esm.getHNOT(ref.mNam9, "NAM9"); @@ -201,18 +203,28 @@ bool Cell::getNextRef(ESMReader &esm, CellRef &ref) } // Integer, despite the name suggesting otherwise - ref.mLockLevel = 0; + ref.mLockLevel = -1; esm.getHNOT(ref.mLockLevel, "FLTV"); ref.mKey = esm.getHNOString("KNAM"); ref.mTrap = esm.getHNOString("TNAM"); - ref.mUnam = 0; + ref.mUnam = -1; ref.mFltv = 0; esm.getHNOT(ref.mUnam, "UNAM"); esm.getHNOT(ref.mFltv, "FLTV"); esm.getHNT(ref.mPos, "DATA", 24); + // Number of references in the cell? Maximum once in each cell, + // but not always at the beginning, and not always right. In other + // words, completely useless. + ref.mNam0 = 0; + if (esm.isNextSub("NAM0")) + { + esm.getHT(ref.mNam0); + //esm.getHNOT(NAM0, "NAM0"); + } + return true; } diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index b22daeb03..b9d85cb9e 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -71,6 +71,7 @@ public: // Brindisi Dorom", where it has the value 100. Also only for // activators. int mFltv; + int mNam0; // Position and rotation of this object within the cell Position mPos; @@ -120,6 +121,7 @@ struct Cell : public Record DATAstruct mData; AMBIstruct mAmbi; float mWater; // Water level + bool mWaterInt; int mMapColor; int mNAM0; diff --git a/components/esm/loadinfo.cpp b/components/esm/loadinfo.cpp index 9fe3668be..b29c1dd94 100644 --- a/components/esm/loadinfo.cpp +++ b/components/esm/loadinfo.cpp @@ -136,17 +136,17 @@ void DialInfo::load(ESMReader &esm) void DialInfo::save(ESMWriter &esm) { - esm.writeHNString("INAM", mSelfId); - esm.writeHNString("PNAM", mPrev); - esm.writeHNString("NNAM", mNext); + esm.writeHNCString("INAM", mSelfId); + esm.writeHNCString("PNAM", mPrev); + esm.writeHNCString("NNAM", mNext); esm.writeHNT("DATA", mData, 12); - esm.writeHNOString("ONAM", mActor); - esm.writeHNOString("RNAM", mRace); - esm.writeHNOString("CNAM", mClass); - esm.writeHNOString("FNAM", mNpcFaction); - esm.writeHNOString("ANAM", mCell); - esm.writeHNOString("DNAM", mPcFaction); - esm.writeHNOString("SNAM", mSound); + esm.writeHNOCString("ONAM", mActor); + esm.writeHNOCString("RNAM", mRace); + esm.writeHNOCString("CNAM", mClass); + esm.writeHNOCString("FNAM", mNpcFaction); + esm.writeHNOCString("ANAM", mCell); + esm.writeHNOCString("DNAM", mPcFaction); + esm.writeHNOCString("SNAM", mSound); esm.writeHNOString("NAME", mResponse); for (std::vector::iterator it = mSelects.begin(); it != mSelects.end(); ++it) diff --git a/components/esm/loadingr.cpp b/components/esm/loadingr.cpp index 65d0a6259..13d66a632 100644 --- a/components/esm/loadingr.cpp +++ b/components/esm/loadingr.cpp @@ -13,7 +13,7 @@ void Ingredient::load(ESMReader &esm) esm.getHNT(mData, "IRDT", 56); mScript = esm.getHNOString("SCRI"); mIcon = esm.getHNOString("ITEX"); - +/* // horrible hack to fix broken data in records for (int i=0; i<4; ++i) { @@ -36,6 +36,7 @@ void Ingredient::load(ESMReader &esm) mData.mSkills[i] = -1; } } +*/ } void Ingredient::save(ESMWriter &esm) diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index 13c640972..fb7c94fcf 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -10,18 +10,61 @@ void Land::LandData::save(ESMWriter &esm) { // TODO: Make this actually work. - esm.writeHNT("VNML", mNormals, sizeof(VNML)); - esm.writeHNT("VHGT", mHeights, sizeof(VHGT)); + if (mDataTypes & Land::DATA_VNML) { + esm.writeHNT("VNML", mNormals, sizeof(VNML)); + } + + if (mDataTypes & Land::DATA_VHGT) { + VHGT offsets; + offsets.mHeightOffset = mHeights[0] / HEIGHT_SCALE; + offsets.mUnknown1 = mUnk1; + offsets.mUnknown2 = mUnk2; + + float prevY = mHeights[0], prevX; + int number = 0; // avoid multiplication + for (int i = 0; i < LAND_SIZE; ++i) { + float diff = (mHeights[number] - prevY) / HEIGHT_SCALE; + offsets.mHeightData[number] = + (diff >= 0) ? (int8_t) (diff + 0.5) : (int8_t) (diff - 0.5); + + prevX = prevY = mHeights[number]; + ++number; + + for (int j = 1; j < LAND_SIZE; ++j) { + diff = (mHeights[number] - prevX) / HEIGHT_SCALE; + offsets.mHeightData[number] = + (diff >= 0) ? (int8_t) (diff + 0.5) : (int8_t) (diff - 0.5); + + prevX = mHeights[number]; + ++number; + } + } + esm.writeHNT("VHGT", offsets, sizeof(VHGT)); + } //esm.writeHNT("WNAM", 0, 81); - esm.startSubRecord("WNAM"); +/* esm.startSubRecord("WNAM"); for (int i = 0; i < 81; i++) esm.writeT((char)0x80, 1); esm.endRecord("WNAM"); +*/ + if (mDataTypes & Land::DATA_WNAM) { + esm.writeHNT("WNAM", mWnam, 81); + } if (mDataTypes & Land::DATA_VCLR) esm.writeHNT("VCLR", mColours, 3*LAND_NUM_VERTS); - if (mDataTypes & Land::DATA_VTEX) - esm.writeHNT("VTEX", mTextures, 512); + if (mDataTypes & Land::DATA_VTEX) { + uint16_t vtex[256]; + + int readPos = 0; //bit ugly, but it works + for ( int y1 = 0; y1 < 4; y1++ ) + for ( int x1 = 0; x1 < 4; x1++ ) + for ( int y2 = 0; y2 < 4; y2++) + for ( int x2 = 0; x2 < 4; x2++ ) + vtex[(y1*4+y2)*16+(x1*4+x2)] = mTextures[readPos++]; + + esm.writeHNT("VTEX", vtex, 512); + } } Land::Land() @@ -87,7 +130,7 @@ void Land::load(ESMReader &esm) // We need all three of VNML, VHGT and VTEX in order to use the // landscape. (Though Morrowind seems to accept terrain without VTEX/VCLR entries) - mHasData = mDataTypes & (DATA_VNML|DATA_VHGT|DATA_WNAM); + mHasData = mDataTypes & (DATA_VNML|DATA_VHGT|DATA_WNAM|DATA_VTEX|DATA_VCLR); mDataLoaded = false; mLandData = NULL; @@ -130,32 +173,38 @@ void Land::loadData() memset(mLandData->mNormals, 0, LAND_NUM_VERTS * 3); - //esm.getHNExact(landData->normals, sizeof(VNML), "VNML"); + if (mEsm->isNextSub("VNML")) { + mEsm->getHExact(mLandData->mNormals, sizeof(VNML)); + }/* if (mEsm->isNextSub("VNML")) { mEsm->skipHSubSize(12675); - } + } */ + if (mEsm->isNextSub("VHGT")) { VHGT rawHeights; - mEsm->getHNExact(&rawHeights, sizeof(VHGT), "VHGT"); - int currentHeightOffset = rawHeights.mHeightOffset; + mEsm->getHExact(&rawHeights, sizeof(VHGT)); + float currentHeightOffset = rawHeights.mHeightOffset; for (int y = 0; y < LAND_SIZE; y++) { currentHeightOffset += rawHeights.mHeightData[y * LAND_SIZE]; mLandData->mHeights[y * LAND_SIZE] = currentHeightOffset * HEIGHT_SCALE; - int tempOffset = currentHeightOffset; + float tempOffset = currentHeightOffset; for (int x = 1; x < LAND_SIZE; x++) { tempOffset += rawHeights.mHeightData[y * LAND_SIZE + x]; mLandData->mHeights[x + y * LAND_SIZE] = tempOffset * HEIGHT_SCALE; } } + mLandData->mUnk1 = rawHeights.mUnknown1; + mLandData->mUnk2 = rawHeights.mUnknown2; + } if (mEsm->isNextSub("WNAM")) { - mEsm->skipHSubSize(81); + mEsm->getHExact(mLandData->mWnam, 81); } if (mEsm->isNextSub("VCLR")) { @@ -167,7 +216,7 @@ void Land::loadData() if (mEsm->isNextSub("VTEX")) { //TODO fix magic numbers - uint16_t vtex[512]; + uint16_t vtex[256]; mEsm->getHExact(&vtex, 512); int readPos = 0; //bit ugly, but it works @@ -181,7 +230,7 @@ void Land::loadData() else { mLandData->mUsingColours = false; - memset(&mLandData->mTextures, 0, 512 * sizeof(uint16_t)); + memset(mLandData->mTextures, 0, sizeof(mLandData->mTextures)); for (int i = 0; i < LAND_NUM_VERTS; i++) { mLandData->mHeights[i] = -256.0f * HEIGHT_SCALE; diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index 3575a79ce..f51ccc780 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -79,6 +79,10 @@ struct Land : public Record char mColours[3 * LAND_NUM_VERTS]; int mDataTypes; + uint8_t mWnam[81]; + short mUnk1; + uint8_t mUnk2; + void save(ESMWriter &esm); }; diff --git a/components/esm/loadmgef.cpp b/components/esm/loadmgef.cpp index 126556143..c18833e01 100644 --- a/components/esm/loadmgef.cpp +++ b/components/esm/loadmgef.cpp @@ -36,10 +36,10 @@ void MagicEffect::load(ESMReader &esm) esm.getHNT(mIndex, "INDX"); esm.getHNT(mData, "MEDT", 36); - +/* if (mIndex>=0 && mIndex Date: Fri, 21 Sep 2012 09:36:18 +0400 Subject: [PATCH 18/48] a bit formatting --- components/esm/loadland.cpp | 138 +++++++++++++++--------------------- components/esm/loadland.hpp | 5 +- 2 files changed, 62 insertions(+), 81 deletions(-) diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index fb7c94fcf..47f238242 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -8,63 +8,57 @@ namespace ESM void Land::LandData::save(ESMWriter &esm) { - // TODO: Make this actually work. - if (mDataTypes & Land::DATA_VNML) { esm.writeHNT("VNML", mNormals, sizeof(VNML)); } - if (mDataTypes & Land::DATA_VHGT) { - VHGT offsets; - offsets.mHeightOffset = mHeights[0] / HEIGHT_SCALE; - offsets.mUnknown1 = mUnk1; - offsets.mUnknown2 = mUnk2; + VHGT offsets; + offsets.mHeightOffset = mHeights[0] / HEIGHT_SCALE; + offsets.mUnk1 = mUnk1; + offsets.mUnk2 = mUnk2; - float prevY = mHeights[0], prevX; - int number = 0; // avoid multiplication - for (int i = 0; i < LAND_SIZE; ++i) { - float diff = (mHeights[number] - prevY) / HEIGHT_SCALE; - offsets.mHeightData[number] = - (diff >= 0) ? (int8_t) (diff + 0.5) : (int8_t) (diff - 0.5); - - prevX = prevY = mHeights[number]; - ++number; - - for (int j = 1; j < LAND_SIZE; ++j) { - diff = (mHeights[number] - prevX) / HEIGHT_SCALE; + float prevY = mHeights[0], prevX; + int number = 0; // avoid multiplication + for (int i = 0; i < LAND_SIZE; ++i) { + float diff = (mHeights[number] - prevY) / HEIGHT_SCALE; offsets.mHeightData[number] = (diff >= 0) ? (int8_t) (diff + 0.5) : (int8_t) (diff - 0.5); - - prevX = mHeights[number]; + + prevX = prevY = mHeights[number]; ++number; + + for (int j = 1; j < LAND_SIZE; ++j) { + diff = (mHeights[number] - prevX) / HEIGHT_SCALE; + offsets.mHeightData[number] = + (diff >= 0) ? (int8_t) (diff + 0.5) : (int8_t) (diff - 0.5); + + prevX = mHeights[number]; + ++number; + } } + esm.writeHNT("VHGT", offsets, sizeof(VHGT)); } - esm.writeHNT("VHGT", offsets, sizeof(VHGT)); - } - //esm.writeHNT("WNAM", 0, 81); -/* esm.startSubRecord("WNAM"); - for (int i = 0; i < 81; i++) - esm.writeT((char)0x80, 1); - esm.endRecord("WNAM"); -*/ if (mDataTypes & Land::DATA_WNAM) { esm.writeHNT("WNAM", mWnam, 81); } - - if (mDataTypes & Land::DATA_VCLR) + if (mDataTypes & Land::DATA_VCLR) { esm.writeHNT("VCLR", mColours, 3*LAND_NUM_VERTS); - if (mDataTypes & Land::DATA_VTEX) { - uint16_t vtex[256]; - - int readPos = 0; //bit ugly, but it works - for ( int y1 = 0; y1 < 4; y1++ ) - for ( int x1 = 0; x1 < 4; x1++ ) - for ( int y2 = 0; y2 < 4; y2++) - for ( int x2 = 0; x2 < 4; x2++ ) - vtex[(y1*4+y2)*16+(x1*4+x2)] = mTextures[readPos++]; - - esm.writeHNT("VTEX", vtex, 512); } + if (mDataTypes & Land::DATA_VTEX) { + static uint16_t vtex[LAND_NUM_TEXTURES]; + transposeTextureData(mTextures, vtex); + esm.writeHNT("VTEX", vtex, sizeof(vtex)); + } +} + +void Land::LandData::transposeTextureData(uint16_t *in, uint16_t *out) +{ + int readPos = 0; //bit ugly, but it works + for ( int y1 = 0; y1 < 4; y1++ ) + for ( int x1 = 0; x1 < 4; x1++ ) + for ( int y2 = 0; y2 < 4; y2++) + for ( int x2 = 0; x2 < 4; x2++ ) + out[(y1*4+y2)*16+(x1*4+x2)] = in[readPos++]; } Land::Land() @@ -175,56 +169,42 @@ void Land::loadData() if (mEsm->isNextSub("VNML")) { mEsm->getHExact(mLandData->mNormals, sizeof(VNML)); - }/* - if (mEsm->isNextSub("VNML")) - { - mEsm->skipHSubSize(12675); - } */ + } if (mEsm->isNextSub("VHGT")) { - VHGT rawHeights; + VHGT rawHeights; - mEsm->getHExact(&rawHeights, sizeof(VHGT)); - float currentHeightOffset = rawHeights.mHeightOffset; - for (int y = 0; y < LAND_SIZE; y++) - { - currentHeightOffset += rawHeights.mHeightData[y * LAND_SIZE]; - mLandData->mHeights[y * LAND_SIZE] = currentHeightOffset * HEIGHT_SCALE; - - float tempOffset = currentHeightOffset; - for (int x = 1; x < LAND_SIZE; x++) + mEsm->getHExact(&rawHeights, sizeof(VHGT)); + float currentHeightOffset = rawHeights.mHeightOffset; + for (int y = 0; y < LAND_SIZE; y++) { - tempOffset += rawHeights.mHeightData[y * LAND_SIZE + x]; - mLandData->mHeights[x + y * LAND_SIZE] = tempOffset * HEIGHT_SCALE; + currentHeightOffset += rawHeights.mHeightData[y * LAND_SIZE]; + mLandData->mHeights[y * LAND_SIZE] = currentHeightOffset * HEIGHT_SCALE; + + float tempOffset = currentHeightOffset; + for (int x = 1; x < LAND_SIZE; x++) + { + tempOffset += rawHeights.mHeightData[y * LAND_SIZE + x]; + mLandData->mHeights[x + y * LAND_SIZE] = tempOffset * HEIGHT_SCALE; + } } - } - mLandData->mUnk1 = rawHeights.mUnknown1; - mLandData->mUnk2 = rawHeights.mUnknown2; + mLandData->mUnk1 = rawHeights.mUnk1; + mLandData->mUnk2 = rawHeights.mUnk2; } - if (mEsm->isNextSub("WNAM")) - { + if (mEsm->isNextSub("WNAM")) { mEsm->getHExact(mLandData->mWnam, 81); } - if (mEsm->isNextSub("VCLR")) - { + if (mEsm->isNextSub("VCLR")) { mLandData->mUsingColours = true; mEsm->getHExact(&mLandData->mColours, 3*LAND_NUM_VERTS); - }else{ + } else { mLandData->mUsingColours = false; } - if (mEsm->isNextSub("VTEX")) - { - //TODO fix magic numbers - uint16_t vtex[256]; - mEsm->getHExact(&vtex, 512); - - int readPos = 0; //bit ugly, but it works - for ( int y1 = 0; y1 < 4; y1++ ) - for ( int x1 = 0; x1 < 4; x1++ ) - for ( int y2 = 0; y2 < 4; y2++) - for ( int x2 = 0; x2 < 4; x2++ ) - mLandData->mTextures[(y1*4+y2)*16+(x1*4+x2)] = vtex[readPos++]; + if (mEsm->isNextSub("VTEX")) { + static uint16_t vtex[LAND_NUM_TEXTURES]; + mEsm->getHExact(&vtex, sizeof(vtex)); + LandData::transposeTextureData(vtex, mLandData->mTextures); } } else diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index f51ccc780..830f74c71 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -61,8 +61,8 @@ struct Land : public Record { float mHeightOffset; int8_t mHeightData[LAND_NUM_VERTS]; - short mUnknown1; - char mUnknown2; + short mUnk1; + char mUnk2; }; #pragma pack(pop) @@ -84,6 +84,7 @@ struct Land : public Record uint8_t mUnk2; void save(ESMWriter &esm); + static void transposeTextureData(uint16_t *in, uint16_t *out); }; LandData *mLandData; From 2d5ddd104bdea09687b6e0ff91492de544fa05e4 Mon Sep 17 00:00:00 2001 From: greye Date: Fri, 21 Sep 2012 12:12:16 +0400 Subject: [PATCH 19/48] Land::loadData rework --- apps/openmw/mwrender/terrain.cpp | 9 ++- components/esm/loadland.cpp | 132 +++++++++++++++++-------------- components/esm/loadland.hpp | 15 +++- 3 files changed, 90 insertions(+), 66 deletions(-) diff --git a/apps/openmw/mwrender/terrain.cpp b/apps/openmw/mwrender/terrain.cpp index 35e2344e9..114a9bc37 100644 --- a/apps/openmw/mwrender/terrain.cpp +++ b/apps/openmw/mwrender/terrain.cpp @@ -99,9 +99,10 @@ namespace MWRender if (land == NULL) // no land data means we're not going to create any terrain. return; - if (!land->mDataLoaded) + int dataRequired = ESM::Land::DATA_VHGT | ESM::Land::DATA_VCLR; + if (!land->isDataLoaded(dataRequired)) { - land->loadData(); + land->loadData(dataRequired); } //split the cell terrain into four segments @@ -413,9 +414,9 @@ namespace MWRender ESM::Land* land = MWBase::Environment::get().getWorld()->getStore().lands.search(cellX, cellY); if ( land != NULL ) { - if (!land->mDataLoaded) + if (!land->isDataLoaded(ESM::Land::DATA_VTEX)) { - land->loadData(); + land->loadData(ESM::Land::DATA_VTEX); } return land->mLandData diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index 47f238242..0107e80ef 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -12,7 +12,7 @@ void Land::LandData::save(ESMWriter &esm) esm.writeHNT("VNML", mNormals, sizeof(VNML)); } if (mDataTypes & Land::DATA_VHGT) { - VHGT offsets; + static VHGT offsets; offsets.mHeightOffset = mHeights[0] / HEIGHT_SCALE; offsets.mUnk1 = mUnk1; offsets.mUnk2 = mUnk2; @@ -124,9 +124,9 @@ void Land::load(ESMReader &esm) // We need all three of VNML, VHGT and VTEX in order to use the // landscape. (Though Morrowind seems to accept terrain without VTEX/VCLR entries) - mHasData = mDataTypes & (DATA_VNML|DATA_VHGT|DATA_WNAM|DATA_VTEX|DATA_VCLR); + mHasData = mDataTypes & (DATA_VNML|DATA_VHGT|DATA_WNAM); - mDataLoaded = false; + mDataLoaded = 0; mLandData = NULL; } @@ -141,10 +141,10 @@ void Land::save(ESMWriter &esm) // TODO: Land! bool wasLoaded = mDataLoaded; - if (mHasData) - loadData(); // I think it might be a good idea to have - // the data loaded before trying to save it - + if (mDataTypes) { + // Try to load all available data before saving + loadData(mDataTypes); + } if (mDataLoaded) mLandData->save(esm); @@ -152,73 +152,71 @@ void Land::save(ESMWriter &esm) unloadData(); // Don't need to keep the data loaded if it wasn't already } -void Land::loadData() +/// \todo remove memory allocation when only defaults needed +void Land::loadData(int flags) { - if (mDataLoaded) - { + // Try to load only available data + int actual = flags & mDataTypes; + // Return if all required data is loaded + if (flags == 0 || (actual != 0 && (mDataLoaded & actual) == actual)) { return; } + // Create storage if nothing is loaded + if (mLandData == NULL) { + mLandData = new LandData; + mLandData->mDataTypes = mDataTypes; + } + mEsm->restoreContext(mContext); - mLandData = new LandData; - - if (mHasData) - { - mEsm->restoreContext(mContext); - - memset(mLandData->mNormals, 0, LAND_NUM_VERTS * 3); + memset(mLandData->mNormals, 0, LAND_NUM_VERTS * 3); - if (mEsm->isNextSub("VNML")) { - mEsm->getHExact(mLandData->mNormals, sizeof(VNML)); - } + if (mEsm->isNextSub("VNML")) { + condLoad(actual, DATA_VNML, mLandData->mNormals, sizeof(VNML)); + } - if (mEsm->isNextSub("VHGT")) { - VHGT rawHeights; + if (mEsm->isNextSub("VHGT")) { + static VHGT vhgt; + if (condLoad(actual, DATA_VHGT, &vhgt, sizeof(vhgt))) { + float rowOffset = vhgt.mHeightOffset; + for (int y = 0; y < LAND_SIZE; y++) { + rowOffset += vhgt.mHeightData[y * LAND_SIZE]; - mEsm->getHExact(&rawHeights, sizeof(VHGT)); - float currentHeightOffset = rawHeights.mHeightOffset; - for (int y = 0; y < LAND_SIZE; y++) - { - currentHeightOffset += rawHeights.mHeightData[y * LAND_SIZE]; - mLandData->mHeights[y * LAND_SIZE] = currentHeightOffset * HEIGHT_SCALE; + mLandData->mHeights[y * LAND_SIZE] = rowOffset * HEIGHT_SCALE; - float tempOffset = currentHeightOffset; - for (int x = 1; x < LAND_SIZE; x++) - { - tempOffset += rawHeights.mHeightData[y * LAND_SIZE + x]; - mLandData->mHeights[x + y * LAND_SIZE] = tempOffset * HEIGHT_SCALE; + float colOffset = rowOffset; + for (int x = 1; x < LAND_SIZE; x++) { + colOffset += vhgt.mHeightData[y * LAND_SIZE + x]; + mLandData->mHeights[x + y * LAND_SIZE] = colOffset * HEIGHT_SCALE; } } - mLandData->mUnk1 = rawHeights.mUnk1; - mLandData->mUnk2 = rawHeights.mUnk2; + mLandData->mUnk1 = vhgt.mUnk1; + mLandData->mUnk2 = vhgt.mUnk2; } - - if (mEsm->isNextSub("WNAM")) { - mEsm->getHExact(mLandData->mWnam, 81); - } - if (mEsm->isNextSub("VCLR")) { - mLandData->mUsingColours = true; - mEsm->getHExact(&mLandData->mColours, 3*LAND_NUM_VERTS); - } else { - mLandData->mUsingColours = false; - } - if (mEsm->isNextSub("VTEX")) { - static uint16_t vtex[LAND_NUM_TEXTURES]; - mEsm->getHExact(&vtex, sizeof(vtex)); - LandData::transposeTextureData(vtex, mLandData->mTextures); - } - } - else - { - mLandData->mUsingColours = false; - memset(mLandData->mTextures, 0, sizeof(mLandData->mTextures)); - for (int i = 0; i < LAND_NUM_VERTS; i++) - { + } else if ((flags & DATA_VHGT) && (mDataLoaded & DATA_VHGT) == 0) { + for (int i = 0; i < LAND_NUM_VERTS; ++i) { mLandData->mHeights[i] = -256.0f * HEIGHT_SCALE; } + mDataLoaded |= DATA_VHGT; } - mLandData->mDataTypes = mDataTypes; - mDataLoaded = true; + if (mEsm->isNextSub("WNAM")) { + condLoad(actual, DATA_WNAM, mLandData->mWnam, 81); + } + if (mEsm->isNextSub("VCLR")) { + mLandData->mUsingColours = true; + condLoad(actual, DATA_VCLR, mLandData->mColours, 3 * LAND_NUM_VERTS); + } else { + mLandData->mUsingColours = false; + } + if (mEsm->isNextSub("VTEX")) { + static uint16_t vtex[LAND_NUM_TEXTURES]; + if (condLoad(actual, DATA_VTEX, vtex, sizeof(vtex))) { + LandData::transposeTextureData(vtex, mLandData->mTextures); + } + } else if ((flags & DATA_VTEX) && (mDataLoaded & DATA_VTEX) == 0) { + memset(mLandData->mTextures, 0, sizeof(mLandData->mTextures)); + mDataLoaded |= DATA_VTEX; + } } void Land::unloadData() @@ -227,8 +225,22 @@ void Land::unloadData() { delete mLandData; mLandData = NULL; - mDataLoaded = false; + mDataLoaded = 0; } } +bool Land::condLoad(int flags, int dataFlag, void *ptr, unsigned int size) +{ + if ((mDataLoaded & dataFlag) != 0) { + return false; + } + if (flags & dataFlag) { + mEsm->getHExact(ptr, size); + mDataLoaded |= dataFlag; + return true; + } + mEsm->skipHSubSize(size); + return false; +} + } diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index 830f74c71..46534c826 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -28,7 +28,7 @@ struct Land : public Record bool mHasData; int mDataTypes; - bool mDataLoaded; + int mDataLoaded; enum { @@ -97,16 +97,27 @@ struct Land : public Record /** * Actually loads data */ - void loadData(); + void loadData(int flags); /** * Frees memory allocated for land data */ void unloadData(); + /// Check if given data type is loaded + /// \todo reimplement this + bool isDataLoaded(int flags) { + return (mDataLoaded & flags) == flags; + } + private: Land(const Land& land); Land& operator=(const Land& land); + + /// Loads data and marks it as loaded + /// \return true if data is actually loaded from file, false otherwise + /// including the case when data is already loaded + bool condLoad(int flags, int dataFlag, void *ptr, unsigned int size); }; } From 09195894cff2bda6e79949f79ac5c35382c5123f Mon Sep 17 00:00:00 2001 From: greye Date: Fri, 21 Sep 2012 12:30:08 +0400 Subject: [PATCH 20/48] restore INGR and MGEF --- components/esm/loadingr.cpp | 2 -- components/esm/loadmgef.cpp | 10 ++++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/components/esm/loadingr.cpp b/components/esm/loadingr.cpp index 13d66a632..e39d12a4e 100644 --- a/components/esm/loadingr.cpp +++ b/components/esm/loadingr.cpp @@ -13,7 +13,6 @@ void Ingredient::load(ESMReader &esm) esm.getHNT(mData, "IRDT", 56); mScript = esm.getHNOString("SCRI"); mIcon = esm.getHNOString("ITEX"); -/* // horrible hack to fix broken data in records for (int i=0; i<4; ++i) { @@ -36,7 +35,6 @@ void Ingredient::load(ESMReader &esm) mData.mSkills[i] = -1; } } -*/ } void Ingredient::save(ESMWriter &esm) diff --git a/components/esm/loadmgef.cpp b/components/esm/loadmgef.cpp index c18833e01..bcd1dfaf5 100644 --- a/components/esm/loadmgef.cpp +++ b/components/esm/loadmgef.cpp @@ -3,6 +3,8 @@ #include "esm_reader.hpp" #include "esm_writer.hpp" +#include + namespace { const int NumberOfHardcodedFlags = 143; @@ -36,10 +38,9 @@ void MagicEffect::load(ESMReader &esm) esm.getHNT(mIndex, "INDX"); esm.getHNT(mData, "MEDT", 36); -/* if (mIndex>=0 && mIndex=0 && mIndex Date: Sun, 23 Sep 2012 19:29:00 +0400 Subject: [PATCH 21/48] fix dynamic potion id --- apps/openmw/mwworld/worldimp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 5e2ca4605..0cdb2b528 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -776,7 +776,7 @@ namespace MWWorld stream << "$dynamic" << mNextDynamicRecord++; ESM::Potion record2 (record); - record2.getId() = stream.str(); + record2.setId(stream.str()); const ESM::Potion *created = &mStore.potions.list.insert (std::make_pair (stream.str(), record2)).first->second; From c54750977f22c7bace3dee97199d359b8d8f6a42 Mon Sep 17 00:00:00 2001 From: greye Date: Sun, 23 Sep 2012 22:11:08 +0400 Subject: [PATCH 22/48] remove underscores in guards --- components/esm/attr.hpp | 4 ++-- components/esm/defs.hpp | 4 ++-- components/esm/esm_common.hpp | 4 ++-- components/esm/esm_reader.hpp | 4 ++-- components/esm/esm_writer.hpp | 4 ++-- components/esm/loadacti.hpp | 4 ++-- components/esm/loadalch.hpp | 4 ++-- components/esm/loadappa.hpp | 4 ++-- components/esm/loadarmo.hpp | 4 ++-- components/esm/loadbody.hpp | 4 ++-- components/esm/loadbook.hpp | 4 ++-- components/esm/loadbsgn.hpp | 4 ++-- components/esm/loadcell.hpp | 4 ++-- components/esm/loadclas.hpp | 4 ++-- components/esm/loadclot.hpp | 4 ++-- components/esm/loadcont.hpp | 4 ++-- components/esm/loadcrea.hpp | 4 ++-- components/esm/loadcrec.hpp | 4 ++-- components/esm/loaddial.hpp | 4 ++-- components/esm/loaddoor.hpp | 4 ++-- components/esm/loadench.hpp | 4 ++-- components/esm/loadfact.hpp | 4 ++-- components/esm/loadglob.hpp | 4 ++-- components/esm/loadgmst.hpp | 4 ++-- components/esm/loadinfo.hpp | 4 ++-- components/esm/loadingr.hpp | 4 ++-- components/esm/loadland.hpp | 4 ++-- components/esm/loadlevlist.hpp | 4 ++-- components/esm/loadligh.hpp | 4 ++-- components/esm/loadlocks.hpp | 4 ++-- components/esm/loadltex.hpp | 4 ++-- components/esm/loadmgef.hpp | 4 ++-- components/esm/loadmisc.hpp | 4 ++-- components/esm/loadnpc.hpp | 4 ++-- components/esm/loadnpcc.hpp | 4 ++-- components/esm/loadpgrd.hpp | 4 ++-- components/esm/loadrace.hpp | 4 ++-- components/esm/loadregn.hpp | 4 ++-- components/esm/loadscpt.hpp | 4 ++-- components/esm/loadskil.hpp | 4 ++-- components/esm/loadsndg.hpp | 4 ++-- components/esm/loadsoun.hpp | 4 ++-- components/esm/loadspel.hpp | 4 ++-- components/esm/loadsscr.hpp | 4 ++-- components/esm/loadstat.hpp | 4 ++-- components/esm/loadweap.hpp | 4 ++-- components/esm/record.hpp | 4 ++-- components/esm/records.hpp | 4 ++-- 48 files changed, 96 insertions(+), 96 deletions(-) diff --git a/components/esm/attr.hpp b/components/esm/attr.hpp index 867f95681..2ed9b4f41 100644 --- a/components/esm/attr.hpp +++ b/components/esm/attr.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_ATTR_H -#define _ESM_ATTR_H +#ifndef OPENMW_ESM_ATTR_H +#define OPENMW_ESM_ATTR_H #include diff --git a/components/esm/defs.hpp b/components/esm/defs.hpp index 622bcd6e1..0a8f95108 100644 --- a/components/esm/defs.hpp +++ b/components/esm/defs.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_DEFS_H -#define _ESM_DEFS_H +#ifndef OPENMW_ESM_DEFS_H +#define OPENMW_ESM_DEFS_H #include diff --git a/components/esm/esm_common.hpp b/components/esm/esm_common.hpp index 59c0fde7b..eb16e3768 100644 --- a/components/esm/esm_common.hpp +++ b/components/esm/esm_common.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_COMMON_H -#define _ESM_COMMON_H +#ifndef OPENMW_ESM_COMMON_H +#define OPENMW_ESM_COMMON_H #include #include diff --git a/components/esm/esm_reader.hpp b/components/esm/esm_reader.hpp index 14847307a..fe96f37ae 100644 --- a/components/esm/esm_reader.hpp +++ b/components/esm/esm_reader.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_READER_H -#define _ESM_READER_H +#ifndef OPENMW_ESM_READER_H +#define OPENMW_ESM_READER_H #include #include diff --git a/components/esm/esm_writer.hpp b/components/esm/esm_writer.hpp index 6eb34a97c..6a3382b8f 100644 --- a/components/esm/esm_writer.hpp +++ b/components/esm/esm_writer.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_WRITER_H -#define _ESM_WRITER_H +#ifndef OPENMW_ESM_WRITER_H +#define OPENMW_ESM_WRITER_H #include #include diff --git a/components/esm/loadacti.hpp b/components/esm/loadacti.hpp index a58fc4e98..c1a630ab8 100644 --- a/components/esm/loadacti.hpp +++ b/components/esm/loadacti.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_ACTI_H -#define _ESM_ACTI_H +#ifndef OPENMW_ESM_ACTI_H +#define OPENMW_ESM_ACTI_H #include "record.hpp" diff --git a/components/esm/loadalch.hpp b/components/esm/loadalch.hpp index 780fbc6c0..4d21b3b58 100644 --- a/components/esm/loadalch.hpp +++ b/components/esm/loadalch.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_ALCH_H -#define _ESM_ALCH_H +#ifndef OPENMW_ESM_ALCH_H +#define OPENMW_ESM_ALCH_H #include diff --git a/components/esm/loadappa.hpp b/components/esm/loadappa.hpp index 0a2fcda3a..e0850231f 100644 --- a/components/esm/loadappa.hpp +++ b/components/esm/loadappa.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_APPA_H -#define _ESM_APPA_H +#ifndef OPENMW_ESM_APPA_H +#define OPENMW_ESM_APPA_H #include "record.hpp" diff --git a/components/esm/loadarmo.hpp b/components/esm/loadarmo.hpp index 95717bfc0..1adfd4fbc 100644 --- a/components/esm/loadarmo.hpp +++ b/components/esm/loadarmo.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_ARMO_H -#define _ESM_ARMO_H +#ifndef OPENMW_ESM_ARMO_H +#define OPENMW_ESM_ARMO_H #include #include diff --git a/components/esm/loadbody.hpp b/components/esm/loadbody.hpp index 02fc723f5..d07a78fc8 100644 --- a/components/esm/loadbody.hpp +++ b/components/esm/loadbody.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_BODY_H -#define _ESM_BODY_H +#ifndef OPENMW_ESM_BODY_H +#define OPENMW_ESM_BODY_H #include "record.hpp" diff --git a/components/esm/loadbook.hpp b/components/esm/loadbook.hpp index 7428a1e70..8102b2dc1 100644 --- a/components/esm/loadbook.hpp +++ b/components/esm/loadbook.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_BOOK_H -#define _ESM_BOOK_H +#ifndef OPENMW_ESM_BOOK_H +#define OPENMW_ESM_BOOK_H #include "record.hpp" diff --git a/components/esm/loadbsgn.hpp b/components/esm/loadbsgn.hpp index 2b48bf3ea..cd8a1c753 100644 --- a/components/esm/loadbsgn.hpp +++ b/components/esm/loadbsgn.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_BSGN_H -#define _ESM_BSGN_H +#ifndef OPENMW_ESM_BSGN_H +#define OPENMW_ESM_BSGN_H #include diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index b9d85cb9e..3d1369637 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_CELL_H -#define _ESM_CELL_H +#ifndef OPENMW_ESM_CELL_H +#define OPENMW_ESM_CELL_H #include diff --git a/components/esm/loadclas.hpp b/components/esm/loadclas.hpp index ce03c4925..556892585 100644 --- a/components/esm/loadclas.hpp +++ b/components/esm/loadclas.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_CLAS_H -#define _ESM_CLAS_H +#ifndef OPENMW_ESM_CLAS_H +#define OPENMW_ESM_CLAS_H #include diff --git a/components/esm/loadclot.hpp b/components/esm/loadclot.hpp index 70588c769..a27953c6e 100644 --- a/components/esm/loadclot.hpp +++ b/components/esm/loadclot.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_CLOT_H -#define _ESM_CLOT_H +#ifndef OPENMW_ESM_CLOT_H +#define OPENMW_ESM_CLOT_H #include diff --git a/components/esm/loadcont.hpp b/components/esm/loadcont.hpp index 25eb8427d..e8384a8d4 100644 --- a/components/esm/loadcont.hpp +++ b/components/esm/loadcont.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_CONT_H -#define _ESM_CONT_H +#ifndef OPENMW_ESM_CONT_H +#define OPENMW_ESM_CONT_H #include #include diff --git a/components/esm/loadcrea.hpp b/components/esm/loadcrea.hpp index c18b78e9c..262bc92dd 100644 --- a/components/esm/loadcrea.hpp +++ b/components/esm/loadcrea.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_CREA_H -#define _ESM_CREA_H +#ifndef OPENMW_ESM_CREA_H +#define OPENMW_ESM_CREA_H #include diff --git a/components/esm/loadcrec.hpp b/components/esm/loadcrec.hpp index 5552478f4..b0e8dccd1 100644 --- a/components/esm/loadcrec.hpp +++ b/components/esm/loadcrec.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_CREC_H -#define _ESM_CREC_H +#ifndef OPENMW_ESM_CREC_H +#define OPENMW_ESM_CREC_H #include "record.hpp" diff --git a/components/esm/loaddial.hpp b/components/esm/loaddial.hpp index 7bf6503c2..ccf2ebb44 100644 --- a/components/esm/loaddial.hpp +++ b/components/esm/loaddial.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_DIAL_H -#define _ESM_DIAL_H +#ifndef OPENMW_ESM_DIAL_H +#define OPENMW_ESM_DIAL_H #include diff --git a/components/esm/loaddoor.hpp b/components/esm/loaddoor.hpp index 5e544b4c6..37ec5fdd3 100644 --- a/components/esm/loaddoor.hpp +++ b/components/esm/loaddoor.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_DOOR_H -#define _ESM_DOOR_H +#ifndef OPENMW_ESM_DOOR_H +#define OPENMW_ESM_DOOR_H #include diff --git a/components/esm/loadench.hpp b/components/esm/loadench.hpp index 6431a40f6..81486c390 100644 --- a/components/esm/loadench.hpp +++ b/components/esm/loadench.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_ENCH_H -#define _ESM_ENCH_H +#ifndef OPENMW_ESM_ENCH_H +#define OPENMW_ESM_ENCH_H #include "record.hpp" #include "effectlist.hpp" diff --git a/components/esm/loadfact.hpp b/components/esm/loadfact.hpp index cb0f12eff..f5a6f05d7 100644 --- a/components/esm/loadfact.hpp +++ b/components/esm/loadfact.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_FACT_H -#define _ESM_FACT_H +#ifndef OPENMW_ESM_FACT_H +#define OPENMW_ESM_FACT_H #include #include diff --git a/components/esm/loadglob.hpp b/components/esm/loadglob.hpp index b5ae6452f..2aceaae59 100644 --- a/components/esm/loadglob.hpp +++ b/components/esm/loadglob.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_GLOB_H -#define _ESM_GLOB_H +#ifndef OPENMW_ESM_GLOB_H +#define OPENMW_ESM_GLOB_H #include "record.hpp" #include "defs.hpp" diff --git a/components/esm/loadgmst.hpp b/components/esm/loadgmst.hpp index c9dc8d5c1..c99ec5fd1 100644 --- a/components/esm/loadgmst.hpp +++ b/components/esm/loadgmst.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_GMST_H -#define _ESM_GMST_H +#ifndef OPENMW_ESM_GMST_H +#define OPENMW_ESM_GMST_H #include diff --git a/components/esm/loadinfo.hpp b/components/esm/loadinfo.hpp index ff923b597..085aabb24 100644 --- a/components/esm/loadinfo.hpp +++ b/components/esm/loadinfo.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_INFO_H -#define _ESM_INFO_H +#ifndef OPENMW_ESM_INFO_H +#define OPENMW_ESM_INFO_H #include #include diff --git a/components/esm/loadingr.hpp b/components/esm/loadingr.hpp index 0a88296c1..4c4b40443 100644 --- a/components/esm/loadingr.hpp +++ b/components/esm/loadingr.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_INGR_H -#define _ESM_INGR_H +#ifndef OPENMW_ESM_INGR_H +#define OPENMW_ESM_INGR_H #include diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index 46534c826..3149dfcb7 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_LAND_H -#define _ESM_LAND_H +#ifndef OPENMW_ESM_LAND_H +#define OPENMW_ESM_LAND_H #include diff --git a/components/esm/loadlevlist.hpp b/components/esm/loadlevlist.hpp index 8eb65c7e2..6d420d68b 100644 --- a/components/esm/loadlevlist.hpp +++ b/components/esm/loadlevlist.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_LEVLISTS_H -#define _ESM_LEVLISTS_H +#ifndef OPENMW_ESM_LEVLISTS_H +#define OPENMW_ESM_LEVLISTS_H #include #include diff --git a/components/esm/loadligh.hpp b/components/esm/loadligh.hpp index c560eaef3..626dd06e4 100644 --- a/components/esm/loadligh.hpp +++ b/components/esm/loadligh.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_LIGH_H -#define _ESM_LIGH_H +#ifndef OPENMW_ESM_LIGH_H +#define OPENMW_ESM_LIGH_H #include diff --git a/components/esm/loadlocks.hpp b/components/esm/loadlocks.hpp index e1bb7e1cb..f30b0c4f1 100644 --- a/components/esm/loadlocks.hpp +++ b/components/esm/loadlocks.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_LOCKS_H -#define _ESM_LOCKS_H +#ifndef OPENMW_ESM_LOCKS_H +#define OPENMW_ESM_LOCKS_H #include "record.hpp" diff --git a/components/esm/loadltex.hpp b/components/esm/loadltex.hpp index 0914f4a32..8ac0da155 100644 --- a/components/esm/loadltex.hpp +++ b/components/esm/loadltex.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_LTEX_H -#define _ESM_LTEX_H +#ifndef OPENMW_ESM_LTEX_H +#define OPENMW_ESM_LTEX_H #include diff --git a/components/esm/loadmgef.hpp b/components/esm/loadmgef.hpp index 06641d981..caa983d6b 100644 --- a/components/esm/loadmgef.hpp +++ b/components/esm/loadmgef.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_MGEF_H -#define _ESM_MGEF_H +#ifndef OPENMW_ESM_MGEF_H +#define OPENMW_ESM_MGEF_H #include diff --git a/components/esm/loadmisc.hpp b/components/esm/loadmisc.hpp index fe94aa69a..3e0d5db64 100644 --- a/components/esm/loadmisc.hpp +++ b/components/esm/loadmisc.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_MISC_H -#define _ESM_MISC_H +#ifndef OPENMW_ESM_MISC_H +#define OPENMW_ESM_MISC_H #include diff --git a/components/esm/loadnpc.hpp b/components/esm/loadnpc.hpp index 62366e5f9..f9b579f4f 100644 --- a/components/esm/loadnpc.hpp +++ b/components/esm/loadnpc.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_NPC_H -#define _ESM_NPC_H +#ifndef OPENMW_ESM_NPC_H +#define OPENMW_ESM_NPC_H #include #include diff --git a/components/esm/loadnpcc.hpp b/components/esm/loadnpcc.hpp index 87e85024a..3641c0fa9 100644 --- a/components/esm/loadnpcc.hpp +++ b/components/esm/loadnpcc.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_NPCC_H -#define _ESM_NPCC_H +#ifndef OPENMW_ESM_NPCC_H +#define OPENMW_ESM_NPCC_H #include "record.hpp" diff --git a/components/esm/loadpgrd.hpp b/components/esm/loadpgrd.hpp index 448be3ec7..3d8fb5ccd 100644 --- a/components/esm/loadpgrd.hpp +++ b/components/esm/loadpgrd.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_PGRD_H -#define _ESM_PGRD_H +#ifndef OPENMW_ESM_PGRD_H +#define OPENMW_ESM_PGRD_H #include #include diff --git a/components/esm/loadrace.hpp b/components/esm/loadrace.hpp index 418949ce5..bd7096a4c 100644 --- a/components/esm/loadrace.hpp +++ b/components/esm/loadrace.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_RACE_H -#define _ESM_RACE_H +#ifndef OPENMW_ESM_RACE_H +#define OPENMW_ESM_RACE_H #include diff --git a/components/esm/loadregn.hpp b/components/esm/loadregn.hpp index 0a0349bab..ae78b2004 100644 --- a/components/esm/loadregn.hpp +++ b/components/esm/loadregn.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_REGN_H -#define _ESM_REGN_H +#ifndef OPENMW_ESM_REGN_H +#define OPENMW_ESM_REGN_H #include #include diff --git a/components/esm/loadscpt.hpp b/components/esm/loadscpt.hpp index 8a6ea1194..4c273fbe2 100644 --- a/components/esm/loadscpt.hpp +++ b/components/esm/loadscpt.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_SCPT_H -#define _ESM_SCPT_H +#ifndef OPENMW_ESM_SCPT_H +#define OPENMW_ESM_SCPT_H #include #include diff --git a/components/esm/loadskil.hpp b/components/esm/loadskil.hpp index 05c89d627..a6716dc27 100644 --- a/components/esm/loadskil.hpp +++ b/components/esm/loadskil.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_SKIL_H -#define _ESM_SKIL_H +#ifndef OPENMW_ESM_SKIL_H +#define OPENMW_ESM_SKIL_H #include diff --git a/components/esm/loadsndg.hpp b/components/esm/loadsndg.hpp index 2a46febb9..e58f2eb0c 100644 --- a/components/esm/loadsndg.hpp +++ b/components/esm/loadsndg.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_SNDG_H -#define _ESM_SNDG_H +#ifndef OPENMW_ESM_SNDG_H +#define OPENMW_ESM_SNDG_H #include diff --git a/components/esm/loadsoun.hpp b/components/esm/loadsoun.hpp index b560e6995..d4647bd08 100644 --- a/components/esm/loadsoun.hpp +++ b/components/esm/loadsoun.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_SOUN_H -#define _ESM_SOUN_H +#ifndef OPENMW_ESM_SOUN_H +#define OPENMW_ESM_SOUN_H #include diff --git a/components/esm/loadspel.hpp b/components/esm/loadspel.hpp index d9c02d14a..9f557a9b2 100644 --- a/components/esm/loadspel.hpp +++ b/components/esm/loadspel.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_SPEL_H -#define _ESM_SPEL_H +#ifndef OPENMW_ESM_SPEL_H +#define OPENMW_ESM_SPEL_H #include diff --git a/components/esm/loadsscr.hpp b/components/esm/loadsscr.hpp index 77fbd00f9..2b87f7621 100644 --- a/components/esm/loadsscr.hpp +++ b/components/esm/loadsscr.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_SSCR_H -#define _ESM_SSCR_H +#ifndef OPENMW_ESM_SSCR_H +#define OPENMW_ESM_SSCR_H #include diff --git a/components/esm/loadstat.hpp b/components/esm/loadstat.hpp index 783b6404c..2a51fa7a7 100644 --- a/components/esm/loadstat.hpp +++ b/components/esm/loadstat.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_STAT_H -#define _ESM_STAT_H +#ifndef OPENMW_ESM_STAT_H +#define OPENMW_ESM_STAT_H #include diff --git a/components/esm/loadweap.hpp b/components/esm/loadweap.hpp index 0db851dcd..2a6439f8f 100644 --- a/components/esm/loadweap.hpp +++ b/components/esm/loadweap.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_WEAP_H -#define _ESM_WEAP_H +#ifndef OPENMW_ESM_WEAP_H +#define OPENMW_ESM_WEAP_H #include diff --git a/components/esm/record.hpp b/components/esm/record.hpp index 9ab1942ff..3e5330681 100644 --- a/components/esm/record.hpp +++ b/components/esm/record.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_RECORD_H -#define _ESM_RECORD_H +#ifndef OPENMW_ESM_RECORD_H +#define OPENMW_ESM_RECORD_H #include diff --git a/components/esm/records.hpp b/components/esm/records.hpp index e05f74f5d..97b7cb4a7 100644 --- a/components/esm/records.hpp +++ b/components/esm/records.hpp @@ -1,5 +1,5 @@ -#ifndef _ESM_RECORDS_H -#define _ESM_RECORDS_H +#ifndef OPENMW_ESM_RECORDS_H +#define OPENMW_ESM_RECORDS_H #include "record.hpp" #include "loadacti.hpp" From 7368e7b6550d4a6a0fc124cbcc6e3e79eba4bd16 Mon Sep 17 00:00:00 2001 From: greye Date: Sun, 23 Sep 2012 22:20:18 +0400 Subject: [PATCH 23/48] rename getASCII() to getLegacyEnc() --- components/esm/esm_writer.cpp | 2 +- components/to_utf8/to_utf8.cpp | 2 +- components/to_utf8/to_utf8.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/esm/esm_writer.cpp b/components/esm/esm_writer.cpp index 5bb9e286d..113f31ae9 100644 --- a/components/esm/esm_writer.cpp +++ b/components/esm/esm_writer.cpp @@ -162,7 +162,7 @@ void ESMWriter::writeHString(const std::string& data) ptr[data.size()] = '\0'; // Convert to UTF8 and return - std::string ascii = ToUTF8::getASCII(m_encoding); + std::string ascii = ToUTF8::getLegacyEnc(m_encoding); write(ascii.c_str(), ascii.size()); } diff --git a/components/to_utf8/to_utf8.cpp b/components/to_utf8/to_utf8.cpp index 0c7ea388e..6f0ed8bfd 100644 --- a/components/to_utf8/to_utf8.cpp +++ b/components/to_utf8/to_utf8.cpp @@ -291,7 +291,7 @@ static void copyFromArray2(const char *arr, char*& chp, char* &out) *(out++) = ch; // Could not find glyph, just put whatever } -std::string ToUTF8::getASCII(ToUTF8::FromType to) +std::string ToUTF8::getLegacyEnc(ToUTF8::FromType to) { // Pick translation array const char *arr; diff --git a/components/to_utf8/to_utf8.hpp b/components/to_utf8/to_utf8.hpp index 1a6a077be..69e9fc92c 100644 --- a/components/to_utf8/to_utf8.hpp +++ b/components/to_utf8/to_utf8.hpp @@ -21,7 +21,7 @@ namespace ToUTF8 // Convert the previously written buffer to UTF8 from the given code // page. std::string getUtf8(FromType from); - std::string getASCII(FromType to); + std::string getLegacyEnc(FromType to); } #endif From 13397878635b3a7d3bbaf1a9bbc1ab0be4507bcb Mon Sep 17 00:00:00 2001 From: greye Date: Sun, 23 Sep 2012 22:41:41 +0400 Subject: [PATCH 24/48] remove underscores from filenames in esm --- apps/esmtool/esmtool.cpp | 4 ++-- apps/launcher/datafilespage.cpp | 2 +- components/CMakeLists.txt | 2 +- components/esm/aipackage.cpp | 4 ++-- components/esm/aipackage.hpp | 2 +- components/esm/effectlist.cpp | 4 ++-- components/esm/{esm_common.hpp => esmcommon.hpp} | 0 components/esm/{esm_reader.cpp => esmreader.cpp} | 2 +- components/esm/{esm_reader.hpp => esmreader.hpp} | 2 +- components/esm/{esm_writer.cpp => esmwriter.cpp} | 2 +- components/esm/{esm_writer.hpp => esmwriter.hpp} | 2 +- components/esm/loadacti.cpp | 4 ++-- components/esm/loadalch.cpp | 4 ++-- components/esm/loadappa.cpp | 4 ++-- components/esm/loadarmo.cpp | 4 ++-- components/esm/loadbody.cpp | 4 ++-- components/esm/loadbook.cpp | 4 ++-- components/esm/loadbsgn.cpp | 4 ++-- components/esm/loadcell.cpp | 4 ++-- components/esm/loadcell.hpp | 2 +- components/esm/loadclas.cpp | 4 ++-- components/esm/loadclot.cpp | 4 ++-- components/esm/loadcont.cpp | 4 ++-- components/esm/loadcont.hpp | 2 +- components/esm/loadcrea.cpp | 4 ++-- components/esm/loadcrec.hpp | 2 +- components/esm/loaddial.cpp | 4 ++-- components/esm/loaddoor.cpp | 4 ++-- components/esm/loadench.cpp | 4 ++-- components/esm/loadfact.cpp | 4 ++-- components/esm/loadglob.cpp | 4 ++-- components/esm/loadgmst.cpp | 4 ++-- components/esm/loadinfo.cpp | 4 ++-- components/esm/loadingr.cpp | 4 ++-- components/esm/loadland.cpp | 4 ++-- components/esm/loadland.hpp | 2 +- components/esm/loadlevlist.cpp | 4 ++-- components/esm/loadligh.cpp | 4 ++-- components/esm/loadlocks.cpp | 4 ++-- components/esm/loadltex.cpp | 4 ++-- components/esm/loadmgef.cpp | 4 ++-- components/esm/loadmisc.cpp | 4 ++-- components/esm/loadnpc.cpp | 4 ++-- components/esm/loadnpcc.hpp | 2 +- components/esm/loadpgrd.cpp | 4 ++-- components/esm/loadrace.cpp | 4 ++-- components/esm/loadregn.cpp | 4 ++-- components/esm/loadregn.hpp | 2 +- components/esm/loadscpt.cpp | 4 ++-- components/esm/loadscpt.hpp | 2 +- components/esm/loadskil.cpp | 4 ++-- components/esm/loadsndg.cpp | 4 ++-- components/esm/loadsoun.cpp | 4 ++-- components/esm/loadspel.cpp | 4 ++-- components/esm/loadsscr.cpp | 4 ++-- components/esm/loadstat.cpp | 4 ++-- components/esm/loadweap.cpp | 4 ++-- components/esm/spelllist.cpp | 4 ++-- components/terrain/esm_land_factory.cpp | 2 +- 59 files changed, 101 insertions(+), 101 deletions(-) rename components/esm/{esm_common.hpp => esmcommon.hpp} (100%) rename components/esm/{esm_reader.cpp => esmreader.cpp} (99%) rename components/esm/{esm_reader.hpp => esmreader.hpp} (99%) rename components/esm/{esm_writer.cpp => esmwriter.cpp} (99%) rename components/esm/{esm_writer.hpp => esmwriter.hpp} (98%) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index cd0e8e1c1..8d224e8b3 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -4,8 +4,8 @@ #include -#include -#include +#include +#include #include #define ESMTOOL_VERSION 1.1 diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index d32a3b045..8ca3c9aed 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include "datafilespage.hpp" diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 5b547d00c..c714693c3 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -39,7 +39,7 @@ add_component_dir (esm_store ) add_component_dir (esm - attr defs esm_reader esm_writer loadacti loadalch loadappa loadarmo loadbody loadbook loadbsgn loadcell + attr defs esmcommon esmreader esmwriter loadacti loadalch loadappa loadarmo loadbody loadbook loadbsgn loadcell loadclas loadclot loadcont loadcrea loadcrec loaddial loaddoor loadench loadfact loadglob loadgmst loadinfo loadingr loadland loadlevlist loadligh loadlocks loadltex loadmgef loadmisc loadnpcc loadnpc loadpgrd loadrace loadregn loadscpt loadskil loadsndg loadsoun loadspel loadsscr loadstat diff --git a/components/esm/aipackage.cpp b/components/esm/aipackage.cpp index 7cc9cd2e5..1e6220c3a 100644 --- a/components/esm/aipackage.cpp +++ b/components/esm/aipackage.cpp @@ -1,7 +1,7 @@ #include "aipackage.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/aipackage.hpp b/components/esm/aipackage.hpp index 0efc3b61e..3046a6a98 100644 --- a/components/esm/aipackage.hpp +++ b/components/esm/aipackage.hpp @@ -4,7 +4,7 @@ #include #include -#include "esm_common.hpp" +#include "esmcommon.hpp" namespace ESM { diff --git a/components/esm/effectlist.cpp b/components/esm/effectlist.cpp index 187dffc19..88f87d6e2 100644 --- a/components/esm/effectlist.cpp +++ b/components/esm/effectlist.cpp @@ -1,7 +1,7 @@ #include "effectlist.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/esm_common.hpp b/components/esm/esmcommon.hpp similarity index 100% rename from components/esm/esm_common.hpp rename to components/esm/esmcommon.hpp diff --git a/components/esm/esm_reader.cpp b/components/esm/esmreader.cpp similarity index 99% rename from components/esm/esm_reader.cpp rename to components/esm/esmreader.cpp index 95ef46e81..2915a1ce7 100644 --- a/components/esm/esm_reader.cpp +++ b/components/esm/esmreader.cpp @@ -1,4 +1,4 @@ -#include "esm_reader.hpp" +#include "esmreader.hpp" #include namespace ESM diff --git a/components/esm/esm_reader.hpp b/components/esm/esmreader.hpp similarity index 99% rename from components/esm/esm_reader.hpp rename to components/esm/esmreader.hpp index fe96f37ae..6a74c53e8 100644 --- a/components/esm/esm_reader.hpp +++ b/components/esm/esmreader.hpp @@ -12,7 +12,7 @@ #include #include -#include "esm_common.hpp" +#include "esmcommon.hpp" namespace ESM { diff --git a/components/esm/esm_writer.cpp b/components/esm/esmwriter.cpp similarity index 99% rename from components/esm/esm_writer.cpp rename to components/esm/esmwriter.cpp index 113f31ae9..24658a40b 100644 --- a/components/esm/esm_writer.cpp +++ b/components/esm/esmwriter.cpp @@ -1,4 +1,4 @@ -#include "esm_writer.hpp" +#include "esmwriter.hpp" #include #include diff --git a/components/esm/esm_writer.hpp b/components/esm/esmwriter.hpp similarity index 98% rename from components/esm/esm_writer.hpp rename to components/esm/esmwriter.hpp index 6a3382b8f..d3777be81 100644 --- a/components/esm/esm_writer.hpp +++ b/components/esm/esmwriter.hpp @@ -5,7 +5,7 @@ #include #include -#include "esm_common.hpp" +#include "esmcommon.hpp" #include "../to_utf8/to_utf8.hpp" namespace ESM { diff --git a/components/esm/loadacti.cpp b/components/esm/loadacti.cpp index 1fd5819c8..0e214e2b6 100644 --- a/components/esm/loadacti.cpp +++ b/components/esm/loadacti.cpp @@ -1,7 +1,7 @@ #include "loadacti.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadalch.cpp b/components/esm/loadalch.cpp index be8464216..a4b1bb718 100644 --- a/components/esm/loadalch.cpp +++ b/components/esm/loadalch.cpp @@ -1,7 +1,7 @@ #include "loadalch.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadappa.cpp b/components/esm/loadappa.cpp index b9e3f5c37..f5e7e10e1 100644 --- a/components/esm/loadappa.cpp +++ b/components/esm/loadappa.cpp @@ -1,7 +1,7 @@ #include "loadappa.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadarmo.cpp b/components/esm/loadarmo.cpp index 36b12e7d4..613346533 100644 --- a/components/esm/loadarmo.cpp +++ b/components/esm/loadarmo.cpp @@ -1,7 +1,7 @@ #include "loadarmo.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadbody.cpp b/components/esm/loadbody.cpp index 421717049..831ad8b64 100644 --- a/components/esm/loadbody.cpp +++ b/components/esm/loadbody.cpp @@ -1,7 +1,7 @@ #include "loadbody.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadbook.cpp b/components/esm/loadbook.cpp index 365868338..8ed2f122a 100644 --- a/components/esm/loadbook.cpp +++ b/components/esm/loadbook.cpp @@ -1,7 +1,7 @@ #include "loadbook.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadbsgn.cpp b/components/esm/loadbsgn.cpp index 9b1835fab..b58071644 100644 --- a/components/esm/loadbsgn.cpp +++ b/components/esm/loadbsgn.cpp @@ -1,7 +1,7 @@ #include "loadbsgn.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index c83c5f400..b7e2063ef 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -3,8 +3,8 @@ #include #include -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index 3d1369637..6936dc255 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -3,7 +3,7 @@ #include -#include "esm_common.hpp" +#include "esmcommon.hpp" #include "record.hpp" #include "defs.hpp" diff --git a/components/esm/loadclas.cpp b/components/esm/loadclas.cpp index 620144160..a62668950 100644 --- a/components/esm/loadclas.cpp +++ b/components/esm/loadclas.cpp @@ -1,7 +1,7 @@ #include "loadclas.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadclot.cpp b/components/esm/loadclot.cpp index 4279ae9f4..a37fbe8a4 100644 --- a/components/esm/loadclot.cpp +++ b/components/esm/loadclot.cpp @@ -1,7 +1,7 @@ #include "loadclot.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadcont.cpp b/components/esm/loadcont.cpp index 6eef4124d..e6ba91e7c 100644 --- a/components/esm/loadcont.cpp +++ b/components/esm/loadcont.cpp @@ -1,7 +1,7 @@ #include "loadcont.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadcont.hpp b/components/esm/loadcont.hpp index e8384a8d4..66e906050 100644 --- a/components/esm/loadcont.hpp +++ b/components/esm/loadcont.hpp @@ -5,7 +5,7 @@ #include #include "record.hpp" -#include "esm_common.hpp" +#include "esmcommon.hpp" namespace ESM { diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index 2af6aeb05..b59835bd6 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -1,7 +1,7 @@ #include "loadcrea.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadcrec.hpp b/components/esm/loadcrec.hpp index b0e8dccd1..b40a9605f 100644 --- a/components/esm/loadcrec.hpp +++ b/components/esm/loadcrec.hpp @@ -4,7 +4,7 @@ #include "record.hpp" // TODO create implementation files and remove this one -#include "esm_reader.hpp" +#include "esmreader.hpp" namespace ESM { diff --git a/components/esm/loaddial.cpp b/components/esm/loaddial.cpp index a3189b7a9..fb50d5e9f 100644 --- a/components/esm/loaddial.cpp +++ b/components/esm/loaddial.cpp @@ -1,7 +1,7 @@ #include "loaddial.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loaddoor.cpp b/components/esm/loaddoor.cpp index ddcb0a5cb..b8ef029c5 100644 --- a/components/esm/loaddoor.cpp +++ b/components/esm/loaddoor.cpp @@ -1,7 +1,7 @@ #include "loaddoor.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadench.cpp b/components/esm/loadench.cpp index 8e7bbd35e..c4e278368 100644 --- a/components/esm/loadench.cpp +++ b/components/esm/loadench.cpp @@ -1,7 +1,7 @@ #include "loadench.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadfact.cpp b/components/esm/loadfact.cpp index c09d9657a..6ea66977d 100644 --- a/components/esm/loadfact.cpp +++ b/components/esm/loadfact.cpp @@ -1,7 +1,7 @@ #include "loadfact.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadglob.cpp b/components/esm/loadglob.cpp index 1c3edef4c..39c07fb31 100644 --- a/components/esm/loadglob.cpp +++ b/components/esm/loadglob.cpp @@ -1,7 +1,7 @@ #include "loadglob.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadgmst.cpp b/components/esm/loadgmst.cpp index b496170e7..aca880b4d 100644 --- a/components/esm/loadgmst.cpp +++ b/components/esm/loadgmst.cpp @@ -2,8 +2,8 @@ #include -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadinfo.cpp b/components/esm/loadinfo.cpp index b29c1dd94..5535d6abb 100644 --- a/components/esm/loadinfo.cpp +++ b/components/esm/loadinfo.cpp @@ -1,7 +1,7 @@ #include "loadinfo.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadingr.cpp b/components/esm/loadingr.cpp index e39d12a4e..4312dc05b 100644 --- a/components/esm/loadingr.cpp +++ b/components/esm/loadingr.cpp @@ -1,7 +1,7 @@ #include "loadingr.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index 0107e80ef..ec5ea5052 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -1,7 +1,7 @@ #include "loadland.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index 3149dfcb7..f82cd1da8 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -4,7 +4,7 @@ #include #include "record.hpp" -#include "esm_common.hpp" +#include "esmcommon.hpp" namespace ESM { diff --git a/components/esm/loadlevlist.cpp b/components/esm/loadlevlist.cpp index 2431f139e..4cba1119b 100644 --- a/components/esm/loadlevlist.cpp +++ b/components/esm/loadlevlist.cpp @@ -1,7 +1,7 @@ #include "loadlevlist.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadligh.cpp b/components/esm/loadligh.cpp index 727c662cd..48a56db3c 100644 --- a/components/esm/loadligh.cpp +++ b/components/esm/loadligh.cpp @@ -1,7 +1,7 @@ #include "loadligh.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadlocks.cpp b/components/esm/loadlocks.cpp index 0399f75b9..057da595e 100644 --- a/components/esm/loadlocks.cpp +++ b/components/esm/loadlocks.cpp @@ -1,7 +1,7 @@ #include "loadlocks.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadltex.cpp b/components/esm/loadltex.cpp index 40fe37298..e523e9fa7 100644 --- a/components/esm/loadltex.cpp +++ b/components/esm/loadltex.cpp @@ -1,7 +1,7 @@ #include "loadltex.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadmgef.cpp b/components/esm/loadmgef.cpp index b36355d2a..be588fbb0 100644 --- a/components/esm/loadmgef.cpp +++ b/components/esm/loadmgef.cpp @@ -1,7 +1,7 @@ #include "loadmgef.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace { diff --git a/components/esm/loadmisc.cpp b/components/esm/loadmisc.cpp index a6d53c7f1..3a5dded15 100644 --- a/components/esm/loadmisc.cpp +++ b/components/esm/loadmisc.cpp @@ -1,7 +1,7 @@ #include "loadmisc.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadnpc.cpp b/components/esm/loadnpc.cpp index ee2833ca1..72d0b3736 100644 --- a/components/esm/loadnpc.cpp +++ b/components/esm/loadnpc.cpp @@ -1,7 +1,7 @@ #include "loadnpc.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadnpcc.hpp b/components/esm/loadnpcc.hpp index 3641c0fa9..17ef8763b 100644 --- a/components/esm/loadnpcc.hpp +++ b/components/esm/loadnpcc.hpp @@ -4,7 +4,7 @@ #include "record.hpp" // TODO: create implementation files to remove this -#include "esm_reader.hpp" +#include "esmreader.hpp" namespace ESM { diff --git a/components/esm/loadpgrd.cpp b/components/esm/loadpgrd.cpp index 7c238a30b..56c2f8c74 100644 --- a/components/esm/loadpgrd.cpp +++ b/components/esm/loadpgrd.cpp @@ -1,7 +1,7 @@ #include "loadpgrd.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadrace.cpp b/components/esm/loadrace.cpp index 6fb264446..139ef081c 100644 --- a/components/esm/loadrace.cpp +++ b/components/esm/loadrace.cpp @@ -1,7 +1,7 @@ #include "loadrace.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadregn.cpp b/components/esm/loadregn.cpp index 75a7bdc63..d39a29454 100644 --- a/components/esm/loadregn.cpp +++ b/components/esm/loadregn.cpp @@ -1,7 +1,7 @@ #include "loadregn.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadregn.hpp b/components/esm/loadregn.hpp index ae78b2004..5c9086d14 100644 --- a/components/esm/loadregn.hpp +++ b/components/esm/loadregn.hpp @@ -5,7 +5,7 @@ #include #include "record.hpp" -#include "esm_common.hpp" +#include "esmcommon.hpp" namespace ESM { diff --git a/components/esm/loadscpt.cpp b/components/esm/loadscpt.cpp index 5bf7278a3..dc28166d4 100644 --- a/components/esm/loadscpt.cpp +++ b/components/esm/loadscpt.cpp @@ -1,7 +1,7 @@ #include "loadscpt.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadscpt.hpp b/components/esm/loadscpt.hpp index 4c273fbe2..2cc786cb9 100644 --- a/components/esm/loadscpt.hpp +++ b/components/esm/loadscpt.hpp @@ -5,7 +5,7 @@ #include #include "record.hpp" -#include "esm_common.hpp" +#include "esmcommon.hpp" namespace ESM { diff --git a/components/esm/loadskil.cpp b/components/esm/loadskil.cpp index 8e4bc2c66..a4d21c591 100644 --- a/components/esm/loadskil.cpp +++ b/components/esm/loadskil.cpp @@ -1,7 +1,7 @@ #include "loadskil.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadsndg.cpp b/components/esm/loadsndg.cpp index 3ff77030e..42d524226 100644 --- a/components/esm/loadsndg.cpp +++ b/components/esm/loadsndg.cpp @@ -1,7 +1,7 @@ #include "loadsndg.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadsoun.cpp b/components/esm/loadsoun.cpp index 66ac0ad22..87a08d2d3 100644 --- a/components/esm/loadsoun.cpp +++ b/components/esm/loadsoun.cpp @@ -1,7 +1,7 @@ #include "loadsoun.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadspel.cpp b/components/esm/loadspel.cpp index dc2695dd2..b0f1ca64b 100644 --- a/components/esm/loadspel.cpp +++ b/components/esm/loadspel.cpp @@ -1,7 +1,7 @@ #include "loadspel.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadsscr.cpp b/components/esm/loadsscr.cpp index f34ebbfa0..ae50de517 100644 --- a/components/esm/loadsscr.cpp +++ b/components/esm/loadsscr.cpp @@ -1,7 +1,7 @@ #include "loadsscr.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadstat.cpp b/components/esm/loadstat.cpp index 6b39e61ed..92c9ebc71 100644 --- a/components/esm/loadstat.cpp +++ b/components/esm/loadstat.cpp @@ -1,7 +1,7 @@ #include "loadstat.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/loadweap.cpp b/components/esm/loadweap.cpp index c20747e69..18d37e56c 100644 --- a/components/esm/loadweap.cpp +++ b/components/esm/loadweap.cpp @@ -1,7 +1,7 @@ #include "loadweap.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/esm/spelllist.cpp b/components/esm/spelllist.cpp index 364131242..dd886cf7f 100644 --- a/components/esm/spelllist.cpp +++ b/components/esm/spelllist.cpp @@ -1,7 +1,7 @@ #include "spelllist.hpp" -#include "esm_reader.hpp" -#include "esm_writer.hpp" +#include "esmreader.hpp" +#include "esmwriter.hpp" namespace ESM { diff --git a/components/terrain/esm_land_factory.cpp b/components/terrain/esm_land_factory.cpp index a6335c6dc..5cab7ed5d 100644 --- a/components/terrain/esm_land_factory.cpp +++ b/components/terrain/esm_land_factory.cpp @@ -3,7 +3,7 @@ // The first one already includes the others implicitly, but it // doesn't hurt to be explicit. #include "../esm_store/store.hpp" -#include "../esm/esm_reader.hpp" +#include "../esm/esmreader.hpp" #include "../esm/loadland.hpp" using namespace Terrain; From a34bdb962355f2d2938eea141339cbe2ef94629c Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 25 Sep 2012 10:48:57 +0200 Subject: [PATCH 25/48] per NPC ID interaction tracking --- apps/openmw/mwmechanics/npcstats.cpp | 10 ++++++++++ apps/openmw/mwmechanics/npcstats.hpp | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/apps/openmw/mwmechanics/npcstats.cpp b/apps/openmw/mwmechanics/npcstats.cpp index 39a5d6803..5367d3110 100644 --- a/apps/openmw/mwmechanics/npcstats.cpp +++ b/apps/openmw/mwmechanics/npcstats.cpp @@ -227,3 +227,13 @@ int MWMechanics::NpcStats::getLevelupAttributeMultiplier(int attribute) const else return 5; } + +void MWMechanics::NpcStats::flagAsUsed (const std::string& id) +{ + mUsedIds.insert (id); +} + +bool MWMechanics::NpcStats::hasBeenUsed (const std::string& id) const +{ + return mUsedIds.find (id)!=mUsedIds.end(); +} diff --git a/apps/openmw/mwmechanics/npcstats.hpp b/apps/openmw/mwmechanics/npcstats.hpp index 7c3055783..48e63d7b6 100644 --- a/apps/openmw/mwmechanics/npcstats.hpp +++ b/apps/openmw/mwmechanics/npcstats.hpp @@ -50,6 +50,8 @@ namespace MWMechanics std::vector mSkillIncreases; // number of skill increases for each attribute + std::set mUsedIds; + public: NpcStats(); @@ -86,6 +88,10 @@ namespace MWMechanics int getLevelupAttributeMultiplier(int attribute) const; void levelUp(); + + void flagAsUsed (const std::string& id); + + bool hasBeenUsed (const std::string& id) const; }; } From 853d62adba94b292cd1bbcff5df76ec9dc813064 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 25 Sep 2012 18:59:24 +0200 Subject: [PATCH 26/48] book skillgain --- apps/openmw/mwworld/actionread.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwworld/actionread.cpp b/apps/openmw/mwworld/actionread.cpp index fe5e2d58f..59c1e722f 100644 --- a/apps/openmw/mwworld/actionread.cpp +++ b/apps/openmw/mwworld/actionread.cpp @@ -35,22 +35,21 @@ namespace MWWorld MWBase::Environment::get().getWindowManager()->getBookWindow()->open(getTarget()); } - /* + MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer().getPlayer(); + MWMechanics::NpcStats& npcStats = MWWorld::Class::get(player).getNpcStats (player); + // Skill gain from books - if (ref->base->data.skillID >= 0 && ref->base->data.skillID < ESM::Skill::Length) + if (ref->base->data.skillID >= 0 && ref->base->data.skillID < ESM::Skill::Length + && !npcStats.hasBeenUsed (ref->base->name)) { - MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer().getPlayer(); - MWMechanics::NpcStats& npcStats = MWWorld::Class::get(player).getNpcStats (player); MWWorld::LiveCellRef *playerRef = player.get(); const ESM::Class *class_ = MWBase::Environment::get().getWorld()->getStore().classes.find ( playerRef->base->cls); npcStats.increaseSkill (ref->base->data.skillID, *class_, true); - /// \todo Remove skill from the book. Right now you can read as many times as you want - /// and the skill will still increase. + npcStats.flagAsUsed (ref->base->name); } - */ } } From d163f8203c17355d5ce80fe895582a54a735c757 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 25 Sep 2012 21:38:34 +0200 Subject: [PATCH 27/48] change books to RecListWithIDT --- apps/esmtool/esmtool.cpp | 2 +- apps/openmw/mwworld/actionread.cpp | 4 ++-- components/esm/loadbook.cpp | 3 ++- components/esm/loadbook.hpp | 3 ++- components/esm_store/store.hpp | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index 4888d3ceb..ac2746a89 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -226,7 +226,7 @@ int main(int argc, char**argv) case REC_BOOK: { Book b; - b.load(esm); + b.load(esm, id); if(quiet) break; cout << " Name: " << b.name << endl; cout << " Mesh: " << b.model << endl; diff --git a/apps/openmw/mwworld/actionread.cpp b/apps/openmw/mwworld/actionread.cpp index 59c1e722f..ed118d9b8 100644 --- a/apps/openmw/mwworld/actionread.cpp +++ b/apps/openmw/mwworld/actionread.cpp @@ -40,7 +40,7 @@ namespace MWWorld // Skill gain from books if (ref->base->data.skillID >= 0 && ref->base->data.skillID < ESM::Skill::Length - && !npcStats.hasBeenUsed (ref->base->name)) + && !npcStats.hasBeenUsed (ref->base->id)) { MWWorld::LiveCellRef *playerRef = player.get(); const ESM::Class *class_ = MWBase::Environment::get().getWorld()->getStore().classes.find ( @@ -48,7 +48,7 @@ namespace MWWorld npcStats.increaseSkill (ref->base->data.skillID, *class_, true); - npcStats.flagAsUsed (ref->base->name); + npcStats.flagAsUsed (ref->base->id); } } diff --git a/components/esm/loadbook.cpp b/components/esm/loadbook.cpp index ffa958e14..48d9aed0d 100644 --- a/components/esm/loadbook.cpp +++ b/components/esm/loadbook.cpp @@ -3,7 +3,7 @@ namespace ESM { -void Book::load(ESMReader &esm) +void Book::load(ESMReader &esm, const std::string& recordId) { model = esm.getHNString("MODL"); name = esm.getHNOString("FNAM"); @@ -12,6 +12,7 @@ void Book::load(ESMReader &esm) icon = esm.getHNOString("ITEX"); text = esm.getHNOString("TEXT"); enchant = esm.getHNOString("ENAM"); + id = recordId; } } diff --git a/components/esm/loadbook.hpp b/components/esm/loadbook.hpp index 3a4ab441e..525c21d33 100644 --- a/components/esm/loadbook.hpp +++ b/components/esm/loadbook.hpp @@ -20,8 +20,9 @@ struct Book BKDTstruct data; std::string name, model, icon, script, enchant, text; + std::string id; - void load(ESMReader &esm); + void load(ESMReader &esm, const std::string& recordId); }; } #endif diff --git a/components/esm_store/store.hpp b/components/esm_store/store.hpp index 991925bd4..7329386d4 100644 --- a/components/esm_store/store.hpp +++ b/components/esm_store/store.hpp @@ -34,7 +34,7 @@ namespace ESMS RecListT appas; RecListT armors; RecListT bodyParts; - RecListT books; + RecListWithIDT books; RecListT birthSigns; RecListT classes; RecListT clothes; From e2b13296202fc7e190610a6eb081a0c2ede84c08 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 24 Sep 2012 00:42:05 +0200 Subject: [PATCH 28/48] fix the race selection escape crash --- apps/openmw/mwgui/race.cpp | 19 +++++++++++++------ apps/openmw/mwgui/race.hpp | 3 ++- apps/openmw/mwrender/characterpreview.cpp | 1 + 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp index 5cb73e682..4b74ee2c8 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -33,11 +33,6 @@ RaceDialog::RaceDialog(MWBase::WindowManager& parWindowManager) setText("AppearanceT", mWindowManager.getGameSettingString("sRaceMenu1", "Appearance")); getWidget(mPreviewImage, "PreviewImage"); - MWBase::Environment::get().getWorld ()->setupExternalRendering (mPreview); - mPreview.update (0); - - mPreviewImage->setImageTexture ("CharacterHeadPreview"); - getWidget(mHeadRotate, "HeadRotate"); mHeadRotate->setScrollRange(50); mHeadRotate->setScrollPosition(25); @@ -107,6 +102,12 @@ void RaceDialog::open() updateRaces(); updateSkills(); updateSpellPowers(); + + mPreview = new MWRender::RaceSelectionPreview(); + MWBase::Environment::get().getWorld ()->setupExternalRendering (*mPreview); + mPreview->update (0); + + mPreviewImage->setImageTexture ("CharacterHeadPreview"); } @@ -138,6 +139,12 @@ int wrap(int index, int max) return index; } +void RaceDialog::close() +{ + delete mPreview; + mPreview = 0; +} + // widget controls void RaceDialog::onOkClicked(MyGUI::Widget* _sender) @@ -154,7 +161,7 @@ void RaceDialog::onHeadRotate(MyGUI::ScrollBar*, size_t _position) { float angle = (float(_position) / 49.f - 0.5) * 3.14 * 2; float diff = angle - mCurrentAngle; - mPreview.update (diff); + mPreview->update (diff); mCurrentAngle += diff; } diff --git a/apps/openmw/mwgui/race.hpp b/apps/openmw/mwgui/race.hpp index 0505e58e1..c4734eae8 100644 --- a/apps/openmw/mwgui/race.hpp +++ b/apps/openmw/mwgui/race.hpp @@ -46,6 +46,7 @@ namespace MWGui void setNextButtonShow(bool shown); virtual void open(); + virtual void close(); // Events typedef MyGUI::delegates::CMultiDelegate0 EventHandle_Void; @@ -94,7 +95,7 @@ namespace MWGui float mCurrentAngle; - MWRender::RaceSelectionPreview mPreview; + MWRender::RaceSelectionPreview* mPreview; }; } #endif diff --git a/apps/openmw/mwrender/characterpreview.cpp b/apps/openmw/mwrender/characterpreview.cpp index c8852bff5..4a0554568 100644 --- a/apps/openmw/mwrender/characterpreview.cpp +++ b/apps/openmw/mwrender/characterpreview.cpp @@ -25,6 +25,7 @@ namespace MWRender , mPosition(position) , mLookAt(lookAt) , mCharacter(character) + , mAnimation(NULL) { } From 44534593788136d6aa86943a65903561f1c4742f Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 24 Sep 2012 01:06:17 +0200 Subject: [PATCH 29/48] re-use the texture across preview instances --- apps/openmw/mwrender/characterpreview.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwrender/characterpreview.cpp b/apps/openmw/mwrender/characterpreview.cpp index 4a0554568..175f48e42 100644 --- a/apps/openmw/mwrender/characterpreview.cpp +++ b/apps/openmw/mwrender/characterpreview.cpp @@ -54,10 +54,13 @@ namespace MWRender mCamera->setNearClipDistance (0.01); mCamera->setFarClipDistance (1000); - mTexture = Ogre::TextureManager::getSingleton().createManual(mName, - Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, mSizeX, mSizeY, 0, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET); + mTexture = Ogre::TextureManager::getSingleton().getByName (mName); + if (mTexture.isNull ()) + mTexture = Ogre::TextureManager::getSingleton().createManual(mName, + Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, mSizeX, mSizeY, 0, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET); mRenderTarget = mTexture->getBuffer()->getRenderTarget(); + mRenderTarget->removeAllViewports (); mViewport = mRenderTarget->addViewport(mCamera); mViewport->setOverlaysEnabled(false); mViewport->setBackgroundColour(Ogre::ColourValue(0, 0, 0, 0)); From 359824d6142c40f4ed57aa90a93d7885a1248fe1 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 24 Sep 2012 01:07:33 +0200 Subject: [PATCH 30/48] oops --- apps/openmw/mwrender/characterpreview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/characterpreview.cpp b/apps/openmw/mwrender/characterpreview.cpp index 175f48e42..f755f34ef 100644 --- a/apps/openmw/mwrender/characterpreview.cpp +++ b/apps/openmw/mwrender/characterpreview.cpp @@ -75,7 +75,7 @@ namespace MWRender CharacterPreview::~CharacterPreview () { - Ogre::TextureManager::getSingleton().remove(mName); + //Ogre::TextureManager::getSingleton().remove(mName); mSceneMgr->destroyCamera (mName); delete mAnimation; } From caef570c8a3f8629b4d221bc9a36fb2062c4a682 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 25 Sep 2012 21:28:25 +0200 Subject: [PATCH 31/48] fix the weather not changing when sleeping/waiting --- apps/openmw/mwworld/weather.cpp | 10 +++++++--- apps/openmw/mwworld/weather.hpp | 7 +++++++ apps/openmw/mwworld/worldimp.cpp | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 0adf87dae..74c9cc9cd 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -41,7 +41,8 @@ const float WeatherGlobals::mThunderSoundDelay = 0.25; WeatherManager::WeatherManager(MWRender::RenderingManager* rendering) : mHour(14), mCurrentWeather("clear"), mFirstUpdate(true), mWeatherUpdateTime(0), mThunderFlash(0), mThunderChance(0), mThunderChanceNeeded(50), mThunderSoundDelay(0), - mRemainingTransitionTime(0), mMonth(0), mDay(0) + mRemainingTransitionTime(0), mMonth(0), mDay(0), + mTimePassed(0) { mRendering = rendering; @@ -487,7 +488,10 @@ WeatherResult WeatherManager::transition(float factor) void WeatherManager::update(float duration) { - mWeatherUpdateTime -= duration * MWBase::Environment::get().getWorld()->getTimeScaleFactor(); + float timePassed = mTimePassed; + mTimePassed = 0; + + mWeatherUpdateTime -= timePassed; bool exterior = (MWBase::Environment::get().getWorld()->isCellExterior() || MWBase::Environment::get().getWorld()->isCellQuasiExterior()); @@ -558,7 +562,7 @@ void WeatherManager::update(float duration) if (mNextWeather != "") { - mRemainingTransitionTime -= duration * MWBase::Environment::get().getWorld()->getTimeScaleFactor(); + mRemainingTransitionTime -= timePassed; if (mRemainingTransitionTime < 0) { mCurrentWeather = mNextWeather; diff --git a/apps/openmw/mwworld/weather.hpp b/apps/openmw/mwworld/weather.hpp index 5e0388751..589dff3eb 100644 --- a/apps/openmw/mwworld/weather.hpp +++ b/apps/openmw/mwworld/weather.hpp @@ -231,6 +231,11 @@ namespace MWWorld void setDate(const int day, const int month); + void advanceTime(double hours) + { + mTimePassed += hours*3600; + } + unsigned int getWeatherID() const; private: @@ -261,6 +266,8 @@ namespace MWWorld float mThunderChanceNeeded; float mThunderSoundDelay; + double mTimePassed; // time passed since last update + WeatherResult transition(const float factor); WeatherResult getResult(const Ogre::String& weather); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 834dffe79..38063b051 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -366,6 +366,8 @@ namespace MWWorld void World::advanceTime (double hours) { + mWeatherManager->advanceTime (hours); + hours += mGlobalVariables->getFloat ("gamehour"); setHour (hours); From 71d04e16da9d2d54591cdcbb620ff14043254a6d Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 25 Sep 2012 21:57:57 +0200 Subject: [PATCH 32/48] fix the global map updating when pinned --- apps/openmw/mwgui/map_window.cpp | 12 ++++++++++++ apps/openmw/mwgui/map_window.hpp | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/apps/openmw/mwgui/map_window.cpp b/apps/openmw/mwgui/map_window.cpp index 0fc4233b6..8b1de6258 100644 --- a/apps/openmw/mwgui/map_window.cpp +++ b/apps/openmw/mwgui/map_window.cpp @@ -224,6 +224,9 @@ void LocalMapBase::setPlayerPos(const float x, const float y) { if (x == mLastPositionX && y == mLastPositionY) return; + + notifyPlayerUpdate (); + MyGUI::IntSize size = mLocalMap->getCanvasSize(); MyGUI::IntPoint middle = MyGUI::IntPoint((1/3.f + x/3.f)*size.width,(1/3.f + y/3.f)*size.height); MyGUI::IntCoord viewsize = mLocalMap->getCoord(); @@ -239,6 +242,9 @@ void LocalMapBase::setPlayerDir(const float x, const float y) { if (x == mLastDirectionX && y == mLastDirectionY) return; + + notifyPlayerUpdate (); + MyGUI::ISubWidget* main = mCompass->getSubWidgetMain(); MyGUI::RotatingSkin* rotatingSubskin = main->castType(); rotatingSubskin->setCenter(MyGUI::IntPoint(16,16)); @@ -407,3 +413,9 @@ void MapWindow::globalMapUpdatePlayer () MyGUI::IntPoint viewoffs(0.5*viewsize.width - worldX, 0.5*viewsize.height - worldY); mGlobalMap->setViewOffset(viewoffs); } + +void MapWindow::notifyPlayerUpdate () +{ + if (mGlobal) + globalMapUpdatePlayer (); +} diff --git a/apps/openmw/mwgui/map_window.hpp b/apps/openmw/mwgui/map_window.hpp index 042e6c8ec..73eaad1cd 100644 --- a/apps/openmw/mwgui/map_window.hpp +++ b/apps/openmw/mwgui/map_window.hpp @@ -49,6 +49,8 @@ namespace MWGui void onMarkerFocused(MyGUI::Widget* w1, MyGUI::Widget* w2); void onMarkerUnfocused(MyGUI::Widget* w1, MyGUI::Widget* w2); + virtual void notifyPlayerUpdate() {} + OEngine::GUI::Layout* mLayout; bool mMapDragAndDrop; @@ -93,6 +95,8 @@ namespace MWGui protected: virtual void onPinToggled(); + + virtual void notifyPlayerUpdate(); }; } #endif From 9b0254a158716904d9d0963a9a29a3e52bc5d42c Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 26 Sep 2012 23:34:35 +0200 Subject: [PATCH 33/48] small map fix --- apps/openmw/mwgui/map_window.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwgui/map_window.cpp b/apps/openmw/mwgui/map_window.cpp index 8b1de6258..1913ed8dd 100644 --- a/apps/openmw/mwgui/map_window.cpp +++ b/apps/openmw/mwgui/map_window.cpp @@ -406,16 +406,15 @@ void MapWindow::globalMapUpdatePlayer () rotatingSubskin->setCenter(MyGUI::IntPoint(16,16)); float angle = std::atan2(dir.x, dir.y); rotatingSubskin->setAngle(angle); - } - // set the view offset so that player is in the center - MyGUI::IntSize viewsize = mGlobalMap->getSize(); - MyGUI::IntPoint viewoffs(0.5*viewsize.width - worldX, 0.5*viewsize.height - worldY); - mGlobalMap->setViewOffset(viewoffs); + // set the view offset so that player is in the center + MyGUI::IntSize viewsize = mGlobalMap->getSize(); + MyGUI::IntPoint viewoffs(0.5*viewsize.width - worldX, 0.5*viewsize.height - worldY); + mGlobalMap->setViewOffset(viewoffs); + } } void MapWindow::notifyPlayerUpdate () { - if (mGlobal) - globalMapUpdatePlayer (); + globalMapUpdatePlayer (); } From 044ab3d2b6d7715fdb059586036f1664fb225c07 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 28 Sep 2012 17:02:18 +0200 Subject: [PATCH 34/48] fix error in framelistener with tcg enabled --- apps/openmw/mwrender/debugging.cpp | 5 +++++ apps/openmw/mwrender/renderconst.hpp | 4 ++-- libs/openengine/bullet/BtOgreExtras.h | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwrender/debugging.cpp b/apps/openmw/mwrender/debugging.cpp index 91b217a36..71366307a 100644 --- a/apps/openmw/mwrender/debugging.cpp +++ b/apps/openmw/mwrender/debugging.cpp @@ -19,6 +19,7 @@ #include "../mwworld/ptr.hpp" #include "player.hpp" +#include "renderconst.hpp" using namespace Ogre; @@ -86,6 +87,8 @@ ManualObject *Debugging::createPathgridLines(const ESM::Pathgrid *pathgrid) } result->end(); + result->setVisibilityFlags (RV_Debug); + return result; } @@ -140,6 +143,8 @@ ManualObject *Debugging::createPathgridPoints(const ESM::Pathgrid *pathgrid) result->end(); + result->setVisibilityFlags (RV_Debug); + return result; } diff --git a/apps/openmw/mwrender/renderconst.hpp b/apps/openmw/mwrender/renderconst.hpp index e6ecb5150..75e243ec7 100644 --- a/apps/openmw/mwrender/renderconst.hpp +++ b/apps/openmw/mwrender/renderconst.hpp @@ -56,9 +56,9 @@ enum VisibilityFlags RV_PlayerPreview = 512, - RV_Map = RV_Terrain + RV_Statics + RV_StaticsSmall + RV_Misc + RV_Water + RV_Debug = 1024, - /// \todo markers (normally hidden) + RV_Map = RV_Terrain + RV_Statics + RV_StaticsSmall + RV_Misc + RV_Water }; } diff --git a/libs/openengine/bullet/BtOgreExtras.h b/libs/openengine/bullet/BtOgreExtras.h index f3e1aa87a..423924eda 100644 --- a/libs/openengine/bullet/BtOgreExtras.h +++ b/libs/openengine/bullet/BtOgreExtras.h @@ -206,6 +206,8 @@ public: } mLineDrawer->setMaterial("BtOgre/DebugLines"); + + mLineDrawer->setVisibilityFlags (1024); } ~DebugDrawer() From 9b491edbf81374663b09ecec6de8584ef1952aa2 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 28 Sep 2012 18:50:07 -0700 Subject: [PATCH 35/48] Small cleanup for loading animation keyframes --- components/nifogre/ogre_nif_loader.cpp | 72 +++++++++++--------------- 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 5127af966..91432ed6a 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -274,23 +274,18 @@ void loadResource(Ogre::Resource *resource) if(scaleiter != scalekeys.mKeys.end()) lastscale = curscale = Ogre::Vector3(scaleiter->mValue) / startscale; bool didlast = false; - + while(!didlast) { float curtime = kfc->timeStop; - //Get latest time - if(quatiter != quatkeys.mKeys.end()){ + if(quatiter != quatkeys.mKeys.end()) curtime = std::min(curtime, quatiter->mTime); - } - if(traniter != trankeys.mKeys.end()){ + if(traniter != trankeys.mKeys.end()) curtime = std::min(curtime, traniter->mTime); - - } - if(scaleiter != scalekeys.mKeys.end()){ + if(scaleiter != scalekeys.mKeys.end()) curtime = std::min(curtime, scaleiter->mTime); - } curtime = std::max(curtime, kfc->timeStart); if(curtime >= kfc->timeStop) @@ -299,15 +294,33 @@ void loadResource(Ogre::Resource *resource) curtime = kfc->timeStop; } - bool rinterpolate = quatiter != quatkeys.mKeys.end() && quatiter != quatkeys.mKeys.begin() && curtime != quatiter->mTime; - bool tinterpolate = traniter != trankeys.mKeys.end() && traniter != trankeys.mKeys.begin() && curtime != traniter->mTime; - bool sinterpolate = scaleiter != scalekeys.mKeys.end() && scaleiter != scalekeys.mKeys.begin() && curtime != scaleiter->mTime; + // Get the latest quaternions, translations, and scales for the + // current time + while(quatiter != quatkeys.mKeys.end() && curtime >= quatiter->mTime) + { + lastquat = curquat; + quatiter++; + if(quatiter != quatkeys.mKeys.end()) + curquat = startquat.Inverse() * quatiter->mValue ; + } + while(traniter != trankeys.mKeys.end() && curtime >= traniter->mTime) + { + lasttrans = curtrans; + traniter++; + if(traniter != trankeys.mKeys.end()) + curtrans = traniter->mValue - starttrans; + } + while(scaleiter != scalekeys.mKeys.end() && curtime >= scaleiter->mTime) + { + lastscale = curscale; + scaleiter++; + if(scaleiter != scalekeys.mKeys.end()) + curscale = Ogre::Vector3(scaleiter->mValue) / startscale; + } - - Ogre::TransformKeyFrame *kframe; kframe = nodetrack->createNodeKeyFrame(curtime); - if(!rinterpolate) + if(quatiter == quatkeys.mKeys.end() || quatiter == quatkeys.mKeys.begin()) kframe->setRotation(curquat); else { @@ -315,7 +328,7 @@ void loadResource(Ogre::Resource *resource) float diff = (curtime-last->mTime) / (quatiter->mTime-last->mTime); kframe->setRotation(Ogre::Quaternion::nlerp(diff, lastquat, curquat)); } - if(!tinterpolate) + if(traniter == trankeys.mKeys.end() || traniter == trankeys.mKeys.begin()) kframe->setTranslate(curtrans); else { @@ -323,7 +336,7 @@ void loadResource(Ogre::Resource *resource) float diff = (curtime-last->mTime) / (traniter->mTime-last->mTime); kframe->setTranslate(lasttrans + ((curtrans-lasttrans)*diff)); } - if(!sinterpolate) + if(scaleiter == scalekeys.mKeys.end() || scaleiter == scalekeys.mKeys.begin()) kframe->setScale(curscale); else { @@ -331,31 +344,6 @@ void loadResource(Ogre::Resource *resource) float diff = (curtime-last->mTime) / (scaleiter->mTime-last->mTime); kframe->setScale(lastscale + ((curscale-lastscale)*diff)); } - - // Get the latest quaternion, translation, and scale for the - // current time - while(quatiter != quatkeys.mKeys.end() && curtime >= quatiter->mTime) - { - quatiter++; - lastquat = curquat; - if(quatiter != quatkeys.mKeys.end()) - curquat = startquat.Inverse() * quatiter->mValue ; - } - while(traniter != trankeys.mKeys.end() && curtime >= traniter->mTime) - { - traniter++; - lasttrans = curtrans; - if(traniter != trankeys.mKeys.end()) - curtrans = traniter->mValue - starttrans; - } - while(scaleiter != scalekeys.mKeys.end() && curtime >= scaleiter->mTime) - { - scaleiter++; - lastscale = curscale; - if(scaleiter != scalekeys.mKeys.end()) - curscale = Ogre::Vector3(scaleiter->mValue) / startscale; - } - } } anim->optimise(); From cd8515396adfa654574c30d80f89075efb76b7f5 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 28 Sep 2012 21:57:26 -0700 Subject: [PATCH 36/48] Use a multimap to store the text keys --- apps/openmw/mwrender/animation.cpp | 53 +++++++++----------------- components/nifogre/ogre_nif_loader.cpp | 25 +++++++++++- components/nifogre/ogre_nif_loader.hpp | 2 +- 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 3d7629e5b..f7a175332 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -49,44 +49,27 @@ bool Animation::findGroupTimes(const std::string &groupname, Animation::GroupTim std::string::const_iterator strpos = iter->second.begin(); std::string::const_iterator strend = iter->second.end(); + size_t strlen = strend-strpos; - while(strpos != strend) + if(start.size() <= strlen && std::mismatch(strpos, strend, start.begin(), checklow()).first == strend) { - size_t strlen = strend-strpos; - std::string::const_iterator striter; - - if(start.size() <= strlen && - ((striter=std::mismatch(strpos, strend, start.begin(), checklow()).first) == strend || - *striter == '\r' || *striter == '\n')) - { - times->mStart = iter->first; - times->mLoopStart = iter->first; - } - else if(startloop.size() <= strlen && - ((striter=std::mismatch(strpos, strend, startloop.begin(), checklow()).first) == strend || - *striter == '\r' || *striter == '\n')) - { - times->mLoopStart = iter->first; - } - else if(stoploop.size() <= strlen && - ((striter=std::mismatch(strpos, strend, stoploop.begin(), checklow()).first) == strend || - *striter == '\r' || *striter == '\n')) - { + times->mStart = iter->first; + times->mLoopStart = iter->first; + } + else if(startloop.size() <= strlen && std::mismatch(strpos, strend, startloop.begin(), checklow()).first == strend) + { + times->mLoopStart = iter->first; + } + else if(stoploop.size() <= strlen && std::mismatch(strpos, strend, stoploop.begin(), checklow()).first == strend) + { + times->mLoopStop = iter->first; + } + else if(stop.size() <= strlen && std::mismatch(strpos, strend, stop.begin(), checklow()).first == strend) + { + times->mStop = iter->first; + if(times->mLoopStop < 0.0f) times->mLoopStop = iter->first; - } - else if(stop.size() <= strlen && - ((striter=std::mismatch(strpos, strend, stop.begin(), checklow()).first) == strend || - *striter == '\r' || *striter == '\n')) - { - times->mStop = iter->first; - if(times->mLoopStop < 0.0f) - times->mLoopStop = iter->first; - break; - } - - strpos = std::find(strpos+1, strend, '\n'); - while(strpos != strend && *strpos == '\n') - strpos++; + break; } } diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 91432ed6a..ad51d50b9 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -152,6 +152,28 @@ static void fail(const std::string &msg) } +static void insertTextKeys(const Nif::NiTextKeyExtraData *tk, TextKeyMap *textkeys) +{ + for(size_t i = 0;i < tk->list.size();i++) + { + const std::string &str = tk->list[i].text; + std::string::size_type pos = 0; + while(pos < str.length()) + { + while(pos < str.length() && ::isspace(str[pos])) + pos++; + if(pos >= str.length()) + break; + + std::string::size_type nextpos = std::min(str.find('\r', pos), str.find('\n', pos)); + textkeys->insert(std::make_pair(tk->list[i].time, str.substr(pos, nextpos-pos))); + + pos = nextpos; + } + } +} + + void buildBones(Ogre::Skeleton *skel, const Nif::Node *node, std::vector &ctrls, Ogre::Bone *parent=NULL) { Ogre::Bone *bone; @@ -359,8 +381,7 @@ bool createSkeleton(const std::string &name, const std::string &group, TextKeyMa if(e->recType == Nif::RC_NiTextKeyExtraData) { const Nif::NiTextKeyExtraData *tk = static_cast(e.getPtr()); - for(size_t i = 0;i < tk->list.size();i++) - (*textkeys)[tk->list[i].time] = tk->list[i].text; + insertTextKeys(tk, textkeys); } e = e->extra; } diff --git a/components/nifogre/ogre_nif_loader.hpp b/components/nifogre/ogre_nif_loader.hpp index b6610d8a7..a203112b5 100644 --- a/components/nifogre/ogre_nif_loader.hpp +++ b/components/nifogre/ogre_nif_loader.hpp @@ -59,7 +59,7 @@ namespace NifOgre { // FIXME: These should not be in NifOgre, it works agnostic of what model format is used -typedef std::map TextKeyMap; +typedef std::multimap TextKeyMap; struct EntityList { std::vector mEntities; Ogre::Entity *mSkelBase; From 0c6ad1336465dd571de5ab954f00b6d273eadf1d Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 29 Sep 2012 09:41:34 +0200 Subject: [PATCH 37/48] WakeUpPc instruction --- apps/openmw/mwbase/windowmanager.hpp | 1 + apps/openmw/mwgui/waitdialog.cpp | 9 ++++++++- apps/openmw/mwgui/waitdialog.hpp | 1 + apps/openmw/mwgui/windowmanagerimp.cpp | 5 +++++ apps/openmw/mwgui/windowmanagerimp.hpp | 1 + apps/openmw/mwscript/docs/vmformat.txt | 3 ++- apps/openmw/mwscript/miscextensions.cpp | 13 +++++++++++++ 7 files changed, 31 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 429163136..8ea9e5cef 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -226,6 +226,7 @@ namespace MWBase virtual bool getRestEnabled() = 0; virtual bool getPlayerSleeping() = 0; + virtual void wakeUpPlayer() = 0; }; } diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index 3210f1db9..380fb8dd5 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -202,7 +202,7 @@ namespace MWGui { MWBase::Environment::get().getWorld ()->getFader ()->fadeIn(0.2); mProgressBar.setVisible (false); - mWindowManager.popGuiMode (); + mWindowManager.removeGuiMode (GM_Rest); mWaiting = false; MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); @@ -215,4 +215,11 @@ namespace MWGui } } + void WaitDialog::wakeUp () + { + mSleeping = false; + mWaiting = false; + stopWaiting(); + } + } diff --git a/apps/openmw/mwgui/waitdialog.hpp b/apps/openmw/mwgui/waitdialog.hpp index 4a401c0c6..6af565c6e 100644 --- a/apps/openmw/mwgui/waitdialog.hpp +++ b/apps/openmw/mwgui/waitdialog.hpp @@ -32,6 +32,7 @@ namespace MWGui void bedActivated() { setCanRest(true); } bool getSleeping() { return mWaiting && mSleeping; } + void wakeUp(); protected: MyGUI::TextBox* mDateTimeText; diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 5a04a90c0..de8def126 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -956,6 +956,11 @@ bool WindowManager::getPlayerSleeping () return mWaitDialog->getSleeping(); } +void WindowManager::wakeUpPlayer() +{ + mWaitDialog->wakeUp(); +} + void WindowManager::addVisitedLocation(const std::string& name, int x, int y) { mMap->addVisitedLocation (name, x, y); diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index d7773e261..e30e110d3 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -209,6 +209,7 @@ namespace MWGui virtual bool getRestEnabled() { return mRestAllowed; } virtual bool getPlayerSleeping(); + virtual void wakeUpPlayer(); private: OEngine::GUI::MyGUIManager *mGuiManager; diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index a4a9e99fd..584a29926 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -205,5 +205,6 @@ op 0x200019e: PlaceAtMe Explicit op 0x200019f: GetPcSleep op 0x20001a0: ShowMap op 0x20001a1: FillMap -opcodes 0x20001a2-0x3ffffff unused +op 0x20001a2: WakeUpPc +opcodes 0x20001a3-0x3ffffff unused diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index a869f882b..674548cd6 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -31,6 +31,16 @@ namespace MWScript } }; + class OpWakeUpPc : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWBase::Environment::get().getWindowManager ()->wakeUpPlayer(); + } + }; + class OpXBox : public Interpreter::Opcode0 { public: @@ -261,6 +271,7 @@ namespace MWScript const int opcodeDontSaveObject = 0x2000153; const int opcodeToggleVanityMode = 0x2000174; const int opcodeGetPcSleep = 0x200019f; + const int opcodeWakeUpPc = 0x20001a2; void registerExtensions (Compiler::Extensions& extensions) { @@ -286,6 +297,7 @@ namespace MWScript extensions.registerInstruction ("togglevanitymode", "", opcodeToggleVanityMode); extensions.registerInstruction ("tvm", "", opcodeToggleVanityMode); extensions.registerFunction ("getpcsleep", 'l', "", opcodeGetPcSleep); + extensions.registerInstruction ("wakeuppc", "", opcodeWakeUpPc); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -307,6 +319,7 @@ namespace MWScript interpreter.installSegment5 (opcodeDontSaveObject, new OpDontSaveObject); interpreter.installSegment5 (opcodeToggleVanityMode, new OpToggleVanityMode); interpreter.installSegment5 (opcodeGetPcSleep, new OpGetPcSleep); + interpreter.installSegment5 (opcodeWakeUpPc, new OpWakeUpPc); } } } From 41f80908d96697979409f61e75258b5635b841d8 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 29 Sep 2012 01:10:49 -0700 Subject: [PATCH 38/48] Simplify getting the stop time when playing all animation groups --- apps/openmw/mwrender/animation.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index f7a175332..ef92497e5 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -87,17 +87,9 @@ void Animation::playGroup(std::string groupname, int mode, int loops) times.mStart = times.mLoopStart = 0.0f; times.mLoopStop = times.mStop = 0.0f; - if(mEntityList.mSkelBase) - { - Ogre::AnimationStateSet *aset = mEntityList.mSkelBase->getAllAnimationStates(); - Ogre::AnimationStateIterator as = aset->getAnimationStateIterator(); - while(as.hasMoreElements()) - { - Ogre::AnimationState *state = as.getNext(); - times.mLoopStop = times.mStop = state->getLength(); - break; - } - } + NifOgre::TextKeyMap::const_reverse_iterator iter = mTextKeys.rbegin(); + if(iter != mTextKeys.rend()) + times.mLoopStop = times.mStop = iter->first; } else if(!findGroupTimes(groupname, ×)) throw std::runtime_error("Failed to find animation group "+groupname); From 721324c1db1478abe13bcfdb59e10d9a910395f8 Mon Sep 17 00:00:00 2001 From: greye Date: Sun, 30 Sep 2012 23:34:53 +0400 Subject: [PATCH 39/48] rm record inheritance, rework esmtool accordingly --- apps/esmtool/CMakeLists.txt | 2 + apps/esmtool/esmtool.cpp | 738 ++++++------------------ apps/esmtool/record.cpp | 568 ++++++++++++++++++ apps/esmtool/record.hpp | 127 ++++ apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/ingredient.cpp | 2 +- apps/openmw/mwclass/npc.cpp | 2 +- apps/openmw/mwclass/potion.cpp | 2 +- apps/openmw/mwdialogue/journalentry.cpp | 4 +- apps/openmw/mwdialogue/quest.cpp | 2 +- apps/openmw/mwworld/worldimp.cpp | 2 +- components/esm/loadacti.hpp | 4 +- components/esm/loadalch.hpp | 8 +- components/esm/loadappa.hpp | 4 +- components/esm/loadarmo.hpp | 4 +- components/esm/loadbody.hpp | 4 +- components/esm/loadbook.hpp | 6 +- components/esm/loadbsgn.hpp | 4 +- components/esm/loadcell.cpp | 2 + components/esm/loadcell.hpp | 4 +- components/esm/loadclas.hpp | 4 +- components/esm/loadclot.hpp | 4 +- components/esm/loadcont.hpp | 4 +- components/esm/loadcrea.hpp | 6 +- components/esm/loadcrec.hpp | 8 +- components/esm/loaddial.hpp | 5 +- components/esm/loaddoor.hpp | 4 +- components/esm/loadench.hpp | 4 +- components/esm/loadfact.hpp | 6 +- components/esm/loadglob.hpp | 4 +- components/esm/loadgmst.hpp | 5 +- components/esm/loadinfo.cpp | 6 +- components/esm/loadinfo.hpp | 6 +- components/esm/loadingr.hpp | 6 +- components/esm/loadland.hpp | 4 +- components/esm/loadlevlist.hpp | 10 +- components/esm/loadligh.hpp | 4 +- components/esm/loadlocks.hpp | 12 +- components/esm/loadltex.hpp | 6 +- components/esm/loadmgef.hpp | 4 +- components/esm/loadmisc.hpp | 4 +- components/esm/loadnpc.hpp | 6 +- components/esm/loadnpcc.hpp | 4 +- components/esm/loadpgrd.hpp | 4 +- components/esm/loadrace.hpp | 4 +- components/esm/loadregn.hpp | 4 +- components/esm/loadscpt.hpp | 4 +- components/esm/loadskil.hpp | 4 +- components/esm/loadsndg.hpp | 4 +- components/esm/loadsoun.hpp | 4 +- components/esm/loadspel.hpp | 4 +- components/esm/loadsscr.hpp | 4 +- components/esm/loadstat.hpp | 4 +- components/esm/loadweap.hpp | 4 +- components/esm_store/reclists.hpp | 6 +- 55 files changed, 932 insertions(+), 735 deletions(-) create mode 100644 apps/esmtool/record.cpp create mode 100644 apps/esmtool/record.hpp diff --git a/apps/esmtool/CMakeLists.txt b/apps/esmtool/CMakeLists.txt index bd397d554..f48aa41bf 100644 --- a/apps/esmtool/CMakeLists.txt +++ b/apps/esmtool/CMakeLists.txt @@ -1,5 +1,7 @@ set(ESMTOOL esmtool.cpp + record.hpp + record.cpp ) source_group(apps\\esmtool FILES ${ESMTOOL}) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index 8d224e8b3..71d42df55 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -1,6 +1,9 @@ #include +#include +#include #include #include +#include #include @@ -8,10 +11,9 @@ #include #include -#define ESMTOOL_VERSION 1.1 +#include "record.hpp" -using namespace std; -using namespace ESM; +#define ESMTOOL_VERSION 1.1 // Create a local alias for brevity namespace bpo = boost::program_options; @@ -19,15 +21,31 @@ namespace bpo = boost::program_options; struct ESMData { std::string author; - string description; + std::string description; int version; int type; - ESMReader::MasterList masters; + ESM::ESMReader::MasterList masters; - list records; - map > cellRefs; + std::deque mRecords; + std::map > mCellRefs; + std::map mRecordStats; + + static const std::set sLabeledRec; }; +static const int sLabeledRecIds[] = { + ESM::REC_GLOB, ESM::REC_CLAS, ESM::REC_FACT, ESM::REC_RACE, ESM::REC_SOUN, + ESM::REC_REGN, ESM::REC_BSGN, ESM::REC_LTEX, ESM::REC_STAT, ESM::REC_DOOR, + ESM::REC_MISC, ESM::REC_WEAP, ESM::REC_CONT, ESM::REC_SPEL, ESM::REC_CREA, + ESM::REC_BODY, ESM::REC_LIGH, ESM::REC_ENCH, ESM::REC_NPC_, ESM::REC_ARMO, + ESM::REC_CLOT, ESM::REC_REPA, ESM::REC_ACTI, ESM::REC_APPA, ESM::REC_LOCK, + ESM::REC_PROB, ESM::REC_INGR, ESM::REC_BOOK, ESM::REC_ALCH, ESM::REC_LEVI, + ESM::REC_LEVC, ESM::REC_SNDG, ESM::REC_CELL, ESM::REC_DIAL +}; + +const std::set ESMData::sLabeledRec = + std::set(sLabeledRecIds, sLabeledRecIds + 34); + // Based on the legacy struct struct Arguments { @@ -35,14 +53,14 @@ struct Arguments unsigned int quiet_given; unsigned int loadcells_given; - string mode; - string encoding; - string filename; - string outname; + std::string mode; + std::string encoding; + std::string filename; + std::string outname; ESMData data; - ESMReader reader; - ESMWriter writer; + ESM::ESMReader reader; + ESM::ESMWriter writer; }; bool parseOptions (int argc, char** argv, Arguments &info) @@ -56,7 +74,7 @@ bool parseOptions (int argc, char** argv, Arguments &info) ("quiet,q", "Supress all record information. Useful for speed tests.") ("loadcells,C", "Browse through contents of all cells.") - ( "encoding,e", bpo::value(&(info.encoding))-> + ( "encoding,e", bpo::value(&(info.encoding))-> default_value("win1252"), "Character encoding used in ESMTool:\n" "\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages\n" @@ -64,14 +82,14 @@ bool parseOptions (int argc, char** argv, Arguments &info) "\n\twin1252 - Western European (Latin) alphabet, used by default") ; - string finalText = "\nIf no option is given, the default action is to parse all records in the archive\nand display diagnostic information."; + std::string finalText = "\nIf no option is given, the default action is to parse all records in the archive\nand display diagnostic information."; // input-file is hidden and used as a positional argument bpo::options_description hidden("Hidden Options"); hidden.add_options() - ( "mode,m", bpo::value(), "esmtool mode") - ( "input-file,i", bpo::value< vector >(), "input file") + ( "mode,m", bpo::value(), "esmtool mode") + ( "input-file,i", bpo::value< std::vector >(), "input file") ; bpo::positional_options_description p; @@ -89,77 +107,77 @@ bool parseOptions (int argc, char** argv, Arguments &info) if (variables.count ("help")) { - cout << desc << finalText << endl; + std::cout << desc << finalText << std::endl; return false; } if (variables.count ("version")) { - cout << "ESMTool version " << ESMTOOL_VERSION << endl; + std::cout << "ESMTool version " << ESMTOOL_VERSION << std::endl; return false; } if (!variables.count("mode")) { - cout << "No mode specified!" << endl << endl - << desc << finalText << endl; + std::cout << "No mode specified!" << std::endl << std::endl + << desc << finalText << std::endl; return false; } - info.mode = variables["mode"].as(); + info.mode = variables["mode"].as(); if (!(info.mode == "dump" || info.mode == "clone" || info.mode == "comp")) { - cout << endl << "ERROR: invalid mode \"" << info.mode << "\"" << endl << endl - << desc << finalText << endl; + std::cout << std::endl << "ERROR: invalid mode \"" << info.mode << "\"" << std::endl << std::endl + << desc << finalText << std::endl; return false; } if ( !variables.count("input-file") ) { - cout << "\nERROR: missing ES file\n\n"; - cout << desc << finalText << endl; + std::cout << "\nERROR: missing ES file\n\n"; + std::cout << desc << finalText << std::endl; return false; } // handling gracefully the user adding multiple files -/* if (variables["input-file"].as< vector >().size() > 1) +/* if (variables["input-file"].as< std::vector >().size() > 1) { - cout << "\nERROR: more than one ES file specified\n\n"; - cout << desc << finalText << endl; + std::cout << "\nERROR: more than one ES file specified\n\n"; + std::cout << desc << finalText << std::endl; return false; }*/ - info.filename = variables["input-file"].as< vector >()[0]; - if (variables["input-file"].as< vector >().size() > 1) - info.outname = variables["input-file"].as< vector >()[1]; + info.filename = variables["input-file"].as< std::vector >()[0]; + if (variables["input-file"].as< std::vector >().size() > 1) + info.outname = variables["input-file"].as< std::vector >()[1]; info.raw_given = variables.count ("raw"); info.quiet_given = variables.count ("quiet"); info.loadcells_given = variables.count ("loadcells"); // Font encoding settings - info.encoding = variables["encoding"].as(); + info.encoding = variables["encoding"].as(); if (info.encoding == "win1250") { - cout << "Using Central and Eastern European font encoding." << endl; + std::cout << "Using Central and Eastern European font encoding." << std::endl; } else if (info.encoding == "win1251") { - cout << "Using Cyrillic font encoding." << endl; + std::cout << "Using Cyrillic font encoding." << std::endl; } else { if(info.encoding != "win1252") { - cout << info.encoding << " is not a valid encoding option." << endl; + std::cout << info.encoding << " is not a valid encoding option." << std::endl; info.encoding = "win1252"; } - cout << "Using default (English) font encoding." << endl; + std::cout << "Using default (English) font encoding." << std::endl; } return true; } -void printRaw(ESMReader &esm); -void loadCell(Cell &cell, ESMReader &esm, Arguments& info); +void printRaw(ESM::ESMReader &esm); +void loadCell(ESM::Cell &cell, ESM::ESMReader &esm, Arguments& info); int load(Arguments& info); int clone(Arguments& info); @@ -179,14 +197,14 @@ int main(int argc, char**argv) return comp(info); else { - cout << "Invalid or no mode specified, dying horribly. Have a nice day." << endl; + std::cout << "Invalid or no mode specified, dying horribly. Have a nice day." << std::endl; return 1; } return 0; } -void loadCell(Cell &cell, ESMReader &esm, Arguments& info) +void loadCell(ESM::Cell &cell, ESM::ESMReader &esm, Arguments& info) { bool quiet = (info.quiet_given || info.mode == "clone"); bool save = (info.mode == "clone"); @@ -195,28 +213,29 @@ void loadCell(Cell &cell, ESMReader &esm, Arguments& info) cell.restore(esm); // Loop through all the references - CellRef ref; - if(!quiet) cout << " References:\n"; + ESM::CellRef ref; + if(!quiet) std::cout << " References:\n"; while(cell.getNextRef(esm, ref)) { - if (save) - info.data.cellRefs[&cell].push_back(ref); + if (save) { + info.data.mCellRefs[&cell].push_back(ref); + } if(quiet) continue; - cout << " Refnum: " << ref.mRefnum << endl; - cout << " ID: '" << ref.mRefID << "'\n"; - cout << " Owner: '" << ref.mOwner << "'\n"; - cout << " INTV: " << ref.mIntv << " NAM9: " << ref.mIntv << endl; + std::cout << " Refnum: " << ref.mRefnum << std::endl; + std::cout << " ID: '" << ref.mRefID << "'\n"; + std::cout << " Owner: '" << ref.mOwner << "'\n"; + std::cout << " INTV: " << ref.mIntv << " NAM9: " << ref.mIntv << std::endl; } } -void printRaw(ESMReader &esm) +void printRaw(ESM::ESMReader &esm) { while(esm.hasMoreRecs()) { - NAME n = esm.getRecName(); - cout << "Record: " << n.toString() << endl; + ESM::NAME n = esm.getRecName(); + std::cout << "Record: " << n.toString() << std::endl; esm.getRecHeader(); while(esm.hasMoreSubs()) { @@ -224,27 +243,27 @@ void printRaw(ESMReader &esm) esm.getSubName(); esm.skipHSub(); n = esm.retSubName(); - cout << " " << n.toString() << " - " << esm.getSubSize() - << " bytes @ 0x" << hex << offs << "\n"; + std::cout << " " << n.toString() << " - " << esm.getSubSize() + << " bytes @ 0x" << std::hex << offs << "\n"; } } } int load(Arguments& info) { - ESMReader& esm = info.reader; + ESM::ESMReader& esm = info.reader; esm.setEncoding(info.encoding); - string filename = info.filename; - cout << "Loading file: " << filename << endl; + std::string filename = info.filename; + std::cout << "Loading file: " << filename << std::endl; - list skipped; + std::list skipped; try { if(info.raw_given && info.mode == "dump") { - cout << "RAW file listing:\n"; + std::cout << "RAW file listing:\n"; esm.openRaw(filename); @@ -267,496 +286,79 @@ int load(Arguments& info) if (!quiet) { - cout << "Author: " << esm.getAuthor() << endl - << "Description: " << esm.getDesc() << endl - << "File format version: " << esm.getFVer() << endl - << "Special flag: " << esm.getSpecial() << endl; - ESMReader::MasterList m = esm.getMasters(); + std::cout << "Author: " << esm.getAuthor() << std::endl + << "Description: " << esm.getDesc() << std::endl + << "File format version: " << esm.getFVer() << std::endl + << "Special flag: " << esm.getSpecial() << std::endl; + ESM::ESMReader::MasterList m = esm.getMasters(); if (!m.empty()) { - cout << "Masters:" << endl; + std::cout << "Masters:" << std::endl; for(unsigned int i=0;igetType() == ESM::REC_GMST) { + // preset id for GameSetting record + record->cast()->get().mId = id; + } + record->setId(id); + record->setFlags((int) flags); + record->load(esm); + if (!quiet) { + record->print(); + } - if (rec != NULL) - { - rec->setId(id); + if (record->getType() == ESM::REC_CELL && loadCells) { + loadCell(record->cast()->get(), esm, info); + } - rec->setFlags((int)flags); - - if (save) - info.data.records.push_back(rec); - else - delete rec; + if (save) { + info.data.mRecords.push_back(record); + } else { + delete record; + } + ++info.data.mRecordStats[n.val]; } } - } catch(exception &e) - { - cout << "\nERROR:\n\n " << e.what() << endl; + } catch(std::exception &e) { + std::cout << "\nERROR:\n\n " << e.what() << std::endl; - for (list::iterator it = info.data.records.begin(); it != info.data.records.end();) + typedef std::deque RecStore; + RecStore &store = info.data.mRecords; + for (RecStore::iterator it = store.begin(); it != store.end(); ++it) { delete *it; - info.data.records.erase(it++); } + store.clear(); return 1; } @@ -769,17 +371,17 @@ int clone(Arguments& info) { if (info.outname.empty()) { - cout << "You need to specify an output name" << endl; + std::cout << "You need to specify an output name" << std::endl; return 1; } if (load(info) != 0) { - cout << "Failed to load, aborting." << endl; + std::cout << "Failed to load, aborting." << std::endl; return 1; } - int recordCount = info.data.records.size(); + int recordCount = info.data.mRecords.size(); int digitCount = 1; // For a nicer output if (recordCount > 9) ++digitCount; @@ -789,92 +391,84 @@ int clone(Arguments& info) if (recordCount > 99999) ++digitCount; if (recordCount > 999999) ++digitCount; - cout << "Loaded " << recordCount << " records:" << endl << endl; + std::cout << "Loaded " << recordCount << " records:" << std::endl << std::endl; - map records; - - for (list::iterator it = info.data.records.begin(); it != info.data.records.end(); ++it) - { - Record* rec = *it; - NAME n; - n.val = rec->getName(); - records[n.toString()]++; - } + ESM::NAME name; int i = 0; - for (map::iterator it = records.begin(); it != records.end(); ++it) + typedef std::map Stats; + Stats &stats = info.data.mRecordStats; + for (Stats::iterator it = stats.begin(); it != stats.end(); ++it) { - string n = it->first; + name.val = it->first; float amount = it->second; - cout << setw(digitCount) << amount << " " << n << " "; + std::cout << std::setw(digitCount) << amount << " " << name.toString() << " "; if (++i % 3 == 0) - cout << endl; + std::cout << std::endl; } if (i % 3 != 0) - cout << endl; + std::cout << std::endl; - cout << endl << "Saving records to: " << info.outname << "..." << endl; + std::cout << std::endl << "Saving records to: " << info.outname << "..." << std::endl; - ESMWriter& esm = info.writer; + ESM::ESMWriter& esm = info.writer; esm.setEncoding(info.encoding); esm.setAuthor(info.data.author); esm.setDescription(info.data.description); esm.setVersion(info.data.version); esm.setType(info.data.type); - for (ESMReader::MasterList::iterator it = info.data.masters.begin(); it != info.data.masters.end(); ++it) + for (ESM::ESMReader::MasterList::iterator it = info.data.masters.begin(); it != info.data.masters.end(); ++it) esm.addMaster(it->name, it->size); - fstream save(info.outname.c_str(), fstream::out | fstream::binary); + std::fstream save(info.outname.c_str(), std::fstream::out | std::fstream::binary); esm.save(save); int saved = 0; - for (list::iterator it = info.data.records.begin(); it != info.data.records.end() && i > 0; ++it) + typedef std::deque Records; + Records &records = info.data.mRecords; + for (Records::iterator it = records.begin(); it != records.end() && i > 0; ++it) { - Record* rec = *it; + EsmTool::RecordBase *record = *it; - NAME n; - n.val = rec->getName(); + name.val = record->getType(); - esm.startRecord(n.toString(), rec->getFlags()); - string id = rec->getId(); + esm.startRecord(name.toString(), record->getFlags()); // TODO wrap this with std::set - if (n.val == REC_GLOB || n.val == REC_CLAS || n.val == REC_FACT || n.val == REC_RACE || n.val == REC_SOUN - || n.val == REC_REGN || n.val == REC_BSGN || n.val == REC_LTEX || n.val == REC_STAT || n.val == REC_DOOR - || n.val == REC_MISC || n.val == REC_WEAP || n.val == REC_CONT || n.val == REC_SPEL || n.val == REC_CREA - || n.val == REC_BODY || n.val == REC_LIGH || n.val == REC_ENCH || n.val == REC_NPC_ || n.val == REC_ARMO - || n.val == REC_CLOT || n.val == REC_REPA || n.val == REC_ACTI || n.val == REC_APPA || n.val == REC_LOCK - || n.val == REC_PROB || n.val == REC_INGR || n.val == REC_BOOK || n.val == REC_ALCH || n.val == REC_LEVI - || n.val == REC_LEVC || n.val == REC_SNDG || n.val == REC_CELL || n.val == REC_DIAL) - esm.writeHNCString("NAME", id); - else - esm.writeHNOString("NAME", id); + if (ESMData::sLabeledRec.count(name.val) > 0) { + esm.writeHNCString("NAME", record->getId()); + } else { + esm.writeHNOString("NAME", record->getId()); + } - rec->save(esm); + record->save(esm); - if (n.val == REC_CELL && !info.data.cellRefs[rec].empty()) - { - list& refs = info.data.cellRefs[rec]; - for (list::iterator it = refs.begin(); it != refs.end(); ++it) - { - it->save(esm); + if (name.val == ESM::REC_CELL) { + ESM::Cell *ptr = &record->cast()->get(); + if (!info.data.mCellRefs[ptr].empty()) { + typedef std::deque RefList; + RefList &refs = info.data.mCellRefs[ptr]; + for (RefList::iterator it = refs.begin(); it != refs.end(); ++it) + { + it->save(esm); + } } } - esm.endRecord(n.toString()); + esm.endRecord(name.toString()); saved++; int perc = (saved / (float)recordCount)*100; if (perc % 10 == 0) { - cerr << "\r" << perc << "%"; + std::cerr << "\r" << perc << "%"; } } - cout << "\rDone!" << endl; + std::cout << "\rDone!" << std::endl; esm.close(); save.close(); @@ -886,7 +480,7 @@ int comp(Arguments& info) { if (info.filename.empty() || info.outname.empty()) { - cout << "You need to specify two input files" << endl; + std::cout << "You need to specify two input files" << std::endl; return 1; } @@ -907,19 +501,19 @@ int comp(Arguments& info) if (load(fileOne) != 0) { - cout << "Failed to load " << info.filename << ", aborting comparison." << endl; + std::cout << "Failed to load " << info.filename << ", aborting comparison." << std::endl; return 1; } if (load(fileTwo) != 0) { - cout << "Failed to load " << info.outname << ", aborting comparison." << endl; + std::cout << "Failed to load " << info.outname << ", aborting comparison." << std::endl; return 1; } - if (fileOne.data.records.size() != fileTwo.data.records.size()) + if (fileOne.data.mRecords.size() != fileTwo.data.mRecords.size()) { - cout << "Not equal, different amount of records." << endl; + std::cout << "Not equal, different amount of records." << std::endl; return 1; } diff --git a/apps/esmtool/record.cpp b/apps/esmtool/record.cpp new file mode 100644 index 000000000..9609e5242 --- /dev/null +++ b/apps/esmtool/record.cpp @@ -0,0 +1,568 @@ +#include "record.hpp" + +#include + +namespace EsmTool { + +RecordBase * +RecordBase::create(int type) +{ + RecordBase *record = 0; + + switch (type) { + case ESM::REC_ACTI: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_ALCH: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_APPA: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_ARMO: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_BODY: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_BOOK: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_BSGN: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_CELL: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_CLAS: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_CLOT: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_CONT: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_CREA: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_DIAL: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_DOOR: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_ENCH: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_FACT: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_GLOB: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_GMST: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_INFO: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_INGR: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_LAND: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_LEVI: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_LEVC: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_LIGH: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_LOCK: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_LTEX: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_MISC: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_MGEF: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_NPC_: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_PGRD: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_PROB: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_RACE: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_REGN: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_REPA: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_SCPT: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_SKIL: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_SNDG: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_SOUN: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_SPEL: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_STAT: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_WEAP: + { + record = new EsmTool::Record; + break; + } + case ESM::REC_SSCR: + { + record = new EsmTool::Record; + break; + } + default: + record = 0; + } + if (record) { + record->mType = type; + } + return record; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Mesh: " << mData.mModel << std::endl; + std::cout << " Script: " << mData.mScript << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Mesh: " << mData.mModel << std::endl; + std::cout << " Icon: " << mData.mIcon << std::endl; + std::cout << " Script: " << mData.mScript << std::endl; + std::cout << " Enchantment: " << mData.mEnchant << std::endl; + std::cout << " Type: " << mData.mData.mType << std::endl; + std::cout << " Weight: " << mData.mData.mWeight << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Mesh: " << mData.mModel << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Mesh: " << mData.mModel << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Texture: " << mData.mTexture << std::endl; + std::cout << " Description: " << mData.mDescription << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Region: " << mData.mRegion << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Description: " << mData.mDescription << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; +} + +template<> +void Record::print() +{ + // nothing to print +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Mesh: " << mData.mModel << std::endl; + std::cout << " Script: " << mData.mScript << std::endl; + std::cout << " OpenSound: " << mData.mOpenSound << std::endl; + std::cout << " CloseSound: " << mData.mCloseSound << std::endl; +} + +template<> +void Record::print() +{ + // nothing to print +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Attr1: " << mData.mData.mAttribute1 << std::endl; + std::cout << " Attr2: " << mData.mData.mAttribute2 << std::endl; + std::cout << " Hidden: " << mData.mData.mIsHidden << std::endl; +} + +template<> +void Record::print() +{ + // nothing to print +} + +template<> +void Record::print() +{ + std::cout << " Value: "; + switch (mData.mType) { + case ESM::VT_String: + std::cout << "'" << mData.mStr << "' (std::string)"; + break; + + case ESM::VT_Float: + std::cout << mData.mF << " (float)"; + break; + + case ESM::VT_Int: + std::cout << mData.mI << " (int)"; + break; + + default: + std::cout << "unknown type"; + } + std::cout << "\n Dirty: " << mData.mDirty << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Id: " << mData.mId << std::endl; + std::cout << " Text: " << mData.mResponse << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Weight: " << mData.mData.mWeight << std::endl; + std::cout << " Value: " << mData.mData.mValue << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Coords: [" << mData.mX << "," << mData.mY << "]" << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Number of items: " << mData.mList.size() << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Number of items: " << mData.mList.size() << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Weight: " << mData.mData.mWeight << std::endl; + std::cout << " Value: " << mData.mData.mValue << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Quality: " << mData.mData.mQuality << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Quality: " << mData.mData.mQuality << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Quality: " << mData.mData.mQuality << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Id: " << mData.mId << std::endl; + std::cout << " Texture: " << mData.mTexture << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Index: " << mData.mIndex << std::endl; + + const char *text = "Positive"; + if (mData.mData.mFlags & ESM::MagicEffect::Negative) { + text = "Negative"; + } + std::cout << " " << text << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Value: " << mData.mData.mValue << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Race: " << mData.mRace << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Cell: " << mData.mCell << std::endl; + std::cout << " Point count: " << mData.mPoints.size() << std::endl; + std::cout << " Edge count: " << mData.mEdges.size() << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Length: " << mData.mData.mHeight.mMale << "m " << mData.mData.mHeight.mFemale << "f" << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mData.mName.toString() << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " ID: " << mData.mIndex << std::endl; + + const char *spec = 0; + int specId = mData.mData.mSpecialization; + if (specId == 0) { + spec = "Combat"; + } else if (specId == 1) { + spec = "Magic"; + } else { + spec = "Stealth"; + } + std::cout << " Type: " << spec << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Creature: " << mData.mCreature << std::endl; + std::cout << " Sound: " << mData.mSound << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Sound: " << mData.mSound << std::endl; + std::cout << " Volume: " << mData.mData.mVolume << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; +} + +template<> +void Record::print() +{ + std::cout << "Start script: " << mData.mScript << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Model: " << mData.mModel << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Name: " << mData.mName << std::endl; + std::cout << " Chop: " << mData.mData.mChop[0] << "-" << mData.mData.mChop[1] << std::endl; + std::cout << " Slash: " << mData.mData.mSlash[0] << "-" << mData.mData.mSlash[1] << std::endl; + std::cout << " Thrust: " << mData.mData.mThrust[0] << "-" << mData.mData.mThrust[1] << std::endl; + std::cout << " Value: " << mData.mData.mValue << std::endl; +} + +template<> +void Record::print() +{ + std::cout << " Refnum: " << mData.mRefnum << std::endl; + std::cout << " ID: '" << mData.mRefID << "'\n"; + std::cout << " Owner: '" << mData.mOwner << "'\n"; + std::cout << " INTV: " << mData.mIntv << " NAM9: " << mData.mIntv << std::endl; +} + +} // end namespace diff --git a/apps/esmtool/record.hpp b/apps/esmtool/record.hpp new file mode 100644 index 000000000..3cd7f5b54 --- /dev/null +++ b/apps/esmtool/record.hpp @@ -0,0 +1,127 @@ +#ifndef OPENMW_ESMTOOL_RECORD_H +#define OPENMW_ESMTOOL_RECORD_H + +#include + +#include + +namespace ESM +{ + class ESMReader; + class ESMWriter; +} + +namespace EsmTool +{ + template class Record; + + class RecordBase + { + protected: + std::string mId; + int mFlags; + int mType; + + public: + RecordBase () {} + virtual ~RecordBase() {} + + const std::string &getId() const { + return mId; + } + + void setId(const std::string &id) { + mId = id; + } + + int getFlags() const { + return mFlags; + } + + void setFlags(int flags) { + mFlags = flags; + } + + int getType() const { + return mType; + } + + virtual void load(ESM::ESMReader &esm) = 0; + virtual void save(ESM::ESMWriter &esm) = 0; + virtual void print() = 0; + + static RecordBase *create(int type); + + // just make it a bit shorter + template + Record *cast() { + return static_cast *>(this); + } + }; + + template + class Record : public RecordBase + { + T mData; + + public: + T &get() { + return mData; + } + + void save(ESM::ESMWriter &esm) { + mData.save(esm); + } + + void load(ESM::ESMReader &esm) { + mData.load(esm); + } + + void print(); + }; + + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); + template<> void Record::print(); +} + +#endif diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index d89c9abfe..0cf348b14 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -81,7 +81,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return ref->base->getId(); + return ref->base->mId; } void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 75cd84a2e..8dec3f537 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -25,7 +25,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return ref->base->getId(); + return ref->base->mId; } void Ingredient::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index e7ec1d794..03b5e56aa 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -120,7 +120,7 @@ namespace MWClass MWWorld::LiveCellRef *ref = ptr.get(); - return ref->base->getId(); + return ref->base->mId; } void Npc::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 2b76ebd54..be0d1dd0f 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -159,7 +159,7 @@ namespace MWClass MWWorld::Ptr actor = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); boost::shared_ptr action ( - new MWWorld::ActionApply (actor, ref->base->getId())); + new MWWorld::ActionApply (actor, ref->base->mId)); action->setSound ("Drink"); diff --git a/apps/openmw/mwdialogue/journalentry.cpp b/apps/openmw/mwdialogue/journalentry.cpp index d25efc269..1c6addb6e 100644 --- a/apps/openmw/mwdialogue/journalentry.cpp +++ b/apps/openmw/mwdialogue/journalentry.cpp @@ -22,7 +22,7 @@ namespace MWDialogue for (std::vector::const_iterator iter (dialogue->mInfo.begin()); iter!=dialogue->mInfo.end(); ++iter) - if (iter->getId() == mInfoId) + if (iter->mId == mInfoId) return iter->mResponse; throw std::runtime_error ("unknown info ID " + mInfoId + " for topic " + mTopic); @@ -41,7 +41,7 @@ namespace MWDialogue iter!=dialogue->mInfo.end(); ++iter) if (iter->mData.mDisposition==index) /// \todo cleanup info structure { - return iter->getId(); + return iter->mId; } throw std::runtime_error ("unknown journal index for topic " + topic); diff --git a/apps/openmw/mwdialogue/quest.cpp b/apps/openmw/mwdialogue/quest.cpp index c6a1d7ea5..b4f02e128 100644 --- a/apps/openmw/mwdialogue/quest.cpp +++ b/apps/openmw/mwdialogue/quest.cpp @@ -67,7 +67,7 @@ namespace MWDialogue for (std::vector::const_iterator iter (dialogue->mInfo.begin()); iter!=dialogue->mInfo.end(); ++iter) - if (iter->getId() == entry.mInfoId) + if (iter->mId == entry.mInfoId) { index = iter->mData.mDisposition; /// \todo cleanup info structure break; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 0cdb2b528..1bb29e9a6 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -776,7 +776,7 @@ namespace MWWorld stream << "$dynamic" << mNextDynamicRecord++; ESM::Potion record2 (record); - record2.setId(stream.str()); + record2.mId = stream.str(); const ESM::Potion *created = &mStore.potions.list.insert (std::make_pair (stream.str(), record2)).first->second; diff --git a/components/esm/loadacti.hpp b/components/esm/loadacti.hpp index c1a630ab8..64cf1db6f 100644 --- a/components/esm/loadacti.hpp +++ b/components/esm/loadacti.hpp @@ -6,14 +6,12 @@ namespace ESM { -struct Activator : public Record +struct Activator { std::string mName, mScript, mModel; void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_ACTI; } }; } diff --git a/components/esm/loadalch.hpp b/components/esm/loadalch.hpp index 4d21b3b58..1367b9927 100644 --- a/components/esm/loadalch.hpp +++ b/components/esm/loadalch.hpp @@ -12,7 +12,7 @@ namespace ESM * Alchemy item (potions) */ -struct Potion : public Record +struct Potion { struct ALDTstruct { @@ -22,13 +22,11 @@ struct Potion : public Record }; ALDTstruct mData; - std::string mName, mModel, mIcon, mScript; + std::string mId, mName, mModel, mIcon, mScript; EffectList mEffects; void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_ALCH; } -}; + }; } #endif diff --git a/components/esm/loadappa.hpp b/components/esm/loadappa.hpp index e0850231f..b3d37cf75 100644 --- a/components/esm/loadappa.hpp +++ b/components/esm/loadappa.hpp @@ -9,7 +9,7 @@ namespace ESM * Alchemist apparatus */ -struct Apparatus : public Record +struct Apparatus { enum AppaType { @@ -32,8 +32,6 @@ struct Apparatus : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_APPA; } }; } #endif diff --git a/components/esm/loadarmo.hpp b/components/esm/loadarmo.hpp index 1adfd4fbc..04616c9ea 100644 --- a/components/esm/loadarmo.hpp +++ b/components/esm/loadarmo.hpp @@ -56,7 +56,7 @@ struct PartReferenceList void save(ESMWriter &esm); }; -struct Armor : public Record +struct Armor { enum Type { @@ -87,8 +87,6 @@ struct Armor : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_ARMO; } }; } #endif diff --git a/components/esm/loadbody.hpp b/components/esm/loadbody.hpp index d07a78fc8..66d555029 100644 --- a/components/esm/loadbody.hpp +++ b/components/esm/loadbody.hpp @@ -6,7 +6,7 @@ namespace ESM { -struct BodyPart : public Record +struct BodyPart { enum MeshPart { @@ -53,8 +53,6 @@ struct BodyPart : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_BODY; } }; } #endif diff --git a/components/esm/loadbook.hpp b/components/esm/loadbook.hpp index 8102b2dc1..dc7067e1f 100644 --- a/components/esm/loadbook.hpp +++ b/components/esm/loadbook.hpp @@ -9,7 +9,7 @@ namespace ESM * Books, magic scrolls, notes and so on */ -struct Book : public Record +struct Book { struct BKDTstruct { @@ -22,8 +22,6 @@ struct Book : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_BOOK; } -}; + }; } #endif diff --git a/components/esm/loadbsgn.hpp b/components/esm/loadbsgn.hpp index cd8a1c753..7733cb42f 100644 --- a/components/esm/loadbsgn.hpp +++ b/components/esm/loadbsgn.hpp @@ -9,7 +9,7 @@ namespace ESM { -struct BirthSign : public Record +struct BirthSign { std::string mName, mDescription, mTexture; @@ -18,8 +18,6 @@ struct BirthSign : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_BSGN; } }; } #endif diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index b7e2063ef..97ce17775 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -102,6 +102,8 @@ void Cell::load(ESMReader &esm) { // Exterior cells mRegion = esm.getHNOString("RGNN"); + + mMapColor = 0; esm.getHNOT(mMapColor, "NAM5"); } if (esm.isNextSub("NAM0")) { diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index 6936dc255..6773235a7 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -87,7 +87,7 @@ public: (using ESMReader::getContext()) and jumping back into place whenever we need to load a given cell. */ -struct Cell : public Record +struct Cell { enum Flags { @@ -128,8 +128,6 @@ struct Cell : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - int getName() { return REC_CELL; } - bool isExterior() const { return !(mData.mFlags & Interior); diff --git a/components/esm/loadclas.hpp b/components/esm/loadclas.hpp index 556892585..3897aabed 100644 --- a/components/esm/loadclas.hpp +++ b/components/esm/loadclas.hpp @@ -13,7 +13,7 @@ namespace ESM // These flags tells us which items should be auto-calculated for this // class -struct Class : public Record +struct Class { enum AutoCalc { @@ -63,8 +63,6 @@ struct Class : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_CLAS; } }; } #endif diff --git a/components/esm/loadclot.hpp b/components/esm/loadclot.hpp index a27953c6e..7fc59fdbd 100644 --- a/components/esm/loadclot.hpp +++ b/components/esm/loadclot.hpp @@ -13,7 +13,7 @@ namespace ESM * Clothing */ -struct Clothing : public Record +struct Clothing { enum Type { @@ -44,8 +44,6 @@ struct Clothing : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_CLOT; } }; } #endif diff --git a/components/esm/loadcont.hpp b/components/esm/loadcont.hpp index 66e906050..d3a89a503 100644 --- a/components/esm/loadcont.hpp +++ b/components/esm/loadcont.hpp @@ -28,7 +28,7 @@ struct InventoryList void save(ESMWriter &esm); }; -struct Container : public Record +struct Container { enum Flags { @@ -45,8 +45,6 @@ struct Container : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_CONT; } }; } #endif diff --git a/components/esm/loadcrea.hpp b/components/esm/loadcrea.hpp index 262bc92dd..e1b1e9310 100644 --- a/components/esm/loadcrea.hpp +++ b/components/esm/loadcrea.hpp @@ -16,7 +16,7 @@ namespace ESM * */ -struct Creature : public Record +struct Creature { // Default is 0x48? enum Flags @@ -69,7 +69,7 @@ struct Creature : public Record int mFlags; float mScale; - std::string mModel, mName, mScript; + std::string mId, mModel, mName, mScript; std::string mOriginal; // Base creature that this is a modification of InventoryList mInventory; @@ -80,8 +80,6 @@ struct Creature : public Record AIData mAiData; AIPackageList mAiPackage; - int getName() { return REC_CREA; } - void load(ESMReader &esm); void save(ESMWriter &esm); }; diff --git a/components/esm/loadcrec.hpp b/components/esm/loadcrec.hpp index b40a9605f..0609ea37f 100644 --- a/components/esm/loadcrec.hpp +++ b/components/esm/loadcrec.hpp @@ -12,7 +12,7 @@ namespace ESM { */ /// Changes a creature -struct LoadCREC : public Record +struct LoadCREC { void load(ESMReader &esm) { @@ -22,12 +22,10 @@ struct LoadCREC : public Record void save(ESMWriter &esm) { } - - int getName() { return REC_CREC; } }; /// Changes an item list / container -struct LoadCNTC : public Record +struct LoadCNTC { void load(ESMReader &esm) { @@ -37,8 +35,6 @@ struct LoadCNTC : public Record void save(ESMWriter &esm) { } - - int getName() { return REC_CNTC; } }; } #endif diff --git a/components/esm/loaddial.hpp b/components/esm/loaddial.hpp index ccf2ebb44..d561b9d76 100644 --- a/components/esm/loaddial.hpp +++ b/components/esm/loaddial.hpp @@ -14,7 +14,7 @@ namespace ESM * the INFO records following the DIAL. */ -struct Dialogue : public Record +struct Dialogue { enum Type { @@ -26,13 +26,12 @@ struct Dialogue : public Record Deleted = -1 }; + std::string mId; char mType; std::vector mInfo; void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_DIAL; } }; } #endif diff --git a/components/esm/loaddoor.hpp b/components/esm/loaddoor.hpp index 37ec5fdd3..337c81328 100644 --- a/components/esm/loaddoor.hpp +++ b/components/esm/loaddoor.hpp @@ -8,14 +8,12 @@ namespace ESM { -struct Door : public Record +struct Door { std::string mName, mModel, mScript, mOpenSound, mCloseSound; void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_DOOR; } }; } #endif diff --git a/components/esm/loadench.hpp b/components/esm/loadench.hpp index 81486c390..2894df393 100644 --- a/components/esm/loadench.hpp +++ b/components/esm/loadench.hpp @@ -10,7 +10,7 @@ namespace ESM * Enchantments */ -struct Enchantment : public Record +struct Enchantment { enum Type { @@ -34,8 +34,6 @@ struct Enchantment : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_ENCH; } }; } #endif diff --git a/components/esm/loadfact.hpp b/components/esm/loadfact.hpp index f5a6f05d7..50c2b42ba 100644 --- a/components/esm/loadfact.hpp +++ b/components/esm/loadfact.hpp @@ -26,9 +26,9 @@ struct RankData int mFactReaction; // Reaction from faction members }; -struct Faction : public Record +struct Faction { - std::string mName; + std::string mId, mName; struct FADTstruct { @@ -57,8 +57,6 @@ struct Faction : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_FACT; } }; } #endif diff --git a/components/esm/loadglob.hpp b/components/esm/loadglob.hpp index 2aceaae59..0147afded 100644 --- a/components/esm/loadglob.hpp +++ b/components/esm/loadglob.hpp @@ -11,15 +11,13 @@ namespace ESM * Global script variables */ -struct Global : public Record +struct Global { unsigned mValue; VarType mType; void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_GLOB; } }; } #endif diff --git a/components/esm/loadgmst.hpp b/components/esm/loadgmst.hpp index c99ec5fd1..acfc49814 100644 --- a/components/esm/loadgmst.hpp +++ b/components/esm/loadgmst.hpp @@ -13,8 +13,9 @@ namespace ESM * */ -struct GameSetting : public Record +struct GameSetting { + std::string mId; // One of these is used depending on the variable type std::string mStr; int mI; @@ -93,8 +94,6 @@ struct GameSetting : public Record ///< Throwns an exception if GMST is not of type string. void save(ESMWriter &esm); - - int getName() { return REC_GMST; } }; } #endif diff --git a/components/esm/loadinfo.cpp b/components/esm/loadinfo.cpp index 5535d6abb..f237cf780 100644 --- a/components/esm/loadinfo.cpp +++ b/components/esm/loadinfo.cpp @@ -8,7 +8,7 @@ namespace ESM void DialInfo::load(ESMReader &esm) { - mSelfId = esm.getHNString("INAM"); + mId = esm.getHNString("INAM"); mPrev = esm.getHNString("PNAM"); mNext = esm.getHNString("NNAM"); @@ -127,7 +127,7 @@ void DialInfo::load(ESMReader &esm) else esm.fail( "Don't know what to do with " + subName.toString() - + " in INFO " + mSelfId); + + " in INFO " + mId); if (mQuestStatus != QS_None) // Skip rest of record @@ -136,7 +136,7 @@ void DialInfo::load(ESMReader &esm) void DialInfo::save(ESMWriter &esm) { - esm.writeHNCString("INAM", mSelfId); + esm.writeHNCString("INAM", mId); esm.writeHNCString("PNAM", mPrev); esm.writeHNCString("NNAM", mNext); esm.writeHNT("DATA", mData, 12); diff --git a/components/esm/loadinfo.hpp b/components/esm/loadinfo.hpp index 085aabb24..83d5fe6b4 100644 --- a/components/esm/loadinfo.hpp +++ b/components/esm/loadinfo.hpp @@ -17,7 +17,7 @@ namespace ESM * and form a linked list of dialogue items. */ -struct DialInfo : public Record +struct DialInfo { enum Gender { @@ -61,7 +61,7 @@ struct DialInfo : public Record std::vector mSelects; // Id of this, previous and next INFO items - std::string mSelfId, mPrev, mNext; + std::string mId, mPrev, mNext; // Various references used in determining when to select this item. std::string mActor, mRace, mClass, mNpcFaction, mPcFaction, mCell; @@ -102,8 +102,6 @@ struct DialInfo : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_INFO; } }; /* diff --git a/components/esm/loadingr.hpp b/components/esm/loadingr.hpp index 4c4b40443..3f0423e1c 100644 --- a/components/esm/loadingr.hpp +++ b/components/esm/loadingr.hpp @@ -11,7 +11,7 @@ namespace ESM * Alchemy ingredient */ -struct Ingredient : public Record +struct Ingredient { struct IRDTstruct { @@ -23,12 +23,10 @@ struct Ingredient : public Record }; IRDTstruct mData; - std::string mName, mModel, mIcon, mScript; + std::string mId, mName, mModel, mIcon, mScript; void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_INGR; } }; } #endif diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index f82cd1da8..9f85bfb00 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -12,7 +12,7 @@ namespace ESM * Landscape data. */ -struct Land : public Record +struct Land { Land(); ~Land(); @@ -92,8 +92,6 @@ struct Land : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - int getName() { return REC_LAND; } - /** * Actually loads data */ diff --git a/components/esm/loadlevlist.hpp b/components/esm/loadlevlist.hpp index 6d420d68b..f39ddd4c2 100644 --- a/components/esm/loadlevlist.hpp +++ b/components/esm/loadlevlist.hpp @@ -17,7 +17,7 @@ namespace ESM * several files. */ -struct LeveledListBase : public Record +struct LeveledListBase { enum Flags { @@ -47,14 +47,6 @@ struct LeveledListBase : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() - { - if (mRecName[0] == 'C') - return REC_LEVC; - - return REC_LEVI; - } }; struct CreatureLevList: LeveledListBase diff --git a/components/esm/loadligh.hpp b/components/esm/loadligh.hpp index 626dd06e4..febbe4a5c 100644 --- a/components/esm/loadligh.hpp +++ b/components/esm/loadligh.hpp @@ -13,7 +13,7 @@ namespace ESM * and torches. */ -struct Light : public Record +struct Light { enum Flags { @@ -44,8 +44,6 @@ struct Light : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_LIGH; } }; } #endif diff --git a/components/esm/loadlocks.hpp b/components/esm/loadlocks.hpp index f30b0c4f1..e3a486086 100644 --- a/components/esm/loadlocks.hpp +++ b/components/esm/loadlocks.hpp @@ -11,7 +11,7 @@ namespace ESM * items (REPA). These have nearly identical data structures. */ -struct Tool : public Record +struct Tool { enum Type { @@ -37,16 +37,6 @@ struct Tool : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() - { - if (mType == Type_Probe) - return REC_PROB; - else if (mType == Type_Repair) - return REC_REPA; - else - return REC_LOCK; - } }; struct Probe: Tool diff --git a/components/esm/loadltex.hpp b/components/esm/loadltex.hpp index 8ac0da155..34aea8314 100644 --- a/components/esm/loadltex.hpp +++ b/components/esm/loadltex.hpp @@ -24,15 +24,13 @@ namespace ESM * texture, and see if it affects the game. */ -struct LandTexture : public Record +struct LandTexture { - std::string mTexture; + std::string mId, mTexture; int mIndex; void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_LTEX; } }; } #endif diff --git a/components/esm/loadmgef.hpp b/components/esm/loadmgef.hpp index caa983d6b..1ca7382b0 100644 --- a/components/esm/loadmgef.hpp +++ b/components/esm/loadmgef.hpp @@ -8,7 +8,7 @@ namespace ESM { -struct MagicEffect : public Record +struct MagicEffect { enum Flags { @@ -50,8 +50,6 @@ struct MagicEffect : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_MGEF; } }; } #endif diff --git a/components/esm/loadmisc.hpp b/components/esm/loadmisc.hpp index 3e0d5db64..f40ac9b79 100644 --- a/components/esm/loadmisc.hpp +++ b/components/esm/loadmisc.hpp @@ -13,7 +13,7 @@ namespace ESM * carried, bought and sold. It also includes keys. */ -struct Miscellaneous : public Record +struct Miscellaneous { struct MCDTstruct { @@ -29,8 +29,6 @@ struct Miscellaneous : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_MISC; } }; } #endif diff --git a/components/esm/loadnpc.hpp b/components/esm/loadnpc.hpp index f9b579f4f..42a8a70bd 100644 --- a/components/esm/loadnpc.hpp +++ b/components/esm/loadnpc.hpp @@ -15,7 +15,7 @@ namespace ESM { * NPC definition */ -struct NPC : public Record +struct NPC { // Services enum Services @@ -106,7 +106,7 @@ struct NPC : public Record std::vector mTransport; AIPackageList mAiPackage; - std::string mName, mModel, mRace, mClass, mFaction, mScript; + std::string mId, mName, mModel, mRace, mClass, mFaction, mScript; // body parts std::string mHair, mHead; @@ -114,8 +114,6 @@ struct NPC : public Record // Implementation moved to load_impl.cpp void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_NPC_; } }; } #endif diff --git a/components/esm/loadnpcc.hpp b/components/esm/loadnpcc.hpp index 17ef8763b..a056dc701 100644 --- a/components/esm/loadnpcc.hpp +++ b/components/esm/loadnpcc.hpp @@ -73,7 +73,7 @@ namespace ESM { * will be harder than reading it. */ -struct LoadNPCC : public Record +struct LoadNPCC { void load(ESMReader &esm) { @@ -82,8 +82,6 @@ struct LoadNPCC : public Record void save(ESMWriter &esm) { } - - int getName() { return REC_NPCC; } }; } #endif diff --git a/components/esm/loadpgrd.hpp b/components/esm/loadpgrd.hpp index 3d8fb5ccd..039812040 100644 --- a/components/esm/loadpgrd.hpp +++ b/components/esm/loadpgrd.hpp @@ -12,7 +12,7 @@ namespace ESM /* * Path grid. */ -struct Pathgrid : public Record +struct Pathgrid { struct DATAstruct { @@ -46,8 +46,6 @@ struct Pathgrid : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_PGRD; } }; } #endif diff --git a/components/esm/loadrace.hpp b/components/esm/loadrace.hpp index bd7096a4c..ae12eec14 100644 --- a/components/esm/loadrace.hpp +++ b/components/esm/loadrace.hpp @@ -12,7 +12,7 @@ namespace ESM * Race definition */ -struct Race : public Record +struct Race { struct SkillBonus { @@ -66,8 +66,6 @@ struct Race : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_RACE; } }; } diff --git a/components/esm/loadregn.hpp b/components/esm/loadregn.hpp index 5c9086d14..568d096fe 100644 --- a/components/esm/loadregn.hpp +++ b/components/esm/loadregn.hpp @@ -14,7 +14,7 @@ namespace ESM * Region data */ -struct Region : public Record +struct Region { #pragma pack(push) #pragma pack(1) @@ -46,8 +46,6 @@ struct Region : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_REGN; } }; } #endif diff --git a/components/esm/loadscpt.hpp b/components/esm/loadscpt.hpp index 2cc786cb9..9c8acd81f 100644 --- a/components/esm/loadscpt.hpp +++ b/components/esm/loadscpt.hpp @@ -14,7 +14,7 @@ namespace ESM * Script definitions */ -class Script : public Record +class Script { public: struct SCHDstruct @@ -55,8 +55,6 @@ public: void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_SCPT; } }; } #endif diff --git a/components/esm/loadskil.hpp b/components/esm/loadskil.hpp index a6716dc27..56ea07929 100644 --- a/components/esm/loadskil.hpp +++ b/components/esm/loadskil.hpp @@ -15,7 +15,7 @@ namespace ESM { * */ -struct Skill : public Record +struct Skill { struct SKDTstruct { @@ -71,8 +71,6 @@ struct Skill : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_SKIL; } }; } #endif diff --git a/components/esm/loadsndg.hpp b/components/esm/loadsndg.hpp index e58f2eb0c..22d42dc2f 100644 --- a/components/esm/loadsndg.hpp +++ b/components/esm/loadsndg.hpp @@ -12,7 +12,7 @@ namespace ESM * Sound generator. This describes the sounds a creature make. */ -struct SoundGenerator : public Record +struct SoundGenerator { enum Type { @@ -33,8 +33,6 @@ struct SoundGenerator : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_SNDG; } }; } #endif diff --git a/components/esm/loadsoun.hpp b/components/esm/loadsoun.hpp index d4647bd08..73ee5b22f 100644 --- a/components/esm/loadsoun.hpp +++ b/components/esm/loadsoun.hpp @@ -13,15 +13,13 @@ struct SOUNstruct unsigned char mVolume, mMinRange, mMaxRange; }; -struct Sound : public Record +struct Sound { SOUNstruct mData; std::string mSound; void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_SOUN; } }; } #endif diff --git a/components/esm/loadspel.hpp b/components/esm/loadspel.hpp index 9f557a9b2..d96a12a4e 100644 --- a/components/esm/loadspel.hpp +++ b/components/esm/loadspel.hpp @@ -9,7 +9,7 @@ namespace ESM { -struct Spell : public Record +struct Spell { enum SpellType { @@ -41,8 +41,6 @@ struct Spell : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_SPEL; } }; } #endif diff --git a/components/esm/loadsscr.hpp b/components/esm/loadsscr.hpp index 2b87f7621..758847f21 100644 --- a/components/esm/loadsscr.hpp +++ b/components/esm/loadsscr.hpp @@ -16,7 +16,7 @@ namespace ESM reference. */ -struct StartScript : public Record +struct StartScript { std::string mData; std::string mScript; @@ -24,8 +24,6 @@ struct StartScript : public Record // Load a record and add it to the list void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_SSCR; } }; } diff --git a/components/esm/loadstat.hpp b/components/esm/loadstat.hpp index 2a51fa7a7..45a43082d 100644 --- a/components/esm/loadstat.hpp +++ b/components/esm/loadstat.hpp @@ -19,14 +19,12 @@ namespace ESM { * you decode the CELL blocks, if you want to test this hypothesis. */ -struct Static : public Record +struct Static { std::string mModel; void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_STAT; } }; } #endif diff --git a/components/esm/loadweap.hpp b/components/esm/loadweap.hpp index 2a6439f8f..724c96c88 100644 --- a/components/esm/loadweap.hpp +++ b/components/esm/loadweap.hpp @@ -12,7 +12,7 @@ namespace ESM * Weapon definition */ -struct Weapon : public Record +struct Weapon { enum Type { @@ -59,8 +59,6 @@ struct Weapon : public Record void load(ESMReader &esm); void save(ESMWriter &esm); - - int getName() { return REC_WEAP; } }; } #endif diff --git a/components/esm_store/reclists.hpp b/components/esm_store/reclists.hpp index bf98bf1d7..24580a79c 100644 --- a/components/esm_store/reclists.hpp +++ b/components/esm_store/reclists.hpp @@ -173,7 +173,7 @@ namespace ESMS void load(ESMReader &esm, const std::string &id) { std::string id2 = toLower (id); - list[id2].setId(id2); + list[id2].mId = id2; list[id2].load(esm); } @@ -226,7 +226,7 @@ namespace ESMS std::string id2 = toLower (id); X& ref = list[id2]; - ref.setId(id); + ref.mId = id; ref.load(esm); } @@ -293,7 +293,7 @@ namespace ESMS { LandTexture lt; lt.load(esm); - lt.setId(id); + lt.mId = id; // Make sure we have room for the structure if(lt.mIndex + 1 > (int)ltex.size()) From 3494e17b7ce0d0287dd1c534e6f071f0bf9b5310 Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 1 Oct 2012 00:51:54 +0400 Subject: [PATCH 40/48] wipe record superclass --- components/esm/defs.hpp | 49 ++++++++++++++++++++++++++++++++++ components/esm/esmcommon.hpp | 2 ++ components/esm/loadacti.hpp | 5 +++- components/esm/loadalch.hpp | 5 +++- components/esm/loadappa.hpp | 6 ++++- components/esm/loadarmo.hpp | 5 ++-- components/esm/loadbody.hpp | 5 +++- components/esm/loadbook.hpp | 5 +++- components/esm/loadbsgn.hpp | 4 ++- components/esm/loadcell.hpp | 5 +++- components/esm/loadclas.hpp | 6 +++-- components/esm/loadclot.hpp | 4 ++- components/esm/loadcont.hpp | 4 ++- components/esm/loadcrea.hpp | 4 ++- components/esm/loadcrec.hpp | 5 ++-- components/esm/loaddial.hpp | 5 +++- components/esm/loaddoor.hpp | 5 ++-- components/esm/loadench.hpp | 5 +++- components/esm/loadfact.hpp | 5 ++-- components/esm/loadglob.hpp | 4 ++- components/esm/loadgmst.hpp | 5 +++- components/esm/loadinfo.hpp | 4 ++- components/esm/loadingr.hpp | 6 +++-- components/esm/loadland.hpp | 5 +++- components/esm/loadlevlist.hpp | 5 ++-- components/esm/loadligh.hpp | 5 ++-- components/esm/loadlocks.hpp | 5 +++- components/esm/loadltex.hpp | 5 ++-- components/esm/loadmgef.hpp | 5 ++-- components/esm/loadmisc.hpp | 5 ++-- components/esm/loadnpc.hpp | 5 +++- components/esm/loadnpcc.hpp | 5 ++-- components/esm/loadpgrd.hpp | 5 ++-- components/esm/loadrace.hpp | 5 +++- components/esm/loadregn.hpp | 4 ++- components/esm/loadscpt.hpp | 4 ++- components/esm/loadskil.hpp | 4 ++- components/esm/loadsndg.hpp | 5 ++-- components/esm/loadsoun.hpp | 5 ++-- components/esm/loadspel.hpp | 4 ++- components/esm/loadsscr.hpp | 5 ++-- components/esm/loadstat.hpp | 5 ++-- components/esm/loadweap.hpp | 5 ++-- components/esm/record.hpp | 26 ------------------ components/esm/records.hpp | 2 +- 45 files changed, 191 insertions(+), 86 deletions(-) diff --git a/components/esm/defs.hpp b/components/esm/defs.hpp index 0a8f95108..aa870f925 100644 --- a/components/esm/defs.hpp +++ b/components/esm/defs.hpp @@ -46,5 +46,54 @@ struct Position }; #pragma pack(pop) +enum RecNameInts +{ + REC_ACTI = 0x49544341, + REC_ALCH = 0x48434c41, + REC_APPA = 0x41505041, + REC_ARMO = 0x4f4d5241, + REC_BODY = 0x59444f42, + REC_BOOK = 0x4b4f4f42, + REC_BSGN = 0x4e475342, + REC_CELL = 0x4c4c4543, + REC_CLAS = 0x53414c43, + REC_CLOT = 0x544f4c43, + REC_CNTC = 0x43544e43, + REC_CONT = 0x544e4f43, + REC_CREA = 0x41455243, + REC_CREC = 0x43455243, + REC_DIAL = 0x4c414944, + REC_DOOR = 0x524f4f44, + REC_ENCH = 0x48434e45, + REC_FACT = 0x54434146, + REC_GLOB = 0x424f4c47, + REC_GMST = 0x54534d47, + REC_INFO = 0x4f464e49, + REC_INGR = 0x52474e49, + REC_LAND = 0x444e414c, + REC_LEVC = 0x4356454c, + REC_LEVI = 0x4956454c, + REC_LIGH = 0x4847494c, + REC_LOCK = 0x4b434f4c, + REC_LTEX = 0x5845544c, + REC_MGEF = 0x4645474d, + REC_MISC = 0x4353494d, + REC_NPC_ = 0x5f43504e, + REC_NPCC = 0x4343504e, + REC_PGRD = 0x44524750, + REC_PROB = 0x424f5250, + REC_RACE = 0x45434152, + REC_REGN = 0x4e474552, + REC_REPA = 0x41504552, + REC_SCPT = 0x54504353, + REC_SKIL = 0x4c494b53, + REC_SNDG = 0x47444e53, + REC_SOUN = 0x4e554f53, + REC_SPEL = 0x4c455053, + REC_SSCR = 0x52435353, + REC_STAT = 0x54415453, + REC_WEAP = 0x50414557 +}; + } #endif diff --git a/components/esm/esmcommon.hpp b/components/esm/esmcommon.hpp index eb16e3768..e0c5c08af 100644 --- a/components/esm/esmcommon.hpp +++ b/components/esm/esmcommon.hpp @@ -1,6 +1,8 @@ #ifndef OPENMW_ESM_COMMON_H #define OPENMW_ESM_COMMON_H +#include + #include #include diff --git a/components/esm/loadacti.hpp b/components/esm/loadacti.hpp index 64cf1db6f..86c2f44c4 100644 --- a/components/esm/loadacti.hpp +++ b/components/esm/loadacti.hpp @@ -1,11 +1,14 @@ #ifndef OPENMW_ESM_ACTI_H #define OPENMW_ESM_ACTI_H -#include "record.hpp" +#include namespace ESM { +class ESMReader; +class ESMWriter; + struct Activator { std::string mName, mScript, mModel; diff --git a/components/esm/loadalch.hpp b/components/esm/loadalch.hpp index 1367b9927..1e571ac40 100644 --- a/components/esm/loadalch.hpp +++ b/components/esm/loadalch.hpp @@ -3,11 +3,14 @@ #include -#include "record.hpp" #include "effectlist.hpp" namespace ESM { + +class ESMReader; +class ESMWriter; + /* * Alchemy item (potions) */ diff --git a/components/esm/loadappa.hpp b/components/esm/loadappa.hpp index b3d37cf75..101c39f41 100644 --- a/components/esm/loadappa.hpp +++ b/components/esm/loadappa.hpp @@ -1,10 +1,14 @@ #ifndef OPENMW_ESM_APPA_H #define OPENMW_ESM_APPA_H -#include "record.hpp" +#include namespace ESM { + +class ESMReader; +class ESMWriter; + /* * Alchemist apparatus */ diff --git a/components/esm/loadarmo.hpp b/components/esm/loadarmo.hpp index 04616c9ea..57c9ccf12 100644 --- a/components/esm/loadarmo.hpp +++ b/components/esm/loadarmo.hpp @@ -4,11 +4,12 @@ #include #include -#include "record.hpp" - namespace ESM { +class ESMReader; +class ESMWriter; + enum PartReferenceType { PRT_Head = 0, diff --git a/components/esm/loadbody.hpp b/components/esm/loadbody.hpp index 66d555029..8a05d9924 100644 --- a/components/esm/loadbody.hpp +++ b/components/esm/loadbody.hpp @@ -1,11 +1,14 @@ #ifndef OPENMW_ESM_BODY_H #define OPENMW_ESM_BODY_H -#include "record.hpp" +#include namespace ESM { +class ESMReader; +class ESMWriter; + struct BodyPart { enum MeshPart diff --git a/components/esm/loadbook.hpp b/components/esm/loadbook.hpp index 9f937ee4b..22201abed 100644 --- a/components/esm/loadbook.hpp +++ b/components/esm/loadbook.hpp @@ -1,7 +1,7 @@ #ifndef OPENMW_ESM_BOOK_H #define OPENMW_ESM_BOOK_H -#include "record.hpp" +#include namespace ESM { @@ -9,6 +9,9 @@ namespace ESM * Books, magic scrolls, notes and so on */ +class ESMReader; +class ESMWriter; + struct Book { struct BKDTstruct diff --git a/components/esm/loadbsgn.hpp b/components/esm/loadbsgn.hpp index 7733cb42f..ac4050878 100644 --- a/components/esm/loadbsgn.hpp +++ b/components/esm/loadbsgn.hpp @@ -3,12 +3,14 @@ #include -#include "record.hpp" #include "spelllist.hpp" namespace ESM { +class ESMReader; +class ESMWriter; + struct BirthSign { std::string mName, mDescription, mTexture; diff --git a/components/esm/loadcell.hpp b/components/esm/loadcell.hpp index 6773235a7..fbd7c0456 100644 --- a/components/esm/loadcell.hpp +++ b/components/esm/loadcell.hpp @@ -4,11 +4,14 @@ #include #include "esmcommon.hpp" -#include "record.hpp" #include "defs.hpp" namespace ESM { + +class ESMReader; +class ESMWriter; + /* Cell reference. This represents ONE object (of many) inside the cell. The cell references are not loaded as part of the normal loading process, but are rather loaded later on demand when we are diff --git a/components/esm/loadclas.hpp b/components/esm/loadclas.hpp index 3897aabed..0311002b8 100644 --- a/components/esm/loadclas.hpp +++ b/components/esm/loadclas.hpp @@ -3,10 +3,12 @@ #include -#include "record.hpp" - namespace ESM { + +class ESMReader; +class ESMWriter; + /* * Character class definitions */ diff --git a/components/esm/loadclot.hpp b/components/esm/loadclot.hpp index 7fc59fdbd..df64c87d3 100644 --- a/components/esm/loadclot.hpp +++ b/components/esm/loadclot.hpp @@ -3,12 +3,14 @@ #include -#include "record.hpp" #include "loadarmo.hpp" namespace ESM { +class ESMReader; +class ESMWriter; + /* * Clothing */ diff --git a/components/esm/loadcont.hpp b/components/esm/loadcont.hpp index d3a89a503..eb1f64d6f 100644 --- a/components/esm/loadcont.hpp +++ b/components/esm/loadcont.hpp @@ -4,12 +4,14 @@ #include #include -#include "record.hpp" #include "esmcommon.hpp" namespace ESM { +class ESMReader; +class ESMWriter; + /* * Container definition */ diff --git a/components/esm/loadcrea.hpp b/components/esm/loadcrea.hpp index e1b1e9310..1c93d995a 100644 --- a/components/esm/loadcrea.hpp +++ b/components/esm/loadcrea.hpp @@ -3,7 +3,6 @@ #include -#include "record.hpp" #include "loadcont.hpp" #include "spelllist.hpp" #include "aipackage.hpp" @@ -11,6 +10,9 @@ namespace ESM { +class ESMReader; +class ESMWriter; + /* * Creature definition * diff --git a/components/esm/loadcrec.hpp b/components/esm/loadcrec.hpp index 0609ea37f..a95656f63 100644 --- a/components/esm/loadcrec.hpp +++ b/components/esm/loadcrec.hpp @@ -1,13 +1,14 @@ #ifndef OPENMW_ESM_CREC_H #define OPENMW_ESM_CREC_H -#include "record.hpp" - // TODO create implementation files and remove this one #include "esmreader.hpp" namespace ESM { +class ESMReader; +class ESMWriter; + /* These two are only used in save games. They are not decoded yet. */ diff --git a/components/esm/loaddial.hpp b/components/esm/loaddial.hpp index d561b9d76..078c78811 100644 --- a/components/esm/loaddial.hpp +++ b/components/esm/loaddial.hpp @@ -1,14 +1,17 @@ #ifndef OPENMW_ESM_DIAL_H #define OPENMW_ESM_DIAL_H +#include #include -#include "record.hpp" #include "loadinfo.hpp" namespace ESM { +class ESMReader; +class ESMWriter; + /* * Dialogue topic and journal entries. The actual data is contained in * the INFO records following the DIAL. diff --git a/components/esm/loaddoor.hpp b/components/esm/loaddoor.hpp index 337c81328..5c0af52e4 100644 --- a/components/esm/loaddoor.hpp +++ b/components/esm/loaddoor.hpp @@ -3,11 +3,12 @@ #include -#include "record.hpp" - namespace ESM { +class ESMReader; +class ESMWriter; + struct Door { std::string mName, mModel, mScript, mOpenSound, mCloseSound; diff --git a/components/esm/loadench.hpp b/components/esm/loadench.hpp index 2894df393..d89549322 100644 --- a/components/esm/loadench.hpp +++ b/components/esm/loadench.hpp @@ -1,11 +1,14 @@ #ifndef OPENMW_ESM_ENCH_H #define OPENMW_ESM_ENCH_H -#include "record.hpp" #include "effectlist.hpp" namespace ESM { + +class ESMReader; +class ESMWriter; + /* * Enchantments */ diff --git a/components/esm/loadfact.hpp b/components/esm/loadfact.hpp index 50c2b42ba..49898b1cf 100644 --- a/components/esm/loadfact.hpp +++ b/components/esm/loadfact.hpp @@ -4,11 +4,12 @@ #include #include -#include "record.hpp" - namespace ESM { +class ESMReader; +class ESMWriter; + /* * Faction definitions */ diff --git a/components/esm/loadglob.hpp b/components/esm/loadglob.hpp index 0147afded..b85af74bc 100644 --- a/components/esm/loadglob.hpp +++ b/components/esm/loadglob.hpp @@ -1,12 +1,14 @@ #ifndef OPENMW_ESM_GLOB_H #define OPENMW_ESM_GLOB_H -#include "record.hpp" #include "defs.hpp" namespace ESM { +class ESMReader; +class ESMWriter; + /* * Global script variables */ diff --git a/components/esm/loadgmst.hpp b/components/esm/loadgmst.hpp index 8435899f5..a3471598c 100644 --- a/components/esm/loadgmst.hpp +++ b/components/esm/loadgmst.hpp @@ -3,11 +3,14 @@ #include -#include "record.hpp" #include "defs.hpp" namespace ESM { + +class ESMReader; +class ESMWriter; + /* * Game setting, with automatic cleaning of "dirty" entries. * diff --git a/components/esm/loadinfo.hpp b/components/esm/loadinfo.hpp index 83d5fe6b4..f04fe862e 100644 --- a/components/esm/loadinfo.hpp +++ b/components/esm/loadinfo.hpp @@ -4,12 +4,14 @@ #include #include -#include "record.hpp" #include "defs.hpp" namespace ESM { +class ESMReader; +class ESMWriter; + // NOT DONE /* diff --git a/components/esm/loadingr.hpp b/components/esm/loadingr.hpp index 3f0423e1c..cd63cf39a 100644 --- a/components/esm/loadingr.hpp +++ b/components/esm/loadingr.hpp @@ -3,10 +3,12 @@ #include -#include "record.hpp" - namespace ESM { + +class ESMReader; +class ESMWriter; + /* * Alchemy ingredient */ diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index 9f85bfb00..5bc439c96 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -3,11 +3,14 @@ #include -#include "record.hpp" #include "esmcommon.hpp" namespace ESM { + +class ESMReader; +class ESMWriter; + /* * Landscape data. */ diff --git a/components/esm/loadlevlist.hpp b/components/esm/loadlevlist.hpp index f39ddd4c2..72b4af92f 100644 --- a/components/esm/loadlevlist.hpp +++ b/components/esm/loadlevlist.hpp @@ -4,11 +4,12 @@ #include #include -#include "record.hpp" - namespace ESM { +class ESMReader; +class ESMWriter; + /* * Leveled lists. Since these have identical layout, I only bothered * to implement it once. diff --git a/components/esm/loadligh.hpp b/components/esm/loadligh.hpp index febbe4a5c..c425af6b3 100644 --- a/components/esm/loadligh.hpp +++ b/components/esm/loadligh.hpp @@ -3,11 +3,12 @@ #include -#include "record.hpp" - namespace ESM { +class ESMReader; +class ESMWriter; + /* * Lights. Includes static light sources and also carryable candles * and torches. diff --git a/components/esm/loadlocks.hpp b/components/esm/loadlocks.hpp index e3a486086..72d375cbb 100644 --- a/components/esm/loadlocks.hpp +++ b/components/esm/loadlocks.hpp @@ -1,11 +1,14 @@ #ifndef OPENMW_ESM_LOCKS_H #define OPENMW_ESM_LOCKS_H -#include "record.hpp" +#include namespace ESM { +class ESMReader; +class ESMWriter; + /* * This file covers lockpicks (LOCK), probes (PROB) and armor repair * items (REPA). These have nearly identical data structures. diff --git a/components/esm/loadltex.hpp b/components/esm/loadltex.hpp index 34aea8314..6e6d987d4 100644 --- a/components/esm/loadltex.hpp +++ b/components/esm/loadltex.hpp @@ -3,11 +3,12 @@ #include -#include "record.hpp" - namespace ESM { +class ESMReader; +class ESMWriter; + /* * Texture used for texturing landscape. * diff --git a/components/esm/loadmgef.hpp b/components/esm/loadmgef.hpp index 1ca7382b0..861f66be0 100644 --- a/components/esm/loadmgef.hpp +++ b/components/esm/loadmgef.hpp @@ -3,11 +3,12 @@ #include -#include "record.hpp" - namespace ESM { +class ESMReader; +class ESMWriter; + struct MagicEffect { enum Flags diff --git a/components/esm/loadmisc.hpp b/components/esm/loadmisc.hpp index f40ac9b79..1a34e6504 100644 --- a/components/esm/loadmisc.hpp +++ b/components/esm/loadmisc.hpp @@ -3,11 +3,12 @@ #include -#include "record.hpp" - namespace ESM { +class ESMReader; +class ESMWriter; + /* * Misc inventory items, basically things that have no use but can be * carried, bought and sold. It also includes keys. diff --git a/components/esm/loadnpc.hpp b/components/esm/loadnpc.hpp index 42a8a70bd..ee9ef6b0b 100644 --- a/components/esm/loadnpc.hpp +++ b/components/esm/loadnpc.hpp @@ -5,12 +5,15 @@ #include #include "defs.hpp" -#include "record.hpp" #include "loadcont.hpp" #include "aipackage.hpp" #include "spelllist.hpp" namespace ESM { + +class ESMReader; +class ESMWriter; + /* * NPC definition */ diff --git a/components/esm/loadnpcc.hpp b/components/esm/loadnpcc.hpp index a056dc701..3da14655f 100644 --- a/components/esm/loadnpcc.hpp +++ b/components/esm/loadnpcc.hpp @@ -1,13 +1,14 @@ #ifndef OPENMW_ESM_NPCC_H #define OPENMW_ESM_NPCC_H -#include "record.hpp" - // TODO: create implementation files to remove this #include "esmreader.hpp" namespace ESM { +class ESMReader; +class ESMWriter; + /* * NPC change information (found in savegame files only). We can't * read these yet. diff --git a/components/esm/loadpgrd.hpp b/components/esm/loadpgrd.hpp index 039812040..c3f50fc4d 100644 --- a/components/esm/loadpgrd.hpp +++ b/components/esm/loadpgrd.hpp @@ -4,11 +4,12 @@ #include #include -#include "record.hpp" - namespace ESM { +class ESMReader; +class ESMWriter; + /* * Path grid. */ diff --git a/components/esm/loadrace.hpp b/components/esm/loadrace.hpp index ae12eec14..42b2c91a7 100644 --- a/components/esm/loadrace.hpp +++ b/components/esm/loadrace.hpp @@ -3,11 +3,14 @@ #include -#include "record.hpp" #include "spelllist.hpp" namespace ESM { + +class ESMReader; +class ESMWriter; + /* * Race definition */ diff --git a/components/esm/loadregn.hpp b/components/esm/loadregn.hpp index 568d096fe..fd0863b5b 100644 --- a/components/esm/loadregn.hpp +++ b/components/esm/loadregn.hpp @@ -4,12 +4,14 @@ #include #include -#include "record.hpp" #include "esmcommon.hpp" namespace ESM { +class ESMReader; +class ESMWriter; + /* * Region data */ diff --git a/components/esm/loadscpt.hpp b/components/esm/loadscpt.hpp index 9c8acd81f..db8f85057 100644 --- a/components/esm/loadscpt.hpp +++ b/components/esm/loadscpt.hpp @@ -4,12 +4,14 @@ #include #include -#include "record.hpp" #include "esmcommon.hpp" namespace ESM { +class ESMReader; +class ESMWriter; + /* * Script definitions */ diff --git a/components/esm/loadskil.hpp b/components/esm/loadskil.hpp index 56ea07929..05bac717b 100644 --- a/components/esm/loadskil.hpp +++ b/components/esm/loadskil.hpp @@ -5,11 +5,13 @@ #include -#include "record.hpp" #include "defs.hpp" namespace ESM { +class ESMReader; +class ESMWriter; + /* * Skill information * diff --git a/components/esm/loadsndg.hpp b/components/esm/loadsndg.hpp index 22d42dc2f..dadfbd239 100644 --- a/components/esm/loadsndg.hpp +++ b/components/esm/loadsndg.hpp @@ -3,11 +3,12 @@ #include -#include "record.hpp" - namespace ESM { +class ESMReader; +class ESMWriter; + /* * Sound generator. This describes the sounds a creature make. */ diff --git a/components/esm/loadsoun.hpp b/components/esm/loadsoun.hpp index 73ee5b22f..5443c6cb9 100644 --- a/components/esm/loadsoun.hpp +++ b/components/esm/loadsoun.hpp @@ -3,11 +3,12 @@ #include -#include "record.hpp" - namespace ESM { +class ESMReader; +class ESMWriter; + struct SOUNstruct { unsigned char mVolume, mMinRange, mMaxRange; diff --git a/components/esm/loadspel.hpp b/components/esm/loadspel.hpp index d96a12a4e..5ad184126 100644 --- a/components/esm/loadspel.hpp +++ b/components/esm/loadspel.hpp @@ -3,12 +3,14 @@ #include -#include "record.hpp" #include "effectlist.hpp" namespace ESM { +class ESMReader; +class ESMWriter; + struct Spell { enum SpellType diff --git a/components/esm/loadsscr.hpp b/components/esm/loadsscr.hpp index 758847f21..d180bfcff 100644 --- a/components/esm/loadsscr.hpp +++ b/components/esm/loadsscr.hpp @@ -3,11 +3,12 @@ #include -#include "record.hpp" - namespace ESM { +class ESMReader; +class ESMWriter; + /* Startup script. I think this is simply a 'main' script that is run from the begining. The SSCR records contain a DATA identifier which diff --git a/components/esm/loadstat.hpp b/components/esm/loadstat.hpp index 45a43082d..ba35fa718 100644 --- a/components/esm/loadstat.hpp +++ b/components/esm/loadstat.hpp @@ -3,10 +3,11 @@ #include -#include "record.hpp" - namespace ESM { +class ESMReader; +class ESMWriter; + /* * Definition of static object. * diff --git a/components/esm/loadweap.hpp b/components/esm/loadweap.hpp index 724c96c88..341a2c86e 100644 --- a/components/esm/loadweap.hpp +++ b/components/esm/loadweap.hpp @@ -3,11 +3,12 @@ #include -#include "record.hpp" - namespace ESM { +class ESMReader; +class ESMWriter; + /* * Weapon definition */ diff --git a/components/esm/record.hpp b/components/esm/record.hpp index 3e5330681..a8c1643e6 100644 --- a/components/esm/record.hpp +++ b/components/esm/record.hpp @@ -1,8 +1,6 @@ #ifndef OPENMW_ESM_RECORD_H #define OPENMW_ESM_RECORD_H -#include - namespace ESM { @@ -55,30 +53,6 @@ enum RecNameInts REC_WEAP = 0x50414557 }; -class ESMReader; -class ESMWriter; - -class Record -{ -public: - Record() {} - virtual ~Record() {} - - virtual void load(ESMReader& esm) = 0; - virtual void save(ESMWriter& esm) = 0; - - std::string getId() const { return mId; } - void setId(const std::string& in) { mId = in; } - - int getFlags() const { return (mFlags & 0x1 ? 0x00002000 : 0) | (mFlags & 0x2 ? 0x00000400 : 0); } - void setFlags(int in) { mFlags = (in & 0x00002000 ? 0x1 : 0) | (in & 0x00000400 ? 0x2 : 0); } - - virtual int getName() = 0; - -protected: - std::string mId; - char mFlags; -}; } diff --git a/components/esm/records.hpp b/components/esm/records.hpp index 97b7cb4a7..0662c797c 100644 --- a/components/esm/records.hpp +++ b/components/esm/records.hpp @@ -1,7 +1,7 @@ #ifndef OPENMW_ESM_RECORDS_H #define OPENMW_ESM_RECORDS_H -#include "record.hpp" +#include "defs.hpp" #include "loadacti.hpp" #include "loadalch.hpp" #include "loadappa.hpp" From 93078bb0dca74cc6df1ff0b3417509fc75f153d0 Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 1 Oct 2012 00:55:27 +0400 Subject: [PATCH 41/48] move record ids to defs.hpp --- components/esm/record.hpp | 59 --------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 components/esm/record.hpp diff --git a/components/esm/record.hpp b/components/esm/record.hpp deleted file mode 100644 index a8c1643e6..000000000 --- a/components/esm/record.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef OPENMW_ESM_RECORD_H -#define OPENMW_ESM_RECORD_H - -namespace ESM -{ - -enum RecNameInts -{ - REC_ACTI = 0x49544341, - REC_ALCH = 0x48434c41, - REC_APPA = 0x41505041, - REC_ARMO = 0x4f4d5241, - REC_BODY = 0x59444f42, - REC_BOOK = 0x4b4f4f42, - REC_BSGN = 0x4e475342, - REC_CELL = 0x4c4c4543, - REC_CLAS = 0x53414c43, - REC_CLOT = 0x544f4c43, - REC_CNTC = 0x43544e43, - REC_CONT = 0x544e4f43, - REC_CREA = 0x41455243, - REC_CREC = 0x43455243, - REC_DIAL = 0x4c414944, - REC_DOOR = 0x524f4f44, - REC_ENCH = 0x48434e45, - REC_FACT = 0x54434146, - REC_GLOB = 0x424f4c47, - REC_GMST = 0x54534d47, - REC_INFO = 0x4f464e49, - REC_INGR = 0x52474e49, - REC_LAND = 0x444e414c, - REC_LEVC = 0x4356454c, - REC_LEVI = 0x4956454c, - REC_LIGH = 0x4847494c, - REC_LOCK = 0x4b434f4c, - REC_LTEX = 0x5845544c, - REC_MGEF = 0x4645474d, - REC_MISC = 0x4353494d, - REC_NPC_ = 0x5f43504e, - REC_NPCC = 0x4343504e, - REC_PGRD = 0x44524750, - REC_PROB = 0x424f5250, - REC_RACE = 0x45434152, - REC_REGN = 0x4e474552, - REC_REPA = 0x41504552, - REC_SCPT = 0x54504353, - REC_SKIL = 0x4c494b53, - REC_SNDG = 0x47444e53, - REC_SOUN = 0x4e554f53, - REC_SPEL = 0x4c455053, - REC_SSCR = 0x52435353, - REC_STAT = 0x54415453, - REC_WEAP = 0x50414557 -}; - - -} - -#endif From 6942fa97da5042e0d3911b8d400c5032a4dbafe4 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 30 Sep 2012 17:23:05 -0700 Subject: [PATCH 42/48] Specify a proper up vector for the listener --- apps/openmw/mwbase/soundmanager.hpp | 2 +- apps/openmw/mwrender/player.cpp | 4 +++- apps/openmw/mwsound/soundmanagerimp.cpp | 5 +++-- apps/openmw/mwsound/soundmanagerimp.hpp | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwbase/soundmanager.hpp b/apps/openmw/mwbase/soundmanager.hpp index 93d1e27e1..745832583 100644 --- a/apps/openmw/mwbase/soundmanager.hpp +++ b/apps/openmw/mwbase/soundmanager.hpp @@ -114,7 +114,7 @@ namespace MWBase virtual void update(float duration) = 0; - virtual void setListenerPosDir(const Ogre::Vector3 &pos, const Ogre::Vector3 &dir) = 0; + virtual void setListenerPosDir(const Ogre::Vector3 &pos, const Ogre::Vector3 &dir, const Ogre::Vector3 &up) = 0; }; inline int operator|(SoundManager::PlayMode a, SoundManager::PlayMode b) diff --git a/apps/openmw/mwrender/player.cpp b/apps/openmw/mwrender/player.cpp index 8c8bbb86f..5e74938b0 100644 --- a/apps/openmw/mwrender/player.cpp +++ b/apps/openmw/mwrender/player.cpp @@ -111,12 +111,14 @@ namespace MWRender { Ogre::Vector3 pos = mCamera->getRealPosition(); Ogre::Vector3 dir = mCamera->getRealDirection(); + Ogre::Vector3 up = mCamera->getRealUp(); Ogre::Real xch; xch = pos.y, pos.y = -pos.z, pos.z = xch; xch = dir.y, dir.y = -dir.z, dir.z = xch; + xch = up.y, up.y = -up.z, up.z = xch; - MWBase::Environment::get().getSoundManager()->setListenerPosDir(pos, dir); + MWBase::Environment::get().getSoundManager()->setListenerPosDir(pos, dir, up); } void Player::update(float duration) diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index dbe45c524..f8f4781f3 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -486,7 +486,7 @@ namespace MWSound mOutput->updateListener( mListenerPos, mListenerDir, - Ogre::Vector3::UNIT_Z, + mListenerUp, env ); @@ -546,10 +546,11 @@ namespace MWSound } } - void SoundManager::setListenerPosDir(const Ogre::Vector3 &pos, const Ogre::Vector3 &dir) + void SoundManager::setListenerPosDir(const Ogre::Vector3 &pos, const Ogre::Vector3 &dir, const Ogre::Vector3 &up) { mListenerPos = pos; mListenerDir = dir; + mListenerUp = up; } // Default readAll implementation, for decoders that can't do anything diff --git a/apps/openmw/mwsound/soundmanagerimp.hpp b/apps/openmw/mwsound/soundmanagerimp.hpp index 6931e5325..f91e291ef 100644 --- a/apps/openmw/mwsound/soundmanagerimp.hpp +++ b/apps/openmw/mwsound/soundmanagerimp.hpp @@ -52,6 +52,7 @@ namespace MWSound Ogre::Vector3 mListenerPos; Ogre::Vector3 mListenerDir; + Ogre::Vector3 mListenerUp; std::string lookup(const std::string &soundId, float &volume, float &min, float &max); @@ -128,7 +129,7 @@ namespace MWSound virtual void update(float duration); - virtual void setListenerPosDir(const Ogre::Vector3 &pos, const Ogre::Vector3 &dir); + virtual void setListenerPosDir(const Ogre::Vector3 &pos, const Ogre::Vector3 &dir, const Ogre::Vector3 &up); }; } From 6c5c9ce46e02cda50758679b580e9cad2aa44e9d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 30 Sep 2012 17:38:55 -0700 Subject: [PATCH 43/48] Avoid console spam when a sound can't play --- apps/openmw/mwsound/soundmanagerimp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index f8f4781f3..706cb4e24 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -296,7 +296,7 @@ namespace MWSound } catch(std::exception &e) { - std::cout <<"Sound Error: "< Date: Mon, 1 Oct 2012 11:24:44 +0400 Subject: [PATCH 44/48] updateListener() every frame --- apps/openmw/mwrender/player.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/player.cpp b/apps/openmw/mwrender/player.cpp index 8c8bbb86f..51e7fa745 100644 --- a/apps/openmw/mwrender/player.cpp +++ b/apps/openmw/mwrender/player.cpp @@ -94,7 +94,6 @@ namespace MWRender } else { mCameraNode->setOrientation(zr * xr); } - updateListener(); } std::string Player::getHandle() const @@ -121,6 +120,8 @@ namespace MWRender void Player::update(float duration) { + updateListener(); + // only show the crosshair in game mode and in first person mode. MWBase::Environment::get().getWindowManager ()->showCrosshair (!MWBase::Environment::get().getWindowManager ()->isGuiMode () && (mFirstPersonView && !mVanity.enabled && !mPreviewMode)); From d1c4559abe07c27cea5c15883a8ec07bd32fddef Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 1 Oct 2012 10:03:49 +0200 Subject: [PATCH 45/48] fixed GMST string handling in GUI --- apps/openmw/mwbase/windowmanager.hpp | 2 +- apps/openmw/mwgui/windowmanagerimp.cpp | 4 ++-- apps/openmw/mwgui/windowmanagerimp.hpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 8ea9e5cef..d1daa101d 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -213,7 +213,7 @@ namespace MWBase * @param id Identifier for the GMST setting, e.g. "aName" * @param default Default value if the GMST setting cannot be used. */ - virtual const std::string &getGameSettingString(const std::string &id, const std::string &default_) = 0; + virtual std::string getGameSettingString(const std::string &id, const std::string &default_) = 0; virtual void processChangedSettings(const Settings::CategorySettingVector& changed) = 0; diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 87a2bc440..2b592e2ca 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -520,9 +520,9 @@ int WindowManager::readPressedButton () return mMessageBoxManager->readPressedButton(); } -const std::string &WindowManager::getGameSettingString(const std::string &id, const std::string &default_) +std::string WindowManager::getGameSettingString(const std::string &id, const std::string &default_) { - const ESM::GameSetting *setting = MWBase::Environment::get().getWorld()->getStore().gameSettings.find(id); + const ESM::GameSetting *setting = MWBase::Environment::get().getWorld()->getStore().gameSettings.search(id); if (setting && setting->mType == ESM::VT_String) return setting->getString(); return default_; diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index e30e110d3..f67559ccd 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -196,7 +196,7 @@ namespace MWGui * @param id Identifier for the GMST setting, e.g. "aName" * @param default Default value if the GMST setting cannot be used. */ - virtual const std::string &getGameSettingString(const std::string &id, const std::string &default_); + virtual std::string getGameSettingString(const std::string &id, const std::string &default_); virtual void processChangedSettings(const Settings::CategorySettingVector& changed); From 31f7325e1f170d4e2efd948f9eaa516f50dd182c Mon Sep 17 00:00:00 2001 From: greye Date: Mon, 1 Oct 2012 15:46:32 +0400 Subject: [PATCH 46/48] fix land loading --- components/esm/loadland.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index ec5ea5052..e1af0ee7c 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -169,7 +169,7 @@ void Land::loadData(int flags) mEsm->restoreContext(mContext); memset(mLandData->mNormals, 0, LAND_NUM_VERTS * 3); - + if (mEsm->isNextSub("VNML")) { condLoad(actual, DATA_VNML, mLandData->mNormals, sizeof(VNML)); } @@ -231,10 +231,7 @@ void Land::unloadData() bool Land::condLoad(int flags, int dataFlag, void *ptr, unsigned int size) { - if ((mDataLoaded & dataFlag) != 0) { - return false; - } - if (flags & dataFlag) { + if ((mDataLoaded & dataFlag) == 0 && (flags & dataFlag) != 0) { mEsm->getHExact(ptr, size); mDataLoaded |= dataFlag; return true; From 1f087645a772bb904c2013c8ccd08ddbdb175a03 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 1 Oct 2012 17:02:14 +0200 Subject: [PATCH 47/48] update shiny to auto-delete the corresponding cache if a shader was edited --- extern/shiny | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/shiny b/extern/shiny index 4750676ac..ffd078843 160000 --- a/extern/shiny +++ b/extern/shiny @@ -1 +1 @@ -Subproject commit 4750676ac46a7aaa86bca53dc68c5a1ba11f3bc1 +Subproject commit ffd078843c11586107024ccbc2493d0ec2df896c From fa358ab1963a312f549bcf1120ba1dcdc50b5b29 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 1 Oct 2012 18:04:21 +0200 Subject: [PATCH 48/48] change the inventory preview to "inventoryhandtohand" animation pose --- apps/openmw/mwrender/characterpreview.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/openmw/mwrender/characterpreview.cpp b/apps/openmw/mwrender/characterpreview.cpp index f755f34ef..017062baa 100644 --- a/apps/openmw/mwrender/characterpreview.cpp +++ b/apps/openmw/mwrender/characterpreview.cpp @@ -118,6 +118,9 @@ namespace MWRender void InventoryPreview::onSetup () { mSelectionBuffer = new OEngine::Render::SelectionBuffer(mCamera, 512, 1024, RV_PlayerPreview); + + mAnimation->playGroup ("inventoryhandtohand", 0, 1); + mAnimation->runAnimation (0); } // --------------------------------------------------------------------------------------------------