mirror of
https://github.com/cave-story-randomizer/cave-story-randomizer
synced 2024-11-09 00:14:37 +00:00
use a proper hashing algorithm for seeds like i should've from the start
This commit is contained in:
parent
6afa0ad2e5
commit
c45f243d15
|
@ -17,7 +17,6 @@ function love.conf(t)
|
|||
t.gammacorrect = false
|
||||
|
||||
t.modules.audio = false
|
||||
t.modules.data = false
|
||||
t.modules.joystick = false
|
||||
t.modules.physics = false
|
||||
t.modules.sound = false
|
||||
|
|
|
@ -7,6 +7,7 @@ _ = require 'lib.moses'
|
|||
|
||||
lf = love.filesystem
|
||||
lg = love.graphics
|
||||
ld = love.data
|
||||
|
||||
U = require 'util'
|
||||
|
||||
|
|
|
@ -93,14 +93,12 @@ function C:_mountDirectory(path)
|
|||
end
|
||||
|
||||
function C:_seedRngesus()
|
||||
local seed = self.customseed or os.time()
|
||||
seed = tonumber(seed) or tonumber(seed, 36) -- convert alphanumeric strings to numbers
|
||||
local seedstring = self.customseed or tostring(seed)
|
||||
if seed == nil then
|
||||
seed = os.time()
|
||||
seedstring = ('%d ("%s" was invalid)'):format(seed, self.customseed)
|
||||
end
|
||||
love.math.setRandomSeed(seed)
|
||||
local seedstring = self.customseed or tostring(os.time())
|
||||
local seed = ld.encode('string', 'hex', ld.hash('sha256', seedstring))
|
||||
local s1 = tonumber(seed:sub(-8, -1), 16) -- first 32 bits (from right)
|
||||
local s2 = tonumber(seed:sub(-16, -9), 16) -- next 32 bits
|
||||
|
||||
love.math.setRandomSeed(s1, s2)
|
||||
|
||||
logNotice(('Offering seed "%s" to RNGesus' ):format(seedstring))
|
||||
return seedstring
|
||||
|
|
Loading…
Reference in a new issue