Commit 5f7038fd authored by fallenstardust's avatar fallenstardust

update gframe

parent 5949ac30
......@@ -13,6 +13,7 @@ void DeckManager::LoadLFListSingle(const char* path) {
FILE* fp = std::fopen(path, "r");
char linebuf[256]{};
wchar_t strBuffer[256]{};
char str1[16]{};
if(fp) {
while(std::fgets(linebuf, sizeof linebuf, fp)) {
if(linebuf[0] == '#')
......@@ -32,10 +33,11 @@ void DeckManager::LoadLFListSingle(const char* path) {
continue;
unsigned int code = 0;
int count = -1;
if (std::sscanf(linebuf, "%9u%*[ ]%9d", &code, &count) != 2)
if (std::sscanf(linebuf, "%10s%*[ ]%1d", str1, &count) != 2)
continue;
if (count < 0 || count > 2)
continue;
code = std::strtoul(str1, nullptr, 10);
cur->content[code] = count;
cur->hash = cur->hash ^ ((code << 18) | (code >> 14)) ^ ((code << (27 + count)) | (code >> (5 - count)));
}
......@@ -140,13 +142,12 @@ unsigned int DeckManager::CheckDeck(const Deck& deck, unsigned int lfhash, int r
}
return 0;
}
int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_packlist) {
uint32_t DeckManager::LoadDeck(Deck& deck, uint32_t dbuf[], int mainc, int sidec, bool is_packlist) {
deck.clear();
int code;
int errorcode = 0;
uint32_t errorcode = 0;
CardData cd;
for(int i = 0; i < mainc; ++i) {
code = dbuf[i];
auto code = dbuf[i];
if(!dataManager.GetData(code, &cd)) {
errorcode = code;
continue;
......@@ -169,7 +170,7 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_p
}
}
for(int i = 0; i < sidec; ++i) {
code = dbuf[mainc + i];
auto code = dbuf[mainc + i];
if(!dataManager.GetData(code, &cd)) {
errorcode = code;
continue;
......@@ -183,22 +184,21 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_p
}
return errorcode;
}
int DeckManager::LoadDeck(Deck& deck, std::istringstream& deckStream, bool is_packlist) {
size_t ct = 0;
int mainc = 0, sidec = 0, code = 0;
int cardlist[PACK_MAX_SIZE]{};
uint32_t DeckManager::LoadDeckFromStream(Deck& deck, std::istringstream& deckStream, bool is_packlist) {
int ct = 0;
int mainc = 0, sidec = 0;
uint32_t cardlist[PACK_MAX_SIZE]{};
bool is_side = false;
std::string linebuf;
while (std::getline(deckStream, linebuf, '\n') && ct < (sizeof cardlist / sizeof cardlist[0])) {
while (std::getline(deckStream, linebuf, '\n') && ct < PACK_MAX_SIZE) {
if (linebuf[0] == '!') {
is_side = true;
continue;
}
if (linebuf[0] < '0' || linebuf[0] > '9')
continue;
errno = 0;
code = std::strtol(linebuf.c_str(), nullptr, 10);
if (errno == ERANGE)
auto code = std::strtoul(linebuf.c_str(), nullptr, 10);
if (code >= UINT32_MAX)
continue;
cardlist[ct++] = code;
if (is_side)
......@@ -208,32 +208,32 @@ int DeckManager::LoadDeck(Deck& deck, std::istringstream& deckStream, bool is_pa
}
return LoadDeck(deck, cardlist, mainc, sidec, is_packlist);
}
bool DeckManager::LoadSide(Deck& deck, int* dbuf, int mainc, int sidec) {
std::unordered_map<int, int> pcount;
std::unordered_map<int, int> ncount;
bool DeckManager::LoadSide(Deck& deck, uint32_t dbuf[], int mainc, int sidec) {
std::unordered_map<uint32_t, int> pcount;
std::unordered_map<uint32_t, int> ncount;
for(size_t i = 0; i < deck.main.size(); ++i)
++pcount[deck.main[i]->first];
pcount[deck.main[i]->first]++;
for(size_t i = 0; i < deck.extra.size(); ++i)
++pcount[deck.extra[i]->first];
pcount[deck.extra[i]->first]++;
for(size_t i = 0; i < deck.side.size(); ++i)
++pcount[deck.side[i]->first];
pcount[deck.side[i]->first]++;
Deck ndeck;
LoadDeck(ndeck, dbuf, mainc, sidec);
if (ndeck.main.size() != deck.main.size() || ndeck.extra.size() != deck.extra.size() || ndeck.side.size() != deck.side.size())
return false;
for(size_t i = 0; i < ndeck.main.size(); ++i)
++ncount[ndeck.main[i]->first];
ncount[ndeck.main[i]->first]++;
for(size_t i = 0; i < ndeck.extra.size(); ++i)
++ncount[ndeck.extra[i]->first];
ncount[ndeck.extra[i]->first]++;
for(size_t i = 0; i < ndeck.side.size(); ++i)
++ncount[ndeck.side[i]->first];
ncount[ndeck.side[i]->first]++;
for (auto& cdit : ncount)
if (cdit.second != pcount[cdit.first])
return false;
deck = ndeck;
return true;
}
void DeckManager::GetCategoryPath(wchar_t* ret, int index, const wchar_t* text, bool showPack) {
void DeckManager::GetCategoryPath(wchar_t* ret, int index, const wchar_t* text, bool showPack) {//hide packlist if showing on duelling ready
wchar_t catepath[256];
switch(index) {
case 0:
......@@ -309,8 +309,8 @@ bool DeckManager::LoadCurrentDeck(const wchar_t* file, bool is_packlist) {
return false;
}
std::istringstream deckStream(deckBuffer);
LoadDeck(current_deck, deckStream, is_packlist);
return true; // the above LoadDeck has return value but we ignore it here for now
LoadDeckFromStream(current_deck, deckStream, is_packlist);
return true; // the above function has return value but we ignore it here for now
}
bool DeckManager::LoadCurrentDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck) {
wchar_t filepath[256];
......
......@@ -48,21 +48,23 @@ public:
const wchar_t* GetLFListName(unsigned int lfhash);
const LFList* GetLFList(unsigned int lfhash);
unsigned int CheckDeck(const Deck& deck, unsigned int lfhash, int rule);
int LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_packlist = false);
int LoadDeck(Deck& deck, std::istringstream& deckStream, bool is_packlist = false);
bool LoadSide(Deck& deck, int* dbuf, int mainc, int sidec);
void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text, bool showPack);//
void GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
FILE* OpenDeckFile(const wchar_t* file, const char* mode);
irr::io::IReadFile* OpenDeckReader(const wchar_t* file);
bool LoadCurrentDeck(const wchar_t* file, bool is_packlist = false);
bool LoadCurrentDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
bool SaveDeck(Deck& deck, const wchar_t* file);
bool DeleteDeck(const wchar_t* file);
bool CreateCategory(const wchar_t* name);
bool RenameCategory(const wchar_t* oldname, const wchar_t* newname);
bool DeleteCategory(const wchar_t* name);
bool SaveDeckBuffer(const int deckbuf[], const wchar_t* name);
static uint32_t LoadDeck(Deck& deck, uint32_t dbuf[], int mainc, int sidec, bool is_packlist = false);
static uint32_t LoadDeckFromStream(Deck& deck, std::istringstream& deckStream, bool is_packlist = false);
static bool LoadSide(Deck& deck, uint32_t dbuf[], int mainc, int sidec);
static void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text, bool showPack);//
static void GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
static FILE* OpenDeckFile(const wchar_t* file, const char* mode);
static irr::io::IReadFile* OpenDeckReader(const wchar_t* file);
static bool SaveDeck(Deck& deck, const wchar_t* file);
static bool DeleteDeck(const wchar_t* file);
static bool CreateCategory(const wchar_t* name);
static bool RenameCategory(const wchar_t* oldname, const wchar_t* newname);
static bool DeleteCategory(const wchar_t* name);
int TypeCount(std::vector<code_pointer> list, unsigned int ctype);
};
......
......@@ -1695,7 +1695,7 @@ void Game::RefreshDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBo
}
}
wchar_t catepath[256];
deckManager.GetCategoryPath(catepath, cbCategory->getSelected(), cbCategory->getText(), cbCategory == mainGame->cbDBCategory);
DeckManager::GetCategoryPath(catepath, cbCategory->getSelected(), cbCategory->getText(), cbCategory == mainGame->cbDBCategory);
cbDeck->clear();
RefreshDeck(catepath, [cbDeck](const wchar_t* item) { cbDeck->addItem(item); });
}
......
......@@ -464,7 +464,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wchar_t warg1[512];
if(mainGame->botInfo[sel].select_deckfile) {
wchar_t botdeck[256];
deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory, mainGame->cbBotDeck);
DeckManager::GetDeckFile(botdeck, mainGame->cbBotDeckCategory, mainGame->cbBotDeck);
myswprintf(warg1, L"%ls DeckFile='%ls'", mainGame->botInfo[sel].command, botdeck);
}
else
......
......@@ -57,7 +57,7 @@ static_assert(sizeof(HostRequest) == 2, "size mismatch: HostRequest");
struct CTOS_DeckData {
int32_t mainc{};
int32_t sidec{};
int32_t list[MAINC_MAX + SIDEC_MAX]{};
uint32_t list[MAINC_MAX + SIDEC_MAX]{};
};
check_trivially_copyable(CTOS_DeckData);
......
......@@ -297,9 +297,9 @@ void SingleDuel::UpdateDeck(DuelPlayer* dp, unsigned char* pdata, int len) {
return;
}
if(duel_count == 0) {
deck_error[dp->type] = deckManager.LoadDeck(pdeck[dp->type], deckbuf.list, deckbuf.mainc, deckbuf.sidec);
deck_error[dp->type] = DeckManager::LoadDeck(pdeck[dp->type], deckbuf.list, deckbuf.mainc, deckbuf.sidec);
} else {
if(deckManager.LoadSide(pdeck[dp->type], deckbuf.list, deckbuf.mainc, deckbuf.sidec)) {
if(DeckManager::LoadSide(pdeck[dp->type], deckbuf.list, deckbuf.mainc, deckbuf.sidec)) {
ready[dp->type] = true;
NetServer::SendPacketToPlayer(dp, STOC_DUEL_START);
if(ready[0] && ready[1]) {
......
......@@ -279,7 +279,7 @@ void TagDuel::UpdateDeck(DuelPlayer* dp, unsigned char* pdata, int len) {
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
return;
}
deck_error[dp->type] = deckManager.LoadDeck(pdeck[dp->type], deckbuf.list, deckbuf.mainc, deckbuf.sidec);
deck_error[dp->type] = DeckManager::LoadDeck(pdeck[dp->type], deckbuf.list, deckbuf.mainc, deckbuf.sidec);
}
void TagDuel::StartDuel(DuelPlayer* dp) {
if(dp != host_player)
......
......@@ -21,7 +21,7 @@
<pre>
更新:
1.更新ygopro内核;
2.新卡DBJH+VJ;
2.新卡DBJH+VX05+VJ;
3.2025.4 OCG禁卡表;
变更:
1.优化部分场景下超量素材显示到超量怪兽上方的问题;
......
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