public static Byte[] GetFileBytesFromMpk(string mpk, string filename) { MPAK mpak = new MPAK(); mpak.Load(mpk); return(mpak.GetFile(filename).Data); }
public static StreamReader GetFileFromMpk(string mpk, string filename) { MPAK mpak = new MPAK(); mpak.Load(mpk); if (mpak.Files.Where(f => f.Name.ToLower() == filename.ToLower()).Count() > 0) { return new StreamReader(new MemoryStream(mpak.GetFile(filename).Data)); } return null; }
public static StreamReader GetFileFromMpk(string mpk, string filename) { MPAK mpak = new MPAK(); mpak.Load(mpk); if (mpak.Files.Where(f => f.Name.ToLower() == filename.ToLower()).Count() > 0) { return(new StreamReader(new MemoryStream(mpak.GetFile(filename).Data))); } return(null); }
/// <summary> /// Load the Polygons if the nifRows /// </summary> private static void LoadPolygons() { if (nifRows.Count() == 0 || fixtureRows.Count() == 0) { return; } // MainForm progress MainForm.Log("Loading polygons ...", MainForm.LogLevel.notice); MainForm.ProgressStart("Loading polygons ..."); DirectoryInfo polysDirectory = new DirectoryInfo(string.Format("{0}\\data\\polys", System.Windows.Forms.Application.StartupPath)); if (!polysDirectory.Exists) { polysDirectory.Create(); } string polysMpkFile = string.Format("{0}\\data\\polys.mpk", System.Windows.Forms.Application.StartupPath); MPAK polyMpk = new MPAK(); bool polyMpkModified = false; if (!File.Exists(polysMpkFile)) { polyMpkModified = true; // Create a new poyls.mpk } else { polyMpk.Load(polysMpkFile); // Load existing polys.mpk } // Loop all nifs from nifs.csv int progressCounter = 0; foreach (NifRow nifRow in nifRows) { // Check if this nif is a TreeCluster bool isTreeCluster = treeClusterRows.Any(tc => tc.Name.ToLower() == nifRow.Filename.ToLower()); if (isTreeCluster) { continue; } // The poly filename string modelPolyFileName = Path.GetFileNameWithoutExtension(nifRow.Filename) + ".poly"; string modelPolySavePath = string.Format("{0}\\{1}", polysDirectory, modelPolyFileName); // MPK handling, cache .poly file for models if (polyMpk.Files.Where(f => f.Name.ToLower() == modelPolyFileName.ToLower()).Count() == 0) { string nifArchivePath = FindNifArchive(nifRow); if (string.IsNullOrEmpty(nifArchivePath)) { continue; } // open the archive using (StreamReader nifFileFromNpk = MpkWrapper.GetFileFromMpk(nifArchivePath, nifRow.Filename)) { if (nifFileFromNpk != null) { MainForm.Log(string.Format("Processing {0}...", nifRow.TextualName), MainForm.LogLevel.notice); // Create a new poly and add to mpk polyMpkModified = true; NifParser nifParser = new NifParser(); nifParser.IsNodeDrawable += delegate(Niflib.NiAVObject node) { return(NifParser_IsNodeDrawable(nifRow, node)); }; nifParser.Load(nifFileFromNpk); nifParser.Convert(ConvertType.Poly, modelPolySavePath); // Add file to polys.mpk polyMpk.AddFile(modelPolySavePath); // Assign polys nifRow.Polygons = nifParser.GetPolys(); } } } else { // .poly file for model is found, read it nifRow.Polygons = NifParser.ReadPoly(new StreamReader(new MemoryStream(polyMpk.GetFile(modelPolyFileName).Data))); } int percent = 100 * progressCounter / nifRows.Count; MainForm.ProgressUpdate(percent); progressCounter++; } MainForm.ProgressStartMarquee("Saving polygons ..."); // Save the mpk if (polyMpkModified) { polyMpk.Save(polysMpkFile); } // Delete polys directory Directory.Delete(polysDirectory.FullName, true); MainForm.Log("Polygons loaded!", MainForm.LogLevel.success); MainForm.ProgressReset(); }
/// <summary> /// Gets zones from zones.dat /// </summary> /// <returns></returns> public static Dictionary<int, string> GetZones() { if (!CheckGamePath()) { return null; } Dictionary<int, string> zones = new Dictionary<int, string>(); string zonesMpk = string.Format("{0}\\zones\\zones.mpk", Properties.Settings.Default.game_path); MPAK mpak = new MPAK(); mpak.Load(zonesMpk); MPAKFileEntry zonesFile = mpak.GetFile("zones.dat"); using (Stream stream = new MemoryStream(zonesFile.Data)) { using (StreamReader reader = new StreamReader(stream)) { string row; bool recording = false; int current_zone = 0; string current_zone_name = ""; Match match; while ((row = reader.ReadLine()) != null) { if (string.IsNullOrEmpty(row.Trim())) continue; // Sections // ALBION if (row.StartsWith("[zone")) { recording = true; Regex regex = new Regex(@"\[zone(.*)\]", RegexOptions.IgnoreCase); if ((match = regex.Match(row)) != null) { current_zone = Convert.ToInt32(match.Groups[1].Value); } } if (recording && row.StartsWith("name=")) { Regex regex = new Regex(@"name=(.*)", RegexOptions.IgnoreCase); if ((match = regex.Match(row)) != null) { current_zone_name = match.Groups[1].Value; } } if (recording && current_zone > 0 && current_zone_name != "") { zones.Add(current_zone, current_zone_name); current_zone = 0; current_zone_name = ""; recording = false; } } } } return zones; }
public static Byte[] GetFileBytesFromMpk(string mpk, string filename) { MPAK mpak = new MPAK(); mpak.Load(mpk); return mpak.GetFile(filename).Data; }
/// <summary> /// Load the Polygons if the nifRows /// </summary> private static void LoadPolygons() { if (nifRows.Count() == 0 || fixtureRows.Count() == 0) return; // MainForm progress MainForm.Log("Loading polygons ...", MainForm.LogLevel.notice); MainForm.ProgressStart("Loading polygons ..."); DirectoryInfo polysDirectory = new DirectoryInfo(string.Format("{0}\\data\\polys", System.Windows.Forms.Application.StartupPath)); if (!polysDirectory.Exists) polysDirectory.Create(); string polysMpkFile = string.Format("{0}\\data\\polys.mpk", System.Windows.Forms.Application.StartupPath); MPAK polyMpk = new MPAK(); bool polyMpkModified = false; if (!File.Exists(polysMpkFile)) polyMpkModified = true; // Create a new poyls.mpk else polyMpk.Load(polysMpkFile); // Load existing polys.mpk // Loop all nifs from nifs.csv int progressCounter = 0; foreach (NifRow nifRow in nifRows) { // Check if this nif is a TreeCluster bool isTreeCluster = treeClusterRows.Any(tc => tc.Name.ToLower() == nifRow.Filename.ToLower()); if(isTreeCluster) continue; // The poly filename string modelPolyFileName = Path.GetFileNameWithoutExtension(nifRow.Filename) + ".poly"; string modelPolySavePath = string.Format("{0}\\{1}", polysDirectory, modelPolyFileName); // MPK handling, cache .poly file for models if (polyMpk.Files.Where(f => f.Name.ToLower() == modelPolyFileName.ToLower()).Count() == 0) { string nifArchivePath = FindNifArchive(nifRow); if(string.IsNullOrEmpty(nifArchivePath)) continue; // open the archive using (StreamReader nifFileFromNpk = MpkWrapper.GetFileFromMpk(nifArchivePath, nifRow.Filename)) { if (nifFileFromNpk != null) { MainForm.Log(string.Format("Processing {0}...", nifRow.TextualName), MainForm.LogLevel.notice); // Create a new poly and add to mpk polyMpkModified = true; NifParser nifParser = new NifParser(); nifParser.Load(nifFileFromNpk); nifParser.Convert(ConvertType.Poly, modelPolySavePath); // Add file to polys.mpk polyMpk.AddFile(modelPolySavePath); // Assign polys nifRow.Polygons = nifParser.GetPolys(); } } } else { // .poly file for model is found, read it nifRow.Polygons = NifParser.ReadPoly(new StreamReader(new MemoryStream(polyMpk.GetFile(modelPolyFileName).Data))); } int percent = 100 * progressCounter / nifRows.Count; MainForm.ProgressUpdate(percent); progressCounter++; } MainForm.ProgressStartMarquee("Saving polygons ..."); // Save the mpk if (polyMpkModified) { polyMpk.Save(polysMpkFile); } // Delete polys directory Directory.Delete(polysDirectory.FullName, true); MainForm.Log("Polygons loaded!", MainForm.LogLevel.success); MainForm.ProgressReset(); }
public MagickImage Draw() { MainForm.ProgressStart("Rendering background ..."); // Check which terrain file is used string texMpk = string.Format("{0}\\tex{1}.mpk", this.textureZoneDataDirectory, this.textureZoneId); string lodMpk = string.Format("{0}\\lod{1}.mpk", this.textureZoneDataDirectory, this.textureZoneId); // Get the tile dimension double tileWidth = 512.0; string tileTemplate = ""; MPAK mpak = new MPAK(); if (File.Exists(texMpk)) { mpak.Load(texMpk); if (mpak.Files.Where(f => f.Name.ToLower() == "tex00-00.dds").Count() > 0) { tileTemplate += "tex0{0}-0{1}.dds"; tileWidth = 512.0; } } if (string.IsNullOrEmpty(tileTemplate)) { mpak.Load(lodMpk); if (mpak.Files.Where(f => f.Name.ToLower() == "lod00-00.dds").Count() > 0) { tileTemplate += "lod0{0}-0{1}.dds"; tileWidth = 256.0; } } if (string.IsNullOrEmpty(tileTemplate)) { MainForm.Log(string.Format("Zone {0}: No background textures found!", zoneConfiguration.ZoneId), MainForm.LogLevel.error); return null; } // original size double orginalWidth = tileWidth * 8; double resizeFactor = (double)zoneConfiguration.TargetMapSize / (double)orginalWidth; // 0 - 1 MagickImage map = new MagickImage(Color.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize); int lastWidth = 0; int x = 0; for (int col = 0; col <= 7; col++) { int y = 0; for (int row = 0; row <= 7; row++) { string filename = string.Format(tileTemplate, col, row); using (MagickImage mapTile = new MagickImage(mpak.GetFile(filename).Data)) { int newSize = Convert.ToInt32(mapTile.Width * resizeFactor); mapTile.Resize(newSize, newSize); map.Composite(mapTile, x, y, CompositeOperator.SrcOver); // Calculate new y y += mapTile.Height; lastWidth = mapTile.Height; } } x += lastWidth; int percent = 100 * col / 8; MainForm.ProgressUpdate(percent); } MainForm.ProgressStartMarquee("Merging ..."); // Remove rounding fails map.Trim(); // Flip if set if (this.flipX) map.Flop(); if (this.flipY) map.Flip(); // Sharpen (tested a lot, seems to be the best values) map.Sharpen(4, 3); MainForm.ProgressReset(); return map; }
public MagickImage Draw() { MainForm.ProgressStart("Rendering background ..."); // Check which terrain file is used string texMpk = string.Format("{0}\\tex{1}.mpk", this.textureZoneDataDirectory, this.textureZoneId); string lodMpk = string.Format("{0}\\lod{1}.mpk", this.textureZoneDataDirectory, this.textureZoneId); // Get the tile dimension double tileWidth = 512.0; string tileTemplate = ""; MPAK mpak = new MPAK(); if (File.Exists(texMpk)) { mpak.Load(texMpk); if (mpak.Files.Where(f => f.Name.ToLower() == "tex00-00.dds").Count() > 0) { tileTemplate += "tex0{0}-0{1}.dds"; tileWidth = 512.0; } } if (string.IsNullOrEmpty(tileTemplate)) { mpak.Load(lodMpk); if (mpak.Files.Where(f => f.Name.ToLower() == "lod00-00.dds").Count() > 0) { tileTemplate += "lod0{0}-0{1}.dds"; tileWidth = 256.0; } } if (string.IsNullOrEmpty(tileTemplate)) { MainForm.Log(string.Format("Zone {0}: No background textures found!", zoneConfiguration.ZoneId), MainForm.LogLevel.error); return(null); } // original size double orginalWidth = tileWidth * 8; double resizeFactor = (double)zoneConfiguration.TargetMapSize / (double)orginalWidth; // 0 - 1 MagickImage map = new MagickImage(Color.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize); int lastWidth = 0; int x = 0; for (int col = 0; col <= 7; col++) { int y = 0; for (int row = 0; row <= 7; row++) { string filename = string.Format(tileTemplate, col, row); using (MagickImage mapTile = new MagickImage(mpak.GetFile(filename).Data)) { int newSize = Convert.ToInt32(mapTile.Width * resizeFactor); mapTile.Resize(newSize, newSize); map.Composite(mapTile, x, y, CompositeOperator.SrcOver); // Calculate new y y += mapTile.Height; lastWidth = mapTile.Height; } } x += lastWidth; int percent = 100 * col / 8; MainForm.ProgressUpdate(percent); } MainForm.ProgressStartMarquee("Merging ..."); // Remove rounding fails map.Trim(); // Flip if set if (this.flipX) { map.Flop(); } if (this.flipY) { map.Flip(); } // Sharpen (tested a lot, seems to be the best values) map.Sharpen(4, 3); MainForm.ProgressReset(); return(map); }
/// <summary> /// Gets zones from zones.dat /// </summary> /// <returns></returns> public static Dictionary <int, string> GetZones() { if (!CheckGamePath()) { return(null); } Dictionary <int, string> zones = new Dictionary <int, string>(); string zonesMpk = string.Format("{0}\\zones\\zones.mpk", Properties.Settings.Default.game_path); MPAK mpak = new MPAK(); mpak.Load(zonesMpk); MPAKFileEntry zonesFile = mpak.GetFile("zones.dat"); using (Stream stream = new MemoryStream(zonesFile.Data)) { using (StreamReader reader = new StreamReader(stream)) { string row; bool recording = false; int current_zone = 0; string current_zone_name = ""; Match match; while ((row = reader.ReadLine()) != null) { if (string.IsNullOrEmpty(row.Trim())) { continue; } // Sections // ALBION if (row.StartsWith("[zone")) { recording = true; Regex regex = new Regex(@"\[zone(.*)\]", RegexOptions.IgnoreCase); if ((match = regex.Match(row)) != null) { current_zone = Convert.ToInt32(match.Groups[1].Value); } } if (recording && row.StartsWith("name=")) { Regex regex = new Regex(@"name=(.*)", RegexOptions.IgnoreCase); if ((match = regex.Match(row)) != null) { current_zone_name = match.Groups[1].Value; } } if (recording && current_zone > 0 && current_zone_name != "") { zones.Add(current_zone, current_zone_name); current_zone = 0; current_zone_name = ""; recording = false; } } } } return(zones); }