Commit 40a71691 authored by wind2009's avatar wind2009

Merge remote-tracking branch 'nanahira/server' into 2pick

parents 288bc2f6 57f42254
Pipeline #27541 passed with stages
in 2 minutes and 15 seconds
...@@ -71,12 +71,12 @@ mat_windows: ...@@ -71,12 +71,12 @@ mat_windows:
- wget -O - https://cdn01.moecube.com/ygopro-build-materials/libevent-2.0.22-stable.tar.gz | tar zfx - - wget -O - https://cdn01.moecube.com/ygopro-build-materials/libevent-2.0.22-stable.tar.gz | tar zfx -
- mv libevent-2.0.22-stable event - mv libevent-2.0.22-stable event
# irrlicht # irrlicht
- git clone --depth=1 https://code.mycard.moe/mycard/irrlicht-new irrlicht # - git clone --depth=1 https://code.mycard.moe/mycard/irrlicht-new irrlicht
artifacts: artifacts:
paths: paths:
- premake5.exe - premake5.exe
- event - event
- irrlicht # - irrlicht
._exec_build: ._exec_build:
stage: build stage: build
...@@ -98,7 +98,7 @@ exec_windows: ...@@ -98,7 +98,7 @@ exec_windows:
- mat_submodules - mat_submodules
script: script:
- bash -c 'cp -rf premake/* .' - bash -c 'cp -rf premake/* .'
- '.\premake5.exe vs2019 --server-zip-support' - '.\premake5.exe vs2019'
- cmd /c '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe" build\YGOPro.sln /m /p:Configuration=Release' - cmd /c '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe" build\YGOPro.sln /m /p:Configuration=Release'
- copy bin\release\ygopro.exe . - copy bin\release\ygopro.exe .
artifacts: artifacts:
......
No preview for this file type
...@@ -79,9 +79,9 @@ video::IImage* SGUITTGlyph::createGlyphImage(const FT_Bitmap& bits, video::IVide ...@@ -79,9 +79,9 @@ video::IImage* SGUITTGlyph::createGlyphImage(const FT_Bitmap& bits, video::IVide
const u32 image_pitch = image->getPitch() / sizeof(u16); const u32 image_pitch = image->getPitch() / sizeof(u16);
u16* image_data = (u16*)image->lock(); u16* image_data = (u16*)image->lock();
u8* glyph_data = bits.buffer; u8* glyph_data = bits.buffer;
for (s32 y = 0; y < bits.rows; ++y) { for (s32 y = 0; y < (s32)bits.rows; ++y) {
u16* row = image_data; u16* row = image_data;
for (s32 x = 0; x < bits.width; ++x) { for (s32 x = 0; x < (s32)bits.width; ++x) {
// Monochrome bitmaps store 8 pixels per byte. The left-most pixel is the bit 0x80. // Monochrome bitmaps store 8 pixels per byte. The left-most pixel is the bit 0x80.
// So, we go through the data each bit at a time. // So, we go through the data each bit at a time.
if ((glyph_data[y * bits.pitch + (x / 8)] & (0x80 >> (x % 8))) != 0) if ((glyph_data[y * bits.pitch + (x / 8)] & (0x80 >> (x % 8))) != 0)
...@@ -105,9 +105,9 @@ video::IImage* SGUITTGlyph::createGlyphImage(const FT_Bitmap& bits, video::IVide ...@@ -105,9 +105,9 @@ video::IImage* SGUITTGlyph::createGlyphImage(const FT_Bitmap& bits, video::IVide
const u32 image_pitch = image->getPitch() / sizeof(u32); const u32 image_pitch = image->getPitch() / sizeof(u32);
u32* image_data = (u32*)image->lock(); u32* image_data = (u32*)image->lock();
u8* glyph_data = bits.buffer; u8* glyph_data = bits.buffer;
for (s32 y = 0; y < bits.rows; ++y) { for (s32 y = 0; y < (s32)bits.rows; ++y) {
u8* row = glyph_data; u8* row = glyph_data;
for (s32 x = 0; x < bits.width; ++x) { for (s32 x = 0; x < (s32)bits.width; ++x) {
image_data[y * image_pitch + x] |= static_cast<u32>(255.0f * (static_cast<float>(*row++) / gray_count)) << 24; image_data[y * image_pitch + x] |= static_cast<u32>(255.0f * (static_cast<float>(*row++) / gray_count)) << 24;
//data[y * image_pitch + x] |= ((u32)(*bitsdata++) << 24); //data[y * image_pitch + x] |= ((u32)(*bitsdata++) << 24);
} }
...@@ -154,8 +154,8 @@ void SGUITTGlyph::preload(u32 char_index, FT_Face face, video::IVideoDriver* dri ...@@ -154,8 +154,8 @@ void SGUITTGlyph::preload(u32 char_index, FT_Face face, video::IVideoDriver* dri
glyph_page = parent->getLastGlyphPageIndex(); glyph_page = parent->getLastGlyphPageIndex();
u32 texture_side_length = page->texture_size.Width - font_size; u32 texture_side_length = page->texture_size.Width - font_size;
u32 margin = font_size * 0.5; u32 margin = (u32)(font_size * 0.5);
u32 sprite_size = font_size * 1.5; u32 sprite_size = (u32)(font_size * 1.5);
core::vector2di page_position( core::vector2di page_position(
(s32)(page->used_slots % (s32)(texture_side_length / sprite_size)) * sprite_size + margin, (s32)(page->used_slots % (s32)(texture_side_length / sprite_size)) * sprite_size + margin,
(s32)(page->used_slots / (s32)(texture_side_length / sprite_size)) * sprite_size + margin (s32)(page->used_slots / (s32)(texture_side_length / sprite_size)) * sprite_size + margin
...@@ -527,29 +527,28 @@ void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position ...@@ -527,29 +527,28 @@ void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position
core::ustring::const_iterator iter(utext); core::ustring::const_iterator iter(utext);
while (!iter.atEnd()) { while (!iter.atEnd()) {
uchar32_t currentChar = *iter; uchar32_t currentChar = *iter;
bool lineBreak = false;
if (currentChar == L'\r') { // Mac or Windows breaks
lineBreak = true;
if (*(iter + 1) == L'\n') // Windows line breaks.
currentChar = *(++iter);
} else if (currentChar == L'\n') { // Unix breaks
lineBreak = true;
}
if (lineBreak) {
previousChar = 0;
offset.Y += supposed_line_height; //font_metrics.ascender / 64;
offset.X = position.UpperLeftCorner.X;
if (hcenter)
offset.X += (position.getWidth() - textDimension.Width) >> 1;
++iter;
continue;
}
n = getGlyphIndexByChar(currentChar); n = getGlyphIndexByChar(currentChar);
bool visible = (Invisible.findFirst(currentChar) == -1); bool visible = (Invisible.findFirst(currentChar) == -1);
if (n > 0 && visible) { if (n > 0 && visible) {
bool lineBreak = false;
if (currentChar == L'\r') { // Mac or Windows breaks
lineBreak = true;
if (*(iter + 1) == (uchar32_t)'\n') // Windows line breaks.
currentChar = *(++iter);
} else if (currentChar == (uchar32_t)'\n') { // Unix breaks
lineBreak = true;
}
if (lineBreak) {
previousChar = 0;
offset.Y += supposed_line_height; //font_metrics.ascender / 64;
offset.X = position.UpperLeftCorner.X;
if (hcenter)
offset.X += (position.getWidth() - textDimension.Width) >> 1;
++iter;
continue;
}
// Calculate the glyph offset. // Calculate the glyph offset.
s32 offx = Glyphs[n - 1].offset.X; s32 offx = Glyphs[n - 1].offset.X;
s32 offy = (font_metrics.ascender / 64) - Glyphs[n - 1].offset.Y; s32 offy = (font_metrics.ascender / 64) - Glyphs[n - 1].offset.Y;
......
...@@ -53,9 +53,9 @@ class Base64 { ...@@ -53,9 +53,9 @@ class Base64 {
return (enc_len == out->size()); return (enc_len == out->size());
} }
static bool Encode(const char *input, size_t input_length, char *out, size_t out_length) { static bool Encode(const unsigned char *input, size_t input_length, unsigned char *out, size_t out_length) {
int i = 0, j = 0; int i = 0, j = 0;
char *out_begin = out; unsigned char *out_begin = out;
unsigned char a3[3]; unsigned char a3[3];
unsigned char a4[4]; unsigned char a4[4];
...@@ -148,9 +148,9 @@ class Base64 { ...@@ -148,9 +148,9 @@ class Base64 {
return (dec_len == out->size()); return (dec_len == out->size());
} }
static bool Decode(const char *input, size_t input_length, char *out, size_t out_length) { static bool Decode(const unsigned char *input, size_t input_length, unsigned char *out, size_t out_length) {
int i = 0, j = 0; int i = 0, j = 0;
char *out_begin = out; unsigned char *out_begin = out;
unsigned char a3[3]; unsigned char a3[3];
unsigned char a4[4]; unsigned char a4[4];
...@@ -198,10 +198,10 @@ class Base64 { ...@@ -198,10 +198,10 @@ class Base64 {
return (out == (out_begin + decoded_length)); return (out == (out_begin + decoded_length));
} }
static int DecodedLength(const char *in, size_t in_length) { static int DecodedLength(const unsigned char *in, size_t in_length) {
int numEq = 0; int numEq = 0;
const char *in_end = in + in_length; const unsigned char *in_end = in + in_length;
while (*--in_end == '=') ++numEq; while (*--in_end == '=') ++numEq;
return ((6 * in_length) / 8) - numEq; return ((6 * in_length) / 8) - numEq;
......
#ifndef BUFFERIO_H #ifndef BUFFERIO_H
#define BUFFERIO_H #define BUFFERIO_H
#ifdef _MSC_VER #include <cstdint>
#pragma warning(disable: 4244) #include "../ocgcore/buffer.h"
#endif
class BufferIO { class BufferIO {
public: public:
inline static int ReadInt32(char*& p) { inline static int ReadInt32(unsigned char*& p) {
int ret = *(int*)p; return buffer_read<int32_t>(p);
p += 4;
return ret;
} }
inline static unsigned int ReadUInt32(char*& p) { inline static unsigned int ReadUInt32(unsigned char*& p) {
unsigned int ret = *(unsigned int*)p; unsigned int ret = *(unsigned int*)p;
p += 4; p += 4;
return ret; return ret;
} }
inline static short ReadInt16(char*& p) { inline static short ReadInt16(unsigned char*& p) {
short ret = *(short*)p; return buffer_read<int16_t>(p);
p += 2;
return ret;
} }
inline static unsigned short ReadUInt16(char*& p) { inline static unsigned short ReadUInt16(unsigned char*& p) {
unsigned short ret = *(unsigned short*)p; unsigned short ret = *(unsigned short*)p;
p += 2; p += 2;
return ret; return ret;
} }
inline static char ReadInt8(char*& p) { inline static char ReadInt8(unsigned char*& p) {
char ret = *(char*)p; return buffer_read<char>(p);
p++;
return ret;
} }
inline static unsigned char ReadUInt8(char*& p) { inline static unsigned char ReadUInt8(unsigned char*& p) {
unsigned char ret = *(unsigned char*)p; return buffer_read<unsigned char>(p);
p++;
return ret;
} }
inline static void WriteInt32(char*& p, int val) { inline static void WriteInt32(unsigned char*& p, int val) {
(*(int*)p) = val; buffer_write<int32_t>(p, val);
p += 4;
} }
inline static void WriteInt16(char*& p, short val) { inline static void WriteInt16(unsigned char*& p, short val) {
(*(short*)p) = val; buffer_write<int16_t>(p, val);
p += 2;
} }
inline static void WriteInt8(char*& p, char val) { inline static void WriteInt8(unsigned char*& p, char val) {
*p = val; buffer_write<char>(p, val);
p++;
} }
// return: string length
template<typename T1, typename T2> template<typename T1, typename T2>
inline static int CopyWStr(T1* src, T2* pstr, int bufsize) { inline static int CopyWStr(const T1* src, T2* pstr, int bufsize) {
int l = 0; int l = 0;
while(src[l] && l < bufsize - 1) { while(src[l] && l < bufsize - 1) {
pstr[l] = src[l]; pstr[l] = (T2)src[l];
l++; l++;
} }
pstr[l] = 0; pstr[l] = 0;
return l; return l;
} }
template<typename T1, typename T2> template<typename T1, typename T2>
inline static int CopyWStrRef(T1* src, T2*& pstr, int bufsize) { inline static int CopyWStrRef(const T1* src, T2*& pstr, int bufsize) {
int l = 0; int l = 0;
while(src[l] && l < bufsize - 1) { while(src[l] && l < bufsize - 1) {
pstr[l] = src[l]; pstr[l] = (T2)src[l];
l++; l++;
} }
pstr += l; pstr += l;
...@@ -71,67 +60,93 @@ public: ...@@ -71,67 +60,93 @@ public:
return l; return l;
} }
// UTF-16/UTF-32 to UTF-8 // UTF-16/UTF-32 to UTF-8
static int EncodeUTF8(const wchar_t * wsrc, char * str) { // return: string length
static int EncodeUTF8String(const wchar_t* wsrc, char* str, int size) {
char* pstr = str; char* pstr = str;
while(*wsrc != 0) { while (*wsrc != 0) {
if(*wsrc < 0x80) { unsigned cur = *wsrc;
*str = *wsrc; int codepoint_size = 0;
++str; if (cur < 0x80U)
} else if(*wsrc < 0x800) { codepoint_size = 1;
str[0] = ((*wsrc >> 6) & 0x1f) | 0xc0; else if (cur < 0x800U)
str[1] = ((*wsrc) & 0x3f) | 0x80; codepoint_size = 2;
str += 2; else if (cur < 0x10000U && (cur < 0xd800U || cur > 0xdfffU))
} else if(*wsrc < 0x10000 && (*wsrc < 0xd800 || *wsrc > 0xdfff)) { codepoint_size = 3;
str[0] = ((*wsrc >> 12) & 0xf) | 0xe0; else
str[1] = ((*wsrc >> 6) & 0x3f) | 0x80; codepoint_size = 4;
str[2] = ((*wsrc) & 0x3f) | 0x80; if (pstr - str + codepoint_size > size - 1)
str += 3; break;
} else { switch (codepoint_size) {
#ifdef _WIN32 case 1:
unsigned unicode = 0; *pstr = (char)cur;
unicode |= (*wsrc++ & 0x3ff) << 10; break;
unicode |= *wsrc & 0x3ff; case 2:
unicode += 0x10000; pstr[0] = ((cur >> 6) & 0x1f) | 0xc0;
str[0] = ((unicode >> 18) & 0x7) | 0xf0; pstr[1] = (cur & 0x3f) | 0x80;
str[1] = ((unicode >> 12) & 0x3f) | 0x80; break;
str[2] = ((unicode >> 6) & 0x3f) | 0x80; case 3:
str[3] = ((unicode) & 0x3f) | 0x80; pstr[0] = ((cur >> 12) & 0xf) | 0xe0;
#else pstr[1] = ((cur >> 6) & 0x3f) | 0x80;
str[0] = ((*wsrc >> 18) & 0x7) | 0xf0; pstr[2] = (cur & 0x3f) | 0x80;
str[1] = ((*wsrc >> 12) & 0x3f) | 0x80; break;
str[2] = ((*wsrc >> 6) & 0x3f) | 0x80; case 4:
str[3] = ((*wsrc) & 0x3f) | 0x80; if (sizeof(wchar_t) == 2) {
#endif // _WIN32 cur = 0;
str += 4; cur |= ((unsigned)*wsrc & 0x3ff) << 10;
++wsrc;
cur |= (unsigned)*wsrc & 0x3ff;
cur += 0x10000;
}
pstr[0] = ((cur >> 18) & 0x7) | 0xf0;
pstr[1] = ((cur >> 12) & 0x3f) | 0x80;
pstr[2] = ((cur >> 6) & 0x3f) | 0x80;
pstr[3] = (cur & 0x3f) | 0x80;
break;
default:
break;
} }
pstr += codepoint_size;
wsrc++; wsrc++;
} }
*str = 0; *pstr = 0;
return str - pstr; return pstr - str;
} }
// UTF-8 to UTF-16/UTF-32 // UTF-8 to UTF-16/UTF-32
static int DecodeUTF8(const char * src, wchar_t * wstr) { // return: string length
static int DecodeUTF8String(const char* src, wchar_t* wstr, int size) {
const char* p = src; const char* p = src;
wchar_t* wp = wstr; wchar_t* wp = wstr;
while(*p != 0) { while(*p != 0) {
if((*p & 0x80) == 0) { const unsigned cur = (unsigned)*p & 0xff;
int codepoint_size = 0;
if ((cur & 0xf8) == 0xf0) {
if (sizeof(wchar_t) == 2)
codepoint_size = 2;
else
codepoint_size = 1;
}
else
codepoint_size = 1;
if (wp - wstr + codepoint_size > size - 1)
break;
if((cur & 0x80) == 0) {
*wp = *p; *wp = *p;
p++; p++;
} else if((*p & 0xe0) == 0xc0) { } else if((cur & 0xe0) == 0xc0) {
*wp = (((unsigned)p[0] & 0x1f) << 6) | ((unsigned)p[1] & 0x3f); *wp = (((unsigned)p[0] & 0x1f) << 6) | ((unsigned)p[1] & 0x3f);
p += 2; p += 2;
} else if((*p & 0xf0) == 0xe0) { } else if((cur & 0xf0) == 0xe0) {
*wp = (((unsigned)p[0] & 0xf) << 12) | (((unsigned)p[1] & 0x3f) << 6) | ((unsigned)p[2] & 0x3f); *wp = (((unsigned)p[0] & 0xf) << 12) | (((unsigned)p[1] & 0x3f) << 6) | ((unsigned)p[2] & 0x3f);
p += 3; p += 3;
} else if((*p & 0xf8) == 0xf0) { } else if((cur & 0xf8) == 0xf0) {
#ifdef _WIN32 if (sizeof(wchar_t) == 2) {
unsigned unicode = (((unsigned)p[0] & 0x7) << 18) | (((unsigned)p[1] & 0x3f) << 12) | (((unsigned)p[2] & 0x3f) << 6) | ((unsigned)p[3] & 0x3f); unsigned unicode = (((unsigned)p[0] & 0x7) << 18) | (((unsigned)p[1] & 0x3f) << 12) | (((unsigned)p[2] & 0x3f) << 6) | ((unsigned)p[3] & 0x3f);
unicode -= 0x10000; unicode -= 0x10000;
*wp++ = (unicode >> 10) | 0xd800; *wp++ = (unicode >> 10) | 0xd800;
*wp = (unicode & 0x3ff) | 0xdc00; *wp = (unicode & 0x3ff) | 0xdc00;
#else } else {
*wp = (((unsigned)p[0] & 0x7) << 18) | (((unsigned)p[1] & 0x3f) << 12) | (((unsigned)p[2] & 0x3f) << 6) | ((unsigned)p[3] & 0x3f); *wp = (((unsigned)p[0] & 0x7) << 18) | (((unsigned)p[1] & 0x3f) << 12) | (((unsigned)p[2] & 0x3f) << 6) | ((unsigned)p[3] & 0x3f);
#endif // _WIN32 }
p += 4; p += 4;
} else } else
p++; p++;
...@@ -140,13 +155,23 @@ public: ...@@ -140,13 +155,23 @@ public:
*wp = 0; *wp = 0;
return wp - wstr; return wp - wstr;
} }
template<size_t N>
static int EncodeUTF8(const wchar_t* src, char(&dst)[N]) {
return EncodeUTF8String(src, dst, N);
}
template<size_t N>
static int DecodeUTF8(const char* src, wchar_t(&dst)[N]) {
return DecodeUTF8String(src, dst, N);
}
static int GetVal(const wchar_t* pstr) { static int GetVal(const wchar_t* pstr) {
int ret = 0; unsigned int ret = 0;
while(*pstr >= L'0' && *pstr <= L'9') { while(*pstr >= L'0' && *pstr <= L'9') {
ret = ret * 10 + (*pstr - L'0'); ret = ret * 10 + (*pstr - L'0');
pstr++; pstr++;
} }
return ret; if (*pstr == 0)
return (int)ret;
return 0;
} }
}; };
......
...@@ -5,50 +5,32 @@ ...@@ -5,50 +5,32 @@
namespace ygo { namespace ygo {
ClientCard::ClientCard() { ClientCard::~ClientCard() {
curAlpha = 255; ClearTarget();
dAlpha = 0; if (equipTarget) {
aniFrame = 0; equipTarget->is_showequip = false;
is_moving = false; equipTarget->equipped.erase(this);
is_fading = false; equipTarget = nullptr;
is_hovered = false; }
is_selectable = false; for (auto& card : equipped) {
is_selected = false; card->is_showequip = false;
is_showequip = false; card->equipTarget = nullptr;
is_showtarget = false; }
is_showchaintarget = false; equipped.clear();
is_highlighting = false; if (overlayTarget) {
status = 0; for (auto it = overlayTarget->overlayed.begin(); it != overlayTarget->overlayed.end(); ) {
is_reversed = false; if (*it == this) {
cmdFlag = 0; it = overlayTarget->overlayed.erase(it);
code = 0; }
chain_code = 0; else
location = 0; ++it;
type = 0; }
alias = 0; overlayTarget = nullptr;
level = 0; }
rank = 0; for (auto& card : overlayed) {
link = 0; card->overlayTarget = nullptr;
race = 0; }
attribute = 0; overlayed.clear();
attack = 0;
defense = 0;
base_attack = 0;
base_defense = 0;
lscale = 0;
rscale = 0;
link_marker = 0;
position = 0;
cHint = 0;
chValue = 0;
atkstring[0] = 0;
defstring[0] = 0;
lvstring[0] = 0;
linkstring[0] = 0;
rscstring[0] = 0;
lscstring[0] = 0;
overlayTarget = 0;
equipTarget = 0;
} }
void ClientCard::SetCode(int code) { void ClientCard::SetCode(int code) {
if((location == LOCATION_HAND) && (this->code != (unsigned int)code)) { if((location == LOCATION_HAND) && (this->code != (unsigned int)code)) {
...@@ -57,13 +39,16 @@ void ClientCard::SetCode(int code) { ...@@ -57,13 +39,16 @@ void ClientCard::SetCode(int code) {
} else } else
this->code = code; this->code = code;
} }
void ClientCard::UpdateInfo(char* buf) { void ClientCard::UpdateInfo(unsigned char* buf) {
int flag = BufferIO::ReadInt32(buf); int flag = BufferIO::ReadInt32(buf);
if(flag == 0) if (flag == 0) {
ClearData();
return; return;
int pdata; }
if(flag & QUERY_CODE) { if(flag & QUERY_CODE) {
pdata = BufferIO::ReadInt32(buf); int pdata = BufferIO::ReadInt32(buf);
if (!pdata)
ClearData();
if((location == LOCATION_HAND) && ((unsigned int)pdata != code)) { if((location == LOCATION_HAND) && ((unsigned int)pdata != code)) {
code = pdata; code = pdata;
mainGame->dField.MoveCard(this, 5); mainGame->dField.MoveCard(this, 5);
...@@ -71,7 +56,7 @@ void ClientCard::UpdateInfo(char* buf) { ...@@ -71,7 +56,7 @@ void ClientCard::UpdateInfo(char* buf) {
code = pdata; code = pdata;
} }
if(flag & QUERY_POSITION) { if(flag & QUERY_POSITION) {
pdata = (BufferIO::ReadInt32(buf) >> 24) & 0xff; int pdata = (BufferIO::ReadInt32(buf) >> 24) & 0xff;
if((location & (LOCATION_EXTRA | LOCATION_REMOVED)) && (u8)pdata != position) { if((location & (LOCATION_EXTRA | LOCATION_REMOVED)) && (u8)pdata != position) {
position = pdata; position = pdata;
mainGame->dField.MoveCard(this, 1); mainGame->dField.MoveCard(this, 1);
...@@ -83,14 +68,14 @@ void ClientCard::UpdateInfo(char* buf) { ...@@ -83,14 +68,14 @@ void ClientCard::UpdateInfo(char* buf) {
if(flag & QUERY_TYPE) if(flag & QUERY_TYPE)
type = BufferIO::ReadInt32(buf); type = BufferIO::ReadInt32(buf);
if(flag & QUERY_LEVEL) { if(flag & QUERY_LEVEL) {
pdata = BufferIO::ReadInt32(buf); int pdata = BufferIO::ReadInt32(buf);
if(level != (unsigned int)pdata) { if(level != (unsigned int)pdata) {
level = pdata; level = pdata;
myswprintf(lvstring, L"L%d", level); myswprintf(lvstring, L"L%d", level);
} }
} }
if(flag & QUERY_RANK) { if(flag & QUERY_RANK) {
pdata = BufferIO::ReadInt32(buf); int pdata = BufferIO::ReadInt32(buf);
if(pdata && rank != (unsigned int)pdata) { if(pdata && rank != (unsigned int)pdata) {
rank = pdata; rank = pdata;
myswprintf(lvstring, L"R%d", rank); myswprintf(lvstring, L"R%d", rank);
...@@ -128,24 +113,28 @@ void ClientCard::UpdateInfo(char* buf) { ...@@ -128,24 +113,28 @@ void ClientCard::UpdateInfo(char* buf) {
if(flag & QUERY_REASON_CARD) if(flag & QUERY_REASON_CARD)
buf += 4; buf += 4;
if(flag & QUERY_EQUIP_CARD) { if(flag & QUERY_EQUIP_CARD) {
int c = BufferIO::ReadInt8(buf); int c = BufferIO::ReadUInt8(buf);
int l = BufferIO::ReadInt8(buf); unsigned int l = BufferIO::ReadUInt8(buf);
int s = BufferIO::ReadInt8(buf); int s = BufferIO::ReadUInt8(buf);
BufferIO::ReadInt8(buf); BufferIO::ReadUInt8(buf);
ClientCard* ecard = mainGame->dField.GetCard(mainGame->LocalPlayer(c), l, s); ClientCard* ecard = mainGame->dField.GetCard(mainGame->LocalPlayer(c), l, s);
equipTarget = ecard; if (ecard) {
ecard->equipped.insert(this); equipTarget = ecard;
ecard->equipped.insert(this);
}
} }
if(flag & QUERY_TARGET_CARD) { if(flag & QUERY_TARGET_CARD) {
int count = BufferIO::ReadInt32(buf); int count = BufferIO::ReadInt32(buf);
for(int i = 0; i < count; ++i) { for(int i = 0; i < count; ++i) {
int c = BufferIO::ReadInt8(buf); int c = BufferIO::ReadUInt8(buf);
int l = BufferIO::ReadInt8(buf); unsigned int l = BufferIO::ReadUInt8(buf);
int s = BufferIO::ReadInt8(buf); int s = BufferIO::ReadUInt8(buf);
BufferIO::ReadInt8(buf); BufferIO::ReadUInt8(buf);
ClientCard* tcard = mainGame->dField.GetCard(mainGame->LocalPlayer(c), l, s); ClientCard* tcard = mainGame->dField.GetCard(mainGame->LocalPlayer(c), l, s);
cardTarget.insert(tcard); if (tcard) {
tcard->ownerTarget.insert(this); cardTarget.insert(tcard);
tcard->ownerTarget.insert(this);
}
} }
} }
if(flag & QUERY_OVERLAY_CARD) { if(flag & QUERY_OVERLAY_CARD) {
...@@ -175,7 +164,7 @@ void ClientCard::UpdateInfo(char* buf) { ...@@ -175,7 +164,7 @@ void ClientCard::UpdateInfo(char* buf) {
myswprintf(rscstring, L"%d", rscale); myswprintf(rscstring, L"%d", rscale);
} }
if(flag & QUERY_LINK) { if(flag & QUERY_LINK) {
pdata = BufferIO::ReadInt32(buf); int pdata = BufferIO::ReadInt32(buf);
if (link != (unsigned int)pdata) { if (link != (unsigned int)pdata) {
link = pdata; link = pdata;
} }
...@@ -198,6 +187,31 @@ void ClientCard::ClearTarget() { ...@@ -198,6 +187,31 @@ void ClientCard::ClearTarget() {
cardTarget.clear(); cardTarget.clear();
ownerTarget.clear(); ownerTarget.clear();
} }
void ClientCard::ClearData() {
alias = 0;
type = 0;
level = 0;
rank = 0;
race = 0;
attribute = 0;
attack = 0;
defense = 0;
base_attack = 0;
base_defense = 0;
lscale = 0;
rscale = 0;
link = 0;
link_marker = 0;
status = 0;
atkstring[0] = 0;
defstring[0] = 0;
lvstring[0] = 0;
linkstring[0] = 0;
rscstring[0] = 0;
lscstring[0] = 0;
counters.clear();
}
bool ClientCard::client_card_sort(ClientCard* c1, ClientCard* c2) { bool ClientCard::client_card_sort(ClientCard* c1, ClientCard* c2) {
if(c1->is_selected != c2->is_selected) if(c1->is_selected != c2->is_selected)
return c1->is_selected < c2->is_selected; return c1->is_selected < c2->is_selected;
...@@ -207,23 +221,26 @@ bool ClientCard::client_card_sort(ClientCard* c1, ClientCard* c2) { ...@@ -207,23 +221,26 @@ bool ClientCard::client_card_sort(ClientCard* c1, ClientCard* c2) {
return cp1 < cp2; return cp1 < cp2;
if(c1->location != c2->location) if(c1->location != c2->location)
return c1->location < c2->location; return c1->location < c2->location;
if(c1->location & LOCATION_OVERLAY) if (c1->location & LOCATION_OVERLAY) {
if(c1->overlayTarget != c2->overlayTarget) if (c1->overlayTarget != c2->overlayTarget)
return c1->overlayTarget->sequence < c2->overlayTarget->sequence; return c1->overlayTarget->sequence < c2->overlayTarget->sequence;
else return c1->sequence < c2->sequence; else
return c1->sequence < c2->sequence;
}
else { else {
if(c1->location & (LOCATION_DECK | LOCATION_GRAVE | LOCATION_REMOVED | LOCATION_EXTRA)) { if(c1->location & (LOCATION_DECK | LOCATION_GRAVE | LOCATION_REMOVED | LOCATION_EXTRA)) {
auto it1 = std::find_if(mainGame->dField.chains.rbegin(), mainGame->dField.chains.rend(), [c1](const auto& ch) { auto it1 = std::find_if(mainGame->dField.chains.rbegin(), mainGame->dField.chains.rend(), [c1](const ChainInfo& ch) {
return c1 == ch.chain_card || ch.target.find(c1) != ch.target.end(); return c1 == ch.chain_card || ch.target.find(c1) != ch.target.end();
}); });
auto it2 = std::find_if(mainGame->dField.chains.rbegin(), mainGame->dField.chains.rend(), [c2](const auto& ch) { auto it2 = std::find_if(mainGame->dField.chains.rbegin(), mainGame->dField.chains.rend(), [c2](const ChainInfo& ch) {
return c2 == ch.chain_card || ch.target.find(c2) != ch.target.end(); return c2 == ch.chain_card || ch.target.find(c2) != ch.target.end();
}); });
if(it1 != mainGame->dField.chains.rend() || it2 != mainGame->dField.chains.rend()) { if(it1 != mainGame->dField.chains.rend() || it2 != mainGame->dField.chains.rend()) {
return it1 < it2; return it1 < it2;
} }
return c1->sequence > c2->sequence; return c1->sequence > c2->sequence;
} else }
else
return c1->sequence < c2->sequence; return c1->sequence < c2->sequence;
} }
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define CLIENT_CARD_H #define CLIENT_CARD_H
#include "config.h" #include "config.h"
#include "../ocgcore/card_data.h"
#include <vector> #include <vector>
#include <set> #include <set>
#include <map> #include <map>
...@@ -9,35 +10,18 @@ ...@@ -9,35 +10,18 @@
namespace ygo { namespace ygo {
struct CardData { using CardData = card_data;
unsigned int code; struct CardDataC : card_data {
unsigned int alias; unsigned int ot{};
unsigned long long setcode; unsigned int category{};
unsigned int type;
unsigned int level; bool is_setcodes(std::vector <uint32> values) const {
unsigned int attribute; for (auto& value : values) {
unsigned int race; if (is_setcode(value))
int attack; return true;
int defense; }
unsigned int lscale; return false;
unsigned int rscale; }
unsigned int link_marker;
};
struct CardDataC {
unsigned int code;
unsigned int alias;
unsigned long long setcode;
unsigned int type;
unsigned int level;
unsigned int attribute;
unsigned int race;
int attack;
int defense;
unsigned int lscale;
unsigned int rscale;
unsigned int link_marker;
unsigned int ot;
unsigned int category;
}; };
struct CardString { struct CardString {
std::wstring name; std::wstring name;
...@@ -45,6 +29,7 @@ struct CardString { ...@@ -45,6 +29,7 @@ struct CardString {
std::wstring desc[16]; std::wstring desc[16];
}; };
typedef std::unordered_map<unsigned int, CardDataC>::const_iterator code_pointer; typedef std::unordered_map<unsigned int, CardDataC>::const_iterator code_pointer;
typedef std::unordered_map<unsigned int, CardString>::const_iterator string_pointer;
class ClientCard { class ClientCard {
public: public:
...@@ -54,67 +39,70 @@ public: ...@@ -54,67 +39,70 @@ public:
irr::core::vector3df curRot; irr::core::vector3df curRot;
irr::core::vector3df dPos; irr::core::vector3df dPos;
irr::core::vector3df dRot; irr::core::vector3df dRot;
u32 curAlpha; u32 curAlpha{ 255 };
u32 dAlpha; u32 dAlpha{ 0 };
u32 aniFrame; u32 aniFrame{ 0 };
bool is_moving; bool is_moving{ false };
bool is_fading; bool is_fading{ false };
bool is_hovered; bool is_hovered{ false };
bool is_selectable; bool is_selectable{ false };
bool is_selected; bool is_selected{ false };
bool is_showequip; bool is_showequip{ false };
bool is_showtarget; bool is_showtarget{ false };
bool is_showchaintarget; bool is_showchaintarget{ false };
bool is_highlighting; bool is_highlighting{ false };
bool is_reversed; bool is_reversed{ false };
u32 code;
u32 chain_code; unsigned int code{ 0 };
u32 alias; unsigned int chain_code{ 0 };
u32 type; unsigned int alias{ 0 };
u32 level; unsigned int type{ 0 };
u32 rank; unsigned int level{ 0 };
u32 link; unsigned int rank{ 0 };
u32 attribute; unsigned int link{ 0 };
u32 race; unsigned int attribute{ 0 };
s32 attack; unsigned int race{ 0 };
s32 defense; int attack{ 0 };
s32 base_attack; int defense{ 0 };
s32 base_defense; int base_attack{ 0 };
u32 lscale; int base_defense{ 0 };
u32 rscale; unsigned int lscale{ 0 };
u32 link_marker; unsigned int rscale{ 0 };
u32 reason; unsigned int link_marker{ 0 };
u32 select_seq; unsigned int reason{ 0 };
u8 owner; unsigned int select_seq{ 0 };
u8 controler; unsigned char owner{ PLAYER_NONE };
u8 location; unsigned char controler{ PLAYER_NONE };
u8 sequence; unsigned char location{ 0 };
u8 position; unsigned char sequence{ 0 };
u32 status; unsigned char position{ 0 };
u8 cHint; unsigned int status{ 0 };
u32 chValue; unsigned char cHint{ 0 };
u32 opParam; unsigned int chValue{ 0 };
u32 symbol; unsigned int opParam{ 0 };
u32 cmdFlag; unsigned int symbol{ 0 };
ClientCard* overlayTarget; unsigned int cmdFlag{ 0 };
ClientCard* overlayTarget{ nullptr };
std::vector<ClientCard*> overlayed; std::vector<ClientCard*> overlayed;
ClientCard* equipTarget; ClientCard* equipTarget{ nullptr };
std::set<ClientCard*> equipped; std::set<ClientCard*> equipped;
std::set<ClientCard*> cardTarget; std::set<ClientCard*> cardTarget;
std::set<ClientCard*> ownerTarget; std::set<ClientCard*> ownerTarget;
std::map<int, int> counters; std::map<int, int> counters;
std::map<int, int> desc_hints; std::map<int, int> desc_hints;
wchar_t atkstring[16]; wchar_t atkstring[16]{};
wchar_t defstring[16]; wchar_t defstring[16]{};
wchar_t lvstring[16]; wchar_t lvstring[16]{};
wchar_t linkstring[16]; wchar_t linkstring[16]{};
wchar_t lscstring[16]; wchar_t lscstring[16]{};
wchar_t rscstring[16]; wchar_t rscstring[16]{};
ClientCard(); ClientCard() = default;
~ClientCard();
void SetCode(int code); void SetCode(int code);
void UpdateInfo(char* buf); void UpdateInfo(unsigned char* buf);
void ClearTarget(); void ClearTarget();
void ClearData();
static bool client_card_sort(ClientCard* c1, ClientCard* c2); static bool client_card_sort(ClientCard* c1, ClientCard* c2);
static bool deck_sort_lv(code_pointer l1, code_pointer l2); static bool deck_sort_lv(code_pointer l1, code_pointer l2);
static bool deck_sort_atk(code_pointer l1, code_pointer l2); static bool deck_sort_atk(code_pointer l1, code_pointer l2);
......
This diff is collapsed.
...@@ -13,13 +13,13 @@ class ClientCard; ...@@ -13,13 +13,13 @@ class ClientCard;
struct ChainInfo { struct ChainInfo {
irr::core::vector3df chain_pos; irr::core::vector3df chain_pos;
ClientCard* chain_card; ClientCard* chain_card{ nullptr };
int code; int code{ 0 };
int desc; int desc{ 0 };
int controler; int controler{ 0 };
int location; int location{ 0 };
int sequence; int sequence{ 0 };
bool solved; bool solved{ false };
std::set<ClientCard*> target; std::set<ClientCard*> target;
}; };
...@@ -34,6 +34,7 @@ public: ...@@ -34,6 +34,7 @@ public:
std::vector<ClientCard*> extra[2]; std::vector<ClientCard*> extra[2];
std::vector<ClientCard*> limbo_temp; std::vector<ClientCard*> limbo_temp;
std::set<ClientCard*> overlay_cards; std::set<ClientCard*> overlay_cards;
std::vector<ClientCard*> summonable_cards; std::vector<ClientCard*> summonable_cards;
std::vector<ClientCard*> spsummonable_cards; std::vector<ClientCard*> spsummonable_cards;
std::vector<ClientCard*> msetable_cards; std::vector<ClientCard*> msetable_cards;
...@@ -46,27 +47,27 @@ public: ...@@ -46,27 +47,27 @@ public:
std::vector<int> select_options; std::vector<int> select_options;
std::vector<int> select_options_index; std::vector<int> select_options_index;
std::vector<ChainInfo> chains; std::vector<ChainInfo> chains;
int extra_p_count[2]; int extra_p_count[2]{};
size_t selected_option; size_t selected_option{ 0 };
ClientCard* attacker; ClientCard* attacker{ nullptr };
ClientCard* attack_target; ClientCard* attack_target{ nullptr };
unsigned int disabled_field; unsigned int disabled_field{ 0 };
unsigned int selectable_field; unsigned int selectable_field{ 0 };
unsigned int selected_field; unsigned int selected_field{ 0 };
int select_min; int select_min{ 0 };
int select_max; int select_max{ 0 };
int must_select_count; int must_select_count{ 0 };
int select_sumval; int select_sumval{ 0 };
int select_mode; int select_mode{ 0 };
bool select_cancelable; bool select_cancelable{ false };
bool select_panalmode; bool select_panalmode{ false };
bool select_ready; bool select_ready{ false };
int announce_count; int announce_count{ 0 };
int select_counter_count; int select_counter_count{ 0 };
int select_counter_type; int select_counter_type{ 0 };
int current_mset_param; int current_mset_param{ 0 };
std::vector<ClientCard *> selectable_cards; std::vector<ClientCard*> selectable_cards;
std::vector<ClientCard*> selected_cards; std::vector<ClientCard*> selected_cards;
std::set<ClientCard*> selectsum_cards; std::set<ClientCard*> selectsum_cards;
std::vector<ClientCard*> selectsum_all; std::vector<ClientCard*> selectsum_all;
...@@ -74,28 +75,31 @@ public: ...@@ -74,28 +75,31 @@ public:
std::vector<ClientCard*> display_cards; std::vector<ClientCard*> display_cards;
std::vector<int> sort_list; std::vector<int> sort_list;
std::map<int, int> player_desc_hints[2]; std::map<int, int> player_desc_hints[2];
bool grave_act; bool grave_act{ false };
bool remove_act; bool remove_act{ false };
bool deck_act; bool deck_act{ false };
bool extra_act; bool extra_act{ false };
bool pzone_act[2]; bool pzone_act[2]{};
bool conti_act; bool conti_act{ false };
bool chain_forced; bool chain_forced{ false };
ChainInfo current_chain; ChainInfo current_chain;
bool last_chain; bool last_chain{ false };
bool deck_reversed; bool deck_reversed{ false };
bool conti_selecting; bool conti_selecting{ false };
bool cant_check_grave; bool cant_check_grave{ false };
bool tag_surrender{ false };
bool tag_teammate_surrender{ false };
mt19937 rnd; mt19937 rnd;
ClientField(); ClientField();
~ClientField();
void Clear(); void Clear();
void Initial(int player, int deckc, int extrac); void Initial(int player, int deckc, int extrac);
ClientCard* GetCard(int controler, int location, int sequence, int sub_seq = 0); ClientCard* GetCard(int controler, int location, int sequence, int sub_seq = 0);
void AddCard(ClientCard* pcard, int controler, int location, int sequence); void AddCard(ClientCard* pcard, int controler, int location, int sequence);
ClientCard* RemoveCard(int controler, int location, int sequence); ClientCard* RemoveCard(int controler, int location, int sequence);
void UpdateCard(int controler, int location, int sequence, char* data); void UpdateCard(int controler, int location, int sequence, unsigned char* data);
void UpdateFieldCard(int controler, int location, char* data); void UpdateFieldCard(int controler, int location, unsigned char* data);
void ClearCommandFlag(); void ClearCommandFlag();
void ClearSelect(); void ClearSelect();
void ClearChainSelect(); void ClearChainSelect();
...@@ -122,27 +126,26 @@ public: ...@@ -122,27 +126,26 @@ public:
bool check_sum_trib(std::set<ClientCard*>::const_iterator index, std::set<ClientCard*>::const_iterator end, int acc); bool check_sum_trib(std::set<ClientCard*>::const_iterator index, std::set<ClientCard*>::const_iterator end, int acc);
void UpdateDeclarableList(); void UpdateDeclarableList();
void RefreshCardCountDisplay(); void RefreshCardCountDisplay();
irr::gui::IGUIElement* panel; irr::gui::IGUIElement* panel{ nullptr };
bool is_dragging_cardtext; bool is_dragging_cardtext{ false };
int dragging_cardtext_start_pos; int dragging_cardtext_start_pos{ 0 };
int dragging_cardtext_start_y; int dragging_cardtext_start_y{ 0 };
std::vector<int> ancard; std::vector<int> ancard;
int hovered_controler; int hovered_controler{ 0 };
int hovered_location; int hovered_location{ 0 };
size_t hovered_sequence; size_t hovered_sequence{ 0 };
int command_controler; int command_controler{ 0 };
int command_location; int command_location{ 0 };
size_t command_sequence; size_t command_sequence{ 0 };
ClientCard* hovered_card; ClientCard* hovered_card{ nullptr };
int hovered_player; int hovered_player{ 0 };
ClientCard* clicked_card; ClientCard* clicked_card{ nullptr };
ClientCard* command_card; ClientCard* command_card{ nullptr };
ClientCard* highlighting_card; ClientCard* highlighting_card{ nullptr };
ClientCard* menu_card; ClientCard* menu_card{ nullptr };
int list_command; int list_command{ 0 };
virtual bool OnEvent(const irr::SEvent& event); virtual bool OnEvent(const irr::SEvent& event);
virtual bool OnCommonEvent(const irr::SEvent& event); virtual bool OnCommonEvent(const irr::SEvent& event);
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#define IRR_COMPILE_WITH_DX9_DEV_PACK #define IRR_COMPILE_WITH_DX9_DEV_PACK
#ifdef _WIN32 #ifdef _WIN32
#include <WinSock2.h>
#define NOMINMAX #define NOMINMAX
#include <WinSock2.h>
#include <windows.h> #include <windows.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
...@@ -71,7 +71,6 @@ inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) { ...@@ -71,7 +71,6 @@ inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
#include <iostream> #include <iostream>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <memory.h>
#include <time.h> #include <time.h>
#include <thread> #include <thread>
#include <mutex> #include <mutex>
...@@ -98,7 +97,7 @@ using namespace io; ...@@ -98,7 +97,7 @@ using namespace io;
#endif #endif
extern unsigned short PRO_VERSION; extern unsigned short PRO_VERSION;
extern int enable_log; extern unsigned int enable_log;
extern bool exit_on_return; extern bool exit_on_return;
extern bool auto_watch_mode; extern bool auto_watch_mode;
extern bool open_file; extern bool open_file;
......
...@@ -11,6 +11,13 @@ IFileSystem* DataManager::FileSystem; ...@@ -11,6 +11,13 @@ IFileSystem* DataManager::FileSystem;
#endif #endif
DataManager dataManager; DataManager dataManager;
DataManager::DataManager() : _datas(16384), _strings(16384) {
datas_begin = _datas.begin();
datas_end = _datas.end();
strings_begin = _strings.begin();
strings_end = _strings.end();
extra_setcode = { {8512558u, {0x8f, 0x54, 0x59, 0x82, 0x13a}}, };
}
bool DataManager::LoadDB(const wchar_t* wfile) { bool DataManager::LoadDB(const wchar_t* wfile) {
char file[256]; char file[256];
BufferIO::EncodeUTF8(wfile, file); BufferIO::EncodeUTF8(wfile, file);
...@@ -50,13 +57,13 @@ bool DataManager::LoadDB(const wchar_t* wfile) { ...@@ -50,13 +57,13 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
#else #else
return Error(&db); return Error(&db);
#endif #endif
CardDataC cd;
CardString cs;
#ifndef YGOPRO_SERVER_MODE #ifndef YGOPRO_SERVER_MODE
wchar_t strBuffer[4096]; wchar_t strBuffer[4096];
#endif #endif
int step = 0; int step = 0;
do { do {
CardDataC cd;
CardString cs;
step = sqlite3_step(pStmt); step = sqlite3_step(pStmt);
if(step == SQLITE_BUSY || step == SQLITE_ERROR || step == SQLITE_MISUSE) if(step == SQLITE_BUSY || step == SQLITE_ERROR || step == SQLITE_MISUSE)
#if defined(YGOPRO_SERVER_MODE) && !defined(SERVER_ZIP_SUPPORT) #if defined(YGOPRO_SERVER_MODE) && !defined(SERVER_ZIP_SUPPORT)
...@@ -68,7 +75,19 @@ bool DataManager::LoadDB(const wchar_t* wfile) { ...@@ -68,7 +75,19 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
cd.code = sqlite3_column_int(pStmt, 0); cd.code = sqlite3_column_int(pStmt, 0);
cd.ot = sqlite3_column_int(pStmt, 1); cd.ot = sqlite3_column_int(pStmt, 1);
cd.alias = sqlite3_column_int(pStmt, 2); cd.alias = sqlite3_column_int(pStmt, 2);
cd.setcode = sqlite3_column_int64(pStmt, 3); auto setcode = sqlite3_column_int64(pStmt, 3);
if (setcode) {
auto it = extra_setcode.find(cd.code);
if (it != extra_setcode.end()) {
int len = it->second.size();
if (len > SIZE_SETCODE)
len = SIZE_SETCODE;
if (len)
std::memcpy(cd.setcode, it->second.data(), len * sizeof(uint16_t));
}
else
cd.set_setcode(setcode);
}
cd.type = sqlite3_column_int(pStmt, 4); cd.type = sqlite3_column_int(pStmt, 4);
cd.attack = sqlite3_column_int(pStmt, 5); cd.attack = sqlite3_column_int(pStmt, 5);
cd.defense = sqlite3_column_int(pStmt, 6); cd.defense = sqlite3_column_int(pStmt, 6);
...@@ -111,6 +130,10 @@ bool DataManager::LoadDB(const wchar_t* wfile) { ...@@ -111,6 +130,10 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
spmemvfs_close_db(&db); spmemvfs_close_db(&db);
spmemvfs_env_fini(); spmemvfs_env_fini();
#endif #endif
datas_begin = _datas.begin();
datas_end = _datas.end();
strings_begin = _strings.begin();
strings_end = _strings.end();
return true; return true;
} }
bool DataManager::LoadStrings(const char* file) { bool DataManager::LoadStrings(const char* file) {
...@@ -146,24 +169,30 @@ bool DataManager::LoadStrings(IReadFile* reader) { ...@@ -146,24 +169,30 @@ bool DataManager::LoadStrings(IReadFile* reader) {
void DataManager::ReadStringConfLine(const char* linebuf) { void DataManager::ReadStringConfLine(const char* linebuf) {
if(linebuf[0] != '!') if(linebuf[0] != '!')
return; return;
char strbuf[256]; char strbuf[256]{};
int value; int value{};
wchar_t strBuffer[4096]; wchar_t strBuffer[4096]{};
sscanf(linebuf, "!%s", strbuf); if (sscanf(linebuf, "!%63s", strbuf) != 1)
return;
if(!strcmp(strbuf, "system")) { if(!strcmp(strbuf, "system")) {
sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf); if (sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer); BufferIO::DecodeUTF8(strbuf, strBuffer);
_sysStrings[value] = strBuffer; _sysStrings[value] = strBuffer;
} else if(!strcmp(strbuf, "victory")) { } else if(!strcmp(strbuf, "victory")) {
sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf); if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer); BufferIO::DecodeUTF8(strbuf, strBuffer);
_victoryStrings[value] = strBuffer; _victoryStrings[value] = strBuffer;
} else if(!strcmp(strbuf, "counter")) { } else if(!strcmp(strbuf, "counter")) {
sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf); if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer); BufferIO::DecodeUTF8(strbuf, strBuffer);
_counterStrings[value] = strBuffer; _counterStrings[value] = strBuffer;
} else if(!strcmp(strbuf, "setname")) { } else if(!strcmp(strbuf, "setname")) {
sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf);//using tab for comment //using tab for comment
if (sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer); BufferIO::DecodeUTF8(strbuf, strBuffer);
_setnameStrings[value] = strBuffer; _setnameStrings[value] = strBuffer;
} }
...@@ -188,18 +217,34 @@ bool DataManager::Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt) { ...@@ -188,18 +217,34 @@ bool DataManager::Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt) {
return false; return false;
} }
#endif //YGOPRO_SERVER_MODE #endif //YGOPRO_SERVER_MODE
bool DataManager::GetData(int code, CardData* pData) { bool DataManager::GetData(unsigned int code, CardData* pData) {
auto cdit = _datas.find(code); code_pointer cdit = _datas.find(code);
if(cdit == _datas.end()) if(cdit == _datas.end())
return false; return false;
if(pData) auto& data = cdit->second;
*pData = *((CardData*)&cdit->second); if (pData) {
pData->code = data.code;
pData->alias = data.alias;
std::memcpy(pData->setcode, data.setcode, SIZE_SETCODE);
pData->type = data.type;
pData->level = data.level;
pData->attribute = data.attribute;
pData->race = data.race;
pData->attack = data.attack;
pData->defense = data.defense;
pData->lscale = data.lscale;
pData->rscale = data.rscale;
pData->link_marker = data.link_marker;
}
return true; return true;
} }
code_pointer DataManager::GetCodePointer(int code) { code_pointer DataManager::GetCodePointer(unsigned int code) const {
return _datas.find(code); return _datas.find(code);
} }
bool DataManager::GetString(int code, CardString* pStr) { string_pointer DataManager::GetStringPointer(unsigned int code) const {
return _strings.find(code);
}
bool DataManager::GetString(unsigned int code, CardString* pStr) {
auto csit = _strings.find(code); auto csit = _strings.find(code);
if(csit == _strings.end()) { if(csit == _strings.end()) {
pStr->name = unknown_string; pStr->name = unknown_string;
...@@ -209,7 +254,7 @@ bool DataManager::GetString(int code, CardString* pStr) { ...@@ -209,7 +254,7 @@ bool DataManager::GetString(int code, CardString* pStr) {
*pStr = csit->second; *pStr = csit->second;
return true; return true;
} }
const wchar_t* DataManager::GetName(int code) { const wchar_t* DataManager::GetName(unsigned int code) {
auto csit = _strings.find(code); auto csit = _strings.find(code);
if(csit == _strings.end()) if(csit == _strings.end())
return unknown_string; return unknown_string;
...@@ -217,7 +262,7 @@ const wchar_t* DataManager::GetName(int code) { ...@@ -217,7 +262,7 @@ const wchar_t* DataManager::GetName(int code) {
return csit->second.name.c_str(); return csit->second.name.c_str();
return unknown_string; return unknown_string;
} }
const wchar_t* DataManager::GetText(int code) { const wchar_t* DataManager::GetText(unsigned int code) {
auto csit = _strings.find(code); auto csit = _strings.find(code);
if(csit == _strings.end()) if(csit == _strings.end())
return unknown_string; return unknown_string;
...@@ -226,7 +271,7 @@ const wchar_t* DataManager::GetText(int code) { ...@@ -226,7 +271,7 @@ const wchar_t* DataManager::GetText(int code) {
return unknown_string; return unknown_string;
} }
const wchar_t* DataManager::GetDesc(unsigned int strCode) { const wchar_t* DataManager::GetDesc(unsigned int strCode) {
if(strCode < 10000u) if (strCode < (MIN_CARD_ID << 4))
return GetSysString(strCode); return GetSysString(strCode);
unsigned int code = (strCode >> 4) & 0x0fffffff; unsigned int code = (strCode >> 4) & 0x0fffffff;
unsigned int offset = strCode & 0xf; unsigned int offset = strCode & 0xf;
...@@ -238,7 +283,7 @@ const wchar_t* DataManager::GetDesc(unsigned int strCode) { ...@@ -238,7 +283,7 @@ const wchar_t* DataManager::GetDesc(unsigned int strCode) {
return unknown_string; return unknown_string;
} }
const wchar_t* DataManager::GetSysString(int code) { const wchar_t* DataManager::GetSysString(int code) {
if(code < 0 || code >= 2048) if (code < 0 || code > MAX_STRING_ID)
return unknown_string; return unknown_string;
auto csit = _sysStrings.find(code); auto csit = _sysStrings.find(code);
if(csit == _sysStrings.end()) if(csit == _sysStrings.end())
...@@ -263,17 +308,27 @@ const wchar_t* DataManager::GetSetName(int code) { ...@@ -263,17 +308,27 @@ const wchar_t* DataManager::GetSetName(int code) {
return NULL; return NULL;
return csit->second.c_str(); return csit->second.c_str();
} }
unsigned int DataManager::GetSetCode(const wchar_t* setname) { std::vector<unsigned int> DataManager::GetSetCodes(std::wstring setname) {
std::vector<unsigned int> matchingCodes;
for(auto csit = _setnameStrings.begin(); csit != _setnameStrings.end(); ++csit) { for(auto csit = _setnameStrings.begin(); csit != _setnameStrings.end(); ++csit) {
auto xpos = csit->second.find_first_of(L'|');//setname|another setname or extra info auto xpos = csit->second.find_first_of(L'|');//setname|another setname or extra info
if(csit->second.compare(0, xpos, setname) == 0 || csit->second.compare(xpos + 1, csit->second.length(), setname) == 0
#ifndef YGOPRO_SERVER_MODE #ifndef YGOPRO_SERVER_MODE
|| mainGame->CheckRegEx(csit->second, setname, true) if (mainGame->CheckRegEx(csit->second, setname, true)) {
matchingCodes.push_back(csit->first);
} else
#endif #endif
) if(setname.size() < 2) {
return csit->first; if(csit->second.compare(0, xpos, setname) == 0
|| csit->second.compare(xpos + 1, csit->second.length(), setname) == 0)
matchingCodes.push_back(csit->first);
} else {
if(csit->second.substr(0, xpos).find(setname) != std::wstring::npos
|| csit->second.substr(xpos + 1).find(setname) != std::wstring::npos) {
matchingCodes.push_back(csit->first);
}
}
} }
return 0; return matchingCodes;
} }
const wchar_t* DataManager::GetNumString(int num, bool bracket) { const wchar_t* DataManager::GetNumString(int num, bool bracket) {
if(!bracket) if(!bracket)
...@@ -354,10 +409,12 @@ const wchar_t* DataManager::FormatType(int type) { ...@@ -354,10 +409,12 @@ const wchar_t* DataManager::FormatType(int type) {
return unknown_string; return unknown_string;
return tpBuffer; return tpBuffer;
} }
const wchar_t* DataManager::FormatSetName(unsigned long long setcode) { const wchar_t* DataManager::FormatSetName(const uint16_t setcode[]) {
wchar_t* p = scBuffer; wchar_t* p = scBuffer;
for(int i = 0; i < 4; ++i) { for(int i = 0; i < 10; ++i) {
const wchar_t* setname = GetSetName((setcode >> i * 16) & 0xffff); if (!setcode[i])
break;
const wchar_t* setname = GetSetName(setcode[i]);
if(setname) { if(setname) {
BufferIO::CopyWStrRef(setname, p, 32); BufferIO::CopyWStrRef(setname, p, 32);
*p = L'|'; *p = L'|';
...@@ -391,9 +448,9 @@ const wchar_t* DataManager::FormatLinkMarker(int link_marker) { ...@@ -391,9 +448,9 @@ const wchar_t* DataManager::FormatLinkMarker(int link_marker) {
BufferIO::CopyWStrRef(L"[\u2198]", p, 4); BufferIO::CopyWStrRef(L"[\u2198]", p, 4);
return lmBuffer; return lmBuffer;
} }
int DataManager::CardReader(int code, void* pData) { uint32 DataManager::CardReader(uint32 code, card_data* pData) {
if(!dataManager.GetData(code, (CardData*)pData)) if (!dataManager.GetData(code, pData))
memset(pData, 0, sizeof(CardData)); pData->clear();
return 0; return 0;
} }
byte* DataManager::ScriptReaderEx(const char* script_name, int* slen) { byte* DataManager::ScriptReaderEx(const char* script_name, int* slen) {
...@@ -418,7 +475,7 @@ byte* DataManager::ScriptReaderEx(const char* script_name, int* slen) { ...@@ -418,7 +475,7 @@ byte* DataManager::ScriptReaderEx(const char* script_name, int* slen) {
} }
byte* DataManager::ScriptReaderExSingle(const char* path, const char* script_name, int* slen, int pre_len) { byte* DataManager::ScriptReaderExSingle(const char* path, const char* script_name, int* slen, int pre_len) {
char sname[256]; char sname[256];
sprintf(sname, "%s%s", path, script_name + pre_len); //default script name: ./script/c%d.lua snprintf(sname, sizeof sname, "%s%s", path, script_name + pre_len); //default script name: ./script/c%d.lua
return ScriptReader(sname, slen); return ScriptReader(sname, slen);
} }
byte* DataManager::ScriptReader(const char* script_name, int* slen) { byte* DataManager::ScriptReader(const char* script_name, int* slen) {
...@@ -433,7 +490,7 @@ byte* DataManager::ScriptReader(const char* script_name, int* slen) { ...@@ -433,7 +490,7 @@ byte* DataManager::ScriptReader(const char* script_name, int* slen) {
*slen = len; *slen = len;
#else #else
#ifdef _WIN32 #ifdef _WIN32
wchar_t fname[256]; wchar_t fname[256]{};
BufferIO::DecodeUTF8(script_name, fname); BufferIO::DecodeUTF8(script_name, fname);
IReadFile* reader = FileSystem->createAndOpenFile(fname); IReadFile* reader = FileSystem->createAndOpenFile(fname);
#else #else
......
...@@ -10,10 +10,12 @@ ...@@ -10,10 +10,12 @@
#include <unordered_map> #include <unordered_map>
namespace ygo { namespace ygo {
constexpr int MAX_STRING_ID = 0x7ff;
constexpr unsigned int MIN_CARD_ID = (unsigned int)(MAX_STRING_ID + 1) >> 4;
class DataManager { class DataManager {
public: public:
DataManager(): _datas(8192), _strings(8192) {} DataManager();
bool LoadDB(const wchar_t* wfile); bool LoadDB(const wchar_t* wfile);
bool LoadStrings(const char* file); bool LoadStrings(const char* file);
#ifndef YGOPRO_SERVER_MODE #ifndef YGOPRO_SERVER_MODE
...@@ -25,49 +27,57 @@ public: ...@@ -25,49 +27,57 @@ public:
#else #else
bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = 0); bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = 0);
#endif //YGOPRO_SERVER_MODE #endif //YGOPRO_SERVER_MODE
bool GetData(int code, CardData* pData); bool GetData(unsigned int code, CardData* pData);
code_pointer GetCodePointer(int code); code_pointer GetCodePointer(unsigned int code) const;
bool GetString(int code, CardString* pStr); string_pointer GetStringPointer(unsigned int code) const;
const wchar_t* GetName(int code); bool GetString(unsigned int code, CardString* pStr);
const wchar_t* GetText(int code); const wchar_t* GetName(unsigned int code);
const wchar_t* GetText(unsigned int code);
const wchar_t* GetDesc(unsigned int strCode); const wchar_t* GetDesc(unsigned int strCode);
const wchar_t* GetSysString(int code); const wchar_t* GetSysString(int code);
const wchar_t* GetVictoryString(int code); const wchar_t* GetVictoryString(int code);
const wchar_t* GetCounterName(int code); const wchar_t* GetCounterName(int code);
const wchar_t* GetSetName(int code); const wchar_t* GetSetName(int code);
unsigned int GetSetCode(const wchar_t* setname); std::vector<unsigned int> GetSetCodes(std::wstring setname);
const wchar_t* GetNumString(int num, bool bracket = false); const wchar_t* GetNumString(int num, bool bracket = false);
const wchar_t* FormatLocation(int location, int sequence); const wchar_t* FormatLocation(int location, int sequence);
const wchar_t* FormatAttribute(int attribute); const wchar_t* FormatAttribute(int attribute);
const wchar_t* FormatRace(int race); const wchar_t* FormatRace(int race);
const wchar_t* FormatType(int type); const wchar_t* FormatType(int type);
const wchar_t* FormatSetName(unsigned long long setcode); const wchar_t* FormatSetName(const uint16_t setcode[]);
const wchar_t* FormatLinkMarker(int link_marker); const wchar_t* FormatLinkMarker(int link_marker);
std::unordered_map<unsigned int, CardDataC> _datas;
std::unordered_map<unsigned int, CardString> _strings;
std::unordered_map<unsigned int, std::wstring> _counterStrings; std::unordered_map<unsigned int, std::wstring> _counterStrings;
std::unordered_map<unsigned int, std::wstring> _victoryStrings; std::unordered_map<unsigned int, std::wstring> _victoryStrings;
std::unordered_map<unsigned int, std::wstring> _setnameStrings; std::unordered_map<unsigned int, std::wstring> _setnameStrings;
std::unordered_map<unsigned int, std::wstring> _sysStrings; std::unordered_map<unsigned int, std::wstring> _sysStrings;
code_pointer datas_begin;
code_pointer datas_end;
string_pointer strings_begin;
string_pointer strings_end;
wchar_t numStrings[301][4]; wchar_t numStrings[301][4]{};
wchar_t numBuffer[6]; wchar_t numBuffer[6]{};
wchar_t attBuffer[128]; wchar_t attBuffer[128]{};
wchar_t racBuffer[128]; wchar_t racBuffer[128]{};
wchar_t tpBuffer[128]; wchar_t tpBuffer[128]{};
wchar_t scBuffer[128]; wchar_t scBuffer[128]{};
wchar_t lmBuffer[32]; wchar_t lmBuffer[32]{};
static byte scriptBuffer[0x20000]; static byte scriptBuffer[0x20000];
static const wchar_t* unknown_string; static const wchar_t* unknown_string;
static int CardReader(int, void*); static uint32 CardReader(uint32, card_data*);
static byte* ScriptReaderEx(const char* script_name, int* slen); static byte* ScriptReaderEx(const char* script_name, int* slen);
static byte* ScriptReaderExSingle(const char* path, const char* script_name, int* slen, int pre_len = 2); static byte* ScriptReaderExSingle(const char* path, const char* script_name, int* slen, int pre_len = 2);
static byte* ScriptReader(const char* script_name, int* slen); static byte* ScriptReader(const char* script_name, int* slen);
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT) #if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
static IFileSystem* FileSystem; static IFileSystem* FileSystem;
#endif #endif
private:
std::unordered_map<unsigned int, CardDataC> _datas;
std::unordered_map<unsigned int, CardString> _strings;
std::unordered_map<unsigned int, std::vector<uint16_t>> extra_setcode;
}; };
extern DataManager dataManager; extern DataManager dataManager;
......
...@@ -40,23 +40,6 @@ static int parse_filter(const wchar_t* pstr, unsigned int* type) { ...@@ -40,23 +40,6 @@ static int parse_filter(const wchar_t* pstr, unsigned int* type) {
return 0; return 0;
} }
static bool check_set_code(const CardDataC& data, int set_code) {
unsigned long long sc = data.setcode;
if (data.alias) {
auto aptr = dataManager._datas.find(data.alias);
if (aptr != dataManager._datas.end())
sc = aptr->second.setcode;
}
bool res = false;
int settype = set_code & 0xfff;
int setsubtype = set_code & 0xf000;
while (sc) {
if ((sc & 0xfff) == settype && (sc & 0xf000 & setsubtype) == setsubtype)
res = true;
sc = sc >> 16;
}
return res;
}
static inline bool havePopupWindow() { static inline bool havePopupWindow() {
return mainGame->wQuery->isVisible() || mainGame->wCategories->isVisible() || mainGame->wLinkMarks->isVisible() || mainGame->wDeckManage->isVisible() || mainGame->wDMQuery->isVisible(); return mainGame->wQuery->isVisible() || mainGame->wCategories->isVisible() || mainGame->wLinkMarks->isVisible() || mainGame->wDeckManage->isVisible() || mainGame->wDMQuery->isVisible();
...@@ -79,7 +62,7 @@ void DeckBuilder::Initialize() { ...@@ -79,7 +62,7 @@ void DeckBuilder::Initialize() {
mainGame->btnSideReload->setVisible(false); mainGame->btnSideReload->setVisible(false);
filterList = &deckManager._lfList[mainGame->gameConf.use_lflist ? mainGame->gameConf.default_lflist : deckManager._lfList.size() - 1].content; filterList = &deckManager._lfList[mainGame->gameConf.use_lflist ? mainGame->gameConf.default_lflist : deckManager._lfList.size() - 1].content;
ClearSearch(); ClearSearch();
rnd.reset((unsigned int)time(nullptr)); rnd.reset((uint_fast32_t)time(nullptr));
mouse_pos.set(0, 0); mouse_pos.set(0, 0);
hovered_code = 0; hovered_code = 0;
hovered_pos = 0; hovered_pos = 0;
...@@ -111,6 +94,7 @@ void DeckBuilder::Terminate() { ...@@ -111,6 +94,7 @@ void DeckBuilder::Terminate() {
mainGame->btnBigCardZoomIn->setVisible(false); mainGame->btnBigCardZoomIn->setVisible(false);
mainGame->btnBigCardZoomOut->setVisible(false); mainGame->btnBigCardZoomOut->setVisible(false);
mainGame->btnBigCardClose->setVisible(false); mainGame->btnBigCardClose->setVisible(false);
mainGame->ResizeChatInputWindow();
mainGame->PopupElement(mainGame->wMainMenu); mainGame->PopupElement(mainGame->wMainMenu);
mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->wACMessage->setVisible(false); mainGame->wACMessage->setVisible(false);
...@@ -233,9 +217,9 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -233,9 +217,9 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
mainGame->wDeckCode->setText(dataManager.GetSysString(1387)); mainGame->wDeckCode->setText(dataManager.GetSysString(1387));
if(deckManager.current_deck.main.size() > 0 || deckManager.current_deck.extra.size() > 0 || deckManager.current_deck.side.size() > 0) { if(deckManager.current_deck.main.size() > 0 || deckManager.current_deck.extra.size() > 0 || deckManager.current_deck.side.size() > 0) {
wchar_t deck_code[2048]; wchar_t deck_code[2048];
char deck_code_utf8[1024]; unsigned char deck_code_utf8[1024];
deckManager.SaveDeckToCode(deckManager.current_deck, deck_code_utf8); deckManager.SaveDeckToCode(deckManager.current_deck, deck_code_utf8);
BufferIO::DecodeUTF8(deck_code_utf8, deck_code); BufferIO::DecodeUTF8((char*)deck_code_utf8, deck_code);
mainGame->ebDeckCode->setText(deck_code); mainGame->ebDeckCode->setText(deck_code);
} else } else
mainGame->ebDeckCode->setText(L""); mainGame->ebDeckCode->setText(L"");
...@@ -249,9 +233,11 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -249,9 +233,11 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
mainGame->HideElement(mainGame->wDeckCode); mainGame->HideElement(mainGame->wDeckCode);
if(prev_operation == BUTTON_DECK_CODE) { if(prev_operation == BUTTON_DECK_CODE) {
Deck new_deck; Deck new_deck;
char deck_code[1024]; char pcode[1024];
BufferIO::EncodeUTF8(mainGame->ebDeckCode->getText(), deck_code); BufferIO::EncodeUTF8(mainGame->ebDeckCode->getText(), pcode);
if(deckManager.LoadDeckFromCode(new_deck, deck_code, strlen(deck_code))) unsigned char deck_code[1024];
memcpy(deck_code, pcode, 1024);
if(deckManager.LoadDeckFromCode(new_deck, deck_code, strlen(pcode)))
deckManager.current_deck = new_deck; deckManager.current_deck = new_deck;
else else
mainGame->env->addMessageBox(L"", dataManager.GetSysString(1389)); mainGame->env->addMessageBox(L"", dataManager.GetSysString(1389));
...@@ -693,8 +679,8 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -693,8 +679,8 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break; break;
} }
mainGame->ClearCardInfo(); mainGame->ClearCardInfo();
char deckbuf[1024]; unsigned char deckbuf[1024];
char* pdeck = deckbuf; auto pdeck = deckbuf;
BufferIO::WriteInt32(pdeck, deckManager.current_deck.main.size() + deckManager.current_deck.extra.size()); BufferIO::WriteInt32(pdeck, deckManager.current_deck.main.size() + deckManager.current_deck.extra.size());
BufferIO::WriteInt32(pdeck, deckManager.current_deck.side.size()); BufferIO::WriteInt32(pdeck, deckManager.current_deck.side.size());
for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i) for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i)
...@@ -1071,7 +1057,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -1071,7 +1057,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
dragx = event.MouseInput.X; dragx = event.MouseInput.X;
dragy = event.MouseInput.Y; dragy = event.MouseInput.Y;
draging_pointer = dataManager.GetCodePointer(hovered_code); draging_pointer = dataManager.GetCodePointer(hovered_code);
if(draging_pointer == dataManager._datas.end()) if(draging_pointer == dataManager.datas_end)
break; break;
if(hovered_pos == 4) { if(hovered_pos == 4) {
if(!check_limit(draging_pointer)) if(!check_limit(draging_pointer))
...@@ -1125,7 +1111,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -1125,7 +1111,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if(hovered_pos == 0 || hovered_seq == -1) if(hovered_pos == 0 || hovered_seq == -1)
break; break;
auto pointer = dataManager.GetCodePointer(hovered_code); auto pointer = dataManager.GetCodePointer(hovered_code);
if(pointer == dataManager._datas.end()) if(pointer == dataManager.datas_end)
break; break;
soundManager.PlaySoundEffect(SOUND_CARD_DROP); soundManager.PlaySoundEffect(SOUND_CARD_DROP);
if(hovered_pos == 1) { if(hovered_pos == 1) {
...@@ -1160,7 +1146,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -1160,7 +1146,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
pop_side(hovered_seq); pop_side(hovered_seq);
} else { } else {
auto pointer = dataManager.GetCodePointer(hovered_code); auto pointer = dataManager.GetCodePointer(hovered_code);
if(pointer == dataManager._datas.end()) if(pointer == dataManager.datas_end)
break; break;
if(!check_limit(pointer)) if(!check_limit(pointer))
break; break;
...@@ -1195,6 +1181,8 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -1195,6 +1181,8 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if (is_draging) if (is_draging)
break; break;
auto pointer = dataManager.GetCodePointer(hovered_code); auto pointer = dataManager.GetCodePointer(hovered_code);
if (pointer == dataManager.datas_end)
break;
if(!check_limit(pointer)) if(!check_limit(pointer))
break; break;
soundManager.PlaySoundEffect(SOUND_CARD_PICK); soundManager.PlaySoundEffect(SOUND_CARD_PICK);
...@@ -1304,7 +1292,7 @@ void DeckBuilder::GetHoveredCard() { ...@@ -1304,7 +1292,7 @@ void DeckBuilder::GetHoveredCard() {
} else if(y >= 164 && y <= 435) { } else if(y >= 164 && y <= 435) {
int lx = 10, px, py = (y - 164) / 68; int lx = 10, px, py = (y - 164) / 68;
hovered_pos = 1; hovered_pos = 1;
if(deckManager.current_deck.main.size() > 40) if(deckManager.current_deck.main.size() > DECK_MIN_SIZE)
lx = (deckManager.current_deck.main.size() - 41) / 4 + 11; lx = (deckManager.current_deck.main.size() - 41) / 4 + 11;
if(x >= 750) if(x >= 750)
px = lx - 1; px = lx - 1;
...@@ -1392,14 +1380,14 @@ void DeckBuilder::FilterCards() { ...@@ -1392,14 +1380,14 @@ void DeckBuilder::FilterCards() {
results.clear(); results.clear();
struct element_t { struct element_t {
std::wstring keyword; std::wstring keyword;
int setcode; std::vector<unsigned int> setcodes;
enum class type_t { enum class type_t {
all, all,
name, name,
setcode setcode
} type; } type;
bool exclude; bool exclude;
element_t(): setcode(0), type(type_t::all), exclude(false) {} element_t(): type(type_t::all), exclude(false) {}
}; };
const wchar_t* pstr = mainGame->ebCardName->getText(); const wchar_t* pstr = mainGame->ebCardName->getText();
std::wstring str = std::wstring(pstr); std::wstring str = std::wstring(pstr);
...@@ -1440,7 +1428,7 @@ void DeckBuilder::FilterCards() { ...@@ -1440,7 +1428,7 @@ void DeckBuilder::FilterCards() {
element.keyword = str.substr(element_start, length); element.keyword = str.substr(element_start, length);
} else } else
element.keyword = str.substr(element_start); element.keyword = str.substr(element_start);
element.setcode = dataManager.GetSetCode(element.keyword.c_str()); element.setcodes = dataManager.GetSetCodes(element.keyword);
query_elements.push_back(element); query_elements.push_back(element);
if(element_end == std::wstring::npos) if(element_end == std::wstring::npos)
break; break;
...@@ -1458,13 +1446,15 @@ void DeckBuilder::FilterCards() { ...@@ -1458,13 +1446,15 @@ void DeckBuilder::FilterCards() {
} }
if(element_start < str.size()) { if(element_start < str.size()) {
element.keyword = str.substr(element_start); element.keyword = str.substr(element_start);
element.setcode = dataManager.GetSetCode(element.keyword.c_str()); element.setcodes = dataManager.GetSetCodes(element.keyword);
query_elements.push_back(element); query_elements.push_back(element);
} }
} }
auto strpointer = dataManager._strings.begin(); for(code_pointer ptr = dataManager.datas_begin; ptr != dataManager.datas_end; ++ptr) {
for(code_pointer ptr = dataManager._datas.begin(); ptr != dataManager._datas.end(); ++ptr, ++strpointer) {
const CardDataC& data = ptr->second; const CardDataC& data = ptr->second;
auto strpointer = dataManager.GetStringPointer(ptr->first);
if (strpointer == dataManager.strings_end)
continue;
const CardString& text = strpointer->second; const CardString& text = strpointer->second;
if(data.type & TYPE_TOKEN) if(data.type & TYPE_TOKEN)
continue; continue;
...@@ -1543,7 +1533,7 @@ void DeckBuilder::FilterCards() { ...@@ -1543,7 +1533,7 @@ void DeckBuilder::FilterCards() {
if (elements_iterator->type == element_t::type_t::name) { if (elements_iterator->type == element_t::type_t::name) {
match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str()); match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str());
} else if (elements_iterator->type == element_t::type_t::setcode) { } else if (elements_iterator->type == element_t::type_t::setcode) {
match = elements_iterator->setcode && check_set_code(data, elements_iterator->setcode); match = data.is_setcodes(elements_iterator->setcodes);
} else { } else {
int trycode = BufferIO::GetVal(elements_iterator->keyword.c_str()); int trycode = BufferIO::GetVal(elements_iterator->keyword.c_str());
bool tryresult = dataManager.GetData(trycode, 0); bool tryresult = dataManager.GetData(trycode, 0);
...@@ -1551,7 +1541,7 @@ void DeckBuilder::FilterCards() { ...@@ -1551,7 +1541,7 @@ void DeckBuilder::FilterCards() {
match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str()) match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str())
|| text.text.find(elements_iterator->keyword) != std::wstring::npos || text.text.find(elements_iterator->keyword) != std::wstring::npos
|| mainGame->CheckRegEx(text.text, elements_iterator->keyword) || mainGame->CheckRegEx(text.text, elements_iterator->keyword)
|| (elements_iterator->setcode && check_set_code(data, elements_iterator->setcode)); || data.is_setcodes(elements_iterator->setcodes);
} else { } else {
match = data.code == trycode || data.alias == trycode; match = data.code == trycode || data.alias == trycode;
} }
...@@ -1813,7 +1803,7 @@ bool DeckBuilder::push_main(code_pointer pointer, int seq) { ...@@ -1813,7 +1803,7 @@ bool DeckBuilder::push_main(code_pointer pointer, int seq) {
if(pointer->second.type & (TYPE_FUSION | TYPE_SYNCHRO | TYPE_XYZ | TYPE_LINK)) if(pointer->second.type & (TYPE_FUSION | TYPE_SYNCHRO | TYPE_XYZ | TYPE_LINK))
return false; return false;
auto& container = deckManager.current_deck.main; auto& container = deckManager.current_deck.main;
int maxc = mainGame->is_siding ? YGOPRO_MAX_DECK + 5 : YGOPRO_MAX_DECK; int maxc = mainGame->is_siding ? DECK_MAX_SIZE + 4 : DECK_MAX_SIZE;
if((int)container.size() >= maxc) if((int)container.size() >= maxc)
return false; return false;
if(seq >= 0 && seq < (int)container.size()) if(seq >= 0 && seq < (int)container.size())
...@@ -1828,7 +1818,7 @@ bool DeckBuilder::push_extra(code_pointer pointer, int seq) { ...@@ -1828,7 +1818,7 @@ bool DeckBuilder::push_extra(code_pointer pointer, int seq) {
if(!(pointer->second.type & (TYPE_FUSION | TYPE_SYNCHRO | TYPE_XYZ | TYPE_LINK))) if(!(pointer->second.type & (TYPE_FUSION | TYPE_SYNCHRO | TYPE_XYZ | TYPE_LINK)))
return false; return false;
auto& container = deckManager.current_deck.extra; auto& container = deckManager.current_deck.extra;
int maxc = mainGame->is_siding ? YGOPRO_MAX_EXTRA + 5 : YGOPRO_MAX_EXTRA; int maxc = mainGame->is_siding ? EXTRA_MAX_SIZE + 5 : EXTRA_MAX_SIZE;
if((int)container.size() >= maxc) if((int)container.size() >= maxc)
return false; return false;
if(seq >= 0 && seq < (int)container.size()) if(seq >= 0 && seq < (int)container.size())
...@@ -1841,7 +1831,7 @@ bool DeckBuilder::push_extra(code_pointer pointer, int seq) { ...@@ -1841,7 +1831,7 @@ bool DeckBuilder::push_extra(code_pointer pointer, int seq) {
} }
bool DeckBuilder::push_side(code_pointer pointer, int seq) { bool DeckBuilder::push_side(code_pointer pointer, int seq) {
auto& container = deckManager.current_deck.side; auto& container = deckManager.current_deck.side;
int maxc = mainGame->is_siding ? YGOPRO_MAX_SIDE + 5 : YGOPRO_MAX_SIDE; int maxc = mainGame->is_siding ? SIDE_MAX_SIZE + 5 : SIDE_MAX_SIZE;
if((int)container.size() >= maxc) if((int)container.size() >= maxc)
return false; return false;
if(seq >= 0 && seq < (int)container.size()) if(seq >= 0 && seq < (int)container.size())
......
...@@ -41,49 +41,49 @@ public: ...@@ -41,49 +41,49 @@ public:
void pop_side(int seq); void pop_side(int seq);
bool check_limit(code_pointer pointer); bool check_limit(code_pointer pointer);
long long filter_effect; long long filter_effect{};
unsigned int filter_type; unsigned int filter_type{};
unsigned int filter_type2; unsigned int filter_type2{};
unsigned int filter_attrib; unsigned int filter_attrib{};
unsigned int filter_race; unsigned int filter_race{};
unsigned int filter_atktype; unsigned int filter_atktype{};
int filter_atk; int filter_atk{};
unsigned int filter_deftype; unsigned int filter_deftype{};
int filter_def; int filter_def{};
unsigned int filter_lvtype; unsigned int filter_lvtype{};
unsigned int filter_lv; unsigned int filter_lv{};
unsigned int filter_scltype; unsigned int filter_scltype{};
unsigned int filter_scl; unsigned int filter_scl{};
unsigned int filter_marks; unsigned int filter_marks{};
int filter_lm; int filter_lm{};
position2di mouse_pos; position2di mouse_pos;
int hovered_code; int hovered_code{};
int hovered_pos; int hovered_pos{};
int hovered_seq; int hovered_seq{ -1 };
int is_lastcard; int is_lastcard{};
int click_pos; int click_pos{};
bool is_draging; bool is_draging{};
bool is_starting_dragging; bool is_starting_dragging{};
int dragx; int dragx{};
int dragy; int dragy{};
int bigcard_code; int bigcard_code{};
float bigcard_zoom; float bigcard_zoom{};
size_t pre_mainc; size_t pre_mainc{};
size_t pre_extrac; size_t pre_extrac{};
size_t pre_sidec; size_t pre_sidec{};
code_pointer draging_pointer; code_pointer draging_pointer;
int prev_category; int prev_category{};
int prev_deck; int prev_deck{};
s32 prev_operation; s32 prev_operation{};
int prev_sel; int prev_sel{ -1 };
bool is_modified; bool is_modified{};
bool readonly; bool readonly{};
bool showing_pack; bool showing_pack{};
mt19937 rnd; mt19937 rnd;
const std::unordered_map<int, int>* filterList; const std::unordered_map<int, int>* filterList;
std::vector<code_pointer> results; std::vector<code_pointer> results;
wchar_t result_string[8]; wchar_t result_string[8]{};
std::vector<std::wstring> expansionPacks; std::vector<std::wstring> expansionPacks;
}; };
......
...@@ -7,22 +7,23 @@ ...@@ -7,22 +7,23 @@
namespace ygo { namespace ygo {
#ifndef YGOPRO_SERVER_MODE #ifndef YGOPRO_SERVER_MODE
char DeckManager::deckBuffer[0x10000]; char DeckManager::deckBuffer[0x10000]{};
#endif #endif
DeckManager deckManager; DeckManager deckManager;
void DeckManager::LoadLFListSingle(const char* path) { void DeckManager::LoadLFListSingle(const char* path) {
LFList* cur = nullptr; LFList* cur = nullptr;
FILE* fp = fopen(path, "r"); FILE* fp = fopen(path, "r");
char linebuf[256]; char linebuf[256]{};
wchar_t strBuffer[256]; wchar_t strBuffer[256]{};
if(fp) { if(fp) {
while(fgets(linebuf, 256, fp)) { while(fgets(linebuf, 256, fp)) {
if(linebuf[0] == '#') if(linebuf[0] == '#')
continue; continue;
if(linebuf[0] == '!') { if(linebuf[0] == '!') {
int sa = BufferIO::DecodeUTF8(&linebuf[1], strBuffer); int sa = BufferIO::DecodeUTF8(&linebuf[1], strBuffer);
while(strBuffer[sa - 1] == L'\r' || strBuffer[sa - 1] == L'\n' ) sa--; while(strBuffer[sa - 1] == L'\r' || strBuffer[sa - 1] == L'\n' )
sa--;
strBuffer[sa] = 0; strBuffer[sa] = 0;
LFList newlist; LFList newlist;
_lfList.push_back(newlist); _lfList.push_back(newlist);
...@@ -31,20 +32,18 @@ void DeckManager::LoadLFListSingle(const char* path) { ...@@ -31,20 +32,18 @@ void DeckManager::LoadLFListSingle(const char* path) {
cur->hash = 0x7dfcee6a; cur->hash = 0x7dfcee6a;
continue; continue;
} }
int p = 0; if(linebuf[0] == 0)
while(linebuf[p] != ' ' && linebuf[p] != '\t' && linebuf[p] != 0) p++;
if(linebuf[p] == 0)
continue; continue;
linebuf[p++] = 0; int code = 0;
int sa = p; int count = -1;
int code = atoi(linebuf); if (sscanf(linebuf, "%d %d", &code, &count) != 2)
if(code == 0) continue;
if (code <= 0 || code > 0xfffffff)
continue;
if (count < 0 || count > 2)
continue;
if (!cur)
continue; continue;
while(linebuf[p] == ' ' || linebuf[p] == '\t') p++;
while(linebuf[p] != ' ' && linebuf[p] != '\t' && linebuf[p] != 0) p++;
linebuf[p] = 0;
int count = atoi(&linebuf[sa]);
if(!cur) continue;
cur->content[code] = count; cur->content[code] = count;
cur->hash = cur->hash ^ ((code << 18) | (code >> 14)) ^ ((code << (27 + count)) | (code >> (5 - count))); cur->hash = cur->hash ^ ((code << 18) | (code >> 14)) ^ ((code << (27 + count)) | (code >> (5 - count)));
} }
...@@ -95,11 +94,11 @@ int DeckManager::CheckDeck(Deck& deck, int lfhash, int rule) { ...@@ -95,11 +94,11 @@ int DeckManager::CheckDeck(Deck& deck, int lfhash, int rule) {
if(!list) if(!list)
return 0; return 0;
int dc = 0; int dc = 0;
if(deck.main.size() < YGOPRO_MIN_DECK || deck.main.size() > YGOPRO_MAX_DECK) if(deck.main.size() < DECK_MIN_SIZE || deck.main.size() > DECK_MAX_SIZE)
return (DECKERROR_MAINCOUNT << 28) + deck.main.size(); return (DECKERROR_MAINCOUNT << 28) + deck.main.size();
if(deck.extra.size() > YGOPRO_MAX_EXTRA) if(deck.extra.size() > EXTRA_MAX_SIZE)
return (DECKERROR_EXTRACOUNT << 28) + deck.extra.size(); return (DECKERROR_EXTRACOUNT << 28) + deck.extra.size();
if(deck.side.size() > YGOPRO_MAX_SIDE) if(deck.side.size() > SIDE_MAX_SIZE)
return (DECKERROR_SIDECOUNT << 28) + deck.side.size(); return (DECKERROR_SIDECOUNT << 28) + deck.side.size();
const int rule_map[6] = { AVAIL_OCG, AVAIL_TCG, AVAIL_SC, AVAIL_CUSTOM, AVAIL_OCGTCG, 0 }; const int rule_map[6] = { AVAIL_OCG, AVAIL_TCG, AVAIL_SC, AVAIL_CUSTOM, AVAIL_OCGTCG, 0 };
int avail = rule_map[rule]; int avail = rule_map[rule];
...@@ -167,10 +166,10 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_p ...@@ -167,10 +166,10 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_p
continue; continue;
} }
else if(cd.type & (TYPE_FUSION | TYPE_SYNCHRO | TYPE_XYZ | TYPE_LINK)) { else if(cd.type & (TYPE_FUSION | TYPE_SYNCHRO | TYPE_XYZ | TYPE_LINK)) {
if(deck.extra.size() >= YGOPRO_MAX_EXTRA) if(deck.extra.size() >= EXTRA_MAX_SIZE)
continue; continue;
deck.extra.push_back(dataManager.GetCodePointer(code)); //verified by GetData() deck.extra.push_back(dataManager.GetCodePointer(code));
} else if(deck.main.size() < YGOPRO_MAX_DECK) { } else if(deck.main.size() < DECK_MAX_SIZE) {
deck.main.push_back(dataManager.GetCodePointer(code)); deck.main.push_back(dataManager.GetCodePointer(code));
} }
} }
...@@ -183,7 +182,7 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_p ...@@ -183,7 +182,7 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_p
if(cd.type & TYPE_TOKEN) if(cd.type & TYPE_TOKEN)
continue; continue;
if(deck.side.size() < YGOPRO_MAX_SIDE) if(deck.side.size() < YGOPRO_MAX_SIDE)
deck.side.push_back(dataManager.GetCodePointer(code)); //verified by GetData() deck.side.push_back(dataManager.GetCodePointer(code));
} }
return errorcode; return errorcode;
} }
...@@ -241,7 +240,7 @@ void DeckManager::GetCategoryPath(wchar_t* ret, int index, const wchar_t* text) ...@@ -241,7 +240,7 @@ void DeckManager::GetCategoryPath(wchar_t* ret, int index, const wchar_t* text)
void DeckManager::GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck) { void DeckManager::GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck) {
wchar_t filepath[256]; wchar_t filepath[256];
wchar_t catepath[256]; wchar_t catepath[256];
wchar_t* deckname = (wchar_t*)cbDeck->getItem(cbDeck->getSelected()); const wchar_t* deckname = cbDeck->getItem(cbDeck->getSelected());
if(deckname != NULL) { if(deckname != NULL) {
GetCategoryPath(catepath, cbCategory->getSelected(), cbCategory->getText()); GetCategoryPath(catepath, cbCategory->getSelected(), cbCategory->getText());
myswprintf(filepath, L"%ls/%ls.ydk", catepath, deckname); myswprintf(filepath, L"%ls/%ls.ydk", catepath, deckname);
...@@ -262,7 +261,9 @@ bool DeckManager::LoadDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUICom ...@@ -262,7 +261,9 @@ bool DeckManager::LoadDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUICom
} }
FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) { FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
#ifdef WIN32 #ifdef WIN32
FILE* fp = _wfopen(file, (wchar_t*)mode); wchar_t wmode[20]{};
BufferIO::CopyWStr(mode, wmode, sizeof(wmode) / sizeof(wchar_t));
FILE* fp = _wfopen(file, wmode);
#else #else
char file2[256]; char file2[256];
BufferIO::EncodeUTF8(file, file2); BufferIO::EncodeUTF8(file, file2);
...@@ -366,8 +367,8 @@ int DeckManager::TypeCount(std::vector<code_pointer> list, unsigned int ctype) { ...@@ -366,8 +367,8 @@ int DeckManager::TypeCount(std::vector<code_pointer> list, unsigned int ctype) {
} }
return res; return res;
} }
bool DeckManager::LoadDeckFromCode(Deck& deck, const char *code, int len) { bool DeckManager::LoadDeckFromCode(Deck& deck, const unsigned char *code, int len) {
char data[1024], *pdeck = data, *data_ = data; unsigned char data[1024], *pdeck = data, *data_ = data;
int decoded_len = Base64::DecodedLength(code, len); int decoded_len = Base64::DecodedLength(code, len);
if(decoded_len > 1024 || decoded_len < 8 || !Base64::Decode(code, len, data_, decoded_len)) if(decoded_len > 1024 || decoded_len < 8 || !Base64::Decode(code, len, data_, decoded_len))
return false; return false;
...@@ -376,8 +377,8 @@ bool DeckManager::LoadDeckFromCode(Deck& deck, const char *code, int len) { ...@@ -376,8 +377,8 @@ bool DeckManager::LoadDeckFromCode(Deck& deck, const char *code, int len) {
int errorcode = LoadDeck(deck, (int*)pdeck, mainc, sidec); int errorcode = LoadDeck(deck, (int*)pdeck, mainc, sidec);
return (errorcode == 0); return (errorcode == 0);
} }
int DeckManager::SaveDeckToCode(Deck& deck, char* code) { int DeckManager::SaveDeckToCode(Deck& deck, unsigned char* code) {
char deckbuf[1024], *pdeck = deckbuf; unsigned char deckbuf[1024], *pdeck = deckbuf;
BufferIO::WriteInt32(pdeck, deck.main.size() + deck.extra.size()); BufferIO::WriteInt32(pdeck, deck.main.size() + deck.extra.size());
BufferIO::WriteInt32(pdeck, deck.side.size()); BufferIO::WriteInt32(pdeck, deck.side.size());
for(size_t i = 0; i < deck.main.size(); ++i) for(size_t i = 0; i < deck.main.size(); ++i)
......
...@@ -9,10 +9,30 @@ ...@@ -9,10 +9,30 @@
#include <sstream> #include <sstream>
#endif #endif
#ifndef YGOPRO_MAX_DECK
#define YGOPRO_MAX_DECK 60
#endif
#ifndef YGOPRO_MIN_DECK
#define YGOPRO_MIN_DECK 40
#endif
#ifndef YGOPRO_MAX_EXTRA
#define YGOPRO_MAX_EXTRA 15
#endif
#ifndef YGOPRO_MAX_SIDE
#define YGOPRO_MAX_SIDE 15
#endif
namespace ygo { namespace ygo {
constexpr int DECK_MAX_SIZE = YGOPRO_MAX_DECK;
constexpr int DECK_MIN_SIZE = YGOPRO_MIN_DECK;
constexpr int EXTRA_MAX_SIZE = YGOPRO_MAX_EXTRA;
constexpr int SIDE_MAX_SIZE = YGOPRO_MAX_SIDE;
struct LFList { struct LFList {
unsigned int hash; unsigned int hash{};
std::wstring listName; std::wstring listName;
std::unordered_map<int, int> content; std::unordered_map<int, int> content;
}; };
...@@ -61,8 +81,8 @@ public: ...@@ -61,8 +81,8 @@ public:
bool DeleteDeck(const wchar_t* file); bool DeleteDeck(const wchar_t* file);
wchar_t DeckFormatBuffer[128]; wchar_t DeckFormatBuffer[128];
int TypeCount(std::vector<code_pointer> list, unsigned int ctype); int TypeCount(std::vector<code_pointer> list, unsigned int ctype);
bool LoadDeckFromCode(Deck& deck, const char *code, int len); bool LoadDeckFromCode(Deck& deck, const unsigned char *code, int len);
int SaveDeckToCode(Deck &deck, char *code); int SaveDeckToCode(Deck &deck, unsigned char *code);
bool CreateCategory(const wchar_t* name); bool CreateCategory(const wchar_t* name);
bool RenameCategory(const wchar_t* oldname, const wchar_t* newname); bool RenameCategory(const wchar_t* oldname, const wchar_t* newname);
bool DeleteCategory(const wchar_t* name); bool DeleteCategory(const wchar_t* name);
......
...@@ -18,10 +18,10 @@ void Game::DrawSelectionLine(irr::video::S3DVertex* vec, bool strip, int width, ...@@ -18,10 +18,10 @@ void Game::DrawSelectionLine(irr::video::S3DVertex* vec, bool strip, int width,
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glMaterialfv(GL_FRONT, GL_AMBIENT, cv); glMaterialfv(GL_FRONT, GL_AMBIENT, cv);
glBegin(GL_LINE_LOOP); glBegin(GL_LINE_LOOP);
glVertex3fv((float*)&vec[0].Pos); glVertex3fv(&vec[0].Pos.X);
glVertex3fv((float*)&vec[1].Pos); glVertex3fv(&vec[1].Pos.X);
glVertex3fv((float*)&vec[3].Pos); glVertex3fv(&vec[3].Pos.X);
glVertex3fv((float*)&vec[2].Pos); glVertex3fv(&vec[2].Pos.X);
glEnd(); glEnd();
glMaterialfv(GL_FRONT, GL_AMBIENT, origin); glMaterialfv(GL_FRONT, GL_AMBIENT, origin);
glDisable(GL_LINE_STIPPLE); glDisable(GL_LINE_STIPPLE);
...@@ -341,8 +341,21 @@ void Game::DrawCards() { ...@@ -341,8 +341,21 @@ void Game::DrawCards() {
for(auto it = dField.extra[p].begin(); it != dField.extra[p].end(); ++it) for(auto it = dField.extra[p].begin(); it != dField.extra[p].end(); ++it)
DrawCard(*it); DrawCard(*it);
} }
for(auto cit = dField.overlay_cards.begin(); cit != dField.overlay_cards.end(); ++cit) for (auto cit = dField.overlay_cards.begin(); cit != dField.overlay_cards.end(); ++cit) {
DrawCard(*cit); auto pcard = (*cit);
auto olcard = pcard->overlayTarget;
if (pcard->aniFrame) {
DrawCard(pcard);
}
else if (olcard && olcard->location == LOCATION_MZONE) {
if (pcard->sequence < MAX_LAYER_COUNT) {
DrawCard(pcard);
}
}
else {
DrawCard(pcard);
}
}
} }
void Game::DrawCard(ClientCard* pcard) { void Game::DrawCard(ClientCard* pcard) {
if(pcard->aniFrame) { if(pcard->aniFrame) {
...@@ -546,6 +559,8 @@ void Game::DrawMisc() { ...@@ -546,6 +559,8 @@ void Game::DrawMisc() {
//finish button //finish button
if(btnCancelOrFinish->isVisible() && dField.select_ready) if(btnCancelOrFinish->isVisible() && dField.select_ready)
DrawSelectionLine(btnCancelOrFinish, 2, 0xffffff00); DrawSelectionLine(btnCancelOrFinish, 2, 0xffffff00);
if(btnLeaveGame->isVisible() && dField.tag_teammate_surrender)
DrawSelectionLine(btnLeaveGame, 2, 0xffffff00);
//lp bar //lp bar
if((dInfo.turn % 2 && dInfo.isFirst && !dInfo.is_swapped) || (!(dInfo.turn % 2) && !dInfo.isFirst && !dInfo.is_swapped) || (!(dInfo.turn % 2) && dInfo.isFirst && dInfo.is_swapped) || (dInfo.turn % 2 && !dInfo.isFirst && dInfo.is_swapped)) { if((dInfo.turn % 2 && dInfo.isFirst && !dInfo.is_swapped) || (!(dInfo.turn % 2) && !dInfo.isFirst && !dInfo.is_swapped) || (!(dInfo.turn % 2) && dInfo.isFirst && dInfo.is_swapped) || (dInfo.turn % 2 && !dInfo.isFirst && dInfo.is_swapped)) {
driver->draw2DRectangle(0xa0000000, Resize(327, 8, 630, 51)); driver->draw2DRectangle(0xa0000000, Resize(327, 8, 630, 51));
...@@ -1052,26 +1067,40 @@ void Game::DrawSpec() { ...@@ -1052,26 +1067,40 @@ void Game::DrawSpec() {
showChat = false; showChat = false;
hideChatTimer--; hideChatTimer--;
} }
int chatRectY = 0;
for(int i = 0; i < 8; ++i) { for(int i = 0; i < 8; ++i) {
static unsigned int chatColor[] = {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xff8080ff, 0xffff4040, 0xffff4040, static unsigned int chatColor[] = {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xff8080ff, 0xffff4040, 0xffff4040,
0xffff4040, 0xff40ff40, 0xff4040ff, 0xff40ffff, 0xffff40ff, 0xffffff40, 0xffffffff, 0xff808080, 0xff404040}; 0xffff4040, 0xff40ff40, 0xff4040ff, 0xff40ffff, 0xffff40ff, 0xffffff40, 0xffffffff, 0xff808080, 0xff404040};
if(chatTiming[i]) { if(chatTiming[i]) {
chatTiming[i]--; chatTiming[i]--;
if(mainGame->dInfo.isStarted && i >= 5) if(!is_building) {
continue; if(dInfo.isStarted && i >= 5)
if(!showChat && i > 2) continue;
continue; if(!showChat && i > 2)
int w = guiFont->getDimension(chatMsg[i].c_str()).Width; continue;
}
recti rectloc(mainGame->wChat->getRelativePosition().UpperLeftCorner.X, mainGame->window_size.Height - 45, mainGame->wChat->getRelativePosition().UpperLeftCorner.X + 2 + w, mainGame->window_size.Height - 25); int x = wChat->getRelativePosition().UpperLeftCorner.X;
rectloc -= position2di(0, i * 20); int y = window_size.Height - 25;
recti msgloc(mainGame->wChat->getRelativePosition().UpperLeftCorner.X, mainGame->window_size.Height - 45, mainGame->wChat->getRelativePosition().UpperLeftCorner.X - 4, mainGame->window_size.Height - 25); int maxwidth = 705 * xScale;
msgloc -= position2di(0, i * 20); if(is_building) {
x = 810 * xScale;
maxwidth = 205 * xScale;
}
std::wstring msg = SetStaticText(nullptr, maxwidth, guiFont, chatMsg[i].c_str());
int w = guiFont->getDimension(msg).Width;
int h = guiFont->getDimension(msg).Height + 2;
recti rectloc(x, y - chatRectY - h, x + 2 + w, y - chatRectY);
recti msgloc(x, y - chatRectY - h, x - 4, y - chatRectY);
recti shadowloc = msgloc + position2di(1, 1); recti shadowloc = msgloc + position2di(1, 1);
driver->draw2DRectangle(rectloc, 0xa0000000, 0xa0000000, 0xa0000000, 0xa0000000); driver->draw2DRectangle(rectloc, 0xa0000000, 0xa0000000, 0xa0000000, 0xa0000000);
guiFont->draw(chatMsg[i].c_str(), msgloc, 0xff000000, false, false); guiFont->draw(msg.c_str(), msgloc, 0xff000000, false, false);
guiFont->draw(chatMsg[i].c_str(), shadowloc, chatColor[chatType[i]], false, false); guiFont->draw(msg.c_str(), shadowloc, chatColor[chatType[i]], false, false);
chatRectY += h;
} }
} }
} }
...@@ -1261,10 +1290,10 @@ void Game::DrawDeckBd() { ...@@ -1261,10 +1290,10 @@ void Game::DrawDeckBd() {
dx = 436.0f / (lx - 1); dx = 436.0f / (lx - 1);
} }
int padding = scrPackCards->getPos() * lx; int padding = scrPackCards->getPos() * lx;
for(size_t i = 0; i < mainsize - padding && i < 7 * lx; ++i) { for(int i = 0; i < mainsize - padding && i < 7 * lx; ++i) {
size_t j = i + padding; int j = i + padding;
DrawThumb(deckManager.current_deck.main[j], position2di(314 + (i % lx) * dx, 164 + (i / lx) * dy), deckBuilder.filterList); DrawThumb(deckManager.current_deck.main[j], position2di(314 + (i % lx) * dx, 164 + (i / lx) * dy), deckBuilder.filterList);
if(deckBuilder.hovered_pos == 1 && deckBuilder.hovered_seq == (int)j) if(deckBuilder.hovered_pos == 1 && deckBuilder.hovered_seq == j)
driver->draw2DRectangleOutline(Resize(313 + (i % lx) * dx, 163 + (i / lx) * dy, 359 + (i % lx) * dx, 228 + (i / lx) * dy)); driver->draw2DRectangleOutline(Resize(313 + (i % lx) * dx, 163 + (i / lx) * dy, 359 + (i % lx) * dx, 228 + (i / lx) * dy));
} }
if(!deckBuilder.showing_pack) { if(!deckBuilder.showing_pack) {
...@@ -1353,13 +1382,19 @@ void Game::DrawDeckBd() { ...@@ -1353,13 +1382,19 @@ void Game::DrawDeckBd() {
driver->draw2DRectangleOutline(Resize(313 + i * dx, 563, 359 + i * dx, 629)); driver->draw2DRectangleOutline(Resize(313 + i * dx, 563, 359 + i * dx, 629));
} }
} }
//search result if(is_siding) {
driver->draw2DRectangle(Resize(805, 137, 926, 157), 0x400000ff, 0x400000ff, 0x40000000, 0x40000000); // side chat background
driver->draw2DRectangleOutline(Resize(804, 136, 926, 157)); driver->draw2DRectangle(Resize(805, 10, 1020, 630), 0x400000ff, 0x400000ff, 0x40000000, 0x40000000);
DrawShadowText(textFont, dataManager.GetSysString(1333), Resize(810, 137, 915, 157), Resize(1, 1, 1, 1), 0xffffffff, 0xff000000, false, true); driver->draw2DRectangleOutline(Resize(804, 9, 1020, 630));
DrawShadowText(numFont, deckBuilder.result_string, Resize(875, 137, 935, 157), Resize(1, 1, 1, 1), 0xffffffff, 0xff000000, false, true); } else {
driver->draw2DRectangle(Resize(805, 160, 1020, 630), 0x400000ff, 0x400000ff, 0x40000000, 0x40000000); //search result
driver->draw2DRectangleOutline(Resize(804, 159, 1020, 630)); driver->draw2DRectangle(Resize(805, 137, 926, 157), 0x400000ff, 0x400000ff, 0x40000000, 0x40000000);
driver->draw2DRectangleOutline(Resize(804, 136, 926, 157));
DrawShadowText(textFont, dataManager.GetSysString(1333), Resize(810, 137, 915, 157), Resize(1, 1, 1, 1), 0xffffffff, 0xff000000, false, true);
DrawShadowText(numFont, deckBuilder.result_string, Resize(875, 137, 935, 157), Resize(1, 1, 1, 1), 0xffffffff, 0xff000000, false, true);
driver->draw2DRectangle(Resize(805, 160, 1020, 630), 0x400000ff, 0x400000ff, 0x40000000, 0x40000000);
driver->draw2DRectangleOutline(Resize(804, 159, 1020, 630));
}
for(size_t i = 0; i < 9 && i + scrFilter->getPos() < deckBuilder.results.size(); ++i) { for(size_t i = 0; i < 9 && i + scrFilter->getPos() < deckBuilder.results.size(); ++i) {
code_pointer ptr = deckBuilder.results[i + scrFilter->getPos()]; code_pointer ptr = deckBuilder.results[i + scrFilter->getPos()];
if(i >= 7) if(i >= 7)
......
This diff is collapsed.
...@@ -5,11 +5,6 @@ ...@@ -5,11 +5,6 @@
#include <vector> #include <vector>
#include <set> #include <set>
#include <utility> #include <utility>
#include <event2/event.h>
#include <event2/listener.h>
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#include <event2/thread.h>
#include "network.h" #include "network.h"
#include "data_manager.h" #include "data_manager.h"
#include "deck_manager.h" #include "deck_manager.h"
...@@ -59,21 +54,21 @@ public: ...@@ -59,21 +54,21 @@ public:
class DuelClient { class DuelClient {
private: private:
static unsigned int connect_state; static unsigned int connect_state;
static unsigned char response_buf[64]; static unsigned char response_buf[SIZE_RETURN_VALUE];
static unsigned char response_len; static unsigned int response_len;
static unsigned int watching; static unsigned int watching;
static unsigned char selftype;
static bool is_host; static bool is_host;
static event_base* client_base; static event_base* client_base;
static bufferevent* client_bev; static bufferevent* client_bev;
static char duel_client_read[0x2000]; static unsigned char duel_client_read[SIZE_NETWORK_BUFFER];
static char duel_client_write[0x2000]; static int read_len;
static unsigned char duel_client_write[SIZE_NETWORK_BUFFER];
static bool is_closing; static bool is_closing;
static bool is_swapping; static bool is_swapping;
static int select_hint; static int select_hint;
static int select_unselect_hint; static int select_unselect_hint;
static int last_select_hint; static int last_select_hint;
static char last_successful_msg[0x2000]; static unsigned char last_successful_msg[0x2000];
static unsigned int last_successful_msg_length; static unsigned int last_successful_msg_length;
static wchar_t event_string[256]; static wchar_t event_string[256];
static mt19937 rnd; static mt19937 rnd;
...@@ -82,25 +77,25 @@ public: ...@@ -82,25 +77,25 @@ public:
static unsigned short temp_port; static unsigned short temp_port;
static unsigned short temp_ver; static unsigned short temp_ver;
static bool try_needed; static bool try_needed;
static unsigned char selftype;
static bool StartClient(unsigned int ip, unsigned short port, bool create_game = true); static bool StartClient(unsigned int ip, unsigned short port, bool create_game = true);
static void ConnectTimeout(evutil_socket_t fd, short events, void* arg); static void ConnectTimeout(evutil_socket_t fd, short events, void* arg);
static void StopClient(bool is_exiting = false); static void StopClient(bool is_exiting = false);
static void ClientRead(bufferevent* bev, void* ctx); static void ClientRead(bufferevent* bev, void* ctx);
static void ClientEvent(bufferevent *bev, short events, void *ctx); static void ClientEvent(bufferevent *bev, short events, void *ctx);
static int ClientThread(); static int ClientThread();
static void HandleSTOCPacketLan(char* data, unsigned int len); static void HandleSTOCPacketLan(unsigned char* data, int len);
static int ClientAnalyze(char* msg, unsigned int len); static int ClientAnalyze(unsigned char* msg, unsigned int len);
static void SwapField(); static void SwapField();
static void SetResponseI(int respI); static void SetResponseI(int respI);
static void SetResponseB(void* respB, unsigned char len); static void SetResponseB(void* respB, unsigned int len);
static void SendResponse(); static void SendResponse();
static unsigned int LookupHost(char *host); static unsigned int LookupHost(char *host);
static bool LookupSRV(char *hostname, HostResult* result); static bool LookupSRV(char *hostname, HostResult* result);
static bool CheckHostnameSplitter(char *hostname, HostResult *result); static bool CheckHostnameSplitter(char *hostname, HostResult *result);
static HostResult ParseHost(char *hostname, unsigned short port); static HostResult ParseHost(char *hostname, unsigned short port);
static void SendPacketToServer(unsigned char proto) { static void SendPacketToServer(unsigned char proto) {
char* p = duel_client_write; auto p = duel_client_write;
BufferIO::WriteInt16(p, 1); BufferIO::WriteInt16(p, 1);
BufferIO::WriteInt8(p, proto); BufferIO::WriteInt8(p, proto);
#ifdef YGOPRO_MESSAGE_DEBUG #ifdef YGOPRO_MESSAGE_DEBUG
...@@ -110,24 +105,32 @@ public: ...@@ -110,24 +105,32 @@ public:
} }
template<typename ST> template<typename ST>
static void SendPacketToServer(unsigned char proto, ST& st) { static void SendPacketToServer(unsigned char proto, ST& st) {
char* p = duel_client_write; auto p = duel_client_write;
BufferIO::WriteInt16(p, 1 + sizeof(ST)); int blen = sizeof(ST);
if (blen > MAX_DATA_SIZE)
return;
BufferIO::WriteInt16(p, (short)(1 + blen));
BufferIO::WriteInt8(p, proto); BufferIO::WriteInt8(p, proto);
memcpy(p, &st, sizeof(ST)); std::memcpy(p, &st, blen);
#ifdef YGOPRO_MESSAGE_DEBUG #ifdef YGOPRO_MESSAGE_DEBUG
printf("CTOS: %d Length: %ld\n", proto, sizeof(ST)); printf("CTOS: %d Length: %ld\n", proto, sizeof(ST));
#endif #endif
bufferevent_write(client_bev, duel_client_write, sizeof(ST) + 3); bufferevent_write(client_bev, duel_client_write, blen + 3);
} }
static void SendBufferToServer(unsigned char proto, void* buffer, size_t len) { static void SendBufferToServer(unsigned char proto, void* buffer, size_t len) {
char* p = duel_client_write; auto p = duel_client_write;
BufferIO::WriteInt16(p, 1 + len); int blen = len;
if (blen < 0)
return;
if (blen > MAX_DATA_SIZE)
blen = MAX_DATA_SIZE;
BufferIO::WriteInt16(p, (short)(1 + blen));
BufferIO::WriteInt8(p, proto); BufferIO::WriteInt8(p, proto);
memcpy(p, buffer, len); std::memcpy(p, buffer, blen);
#ifdef YGOPRO_MESSAGE_DEBUG #ifdef YGOPRO_MESSAGE_DEBUG
printf("CTOS: %d Length: %ld\n", proto, len); printf("CTOS: %d Length: %ld\n", proto, len);
#endif #endif
bufferevent_write(client_bev, duel_client_write, len + 3); bufferevent_write(client_bev, duel_client_write, blen + 3);
} }
protected: protected:
......
...@@ -127,6 +127,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -127,6 +127,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
if(mainGame->dInfo.player_type == 7) { if(mainGame->dInfo.player_type == 7) {
DuelClient::StopClient(); DuelClient::StopClient();
mainGame->dInfo.isStarted = false; mainGame->dInfo.isStarted = false;
mainGame->dInfo.isInDuel = false;
mainGame->dInfo.isFinished = false; mainGame->dInfo.isFinished = false;
mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->CloseDuelWindow(); mainGame->CloseDuelWindow();
...@@ -142,7 +143,8 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -142,7 +143,8 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
if(exit_on_return) if(exit_on_return)
mainGame->device->closeDevice(); mainGame->device->closeDevice();
} else { } else {
mainGame->PopupElement(mainGame->wSurrender); if(!(mainGame->dInfo.isTag && mainGame->dField.tag_surrender))
mainGame->PopupElement(mainGame->wSurrender);
} }
break; break;
} }
...@@ -150,10 +152,12 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -150,10 +152,12 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
soundManager.PlaySoundEffect(SOUND_BUTTON); soundManager.PlaySoundEffect(SOUND_BUTTON);
DuelClient::SendPacketToServer(CTOS_SURRENDER); DuelClient::SendPacketToServer(CTOS_SURRENDER);
mainGame->HideElement(mainGame->wSurrender); mainGame->HideElement(mainGame->wSurrender);
mainGame->dField.tag_surrender = true;
break; break;
} }
case BUTTON_SURRENDER_NO: { case BUTTON_SURRENDER_NO: {
soundManager.PlaySoundEffect(SOUND_BUTTON); soundManager.PlaySoundEffect(SOUND_BUTTON);
mainGame->dField.tag_teammate_surrender = false;
mainGame->HideElement(mainGame->wSurrender); mainGame->HideElement(mainGame->wSurrender);
break; break;
} }
...@@ -521,7 +525,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -521,7 +525,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
current_mset_param = (i << 16) + 3; current_mset_param = (i << 16) + 3;
if(mainGame->gameConf.ask_mset) { if(mainGame->gameConf.ask_mset) {
wchar_t wbuf[256]; wchar_t wbuf[256];
myswprintf(wbuf, dataManager.GetSysString(1355), dataManager.GetName(clicked_card->code)); myswprintf(wbuf, dataManager.GetSysString(1368), dataManager.GetName(clicked_card->code));
mainGame->stQMessage->setText(wbuf); mainGame->stQMessage->setText(wbuf);
mainGame->PopupElement(mainGame->wQuery); mainGame->PopupElement(mainGame->wQuery);
} else { } else {
...@@ -786,7 +790,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -786,7 +790,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
myswprintf(formatBuffer, L"%d", select_min); myswprintf(formatBuffer, L"%d", select_min);
mainGame->stCardPos[id - BUTTON_CARD_0]->setText(formatBuffer); mainGame->stCardPos[id - BUTTON_CARD_0]->setText(formatBuffer);
if(select_min == select_max) { if(select_min == select_max) {
unsigned char respbuf[64]; unsigned char respbuf[SIZE_RETURN_VALUE];
for(int i = 0; i < select_max; ++i) for(int i = 0; i < select_max; ++i)
respbuf[i] = sort_list[i] - 1; respbuf[i] = sort_list[i] - 1;
DuelClient::SetResponseB(respbuf, select_max); DuelClient::SetResponseB(respbuf, select_max);
...@@ -1946,7 +1950,7 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) { ...@@ -1946,7 +1950,7 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
} }
#endif #endif
case CHECKBOX_DISABLE_CHAT: { case CHECKBOX_DISABLE_CHAT: {
bool show = !mainGame->is_building; bool show = (mainGame->is_building && !mainGame->is_siding) ? false : true;
mainGame->wChat->setVisible(show); mainGame->wChat->setVisible(show);
/* /*
if(!show) if(!show)
...@@ -2082,9 +2086,9 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) { ...@@ -2082,9 +2086,9 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
break; break;
const wchar_t* input = mainGame->ebChatInput->getText(); const wchar_t* input = mainGame->ebChatInput->getText();
if(input[0]) { if(input[0]) {
unsigned short msgbuf[256]; uint16_t msgbuf[LEN_CHAT_MSG];
int len = BufferIO::CopyWStr(input, msgbuf, 256); int len = BufferIO::CopyWStr(input, msgbuf, LEN_CHAT_MSG);
DuelClient::SendBufferToServer(CTOS_CHAT, msgbuf, (len + 1) * sizeof(short)); DuelClient::SendBufferToServer(CTOS_CHAT, msgbuf, (len + 1) * sizeof(uint16_t));
mainGame->ebChatInput->setText(L""); mainGame->ebChatInput->setText(L"");
return true; return true;
} }
...@@ -2281,6 +2285,7 @@ void ClientField::GetHoverField(int x, int y) { ...@@ -2281,6 +2285,7 @@ void ClientField::GetHoverField(int x, int y) {
hovered_location = LOCATION_REMOVED; hovered_location = LOCATION_REMOVED;
} }
} else if(rule == 1 && boardx >= matManager.vFieldSzone[1][7][rule][1].Pos.X && boardx <= matManager.vFieldSzone[1][7][rule][2].Pos.X) { } else if(rule == 1 && boardx >= matManager.vFieldSzone[1][7][rule][1].Pos.X && boardx <= matManager.vFieldSzone[1][7][rule][2].Pos.X) {
// deprecated szone[7]
if(boardy >= matManager.vFieldSzone[1][7][rule][2].Pos.Y && boardy <= matManager.vFieldSzone[1][7][rule][0].Pos.Y) { if(boardy >= matManager.vFieldSzone[1][7][rule][2].Pos.Y && boardy <= matManager.vFieldSzone[1][7][rule][0].Pos.Y) {
hovered_controler = 1; hovered_controler = 1;
hovered_location = LOCATION_SZONE; hovered_location = LOCATION_SZONE;
...@@ -2312,7 +2317,8 @@ void ClientField::GetHoverField(int x, int y) { ...@@ -2312,7 +2317,8 @@ void ClientField::GetHoverField(int x, int y) {
hovered_controler = 1; hovered_controler = 1;
hovered_location = LOCATION_EXTRA; hovered_location = LOCATION_EXTRA;
} }
} else if(rule == 0 && boardx >= matManager.vFieldSzone[0][7][rule][0].Pos.X && boardx <= matManager.vFieldSzone[0][7][rule][1].Pos.X) { } else if(rule == 1 && boardx >= matManager.vFieldSzone[0][7][rule][0].Pos.X && boardx <= matManager.vFieldSzone[0][7][rule][1].Pos.X) {
// deprecated szone[7]
if(boardy >= matManager.vFieldSzone[0][7][rule][0].Pos.Y && boardy <= matManager.vFieldSzone[0][7][rule][2].Pos.Y) { if(boardy >= matManager.vFieldSzone[0][7][rule][0].Pos.Y && boardy <= matManager.vFieldSzone[0][7][rule][2].Pos.Y) {
hovered_controler = 0; hovered_controler = 0;
hovered_location = LOCATION_SZONE; hovered_location = LOCATION_SZONE;
...@@ -2337,25 +2343,62 @@ void ClientField::GetHoverField(int x, int y) { ...@@ -2337,25 +2343,62 @@ void ClientField::GetHoverField(int x, int y) {
hovered_sequence = sequence; hovered_sequence = sequence;
} else if(boardy >= matManager.vFieldMzone[0][5][0].Pos.Y && boardy <= matManager.vFieldMzone[0][5][2].Pos.Y) { } else if(boardy >= matManager.vFieldMzone[0][5][0].Pos.Y && boardy <= matManager.vFieldMzone[0][5][2].Pos.Y) {
if(sequence == 1) { if(sequence == 1) {
if(!mzone[1][6]) { if (mzone[0][5]) {
hovered_controler = 0; hovered_controler = 0;
hovered_location = LOCATION_MZONE; hovered_location = LOCATION_MZONE;
hovered_sequence = 5; hovered_sequence = 5;
} else { }
else if(mzone[1][6]) {
hovered_controler = 1; hovered_controler = 1;
hovered_location = LOCATION_MZONE; hovered_location = LOCATION_MZONE;
hovered_sequence = 6; hovered_sequence = 6;
} }
} else if(sequence == 3) { else if((mainGame->dInfo.curMsg == MSG_SELECT_PLACE || mainGame->dInfo.curMsg == MSG_SELECT_DISFIELD)) {
if(!mzone[1][5]) { if (mainGame->dField.selectable_field & (0x1 << (16 + 6))) {
hovered_controler = 1;
hovered_location = LOCATION_MZONE;
hovered_sequence = 6;
}
else {
hovered_controler = 0;
hovered_location = LOCATION_MZONE;
hovered_sequence = 5;
}
}
else{
hovered_controler = 0;
hovered_location = LOCATION_MZONE;
hovered_sequence = 5;
}
}
else if(sequence == 3) {
if (mzone[0][6]) {
hovered_controler = 0; hovered_controler = 0;
hovered_location = LOCATION_MZONE; hovered_location = LOCATION_MZONE;
hovered_sequence = 6; hovered_sequence = 6;
} else { }
else if (mzone[1][5]) {
hovered_controler = 1; hovered_controler = 1;
hovered_location = LOCATION_MZONE; hovered_location = LOCATION_MZONE;
hovered_sequence = 5; hovered_sequence = 5;
} }
else if ((mainGame->dInfo.curMsg == MSG_SELECT_PLACE || mainGame->dInfo.curMsg == MSG_SELECT_DISFIELD)) {
if (mainGame->dField.selectable_field & (0x1 << (16 + 5))) {
hovered_controler = 1;
hovered_location = LOCATION_MZONE;
hovered_sequence = 5;
}
else {
hovered_controler = 0;
hovered_location = LOCATION_MZONE;
hovered_sequence = 6;
}
}
else {
hovered_controler = 0;
hovered_location = LOCATION_MZONE;
hovered_sequence = 6;
}
} }
} else if(boardy >= matManager.vFieldMzone[1][0][2].Pos.Y && boardy <= matManager.vFieldMzone[1][0][0].Pos.Y) { } else if(boardy >= matManager.vFieldMzone[1][0][2].Pos.Y && boardy <= matManager.vFieldMzone[1][0][0].Pos.Y) {
hovered_controler = 1; hovered_controler = 1;
...@@ -2543,7 +2586,7 @@ void ClientField::ShowCardInfoInList(ClientCard* pcard, irr::gui::IGUIElement* e ...@@ -2543,7 +2586,7 @@ void ClientField::ShowCardInfoInList(ClientCard* pcard, irr::gui::IGUIElement* e
} }
} }
void ClientField::SetResponseSelectedCards() const { void ClientField::SetResponseSelectedCards() const {
unsigned char respbuf[64]; unsigned char respbuf[SIZE_RETURN_VALUE];
respbuf[0] = selected_cards.size(); respbuf[0] = selected_cards.size();
for (size_t i = 0; i < selected_cards.size(); ++i) for (size_t i = 0; i < selected_cards.size(); ++i)
respbuf[i + 1] = selected_cards[i]->select_seq; respbuf[i + 1] = selected_cards[i]->select_seq;
......
This diff is collapsed.
...@@ -14,113 +14,121 @@ ...@@ -14,113 +14,121 @@
#include <vector> #include <vector>
#include <list> #include <list>
#ifndef YGOPRO_DEFAULT_DUEL_RULE
#define YGOPRO_DEFAULT_DUEL_RULE 5
#endif
namespace ygo { namespace ygo {
#ifndef YGOPRO_SERVER_MODE #ifndef YGOPRO_SERVER_MODE
struct Config { struct Config {
bool use_d3d; bool use_d3d{ false };
bool use_image_scale; bool use_image_scale{ true };
unsigned short antialias; unsigned short antialias{ 0 };
unsigned short serverport; unsigned short serverport{ 7911 };
unsigned char textfontsize; unsigned char textfontsize{ 14 };
wchar_t lasthost[100]; wchar_t lasthost[100]{};
unsigned short lastport; int lastport{ 0 };
wchar_t nickname[20]; wchar_t nickname[20]{};
wchar_t gamename[20]; wchar_t gamename[20]{};
wchar_t lastcategory[64]; wchar_t lastcategory[64]{};
wchar_t lastdeck[64]; wchar_t lastdeck[64]{};
wchar_t textfont[256]; wchar_t textfont[256]{};
wchar_t numfont[256]; wchar_t numfont[256]{};
wchar_t roompass[20]; wchar_t roompass[20]{};
wchar_t bot_deck_path[64]{};
wchar_t locale[64]; wchar_t locale[64];
wchar_t bot_deck_path[64];
//settings //settings
int chkMAutoPos; int chkMAutoPos{ 0 };
int chkSTAutoPos; int chkSTAutoPos{ 1 };
int chkRandomPos; int chkRandomPos{ 0 };
int chkAutoChain; int chkAutoChain{ 0 };
int chkWaitChain; int chkWaitChain{ 0 };
int chkDefaultShowChain; int chkDefaultShowChain{ 0 };
int chkIgnore1; int chkIgnore1{ 0 };
int chkIgnore2; int chkIgnore2{ 0 };
int use_lflist; int use_lflist{ 1 };
int default_lflist; int default_lflist{ 0 };
int default_rule; int default_rule{ YGOPRO_DEFAULT_DUEL_RULE };
int hide_setname; int hide_setname{ 0 };
int hide_hint_button; int hide_hint_button{ 0 };
int control_mode; int control_mode{ 0 };
int draw_field_spell; int draw_field_spell{ 1 };
int separate_clear_button; int separate_clear_button{ 1 };
int auto_search_limit; int auto_search_limit{ -1 };
int search_multiple_keywords; int search_multiple_keywords{ 1 };
int search_regex; int chkIgnoreDeckChanges{ 0 };
int chkIgnoreDeckChanges; int defaultOT{ 1 };
int defaultOT; int enable_bot_mode{ 0 };
int enable_bot_mode; int quick_animation{ 0 };
int quick_animation; int auto_save_replay{ 0 };
bool window_maximized; int draw_single_chain{ 0 };
int window_width; int hide_player_name{ 0 };
int window_height; int prefer_expansion_script{ 0 };
bool resize_popup_menu; bool enable_sound{ true };
int auto_save_replay; bool enable_music{ true };
int draw_single_chain; double sound_volume{ 0.5 };
int hide_player_name; double music_volume{ 0.5 };
int prefer_expansion_script; int music_mode{ 1 };
int ask_mset; bool window_maximized{ false };
bool enable_sound; int window_width{ 1024 };
bool enable_music; int window_height{ 640 };
double sound_volume; bool resize_popup_menu{ false };
double music_volume; int search_regex{ 0 };
int music_mode; int chkEnablePScale{ 1 };
int chkEnablePScale; int skin_index { -1 };
int skin_index; int ask_mset{ 0 };
}; };
struct DuelInfo { struct DuelInfo {
bool isStarted; bool isStarted{ false };
bool isFinished; bool isInDuel{ false };
bool isReplay; bool isFinished{false};
bool isReplaySkiping; bool isReplay{ false };
bool isFirst; bool isReplaySkiping{ false };
bool isTag; bool isFirst{ false };
bool isSingleMode; bool isTag{ false };
bool is_shuffling; bool isSingleMode{ false };
bool is_swapped; bool is_shuffling{ false };
bool tag_player[2]; bool is_swapped{ false };
int lp[2]; bool tag_player[2]{};
int start_lp; bool isReplaySwapped{ false };
int card_count[2]; int lp[2]{};
int total_attack[2]; int start_lp{ 0 };
int duel_rule; int card_count[2]{};
int turn; int total_attack[2]{};
short curMsg; int duel_rule{ 0 };
wchar_t hostname[20]; int turn{ 0 };
wchar_t clientname[20]; short curMsg{ 0 };
wchar_t hostname_tag[20]; wchar_t hostname[20]{};
wchar_t clientname_tag[20]; wchar_t clientname[20]{};
wchar_t strLP[2][16]; wchar_t hostname_tag[20]{};
wchar_t* vic_string; wchar_t clientname_tag[20]{};
unsigned char player_type; wchar_t strLP[2][16]{};
unsigned char time_player; wchar_t* vic_string{ nullptr };
unsigned short time_limit; unsigned char player_type{ 0 };
unsigned short time_left[2]; unsigned char time_player{ 0 };
wchar_t str_time_left[2][16]; unsigned short time_limit{ 0 };
video::SColor time_color[2]; unsigned short time_left[2]{};
wchar_t str_card_count[2][16]; wchar_t str_time_left[2][16]{};
wchar_t str_total_attack[2][16]; video::SColor time_color[2]{};
video::SColor card_count_color[2]; wchar_t str_card_count[2][16]{};
video::SColor total_attack_color[2]; wchar_t str_total_attack[2][16]{};
bool isReplaySwapped; video::SColor card_count_color[2]{};
video::SColor total_attack_color[2]{};
std::vector<unsigned int> announce_cache;
void Clear();
}; };
struct BotInfo { struct BotInfo {
wchar_t name[256]; wchar_t name[256]{};
wchar_t command[256]; wchar_t command[256]{};
wchar_t desc[256]; wchar_t desc[256]{};
bool support_master_rule_3; bool support_master_rule_3{ false };
bool support_new_master_rule; bool support_new_master_rule{ false };
bool support_master_rule_2020; bool support_master_rule_2020{ false };
bool select_deckfile; bool select_deckfile{ false };
}; };
struct FadingUnit { struct FadingUnit {
...@@ -186,7 +194,7 @@ public: ...@@ -186,7 +194,7 @@ public:
void ShowCardInfo(int code, bool resize = false); void ShowCardInfo(int code, bool resize = false);
void ClearCardInfo(int player = 0); void ClearCardInfo(int player = 0);
void AddLog(const wchar_t* msg, int param = 0); void AddLog(const wchar_t* msg, int param = 0);
void AddChatMsg(const wchar_t* msg, int player); void AddChatMsg(const wchar_t* msg, int player, bool play_sound = false);
void ClearChatMsg(); void ClearChatMsg();
void AddDebugMsg(const char* msgbuf); void AddDebugMsg(const char* msgbuf);
void ErrorLog(const char* msgbuf); void ErrorLog(const char* msgbuf);
...@@ -196,7 +204,9 @@ public: ...@@ -196,7 +204,9 @@ public:
void CloseGameWindow(); void CloseGameWindow();
void CloseDuelWindow(); void CloseDuelWindow();
int LocalPlayer(int player); int LocalPlayer(int player) const;
int OppositePlayer(int player);
int ChatLocalPlayer(int player);
const wchar_t* LocalName(int local_player); const wchar_t* LocalName(int local_player);
const char* GetLocaleDir(const char* dir); const char* GetLocaleDir(const char* dir);
const wchar_t* GetLocaleDirWide(const char* dir); const wchar_t* GetLocaleDirWide(const char* dir);
...@@ -214,6 +224,7 @@ public: ...@@ -214,6 +224,7 @@ public:
} }
void OnResize(); void OnResize();
void ResizeChatInputWindow();
recti Resize(s32 x, s32 y, s32 x2, s32 y2); recti Resize(s32 x, s32 y, s32 x2, s32 y2);
recti Resize(s32 x, s32 y, s32 x2, s32 y2, s32 dx, s32 dy, s32 dx2, s32 dy2); recti Resize(s32 x, s32 y, s32 x2, s32 y2, s32 dx, s32 dy, s32 dx2, s32 dy2);
position2di Resize(s32 x, s32 y); position2di Resize(s32 x, s32 y);
...@@ -250,8 +261,8 @@ public: ...@@ -250,8 +261,8 @@ public:
int hideChatTimer; int hideChatTimer;
bool hideChat; bool hideChat;
int chatTiming[8]; int chatTiming[8]{};
int chatType[8]; int chatType[8]{};
unsigned short linePatternD3D; unsigned short linePatternD3D;
unsigned short linePatternGL; unsigned short linePatternGL;
int waitFrame; int waitFrame;
...@@ -658,6 +669,12 @@ extern unsigned int pre_seed[3]; ...@@ -658,6 +669,12 @@ extern unsigned int pre_seed[3];
#endif #endif
} }
#ifdef YGOPRO_SERVER_MODE
#define SIZE_QUERY_BUFFER 0x40000
#else
#define SIZE_QUERY_BUFFER 0x4000
#endif
#define CARD_IMG_WIDTH 177 #define CARD_IMG_WIDTH 177
#define CARD_IMG_HEIGHT 254 #define CARD_IMG_HEIGHT 254
#define CARD_THUMB_WIDTH 44 #define CARD_THUMB_WIDTH 44
...@@ -882,6 +899,18 @@ extern unsigned int pre_seed[3]; ...@@ -882,6 +899,18 @@ extern unsigned int pre_seed[3];
#define TEXTURE_COVER_O 4 #define TEXTURE_COVER_O 4
#define TEXTURE_ATTACK 5 #define TEXTURE_ATTACK 5
#define TEXTURE_ACTIVATE 6 #define TEXTURE_ACTIVATE 6
//STOC_GAME_MSG messages
#define MSG_WAITING 3
#define MSG_START 4
#define MSG_UPDATE_DATA 6 // flag=0: clear
#define MSG_UPDATE_CARD 7 // flag=QUERY_CODE, code=0: clear
#define MSG_REQUEST_DECK 8
#define MSG_REFRESH_DECK 34
#define MSG_CARD_SELECTED 80
#define MSG_UNEQUIP 95
#define MSG_BE_CHAIN_TARGET 121
#define MSG_CREATE_RELATION 122
#define MSG_RELEASE_RELATION 123
#define AVAIL_OCG 0x1 #define AVAIL_OCG 0x1
#define AVAIL_TCG 0x2 #define AVAIL_TCG 0x2
...@@ -889,25 +918,5 @@ extern unsigned int pre_seed[3]; ...@@ -889,25 +918,5 @@ extern unsigned int pre_seed[3];
#define AVAIL_SC 0x8 #define AVAIL_SC 0x8
#define AVAIL_OCGTCG (AVAIL_OCG|AVAIL_TCG) #define AVAIL_OCGTCG (AVAIL_OCG|AVAIL_TCG)
#ifndef YGOPRO_DEFAULT_DUEL_RULE #define MAX_LAYER_COUNT 6
#define YGOPRO_DEFAULT_DUEL_RULE 5
#endif
#ifndef YGOPRO_MAX_DECK
#define YGOPRO_MAX_DECK 60
#endif
#ifndef YGOPRO_MIN_DECK
#define YGOPRO_MIN_DECK 40
#endif
#ifndef YGOPRO_MAX_EXTRA
#define YGOPRO_MAX_EXTRA 15
#endif
#ifndef YGOPRO_MAX_SIDE
#define YGOPRO_MAX_SIDE 15
#endif
#define CARD_ARTWORK_VERSIONS_OFFSET 10
#endif // GAME_H #endif // GAME_H
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#import <CoreFoundation/CoreFoundation.h> #import <CoreFoundation/CoreFoundation.h>
#endif #endif
int enable_log = 0; unsigned int enable_log = 0x3;
#ifndef YGOPRO_SERVER_MODE #ifndef YGOPRO_SERVER_MODE
bool exit_on_return = false; bool exit_on_return = false;
bool auto_watch_mode = false; bool auto_watch_mode = false;
......
...@@ -323,26 +323,26 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) { ...@@ -323,26 +323,26 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
auto tit = tMap[fit ? 1 : 0].find(code); auto tit = tMap[fit ? 1 : 0].find(code);
if(tit == tMap[fit ? 1 : 0].end()) { if(tit == tMap[fit ? 1 : 0].end()) {
char file[256]; char file[256];
sprintf(file, "expansions/pics/%d.png", code); snprintf(file, sizeof file, "expansions/pics/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, width, height); irr::video::ITexture* img = GetTextureFromFile(file, width, height);
if(img == NULL) { if(img == NULL) {
sprintf(file, "expansions/pics/%d.jpg", code); snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
img = GetTextureFromFile(file, width, height); img = GetTextureFromFile(file, width, height);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, mainGame->GetLocaleDir("pics/%d.png"), code); snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.png"), code);
img = GetTextureFromFile(file, width, height); img = GetTextureFromFile(file, width, height);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, mainGame->GetLocaleDir("pics/%d.jpg"), code); snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.jpg"), code);
img = GetTextureFromFile(file, width, height); img = GetTextureFromFile(file, width, height);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/%d.png", code); snprintf(file, sizeof file, "pics/%d.png", code);
img = GetTextureFromFile(file, width, height); img = GetTextureFromFile(file, width, height);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/%d.jpg", code); snprintf(file, sizeof file, "pics/%d.jpg", code);
img = GetTextureFromFile(file, width, height); img = GetTextureFromFile(file, width, height);
} }
if(img == NULL && !mainGame->gameConf.use_image_scale) { if(img == NULL && !mainGame->gameConf.use_image_scale) {
...@@ -366,10 +366,10 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) { ...@@ -366,10 +366,10 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
} }
irr::video::ITexture* texture; irr::video::ITexture* texture;
char file[256]; char file[256];
sprintf(file, "expansions/pics/%d.jpg", code); snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
irr::video::IImage* srcimg = driver->createImageFromFile(file); irr::video::IImage* srcimg = driver->createImageFromFile(file);
if(srcimg == NULL) { if(srcimg == NULL) {
sprintf(file, "pics/%d.jpg", code); snprintf(file, sizeof file, "pics/%d.jpg", code);
srcimg = driver->createImageFromFile(file); srcimg = driver->createImageFromFile(file);
} }
if(srcimg == NULL) { if(srcimg == NULL) {
...@@ -395,49 +395,49 @@ int ImageManager::LoadThumbThread() { ...@@ -395,49 +395,49 @@ int ImageManager::LoadThumbThread() {
imageManager.tThumbLoadingCodes.pop(); imageManager.tThumbLoadingCodes.pop();
imageManager.tThumbLoadingMutex.unlock(); imageManager.tThumbLoadingMutex.unlock();
char file[256]; char file[256];
sprintf(file, "expansions/pics/thumbnail/%d.png", code); snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.png", code);
irr::video::IImage* img = imageManager.driver->createImageFromFile(file); irr::video::IImage* img = imageManager.driver->createImageFromFile(file);
if(img == NULL) { if(img == NULL) {
sprintf(file, "expansions/pics/thumbnail/%d.jpg", code); snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, mainGame->GetLocaleDir("pics/thumbnail/%d.png"), code); snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/thumbnail/%d.png"), code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, mainGame->GetLocaleDir("pics/thumbnail/%d.jpg"), code); snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/thumbnail/%d.jpg"), code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/thumbnail/%d.png", code); snprintf(file, sizeof file, "pics/thumbnail/%d.png", code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/thumbnail/%d.jpg", code); snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
if(img == NULL && mainGame->gameConf.use_image_scale) { if(img == NULL && mainGame->gameConf.use_image_scale) {
sprintf(file, "expansions/pics/%d.png", code); snprintf(file, sizeof file, "expansions/pics/%d.png", code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
if(img == NULL) { if(img == NULL) {
sprintf(file, "expansions/pics/%d.jpg", code); snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, mainGame->GetLocaleDir("pics/%d.png"), code); snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.png"), code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, mainGame->GetLocaleDir("pics/%d.jpg"), code); snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.jpg"), code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/%d.png", code); snprintf(file, sizeof file, "pics/%d.png", code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/%d.jpg", code); snprintf(file, sizeof file, "pics/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
} }
...@@ -483,7 +483,7 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) { ...@@ -483,7 +483,7 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if(lit != tThumbLoading.end()) { if(lit != tThumbLoading.end()) {
if(lit->second != NULL) { if(lit->second != NULL) {
char file[256]; char file[256];
sprintf(file, "pics/thumbnail/%d.jpg", code); snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
irr::video::ITexture* texture = driver->addTexture(file, lit->second); // textures must be added in the main thread due to OpenGL irr::video::ITexture* texture = driver->addTexture(file, lit->second); // textures must be added in the main thread due to OpenGL
lit->second->drop(); lit->second->drop();
tThumb[code] = texture; tThumb[code] = texture;
...@@ -513,26 +513,26 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) { ...@@ -513,26 +513,26 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
auto tit = tFields.find(code); auto tit = tFields.find(code);
if(tit == tFields.end()) { if(tit == tFields.end()) {
char file[256]; char file[256];
sprintf(file, "expansions/pics/field/%d.png", code); snprintf(file, sizeof file, "expansions/pics/field/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == NULL) { if(img == NULL) {
sprintf(file, "expansions/pics/field/%d.jpg", code); snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, mainGame->GetLocaleDir("pics/field/%d.png"), code); snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.png"), code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, mainGame->GetLocaleDir("pics/field/%d.jpg"), code); snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.jpg"), code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/field/%d.png", code); snprintf(file, sizeof file, "pics/field/%d.png", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/field/%d.jpg", code); snprintf(file, sizeof file, "pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == NULL) { if(img == NULL) {
tFields[code] = NULL; tFields[code] = NULL;
...@@ -557,26 +557,26 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) { ...@@ -557,26 +557,26 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) {
auto tit = tFields.find(code); auto tit = tFields.find(code);
if(tit == tFields.end()) { if(tit == tFields.end()) {
char file[256]; char file[256];
sprintf(file, "expansions/pics/field/%d.png", code); snprintf(file, sizeof file, "expansions/pics/field/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == NULL) { if(img == NULL) {
sprintf(file, "expansions/pics/field/%d.jpg", code); snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, mainGame->GetLocaleDir("pics/field/%d.png"), code); snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.png"), code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, mainGame->GetLocaleDir("pics/field/%d.jpg"), code); snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.jpg"), code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/field/%d.png", code); snprintf(file, sizeof file, "pics/field/%d.png", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
} }
if(img == NULL) { if(img == NULL) {
sprintf(file, "pics/field/%d.jpg", code); snprintf(file, sizeof file, "pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == NULL) { if(img == NULL) {
tFields[code] = NULL; tFields[code] = NULL;
......
...@@ -31,12 +31,8 @@ ...@@ -31,12 +31,8 @@
#ifndef __IRR_USTRING_H_INCLUDED__ #ifndef __IRR_USTRING_H_INCLUDED__
#define __IRR_USTRING_H_INCLUDED__ #define __IRR_USTRING_H_INCLUDED__
#if (__cplusplus > 199711L) || (_MSC_VER >= 1600) || defined(__GXX_EXPERIMENTAL_CXX0X__) #define USTRING_CPP0X
# define USTRING_CPP0X #define USTRING_CPP0X_NEWLITERALS
# if defined(__GXX_EXPERIMENTAL_CXX0X__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)))
# define USTRING_CPP0X_NEWLITERALS
# endif
#endif
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
......
...@@ -22,11 +22,11 @@ public: ...@@ -22,11 +22,11 @@ public:
S3DVertex vFieldSpell2[4]; S3DVertex vFieldSpell2[4];
//S3DVertex vBackLine[76]; //S3DVertex vBackLine[76];
S3DVertex vFieldDeck[2][4]; S3DVertex vFieldDeck[2][4];
S3DVertex vFieldGrave[2][2][4]; S3DVertex vFieldGrave[2][2][4]; //[player][rule], rule = 0: dule_rule <= 3, 1: dule_rule >= 4
S3DVertex vFieldExtra[2][4]; S3DVertex vFieldExtra[2][4];
S3DVertex vFieldRemove[2][2][4]; S3DVertex vFieldRemove[2][2][4]; //[player][rule]
S3DVertex vFieldMzone[2][7][4]; S3DVertex vFieldMzone[2][7][4]; //[player][sequence]
S3DVertex vFieldSzone[2][8][2][4]; S3DVertex vFieldSzone[2][8][2][4]; //[player][sequence][rule]
irr::core::vector3df vFieldContiAct[4]; irr::core::vector3df vFieldContiAct[4];
S3DVertex vArrow[40]; S3DVertex vArrow[40];
SColor c2d[4]; SColor c2d[4];
......
...@@ -16,8 +16,8 @@ void UpdateDeck() { ...@@ -16,8 +16,8 @@ void UpdateDeck() {
mainGame->gameConf.lastcategory, 64); mainGame->gameConf.lastcategory, 64);
BufferIO::CopyWStr(mainGame->cbDeckSelect->getItem(mainGame->cbDeckSelect->getSelected()), BufferIO::CopyWStr(mainGame->cbDeckSelect->getItem(mainGame->cbDeckSelect->getSelected()),
mainGame->gameConf.lastdeck, 64); mainGame->gameConf.lastdeck, 64);
char deckbuf[1024]; unsigned char deckbuf[1024];
char* pdeck = deckbuf; auto pdeck = deckbuf;
BufferIO::WriteInt32(pdeck, deckManager.current_deck.main.size() + deckManager.current_deck.extra.size()); BufferIO::WriteInt32(pdeck, deckManager.current_deck.main.size() + deckManager.current_deck.extra.size());
BufferIO::WriteInt32(pdeck, deckManager.current_deck.side.size()); BufferIO::WriteInt32(pdeck, deckManager.current_deck.side.size());
for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i) for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i)
...@@ -298,11 +298,17 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -298,11 +298,17 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
for(int i = 0; i < max; ++i) { for(int i = 0; i < max; ++i) {
int main = replay.ReadInt32(); int main = replay.ReadInt32();
Deck tmp_deck; Deck tmp_deck;
for(int j = 0; j < main; ++j) for (int j = 0; j < main; ++j) {
tmp_deck.main.push_back(dataManager.GetCodePointer(replay.ReadInt32())); auto card = dataManager.GetCodePointer(replay.ReadInt32());
if (card != dataManager.datas_end)
tmp_deck.main.push_back(card);
}
int extra = replay.ReadInt32(); int extra = replay.ReadInt32();
for(int j = 0; j < extra; ++j) for (int j = 0; j < extra; ++j) {
tmp_deck.extra.push_back(dataManager.GetCodePointer(replay.ReadInt32())); auto card = dataManager.GetCodePointer(replay.ReadInt32());
if (card != dataManager.datas_end)
tmp_deck.extra.push_back(card);
}
FileSystem::SafeFileName(namebuf[i]); FileSystem::SafeFileName(namebuf[i]);
myswprintf(filename, L"deck/%ls-%d %ls.ydk", ex_filename, i + 1, namebuf[i]); myswprintf(filename, L"deck/%ls-%d %ls.ydk", ex_filename, i + 1, namebuf[i]);
deckManager.SaveDeck(tmp_deck, filename); deckManager.SaveDeck(tmp_deck, filename);
...@@ -366,9 +372,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -366,9 +372,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int flag = 0; int flag = 0;
flag += (mainGame->chkBotHand->isChecked() ? 0x1 : 0); flag += (mainGame->chkBotHand->isChecked() ? 0x1 : 0);
char arg2[8]; char arg2[8];
sprintf(arg2, "%d", flag); snprintf(arg2, sizeof arg2, "%d", flag);
char arg3[8]; char arg3[8];
sprintf(arg3, "%d", mainGame->gameConf.serverport); snprintf(arg3, sizeof arg3, "%d", mainGame->gameConf.serverport);
execl("./bot", "bot", arg1, arg2, arg3, NULL); execl("./bot", "bot", arg1, arg2, arg3, NULL);
exit(0); exit(0);
} else { } else {
......
...@@ -176,7 +176,7 @@ public: ...@@ -176,7 +176,7 @@ public:
bool success = true; bool success = true;
TraversalDir(dir, [dir, &success](const char *name, bool isdir) { TraversalDir(dir, [dir, &success](const char *name, bool isdir) {
char full_path[256]; char full_path[256];
sprintf(full_path, "%s/%s", dir, name); snprintf(full_path, sizeof full_path, "%s/%s", dir, name);
if (isdir) if (isdir)
{ {
if(!DeleteDir(full_path)) if(!DeleteDir(full_path))
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -29,6 +29,9 @@ if SERVER_MODE then ...@@ -29,6 +29,9 @@ if SERVER_MODE then
if SERVER_PRO2_SUPPORT then if SERVER_PRO2_SUPPORT then
defines { "SERVER_PRO2_SUPPORT" } defines { "SERVER_PRO2_SUPPORT" }
end end
if SERVER_TAG_SURRENDER_CONFIRM then
defines { "SERVER_TAG_SURRENDER_CONFIRM" }
end
else else
kind "WindowedApp" kind "WindowedApp"
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Subproject commit dd4322d6ebd8850defa34e6128559c4f7e2bd96b Subproject commit b69f68fc424281977c6e8e2d4aa2f381c91ec399
1 ICON "ygopro.ico" 1 ICON "ygopro.ico"
1 VERSIONINFO 1 VERSIONINFO
FILEVERSION 1, 0, 36, 0 FILEVERSION 1, 0, 36, 1
PRODUCTVERSION 1, 0, 36, 0 PRODUCTVERSION 1, 0, 36, 1
FILEOS 0x4 FILEOS 0x4
FILETYPE 0x1 FILETYPE 0x1
......
This diff is collapsed.
Subproject commit 52e79efa0da5294cf5218c107de224a0af264965 Subproject commit eccdab4349138c7c4aa1f2f44ea994dfa98c0b79
This diff is collapsed.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#nickname & gamename should be less than 20 characters #nickname & gamename should be less than 20 characters
use_d3d = 0 use_d3d = 0
use_image_scale = 1 use_image_scale = 1
pro_version = 4960 pro_version = 4961
antialias = 2 antialias = 2
errorlog = 3 errorlog = 3
nickname = Komeiji Koishi nickname = Komeiji Koishi
......
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