Commit ca41360e authored by 水濑真白's avatar 水濑真白

Merge develop into server-develop

parents 4224d17e 1274720b
Pipeline #42857 passed with stages
in 24 minutes and 2 seconds
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <cwchar> #include <cwchar>
#include <vector>
class BufferIO { class BufferIO {
public: public:
...@@ -15,11 +16,21 @@ public: ...@@ -15,11 +16,21 @@ public:
return ret; return ret;
} }
template<typename T> template<typename T>
static void Write(unsigned char*& p, T value) { static void Write(unsigned char*& p, const T& value) {
std::memcpy(p, &value, sizeof(T)); std::memcpy(p, &value, sizeof(T));
p += sizeof(T); p += sizeof(T);
} }
static void VectorWriteBlock(std::vector<unsigned char>& buffer, const void* src, size_t size) {
const auto len = buffer.size();
buffer.resize(len + size);
std::memcpy(buffer.data() + len, src, size);
}
template<typename T>
static void VectorWrite(std::vector<unsigned char>& buffer, const T& value) {
VectorWriteBlock(buffer, &value, sizeof(T));
}
// for compatibility // for compatibility
[[deprecated]] [[deprecated]]
static int32_t ReadInt32(unsigned char*& p) { static int32_t ReadInt32(unsigned char*& p) {
......
...@@ -32,14 +32,15 @@ ClientCard::~ClientCard() { ...@@ -32,14 +32,15 @@ ClientCard::~ClientCard() {
overlayed.clear(); overlayed.clear();
} }
void ClientCard::SetCode(unsigned int x) { void ClientCard::SetCode(unsigned int x) {
if((location == LOCATION_HAND) && (code != x)) { if (code == x) {
code = x; return;
}
if (x == 0) {
chain_code = code;
}
code = x;
if (location == LOCATION_HAND) {
mainGame->dField.MoveCard(this, 5); mainGame->dField.MoveCard(this, 5);
} else {
if (x == 0 && code != 0) {
chain_code = code;
}
code = x;
} }
} }
void ClientCard::UpdateInfo(unsigned char* buf) { void ClientCard::UpdateInfo(unsigned char* buf) {
......
...@@ -467,19 +467,18 @@ void ClientField::ShowSelectCard(bool buttonok, bool is_continuous) { ...@@ -467,19 +467,18 @@ void ClientField::ShowSelectCard(bool buttonok, bool is_continuous) {
if(mainGame->dInfo.curMsg != MSG_SORT_CARD) { if(mainGame->dInfo.curMsg != MSG_SORT_CARD) {
// text // text
wchar_t formatBuffer[2048]; wchar_t formatBuffer[2048];
if(select_continuous) if (select_continuous)
myswprintf(formatBuffer, L"%ls", dataManager.unknown_string); myswprintf(formatBuffer, L"%ls", dataManager.unknown_string);
else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE) else if (cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE)
myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0)); myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0));
else if(selectable_cards[i]->location == LOCATION_OVERLAY) else if (selectable_cards[i]->location == LOCATION_OVERLAY)
myswprintf(formatBuffer, L"%ls[%d](%d)", myswprintf(formatBuffer, L"%ls[%d](%d)",
dataManager.FormatLocation(selectable_cards[i]->overlayTarget->location, selectable_cards[i]->overlayTarget->sequence), dataManager.FormatLocation(selectable_cards[i]->overlayTarget),
selectable_cards[i]->overlayTarget->sequence + 1, selectable_cards[i]->sequence + 1); selectable_cards[i]->overlayTarget->sequence + 1, selectable_cards[i]->sequence + 1);
else if (selectable_cards[i]->location == 0) else if (selectable_cards[i]->location == 0)
myswprintf(formatBuffer, L""); myswprintf(formatBuffer, L"");
else else
myswprintf(formatBuffer, L"%ls[%d]", dataManager.FormatLocation(selectable_cards[i]->location, selectable_cards[i]->sequence), myswprintf(formatBuffer, L"%ls[%d]", dataManager.FormatLocation(selectable_cards[i]), selectable_cards[i]->sequence + 1);
selectable_cards[i]->sequence + 1);
mainGame->stCardPos[i]->setText(formatBuffer); mainGame->stCardPos[i]->setText(formatBuffer);
// color // color
if (selectable_cards[i]->is_selected) if (selectable_cards[i]->is_selected)
...@@ -555,8 +554,7 @@ void ClientField::ShowChainCard() { ...@@ -555,8 +554,7 @@ void ClientField::ShowChainCard() {
mainGame->btnCardSelect[i]->setPressed(false); mainGame->btnCardSelect[i]->setPressed(false);
mainGame->btnCardSelect[i]->setVisible(true); mainGame->btnCardSelect[i]->setVisible(true);
wchar_t formatBuffer[2048]; wchar_t formatBuffer[2048];
myswprintf(formatBuffer, L"%ls[%d]", dataManager.FormatLocation(selectable_cards[i]->location, selectable_cards[i]->sequence), myswprintf(formatBuffer, L"%ls[%d]", dataManager.FormatLocation(selectable_cards[i]), selectable_cards[i]->sequence + 1);
selectable_cards[i]->sequence + 1);
mainGame->stCardPos[i]->setText(formatBuffer); mainGame->stCardPos[i]->setText(formatBuffer);
if(selectable_cards[i]->location == LOCATION_OVERLAY) { if(selectable_cards[i]->location == LOCATION_OVERLAY) {
if(selectable_cards[i]->owner != selectable_cards[i]->overlayTarget->controler) if(selectable_cards[i]->owner != selectable_cards[i]->overlayTarget->controler)
...@@ -610,13 +608,11 @@ void ClientField::ShowLocationCard() { ...@@ -610,13 +608,11 @@ void ClientField::ShowLocationCard() {
mainGame->btnCardDisplay[i]->setPressed(false); mainGame->btnCardDisplay[i]->setPressed(false);
mainGame->btnCardDisplay[i]->setVisible(true); mainGame->btnCardDisplay[i]->setVisible(true);
wchar_t formatBuffer[2048]; wchar_t formatBuffer[2048];
if(display_cards[i]->location == LOCATION_OVERLAY) if (display_cards[i]->location == LOCATION_OVERLAY)
myswprintf(formatBuffer, L"%ls[%d](%d)", myswprintf(formatBuffer, L"%ls[%d](%d)",
dataManager.FormatLocation(display_cards[i]->overlayTarget->location, display_cards[i]->overlayTarget->sequence), dataManager.FormatLocation(display_cards[i]->overlayTarget), display_cards[i]->overlayTarget->sequence + 1, display_cards[i]->sequence + 1);
display_cards[i]->overlayTarget->sequence + 1, display_cards[i]->sequence + 1);
else else
myswprintf(formatBuffer, L"%ls[%d]", dataManager.FormatLocation(display_cards[i]->location, display_cards[i]->sequence), myswprintf(formatBuffer, L"%ls[%d]", dataManager.FormatLocation(display_cards[i]), display_cards[i]->sequence + 1);
display_cards[i]->sequence + 1);
mainGame->stDisplayPos[i]->setText(formatBuffer); mainGame->stDisplayPos[i]->setText(formatBuffer);
if(display_cards[i]->location == LOCATION_OVERLAY) { if(display_cards[i]->location == LOCATION_OVERLAY) {
if(display_cards[i]->owner != display_cards[i]->overlayTarget->controler) if(display_cards[i]->owner != display_cards[i]->overlayTarget->controler)
......
#include "data_manager.h" #include "data_manager.h"
#include "game.h" #include "game.h"
#ifndef YGOPRO_SERVER_MODE
#include "client_card.h"
#endif
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT) #if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
#include "spmemvfs/spmemvfs.h" #include "spmemvfs/spmemvfs.h"
#endif #endif
...@@ -414,8 +417,6 @@ const wchar_t* DataManager::GetDesc(uint32_t strCode) const { ...@@ -414,8 +417,6 @@ const wchar_t* DataManager::GetDesc(uint32_t strCode) const {
return unknown_string; return unknown_string;
} }
const wchar_t* DataManager::GetSysString(int code) const { const wchar_t* DataManager::GetSysString(int code) const {
if (code < 0 || code > MAX_STRING_ID)
return unknown_string;
auto csit = _sysStrings.find(code); auto csit = _sysStrings.find(code);
if(csit == _sysStrings.end()) if(csit == _sysStrings.end())
return unknown_string; return unknown_string;
...@@ -478,11 +479,10 @@ const wchar_t* DataManager::FormatLocation(int location, int sequence) const { ...@@ -478,11 +479,10 @@ const wchar_t* DataManager::FormatLocation(int location, int sequence) const {
else else
return GetSysString(1009); return GetSysString(1009);
} }
int i = 1000;
int string_id = 0; int string_id = 0;
for (unsigned filter = LOCATION_DECK; filter <= LOCATION_PZONE; filter <<= 1, ++i) { for (int i = 0; i < 10; ++i) {
if (filter == location) { if ((0x1U << i) == location) {
string_id = i; string_id = STRING_ID_LOCATION + i;
break; break;
} }
} }
...@@ -491,6 +491,11 @@ const wchar_t* DataManager::FormatLocation(int location, int sequence) const { ...@@ -491,6 +491,11 @@ const wchar_t* DataManager::FormatLocation(int location, int sequence) const {
else else
return unknown_string; return unknown_string;
} }
const wchar_t* DataManager::FormatLocation(ClientCard* card) const {
if (!card)
return unknown_string;
return FormatLocation(card->location, card->sequence);
}
std::wstring DataManager::FormatAttribute(unsigned int attribute) const { std::wstring DataManager::FormatAttribute(unsigned int attribute) const {
std::wstring buffer; std::wstring buffer;
for (int i = 0; i < ATTRIBUTES_COUNT; ++i) { for (int i = 0; i < ATTRIBUTES_COUNT; ++i) {
...@@ -501,7 +506,7 @@ std::wstring DataManager::FormatAttribute(unsigned int attribute) const { ...@@ -501,7 +506,7 @@ std::wstring DataManager::FormatAttribute(unsigned int attribute) const {
} }
} }
if (buffer.empty()) if (buffer.empty())
return std::wstring(unknown_string); buffer = unknown_string;
return buffer; return buffer;
} }
std::wstring DataManager::FormatRace(unsigned int race) const { std::wstring DataManager::FormatRace(unsigned int race) const {
...@@ -514,7 +519,7 @@ std::wstring DataManager::FormatRace(unsigned int race) const { ...@@ -514,7 +519,7 @@ std::wstring DataManager::FormatRace(unsigned int race) const {
} }
} }
if (buffer.empty()) if (buffer.empty())
return std::wstring(unknown_string); buffer = unknown_string;
return buffer; return buffer;
} }
std::wstring DataManager::FormatType(unsigned int type) const { std::wstring DataManager::FormatType(unsigned int type) const {
...@@ -527,7 +532,7 @@ std::wstring DataManager::FormatType(unsigned int type) const { ...@@ -527,7 +532,7 @@ std::wstring DataManager::FormatType(unsigned int type) const {
} }
} }
if (buffer.empty()) if (buffer.empty())
return std::wstring(unknown_string); buffer = unknown_string;
return buffer; return buffer;
} }
std::wstring DataManager::FormatSetName(const uint16_t setcode[]) const { std::wstring DataManager::FormatSetName(const uint16_t setcode[]) const {
...@@ -541,7 +546,7 @@ std::wstring DataManager::FormatSetName(const uint16_t setcode[]) const { ...@@ -541,7 +546,7 @@ std::wstring DataManager::FormatSetName(const uint16_t setcode[]) const {
buffer.append(setname); buffer.append(setname);
} }
if (buffer.empty()) if (buffer.empty())
return std::wstring(unknown_string); buffer = unknown_string;
return buffer; return buffer;
} }
std::wstring DataManager::FormatLinkMarker(unsigned int link_marker) const { std::wstring DataManager::FormatLinkMarker(unsigned int link_marker) const {
......
...@@ -58,6 +58,8 @@ struct CardString { ...@@ -58,6 +58,8 @@ struct CardString {
using code_pointer = std::unordered_map<uint32_t, CardDataC>::const_iterator; using code_pointer = std::unordered_map<uint32_t, CardDataC>::const_iterator;
using string_pointer = std::unordered_map<uint32_t, CardString>::const_iterator; using string_pointer = std::unordered_map<uint32_t, CardString>::const_iterator;
class ClientCard;
class DataManager { class DataManager {
public: public:
DataManager(); DataManager();
...@@ -109,6 +111,7 @@ public: ...@@ -109,6 +111,7 @@ public:
std::vector<unsigned int> GetSetCodes(std::wstring setname) const; std::vector<unsigned int> GetSetCodes(std::wstring setname) const;
std::wstring GetNumString(int num, bool bracket = false) const; std::wstring GetNumString(int num, bool bracket = false) const;
const wchar_t* FormatLocation(int location, int sequence) const; const wchar_t* FormatLocation(int location, int sequence) const;
const wchar_t* FormatLocation(ClientCard* card) const;
std::wstring FormatAttribute(unsigned int attribute) const; std::wstring FormatAttribute(unsigned int attribute) const;
std::wstring FormatRace(unsigned int race) const; std::wstring FormatRace(unsigned int race) const;
std::wstring FormatType(unsigned int type) const; std::wstring FormatType(unsigned int type) const;
...@@ -127,6 +130,7 @@ public: ...@@ -127,6 +130,7 @@ public:
irr::io::IFileSystem* FileSystem{}; irr::io::IFileSystem* FileSystem{};
#endif #endif
static constexpr int STRING_ID_LOCATION = 1000;
static constexpr int STRING_ID_ATTRIBUTE = 1010; static constexpr int STRING_ID_ATTRIBUTE = 1010;
static constexpr int STRING_ID_RACE = 1020; static constexpr int STRING_ID_RACE = 1020;
static constexpr int STRING_ID_TYPE = 1050; static constexpr int STRING_ID_TYPE = 1050;
......
...@@ -180,10 +180,12 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -180,10 +180,12 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
std::sort(deckManager.current_deck.main.begin(), deckManager.current_deck.main.end(), DataManager::deck_sort_lv); std::sort(deckManager.current_deck.main.begin(), deckManager.current_deck.main.end(), DataManager::deck_sort_lv);
std::sort(deckManager.current_deck.extra.begin(), deckManager.current_deck.extra.end(), DataManager::deck_sort_lv); std::sort(deckManager.current_deck.extra.begin(), deckManager.current_deck.extra.end(), DataManager::deck_sort_lv);
std::sort(deckManager.current_deck.side.begin(), deckManager.current_deck.side.end(), DataManager::deck_sort_lv); std::sort(deckManager.current_deck.side.begin(), deckManager.current_deck.side.end(), DataManager::deck_sort_lv);
is_modified = true;
break; break;
} }
case BUTTON_SHUFFLE_DECK: { case BUTTON_SHUFFLE_DECK: {
std::shuffle(deckManager.current_deck.main.begin(), deckManager.current_deck.main.end(), rnd); std::shuffle(deckManager.current_deck.main.begin(), deckManager.current_deck.main.end(), rnd);
is_modified = true;
break; break;
} }
case BUTTON_SAVE_DECK: { case BUTTON_SAVE_DECK: {
...@@ -746,17 +748,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -746,17 +748,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break; break;
} }
mainGame->ClearCardInfo(); mainGame->ClearCardInfo();
unsigned char deckbuf[1024]{}; DuelClient::SendUpdateDeck(deckManager.current_deck);
auto pdeck = deckbuf;
BufferIO::Write<int32_t>(pdeck, static_cast<int32_t>(deckManager.current_deck.main.size() + deckManager.current_deck.extra.size()));
BufferIO::Write<int32_t>(pdeck, static_cast<int32_t>(deckManager.current_deck.side.size()));
for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i)
BufferIO::Write<uint32_t>(pdeck, deckManager.current_deck.main[i]->first);
for(size_t i = 0; i < deckManager.current_deck.extra.size(); ++i)
BufferIO::Write<uint32_t>(pdeck, deckManager.current_deck.extra[i]->first);
for(size_t i = 0; i < deckManager.current_deck.side.size(); ++i)
BufferIO::Write<uint32_t>(pdeck, deckManager.current_deck.side[i]->first);
DuelClient::SendBufferToServer(CTOS_UPDATE_DECK, deckbuf, pdeck - deckbuf);
break; break;
} }
case BUTTON_SIDE_RELOAD: { case BUTTON_SIDE_RELOAD: {
...@@ -794,6 +786,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -794,6 +786,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
deckManager.current_deck.main.clear(); deckManager.current_deck.main.clear();
deckManager.current_deck.extra.clear(); deckManager.current_deck.extra.clear();
deckManager.current_deck.side.clear(); deckManager.current_deck.side.clear();
is_modified = true;
} else if(prev_operation == BUTTON_DELETE_DECK) { } else if(prev_operation == BUTTON_DELETE_DECK) {
int sel = prev_sel; int sel = prev_sel;
mainGame->cbDBDecks->setSelected(sel); mainGame->cbDBDecks->setSelected(sel);
...@@ -1137,6 +1130,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -1137,6 +1130,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
is_starting_dragging = false; is_starting_dragging = false;
irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement(); irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement();
if(!is_draging && !mainGame->is_siding && root->getElementFromPoint(mouse_pos) == mainGame->imgCard) { if(!is_draging && !mainGame->is_siding && root->getElementFromPoint(mouse_pos) == mainGame->imgCard) {
soundManager.PlaySoundEffect(SOUND_CARD_DROP);
ShowBigCard(mainGame->showingcode, 1); ShowBigCard(mainGame->showingcode, 1);
break; break;
} }
...@@ -1166,6 +1160,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -1166,6 +1160,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
case irr::EMIE_LMOUSE_DOUBLE_CLICK: { case irr::EMIE_LMOUSE_DOUBLE_CLICK: {
irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement(); irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement();
if(!is_draging && !mainGame->is_siding && root->getElementFromPoint(mouse_pos) == root && hovered_code) { if(!is_draging && !mainGame->is_siding && root->getElementFromPoint(mouse_pos) == root && hovered_code) {
soundManager.PlaySoundEffect(SOUND_CARD_DROP);
ShowBigCard(hovered_code, 1); ShowBigCard(hovered_code, 1);
break; break;
} }
...@@ -1425,8 +1420,6 @@ void DeckBuilder::GetHoveredCard() { ...@@ -1425,8 +1420,6 @@ void DeckBuilder::GetHoveredCard() {
if(!is_draging && pre_code != hovered_code) { if(!is_draging && pre_code != hovered_code) {
if(hovered_code) if(hovered_code)
mainGame->ShowCardInfo(hovered_code); mainGame->ShowCardInfo(hovered_code);
if(pre_code)
imageManager.RemoveTexture(pre_code);
} }
} }
void DeckBuilder::StartFilter() { void DeckBuilder::StartFilter() {
......
...@@ -946,11 +946,11 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) { ...@@ -946,11 +946,11 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) {
break; break;
} }
case STOC_HS_PLAYER_ENTER: { case STOC_HS_PLAYER_ENTER: {
if (len < 1 + STOC_HS_PlayerEnter_size) if (len < 1 + sizeof(STOC_HS_PlayerEnter))
return; return;
soundManager.PlaySoundEffect(SOUND_PLAYER_ENTER); soundManager.PlaySoundEffect(SOUND_PLAYER_ENTER);
STOC_HS_PlayerEnter packet; STOC_HS_PlayerEnter packet;
std::memcpy(&packet, pdata, STOC_HS_PlayerEnter_size); std::memcpy(&packet, pdata, sizeof(STOC_HS_PlayerEnter));
auto pkt = &packet; auto pkt = &packet;
if(pkt->pos > 3) if(pkt->pos > 3)
break; break;
...@@ -3164,9 +3164,9 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) { ...@@ -3164,9 +3164,9 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
ClientCard* pcard = mainGame->dField.GetCard(cc, cl, cs); ClientCard* pcard = mainGame->dField.GetCard(cc, cl, cs);
pcard->SetCode(code); pcard->SetCode(code);
pcard->position = cp; pcard->position = cp;
if(!mainGame->dInfo.isReplaySkiping) { if(!mainGame->dInfo.isReplaySkiping) {
soundManager.PlaySoundEffect(SOUND_FILP); soundManager.PlaySoundEffect(SOUND_FLIP);
myswprintf(event_string, dataManager.GetSysString(1607), dataManager.GetName(code)); myswprintf(event_string, dataManager.GetSysString(1607), dataManager.GetName(code));
mainGame->dField.MoveCard(pcard, 10); mainGame->dField.MoveCard(pcard, 10);
mainGame->WaitFrameSignal(11); mainGame->WaitFrameSignal(11);
mainGame->showcardcode = code; mainGame->showcardcode = code;
...@@ -4335,6 +4335,19 @@ void DuelClient::SendResponse() { ...@@ -4335,6 +4335,19 @@ void DuelClient::SendResponse() {
SendBufferToServer(CTOS_RESPONSE, response_buf, response_len); SendBufferToServer(CTOS_RESPONSE, response_buf, response_len);
} }
} }
void DuelClient::SendUpdateDeck(const Deck& deck) {
std::vector<unsigned char> deckbuf;
deckbuf.reserve(1024);
BufferIO::VectorWrite<int32_t>(deckbuf, static_cast<int32_t>(deck.main.size() + deck.extra.size()));
BufferIO::VectorWrite<int32_t>(deckbuf, static_cast<int32_t>(deck.side.size()));
for (const auto& card: deck.main)
BufferIO::VectorWrite<uint32_t>(deckbuf, card->first);
for (const auto& card: deck.extra)
BufferIO::VectorWrite<uint32_t>(deckbuf, card->first);
for (const auto& card: deck.side)
BufferIO::VectorWrite<uint32_t>(deckbuf, card->first);
SendBufferToServer(CTOS_UPDATE_DECK, deckbuf.data(), deckbuf.size());
}
void DuelClient::BeginRefreshHost() { void DuelClient::BeginRefreshHost() {
if(is_refreshing) if(is_refreshing)
return; return;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <set> #include <set>
#include <random> #include <random>
#include "config.h" #include "config.h"
#include "deck_manager.h"
#include "network.h" #include "network.h"
namespace ygo { namespace ygo {
...@@ -91,6 +92,7 @@ public: ...@@ -91,6 +92,7 @@ public:
static void SetResponseI(int32_t respI); static void SetResponseI(int32_t respI);
static void SetResponseB(void* respB, size_t len); static void SetResponseB(void* respB, size_t len);
static void SendResponse(); static void SendResponse();
static void SendUpdateDeck(const Deck& deck);
static unsigned int LookupHost(char *host); static unsigned int LookupHost(char *host);
static bool LookupSRV(char *hostname, HostResult* result); static bool LookupSRV(char *hostname, HostResult* result);
static bool CheckHostnameSplitter(char *hostname, HostResult *result); static bool CheckHostnameSplitter(char *hostname, HostResult *result);
......
...@@ -920,19 +920,18 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -920,19 +920,18 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
else else
myswprintf(formatBuffer, L""); myswprintf(formatBuffer, L"");
} else { } else {
if(select_continuous) if (select_continuous)
myswprintf(formatBuffer, L"%ls", dataManager.unknown_string); myswprintf(formatBuffer, L"%ls", dataManager.unknown_string);
else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE) else if (cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE)
myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0)); myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0));
else if(selectable_cards[i + pos]->location == LOCATION_OVERLAY) else if (selectable_cards[i + pos]->location == LOCATION_OVERLAY)
myswprintf(formatBuffer, L"%ls[%d](%d)", myswprintf(formatBuffer, L"%ls[%d](%d)",
dataManager.FormatLocation(selectable_cards[i + pos]->overlayTarget->location, selectable_cards[i + pos]->overlayTarget->sequence), dataManager.FormatLocation(selectable_cards[i + pos]->overlayTarget),
selectable_cards[i + pos]->overlayTarget->sequence + 1, selectable_cards[i + pos]->sequence + 1); selectable_cards[i + pos]->overlayTarget->sequence + 1, selectable_cards[i + pos]->sequence + 1);
else if (selectable_cards[i]->location == 0) else if (selectable_cards[i]->location == 0)
myswprintf(formatBuffer, L""); myswprintf(formatBuffer, L"");
else else
myswprintf(formatBuffer, L"%ls[%d]", dataManager.FormatLocation(selectable_cards[i + pos]->location, selectable_cards[i + pos]->sequence), myswprintf(formatBuffer, L"%ls[%d]", dataManager.FormatLocation(selectable_cards[i + pos]), selectable_cards[i + pos]->sequence + 1);
selectable_cards[i + pos]->sequence + 1);
} }
mainGame->stCardPos[i]->setText(formatBuffer); mainGame->stCardPos[i]->setText(formatBuffer);
// color // color
...@@ -978,13 +977,11 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -978,13 +977,11 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
mainGame->btnCardDisplay[i]->setImage(imageManager.tCover[display_cards[i + pos]->controler + 2]); mainGame->btnCardDisplay[i]->setImage(imageManager.tCover[display_cards[i + pos]->controler + 2]);
mainGame->btnCardDisplay[i]->setRelativePosition(irr::core::rect<irr::s32>(30 + i * 125, 55, 30 + 120 + i * 125, 225)); mainGame->btnCardDisplay[i]->setRelativePosition(irr::core::rect<irr::s32>(30 + i * 125, 55, 30 + 120 + i * 125, 225));
wchar_t formatBuffer[2048]; wchar_t formatBuffer[2048];
if(display_cards[i + pos]->location == LOCATION_OVERLAY) { if(display_cards[i + pos]->location == LOCATION_OVERLAY)
myswprintf(formatBuffer, L"%ls[%d](%d)", myswprintf(formatBuffer, L"%ls[%d](%d)",
dataManager.FormatLocation(display_cards[i + pos]->overlayTarget->location, display_cards[i + pos]->overlayTarget->sequence), dataManager.FormatLocation(display_cards[i + pos]->overlayTarget), display_cards[i + pos]->overlayTarget->sequence + 1, display_cards[i + pos]->sequence + 1);
display_cards[i + pos]->overlayTarget->sequence + 1, display_cards[i + pos]->sequence + 1); else
} else myswprintf(formatBuffer, L"%ls[%d]", dataManager.FormatLocation(display_cards[i + pos]), display_cards[i + pos]->sequence + 1);
myswprintf(formatBuffer, L"%ls[%d]", dataManager.FormatLocation(display_cards[i + pos]->location, display_cards[i + pos]->sequence),
display_cards[i + pos]->sequence + 1);
mainGame->stDisplayPos[i]->setText(formatBuffer); mainGame->stDisplayPos[i]->setText(formatBuffer);
if(display_cards[i + pos]->location == LOCATION_OVERLAY) { if(display_cards[i + pos]->location == LOCATION_OVERLAY) {
if(display_cards[i + pos]->owner != display_cards[i + pos]->overlayTarget->controler) if(display_cards[i + pos]->owner != display_cards[i + pos]->overlayTarget->controler)
......
...@@ -1257,16 +1257,13 @@ void Game::InitStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cWidth, i ...@@ -1257,16 +1257,13 @@ void Game::InitStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cWidth, i
scrCardText->setPos(0); scrCardText->setPos(0);
} }
std::wstring Game::SetStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cWidth, irr::gui::CGUITTFont* font, const wchar_t* text, irr::u32 pos) { std::wstring Game::SetStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cWidth, irr::gui::CGUITTFont* font, const wchar_t* text, irr::u32 pos) {
size_t pbuffer = 0;
irr::u32 _width = 0, _height = 0; irr::u32 _width = 0, _height = 0;
wchar_t prev = 0; wchar_t prev = 0;
wchar_t strBuffer[4096]{}; std::wstring result;
constexpr size_t buffer_len = sizeof strBuffer / sizeof strBuffer[0] - 1; result.reserve(4096);
const size_t text_len = std::wcslen(text); const size_t text_len = std::wcslen(text);
for(size_t i = 0; i < text_len ; ++i) { for(size_t i = 0; i < text_len ; ++i) {
if (pbuffer >= buffer_len)
break;
wchar_t c = text[i]; wchar_t c = text[i];
irr::u32 w = font->getCharDimension(c).Width + font->getKerningWidth(c, prev); irr::u32 w = font->getCharDimension(c).Width + font->getKerningWidth(c, prev);
prev = c; prev = c;
...@@ -1274,31 +1271,28 @@ std::wstring Game::SetStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cW ...@@ -1274,31 +1271,28 @@ std::wstring Game::SetStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cW
continue; continue;
} }
if (c == L'\n') { if (c == L'\n') {
strBuffer[pbuffer++] = L'\n'; result.push_back(L'\n');
_width = 0; _width = 0;
_height++; _height++;
prev = 0; prev = 0;
if (_height == pos) if (_height == pos)
pbuffer = 0; result.clear();
continue; continue;
} }
if (_width > 0 && _width + w > cWidth) { if (_width > 0 && _width + w > cWidth) {
strBuffer[pbuffer++] = L'\n'; result.push_back(L'\n');
_width = 0; _width = 0;
_height++; _height++;
prev = 0; prev = 0;
if (_height == pos) if (_height == pos)
pbuffer = 0; result.clear();
} }
if (pbuffer >= buffer_len)
break;
_width += w; _width += w;
strBuffer[pbuffer++] = c; result.push_back(c);
} }
strBuffer[pbuffer] = 0;
if (pControl) if (pControl)
pControl->setText(strBuffer); pControl->setText(result.c_str());
return std::wstring(strBuffer); return result;
} }
#endif //YGOPRO_SERVER_MODE #endif //YGOPRO_SERVER_MODE
void Game::LoadExpansions(const wchar_t* expansions_path) { void Game::LoadExpansions(const wchar_t* expansions_path) {
...@@ -1646,8 +1640,6 @@ bool Game::LoadConfigFromFile(const char* file) { ...@@ -1646,8 +1640,6 @@ bool Game::LoadConfigFromFile(const char* file) {
gameConf.antialias = std::strtol(valbuf, nullptr, 10); gameConf.antialias = std::strtol(valbuf, nullptr, 10);
} else if(!std::strcmp(strbuf, "use_d3d")) { } else if(!std::strcmp(strbuf, "use_d3d")) {
gameConf.use_d3d = std::strtol(valbuf, nullptr, 10) > 0; gameConf.use_d3d = std::strtol(valbuf, nullptr, 10) > 0;
} else if(!std::strcmp(strbuf, "use_image_scale")) {
gameConf.use_image_scale = std::strtol(valbuf, nullptr, 10) > 0;
} else if (!std::strcmp(strbuf, "use_image_scale_multi_thread")) { } else if (!std::strcmp(strbuf, "use_image_scale_multi_thread")) {
gameConf.use_image_scale_multi_thread = std::strtol(valbuf, nullptr, 10) > 0; gameConf.use_image_scale_multi_thread = std::strtol(valbuf, nullptr, 10) > 0;
} else if (!std::strcmp(strbuf, "use_image_load_background_thread")) { } else if (!std::strcmp(strbuf, "use_image_load_background_thread")) {
...@@ -1796,60 +1788,6 @@ bool Game::LoadConfigFromFile(const char* file) { ...@@ -1796,60 +1788,6 @@ bool Game::LoadConfigFromFile(const char* file) {
return true; return true;
} }
void Game::LoadConfig() { void Game::LoadConfig() {
gameConf.use_d3d = 0;
gameConf.use_image_scale = 1;
gameConf.antialias = 0;
gameConf.serverport = 7911;
gameConf.textfontsize = 14;
gameConf.nickname[0] = 0;
gameConf.gamename[0] = 0;
gameConf.bot_deck_path[0] = 0;
gameConf.lastcategory[0] = 0;
gameConf.lastdeck[0] = 0;
gameConf.numfont[0] = 0;
gameConf.textfont[0] = 0;
gameConf.lasthost[0] = 0;
gameConf.roompass[0] = 0;
//settings
gameConf.chkMAutoPos = 0;
gameConf.chkSTAutoPos = 1;
gameConf.chkRandomPos = 0;
gameConf.chkAutoChain = 0;
gameConf.chkWaitChain = 0;
gameConf.chkDefaultShowChain = 0;
gameConf.chkIgnore1 = 0;
gameConf.chkIgnore2 = 0;
gameConf.use_lflist = 1;
gameConf.default_lflist = 0;
gameConf.default_rule = YGOPRO_DEFAULT_DUEL_RULE;
gameConf.hide_setname = 0;
gameConf.hide_hint_button = 0;
gameConf.control_mode = 0;
gameConf.draw_field_spell = 1;
gameConf.separate_clear_button = 1;
gameConf.auto_search_limit = 0;
gameConf.search_multiple_keywords = 1;
gameConf.search_regex = 0;
gameConf.chkIgnoreDeckChanges = 0;
gameConf.defaultOT = 1;
gameConf.enable_bot_mode = 1;
gameConf.quick_animation = 0;
gameConf.auto_save_replay = 0;
gameConf.draw_single_chain = 0;
gameConf.hide_player_name = 0;
gameConf.prefer_expansion_script = 0;
gameConf.ask_mset = 0;
gameConf.enable_sound = true;
gameConf.sound_volume = 0.5;
gameConf.enable_music = true;
gameConf.music_volume = 0.5;
gameConf.music_mode = 1;
gameConf.window_maximized = false;
gameConf.window_width = 1024;
gameConf.window_height = 640;
gameConf.resize_popup_menu = false;
gameConf.chkEnablePScale = 1;
gameConf.skin_index = -1;
LoadConfigFromFile("system.conf"); //default config LoadConfigFromFile("system.conf"); //default config
#ifdef YGOPRO_COMPAT_MYCARD #ifdef YGOPRO_COMPAT_MYCARD
if(!gameConf.locale || wcslen(gameConf.locale) <= 0) if(!gameConf.locale || wcslen(gameConf.locale) <= 0)
...@@ -1909,9 +1847,6 @@ void Game::LoadConfig() { ...@@ -1909,9 +1847,6 @@ void Game::LoadConfig() {
lcid = 0x16; lcid = 0x16;
} }
*/ */
#endif
#ifndef YGOPRO_COMPAT_MYCARD
//SaveConfig();
#endif #endif
} }
} }
...@@ -1924,7 +1859,6 @@ void Game::SaveConfig() { ...@@ -1924,7 +1859,6 @@ void Game::SaveConfig() {
std::fprintf(fp, "#config file\n#nickname & gamename should be less than 20 characters\n"); std::fprintf(fp, "#config file\n#nickname & gamename should be less than 20 characters\n");
char linebuf[CONFIG_LINE_SIZE]; char linebuf[CONFIG_LINE_SIZE];
std::fprintf(fp, "use_d3d = %d\n", gameConf.use_d3d ? 1 : 0); std::fprintf(fp, "use_d3d = %d\n", gameConf.use_d3d ? 1 : 0);
std::fprintf(fp, "use_image_scale = %d\n", gameConf.use_image_scale ? 1 : 0);
std::fprintf(fp, "use_image_scale_multi_thread = %d\n", gameConf.use_image_scale_multi_thread ? 1 : 0); std::fprintf(fp, "use_image_scale_multi_thread = %d\n", gameConf.use_image_scale_multi_thread ? 1 : 0);
std::fprintf(fp, "use_image_load_background_thread = %d\n", gameConf.use_image_load_background_thread ? 1 : 0); std::fprintf(fp, "use_image_load_background_thread = %d\n", gameConf.use_image_load_background_thread ? 1 : 0);
std::fprintf(fp, "pro_version = %d\n", PRO_VERSION); std::fprintf(fp, "pro_version = %d\n", PRO_VERSION);
......
...@@ -58,7 +58,6 @@ bool IsExtension(const char* filename, const char(&extension)[N]) { ...@@ -58,7 +58,6 @@ bool IsExtension(const char* filename, const char(&extension)[N]) {
#ifndef YGOPRO_SERVER_MODE #ifndef YGOPRO_SERVER_MODE
struct Config { struct Config {
bool use_d3d{ false }; bool use_d3d{ false };
bool use_image_scale{ true };
bool use_image_scale_multi_thread{ true }; bool use_image_scale_multi_thread{ true };
#ifdef _OPENMP #ifdef _OPENMP
bool use_image_load_background_thread{ false }; bool use_image_load_background_thread{ false };
......
This diff is collapsed.
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
namespace ygo { namespace ygo {
class ImageManager { class ImageManager {
private:
irr::video::ITexture* addTexture(const char* name, irr::video::IImage* srcimg, irr::s32 width, irr::s32 height);
public: public:
std::vector<std::wstring> ImageList[7]; std::vector<std::wstring> ImageList[7];
int saved_image_id[7]; int saved_image_id[7];
...@@ -21,9 +23,10 @@ public: ...@@ -21,9 +23,10 @@ public:
void RefreshImageDir(std::wstring path, int image_type); void RefreshImageDir(std::wstring path, int image_type);
void SetDevice(irr::IrrlichtDevice* dev); void SetDevice(irr::IrrlichtDevice* dev);
void ClearTexture(); void ClearTexture();
void RemoveTexture(int code);
void ResizeTexture(); void ResizeTexture();
irr::video::ITexture* GetTextureFromFile(const char* file, irr::s32 width, irr::s32 height); irr::video::ITexture* GetTextureFromFile(const char* file, irr::s32 width, irr::s32 height);
irr::video::IImage* GetImage(int code);
irr::video::ITexture* GetTexture(int code, irr::s32 width, irr::s32 height);
irr::video::ITexture* GetTexture(int code, bool fit = false); irr::video::ITexture* GetTexture(int code, bool fit = false);
irr::video::ITexture* GetBigPicture(int code, float zoom); irr::video::ITexture* GetBigPicture(int code, float zoom);
irr::video::ITexture* GetTextureThumb(int code); irr::video::ITexture* GetTextureThumb(int code);
......
...@@ -15,17 +15,7 @@ namespace ygo { ...@@ -15,17 +15,7 @@ namespace ygo {
void UpdateDeck() { void UpdateDeck() {
BufferIO::CopyWideString(mainGame->cbCategorySelect->getText(), mainGame->gameConf.lastcategory); BufferIO::CopyWideString(mainGame->cbCategorySelect->getText(), mainGame->gameConf.lastcategory);
BufferIO::CopyWideString(mainGame->cbDeckSelect->getText(), mainGame->gameConf.lastdeck); BufferIO::CopyWideString(mainGame->cbDeckSelect->getText(), mainGame->gameConf.lastdeck);
unsigned char deckbuf[1024]{}; DuelClient::SendUpdateDeck(deckManager.current_deck);
auto pdeck = deckbuf;
BufferIO::Write<int32_t>(pdeck, static_cast<int32_t>(deckManager.current_deck.main.size() + deckManager.current_deck.extra.size()));
BufferIO::Write<int32_t>(pdeck, static_cast<int32_t>(deckManager.current_deck.side.size()));
for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i)
BufferIO::Write<uint32_t>(pdeck, deckManager.current_deck.main[i]->first);
for(size_t i = 0; i < deckManager.current_deck.extra.size(); ++i)
BufferIO::Write<uint32_t>(pdeck, deckManager.current_deck.extra[i]->first);
for(size_t i = 0; i < deckManager.current_deck.side.size(); ++i)
BufferIO::Write<uint32_t>(pdeck, deckManager.current_deck.side[i]->first);
DuelClient::SendBufferToServer(CTOS_UPDATE_DECK, deckbuf, pdeck - deckbuf);
} }
bool MenuHandler::OnEvent(const irr::SEvent& event) { bool MenuHandler::OnEvent(const irr::SEvent& event) {
if(mainGame->dField.OnCommonEvent(event)) if(mainGame->dField.OnCommonEvent(event))
......
...@@ -172,14 +172,14 @@ constexpr int LEN_CHAT_PLAYER = 1; ...@@ -172,14 +172,14 @@ constexpr int LEN_CHAT_PLAYER = 1;
constexpr int LEN_CHAT_MSG = 256; constexpr int LEN_CHAT_MSG = 256;
constexpr int SIZE_STOC_CHAT = (LEN_CHAT_PLAYER + LEN_CHAT_MSG) * sizeof(uint16_t); constexpr int SIZE_STOC_CHAT = (LEN_CHAT_PLAYER + LEN_CHAT_MSG) * sizeof(uint16_t);
#pragma pack(push, 1)
struct STOC_HS_PlayerEnter { struct STOC_HS_PlayerEnter {
uint16_t name[20]{}; uint16_t name[20]{};
uint8_t pos{}; uint8_t pos{};
// byte padding[1]
}; };
#pragma pack(pop)
check_trivially_copyable(STOC_HS_PlayerEnter); check_trivially_copyable(STOC_HS_PlayerEnter);
//static_assert(sizeof(STOC_HS_PlayerEnter) == 42, "size mismatch: STOC_HS_PlayerEnter"); static_assert(sizeof(STOC_HS_PlayerEnter) == 41, "size mismatch: STOC_HS_PlayerEnter");
constexpr int STOC_HS_PlayerEnter_size = 41; //workwround
struct STOC_HS_PlayerChange { struct STOC_HS_PlayerChange {
//pos<<4 | state //pos<<4 | state
......
...@@ -142,7 +142,7 @@ void SoundManager::PlaySoundEffect(int sound) { ...@@ -142,7 +142,7 @@ void SoundManager::PlaySoundEffect(int sound) {
strcpy(soundName, "set"); strcpy(soundName, "set");
break; break;
} }
case SOUND_FILP: { case SOUND_FLIP: {
strcpy(soundName, "flip"); strcpy(soundName, "flip");
break; break;
} }
......
...@@ -61,7 +61,7 @@ extern SoundManager soundManager; ...@@ -61,7 +61,7 @@ extern SoundManager soundManager;
#define SOUND_SPECIAL_SUMMON 102 #define SOUND_SPECIAL_SUMMON 102
#define SOUND_ACTIVATE 103 #define SOUND_ACTIVATE 103
#define SOUND_SET 104 #define SOUND_SET 104
#define SOUND_FILP 105 #define SOUND_FLIP 105
#define SOUND_REVEAL 106 #define SOUND_REVEAL 106
#define SOUND_EQUIP 107 #define SOUND_EQUIP 107
#define SOUND_DESTROYED 108 #define SOUND_DESTROYED 108
......
This diff is collapsed.
Subproject commit 6ee4147f21b30aa386368c920cdc4468d2e58569 Subproject commit bf0e868b058dc5255a9219c9c485e56fdfeae477
Subproject commit 7d871e9a3cdbed474150ea221e5e7632e53afe67 Subproject commit 325de7ece43038683c3097b5856c513e04a295c0
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