Guest User

Untitled

a guest
Jul 9th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.73 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.  
  28. -- Deals with refreshing player information and loading user settings --
  29.  
  30.  
  31.  
  32. -----------------------------------------------------------------------------------
  33. --Name: refresh_globals()
  34. --Args:
  35. ---- None
  36. -----------------------------------------------------------------------------------
  37. --Returns:
  38. ---- None
  39. ---- Updates all global variables to reflect the player's status. Generally run
  40. ---- before calling a player function.
  41. -----------------------------------------------------------------------------------
  42. function refresh_globals(user_event_flag)
  43. local current = os.clock()
  44. local dt = current - last_refresh
  45. if not user_event_flag or dt > 0.05 then
  46. refresh_player(dt,user_event_flag)
  47. refresh_ffxi_info(dt,user_event_flag)
  48. refresh_group_info(dt,user_event_flag)
  49. last_refresh = current
  50. end
  51. end
  52.  
  53. -----------------------------------------------------------------------------------
  54. --Name: load_user_files()
  55. --Args:
  56. ---- None
  57. -----------------------------------------------------------------------------------
  58. --Returns:
  59. ---- user_env, a table of all of the player defined functions and their current
  60. ---- variables.
  61. -----------------------------------------------------------------------------------
  62. function load_user_files(job_id,user_file)
  63. job_id = tonumber(job_id)
  64.  
  65. if job_id and res.jobs[job_id] then
  66. user_pcall('file_unload',res.jobs[job_id][language..'_short'])
  67. end
  68.  
  69. for i in pairs(registered_user_events) do
  70. unregister_event_user(i)
  71. end
  72.  
  73. for i in pairs(__raw.text.registry) do
  74. windower.text.delete(i)
  75. end
  76.  
  77. for i in pairs(__raw.prim.registry) do
  78. windower.prim.delete(i)
  79. end
  80.  
  81. user_env = nil
  82. unhandled_command_events = {}
  83. --registered_user_events = {}
  84. include_user_path = nil
  85.  
  86. language = 'english' -- Reset language to english when changing job files.
  87. refresh_globals()
  88.  
  89. if job_id and res.jobs[job_id] then
  90. player.main_job_id = job_id
  91. update_job_names()
  92. end
  93.  
  94.  
  95. local path
  96. path = pathsearch({user_file})
  97. if not path then
  98. local long_job = res.jobs[job_id].english
  99. local short_job = res.jobs[job_id].english_short
  100. local tab = {player.name..'_'..short_job..'.lua',player.name..'-'..short_job..'.lua',
  101. player.name..'_'..long_job..'.lua',player.name..'-'..long_job..'.lua',
  102. player.name..'.lua',short_job..'.lua',long_job..'.lua','default.lua'}
  103. path = pathsearch(tab)
  104. end
  105.  
  106. if not path then
  107. current_job_file = nil
  108. gearswap_disabled = true
  109. sets = nil
  110. return
  111. end
  112.  
  113. user_env = {gearswap = _G, _global = _global, _settings = _settings,_addon=_addon,
  114. -- Player functions
  115. equip = equip, cancel_spell=cancel_spell, change_target=change_target, cast_delay=cast_delay,
  116. print_set=print_set,set_combine=set_combine,disable=disable,enable=user_enable,
  117. send_command=send_cmd_user,windower=user_windower,include=include_user,
  118. midaction=user_midaction,pet_midaction=user_pet_midaction,set_language=set_language,
  119. show_swaps = show_swaps,debug_mode=debug_mode,include_path=user_include_path,
  120. register_unhandled_command=user_unhandled_command,
  121.  
  122. -- Library functions
  123. string=string,math=math,table=table,set=set,list=list,T=T,S=S,L=L,pack=pack,
  124. os=os,texts=texts,type=type,tostring=tostring,tonumber=tonumber,pairs=pairs,
  125. ipairs=ipairs, print=print, add_to_chat=add_to_chat_user,unpack=unpack,next=next,
  126. select=select,lua_base_path=windower.addon_path,empty=empty,file=file,
  127. loadstring=loadstring,assert=assert,error=error,pcall=pcall,io=io,dofile=dofile,
  128.  
  129. debug=debug,coroutine=coroutine,setmetatable=setmetatable,getmetatable=getmetatable,
  130. rawset=rawset,rawget=rawget,require=include_user,
  131.  
  132. -- Player environment things
  133. buffactive=buffactive,
  134. player=player,
  135. world=world,
  136. pet=pet,
  137. fellow=fellow,
  138. alliance=alliance,
  139. party=alliance[1],
  140. sets={naked = {main=empty,sub=empty,range=empty,ammo=empty,
  141. head=empty,neck=empty,ear1=empty,ear2=empty,
  142. body=empty,hands=empty,ring1=empty,ring2=empty,
  143. back=empty,waist=empty,legs=empty,feet=empty}}
  144. }
  145.  
  146. user_env['_G'] = user_env
  147.  
  148. -- Try to load data/<name>_<main job>.lua
  149. local funct, err = loadfile(path)
  150.  
  151. -- If the file cannot be loaded, print the error and load the default.
  152. if funct == nil then
  153. print('User file problem: '..err)
  154. current_job_file = nil
  155. gearswap_disabled = true
  156. sets = nil
  157. return
  158. else
  159. current_job_file = user_file or res.jobs[job_id][language..'_short']
  160. print('GearSwap: Loaded your '..current_job_file..' Lua file!')
  161. end
  162.  
  163. setfenv(funct, user_env)
  164.  
  165. -- Verify that funct contains functions.
  166. local status, plugin = pcall(funct)
  167.  
  168. if not status then
  169. error('GearSwap: File failed to load: \n'..plugin)
  170. gearswap_disabled = true
  171. sets = nil
  172. return nil
  173. end
  174.  
  175. _global.pretarget_cast_delay = 0
  176. _global.precast_cast_delay = 0
  177. _global.cancel_spell = false
  178. _global.current_event = 'get_sets'
  179. user_pcall('get_sets')
  180.  
  181. gearswap_disabled = false
  182. sets = user_env.sets
  183. end
  184.  
  185.  
  186. -----------------------------------------------------------------------------------
  187. --Name: refresh_player()
  188. --Args:
  189. ---- None
  190. -----------------------------------------------------------------------------------
  191. --Returns:
  192. ---- None
  193. ----
  194. ---- Loads player from windower.ffxi.get_player().
  195. ---- Adds in a "job", "race", "equipment", "target", and "subtarget" field
  196. ---- Also updates "pet" and assigns isvalid and element fields.
  197. ---- Further converts player.buffs to buffactive.
  198. -------- Indexes buffs by their buff name and assigns a value equal to the number
  199. -------- of buffs with that name active.
  200. -----------------------------------------------------------------------------------
  201. function refresh_player(dt,user_event_flag)
  202. local pl, player_mob_table
  203. if not user_event_flag or dt > 0.5 then
  204. pl = windower.ffxi.get_player()
  205. if not pl or not pl.vitals then return end
  206.  
  207. player_mob_table = windower.ffxi.get_mob_by_index(pl.index)
  208. if not player_mob_table then return end
  209.  
  210. table.reassign(player,pl)
  211. for i,v in pairs(player.vitals) do
  212. player[i]=v
  213. end
  214. update_job_names()
  215. player.status_id = player.status
  216. player.status = res.statuses[player.status].english
  217. player.nation_id = player.nation
  218. player.nation = res.regions[player.nation_id][language] or 'None'
  219.  
  220. for i,v in pairs(player_mob_table) do
  221. if i == 'name' then
  222. player.mob_name = v
  223. elseif i~= 'is_npc' and i~='tp' and i~='mpp' and i~='claim_id' and i~='status' then
  224. player[i] = v
  225. end
  226. end
  227.  
  228. if player_mob_table.race ~= nil then
  229. player.race_id = player.race
  230. player.race = res.races[player.race][language]
  231. end
  232. end
  233.  
  234. -- This being nil does not cause a return, but items should not really be changing when zoning.
  235. local cur_equip = table.reassign({},items.equipment)
  236.  
  237. -- Assign player.equipment to be the gear that has been sent out and the server currently thinks
  238. -- you are wearing. (the sent_out_equip for loop above).
  239. player.equipment = make_user_table()
  240. table.reassign(player.equipment,to_names_set(cur_equip))
  241.  
  242. -- Assign player.inventory to be keyed to item.inventory[i][language] and to have a value of count, similar to buffactive
  243. if items.inventory then player.inventory = refresh_item_list(items.inventory) end
  244. if items.sack then player.sack = refresh_item_list(items.sack) end
  245. if items.satchel then player.satchel = refresh_item_list(items.satchel) end
  246. if items.case then player.case = refresh_item_list(items.case) end
  247. if items.wardrobe then player.wardrobe = refresh_item_list(items.wardrobe) end
  248.  
  249. -- Monster tables for the target and subtarget.
  250. player.target = target_complete(windower.ffxi.get_mob_by_target('t'))
  251. player.subtarget = target_complete(windower.ffxi.get_mob_by_target('st'))
  252. player.last_subtarget = target_complete(windower.ffxi.get_mob_by_target('lastst'))
  253.  
  254. -- If we have a pet, create or update the table info.
  255. if player_mob_table and player_mob_table.pet_index then
  256. local player_pet_table = windower.ffxi.get_mob_by_index(player_mob_table.pet_index)
  257. if player_pet_table then
  258. table.reassign(pet, target_complete(player_pet_table))
  259. pet.claim_id = nil
  260. pet.is_npc = nil
  261. pet.isvalid = true
  262. if pet.tp then pet.tp = pet.tp/10 end
  263.  
  264. if avatar_element[pet.name] then
  265. pet.element = res.elements[avatar_element[pet.name]][language]
  266. else
  267. pet.element = res.elements[-1][language] -- Physical
  268. end
  269. else
  270. table.reassign(pet, {isvalid=false})
  271. end
  272. else
  273. table.reassign(pet, {isvalid=false})
  274. end
  275.  
  276. if player.main_job_id == 18 or player.sub_job_id == 18 then
  277. local auto_tab
  278. if player.main_job_id == 18 then auto_tab = windower.ffxi.get_mjob_data()
  279. else auto_tab = windower.ffxi.get_sjob_data() end
  280.  
  281. if auto_tab.name then
  282. for i,v in pairs(auto_tab) do
  283. if not T{'available_heads','attachments','available_frames','available_attachments','frame','head'}:contains(i) then
  284. pet[i] = v
  285. end
  286. end
  287. pet.available_heads = make_user_table()
  288. pet.attachments = make_user_table()
  289. pet.available_frames = make_user_table()
  290. pet.available_attachments = make_user_table()
  291.  
  292. -- available parts
  293. for i,id in pairs(auto_tab.available_heads) do
  294. if res.items[id] and type(res.items[id]) == 'table' then
  295. pet.available_heads[res.items[id][language]] = true
  296. end
  297. end
  298. for i,id in pairs(auto_tab.available_frames) do
  299. if res.items[id] and type(res.items[id]) == 'table' then
  300. pet.available_frames[res.items[id][language]] = true
  301. end
  302. end
  303. for i,id in pairs(auto_tab.available_attachments) do
  304. if res.items[id] and type(res.items[id]) == 'table' then
  305. pet.available_attachments[res.items[id][language]] = true
  306. end
  307. end
  308.  
  309. -- actual parts
  310. pet.head = res.items[auto_tab.head][language]
  311. pet.frame = res.items[auto_tab.frame][language]
  312. for i,id in pairs(auto_tab.attachments) do
  313. if res.items[id] and type(res.items[id]) == 'table' then
  314. pet.attachments[res.items[id][language]] = true
  315. end
  316. end
  317.  
  318. if pet.max_mp ~= 0 then
  319. pet.mpp = math.floor(pet.mp/pet.max_mp*100)
  320. else
  321. pet.mpp = 0
  322. end
  323. end
  324. elseif player.main_job_id == 23 then
  325. local species_id = windower.ffxi.get_mjob_data().species
  326. -- Should add instincts when they become available
  327.  
  328. if species_id then
  329. player.species = {}
  330. for i,v in pairs(res.monstrosity[species_id]) do
  331. player.species[i] = v
  332. end
  333. player.species.name = player.species[language]
  334. player.species.tp_moves = copy_entry(res.monstrosity[species_id].tp_moves)
  335. for i,v in pairs(player.species.tp_moves) do
  336. if v > player.main_job_level then
  337. player.species.tp_moves[i] = nil
  338. end
  339. end
  340. end
  341. else
  342. player.species = nil
  343. end
  344.  
  345. table.reassign(fellow,target_complete(windower.ffxi.get_mob_by_target('<ft>')))
  346. if fellow.name then
  347. fellow.isvalid = true
  348. else
  349. fellow.isvalid=false
  350. end
  351.  
  352. refresh_buff_active(player.buffs)
  353.  
  354. for global_variable_name,extradatatable in pairs(_ExtraData) do
  355. if _G[global_variable_name] then
  356. for sub_variable_name,value in pairs(extradatatable) do
  357. _G[global_variable_name][sub_variable_name] = value
  358. end
  359. end
  360. end
  361. end
  362.  
  363. -----------------------------------------------------------------------------------
  364. --Name: refresh_ffxi_info()
  365. --Args:
  366. ---- None
  367. -----------------------------------------------------------------------------------
  368. --Returns:
  369. ---- None
  370. ----
  371. ---- Updates the global "world" with windower.ffxi.get_info (ignores the target field).
  372. ---- Also sets windower.ffxi.get_info()['zone'] to be world.area for consistency with spellcast
  373. -----------------------------------------------------------------------------------
  374. function refresh_ffxi_info(dt,user_event_flag)
  375. local info = windower.ffxi.get_info()
  376. for i,v in pairs(info) do
  377. if i == 'zone' and res.zones[v] then
  378. world.zone = res.zones[v][language]
  379. world.area = world.zone
  380. elseif i == 'weather' and res.weather[v] then
  381. weather_update(v)
  382. elseif i == 'day' and res.days[v] then
  383. world.day = res.days[v][language]
  384. world.day_element = res.elements[res.days[v].element][language]
  385. elseif i == 'moon' then
  386. world.moon_pct = v
  387. elseif i == 'moon_phase' and res.moon_phases[v] then
  388. world.moon = res.moon_phases[v][language]
  389. elseif i ~= 'target' then
  390. world[i] = v
  391. end
  392. end
  393.  
  394. for global_variable_name,extradatatable in pairs(_ExtraData) do
  395. if _G[global_variable_name] then
  396. for sub_variable_name,value in pairs(extradatatable) do
  397. _G[global_variable_name][sub_variable_name] = value
  398. end
  399. end
  400. end
  401. end
  402.  
  403.  
  404. -----------------------------------------------------------------------------------
  405. --Name: weather_update(id)
  406. --Args:
  407. ---- id Current weather ID
  408. -----------------------------------------------------------------------------------
  409. --Returns:
  410. ---- None, updates the table.
  411. -----------------------------------------------------------------------------------
  412. function weather_update(id)
  413. world.weather_id = id
  414. world.real_weather_id = id
  415. world.real_weather = res.weather[id][language]
  416. world.real_weather_element = res.elements[res.weather[id].element][language]
  417. local buff = false
  418. if buffactive[178] then
  419. buff = true
  420. world.weather_id = 4
  421. elseif buffactive[179] then
  422. buff = true
  423. world.weather_id = 12
  424. elseif buffactive[180] then
  425. buff = true
  426. world.weather_id = 10
  427. elseif buffactive[181] then
  428. buff = true
  429. world.weather_id = 8
  430. elseif buffactive[182] then
  431. buff = true
  432. world.weather_id = 14
  433. elseif buffactive[183] then
  434. buff = true
  435. world.weather_id = 6
  436. elseif buffactive[184] then
  437. buff = true
  438. world.weather_id = 16
  439. elseif buffactive[185] then
  440. buff = true
  441. world.weather_id = 18
  442. elseif buffactive[589] then
  443. world.weather_id = 5
  444. elseif buffactive[590] then
  445. world.weather_id = 13
  446. elseif buffactive[591] then
  447. world.weather_id = 11
  448. elseif buffactive[592] then
  449. world.weather_id = 9
  450. elseif buffactive[593] then
  451. world.weather_id = 15
  452. elseif buffactive[594] then
  453. world.weather_id = 7
  454. elseif buffactive[595] then
  455. world.weather_id = 17
  456. elseif buffactive[596] then
  457. world.weather_id = 19
  458. end
  459. if buff and world.weather_id == world.real_weather_id then
  460. world.weather_id = world.weather_id + 1
  461. end
  462. world.weather = res.weather[world.weather_id][language]
  463. world.weather_element = res.elements[res.weather[world.weather_id].element][language]
  464. end
  465.  
  466.  
  467. -----------------------------------------------------------------------------------
  468. --Name: refresh_group_info()
  469. --Args:
  470. ---- None
  471. -----------------------------------------------------------------------------------
  472. --Returns:
  473. ---- None
  474. ----
  475. ---- Takes the mob arrays from windower.ffxi.get_party() and splits them from p0~5, a10~15, a20~25
  476. ---- into alliance[1][1~6], alliance[2][1~6], alliance[3][1~6], respectively.
  477. ---- Also adds a "count" field to alliance (total number of people in alliance) and
  478. ---- to the individual subtables (total number of people in each party.
  479. -----------------------------------------------------------------------------------
  480. function refresh_group_info(dt,user_event_flag)
  481. clean_alliance()
  482.  
  483. local j = windower.ffxi.get_party() or {}
  484. for i,v in pairs(j) do
  485. if type(v) == 'table' and v.mob and v.mob.race then
  486. v.mob.race_id = v.mob.race
  487. v.mob.race = res.races[v.mob.race][language]
  488. end
  489.  
  490. local allyIndex
  491. local partyIndex
  492.  
  493. -- For 'p#', ally index is 1, party index is the second char
  494. if i:sub(1,1) == 'p' and tonumber(i:sub(2)) then
  495. allyIndex = 1
  496. partyIndex = tonumber(i:sub(2))+1
  497. -- For 'a##', ally index is the second char, party index is the third char
  498. elseif tonumber(i:sub(2,2)) and tonumber(i:sub(3)) then
  499. allyIndex = tonumber(i:sub(2,2))+1
  500. partyIndex = tonumber(i:sub(3))+1
  501. end
  502.  
  503. if allyIndex and partyIndex then
  504. alliance[allyIndex][partyIndex] = v
  505. alliance[allyIndex].count = alliance[allyIndex].count + 1
  506. alliance.count = alliance.count + 1
  507. end
  508. end
  509. end
  510.  
  511. -- Cleans the current alliance array while keeping the subtable pointers intact.
  512. function clean_alliance()
  513. if not alliance or #alliance == 0 then
  514. alliance = make_user_table()
  515. alliance[1]={count=0}
  516. alliance[2]={count=0}
  517. alliance[3]={count=0}
  518. alliance.count=0
  519. else
  520. for ally_party = 1,3 do
  521. for i,v in pairs(alliance[ally_party]) do
  522. alliance[ally_party][i] = nil
  523. end
  524. alliance[ally_party].count = 0
  525. end
  526. alliance.count = 0
  527. end
  528. end
  529.  
  530. -----------------------------------------------------------------------------------
  531. --Name: refresh_buff_active(bufflist)
  532. --Args:
  533. ---- bufflist (table): List of buffs from windower.ffxi.get_player()['buffs']
  534. -----------------------------------------------------------------------------------
  535. --Returns:
  536. ---- buffarr (table)
  537. ---- buffarr is indexed by the string buff name and has a value equal to the number
  538. ---- of that string present in the buff array. So two marches would give
  539. ---- buffarr.march==2.
  540. -----------------------------------------------------------------------------------
  541. function refresh_buff_active(bufflist)
  542. buffarr = {}
  543. for i,v in pairs(bufflist) do
  544. if res.buffs[v] then -- For some reason we always have buff 255 active, which doesn't have an entry.
  545. local buff = res.buffs[v][language]:lower()
  546. if buffarr[buff] then
  547. buffarr[buff] = buffarr[buff] +1
  548. else
  549. buffarr[buff] = 1
  550. end
  551.  
  552. if buffarr[v] then
  553. buffarr[v] = buffarr[v] +1
  554. else
  555. buffarr[v] = 1
  556. end
  557. end
  558. end
  559. table.reassign(buffactive,buffarr)
  560. end
  561.  
  562. -----------------------------------------------------------------------------------
  563. --Name: refresh_item_list(itemlist)
  564. --Args:
  565. ---- itemlist (table): List of items from windower.ffxi.get_items().something
  566. -----------------------------------------------------------------------------------
  567. --Returns:
  568. ---- retarr (table)
  569. ---- retarr is indexed by the item name, and contains a table with the
  570. ---- item id, count, and short name. If the long name for the item is
  571. ---- different than the short name, an additional entry is added for
  572. ---- that.
  573. ----
  574. ---- Overall, this allows doing simple existance checks for both short
  575. ---- and long name (eg: player.inventory["Theo. Cap +1"] and
  576. ---- player.inventory["Theopany Cap +1"] both return the same table,
  577. ---- and both would be 'true' in a conditional check)), and get the item
  578. ---- count (player.inventory["Orichalc. Bullet"].count)
  579. ---- It also allows one to check for the alternate spelling of an item.
  580. -----------------------------------------------------------------------------------
  581. function refresh_item_list(itemlist)
  582. retarr = make_user_table()
  583. for i,v in pairs(itemlist) do
  584. if type(v) == 'table' and v.id and v.id ~= 0 then
  585. -- If we don't already have the primary item name in the table, add it.
  586. if res.items[v.id] and res.items[v.id][language] and not retarr[res.items[v.id][language]] then
  587. -- We add the entry as a sub-table containing the id and count
  588. retarr[res.items[v.id][language]] = {id=v.id, count=v.count, shortname=res.items[v.id][language]:lower()}
  589. -- If a long version of the name exists, and is different from the short version,
  590. -- add the long name to the info table and point the long name's key at that table.
  591. if res.items[v.id][language..'_log'] and res.items[v.id][language..'_log']:lower() ~= res.items[v.id][language]:lower() then
  592. retarr[res.items[v.id][language]].longname = res.items[v.id][language..'_log']:lower()
  593. retarr[res.items[v.id][language..'_log']] = retarr[res.items[v.id][language]]
  594. end
  595. elseif res.items[v.id] and res.items[v.id][language] then
  596. -- If there's already an entry for this item, all the hard work has already
  597. -- been done. Just update the count on the subtable of the main item, and
  598. -- everything else will link together.
  599. retarr[res.items[v.id][language]].count = retarr[res.items[v.id][language]].count + v.count
  600. end
  601. end
  602. end
  603. return retarr
  604. end
  605.  
  606. -----------------------------------------------------------------------------------
  607. --Name: refresh_user_env()
  608. --Args:
  609. ---- none
  610. -----------------------------------------------------------------------------------
  611. --Returns:
  612. ---- none, but loads user files if they exist.
  613. -----------------------------------------------------------------------------------
  614. function refresh_user_env(job_id)
  615. refresh_globals()
  616. if not job_id then job_id = windower.ffxi.get_player().main_job_id end
  617.  
  618. if not job_id then
  619. windower.send_command('@wait 1;lua i '.._addon.name..' refresh_user_env')
  620. else
  621. load_user_files(job_id)
  622. end
  623. end
  624.  
  625.  
  626. -----------------------------------------------------------------------------------
  627. --Name: pathsearch()
  628. --Args:
  629. ---- files_list - table of strings of the file name to search.
  630. -----------------------------------------------------------------------------------
  631. --Returns:
  632. ---- path of a valid file, if it exists. False if it doesn't.
  633. -----------------------------------------------------------------------------------
  634. function pathsearch(files_list)
  635.  
  636. -- base directory search order:
  637. -- windower
  638. -- %appdata%/Windower/GearSwap
  639.  
  640. -- sub directory search order:
  641. -- libs-dev (only in windower addon path)
  642. -- libs (only in windower addon path)
  643. -- data/player.name
  644. -- data/common
  645. -- data
  646.  
  647. local gearswap_data = windower.addon_path .. 'data/'
  648. local gearswap_appdata = os.getenv('APPDATA') .. '/Windower/GearSwap/'
  649.  
  650. local search_path = {
  651. [1] = windower.addon_path .. 'libs-dev/',
  652. [2] = windower.addon_path .. 'libs/',
  653. [3] = gearswap_data .. player.name .. '/',
  654. [4] = gearswap_data .. 'common/',
  655. [5] = gearswap_data,
  656. [6] = gearswap_appdata .. player.name .. '/',
  657. [7] = gearswap_appdata .. 'common/',
  658. [8] = gearswap_appdata,
  659. [9] = windower.windower_path .. 'addons/libs/'
  660. }
  661.  
  662. local user_path
  663. local normal_path
  664.  
  665. for _,basepath in ipairs(search_path) do
  666. if windower.dir_exists(basepath) then
  667. for i,v in ipairs(files_list) do
  668. if v ~= '' then
  669. if include_user_path then
  670. user_path = basepath .. include_user_path .. '/' .. v
  671. end
  672. normal_path = basepath .. v
  673.  
  674. if user_path and windower.file_exists(user_path) then
  675. return user_path
  676. elseif normal_path and windower.file_exists(normal_path) then
  677. return normal_path
  678. end
  679. end
  680. end
  681. end
  682. end
  683.  
  684. return false
  685. end
  686.  
  687. -- Much force update
Advertisement
Add Comment
Please, Sign In to add comment