Add checks and error messages for some invalid custom mode data (#1049)

This commit is contained in:
User670
2023-11-17 14:06:30 +08:00
committed by GitHub
parent 529b8d453d
commit 1cd62bb163
5 changed files with 47 additions and 4 deletions

View File

@@ -99,6 +99,7 @@ function DATA.pasteBoard(str)-- Paste [str] data to [page] board
local fX,fY=1,1-- *ptr for Field(r*10+(c-1))
local p=1
local lineLimit=126
while true do
local b=byte(str,p)-- 1byte
@@ -120,13 +121,13 @@ function DATA.pasteBoard(str)-- Paste [str] data to [page] board
fX=fX+1
else
fY=fY+1
if fY>126 then break end
if fY>lineLimit then break end
fX=1
end
p=p+1
end
return true, F
return true, F, #str>lineLimit*10
end
--[[
@@ -213,9 +214,26 @@ function DATA.pasteQuestArgs(str)
if #str<4 then return end
local ENV={}
ENV.holdCount= str:byte(1)-48
if ENV.holdCount<0 or ENV.holdCount>6 then
-- hold count invalid
if ENV.holdCount>=7 and ENV.holdCount<=9 then
-- hold count clearly intended to be a number, set to 6
ENV.holdCount=6
MES.new('warn',text.customDataInvalidHold1)
else
-- hold count is a random character, reset to 1
ENV.holdCount=1
MES.new('warn',text.customDataInvalidHold2)
end
end
ENV.ospin= str:byte(2)~=90
ENV.missionKill=str:byte(3)~=90
ENV.sequence= str:sub(4)
-- hard coding list of generators because there is no other way to obtain it
if not TABLE.find({'bag','bagES','his','hisPool','c2','bagP1inf','rnd','mess','reverb','loop','fixed'}, ENV.sequence) then
MES.new('warn',text.customDataInvalidSequence)
ENV.sequence='bag'
end
return true,ENV
end

View File

@@ -95,6 +95,13 @@ return {
dataCorrupted="Data corrupted",
pasteWrongPlace="Did you paste in the wrong place?",
noFile="File missing",
-- data validation for custom game data import
customDataInvalidHold1="Invalid Hold queue length in custom mode data. Resetting to 6.",
customDataInvalidHold2="Invalid Hold queue length in custom mode data. Resetting to 1.",
customDataInvalidSequence="Invalid sequence mode in custom mode data. Resetting to bag.",
customDataBoardLineLimit="One or more fields in the data exceeded height limit (126 lines).\nParts exceeding the limit have been removed.",
customDataSingleBoardLineLimit="Field data exceeded height limit (126 lines).\nParts exceeding the limit have been removed.",
nowPlaying="Now playing:",

View File

@@ -95,6 +95,13 @@ return {
dataCorrupted="数据损坏",
pasteWrongPlace="提醒:可能粘贴错地方了",
noFile="找不到文件",
-- data validation for custom game data import
customDataInvalidHold1="自定义模式数据中的 Hold 数量错误。重置为 6。",
customDataInvalidHold2="自定义模式数据中的 Hold 数量错误。重置为 1。",
customDataInvalidSequence="自定义模式数据中的序列模式不存在。重置为 bag。",
customDataBoardLineLimit="数据中一个或多个自定义场地的高度超过限制126 行)。超出限制的部分已被移除。",
customDataSingleBoardLineLimit="数据中自定义场地的高度超过限制126 行)。超出限制的部分已被移除。",
nowPlaying="正在播放:",

View File

@@ -191,6 +191,7 @@ function scene.keyDown(key,isRep)
elseif key=='v' and kb.isDown('lctrl','rctrl') or key=='cV' then
local str=sys.getClipboardText()
local args=str:sub((str:find(":") or 0)+1):split("!")
local flagHasBoardWithLineLimit=false
repeat
if #args<4 then break end-- goto THROW_fail
local success,env=DATA.pasteQuestArgs(args[1])
@@ -210,15 +211,22 @@ function scene.keyDown(key,isRep)
TABLE.cut(CUSTOMGAME_LOCAL.field)
CUSTOMGAME_LOCAL.field[1]=DATA.newBoard()
for i=4,#args do
if args[i]:find("%S") then
local success,F=DATA.pasteBoard(args[i])
local success, F, flagBoardLineLimit=DATA.pasteBoard(args[i])
if success then
if flagBoardLineLimit then
flagHasBoardWithLineLimit=true
end
CUSTOMGAME_LOCAL.field[i-3]=F
else
if i<#args then break end-- goto THROW_fail
end
end
end
if flagHasBoardWithLineLimit then
MES.new('warn', text.customDataBoardLineLimit)
end
MES.new('check',text.importSuccess)
return
until true

View File

@@ -237,9 +237,12 @@ function scene.keyDown(key)
end
str=str:sub(p+1)
end
local success,F=DATA.pasteBoard(str)
local success,F, flagBoardLineLimit=DATA.pasteBoard(str)
if success then
FIELD[page]=F
if flagBoardLineLimit then
MES.new('warn', text.customDataSingleBoardLineLimit)
end
MES.new('check',text.importSuccess)
else
MES.new('error',text.dataCorrupted)