-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlua_prototype_reader.lua
More file actions
67 lines (46 loc) · 1.45 KB
/
Copy pathlua_prototype_reader.lua
File metadata and controls
67 lines (46 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
LuaPrototypeReader = {}
LuaPrototypeReader.__index = LuaPrototypeReader
function LuaPrototypeReader:new(binary)
local self = setmetatable({}, LuaPrototypeReader)
self.m_binary = binary
self.m_position = 27
return self
end
function LuaPrototypeReader:addPosition(size)
self.m_position = self.m_position + size
end
function LuaPrototypeReader:readInt8()
local int8 = string.unpack("i1", self.m_binary, self.m_position)
self:addPosition(1)
return int8
end
function LuaPrototypeReader:readUInt8()
return self:readInt8() & 0xFF
end
function LuaPrototypeReader:readInt32()
local int32 = string.unpack("i4", self.m_binary, self.m_position)
self.m_position = self.m_position + 4
return int32
end
function LuaPrototypeReader:readUInt32()
return self:readInt32() & 0xFFFFFFFF
end
function LuaPrototypeReader:readNumber()
local _number = string.unpack("n", self.m_binary, self.m_position)
self.m_position = self.m_position + 8
return _number
end
function LuaPrototypeReader:readStr()
local strLen = self:readInt32()
local str = self.m_binary:sub(self.m_position, self.m_position + strLen - 1)
self.m_position = self.m_position + strLen
return str
end
function LuaPrototypeReader:readIntArray()
local size = self:readInt32()
local intArray = {}
for i = 1, size do
intArray[i] = self:readUInt32()
end
return intArray
end