Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
knight00 committed May 29, 2021
2 parents 4b3b80a + ba83e7a commit 6329afd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
16 changes: 7 additions & 9 deletions gframe/bufferio.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BufferIO {
insert_data(vec, &val, sizeof(T));
}
inline static void Read(char*& p, void* dest, size_t size) {
memcpy(dest, p, size);
std::memcpy(dest, p, size);
p += size;
}
template<typename T>
Expand Down Expand Up @@ -185,10 +185,9 @@ class BufferIO {
return EncodeUTF8internal<false>(wsrc, out);
}
static std::string EncodeUTF8(epro::wstringview source) {
thread_local std::vector<char> res;
res.reserve(source.size() * sizeof(wchar_t) + 1);
const size_t size = EncodeUTF8(source.data(), res.data());
return { res.data(), size };
std::string res(source.size() * sizeof(wchar_t) + 1, L'\0');
res.resize(EncodeUTF8(source.data(), &res[0]));
return res;
}
// UTF-8 to UTF-16/UTF-32
static inline int DecodeUTF8(const char* src, wchar_t* out, size_t size) {
Expand All @@ -198,10 +197,9 @@ class BufferIO {
return DecodeUTF8internal<false>(src, out);
}
static std::wstring DecodeUTF8(epro::stringview source) {
thread_local std::vector<wchar_t> res;
res.reserve(source.size() + 1);
const size_t size = DecodeUTF8(source.data(), res.data());
return { res.data(), size };
std::wstring res(source.size() + 1, '\0');
res.resize(DecodeUTF8(source.data(), &res[0]));
return res;
}
// UTF-16 to UTF-16/UTF-32
static inline int DecodeUTF16(const uint16_t* source, wchar_t* out, size_t size) {
Expand Down
2 changes: 2 additions & 0 deletions gframe/duelclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#ifndef _WIN32
#include <arpa/inet.h>
#include <unistd.h>
#else
#include <ws2tcpip.h>
#endif
#include "game_config.h"
#include <irrlicht.h>
Expand Down
2 changes: 1 addition & 1 deletion gframe/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ namespace ygo {
#ifdef _WIN32
TCHAR exepath[MAX_PATH];
GetModuleFileName(nullptr, exepath, MAX_PATH);
return Utils::NormalizePath(exepath, false);
return Utils::NormalizePath<TCHAR>(exepath, false);
#elif defined(__linux__) && !defined(__ANDROID__)
epro::path_char buff[PATH_MAX];
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff) - 1);
Expand Down
8 changes: 6 additions & 2 deletions gframe/windbot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ uint32_t WindBot::version{ CLIENT_VERSION };
#ifndef __ANDROID__
nlohmann::ordered_json WindBot::databases{};
bool WindBot::serialized{ false };
epro::path_string WindBot::serialized_databases{};
#ifdef _WIN32
std::wstring WindBot::serialized_databases{};
#else
std::string WindBot::serialized_databases{};
#endif
#endif

WindBot::launch_ret_t WindBot::Launch(int port, epro::wstringview pass, bool chat, int hand, const wchar_t* overridedeck) const {
#ifndef __ANDROID__
if(!serialized) {
serialized = true;
serialized_databases = base64_encode<epro::path_string>(databases.dump(-1, ' ', false, nlohmann::detail::error_handler_t::replace));
serialized_databases = base64_encode<decltype(serialized_databases)>(databases.dump(-1, ' ', false, nlohmann::detail::error_handler_t::replace));
}
#endif
#ifdef _WIN32
Expand Down
6 changes: 5 additions & 1 deletion gframe/windbot.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ struct WindBot {
#ifndef __ANDROID__
static nlohmann::ordered_json databases;
static bool serialized;
static epro::path_string serialized_databases;
#ifdef _WIN32
static std::wstring serialized_databases;
#else
static std::string serialized_databases;
#endif
#endif

static void AddDatabase(epro::path_stringview database);
Expand Down

0 comments on commit 6329afd

Please sign in to comment.