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); } // add texturegroup_world inside GamerSettings.ini in order to overwrite values ImageSize maxSize = imgList.Max(image => image.imgSize); uint maxValue = Math.Max(maxSize.width, maxSize.height); string section = "SystemSettings"; string key = "texturegroup_shadowmap"; string newValue = "(MinLODSize=128,MaxLODSize=" + maxValue + ",LODBias=0)"; IniFile iniFile = new IniFile(ME3Directory.GamerSettingsIniFile); string oldValue = iniFile.IniReadValue(section, key); if (oldValue == "") { iniFile.IniWriteValue(section, key, newValue); } else { char[] delimiters = new char[] { '=', ',' }; uint maxLODSize = Convert.ToUInt32(oldValue.Split(delimiters)[3]); if (maxValue > maxLODSize) { iniFile.IniWriteValue(section, key, newValue); } } // 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; if (!pccRef.Names.Exists(name => name == newTextureGroupName)) { pccRef.Names.Add(newTextureGroupName); } using (MemoryStream rawStream = new MemoryStream(LODGroup.raw)) { rawStream.Seek(32, SeekOrigin.Begin); rawStream.WriteValueS32(pccRef.Names.FindIndex(name => name == newTextureGroupName)); //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"); * * * } * }*/ }
public void OneImageToRuleThemAll(string archiveDir, ImageFile im, out string newTextureGroup, byte[] imgData) { newTextureGroup = null; ImageMipMapHandler imgMipMap = new ImageMipMapHandler("", imgData); // 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; } // 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, archiveDir); } else // if the image doesn't exists then we have to add it { // ...and use my addBiggerImage function! :P addBiggerImage(newImageFile, archiveDir); } File.Delete(newImageFile.fileName); } // add texturegroup_world inside GamerSettings.ini in order to overwrite values ImageSize maxSize = imgList.Max(image => image.imgSize); uint maxValue = Math.Max(maxSize.width, maxSize.height); string section = "SystemSettings"; string key = "texturegroup_shadowmap"; string newValue = "(MinLODSize=128,MaxLODSize=" + maxValue + ",LODBias=0)"; IniFile iniFile = new IniFile(ME3Directory.GamerSettingsIniFile); string oldValue = iniFile.IniReadValue(section, key); if (oldValue == "") { iniFile.IniWriteValue(section, key, newValue); } else { char[] delimiters = new char[] { '=', ',' }; uint maxLODSize = Convert.ToUInt32(oldValue.Split(delimiters)[3]); if (maxValue > maxLODSize) { iniFile.IniWriteValue(section, key, newValue); } } // 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; if (!pccRef.Names.Exists(name => name == newTextureGroupName)) { pccRef.Names.Add(newTextureGroupName); } using (MemoryStream rawStream = new MemoryStream(LODGroup.raw)) { rawStream.Seek(32, SeekOrigin.Begin); rawStream.WriteValueS32(pccRef.Names.FindIndex(name => name == newTextureGroupName)); //rawStream.Seek(32, SeekOrigin.Begin); rawStream.WriteValueS32(0); properties["LODGroup"].raw = rawStream.ToArray(); } }