原生绘制字符(满意一般)

This commit is contained in:
Lenheart 2022-04-24 18:02:17 +08:00
parent 6583312298
commit bf57a0ad7a
5 changed files with 111 additions and 15 deletions

View File

@ -264,6 +264,51 @@ wchar_t* DNFTOOL::charTowchar_t(char* wbuffer)
return wcString; 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) wchar_t* DNFTOOL::AnsiToUnicode(const char* szStr, wchar_t* pResult, int maxLen)
{ {
if (NULL == pResult) if (NULL == pResult)

View File

@ -88,6 +88,15 @@ public:
//char* 转 wchar_t* 有用 //char* 转 wchar_t* 有用
static wchar_t* charTowchar_t(char* wbuffer); 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* //wchar_t* 转 string*
static void Wchar_tToString(std::string& szDst, wchar_t* wchar); static void Wchar_tToString(std::string& szDst, wchar_t* wchar);
//char* 转 wchar_t* //char* 转 wchar_t*

View File

@ -67,7 +67,7 @@ static std::map<std::string, int>DargonModel_STL;
//»æÖƺº×ֽṹÌå //»æÖƺº×ֽṹÌå
struct DrawCodestruct struct DrawCodestruct
{ {
std::string str; wchar_t* str;
int Xpos; int Xpos;
int Ypos; int Ypos;
int Color; int Color;

View File

@ -29,8 +29,8 @@ void _fastcall hook::H_Register_DrawCode(DWORD thisc, int Seat, int a3, int a4,
{ {
for (DrawCodestruct iter : DrawCodeT1_STL) for (DrawCodestruct iter : DrawCodeT1_STL)
{ {
wchar_t* str = DNFTOOL::charTowchar_t((char*)iter.str.c_str()); //wchar_t* str = DNFTOOL::charTowchar_t((char*)iter.str.c_str());
DrawCodeF(thisc, Seat, iter.Xpos, iter.Ypos, iter.Color, (int)str); DrawCodeF(thisc, Seat, iter.Xpos, iter.Ypos, iter.Color, (int)iter.str);
} }
DrawCodeT1_STL.clear(); 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) for (DrawCodestruct iter : DrawCodeT2_STL)
{ {
wchar_t* str = DNFTOOL::charTowchar_t((char*)iter.str.c_str()); //wchar_t* str = DNFTOOL::charTowchar_t((char*)iter.str.c_str());
DrawCodeF(thisc, Seat, iter.Xpos, iter.Ypos, iter.Color, (int)str); DrawCodeF(thisc, Seat, iter.Xpos, iter.Ypos, iter.Color, (int)iter.str);
} }
DrawCodeT2_STL.clear(); DrawCodeT2_STL.clear();
} }

View File

@ -67,19 +67,57 @@ int squirrel::SQdofile(uint32_t v, const wchar_t* filename, BOOL retval, BOOL pr
} }
//Test //Test
extern std::vector<DrawCodestruct>DrawCodeT1_STL;
extern std::vector<DrawCodestruct>DrawCodeT2_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 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"我的天"); //std::cout << (int)str << std::endl;
//WindowsNotice((char*)u"我的天"); //std::cout << str << std::endl;
//SQPopTop(v);
//SQPushInt(v, 1);
//char* str = (char*)"test";
std::cout << a << std::endl;
return 0; return 0;
} }
//读人物 或 装备属性 //读人物 或 装备属性
@ -1273,6 +1311,7 @@ int squirrel::Coder_STL(uint32_t v)
int Color; int Color;
int Type; int Type;
int ParameterNum = SQGetTop(v); int ParameterNum = SQGetTop(v);
if (ParameterNum == 6) if (ParameterNum == 6)
{ {
//获取字符串内容 //获取字符串内容
@ -1286,8 +1325,10 @@ int squirrel::Coder_STL(uint32_t v)
//获取类型 //获取类型
SQGetInt(v, 6, &Type); SQGetInt(v, 6, &Type);
//ËÉÊó Wchar_t ת»»Îª Unicode
wchar_t* str = DNFTOOL::SquirrelW2W(Str);
DrawCodestruct Buffer; DrawCodestruct Buffer;
char* str = DNFTOOL::wchar_tTochar(Str);
Buffer.str = str; Buffer.str = str;
Buffer.Xpos = XPos; Buffer.Xpos = XPos;
Buffer.Ypos = YPos; Buffer.Ypos = YPos;
@ -1311,6 +1352,7 @@ int squirrel::Coder_STL(uint32_t v)
{ {
SQPushBool(v, false); SQPushBool(v, false);
} }
return 1; return 1;
} }
#endif #endif