Commit 700f263c authored by fallenstardust's avatar fallenstardust

update gframe

parent 8e0fdfe1
......@@ -32,7 +32,7 @@ public:
* @brief Copy a C-style string to another C-style string.
* @param src The source wide string
* @param pstr The destination char string
* @param bufsize The size of the destination buffer
* @param bufsize The length of the destination buffer
* @return The length of the copied string
*/
template<typename T1, typename T2>
......@@ -62,13 +62,13 @@ public:
}
template<size_t N>
static void CopyString(const char* src, char(&dst)[N]) {
dst[0] = 0;
std::strncat(dst, src, N - 1);
std::strncpy(dst, src, N - 1);
dst[N - 1] = 0;
}
template<size_t N>
static void CopyWideString(const wchar_t* src, wchar_t(&dst)[N]) {
dst[0] = 0;
std::wcsncat(dst, src, N - 1);
std::wcsncpy(dst, src, N - 1);
dst[N - 1] = 0;
}
template<typename T>
static bool CheckUTF8Byte(const T* str, int len) {
......
......@@ -326,6 +326,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_LOAD_REPLAY: {
int start_turn = 1;
auto selected = mainGame->lstReplayList->getSelected();
if(selected == -1)
break;
......@@ -333,6 +334,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
myswprintf(replay_path, L"./replay/%ls", mainGame->lstReplayList->getListItem(selected));
if (!ReplayMode::cur_replay.OpenReplay(replay_path))
break;
start_turn = std::wcstol(mainGame->ebRepStartTurn->getText(), nullptr, 10);
mainGame->ClearCardInfo();
mainGame->imgCard->setScaleImage(true);
mainGame->wCardImg->setVisible(true);
......@@ -349,7 +351,6 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->dField.Clear();
mainGame->HideElement(mainGame->wReplay);
mainGame->device->setEventReceiver(&mainGame->dField);
unsigned int start_turn = std::wcstol(mainGame->ebRepStartTurn->getText(), nullptr, 10);
if(start_turn == 1)
start_turn = 0;
ReplayMode::StartReplay(start_turn);
......@@ -621,27 +622,27 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
wchar_t replay_path[256]{};
myswprintf(replay_path, L"./replay/%ls", mainGame->lstReplayList->getListItem(sel));
if (!ReplayMode::cur_replay.OpenReplay(replay_path)) {
if (!temp_replay.OpenReplay(replay_path)) {
mainGame->stReplayInfo->setText(L"Error");
break;
}
wchar_t infobuf[256]{};
std::wstring repinfo;
time_t curtime;
if(ReplayMode::cur_replay.pheader.flag & REPLAY_UNIFORM)
curtime = ReplayMode::cur_replay.pheader.start_time;
if(temp_replay.pheader.flag & REPLAY_UNIFORM)
curtime = temp_replay.pheader.start_time;
else
curtime = ReplayMode::cur_replay.pheader.seed;
curtime = temp_replay.pheader.seed;
std::wcsftime(infobuf, sizeof infobuf / sizeof infobuf[0], L"%Y/%m/%d %H:%M:%S\n", std::localtime(&curtime));
repinfo.append(infobuf);
if (ReplayMode::cur_replay.pheader.flag & REPLAY_SINGLE_MODE) {
if (temp_replay.pheader.flag & REPLAY_SINGLE_MODE) {
wchar_t path[256]{};
BufferIO::DecodeUTF8(ReplayMode::cur_replay.script_name.c_str(), path);
BufferIO::DecodeUTF8(temp_replay.script_name.c_str(), path);
repinfo.append(path);
repinfo.append(L"\n");
}
const auto& player_names = ReplayMode::cur_replay.players;
if(ReplayMode::cur_replay.pheader.flag & REPLAY_TAG)
const auto& player_names = temp_replay.players;
if(temp_replay.pheader.flag & REPLAY_TAG)
myswprintf(infobuf, L"%ls\n%ls\n===VS===\n%ls\n%ls\n", player_names[0].c_str(), player_names[1].c_str(), player_names[2].c_str(), player_names[3].c_str());
else
myswprintf(infobuf, L"%ls\n===VS===\n%ls\n", player_names[0].c_str(), player_names[1].c_str());
......
......@@ -2,6 +2,8 @@
#define MENU_HANDLER_H
#include <irrlicht.h>
#include "replay.h"
#ifdef _IRR_ANDROID_PLATFORM_
#include <android/TouchEventTransferAndroid.h>
#endif
......@@ -13,7 +15,7 @@ public:
bool OnEvent(const irr::SEvent& event) override;
irr::s32 prev_operation{ 0 };
int prev_sel{ -1 };
Replay temp_replay;
};
}
......
......@@ -227,7 +227,11 @@ void Replay::Reset() {
script_name.clear();
}
void Replay::SkipInfo(){
data_position += info_offset;
if (data_position == 0)
data_position += info_offset;
}
bool Replay::IsReplaying() const {
return is_replaying;
}
bool Replay::ReadInfo() {
int player_count = (pheader.flag & REPLAY_TAG) ? 4 : 2;
......
......@@ -81,6 +81,7 @@ public:
void Rewind();
void Reset();
void SkipInfo();
bool IsReplaying() const;
FILE* fp{ nullptr };
......
......@@ -159,7 +159,7 @@ bool ReplayMode::StartDuel() {
unsigned int seed = rh.seed;
std::mt19937 rnd(seed);
cur_replay.SkipInfo();
if(mainGame->dInfo.isTag) {
if(rh.flag & REPLAY_TAG) {
BufferIO::CopyWideString(cur_replay.players[0].c_str(), mainGame->dInfo.hostname);
BufferIO::CopyWideString(cur_replay.players[1].c_str(), mainGame->dInfo.hostname_tag);
BufferIO::CopyWideString(cur_replay.players[2].c_str(), mainGame->dInfo.clientname_tag);
......@@ -824,12 +824,12 @@ bool ReplayMode::ReplayAnalyze(unsigned char* msg, unsigned int len) {
break;
}
case MSG_AI_NAME: {
int len = BufferIO::ReadInt16(pbuf);
int len = buffer_read<uint16_t>(pbuf);
pbuf += len + 1;
break;
}
case MSG_SHOW_HINT: {
int len = BufferIO::ReadInt16(pbuf);
int len = buffer_read<uint16_t>(pbuf);
pbuf += len + 1;
break;
}
......
......@@ -25,7 +25,6 @@ private:
public:
static Replay cur_replay;
public:
static bool StartReplay(int skipturn);
static void StopReplay(bool is_exiting = false);
static void SwapField();
......
......@@ -739,21 +739,25 @@ bool SingleMode::SinglePlayAnalyze(unsigned char* msg, unsigned int len) {
case MSG_AI_NAME: {
char namebuf[128]{};
wchar_t wname[20]{};
int len = BufferIO::ReadInt16(pbuf);
auto begin = pbuf;
pbuf += len + 1;
std::memcpy(namebuf, begin, len + 1);
int name_len = buffer_read<uint16_t>(pbuf);
if (name_len + 1 <= (int)sizeof namebuf) {
std::memcpy(namebuf, pbuf, name_len);
namebuf[name_len] = 0;
}
pbuf += name_len + 1;
BufferIO::DecodeUTF8(namebuf, wname);
BufferIO::CopyCharArray(wname, mainGame->dInfo.clientname);
break;
}
case MSG_SHOW_HINT: {
char msgbuf[1024];
wchar_t msg[1024];
int len = BufferIO::ReadInt16(pbuf);
auto begin = pbuf;
pbuf += len + 1;
std::memcpy(msgbuf, begin, len + 1);
char msgbuf[1024]{};
wchar_t msg[1024]{};
int msg_len = buffer_read<uint16_t>(pbuf);
if (msg_len + 1 <= (int)sizeof msgbuf) {
std::memcpy(msgbuf, pbuf, msg_len);
msgbuf[msg_len] = 0;
}
pbuf += msg_len + 1;
BufferIO::DecodeUTF8(msgbuf, msg);
mainGame->gMutex.lock();
mainGame->SetStaticText(mainGame->stMessage, 370 * mainGame->xScale, mainGame->guiFont, msg);
......
......@@ -32,7 +32,7 @@ public:
* @brief Copy a C-style string to another C-style string.
* @param src The source wide string
* @param pstr The destination char string
* @param bufsize The size of the destination buffer
* @param bufsize The length of the destination buffer
* @return The length of the copied string
*/
template<typename T1, typename T2>
......@@ -62,13 +62,13 @@ public:
}
template<size_t N>
static void CopyString(const char* src, char(&dst)[N]) {
dst[0] = 0;
std::strncat(dst, src, N - 1);
std::strncpy(dst, src, N - 1);
dst[N - 1] = 0;
}
template<size_t N>
static void CopyWideString(const wchar_t* src, wchar_t(&dst)[N]) {
dst[0] = 0;
std::wcsncat(dst, src, N - 1);
std::wcsncpy(dst, src, N - 1);
dst[N - 1] = 0;
}
template<typename T>
static bool CheckUTF8Byte(const T* str, int len) {
......
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