WoW:API UnitGUID: Difference between revisions

Line 7: Line 7:
== What does it all mean? ==
== What does it all mean? ==


The GUID is a unique hexadecimal string for each unit in the game.
The GUID is a unique hexadecimal string for each unit in the game. Just how unique are they? Slouken[http://forums.worldofwarcraft.com/thread.html?topicId=2968233433&postId=44201363100&sid=1#231] has this to say on it:
 
A monster has a single GUID from spawn until death (or despawn). When it respawns it gets a new GUID.
Pets get a new GUID each time they are summoned.
Monster and pet GUIDs can be recycled after server (or instance) restart.
Players keep their GUID forever, and are unique even in cross-server battlegrounds.


The strings always begin with '0x', which is the normal prefix for hexadecimal numbers. The '0x' prefix isn't actually part of the string, it's just to say "this is a hex string."
The strings always begin with '0x', which is the normal prefix for hexadecimal numbers. The '0x' prefix isn't actually part of the string, it's just to say "this is a hex string."
=== Determine if it's a player, pet or NPC ===
* It's a player if the upper bits masked with 0x00f = 0x000
* It's a creature if the upper bits masked with 0x00f = 0x003
* It's a pet if the upper bits masked with 0x00f = 0x004




Line 15: Line 26:
* The GUID is a simple number in the order characters are created. An older character has a lower number than a new.
* The GUID is a simple number in the order characters are created. An older character has a lower number than a new.


It's possible that the first four to six digits are reserved and always has to be '0', which would limit the amount of characters able to be stored, but it's still a very very very high amount of available space. Reserving the first bits and always make them '0' would make it very easy to always identify a character.
The top three digits are reserved. It's unknown if any of the lower digits are also reserved.


Renaming and transfering to another server, or to another account gives your character a new GUID. It's possible that the GUIDs are stored globally, either per datacenter or even per region. It's also possible that there are some reserved bits in there which makes the number higher than it really is.
Renaming and transfering to another server, or to another account gives your character a new GUID. Slouken confirms[http://forums.worldofwarcraft.com/thread.html?topicId=2968233433&postId=44201363100&sid=1#231] that player GUIDs are unique even in crossserver battlegrounds, which strongly indicates that the GUIDs are stored globally, either per region or per datacenter.


Restoring a character from backup is untested wether it restores the old GUID or not.
Slouken, in the link earlier, also states that "Players keep their GUID forever, ..." My empirical studies has shown that this is not true, certain actions like transfering and renaming your character will give you a new GUID. Restoring a character from backup is untested wether it restores the old GUID or not.




=== Format for non-pet NPCs ===
=== Format for non-pet NPCs ===
* The first two digits seems to be 'F1' or 'F3'.
* The first three characters masked with 0x00f will result in 0x003.
* The next digit seems to always be '3'.
* The next three digits are unknown. It's usually '000'.
* The next three digits are unknown. It's usually '000'.
* The next four digits are the NPC id.
* The next four digits are the NPC id.
* The last six digits are the spawn counter.
* The last six digits are the spawn counter.


I couldn't find any logic behind why some NPCs are 'F1' and some are 'F3'. From my testing it seems that 'F1' is more common, but there are some places where I found an 'F1' mob right next to an 'F3' mob. If you take the 'NPC id' and convert it to decimal you can check wowhead and see what NPC it is. See examples below.
If you take the 'NPC id' and convert it to decimal you can check wowhead and see what NPC it is. See examples below.




=== Format for pets ===
=== Format for pets ===
* The first two digits seem to be 'F1'.
* The first three characters masked with 0x00f will result in 0x004.
* The next digit is always '4'.
* The next seven digits are unknown.
* The next seven digits are unknown.
* The last six digits are the spawn counter.
* The last six digits are the spawn counter.


I haven't found any pet that starts with 'F3', like non-pet NPCs. It's possible that the seven digits that at this point are unknown are split into smaller pieces. The unknown seven digits seem to be some sort of counter, as repeatedly taming beasts with the same npc id will result in marginally higher numbers each subsequent tame. You must log out before the pet gets this GUID, if querried during the same session that you tamed it, your pet will have its pre-taming GUID.
It's possible that the seven digits that at this point are unknown are split into smaller pieces. I couldn't find any structure among them, but looking at non-pet NPCs, I can imagine that the NPC id is there somewhere but I couldn't find it. You must log out before the pet gets this GUID, if querried during the same session that you tamed it, your pet will have its pre-taming GUID.


== Spawn counter ==
== Spawn counter ==
Line 49: Line 58:
We have a GUID: "0xF530004D2B008852".
We have a GUID: "0xF530004D2B008852".


From that we know the following: This is a non-pet NPC. It can't be a player because the first two characters are 'F5', players have '00'. The third character is not '3' for NPCs and not '4' for pets.
First of all, let's find out what kind of unit it is. Take the first three digits in the GUID, ie "F53" (or 0xF53 to show it's an hex value) and apply an AND mask of 0x00F.
 
0xF53 & 0x00F = 0x003
 
This GUID is for a normal NPC, not a pet and not a player.ts.


We can extract the Unit ID by taking the sixth to tenth digit and converting it to decimal form: "4D2B", or converted to decimal form "19755". A quick visit to wowhead shows that the NPC with that id is "Mo'arg Weaponsmith", [http://www.wowhead.com/?npc=19755]. All "Mo'arg Weaponsmiths" will have that id to identify them.
We can also extract the Unit ID by taking the sixth to tenth digit and converting it to decimal form: "4D2B", or converted to decimal form "19755". A quick visit to wowhead shows that the NPC with that id is "Mo'arg Weaponsmith", [http://www.wowhead.com/?npc=19755]. All "Mo'arg Weaponsmiths" will have that id to identify them.


The last six digits, "008852" is the spawn counter. There will never be two "Mo'arg Weaponsmith", possible even never two mobs in the outside world, with the same spawn number.
The last six digits, "008852" is the spawn counter. There will never be two "Mo'arg Weaponsmith", possible even never two mobs in the outside world, with the same spawn number. This spawn counter, combined with the rest makes it possible to always refer to exactly this "Mo'arg Weaponsmith", and not the one next to it.


== Speculations ==
== Speculations ==
Anonymous user