Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.26 KB | None | 0 0
  1. --Copyright (c) 2013, Byrthnoth
  2. --All rights reserved.
  3.  
  4. --Redistribution and use in source and binary forms, with or without
  5. --modification, are permitted provided that the following conditions are met:
  6.  
  7. -- * Redistributions of source code must retain the above copyright
  8. -- notice, this list of conditions and the following disclaimer.
  9. -- * Redistributions in binary form must reproduce the above copyright
  10. -- notice, this list of conditions and the following disclaimer in the
  11. -- documentation and/or other materials provided with the distribution.
  12. -- * Neither the name of <addon name> nor the
  13. -- names of its contributors may be used to endorse or promote products
  14. -- derived from this software without specific prior written permission.
  15.  
  16. --THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17. --ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. --WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. --DISCLAIMED. IN NO EVENT SHALL <your name> BE LIABLE FOR ANY
  20. --DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. --(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. --LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. --ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. --(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. --SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26.  
  27. _addon.name = 'GearSwap'
  28. _addon.version = '0.901'
  29. _addon.author = 'Byrth'
  30. _addon.commands = {'gs','gearswap'}
  31.  
  32. if windower.file_exists(windower.addon_path..'data/bootstrap.lua') then
  33. debugging = {windower_debug = true,command_registry = false,general=false,logging=false}
  34. else
  35. debugging = {}
  36. end
  37.  
  38. __raw = {lower = string.lower, upper = string.upper, debug=windower.debug,text={create=windower.text.create,
  39. delete=windower.text.delete,registry = {}},prim={create=windower.prim.create,delete=windower.prim.delete,registry={}}}
  40.  
  41.  
  42. language = 'english'
  43. file = require 'files'
  44. require 'strings'
  45. require 'tables'
  46. require 'logger'
  47. -- Restore the normal error function (logger changes it)
  48. error = _raw.error
  49.  
  50. require 'lists'
  51. require 'sets'
  52.  
  53.  
  54. windower.text.create = function (str)
  55. if __raw.text.registry[str] then
  56. msg.addon_msg(123,'Text object cannot be created because it already exists.')
  57. else
  58. __raw.text.registry[str] = true
  59. __raw.text.create(str)
  60. end
  61. end
  62.  
  63. windower.text.delete = function (str)
  64. if __raw.text.registry[str] then
  65. local deleted = false
  66. if windower.text.saved_texts then
  67. for i,v in pairs(windower.text.saved_texts) do
  68. if v._name == str then
  69. __raw.text.registry[str] = nil
  70. windower.text.saved_texts[i]:destroy()
  71. deleted = true
  72. break
  73. end
  74. end
  75. end
  76. if not deleted then
  77. __raw.text.registry[str] = nil
  78. __raw.text.delete(str)
  79. end
  80. else
  81. __raw.text.delete(str)
  82. end
  83. end
  84.  
  85. windower.prim.create = function (str)
  86. if __raw.prim.registry[str] then
  87. msg.addon_msg(123,'Primitive cannot be created because it already exists.')
  88. else
  89. __raw.prim.registry[str] = true
  90. __raw.prim.create(str)
  91. end
  92. end
  93.  
  94. windower.prim.delete = function (str)
  95. if __raw.prim.registry[str] then
  96. __raw.prim.registry[str] = nil
  97. __raw.prim.delete(str)
  98. else
  99. __raw.prim.delete(str)
  100. end
  101. end
  102.  
  103. texts = require 'texts'
  104. require 'pack'
  105. bit = require 'bit'
  106. socket = require 'socket'
  107. mime = require 'mime'
  108. res = require 'resources'
  109. extdata = require 'extdata'
  110. require 'helper_functions'
  111. require 'actions'
  112.  
  113. -- Resources Checks
  114. if res.items and res.bags and res.slots and res.statuses and res.jobs and res.elements and res.skills and res.buffs and res.spells and res.job_abilities and res.weapon_skills and res.monster_abilities and res.action_messages and res.skills and res.monstrosity and res.weather and res.moon_phases and res.races then
  115. else
  116. error('Missing resources!')
  117. end
  118.  
  119. require 'statics'
  120. require 'equip_processing'
  121. require 'targets'
  122. require 'user_functions'
  123. require 'refresh'
  124. require 'export'
  125. require 'validate'
  126. require 'flow'
  127. require 'triggers'
  128.  
  129. windower.register_event('load',function()
  130. windower.debug('load')
  131. refresh_globals()
  132.  
  133. if world.logged_in then
  134. refresh_user_env()
  135. if debugging.general then windower.send_command('@unload spellcast;') end
  136. end
  137. end)
  138.  
  139. windower.register_event('unload',function ()
  140. windower.debug('unload')
  141. user_pcall('file_unload')
  142. if logging then logfile:close() end
  143. end)
  144.  
  145. windower.register_event('addon command',function (...)
  146. windower.debug('addon command')
  147. logit('\n\n'..tostring(os.clock)..table.concat({...},' '))
  148. local splitup = {...}
  149. if not splitup[1] then return end -- handles //gs
  150.  
  151. for i,v in pairs(splitup) do splitup[i] = windower.from_shift_jis(windower.convert_auto_trans(v)) end
  152.  
  153. local cmd = table.remove(splitup,1):lower()
  154.  
  155. if cmd == 'c' then
  156. if gearswap_disabled then return end
  157. if splitup[1] then
  158. refresh_globals()
  159. equip_sets('self_command',nil,_raw.table.concat(splitup,' '))
  160. else
  161. msg.addon_msg(123,'No self command passed.')
  162. end
  163. elseif cmd == 'equip' then
  164. if gearswap_disabled then return end
  165. local key_list = parse_set_to_keys(splitup)
  166. local set = get_set_from_keys(key_list)
  167. if set then
  168. refresh_globals()
  169. equip_sets('equip_command',nil,set)
  170. else
  171. msg.addon_msg(123,'Equip command cannot be completed. That set does not exist.')
  172. end
  173. elseif cmd == 'export' then
  174. export_set(splitup)
  175. elseif cmd == 'validate' then
  176. if user_env and user_env.sets then
  177. refresh_globals()
  178. validate(splitup)
  179. else
  180. msg.addon_msg(123,'There is nothing to validate because there is no file loaded.')
  181. end
  182. elseif cmd == 'l' or cmd == 'load' then
  183. if splitup[1] then
  184. local f_name = table.concat(splitup,' ')
  185. if pathsearch({f_name}) then
  186. refresh_globals()
  187. command_registry = Command_Registry.new()
  188. load_user_files(false,f_name)
  189. else
  190. msg.addon_msg(123,'File not found.')
  191. end
  192. else
  193. msg.addon_msg(123,'No file name was provided.')
  194. end
  195. elseif cmd == 'enable' then
  196. disenable(splitup,command_enable,'enable',false)
  197. elseif cmd == 'disable' then
  198. disenable(splitup,disable,'disable',true)
  199. elseif cmd == 'reload' or cmd == 'r' then
  200. refresh_user_env()
  201. elseif strip(cmd) == 'debugmode' then
  202. _settings.debug_mode = not _settings.debug_mode
  203. print('GearSwap: Debug Mode set to '..tostring(_settings.debug_mode)..'.')
  204. elseif strip(cmd) == 'demomode' then
  205. _settings.demo_mode = not _settings.demo_mode
  206. print('GearSwap: Demo Mode set to '..tostring(_settings.demo_mode)..'.')
  207. elseif strip(cmd) == 'showswaps' then
  208. _settings.show_swaps = not _settings.show_swaps
  209. print('GearSwap: Show Swaps set to '..tostring(_settings.show_swaps)..'.')
  210. elseif _settings.debug_mode and strip(cmd) == 'eval' then
  211. assert(loadstring(table.concat(splitup,' ')))()
  212. else
  213. local handled = false
  214. if not gearswap_disabled then
  215. for i,v in ipairs(unhandled_command_events) do
  216. handled = equip_sets(v,nil,cmd,unpack(splitup))
  217. if handled then break end
  218. end
  219. end
  220. if not handled then
  221. print('GearSwap: Command not found')
  222. end
  223. end
  224. end)
  225.  
  226. function disenable(tab,funct,functname,pol)
  227. local slot_name = ''
  228. local ltab = L{}
  229. for i,v in pairs(tab) do
  230. ltab:append(v:gsub('[^%a_%d]',''):lower())
  231. end
  232. if ltab:contains('all') then
  233. funct('main','sub','range','ammo','head','neck','lear','rear','body','hands','lring','rring','back','waist','legs','feet')
  234. print('GearSwap: All slots '..functname..'d.')
  235. elseif ltab.n > 0 then
  236. local found = L{}
  237. local not_found = L{}
  238. for slot_name in ltab:it() do
  239. if slot_map[slot_name] then
  240. funct(slot_name)
  241. found:append(slot_name)
  242. else
  243. not_found:append(slot_name)
  244. end
  245. end
  246. if found.n > 0 then
  247. print('GearSwap: '..found:tostring()..' slot'..(found.n>1 and 's' or '')..' '..functname..'d.')
  248. end
  249. if not_found.n > 0 then
  250. print('GearSwap: Unable to find slot'..(not_found.n>1 and 's' or '')..' '..not_found:tostring()..'.')
  251. end
  252. elseif gearswap_disabled ~= pol and not tab[2] then
  253. print('GearSwap: User file '..functname..'d')
  254. gearswap_disabled = pol
  255. end
  256. end
  257.  
  258. windower.register_event('incoming chunk',function(id,data,modified,injected,blocked)
  259. windower.debug('incoming chunk '..id)
  260.  
  261. if next_packet_events and next_packet_events.sequence_id ~= data:unpack('H',3) then
  262. if not next_packet_events.globals_update or next_packet_events.globals_update ~= data:unpack('H',3) then
  263. refresh_globals()
  264. next_packet_events.globals_update = data:unpack('H',3)
  265. end
  266. if next_packet_events.pet_status_change then
  267. if pet.isvalid then
  268. equip_sets('pet_status_change',nil,next_packet_events.pet_status_change.newstatus,next_packet_events.pet_status_change.oldstatus)
  269. end
  270. next_packet_events.pet_status_change = nil
  271. end
  272. if next_packet_events.pet_change then
  273. if next_packet_events.pet_change.pet then -- Losing a pet
  274. equip_sets('pet_change',nil,next_packet_events.pet_change.pet,false)
  275. next_packet_events.pet_change = nil
  276. elseif pet.isvalid then -- Gaining a pet
  277. equip_sets('pet_change',nil,pet,true)
  278. next_packet_events.pet_change = nil
  279. end
  280. end
  281. if not next_packet_events.pet_status_change and not next_packet_events.pet_change then
  282. next_packet_events = nil
  283. end
  284. end
  285.  
  286. if injected then
  287. elseif id == 0x00A then
  288. windower.debug('zone change')
  289. command_registry = Command_Registry.new()
  290. table.clear(not_sent_out_equip)
  291.  
  292. player.id = data:unpack('I',0x05)
  293. player.index = data:unpack('H',0x09)
  294. if player.main_job_id and player.main_job_id ~= data:byte(0xB5) and player.name and player.name == data:unpack('z',0x85) then
  295. windower.debug('job change on zone')
  296. load_user_files(data:byte(0xB5))
  297. else
  298. player.name = data:unpack('z',0x85)
  299. end
  300. player.main_job_id = data:byte(0xB5)
  301. player.sub_job_id = data:byte(0xB8)
  302. player.vitals.max_hp = data:unpack('I',0xE9)
  303. player.vitals.max_mp = data:unpack('I',0xED)
  304. player.max_hp = data:unpack('I',0xE9)
  305. player.max_mp = data:unpack('I',0xED)
  306. update_job_names()
  307.  
  308. world.zone_id = data:unpack('H',0x31)
  309. _ExtraData.world.conquest = false
  310. for i,v in pairs(region_to_zone_map) do
  311. if v:contains(world.zone_id) then
  312. _ExtraData.world.conquest = {
  313. region_id = i,
  314. region_name = res.regions[i][language],
  315. }
  316. break
  317. end
  318. end
  319. weather_update(data:byte(0x69))
  320. world.logged_in = true
  321.  
  322. _ExtraData.world.in_mog_house = data:byte(0x81) == 1
  323. refresh_ffxi_info()
  324. elseif id == 0x00B then
  325. -- Blank temporary items when zoning.
  326. items.temporary = make_inventory_table()
  327. elseif id == 0x0E and pet.index and pet.index == data:unpack('H',9) and math.floor((data:byte(11)%8)/4)== 1 then
  328. local oldstatus = pet.status
  329. local status_id = data:byte(32)
  330. -- Filter all statuses aside from Idle/Engaged/Dead/Engaged dead.
  331. if status_id < 4 or status_id == 33 or status_id == 47 then
  332. local newstatus = copy_entry(res.statuses[status_id])
  333. if newstatus and newstatus[language] then
  334. newstatus = newstatus[language]
  335. if oldstatus ~= newstatus then
  336. if not next_packet_events then next_packet_events = {sequence_id = data:byte(4)*256+data:byte(3)} end
  337. next_packet_events.pet_status_change = {newstatus=newstatus,oldstatus=oldstatus}
  338. end
  339. end
  340. end
  341. elseif id == 0x01B then
  342. for job_id = 1,23 do
  343. player.jobs[to_windower_api(res.jobs[job_id].english)] = data:byte(job_id + 72)
  344. end
  345.  
  346. local enc = data:unpack('H',0x61)
  347. local tab = {}
  348. for slot_id,slot_name in pairs(default_slot_map) do
  349. local tf = (((enc%(2^(slot_id+1))) / 2^slot_id) >= 1)
  350. if encumbrance_table[slot_id] and not tf and not_sent_out_equip[slot_name] and not disable_table[i] then
  351. tab[slot_name] = not_sent_out_equip[slot_name]
  352. not_sent_out_equip[slot_name] = nil
  353. end
  354. if encumbrance_table[slot_id] and not tf then
  355. msg.debugging("Your "..slot_name.." slot is now unlocked.")
  356. end
  357. encumbrance_table[slot_id] = tf
  358. end
  359. if table.length(tab) > 0 then
  360. refresh_globals()
  361. equip_sets('equip_command',nil,tab)
  362. end
  363. elseif id == 0x01E then
  364. local bag = to_windower_compact(res.bags[data:byte(0x09)].english)
  365. local slot = data:byte(0x0A)
  366. local count = data:unpack('I',5)
  367. if not items[bag][slot] then items[bag][slot] = make_empty_item_table(slot) end
  368. items[bag][slot].count = count
  369. if count == 0 then
  370. items[bag][slot].id = 0
  371. items[bag][slot].bazaar = 0
  372. items[bag][slot].status = 0
  373. end
  374. elseif id == 0x01F then
  375. local bag = to_windower_compact(res.bags[data:byte(0x0B)].english)
  376. local slot = data:byte(0x0C)
  377. if not items[bag][slot] then items[bag][slot] = make_empty_item_table(slot) end
  378. items[bag][slot].id = data:unpack('H',9)
  379. items[bag][slot].count = data:unpack('I',5)
  380. items[bag][slot].status = data:byte(0x0D)
  381. elseif id == 0x020 then
  382. local bag = to_windower_compact(res.bags[data:byte(0x0F)].english)
  383. local slot = data:byte(0x10)
  384. if not items[bag][slot] then items[bag][slot] = make_empty_item_table(slot) end
  385. items[bag][slot].id = data:unpack('H',0x0D)
  386. items[bag][slot].count = data:unpack('I',5)
  387. items[bag][slot].bazaar = data:unpack('I',9)
  388. items[bag][slot].status = data:byte(0x11)
  389. items[bag][slot].extdata = data:sub(0x12,0x29)
  390. -- Did not mess with linkshell stuff
  391. elseif id == 0x28 then
  392. inc_action(windower.packets.parse_action(data))
  393. elseif id == 0x29 then
  394. if gearswap_disabled then return end
  395. local arr = {}
  396. arr.actor_id = data:unpack('I',0x05)
  397. arr.target_id = data:unpack('I',0x09)
  398. arr.param_1 = data:unpack('I',0x0D)
  399. arr.param_2 = data:unpack('I',0x11)%64 -- First 6 bits
  400. arr.param_3 = math.floor(data:unpack('I',0x11)/64) -- Rest
  401. arr.actor_index = data:unpack('H',0x15)
  402. arr.target_index = data:unpack('H',0x17)
  403. arr.message_id = data:unpack('H',0x19)%32768
  404.  
  405. inc_action_message(arr)
  406. elseif id == 0x037 then
  407. player.status_id = data:byte(0x31)
  408. local bitmask = data:sub(0x4D,0x54)
  409. for i = 1,32 do
  410. local bitmask_position = 2*((i-1)%4)
  411. player.buffs[i] = data:byte(4+i) + 256*math.floor(bitmask:byte(1+math.floor((i-1)/4))%(2^(bitmask_position+2))/(2^bitmask_position))
  412. end
  413.  
  414. local indi_byte = data:byte(0x59)
  415. if indi_byte%128/64 >= 1 then
  416. local temp_indi = _ExtraData.player.indi
  417. _ExtraData.player.indi = {
  418. element = res.elements[indi_byte%8][language],
  419. element_id = indi_byte%8,
  420. size = math.floor((indi_byte%64)/16) + 1, -- Size range of 1~4
  421. }
  422. if (indi_byte%16)/8 >= 1 then
  423. _ExtraData.player.indi.target = 'Enemy'
  424. else
  425. _ExtraData.player.indi.target = 'Ally'
  426. end
  427. if not temp_indi then
  428. -- There was not an indi spell up
  429. refresh_globals()
  430. equip_sets('indi_change',nil,_ExtraData.player.indi,true)
  431. elseif temp_indi.element_id ~= _ExtraData.player.indi.element_id or temp_indi.target ~= _ExtraData.player.indi.target or temp_indi.size ~= _ExtraData.player.indi.size then
  432. -- There was already an indi spell up, so check if it changed
  433. refresh_globals()
  434. equip_sets('indi_change',nil,temp_indi,false)
  435. equip_sets('indi_change',nil,_ExtraData.player.indi,true)
  436. end
  437. elseif _ExtraData.player.indi then
  438. -- An indi effect has been lost.
  439. local temp_indi = _ExtraData.player.indi
  440. _ExtraData.player.indi = nil
  441. refresh_globals()
  442. equip_sets('indi_change',nil,temp_indi,false)
  443. end
  444.  
  445. local subj_ind = data:unpack('H', 0x35) / 8
  446. if subj_ind == 0 and pet.isvalid then
  447. if not next_packet_events then next_packet_events = {sequence_id = data:unpack('H',3)} end
  448. refresh_globals()
  449. pet.isvalid = false
  450. next_packet_events.pet_change = {pet = table.reassign({},pet)}
  451. elseif subj_ind ~= 0 and not pet.isvalid then
  452. if not next_packet_events then next_packet_events = {sequence_id = data:unpack('H',3)} end
  453. next_packet_events.pet_change = {subj_ind = subj_ind}
  454. end
  455. elseif id == 0x044 then
  456. -- No idea what this is doing
  457. elseif id == 0x050 then
  458. local inv = items[to_windower_compact(res.bags[data:byte(7)].english)]
  459. if data:byte(5) ~= 0 then
  460. items.equipment[toslotname(data:byte(6))] = {slot=data:byte(5),bag_id = data:byte(7)}
  461. if not inv[data:byte(5)] then inv[data:byte(5)] = make_empty_item_table(data:byte(5)) end
  462. items[to_windower_compact(res.bags[data:byte(7)].english)][data:byte(5)].status = 5 -- Set the status to "equipped"
  463. else
  464. items.equipment[toslotname(data:byte(6))] = {slot=empty,bag_id=0}
  465. if not inv[data:byte(5)] then inv[data:byte(5)] = make_empty_item_table(data:byte(5)) end
  466. items[to_windower_compact(res.bags[data:byte(7)].english)][data:byte(5)].status = 0 -- Set the status to "unequipped"
  467. end
  468. elseif id == 0x05E then -- Conquest ID
  469. if _ExtraData.world.conquest then
  470. local offset = _ExtraData.world.conquest.region_id*4 + 11
  471. if offset == 99 then
  472. offset = 95
  473. elseif offset == 107 then
  474. offset = 99
  475. end
  476. local strength_map = {[0]='Minimal',[1]='Minor',[2]='Major',[3]='Dominant'}
  477. local nation_map = {[0]={english='Neutral',japanese='Neutral'},[1]=res.regions[0],[2]=res.regions[1],
  478. [3]=res.regions[2],[4]={english='Beastman',japanese='Beastman'},[0xFF]=res.regions[3]}
  479. _ExtraData.world.conquest.strengths = {
  480. sandoria=strength_map[data:byte(offset+2)%4],
  481. bastok=strength_map[math.floor(data:byte(offset+2)%16/4)],
  482. windurst=strength_map[math.floor(data:byte(offset+2)%64/16)],
  483. beastmen=strength_map[math.floor(data:byte(offset+2)/64)],}
  484. _ExtraData.world.conquest.nation = nation_map[data:byte(offset+3)][language]
  485. _ExtraData.world.conquest.sandoria = data:byte(0x87)
  486. _ExtraData.world.conquest.bastok = data:byte(0x88)
  487. _ExtraData.world.conquest.windurst = data:byte(0x89)
  488. _ExtraData.world.conquest.beastmen = 100-data:byte(0x87)-data:byte(0x88)-data:byte(0x89)
  489. end
  490. elseif id == 0x061 then
  491. player.vitals.max_hp = data:unpack('I',5)
  492. player.vitals.max_mp = data:unpack('I',9)
  493. player.max_hp = data:unpack('I',5)
  494. player.max_mp = data:unpack('I',9)
  495. player.main_job_id = data:byte(13)
  496. player.main_job_level = data:byte(14)
  497.  
  498. _ExtraData.player.nation_id = data:byte(0x51)
  499. _ExtraData.player.nation = res.regions[_ExtraData.player.nation_id][language] or 'None'
  500.  
  501. if player.sub_job_id ~= data:byte(15) then
  502. -- Subjob change event
  503. local temp_sub = player.sub_job
  504. player.sub_job_id = data:byte(15)
  505. player.sub_job_level = data:byte(16)
  506. update_job_names()
  507. refresh_globals()
  508. equip_sets('sub_job_change',nil,player.sub_job,temp_sub)
  509. end
  510. update_job_names()
  511. elseif id == 0x062 then
  512. for i = 1,0x71,2 do
  513. local skill = data:unpack('H',i + 0x82)%32768
  514. local current_skill = res.skills[math.floor(i/2)+1]
  515. if current_skill then
  516. player.skills[to_windower_api(current_skill.english)] = skill
  517. end
  518. end
  519. elseif id == 0x0DF and data:unpack('I',5) == player.id then
  520. player.vitals.hp = data:unpack('I',9)
  521. player.vitals.mp = data:unpack('I',13)
  522. player.vitals.tp = data:unpack('I',0x11)
  523. player.vitals.hpp = data:byte(0x17)
  524. player.vitals.mpp = data:byte(0x18)
  525.  
  526. player.hp = data:unpack('I',9)
  527. player.mp = data:unpack('I',13)
  528. player.tp = data:unpack('I',0x11)
  529. player.hpp = data:byte(0x17)
  530. player.mpp = data:byte(0x18)
  531. elseif id == 0x0E2 and data:unpack('I',5)==player.id then
  532. player.vitals.hp = data:unpack('I',9)
  533. player.vitals.mp = data:unpack('I',0xB)
  534. player.vitals.tp = data:unpack('I',0x11)
  535. player.vitals.hpp = data:byte(0x1E)
  536. player.vitals.mpp = data:byte(0x1F)
  537.  
  538. player.hp = data:unpack('I',9)
  539. player.mp = data:unpack('I',0xB)
  540. player.tp = data:unpack('I',0x11)
  541. player.hpp = data:byte(0x1E)
  542. player.mpp = data:byte(0x1F)
  543. elseif id == 0x117 then
  544. for i=0x49,0x85,4 do
  545. local arr = data:sub(i,i+3)
  546. local inv = items[to_windower_compact(res.bags[arr:byte(3)].english)]
  547. if arr:byte(1) ~= 0 then
  548. items.equipment[toslotname(arr:byte(2))] = {slot=arr:byte(1),bag_id = arr:byte(3)}
  549. if not inv[arr:byte(1)] then inv[arr:byte(1)] = make_empty_item_table(arr:byte(1)) end
  550. items[to_windower_compact(res.bags[arr:byte(3)].english)][arr:byte(1)].status = 5 -- Set the status to "equipped"
  551. else
  552. items.equipment[toslotname(arr:byte(2))] = {slot=empty,bag_id=0}
  553. if not inv[arr:byte(1)] then inv[arr:byte(1)] = make_empty_item_table(arr:byte(1)) end
  554. items[to_windower_compact(res.bags[arr:byte(3)].english)][arr:byte(1)].status = 0 -- Set the status to "unequipped"
  555. end
  556. end
  557. end
  558. end)
  559.  
  560. windower.register_event('status change',function(new,old)
  561. windower.debug('status change '..new)
  562. if gearswap_disabled or T{2,3,4}:contains(old) or T{2,3,4}:contains(new) then return end
  563.  
  564. refresh_globals()
  565. equip_sets('status_change',nil,res.statuses[new].english,res.statuses[old].english)
  566. end)
  567.  
  568. windower.register_event('gain buff',function(buff_id)
  569. if not res.buffs[buff_id] then
  570. error('GearSwap: No known status for buff id #'..tostring(buff_id))
  571. end
  572. local buff_name = res.buffs[buff_id][language]
  573. windower.debug('gain buff '..buff_name..' ('..tostring(buff_id)..')')
  574. if gearswap_disabled then return end
  575.  
  576. -- Need to figure out what I'm going to do with this:
  577. if T{'terror','sleep','stun','petrification','charm','weakness'}:contains(buff_name:lower()) then
  578. for ts,v in pairs(command_registry) do
  579. if v.midaction then
  580. command_registry:delete_entry(ts)
  581. end
  582. end
  583. end
  584.  
  585. refresh_globals()
  586. equip_sets('buff_change',nil,buff_name,true,copy_entry(res.buffs[buff_id]))
  587. end)
  588.  
  589. windower.register_event('lose buff',function(buff_id)
  590. if not res.buffs[buff_id] then
  591. error('GearSwap: No known status for buff id #'..tostring(buff_id))
  592. end
  593. local buff_name = res.buffs[buff_id][language]
  594. windower.debug('lose buff '..buff_name..' ('..tostring(buff_id)..')')
  595. if gearswap_disabled then return end
  596. refresh_globals()
  597. equip_sets('buff_change',nil,buff_name,false,copy_entry(res.buffs[buff_id]))
  598. end)
  599.  
  600. windower.register_event('login',function(name)
  601. windower.debug('login '..name)
  602. initialize_globals()
  603. windower.send_command('@wait 2;lua i gearswap refresh_user_env;')
  604. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement