Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void BodyMorphInterface::ReadBodyMorphs(BSFixedString filePath)
- {
- BSResourceNiBinaryStream file(filePath.data);
- if (!file.IsValid()) {
- return;
- }
- UInt32 lineCount = 0;
- std::string str = "";
- while (BSReadLine(&file, &str))
- {
- lineCount++;
- str = std::trim(str);
- if (str.length() == 0)
- continue;
- if (str.at(0) == '#')
- continue;
- std::vector<std::string> side = std::explode(str, '=');
- if (side.size() < 2) {
- _ERROR("%s - Error - Line (%d) loading a morph from %s has no left-hand side.", __FUNCTION__, lineCount, filePath.data);
- continue;
- }
- std::string lSide = std::trim(side[0]);
- std::string rSide = std::trim(side[1]);
- std::vector<std::string> form = std::explode(lSide, '|');
- if (form.size() < 2) {
- _ERROR("%s - Error - Line (%d) morph left side from %s missing mod name or formID.", __FUNCTION__, lineCount, filePath.data);
- continue;
- }
- std::string modNameText = std::trim(form[0]);
- BSFixedString modText(modNameText.c_str());
- UInt8 modIndex = DataHandler::GetSingleton()->GetModIndex(modText.data);
- if (modIndex == -1) {
- _WARNING("%s - Warning - Line (%d) Mod %s from %s not a loaded mod.", __FUNCTION__, lineCount, modText.data, filePath.data);
- continue;
- }
- std::string formIdText = std::trim(form[1]);
- UInt32 formLower = strtoul(formIdText.c_str(), NULL, 16);
- if (formLower == 0) {
- _ERROR("%s - Error - Line (%d) from %s invalid formID.", __FUNCTION__, lineCount, filePath.data);
- continue;
- }
- UInt32 formId = modIndex << 24 | formLower & 0xFFFFFF;
- TESForm * foundForm = LookupFormByID(formId);
- if (!foundForm) {
- _ERROR("%s - Error - Line (%d) from %s invalid form %08X.", __FUNCTION__, lineCount, filePath.data, formId);
- continue;
- }
- TESNPC * npc = DYNAMIC_CAST(foundForm, TESForm, TESNPC);
- if (!npc) {
- _ERROR("%s - Error - Line (%d) from %s invalid form %08X not an ActorBase.", __FUNCTION__, lineCount, filePath.data, formId);
- continue;
- }
- BodyGenSets bodyGenSets;
- std::string error = "";
- std::vector<std::string> sets = std::explode(rSide, '/');
- for (UInt32 i = 0; i < sets.size(); i++) {
- sets[i] = std::trim(sets[i]);
- BodyGenMorphs bodyMorphs;
- std::vector<std::string> morphs = std::explode(sets[i], ',');
- for (UInt32 j = 0; j < morphs.size(); j++) {
- morphs[j] = std::trim(morphs[j]);
- std::vector<std::string> selectors = std::explode(morphs[j], '|');
- BodyGenMorphSelector selector;
- for (UInt32 k = 0; k < selectors.size(); k++) {
- selectors[k] = std::trim(selectors[k]);
- std::vector<std::string> pairs = std::explode(selectors[k], '@');
- if (pairs.size() < 2) {
- error = "Must have value pair with @";
- break;
- }
- std::string morphName = std::trim(pairs[0]);
- if (morphName.length() == 0) {
- error = "Empty morph name";
- break;
- }
- std::string morphValues = std::trim(pairs[1]);
- if (morphValues.length() == 0) {
- error = "Empty values";
- break;
- }
- float lowerValue = 0;
- float upperValue = 0;
- std::vector<std::string> range = std::explode(morphValues, ':');
- if (range.size() > 1) {
- std::string lowerRange = std::trim(range[0]);
- if (lowerRange.length() == 0) {
- error = "Empty lower range";
- break;
- }
- lowerValue = strtof(lowerRange.c_str(), NULL);
- std::string upperRange = std::trim(range[1]);
- if (upperRange.length() == 0) {
- error = "Empty upper range";
- break;
- }
- upperValue = strtof(upperRange.c_str(), NULL);
- }
- else {
- lowerValue = strtof(morphValues.c_str(), NULL);
- upperValue = lowerValue;
- }
- BodyGenMorphData morphData;
- morphData.name = morphName.c_str();
- morphData.lower = lowerValue;
- morphData.upper = upperValue;
- selector.push_back(morphData);
- }
- if (error.length() > 0)
- break;
- bodyMorphs.push_back(selector);
- }
- if (error.length() > 0)
- break;
- bodyGenSets.push_back(bodyMorphs);
- }
- if (error.length() > 0) {
- _ERROR("%s - Error - Line (%d) could not parse morphs from %s. (%s)", __FUNCTION__, lineCount, filePath.data, error.c_str());
- continue;
- }
- bodyGenData[npc] = bodyGenSets;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement