Commit 8ca8759a authored by fallenstardust's avatar fallenstardust

update gframe

parent 31b2b890
......@@ -49,67 +49,93 @@ public:
return l;
}
// UTF-16/UTF-32 to UTF-8
static int EncodeUTF8(const wchar_t * wsrc, char * str) {
template<size_t N>
static int EncodeUTF8(const wchar_t* wsrc, char(&str)[N]) {
char* pstr = str;
while(*wsrc != 0) {
if(*wsrc < 0x80) {
*str = (char)*wsrc;
++str;
} else if(*wsrc < 0x800) {
str[0] = ((*wsrc >> 6) & 0x1f) | 0xc0;
str[1] = ((*wsrc) & 0x3f) | 0x80;
str += 2;
} else if(*wsrc < 0x10000 && (*wsrc < 0xd800 || *wsrc > 0xdfff)) {
str[0] = ((*wsrc >> 12) & 0xf) | 0xe0;
str[1] = ((*wsrc >> 6) & 0x3f) | 0x80;
str[2] = ((*wsrc) & 0x3f) | 0x80;
str += 3;
} else {
#ifdef _WIN32
unsigned unicode = 0;
unicode |= (*wsrc++ & 0x3ff) << 10;
unicode |= *wsrc & 0x3ff;
unicode += 0x10000;
str[0] = ((unicode >> 18) & 0x7) | 0xf0;
str[1] = ((unicode >> 12) & 0x3f) | 0x80;
str[2] = ((unicode >> 6) & 0x3f) | 0x80;
str[3] = ((unicode) & 0x3f) | 0x80;
#else
str[0] = ((*wsrc >> 18) & 0x7) | 0xf0;
str[1] = ((*wsrc >> 12) & 0x3f) | 0x80;
str[2] = ((*wsrc >> 6) & 0x3f) | 0x80;
str[3] = ((*wsrc) & 0x3f) | 0x80;
#endif // _WIN32
str += 4;
while (*wsrc != 0) {
unsigned cur = *wsrc;
int codepoint_size = 0;
if (cur < 0x80U)
codepoint_size = 1;
else if (cur < 0x800U)
codepoint_size = 2;
else if (cur < 0x10000U && (cur < 0xd800U || cur > 0xdfffU))
codepoint_size = 3;
else
codepoint_size = 4;
if (pstr - str + codepoint_size > N - 1)
break;
switch (codepoint_size) {
case 1:
*pstr = (char)cur;
break;
case 2:
pstr[0] = ((cur >> 6) & 0x1f) | 0xc0;
pstr[1] = (cur & 0x3f) | 0x80;
break;
case 3:
pstr[0] = ((cur >> 12) & 0xf) | 0xe0;
pstr[1] = ((cur >> 6) & 0x3f) | 0x80;
pstr[2] = (cur & 0x3f) | 0x80;
break;
case 4:
if (sizeof(wchar_t) == 2) {
cur = 0;
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++;
}
*str = 0;
return str - pstr;
*pstr = 0;
return pstr - str;
}
// UTF-8 to UTF-16/UTF-32
static int DecodeUTF8(const char * src, wchar_t * wstr) {
template<size_t N>
static int DecodeUTF8(const char* src, wchar_t(&wstr)[N]) {
const char* p = src;
wchar_t* wp = wstr;
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 > N - 1)
break;
if((cur & 0x80) == 0) {
*wp = *p;
p++;
} else if((*p & 0xe0) == 0xc0) {
} else if((cur & 0xe0) == 0xc0) {
*wp = (((unsigned)p[0] & 0x1f) << 6) | ((unsigned)p[1] & 0x3f);
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);
p += 3;
} else if((*p & 0xf8) == 0xf0) {
#ifdef _WIN32
unsigned unicode = (((unsigned)p[0] & 0x7) << 18) | (((unsigned)p[1] & 0x3f) << 12) | (((unsigned)p[2] & 0x3f) << 6) | ((unsigned)p[3] & 0x3f);
unicode -= 0x10000;
*wp++ = (unicode >> 10) | 0xd800;
*wp = (unicode & 0x3ff) | 0xdc00;
#else
*wp = (((unsigned)p[0] & 0x7) << 18) | (((unsigned)p[1] & 0x3f) << 12) | (((unsigned)p[2] & 0x3f) << 6) | ((unsigned)p[3] & 0x3f);
#endif // _WIN32
} else if((cur & 0xf8) == 0xf0) {
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);
unicode -= 0x10000;
*wp++ = (unicode >> 10) | 0xd800;
*wp = (unicode & 0x3ff) | 0xdc00;
} else {
*wp = (((unsigned)p[0] & 0x7) << 18) | (((unsigned)p[1] & 0x3f) << 12) | (((unsigned)p[2] & 0x3f) << 6) | ((unsigned)p[3] & 0x3f);
}
p += 4;
} else
p++;
......
......@@ -14,6 +14,14 @@ using CardData = card_data;
struct CardDataC : card_data {
unsigned int ot{};
unsigned int category{};
bool is_setcodes(std::vector <uint32> values) const {
for (auto& value : values) {
if (is_setcode(value))
return true;
}
return false;
}
};
struct CardString {
std::wstring name;
......
......@@ -700,8 +700,7 @@ void ClientField::ShowSelectOption(int select_hint) {
mainGame->wOptions->setRelativePosition(pos);
mainGame->bgOptions->setRelativePosition(rect<s32>(0, 0, (scrollbar ? 405 : 390) * mainGame->xScale, pos.LowerRightCorner.Y - pos.UpperLeftCorner.Y));
} else {
mainGame->SetStaticText(mainGame->stOptions, 350 * mainGame->xScale, mainGame->guiFont,
(wchar_t*)dataManager.GetDesc(select_options[0]));
mainGame->SetStaticText(mainGame->stOptions, 350 * mainGame->xScale, mainGame->guiFont, dataManager.GetDesc(select_options[0]));
mainGame->stOptions->setVisible(true);
mainGame->btnOptionp->setVisible(false);
mainGame->btnOptionn->setVisible(count > 1);
......
......@@ -272,13 +272,22 @@ const wchar_t* DataManager::GetSetName(int code) {
return NULL;
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) {
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)
return csit->first;
if(setname.size() < 2) {
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) {
if(!bracket)
......@@ -405,14 +414,14 @@ uint32 DataManager::CardReader(uint32 code, card_data* pData) {
}
byte* DataManager::ScriptReaderEx(const char* script_name, int* slen) {
// default script name: ./script/c%d.lua
char first[256];
char second[256];
char first[256]{};
char second[256]{};
if(mainGame->gameConf.prefer_expansion_script) {
sprintf(first, "expansions/%s", script_name + 2);
sprintf(second, "%s", script_name + 2);
snprintf(first, sizeof first, "expansions/%s", script_name + 2);
snprintf(second, sizeof second, "%s", script_name + 2);
} else {
sprintf(first, "%s", script_name + 2);
sprintf(second, "expansions/%s", script_name + 2);
snprintf(first, sizeof first, "%s", script_name + 2);
snprintf(second, sizeof second, "expansions/%s", script_name + 2);
}
if(mainGame->gameConf.prefer_expansion_script) {
if(ScriptReader(first, slen))
......
......@@ -34,7 +34,7 @@ public:
const wchar_t* GetVictoryString(int code);
const wchar_t* GetCounterName(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* FormatLocation(int location, int sequence);
const wchar_t* FormatAttribute(int attribute);
......
......@@ -1398,14 +1398,14 @@ void DeckBuilder::FilterCards() {
results.clear();
struct element_t {
std::wstring keyword;
unsigned int setcode;
std::vector<unsigned int> setcodes;
enum class type_t {
all,
name,
setcode
} type;
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();
std::wstring str = std::wstring(pstr);
......@@ -1446,7 +1446,7 @@ void DeckBuilder::FilterCards() {
element.keyword = str.substr(element_start, length);
} else
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);
if(element_end == std::wstring::npos)
break;
......@@ -1464,7 +1464,7 @@ void DeckBuilder::FilterCards() {
}
if(element_start < str.size()) {
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);
}
}
......@@ -1551,14 +1551,14 @@ void DeckBuilder::FilterCards() {
if (elements_iterator->type == element_t::type_t::name) {
match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str());
} else if (elements_iterator->type == element_t::type_t::setcode) {
match = elements_iterator->setcode && data.is_setcode(elements_iterator->setcode);
match = data.is_setcodes(elements_iterator->setcodes);
} else {
int trycode = BufferIO::GetVal(elements_iterator->keyword.c_str());
bool tryresult = dataManager.GetData(trycode, 0);
if(!tryresult) {
match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str())
|| text.text.find(elements_iterator->keyword) != std::wstring::npos
|| (elements_iterator->setcode && data.is_setcode(elements_iterator->setcode));
|| data.is_setcodes(elements_iterator->setcodes);
} else {
match = data.code == trycode || data.alias == trycode;
}
......
......@@ -242,7 +242,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) {
wchar_t filepath[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) {
GetCategoryPath(catepath, cbCategory->getSelected(), cbCategory->getText(), cbCategory == mainGame->cbDBCategory);
myswprintf(filepath, L"%ls/%ls.ydk", catepath, deckname);
......
......@@ -2038,7 +2038,7 @@ void Game::AddDebugMsg(const char* msg) {
}
if (enable_log & 0x2) {
char msgbuf[1040];
sprintf(msgbuf, "[Script Error]: %s", msg);
snprintf(msgbuf, sizeof msgbuf, "[Script Error]: %s", msg);
ErrorLog(msgbuf);
}
}
......
......@@ -133,11 +133,11 @@ irr::video::ITexture* ImageManager::GetTexture(int code) {
if(tit == tMap.end()) {
char file[256];
// char file_img[256];
sprintf(file, "expansions/pics/%d.jpg", code);
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
irr::video::ITexture* img = NULL;
std::list<std::string>::iterator iter;
for (iter = support_types.begin(); iter != support_types.end(); ++iter) {
sprintf(file, "/expansions/pics/%d.%s", code, iter->c_str());
snprintf(file, sizeof file, "/expansions/pics/%d.%s", code, iter->c_str());
img = driver->getTexture(image_work_path + path(file));
// sprintf(file_img, "%s", (image_work_path + path(file)).c_str());
// img = GetTextureFromFile(file_img, width, height);
......@@ -147,7 +147,7 @@ irr::video::ITexture* ImageManager::GetTexture(int code) {
}
if(img == NULL) {
for (iter = support_types.begin(); iter != support_types.end(); ++iter) {
sprintf(file, "%s/%d.%s", irr::android::getCardImagePath(mainGame->appMain).c_str(), code, iter->c_str());
snprintf(file, sizeof file, "%s/%d.%s", irr::android::getCardImagePath(mainGame->appMain).c_str(), code, iter->c_str());
img = driver->getTexture(file);
// img = GetTextureFromFile(file, width, height);
if (img != NULL) {
......@@ -157,7 +157,7 @@ irr::video::ITexture* ImageManager::GetTexture(int code) {
}
if(img == NULL){//sdcard first, then zip
for (iter = support_types.begin(); iter != support_types.end(); ++iter) {
sprintf(file, "pics/%d.%s", code, iter->c_str());
snprintf(file, sizeof file, "pics/%d.%s", code, iter->c_str());
//load image in zip
irr::io::IReadFile* in_zip_file = device->getFileSystem()->createAndOpenFile(file);
if (in_zip_file && in_zip_file->getSize() > 0) {
......@@ -190,10 +190,10 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
}
irr::video::ITexture* texture;
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);
if(srcimg == NULL) {
sprintf(file, "pics/%d.jpg", code);
snprintf(file, sizeof file, "pics/%d.jpg", code);
srcimg = driver->createImageFromFile(file);
}
if(srcimg == NULL) {
......@@ -221,18 +221,18 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) {
auto tit = tFields.find(code);
if(tit == tFields.end()) {
char file[256];
sprintf(file, "field/%s/%d.jpg", irr::android::getCardImagePath(mainGame->appMain).c_str(), code);
snprintf(file, sizeof file, "field/%s/%d.jpg", irr::android::getCardImagePath(mainGame->appMain).c_str(), code);
irr::video::ITexture* img = driver->getTexture(file);
if(img == NULL) {
sprintf(file, "field/%s/%d.jpg", irr::android::getCardImagePath(mainGame->appMain).c_str(), code);
snprintf(file, sizeof file, "field/%s/%d.jpg", irr::android::getCardImagePath(mainGame->appMain).c_str(), code);
img = driver->getTexture(file);
}
if(img == NULL) {
sprintf(file, "field/%s/%d.png", irr::android::getCardImagePath(mainGame->appMain).c_str(), code);
snprintf(file, sizeof file, "field/%s/%d.png", irr::android::getCardImagePath(mainGame->appMain).c_str(), code);
img = driver->getTexture(file);
}
if(img == NULL) {
sprintf(file, "pics/field/%d.jpg", code);
snprintf(file, sizeof file, "pics/field/%d.jpg", code);
img = driver->getTexture(file);
if(img == NULL) {
tFields[code] = NULL;
......
......@@ -31,12 +31,8 @@
#ifndef __IRR_USTRING_H_INCLUDED__
#define __IRR_USTRING_H_INCLUDED__
#if (__cplusplus > 199711L) || (_MSC_VER >= 1600) || defined(__GXX_EXPERIMENTAL_CXX0X__)
# define USTRING_CPP0X
# if defined(__GXX_EXPERIMENTAL_CXX0X__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)))
# define USTRING_CPP0X_NEWLITERALS
# endif
#endif
#define USTRING_CPP0X
#define USTRING_CPP0X_NEWLITERALS
#include <stdio.h>
#include <string.h>
......
......@@ -464,10 +464,10 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
char arg2[32];
arg2[0]=0;
if(mainGame->chkBotHand->isChecked())
sprintf(arg2, " Hand=1");
snprintf(arg2, sizeof arg2, " Hand=1");
char arg3[32];
sprintf(arg3, " Port=%d", mainGame->gameConf.serverport);
sprintf(args, "%s%s%s", arg1, arg2, arg3);
snprintf(arg3, sizeof arg3, " Port=%d", mainGame->gameConf.serverport);
snprintf(args, sizeof args, "%s%s%s", arg1, arg2, arg3);
android::runWindbot(mainGame->appMain, args);
if(!NetServer::StartServer(mainGame->gameConf.serverport)) {
mainGame->soundManager->PlaySoundEffect(SoundManager::SFX::INFO);
......
......@@ -176,7 +176,7 @@ public:
bool success = true;
TraversalDir(dir, [dir, &success](const char *name, bool isdir) {
char full_path[256];
sprintf(full_path, "%s/%s", dir, name);
snprintf(full_path, sizeof full_path, "%s/%s", dir, name);
if (isdir)
{
if(!DeleteDir(full_path))
......
......@@ -3,11 +3,7 @@
namespace ygo {
Replay::Replay()
: fp(nullptr), pheader(), pdata(nullptr), replay_size(0), comp_size(0), is_recording(false), is_replaying(false) {
#ifdef _WIN32
recording_fp = nullptr;
#endif
Replay::Replay() {
replay_data = new unsigned char[MAX_REPLAY_SIZE];
comp_data = new unsigned char[MAX_COMP_SIZE];
}
......@@ -134,8 +130,8 @@ void Replay::EndRecord() {
comp_size = MAX_COMP_SIZE;
int ret = LzmaCompress(comp_data, &comp_size, replay_data, replay_size, pheader.props, &propsize, 5, 1 << 24, 3, 0, 2, 32, 1);
if (ret != SZ_OK) {
*((int*)(comp_data)) = ret;
comp_size = sizeof(ret);
std::memcpy(comp_data, &ret, sizeof ret);
comp_size = sizeof ret;
}
is_recording = false;
}
......
......@@ -17,16 +17,13 @@ namespace ygo {
#define MAX_COMP_SIZE 0x2000
struct ReplayHeader {
unsigned int id;
unsigned int version;
unsigned int flag;
unsigned int seed;
unsigned int datasize;
unsigned int start_time;
unsigned char props[8];
ReplayHeader()
: id(0), version(0), flag(0), seed(0), datasize(0), start_time(0), props{ 0 } {}
unsigned int id{};
unsigned int version{};
unsigned int flag{};
unsigned int seed{};
unsigned int datasize{};
unsigned int start_time{};
unsigned char props[8]{};
};
class Replay {
......@@ -59,21 +56,21 @@ public:
char ReadInt8();
void Rewind();
FILE* fp;
FILE* fp{ nullptr };
#ifdef _WIN32
HANDLE recording_fp;
HANDLE recording_fp{ nullptr };
#endif
ReplayHeader pheader;
unsigned char* replay_data;
unsigned char* comp_data;
size_t replay_size;
size_t comp_size;
size_t replay_size{};
size_t comp_size{};
private:
unsigned char* pdata;
bool is_recording;
bool is_replaying;
unsigned char* pdata{ nullptr };
bool is_recording{};
bool is_replaying{};
};
}
......
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