|
10 | 10 | * http://themanaworld.org/
|
11 | 11 | * from the mapreader.cpp file
|
12 | 12 | *
|
| 13 | + * Some modifications were taken from: |
| 14 | + * https://www.codeandweb.com/texturepacker/contentprotection |
| 15 | + * |
13 | 16 | */
|
14 |
| - |
| 17 | + |
15 | 18 | #ifndef __CC_ZIP_UTILS_H
|
16 | 19 | #define __CC_ZIP_UTILS_H
|
17 | 20 |
|
|
21 | 24 | extern "C" {
|
22 | 25 | #endif
|
23 | 26 |
|
24 |
| - /* XXX: pragma pack ??? */ |
25 |
| - /** @struct CCZHeader |
26 |
| - */ |
27 |
| - struct CCZHeader { |
28 |
| - uint8_t sig[4]; // signature. Should be 'CCZ!' 4 bytes |
29 |
| - uint16_t compression_type; // should 0 |
30 |
| - uint16_t version; // should be 2 (although version type==1 is also supported) |
31 |
| - uint32_t reserved; // Reserved for users. |
32 |
| - uint32_t len; // size of the uncompressed file |
33 |
| - }; |
| 27 | +/** |
| 28 | + * Set the TexturePacker encryption key |
| 29 | + * |
| 30 | + * If your key used to encrypt the pvr.ccz file is |
| 31 | + * aaaaaaaabbbbbbbbccccccccdddddddd |
| 32 | + * you have to call this function 4 times: |
| 33 | + * caw_setkey_part(0, 0xaaaaaaaa); |
| 34 | + * caw_setkey_part(1, 0xbbbbbbbb); |
| 35 | + * caw_setkey_part(2, 0xcccccccc); |
| 36 | + * caw_setkey_part(3, 0xdddddddd); |
| 37 | + * |
| 38 | + * Distribute the call accross some files but make sure |
| 39 | + * to call all of the parts *before* loading the first |
| 40 | + * spritesheet. |
| 41 | + * |
| 42 | + * @param index part of the key [0..3] |
| 43 | + * @param value value of the key part |
| 44 | + */ |
| 45 | +void caw_setkey_part(int index, uint32_t value); |
| 46 | + |
| 47 | +/* XXX: pragma pack ??? */ |
| 48 | +/** @struct CCZHeader |
| 49 | + */ |
| 50 | +struct CCZHeader { |
| 51 | + uint8_t sig[4]; // signature. Should be 'CCZ!' 4 bytes |
| 52 | + uint16_t compression_type; // should 0 |
| 53 | + uint16_t version; // should be 2 (although version type==1 is also supported) |
| 54 | + uint32_t reserved; // Reserverd for users. |
| 55 | + uint32_t len; // size of the uncompressed file |
| 56 | +}; |
34 | 57 |
|
35 |
| - enum { |
36 |
| - CCZ_COMPRESSION_ZLIB, // zlib format. |
37 |
| - CCZ_COMPRESSION_BZIP2, // bzip2 format (not supported yet) |
38 |
| - CCZ_COMPRESSION_GZIP, // gzip format (not supported yet) |
39 |
| - CCZ_COMPRESSION_NONE, // plain (not supported yet) |
40 |
| - }; |
| 58 | +enum { |
| 59 | + CCZ_COMPRESSION_ZLIB, // zlib format. |
| 60 | + CCZ_COMPRESSION_BZIP2, // bzip2 format (not supported yet) |
| 61 | + CCZ_COMPRESSION_GZIP, // gzip format (not supported yet) |
| 62 | + CCZ_COMPRESSION_NONE, // plain (not supported yet) |
| 63 | +}; |
41 | 64 |
|
42 | 65 | /** @file
|
43 | 66 | * Zip helper functions
|
44 | 67 | */
|
45 |
| - |
| 68 | + |
46 | 69 | /**
|
47 | 70 | * Inflates either zlib or gzip deflated memory. The inflated memory is
|
48 | 71 | * expected to be freed by the caller.
|
49 | 72 | *
|
50 |
| - * It will allocate 256k for the destination buffer. If it is not enough it will multiply the previous buffer size per 2, until there is enough memory. |
| 73 | + * It will allocate 256k for the destination buffer. If it is not enought it will multiply the previous buffer size per 2, until there is enough memory. |
51 | 74 | * @returns the length of the deflated buffer
|
52 | 75 | *
|
| 76 | + @since v0.8.1 |
53 | 77 | */
|
54 | 78 | int ccInflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out);
|
55 | 79 |
|
56 | 80 | /**
|
57 | 81 | * Inflates either zlib or gzip deflated memory. The inflated memory is
|
58 | 82 | * expected to be freed by the caller.
|
59 | 83 | *
|
60 |
| - * outlengthHint is assumed to be the needed room to allocate the inflated buffer. |
| 84 | + * outLengthHint is assumed to be the needed room to allocate the inflated buffer. |
61 | 85 | *
|
62 | 86 | * @returns the length of the deflated buffer
|
63 | 87 | *
|
| 88 | + @since v1.0.0 |
64 | 89 | */
|
65 |
| -int ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int outlengthHint ); |
| 90 | +int ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int outLengthHint ); |
66 | 91 |
|
67 | 92 |
|
68 | 93 | /** inflates a GZip file into memory
|
69 | 94 | *
|
70 | 95 | * @returns the length of the deflated buffer
|
71 | 96 | *
|
| 97 | + * @since v0.99.5 |
72 | 98 | */
|
73 | 99 | int ccInflateGZipFile(const char *filename, unsigned char **out);
|
74 | 100 |
|
75 | 101 | /** inflates a CCZ file into memory
|
76 | 102 | *
|
77 | 103 | * @returns the length of the deflated buffer
|
78 | 104 | *
|
| 105 | + * @since v0.99.5 |
79 | 106 | */
|
80 | 107 | int ccInflateCCZFile(const char *filename, unsigned char **out);
|
81 | 108 |
|
|
0 commit comments