Beispiel #1
0
        public FormToolOutput(ppParser ppParser, string toolOutputParserVar)
        {
            InitializeComponent();

            ToolOutputParser parser = (ToolOutputParser)Gui.Scripting.Variables[toolOutputParserVar];
            if (parser.readFromOtherParser)
            {
                syntaxHighlightingTextBoxToolOutput.ReadOnly = true;
            }

            this.ShowHint = DockState.Document;
            this.Text = parser.Name;
            this.ToolTipText = ppParser.FilePath + @"\" + parser.Name;

            ParserVar = toolOutputParserVar;

            EditorVar = Gui.Scripting.GetNextVariable("toolOutputEditor");
            Editor = (ToolOutputEditor)Gui.Scripting.RunScript(EditorVar + " = ToolOutputEditor(parser=" + ParserVar + ", ppFormatIndex=" + (int)ppParser.Format.ppFormatIdx + ")");

            checkBoxWordWrap.Checked = syntaxHighlightingTextBoxToolOutput.WordWrap;
            syntaxHighlightingTextBoxToolOutput.ScrollBars = RichTextBoxScrollBars.Both & RichTextBoxScrollBars.ForcedBoth;

            syntaxHighlightingTextBoxToolOutput.Seperators.Add('\t');
            syntaxHighlightingTextBoxToolOutput.HighlightDescriptors.Add(new HighlightDescriptor("//", Color.DimGray, null, DescriptorType.ToEOL, DescriptorRecognition.StartsWith, false));

            syntaxHighlightingTextBoxToolOutput.InitText(Editor.Text);
            syntaxHighlightingTextBoxToolOutput.TextChanged += new EventHandler(syntaxHighlightingTextBoxToolOutput_TextChanged);

            syntaxHighlightingTextBoxToolOutput.DragDrop += new DragEventHandler(syntaxHighlightingTextBoxToolOutput_DragDrop);
            syntaxHighlightingTextBoxToolOutput.EnableAutoDragDrop = true;

            Gui.Docking.ShowDockContent(this, Gui.Docking.DockEditors, ContentCategory.Others);
        }
Beispiel #2
0
 public void Execute(ppParser pp)
 {
     if (checkEnable.Checked)
     {
         plugin.ProcessPP(pp);
     }
     prgProgress.Value = 100;
 }
Beispiel #3
0
 public long Analyze(ppParser pp)
 {
     long savings = 0;
     if (checkEnable.Checked)
     {
         savings = plugin.AnalyzePP(pp);
     }
     updateProgress(100);
     return savings;
 }
Beispiel #4
0
        public ppEditor(ppParser parser)
        {
            if (ExternalTools == null && Gui.Config != null)
            {
                ExternalTools = new Dictionary<string, List<ExternalTool>>();

                foreach (SettingsPropertyValue value in Gui.Config.PropertyValues)
                {
                    if (value.PropertyValue.GetType() == typeof(ExternalTool))
                    {
                        ExternalTool tool = (ExternalTool)value.PropertyValue;
                        tool = RegisterExternalTool(tool, false);
                        string toolVar = Gui.Scripting.GetNextVariable("externalTool");
                        Gui.Scripting.Variables.Add(toolVar, tool);
                    }
                }
            }

            Parser = parser;
        }
Beispiel #5
0
        public static void ExportSubfile([DefaultVar] ppParser parser, string name, string path)
        {
            for (int i = 0; i < parser.Subfiles.Count; i++)
            {
                if (parser.Subfiles[i].Name == name)
                {
                    FileInfo      file = new FileInfo(path);
                    DirectoryInfo dir  = file.Directory;
                    if (!dir.Exists)
                    {
                        dir.Create();
                    }

                    using (FileStream fs = file.Create())
                    {
                        parser.Subfiles[i].WriteTo(fs);
                    }
                    break;
                }
            }
        }
Beispiel #6
0
        public long AnalyzePP(ppParser pp)
        {
            long savings = 0;
            for (int i = 0; i < pp.Subfiles.Count; i++)
            {
                IWriteFile iw = pp.Subfiles[i];

                if (!iw.Name.EndsWith(".tga"))
                    continue;

                Stream str = Tools.GetReadStream(iw);

                if (!str.CanSeek || str.Length == 0)
                {
                    str.Close();
                    continue;
                }

                using (str)
                {
                    try
                    {
                        MagickImage m = new MagickImage(str);
                        m.CompressionMethod = CompressionMethod.RLE;

                        using (MemoryStream rle = new MemoryStream())
                        {
                            m.Write(rle, MagickFormat.Tga);
                            savings += str.Length - rle.Length;
                        }
                    }
                    catch (MagickException) { }
                }

                if (ProgressUpdated != null)
                    ProgressUpdated((int)Math.Floor((double)(100 * i) / pp.Subfiles.Count));
            }

            return savings;
        }
