Commit 22b3d51f authored by edo9300's avatar edo9300

Added support for yrp

parent 39327771
......@@ -28,6 +28,7 @@ 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;
......@@ -735,6 +736,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
mainGame->gMutex.Unlock();
match_kill = 0;
replay_stream.clear();
old_replay = true;
break;
}
case STOC_DUEL_END: {
......@@ -771,6 +773,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
break;
}
case STOC_REPLAY: {
if (!old_replay) break;
mainGame->gMutex.Lock();
mainGame->wPhase->setVisible(false);
if(mainGame->dInfo.player_type < 7)
......@@ -956,6 +959,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
break;
}
case STOC_NEW_REPLAY: {
old_replay = false;
mainGame->gMutex.Lock();
mainGame->wPhase->setVisible(false);
if(mainGame->dInfo.player_type < 7)
......@@ -994,7 +998,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
char* pbuf = msg;
wchar_t textBuffer[256];
if(!mainGame->dInfo.isReplay) {
if(!mainGame->dInfo.isReplay || mainGame->dInfo.isOldReplay) {
mainGame->dInfo.curMsg = BufferIO::ReadUInt8(pbuf);
if(mainGame->dInfo.curMsg != MSG_WAITING) {
BufferIO::ReplayPacket p;
......
......@@ -617,6 +617,7 @@ bool Game::Initialize() {
btnReplayCancel = env->addButton(rect<s32>(460, 385, 570, 410), wReplay, BUTTON_CANCEL_REPLAY, dataManager.GetSysString(1347));
env->addStaticText(dataManager.GetSysString(1349), rect<s32>(360, 30, 570, 50), false, true, wReplay);
stReplayInfo = env->addStaticText(L"", rect<s32>(360, 60, 570, 350), false, true, wReplay);
chkYrp = env->addCheckBox(false, recti(360, 250, 460, 270), wReplay, -1, dataManager.GetSysString(1999));
env->addStaticText(dataManager.GetSysString(1353), rect<s32>(360, 275, 570, 295), false, true, wReplay);
ebRepStartTurn = env->addEditBox(L"", rect<s32>(360, 300, 460, 320), true, wReplay, -1);
ebRepStartTurn->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
......
......@@ -48,6 +48,7 @@ struct Config {
struct DuelInfo {
bool isStarted;
bool isReplay;
bool isOldReplay;
bool isReplaySkiping;
bool isFirst;
bool isTag;
......@@ -310,6 +311,7 @@ public:
irr::gui::IGUIWindow* wReplay;
irr::gui::IGUIListBox* lstReplayList;
irr::gui::IGUIStaticText* stReplayInfo;
irr::gui::IGUICheckBox* chkYrp;
irr::gui::IGUIButton* btnLoadReplay;
irr::gui::IGUIButton* btnReplayCancel;
irr::gui::IGUIEditBox* ebRepStartTurn;
......
......@@ -274,6 +274,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
if(!ReplayMode::cur_replay.OpenReplay(mainGame->lstReplayList->getListItem(mainGame->lstReplayList->getSelected())))
break;
}
if(mainGame->chkYrp->isChecked() && !ReplayMode::cur_replay.LoadYrp())
break;
mainGame->imgCard->setImage(imageManager.tCover[0]);
mainGame->wCardImg->setVisible(true);
mainGame->wInfos->setVisible(true);
......
This diff is collapsed.
#include "replay.h"
#include "../ocgcore/ocgapi.h"
#include "../ocgcore/card.h"
#include "../ocgcore/field.h"
#include <algorithm>
#include "lzma/LzmaLib.h"
......@@ -269,4 +270,31 @@ void Replay::Rewind() {
pdata = replay_data;
}
bool Replay::LoadYrp() {
if (pheader.flag & REPLAY_NEWREPLAY) {
pdata += (4 + ((pheader.flag & REPLAY_TAG) ? 160 : 80));
BufferIO::ReplayPacket p;
while (ReadNextPacket(&p))
if (p.message == OLD_REPLAY_MODE) {
char* prep = (char*)p.data;
memcpy(&pheader, prep, sizeof(ReplayHeader));
prep += sizeof(ReplayHeader);
if(pheader.flag & REPLAY_COMPRESSED) {
comp_size = (size_t)(p.length - sizeof(ReplayHeader));
replay_size = pheader.datasize;
if (LzmaUncompress(replay_data, &replay_size, (unsigned char*)prep, &comp_size, pheader.props, 5) != SZ_OK)
return false;
} else {
comp_size = fread(replay_data, 1, 0x20000, fp);
fclose(fp);
replay_size = comp_size;
}
pdata = replay_data;
is_replaying = true;
return true;
}
}
return !(pheader.flag & REPLAY_NEWREPLAY);
}
}
......@@ -11,6 +11,7 @@ namespace ygo {
#define REPLAY_DECODED 0x4
#define REPLAY_SINGLE_MODE 0x8
#define REPLAY_LUA64 0x10
#define REPLAY_NEWREPLAY 0x20
struct ReplayHeader {
unsigned int id;
......@@ -42,12 +43,12 @@ public:
bool ReadNextPacket(BufferIO::ReplayPacket* packet);
bool ReadNextResponse(unsigned char resp[64]);
void ReadName(wchar_t* data);
void ReadHeader(ReplayHeader& header);
void ReadData(void* data, unsigned int length);
int ReadInt32();
short ReadInt16();
char ReadInt8();
void Rewind();
bool LoadYrp();
FILE* fp;
ReplayHeader pheader;
......
......@@ -9,6 +9,7 @@
namespace ygo {
long ReplayMode::pduel = 0;
bool ReplayMode::yrp = false;
Replay ReplayMode::cur_replay;
std::vector<BufferIO::ReplayPacket> ReplayMode::current_stream;
bool ReplayMode::is_continuing = true;
......@@ -26,6 +27,10 @@ bool ReplayMode::StartReplay(int skipturn) {
skip_turn = skipturn;
if(skip_turn < 0)
skip_turn = 0;
yrp = cur_replay.pheader.id == 0x31707279;
if(yrp)
Thread::NewThread(OldReplayThread, 0);
else
Thread::NewThread(ReplayThread, 0);
return true;
}
......@@ -51,13 +56,6 @@ void ReplayMode::Pause(bool is_pause, bool is_step) {
mainGame->actionSignal.Set();
}
}
bool ReplayMode::ReadReplayResponse() {
unsigned char resp[64];
bool result = cur_replay.ReadNextResponse(resp);
if(result)
set_responseb(pduel, resp);
return result;
}
int ReplayMode::ReplayThread(void* param) {
const ReplayHeader& rh = cur_replay.pheader;
mainGame->dInfo.isFirst = true;
......@@ -123,6 +121,8 @@ int ReplayMode::ReplayThread(void* param) {
return 0;
}
void ReplayMode::EndDuel() {
if(yrp)
end_duel(pduel);
if(!is_closing) {
mainGame->actionSignal.Reset();
mainGame->gMutex.Lock();
......@@ -135,6 +135,7 @@ void ReplayMode::EndDuel() {
mainGame->gMutex.Lock();
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isReplay = false;
mainGame->dInfo.isOldReplay = false;
mainGame->gMutex.Unlock();
mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set();
......@@ -149,10 +150,17 @@ void ReplayMode::EndDuel() {
}
}
void ReplayMode::Restart(bool refresh) {
if(yrp) {
end_duel(pduel);
cur_replay.Rewind();
}
mainGame->dInfo.isStarted = false;
mainGame->dField.Clear();
mainGame->dInfo.tag_player[0] = false;
mainGame->dInfo.tag_player[1] = false;
if (yrp && !StartDuel()) {
EndDuel();
}
if(refresh) {
mainGame->dField.RefreshAllCards();
mainGame->dInfo.isStarted = true;
......
......@@ -12,6 +12,7 @@ namespace ygo {
class ReplayMode {
private:
static long pduel;
static bool yrp;
static bool is_continuing;
static bool is_closing;
static bool is_pausing;
......@@ -35,11 +36,23 @@ public:
static void Pause(bool is_pause, bool is_step);
static bool ReadReplayResponse();
static int ReplayThread(void* param);
static int OldReplayThread(void* param);
static bool StartDuel();
static void EndDuel();
static void Restart(bool refresh);
static void Undo();
static bool ReplayAnalyze(BufferIO::ReplayPacket p);
static bool ReplayAnalyze(char* msg, unsigned int len);
static void ReplayRefresh(int flag = 0xf81fff);
static void ReplayRefreshHand(int player, int flag = 0x781fff);
static void ReplayRefreshGrave(int player, int flag = 0x181fff);
static void ReplayRefreshDeck(int player, int flag = 0x181fff);
static void ReplayRefreshExtra(int player, int flag = 0x181fff);
static void ReplayRefreshSingle(int player, int location, int sequence, int flag = 0xf81fff);
static void ReplayReload();
static int MessageHandler(long fduel, int type);
};
}
......
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