Commit 07614071 authored by Chen Bill's avatar Chen Bill Committed by GitHub

use std::memcpy in class Replay (#2549)

* use std::memcpy in class Replay

* remove pointer casting
parent 4c91f19f
......@@ -682,8 +682,7 @@ void ClientField::ShowSelectOption(int select_hint) {
pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + newheight;
mainGame->wOptions->setRelativePosition(pos);
} else {
mainGame->SetStaticText(mainGame->stOptions, 310, mainGame->guiFont,
(wchar_t*)dataManager.GetDesc(select_options[0]));
mainGame->SetStaticText(mainGame->stOptions, 310, mainGame->guiFont, dataManager.GetDesc(select_options[0]));
mainGame->stOptions->setVisible(true);
mainGame->btnOptionp->setVisible(false);
mainGame->btnOptionn->setVisible(count > 1);
......
......@@ -225,7 +225,7 @@ void DeckManager::GetCategoryPath(wchar_t* ret, int index, const wchar_t* text)
void DeckManager::GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck) {
wchar_t filepath[256];
wchar_t catepath[256];
wchar_t* deckname = (wchar_t*)cbDeck->getItem(cbDeck->getSelected());
const wchar_t* deckname = cbDeck->getItem(cbDeck->getSelected());
if(deckname != NULL) {
GetCategoryPath(catepath, cbCategory->getSelected(), cbCategory->getText());
myswprintf(filepath, L"%ls/%ls.ydk", catepath, deckname);
......
......@@ -3,11 +3,7 @@
namespace ygo {
Replay::Replay()
: fp(nullptr), pheader(), pdata(nullptr), replay_size(0), comp_size(0), is_recording(false), is_replaying(false) {
#ifdef _WIN32
recording_fp = nullptr;
#endif
Replay::Replay() {
replay_data = new unsigned char[MAX_REPLAY_SIZE];
comp_data = new unsigned char[MAX_COMP_SIZE];
}
......@@ -134,8 +130,8 @@ void Replay::EndRecord() {
comp_size = MAX_COMP_SIZE;
int ret = LzmaCompress(comp_data, &comp_size, replay_data, replay_size, pheader.props, &propsize, 5, 1 << 24, 3, 0, 2, 32, 1);
if (ret != SZ_OK) {
*((int*)(comp_data)) = ret;
comp_size = sizeof(ret);
std::memcpy(comp_data, &ret, sizeof ret);
comp_size = sizeof ret;
}
is_recording = false;
}
......
......@@ -17,16 +17,13 @@ namespace ygo {
#define MAX_COMP_SIZE 0x2000
struct ReplayHeader {
unsigned int id;
unsigned int version;
unsigned int flag;
unsigned int seed;
unsigned int datasize;
unsigned int start_time;
unsigned char props[8];
ReplayHeader()
: id(0), version(0), flag(0), seed(0), datasize(0), start_time(0), props{ 0 } {}
unsigned int id{};
unsigned int version{};
unsigned int flag{};
unsigned int seed{};
unsigned int datasize{};
unsigned int start_time{};
unsigned char props[8]{};
};
class Replay {
......@@ -59,21 +56,21 @@ public:
char ReadInt8();
void Rewind();
FILE* fp;
FILE* fp{ nullptr };
#ifdef _WIN32
HANDLE recording_fp;
HANDLE recording_fp{ nullptr };
#endif
ReplayHeader pheader;
unsigned char* replay_data;
unsigned char* comp_data;
size_t replay_size;
size_t comp_size;
size_t replay_size{};
size_t comp_size{};
private:
unsigned char* pdata;
bool is_recording;
bool is_replaying;
unsigned char* pdata{ nullptr };
bool is_recording{};
bool is_replaying{};
};
}
......
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