private void button2_Click(object sender, EventArgs e) { string bjpath = textBox1.Text; string cjpath = Application.StartupPath + @"\pjass\common.j"; if (!File.Exists(bjpath)) { MessageBox.Show("invalid blizzard.j path!"); return; } if (openMapDialog.ShowDialog() != DialogResult.OK) { return; } MpqLib.Mpq.CArchive map = new MpqLib.Mpq.CArchive(openMapDialog.FileName); string[] listfile = GenerateMapFilelist(map); if (saveMpqDialog.ShowDialog() == DialogResult.OK) { if (File.Exists(saveMpqDialog.FileName)) { File.Delete(saveMpqDialog.FileName); } //================== MpqLib.Mpq.CArchive mpq = new MpqLib.Mpq.CArchive(saveMpqDialog.FileName, true, MpqLib.Mpq.EArchiveFormat.Version1, 10000); //添加地图内文件 for (int i = 0; i < listfile.Length; i++) { MpqLib.Mpq.CFileStream file = new MpqLib.Mpq.CFileStream(map, listfile[i]); byte[] fileb = new byte[file.Length]; fileb = file.Read((int)file.Length); file.Close(); mpq.ImportFile(listfile[i], fileb); fileb = null; /* * if (map.FileExists(listfile[i])) * { * if (File.Exists("temp")) { File.Delete("temp"); } * map.ExportFile(listfile[i], "temp"); * mpq.ImportFile(listfile[i], "temp"); * } */ } map.Close(); //添加blizzard.j mpq.ImportFile(@"Scripts\Blizzard.j", bjpath); //添加blizzard.j mpq.ImportFile(@"Scripts\common.j", cjpath); //添加additional resources... PackAllFileToMpq(textBox2.Text.Trim(), textBox2.Text.Trim(), mpq); //关闭mpq mpq.Flush(); mpq.Compact(); mpq.Close(); //测试地图 MessageBox.Show("Mpq generated at:" + Environment.NewLine + saveMpqDialog.FileName, "Finish!"); } }
/// <summary> Adds a single chat message to a replay. </summary> /// <param name="fileName"> The file name. </param> /// <param name="message"> The message. </param> /// <param name="playerId"> The player id. </param> /// <param name="numSeconds"> The number of in-game seconds to insert the message at. </param> public static void AddChatMessageToReplay(string fileName, string message, ChatMessageTarget target, int playerId, int numSeconds) { var replay = new Replay(); // File in the version numbers for later use. MpqHeader.ParseHeader(replay, fileName); using (var archive = new MpqLib.Mpq.CArchive(fileName)) { var files = archive.FindFiles("replay.*"); { const string CurFile = "replay.message.events"; var fileSize = (from f in files where f.FileName.Equals(CurFile) select f).Single().Size; var buffer = new byte[fileSize]; archive.ExportFile(CurFile, buffer); var arr = GenerateChatMessage(buffer, message, target, playerId, numSeconds); archive.ImportFile("replay.message.events", arr); } archive.Close(); } }
/// <summary> Adds a single chat message to a replay. </summary> /// <param name="fileName"> The file name. </param> /// <param name="messages"> The messages to add. </param> public static void AddChatMessageToReplay(string fileName, IEnumerable<ChatMessage> messages) { var replay = new Replay(); // File in the version numbers for later use. MpqHeader.ParseHeader(replay, fileName); using (var archive = new MpqLib.Mpq.CArchive(fileName)) { var files = archive.FindFiles("replay.*"); { const string CurFile = "replay.message.events"; var fileSize = (from f in files where f.FileName.Equals(CurFile) select f).Single().Size; var buffer = new byte[fileSize]; archive.ExportFile(CurFile, buffer); foreach (var message in messages) { buffer = GenerateChatMessage(buffer, message.Message, message.MessageTarget, message.PlayerId, (int)message.Timestamp.TotalSeconds); } archive.ImportFile("replay.message.events", buffer); } archive.Close(); } }
private void button9_Click(object sender, EventArgs e) { if (openMapDialog.ShowDialog() == DialogResult.OK) { if (File.Exists("war3map_edited.wts")) { File.Delete("war3map_edited.wts"); } if (File.Exists("war3map.j")) { File.Delete("war3map.j"); } if (File.Exists("war3mapMisc.txt")) { File.Delete("war3mapMisc.txt"); } //导出文件 MpqLib.Mpq.CArchive map = new MpqLib.Mpq.CArchive(openMapDialog.FileName); if (map.FileExists("war3map.j")) { map.ExportFile("war3map.j", "war3map.j"); } if (map.FileExists("war3mapMisc.txt")) { map.ExportFile("war3mapMisc.txt", "war3mapMisc.txt"); } if (map.FileExists("war3map.wts")) { map.ExportFile("war3map.wts", "war3map_edited.wts"); } else { label1.Text = "war3map.wts doesn't exist in this map."; map.Close(); return; } TransferStatus(true); label1.Text = "Transfering strings from war3map.wts..."; wts_file wts = new wts_file("war3map_edited.wts"); wts.SaveStripDataFile(true); wts.StringMapping(); //打包进地图 map.ImportFile("war3map.wts", "war3map_edited.wts"); map.Flush(); map.Compact(); map.Close(); if (File.Exists("war3map_edited.wts")) { File.Delete("war3map_edited.wts"); } TransferStatus(false); refreshfrm(); label1.Text = "Finish."; MessageBox.Show("Finish!"); } }
private void PackAllFileToMpq(string path, string basepath, MpqLib.Mpq.CArchive mpq) { DirectoryInfo dir = new DirectoryInfo(path); foreach (FileInfo fChild in dir.GetFiles("*")) //设置文件类型 { string mpqpath = fChild.FullName.Replace(basepath + @"\", ""); mpq.ImportFile(mpqpath, fChild.FullName); } foreach (DirectoryInfo dChild in dir.GetDirectories("*")) //操作子目录 { PackAllFileToMpq(dChild.FullName, basepath, mpq); //递归 } }
private void button2_Click(object sender, EventArgs e) { string bjpath = textBox1.Text; string cjpath = Application.StartupPath + @"\pjass\common.j"; if (!File.Exists(bjpath)) { MessageBox.Show("invalid blizzard.j path!"); return; } if (openMapDialog.ShowDialog() != DialogResult.OK) { return; } MpqLib.Mpq.CArchive map = new MpqLib.Mpq.CArchive(openMapDialog.FileName); string[] listfile = GenerateMapFilelist(map); if (saveMpqDialog.ShowDialog() == DialogResult.OK) { if (File.Exists(saveMpqDialog.FileName)) { File.Delete(saveMpqDialog.FileName); } //================== MpqLib.Mpq.CArchive mpq = new MpqLib.Mpq.CArchive(saveMpqDialog.FileName, true, MpqLib.Mpq.EArchiveFormat.Version1, 10000); //添加地图内文件 for (int i = 0; i < listfile.Length; i++) { MpqLib.Mpq.CFileStream file = new MpqLib.Mpq.CFileStream(map, listfile[i]); byte[] fileb = new byte[file.Length]; fileb = file.Read((int)file.Length); file.Close(); mpq.ImportFile(listfile[i], fileb); fileb = null; /* if (map.FileExists(listfile[i])) { if (File.Exists("temp")) { File.Delete("temp"); } map.ExportFile(listfile[i], "temp"); mpq.ImportFile(listfile[i], "temp"); } */ } map.Close(); //添加blizzard.j mpq.ImportFile(@"Scripts\Blizzard.j", bjpath); //添加blizzard.j mpq.ImportFile(@"Scripts\common.j", cjpath); //添加additional resources... PackAllFileToMpq(textBox2.Text.Trim(), textBox2.Text.Trim(), mpq); //关闭mpq mpq.Flush(); mpq.Compact(); mpq.Close(); //测试地图 MessageBox.Show("Mpq generated at:"+Environment.NewLine+saveMpqDialog.FileName,"Finish!"); } }
/// <summary> Erases the entire chat log of a file. </summary> /// <param name="fileName"> The file name. </param> public static void ClearChatLog(string fileName) { var replay = new Replay(); // File in the version numbers for later use. MpqHeader.ParseHeader(replay, fileName); using (var archive = new MpqLib.Mpq.CArchive(fileName)) { var files = archive.FindFiles("replay.*"); { const string CurFile = "replay.message.events"; var fileSize = (from f in files where f.FileName.Equals(CurFile) select f).Single().Size; var buffer = new byte[fileSize]; archive.ExportFile(CurFile, buffer); var arr = ClearChatLog(buffer); archive.ImportFile("replay.message.events", arr); } archive.Close(); } }