Skip to content

Commit

Permalink
Fixed insert beatmaps crash
Browse files Browse the repository at this point in the history
Fixed background image not registered for SIF beatmap download

Fixed hang when loading some CBF beatmaps

- Caused by LOVE 0.11.0 seekless file line enumerator function

Modified LS2 beatmap loader to always close file handle after calling methods

Note loader cache now supports CBF difficulty string
  • Loading branch information
MikuAuahDark committed Feb 10, 2018
1 parent 6e19591 commit 9c8527b
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 51 deletions.
19 changes: 16 additions & 3 deletions beatmap_select_node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function BeatmapSelect.Start(arg)
AquaShine.LoadImage("assets/image/ui/s_button_03se.png"),
function()
local list = AquaShine.FileSelection("Insert Beatmap(s)", nil, nil, true)
BeatmapSelect.FileDropped(list)
BeatmapSelect.BeatmapInstall(list)
end,
0.5
)
Expand Down Expand Up @@ -130,9 +130,18 @@ function BeatmapSelect.Start(arg)
end

function BeatmapSelect.FileDropped(list)
local out = {}
for i = 1, #list do
out[i] = list[i]:getFilename()
end

return BeatmapSelect.BeatmapInstall(out)
end

function BeatmapSelect.BeatmapInstall(list)
local hasInstalled = false
for i, v in ipairs(list) do
local f, h = io.open(v:getFilename(), "rb")
local f, h = io.open(v, "rb")

if f then
local output = "temp/"..BeatmapSelect.CreateRandomString()
Expand All @@ -149,7 +158,11 @@ function BeatmapSelect.FileDropped(list)
local test = NoteLoader.NoteLoader(output)

if test then
assert(os.rename(BeatmapSelect.SaveDir..output, BeatmapSelect.SaveDir.."beatmap/"..AquaShine.Basename(v:getFilename())))
local source_path = BeatmapSelect.SaveDir..output
local dest_path = BeatmapSelect.SaveDir.."beatmap/"..AquaShine.Basename(v)
print(source_path, dest_path)
print("remove", os.remove(dest_path))
assert(os.rename(source_path, dest_path))
hasInstalled = true
end

Expand Down
2 changes: 2 additions & 0 deletions download_beatmap_sif2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ function DLBeatmap.ToLS2(beatmap)
score = cur.score,
combo = cur.combo
})
-- Set background image
:set_background_id(cur.star)
-- Add beatmap
:add_beatmap(beatmap)
-- Add cover art
Expand Down
10 changes: 10 additions & 0 deletions noteloader/load_cbf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,21 @@ function CBFBeatmap.GetNotesList(this)
end

-- Load it line by line
-- FIXME: LOVE 0.11.0 seekless love.filesystem.lines causes it to enter infinite loop.
-- So, read all contents then use string.gmatch. Slower but it should work.
--[[
for line in f:lines() do
if #line > 0 then
readed_notes_data[#readed_notes_data + 1] = line
end
end
]]
local contents = f:read()
for line in contents:gmatch("([^\r\n|\r|\n]+)") do
if #line > 0 then
readed_notes_data[#readed_notes_data + 1] = line
end
end
f:close()

-- First phase sort
Expand Down
66 changes: 44 additions & 22 deletions noteloader/load_ls2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,38 @@ function LS2Loader.LoadNoteFromFilename(f, file)
local this = LS2Beatmap()

this.name = NoteLoader._GetBasenameWOExt(file)
this.file = f
this.ls2 = ls2.loadstream(f)
return this, true
this.file = f
this.file_count = 0

return this
end

------------------------
-- LS2 Beatmap Object --
------------------------

function LS2Beatmap.GetNotesList(this)
local function _wrapFileHandle(func)
return function(this, ...)
if this.file_count == 0 then
assert(this.file:open("r"))
this.file_count = 1
else
this.file_count = this.file_count + 1
end

local r1, r2, r3, r4 = func(this, select(1, ...))

this.file_count = this.file_count - 1
if this.file_count == 0 then
this.file:close()
end

return r1, r2, r3, r4
end
end

LS2Beatmap.GetNotesList = _wrapFileHandle(function(this)
if not(this.notes_list) then
local nlist = {}

Expand Down Expand Up @@ -72,9 +94,9 @@ function LS2Beatmap.GetNotesList(this)
end

return this.notes_list
end
end)

function LS2Beatmap._GetMetadata(this)
LS2Beatmap._GetMetadata = _wrapFileHandle(function(this)
if not(this.metadata) then
if this.ls2.sections.MTDT then
this.file:seek(this.ls2.sections.MTDT[1])
Expand All @@ -85,9 +107,9 @@ function LS2Beatmap._GetMetadata(this)
end

return this.metadata
end
end)

function LS2Beatmap.GetName(this)
LS2Beatmap.GetName = _wrapFileHandle(function(this)
-- Get from metadata (v2.0)
local meta = this:_GetMetadata()
if meta.name then return meta.name end
Expand All @@ -100,13 +122,13 @@ function LS2Beatmap.GetName(this)

-- Not found too? Okay, fallback to basename without extension
return this.name
end
end)

function LS2Beatmap.GetBeatmapTypename(this)
return string.format("Live Simulator: 2 Beatmap (v%s)", this.ls2.version_2 and "2.0" or "1.x")
end

function LS2Beatmap.GetCoverArt(this)
LS2Beatmap.GetCoverArt = _wrapFileHandle(function(this)
if not(this.cover_art_loaded) then
if this.ls2.sections.COVR then
-- Cover available
Expand All @@ -119,9 +141,9 @@ function LS2Beatmap.GetCoverArt(this)
end

return this.cover_art
end
end)

function LS2Beatmap.GetCustomUnitInformation(this)
LS2Beatmap.GetCustomUnitInformation = _wrapFileHandle(function(this)
-- Get all UIMG information
if not(this.unit_info) then
local unit_list = {}
Expand Down Expand Up @@ -151,9 +173,9 @@ function LS2Beatmap.GetCustomUnitInformation(this)
end

return this.unit_info
end
end)

function LS2Beatmap.GetScoreInformation(this)
LS2Beatmap.GetScoreInformation = _wrapFileHandle(function(this)
if this.ls2.version_2 then
-- Live Simulator: 2 beatmap v2.0
-- Get from metadata instead from SCRI
Expand All @@ -168,7 +190,7 @@ function LS2Beatmap.GetScoreInformation(this)
end

return this.score
end
end)

function LS2Beatmap.GetComboInformation(this)
-- Combo information only supported in v2.0 beatmap format
Expand All @@ -183,7 +205,7 @@ function LS2Beatmap.HasStoryboard(this)
return not(not(this.ls2.sections.SRYL))
end

function LS2Beatmap.GetStoryboard(this)
LS2Beatmap.GetStoryboard = _wrapFileHandle(function(this)
if this.ls2.sections.SRYL then
this.file:seek(this.ls2.sections.SRYL[1])
local story_data = ls2.section_processor.SRYL[1](this.file)
Expand Down Expand Up @@ -217,7 +239,7 @@ function LS2Beatmap.GetStoryboard(this)
end

return nil
end
end)

function LS2Beatmap.GetBackgroundID(this)
if this.ls2.sections.BIMG then
Expand All @@ -227,7 +249,7 @@ function LS2Beatmap.GetBackgroundID(this)
end
end

function LS2Beatmap.GetCustomBackground(this)
LS2Beatmap.GetCustomBackground = _wrapFileHandle(function(this)
if not(this.background_loaded) and this.ls2.sections.BIMG then
local backgrounds = {}

Expand All @@ -243,7 +265,7 @@ function LS2Beatmap.GetCustomBackground(this)
end

return this.background
end
end)

function LS2Beatmap.GetScorePerTap(this)
return this.ls2.score_tap or 0
Expand All @@ -257,7 +279,7 @@ function LS2Beatmap.GetNotesStyle(this)
return this.ls2.note_style
end

function LS2Beatmap.GetBeatmapAudio(this)
LS2Beatmap.GetBeatmapAudio = _wrapFileHandle(function(this)
if not(this.audio_loaded) then
if this.ls2.sections.ADIO then
-- Embedded audio available
Expand Down Expand Up @@ -285,9 +307,9 @@ function LS2Beatmap.GetBeatmapAudio(this)
end

return this.audio
end
end)

function LS2Beatmap.GetLiveClearSound(this)
LS2Beatmap.GetLiveClearSound = _wrapFileHandle(function(this)
if this.ls2.sections.LCLR then
-- Embedded audio available
this.file:seek(this.ls2.sections.LCLR[1])
Expand All @@ -302,7 +324,7 @@ function LS2Beatmap.GetLiveClearSound(this)
end

return nil
end
end)

function LS2Beatmap.GetStarDifficultyInfo(this, rand)
local metadata = this:_GetMetadata()
Expand Down
16 changes: 1 addition & 15 deletions noteloader_cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,7 @@ function NCache.CreateCache(note, filename)
ncache.combo_data = note:GetComboInformation()
ncache.cover_art = note:GetCoverArt()
ncache.has_storyboard = note:HasStoryboard()

do
local s = note:GetStarDifficultyInfo()
local rs = note:GetStarDifficultyInfo(true)

if s > 0 then
if rs ~= s then
ncache.difficulty = string.format("%d\226\152\134 (Random %d\226\152\134)", s, rs)
else
ncache.difficulty = string.format("%d\226\152\134", s)
end
end
end
ncache.difficulty = note:GetDifficultyString()

-- Resize cover art and add PNG string representation
if ncache.cover_art then
Expand Down Expand Up @@ -96,7 +84,6 @@ function NCache.LoadCache(beatmap_path)

cache = NCache.CreateCache(note, beatmap_path)
NCache._SaveCache(cname, beatmap_path, cache)
note:Release()
else
local beatmap_mtime = assert(love.filesystem.getLastModified(beatmap_path))
local status
Expand All @@ -115,7 +102,6 @@ function NCache.LoadCache(beatmap_path)

cache = NCache.CreateCache(note, beatmap_path)
NCache._SaveCache(cname, beatmap_path, cache)
note:Release()
end
end

Expand Down
21 changes: 10 additions & 11 deletions splash/o-ten-one/init.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
local splashlib = {
_VERSION = "v1.2.0",
_VERSION = "v1.2.0-modified",
_DESCRIPTION = "a 0.10.1 splash",
_URL = "https://github.com/love2d-community/splashes",
_LICENSE = [[Copyright (c) 2016 love-community members (as per git commits in repository above)
(Modified to be compatible with letterbox)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -78,8 +79,8 @@ function splashlib.new(init)
local ox = rain.ox
local oy = rain.oy

local batch_w = 2 * math.ceil(960 / sx) + 2
local batch_h = 2 * math.ceil(640 / sy) + 2
local batch_w = 2 * math.ceil(love.graphics.getWidth() / sx) + 2
local batch_h = 2 * math.ceil(love.graphics.getHeight() / sy) + 2

batch:clear()

Expand Down Expand Up @@ -125,6 +126,7 @@ function splashlib.new(init)
extern number blur;
extern number shadow;
extern number lighten;
#define iResolution love_ScreenSize
vec4 desat(vec4 color) {
number g = dot(vec3(.299, .587, .114), color.rgb);
Expand All @@ -135,7 +137,7 @@ function splashlib.new(init)
{
// radial mask
vec4 color = Texel(canvas, tc);
number r = length((tc - vec2(.5)) * love_ScreenSize.xy);
number r = length((tc - vec2(.5)) * iResolution.xy);
number s = smoothstep(radius+blur, radius-blur, r);
#ifdef LIGHTEN
color = color + desat(color) * (1.0-s);
Expand All @@ -158,10 +160,7 @@ function splashlib.new(init)
vec4 effect(vec4 color, Image logo, vec2 tc, vec2 sc)
{
//Probably would be better to just use the texture's dimensions instead; faster reaction.
vec2 sd = sc / love_ScreenSize.xy;
if (sd.x <= alpha) {
if (tc.x * 0.5 <= alpha) {
return color * Texel(logo, tc);
}
return vec4(0);
Expand Down Expand Up @@ -191,7 +190,7 @@ function splashlib.new(init)
}
]]

self.canvas = love.graphics.newCanvas()
self.canvas = love.graphics.newCanvas(width, height)

self.elapsed = 0
self.alpha = 1
Expand Down Expand Up @@ -341,13 +340,13 @@ function splashlib:draw()
love.graphics.pop()

love.graphics.setColor(1, 1, 1, self.heart.scale)
love.graphics.draw(self.heart.sprite, 0, 5, self.heart.rot, self.heart.scale, self.heart.scale, 43, 39)
love.graphics.draw(self.heart.sprite, 0, 5, self.heart.rot, self.heart.scale, self.heart.scale, 43, 39.5)
love.graphics.pop()
end)

love.graphics.setColor(1, 1, 1, self.alpha)
love.graphics.setShader(self.maskshader)
love.graphics.draw(self.canvas, 0,0)
love.graphics.draw(self.canvas)
love.graphics.setShader()

love.graphics.push()
Expand Down

0 comments on commit 9c8527b

Please sign in to comment.