public WzFile(short pGameVersion, WzMapleVersion pVersion) { Header = WzHeader.GetDefault(); mFileVersion = pGameVersion; mMapleVersion = pVersion; mWzIv = WzTool.GetIvByMapleVersion(pVersion); }
/// <summary> /// Open a wz list file from a file on the disk /// </summary> /// <param name="pFilePath">Path to the wz file</param> public WzListFile(string pFilePath, WzMapleVersion pVersion) { mName = Path.GetFileName(pFilePath); mWzIv = WzTool.GetIvByMapleVersion(pVersion); mVersion = pVersion; mWzFileBytes = File.ReadAllBytes(pFilePath); }
public WzImage WzImageFromIMGBytes(byte[] bytes, WzMapleVersion version, string name, bool freeResources) { byte[] iv = WzTool.GetIvByMapleVersion(version); MemoryStream stream = new MemoryStream(bytes); WzBinaryReader wzReader = new WzBinaryReader(stream, iv); WzImage img = new WzImage(name, wzReader); img.BlockSize = bytes.Length; img.Checksum = 0; foreach (byte b in bytes) { img.Checksum += b; } img.Offset = 0; if (freeResources) { img.ParseImage(true); img.Changed = true; wzReader.Close(); } return(img); }
/// <summary> /// Saves a wz file to the disk, AKA repacking. /// </summary> /// <param name="pPath">Path to the output wz file</param> public void SaveToDisk(string pPath) { mWzIv = WzTool.GetIvByMapleVersion(mMapleVersion); CreateVersionHash(); SetHash(mVersionHash); string tempFile = Path.GetFileNameWithoutExtension(pPath) + ".TEMP"; File.Create(tempFile).Close(); GenerateDataFile(tempFile); WzTool.StringCache.Clear(); uint totalLen = GetImgOffsets(GetOffsets(Header.FStart + 2)); WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(pPath), mWzIv) { Hash = mVersionHash }; Header.FSize = totalLen - Header.FStart; wzWriter.Write(Header.Ident, false); wzWriter.Write((long)Header.FSize); wzWriter.Write(Header.FStart); wzWriter.WriteNullTerminatedString(Header.Copyright); wzWriter.Write(new byte[Header.ExtraBytes]); wzWriter.Write(mVersion); wzWriter.Header = Header; SaveDirectory(wzWriter); wzWriter.StringCache.Clear(); FileStream fs = File.OpenRead(tempFile); SaveImages(wzWriter, fs); fs.Close(); File.Delete(tempFile); wzWriter.StringCache.Clear(); wzWriter.Close(); }
private void RunWzFilesExtraction(object param) { ChangeApplicationState(false); string[] wzFilesToDump = (string[])((object[])param)[0]; string baseDir = (string)((object[])param)[1]; WzMapleVersion version = (WzMapleVersion)((object[])param)[2]; IWzFileSerializer serializer = (IWzFileSerializer)((object[])param)[3]; UpdateProgressBar(MainPanel.mainProgressBar, 0, false, true); UpdateProgressBar(MainPanel.mainProgressBar, wzFilesToDump.Length, true, true); foreach (string wzpath in wzFilesToDump) { if (WzTool.IsListFile(wzpath)) { Warning.Error(string.Format(HaRepacker.Properties.Resources.MainListWzDetected, wzpath)); continue; } WzFile f = new WzFile(wzpath, version); f.ParseWzFile(); serializer.SerializeFile(f, Path.Combine(baseDir, f.Name)); f.Dispose(); UpdateProgressBar(MainPanel.mainProgressBar, 1, false, false); } threadDone = true; }
private void iMGToolStripMenuItem2_Click(object sender, EventArgs e) { if (MainPanel.DataTree.SelectedNode == null || (!(MainPanel.DataTree.SelectedNode.Tag is WzDirectory) && !(MainPanel.DataTree.SelectedNode.Tag is WzFile) && !(MainPanel.DataTree.SelectedNode.Tag is IPropertyContainer))) { return; } WzFile wzFile = ((WzObject)MainPanel.DataTree.SelectedNode.Tag).WzFileParent; if (!(wzFile is WzFile)) { return; } OpenFileDialog dialog = new OpenFileDialog() { Title = HaRepacker.Properties.Resources.SelectWzImg, Filter = string.Format("{0}|*.img", HaRepacker.Properties.Resources.WzImgFilter), Multiselect = true }; if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } byte[] iv = WzTool.GetIvByMapleVersion(wzFile.MapleVersion); WzImgDeserializer deserializer = new WzImgDeserializer(false); yesToAll = false; noToAll = false; threadDone = false; runningThread = new Thread(new ParameterizedThreadStart(WzImporterThread)); runningThread.Start(new object[] { deserializer, dialog.FileNames, MainPanel.DataTree.SelectedNode, iv }); new Thread(new ParameterizedThreadStart(ProgressBarThread)).Start(deserializer); }
/// <summary> /// Load a WZ file from path /// </summary> /// <param name="path"></param> /// <returns></returns> public WzFile LoadWzFile(string path) { short fileVersion = -1; bool isList = WzTool.IsListFile(path); return(LoadWzFile(path, WzTool.DetectMapleVersion(path, out fileVersion), fileVersion)); }
public WzFile(short gameVersion, WzMapleVersionType version) { Version = gameVersion; MapleVersionType = version; _wzIv = WzTool.GetIvByMapleVersion(version); WzDirectory.WzIv = _wzIv; }
public WzFile LoadWzFile(string path, HaRepackerMainPanel panel) { short fileVersion = -1; bool isList = WzTool.IsListFile(path); return(LoadWzFile(path, WzTool.DetectMapleVersion(path, out fileVersion), fileVersion, panel)); }
private void debugButton_Click(object sender, EventArgs e) { // This function iterates over all maps in the game and verifies that we recognize all their props // It is meant to use by the developer(s) to speed up the process of adjusting this program for different MapleStory versions string wzPath = pathBox.Text; short version = -1; WzMapleVersion fileVersion = WzTool.DetectMapleVersion(Path.Combine(wzPath, "Item.wz"), out version); InitializeWzFiles(wzPath, fileVersion); MultiBoard mb = new MultiBoard(); Board b = new Board(new Microsoft.Xna.Framework.Point(), new Microsoft.Xna.Framework.Point(), mb, null, MapleLib.WzLib.WzStructure.Data.ItemTypes.None, MapleLib.WzLib.WzStructure.Data.ItemTypes.None); foreach (string mapid in Program.InfoManager.Maps.Keys) { MapLoader loader = new MapLoader(); string mapcat = "Map" + mapid.Substring(0, 1); WzImage mapImage = null; foreach (var dir in Program.WzManager.GetDirsStartsWith("map")) { if (dir["Map"] != null && dir["Map"][mapcat] != null) { mapImage = (WzImage)dir["Map"][mapcat][mapid + ".img"]; } if (mapImage != null) { break; } } if (mapImage == null) { continue; } mapImage.ParseImage(); if (mapImage["info"]["link"] != null) { mapImage.UnparseImage(); continue; } loader.VerifyMapPropsKnown(mapImage, true); MapInfo info = new MapInfo(mapImage, null, null, null); loader.LoadMisc(mapImage, b); if (ErrorLogger.ErrorsPresent()) { ErrorLogger.SaveToFile("debug_errors.txt"); ErrorLogger.ClearErrors(); } mapImage.UnparseImage(); // To preserve memory, since this is a very memory intensive test } MessageBox.Show("Done"); }
/// <summary> /// Open a wz file from a file on the disk /// </summary> /// <param name="filePath">Path to the wz file</param> /// <param name="gameVersion"></param> /// <param name="version"></param> public WzFile(string filePath, short gameVersion, WzMapleVersionType version) { Name = Path.GetFileName(filePath); FilePath = filePath; Version = gameVersion; MapleVersionType = version; _wzIv = WzTool.GetIvByMapleVersion(version); }
/// <summary> /// Open a wz file from a file on the disk /// </summary> /// <param name="filePath">Path to the wz file</param> public WzFile(string filePath, WzMapleVersion version) { name = Path.GetFileName(filePath); path = filePath; fileVersion = -1; mapleVersion = version; WzIv = WzTool.GetIvByMapleVersion(version); }
/// <summary> /// Saves a wz file to the disk, AKA repacking. /// </summary> /// <param name="path">Path to the output wz file</param> public void SaveToDisk(string path, WzMapleVersion savingToPreferredWzVer = WzMapleVersion.UNKNOWN) { if (savingToPreferredWzVer == WzMapleVersion.UNKNOWN) { WzIv = WzTool.GetIvByMapleVersion(maplepLocalVersion); // get from local WzFile } else { WzIv = WzTool.GetIvByMapleVersion(savingToPreferredWzVer); // custom selected } wzDir.WzIv = WzIv; CreateVersionHash(); wzDir.SetHash(versionHash); string tempFile = Path.GetFileNameWithoutExtension(path) + ".TEMP"; File.Create(tempFile).Close(); wzDir.GenerateDataFile(tempFile, WzIv); WzTool.StringCache.Clear(); uint totalLen = wzDir.GetImgOffsets(wzDir.GetOffsets(Header.FStart + 2)); using (WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(path), WzIv)) { wzWriter.Hash = (uint)versionHash; Header.FSize = totalLen - Header.FStart; for (int i = 0; i < 4; i++) { wzWriter.Write((byte)Header.Ident[i]); } wzWriter.Write((long)Header.FSize); wzWriter.Write(Header.FStart); wzWriter.WriteNullTerminatedString(Header.Copyright); long extraHeaderLength = Header.FStart - wzWriter.BaseStream.Position; if (extraHeaderLength > 0) { wzWriter.Write(new byte[(int)extraHeaderLength]); } wzWriter.Write(version); wzWriter.Header = Header; wzDir.SaveDirectory(wzWriter); wzWriter.StringCache.Clear(); using (FileStream fs = File.OpenRead(tempFile)) { wzDir.SaveImages(wzWriter, fs); } File.Delete(tempFile); wzWriter.StringCache.Clear(); } GC.Collect(); GC.WaitForPendingFinalizers(); }
/// <summary> /// Initialize MapleStory WZ file /// </summary> /// <param name="gameVersion"></param> /// <param name="version"></param> public WzFile(short gameVersion, WzMapleVersion version) { wzDir = new WzDirectory(); this.Header = WzHeader.GetDefault(); mapleStoryPatchVersion = gameVersion; maplepLocalVersion = version; WzIv = WzTool.GetIvByMapleVersion(version); wzDir.WzIv = WzIv; }
public WzFile(short gameVersion, WzMapleVersion version) { WzDirectory = new WzDirectory(); Header = WzHeader.GetDefault(); FileVersion = gameVersion; MapleVersion = version; _wzIv = WzTool.GetIvByMapleVersion(version); WzDirectory.WzIv = _wzIv; }
internal void CompressPng(Bitmap bmp) { byte[] buf = new byte[bmp.Width * bmp.Height * 8]; format = 2; format2 = 0; width = bmp.Width; height = bmp.Height; //byte[] bmpBytes = bmp.BitmapToBytes(); /* if (SquishPNGWrapper.CheckAndLoadLibrary()) * { * byte[] bmpBytes = bmp.BitmapToBytes(); * SquishPNGWrapper.CompressImage(bmpBytes, width, height, buf, (int)SquishPNGWrapper.FlagsEnum.kDxt1); * } * else * {*/ int curPos = 0; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Color curPixel = bmp.GetPixel(j, i); buf[curPos] = curPixel.B; buf[curPos + 1] = curPixel.G; buf[curPos + 2] = curPixel.R; buf[curPos + 3] = curPixel.A; curPos += 4; } } compressedImageBytes = Compress(buf); buf = null; if (listWzUsed) { using (MemoryStream memStream = new MemoryStream()) { using (WzBinaryWriter writer = new WzBinaryWriter(memStream, WzTool.GetIvByMapleVersion(WzMapleVersion.GMS))) { writer.Write(2); for (int i = 0; i < 2; i++) { writer.Write((byte)(compressedImageBytes[i] ^ writer.WzKey[i])); } writer.Write(compressedImageBytes.Length - 2); for (int i = 2; i < compressedImageBytes.Length; i++) { writer.Write((byte)(compressedImageBytes[i] ^ writer.WzKey[i - 2])); } compressedImageBytes = memStream.GetBuffer(); } } } }
/// <summary> /// Begin loading WZ data corresponding to the selected tab /// </summary> private void BtnWzLoad_Click(object sender, EventArgs e) { string folderPath = TextWzPath.Text; if (folderPath.Length > 0) { if (!folderPath.Equals(Settings.Default.PathCache)) { Settings.Default.PathCache = folderPath; Settings.Default.Save(); } string stringWzPath = folderPath + @"/String"; WzMapleVersion mapleVersion; if (File.Exists(stringWzPath + Resources.FileExtension)) { if (ComboEncType.SelectedIndex == 0) { mapleVersion = WzTool.DetectMapleVersion(stringWzPath + Resources.FileExtension, out _); } else { mapleVersion = (WzMapleVersion) ComboEncType.SelectedIndex - 1; } StringWz = new WzFile(stringWzPath + Resources.FileExtension, mapleVersion); StringWz.ParseWzFile(); short?version = StringWz.FileVersion; if (WzTool.GetDecryptionSuccessRate(stringWzPath + Resources.FileExtension, mapleVersion, ref version) < 0.8) { MessageBox.Show(Resources.BadEncryption, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else if (Directory.Exists(stringWzPath)) // KMS { mapleVersion = WzMapleVersion.EMS; StringWz = new WzFile(stringWzPath, mapleVersion); WzDirectory dir = new WzDirectory("String", StringWz); StringWz.WzDirectory = dir; RecursivelyLoadDirectory(dir, stringWzPath, mapleVersion); } else { MessageBox.Show(Resources.MissingStringFile, Resources.FIleNotFound, MessageBoxButtons.OK, MessageBoxIcon.Error); DisposeWzFiles(); return; } StringUtility = new WzStringUtility(StringWz); LoadWzData(mapleVersion, folderPath); } DisposeWzFiles(); }
public MainForm(string wzToLoad, bool usingPipes, bool firstrun) { InitializeComponent(); encryptionBox.Items.Add(HaRepacker.Properties.Resources.EncTypeGMS); encryptionBox.Items.Add(HaRepacker.Properties.Resources.EncTypeMSEA); encryptionBox.Items.Add(HaRepacker.Properties.Resources.EncTypeNone); #if DEBUG debugToolStripMenuItem.Visible = true; #endif WindowState = ApplicationSettings.Maximized ? FormWindowState.Maximized : FormWindowState.Normal; Size = ApplicationSettings.WindowSize; if (usingPipes) { try { Program.pipe = new NamedPipeServerStream(Program.pipeName, PipeDirection.In); Program.pipeThread = new Thread(new ThreadStart(PipeServer)); Program.pipeThread.IsBackground = true; Program.pipeThread.Start(); } catch (IOException) { if (wzToLoad != null) { try { NamedPipeClientStream clientPipe = new NamedPipeClientStream(".", Program.pipeName, PipeDirection.Out); clientPipe.Connect(0); StreamWriter sw = new StreamWriter(clientPipe); sw.WriteLine(wzToLoad); clientPipe.WaitForPipeDrain(); sw.Close(); Environment.Exit(0); } catch (TimeoutException) { } } } } if (wzToLoad != null && File.Exists(wzToLoad)) { short version; WzMapleVersion encVersion = WzTool.DetectMapleVersion(wzToLoad, out version); encryptionBox.SelectedIndex = (int)encVersion; LoadWzFileThreadSafe(wzToLoad, MainPanel, false); } WzNode.ContextMenuBuilder = new WzNode.ContextMenuBuilderDelegate(new ContextMenuManager(MainPanel.UndoRedoMan).CreateMenu); }
/// <summary> /// Open a wz file from a file on the disk /// </summary> /// <param name="pFilePath">Path to the wz file</param> public WzFile(string pFilePath, short pGameVersion, WzMapleVersion pVersion) { mName = Path.GetFileName(pFilePath); mPath = pFilePath; mFileVersion = pGameVersion; mMapleVersion = pVersion; /*if (pVersion == WzMapleVersion.LOAD_FROM_ZLZ) { * FileStream zlzStream = File.OpenRead(Path.Combine(Path.GetDirectoryName(pFilePath), "ZLZ.dll")); * mWzIv = WzKeyGenerator.GetIvFromZlz(zlzStream); * zlzStream.Close(); * } else {*/ mWzIv = WzTool.GetIvByMapleVersion(pVersion); //} }
/// <summary> /// Saves a wz file to the disk, AKA repacking. /// </summary> /// <param name="path">Path to the output wz file</param> public void SaveToDisk(string path) { _wzIv = WzTool.GetIvByMapleVersion(MapleVersion); CreateVersionHash(); WzDirectory.SetHash(_versionHash); var tempFile = Path.GetFileNameWithoutExtension(path) + ".TEMP"; File.Create(tempFile).Close(); WzDirectory.GenerateDataFile(tempFile); WzTool.StringCache.Clear(); var totalLen = WzDirectory.GetImgOffsets(WzDirectory.GetOffsets(Header.FStart + 2)); var wzWriter = new WzBinaryWriter(File.Create(path), _wzIv) { Hash = _versionHash }; Header.FSize = totalLen - Header.FStart; for (var i = 0; i < 4; i++) { { wzWriter.Write((byte)Header.Ident[i]); } } wzWriter.Write((long)Header.FSize); wzWriter.Write(Header.FStart); wzWriter.WriteNullTerminatedString(Header.Copyright); var extraHeaderLength = Header.FStart - wzWriter.BaseStream.Position; if (extraHeaderLength > 0) { wzWriter.Write(new byte[(int)extraHeaderLength]); } wzWriter.Write(_version); wzWriter.Header = Header; WzDirectory.SaveDirectory(wzWriter); wzWriter.StringCache.Clear(); var fs = File.OpenRead(tempFile); WzDirectory.SaveImages(wzWriter, fs); fs.Close(); File.Delete(tempFile); wzWriter.StringCache.Clear(); wzWriter.Close(); GC.Collect(); GC.WaitForPendingFinalizers(); }
/// <summary> /// Begin loading WZ data corresponding to the selected tab /// </summary> private void BtnWzLoad_Click(object sender, EventArgs e) { ClearAllPages(TabControlMain); DisposeWzFiles(); var wzFolderPath = TextWzPath.Text; var wzStringPath = wzFolderPath + @"\String"; if (string.IsNullOrEmpty(wzFolderPath)) { MessageBox.Show(Resources.Error, Resources.FileNotFound, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!wzFolderPath.Equals(Settings.Default.PathCache)) { Settings.Default.PathCache = wzFolderPath; Settings.Default.Save(); } var item = (ComboBoxItem)ComboEncType.Items[ComboEncType.SelectedIndex]; WzMapleVersion encryption; if (item.Value == null) { // auto detect if (File.Exists(wzStringPath + Resources.FileExtensionWZ)) { encryption = WzTool.DetectMapleVersion(wzStringPath += Resources.FileExtensionWZ, out _); short? gameVersion = null; if (WzTool.GetDecryptionSuccessRate(wzStringPath, encryption, ref gameVersion) < 0.8) { MessageBox.Show(Resources.BadEncryption, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else if (Directory.Exists(wzStringPath)) { encryption = (WzMapleVersion)WzTool.DetectMapleVersion(wzStringPath, "Cash.img"); } else { MessageBox.Show(Resources.MissingStringFile, Resources.FileNotFound, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (Wz.String.LoadFile(wzStringPath, encryption) == null) { MessageBox.Show(Resources.MissingStringFile, Resources.FileNotFound, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { // manual selection encryption = (WzMapleVersion)item.Value; } loadAll = false; var selectedIndex = (ModifierKeys == Keys.Shift) ? -1 : TabControlMain.SelectedIndex; LoadWzData(selectedIndex, encryption, wzFolderPath); }
private void button1_Click(object sender, EventArgs e) { ApplicationSettings.MapleVersionIndex = versionBox.SelectedIndex; ApplicationSettings.MapleFolderIndex = pathBox.SelectedIndex; string wzPath = pathBox.Text; if (wzPath == "Select Maple Folder") { MessageBox.Show("Please select the maple folder.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!ApplicationSettings.MapleFolder.Contains(wzPath) && !IsPathCommon(wzPath)) { ApplicationSettings.MapleFolder = ApplicationSettings.MapleFolder == "" ? wzPath : (ApplicationSettings.MapleFolder + "," + wzPath); } WzMapleVersion fileVersion; short version = -1; if (versionBox.SelectedIndex == 3) { string testFile = File.Exists(Path.Combine(wzPath, "Data.wz")) ? "Data.wz" : "Item.wz"; try { fileVersion = WzTool.DetectMapleVersion(Path.Combine(wzPath, testFile), out version); } catch (Exception ex) { HaRepackerLib.Warning.Error("Error initializing " + testFile + " (" + ex.Message + ").\r\nCheck that the directory is valid and the file is not in use."); return; } } else { fileVersion = (WzMapleVersion)versionBox.SelectedIndex; } InitializeWzFiles(wzPath, fileVersion); Hide(); Application.DoEvents(); editor = new HaEditor(); editor.ShowDialog(); Application.Exit(); }
/// <summary> /// Open a wz file from a file on the disk /// </summary> /// <param name="filePath">Path to the wz file</param> public WzFile(string filePath, short gameVersion, WzMapleVersion version) { name = Path.GetFileName(filePath); path = filePath; fileVersion = gameVersion; mapleVersion = version; if (version == WzMapleVersion.GETFROMZLZ) { FileStream zlzStream = File.OpenRead(Path.Combine(Path.GetDirectoryName(filePath), "ZLZ.dll")); WzIv = Util.WzKeyGenerator.GetIvFromZlz(zlzStream); zlzStream.Close(); } else { WzIv = WzTool.GetIvByMapleVersion(version); } }
public static WzSoundProperty CreateCustomProperty(string name, string file) { WzSoundProperty newProp = new WzSoundProperty(name); MP3Header header = new MP3Header(); header.ReadMP3Information(file); newProp.mLenMs = header.intLength * 1000; byte[] frequencyBytes = BitConverter.GetBytes(header.intFrequency); byte[] headerBytes = new byte[SoundHeaderMask.Length]; Array.Copy(SoundHeaderMask, headerBytes, headerBytes.Length); for (int i = 0; i < 4; i++) { headerBytes[56 + i] = frequencyBytes[i]; } newProp.mMp3bytes = WzTool.Combine(headerBytes, File.ReadAllBytes(file)); return(newProp); }
internal void CompressPng(Bitmap bmp) { byte[] buf = new byte[bmp.Width * bmp.Height * 8]; format = 2; format2 = 0; width = bmp.Width; height = bmp.Height; int curPos = 0; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Color curPixel = bmp.GetPixel(j, i); buf[curPos] = curPixel.B; buf[curPos + 1] = curPixel.G; buf[curPos + 2] = curPixel.R; buf[curPos + 3] = curPixel.A; curPos += 4; } } compressedImageBytes = Compress(buf); if (listWzUsed) { using (MemoryStream memStream = new MemoryStream()) { using (WzBinaryWriter writer = new WzBinaryWriter(memStream, WzTool.GetIvByMapleVersion(WzMapleVersion.GMS))) { writer.Write(2); for (int i = 0; i < 2; i++) { writer.Write((byte)(compressedImageBytes[i] ^ writer.WzKey[i])); } writer.Write(compressedImageBytes.Length - 2); for (int i = 2; i < compressedImageBytes.Length; i++) { writer.Write((byte)(compressedImageBytes[i] ^ writer.WzKey[i - 2])); } compressedImageBytes = memStream.GetBuffer(); } } } }
/// <summary> /// Open a wz file from a file on the disk /// </summary> /// <param name="filePath">Path to the wz file</param> public WzFile(string filePath, WzMapleVersion version) { Name = Path.GetFileName(filePath); FilePath = filePath; FileVersion = -1; MapleVersion = version; if (version == WzMapleVersion.GetFromZlz) { var zlzStream = File.OpenRead(Path.Combine(Path.GetDirectoryName(filePath), "ZLZ.dll")); _wzIv = WzKeyGenerator.GetIvFromZlz(zlzStream); zlzStream.Close(); } else { { _wzIv = WzTool.GetIvByMapleVersion(version); } } }
private void LoadFromImg() { var mapleVersion = WzTool.DetectMapleVersion("Data\\Etc", "Commodity.img"); if (mapleVersion == -1) { MessageBox.Show(Resources.ErrorWzEncryption, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var etc = Wz.Etc.LoadFile($"Data\\Etc", (WzMapleVersion)mapleVersion); Wz.Character.LoadFile($"Data\\Character", (WzMapleVersion)mapleVersion); Wz.Item.LoadFile($"Data\\Item", (WzMapleVersion)mapleVersion); commodityImg = etc.WzDirectory.GetImageByName("Commodity.img"); commodityImg.ParseImage(); AddItems(commodityImg.WzProperties); }
internal void CompressPng(Bitmap pBmp) { byte[] buf = new byte[pBmp.Width * pBmp.Height * 8]; mFormat = 2; mFormat2 = 0; mWidth = pBmp.Width; mHeight = pBmp.Height; int curPos = 0; for (int i = 0; i < mHeight; i++) { for (int j = 0; j < mWidth; j++) { Color curPixel = pBmp.GetPixel(j, i); buf[curPos] = curPixel.B; buf[curPos + 1] = curPixel.G; buf[curPos + 2] = curPixel.R; buf[curPos + 3] = curPixel.A; curPos += 4; } } mCompressedBytes = Compress(buf); //if (!mIsNew) // return; MemoryStream memStream = new MemoryStream(); WzBinaryWriter writer = new WzBinaryWriter(memStream, WzTool.GetIvByMapleVersion(WzMapleVersion.GMS)); writer.Write(2); for (int i = 0; i < 2; i++) { writer.Write((byte)(mCompressedBytes[i] ^ writer.WzKey[i])); } writer.Write(mCompressedBytes.Length - 2); for (int i = 2; i < mCompressedBytes.Length; i++) { writer.Write((byte)(mCompressedBytes[i] ^ writer.WzKey[i - 2])); } mCompressedBytes = memStream.GetBuffer(); writer.Close(); }
private void LoadFromWz() { var mapleVersion = WzTool.DetectMapleVersion("Etc.wz", out var detectVersion); short?nVersion = null; if (WzTool.GetDecryptionSuccessRate("Etc.wz", mapleVersion, ref nVersion) < 0.8) { MessageBox.Show(Resources.ErrorWzEncryption, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var etc = Wz.Etc.LoadFile("Etc", mapleVersion); Wz.Character.LoadFile("Character", mapleVersion); Wz.Item.LoadFile("Item", mapleVersion); commodityImg = etc.WzDirectory.GetImageByName("Commodity.img"); commodityImg.ParseImage(); AddItems(commodityImg.WzProperties); }
/// <summary> /// Open a wz file from a file on the disk /// </summary> /// <param name="filePath">Path to the wz file</param> public WzFile(string filePath, short gameVersion, WzMapleVersion version) { name = Path.GetFileName(filePath); path = filePath; mapleStoryPatchVersion = gameVersion; maplepLocalVersion = version; if (version == WzMapleVersion.GETFROMZLZ) { using (FileStream zlzStream = File.OpenRead(Path.Combine(Path.GetDirectoryName(filePath), "ZLZ.dll"))) { this.WzIv = Util.WzKeyGenerator.GetIvFromZlz(zlzStream); } } else { this.WzIv = WzTool.GetIvByMapleVersion(version); } string[] filePathSplit = Regex.Split(filePath, @"\\"); this.b64BitClient = filePathSplit.Contains("Data"); // TODO: Find a better way of identifying 64-bit client/ WZ from the WZ files instead. This might break if it isnt installed in the right path, esp. private servers }