Пример #1
0
        /// <summary>
        /// The tree view 1_ drag drop.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        /// <remarks></remarks>
        private void treeView1_DragDrop(object sender, DragEventArgs e)
        {
            MapForm f = (MapForm)e.Data.GetData(this.GetType());
            this.treeView1.PathSeparator = ".";
            f.treeView1.PathSeparator = ".";
            string lastPath = f.treeView1.SelectedNode.FullPath;
            f.treeView1.PathSeparator = "\\";
            if (f == this)
            {
                return;
            }

            // try
            // {
            this.Enabled = false;
            this.Focus();
            ArrayList metas = new ArrayList(0);

            metas = f.scanandpassmetasfordraganddrop();

            int x = 0;
            while (x < metas.Count)
            {
                Meta temp = (Meta)metas[x];
                string tagtype = temp.type;
                string tagname = temp.name;
                int tempint = map.Functions.ForMeta.FindByNameAndTagType(tagtype, tagname);
                if (tempint != -1)
                {
                    metas.RemoveAt(x);
                    continue;
                }

                temp.RelinkReferences();
                x++;
            }

            if (x > 0)
            {
                MapAnalyzer analyze = new MapAnalyzer();
                MapLayout layout = analyze.ScanMapForLayOut(map, false);
                layout.ReadChunks(map);
                Builder build = new Builder();
                build.MapBuilder(metas, ref layout, map, soundsCheckBox.Checked);
                map = Map.Refresh(map);
                formFuncs.AddMetasToTreeView(map, treeView1, metaView, false);
            }

            ChunkClonerWindow.ExpandToNode(treeView1.Nodes, lastPath, treeView1.PathSeparator);
            this.treeView1.PathSeparator = "\\";
            this.Enabled = true;
            MessageBox.Show(x + " metas transferred\nDone");

            // }
            // catch
            // {
            this.Enabled = true;

            // }
        }
Пример #2
0
        /// <summary>
        /// The inject obj tool strip menu item_ click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        /// <remarks></remarks>
        private void injectOBJToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            ParsedModel pm = new ParsedModel(ref map.SelectedMeta);
            Meta addme = pm.InjectModel(folderBrowserDialog.SelectedPath, map.SelectedMeta);
            addme.name += "(new)";
            addme.name = GetNameDialog.Show("Choose injection name", "Meta Name:", addme.name, "OK");

            ArrayList oi = new ArrayList();
            oi.Add(addme);
            MapAnalyzer analyze = new MapAnalyzer();

            MapLayout layout = analyze.ScanMapForLayOut(map, false);
            layout.ReadChunks(map);
            Builder build = new Builder();
            build.MapBuilder(oi, ref layout, map, false);

            map = Map.Refresh(map);
            formFuncs.AddMetasToTreeView(map, treeView1, metaView, false);
            this.Enabled = true;
            MessageBox.Show("Done");
        }
