11462
|
1 |
unit uFLDrawnMap;
|
|
2 |
interface
|
11480
|
3 |
uses SDLh;
|
11462
|
4 |
|
11480
|
5 |
procedure decodeDrawnMap(data: ansistring; dataSize: Longword; var mapData: PByteArray; var size: Longword);
|
11462
|
6 |
|
|
7 |
implementation
|
11480
|
8 |
uses uUtils, zlib;
|
|
9 |
|
|
10 |
procedure decodeDrawnMap(data: ansistring; dataSize: Longword; var mapData: PByteArray; var size: Longword);
|
|
11 |
var i, cl: Longword;
|
|
12 |
ul: uLong;
|
|
13 |
s: shortstring;
|
|
14 |
r: LongInt;
|
|
15 |
compressedBuf, uncompressedData: PByteArray;
|
|
16 |
begin
|
|
17 |
if dataSize = 0 then
|
|
18 |
begin
|
|
19 |
mapData:= nil;
|
|
20 |
size:= 0;
|
|
21 |
exit;
|
|
22 |
end;
|
|
23 |
|
|
24 |
compressedBuf:= GetMem(dataSize * 3 div 4);
|
|
25 |
cl:= 0;
|
|
26 |
i:= 1;
|
11462
|
27 |
|
11480
|
28 |
while i < dataSize do
|
|
29 |
begin
|
|
30 |
if dataSize - i > 240 then
|
|
31 |
s:= copy(data, i, 240)
|
|
32 |
else
|
|
33 |
s:= copy(data, i, dataSize - i + 1);
|
|
34 |
|
|
35 |
s:= DecodeBase64(s);
|
|
36 |
Move(s[1], compressedBuf^[cl], byte(s[0]));
|
|
37 |
inc(i, 240);
|
|
38 |
inc(cl, byte(s[0]));
|
|
39 |
end;
|
|
40 |
|
|
41 |
ul:= SDLNet_Read32(compressedBuf);
|
|
42 |
uncompressedData:= GetMem(ul);
|
|
43 |
r:= uncompress(pBytef(uncompressedData), @ul, @(compressedBuf^[4]), cl - 4);
|
|
44 |
FreeMem(compressedBuf, dataSize * 3 div 4);
|
|
45 |
|
|
46 |
if r = Z_OK then
|
|
47 |
begin
|
|
48 |
mapData:= uncompressedData;
|
|
49 |
size:= ul
|
|
50 |
end else
|
|
51 |
begin
|
|
52 |
FreeMem(uncompressedData, ul);
|
|
53 |
mapData:= nil;
|
|
54 |
size:= 0
|
|
55 |
end;
|
11462
|
56 |
end;
|
|
57 |
|
|
58 |
end.
|