Created
April 10, 2015 02:21
-
-
Save SpiralP/b9e59c17bbb7af87d28d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require'vstruct' | |
local metatable = { | |
__index = { | |
read = function(self,n) | |
if not n then | |
n = 1 | |
end | |
self.pos = self.pos+n | |
if self.pos-1>#self.str then return false end | |
return self.str:sub(self.pos-n,self.pos-1) | |
end, | |
seek = function(self,n) | |
self.pos = n | |
end, | |
int4 = function(self) | |
return vstruct.readvals('u4',self:read(4)) | |
end, | |
int2 = function(self) | |
return vstruct.readvals('u2',self:read(2)) | |
end, | |
sz = function(s) | |
local out = {} | |
while true do | |
local cur = s:read(1) | |
if not cur or cur =='\0' then break end | |
out[#out+1] = vstruct.readvals('s1',cur) | |
end | |
if #out==0 then return false end | |
return table.concat(out,'') | |
end, | |
}, | |
__tostring = function(self) | |
return self.str | |
end, | |
__add = function(self,n) | |
return self:read(n) | |
end, | |
__sub = function(self,n) | |
return self:read(-n) | |
end, | |
} | |
local function createString(str) | |
local s = { | |
str=str, | |
pos = 1, | |
} | |
debug.setmetatable(s,metatable) | |
return s | |
end | |
local file = createString(file.Read('garrysmod_dir.vpk','GAME')) | |
local signature = GLib.String.DumpHex(file:read(4)) | |
local version = file:int4() | |
local dirlength = file:int4() | |
local unknown1 = file:int4() | |
local unknown2 = file:int4() | |
local unknown3 = file:int4() | |
local unknown4 = file:int4() | |
print(signature) | |
print(version) | |
print(dirlength) | |
while true do | |
local ext = file:sz() | |
if not ext then break end | |
while true do | |
local folder = file:sz() | |
if not folder then break end | |
while true do | |
local filename = file:sz() | |
if not filename then break end | |
local path = string.format('%s/%s.%s',folder,filename,ext) | |
print(path) | |
local CRC = file:int4() | |
local preload_bytes = file:int2() | |
local archive_index = file:int2() | |
if archive_index == '\x7fff' then | |
ErrorNoHalt('EMBED') | |
end | |
local offset = file:int4() | |
local length = file:int4() | |
file:int2() | |
if preload_bytes and preload_bytes!=0 then | |
file:read(preload_bytes) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment