Exemplo n.º 1
0
 private void startToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (AllFiles.Count == 0 || Rules.Count == 0)
     {
         return;
     }
     DebugOutput.StartDebugger("Batch Renamer");
     foreach (string file in AllFiles)
     {
         string s = Path.GetFileName(file);
         foreach (string rule in Rules)
         {
             string[] s2 = rule.Split(':');
             if (s2.Length != 2)
             {
                 continue;
             }
             s = s.Replace(s2[0], s2[1]);
         }
         s = Path.GetDirectoryName(file) + "\\" + s;
         try
         {
             DebugOutput.PrintLn("Trying to move \nfrom:\t" + file + "\nto:\t" + s);
             File.Move(file, s);
             DebugOutput.PrintLn("Success");
         }
         catch (Exception ex)
         {
             DebugOutput.PrintLn("Error : " + ex.ToString());
         }
     }
     MessageBox.Show("Done.");
 }
Exemplo n.º 2
0
 public void LoadPCC(string path)
 {
     timer1.Enabled = false;
     DebugOutput.StartDebugger("LevelEditor");
     SceneMan.AddLevel(path);
     timer1.Enabled = true;
 }
Exemplo n.º 3
0
 public void LoadPCC(string path)
 {
     timer1.Enabled = false;
     DebugOutput.StartDebugger("LevelExplorer");
     LoadME3Package(path);
     SceneMan.AddLevel(pcc as ME3Package);
     timer1.Enabled = true;
 }
Exemplo n.º 4
0
        private void startScanToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(ME3Directory.cookedPath))
            {
                MessageBox.Show("This functionality requires ME3 to be installed. Set its path at:\n Options > Set Custom Path > Mass Effect 3");
                return;
            }
            string pathcook = ME3Directory.cookedPath;

            DebugOutput.StartDebugger("ScriptDB");
            string[] files = Directory.GetFiles(pathcook, "*.pcc");
            int      count = 1;

            database = new List <ScriptEntry>();
            foreach (string file in files)
            {
                DebugOutput.PrintLn(count + "\\" + files.Length + " : Scanning " + Path.GetFileName(file) + " ...");
                try
                {
                    using (IMEPackage pcc = MEPackageHandler.OpenME3Package(file))
                    {
                        int count2 = 0;
                        foreach (ExportEntry ent in pcc.Exports)
                        {
                            if (ent.ClassName == "Function")
                            {
                                Function    f = new Function(ent.Data, ent);
                                ScriptEntry n = new ScriptEntry();
                                n.file = Path.GetFileName(file);
                                n.name = ent.InstancedFullPath;
                                f.ParseFunction();
                                n.script = f.ScriptText;
                                database.Add(n);
                                DebugOutput.PrintLn("\tFound \"" + n.name + "\"", false);
                            }
                            count2++;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error:\n" + ex.Message);
                    DebugOutput.PrintLn("Could not open file: " + Path.GetFileName(file));
                }
                {
                    pb1.Maximum = files.Length;
                    pb1.Value   = count;
                }
                count++;
            }
            RefreshList();
        }
Exemplo n.º 5
0
 private void rebuildSFARToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (DLC == null)
     {
         return;
     }
     DebugOutput.StartDebugger("DLCEditor2");
     DLC.ReBuild();
     DLC = new DLCPackage(DLC.FileName);
     treeView1.Nodes.Clear();
     treeView1.Nodes.Add(DLC.ToTree());
     MessageBox.Show("SFAR Rebuilt.");
 }
Exemplo n.º 6
0
        private void startScanToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult res     = MessageBox.Show("Scan DLCs too?", "", MessageBoxButtons.YesNo);
            bool         scanDLC = (res == System.Windows.Forms.DialogResult.Yes);

            DebugOutput.StartDebugger("Subtitle Scanner");
            Entries = new List <EntryStruct>();
            ScanBasefolder();
            if (scanDLC)
            {
                ScanDLCfolder1();
                ScanDLCfolder2();
            }
            RefreshDisplay();
        }
