--[[ * Ashita - Copyright (c) 2014 - 2016 atom0s [atom0s@live.com] * * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. * * By using Ashita, you agree to the above license and its terms. * * Attribution - You must give appropriate credit, provide a link to the license and indicate if changes were * made. You must do so in any reasonable manner, but not in any way that suggests the licensor * endorses you or your use. * * Non-Commercial - You may not use the material (Ashita) for commercial purposes. * * No-Derivatives - If you remix, transform, or build upon the material (Ashita), you may not distribute the * modified material. You are, however, allowed to submit the modified works back to the original * Ashita project in attempt to have it added to the original project. * * You may not apply legal terms or technological measures that legally restrict others * from doing anything the license permits. * * No warranties are given. ]]-- _addon.author = 'atom0s'; _addon.name = 'filterscan'; _addon.version = '3.0.0'; require 'common' require 'mobparse' --------------------------------------------------------------------------------------------------- -- Variables --------------------------------------------------------------------------------------------------- local FilterScan = { FFXiPath = ashita.file.get_install_dir(0, 1) .. '\\', MobList = { }, ZoneDatList = require('zonemoblist'), Filter = '' }; --------------------------------------------------------------------------------------------------- -- func: UpdateZoneMobList -- desc: Updates the zone mob list. --------------------------------------------------------------------------------------------------- local function UpdateZoneMobList(zoneId) -- Attempt to get the dat file for this entry.. local dat = FilterScan.ZoneDatList[zoneId]; if (dat == nil) then FilterScan.MobList = { }; return false; end -- Attempt to parse the dat file.. FilterScan.MobList = ParseZoneMobDat(FilterScan.FFXiPath .. dat); return true; end --------------------------------------------------------------------------------------------------- -- func: MobNameFromTargetIndex -- desc: Returns the mob name from the given target index. --------------------------------------------------------------------------------------------------- local function MobNameFromTargetIndex(targetIndex) if (FilterScan.MobList == nil) then return nil; end for _, v in pairs(FilterScan.MobList) do if (v[1] == targetIndex) then return v[2]; end end return nil; end ---------------------------------------------------------------------------------------------------- -- func: load -- desc: Event called when the addon is being loaded. ---------------------------------------------------------------------------------------------------- ashita.register_event('load', function() -- Parse the players current zone if we are in-game.. if (AshitaCore:GetDataManager():GetParty():GetMemberActive(0) > 0) then local zoneId = AshitaCore:GetDataManager():GetParty():GetMemberZone(0); UpdateZoneMobList(zoneId); print('Loaded zone mobs.') end end); ---------------------------------------------------------------------------------------------------- -- func: command -- desc: Event called when a command was entered. ---------------------------------------------------------------------------------------------------- ashita.register_event('command', function(command, ntype) -- Ensure we should handle this command.. local args = command:args(); if (args[1] ~= '/filterscan') then return false; end -- Pull the filter from the command.. FilterScan.Filter = (string.gsub(command, '/filterscan', '')):trim() print(string.format('[FilterScan] Set new filter to: %s', FilterScan.Filter)); return true; end); --------------------------------------------------------------------------------------------------- -- func: incoming_packet -- desc: Called when our addon receives an incoming packet. --------------------------------------------------------------------------------------------------- ashita.register_event('incoming_packet', function(id, size, data) -- Check for zone-in packets.. if (id == 0x0A) then -- Are we zoning into a mog house.. if (struct.unpack('b', data, 0x80 + 1) == 1) then return false; end -- Pull the zone id from the packet.. local zoneId = struct.unpack('H', data, 0x30 + 1); if (zoneId == 0) then zoneId = struct.unpack('H', data, 0x42 + 1); end -- Update our mob list.. UpdateZoneMobList(zoneId); end -- Handle incoming widescan result packets.. if (id == 0xF4) then local targetIndex = struct.unpack('H', data, 0x04 + 1); local mobName = MobNameFromTargetIndex(targetIndex); if (mobName == nil) then return false; else -- Filter by name.. if (mobName:lower():find(FilterScan.Filter:lower()) ~= nil) then return false; end -- Filter by target index.. if (targetIndex == tonumber(FilterScan.Filter, 16)) then return false; end if (tostring(targetIndex) == FilterScan.Filter) then return false; end -- Ignore all non-matching entries.. return true; end -- This should never happen here.. return true; end return false; end);