initial commit, kind of working.

This commit is contained in:
2026-10-10 15:50:17 -06:00
commit 4db96b0bae
1041 changed files with 51423 additions and 0 deletions
@@ -0,0 +1,67 @@
package com.newgrounds.encoders
{
import flash.utils.Dictionary;
public class BaseN
{
private static const DEFAULT_HASH:String = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~@#$%^&*()+|;/";
private var _hash:String;
private var _base:uint;
private var _reverseHash:Dictionary;
public function BaseN(param1:String)
{
super();
if(param1)
{
this._hash = param1;
}
else
{
this._hash = DEFAULT_HASH;
}
this._base = this._hash.length;
this._reverseHash = new Dictionary();
var _loc2_:uint = 0;
while(_loc2_ < this._hash.length)
{
this._reverseHash[this._hash.charAt(_loc2_)] = _loc2_;
_loc2_++;
}
}
public function encodeUint(param1:uint, param2:uint = 1) : String
{
var _loc3_:String = "";
var _loc4_:uint = param1;
while(_loc4_ != 0)
{
_loc3_ = this._hash.charAt(_loc4_ % this._base) + _loc3_;
_loc4_ /= this._base;
}
while(_loc3_.length < param2)
{
_loc3_ = this._hash.charAt(0) + _loc3_;
}
return _loc3_;
}
public function decodeUint(param1:String) : uint
{
var _loc2_:uint = 0;
var _loc3_:uint = 0;
while(_loc3_ < param1.length)
{
_loc2_ *= this._base;
_loc2_ += this._reverseHash[param1.charAt(_loc3_)];
_loc3_++;
}
return _loc2_;
}
}
}
@@ -0,0 +1,122 @@
package com.newgrounds.encoders
{
import flash.display.BitmapData;
import flash.geom.*;
import flash.utils.ByteArray;
public class PNGEncoder
{
private static var crcTable:Array;
private static var crcTableComputed:Boolean = false;
public function PNGEncoder()
{
super();
}
public static function encode(param1:BitmapData) : ByteArray
{
var _loc6_:uint = 0;
var _loc7_:int = 0;
var _loc2_:ByteArray = new ByteArray();
_loc2_.writeUnsignedInt(2303741511);
_loc2_.writeUnsignedInt(218765834);
var _loc3_:ByteArray = new ByteArray();
_loc3_.writeInt(param1.width);
_loc3_.writeInt(param1.height);
_loc3_.writeUnsignedInt(134610944);
_loc3_.writeByte(0);
writeChunk(_loc2_,1229472850,_loc3_);
var _loc4_:ByteArray = new ByteArray();
var _loc5_:int = 0;
while(_loc5_ < param1.height)
{
_loc4_.writeByte(0);
if(!param1.transparent)
{
_loc7_ = 0;
while(_loc7_ < param1.width)
{
_loc6_ = param1.getPixel(_loc7_,_loc5_);
_loc4_.writeUnsignedInt(uint((_loc6_ & 0xFFFFFF) << 8 | 0xFF));
_loc7_++;
}
}
else
{
_loc7_ = 0;
while(_loc7_ < param1.width)
{
_loc6_ = param1.getPixel32(_loc7_,_loc5_);
_loc4_.writeUnsignedInt(uint((_loc6_ & 0xFFFFFF) << 8 | _loc6_ >>> 24));
_loc7_++;
}
}
_loc5_++;
}
_loc4_.compress();
writeChunk(_loc2_,1229209940,_loc4_);
writeChunk(_loc2_,1229278788,null);
return _loc2_;
}
private static function writeChunk(param1:ByteArray, param2:uint, param3:ByteArray) : void
{
var _loc8_:uint = 0;
var _loc9_:uint = 0;
var _loc10_:uint = 0;
if(!crcTableComputed)
{
crcTableComputed = true;
crcTable = [];
_loc9_ = 0;
while(_loc9_ < 256)
{
_loc8_ = _loc9_;
_loc10_ = 0;
while(_loc10_ < 8)
{
if(_loc8_ & 1)
{
_loc8_ = uint(uint(3988292384) ^ uint(_loc8_ >>> 1));
}
else
{
_loc8_ = uint(_loc8_ >>> 1);
}
_loc10_++;
}
crcTable[_loc9_] = _loc8_;
_loc9_++;
}
}
var _loc4_:uint = 0;
if(param3 != null)
{
_loc4_ = param3.length;
}
param1.writeUnsignedInt(_loc4_);
var _loc5_:uint = param1.position;
param1.writeUnsignedInt(param2);
if(param3 != null)
{
param1.writeBytes(param3);
}
var _loc6_:uint = param1.position;
param1.position = _loc5_;
_loc8_ = 4294967295;
var _loc7_:int = 0;
while(_loc7_ < _loc6_ - _loc5_)
{
_loc8_ = uint(crcTable[(_loc8_ ^ param1.readUnsignedByte()) & uint(255)] ^ uint(_loc8_ >>> 8));
_loc7_++;
}
_loc8_ = uint(_loc8_ ^ uint(4294967295));
param1.position = _loc6_;
param1.writeUnsignedInt(_loc8_);
}
}
}
@@ -0,0 +1,22 @@
package com.newgrounds.encoders.json
{
public class JSON
{
public function JSON()
{
super();
}
public static function encode(param1:Object) : String
{
return encodeJson(param1);
}
public static function decode(param1:String) : Object
{
return decodeJson(param1);
}
}
}
@@ -0,0 +1,320 @@
package com.newgrounds.encoders.json
{
public const decodeJson:Function = initDecodeJson();
}
import com.newgrounds.encoders.json.§com.newgrounds.encoders.json.decodeJson§;
import flash.utils.ByteArray;
function initDecodeJson():Function
{
var i:int;
var parseStringEscaped:Function;
var position:uint = 0;
var byteInput:ByteArray = null;
var char:uint = 0;
var charConvert:ByteArray = null;
var isNumberChar:ByteArray = null;
var stringHelper:ByteArray = null;
var isWhitespace:ByteArray = null;
var parseNumber:Function = null;
var parseWhitespace:Function = null;
var parse:Object = null;
charConvert = new ByteArray();
charConvert.length = 256;
charConvert[34] = 34;
charConvert[92] = 92;
charConvert[47] = 47;
charConvert[98] = 8;
charConvert[102] = 12;
charConvert[110] = 10;
charConvert[114] = 13;
charConvert[116] = 9;
isNumberChar = new ByteArray();
isNumberChar.length = 256;
isNumberChar[43] = 1;
isNumberChar[45] = 1;
isNumberChar[46] = 1;
isNumberChar[48] = 1;
isNumberChar[49] = 1;
isNumberChar[50] = 1;
isNumberChar[51] = 1;
isNumberChar[52] = 1;
isNumberChar[53] = 1;
isNumberChar[54] = 1;
isNumberChar[55] = 1;
isNumberChar[56] = 1;
isNumberChar[57] = 1;
isNumberChar[69] = 1;
isNumberChar[101] = 1;
stringHelper = new ByteArray();
stringHelper.length = 256;
i = 0;
while(i < 256)
{
stringHelper[i++] = 1;
}
stringHelper[34] = 0;
stringHelper[92] = 0;
isWhitespace = new ByteArray();
isWhitespace.length = 256;
isWhitespace[9] = 1;
isWhitespace[10] = 1;
isWhitespace[13] = 1;
isWhitespace[32] = 1;
parseNumber = function():Number
{
if(position === 1)
{
byteInput.position = 0;
return parseFloat(byteInput.readUTFBytes(byteInput.length));
}
byteInput.position = position - 1;
while(isNumberChar[byteInput[position++]])
{
}
return Number(byteInput.readUTFBytes(position-- - byteInput.position - 1));
};
parseWhitespace = function():Object
{
while(isWhitespace[byteInput[position]])
{
position++;
}
return parse[byteInput[position++]]();
};
parseStringEscaped = function(param1:String):String
{
while(true)
{
if((char = byteInput[position++]) === 117)
{
byteInput.position = position;
char = parseInt(byteInput.readUTFBytes(4),16);
position = position + 4;
}
else
{
if(!(char = charConvert[char]))
{
break;
}
byteInput.position = position;
}
param1 = param1 + String.fromCharCode(char);
while(stringHelper[byteInput[position++]])
{
}
if(position - 1 > byteInput.position)
{
param1 = param1 + byteInput.readUTFBytes(position - 1 - byteInput.position);
}
if(byteInput[position - 1] !== 92)
{
return param1;
}
}
throw new Error("Unknown escaped character encountered at position " + (position - 1));
};
parse = {
34:function():String
{
if(stringHelper[byteInput[position++]])
{
byteInput.position = position - 1;
while(stringHelper[byteInput[position++]])
{
}
if(byteInput[position - 1] === 92)
{
return parseStringEscaped(byteInput.readUTFBytes(position - 1 - byteInput.position));
}
return byteInput.readUTFBytes(position - 1 - byteInput.position);
}
if(byteInput[position - 1] === 92)
{
return parseStringEscaped("");
}
return "";
},
123:function():Object
{
var _loc2_:* = undefined;
while(isWhitespace[byteInput[position]])
{
position++;
}
if(byteInput[position] === 125)
{
position++;
return {};
}
var _loc1_:* = {};
loop1:
while(true)
{
do
{
_loc2_ = parse[byteInput[position++]]();
if(byteInput[position] !== 58)
{
while(isWhitespace[byteInput[position]])
{
position++;
}
if(byteInput[position++] !== 58)
{
break loop1;
}
}
else
{
position++;
}
_loc1_[_loc2_] = parse[byteInput[position++]]();
}
while(byteInput[position++] === 44);
if(byteInput[position - 1] === 125)
{
return _loc1_;
}
while(isWhitespace[byteInput[position]])
{
position++;
}
if(byteInput[position++] !== 44)
{
if(byteInput[position - 1] !== 125)
{
throw new Error("Expected , or } at " + (position - 1));
}
return _loc1_;
}
}
throw new Error("Expected : at " + (position - 1));
},
91:function():Object
{
while(isWhitespace[byteInput[position]])
{
position++;
}
if(byteInput[position] === 93)
{
position++;
return [];
}
var _loc1_:* = [];
while(true)
{
do
{
_loc1_[_loc1_.length] = parse[byteInput[position++]]();
}
while(byteInput[position++] === 44);
if(byteInput[position - 1] === 93)
{
break;
}
position--;
while(isWhitespace[byteInput[position]])
{
position++;
}
if(byteInput[position++] !== 44)
{
if(byteInput[position - 1] !== 93)
{
throw new Error("Expected , or ] at " + (position - 1));
}
return _loc1_;
}
}
return _loc1_;
},
116:function():Boolean
{
if(byteInput[position] === 114 && byteInput[position + 1] === 117 && byteInput[position + 2] === 101)
{
position = position + 3;
return true;
}
throw new Error("Expected \"true\" at position " + position);
},
102:function():Boolean
{
if(byteInput[position] === 97 && byteInput[position + 1] === 108 && byteInput[position + 2] === 115 && byteInput[position + 3] === 101)
{
position = position + 4;
return false;
}
throw new Error("Expected \"false\" at position " + (position - 1));
},
110:function():Object
{
if(byteInput[position] === 117 && byteInput[position + 1] === 108 && byteInput[position + 2] === 108)
{
position = position + 3;
return null;
}
throw new Error("Expected \"null\" at position " + position);
},
110:function():void
{
throw new Error("Unexpected end of array at " + position);
},
125:function():void
{
throw new Error("Unexpected end of object at " + position);
},
44:function():void
{
throw new Error("Unexpected comma at " + position);
},
45:parseNumber,
48:parseNumber,
49:parseNumber,
50:parseNumber,
51:parseNumber,
52:parseNumber,
53:parseNumber,
54:parseNumber,
55:parseNumber,
56:parseNumber,
57:parseNumber,
13:parseWhitespace,
10:parseWhitespace,
9:parseWhitespace,
32:parseWhitespace
};
return function(param1:*):Object
{
var input:* = param1;
if(input is String)
{
byteInput = new ByteArray();
byteInput.writeUTFBytes(input as String);
}
else
{
if(!(input is ByteArray))
{
throw new Error("Unexpected input <" + input + ">");
}
byteInput = input as ByteArray;
}
position = 0;
try
{
return parse[byteInput[position++]]();
}
catch(e:TypeError)
{
if(position - 1 < byteInput.length)
{
e.message = "Unexpected character " + String.fromCharCode(byteInput[position - 1]) + " (0x" + byteInput[position - 1].toString(16) + ")" + " at position " + (position - 1) + " (" + e.message + ")";
}
throw e;
}
};
}
@@ -0,0 +1,237 @@
package com.newgrounds.encoders.json
{
public const encodeJson:Function = initDecodeJson();
}
import com.newgrounds.encoders.json.§com.newgrounds.encoders.json.encodeJson§;
import flash.utils.ByteArray;
import flash.utils.IDataOutput;
function initDecodeJson():Function
{
var parseArray:Function;
var result:IDataOutput = null;
var i:int = 0;
var j:int = 0;
var strLen:int = 0;
var str:String = null;
var char:int = 0;
var tempBytes:ByteArray = null;
var blockNonFiniteNumbers:Boolean = false;
var charConvert:Array = null;
var parseString:Function = null;
var parse:Object = null;
tempBytes = new ByteArray();
charConvert = new Array(256);
j = 0;
while(j < 10)
{
charConvert[j] = j + 48 | 0x30303000;
j++;
}
while(j < 16)
{
charConvert[j] = j + 55 | 0x30303000;
j++;
}
while(j < 26)
{
charConvert[j] = j + 32 | 0x30303100;
j++;
}
while(j < 32)
{
charConvert[j] = j + 39 | 0x30303100;
j++;
}
while(j < 256)
{
charConvert[j] = j;
j++;
}
charConvert[10] = 23662;
charConvert[13] = 23666;
charConvert[9] = 23668;
charConvert[8] = 23650;
charConvert[12] = 23654;
charConvert[8] = 23650;
charConvert[34] = 23586;
charConvert[92] = 23644;
charConvert[127] = 808466246;
parseArray = function(param1:Array):void
{
result.writeByte(91);
var _loc2_:* = 0;
var _loc3_:int = param1.length - 1;
if(_loc3_ >= 0)
{
while(_loc2_ < _loc3_)
{
parse[typeof param1[_loc2_]](param1[_loc2_]);
result.writeByte(44);
_loc2_++;
}
parse[typeof param1[_loc2_]](param1[_loc2_]);
}
result.writeByte(93);
};
parseString = function(param1:String):void
{
result.writeByte(34);
tempBytes.position = 0;
tempBytes.length = 0;
tempBytes.writeUTFBytes(param1);
i = 0;
j = 0;
strLen = tempBytes.length;
while(j < strLen)
{
char = charConvert[tempBytes[j++]];
if(char > 256)
{
if(j - 1 > i)
{
result.writeBytes(tempBytes,i,j - 1 - i);
}
if(char > 65536)
{
result.writeShort(23669);
result.writeUnsignedInt(char);
}
else
{
result.writeShort(char);
}
i = j;
}
}
if(strLen > i)
{
result.writeBytes(tempBytes,i,strLen - i);
}
result.writeByte(34);
};
parse = {
"object":function(param1:Object):void
{
var _loc2_:* = undefined;
if(param1)
{
if(param1 is Array)
{
parseArray(param1);
}
else
{
result.writeByte(123);
_loc2_ = true;
for(str in param1)
{
if(_loc2_)
{
_loc2_ = false;
}
else
{
result.writeByte(44);
}
parseString(str);
result.writeByte(58);
parse[typeof param1[str]](param1[str]);
}
result.writeByte(125);
}
}
else
{
result.writeUnsignedInt(1853189228);
}
},
"string":parseString,
"number":function(param1:Number):void
{
if(blockNonFiniteNumbers && !isFinite(param1))
{
throw new Error("Number " + param1 + " is not encodable");
}
result.writeUTFBytes(String(param1));
},
"boolean":function(param1:Boolean):void
{
if(param1)
{
result.writeUnsignedInt(1953658213);
}
else
{
result.writeByte(102);
result.writeUnsignedInt(1634497381);
}
},
"xml":function(param1:Object):void
{
if(!param1.toXMLString is Function || (param1 = param1.toXMLString() as String) == null)
{
throw new Error("unserializable XML object encountered");
}
parseString(param1);
},
"undefined":function(param1:Boolean):void
{
result.writeUnsignedInt(1853189228);
}
};
return function(param1:Object, param2:IDataOutput = null, param3:Boolean = false):String
{
var byteOutput:* = undefined;
var input:Object = param1;
var writeTo:IDataOutput = param2;
var strictNumberSupport:Boolean = param3;
blockNonFiniteNumbers = strictNumberSupport;
try
{
if(writeTo)
{
result = writeTo;
result.endian = "bigEndian";
parse[typeof input](input);
byteOutput.position = 0;
return byteOutput.readUTFBytes(byteOutput.length);
}
switch(typeof input)
{
case "xml":
if(!input.toXMLString is Function || (input = input.toXMLString() as String) == null)
{
throw new Error("unserializable XML object encountered");
}
break;
case "object":
case "string":
break;
case "number":
if(blockNonFiniteNumbers && !isFinite(input as Number))
{
throw new Error("Number " + input + " is not encodable");
}
return String(input);
break;
case "boolean":
return input ? "true" : "false";
case "undefined":
return "null";
default:
throw new Error("Unexpected type \"" + typeof input + "\" encountered");
}
result = byteOutput = new ByteArray();
result.endian = "bigEndian";
parse[typeof input](input);
byteOutput.position = 0;
return byteOutput.readUTFBytes(byteOutput.length);
}
catch(e:TypeError)
{
throw new Error("Unexpected type encountered");
}
};
}