|
12 | 12 | *****************************************************************************/ |
13 | 13 |
|
14 | 14 | #include "StdInc.h" |
| 15 | +#include <array> |
15 | 16 | #include <CMatrix.h> |
16 | 17 | #include <core/CCoreInterface.h> |
17 | 18 | #define RWFUNC_IMPLEMENT |
@@ -816,6 +817,62 @@ void CRenderWareSA::TxdForceUnload(ushort usTxdId, bool bDestroyTextures) |
816 | 817 | } |
817 | 818 | } |
818 | 819 |
|
| 820 | +namespace |
| 821 | +{ |
| 822 | + struct TextureMapping |
| 823 | + { |
| 824 | + const char* externalName; |
| 825 | + const char* internalName; |
| 826 | + }; |
| 827 | + |
| 828 | + constexpr std::array<TextureMapping, 2> kTextureMappings = {{ |
| 829 | + {"remap", "#emap"}, |
| 830 | + {"white", "@hite"} |
| 831 | + }}; |
| 832 | +} |
| 833 | + |
| 834 | +//////////////////////////////////////////////////////////////// |
| 835 | +// |
| 836 | +// CRenderWareSA::GetInternalTextureName |
| 837 | +// |
| 838 | +// Maps external texture names (e.g. "remap") to internal GTA:SA names (e.g. "#emap") |
| 839 | +// Returns original name if no mapping exists |
| 840 | +// |
| 841 | +//////////////////////////////////////////////////////////////// |
| 842 | +const char* CRenderWareSA::GetInternalTextureName(const char* szExternalName) |
| 843 | +{ |
| 844 | + if (!szExternalName) |
| 845 | + return nullptr; |
| 846 | + |
| 847 | + for (const auto& mapping : kTextureMappings) |
| 848 | + { |
| 849 | + if (_stricmp(szExternalName, mapping.externalName) == 0) |
| 850 | + return mapping.internalName; |
| 851 | + } |
| 852 | + return szExternalName; |
| 853 | +} |
| 854 | + |
| 855 | +//////////////////////////////////////////////////////////////// |
| 856 | +// |
| 857 | +// CRenderWareSA::GetExternalTextureName |
| 858 | +// |
| 859 | +// Maps internal GTA:SA names (e.g. "#emap") to external texture names (e.g. "remap") |
| 860 | +// Returns original name if no mapping exists |
| 861 | +// |
| 862 | +//////////////////////////////////////////////////////////////// |
| 863 | +const char* CRenderWareSA::GetExternalTextureName(const char* szInternalName) |
| 864 | +{ |
| 865 | + if (!szInternalName) |
| 866 | + return nullptr; |
| 867 | + |
| 868 | + for (const auto& mapping : kTextureMappings) |
| 869 | + { |
| 870 | + if (_stricmp(szInternalName, mapping.internalName) == 0) |
| 871 | + return mapping.externalName; |
| 872 | + } |
| 873 | + return szInternalName; |
| 874 | +} |
| 875 | + |
819 | 876 | //////////////////////////////////////////////////////////////// |
820 | 877 | // |
821 | 878 | // CRenderWareSA::GetTXDIDForModelID |
@@ -889,9 +946,13 @@ void CRenderWareSA::GetModelTextureNames(std::vector<SString>& outNameList, usho |
889 | 946 | std::vector<RwTexture*> textureList; |
890 | 947 | GetTxdTextures(textureList, pTXD); |
891 | 948 |
|
892 | | - for (std::vector<RwTexture*>::iterator iter = textureList.begin(); iter != textureList.end(); iter++) |
| 949 | + for (RwTexture* pTexture : textureList) |
893 | 950 | { |
894 | | - outNameList.push_back((*iter)->name); |
| 951 | + // Fix for #emap corruption: |
| 952 | + // Some textures (like 'remap') are internally renamed to start with '#' (e.g. '#emap') by SA. |
| 953 | + // This causes issues when scripts try to access them by their original name. |
| 954 | + // We detect this case and return the expected name 'remap' instead. |
| 955 | + outNameList.push_back(GetExternalTextureName(pTexture->name)); |
895 | 956 | } |
896 | 957 |
|
897 | 958 | if (bLoadedModel) |
@@ -951,7 +1012,8 @@ bool CRenderWareSA::GetModelTextures(std::vector<std::tuple<std::string, CPixels |
951 | 1012 |
|
952 | 1013 | for (RwTexture* pTexture : rwTextureList) |
953 | 1014 | { |
954 | | - SString strTextureName = pTexture->name; |
| 1015 | + SString strTextureName = GetExternalTextureName(pTexture->name); |
| 1016 | + |
955 | 1017 | bool bValidTexture = false; |
956 | 1018 |
|
957 | 1019 | if (bExcludeTextures) |
|
0 commit comments