Merge branch 'fix_model_path' into 'master'

Fix #7403: incorrect model path for records created by Lua scripts

Closes #7403

See merge request OpenMW/openmw!3151
revert-6246b479
psi29a 2 years ago
commit 31efad1dd0

@ -23,7 +23,7 @@ namespace
{
ESM::Activator activator;
activator.mName = rec["name"];
activator.mModel = rec["model"];
activator.mModel = Misc::ResourceHelpers::meshPathForESM3(rec["model"].get<std::string_view>());
std::string_view scriptId = rec["mwscript"].get<std::string_view>();
activator.mScript = ESM::RefId::deserializeText(scriptId);
return activator;

@ -23,7 +23,7 @@ namespace
{
ESM::Armor armor;
armor.mName = rec["name"];
armor.mModel = rec["model"];
armor.mModel = Misc::ResourceHelpers::meshPathForESM3(rec["model"].get<std::string_view>());
armor.mIcon = rec["icon"];
std::string_view enchantId = rec["enchant"].get<std::string_view>();
armor.mEnchant = ESM::RefId::deserializeText(enchantId);

@ -28,7 +28,7 @@ namespace
{
ESM::Book book;
book.mName = rec["name"];
book.mModel = rec["model"];
book.mModel = Misc::ResourceHelpers::meshPathForESM3(rec["model"].get<std::string_view>());
book.mIcon = rec["icon"];
book.mText = rec["text"];
std::string_view enchantId = rec["enchant"].get<std::string_view>();

@ -23,7 +23,7 @@ namespace
{
ESM::Clothing clothing;
clothing.mName = rec["name"];
clothing.mModel = rec["model"];
clothing.mModel = Misc::ResourceHelpers::meshPathForESM3(rec["model"].get<std::string_view>());
clothing.mIcon = rec["icon"];
std::string_view scriptId = rec["mwscript"].get<std::string_view>();
clothing.mScript = ESM::RefId::deserializeText(scriptId);

@ -25,7 +25,7 @@ namespace
{
ESM::Miscellaneous misc;
misc.mName = rec["name"];
misc.mModel = rec["model"];
misc.mModel = Misc::ResourceHelpers::meshPathForESM3(rec["model"].get<std::string_view>());
misc.mIcon = rec["icon"];
std::string_view scriptId = rec["mwscript"].get<std::string_view>();
misc.mScript = ESM::RefId::deserializeText(scriptId);

@ -24,7 +24,7 @@ namespace
{
ESM::Potion potion;
potion.mName = rec["name"];
potion.mModel = rec["model"];
potion.mModel = Misc::ResourceHelpers::meshPathForESM3(rec["model"].get<std::string_view>());
potion.mIcon = rec["icon"];
std::string_view scriptId = rec["mwscript"].get<std::string_view>();
potion.mScript = ESM::RefId::deserializeText(scriptId);

@ -25,7 +25,7 @@ namespace
{
ESM::Weapon weapon;
weapon.mName = rec["name"];
weapon.mModel = rec["model"];
weapon.mModel = Misc::ResourceHelpers::meshPathForESM3(rec["model"].get<std::string_view>());
weapon.mIcon = rec["icon"];
std::string_view enchantId = rec["enchant"].get<std::string_view>();
weapon.mEnchant = ESM::RefId::deserializeText(enchantId);

@ -150,6 +150,17 @@ std::string Misc::ResourceHelpers::correctMeshPath(const std::string& resPath, c
return "meshes\\" + resPath;
}
std::string_view Misc::ResourceHelpers::meshPathForESM3(std::string_view resPath)
{
constexpr std::string_view prefix = "meshes";
if (resPath.length() < prefix.size() + 1 || !Misc::StringUtils::ciStartsWith(resPath, prefix)
|| (resPath[prefix.size()] != '/' && resPath[prefix.size()] != '\\'))
{
throw std::runtime_error("Path should start with 'meshes\\'");
}
return resPath.substr(prefix.size() + 1);
}
std::string Misc::ResourceHelpers::correctSoundPath(std::string_view resPath, const VFS::Manager* vfs)
{
// Workaround: Bethesda at some point converted some of the files to mp3, but the references were kept as .wav.

@ -31,8 +31,13 @@ namespace Misc
/// Use "xfoo.nif" instead of "foo.nif" if "xfoo.kf" is available
/// Note that if "xfoo.nif" is actually unavailable, we can't fall back to "foo.nif". :(
std::string correctActorModelPath(const std::string& resPath, const VFS::Manager* vfs);
// Adds "meshes\\".
std::string correctMeshPath(const std::string& resPath, const VFS::Manager* vfs);
// Removes "meshes\\".
std::string_view meshPathForESM3(std::string_view resPath);
std::string correctSoundPath(std::string_view resPath, const VFS::Manager* vfs);
/// marker objects that have a hardcoded function in the game logic, should be hidden from the player

Loading…
Cancel
Save