Dimitri_UA

(dff) gtaRwString

Dec 17th, 2014
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.66 KB | None | 0 0
  1. include "$scripts\\dff\\include\\stream.ms"
  2.  
  3. struct gtaRwString
  4. (
  5.     m_string = "",
  6.     m_isUnicode = false,
  7.  
  8.     fn Init string isUnicode =
  9.     (
  10.         m_string = string
  11.         m_isUnicode = isUnicode
  12.     ),
  13.  
  14.     fn StreamRead stream =
  15.     (
  16.         gtaRwStreamReadChunkHeader stream &outType &size &version &build
  17.         while outType != 2 and outType != 19 do --rwID_STRING, rwID_UNICODESTRING
  18.         (
  19.             gtaRwStreamSkip stream size
  20.         gtaRwStreamReadChunkHeader stream &outType &size &version &build
  21.         )
  22.         if size > 0 do
  23.         (
  24.             if outType == 2 then --rwID_STRING
  25.             (
  26.                 m_string = gtaRwStreamReadString stream
  27.                 gtaRwStreamSkip stream (size - m_string.count - 1)
  28.             )
  29.             else --rwID_UNICODESTRING
  30.             (
  31.                 m_isUnicode = true
  32.                 for i = 1 to (size / 2) do
  33.                 (
  34.                     character = gtaRwStreamReadInt16 stream
  35.                     if character != 0 then
  36.                     (
  37.                         m_string += (bit.intAsChar character)
  38.                     )
  39.                     else
  40.                     (
  41.                         break
  42.                     )
  43.                 )
  44.                 gtaRwStreamSkip stream (size - (m_string.count * 2) - 2)
  45.             )
  46.         )
  47.     ),
  48.  
  49.     fn StreamWrite stream =
  50.     (
  51.         if m_isUnicode == true then
  52.         (
  53.             size = bit.and (m_string.count * 2 + 4) 0x7FFFFFFC
  54.             gtaRwStreamWriteVersionedChunkHeader stream 19 size --rwID_UNICODESTRING
  55.             for i = 1 to m_string.count do
  56.             (
  57.                 gtaRwStreamWriteInt16 stream (bit.charAsInt m_string[i])
  58.             )
  59.             for i = 1 to (size - m_string.count * 2) do
  60.             (
  61.                 gtaRwStreamWriteInt8 stream 0
  62.             )
  63.         )
  64.         else
  65.         (
  66.             size = bit.and (m_string.count + 4) 0x7FFFFFFC
  67.             gtaRwStreamWriteVersionedChunkHeader stream 2 size --rwID_STRING
  68.             gtaRwStreamWriteString stream m_string
  69.             size = size - m_string.count - 1
  70.             if size > 1 do
  71.             (
  72.                 for i = 1 to size do
  73.                 (
  74.                     gtaRwStreamWriteInt8 stream 0
  75.                 )
  76.             )
  77.         )
  78.     ),
  79.  
  80.     fn GetStreamSize =
  81.     (
  82.         if m_string.count == 0 then
  83.             return 16
  84.         else
  85.         (
  86.             if m_isUnicode == true then
  87.                 return 12 + bit.and (m_string.count * 2 + 4) 0x7FFFFFFC
  88.             else
  89.                 return 12 + bit.and (m_string.count + 4) 0x7FFFFFFC
  90.         )
  91.     )
  92. )
Add Comment
Please, Sign In to add comment