Beispiel #7
0
        public static void ExportPP([DefaultVar] ppParser parser, string path)
        {
            if (path == String.Empty)
            {
                path = @".\";
            }
            DirectoryInfo dir = new DirectoryInfo(path);

            if (!dir.Exists)
            {
                dir.Create();
            }

            for (int i = 0; i < parser.Subfiles.Count; i++)
            {
                var subfile = parser.Subfiles[i];
                using (FileStream fs = File.Create(dir.FullName + @"\" + subfile.Name))
                {
                    subfile.WriteTo(fs);
                }
            }
        }
Beispiel #8
0
 public basePP(string file, string destination)
 {
     ppRAW = file;
     pp = new ppParser(destination + "\\" + ppFile);
 }
Beispiel #9
0
        static void Main(string[] args)
        {
            #if DEBUG
            System.Diagnostics.Debugger.Launch();
            #endif

            ConsoleWriter.WriteLineFormat("AA2Pack v{0}", Assembly.GetExecutingAssembly().GetName().Version.ToString());
            ConsoleWriter.WriteLineFormat("by {0}", "drpavel");
            ConsoleWriter.WriteLine();

            if (args.Length == 0 ||
                args.ContainsSwitch("h"))
            {
                PrintHelp();
            #if DEBUG
                Console.ReadKey();
            #endif
                return;
            }

            bool suppress = args.ContainsSwitch("y");

            foreach (string s in args)
            {

                if (File.Exists(s))
                {
                    //extracting a .pp
                    ConsoleWriter.WriteLineFormat("Processing {0}...", Path.GetFileName(s));

                    ppParser pp = new ppParser(s);

                    string dirPath = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(s)), Path.GetFileNameWithoutExtension(s));

                    if (Directory.Exists(dirPath))
                    {
                        if (!suppress &&
                            !PromptUser("Are you sure you want to overwrite \"" + dirPath + "\"?"))
                            continue;
                    }
                    else
                        Directory.CreateDirectory(dirPath);

                    int i = 0;
                    foreach (IWriteFile iw in pp.Subfiles)
                    {
                        string path = Path.Combine(dirPath, iw.Name);
                        using (FileStream fs = new FileStream(path, FileMode.Create))
                            iw.WriteTo(fs);

                        ConsoleWriter.WriteLineFormat("[{0}/{1}] Processed {2}... ({3})",
                            (++i).ToString(), //processed subfiles
                            pp.Subfiles.Count.ToString(), //total subfiles
                            iw.Name, //current subfile
                            string.Format("{0}", Math.Round((double)100 * i / pp.Subfiles.Count) + "%"));
                    }

                    ConsoleWriter.WriteLine();
                }
                else if (Directory.Exists(s))
                {
                    //packing into a .pp

                    string ppPath = Path.GetFullPath(s).TrimEnd('\\') + ".pp";

                    if (File.Exists(ppPath))
                    {
                        if (!suppress &&
                            !PromptUser("Are you sure you want to overwrite \"" + ppPath + "\"?"))
                        {
                            continue;
                        }
                        else
                            File.Delete(ppPath);
                    }

                    ppParser pp = new ppParser(ppPath);

                    foreach (string file in Directory.GetFiles(s))
                        pp.Subfiles.Add(new Subfile(file));

                    var bg = pp.WriteArchive(ppPath, false);

                    bg.ProgressChanged += (sender, e) =>
                    {
                        ConsoleWriter.ClearLine();
                        ConsoleWriter.WriteFormat("Writing " + ppPath + "... ({0})", e.ProgressPercentage + "%");
                    };

                    bg.RunWorkerAsync();

                    while (bg.IsBusy)
                        System.Threading.Thread.Sleep(50);

                    ConsoleWriter.ClearLine();
                    ConsoleWriter.WriteLineFormat("Writing " + ppPath + "... ({0})", "100%");
                }
            }

            #if DEBUG
            Console.ReadKey();
            #endif
        }
