/// <summary>
 /// Populates IconData dictionares.
 /// </summary>
 public static void PopulateIconDictionaries()
 {
     IconData.ReadModdedItemIcons();
     IconData.ReadDefaultItemIcons();
     IconData.ReadUIIcons();
 }
        /// <summary>
        /// Reads and stores uiIcons.
        /// </summary>
        private static void ReadUIIcons()
        {
            string path = Config.GetSetting("gameRoot") + "\\7DaysToDie_Data\\resources.assets";

            BinaryReader reader          = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read));
            AssetInfo    uiIconReference = AssetInfo.GetAssetInfoByNameAndType("UIAtlas", 28);

            reader.BaseStream.Position = uiIconReference.offsetToFileStart;

            int width  = reader.ReadInt32();
            int height = reader.ReadInt32();

            // Skip the atlas header.
            reader.BaseStream.Position += 52;

            // Texture is empty, gets the link to the real atlas in .resS file.
            int offsetInResSFile = reader.ReadInt32();

            // Gets the texture atlas as a byte array of pixels.
            path = Config.GetSetting("gameRoot") + "\\7DaysToDie_Data\\resources.assets.resS";

            reader = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read));
            reader.BaseStream.Position = offsetInResSFile;

            byte[] textureStream = IconData.GetTextureAtlas(reader, width, height);

            // Go back to .assets file and get the coordinates of individual uiIcons to load.
            path   = Config.GetSetting("gameRoot") + "\\7DaysToDie_Data\\resources.assets";
            reader = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read));


            //need a better way to do this. Thanks to DorHans for the new offset.
            //ulong skillidx = 43116;
            ulong skillidx = 59162;

            AssetInfo uiIconText = AssetInfo.GetAssetInfoByIndex(skillidx);

            reader.BaseStream.Position = uiIconText.offsetToFileStart + 40;

            BinaryReader textureReader = new BinaryReader(new MemoryStream(textureStream));

            int itemNumber = reader.ReadInt32();

            for (int i = 0; i < itemNumber; i++)
            {
                int    nameLength = reader.ReadInt32();
                string name       = Util.ReadAssetString(reader, nameLength);

                // Align to 4-bytes.
                while (reader.BaseStream.Position % 4 != 0)
                {
                    reader.BaseStream.Position++;
                }

                int XCoord = reader.ReadInt32();
                int YCoord = reader.ReadInt32();

                int imageWidth  = reader.ReadInt32();
                int imageHeight = reader.ReadInt32();

                byte[] imageData = ExtractImageFromTextureAtlas(textureReader, width, YCoord, XCoord, imageWidth, imageHeight);

                UIIconData iconData = new UIIconData(imageData, imageWidth, imageHeight);

                uiIconDictionary.Add(name, iconData);

                reader.BaseStream.Position += 32;
            }
        }