Exemplo n.º 7
0
        private void startScanToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(ME3Directory.cookedPath))
            {
                MessageBox.Show("This functionality requires ME3 to be installed. Set its path at:\n Options > Set Custom Path > Mass Effect 3");
                return;
            }
            string pathcook = ME3Directory.cookedPath;

            DebugOutput.StartDebugger("ScriptDB");
            string[] files = Directory.GetFiles(pathcook, "*.pcc");
            int      count = 1;

            database = new List <ScriptEntry>();
            foreach (string file in files)
            {
                DebugOutput.PrintLn(count + "\\" + files.Length + " : Scanning " + Path.GetFileName(file) + " ...");
                PCCObject pcc    = new PCCObject(file);
                int       count2 = 0;
                foreach (PCCObject.ExportEntry ent in pcc.Exports)
                {
                    if (ent.ClassName == "Function")
                    {
                        Function    f = new Function(ent.Data, pcc);
                        ScriptEntry n = new ScriptEntry();
                        n.file   = Path.GetFileName(file);
                        n.name   = ent.PackageFullName + "." + ent.ObjectName;
                        n.script = f.ToRawText(false);
                        database.Add(n);
                        DebugOutput.PrintLn("\tFound \"" + n.name + "\"", false);
                    }
                    count2++;
                }
                {
                    pb1.Maximum = files.Length;
                    pb1.Value   = count;
                }
                count++;
            }
            RefreshList();
        }
Exemplo n.º 8
0
        private static string relinkUIndex(IMEPackage importingPCC, ExportEntry relinkingExport, ref int uIndex, string propertyName,
                                           OrderedMultiValueDictionary <IEntry, IEntry> crossPCCObjectMappingList, string prefix, bool importExportDependencies = false)
        {
            if (uIndex == 0)
            {
                return(null); //do not relink 0
            }

            IMEPackage destinationPcc = relinkingExport.FileRef;

            if (importingPCC == destinationPcc && uIndex < 0)
            {
                return(null); //do not relink same-pcc imports.
            }
            int sourceObjReference = uIndex;

            //Debug.WriteLine($"{prefix} Relinking:{propertyName}");

            if (crossPCCObjectMappingList.TryGetValue(entry => entry.UIndex == sourceObjReference, out IEntry targetEntry))
            {
                //relink
                uIndex = targetEntry.UIndex;

                //Debug.WriteLine($"{prefix} Relink hit: {sourceObjReference}{propertyName} : {targetEntry.FullPath}");
            }
            else if (uIndex < 0) //It's an unmapped import
            {
                //objProperty is currently pointing to importingPCC as that is where we read the properties from
                int n         = uIndex;
                int origvalue = n;
                //Debug.WriteLine("Relink miss, attempting JIT relink on " + n + " " + rootNode.Text);
                if (importingPCC.IsImport(n))
                {
                    //Get the original import
                    ImportEntry origImport         = importingPCC.GetImport(n);
                    string      origImportFullName = origImport.FullPath;
                    //Debug.WriteLine("We should import " + origImport.GetFullPath);

                    IEntry crossImport          = null;
                    string linkFailedDueToError = null;
                    try
                    {
                        crossImport = EntryImporter.GetOrAddCrossImportOrPackage(origImportFullName, importingPCC, destinationPcc);
                    }
                    catch (Exception e)
                    {
                        //Error during relink
                        DebugOutput.StartDebugger("PCC Relinker");
                        DebugOutput.PrintLn("Exception occured during relink: ");
                        DebugOutput.PrintLn(ExceptionHandlerDialogWPF.FlattenException(e));
                        DebugOutput.PrintLn("You may want to consider discarding this sessions' changes as relinking was not able to properly finish.");
                        linkFailedDueToError = e.Message;
                    }

                    if (crossImport != null)
                    {
                        crossPCCObjectMappingList.Add(origImport, crossImport); //add to mapping to speed up future relinks
                        uIndex = crossImport.UIndex;
                        // Debug.WriteLine($"Relink hit: Dynamic CrossImport for {origvalue} {importingPCC.GetEntry(origvalue).FullPath} -> {uIndex}");
                    }
                    else
                    {
                        string path = importingPCC.GetEntry(uIndex) != null?importingPCC.GetEntry(uIndex).FullPath : "Entry not found: " + uIndex;

                        if (linkFailedDueToError != null)
                        {
                            Debug.WriteLine($"Relink failed: CrossImport porting failed for {relinkingExport.ObjectName.Instanced} {relinkingExport.UIndex}: {propertyName} ({uIndex}): {importingPCC.GetEntry(origvalue).FullPath}");
                            return($"Relink failed for {prefix}{propertyName} {uIndex} in export {path}({relinkingExport.UIndex}): {linkFailedDueToError}");
                        }

                        if (destinationPcc.GetEntry(uIndex) != null)
                        {
                            Debug.WriteLine($"Relink failed: CrossImport porting failed for {relinkingExport.ObjectName.Instanced} {relinkingExport.UIndex}: {propertyName} ({uIndex}): {importingPCC.GetEntry(origvalue).FullPath}");
                            return($"Relink failed: CrossImport porting failed for {prefix}{propertyName} {uIndex} {destinationPcc.GetEntry(uIndex).FullPath} in export {relinkingExport.FullPath}({relinkingExport.UIndex})");
                        }

                        return($"Relink failed: New export does not exist - this is probably a bug in cross import code for {prefix}{propertyName} {uIndex} in export {relinkingExport.FullPath}({relinkingExport.UIndex})");
                    }
                }
            }
            else
            {
                //It's an export
                //Attempt lookup
                ExportEntry sourceExport  = importingPCC.GetUExport(uIndex);
                string      fullPath      = sourceExport.FullPath;
                int         indexValue    = sourceExport.indexValue;
                IEntry      existingEntry = destinationPcc.Exports.FirstOrDefault(x => x.FullPath == fullPath && indexValue == x.indexValue);
                existingEntry ??= destinationPcc.Imports.FirstOrDefault(x => x.FullPath == fullPath);
                if (existingEntry != null)
                {
                    //Debug.WriteLine($"Relink hit [EXPERIMENTAL]: Existing entry in file was found, linking to it:  {uIndex} {sourceExport.InstancedFullPath} -> {existingEntry.InstancedFullPath}");
                    uIndex = existingEntry.UIndex;
                }
                else if (importExportDependencies)
                {
                    if (!crossPCCObjectMappingList.TryGetValue(sourceExport.Parent, out IEntry parent))
                    {
                        parent = EntryImporter.GetOrAddCrossImportOrPackage(sourceExport.ParentFullPath, importingPCC, destinationPcc, true, crossPCCObjectMappingList);
                    }
                    ExportEntry importedExport = EntryImporter.ImportExport(destinationPcc, sourceExport, parent?.UIndex ?? 0, true, crossPCCObjectMappingList);
                    uIndex = importedExport.UIndex;
                }
                else
                {
                    string path = importingPCC.GetEntry(uIndex)?.FullPath ?? $"Entry not found: {uIndex}";
                    Debug.WriteLine($"Relink failed in {relinkingExport.ObjectName.Instanced} {relinkingExport.UIndex}: {propertyName} {uIndex} {path}");
                    return($"Relink failed: {prefix}{propertyName} {uIndex} in export {relinkingExport.FullPath}({relinkingExport.UIndex})");
                }
            }

            return(null);
        }