Beispiel #10
0
        public long AnalyzePP(ppParser pp)
        {
            long total = 0;

            for (int i = 0; i < pp.Subfiles.Count; i++)
            {
                IWriteFile iw = pp.Subfiles[i];

                if (!iw.Name.EndsWith(".wav"))
                    continue;

                Stream str = Tools.GetReadStream(iw);

                if (!str.CanSeek || str.Length == 0)
                {
                    str.Close();
                    continue;
                }

                using (str)
                {
                    WaveFileChunkReader wv = new WaveFileChunkReader();

                    WaveFormat f;
                    try
                    {
                        f = wv.ReadWaveHeader(str);
                    }
                    catch (FormatException)
                    {
                        str.Close();
                        continue;
                    }

                    long length = str.Length;
                    long remaining = length;
                    if (f.Channels > 1) // || wv.WaveFormat.Encoding != WaveFormatEncoding.Adpcm
                    {
                        total += (length / 2);
                        remaining /= 2;
                    }
                    if (f.SampleRate > SampleRate)
                    {
                        total += remaining - (long)(((float)SampleRate / f.SampleRate) * remaining);
                    }
                }

                if (ProgressUpdated != null)
                    ProgressUpdated((int)Math.Floor((double)(100 * i) / pp.Subfiles.Count));
            }

            return total;
        }
Beispiel #11
0
        public FormPP(string path, string variable)
        {
            try
            {
                InitializeComponent();

                FormVariable = variable;

                ParserVar = Gui.Scripting.GetNextVariable("ppParser");
                ppParser ppParser = (ppParser)Gui.Scripting.RunScript(ParserVar + " = OpenPP(path=\"" + path + "\")");

                EditorVar = Gui.Scripting.GetNextVariable("ppEditor");
                Editor    = (ppEditor)Gui.Scripting.RunScript(EditorVar + " = ppEditor(parser=" + ParserVar + ")");

                Text        = Path.GetFileName(ppParser.FilePath);
                ToolTipText = ppParser.FilePath;
                ShowHint    = DockState.Document;

                saveFileDialog1.Filter = ".pp Files (*.pp)|*.pp|All Files (*.*)|*.*";

                subfileListViews.Add(xxSubfilesList);
                subfileListViews.Add(xaSubfilesList);
                subfileListViews.Add(imageSubfilesList);
                subfileListViews.Add(soundSubfilesList);
                subfileListViews.Add(otherSubfilesList);

                InitSubfileLists();

                comboBoxFormat.Items.AddRange(ppFormat.Array);
                comboBoxFormat.SelectedIndex         = (int)ppParser.Format.ppFormatIdx;
                comboBoxFormat.SelectedIndexChanged += new EventHandler(comboBoxFormat_SelectedIndexChanged);

                Gui.Docking.ShowDockContent(this, Gui.Docking.DockFiles);
                this.FormClosing += new FormClosingEventHandler(FormPP_FormClosing);

                List <DockContent> formPPList;
                if (Gui.Docking.DockContents.TryGetValue(typeof(FormPP), out formPPList))
                {
                    var listCopy = new List <FormPP>(formPPList.Count);
                    for (int i = 0; i < formPPList.Count; i++)
                    {
                        listCopy.Add((FormPP)formPPList[i]);
                    }

                    foreach (var form in listCopy)
                    {
                        if (form != this)
                        {
                            var formParser = (ppParser)Gui.Scripting.Variables[form.ParserVar];
                            if (formParser.FilePath == path)
                            {
                                form.Close();
                            }
                        }
                    }
                }

                keepBackupToolStripMenuItem.Checked         = (bool)Gui.Config["KeepBackupOfPP"];
                keepBackupToolStripMenuItem.CheckedChanged += keepBackupToolStripMenuItem_CheckedChanged;
            }
            catch (Exception ex)
            {
                Utility.ReportException(ex);
            }
        }
Beispiel #12
0
        public FormXA(ppParser ppParser, string xaParserVar)
        {
            InitializeComponent();
            this.Controls.Remove(this.menuStrip1);

            xaParser parser = (xaParser)Gui.Scripting.Variables[xaParserVar];

            this.ShowHint = DockState.Document;
            this.Text = parser.Name;
            this.ToolTipText = ppParser.FilePath + @"\" + parser.Name;

            ParserVar = xaParserVar;

            EditorVar = Gui.Scripting.GetNextVariable("xaEditor");
            Editor = (xaEditor)Gui.Scripting.RunScript(EditorVar + " = xaEditor(parser=" + ParserVar + ")");

            Init();
            LoadXA();
        }
Beispiel #13
0
 public ppEditor(ppParser parser)
 {
     Parser = parser;
 }
Beispiel #14
0
        public static CustomPersonality LoadPersonality(ppParser pp)
        {
            if (!pp.Subfiles.Select(iw => iw.Name).Any(n => n.EndsWith(".icf")) || //check if it's a valid personality .pp which contains everything we need
                !pp.Subfiles.Select(iw => iw.Name).Any(n => n.EndsWith(".lst") && n.StartsWith("jg2p")))
                return null;

            string filename = pp.FilePath.Remove(0, pp.FilePath.LastIndexOf('\\') + 1);
            IWriteFile lst = pp.Subfiles.First(iw => iw.Name.EndsWith(".lst") && iw.Name.StartsWith("jg2p")); //you can thank a certain person for making this difficult (http://pastebin.com/3zkjpM7e)

            byte slot = byte.Parse(Tools.GetLstValue(lst, 2));

            Gender gender = (Gender)byte.Parse(Tools.GetLstValue(lst, 6)); //not sure if more accurate than grabbing ID letter, this column is set to 1 for female and 0 for male

            string ID = Tools.GetLstValue(lst, 7);

            string Name = Tools.GetLstValue(lst, 8);
            Name = AppendTranslation.GetValueOrDefault(Name, Name);

            return new CustomPersonality(gender, filename, ID, filename + "/" + lst.Name, Name, slot);
        }
Beispiel #15
0
 public ppEditor(ppParser parser)
 {
     Parser = parser;
 }
Beispiel #16
0
        public void deleteModTest()
        {
            Assert.IsTrue(File.Exists(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp"), Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp did not deploy");

            CopyFilesRecursively(new DirectoryInfo(Environment.CurrentDirectory + @"\mods\"), new DirectoryInfo(Environment.CurrentDirectory + @"\mods2\"));
            form.refreshModList();

            var subfiles = new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp").Subfiles;
            Dictionary<string, uint> CRCValues = new Dictionary<string, uint>();

            foreach (IWriteFile kv in subfiles)
            {
                using (MemoryStream mem = new MemoryStream())
                {
                    kv.WriteTo(mem);

                    var value = DamienG.Security.Cryptography.Crc32.Compute(mem.ToArray());
                    CRCValues.Add(kv.Name, value);
                }
            }

            foreach (ListViewItem lv in form.lsvMods.Items)
                lv.Checked = true;

            Assert.IsTrue(form.inject(true, true, true), "Installation injection failed. Log: {0}", form.labelStatus.Text);

            foreach (Mod m in form.modDict.Values)
            {
                Assert.IsTrue(m.Installed, "Backup archive for {0} was not created.", m.Name);
            }

            Assert.IsTrue(File.Exists(Environment.CurrentDirectory + @"\testdir\jg2e04_00_TEST.pp"), "jg2e04_00_TEST.pp was not created.");
            Assert.IsTrue(File.Exists(Environment.CurrentDirectory + @"\testdir\jg2p01_00_TEST.pp"), "jg2p01_00_TEST.pp was not created.");

            Dictionary<string, uint> diff = new Dictionary<string, uint>();

            foreach (IWriteFile kv in new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp").Subfiles)
            {
                using (MemoryStream mem = new MemoryStream())
                {
                    kv.WriteTo(mem);
                    byte[] buffer = new byte[mem.Length];
                    mem.Position = 0;
                    mem.Read(buffer, 0, (int)mem.Length);

                    var value = DamienG.Security.Cryptography.Crc32.Compute(buffer);
                    if (CRCValues[kv.Name] != value)
                        diff.Add(kv.Name, value);
                }
            }

            Dictionary<string, uint> TrueCRC = new Dictionary<string, uint>()
            {
                { "jg2_01_05_00.lst", 838774076 },
                { "jg2_01_05_01.lst", 1767953068 },
                { "jg2_01_05_02.lst", 1609570759 },
                { "jg2_01_05_03.lst", 4121681499 },
                { "jg2_01_06_05.lst", 32814373 },
                { "jg2_01_06_06.lst", 2454317916 },
                { "jg2_01_06_08.lst", 3999174270 }
            };

            //Assert.IsFalse(subfiles.Count == new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp", new ppFormat_AA2()).Subfiles.Count, "Subfiles have not changed.");
            Assert.IsTrue(diff.Count == TrueCRC.Count, "Amount of changes in jg2p00_00_00.pp was incorrect. Expected value: {0}; Actual value: {1}", TrueCRC.Count, diff.Count);

            foreach (KeyValuePair<string, uint> kv in TrueCRC)
                Assert.IsTrue(kv.Value == diff[kv.Key], "CRC check failed after installation. Key: {0}; Expected value: {1}; Actual value: {2}", kv.Key, kv.Value, diff[kv.Key]);

            foreach (ListViewItem lv in form.lsvMods.Items)
            {
                lv.Checked = false;
                lv.Selected = true;
            }

            //Assert.IsTrue(form.inject(false, false, true), "Uninstallation injection failed. Log: {0}", form.labelStatus.Text);
            form.deleteSelectedMods(true);

            Assert.IsTrue(!File.Exists(Environment.CurrentDirectory + @"\testdir\jg2e04_00_TEST.pp"), "jg2e04_00_TEST.pp was not deleted.");
            Assert.IsTrue(!File.Exists(Environment.CurrentDirectory + @"\testdir\jg2p01_00_TEST.pp"), "jg2p01_00_TEST.pp was not deleted.");

            foreach (Mod m in form.modDict.Values)
            {
                Assert.IsTrue(!m.Installed, "Backup archive for {0} was not deleted.", m.Name);
            }

            Assert.IsTrue(subfiles.Count == new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp").Subfiles.Count, "Amount of restored changes in jg2p00_00_00.pp was incorrect. Expected value: {0}; Actual value: {1}", new object[] { subfiles.Count, new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp").Subfiles.Count });

            foreach (IWriteFile kv in new ppParser(Environment.CurrentDirectory + @"\testdir\jg2p00_00_00.pp").Subfiles)
            {
                using (MemoryStream mem = new MemoryStream())
                {
                    kv.WriteTo(mem);
                    byte[] buffer = new byte[mem.Length];
                    mem.Position = 0;
                    mem.Read(buffer, 0, (int)mem.Length);

                    var value = DamienG.Security.Cryptography.Crc32.Compute(buffer);
                    Assert.IsTrue(CRCValues[kv.Name] == value, "CRC check failed after uninstallation. Key: {0}; Expected value: {1}; Actual value: {2}", kv.Name, CRCValues[kv.Name], value);
                }
            }

            formMain.TryDeleteDirectory(Environment.CurrentDirectory + @"\mods\");
            Directory.Move(Environment.CurrentDirectory + @"\mods2\", Environment.CurrentDirectory + @"\mods\");

            Configuration.saveMods(form.modDict);
        }
Beispiel #17
0
        public static ppSwapfile OpenSwapfile([DefaultVar] ppParser ppParser, IWriteFile parserToSwap)
        {
            ppSwapfile swap = new ppSwapfile(ppParser.FilePath, parserToSwap);

            return(swap);
        }
Beispiel #18
-1
        public void ProcessPP(ppParser pp)
        {
            for (int i = 0; i < pp.Subfiles.Count; i++)
            {
                IWriteFile iw = pp.Subfiles[i];

                if (!iw.Name.EndsWith(".wav"))
                    continue;

                Stream str = Tools.GetReadStream(iw);

                if (!str.CanSeek || str.Length == 0)
                {
                    str.Close();
                    continue;
                }

                using (str)
                using (WaveFileReader wv = new WaveFileReader(str))
                {
                    if (wv.WaveFormat.Channels > 1 || wv.WaveFormat.SampleRate > SampleRate) // || wv.WaveFormat.Encoding != WaveFormatEncoding.Adpcm
                    {
                        WaveFormat f = new WaveFormat(SampleRate, 16, 1); //new AdpcmWaveFormat(wv.WaveFormat.SampleRate, 1);

                        using (MediaFoundationResampler resampledAudio = new MediaFoundationResampler(wv, f))
                        {
                            resampledAudio.ResamplerQuality = 60;

                            MemoryStream o = new MemoryStream();
                            using (WaveFileWriter wr = new WaveFileWriter(o, f))
                            {
                                int count = 0;
                                byte[] buffer = new byte[2048];
                                while ((count = resampledAudio.Read(buffer, 0, 2048)) > 0)
                                {
                                    wr.Write(buffer, 0, count);
                                }
                                wr.Flush();
                                pp.Subfiles[i] = new MemSubfile(ToByteArray(o), iw.Name);
                            }
                        }

                    }
                }

                if (ProgressUpdated != null)
                    ProgressUpdated((int)Math.Floor((double)(100 * i) / pp.Subfiles.Count));
            }
        }