Common::UString Module::getName(const Common::UString &module) { /* Return the localized name of the first (and only) area of the module, * which is the closest thing to the name of the module. * * To do that, if looks through the module directory for a matching RIM file * (case-insensitively) and opens it without indexing into the ResourceManager. * It then opens the module.ifo, grabs the name of the area, opens its ARE file * and returns the localized "Name" field. * * If there's any error while doing all this, an empty string is returned. */ try { const Common::FileList modules(ConfigMan.getString("KOTOR_moduleDir")); const Aurora::RIMFile rim(new Common::ReadFile(modules.findFirst(module + ".rim", true))); const uint32 ifoIndex = rim.findResource("module", Aurora::kFileTypeIFO); const Aurora::GFF3File ifo(rim.getResource(ifoIndex), MKTAG('I', 'F', 'O', ' ')); const Aurora::GFF3List &areas = ifo.getTopLevel().getList("Mod_Area_list"); if (areas.empty()) return ""; const uint32 areIndex = rim.findResource((*areas.begin())->getString("Area_Name"), Aurora::kFileTypeARE); const Aurora::GFF3File are(rim.getResource(areIndex), MKTAG('A', 'R', 'E', ' ')); return are.getTopLevel().getString("Name"); } catch (...) { } return ""; }
void Campaign::loadCampaignFile(const CampaignDescription &desc) { Common::ReadFile *file = 0; Aurora::GFF3File *gff = 0; try { try { if (desc.file.empty()) throw Common::Exception("Campaign file is empty"); file = new Common::ReadFile(desc.file); gff = new Aurora::GFF3File(file, MKTAG('M', 'M', 'D', ' ')); } catch (Common::Exception &UNUSED(e)) { delete file; throw; } _startModule = gff->getTopLevel().getString("StartingMod"); const Aurora::GFF3List &modules = gff->getTopLevel().getList("Meta_Mod_list"); for (Aurora::GFF3List::const_iterator m = modules.begin(); m != modules.end(); ++m) _modules.push_back((*m)->getString("Mod_Name")); if (_startModule.empty()) throw Common::Exception("No starting module"); } catch (Common::Exception &e) { delete gff; e.add("Failed to load campaign \"%s\" (\"%s\")", desc.tag.c_str(), desc.name.getString().c_str()); throw; } delete gff; }
bool Campaign::readCampaign(const Common::UString &mmdFile, CampaignDescription &desc) { Common::ReadFile *file = new Common::ReadFile; if (!file->open(mmdFile)) { delete file; return false; } Aurora::GFF3File *gff = 0; try { gff = new Aurora::GFF3File(file, MKTAG('M', 'M', 'D', ' ')); } catch (...) { return false; } gff->getTopLevel().getLocString("Meta_Name", desc.name); gff->getTopLevel().getLocString("Meta_Desc", desc.description); delete gff; desc.file = mmdFile; desc.tag = Common::FilePath::getStem(mmdFile).toLower(); return true; }
void Placeable::load(const Aurora::GFF3Struct &placeable) { Common::UString temp = placeable.getString("TemplateResRef"); Aurora::GFF3File *utp = 0; if (!temp.empty()) { try { utp = new Aurora::GFF3File(temp, Aurora::kFileTypeUTP, MKTAG('U', 'T', 'P', ' ')); } catch (...) { } } Situated::load(placeable, utp ? &utp->getTopLevel() : 0); delete utp; }
void Waypoint::load(const Aurora::GFF3Struct &waypoint) { Common::UString temp = waypoint.getString("TemplateResRef"); Aurora::GFF3File *utw = 0; if (!temp.empty()) { try { utw = new Aurora::GFF3File(temp, Aurora::kFileTypeUTW, MKTAG('U', 'T', 'W', ' ')); } catch (...) { } } load(waypoint, utw ? &utw->getTopLevel() : 0); delete utw; }
Common::UString Module::getDescription(const Common::UString &module) { try { const Common::FileList modules(ConfigMan.getString("NWN2_moduleDir")); const Aurora::ERFFile mod(new Common::ReadFile(modules.findFirst(module + ".mod", true))); const uint32 ifoIndex = mod.findResource("module", Aurora::kFileTypeIFO); const Aurora::GFF3File ifo(mod.getResource(ifoIndex), MKTAG('I', 'F', 'O', ' ')); return ifo.getTopLevel().getString("Mod_Description"); } catch (...) { } return ""; }
void Door::load(const Aurora::GFF3Struct &door) { Common::UString temp = door.getString("TemplateResRef"); Aurora::GFF3File *utd = 0; if (!temp.empty()) { try { utd = new Aurora::GFF3File(temp, Aurora::kFileTypeUTD, MKTAG('U', 'T', 'D', ' ')); } catch (...) { } } Situated::load(door, utd ? &utd->getTopLevel() : 0); delete utd; setModelState(); }
void Trigger::load(const Aurora::GFF3Struct &trigger) { Common::UString temp = trigger.getString("ResRef"); if (!temp.empty()) { Aurora::GFF3File *trg = 0; try { trg = new Aurora::GFF3File(temp, Aurora::kFileTypeTRG, MKTAG('T', 'R', 'G', ' ')); loadBlueprint(trg->getTopLevel()); } catch (...) { warning("Trigger \"%s\" has no blueprint", temp.c_str()); delete trg; throw; } delete trg; } loadInstance(trigger); }
void GUI::load(const Common::UString &resref) { _name = resref; Aurora::GFF3File *gff = 0; try { gff = new Aurora::GFF3File(resref, Aurora::kFileTypeGUI, MKTAG('G', 'U', 'I', ' ')); loadWidget(gff->getTopLevel(), 0); } catch (Common::Exception &e) { delete gff; e.add("Can't load GUI \"%s\"", resref.c_str()); throw; } delete gff; }
void Placeable::load(const Aurora::GFF3Struct &placeable) { _resRef = placeable.getString("TemplateResRef"); Aurora::GFF3File *utp = 0; if (!_resRef.empty()) { try { utp = new Aurora::GFF3File(_resRef, Aurora::kFileTypeUTP, MKTAG('U', 'T', 'P', ' ')); } catch (...) { } } try { load(placeable, utp ? &utp->getTopLevel() : 0); } catch (...) { delete utp; throw; } delete utp; }
void Creature::loadCharacter(const Common::UString &bic, bool local) { Aurora::GFF3File *gff = openPC(bic, local); try { load(gff->getTopLevel(), 0); } catch (...) { delete gff; throw; } delete gff; // All BICs should be PCs. _isPC = true; // Set the PC tag to something recognizable for now. // Let's hope no script depends on it being "". _tag = Common::UString::format("[PC: %s]", _name.c_str()); }
void Creature::load(const Aurora::GFF3Struct &creature) { Common::UString temp = creature.getString("TemplateResRef"); Aurora::GFF3File *utc = 0; if (!temp.empty()) { try { utc = new Aurora::GFF3File(temp, Aurora::kFileTypeUTC, MKTAG('U', 'T', 'C', ' ')); } catch (...) { } } try { load(creature, utc ? &utc->getTopLevel() : 0); } catch (...) { delete utc; throw; } delete utc; }
void Creature::getPCListInfo(const Common::UString &bic, bool local, Common::UString &name, Common::UString &classes, Common::UString &portrait) { Aurora::GFF3File *gff = openPC(bic, local); try { const Aurora::GFF3Struct &top = gff->getTopLevel(); // Reading name const Common::UString firstName = top.getString("FirstName"); const Common::UString lastName = top.getString("LastName"); name = firstName + " " + lastName; name.trim(); // Reading portrait (failure non-fatal) try { loadPortrait(top, portrait); } catch (...) { portrait.clear(); Common::exceptionDispatcherWarning("Can't read portrait for PC \"%s\"", bic.c_str()); } // Reading classes std::vector<Class> classLevels; uint8 hitDice; loadClasses(top, classLevels, hitDice); getClassString(classLevels, classes); classes = "(" + classes + ")"; } catch (...) { delete gff; throw; } delete gff; }
void Placeable::load(const Aurora::GFF3Struct &placeable) { Common::UString temp = placeable.getString("TemplateResRef"); Aurora::GFF3File *utp = 0; if (!temp.empty()) { try { utp = new Aurora::GFF3File(temp, Aurora::kFileTypeUTP, MKTAG('U', 'T', 'P', ' ')); } catch (...) { } } try { Situated::load(placeable, utp ? &utp->getTopLevel() : 0); } catch (...) { delete utp; throw; } if (!utp) warning("Placeable \"%s\" has no blueprint", _tag.c_str()); delete utp; }