diff --git a/addons/GearSwap/flow.lua b/addons/GearSwap/flow.lua index 1dc929389..67707325d 100644 --- a/addons/GearSwap/flow.lua +++ b/addons/GearSwap/flow.lua @@ -206,7 +206,6 @@ function equip_sets_exit(swap_type, ts, val1) if command_registry[ts].cancel_spell then msg.debugging('Action canceled (' .. storedcommand .. ' ' .. val1.target.raw .. ')') - storedcommand = nil command_registry:delete_entry(ts) return true elseif not ts or not command_registry[ts] or not storedcommand then @@ -216,6 +215,14 @@ function equip_sets_exit(swap_type, ts, val1) if command_registry[ts].new_target then val1.target = command_registry[ts].new_target -- Switch target, if it is requested. + + if val1.prefix == '/item' then + if val1.target.type ~= 'NONE' and bit.band(val1.target.spawn_type, 2) == 2 and find_inventory_item(val1.id) then + val1.action_type = 'Trade' + else + val1.action_type = 'Item' + end + end end if st_targs[val1.target.raw] then @@ -224,62 +231,36 @@ function equip_sets_exit(swap_type, ts, val1) end -- Compose a proposed packet for the given action (this should be possible after pretarget) - if val1.target.id and val1.target.index then + if filter_precast(val1) then if val1.prefix == '/item' then -- Item use packet handling here - if bit.band(val1.target.spawn_type, 2) == 2 and find_inventory_item(val1.id) then + if val1.action_type == 'Trade' then -- 0x36 packet if val1.target.distance <= 6 then command_registry[ts].proposed_packet = assemble_menu_item_packet(val1.target.id, val1.target.index, val1.id) - else - windower.add_to_chat(67, 'Target out of range.') end elseif find_usable_item(val1.id) then -- 0x37 packet command_registry[ts].proposed_packet = assemble_use_item_packet(val1.target.id, val1.target.index, val1.id) end - if not command_registry[ts].proposed_packet then - command_registry:delete_entry(ts) - end - elseif outgoing_action_category_table[unify_prefix[val1.prefix]] then - if filter_precast(val1) then - command_registry[ts].proposed_packet = assemble_action_packet(val1.target.id, val1.target.index, outgoing_action_category_table[unify_prefix[val1.prefix]], val1.id, command_registry[ts].target_arrow) - if not command_registry[ts].proposed_packet then - command_registry:delete_entry(ts) - - msg.debugging('Unable to create a packet for this command because the target is still invalid after pretarget (' .. storedcommand .. ' ' .. val1.target.raw .. ')') - storedcommand = nil - return storedcommand .. ' ' .. val1.target.raw - end - end else - msg.debugging('Hark, what weird prefix through yonder window breaks? ' .. tostring(val1.prefix)) + command_registry[ts].proposed_packet = assemble_action_packet(val1.target.id, val1.target.index, outgoing_action_category_table[unify_prefix[val1.prefix]], val1.id, command_registry[ts].target_arrow) end - end - if ts and command_registry[ts] then - if not val1.target.name then - -- Spells with invalid pass_through_targs, like using without a target - command_registry:delete_entry(ts) - msg.debugging('Change target was used to pick an invalid target (' .. storedcommand .. ' ' .. val1.target.raw .. ')') - local ret = storedcommand .. ' ' .. val1.target.raw - storedcommand = nil - return ret - else - -- Spells with complete target information - -- command_registry[ts] is deleted for cancelled spells + if command_registry[ts].proposed_packet then if command_registry[ts].pretarget_cast_delay == 0 then equip_sets('precast', ts, val1) else - windower.send_command('@wait ' .. command_registry[ts].pretarget_cast_delay .. ';lua i ' .. _addon.name .. ' pretarget_delayed_cast ' .. ts) + equip_sets:schedule(command_registry[ts].pretarget_cast_delay, 'precast', ts, val1) end return true end - elseif not ts or not command_registry[ts] then - msg.debugging('This case should not be hittable - 2') - return true end + msg.debugging('No valid target at end of pretarget (' .. storedcommand .. ' ' .. val1.target.raw .. ')') + command_registry:delete_entry(ts) + return storedcommand .. ' ' .. val1.target.raw + elseif swap_type == 'precast' then -- Update the target_arrow if val1.prefix ~= '/item' then @@ -287,7 +268,6 @@ function equip_sets_exit(swap_type, ts, val1) end return precast_send_check(ts) elseif swap_type == 'filtered_action' and command_registry[ts] and command_registry[ts].cancel_spell then - storedcommand = nil command_registry:delete_entry(ts) return true elseif swap_type == 'midcast' and _settings.demo_mode then @@ -348,31 +328,11 @@ function user_pcall2(str,...) end ------------------------------------------------------------------------------------ ---Name: pretarget_delayed_cast(ts) ---Desc: Triggers an outgoing action packet (if the passed key is valid). ---Args: ----- ts - Timestamp argument to precast_delayed_cast ------------------------------------------------------------------------------------ ---Returns: ----- none ------------------------------------------------------------------------------------ -function pretarget_delayed_cast(ts) - ts = tonumber(ts) - if ts then - equip_sets('precast',ts,command_registry[ts].spell) - else - msg.debugging("Bad index passed to pretarget_delayed_cast") - end -end - - - ----------------------------------------------------------------------------------- --Name: precast_send_check(ts) --Desc: Determines whether or not to send the current packet. -- Cancels if _global.cancel_spell is true --- If command_registry[ts].precast_cast_delay is not 0, cues precast_delayed_cast with the proper +-- If command_registry[ts].precast_cast_delay is not 0, cues send_action with the proper -- delay instead of sending immediately. --Args: ---- ts - key of command_registry @@ -389,7 +349,7 @@ function precast_send_check(ts) send_action(ts) return else - windower.send_command('@wait '..command_registry[ts].precast_cast_delay..';lua i '.._addon.name..' precast_delayed_cast '..ts) + send_action:schedule(command_registry[ts].precast_cast_delay, ts) end end end @@ -397,25 +357,6 @@ function precast_send_check(ts) end ------------------------------------------------------------------------------------ ---Name: precast_delayed_cast(ts) ---Desc: Triggers an outgoing action packet (if the passed key is valid). ---Args: ----- ts - Timestamp argument to precast_delayed_cast ------------------------------------------------------------------------------------ ---Returns: ----- none ------------------------------------------------------------------------------------ -function precast_delayed_cast(ts) - ts = tonumber(ts) - if ts then - send_action(ts) - else - msg.debugging("Bad index passed to precast_delayed_cast") - end -end - - ----------------------------------------------------------------------------------- --Name: send_action(ts) --Desc: Sends the cued action packet, if it exists. diff --git a/addons/GearSwap/gearswap.lua b/addons/GearSwap/gearswap.lua index 29f8a702e..e3ca5e62e 100644 --- a/addons/GearSwap/gearswap.lua +++ b/addons/GearSwap/gearswap.lua @@ -50,6 +50,7 @@ error = _raw.error require 'lists' require 'queues' require 'sets' +require 'sqlite3' windower.text.create = function (str) diff --git a/addons/GearSwap/helper_functions.lua b/addons/GearSwap/helper_functions.lua index 13bfda9a5..f3ce4c95a 100644 --- a/addons/GearSwap/helper_functions.lua +++ b/addons/GearSwap/helper_functions.lua @@ -966,7 +966,7 @@ function get_spell(act) end if act.category == 12 or act.category == 2 then - spell = copy_entry(resources_ranged_attack) + spell = copy_entry(res.ranged_attacks[0]) else if not res.action_messages[msg_ID] or msg_ID == 31 then if act.category == 4 or act.category == 8 then @@ -1095,6 +1095,30 @@ function spell_complete(rline) return rline end +----------------------------------------------------------------------------------- +--Name: find_monster_skill(abil) +--Desc: Takes a monster ability name and finds the corresponding monster_skills +-- resource line for the player's current species +--Args: +---- abil - ability name +----------------------------------------------------------------------------------- +--Returns: +---- rline - resource line +----------------------------------------------------------------------------------- +function find_monster_skill(abil) + local rline = false + if player.species and player.species.tp_moves then + -- Iterates over currently available monster TP moves instead of using validabils + for i, v in pairs(player.species.tp_moves) do + if res.monster_skills[i][language]:lower() == abil then + rline = copy_entry(res.monster_skills[i]) + break + end + end + end + return rline +end + ----------------------------------------------------------------------------------- --Name: logit() --Args: diff --git a/addons/GearSwap/packet_parsing.lua b/addons/GearSwap/packet_parsing.lua index 0cadd9c6c..3c006e881 100644 --- a/addons/GearSwap/packet_parsing.lua +++ b/addons/GearSwap/packet_parsing.lua @@ -96,6 +96,8 @@ end parse.i[0x00B] = function(data) -- Blank temporary items when zoning. items.temporary = make_inventory_table() + if bag_tables then bag_tables.temporary = make_bag_table() end + if player then player.temporary = bag_tables and bag_tables.temporary or make_bag_table() end end parse.i[0x00E] = function (data) @@ -141,6 +143,8 @@ parse.i[0x01E] = function (data) local count = data:unpack('I',5) local status = data:byte(0x0B) if not items[bag][slot] then items[bag][slot] = make_empty_item_table(slot) end + local old_id = items[bag][slot].id or 0 + local old_count = items[bag][slot].count or 0 items[bag][slot].count = count items[bag][slot].status = status if count == 0 then @@ -148,26 +152,33 @@ parse.i[0x01E] = function (data) items[bag][slot].bazaar = 0 items[bag][slot].status = 0 end + update_item_slot(bag, old_id, old_count, items[bag][slot]) end parse.i[0x01F] = function (data) local bag = to_windower_compact(res.bags[data:byte(0x0B)].english) local slot = data:byte(0x0C) if not items[bag][slot] then items[bag][slot] = make_empty_item_table(slot) end + local old_id = items[bag][slot].id or 0 + local old_count = items[bag][slot].count or 0 items[bag][slot].id = data:unpack('H',9) items[bag][slot].count = data:unpack('I',5) items[bag][slot].status = data:byte(0x0D) + update_item_slot(bag, old_id, old_count, items[bag][slot]) end parse.i[0x020] = function (data) local bag = to_windower_compact(res.bags[data:byte(0x0F)].english) local slot = data:byte(0x10) if not items[bag][slot] then items[bag][slot] = make_empty_item_table(slot) end + local old_id = items[bag][slot].id or 0 + local old_count = items[bag][slot].count or 0 items[bag][slot].id = data:unpack('H',0x0D) items[bag][slot].count = data:unpack('I',5) items[bag][slot].bazaar = data:unpack('I',9) items[bag][slot].status = data:byte(0x11) items[bag][slot].extdata = data:sub(0x12,0x29) + update_item_slot(bag, old_id, old_count, items[bag][slot]) -- Did not mess with linkshell stuff end @@ -481,7 +492,7 @@ parse.i[0x063] = function (data) newbuffs[n].matched_exactly = nil for i,old in pairs(_ExtraData.player.buff_details) do -- Find unchanged buffs - if old.id == new.id and math.abs(old.time-new.time) < 1 and not old.matched_exactly then + if old.id == new.id and math.abs(old.time-new.time) < (old.duration < 6 and 4 or 1) and not old.matched_exactly then newbuffs[n].matched_exactly = true _ExtraData.player.buff_details[i].matched_exactly = true break diff --git a/addons/GearSwap/refresh.lua b/addons/GearSwap/refresh.lua index c39ef2290..777b76fed 100644 --- a/addons/GearSwap/refresh.lua +++ b/addons/GearSwap/refresh.lua @@ -337,7 +337,12 @@ function refresh_player(dt,user_event_flag) -- Assign player.inventory to be keyed to item.inventory[i][language] and to have a value of count, similar to buffactive for i,bag in pairs(res.bags) do local bag_name = to_windower_bag_api(bag.en) - if items[bag_name] then player[bag_name] = refresh_item_list(items[bag_name]) end + if items[bag_name] then + if not bag_tables[bag_name] then + bag_tables[bag_name] = refresh_item_list(items[bag_name]) + end + player[bag_name] = bag_tables[bag_name] + end end -- Monster tables for the target and subtarget. @@ -599,6 +604,39 @@ function convert_buff_list(bufflist) return buffarr end +----------------------------------------------------------------------------------- +-- Read-only Metatables for Bags and Item Entries +----------------------------------------------------------------------------------- +read_only_entry_mt = { + __index = function(t, k) + local data = rawget(t, '__data') + return data and data[k] + end, + __newindex = function(t, k, v) + error('GearSwap: Cannot modify read-only item data ("'..tostring(k)..'")', 2) + end, + __pairs = function(t) + return pairs(rawget(t, '__data') or {}) + end +} + +function make_read_only_entry(data) + return setmetatable({__data = data}, read_only_entry_mt) +end + +bag_user_data_table = { + __newindex = function(tab, key, val) + error('GearSwap: Cannot modify read-only inventory bag table ("'..tostring(key)..'")', 2) + end, + __index = function(tab, key) + return rawget(tab, user_key_filter(key)) + end +} + +function make_bag_table() + return setmetatable({}, bag_user_data_table) +end + ----------------------------------------------------------------------------------- --Name: refresh_item_list(itemlist) --Args: @@ -619,7 +657,7 @@ end ---- It also allows one to check for the alternate spelling of an item. ----------------------------------------------------------------------------------- function refresh_item_list(itemlist) - local retarr = make_user_table() + local retarr = make_bag_table() for i,v in pairs(itemlist) do if type(v) == 'table' and v.id and v.id ~= 0 then local item = res.items[v.id] @@ -631,20 +669,22 @@ function refresh_item_list(itemlist) -- If there's already an entry for this item, all the hard work has already -- been done. Just update the count on the subtable of the main item, and -- everything else will link together. - entry.count = entry.count + v.count + local raw_entry = (type(entry) == 'table' and rawget(entry, '__data')) or entry + raw_entry.count = raw_entry.count + v.count else local lower_item_name = item_name:lower() - local new_entry = table.copy(v) - new_entry.shortname=lower_item_name - retarr[item_name] = new_entry + local raw_data = table.copy(v) + raw_data.shortname = lower_item_name + local new_entry = make_read_only_entry(raw_data) + rawset(retarr, user_key_filter(item_name), new_entry) -- If a long version of the name exists, and is different from the short version, -- add the long name to the info table and point the long name's key at that table. local long_item_name = item[language..'_log'] local lower_long_item_name = long_item_name and long_item_name:lower() if lower_long_item_name and lower_long_item_name ~= lower_item_name then - new_entry.longname = lower_long_item_name - retarr[long_item_name] = new_entry + raw_data.longname = lower_long_item_name + rawset(retarr, user_key_filter(long_item_name), new_entry) end end end @@ -653,6 +693,99 @@ function refresh_item_list(itemlist) return retarr end +----------------------------------------------------------------------------------- +--Name: update_item_slot(bag, old_id, old_count, new_slot_data) +--Args: +---- bag (string): Bag name (e.g. 'inventory') +---- old_id (number): Previous item id in the slot +---- old_count (number): Previous item count in the slot +---- new_slot_data (table): Current slot table from items[bag][slot] +----------------------------------------------------------------------------------- +function update_item_slot(bag, old_id, old_count, new_slot_data) + if not bag_tables[bag] then + if items[bag] then + bag_tables[bag] = refresh_item_list(items[bag]) + else + bag_tables[bag] = make_bag_table() + end + end + local target_bag = bag_tables[bag] + local new_id = new_slot_data and new_slot_data.id or 0 + local new_count = new_slot_data and new_slot_data.count or 0 + + if old_id == new_id then + local delta = new_count - old_count + if delta ~= 0 and old_id ~= 0 then + local item = res.items[old_id] + local item_name = item and item[language] + if item_name and target_bag[item_name] then + local entry = target_bag[item_name] + local raw_entry = (type(entry) == 'table' and rawget(entry, '__data')) or entry + raw_entry.count = raw_entry.count + delta + if raw_entry.count <= 0 then + rawset(target_bag, user_key_filter(item_name), nil) + local long_name = item[language..'_log'] + if long_name and long_name ~= item_name then + rawset(target_bag, user_key_filter(long_name), nil) + end + end + elseif item_name and delta > 0 then + local lower_item_name = item_name:lower() + local raw_data = table.copy(new_slot_data) + raw_data.shortname = lower_item_name + local new_entry = make_read_only_entry(raw_data) + rawset(target_bag, user_key_filter(item_name), new_entry) + local long_item_name = item[language..'_log'] + local lower_long_item_name = long_item_name and long_item_name:lower() + if lower_long_item_name and lower_long_item_name ~= lower_item_name then + raw_data.longname = lower_long_item_name + rawset(target_bag, user_key_filter(long_item_name), new_entry) + end + end + end + else + if old_id ~= 0 and old_count > 0 then + local old_item = res.items[old_id] + local old_name = old_item and old_item[language] + if old_name and target_bag[old_name] then + local entry = target_bag[old_name] + local raw_entry = (type(entry) == 'table' and rawget(entry, '__data')) or entry + raw_entry.count = raw_entry.count - old_count + if raw_entry.count <= 0 then + rawset(target_bag, user_key_filter(old_name), nil) + local old_long = old_item[language..'_log'] + if old_long and old_long ~= old_name then + rawset(target_bag, user_key_filter(old_long), nil) + end + end + end + end + if new_id ~= 0 and new_count > 0 then + local new_item = res.items[new_id] + local new_name = new_item and new_item[language] + if new_name then + local entry = target_bag[new_name] + if entry then + local raw_entry = (type(entry) == 'table' and rawget(entry, '__data')) or entry + raw_entry.count = raw_entry.count + new_count + else + local lower_item_name = new_name:lower() + local raw_data = table.copy(new_slot_data) + raw_data.shortname = lower_item_name + local new_entry = make_read_only_entry(raw_data) + rawset(target_bag, user_key_filter(new_name), new_entry) + local long_item_name = new_item[language..'_log'] + local lower_long_item_name = long_item_name and long_item_name:lower() + if lower_long_item_name and lower_long_item_name ~= lower_item_name then + raw_data.longname = lower_long_item_name + rawset(target_bag, user_key_filter(long_item_name), new_entry) + end + end + end + end + end +end + ----------------------------------------------------------------------------------- --Name: refresh_user_env() --Args: diff --git a/addons/GearSwap/statics.lua b/addons/GearSwap/statics.lua index e30609390..c87eb8d5e 100644 --- a/addons/GearSwap/statics.lua +++ b/addons/GearSwap/statics.lua @@ -194,6 +194,7 @@ equip_list_history = {} world = make_user_table() buffactive = make_user_table() alliance = make_user_table() +bag_tables = {} st_targs = {['']=true,['']=true,['']=true,['']=true,['']=true} st_flag = false current_file = nil diff --git a/addons/GearSwap/triggers.lua b/addons/GearSwap/triggers.lua index e3e54d8f5..27bb062bb 100644 --- a/addons/GearSwap/triggers.lua +++ b/addons/GearSwap/triggers.lua @@ -59,7 +59,7 @@ windower.register_event('outgoing text', function(original, modified) return modified end - local abil + local abil, r_line local r_name = res_prefix_map[unified_prefix] local targ = splitline[3] if unified_prefix == '/ra' then @@ -99,23 +99,6 @@ windower.register_event('outgoing text', function(original, modified) refresh_globals() - local r_line, find_monster_skill - - function find_monster_skill(abil) - local line = false - if player.species and player.species.tp_moves then - -- Iterates over currently available monster TP moves instead of using validabils - for i, v in pairs(player.species.tp_moves) do - if res.monster_skills[i][language]:lower() == abil then - line = copy_entry(res.monster_skills[i]) - break - end - end - end - return line - end - - if unified_prefix == '/ms' then r_line = find_monster_skill(abil) else @@ -135,7 +118,7 @@ windower.register_event('outgoing text', function(original, modified) spell.target = temp_mob_arr spell.action_type = action_type_map[command] - if spell.prefix == '/item' and spell.target.type ~= 'NONE' and bit.band(spell.target.spawn_type, 2) == 2 then + if spell.prefix == '/item' and spell.target.type ~= 'NONE' and bit.band(spell.target.spawn_type, 2) == 2 and find_inventory_item(spell.id) then spell.action_type = 'Trade' end @@ -152,13 +135,10 @@ windower.register_event('outgoing text', function(original, modified) if spell.prefix == '/item' then -- Item use packet handling here - if spell.action_type == 'Trade' and find_inventory_item(spell.id) then + if spell.action_type == 'Trade' then --0x36 packet if spell.target.distance <= 6 then command_registry[ts].proposed_packet = assemble_menu_item_packet(spell.target.id, spell.target.index, spell.id) - else - windower.add_to_chat(67, 'Target out of range.') - return true end elseif find_usable_item(spell.id) then --0x37 packet @@ -168,10 +148,11 @@ windower.register_event('outgoing text', function(original, modified) command_registry[ts].proposed_packet = assemble_action_packet(spell.target.id, spell.target.index, outgoing_action_category_table[unify_prefix[spell.prefix]], spell.id, initialize_arrow_offset(spell.target)) end - -- The packets created above should not be used. if command_registry[ts].proposed_packet then equip_sets('precast', ts, spell) return true + else + command_registry:delete_entry(ts) end end diff --git a/addons/Logger/Logger.lua b/addons/Logger/Logger.lua index c38de0bde..58e631b85 100644 --- a/addons/Logger/Logger.lua +++ b/addons/Logger/Logger.lua @@ -47,7 +47,9 @@ windower.register_event('incoming text', function(_, text, _, _, blocked) local time = os.time() refresh_file(time) - local formatted = text:strip_colors() + local formatted = windower.from_shift_jis( + windower.convert_auto_trans(text):strip_colors() + ):match('^(.-)%s*$') if settings.AddTimestamp then file:append(('%s %s\n'):format(os.date(settings.TimestampFormat, time), formatted)) else @@ -77,4 +79,4 @@ Redistribution and use in source and binary forms, with or without modification, 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -]] \ No newline at end of file +]] diff --git a/addons/libs/packets/fields.lua b/addons/libs/packets/fields.lua index 0fdbec6ad..6f98dfd28 100644 --- a/addons/libs/packets/fields.lua +++ b/addons/libs/packets/fields.lua @@ -3171,7 +3171,7 @@ func.incoming[0x063][0x03] = L{ {ctype='unsigned short', label='_unknown2'}, -- 0E 00 00 {ctype='unsigned short', label='_unknown3'}, -- 10 76 00 {ctype='unsigned short', label='Infamy'}, -- 12 - {ctype='unsigned int', label='_unknown4'}, -- 14 00s + {ctype='unsigned int', label='Prestige'}, -- 14 {ctype='unsigned int', label='_unknown5'}, -- 18 00s {ctype='data[64]', label='Instinct Bitfield 1'}, -- 1C See below -- Bitpacked 2-bit values. 0 = no instincts from that species, 1 == first instinct, 2 == first and second instinct, 3 == first, second, and third instinct. diff --git a/addons/linuxfix/linuxfix.lua b/addons/linuxfix/linuxfix.lua deleted file mode 100644 index bc29feede..000000000 --- a/addons/linuxfix/linuxfix.lua +++ /dev/null @@ -1,143 +0,0 @@ -_addon.name = 'linuxfix' -_addon.version = '0.5.0' -_addon.author = 'Rubenator,Surik,BeYoNDLiFe' - ---[[ - Do not bother using this if you are on Windows. - - This addon will need to be autoloaded via your init. - - This code has only been tested with fairly standard en-US keyboards. - - This addon restores full keyboard functionality in Windower with newer versions of Wine and bypasses the need to build your own version of Wine with a specific commit reverted. - It also remaps Windows key bindings and makes them functional again with the exception of bindings with multiple modifiers such as %^!1 (Ctrl+Super+Alt+1). The listbinds command is only capable of returning a single modifier and thus they cannot be remapped correctly. - It reads and parses the content of the 'listbinds' command anytime it runs and forwards the keys as appropriate to the client. It also hides the output of this command to avoid console spam. - It's not a fix since it doesn't actually repair the original issue of the keybinds using raw keyboard input but it does work nicely as a workaround. - - When there are a left and right version of a key such as lctrl and rctrl windower sends the lctrl dik even when the right key has been pressed. This also applies to enter and numpadenter. - While the correct keys are in the table below, windower will just use the left version. - - For lack of a better method of keeping the keybinds up to date, the list is refreshed every time you press a key. This was done because Gearswap files frequently rebind keys between jobs. - Since this caused significant lag, a limit was placed so it could not run more than once per second. This limit can be modified using the 'check_rate' variable. - The binds are also now added to a table and don't have to be parsed everytime you press a key which has reduced overhead as well. - - Big shoutout and thanks to Rubenator, he took the awful code Surik and BeYoNDLiFe gave him and made it so much better. -]]-- - -check_rate = 1 - -require('luau') -mods = S{} -keybinds = {} -last_state = T{} -local dik_lookup = T{[-1]='sysrq', [1]='escape', [2]='1', [3]='2', [4]='3', [5]='4', [6]='5', [7]='6', [8]='7', [9]='8', [10]='9', [11]='0', [12]='-', [13]='=', [14]='backspace', [15]='tab', [16]='q', [17]='w', [18]='e', [19]='r', [20]='t', [21]='y', [22]='u', [23]='i', [24]='o', [25]='p', [26]='[', [27]=']', [28]='enter', [30]='a', [31]='s', [32]='d', [33]='f', [34]='g', [35]='h', [36]='j', [37]='k', [38]='l', [39]="\\;", [40]="'", [41]='`', [43]='\\\\', [44]='z', [45]='x', [46]='c', [47]='v', [48]='b', [49]='n', [50]='m', [51]=',', [52]='.', [53]='/', [54]='rshift', [55]='numpad*', [57]='space', [58]='capslock', [59]='f1', [60]='f2', [61]='f3', [62]='f4', [63]='f5', [64]='f6', [65]='f7', [66]='f8', [67]='f9', [68]='f10', [69]='numlock', [70]='scrolllock', [71]='numpad7', [72]='numpad8', [73]='numpad9', [74]='numpad-', [75]='numpad4', [76]='numpad5', [77]='numpad6', [78]='numpad+', [79]='numpad1', [80]='numpad2', [81]='numpad3', [82]='numpad0', [83]='numpad.', [86]='oem_102', [87]='f11', [88]='f12', [100]='f13', [101]='f14', [102]='f15', [112]='kana', [115]='abnt_c1', [121]='convert', [123]='noconvert', [125]='yen', [126]='abnt_c2', [141]='numpadequals', [145]='at', [146]='colon', [147]='underline', [148]='kanji', [149]='stop', [150]='ax', [151]='unlabeled', [153]='nexttrack', [156]='numpadenter', [157]='rctrl', [160]='mute', [161]='calculator', [162]='playpause', [164]='mediastop', [174]='volumedown', [176]='volumeup', [178]='webhome', [179]='numpadcomma', [181]='numpad/', [183]='sysrq', [184]='rmenu', [197]='pause', [199]='home', [200]='up', [201]='pageup', [203]='left', [205]='right', [207]='end', [208]='down', [209]='pagedown', [210]='insert', [211]='delete', [220]='rwin', [222]='power', [223]='sleep', [227]='wake', [229]='websearch', [230]='webfavorites', [231]='webrefresh', [232]='webstop', [233]='', [234]='webback', [235]='mycomputer', [236]='mail', [237]='mediaselect'} -local mod_lookup = T{[29]='Ctrl', [42]='Shift', [56]='Alt', [219]='Win', [221]='Apps'} -key_lookup = T{} -name_lookup = T{} -last_update = nil -do - key_lookup:update(dik_lookup:map(function(name) return {name=name} end)) - key_lookup:update(mod_lookup:map(function(name) return {name=name, mod=true} end)) - for dik, data in pairs(key_lookup) do - name_lookup[data.name] = {mod=data.mod, dik=dik} - end -end - -windower.register_event('keyboard',function(dik,pressed) - if pressed == last_state[dik] then return end - last_state[dik] = pressed - local key_data = key_lookup[dik] - if not key_data then return end - if key_data.mod then - if pressed then - mods:add(key_data.name) - else - mods:remove(key_data.name) - end - send_key_state(key_data, pressed) - elseif pressed then - if not last_update or os.clock() - last_update > check_rate then - windower.send_command('listbinds') - end - local command = check_bind(key_data) - if command then - windower.send_command(command) - else - send_key_state(key_data, pressed) - end - else - send_key_state(key_data, pressed) - end -end) - -function check_bind(key_data) - local binds = keybinds[key_data.name] - if not binds then return false end - local info = windower.ffxi.get_info() - local chat_open = info and info.chat_open - --if chat_open == nil then return false end - binds = binds:filter(function(bind) - return (bind.chat_state == nil or chat_open and bind.chat_state == 'ChatOnly' or not chat_open) and (bind.mods:length() == bind.mods:intersection(mods):length()) - end) - local number_of_binds = binds:length() - if number_of_binds == 0 then - return false - else - return binds:first().command - end -end - -function send_key_state(key_data, pressed) - windower.send_command('setkey %s %s':format(key_data.name, pressed and "down" or "up")) -end - -windower.register_event('incoming text', function(original, modified, color, color_m, blocked) - if color ~= 141 then return end - if ListBinds then - if original == '===== Done Listing Currently Bound Keys =====' then - ListBinds = false - for _,binds in pairs(new_keybinds) do - binds:sort(function(a,b) return a.mods:length() > b.mods:length() end) - end - keybinds = new_keybinds - else - add_bind(original) - end - return true - elseif original == '===== Listing Currently Bound Keys =====' then - last_update = os.clock() - new_keybinds = {} - ListBinds = true - return true - end -end) - -local chat_states = {['(NoChat)']='NoChat', ['(ChatOnly)']='ChatOnly'} -function add_bind(original) - local bind, command = original:match('^([^:]*): (.*)$') - if not bind or not command then return end - bind = bind:gsub('^%-', 'minus'):gsub('%-%-', '-minus') - parts = bind:split('-'):map(string.gsub-{'minus', '-'}) - local chat_state, key - local mods = S{} - for _,part in pairs(parts) do - if chat_states[part] then - chat_state = chat_states[part] - elseif part ~= '' then - local key_data = name_lookup[part] - if key_data then - if key_data.mod then - mods:add(part) - else - key = part - end - end - end - end - if not new_keybinds[key] then - new_keybinds[key] = L{} - end - new_keybinds[key]:append({key=key, mods=mods, chat_state=chat_state, command=command}) -end - -windower.send_command('listbinds') diff --git a/addons/send/send.lua b/addons/send/send.lua index 65ee82b33..99f715f56 100644 --- a/addons/send/send.lua +++ b/addons/send/send.lua @@ -1,4 +1,4 @@ -_addon.version = '1.3' +_addon.version = '1.4' _addon.name = 'Send' _addon.command = 'send' _addon.author = 'Byrth, Lili' @@ -39,20 +39,20 @@ windower.register_event('addon command', function(target, ...) if player and target == player['name']:lower() then execute_command(command) return - elseif target == '@all' then + elseif target == '@all' or target == '@a' then execute_command(command) elseif player and target == '@'..player.main_job:lower() then execute_command(command) - elseif target == '@party' then + elseif target == '@party' or target == '@p' then if player then execute_command(command) end - target = target .. player.name - elseif target == '@zone' then + target = '@party' .. player.name + elseif target == '@zone' or target == '@z' then if player then execute_command(command) end - target = target .. windower.ffxi.get_info().zone + target = '@zone' .. windower.ffxi.get_info().zone end command = 'send ' .. target .. ' ' .. command @@ -77,7 +77,7 @@ windower.register_event('ipc message', function (msg) local target = split[2] local command = split[3] - if target == '@all' or target == '@others' then + if target == '@all' or target == '@others' or target == '@o' or target == '@a' then execute_command(command) return end