-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHActInfo.cs
224 lines (167 loc) · 6.11 KB
/
HActInfo.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Yarhl.FileSystem;
using Yarhl.FileFormat;
using ParLibrary;
using ParLibrary.Converter;
namespace HActLib
{
public struct HActInfo
{
public bool IsTEV;
public string MainPath;
public string[] ResourcesPaths;
public Yarhl.FileSystem.Node Par;
public string ParPath;
private static string GetCMNPath(string path)
{
string def = Path.Combine(path, "cmn");
string alt2 = Path.Combine(path, "cmn.par.unpack", "cmn");
string alt1 = Path.Combine(path, "cmn.par.unpack");
string cmnPath = null;
if (Directory.Exists(def))
cmnPath = def;
else if (Directory.Exists(alt2))
cmnPath = alt2;
else if (Directory.Exists(alt1))
cmnPath = alt1;
if(!string.IsNullOrEmpty(cmnPath))
if (Directory.Exists(Path.Combine(cmnPath, "cmn")))
cmnPath = Path.Combine(cmnPath, "cmn");
if (cmnPath != null)
return Path.Combine(cmnPath, "cmn.bin");
return null;
}
private static string GetTEVPath(string path)
{
string def = null;
if (new DirectoryInfo(path).Name == "tmp")
def = path;
if(new DirectoryInfo(path).GetDirectories().FirstOrDefault(x => x.Name == "tmp") != null)
{
def = Path.Combine(path, "tmp");
}
if (Directory.Exists(def))
return Path.Combine(def, "hact_tev.bin");
return null;
}
private static string TryResPath(string path, string res)
{
string def = Path.Combine(path, res);
string alt2 = Path.Combine(path, $"{res}.par.unpack", res);
string alt1 = Path.Combine(path, $"{res}.par.unpack");
string resPath = null;
if (Directory.Exists(def))
resPath = def;
else if (Directory.Exists(alt2))
resPath = alt2;
else if (Directory.Exists(alt1))
resPath = alt1;
if(!string.IsNullOrEmpty(resPath))
if(Directory.Exists(Path.Combine(resPath, res)))
resPath = Path.Combine(resPath, res);
if (resPath != null)
return Path.Combine(resPath, "res.bin");
else
return null;
}
private static string[] GetRESPath(string path)
{
int count = 0;
string foundPath = null;
List<string> paths = new List<string>();
do
{
foundPath = TryResPath(path, count.ToString("000"));
if (!string.IsNullOrEmpty(foundPath))
paths.Add(foundPath);
count++;
} while (!string.IsNullOrEmpty(foundPath));
return paths.ToArray();
}
public void ProcessPar(string parDir)
{
ParPath = parDir;
Par = NodeFactory.FromFile(ParPath, "par");
Par.TransformWith<ParArchiveReader, ParArchiveReaderParameters>(new ParArchiveReaderParameters() { Recursive = true });
Yarhl.FileSystem.Node cmn = Navigator.IterateNodes(Par).FirstOrDefault(x => x.Path.EndsWith("cmn.bin") || x.Path.EndsWith("hact_tev.bin"));
if (cmn == null)
return;
/*
if (cmn.Path.EndsWith(".par"))
{
var cmnFile = cmn.GetFormatAs<ParFile>();
if (cmnFile.IsCompressed)
cmn.TransformWith<ParLibrary.Sllz.Decompressor>();
var cmnPar = NodeFactory.FromSubstream("cmnpar", cmnFile.Stream, 0, cmnFile.Stream.Length);
MainPath = "cmn.bin";
}
*/
MainPath = cmn.Path;
// string[] paths = Navigator.IterateNodes(par).Select(x => x.Path.Replace(@"/par/./", "")).ToArray();
}
public byte[] GetCmnBuffer()
{
if (string.IsNullOrEmpty(MainPath) || (Par == null && !File.Exists(MainPath)))
return new byte[0];
if (Par == null)
return File.ReadAllBytes(MainPath);
string cmnPath = MainPath;
Yarhl.FileSystem.Node cmn = Navigator.IterateNodes(Par).FirstOrDefault(x => x.Path == cmnPath);
if (cmn != null)
{
var cmnFile = cmn.GetFormatAs<ParFile>();
if (cmnFile.IsCompressed)
cmn.TransformWith<ParLibrary.Sllz.Decompressor>();
byte[] buf = new byte[cmn.Stream.Length];
cmn.Stream.Read(buf, 0, (int)cmn.Stream.Length);
return buf;
}
return new byte[0];
}
public HActInfo(string folder)
{
IsTEV = false;
Par = null;
ParPath = null;
if (folder.EndsWith("hact_tev.bin"))
{
IsTEV = true;
MainPath = folder;
ResourcesPaths = new string[0];
return;
}
else if (folder.EndsWith(".bin"))
{
MainPath = folder;
ResourcesPaths = new string[0];
return;
}
else if (folder.EndsWith(".par"))
{
MainPath = "";
ResourcesPaths = new string[0];
ProcessPar(folder);
return;
}
if (!Directory.Exists(folder))
MainPath = "";
MainPath = GetCMNPath(folder);
if (string.IsNullOrEmpty(MainPath))
{
MainPath = GetTEVPath(folder);
if (!string.IsNullOrEmpty(MainPath))
IsTEV = true;
ResourcesPaths = new string[0];
}
else
{
ResourcesPaths = GetRESPath(folder);
}
}
}
}