Exemplo n.º 9
0
 public SFAREditor2()
 {
     InitializeComponent();
     DebugOutput.StartDebugger("SFAR Editor 2");
 }
Exemplo n.º 10
0
 private void openDebugWindowToolStripMenuItem_Click(object sender, EventArgs e)
 {
     DebugOutput.StartDebugger("ME3 Level Explorer");
 }
Exemplo n.º 11
0
        private void scanToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(ME3Directory.cookedPath))
            {
                MessageBox.Show("This functionality requires ME3 to be installed. Set its path at:\n Options > Set Custom Path > Mass Effect 3");
                return;
            }
            DebugOutput.StartDebugger("Meshplorer2");
            int count = 0;

            timer1.Enabled = false;
            Entries        = new List <EntryStruct>();
            bool ScanDLC = false;

            if (MessageBox.Show("Scan DLCs too?", "Meshplorer 2", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                ScanDLC = true;
            }
            if (ScanDLC)
            {
                #region DLC Stuff
                string dirDLC = ME3Directory.DLCPath;
                if (!Directory.Exists(dirDLC))
                {
                    DebugOutput.PrintLn("No DLC Folder found!");
                }
                else
                {
                    string[] subdirs = Directory.GetDirectories(dirDLC);
                    string   loc     = Path.GetDirectoryName(Application.ExecutablePath) + "\\exec\\";
                    Directory.CreateDirectory(loc + "temp");
                    foreach (string DLCpath in subdirs)
                    {
                        if (!DLCpath.StartsWith("__") && !DLCpath.StartsWith("DLC_UPD"))
                        {
                            string  path = DLCpath + "\\CookedPCConsole\\Default.sfar";
                            DLCBase dlcbase;
                            try
                            {
                                dlcbase       = new DLCBase(path);
                                count         = 0;
                                pbar1.Maximum = dlcbase.fileList.Count;
                                foreach (sfarFile file in dlcbase.fileList)
                                {
                                    try
                                    {
                                        string filename = Path.GetFileName(file.fileName);
                                        if (Path.GetExtension(filename).ToLower().EndsWith(".pcc"))
                                        {
                                            using (Stream input = File.OpenRead(path), output = File.Create(loc + "temp\\" + filename))
                                            {
                                                AmaroK86.MassEffect3.DLCUnpack.DecompressEntry(file, input, output, dlcbase.CompressionScheme);
                                            }
                                            FileInfo f = new FileInfo(loc + "temp\\" + filename);
                                            DebugOutput.PrintLn("checking DLC: " + Path.GetFileName(DLCpath) + " File: " + filename + " Size: " + f.Length + " bytes", count % 3 == 0);
                                            PCCObject pcc = new PCCObject(loc + "temp\\" + filename);
                                            for (int i = 0; i < pcc.Exports.Count; i++)
                                            {
                                                if (pcc.Exports[i].ClassName == "SkeletalMesh" ||
                                                    pcc.Exports[i].ClassName == "StaticMesh")
                                                {
                                                    EntryStruct ent = new EntryStruct();
                                                    ent.DLCName    = Path.GetFileName(DLCpath);
                                                    ent.Filename   = filename;
                                                    ent.Index      = i;
                                                    ent.isDLC      = true;
                                                    ent.ObjectPath = pcc.Exports[i].GetFullPath;
                                                    ent.isSkeletal = (pcc.Exports[i].ClassName == "SkeletalMesh");
                                                    Entries.Add(ent);
                                                }
                                            }
                                            File.Delete(loc + "temp\\" + filename);
                                        }
                                        if (count % 3 == 0)
                                        {
                                            pbar1.Value = count;
                                            Application.DoEvents();
                                        }
                                        count++;
                                    }
                                    catch (Exception ex)
                                    {
                                        DebugOutput.PrintLn("=====ERROR=====\n" + ex.ToString() + "\n=====ERROR=====");
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                DebugOutput.PrintLn("=====ERROR=====\n" + ex.ToString() + "\n=====ERROR=====");
                            }
                        }
                    }
                    Directory.Delete(loc + "temp", true);
                }
                #endregion
            }
            #region Basegame Stuff
            string   dir   = ME3Directory.cookedPath;
            string[] files = Directory.GetFiles(dir, "*.pcc");
            pbar1.Maximum = files.Length - 1;
            foreach (string file in files)
            {
                DebugOutput.PrintLn("Scan file #" + count + " : " + file, count % 10 == 0);
                try
                {
                    PCCObject pcc = new PCCObject(file);
                    for (int i = 0; i < pcc.Exports.Count; i++)
                    {
                        if (pcc.Exports[i].ClassName == "SkeletalMesh" ||
                            pcc.Exports[i].ClassName == "StaticMesh")
                        {
                            EntryStruct ent = new EntryStruct();
                            ent.DLCName    = "";
                            ent.Filename   = Path.GetFileName(file);
                            ent.Index      = i;
                            ent.isDLC      = false;
                            ent.ObjectPath = pcc.Exports[i].GetFullPath;
                            ent.isSkeletal = (pcc.Exports[i].ClassName == "SkeletalMesh");
                            Entries.Add(ent);
                        }
                    }
                    if (count % 10 == 0)
                    {
                        Application.DoEvents();
                        pbar1.Value = count;
                    }
                    count++;
                }
                catch (Exception ex)
                {
                    DebugOutput.PrintLn("=====ERROR=====\n" + ex.ToString() + "\n=====ERROR=====");
                }
            }
            #endregion
            #region Sorting
            bool run = true;
            DebugOutput.PrintLn("=====Info=====\n\nSorting names...\n\n=====Info=====");
            count = 0;
            while (run)
            {
                run = false;
                for (int i = 0; i < Entries.Count - 1; i++)
                {
                    if (Entries[i].Filename.CompareTo(Entries[i + 1].Filename) > 0)
                    {
                        EntryStruct tmp = Entries[i];
                        Entries[i]     = Entries[i + 1];
                        Entries[i + 1] = tmp;
                        run            = true;
                        if (count++ % 100 == 0)
                        {
                            Application.DoEvents();
                        }
                    }
                }
            }
            #endregion
            TreeRefresh();
            timer1.Enabled = true;
        }
Exemplo n.º 12
0
        public DLCEditor2()
        {
            InitializeComponent();

            //FemShep's Mod Manager 3 automator for DLCEditor2.
            string[] arguments = Environment.GetCommandLineArgs();
            if (arguments.Length > 2)
            {
                try
                {
                    string cmdCommand = arguments[1];
                    if (cmdCommand.Equals("-dlcinject", StringComparison.Ordinal))
                    {
                        if (arguments.Length % 2 != 1 || arguments.Length < 5)
                        {
                            MessageBox.Show("Wrong number of arguments for the -dlcinject switch.:\nSyntax is: <exe> -dlcinject SFARPATH SEARCHTERM NEWFILEPATH [SEARCHTERM2 NEWFILEPATH2]...", "ME3 DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        string dlcFileName = arguments[2];
                        int    numfiles    = (arguments.Length - 3) / 2;

                        string[] filesToReplace = new String[numfiles];
                        string[] newFiles       = new String[numfiles];

                        int argnum = 3; //starts at 3
                        for (int i = 0; i < filesToReplace.Length; i++)
                        {
                            filesToReplace[i] = arguments[argnum];
                            argnum++;
                            newFiles[i] = arguments[argnum];
                            argnum++;
                        }
                        automated = true;
                        if (File.Exists(dlcFileName))
                        {
                            openSFAR(dlcFileName);
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("dlcFilename does not exist: " + dlcFileName);
                            MessageBox.Show("Failed to autoinject: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        //SFAR was opened.
                        //Now we search for the element to replace so it is selected...
                        for (int i = 0; i < numfiles; i++)
                        {
                            selectSearchedElement(filesToReplace[i]);
                            //the element is now selected, hopefully.
                            TreeNode t = treeView1.SelectedNode;
                            if (DLC == null || t == null || t.Parent == null || t.Parent.Text != "FileEntries")
                            {
                                MessageBox.Show("DLCEditor2 automator encountered an error: the file to replace does not exist or the tree has not been initialized.", "ME3 DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            replaceFile(newFiles[i], t.Index);
                        }
                    }
                    else if (cmdCommand.Equals("-dlcextract", StringComparison.Ordinal))
                    {
                        if (arguments.Length != 5)
                        {
                            //-2 for me3explorer & -dlcextract
                            MessageBox.Show("Wrong number of arguments for the -dlcinject switch.:\nSyntax is: <exe> -dlcextract SFARPATH SEARCHTERM EXTRACTIONPATH", "ME3 DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        automated = true;
                        string dlcFileName    = arguments[2];
                        string searchTerm     = arguments[3];
                        string extractionPath = arguments[4];
                        if (File.Exists(dlcFileName))
                        {
                            openSFAR(dlcFileName);
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("dlcFilename does not exist: " + dlcFileName);
                            MessageBox.Show("Failed to autoextract: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        //SFAR was opened.
                        //Now we search for the element to extract so it is selected...
                        selectSearchedElement(searchTerm);
                        //the element is now selected, hopefully.
                        TreeNode t = treeView1.SelectedNode;
                        if (DLC == null || t == null || t.Parent == null || t.Parent.Text != "FileEntries")
                        {
                            MessageBox.Show("DLCEditor2 extraction automator encountered an error:\nThe file to replace does not exist or the tree has not been initialized.", "DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        extractFile(t.Index, extractionPath);
                    }
                    else if (cmdCommand.Equals("-dlcaddfiles", StringComparison.Ordinal))
                    {
                        if (arguments.Length % 2 != 1 || arguments.Length < 5)
                        {
                            MessageBox.Show("Wrong number of arguments for the -dlcaddfiles switch.:\nSyntax is: <exe> -dlcinject SFARPATH INTERNALPATH NEWFILEPATH [INTERNALPATH2 NEWFILEPATH2]...", "ME3 DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }

                        automated = true;
                        string dlcFileName = arguments[2];

                        int      numfiles      = (arguments.Length - 3) / 2;
                        string[] internalPaths = new String[numfiles];
                        string[] sourcePaths   = new String[numfiles];

                        int argnum = 3; //starts at 3
                        for (int i = 0; i < internalPaths.Length; i++)
                        {
                            internalPaths[i] = arguments[argnum];
                            argnum++;
                            sourcePaths[i] = arguments[argnum];
                            argnum++;
                        }

                        if (File.Exists(dlcFileName))
                        {
                            openSFAR(dlcFileName);
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("DLC does not exist: " + dlcFileName);
                            MessageBox.Show("Failed to autoadd: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        //SFAR was opened.
                        for (int i = 0; i < internalPaths.Length; i++)
                        {
                            System.Diagnostics.Debug.WriteLine("Adding file quick: " + sourcePaths[i] + " " + internalPaths[i]);
                            DLC.AddFileQuick(sourcePaths[i], internalPaths[i]);
                            DLC = new DLCPackage(DLC.MyFileName);
                            treeView1.Nodes.Clear();
                            treeView1.Nodes.Add(DLC.ToTree());
                        }
                    }
                    else if (cmdCommand.Equals("-dlcremovefiles", StringComparison.Ordinal))
                    {
                        if (arguments.Length < 4)
                        {
                            //-2 for me3explorer & -dlcextract
                            MessageBox.Show("Wrong number of arguments for the -dlcremovefiles switch.:\nSyntax is: <exe> -dlcinject SFARPATH INTERNALPATH [INTERNALPATH2]...", "ME3 DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        automated = true;
                        string dlcFileName = arguments[2];

                        int numfiles = (arguments.Length - 3);

                        string[] filesToRemove = new String[numfiles];

                        int argnum = 3; //starts at 3
                        for (int i = 0; i < filesToRemove.Length; i++)
                        {
                            filesToRemove[i] = arguments[argnum];
                            argnum++;
                        }

                        if (File.Exists(dlcFileName))
                        {
                            openSFAR(dlcFileName);
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("DLC does not exist: " + dlcFileName);
                            MessageBox.Show("Failed to autoremove: DLC file does not exist: " + dlcFileName, "ME3Explorer DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        //SFAR was opened.
                        for (int i = 0; i < filesToRemove.Length; i++)
                        {
                            selectSearchedElement(filesToRemove[i]);
                            //the element is now selected, hopefully.
                            TreeNode t = treeView1.SelectedNode;
                            if (DLC == null || t == null || t.Parent == null || t.Parent.Text != "FileEntries")
                            {
                                MessageBox.Show("DLCEditor2 file removal automator encountered an error:\nThe file to remove does not exist or the tree has not been initialized.", "DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                Application.Exit();
                                return;
                            }
                            DLC.DeleteEntry(t.Index);
                            DLC = new DLCPackage(DLC.MyFileName);
                            treeView1.Nodes.Clear();
                            treeView1.Nodes.Add(DLC.ToTree());
                        }
                    }
                    else if (cmdCommand.Equals("-dlcunpack", StringComparison.Ordinal) || cmdCommand.Equals("-dlcunpack-nodebug", StringComparison.Ordinal))
                    {
                        if (arguments.Length != 4)
                        {
                            MessageBox.Show("Wrong number of arguments for automated DLC unpacking:\nSyntax is: <exe> -dlcinject SFARPATH EXTRACTIONPATH", "ME3 DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }


                        string sfarPath = arguments[2];
                        autoUnpackFolder = arguments[3];

                        automated = true;
                        if (File.Exists(sfarPath))
                        {
                            openSFAR(sfarPath);
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("DLC does not exist: " + sfarPath);
                            MessageBox.Show("Failed to autounpack: DLC file does not exist: " + sfarPath, "ME3Explorer DLCEditor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Application.Exit();
                            return;
                        }
                        //SFAR was opened.
                        if (cmdCommand.Equals("-dlcunpack"))
                        {
                            DebugOutput.StartDebugger("DLC Editor 2"); //open debugging window since this operation takes a long time. The main debugger won't start as this will exit before that code can be reached
                        }
                        //Simulate Unpack operation click.
                        unpackSFARToolStripMenuItem.PerformClick();
                    }
                }
                catch (FileNotFoundException exc)
                {
                    MessageBox.Show("Failed to run DLCEditor2 Automator with the specified parameters.\n\nA file not found error occured while trying to automate a task.\n" + exc.Message, "DLC Editor2 Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(1);
                    Application.Exit();
                }
                Environment.Exit(0);
                Application.Exit();
            }
            DebugOutput.StartDebugger("DLC Editor 2"); //open debugging window AFTER automation. Otherwise it pops up all weirdlike.
        }