From c63618a44c7251ddd548b17aaa3b780dcd2fe097 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Mon, 30 Nov 2020 01:35:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BD=95=E5=83=8F=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E8=BD=AC=E7=A0=81=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/gametoolfunc.lua | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/parts/gametoolfunc.lua b/parts/gametoolfunc.lua index ab25b09a..a02c8086 100644 --- a/parts/gametoolfunc.lua +++ b/parts/gametoolfunc.lua @@ -507,4 +507,63 @@ function scoreValid() end end return true +end +function dumpRecording(L) + local out="" + local buffer="" + local prevFrm=0 + local p=1 + while L[p]do + --Check buffer size + if #buffer>10 then + out=out..buffer + buffer="" + end + + --Encode time + local t=L[p]-prevFrm + prevFrm=L[p] + while t>=255 do + buffer=buffer.."\255" + t=t-255 + end + buffer=buffer..char(t) + + --Encode key + t=L[p+1] + buffer=buffer..char(t>0 and t or 256+t) + + --Step + p=p+2 + end + return data.encode("string","base64",out..buffer) +end +function parseRecording(str) + str=data.decode("string","base64",str) + local len=#str + local L={} + local p=1 + local curFrm=0 + + while p<=len do + --Read delta time + ::nextByte:: + local b=byte(str,p) + if b==255 then + curFrm=curFrm+255 + p=p+1 + goto nextByte + end + curFrm=curFrm+b + L[#L+1]=curFrm + p=p+1 + + b=byte(str,p) + if b>127 then + b=b-256 + end + L[#L+1]=b + p=p+1 + end + return L end \ No newline at end of file