ME3Explorer.Unreal.Classes.Texture2D.OneImageToRuleThemAll C# (CSharp) Method

OneImageToRuleThemAll() public method

public OneImageToRuleThemAll ( string imageFileName, string archiveDir, string &newTextureGroup ) : void
imageFileName string
archiveDir string
newTextureGroup string
return void
        public void OneImageToRuleThemAll(string imageFileName, string archiveDir, out string newTextureGroup)
        {
            newTextureGroup = null;
            ImageMipMapHandler imgMipMap = new ImageMipMapHandler(imageFileName, null);

            // starts from the smaller image
            for (int i = imgMipMap.imageList.Count - 1; i >= 0; i--)
            {
                ImageFile newImageFile = imgMipMap.imageList[i];

                // insert images only with size > 64
                if (newImageFile.imgSize.width < 64 && newImageFile.imgSize.height < 64)
                    continue;

                // write the new image into a file (I know that's crappy solution, I'll find another one later...)
                using (FileStream newImageStream = File.Create(newImageFile.fileName))
                {
                    byte[] buffer = newImageFile.ToArray();
                    newImageStream.Write(buffer, 0, buffer.Length);
                }

                // if the image size exists inside the texture2d image list then we have to replace it
                if (imgList.Exists(img => img.imgSize == newImageFile.imgSize))
                {
                    // ...but at least for now I can reuse my replaceImage function... ;)
                    replaceImage(newImageFile.imgSize.ToString(), newImageFile.fileName, archiveDir);
                }
                else // if the image doesn't exists then we have to add it
                {
                    // ...and use my addBiggerImage function! :P
                    addBiggerImage(newImageFile.fileName, archiveDir);
                }

                File.Delete(newImageFile.fileName);
            }
            
            
            // check that Texture2D has a TextureGroup
            if (!properties.ContainsKey("LODGroup"))
                return;

            // extracting values from LODGroup Property
            PropertyReader.Property LODGroup = properties["LODGroup"];
            string textureGroupName = pccRef.Names[LODGroup.Value.IntValue];

            string newTextureGroupName = "TEXTUREGROUP_Shadowmap";
            textureGroupName = newTextureGroupName;
            int nameIndex = pccRef.FindNameOrAdd(newTextureGroupName);
            using (MemoryStream rawStream = new MemoryStream(LODGroup.raw))
            {
                rawStream.Seek(32, SeekOrigin.Begin);
                rawStream.WriteValueS32(nameIndex);
                //rawStream.Seek(32, SeekOrigin.Begin);
                rawStream.WriteValueS32(0);
                properties["LODGroup"].raw = rawStream.ToArray();
            }
            //LODGroup.Value.IntValue = pccRef.Names.FindIndex(name => name == newTextureGroupName);

            /*MessageBox.Show("Texturegroup Name: " + textureGroupName);
            ImageSize maxImageSize = imgList.Max(image => image.imgSize);
            int textureGroupValue = (int)Math.Max(maxImageSize.width, maxImageSize.height) + 1;

            // open Engine.pcc file and edit TextureGroup enumerator
            {
                PCCObject pccEngine = new PCCObject(ME3Directory.cookedPath + "Engine.pcc");
                int idxTexGroups = pccEngine.Exports.FindIndex(export => export.ObjectName == "TextureGroup");

                TextureGroup texGroup = new TextureGroup(pccEngine, pccEngine.Exports[idxTexGroups].Data);
                if (texGroup.ExistsTextureGroup(textureGroupName, textureGroupValue))
                    return;
                else
                {
                    if (!pccEngine.Names.Exists(name => name == newTextureGroupName))
                        pccEngine.Names.Add(newTextureGroupName);

                    newTextureGroup = textureGroupName + "_" + (textureGroupValue - 1);

                    texGroup.Add(textureGroupName, textureGroupValue);
                    MessageBox.Show("Now editing texgroup enum");
                    pccEngine.Exports[idxTexGroups].Data = texGroup.ToArray();
                    MessageBox.Show("Now saving engine.pcc");
                    pccEngine.saveToFile(true, ME3Directory.cookedPath + "Engine.pcc");
                    MessageBox.Show("Saved engine.pcc");


                }
            }*/
        }