Commit d1c4b218 authored by edo9300's avatar edo9300

Added replay recording without writing

parent 595e266a
......@@ -28,7 +28,6 @@ mtrandom DuelClient::rnd;
std::vector<BufferIO::ReplayPacket> DuelClient::replay_stream;
Replay DuelClient::last_replay;
bool DuelClient::old_replay = true;
bool DuelClient::is_refreshing = false;
int DuelClient::match_kill = 0;
......@@ -797,8 +796,8 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
ReplayHeader pheader;
memcpy(&pheader, prep, sizeof(ReplayHeader));
replay_stream.push_back(BufferIO::ReplayPacket(OLD_REPLAY_MODE, prep, len - 1));
if(old_replay && mainGame->saveReplay) {
last_replay.BeginRecord();
if(mainGame->saveReplay) {
last_replay.BeginRecord(false);
last_replay.WriteHeader(pheader);
last_replay.pheader.id = 0x58707279;
last_replay.WriteData(mainGame->dInfo.hostname, 40, false);
......@@ -807,7 +806,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
last_replay.WriteData(mainGame->dInfo.hostname_tag, 40, false);
last_replay.WriteData(mainGame->dInfo.clientname_tag, 40, false);
}
last_replay.WriteInt32(mainGame->dInfo.duel_field | mainGame->dInfo.extraval);
last_replay.WriteInt32(mainGame->dInfo.duel_field | mainGame->dInfo.extraval >> 8);
last_replay.WriteStream(replay_stream);
last_replay.EndRecord();
}
......@@ -957,12 +956,37 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
break;
}
case STOC_NEW_REPLAY: {
char* prep = pdata;
memcpy(&last_replay.pheader, prep, sizeof(ReplayHeader));
prep += sizeof(ReplayHeader);
memcpy(last_replay.comp_data, prep, len - sizeof(ReplayHeader) - 1);
last_replay.comp_size = len - sizeof(ReplayHeader) - 1;
old_replay = false;
mainGame->gMutex.Lock();
mainGame->wPhase->setVisible(false);
if(mainGame->dInfo.player_type < 7)
mainGame->btnLeaveGame->setVisible(false);
mainGame->btnChainIgnore->setVisible(false);
mainGame->btnChainAlways->setVisible(false);
mainGame->btnChainWhenAvail->setVisible(false);
mainGame->btnCancelOrFinish->setVisible(false);
time_t nowtime = time(NULL);
struct tm *localedtime = localtime(&nowtime);
char timebuf[40];
strftime(timebuf, 40, "%Y-%m-%d %H-%M-%S", localedtime);
size_t size = strlen(timebuf) + 1;
wchar_t timetext[80];
mbstowcs(timetext, timebuf, size);
mainGame->ebRSName->setText(timetext);
mainGame->PopupElement(mainGame->wReplaySave);
mainGame->gMutex.Unlock();
mainGame->replaySignal.Reset();
mainGame->replaySignal.Wait();
if(mainGame->saveReplay || !is_host) {
char* prep = pdata;
Replay new_replay;
memcpy(&new_replay.pheader, prep, sizeof(ReplayHeader));
prep += sizeof(ReplayHeader);
memcpy(new_replay.comp_data, prep, len - sizeof(ReplayHeader) - 1);
new_replay.comp_size = len - sizeof(ReplayHeader) - 1;
if(mainGame->saveReplay)
new_replay.SaveReplay(mainGame->ebRSName->getText());
else new_replay.SaveReplay(L"_LastReplay");
}
break;
}
}
......
......@@ -48,7 +48,6 @@ public:
static void HandleSTOCPacketLan(char* data, unsigned int len);
static std::vector<BufferIO::ReplayPacket> replay_stream;
static Replay last_replay;
static bool old_replay;
static int ClientAnalyze(char* msg, unsigned int len);
static void SetResponseI(int respI);
static void SetResponseB(void* respB, unsigned char len);
......
......@@ -16,36 +16,25 @@ Replay::~Replay() {
delete[] replay_data;
delete[] comp_data;
}
void Replay::BeginRecord() {
void Replay::BeginRecord(bool write) {
#ifdef _WIN32
if(is_recording)
if(is_recording && is_writing)
CloseHandle(recording_fp);
recording_fp = CreateFileW(L"./replay/_LastReplay.yrp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
if(recording_fp == INVALID_HANDLE_VALUE)
return;
#else
if(is_recording)
fclose(fp);
fp = fopen("./replay/_LastReplay.yrp", "wb");
if(!fp)
return;
#endif
pdata = replay_data;
is_recording = true;
}
void Replay::BeginRecord2() {
#ifdef _WIN32
if(is_recording)
CloseHandle(recording_fp);
recording_fp = CreateFileW(L"./replay/_LastReplay2.yrp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
if(recording_fp == INVALID_HANDLE_VALUE)
return;
is_writing = write;
if(is_writing) {
recording_fp = CreateFileW(L"./replay/_LastReplay.yrp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
if(recording_fp == INVALID_HANDLE_VALUE)
return;
}
#else
if(is_recording)
if(is_recording && is_writing)
fclose(fp);
fp = fopen("./replay/_LastReplay2.yrp", "wb");
if(!fp)
return;
is_writing = write;
if(is_writing) {
fp = fopen("./replay/_LastReplay.yrp", "wb");
if(!fp)
return;
}
#endif
pdata = replay_data;
is_recording = true;
......@@ -62,6 +51,7 @@ void Replay::WriteStream(std::vector<BufferIO::ReplayPacket> stream) {
}
void Replay::WriteHeader(ReplayHeader& header) {
pheader = header;
if(!is_writing) return;
#ifdef _WIN32
DWORD size;
WriteFile(recording_fp, &header, sizeof(header), &size, NULL);
......@@ -75,6 +65,7 @@ void Replay::WriteData(const void* data, unsigned int length, bool flush) {
return;
memcpy(pdata, data, length);
pdata += length;
if(!is_writing) return;
#ifdef _WIN32
DWORD size;
WriteFile(recording_fp, data, length, &size, NULL);
......@@ -89,6 +80,7 @@ void Replay::WriteInt32(int data, bool flush) {
return;
*((int*)(pdata)) = data;
pdata += 4;
if(!is_writing) return;
#ifdef _WIN32
DWORD size;
WriteFile(recording_fp, &data, sizeof(int), &size, NULL);
......@@ -103,6 +95,7 @@ void Replay::WriteInt16(short data, bool flush) {
return;
*((short*)(pdata)) = data;
pdata += 2;
if(!is_writing) return;
#ifdef _WIN32
DWORD size;
WriteFile(recording_fp, &data, sizeof(short), &size, NULL);
......@@ -117,6 +110,7 @@ void Replay::WriteInt8(char data, bool flush) {
return;
*pdata = data;
pdata++;
if(!is_writing) return;
#ifdef _WIN32
DWORD size;
WriteFile(recording_fp, &data, sizeof(char), &size, NULL);
......@@ -129,6 +123,7 @@ void Replay::WriteInt8(char data, bool flush) {
void Replay::Flush() {
if(!is_recording)
return;
if(!is_writing) return;
#ifdef _WIN32
#else
fflush(fp);
......@@ -137,6 +132,7 @@ void Replay::Flush() {
void Replay::EndRecord() {
if(!is_recording)
return;
if(is_writing)
#ifdef _WIN32
CloseHandle(recording_fp);
#else
......
......@@ -26,8 +26,7 @@ class Replay {
public:
Replay();
~Replay();
void BeginRecord();
void BeginRecord2();
void BeginRecord(bool write = true);
void WriteStream(std::vector<BufferIO::ReplayPacket> stream);
void WritePacket(BufferIO::ReplayPacket p);
void WriteHeader(ReplayHeader& header);
......@@ -61,6 +60,7 @@ public:
size_t replay_size;
size_t comp_size;
bool is_recording;
bool is_writing;
bool is_replaying;
};
......
......@@ -400,13 +400,13 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
rh.flag = REPLAY_LUA64;
time_t seed = time(0);
rh.seed = seed;
last_replay.BeginRecord();
last_replay.BeginRecord(false);
last_replay.WriteHeader(rh);
rnd.reset(seed);
last_replay.WriteData(players[0]->name, 40, false);
last_replay.WriteData(players[1]->name, 40, false);
//records the replay with the new system
new_replay.BeginRecord2();
new_replay.BeginRecord();
rh.id = 0x58707279;
new_replay.WriteHeader(rh);
new_replay.WriteData(players[0]->name, 40, false);
......
......@@ -108,10 +108,10 @@ int SingleMode::SinglePlayThread(void* param) {
char engineBuffer[0x1000];
is_closing = false;
is_continuing = true;
last_replay.BeginRecord();
last_replay.BeginRecord(false);
last_replay.WriteHeader(rh);
//records the replay with the new system
new_replay.BeginRecord2();
new_replay.BeginRecord();
rh.id = 0x58707279;
new_replay.WriteHeader(rh);
replay_stream.clear();
......
......@@ -357,7 +357,7 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
rh.flag = REPLAY_TAG + REPLAY_LUA64;
time_t seed = time(0);
rh.seed = seed;
last_replay.BeginRecord();
last_replay.BeginRecord(false);
last_replay.WriteHeader(rh);
rnd.reset(seed);
last_replay.WriteData(players[0]->name, 40, false);
......@@ -365,7 +365,7 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
last_replay.WriteData(players[2]->name, 40, false);
last_replay.WriteData(players[3]->name, 40, false);
//records the replay with the new system
new_replay.BeginRecord2();
new_replay.BeginRecord();
rh.id = 0x58707279;
new_replay.WriteHeader(rh);
new_replay.WriteData(players[0]->name, 40, false);
......
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