Commit 5f56a93a authored by nanahira's avatar nanahira

Merge branch 'master' into server

parents 56c43452 89494171
...@@ -27,13 +27,11 @@ ClientField::~ClientField() { ...@@ -27,13 +27,11 @@ ClientField::~ClientField() {
} }
hand[i].clear(); hand[i].clear();
for (auto& card : mzone[i]) { for (auto& card : mzone[i]) {
if (card) delete card;
delete card;
card = nullptr; card = nullptr;
} }
for (auto& card : szone[i]) { for (auto& card : szone[i]) {
if (card) delete card;
delete card;
card = nullptr; card = nullptr;
} }
for (auto& card : grave[i]) { for (auto& card : grave[i]) {
...@@ -44,7 +42,6 @@ ClientField::~ClientField() { ...@@ -44,7 +42,6 @@ ClientField::~ClientField() {
delete card; delete card;
} }
remove[i].clear(); remove[i].clear();
for (auto& card : extra[i]) { for (auto& card : extra[i]) {
delete card; delete card;
} }
...@@ -57,30 +54,33 @@ ClientField::~ClientField() { ...@@ -57,30 +54,33 @@ ClientField::~ClientField() {
} }
void ClientField::Clear() { void ClientField::Clear() {
for(int i = 0; i < 2; ++i) { for(int i = 0; i < 2; ++i) {
for(auto cit = deck[i].begin(); cit != deck[i].end(); ++cit) for (auto& card : deck[i]) {
delete *cit; delete card;
}
deck[i].clear(); deck[i].clear();
for(auto cit = hand[i].begin(); cit != hand[i].end(); ++cit) for (auto& card : hand[i]) {
delete *cit; delete card;
}
hand[i].clear(); hand[i].clear();
for(auto cit = mzone[i].begin(); cit != mzone[i].end(); ++cit) { for (auto& card : mzone[i]) {
if(*cit) delete card;
delete *cit; card = nullptr;
*cit = 0; }
} for (auto& card : szone[i]) {
for(auto cit = szone[i].begin(); cit != szone[i].end(); ++cit) { delete card;
if(*cit) card = nullptr;
delete *cit; }
*cit = 0; for (auto& card : grave[i]) {
} delete card;
for(auto cit = grave[i].begin(); cit != grave[i].end(); ++cit) }
delete *cit;
grave[i].clear(); grave[i].clear();
for(auto cit = remove[i].begin(); cit != remove[i].end(); ++cit) for (auto& card : remove[i]) {
delete *cit; delete card;
}
remove[i].clear(); remove[i].clear();
for(auto cit = extra[i].begin(); cit != extra[i].end(); ++cit) for (auto& card : extra[i]) {
delete *cit; delete card;
}
extra[i].clear(); extra[i].clear();
deck_act[i] = false; deck_act[i] = false;
grave_act[i] = false; grave_act[i] = false;
...@@ -88,11 +88,13 @@ void ClientField::Clear() { ...@@ -88,11 +88,13 @@ void ClientField::Clear() {
extra_act[i] = false; extra_act[i] = false;
pzone_act[i] = false; pzone_act[i] = false;
} }
for(auto cit = limbo_temp.begin(); cit != limbo_temp.end(); ++cit) for (auto& card : limbo_temp) {
delete *cit; delete card;
}
limbo_temp.clear(); limbo_temp.clear();
for(auto sit = overlay_cards.begin(); sit != overlay_cards.end(); ++sit) for (auto& card : overlay_cards) {
delete *sit; delete card;
}
overlay_cards.clear(); overlay_cards.clear();
extra_p_count[0] = 0; extra_p_count[0] = 0;
extra_p_count[1] = 0; extra_p_count[1] = 0;
...@@ -427,7 +429,8 @@ void ClientField::ClearChainSelect() { ...@@ -427,7 +429,8 @@ void ClientField::ClearChainSelect() {
conti_act = false; conti_act = false;
} }
// needs to be synchronized with EGET_SCROLL_BAR_CHANGED // needs to be synchronized with EGET_SCROLL_BAR_CHANGED
void ClientField::ShowSelectCard(bool buttonok, bool chain) { void ClientField::ShowSelectCard(bool buttonok, bool is_continuous) {
select_continuous = is_continuous;
if(cant_check_grave) { if(cant_check_grave) {
bool has_card_in_grave = false; bool has_card_in_grave = false;
for (auto& pcard : selectable_cards) { for (auto& pcard : selectable_cards) {
...@@ -454,7 +457,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) { ...@@ -454,7 +457,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
// image // image
if(selectable_cards[i]->code) if(selectable_cards[i]->code)
mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardSelect[i], selectable_cards[i]->code)); mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardSelect[i], selectable_cards[i]->code));
else if(conti_selecting) else if(select_continuous)
mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardSelect[i], selectable_cards[i]->chain_code)); mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardSelect[i], selectable_cards[i]->chain_code));
else else
mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i]->controler + 2]); mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i]->controler + 2]);
...@@ -464,7 +467,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) { ...@@ -464,7 +467,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
if(mainGame->dInfo.curMsg != MSG_SORT_CARD) { if(mainGame->dInfo.curMsg != MSG_SORT_CARD) {
// text // text
wchar_t formatBuffer[2048]; wchar_t formatBuffer[2048];
if(conti_selecting) if(select_continuous)
myswprintf(formatBuffer, L"%ls", dataManager.unknown_string); myswprintf(formatBuffer, L"%ls", dataManager.unknown_string);
else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE) else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE)
myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0)); myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0));
...@@ -482,7 +485,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) { ...@@ -482,7 +485,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
if (selectable_cards[i]->is_selected) if (selectable_cards[i]->is_selected)
mainGame->stCardPos[i]->setBackgroundColor(0xffffff00); mainGame->stCardPos[i]->setBackgroundColor(0xffffff00);
else { else {
if(conti_selecting) if(select_continuous)
mainGame->stCardPos[i]->setBackgroundColor(0xffffffff); mainGame->stCardPos[i]->setBackgroundColor(0xffffffff);
else if(selectable_cards[i]->location == LOCATION_OVERLAY) { else if(selectable_cards[i]->location == LOCATION_OVERLAY) {
if(selectable_cards[i]->owner != selectable_cards[i]->overlayTarget->controler) if(selectable_cards[i]->owner != selectable_cards[i]->overlayTarget->controler)
......
...@@ -88,14 +88,14 @@ public: ...@@ -88,14 +88,14 @@ public:
ChainInfo current_chain; ChainInfo current_chain;
bool last_chain{ false }; bool last_chain{ false };
bool deck_reversed{ false }; bool deck_reversed{ false };
bool conti_selecting{ false }; bool select_continuous{ false };
bool cant_check_grave{ false }; bool cant_check_grave{ false };
bool tag_surrender{ false }; bool tag_surrender{ false };
bool tag_teammate_surrender{ false }; bool tag_teammate_surrender{ false };
std::mt19937 rnd; std::mt19937 rnd;
ClientField(); ClientField();
~ClientField(); ~ClientField() override;
void Clear(); void Clear();
void Initial(int player, int deckc, int extrac, int sidec = 0); void Initial(int player, int deckc, int extrac, int sidec = 0);
void ResetSequence(std::vector<ClientCard*>& list, bool reset_height); void ResetSequence(std::vector<ClientCard*>& list, bool reset_height);
...@@ -107,7 +107,7 @@ public: ...@@ -107,7 +107,7 @@ public:
void ClearCommandFlag(); void ClearCommandFlag();
void ClearSelect(); void ClearSelect();
void ClearChainSelect(); void ClearChainSelect();
void ShowSelectCard(bool buttonok = false, bool chain = false); void ShowSelectCard(bool buttonok = false, bool is_continuous = false);
void ShowChainCard(); void ShowChainCard();
void ShowLocationCard(); void ShowLocationCard();
void ShowSelectOption(int select_hint = 0); void ShowSelectOption(int select_hint = 0);
......
...@@ -497,7 +497,7 @@ std::wstring DataManager::FormatAttribute(unsigned int attribute) const { ...@@ -497,7 +497,7 @@ std::wstring DataManager::FormatAttribute(unsigned int attribute) const {
if (attribute & (0x1U << i)) { if (attribute & (0x1U << i)) {
if (!buffer.empty()) if (!buffer.empty())
buffer.push_back(L'|'); buffer.push_back(L'|');
buffer.append(GetSysString(1010 + i)); buffer.append(GetSysString(STRING_ID_ATTRIBUTE + i));
} }
} }
if (buffer.empty()) if (buffer.empty())
...@@ -510,7 +510,7 @@ std::wstring DataManager::FormatRace(unsigned int race) const { ...@@ -510,7 +510,7 @@ std::wstring DataManager::FormatRace(unsigned int race) const {
if(race & (0x1U << i)) { if(race & (0x1U << i)) {
if (!buffer.empty()) if (!buffer.empty())
buffer.push_back(L'|'); buffer.push_back(L'|');
buffer.append(GetSysString(1020 + i)); buffer.append(GetSysString(STRING_ID_RACE + i));
} }
} }
if (buffer.empty()) if (buffer.empty())
...@@ -519,12 +519,11 @@ std::wstring DataManager::FormatRace(unsigned int race) const { ...@@ -519,12 +519,11 @@ std::wstring DataManager::FormatRace(unsigned int race) const {
} }
std::wstring DataManager::FormatType(unsigned int type) const { std::wstring DataManager::FormatType(unsigned int type) const {
std::wstring buffer; std::wstring buffer;
int i = 1050; for (int i = 0; i < TYPES_COUNT; ++i) {
for (unsigned filter = TYPE_MONSTER; filter <= TYPE_LINK; filter <<= 1, ++i) { if (type & (0x1U << i)) {
if (type & filter) {
if (!buffer.empty()) if (!buffer.empty())
buffer.push_back(L'|'); buffer.push_back(L'|');
buffer.append(GetSysString(i)); buffer.append(GetSysString(STRING_ID_TYPE + i));
} }
} }
if (buffer.empty()) if (buffer.empty())
......
...@@ -15,6 +15,7 @@ namespace irr { ...@@ -15,6 +15,7 @@ namespace irr {
} }
namespace ygo { namespace ygo {
constexpr int MAX_STRING_ID = 0x7ff; constexpr int MAX_STRING_ID = 0x7ff;
constexpr uint32_t MIN_CARD_ID = (uint32_t)(MAX_STRING_ID + 1) >> 4; constexpr uint32_t MIN_CARD_ID = (uint32_t)(MAX_STRING_ID + 1) >> 4;
constexpr uint32_t MAX_CARD_ID = 0x0fffffffU; constexpr uint32_t MAX_CARD_ID = 0x0fffffffU;
...@@ -125,6 +126,11 @@ public: ...@@ -125,6 +126,11 @@ public:
irr::io::IFileSystem* FileSystem{}; irr::io::IFileSystem* FileSystem{};
#endif #endif
static constexpr int STRING_ID_ATTRIBUTE = 1010;
static constexpr int STRING_ID_RACE = 1020;
static constexpr int STRING_ID_TYPE = 1050;
static constexpr int TYPES_COUNT = 27;
static unsigned char scriptBuffer[0x100000]; static unsigned char scriptBuffer[0x100000];
static uint32_t CardReader(uint32_t, card_data*); static uint32_t CardReader(uint32_t, card_data*);
static unsigned char* ScriptReaderEx(const char* script_name, int* slen); static unsigned char* ScriptReaderEx(const char* script_name, int* slen);
......
...@@ -25,20 +25,21 @@ ...@@ -25,20 +25,21 @@
#endif #endif
namespace ygo { namespace ygo {
constexpr int DECK_MAX_SIZE = YGOPRO_MAX_DECK;
constexpr int DECK_MIN_SIZE = YGOPRO_MIN_DECK; constexpr int DECK_MAX_SIZE = YGOPRO_MAX_DECK;
constexpr int EXTRA_MAX_SIZE = YGOPRO_MAX_EXTRA; constexpr int DECK_MIN_SIZE = YGOPRO_MIN_DECK;
constexpr int SIDE_MAX_SIZE = YGOPRO_MAX_SIDE; constexpr int EXTRA_MAX_SIZE = YGOPRO_MAX_EXTRA;
constexpr int PACK_MAX_SIZE = 1000; constexpr int SIDE_MAX_SIZE = YGOPRO_MAX_SIDE;
constexpr int PACK_MAX_SIZE = 1000;
constexpr int MAINC_MAX = 250; // the limit of card_state
constexpr int SIDEC_MAX = MAINC_MAX; constexpr int MAINC_MAX = 250; // the limit of card_state
constexpr int SIDEC_MAX = MAINC_MAX;
constexpr int DECK_CATEGORY_PACK = 0;
constexpr int DECK_CATEGORY_BOT = 1; constexpr int DECK_CATEGORY_PACK = 0;
constexpr int DECK_CATEGORY_NONE = 2; constexpr int DECK_CATEGORY_BOT = 1;
constexpr int DECK_CATEGORY_SEPARATOR = 3; constexpr int DECK_CATEGORY_NONE = 2;
constexpr int DECK_CATEGORY_CUSTOM = 4; constexpr int DECK_CATEGORY_SEPARATOR = 3;
constexpr int DECK_CATEGORY_CUSTOM = 4;
struct LFList { struct LFList {
unsigned int hash{}; unsigned int hash{};
......
...@@ -1171,7 +1171,6 @@ void Game::HideElement(irr::gui::IGUIElement * win, bool set_action) { ...@@ -1171,7 +1171,6 @@ void Game::HideElement(irr::gui::IGUIElement * win, bool set_action) {
if(win == wCardSelect) { if(win == wCardSelect) {
for(int i = 0; i < 5; ++i) for(int i = 0; i < 5; ++i)
btnCardSelect[i]->setDrawImage(false); btnCardSelect[i]->setDrawImage(false);
dField.conti_selecting = false;
stCardListTip->setVisible(false); stCardListTip->setVisible(false);
for(auto& pcard : dField.selectable_cards) for(auto& pcard : dField.selectable_cards)
dField.SetShowMark(pcard, false); dField.SetShowMark(pcard, false);
...@@ -1462,8 +1461,9 @@ void Game::DrawDeckBd() { ...@@ -1462,8 +1461,9 @@ void Game::DrawDeckBd() {
else else
myswprintf(adBuffer, L"%d/-", ptr->second.attack); myswprintf(adBuffer, L"%d/-", ptr->second.attack);
} }
myswprintf(textBuffer, L"%ls/%ls %ls%d", dataManager.FormatAttribute(ptr->second.attribute).c_str(), dataManager.FormatRace(ptr->second.race).c_str(), const auto& attribute = dataManager.FormatAttribute(ptr->second.attribute);
form, ptr->second.level); const auto& race = dataManager.FormatRace(ptr->second.race);
myswprintf(textBuffer, L"%ls/%ls %ls%d", attribute.c_str(), race.c_str(), form, ptr->second.level);
DrawShadowText(textFont, textBuffer, Resize(860, 187 + i * 66, 955, 207 + i * 66), Resize(1, 1, 0, 0)); DrawShadowText(textFont, textBuffer, Resize(860, 187 + i * 66, 955, 207 + i * 66), Resize(1, 1, 0, 0));
if(ptr->second.type & TYPE_PENDULUM) { if(ptr->second.type & TYPE_PENDULUM) {
myswprintf(scaleBuffer, L" %d/%d", ptr->second.lscale, ptr->second.rscale); myswprintf(scaleBuffer, L" %d/%d", ptr->second.lscale, ptr->second.rscale);
...@@ -1473,7 +1473,8 @@ void Game::DrawDeckBd() { ...@@ -1473,7 +1473,8 @@ void Game::DrawDeckBd() {
} else { } else {
myswprintf(textBuffer, L"%ls", dataManager.GetName(ptr->first)); myswprintf(textBuffer, L"%ls", dataManager.GetName(ptr->first));
DrawShadowText(textFont, textBuffer, Resize(860, 165 + i * 66, 955, 185 + i * 66), Resize(1, 1, 0, 0)); DrawShadowText(textFont, textBuffer, Resize(860, 165 + i * 66, 955, 185 + i * 66), Resize(1, 1, 0, 0));
myswprintf(textBuffer, L"%ls", dataManager.FormatType(ptr->second.type).c_str()); const auto& type = dataManager.FormatType(ptr->second.type);
myswprintf(textBuffer, L"%ls", type.c_str());
DrawShadowText(textFont, textBuffer, Resize(860, 187 + i * 66, 955, 207 + i * 66), Resize(1, 1, 0, 0)); DrawShadowText(textFont, textBuffer, Resize(860, 187 + i * 66, 955, 207 + i * 66), Resize(1, 1, 0, 0));
myswprintf(textBuffer, L"%ls", availBuffer); myswprintf(textBuffer, L"%ls", availBuffer);
DrawShadowText(textFont, textBuffer, Resize(860, 209 + i * 66, 955, 229 + i * 66), Resize(1, 1, 0, 0)); DrawShadowText(textFont, textBuffer, Resize(860, 209 + i * 66, 955, 229 + i * 66), Resize(1, 1, 0, 0));
......
...@@ -878,8 +878,11 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) { ...@@ -878,8 +878,11 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) {
prep += sizeof new_replay.pheader; prep += sizeof new_replay.pheader;
std::memcpy(new_replay.comp_data, prep, len - sizeof new_replay.pheader - 1); std::memcpy(new_replay.comp_data, prep, len - sizeof new_replay.pheader - 1);
new_replay.comp_size = len - sizeof new_replay.pheader - 1; new_replay.comp_size = len - sizeof new_replay.pheader - 1;
if(mainGame->actionParam) if (mainGame->actionParam) {
new_replay.SaveReplay(mainGame->ebRSName->getText()); bool save_result = new_replay.SaveReplay(mainGame->ebRSName->getText());
if (!save_result)
new_replay.SaveReplay(L"_LastReplay");
}
else else
new_replay.SaveReplay(L"_LastReplay"); new_replay.SaveReplay(L"_LastReplay");
} }
...@@ -1237,7 +1240,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) { ...@@ -1237,7 +1240,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
break; break;
} }
case HINT_RACE: { case HINT_RACE: {
myswprintf(textBuffer, dataManager.GetSysString(1511), dataManager.FormatRace(data).c_str()); const auto& race = dataManager.FormatRace(data);
myswprintf(textBuffer, dataManager.GetSysString(1511), race.c_str());
mainGame->AddLog(textBuffer); mainGame->AddLog(textBuffer);
mainGame->gMutex.lock(); mainGame->gMutex.lock();
mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, textBuffer); mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, textBuffer);
...@@ -1247,7 +1251,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) { ...@@ -1247,7 +1251,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
break; break;
} }
case HINT_ATTRIB: { case HINT_ATTRIB: {
myswprintf(textBuffer, dataManager.GetSysString(1511), dataManager.FormatAttribute(data).c_str()); const auto& attribute = dataManager.FormatAttribute(data);
myswprintf(textBuffer, dataManager.GetSysString(1511), attribute.c_str());
mainGame->AddLog(textBuffer); mainGame->AddLog(textBuffer);
mainGame->gMutex.lock(); mainGame->gMutex.lock();
mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, textBuffer); mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, textBuffer);
......
...@@ -411,7 +411,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -411,7 +411,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
} }
} else { } else {
selectable_cards.clear(); selectable_cards.clear();
conti_selecting = false; bool is_continuous = false;
switch(command_location) { switch(command_location) {
case LOCATION_DECK: { case LOCATION_DECK: {
for(size_t i = 0; i < deck[command_controler].size(); ++i) for(size_t i = 0; i < deck[command_controler].size(); ++i)
...@@ -438,15 +438,15 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -438,15 +438,15 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break; break;
} }
case POSITION_HINT: { case POSITION_HINT: {
is_continuous = true;
selectable_cards = conti_cards; selectable_cards = conti_cards;
std::sort(selectable_cards.begin(), selectable_cards.end()); std::sort(selectable_cards.begin(), selectable_cards.end());
auto eit = std::unique(selectable_cards.begin(), selectable_cards.end()); auto eit = std::unique(selectable_cards.begin(), selectable_cards.end());
selectable_cards.erase(eit, selectable_cards.end()); selectable_cards.erase(eit, selectable_cards.end());
conti_selecting = true;
break; break;
} }
} }
if(!conti_selecting) { if (!is_continuous) {
mainGame->wCardSelect->setText(dataManager.GetSysString(566)); mainGame->wCardSelect->setText(dataManager.GetSysString(566));
list_command = COMMAND_ACTIVATE; list_command = COMMAND_ACTIVATE;
} else { } else {
...@@ -454,7 +454,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -454,7 +454,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
list_command = COMMAND_OPERATION; list_command = COMMAND_OPERATION;
} }
std::sort(selectable_cards.begin(), selectable_cards.end(), ClientCard::client_card_sort); std::sort(selectable_cards.begin(), selectable_cards.end(), ClientCard::client_card_sort);
ShowSelectCard(true, true); ShowSelectCard(true, is_continuous);
} }
break; break;
} }
...@@ -907,7 +907,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -907,7 +907,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
// image // image
if(selectable_cards[i + pos]->code) if(selectable_cards[i + pos]->code)
mainGame->btnCardSelect[i]->setImage(imageManager.GetTexture(selectable_cards[i + pos]->code)); mainGame->btnCardSelect[i]->setImage(imageManager.GetTexture(selectable_cards[i + pos]->code));
else if(conti_selecting) else if(select_continuous)
mainGame->btnCardSelect[i]->setImage(imageManager.GetTexture(selectable_cards[i + pos]->chain_code)); mainGame->btnCardSelect[i]->setImage(imageManager.GetTexture(selectable_cards[i + pos]->chain_code));
else else
mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i + pos]->controler + 2]); mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i + pos]->controler + 2]);
...@@ -920,7 +920,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -920,7 +920,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
else else
myswprintf(formatBuffer, L""); myswprintf(formatBuffer, L"");
} else { } else {
if(conti_selecting) if(select_continuous)
myswprintf(formatBuffer, L"%ls", dataManager.unknown_string); myswprintf(formatBuffer, L"%ls", dataManager.unknown_string);
else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE) else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE)
myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0)); myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0));
...@@ -936,7 +936,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -936,7 +936,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
} }
mainGame->stCardPos[i]->setText(formatBuffer); mainGame->stCardPos[i]->setText(formatBuffer);
// color // color
if(conti_selecting) if(select_continuous)
mainGame->stCardPos[i]->setBackgroundColor(0xffffffff); mainGame->stCardPos[i]->setBackgroundColor(0xffffffff);
else if(selectable_cards[i + pos]->location == LOCATION_OVERLAY) { else if(selectable_cards[i + pos]->location == LOCATION_OVERLAY) {
if(selectable_cards[i + pos]->owner != selectable_cards[i + pos]->overlayTarget->controler) if(selectable_cards[i + pos]->owner != selectable_cards[i + pos]->overlayTarget->controler)
...@@ -1614,7 +1614,9 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -1614,7 +1614,9 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
myswprintf(formatBuffer, L"\nLINK-%d", mcard->link); myswprintf(formatBuffer, L"\nLINK-%d", mcard->link);
str.append(formatBuffer); str.append(formatBuffer);
} }
myswprintf(formatBuffer, L" %ls/%ls", dataManager.FormatRace(mcard->race).c_str(), dataManager.FormatAttribute(mcard->attribute).c_str()); const auto& race = dataManager.FormatRace(mcard->race);
const auto& attribute = dataManager.FormatAttribute(mcard->attribute);
myswprintf(formatBuffer, L" %ls/%ls", race.c_str(), attribute.c_str());
str.append(formatBuffer); str.append(formatBuffer);
if(mcard->location == LOCATION_HAND && (mcard->type & TYPE_PENDULUM)) { if(mcard->location == LOCATION_HAND && (mcard->type & TYPE_PENDULUM)) {
myswprintf(formatBuffer, L"\n%d/%d", mcard->lscale, mcard->rscale); myswprintf(formatBuffer, L"\n%d/%d", mcard->lscale, mcard->rscale);
...@@ -1639,10 +1641,14 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -1639,10 +1641,14 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
myswprintf(formatBuffer, L"\n%ls%d", dataManager.GetSysString(211), mcard->chValue); myswprintf(formatBuffer, L"\n%ls%d", dataManager.GetSysString(211), mcard->chValue);
else if(mcard->cHint == CHINT_CARD) else if(mcard->cHint == CHINT_CARD)
myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(212), dataManager.GetName(mcard->chValue)); myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(212), dataManager.GetName(mcard->chValue));
else if(mcard->cHint == CHINT_RACE) else if(mcard->cHint == CHINT_RACE) {
myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(213), dataManager.FormatRace(mcard->chValue).c_str()); const auto& race = dataManager.FormatRace(mcard->chValue);
else if(mcard->cHint == CHINT_ATTRIBUTE) myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(213), race.c_str());
myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(214), dataManager.FormatAttribute(mcard->chValue).c_str()); }
else if(mcard->cHint == CHINT_ATTRIBUTE) {
const auto& attribute = dataManager.FormatAttribute(mcard->chValue);
myswprintf(formatBuffer, L"\n%ls%ls", dataManager.GetSysString(214), attribute.c_str());
}
else if(mcard->cHint == CHINT_NUMBER) else if(mcard->cHint == CHINT_NUMBER)
myswprintf(formatBuffer, L"\n%ls%d", dataManager.GetSysString(215), mcard->chValue); myswprintf(formatBuffer, L"\n%ls%d", dataManager.GetSysString(215), mcard->chValue);
str.append(formatBuffer); str.append(formatBuffer);
......
...@@ -273,7 +273,7 @@ bool Game::Initialize() { ...@@ -273,7 +273,7 @@ bool Game::Initialize() {
SetWindowsIcon(); SetWindowsIcon();
//main menu //main menu
wchar_t strbuf[256]; wchar_t strbuf[256];
myswprintf(strbuf, L"KoishiPro %X.0%X.%X Memes", (PRO_VERSION & 0xf000U) >> 12, (PRO_VERSION & 0x0ff0U) >> 4, PRO_VERSION & 0x000fU); myswprintf(strbuf, L"KoishiPro %X.0%X.%X EatemUp", (PRO_VERSION & 0xf000U) >> 12, (PRO_VERSION & 0x0ff0U) >> 4, PRO_VERSION & 0x000fU);
wMainMenu = env->addWindow(irr::core::rect<irr::s32>(370, 200, 650, 415), false, strbuf); wMainMenu = env->addWindow(irr::core::rect<irr::s32>(370, 200, 650, 415), false, strbuf);
wMainMenu->getCloseButton()->setVisible(false); wMainMenu->getCloseButton()->setVisible(false);
btnLanMode = env->addButton(irr::core::rect<irr::s32>(10, 30, 270, 60), wMainMenu, BUTTON_LAN_MODE, dataManager.GetSysString(1200)); btnLanMode = env->addButton(irr::core::rect<irr::s32>(10, 30, 270, 60), wMainMenu, BUTTON_LAN_MODE, dataManager.GetSysString(1200));
...@@ -720,16 +720,16 @@ bool Game::Initialize() { ...@@ -720,16 +720,16 @@ bool Game::Initialize() {
wANAttribute = env->addWindow(irr::core::rect<irr::s32>(500, 200, 830, 285), false, dataManager.GetSysString(562)); wANAttribute = env->addWindow(irr::core::rect<irr::s32>(500, 200, 830, 285), false, dataManager.GetSysString(562));
wANAttribute->getCloseButton()->setVisible(false); wANAttribute->getCloseButton()->setVisible(false);
wANAttribute->setVisible(false); wANAttribute->setVisible(false);
for(int filter = 0x1, i = 0; i < 7; filter <<= 1, ++i) for (int i = 0; i < ATTRIBUTES_COUNT; ++i)
chkAttribute[i] = env->addCheckBox(false, irr::core::rect<irr::s32>(10 + (i % 4) * 80, 25 + (i / 4) * 25, 90 + (i % 4) * 80, 50 + (i / 4) * 25), chkAttribute[i] = env->addCheckBox(false, irr::core::rect<irr::s32>(10 + (i % 4) * 80, 25 + (i / 4) * 25, 90 + (i % 4) * 80, 50 + (i / 4) * 25),
wANAttribute, CHECK_ATTRIBUTE, dataManager.FormatAttribute(filter).c_str()); wANAttribute, CHECK_ATTRIBUTE, dataManager.GetSysString(DataManager::STRING_ID_ATTRIBUTE + i));
//announce race //announce race
wANRace = env->addWindow(irr::core::rect<irr::s32>(480, 200, 850, 410), false, dataManager.GetSysString(563)); wANRace = env->addWindow(irr::core::rect<irr::s32>(480, 200, 850, 410), false, dataManager.GetSysString(563));
wANRace->getCloseButton()->setVisible(false); wANRace->getCloseButton()->setVisible(false);
wANRace->setVisible(false); wANRace->setVisible(false);
for(int filter = 0x1, i = 0; i < RACES_COUNT; filter <<= 1, ++i) for (int i = 0; i < RACES_COUNT; ++i)
chkRace[i] = env->addCheckBox(false, irr::core::rect<irr::s32>(10 + (i % 4) * 90, 25 + (i / 4) * 25, 100 + (i % 4) * 90, 50 + (i / 4) * 25), chkRace[i] = env->addCheckBox(false, irr::core::rect<irr::s32>(10 + (i % 4) * 90, 25 + (i / 4) * 25, 100 + (i % 4) * 90, 50 + (i / 4) * 25),
wANRace, CHECK_RACE, dataManager.FormatRace(filter).c_str()); wANRace, CHECK_RACE, dataManager.GetSysString(DataManager::STRING_ID_RACE + i));
//selection hint //selection hint
stHintMsg = env->addStaticText(L"", irr::core::rect<irr::s32>(500, 60, 820, 90), true, false, 0, -1, false); stHintMsg = env->addStaticText(L"", irr::core::rect<irr::s32>(500, 60, 820, 90), true, false, 0, -1, false);
stHintMsg->setBackgroundColor(0xc0ffffff); stHintMsg->setBackgroundColor(0xc0ffffff);
...@@ -874,14 +874,14 @@ bool Game::Initialize() { ...@@ -874,14 +874,14 @@ bool Game::Initialize() {
cbAttribute = env->addComboBox(irr::core::rect<irr::s32>(60, 20 + 50 / 6, 195, 40 + 50 / 6), wFilter, COMBOBOX_ATTRIBUTE); cbAttribute = env->addComboBox(irr::core::rect<irr::s32>(60, 20 + 50 / 6, 195, 40 + 50 / 6), wFilter, COMBOBOX_ATTRIBUTE);
cbAttribute->setMaxSelectionRows(10); cbAttribute->setMaxSelectionRows(10);
cbAttribute->addItem(dataManager.GetSysString(1310), 0); cbAttribute->addItem(dataManager.GetSysString(1310), 0);
for (int filter = 0; filter < ATTRIBUTES_COUNT; ++filter) for (int i = 0; i < ATTRIBUTES_COUNT; ++i)
cbAttribute->addItem(dataManager.FormatAttribute(0x1U << filter).c_str(), 0x1U << filter); cbAttribute->addItem(dataManager.GetSysString(DataManager::STRING_ID_ATTRIBUTE + i), 0x1U << i);
stRace = env->addStaticText(dataManager.GetSysString(1321), irr::core::rect<irr::s32>(10, 42 + 75 / 6, 70, 62 + 75 / 6), false, false, wFilter); stRace = env->addStaticText(dataManager.GetSysString(1321), irr::core::rect<irr::s32>(10, 42 + 75 / 6, 70, 62 + 75 / 6), false, false, wFilter);
cbRace = env->addComboBox(irr::core::rect<irr::s32>(60, 40 + 75 / 6, 195, 60 + 75 / 6), wFilter, COMBOBOX_RACE); cbRace = env->addComboBox(irr::core::rect<irr::s32>(60, 40 + 75 / 6, 195, 60 + 75 / 6), wFilter, COMBOBOX_RACE);
cbRace->setMaxSelectionRows(10); cbRace->setMaxSelectionRows(10);
cbRace->addItem(dataManager.GetSysString(1310), 0); cbRace->addItem(dataManager.GetSysString(1310), 0);
for (int filter = 0; filter < RACES_COUNT; ++filter) for (int i = 0; i < RACES_COUNT; ++i)
cbRace->addItem(dataManager.FormatRace(0x1U << filter).c_str(), 0x1U << filter); cbRace->addItem(dataManager.GetSysString(DataManager::STRING_ID_RACE + i), 0x1U << i);
stAttack = env->addStaticText(dataManager.GetSysString(1322), irr::core::rect<irr::s32>(205, 22 + 50 / 6, 280, 42 + 50 / 6), false, false, wFilter); stAttack = env->addStaticText(dataManager.GetSysString(1322), irr::core::rect<irr::s32>(205, 22 + 50 / 6, 280, 42 + 50 / 6), false, false, wFilter);
ebAttack = env->addEditBox(L"", irr::core::rect<irr::s32>(260, 20 + 50 / 6, 340, 40 + 50 / 6), true, wFilter, EDITBOX_INPUTS); ebAttack = env->addEditBox(L"", irr::core::rect<irr::s32>(260, 20 + 50 / 6, 340, 40 + 50 / 6), true, wFilter, EDITBOX_INPUTS);
ebAttack->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER); ebAttack->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
...@@ -1259,41 +1259,48 @@ void Game::InitStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cWidth, i ...@@ -1259,41 +1259,48 @@ void Game::InitStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cWidth, i
scrCardText->setPos(0); scrCardText->setPos(0);
} }
std::wstring Game::SetStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cWidth, irr::gui::CGUITTFont* font, const wchar_t* text, irr::u32 pos) { std::wstring Game::SetStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cWidth, irr::gui::CGUITTFont* font, const wchar_t* text, irr::u32 pos) {
int pbuffer = 0; size_t pbuffer = 0;
irr::u32 _width = 0, _height = 0; irr::u32 _width = 0, _height = 0;
wchar_t prev = 0; wchar_t prev = 0;
wchar_t strBuffer[4096]; wchar_t strBuffer[4096]{};
std::wstring ret; constexpr size_t buffer_len = sizeof strBuffer / sizeof strBuffer[0] - 1;
const size_t text_len = std::wcslen(text);
for(size_t i = 0; text[i] != 0 && i < std::wcslen(text); ++i) { for(size_t i = 0; i < text_len ; ++i) {
if (pbuffer >= buffer_len)
break;
wchar_t c = text[i]; wchar_t c = text[i];
irr::u32 w = font->getCharDimension(c).Width + font->getKerningWidth(c, prev); irr::u32 w = font->getCharDimension(c).Width + font->getKerningWidth(c, prev);
prev = c; prev = c;
if(text[i] == L'\r') { if (c == L'\r') {
continue; continue;
} else if(text[i] == L'\n') { }
if (c == L'\n') {
strBuffer[pbuffer++] = L'\n'; strBuffer[pbuffer++] = L'\n';
_width = 0; _width = 0;
_height++; _height++;
prev = 0; prev = 0;
if(_height == pos) if (_height == pos)
pbuffer = 0; pbuffer = 0;
continue; continue;
} else if(_width > 0 && _width + w > cWidth) { }
if (_width > 0 && _width + w > cWidth) {
strBuffer[pbuffer++] = L'\n'; strBuffer[pbuffer++] = L'\n';
_width = 0; _width = 0;
_height++; _height++;
prev = 0; prev = 0;
if(_height == pos) if (_height == pos)
pbuffer = 0; pbuffer = 0;
} }
if (pbuffer >= buffer_len)
break;
_width += w; _width += w;
strBuffer[pbuffer++] = c; strBuffer[pbuffer++] = c;
} }
strBuffer[pbuffer] = 0; strBuffer[pbuffer] = 0;
if(pControl) pControl->setText(strBuffer); if (pControl)
ret.assign(strBuffer); pControl->setText(strBuffer);
return ret; return std::wstring(strBuffer);
} }
#endif //YGOPRO_SERVER_MODE #endif //YGOPRO_SERVER_MODE
void Game::LoadExpansions(const wchar_t* expansions_path) { void Game::LoadExpansions(const wchar_t* expansions_path) {
...@@ -2030,7 +2037,8 @@ void Game::ShowCardInfo(int code, bool resize) { ...@@ -2030,7 +2037,8 @@ void Game::ShowCardInfo(int code, bool resize) {
} }
if (target->second.setcode[0]) { if (target->second.setcode[0]) {
offset = 23;// *yScale; offset = 23;// *yScale;
myswprintf(formatBuffer, L"%ls%ls", dataManager.GetSysString(1329), dataManager.FormatSetName(target->second.setcode).c_str()); const auto& setname = dataManager.FormatSetName(target->second.setcode);
myswprintf(formatBuffer, L"%ls%ls", dataManager.GetSysString(1329), setname.c_str());
stSetName->setText(formatBuffer); stSetName->setText(formatBuffer);
} }
else else
...@@ -2041,7 +2049,10 @@ void Game::ShowCardInfo(int code, bool resize) { ...@@ -2041,7 +2049,10 @@ void Game::ShowCardInfo(int code, bool resize) {
} }
if(is_valid && cit->second.type & TYPE_MONSTER) { if(is_valid && cit->second.type & TYPE_MONSTER) {
auto& cd = cit->second; auto& cd = cit->second;
myswprintf(formatBuffer, L"[%ls] %ls/%ls", dataManager.FormatType(cd.type).c_str(), dataManager.FormatRace(cd.race).c_str(), dataManager.FormatAttribute(cd.attribute).c_str()); const auto& type = dataManager.FormatType(cd.type);
const auto& race = dataManager.FormatRace(cd.race);
const auto& attribute = dataManager.FormatAttribute(cd.attribute);
myswprintf(formatBuffer, L"[%ls] %ls/%ls", type.c_str(), race.c_str(), attribute.c_str());
stInfo->setText(formatBuffer); stInfo->setText(formatBuffer);
int offset_info = 0; int offset_info = 0;
irr::core::dimension2d<unsigned int> dtxt = guiFont->getDimension(formatBuffer); irr::core::dimension2d<unsigned int> dtxt = guiFont->getDimension(formatBuffer);
...@@ -2063,10 +2074,11 @@ void Game::ShowCardInfo(int code, bool resize) { ...@@ -2063,10 +2074,11 @@ void Game::ShowCardInfo(int code, bool resize) {
myswprintf(adBuffer, L"%d/%d", cd.attack, cd.defense); myswprintf(adBuffer, L"%d/%d", cd.attack, cd.defense);
} else { } else {
form = L"LINK-"; form = L"LINK-";
const auto& link_marker = dataManager.FormatLinkMarker(cd.link_marker);
if(cd.attack < 0) if(cd.attack < 0)
myswprintf(adBuffer, L"?/- %ls", dataManager.FormatLinkMarker(cd.link_marker).c_str()); myswprintf(adBuffer, L"?/- %ls", link_marker.c_str());
else else
myswprintf(adBuffer, L"%d/- %ls", cd.attack, dataManager.FormatLinkMarker(cd.link_marker).c_str()); myswprintf(adBuffer, L"%d/- %ls", cd.attack, link_marker.c_str());
} }
if(cd.type & TYPE_PENDULUM) { if(cd.type & TYPE_PENDULUM) {
myswprintf(scaleBuffer, L" %d/%d", cd.lscale, cd.rscale); myswprintf(scaleBuffer, L" %d/%d", cd.lscale, cd.rscale);
...@@ -2084,8 +2096,10 @@ void Game::ShowCardInfo(int code, bool resize) { ...@@ -2084,8 +2096,10 @@ void Game::ShowCardInfo(int code, bool resize) {
scrCardText->setRelativePosition(irr::core::rect<irr::s32>(287 * xScale - 20, (83 + offset_arrows) + offset, 287 * xScale, 324 * yScale)); scrCardText->setRelativePosition(irr::core::rect<irr::s32>(287 * xScale - 20, (83 + offset_arrows) + offset, 287 * xScale, 324 * yScale));
} }
else { else {
if (is_valid) if (is_valid) {
myswprintf(formatBuffer, L"[%ls]", dataManager.FormatType(cit->second.type).c_str()); const auto& type = dataManager.FormatType(cit->second.type);
myswprintf(formatBuffer, L"[%ls]", type.c_str());
}
else else
myswprintf(formatBuffer, L"[%ls]", dataManager.unknown_string); myswprintf(formatBuffer, L"[%ls]", dataManager.unknown_string);
stInfo->setText(formatBuffer); stInfo->setText(formatBuffer);
......
...@@ -28,15 +28,15 @@ ...@@ -28,15 +28,15 @@
#include <functional> #include <functional>
#ifndef YGOPRO_DEFAULT_DUEL_RULE #ifndef YGOPRO_DEFAULT_DUEL_RULE
#define YGOPRO_DEFAULT_DUEL_RULE 5 #define YGOPRO_DEFAULT_DUEL_RULE CURRENT_RULE
#endif #endif
#define DEFAULT_DUEL_RULE YGOPRO_DEFAULT_DUEL_RULE namespace ygo {
constexpr int DEFAULT_DUEL_RULE = YGOPRO_DEFAULT_DUEL_RULE;
constexpr int CONFIG_LINE_SIZE = 1024; constexpr int CONFIG_LINE_SIZE = 1024;
constexpr int TEXT_LINE_SIZE = 256; constexpr int TEXT_LINE_SIZE = 256;
namespace ygo {
template<size_t N> template<size_t N>
bool IsExtension(const wchar_t* filename, const wchar_t(&extension)[N]) { bool IsExtension(const wchar_t* filename, const wchar_t(&extension)[N]) {
auto flen = std::wcslen(filename); auto flen = std::wcslen(filename);
......
...@@ -14,8 +14,9 @@ ...@@ -14,8 +14,9 @@
#define check_trivially_copyable(T) static_assert(std::is_trivially_copyable<T>::value == true && std::is_standard_layout<T>::value == true, "not trivially copyable") #define check_trivially_copyable(T) static_assert(std::is_trivially_copyable<T>::value == true && std::is_standard_layout<T>::value == true, "not trivially copyable")
namespace ygo { namespace ygo {
constexpr int SIZE_NETWORK_BUFFER = 0x20000;
constexpr int MAX_DATA_SIZE = UINT16_MAX - 1; constexpr int SIZE_NETWORK_BUFFER = 0x20000;
constexpr int MAX_DATA_SIZE = UINT16_MAX - 1;
struct HostInfo { struct HostInfo {
uint32_t lflist{}; uint32_t lflist{};
......
...@@ -98,24 +98,30 @@ void Replay::EndRecord() { ...@@ -98,24 +98,30 @@ void Replay::EndRecord() {
} }
is_recording = false; is_recording = false;
} }
void Replay::SaveReplay(const wchar_t* name) { bool Replay::SaveReplay(const wchar_t* base_name) {
if(!FileSystem::IsDirExists(L"./replay") && !FileSystem::MakeDir(L"./replay")) if(!FileSystem::IsDirExists(L"./replay") && !FileSystem::MakeDir(L"./replay"))
return; return false;
wchar_t fname[256]; wchar_t filename[256]{};
myswprintf(fname, L"./replay/%ls.yrp", name); wchar_t path[256]{};
FILE* rfp = mywfopen(fname, "wb"); BufferIO::CopyWideString(base_name, filename);
FileSystem::SafeFileName(filename);
if (myswprintf(path, L"./replay/%ls.yrp", filename) <= 0)
return false;
FILE* rfp = mywfopen(path, "wb");
if(!rfp) if(!rfp)
return; return false;
std::fwrite(&pheader, sizeof pheader, 1, rfp); std::fwrite(&pheader, sizeof pheader, 1, rfp);
std::fwrite(comp_data, comp_size, 1, rfp); std::fwrite(comp_data, comp_size, 1, rfp);
std::fclose(rfp); std::fclose(rfp);
return true;
} }
#ifndef YGOPRO_SERVER_MODE #ifndef YGOPRO_SERVER_MODE
bool Replay::OpenReplay(const wchar_t* name) { bool Replay::OpenReplay(const wchar_t* name) {
FILE* rfp = mywfopen(name, "rb"); FILE* rfp = mywfopen(name, "rb");
if(!rfp) { if(!rfp) {
wchar_t fname[256]; wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name); if (myswprintf(fname, L"./replay/%ls", name) <= 0)
return false;
rfp = mywfopen(fname, "rb"); rfp = mywfopen(fname, "rb");
} }
if(!rfp) if(!rfp)
...@@ -167,19 +173,28 @@ bool Replay::OpenReplay(const wchar_t* name) { ...@@ -167,19 +173,28 @@ bool Replay::OpenReplay(const wchar_t* name) {
return true; return true;
} }
bool Replay::DeleteReplay(const wchar_t* name) { bool Replay::DeleteReplay(const wchar_t* name) {
if (std::wcschr(name, L'/') || std::wcschr(name, L'\\'))
return false;
wchar_t fname[256]; wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name); if(myswprintf(fname, L"./replay/%ls", name) <= 0)
return false;
return FileSystem::RemoveFile(fname); return FileSystem::RemoveFile(fname);
} }
bool Replay::RenameReplay(const wchar_t* oldname, const wchar_t* newname) { bool Replay::RenameReplay(const wchar_t* oldname, const wchar_t* newname) {
wchar_t oldfname[256]; wchar_t old_path[256];
wchar_t newfname[256]; wchar_t new_path[256];
myswprintf(oldfname, L"./replay/%ls", oldname); if (std::wcschr(oldname, L'/') || std::wcschr(oldname, L'\\'))
myswprintf(newfname, L"./replay/%ls", newname); return false;
if (std::wcschr(newname, L'/') || std::wcschr(newname, L'\\'))
return false;
if (myswprintf(old_path, L"./replay/%ls", oldname) <= 0)
return false;
if (myswprintf(new_path, L"./replay/%ls", newname) <= 0)
return false;
char oldfilefn[1024]; char oldfilefn[1024];
char newfilefn[1024]; char newfilefn[1024];
BufferIO::EncodeUTF8(oldfname, oldfilefn); BufferIO::EncodeUTF8(old_path, oldfilefn);
BufferIO::EncodeUTF8(newfname, newfilefn); BufferIO::EncodeUTF8(new_path, newfilefn);
int result = std::rename(oldfilefn, newfilefn); int result = std::rename(oldfilefn, newfilefn);
return result == 0; return result == 0;
} }
......
...@@ -74,7 +74,7 @@ public: ...@@ -74,7 +74,7 @@ public:
void WriteInt32(int32_t data, bool flush = true); void WriteInt32(int32_t data, bool flush = true);
void Flush(); void Flush();
void EndRecord(); void EndRecord();
void SaveReplay(const wchar_t* name); bool SaveReplay(const wchar_t* base_name);
// play // play
static bool DeleteReplay(const wchar_t* name); static bool DeleteReplay(const wchar_t* name);
......
Subproject commit d15a8ef70c54e3cfdbda2cf82e0164ca79d23f2d Subproject commit 2a8284cd1635331257262cab8c7d852f5237a428
Subproject commit 6b920a4f75575c884139779d83d64eaad9d04301 Subproject commit c26a7cec206cd1de8ad9fdb6db8cc228a9df2d17
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