Example #1
0
 public D3AttributeValue ReadAttribute(uint ptr, D3Attribute attrib)
 {
     if (attrib.IsInteger)
     {
         return(new D3AttributeValue(ReadInt(ptr + 8)));
     }
     else
     {
         return(new D3AttributeValue(ReadFloat(ptr + 8)));
     }
 }
Example #2
0
        public D3AttributeValue?GetAttribute(uint attributesPtr, D3Attribute attrib)
        {
            uint ptr;
            uint attribID = Offsets.ATTRIBUTE_MASK | (uint)attrib.ID;
            uint v0       = ReadUInt(attributesPtr + 16);

            ptr = ReadUInt(ReadUInt(v0 + 8) + 4 * (ReadUInt(v0 + Offsets.ATTRIB_SLOTCOUNT_OFFSET) & (attribID ^ (attribID >> 16))));
            if (ptr != 0)
            {
                while (ReadUInt(ptr + 4) != attribID)
                {
                    ptr = ReadUInt(ptr);
                    if (ptr == 0)
                    {
                        return(null);
                    }
                }

                return(ReadAttribute(ptr, attrib));
            }

            return(null);
        }
Example #3
0
        /// <summary>
        /// Fetch all attributes associated with a given actor
        /// </summary>
        /// <param name="attributesPtr">Pointer to an attributes container</param>
        public D3AttributeMap GetAttributes(uint attributesPtr)
        {
            uint           v0         = ReadUInt(attributesPtr + 16);
            uint           p0         = ReadUInt(v0 + 8);
            int            capacity   = ReadInt(v0 + Offsets.ATTRIB_SLOTCOUNT_OFFSET);
            int            count      = ReadInt(v0 + Offsets.ATTRIB_COUNT_OFFSET);
            D3AttributeMap attributes = new D3AttributeMap(count);
            uint           basePtr;
            uint           ptr;

            byte[] attribData;
            uint   attribID;

            #region TeamID-only Optimization

            if (count == 1)
            {
                ptr = ReadUInt(p0 + 0x29C);
                if (ptr != 0)
                {
                    attribData = ReadBytes(ptr + 4, 8);
                    attribID   = BitConverter.ToUInt32(attribData, 0);

                    if ((attribID & 0xFFF) == D3Attribute.TeamID.ID)
                    {
                        attributes[D3Attribute.TeamID] = new D3AttributeValue(BitConverter.ToInt32(attribData, 4));
                        return(attributes);
                    }
                }
            }

            #endregion TeamID-only Optimization

            byte[] data     = ReadBytes(p0, 4 * capacity);
            int    curCount = 0;

            unsafe
            {
                fixed(byte *bytePtr = data)
                {
                    uint *ptrs = (uint *)bytePtr;

                    for (int i = 0; i < capacity; i++)
                    {
                        basePtr = *(ptrs + i);
                        if (basePtr != 0)
                        {
                            ptr = basePtr;
                            while (ptr != 0)
                            {
                                attribData = ReadBytes(ptr, 12);
                                ptr        = BitConverter.ToUInt32(attribData, 0);
                                attribID   = BitConverter.ToUInt32(attribData, 4);

                                if (attribID != Offsets.INVALID)
                                {
                                    D3Attribute attrib = D3Attribute.AttributesMap[attribID & 0xFFF];
                                    attributes[attribID] = (attrib.IsInteger)
                                        ? new D3AttributeValue(BitConverter.ToInt32(attribData, 8))
                                        : new D3AttributeValue(BitConverter.ToSingle(attribData, 8));

                                    if (++curCount == count)
                                    {
                                        return(attributes);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(attributes);
        }
Example #4
0
 private uint GetID(D3Attribute attribute)
 {
     return((uint)attribute.ID | Offsets.ATTRIBUTE_MASK);
 }
Example #5
0
 private uint GetID(D3Attribute attribute, int key)
 {
     return(((uint)attribute.ID & 0xFFF) | ((uint)key << 12));
 }
Example #6
0
 public D3AttributeValue this[D3Attribute attribute, int key]
 {
     get { return(attributes[GetID(attribute, key)]); }
     set { attributes[GetID(attribute, key)] = value; }
 }
Example #7
0
 public D3AttributeValue this[D3Attribute attribute]
 {
     get { return(attributes[GetID(attribute)]); }
     set { attributes[GetID(attribute)] = value; }
 }
Example #8
0
 public void SetValue(D3Attribute attribute, int key, D3AttributeValue value)
 {
     attributes[GetID(attribute, key)] = value;
 }
Example #9
0
 public void SetValue(D3Attribute attribute, D3AttributeValue value)
 {
     attributes[GetID(attribute)] = value;
 }
Example #10
0
 public bool TryGetValue(D3Attribute attribute, int key, out D3AttributeValue value)
 {
     return(attributes.TryGetValue(GetID(attribute, key), out value));
 }