Current News
Archived News
Search News
Discussion Forum


Old Forum
Install Programs More Downloads...
Troubleshooting
Source Code
Format Specs.
Misc. Information
Non-SF Stuff
Links




CommitLineData
cfca19c6 1These structs are to demonstrate the layout of a CWAD file. Note that they are not actual working structs.
2
3In C++:
4
5 struct CWAD {
6 char IDTag[4] = "CWAD";
7 CWADFILE Files[];
8 };
9
10 struct CWADFILE {
11 DWORD dwPackedSize;
12 DWORD dwNameLength;
13 DWORD dwFullSize;
14 DWORD dwFlags;
15 char lpFileName[dwNameLength];
16 BYTE lpData[dwPackedSize];
17 };
18
19In VB:
20
21 Type CWAD
22 IDTag As String * 4 = "CWAD"
23 Files() as CWADFILE
24 End Type
25
26 Type CWADFILE
27 dwPackedSize As Long
28 dwNameLength As Long
29 dwFullSize As Long
30 dwFlags As Long
31 lpFileName As String * dwNameLength
32 lpData(dwPackedSize) As Byte
33 End Type
34
35At the beginning, there are 4 bytes, the string "CWAD". After that there is a CWADFILE struct for each file until the end of the CWAD file. After the 16 bytes for the header for each file is the filename, then the actual file data, then the next file header.
36
37If dwFlags is 0, the file is uncompressed.
38If it is 1, the file is compressed.
39
40Filenames are encrypted with a fairly simple encryption method. Here is some code for decrypting them:
41
42In C++:
43
44void DecryptData(BYTE *lpBuffer, DWORD dwBufferLength)
45{
46 if (lpBuffer==0 || dwBufferLength==0) return;
47 lpBuffer += dwBufferLength - 1;
48 BYTE byCWadKey;
49 byCWadKey = (BYTE)(66 - (dwBufferLength << 1));
50 for (DWORD i=0;i<dwBufferLength;i++) {
51 lpBuffer[0] ^= (BYTE)(byCWadKey + (i << 1));
52 lpBuffer--;
53 }
54}
55
56In VB:
57
58Sub DecryptData(ByRef lpBuffer As String)
59 Dim byCWadKey As Byte, i As Long, n As Long
60 n = Len(lpBuffer)
61 byCWadKey = (66 - (n * 2)) Mod 256
62 For i = 0 To Len(lpBuffer) - 1
63 Mid(lpBuffer, n, 1) = Chr$(Asc(Mid$(lpBuffer, n, 1)) Xor ((byCWadKey + (i * 2)) Mod 256))
64 n = n - 1
65 Next i
66End Function
67
c4ef51f5 68The actual file data is compressed with zlib's compress function, so use zlib's decompress function to decompress the file data. You may get zlib at http://zlib.net/
cfca19c6 69