public static bool FileExists(string filename) { if (string.IsNullOrEmpty(filename)) { return(false); } return(cascHandler.FileExists(filename)); }
protected override void LoadCoreStormMod() { SetCorrectFileCasing(); if (LoadXmlFilesEnabled) { // core.stormmod xml files CASCFolder currentFolder = _cascFolderData.GetDirectory(Path.Combine(CoreBaseDataDirectoryPath, GameDataStringName)); foreach (KeyValuePair <string, ICASCEntry> file in currentFolder.Entries) { if (Path.GetExtension(file.Key) != ".xml") { continue; } string filePath = ((CASCFile)file.Value).FullName; if (!_cascHandlerData.FileExists(filePath)) { throw new FileNotFoundException(filePath); } using Stream stream = _cascHandlerData.OpenFile(filePath); if (XmlGameData.LastNode == null) { XmlGameData = XDocument.Load(stream); XmlFileCount++; if (IsCacheEnabled) { AddXmlCachedFilePath(filePath); } } else { LoadXmlFile(stream, filePath); } } } if (LoadTextFilesOnlyEnabled) { string filePath = Path.Combine(CoreLocalizedDataPath, GameStringFile); LoadTextFile(_cascHandlerData.OpenFile(filePath), filePath); } string fontStylesFilePath = Path.Combine(CoreBaseDataDirectoryPath, UIDirectoryStringName, FontStyleFile); if (LoadStormStyleEnabled) { LoadStormStyleFile(_cascHandlerData.OpenFile(fontStylesFilePath)); } if (IsCacheEnabled) { AddStormStyleCachedFilePath(fontStylesFilePath); } }
public static Stream OpenFile(uint fileDataId) { if (!Directory.Exists("Cache")) { Directory.CreateDirectory("Cache"); } if (File.Exists($"Cache/{fileDataId}")) { var stream = File.Open($"Cache/{fileDataId}", FileMode.Open, FileAccess.Read, FileShare.Read); return(stream); } else if (cascHandler.FileExists((int)fileDataId)) { var stream = cascHandler.OpenFile((int)fileDataId); var buffer = new byte[stream.Length]; // Read the data and save the file. stream.Read(buffer, 0, buffer.Length); File.WriteAllBytes($"Cache/{fileDataId}", buffer); stream.Position = 0; return(stream); } return(null); }
public static bool FileExists(string filename) { if (usingLocalAPI) { if (Client.GetStringAsync("http://" + CASCToolHostURL + "/casc/root/exists?buildconfig=" + BuildConfig + "&cdnconfig=" + CDNConfig + "&filename=" + filename).Result == "true") { return(true); } else { return(false); } } else { return(cascHandler.FileExists(filename)); } }
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 Stream OpenFile(uint fileDataId) { if (!cascHandler.FileExists((int)fileDataId)) { return(null); } var stream = cascHandler.OpenFile((int)fileDataId); return(stream); }
public static Boolean FileExists(string filename) { bool exists; if (usingCasc) { exists = cascHandler.FileExists(filename); } else { if (MainListFile.FindIndex(a => a.Contains(filename.ToLower())) != -1) //It returns -1 if the file is not found { exists = true; } else { exists = false; } } return(exists); }
protected bool FileExists(string filePath) { if (StorageMode == StorageMode.CASC) { return(CASCHandler.FileExists(filePath)); } else if (StorageMode == StorageMode.Mods) { return(File.Exists(Path.Combine(ModsFolderPath, filePath.Substring(5)))); } else { return(false); } }
/// <summary> /// Open a new <see cref="BinaryReader"/> instance with the given FileId. /// </summary> public static BinaryReader OpenFile(uint fileDataId) { if (!NewStorage.FileExists((int)fileDataId)) { return(null); } var stream = NewStorage.OpenFile((int)fileDataId); if (stream == null) { return(null); } return(new BinaryReader(stream)); }
private void ExtractFiles(IEnumerable <string> files, int amount, string fileType) { if (_cascHotsStorage?.CASCHandler == null || _cascHotsStorage.CASCFolderRoot == null) { throw new NullReferenceException($"{nameof(_cascHotsStorage.CASCHandler)} and {nameof(_cascHotsStorage.CASCFolderRoot)} cannot be null"); } int count = 0; foreach (string filePath in files) { if (_cascHotsStorage !.CASCHandler.FileExists(filePath)) { _cascHotsStorage.CASCHandler.SaveFileTo(filePath.ToLowerInvariant(), _outputDirectory); count++; Console.Write($"\r{count,6}/{amount} {fileType}"); }
static void Main(string[] args) { string product = args[0]; var list = args.ToList(); list.RemoveAt(0); args = list.ToArray(); listfile = Toolbox.Listfile(); filelist = Toolbox.Filelist(wdt_from_list); listmap = Toolbox.Listmaps(); listarea = Toolbox.Listareas(); int[] arg_arr = listmap.Where(x => x.WdtFileDataID != 0).Select(x => x.WdtFileDataID).ToList().Union(wdt_from_list.Select(x => x.Value).ToList()).ToArray(); //int[] arg_arr = new int[1]; //arg_arr[0] = Convert.ToInt32(args[0]); Console.WriteLine("map count : " + arg_arr.Length); CASCHandler cs = CascConnect("offline", product); string output_dir = "../"; List <string> Maps = new List <string>(); var versionjson = output_dir + @"versions.json"; List <Toolbox.VersionDef> versions = new List <Toolbox.VersionDef>(); List <Toolbox.VersionDef> newVersions = GetNewVersions(cs, out versions, output_dir, product, arg_arr); /* DEBUG */ /*Toolbox.VersionDef Debug = new Toolbox.VersionDef(); * Debug.map = new Toolbox.MapDef(); * Debug.map.WdtFileDataID = Convert.ToInt32(args[0]); * Debug.map.MapName_lang = "debug"; * newVersions.Add(Debug);*/ /*foreach(int i in arg_arr){ * Toolbox.VersionDef Debug = new Toolbox.VersionDef(); * Debug.map = new Toolbox.MapDef(); * Debug.map.WdtFileDataID = i; * Debug.map.MapName_lang = ""+i; * newVersions.Add(Debug); * }*/ foreach (Toolbox.VersionDef ver in newVersions) { if (cs.FileExists(ver.map.WdtFileDataID)) { IG_Obj.Clear(); Wdt wdt = new Wdt(ver.map.WdtFileDataID, cs, listfile, filelist, IG_Obj); Console.WriteLine("---- parsing " + ver.map.MapName_lang); string map_dir = output_dir + wdt.wdt_id + "/" + version_build; /* if (Directory.Exists(map_dir)) * Directory.Delete(map_dir, true);*/ Directory.CreateDirectory(map_dir); Adt[,] adts = new Adt[64, 64]; ObjAdt[,] obj0 = new ObjAdt[64, 64]; ObjAdt[,] obj1 = new ObjAdt[64, 64]; Dictionary <int, List <Toolbox.Area> > Areas = new Dictionary <int, List <Toolbox.Area> >(); wdt.LoadExtra(); if ((wdt.wmo_only == true) && (wdt.found_unref == false)) { Mapper.Make_Models(map_dir, wdt, adts, obj0, obj1); } else { for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { adts[i, j] = new Adt(cs, i, j, listfile, listarea, filelist); adts[i, j].Parse((int)wdt.maid_chunk.root[i, j], IG_Obj); foreach (Toolbox.Area area in adts[i, j].areas) { if (!Areas.ContainsKey(area.ID)) { Areas.Add(area.ID, new List <Toolbox.Area>()); } Areas[area.ID].Add(area); } obj0[i, j] = new ObjAdt(cs, i, j, listfile, filelist); obj0[i, j].Parse((int)wdt.maid_chunk.obj0[i, j], IG_Obj); obj1[i, j] = new ObjAdt(cs, i, j, listfile, filelist); obj1[i, j].Parse((int)wdt.maid_chunk.obj1[i, j], IG_Obj); Mapper.CreateModelsJson(IG_Obj, map_dir, wdt, i, j); IG_Obj.Clear(); } } Mapper.Make_ZoomMap(wdt, map_dir, cs); if ((wdt.size_x >= 0) && (wdt.size_y >= 0)) { Console.WriteLine(wdt.size_x + " / " + wdt.size_y + " / native " + wdt.minNative); Mapper.Make_UnrefMap(map_dir, wdt.unref, wdt); Mapper.Make_ImpassMap(map_dir, adts, wdt); Mapper.Make_UnknownMap(map_dir, adts, wdt); Mapper.Make_AreaMap(map_dir, Areas, wdt); Mapper.Make_WdtBorders(map_dir, wdt); Mapper.Make_DeathMap(map_dir, adts, wdt); } string wdt_info = "{\"min_x\":\"" + wdt.min_x + "\",\"min_y\":\"" + wdt.min_y + "\",\"size_x\":\"" + wdt.size_x + "\",\"size_y\":\"" + wdt.size_y + "\",\"NativeZoom\":\"" + wdt.minNative + "\"}"; File.WriteAllText(map_dir + "/wdt_info.json", wdt_info); } if ((wdt.size_x < 0) && (wdt.size_y < 0) && (wdt.wmo_only == false)) { Console.WriteLine("bad wdt removing " + ver.map.WdtFileDataID); versions.Remove(ver); } else { Console.WriteLine("Added " + ver.map.WdtFileDataID + " to versions.json"); List <Toolbox.VersionDef> during = new List <Toolbox.VersionDef>(); var duringfile = output_dir + @"versions.json"; using (StreamReader r = new StreamReader(duringfile)) { string jsonduring = r.ReadToEnd(); during = JsonConvert.DeserializeObject <List <Toolbox.VersionDef> >(jsonduring); } during.Add(ver); string jsonduringout = JsonConvert.SerializeObject(during.ToArray()); System.IO.File.WriteAllText(duringfile, jsonduringout); } } else { Console.WriteLine("removing " + ver.map.WdtFileDataID); versions.Remove(ver); } } /* string jsonverout = JsonConvert.SerializeObject(versions.ToArray()); * System.IO.File.WriteAllText(versionjson, jsonverout);*/ }
public static void Make_ZoomMap(Wdt map, string base_dir, CASCHandler cs) { string zoom_fullmap = base_dir + "/map_zoom.png"; Console.WriteLine("Making zoom map:"); for (var cur_x = 0; cur_x < 64; cur_x++) { for (var cur_y = 0; cur_y < 64; cur_y++) { if (map.all_claimed_tiles[cur_x, cur_y] == true) { //Console.WriteLine("exists " + cur_x + " /" + cur_y); if (cur_x < map.min_y) { map.min_y = cur_x; } if (cur_y < map.min_x) { map.min_x = cur_y; } if (cur_x > map.max_y) { map.max_y = cur_x; } if (cur_y > map.max_x) { map.max_x = cur_y; } } } } Console.WriteLine("minx " + map.min_x + " / miny " + map.min_y); Console.WriteLine("maxx " + map.max_x + " / maxy " + map.max_y); map.size_x = map.max_x - map.min_x + 1; map.size_y = map.max_y - map.min_y + 1; var canvas = NetVips.Image.Black(1, 1); for (var cur_x = 0; cur_x < 64; cur_x++) { for (var cur_y = 0; cur_y < 64; cur_y++) { using (var stream = new MemoryStream()) { var minit = map.maid_chunk.minit[cur_x, cur_y]; if ((minit != 0) && cs.FileExists((int)minit)) { using (var stream2 = new MemoryStream()) { new BlpFile(cs.OpenFile((int)minit)).GetBitmap(0).Save(stream2, System.Drawing.Imaging.ImageFormat.Png); var image = NetVips.Image.NewFromBuffer(stream2.ToArray()); if (image.Width != Toolbox.tile_size) { if (Toolbox.tile_size == 512 && image.Width == 256) { image = image.Resize(2, "VIPS_KERNEL_NEAREST"); } else if (Toolbox.tile_size == 256 && image.Width == 512) { image = image.Resize(0.5, "VIPS_KERNEL_NEAREST"); } } //Console.WriteLine("writing at : " + cur_y +" - " + map.min_y + " = " + (cur_y - map.min_y) + " | " +cur_x +" - " + map.min_x + " = " + (cur_x - map.min_x)); canvas = canvas.Insert(image, (cur_y - map.min_y) * Toolbox.tile_size, (cur_x - map.min_x) * Toolbox.tile_size, true); } } } } } Console.WriteLine("writing zoom map"); canvas.WriteToFile(zoom_fullmap); CutZoomMap(map, zoom_fullmap, base_dir + "/zoom_tiles", 10); }
public void Parse(int adt_name, Dictionary <uint, List <Toolbox.IngameObject> > IG_Obj) { if ((adt_name > 0) && cs.FileExists(adt_name)) { //Console.WriteLine("parsing " + adt_name + " : " +x + " / " + y); using (Stream stream = cs.OpenFile(adt_name)) { using (BinaryReader reader = new BinaryReader(stream)) { while (reader.BaseStream.Position != reader.BaseStream.Length) { var magic = reader.ReadUInt32(); var size = reader.ReadUInt32(); var pos = reader.BaseStream.Position; if (magic == Toolbox.mk("MFBO")) { plane_max.a = new short[3]; plane_max.a[0] = reader.ReadInt16(); plane_max.a[1] = reader.ReadInt16(); plane_max.a[2] = reader.ReadInt16(); plane_max.b = new short[3]; plane_max.b[0] = reader.ReadInt16(); plane_max.b[1] = reader.ReadInt16(); plane_max.b[2] = reader.ReadInt16(); plane_max.c = new short[3]; plane_max.c[0] = reader.ReadInt16(); plane_max.c[1] = reader.ReadInt16(); plane_max.c[2] = reader.ReadInt16(); plane_min.a = new short[3]; plane_min.a[0] = reader.ReadInt16(); plane_min.a[1] = reader.ReadInt16(); plane_min.a[2] = reader.ReadInt16(); plane_min.b = new short[3]; plane_min.b[0] = reader.ReadInt16(); plane_min.b[1] = reader.ReadInt16(); plane_min.b[2] = reader.ReadInt16(); plane_min.c = new short[3]; plane_min.c[0] = reader.ReadInt16(); plane_min.c[1] = reader.ReadInt16(); plane_min.c[2] = reader.ReadInt16(); } if (magic == Toolbox.mk("MCNK")) { var flags = reader.ReadUInt32(); var sub_x = reader.ReadUInt32(); var sub_y = reader.ReadUInt32(); var nLayers = reader.ReadUInt32(); var nDoodadRefs = reader.ReadUInt32(); var holes_high_res = reader.ReadUInt64(); var ofsLayer = reader.ReadUInt32(); var ofsRefs = reader.ReadUInt32(); var ofsAlpha = reader.ReadUInt32(); var sizeAlpha = reader.ReadUInt32(); var ofsShadow = reader.ReadUInt32(); var sizeShadow = reader.ReadUInt32(); var areaid = reader.ReadUInt32(); impasses[sub_x, sub_y] = -1; if (areaid == 0) { unknown[sub_x, sub_y] = 1; } else { Toolbox.CsvArea csvdefault = CsvAreas.Find(e => e.ID == (int)areaid); Toolbox.Area area = new Toolbox.Area(); area.x = x; area.y = y; area.sub_x = sub_x; area.sub_y = sub_y; area.ID = (int)areaid; if (csvdefault != null) { area.ZoneName = csvdefault.ZoneName; area.AreaName_lang = csvdefault.AreaName_lang; area.ContinentID = csvdefault.ContinentID; } areas.Add(area); } if ((flags & 2) == 2) { impasses[sub_x, sub_y] = 1; } } if (magic == Toolbox.mk("MWMO")) // wmo filenames { char c; int i = (int)size; while (i > 0) { StringBuilder sb = new StringBuilder(); while ((c = Convert.ToChar(reader.ReadByte())) != '\0') { sb.Append(c); i--; } i--; if (!filenameswmo.Contains(sb.ToString())) { filenameswmo.Add(sb.ToString()); } } } if (magic == Toolbox.mk("MMDX")) // m2 filenames { char c; int i = (int)size; while (i > 0) { StringBuilder sb = new StringBuilder(); while ((c = Convert.ToChar(reader.ReadByte())) != '\0') { sb.Append(c); i--; } i--; if (!filenamesm2.Contains(sb.ToString())) { filenamesm2.Add(sb.ToString()); } } } if (magic == Toolbox.mk("MMID")) // m2 offset names { while (reader.BaseStream.Position < pos + size) { mmid.Add(reader.ReadUInt32()); } } if (magic == Toolbox.mk("MWID")) // wmo offset names { while (reader.BaseStream.Position < pos + size) { mwid.Add(reader.ReadUInt32()); } } if (magic == Toolbox.mk("MODF")) // placement WMO { while (reader.BaseStream.Position < pos + size) { objects.Add(Toolbox.MakeObject(reader, 0, listfile, x, y, mwid, filenameswmo, filelist, IG_Obj)); } } if (magic == Toolbox.mk("MDDF")) // placement m2 { while (reader.BaseStream.Position < pos + size) { objects.Add(Toolbox.MakeObject(reader, 1, listfile, x, y, mmid, filenamesm2, filelist, IG_Obj)); } } reader.BaseStream.Position = pos + size; } } } adt_claims_tile = true; } }
/*public static bool ExtractFile(string from, string to) * { * try * { * CASC.SaveFileTo(from, to, locale); * return true; * } * catch * { * return false; * } * }*/ public static bool FileExists(string path) { return(_casc.FileExists(path)); }
public void Parse(int adt_name, Dictionary <uint, List <Toolbox.IngameObject> > IG_Obj) { if ((adt_name > 0) && cs.FileExists(adt_name)) { using (Stream stream = cs.OpenFile(adt_name)) { using (BinaryReader reader = new BinaryReader(stream)) { while (reader.BaseStream.Position != reader.BaseStream.Length) { var magic = reader.ReadUInt32(); var size = reader.ReadUInt32(); var pos = reader.BaseStream.Position; if (magic == Toolbox.mk("MWMO")) // wmo filenames { char c; int i = (int)size; while (i > 0) { StringBuilder sb = new StringBuilder(); while ((c = Convert.ToChar(reader.ReadByte())) != '\0') { sb.Append(c); i--; } i--; if (!filenameswmo.Contains(sb.ToString())) { filenameswmo.Add(sb.ToString()); } } } if (magic == Toolbox.mk("MMDX")) // m2 filenames { char c; int i = (int)size; while (i > 0) { StringBuilder sb = new StringBuilder(); while ((c = Convert.ToChar(reader.ReadByte())) != '\0') { sb.Append(c); i--; } i--; if (!filenamesm2.Contains(sb.ToString())) { filenamesm2.Add(sb.ToString()); } } } if (magic == Toolbox.mk("MMID")) // m2 offset names { while (reader.BaseStream.Position < pos + size) { mmid.Add(reader.ReadUInt32()); } } if (magic == Toolbox.mk("MWID")) // wmo offset names { while (reader.BaseStream.Position < pos + size) { mwid.Add(reader.ReadUInt32()); } } if (magic == Toolbox.mk("MODF")) // placement WMO { while (reader.BaseStream.Position < pos + size) { objects.Add(Toolbox.MakeObject(reader, 0, listfile, x, y, mwid, filenameswmo, filelist, IG_Obj)); } } if (magic == Toolbox.mk("MDDF")) // placement m2 { while (reader.BaseStream.Position < pos + size) { objects.Add(Toolbox.MakeObject(reader, 1, listfile, x, y, mmid, filenamesm2, filelist, IG_Obj)); } } reader.BaseStream.Position = pos + size; } } } obj_claims_tile = true; } }