Skip to content

Commit

Permalink
Fixed news checksum differing for each character due to item links
Browse files Browse the repository at this point in the history
  • Loading branch information
derfloh205 committed Dec 22, 2023
1 parent 887fcae commit 6dbbccc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Data/News.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ local CraftSim = select(2, ...)

CraftSim.NEWS = {}

local print = CraftSim.UTIL:SetDebugPrint(CraftSim.CONST.DEBUG_IDS.NEWS)

---@param itemMap table<string, ItemMixin>
function CraftSim.NEWS:GET_NEWS(itemMap)
-- minimize names to make manual formatting easier :p
Expand Down Expand Up @@ -123,11 +125,19 @@ function CraftSim.NEWS:GetChecksum(newsText)
local checksum = 0
local checkSumBitSize = 256

-- replace each itemLink with a generic string so there are no differences between characters in the checksum
-- for _, item in pairs(itemMap) do
-- end
newsText = string.gsub(newsText, "|cff%x+|Hitem:.+|h|r", "[LINK]")

-- Iterate through each character in the string
for i = 1, #newsText do
checksum = (checksum + string.byte(newsText, i)) % checkSumBitSize
end

-- print("replacing links in newstext:")
-- print(newsText)

return checksum
end

Expand Down Expand Up @@ -155,6 +165,7 @@ function CraftSim.NEWS:ShowNews(force)
return
end

print("showing news, old / new cs: " .. tostring(CraftSimOptions.newsChecksum) .. "/" .. tostring(newChecksum))
CraftSimOptions.newsChecksum = newChecksum

local infoFrame = CraftSim.GGUI:GetFrame(CraftSim.MAIN.FRAMES, CraftSim.CONST.FRAMES.INFO)
Expand Down
1 change: 1 addition & 0 deletions Util/Const.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ CraftSim.CONST.DEBUG_IDS = {
PRICE_APIS = "PRICE_APIS",
CONTROL_PANEL = "CONTROL_PANEL",
CRAFTQ = "CRAFTQ",
NEWS = "NEWS",
}

CraftSim.CONST.ERROR = {
Expand Down

0 comments on commit 6dbbccc

Please sign in to comment.