/// <summary> /// Constructor for tree texture object. /// </summary> /// <param name="temppcc">PCC to get info from.</param> /// <param name="ExpID">ExpID of texture.</param> /// <param name="WhichGame">Game target.</param> /// <param name="pathBIOGame">BIOGame path to game targeted.</param> /// <param name="ExecPath">Path to ME3Explorer \exec\ folder.</param> /// <param name="allfiles">List of all PCC's containing texture.</param> /// <param name="Success">OUT: True if sucessfully created.</param> public TreeTexInfo(IPCCObject temppcc, int ExpID, int WhichGame, string pathBIOGame, string ExecPath, out bool Success) { Success = false; CRC32 crcgen = new CRC32(); string ArcPath = pathBIOGame; ITexture2D temptex2D = null; if (temppcc.Exports[ExpID].ValidTextureClass()) { try { temptex2D = temppcc.CreateTexture2D(ExpID, pathBIOGame); } catch (Exception e) { Console.WriteLine(e); return; } // KFreon: If no images, ignore if (temptex2D.imgList.Count == 0) { return; } string texname = temptex2D.texName; IImageInfo tempImg = temptex2D.GenerateImageInfo(); uint hash = 0; /*if (WhichGame != 1 && temptex2D.arcName != "None") * ValidFirstPCC = true;*/ // KFreon: Add pcc name to list in tex2D if necessary /*if (temptex2D.allFiles == null || temptex2D.allFiles.Count == 0) * { * temptex2D.allFiles = new List<string>(); * temptex2D.allFiles.Add(temppcc.pccFileName); * } * else if (!temptex2D.allFiles.Contains(temppcc.pccFileName)) * temptex2D.allFiles.Add(temppcc.pccFileName);*/ // KFreon: Get texture hash if (tempImg.CompareStorage("pccSto")) { if (temptex2D.texFormat != "PF_NormalMap_HQ") { hash = ~crcgen.BlockChecksum(temptex2D.DumpImg(tempImg.imgSize, ArcPath)); } else { hash = ~crcgen.BlockChecksum(temptex2D.DumpImg(tempImg.imgSize, pathBIOGame), 0, tempImg.uncSize / 2); } } else { byte[] buffer = temptex2D.DumpImg(tempImg.imgSize, ArcPath); if (buffer == null) { hash = 0; } else { if (temptex2D.texFormat != "PF_NormalMap_HQ") { hash = ~crcgen.BlockChecksum(buffer); } else { hash = ~crcgen.BlockChecksum(buffer, 0, tempImg.uncSize / 2); } } } // KFreon: Get image thumbnail string thumbnailPath = ExecPath + "placeholder.ico"; string tempthumbpath = ExecPath + "ThumbnailCaches\\" + "ME" + WhichGame + "ThumbnailCache\\" + texname + "_" + hash + ".jpg"; bool exists = File.Exists(tempthumbpath); if (!exists) { try { using (MemoryStream ms = new MemoryStream(temptex2D.GetImageData())) if (ImageEngine.GenerateThumbnailToFile(ms, tempthumbpath, 128)) { thumbnailPath = tempthumbpath; } } catch { } // KFreon: Don't really care about failures } // KFreon: Initialise things ValidFirstPCC = WhichGame == 2 && (!String.IsNullOrEmpty(temptex2D.arcName) && temptex2D.arcName != "None"); InfoInitialise(temptex2D, ExpID, hash, WhichGame, temppcc, tempImg.offset, thumbnailPath, pathBIOGame); Success = true; } }
/// <summary> /// Constructor for tree texture object. /// </summary> /// <param name="temppcc">PCC to get info from.</param> /// <param name="ExpID">ExpID of texture.</param> /// <param name="WhichGame">Game target.</param> /// <param name="pathBIOGame">BIOGame path to game targeted.</param> /// <param name="ExecPath">Path to ME3Explorer \exec\ folder.</param> /// <param name="allfiles">List of all PCC's containing texture.</param> /// <param name="Success">OUT: True if sucessfully created.</param> public TreeTexInfo(IPCCObject temppcc, int ExpID, int WhichGame, string pathBIOGame, string ExecPath, out bool Success) { Success = false; CRC32 crcgen = new CRC32(); string ArcPath = pathBIOGame; ITexture2D temptex2D = null; if (temppcc.Exports[ExpID].ValidTextureClass()) { try { temptex2D = temppcc.CreateTexture2D(ExpID, pathBIOGame); } catch (Exception e) { Console.WriteLine(e); return; } // KFreon: If no images, ignore if (temptex2D.imgList.Count == 0) { return; } string texname = temptex2D.texName; IImageInfo tempImg = temptex2D.GenerateImageInfo(); uint hash = 0; // KFreon: Get texture hash if (tempImg.CompareStorage("pccSto")) { if (temptex2D.texFormat != ImageEngineFormat.DDS_ATI2_3Dc) { hash = ~crcgen.BlockChecksum(temptex2D.DumpImg(tempImg.imgSize, ArcPath)); } else { hash = ~crcgen.BlockChecksum(temptex2D.DumpImg(tempImg.imgSize, pathBIOGame), 0, tempImg.uncSize / 2); } } else { byte[] buffer = temptex2D.DumpImg(tempImg.imgSize, ArcPath); if (buffer == null) { hash = 0; } else { if (temptex2D.texFormat != ImageEngineFormat.DDS_ATI2_3Dc) { hash = ~crcgen.BlockChecksum(buffer); } else { hash = ~crcgen.BlockChecksum(buffer, 0, tempImg.uncSize / 2); } } } // KFreon: Get image thumbnail string thumbnailPath = ExecPath + "placeholder.ico"; string tempthumbpath = ExecPath + "ThumbnailCaches\\" + "ME" + WhichGame + "ThumbnailCache\\" + texname + "_" + hash + ".jpg"; bool exists = File.Exists(tempthumbpath); if (!exists) { try { using (MemoryStream ms = new MemoryStream(temptex2D.GetImageData())) { var tex = temptex2D.imgList.Where(t => t.offset != -1).First(); int max = (int)(tex.imgSize.height > tex.imgSize.width ? tex.imgSize.height : tex.imgSize.width); double divisor = max > 128 ? max / 128.0 : 1; int newWidth = (int)(tex.imgSize.width / divisor); int newHeight = (int)(tex.imgSize.height / divisor); string temp = KFreonLib.Textures.Creation.GenerateThumbnail(ms, tempthumbpath, newWidth, newHeight); if (temp != null) { thumbnailPath = temp; } } } catch { } // KFreon: Don't really care about failures } // KFreon: Initialise things ValidFirstPCC = WhichGame == 2 && (!String.IsNullOrEmpty(temptex2D.arcName) && temptex2D.arcName != "None"); InfoInitialise(temptex2D, ExpID, hash, WhichGame, temppcc, tempImg.offset, thumbnailPath, pathBIOGame); Success = true; } }