Commit a5ce265b authored by Chen Bill's avatar Chen Bill Committed by GitHub

fix dangling pointer (#2920)

parent c470682b
...@@ -299,7 +299,7 @@ std::wstring DataManager::FormatAttribute(unsigned int attribute) const { ...@@ -299,7 +299,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())
...@@ -312,7 +312,7 @@ std::wstring DataManager::FormatRace(unsigned int race) const { ...@@ -312,7 +312,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())
...@@ -321,12 +321,11 @@ std::wstring DataManager::FormatRace(unsigned int race) const { ...@@ -321,12 +321,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())
......
...@@ -100,6 +100,11 @@ public: ...@@ -100,6 +100,11 @@ public:
const wchar_t* unknown_string{ L"???" }; const wchar_t* unknown_string{ L"???" };
irr::io::IFileSystem* FileSystem{}; irr::io::IFileSystem* FileSystem{};
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_path, int* slen); static unsigned char* ScriptReaderEx(const char* script_path, int* slen);
......
...@@ -1307,8 +1307,9 @@ void Game::DrawDeckBd() { ...@@ -1307,8 +1307,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(), auto attribute = dataManager.FormatAttribute(ptr->second.attribute);
form, ptr->second.level); 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);
...@@ -1318,7 +1319,8 @@ void Game::DrawDeckBd() { ...@@ -1318,7 +1319,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()); 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));
......
...@@ -1116,7 +1116,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) { ...@@ -1116,7 +1116,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()); 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);
...@@ -1126,7 +1127,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) { ...@@ -1126,7 +1127,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()); 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);
......
...@@ -1597,7 +1597,9 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -1597,7 +1597,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()); auto race = dataManager.FormatRace(mcard->race);
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);
...@@ -1622,10 +1624,14 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -1622,10 +1624,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()); 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) {
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);
......
...@@ -599,16 +599,16 @@ bool Game::Initialize() { ...@@ -599,16 +599,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);
...@@ -741,14 +741,14 @@ bool Game::Initialize() { ...@@ -741,14 +741,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);
...@@ -1564,7 +1564,8 @@ void Game::ShowCardInfo(int code, bool resize) { ...@@ -1564,7 +1564,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()); 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
...@@ -1575,7 +1576,10 @@ void Game::ShowCardInfo(int code, bool resize) { ...@@ -1575,7 +1576,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()); auto type = dataManager.FormatType(cd.type);
auto race = dataManager.FormatRace(cd.race);
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);
...@@ -1597,10 +1601,11 @@ void Game::ShowCardInfo(int code, bool resize) { ...@@ -1597,10 +1601,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-";
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);
...@@ -1618,8 +1623,10 @@ void Game::ShowCardInfo(int code, bool resize) { ...@@ -1618,8 +1623,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()); 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);
......
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