-
Notifications
You must be signed in to change notification settings - Fork 0
/
COD4_Decompress.cs
136 lines (132 loc) · 3.82 KB
/
COD4_Decompress.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Collections;
using System.Xml;
using System.Diagnostics;
using System.IO;
namespace ffManager
{
public class COD4_Decompress
{
private ArrayList missing_files = new ArrayList();
private string fastfile;
private string console;
private string extractDir;
private string dumpDir;
private string hashDir;
private string DS = ffManager.MainClass.getOS() == "win32" ? @"\" : "/";
private XmlDocument offsets;
public COD4_Decompress (string file, string console)
{
fastfile = file;
this.console = console;
}
public void decompress(string dir, string xml)
{
offsets = new XmlDocument();
offsets.Load(xml);
if(Directory.Exists(dir)) Directory.Delete(dir,true);
extractDir = dir + DS + "scripts";
dumpDir = dir + DS + "raw";
hashDir = dir + DS + "hashes";
Directory.CreateDirectory(dir);
Directory.CreateDirectory(extractDir);
Directory.CreateDirectory(dumpDir);
Directory.CreateDirectory(hashDir);
Process ps = new Process();
ps.StartInfo.CreateNoWindow = true;
ps.StartInfo.WindowStyle= ProcessWindowStyle.Hidden;
string decomp = "";
if(ffManager.MainClass.console == "ps3")
{
decomp = "-z -15";
}
else if(ffManager.MainClass.console == "xbox")
{
decomp = "";
}
if(ffManager.MainClass.getOS() == "win32")
{
ps.StartInfo.FileName = MainClass.cwd + @"\offzip.exe";
ps.StartInfo.Arguments = "-a " + decomp + @" """ + fastfile + @""" " + @"""" + dumpDir + @""" 0";
}
else if(ffManager.MainClass.getOS() == "unix")
{
ps.StartInfo.FileName = "wine";
ps.StartInfo.Arguments =@"""" + MainClass.cwd + @"/offzip.exe"" -a " + decomp + @" """ + fastfile + @""" " + @"""" + dumpDir + @""" 0";
}
ps.Start();
ps.WaitForExit();
writeScripts();
}
private void writeScripts()
{
XmlNodeList files = offsets.GetElementsByTagName("file");
foreach(XmlNode file in files)
{
Console.WriteLine("Processing " + file.Attributes["name"].Value);
if(!File.Exists(extractDir + DS + file))
File.WriteAllText(extractDir + DS + file.Attributes["name"].Value,"");
extractData(file);
File.WriteAllText(hashDir + DS + file.Attributes["name"].Value + ".md5",MainClass.GetMD5HashFromFile(extractDir + DS + file.Attributes["name"].Value));
}
}
private void extractData(XmlNode data)
{
XmlNodeList dats = data.ChildNodes;
foreach(XmlNode dat in dats)
{
extractPart(dat, data.Attributes["name"].Value);
}
}
private void extractPart(XmlNode part, string file)
{
string source = locateDumpFile(part.Attributes["name"].Value);
if(source == "")
{
ArrayList data = new ArrayList();
data.Add(part.Attributes["name"].Value);
data.Add(file);
missing_files.Add(data);
return;
}
long spos = Convert.ToInt64(part.Attributes["startpos"].Value);
long epos = Convert.ToInt64(part.Attributes["endpos"].Value);
BinaryReader source_handle = new BinaryReader( File.OpenRead(dumpDir + DS + source));
BinaryWriter file_fhandle = new BinaryWriter( File.Open(extractDir + DS + file,FileMode.Append,FileAccess.Write));
source_handle.BaseStream.Seek(spos, SeekOrigin.Begin);
long size = epos - spos;
long len = 0;
try
{
while(len <= size)
{
byte data = source_handle.ReadByte();
if(data != 0x00)
file_fhandle.BaseStream.WriteByte(data);
len++;
}
}
catch (EndOfStreamException feof)
{
source_handle.Close();
file_fhandle.Close();
}
source_handle.Close();
file_fhandle.Close();
}
private string locateDumpFile(string name)
{
DirectoryInfo files = new DirectoryInfo(dumpDir);
foreach(FileInfo finfo in files.GetFiles())
{
if(finfo.Name.Replace(finfo.Extension,"") == name)
return finfo.Name;
}
return "";
}
public ArrayList getMissingFiles()
{
return missing_files;
}
}
}