Advertisement
Guest User

weap_data.script

a guest
Mar 11th, 2013
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --------------------------------------------------------------
  2. -- Все функции взяты из АМК в чистом виде --
  3. --------------------------------------------------------------
  4.  
  5. function get_weapon_data(sobj)
  6.   local stpk=net_packet()
  7. --  local uppk=net_packet()
  8.   sobj:STATE_Write(stpk)
  9. --  sobj:UPDATE_Write(uppk)
  10.   local size=stpk:w_tell()
  11. --  local size1=uppk:w_tell()
  12.   -- amk.mylog("rsp "..size.." "..size1)
  13.   stpk:r_seek(0)
  14.  -- uppk:r_seek(0)
  15.   local t={}
  16.   parse_object_packet(t,stpk,size)--,uppk
  17.   parse_visual_packet(t,stpk,size)--,uppk
  18.   parse_item_packet(t,stpk,size)--,uppk
  19.   parse_item_weapon_packet(t,stpk,size)--,uppk
  20.   -- amk.mylog("rsp "..size.." "..size1.." "..stpk:r_tell())
  21.   return t
  22. end
  23.  
  24. function set_weapon_data(t,sobj)
  25.   local stpk=net_packet()
  26.   --local uppk=net_packet()
  27.    
  28.   fill_object_packet(t,stpk)--,uppk
  29.   fill_visual_packet(t,stpk)--,uppk
  30.   fill_item_packet(t,stpk)--,uppk
  31.   fill_item_weapon_packet(t,stpk)--,uppk
  32.    
  33.   local size=stpk:w_tell()
  34.  -- local size1=uppk:w_tell()
  35.   -- amk.mylog("wsp "..size.." "..size1)
  36.   stpk:r_seek(0)
  37.  -- uppk:r_seek(0)
  38.   sobj:STATE_Read(stpk,size)
  39.  -- sobj:UPDATE_Read(uppk)
  40.  
  41. end
  42.  
  43. function parse_item_weapon_packet(ret,stpk)--,updpk
  44.     ret.ammo_current = stpk:r_u16()
  45.     ret.ammo_elapsed = stpk:r_u16()
  46.     ret.weapon_state = stpk:r_u8()
  47.     ret.addon_flags = stpk:r_u8()
  48.     ret.ammo_type = stpk:r_u8()
  49.    
  50.     --[[ret.updgrenade_mode = updpk:r_u8()
  51.     ret.updcurrent_fire_mode = updpk:r_u8()
  52.     ret.updcondition = updpk:r_u8()
  53.     ret.updweapon_flags = updpk:r_u8()
  54.     ret.updammo_elapsed = updpk:r_u16()
  55.     ret.updaddon_flags = updpk:r_u8()
  56.     ret.updammo_type = updpk:r_u8()
  57.     ret.updweapon_state = updpk:r_u8()
  58.     ret.updweapon_zoom = updpk:r_u8()]]
  59.   return ret
  60. end
  61.  
  62. function parse_object_packet(ret,stpk)--,updpk
  63.   ret.gvid=stpk:r_u16()
  64.   ret.obf32u1=stpk:r_float()
  65.   ret.obs32u2=stpk:r_s32()
  66.   ret.lvid=stpk:r_s32()
  67.   ret.oflags=stpk:r_s32()
  68.   ret.custom=stpk:r_stringZ()
  69.   ret.sid=stpk:r_s32()
  70.   ret.obs32u3=stpk:r_s32()
  71.   return ret
  72. end
  73.  
  74. function parse_visual_packet(ret,stpk)--,updpk
  75.   ret.visual=stpk:r_stringZ()
  76.   ret.vsu8u1=stpk:r_u8()
  77.   return ret
  78. end
  79.  
  80. function parse_item_packet(ret,stpk)--,updpk
  81.     ret.condition=stpk:r_float()
  82.    
  83.     --[[ret.updnum_items=updpk:r_u8()
  84.   ret.updpos={} -- или поставить вектор? ладно потом
  85.   ret.updpos.x=updpk:r_float()
  86.   ret.updpos.y=updpk:r_float()
  87.   ret.updpos.z=updpk:r_float()
  88.     ret.updcse_alife_item__unk1_q8v4=readvu8uN(updpk,4)
  89.     ret.updcse_alife_item__unk2_q8v3=readvu8uN(updpk,3)
  90.     ret.updcse_alife_item__unk3_q8v3=readvu8uN(updpk,3)]]
  91.   return ret
  92. end
  93.  
  94. function readvu8uN(packet,n)
  95.   local v={}
  96.   for i=1,n,1 do
  97.     table.insert(v,packet:r_u8())
  98.   end
  99.   return v
  100. end
  101.  
  102. function fill_item_weapon_packet(ret,stpk)--,updpk
  103.     stpk:w_u16(ret.ammo_current)
  104.     stpk:w_u16(ret.ammo_elapsed)
  105.     stpk:w_u8(ret.weapon_state)
  106.     stpk:w_u8(ret.addon_flags)
  107.     stpk:w_u8(ret.ammo_type)
  108.    
  109.     --[[updpk:w_u8(ret.updgrenade_mode)
  110.     updpk:w_u8(ret.updcurrent_fire_mode)
  111.     updpk:w_u8(ret.updcondition)
  112.     updpk:w_u8(ret.updweapon_flags)
  113.     updpk:w_u16(ret.updammo_elapsed)
  114.     updpk:w_u8(ret.updaddon_flags)
  115.     updpk:w_u8(ret.updammo_type)
  116.     updpk:w_u8(ret.updweapon_state)
  117.     updpk:w_u8(ret.updweapon_zoom)]]
  118.   return ret
  119. end
  120.  
  121. function fill_item_packet(ret,stpk)--,updpk
  122.     stpk:w_float(ret.condition)
  123.     --[[updpk:w_u8(ret.updnum_items)
  124.   updpk:w_float(ret.updpos.x)
  125.   updpk:w_float(ret.updpos.y)
  126.   updpk:w_float(ret.updpos.z)
  127. --  readvu8uN(updpk,ret.updcse_alife_item__unk1_q8v4)       --  было в оригинале
  128. --  readvu8uN(updpk,ret.updcse_alife_item__unk2_q8v3)       -- единственное, что я поправил
  129. --  readvu8uN(updpk,ret.updcse_alife_item__unk3_q8v3)       -- иначе вылетало
  130.     writevu8uN(updpk,ret.updcse_alife_item__unk1_q8v4)
  131.     writevu8uN(updpk,ret.updcse_alife_item__unk2_q8v3)
  132.     writevu8uN(updpk,ret.updcse_alife_item__unk3_q8v3)]]
  133.   return ret
  134. end
  135.  
  136. function fill_object_packet(ret,stpk)--,updpk
  137.   stpk:w_u16(ret.gvid)
  138.   stpk:w_float(ret.obf32u1)
  139.   stpk:w_s32(ret.obs32u2)
  140.   stpk:w_s32(ret.lvid)
  141.   stpk:w_s32(ret.oflags)
  142.   stpk:w_stringZ(ret.custom)
  143.   stpk:w_s32(ret.sid)
  144.   stpk:w_s32(ret.obs32u3)
  145.   return ret
  146. end
  147.  
  148. function fill_visual_packet(ret,stpk)--,updpk
  149.   stpk:w_stringZ(ret.visual)
  150.   stpk:w_u8(ret.vsu8u1)
  151.   return ret
  152. end
  153.  
  154. function writevu8uN(pk,v)
  155.   local len=table.getn(v)
  156.   --pk:w_u8(len)
  157.   for i=1,len,1 do
  158.     pk:w_u8(v[i])
  159.   end
  160. end
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement