Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改超先行下载、热更新expansions文件夹 #1

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@
/sqlite3/
/irrklang/
/ikpmp3/
premake5.exe
/.vs/
/expansions/
/pics/
/script/
/deck/
/WindBot/
/gframe/*.ico
/*.exe
/*.conf
/*.dll
/*.bat
error.log
cards.cdb
Binary file modified download/YGO-VI-EX-Downloader.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion download/ver.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Power
Happy National Day
Binary file added download/老喵师牌YGO-VI-EX下载器.exe
Binary file not shown.
20 changes: 14 additions & 6 deletions gframe/data_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ DataManager::DataManager() : _datas(16384), _strings(16384) {
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, bool expansion) {
char file[256];
BufferIO::EncodeUTF8(wfile, file);
#ifdef _WIN32
Expand Down Expand Up @@ -82,6 +82,7 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
cd.attribute = sqlite3_column_int(pStmt, 9);
cd.category = sqlite3_column_int(pStmt, 10);
_datas[cd.code] = cd;
if (expansion) _expansionDatas.push_back(cd.code);
if(const char* text = (const char*)sqlite3_column_text(pStmt, 12)) {
BufferIO::DecodeUTF8(text, strBuffer);
cs.name = strBuffer;
Expand All @@ -108,35 +109,35 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
strings_end = _strings.end();
return true;
}
bool DataManager::LoadStrings(const char* file) {
bool DataManager::LoadStrings(const char* file, bool expansion) {
FILE* fp = fopen(file, "r");
if(!fp)
return false;
char linebuf[256];
while(fgets(linebuf, 256, fp)) {
ReadStringConfLine(linebuf);
ReadStringConfLine(linebuf, expansion);
}
fclose(fp);
for(int i = 0; i < 301; ++i)
myswprintf(numStrings[i], L"%d", i);
return true;
}
bool DataManager::LoadStrings(IReadFile* reader) {
bool DataManager::LoadStrings(IReadFile* reader, bool expansion) {
char ch[2] = " ";
char linebuf[256] = "";
while(reader->read(&ch[0], 1)) {
if(ch[0] == '\0')
break;
strcat(linebuf, ch);
if(ch[0] == '\n') {
ReadStringConfLine(linebuf);
ReadStringConfLine(linebuf, expansion);
linebuf[0] = '\0';
}
}
reader->drop();
return true;
}
void DataManager::ReadStringConfLine(const char* linebuf) {
void DataManager::ReadStringConfLine(const char* linebuf, bool expansion) {
if(linebuf[0] != '!')
return;
char strbuf[256]{};
Expand All @@ -149,22 +150,26 @@ void DataManager::ReadStringConfLine(const char* linebuf) {
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_sysStrings[value] = strBuffer;
if (expansion) _expansionStrings.push_back(value);
} else if(!strcmp(strbuf, "victory")) {
if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_victoryStrings[value] = strBuffer;
if (expansion) _expansionStrings.push_back(value);
} else if(!strcmp(strbuf, "counter")) {
if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_counterStrings[value] = strBuffer;
if (expansion) _expansionStrings.push_back(value);
} else if(!strcmp(strbuf, "setname")) {
//using tab for comment
if (sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_setnameStrings[value] = strBuffer;
if (expansion) _expansionStrings.push_back(value);
}
}
bool DataManager::Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt) {
Expand Down Expand Up @@ -406,6 +411,9 @@ byte* DataManager::ScriptReaderEx(const char* script_name, int* slen) {
if(buffer)
return buffer;
buffer = ScriptReaderExSingle("expansions/", script_name, slen);
if(buffer)
return buffer;
buffer = ScriptReaderExSingle("expansions/ygopro-super-pre/", script_name, slen);
if(buffer)
return buffer;
return ScriptReaderExSingle("", script_name, slen);
Expand Down
14 changes: 8 additions & 6 deletions gframe/data_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace ygo {
class DataManager {
public:
DataManager();
bool LoadDB(const wchar_t* wfile);
bool LoadStrings(const char* file);
bool LoadStrings(IReadFile* reader);
void ReadStringConfLine(const char* linebuf);
bool LoadDB(const wchar_t* wfile, bool expansion = false);
bool LoadStrings(const char* file, bool epxansion = false);
bool LoadStrings(IReadFile* reader, bool epxansion = false);
void ReadStringConfLine(const char* linebuf, bool epxansion = false);
bool Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt = 0);
bool GetData(unsigned int code, CardData* pData);
code_pointer GetCodePointer(unsigned int code) const;
Expand All @@ -39,6 +39,10 @@ class DataManager {
const wchar_t* FormatSetName(const uint16_t setcode[]);
const wchar_t* FormatLinkMarker(int link_marker);

std::vector<int> _expansionDatas;
std::vector<int> _expansionStrings;
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> _victoryStrings;
std::unordered_map<unsigned int, std::wstring> _setnameStrings;
Expand All @@ -65,8 +69,6 @@ class DataManager {
static IFileSystem* FileSystem;

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;
};

Expand Down
105 changes: 101 additions & 4 deletions gframe/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ bool Game::Initialize() {
return false;
}
dataManager.FileSystem = device->getFileSystem();
LastExpansionsTime = GetLastWriteTime(L"./expansions");
LastSurperpreTime = GetLastWriteTime(L"./expansions/ygopro-super-pre");
LoadExpansions();
if(dataManager.LoadDB(GetLocaleDirWide("cards.cdb"))) {} else
if(!dataManager.LoadDB(L"cards.cdb")) {
Expand All @@ -128,7 +130,11 @@ bool Game::Initialize() {
ErrorLog("Failed to load strings!");
return false;
}
dataManager.LoadStrings("./expansions/strings.conf");
dataManager.LoadStrings("./expansions/strings.conf", true);
dataManager.LoadStrings("./expansions/ygopro-super-pre/strings.conf", true);
dataManager.LoadStrings("./expansions/ygopro-super-pre/test-strings.conf", true);
ChkLastTime();
ChkReload = false;
env = device->getGUIEnvironment();
numFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 16);
adFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 12);
Expand Down Expand Up @@ -1202,12 +1208,85 @@ std::wstring Game::SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth,
ret.assign(strBuffer);
return ret;
}
int Game::GetLastWriteTime(wchar_t* dirPath) {
struct _stat64i32 st = { 0 };
if (_wstat(dirPath, &st) != -1)
return (int)(st.st_mtime);
return 0;
}
void Game::ChkLastTime() {
int time = 0;
time = GetLastWriteTime(L"./expansions");
if (LastExpansionsTime < time) {
LastExpansionsTime = time;
ChkReload = true;
}
time = GetLastWriteTime(L"./expansions/ygopro-super-pre");
if (LastSurperpreTime < time) {
LastSurperpreTime = time;
ChkReload = true;
}
FileSystem::TraversalDir(L"./expansions", [](const wchar_t* name, bool isdir) {
if (!isdir && wcsrchr(name, '.') && (!mywcsncasecmp(wcsrchr(name, '.'), L".cdb", 4) || !mywcsncasecmp(wcsrchr(name, '.'), L".zip", 4) || !mywcsncasecmp(wcsrchr(name, '.'), L".ypk", 4) || !mywcsncasecmp(wcsrchr(name, '.'), L".conf", 5))) {
wchar_t fpath[1024];
myswprintf(fpath, L"./expansions/%ls", name);
int time = mainGame->GetLastWriteTime(fpath);
if (mainGame->LastExpansionsFileTime < time) {
mainGame->LastExpansionsFileTime = time;
mainGame->ChkReload = true;
}
}
});
FileSystem::TraversalDir(L"./expansions/ygopro-super-pre", [](const wchar_t* name, bool isdir) {
if (!isdir && wcsrchr(name, '.') && (!mywcsncasecmp(wcsrchr(name, '.'), L".cdb", 4) || !mywcsncasecmp(wcsrchr(name, '.'), L".zip", 4) || !mywcsncasecmp(wcsrchr(name, '.'), L".ypk", 4) || !mywcsncasecmp(wcsrchr(name, '.'), L".conf", 5))) {
wchar_t fpath[1024];
myswprintf(fpath, L"./expansions//ygopro-super-pre/%ls", name);
int time = mainGame->GetLastWriteTime(fpath);
if (mainGame->LastSurperpreFileTime < time) {
mainGame->LastSurperpreFileTime = time;
mainGame->ChkReload = true;
}
}
});
}
void Game::ReLoadExpansions() {
ChkLastTime();
if (ChkReload) {
ChkReload = false;
for (size_t i = 0; i < dataManager._expansionDatas.size(); ++i) {
int code = dataManager._expansionDatas[i];
dataManager._strings.erase(code);
dataManager._datas.erase(code);
}
dataManager._expansionDatas.clear();
for (size_t i = 0; i < dataManager._expansionStrings.size(); ++i) {
int value = dataManager._expansionStrings[i];
dataManager._counterStrings.erase(value);
dataManager._victoryStrings.erase(value);
dataManager._setnameStrings.erase(value);
dataManager._sysStrings.erase(value);
}
dataManager._expansionStrings.clear();
dataManager.LoadStrings("./expansions/strings.conf", true);
dataManager.LoadStrings("./expansions/ygopro-super-pre/strings.conf", true);
dataManager.LoadStrings("./expansions/ygopro-super-pre/test-strings.conf", true);
deckManager._lfList.clear();
deckManager.LoadLFList();
cbDBLFList->clear();
cbLFlist->clear();
for (unsigned int i = 0; i < deckManager._lfList.size(); ++i)
cbDBLFList->addItem(deckManager._lfList[i].listName.c_str());
for (unsigned int i = 0; i < deckManager._lfList.size(); ++i)
cbLFlist->addItem(deckManager._lfList[i].listName.c_str(), deckManager._lfList[i].hash);
LoadExpansions();
}
}
void Game::LoadExpansions() {
FileSystem::TraversalDir(L"./expansions", [](const wchar_t* name, bool isdir) {
if(!isdir && wcsrchr(name, '.') && !mywcsncasecmp(wcsrchr(name, '.'), L".cdb", 4)) {
wchar_t fpath[1024];
myswprintf(fpath, L"./expansions/%ls", name);
dataManager.LoadDB(fpath);
dataManager.LoadDB(fpath, true);
}
if(!isdir && wcsrchr(name, '.') && (!mywcsncasecmp(wcsrchr(name, '.'), L".zip", 4) || !mywcsncasecmp(wcsrchr(name, '.'), L".ypk", 4))) {
wchar_t fpath[1024];
Expand All @@ -1218,6 +1297,24 @@ void Game::LoadExpansions() {
char upath[1024];
BufferIO::EncodeUTF8(fpath, upath);
dataManager.FileSystem->addFileArchive(upath, true, false, EFAT_ZIP);
#endif
}
});
FileSystem::TraversalDir(L"./expansions/ygopro-super-pre", [](const wchar_t* name, bool isdir) {
if(!isdir && wcsrchr(name, '.') && !mywcsncasecmp(wcsrchr(name, '.'), L".cdb", 4)) {
wchar_t fpath[1024];
myswprintf(fpath, L"./expansions/ygopro-super-pre/%ls", name);
dataManager.LoadDB(fpath, true);
}
if(!isdir && wcsrchr(name, '.') && (!mywcsncasecmp(wcsrchr(name, '.'), L".zip", 4) || !mywcsncasecmp(wcsrchr(name, '.'), L".ypk", 4))) {
wchar_t fpath[1024];
myswprintf(fpath, L"./expansions/ygopro-super-pre/%ls", name);
#ifdef _WIN32
dataManager.FileSystem->addFileArchive(fpath, true, false, EFAT_ZIP);
#else
char upath[1024];
BufferIO::EncodeUTF8(fpath, upath);
dataManager.FileSystem->addFileArchive(upath, true, false, EFAT_ZIP);
#endif
}
});
Expand All @@ -1232,14 +1329,14 @@ void Game::LoadExpansions() {
BufferIO::DecodeUTF8(uname, fname);
#endif
if(wcsrchr(fname, '.') && !mywcsncasecmp(wcsrchr(fname, '.'), L".cdb", 4))
dataManager.LoadDB(fname);
dataManager.LoadDB(fname, true);
if(wcsrchr(fname, '.') && !mywcsncasecmp(wcsrchr(fname, '.'), L".conf", 5)) {
#ifdef _WIN32
IReadFile* reader = DataManager::FileSystem->createAndOpenFile(fname);
#else
IReadFile* reader = DataManager::FileSystem->createAndOpenFile(uname);
#endif
dataManager.LoadStrings(reader);
dataManager.LoadStrings(reader, true);
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions gframe/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ struct FadingUnit {
};

class Game {
private:
int LastExpansionsTime;
int LastSurperpreTime;
int LastExpansionsFileTime;
int LastSurperpreFileTime;
bool ChkReload;

public:
bool Initialize();
Expand All @@ -137,6 +143,7 @@ class Game {
void InitStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, u32 cHeight, irr::gui::CGUITTFont* font, const wchar_t* text);
std::wstring SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, irr::gui::CGUITTFont* font, const wchar_t* text, u32 pos = 0);
void LoadExpansions();
void ReLoadExpansions();
void RefreshDeck(irr::gui::IGUIComboBox* cbDeck);
void RefreshReplay();
void RefreshSingleplay();
Expand Down Expand Up @@ -179,7 +186,9 @@ class Game {
void initUtils();
void ClearTextures();
void CloseDuelWindow();
void ChkLastTime();

int GetLastWriteTime(wchar_t* dirPath);
int LocalPlayer(int player) const;
int OppositePlayer(int player);
int ChatLocalPlayer(int player);
Expand Down
Loading