Skip to content

Commit

Permalink
Cross platform wstring conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphalaneous committed Mar 7, 2024
1 parent 4618f05 commit 692395c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
#include "ui/hooks/LoadingLayer.h"
#include "ui/hooks/CreatorLayer.h"
#include "ui/hooks/CCDirector.h"

$execute{
setlocale( LC_ALL, "en_US.utf8" );
}
6 changes: 4 additions & 2 deletions src/ui/nodes/MinecraftLabel.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "MinecraftLabel.h"
#include "../../utils/Utils.h"
#include <cstdlib>

struct ColorPos {
unsigned int pos;
Expand All @@ -9,9 +10,10 @@ struct ColorPos {
std::string what_the_fuck(std::wstring wstr) {

int slength = (int)wstr.length() + 1;
int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), slength, 0, 0, 0, 0);
int len = wcstombs(nullptr, data(wstr), size(wstr));
std::string r(len, '\0');
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), slength, &r[0], len, 0, 0);
wcstombs(data(r), data(wstr), size(wstr));

return r;
}

Expand Down

0 comments on commit 692395c

Please sign in to comment.