private void replaceTexture() { if (listViewTextures.SelectedItems.Count == 0) { return; } using (OpenFileDialog selectDDS = new OpenFileDialog()) { selectDDS.Title = "Please select DDS file"; selectDDS.Filter = "DDS file|*.dds"; if (selectDDS.ShowDialog() != DialogResult.OK) { return; } DDSImage image = new DDSImage(selectDDS.FileName); if (!image.checkExistAllMipmaps()) { MessageBox.Show("This texture has not all the required mipmaps, canceling..."); return; } bool loadMod = loadMODsToolStripMenuItem.Enabled; bool clearMod = clearMODsToolStripMenuItem.Enabled; bool packMod = packMODToolStripMenuItem.Enabled; EnableMenuOptions(false); PackageTreeNode node = (PackageTreeNode)treeViewPackages.SelectedNode; ListViewItem item = listViewTextures.FocusedItem; int index = Convert.ToInt32(item.Name); MipMaps mipMaps = new MipMaps(); richTextBoxInfo.Text = mipMaps.replaceTexture(image, node.textures[index].list, cachePackageMgr, node.textures[index].name, node.textures[index].crc); if (richTextBoxInfo.Text != "") { richTextBoxInfo.Show(); pictureBoxPreview.Hide(); MessageBox.Show("WARNING: Some errors have occured!"); } cachePackageMgr.CloseAllWithSave(); EnableMenuOptions(true); loadMODsToolStripMenuItem.Enabled = loadMod; clearMODsToolStripMenuItem.Enabled = clearMod; packMODToolStripMenuItem.Enabled = packMod; listViewTextures.Focus(); item.Selected = false; item.Selected = true; item.Focused = true; } }
public void applyModules() { for (int i = 0; i < memFiles.Count; i++) { log += "Mod: " + (i + 1) + " of " + memFiles.Count + " started: " + Path.GetFileName(memFiles[i]) + Environment.NewLine; using (FileStream fs = new FileStream(memFiles[i], FileMode.Open, FileAccess.Read)) { uint tag = fs.ReadUInt32(); uint version = fs.ReadUInt32(); if (tag != TexExplorer.TextureModTag || version != TexExplorer.TextureModVersion) { if (version != TexExplorer.TextureModVersion) { errors += "File " + memFiles[i] + " was made with an older version of MEM, skipping..." + Environment.NewLine; log += "File " + memFiles[i] + " was made with an older version of MEM, skipping..." + Environment.NewLine; } else { errors += "File " + memFiles[i] + " is not a valid MEM mod, skipping..." + Environment.NewLine; log += "File " + memFiles[i] + " is not a valid MEM mod, skipping..." + Environment.NewLine; } continue; } else { uint gameType = 0; fs.JumpTo(fs.ReadInt64()); gameType = fs.ReadUInt32(); if ((MeType)gameType != GameData.gameType) { errors += "File " + memFiles[i] + " is not a MEM mod valid for this game, skipping..." + Environment.NewLine; log += "File " + memFiles[i] + " is not a MEM mod valid for this game, skipping..." + Environment.NewLine; continue; } } int numFiles = fs.ReadInt32(); List <MipMaps.FileMod> modFiles = new List <MipMaps.FileMod>(); for (int k = 0; k < numFiles; k++) { MipMaps.FileMod fileMod = new MipMaps.FileMod(); fileMod.tag = fs.ReadUInt32(); fileMod.name = fs.ReadStringASCIINull(); fileMod.offset = fs.ReadInt64(); fileMod.size = fs.ReadInt64(); modFiles.Add(fileMod); } numFiles = modFiles.Count; for (int l = 0; l < numFiles; l++) { string name = ""; uint crc = 0; long size = 0, dstLen = 0; int exportId = -1; string pkgPath = ""; byte[] dst = null; fs.JumpTo(modFiles[l].offset); size = modFiles[l].size; if (modFiles[l].tag == MipMaps.FileTextureTag) { name = fs.ReadStringASCIINull(); crc = fs.ReadUInt32(); } else if (modFiles[l].tag == MipMaps.FileBinaryTag) { name = modFiles[l].name; exportId = fs.ReadInt32(); pkgPath = fs.ReadStringASCIINull(); } dst = MipMaps.decompressData(fs, size); dstLen = dst.Length; updateStatusTextures("Mod: " + (i + 1) + " of " + memFiles.Count + " - in progress: " + ((l + 1) * 100 / numFiles) + " % "); if (modFiles[l].tag == MipMaps.FileTextureTag) { FoundTexture foundTexture; foundTexture = textures.Find(s => s.crc == crc); if (foundTexture.crc != 0) { DDSImage image = new DDSImage(new MemoryStream(dst, 0, (int)dstLen)); if (!image.checkExistAllMipmaps()) { errors += "Error in texture: " + name + string.Format("_0x{0:X8}", crc) + " Texture skipped. This texture has not all the required mipmaps" + Environment.NewLine; log += "Error in texture: " + name + string.Format("_0x{0:X8}", crc) + " Texture skipped. This texture has not all the required mipmaps" + Environment.NewLine; continue; } errors += mipMaps.replaceTexture(image, foundTexture.list, cachePackageMgr, foundTexture.name, crc); } else { log += "Texture skipped. Texture " + name + string.Format("_0x{0:X8}", crc) + " is not present in your game setup" + Environment.NewLine; } } else if (modFiles[l].tag == MipMaps.FileBinaryTag) { string path = GameData.GamePath + pkgPath; if (!File.Exists(path)) { log += "Warning: File " + path + " not exists in your game setup." + Environment.NewLine; continue; } Package pkg = cachePackageMgr.OpenPackage(path); pkg.setExportData(exportId, dst); } else { errors += "Unknown tag for file: " + name + Environment.NewLine; log += "Unknown tag for file: " + name + Environment.NewLine; } } } } }