Skip to content

Commit

Permalink
添加大富翁7支持
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludibrium committed Jan 7, 2019
1 parent 83f1c83 commit 1bae9a8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
15 changes: 13 additions & 2 deletions Rich6Extractor/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand All @@ -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));
}
Expand Down
38 changes: 27 additions & 11 deletions Rich6Extractor/Rich6Viewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text;
using System.IO.MemoryMappedFiles;

namespace Rich6Extractor
Expand All @@ -17,9 +16,27 @@ public class Rich6Viewer
public List<string> fileName;
public List<int> fileSize;
public List<long> 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);
Expand All @@ -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<byte>(begin, second, 0, len + 2);
mv.ReadArray<byte>(temp_begin, second, 0, len + 2);
fileName.Add(encoding.GetString(second));
var third = new byte[8];
mv.ReadArray<byte>(begin + 0x100, third, 0, 4);
mv.ReadArray<byte>(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));
}
}
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 1bae9a8

Please sign in to comment.