修改任务和序列的编码

This commit is contained in:
MrZ626
2020-09-21 14:25:34 +08:00
parent d5634c0f6f
commit fce0b3862d

View File

@@ -79,34 +79,62 @@ function pasteQuestArgs(str)
ENV.sequence= sub(str,4) ENV.sequence= sub(str,4)
end end
--Encoding Functions
--Safe char: 33~94, 96~126
--[[
Count: 33~94
Block: 97~125
Encode: [A] or [AB] sequence, A = block ID, B = repeat times, no B means do not repeat.
Example: "abcdefg" is [SZJLTOI], "a^aDb)" is [Z*63,Z*37,S*10]
]]
function copySequence() function copySequence()
local preBag=preBag local preBag=preBag
local str="" local str=""
for i=1,#preBag do local count=1
str=str..char(preBag[i]-1) for i=1,#preBag+1 do
if preBag[i+1]~=preBag[i]or count==63 then
str=str..char(96+preBag[i])
if count>1 then
str=str..char(31+count)
count=1
end
else
count=count+1
end
end end
return data.encode("string","base64",data.compress("string","deflate",str)) return str
end end
function pasteSequence(str) function pasteSequence(str)
local _ local _
--Decode
_,str=pcall(data.decode,"string","base64",str)
if not _ then return end
_,str=pcall(data.decompress,"string","deflate",str)
if not _ then return end
local bag={} local bag={}
local reg
for i=1,#str do for i=1,#str do
_=byte(str,i) _=byte(str,i)
if _<25 then if not reg then
bag[i]=_+1 if _>=97 and _<=125 then
reg=_-96
else
return
end
else else
return if _>=97 and _<=125 then
ins(bag,reg)
reg=_-96
elseif _>=33 and _<=94 then
for i=1,_-31 do
ins(bag,reg)
end
reg=nil
end
end end
end end
if reg then
ins(bag,reg)
end
preBag=bag preBag=bag
sceneTemp.cur=#preBag sceneTemp.cur=#preBag
@@ -136,7 +164,7 @@ function copyBoard()
end end
str=str..S str=str..S
end end
return data.encode("string","base64",data.compress("string","deflate",str)) return data.encode("string","base64",data.compress("string","zlib",str))
end end
function pasteBoard(str) function pasteBoard(str)
local _ local _
@@ -144,7 +172,7 @@ function pasteBoard(str)
--Decode --Decode
_,str=pcall(data.decode,"string","base64",str) _,str=pcall(data.decode,"string","base64",str)
if not _ then return end if not _ then return end
_,str=pcall(data.decompress,"string","deflate",str) _,str=pcall(data.decompress,"string","zlib",str)
if not _ then return end if not _ then return end
local fX,fY=1,1--*ptr for Field(r*10+(c-1)) local fX,fY=1,1--*ptr for Field(r*10+(c-1))
@@ -186,35 +214,74 @@ function pasteBoard(str)
return true return true
end end
--[[
mission: 33~94,96~115
Count: 116~126
Encode: [A] or [AB] sequence, A = mission ID, B = repeat times, no B means do not repeat.
_1=01,_2=02,_3=03,_4=04,
A1=05,A2=06,A3=07,A4=08,
PC=09,
Z1=11,Z2=12,Z3=13,
S1=21,S2=22,S3=23,
J1=31,J2=32,J3=33,
L1=41,L2=42,L3=43,
T1=51,T2=52,T3=53,
O1=61,O2=62,O3=63,O4=64,
I1=71,I2=72,I3=73,I4=74,
]]
function copyMission() function copyMission()
local str="" local _
local preMission=preMission local preMission=preMission
for i=1,#preMission do local str=""
str=str..char(preMission[i])
local count=1
for i=1,#preMission+1 do
if preMission[i+1]~=preMission[i]or count==11 then
_=32+preMission[i]
if _>=95 then _=_+1 end
str=str..char(_)
if count>1 then
str=str..char(115+count)
count=1
end
else
count=count+1
end
end end
return data.encode("string","base64",data.compress("string","deflate",str)) return str
end end
function pasteMission(str) function pasteMission(str)
local _ local _
--Decode
_,str=pcall(data.decode,"string","base64",str)
if not _ then return end
_,str=pcall(data.decompress,"string","deflate",str)
if not _ then return end
local mission={} local mission={}
local reg
for i=1,#str do for i=1,#str do
_=byte(str,i) _=byte(str,i)
if missionEnum[_]then if not reg then
ins(mission,_) if _>=33 and _<=115 and _~=95 then
reg=_<95 and _-32 or _-33
else
return
end
else else
return if _>=33 and _<=115 and _~=95 then
ins(mission,reg)
reg=_<95 and _-32 or _-33
elseif _>=116 and _<=126 then
for i=1,_-114 do
ins(mission,reg)
end
reg=nil
end
end end
end end
if reg then
ins(mission,reg)
end
preMission=mission preMission=mission
sceneTemp.cur=#preMission sceneTemp.cur=#preBag
return true return true
end end