// Handle via CASCLib public static void InitCasc(BackgroundWorkerEx worker = null, string basedir = null, string program = "wowt", LocaleFlags locale = LocaleFlags.enUS) { usingLocalAPI = false; CASCConfig.LoadFlags &= ~(LoadFlags.Download | LoadFlags.Install); CASCConfig.ValidateData = false; CASCConfig.ThrowOnFileNotFound = false; if (basedir == null) { Console.WriteLine("Initializing CASC from web for program " + program); cascHandler = CASCHandler.OpenOnlineStorage(program, "eu", worker); } else { basedir = basedir.Replace("_retail_", "").Replace("_ptr_", ""); Console.WriteLine("Initializing CASC from local disk with basedir " + basedir); cascHandler = CASCHandler.OpenLocalStorage(basedir, worker); } BuildName = cascHandler.Config.BuildName; cascHandler.Root.SetFlags(locale, ContentFlags.None, false); IsCASCInit = true; }
public static void MapCMF(OwRootHandler ow, CASCHandler handler, Dictionary <ulong, PackageRecord> map, Dictionary <ushort, List <ulong> > track, string language) { if (ow == null || handler == null) { return; } foreach (ApplicationPackageManifest apm in ow.APMFiles) { if (!apm.Name.ToLowerInvariant().Contains("rdev")) { continue; } if (language != null && !apm.Name.ToLowerInvariant().Contains("l" + language.ToLowerInvariant())) { continue; } foreach (KeyValuePair <ulong, PackageRecord> pair in apm.FirstOccurence) { ushort id = GUID.Type(pair.Key); if (track != null && track.ContainsKey(id)) { track[id].Add(pair.Value.GUID); } if (map.ContainsKey(pair.Key)) { continue; } map[pair.Key] = pair.Value; } } }
public static Stream OpenFile(Record record, CASCHandler handler) { long offset = 0; EncodingEntry enc; if (((ContentFlags)record.record.Flags & ContentFlags.Bundle) == ContentFlags.Bundle) { offset = record.record.Offset; handler.Encoding.GetEntry(record.index.bundleContentKey, out enc); } else { handler.Encoding.GetEntry(record.record.ContentKey, out enc); } MemoryStream ms = new MemoryStream(record.record.Size); try { Stream fstream = handler.OpenFile(enc.Key); fstream.Position = offset; CopyBytes(fstream, ms, record.record.Size); ms.Position = 0; } catch (Exception ex) { Console.Out.WriteLine("Error {0} with file {2:X12}.{3:X3} ({1})", ex.Message, TypeAlias(GUID.Type(record.record.Key)), GUID.LongKey(record.record.Key), GUID.Type(record.record.Key)); return(null); } if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Log(0, "CASC:IO", $"[CASC:IO] Opened file {GUID.LongKey(record.record.Key):X12}.{GUID.Type(record.record.Key):X3}\n"); } return(ms); }
internal static STUInstance[] GetInstances(ulong guid, CASCHandler handler, Dictionary <ulong, Record> map) { Stream str = Util.OpenFile(map[guid], handler); ISTU stu = ISTU.NewInstance(str, uint.MaxValue); return(stu.Instances.ToArray()); }
public static void ReadTXID(BinaryReader br, M2Data m2Data, CASCHandler CascHandler, uint Size) { LoadedBLPFileDataIds.Clear(); var numTextures = Size / 4; for (int i = 0; i < numTextures; i++) { uint texture = br.ReadUInt32(); M2Texture m2Texture = new M2Texture(); Texture2Ddata texture2Ddata = new Texture2Ddata(); if (!LoadedBLPFileDataIds.Contains(texture)) { var stream = CascHandler.OpenFile(texture); BLP blp = new BLP(); byte[] data = blp.GetUncompressed(stream, true); BLPinfo info = blp.Info(); texture2Ddata.hasMipmaps = info.hasMipmaps; texture2Ddata.width = info.width; texture2Ddata.height = info.height; texture2Ddata.textureFormat = info.textureFormat; texture2Ddata.TextureData = data; m2Texture.texture2Ddata = texture2Ddata; m2Texture.FileDataId = texture; stream.Close(); stream.Dispose(); LoadedBLPFileDataIds.Add(texture); } m2Data.m2Tex.Add(m2Texture); } }
//---------------------------------------------------------------------------------- // CASC //---------------------------------------------------------------------------------- public static void LoadCASC() { if (ConfigurationManager.GameDir == null) { throw new Exception("Game directory not initialized, unable to load CASC"); } try { cascHandler = CASCHandler.OpenLocalStorage(ConfigurationManager.GameDir); //Download a listfile if none exists if (!File.Exists(listFilePath)) { WoWExport.Listfile.Update(); } cascHandler.Root.LoadListFile(listFilePath); //Console.WriteLine(cascHandler.Config.BuildName); CASCConfig.ValidateData = false; CASCConfig.ThrowOnFileNotFound = false; //-------------------------------------------------------------------------- // TO DO: FIND A WAY TO GET THE LOCALE //-------------------------------------------------------------------------- cascHandler.Root.SetFlags(LocaleFlags.enUS); //Hardcoded for the moment //-------------------------------------------------------------------------- } catch (Exception e) { throw new Exception(e.Message); } }
private string GetGameParam(ulong key, Dictionary <ulong, Record> map, CASCHandler handler) { if (!map.ContainsKey(key)) { return(null); } using (Stream input = Util.OpenFile(map[key], handler)) { if (input == null) { return(null); } STUD stud = new STUD(input); if (stud.Instances == null || stud.Instances[0] == null) { return(null); } GameTypeParam gm = stud.Instances[0] as GameTypeParam; if (gm == null) { return(null); } return(Util.GetString(gm.Header.name, map, handler)); } }
/// <summary> /// Read the WDT file. /// </summary> public void ReadWDT(CASCHandler handler, uint wdtfiledataid) { var stream = handler.OpenFile((int)wdtfiledataid); if (stream == null) { return; } using (var reader = new BinaryReader(stream)) { while (reader.BaseStream.Position < reader.BaseStream.Length) { var chunkId = (Chunk)reader.ReadUInt32(); var chunkSize = reader.ReadUInt32(); switch (chunkId) { case Chunk.MAID: for (var x = 0; x < 64; ++x) { for (var y = 0; y < 64; ++y) { var rootAdt = reader.ReadUInt32(); var obj0Adt = reader.ReadUInt32(); var obj1Adt = reader.ReadUInt32(); var tex0Adt = reader.ReadUInt32(); var lodAdt = reader.ReadUInt32(); var mapTexture = reader.ReadUInt32(); var mapTextureN = reader.ReadUInt32(); var minimapTexture = reader.ReadUInt32(); if (rootAdt == 0) { continue; } MAIDs.Add($"{y}_{x}", new MAID { RootADT = rootAdt, Obj0ADT = obj0Adt, Obj1ADT = obj1Adt, Tex0ADT = tex0Adt, LodADT = lodAdt, MapTexture = mapTexture, MapTextureN = mapTextureN, MinimapTexture = minimapTexture, }); } } break; default: Skip(reader, chunkSize); break; } } } }
public bool loadFile(CASCHandler cascHandler, string fileName) { var file = cascHandler.OpenFile(fileName); if (file == null) { return(false); } var fileSize = file.Length; if (fileSize == 0xFFFFFFFF) { return(false); } data_size = (uint)fileSize; _data = new BinaryReader(file).ReadBytes((int)data_size); parseChunks(); if (prepareLoadedData()) { return(true); } Console.WriteLine($"Error loading {fileName}\n"); return(false); }
public bool LoadFile(CASCHandler cascHandler, uint fileDataId, string description) { var file = cascHandler.OpenFile((int)fileDataId); if (file == null) { return(false); } var fileSize = file.Length; if (fileSize == 0xFFFFFFFF) { return(false); } dataSize = (uint)fileSize; data = new BinaryReader(file).ReadBytes((int)dataSize); ParseChunks(); if (PrepareLoadedData()) { return(true); } Console.WriteLine($"Error loading {description}\n"); return(false); }
public static void Load_hTextures(CASCHandler Handler) { if (ADTTexData.textureBlockData.MTXP) { ADTTexData.textureBlockData.terrainHTextures = new Dictionary <uint, ADTTexData.Texture2Ddata>(); foreach (uint TextureFileDataId in ADTTexData.textureBlockData.terrainTextureFileDataIds) { using (var stream = Handler.OpenFile(TextureFileDataId)) { BLP blp = new BLP(); byte[] data = blp.GetUncompressed(stream, true); BLPinfo info = blp.Info(); ADTTexData.Texture2Ddata texture2Ddata = new ADTTexData.Texture2Ddata(); texture2Ddata.hasMipmaps = info.hasMipmaps; texture2Ddata.width = info.width; texture2Ddata.height = info.height; if (info.width != info.height) // Unity doesn't support nonsquare mipmaps // sigh { texture2Ddata.hasMipmaps = false; } texture2Ddata.textureFormat = info.textureFormat; texture2Ddata.TextureData = data; ADTTexData.textureBlockData.terrainHTextures.Add(TextureFileDataId, texture2Ddata); stream.Close(); } } } }
private async Task LoadCASCDBFiles() { lstFiles.DataSource = null; FileNames.Clear(); try { await Task.Factory.StartNew(() => { using (var casc = new CASCHandler(filePath)) { Parallel.ForEach(ClientDBFileNames, file => { var stream = casc.ReadFile(file, locale); if (stream != null) { FileNames.TryAdd(file, Path.GetFileName(file)); Streams.TryAdd(file, stream); } }); } }); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public Wdt(int wdt_name, CASCHandler cascH, Dictionary <uint, string> lf, Dictionary <string, uint> fl, Dictionary <uint, List <Toolbox.IngameObject> > IG_Obj) { wdt_id = wdt_name; cs = cascH; listfile = lf; filelist = fl; ParseWdt(IG_Obj); }
/*Toolbox.plane plane_min = new Toolbox.plane(); * Toolbox.plane plane_max = new Toolbox.plane();*/ public ObjAdt(CASCHandler cascH, int adt_x, int adt_y, Dictionary <uint, string> lf, Dictionary <string, uint> fl) { cs = cascH; x = adt_x; y = adt_y; listfile = lf; filelist = fl; }
public static void Initialize(string path, LocaleFlags locale) { Locale = locale; Handler = CASCHandler.OpenLocalStorage(path); Handler.Root.SetFlags(locale, ContentFlags.None, false); Initialized = true; }
public static void InitializeOnline(LocaleFlags locale, BackgroundWorkerEx worker = null) { Locale = locale; Handler = CASCHandler.OpenOnlineStorage("wow", worker: worker); Handler.Root.SetFlags(locale, ContentFlags.None, false); Initialized = true; }
public static void Initialize(string path, LocaleFlags locale, BackgroundWorkerEx worker = null) { Locale = locale; Handler = CASCHandler.OpenLocalStorage(path, worker); Handler.Root.SetFlags(locale, ContentFlags.None, false); Initialized = true; }
public Adt(CASCHandler cascH, int adt_x, int adt_y, Dictionary <uint, string> lf, List <Toolbox.CsvArea> listareas, Dictionary <string, uint> fl) { cs = cascH; x = adt_x; y = adt_y; listfile = lf; filelist = fl; CsvAreas = listareas; }
//Load druid form model public void LoadModel(string modelfile, CASCHandler casc) { Loaded = false; if (loadBinaries != null) { loadBinaries.Abort(); } StartCoroutine(LoadPrefab(modelfile, casc)); }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(@" _ _ "); Console.WriteLine(@" /\ | | (_) "); Console.WriteLine(@" / \ _ __ ___| |_ _ _ _ _ __ ___ "); Console.WriteLine(@" / /\ \ | '__/ __| __| | | | | '_ ` _ \ "); Console.WriteLine(@" / ____ \| | | (__| |_| | |_| | | | | | |"); Console.WriteLine(@"/_/ \_\_| \___|\__|_|\__,_|_| |_| |_|"); Console.WriteLine(@" _ "); Console.WriteLine(@" |_._ _ | __|_ o _._ "); Console.WriteLine(@" |_| | |_||(_||_ |(_| | "); Console.WriteLine(); //Console.WriteLine($"{"www.arctium-emulation.com",33}"); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Gray; ReadConsoleArgs(args); if (isMacOrUnix && string.IsNullOrEmpty(appFolder)) { Console.WriteLine("Please use your '.app' folder as start parameter."); } else { pluralService = new PluralizationService(); pluralService.AddException("gtNpcTotalHp"); Console.WriteLine("Initializing CASC library..."); if (string.IsNullOrEmpty(appFolder)) { cascHandler = new CASCHandler(appFolder = Environment.CurrentDirectory); } else { cascHandler = new CASCHandler(Directory.GetParent(appFolder).ToString()); } Console.WriteLine("Done."); ExtractClientDBData(); Console.WriteLine("Done."); ExtractMapData(); Console.WriteLine(); Console.WriteLine("Press any key to exit..."); } Console.ReadKey(true); }
private static void ParseM2_Skin(uint skinFileId, M2Data m2Data, CASCHandler CascHandler) { var stream = CascHandler.OpenFile(skinFileId); using (BinaryReader reader = new BinaryReader(stream)) { ParseSkin(reader, m2Data); } }
public GUIDCollection(CASCConfig Config, CASCHandler CASC, ProgressReportSlave Slave) { this.Config = Config; this.CASC = CASC; this.Slave = Slave; long total = CASC.RootHandler.RootFiles.Count + CASC.RootHandler.APMFiles.SelectMany(x => x.FirstOccurence).LongCount(); Slave?.ReportProgress(0, "Building file tree..."); long c = 0; foreach (KeyValuePair <string, MD5Hash> entry in this.CASC.RootHandler.RootFiles.OrderBy(x => x.Key).ToArray()) { c++; Slave?.ReportProgress((int)(((float)c / (float)total) * 100)); AddEntry(entry.Key, 0, null, entry.Value, 0, 0, ContentFlags.None, LocaleFlags.None); } foreach (ApplicationPackageManifest apm in this.CASC.RootHandler.APMFiles.OrderBy(x => x.Name).ToArray()) { foreach (KeyValuePair <ulong, PackageRecord> record in apm.FirstOccurence.OrderBy(x => x.Key).ToArray()) { c++; if (c % 10000 == 0) { Slave?.ReportProgress((int)(((float)c / (float)total) * 100)); } ushort typeVal = teResourceGUID.Type(record.Key); string typeStr = typeVal.ToString("X3"); DataHelper.DataType typeData = DataHelper.GetDataType(typeVal); if (typeData != DataHelper.DataType.Unknown) { typeStr = $"{typeStr} ({typeData.ToString()})"; } AddEntry($"files/{Path.GetFileNameWithoutExtension(apm.Name)}/{typeStr}", record.Key, apm, record.Value.LoadHash, (int)record.Value.Size, (int)record.Value.Offset, record.Value.Flags, apm.Locale); } } Slave?.ReportProgress(0, "Sorting tree..."); long t = GetSize(Root); Sort(Root, 0, t); NotifyPropertyChanged(nameof(Data)); NotifyPropertyChanged(nameof(Root)); try { SelectedEntries = Data["RetailClient"]?.Files; } catch (KeyNotFoundException) { // } }
public static bool ParseWDT(uint FileDataId) { long streamPos = 0; CASC = GameObject.Find("[CASC]").GetComponent <CascHandler>().cascHandler; if (CASC.FileExists(FileDataId)) { using (var stream = CASC.OpenFile(FileDataId)) using (var reader = new BinaryReader(stream)) { WDTflagsdata WDTFlags = new WDTflagsdata(); while (streamPos < stream.Length) { stream.Position = streamPos; WDTChunkId ChunkId = (WDTChunkId)reader.ReadUInt32(); uint ChunkSize = reader.ReadUInt32(); streamPos = stream.Position + ChunkSize; switch (ChunkId) { case WDTChunkId.MVER: ReadMVER(reader); break; case WDTChunkId.MPHD: ReadMPHD(reader, WDTFlags); break; case WDTChunkId.MAIN: ReadMAIN(reader, WDTFlags); break; case WDTChunkId.MAID: ReadMAID(reader, FileDataId); break; default: SkipUnknownChunk(stream, ChunkId, ChunkSize); break; } } if (!Flags.ContainsKey(FileDataId)) { Flags.Add(FileDataId, WDTFlags); } } return(true); } else { return(false); } }
public static void LoadThread(CASCHandler Handler) { CascHandler = Handler; ThreadAlive = true; CompileMapList(currentWdtFileDataId); GetMinMax(); checkWMOonly = true; ResetParentSize = true; ThreadAlive = false; }
public static Stream OpenFile(MD5Hash hash, CASCHandler handler) { try { Stream fstream = handler.OpenFile(hash); return(fstream); } catch (Exception ex) { Console.Out.WriteLine("Error {0}", ex.Message); return(null); } }
/// <summary> /// Open both instances of <see cref="CASCHandler"/> (old and new) /// </summary> public static void OpenCasc(string product, string buildConfig, string cdnConfig) { // Open old CASC. OldStorage = CASCHandler.OpenSpecificStorage(product, buildConfig, cdnConfig); OldStorage.Root.SetFlags(LocaleFlags.All_WoW); // Open new CASC. NewStorage = CASCHandler.OpenOnlineStorage(product); NewStorage.Root.SetFlags(LocaleFlags.All_WoW); }
// materials // public static void ReadMOMT(BinaryReader reader, int MOMTsize, CASCHandler Handler) { wmoData.Info.nMaterials = MOMTsize / 64; for (int i = 0; i < wmoData.Info.nMaterials; i++) { WMOMaterial material = new WMOMaterial(); material.flags = reader.ReadMaterialFlags(); material.ShaderType = (WMOFragmentShader)reader.ReadUInt32(); // Index into CMapObj::s_wmoShaderMetaData. See below (shader types). material.BlendMode = (BlendingMode)reader.ReadUInt32(); // Blending: see https://wowdev.wiki/Rendering#EGxBlend material.TextureId1 = reader.ReadUInt32(); // offset into MOTX; ≥ Battle (8.1.0.27826) No longer references MOTX but is a filedata id directly. material.SidnColor = reader.ReadBGRA(); // emissive color; see below (emissive color) material.FrameSidnColor = reader.ReadBGRA(); // sidn emissive color; set at runtime; gets sidn-manipulated emissive color; see below (emissive color) material.TextureId2 = reader.ReadUInt32(); // Environment Texture; envNameIndex; offset into MOTX material.DiffColor = reader.ReadBGRA(); // diffuse color; CWorldView::GatherMapObjDefGroupLiquids(): geomFactory->SetDiffuseColor((CImVectorⁱ*)(smo+7)); // environment textures don't need flags material.GroundType = reader.ReadUInt32(); // foreign_keyⁱ< uint32_t, &TerrainTypeRec::m_ID > ground_type; // according to CMapObjDef::GetGroundType material.TextureId3 = reader.ReadUInt32(); // offset into MOTX material.Color = reader.ReadBGRA(); material.texture3_flags = reader.ReadMaterialFlags(); // skip runtime data // reader.BaseStream.Seek(16, SeekOrigin.Current); wmoData.materials.Add(material); if (!wmoData.texturePaths.ContainsKey(material.TextureId1)) { wmoData.texturePaths.Add(material.TextureId1, material.TextureId1); } if (material.TextureId1 != 0) { Texture2Ddata textureData = new Texture2Ddata(); Stream stream = Handler.OpenFile(material.TextureId1); BLP blp = new BLP(); byte[] data = blp.GetUncompressed(stream, true); BLPinfo info = blp.Info(); textureData.hasMipmaps = info.hasMipmaps; textureData.width = info.width; textureData.height = info.height; textureData.textureFormat = info.textureFormat; textureData.TextureData = data; stream.Close(); stream.Dispose(); LoadedBLPs.Add(material.TextureId1); if (!wmoData.textureData.ContainsKey(material.TextureId1)) { wmoData.textureData.Add(material.TextureId1, textureData); } } } } // loaded
public static bool ConvertADT(CASCHandler cascHandler, uint fileDataId, string mapName, string outputPath, int gx, int gy, bool ignoreDeepWater) { ChunkedFile adt = new(); if (!adt.LoadFile(cascHandler, fileDataId, $"Map {mapName} grid [{gx},{gy}]")) { return(false); } return(ConvertADT(adt, mapName, outputPath, gx, gy, cascHandler.Config.GetBuildNumber(), ignoreDeepWater)); }
private static void CascWorkerOnDoWork(object sender, DoWorkEventArgs e) { var config = (ModelViewerConfig)e.Argument; cascHandler = config.LoadType == CascLoadType.Online ? CASCHandler.OpenOnlineStorage(cascWorker, config.OnlineBranch) : CASCHandler.OpenLocalStorage(cascWorker, config.LocalStorage, config.LocalBranch); cascWorker.ReportProgress(0, "Setting flags..."); cascHandler.Root.SetFlags(LocaleFlags.enUS); }
internal static string GetOWString(ulong guid, CASCHandler handler, Dictionary <ulong, Record> map) { if (guid == 0 || !map.ContainsKey(guid)) { return(null); } Stream str = Util.OpenFile(map[guid], handler); OWString ows = new OWString(str); return(ows); }