Example #1
0
        private void extractHEXOfChunkToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;
            int m = listBox2.SelectedIndex;

            if (n == -1 || m == -1)
            {
                return;
            }
            Bundle b = sb.bundles[n];
            SoundWaveAssetEntry sound = sounds[m];

            if (sound.chunks.Count == 0 || sound.chunks[0].sha1 == null)
            {
                return;
            }
            byte[]         data = Tools.GetDataBySHA1(sound.chunks[0].sha1, cat);
            SaveFileDialog d    = new SaveFileDialog();

            d.Filter = "*.bin|*.bin";
            if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                File.WriteAllBytes(d.FileName, data);
                MessageBox.Show("Done.");
            }
        }
Example #2
0
        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;
            int m = listBox2.SelectedIndex;

            if (n == -1 || m == -1)
            {
                return;
            }
            Bundle b = sb.bundles[n];
            SoundWaveAssetEntry sound = sounds[m];

            Bundle.ebxtype ebx = b.ebx[sound.Index];
            string         xml = Encoding.UTF8.GetString(Tools.ExtractEbx(new MemoryStream(Tools.GetDataBySHA1(ebx.SHA1, cat))));

            rtb1.Text = xml;
            if (sound.chunks.Count != 0 && sound.chunks[0].sha1 != null)
            {
                hb1.ByteProvider = new DynamicByteProvider(Tools.GetDataBySHA1(sound.chunks[0].sha1, cat));
            }
            if (sound.chunks.Count == 0)
            {
                return;
            }
            foreach (DialogChunk dc in dchunks)
            {
                if (Tools.ByteArrayCompare(sound.chunks[0].id, dc.id))
                {
                    string     basepath = Path.GetDirectoryName(langTOC.MyPath) + "\\" + Path.GetFileNameWithoutExtension(langTOC.MyPath) + ".sb";
                    FileStream fs       = new FileStream(basepath, FileMode.Open, FileAccess.Read);
                    fs.Seek(dc.offset, 0);
                    byte[] buff = new byte[dc.size];
                    fs.Read(buff, 0, (int)dc.size);
                    hb1.ByteProvider = new DynamicByteProvider(buff);
                }
            }
            listBox3.Items.Clear();
            if (sound.segments.Count != 0)
            {
                for (int i = 0; i < sound.segments.Count; i++)
                {
                    listBox3.Items.Add(i.ToString("d4") + " : Segment at 0x" + sound.segments[i].offset.ToString("X"));
                }
            }
        }
        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            if (CurrentSound == null)
            {
                return;
            }
            SoundWaveAssetEntry sound = CurrentSound;
            SQLiteConnection    con   = Database.GetConnection();

            con.Open();
            byte[] data = new byte[0];
            if (sound.chunks[0].sha1 != null)
            {
                data = Database.getDataBySHA1(sound.chunks[0].sha1, con);
            }
            else
            {
                foreach (DialogChunk dc in dchunks)
                {
                    if (Tools.ByteArrayCompare(sound.chunks[0].id, dc.id))
                    {
                        string     path = Path.GetDirectoryName(langTOC.MyPath) + "\\" + Path.GetFileNameWithoutExtension(langTOC.MyPath) + ".sb";
                        FileStream fs   = new FileStream(path, FileMode.Open, FileAccess.Read);
                        fs.Seek(dc.offset, 0);
                        data = new byte[dc.size];
                        fs.Read(data, 0, (int)dc.size);
                    }
                }
            }
            con.Close();
            if (data.Length == 0)
            {
                return;
            }
            SaveFileDialog d = new SaveFileDialog();

            d.Filter = "*.bin|*.bin";
            if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                hb1.ByteProvider = new DynamicByteProvider(data);
                File.WriteAllBytes(d.FileName, data);
                MessageBox.Show("Done.");
            }
        }
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode t = treeView1.SelectedNode;

            if (t == null || t.Nodes.Count != 0)
            {
                return;
            }
            string path = t.Text;

            while (t.Parent.Text != "Sounds")
            {
                t    = t.Parent;
                path = t.Text + "/" + path;
            }
            SQLiteConnection con = Database.GetConnection();

            con.Open();
            SQLiteDataReader reader = Database.getReader("SELECT sha1 FROM ebx WHERE name='" + path + "'", con);

            reader.Read();
            string sha1 = reader.GetString(0);

            byte[] data = Database.getDataBySHA1(sha1, con);
            try
            {
                CurrentSound           = GetSoundData(data, con);
                CurrentSound.SoundPath = path;
                listBox1.Items.Clear();
                foreach (SoundSegment seg in CurrentSound.segments)
                {
                    listBox1.Items.Add("Segment at 0x" + seg.offset.ToString("X8"));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:\n" + ex.Message);
                con.Close();
                return;
            }
            con.Close();
        }
