CapsAdmin

Untitled

Jun 26th, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. function hllib.ReadFromPackage(path, file)
  2.     -- get the package type (gcf, ncf, ...)
  3.     -- atm we don't care about the type
  4.     local type = m.hlGetPackageTypeFromName(path)
  5.    
  6.     -- tell hllib we're going to use a package
  7.     local id = ffi.new("unsigned int[1]", 0)
  8.     m.hlCreatePackage(type, id)
  9.     m.hlBindPackage(id[0])   
  10.    
  11.     if m.hlPackageOpenFile(path, m.HL_MODE_READ + m.HL_MODE_VOLATILE) == 1 then
  12.        
  13.         -- get the file we're looking for
  14.         local pItem = m.hlFolderGetItemByPath(m.hlPackageGetRoot(), file, m.HL_FIND_ALL)
  15.        
  16.         -- create a stream for the file for reading
  17.         local pStream = ffi.new("void *[1]")
  18.         if m.hlPackageCreateStream(pItem, pStream) == 1 and m.hlStreamOpen(pStream[0], m.HL_MODE_READ) == 1 then
  19.            
  20.             local str = ""
  21.            
  22.             -- stream will be output to this char
  23.             local pChar = ffi.new("char[1]", 0)
  24.            
  25.             -- read the stream until hllib says we're done reading
  26.             -- this is the wrong way to write the wav but it's just an example
  27.             while m.hlStreamReadChar(pStream[0], pChar) == 1 do
  28.                 local byte = pChar[0] + 128
  29.                 -- this is slow!!!!
  30.                 str = str .. string.char(byte)
  31.             end
  32.  
  33.             m.hlStreamClose(pItem)
  34.             m.hlPackageClose()
  35.            
  36.             return str
  37.         end
  38.        
  39.         m.hlPackageClose()
  40.     end
  41. end
  42.  
  43. 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