-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
187 lines (170 loc) · 7.09 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
using ModLib;
namespace WiiUTexturesTool
{
internal class Program
{
static string Version = "1.1";
static void Main(string[] args)
{
//string input = @"A:\Dimensions\EXTRACT\LEVELS\STORY\11SCOOBYDOO\11SCOOBYDOOA\11SCOOBYDOOA_NXG_DESWIZZLED\Lightmap.3.dds";
//using (ModFile file = ModFile.Open(input, true))
//{
// file.Seek(12, SeekOrigin.Begin);
// int height = file.ReadInt();
// int width = file.ReadInt();
// file.Seek(8, SeekOrigin.Current);
// int mipmapCount = file.ReadInt();
// file.Seek(0x80, SeekOrigin.Begin);
// Pair[] pairs = new Pair[(int)Math.Ceiling(((float)(file.Length - file.Position)) / 16)];
// for (int i = 0; i < pairs.Length; i++)
// {
// pairs[i] = new Pair()
// {
// Part1 = file.ReadLong(),
// Part2 = file.ReadLong()
// };
// }
// Pair[] result = DXT1.Swizzle(pairs, width, height, mipmapCount);
// using (ModFile resultFile = ModFile.Create(@"A:\Dimensions\EXTRACT\LEVELS\STORY\11SCOOBYDOO\11SCOOBYDOOA\11SCOOBYDOOA_NXG_DESWIZZLED\Lightmap.3.1.dds"))
// {
// file.Seek(0, SeekOrigin.Begin);
// file.fileStream.SetLength(0x80);
// file.fileStream.CopyTo(resultFile.fileStream);
// for (int i = 0; i < result.Length; i++)
// {
// resultFile.WriteLong(result[i].Part1);
// resultFile.WriteLong(result[i].Part2);
// }
// }
//}
//return;
#if DEBUG
//foreach (string file in Directory.EnumerateFiles(@"A:\Dimensions\EXTRACT\LEVELS\STORY\", "*.WIIU_TEXTURES", SearchOption.AllDirectories))
//{
//ExtractSettings settings = new ExtractSettings()
//{
// InputLocation = @"A:\Dimensions\EXTRACT\LEVELS\STORY\4DOCTORWHO\4DOCTORWHO_MATERIALS_NXG.WIIU_TEXTURES",
// OutputLocation = @"A:\Dimensions\EXTRACT\LEVELS\STORY\4DOCTORWHO",
// ShouldDeswizzle = true
//};
//Extractor.Extract(settings);
//}
#else
if (args.Length == 0)
{
Logger.Log(new LogSeg("WiiUTexturesTool - "), new LogSeg("Version {0}", ConsoleColor.DarkYellow, Version));
Logger.Log(new LogSeg("Author: "), new LogSeg("Connor", ConsoleColor.Green));
ShowOptions();
Console.ReadKey();
return;
}
string command = args[0].ToLower();
if (command == "extract" || command == "e")
{
WUTExtractSettings settings = new WUTExtractSettings()
{
ShouldDeswizzle = true
};
for (int i = 0; i < args.Length; i++)
{
if (args[i].Length == 0) continue;
string arg = args[i];
if (ValidateArgument(arg, "input"))
{
settings.InputLocation = args[i + 1];
i++;
}
else if (ValidateArgument(arg, "output"))
{
settings.OutputLocation = args[i + 1];
i++;
}
else if (ValidateArgument(arg, "disable-deswizzle"))
{
settings.ShouldDeswizzle = false;
}
else if (arg.EndsWith("wiiu_textures"))
{
settings.InputLocation = args[i];
}
else
{
settings.OutputLocation = args[i];
}
}
Logger.Log("Extracting {0} into {1} with deswizzling {2}", settings.InputLocation, settings.OutputLocation, settings.ShouldDeswizzle ? "enabled" : "disabled");
WiiUTextures.Extract(settings);
}
else if (command == "import" || command == "i")
{
Logger.Error("Not yet supported - Check if a newer version of WiiUTexturesTool is available!");
}
else
{
foreach (string arg in args)
{
if (arg.ToLower().EndsWith("wiiu_textures"))
{
WiiUTextures.Extract(new WUTExtractSettings()
{
InputLocation = arg,
OutputLocation = GetOutputFromInput(arg),
ShouldDeswizzle = true
});
}
}
}
#endif
}
private static bool ValidateArgument(string arg, string option)
{
return (arg == option) || (arg == "-" + option[0]) || (arg == "--" + option[0]) || (arg == "-" + option) ||
(arg == "--" + option);
}
private static string GetOutputFromInput(string inputLocation)
{
return (Path.IsPathFullyQualified(inputLocation) ? Path.GetDirectoryName(inputLocation) : Directory.GetCurrentDirectory()) + "\\" + Path.GetFileNameWithoutExtension(inputLocation);
}
private static void ShowOptions()
{
Console.WriteLine();
Logger.Log("What would you like to do?");
Logger.Log(new LogSeg("1) "), new LogSeg("Extract textures from wiiu_textures", ConsoleColor.Gray));
if (Console.ReadKey().Key == ConsoleKey.D1)
{
ShowExtract();
}
else
{
Console.WriteLine();
Logger.Error("Invalid option\n");
ShowOptions();
}
}
private static void ShowExtract()
{
Logger.Log(new LogSeg("\nDrag and drop your wiiu_textures file here and press enter:"));
string input = Console.ReadLine();
if (input.Length < 4)
{ // Fail safe
Logger.Error("Input {0} is too short to be a valid file!", input);
ShowExtract();
}
if (input[0] == '"') input = input.Substring(1, (input[input.Length - 1] == '"') ? input.Length - 2 : input.Length - 1); // Strip speech marks
if (File.Exists(input))
{
WiiUTextures.Extract(new WUTExtractSettings()
{
InputLocation = input,
OutputLocation = GetOutputFromInput(input),
ShouldDeswizzle = true
});
}
else
{
Logger.Error("File {0} does not exist!\n", input);
ShowExtract();
}
}
}
}