Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to replay a yrp file? #2516

Open
OhnkytaBlabdey opened this issue Mar 7, 2024 · 0 comments
Open

how to replay a yrp file? #2516

OhnkytaBlabdey opened this issue Mar 7, 2024 · 0 comments

Comments

@OhnkytaBlabdey
Copy link

我照着replay_mdoe.cpp上面改了一下,想回放录像文件。

遇到的问题:
录像是2个windbot客户端在1.036.0服务端1v1,服务端保存得到的,flag是REPLAY_UNIFORM,用正确版本的1.036.0客户端可以正常播放。

我写的代码会报错MSG_RETRY。顺着搜索了一下这个变量,似乎是回放时出现了不同步导致的。
每一步用query_field_info打印了一下日志,一开始是一致的,后面确实出现了不一致,回放太长了人肉找不到哪一步出错。
比较replay_mode.cpp的代码没找到问题在哪里。
ocgapi里有set_responsei,但是replay_mode.cpp没有调用过这个function,也没有理解原因。

想问一下怎样正确回放yrp文件。

下面是代码

	Replay *replay = new Replay();
	if (!replay->OpenReplay(L"2024-02-16 01-49-58 54541.yrp")) {
		return 1;
	}
	wchar_t player_name[2][40] = {0,0};
	replay->ReadName(player_name[0]);
	replay->ReadName(player_name[1]);
	int start_lp, start_hand, draw_count,opt;
	start_lp = replay->ReadInt32();
	start_hand = replay->ReadInt32();
	draw_count = replay->ReadInt32();
	opt = replay->ReadInt32();
	auto duel_seed = replay->pheader.seed;
	auto isSingleMode = !!(replay->pheader.flag & REPLAY_SINGLE_MODE);
	dataManager.LoadDB(L"cards.cdb");
	set_script_reader(ygo::DataManager::ScriptReaderEx);
	set_card_reader(ygo::DataManager::CardReader);
	set_message_handler(ygo::SingleDuel::MessageHandler);
	auto pduel = create_duel(duel_seed);
	set_player_info(pduel, 0, start_lp, start_hand, draw_count);
	set_player_info(pduel, 1, start_lp, start_hand, draw_count);
	int main_size[2];
	int extra_size[2];
	main_size[0] = replay->ReadInt32();
	for (int32 i = (int32)main_size[0]- 1; i >= 0; --i) {
		auto cid = (unsigned int)replay->ReadInt32();
		new_card(pduel, cid, 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE);
	}
	extra_size[0] = replay->ReadInt32();
	for (int32 i = (int32)extra_size[0]- 1; i >= 0; --i) {
		new_card(pduel, (unsigned int)replay->ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE);
	}
	main_size[1] = replay->ReadInt32();
	for (int32 i = (int32)main_size[1] - 1; i >= 0; --i) {
		auto cid = (unsigned int)replay->ReadInt32();
		new_card(pduel, cid, 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE);
	}
	extra_size[1] = replay->ReadInt32();
	for (int32 i = (int32)extra_size[1]- 1; i >= 0; --i) {
		new_card(pduel, (unsigned int)replay->ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE);
	}
	if (!(replay->pheader.flag & REPLAY_UNIFORM))
		opt |= DUEL_OLD_REPLAY;
	start_duel(pduel, opt);
	unsigned char resp[64];
	std::vector<unsigned char> engineBuffer;
	engineBuffer.resize(SIZE_MESSAGE_BUFFER);
	int is_continuing = analyze_continue;
	if (isSingleMode) {
		int len = get_message(pduel, engineBuffer.data());
		if (len > 0)
			is_continuing = ReplayAnalyze(engineBuffer.data(), len);
		if (is_continuing) {
			bool result = replay->ReadNextResponse(resp);
			if (result)
				set_responseb(pduel, resp);
			else
				is_continuing = analyze_win;
		}
	}
	while (is_continuing > 0) {
		unsigned int result = process(pduel);
		int len = result & PROCESSOR_BUFFER_LEN;
		if (len > 0) {
			if (len > (int)engineBuffer.size())
				engineBuffer.resize(len);
			get_message(pduel, engineBuffer.data());
			is_continuing = ReplayAnalyze(engineBuffer.data(), len);
			if (is_continuing == analyze_resp) {
				bool result = replay->ReadNextResponse(resp);
				if (result)
					set_responseb(pduel, resp);
				else
					is_continuing = analyze_win;
			}
		}
	}
	end_duel(pduel);
