Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 57 additions & 29 deletions gframe/data_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ static const char SELECT_STMT[] = "SELECT datas.id, datas.ot, datas.alias, datas
" texts.str9, texts.str10, texts.str11, texts.str12, texts.str13, texts.str14, texts.str15, texts.str16 FROM datas INNER JOIN texts ON datas.id = texts.id";
static constexpr int DATAS_COUNT = 11;

static const char SELECT_STMT_V2[] = "SELECT datas.id, datas.ot, datas.alias, datas.setcode, datas.type, datas.atk, datas.def, datas.level, datas.race, datas.attribute, datas.category,"
" datas.rule_code, datas.scale, datas.setcode2, datas.setcode3, datas.setcode4,"
" texts.name, texts.desc, texts.str1, texts.str2, texts.str3, texts.str4, texts.str5, texts.str6, texts.str7, texts.str8,"
" texts.str9, texts.str10, texts.str11, texts.str12, texts.str13, texts.str14, texts.str15, texts.str16 FROM datas INNER JOIN texts ON datas.id = texts.id";
static constexpr int DATAS_COUNT_V2 = 16;

static constexpr int CARD_ARTWORK_VERSIONS_OFFSET = 20;
static inline bool is_alternative(uint32_t code, uint32_t alias) {
return alias && (alias < code + CARD_ARTWORK_VERSIONS_OFFSET) && (code < alias + CARD_ARTWORK_VERSIONS_OFFSET);
Expand All @@ -28,8 +34,15 @@ DataManager::DataManager() : _datas(32768), _strings(32768) {
}
bool DataManager::ReadDB(sqlite3* pDB) {
sqlite3_stmt* pStmt = nullptr;
int texts_offset = DATAS_COUNT;
if (sqlite3_prepare_v2(pDB, SELECT_STMT, -1, &pStmt, nullptr) != SQLITE_OK)
int version = 2;
int texts_offset = DATAS_COUNT_V2;
const char* select = SELECT_STMT_V2;
if (sqlite3_table_column_metadata(pDB, nullptr, "datas", "rule_code", nullptr, nullptr, nullptr, nullptr, nullptr) != SQLITE_OK) {
version = 1;
texts_offset = DATAS_COUNT;
select = SELECT_STMT;
}
if (sqlite3_prepare_v2(pDB, select, -1, &pStmt, nullptr) != SQLITE_OK)
return Error(pDB, pStmt);
Comment thread
salix5 marked this conversation as resolved.
Outdated
wchar_t strBuffer[4096];
for (int step = sqlite3_step(pStmt); step != SQLITE_DONE; step = sqlite3_step(pStmt)) {
Expand All @@ -53,19 +66,32 @@ bool DataManager::ReadDB(sqlite3* pDB) {
cd.link_marker = 0;
uint32_t level = static_cast<uint32_t>(sqlite3_column_int64(pStmt, 7));
cd.level = level & 0xff;
cd.lscale = (level >> 24) & 0xff;
cd.rscale = (level >> 16) & 0xff;
cd.race = static_cast<decltype(cd.race)>(sqlite3_column_int64(pStmt, 8));
cd.attribute = static_cast<decltype(cd.attribute)>(sqlite3_column_int64(pStmt, 9));
cd.category = static_cast<decltype(cd.category)>(sqlite3_column_int64(pStmt, 10));
// rule_code
if (cd.code == 5405695) {
cd.rule_code = cd.alias;
cd.alias = 0;
if (version >= 2) {
cd.rule_code = static_cast<uint32_t>(sqlite3_column_int64(pStmt, 11));
cd.lscale = static_cast<uint32_t>(sqlite3_column_int64(pStmt, 12));
cd.rscale = cd.lscale;
uint64_t setcode2 = static_cast<uint64_t>(sqlite3_column_int64(pStmt, 13));
uint64_t setcode3 = static_cast<uint64_t>(sqlite3_column_int64(pStmt, 14));
uint64_t setcode4 = static_cast<uint64_t>(sqlite3_column_int64(pStmt, 15));
write_setcode(cd.setcode, setcode2, 4);
write_setcode(cd.setcode, setcode3, 8);
write_setcode(cd.setcode, setcode4, 12);
}
else if (cd.alias && !(cd.type & TYPE_TOKEN) && !is_alternative(cd.code, cd.alias)) {
cd.rule_code = cd.alias;
cd.alias = 0;
else {
// rule_code
if (cd.code == 5405695) {
cd.rule_code = cd.alias;
cd.alias = 0;
}
else if (cd.alias && !(cd.type & TYPE_TOKEN) && !is_alternative(cd.code, cd.alias)) {
cd.rule_code = cd.alias;
cd.alias = 0;
}
cd.lscale = (level >> 24) & 0xff;
cd.rscale = (level >> 16) & 0xff;
}
auto& cs = _strings[code];
if (const char* text = (const char*)sqlite3_column_text(pStmt, texts_offset + 0)) {
Expand All @@ -84,24 +110,26 @@ bool DataManager::ReadDB(sqlite3* pDB) {
}
}
sqlite3_finalize(pStmt);
for (auto& entry : _datas) {
auto& cd = entry.second;
if (cd.rule_code || !cd.alias || (cd.type & TYPE_TOKEN))
continue;
auto it = _datas.find(cd.alias);
if (it == _datas.end())
continue;
cd.rule_code = it->second.rule_code;
}
for (const auto& entry : extra_setcode) {
const auto& code = entry.first;
const auto& list = entry.second;
if (list.size() > SIZE_SETCODE || list.empty())
continue;
auto it = _datas.find(code);
if (it == _datas.end())
continue;
std::memcpy(it->second.setcode, list.data(), list.size() * sizeof(uint16_t));
if (version < 2) {
for (auto& entry : _datas) {
auto& cd = entry.second;
if (cd.rule_code || !cd.alias || (cd.type & TYPE_TOKEN))
continue;
auto it = _datas.find(cd.alias);
if (it == _datas.end())
continue;
cd.rule_code = it->second.rule_code;
}
for (const auto& entry : extra_setcode) {
const auto& code = entry.first;
const auto& list = entry.second;
if (list.size() > SIZE_SETCODE || list.empty())
continue;
auto it = _datas.find(code);
if (it == _datas.end())
continue;
std::memcpy(it->second.setcode, list.data(), list.size() * sizeof(uint16_t));
}
}
return true;
}
Expand Down
14 changes: 14 additions & 0 deletions resource/migrate.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
BEGIN TRANSACTION;
--Add rule_code column
--step 1: add new column
ALTER TABLE datas ADD COLUMN rule_code INTEGER DEFAULT 0;

Expand All @@ -18,3 +20,15 @@ WHERE id = 5405695;
UPDATE datas
SET rule_code = 13331639
WHERE alias = 6218704;

--Add scale column
ALTER TABLE datas ADD COLUMN scale INTEGER DEFAULT 0;
UPDATE datas SET scale = (level >> 24) & 0xff WHERE type & 0x1000000;
UPDATE datas SET level = level & 0xff WHERE type & 0x1000000;

--Add setcode2, setcode3, setcode4 columns
ALTER TABLE datas ADD COLUMN setcode2 INTEGER DEFAULT 0;
ALTER TABLE datas ADD COLUMN setcode3 INTEGER DEFAULT 0;
ALTER TABLE datas ADD COLUMN setcode4 INTEGER DEFAULT 0;
UPDATE datas SET setcode2 = 0x13a WHERE id IN (8512558, 55088578);
COMMIT;