-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMXparser.cs
241 lines (201 loc) · 9.23 KB
/
CMXparser.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace PSO2CMXParser
{
public class CMXparser
{
public static List<int> endTagLocations = new List<int>();
public static byte[] stringFlagByte = new byte[2]{0x2,0x12} ;
public static byte[] fileByteArray;
private static bool showDeepLog;
private static bool showLog;
static CMXparser()
{
showLog = true;
showDeepLog = false;
}
public CMXparser(string cmxFile)
{
fileByteArray = File.ReadAllBytes(cmxFile);
string endTag = "vtc0";
byte[] endTagArray = Encoding.UTF8.GetBytes(endTag);
BoyerMoore endTagSearcher = new BoyerMoore(endTagArray);
endTagLocations = endTagSearcher.SearchAll(fileByteArray);
}
public static void ParseCMX(string cmxFile)
{
fileByteArray = File.ReadAllBytes(cmxFile);
string endTag = "vtc0";
byte[] endTagArray = Encoding.UTF8.GetBytes(endTag);
BoyerMoore endTagSearcher = new BoyerMoore(endTagArray);
endTagLocations = endTagSearcher.SearchAll(fileByteArray);
List<byte[]> bodyData = FindDataTag("BODY");
foreach(byte[] data in bodyData){
int id = BitConverter.ToInt32(data, 10);
byte flagByte = data[14];
//start from 14th bit with text 0x__, 0x01, 0x12
string texture1 = Encoding.UTF8.GetString(data, 17, 18);
//string texture2 = Encoding.UTF8.GetString(data, 38, 18);
//string texture3 = Encoding.UTF8.GetString(data, 59, 18);
//string texture4 = Encoding.UTF8.GetString(data, 80, 18);
//string texture5 = Encoding.UTF8.GetString(data, 101, 18);
Console.WriteLine("BODY ID " + id);
Console.WriteLine("file list: {0}", texture1 );
//Console.WriteLine("texture file list: {0}, {1}, {2}, {3}, {4}", texture1 , texture2, texture3,texture4, texture5 );
}
List<byte[]> carmData = FindDataTag("CARM");
foreach(byte[] data in carmData){
int id = BitConverter.ToInt32(data, 10);
string texture1 = Encoding.UTF8.GetString(data, 17, 18);
string texture2 = Encoding.UTF8.GetString(data, 38, 18);
//string texture3 = Encoding.UTF8.GetString(data, 59, 18);
//string texture4 = Encoding.UTF8.GetString(data, 80, 18);
//string texture5 = Encoding.UTF8.GetString(data, 101, 18);
//string texture6 = Encoding.UTF8.GetString(data, 122, 18);
Console.WriteLine("CARM ID " + id);
Console.WriteLine("file list: {0}", texture1 );
//Console.WriteLine("file list: {0}, {1}, {2}, {3}, {4}, {5}", texture1 , texture2, texture3,texture4, texture5, texture6);
}
List<byte[]> clegData = FindDataTag("CLEG");
foreach(byte[] data in clegData){
int id = BitConverter.ToInt32(data, 10);
string texture1 = Encoding.UTF8.GetString(data, 17, 18);
//string texture2 = Encoding.UTF8.GetString(data, 38, 18);
//string texture3 = Encoding.UTF8.GetString(data, 59, 18);
//string texture4 = Encoding.UTF8.GetString(data, 80, 18);
//string texture5 = Encoding.UTF8.GetString(data, 101, 18);
//string texture6 = Encoding.UTF8.GetString(data, 122, 18);
Console.WriteLine("CLEG ID " + id);
Console.WriteLine("texture file list: {0}", texture1 );
//Console.WriteLine("file list: {0}, {1}, {2}, {3}, {4}, {5}", texture1 , texture2, texture3,texture4, texture5, texture6);
}
List<byte[]> bdp1Data = FindDataTag("BDP1");
foreach(byte[] data in bdp1Data){
int id = BitConverter.ToInt32(data, 10);
string texture1 = Encoding.UTF8.GetString(data, 17, 18);
//string texture2 = Encoding.UTF8.GetString(data, 38, 18);
//string texture3 = Encoding.UTF8.GetString(data, 59, 18);
Console.WriteLine("BDP1 ID " + id);
Console.WriteLine("texture file list: {0}", texture1 );
//Console.WriteLine("file list: {0}, {1}, {2}", texture1 , texture2, texture3);
}
List<byte[]> bdp2Data = FindDataTag("BDP2");
foreach(byte[] data in bdp2Data){
int id = BitConverter.ToInt32(data, 10);
string texture1 = Encoding.UTF8.GetString(data, 17, 18);
//string texture2 = Encoding.UTF8.GetString(data, 38, 18);
//string texture3 = Encoding.UTF8.GetString(data, 59, 18);
Console.WriteLine("BDP2 ID " + id);
Console.WriteLine("file list: {0}", texture1 );
//Console.WriteLine("file list: {0}, {1}, {2}", texture1 , texture2, texture3);
}
List<byte[]> eyeData = FindDataTag("EYE ");
foreach(byte[] data in eyeData){
int id = BitConverter.ToInt32(data, 10);
string texture1 = Encoding.UTF8.GetString(data, 17, 18);
Console.WriteLine("EYE ID " + id);
Console.WriteLine("file list: {0}", texture1 );
}
List<byte[]> eyeblData = FindDataTag("EYEL");
foreach(byte[] data in eyeblData){
int id = BitConverter.ToInt32(data, 10);
string texture1 = Encoding.UTF8.GetString(data, 17, 18);
Console.WriteLine("EYEB ID " + id);
Console.WriteLine("file list: {0}", texture1 );
}
List<byte[]> eyebData = FindDataTag("EYEB");
foreach(byte[] data in eyebData){
int id = BitConverter.ToInt32(data, 10);
string texture1 = Encoding.UTF8.GetString(data, 17, 18);
Console.WriteLine("EYEB ID " + id);
Console.WriteLine("file list: {0}", texture1 );
}
List<byte[]> hairData = FindDataTag("HAIR");
foreach(byte[] data in hairData){
int id = BitConverter.ToInt32(data, 10);
string texture1 = Encoding.UTF8.GetString(data, 17, 18);
Console.WriteLine("HAIR ID " + id);
Console.WriteLine("file list: {0}", texture1 );
}
List<byte[]> bblyData = FindDataTag("BBLY");
foreach(byte[] data in bblyData){
int id = BitConverter.ToInt32(data, 10);
string texture1 = Encoding.UTF8.GetString(data, 17, 18);
//string texture2 = Encoding.UTF8.GetString(data, 38, 18);
//string texture3 = Encoding.UTF8.GetString(data, 59, 18);
//string texture4 = Encoding.UTF8.GetString(data, 80, 18);
Console.WriteLine("BBLY ID " + id);
Console.WriteLine("file list: {0}", texture1 );
//Console.WriteLine("texture file list: {0}, {1}, {2}, {3}", texture1 , texture2, texture3,texture4);
}
List<byte[]> faceData = FindDataTag("FACE");
foreach(byte[] data in faceData){
int id = BitConverter.ToInt32(data, 10);
string texture1 = Encoding.UTF8.GetString(data, 17, 18);
Console.WriteLine("FACE ID " + id);
Console.WriteLine("file list: {0}", texture1 );
//Console.WriteLine("texture file list: {0}, {1}, {2}, {3}", texture1 , texture2, texture3,texture4);
}
List<byte[]> fcmnData = FindDataTag("FCMN");
foreach(byte[] data in fcmnData){
int id = BitConverter.ToInt32(data, 10);
string texture1 = Encoding.UTF8.GetString(data, 17, 18);
Console.WriteLine("FCMN ID " + id);
Console.WriteLine("file list: {0}", texture1 );
//Console.WriteLine("texture file list: {0}, {1}, {2}, {3}", texture1 , texture2, texture3,texture4);
}
List<byte[]> bclnData = FindDataTag("BCLN");
foreach(byte[] data in bclnData){
int id = BitConverter.ToInt32(data, 10);
Console.WriteLine("BCLN ID " + id);
}
List<byte[]> iclnData = FindDataTag("ICLN");
foreach(byte[] data in iclnData){
int id = BitConverter.ToInt32(data, 10);
Console.WriteLine("ICLN ID " + id);
}
List<byte[]> acceData = FindDataTag("ACCE");
foreach(byte[] data in acceData){
int id = BitConverter.ToInt32(data, 10);
//start from 14th bit with text 0x__, 0x01, 0x12
string texture1 = Encoding.UTF8.GetString(data, 17, 18);
//string texture2 = Encoding.UTF8.GetString(data, 38, 18);
//string texture3 = Encoding.UTF8.GetString(data, 59, 18);
//string texture4 = Encoding.UTF8.GetString(data, 80, 18);
//string texture5 = Encoding.UTF8.GetString(data, 101, 18);
Console.WriteLine("ACCE ID " + id);
Console.WriteLine("file list: {0}", texture1 );
//Console.WriteLine("texture file list: {0}, {1}, {2}, {3}, {4}", texture1 , texture2, texture3,texture4, texture5 );
}
/*
List<string> tags = new List<string>(){"CARM","CLEG","BDP1","EYEB","BBLY","BCLN","ICLN"};
foreach(var tag in tags){
FindDataTag(tag);
}*/
}
private static List<byte[]> FindDataTag(string tagName)
{
List<byte[]> tagData = new List<byte[]>();
byte[] tagArray = Encoding.UTF8.GetBytes(tagName);
BoyerMoore tagSearcher = new BoyerMoore(tagArray);
List<int> tagLocations = tagSearcher.SearchAll(fileByteArray);
foreach (int location in tagLocations)
{
//Console.WriteLine(tagName + " Tag Location:" + location);
int currentEndTaglocation = endTagLocations.FirstOrDefault(v => v > location);
if(currentEndTaglocation == 0) continue;
//Console.WriteLine(tagName + " Tag End Location:" + currentEndTaglocation);
int arrayLength = currentEndTaglocation - location;
byte[] resultArray = new byte[arrayLength];
Array.Copy(fileByteArray, location, resultArray, 0, arrayLength);
//Console.WriteLine("Tag Content: ");
//Console.WriteLine(Encoding.UTF8.GetString(resultArray));
tagData.Add(resultArray);
}
return tagData;
}
}
}