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