Commit 944a7897 authored by nanahira's avatar nanahira

Merge branch 'develop-nanahira' into 'develop'

Develop update

See merge request nanahira/ygopro!1
parents 25e5c6a4 3a6724a5
No preview for this file type
......@@ -6,40 +6,36 @@
class BufferIO {
public:
inline static int ReadInt32(unsigned char*& p) {
static int ReadInt32(unsigned char*& p) {
return buffer_read<int32_t>(p);
}
inline static unsigned int ReadUInt32(unsigned char*& p) {
unsigned int ret = *(unsigned int*)p;
p += 4;
return ret;
static unsigned int ReadUInt32(unsigned char*& p) {
return buffer_read<uint32_t>(p);
}
inline static short ReadInt16(unsigned char*& p) {
static short ReadInt16(unsigned char*& p) {
return buffer_read<int16_t>(p);
}
inline static unsigned short ReadUInt16(unsigned char*& p) {
unsigned short ret = *(unsigned short*)p;
p += 2;
return ret;
static unsigned short ReadUInt16(unsigned char*& p) {
return buffer_read<uint16_t>(p);
}
inline static char ReadInt8(unsigned char*& p) {
static char ReadInt8(unsigned char*& p) {
return buffer_read<char>(p);
}
inline static unsigned char ReadUInt8(unsigned char*& p) {
static unsigned char ReadUInt8(unsigned char*& p) {
return buffer_read<unsigned char>(p);
}
inline static void WriteInt32(unsigned char*& p, int val) {
static void WriteInt32(unsigned char*& p, int val) {
buffer_write<int32_t>(p, val);
}
inline static void WriteInt16(unsigned char*& p, short val) {
static void WriteInt16(unsigned char*& p, short val) {
buffer_write<int16_t>(p, val);
}
inline static void WriteInt8(unsigned char*& p, char val) {
static void WriteInt8(unsigned char*& p, char val) {
buffer_write<char>(p, val);
}
// return: string length
template<typename T1, typename T2>
inline static int CopyWStr(const T1* src, T2* pstr, int bufsize) {
static int CopyWStr(const T1* src, T2* pstr, int bufsize) {
int l = 0;
while(src[l] && l < bufsize - 1) {
pstr[l] = (T2)src[l];
......@@ -49,7 +45,7 @@ public:
return l;
}
template<typename T1, typename T2>
inline static int CopyWStrRef(const T1* src, T2*& pstr, int bufsize) {
static int CopyWStrRef(const T1* src, T2*& pstr, int bufsize) {
int l = 0;
while(src[l] && l < bufsize - 1) {
pstr[l] = (T2)src[l];
......@@ -59,22 +55,117 @@ public:
*pstr = 0;
return l;
}
template<typename T>
static bool CheckUTF8Byte(const T* str, int len) {
for (int i = 1; i < len; ++i) {
if ((str[i] & 0xc0U) != 0x80U)
return false;
}
return true;
}
static unsigned int ConvertUTF8(const char*& p) {
unsigned int cur = 0;
if ((p[0] & 0x80U) == 0) {
cur = p[0] & 0xffU;
p++;
}
else if ((p[0] & 0xe0U) == 0xc0U) {
if (!CheckUTF8Byte(p, 2)) {
p++;
return UINT32_MAX;
}
cur = ((p[0] & 0x1fU) << 6) | (p[1] & 0x3fU);
p += 2;
if(cur < 0x80U)
return UINT32_MAX;
}
else if ((p[0] & 0xf0U) == 0xe0U) {
if (!CheckUTF8Byte(p, 3)) {
p++;
return UINT32_MAX;
}
cur = ((p[0] & 0xfU) << 12) | ((p[1] & 0x3fU) << 6) | (p[2] & 0x3fU);
p += 3;
if (cur < 0x800U)
return UINT32_MAX;
}
else if ((p[0] & 0xf8U) == 0xf0U) {
if (!CheckUTF8Byte(p, 4)) {
p++;
return UINT32_MAX;
}
cur = ((p[0] & 0x7U) << 18) | ((p[1] & 0x3fU) << 12) | ((p[2] & 0x3fU) << 6) | (p[3] & 0x3fU);
p += 4;
if (cur < 0x10000U)
return UINT32_MAX;
}
else {
p++;
return UINT32_MAX;
}
return cur;
}
static bool IsHighSurrogate(unsigned int c) {
return (c >= 0xd800U && c <= 0xdbffU);
}
static bool IsLowSurrogate(unsigned int c) {
return (c >= 0xdc00U && c <= 0xdfffU);
}
static bool IsUnicodeChar(unsigned int c) {
if(IsHighSurrogate(c))
return false;
if (IsLowSurrogate(c))
return false;
if (c > 0x10ffffU)
return false;
return true;
}
// UTF-16/UTF-32 to UTF-8
// return: string length
static int EncodeUTF8String(const wchar_t* wsrc, char* str, int size) {
char* pstr = str;
while (*wsrc != 0) {
unsigned cur = *wsrc;
auto pw = wsrc;
auto pstr = str;
while (*pw != 0) {
unsigned cur = 0;
int codepoint_size = 0;
if (sizeof(wchar_t) == 2) {
if (IsHighSurrogate(pw[0])) {
if (pw[1] == 0)
break;
if (IsLowSurrogate(pw[1])) {
cur = ((pw[0] & 0x3ffU) << 10) | (pw[1] & 0x3ffU);
cur += 0x10000;
pw += 2;
}
else {
pw++;
continue;
}
}
else if (IsLowSurrogate(pw[0])) {
pw++;
continue;
}
else {
cur = *pw;
pw++;
}
}
else {
cur = *pw;
pw++;
}
if (!IsUnicodeChar(cur))
continue;
if (cur < 0x80U)
codepoint_size = 1;
else if (cur < 0x800U)
codepoint_size = 2;
else if (cur < 0x10000U && (cur < 0xd800U || cur > 0xdfffU))
else if (cur < 0x10000U)
codepoint_size = 3;
else
codepoint_size = 4;
if (pstr - str + codepoint_size > size - 1)
if ((int)(pstr - str) + codepoint_size > size - 1)
break;
switch (codepoint_size) {
case 1:
......@@ -90,13 +181,6 @@ public:
pstr[2] = (cur & 0x3f) | 0x80;
break;
case 4:
if (sizeof(wchar_t) == 2) {
cur = 0;
cur |= (*wsrc & 0x3ffU) << 10;
++wsrc;
cur |= *wsrc & 0x3ffU;
cur += 0x10000;
}
pstr[0] = ((cur >> 18) & 0x7) | 0xf0;
pstr[1] = ((cur >> 12) & 0x3f) | 0x80;
pstr[2] = ((cur >> 6) & 0x3f) | 0x80;
......@@ -106,10 +190,9 @@ public:
break;
}
pstr += codepoint_size;
wsrc++;
}
*pstr = 0;
return pstr - str;
return (int)(pstr - str);
}
// UTF-8 to UTF-16/UTF-32
// return: string length
......@@ -117,9 +200,11 @@ public:
const char* p = src;
wchar_t* wp = wstr;
while(*p != 0) {
const unsigned cur = *p & 0xffU;
unsigned int cur = ConvertUTF8(p);
int codepoint_size = 0;
if ((cur & 0xf8) == 0xf0) {
if (!IsUnicodeChar(cur))
continue;
if (cur >= 0x10000) {
if (sizeof(wchar_t) == 2)
codepoint_size = 2;
else
......@@ -127,30 +212,18 @@ public:
}
else
codepoint_size = 1;
if (wp - wstr + codepoint_size > size - 1)
if ((int)(wp - wstr) + codepoint_size > size - 1)
break;
if((cur & 0x80) == 0) {
*wp = *p;
p++;
} else if((cur & 0xe0) == 0xc0) {
*wp = ((p[0] & 0x1fU) << 6) | (p[1] & 0x3fU);
p += 2;
} else if((cur & 0xf0) == 0xe0) {
*wp = ((p[0] & 0xfU) << 12) | ((p[1] & 0x3fU) << 6) | (p[2] & 0x3fU);
p += 3;
} else if((cur & 0xf8) == 0xf0) {
if (sizeof(wchar_t) == 2) {
unsigned unicode = ((p[0] & 0x7U) << 18) | ((p[1] & 0x3fU) << 12) | ((p[2] & 0x3fU) << 6) | (p[3] & 0x3fU);
unicode -= 0x10000;
*wp++ = (unicode >> 10) | 0xd800;
*wp = (unicode & 0x3ff) | 0xdc00;
} else {
*wp = ((p[0] & 0x7U) << 18) | ((p[1] & 0x3fU) << 12) | ((p[2] & 0x3fU) << 6) | (p[3] & 0x3fU);
}
p += 4;
} else
p++;
wp++;
if (codepoint_size == 1) {
wp[0] = cur;
wp++;
}
else {
cur -= 0x10000U;
wp[0] = (cur >> 10) | 0xd800;
wp[1] = (cur & 0x3ff) | 0xdc00;
wp += 2;
}
}
*wp = 0;
return wp - wstr;
......
......@@ -1572,10 +1572,10 @@ void ClientField::UpdateDeclarableList() {
if(ancard.size())
return;
}
for(auto cit = dataManager.strings_begin; cit != dataManager.strings_end; ++cit) {
for(auto cit = dataManager.strings_begin(); cit != dataManager.strings_end(); ++cit) {
if(cit->second.name.find(pname) != std::wstring::npos) {
auto cp = dataManager.GetCodePointer(cit->first);
if (cp == dataManager.datas_end)
if (cp == dataManager.datas_end())
continue;
//datas.alias can be double card names or alias
if(is_declarable(cp->second, declare_opcodes)) {
......
......@@ -63,6 +63,20 @@ inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
#include "../ocgcore/ocgapi.h"
#include "../ocgcore/common.h"
inline FILE* myfopen(const char* filename, const char* mode) {
FILE* fp{};
#ifdef _WIN32
wchar_t wname[256]{};
wchar_t wmode[20]{};
BufferIO::DecodeUTF8(filename, wname);
BufferIO::CopyWStr(mode, wmode, sizeof wmode / sizeof wmode[0]);
fp = _wfopen(wname, wmode);
#else
fp = fopen(filename, mode);
#endif
return fp;
}
#include <irrlicht.h>
using namespace irr;
using namespace core;
......
This diff is collapsed.
......@@ -2,10 +2,9 @@
#define DATAMANAGER_H
#include "config.h"
#include "sqlite3.h"
#include "spmemvfs/spmemvfs.h"
#include "client_card.h"
#include <unordered_map>
#include <sqlite3.h>
#include "client_card.h"
namespace ygo {
constexpr int MAX_STRING_ID = 0x7ff;
......@@ -14,25 +13,31 @@ namespace ygo {
class DataManager {
public:
DataManager();
bool ReadDB(sqlite3* pDB);
bool LoadDB(const wchar_t* wfile);
bool LoadStrings(const char* file);
bool LoadStrings(IReadFile* reader);
void ReadStringConfLine(const char* linebuf);
bool Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt = 0);
bool GetData(unsigned int code, CardData* pData);
bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = nullptr);
code_pointer GetCodePointer(unsigned int code) const;
string_pointer GetStringPointer(unsigned int code) const;
bool GetString(unsigned int code, CardString* pStr);
const wchar_t* GetName(unsigned int code);
const wchar_t* GetText(unsigned int code);
const wchar_t* GetDesc(unsigned int strCode);
const wchar_t* GetSysString(int code);
const wchar_t* GetVictoryString(int code);
const wchar_t* GetCounterName(int code);
const wchar_t* GetSetName(int code);
std::vector<unsigned int> GetSetCodes(std::wstring setname);
code_pointer datas_begin();
code_pointer datas_end();
string_pointer strings_begin();
string_pointer strings_end();
bool GetData(unsigned int code, CardData* pData) const;
bool GetString(unsigned int code, CardString* pStr) const;
const wchar_t* GetName(unsigned int code) const;
const wchar_t* GetText(unsigned int code) const;
const wchar_t* GetDesc(unsigned int strCode) const;
const wchar_t* GetSysString(int code) const;
const wchar_t* GetVictoryString(int code) const;
const wchar_t* GetCounterName(int code) const;
const wchar_t* GetSetName(int code) const;
std::vector<unsigned int> GetSetCodes(std::wstring setname) const;
const wchar_t* GetNumString(int num, bool bracket = false);
const wchar_t* FormatLocation(int location, int sequence);
const wchar_t* FormatLocation(int location, int sequence) const;
const wchar_t* FormatAttribute(int attribute);
const wchar_t* FormatRace(int race);
const wchar_t* FormatType(int type);
......@@ -43,10 +48,7 @@ public:
std::unordered_map<unsigned int, std::wstring> _victoryStrings;
std::unordered_map<unsigned int, std::wstring> _setnameStrings;
std::unordered_map<unsigned int, std::wstring> _sysStrings;
code_pointer datas_begin;
code_pointer datas_end;
string_pointer strings_begin;
string_pointer strings_end;
char errmsg[512]{};
wchar_t numStrings[301][4]{};
wchar_t numBuffer[6]{};
......
......@@ -1058,7 +1058,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
dragx = event.MouseInput.X;
dragy = event.MouseInput.Y;
draging_pointer = dataManager.GetCodePointer(hovered_code);
if(draging_pointer == dataManager.datas_end)
if(draging_pointer == dataManager.datas_end())
break;
if(hovered_pos == 4) {
if(!check_limit(draging_pointer))
......@@ -1112,7 +1112,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if(hovered_pos == 0 || hovered_seq == -1)
break;
auto pointer = dataManager.GetCodePointer(hovered_code);
if(pointer == dataManager.datas_end)
if(pointer == dataManager.datas_end())
break;
soundManager.PlaySoundEffect(SOUND_CARD_DROP);
if(hovered_pos == 1) {
......@@ -1147,7 +1147,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
pop_side(hovered_seq);
} else {
auto pointer = dataManager.GetCodePointer(hovered_code);
if(pointer == dataManager.datas_end)
if(pointer == dataManager.datas_end())
break;
if(!check_limit(pointer))
break;
......@@ -1182,7 +1182,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if (is_draging)
break;
auto pointer = dataManager.GetCodePointer(hovered_code);
if (pointer == dataManager.datas_end)
if (pointer == dataManager.datas_end())
break;
if(!check_limit(pointer))
break;
......@@ -1391,6 +1391,7 @@ void DeckBuilder::FilterCards() {
element_t(): type(type_t::all), exclude(false) {}
};
const wchar_t* pstr = mainGame->ebCardName->getText();
int trycode = BufferIO::GetVal(pstr);
std::wstring str = std::wstring(pstr);
std::vector<element_t> query_elements;
if(mainGame->gameConf.search_multiple_keywords) {
......@@ -1451,10 +1452,10 @@ void DeckBuilder::FilterCards() {
query_elements.push_back(element);
}
}
for(code_pointer ptr = dataManager.datas_begin; ptr != dataManager.datas_end; ++ptr) {
for(code_pointer ptr = dataManager.datas_begin(); ptr != dataManager.datas_end(); ++ptr) {
const CardDataC& data = ptr->second;
auto strpointer = dataManager.GetStringPointer(ptr->first);
if (strpointer == dataManager.strings_end)
if (strpointer == dataManager.strings_end())
continue;
const CardString& text = strpointer->second;
if(data.type & TYPE_TOKEN)
......@@ -1535,17 +1536,13 @@ void DeckBuilder::FilterCards() {
match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str());
} else if (elements_iterator->type == element_t::type_t::setcode) {
match = data.is_setcodes(elements_iterator->setcodes);
} else if (trycode && (data.code == trycode || data.alias == trycode && data.is_alternative())){
match = true;
} else {
int trycode = BufferIO::GetVal(elements_iterator->keyword.c_str());
bool tryresult = dataManager.GetData(trycode, 0);
if(!tryresult) {
match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str())
|| text.text.find(elements_iterator->keyword) != std::wstring::npos
|| mainGame->CheckRegEx(text.text, elements_iterator->keyword)
|| data.is_setcodes(elements_iterator->setcodes);
} else {
match = data.code == trycode || data.alias == trycode;
}
match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str())
|| text.text.find(elements_iterator->keyword) != std::wstring::npos
|| mainGame->CheckRegEx(text.text, elements_iterator->keyword)
|| data.is_setcodes(elements_iterator->setcodes);
}
if(elements_iterator->exclude)
match = !match;
......
......@@ -270,15 +270,9 @@ void DeckManager::GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory,
}
}
FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
#ifdef WIN32
wchar_t wmode[20]{};
BufferIO::CopyWStr(mode, wmode, sizeof wmode / sizeof wmode[0]);
FILE* fp = _wfopen(file, wmode);
#else
char file2[256];
BufferIO::EncodeUTF8(file, file2);
FILE* fp = fopen(file2, mode);
#endif
char fullname[256]{};
BufferIO::EncodeUTF8(file, fullname);
FILE* fp = myfopen(fullname, mode);
return fp;
}
IReadFile* DeckManager::OpenDeckReader(const wchar_t* file) {
......
......@@ -2586,11 +2586,14 @@ void ClientField::ShowCardInfoInList(ClientCard* pcard, irr::gui::IGUIElement* e
}
}
void ClientField::SetResponseSelectedCards() const {
unsigned char respbuf[SIZE_RETURN_VALUE];
respbuf[0] = selected_cards.size();
for (size_t i = 0; i < selected_cards.size(); ++i)
unsigned char respbuf[SIZE_RETURN_VALUE]{};
int len = (int)selected_cards.size();
if (len > UINT8_MAX)
len = UINT8_MAX;
respbuf[0] = (unsigned char)len;
for (int i = 0; i < len; ++i)
respbuf[i + 1] = selected_cards[i]->select_seq;
DuelClient::SetResponseB(respbuf, selected_cards.size() + 1);
DuelClient::SetResponseB(respbuf, len + 1);
}
void ClientField::SetResponseSelectedOption() const {
if(mainGame->dInfo.curMsg == MSG_SELECT_OPTION) {
......
......@@ -228,7 +228,7 @@ bool Game::Initialize() {
SetWindowsIcon();
//main menu
wchar_t strbuf[256];
myswprintf(strbuf, L"KoishiPro %X.0%X.%X Euphoria", (PRO_VERSION & 0xf000U) >> 12, (PRO_VERSION & 0x0ff0U) >> 4, PRO_VERSION & 0x000fU);
myswprintf(strbuf, L"KoishiPro %X.0%X.%X Do-Dai", (PRO_VERSION & 0xf000U) >> 12, (PRO_VERSION & 0x0ff0U) >> 4, PRO_VERSION & 0x000fU);
wMainMenu = env->addWindow(rect<s32>(370, 200, 650, 415), false, strbuf);
wMainMenu->getCloseButton()->setVisible(false);
btnLanMode = env->addButton(rect<s32>(10, 30, 270, 60), wMainMenu, BUTTON_LAN_MODE, dataManager.GetSysString(1200));
......@@ -1823,7 +1823,7 @@ void Game::ShowCardInfo(int code, bool resize) {
return;
wchar_t formatBuffer[256];
auto cit = dataManager.GetCodePointer(code);
bool is_valid = (cit != dataManager.datas_end);
bool is_valid = (cit != dataManager.datas_end());
imgCard->setImage(imageManager.GetTexture(code, true));
if (is_valid) {
auto& cd = cit->second;
......@@ -1840,7 +1840,7 @@ void Game::ShowCardInfo(int code, bool resize) {
if (is_valid && !gameConf.hide_setname) {
auto& cd = cit->second;
auto target = cit;
if (cd.alias && dataManager.GetCodePointer(cd.alias) != dataManager.datas_end) {
if (cd.alias && dataManager.GetCodePointer(cd.alias) != dataManager.datas_end()) {
target = dataManager.GetCodePointer(cd.alias);
}
if (target->second.setcode[0]) {
......
......@@ -558,14 +558,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
const wchar_t* name = mainGame->lstSinglePlayList->getListItem(sel);
wchar_t fname[256];
myswprintf(fname, L"./single/%ls", name);
FILE *fp;
#ifdef _WIN32
fp = _wfopen(fname, L"rb");
#else
char filename[256];
BufferIO::EncodeUTF8(fname, filename);
fp = fopen(filename, "rb");
#endif
char fullname[256]{};
BufferIO::EncodeUTF8(fname, fullname);
FILE* fp = myfopen(fullname, "rb");
if(!fp) {
mainGame->stSinglePlayInfo->setText(L"");
break;
......
......@@ -208,26 +208,25 @@ inline unsigned int GetPosition(unsigned char* qbuf, int offset) {
class DuelMode {
public:
virtual ~DuelMode() {}
virtual void Chat(DuelPlayer* dp, unsigned char* pdata, int len) {}
virtual void JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater) {}
virtual void LeaveGame(DuelPlayer* dp) {}
virtual void ToDuelist(DuelPlayer* dp) {}
virtual void ToObserver(DuelPlayer* dp) {}
virtual void PlayerReady(DuelPlayer* dp, bool is_ready) {}
virtual void PlayerKick(DuelPlayer* dp, unsigned char pos) {}
virtual void UpdateDeck(DuelPlayer* dp, unsigned char* pdata, int len) {}
virtual void StartDuel(DuelPlayer* dp) {}
virtual void HandResult(DuelPlayer* dp, unsigned char res) {}
virtual void TPResult(DuelPlayer* dp, unsigned char tp) {}
virtual void Process() {}
virtual int Analyze(char* msgbuffer, unsigned int len) {
return 0;
}
virtual void Surrender(DuelPlayer* dp) {}
virtual void GetResponse(DuelPlayer* dp, unsigned char* pdata, unsigned int len) {}
virtual void TimeConfirm(DuelPlayer* dp) {}
virtual void EndDuel() {}
DuelMode() = default;
virtual ~DuelMode() = default;
virtual void Chat(DuelPlayer* dp, unsigned char* pdata, int len) = 0;
virtual void JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater) = 0;
virtual void LeaveGame(DuelPlayer* dp) = 0;
virtual void ToDuelist(DuelPlayer* dp) = 0;
virtual void ToObserver(DuelPlayer* dp) = 0;
virtual void PlayerReady(DuelPlayer* dp, bool is_ready) = 0;
virtual void PlayerKick(DuelPlayer* dp, unsigned char pos) = 0;
virtual void UpdateDeck(DuelPlayer* dp, unsigned char* pdata, int len) = 0;
virtual void StartDuel(DuelPlayer* dp) = 0;
virtual void HandResult(DuelPlayer* dp, unsigned char res) = 0;
virtual void TPResult(DuelPlayer* dp, unsigned char tp) = 0;
virtual void Process() = 0;
virtual int Analyze(unsigned char* msgbuffer, unsigned int len) = 0;
virtual void Surrender(DuelPlayer* dp) = 0;
virtual void GetResponse(DuelPlayer* dp, unsigned char* pdata, unsigned int len) = 0;
virtual void TimeConfirm(DuelPlayer* dp) = 0;
virtual void EndDuel() = 0;
public:
event* etimer { nullptr };
......
......@@ -102,39 +102,26 @@ void Replay::SaveReplay(const wchar_t* name) {
return;
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls.yrp", name);
#ifdef WIN32
fp = _wfopen(fname, L"wb");
#else
char fname2[256];
BufferIO::EncodeUTF8(fname, fname2);
fp = fopen(fname2, "wb");
#endif
if(!fp)
char fullname[256]{};
BufferIO::EncodeUTF8(fname, fullname);
FILE* rfp = myfopen(fullname, "wb");
if(!rfp)
return;
fwrite(&pheader, sizeof(pheader), 1, fp);
fwrite(comp_data, comp_size, 1, fp);
fclose(fp);
fwrite(&pheader, sizeof pheader, 1, rfp);
fwrite(comp_data, comp_size, 1, rfp);
fclose(rfp);
}
bool Replay::OpenReplay(const wchar_t* name) {
#ifdef WIN32
fp = _wfopen(name, L"rb");
#else
char name2[256];
BufferIO::EncodeUTF8(name, name2);
fp = fopen(name2, "rb");
#endif
if(!fp) {
char fullname[256]{};
BufferIO::EncodeUTF8(name, fullname);
FILE* rfp = myfopen(fullname, "rb");
if(!rfp) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
#ifdef WIN32
fp = _wfopen(fname, L"rb");
#else
char fname2[256];
BufferIO::EncodeUTF8(fname, fname2);
fp = fopen(fname2, "rb");
#endif
BufferIO::EncodeUTF8(fname, fullname);
rfp = myfopen(fullname, "rb");
}
if(!fp)
if(!rfp)
return false;
pdata = replay_data;
......@@ -142,13 +129,13 @@ bool Replay::OpenReplay(const wchar_t* name) {
is_replaying = false;
replay_size = 0;
comp_size = 0;
if(fread(&pheader, sizeof(pheader), 1, fp) < 1) {
fclose(fp);
if(fread(&pheader, sizeof pheader, 1, rfp) < 1) {
fclose(rfp);
return false;
}
if(pheader.flag & REPLAY_COMPRESSED) {
comp_size = fread(comp_data, 1, MAX_COMP_SIZE, fp);
fclose(fp);
comp_size = fread(comp_data, 1, MAX_COMP_SIZE, rfp);
fclose(rfp);
if ((int)pheader.datasize < 0 && (int)pheader.datasize > MAX_REPLAY_SIZE)
return false;
replay_size = pheader.datasize;
......@@ -159,8 +146,8 @@ bool Replay::OpenReplay(const wchar_t* name) {
return false;
}
} else {
replay_size = fread(replay_data, 1, MAX_REPLAY_SIZE, fp);
fclose(fp);
replay_size = fread(replay_data, 1, MAX_REPLAY_SIZE, rfp);
fclose(rfp);
comp_size = 0;
}
is_replaying = true;
......@@ -169,24 +156,20 @@ bool Replay::OpenReplay(const wchar_t* name) {
bool Replay::CheckReplay(const wchar_t* name) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
#ifdef WIN32
FILE* rfp = _wfopen(fname, L"rb");
#else
char fname2[256];
BufferIO::EncodeUTF8(fname, fname2);
FILE* rfp = fopen(fname2, "rb");
#endif
char fullname[256]{};
BufferIO::EncodeUTF8(fname, fullname);
FILE* rfp = myfopen(fullname, "rb");
if(!rfp)
return false;
ReplayHeader rheader;
size_t count = fread(&rheader, sizeof(ReplayHeader), 1, rfp);
size_t count = fread(&rheader, sizeof rheader, 1, rfp);
fclose(rfp);
return count == 1 && rheader.id == 0x31707279 && rheader.version >= 0x12d0u && (rheader.version < 0x1353u || (rheader.flag & REPLAY_UNIFORM));
}
bool Replay::DeleteReplay(const wchar_t* name) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
#ifdef WIN32
#ifdef _WIN32
BOOL result = DeleteFileW(fname);
return !!result;
#else
......@@ -201,7 +184,7 @@ bool Replay::RenameReplay(const wchar_t* oldname, const wchar_t* newname) {
wchar_t newfname[256];
myswprintf(oldfname, L"./replay/%ls", oldname);
myswprintf(newfname, L"./replay/%ls", newname);
#ifdef WIN32
#ifdef _WIN32
BOOL result = MoveFileW(oldfname, newfname);
return !!result;
#else
......
......@@ -236,7 +236,7 @@ bool ReplayMode::StartDuel() {
}
cur_replay.ReadData(filename, slen);
filename[slen] = 0;
if(!preload_script(pduel, filename, 0)) {
if(!preload_script(pduel, filename)) {
return false;
}
}
......
......@@ -10,24 +10,24 @@ namespace ygo {
class SingleDuel: public DuelMode {
public:
SingleDuel(bool is_match);
virtual ~SingleDuel();
virtual void Chat(DuelPlayer* dp, unsigned char* pdata, int len);
virtual void JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater);
virtual void LeaveGame(DuelPlayer* dp);
virtual void ToDuelist(DuelPlayer* dp);
virtual void ToObserver(DuelPlayer* dp);
virtual void PlayerReady(DuelPlayer* dp, bool ready);
virtual void PlayerKick(DuelPlayer* dp, unsigned char pos);
virtual void UpdateDeck(DuelPlayer* dp, unsigned char* pdata, int len);
virtual void StartDuel(DuelPlayer* dp);
virtual void HandResult(DuelPlayer* dp, unsigned char res);
virtual void TPResult(DuelPlayer* dp, unsigned char tp);
virtual void Process();
virtual void Surrender(DuelPlayer* dp);
virtual int Analyze(unsigned char* msgbuffer, unsigned int len);
virtual void GetResponse(DuelPlayer* dp, unsigned char* pdata, unsigned int len);
virtual void TimeConfirm(DuelPlayer* dp);
virtual void EndDuel();
~SingleDuel() override;
void Chat(DuelPlayer* dp, unsigned char* pdata, int len) override;
void JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater) override;
void LeaveGame(DuelPlayer* dp) override;
void ToDuelist(DuelPlayer* dp) override;
void ToObserver(DuelPlayer* dp) override;
void PlayerReady(DuelPlayer* dp, bool ready) override;
void PlayerKick(DuelPlayer* dp, unsigned char pos) override;
void UpdateDeck(DuelPlayer* dp, unsigned char* pdata, int len) override;
void StartDuel(DuelPlayer* dp) override;
void HandResult(DuelPlayer* dp, unsigned char res) override;
void TPResult(DuelPlayer* dp, unsigned char tp) override;
void Process() override;
void Surrender(DuelPlayer* dp) override;
int Analyze(unsigned char* msgbuffer, unsigned int len) override;
void GetResponse(DuelPlayer* dp, unsigned char* pdata, unsigned int len) override;
void TimeConfirm(DuelPlayer* dp) override;
void EndDuel() override;
void DuelEndProc();
void WaitforResponse(int playerid);
......
......@@ -63,11 +63,11 @@ int SingleMode::SinglePlayThread() {
if(open_file) {
open_file = false;
slen = BufferIO::EncodeUTF8(open_file_name, filename);
if(!preload_script(pduel, filename, 0)) {
if(!preload_script(pduel, filename)) {
wchar_t fname[256];
myswprintf(fname, L"./single/%ls", open_file_name);
slen = BufferIO::EncodeUTF8(fname, filename);
if(!preload_script(pduel, filename, 0))
if(!preload_script(pduel, filename))
slen = 0;
}
} else {
......@@ -75,7 +75,7 @@ int SingleMode::SinglePlayThread() {
wchar_t fname[256];
myswprintf(fname, L"./single/%ls", name);
slen = BufferIO::EncodeUTF8(fname, filename);
if(!preload_script(pduel, filename, 0))
if(!preload_script(pduel, filename))
slen = 0;
}
if(slen == 0) {
......
......@@ -10,24 +10,24 @@ namespace ygo {
class TagDuel: public DuelMode {
public:
TagDuel();
virtual ~TagDuel();
virtual void Chat(DuelPlayer* dp, unsigned char* pdata, int len);
virtual void JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater);
virtual void LeaveGame(DuelPlayer* dp);
virtual void ToDuelist(DuelPlayer* dp);
virtual void ToObserver(DuelPlayer* dp);
virtual void PlayerReady(DuelPlayer* dp, bool ready);
virtual void PlayerKick(DuelPlayer* dp, unsigned char pos);
virtual void UpdateDeck(DuelPlayer* dp, unsigned char* pdata, int len);
virtual void StartDuel(DuelPlayer* dp);
virtual void HandResult(DuelPlayer* dp, unsigned char res);
virtual void TPResult(DuelPlayer* dp, unsigned char tp);
virtual void Process();
virtual void Surrender(DuelPlayer* dp);
virtual int Analyze(unsigned char* msgbuffer, unsigned int len);
virtual void GetResponse(DuelPlayer* dp, unsigned char* pdata, unsigned int len);
virtual void TimeConfirm(DuelPlayer* dp);
virtual void EndDuel();
~TagDuel() override;
void Chat(DuelPlayer* dp, unsigned char* pdata, int len) override;
void JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater) override;
void LeaveGame(DuelPlayer* dp) override;
void ToDuelist(DuelPlayer* dp) override;
void ToObserver(DuelPlayer* dp) override;
void PlayerReady(DuelPlayer* dp, bool ready) override;
void PlayerKick(DuelPlayer* dp, unsigned char pos) override;
void UpdateDeck(DuelPlayer* dp, unsigned char* pdata, int len) override;
void StartDuel(DuelPlayer* dp) override;
void HandResult(DuelPlayer* dp, unsigned char res) override;
void TPResult(DuelPlayer* dp, unsigned char tp) override;
void Process() override;
void Surrender(DuelPlayer* dp) override;
int Analyze(unsigned char* msgbuffer, unsigned int len) override;
void GetResponse(DuelPlayer* dp, unsigned char* pdata, unsigned int len) override;
void TimeConfirm(DuelPlayer* dp) override;
void EndDuel() override;
void DuelEndProc();
void WaitforResponse(int playerid);
......
This diff is collapsed.
Subproject commit 0cf488769f8da7385bf1abd1ed12aa0cf8c59266
Subproject commit 204eb0d8bdedd2ca0c0e473798a63735c8c8528d
......@@ -16,8 +16,8 @@ VALUE "InternalName", "KoishiPro"
VALUE "LegalCopyright", "Copyright (C) 2023 Nanahira"
VALUE "OriginalFilename", "ygopro.exe"
VALUE "ProductName", "KoishiPro"
VALUE "FileVersion", "Euphoria"
VALUE "ProductVersion", "Euphoria"
VALUE "FileVersion", "Do-Dai"
VALUE "ProductVersion", "Do-Dai"
END
END
BLOCK "VarFileInfo"
......
......@@ -10,6 +10,9 @@ project "lua"
filter "not action:vs*"
buildoptions { "-x c++" }
filter "configurations:Debug"
defines { "LUA_USE_APICHECK" }
filter "system:bsd"
defines { "LUA_USE_POSIX" }
......
Subproject commit d30738e0ac99e66639e9b0afc8c09bf266fbf8b5
Subproject commit 02cf811961c11c61f448e105c732a5369025f076
......@@ -1246,3 +1246,6 @@
!setname 0x1bb 魔瞳 モルガナイト
!setname 0x1bc 蓟花 アザミナ
!setname 0x1bd 祝台
!setname 0x1be 雷火沸动 ライゼオル
!setname 0x1bf 码丽丝 MLICE
!setname 0x1c0 龙华 竜華
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