|
| 1 | +// mcos is a game server, written from scratch, for an old game |
| 2 | +// Copyright (C) <2017> <Drazi Crendraven> |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Affero General Public License as published |
| 6 | +// by the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Affero General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Affero General Public License |
| 15 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +type read_buf_func = (buf: Buffer, size: number, param: any) => number // uint |
| 18 | + |
| 19 | +type write_buf_func = (buf: Buffer, size: number, param: any) => void |
| 20 | + |
| 21 | +enum LUTSizesEnum { |
| 22 | + DIST_SIZES=0x40, |
| 23 | + CH_BITS_ASC_SIZE=0x100, |
| 24 | + LENS_SIZES=0x10, |
| 25 | +}; |
| 26 | + |
| 27 | +enum CommonSizes { |
| 28 | + OUT_BUFF_SIZE = 0x802, |
| 29 | + BUFF_SIZE=0x2204, |
| 30 | +}; |
| 31 | + |
| 32 | +enum ExplodeSizesEnum { |
| 33 | + IN_BUFF_SIZE=0x800, |
| 34 | + CODES_SIZE=0x100, |
| 35 | + OFFSS_SIZE=0x100, |
| 36 | + OFFSS_SIZE1=0x80, |
| 37 | +}; |
| 38 | + |
| 39 | +enum { |
| 40 | + EXP_BUFFER_SIZE = sizeof(TDcmpStruct), // Size of decompression structure |
| 41 | + // Defined as 12596 in pkware headers |
| 42 | +}; |
| 43 | + |
| 44 | +class TDcmpStruct { |
| 45 | + private offs0000 // ulong 0000 |
| 46 | + private ctype // ulong 0004: Compression type (CMP_BINARY or CMP_ASCII) |
| 47 | + private outputPos // ulong 0008: Position in output buffer |
| 48 | + private dsize_bits // ulong 000C: Dict size (4, 5, 6 for 0x400, 0x800, 0x1000) |
| 49 | + private dsize_mask // ulong 0010: Dict size bitmask (0x0F, 0x1F, 0x3F for 0x400, 0x800, 0x1000) |
| 50 | + private bit_buff // ulong 0014: 16-bit buffer for processing input data |
| 51 | + private extra_bits // ulong 0018: Number of extra (above 8) bits in bit buffer |
| 52 | + private extra_bits // uint 001C: Position in in_buff |
| 53 | + private in_bytes // ulong 0020: Number of bytes in input buffer |
| 54 | + private param // void* 0024: Custom parameter |
| 55 | + private read_buf: read_buf_func // read_buf_func // Pointer to function that reads data from the input stream |
| 56 | + private write_buf: write_buf_func // write_buf_func // Pointer to function that writes data to the output stream |
| 57 | + private out_buff // uchar[BUFF_SIZE] 0030: Output circle buffer. |
| 58 | + // 0x0000 - 0x0FFF: Previous uncompressed data, kept for repetitions |
| 59 | + // 0x1000 - 0x1FFF: Currently decompressed data |
| 60 | + // 0x2000 - 0x2203: Reserve space for the longest possible repetition |
| 61 | + private in_buff // uchar[IN_BUFF_SIZE] 2234: Buffer for data to be decompressed |
| 62 | + private DistPosCodes // uchar[CODES_SIZE] 2A34: Table of distance position codes |
| 63 | + private LengthCodes // uchar[CODES_SIZE] 2B34: Table of length codes |
| 64 | + private offs2C34 // uchar[OFFSS_SIZE] 2C34: Buffer for |
| 65 | + private offs2D34 // uchar[OFFSS_SIZE] 2D34: Buffer for |
| 66 | + private offs2E34 // uchar[OFFSS_SIZE1] 2E34: Buffer for |
| 67 | + private offs2EB4 // uchar[OFFSS_SIZE] 2EB4: Buffer fo |
| 68 | + private ChBitsAsc // uchar[CH_BITS_ASC_SIZE] 2FB4: Buffer for |
| 69 | + private DistBits // uchar[DIST_SIZES] 30B4: Numbers of bytes to skip copied block length |
| 70 | + private LenBits // uchar[LENS_SIZES] 30F4: Numbers of bits for skip copied block length |
| 71 | + private ExLenBits // uchar[LENS_SIZES] 3104: Number of valid bits for copied block |
| 72 | + private LenBase // ushort[LENS_SIZES] 3114: Buffer fo |
| 73 | + |
| 74 | +} |
| 75 | + |
| 76 | +export function explode(read_buf: read_buf_func, write_buf: write_buf_func, work_buf: Buffer, param: any) {} |
| 77 | + |
| 78 | +export function implode() {} |
0 commit comments