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

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

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

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