Exemplo n.º 1
0
        private void ImportTextures(string sourceDir, string targetDir, Rectangle sectorRect, Rectangle sectionRect, XmlElement xmlTextureEntries)
        {
            List <string> list = new List <string>();
            List <WorldImport.TextureSectorInfo> list2 = new List <WorldImport.TextureSectorInfo>();

            for (int i = sectionRect.Top; i <= sectionRect.Bottom; i++)
            {
                for (int j = sectionRect.Left; j <= sectionRect.Right; j++)
                {
                    string str  = j.ToString("D4") + "_" + i.ToString("D4");
                    string text = sourceDir + "section" + str + ".xml";
                    if (File.Exists(text))
                    {
                        XmlDocument xmlDocument = new XmlDocument();
                        xmlDocument.Load(text);
                        List <string> list3         = new List <string>();
                        XmlElement    elementByName = XmlHelper.GetElementByName(xmlDocument.DocumentElement, "List");
                        foreach (XmlElement current in XmlHelper.GetElementsByName(elementByName, "Entry"))
                        {
                            list3.Add(current.GetAttribute("Id"));
                        }
                        XmlElement elementByName2 = XmlHelper.GetElementByName(xmlDocument.DocumentElement, "Sectors");
                        foreach (XmlElement current2 in XmlHelper.GetElementsByName(elementByName2, "Sector"))
                        {
                            int num  = int.Parse(current2.GetAttribute("X"));
                            int num2 = int.Parse(current2.GetAttribute("Y"));
                            if (num >= sectorRect.X && num < sectorRect.Right && num2 >= sectorRect.Y && num2 < sectorRect.Bottom)
                            {
                                WorldImport.TextureSectorInfo textureSectorInfo = new WorldImport.TextureSectorInfo();
                                textureSectorInfo.sectorX      = num;
                                textureSectorInfo.sectorY      = num2;
                                textureSectorInfo.xmlSector    = current2;
                                textureSectorInfo.layerFile    = sourceDir + "section" + str + ".png";
                                textureSectorInfo.layerIds     = new List <string>();
                                textureSectorInfo.layerIndexes = new List <int>();
                                foreach (XmlElement current3 in XmlHelper.GetElementsByName(current2, "Entry"))
                                {
                                    string attribute = current3.GetAttribute("Id");
                                    if (!list.Contains(attribute))
                                    {
                                        list.Add(attribute);
                                    }
                                    textureSectorInfo.layerIds.Add(attribute);
                                    textureSectorInfo.layerIndexes.Add(list3.IndexOf(attribute));
                                }
                                list2.Add(textureSectorInfo);
                            }
                        }
                    }
                }
            }
            if (list.Count > 4)
            {
                list.RemoveRange(4, list.Count - 4);
            }
            int[] array = new int[]
            {
                2,
                1,
                0,
                3
            };
            byte[] array2 = new byte[1048576];
            foreach (WorldImport.TextureSectorInfo current4 in list2)
            {
                int        sectorX    = current4.sectorX;
                int        sectorY    = current4.sectorY;
                Image      image      = Image.FromFile(current4.layerFile);
                Bitmap     bitmap     = new Bitmap(image);
                BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                int        num3       = sectorX % 4;
                int        num4       = sectorY % 4;
                int        num5       = num3 * 64;
                int        num6       = num4 * 64;
                int        num7       = (sectorX - sectorRect.Left) * 64;
                int        num8       = (sectorY - sectorRect.Top) * 64;
                for (int k = 0; k < current4.layerIds.Count; k++)
                {
                    string item  = current4.layerIds[k];
                    int    num9  = current4.layerIndexes[k];
                    int    num10 = list.IndexOf(item);
                    if (num10 != -1)
                    {
                        num10 = array[num10];
                        for (int l = 0; l < 64; l++)
                        {
                            byte[] array3 = new byte[256];
                            Marshal.Copy((IntPtr)(bitmapData.Scan0.ToInt32() + (num6 + num9 * bitmap.Width + l) * bitmapData.Stride + num5 * 4), array3, 0, 256);
                            for (int m = 0; m < 64; m++)
                            {
                                array2[((num8 + l) * 512 + num7 + m) * 4 + num10] = array3[m * 4];
                            }
                        }
                    }
                }
                for (int n = 0; n < 64; n++)
                {
                    byte[] destination = new byte[256];
                    Marshal.Copy((IntPtr)(bitmapData.Scan0.ToInt32() + (num6 + n) * bitmapData.Stride + num5 * 4), destination, 0, 256);
                    for (int num11 = 0; num11 < 64; num11++)
                    {
                        int num12 = ((num8 + n) * 512 + num7 + num11) * 4;
                        int num13 = 255;
                        for (int num14 = current4.layerIds.Count - 1; num14 >= 0; num14--)
                        {
                            string item2 = current4.layerIds[num14];
                            int    num15 = list.IndexOf(item2);
                            if (num15 != -1)
                            {
                                num15 = array[num15];
                                byte b = array2[num12 + num15];
                                if (num13 >= (int)b)
                                {
                                    num13 -= (int)b;
                                }
                                else
                                {
                                    b = (byte)Math.Min((int)b, num13);
                                    array2[num12 + num15] = b;
                                    num13 -= (int)b;
                                }
                            }
                        }
                        if (num13 != 0)
                        {
                            int num16 = list.IndexOf(current4.layerIds[0]);
                            if (num16 != -1)
                            {
                                num16 = array[num16];
                                byte[] expr_554_cp_0 = array2;
                                int    expr_554_cp_1 = num12 + num16;
                                expr_554_cp_0[expr_554_cp_1] += (byte)num13;
                            }
                        }
                    }
                }
                bitmap.UnlockBits(bitmapData);
                bitmap.Dispose();
                image.Dispose();
            }
            File.WriteAllBytes(targetDir + "texture.mask", array2);
            for (int num17 = 0; num17 < list.Count; num17++)
            {
                XmlElement xmlElement = xmlTextureEntries.OwnerDocument.CreateElement("Entry");
                xmlElement.SetAttribute("Id", list[num17]);
                xmlTextureEntries.AppendChild(xmlElement);
            }
        }
