first commit
This commit is contained in:
50
assets/scripts/libs/convert.ts
Normal file
50
assets/scripts/libs/convert.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
|
||||
export class convert {
|
||||
stringToByte(str) {
|
||||
var bytes = new Array();
|
||||
var len, c;
|
||||
len = str.length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
c = str.charCodeAt(i);
|
||||
if (c >= 0x010000 && c <= 0x10FFFF) {
|
||||
bytes.push(((c >> 18) & 0x07) | 0xF0);
|
||||
bytes.push(((c >> 12) & 0x3F) | 0x80);
|
||||
bytes.push(((c >> 6) & 0x3F) | 0x80);
|
||||
bytes.push((c & 0x3F) | 0x80);
|
||||
} else if (c >= 0x000800 && c <= 0x00FFFF) {
|
||||
bytes.push(((c >> 12) & 0x0F) | 0xE0);
|
||||
bytes.push(((c >> 6) & 0x3F) | 0x80);
|
||||
bytes.push((c & 0x3F) | 0x80);
|
||||
} else if (c >= 0x000080 && c <= 0x0007FF) {
|
||||
bytes.push(((c >> 6) & 0x1F) | 0xC0);
|
||||
bytes.push((c & 0x3F) | 0x80);
|
||||
} else {
|
||||
bytes.push(c & 0xFF);
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
byteToString(arr) {
|
||||
if (typeof arr === 'string') {
|
||||
return arr;
|
||||
}
|
||||
var str = '', _arr = arr;
|
||||
for (var i = 0; i < _arr.length; i++) {
|
||||
var one = _arr[i].toString(2), v = one.match(/^1+?(?=0)/);
|
||||
if (v && one.length == 8) {
|
||||
var bytesLength = v[0].length;
|
||||
var store = _arr[i].toString(2).slice(7 - bytesLength);
|
||||
for (var st = 1; st < bytesLength; st++) {
|
||||
store += _arr[st + i].toString(2).slice(2);
|
||||
}
|
||||
str += String.fromCharCode(parseInt(store, 2));
|
||||
i += bytesLength - 1;
|
||||
} else {
|
||||
str += String.fromCharCode(_arr[i]);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
9
assets/scripts/libs/convert.ts.meta
Normal file
9
assets/scripts/libs/convert.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "827c1ab9-c3c0-4a7b-990a-c7f6e6e58340",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
12
assets/scripts/libs/crypto.meta
Normal file
12
assets/scripts/libs/crypto.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "06b8b43e-7e62-42d0-a003-5a7d480d4e98",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
2277
assets/scripts/libs/crypto/crypto.ts
Normal file
2277
assets/scripts/libs/crypto/crypto.ts
Normal file
File diff suppressed because it is too large
Load Diff
9
assets/scripts/libs/crypto/crypto.ts.meta
Normal file
9
assets/scripts/libs/crypto/crypto.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "7b2dc4c7-2f77-4861-bfdd-17bad2444b41",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
400
assets/scripts/libs/crypto/md5.ts
Normal file
400
assets/scripts/libs/crypto/md5.ts
Normal file
@@ -0,0 +1,400 @@
|
||||
"use strict";
|
||||
/*
|
||||
|
||||
TypeScript Md5
|
||||
==============
|
||||
|
||||
Based on work by
|
||||
* Joseph Myers: http://www.myersdaily.org/joseph/javascript/md5-text.html
|
||||
* André Cruz: https://github.com/satazor/SparkMD5
|
||||
* Raymond Hill: https://github.com/gorhill/yamd5.js
|
||||
|
||||
Effectively a TypeScrypt re-write of Raymond Hill JS Library
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (C) 2014 Raymond Hill
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2015 André Cruz <amdfcruz@gmail.com>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
|
||||
|
||||
*/
|
||||
var Md5 = /** @class */ (function () {
|
||||
function Md5() {
|
||||
this._state = new Int32Array(4);
|
||||
this._buffer = new ArrayBuffer(68);
|
||||
this._buffer8 = new Uint8Array(this._buffer, 0, 68);
|
||||
this._buffer32 = new Uint32Array(this._buffer, 0, 17);
|
||||
this.start();
|
||||
}
|
||||
Md5.hashStr = function (str, raw) {
|
||||
if (raw === void 0) { raw = false; }
|
||||
return this.onePassHasher
|
||||
.start()
|
||||
.appendStr(str)
|
||||
.end(raw);
|
||||
};
|
||||
|
||||
Md5.encrypt = function(str){
|
||||
return Md5.hashStr(str, false);
|
||||
}
|
||||
Md5.hashAsciiStr = function (str, raw) {
|
||||
if (raw === void 0) { raw = false; }
|
||||
return this.onePassHasher
|
||||
.start()
|
||||
.appendAsciiStr(str)
|
||||
.end(raw);
|
||||
};
|
||||
Md5._hex = function (x) {
|
||||
var hc = Md5.hexChars;
|
||||
var ho = Md5.hexOut;
|
||||
var n;
|
||||
var offset;
|
||||
var j;
|
||||
var i;
|
||||
for (i = 0; i < 4; i += 1) {
|
||||
offset = i * 8;
|
||||
n = x[i];
|
||||
for (j = 0; j < 8; j += 2) {
|
||||
ho[offset + 1 + j] = hc.charAt(n & 0x0F);
|
||||
n >>>= 4;
|
||||
ho[offset + 0 + j] = hc.charAt(n & 0x0F);
|
||||
n >>>= 4;
|
||||
}
|
||||
}
|
||||
return ho.join('');
|
||||
};
|
||||
Md5._md5cycle = function (x, k) {
|
||||
var a = x[0];
|
||||
var b = x[1];
|
||||
var c = x[2];
|
||||
var d = x[3];
|
||||
// ff()
|
||||
a += (b & c | ~b & d) + k[0] - 680876936 | 0;
|
||||
a = (a << 7 | a >>> 25) + b | 0;
|
||||
d += (a & b | ~a & c) + k[1] - 389564586 | 0;
|
||||
d = (d << 12 | d >>> 20) + a | 0;
|
||||
c += (d & a | ~d & b) + k[2] + 606105819 | 0;
|
||||
c = (c << 17 | c >>> 15) + d | 0;
|
||||
b += (c & d | ~c & a) + k[3] - 1044525330 | 0;
|
||||
b = (b << 22 | b >>> 10) + c | 0;
|
||||
a += (b & c | ~b & d) + k[4] - 176418897 | 0;
|
||||
a = (a << 7 | a >>> 25) + b | 0;
|
||||
d += (a & b | ~a & c) + k[5] + 1200080426 | 0;
|
||||
d = (d << 12 | d >>> 20) + a | 0;
|
||||
c += (d & a | ~d & b) + k[6] - 1473231341 | 0;
|
||||
c = (c << 17 | c >>> 15) + d | 0;
|
||||
b += (c & d | ~c & a) + k[7] - 45705983 | 0;
|
||||
b = (b << 22 | b >>> 10) + c | 0;
|
||||
a += (b & c | ~b & d) + k[8] + 1770035416 | 0;
|
||||
a = (a << 7 | a >>> 25) + b | 0;
|
||||
d += (a & b | ~a & c) + k[9] - 1958414417 | 0;
|
||||
d = (d << 12 | d >>> 20) + a | 0;
|
||||
c += (d & a | ~d & b) + k[10] - 42063 | 0;
|
||||
c = (c << 17 | c >>> 15) + d | 0;
|
||||
b += (c & d | ~c & a) + k[11] - 1990404162 | 0;
|
||||
b = (b << 22 | b >>> 10) + c | 0;
|
||||
a += (b & c | ~b & d) + k[12] + 1804603682 | 0;
|
||||
a = (a << 7 | a >>> 25) + b | 0;
|
||||
d += (a & b | ~a & c) + k[13] - 40341101 | 0;
|
||||
d = (d << 12 | d >>> 20) + a | 0;
|
||||
c += (d & a | ~d & b) + k[14] - 1502002290 | 0;
|
||||
c = (c << 17 | c >>> 15) + d | 0;
|
||||
b += (c & d | ~c & a) + k[15] + 1236535329 | 0;
|
||||
b = (b << 22 | b >>> 10) + c | 0;
|
||||
// gg()
|
||||
a += (b & d | c & ~d) + k[1] - 165796510 | 0;
|
||||
a = (a << 5 | a >>> 27) + b | 0;
|
||||
d += (a & c | b & ~c) + k[6] - 1069501632 | 0;
|
||||
d = (d << 9 | d >>> 23) + a | 0;
|
||||
c += (d & b | a & ~b) + k[11] + 643717713 | 0;
|
||||
c = (c << 14 | c >>> 18) + d | 0;
|
||||
b += (c & a | d & ~a) + k[0] - 373897302 | 0;
|
||||
b = (b << 20 | b >>> 12) + c | 0;
|
||||
a += (b & d | c & ~d) + k[5] - 701558691 | 0;
|
||||
a = (a << 5 | a >>> 27) + b | 0;
|
||||
d += (a & c | b & ~c) + k[10] + 38016083 | 0;
|
||||
d = (d << 9 | d >>> 23) + a | 0;
|
||||
c += (d & b | a & ~b) + k[15] - 660478335 | 0;
|
||||
c = (c << 14 | c >>> 18) + d | 0;
|
||||
b += (c & a | d & ~a) + k[4] - 405537848 | 0;
|
||||
b = (b << 20 | b >>> 12) + c | 0;
|
||||
a += (b & d | c & ~d) + k[9] + 568446438 | 0;
|
||||
a = (a << 5 | a >>> 27) + b | 0;
|
||||
d += (a & c | b & ~c) + k[14] - 1019803690 | 0;
|
||||
d = (d << 9 | d >>> 23) + a | 0;
|
||||
c += (d & b | a & ~b) + k[3] - 187363961 | 0;
|
||||
c = (c << 14 | c >>> 18) + d | 0;
|
||||
b += (c & a | d & ~a) + k[8] + 1163531501 | 0;
|
||||
b = (b << 20 | b >>> 12) + c | 0;
|
||||
a += (b & d | c & ~d) + k[13] - 1444681467 | 0;
|
||||
a = (a << 5 | a >>> 27) + b | 0;
|
||||
d += (a & c | b & ~c) + k[2] - 51403784 | 0;
|
||||
d = (d << 9 | d >>> 23) + a | 0;
|
||||
c += (d & b | a & ~b) + k[7] + 1735328473 | 0;
|
||||
c = (c << 14 | c >>> 18) + d | 0;
|
||||
b += (c & a | d & ~a) + k[12] - 1926607734 | 0;
|
||||
b = (b << 20 | b >>> 12) + c | 0;
|
||||
// hh()
|
||||
a += (b ^ c ^ d) + k[5] - 378558 | 0;
|
||||
a = (a << 4 | a >>> 28) + b | 0;
|
||||
d += (a ^ b ^ c) + k[8] - 2022574463 | 0;
|
||||
d = (d << 11 | d >>> 21) + a | 0;
|
||||
c += (d ^ a ^ b) + k[11] + 1839030562 | 0;
|
||||
c = (c << 16 | c >>> 16) + d | 0;
|
||||
b += (c ^ d ^ a) + k[14] - 35309556 | 0;
|
||||
b = (b << 23 | b >>> 9) + c | 0;
|
||||
a += (b ^ c ^ d) + k[1] - 1530992060 | 0;
|
||||
a = (a << 4 | a >>> 28) + b | 0;
|
||||
d += (a ^ b ^ c) + k[4] + 1272893353 | 0;
|
||||
d = (d << 11 | d >>> 21) + a | 0;
|
||||
c += (d ^ a ^ b) + k[7] - 155497632 | 0;
|
||||
c = (c << 16 | c >>> 16) + d | 0;
|
||||
b += (c ^ d ^ a) + k[10] - 1094730640 | 0;
|
||||
b = (b << 23 | b >>> 9) + c | 0;
|
||||
a += (b ^ c ^ d) + k[13] + 681279174 | 0;
|
||||
a = (a << 4 | a >>> 28) + b | 0;
|
||||
d += (a ^ b ^ c) + k[0] - 358537222 | 0;
|
||||
d = (d << 11 | d >>> 21) + a | 0;
|
||||
c += (d ^ a ^ b) + k[3] - 722521979 | 0;
|
||||
c = (c << 16 | c >>> 16) + d | 0;
|
||||
b += (c ^ d ^ a) + k[6] + 76029189 | 0;
|
||||
b = (b << 23 | b >>> 9) + c | 0;
|
||||
a += (b ^ c ^ d) + k[9] - 640364487 | 0;
|
||||
a = (a << 4 | a >>> 28) + b | 0;
|
||||
d += (a ^ b ^ c) + k[12] - 421815835 | 0;
|
||||
d = (d << 11 | d >>> 21) + a | 0;
|
||||
c += (d ^ a ^ b) + k[15] + 530742520 | 0;
|
||||
c = (c << 16 | c >>> 16) + d | 0;
|
||||
b += (c ^ d ^ a) + k[2] - 995338651 | 0;
|
||||
b = (b << 23 | b >>> 9) + c | 0;
|
||||
// ii()
|
||||
a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;
|
||||
a = (a << 6 | a >>> 26) + b | 0;
|
||||
d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;
|
||||
d = (d << 10 | d >>> 22) + a | 0;
|
||||
c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;
|
||||
c = (c << 15 | c >>> 17) + d | 0;
|
||||
b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;
|
||||
b = (b << 21 | b >>> 11) + c | 0;
|
||||
a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;
|
||||
a = (a << 6 | a >>> 26) + b | 0;
|
||||
d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;
|
||||
d = (d << 10 | d >>> 22) + a | 0;
|
||||
c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;
|
||||
c = (c << 15 | c >>> 17) + d | 0;
|
||||
b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;
|
||||
b = (b << 21 | b >>> 11) + c | 0;
|
||||
a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;
|
||||
a = (a << 6 | a >>> 26) + b | 0;
|
||||
d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;
|
||||
d = (d << 10 | d >>> 22) + a | 0;
|
||||
c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;
|
||||
c = (c << 15 | c >>> 17) + d | 0;
|
||||
b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;
|
||||
b = (b << 21 | b >>> 11) + c | 0;
|
||||
a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;
|
||||
a = (a << 6 | a >>> 26) + b | 0;
|
||||
d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;
|
||||
d = (d << 10 | d >>> 22) + a | 0;
|
||||
c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;
|
||||
c = (c << 15 | c >>> 17) + d | 0;
|
||||
b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;
|
||||
b = (b << 21 | b >>> 11) + c | 0;
|
||||
x[0] = a + x[0] | 0;
|
||||
x[1] = b + x[1] | 0;
|
||||
x[2] = c + x[2] | 0;
|
||||
x[3] = d + x[3] | 0;
|
||||
};
|
||||
Md5.prototype.start = function () {
|
||||
this._dataLength = 0;
|
||||
this._bufferLength = 0;
|
||||
this._state.set(Md5.stateIdentity);
|
||||
return this;
|
||||
};
|
||||
// Char to code point to to array conversion:
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt
|
||||
// #Example.3A_Fixing_charCodeAt_to_handle_non-Basic-Multilingual-Plane_characters_if_their_presence_earlier_in_the_string_is_unknown
|
||||
Md5.prototype.appendStr = function (str) {
|
||||
var buf8 = this._buffer8;
|
||||
var buf32 = this._buffer32;
|
||||
var bufLen = this._bufferLength;
|
||||
var code;
|
||||
var i;
|
||||
for (i = 0; i < str.length; i += 1) {
|
||||
code = str.charCodeAt(i);
|
||||
if (code < 128) {
|
||||
buf8[bufLen++] = code;
|
||||
}
|
||||
else if (code < 0x800) {
|
||||
buf8[bufLen++] = (code >>> 6) + 0xC0;
|
||||
buf8[bufLen++] = code & 0x3F | 0x80;
|
||||
}
|
||||
else if (code < 0xD800 || code > 0xDBFF) {
|
||||
buf8[bufLen++] = (code >>> 12) + 0xE0;
|
||||
buf8[bufLen++] = (code >>> 6 & 0x3F) | 0x80;
|
||||
buf8[bufLen++] = (code & 0x3F) | 0x80;
|
||||
}
|
||||
else {
|
||||
code = ((code - 0xD800) * 0x400) + (str.charCodeAt(++i) - 0xDC00) + 0x10000;
|
||||
if (code > 0x10FFFF) {
|
||||
throw new Error('Unicode standard supports code points up to U+10FFFF');
|
||||
}
|
||||
buf8[bufLen++] = (code >>> 18) + 0xF0;
|
||||
buf8[bufLen++] = (code >>> 12 & 0x3F) | 0x80;
|
||||
buf8[bufLen++] = (code >>> 6 & 0x3F) | 0x80;
|
||||
buf8[bufLen++] = (code & 0x3F) | 0x80;
|
||||
}
|
||||
if (bufLen >= 64) {
|
||||
this._dataLength += 64;
|
||||
Md5._md5cycle(this._state, buf32);
|
||||
bufLen -= 64;
|
||||
buf32[0] = buf32[16];
|
||||
}
|
||||
}
|
||||
this._bufferLength = bufLen;
|
||||
return this;
|
||||
};
|
||||
Md5.prototype.appendAsciiStr = function (str) {
|
||||
var buf8 = this._buffer8;
|
||||
var buf32 = this._buffer32;
|
||||
var bufLen = this._bufferLength;
|
||||
var i;
|
||||
var j = 0;
|
||||
for (;;) {
|
||||
i = Math.min(str.length - j, 64 - bufLen);
|
||||
while (i--) {
|
||||
buf8[bufLen++] = str.charCodeAt(j++);
|
||||
}
|
||||
if (bufLen < 64) {
|
||||
break;
|
||||
}
|
||||
this._dataLength += 64;
|
||||
Md5._md5cycle(this._state, buf32);
|
||||
bufLen = 0;
|
||||
}
|
||||
this._bufferLength = bufLen;
|
||||
return this;
|
||||
};
|
||||
Md5.prototype.appendByteArray = function (input) {
|
||||
var buf8 = this._buffer8;
|
||||
var buf32 = this._buffer32;
|
||||
var bufLen = this._bufferLength;
|
||||
var i;
|
||||
var j = 0;
|
||||
for (;;) {
|
||||
i = Math.min(input.length - j, 64 - bufLen);
|
||||
while (i--) {
|
||||
buf8[bufLen++] = input[j++];
|
||||
}
|
||||
if (bufLen < 64) {
|
||||
break;
|
||||
}
|
||||
this._dataLength += 64;
|
||||
Md5._md5cycle(this._state, buf32);
|
||||
bufLen = 0;
|
||||
}
|
||||
this._bufferLength = bufLen;
|
||||
return this;
|
||||
};
|
||||
Md5.prototype.getState = function () {
|
||||
var self = this;
|
||||
var s = self._state;
|
||||
return {
|
||||
buffer: String.fromCharCode.apply(null, self._buffer8),
|
||||
buflen: self._bufferLength,
|
||||
length: self._dataLength,
|
||||
state: [s[0], s[1], s[2], s[3]]
|
||||
};
|
||||
};
|
||||
Md5.prototype.setState = function (state) {
|
||||
var buf = state.buffer;
|
||||
var x = state.state;
|
||||
var s = this._state;
|
||||
var i;
|
||||
this._dataLength = state.length;
|
||||
this._bufferLength = state.buflen;
|
||||
s[0] = x[0];
|
||||
s[1] = x[1];
|
||||
s[2] = x[2];
|
||||
s[3] = x[3];
|
||||
for (i = 0; i < buf.length; i += 1) {
|
||||
this._buffer8[i] = buf.charCodeAt(i);
|
||||
}
|
||||
};
|
||||
Md5.prototype.end = function (raw) {
|
||||
if (raw === void 0) { raw = false; }
|
||||
var bufLen = this._bufferLength;
|
||||
var buf8 = this._buffer8;
|
||||
var buf32 = this._buffer32;
|
||||
var i = (bufLen >> 2) + 1;
|
||||
var dataBitsLen;
|
||||
this._dataLength += bufLen;
|
||||
buf8[bufLen] = 0x80;
|
||||
buf8[bufLen + 1] = buf8[bufLen + 2] = buf8[bufLen + 3] = 0;
|
||||
buf32.set(Md5.buffer32Identity.subarray(i), i);
|
||||
if (bufLen > 55) {
|
||||
Md5._md5cycle(this._state, buf32);
|
||||
buf32.set(Md5.buffer32Identity);
|
||||
}
|
||||
// Do the final computation based on the tail and length
|
||||
// Beware that the final length may not fit in 32 bits so we take care of that
|
||||
dataBitsLen = this._dataLength * 8;
|
||||
if (dataBitsLen <= 0xFFFFFFFF) {
|
||||
buf32[14] = dataBitsLen;
|
||||
}
|
||||
else {
|
||||
var matches = dataBitsLen.toString(16).match(/(.*?)(.{0,8})$/);
|
||||
if (matches === null) {
|
||||
return;
|
||||
}
|
||||
var lo = parseInt(matches[2], 16);
|
||||
var hi = parseInt(matches[1], 16) || 0;
|
||||
buf32[14] = lo;
|
||||
buf32[15] = hi;
|
||||
}
|
||||
Md5._md5cycle(this._state, buf32);
|
||||
return raw ? this._state : Md5._hex(this._state);
|
||||
};
|
||||
// Private Static Variables
|
||||
Md5.stateIdentity = new Int32Array([1732584193, -271733879, -1732584194, 271733878]);
|
||||
Md5.buffer32Identity = new Int32Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
||||
Md5.hexChars = '0123456789abcdef';
|
||||
Md5.hexOut = [];
|
||||
// Permanent instance is to use for one-call hashing
|
||||
Md5.onePassHasher = new Md5();
|
||||
return Md5;
|
||||
}());
|
||||
export { Md5 };
|
||||
9
assets/scripts/libs/crypto/md5.ts.meta
Normal file
9
assets/scripts/libs/crypto/md5.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b247f0c9-522a-4358-85ae-a223525516c3",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
12
assets/scripts/libs/gzip.meta
Normal file
12
assets/scripts/libs/gzip.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "309a794f-ea53-469b-a13b-7504210605c8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
83
assets/scripts/libs/gzip/crc32.ts
Normal file
83
assets/scripts/libs/gzip/crc32.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
var table = [];
|
||||
var poly = 0xEDB88320; // reverse polynomial
|
||||
|
||||
function makeTable() {
|
||||
var c, n, k;
|
||||
|
||||
for (n = 0; n < 256; n += 1) {
|
||||
c = n;
|
||||
for (k = 0; k < 8; k += 1) {
|
||||
if (c & 1) {
|
||||
c = poly ^ (c >>> 1);
|
||||
} else {
|
||||
c = c >>> 1;
|
||||
}
|
||||
}
|
||||
table[n] = c >>> 0;
|
||||
}
|
||||
}
|
||||
|
||||
function strToArr(str) {
|
||||
// sweet hack to turn string into a 'byte' array
|
||||
return Array.prototype.map.call(str, function (c) {
|
||||
return c.charCodeAt(0);
|
||||
});
|
||||
}
|
||||
|
||||
function crcDirect(arr) {
|
||||
var crc = -1, // initial contents of LFBSR
|
||||
i, j, l, temp;
|
||||
|
||||
for (i = 0, l = arr.length; i < l; i += 1) {
|
||||
temp = (crc ^ arr[i]) & 0xff;
|
||||
|
||||
// read 8 bits one at a time
|
||||
for (j = 0; j < 8; j += 1) {
|
||||
if ((temp & 1) === 1) {
|
||||
temp = (temp >>> 1) ^ poly;
|
||||
} else {
|
||||
temp = (temp >>> 1);
|
||||
}
|
||||
}
|
||||
crc = (crc >>> 8) ^ temp;
|
||||
}
|
||||
|
||||
// flip bits
|
||||
return crc ^ -1;
|
||||
}
|
||||
|
||||
|
||||
function crcTable(arr, append) {
|
||||
var crc, i, l;
|
||||
|
||||
// if we're in append mode, don't reset crc
|
||||
// if arr is null or undefined, reset table and return
|
||||
if (typeof crcTable.crc === 'undefined' || !append || !arr) {
|
||||
crcTable.crc = 0 ^ -1;
|
||||
|
||||
if (!arr) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// store in temp variable for minor speed gain
|
||||
crc = crcTable.crc;
|
||||
|
||||
for (i = 0, l = arr.length; i < l; i += 1) {
|
||||
crc = (crc >>> 8) ^ table[(crc ^ arr[i]) & 0xff];
|
||||
}
|
||||
|
||||
crcTable.crc = crc;
|
||||
|
||||
return crc ^ -1;
|
||||
}
|
||||
|
||||
makeTable();
|
||||
|
||||
export function crc32(val, direct) {
|
||||
var val = (typeof val === 'string') ? strToArr(val) : val,
|
||||
ret = direct ? crcDirect(val) : crcTable(val);
|
||||
|
||||
// convert to 2's complement hex
|
||||
return (ret >>> 0).toString(16);
|
||||
};
|
||||
9
assets/scripts/libs/gzip/crc32.ts.meta
Normal file
9
assets/scripts/libs/gzip/crc32.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "fc769e4d-a6ae-4a81-b1b1-3703913d3afb",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
5
assets/scripts/libs/gzip/deflate-js.ts
Normal file
5
assets/scripts/libs/gzip/deflate-js.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
import {inflate} from "./rawinflate"
|
||||
import {deflate} from "./rawdeflate"
|
||||
|
||||
export {inflate, deflate}
|
||||
9
assets/scripts/libs/gzip/deflate-js.ts.meta
Normal file
9
assets/scripts/libs/gzip/deflate-js.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8f67b3f2-2af7-40ad-bfc9-46a299252d4e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
273
assets/scripts/libs/gzip/gzip.ts
Normal file
273
assets/scripts/libs/gzip/gzip.ts
Normal file
@@ -0,0 +1,273 @@
|
||||
|
||||
|
||||
import { crc32 } from "./crc32";
|
||||
import * as deflate from "./deflate-js";
|
||||
|
||||
// magic numbers marking this file as GZIP
|
||||
var ID1 = 0x1F,
|
||||
ID2 = 0x8B,
|
||||
compressionMethods = {
|
||||
'deflate': 8
|
||||
},
|
||||
possibleFlags = {
|
||||
'FTEXT': 0x01,
|
||||
'FHCRC': 0x02,
|
||||
'FEXTRA': 0x04,
|
||||
'FNAME': 0x08,
|
||||
'FCOMMENT': 0x10
|
||||
},
|
||||
osMap = {
|
||||
'fat': 0, // FAT file system (DOS, OS/2, NT) + PKZIPW 2.50 VFAT, NTFS
|
||||
'amiga': 1, // Amiga
|
||||
'vmz': 2, // VMS (VAX or Alpha AXP)
|
||||
'unix': 3, // Unix
|
||||
'vm/cms': 4, // VM/CMS
|
||||
'atari': 5, // Atari
|
||||
'hpfs': 6, // HPFS file system (OS/2, NT 3.x)
|
||||
'macintosh': 7, // Macintosh
|
||||
'z-system': 8, // Z-System
|
||||
'cplm': 9, // CP/M
|
||||
'tops-20': 10, // TOPS-20
|
||||
'ntfs': 11, // NTFS file system (NT)
|
||||
'qdos': 12, // SMS/QDOS
|
||||
'acorn': 13, // Acorn RISC OS
|
||||
'vfat': 14, // VFAT file system (Win95, NT)
|
||||
'vms': 15, // MVS (code also taken for PRIMOS)
|
||||
'beos': 16, // BeOS (BeBox or PowerMac)
|
||||
'tandem': 17, // Tandem/NSK
|
||||
'theos': 18 // THEOS
|
||||
},
|
||||
os = 'unix',
|
||||
DEFAULT_LEVEL = 6;
|
||||
|
||||
function putByte(n, arr) {
|
||||
arr.push(n & 0xFF);
|
||||
}
|
||||
|
||||
// LSB first
|
||||
function putShort(n, arr) {
|
||||
arr.push(n & 0xFF);
|
||||
arr.push(n >>> 8);
|
||||
}
|
||||
|
||||
// LSB first
|
||||
function putLong(n, arr) {
|
||||
putShort(n & 0xffff, arr);
|
||||
putShort(n >>> 16, arr);
|
||||
}
|
||||
|
||||
function putString(s, arr) {
|
||||
var i, len = s.length;
|
||||
for (i = 0; i < len; i += 1) {
|
||||
putByte(s.charCodeAt(i), arr);
|
||||
}
|
||||
}
|
||||
|
||||
function readByte(arr) {
|
||||
return arr.shift();
|
||||
}
|
||||
|
||||
function readShort(arr) {
|
||||
return arr.shift() | (arr.shift() << 8);
|
||||
}
|
||||
|
||||
function readLong(arr) {
|
||||
var n1 = readShort(arr),
|
||||
n2 = readShort(arr);
|
||||
|
||||
// JavaScript can't handle bits in the position 32
|
||||
// we'll emulate this by removing the left-most bit (if it exists)
|
||||
// and add it back in via multiplication, which does work
|
||||
if (n2 > 32768) {
|
||||
n2 -= 32768;
|
||||
|
||||
return ((n2 << 16) | n1) + 32768 * Math.pow(2, 16);
|
||||
}
|
||||
|
||||
return (n2 << 16) | n1;
|
||||
}
|
||||
|
||||
function readString(arr) {
|
||||
var charArr = [];
|
||||
|
||||
// turn all bytes into chars until the terminating null
|
||||
while (arr[0] !== 0) {
|
||||
charArr.push(String.fromCharCode(arr.shift()));
|
||||
}
|
||||
|
||||
// throw away terminating null
|
||||
arr.shift();
|
||||
|
||||
// join all characters into a cohesive string
|
||||
return charArr.join('');
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads n number of bytes and return as an array.
|
||||
*
|
||||
* @param arr- Array of bytes to read from
|
||||
* @param n- Number of bytes to read
|
||||
*/
|
||||
function readBytes(arr, n) {
|
||||
var i, ret = [];
|
||||
for (i = 0; i < n; i += 1) {
|
||||
ret.push(arr.shift());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* ZIPs a file in GZIP format. The format is as given by the spec, found at:
|
||||
* http://www.gzip.org/zlib/rfc-gzip.html
|
||||
*
|
||||
* Omitted parts in this implementation:
|
||||
*/
|
||||
export function zip(data, options) {
|
||||
var flags = 0,
|
||||
level,
|
||||
crc, out = [];
|
||||
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
level = options.level || DEFAULT_LEVEL;
|
||||
|
||||
if (typeof data === 'string') {
|
||||
data = Array.prototype.map.call(data, function (char) {
|
||||
return char.charCodeAt(0);
|
||||
});
|
||||
}
|
||||
|
||||
// magic number marking this file as GZIP
|
||||
putByte(ID1, out);
|
||||
putByte(ID2, out);
|
||||
|
||||
putByte(compressionMethods['deflate'], out);
|
||||
|
||||
if (options.name) {
|
||||
flags |= possibleFlags['FNAME'];
|
||||
}
|
||||
|
||||
putByte(flags, out);
|
||||
putLong(options.timestamp || parseInt(Date.now() / 1000, 10), out);
|
||||
|
||||
// put deflate args (extra flags)
|
||||
if (level === 1) {
|
||||
// fastest algorithm
|
||||
putByte(4, out);
|
||||
} else if (level === 9) {
|
||||
// maximum compression (fastest algorithm)
|
||||
putByte(2, out);
|
||||
} else {
|
||||
putByte(0, out);
|
||||
}
|
||||
|
||||
// OS identifier
|
||||
putByte(osMap[os], out);
|
||||
|
||||
if (options.name) {
|
||||
// ignore the directory part
|
||||
putString(options.name.substring(options.name.lastIndexOf('/') + 1), out);
|
||||
|
||||
// terminating null
|
||||
putByte(0, out);
|
||||
}
|
||||
|
||||
deflate.deflate(data, level).forEach(function (byte) {
|
||||
putByte(byte, out);
|
||||
});
|
||||
|
||||
putLong(parseInt(crc32(data), 16), out);
|
||||
putLong(data.length, out);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
export function unzip(data) {
|
||||
// start with a copy of the array
|
||||
var arr = Array.prototype.slice.call(data, 0),
|
||||
t,
|
||||
compressionMethod,
|
||||
flags,
|
||||
mtime,
|
||||
xFlags,
|
||||
key,
|
||||
os,
|
||||
crc,
|
||||
size,
|
||||
res;
|
||||
|
||||
// check the first two bytes for the magic numbers
|
||||
if (readByte(arr) !== ID1 || readByte(arr) !== ID2) {
|
||||
throw 'Not a GZIP file';
|
||||
}
|
||||
|
||||
t = readByte(arr);
|
||||
t = Object.keys(compressionMethods).some(function (key) {
|
||||
compressionMethod = key;
|
||||
return compressionMethods[key] === t;
|
||||
});
|
||||
|
||||
if (!t) {
|
||||
throw 'Unsupported compression method';
|
||||
}
|
||||
|
||||
flags = readByte(arr);
|
||||
mtime = readLong(arr);
|
||||
xFlags = readByte(arr);
|
||||
t = readByte(arr);
|
||||
Object.keys(osMap).some(function (key) {
|
||||
if (osMap[key] === t) {
|
||||
os = key;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// just throw away the bytes for now
|
||||
if (flags & possibleFlags['FEXTRA']) {
|
||||
t = readShort(arr);
|
||||
readBytes(arr, t);
|
||||
}
|
||||
|
||||
// just throw away for now
|
||||
if (flags & possibleFlags['FNAME']) {
|
||||
readString(arr);
|
||||
}
|
||||
|
||||
// just throw away for now
|
||||
if (flags & possibleFlags['FCOMMENT']) {
|
||||
readString(arr);
|
||||
}
|
||||
|
||||
// just throw away for now
|
||||
if (flags & possibleFlags['FHCRC']) {
|
||||
readShort(arr);
|
||||
}
|
||||
|
||||
if (compressionMethod === 'deflate') {
|
||||
// give deflate everything but the last 8 bytes
|
||||
// the last 8 bytes are for the CRC32 checksum and filesize
|
||||
res = deflate.inflate(arr.splice(0, arr.length - 8));
|
||||
}
|
||||
|
||||
if (flags & possibleFlags['FTEXT']) {
|
||||
res = Array.prototype.map.call(res, function (byte) {
|
||||
return String.fromCharCode(byte);
|
||||
}).join('');
|
||||
}
|
||||
|
||||
crc = readLong(arr) >>> 0;
|
||||
if (crc !== parseInt(crc32(res), 16)) {
|
||||
throw 'Checksum does not match';
|
||||
}
|
||||
|
||||
size = readLong(arr);
|
||||
if (size !== res.length) {
|
||||
throw 'Size of decompressed file not correct';
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
9
assets/scripts/libs/gzip/gzip.ts.meta
Normal file
9
assets/scripts/libs/gzip/gzip.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "333c586f-0634-4727-b1a3-cbf2d0461cf2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
1692
assets/scripts/libs/gzip/rawdeflate.ts
Normal file
1692
assets/scripts/libs/gzip/rawdeflate.ts
Normal file
File diff suppressed because it is too large
Load Diff
9
assets/scripts/libs/gzip/rawdeflate.ts.meta
Normal file
9
assets/scripts/libs/gzip/rawdeflate.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "edd7bf06-20cc-41a7-ad71-138340c69a5e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
808
assets/scripts/libs/gzip/rawinflate.ts
Normal file
808
assets/scripts/libs/gzip/rawinflate.ts
Normal file
@@ -0,0 +1,808 @@
|
||||
/*
|
||||
* $Id: rawinflate.js,v 0.2 2009/03/01 18:32:24 dankogai Exp $
|
||||
*
|
||||
* original:
|
||||
* http://www.onicos.com/staff/iz/amuse/javascript/expert/inflate.txt
|
||||
*/
|
||||
|
||||
/* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
|
||||
* Version: 1.0.0.1
|
||||
* LastModified: Dec 25 1999
|
||||
*/
|
||||
|
||||
/* Interface:
|
||||
* data = inflate(src);
|
||||
*/
|
||||
|
||||
/* constant parameters */
|
||||
var WSIZE = 32768, // Sliding Window size
|
||||
STORED_BLOCK = 0,
|
||||
STATIC_TREES = 1,
|
||||
DYN_TREES = 2,
|
||||
|
||||
/* for inflate */
|
||||
lbits = 9, // bits in base literal/length lookup table
|
||||
dbits = 6, // bits in base distance lookup table
|
||||
|
||||
/* variables (inflate) */
|
||||
slide,
|
||||
wp, // current position in slide
|
||||
fixed_tl = null, // inflate static
|
||||
fixed_td, // inflate static
|
||||
fixed_bl, // inflate static
|
||||
fixed_bd, // inflate static
|
||||
bit_buf, // bit buffer
|
||||
bit_len, // bits in bit buffer
|
||||
method,
|
||||
eof,
|
||||
copy_leng,
|
||||
copy_dist,
|
||||
tl, // literal length decoder table
|
||||
td, // literal distance decoder table
|
||||
bl, // number of bits decoded by tl
|
||||
bd, // number of bits decoded by td
|
||||
|
||||
inflate_data,
|
||||
inflate_pos,
|
||||
|
||||
|
||||
/* constant tables (inflate) */
|
||||
MASK_BITS = [
|
||||
0x0000,
|
||||
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
|
||||
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
|
||||
],
|
||||
// Tables for deflate from PKZIP's appnote.txt.
|
||||
// Copy lengths for literal codes 257..285
|
||||
cplens = [
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
||||
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
|
||||
],
|
||||
/* note: see note #13 above about the 258 in this list. */
|
||||
// Extra bits for literal codes 257..285
|
||||
cplext = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 // 99==invalid
|
||||
],
|
||||
// Copy offsets for distance codes 0..29
|
||||
cpdist = [
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
||||
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
||||
8193, 12289, 16385, 24577
|
||||
],
|
||||
// Extra bits for distance codes
|
||||
cpdext = [
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
|
||||
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
|
||||
12, 12, 13, 13
|
||||
],
|
||||
// Order of the bit length code lengths
|
||||
border = [
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
|
||||
];
|
||||
/* objects (inflate) */
|
||||
|
||||
function HuftList() {
|
||||
this.next = null;
|
||||
this.list = null;
|
||||
}
|
||||
|
||||
function HuftNode() {
|
||||
this.e = 0; // number of extra bits or operation
|
||||
this.b = 0; // number of bits in this code or subcode
|
||||
|
||||
// union
|
||||
this.n = 0; // literal, length base, or distance base
|
||||
this.t = null; // (HuftNode) pointer to next level of table
|
||||
}
|
||||
|
||||
/*
|
||||
* @param b- code lengths in bits (all assumed <= BMAX)
|
||||
* @param n- number of codes (assumed <= N_MAX)
|
||||
* @param s- number of simple-valued codes (0..s-1)
|
||||
* @param d- list of base values for non-simple codes
|
||||
* @param e- list of extra bits for non-simple codes
|
||||
* @param mm- maximum lookup bits
|
||||
*/
|
||||
function HuftBuild(b, n, s, d, e, mm) {
|
||||
this.BMAX = 16; // maximum bit length of any code
|
||||
this.N_MAX = 288; // maximum number of codes in any set
|
||||
this.status = 0; // 0: success, 1: incomplete table, 2: bad input
|
||||
this.root = null; // (HuftList) starting table
|
||||
this.m = 0; // maximum lookup bits, returns actual
|
||||
|
||||
/* Given a list of code lengths and a maximum table size, make a set of
|
||||
tables to decode that set of codes. Return zero on success, one if
|
||||
the given code set is incomplete (the tables are still built in this
|
||||
case), two if the input is invalid (all zero length codes or an
|
||||
oversubscribed set of lengths), and three if not enough memory.
|
||||
The code with value 256 is special, and the tables are constructed
|
||||
so that no bits beyond that code are fetched when that code is
|
||||
decoded. */
|
||||
var a; // counter for codes of length k
|
||||
var c = [];
|
||||
var el; // length of EOB code (value 256)
|
||||
var f; // i repeats in table every f entries
|
||||
var g; // maximum code length
|
||||
var h; // table level
|
||||
var i; // counter, current code
|
||||
var j; // counter
|
||||
var k; // number of bits in current code
|
||||
var lx = [];
|
||||
var p; // pointer into c[], b[], or v[]
|
||||
var pidx; // index of p
|
||||
var q; // (HuftNode) points to current table
|
||||
var r = new HuftNode(); // table entry for structure assignment
|
||||
var u = [];
|
||||
var v = [];
|
||||
var w;
|
||||
var x = [];
|
||||
var xp; // pointer into x or c
|
||||
var y; // number of dummy codes added
|
||||
var z; // number of entries in current table
|
||||
var o;
|
||||
var tail; // (HuftList)
|
||||
|
||||
tail = this.root = null;
|
||||
|
||||
// bit length count table
|
||||
for (i = 0; i < this.BMAX + 1; i++) {
|
||||
c[i] = 0;
|
||||
}
|
||||
// stack of bits per table
|
||||
for (i = 0; i < this.BMAX + 1; i++) {
|
||||
lx[i] = 0;
|
||||
}
|
||||
// HuftNode[BMAX][] table stack
|
||||
for (i = 0; i < this.BMAX; i++) {
|
||||
u[i] = null;
|
||||
}
|
||||
// values in order of bit length
|
||||
for (i = 0; i < this.N_MAX; i++) {
|
||||
v[i] = 0;
|
||||
}
|
||||
// bit offsets, then code stack
|
||||
for (i = 0; i < this.BMAX + 1; i++) {
|
||||
x[i] = 0;
|
||||
}
|
||||
|
||||
// Generate counts for each bit length
|
||||
el = n > 256 ? b[256] : this.BMAX; // set length of EOB code, if any
|
||||
p = b; pidx = 0;
|
||||
i = n;
|
||||
do {
|
||||
c[p[pidx]]++; // assume all entries <= BMAX
|
||||
pidx++;
|
||||
} while (--i > 0);
|
||||
if (c[0] === n) { // null input--all zero length codes
|
||||
this.root = null;
|
||||
this.m = 0;
|
||||
this.status = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Find minimum and maximum length, bound *m by those
|
||||
for (j = 1; j <= this.BMAX; j++) {
|
||||
if (c[j] !== 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
k = j; // minimum code length
|
||||
if (mm < j) {
|
||||
mm = j;
|
||||
}
|
||||
for (i = this.BMAX; i !== 0; i--) {
|
||||
if (c[i] !== 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
g = i; // maximum code length
|
||||
if (mm > i) {
|
||||
mm = i;
|
||||
}
|
||||
|
||||
// Adjust last length count to fill out codes, if needed
|
||||
for (y = 1 << j; j < i; j++, y <<= 1) {
|
||||
if ((y -= c[j]) < 0) {
|
||||
this.status = 2; // bad input: more codes than bits
|
||||
this.m = mm;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ((y -= c[i]) < 0) {
|
||||
this.status = 2;
|
||||
this.m = mm;
|
||||
return;
|
||||
}
|
||||
c[i] += y;
|
||||
|
||||
// Generate starting offsets into the value table for each length
|
||||
x[1] = j = 0;
|
||||
p = c;
|
||||
pidx = 1;
|
||||
xp = 2;
|
||||
while (--i > 0) { // note that i == g from above
|
||||
x[xp++] = (j += p[pidx++]);
|
||||
}
|
||||
|
||||
// Make a table of values in order of bit lengths
|
||||
p = b; pidx = 0;
|
||||
i = 0;
|
||||
do {
|
||||
if ((j = p[pidx++]) !== 0) {
|
||||
v[x[j]++] = i;
|
||||
}
|
||||
} while (++i < n);
|
||||
n = x[g]; // set n to length of v
|
||||
|
||||
// Generate the Huffman codes and for each, make the table entries
|
||||
x[0] = i = 0; // first Huffman code is zero
|
||||
p = v; pidx = 0; // grab values in bit order
|
||||
h = -1; // no tables yet--level -1
|
||||
w = lx[0] = 0; // no bits decoded yet
|
||||
q = null; // ditto
|
||||
z = 0; // ditto
|
||||
|
||||
// go through the bit lengths (k already is bits in shortest code)
|
||||
for (null; k <= g; k++) {
|
||||
a = c[k];
|
||||
while (a-- > 0) {
|
||||
// here i is the Huffman code of length k bits for value p[pidx]
|
||||
// make tables up to required level
|
||||
while (k > w + lx[1 + h]) {
|
||||
w += lx[1 + h]; // add bits already decoded
|
||||
h++;
|
||||
|
||||
// compute minimum size table less than or equal to *m bits
|
||||
z = (z = g - w) > mm ? mm : z; // upper limit
|
||||
if ((f = 1 << (j = k - w)) > a + 1) { // try a k-w bit table
|
||||
// too few codes for k-w bit table
|
||||
f -= a + 1; // deduct codes from patterns left
|
||||
xp = k;
|
||||
while (++j < z) { // try smaller tables up to z bits
|
||||
if ((f <<= 1) <= c[++xp]) {
|
||||
break; // enough codes to use up j bits
|
||||
}
|
||||
f -= c[xp]; // else deduct codes from patterns
|
||||
}
|
||||
}
|
||||
if (w + j > el && w < el) {
|
||||
j = el - w; // make EOB code end at table
|
||||
}
|
||||
z = 1 << j; // table entries for j-bit table
|
||||
lx[1 + h] = j; // set table size in stack
|
||||
|
||||
// allocate and link in new table
|
||||
q = [];
|
||||
for (o = 0; o < z; o++) {
|
||||
q[o] = new HuftNode();
|
||||
}
|
||||
|
||||
if (!tail) {
|
||||
tail = this.root = new HuftList();
|
||||
} else {
|
||||
tail = tail.next = new HuftList();
|
||||
}
|
||||
tail.next = null;
|
||||
tail.list = q;
|
||||
u[h] = q; // table starts after link
|
||||
|
||||
/* connect to last table, if there is one */
|
||||
if (h > 0) {
|
||||
x[h] = i; // save pattern for backing up
|
||||
r.b = lx[h]; // bits to dump before this table
|
||||
r.e = 16 + j; // bits in this table
|
||||
r.t = q; // pointer to this table
|
||||
j = (i & ((1 << w) - 1)) >> (w - lx[h]);
|
||||
u[h - 1][j].e = r.e;
|
||||
u[h - 1][j].b = r.b;
|
||||
u[h - 1][j].n = r.n;
|
||||
u[h - 1][j].t = r.t;
|
||||
}
|
||||
}
|
||||
|
||||
// set up table entry in r
|
||||
r.b = k - w;
|
||||
if (pidx >= n) {
|
||||
r.e = 99; // out of values--invalid code
|
||||
} else if (p[pidx] < s) {
|
||||
r.e = (p[pidx] < 256 ? 16 : 15); // 256 is end-of-block code
|
||||
r.n = p[pidx++]; // simple code is just the value
|
||||
} else {
|
||||
r.e = e[p[pidx] - s]; // non-simple--look up in lists
|
||||
r.n = d[p[pidx++] - s];
|
||||
}
|
||||
|
||||
// fill code-like entries with r //
|
||||
f = 1 << (k - w);
|
||||
for (j = i >> w; j < z; j += f) {
|
||||
q[j].e = r.e;
|
||||
q[j].b = r.b;
|
||||
q[j].n = r.n;
|
||||
q[j].t = r.t;
|
||||
}
|
||||
|
||||
// backwards increment the k-bit code i
|
||||
for (j = 1 << (k - 1); (i & j) !== 0; j >>= 1) {
|
||||
i ^= j;
|
||||
}
|
||||
i ^= j;
|
||||
|
||||
// backup over finished tables
|
||||
while ((i & ((1 << w) - 1)) !== x[h]) {
|
||||
w -= lx[h]; // don't need to update q
|
||||
h--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* return actual size of base table */
|
||||
this.m = lx[1];
|
||||
|
||||
/* Return true (1) if we were given an incomplete table */
|
||||
this.status = ((y !== 0 && g !== 1) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
/* routines (inflate) */
|
||||
|
||||
function GET_BYTE() {
|
||||
if (inflate_data.length === inflate_pos) {
|
||||
return -1;
|
||||
}
|
||||
return inflate_data[inflate_pos++] & 0xff;
|
||||
}
|
||||
|
||||
function NEEDBITS(n) {
|
||||
while (bit_len < n) {
|
||||
bit_buf |= GET_BYTE() << bit_len;
|
||||
bit_len += 8;
|
||||
}
|
||||
}
|
||||
|
||||
function GETBITS(n) {
|
||||
return bit_buf & MASK_BITS[n];
|
||||
}
|
||||
|
||||
function DUMPBITS(n) {
|
||||
bit_buf >>= n;
|
||||
bit_len -= n;
|
||||
}
|
||||
|
||||
function inflate_codes(buff, off, size) {
|
||||
// inflate (decompress) the codes in a deflated (compressed) block.
|
||||
// Return an error code or zero if it all goes ok.
|
||||
var e; // table entry flag/number of extra bits
|
||||
var t; // (HuftNode) pointer to table entry
|
||||
var n;
|
||||
|
||||
if (size === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// inflate the coded data
|
||||
n = 0;
|
||||
for (;;) { // do until end of block
|
||||
NEEDBITS(bl);
|
||||
t = tl.list[GETBITS(bl)];
|
||||
e = t.e;
|
||||
while (e > 16) {
|
||||
if (e === 99) {
|
||||
return -1;
|
||||
}
|
||||
DUMPBITS(t.b);
|
||||
e -= 16;
|
||||
NEEDBITS(e);
|
||||
t = t.t[GETBITS(e)];
|
||||
e = t.e;
|
||||
}
|
||||
DUMPBITS(t.b);
|
||||
|
||||
if (e === 16) { // then it's a literal
|
||||
wp &= WSIZE - 1;
|
||||
buff[off + n++] = slide[wp++] = t.n;
|
||||
if (n === size) {
|
||||
return size;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// exit if end of block
|
||||
if (e === 15) {
|
||||
break;
|
||||
}
|
||||
|
||||
// it's an EOB or a length
|
||||
|
||||
// get length of block to copy
|
||||
NEEDBITS(e);
|
||||
copy_leng = t.n + GETBITS(e);
|
||||
DUMPBITS(e);
|
||||
|
||||
// decode distance of block to copy
|
||||
NEEDBITS(bd);
|
||||
t = td.list[GETBITS(bd)];
|
||||
e = t.e;
|
||||
|
||||
while (e > 16) {
|
||||
if (e === 99) {
|
||||
return -1;
|
||||
}
|
||||
DUMPBITS(t.b);
|
||||
e -= 16;
|
||||
NEEDBITS(e);
|
||||
t = t.t[GETBITS(e)];
|
||||
e = t.e;
|
||||
}
|
||||
DUMPBITS(t.b);
|
||||
NEEDBITS(e);
|
||||
copy_dist = wp - t.n - GETBITS(e);
|
||||
DUMPBITS(e);
|
||||
|
||||
// do the copy
|
||||
while (copy_leng > 0 && n < size) {
|
||||
copy_leng--;
|
||||
copy_dist &= WSIZE - 1;
|
||||
wp &= WSIZE - 1;
|
||||
buff[off + n++] = slide[wp++] = slide[copy_dist++];
|
||||
}
|
||||
|
||||
if (n === size) {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
method = -1; // done
|
||||
return n;
|
||||
}
|
||||
|
||||
function inflate_stored(buff, off, size) {
|
||||
/* "decompress" an inflated type 0 (stored) block. */
|
||||
var n;
|
||||
|
||||
// go to byte boundary
|
||||
n = bit_len & 7;
|
||||
DUMPBITS(n);
|
||||
|
||||
// get the length and its complement
|
||||
NEEDBITS(16);
|
||||
n = GETBITS(16);
|
||||
DUMPBITS(16);
|
||||
NEEDBITS(16);
|
||||
if (n !== ((~bit_buf) & 0xffff)) {
|
||||
return -1; // error in compressed data
|
||||
}
|
||||
DUMPBITS(16);
|
||||
|
||||
// read and output the compressed data
|
||||
copy_leng = n;
|
||||
|
||||
n = 0;
|
||||
while (copy_leng > 0 && n < size) {
|
||||
copy_leng--;
|
||||
wp &= WSIZE - 1;
|
||||
NEEDBITS(8);
|
||||
buff[off + n++] = slide[wp++] = GETBITS(8);
|
||||
DUMPBITS(8);
|
||||
}
|
||||
|
||||
if (copy_leng === 0) {
|
||||
method = -1; // done
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
function inflate_fixed(buff, off, size) {
|
||||
// decompress an inflated type 1 (fixed Huffman codes) block. We should
|
||||
// either replace this with a custom decoder, or at least precompute the
|
||||
// Huffman tables.
|
||||
|
||||
// if first time, set up tables for fixed blocks
|
||||
if (!fixed_tl) {
|
||||
var i; // temporary variable
|
||||
var l = []; // 288 length list for huft_build (initialized below)
|
||||
var h; // HuftBuild
|
||||
|
||||
// literal table
|
||||
for (i = 0; i < 144; i++) {
|
||||
l[i] = 8;
|
||||
}
|
||||
for (null; i < 256; i++) {
|
||||
l[i] = 9;
|
||||
}
|
||||
for (null; i < 280; i++) {
|
||||
l[i] = 7;
|
||||
}
|
||||
for (null; i < 288; i++) { // make a complete, but wrong code set
|
||||
l[i] = 8;
|
||||
}
|
||||
fixed_bl = 7;
|
||||
|
||||
h = new HuftBuild(l, 288, 257, cplens, cplext, fixed_bl);
|
||||
if (h.status !== 0) {
|
||||
console.error("HufBuild error: " + h.status);
|
||||
return -1;
|
||||
}
|
||||
fixed_tl = h.root;
|
||||
fixed_bl = h.m;
|
||||
|
||||
// distance table
|
||||
for (i = 0; i < 30; i++) { // make an incomplete code set
|
||||
l[i] = 5;
|
||||
}
|
||||
fixed_bd = 5;
|
||||
|
||||
h = new HuftBuild(l, 30, 0, cpdist, cpdext, fixed_bd);
|
||||
if (h.status > 1) {
|
||||
fixed_tl = null;
|
||||
console.error("HufBuild error: " + h.status);
|
||||
return -1;
|
||||
}
|
||||
fixed_td = h.root;
|
||||
fixed_bd = h.m;
|
||||
}
|
||||
|
||||
tl = fixed_tl;
|
||||
td = fixed_td;
|
||||
bl = fixed_bl;
|
||||
bd = fixed_bd;
|
||||
return inflate_codes(buff, off, size);
|
||||
}
|
||||
|
||||
function inflate_dynamic(buff, off, size) {
|
||||
// decompress an inflated type 2 (dynamic Huffman codes) block.
|
||||
var i; // temporary variables
|
||||
var j;
|
||||
var l; // last length
|
||||
var n; // number of lengths to get
|
||||
var t; // (HuftNode) literal/length code table
|
||||
var nb; // number of bit length codes
|
||||
var nl; // number of literal/length codes
|
||||
var nd; // number of distance codes
|
||||
var ll = [];
|
||||
var h; // (HuftBuild)
|
||||
|
||||
// literal/length and distance code lengths
|
||||
for (i = 0; i < 286 + 30; i++) {
|
||||
ll[i] = 0;
|
||||
}
|
||||
|
||||
// read in table lengths
|
||||
NEEDBITS(5);
|
||||
nl = 257 + GETBITS(5); // number of literal/length codes
|
||||
DUMPBITS(5);
|
||||
NEEDBITS(5);
|
||||
nd = 1 + GETBITS(5); // number of distance codes
|
||||
DUMPBITS(5);
|
||||
NEEDBITS(4);
|
||||
nb = 4 + GETBITS(4); // number of bit length codes
|
||||
DUMPBITS(4);
|
||||
if (nl > 286 || nd > 30) {
|
||||
return -1; // bad lengths
|
||||
}
|
||||
|
||||
// read in bit-length-code lengths
|
||||
for (j = 0; j < nb; j++) {
|
||||
NEEDBITS(3);
|
||||
ll[border[j]] = GETBITS(3);
|
||||
DUMPBITS(3);
|
||||
}
|
||||
for (null; j < 19; j++) {
|
||||
ll[border[j]] = 0;
|
||||
}
|
||||
|
||||
// build decoding table for trees--single level, 7 bit lookup
|
||||
bl = 7;
|
||||
h = new HuftBuild(ll, 19, 19, null, null, bl);
|
||||
if (h.status !== 0) {
|
||||
return -1; // incomplete code set
|
||||
}
|
||||
|
||||
tl = h.root;
|
||||
bl = h.m;
|
||||
|
||||
// read in literal and distance code lengths
|
||||
n = nl + nd;
|
||||
i = l = 0;
|
||||
while (i < n) {
|
||||
NEEDBITS(bl);
|
||||
t = tl.list[GETBITS(bl)];
|
||||
j = t.b;
|
||||
DUMPBITS(j);
|
||||
j = t.n;
|
||||
if (j < 16) { // length of code in bits (0..15)
|
||||
ll[i++] = l = j; // save last length in l
|
||||
} else if (j === 16) { // repeat last length 3 to 6 times
|
||||
NEEDBITS(2);
|
||||
j = 3 + GETBITS(2);
|
||||
DUMPBITS(2);
|
||||
if (i + j > n) {
|
||||
return -1;
|
||||
}
|
||||
while (j-- > 0) {
|
||||
ll[i++] = l;
|
||||
}
|
||||
} else if (j === 17) { // 3 to 10 zero length codes
|
||||
NEEDBITS(3);
|
||||
j = 3 + GETBITS(3);
|
||||
DUMPBITS(3);
|
||||
if (i + j > n) {
|
||||
return -1;
|
||||
}
|
||||
while (j-- > 0) {
|
||||
ll[i++] = 0;
|
||||
}
|
||||
l = 0;
|
||||
} else { // j === 18: 11 to 138 zero length codes
|
||||
NEEDBITS(7);
|
||||
j = 11 + GETBITS(7);
|
||||
DUMPBITS(7);
|
||||
if (i + j > n) {
|
||||
return -1;
|
||||
}
|
||||
while (j-- > 0) {
|
||||
ll[i++] = 0;
|
||||
}
|
||||
l = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// build the decoding tables for literal/length and distance codes
|
||||
bl = lbits;
|
||||
h = new HuftBuild(ll, nl, 257, cplens, cplext, bl);
|
||||
if (bl === 0) { // no literals or lengths
|
||||
h.status = 1;
|
||||
}
|
||||
if (h.status !== 0) {
|
||||
if (h.status !== 1) {
|
||||
return -1; // incomplete code set
|
||||
}
|
||||
// **incomplete literal tree**
|
||||
}
|
||||
tl = h.root;
|
||||
bl = h.m;
|
||||
|
||||
for (i = 0; i < nd; i++) {
|
||||
ll[i] = ll[i + nl];
|
||||
}
|
||||
bd = dbits;
|
||||
h = new HuftBuild(ll, nd, 0, cpdist, cpdext, bd);
|
||||
td = h.root;
|
||||
bd = h.m;
|
||||
|
||||
if (bd === 0 && nl > 257) { // lengths but no distances
|
||||
// **incomplete distance tree**
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
if (h.status === 1) {
|
||||
// **incomplete distance tree**
|
||||
}
|
||||
*/
|
||||
if (h.status !== 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// decompress until an end-of-block code
|
||||
return inflate_codes(buff, off, size);
|
||||
}
|
||||
|
||||
function inflate_start() {
|
||||
if (!slide) {
|
||||
slide = []; // new Array(2 * WSIZE); // slide.length is never called
|
||||
}
|
||||
wp = 0;
|
||||
bit_buf = 0;
|
||||
bit_len = 0;
|
||||
method = -1;
|
||||
eof = false;
|
||||
copy_leng = copy_dist = 0;
|
||||
tl = null;
|
||||
}
|
||||
|
||||
function inflate_internal(buff, off, size) {
|
||||
// decompress an inflated entry
|
||||
var n, i;
|
||||
|
||||
n = 0;
|
||||
while (n < size) {
|
||||
if (eof && method === -1) {
|
||||
return n;
|
||||
}
|
||||
|
||||
if (copy_leng > 0) {
|
||||
if (method !== STORED_BLOCK) {
|
||||
// STATIC_TREES or DYN_TREES
|
||||
while (copy_leng > 0 && n < size) {
|
||||
copy_leng--;
|
||||
copy_dist &= WSIZE - 1;
|
||||
wp &= WSIZE - 1;
|
||||
buff[off + n++] = slide[wp++] = slide[copy_dist++];
|
||||
}
|
||||
} else {
|
||||
while (copy_leng > 0 && n < size) {
|
||||
copy_leng--;
|
||||
wp &= WSIZE - 1;
|
||||
NEEDBITS(8);
|
||||
buff[off + n++] = slide[wp++] = GETBITS(8);
|
||||
DUMPBITS(8);
|
||||
}
|
||||
if (copy_leng === 0) {
|
||||
method = -1; // done
|
||||
}
|
||||
}
|
||||
if (n === size) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
if (method === -1) {
|
||||
if (eof) {
|
||||
break;
|
||||
}
|
||||
|
||||
// read in last block bit
|
||||
NEEDBITS(1);
|
||||
if (GETBITS(1) !== 0) {
|
||||
eof = true;
|
||||
}
|
||||
DUMPBITS(1);
|
||||
|
||||
// read in block type
|
||||
NEEDBITS(2);
|
||||
method = GETBITS(2);
|
||||
DUMPBITS(2);
|
||||
tl = null;
|
||||
copy_leng = 0;
|
||||
}
|
||||
|
||||
switch (method) {
|
||||
case STORED_BLOCK:
|
||||
i = inflate_stored(buff, off + n, size - n);
|
||||
break;
|
||||
|
||||
case STATIC_TREES:
|
||||
if (tl) {
|
||||
i = inflate_codes(buff, off + n, size - n);
|
||||
} else {
|
||||
i = inflate_fixed(buff, off + n, size - n);
|
||||
}
|
||||
break;
|
||||
|
||||
case DYN_TREES:
|
||||
if (tl) {
|
||||
i = inflate_codes(buff, off + n, size - n);
|
||||
} else {
|
||||
i = inflate_dynamic(buff, off + n, size - n);
|
||||
}
|
||||
break;
|
||||
|
||||
default: // error
|
||||
i = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (i === -1) {
|
||||
if (eof) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
n += i;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
export function inflate(arr) {
|
||||
var buff = [], i;
|
||||
|
||||
inflate_start();
|
||||
inflate_data = arr;
|
||||
inflate_pos = 0;
|
||||
|
||||
do {
|
||||
i = inflate_internal(buff, buff.length, 1024);
|
||||
} while (i > 0);
|
||||
inflate_data = null; // G.C.
|
||||
return buff;
|
||||
}
|
||||
9
assets/scripts/libs/gzip/rawinflate.ts.meta
Normal file
9
assets/scripts/libs/gzip/rawinflate.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "05939942-dd2a-4db3-be1e-079633424127",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user