Mercurial > wow > cyborg-mmo7
comparison support/casc/blte.lua @ 65:8b8b0bade520
Fixed support for mounts using the new MountJournal and mount IDs (no conversion of old profiles at the moment).
author | Jerome Vuarand <jerome.vuarand@gmail.com> |
---|---|
date | Thu, 23 Oct 2014 13:44:59 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
64:49ae7191821f | 65:8b8b0bade520 |
---|---|
1 local M, plat, bin = {}, require("casc.platform"), require("casc.bin") | |
2 local open, tconcat, assert, error = io.open, table.concat, assert, error | |
3 local uint32_le, uint32_be = bin.uint32_le, bin.uint32_be | |
4 | |
5 local string_cursor do | |
6 local function read(self, n) | |
7 local p = self.pos | |
8 self.pos = p + n | |
9 return self.str:sub(p, p+n-1) | |
10 end | |
11 function string_cursor(s) | |
12 return {str=s, read=read, pos=1} | |
13 end | |
14 end | |
15 | |
16 local function decodeChunk(chunk) | |
17 local format = chunk:sub(1,1) | |
18 if format == 'N' then | |
19 return chunk:sub(2) | |
20 elseif format == 'Z' then | |
21 return plat.decompress(chunk:sub(2)) | |
22 else | |
23 error('Unknown chunk format: ' .. tostring(format)) | |
24 end | |
25 end | |
26 local function parseBLTE(h, dataSize) | |
27 local header = h:read(8) | |
28 assert(header:sub(1,4) == 'BLTE', 'BLTE file magic signature') | |
29 local ofs = uint32_be(header, 4) | |
30 | |
31 local chunks, ret = ofs > 0 and {} | |
32 if ofs > 0 then | |
33 local n = uint32_be(h:read(4)) % 2^16 | |
34 local buf, p = h:read(n*24), 0 | |
35 for i=1, n do | |
36 chunks[i], p = uint32_be(buf, p), p + 24 | |
37 end | |
38 for i=1, #chunks do | |
39 chunks[i] = decodeChunk(h:read(chunks[i])) | |
40 end | |
41 ret = tconcat(chunks, "") | |
42 else | |
43 ret = decodeChunk(h:read(dataSize)) | |
44 end | |
45 return ret | |
46 end | |
47 | |
48 function M.readArchive(path, offset) | |
49 assert(type(path) == "string" and type(offset) == "number", 'Syntax: "content" = casc.blte.readArchive("path", offset)') | |
50 | |
51 local h = open(path, "rb") | |
52 h:seek("set", offset) | |
53 local blockHead = h:read(30) | |
54 local ret = parseBLTE(h, uint32_le(blockHead, 16)-30) | |
55 h:close() | |
56 | |
57 return ret | |
58 end | |
59 function M.readData(str) | |
60 assert(type(str) == "string", 'Syntax: "content" = casc.blte.readContent("str")') | |
61 return parseBLTE(string_cursor(str), #str) | |
62 end | |
63 | |
64 return M |