diff --git a/Rich6Extractor/Form1.cs b/Rich6Extractor/Form1.cs index aad076b..840404b 100644 --- a/Rich6Extractor/Form1.cs +++ b/Rich6Extractor/Form1.cs @@ -24,13 +24,22 @@ public Form1() private void ToolStripMenuItem1_Click(object sender, EventArgs e) { + textBox1.Clear(); + textBox2.Clear(); var f = new OpenFileDialog(); f.Filter = ".pck文件|*.pck"; f.ShowDialog(); if (f.FileName.Length > 0) { path = f.FileName; - viewer = new Rich6Viewer(path); + int v; + byte[] header = new byte[8]; + using (var tempF=File.Open(path, FileMode.Open)){ + tempF.Read(header, 0, 8); + if (header[4] == 0x1) v = 6; + else v = 7; + } + viewer = new Rich6Viewer(path, v); viewer.ReadAll(); for (int i = 0; i < viewer.fileName.Count; i++) { @@ -52,7 +61,9 @@ private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs contextMenuStrip1.Show(new Point(MousePosition.X, MousePosition.Y)); } int index = e.Node.Index; - textBox2.Text = "Size:" + viewer.fileSize[index] + " " + "Offset:" + viewer.fileOffset[index] + " (decimal)"; + textBox2.Text = ("Size:" + viewer.fileSize[index].ToString("X8") + " " + + "Offset:" + viewer.fileOffset[index].ToString("X8") + " " + + " meta:"+(0x9+0x108*(index-1)).ToString("X8")); var encoding = Encoding.GetEncoding(936); textBox1.Text = encoding.GetString(viewer.ReadNode(index)); } diff --git a/Rich6Extractor/Rich6Viewer.cs b/Rich6Extractor/Rich6Viewer.cs index 778c4c3..9c584e1 100644 --- a/Rich6Extractor/Rich6Viewer.cs +++ b/Rich6Extractor/Rich6Viewer.cs @@ -4,7 +4,6 @@ using System.Text; using System.Threading.Tasks; using System.IO; -using System.Text; using System.IO.MemoryMappedFiles; namespace Rich6Extractor @@ -17,9 +16,27 @@ public class Rich6Viewer public List fileName; public List fileSize; public List fileOffset; - public Rich6Viewer(string path) + + public int begin; + public int stride = 0x108; + int sizeLen; + + public Rich6Viewer(string path,int RichVersion) { this.path = path; + switch (RichVersion) { + case 6: + sizeLen = 4; + begin = 9; + break; + case 7: + sizeLen = 4; + begin = 8; + break; + default: + throw new ArgumentException("No Support Rich Version."); + } + try { m = MemoryMappedFile.CreateFromFile(path); @@ -33,22 +50,21 @@ public Rich6Viewer(string path) public void ReadAll() { - int stride = 0x108; var encoding = Encoding.GetEncoding(936); - for (int begin = 0x9; begin < 0x8a200; begin += stride) + for (int temp_begin = begin; temp_begin < 0x8a200; temp_begin += stride) { int len = 0; - while (mv.ReadByte(begin + len) != 0) len++; + while (mv.ReadByte(temp_begin + len) != 0) len++; byte[] second = new byte[len + 2]; - mv.ReadArray(begin, second, 0, len + 2); + mv.ReadArray(temp_begin, second, 0, len + 2); fileName.Add(encoding.GetString(second)); var third = new byte[8]; - mv.ReadArray(begin + 0x100, third, 0, 4); + mv.ReadArray(temp_begin + stride - sizeLen - 0x4, third, 0, 4); //Buffer.BlockCopy(data, begin + 0x100, third, 0, 4); fileOffset.Add(BitConverter.ToInt64(third, 0)); third = new byte[4]; - mv.ReadArray(begin + 0x104, third, 0, 4); - // Buffer.BlockCopy(data, begin + 0x104, third, 0, 4); + mv.ReadArray(temp_begin + stride - sizeLen, third, 0, 4); + // Buffer.BlockCopy(data, begin + 0x104, third, 0, 4); fileSize.Add(BitConverter.ToInt32(third, 0)); } } @@ -79,9 +95,9 @@ public string InputNode(string p, int index) mv.WriteArray(offset, input, 0, input.Length); //Buffer.BlockCopy(input, 0, data, Convert.ToInt32(offset), Convert.ToInt32(fileinfo.Length)); var size = BitConverter.GetBytes(fileSize[index]); - mv.Write(0x9 + 0x108 * (index - 1) + 0x104, Convert.ToInt32(fileinfo.Length)); + mv.Write(begin + stride * (index - 1) + stride - sizeLen, Convert.ToInt32(fileinfo.Length)); //Buffer.BlockCopy(size, 0, data, 0x9 + 0x108 * (index - 1) + 0x104, 4); - result = "Success"; + result = "Success"; } catch (Exception e) {