Commit 6bacd86b authored by fallenstardust's avatar fallenstardust

update gframe

sync ocgcore
parent 82c37c8d
......@@ -53,12 +53,17 @@
#include <iostream>
#include <algorithm>
#include <string>
#include "bufferio.h"
#include "mysignal.h"
#include "../ocgcore/ocgapi.h"
template<size_t N, typename... TR>
inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
return std::swprintf(buf, N, fmt, args...);
inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR&&... args) {
return std::swprintf(buf, N, fmt, std::forward<TR>(args)...);
}
template<size_t N, typename... TR>
inline int mysnprintf(char(&buf)[N], const char* fmt, TR&&... args) {
return std::snprintf(buf, N, fmt, std::forward<TR>(args)...);
}
inline FILE* mywfopen(const wchar_t* filename, const char* mode) {
......@@ -69,20 +74,7 @@ inline FILE* mywfopen(const wchar_t* filename, const char* mode) {
return fp;
}
#if !defined(_WIN32)
#define myfopen std::fopen
#elif defined(WDK_NTDDI_VERSION) && (WDK_NTDDI_VERSION >= 0x0A000005) // Redstone 4, Version 1803, Build 17134.
#define FOPEN_WINDOWS_SUPPORT_UTF8
#define myfopen std::fopen
#else
inline FILE* myfopen(const char* filename, const char* mode) {
wchar_t wfilename[256]{};
BufferIO::DecodeUTF8(filename, wfilename);
wchar_t wmode[20]{};
BufferIO::CopyCharArray(mode, wmode);
return _wfopen(wfilename, wmode);
}
#endif
#include <irrlicht.h>
using namespace irr::io;
......
......@@ -10,7 +10,10 @@ irr::io::IFileSystem* DataManager::FileSystem = nullptr;
DataManager dataManager;
DataManager::DataManager() : _datas(32768), _strings(32768) {
extra_setcode = { {8512558u, {0x8f, 0x54, 0x59, 0x82, 0x13a}}, };
extra_setcode = {
{8512558u, {0x8f, 0x54, 0x59, 0x82, 0x13a}},
{55088578u, {0x8f, 0x54, 0x59, 0x82, 0x13a}},
};
}
bool DataManager::ReadDB(sqlite3* pDB) {
sqlite3_stmt* pStmt = nullptr;
......@@ -156,7 +159,7 @@ void DataManager::ReadStringConfLine(const char* linebuf) {
}
bool DataManager::Error(sqlite3* pDB, sqlite3_stmt* pStmt) {
if (const char* msg = sqlite3_errmsg(pDB))
std::snprintf(errmsg, sizeof errmsg, "%s", msg);
mysnprintf(errmsg, "%s", msg);
else
errmsg[0] = '\0';
sqlite3_finalize(pStmt);
......@@ -374,7 +377,7 @@ unsigned char* DataManager::ScriptReaderEx(const char* script_path, int* slen) {
return ReadScriptFromFile(script_path, slen);
const char* script_name = script_path + 2;
char expansions_path[1024]{};
std::snprintf(expansions_path, sizeof expansions_path, "./expansions/%s", script_name);
mysnprintf(expansions_path, "./expansions/%s", script_name);
if (mainGame->gameConf.prefer_expansion_script) { // debug script with raw file in expansions
if (ReadScriptFromFile(expansions_path, slen))
return scriptBuffer;
......
......@@ -2087,16 +2087,16 @@ void Game::AddDebugMsg(const char* msg) {
fullMsg += "";
}
fullMsg += message;
if (enable_log & 0x1) {
wchar_t wbuf[1024];
if (enable_log & 0x1) {
wchar_t wbuf[1024];
BufferIO::DecodeUTF8(fullMsg.c_str(), wbuf);
AddChatMsg(wbuf, 9);
}
if (enable_log & 0x2) {
char msgbuf[1040];
std::snprintf(msgbuf, sizeof msgbuf, "[Script Error]: %s", fullMsg.c_str());
ErrorLog(msgbuf);
}
AddChatMsg(wbuf, 9);
}
if (enable_log & 0x2) {
char msgbuf[1040];
mysnprintf(msgbuf, "[Script Error]: %s", fullMsg.c_str());
ErrorLog(msgbuf);
}
}
void Game::ErrorLog(const char* msg) {
std::fprintf(stderr, "%s\n", msg);
......
......@@ -191,10 +191,10 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
}
irr::video::ITexture* texture;
char file[256];
std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
mysnprintf(file, "expansions/pics/%d.jpg", code);
irr::video::IImage* srcimg = driver->createImageFromFile(file);
if(srcimg == nullptr) {
std::snprintf(file, sizeof file, "pics/%d.jpg", code);
mysnprintf(file, "pics/%d.jpg", code);
srcimg = driver->createImageFromFile(file);
}
if(srcimg == nullptr) {
......@@ -222,18 +222,18 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) {
auto tit = tFields.find(code);
if(tit == tFields.end()) {
char file[256];
std::snprintf(file, sizeof file, "field/%s/%d.jpg", irr::android::getCardImagePath(mainGame->appMain).c_str(), code);
mysnprintf(file, "field/%s/%d.jpg", irr::android::getCardImagePath(mainGame->appMain).c_str(), code);
irr::video::ITexture* img = driver->getTexture(file);
if(img == nullptr) {
std::snprintf(file, sizeof file, "field/%s/%d.jpg", irr::android::getCardImagePath(mainGame->appMain).c_str(), code);
mysnprintf(file, "field/%s/%d.jpg", irr::android::getCardImagePath(mainGame->appMain).c_str(), code);
img = driver->getTexture(file);
}
if(img == nullptr) {
std::snprintf(file, sizeof file, "field/%s/%d.png", irr::android::getCardImagePath(mainGame->appMain).c_str(), code);
mysnprintf(file, "field/%s/%d.png", irr::android::getCardImagePath(mainGame->appMain).c_str(), code);
img = driver->getTexture(file);
}
if(img == nullptr) {
std::snprintf(file, sizeof file, "pics/field/%d.jpg", code);
mysnprintf(file, "pics/field/%d.jpg", code);
img = driver->getTexture(file);
if(img == nullptr) {
tFields[code] = nullptr;
......
......@@ -456,10 +456,10 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
char arg2[32];
arg2[0]=0;
if(mainGame->chkBotHand->isChecked())
snprintf(arg2, sizeof arg2, " Hand=1");
mysnprintf(arg2, " Hand=1");
char arg3[32];
snprintf(arg3, sizeof arg3, " Port=%d", mainGame->gameConf.serverport);
snprintf(args, sizeof args, "%s%s%s", arg1, arg2, arg3);
mysnprintf(arg3, " Port=%d", mainGame->gameConf.serverport);
mysnprintf(args, "%s%s%s", arg1, arg2, arg3);
irr::android::runWindbot(mainGame->appMain, args);
if(!NetServer::StartServer(mainGame->gameConf.serverport)) {
mainGame->soundManager->PlaySoundEffect(SoundManager::SFX::INFO);
......
......@@ -182,7 +182,7 @@ public:
bool success = true;
TraversalDir(dir, [dir, &success](const char *name, bool isdir) {
char full_path[1024];
int len = std::snprintf(full_path, sizeof full_path, "%s/%s", dir, name);
int len = mysnprintf(full_path, "%s/%s", dir, name);
if (len < 0 || len >= (int)(sizeof full_path)) {
success = false;
return;
......@@ -228,7 +228,7 @@ public:
while((dirp = readdir(dir)) != nullptr) {
file_unit funit;
char fname[1024];
int len = std::snprintf(fname, sizeof fname, "%s/%s", path, dirp->d_name);
int len = mysnprintf(fname, "%s/%s", path, dirp->d_name);
if (len < 0 || len >= (int)(sizeof fname))
continue;
stat(fname, &fileStat);
......
......@@ -140,17 +140,12 @@ 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
BOOL result = MoveFileW(oldfname, newfname);
return !!result;
#else
char oldfilefn[256];
char newfilefn[256];
char oldfilefn[1024];
char newfilefn[1024];
BufferIO::EncodeUTF8(oldfname, oldfilefn);
BufferIO::EncodeUTF8(newfname, newfilefn);
int result = rename(oldfilefn, newfilefn);
int result = std::rename(oldfilefn, newfilefn);
return result == 0;
#endif
}
bool Replay::ReadNextResponse(unsigned char resp[]) {
unsigned char len{};
......
......@@ -212,7 +212,7 @@ bool ReplayMode::StartDuel() {
}
} else {
char filename[256]{};
std::snprintf(filename, sizeof filename, "./single/%s", cur_replay.script_name.c_str());
mysnprintf(filename, "./single/%s", cur_replay.script_name.c_str());
if(!preload_script(pduel, filename)) {
return false;
}
......
......@@ -149,6 +149,10 @@ int32_t scriptlib::debug_reload_field_begin(lua_State *L) {
pduel->game_field->core.duel_rule = 1;
else
pduel->game_field->core.duel_rule = CURRENT_RULE;
if (pduel->game_field->core.duel_rule == MASTER_RULE3) {
pduel->game_field->player[0].szone_size = 8;
pduel->game_field->player[1].szone_size = 8;
}
return 0;
}
int32_t scriptlib::debug_reload_field_end(lua_State *L) {
......
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