Public feed #380345

Mine

public text v1 · immutable
Raw Edit
·published 2007-03-04 00:11 UTC
rendered paste body
public class GUIDGenerator
    {
        private static Dictionary<GUIDType, uint> m_keyHolder;
        public static GUID Create(GUIDType guidType)
        {
            if (!m_keyHolder.ContainsKey(guidType))
            {
                m_keyHolder.Add(guidType, 0);
            }
            return new GUID(++m_keyHolder[guidType],(uint)guidType);
        }
    }

    public enum GUIDType : uint
    {
        Item = 0x40000070,
        Container = 0x40000070,
        Unit = 0xF0001000,
        Player = 0x00000000,
        GameObject = 0xF0004000,
        DynamicObject = 0xF000A000,
        Corpse = 0xF0007000,
        PlayerCorpse = 0x80000001,
        Transport = 0x80000000
    }

    public class GUID
    {
        private ulong m_rawGuid;
        public GUID(ulong rawGuid)
        {
            m_rawGuid = rawGuid;
        }
        public GUID(uint guidLow, uint guidHigh)
        {
            List<byte> guidBytes = new List<byte>();
            guidBytes.AddRange(BitConverter.GetBytes(guidLow));
            guidBytes.AddRange(BitConverter.GetBytes(guidHigh));
            m_rawGuid = BitConverter.ToUInt64(guidBytes.ToArray(), 0);
        }

        public byte[] GetPacked()
        {
            byte[] guidBytes = BitConverter.GetBytes(m_rawGuid);
            List<byte> packedGUID = new List<byte>();
            packedGUID.Add(0);
            for (int i = 0; i < 8; i++)
            {
                if (guidBytes[i] != 0)
                {
                    packedGUID[0] |= (byte)(1 << i);
                    packedGUID.Add(guidBytes[i]);
                }
            }
            return packedGUID.ToArray();
        }

        public static GUID GetNew()
        {
            return new GUID(0);// do GUIDGenerator magic
        }
    }