Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Fluorohydride/ygopro
Browse files Browse the repository at this point in the history
  • Loading branch information
mercury233 committed Nov 18, 2018
2 parents 38385e5 + 83ad622 commit 17cdeb8
Show file tree
Hide file tree
Showing 21 changed files with 432 additions and 353 deletions.
18 changes: 12 additions & 6 deletions gframe/client_card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ClientCard::ClientCard() {
is_showtarget = false;
is_showchaintarget = false;
is_highlighting = false;
is_disabled = false;
status = 0;
is_reversed = false;
cmdFlag = 0;
code = 0;
Expand Down Expand Up @@ -125,6 +125,8 @@ void ClientCard::UpdateInfo(char* buf) {
base_defense = BufferIO::ReadInt32(buf);
if(flag & QUERY_REASON)
reason = BufferIO::ReadInt32(buf);
if(flag & QUERY_REASON_CARD)
buf += 4;
if(flag & QUERY_EQUIP_CARD) {
int c = BufferIO::ReadInt8(buf);
int l = BufferIO::ReadInt8(buf);
Expand Down Expand Up @@ -162,10 +164,8 @@ void ClientCard::UpdateInfo(char* buf) {
}
if(flag & QUERY_OWNER)
owner = BufferIO::ReadInt32(buf);
if(flag & QUERY_IS_DISABLED)
is_disabled = BufferIO::ReadInt32(buf);
if(flag & QUERY_IS_PUBLIC)
is_public = BufferIO::ReadInt32(buf);
if(flag & QUERY_STATUS)
status = BufferIO::ReadInt32(buf);
if(flag & QUERY_LSCALE) {
lscale = BufferIO::ReadInt32(buf);
myswprintf(lscstring, L"%d", lscale);
Expand Down Expand Up @@ -210,8 +210,14 @@ bool ClientCard::client_card_sort(ClientCard* c1, ClientCard* c2) {
return c1->overlayTarget->sequence < c2->overlayTarget->sequence;
else return c1->sequence < c2->sequence;
else {
if(c1->location & 0x71)
if(c1->location & (LOCATION_DECK | LOCATION_GRAVE | LOCATION_REMOVED | LOCATION_EXTRA)) {
for(size_t i = 0; i < mainGame->dField.chains.size(); ++i) {
auto chit = mainGame->dField.chains[i];
if(c1 == chit.chain_card || chit.target.find(c1) != chit.target.end())
return true;
}
return c1->sequence > c2->sequence;
}
else
return c1->sequence < c2->sequence;
}
Expand Down
3 changes: 1 addition & 2 deletions gframe/client_card.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ class ClientCard {
u8 location;
u8 sequence;
u8 position;
u8 is_disabled;
u8 is_public;
u32 status;
u8 cHint;
u32 chValue;
u32 opParam;
Expand Down
1 change: 1 addition & 0 deletions gframe/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
#include <memory.h>
#include <time.h>
#include "bufferio.h"
#include "myfilesystem.h"
#include "mymutex.h"
#include "mysignal.h"
#include "mythread.h"
Expand Down
79 changes: 61 additions & 18 deletions gframe/deck_con.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
switch(id) {
case BUTTON_CLEAR_DECK: {
mainGame->gMutex.Lock();
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)dataManager.GetSysString(1339));
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, dataManager.GetSysString(1339));
mainGame->PopupElement(mainGame->wQuery);
mainGame->gMutex.Unlock();
prev_operation = id;
Expand Down Expand Up @@ -185,7 +185,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
mainGame->gMutex.Lock();
wchar_t textBuffer[256];
myswprintf(textBuffer, L"%ls\n%ls", mainGame->cbDBDecks->getItem(sel), dataManager.GetSysString(1337));
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)textBuffer);
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, textBuffer);
mainGame->PopupElement(mainGame->wQuery);
mainGame->gMutex.Unlock();
prev_operation = id;
Expand All @@ -195,7 +195,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
case BUTTON_LEAVE_GAME: {
if(is_modified && !mainGame->chkIgnoreDeckChanges->isChecked()) {
mainGame->gMutex.Lock();
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)dataManager.GetSysString(1356));
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, dataManager.GetSysString(1356));
mainGame->PopupElement(mainGame->wQuery);
mainGame->gMutex.Unlock();
prev_operation = id;
Expand Down Expand Up @@ -362,7 +362,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
case COMBOBOX_DBDECKS: {
if(is_modified && !mainGame->chkIgnoreDeckChanges->isChecked()) {
mainGame->gMutex.Lock();
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)dataManager.GetSysString(1356));
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, dataManager.GetSysString(1356));
mainGame->PopupElement(mainGame->wQuery);
mainGame->gMutex.Unlock();
prev_operation = id;
Expand Down Expand Up @@ -776,6 +776,34 @@ void DeckBuilder::StartFilter() {
void DeckBuilder::FilterCards() {
results.clear();
const wchar_t* pstr = mainGame->ebCardName->getText();
std::wstring str = std::wstring(pstr);
std::vector<std::wstring> query_elements;
std::vector<std::vector<std::wstring>::iterator> query_elements_track;
size_t element_start = 0;
while(mainGame->gameConf.search_multiple_keywords) {
size_t element_end = str.find_first_of(mainGame->gameConf.search_multiple_keywords == 1 ? L' ' : L'+', element_start);
if(element_end == std::wstring::npos)
break;
size_t length = element_end - element_start;
if(length > 0) {
query_elements.push_back(str.substr(element_start, length));
element_start = element_end + 1;
} else
element_start++;
}
query_elements.push_back(str.substr(element_start));
std::unordered_map<std::wstring, unsigned int> set_code_map;
for(auto elements_iterator = query_elements.begin(); elements_iterator != query_elements.end(); elements_iterator++) {
const wchar_t* element_pointer = elements_iterator->c_str();
if(element_pointer[0] == L'@')
set_code_map[*elements_iterator] = dataManager.GetSetCode(&element_pointer[1]);
else
set_code_map[*elements_iterator] = dataManager.GetSetCode(&element_pointer[0]);
if(element_pointer[0] == 0 || (element_pointer[0] == L'$' && element_pointer[1] == 0) || (element_pointer[0] == L'@' && element_pointer[1] == 0))
query_elements_track.push_back(elements_iterator);
}
for(auto elements_track_iterator = query_elements_track.begin(); elements_track_iterator != query_elements_track.end(); elements_track_iterator++)
query_elements.erase(*elements_track_iterator);
unsigned int set_code = 0;
if(pstr[0] == L'@')
set_code = dataManager.GetSetCode(&pstr[1]);
Expand Down Expand Up @@ -856,24 +884,39 @@ void DeckBuilder::FilterCards() {
if(filter_lm == 7 && data.ot != 4)
continue;
}
if(pstr) {
if(pstr[0] == L'$') {
if(!CardNameContains(text.name.c_str(), &pstr[1]))
continue;
} else if(pstr[0] == L'@' && set_code) {
if(!check_set_code(data, set_code)) continue;
bool is_target = true;
for (auto elements_iterator = query_elements.begin(); elements_iterator != query_elements.end(); elements_iterator++) {
const wchar_t* element_pointer = elements_iterator->c_str();
if (element_pointer[0] == L'$') {
if(!CardNameContains(text.name.c_str(), &element_pointer[1])){
is_target = false;
break;
}
}
else if (element_pointer[0] == L'@' && set_code_map[*elements_iterator]) {
if(!check_set_code(data, set_code_map[*elements_iterator])) {
is_target = false;
break;
}
} else {
int trycode = BufferIO::GetVal(pstr);
int trycode = BufferIO::GetVal(elements_iterator->c_str());
bool tryresult = dataManager.GetData(trycode, 0);
if(!tryresult && !CardNameContains(text.name.c_str(), pstr) && text.text.find(pstr) == std::wstring::npos
&& (!set_code || !check_set_code(data, set_code)))
continue;
if (tryresult && data.code != trycode
&& !(data.alias == trycode && (data.alias - data.code < CARD_ARTWORK_VERSIONS_OFFSET || data.code - data.alias < CARD_ARTWORK_VERSIONS_OFFSET)))
continue;
if(!tryresult && !CardNameContains(text.name.c_str(), elements_iterator->c_str()) && text.text.find(elements_iterator->c_str()) == std::wstring::npos
&& (!set_code_map[*elements_iterator] || !check_set_code(data, set_code_map[*elements_iterator]))) {
is_target = false;
break;
}
if(tryresult && data.code != trycode
&& !(data.alias == trycode && (data.alias - data.code < CARD_ARTWORK_VERSIONS_OFFSET || data.code - data.alias < CARD_ARTWORK_VERSIONS_OFFSET))) {
is_target = false;
break;
}
}
}
results.push_back(ptr);
if(is_target)
results.push_back(ptr);
else
continue;
}
myswprintf(result_string, L"%d", results.size());
if(results.size() > 7) {
Expand Down
48 changes: 9 additions & 39 deletions gframe/deck_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,11 @@ namespace ygo {

DeckManager deckManager;

void DeckManager::LoadLFList() {
void DeckManager::LoadLFListSingle(const char* path) {
LFList* cur = NULL;
FILE* fp = fopen("lflist.conf", "r");
FILE* fp_custom = fopen("expansions/lflist.conf", "r");
FILE* fp = fopen(path, "r");
char linebuf[256];
wchar_t strBuffer[256];
if(fp_custom) {
while(fgets(linebuf, 256, fp_custom)) {
if(linebuf[0] == '#')
continue;
int p = 0, sa = 0, code, count;
if(linebuf[0] == '!') {
sa = BufferIO::DecodeUTF8((const char*)(&linebuf[1]), strBuffer);
while(strBuffer[sa - 1] == L'\r' || strBuffer[sa - 1] == L'\n' ) sa--;
LFList newlist;
_lfList.push_back(newlist);
cur = &_lfList[_lfList.size() - 1];
memcpy(cur->listName, (const void*)strBuffer, 40);
cur->listName[sa] = 0;
cur->content = new std::unordered_map<int, int>;
cur->hash = 0x7dfcee6a;
continue;
}
while(linebuf[p] != ' ' && linebuf[p] != '\t' && linebuf[p] != 0) p++;
if(linebuf[p] == 0)
continue;
linebuf[p++] = 0;
sa = p;
code = atoi(linebuf);
if(code == 0)
continue;
while(linebuf[p] == ' ' || linebuf[p] == '\t') p++;
while(linebuf[p] != ' ' && linebuf[p] != '\t' && linebuf[p] != 0) p++;
linebuf[p] = 0;
count = atoi(&linebuf[sa]);
if(cur == NULL) continue;
(*cur->content)[code] = count;
cur->hash = cur->hash ^ ((code << 18) | (code >> 14)) ^ ((code << (27 + count)) | (code >> (5 - count)));
}
fclose(fp_custom);
}
if(fp) {
while(fgets(linebuf, 256, fp)) {
if(linebuf[0] == '#')
Expand All @@ -60,7 +24,7 @@ void DeckManager::LoadLFList() {
LFList newlist;
_lfList.push_back(newlist);
cur = &_lfList[_lfList.size() - 1];
memcpy(cur->listName, (const void*)strBuffer, 40);
memcpy(cur->listName, (const void*)strBuffer, 20 * sizeof(wchar_t));
cur->listName[sa] = 0;
cur->content = new std::unordered_map<int, int>;
cur->hash = 0x7dfcee6a;
Expand All @@ -84,6 +48,10 @@ void DeckManager::LoadLFList() {
}
fclose(fp);
}
}
void DeckManager::LoadLFList() {
LoadLFListSingle("expansions/lflist.conf");
LoadLFListSingle("lflist.conf");
LFList nolimit;
myswprintf(nolimit.listName, L"N/A");
nolimit.hash = 0;
Expand Down Expand Up @@ -266,6 +234,8 @@ bool DeckManager::LoadDeck(const wchar_t* file) {
return true;
}
bool DeckManager::SaveDeck(Deck& deck, const wchar_t* name) {
if(!FileSystem::IsDirExists(L"./deck") && !FileSystem::MakeDir(L"./deck"))
return false;
wchar_t file[64];
myswprintf(file, L"./deck/%ls.ydk", name);
FILE* fp = OpenDeckFile(file, "w");
Expand Down
1 change: 1 addition & 0 deletions gframe/deck_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DeckManager {
Deck current_deck;
std::vector<LFList> _lfList;

void LoadLFListSingle(const char* path);
void LoadLFList();
wchar_t* GetLFListName(int lfhash);
int CheckDeck(Deck& deck, int lfhash, bool allow_ocg, bool allow_tcg);
Expand Down
3 changes: 2 additions & 1 deletion gframe/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ void Game::DrawCard(ClientCard* pcard) {
matManager.mTexture.setTexture(0, imageManager.tChainTarget);
driver->setMaterial(matManager.mTexture);
driver->drawVertexPrimitiveList(matManager.vSymbol, 4, matManager.iRectangle, 2);
} else if(pcard->is_disabled && (pcard->location & LOCATION_ONFIELD) && (pcard->position & POS_FACEUP)) {
} else if((pcard->status & (STATUS_DISABLED | STATUS_FORBIDDEN))
&& (pcard->location & LOCATION_ONFIELD) && (pcard->position & POS_FACEUP)) {
matManager.mTexture.setTexture(0, imageManager.tNegated);
driver->setMaterial(matManager.mTexture);
driver->drawVertexPrimitiveList(matManager.vNegate, 4, matManager.iRectangle, 2);
Expand Down
42 changes: 28 additions & 14 deletions gframe/duelclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
mainGame->stHostPrepDuelist[2]->setText(L"");
mainGame->stHostPrepDuelist[3]->setText(L"");
mainGame->stHostPrepOB->setText(L"");
mainGame->SetStaticText(mainGame->stHostPrepRule, 180, mainGame->guiFont, (wchar_t*)str.c_str());
mainGame->SetStaticText(mainGame->stHostPrepRule, 180, mainGame->guiFont, str.c_str());
mainGame->RefreshDeck(mainGame->cbDeckSelect);
mainGame->cbDeckSelect->setEnabled(true);
if(mainGame->wCreateHost->isVisible())
Expand Down Expand Up @@ -681,18 +681,26 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
mainGame->btnCancelOrFinish->setVisible(false);
mainGame->btnShuffle->setVisible(false);
time_t nowtime = time(NULL);
struct tm *localedtime = localtime(&nowtime);
char timebuf[40];
strftime(timebuf, 40, "%Y-%m-%d %H-%M-%S", localedtime);
size_t size = strlen(timebuf) + 1;
wchar_t timetext[80];
mbstowcs(timetext, timebuf, size);
tm* localedtime = localtime(&nowtime);
wchar_t timetext[40];
wcsftime(timetext, 40, L"%Y-%m-%d %H-%M-%S", localedtime);
mainGame->ebRSName->setText(timetext);
mainGame->wReplaySave->setText(dataManager.GetSysString(1340));
mainGame->PopupElement(mainGame->wReplaySave);
mainGame->gMutex.Unlock();
mainGame->replaySignal.Reset();
mainGame->replaySignal.Wait();
if(!mainGame->chkAutoSaveReplay->isChecked()) {
mainGame->wReplaySave->setText(dataManager.GetSysString(1340));
mainGame->PopupElement(mainGame->wReplaySave);
mainGame->gMutex.Unlock();
mainGame->replaySignal.Reset();
mainGame->replaySignal.Wait();
}
else {
mainGame->actionParam = 1;
wchar_t msgbuf[256];
myswprintf(msgbuf, dataManager.GetSysString(1367), timetext);
mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, msgbuf);
mainGame->PopupElement(mainGame->wACMessage, 20);
mainGame->gMutex.Unlock();
mainGame->WaitFrameSignal(30);
}
if(mainGame->actionParam || !is_host) {
char* prep = pdata;
Replay new_replay;
Expand Down Expand Up @@ -1296,6 +1304,10 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
wchar_t ynbuf[256];
myswprintf(ynbuf, dataManager.GetSysString(200), dataManager.FormatLocation(l, s), dataManager.GetName(code));
myswprintf(textBuffer, L"%ls\n%ls", event_string, ynbuf);
} else if(desc == 221) {
wchar_t ynbuf[256];
myswprintf(ynbuf, dataManager.GetSysString(221), dataManager.FormatLocation(l, s), dataManager.GetName(code));
myswprintf(textBuffer, L"%ls\n%ls\n%ls", event_string, ynbuf, dataManager.GetSysString(223));
} else if(desc < 2048) {
myswprintf(textBuffer, dataManager.GetSysString(desc), dataManager.GetName(code));
} else {
Expand All @@ -1312,7 +1324,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
int desc = BufferIO::ReadInt32(pbuf);
mainGame->dField.highlighting_card = 0;
mainGame->gMutex.Lock();
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)dataManager.GetDesc(desc));
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, dataManager.GetDesc(desc));
mainGame->PopupElement(mainGame->wQuery);
mainGame->gMutex.Unlock();
return false;
Expand Down Expand Up @@ -1550,9 +1562,11 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
if(!forced) {
if(count == 0)
myswprintf(textBuffer, L"%ls\n%ls", dataManager.GetSysString(201), dataManager.GetSysString(202));
else if(select_trigger)
myswprintf(textBuffer, L"%ls\n%ls\n%ls", event_string, dataManager.GetSysString(222), dataManager.GetSysString(223));
else
myswprintf(textBuffer, L"%ls\n%ls", event_string, dataManager.GetSysString(203));
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, (wchar_t*)textBuffer);
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->textFont, textBuffer);
mainGame->PopupElement(mainGame->wQuery);
}
}
Expand Down
Loading

0 comments on commit 17cdeb8

Please sign in to comment.