From bf57a0ad7a55c467ded99e851ae47dd6647658ff Mon Sep 17 00:00:00 2001 From: Lenheart <947330670@qq.com> Date: Sun, 24 Apr 2022 18:02:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=9F=E7=94=9F=E7=BB=98=E5=88=B6=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=EF=BC=88=E6=BB=A1=E6=84=8F=E4=B8=80=E8=88=AC=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/DNFTOOL.cpp | 45 ++++++++++++++++++++++++++++++++++ test/DNFTOOL.h | 9 +++++++ test/STL.h | 2 +- test/hook.cpp | 8 +++--- test/squirrel.cpp | 62 +++++++++++++++++++++++++++++++++++++++-------- 5 files changed, 111 insertions(+), 15 deletions(-) diff --git a/test/DNFTOOL.cpp b/test/DNFTOOL.cpp index 5b610c6..f0e34f0 100644 --- a/test/DNFTOOL.cpp +++ b/test/DNFTOOL.cpp @@ -264,6 +264,51 @@ wchar_t* DNFTOOL::charTowchar_t(char* wbuffer) return wcString; } +wchar_t* DNFTOOL::char2wchar(const char* cchar) +{ + wchar_t* m_wchar; + int len = MultiByteToWideChar(CP_ACP, 0, cchar, strlen(cchar), NULL, 0); + m_wchar = new wchar_t[len + 1]; + MultiByteToWideChar(CP_ACP, 0, cchar, strlen(cchar), m_wchar, len); + m_wchar[len] = '\0'; + return m_wchar; +} + +char* DNFTOOL::wchar2char(const wchar_t* wchar) +{ + char* m_char; + int len = WideCharToMultiByte(CP_ACP, 0, wchar, wcslen(wchar), NULL, 0, NULL, NULL); + m_char = new char[len + 1]; + WideCharToMultiByte(CP_ACP, 0, wchar, wcslen(wchar), m_char, len, NULL, NULL); + m_char[len] = '\0'; + return m_char; +} + +wchar_t* DNFTOOL::SquirrelW2W(const wchar_t* Str) +{ + size_t len = 0; + char* wbuffer = (char*)(Str); + while (true) + { + if (wbuffer[len] == 0 && wbuffer[len + 1] == 0)break; + ++len; + } + char* cbuffer = new char[len / 2 + 1]; + int k = 0; + for (size_t i = 0; i < len; i++) + { + if (i % 2 == 0) + { + cbuffer[k] = wbuffer[i]; + ++k; + } + } + cbuffer[len / 2] = '\0'; + wchar_t* str = DNFTOOL::char2wchar(cbuffer); + delete cbuffer; + return str; +} + wchar_t* DNFTOOL::AnsiToUnicode(const char* szStr, wchar_t* pResult, int maxLen) { if (NULL == pResult) diff --git a/test/DNFTOOL.h b/test/DNFTOOL.h index 602d7b7..0b63d15 100644 --- a/test/DNFTOOL.h +++ b/test/DNFTOOL.h @@ -88,6 +88,15 @@ public: //char* 转 wchar_t* 有用 static wchar_t* charTowchar_t(char* wbuffer); + //char* Windows编码 转 wchar_t* + static wchar_t* char2wchar(const char* cchar); + //wchar_t* Windows编码 转 char* + static char* wchar2char(const wchar_t* wchar); + + //Squirrel wchar_t* 转 Unicode + static wchar_t* SquirrelW2W(const wchar_t* wchar); + + //wchar_t* 转 string* static void Wchar_tToString(std::string& szDst, wchar_t* wchar); //char* 转 wchar_t* diff --git a/test/STL.h b/test/STL.h index 8c23e2d..36a7bc2 100644 --- a/test/STL.h +++ b/test/STL.h @@ -67,7 +67,7 @@ static std::mapDargonModel_STL; //绘制汉字结构体 struct DrawCodestruct { - std::string str; + wchar_t* str; int Xpos; int Ypos; int Color; diff --git a/test/hook.cpp b/test/hook.cpp index a066078..4adcd92 100644 --- a/test/hook.cpp +++ b/test/hook.cpp @@ -29,8 +29,8 @@ void _fastcall hook::H_Register_DrawCode(DWORD thisc, int Seat, int a3, int a4, { for (DrawCodestruct iter : DrawCodeT1_STL) { - wchar_t* str = DNFTOOL::charTowchar_t((char*)iter.str.c_str()); - DrawCodeF(thisc, Seat, iter.Xpos, iter.Ypos, iter.Color, (int)str); + //wchar_t* str = DNFTOOL::charTowchar_t((char*)iter.str.c_str()); + DrawCodeF(thisc, Seat, iter.Xpos, iter.Ypos, iter.Color, (int)iter.str); } DrawCodeT1_STL.clear(); } @@ -38,8 +38,8 @@ void _fastcall hook::H_Register_DrawCode(DWORD thisc, int Seat, int a3, int a4, { for (DrawCodestruct iter : DrawCodeT2_STL) { - wchar_t* str = DNFTOOL::charTowchar_t((char*)iter.str.c_str()); - DrawCodeF(thisc, Seat, iter.Xpos, iter.Ypos, iter.Color, (int)str); + //wchar_t* str = DNFTOOL::charTowchar_t((char*)iter.str.c_str()); + DrawCodeF(thisc, Seat, iter.Xpos, iter.Ypos, iter.Color, (int)iter.str); } DrawCodeT2_STL.clear(); } diff --git a/test/squirrel.cpp b/test/squirrel.cpp index 59fbdb5..d6e5860 100644 --- a/test/squirrel.cpp +++ b/test/squirrel.cpp @@ -67,19 +67,57 @@ int squirrel::SQdofile(uint32_t v, const wchar_t* filename, BOOL retval, BOOL pr } //Test +extern std::vectorDrawCodeT1_STL; +extern std::vectorDrawCodeT2_STL; +using uchar = unsigned char; +char* strconv(char* str) +{ + size_t len = strlen(str); + for (size_t i = 0; i < len; i++) + { + if (str[i] == -1) + { + strcpy(str + i, str + i + 1); + } + } + return str; +} int squirrel::sq_Test(uint32_t v) { - int a; + wchar_t* a; - SQGetInt(v, 2, &a); + SQGetString(v, 2, &a); + + size_t len = 0; + char* wbuffer = (char*)(a); + while (true) + { + if (wbuffer[len] == 0 && wbuffer[len + 1] == 0)break; + ++len; + } + char* cbuffer = new char[len/2 + 1]; + int k = 0; + for (size_t i = 0; i < len; i++) + { + if (i % 2 == 0) + { + cbuffer[k] = wbuffer[i]; + ++k; + } + } + cbuffer[len / 2] = '\0'; + wchar_t* str = DNFTOOL::char2wchar(cbuffer); + delete cbuffer; + DrawCodestruct Buffer; + Buffer.str = str; + Buffer.Xpos = 300; + Buffer.Ypos = 200; + Buffer.Color = 0xffffffff; + + DrawCodeT2_STL.push_back(Buffer); - //GMNotice((char*)u"我的天"); - //WindowsNotice((char*)u"我的天"); - //SQPopTop(v); - //SQPushInt(v, 1); - //char* str = (char*)"test"; - - std::cout << a << std::endl; + //std::cout << (int)str << std::endl; + //std::cout << str << std::endl; return 0; } //读人物 或 装备属性 @@ -1273,6 +1311,7 @@ int squirrel::Coder_STL(uint32_t v) int Color; int Type; int ParameterNum = SQGetTop(v); + if (ParameterNum == 6) { //获取字符串内容 @@ -1286,8 +1325,10 @@ int squirrel::Coder_STL(uint32_t v) //获取类型 SQGetInt(v, 6, &Type); + //松鼠 Wchar_t 转换为 Unicode + wchar_t* str = DNFTOOL::SquirrelW2W(Str); + DrawCodestruct Buffer; - char* str = DNFTOOL::wchar_tTochar(Str); Buffer.str = str; Buffer.Xpos = XPos; Buffer.Ypos = YPos; @@ -1311,6 +1352,7 @@ int squirrel::Coder_STL(uint32_t v) { SQPushBool(v, false); } + return 1; } #endif