Example #5
0
        private void ExtractSounds(int a, int b, int c, bool wav)
        {
            if (a == -1 || b == -1 || c == -1)
            {
                return;
            }
            Bundle bun = sb.bundles[a];
            SoundWaveAssetEntry sound = sounds[b];
            SoundSegment        seg   = sound.segments[c];

            byte[] data = new byte[0];
            if (sound.chunks[0].sha1 != null)
            {
                data = Tools.GetDataBySHA1(sound.chunks[0].sha1, cat);
            }
            else
            {
                foreach (DialogChunk dc in dchunks)
                {
                    if (Tools.ByteArrayCompare(sound.chunks[0].id, dc.id))
                    {
                        string     path = Path.GetDirectoryName(langTOC.MyPath) + "\\" + Path.GetFileNameWithoutExtension(langTOC.MyPath) + ".sb";
                        FileStream fs   = new FileStream(path, FileMode.Open, FileAccess.Read);
                        fs.Seek(dc.offset, 0);
                        data = new byte[dc.size];
                        fs.Read(data, 0, (int)dc.size);
                    }
                }
            }
            if (data.Length == 0)
            {
                return;
            }
            int offset = seg.offset;

            if (offset < 0)
            {
                return;
            }
            int toffset = -1;

            for (int i = offset; i >= 0; i--)
            {
                if (data[i] == 0x48 &&
                    data[i + 1] == 0x00 &&
                    data[i + 2] == 0x00 &&
                    data[i + 3] == 0x0C)
                {
                    toffset = i;
                    break;
                }
            }
            if (toffset == -1 || offset - toffset > 0x1000)
            {
                int toffset3 = -1;
                for (int i = offset; i < data.Length; i++)
                {
                    if (data[i] == 0x48 &&
                        data[i + 1] == 0x00 &&
                        data[i + 2] == 0x00 &&
                        data[i + 3] == 0x0C)
                    {
                        toffset3 = i;
                        break;
                    }
                }
                if (toffset3 != -1 && toffset3 - offset < 0x1000)
                {
                    toffset = toffset3;
                }
            }
            offset = toffset;
            int size = data.Length - offset;

            if (c + 1 < sound.segments.Count)
            {
                int offset2 = sound.segments[c + 1].offset;
                toffset = -1;
                for (int i = offset2; i > 0; i--)
                {
                    if (data[i] == 0x48 &&
                        data[i + 1] == 0x00 &&
                        data[i + 2] == 0x00 &&
                        data[i + 3] == 0x0C)
                    {
                        toffset = i;
                        break;
                    }
                }
                if (toffset == -1 || toffset == offset)
                {
                    int toffset3 = -1;
                    for (int i = offset2; i < data.Length; i++)
                    {
                        if (data[i] == 0x48 &&
                            data[i + 1] == 0x00 &&
                            data[i + 2] == 0x00 &&
                            data[i + 3] == 0x0C)
                        {
                            toffset3 = i;
                            break;
                        }
                    }
                    if (toffset3 != -1 && toffset3 - offset2 < 0x1000)
                    {
                        toffset = toffset3;
                    }
                }
                size = toffset - offset;
            }
            string basepath = Application.StartupPath + "\\ealayer3\\";

            byte[] result = new byte[size];
            for (int i = 0; i < size; i++)
            {
                result[i] = data[offset + i];
            }
            CleanUP();
            File.WriteAllBytes(basepath + "temp.bin", result);
            if (wav)
            {
                Tools.RunShell(basepath + "ealayer3.exe", "-w temp.bin");
            }
            else
            {
                Tools.RunShell(basepath + "ealayer3.exe", "temp.bin");
            }
        }
Example #6
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            Bundle b = sb.bundles[n];

            listBox2.Items.Clear();
            sounds = new List <SoundWaveAssetEntry>();
            for (int i = 0; i < b.ebx.Count; i++)
            {
                Bundle.ebxtype ebx = b.ebx[i];
                try
                {
                    string      x   = Encoding.UTF8.GetString(Tools.ExtractEbx(new MemoryStream(Tools.GetDataBySHA1(ebx.SHA1, cat))));
                    XmlDocument xml = new XmlDocument();
                    xml.LoadXml("<xml>" + x + "</xml>");
                    XmlNodeList list = xml.GetElementsByTagName("SoundWaveAsset");
                    foreach (XmlNode node in list)
                    {
                        SoundWaveAssetEntry sound = new SoundWaveAssetEntry();
                        sound.chunks   = new List <SoundChunk>();
                        sound.segments = new List <SoundSegment>();
                        sound.Index    = i;
                        if (node.Name == "SoundWaveAsset")
                        {
                            foreach (XmlNode node2 in node.ChildNodes)
                            {
                                switch (node2.Name)
                                {
                                case "SoundDataAsset":
                                    foreach (XmlNode node3 in node2.ChildNodes)
                                    {
                                        switch (node3.Name)
                                        {
                                        case "Asset":
                                            foreach (XmlNode node4 in node3.ChildNodes)
                                            {
                                                switch (node4.Name)
                                                {
                                                case "Name":
                                                    sound.name = node4.InnerText;
                                                    break;
                                                }
                                            }
                                            break;

                                        case "Chunks":
                                            XmlNode members = node3.ChildNodes[0];
                                            if (members == null)
                                            {
                                                continue;
                                            }
                                            foreach (XmlNode node4 in members)
                                            {
                                                switch (node4.Name)
                                                {
                                                case "SoundDataChunk":
                                                    SoundChunk chunk = new SoundChunk();
                                                    XmlNode    nId   = node4.ChildNodes[0];
                                                    chunk.id = Tools.StringToByteArray(nId.InnerText);
                                                    foreach (CATFile.ChunkType c in cat.chunks)
                                                    {
                                                        if (Tools.ByteArrayCompare(c.id, chunk.id))
                                                        {
                                                            chunk.sha1 = c.sha1;
                                                        }
                                                    }
                                                    sound.chunks.Add(chunk);
                                                    break;
                                                }
                                            }
                                            break;
                                        }
                                    }
                                    break;

                                case "Segments":
                                    foreach (XmlNode node3 in node2.ChildNodes)
                                    {
                                        switch (node3.Name)
                                        {
                                        case "member":
                                            XmlNode swvseg = node3.ChildNodes[0];
                                            if (swvseg != null && swvseg.Name == "SoundWaveVariationSegment")
                                            {
                                                SoundSegment seg    = new SoundSegment();
                                                XmlNode      offset = swvseg.ChildNodes[0];
                                                seg.offset = Convert.ToInt32(offset.InnerText, 16);
                                                sound.segments.Add(seg);
                                            }
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        sounds.Add(sound);
                    }
                }
                catch (Exception)
                {
                }
            }
            foreach (SoundWaveAssetEntry sound in sounds)
            {
                listBox2.Items.Add(sound.name);
            }
        }
        private SoundWaveAssetEntry GetSoundData(byte[] data, SQLiteConnection con)
        {
            string      x   = Encoding.UTF8.GetString(Tools.ExtractEbx(new MemoryStream(data)));
            XmlDocument xml = new XmlDocument();

            xml.LoadXml("<xml>" + x + "</xml>");
            XmlNodeList         list  = xml.GetElementsByTagName("SoundWaveAsset");
            XmlNode             node  = list[0];
            SoundWaveAssetEntry sound = new SoundWaveAssetEntry();

            sound.chunks   = new List <SoundChunk>();
            sound.segments = new List <SoundSegment>();
            if (node.Name == "SoundWaveAsset")
            {
                foreach (XmlNode node2 in node.ChildNodes)
                {
                    switch (node2.Name)
                    {
                    case "SoundDataAsset":
                        foreach (XmlNode node3 in node2.ChildNodes)
                        {
                            switch (node3.Name)
                            {
                            case "Asset":
                                foreach (XmlNode node4 in node3.ChildNodes)
                                {
                                    switch (node4.Name)
                                    {
                                    case "Name":
                                        sound.name = node4.InnerText;
                                        break;
                                    }
                                }
                                break;

                            case "Chunks":
                                XmlNode members = node3.ChildNodes[0];
                                if (members == null)
                                {
                                    continue;
                                }
                                foreach (XmlNode node4 in members)
                                {
                                    switch (node4.Name)
                                    {
                                    case "SoundDataChunk":
                                        SoundChunk chunk = new SoundChunk();
                                        XmlNode    nId   = node4.ChildNodes[0];
                                        chunk.id = Tools.StringToByteArray(nId.InnerText);
                                        SQLiteDataReader reader = Database.getReader("SELECT sha1 FROM chunkids WHERE id='" + nId.InnerText + "'", con);
                                        if (reader.Read())
                                        {
                                            chunk.sha1 = reader.GetString(0);
                                        }
                                        sound.chunks.Add(chunk);
                                        break;
                                    }
                                }
                                break;
                            }
                        }
                        break;

                    case "Segments":
                        foreach (XmlNode node3 in node2.ChildNodes)
                        {
                            switch (node3.Name)
                            {
                            case "member":
                                XmlNode swvseg = node3.ChildNodes[0];
                                if (swvseg != null && swvseg.Name == "SoundWaveVariationSegment")
                                {
                                    SoundSegment seg    = new SoundSegment();
                                    XmlNode      offset = swvseg.ChildNodes[0];
                                    seg.offset = Convert.ToInt32(offset.InnerText, 16);
                                    sound.segments.Add(seg);
                                }
                                break;
                            }
                        }
                        break;
                    }
                }
            }
            return(sound);
        }