void Dialogue::load(ESMReader &esm) { esm.getSubNameIs("DATA"); esm.getSubHeader(); int si = esm.getSubSize(); if (si == 1) esm.getT(type); else if (si == 4) { // These are just markers, their values are not used. int i; esm.getT(i); esm.getHNT(i, "DELE"); type = Deleted; } else esm.fail("Unknown sub record size"); }
void printRaw(ESMReader &esm) { while(esm.hasMoreRecs()) { NAME n = esm.getRecName(); cout << "Record: " << n.toString() << endl; esm.getRecHeader(); while(esm.hasMoreSubs()) { uint64_t offs = esm.getOffset(); esm.getSubName(); esm.skipHSub(); n = esm.retSubName(); cout << " " << n.toString() << " - " << esm.getSubSize() << " bytes @ 0x" << hex << offs << "\n"; } } }
void ESM::GlobalMap::load (ESMReader &esm) { esm.getHNT(mBounds, "BNDS"); esm.getSubNameIs("DATA"); esm.getSubHeader(); mImageData.resize(esm.getSubSize()); esm.getExact(&mImageData[0], mImageData.size()); while (esm.isNextSub("MRK_")) { esm.getSubHeader(); CellId cell; esm.getT(cell.first); esm.getT(cell.second); mMarkers.push_back(cell); } }
void Pathgrid::load(ESMReader &esm) { esm.getHNT(mData, "DATA", 12); mCell = esm.getHNString("NAME"); // keep track of total connections so we can reserve edge vector size int edgeCount = 0; if (esm.isNextSub("PGRP")) { esm.getSubHeader(); int size = esm.getSubSize(); // Check that the sizes match up. Size = 16 * s2 (path points) if (size != static_cast<int> (sizeof(Point) * mData.mS2)) esm.fail("Path point subrecord size mismatch"); else { int pointCount = mData.mS2; mPoints.reserve(pointCount); for (int i = 0; i < pointCount; ++i) { Point p; esm.getExact(&p, sizeof(Point)); mPoints.push_back(p); edgeCount += p.mConnectionNum; } } } if (esm.isNextSub("PGRC")) { esm.getSubHeader(); int size = esm.getSubSize(); if (size % sizeof(int) != 0) esm.fail("PGRC size not a multiple of 4"); else { int rawConnNum = size / sizeof(int); std::vector<int> rawConnections; rawConnections.reserve(rawConnNum); for (int i = 0; i < rawConnNum; ++i) { int currentValue; esm.getT(currentValue); rawConnections.push_back(currentValue); } std::vector<int>::const_iterator rawIt = rawConnections.begin(); int pointIndex = 0; mEdges.reserve(edgeCount); for(PointList::const_iterator it = mPoints.begin(); it != mPoints.end(); ++it, ++pointIndex) { unsigned char connectionNum = (*it).mConnectionNum; for (int i = 0; i < connectionNum; ++i) { Edge edge; edge.mV0 = pointIndex; edge.mV1 = *rawIt; ++rawIt; mEdges.push_back(edge); } } } } }
void NPC::load(ESMReader &esm) { mPersistent = (esm.getRecordFlags() & 0x0400) != 0; mSpells.mList.clear(); mInventory.mList.clear(); mTransport.mList.clear(); mAiPackage.mList.clear(); bool hasNpdt = false; bool hasFlags = false; mHasAI = false; while (esm.hasMoreSubs()) { esm.getSubName(); uint32_t name = esm.retSubName().val; switch (name) { case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; case ESM::FourCC<'F','N','A','M'>::value: mName = esm.getHString(); break; case ESM::FourCC<'R','N','A','M'>::value: mRace = esm.getHString(); break; case ESM::FourCC<'C','N','A','M'>::value: mClass = esm.getHString(); break; case ESM::FourCC<'A','N','A','M'>::value: mFaction = esm.getHString(); break; case ESM::FourCC<'B','N','A','M'>::value: mHead = esm.getHString(); break; case ESM::FourCC<'K','N','A','M'>::value: mHair = esm.getHString(); break; case ESM::FourCC<'S','C','R','I'>::value: mScript = esm.getHString(); break; case ESM::FourCC<'N','P','D','T'>::value: hasNpdt = true; esm.getSubHeader(); if (esm.getSubSize() == 52) { mNpdtType = NPC_DEFAULT; esm.getExact(&mNpdt52, 52); } else if (esm.getSubSize() == 12) { mNpdtType = NPC_WITH_AUTOCALCULATED_STATS; esm.getExact(&mNpdt12, 12); } else esm.fail("NPC_NPDT must be 12 or 52 bytes long"); break; case ESM::FourCC<'F','L','A','G'>::value: hasFlags = true; esm.getHT(mFlags); break; case ESM::FourCC<'N','P','C','S'>::value: mSpells.add(esm); break; case ESM::FourCC<'N','P','C','O'>::value: mInventory.add(esm); break; case ESM::FourCC<'A','I','D','T'>::value: esm.getHExact(&mAiData, sizeof(mAiData)); mHasAI= true; break; case ESM::FourCC<'D','O','D','T'>::value: case ESM::FourCC<'D','N','A','M'>::value: mTransport.add(esm); break; case AI_Wander: case AI_Activate: case AI_Escort: case AI_Follow: case AI_Travel: case AI_CNDT: mAiPackage.add(esm); break; default: esm.fail("Unknown subrecord"); } } if (!hasNpdt) esm.fail("Missing NPDT subrecord"); if (!hasFlags) esm.fail("Missing FLAG subrecord"); }
void NPC::load(ESMReader &esm, bool &isDeleted) { isDeleted = false; mPersistent = (esm.getRecordFlags() & 0x0400) != 0; mSpells.mList.clear(); mInventory.mList.clear(); mTransport.mList.clear(); mAiPackage.mList.clear(); mAiData.blank(); mAiData.mHello = mAiData.mFight = mAiData.mFlee = 30; bool hasName = false; bool hasNpdt = false; bool hasFlags = false; while (esm.hasMoreSubs()) { esm.getSubName(); switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); hasName = true; break; case ESM::FourCC<'M','O','D','L'>::value: mModel = esm.getHString(); break; case ESM::FourCC<'F','N','A','M'>::value: mName = esm.getHString(); break; case ESM::FourCC<'R','N','A','M'>::value: mRace = esm.getHString(); break; case ESM::FourCC<'C','N','A','M'>::value: mClass = esm.getHString(); break; case ESM::FourCC<'A','N','A','M'>::value: mFaction = esm.getHString(); break; case ESM::FourCC<'B','N','A','M'>::value: mHead = esm.getHString(); break; case ESM::FourCC<'K','N','A','M'>::value: mHair = esm.getHString(); break; case ESM::FourCC<'S','C','R','I'>::value: mScript = esm.getHString(); break; case ESM::FourCC<'N','P','D','T'>::value: hasNpdt = true; esm.getSubHeader(); if (esm.getSubSize() == 52) { mNpdtType = NPC_DEFAULT; esm.getExact(&mNpdt, 52); } else if (esm.getSubSize() == 12) { //Reading into temporary NPDTstruct12 object NPDTstruct12 npdt12; mNpdtType = NPC_WITH_AUTOCALCULATED_STATS; esm.getExact(&npdt12, 12); //Clearing the mNdpt struct to initialize all values blankNpdt(); //Swiching to an internal representation mNpdt.mLevel = npdt12.mLevel; mNpdt.mDisposition = npdt12.mDisposition; mNpdt.mReputation = npdt12.mReputation; mNpdt.mRank = npdt12.mRank; mNpdt.mGold = npdt12.mGold; } else esm.fail("NPC_NPDT must be 12 or 52 bytes long"); break; case ESM::FourCC<'F','L','A','G'>::value: hasFlags = true; esm.getHT(mFlags); break; case ESM::FourCC<'N','P','C','S'>::value: mSpells.add(esm); break; case ESM::FourCC<'N','P','C','O'>::value: mInventory.add(esm); break; case ESM::FourCC<'A','I','D','T'>::value: esm.getHExact(&mAiData, sizeof(mAiData)); break; case ESM::FourCC<'D','O','D','T'>::value: case ESM::FourCC<'D','N','A','M'>::value: mTransport.add(esm); break; case AI_Wander: case AI_Activate: case AI_Escort: case AI_Follow: case AI_Travel: case AI_CNDT: mAiPackage.add(esm); break; case ESM::SREC_DELE: esm.skipHSub(); isDeleted = true; break; default: esm.fail("Unknown subrecord"); break; } } if (!hasName) esm.fail("Missing NAME subrecord"); if (!hasNpdt && !isDeleted) esm.fail("Missing NPDT subrecord"); if (!hasFlags && !isDeleted) esm.fail("Missing FLAG subrecord"); }