private void HandleItemCategory(WzDirectory pDir) { string tmp = exDir; exDir += Path.DirectorySeparatorChar + pDir.Name; // Etc foreach (var collection in pDir.GetChildImages()) // 0400.img { exDir += Path.DirectorySeparatorChar + collection.Name; bool isNebuliteDir = collection.Name == "0306.img"; foreach (var item in collection.WzProperties.Where(p => { return p is WzSubProperty; })) // 04000000 { exDir += Path.DirectorySeparatorChar + item.Name + Path.DirectorySeparatorChar; currentID = Convert.ToInt32(item.Name); if (item["info"] != null) { ExportIfExists(exDir, item["info"]["icon"], "info"); ExportIfExists(exDir, item["info"]["iconRaw"], "info"); ExportIfExists(exDir, item["info"]["iconD"], "info"); ExportIfExists(exDir, item["info"]["iconRawD"], "info"); ItemInformation.Instance.HandleInfo(currentID, item["info"].ToSubProperty()); } if (item["spec"] != null) { if (item["spec"]["slotCount"] != null) SQLStrings.Instance.AppendRow("item_spec", currentID, "slotcount", item["spec"]["slotCount"].ToInt().ToString()); if (item["spec"]["slotPerLine"] != null) SQLStrings.Instance.AppendRow("item_spec", currentID, "slotperline", item["spec"]["slotPerLine"].ToInt().ToString()); if (item["spec"]["type"] != null) SQLStrings.Instance.AppendRow("item_spec", currentID, "type", item["spec"]["type"].ToInt().ToString()); } if (item["effect"] != null) { foreach (var stance in CharacterExtractor.STANCES) if (item["effect"][stance] != null) HandleHairStyle(exDir, item["effect"][stance].ToSubProperty(), "effect." + stance); } if (isNebuliteDir && item["socket"] != null) { // Extract moar options string description = item["socket"]["string"] != null ? item["socket"]["string"].ToStringValue() : ""; string optionlist = ""; foreach (var option in item["socket"]["option"].WzProperties) { if (optionlist != "") optionlist += ';'; optionlist += option["optionString"].ToStringValue() + '=' + option["level"].ToInt(); } SqlFileItemSocket.Instance.AppendRow(currentID, description, optionlist); } exDir = RemoveFromBackDirSlash(exDir); exDir = RemoveFromBackDirSlash(exDir); } exDir = RemoveFromBackDirSlash(exDir); } exDir = RemoveFromBackDirSlash(exDir); }
public void PrepareAllImgs(WzDirectory dir) { foreach (WzImage img in dir.WzImages) img.Changed = true; foreach (WzDirectory subdir in dir.WzDirectories) PrepareAllImgs(subdir); }
public WzFile(short gameVersion, WzMapleVersion version) { wzDir = new WzDirectory(); this.Header = WzHeader.GetDefault(); fileVersion = gameVersion; mapleVersion = version; WzIv = WzTool.GetIvByMapleVersion(version); wzDir.WzIv = WzIv; }
public void parseDir(WzDirectory dir) { deep++; makeRealDir(); string tempDir = currentDir; Form1.Instance.BeginInvoke((MethodInvoker)delegate { Form1.Instance.progress.Maximum += dir.WzDirectories.Length; }); foreach (WzDirectory dirInDir in dir.WzDirectories) { Form1.Instance.BeginInvoke((MethodInvoker)delegate { Form1.Instance.progress.Value++; }); currentDir += dirInDir.Name + "\\"; parseDir(dirInDir); currentDir = tempDir; } Form1.Instance.BeginInvoke((MethodInvoker)delegate { Form1.Instance.progress.Maximum += dir.WzImages.Length; }); foreach (WzImage img in dir.WzImages) { Form1.Instance.BeginInvoke((MethodInvoker)delegate { Form1.Instance.progress.Value++; }); currentDir += img.Name + "\\"; parseImage(img); currentDir = tempDir; } deep--; }
/// <summary> /// Removes a sub directory from the list /// </summary> /// <param name="name">The sub directory to remove</param> public void RemoveDirectory(WzDirectory dir) { subDirs.Remove(dir); dir.Parent = null; }
/// <summary> /// Adds a WzDirectory to the list of sub directories /// </summary> /// <param name="dir">The WzDirectory to add</param> public void AddDirectory(WzDirectory dir) { subDirs.Add(dir); dir.wzFile = wzFile; dir.Parent = this; }
private void InsertImage() { if (board.MapInfo.mapType == MapType.RegularMap) { string cat = "Map" + image.Name.Substring(0, 1); WzDirectory mapDir = (WzDirectory)Program.WzManager["map"]["Map"]; WzDirectory catDir = (WzDirectory)mapDir[cat]; if (catDir == null) { catDir = new WzDirectory(cat); mapDir.AddDirectory(catDir); } WzImage mapImg = (WzImage)catDir[image.Name]; if (mapImg != null) { mapImg.Remove(); } catDir.AddImage(image); Program.WzManager.SetUpdated("map", image); } else { WzDirectory mapDir = (WzDirectory)Program.WzManager["ui"]; WzImage mapImg = (WzImage)mapDir[image.Name]; if (mapImg != null) { mapImg.Remove(); } mapDir.AddImage(image); Program.WzManager.SetUpdated("ui", image); } }
/// <summary> /// Parses the WzDirectory /// </summary> internal void ParseDirectory() { int entryCount = reader.ReadCompressedInt(); for (int i = 0; i < entryCount; i++) { byte type = reader.ReadByte(); string fname = null; int fsize; int checksum; uint offset; long rememberPos = 0; if (type == 1) //01 XX 00 00 00 00 00 OFFSET (4 bytes) { int unknown = reader.ReadInt32(); reader.ReadInt16(); uint offs = reader.ReadOffset(); continue; } else if (type == 2) { int stringOffset = reader.ReadInt32(); rememberPos = reader.BaseStream.Position; reader.BaseStream.Position = reader.Header.FStart + stringOffset; type = reader.ReadByte(); fname = reader.ReadString(); } else if (type == 3 || type == 4) { fname = reader.ReadString(); rememberPos = reader.BaseStream.Position; } else { } reader.BaseStream.Position = rememberPos; fsize = reader.ReadCompressedInt(); checksum = reader.ReadCompressedInt(); offset = reader.ReadOffset(); if (type == 3) { WzDirectory subDir = new WzDirectory(reader, fname, hash, WzIv, wzFile); subDir.BlockSize = fsize; subDir.Checksum = checksum; subDir.Offset = offset; subDir.Parent = this; subDirs.Add(subDir); } else { WzImage img = new WzImage(fname, reader); img.BlockSize = fsize; img.Checksum = checksum; img.Offset = offset; img.Parent = this; images.Add(img); } } foreach (WzDirectory subdir in subDirs) { reader.BaseStream.Position = subdir.offset; subdir.ParseDirectory(); } }
public IWzObject[] GetObjectsFromDirectory(WzDirectory dir) { List<IWzObject> objList = new List<IWzObject>(); foreach (WzImage img in dir.WzImages) { objList.Add(img); objList.AddRange(GetObjectsFromImage(img)); } foreach (WzDirectory subdir in dir.WzDirectories) { objList.Add(subdir); objList.AddRange(GetObjectsFromDirectory(subdir)); } return objList.ToArray(); }
/// <summary> /// Removes a sub directory from the list /// </summary> /// <param name="dir">The sub directory to remove</param> public void RemoveDirectory(WzDirectory dir) { WzDirectories.Remove(dir); dir.Parent = null; }
/// <summary> /// Adds a WzDirectory to the list of sub directories /// </summary> /// <param name="dir">The WzDirectory to add</param> public void AddDirectory(WzDirectory dir) { WzDirectories.Add(dir); dir._wzFile = _wzFile; dir.Parent = this; }
/// <summary> /// Parses the WzDirectory /// </summary> internal void ParseDirectory() { var entryCount = _reader.ReadCompressedInt(); for (var i = 0; i < entryCount; i++) { var type = _reader.ReadByte(); string fname = null; long rememberPos = 0; switch (type) { case 1: var unknown = _reader.ReadInt32(); _reader.ReadInt16(); var offs = _reader.ReadOffset(); continue; case 2: var stringOffset = _reader.ReadInt32(); rememberPos = _reader.BaseStream.Position; _reader.BaseStream.Position = _reader.Header.FStart + stringOffset; type = _reader.ReadByte(); fname = _reader.ReadString(); break; case 3: case 4: fname = _reader.ReadString(); rememberPos = _reader.BaseStream.Position; break; } _reader.BaseStream.Position = rememberPos; var fsize = _reader.ReadCompressedInt(); var dirChecksum = _reader.ReadCompressedInt(); var dirOffset = _reader.ReadOffset(); if (type == 3) { var subDir = new WzDirectory(_reader, fname, _hash, WzIv, _wzFile) { BlockSize = fsize, Checksum = dirChecksum, Offset = dirOffset, Parent = this }; WzDirectories.Add(subDir); } else { var img = new WzImage(fname, _reader) { BlockSize = fsize, Checksum = dirChecksum, Offset = dirOffset, Parent = this }; WzImages.Add(img); } } foreach (var subdir in WzDirectories) { _reader.BaseStream.Position = subdir.Offset; subdir.ParseDirectory(); } }
/// <summary> /// Parse directories in the WZ file /// </summary> /// <param name="parseErrorMessage"></param> /// <param name="lazyParse">Only load the firt WzDirectory found if true</param> /// <returns></returns> internal WzFileParseStatus ParseMainWzDirectory(bool lazyParse = false) { if (this.path == null) { Helpers.ErrorLogger.Log(Helpers.ErrorLevel.Critical, "[Error] Path is null"); return(WzFileParseStatus.Path_Is_Null); } WzBinaryReader reader = new WzBinaryReader(File.Open(this.path, FileMode.Open, FileAccess.Read, FileShare.Read), WzIv); this.Header = new WzHeader(); this.Header.Ident = reader.ReadString(4); this.Header.FSize = reader.ReadUInt64(); this.Header.FStart = reader.ReadUInt32(); this.Header.Copyright = reader.ReadString((int)(Header.FStart - 17U)); reader.ReadBytes(1); reader.ReadBytes((int)(Header.FStart - (ulong)reader.BaseStream.Position)); reader.Header = this.Header; this.version = reader.ReadInt16(); if (mapleStoryPatchVersion == -1) { const short MAX_PATCH_VERSION = 10000; // wont be reached for the forseeable future. for (int j = 0; j < MAX_PATCH_VERSION; j++) { this.mapleStoryPatchVersion = (short)j; this.versionHash = CheckAndGetVersionHash(version, mapleStoryPatchVersion); if (this.versionHash == 0) // ugly hack, but that's the only way if the version number isnt known (nexon stores this in the .exe) { continue; } reader.Hash = this.versionHash; long position = reader.BaseStream.Position; // save position to rollback to, if should parsing fail from here WzDirectory testDirectory; try { testDirectory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv, this); testDirectory.ParseDirectory(lazyParse); } catch (Exception exp) { Debug.WriteLine(exp.ToString()); reader.BaseStream.Position = position; continue; } try { List <WzImage> childImages = testDirectory.GetChildImages(); if (childImages.Count == 0) // coincidentally in msea v194 Map001.wz, the hash matches exactly using mapleStoryPatchVersion of 113, and it fails to decrypt later on (probably 1 in a million chance). { reader.BaseStream.Position = position; // reset continue; } WzImage testImage = childImages[0]; try { reader.BaseStream.Position = testImage.Offset; byte checkByte = reader.ReadByte(); reader.BaseStream.Position = position; switch (checkByte) { case 0x73: case 0x1b: { WzDirectory directory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv, this); directory.ParseDirectory(lazyParse); this.wzDir = directory; return(WzFileParseStatus.Success); } case 0x30: case 0x6C: // idk case 0xBC: // Map002.wz? KMST? default: { Helpers.ErrorLogger.Log(Helpers.ErrorLevel.MissingFeature, string.Format("[WzFile.cs] New Wz image header found. checkByte = {0}. File Name = {1}", checkByte, Name)); // log or something break; } } reader.BaseStream.Position = position; // reset } catch { reader.BaseStream.Position = position; // reset } } finally { testDirectory.Dispose(); } } //parseErrorMessage = "Error with game version hash : The specified game version is incorrect and WzLib was unable to determine the version itself"; return(WzFileParseStatus.Error_Game_Ver_Hash); } else { this.versionHash = CheckAndGetVersionHash(version, mapleStoryPatchVersion); reader.Hash = this.versionHash; WzDirectory directory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv, this); directory.ParseDirectory(); this.wzDir = directory; } return(WzFileParseStatus.Success); }
internal void ParseMainWzDirectory() { if (this.path == null) { Helpers.ErrorLogger.Log(Helpers.ErrorLevel.Critical, "[Error] Path is null"); return; } WzBinaryReader reader = new WzBinaryReader(File.Open(this.path, FileMode.Open, FileAccess.Read, FileShare.Read), WzIv); this.Header = new WzHeader(); this.Header.Ident = reader.ReadString(4); this.Header.FSize = reader.ReadUInt64(); this.Header.FStart = reader.ReadUInt32(); this.Header.Copyright = reader.ReadNullTerminatedString(); reader.ReadBytes((int)(Header.FStart - reader.BaseStream.Position)); reader.Header = this.Header; this.version = reader.ReadInt16(); if (fileVersion == -1) { for (int j = 0; j < short.MaxValue; j++) { this.fileVersion = (short)j; this.versionHash = GetVersionHash(version, fileVersion); if (this.versionHash != 0) { reader.Hash = this.versionHash; long position = reader.BaseStream.Position; WzDirectory testDirectory = null; try { testDirectory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv, this); testDirectory.ParseDirectory(); } catch { reader.BaseStream.Position = position; continue; } WzImage testImage = testDirectory.GetChildImages()[0]; try { reader.BaseStream.Position = testImage.Offset; byte checkByte = reader.ReadByte(); reader.BaseStream.Position = position; testDirectory.Dispose(); switch (checkByte) { case 0x73: case 0x1b: { WzDirectory directory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv, this); directory.ParseDirectory(); this.wzDir = directory; return; } } reader.BaseStream.Position = position; } catch { reader.BaseStream.Position = position; } } } throw new Exception("Error with game version hash : The specified game version is incorrect and WzLib was unable to determine the version itself"); } else { this.versionHash = GetVersionHash(version, fileVersion); reader.Hash = this.versionHash; WzDirectory directory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv, this); directory.ParseDirectory(); this.wzDir = directory; } }
private void HandlePets(WzDirectory pDir) { string tmp = exDir; exDir += Path.DirectorySeparatorChar + pDir.Name; // Pet foreach (var item in pDir.GetChildImages()) // 5000000.img { exDir += Path.DirectorySeparatorChar + item.Name + Path.DirectorySeparatorChar; int itemid = Convert.ToInt32(item.Name.Remove(item.Name.IndexOf('.'))); currentID = itemid; if (item["info"] != null) { ExportIfExists(exDir, item["info"]["icon"], "info"); ExportIfExists(exDir, item["info"]["iconRaw"], "info"); ExportIfExists(exDir, item["info"]["iconD"], "info"); // Dead pets ExportIfExists(exDir, item["info"]["iconRawD"], "info"); ItemInformation.Instance.HandleInfo(currentID, item["info"].ToSubProperty()); } if (item["stand0"] != null) { ExportIfExists(exDir, item["stand0"]["0"], "stand0"); SaveVector(item["stand0"]["0"]["origin"] as WzVectorProperty, "stand0.0"); } exDir = RemoveFromBackDirSlash(exDir); exDir = RemoveFromBackDirSlash(exDir); } exDir = RemoveFromBackDirSlash(exDir); }
/// <summary> /// Adds a WzDirectory to the list of sub directories /// </summary> /// <param name="dir">The WzDirectory to add</param> public void AddDirectory(WzDirectory dir) { subDirs.Add(dir); }
internal void ParseMainWzDirectory() { if (this.path == null) { Console.WriteLine("[Error] Path is null"); return; } WzBinaryReader reader = new WzBinaryReader(File.Open(this.path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), WzIv); this.Header = new WzHeader(); this.Header.Ident = reader.ReadString(4); this.Header.FSize = reader.ReadUInt64(); this.Header.FStart = reader.ReadUInt32(); this.Header.Copyright = reader.ReadNullTerminatedString(); reader.ReadBytes((int)(Header.FStart - reader.BaseStream.Position)); reader.Header = this.Header; this.version = reader.ReadInt16(); if (fileVersion == -1) { for (int j = 0; j < short.MaxValue; j++) { this.fileVersion = (short)j; this.versionHash = GetVersionHash(version, fileVersion); if (this.versionHash != 0) { reader.Hash = this.versionHash; long position = reader.BaseStream.Position; WzDirectory testDirectory = null; try { testDirectory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv); testDirectory.ParseDirectory(); } catch { reader.BaseStream.Position = position; continue; } WzImage testImage = testDirectory.GetChildImages()[0]; try { reader.BaseStream.Position = testImage.Offset; byte checkByte = reader.ReadByte(); reader.BaseStream.Position = position; testDirectory.Dispose(); switch (checkByte) { case 0x73: case 0x1b: { WzDirectory directory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv); directory.ParseDirectory(); this.wzDir = directory; return; } } reader.BaseStream.Position = position; } catch { reader.BaseStream.Position = position; } } } throw new Exception("Error with game version hash : The specified game version is incorrect and WzLib was unable to determine the version itself"); } else { this.versionHash = GetVersionHash(version, fileVersion); reader.Hash = this.versionHash; WzDirectory directory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv); directory.ParseDirectory(); this.wzDir = directory; } }
/*public void ReplaceObj(IWzObject obj, WzFile baseFile) { if (baseFile.GetObjectFromPath(obj.FullPath) == null) ReplaceObj(obj.Parent, baseFile); else { baseFile.GetObjectFromPath(obj.FullPath).Remove(); baseFile.GetObjectFromPath(obj.Parent.FullPath) } }*/ public void ReplaceDirs(WzDirectory parent, WzFile orignal) { string curVTxt = "(Current V" + Patcher_UserSettings.CurrentVersion + ")"; string slTxt = curVTxt + " Patching files..."; //AppendStatus("TEST"); //RefreshStuff(); foreach (WzDirectory dir in parent.WzDirectories) { if (orignal.GetObjectFromPath(dir.FullPath.Replace(@"\", "/")) == null) { /*AppendStatus("TEST1"); RefreshStuff(); MessageBox.Show("TEST1");*/ ((WzDirectory)orignal.GetObjectFromPath(dir.FullPath.Replace(@"\", "/"))).AddDirectory(dir); } if ((dir.WzDirectories.Count != 0) || (dir.WzImages.Count != 0)) { /*AppendStatus("TEST2"); RefreshStuff(); MessageBox.Show("TEST2");*/ ReplaceDirs(dir, orignal); } AppendStatus(slTxt + " [" + orignal.Name + "]" + " [" + ((WzDirectory)dir).Name + "]"); RefreshStuff(); } //if (parent.WzImages.Count <= 0) { MessageBox.Show("TEST4"); } if ((parent.WzImages != null) && (parent.WzImages.Count > 0)) { ProgressValue(0); ProgressStyle(ProgressBarStyle.Continuous); ProgressMax(parent.WzImages.Count); RefreshStuff(); } foreach (WzImage img in parent.WzImages) { /*AppendStatus("TEST5"); //THIS HAPPENS ON STRING.WZ BUT NOT CHARACTER.WZ RefreshStuff(); MessageBox.Show("TEST5");*/ if (orignal.GetObjectFromPath(img.FullPath.Replace(@"\", "/")) != null) { object Dir = orignal.GetObjectFromPath(img.FullPath.Replace(@"\", "/")).Parent; //is WzDirectory AppendStatus(slTxt + " [" + orignal.Name + "]" + " [" + ((WzDirectory)Dir).Name + "]" + " [" + ((WzImage)img).Name + "]"); RefreshStuff(); ((WzImage)orignal.GetObjectFromPath(img.FullPath.Replace(@"\", "/"))).Remove(); if (Dir is WzDirectory) { ((WzDirectory)Dir).AddImage(img); ((WzImage)((WzDirectory)Dir)[img.Name]).Changed = true; } else if (Dir is WzFile) { ((WzFile)Dir).WzDirectory.AddImage(img); ((WzImage)((WzFile)Dir).WzDirectory[img.Name]).Changed = true; } ProgressValue(); RefreshStuff(); } else { string path = img.Parent.FullPath.Replace(@"\", "/"); object dir = orignal.GetObjectFromPath(path); AppendStatus(slTxt + " [" + orignal.Name + "]" + " [" + ((WzDirectory)dir).Name + "]" + " [" + ((WzImage)img).Name + "]"); RefreshStuff(); if (dir is WzDirectory) { ((WzDirectory)dir).AddImage(img); ((WzImage)((WzDirectory)dir)[img.Name]).Changed = true; } else if (dir is WzFile) { ((WzFile)dir).WzDirectory.AddImage(img); ((WzImage)((WzFile)dir).WzDirectory[img.Name]).Changed = true; } ProgressValue(); RefreshStuff(); } } }
internal string[] GetPathsFromDirectory(WzDirectory dir, string curPath) { List<string> objList = new List<string>(); foreach (WzImage img in dir.WzImages) { objList.Add(curPath + "/" + img.Name); objList.AddRange(GetPathsFromImage(img, curPath + "/" + img.Name)); } foreach (WzDirectory subdir in dir.WzDirectories) { objList.Add(curPath + "/" + subdir.Name); objList.AddRange(GetPathsFromDirectory(subdir, curPath + "/" + subdir.Name)); } return objList.ToArray(); }
public WzMainDirectory(WzFile file) { this.file = file; this.directory = file.WzDirectory; }
public WzMainDirectory(WzFile file, WzDirectory directory) { this.file = file; this.directory = directory; }
/// <summary> /// Parses the WzDirectory /// <paramref name="lazyParse">Only parses the first directory</paramref> /// </summary> internal void ParseDirectory(bool lazyParse = false) { //Debug.WriteLine(HexTool.ToString( reader.ReadBytes(20))); //reader.BaseStream.Position = reader.BaseStream.Position - 20; long available = reader.Available(); if (available == 0) { return; } int entryCount = reader.ReadCompressedInt(); if (entryCount < 0 || entryCount > 100000) // probably nothing > 100k folders for now. { throw new Exception("Invalid wz version used for decryption, try parsing other version numbers."); } for (int i = 0; i < entryCount; i++) { byte type = reader.ReadByte(); string fname = null; int fsize; int checksum; uint offset; long rememberPos = 0; switch (type) { case 1: //01 XX 00 00 00 00 00 OFFSET (4 bytes) { int unknown = reader.ReadInt32(); reader.ReadInt16(); uint offs = reader.ReadOffset(); continue; } case 2: { int stringOffset = reader.ReadInt32(); rememberPos = reader.BaseStream.Position; reader.BaseStream.Position = reader.Header.FStart + stringOffset; type = reader.ReadByte(); fname = reader.ReadString(); break; } case 3: case 4: { fname = reader.ReadString(); rememberPos = reader.BaseStream.Position; break; } default: { throw new Exception("[WzDirectory] Unknown directory. type = " + type); } } reader.BaseStream.Position = rememberPos; fsize = reader.ReadCompressedInt(); checksum = reader.ReadCompressedInt(); offset = reader.ReadOffset(); if (type == 3) { WzDirectory subDir = new WzDirectory(reader, fname, hash, WzIv, wzFile) { BlockSize = fsize, Checksum = checksum, Offset = offset, Parent = this }; subDirs.Add(subDir); if (lazyParse) { break; } } else { WzImage img = new WzImage(fname, reader, checksum) { BlockSize = fsize, Offset = offset, Parent = this }; images.Add(img); if (lazyParse) { break; } } } foreach (WzDirectory subdir in subDirs) { if (subdir.Checksum != 0) { reader.BaseStream.Position = subdir.offset; subdir.ParseDirectory(); } } }