diff options
author | Mikkel Krautz <mikkel@krautz.dk> | 2014-12-30 23:44:07 +0300 |
---|---|---|
committer | Mikkel Krautz <mikkel@krautz.dk> | 2014-12-30 23:44:47 +0300 |
commit | f3c64b382695e075609e701f84bb96692d612915 (patch) | |
tree | 6d087307a931ae33ae6db36e3b2d6c955e39010f /plugins | |
parent | b2f5bd0981d80ff68a3a607737e770f2b3039b32 (diff) |
plugins: move u8 function into the Star Trek: Online plugin.
The sto plugin is the only user of the function.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/mumble_plugin_win32.h | 18 | ||||
-rw-r--r-- | plugins/sto/sto.cpp | 14 |
2 files changed, 14 insertions, 18 deletions
diff --git a/plugins/mumble_plugin_win32.h b/plugins/mumble_plugin_win32.h index 4cd81d167..671997e49 100644 --- a/plugins/mumble_plugin_win32.h +++ b/plugins/mumble_plugin_win32.h @@ -112,24 +112,6 @@ T peekProc(VOID *base) { return v; } -static void inline u8(std::wstring &dst, const std::string &src) { - int len = MultiByteToWideChar(CP_UTF8, 0, src.data(), src.length(), NULL, 0); - - wchar_t *wbuff = reinterpret_cast<wchar_t *>(_alloca(sizeof(wchar_t) * len)); - MultiByteToWideChar(CP_UTF8, 0, src.data(), src.length(), wbuff, len); - - dst.assign(wbuff, len); -} - -static void inline u8(std::wstring &dst, const char *src, int srclen) { - int len = MultiByteToWideChar(CP_UTF8, 0, src, srclen, NULL, 0); - - wchar_t *wbuff = reinterpret_cast<wchar_t *>(_alloca(sizeof(wchar_t) * len)); - MultiByteToWideChar(CP_UTF8, 0, src, srclen, wbuff, len); - - dst.assign(wbuff, len); -} - static bool inline initialize(const std::multimap<std::wstring, unsigned long long int> &pids, const wchar_t *procname, const wchar_t *modname = NULL) { hProcess = NULL; pModule = NULL; diff --git a/plugins/sto/sto.cpp b/plugins/sto/sto.cpp index a833c4e3a..a2ed8b698 100644 --- a/plugins/sto/sto.cpp +++ b/plugins/sto/sto.cpp @@ -34,6 +34,20 @@ static BYTE *identptr; static BYTE *contextptr; static BYTE *posptr; +static void inline u8(std::wstring &dst, const std::string &src) { + if (src.length() > std::numeric_limits<int>::max()) { + dst.clear(); + return; + } + + int len = MultiByteToWideChar(CP_UTF8, 0, src.data(), static_cast<int>(src.length()), NULL, 0); + + wchar_t *wbuff = reinterpret_cast<wchar_t *>(_alloca(sizeof(wchar_t) * len)); + MultiByteToWideChar(CP_UTF8, 0, src.data(), static_cast<int>(src.length()), wbuff, len); + + dst.assign(wbuff, len); +} + static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, float *camera_pos, float *camera_front, float *camera_top, std::string &context, std::wstring &identity) { char identblock[0x200]; char contextblock[0x80]; |