예제 #1
0
        private void exportToWAVToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            int index = ObjectIndexes[n];

            PCCObject.ExportEntry ex = pcc.Exports[index];
            if (ex.ClassName == "WwiseStream")
            {
                SaveFileDialog d = new SaveFileDialog();
                d.Filter = "*.wav|*.wav";
                if (ex.ObjectName.Length > 4)
                {
                    d.FileName = ex.ObjectName.Substring(0, ex.ObjectName.Length - 4);
                }
                if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string path = getPathToAFC();
                    if (path != "")
                    {
                        Status.Text = "Exporting...";
                        w.ExtractToFile(path, d.FileName, false);
                        Status.Text = "Ready";
                        MessageBox.Show("Done");
                    }
                }
            }
        }
예제 #2
0
        public void AddLevel(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }
            Levelfile l = new Levelfile();

            l.path = path;
            l.pcc  = new PCCObject(path);
            for (int i = 0; i < l.pcc.Exports.Count; i++)
            {
                PCCObject.ExportEntry e = l.pcc.Exports[i];
                if (e.ClassName == "Level")
                {
                    DebugOutput.Clear();
                    l.level = new Level(l.pcc, i);
                    TreeNode t = new TreeNode(Path.GetFileName(path));
                    t.Nodes.Add(l.level.ToTree(i));
                    GlobalTree.Visible = false;
                    GlobalTree.Nodes.Add(t);
                    GlobalTree.Visible    = true;
                    DirectXGlobal.Cam.dir = new Vector3(1.0f, 1.0f, 1.0f);
                    Levels.Add(l);
                }
            }
        }
예제 #3
0
 private void removeTopImageToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count == 0)
     {
         return;
     }
     if (tex2D.imgList.Count == 1)
     {
         MessageBox.Show("Only 1 image present. You can't remove that", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return;
     }
     try
     {
         tex2D.removeImage();
         ListViewItem item  = listView1.SelectedItems[0];
         int          index = Convert.ToInt32(item.Name);
         // copy export data
         PCCObject.ExportEntry expEntry = pcc.Exports[index];
         // change data with new tex data
         expEntry.Data = tex2D.ToArray(expEntry.DataOffset);
         MessageBox.Show("Texture successfuly removed");
     }
     catch (Exception exc)
     {
         MessageBox.Show("An error occurred while removing texture: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #4
0
        public void ImportSound()
        {
            if (listView1.SelectedItems.Count != 1 || pcc == null)
            {
                return;
            }
            ListViewItem item  = listView1.SelectedItems[0];
            int          index = Convert.ToInt32(item.Name);

            if (pcc.Exports[index].ClassName == "WwiseStream")
            {
                OpenFileDialog o = new OpenFileDialog();
                o.Filter = "Wwise wav (*.wav)|*.wav";
                if (o.ShowDialog() == DialogResult.OK)
                {
                    w = new WwiseStream(pcc, index);
                    w.ImportFromFile(o.FileName, pathCooked);
                    byte[] buff = new byte[w.memsize];
                    for (int i = 0; i < w.memsize; i++)
                    {
                        buff[i] = w.memory[i];
                    }
                    PCCObject.ExportEntry ent = pcc.Exports[index];
                    ent.Data = buff;
                    //pcc.ChangeExportEntry(index, CopyExport(ent));
                    MessageBox.Show("Done.");
                }
            }
        }
예제 #5
0
        public TreeNode ToTreeSimple(int nr)
        {
            TreeNode t = new TreeNode("#" + nr + " Level");

            DebugOutput.PrintLn("Generating Tree...");
            for (int i = 0; i < Objects.Count(); i++)
            {
                int index = Objects[i];
                if (index > 0)
                {
                    PCCObject.ExportEntry e = pcc.Exports[index];
                    DebugOutput.PrintLn((i + 1) + " / " + Objects.Count + " : \"" + e.ObjectName + "\" - \"" + e.ClassName + "\"");
                    switch (e.ClassName)
                    {
                    default:
                        string s = "#" + index + " : \"";
                        s += e.ObjectName + "\" CLASS : \"";
                        s += e.ClassName + "\"";
                        TreeNode t1 = new TreeNode(s);
                        t.Nodes.Add(t1);
                        break;
                    }
                }
                else
                {
                    TreeNode t1 = new TreeNode("#" + index + " : NOT IMPLEMENTED");
                    t.Nodes.Add(t1);
                }
            }
            return(t);
        }
예제 #6
0
        public void LetsDump()
        {
            pb1.Minimum = 0;
            pb1.Maximum = pcc.Exports.Count;
            rtb1.Text   = "";
            int    count = 0;
            string t     = "";

            for (int i = 0; i < pcc.Exports.Count; i++)
            {
                PCCObject.ExportEntry e = pcc.Exports[i];
                string s = "Properties for Object #" + i + " \"" + e.ObjectName + "\" :\n\n";
                List <PropertyReader.Property> p = PropertyReader.getPropList(pcc, e.Data);
                foreach (PropertyReader.Property prop in p)
                {
                    s += PropertyReader.PropertyToText(prop, pcc) + "\n";
                }
                s += "\n";
                t += s;
                if (count++ > 100)
                {
                    count       = 0;
                    pb1.Value   = i;
                    Status.Text = "State : " + i + " / " + pcc.Exports.Count;
                    Application.DoEvents();
                }
            }
            Status.Text          = "State : Done";
            rtb1.Text            = t;
            rtb1.SelectionStart  = rtb1.TextLength;
            rtb1.SelectionLength = 0;
            rtb1.ScrollToCaret();
            pb1.Value = 0;
        }
예제 #7
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            rtb1.Text    = "";
            rtb1.Visible = true;
            hb1.Visible  = false;
            int index = ObjectIndexes[n];

            PCCObject.ExportEntry ex = pcc.Exports[index];
            if (ex.ClassName == "WwiseStream")
            {
                w = new WwiseStream(pcc, index);
                string s = "#" + index + " WwiseStream : " + ex.ObjectName + "\n\n";
                s        += "Filename : \"" + w.FileName + "\"\n";
                s        += "Data size: " + w.DataSize + " bytes\n";
                s        += "Data offset: 0x" + w.DataOffset.ToString("X8") + "\n";
                s        += "ID: 0x" + w.Id.ToString("X8") + " = " + w.Id + "\n";
                rtb1.Text = s;
            }
            if (ex.ClassName == "WwiseBank")
            {
                rtb1.Visible     = false;
                hb1.Visible      = true;
                wb               = new WwiseBank(pcc, index);
                hb1.ByteProvider = new DynamicByteProvider(wb.getBinary());
            }
        }
예제 #8
0
        public void CreateDataBase()
        {
            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;
            }
            FileStream fs       = new FileStream(DataBaseFile, FileMode.Create, FileAccess.Write);
            string     pathcook = ME3Directory.cookedPath;

            DebugOutput.Clear();
            DebugOutput.PrintLn("Levelbase.cs: Loading files from :" + pathcook);
            string[] files = Directory.GetFiles(pathcook, "*.pcc");
            for (int i = 0; i < files.Length; i++)
            {
                string file = files[i];
                DebugOutput.PrintLn(i + "/" + (files.Length - 1) + " Scanning : " + Path.GetFileName(file));
                PCCObject pcc = new PCCObject(file);
                for (int j = 0; j < pcc.Exports.Count(); j++)
                {
                    PCCObject.ExportEntry e = pcc.Exports[j];
                    if (e.ClassName == "Level")
                    {
                        Level   l     = new Level(pcc, j, true);
                        DBEntry entry = new DBEntry();
                        entry.filepath = file;
                        entry.index    = j;
                        entry.count    = l.Objects.Count();
                        database.Add(entry);
                        //foreach(int idx in l.Objects)
                        //    if (pcc.isExport(idx) && pcc.Exports[idx].ClassName == "BioPlaypenVolumeAdditive")
                        //        DebugOutput.PrintLn("#############################found");
                        DebugOutput.PrintLn("\tfound Level with " + entry.count + " Objects");
                    }
                }
            }
            database.Sort((a, b) => a.filepath.CompareTo(b.filepath));
            BitConverter.IsLittleEndian = true;
            byte[] buff = BitConverter.GetBytes(database.Count());
            fs.Write(buff, 0, 4);
            foreach (DBEntry e in database)
            {
                buff = BitConverter.GetBytes(e.index);
                fs.Write(buff, 0, 4);
                buff = BitConverter.GetBytes(e.count);
                fs.Write(buff, 0, 4);
                buff = BitConverter.GetBytes(e.filepath.Length);
                fs.Write(buff, 0, 4);
                foreach (char c in e.filepath)
                {
                    fs.WriteByte((byte)c);
                }
            }
            fs.Close();
        }
예제 #9
0
 public PCCObject.ExportEntry CopyExport(PCCObject.ExportEntry exp)
 {
     PCCObject.ExportEntry ret = new PCCObject.ExportEntry(pcc, exp.Data, exp.offset);
     //ret.childs = exp.childs;
     //ret.ClassName = exp.ClassName;
     //ret.Data = CopyArray(exp.Data);
     //ret.DataSize = exp.DataSize;
     //ret.Link = exp.Link;
     //ret.ObjectName = exp.ObjectName;
     //ret.off = exp.off;
     //ret.raw = CopyArray(exp.raw);
     return(ret);
 }
예제 #10
0
 public void LoadObjects()
 {
     listBox1.Items.Clear();
     ObjectIndexes = new List <int>();
     for (int i = 0; i < pcc.Exports.Count; i++)
     {
         PCCObject.ExportEntry e = pcc.Exports[i];
         Status.Text = "Scan object " + i + " / " + pcc.Exports.Count;
         if (e.ClassName == "WwiseBank" || e.ClassName == "WwiseStream")
         {
             string s = i.ToString("d6") + " : " + e.ClassName + " : \"" + e.ObjectName + "\"";
             listBox1.Items.Add(s);
             ObjectIndexes.Add(i);
         }
     }
 }
예제 #11
0
        private void importFromPSKToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1 | pcc == null)
            {
                return;
            }
            if (pcc.Exports[Objects[n].index].ClassName == "StaticMesh")
            {
                OpenFileDialog d = new OpenFileDialog();
                d.Filter = "*.psk|*.psk;*.pskx";
                if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    timer1.Enabled = false;
                    stm.ImportFromPsk(d.FileName);
                    byte[] buff = stm.SerializeToBuffer();
                    int    idx  = Objects[n].index;
                    PCCObject.ExportEntry en = pcc.Exports[idx];
                    en.Data = buff;
                    pcc.altSaveToFile(CurrFile, true);
                    MessageBox.Show("Done.");
                    timer1.Enabled = true;
                }
            }
            if (pcc.Exports[Objects[n].index].ClassName == "SkeletalMesh")
            {
                OpenFileDialog d = new OpenFileDialog();
                d.Filter = "*.psk|*.psk;*.pskx";
                if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    timer1.Enabled = false;
                    rtb1.Visible   = true;
                    skmold.ImportFromPsk(d.FileName, getLOD());
                    byte[] buff = skmold.Serialize();
                    int    idx  = Objects[n].index;
                    PCCObject.ExportEntry en = pcc.Exports[idx];
                    en.Data = buff;
                    pcc.altSaveToFile(CurrFile, true);
                    MessageBox.Show("Done.");
                    rtb1.Visible   = false;
                    timer1.Enabled = true;
                }
            }
        }
예제 #12
0
        private void importFromWAVToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            int index = ObjectIndexes[n];

            PCCObject.ExportEntry ex = pcc.Exports[index];
            if (ex.ClassName == "WwiseStream")
            {
                OpenFileDialog d = new OpenFileDialog();
                d.Filter = "*.wav|*.wav";
                if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string pathcook = ME3Directory.cookedPath;
                    string pathbio  = Path.GetDirectoryName(Path.GetDirectoryName(pathcook)) + "\\";
                    Status.Text = "Importing...";
                    if (!isDLC)
                    {
                        w.ImportFromFile(d.FileName, pathbio, pathcook);
                    }
                    else
                    {
                        w.ImportFromFile(d.FileName, pathbio, "", false);
                    }
                    byte[] buff = new byte[w.memsize];
                    for (int i = 0; i < w.memsize; i++)
                    {
                        buff[i] = w.memory[i];
                    }
                    ex.Data     = buff;
                    Status.Text = "Saving...";
                    pcc.altSaveToFile(CurrentFile, true);
                    Status.Text = "Ready";
                    MessageBox.Show("Done");
                }
            }
        }
예제 #13
0
        private void playToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            int index = ObjectIndexes[n];

            PCCObject.ExportEntry ex = pcc.Exports[index];
            if (ex.ClassName == "WwiseStream")
            {
                Stop();
                w = new WwiseStream(pcc, ex.Data);
                string path = ME3Directory.cookedPath;
                Status.Text = "Loading...";
                w.Play(path);
                Status.Text = "Ready";
            }
        }
예제 #14
0
        private void directAFCReplaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DirectReplace dr = new DirectReplace();

            dr.MdiParent = this.MdiParent;
            dr.Show();
            dr.WindowState = FormWindowState.Maximized;
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            int index = ObjectIndexes[n];

            PCCObject.ExportEntry ex = pcc.Exports[index];
            if (ex.ClassName == "WwiseStream")
            {
                dr.textBox3.Text = w.DataOffset.ToString();
                dr.textBox2.Text = w.FileName + ".afc";
            }
        }
예제 #15
0
        public void ReadGUIDs(PCCObject.ExportEntry export)
        {
            props = PropertyReader.getPropList(pcc, export);
            byte[] buff  = export.Data;
            int    pos   = props[props.Count - 1].offend;
            int    count = BitConverter.ToInt32(buff, pos);

            pos  += 4;
            GUIDs = new List <GuidEntry>();
            for (int i = 0; i < count; i++)
            {
                GuidEntry g = new GuidEntry();
                g.NameIdx = BitConverter.ToInt32(buff, pos);
                g.Name    = pcc.getNameEntry(g.NameIdx);
                g.GUID    = new byte[16];
                for (int j = 0; j < 16; j++)
                {
                    g.GUID[j] = buff[pos + j + 8];
                }
                GUIDs.Add(g);
                pos += 24;
            }
        }
예제 #16
0
        public void InitStuff()
        {
            textBox1.Text = pcc.Exports[ObjectIndex].ObjectName;
            comboBox1.Items.Clear();
            foreach (string name in pcc.Names)
            {
                comboBox1.Items.Add(name);
            }
            Classes = new List <int>();
            foreach (PCCObject.ExportEntry e in pcc.Exports)
            {
                bool found = false;
                foreach (int index in Classes)
                {
                    if (e.idxClassName == index)
                    {
                        found = true;
                    }
                }
                if (!found)
                {
                    Classes.Add(e.idxClassName);
                }
            }
            bool run = true;

            while (run)
            {
                run = false;
                for (int i = 0; i < Classes.Count - 1; i++)
                {
                    if (pcc.getClassName(Classes[i]).CompareTo(pcc.getClassName(Classes[i + 1])) > 0)
                    {
                        int t = Classes[i];
                        Classes[i]     = Classes[i + 1];
                        Classes[i + 1] = t;
                        run            = true;
                    }
                }
            }
            comboBox2.Items.Clear();
            foreach (int index in Classes)
            {
                comboBox2.Items.Add(pcc.getClassName(index));
            }
            treeView1.Nodes.Clear();
            TreeNode Root = new TreeNode("Root");

            Root.Name = "0";
            List <int> Links = new List <int>();

            for (int i = 0; i < pcc.Exports.Count; i++)
            {
                PCCObject.ExportEntry e = pcc.Exports[i];
                bool found = false;
                foreach (int index in Links)
                {
                    if (index == e.idxLink)
                    {
                        found = true;
                    }
                }
                if (!found)
                {
                    Links.Add(e.idxLink);
                }
            }
            Links.Sort();
            foreach (int index in Links)
            {
                if (index != 0)
                {
                    if (index > 0)
                    {
                        PCCObject.ExportEntry e = pcc.Exports[index - 1];
                        string s = (index - 1).ToString() + " : ";
                        if (e.PackageFullName != "Class" && e.PackageFullName != "Package")
                        {
                            s += e.PackageFullName + ".";
                        }
                        s += e.ObjectName;
                        TreeNode newlink = new TreeNode(s);
                        newlink.Name = index.ToString();
                        Root.Nodes.Add(newlink);
                    }
                    else
                    {
                        //PCCObject.ImportEntry e = pcc.Imports[index * -1 - 1];
                        //string s = "";
                        //if (e.PackageFullName != "Class" && e.PackageFullName != "Package")
                        //    s += e.PackageFullName + ".";
                        //s += e.ObjectName;
                        //TreeNode newlink = new TreeNode(s);
                        //newlink.Name = index.ToString();
                        //Root.Nodes.Add(newlink);
                    }
                }
            }
            treeView1.Nodes.Add(Root);
            treeView1.ExpandAll();
        }
예제 #17
0
        private void button7_Click(object sender, EventArgs e)
        {
            PCCObject.ExportEntry entry  = new PCCObject.ExportEntry();
            PCCObject.ExportEntry source = pcc.Exports[ObjectIndex];
            byte[] Header = new byte[source.info.Length];                       //Header
            for (int i = 0; i < source.info.Length; i++)
            {
                Header[i] = source.info[i];
            }
            entry.pccRef = pcc;
            entry.info   = Header;
            if (radioButton2.Checked)                                           //Name from list
            {
                if (comboBox1.SelectedIndex != -1)
                {
                    entry.idxObjectName = comboBox1.SelectedIndex;
                }
            }
            if (radioButton3.Checked)                                           //Custom Name
            {
                if (textBox1.Text != "")
                {
                    pcc.Names.Add(textBox1.Text);
                    entry.idxObjectName = pcc.Names.Count - 1;
                }
            }
            if (radioButton4.Checked)                                           //Class
            {
                if (comboBox2.SelectedIndex != -1)
                {
                    entry.idxClassName = Classes[comboBox2.SelectedIndex];
                }
            }
            if (radioButton8.Checked)                                           //Link
            {
                if (treeView1.SelectedNode != null)
                {
                    string link = treeView1.SelectedNode.Name;
                    entry.idxLink = Convert.ToInt32(link);
                }
            }
            byte[] Data = new byte[0];
            if (radioButton6.Checked)                                           //Load data from file...
            {
                if (File.Exists(textBox2.Text))
                {
                    FileStream fs = new FileStream(textBox2.Text, FileMode.Open, FileAccess.Read);
                    Data = new byte[fs.Length];
                    for (int i = 0; i < fs.Length; i++)
                    {
                        Data[i] = (byte)fs.ReadByte();
                    }
                    fs.Close();
                }
            }
            if (radioButton7.Checked)                                           //...or keep old data
            {
                Data = new byte[source.Data.Length];
                for (int i = 0; i < source.Data.Length; i++)
                {
                    Data[i] = source.Data[i];
                }
            }
            entry.Data = Data;
            int lastoffset = 0;

            foreach (PCCObject.ExportEntry ent in pcc.Exports)
            {
                if (ent.DataOffset > lastoffset)
                {
                    lastoffset = ent.DataOffset + ent.Data.Length;
                }
            }
            entry.DataOffset = lastoffset;
            //entry.DataSize = -1;//force update
            pcc.addExport(entry);
            foreach (PCCObject.ExportEntry ex in pcc.Exports) //silly update trick, but it works... wv
            {
                ex.Data = ex.Data;
            }
            refForm.RefreshView();
            this.Close();
        }
예제 #18
0
        private void addBiggestImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //try
            {
                if (tex2D.imgList.Count <= 1)
                {
                    MessageBox.Show("You cannot upscale a texture that has only one image!", "Invalid operation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string         currentDir = pathCooked;
                string         texGroupToAdd;
                OpenFileDialog openImage = openFileDialog;
                openImage.Title  = "Select the image to add";
                openImage.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";

                if (openImage.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                // add function
                int numTexBegin = tex2D.imgList.Count;
                tex2D.OneImageToRuleThemAll(openImage.FileName, currentDir, out texGroupToAdd);
                int numTexEnd = tex2D.imgList.Count;

                //--------- update the pcc with the new replaced infos ----------
                // select export index
                ListViewItem item  = listView1.SelectedItems[0];
                int          index = Convert.ToInt32(item.Name);
                // copy export data
                PCCObject.ExportEntry expEntry = pcc.Exports[index];
                // change data with new tex data
                expEntry.Data = tex2D.ToArray(expEntry.DataOffset);
                // updating pcc file
                //pcc.ChangeExportEntry(index, expEntry);
                //pcc.UpdateAllOffsets();

                // changing tfc size
                // check that the image list has at least one image stored inside an external archive, if not it's useless to search the archive location
                if (tex2D.imgList.Any(images => images.storageType == Texture2D.storage.arcCpr || images.storageType == Texture2D.storage.arcUnc))
                {
                    TOCeditor tc = new TOCeditor();
                    uint      arcSize;
                    string    arcPath = currentDir + tex2D.arcName + ".tfc";
                    using (FileStream archiveStream = File.OpenRead(arcPath))
                        arcSize = (uint)archiveStream.Length;
                    string tocpath = pathBIOGame + "PCConsoleTOC.bin";
                    if (File.Exists(tocpath))
                    {
                        while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize, tocpath))
                        {
                            openImage        = openFileDialog;
                            openImage.Title  = "Select the archive path";
                            openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                            openImage.ShowDialog();
                            arcPath = openImage.FileName;
                            using (FileStream archiveStream = File.OpenRead(arcPath))
                                arcSize = (uint)archiveStream.Length;
                        }
                    }
                    else
                    {
                        while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize))
                        {
                            openImage        = openFileDialog;
                            openImage.Title  = "Select the archive path";
                            openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                            openImage.ShowDialog();
                            arcPath = openImage.FileName;
                            using (FileStream archiveStream = File.OpenRead(arcPath))
                                arcSize = (uint)archiveStream.Length;
                        }
                    }
                }

                //---------------- end of replace -------------------------------
                if (texGroupToAdd != null)
                {
                    MessageBox.Show("Texture replaced correctly. Make sure to add " + texGroupToAdd + " inside coalesced.bin", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Texture replaced correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            /*catch (Exception exc)
             * {
             *  MessageBox.Show("An error occurred while replacing texture: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             * }*/
        }
예제 #19
0
        private void upscaleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (tex2D.imgList.Count <= 1)
                {
                    MessageBox.Show("You cannot upscale a texture that has only one image!", "Invalid operation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string         currentDir = pathCooked;
                OpenFileDialog openImage  = openFileDialog;
                openImage.Title  = "Select the image to add";
                openImage.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";

                if (openImage.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                // add function
                tex2D.addBiggerImage(openImage.FileName, currentDir);

                //--------- update the pcc with the new replaced infos ----------
                // select export index
                ListViewItem item  = listView1.SelectedItems[0];
                int          index = Convert.ToInt32(item.Name);
                // copy export data
                PCCObject.ExportEntry expEntry = pcc.Exports[index];
                // change data with new tex data
                expEntry.Data = tex2D.ToArray(expEntry.DataOffset);
                // updating pcc file
                //pcc.ChangeExportEntry(index, expEntry);
                //pcc.UpdateAllOffsets();

                // changing tfc size
                // check that the image list has at least one image stored inside an external archive, if not it's useless to search the archive location
                if (tex2D.imgList.Any(images => images.storageType == Texture2D.storage.arcCpr || images.storageType == Texture2D.storage.arcUnc))
                {
                    TOCeditor tc = new TOCeditor();
                    uint      arcSize;
                    string    arcPath = currentDir + tex2D.arcName + ".tfc";
                    using (FileStream archiveStream = File.OpenRead(arcPath))
                        arcSize = (uint)archiveStream.Length;
                    string tocpath = pathBIOGame + "PCConsoleTOC.bin";
                    if (File.Exists(tocpath))
                    {
                        while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize, tocpath))
                        {
                            openImage        = openFileDialog;
                            openImage.Title  = "Select the archive path";
                            openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                            openImage.ShowDialog();
                            arcPath = openImage.FileName;
                            using (FileStream archiveStream = File.OpenRead(arcPath))
                                arcSize = (uint)archiveStream.Length;
                        }
                    }
                    else
                    {
                        while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize))
                        {
                            openImage        = openFileDialog;
                            openImage.Title  = "Select the archive path";
                            openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                            openImage.ShowDialog();
                            arcPath = openImage.FileName;
                            using (FileStream archiveStream = File.OpenRead(arcPath))
                                arcSize = (uint)archiveStream.Length;
                        }
                    }
                }
                //---------------- end of replace -------------------------------

                /*
                 * // code test to prove that tex2d works, just decomment it and comment precedent code
                 * byte[] pccFile = PCCHandler.Decompress(pcc.pccFileName);
                 * using (FileStream debugStr = File.OpenWrite(pcc.pccFileName))
                 * {
                 *  debugStr.Write(pccFile, 0, pccFile.Length);
                 *  debugStr.Seek(expEntry.DataOffset, SeekOrigin.Begin);
                 *  byte[] buffer = tex2D.ToArray(expEntry.DataOffset);
                 *  debugStr.Write(buffer, 0, buffer.Length);
                 * }*/
                MessageBox.Show("Image was added correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception exc)
            {
                MessageBox.Show("An error occurred while adding image: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #20
0
        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string currentDir = ME3Directory.cookedPath;

            // setting TexSelection Form to export images
            TexSelection texSelection = new TexSelection(tex2D, true);

            texSelection.FormTitle        = "Select images to replace";
            texSelection.btnSelectionText = "Replace";
            if (tex2D.imgList.Count > 1)
            {
                texSelection.ShowDialog();
                texSelection.Dispose();
            }
            else
            {
                texSelection.bOk = true;
            }

            if (texSelection.bOk)
            {
                try
                {
                    // main replace loop
                    foreach (Object entry in texSelection.imageListBox.CheckedItems)
                    {
                        string imgSize = entry.ToString().Split(' ')[1]; // take imagesize (ex. 512x512) from checklist text: "Image 512x512 stored..."

                        OpenFileDialog openImage = openFileDialog;
                        openImage.Title  = "Select the image to replace with size " + imgSize;
                        openImage.Filter = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";

                        if (openImage.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }

                        // replace function
                        tex2D.replaceImage(imgSize, openImage.FileName, currentDir);
                    }

                    //--------- update the pcc with the new replaced infos ----------
                    // select export index
                    ListViewItem item  = listView1.SelectedItems[0];
                    int          index = Convert.ToInt32(item.Name);
                    // copy export data
                    PCCObject.ExportEntry expEntry = pcc.Exports[index];
                    // change data with new tex data
                    expEntry.Data = tex2D.ToArray(expEntry.DataOffset);
                    // updating pcc file
                    //pcc.ChangeExportEntry(index, expEntry);
                    //pcc.UpdateAllOffsets();

                    // changing tfc size
                    // check that the image list has at least one image stored inside an external archive, if not it's useless to search the archive location
                    if (tex2D.imgList.Any(images => images.storageType == Texture2D.storage.arcCpr || images.storageType == Texture2D.storage.arcUnc))
                    {
                        TOCeditor tc = new TOCeditor();
                        uint      arcSize;
                        string    arcPath = currentDir + tex2D.arcName + ".tfc";
                        using (FileStream archiveStream = File.OpenRead(arcPath))
                            arcSize = (uint)archiveStream.Length;
                        string tocpath = pathBIOGame + "PCConsoleTOC.bin";
                        if (File.Exists(tocpath))
                        {
                            while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize, tocpath))
                            {
                                OpenFileDialog openImage = openFileDialog;
                                openImage.Title  = "Select the archive path";
                                openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                                openImage.ShowDialog();
                                arcPath = openImage.FileName;
                                using (FileStream archiveStream = File.OpenRead(arcPath))
                                    arcSize = (uint)archiveStream.Length;
                            }
                        }
                        else
                        {
                            while (!tc.UpdateFile("\\" + tex2D.arcName + ".tfc", arcSize))
                            {
                                OpenFileDialog openImage = openFileDialog;
                                openImage.Title  = "Select the archive path";
                                openImage.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";
                                openImage.ShowDialog();
                                arcPath = openImage.FileName;
                                using (FileStream archiveStream = File.OpenRead(arcPath))
                                    arcSize = (uint)archiveStream.Length;
                            }
                        }
                    }

                    //---------------- end of replace -------------------------------
                    MessageBox.Show("All images are replaced correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exc)
                {
                    MessageBox.Show("An error occurred while replacing images: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #21
0
        public void LetsDump2(string classname)
        {
            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 path = ME3Directory.cookedPath;

            string[] files = Directory.GetFiles(path, "*.pcc");
            pb1.Minimum = 0;
            rtb1.Text   = "";
            pauseToolStripMenuItem.Visible = true;
            pb2.Value   = 0;
            pb2.Maximum = files.Length;
            List <string> Names = new List <string>();
            List <string> Types = new List <string>();
            List <string> First = new List <string>();

            DebugOutput.Clear();
            for (int i = 0; i < files.Length; i++)
            {
                while (pause)
                {
                    Application.DoEvents();
                }
                pcc = new PCCObject(files[i]);
                DebugOutput.PrintLn(i + "/" + files.Length + " Scanning file : " + Path.GetFileName(files[i]));
                pb1.Maximum = pcc.Exports.Count;
                pb2.Value   = i;
                for (int j = 0; j < pcc.Exports.Count; j++)
                {
                    PCCObject.ExportEntry ent = pcc.Exports[j];
                    if (ent.ClassName == classname)
                    {
                        List <PropertyReader.Property> p = PropertyReader.getPropList(pcc, ent.Data);
                        for (int k = 0; k < p.Count; k++)
                        {
                            PropertyReader.Property prop = p[k];
                            int found = -1;
                            for (int l = 0; l < Names.Count(); l++)
                            {
                                if (pcc.getNameEntry(prop.Name) == Names[l])
                                {
                                    found = l;
                                }
                            }
                            if (found == -1)
                            {
                                Names.Add(pcc.getNameEntry(prop.Name));
                                Types.Add(PropertyReader.TypeToString((int)prop.TypeVal));
                                First.Add(Path.GetFileName(files[i]) + " #" + j);
                            }
                        }
                    }
                    if (j % 500 == 0)
                    {
                        pb1.Value   = j;
                        Status.Text = "State : " + j + " / " + pcc.Exports.Count;
                        string s = "Possible properties found so far for class \"" + classname + "\":\n";
                        for (int k = 0; k < Names.Count(); k++)
                        {
                            s += Types[k] + " : \"" + Names[k] + "\" first found: " + First[k] + "\n";
                        }
                        Action action = () => rtb1.Text = s;
                        rtb1.Invoke(action);
                        action = () => rtb1.SelectionStart = s.Length;
                        rtb1.Invoke(action);
                        action = () => rtb1.ScrollToCaret();
                        rtb1.Invoke(action);
                        Application.DoEvents();
                    }
                }
            }
            Status.Text = "State : Done";
            string t = "Possible properties found for class \"" + classname + "\":\n";

            for (int k = 0; k < Names.Count(); k++)
            {
                t += Types[k] + " : \"" + Names[k] + "\" first found: " + First[k] + "\n";
            }
            rtb1.Text           = t;
            rtb1.SelectionStart = rtb1.TextLength;
            rtb1.ScrollToCaret();
            pb1.Value = 0;
            pauseToolStripMenuItem.Visible = false;
        }
예제 #22
0
        private void pg1_PropertyValueChanged(object o, PropertyValueChangedEventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            n = CurrentObjects[n];
            string   name   = e.ChangedItem.Label;
            GridItem parent = e.ChangedItem.Parent;

            //if (parent != null) name = parent.Label;
            if (parent.Label == "data")
            {
                GridItem parent2 = parent.Parent;
                if (parent2 != null)
                {
                    name = parent2.Label;
                }
            }
            Type parentVal = null;

            if (parent.Value != null)
            {
                parentVal = parent.Value.GetType();
            }
            if (name == "nameindex" || parentVal == typeof(Unreal.ColorProp) || parentVal == typeof(Unreal.VectorProp) || parentVal == typeof(Unreal.RotatorProp))
            {
                name = parent.Label;
            }
            PCCObject.ExportEntry          ent = pcc.Exports[n];
            List <PropertyReader.Property> p   = PropertyReader.getPropList(pcc, ent);
            int m = -1;

            for (int i = 0; i < p.Count; i++)
            {
                if (pcc.Names[p[i].Name] == name)
                {
                    m = i;
                }
            }
            if (m == -1)
            {
                return;
            }
            byte[] buff2;
            switch (p[m].TypeVal)
            {
            case PropertyReader.Type.BoolProperty:
                byte res = 0;
                if ((bool)e.ChangedItem.Value == true)
                {
                    res = 1;
                }
                ent.Data[p[m].offsetval] = res;
                break;

            case PropertyReader.Type.FloatProperty:
                buff2 = BitConverter.GetBytes((float)e.ChangedItem.Value);
                for (int i = 0; i < 4; i++)
                {
                    ent.Data[p[m].offsetval + i] = buff2[i];
                }
                break;

            case PropertyReader.Type.IntProperty:
            case PropertyReader.Type.StringRefProperty:
                int newv = Convert.ToInt32(e.ChangedItem.Value);
                int oldv = Convert.ToInt32(e.OldValue);
                buff2 = BitConverter.GetBytes(newv);
                for (int i = 0; i < 4; i++)
                {
                    ent.Data[p[m].offsetval + i] = buff2[i];
                }
                break;

            case PropertyReader.Type.StrProperty:
                string      s          = Convert.ToString(e.ChangedItem.Value);
                int         oldLength  = -(int)BitConverter.ToInt64(ent.Data, p[m].offsetval);
                List <byte> stringBuff = new List <byte>(s.Length * 2);
                for (int i = 0; i < s.Length; i++)
                {
                    stringBuff.AddRange(BitConverter.GetBytes(s[i]));
                }
                stringBuff.Add(0);
                stringBuff.Add(0);
                buff2 = BitConverter.GetBytes((s.LongCount() + 1) * 2 + 4);
                for (int i = 0; i < 4; i++)
                {
                    ent.Data[p[m].offsetval - 8 + i] = buff2[i];
                }
                buff2 = BitConverter.GetBytes(-(s.LongCount() + 1));
                for (int i = 0; i < 8; i++)
                {
                    ent.Data[p[m].offsetval + i] = buff2[i];
                }
                buff2 = new byte[ent.Data.Length - (oldLength * 2) + stringBuff.Count];
                int startLength  = p[m].offsetval + 4;
                int startLength2 = startLength + (oldLength * 2);
                for (int i = 0; i < startLength; i++)
                {
                    buff2[i] = ent.Data[i];
                }
                for (int i = 0; i < stringBuff.Count; i++)
                {
                    buff2[i + startLength] = stringBuff[i];
                }
                startLength += stringBuff.Count;
                for (int i = 0; i < ent.Data.Length - startLength2; i++)
                {
                    buff2[i + startLength] = ent.Data[i + startLength2];
                }
                ent.Data = buff2;
                break;

            case PropertyReader.Type.StructProperty:
                if (e.ChangedItem.Label != "nameindex" && parentVal == typeof(Unreal.ColorProp))
                {
                    switch (e.ChangedItem.Label)
                    {
                    case "Alpha":
                        ent.Data[p[m].offsetval + 11] = Convert.ToByte(e.ChangedItem.Value);
                        break;

                    case "Red":
                        ent.Data[p[m].offsetval + 10] = Convert.ToByte(e.ChangedItem.Value);
                        break;

                    case "Green":
                        ent.Data[p[m].offsetval + 9] = Convert.ToByte(e.ChangedItem.Value);
                        break;

                    case "Blue":
                        ent.Data[p[m].offsetval + 8] = Convert.ToByte(e.ChangedItem.Value);
                        break;

                    default:
                        break;
                    }
                    int t = listBox1.SelectedIndex;
                    listBox1.SelectedIndex = -1;
                    listBox1.SelectedIndex = t;
                }
                else if (e.ChangedItem.Label != "nameindex" && parentVal == typeof(Unreal.VectorProp))
                {
                    int offset = 0;
                    switch (e.ChangedItem.Label)
                    {
                    case "X":
                        offset = 8;
                        break;

                    case "Y":
                        offset = 12;
                        break;

                    case "Z":
                        offset = 16;
                        break;

                    default:
                        break;
                    }
                    if (offset != 0)
                    {
                        buff2 = BitConverter.GetBytes(Convert.ToSingle(e.ChangedItem.Value));
                        for (int i = 0; i < 4; i++)
                        {
                            ent.Data[p[m].offsetval + offset + i] = buff2[i];
                        }
                    }
                    int t = listBox1.SelectedIndex;
                    listBox1.SelectedIndex = -1;
                    listBox1.SelectedIndex = t;
                }
                else if (e.ChangedItem.Label != "nameindex" && parentVal == typeof(Unreal.RotatorProp))
                {
                    int offset = 0;
                    switch (e.ChangedItem.Label)
                    {
                    case "Pitch":
                        offset = 8;
                        break;

                    case "Yaw":
                        offset = 12;
                        break;

                    case "Roll":
                        offset = 16;
                        break;

                    default:
                        break;
                    }
                    if (offset != 0)
                    {
                        int val = Convert.ToInt32(Convert.ToSingle(e.ChangedItem.Value) * 65536f / 360f);
                        buff2 = BitConverter.GetBytes(val);
                        for (int i = 0; i < 4; i++)
                        {
                            ent.Data[p[m].offsetval + offset + i] = buff2[i];
                        }
                    }
                    int t = listBox1.SelectedIndex;
                    listBox1.SelectedIndex = -1;
                    listBox1.SelectedIndex = t;
                }
                else if (e.ChangedItem.Label != "nameindex" && parentVal == typeof(Unreal.LinearColorProp))
                {
                    int offset = 0;
                    switch (e.ChangedItem.Label)
                    {
                    case "Red":
                        offset = 8;
                        break;

                    case "Green":
                        offset = 12;
                        break;

                    case "Blue":
                        offset = 16;
                        break;

                    case "Alpha":
                        offset = 20;
                        break;

                    default:
                        break;
                    }
                    if (offset != 0)
                    {
                        buff2 = BitConverter.GetBytes(Convert.ToSingle(e.ChangedItem.Value));
                        for (int i = 0; i < 4; i++)
                        {
                            ent.Data[p[m].offsetval + offset + i] = buff2[i];
                        }
                    }
                    int t = listBox1.SelectedIndex;
                    listBox1.SelectedIndex = -1;
                    listBox1.SelectedIndex = t;
                }
                else if (e.ChangedItem.Value.GetType() == typeof(int))
                {
                    int val = Convert.ToInt32(e.ChangedItem.Value);
                    if (e.ChangedItem.Label == "nameindex")
                    {
                        int val1 = Convert.ToInt32(e.ChangedItem.Value);
                        buff2 = BitConverter.GetBytes(val1);
                        for (int i = 0; i < 4; i++)
                        {
                            ent.Data[p[m].offsetval + i] = buff2[i];
                        }
                        int t = listBox1.SelectedIndex;
                        listBox1.SelectedIndex = -1;
                        listBox1.SelectedIndex = t;
                    }
                    else
                    {
                        string sidx = e.ChangedItem.Label.Replace("[", "");
                        sidx = sidx.Replace("]", "");
                        int index = Convert.ToInt32(sidx);
                        buff2 = BitConverter.GetBytes(val);
                        for (int i = 0; i < 4; i++)
                        {
                            ent.Data[p[m].offsetval + i + index * 4 + 8] = buff2[i];
                        }
                        int t = listBox1.SelectedIndex;
                        listBox1.SelectedIndex = -1;
                        listBox1.SelectedIndex = t;
                    }
                }
                break;

            case PropertyReader.Type.ByteProperty:
            case PropertyReader.Type.NameProperty:
                if (e.ChangedItem.Value.GetType() == typeof(int))
                {
                    int val = Convert.ToInt32(e.ChangedItem.Value);
                    buff2 = BitConverter.GetBytes(val);
                    for (int i = 0; i < 4; i++)
                    {
                        ent.Data[p[m].offsetval + i] = buff2[i];
                    }
                    int t = listBox1.SelectedIndex;
                    listBox1.SelectedIndex = -1;
                    listBox1.SelectedIndex = t;
                }
                break;

            case PropertyReader.Type.ObjectProperty:
                if (e.ChangedItem.Value.GetType() == typeof(int))
                {
                    int val = Convert.ToInt32(e.ChangedItem.Value);
                    buff2 = BitConverter.GetBytes(val);
                    for (int i = 0; i < 4; i++)
                    {
                        ent.Data[p[m].offsetval + i] = buff2[i];
                    }
                    int t = listBox1.SelectedIndex;
                    listBox1.SelectedIndex = -1;
                    listBox1.SelectedIndex = t;
                }
                break;

            default:
                return;
            }
            pcc.Exports[n] = ent;
            pg1.ExpandAllGridItems();
        }
예제 #23
0
        }                                                    // showable image list

        public Texture2D(PCCObject pccObj, int texIdx)
        {
            pccRef = pccObj;
            // check if texIdx is an Export index and a Texture2D class
            if (pccObj.isExport(texIdx) && (pccObj.Exports[texIdx].ClassName == className))
            {
                PCCObject.ExportEntry expEntry = pccObj.Exports[texIdx];
                properties = new Dictionary <string, PropertyReader.Property>();
                byte[] rawData          = (byte[])expEntry.Data.Clone();
                int    propertiesOffset = PropertyReader.detectStart(pccObj, rawData);
                headerData = new byte[propertiesOffset];
                Buffer.BlockCopy(rawData, 0, headerData, 0, propertiesOffset);
                pccOffset = (uint)expEntry.DataOffset;
                List <PropertyReader.Property> tempProperties = PropertyReader.getPropList(pccObj, rawData);
                texName = expEntry.ObjectName;
                for (int i = 0; i < tempProperties.Count; i++)
                {
                    PropertyReader.Property property = tempProperties[i];
                    if (!properties.ContainsKey(pccObj.Names[property.Name]))
                    {
                        properties.Add(pccObj.Names[property.Name], property);
                    }

                    switch (pccObj.Names[property.Name])
                    {
                    case "Format": texFormat = pccObj.Names[property.Value.IntValue].Substring(3); break;

                    case "TextureFileCacheName": arcName = pccObj.Names[property.Value.IntValue]; break;

                    case "LODGroup": LODGroup = pccObj.Names[property.Value.IntValue]; break;

                    case "None": dataOffset = (uint)(property.offsetval + property.Size); break;
                    }
                }

                // if "None" property isn't found throws an exception
                if (dataOffset == 0)
                {
                    throw new Exception("\"None\" property not found");
                }
                else
                {
                    imageData = new byte[rawData.Length - dataOffset];
                    Buffer.BlockCopy(rawData, (int)dataOffset, imageData, 0, (int)(rawData.Length - dataOffset));
                }
            }
            else
            {
                throw new Exception("Texture2D " + texIdx + " not found");
            }

            pccExpIdx = texIdx;
            MemoryStream dataStream = new MemoryStream(imageData);

            numMipMaps = dataStream.ReadValueU32();
            uint count = numMipMaps;

            imgList = new List <ImageInfo>();
            while (dataStream.Position < dataStream.Length && count > 0)
            {
                ImageInfo imgInfo = new ImageInfo();
                imgInfo.storageType = (storage)dataStream.ReadValueS32();
                imgInfo.uncSize     = dataStream.ReadValueS32();
                imgInfo.cprSize     = dataStream.ReadValueS32();
                imgInfo.offset      = dataStream.ReadValueS32();
                if (imgInfo.storageType == storage.pccSto)
                {
                    //imgInfo.offset = (int)(pccOffset + dataOffset); // saving pcc offset as relative to exportdata offset, not absolute
                    imgInfo.offset = (int)dataStream.Position; // saving pcc offset as relative to exportdata offset, not absolute
                    //MessageBox.Show("Pcc class offset: " + pccOffset + "\nimages data offset: " + imgInfo.offset.ToString());
                    dataStream.Seek(imgInfo.uncSize, SeekOrigin.Current);
                }
                imgInfo.imgSize = new ImageSize(dataStream.ReadValueU32(), dataStream.ReadValueU32());
                imgList.Add(imgInfo);
                count--;
            }

            // save what remains

            /*int remainingBytes = (int)(dataStream.Length - dataStream.Position);
             * footerData = new byte[remainingBytes];
             * dataStream.Read(footerData, 0, footerData.Length);*/
        }
예제 #24
0
        public TreeNode ToTree(int nr)
        {
            TreeNode t = new TreeNode("#" + nr + " Level");

            DebugOutput.PrintLn("Generating Tree...");
            for (int i = 0; i < Objects.Count(); i++)
            {
                int index = Objects[i];
                if (index > 0)
                {
                    PCCObject.ExportEntry e = pcc.Exports[index];
                    DebugOutput.PrintLn((i + 1) + " / " + Objects.Count + " : \"" + e.ObjectName + "\" - \"" + e.ClassName + "\"");
                    switch (e.ClassName)
                    {
                    case "WwiseEnvironmentVolume":
                        foreach (WwiseEnvironmentVolume wev in WEV)
                        {
                            if (wev.MyIndex == index)
                            {
                                t.Nodes.Add(wev.ToTree());
                            }
                        }
                        break;

                    case "WwiseAudioVolume":
                        foreach (WwiseAudioVolume wav in WAV)
                        {
                            if (wav.MyIndex == index)
                            {
                                t.Nodes.Add(wav.ToTree());
                            }
                        }
                        break;

                    case "WwiseAmbientSound":
                        foreach (WwiseAmbientSound was in WAS)
                        {
                            if (was.MyIndex == index)
                            {
                                t.Nodes.Add(was.ToTree());
                            }
                        }
                        break;

                    case "BioPathPoint":
                        foreach (BioPathPoint bpp in BPP)
                        {
                            if (bpp.MyIndex == index)
                            {
                                t.Nodes.Add(bpp.ToTree());
                            }
                        }
                        break;

                    case "BioTriggerVolume":
                        foreach (BioTriggerVolume btv in BTV)
                        {
                            if (btv.MyIndex == index)
                            {
                                t.Nodes.Add(btv.ToTree());
                            }
                        }
                        break;

                    case "BioPlaypenVolumeAdditive":
                        foreach (BioPlaypenVolumeAdditive bpva in BPVA)
                        {
                            if (bpva.MyIndex == index)
                            {
                                t.Nodes.Add(bpva.ToTree());
                            }
                        }
                        break;

                    case "BlockingVolume":
                        foreach (BlockingVolume bv in BV)
                        {
                            if (bv.MyIndex == index)
                            {
                                t.Nodes.Add(bv.ToTree());
                            }
                        }
                        break;

                    case "MantleMarker":
                        foreach (MantleMarker mm in MM)
                        {
                            if (mm.MyIndex == index)
                            {
                                t.Nodes.Add(mm.ToTree());
                            }
                        }
                        break;

                    case "PathNode":
                        foreach (PathNode pn in PN)
                        {
                            if (pn.MyIndex == index)
                            {
                                t.Nodes.Add(pn.ToTree());
                            }
                        }
                        break;

                    case "SplineActor":
                        foreach (SplineActor sp in SPA)
                        {
                            if (sp.MyIndex == index)
                            {
                                t.Nodes.Add(sp.ToTree());
                            }
                        }
                        break;

                    case "TargetPoint":
                        foreach (TargetPoint tp in TP)
                        {
                            if (tp.MyIndex == index)
                            {
                                t.Nodes.Add(tp.ToTree());
                            }
                        }
                        break;

                    case "LightVolume":
                        foreach (LightVolume lv in LV)
                        {
                            if (lv.MyIndex == index)
                            {
                                t.Nodes.Add(lv.ToTree());
                            }
                        }
                        break;

                    case "StaticMeshActor":
                        foreach (StaticMeshActor stma in STM_A)
                        {
                            if (stma.MyIndex == index)
                            {
                                t.Nodes.Add(stma.ToTree());
                            }
                        }
                        break;

                    case "DecalActor":
                        foreach (DecalActor da in DA)
                        {
                            if (da.MyIndex == index)
                            {
                                t.Nodes.Add(da.ToTree());
                            }
                        }
                        break;

                    case "InterpActor":
                        foreach (InterpActor ia in IA)
                        {
                            if (ia.MyIndex == index)
                            {
                                t.Nodes.Add(ia.ToTree());
                            }
                        }
                        break;

                    case "StaticMeshCollectionActor":
                        foreach (StaticMeshCollectionActor stmca in STM_CA)
                        {
                            if (stmca.MyIndex == index)
                            {
                                t.Nodes.Add(stmca.ToTree());
                            }
                        }
                        break;

                    case "CoverLink":
                        foreach (CoverLink cl in CL)
                        {
                            if (cl.MyIndex == index)
                            {
                                t.Nodes.Add(cl.ToTree());
                            }
                        }
                        break;

                    case "CoverSlotMarker":
                        foreach (CoverSlotMarker csm in CSM)
                        {
                            if (csm.MyIndex == index)
                            {
                                t.Nodes.Add(csm.ToTree());
                            }
                        }
                        break;

                    case "Emitter":
                        foreach (Emitter em in EM)
                        {
                            if (em.MyIndex == index)
                            {
                                t.Nodes.Add(em.ToTree());
                            }
                        }
                        break;

                    default:
                        string s = "#" + index + " : \"";
                        s += e.ObjectName + "\" CLASS : \"";
                        s += e.ClassName + "\"";
                        TreeNode t1 = new TreeNode(s);
                        t.Nodes.Add(t1);
                        break;
                    }
                }
                else
                {
                    TreeNode t1 = new TreeNode("#" + index + " : NOT IMPLEMENTED");
                    t.Nodes.Add(t1);
                }
            }
            return(t);
        }
예제 #25
0
        private void makeDialogDumpToolStripMenuItem_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 path = ME3Directory.cookedPath;

            string[] files = Directory.GetFiles(path);
            pb1.Minimum = 0;
            rtb1.Text   = "";
            int    count  = 0;
            int    count2 = 0;
            string t      = "";

            pauseToolStripMenuItem.Visible = true;
            pb2.Value   = 0;
            pb2.Maximum = files.Length;
            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].ToLower().EndsWith(".pcc"))
                {
                    while (pause)
                    {
                        Application.DoEvents();
                    }
                    pcc         = new PCCObject(files[i]);
                    pb1.Maximum = pcc.Exports.Count;
                    pb2.Value   = i;
                    string s = "String references for file " + files[i] + "\n";
                    for (int j = 0; j < pcc.Exports.Count; j++)
                    {
                        PCCObject.ExportEntry          ent = pcc.Exports[j];
                        List <PropertyReader.Property> p   = PropertyReader.getPropList(pcc, ent.Data);

                        for (int k = 0; k < p.Count; k++)
                        {
                            PropertyReader.Property prop = p[k];
                            if (prop.TypeVal == PropertyReader.Type.StringRefProperty)
                            {
                                s += "Object #" + j + " : " + PropertyReader.PropertyToText(prop, pcc) + "\n";
                            }
                            if (prop.TypeVal == PropertyReader.Type.ArrayProperty)
                            {
                                string tt = DumpArray(pcc, ent.Data, prop.offsetval + 4, s, 1);
                                if (tt.Length != 0)
                                {
                                    s += "Object #" + j + " in : " + PropertyReader.PropertyToText(prop, pcc) + "\n";
                                    s += tt;
                                }
                            }
                            if (prop.TypeVal == PropertyReader.Type.StructProperty)
                            {
                                string tt = DumpArray(pcc, ent.Data, prop.offsetval + 8, s, 1);
                                if (tt.Length != 0)
                                {
                                    s += "Object #" + j + " in : " + PropertyReader.PropertyToText(prop, pcc) + "\n";
                                    s += tt;
                                }
                            }
                        }
                        if (count++ > 500)
                        {
                            count       = 0;
                            pb1.Value   = j;
                            Status.Text = "State : " + j + " / " + pcc.Exports.Count;
                            if (count2++ > 10)
                            {
                                count2              = 0;
                                rtb1.Text           = t;
                                rtb1.SelectionStart = rtb1.TextLength;
                                rtb1.ScrollToCaret();
                                rtb1.Visible = true;
                            }
                            Application.DoEvents();
                        }
                    }
                    t += s + "\n";
                }
            }
            Status.Text         = "State : Done";
            rtb1.Text           = t;
            rtb1.SelectionStart = rtb1.TextLength;
            rtb1.ScrollToCaret();
            pb1.Value = 0;
            pauseToolStripMenuItem.Visible = false;
        }
예제 #26
0
        private void extractToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string currentDir    = ME3Directory.cookedPath;
            string imgFileName   = null;
            string imgFileFolder = null;

            // setting TexSelection Form to export images
            TexSelection texSelection = new TexSelection(tex2D);

            texSelection.FormTitle        = "Select images to extract";
            texSelection.btnSelectionText = "Extract";
            if (tex2D.imgList.Count > 1)
            {
                texSelection.ShowDialog();
                texSelection.Dispose();
            }
            else
            {
                texSelection.bOk = true;
            }

            if (texSelection.bOk)
            {
                try
                {
                    // check that the image list has at least one image stored inside an external archive, if not it's useless to search the archive location
                    if (tex2D.imgList.Any(images => images.storageType == Texture2D.storage.arcCpr || images.storageType == Texture2D.storage.arcUnc))
                    {
                        // check if archive file is present in the same pcc directory
                        string archivePath = currentDir + tex2D.arcName + ".tfc";
                        if (!File.Exists(archivePath))
                        {
                            OpenFileDialog openArchive = openFileDialog;
                            openArchive.Title  = "Select the .tfc archive needed to extract images";
                            openArchive.Filter = tex2D.arcName + ".tfc|" + tex2D.arcName + ".tfc|All files|*.*";

                            // try to open the last opened directory
                            archivePath = openArchive.InitialDirectory + "\\" + tex2D.arcName + ".tfc";
                            if (File.Exists(archivePath)) // if the archive exists then use it directly
                            {
                                currentDir = openArchive.InitialDirectory;
                            }
                            else // if not then the user searches for it
                            {
                                DialogResult resultSelection;
                                do
                                {
                                    resultSelection = openArchive.ShowDialog();
                                } while (!File.Exists(openArchive.FileName) && resultSelection != DialogResult.Cancel);

                                if (resultSelection == DialogResult.Cancel)
                                {
                                    return; // exit if user press cancel (or undo)
                                }
                                else
                                {
                                    openArchive.InitialDirectory = Path.GetDirectoryName(openArchive.FileName);
                                    currentDir = Path.GetDirectoryName(openArchive.FileName);
                                }
                            }
                        }
                    }

                    if (texSelection.imageListBox.CheckedItems.Count == 1)                                            // if user selected only one image to extract
                    {
                        string         imgSize  = texSelection.imageListBox.CheckedItems[0].ToString().Split(' ')[1]; // take imagesize (ex. 512x512) from checklist text: "Image 512x512 stored..."
                        SaveFileDialog saveFile = new SaveFileDialog();
                        saveFile.Title    = "Select the location to save the image";
                        saveFile.FileName = tex2D.texName + "_" + imgSize + tex2D.getFileFormat();
                        saveFile.Filter   = "Image file|*" + tex2D.getFileFormat() + "|All files|*.*";
                        //saveFile.RestoreDirectory = true;
                        DialogResult resultSelection = saveFile.ShowDialog();
                        if (resultSelection == DialogResult.OK)
                        {
                            imgFileName   = Path.GetFileName(saveFile.FileName);
                            imgFileFolder = Path.GetDirectoryName(saveFile.FileName);
                        }
                        else
                        {
                            return;
                        }
                    }
                    else // if user selected multiple images to extract
                    {
                        FolderBrowserDialog saveFolder = new FolderBrowserDialog();
                        saveFolder.Description = "Select the folder location to save all the images";
                        DialogResult resultSelection = saveFolder.ShowDialog();
                        if (resultSelection == DialogResult.OK)
                        {
                            imgFileFolder = saveFolder.SelectedPath;
                        }
                        else
                        {
                            return;
                        }
                    }

                    // main extraction loop
                    foreach (Object entry in texSelection.imageListBox.CheckedItems)
                    {
                        string imgSize = entry.ToString().Split(' ')[1]; // take imagesize (ex. 512x512) from checklist text: "Image 512x512 stored..."
                        string imgFinalFileName;
                        if (imgFileName == null)
                        {
                            imgFinalFileName = tex2D.texName + "_" + imgSize + tex2D.getFileFormat();
                        }
                        else
                        {
                            imgFinalFileName = imgFileName;
                        }
                        string fullpath = imgFileFolder + "\\" + imgFinalFileName;

                        // extraction function
                        tex2D.extractImage(imgSize, currentDir, fullpath);
                    }

                    // update the pcc with the new replaced infos
                    ListViewItem          item     = listView1.SelectedItems[0];
                    int                   index    = Convert.ToInt32(item.Name);
                    PCCObject.ExportEntry expEntry = pcc.Exports[index];
                    expEntry.Data = tex2D.ToArray(expEntry.DataOffset);
                    //pcc.ChangeExportEntry(index, expEntry);
                    //pcc.UpdateAllOffsets();

                    MessageBox.Show("All images are extracted correctly.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exc)
                {
                    MessageBox.Show("An error occurred while extracting images: " + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #27
0
        public void ReadObjects(int off)
        {
            BitConverter.IsLittleEndian = true;
            int pos   = off;
            int count = BitConverter.ToInt32(memory, pos);

            pos    += 4;
            Objects = new List <int>();
            STM_CA  = new List <StaticMeshCollectionActor>();
            STM_A   = new List <StaticMeshActor>();
            DA      = new List <DecalActor>();
            BV      = new List <BlockingVolume>();
            IA      = new List <InterpActor>();
            SPA     = new List <SplineActor>();
            TP      = new List <TargetPoint>();
            LV      = new List <LightVolume>();
            MM      = new List <MantleMarker>();
            PN      = new List <PathNode>();
            CL      = new List <CoverLink>();
            CSM     = new List <CoverSlotMarker>();
            EM      = new List <Emitter>();
            BPVA    = new List <BioPlaypenVolumeAdditive>();
            BTV     = new List <BioTriggerVolume>();
            BPP     = new List <BioPathPoint>();
            WAS     = new List <WwiseAmbientSound>();
            WAV     = new List <WwiseAudioVolume>();
            WEV     = new List <WwiseEnvironmentVolume>();
            for (int i = 0; i < count; i++)
            {
                int idx = BitConverter.ToInt32(memory, pos) - 1;
                if (pcc.isExport(idx))
                {
                    Objects.Add(idx);
                    PCCObject.ExportEntry e = pcc.Exports[idx];
                    switch (e.ClassName)
                    {
                    case "SplineActor":
                        SPA.Add(new SplineActor(pcc, idx));
                        break;

                    case "Emitter":
                        EM.Add(new Emitter(pcc, idx));
                        break;

                    case "MantleMarker":
                        MM.Add(new MantleMarker(pcc, idx));
                        break;

                    case "PathNode":
                        PN.Add(new PathNode(pcc, idx));
                        break;

                    case "CoverLink":
                        CL.Add(new CoverLink(pcc, idx));
                        break;

                    case "CoverSlotMarker":
                        CSM.Add(new CoverSlotMarker(pcc, idx));
                        break;

                    case "TargetPoint":
                        TP.Add(new TargetPoint(pcc, idx));
                        break;

                    case "InterpActor":
                        IA.Add(new InterpActor(pcc, idx));
                        break;

                    case "DecalActor":
                        DA.Add(new DecalActor(pcc, idx));
                        break;

                    case "StaticMeshCollectionActor":
                        STM_CA.Add(new StaticMeshCollectionActor(pcc, idx));
                        break;

                    case "StaticMeshActor":
                        STM_A.Add(new StaticMeshActor(pcc, idx));
                        break;

                    case "BlockingVolume":
                        BV.Add(new BlockingVolume(pcc, idx));
                        break;

                    case "LightVolume":
                        LV.Add(new LightVolume(pcc, idx));
                        break;

                    case "BioPlaypenVolumeAdditive":
                        BPVA.Add(new BioPlaypenVolumeAdditive(pcc, idx));
                        break;

                    case "BioTriggerVolume":
                        BTV.Add(new BioTriggerVolume(pcc, idx));
                        break;

                    case "BioPathPoint":
                        BPP.Add(new BioPathPoint(pcc, idx));
                        break;

                    case "WwiseAmbientSound":
                        WAS.Add(new WwiseAmbientSound(pcc, idx));
                        break;

                    case "WwiseAudioVolume":
                        WAV.Add(new WwiseAudioVolume(pcc, idx));
                        break;

                    case "WwiseEnvironmentVolume":
                        WEV.Add(new WwiseEnvironmentVolume(pcc, idx));
                        break;
                    }
                }
                pos += 4;
            }
        }
예제 #28
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 path = ME3Directory.cookedPath;

            string[] files = Directory.GetFiles(path, "*.pcc");
            pb1.Maximum = files.Length;
            DebugOutput.Clear();
            database = new List <DBEntry>();
            int count = 0;

            foreach (string file in files)
            {
                pb1.Value = count++;
                DebugOutput.PrintLn("Scanning file : " + Path.GetFileName(file) + " ...");
                PCCObject pcc = new PCCObject(file);
                DBEntry   ent = new DBEntry();
                ent.filename = Path.GetFileName(file);
                ent.Objects  = new List <ObjInf>();
                for (int i = 0; i < pcc.Exports.Count; i++)
                {
                    PCCObject.ExportEntry ex = pcc.Exports[i];
                    ObjInf obj;
                    switch (ex.ClassName)
                    {
                    case "StaticMesh":
                        obj       = new ObjInf();
                        obj.Index = i;
                        obj.Type  = 0;
                        obj.name  = ex.ObjectName;
                        ent.Objects.Add(obj);
                        break;

                    case "SkeletalMesh":
                        obj       = new ObjInf();
                        obj.Index = i;
                        obj.Type  = 1;
                        obj.name  = ex.ObjectName;
                        ent.Objects.Add(obj);
                        break;
                    }
                }
                if (ent.Objects.Count != 0)
                {
                    DebugOutput.PrintLn("Found " + ent.Objects.Count + " Objects:", false);
                    //foreach (ObjInf o in ent.Objects)
                    //    DebugOutput.PrintLn("\t" + o.Index + " : " + o.name + " (" + TypeToString(o.Type) + ")", false);
                    //DebugOutput.Update();
                    database.Add(ent);
                }
                else
                {
                    DebugOutput.PrintLn("Nothing...", false);
                }
            }
            RefreshLists();
            pb1.Value = 0;
        }
예제 #29
0
 public void RefreshFromSelected()
 {
     if (Index == -1)
     {
         return;
     }
     if (isExport)
     {
         PCCObject.ExportEntry e = pcc.Exports[Index];
         if (e.idxClassName == 0)
         {
             listBox7.SelectedIndex = 0;
         }
         else
         {
             if (e.idxClassName > 0)
             {
                 listBox3.SelectedIndex = e.idxClassName - 1;
             }
             else
             {
                 listBox4.SelectedIndex = -e.idxClassName - 1;
             }
         }
         if (e.idxLink == 0)
         {
             listBox8.SelectedIndex = 0;
         }
         else
         {
             if (e.idxLink > 0)
             {
                 listBox5.SelectedIndex = e.idxLink - 1;
             }
             else
             {
                 listBox6.SelectedIndex = -e.idxLink - 1;
             }
         }
         hb1.ByteProvider       = new DynamicByteProvider(pcc.Exports[Index].Data);
         listBox9.SelectedIndex = e.idxObjectName;
     }
     else
     {
         PCCObject.ImportEntry i = pcc.Imports[Index];
         //if (i.idxPackageName == 0)
         //    listBox7.SelectedIndex = 0;
         //else
         //{
         //    if (i.idxPackageName > 0)
         //        listBox3.SelectedIndex = i.idxPackageName - 1;
         //    else
         //        listBox4.SelectedIndex = -i.idxPackageName - 1;
         //}
         if (i.idxLink == 0)
         {
             listBox8.SelectedIndex = 0;
         }
         else
         {
             if (i.idxLink > 0)
             {
                 listBox5.SelectedIndex = i.idxLink - 1;
             }
             else
             {
                 listBox6.SelectedIndex = -i.idxLink - 1;
             }
         }
         listBox9.SelectedIndex = i.idxObjectName;
     }
 }
예제 #30
0
        private void pg1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            n = CurrentObjects[n];
            string   name   = e.ChangedItem.Label;
            GridItem parent = e.ChangedItem.Parent;

            //if (parent != null) name = parent.Label;
            if (parent.Label == "data")
            {
                GridItem parent2 = parent.Parent;
                if (parent2 != null)
                {
                    name = parent2.Label;
                }
            }
            if (name == "nameindex")
            {
                name = parent.Label;
            }
            byte[] buff = pcc.Exports[n].Data;
            List <PropertyReader.Property> p = PropertyReader.getPropList(pcc, buff);
            int m = -1;

            for (int i = 0; i < p.Count; i++)
            {
                if (pcc.Names[p[i].Name] == name)
                {
                    m = i;
                }
            }
            if (m == -1)
            {
                return;
            }
            PCCObject.ExportEntry ent = pcc.Exports[n];
            byte[] buff2;
            switch (p[m].TypeVal)
            {
            case PropertyReader.Type.BoolProperty:
                byte res = 0;
                if ((bool)e.ChangedItem.Value == true)
                {
                    res = 1;
                }
                ent.Data[p[m].offsetval] = res;
                break;

            case PropertyReader.Type.FloatProperty:
                buff2 = BitConverter.GetBytes((float)e.ChangedItem.Value);
                for (int i = 0; i < 4; i++)
                {
                    ent.Data[p[m].offsetval + i] = buff2[i];
                }
                break;

            case PropertyReader.Type.IntProperty:
            case PropertyReader.Type.StringRefProperty:
                int newv = Convert.ToInt32(e.ChangedItem.Value);
                int oldv = Convert.ToInt32(e.OldValue);
                buff2 = BitConverter.GetBytes(newv);
                for (int i = 0; i < 4; i++)
                {
                    ent.Data[p[m].offsetval + i] = buff2[i];
                }
                break;

            case PropertyReader.Type.StructProperty:
                if (e.ChangedItem.Value.GetType() == typeof(int))
                {
                    int val = Convert.ToInt32(e.ChangedItem.Value);
                    if (e.ChangedItem.Label == "nameindex")
                    {
                        int val1 = Convert.ToInt32(e.ChangedItem.Value);
                        buff2 = BitConverter.GetBytes(val1);
                        for (int i = 0; i < 4; i++)
                        {
                            ent.Data[p[m].offsetval + i] = buff2[i];
                        }
                        int t = listBox1.SelectedIndex;
                        listBox1.SelectedIndex = -1;
                        listBox1.SelectedIndex = t;
                    }
                    else
                    {
                        string sidx = e.ChangedItem.Label.Replace("[", "");
                        sidx = sidx.Replace("]", "");
                        int index = Convert.ToInt32(sidx);
                        buff2 = BitConverter.GetBytes(val);
                        for (int i = 0; i < 4; i++)
                        {
                            ent.Data[p[m].offsetval + i + index * 4 + 8] = buff2[i];
                        }
                        int t = listBox1.SelectedIndex;
                        listBox1.SelectedIndex = -1;
                        listBox1.SelectedIndex = t;
                    }
                }
                break;

            case PropertyReader.Type.ByteProperty:
            case PropertyReader.Type.NameProperty:
                if (e.ChangedItem.Value.GetType() == typeof(int))
                {
                    int val = Convert.ToInt32(e.ChangedItem.Value);
                    buff2 = BitConverter.GetBytes(val);
                    for (int i = 0; i < 4; i++)
                    {
                        ent.Data[p[m].offsetval + i] = buff2[i];
                    }
                    int t = listBox1.SelectedIndex;
                    listBox1.SelectedIndex = -1;
                    listBox1.SelectedIndex = t;
                }
                break;

            case PropertyReader.Type.ObjectProperty:
                if (e.ChangedItem.Value.GetType() == typeof(int))
                {
                    int val = Convert.ToInt32(e.ChangedItem.Value);
                    buff2 = BitConverter.GetBytes(val);
                    for (int i = 0; i < 4; i++)
                    {
                        ent.Data[p[m].offsetval + i] = buff2[i];
                    }
                    int t = listBox1.SelectedIndex;
                    listBox1.SelectedIndex = -1;
                    listBox1.SelectedIndex = t;
                }
                break;

            default:
                return;
            }
            pcc.Exports[n] = ent;
            pg1.ExpandAllGridItems();
        }