From 3d70a5ac792b3a8c5a806eb01f3d750f9999017a Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Mon, 18 Oct 2021 15:05:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E6=B5=8B=E8=B5=84=E6=BA=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=98=AF=E5=90=A6=E6=9D=A5=E8=87=AA=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=E7=9A=84=E8=BF=87=E7=A8=8B=E6=94=B9=E4=B8=BA=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.lua | 22 ++++++++-------------- parts/gameFuncs.lua | 7 +++++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/main.lua b/main.lua index 6d9d2723..cb589452 100644 --- a/main.lua +++ b/main.lua @@ -72,7 +72,7 @@ end --Load shader files from SOURCE ONLY SHADER={} for _,v in next,fs.getDirectoryItems('parts/shaders')do - if fs.getRealDirectory('parts/shaders/'..v)~=SAVEDIR then + if isSafeFile('parts/shaders/'..v)then local name=v:sub(1,-6) SHADER[name]=love.graphics.newShader('parts/shaders/'..name..'.glsl') end @@ -285,10 +285,8 @@ SKIN.init{ SFX.init((function() local L={} for _,v in next,fs.getDirectoryItems('media/effect/chiptune/')do - if fs.getRealDirectory('media/effect/chiptune/'..v)~=SAVEDIR then + if isSafeFile('media/effect/chiptune/'..v,"Dangerous file : %SAVE%/media/effect/chiptune/"..v)then table.insert(L,v:sub(1,-5)) - else - MES.new('warn',"Dangerous file : %SAVE%/media/effect/chiptune/"..v) end end return L @@ -296,10 +294,8 @@ end)()) BGM.init((function() local L={} for _,v in next,fs.getDirectoryItems('media/music')do - if fs.getRealDirectory('media/music/'..v)~=SAVEDIR then + if isSafeFile('media/music/'..v,"Dangerous file : %SAVE%/media/music/"..v)then table.insert(L,{name=v:sub(1,-5),path='media/music/'..v}) - else - MES.new('warn',"Dangerous file : %SAVE%/media/music/"..v) end end return L @@ -342,16 +338,14 @@ LANG.init('zh', ) --Load background files from SOURCE ONLY for _,v in next,fs.getDirectoryItems('parts/backgrounds')do - if fs.getRealDirectory('parts/backgrounds/'..v)~=SAVEDIR then - if v:sub(-3)=='lua'then - local name=v:sub(1,-5) - BG.add(name,require('parts.backgrounds.'..name)) - end + if isSafeFile('parts/backgrounds/'..v)and v:sub(-3)=='lua'then + local name=v:sub(1,-5) + BG.add(name,require('parts.backgrounds.'..name)) end end --Load scene files from SOURCE ONLY for _,v in next,fs.getDirectoryItems('parts/scenes')do - if fs.getRealDirectory('parts/scenes/'..v)~=SAVEDIR then + if isSafeFile('parts/scenes/'..v)then local sceneName=v:sub(1,-5) SCN.add(sceneName,require('parts.scenes.'..sceneName)) LANG.addScene(sceneName) @@ -360,7 +354,7 @@ end --Load mode files for i=1,#MODES do local m=MODES[i]--Mode template - if fs.getRealDirectory('parts/modes/'..m.name)~=SAVEDIR then + if isSafeFile('parts/modes/'..m.name)then TABLE.complete(require('parts.modes.'..m.name),MODES[i]) MODES[m.name],MODES[i]=MODES[i] end diff --git a/parts/gameFuncs.lua b/parts/gameFuncs.lua index 26d6f889..29c0198f 100644 --- a/parts/gameFuncs.lua +++ b/parts/gameFuncs.lua @@ -71,6 +71,13 @@ do--function applyXxxSatur(mode) SHADER.fieldSatur:send('k',m[2]) end end +function isSafeFile(file,mes) + if love.filesystem.getRealDirectory(file)~=SAVEDIR then + return true + elseif mes then + MES.new('warn',mes) + end +end --Royale mode function randomTarget(P)--Return a random opponent for P