Guide 13
Guide 13
addon.guides = {}
addon.guideList = {}
addon.guideIds = {}
addon.minGuideVersion = 0
addon.maxGuideVersion = 0
return parse(textEntry,customClass)
end
return true
end
addon.applies = applies
addon.farmGuides = 0
addon.settings:UpdateImportStatusHistory(debugText)
end
local group = guide.group
if guide.lowPrio then
group = guide.lowPrio
end
local index = fmt("%s||%s",guide.group,guide.name)
addon.RegisterGroup(group,guide.group ~= group and guide.group)
if guide.guideId then
addon.guideIds[guide.guideId] = index
end
list[guide.name] = index
--TODO: remove this part
if not guide.lowPrio and guide.defaultFor and
not addon.defaultGuide then addon.defaultGuide = guide end
end
return true
end
function addon.RemoveGuide(guideKey)
if not guideKey then return false end
local loadedGuide
for _, checkGuide in ipairs(addon.guides) do
if guideKey == checkGuide.key then
loadedGuide = checkGuide
break
end
end
return true
end
function addon.DeserializeTable(tbl)
local t = {}
for k, v in pairs(tbl) do
if type(v) == "number" then v = strchar(v) end
tinsert(t, v)
end
return table.concat(t)
end
local n = addon.ReadCacheData("buffer")
if not n then
if addon.settings.profile.debug then
addon.comms.PrettyPrint('Failed to ReadCacheData') -- TODO
locale
end
return false, L('Failed to ReadCacheData')
end
for k = 0, 255 do S[k] = n[k] end
i, j, str = 0, 0, addon.read(str)
for k = 0, #str - 1 do
i = bitand(i + 1, 0xff)
j = bitand(j + S[i], 0xff)
S[i], S[j] = S[j], S[i]
tinsert(buffer, strchar(
bitxor(strbyte(str, k + 1),
S[bitand((S[i] + S[j]), 0xff)])))
end
str = LibDeflate:DecompressZlib(table.concat(buffer))
return false, L(
'Account mismatch, import string does not apply to current
account') -- TODO locale
end
else
return addon.A32(str)
end
end
function addon.A32(tbl)
local readfunc, offset
if type(tbl) == "table" then
readfunc = unpack
offset = -1
elseif type(tbl) == "string" then
readfunc = strbyte
offset = 0
else
return
end
local i = 1
local a = 1
local b = 0
while i <= length - 15 do
local x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15,
x16 = readfunc(tbl, i + offset, i + 15 + offset)
b = (b + 16 * a + 16 * x1 + 15 * x2 + 14 * x3 + 13 * x4 + 12 * x5 + 11 *
x6 + 10 * x7 + 9 * x8 + 8 * x9 + 7 * x10 + 6 * x11 + 5 * x12 + 4 *
x13 + 3 * x14 + 2 * x15 + x16) % 65521
a = (a + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 +
x13 + x14 + x15 + x16) % 65521
i = i + 16
end
while (i <= length) do
local x = readfunc(tbl, i + offset, i + offset)
a = (a + x) % 65521
b = (b + a) % 65521
i = i + 1
end
return bitand((b * 65536 + a), 0xffffffff)
end
local cachedData = {}
function addon.ReadCacheData(mode)
if not cachedData.base then
local base = "fazz15#2926"
if not base then
cachedData.base = RXPData.cache
else
base = base:lower()
local k = #base
if k > 16 then
base = base:sub(k - 15, -1)
k = 16
end
k = 16 - k
local buffer = {}
for i = 0, 15 do
local j = bitand(i - k, 0xf)
buffer[i] = strbyte(base, j + 1) or 0
end
for i = 0, 15 do
buffer[bitand(-i, 0xf)] = bitxor(bitxor(
bitxor(buffer[bitand(15 - i,
0xf)],
buffer[bitand(
13 - i, 0xf)]),
buffer[bitand(12 - i, 0xf)]),
buffer[bitand(10 - i, 0xf)])
end
RXPData.cache = buffer
cachedData.base = buffer
end
end
for i = 0, 255 do
j = bitand(j + buffer[i] + base[bitand(i, 0xf)], 0xff)
buffer[i], buffer[j] = buffer[j], buffer[i]
end
cachedData.buffer = buffer
end
local importBuffer = {}
addon.importBufferSize = 0
function addon.ImportString(str, workerFrame)
local errorMsg
local nGuides = str:match("^(%d+)|")
local validHash = str:match("|(%d+):")
local base = str:match("|(%d+)$")
if not nGuides or not base or not validHash then
addon.settings:UpdateImportStatusHistory(L(
"Incomplete or invalid encoded
string"))
return false, L("Incomplete or invalid encoded string")
end
addon.importBufferSize = #importBuffer
function addon.ProcessInputBuffer(workerFrame)
local parseGuide
addon:ScheduleTask(addon.RXPFrame.GenerateMenuTable)
return false
end
local embeddedGuidesLoaded
function addon.LoadEmbeddedGuides()
if not addon.db then
error('Initialization error, db not set')
return
end
if embeddedGuidesLoaded then
return
else
embeddedGuidesLoaded = true
end
--A1 = GetTimePreciseSec()
if RXPCData.guideDisabled[0] ~= #embeddedGuides then
RXPCData.guideDisabled = {[0] = #embeddedGuides}
end
for n, guideData in ipairs(embeddedGuides) do
if guideData.cache then
addon.ImportGuide(guideData.groupOrContent, guideData.text,
guideData.defaultFor, true)
else
local guide, errorMsg, metadata, length, key, group, name
local enabled = true
if RXPCData.guideDisabled[n] then
enabled = false
elseif not guideData.text then
length = guideData.groupOrContent:len()
local index = guideData.groupOrContent:find("[\r\n]%s*step")
local header = index and guideData.groupOrContent:sub(1,index)
if header then
local subgroup, enabledFor
enabled = false
for line in header:gmatch("[^\r\n]+") do
if subgroup and name and group and enabledFor and enabled
then
break
end
line = line:gsub("%-%-.*$","")
line = line:gsub("^%s*(#.+)%s*<<%s*(.+)", function(l,t)
if not applies(t) then
return ""
else
return l
end
end)
if not enabled then
local u = strupper(line)
if u:find("#" .. addon.game) or
(addon.game == "RETAIL" and u:find("#DF")) then
enabled = true
end
end
enabledFor = enabledFor or line:match("^%s*<<%s*(.-)%s*$")
group = group or line:match("^%s*#group%s+(.-)%s*$")
subgroup = subgroup or line:match("^%s*#subgroup%s+(.-)
%s*$")
name = name or line:match("^%s*#name%s+(.-)%s*$")
end
enabled = enabled and (not enabledFor or applies(enabledFor))
if enabled then
key = addon.BuildGuideKey(group,"",name)
guide = key and RXPCData.guideMetaData[key]
else
RXPCData.guideDisabled[n] = length
end
end
--print('g-ok',guide and guide.length)
end
if addon.addonLoaded then
embeddedGuides = nil
else
embeddedGuides = {}
end
--A1 = GetTimePreciseSec() - A1
addon.RXPFrame.GenerateMenuTable()
end
function addon.BuildGuideKey(arg1,arg2,arg3)
if type(arg1) == "table" then
return fmt("%s|%s|%s", arg1.group, arg1.subgroup or '',
arg1.name)
elseif arg1 and arg3 then
return fmt("%s|%s|%s", arg1, arg2 or '',
arg3)
end
end
function addon.LoadCachedGuides()
if not addon.db then
error('Initialization error, db not set')
return
end
function addon.LoadAllGuides()
for _,guide in pairs(addon.guides) do
if not guide.steps then
addon:FetchGuide(guide)
end
end
end
if step then
local steptag, assignment, value = line:match("^#(%S+)%s*(=?)%s*(.*)")
if steptag and steptag ~= "" then
if not step[steptag] then
if assignment == "=" then
step[steptag] = parsingLogic[value]
else
step[steptag] = value
end
end
return
end
end
local element
local text
line = line:gsub("%s*>>%s*(.*)", function(t)
if t ~= "" then text = t end
return ""
end)
if addon.separators[tag] then
addon.separators[tag](t,args)
else
args = args:gsub("%s*,%s*", ",")
for arg in string.gmatch(args, "[^,]+") do
tinsert(t, arg)
end
end
-- print(tag,args,type(guide))
if parsingLogic[tag] then
element = parsingLogic[tag](linetext, text, unpack(t))
if not element then return end
element.tag = tag
element.step = step
if element.parent then
element.parent = addon.lastEelement
end
else
local ltext
if #linetext > 150 then
ltext = linetext:sub(1,150)
else
ltext = linetext
end
return addon.error(L("Error parsing guide") .. " " ..
addon.currentGuideName ..
": Invalid function call (." .. tag ..
")\n" .. ltext)
end
end)
addon.lastElement = nil
if not groupOrContent then return end
local guide = {}
if groupOrContent:sub(1, 1) == "+" then
addon.farmGuides = addon.farmGuides + 1
guide.farm = true
end
addon.guide = guide
guide.group = groupOrContent
addon.currentGuideGroup = groupOrContent
local currentStep = 0
guide.steps = {}
local parsingLogic
local step
local skip
local skipGuide
local linenumber = 0
if defaultFor then
local boost58
if defaultFor == "58Boost" then
if playerLevel >= 60 or playerLevel < 58 then
parentGroup = groupOrContent
guide.lowPrio = "*" .. groupOrContent
end
boost58 = true
elseif not applies(defaultFor) then
parentGroup = groupOrContent
guide.lowPrio = "*" .. groupOrContent
end
addon.RegisterGroup(groupOrContent, parentGroup)
guide.boost58 = boost58
--guide.lowPrio = groupOrContent
end
guide.displayname = addon.settings.ReplaceColors(guide.displayname or
guide.name)
guide.name = guide.name:gsub("^(%d)-(%d%d?)", addon.affix)
guide.key = addon.BuildGuideKey(guide)
guide.version = tonumber(guide.version) or 0
addon.minGuideVersion = math.min(guide.version,addon.minGuideVersion)
addon.maxGuideVersion = math.max(guide.version,addon.maxGuideVersion)
addon.guide = false
addon.lastElement = nil
-- print(guide.name,"\n",guide.enabledFor)
function addon.GroupOverride(guide,arg2)
local function SwapGroup(grp,subgrp)
local faction = grp:match("RestedXP ([AH][lo][lr][id][ea]%w*)")
--local group,subgroup
local swap
if faction == "Alliance" then
subgrp = subgrp or grp:gsub("RestedXP Alliance", "RXP Speedrun Guide")
grp = "RestedXP Speedrun Guide (A)"
swap = true
--print('\n',grp,subgrp,faction,type(guide) == "table" and
guide.name,'\n')
elseif faction == "Horde" then
subgrp = subgrp or grp:gsub("RestedXP Horde", "RXP Speedrun Guide")
grp = "RestedXP Speedrun Guide (H)"
swap = true
--print(group,guide.subgroup,faction,guide.group,guide.name)
end
return grp,subgrp,swap
end