Skip to content

Commit

Permalink
Merge pull request #2 from Bakudankun/fix-savedata-loading
Browse files Browse the repository at this point in the history
Fixed bug: loading save data may fail when the file contains 0x1A (EOF) byte.
  • Loading branch information
katono authored Nov 19, 2021
2 parents b4028f7 + 9bc1a9a commit 0999f5b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions autoload/rogue/save.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ g.save_file = 'rogue_vim.save'

local function save_into_file(fname)
fname = g.expand_fname(fname, g.game_dir)
local fp = io.open(fname, "w")
local fp = io.open(fname, "wb")
if not fp then
g.message(g.mesg[503])
return
Expand Down Expand Up @@ -100,7 +100,7 @@ end

function g.restore(fname)
fname = g.expand_fname(fname, g.game_dir)
local fp = io.open(fname, "r")
local fp = io.open(fname, "rb")
if not fp then
g.message(g.mesg[504])
return false
Expand Down
4 changes: 2 additions & 2 deletions autoload/rogue/score.lua
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ end
function g.put_scores(monster, other)
local scores = {}
local file = g.game_dir .. score_file
local fp = io.open(file, "r")
local fp = io.open(file, "rb")
if fp then
local buf = fp:read("*a")
g.xxx(true)
Expand All @@ -366,7 +366,7 @@ function g.put_scores(monster, other)
end

if rank <= MAX_RANK then
fp = io.open(file, "w")
fp = io.open(file, "wb")
if not fp then
g.message(g.mesg[186])
sf_error()
Expand Down
4 changes: 4 additions & 0 deletions autoload/rogue/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ g.bxor = nil
local bit_exists, bit = pcall(require, "bit")
if bit_exists then
g.bxor = bit.bxor
elseif _VERSION >= 'Lua 5.3' then
g.bxor = function(x, y)
return x ~ y
end
elseif _VERSION >= 'Lua 5.2' then
g.bxor = bit32.bxor
else
Expand Down

0 comments on commit 0999f5b

Please sign in to comment.