int ReplayAnalyze(unsigned char* msg, unsigned int len) {
	unsigned char* pbuf = msg;
	//int player, count;
	while (pbuf - msg < (int)len) {
		auto curMsg = BufferIO::ReadUInt8(pbuf);
		switch (curMsg) {
			case MSG_RETRY: {
				printf("MSG_RETRY\n");
				return analyze_retry;
			}
			case MSG_WIN: {
				printf("MSG_WIN\n");
				return analyze_win;
			}
			case MSG_SELECT_BATTLECMD:
				printf("MSG_SELECT_BATTLECMD\n"); return analyze_resp;
			case MSG_SELECT_IDLECMD:
				printf("MSG_SELECT_IDLECMD\n"); return analyze_resp;
			case MSG_SELECT_EFFECTYN:
				printf("MSG_SELECT_EFFECTYN\n"); return analyze_resp;
			case MSG_SELECT_YESNO:
				printf("MSG_SELECT_YESNO\n"); return analyze_resp;
			case MSG_SELECT_OPTION:
				printf("MSG_SELECT_OPTION\n"); return analyze_resp;
			case MSG_SELECT_CARD:
				printf("MSG_SELECT_CARD\n"); return analyze_resp;
			case MSG_SELECT_TRIBUTE:
				printf("MSG_SELECT_TRIBUTE\n"); return analyze_resp;
			case MSG_SELECT_UNSELECT_CARD:
				printf("MSG_SELECT_UNSELECT_CARD\n"); return analyze_resp;
			case MSG_SELECT_CHAIN:
				printf("MSG_SELECT_CHAIN\n"); return analyze_resp;
			case MSG_SELECT_PLACE:
				printf("MSG_SELECT_PLACE\n"); return analyze_resp;
			case MSG_SELECT_DISFIELD:
				printf("MSG_SELECT_DISFIELD\n"); return analyze_resp;
			case MSG_SELECT_POSITION:
				printf("MSG_SELECT_POSITION\n"); return analyze_resp;
			case MSG_SELECT_COUNTER:
				printf("MSG_SELECT_COUNTER\n"); return analyze_resp;
			case MSG_SELECT_SUM:
				printf("MSG_SELECT_SUM\n"); return analyze_resp;
			case MSG_SORT_CARD:
				printf("MSG_SORT_CARD\n"); return analyze_resp;
			case MSG_ROCK_PAPER_SCISSORS:
				printf("MSG_ROCK_PAPER_SCISSORS\n"); return analyze_resp;
			case MSG_ANNOUNCE_RACE:
				printf("MSG_ANNOUNCE_RACE\n"); return analyze_resp;
			case MSG_ANNOUNCE_ATTRIB:
				printf("MSG_ANNOUNCE_ATTRIB\n"); return analyze_resp;
			case MSG_ANNOUNCE_CARD:
				printf("MSG_ANNOUNCE_CARD\n"); return analyze_resp;
			case MSG_ANNOUNCE_NUMBER:
				printf("MSG_ANNOUNCE_NUMBER\n"); return analyze_resp;
			case MSG_HINT: { printf("MSG_HINT\n"); return analyze_continue; }
			case MSG_CONFIRM_DECKTOP: { printf("MSG_CONFIRM_DECKTOP\n"); return analyze_continue; }
			case MSG_CONFIRM_EXTRATOP: { printf("MSG_CONFIRM_EXTRATOP\n"); return analyze_continue; }
			case MSG_CONFIRM_CARDS: { printf("MSG_CONFIRM_CARDS\n"); return analyze_continue; }
			case MSG_SHUFFLE_DECK: { printf("MSG_SHUFFLE_DECK\n"); return analyze_continue; }
			case MSG_SHUFFLE_HAND: { printf("MSG_SHUFFLE_HAND\n"); return analyze_continue; }
			case MSG_SHUFFLE_EXTRA: { printf("MSG_SHUFFLE_EXTRA\n"); return analyze_continue; }
			case MSG_REFRESH_DECK: { printf("MSG_REFRESH_DECK\n"); return analyze_continue; }
			case MSG_SWAP_GRAVE_DECK: { printf("MSG_SWAP_GRAVE_DECK\n"); return analyze_continue; }
			case MSG_REVERSE_DECK: { printf("MSG_REVERSE_DECK\n"); return analyze_continue; }
			case MSG_DECK_TOP: { printf("MSG_DECK_TOP\n"); return analyze_continue; }
			case MSG_SHUFFLE_SET_CARD: { printf("MSG_SHUFFLE_SET_CARD\n"); return analyze_continue; }
			case MSG_NEW_TURN: { printf("MSG_NEW_TURN\n"); return analyze_continue; }
			case MSG_NEW_PHASE: { printf("MSG_NEW_PHASE\n"); return analyze_continue; }
			case MSG_MOVE: { printf("MSG_MOVE\n"); return analyze_continue; }
			case MSG_POS_CHANGE: { printf("MSG_POS_CHANGE\n"); return analyze_continue; }
			case MSG_SET: { printf("MSG_SET\n"); return analyze_continue; }
			case MSG_SWAP: { printf("MSG_SWAP\n"); return analyze_continue; }
			case MSG_FIELD_DISABLED: { printf("MSG_FIELD_DISABLED\n"); return analyze_continue; }
			case MSG_SUMMONING: { printf("MSG_SUMMONING\n"); return analyze_continue; }
			case MSG_SUMMONED: { printf("MSG_SUMMONED\n"); return analyze_continue; }
			case MSG_SPSUMMONING: { printf("MSG_SPSUMMONING\n"); return analyze_continue; }
			case MSG_SPSUMMONED: { printf("MSG_SPSUMMONED\n"); return analyze_continue; }
			case MSG_FLIPSUMMONING: { printf("MSG_FLIPSUMMONING\n"); return analyze_continue; }
			case MSG_FLIPSUMMONED: { printf("MSG_FLIPSUMMONED\n"); return analyze_continue; }
			case MSG_CHAINING: { printf("MSG_CHAINING\n"); return analyze_continue; }
			case MSG_CHAINED: { printf("MSG_CHAINED\n"); return analyze_continue; }
			case MSG_CHAIN_SOLVING: { printf("MSG_CHAIN_SOLVING\n"); return analyze_continue; }
			case MSG_CHAIN_SOLVED: { printf("MSG_CHAIN_SOLVED\n"); return analyze_continue; }
			case MSG_CHAIN_END: { printf("MSG_CHAIN_END\n"); return analyze_continue; }
			case MSG_CHAIN_NEGATED: { printf("MSG_CHAIN_NEGATED\n"); return analyze_continue; }
			case MSG_CHAIN_DISABLED: { printf("MSG_CHAIN_DISABLED\n"); return analyze_continue; }
			case MSG_RANDOM_SELECTED: { printf("MSG_RANDOM_SELECTED\n"); return analyze_continue; }
			case MSG_BECOME_TARGET: { printf("MSG_BECOME_TARGET\n"); return analyze_continue; }
			case MSG_DRAW: { printf("MSG_DRAW\n"); return analyze_continue; }
			case MSG_DAMAGE: { printf("MSG_DAMAGE\n"); return analyze_continue; }
			case MSG_RECOVER: { printf("MSG_RECOVER\n"); return analyze_continue; }
			case MSG_EQUIP: { printf("MSG_EQUIP\n"); return analyze_continue; }
			case MSG_LPUPDATE: { printf("MSG_LPUPDATE\n"); return analyze_continue; }
			case MSG_UNEQUIP: { printf("MSG_UNEQUIP\n"); return analyze_continue; }
			case MSG_CARD_TARGET: { printf("MSG_CARD_TARGET\n"); return analyze_continue; }
			case MSG_CANCEL_TARGET: { printf("MSG_CANCEL_TARGET\n"); return analyze_continue; }
			case MSG_PAY_LPCOST: { printf("MSG_PAY_LPCOST\n"); return analyze_continue; }
			case MSG_ADD_COUNTER: { printf("MSG_ADD_COUNTER\n"); return analyze_continue; }
			case MSG_REMOVE_COUNTER: { printf("MSG_REMOVE_COUNTER\n"); return analyze_continue; }
			case MSG_ATTACK: { printf("MSG_ATTACK\n"); return analyze_continue; }
			case MSG_BATTLE: { printf("MSG_BATTLE\n"); return analyze_continue; }
			case MSG_ATTACK_DISABLED: { printf("MSG_ATTACK_DISABLED\n"); return analyze_continue; }
			case MSG_DAMAGE_STEP_START: { printf("MSG_DAMAGE_STEP_START\n"); return analyze_continue; }
			case MSG_DAMAGE_STEP_END: { printf("MSG_DAMAGE_STEP_END\n"); return analyze_continue; }
			case MSG_MISSED_EFFECT: { printf("MSG_MISSED_EFFECT\n"); return analyze_continue; }
			case MSG_TOSS_COIN: { printf("MSG_TOSS_COIN\n"); return analyze_continue; }
			case MSG_TOSS_DICE: { printf("MSG_TOSS_DICE\n"); return analyze_continue; }
			case MSG_HAND_RES: { printf("MSG_HAND_RES\n"); return analyze_continue; }
			case MSG_CARD_HINT: { printf("MSG_CARD_HINT\n"); return analyze_continue; }
			case MSG_PLAYER_HINT: { printf("MSG_PLAYER_HINT\n"); return analyze_continue; }
			case MSG_MATCH_KILL: { printf("MSG_MATCH_KILL\n"); return analyze_win; }
			case MSG_TAG_SWAP: { printf("MSG_TAG_SWAP\n"); return analyze_continue; }
			case MSG_RELOAD_FIELD: { printf("MSG_RELOAD_FIELD\n"); return analyze_continue; }
			case MSG_AI_NAME: { printf("MSG_AI_NAME\n"); return analyze_continue; }
			case MSG_SHOW_HINT: { printf("MSG_SHOW_HINT\n"); return analyze_continue; }
			default:
				return analyze_continue;
		}
	}
	return analyze_continue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant