コード例 #1
0
ファイル: Form1.cs プロジェクト: shawwwn/BJ_Edit
 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!");
     }
 }
コード例 #2
0
        /// <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();
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: shawwwn/BJ_Edit
        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!");
            }
        }
コード例 #4
0
        private void button16_Click_1(object sender, EventArgs e)
        {
            openFileDialog2.FileName = "";
            ChangeLabel(1);
            openFileDialog2.ShowDialog();
            if (openFileDialog2.FileName.Trim() != "" && File.Exists(openFileDialog2.FileName))
            {
                //MessageBox.Show(openFileDialog2.FileName);
                try
                {
                    //if (File.Exists(@"Input\Blizzard.j")) { File.Delete(@"Input\Blizzard.j"); }
                    if (File.Exists(@"Input\war3map.j"))
                    {
                        File.Delete(@"Input\war3map.j");
                    }
                    if (File.Exists(@"Input\war3map.wts"))
                    {
                        File.Delete(@"Input\war3map.wts");
                    }
                    if (File.Exists(@"Input\war3mapMisc.txt"))
                    {
                        File.Delete(@"Input\war3mapMisc.txt");
                    }

                    MpqLib.Mpq.CArchive archive = new MpqLib.Mpq.CArchive(openFileDialog2.FileName);
                    if (!System.IO.Directory.Exists("Input"))
                    {
                        System.IO.Directory.CreateDirectory("Input");
                    }

                    if (archive.FileExists("war3map.j"))
                    {
                        archive.ExportFile("war3map.j", @"Input\war3map.j");
                    }
                    if (archive.FileExists("war3map.wts"))
                    {
                        archive.ExportFile("war3map.wts", @"Input\war3map.wts");
                    }
                    if (archive.FileExists("war3mapMisc.txt"))
                    {
                        archive.ExportFile("war3mapMisc.txt", @"Input\war3mapMisc.txt");
                    }
                    archive.Close();
                    MessageBox.Show("Files have been extracted at: Input\\");
                }
                catch
                {
                    MessageBox.Show("Opps, Something wrong happened during the extracting process.");
                }
            }
            ChangeLabel(0);
        }
コード例 #5
0
ファイル: Utils.cs プロジェクト: shawwwn/nupdater
        public static string getGameVersion(string gamePath, string mpqName = "Nirvana.mpq")
        {
            gamePath = resolvePath(gamePath);
            string mpqPath = gamePath + mpqName;
            var Archive = new MpqLib.Mpq.CArchive(mpqPath);

            string version = "";
            try
            {
                if (Archive.FileExists("(version)"))
                {
                    var H_versionFile = new MpqLib.Mpq.CFileStream(Archive, "(version)");
                    var version_raw = new byte[H_versionFile.Length];
                    version_raw = H_versionFile.Read((int)H_versionFile.Length);
                    H_versionFile.Close();
                    version = Encoding.ASCII.GetString(version_raw);
                }
            }
            catch
            {
            }
            Archive.Close();
            return version;
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: shawwwn/BJ_Edit
        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!");
            }
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: shawwwn/BJ_Edit
        private void button16_Click_1(object sender, EventArgs e)
        {
            openFileDialog2.FileName = "";
            ChangeLabel(1);
            openFileDialog2.ShowDialog();
            if (openFileDialog2.FileName.Trim() != "" && File.Exists(openFileDialog2.FileName))
            {
                //MessageBox.Show(openFileDialog2.FileName);
                try
                {
                    //if (File.Exists(@"Input\Blizzard.j")) { File.Delete(@"Input\Blizzard.j"); }
                    if (File.Exists(@"Input\war3map.j")) { File.Delete(@"Input\war3map.j"); }
                    if (File.Exists(@"Input\war3map.wts")) { File.Delete(@"Input\war3map.wts"); }
                    if (File.Exists(@"Input\war3mapMisc.txt")) { File.Delete(@"Input\war3mapMisc.txt"); }

                    MpqLib.Mpq.CArchive archive = new MpqLib.Mpq.CArchive(openFileDialog2.FileName);
                    if (!System.IO.Directory.Exists("Input")) { System.IO.Directory.CreateDirectory("Input"); }

                    if (archive.FileExists("war3map.j")) { archive.ExportFile("war3map.j", @"Input\war3map.j"); }
                    if (archive.FileExists("war3map.wts")) { archive.ExportFile("war3map.wts", @"Input\war3map.wts"); }
                    if (archive.FileExists("war3mapMisc.txt")) { archive.ExportFile("war3mapMisc.txt", @"Input\war3mapMisc.txt"); }
                    archive.Close();
                    MessageBox.Show("Files have been extracted at: Input\\");
                }
                catch
                {
                    MessageBox.Show("Opps, Something wrong happened during the extracting process.");
                }
            }
            ChangeLabel(0);
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: shawwwn/BJ_Edit
 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!");
     }
 }
コード例 #9
0
ファイル: Form1.cs プロジェクト: shawwwn/BJ_Edit
        private void button7_Click(object sender, EventArgs e)
        {
            if (openMapDialog.ShowDialog() == DialogResult.OK)
            {
                TransferStatus(true);
                if (Directory.Exists("map")) { Directory.Delete("map", true); }
                Directory.CreateDirectory(@"map\Units");
                #region ---解压mpq---
                //开始解压文件
                label1.Text = "Extracting Files...";
                //用于设置进度条。
                progressBar1.Minimum = 0;
                progressBar1.Maximum = unitsfilelist.GetLength(0);
                progressBar1.Step = 1;
                progressBar1.Value = 0;
                MpqLib.Mpq.CArchive map = new MpqLib.Mpq.CArchive(openMapDialog.FileName);
                for (int i = 0; i < unitsfilelist.Length; i++)
                {
                    progressBar1.PerformStep();
                    string filename = @"Units\" + unitsfilelist[i];
                    if (map.FileExists(filename))
                    {
                        map.ExportFile(filename, @"map\Units\" + unitsfilelist[i]);
                    }
                }
                if (map.FileExists(@"war3map.w3i"))   //解w3i
                { map.ExportFile(@"war3map.w3i", @"map\" + @"war3map.w3i"); }

                if (map.FileExists(@"war3map.wts"))   //解wts
                { map.ExportFile(@"war3map.wts", @"map\" + @"war3map.wts"); }

                //map.Close();
                #endregion
                #region ---读取stringlist---
                label1.Text = "Load string list...";
                string inidata = @"inilist.txt";
                string wtsdata = @"wts_data.txt";
                if (!File.Exists(inidata)) { MessageBox.Show("inilist.txt missing"); return; }
                StreamReader sr = new StreamReader(inidata);
                string[] iniss = sr.ReadToEnd().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                sr.Close();
                if (!File.Exists(wtsdata)) { MessageBox.Show("wts_data.txt missing"); return; }
                StreamReader sr2 = new StreamReader(wtsdata);
                string[] wtsss = sr2.ReadToEnd().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                sr2.Close();
                #endregion
                #region ---还原w3i---
                if (File.Exists(@"map\war3map.w3i"))
                {
                    label1.Text = "Restoring war3map.w3i...";
                    RestoreFileStringFromW3i(@"map\war3map.w3i", wtsss, "GAME_STRING ", true);
                }
                #endregion
                #region ---还原wts---
                if (File.Exists(@"map\war3map.wts"))
                {
                    label1.Text = "Restoring war3map.wts...";
                    RestoreFileString(@"map\war3map.wts", wtsss, "GAME_STRING ", true);
                }
                #endregion
                #region ---还原slk---
                label1.Text = "Restoring slk...";
                //遍历文件夹
                DirectoryInfo TheFolder = new DirectoryInfo(@"map\Units");
                FileInfo[] TheFiles = TheFolder.GetFiles();
                //用于设置进度条。
                progressBar1.Minimum = 0;
                progressBar1.Maximum = TheFiles.GetLength(0);
                progressBar1.Step = 1;
                progressBar1.Value = 0;
                foreach (FileInfo NextFile in TheFolder.GetFiles())
                {
                    if (NextFile.Extension == ".txt" || NextFile.Extension == ".fdf")
                    {
                        RestoreFileString(NextFile.FullName, iniss, "INI_STRING "); //it also comes with the "GAME_STRING "
                        Application.DoEvents();
                        RestoreFileString(NextFile.FullName, wtsss, "GAME_STRING ");
                        Application.DoEvents();
                    }
                    progressBar1.PerformStep();
                    Application.DoEvents();
                }
                #endregion
                #region ---重新压入地图---
                //war3map.j导入
                if (File.Exists("war3map.j")) { File.Copy("war3map.j", @"map\war3map.j", true); }
                //war3mapMisc.txt导入
                if (File.Exists("war3mapMisc.txt")) { File.Copy("war3mapMisc.txt", @"map\war3mapMisc.txt", true); }
                label1.Text = "Import to map...";
                PackAllFileToMpq(Application.StartupPath + @"\map", Application.StartupPath + @"\map", map);
                map.Flush();
                map.Compact();
                map.Close();
                #endregion
                label1.Text = "Finish.";
                TransferStatus(false);
                refreshfrm();
                MessageBox.Show("Finish!");
            }
        }
コード例 #10
0
ファイル: Form1.cs プロジェクト: shawwwn/BJ_Edit
        private void button7_Click(object sender, EventArgs e)
        {
            if (openMapDialog.ShowDialog() == DialogResult.OK)
            {
                TransferStatus(true);
                if (Directory.Exists("map"))
                {
                    Directory.Delete("map", true);
                }
                Directory.CreateDirectory(@"map\Units");
                #region ---解压mpq---
                //开始解压文件
                label1.Text = "Extracting Files...";
                //用于设置进度条。
                progressBar1.Minimum = 0;
                progressBar1.Maximum = unitsfilelist.GetLength(0);
                progressBar1.Step    = 1;
                progressBar1.Value   = 0;
                MpqLib.Mpq.CArchive map = new MpqLib.Mpq.CArchive(openMapDialog.FileName);
                for (int i = 0; i < unitsfilelist.Length; i++)
                {
                    progressBar1.PerformStep();
                    string filename = @"Units\" + unitsfilelist[i];
                    if (map.FileExists(filename))
                    {
                        map.ExportFile(filename, @"map\Units\" + unitsfilelist[i]);
                    }
                }
                if (map.FileExists(@"war3map.w3i"))   //解w3i
                {
                    map.ExportFile(@"war3map.w3i", @"map\" + @"war3map.w3i");
                }

                if (map.FileExists(@"war3map.wts"))   //解wts
                {
                    map.ExportFile(@"war3map.wts", @"map\" + @"war3map.wts");
                }

                //map.Close();
                #endregion
                #region ---读取stringlist---
                label1.Text = "Load string list...";
                string inidata = @"inilist.txt";
                string wtsdata = @"wts_data.txt";
                if (!File.Exists(inidata))
                {
                    MessageBox.Show("inilist.txt missing"); return;
                }
                StreamReader sr    = new StreamReader(inidata);
                string[]     iniss = sr.ReadToEnd().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                sr.Close();
                if (!File.Exists(wtsdata))
                {
                    MessageBox.Show("wts_data.txt missing"); return;
                }
                StreamReader sr2   = new StreamReader(wtsdata);
                string[]     wtsss = sr2.ReadToEnd().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                sr2.Close();
                #endregion
                #region ---还原w3i---
                if (File.Exists(@"map\war3map.w3i"))
                {
                    label1.Text = "Restoring war3map.w3i...";
                    RestoreFileStringFromW3i(@"map\war3map.w3i", wtsss, "GAME_STRING ", true);
                }
                #endregion
                #region ---还原wts---
                if (File.Exists(@"map\war3map.wts"))
                {
                    label1.Text = "Restoring war3map.wts...";
                    RestoreFileString(@"map\war3map.wts", wtsss, "GAME_STRING ", true);
                }
                #endregion
                #region ---还原slk---
                label1.Text = "Restoring slk...";
                //遍历文件夹
                DirectoryInfo TheFolder = new DirectoryInfo(@"map\Units");
                FileInfo[]    TheFiles  = TheFolder.GetFiles();
                //用于设置进度条。
                progressBar1.Minimum = 0;
                progressBar1.Maximum = TheFiles.GetLength(0);
                progressBar1.Step    = 1;
                progressBar1.Value   = 0;
                foreach (FileInfo NextFile in TheFolder.GetFiles())
                {
                    if (NextFile.Extension == ".txt" || NextFile.Extension == ".fdf")
                    {
                        RestoreFileString(NextFile.FullName, iniss, "INI_STRING "); //it also comes with the "GAME_STRING "
                        Application.DoEvents();
                        RestoreFileString(NextFile.FullName, wtsss, "GAME_STRING ");
                        Application.DoEvents();
                    }
                    progressBar1.PerformStep();
                    Application.DoEvents();
                }
                #endregion
                #region ---重新压入地图---
                //war3map.j导入
                if (File.Exists("war3map.j"))
                {
                    File.Copy("war3map.j", @"map\war3map.j", true);
                }
                //war3mapMisc.txt导入
                if (File.Exists("war3mapMisc.txt"))
                {
                    File.Copy("war3mapMisc.txt", @"map\war3mapMisc.txt", true);
                }
                label1.Text = "Import to map...";
                PackAllFileToMpq(Application.StartupPath + @"\map", Application.StartupPath + @"\map", map);
                map.Flush();
                map.Compact();
                map.Close();
                #endregion
                label1.Text = "Finish.";
                TransferStatus(false);
                refreshfrm();
                MessageBox.Show("Finish!");
            }
        }
コード例 #11
0
        /// <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();
            }
        }
コード例 #12
0
        /// <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();
            }
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: warcode/SC2RAR
        static void readBytesAndRenameReplay(string path)
        {
            if (config.debugWaitSeconds != 0)
            {
                System.Threading.Thread.Sleep(config.debugWaitSeconds * 1000);
            }
            while (isFileOpenOrReadOnly(path))
            {
                System.Threading.Thread.Sleep(1000);
            }

            bool validPathName = Regex.IsMatch(path, "^[a-zA-Z0-9 .]*$");

            byte[] replayDataBuffer = new byte[2000];
            MpqLib.Mpq.CArchive replay = null;
            try{
                replay = new MpqLib.Mpq.CArchive(path);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return;
            }
            //replay.ExportFile("replay.info", replayDataBuffer); //PRE 0.9
            replay.ExportFile("replay.details", replayDataBuffer);

            List<byte> list = new List<byte>();

            for (int i = 1; i < 2000; i++)
            {
                if ((replayDataBuffer[i - 1] == 0) && (replayDataBuffer[i] != 0)) list.Add(replayDataBuffer[i - 1]);
                if (replayDataBuffer[i - 1] != 0) list.Add(replayDataBuffer[i - 1]);
            }

            replay.Close();

            byte[] replayData = list.ToArray();

            //WRITE TO TEXT FILE FOR EASY VIEWING
            //writeDebugTxt(replayData, true);
            //writeDebugTxt(replayData, false);

            //read backwards until i hit 0 or value that equals buffer size,
            //reverse and add to a list until i  hit {0, 16, 0}
            List<string> playerdata = readPlayerAndMapDataBeta(replayData);
            //List<string> playerdata = readPlayerAndMapData(replayData);

            string map = playerdata[0];

            //REPLACE MAP NAME WITH PLAYER SPECIFIC NAME FROM maplist.txt
            Dictionary<string, string> maplist = new Dictionary<string, string>();
            StreamReader readMapList = new StreamReader("maplist.txt");
            string mapDataString;
            while ((mapDataString = readMapList.ReadLine()) != null)
            {
                string[] mapDataStringSplit = mapDataString.Split('|');
                maplist.Add(mapDataStringSplit[0], mapDataStringSplit[1]);
            }
            readMapList.Close();
            if (maplist.ContainsKey(map)) map = maplist[map];

            //OBSOLETE, KEEP FOR REGEX
            //bool validMapName = Regex.IsMatch(map, "^[a-zA-Z0-9 ]*$");
            //if (!validMapName) map = "X";
            List<Player> players = new List<Player>();
            int teamA = 0;
            int teamB = 0;
            int teamC = 0;

            for (int i = 1; i < playerdata.Count; i = i + 4)
            {
                Player p = new Player();
                p.name = playerdata[i];
                p.nameAndIdent = playerdata[i + 1];
                p.race = playerdata[i + 2];
                p.teamId = playerdata[i + 3];
                if(p.teamId.Equals("0")) teamA++;
                if(p.teamId.Equals("2")) teamB++;
                players.Add(p);
            }

            string gameTypeString;
            int gameType;
            if((teamA == teamB) && (teamC == 0))
            {
                gameTypeString = teamA.ToString() + "v" + teamA.ToString();
                gameType = teamA;
            }
            else if ((teamA == teamB) && (teamB == teamC) && (teamA == 1))
            {
                gameTypeString = "FFA";
                gameType = 5;
            }
            else
            {
                gameTypeString = "Other";
                gameType = 0;
            }

            if (config.filters[gameType] == false)
            {
                return;
            }
            else
            {
                //game type not filtered, continue.
            }

            if (config.autoPosition)
            {
                //GENERAL SORTING OF PLAYERS PLZX
                //players.Sort(delegate(Player p1, Player p2) { return p1.name.CompareTo(p2.name); });

                if(config.typeOfSort.Equals("Player"))
                {
                    int index = players.FindIndex(delegate(Player p) { return p.name.Equals(config.playerName); });
                    if (index != -1)
                    {
                        if (index >= 0 && index < ((players.Count / 2))) //In the first half
                        {
                            if (config.position.Equals("Front"))
                            {
                                players.Insert(0, players[index]);
                                players.RemoveAt(index + 1);
                            }
                            if (config.position.Equals("Back"))
                            {
                                players.Insert(players.Count, players[index]);
                                players.RemoveAt(index);
                                int teammates = (players.Count / 2) - 1;
                                while (teammates > 0)
                                {
                                    players.Insert(players.Count, players[0]);
                                    players.RemoveAt(0);
                                    teammates--;
                                }
                            }
                        }
                        else if (index >= ((players.Count / 2))) //In the second half
                        {
                            if (config.position.Equals("Front"))
                            {
                                players.Insert(0, players[index]);
                                players.RemoveAt(index + 1);
                                int teammates = (players.Count / 2) - 1;
                                while (teammates > 0)
                                {
                                    players.Insert(1, players[players.Count - 1]);
                                    players.RemoveAt(players.Count - 1);
                                    teammates--;
                                }
                            }
                            if (config.position.Equals("Back"))
                            {
                                players.Insert(((players.Count / 2)), players[index]);
                                players.RemoveAt(index + 1);
                            }
                        }
                    }
                }

                if (config.typeOfSort.Equals("Race"))
                {
                    int index = players.FindIndex(delegate(Player p) { return p.race.Equals(config.race); });
                    if (index != -1)
                    {
                        if (index >= 1 && index < ((players.Count / 2))) //In the first half
                        {
                            players.Insert(0, players[index]);
                            players.RemoveAt(index + 1);
                        }
                        else if (index >= ((players.Count / 2))) //In the second half
                        {
                            players.Insert(0, players[index]);
                            players.RemoveAt(index + 1);
                            int teammates = (players.Count / 2) - 1;
                            while (teammates > 0)
                            {
                                players.Insert(1, players[players.Count - 1]);
                                players.RemoveAt(players.Count - 1);
                                teammates--;
                            }
                        }
                    }
                }
            }

            string filename = formatFilename(path, replayDataBuffer, ref map, players, gameTypeString);

            bool exists = System.IO.File.Exists(filename);
            if (System.IO.File.Exists(filename))
            {
            }
            else
            {
                try
                {
                    if (config.copyReplay)
                    {
                        System.IO.File.Copy(path, filename);
                        if (config.moveReplay)
                        {
                            System.IO.File.Delete(path);
                        }
                        if (config.playSound)
                        {
                            playDoneSound();
                        }
                    }
                    else
                    {
                        System.IO.File.Move(path, filename);
                        if (config.playSound)
                        {
                            playDoneSound();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #14
0
        static void readBytesAndRenameReplay(string path)
        {
            if (config.debugWaitSeconds != 0)
            {
                System.Threading.Thread.Sleep(config.debugWaitSeconds * 1000);
            }
            while (isFileOpenOrReadOnly(path))
            {
                System.Threading.Thread.Sleep(1000);
            }

            bool validPathName = Regex.IsMatch(path, "^[a-zA-Z0-9 .]*$");

            byte[] replayDataBuffer    = new byte[2000];
            MpqLib.Mpq.CArchive replay = null;
            try{
                replay = new MpqLib.Mpq.CArchive(path);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return;
            }
            //replay.ExportFile("replay.info", replayDataBuffer); //PRE 0.9
            replay.ExportFile("replay.details", replayDataBuffer);

            List <byte> list = new List <byte>();

            for (int i = 1; i < 2000; i++)
            {
                if ((replayDataBuffer[i - 1] == 0) && (replayDataBuffer[i] != 0))
                {
                    list.Add(replayDataBuffer[i - 1]);
                }
                if (replayDataBuffer[i - 1] != 0)
                {
                    list.Add(replayDataBuffer[i - 1]);
                }
            }

            replay.Close();

            byte[] replayData = list.ToArray();

            //WRITE TO TEXT FILE FOR EASY VIEWING
            //writeDebugTxt(replayData, true);
            //writeDebugTxt(replayData, false);

            //read backwards until i hit 0 or value that equals buffer size,
            //reverse and add to a list until i  hit {0, 16, 0}
            List <string> playerdata = readPlayerAndMapDataBeta(replayData);
            //List<string> playerdata = readPlayerAndMapData(replayData);


            string map = playerdata[0];

            //REPLACE MAP NAME WITH PLAYER SPECIFIC NAME FROM maplist.txt
            Dictionary <string, string> maplist = new Dictionary <string, string>();
            StreamReader readMapList            = new StreamReader("maplist.txt");
            string       mapDataString;

            while ((mapDataString = readMapList.ReadLine()) != null)
            {
                string[] mapDataStringSplit = mapDataString.Split('|');
                maplist.Add(mapDataStringSplit[0], mapDataStringSplit[1]);
            }
            readMapList.Close();
            if (maplist.ContainsKey(map))
            {
                map = maplist[map];
            }

            //OBSOLETE, KEEP FOR REGEX
            //bool validMapName = Regex.IsMatch(map, "^[a-zA-Z0-9 ]*$");
            //if (!validMapName) map = "X";
            List <Player> players = new List <Player>();
            int           teamA   = 0;
            int           teamB   = 0;
            int           teamC   = 0;

            for (int i = 1; i < playerdata.Count; i = i + 4)
            {
                Player p = new Player();
                p.name         = playerdata[i];
                p.nameAndIdent = playerdata[i + 1];
                p.race         = playerdata[i + 2];
                p.teamId       = playerdata[i + 3];
                if (p.teamId.Equals("0"))
                {
                    teamA++;
                }
                if (p.teamId.Equals("2"))
                {
                    teamB++;
                }
                players.Add(p);
            }

            string gameTypeString;
            int    gameType;

            if ((teamA == teamB) && (teamC == 0))
            {
                gameTypeString = teamA.ToString() + "v" + teamA.ToString();
                gameType       = teamA;
            }
            else if ((teamA == teamB) && (teamB == teamC) && (teamA == 1))
            {
                gameTypeString = "FFA";
                gameType       = 5;
            }
            else
            {
                gameTypeString = "Other";
                gameType       = 0;
            }

            if (config.filters[gameType] == false)
            {
                return;
            }
            else
            {
                //game type not filtered, continue.
            }

            if (config.autoPosition)
            {
                //GENERAL SORTING OF PLAYERS PLZX
                //players.Sort(delegate(Player p1, Player p2) { return p1.name.CompareTo(p2.name); });

                if (config.typeOfSort.Equals("Player"))
                {
                    int index = players.FindIndex(delegate(Player p) { return(p.name.Equals(config.playerName)); });
                    if (index != -1)
                    {
                        if (index >= 0 && index < ((players.Count / 2))) //In the first half
                        {
                            if (config.position.Equals("Front"))
                            {
                                players.Insert(0, players[index]);
                                players.RemoveAt(index + 1);
                            }
                            if (config.position.Equals("Back"))
                            {
                                players.Insert(players.Count, players[index]);
                                players.RemoveAt(index);
                                int teammates = (players.Count / 2) - 1;
                                while (teammates > 0)
                                {
                                    players.Insert(players.Count, players[0]);
                                    players.RemoveAt(0);
                                    teammates--;
                                }
                            }
                        }
                        else if (index >= ((players.Count / 2))) //In the second half
                        {
                            if (config.position.Equals("Front"))
                            {
                                players.Insert(0, players[index]);
                                players.RemoveAt(index + 1);
                                int teammates = (players.Count / 2) - 1;
                                while (teammates > 0)
                                {
                                    players.Insert(1, players[players.Count - 1]);
                                    players.RemoveAt(players.Count - 1);
                                    teammates--;
                                }
                            }
                            if (config.position.Equals("Back"))
                            {
                                players.Insert(((players.Count / 2)), players[index]);
                                players.RemoveAt(index + 1);
                            }
                        }
                    }
                }

                if (config.typeOfSort.Equals("Race"))
                {
                    int index = players.FindIndex(delegate(Player p) { return(p.race.Equals(config.race)); });
                    if (index != -1)
                    {
                        if (index >= 1 && index < ((players.Count / 2))) //In the first half
                        {
                            players.Insert(0, players[index]);
                            players.RemoveAt(index + 1);
                        }
                        else if (index >= ((players.Count / 2))) //In the second half
                        {
                            players.Insert(0, players[index]);
                            players.RemoveAt(index + 1);
                            int teammates = (players.Count / 2) - 1;
                            while (teammates > 0)
                            {
                                players.Insert(1, players[players.Count - 1]);
                                players.RemoveAt(players.Count - 1);
                                teammates--;
                            }
                        }
                    }
                }
            }

            string filename = formatFilename(path, replayDataBuffer, ref map, players, gameTypeString);

            bool exists = System.IO.File.Exists(filename);

            if (System.IO.File.Exists(filename))
            {
            }
            else
            {
                try
                {
                    if (config.copyReplay)
                    {
                        System.IO.File.Copy(path, filename);
                        if (config.moveReplay)
                        {
                            System.IO.File.Delete(path);
                        }
                        if (config.playSound)
                        {
                            playDoneSound();
                        }
                    }
                    else
                    {
                        System.IO.File.Move(path, filename);
                        if (config.playSound)
                        {
                            playDoneSound();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }