Beispiel #1
0
 private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
 {
     if ((string)e.Node.Tag == "1")
     {
         var data = new SprFileData();
         data          = SprList[int.Parse(e.Node.Name)];
         textBox3.Text = data.var1.ToString("X");
         textBox4.Text = data.LoopCount1.ToString("X");
         textBox5.Text = data.LoopCount2.ToString("X");
         textBox6.Text = data.var4.ToString("X");
         textBox7.Text = "(" + data.ColorType.ToString("X") + ")-> " +
                         Enum.GetName(typeof(Format), ColorFomat3D3[data.ColorType]);
         textBox8.Text = data.TexBlendType.ToString("X");
         textBox9.Text = "(" + data.m_FileType.ToString("X") + ")-> " +
                         Enum.GetName(typeof(D3DIMAGE_FILEFORMAT), data.m_FileType);
         textBox10.Text = data.SearchColor[0].ToString("X2") + data.SearchColor[1].ToString("X2") +
                          data.SearchColor[2].ToString("X2");
         textBox11.Text = ((short)data.Width).ToString();
         textBox12.Text = ((short)data.Height).ToString();
         textBox13.Text = data.NumPixels.ToString("X");
         label12.Text   = "Byte Count: " + data.ImageData.Length.ToString("X");
         label13.Text   = "Data Offset: " + data.DataOffset.ToString("X");
         CreateBitmap((short)data.Width, (short)data.Height, data.ImageData, ColorPixel[data.ColorType]);
     }
 }
Beispiel #2
0
        private void saveImageFile(string type)
        {
            if (type == "dds")
            {
                saveFileDialog1.Filter = "DDS .dds|*.dds";
            }
            else
            {
                saveFileDialog1.Filter = "PNG .png|*.png";
            }

            try
            {
                saveFileDialog1.FileName = "";
                saveFileDialog1.ShowDialog();
                if (!string.IsNullOrEmpty(saveFileDialog1.FileName) && treeView1 != null &&
                    treeView1.SelectedNode != null)
                {
                    var fileName = saveFileDialog1.FileName;
                    var data     = new SprFileData();
                    data = SprList[int.Parse(treeView1.SelectedNode.Name)];
                    var surface = m_Device.GetBackBuffer(0, 0, BackBufferType.Mono);
                    surface.Device.CreateOffscreenPlainSurface((short)data.Width, (short)data.Height,
                                                               ColorFomat3D3[data.ColorType], Pool.Default);
                    var srcTexture = new Texture(surface.Device, (short)data.Width, (short)data.Height, 1, Usage.None,
                                                 ColorFomat3D3[data.ColorType], Pool.Managed);
                    var stream = srcTexture.LockRectangle(0, LockFlags.None);
                    if (stream.CanWrite)
                    {
                        stream.Write(data.ImageData, 0, data.ImageData.Length);
                    }
                    srcTexture.UnlockRectangle(0);
                    stream.Dispose();

                    if (type == "dds")
                    {
                        TextureLoader.Save(fileName, ImageFileFormat.Dds, srcTexture);
                    }
                    else
                    {
                        TextureLoader.Save(fileName, ImageFileFormat.Png, srcTexture);
                    }

                    srcTexture.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #3
0
        private void ParseSprFile(string fileName, int fileType)
        {
            var num    = 1;
            var header = new SprFileHeader();

            using (var stream = new FileStream(fileName, FileMode.Open))
            {
                var reader = new BinaryReader(stream);
                try
                {
                    if (fileType == 1)
                    {
                        var count = 0;
                        num   = reader.ReadInt32();
                        count = num * 8;
                        reader.ReadBytes(count);
                    }

                    while (num > 0)
                    {
                        if (fileType == 1)
                        {
                            reader.ReadInt32();
                            header.ItemIDCount = reader.ReadInt32();
                            for (int x = 0; x < header.ItemIDCount; x++)
                            {
                                header.ItemID = reader.ReadInt32();
                            }
                        }
                        header.FirstRead  = reader.ReadBytes(ReadSizeType);
                        header.SecondRead = reader.ReadBytes(ReadSizeType);
                        header.ImgCount   = reader.ReadInt32();
                        for (var j = header.ImgCount; j > 0; j--)
                        {
                            var item = new SprFileData();
                            item.var1       = reader.ReadInt32();
                            item.LoopCount1 = reader.ReadInt32();
                            if (item.LoopCount1 > 0)
                            {
                                for (var k = 0; k < item.LoopCount1; k++)
                                {
                                    item.LoopVars1.Add(reader.ReadInt32());
                                    item.LoopVars1.Add(reader.ReadInt32());
                                    item.LoopVars1.Add(reader.ReadInt32());
                                    item.LoopVars1.Add(reader.ReadInt32());
                                }
                            }

                            item.LoopCount2 = reader.ReadInt32();
                            if (item.LoopCount2 > 0)
                            {
                                for (var m = 0; m < item.LoopCount2; m++)
                                {
                                    item.LoopVars2.Add(reader.ReadInt32());
                                    item.LoopVars2.Add(reader.ReadInt32());
                                    item.LoopVars2.Add(reader.ReadInt32());
                                    item.LoopVars2.Add(reader.ReadInt32());
                                }
                            }

                            item.var4         = reader.ReadByte();
                            item.ColorType    = reader.ReadInt32();
                            item.TexBlendType = reader.ReadInt32();
                            item.m_FileType   = reader.ReadInt32();
                            item.SearchColor  = reader.ReadBytes(3);
                            item.Width        = reader.ReadInt32();
                            item.Height       = reader.ReadInt32();
                            item.NumPixels    = reader.ReadInt32();
                            var num6 = 0;
                            switch (item.ColorType)
                            {
                            case 3:
                                num6 = item.NumPixels << 1;
                                break;

                            case 4:
                                num6 = item.NumPixels << 2;
                                break;
                            }

                            item.ImageData  = new byte[num6];
                            item.DataOffset = reader.BaseStream.Position;
                            item.ImageData  = reader.ReadBytes(num6);
                            SprList.Add(item);
                        }

                        num--;

                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                    }
                }
                catch (EndOfStreamException)
                {
                    reader.Close();
                }
                finally
                {
                    if (reader != null)
                    {
                        ((IDisposable)reader).Dispose();
                    }
                }

                stream.Close();
            }

            var index = 0;

            index = 0;
            while (index < 0x80)
            {
                if (header.FirstRead[index] == 0)
                {
                    break;
                }
                index++;
            }

            var encoding = Encoding.GetEncoding("euc-kr");
            var str      = encoding.GetString(header.FirstRead, 0, index);

            header.SprFileName = str;
            str   = "";
            index = 0;
            while (index < 0x80)
            {
                if (header.SecondRead[index] == 0)
                {
                    break;
                }
                index++;
            }

            str = encoding.GetString(header.SecondRead, 0, index);
            header.SprDescrption = str;
            textBox1.Text        = header.SprFileName;
            textBox2.Text        = header.SprDescrption;
            for (var i = 0; i < SprList.Count; i++)
            {
                var num10 = i + 1;
                treeView1.Nodes["mainNode"].Nodes.Add(i.ToString(), "Image : " + num10);
                treeView1.Nodes["mainNode"].Nodes[i.ToString()].Tag = "1";
            }
        }
Beispiel #4
0
        private void buttonAuto_Click(object sender, EventArgs e)
        {
            var dialog = new FolderBrowserDialog();

            dialog.Description = "Select the folder that contain .spr files";
            dialog.ShowDialog();
            var selectedPath = dialog.SelectedPath;

            if (string.IsNullOrEmpty(selectedPath))
            {
                return;
            }

            var info             = new DirectoryInfo(selectedPath);
            var currentDirectory = Directory.GetCurrentDirectory();
            var savingDirectory  = currentDirectory + @"\SprImages\";

            if (info.GetFiles("*.spr").Length <= 0)
            {
                MessageBox.Show("No .spr files found");
                return;
            }

            if (Directory.CreateDirectory(savingDirectory).Exists)
            {
                Process.Start(savingDirectory);
            }

            foreach (var info2 in info.GetFiles("*.spr"))
            {
                var flag = true;
                if (info2.Name == "Dialog_Group.spr")
                {
                    flag = false;
                }
                if (info2.Name == "Dialog_Map.spr")
                {
                    flag = false;
                }
                if (flag)
                {
                    Sname = info2.Name;
                    ParseSprFile(info2.Directory + @"\" + info2.Name, 0);

                    Directory.CreateDirectory(savingDirectory + info2.Name);
                    for (var i = 0; i < treeView1.Nodes[0].Nodes.Count; i++)
                    {
                        treeView1.SelectedNode = treeView1.Nodes[0].Nodes[i];
                        treeView1.Select();

                        var data = new SprFileData();
                        data = SprList[int.Parse(treeView1.SelectedNode.Name)];
                        var surface = m_Device.GetBackBuffer(0, 0, BackBufferType.Mono);
                        surface.Device.CreateOffscreenPlainSurface((short)data.Width, (short)data.Height,
                                                                   ColorFomat3D3[data.ColorType], Pool.Default);
                        var srcTexture = new Texture(surface.Device, (short)data.Width, (short)data.Height, 1,
                                                     Usage.None, ColorFomat3D3[data.ColorType], Pool.Managed);
                        var stream = srcTexture.LockRectangle(0, LockFlags.None);
                        if (stream.CanWrite)
                        {
                            stream.Write(data.ImageData, 0, data.ImageData.Length);
                        }
                        srcTexture.UnlockRectangle(0);

                        surface.Dispose();
                        stream.Dispose();

                        if (radioButtonDds.Checked)
                        {
                            TextureLoader.Save(
                                savingDirectory + info2.Name + @"\" + treeView1.SelectedNode.Name +
                                ".dds",
                                ImageFileFormat.Dds, srcTexture);
                        }
                        else
                        {
                            TextureLoader.Save(
                                savingDirectory + info2.Name + @"\" + treeView1.SelectedNode.Name +
                                ".png",
                                ImageFileFormat.Png, srcTexture);
                        }


                        srcTexture.Dispose();

                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                    }
                }

                treeView1.Nodes["mainNode"].Nodes.Clear();
                SprList.Clear();
            }

            MessageBox.Show("Completed, extracted to:\n" + savingDirectory);
        }