BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
BrawlLib.Wii.Compressor Class Reference

Static Public Member Functions

static bool Supports (CompressionType type)
 
static CompressionType GetAlgorithm (DataSource source)
 
static CompressionType GetAlgorithm (VoidPtr addr, int length)
 
static uint GetExpandedLength (VoidPtr addr, int length)
 
static FileMap TryExpand (ref DataSource source, bool doTest=true)
 
static void Expand (CompressionHeader *header, VoidPtr dstAddr, int dstLen)
 
static void Expand (YAZ0 *header, VoidPtr dstAddr, int dstLen)
 
static void Expand (YAY0 *header, VoidPtr dstAddr, int dstLen)
 
static void Compact (CompressionType type, VoidPtr srcAddr, int srcLen, Stream outStream, ResourceNode r)
 

Member Function Documentation

◆ Compact()

static void BrawlLib.Wii.Compressor.Compact ( CompressionType  type,
VoidPtr  srcAddr,
int  srcLen,
Stream  outStream,
ResourceNode  r 
)
inlinestatic
235 {
236 switch (type)
237 {
238 case CompressionType.LZ77:
239 {
240 LZ77.Compact(srcAddr, srcLen, outStream, r, false);
241 break;
242 }
243
244 case CompressionType.ExtendedLZ77:
245 {
246 LZ77.Compact(srcAddr, srcLen, outStream, r, true);
247 break;
248 }
249
250 case CompressionType.RunLength:
251 {
252 RunLength.Compact(srcAddr, srcLen, outStream, r);
253 break;
254 }
255
256 case CompressionType.RunLengthYAZ0:
257 {
258 RunLength.CompactYAZ0(srcAddr, srcLen, outStream, r);
259 break;
260 }
261
262 case CompressionType.RunLengthYAY0:
263 {
264 RunLength.CompactYAY0(srcAddr, srcLen, outStream, r);
265 break;
266 }
267 }
268 }
Definition: LZ77.cs:13
static int Compact(VoidPtr srcAddr, int srcLen, Stream outStream, ResourceNode r, bool extendedFormat)
Definition: LZ77.cs:250
Definition: RunLength.cs:14
static int CompactYAY0(VoidPtr srcAddr, int srcLen, Stream outStream, ResourceNode r)
Definition: RunLength.cs:312
static int CompactYAZ0(VoidPtr srcAddr, int srcLen, Stream outStream, ResourceNode r)
Definition: RunLength.cs:303
static int Compact(VoidPtr srcAddr, int srcLen, Stream outStream, ResourceNode r)
Definition: RunLength.cs:321
CompressionType
Definition: CompressionHeader.cs:9

◆ Expand() [1/3]

static void BrawlLib.Wii.Compressor.Expand ( CompressionHeader header,
VoidPtr  dstAddr,
int  dstLen 
)
inlinestatic
200 {
201 switch (header->Algorithm)
202 {
203 case CompressionType.LZ77:
204 case CompressionType.ExtendedLZ77:
205 {
206 LZ77.Expand(header, dstAddr, dstLen);
207 break;
208 }
209
210 case CompressionType.RunLength:
211 {
212 RunLength.Expand(header, dstAddr, dstLen);
213 break;
214 }
215
216 //case CompressionType.Huffman: { Huffman.Expand(header, dstAddr, dstLen); break; }
217 //case CompressionType.Differential: { Differential.Expand(header, dstAddr, dstLen); break; }
218 default:
219 throw new InvalidCompressionException("Unknown compression type.");
220 }
221 }
static void Expand(CompressionHeader *header, VoidPtr dstAddress, int dstLen)
Definition: LZ77.cs:263
static void Expand(CompressionHeader *header, VoidPtr dstAddress, int dstLen)
Definition: RunLength.cs:345
CompressionType Algorithm
Definition: CompressionHeader.cs:30

◆ Expand() [2/3]

static void BrawlLib.Wii.Compressor.Expand ( YAY0 header,
VoidPtr  dstAddr,
int  dstLen 
)
inlinestatic
229 {
230 RunLength.ExpandYAY0(header, dstAddr, dstLen);
231 }
static void ExpandYAY0(YAY0 *header, VoidPtr dstAddress, int dstLen)
Definition: RunLength.cs:335

◆ Expand() [3/3]

static void BrawlLib.Wii.Compressor.Expand ( YAZ0 header,
VoidPtr  dstAddr,
int  dstLen 
)
inlinestatic
224 {
225 RunLength.ExpandYAZ0(header, dstAddr, dstLen);
226 }
static void ExpandYAZ0(YAZ0 *header, VoidPtr dstAddress, int dstLen)
Definition: RunLength.cs:330

◆ GetAlgorithm() [1/2]

static CompressionType BrawlLib.Wii.Compressor.GetAlgorithm ( DataSource  source)
inlinestatic
58 {
59 return GetAlgorithm(source.Address, source.Length);
60 }
static CompressionType GetAlgorithm(DataSource source)
Definition: Compressor.cs:57
int Length
Definition: ResourceNode.cs:32
VoidPtr Address
Definition: ResourceNode.cs:31

◆ GetAlgorithm() [2/2]

static CompressionType BrawlLib.Wii.Compressor.GetAlgorithm ( VoidPtr  addr,
int  length 
)
inlinestatic
63 {
64 if (length < 4)
65 {
66 return CompressionType.None;
67 }
68 BinTag compTag = *(BinTag*) addr;
69 if (compTag == YAZ0.Tag)
70 {
71 return CompressionType.RunLengthYAZ0;
72 }
73
74 if (compTag == YAY0.Tag)
75 {
76 return CompressionType.RunLengthYAY0;
77 }
78
80
81 if (cmpr->ExpandedSize < length)
82 {
83 return CompressionType.None;
84 }
85
86 if (!cmpr->HasLegitCompression())
87 {
88 return CompressionType.None;
89 }
90
91 //Check to make sure we're not reading a tag
92 if (IsTag((byte*) addr))
93 {
94 return CompressionType.None;
95 }
96
97 return cmpr->Algorithm;
98 }
Definition: Common.cs:14
Definition: CompressionHeader.cs:24
uint ExpandedSize
Definition: CompressionHeader.cs:72
bool HasLegitCompression()
Definition: CompressionHeader.cs:88
Definition: CompressionHeader.cs:133
const string Tag
Definition: CompressionHeader.cs:135
Definition: CompressionHeader.cs:109
const string Tag
Definition: CompressionHeader.cs:111

◆ GetExpandedLength()

static uint BrawlLib.Wii.Compressor.GetExpandedLength ( VoidPtr  addr,
int  length 
)
inlinestatic
101 {
102 BinTag compTag = *(BinTag*) addr;
103 if (compTag == YAZ0.Tag)
104 {
105 return ((YAZ0*) addr)->_unCompDataLen;
106 }
107
108 if (compTag == YAY0.Tag)
109 {
110 return ((YAY0*) addr)->_unCompDataLen;
111 }
112
113 return ((CompressionHeader*) addr)->ExpandedSize;
114 }

◆ Supports()

static bool BrawlLib.Wii.Compressor.Supports ( CompressionType  type)
inlinestatic
51 {
52 return type != CompressionType.None && _supportedCompressionTypes.Contains(type);
53 }

◆ TryExpand()

static FileMap BrawlLib.Wii.Compressor.TryExpand ( ref DataSource  source,
bool  doTest = true 
)
inlinestatic
156 {
157 FileMap decompressedMap = null;
158 CompressionType algorithm = GetAlgorithm(source);
159 if (Supports(source.Compression = algorithm))
160 {
161 try
162 {
163 if (doTest && !Test(algorithm, source.Address))
164 {
165 return null;
166 }
167
168 uint len = 0;
169 if (algorithm == CompressionType.RunLengthYAZ0)
170 {
171 len = *(buint*) (source.Address + 4);
172 decompressedMap = FileMap.FromTempFile((int) len);
173 Expand((YAZ0*) source.Address, decompressedMap.Address, decompressedMap.Length);
174 }
175 else if (algorithm == CompressionType.RunLengthYAY0)
176 {
177 len = *(buint*) (source.Address + 4);
178 decompressedMap = FileMap.FromTempFile((int) len);
179 Expand((YAY0*) source.Address, decompressedMap.Address, decompressedMap.Length);
180 }
181 else
182 {
183 CompressionHeader* hdr = (CompressionHeader*) source.Address;
184 len = hdr->ExpandedSize;
185
186 decompressedMap = FileMap.FromTempFile((int) len);
187 Expand(hdr, decompressedMap.Address, decompressedMap.Length);
188 }
189 }
190 catch (InvalidCompressionException e)
191 {
192 MessageBox.Show(e.ToString());
193 }
194 }
195
196 return decompressedMap;
197 }
Definition: FileMap.cs:10
int Length
Definition: FileMap.cs:19
static FileMap FromTempFile(int length)
Definition: FileMap.cs:96
VoidPtr Address
Definition: FileMap.cs:16
static void Expand(CompressionHeader *header, VoidPtr dstAddr, int dstLen)
Definition: Compressor.cs:199
static bool Supports(CompressionType type)
Definition: Compressor.cs:50
Definition: BigEndianTypes.cs:59

The documentation for this class was generated from the following file: