Skip to content

Commit

Permalink
Add simple Guid viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Feb 11, 2017
1 parent 4dd95ae commit 892bac3
Show file tree
Hide file tree
Showing 4 changed files with 329 additions and 0 deletions.
28 changes: 28 additions & 0 deletions GuidViewer/GuidViewer.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GuidViewer", "GuidViewer\GuidViewer.vcxproj", "{0FB44F07-2CE6-4492-B6AB-686EF30C85BA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0FB44F07-2CE6-4492-B6AB-686EF30C85BA}.Debug|x64.ActiveCfg = Debug|x64
{0FB44F07-2CE6-4492-B6AB-686EF30C85BA}.Debug|x64.Build.0 = Debug|x64
{0FB44F07-2CE6-4492-B6AB-686EF30C85BA}.Debug|x86.ActiveCfg = Debug|Win32
{0FB44F07-2CE6-4492-B6AB-686EF30C85BA}.Debug|x86.Build.0 = Debug|Win32
{0FB44F07-2CE6-4492-B6AB-686EF30C85BA}.Release|x64.ActiveCfg = Release|x64
{0FB44F07-2CE6-4492-B6AB-686EF30C85BA}.Release|x64.Build.0 = Release|x64
{0FB44F07-2CE6-4492-B6AB-686EF30C85BA}.Release|x86.ActiveCfg = Release|Win32
{0FB44F07-2CE6-4492-B6AB-686EF30C85BA}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
53 changes: 53 additions & 0 deletions GuidViewer/GuidViewer/ObjectGuid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* This file is part of the CMaNGOS Project. See AUTHORS file for Copyright information
*
* 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 "ObjectGuid.h"

#include <sstream>

char const* ObjectGuid::GetTypeName(HighGuid high)
{
switch (high)
{
case HIGHGUID_ITEM: return "Item";
case HIGHGUID_PLAYER: return "Player";
case HIGHGUID_GAMEOBJECT: return "Gameobject";
case HIGHGUID_TRANSPORT: return "Transport";
case HIGHGUID_UNIT: return "Creature";
case HIGHGUID_PET: return "Pet";
case HIGHGUID_DYNAMICOBJECT: return "DynObject";
case HIGHGUID_CORPSE: return "Corpse";
case HIGHGUID_MO_TRANSPORT: return "MoTransport";
case HIGHGUID_GROUP: return "Group";
default:
return "<unknown>";
}
}

std::string ObjectGuid::GetString() const
{
std::ostringstream str;
str << GetTypeName();

str << " (";
if (HasEntry())
str << (IsPet() ? "Petnumber: " : "Entry: ") << GetEntry() << " ";
str << "Guid: " << GetCounter() << ")";
return str.str();
}

