From 50be04111624b5443bafbc4c1b80c3cfaa623fc4 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 30 Mar 2020 02:43:28 +0800 Subject: [PATCH 1/2] Fix plugin build for 3ds Max 9 --- .../nel_3dsmax_shared/string_common.h | 22 ++++--------------- .../plugin_max/nel_patch_converter/script.cpp | 2 +- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/nel/tools/3d/plugin_max/nel_3dsmax_shared/string_common.h b/nel/tools/3d/plugin_max/nel_3dsmax_shared/string_common.h index 737b1a5dd..4a331a78a 100644 --- a/nel/tools/3d/plugin_max/nel_3dsmax_shared/string_common.h +++ b/nel/tools/3d/plugin_max/nel_3dsmax_shared/string_common.h @@ -21,6 +21,7 @@ #define NLMAX_STRING_COMMON_H #include +#include #if (MAX_VERSION_MAJOR < 15) #define GET_OBJECT_NAME_CONST @@ -37,9 +38,7 @@ static TSTR MaxTStrFromUtf8(const std::string &src) { TSTR dst; #if (MAX_VERSION_MAJOR < 15) - ucstring uc; - uc.fromUtf8(src); - dst = (const mwchar_t *)uc.c_str(); + dst = nlUtf8ToTStr(src); #else dst.FromUTF8(src.c_str()); #endif @@ -49,14 +48,7 @@ static TSTR MaxTStrFromUtf8(const std::string &src) static std::string MaxTStrToUtf8(const TSTR& src) { #if (MAX_VERSION_MAJOR < 15) -#ifdef _UNICODE - ucstring uc(src.data()); - return uc.toUtf8(); -#else - WStr ws = src; - ucstring uc((const ucchar *)ws.data()); - return uc.toUtf8(); -#endif + return NLMISC::tStrToUtf8(src.data()); #else return src.ToUTF8().data(); #endif @@ -64,13 +56,7 @@ static std::string MaxTStrToUtf8(const TSTR& src) static std::string MCharStrToUtf8(const MCHAR *src) { -#ifdef _UNICODE - ucstring uc((const ucchar *)src); - return uc.toUtf8(); -#else - ucstring uc((const ucchar *)WStr(src).data()); - return uc.toUtf8(); -#endif + return NLMISC::tStrToUtf8(src); } #endif /* #ifndef NLMAX_STRING_COMMON_H */ diff --git a/nel/tools/3d/plugin_max/nel_patch_converter/script.cpp b/nel/tools/3d/plugin_max/nel_patch_converter/script.cpp index 2c2f100f7..48bf1d921 100644 --- a/nel/tools/3d/plugin_max/nel_patch_converter/script.cpp +++ b/nel/tools/3d/plugin_max/nel_patch_converter/script.cpp @@ -1271,7 +1271,7 @@ Value* get_patch_vertex_cf (Value** arg_list, int count) // Check to see if the arguments match up to what we expect // We want to use 'TurnAllTexturesOn ' - const MCHAR *message= _M("NeLGetPatchVertex [NeLPatchMesh] [PatchId] [VertexId]"); + MCHAR *message= _M("NeLGetPatchVertex [NeLPatchMesh] [PatchId] [VertexId]"); type_check(arg_list[0], MAXNode, message); type_check(arg_list[1], Integer, message); type_check(arg_list[2], Integer, message); From 4f0bbbad69b6df008e4ae0096669070ff8b82c0e Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 30 Mar 2020 08:38:17 +0800 Subject: [PATCH 2/2] String fixes --- nel/include/nel/misc/string_common.h | 8 ++++++++ nel/src/misc/i_xml.cpp | 5 +++-- .../world_editor/world_editor/world_editor.cpp | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/nel/include/nel/misc/string_common.h b/nel/include/nel/misc/string_common.h index 3fd46b835..9f6d59aae 100644 --- a/nel/include/nel/misc/string_common.h +++ b/nel/include/nel/misc/string_common.h @@ -290,6 +290,14 @@ inline bool endsWith(const char *str, const char *suffix) { return endsWith(str, inline bool endsWith(const std::string &str, const char *suffix) { return endsWith(str.c_str(), str.size(), suffix, strlen(suffix)); } inline bool endsWith(const std::string &str, const std::string &suffix) { return endsWith(str.c_str(), str.size(), suffix.c_str(), suffix.size()); } +// **************************************************************************** +// Conversion of strings between +// - UTF-8 +// - Local codepage (UTF-8 on Linux) +// - TString (Local codepage or wide on Windows) +// - Wide (wchar_t *, UTF-16 on Windows, UTF-32 on Linux) +// **************************************************************************** + // Convert local codepage to UTF-8 // On Windows, the local codepage is undetermined // On Linux, the local codepage is always UTF-8 (no-op) diff --git a/nel/src/misc/i_xml.cpp b/nel/src/misc/i_xml.cpp index 87f848ab9..24a2b7910 100644 --- a/nel/src/misc/i_xml.cpp +++ b/nel/src/misc/i_xml.cpp @@ -171,15 +171,16 @@ bool CIXml::init (IStream &stream) // Try binary mode if (_TryBinaryMode) { - char header[4]; + char header[5]; header[0] = buffer[0]; header[1] = buffer[1]; header[2] = buffer[2]; header[3] = buffer[3]; + header[4] = '\0'; toLower(header); // Does it a xml stream ? - if (!strcmp(header, "