-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
251 lines (214 loc) · 11.5 KB
/
Program.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
242
243
244
245
246
247
248
249
250
251
using GDT;
using MyProg;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Xml.Linq;
using static GDT.GameDataTable;
namespace MyApp // Note: actual namespace depends on the project name.
{
public class MaterialInfo
{
public int materialIndex;
public string mapType;
public string mapFileName;
}
public class Material
{
public string colorMap;
public string normalMap;
public string detailMap;
public string cosinePowerMap;
public string specColorMap;
}
public class xModel
{
public string filename;
public string type;
public string cosinePowerMap;
public string specColorMap;
}
public class Program
{
public static void Main(string[] args)
{
/*var configFile = new IniFile("config.ini");
if (!configFile.KeyExists("TOOLS_PATH"))
{
configFile.Write("TOOLS_PATH", "C:\\");
}
string cod4Path = configFile.Read("TOOLS_PATH");*/
string buf = null;
foreach (string asset in args)
{
if (!File.Exists(asset)) return;
string ext = Path.GetExtension(asset);
bool bConverter;
switch (ext)
{
case ".xmodel_export":
{
handlexModel(asset);
break;
}
case ".xanim_export":
{
if (String.IsNullOrEmpty(buf))
{
Console.WriteLine("drag in animated model");
buf = Console.ReadLine();
}
handlexAnim(asset, buf);
break;
}
case ".gdt":
{
Console.WriteLine("converter or linker");
buf = Console.ReadLine();
switch (buf)
{
case "converter": bConverter = true; break;
case "linker": bConverter = false; break;
default:
{
Console.WriteLine("invalid input, press any key to close");
Console.ReadKey();
return;
}
}
Console.WriteLine("enter the type of assets you wanna do (xanim, xmodel, material, all)");
buf = Console.ReadLine();
switch (buf)
{
case "xmodel": break;
case "xanim": break;
case "material": break;
case "all": break;
default:
{
Console.WriteLine("invalid input, press any key to close");
Console.ReadKey();
return;
}
}
if(bConverter)
handleGDT(asset, buf);
else
handleLinker(asset, buf);
break;
}
default:
{
Console.WriteLine("file \"" + ext + "\" does not have a recognized extension. (xmodel_export, gdt)");
return;
}
}
}
File.AppendAllText("convert.bat", "\npause");
}
public static void handlexModel(string xModel)
{
GameDataTable gameDataTable = new GameDataTable();
if (File.Exists("gdt.gdt"))
gameDataTable.Load("gdt.gdt");
using (StreamReader sr = new StreamReader(xModel))
{
while (sr.Peek() >= 0)
{
string str;
string imgFolder;
string strBuffer;
string[] strArray;
string[] fileArray;
str = sr.ReadLine();
Material material = new Material();
if (!str.StartsWith("MATERIAL"))
continue;
strArray = str.Split(' ');
imgFolder = System.IO.Path.GetDirectoryName(xModel) + "\\_images";
strBuffer = imgFolder + "\\" + strArray[2].Trim('"');
//Console.Write(imgFolder + "\n");
if (System.IO.Path.Exists(strBuffer)) Console.WriteLine(strBuffer);
fileArray = Directory.GetFiles(strBuffer);
foreach (string file in fileArray)
{
if (System.IO.Path.GetFileNameWithoutExtension(file).EndsWith("_c") || System.IO.Path.GetFileNameWithoutExtension(file).EndsWith("_color") || System.IO.Path.GetFileNameWithoutExtension(file).EndsWith("_col")) material.colorMap = file.Substring(file.IndexOf("\\model_export") + 1).Replace("\\", "\\\\");
if (System.IO.Path.GetFileNameWithoutExtension(file).EndsWith("_d") || System.IO.Path.GetFileNameWithoutExtension(file).EndsWith("_detail")) material.detailMap = file.Substring(file.IndexOf("\\model_export") + 1).Replace("\\", "\\\\");
if (System.IO.Path.GetFileNameWithoutExtension(file).EndsWith("_n") || System.IO.Path.GetFileNameWithoutExtension(file).EndsWith("_normal") || System.IO.Path.GetFileNameWithoutExtension(file).EndsWith("_nml")) material.normalMap = file.Substring(file.IndexOf("\\model_export") + 1).Replace("\\", "\\\\");
if (System.IO.Path.GetFileNameWithoutExtension(file).EndsWith("_s") || System.IO.Path.GetFileNameWithoutExtension(file).EndsWith("_specular") || System.IO.Path.GetFileNameWithoutExtension(file).EndsWith("_spec")) material.specColorMap = file.Substring(file.IndexOf("\\model_export") + 1).Replace("\\", "\\\\");
if (System.IO.Path.GetFileNameWithoutExtension(file).EndsWith("_g") || System.IO.Path.GetFileNameWithoutExtension(file).EndsWith("_cosine") || System.IO.Path.GetFileNameWithoutExtension(file).EndsWith("_gloss")) material.cosinePowerMap = file.Substring(file.IndexOf("\\model_export") + 1).Replace("\\", "\\\\");
}
GameDataTable.Asset asset = new GameDataTable.Asset(strArray[2].Trim('"'), "material");
asset["colorMap"] = material.colorMap;
asset["detailMap"] = material.detailMap;
asset["cosinePowerMap"] = material.cosinePowerMap;
asset["normalMap"] = material.normalMap;
asset["specColorMap"] = material.specColorMap;
asset["template"] = "material.template";
asset["materialType"] = "model phong";
asset["surfaceType"] = "<none>";
File.AppendAllText("convert.bat", "\nconverter -nocachedownload -nopause -single \"material\" " + strArray[2]);
gameDataTable["material", asset.Name] = asset;
GameDataTable.Asset xModelAsset = new GameDataTable.Asset(Path.GetFileNameWithoutExtension(xModel), "xmodel");
xModelAsset["filename"] = xModel.Substring(xModel.IndexOf("export\\") + 7).Replace("\\", "\\\\");
xModelAsset["type"] = (Path.GetFileNameWithoutExtension(xModel).StartsWith("vm_") || Path.GetFileNameWithoutExtension(xModel).StartsWith("viewmodel_")) ? "animated" : "rigid";
File.AppendAllText("convert.bat", "\nconverter -nocachedownload -nopause -single \"xmodel\" " + xModelAsset.Name);
gameDataTable["xmodel", xModelAsset.Name] = xModelAsset;
}
gameDataTable.Save("gdt.gdt");
}
}
public static void handlexAnim(string xAnim, string animModel)
{
GameDataTable gameDataTable = new GameDataTable();
if (File.Exists("gdt.gdt"))
gameDataTable.Load("gdt.gdt");
GameDataTable.Asset xAnimAsset = new GameDataTable.Asset(Path.GetFileNameWithoutExtension(xAnim), "xanim");
xAnimAsset["filename"] = xAnim.Substring(xAnim.IndexOf("export\\") + 7).Replace("\\", "\\\\");
xAnimAsset["model"] = animModel.Replace("\"", "").Substring(xAnim.IndexOf("export\\") + 7).Replace("\\", "\\\\");
if (xAnim.Contains("idle") || xAnim.Contains("loop"))
xAnimAsset["looping"] = "1";
xAnimAsset["type"] = "relative";
xAnimAsset["angleError"] = "0.0001";
xAnimAsset["useBones"] = "0";
xAnimAsset["translationError"] = "0.0001";
File.AppendAllText("convert.bat", "\nconverter -nocachedownload -nopause -single \"xmodel\" " + xAnimAsset.Name);
gameDataTable["xanim", xAnimAsset.Name] = xAnimAsset;
gameDataTable.Save("gdt.gdt");
}
public static void handleGDT(string gdt, string type)
{
Console.WriteLine("starting " + type + " asset conversion of GDT " + Path.GetFileNameWithoutExtension(gdt));
GameDataTable gameDataTable = new GameDataTable(gdt);
string buffer;
/*string[] bufferArray = gamePath.Split("\\");
File.WriteAllText("convert.bat", bufferArray[0] + "\n");
File.AppendAllText("convert.bat", "cd " + gamePath + "\\bin");*/
foreach (KeyValuePair<string, Dictionary<string, Asset>> asset in gameDataTable.Assets)
{
if(asset.Key != type) continue;
foreach (KeyValuePair<string, Asset> item in asset.Value)
{
File.AppendAllText("convert.bat", "\nconverter -nocachedownload -nopause -single \"" + type + "\" " + item.Key);
}
}
}
public static void handleLinker(string gdt, string type)
{
Console.WriteLine("starting " + type + " asset list building of GDT " + Path.GetFileNameWithoutExtension(gdt));
GameDataTable gameDataTable = new GameDataTable(gdt);
string buffer;
/*string[] bufferArray = gamePath.Split("\\");*/
File.WriteAllText("assetlist.csv", "//" + Path.GetFileNameWithoutExtension(gdt) + " assetlist" + "\n");
foreach (KeyValuePair<string, Dictionary<string, Asset>> asset in gameDataTable.Assets)
{
if (asset.Key != type) continue;
foreach (KeyValuePair<string, Asset> item in asset.Value)
{
File.AppendAllText("assetlist.csv", "\n" + type + "," + item.Key);
}
}
}
}
}