229 changes: 229 additions & 0 deletions GuidViewer/GuidViewer/ObjectGuid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
/*
* This file is part of the CMaNGOS Project. See AUTHORS file for Copyright information
*
* 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_OBJECT_GUID_H
#define MANGOS_OBJECT_GUID_H

#include <functional>
#include <vector>
#include <array>
#include <list>
#include <set>

typedef std::int64_t int64;
typedef std::int32_t int32;
typedef std::int16_t int16;
typedef std::int8_t int8;
typedef std::uint64_t uint64;
typedef std::uint32_t uint32;
typedef std::uint16_t uint16;
typedef std::uint8_t uint8;

enum TypeID
{
TYPEID_OBJECT = 0,
TYPEID_ITEM = 1,
TYPEID_CONTAINER = 2,
TYPEID_UNIT = 3,
TYPEID_PLAYER = 4,
TYPEID_GAMEOBJECT = 5,
TYPEID_DYNAMICOBJECT = 6,
TYPEID_CORPSE = 7
};

#define MAX_TYPE_ID 8

enum TypeMask
{
TYPEMASK_OBJECT = 0x0001,
TYPEMASK_ITEM = 0x0002,
TYPEMASK_CONTAINER = 0x0004,
TYPEMASK_UNIT = 0x0008, // players also have it
TYPEMASK_PLAYER = 0x0010,
TYPEMASK_GAMEOBJECT = 0x0020,
TYPEMASK_DYNAMICOBJECT = 0x0040,
TYPEMASK_CORPSE = 0x0080,

// used combinations in Player::GetObjectByTypeMask (TYPEMASK_UNIT case ignore players in call)
TYPEMASK_CREATURE_OR_GAMEOBJECT = TYPEMASK_UNIT | TYPEMASK_GAMEOBJECT,
TYPEMASK_CREATURE_GAMEOBJECT_OR_ITEM = TYPEMASK_UNIT | TYPEMASK_GAMEOBJECT | TYPEMASK_ITEM,
TYPEMASK_CREATURE_GAMEOBJECT_PLAYER_OR_ITEM = TYPEMASK_UNIT | TYPEMASK_GAMEOBJECT | TYPEMASK_ITEM | TYPEMASK_PLAYER,

TYPEMASK_WORLDOBJECT = TYPEMASK_UNIT | TYPEMASK_PLAYER | TYPEMASK_GAMEOBJECT | TYPEMASK_DYNAMICOBJECT | TYPEMASK_CORPSE,
};

enum HighGuid
{
HIGHGUID_ITEM = 0x4000, // blizz 4000
HIGHGUID_CONTAINER = 0x4000, // blizz 4000
HIGHGUID_PLAYER = 0x0000, // blizz 0000
HIGHGUID_GAMEOBJECT = 0xF110, // blizz F110
HIGHGUID_TRANSPORT = 0xF120, // blizz F120 (for GAMEOBJECT_TYPE_TRANSPORT)
HIGHGUID_UNIT = 0xF130, // blizz F130
HIGHGUID_PET = 0xF140, // blizz F140
HIGHGUID_DYNAMICOBJECT = 0xF100, // blizz F100
HIGHGUID_CORPSE = 0xF101, // blizz F100
HIGHGUID_MO_TRANSPORT = 0x1FC0, // blizz 1FC0 (for GAMEOBJECT_TYPE_MO_TRANSPORT)
HIGHGUID_GROUP = 0x1F50, // blizz 1F5x
};

class ObjectGuid;
class PackedGuid;

struct PackedGuidReader
{
explicit PackedGuidReader(ObjectGuid& guid) : m_guidPtr(&guid) {}
ObjectGuid* m_guidPtr;
};

class ObjectGuid
{
public: // constructors
ObjectGuid() : m_guid(0) {}
explicit ObjectGuid(uint64 const& guid) : m_guid(guid) {}
ObjectGuid(HighGuid hi, uint32 entry, uint32 counter) : m_guid(counter ? uint64(counter) | (uint64(entry) << 24) | (uint64(hi) << 48) : 0) {}
ObjectGuid(HighGuid hi, uint32 counter) : m_guid(counter ? uint64(counter) | (uint64(hi) << 48) : 0) {}

operator uint64() const { return m_guid; }
private:
explicit ObjectGuid(uint32 const&); // no implementation, used for catch wrong type assign
ObjectGuid(HighGuid, uint32, uint64 counter); // no implementation, used for catch wrong type assign
ObjectGuid(HighGuid, uint64 counter); // no implementation, used for catch wrong type assign

public: // modifiers
PackedGuidReader ReadAsPacked() { return PackedGuidReader(*this); }

void Set(uint64 const& guid) { m_guid = guid; }
void Clear() { m_guid = 0; }

PackedGuid WriteAsPacked() const;
public: // accessors
uint64 const& GetRawValue() const { return m_guid; }
HighGuid GetHigh() const { return HighGuid((m_guid >> 48) & 0x0000FFFF); }
uint32 GetEntry() const { return HasEntry() ? uint32((m_guid >> 24) & uint64(0x0000000000FFFFFF)) : 0; }
uint32 GetCounter() const
{
return HasEntry()
? uint32(m_guid & uint64(0x0000000000FFFFFF))
: uint32(m_guid & uint64(0x00000000FFFFFFFF));
}

static uint32 GetMaxCounter(HighGuid high)
{
return HasEntry(high)
? uint32(0x00FFFFFF)
: uint32(0xFFFFFFFF);
}

uint32 GetMaxCounter() const { return GetMaxCounter(GetHigh()); }

bool IsEmpty() const { return m_guid == 0; }
bool IsCreature() const { return GetHigh() == HIGHGUID_UNIT; }
bool IsPet() const { return GetHigh() == HIGHGUID_PET; }
bool IsCreatureOrPet() const { return IsCreature() || IsPet(); }
bool IsAnyTypeCreature() const { return IsCreature() || IsPet(); } // wrapper to master branch
bool IsPlayer() const { return !IsEmpty() && GetHigh() == HIGHGUID_PLAYER; }
bool IsUnit() const { return IsAnyTypeCreature() || IsPlayer(); }
bool IsItem() const { return GetHigh() == HIGHGUID_ITEM; }
bool IsGameObject() const { return GetHigh() == HIGHGUID_GAMEOBJECT; }
bool IsDynamicObject() const { return GetHigh() == HIGHGUID_DYNAMICOBJECT; }
bool IsCorpse() const { return GetHigh() == HIGHGUID_CORPSE; }
bool IsTransport() const { return GetHigh() == HIGHGUID_TRANSPORT; }
bool IsMOTransport() const { return GetHigh() == HIGHGUID_MO_TRANSPORT; }
bool IsGroup() const { return GetHigh() == HIGHGUID_GROUP; }

static TypeID GetTypeId(HighGuid high)
{
switch (high)
{
case HIGHGUID_ITEM: return TYPEID_ITEM;
// case HIGHGUID_CONTAINER: return TYPEID_CONTAINER; HIGHGUID_CONTAINER==HIGHGUID_ITEM currently
case HIGHGUID_UNIT: return TYPEID_UNIT;
case HIGHGUID_PET: return TYPEID_UNIT;
case HIGHGUID_PLAYER: return TYPEID_PLAYER;
case HIGHGUID_GAMEOBJECT: return TYPEID_GAMEOBJECT;
case HIGHGUID_DYNAMICOBJECT: return TYPEID_DYNAMICOBJECT;
case HIGHGUID_CORPSE: return TYPEID_CORPSE;
case HIGHGUID_MO_TRANSPORT: return TYPEID_GAMEOBJECT;
// unknown
case HIGHGUID_GROUP:
default: return TYPEID_OBJECT;
}
}

TypeID GetTypeId() const { return GetTypeId(GetHigh()); }

bool operator!() const { return IsEmpty(); }
bool operator== (ObjectGuid const& guid) const { return GetRawValue() == guid.GetRawValue(); }
bool operator!= (ObjectGuid const& guid) const { return GetRawValue() != guid.GetRawValue(); }
bool operator< (ObjectGuid const& guid) const { return GetRawValue() < guid.GetRawValue(); }

public: // accessors - for debug
static char const* GetTypeName(HighGuid high);
char const* GetTypeName() const { return !IsEmpty() ? GetTypeName(GetHigh()) : "None"; }
std::string GetString() const;

private: // internal functions
static bool HasEntry(HighGuid high)
{
switch (high)
{
case HIGHGUID_ITEM:
case HIGHGUID_PLAYER:
case HIGHGUID_DYNAMICOBJECT:
case HIGHGUID_CORPSE:
case HIGHGUID_MO_TRANSPORT:
case HIGHGUID_GROUP:
return false;
case HIGHGUID_GAMEOBJECT:
case HIGHGUID_TRANSPORT:
case HIGHGUID_UNIT:
case HIGHGUID_PET:
default:
return true;
}
}

bool HasEntry() const { return HasEntry(GetHigh()); }

private: // fields
uint64 m_guid;
};

// Some Shared defines
typedef std::set<ObjectGuid> GuidSet;
typedef std::list<ObjectGuid> GuidList;
typedef std::vector<ObjectGuid> GuidVector;

// minimum buffer size for packed guid is 9 bytes
#define PACKED_GUID_MIN_BUFFER_SIZE 9

namespace std {
template<>
class hash<ObjectGuid>
{
public:

size_t operator()(ObjectGuid const& key) const
{
return hash<uint64>()(key.GetRawValue());
}
};
}

#endif
19 changes: 19 additions & 0 deletions GuidViewer/GuidViewer/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include "ObjectGuid.h"

int main()
{
while (1)
{
uint64 guid;
scanf("%llu",&guid);
if (guid == 0)
break;
ObjectGuid guidObj(guid);
printf("%s\n",guidObj.GetString().data());
}
return 0;
}

0 comments on commit 892bac3

Please sign in to comment.