Пример #3
0
        /// <summary>
        /// The inject mesh from obj tool strip menu item_ click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        /// <remarks></remarks>
        private void injectMeshFromOBJToolStripMenuItem_Click(object sender, EventArgs e)
        {
            folderBrowserDialog.SelectedPath = Prefs.pathExtractsFolder;
            if (folderBrowserDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            Prefs.pathExtractsFolder = folderBrowserDialog.SelectedPath;

            Form tempForm = new Form();
            tempForm.ControlBox = false;
            tempForm.FormBorderStyle = FormBorderStyle.FixedDialog;
            tempForm.Size = new Size(250, 100);
            Label tempLabel = new Label();
            tempLabel.AutoSize = true;
            tempLabel.Location = new Point(20, 20);
            tempLabel.Text = "Loading BSP, please wait...";
            ProgressBar tempPB = new ProgressBar();
            tempPB.Location = new Point(20, 60);
            tempPB.Size = new Size(210, 20);
            tempPB.Minimum = 0;
            tempPB.Maximum = 100;
            tempForm.Controls.Add(tempLabel);
            tempForm.Controls.Add(tempPB);
            tempForm.Show();
            Application.DoEvents();

            BSPModel pm = new BSPModel(ref map.SelectedMeta);
            tempLabel.Text = "Loading Model...";
            tempPB.Value = 35;
            Application.DoEvents();
            Meta addme = pm.InjectModel(folderBrowserDialog.SelectedPath, map.SelectedMeta);

            /*
            addme.name += "(new)";
            addme.name = getNameDialog.Show("Choose injection name", "Meta Name:", addme.name, "OK");
            */
            ArrayList oi = new ArrayList();
            oi.Add(addme);

            tempLabel.Text = "Analyzing Layout...";
            tempPB.Value = 60;
            Application.DoEvents();

            MapAnalyzer analyze = new MapAnalyzer();
            MapLayout layout = analyze.ScanMapForLayOut(map, false);
            layout.ReadChunks(map);

            tempLabel.Text = "Rebuilding Map...";
            tempPB.Value = 70;
            Application.DoEvents();

            Builder build = new Builder();
            build.MapBuilder(oi, ref layout, map, false);

            tempLabel.Text = "Refreshing Map...";
            tempPB.Value = 95;
            Application.DoEvents();
            map = Map.Refresh(map);
            formFuncs.AddMetasToTreeView(map, treeView1, metaView, false);
            this.Enabled = true;

            #region Remove form that shows progress

            tempForm.Dispose();

            #endregion

            MessageBox.Show("Done");
        }
Пример #4
0
        /// <summary>
        /// The duplicate tool strip menu item_ click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        /// <remarks></remarks>
        private void duplicateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (map.SelectedMeta == null)
            {
                return;
            }

            string nodePath = treeView1.SelectedNode.FullPath;
            this.Enabled = false;
            this.Focus();

            MapAnalyzer analyze = new MapAnalyzer();

            MapLayout layout = analyze.ScanMapForLayOut(map, false);
            layout.ReadChunks(map);
            Builder build = new Builder();
            ArrayList metas = new ArrayList();

            string[] temps = map.SelectedMeta.name.Split('(', ')', ' ');
            newName = temps[0];
            int tempcount = 1;
            do
            {
                bool done = false;
                newName = temps[0] + " (" + tempcount + ")";
                int index = Array.IndexOf(map.FileNames.Name, newName);
                if (index == -1)
                {
                    break;
                }

                do
                {
                    if (map.MetaInfo.TagType[index] == map.SelectedMeta.type)
                    {
                        tempcount += 1;
                        break;
                    }

                    index = Array.IndexOf(map.FileNames.Name, newName, index + 1);
                    if (index == -1)
                    {
                        done = true;
                        break;
                    }
                }
                while (tempcount != -1);
                if (done)
                {
                    break;
                }
            }
            while (tempcount != -1);

            // Create a form for renaming a new tag
            AskForTagName();

            if (newName != string.Empty)
            {
                addToQuickList(map.SelectedMeta.type, newName);
                map.SelectedMeta.name = newName;
                metas.Add(map.SelectedMeta);
                build.MapBuilder(metas, ref layout, map, soundsCheckBox.Checked);

                // Leaves map locked!
                map = Map.Refresh(map);
                //

                formFuncs.AddMetasToTreeView(map, treeView1, metaView, false);

                setNodePath(treeView1, newName);

                // MessageBox.Show("Done");
            }

            this.Enabled = true;
        }
