-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
93 lines (75 loc) · 2.57 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
using System;
using System.IO;
using System.Text;
namespace SXAssetExtractor
{
internal class Program
{
internal struct Header
{
internal byte[] Magic;
internal int NumOfFiles;
internal long Padding;
}
internal struct FileInfo
{
internal byte[] Filename;
internal int Offset;
internal int Size;
internal int TexWidth;
internal int TexHeight;
internal bool HasAlpha;
internal byte[] Padding;
}
private static string TrimB(byte[] In)
{
return Encoding.ASCII.GetString(In).Trim('\0');
}
private static void Main(string[] args)
{
var FO = File.OpenRead(args[0]);
var Rd = new BinaryReader(FO);
var Hdr = new Header
{
Magic = Rd.ReadBytes(4),
NumOfFiles = Rd.ReadInt32(),
Padding = Rd.ReadInt64()
};
var FolNm = TrimB(Hdr.Magic);
var Files = new FileInfo[Hdr.NumOfFiles];
Directory.CreateDirectory(FolNm);
for (int i = 0; i < Hdr.NumOfFiles; i++)
{
Files[i] = new FileInfo
{
Filename = Rd.ReadBytes(8),
Offset = Rd.ReadInt32(),
Size = Rd.ReadInt32(),
TexWidth = Rd.ReadInt32(),
TexHeight = Rd.ReadInt32(),
HasAlpha = Rd.ReadBoolean(),
Padding = Rd.ReadBytes(7)
};
var CurPos = FO.Position;
var Name = TrimB(Files[i].Filename);
var Resolution = $"{Files[i].TexWidth}x{Files[i].TexHeight}";
Console.WriteLine
(
$"Extracting {Name}.BIN\t" +
$"(Size: {Resolution}) " +
$"(Alpha: {(Files[i].HasAlpha ? "Yes" : "No")})"
);
var Out = File.OpenWrite($"{FolNm}/{Name}_{Resolution}.BIN");
var Wrt = new BinaryWriter(Out);
FO.Position = Files[i].Offset;
Wrt.Write(Rd.ReadBytes(Files[i].Size));
Wrt.Close();
Out.Close();
FO.Position = CurPos;
}
Console.WriteLine("\nDone!");
Rd.Close();
FO.Close();
}
}
}