Windower / Lua

Lua Addons and Scripts
242 stars 429 forks source link

event_outgoing_chunk() #498

Closed Byrth closed 11 years ago

Byrth commented 11 years ago

Returning true does not seem to block packets. I tested this by sending a /tell to myself and trying to block the packet with this code:

windower.register_event('outgoing chunk',function(id,original,modified,injected,is_blocked) if id == 0xB6 then a,b = string.find(original,'Result:') add_to_chat(8,tostring(a)) return true end end)

The tell still went through even though the add_to_chat worked.

z16 commented 11 years ago

Fixed.

shastaxc commented 3 years ago

I'm having this same problem. I am unable to block the outgoing packet by returning true. Finding documentation on how to block packets is incredibly difficult. Is this the correct way to block a packet?

joshk6656 commented 3 years ago

Post what you are doing to try to block the packet. My guess is you aren't selecting your packet correctly and it is never hitting your return true. Add a print to verify that the your statement is actually getting hit.

shastaxc commented 3 years ago

This is what I'm doing. Trying to detect a WS use, calculate if enemy is out of range, and cancel the packet if it is out of range.

-- Intercept outgoing ws action packets and cancel if out of range
windower.register_event('outgoing chunk', function(id, data, modified, injected, blocked)
  if id == 0x01A then -- Send action command to the server
    local packet = packets.parse('outgoing', data)
    local category = packet.Category -- Type of ability (WS is 7)

    -- We only care about WS actions (category 7)
    if category == 7 then
      local ws_id = packet.Param -- WS ID
      local targetId = packet.Target -- Target ID

      local ws = res.weapon_skills[ws_id]
      local player = windower.ffxi.get_mob_by_target('me')
      local target = windower.ffxi.get_mob_by_id(targetId)

      -- If not valid WS, block packet
      -- Invalid conditions:
      --    Player is targeting self with WS
      --    Attempting to WS while out of range of target
      if player.id == targetId then
        return true
      end
      if isOutOfRange(ws.range, player, target) then
        windower.add_to_chat(167, 'Stopping WS. Target out of range.')
        return true
      end
    end
  end
end)

The chat will correctly display "Stopping WS. Target out of range." in game under the correct conditions, but the WS action still goes through.

joshk6656 commented 3 years ago

Looks good to me, I would check to see if something down the line is actually injecting the weapon skill.

Gearswap would come to mind.

Also, this functionality could easily be added to gearswap using cancel_spell()

shastaxc commented 3 years ago

You're right... It looks like gearswap is the culprit. Unloading gearswap allows my app to properly block the outgoing packet. Thanks for the insight.

joshk6656 commented 3 years ago

Yep, you can fix this by loading them in a different order (I think)

Unload both, and load Your addon then gearswap. If that doesnt work unload both, then load gearswap and then your addon (i think this is the order you want).

Or, just incorporate this check into gearswap.

shastaxc commented 3 years ago

Neither of these options work. I was hoping to have this as a standalone addon but I guess I will implement it into gearswap instead.

joshk6656 commented 3 years ago

The last thing I can think of is also monitoring outgoing text for /ws commands.

A quick test would just be printing all outgoing text to see if you see a /ws command. If so return true those as well.

shastaxc commented 3 years ago

At your suggestion, I tried that method as well, and it had the same result... WS still went through. Here's the code I tried:


windower.register_event('outgoing text',function(original,modified,blocked,ffxi,extra_stuff,extra2)
  local splitStr = split_string(original, ' ')
  if splitStr[1] == '/ws' or splitStr[1] == '/weaponskill' then
    windower.add_to_chat(001, original)
    return true
  end
end)

function split_string(inputstr, sep)
  if sep == nil then
    sep = "%s"
  end

  local t={}
  for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
    table.insert(t, str)
  end

  return t
end
joshk6656 commented 3 years ago

Did you do both together? Monitoring outgoing chunk and outgoing text and returning true on both?

shastaxc commented 3 years ago

Yes I had both running and attempting to block.

joshk6656 commented 3 years ago

I'm out of ideas for you, I would hop in the windower discord and see if anyone else has ideas.

shastaxc commented 3 years ago

According to some folks from the Windower discord, it seems that addons don't really coordinate blocking of packets. So even though I attempted to block it with my addon, gearswap was still sending it through. I ended up nixing my addon and adding in the functionality to gearswap as a library instead.