void listFiles(Aurora::HERFFile &herf) { const Aurora::Archive::ResourceList &resources = herf.getResources(); const size_t fileCount = resources.size(); std::printf("Number of files: %u\n\n", (uint)fileCount); std::printf(" Filename | Size\n"); std::printf("=======================================|===========\n"); for (Aurora::Archive::ResourceList::const_iterator r = resources.begin(); r != resources.end(); ++r) { Common::UString fileName = r->name, fileExt = TypeMan.setFileType("", r->type); if (fileName.empty()) findHashedName(r->hash, fileName, fileExt); std::printf("%32s%-6s | %10d\n", fileName.c_str(), fileExt.c_str(), herf.getResourceSize(r->index)); } }
void Campaign::readManifest(const Common::UString &path) { if (path.empty()) return; Common::ReadFile manifest(path); Common::XMLParser xml(manifest, true); const Common::XMLNode &root = xml.getRoot(); if ((root.getName() != "manifest") || (root.getProperty("type") != "AddIn")) throw Common::Exception("manifest.xml is not an AddIn manifest: \"%s\", \"%s\"", root.getName().c_str(), root.getProperty("type").c_str()); const Common::XMLNode *addinList = root.findChild("addinslist"); if (!addinList) throw Common::Exception("Manifest has no AddInList"); const Common::XMLNode *addinItem = 0; const Common::XMLNode::Children &addinItems = addinList->getChildren(); for (Common::XMLNode::Children::const_iterator c = addinItems.begin(); c != addinItems.end(); ++c) { if ((*c)->getName() == "addinitem") { if (addinItem) throw Common::Exception("Manifest has more than one AddInItem"); addinItem = *c; } } if (!addinItem) throw Common::Exception("Manifest has no AddInItem"); _uid = addinItem->getProperty("uid"); _tag = addinItem->getProperty("name"); _extends = addinItem->getProperty("extendedmoduleuid"); Common::parseString(addinItem->getProperty("enabled" , "0"), _enabled); Common::parseString(addinItem->getProperty("bioware" , "0"), _bioware); Common::parseString(addinItem->getProperty("requiresauthorization", "0"), _needsAuth); Common::parseString(addinItem->getProperty("priority", "0xFFFFFFFF"), _priority); Common::parseString(addinItem->getProperty("state" , "0xFFFFFFFF"), _state); Common::parseString(addinItem->getProperty("format", "0xFFFFFFFF"), _format); }
void extractFiles(Aurora::ERFFile &erf, Aurora::GameID game, std::set<Common::UString> &files, ExtractMode mode) { const Aurora::Archive::ResourceList &resources = erf.getResources(); const size_t fileCount = resources.size(); std::printf("Number of files: %u\n\n", (uint)fileCount); size_t i = 1; for (Aurora::Archive::ResourceList::const_iterator r = resources.begin(); r != resources.end(); ++r, ++i) { Common::UString name = r->name; if (name.empty()) findHashedName(r->hash, name); name.replaceAll('\\', '/'); if (mode == kExtractModeStrip) name = Common::FilePath::getFile(name); const Aurora::FileType type = TypeMan.aliasFileType(r->type, game); Common::UString fileName = TypeMan.addFileType(name, type); if (!files.empty() && (files.find(fileName) == files.end())) continue; if (mode == kExtractModeSubstitute) fileName.replaceAll('/', '='); std::printf("Extracting %u/%u: %s ... ", (uint)i, (uint)fileCount, fileName.c_str()); Common::SeekableReadStream *stream = 0; try { stream = erf.getResource(r->index); dumpStream(*stream, fileName); std::printf("Done\n"); } catch (Common::Exception &e) { Common::printException(e, ""); } delete stream; } }
void Door::load(const Aurora::GFFStruct &door) { Common::UString temp = door.getString("TemplateResRef"); Aurora::GFFFile *utd = 0; if (!temp.empty()) { try { utd = new Aurora::GFFFile(temp, Aurora::kFileTypeUTD, MKTAG('U', 'T', 'D', ' ')); } catch (...) { delete utd; } } Situated::load(door, utd ? &utd->getTopLevel() : 0); delete utd; setModelState(); }
bool ConsoleWindow::setRedirect(Common::UString redirect) { _redirect.flush(); _redirect.close(); if (redirect.empty()) return true; redirect = Common::FilePath::makeAbsolute(redirect); if (!_redirect.open(redirect)) { Common::UString error = Common::UString::sprintf("Failed opening file \"%s\" for writing.", redirect.c_str()); print(error); return false; } return true; }
void Trigger::load(const Aurora::GFF3Struct &trigger) { Common::UString temp = trigger.getString("ResRef"); if (!temp.empty()) { try { Common::ScopedPtr<Aurora::GFF3File> trg(new Aurora::GFF3File(temp, Aurora::kFileTypeTRG, MKTAG('T', 'R', 'G', ' '))); loadBlueprint(trg->getTopLevel()); } catch (Common::Exception &e) { e.add("Trigger \"%s\" has no blueprint", temp.c_str()); throw; } } loadInstance(trigger); }
void GUIQuad::setTexture(const Common::UString &texture) { GfxMan.lockFrame(); try { if (texture.empty()) _texture.clear(); else _texture = TextureMan.get(texture); } catch (...) { _texture.clear(); _r = _g = _b = _a = 0.0; } GfxMan.unlockFrame(); }
void Object::loadSSF() { if (_ssf || (_soundSet == Aurora::kFieldIDInvalid)) return; const Aurora::TwoDAFile &soundSets = TwoDAReg.get("soundset"); Common::UString ssfFile = soundSets.getRow(_soundSet).getString("RESREF"); if (ssfFile.empty()) return; try { _ssf = new Aurora::SSFFile(ssfFile); } catch (...) { warning("Failed to load SSF \"%s\" (object \"%s\")", ssfFile.c_str(), _tag.c_str()); delete _ssf; _ssf = 0; } }
void Module::usePC(const Common::UString &bic, bool local) { unloadPC(); if (bic.empty()) throw Common::Exception("Tried to load an empty PC"); try { _pc = new Creature(bic, local); } catch (Common::Exception &e) { e.add("Can't load PC \"%s\"", bic.c_str()); throw e; } setPCTokens(); LangMan.setCurrentGender(_pc->isFemale() ? Aurora::kLanguageGenderFemale : Aurora::kLanguageGenderMale); addObject(*_pc); }
Language LanguageManager::parseLanguage(Common::UString str) { if (str.empty()) return kLanguageInvalid; str.makeLower(); for (size_t i = 0; i < ARRAYSIZE(kLanguageStrings); i++) { for (size_t j = 0; j < ARRAYSIZE(kLanguageStrings[i].strings); j++) { if (!kLanguageStrings[i].strings[j]) break; if (str == kLanguageStrings[i].strings[j]) return kLanguageStrings[i].language; } } return kLanguageInvalid; }
Encoding parseEncoding(Common::UString str) { if (str.empty()) return kEncodingInvalid; str.makeLower(); for (size_t i = 0; i < ARRAYSIZE(kEncodingStrings); i++) { for (size_t j = 0; j < ARRAYSIZE(kEncodingStrings[i].strings); j++) { if (!kEncodingStrings[i].strings[j]) break; if (str == kEncodingStrings[i].strings[j]) return kEncodingStrings[i].encoding; } } return kEncodingInvalid; }
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 Dialog::updateBox() { GfxMan.lockFrame(); _dlgBox->clear(); // Entry const Aurora::DLGFile::Line *entry = _dlg->getCurrentEntry(); if (entry) { // Name and portrait Object *speaker = getSpeaker(); if (speaker) { _dlgBox->setPortrait(speaker->getPortrait()); _dlgBox->setName(speaker->getName()); } else _dlgBox->setName("[INVALID NPC]"); // Text _dlgBox->setEntry(entry->text.getString()); } // Replies const std::vector<const Aurora::DLGFile::Line *> &replies = _dlg->getCurrentReplies(); if (!replies.empty()) { for (std::vector<const Aurora::DLGFile::Line *>::const_iterator r = replies.begin(); r != replies.end(); ++r) { Common::UString text = (*r)->text.getString(); if (text.empty()) text = TalkMan.getString((*r)->isEnd ? kEndDialog : kContinue); _dlgBox->addReply(text, (*r)->id); } } else _dlgBox->addReply(TalkMan.getString(kEndDialog), Aurora::DLGFile::kEndLine); _dlgBox->finishReplies(); GfxMan.unlockFrame(); }
void GUIQuad::setTexture(const Common::UString &texture) { lockFrameIfVisible(); try { if (texture.empty()) _texture.clear(); else _texture = TextureMan.get(texture); } catch (...) { _texture.clear(); _r = _g = _b = _a = 0.0f; } buildMaterial(); unlockFrameIfVisible(); }
void Creature::load(const Aurora::GFFStruct &creature) { Common::UString temp = creature.getString("TemplateResRef"); Aurora::GFFFile *utc = 0; if (!temp.empty()) { try { utc = new Aurora::GFFFile(temp, Aurora::kFileTypeUTC, MKTAG('U', 'T', 'C', ' ')); } catch (...) { delete utc; } } load(creature, utc ? &utc->getTopLevel() : 0); if (!utc) warning("Creature \"%s\" has no blueprint", _tag.c_str()); delete utc; }
static bool resolveLangInvalid(const std::vector<Aurora::Language> &langs, Aurora::Language &lang, const Common::UString &conf, const Common::UString &specifier, bool find) { if (lang != Aurora::kLanguageInvalid) return true; if (!find || langs.empty()) return false; if (!conf.empty()) warning("Failed to parse \"%s\" into a language", conf.c_str()); lang = langs.front(); status("Using the first available language (%s)%s", Aurora::getLanguageName(lang).c_str(), specifier.c_str()); return true; }
void Door::load(const Aurora::GFFStruct &door) { Common::UString temp = door.getString("TemplateResRef"); Aurora::GFFFile *utd = 0; if (!temp.empty()) { try { utd = new Aurora::GFFFile(temp, Aurora::kFileTypeUTD, MKTAG('U', 'T', 'D', ' ')); } catch (...) { delete utd; } } Situated::load(door, utd ? &utd->getTopLevel() : 0); if (!utd) warning("Door \"%s\" has no blueprint", _tag.c_str()); delete utd; }
void Placeable::load(const Aurora::GFFStruct &placeable) { Common::UString temp = placeable.getString("TemplateResRef"); Aurora::GFFFile *utp = 0; if (!temp.empty()) { try { utp = new Aurora::GFFFile(temp, Aurora::kFileTypeUTP, MKID_BE('UTP ')); } catch (...) { delete utp; } } Situated::load(placeable, utp ? &utp->getTopLevel() : 0); if (!utp) warning("Placeable \"%s\" has no blueprint", _tag.c_str()); delete utp; }
void NWNEngine::getModules(std::vector<Common::UString> &modules) { modules.clear(); Common::UString moduleDir = ConfigMan.getString("NWN_extraModuleDir"); if (moduleDir.empty()) return; Common::FileList mods; mods.addDirectory(moduleDir); for (Common::FileList::const_iterator m = mods.begin(); m != mods.end(); ++m) { if (!Common::FilePath::getExtension(*m).equalsIgnoreCase(".mod")) continue; modules.push_back(Common::FilePath::getStem(*m)); } std::sort(modules.begin(), modules.end(), Common::UString::iless()); }
void Game::getCharacters(std::vector<Common::UString> &characters, bool local) { characters.clear(); Common::UString pcDir = ConfigMan.getString(local ? "NWN2_localPCDir" : "NWN2_serverPCDir"); if (pcDir.empty()) return; Common::FileList chars; chars.addDirectory(pcDir); for (Common::FileList::const_iterator c = chars.begin(); c != chars.end(); ++c) { if (!Common::FilePath::getExtension(*c).equalsIgnoreCase(".bic")) continue; characters.push_back(Common::FilePath::getStem(*c)); } std::sort(characters.begin(), characters.end(), Common::UString::iless()); }
void Functions::beginConversation(Aurora::NWScript::FunctionContext &ctx) { ctx.getReturn() = 0; // Get the script object parameters Aurora::NWScript::Object *obj1 = ctx.getCaller(); Aurora::NWScript::Object *obj2 = getParamObject(ctx, 1); if (!obj2) obj2 = ctx.getTriggerer(); if (!obj2) obj2 = _game->getModule().getPC(); // Try to convert them to an NWN Creature and Object NWN::Creature *pc = NWN::ObjectContainer::toPC(obj2); NWN::Object *object = NWN::ObjectContainer::toObject(obj1); // Try the other way round, if necessary if (!pc || !object) { pc = NWN::ObjectContainer::toPC(obj1); object = NWN::ObjectContainer::toObject(obj2); } // Fail if (!pc || !object) return; if (object->getPCSpeaker()) { if (object->getPCSpeaker() != pc) { Creature *otherPC = NWN::ObjectContainer::toPC(object->getPCSpeaker()); warning("Functions::beginConversation(): " "Object \"%s\" already in conversation with PC \"%s\"", object->getTag().c_str(), otherPC ? otherPC->getName().c_str() : ""); return; } } Common::UString conversation = ctx.getParams()[0].getString(); if (conversation.empty()) conversation = object->getConversation(); ctx.getReturn() = _game->getModule().startConversation(conversation, *pc, *object); }
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 Door::load(const Aurora::GFF3Struct &door) { Common::UString temp = door.getString("TemplateResRef"); Common::ScopedPtr<Aurora::GFF3File> utd; if (!temp.empty()) utd.reset(loadOptionalGFF3(temp, Aurora::kFileTypeUTD, MKTAG('U', 'T', 'D', ' '))); Situated::load(door, utd ? &utd->getTopLevel() : 0); if (!utd) warning("Door \"%s\" has no blueprint", _tag.c_str()); if (!_modelName.empty()) { glm::mat4 transform; transform = glm::translate(transform, glm::make_vec3(_position)); transform = glm::rotate(transform, Common::deg2rad(_orientation[3]), glm::make_vec3(_orientation)); _walkmesh.load(_modelName + "0", ::Aurora::kFileTypeDWK, transform); } }
void Game::getCampaigns(std::vector<Common::UString> &campaigns) { campaigns.clear(); const Common::UString directory = ConfigMan.getString("NWN2_campaignDir"); const Common::FileList camFiles(directory, -1); for (Common::FileList::const_iterator c = camFiles.begin(); c != camFiles.end(); ++c) { if (!Common::FilePath::getFile(*c).equalsIgnoreCase("campaign.cam")) continue; const Common::UString cam = Common::FilePath::relativize(directory, Common::FilePath::getDirectory(*c)); if (cam.empty() || (cam == ".")) continue; campaigns.push_back(cam); } std::sort(campaigns.begin(), campaigns.end(), Common::UString::iless()); }
void Dialog::playSound(bool greeting) { const Aurora::DLGFile::Line *entry = _dlg->getCurrentEntry(); if (!entry) return; Common::UString sound = entry->sound; bool isSSF = false; if (sound.empty() && greeting) { const Aurora::SSFFile *ssf = _object->getSSF(); if (ssf) { isSSF = true; sound = ssf->getSoundFile(kSSFHello); } } _object->playSound(sound, isSSF); }
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; } delete utp; }
GUIQuad::GUIQuad(const Common::UString &texture, float x1 , float y1 , float x2 , float y2, float tX1, float tY1, float tX2, float tY2) : _x1 (x1) , _y1 (y1) , _x2 (x2) , _y2 (y2) , _tX1(tX1), _tY1(tY1), _tX2(tX2), _tY2(tY2), _r(1.0), _g(1.0), _b(1.0), _a(1.0), _xor(false) { try { if (!texture.empty()) _texture = TextureMan.get(texture); } catch (...) { _texture.clear(); _r = _g = _b = _a = 0.0; } _distance = -FLT_MAX; }
void NWNEngine::getCharacters(std::vector<Common::UString> &characters, bool local) { characters.clear(); Common::UString pcDir = ConfigMan.getString(local ? "NWN_localPCDir" : "NWN_serverPCDir"); if (pcDir.empty()) return; Common::FileList pcDirList; pcDirList.addDirectory(pcDir); std::list<Common::UString> chars; uint n = pcDirList.getFileNames(chars); characters.reserve(n); for (std::list<Common::UString>::const_iterator c = chars.begin(); c != chars.end(); ++c) { if (!Common::FilePath::getExtension(*c).equalsIgnoreCase(".bic")) continue; characters.push_back(Common::FilePath::getStem(*c)); } }
void dump2DA(Aurora::TwoDAFile &twoDA, const Common::UString &outFile, Format format) { Common::WriteStream *out = 0; if (!outFile.empty()) out = new Common::WriteFile(outFile); else out = new Common::StdOutStream; try { if (format == kFormat2DA) twoDA.dumpASCII(*out); else twoDA.dumpCSV(*out); } catch (...) { delete out; throw; } out->flush(); delete out; }
bool IngameGUI::startConversation(const Common::UString &conv, Creature &pc, Object &obj, bool playHello) { stopConversation(); if (conv.empty()) return true; try { _dialog = new Dialog(conv, pc, obj, *_module, playHello); _dialog->show(); } catch (Common::Exception &e) { delete _dialog; _dialog = 0; e.add("Failed starting conversation \"%s\"", conv.c_str()); Common::printException(e, "WARNING: "); return false; } return true; }