Exemplo n.º 2
0
 private void ImportTextures(string sourceDir, string targetDir, Rectangle sectorRect, Rectangle sectionRect, XmlElement xmlTextureEntries)
 {
     List<string> list = new List<string>();
     List<WorldImport.TextureSectorInfo> list2 = new List<WorldImport.TextureSectorInfo>();
     for (int i = sectionRect.Top; i <= sectionRect.Bottom; i++)
     {
         for (int j = sectionRect.Left; j <= sectionRect.Right; j++)
         {
             string str = j.ToString("D4") + "_" + i.ToString("D4");
             string text = sourceDir + "section" + str + ".xml";
             if (File.Exists(text))
             {
                 XmlDocument xmlDocument = new XmlDocument();
                 xmlDocument.Load(text);
                 List<string> list3 = new List<string>();
                 XmlElement elementByName = XmlHelper.GetElementByName(xmlDocument.DocumentElement, "List");
                 foreach (XmlElement current in XmlHelper.GetElementsByName(elementByName, "Entry"))
                 {
                     list3.Add(current.GetAttribute("Id"));
                 }
                 XmlElement elementByName2 = XmlHelper.GetElementByName(xmlDocument.DocumentElement, "Sectors");
                 foreach (XmlElement current2 in XmlHelper.GetElementsByName(elementByName2, "Sector"))
                 {
                     int num = int.Parse(current2.GetAttribute("X"));
                     int num2 = int.Parse(current2.GetAttribute("Y"));
                     if (num >= sectorRect.X && num < sectorRect.Right && num2 >= sectorRect.Y && num2 < sectorRect.Bottom)
                     {
                         WorldImport.TextureSectorInfo textureSectorInfo = new WorldImport.TextureSectorInfo();
                         textureSectorInfo.sectorX = num;
                         textureSectorInfo.sectorY = num2;
                         textureSectorInfo.xmlSector = current2;
                         textureSectorInfo.layerFile = sourceDir + "section" + str + ".png";
                         textureSectorInfo.layerIds = new List<string>();
                         textureSectorInfo.layerIndexes = new List<int>();
                         foreach (XmlElement current3 in XmlHelper.GetElementsByName(current2, "Entry"))
                         {
                             string attribute = current3.GetAttribute("Id");
                             if (!list.Contains(attribute))
                             {
                                 list.Add(attribute);
                             }
                             textureSectorInfo.layerIds.Add(attribute);
                             textureSectorInfo.layerIndexes.Add(list3.IndexOf(attribute));
                         }
                         list2.Add(textureSectorInfo);
                     }
                 }
             }
         }
     }
     if (list.Count > 4)
     {
         list.RemoveRange(4, list.Count - 4);
     }
     int[] array = new int[]
     {
         2,
         1,
         0,
         3
     };
     byte[] array2 = new byte[1048576];
     foreach (WorldImport.TextureSectorInfo current4 in list2)
     {
         int sectorX = current4.sectorX;
         int sectorY = current4.sectorY;
         Image image = Image.FromFile(current4.layerFile);
         Bitmap bitmap = new Bitmap(image);
         BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
         int num3 = sectorX % 4;
         int num4 = sectorY % 4;
         int num5 = num3 * 64;
         int num6 = num4 * 64;
         int num7 = (sectorX - sectorRect.Left) * 64;
         int num8 = (sectorY - sectorRect.Top) * 64;
         for (int k = 0; k < current4.layerIds.Count; k++)
         {
             string item = current4.layerIds[k];
             int num9 = current4.layerIndexes[k];
             int num10 = list.IndexOf(item);
             if (num10 != -1)
             {
                 num10 = array[num10];
                 for (int l = 0; l < 64; l++)
                 {
                     byte[] array3 = new byte[256];
                     Marshal.Copy((IntPtr)(bitmapData.Scan0.ToInt32() + (num6 + num9 * bitmap.Width + l) * bitmapData.Stride + num5 * 4), array3, 0, 256);
                     for (int m = 0; m < 64; m++)
                     {
                         array2[((num8 + l) * 512 + num7 + m) * 4 + num10] = array3[m * 4];
                     }
                 }
             }
         }
         for (int n = 0; n < 64; n++)
         {
             byte[] destination = new byte[256];
             Marshal.Copy((IntPtr)(bitmapData.Scan0.ToInt32() + (num6 + n) * bitmapData.Stride + num5 * 4), destination, 0, 256);
             for (int num11 = 0; num11 < 64; num11++)
             {
                 int num12 = ((num8 + n) * 512 + num7 + num11) * 4;
                 int num13 = 255;
                 for (int num14 = current4.layerIds.Count - 1; num14 >= 0; num14--)
                 {
                     string item2 = current4.layerIds[num14];
                     int num15 = list.IndexOf(item2);
                     if (num15 != -1)
                     {
                         num15 = array[num15];
                         byte b = array2[num12 + num15];
                         if (num13 >= (int)b)
                         {
                             num13 -= (int)b;
                         }
                         else
                         {
                             b = (byte)Math.Min((int)b, num13);
                             array2[num12 + num15] = b;
                             num13 -= (int)b;
                         }
                     }
                 }
                 if (num13 != 0)
                 {
                     int num16 = list.IndexOf(current4.layerIds[0]);
                     if (num16 != -1)
                     {
                         num16 = array[num16];
                         byte[] expr_554_cp_0 = array2;
                         int expr_554_cp_1 = num12 + num16;
                         expr_554_cp_0[expr_554_cp_1] += (byte)num13;
                     }
                 }
             }
         }
         bitmap.UnlockBits(bitmapData);
         bitmap.Dispose();
         image.Dispose();
     }
     File.WriteAllBytes(targetDir + "texture.mask", array2);
     for (int num17 = 0; num17 < list.Count; num17++)
     {
         XmlElement xmlElement = xmlTextureEntries.OwnerDocument.CreateElement("Entry");
         xmlElement.SetAttribute("Id", list[num17]);
         xmlTextureEntries.AppendChild(xmlElement);
     }
 }