Skip to content

Commit 300446a

Browse files
committed
Merge branch 'upstream' into patch-genesys
2 parents f82db88 + 4f2069d commit 300446a

50 files changed

Lines changed: 1270 additions & 792 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 184 additions & 71 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
/WindBot
1414
/cards.cdb
1515
/error.log
16+
/system.conf
1617
/bot.conf
1718
/Bot.exe
1819
/bot
1920

2021
/ygopro
2122
/ygopro.exe
2223
/ygopro.app
23-
/ikpMP3.dll
24-
/irrKlang.dll
2524

2625
/.vscode/
2726
/bin/
@@ -31,11 +30,11 @@
3130
/freetype
3231
/irrlicht
3332
/jpeg
34-
/irrklang
35-
/ikpmp3
3633
/lua
3734
/miniaudio
35+
/png
3836
/sqlite3
37+
/zlib
3938
/gframe/*.ico
4039
/gframe/ygopro.rc
4140
/gframe/ygopro.aps

gframe/CGUITTFont.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ video::IImage* SGUITTGlyph::createGlyphImage(const FT_Bitmap& bits, video::IVide
7777

7878
// Load the monochrome data in.
7979
const u32 image_pitch = image->getPitch() / sizeof(u16);
80-
u16* image_data = (u16*)image->lock();
80+
u16* image_data = (u16*)image->getData();
8181
u8* glyph_data = bits.buffer;
8282
for (s32 y = 0; y < (s32)bits.rows; ++y) {
8383
u16* row = image_data;
@@ -102,7 +102,7 @@ video::IImage* SGUITTGlyph::createGlyphImage(const FT_Bitmap& bits, video::IVide
102102
// Load the grayscale data in.
103103
const float gray_count = static_cast<float>(bits.num_grays);
104104
const u32 image_pitch = image->getPitch() / sizeof(u32);
105-
u32* image_data = (u32*)image->lock();
105+
u32* image_data = (u32*)image->getData();
106106
u8* glyph_data = bits.buffer;
107107
for (s32 y = 0; y < (s32)bits.rows; ++y) {
108108
u8* row = glyph_data;

gframe/bufferio.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class BufferIO {
7777
return l;
7878
}
7979
template<typename T1, typename T2>
80+
[[deprecated]]
8081
static int CopyWStrRef(const T1* src, T2*& pstr, int bufsize) {
8182
int l = 0;
8283
while(src[l] && l < bufsize - 1) {
@@ -122,27 +123,25 @@ class BufferIO {
122123
}
123124
// UTF-16/UTF-32 to UTF-8
124125
// return: string length
125-
static int EncodeUTF8String(const wchar_t* wsrc, char* str, size_t len) {
126-
if (len == 0) {
127-
str[0] = 0;
126+
static int EncodeUTF8String(const wchar_t* wsrc, char* str, size_t size) {
127+
if (size == 0) {
128128
return 0;
129129
}
130130
std::mbstate_t state{};
131-
size_t result_len = std::wcsrtombs(str, &wsrc, len - 1, &state);
131+
size_t result_len = std::wcsrtombs(str, &wsrc, size - 1, &state);
132132
if (result_len == static_cast<size_t>(-1))
133133
result_len = 0;
134134
str[result_len] = 0;
135135
return static_cast<int>(result_len);
136136
}
137137
// UTF-8 to UTF-16/UTF-32
138138
// return: string length
139-
static int DecodeUTF8String(const char* src, wchar_t* wstr, size_t len) {
140-
if (len == 0) {
141-
wstr[0] = 0;
139+
static int DecodeUTF8String(const char* src, wchar_t* wstr, size_t size) {
140+
if (size == 0) {
142141
return 0;
143142
}
144143
std::mbstate_t state{};
145-
size_t result_len = std::mbsrtowcs(wstr, &src, len - 1, &state);
144+
size_t result_len = std::mbsrtowcs(wstr, &src, size - 1, &state);
146145
if (result_len == static_cast<size_t>(-1))
147146
result_len = 0;
148147
wstr[result_len] = 0;

gframe/client_card.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ void ClientCard::UpdateInfo(unsigned char* buf) {
141141
if(flag & QUERY_OVERLAY_CARD) {
142142
int count = BufferIO::Read<int32_t>(buf);
143143
for(int i = 0; i < count; ++i) {
144+
if(i >= overlayed.size()) {
145+
ClientCard* xcard = new ClientCard;
146+
overlayed.push_back(xcard);
147+
mainGame->dField.overlay_cards.insert(xcard);
148+
xcard->overlayTarget = this;
149+
xcard->location = LOCATION_OVERLAY;
150+
xcard->sequence = (unsigned char)(overlayed.size() - 1);
151+
xcard->owner = controler; // not accurate
152+
xcard->controler = controler;
153+
}
144154
overlayed[i]->SetCode(BufferIO::Read<int32_t>(buf));
145155
}
146156
}

gframe/client_field.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir
10501050
return;
10511051
}
10521052
int oseq = pcard->overlayTarget->sequence;
1053-
int mseq = (sequence < MAX_LAYER_COUNT) ? sequence : (MAX_LAYER_COUNT - 1);
1053+
int mseq = myclamp(sequence, 0, MAX_LAYER_COUNT - 1);
10541054
if (pcard->overlayTarget->controler == 0) {
10551055
t->X = (matManager.vFieldMzone[0][oseq][0].Pos.X + matManager.vFieldMzone[0][oseq][1].Pos.X) / 2 - 0.12f + 0.06f * mseq;
10561056
t->Y = (matManager.vFieldMzone[0][oseq][0].Pos.Y + matManager.vFieldMzone[0][oseq][2].Pos.Y) / 2 + 0.05f;
@@ -1175,7 +1175,7 @@ bool ClientField::CheckSelectSum() {
11751175
int op1 = selected_cards[i]->opParam & 0xffff;
11761176
int op2 = selected_cards[i]->opParam >> 16;
11771177
int opmin = (op2 > 0 && op1 > op2) ? op2 : op1;
1178-
int opmax = op2 > op1 ? op2 : op1;
1178+
int opmax = std::max(op1, op2);
11791179
select_curval_l += opmin;
11801180
select_curval_h += opmax;
11811181
}
@@ -1198,7 +1198,7 @@ bool ClientField::CheckSelectSum() {
11981198
int op1, op2;
11991199
get_sum_params(sc->opParam, op1, op2);
12001200
int opmin = (op2 > 0 && op1 > op2) ? op2 : op1;
1201-
int opmax = op2 > op1 ? op2 : op1;
1201+
int opmax = std::max(op1, op2);
12021202
if (mm == -1 || opmin < mm)
12031203
mm = opmin;
12041204
if (mx == -1 || opmax < mx)

gframe/config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ template<size_t N, typename... TR>
5757
inline int mysnprintf(char(&buf)[N], const char* fmt, TR... args) {
5858
return std::snprintf(buf, N, fmt, args...);
5959
}
60+
template<typename T>
61+
inline T myclamp(T v, T lo, T hi) {
62+
return (v < lo) ? lo : (hi < v) ? hi : v;
63+
}
6064

6165
inline FILE* mywfopen(const wchar_t* filename, const char* mode) {
6266
FILE* fp{};

gframe/data_manager.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,27 +176,30 @@ bool DataManager::LoadStrings(irr::io::IReadFile* reader) {
176176
linebuf.clear();
177177
}
178178
}
179+
if (!linebuf.empty()) {
180+
ReadStringConfLine(linebuf.data());
181+
}
179182
reader->drop();
180183
return true;
181184
}
182185
void DataManager::ReadStringConfLine(const char* linebuf) {
183186
if(linebuf[0] != '!')
184187
return;
185188
char strbuf[TEXT_LINE_SIZE]{};
186-
int value{};
189+
uint32_t value{};
187190
wchar_t strBuffer[4096]{};
188191
if (std::sscanf(linebuf, "!%63s", strbuf) != 1)
189192
return;
190193
if(!std::strcmp(strbuf, "system")) {
191-
if (std::sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf) != 2)
194+
if (std::sscanf(&linebuf[7], "%u %240[^\n]", &value, strbuf) != 2)
192195
return;
193196
BufferIO::DecodeUTF8(strbuf, strBuffer);
194-
_sysStrings[value] = strBuffer;
197+
_sysStrings.emplace(value, strBuffer);
195198
} else if(!std::strcmp(strbuf, "victory")) {
196199
if (std::sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
197200
return;
198201
BufferIO::DecodeUTF8(strbuf, strBuffer);
199-
_victoryStrings[value] = strBuffer;
202+
_victoryStrings.emplace(value, strBuffer);
200203
} else if(!std::strcmp(strbuf, "counter")) {
201204
if (std::sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
202205
return;
@@ -260,7 +263,7 @@ const wchar_t* DataManager::GetText(uint32_t code) const {
260263
return unknown_string;
261264
}
262265
const wchar_t* DataManager::GetDesc(uint32_t strCode) const {
263-
if (strCode < (MIN_CARD_ID << 4))
266+
if (strCode <= MAX_STRING_ID)
264267
return GetSysString(strCode);
265268
unsigned int code = (strCode >> 4) & 0x0fffffff;
266269
unsigned int offset = strCode & 0xf;

gframe/deck.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
#include <vector>
55
#include <cstdint>
6-
#include "data_manager.h"
76

87
namespace ygo {
98

9+
struct CardDataC;
10+
1011
struct Deck {
1112
std::vector<const CardDataC*> main;
1213
std::vector<const CardDataC*> extra;

gframe/deck_con.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <array>
33
#include "config.h"
44
#include "deck_con.h"
5+
#include "data_manager.h"
6+
#include "deck_manager.h"
57
#include "myfilesystem.h"
68
#include "image_manager.h"
79
#include "sound_manager.h"
@@ -1746,10 +1748,7 @@ void DeckBuilder::ShowBigCard(int code, float zoom) {
17461748
mainGame->gMutex.unlock();
17471749
}
17481750
void DeckBuilder::ZoomBigCard(irr::s32 centerx, irr::s32 centery) {
1749-
if(bigcard_zoom >= 4)
1750-
bigcard_zoom = 4;
1751-
if(bigcard_zoom <= 0.2f)
1752-
bigcard_zoom = 0.2f;
1751+
bigcard_zoom = myclamp(bigcard_zoom, 0.2f, 4.0f);
17531752
auto img = imageManager.GetBigPicture(bigcard_code, bigcard_zoom);
17541753
mainGame->imgBigCard->setImage(img);
17551754
auto size = img->getSize();

0 commit comments

Comments
 (0)