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

Use BufferIO::ReadUInt8 (#2537)

* change code, location, position to unsigned

* change code, location, postion to unsigned

* use ReadUInt8() for 1-byte data

* Game::LocalPlayer() returns 0, 1

* wrong matching

* change card code to unsigned
parent 497b364a
......@@ -113,10 +113,10 @@ void ClientCard::UpdateInfo(unsigned char* buf) {
if(flag & QUERY_REASON_CARD)
buf += 4;
if(flag & QUERY_EQUIP_CARD) {
int c = BufferIO::ReadInt8(buf);
int l = BufferIO::ReadInt8(buf);
int s = BufferIO::ReadInt8(buf);
BufferIO::ReadInt8(buf);
int c = BufferIO::ReadUInt8(buf);
unsigned int l = BufferIO::ReadUInt8(buf);
int s = BufferIO::ReadUInt8(buf);
BufferIO::ReadUInt8(buf);
ClientCard* ecard = mainGame->dField.GetCard(mainGame->LocalPlayer(c), l, s);
if (ecard) {
equipTarget = ecard;
......@@ -126,10 +126,10 @@ void ClientCard::UpdateInfo(unsigned char* buf) {
if(flag & QUERY_TARGET_CARD) {
int count = BufferIO::ReadInt32(buf);
for(int i = 0; i < count; ++i) {
int c = BufferIO::ReadInt8(buf);
int l = BufferIO::ReadInt8(buf);
int s = BufferIO::ReadInt8(buf);
BufferIO::ReadInt8(buf);
int c = BufferIO::ReadUInt8(buf);
unsigned int l = BufferIO::ReadUInt8(buf);
int s = BufferIO::ReadUInt8(buf);
BufferIO::ReadUInt8(buf);
ClientCard* tcard = mainGame->dField.GetCard(mainGame->LocalPlayer(c), l, s);
if (tcard) {
cardTarget.insert(tcard);
......
This diff is collapsed.
......@@ -1775,8 +1775,9 @@ void Game::CloseDuelWindow() {
ClearTextures();
closeDoneSignal.Set();
}
int Game::LocalPlayer(int player) {
return dInfo.isFirst ? player : 1 - player;
int Game::LocalPlayer(int player) const {
int pid = player ? 1 : 0;
return dInfo.isFirst ? pid : 1 - pid;
}
const wchar_t* Game::LocalName(int local_player) {
return local_player == 0 ? dInfo.hostname : dInfo.clientname;
......
......@@ -167,7 +167,7 @@ public:
void CloseGameWindow();
void CloseDuelWindow();
int LocalPlayer(int player);
int LocalPlayer(int player) const;
const wchar_t* LocalName(int local_player);
bool HasFocus(EGUI_ELEMENT_TYPE type) const {
......
......@@ -352,141 +352,141 @@ bool ReplayMode::ReplayAnalyze(unsigned char* msg, unsigned int len) {
return false;
}
case MSG_SELECT_BATTLECMD: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 11;
count = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 8 + 2;
ReplayRefresh();
return ReadReplayResponse();
}
case MSG_SELECT_IDLECMD: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 7;
count = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 7;
count = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 7;
count = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 7;
count = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 7;
count = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 11 + 3;
ReplayRefresh();
return ReadReplayResponse();
}
case MSG_SELECT_EFFECTYN: {
player = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
pbuf += 12;
return ReadReplayResponse();
}
case MSG_SELECT_YESNO: {
player = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
pbuf += 4;
return ReadReplayResponse();
}
case MSG_SELECT_OPTION: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 4;
return ReadReplayResponse();
}
case MSG_SELECT_CARD:
case MSG_SELECT_TRIBUTE: {
player = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
pbuf += 3;
count = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 8;
return ReadReplayResponse();
}
case MSG_SELECT_UNSELECT_CARD: {
player = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
pbuf += 4;
count = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 8;
count = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 8;
return ReadReplayResponse();
}
case MSG_SELECT_CHAIN: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += 10 + count * 13;
return ReadReplayResponse();
}
case MSG_SELECT_PLACE:
case MSG_SELECT_DISFIELD: {
player = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
pbuf += 5;
return ReadReplayResponse();
}
case MSG_SELECT_POSITION: {
player = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
pbuf += 5;
return ReadReplayResponse();
}
case MSG_SELECT_COUNTER: {
player = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
pbuf += 4;
count = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 9;
return ReadReplayResponse();
}
case MSG_SELECT_SUM: {
pbuf++;
player = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
pbuf += 6;
count = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 11;
count = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 11;
return ReadReplayResponse();
}
case MSG_SORT_CARD: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 7;
return ReadReplayResponse();
}
case MSG_CONFIRM_DECKTOP: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 7;
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
}
case MSG_CONFIRM_EXTRATOP: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 7;
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
}
case MSG_CONFIRM_CARDS: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 7;
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
}
case MSG_SHUFFLE_DECK: {
player = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
DuelClient::ClientAnalyze(offset, pbuf - offset);
ReplayRefreshDeck(player);
break;
}
case MSG_SHUFFLE_HAND: {
/*int oplayer = */BufferIO::ReadInt8(pbuf);
int count = BufferIO::ReadInt8(pbuf);
/*int oplayer = */BufferIO::ReadUInt8(pbuf);
int count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 4;
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
}
case MSG_SHUFFLE_EXTRA: {
/*int oplayer = */BufferIO::ReadInt8(pbuf);
int count = BufferIO::ReadInt8(pbuf);
/*int oplayer = */BufferIO::ReadUInt8(pbuf);
int count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 4;
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
......@@ -497,7 +497,7 @@ bool ReplayMode::ReplayAnalyze(unsigned char* msg, unsigned int len) {
break;
}
case MSG_SWAP_GRAVE_DECK: {
player = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
DuelClient::ClientAnalyze(offset, pbuf - offset);
ReplayRefreshGrave(player);
break;
......@@ -515,7 +515,7 @@ bool ReplayMode::ReplayAnalyze(unsigned char* msg, unsigned int len) {
}
case MSG_SHUFFLE_SET_CARD: {
pbuf++;
count = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 8;
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
......@@ -529,7 +529,7 @@ bool ReplayMode::ReplayAnalyze(unsigned char* msg, unsigned int len) {
mainGame->gMutex.unlock();
}
}
player = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
}
......@@ -653,22 +653,22 @@ bool ReplayMode::ReplayAnalyze(unsigned char* msg, unsigned int len) {
}
case MSG_CARD_SELECTED:
case MSG_RANDOM_SELECTED: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 4;
DuelClient::ClientAnalyze(offset, pbuf - offset);
pauseable = false;
break;
}
case MSG_BECOME_TARGET: {
count = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 4;
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
}
case MSG_DRAW: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 4;
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
......@@ -761,21 +761,21 @@ bool ReplayMode::ReplayAnalyze(unsigned char* msg, unsigned int len) {
break;
}
case MSG_TOSS_COIN: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count;
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
}
case MSG_TOSS_DICE: {
player = BufferIO::ReadInt8(pbuf);
count = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += count;
DuelClient::ClientAnalyze(offset, pbuf - offset);
break;
}
case MSG_ROCK_PAPER_SCISSORS: {
player = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
return ReadReplayResponse();
}
case MSG_HAND_RES: {
......@@ -784,18 +784,18 @@ bool ReplayMode::ReplayAnalyze(unsigned char* msg, unsigned int len) {
break;
}
case MSG_ANNOUNCE_RACE: {
player = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
pbuf += 5;
return ReadReplayResponse();
}
case MSG_ANNOUNCE_ATTRIB: {
player = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
pbuf += 5;
return ReadReplayResponse();
}
case MSG_ANNOUNCE_CARD:
case MSG_ANNOUNCE_NUMBER: {
player = BufferIO::ReadInt8(pbuf);
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += 4 * count;
return ReadReplayResponse();
......@@ -827,12 +827,12 @@ bool ReplayMode::ReplayAnalyze(unsigned char* msg, unsigned int len) {
for(int p = 0; p < 2; ++p) {
pbuf += 4;
for(int seq = 0; seq < 7; ++seq) {
int val = BufferIO::ReadInt8(pbuf);
int val = BufferIO::ReadUInt8(pbuf);
if(val)
pbuf += 2;
}
for(int seq = 0; seq < 8; ++seq) {
int val = BufferIO::ReadInt8(pbuf);
int val = BufferIO::ReadUInt8(pbuf);
if(val)
pbuf++;
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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