From 2f16a8d27cbfc0514343eeb2d6b569a5c6becf35 Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Sat, 17 Jun 2023 20:47:42 +0200 Subject: [PATCH] Fix incorrect model part for records created by Lua scripts --- apps/openmw/mwlua/types/activator.cpp | 2 +- apps/openmw/mwlua/types/armor.cpp | 2 +- apps/openmw/mwlua/types/book.cpp | 2 +- apps/openmw/mwlua/types/clothing.cpp | 2 +- apps/openmw/mwlua/types/misc.cpp | 2 +- apps/openmw/mwlua/types/potion.cpp | 2 +- apps/openmw/mwlua/types/weapon.cpp | 2 +- components/misc/resourcehelpers.cpp | 11 +++++++++++ components/misc/resourcehelpers.hpp | 5 +++++ 9 files changed, 23 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwlua/types/activator.cpp b/apps/openmw/mwlua/types/activator.cpp index 1ea9ec07f7..77ffd384cb 100644 --- a/apps/openmw/mwlua/types/activator.cpp +++ b/apps/openmw/mwlua/types/activator.cpp @@ -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 scriptId = rec["mwscript"].get(); activator.mScript = ESM::RefId::deserializeText(scriptId); return activator; diff --git a/apps/openmw/mwlua/types/armor.cpp b/apps/openmw/mwlua/types/armor.cpp index d530ddd205..1006dcefcd 100644 --- a/apps/openmw/mwlua/types/armor.cpp +++ b/apps/openmw/mwlua/types/armor.cpp @@ -23,7 +23,7 @@ namespace { ESM::Armor armor; armor.mName = rec["name"]; - armor.mModel = rec["model"]; + armor.mModel = Misc::ResourceHelpers::meshPathForESM3(rec["model"].get()); armor.mIcon = rec["icon"]; std::string_view enchantId = rec["enchant"].get(); armor.mEnchant = ESM::RefId::deserializeText(enchantId); diff --git a/apps/openmw/mwlua/types/book.cpp b/apps/openmw/mwlua/types/book.cpp index 12daf52fd9..f7120e529a 100644 --- a/apps/openmw/mwlua/types/book.cpp +++ b/apps/openmw/mwlua/types/book.cpp @@ -28,7 +28,7 @@ namespace { ESM::Book book; book.mName = rec["name"]; - book.mModel = rec["model"]; + book.mModel = Misc::ResourceHelpers::meshPathForESM3(rec["model"].get()); book.mIcon = rec["icon"]; book.mText = rec["text"]; std::string_view enchantId = rec["enchant"].get(); diff --git a/apps/openmw/mwlua/types/clothing.cpp b/apps/openmw/mwlua/types/clothing.cpp index 18c9580fb9..029b084e95 100644 --- a/apps/openmw/mwlua/types/clothing.cpp +++ b/apps/openmw/mwlua/types/clothing.cpp @@ -23,7 +23,7 @@ namespace { ESM::Clothing clothing; clothing.mName = rec["name"]; - clothing.mModel = rec["model"]; + clothing.mModel = Misc::ResourceHelpers::meshPathForESM3(rec["model"].get()); clothing.mIcon = rec["icon"]; std::string_view scriptId = rec["mwscript"].get(); clothing.mScript = ESM::RefId::deserializeText(scriptId); diff --git a/apps/openmw/mwlua/types/misc.cpp b/apps/openmw/mwlua/types/misc.cpp index b20107a4e3..3a4fba9cec 100644 --- a/apps/openmw/mwlua/types/misc.cpp +++ b/apps/openmw/mwlua/types/misc.cpp @@ -25,7 +25,7 @@ namespace { ESM::Miscellaneous misc; misc.mName = rec["name"]; - misc.mModel = rec["model"]; + misc.mModel = Misc::ResourceHelpers::meshPathForESM3(rec["model"].get()); misc.mIcon = rec["icon"]; std::string_view scriptId = rec["mwscript"].get(); misc.mScript = ESM::RefId::deserializeText(scriptId); diff --git a/apps/openmw/mwlua/types/potion.cpp b/apps/openmw/mwlua/types/potion.cpp index 3ab15f2691..4fab7f5196 100644 --- a/apps/openmw/mwlua/types/potion.cpp +++ b/apps/openmw/mwlua/types/potion.cpp @@ -24,7 +24,7 @@ namespace { ESM::Potion potion; potion.mName = rec["name"]; - potion.mModel = rec["model"]; + potion.mModel = Misc::ResourceHelpers::meshPathForESM3(rec["model"].get()); potion.mIcon = rec["icon"]; std::string_view scriptId = rec["mwscript"].get(); potion.mScript = ESM::RefId::deserializeText(scriptId); diff --git a/apps/openmw/mwlua/types/weapon.cpp b/apps/openmw/mwlua/types/weapon.cpp index 2457a0752f..1f06a4bd70 100644 --- a/apps/openmw/mwlua/types/weapon.cpp +++ b/apps/openmw/mwlua/types/weapon.cpp @@ -25,7 +25,7 @@ namespace { ESM::Weapon weapon; weapon.mName = rec["name"]; - weapon.mModel = rec["model"]; + weapon.mModel = Misc::ResourceHelpers::meshPathForESM3(rec["model"].get()); weapon.mIcon = rec["icon"]; std::string_view enchantId = rec["enchant"].get(); weapon.mEnchant = ESM::RefId::deserializeText(enchantId); diff --git a/components/misc/resourcehelpers.cpp b/components/misc/resourcehelpers.cpp index 9e25c9a0af..e4f8452ef0 100644 --- a/components/misc/resourcehelpers.cpp +++ b/components/misc/resourcehelpers.cpp @@ -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. diff --git a/components/misc/resourcehelpers.hpp b/components/misc/resourcehelpers.hpp index 64782a8ccb..2ab92e0bed 100644 --- a/components/misc/resourcehelpers.hpp +++ b/components/misc/resourcehelpers.hpp @@ -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