From 9c5dab1248936f18b1fe8d5424f964f08101d04f Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Sat, 27 Dec 2008 17:23:00 +0300 Subject: [PATCH] [6953] Cleanup packed guids write/read code. * Remove unused function writeGUID and move function readGUID (with some changes) to ByteBuffer class. * Remove now empty Tools.cpp/Tools.h from project. --- src/game/Makefile.am | 2 - src/game/MiscHandler.cpp | 3 +- src/game/Spell.cpp | 9 ++-- src/game/Tools.h | 26 --------- src/game/tools.cpp | 114 --------------------------------------- src/shared/ByteBuffer.h | 26 +++++++++ src/shared/revision_nr.h | 2 +- win/VC71/game.vcproj | 6 --- win/VC80/game.vcproj | 8 --- win/VC90/game.vcproj | 8 --- 10 files changed, 32 insertions(+), 172 deletions(-) delete mode 100644 src/game/Tools.h delete mode 100644 src/game/tools.cpp diff --git a/src/game/Makefile.am b/src/game/Makefile.am index 5f5ce4542..44c7898a0 100644 --- a/src/game/Makefile.am +++ b/src/game/Makefile.am @@ -232,8 +232,6 @@ libmangosgame_a_SOURCES = \ TaxiHandler.cpp \ TemporarySummon.cpp \ TemporarySummon.h \ - tools.cpp \ - Tools.h \ TotemAI.cpp \ TotemAI.h \ Totem.cpp \ diff --git a/src/game/MiscHandler.cpp b/src/game/MiscHandler.cpp index 885af56fc..3eed7737f 100644 --- a/src/game/MiscHandler.cpp +++ b/src/game/MiscHandler.cpp @@ -41,7 +41,6 @@ #include "SpellAuras.h" #include "Pet.h" #include "SocialMgr.h" -#include "Tools.h" void WorldSession::HandleRepopRequestOpcode( WorldPacket & /*recv_data*/ ) { @@ -1649,7 +1648,7 @@ void WorldSession::HandleInspectAchievements( WorldPacket & recv_data ) { CHECK_PACKET_SIZE(recv_data, 1); uint64 guid; - if(!readGUID(recv_data, guid)) + if(!recv_data.readPackGUID(guid)) return; Player *player = objmgr.GetPlayer(guid); diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index d7d5cba64..ec00ddb3b 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -41,7 +41,6 @@ #include "CellImpl.h" #include "Policies/SingletonImp.h" #include "SharedDefines.h" -#include "Tools.h" #include "LootMgr.h" #include "VMapFactory.h" #include "BattleGround.h" @@ -167,15 +166,15 @@ bool SpellCastTargets::read ( WorldPacket * data, Unit *caster ) // TARGET_FLAG_UNK2 is used for non-combat pets, maybe other? if( m_targetMask & ( TARGET_FLAG_UNIT | TARGET_FLAG_UNK2 )) - if(!readGUID(*data, m_unitTargetGUID)) + if(!data->readPackGUID(m_unitTargetGUID)) return false; if( m_targetMask & ( TARGET_FLAG_OBJECT | TARGET_FLAG_OBJECT_UNK )) - if(!readGUID(*data, m_GOTargetGUID)) + if(!data->readPackGUID(m_GOTargetGUID)) return false; if(( m_targetMask & ( TARGET_FLAG_ITEM | TARGET_FLAG_TRADE_ITEM )) && caster->GetTypeId() == TYPEID_PLAYER) - if(!readGUID(*data, m_itemTargetGUID)) + if(!data->readPackGUID(m_itemTargetGUID)) return false; if( m_targetMask & TARGET_FLAG_SOURCE_LOCATION ) @@ -207,7 +206,7 @@ bool SpellCastTargets::read ( WorldPacket * data, Unit *caster ) } if( m_targetMask & (TARGET_FLAG_CORPSE | TARGET_FLAG_PVP_CORPSE ) ) - if(!readGUID(*data, m_CorpseTargetGUID)) + if(!data->readPackGUID(m_CorpseTargetGUID)) return false; // find real units/GOs diff --git a/src/game/Tools.h b/src/game/Tools.h deleted file mode 100644 index e8ad44a22..000000000 --- a/src/game/Tools.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2005-2008 MaNGOS - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef MANGOS_TOOLS_H -#define MANGOS_TOOLS_H - -#include "Common.h" -#include "WorldPacket.h" - -bool readGUID(WorldPacket & data, uint64& guid); -void writeGUID(WorldPacket & data, uint64 & guid); -#endif diff --git a/src/game/tools.cpp b/src/game/tools.cpp deleted file mode 100644 index f5ebde52d..000000000 --- a/src/game/tools.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2005-2008 MaNGOS - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "Tools.h" - -// THIS CAN BE A LOT FASTER -bool readGUID(WorldPacket & data, uint64& guid) -{ - if(data.rpos()+1 > data.size()) - return false; - - uint8 guidmark=0; - uint8 bit; - uint8 shiftdata=0x1; - uint64 Temp=0; - - guid = 0; - - data >> guidmark; - for(int i=0;i<8;i++) - { - if(guidmark & shiftdata) - { - Temp = 0; - - if(data.rpos()+1 > data.size()) - return false; - - data >> bit; - Temp = bit; - Temp <<= i*8; - guid |= Temp; - } - shiftdata=shiftdata<<1; - } - - return true; -} - -void writeGUID(WorldPacket & data, uint64 & guid) -{ - uint8 RAWmask = 0; - uint8 PackedGuid[8] = {0,0,0,0,0,0,0,0}; - - int j = 1; - uint8 * test = (uint8*)&guid; - - if (*test) - { - PackedGuid[j] = *test; - RAWmask |= 1; - ++j; - } - if (*(test+1)) - { - PackedGuid[j] = *(test+1); - RAWmask |= 2; - ++j; - } - if (*(test+2)) - { - PackedGuid[j] = *(test+2); - RAWmask |= 4; - ++j; - } - if (*(test+3)) - { - PackedGuid[j] = *(test+3); - RAWmask |= 8; - ++j; - } - if (*(test+4)) - { - PackedGuid[j] = *(test+4); - RAWmask |= 16; - ++j; - } - if (*(test+5)) - { - PackedGuid[j] = *(test+5); - RAWmask |= 32; - ++j; - } - if (*(test+6)) - { - PackedGuid[j] = *(test+6); - RAWmask |= 64; - ++j; - } - if (*(test+7)) - { - PackedGuid[j] = *(test+7); - RAWmask |= 128; - ++j; - } - PackedGuid[0] = RAWmask; - - data.append(PackedGuid,j); -} diff --git a/src/shared/ByteBuffer.h b/src/shared/ByteBuffer.h index eff26bfa8..cca7216c8 100644 --- a/src/shared/ByteBuffer.h +++ b/src/shared/ByteBuffer.h @@ -241,6 +241,32 @@ class ByteBuffer _rpos += len; } + bool readPackGUID(uint64& guid) + { + if(rpos()+1 > size()) + return false; + + guid = 0; + + uint8 guidmark=0; + (*this) >> guidmark; + + for(int i=0;i<8;i++) + { + if(guidmark & (uint8(1) << i)) + { + if(rpos()+1 > size()) + return false; + + uint8 bit; + (*this) >> bit; + guid |= (uint64(bit) << (i*8)); + } + } + + return true; + } + const uint8 *contents() const { return &_storage[0]; } size_t size() const { return _storage.size(); } diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 8ef011ff2..014cf29cb 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "6952" + #define REVISION_NR "6953" #endif // __REVISION_NR_H__ diff --git a/win/VC71/game.vcproj b/win/VC71/game.vcproj index ba5370d3d..b6827360d 100644 --- a/win/VC71/game.vcproj +++ b/win/VC71/game.vcproj @@ -842,12 +842,6 @@ - - - - - - - - - - - -