Пример #5
0
        /// <summary>
        /// The duplicate recursively tool strip menu item_ click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        /// <remarks></remarks>
        private void duplicateRecursivelyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (map.SelectedMeta == null)
            {
                return;
            }

            this.Enabled = false;
            this.Focus();

            MapAnalyzer analyze = new MapAnalyzer();

            MapLayout layout = analyze.ScanMapForLayOut(map, false);
            layout.ReadChunks(map);
            Builder build = new Builder();
            ArrayList metas = new ArrayList();
            metas = scanandpassmetasfordraganddrop();

            // Holds name before renaming
            ArrayList metaNameBackup = new ArrayList();

            // Create new indexed names for each tag to be duplicated
            for (int x = 0; x < metas.Count; x++)
            {
                string[] temps = ((Meta)metas[x]).name.Split('(', ')', ' ');
                string newname = temps[0];
                int tempcount = 1;
                do
                {
                    bool done = false;
                    newname = temps[0] + " (" + tempcount + ")";
                    int index = Array.IndexOf(map.FileNames.Name, newname);
                    if (index == -1)
                    {
                        break;
                    }

                    do
                    {
                        if (map.MetaInfo.TagType[index] == ((Meta)metas[x]).type)
                        {
                            tempcount += 1;
                            break;
                        }

                        index = Array.IndexOf(map.FileNames.Name, newname, index + 1);
                        if (index == -1)
                        {
                            done = true;
                            break;
                        }
                    }
                    while (tempcount != -1);
                    if (done)
                    {
                        break;
                    }
                }
                while (tempcount != -1);
                // Save original tag Index, type, new name, (space for) new ident
                metaNameBackup.Add(new object[4] { ((Meta)metas[x]).TagIndex, ((Meta)metas[x]).type, newname, -1 });
                ((Meta)metas[x]).name = newname;
            }

            string temp = ((Meta)metas[0]).name;
            addToQuickList(map.SelectedMeta.type, temp);
            build.MapBuilder(metas, ref layout, map, soundsCheckBox.Checked);

            // Update new tags
            map = Map.Refresh(map);
            metas = scanandpassmetasfordraganddrop();

            // Redirect all pointers within tags to point to duplicated tags
            map.OpenMap(MapTypes.Internal);
            for (int count = 0; count < metaNameBackup.Count; count++)
            {
                if (this.progressbar.Value != count * 100 / metaNameBackup.Count)
                {
                    this.progressbar.Value = count * 100 / metaNameBackup.Count;
                    Application.DoEvents();
                }
                object[] o = (object[])metaNameBackup[count];

                for (int x = 0; x < metas.Count; x++)
                {
                    Meta m = (Meta)metas[x];

                    // Find matching tag (cannot access metas[count] directly as some tags get removed)
                    //if (m.type != (string)o[1] || m.name != (string)o[2])
                    if (m.TagIndex != (int)o[0])
                            continue;
                    int index = map.Functions.ForMeta.FindByNameAndTagType((string)o[1], (string)o[2]);

                    if (index != -1)
                        o[3] = map.MetaInfo.Ident[index];
                    else
                        o[3] = m.ident;
                    break;
                }
                // (Only?) First listing is wrong due to already being renamed, so just grab it from the map
                if ((int)o[3] == -1)
                {
                    int index = map.Functions.ForMeta.FindByNameAndTagType((string)o[1], (string)o[2]);
                    if (index != -1)
                        o[3] = map.MetaInfo.Ident[index];
                }
            }

            // Write updated Idents to all listings in the map file
            foreach (Meta m in metas)
            {
                if (this.progressbar.Value != metas.IndexOf(m) * 100 / metas.Count)
                {
                    this.progressbar.Value = metas.IndexOf(m) * 100 / metas.Count;
                    Application.DoEvents();
                }
                foreach (HaloMap.Meta.Meta.Item i in m.items)
                    if (i is Meta.Ident)
                    {
                        Meta.Ident id = (Meta.Ident)i;
                        for (int count = 0; count < metaNameBackup.Count; count++)
                        {
                            object[] o = (object[])metaNameBackup[count];
                            if ((int)o[0] == id.pointstoTagIndex)
                            {
                                /*
                                BinaryReader br = new BinaryReader(m.MS);
                                br.BaseStream.Position = id.offset;
                                int lll = br.ReadInt32();
                                map.BR.BaseStream.Position = id.mapOffset;
                                int llll = map.BR.ReadInt32();
                                */

                                map.BW.BaseStream.Position = id.mapOffset;
                                map.BW.Write((int)o[3]);
                            }
                        }
                    }
            }
            map.CloseMap();

            map = Map.Refresh(map);

            // ME2 stores pointer to loaded map, so we need to close all open tabs to ensure compatibilty
            if (wME != null)
                wME.Dispose();

            formFuncs.AddMetasToTreeView(map, treeView1, metaView, false);
            setNodePath(treeView1, temp);
            this.progressbar.Value = 0;
            this.Enabled = true;

            // MessageBox.Show("Done");
        }
Пример #6
0
        /// <summary>
        /// The build button_ click_1.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        /// <remarks></remarks>
        private void buildButton_Click_1(object sender, EventArgs e)
        {
            if (openInfoFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            this.Enabled = false;
            this.Focus();

            MapAnalyzer analyze = new MapAnalyzer();

            MapLayout layout = analyze.ScanMapForLayOut(map, false);
            layout.ReadChunks(map);
            Builder build = new Builder();
            build.BuildMapFromInfoFile(openInfoFileDialog.FileName, ref layout, map, soundsCheckBox.Checked);

            map = Map.Refresh(map);
            formFuncs.AddMetasToTreeView(map, treeView1, metaView, false);
            this.Enabled = true;
            MessageBox.Show("Done");
        }