Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function hllib.ReadFromPackage(path, file)
- -- get the package type (gcf, ncf, ...)
- -- atm we don't care about the type
- local type = m.hlGetPackageTypeFromName(path)
- -- tell hllib we're going to use a package
- local id = ffi.new("unsigned int[1]", 0)
- m.hlCreatePackage(type, id)
- m.hlBindPackage(id[0])
- if m.hlPackageOpenFile(path, m.HL_MODE_READ + m.HL_MODE_VOLATILE) == 1 then
- -- get the file we're looking for
- local pItem = m.hlFolderGetItemByPath(m.hlPackageGetRoot(), file, m.HL_FIND_ALL)
- -- create a stream for the file for reading
- local pStream = ffi.new("void *[1]")
- if m.hlPackageCreateStream(pItem, pStream) == 1 and m.hlStreamOpen(pStream[0], m.HL_MODE_READ) == 1 then
- local str = ""
- -- stream will be output to this char
- local pChar = ffi.new("char[1]", 0)
- -- read the stream until hllib says we're done reading
- -- this is the wrong way to write the wav but it's just an example
- while m.hlStreamReadChar(pStream[0], pChar) == 1 do
- local byte = pChar[0] + 128
- -- this is slow!!!!
- str = str .. string.char(byte)
- end
- m.hlStreamClose(pItem)
- m.hlPackageClose()
- return str
- end
- m.hlPackageClose()
- end
- end
- file.Write("test.wav", hllib.ReadFromPackage("I:/steam/steamapps/source sounds.gcf", "hl2/sound/buttons/button8.wav"))
Advertisement
Add Comment
Please, Sign In to add comment