forked from kiraio-moe/UnityWebTools.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnityWebData.cs
161 lines (151 loc) · 4.61 KB
/
UnityWebData.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
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
namespace Kaitai
{
/// <summary>
/// UnityWebData are the Unity game engine file format used to store the
/// game data and resources for WebGL build.
/// </summary>
/// <remarks>
/// Reference: <a href="https://forum.xentax.com/viewtopic.php?f=21&p=187239">Source</a>
/// </remarks>
public partial class UnityWebData : KaitaiStruct
{
public static UnityWebData FromFile(string fileName)
{
return new UnityWebData(new KaitaiStream(fileName));
}
public UnityWebData(
KaitaiStream p__io,
KaitaiStruct p__parent = null,
UnityWebData p__root = null
) : base(p__io)
{
m_parent = p__parent;
m_root = p__root ?? this;
_read();
}
private void _read()
{
_magic = System.Text.Encoding
.GetEncoding("utf-8")
.GetString(m_io.ReadBytesTerm(0, false, true, true));
_beginOffset = m_io.ReadU4le();
_files = new List<FileEntry>();
{
var i = 0;
FileEntry M_;
do
{
M_ = new FileEntry(m_io, this, m_root);
_files.Add(M_);
i++;
} while (!(M_Io.Pos == BeginOffset));
}
}
public partial class FileEntry : KaitaiStruct
{
public static FileEntry FromFile(string fileName)
{
return new FileEntry(new KaitaiStream(fileName));
}
public FileEntry(
KaitaiStream p__io,
UnityWebData p__parent = null,
UnityWebData p__root = null
) : base(p__io)
{
m_parent = p__parent;
m_root = p__root;
f_data = false;
_read();
}
private void _read()
{
_fileOffset = m_io.ReadU4le();
_fileSize = m_io.ReadU4le();
_filenameLength = m_io.ReadU4le();
_filename = System.Text.Encoding
.GetEncoding("utf-8")
.GetString(m_io.ReadBytes(FilenameLength));
}
private bool f_data;
private byte[] _data;
public byte[] Data
{
get
{
if (f_data)
return _data;
KaitaiStream io = M_Root.M_Io;
long _pos = io.Pos;
io.Seek(FileOffset);
_data = io.ReadBytes(FileSize);
io.Seek(_pos);
f_data = true;
return _data;
}
}
private uint _fileOffset;
private uint _fileSize;
private uint _filenameLength;
private string _filename;
private UnityWebData m_root;
private UnityWebData m_parent;
public uint FileOffset
{
get { return _fileOffset; }
}
public uint FileSize
{
get { return _fileSize; }
}
public uint FilenameLength
{
get { return _filenameLength; }
}
public string Filename
{
get { return _filename; }
}
public UnityWebData M_Root
{
get { return m_root; }
}
public UnityWebData M_Parent
{
get { return m_parent; }
}
}
private string _magic;
private uint _beginOffset;
private List<FileEntry> _files;
private UnityWebData m_root;
private KaitaiStruct m_parent;
/// <summary>
/// The file identifier are consist of 16 char `UnityWebData1.0`.
/// </summary>
public string Magic
{
get { return _magic; }
}
/// <summary>
/// The offset value where the first file offset reside.
/// </summary>
public uint BeginOffset
{
get { return _beginOffset; }
}
public List<FileEntry> Files
{
get { return _files; }
}
public UnityWebData M_Root
{
get { return m_root; }
}
public KaitaiStruct M_Parent
{
get { return m_parent; }
}
}
}