public void LoadSKIN(int fileDataID) { BinaryReader bin = new BinaryReader(CASC.OpenFile(fileDataID)); var header = new string(bin.ReadChars(4)); if (header != "SKIN") { Console.WriteLine("Invalid SKIN file!"); } var nIndices = bin.ReadUInt32(); var ofsIndices = bin.ReadUInt32(); var nTriangles = bin.ReadUInt32(); var ofsTriangles = bin.ReadUInt32(); var nProperties = bin.ReadUInt32(); var ofsProperties = bin.ReadUInt32(); var nSubmeshes = bin.ReadUInt32(); var ofsSubmeshes = bin.ReadUInt32(); var nTextureUnits = bin.ReadUInt32(); var ofsTextureUnits = bin.ReadUInt32(); skin.bones = bin.ReadUInt32(); skin.indices = ReadIndices(nIndices, ofsIndices, bin); skin.triangles = ReadTriangles(nTriangles, ofsTriangles, bin); skin.properties = ReadProperties(nProperties, ofsProperties, bin); skin.submeshes = ReadSubmeshes(nSubmeshes, ofsSubmeshes, bin); skin.textureunit = ReadTextureUnits(nTextureUnits, ofsTextureUnits, bin); bin.Close(); }
public static void ReadTXID(BinaryReader reader, M2Model model, uint chunkSize) { var txidSize = chunkSize / 4; for (var i = 0; i < txidSize; ++i) { var fileDataId = reader.ReadUInt32(); if (!TextureFileIds.Contains(fileDataId)) { var m2Texture = new M2Texture(); var textureData = new TextureData(); using (var blpStream = CASC.OpenFile(fileDataId)) { var blp = new BLP(); var blpData = blp.GetUncompressed(blpStream); var blpInfo = blp.GetInfo(); textureData.HasMipmaps = blpInfo.hasMipmaps; textureData.Width = blpInfo.width; textureData.Height = blpInfo.height; textureData.RawData = blpData; textureData.TextureFormat = blpInfo.textureFormat; m2Texture.TextureData = textureData; m2Texture.FileDataId = fileDataId; TextureFileIds.Add(fileDataId); } model.Textures.Add(m2Texture); } } }
private void ReadMWMOChunk(BinaryReader bin, uint size) { var wmoFilesChunk = bin.ReadBytes((int)size); var str = new StringBuilder(); for (var i = 0; i < wmoFilesChunk.Length; i++) { if (wmoFilesChunk[i] == '\0') { if (str.Length > 1) { if (!CASC.FileExists(str.ToString())) { Console.WriteLine("WMO file does not exist!!! {0}", str.ToString()); } } str = new StringBuilder(); } else { str.Append((char)wmoFilesChunk[i]); } } }
private void CASCworker_DoWork(object sender, DoWorkEventArgs e) { var basedir = ConfigurationManager.AppSettings["basedir"]; if (Directory.Exists(basedir)) { if (File.Exists(Path.Combine(basedir, ".build.info"))) { cascworker.ReportProgress(0, "Loading WoW from disk.."); try { CASC.InitCasc(cascworker, basedir, ConfigurationManager.AppSettings["program"]); } catch (Exception exception) { Logger.WriteLine("CASCWorker: Exception from {0} during CASC startup: {1}", exception.Source, exception.Message); var result = MessageBox.Show("A fatal error occured during loading your local WoW installation.\n\n" + exception.Message + "\n\nPlease try updating/repairing WoW through the Battle.net App. \n\nIf that doesn't work do the following: \n- Go to your WoW install directory\n- Go inside the data folder\n- Rename the 'indices' folder to 'indices_old'\n- Start WoW to regenerate indices\n- After WoW has started, quit WoW\n\nStill having issues?\nGo to marlam.in/obj and contact me for further help.", "Fatal error", MessageBoxButton.OK, MessageBoxImage.Error); if (result == MessageBoxResult.OK) { Environment.Exit(1); } } } else { throw new Exception("Unable to find World of Warcraft client!"); } } else { cascworker.ReportProgress(0, "Loading WoW from web.."); CASC.InitCasc(cascworker, null, ConfigurationManager.AppSettings["program"]); } }
private static void Main(string[] args) { CASC.InitCasc(null, @"C:\World of Warcraft", "wow"); Console.WriteLine("CASC loaded!"); var reader = new M2Reader(); var filename = @"item\objectcomponents\shield\shield_1h_artifactnorgannon_d_01.m2"; reader.LoadM2(filename); var fileDataID = CASC.getFileDataIdByName(filename); for (int i = 0; i < reader.model.textures.Length; i++) { Console.WriteLine("Doing type " + reader.model.textures[i].type + " lookup for texture #" + i); switch (reader.model.textures[i].type) { case 1: case 2: case 11: uint[] cdifilenames = DBCHelper.getTexturesByModelFilename(fileDataID, (int)reader.model.textures[i].type); for (int ti = 0; ti < cdifilenames.Length; ti++) { Console.WriteLine("Found (texture #" + ti + ") " + cdifilenames[ti]); var blpreader = new BLPReader(); blpreader.LoadBLP((int)cdifilenames[ti]); } break; default: throw new Exception("Unhandled texture type"); break; } } Console.WriteLine("Done."); Console.ReadLine(); }
public static void Load() { if (!File.Exists("listfile.csv")) { throw new FileNotFoundException("Listfile.csv not found, download it at http://wow.tools/files/"); } foreach (var line in File.ReadAllLines("listfile.csv")) { if (line.Length == 0) { continue; } var splitLine = line.Split(';'); if (!splitLine[1].StartsWith("world")) { continue; } var fdid = uint.Parse(splitLine[0]); if (!CASC.FileExists(fdid)) { continue; } fdidToNameMap.Add(fdid, splitLine[1]); nameToFDIDMap.Add(splitLine[1], fdid); } }
public MTEX ReadMTEXChunk(BlizzHeader chunk, BinaryReader bin) { MTEX txchunk = new MTEX(); //List of BLP filenames var blpFilesChunk = bin.ReadBytes((int)chunk.Size); var str = new StringBuilder(); for (var i = 0; i < blpFilesChunk.Length; i++) { if (blpFilesChunk[i] == '\0') { blpFiles.Add(str.ToString()); if (!CASC.FileExists(str.ToString())) { Console.WriteLine("BLP file does not exist!!! {0}", str.ToString()); new WoWFormatLib.Utils.MissingFile(str.ToString()); } str = new StringBuilder(); } else { str.Append((char)blpFilesChunk[i]); } } txchunk.filenames = blpFiles.ToArray(); return(txchunk); }
public static Stream OpenFile(PackageRecord record) { long offset = 0; EncodingEntry enc; if (record.Flags.HasFlag(ContentFlags.Bundle)) { offset = record.Offset; } if (!CASC.Encoding.GetEntry(record.Hash, out enc)) { return(null); } MemoryStream ms = new MemoryStream((int)record.Size); try { Stream fstream = CASC.OpenFile(enc.Key); fstream.Position = offset; CopyBytes(fstream, ms, (int)record.Size); ms.Position = 0; } catch (Exception e) { if (e is BLTEKeyException exception) { #if DEBUG Debugger.Log(0, "DataTool", $"[DataTool:CASC]: Missing key: {exception.MissingKey:X16}\r\n"); #endif } return(null); } return(ms); }
public void LoadSKEL(uint fileDataID) { using (var bin = new BinaryReader(CASC.OpenFile(fileDataID))) { var header = new string(bin.ReadChars(4)); } }
public static int LoadTexture(uint filedataid, CacheStorage cache) { GL.ActiveTexture(TextureUnit.Texture0); if (cache.materials.ContainsKey(filedataid)) { return(cache.materials[filedataid]); } int textureId = GL.GenTexture(); using (var blp = new BlpFile(CASC.OpenFile(filedataid))) { var bmp = blp.GetBitmap(0); if (bmp == null) { throw new Exception("BMP is null!"); } GL.BindTexture(TextureTarget.Texture2D, textureId); cache.materials.Add(filedataid, textureId); var bmp_data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp_data.Width, bmp_data.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); bmp.UnlockBits(bmp_data); } return(textureId); }
private void MapListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { tileListBox.Items.Clear(); if (mapListBox.HasItems) { var selectedItem = (MapListItem)mapListBox.SelectedItem; if (CASC.FileExists((uint)selectedItem.WDTFileDataID)) { if (!wdtCache.ContainsKey(selectedItem.ID)) { var reader = new WoWFormatLib.FileReaders.WDTReader(); reader.LoadWDT((uint)selectedItem.WDTFileDataID); wdtCache.Add(selectedItem.ID, reader); } for (var i = 0; i < wdtCache[selectedItem.ID].tiles.Count; i++) { tileListBox.Items.Add(wdtCache[selectedItem.ID].tiles[i].Item1.ToString() + "_" + wdtCache[selectedItem.ID].tiles[i].Item2.ToString()); } } } e.Handled = true; }
public void LoadAnim(uint fileDataID) { using (var bin = new BinaryReader(CASC.OpenFile(fileDataID))) { long position = 0; while (position < bin.BaseStream.Length) { bin.BaseStream.Position = position; var chunkName = (ANIMChunks)bin.ReadUInt32(); var chunkSize = bin.ReadUInt32(); position = bin.BaseStream.Position + chunkSize; switch (chunkName) { case ANIMChunks.AFM2: case ANIMChunks.AFSA: case ANIMChunks.AFSB: break; default: throw new Exception(string.Format("{2} Found unknown header at offset {1} \"{0}\" while we should've already read them all!", chunkName, position, fileDataID)); } } } }
private void ReadTXFNChunk(BinaryReader bin, BlizzHeader chunk) { //List of BLP filenames var blpFilesChunk = bin.ReadBytes((int)chunk.Size); var str = new StringBuilder(); for (var i = 0; i < blpFilesChunk.Length; i++) { if (blpFilesChunk[i] == '\0') { if (str.Length > 1) { str.Replace("..", "."); str.Append(".blp"); //Filenames in TEX dont have have BLP extensions if (!CASC.FileExists(str.ToString())) { new WoWFormatLib.Utils.MissingFile(str.ToString()); } } str = new StringBuilder(); } else { str.Append((char)blpFilesChunk[i]); } } }
public async Task <FileContentResult> GetByContentHash(string buildConfig, string cdnConfig, string contenthash, string filename) { Console.WriteLine("[" + DateTime.Now + "] Serving preview of \"" + filename + "\" (" + contenthash + ") for build " + buildConfig + " and cdn " + cdnConfig); System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition { FileName = "preview", Inline = true }; Response.Headers[HeaderNames.ContentDisposition] = cd.ToString(); var fileBytes = await CASC.GetFile(buildConfig, cdnConfig, contenthash); var ext = Path.GetExtension(filename); var mime = GetMimeTypeByExt(ext); if (ext == ".blp") { using (var stream = new MemoryStream(fileBytes)) using (var outStream = new MemoryStream()) { var blpReader = new SereniaBLPLib.BlpFile(stream); var blp = blpReader.GetBitmap(0); blp.Save(outStream, ImageFormat.Png); fileBytes = outStream.ToArray(); } mime = "image/png"; } return(new FileContentResult(fileBytes, mime)); }
public async Task <FileContentResult> GetByContentHash(string buildConfig, string cdnConfig, string contenthash, string filename) { if (NGDP.encodingDictionary.TryGetValue(contenthash.ToByteArray().ToMD5(), out var entry)) { Logger.WriteLine("Serving cached file \"" + filename + "\" (" + contenthash + ")", ConsoleColor.Green); return(new FileContentResult(await CASC.RetrieveFileBytes(entry), "application/octet-stream") { FileDownloadName = filename }); } else { Logger.WriteLine("Looking up and serving file \"" + filename + "\" (" + contenthash + ") for build " + buildConfig + " and cdn " + cdnConfig, ConsoleColor.Yellow); if (string.IsNullOrEmpty(buildConfig) || string.IsNullOrEmpty(cdnConfig) || string.IsNullOrEmpty(contenthash) || string.IsNullOrEmpty(filename)) { throw new ArgumentException("Invalid arguments!"); } // Retrieve CDNConfig from DB if not set in request if (string.IsNullOrEmpty(cdnConfig) && !string.IsNullOrEmpty(buildConfig)) { cdnConfig = await Database.GetCDNConfigByBuildConfig(buildConfig); } return(new FileContentResult(await CASC.GetFile(buildConfig, cdnConfig, contenthash), "application/octet-stream") { FileDownloadName = filename }); } }
/// <summary> /// Read the Obj0.adt format. /// </summary> /// <param name="fileDataId"></param> /// <param name="model"></param> public static void ReadObjADT(uint fileDataId, ADTModel model) { var stream = CASC.OpenFile(fileDataId); if (stream == null) { return; } using (var reader = new BinaryReader(stream)) { while (reader.BaseStream.Position < reader.BaseStream.Length) { var chunkId = (Chunks)reader.ReadUInt32(); var chunkSize = reader.ReadUInt32(); switch (chunkId) { case Chunks.MDDF: // Doodad Instances ReadMDDF(reader, chunkSize, model); break; default: reader.Skip(chunkSize); // Debug.Log($"ADTOBJ: Skipping {chunkId} (0x{chunkId:X}) with size: {chunkSize}.."); break; } } } }
public FileContentResult GetByFileDataID(string buildConfig, string cdnConfig, uint filedataid, string filename) { Logger.WriteLine("Serving preview of \"" + filename + "\" for build " + buildConfig + " and cdn " + cdnConfig); System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition { FileName = "preview", Inline = true }; Response.Headers[HeaderNames.ContentDisposition] = cd.ToString(); var fileBytes = CASC.GetFile(buildConfig, cdnConfig, filedataid); var ext = Path.GetExtension(filename); var mime = GetMimeTypeByExt(ext); if (ext == ".blp") { using (var stream = new MemoryStream(fileBytes)) using (var outStream = new MemoryStream()) { var blpReader = new SereniaBLPLib.BlpFile(stream); var blp = blpReader.GetBitmap(0); blp.Save(outStream, ImageFormat.Png); fileBytes = outStream.ToArray(); } mime = "image/png"; } return(new FileContentResult(fileBytes, mime)); }
public static TextureData Open(uint fileDataId) { if (fileDataId == 0) { return(null); } var stream = CASC.OpenFile(fileDataId); if (stream == null) { return(null); } var textureData = new TextureData(); var blp = new BLP(); var blpData = blp.GetUncompressed(stream); var blpInfo = blp.GetInfo(); textureData.HasMipmaps = blpInfo.hasMipmaps; textureData.Width = blpInfo.width; textureData.Height = blpInfo.height; textureData.RawData = blpData; textureData.TextureFormat = blpInfo.textureFormat; return(textureData); }
static void Main() { CASC.InitCasc(null, null, "wow_beta"); var tw = new TerrainWindow("Azeroth_32_32", null); tw.Run(); }
/* ROOT */ public void LoadADT(string filename, bool loadSecondaryADTs = true) { filename = Path.ChangeExtension(filename, ".adt"); var mapname = filename.Replace("world\\maps\\", "").Substring(0, filename.Replace("world\\maps\\", "").IndexOf("\\")); var wdtFileName = "world\\maps\\" + mapname + "\\" + mapname + ".wdt"; var exploded = Path.GetFileNameWithoutExtension(filename).Split('_'); if (!byte.TryParse(exploded[exploded.Length - 2], out var tileX) || !byte.TryParse(exploded[exploded.Length - 1], out var tileY)) { throw new FormatException("An error occured converting coordinates from " + filename + " to bytes"); } uint wdtFileDataID; if (CASC.FileExists(wdtFileName)) { wdtFileDataID = CASC.getFileDataIdByName(wdtFileName); } else { throw new Exception("WDT does not exist, need this for MCAL flags!"); } LoadADT(wdtFileDataID, tileX, tileY, loadSecondaryADTs, wdtFileName); }
private static void Main(string[] args) { //CASC.InitCasc(null, @"C:\World of Warcraft", "wow"); CASC.InitCasc(null, null, "wowt"); Console.WriteLine("CASC loaded!"); if (!File.Exists("listfile.txt")) { throw new Exception("Listfile not found!"); } var reader = new BLSReader(); reader.LoadBLS(1694483); var shaderFile = reader.shaderFile; //foreach (var line in File.ReadAllLines("listfile.txt")) //{ // if (CASC.cascHandler.FileExists(line) && line.EndsWith(".bls", StringComparison.CurrentCultureIgnoreCase)) // { // Console.WriteLine("Loading " + line); // var reader = new BLSReader(); // reader.LoadBLS(line); // } //} }
public void LoadBLP(string filename) { using (var blp = new BlpFile(CASC.OpenFile(filename))) { bmp = blp.GetBitmap(0); } }
private MTEX ReadMTEXChunk(uint size, BinaryReader bin) { var txchunk = new MTEX(); //List of BLP filenames var blpFilesChunk = bin.ReadBytes((int)size); var str = new StringBuilder(); for (var i = 0; i < blpFilesChunk.Length; i++) { if (blpFilesChunk[i] == '\0') { blpFiles.Add(str.ToString()); if (!CASC.FileExists(str.ToString())) { Console.WriteLine("BLP file does not exist!!! {0}", str.ToString()); } str = new StringBuilder(); } else { str.Append((char)blpFilesChunk[i]); } } txchunk.filenames = blpFiles.ToArray(); return(txchunk); }
public void LoadBLP(uint fileDataID) { using (var blp = new BlpFile(CASC.OpenFile(fileDataID))) { bmp = blp.GetBitmap(0); } }
public void ExportFolders() { WowRootHandler wowRoot = CASC.Root as WowRootHandler; using (StreamWriter sw = new StreamWriter("dirs.txt")) { HashSet <string> dirData = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var file in CASCFile.Files.OrderBy(f => f.Value.FullName, StringComparer.OrdinalIgnoreCase)) { if (CASC.FileExists(file.Key) && (wowRoot == null || !wowRoot.IsUnknownFile(file.Key))) { ulong fileHash = file.Key; int dirSepIndex = file.Value.FullName.LastIndexOf('\\'); if (dirSepIndex >= 0) { string dir = file.Value.FullName.Substring(0, dirSepIndex); dirData.Add(dir); } } } foreach (var dir in dirData) { sw.WriteLine(dir); } Logger.WriteLine("WowRootHandler: loaded {0} valid file names", CASCFile.Files.Count); } }
public void ExportListFile() { WowRootHandler wowRoot = CASC.Root as WowRootHandler; using (StreamWriter sw = new StreamWriter("listfile_export.txt")) { foreach (var file in CASCFile.Files.OrderBy(f => f.Value.FullName, StringComparer.OrdinalIgnoreCase)) { if (CASC.FileExists(file.Key) && (wowRoot == null || !wowRoot.IsUnknownFile(file.Key))) { sw.WriteLine(file.Value); } } //var wr = CASC.Root as WowRootHandler; //SortedDictionary<int, string> fids = new SortedDictionary<int, string>(); //foreach (var file in CASCFile.FileNames) //{ // var id = wr.GetFileDataIdByName(file.Value); // if (id > 0) // { // fids[id] = file.Value; // } //} //foreach (var file in fids) //{ // sw.WriteLine("{0} {1}", file.Key, file.Value); //} } }
private void FilterBox_TextChanged(object sender, TextChangedEventArgs e) { var filtered = new List <string>(); var selectedTab = (TabItem)tabs.SelectedItem; if ((string)selectedTab.Header == "Textures") { for (var i = 0; i < textures.Count(); i++) { if (textures[i].IndexOf(filterTextBox.Text, 0, StringComparison.CurrentCultureIgnoreCase) != -1) { filtered.Add(textures[i]); } } textureListBox.DataContext = filtered; } else if ((string)selectedTab.Header == "Maps") { UpdateMapListView(); } else { if (filterTextBox.Text.StartsWith("maptile:")) { var filterSplit = filterTextBox.Text.Remove(0, 8).Split('_'); if (filterSplit.Length == 3) { exportButton.Content = "Crawl maptile for models"; if (CASC.FileExists("world/maps/" + filterSplit[0] + "/" + filterSplit[0] + "_" + filterSplit[1] + "_" + filterSplit[2] + ".adt")) { exportButton.IsEnabled = true; } else { exportButton.IsEnabled = false; } } } else { exportButton.Content = "Export model to OBJ!"; } for (var i = 0; i < models.Count(); i++) { if (models[i].IndexOf(filterTextBox.Text, 0, StringComparison.CurrentCultureIgnoreCase) != -1) { filtered.Add(models[i]); } } modelListBox.DataContext = filtered; } }
public BLS LoadBLS(uint fileDataID) { if (!CASC.FileExists(fileDataID)) { throw new FileNotFoundException("BLS " + fileDataID + " not found!"); } return(LoadBLS(CASC.OpenFile(fileDataID))); }
static void Main(string[] args) { cascworker.RunWorkerCompleted += CASCworker_RunWorkerCompleted; cascworker.ProgressChanged += CASC_ProgressChanged; cascworker.WorkerReportsProgress = true; CASC.InitCasc(cascworker, "C:\\Program Files (x86)\\World of Warcraft", "wow"); ADTExporter.ExportADT(775971, 33, 32); }
public void RemoteLoadingSpeed() { var casc = new CASC <DistantProvider, Wow>(); var stopWatch = Stopwatch.StartNew(); casc.Initialize("eu"); stopWatch.Stop(); Trace.WriteLine($"Distant CASC loaded in {stopWatch.ElapsedMilliseconds} ms"); }