Commit 8dac6db3 authored by nanahira's avatar nanahira

Merge branch 'master' of github.com:Fluorohydride/ygopro into develop

parents 7d1c0c71 f9b5c7ed
...@@ -38,7 +38,7 @@ public: ...@@ -38,7 +38,7 @@ public:
* @brief Copy a C-style string to another C-style string. * @brief Copy a C-style string to another C-style string.
* @param src The source wide string * @param src The source wide string
* @param pstr The destination char string * @param pstr The destination char string
* @param bufsize The size of the destination buffer * @param bufsize The length of the destination buffer
* @return The length of the copied string * @return The length of the copied string
*/ */
template<typename T1, typename T2> template<typename T1, typename T2>
...@@ -68,13 +68,13 @@ public: ...@@ -68,13 +68,13 @@ public:
} }
template<size_t N> template<size_t N>
static void CopyString(const char* src, char(&dst)[N]) { static void CopyString(const char* src, char(&dst)[N]) {
dst[0] = 0; std::strncpy(dst, src, N - 1);
std::strncat(dst, src, N - 1); dst[N - 1] = 0;
} }
template<size_t N> template<size_t N>
static void CopyWideString(const wchar_t* src, wchar_t(&dst)[N]) { static void CopyWideString(const wchar_t* src, wchar_t(&dst)[N]) {
dst[0] = 0; std::wcsncpy(dst, src, N - 1);
std::wcsncat(dst, src, N - 1); dst[N - 1] = 0;
} }
template<typename T> template<typename T>
static bool CheckUTF8Byte(const T* str, int len) { static bool CheckUTF8Byte(const T* str, int len) {
......
...@@ -35,11 +35,17 @@ int main(int argc, char* argv[]) { ...@@ -35,11 +35,17 @@ int main(int argc, char* argv[]) {
#ifdef __APPLE__ #ifdef __APPLE__
CFURLRef bundle_url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFURLRef bundle_url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFURLRef bundle_base_url = CFURLCreateCopyDeletingLastPathComponent(nullptr, bundle_url); CFURLRef bundle_base_url = CFURLCreateCopyDeletingLastPathComponent(nullptr, bundle_url);
CFStringRef bundle_ext = CFURLCopyPathExtension(bundle_url);
if (bundle_ext) {
char path[PATH_MAX];
if (CFStringCompare(bundle_ext, CFSTR("app"), kCFCompareCaseInsensitive) == kCFCompareEqualTo
&& CFURLGetFileSystemRepresentation(bundle_base_url, true, (UInt8*)path, PATH_MAX)) {
chdir(path);
}
CFRelease(bundle_ext);
}
CFRelease(bundle_url); CFRelease(bundle_url);
CFStringRef path = CFURLCopyFileSystemPath(bundle_base_url, kCFURLPOSIXPathStyle);
CFRelease(bundle_base_url); CFRelease(bundle_base_url);
chdir(CFStringGetCStringPtr(path, kCFStringEncodingUTF8));
CFRelease(path);
#endif //__APPLE__ #endif //__APPLE__
#ifdef _WIN32 #ifdef _WIN32
if (argc == 2 && (ygo::IsExtension(argv[1], ".ydk") || ygo::IsExtension(argv[1], ".yrp"))) { // open file from explorer if (argc == 2 && (ygo::IsExtension(argv[1], ".ydk") || ygo::IsExtension(argv[1], ".yrp"))) { // open file from explorer
......
...@@ -159,7 +159,7 @@ bool ReplayMode::StartDuel() { ...@@ -159,7 +159,7 @@ bool ReplayMode::StartDuel() {
unsigned int seed = rh.seed; unsigned int seed = rh.seed;
std::mt19937 rnd(seed); std::mt19937 rnd(seed);
cur_replay.SkipInfo(); cur_replay.SkipInfo();
if(mainGame->dInfo.isTag) { if(rh.flag & REPLAY_TAG) {
BufferIO::CopyWideString(cur_replay.players[0].c_str(), mainGame->dInfo.hostname); BufferIO::CopyWideString(cur_replay.players[0].c_str(), mainGame->dInfo.hostname);
BufferIO::CopyWideString(cur_replay.players[1].c_str(), mainGame->dInfo.hostname_tag); BufferIO::CopyWideString(cur_replay.players[1].c_str(), mainGame->dInfo.hostname_tag);
BufferIO::CopyWideString(cur_replay.players[2].c_str(), mainGame->dInfo.clientname_tag); BufferIO::CopyWideString(cur_replay.players[2].c_str(), mainGame->dInfo.clientname_tag);
...@@ -850,12 +850,12 @@ bool ReplayMode::ReplayAnalyze(unsigned char* msg, unsigned int len) { ...@@ -850,12 +850,12 @@ bool ReplayMode::ReplayAnalyze(unsigned char* msg, unsigned int len) {
break; break;
} }
case MSG_AI_NAME: { case MSG_AI_NAME: {
int len = BufferIO::ReadInt16(pbuf); int len = buffer_read<uint16_t>(pbuf);
pbuf += len + 1; pbuf += len + 1;
break; break;
} }
case MSG_SHOW_HINT: { case MSG_SHOW_HINT: {
int len = BufferIO::ReadInt16(pbuf); int len = buffer_read<uint16_t>(pbuf);
pbuf += len + 1; pbuf += len + 1;
break; break;
} }
......
...@@ -763,21 +763,25 @@ bool SingleMode::SinglePlayAnalyze(unsigned char* msg, unsigned int len) { ...@@ -763,21 +763,25 @@ bool SingleMode::SinglePlayAnalyze(unsigned char* msg, unsigned int len) {
case MSG_AI_NAME: { case MSG_AI_NAME: {
char namebuf[128]{}; char namebuf[128]{};
wchar_t wname[20]{}; wchar_t wname[20]{};
int len = BufferIO::ReadInt16(pbuf); int name_len = buffer_read<uint16_t>(pbuf);
auto begin = pbuf; if (name_len + 1 <= (int)sizeof namebuf) {
pbuf += len + 1; std::memcpy(namebuf, pbuf, name_len);
std::memcpy(namebuf, begin, len + 1); namebuf[name_len] = 0;
}
pbuf += name_len + 1;
BufferIO::DecodeUTF8(namebuf, wname); BufferIO::DecodeUTF8(namebuf, wname);
BufferIO::CopyCharArray(wname, mainGame->dInfo.clientname); BufferIO::CopyCharArray(wname, mainGame->dInfo.clientname);
break; break;
} }
case MSG_SHOW_HINT: { case MSG_SHOW_HINT: {
char msgbuf[1024]; char msgbuf[1024]{};
wchar_t msg[1024]; wchar_t msg[1024]{};
int len = BufferIO::ReadInt16(pbuf); int msg_len = buffer_read<uint16_t>(pbuf);
auto begin = pbuf; if (msg_len + 1 <= (int)sizeof msgbuf) {
pbuf += len + 1; std::memcpy(msgbuf, pbuf, msg_len);
std::memcpy(msgbuf, begin, len + 1); msgbuf[msg_len] = 0;
}
pbuf += msg_len + 1;
BufferIO::DecodeUTF8(msgbuf, msg); BufferIO::DecodeUTF8(msgbuf, msg);
mainGame->gMutex.lock(); mainGame->gMutex.lock();
mainGame->SetStaticText(mainGame->stMessage, 310, mainGame->guiFont, msg); mainGame->SetStaticText(mainGame->stMessage, 310, mainGame->guiFont, msg);
......
...@@ -16,6 +16,7 @@ project "irrlicht" ...@@ -16,6 +16,7 @@ project "irrlicht"
"_IRR_STATIC_LIB_", "_IRR_STATIC_LIB_",
"NO_IRR_USE_NON_SYSTEM_BZLIB_", "NO_IRR_USE_NON_SYSTEM_BZLIB_",
"NO_IRR_COMPILE_WITH_BZIP2_", "NO_IRR_COMPILE_WITH_BZIP2_",
"NO_IRR_COMPILE_WITH_LZMA_",
"NO_IRR_COMPILE_WITH_CONSOLE_DEVICE_", "NO_IRR_COMPILE_WITH_CONSOLE_DEVICE_",
"NO_IRR_COMPILE_WITH_DIRECT3D_8_", "NO_IRR_COMPILE_WITH_DIRECT3D_8_",
"NO_IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_", "NO_IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment