From d72738d4745be0e35586d8c7afe330a390ab33a4 Mon Sep 17 00:00:00 2001 From: duncathan Date: Mon, 5 Apr 2021 20:04:06 -0600 Subject: [PATCH 1/2] makes the title screen hash into a real hash --- src/database/world_graph.lua | 18 ++++++++++++++---- src/randomizer.lua | 12 +++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/database/world_graph.lua b/src/database/world_graph.lua index e0e3754..c608dcf 100644 --- a/src/database/world_graph.lua +++ b/src/database/world_graph.lua @@ -702,7 +702,7 @@ function worldGraph.locationsArray(locations) return array end -function worldGraph:logLocations() +function worldGraph:serialize() local array = {} for k,v in pairs(self.regions) do table.insert(array, v) @@ -712,17 +712,27 @@ function worldGraph:logLocations() return a.order < b.order end + local lines = {} + for k,r in ipairs(_.sort(array,sort)) do if next(r.locations) then - logSpoiler("") - logSpoiler("Region: " .. r.name) + lines:insert("") + lines:insert("Region: " .. r.name) for k2,l in pairs(r.locations) do if l.item ~= nil and not _has({l.item}, "event") then - logSpoiler("\t " .. l.name .. ": " .. l.item.name) + lines:insert("\t " .. l.name .. ": " .. l.item.name) end end end end + + return lines +end + +function worldGraph:logLocations() + for k,v in ipairs(worldGraph:serialize()) do + logSpoiler(v) + end end return worldGraph \ No newline at end of file diff --git a/src/randomizer.lua b/src/randomizer.lua index 7c0c19d..d72f3ad 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -286,8 +286,18 @@ function C:_copyMyChar() end function C:_generateHash() + local serialized = self.worldGraph:serialize():concat() + local hashed = ld.encode('string', 'hex', ld.hash('sha256', serialized)) + hashed = tonumber(hashed:sub(-8, -1), 16) + hashed = hashed % (39^5) + + local h = {} + for i=1,5 do + h:insert((hashed%39)+1) + hashed = math.floor(hashed / 39) + end + local path = self:_getWritePath() .. '/hash.txt' - local h = {love.math.random(39), love.math.random(39), love.math.random(39), love.math.random(39), love.math.random(39)} U.writeFile(path, ("%04d,%04d,%04d,%04d,%04d"):format(h[1], h[2], h[3], h[4], h[5])) return h end From 6ad63828c9ba7429dc1e9c8e94d3192d5b438edd Mon Sep 17 00:00:00 2001 From: duncathan Date: Mon, 26 Jul 2021 20:32:12 -0600 Subject: [PATCH 2/2] fix sphere logging (oops) --- src/database/world_graph.lua | 8 ++++---- src/randomizer.lua | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/database/world_graph.lua b/src/database/world_graph.lua index c608dcf..25c1ba7 100644 --- a/src/database/world_graph.lua +++ b/src/database/world_graph.lua @@ -716,11 +716,11 @@ function worldGraph:serialize() for k,r in ipairs(_.sort(array,sort)) do if next(r.locations) then - lines:insert("") - lines:insert("Region: " .. r.name) + table.insert(lines, "") + table.insert(lines, "Region: " .. r.name) for k2,l in pairs(r.locations) do if l.item ~= nil and not _has({l.item}, "event") then - lines:insert("\t " .. l.name .. ": " .. l.item.name) + table.insert(lines, "\t " .. l.name .. ": " .. l.item.name) end end end @@ -730,7 +730,7 @@ function worldGraph:serialize() end function worldGraph:logLocations() - for k,v in ipairs(worldGraph:serialize()) do + for k,v in ipairs(self:serialize()) do logSpoiler(v) end end diff --git a/src/randomizer.lua b/src/randomizer.lua index d72f3ad..4fe209f 100644 --- a/src/randomizer.lua +++ b/src/randomizer.lua @@ -286,14 +286,14 @@ function C:_copyMyChar() end function C:_generateHash() - local serialized = self.worldGraph:serialize():concat() + local serialized = table.concat(self.worldGraph:serialize()) local hashed = ld.encode('string', 'hex', ld.hash('sha256', serialized)) hashed = tonumber(hashed:sub(-8, -1), 16) hashed = hashed % (39^5) local h = {} for i=1,5 do - h:insert((hashed%39)+1) + table.insert(h, (hashed%39)+1) hashed = math.floor(hashed / 39) end