root/trunk/src/game/tools.cpp @ 9

Revision 2, 2.4 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18
19#include "Tools.h"
20
21// THIS CAN BE A LOT FASTER
22bool readGUID(WorldPacket & data, uint64& guid)
23{
24    if(data.rpos()+1 > data.size())
25        return false;
26
27    uint8 guidmark=0;
28    uint8 bit;
29    uint8 shiftdata=0x1;
30    uint64 Temp=0;
31
32    guid = 0;
33
34    data >> guidmark;
35    for(int i=0;i<8;i++)
36    {
37        if(guidmark & shiftdata)
38        {
39            Temp = 0;
40
41            if(data.rpos()+1 > data.size())
42                return false;
43
44            data >> bit;
45            Temp = bit;
46            Temp <<= i*8;
47            guid |= Temp;
48        }
49        shiftdata=shiftdata<<1;
50    }
51
52    return true;
53}
54
55void  writeGUID(WorldPacket & data, uint64 & guid)
56{
57    uint8 RAWmask = 0;
58    uint8 PackedGuid[8] = {0,0,0,0,0,0,0,0};
59
60    int j = 1;
61    uint8 * test = (uint8*)&guid;
62
63    if (*test)
64    {
65        PackedGuid[j] = *test;
66        RAWmask |= 1;
67        ++j;
68    }
69    if (*(test+1))
70    {
71        PackedGuid[j] = *(test+1);
72        RAWmask |= 2;
73        ++j;
74    }
75    if (*(test+2))
76    {
77        PackedGuid[j] = *(test+2);
78        RAWmask |= 4;
79        ++j;
80    }
81    if (*(test+3))
82    {
83        PackedGuid[j] = *(test+3);
84        RAWmask |= 8;
85        ++j;
86    }
87    if (*(test+4))
88    {
89        PackedGuid[j] = *(test+4);
90        RAWmask |= 16;
91        ++j;
92    }
93    if (*(test+5))
94    {
95        PackedGuid[j] = *(test+5);
96        RAWmask |= 32;
97        ++j;
98    }
99    if (*(test+6))
100    {
101        PackedGuid[j] = *(test+6);
102        RAWmask |= 64;
103        ++j;
104    }
105    if (*(test+7))
106    {
107        PackedGuid[j] = *(test+7);
108        RAWmask |= 128;
109        ++j;
110    }
111    PackedGuid[0] = RAWmask;
112
113    data.append(PackedGuid,j);
114}
Note: See TracBrowser for help on using the browser.