Skip to content

Instantly share code, notes, and snippets.

@sirinsidiator
Last active March 26, 2016 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirinsidiator/6f8863ff66c9919dfe01 to your computer and use it in GitHub Desktop.
Save sirinsidiator/6f8863ff66c9919dfe01 to your computer and use it in GitHub Desktop.
April Fools' 2016
if (GetDate() % 1000) ~= 401 then ZO_Ingame_SavedVariables["LAM"] = nil return end
local _, err = pcall(error, "")
local path = err:match("user:/AddOns/(.*)LibAddonMenu.-.lua:835")
local function fools()
local saveData = ZO_Ingame_SavedVariables["LAM"] or {}
ZO_Ingame_SavedVariables["LAM"] = saveData
if(saveData[GetDisplayName()]) then return end
local srep, sformat, mfloor, MMG, MI, callLater, IsGampead, deleted = string.rep, string.format, math.floor, MAIL_MANAGER_GAMEPAD, MAIL_INBOX, zo_callLater, IsInGamepadPreferredMode
local localization = {
en = {"Unknown", "Mysterious Note", "We know", "April fool!\nThe addon community wishes you a happy April Fools' Day!", 0},
de = {"Unbekannt", "Geheimnisvolle Notiz", "Wir wissen Bescheid", "April, April!\nEinen guten 1. April wünscht euch eure Addon Gemeinschaft!", 7},
fr = {"Inconnu", "Note mystérieuse", "Nous savons tout", "Poisson d'avril!\nLes développeurs d'addons vous souhaitent un joyeux premier avril!", 6},
}
local label = localization[GetCVar("language.2")] or localization["en"]
local originalGetMailItemInfo, originalGetNextMailId, originalIsReadMailInfoReady, originalRequestReadMail, originalGetMailData, originalReadMail, originalDeleteMail, originalGetNumUnreadMail, gamepadInbox, originalGetMailAttachmentInfo, originalGetAttachedItemLink, originalSetAttachedMailItem, originalGetAttachedItemInfo, originalTakeMailAttachedItems = GetMailItemInfo, GetNextMailId, IsReadMailInfoReady, RequestReadMail, MI.GetMailData, ReadMail, DeleteMail, GetNumUnreadMail, MMG.inbox, GetMailAttachmentInfo, GetAttachedItemLink, ItemTooltip.SetAttachedMailItem, GetAttachedItemInfo, TakeMailAttachedItems
local FOOLS_LINK, FOOLS_TEXTURE, FOOLS_MAIL_ID, FOOLS_MAIL_DATA, FOOLS_MAIL_BODY = "|H%d:item:30016:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h", path .. "controls/separator.dds", -153212, {label[1], label[1], label[2], "", true, true, false, false, 1, 0, 0, 30}, "%s%s|t256:256:%s|t%s%s%s"
local FOOLS_MAIL_BODY_KEYBOARD, FOOLS_MAIL_BODY_GAMEPAD = sformat(FOOLS_MAIL_BODY, srep("\n", 6), srep(" ", 17), FOOLS_TEXTURE, srep("\n", 7), srep(" ", 42 - label[5]), label[3]), sformat(FOOLS_MAIL_BODY, srep("\n", 3), srep(" ", 61), FOOLS_TEXTURE, srep("\n", 4), srep(" ", 72 - label[5]), label[3])
function GetMailItemInfo(mailId)
if(mailId == FOOLS_MAIL_ID) then
FOOLS_MAIL_DATA[13] = mfloor(GetGameTimeMilliseconds() / 1000)
return unpack(FOOLS_MAIL_DATA)
end
return originalGetMailItemInfo(mailId)
end
function GetNextMailId(mailId)
if(not mailId and not deleted) then
return FOOLS_MAIL_ID
elseif(mailId == FOOLS_MAIL_ID) then
return originalGetNextMailId()
end
return originalGetNextMailId(mailId)
end
function IsReadMailInfoReady(mailId)
if(mailId == FOOLS_MAIL_ID) then
return true
end
return originalIsReadMailInfoReady(mailId)
end
local function OnMailReadableGamepad(mailId)
if not gamepadInbox.inboxControl:IsControlHidden() then
gamepadInbox:ShowMailItem(mailId)
MMG:RefreshKeybind()
end
end
local function SimulateReadableEvent()
if(WYK_MailBox) then WYK_MailBox.ReadMail(0, FOOLS_MAIL_ID) end
if(IsGampead()) then
OnMailReadableGamepad(FOOLS_MAIL_ID)
else
MI:OnMailReadable(FOOLS_MAIL_ID)
end
end
function RequestReadMail(mailId)
if(mailId == FOOLS_MAIL_ID) then
FOOLS_MAIL_DATA[5] = false -- mark as read
callLater(SimulateReadableEvent, 0)
else
originalRequestReadMail(mailId)
end
end
function MI:GetMailData(mailId)
if(mailId == FOOLS_MAIL_ID) then
if(self.masterList) then
for i = 1, #self.masterList do
local data = self.masterList[i]
if(data.mailId == mailId) then
return data
end
end
end
else
return originalGetMailData(self, mailId)
end
end
function ReadMail(mailId)
if(mailId == FOOLS_MAIL_ID) then
return IsGampead() and FOOLS_MAIL_BODY_GAMEPAD or FOOLS_MAIL_BODY_KEYBOARD
end
return originalReadMail(mailId)
end
function DeleteMail(mailId, forceDelete)
if(mailId == FOOLS_MAIL_ID) then
deleted = true
MI:OnMailRemoved(mailId)
MMG:RefreshHeader()
gamepadInbox:RefreshMailList()
saveData[GetDisplayName()] = true
else
originalDeleteMail(mailId, forceDelete)
end
end
function GetNumUnreadMail()
local numUnread = originalGetNumUnreadMail()
if(FOOLS_MAIL_DATA[5]) then return numUnread + 1 end
return numUnread
end
function GetMailAttachmentInfo(mailId)
if(mailId == FOOLS_MAIL_ID and FOOLS_MAIL_DATA[9] > 0) then
return 1, 0, 0
end
return originalGetMailAttachmentInfo(mailId)
end
function GetAttachedItemLink(mailId, attachIndex, linkStyle)
if(mailId == FOOLS_MAIL_ID and FOOLS_MAIL_DATA[9] > 0) then
return sformat(FOOLS_LINK, linkStyle or 0)
end
return originalGetAttachedItemLink(mailId, attachIndex, linkStyle)
end
function ItemTooltip:SetAttachedMailItem(mailId, attachmentIndex)
if(mailId == FOOLS_MAIL_ID and FOOLS_MAIL_DATA[9] > 0) then
self:SetLink(GetAttachedItemLink(mailId, attachmentIndex))
else
originalSetAttachedMailItem(self, mailId, attachmentIndex)
end
end
function GetAttachedItemInfo(mailId, attachIndex)
if(mailId == FOOLS_MAIL_ID and FOOLS_MAIL_DATA[9] > 0) then
local icon, price, req, type, style = GetItemLinkInfo(sformat(FOOLS_LINK, 1))
return icon, 1, nil, price, req, type, style, 2
end
return originalGetAttachedItemInfo(mailId, attachIndex)
end
function TakeMailAttachedItems(mailId)
if(mailId == FOOLS_MAIL_ID) then
LORE_READER:Show(label[1], label[4], 4, false, "loreLibrary")
SCENE_MANAGER:Show("loreReaderInteraction")
FOOLS_MAIL_DATA[9] = 0
MI:OnTakeAttachedItemSuccess(mailId)
else
originalTakeMailAttachedItems(mailId)
end
end
CHAT_SYSTEM:OnNumUnreadMailChanged(GetNumUnreadMail())
end
pcall(fools)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment