mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-20 09:37:50 -05:00
Brought up to date with the private repository (feea4c7)
This commit is contained in:
1 parent
1aa738d692
commit
1b1df1ae48
7925 files changed
+2617237
-20
No files matched your search
@@ -0,0 +1,164 @@
|
||||
package com.adobe.crypto
|
||||
{
|
||||
import com.adobe.utils.IntUtil;
|
||||
|
||||
public class MD5
|
||||
{
|
||||
|
||||
public function MD5()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function hash(s:String) : String
|
||||
{
|
||||
var aa:int = 0;
|
||||
var bb:int = 0;
|
||||
var cc:int = 0;
|
||||
var dd:int = 0;
|
||||
var a:int = 1732584193;
|
||||
var b:int = -271733879;
|
||||
var c:int = -1732584194;
|
||||
var d:int = 271733878;
|
||||
var x:Array = createBlocks(s);
|
||||
var len:int = int(x.length);
|
||||
for(var i:int = 0; i < len; i += 16)
|
||||
{
|
||||
aa = a;
|
||||
bb = b;
|
||||
cc = c;
|
||||
dd = d;
|
||||
a = ff(a,b,c,d,x[i + 0],7,-680876936);
|
||||
d = ff(d,a,b,c,x[i + 1],12,-389564586);
|
||||
c = ff(c,d,a,b,x[i + 2],17,606105819);
|
||||
b = ff(b,c,d,a,x[i + 3],22,-1044525330);
|
||||
a = ff(a,b,c,d,x[i + 4],7,-176418897);
|
||||
d = ff(d,a,b,c,x[i + 5],12,1200080426);
|
||||
c = ff(c,d,a,b,x[i + 6],17,-1473231341);
|
||||
b = ff(b,c,d,a,x[i + 7],22,-45705983);
|
||||
a = ff(a,b,c,d,x[i + 8],7,1770035416);
|
||||
d = ff(d,a,b,c,x[i + 9],12,-1958414417);
|
||||
c = ff(c,d,a,b,x[i + 10],17,-42063);
|
||||
b = ff(b,c,d,a,x[i + 11],22,-1990404162);
|
||||
a = ff(a,b,c,d,x[i + 12],7,1804603682);
|
||||
d = ff(d,a,b,c,x[i + 13],12,-40341101);
|
||||
c = ff(c,d,a,b,x[i + 14],17,-1502002290);
|
||||
b = ff(b,c,d,a,x[i + 15],22,1236535329);
|
||||
a = gg(a,b,c,d,x[i + 1],5,-165796510);
|
||||
d = gg(d,a,b,c,x[i + 6],9,-1069501632);
|
||||
c = gg(c,d,a,b,x[i + 11],14,643717713);
|
||||
b = gg(b,c,d,a,x[i + 0],20,-373897302);
|
||||
a = gg(a,b,c,d,x[i + 5],5,-701558691);
|
||||
d = gg(d,a,b,c,x[i + 10],9,38016083);
|
||||
c = gg(c,d,a,b,x[i + 15],14,-660478335);
|
||||
b = gg(b,c,d,a,x[i + 4],20,-405537848);
|
||||
a = gg(a,b,c,d,x[i + 9],5,568446438);
|
||||
d = gg(d,a,b,c,x[i + 14],9,-1019803690);
|
||||
c = gg(c,d,a,b,x[i + 3],14,-187363961);
|
||||
b = gg(b,c,d,a,x[i + 8],20,1163531501);
|
||||
a = gg(a,b,c,d,x[i + 13],5,-1444681467);
|
||||
d = gg(d,a,b,c,x[i + 2],9,-51403784);
|
||||
c = gg(c,d,a,b,x[i + 7],14,1735328473);
|
||||
b = gg(b,c,d,a,x[i + 12],20,-1926607734);
|
||||
a = hh(a,b,c,d,x[i + 5],4,-378558);
|
||||
d = hh(d,a,b,c,x[i + 8],11,-2022574463);
|
||||
c = hh(c,d,a,b,x[i + 11],16,1839030562);
|
||||
b = hh(b,c,d,a,x[i + 14],23,-35309556);
|
||||
a = hh(a,b,c,d,x[i + 1],4,-1530992060);
|
||||
d = hh(d,a,b,c,x[i + 4],11,1272893353);
|
||||
c = hh(c,d,a,b,x[i + 7],16,-155497632);
|
||||
b = hh(b,c,d,a,x[i + 10],23,-1094730640);
|
||||
a = hh(a,b,c,d,x[i + 13],4,681279174);
|
||||
d = hh(d,a,b,c,x[i + 0],11,-358537222);
|
||||
c = hh(c,d,a,b,x[i + 3],16,-722521979);
|
||||
b = hh(b,c,d,a,x[i + 6],23,76029189);
|
||||
a = hh(a,b,c,d,x[i + 9],4,-640364487);
|
||||
d = hh(d,a,b,c,x[i + 12],11,-421815835);
|
||||
c = hh(c,d,a,b,x[i + 15],16,530742520);
|
||||
b = hh(b,c,d,a,x[i + 2],23,-995338651);
|
||||
a = ii(a,b,c,d,x[i + 0],6,-198630844);
|
||||
d = ii(d,a,b,c,x[i + 7],10,1126891415);
|
||||
c = ii(c,d,a,b,x[i + 14],15,-1416354905);
|
||||
b = ii(b,c,d,a,x[i + 5],21,-57434055);
|
||||
a = ii(a,b,c,d,x[i + 12],6,1700485571);
|
||||
d = ii(d,a,b,c,x[i + 3],10,-1894986606);
|
||||
c = ii(c,d,a,b,x[i + 10],15,-1051523);
|
||||
b = ii(b,c,d,a,x[i + 1],21,-2054922799);
|
||||
a = ii(a,b,c,d,x[i + 8],6,1873313359);
|
||||
d = ii(d,a,b,c,x[i + 15],10,-30611744);
|
||||
c = ii(c,d,a,b,x[i + 6],15,-1560198380);
|
||||
b = ii(b,c,d,a,x[i + 13],21,1309151649);
|
||||
a = ii(a,b,c,d,x[i + 4],6,-145523070);
|
||||
d = ii(d,a,b,c,x[i + 11],10,-1120210379);
|
||||
c = ii(c,d,a,b,x[i + 2],15,718787259);
|
||||
b = ii(b,c,d,a,x[i + 9],21,-343485551);
|
||||
a += aa;
|
||||
b += bb;
|
||||
c += cc;
|
||||
d += dd;
|
||||
}
|
||||
return IntUtil.toHex(a) + IntUtil.toHex(b) + IntUtil.toHex(c) + IntUtil.toHex(d);
|
||||
}
|
||||
|
||||
private static function f(x:int, y:int, z:int) : int
|
||||
{
|
||||
return x & y | ~x & z;
|
||||
}
|
||||
|
||||
private static function g(x:int, y:int, z:int) : int
|
||||
{
|
||||
return x & z | y & ~z;
|
||||
}
|
||||
|
||||
private static function h(x:int, y:int, z:int) : int
|
||||
{
|
||||
return x ^ y ^ z;
|
||||
}
|
||||
|
||||
private static function i(x:int, y:int, z:int) : int
|
||||
{
|
||||
return y ^ (x | ~z);
|
||||
}
|
||||
|
||||
private static function transform(func:Function, a:int, b:int, c:int, d:int, x:int, s:int, t:int) : int
|
||||
{
|
||||
var tmp:int = a + int(func(b,c,d)) + x + t;
|
||||
return IntUtil.rol(tmp,s) + b;
|
||||
}
|
||||
|
||||
private static function ff(a:int, b:int, c:int, d:int, x:int, s:int, t:int) : int
|
||||
{
|
||||
return transform(f,a,b,c,d,x,s,t);
|
||||
}
|
||||
|
||||
private static function gg(a:int, b:int, c:int, d:int, x:int, s:int, t:int) : int
|
||||
{
|
||||
return transform(g,a,b,c,d,x,s,t);
|
||||
}
|
||||
|
||||
private static function hh(a:int, b:int, c:int, d:int, x:int, s:int, t:int) : int
|
||||
{
|
||||
return transform(h,a,b,c,d,x,s,t);
|
||||
}
|
||||
|
||||
private static function ii(a:int, b:int, c:int, d:int, x:int, s:int, t:int) : int
|
||||
{
|
||||
return transform(i,a,b,c,d,x,s,t);
|
||||
}
|
||||
|
||||
private static function createBlocks(s:String) : Array
|
||||
{
|
||||
var blocks:Array = new Array();
|
||||
var len:int = s.length * 8;
|
||||
var mask:int = 255;
|
||||
for(var i:int = 0; i < len; i += 8)
|
||||
{
|
||||
blocks[i >> 5] |= (s.charCodeAt(i / 8) & mask) << i % 32;
|
||||
}
|
||||
blocks[len >> 5] |= 128 << len % 32;
|
||||
blocks[(len + 64 >>> 9 << 4) + 14] = len;
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.adobe.serialization.json
|
||||
{
|
||||
public class JSON
|
||||
{
|
||||
|
||||
public function JSON()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function encode(o:Object) : String
|
||||
{
|
||||
var encoder:JSONEncoder = new JSONEncoder(o);
|
||||
return encoder.getString();
|
||||
}
|
||||
|
||||
public static function decode(s:String) : *
|
||||
{
|
||||
var decoder:JSONDecoder = new JSONDecoder(s);
|
||||
return decoder.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.adobe.serialization.json
|
||||
{
|
||||
public class JSONDecoder
|
||||
{
|
||||
|
||||
private var value:*;
|
||||
|
||||
private var tokenizer:JSONTokenizer;
|
||||
|
||||
private var token:JSONToken;
|
||||
|
||||
public function JSONDecoder(s:String)
|
||||
{
|
||||
super();
|
||||
this.tokenizer = new JSONTokenizer(s);
|
||||
this.nextToken();
|
||||
this.value = this.parseValue();
|
||||
}
|
||||
|
||||
public function getValue() : *
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
|
||||
private function nextToken() : JSONToken
|
||||
{
|
||||
return this.token = this.tokenizer.getNextToken();
|
||||
}
|
||||
|
||||
private function parseArray() : Array
|
||||
{
|
||||
var a:Array = new Array();
|
||||
this.nextToken();
|
||||
if(this.token.type == JSONTokenType.RIGHT_BRACKET)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
while(true)
|
||||
{
|
||||
a.push(this.parseValue());
|
||||
this.nextToken();
|
||||
if(this.token.type == JSONTokenType.RIGHT_BRACKET)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
if(this.token.type == JSONTokenType.COMMA)
|
||||
{
|
||||
this.nextToken();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.tokenizer.parseError("Expecting ] or , but found " + this.token.value);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function parseObject() : Object
|
||||
{
|
||||
var key:String = null;
|
||||
var o:Object = new Object();
|
||||
this.nextToken();
|
||||
if(this.token.type == JSONTokenType.RIGHT_BRACE)
|
||||
{
|
||||
return o;
|
||||
}
|
||||
while(true)
|
||||
{
|
||||
if(this.token.type == JSONTokenType.STRING)
|
||||
{
|
||||
key = String(this.token.value);
|
||||
this.nextToken();
|
||||
if(this.token.type == JSONTokenType.COLON)
|
||||
{
|
||||
this.nextToken();
|
||||
o[key] = this.parseValue();
|
||||
this.nextToken();
|
||||
if(this.token.type == JSONTokenType.RIGHT_BRACE)
|
||||
{
|
||||
return o;
|
||||
}
|
||||
if(this.token.type == JSONTokenType.COMMA)
|
||||
{
|
||||
this.nextToken();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.tokenizer.parseError("Expecting } or , but found " + this.token.value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.tokenizer.parseError("Expecting : but found " + this.token.value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.tokenizer.parseError("Expecting string but found " + this.token.value);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function parseValue() : Object
|
||||
{
|
||||
switch(this.token.type)
|
||||
{
|
||||
case JSONTokenType.LEFT_BRACE:
|
||||
return this.parseObject();
|
||||
case JSONTokenType.LEFT_BRACKET:
|
||||
return this.parseArray();
|
||||
case JSONTokenType.STRING:
|
||||
case JSONTokenType.NUMBER:
|
||||
case JSONTokenType.TRUE:
|
||||
case JSONTokenType.FALSE:
|
||||
case JSONTokenType.NULL:
|
||||
return this.token.value;
|
||||
default:
|
||||
this.tokenizer.parseError("Unexpected " + this.token.value);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
package com.adobe.serialization.json
|
||||
{
|
||||
import flash.utils.describeType;
|
||||
|
||||
public class JSONEncoder
|
||||
{
|
||||
|
||||
private var jsonString:String;
|
||||
|
||||
public function JSONEncoder(value:*)
|
||||
{
|
||||
super();
|
||||
this.jsonString = this.convertToString(value);
|
||||
}
|
||||
|
||||
public function getString() : String
|
||||
{
|
||||
return this.jsonString;
|
||||
}
|
||||
|
||||
private function convertToString(value:*) : String
|
||||
{
|
||||
if(value is String)
|
||||
{
|
||||
return this.escapeString(value as String);
|
||||
}
|
||||
if(value is Number)
|
||||
{
|
||||
return isFinite(value as Number) ? value.toString() : "null";
|
||||
}
|
||||
if(value is Boolean)
|
||||
{
|
||||
return Boolean(value) ? "true" : "false";
|
||||
}
|
||||
if(value is Array)
|
||||
{
|
||||
return this.arrayToString(value as Array);
|
||||
}
|
||||
if(value is Object && value != null)
|
||||
{
|
||||
return this.objectToString(value);
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
|
||||
private function escapeString(str:String) : String
|
||||
{
|
||||
var ch:String = null;
|
||||
var hexCode:String = null;
|
||||
var zeroPad:String = null;
|
||||
var s:String = "";
|
||||
var len:Number = str.length;
|
||||
for(var i:int = 0; i < len; i++)
|
||||
{
|
||||
ch = str.charAt(i);
|
||||
switch(ch)
|
||||
{
|
||||
case "\"":
|
||||
s += "\\\"";
|
||||
break;
|
||||
case "\\":
|
||||
s += "\\\\";
|
||||
break;
|
||||
case "\b":
|
||||
s += "\\b";
|
||||
break;
|
||||
case "\f":
|
||||
s += "\\f";
|
||||
break;
|
||||
case "\n":
|
||||
s += "\\n";
|
||||
break;
|
||||
case "\r":
|
||||
s += "\\r";
|
||||
break;
|
||||
case "\t":
|
||||
s += "\\t";
|
||||
break;
|
||||
default:
|
||||
if(ch < " ")
|
||||
{
|
||||
hexCode = ch.charCodeAt(0).toString(16);
|
||||
zeroPad = hexCode.length == 2 ? "00" : "000";
|
||||
s += "\\u" + zeroPad + hexCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
s += ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "\"" + s + "\"";
|
||||
}
|
||||
|
||||
private function arrayToString(a:Array) : String
|
||||
{
|
||||
var s:String = "";
|
||||
for(var i:int = 0; i < a.length; i++)
|
||||
{
|
||||
if(s.length > 0)
|
||||
{
|
||||
s += ",";
|
||||
}
|
||||
s += this.convertToString(a[i]);
|
||||
}
|
||||
return "[" + s + "]";
|
||||
}
|
||||
|
||||
private function objectToString(o:Object) : String
|
||||
{
|
||||
var value:Object = null;
|
||||
var key:String = null;
|
||||
var v:XML = null;
|
||||
var s:String = "";
|
||||
var classInfo:XML = describeType(o);
|
||||
if(classInfo.@name.toString() == "Object")
|
||||
{
|
||||
for(key in o)
|
||||
{
|
||||
value = o[key];
|
||||
if(!(value is Function))
|
||||
{
|
||||
if(s.length > 0)
|
||||
{
|
||||
s += ",";
|
||||
}
|
||||
s += this.escapeString(key) + ":" + this.convertToString(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for each(v in classInfo..*.(name() == "variable" || name() == "accessor"))
|
||||
{
|
||||
if(s.length > 0)
|
||||
{
|
||||
s += ",";
|
||||
}
|
||||
s += this.escapeString(v.@name.toString()) + ":" + this.convertToString(o[v.@name]);
|
||||
}
|
||||
}
|
||||
return "{" + s + "}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.adobe.serialization.json
|
||||
{
|
||||
public class JSONParseError extends Error
|
||||
{
|
||||
|
||||
private var _location:int;
|
||||
|
||||
private var _text:String;
|
||||
|
||||
public function JSONParseError(message:String = "", location:int = 0, text:String = "")
|
||||
{
|
||||
super(message);
|
||||
this._location = location;
|
||||
this._text = text;
|
||||
}
|
||||
|
||||
public function get location() : int
|
||||
{
|
||||
return this._location;
|
||||
}
|
||||
|
||||
public function get text() : String
|
||||
{
|
||||
return this._text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.adobe.serialization.json
|
||||
{
|
||||
public class JSONToken
|
||||
{
|
||||
|
||||
private var _type:int;
|
||||
|
||||
private var _value:Object;
|
||||
|
||||
public function JSONToken(type:int = -1, value:Object = null)
|
||||
{
|
||||
super();
|
||||
this._type = type;
|
||||
this._value = value;
|
||||
}
|
||||
|
||||
public function get type() : int
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public function set type(value:int) : void
|
||||
{
|
||||
this._type = value;
|
||||
}
|
||||
|
||||
public function get value() : Object
|
||||
{
|
||||
return this._value;
|
||||
}
|
||||
|
||||
public function set value(v:Object) : void
|
||||
{
|
||||
this._value = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.adobe.serialization.json
|
||||
{
|
||||
public class JSONTokenType
|
||||
{
|
||||
|
||||
public static const UNKNOWN:int = -1;
|
||||
|
||||
public static const COMMA:int = 0;
|
||||
|
||||
public static const LEFT_BRACE:int = 1;
|
||||
|
||||
public static const RIGHT_BRACE:int = 2;
|
||||
|
||||
public static const LEFT_BRACKET:int = 3;
|
||||
|
||||
public static const RIGHT_BRACKET:int = 4;
|
||||
|
||||
public static const COLON:int = 6;
|
||||
|
||||
public static const TRUE:int = 7;
|
||||
|
||||
public static const FALSE:int = 8;
|
||||
|
||||
public static const NULL:int = 9;
|
||||
|
||||
public static const STRING:int = 10;
|
||||
|
||||
public static const NUMBER:int = 11;
|
||||
|
||||
public function JSONTokenType()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,350 @@
|
||||
package com.adobe.serialization.json
|
||||
{
|
||||
public class JSONTokenizer
|
||||
{
|
||||
|
||||
private var obj:Object;
|
||||
|
||||
private var jsonString:String;
|
||||
|
||||
private var loc:int;
|
||||
|
||||
private var ch:String;
|
||||
|
||||
public function JSONTokenizer(s:String)
|
||||
{
|
||||
super();
|
||||
this.jsonString = s;
|
||||
this.loc = 0;
|
||||
this.nextChar();
|
||||
}
|
||||
|
||||
public function getNextToken() : JSONToken
|
||||
{
|
||||
var possibleTrue:String = null;
|
||||
var possibleFalse:String = null;
|
||||
var possibleNull:String = null;
|
||||
var token:JSONToken = new JSONToken();
|
||||
this.skipIgnored();
|
||||
switch(this.ch)
|
||||
{
|
||||
case "{":
|
||||
token.type = JSONTokenType.LEFT_BRACE;
|
||||
token.value = "{";
|
||||
this.nextChar();
|
||||
break;
|
||||
case "}":
|
||||
token.type = JSONTokenType.RIGHT_BRACE;
|
||||
token.value = "}";
|
||||
this.nextChar();
|
||||
break;
|
||||
case "[":
|
||||
token.type = JSONTokenType.LEFT_BRACKET;
|
||||
token.value = "[";
|
||||
this.nextChar();
|
||||
break;
|
||||
case "]":
|
||||
token.type = JSONTokenType.RIGHT_BRACKET;
|
||||
token.value = "]";
|
||||
this.nextChar();
|
||||
break;
|
||||
case ",":
|
||||
token.type = JSONTokenType.COMMA;
|
||||
token.value = ",";
|
||||
this.nextChar();
|
||||
break;
|
||||
case ":":
|
||||
token.type = JSONTokenType.COLON;
|
||||
token.value = ":";
|
||||
this.nextChar();
|
||||
break;
|
||||
case "t":
|
||||
possibleTrue = "t" + this.nextChar() + this.nextChar() + this.nextChar();
|
||||
if(possibleTrue == "true")
|
||||
{
|
||||
token.type = JSONTokenType.TRUE;
|
||||
token.value = true;
|
||||
this.nextChar();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parseError("Expecting \'true\' but found " + possibleTrue);
|
||||
}
|
||||
break;
|
||||
case "f":
|
||||
possibleFalse = "f" + this.nextChar() + this.nextChar() + this.nextChar() + this.nextChar();
|
||||
if(possibleFalse == "false")
|
||||
{
|
||||
token.type = JSONTokenType.FALSE;
|
||||
token.value = false;
|
||||
this.nextChar();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parseError("Expecting \'false\' but found " + possibleFalse);
|
||||
}
|
||||
break;
|
||||
case "n":
|
||||
possibleNull = "n" + this.nextChar() + this.nextChar() + this.nextChar();
|
||||
if(possibleNull == "null")
|
||||
{
|
||||
token.type = JSONTokenType.NULL;
|
||||
token.value = null;
|
||||
this.nextChar();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parseError("Expecting \'null\' but found " + possibleNull);
|
||||
}
|
||||
break;
|
||||
case "\"":
|
||||
token = this.readString();
|
||||
break;
|
||||
default:
|
||||
if(this.isDigit(this.ch) || this.ch == "-")
|
||||
{
|
||||
token = this.readNumber();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(this.ch == "")
|
||||
{
|
||||
return null;
|
||||
}
|
||||
this.parseError("Unexpected " + this.ch + " encountered");
|
||||
}
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
private function readString() : JSONToken
|
||||
{
|
||||
var hexValue:String = null;
|
||||
var i:int = 0;
|
||||
var token:JSONToken = new JSONToken();
|
||||
token.type = JSONTokenType.STRING;
|
||||
var string:String = "";
|
||||
this.nextChar();
|
||||
while(this.ch != "\"" && this.ch != "")
|
||||
{
|
||||
if(this.ch == "\\")
|
||||
{
|
||||
this.nextChar();
|
||||
switch(this.ch)
|
||||
{
|
||||
case "\"":
|
||||
string += "\"";
|
||||
break;
|
||||
case "/":
|
||||
string += "/";
|
||||
break;
|
||||
case "\\":
|
||||
string += "\\";
|
||||
break;
|
||||
case "b":
|
||||
string += "\b";
|
||||
break;
|
||||
case "f":
|
||||
string += "\f";
|
||||
break;
|
||||
case "n":
|
||||
string += "\n";
|
||||
break;
|
||||
case "r":
|
||||
string += "\r";
|
||||
break;
|
||||
case "t":
|
||||
string += "\t";
|
||||
break;
|
||||
case "u":
|
||||
hexValue = "";
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
if(!this.isHexDigit(this.nextChar()))
|
||||
{
|
||||
this.parseError(" Excepted a hex digit, but found: " + this.ch);
|
||||
}
|
||||
hexValue += this.ch;
|
||||
}
|
||||
string += String.fromCharCode(parseInt(hexValue,16));
|
||||
break;
|
||||
default:
|
||||
string += "\\" + this.ch;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string += this.ch;
|
||||
}
|
||||
this.nextChar();
|
||||
}
|
||||
if(this.ch == "")
|
||||
{
|
||||
this.parseError("Unterminated string literal");
|
||||
}
|
||||
this.nextChar();
|
||||
token.value = string;
|
||||
return token;
|
||||
}
|
||||
|
||||
private function readNumber() : JSONToken
|
||||
{
|
||||
var token:JSONToken = new JSONToken();
|
||||
token.type = JSONTokenType.NUMBER;
|
||||
var input:String = "";
|
||||
if(this.ch == "-")
|
||||
{
|
||||
input += "-";
|
||||
this.nextChar();
|
||||
}
|
||||
if(!this.isDigit(this.ch))
|
||||
{
|
||||
this.parseError("Expecting a digit");
|
||||
}
|
||||
if(this.ch == "0")
|
||||
{
|
||||
input += this.ch;
|
||||
this.nextChar();
|
||||
if(this.isDigit(this.ch))
|
||||
{
|
||||
this.parseError("A digit cannot immediately follow 0");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while(this.isDigit(this.ch))
|
||||
{
|
||||
input += this.ch;
|
||||
this.nextChar();
|
||||
}
|
||||
}
|
||||
if(this.ch == ".")
|
||||
{
|
||||
input += ".";
|
||||
this.nextChar();
|
||||
if(!this.isDigit(this.ch))
|
||||
{
|
||||
this.parseError("Expecting a digit");
|
||||
}
|
||||
while(this.isDigit(this.ch))
|
||||
{
|
||||
input += this.ch;
|
||||
this.nextChar();
|
||||
}
|
||||
}
|
||||
if(this.ch == "e" || this.ch == "E")
|
||||
{
|
||||
input += "e";
|
||||
this.nextChar();
|
||||
if(this.ch == "+" || this.ch == "-")
|
||||
{
|
||||
input += this.ch;
|
||||
this.nextChar();
|
||||
}
|
||||
if(!this.isDigit(this.ch))
|
||||
{
|
||||
this.parseError("Scientific notation number needs exponent value");
|
||||
}
|
||||
while(this.isDigit(this.ch))
|
||||
{
|
||||
input += this.ch;
|
||||
this.nextChar();
|
||||
}
|
||||
}
|
||||
var num:Number = Number(input);
|
||||
if(isFinite(num) && !isNaN(num))
|
||||
{
|
||||
token.value = num;
|
||||
return token;
|
||||
}
|
||||
this.parseError("Number " + num + " is not valid!");
|
||||
return null;
|
||||
}
|
||||
|
||||
private function nextChar() : String
|
||||
{
|
||||
return this.ch = this.jsonString.charAt(this.loc++);
|
||||
}
|
||||
|
||||
private function skipIgnored() : void
|
||||
{
|
||||
this.skipWhite();
|
||||
this.skipComments();
|
||||
this.skipWhite();
|
||||
}
|
||||
|
||||
private function skipComments() : void
|
||||
{
|
||||
if(this.ch == "/")
|
||||
{
|
||||
this.nextChar();
|
||||
switch(this.ch)
|
||||
{
|
||||
case "/":
|
||||
do
|
||||
{
|
||||
this.nextChar();
|
||||
}
|
||||
while(this.ch != "\n" && this.ch != "");
|
||||
this.nextChar();
|
||||
break;
|
||||
case "*":
|
||||
this.nextChar();
|
||||
while(true)
|
||||
{
|
||||
if(this.ch == "*")
|
||||
{
|
||||
this.nextChar();
|
||||
if(this.ch == "/")
|
||||
{
|
||||
this.nextChar();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.nextChar();
|
||||
}
|
||||
if(this.ch == "")
|
||||
{
|
||||
this.parseError("Multi-line comment not closed");
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
this.parseError("Unexpected " + this.ch + " encountered (expecting \'/\' or \'*\' )");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function skipWhite() : void
|
||||
{
|
||||
while(this.isWhiteSpace(this.ch))
|
||||
{
|
||||
this.nextChar();
|
||||
}
|
||||
}
|
||||
|
||||
private function isWhiteSpace(ch:String) : Boolean
|
||||
{
|
||||
return ch == " " || ch == "\t" || ch == "\n";
|
||||
}
|
||||
|
||||
private function isDigit(ch:String) : Boolean
|
||||
{
|
||||
return ch >= "0" && ch <= "9";
|
||||
}
|
||||
|
||||
private function isHexDigit(ch:String) : Boolean
|
||||
{
|
||||
var uc:String = ch.toUpperCase();
|
||||
return this.isDigit(ch) || uc >= "A" && uc <= "F";
|
||||
}
|
||||
|
||||
public function parseError(message:String) : void
|
||||
{
|
||||
throw new JSONParseError(message,this.loc,this.jsonString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.adobe.utils
|
||||
{
|
||||
public class IntUtil
|
||||
{
|
||||
|
||||
private static var hexChars:String = "0123456789abcdef";
|
||||
|
||||
public function IntUtil()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function rol(x:int, n:int) : int
|
||||
{
|
||||
return x << n | x >>> 32 - n;
|
||||
}
|
||||
|
||||
public static function ror(x:int, n:int) : uint
|
||||
{
|
||||
var nn:int = 32 - n;
|
||||
return x << nn | x >>> 32 - nn;
|
||||
}
|
||||
|
||||
public static function toHex(n:int, bigEndian:Boolean = false) : String
|
||||
{
|
||||
var i:int = 0;
|
||||
var x:int = 0;
|
||||
var s:String = "";
|
||||
if(bigEndian)
|
||||
{
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
s += hexChars.charAt(n >> (3 - i) * 8 + 4 & 0x0F) + hexChars.charAt(n >> (3 - i) * 8 & 0x0F);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(x = 0; x < 4; x++)
|
||||
{
|
||||
s += hexChars.charAt(n >> x * 8 + 4 & 0x0F) + hexChars.charAt(n >> x * 8 & 0x0F);
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.adobe.utils
|
||||
{
|
||||
public class StringUtil
|
||||
{
|
||||
|
||||
public function StringUtil()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function stringsAreEqual(s1:String, s2:String, caseSensitive:Boolean) : Boolean
|
||||
{
|
||||
if(caseSensitive)
|
||||
{
|
||||
return s1 == s2;
|
||||
}
|
||||
return s1.toUpperCase() == s2.toUpperCase();
|
||||
}
|
||||
|
||||
public static function trim(input:String) : String
|
||||
{
|
||||
return StringUtil.ltrim(StringUtil.rtrim(input));
|
||||
}
|
||||
|
||||
public static function ltrim(input:String) : String
|
||||
{
|
||||
var size:Number = input.length;
|
||||
for(var i:Number = 0; i < size; i++)
|
||||
{
|
||||
if(input.charCodeAt(i) > 32)
|
||||
{
|
||||
return input.substring(i);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static function rtrim(input:String) : String
|
||||
{
|
||||
var size:Number = input.length;
|
||||
for(var i:Number = size; i > 0; i--)
|
||||
{
|
||||
if(input.charCodeAt(i - 1) > 32)
|
||||
{
|
||||
return input.substring(0,i);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static function beginsWith(input:String, prefix:String) : Boolean
|
||||
{
|
||||
return prefix == input.substring(0,prefix.length);
|
||||
}
|
||||
|
||||
public static function endsWith(input:String, suffix:String) : Boolean
|
||||
{
|
||||
return suffix == input.substring(input.length - suffix.length);
|
||||
}
|
||||
|
||||
public static function remove(input:String, remove:String) : String
|
||||
{
|
||||
return StringUtil.replace(input,remove,"");
|
||||
}
|
||||
|
||||
public static function replace(input:String, replace:String, replaceWith:String) : String
|
||||
{
|
||||
var j:Number = NaN;
|
||||
var sb:String = new String();
|
||||
var found:Boolean = false;
|
||||
var sLen:Number = input.length;
|
||||
var rLen:Number = replace.length;
|
||||
for(var i:Number = 0; i < sLen; i++)
|
||||
{
|
||||
if(input.charAt(i) == replace.charAt(0))
|
||||
{
|
||||
found = true;
|
||||
for(j = 0; j < rLen; j++)
|
||||
{
|
||||
if(input.charAt(i + j) != replace.charAt(j))
|
||||
{
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(found)
|
||||
{
|
||||
sb += replaceWith;
|
||||
i += rLen - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
sb += input.charAt(i);
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
package com.baseoneonline.astar
|
||||
{
|
||||
import flash.utils.Dictionary;
|
||||
|
||||
public class AStar
|
||||
{
|
||||
|
||||
private var graph:Graph;
|
||||
|
||||
private var g:Vector.<Number>;
|
||||
|
||||
private var h:Vector.<Number>;
|
||||
|
||||
private var f:Vector.<Number>;
|
||||
|
||||
private var parent:Vector.<int>;
|
||||
|
||||
private var open:Vector.<int>;
|
||||
|
||||
private var closed:Vector.<int>;
|
||||
|
||||
private var closedDict:Dictionary;
|
||||
|
||||
private var goalReached:Boolean = false;
|
||||
|
||||
public function AStar(g:Graph = null)
|
||||
{
|
||||
super();
|
||||
if(Boolean(g))
|
||||
{
|
||||
this.setGraph(g);
|
||||
}
|
||||
}
|
||||
|
||||
public function setGraph(graph:Graph) : void
|
||||
{
|
||||
this.graph = graph;
|
||||
this.updateGraph();
|
||||
}
|
||||
|
||||
private function updateGraph() : void
|
||||
{
|
||||
var len:int = this.graph.size();
|
||||
this.g = new Vector.<Number>(len,true);
|
||||
this.h = new Vector.<Number>(len,true);
|
||||
this.f = new Vector.<Number>(len,true);
|
||||
this.parent = new Vector.<int>(len,true);
|
||||
}
|
||||
|
||||
public function solve(start:int, goal:int) : Vector.<int>
|
||||
{
|
||||
var n:int = 0;
|
||||
var tf:Number = NaN;
|
||||
var x:int = 0;
|
||||
var i:int = 0;
|
||||
var y:int = 0;
|
||||
var e:int = 0;
|
||||
var tg:Number = NaN;
|
||||
var better:Boolean = false;
|
||||
var d:Number = NaN;
|
||||
var neighbors:Vector.<int> = new Vector.<int>();
|
||||
this.goalReached = false;
|
||||
this.open = new Vector.<int>();
|
||||
this.closed = new Vector.<int>();
|
||||
this.closedDict = new Dictionary(true);
|
||||
this.open.push(start);
|
||||
this.g[start] = 0;
|
||||
this.h[start] = this.graph.distance(start,goal);
|
||||
this.f[start] = this.h[start];
|
||||
this.parent[start] = -1;
|
||||
this.graph.setStartGridPos(start);
|
||||
while(this.open.length > 0)
|
||||
{
|
||||
tf = Number.POSITIVE_INFINITY;
|
||||
x = -1;
|
||||
for(i = 0; i < this.open.length; i++)
|
||||
{
|
||||
e = this.open[i];
|
||||
if(this.f[e] < tf)
|
||||
{
|
||||
tf = this.f[e];
|
||||
x = e;
|
||||
}
|
||||
}
|
||||
if(x == goal)
|
||||
{
|
||||
this.goalReached = true;
|
||||
return this.createPath(goal,start);
|
||||
}
|
||||
this.open.splice(this.open.indexOf(x),1);
|
||||
this.closed.push(x);
|
||||
this.closedDict[x] = 1;
|
||||
for each(y in this.graph.getNeighbors(x,neighbors))
|
||||
{
|
||||
if(this.closedDict[y] != 1)
|
||||
{
|
||||
tg = this.g[x] + this.graph.distance(x,y);
|
||||
better = false;
|
||||
if(this.open.indexOf(y) == -1)
|
||||
{
|
||||
this.open.push(y);
|
||||
better = true;
|
||||
}
|
||||
else if(tg < this.g[y])
|
||||
{
|
||||
better = true;
|
||||
}
|
||||
if(better)
|
||||
{
|
||||
this.parent[y] = x;
|
||||
this.g[y] = tg;
|
||||
this.h[y] = this.graph.distance(y,goal);
|
||||
this.f[y] = this.g[y] + this.h[y];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var min:Number = Number.POSITIVE_INFINITY;
|
||||
var ng:int = -1;
|
||||
for each(n in this.closed)
|
||||
{
|
||||
d = this.h[n];
|
||||
if(d < min)
|
||||
{
|
||||
min = d;
|
||||
ng = n;
|
||||
}
|
||||
}
|
||||
return this.createPath(ng,start);
|
||||
}
|
||||
|
||||
public function hasReachedGoal() : Boolean
|
||||
{
|
||||
return this.goalReached;
|
||||
}
|
||||
|
||||
private function createPath(n:int, start:int) : Vector.<int>
|
||||
{
|
||||
var solution:Vector.<int> = new Vector.<int>();
|
||||
while(this.parent[n] != -1)
|
||||
{
|
||||
solution.push(n);
|
||||
n = this.parent[n];
|
||||
}
|
||||
solution.push(start);
|
||||
return solution.reverse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baseoneonline.astar
|
||||
{
|
||||
public interface Graph
|
||||
{
|
||||
|
||||
function getNeighbors(param1:int, param2:Vector.<int>) : Vector.<int>;
|
||||
|
||||
function distance(param1:int, param2:int) : Number;
|
||||
|
||||
function size() : int;
|
||||
|
||||
function setStartGridPos(param1:int) : void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
package com.carlcalderon.arthropod
|
||||
{
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.Stage;
|
||||
import flash.events.StatusEvent;
|
||||
import flash.geom.Matrix;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.net.LocalConnection;
|
||||
import flash.system.System;
|
||||
|
||||
public class Debug
|
||||
{
|
||||
|
||||
public static const NAME:String = "Debug";
|
||||
|
||||
public static const VERSION:String = "0.74";
|
||||
|
||||
public static var password:String = "CDC309AF";
|
||||
|
||||
public static var RED:uint = 13369344;
|
||||
|
||||
public static var GREEN:uint = 52224;
|
||||
|
||||
public static var BLUE:uint = 6710988;
|
||||
|
||||
public static var PINK:uint = 13369548;
|
||||
|
||||
public static var YELLOW:uint = 13421568;
|
||||
|
||||
public static var LIGHT_BLUE:uint = 52428;
|
||||
|
||||
public static var ignoreStatus:Boolean = true;
|
||||
|
||||
public static var secure:Boolean = false;
|
||||
|
||||
public static var secureDomain:String = "*";
|
||||
|
||||
public static var allowLog:Boolean = true;
|
||||
|
||||
private static const DOMAIN:String = "com.carlcalderon.Arthropod";
|
||||
|
||||
private static const CHECK:String = ".161E714B6C1A76DE7B9865F88B32FCCE8FABA7B5.1";
|
||||
|
||||
private static const TYPE:String = "app";
|
||||
|
||||
private static const CONNECTION:String = "arthropod";
|
||||
|
||||
private static const LOG_OPERATION:String = "debug";
|
||||
|
||||
private static const ERROR_OPERATION:String = "debugError";
|
||||
|
||||
private static const WARNING_OPERATION:String = "debugWarning";
|
||||
|
||||
private static const ARRAY_OPERATION:String = "debugArray";
|
||||
|
||||
private static const BITMAP_OPERATION:String = "debugBitmapData";
|
||||
|
||||
private static const OBJECT_OPERATION:String = "debugObject";
|
||||
|
||||
private static const MEMORY_OPERATION:String = "debugMemory";
|
||||
|
||||
private static const CLEAR_OPERATION:String = "debugClear";
|
||||
|
||||
private static var lc:LocalConnection = new LocalConnection();
|
||||
|
||||
private static var hasEventListeners:Boolean = false;
|
||||
|
||||
public function Debug()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function log(message:*, color:uint = 16711422) : Boolean
|
||||
{
|
||||
return send(LOG_OPERATION,String(message),color);
|
||||
}
|
||||
|
||||
public static function error(message:*) : Boolean
|
||||
{
|
||||
return send(ERROR_OPERATION,String(message),13369344);
|
||||
}
|
||||
|
||||
public static function warning(message:*) : Boolean
|
||||
{
|
||||
return send(WARNING_OPERATION,String(message),13421568);
|
||||
}
|
||||
|
||||
public static function clear() : Boolean
|
||||
{
|
||||
return send(CLEAR_OPERATION,0,0);
|
||||
}
|
||||
|
||||
public static function array(arr:Array) : Boolean
|
||||
{
|
||||
return send(ARRAY_OPERATION,arr,null);
|
||||
}
|
||||
|
||||
public static function bitmap(bmd:*, label:String = null) : Boolean
|
||||
{
|
||||
var bm:BitmapData = new BitmapData(100,100,true,16777215);
|
||||
var mtx:Matrix = new Matrix();
|
||||
var s:Number = 100 / (bmd.width >= bmd.height ? bmd.width : bmd.height);
|
||||
mtx.scale(s,s);
|
||||
bm.draw(bmd,mtx,null,null,null,true);
|
||||
var bounds:Rectangle = new Rectangle(0,0,Math.floor(bmd.width * s),Math.floor(bmd.height * s));
|
||||
return send(BITMAP_OPERATION,bm.getPixels(bounds),{
|
||||
"bounds":bounds,
|
||||
"lbl":label
|
||||
});
|
||||
}
|
||||
|
||||
public static function snapshot(stage:Stage, label:String = null) : Boolean
|
||||
{
|
||||
if(Boolean(stage))
|
||||
{
|
||||
return bitmap(stage,label);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function object(obj:*) : Boolean
|
||||
{
|
||||
return send(OBJECT_OPERATION,obj,null);
|
||||
}
|
||||
|
||||
public static function memory() : Boolean
|
||||
{
|
||||
return send(MEMORY_OPERATION,System.totalMemory,null);
|
||||
}
|
||||
|
||||
private static function send(operation:String, value:*, prop:*) : Boolean
|
||||
{
|
||||
if(!secure)
|
||||
{
|
||||
lc.allowInsecureDomain("*");
|
||||
}
|
||||
else
|
||||
{
|
||||
lc.allowDomain(secureDomain);
|
||||
}
|
||||
if(!hasEventListeners)
|
||||
{
|
||||
if(ignoreStatus)
|
||||
{
|
||||
lc.addEventListener(StatusEvent.STATUS,ignore);
|
||||
}
|
||||
else
|
||||
{
|
||||
lc.addEventListener(StatusEvent.STATUS,status);
|
||||
}
|
||||
hasEventListeners = true;
|
||||
}
|
||||
if(!allowLog)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
lc.send(TYPE + "#" + DOMAIN + CHECK + ":" + CONNECTION,operation,password,value,prop);
|
||||
return true;
|
||||
}
|
||||
catch(e:*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static function status(e:StatusEvent) : void
|
||||
{
|
||||
trace("Arthropod status:\n" + e.toString());
|
||||
}
|
||||
|
||||
private static function ignore(e:StatusEvent) : void
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
package com.hurlant.crypto
|
||||
{
|
||||
import com.hurlant.crypto.hash.HMAC;
|
||||
import com.hurlant.crypto.hash.IHash;
|
||||
import com.hurlant.crypto.hash.MD2;
|
||||
import com.hurlant.crypto.hash.MD5;
|
||||
import com.hurlant.crypto.hash.SHA1;
|
||||
import com.hurlant.crypto.hash.SHA224;
|
||||
import com.hurlant.crypto.hash.SHA256;
|
||||
import com.hurlant.crypto.prng.ARC4;
|
||||
import com.hurlant.crypto.rsa.RSAKey;
|
||||
import com.hurlant.crypto.symmetric.AESKey;
|
||||
import com.hurlant.crypto.symmetric.BlowFishKey;
|
||||
import com.hurlant.crypto.symmetric.CBCMode;
|
||||
import com.hurlant.crypto.symmetric.CFB8Mode;
|
||||
import com.hurlant.crypto.symmetric.CFBMode;
|
||||
import com.hurlant.crypto.symmetric.CTRMode;
|
||||
import com.hurlant.crypto.symmetric.DESKey;
|
||||
import com.hurlant.crypto.symmetric.ECBMode;
|
||||
import com.hurlant.crypto.symmetric.ICipher;
|
||||
import com.hurlant.crypto.symmetric.IMode;
|
||||
import com.hurlant.crypto.symmetric.IPad;
|
||||
import com.hurlant.crypto.symmetric.ISymmetricKey;
|
||||
import com.hurlant.crypto.symmetric.IVMode;
|
||||
import com.hurlant.crypto.symmetric.NullPad;
|
||||
import com.hurlant.crypto.symmetric.OFBMode;
|
||||
import com.hurlant.crypto.symmetric.PKCS5;
|
||||
import com.hurlant.crypto.symmetric.SimpleIVMode;
|
||||
import com.hurlant.crypto.symmetric.TripleDESKey;
|
||||
import com.hurlant.crypto.symmetric.XTeaKey;
|
||||
import com.hurlant.util.Base64;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class Crypto
|
||||
{
|
||||
|
||||
private var b64:Base64;
|
||||
|
||||
public function Crypto()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function getCipher(name:String, key:ByteArray, pad:IPad = null) : ICipher
|
||||
{
|
||||
var cipher:ICipher = null;
|
||||
var keys:Array = name.split("-");
|
||||
switch(keys[0])
|
||||
{
|
||||
case "simple":
|
||||
keys.shift();
|
||||
name = keys.join("-");
|
||||
cipher = getCipher(name,key,pad);
|
||||
if(cipher is IVMode)
|
||||
{
|
||||
return new SimpleIVMode(cipher as IVMode);
|
||||
}
|
||||
return cipher;
|
||||
break;
|
||||
case "aes":
|
||||
case "aes128":
|
||||
case "aes192":
|
||||
case "aes256":
|
||||
keys.shift();
|
||||
if(key.length * 8 == keys[0])
|
||||
{
|
||||
keys.shift();
|
||||
}
|
||||
return getMode(keys[0],new AESKey(key),pad);
|
||||
case "bf":
|
||||
case "blowfish":
|
||||
keys.shift();
|
||||
return getMode(keys[0],new BlowFishKey(key),pad);
|
||||
case "des":
|
||||
keys.shift();
|
||||
if(keys[0] != "ede" && keys[0] != "ede3")
|
||||
{
|
||||
return getMode(keys[0],new DESKey(key),pad);
|
||||
}
|
||||
if(keys.length == 1)
|
||||
{
|
||||
keys.push("ecb");
|
||||
}
|
||||
break;
|
||||
case "3des":
|
||||
case "des3":
|
||||
break;
|
||||
case "xtea":
|
||||
keys.shift();
|
||||
return getMode(keys[0],new XTeaKey(key),pad);
|
||||
case "rc4":
|
||||
keys.shift();
|
||||
return new ARC4(key);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
keys.shift();
|
||||
return getMode(keys[0],new TripleDESKey(key),pad);
|
||||
}
|
||||
|
||||
public static function getKeySize(name:String) : uint
|
||||
{
|
||||
var keys:Array = name.split("-");
|
||||
switch(keys[0])
|
||||
{
|
||||
case "simple":
|
||||
keys.shift();
|
||||
return getKeySize(keys.join("-"));
|
||||
case "aes128":
|
||||
return 16;
|
||||
case "aes192":
|
||||
return 24;
|
||||
case "aes256":
|
||||
return 32;
|
||||
case "aes":
|
||||
keys.shift();
|
||||
return parseInt(keys[0]) / 8;
|
||||
case "bf":
|
||||
case "blowfish":
|
||||
return 16;
|
||||
case "des":
|
||||
keys.shift();
|
||||
switch(keys[0])
|
||||
{
|
||||
case "ede":
|
||||
return 16;
|
||||
case "ede3":
|
||||
return 24;
|
||||
default:
|
||||
return 8;
|
||||
}
|
||||
break;
|
||||
case "3des":
|
||||
case "des3":
|
||||
return 24;
|
||||
case "xtea":
|
||||
return 8;
|
||||
case "rc4":
|
||||
if(parseInt(keys[1]) > 0)
|
||||
{
|
||||
return parseInt(keys[1]) / 8;
|
||||
}
|
||||
return 16;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static function getMode(name:String, alg:ISymmetricKey, padding:IPad = null) : IMode
|
||||
{
|
||||
switch(name)
|
||||
{
|
||||
case "ecb":
|
||||
return new ECBMode(alg,padding);
|
||||
case "cfb":
|
||||
return new CFBMode(alg,padding);
|
||||
case "cfb8":
|
||||
return new CFB8Mode(alg,padding);
|
||||
case "ofb":
|
||||
return new OFBMode(alg,padding);
|
||||
case "ctr":
|
||||
return new CTRMode(alg,padding);
|
||||
case "cbc":
|
||||
}
|
||||
return new CBCMode(alg,padding);
|
||||
}
|
||||
|
||||
public static function getHash(name:String) : IHash
|
||||
{
|
||||
switch(name)
|
||||
{
|
||||
case "md2":
|
||||
return new MD2();
|
||||
case "md5":
|
||||
return new MD5();
|
||||
case "sha":
|
||||
case "sha1":
|
||||
return new SHA1();
|
||||
case "sha224":
|
||||
return new SHA224();
|
||||
case "sha256":
|
||||
return new SHA256();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getHMAC(name:String) : HMAC
|
||||
{
|
||||
var keys:Array = name.split("-");
|
||||
if(keys[0] == "hmac")
|
||||
{
|
||||
keys.shift();
|
||||
}
|
||||
var bits:uint = 0;
|
||||
if(keys.length > 1)
|
||||
{
|
||||
bits = parseInt(keys[1]);
|
||||
}
|
||||
return new HMAC(getHash(keys[0]),bits);
|
||||
}
|
||||
|
||||
public static function getPad(name:String) : IPad
|
||||
{
|
||||
switch(name)
|
||||
{
|
||||
case "null":
|
||||
return new NullPad();
|
||||
case "pkcs5":
|
||||
}
|
||||
return new PKCS5();
|
||||
}
|
||||
|
||||
public static function getRSA(E:String, M:String) : RSAKey
|
||||
{
|
||||
return RSAKey.parsePublicKey(M,E);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class HMAC
|
||||
{
|
||||
|
||||
private var hash:IHash;
|
||||
|
||||
private var bits:uint;
|
||||
|
||||
public function HMAC(hash:IHash, bits:uint = 0)
|
||||
{
|
||||
super();
|
||||
this.hash = hash;
|
||||
this.bits = bits;
|
||||
}
|
||||
|
||||
public function getHashSize() : uint
|
||||
{
|
||||
if(this.bits != 0)
|
||||
{
|
||||
return this.bits / 8;
|
||||
}
|
||||
return this.hash.getHashSize();
|
||||
}
|
||||
|
||||
public function compute(key:ByteArray, data:ByteArray) : ByteArray
|
||||
{
|
||||
var hashKey:ByteArray = null;
|
||||
if(key.length > this.hash.getInputSize())
|
||||
{
|
||||
hashKey = this.hash.hash(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
hashKey = new ByteArray();
|
||||
hashKey.writeBytes(key);
|
||||
}
|
||||
while(hashKey.length < this.hash.getInputSize())
|
||||
{
|
||||
hashKey[hashKey.length] = 0;
|
||||
}
|
||||
var innerKey:ByteArray = new ByteArray();
|
||||
var outerKey:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < hashKey.length; i++)
|
||||
{
|
||||
innerKey[i] = hashKey[i] ^ 0x36;
|
||||
outerKey[i] = hashKey[i] ^ 0x5C;
|
||||
}
|
||||
innerKey.position = hashKey.length;
|
||||
innerKey.writeBytes(data);
|
||||
var innerHash:ByteArray = this.hash.hash(innerKey);
|
||||
outerKey.position = hashKey.length;
|
||||
outerKey.writeBytes(innerHash);
|
||||
var outerHash:ByteArray = this.hash.hash(outerKey);
|
||||
if(this.bits > 0 && this.bits < 8 * outerHash.length)
|
||||
{
|
||||
outerHash.length = this.bits / 8;
|
||||
}
|
||||
return outerHash;
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
this.hash = null;
|
||||
this.bits = 0;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "hmac-" + (this.bits > 0 ? this.bits + "-" : "") + this.hash.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public interface IHash
|
||||
{
|
||||
|
||||
function getInputSize() : uint;
|
||||
|
||||
function getHashSize() : uint;
|
||||
|
||||
function hash(param1:ByteArray) : ByteArray;
|
||||
|
||||
function toString() : String;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class MD2 implements IHash
|
||||
{
|
||||
|
||||
public static const HASH_SIZE:int = 16;
|
||||
|
||||
private static const S:Array = [41,46,67,201,162,216,124,1,61,54,84,161,236,240,6,19,98,167,5,243,192,199,115,140,152,147,43,217,188,76,130,202,30,155,87,60,253,212,224,22,103,66,111,24,138,23,229,18,190,78,196,214,218,158,222,73,160,251,245,142,187,47,238,122,169,104,121,145,21,178,7,63,148,194,16,137,11,34,95,33,128,127,93,154,90,144,50,39,53,62,204,231,191,247,151,3,255,25,48,179,72,165,181,209,215,94,146,42,172,86,170,198,79,184,56,210,150,164,125,182,118,252,107,226,156,116,4,241,69,157,112,89,100,113,135,32,134,91,207,101,230,45,168,2,27,96,37,173,174,176,185,246,28,70,97,105,52,64,126,15,85,71,163,35,221,81,175,58,195,92,249,206,186,197,234,38,44,83,13,110,133,40,132,9,211,223,205,244,65,129,77,82,106,220,55,200,108,193,171,250,36,225,123,8,12,189,177,74,120,136,149,139,227,99,232,109,233,203,213,254,59,0,29,57,242,239,183,14,102,88,208,228,166,119,114,248,235,117,75,10,49,68,80,180,143,237,31,26,219,153,141,51,159,17,131,20];
|
||||
|
||||
public function MD2()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function getInputSize() : uint
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
public function getHashSize() : uint
|
||||
{
|
||||
return HASH_SIZE;
|
||||
}
|
||||
|
||||
public function hash(src:ByteArray) : ByteArray
|
||||
{
|
||||
var j:uint = 0;
|
||||
var t:uint = 0;
|
||||
var k:uint = 0;
|
||||
var savedLength:uint = src.length;
|
||||
var i:uint = uint(uint(16 - src.length % 16) || 16);
|
||||
do
|
||||
{
|
||||
src[src.length] = i;
|
||||
}
|
||||
while(src.length % 16 != 0);
|
||||
var len:uint = src.length;
|
||||
var checksum:ByteArray = new ByteArray();
|
||||
var L:uint = 0;
|
||||
for(i = 0; i < len; i += 16)
|
||||
{
|
||||
for(j = 0; j < 16; j++)
|
||||
{
|
||||
L = uint(checksum[j] = checksum[j] ^ S[src[i + j] ^ L]);
|
||||
}
|
||||
}
|
||||
src.position = src.length;
|
||||
src.writeBytes(checksum);
|
||||
len += 16;
|
||||
var X:ByteArray = new ByteArray();
|
||||
for(i = 0; i < len; i += 16)
|
||||
{
|
||||
for(j = 0; j < 16; j++)
|
||||
{
|
||||
X[32 + j] = (X[16 + j] = src[i + j]) ^ X[j];
|
||||
}
|
||||
t = 0;
|
||||
for(j = 0; j < 18; j++)
|
||||
{
|
||||
for(k = 0; k < 48; k++)
|
||||
{
|
||||
X[k] = t = uint(X[k] ^ S[t]);
|
||||
}
|
||||
t = uint(t + j & 0xFF);
|
||||
}
|
||||
}
|
||||
X.length = 16;
|
||||
src.length = savedLength;
|
||||
return X;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "md2";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.Endian;
|
||||
|
||||
public class MD5 implements IHash
|
||||
{
|
||||
|
||||
public static const HASH_SIZE:int = 16;
|
||||
|
||||
public function MD5()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function getInputSize() : uint
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
public function getHashSize() : uint
|
||||
{
|
||||
return HASH_SIZE;
|
||||
}
|
||||
|
||||
public function hash(src:ByteArray) : ByteArray
|
||||
{
|
||||
var len:uint = src.length * 8;
|
||||
var savedEndian:String = src.endian;
|
||||
while(src.length % 4 != 0)
|
||||
{
|
||||
src[src.length] = 0;
|
||||
}
|
||||
src.position = 0;
|
||||
var a:Array = [];
|
||||
src.endian = Endian.LITTLE_ENDIAN;
|
||||
for(var i:uint = 0; i < src.length; i += 4)
|
||||
{
|
||||
a.push(src.readUnsignedInt());
|
||||
}
|
||||
var h:Array = this.core_md5(a,len);
|
||||
var out:ByteArray = new ByteArray();
|
||||
out.endian = Endian.LITTLE_ENDIAN;
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
out.writeUnsignedInt(h[i]);
|
||||
}
|
||||
src.length = len / 8;
|
||||
src.endian = savedEndian;
|
||||
return out;
|
||||
}
|
||||
|
||||
private function core_md5(x:Array, len:uint) : Array
|
||||
{
|
||||
var olda:uint = 0;
|
||||
var oldb:uint = 0;
|
||||
var oldc:uint = 0;
|
||||
var oldd:uint = 0;
|
||||
x[len >> 5] |= 128 << len % 32;
|
||||
x[(len + 64 >>> 9 << 4) + 14] = len;
|
||||
var a:uint = 1732584193;
|
||||
var b:uint = 4023233417;
|
||||
var c:uint = 2562383102;
|
||||
var d:uint = 271733878;
|
||||
for(var i:uint = 0; i < x.length; i += 16)
|
||||
{
|
||||
x[i] = x[i] || 0;
|
||||
x[i + 1] = x[i + 1] || 0;
|
||||
x[i + 2] = x[i + 2] || 0;
|
||||
x[i + 3] = x[i + 3] || 0;
|
||||
x[i + 4] = x[i + 4] || 0;
|
||||
x[i + 5] = x[i + 5] || 0;
|
||||
x[i + 6] = x[i + 6] || 0;
|
||||
x[i + 7] = x[i + 7] || 0;
|
||||
x[i + 8] = x[i + 8] || 0;
|
||||
x[i + 9] = x[i + 9] || 0;
|
||||
x[i + 10] = x[i + 10] || 0;
|
||||
x[i + 11] = x[i + 11] || 0;
|
||||
x[i + 12] = x[i + 12] || 0;
|
||||
x[i + 13] = x[i + 13] || 0;
|
||||
x[i + 14] = x[i + 14] || 0;
|
||||
x[i + 15] = x[i + 15] || 0;
|
||||
olda = a;
|
||||
oldb = b;
|
||||
oldc = c;
|
||||
oldd = d;
|
||||
a = this.ff(a,b,c,d,x[i + 0],7,3614090360);
|
||||
d = this.ff(d,a,b,c,x[i + 1],12,3905402710);
|
||||
c = this.ff(c,d,a,b,x[i + 2],17,606105819);
|
||||
b = this.ff(b,c,d,a,x[i + 3],22,3250441966);
|
||||
a = this.ff(a,b,c,d,x[i + 4],7,4118548399);
|
||||
d = this.ff(d,a,b,c,x[i + 5],12,1200080426);
|
||||
c = this.ff(c,d,a,b,x[i + 6],17,2821735955);
|
||||
b = this.ff(b,c,d,a,x[i + 7],22,4249261313);
|
||||
a = this.ff(a,b,c,d,x[i + 8],7,1770035416);
|
||||
d = this.ff(d,a,b,c,x[i + 9],12,2336552879);
|
||||
c = this.ff(c,d,a,b,x[i + 10],17,4294925233);
|
||||
b = this.ff(b,c,d,a,x[i + 11],22,2304563134);
|
||||
a = this.ff(a,b,c,d,x[i + 12],7,1804603682);
|
||||
d = this.ff(d,a,b,c,x[i + 13],12,4254626195);
|
||||
c = this.ff(c,d,a,b,x[i + 14],17,2792965006);
|
||||
b = this.ff(b,c,d,a,x[i + 15],22,1236535329);
|
||||
a = this.gg(a,b,c,d,x[i + 1],5,4129170786);
|
||||
d = this.gg(d,a,b,c,x[i + 6],9,3225465664);
|
||||
c = this.gg(c,d,a,b,x[i + 11],14,643717713);
|
||||
b = this.gg(b,c,d,a,x[i + 0],20,3921069994);
|
||||
a = this.gg(a,b,c,d,x[i + 5],5,3593408605);
|
||||
d = this.gg(d,a,b,c,x[i + 10],9,38016083);
|
||||
c = this.gg(c,d,a,b,x[i + 15],14,3634488961);
|
||||
b = this.gg(b,c,d,a,x[i + 4],20,3889429448);
|
||||
a = this.gg(a,b,c,d,x[i + 9],5,568446438);
|
||||
d = this.gg(d,a,b,c,x[i + 14],9,3275163606);
|
||||
c = this.gg(c,d,a,b,x[i + 3],14,4107603335);
|
||||
b = this.gg(b,c,d,a,x[i + 8],20,1163531501);
|
||||
a = this.gg(a,b,c,d,x[i + 13],5,2850285829);
|
||||
d = this.gg(d,a,b,c,x[i + 2],9,4243563512);
|
||||
c = this.gg(c,d,a,b,x[i + 7],14,1735328473);
|
||||
b = this.gg(b,c,d,a,x[i + 12],20,2368359562);
|
||||
a = this.hh(a,b,c,d,x[i + 5],4,4294588738);
|
||||
d = this.hh(d,a,b,c,x[i + 8],11,2272392833);
|
||||
c = this.hh(c,d,a,b,x[i + 11],16,1839030562);
|
||||
b = this.hh(b,c,d,a,x[i + 14],23,4259657740);
|
||||
a = this.hh(a,b,c,d,x[i + 1],4,2763975236);
|
||||
d = this.hh(d,a,b,c,x[i + 4],11,1272893353);
|
||||
c = this.hh(c,d,a,b,x[i + 7],16,4139469664);
|
||||
b = this.hh(b,c,d,a,x[i + 10],23,3200236656);
|
||||
a = this.hh(a,b,c,d,x[i + 13],4,681279174);
|
||||
d = this.hh(d,a,b,c,x[i + 0],11,3936430074);
|
||||
c = this.hh(c,d,a,b,x[i + 3],16,3572445317);
|
||||
b = this.hh(b,c,d,a,x[i + 6],23,76029189);
|
||||
a = this.hh(a,b,c,d,x[i + 9],4,3654602809);
|
||||
d = this.hh(d,a,b,c,x[i + 12],11,3873151461);
|
||||
c = this.hh(c,d,a,b,x[i + 15],16,530742520);
|
||||
b = this.hh(b,c,d,a,x[i + 2],23,3299628645);
|
||||
a = this.ii(a,b,c,d,x[i + 0],6,4096336452);
|
||||
d = this.ii(d,a,b,c,x[i + 7],10,1126891415);
|
||||
c = this.ii(c,d,a,b,x[i + 14],15,2878612391);
|
||||
b = this.ii(b,c,d,a,x[i + 5],21,4237533241);
|
||||
a = this.ii(a,b,c,d,x[i + 12],6,1700485571);
|
||||
d = this.ii(d,a,b,c,x[i + 3],10,2399980690);
|
||||
c = this.ii(c,d,a,b,x[i + 10],15,4293915773);
|
||||
b = this.ii(b,c,d,a,x[i + 1],21,2240044497);
|
||||
a = this.ii(a,b,c,d,x[i + 8],6,1873313359);
|
||||
d = this.ii(d,a,b,c,x[i + 15],10,4264355552);
|
||||
c = this.ii(c,d,a,b,x[i + 6],15,2734768916);
|
||||
b = this.ii(b,c,d,a,x[i + 13],21,1309151649);
|
||||
a = this.ii(a,b,c,d,x[i + 4],6,4149444226);
|
||||
d = this.ii(d,a,b,c,x[i + 11],10,3174756917);
|
||||
c = this.ii(c,d,a,b,x[i + 2],15,718787259);
|
||||
b = this.ii(b,c,d,a,x[i + 9],21,3951481745);
|
||||
a += olda;
|
||||
b += oldb;
|
||||
c += oldc;
|
||||
d += oldd;
|
||||
}
|
||||
return [a,b,c,d];
|
||||
}
|
||||
|
||||
private function rol(num:uint, cnt:uint) : uint
|
||||
{
|
||||
return num << cnt | num >>> 32 - cnt;
|
||||
}
|
||||
|
||||
private function cmn(q:uint, a:uint, b:uint, x:uint, s:uint, t:uint) : uint
|
||||
{
|
||||
return this.rol(a + q + x + t,s) + b;
|
||||
}
|
||||
|
||||
private function ff(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint) : uint
|
||||
{
|
||||
return this.cmn(b & c | ~b & d,a,b,x,s,t);
|
||||
}
|
||||
|
||||
private function gg(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint) : uint
|
||||
{
|
||||
return this.cmn(b & d | c & ~d,a,b,x,s,t);
|
||||
}
|
||||
|
||||
private function hh(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint) : uint
|
||||
{
|
||||
return this.cmn(b ^ c ^ d,a,b,x,s,t);
|
||||
}
|
||||
|
||||
private function ii(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint) : uint
|
||||
{
|
||||
return this.cmn(c ^ (b | ~d),a,b,x,s,t);
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "md5";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
public class SHA1 extends SHABase implements IHash
|
||||
{
|
||||
|
||||
public static const HASH_SIZE:int = 20;
|
||||
|
||||
public function SHA1()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function getHashSize() : uint
|
||||
{
|
||||
return HASH_SIZE;
|
||||
}
|
||||
|
||||
override protected function core(x:Array, len:uint) : Array
|
||||
{
|
||||
var olda:uint = 0;
|
||||
var oldb:uint = 0;
|
||||
var oldc:uint = 0;
|
||||
var oldd:uint = 0;
|
||||
var olde:uint = 0;
|
||||
var j:uint = 0;
|
||||
var t:uint = 0;
|
||||
x[len >> 5] |= 128 << 24 - len % 32;
|
||||
x[(len + 64 >> 9 << 4) + 15] = len;
|
||||
var w:Array = [];
|
||||
var a:uint = 1732584193;
|
||||
var b:uint = 4023233417;
|
||||
var c:uint = 2562383102;
|
||||
var d:uint = 271733878;
|
||||
var e:uint = 3285377520;
|
||||
for(var i:uint = 0; i < x.length; i += 16)
|
||||
{
|
||||
olda = a;
|
||||
oldb = b;
|
||||
oldc = c;
|
||||
oldd = d;
|
||||
olde = e;
|
||||
for(j = 0; j < 80; j++)
|
||||
{
|
||||
if(j < 16)
|
||||
{
|
||||
w[j] = x[i + j] || 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
w[j] = this.rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16],1);
|
||||
}
|
||||
t = this.rol(a,5) + this.ft(j,b,c,d) + e + w[j] + this.kt(j);
|
||||
e = d;
|
||||
d = c;
|
||||
c = this.rol(b,30);
|
||||
b = a;
|
||||
a = t;
|
||||
}
|
||||
a += olda;
|
||||
b += oldb;
|
||||
c += oldc;
|
||||
d += oldd;
|
||||
e += olde;
|
||||
}
|
||||
return [a,b,c,d,e];
|
||||
}
|
||||
|
||||
private function rol(num:uint, cnt:uint) : uint
|
||||
{
|
||||
return num << cnt | num >>> 32 - cnt;
|
||||
}
|
||||
|
||||
private function ft(t:uint, b:uint, c:uint, d:uint) : uint
|
||||
{
|
||||
if(t < 20)
|
||||
{
|
||||
return b & c | ~b & d;
|
||||
}
|
||||
if(t < 40)
|
||||
{
|
||||
return b ^ c ^ d;
|
||||
}
|
||||
if(t < 60)
|
||||
{
|
||||
return b & c | b & d | c & d;
|
||||
}
|
||||
return b ^ c ^ d;
|
||||
}
|
||||
|
||||
private function kt(t:uint) : uint
|
||||
{
|
||||
return t < 20 ? 1518500249 : (t < 40 ? 1859775393 : (t < 60 ? uint(2400959708) : uint(3395469782)));
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "sha1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
public class SHA224 extends SHA256
|
||||
{
|
||||
|
||||
public function SHA224()
|
||||
{
|
||||
super();
|
||||
_h = [3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428];
|
||||
}
|
||||
|
||||
override public function getHashSize() : uint
|
||||
{
|
||||
return 28;
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "sha224";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
public class SHA256 extends SHABase implements IHash
|
||||
{
|
||||
|
||||
protected static const k:Array = [1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];
|
||||
|
||||
protected var _h:Array = [1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];
|
||||
|
||||
public function SHA256()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
override public function getHashSize() : uint
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
|
||||
override protected function core(x:Array, len:uint) : Array
|
||||
{
|
||||
var olda:uint = 0;
|
||||
var oldb:uint = 0;
|
||||
var oldc:uint = 0;
|
||||
var oldd:uint = 0;
|
||||
var olde:uint = 0;
|
||||
var oldf:uint = 0;
|
||||
var oldg:uint = 0;
|
||||
var oldh:uint = 0;
|
||||
var j:uint = 0;
|
||||
var t2:uint = 0;
|
||||
var t1:uint = 0;
|
||||
var s0:uint = 0;
|
||||
var s1:uint = 0;
|
||||
x[len >> 5] |= 128 << 24 - len % 32;
|
||||
x[(len + 64 >> 9 << 4) + 15] = len;
|
||||
var w:Array = [];
|
||||
var a:uint = uint(this._h[0]);
|
||||
var b:uint = uint(this._h[1]);
|
||||
var c:uint = uint(this._h[2]);
|
||||
var d:uint = uint(this._h[3]);
|
||||
var e:uint = uint(this._h[4]);
|
||||
var f:uint = uint(this._h[5]);
|
||||
var g:uint = uint(this._h[6]);
|
||||
var h:uint = uint(this._h[7]);
|
||||
for(var i:uint = 0; i < x.length; i += 16)
|
||||
{
|
||||
olda = a;
|
||||
oldb = b;
|
||||
oldc = c;
|
||||
oldd = d;
|
||||
olde = e;
|
||||
oldf = f;
|
||||
oldg = g;
|
||||
oldh = h;
|
||||
for(j = 0; j < 64; j++)
|
||||
{
|
||||
if(j < 16)
|
||||
{
|
||||
w[j] = x[i + j] || 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s0 = uint(this.rrol(w[j - 15],7) ^ this.rrol(w[j - 15],18) ^ w[j - 15] >>> 3);
|
||||
s1 = uint(this.rrol(w[j - 2],17) ^ this.rrol(w[j - 2],19) ^ w[j - 2] >>> 10);
|
||||
w[j] = w[j - 16] + s0 + w[j - 7] + s1;
|
||||
}
|
||||
t2 = (this.rrol(a,2) ^ this.rrol(a,13) ^ this.rrol(a,22)) + (a & b ^ a & c ^ b & c);
|
||||
t1 = h + (this.rrol(e,6) ^ this.rrol(e,11) ^ this.rrol(e,25)) + (e & f ^ g & ~e) + k[j] + w[j];
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + t1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = t1 + t2;
|
||||
}
|
||||
a += olda;
|
||||
b += oldb;
|
||||
c += oldc;
|
||||
d += oldd;
|
||||
e += olde;
|
||||
f += oldf;
|
||||
g += oldg;
|
||||
h += oldh;
|
||||
}
|
||||
return [a,b,c,d,e,f,g,h];
|
||||
}
|
||||
|
||||
protected function rrol(num:uint, cnt:uint) : uint
|
||||
{
|
||||
return num << 32 - cnt | num >>> cnt;
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "sha256";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.hurlant.crypto.hash
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.Endian;
|
||||
|
||||
public class SHABase implements IHash
|
||||
{
|
||||
|
||||
public function SHABase()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function getInputSize() : uint
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
public function getHashSize() : uint
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function hash(src:ByteArray) : ByteArray
|
||||
{
|
||||
var savedLength:uint = src.length;
|
||||
var savedEndian:String = src.endian;
|
||||
src.endian = Endian.BIG_ENDIAN;
|
||||
var len:uint = savedLength * 8;
|
||||
while(src.length % 4 != 0)
|
||||
{
|
||||
src[src.length] = 0;
|
||||
}
|
||||
src.position = 0;
|
||||
var a:Array = [];
|
||||
for(var i:uint = 0; i < src.length; i += 4)
|
||||
{
|
||||
a.push(src.readUnsignedInt());
|
||||
}
|
||||
var h:Array = this.core(a,len);
|
||||
var out:ByteArray = new ByteArray();
|
||||
var words:uint = this.getHashSize() / 4;
|
||||
for(i = 0; i < words; i++)
|
||||
{
|
||||
out.writeUnsignedInt(h[i]);
|
||||
}
|
||||
src.length = savedLength;
|
||||
src.endian = savedEndian;
|
||||
return out;
|
||||
}
|
||||
|
||||
protected function core(x:Array, len:uint) : Array
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "sha";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.hurlant.crypto.prng
|
||||
{
|
||||
import com.hurlant.crypto.symmetric.IStreamCipher;
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class ARC4 implements IPRNG, IStreamCipher
|
||||
{
|
||||
|
||||
private var i:int = 0;
|
||||
|
||||
private var j:int = 0;
|
||||
|
||||
private var S:ByteArray;
|
||||
|
||||
private const psize:uint = 256;
|
||||
|
||||
public function ARC4(key:ByteArray = null)
|
||||
{
|
||||
super();
|
||||
this.S = new ByteArray();
|
||||
if(Boolean(key))
|
||||
{
|
||||
this.init(key);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPoolSize() : uint
|
||||
{
|
||||
return this.psize;
|
||||
}
|
||||
|
||||
public function init(key:ByteArray) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var j:int = 0;
|
||||
var t:int = 0;
|
||||
for(i = 0; i < 256; i++)
|
||||
{
|
||||
this.S[i] = i;
|
||||
}
|
||||
j = 0;
|
||||
for(i = 0; i < 256; i++)
|
||||
{
|
||||
j = j + this.S[i] + key[i % key.length] & 0xFF;
|
||||
t = int(this.S[i]);
|
||||
this.S[i] = this.S[j];
|
||||
this.S[j] = t;
|
||||
}
|
||||
this.i = 0;
|
||||
this.j = 0;
|
||||
}
|
||||
|
||||
public function next() : uint
|
||||
{
|
||||
var t:int = 0;
|
||||
this.i = this.i + 1 & 0xFF;
|
||||
this.j = this.j + this.S[this.i] & 0xFF;
|
||||
t = int(this.S[this.i]);
|
||||
this.S[this.i] = this.S[this.j];
|
||||
this.S[this.j] = t;
|
||||
return this.S[t + this.S[this.i] & 0xFF];
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function encrypt(block:ByteArray) : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
while(i < block.length)
|
||||
{
|
||||
var _temp_2:* = block;
|
||||
var _loc3_:uint = i++;
|
||||
_temp_2[_loc3_] ^= this.next();
|
||||
}
|
||||
}
|
||||
|
||||
public function decrypt(block:ByteArray) : void
|
||||
{
|
||||
this.encrypt(block);
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
if(this.S != null)
|
||||
{
|
||||
for(i = 0; i < this.S.length; i++)
|
||||
{
|
||||
this.S[i] = Math.random() * 256;
|
||||
}
|
||||
this.S.length = 0;
|
||||
this.S = null;
|
||||
}
|
||||
this.i = 0;
|
||||
this.j = 0;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "rc4";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.hurlant.crypto.prng
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public interface IPRNG
|
||||
{
|
||||
|
||||
function getPoolSize() : uint;
|
||||
|
||||
function init(param1:ByteArray) : void;
|
||||
|
||||
function next() : uint;
|
||||
|
||||
function dispose() : void;
|
||||
|
||||
function toString() : String;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.hurlant.crypto.prng
|
||||
{
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.system.Capabilities;
|
||||
import flash.system.System;
|
||||
import flash.text.Font;
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.getTimer;
|
||||
|
||||
public class Random
|
||||
{
|
||||
|
||||
private var state:IPRNG;
|
||||
|
||||
private var ready:Boolean = false;
|
||||
|
||||
private var pool:ByteArray;
|
||||
|
||||
private var psize:int;
|
||||
|
||||
private var pptr:int;
|
||||
|
||||
private var seeded:Boolean = false;
|
||||
|
||||
public function Random(prng:Class = null)
|
||||
{
|
||||
var t:uint = 0;
|
||||
super();
|
||||
if(prng == null)
|
||||
{
|
||||
prng = ARC4;
|
||||
}
|
||||
this.state = new prng() as IPRNG;
|
||||
this.psize = this.state.getPoolSize();
|
||||
this.pool = new ByteArray();
|
||||
this.pptr = 0;
|
||||
while(this.pptr < this.psize)
|
||||
{
|
||||
t = 65536 * Math.random();
|
||||
this.pool[this.pptr++] = t >>> 8;
|
||||
this.pool[this.pptr++] = t & 0xFF;
|
||||
}
|
||||
this.pptr = 0;
|
||||
this.seed();
|
||||
}
|
||||
|
||||
public function seed(x:int = 0) : void
|
||||
{
|
||||
if(x == 0)
|
||||
{
|
||||
x = new Date().getTime();
|
||||
}
|
||||
var _temp_3:* = this.pool;
|
||||
var _loc2_:Number = this.pptr++;
|
||||
_temp_3[_loc2_] ^= x & 0xFF;
|
||||
var _temp_6:* = this.pool;
|
||||
var _loc3_:Number = this.pptr++;
|
||||
_temp_6[_loc3_] ^= x >> 8 & 0xFF;
|
||||
var _temp_9:* = this.pool;
|
||||
var _loc4_:Number = this.pptr++;
|
||||
_temp_9[_loc4_] ^= x >> 16 & 0xFF;
|
||||
var _temp_12:* = this.pool;
|
||||
var _loc5_:Number = this.pptr++;
|
||||
_temp_12[_loc5_] ^= x >> 24 & 0xFF;
|
||||
this.pptr %= this.psize;
|
||||
this.seeded = true;
|
||||
}
|
||||
|
||||
public function autoSeed() : void
|
||||
{
|
||||
var f:Font = null;
|
||||
var b:ByteArray = new ByteArray();
|
||||
b.writeUnsignedInt(System.totalMemory);
|
||||
b.writeUTF(Capabilities.serverString);
|
||||
b.writeUnsignedInt(getTimer());
|
||||
b.writeUnsignedInt(new Date().getTime());
|
||||
var a:Array = Font.enumerateFonts(true);
|
||||
for each(f in a)
|
||||
{
|
||||
b.writeUTF(f.fontName);
|
||||
b.writeUTF(f.fontStyle);
|
||||
b.writeUTF(f.fontType);
|
||||
}
|
||||
b.position = 0;
|
||||
while(b.bytesAvailable >= 4)
|
||||
{
|
||||
this.seed(b.readUnsignedInt());
|
||||
}
|
||||
}
|
||||
|
||||
public function nextBytes(buffer:ByteArray, length:int) : void
|
||||
{
|
||||
while(Boolean(length--))
|
||||
{
|
||||
buffer.writeByte(this.nextByte());
|
||||
}
|
||||
}
|
||||
|
||||
public function nextByte() : int
|
||||
{
|
||||
if(!this.ready)
|
||||
{
|
||||
if(!this.seeded)
|
||||
{
|
||||
this.autoSeed();
|
||||
}
|
||||
this.state.init(this.pool);
|
||||
this.pool.length = 0;
|
||||
this.pptr = 0;
|
||||
this.ready = true;
|
||||
}
|
||||
return this.state.next();
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
for(var i:uint = 0; i < this.pool.length; i++)
|
||||
{
|
||||
this.pool[i] = Math.random() * 256;
|
||||
}
|
||||
this.pool.length = 0;
|
||||
this.pool = null;
|
||||
this.state.dispose();
|
||||
this.state = null;
|
||||
this.psize = 0;
|
||||
this.pptr = 0;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "random-" + this.state.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,325 @@
|
||||
package com.hurlant.crypto.rsa
|
||||
{
|
||||
import com.hurlant.crypto.prng.Random;
|
||||
import com.hurlant.math.BigInteger;
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class RSAKey
|
||||
{
|
||||
|
||||
public var e:int;
|
||||
|
||||
public var n:BigInteger;
|
||||
|
||||
public var d:BigInteger;
|
||||
|
||||
public var p:BigInteger;
|
||||
|
||||
public var q:BigInteger;
|
||||
|
||||
public var dmp1:BigInteger;
|
||||
|
||||
public var dmq1:BigInteger;
|
||||
|
||||
public var coeff:BigInteger;
|
||||
|
||||
protected var canDecrypt:Boolean;
|
||||
|
||||
protected var canEncrypt:Boolean;
|
||||
|
||||
public function RSAKey(N:BigInteger, E:int, D:BigInteger = null, P:BigInteger = null, Q:BigInteger = null, DP:BigInteger = null, DQ:BigInteger = null, C:BigInteger = null)
|
||||
{
|
||||
super();
|
||||
this.n = N;
|
||||
this.e = E;
|
||||
this.d = D;
|
||||
this.p = P;
|
||||
this.q = Q;
|
||||
this.dmp1 = DP;
|
||||
this.dmq1 = DQ;
|
||||
this.coeff = C;
|
||||
this.canEncrypt = this.n != null && this.e != 0;
|
||||
this.canDecrypt = this.canEncrypt && this.d != null;
|
||||
}
|
||||
|
||||
public static function parsePublicKey(N:String, E:String) : RSAKey
|
||||
{
|
||||
return new RSAKey(new BigInteger(N,16),parseInt(E,16));
|
||||
}
|
||||
|
||||
public static function parsePrivateKey(N:String, E:String, D:String, P:String = null, Q:String = null, DMP1:String = null, DMQ1:String = null, IQMP:String = null) : RSAKey
|
||||
{
|
||||
if(P == null)
|
||||
{
|
||||
return new RSAKey(new BigInteger(N,16),parseInt(E,16),new BigInteger(D,16));
|
||||
}
|
||||
return new RSAKey(new BigInteger(N,16),parseInt(E,16),new BigInteger(D,16),new BigInteger(P,16),new BigInteger(Q,16),new BigInteger(DMP1,16),new BigInteger(DMQ1),new BigInteger(IQMP));
|
||||
}
|
||||
|
||||
public static function generate(B:uint, E:String) : RSAKey
|
||||
{
|
||||
var p1:BigInteger = null;
|
||||
var q1:BigInteger = null;
|
||||
var phi:BigInteger = null;
|
||||
var t:BigInteger = null;
|
||||
var rng:Random = new Random();
|
||||
var qs:uint = uint(B >> 1);
|
||||
var key:RSAKey = new RSAKey(null,0,null);
|
||||
key.e = parseInt(E,16);
|
||||
for(var ee:BigInteger = new BigInteger(E,16); true; )
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
key.p = bigRandom(B - qs,rng);
|
||||
if(key.p.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) == 0 && key.p.isProbablePrime(10))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
while(true)
|
||||
{
|
||||
key.q = bigRandom(qs,rng);
|
||||
if(key.q.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) == 0 && key.q.isProbablePrime(10))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(key.p.compareTo(key.q) <= 0)
|
||||
{
|
||||
t = key.p;
|
||||
key.p = key.q;
|
||||
key.q = t;
|
||||
}
|
||||
p1 = key.p.subtract(BigInteger.ONE);
|
||||
q1 = key.q.subtract(BigInteger.ONE);
|
||||
phi = p1.multiply(q1);
|
||||
if(phi.gcd(ee).compareTo(BigInteger.ONE) == 0)
|
||||
{
|
||||
key.n = key.p.multiply(key.q);
|
||||
key.d = ee.modInverse(phi);
|
||||
key.dmp1 = key.d.mod(p1);
|
||||
key.dmq1 = key.d.mod(q1);
|
||||
key.coeff = key.q.modInverse(key.p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
protected static function bigRandom(bits:int, rnd:Random) : BigInteger
|
||||
{
|
||||
if(bits < 2)
|
||||
{
|
||||
return BigInteger.nbv(1);
|
||||
}
|
||||
var x:ByteArray = new ByteArray();
|
||||
rnd.nextBytes(x,bits >> 3);
|
||||
x.position = 0;
|
||||
var b:BigInteger = new BigInteger(x);
|
||||
b.primify(bits,1);
|
||||
return b;
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return (this.n.bitLength() + 7) / 8;
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
this.e = 0;
|
||||
this.n.dispose();
|
||||
this.n = null;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray, dst:ByteArray, length:uint, pad:Function = null) : void
|
||||
{
|
||||
this._encrypt(this.doPublic,src,dst,length,pad,2);
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray, dst:ByteArray, length:uint, pad:Function = null) : void
|
||||
{
|
||||
this._decrypt(this.doPrivate2,src,dst,length,pad,2);
|
||||
}
|
||||
|
||||
public function sign(src:ByteArray, dst:ByteArray, length:uint, pad:Function = null) : void
|
||||
{
|
||||
this._encrypt(this.doPrivate2,src,dst,length,pad,1);
|
||||
}
|
||||
|
||||
public function verify(src:ByteArray, dst:ByteArray, length:uint, pad:Function = null) : void
|
||||
{
|
||||
this._decrypt(this.doPublic,src,dst,length,pad,1);
|
||||
}
|
||||
|
||||
private function _encrypt(op:Function, src:ByteArray, dst:ByteArray, length:uint, pad:Function, padType:int) : void
|
||||
{
|
||||
var block:BigInteger = null;
|
||||
var chunk:BigInteger = null;
|
||||
if(pad == null)
|
||||
{
|
||||
pad = this.pkcs1pad;
|
||||
}
|
||||
if(src.position >= src.length)
|
||||
{
|
||||
src.position = 0;
|
||||
}
|
||||
var bl:uint = this.getBlockSize();
|
||||
var end:int = src.position + length;
|
||||
while(src.position < end)
|
||||
{
|
||||
block = new BigInteger(pad(src,end,bl,padType),bl);
|
||||
chunk = op(block);
|
||||
chunk.toArray(dst);
|
||||
}
|
||||
}
|
||||
|
||||
private function _decrypt(op:Function, src:ByteArray, dst:ByteArray, length:uint, pad:Function, padType:int) : void
|
||||
{
|
||||
var block:BigInteger = null;
|
||||
var chunk:BigInteger = null;
|
||||
var b:ByteArray = null;
|
||||
if(pad == null)
|
||||
{
|
||||
pad = this.pkcs1unpad;
|
||||
}
|
||||
if(src.position >= src.length)
|
||||
{
|
||||
src.position = 0;
|
||||
}
|
||||
var bl:uint = this.getBlockSize();
|
||||
var end:int = src.position + length;
|
||||
while(src.position < end)
|
||||
{
|
||||
block = new BigInteger(src,length);
|
||||
chunk = op(block);
|
||||
b = pad(chunk,bl);
|
||||
dst.writeBytes(b);
|
||||
}
|
||||
}
|
||||
|
||||
private function pkcs1pad(src:ByteArray, end:int, n:uint, type:uint = 2) : ByteArray
|
||||
{
|
||||
var x:int = 0;
|
||||
var out:ByteArray = new ByteArray();
|
||||
var p:int = int(src.position);
|
||||
end = Math.min(end,src.length,p + n - 11);
|
||||
src.position = end;
|
||||
var i:int = end - 1;
|
||||
while(i >= p && n > 11)
|
||||
{
|
||||
out[--n] = src[i--];
|
||||
}
|
||||
out[--n] = 0;
|
||||
var rng:Random = new Random();
|
||||
while(n > 2)
|
||||
{
|
||||
for(x = 0; x == 0; )
|
||||
{
|
||||
x = type == 2 ? rng.nextByte() : 255;
|
||||
}
|
||||
out[--n] = x;
|
||||
}
|
||||
out[--n] = type;
|
||||
out[--n] = 0;
|
||||
return out;
|
||||
}
|
||||
|
||||
private function pkcs1unpad(src:BigInteger, n:uint, type:uint = 2) : ByteArray
|
||||
{
|
||||
var b:ByteArray = src.toByteArray();
|
||||
var out:ByteArray = new ByteArray();
|
||||
var i:int = 0;
|
||||
while(i < b.length && b[i] == 0)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
if(b.length - i != n - 1 || b[i] > 2)
|
||||
{
|
||||
trace("PKCS#1 unpad: i=" + i + ", expected b[i]==[0,1,2], got b[i]=" + b[i].toString(16));
|
||||
return null;
|
||||
}
|
||||
i++;
|
||||
while(b[i] != 0)
|
||||
{
|
||||
if(++i >= b.length)
|
||||
{
|
||||
trace("PKCS#1 unpad: i=" + i + ", b[i-1]!=0 (=" + b[i - 1].toString(16) + ")");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
while(++i < b.length)
|
||||
{
|
||||
out.writeByte(b[i]);
|
||||
}
|
||||
out.position = 0;
|
||||
return out;
|
||||
}
|
||||
|
||||
private function rawpad(src:ByteArray, end:int, n:uint) : ByteArray
|
||||
{
|
||||
return src;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "rsa";
|
||||
}
|
||||
|
||||
public function dump() : String
|
||||
{
|
||||
var s:String = "N=" + this.n.toString(16) + "\n" + "E=" + this.e.toString(16) + "\n";
|
||||
if(this.canDecrypt)
|
||||
{
|
||||
s += "D=" + this.d.toString(16) + "\n";
|
||||
if(this.p != null && this.q != null)
|
||||
{
|
||||
s += "P=" + this.p.toString(16) + "\n";
|
||||
s += "Q=" + this.q.toString(16) + "\n";
|
||||
s += "DMP1=" + this.dmp1.toString(16) + "\n";
|
||||
s += "DMQ1=" + this.dmq1.toString(16) + "\n";
|
||||
s += "IQMP=" + this.coeff.toString(16) + "\n";
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
protected function doPublic(x:BigInteger) : BigInteger
|
||||
{
|
||||
return x.modPowInt(this.e,this.n);
|
||||
}
|
||||
|
||||
protected function doPrivate2(x:BigInteger) : BigInteger
|
||||
{
|
||||
if(this.p == null && this.q == null)
|
||||
{
|
||||
return x.modPow(this.d,this.n);
|
||||
}
|
||||
var xp:BigInteger = x.mod(this.p).modPow(this.dmp1,this.p);
|
||||
var xq:BigInteger = x.mod(this.q).modPow(this.dmq1,this.q);
|
||||
while(xp.compareTo(xq) < 0)
|
||||
{
|
||||
xp = xp.add(this.p);
|
||||
}
|
||||
return xp.subtract(xq).multiply(this.coeff).mod(this.p).multiply(this.q).add(xq);
|
||||
}
|
||||
|
||||
protected function doPrivate(x:BigInteger) : BigInteger
|
||||
{
|
||||
if(this.p == null || this.q == null)
|
||||
{
|
||||
return x.modPow(this.d,this.n);
|
||||
}
|
||||
var xp:BigInteger = x.mod(this.p).modPow(this.dmp1,this.p);
|
||||
var xq:BigInteger = x.mod(this.q).modPow(this.dmq1,this.q);
|
||||
while(xp.compareTo(xq) < 0)
|
||||
{
|
||||
xp = xp.add(this.p);
|
||||
}
|
||||
return xp.subtract(xq).multiply(this.coeff).mod(this.p).multiply(this.q).add(xq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.crypto.prng.Random;
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class AESKey implements ISymmetricKey
|
||||
{
|
||||
|
||||
private static const Nb:uint = 4;
|
||||
|
||||
private static const _Sbox:Array = [99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22];
|
||||
|
||||
private static const _InvSbox:Array = [82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125];
|
||||
|
||||
private static const _Xtime2Sbox:Array = [198,248,238,246,255,214,222,145,96,2,206,86,231,181,77,236,143,31,137,250,239,178,142,251,65,179,95,69,35,83,228,155,117,225,61,76,108,126,245,131,104,81,209,249,226,171,98,42,8,149,70,157,48,55,10,47,14,36,27,223,205,78,127,234,18,29,88,52,54,220,180,91,164,118,183,125,82,221,94,19,166,185,0,193,64,227,121,182,212,141,103,114,148,152,176,133,187,197,79,237,134,154,102,17,138,233,4,254,160,120,37,75,162,93,128,5,63,33,112,241,99,119,175,66,32,229,253,191,129,24,38,195,190,53,136,46,147,85,252,122,200,186,50,230,192,25,158,163,68,84,59,11,140,199,107,40,167,188,22,173,219,100,116,20,146,12,72,184,159,189,67,196,57,49,211,242,213,139,110,218,1,177,156,73,216,172,243,207,202,244,71,16,111,240,74,92,56,87,115,151,203,161,232,62,150,97,13,15,224,124,113,204,144,6,247,28,194,106,174,105,23,153,58,39,217,235,43,34,210,169,7,51,45,60,21,201,135,170,80,165,3,89,9,26,101,215,132,208,130,41,90,30,123,168,109,44];
|
||||
|
||||
private static const _Xtime3Sbox:Array = [165,132,153,141,13,189,177,84,80,3,169,125,25,98,230,154,69,157,64,135,21,235,201,11,236,103,253,234,191,247,150,91,194,28,174,106,90,65,2,79,92,244,52,8,147,115,83,63,12,82,101,94,40,161,15,181,9,54,155,61,38,105,205,159,27,158,116,46,45,178,238,251,246,77,97,206,123,62,113,151,245,104,0,44,96,31,200,237,190,70,217,75,222,212,232,74,107,42,229,22,197,215,85,148,207,16,6,129,240,68,186,227,243,254,192,138,173,188,72,4,223,193,117,99,48,26,14,109,76,20,53,47,225,162,204,57,87,242,130,71,172,231,43,149,160,152,209,127,102,126,171,131,202,41,211,60,121,226,29,118,59,86,78,30,219,10,108,228,93,110,239,166,168,164,55,139,50,67,89,183,140,100,210,224,180,250,7,37,175,142,233,24,213,136,111,114,36,241,199,81,35,124,156,33,221,220,134,133,144,66,196,170,216,5,1,18,163,95,249,208,145,88,39,185,56,19,179,51,187,112,137,167,182,34,146,32,73,255,120,122,143,248,128,23,218,49,198,184,195,176,119,17,203,252,214,58];
|
||||
|
||||
private static const _Xtime2:Array = [0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180,182,184,186,188,190,192,194,196,198,200,202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,244,246,248,250,252,254,27,25,31,29,19,17,23,21,11,9,15,13,3,1,7,5,59,57,63,61,51,49,55,53,43,41,47,45,35,33,39,37,91,89,95,93,83,81,87,85,75,73,79,77,67,65,71,69,123,121,127,125,115,113,119,117,107,105,111,109,99,97,103,101,155,153,159,157,147,145,151,149,139,137,143,141,131,129,135,133,187,185,191,189,179,177,183,181,171,169,175,173,163,161,167,165,219,217,223,221,211,209,215,213,203,201,207,205,195,193,199,197,251,249,255,253,243,241,247,245,235,233,239,237,227,225,231,229];
|
||||
|
||||
private static const _Xtime9:Array = [0,9,18,27,36,45,54,63,72,65,90,83,108,101,126,119,144,153,130,139,180,189,166,175,216,209,202,195,252,245,238,231,59,50,41,32,31,22,13,4,115,122,97,104,87,94,69,76,171,162,185,176,143,134,157,148,227,234,241,248,199,206,213,220,118,127,100,109,82,91,64,73,62,55,44,37,26,19,8,1,230,239,244,253,194,203,208,217,174,167,188,181,138,131,152,145,77,68,95,86,105,96,123,114,5,12,23,30,33,40,51,58,221,212,207,198,249,240,235,226,149,156,135,142,177,184,163,170,236,229,254,247,200,193,218,211,164,173,182,191,128,137,146,155,124,117,110,103,88,81,74,67,52,61,38,47,16,25,2,11,215,222,197,204,243,250,225,232,159,150,141,132,187,178,169,160,71,78,85,92,99,106,113,120,15,6,29,20,43,34,57,48,154,147,136,129,190,183,172,165,210,219,192,201,246,255,228,237,10,3,24,17,46,39,60,53,66,75,80,89,102,111,116,125,161,168,179,186,133,140,151,158,233,224,251,242,205,196,223,214,49,56,35,42,21,28,7,14,121,112,107,98,93,84,79,70];
|
||||
|
||||
private static const _XtimeB:Array = [0,11,22,29,44,39,58,49,88,83,78,69,116,127,98,105,176,187,166,173,156,151,138,129,232,227,254,245,196,207,210,217,123,112,109,102,87,92,65,74,35,40,53,62,15,4,25,18,203,192,221,214,231,236,241,250,147,152,133,142,191,180,169,162,246,253,224,235,218,209,204,199,174,165,184,179,130,137,148,159,70,77,80,91,106,97,124,119,30,21,8,3,50,57,36,47,141,134,155,144,161,170,183,188,213,222,195,200,249,242,239,228,61,54,43,32,17,26,7,12,101,110,115,120,73,66,95,84,247,252,225,234,219,208,205,198,175,164,185,178,131,136,149,158,71,76,81,90,107,96,125,118,31,20,9,2,51,56,37,46,140,135,154,145,160,171,182,189,212,223,194,201,248,243,238,229,60,55,42,33,16,27,6,13,100,111,114,121,72,67,94,85,1,10,23,28,45,38,59,48,89,82,79,68,117,126,99,104,177,186,167,172,157,150,139,128,233,226,255,244,197,206,211,216,122,113,108,103,86,93,64,75,34,41,52,63,14,5,24,19,202,193,220,215,230,237,240,251,146,153,132,143,190,181,168,163];
|
||||
|
||||
private static const _XtimeD:Array = [0,13,26,23,52,57,46,35,104,101,114,127,92,81,70,75,208,221,202,199,228,233,254,243,184,181,162,175,140,129,150,155,187,182,161,172,143,130,149,152,211,222,201,196,231,234,253,240,107,102,113,124,95,82,69,72,3,14,25,20,55,58,45,32,109,96,119,122,89,84,67,78,5,8,31,18,49,60,43,38,189,176,167,170,137,132,147,158,213,216,207,194,225,236,251,246,214,219,204,193,226,239,248,245,190,179,164,169,138,135,144,157,6,11,28,17,50,63,40,37,110,99,116,121,90,87,64,77,218,215,192,205,238,227,244,249,178,191,168,165,134,139,156,145,10,7,16,29,62,51,36,41,98,111,120,117,86,91,76,65,97,108,123,118,85,88,79,66,9,4,19,30,61,48,39,42,177,188,171,166,133,136,159,146,217,212,195,206,237,224,247,250,183,186,173,160,131,142,153,148,223,210,197,200,235,230,241,252,103,106,125,112,83,94,73,68,15,2,21,24,59,54,33,44,12,1,22,27,56,53,34,47,100,105,126,115,80,93,74,71,220,209,198,203,232,229,242,255,180,185,174,163,128,141,154,151];
|
||||
|
||||
private static const _XtimeE:Array = [0,14,28,18,56,54,36,42,112,126,108,98,72,70,84,90,224,238,252,242,216,214,196,202,144,158,140,130,168,166,180,186,219,213,199,201,227,237,255,241,171,165,183,185,147,157,143,129,59,53,39,41,3,13,31,17,75,69,87,89,115,125,111,97,173,163,177,191,149,155,137,135,221,211,193,207,229,235,249,247,77,67,81,95,117,123,105,103,61,51,33,47,5,11,25,23,118,120,106,100,78,64,82,92,6,8,26,20,62,48,34,44,150,152,138,132,174,160,178,188,230,232,250,244,222,208,194,204,65,79,93,83,121,119,101,107,49,63,45,35,9,7,21,27,161,175,189,179,153,151,133,139,209,223,205,195,233,231,245,251,154,148,134,136,162,172,190,176,234,228,246,248,210,220,206,192,122,116,102,104,66,76,94,80,10,4,22,24,50,60,46,32,236,226,240,254,212,218,200,198,156,146,128,142,164,170,184,182,12,2,16,30,52,58,40,38,124,114,96,110,68,74,88,86,55,57,43,37,15,1,19,29,71,73,91,85,127,113,99,109,215,217,203,197,239,225,243,253,167,169,187,181,159,145,131,141];
|
||||
|
||||
private static var _Rcon:Array = [0,1,2,4,8,16,32,64,128,27,54];
|
||||
|
||||
private static var Sbox:ByteArray = new ByteArray();
|
||||
|
||||
private static var InvSbox:ByteArray = new ByteArray();
|
||||
|
||||
private static var Xtime2Sbox:ByteArray = new ByteArray();
|
||||
|
||||
private static var Xtime3Sbox:ByteArray = new ByteArray();
|
||||
|
||||
private static var Xtime2:ByteArray = new ByteArray();
|
||||
|
||||
private static var Xtime9:ByteArray = new ByteArray();
|
||||
|
||||
private static var XtimeB:ByteArray = new ByteArray();
|
||||
|
||||
private static var XtimeD:ByteArray = new ByteArray();
|
||||
|
||||
private static var XtimeE:ByteArray = new ByteArray();
|
||||
|
||||
private static var i:uint = 0;
|
||||
|
||||
while(i < 256)
|
||||
{
|
||||
Sbox[i] = _Sbox[i];
|
||||
InvSbox[i] = _InvSbox[i];
|
||||
Xtime2Sbox[i] = _Xtime2Sbox[i];
|
||||
Xtime3Sbox[i] = _Xtime3Sbox[i];
|
||||
Xtime2[i] = _Xtime2[i];
|
||||
Xtime9[i] = _Xtime9[i];
|
||||
XtimeB[i] = _XtimeB[i];
|
||||
XtimeD[i] = _XtimeD[i];
|
||||
XtimeE[i] = _XtimeE[i];
|
||||
++i;
|
||||
}
|
||||
|
||||
private static var Rcon:ByteArray = new ByteArray();
|
||||
|
||||
i = 0;
|
||||
while(i < _Rcon.length)
|
||||
{
|
||||
Rcon[i] = _Rcon[i];
|
||||
++i;
|
||||
}
|
||||
|
||||
private var key:ByteArray;
|
||||
|
||||
private var keyLength:uint;
|
||||
|
||||
private var Nr:uint;
|
||||
|
||||
private var state:ByteArray;
|
||||
|
||||
private var tmp:ByteArray;
|
||||
|
||||
public function AESKey(key:ByteArray)
|
||||
{
|
||||
super();
|
||||
this.tmp = new ByteArray();
|
||||
this.state = new ByteArray();
|
||||
this.keyLength = key.length;
|
||||
this.key = new ByteArray();
|
||||
this.key.writeBytes(key);
|
||||
this.expandKey();
|
||||
}
|
||||
|
||||
private function expandKey() : void
|
||||
{
|
||||
var tmp0:uint = 0;
|
||||
var tmp1:uint = 0;
|
||||
var tmp2:uint = 0;
|
||||
var tmp3:uint = 0;
|
||||
var tmp4:uint = 0;
|
||||
var idx:uint = 0;
|
||||
var Nk:uint = this.key.length / 4;
|
||||
this.Nr = Nk + 6;
|
||||
for(idx = Nk; idx < Nb * (this.Nr + 1); idx++)
|
||||
{
|
||||
tmp0 = uint(this.key[4 * idx - 4]);
|
||||
tmp1 = uint(this.key[4 * idx - 3]);
|
||||
tmp2 = uint(this.key[4 * idx - 2]);
|
||||
tmp3 = uint(this.key[4 * idx - 1]);
|
||||
if(!(idx % Nk))
|
||||
{
|
||||
tmp4 = tmp3;
|
||||
tmp3 = uint(Sbox[tmp0]);
|
||||
tmp0 = uint(Sbox[tmp1] ^ Rcon[idx / Nk]);
|
||||
tmp1 = uint(Sbox[tmp2]);
|
||||
tmp2 = uint(Sbox[tmp4]);
|
||||
}
|
||||
else if(Nk > 6 && idx % Nk == 4)
|
||||
{
|
||||
tmp0 = uint(Sbox[tmp0]);
|
||||
tmp1 = uint(Sbox[tmp1]);
|
||||
tmp2 = uint(Sbox[tmp2]);
|
||||
tmp3 = uint(Sbox[tmp3]);
|
||||
}
|
||||
this.key[4 * idx + 0] = this.key[4 * idx - 4 * Nk + 0] ^ tmp0;
|
||||
this.key[4 * idx + 1] = this.key[4 * idx - 4 * Nk + 1] ^ tmp1;
|
||||
this.key[4 * idx + 2] = this.key[4 * idx - 4 * Nk + 2] ^ tmp2;
|
||||
this.key[4 * idx + 3] = this.key[4 * idx - 4 * Nk + 3] ^ tmp3;
|
||||
}
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
public function encrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
var round:uint = 0;
|
||||
this.state.position = 0;
|
||||
this.state.writeBytes(block,index,Nb * 4);
|
||||
this.addRoundKey(this.key,0);
|
||||
for(round = 1; round < this.Nr + 1; round++)
|
||||
{
|
||||
if(round < this.Nr)
|
||||
{
|
||||
this.mixSubColumns();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.shiftRows();
|
||||
}
|
||||
this.addRoundKey(this.key,round * Nb * 4);
|
||||
}
|
||||
block.position = index;
|
||||
block.writeBytes(this.state);
|
||||
}
|
||||
|
||||
public function decrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
var round:uint = 0;
|
||||
this.state.position = 0;
|
||||
this.state.writeBytes(block,index,Nb * 4);
|
||||
this.addRoundKey(this.key,this.Nr * Nb * 4);
|
||||
this.invShiftRows();
|
||||
for(round = this.Nr; Boolean(round--); )
|
||||
{
|
||||
this.addRoundKey(this.key,round * Nb * 4);
|
||||
if(Boolean(round))
|
||||
{
|
||||
this.invMixSubColumns();
|
||||
}
|
||||
}
|
||||
block.position = index;
|
||||
block.writeBytes(this.state);
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
var r:Random = new Random();
|
||||
for(i = 0; i < this.key.length; i++)
|
||||
{
|
||||
this.key[i] = r.nextByte();
|
||||
}
|
||||
this.Nr = r.nextByte();
|
||||
for(i = 0; i < this.state.length; i++)
|
||||
{
|
||||
this.state[i] = r.nextByte();
|
||||
}
|
||||
for(i = 0; i < this.tmp.length; i++)
|
||||
{
|
||||
this.tmp[i] = r.nextByte();
|
||||
}
|
||||
this.key.length = 0;
|
||||
this.keyLength = 0;
|
||||
this.state.length = 0;
|
||||
this.tmp.length = 0;
|
||||
this.key = null;
|
||||
this.state = null;
|
||||
this.tmp = null;
|
||||
this.Nr = 0;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
protected function shiftRows() : void
|
||||
{
|
||||
var tmp:uint = 0;
|
||||
this.state[0] = Sbox[this.state[0]];
|
||||
this.state[4] = Sbox[this.state[4]];
|
||||
this.state[8] = Sbox[this.state[8]];
|
||||
this.state[12] = Sbox[this.state[12]];
|
||||
tmp = uint(Sbox[this.state[1]]);
|
||||
this.state[1] = Sbox[this.state[5]];
|
||||
this.state[5] = Sbox[this.state[9]];
|
||||
this.state[9] = Sbox[this.state[13]];
|
||||
this.state[13] = tmp;
|
||||
tmp = uint(Sbox[this.state[2]]);
|
||||
this.state[2] = Sbox[this.state[10]];
|
||||
this.state[10] = tmp;
|
||||
tmp = uint(Sbox[this.state[6]]);
|
||||
this.state[6] = Sbox[this.state[14]];
|
||||
this.state[14] = tmp;
|
||||
tmp = uint(Sbox[this.state[15]]);
|
||||
this.state[15] = Sbox[this.state[11]];
|
||||
this.state[11] = Sbox[this.state[7]];
|
||||
this.state[7] = Sbox[this.state[3]];
|
||||
this.state[3] = tmp;
|
||||
}
|
||||
|
||||
protected function invShiftRows() : void
|
||||
{
|
||||
var tmp:uint = 0;
|
||||
this.state[0] = InvSbox[this.state[0]];
|
||||
this.state[4] = InvSbox[this.state[4]];
|
||||
this.state[8] = InvSbox[this.state[8]];
|
||||
this.state[12] = InvSbox[this.state[12]];
|
||||
tmp = uint(InvSbox[this.state[13]]);
|
||||
this.state[13] = InvSbox[this.state[9]];
|
||||
this.state[9] = InvSbox[this.state[5]];
|
||||
this.state[5] = InvSbox[this.state[1]];
|
||||
this.state[1] = tmp;
|
||||
tmp = uint(InvSbox[this.state[2]]);
|
||||
this.state[2] = InvSbox[this.state[10]];
|
||||
this.state[10] = tmp;
|
||||
tmp = uint(InvSbox[this.state[6]]);
|
||||
this.state[6] = InvSbox[this.state[14]];
|
||||
this.state[14] = tmp;
|
||||
tmp = uint(InvSbox[this.state[3]]);
|
||||
this.state[3] = InvSbox[this.state[7]];
|
||||
this.state[7] = InvSbox[this.state[11]];
|
||||
this.state[11] = InvSbox[this.state[15]];
|
||||
this.state[15] = tmp;
|
||||
}
|
||||
|
||||
protected function mixSubColumns() : void
|
||||
{
|
||||
this.tmp.length = 0;
|
||||
this.tmp[0] = Xtime2Sbox[this.state[0]] ^ Xtime3Sbox[this.state[5]] ^ Sbox[this.state[10]] ^ Sbox[this.state[15]];
|
||||
this.tmp[1] = Sbox[this.state[0]] ^ Xtime2Sbox[this.state[5]] ^ Xtime3Sbox[this.state[10]] ^ Sbox[this.state[15]];
|
||||
this.tmp[2] = Sbox[this.state[0]] ^ Sbox[this.state[5]] ^ Xtime2Sbox[this.state[10]] ^ Xtime3Sbox[this.state[15]];
|
||||
this.tmp[3] = Xtime3Sbox[this.state[0]] ^ Sbox[this.state[5]] ^ Sbox[this.state[10]] ^ Xtime2Sbox[this.state[15]];
|
||||
this.tmp[4] = Xtime2Sbox[this.state[4]] ^ Xtime3Sbox[this.state[9]] ^ Sbox[this.state[14]] ^ Sbox[this.state[3]];
|
||||
this.tmp[5] = Sbox[this.state[4]] ^ Xtime2Sbox[this.state[9]] ^ Xtime3Sbox[this.state[14]] ^ Sbox[this.state[3]];
|
||||
this.tmp[6] = Sbox[this.state[4]] ^ Sbox[this.state[9]] ^ Xtime2Sbox[this.state[14]] ^ Xtime3Sbox[this.state[3]];
|
||||
this.tmp[7] = Xtime3Sbox[this.state[4]] ^ Sbox[this.state[9]] ^ Sbox[this.state[14]] ^ Xtime2Sbox[this.state[3]];
|
||||
this.tmp[8] = Xtime2Sbox[this.state[8]] ^ Xtime3Sbox[this.state[13]] ^ Sbox[this.state[2]] ^ Sbox[this.state[7]];
|
||||
this.tmp[9] = Sbox[this.state[8]] ^ Xtime2Sbox[this.state[13]] ^ Xtime3Sbox[this.state[2]] ^ Sbox[this.state[7]];
|
||||
this.tmp[10] = Sbox[this.state[8]] ^ Sbox[this.state[13]] ^ Xtime2Sbox[this.state[2]] ^ Xtime3Sbox[this.state[7]];
|
||||
this.tmp[11] = Xtime3Sbox[this.state[8]] ^ Sbox[this.state[13]] ^ Sbox[this.state[2]] ^ Xtime2Sbox[this.state[7]];
|
||||
this.tmp[12] = Xtime2Sbox[this.state[12]] ^ Xtime3Sbox[this.state[1]] ^ Sbox[this.state[6]] ^ Sbox[this.state[11]];
|
||||
this.tmp[13] = Sbox[this.state[12]] ^ Xtime2Sbox[this.state[1]] ^ Xtime3Sbox[this.state[6]] ^ Sbox[this.state[11]];
|
||||
this.tmp[14] = Sbox[this.state[12]] ^ Sbox[this.state[1]] ^ Xtime2Sbox[this.state[6]] ^ Xtime3Sbox[this.state[11]];
|
||||
this.tmp[15] = Xtime3Sbox[this.state[12]] ^ Sbox[this.state[1]] ^ Sbox[this.state[6]] ^ Xtime2Sbox[this.state[11]];
|
||||
this.state.position = 0;
|
||||
this.state.writeBytes(this.tmp,0,Nb * 4);
|
||||
}
|
||||
|
||||
protected function invMixSubColumns() : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
this.tmp.length = 0;
|
||||
this.tmp[0] = XtimeE[this.state[0]] ^ XtimeB[this.state[1]] ^ XtimeD[this.state[2]] ^ Xtime9[this.state[3]];
|
||||
this.tmp[5] = Xtime9[this.state[0]] ^ XtimeE[this.state[1]] ^ XtimeB[this.state[2]] ^ XtimeD[this.state[3]];
|
||||
this.tmp[10] = XtimeD[this.state[0]] ^ Xtime9[this.state[1]] ^ XtimeE[this.state[2]] ^ XtimeB[this.state[3]];
|
||||
this.tmp[15] = XtimeB[this.state[0]] ^ XtimeD[this.state[1]] ^ Xtime9[this.state[2]] ^ XtimeE[this.state[3]];
|
||||
this.tmp[4] = XtimeE[this.state[4]] ^ XtimeB[this.state[5]] ^ XtimeD[this.state[6]] ^ Xtime9[this.state[7]];
|
||||
this.tmp[9] = Xtime9[this.state[4]] ^ XtimeE[this.state[5]] ^ XtimeB[this.state[6]] ^ XtimeD[this.state[7]];
|
||||
this.tmp[14] = XtimeD[this.state[4]] ^ Xtime9[this.state[5]] ^ XtimeE[this.state[6]] ^ XtimeB[this.state[7]];
|
||||
this.tmp[3] = XtimeB[this.state[4]] ^ XtimeD[this.state[5]] ^ Xtime9[this.state[6]] ^ XtimeE[this.state[7]];
|
||||
this.tmp[8] = XtimeE[this.state[8]] ^ XtimeB[this.state[9]] ^ XtimeD[this.state[10]] ^ Xtime9[this.state[11]];
|
||||
this.tmp[13] = Xtime9[this.state[8]] ^ XtimeE[this.state[9]] ^ XtimeB[this.state[10]] ^ XtimeD[this.state[11]];
|
||||
this.tmp[2] = XtimeD[this.state[8]] ^ Xtime9[this.state[9]] ^ XtimeE[this.state[10]] ^ XtimeB[this.state[11]];
|
||||
this.tmp[7] = XtimeB[this.state[8]] ^ XtimeD[this.state[9]] ^ Xtime9[this.state[10]] ^ XtimeE[this.state[11]];
|
||||
this.tmp[12] = XtimeE[this.state[12]] ^ XtimeB[this.state[13]] ^ XtimeD[this.state[14]] ^ Xtime9[this.state[15]];
|
||||
this.tmp[1] = Xtime9[this.state[12]] ^ XtimeE[this.state[13]] ^ XtimeB[this.state[14]] ^ XtimeD[this.state[15]];
|
||||
this.tmp[6] = XtimeD[this.state[12]] ^ Xtime9[this.state[13]] ^ XtimeE[this.state[14]] ^ XtimeB[this.state[15]];
|
||||
this.tmp[11] = XtimeB[this.state[12]] ^ XtimeD[this.state[13]] ^ Xtime9[this.state[14]] ^ XtimeE[this.state[15]];
|
||||
for(i = 0; i < 4 * Nb; i++)
|
||||
{
|
||||
this.state[i] = InvSbox[this.tmp[i]];
|
||||
}
|
||||
}
|
||||
|
||||
protected function addRoundKey(key:ByteArray, offset:uint) : void
|
||||
{
|
||||
var idx:uint = 0;
|
||||
for(idx = 0; idx < 16; idx++)
|
||||
{
|
||||
this.state[idx] ^= key[idx + offset];
|
||||
}
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "aes" + 8 * this.keyLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class BlowFishKey implements ISymmetricKey
|
||||
{
|
||||
|
||||
private static const KP:Array = [608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731];
|
||||
|
||||
private static const KS0:Array = [3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486
|
||||
,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737
|
||||
,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946];
|
||||
|
||||
private static const KS1:Array = [1266315497,3048417604,3681880366,3289982499,2909710000,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616
|
||||
,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670
|
||||
,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055];
|
||||
|
||||
private static const KS2:Array = [3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280
|
||||
,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629
|
||||
,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504];
|
||||
|
||||
private static const KS3:Array = [976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805
|
||||
,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409000,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506
|
||||
,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462];
|
||||
|
||||
private static const ROUNDS:uint = 16;
|
||||
|
||||
private static const BLOCK_SIZE:uint = 8;
|
||||
|
||||
private static const SBOX_SK:uint = 256;
|
||||
|
||||
private static const P_SZ:uint = ROUNDS + 2;
|
||||
|
||||
private var S0:Array;
|
||||
|
||||
private var S1:Array;
|
||||
|
||||
private var S2:Array;
|
||||
|
||||
private var S3:Array;
|
||||
|
||||
private var P:Array;
|
||||
|
||||
private var key:ByteArray = null;
|
||||
|
||||
public function BlowFishKey(key:ByteArray)
|
||||
{
|
||||
super();
|
||||
this.key = key;
|
||||
this.setKey(key);
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return BLOCK_SIZE;
|
||||
}
|
||||
|
||||
public function decrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
this.decryptBlock(block,index,block,index);
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
i = 0;
|
||||
while(i < this.S0.length)
|
||||
{
|
||||
this.S0[i] = 0;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while(i < this.S1.length)
|
||||
{
|
||||
this.S1[i] = 0;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while(i < this.S2.length)
|
||||
{
|
||||
this.S2[i] = 0;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while(i < this.S3.length)
|
||||
{
|
||||
this.S3[i] = 0;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while(i < this.P.length)
|
||||
{
|
||||
this.P[i] = 0;
|
||||
i++;
|
||||
}
|
||||
this.S0 = null;
|
||||
this.S1 = null;
|
||||
this.S2 = null;
|
||||
this.S3 = null;
|
||||
this.P = null;
|
||||
for(i = 0; i < this.key.length; i++)
|
||||
{
|
||||
this.key[i] = 0;
|
||||
}
|
||||
this.key.length = 0;
|
||||
this.key = null;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function encrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
this.encryptBlock(block,index,block,index);
|
||||
}
|
||||
|
||||
private function F(x:uint) : uint
|
||||
{
|
||||
return (this.S0[x >>> 24] + this.S1[x >>> 16 & 0xFF] ^ this.S2[x >>> 8 & 0xFF]) + this.S3[x & 0xFF];
|
||||
}
|
||||
|
||||
private function processTable(xl:uint, xr:uint, table:Array) : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
var size:uint = table.length;
|
||||
for(var s:uint = 0; s < size; s += 2)
|
||||
{
|
||||
xl ^= this.P[0];
|
||||
for(i = 1; i < ROUNDS; i += 2)
|
||||
{
|
||||
xr ^= this.F(xl) ^ this.P[i];
|
||||
xl ^= this.F(xr) ^ this.P[i + 1];
|
||||
}
|
||||
xr ^= this.P[ROUNDS + 1];
|
||||
table[s] = xr;
|
||||
table[s + 1] = xl;
|
||||
xr = xl;
|
||||
xl = uint(table[s]);
|
||||
}
|
||||
}
|
||||
|
||||
private function setKey(key:ByteArray) : void
|
||||
{
|
||||
var data:uint = 0;
|
||||
var j:uint = 0;
|
||||
this.S0 = KS0.concat();
|
||||
this.S1 = KS1.concat();
|
||||
this.S2 = KS2.concat();
|
||||
this.S3 = KS3.concat();
|
||||
this.P = KP.concat();
|
||||
var keyLength:uint = key.length;
|
||||
var keyIndex:uint = 0;
|
||||
for(var i:uint = 0; i < P_SZ; i++)
|
||||
{
|
||||
data = 0;
|
||||
for(j = 0; j < 4; j++)
|
||||
{
|
||||
data = uint(data << 8 | key[keyIndex++] & 0xFF);
|
||||
if(keyIndex >= keyLength)
|
||||
{
|
||||
keyIndex = 0;
|
||||
}
|
||||
}
|
||||
this.P[i] ^= data;
|
||||
}
|
||||
this.processTable(0,0,this.P);
|
||||
this.processTable(this.P[P_SZ - 2],this.P[P_SZ - 1],this.S0);
|
||||
this.processTable(this.S0[SBOX_SK - 2],this.S0[SBOX_SK - 1],this.S1);
|
||||
this.processTable(this.S1[SBOX_SK - 2],this.S1[SBOX_SK - 1],this.S2);
|
||||
this.processTable(this.S2[SBOX_SK - 2],this.S2[SBOX_SK - 1],this.S3);
|
||||
}
|
||||
|
||||
private function encryptBlock(src:ByteArray, srcIndex:uint, dst:ByteArray, dstIndex:uint) : void
|
||||
{
|
||||
var xl:uint = this.BytesTo32bits(src,srcIndex);
|
||||
var xr:uint = this.BytesTo32bits(src,srcIndex + 4);
|
||||
xl ^= this.P[0];
|
||||
for(var i:uint = 1; i < ROUNDS; i += 2)
|
||||
{
|
||||
xr ^= this.F(xl) ^ this.P[i];
|
||||
xl ^= this.F(xr) ^ this.P[i + 1];
|
||||
}
|
||||
xr ^= this.P[ROUNDS + 1];
|
||||
this.Bits32ToBytes(xr,dst,dstIndex);
|
||||
this.Bits32ToBytes(xl,dst,dstIndex + 4);
|
||||
}
|
||||
|
||||
private function decryptBlock(src:ByteArray, srcIndex:uint, dst:ByteArray, dstIndex:uint) : void
|
||||
{
|
||||
var xl:uint = this.BytesTo32bits(src,srcIndex);
|
||||
var xr:uint = this.BytesTo32bits(src,srcIndex + 4);
|
||||
xl ^= this.P[ROUNDS + 1];
|
||||
for(var i:uint = ROUNDS; i > 0; i -= 2)
|
||||
{
|
||||
xr ^= this.F(xl) ^ this.P[i];
|
||||
xl ^= this.F(xr) ^ this.P[i - 1];
|
||||
}
|
||||
xr ^= this.P[0];
|
||||
this.Bits32ToBytes(xr,dst,dstIndex);
|
||||
this.Bits32ToBytes(xl,dst,dstIndex + 4);
|
||||
}
|
||||
|
||||
private function BytesTo32bits(b:ByteArray, i:uint) : uint
|
||||
{
|
||||
return (b[i] & 0xFF) << 24 | (b[i + 1] & 0xFF) << 16 | (b[i + 2] & 0xFF) << 8 | b[i + 3] & 0xFF;
|
||||
}
|
||||
|
||||
private function Bits32ToBytes(i:uint, b:ByteArray, offset:uint) : void
|
||||
{
|
||||
b[offset + 3] = i;
|
||||
b[offset + 2] = i >> 8;
|
||||
b[offset + 1] = i >> 16;
|
||||
b[offset] = i >> 24;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "blowfish";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class CBCMode extends IVMode implements IMode
|
||||
{
|
||||
|
||||
public function CBCMode(key:ISymmetricKey, padding:IPad = null)
|
||||
{
|
||||
super(key,padding);
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray) : void
|
||||
{
|
||||
var j:uint = 0;
|
||||
padding.pad(src);
|
||||
var vector:ByteArray = getIV4e();
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
for(j = 0; j < blockSize; j++)
|
||||
{
|
||||
src[i + j] ^= vector[j];
|
||||
}
|
||||
key.encrypt(src,i);
|
||||
vector.position = 0;
|
||||
vector.writeBytes(src,i,blockSize);
|
||||
}
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray) : void
|
||||
{
|
||||
var j:uint = 0;
|
||||
var vector:ByteArray = getIV4d();
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
tmp.position = 0;
|
||||
tmp.writeBytes(src,i,blockSize);
|
||||
key.decrypt(src,i);
|
||||
for(j = 0; j < blockSize; j++)
|
||||
{
|
||||
src[i + j] ^= vector[j];
|
||||
}
|
||||
vector.position = 0;
|
||||
vector.writeBytes(tmp,0,blockSize);
|
||||
}
|
||||
padding.unpad(src);
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return key.toString() + "-cbc";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class CFB8Mode extends IVMode implements IMode
|
||||
{
|
||||
|
||||
public function CFB8Mode(key:ISymmetricKey, padding:IPad = null)
|
||||
{
|
||||
super(key,null);
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray) : void
|
||||
{
|
||||
var j:uint = 0;
|
||||
var vector:ByteArray = getIV4e();
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < src.length; i++)
|
||||
{
|
||||
tmp.position = 0;
|
||||
tmp.writeBytes(vector);
|
||||
key.encrypt(vector);
|
||||
src[i] ^= vector[0];
|
||||
for(j = 0; j < blockSize - 1; j++)
|
||||
{
|
||||
vector[j] = tmp[j + 1];
|
||||
}
|
||||
vector[blockSize - 1] = src[i];
|
||||
}
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray) : void
|
||||
{
|
||||
var c:uint = 0;
|
||||
var j:uint = 0;
|
||||
var vector:ByteArray = getIV4d();
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < src.length; i++)
|
||||
{
|
||||
c = uint(src[i]);
|
||||
tmp.position = 0;
|
||||
tmp.writeBytes(vector);
|
||||
key.encrypt(vector);
|
||||
src[i] ^= vector[0];
|
||||
for(j = 0; j < blockSize - 1; j++)
|
||||
{
|
||||
vector[j] = tmp[j + 1];
|
||||
}
|
||||
vector[blockSize - 1] = c;
|
||||
}
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return key.toString() + "-cfb8";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class CFBMode extends IVMode implements IMode
|
||||
{
|
||||
|
||||
public function CFBMode(key:ISymmetricKey, padding:IPad = null)
|
||||
{
|
||||
super(key,null);
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray) : void
|
||||
{
|
||||
var chunk:uint = 0;
|
||||
var j:uint = 0;
|
||||
var l:uint = src.length;
|
||||
var vector:ByteArray = getIV4e();
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
key.encrypt(vector);
|
||||
chunk = i + blockSize < l ? blockSize : uint(l - i);
|
||||
for(j = 0; j < chunk; j++)
|
||||
{
|
||||
src[i + j] ^= vector[j];
|
||||
}
|
||||
vector.position = 0;
|
||||
vector.writeBytes(src,i,chunk);
|
||||
}
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray) : void
|
||||
{
|
||||
var chunk:uint = 0;
|
||||
var j:uint = 0;
|
||||
var l:uint = src.length;
|
||||
var vector:ByteArray = getIV4d();
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
key.encrypt(vector);
|
||||
chunk = i + blockSize < l ? blockSize : uint(l - i);
|
||||
tmp.position = 0;
|
||||
tmp.writeBytes(src,i,chunk);
|
||||
for(j = 0; j < chunk; j++)
|
||||
{
|
||||
src[i + j] ^= vector[j];
|
||||
}
|
||||
vector.position = 0;
|
||||
vector.writeBytes(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return key.toString() + "-cfb";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class CTRMode extends IVMode implements IMode
|
||||
{
|
||||
|
||||
public function CTRMode(key:ISymmetricKey, padding:IPad = null)
|
||||
{
|
||||
super(key,padding);
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray) : void
|
||||
{
|
||||
padding.pad(src);
|
||||
var vector:ByteArray = getIV4e();
|
||||
this.core(src,vector);
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray) : void
|
||||
{
|
||||
var vector:ByteArray = getIV4d();
|
||||
this.core(src,vector);
|
||||
padding.unpad(src);
|
||||
}
|
||||
|
||||
private function core(src:ByteArray, iv:ByteArray) : void
|
||||
{
|
||||
var j:uint = 0;
|
||||
var X:ByteArray = new ByteArray();
|
||||
var Xenc:ByteArray = new ByteArray();
|
||||
X.writeBytes(iv);
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
Xenc.position = 0;
|
||||
Xenc.writeBytes(X);
|
||||
key.encrypt(Xenc);
|
||||
for(j = 0; j < blockSize; j++)
|
||||
{
|
||||
src[i + j] ^= Xenc[j];
|
||||
}
|
||||
for(j = blockSize - 1; j >= 0; j--)
|
||||
{
|
||||
++X[j];
|
||||
if(X[j] != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return key.toString() + "-ctr";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,258 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class DESKey implements ISymmetricKey
|
||||
{
|
||||
|
||||
private static const Df_Key:Array = [1,35,69,103,137,171,205,239,254,220,186,152,118,84,50,16,137,171,205,239,1,35,69,103];
|
||||
|
||||
private static const bytebit:Array = [128,64,32,16,8,4,2,1];
|
||||
|
||||
private static const bigbyte:Array = [8388608,4194304,2097152,1048576,524288,262144,131072,65536,32768,16384,8192,4096,2048,1024,512,256,128,64,32,16,8,4,2,1];
|
||||
|
||||
private static const pc1:Array = [56,48,40,32,24,16,8,0,57,49,41,33,25,17,9,1,58,50,42,34,26,18,10,2,59,51,43,35,62,54,46,38,30,22,14,6,61,53,45,37,29,21,13,5,60,52,44,36,28,20,12,4,27,19,11,3];
|
||||
|
||||
private static const totrot:Array = [1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28];
|
||||
|
||||
private static const pc2:Array = [13,16,10,23,0,4,2,27,14,5,20,9,22,18,11,3,25,7,15,6,26,19,12,1,40,51,30,36,46,54,29,39,50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31];
|
||||
|
||||
private static const SP1:Array = [16843776,0,65536,16843780,16842756,66564,4,65536,1024,16843776,16843780,1024,16778244,16842756,16777216,4,1028,16778240,16778240,66560,66560,16842752,16842752,16778244,65540,16777220,16777220,65540,0,1028,66564,16777216,65536,16843780,4,16842752,16843776,16777216,16777216,1024,16842756,65536,66560,16777220,1024,4,16778244,66564,16843780,65540,16842752,16778244,16777220,1028,66564,16843776,1028,16778240,16778240,0,65540,66560,0,16842756];
|
||||
|
||||
private static const SP2:Array = [2148565024,2147516416,32768,1081376,1048576,32,2148532256,2147516448,2147483680,2148565024,2148564992,2147483648,2147516416,1048576,32,2148532256,1081344,1048608,2147516448,0,2147483648,32768,1081376,2148532224,1048608,2147483680,0,1081344,32800,2148564992,2148532224,32800,0,1081376,2148532256,1048576,2147516448,2148532224,2148564992,32768,2148532224,2147516416,32,2148565024,1081376,32,32768,2147483648,32800,2148564992,1048576,2147483680,1048608,2147516448,2147483680,1048608,1081344,0,2147516416,32800,2147483648,2148532256,2148565024,1081344];
|
||||
|
||||
private static const SP3:Array = [520,134349312,0,134348808,134218240,0,131592,134218240,131080,134217736,134217736,131072,134349320,131080,134348800,520,134217728,8,134349312,512,131584,134348800,134348808,131592,134218248,131584,131072,134218248,8,134349320,512,134217728,134349312,134217728,131080,520,131072,134349312,134218240,0,512,131080,134349320,134218240,134217736,512,0,134348808,134218248,131072,134217728,134349320,8,131592,131584,134217736,134348800,134218248,520,134348800,131592,8,134348808,131584];
|
||||
|
||||
private static const SP4:Array = [8396801,8321,8321,128,8396928,8388737,8388609,8193,0,8396800,8396800,8396929,129,0,8388736,8388609,1,8192,8388608,8396801,128,8388608,8193,8320,8388737,1,8320,8388736,8192,8396928,8396929,129,8388736,8388609,8396800,8396929,129,0,0,8396800,8320,8388736,8388737,1,8396801,8321,8321,128,8396929,129,1,8192,8388609,8193,8396928,8388737,8193,8320,8388608,8396801,128,8388608,8192,8396928];
|
||||
|
||||
private static const SP5:Array = [256,34078976,34078720,1107296512,524288,256,1073741824,34078720,1074266368,524288,33554688,1074266368,1107296512,1107820544,524544,1073741824,33554432,1074266112,1074266112,0,1073742080,1107820800,1107820800,33554688,1107820544,1073742080,0,1107296256,34078976,33554432,1107296256,524544,524288,1107296512,256,33554432,1073741824,34078720,1107296512,1074266368,33554688,1073741824,1107820544,34078976,1074266368,256,33554432,1107820544,1107820800,524544,1107296256,1107820800,34078720,0,1074266112,1107296256,524544,33554688,1073742080,524288,0,1074266112,34078976,1073742080];
|
||||
|
||||
private static const SP6:Array = [536870928,541065216,16384,541081616,541065216,16,541081616,4194304,536887296,4210704,4194304,536870928,4194320,536887296,536870912,16400,0,4194320,536887312,16384,4210688,536887312,16,541065232,541065232,0,4210704,541081600,16400,4210688,541081600,536870912,536887296,16,541065232,4210688,541081616,4194304,16400,536870928,4194304,536887296,536870912,16400,536870928,541081616,4210688,541065216,4210704,541081600,0,541065232,16,16384,541065216,4210704,16384,4194320,536887312,0,541081600,536870912,4194320,536887312];
|
||||
|
||||
private static const SP7:Array = [2097152,69206018,67110914,0,2048,67110914,2099202,69208064,69208066,2097152,0,67108866,2,67108864,69206018,2050,67110912,2099202,2097154,67110912,67108866,69206016,69208064,2097154,69206016,2048,2050,69208066,2099200,2,67108864,2099200,67108864,2099200,2097152,67110914,67110914,69206018,69206018,2,2097154,67108864,67110912,2097152,69208064,2050,2099202,69208064,2050,67108866,69208066,69206016,2099200,0,2,69208066,0,2099202,69206016,2048,67108866,67110912,2048,2097154];
|
||||
|
||||
private static const SP8:Array = [268439616,4096,262144,268701760,268435456,268439616,64,268435456,262208,268697600,268701760,266240,268701696,266304,4096,64,268697600,268435520,268439552,4160,266240,262208,268697664,268701696,4160,0,0,268697664,268435520,268439552,266304,262144,266304,262144,268701696,4096,64,268697664,4096,266304,268439552,64,268435520,268697600,268697664,268435456,262144,268439616,0,268701760,262208,268435520,268697600,268439552,268439616,0,268701760,266240,266240,4160,4160,262208,268435456,268701696];
|
||||
|
||||
protected var key:ByteArray;
|
||||
|
||||
protected var encKey:Array;
|
||||
|
||||
protected var decKey:Array;
|
||||
|
||||
public function DESKey(key:ByteArray)
|
||||
{
|
||||
super();
|
||||
this.key = key;
|
||||
this.encKey = this.generateWorkingKey(true,key,0);
|
||||
this.decKey = this.generateWorkingKey(false,key,0);
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
public function decrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
this.desFunc(this.decKey,block,index,block,index);
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
i = 0;
|
||||
while(i < this.encKey.length)
|
||||
{
|
||||
this.encKey[i] = 0;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while(i < this.decKey.length)
|
||||
{
|
||||
this.decKey[i] = 0;
|
||||
i++;
|
||||
}
|
||||
this.encKey = null;
|
||||
this.decKey = null;
|
||||
i = 0;
|
||||
while(i < this.key.length)
|
||||
{
|
||||
this.key[i] = 0;
|
||||
i++;
|
||||
}
|
||||
this.key.length = 0;
|
||||
this.key = null;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function encrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
this.desFunc(this.encKey,block,index,block,index);
|
||||
}
|
||||
|
||||
protected function generateWorkingKey(encrypting:Boolean, key:ByteArray, off:uint) : Array
|
||||
{
|
||||
var l:uint = 0;
|
||||
var m:uint = 0;
|
||||
var n:uint = 0;
|
||||
var i1:uint = 0;
|
||||
var i2:uint = 0;
|
||||
var newKey:Array = [];
|
||||
var pc1m:ByteArray = new ByteArray();
|
||||
var pcr:ByteArray = new ByteArray();
|
||||
for(var j:uint = 0; j < 56; j++)
|
||||
{
|
||||
l = uint(pc1[j]);
|
||||
pc1m[j] = (key[off + (l >>> 3)] & bytebit[l & 7]) != 0;
|
||||
}
|
||||
for(var i:uint = 0; i < 16; i++)
|
||||
{
|
||||
if(encrypting)
|
||||
{
|
||||
m = uint(i << 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
m = uint(15 - i << 1);
|
||||
}
|
||||
n = m + 1;
|
||||
newKey[m] = newKey[n] = 0;
|
||||
for(j = 0; j < 28; j++)
|
||||
{
|
||||
l = j + totrot[i];
|
||||
if(l < 28)
|
||||
{
|
||||
pcr[j] = pc1m[l];
|
||||
}
|
||||
else
|
||||
{
|
||||
pcr[j] = pc1m[l - 28];
|
||||
}
|
||||
}
|
||||
for(j = 28; j < 56; j++)
|
||||
{
|
||||
l = j + totrot[i];
|
||||
if(l < 56)
|
||||
{
|
||||
pcr[j] = pc1m[l];
|
||||
}
|
||||
else
|
||||
{
|
||||
pcr[j] = pc1m[l - 28];
|
||||
}
|
||||
}
|
||||
for(j = 0; j < 24; j++)
|
||||
{
|
||||
if(Boolean(pcr[pc2[j]]))
|
||||
{
|
||||
newKey[m] |= bigbyte[j];
|
||||
}
|
||||
if(Boolean(pcr[pc2[j + 24]]))
|
||||
{
|
||||
newKey[n] |= bigbyte[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
for(i = 0; i != 32; i += 2)
|
||||
{
|
||||
i1 = uint(newKey[i]);
|
||||
i2 = uint(newKey[i + 1]);
|
||||
newKey[i] = (i1 & 0xFC0000) << 6 | (i1 & 0x0FC0) << 10 | (i2 & 0xFC0000) >>> 10 | (i2 & 0x0FC0) >>> 6;
|
||||
newKey[i + 1] = (i1 & 0x03F000) << 12 | (i1 & 0x3F) << 16 | (i2 & 0x03F000) >>> 4 | i2 & 0x3F;
|
||||
}
|
||||
return newKey;
|
||||
}
|
||||
|
||||
protected function desFunc(wKey:Array, inp:ByteArray, inOff:uint, out:ByteArray, outOff:uint) : void
|
||||
{
|
||||
var work:uint = 0;
|
||||
var right:uint = 0;
|
||||
var left:uint = 0;
|
||||
var fval:uint = 0;
|
||||
left = uint((inp[inOff + 0] & 0xFF) << 24);
|
||||
left |= (inp[inOff + 1] & 0xFF) << 16;
|
||||
left |= (inp[inOff + 2] & 0xFF) << 8;
|
||||
left |= inp[inOff + 3] & 0xFF;
|
||||
right = uint((inp[inOff + 4] & 0xFF) << 24);
|
||||
right |= (inp[inOff + 5] & 0xFF) << 16;
|
||||
right |= (inp[inOff + 6] & 0xFF) << 8;
|
||||
right |= inp[inOff + 7] & 0xFF;
|
||||
work = uint((left >>> 4 ^ right) & 0x0F0F0F0F);
|
||||
right ^= work;
|
||||
left ^= work << 4;
|
||||
work = uint((left >>> 16 ^ right) & 0xFFFF);
|
||||
right ^= work;
|
||||
left ^= work << 16;
|
||||
work = uint((right >>> 2 ^ left) & 0x33333333);
|
||||
left ^= work;
|
||||
right ^= work << 2;
|
||||
work = uint((right >>> 8 ^ left) & 0xFF00FF);
|
||||
left ^= work;
|
||||
right ^= work << 8;
|
||||
right = uint((right << 1 | right >>> 31 & 1) & 0xFFFFFFFF);
|
||||
work = uint((left ^ right) & 0xAAAAAAAA);
|
||||
left ^= work;
|
||||
right ^= work;
|
||||
left = uint((left << 1 | left >>> 31 & 1) & 0xFFFFFFFF);
|
||||
for(var round:uint = 0; round < 8; round++)
|
||||
{
|
||||
work = uint(right << 28 | right >>> 4);
|
||||
work ^= wKey[round * 4 + 0];
|
||||
fval = uint(SP7[work & 0x3F]);
|
||||
fval |= SP5[work >>> 8 & 0x3F];
|
||||
fval |= SP3[work >>> 16 & 0x3F];
|
||||
fval |= SP1[work >>> 24 & 0x3F];
|
||||
work = uint(right ^ wKey[round * 4 + 1]);
|
||||
fval |= SP8[work & 0x3F];
|
||||
fval |= SP6[work >>> 8 & 0x3F];
|
||||
fval |= SP4[work >>> 16 & 0x3F];
|
||||
fval |= SP2[work >>> 24 & 0x3F];
|
||||
left ^= fval;
|
||||
work = uint(left << 28 | left >>> 4);
|
||||
work ^= wKey[round * 4 + 2];
|
||||
fval = uint(SP7[work & 0x3F]);
|
||||
fval |= SP5[work >>> 8 & 0x3F];
|
||||
fval |= SP3[work >>> 16 & 0x3F];
|
||||
fval |= SP1[work >>> 24 & 0x3F];
|
||||
work = uint(left ^ wKey[round * 4 + 3]);
|
||||
fval |= SP8[work & 0x3F];
|
||||
fval |= SP6[work >>> 8 & 0x3F];
|
||||
fval |= SP4[work >>> 16 & 0x3F];
|
||||
fval |= SP2[work >>> 24 & 0x3F];
|
||||
right ^= fval;
|
||||
}
|
||||
right = uint(right << 31 | right >>> 1);
|
||||
work = uint((left ^ right) & 0xAAAAAAAA);
|
||||
left ^= work;
|
||||
right ^= work;
|
||||
left = uint(left << 31 | left >>> 1);
|
||||
work = uint((left >>> 8 ^ right) & 0xFF00FF);
|
||||
right ^= work;
|
||||
left ^= work << 8;
|
||||
work = uint((left >>> 2 ^ right) & 0x33333333);
|
||||
right ^= work;
|
||||
left ^= work << 2;
|
||||
work = uint((right >>> 16 ^ left) & 0xFFFF);
|
||||
left ^= work;
|
||||
right ^= work << 16;
|
||||
work = uint((right >>> 4 ^ left) & 0x0F0F0F0F);
|
||||
left ^= work;
|
||||
right ^= work << 4;
|
||||
out[outOff + 0] = right >>> 24 & 0xFF;
|
||||
out[outOff + 1] = right >>> 16 & 0xFF;
|
||||
out[outOff + 2] = right >>> 8 & 0xFF;
|
||||
out[outOff + 3] = right & 0xFF;
|
||||
out[outOff + 4] = left >>> 24 & 0xFF;
|
||||
out[outOff + 5] = left >>> 16 & 0xFF;
|
||||
out[outOff + 6] = left >>> 8 & 0xFF;
|
||||
out[outOff + 7] = left & 0xFF;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "des";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class ECBMode implements IMode, ICipher
|
||||
{
|
||||
|
||||
private var key:ISymmetricKey;
|
||||
|
||||
private var padding:IPad;
|
||||
|
||||
public function ECBMode(key:ISymmetricKey, padding:IPad = null)
|
||||
{
|
||||
super();
|
||||
this.key = key;
|
||||
if(padding == null)
|
||||
{
|
||||
padding = new PKCS5(key.getBlockSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
padding.setBlockSize(key.getBlockSize());
|
||||
}
|
||||
this.padding = padding;
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return this.key.getBlockSize();
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray) : void
|
||||
{
|
||||
this.padding.pad(src);
|
||||
src.position = 0;
|
||||
var blockSize:uint = this.key.getBlockSize();
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
var dst:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
tmp.length = 0;
|
||||
src.readBytes(tmp,0,blockSize);
|
||||
this.key.encrypt(tmp);
|
||||
dst.writeBytes(tmp);
|
||||
}
|
||||
src.length = 0;
|
||||
src.writeBytes(dst);
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray) : void
|
||||
{
|
||||
src.position = 0;
|
||||
var blockSize:uint = this.key.getBlockSize();
|
||||
if(src.length % blockSize != 0)
|
||||
{
|
||||
throw new Error("ECB mode cipher length must be a multiple of blocksize " + blockSize);
|
||||
}
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
var dst:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
tmp.length = 0;
|
||||
src.readBytes(tmp,0,blockSize);
|
||||
this.key.decrypt(tmp);
|
||||
dst.writeBytes(tmp);
|
||||
}
|
||||
this.padding.unpad(dst);
|
||||
src.length = 0;
|
||||
src.writeBytes(dst);
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
this.key.dispose();
|
||||
this.key = null;
|
||||
this.padding = null;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return this.key.toString() + "-ecb";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public interface ICipher
|
||||
{
|
||||
|
||||
function getBlockSize() : uint;
|
||||
|
||||
function encrypt(param1:ByteArray) : void;
|
||||
|
||||
function decrypt(param1:ByteArray) : void;
|
||||
|
||||
function dispose() : void;
|
||||
|
||||
function toString() : String;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
public interface IMode extends ICipher
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public interface IPad
|
||||
{
|
||||
|
||||
function pad(param1:ByteArray) : void;
|
||||
|
||||
function unpad(param1:ByteArray) : void;
|
||||
|
||||
function setBlockSize(param1:uint) : void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
public interface IStreamCipher extends ICipher
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public interface ISymmetricKey
|
||||
{
|
||||
|
||||
function getBlockSize() : uint;
|
||||
|
||||
function encrypt(param1:ByteArray, param2:uint = 0) : void;
|
||||
|
||||
function decrypt(param1:ByteArray, param2:uint = 0) : void;
|
||||
|
||||
function dispose() : void;
|
||||
|
||||
function toString() : String;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.crypto.prng.Random;
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class IVMode
|
||||
{
|
||||
|
||||
protected var key:ISymmetricKey;
|
||||
|
||||
protected var padding:IPad;
|
||||
|
||||
protected var prng:Random;
|
||||
|
||||
protected var iv:ByteArray;
|
||||
|
||||
protected var lastIV:ByteArray;
|
||||
|
||||
protected var blockSize:uint;
|
||||
|
||||
public function IVMode(key:ISymmetricKey, padding:IPad = null)
|
||||
{
|
||||
super();
|
||||
this.key = key;
|
||||
this.blockSize = key.getBlockSize();
|
||||
if(padding == null)
|
||||
{
|
||||
padding = new PKCS5(this.blockSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
padding.setBlockSize(this.blockSize);
|
||||
}
|
||||
this.padding = padding;
|
||||
this.prng = new Random();
|
||||
this.iv = null;
|
||||
this.lastIV = new ByteArray();
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return this.key.getBlockSize();
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
if(this.iv != null)
|
||||
{
|
||||
for(i = 0; i < this.iv.length; i++)
|
||||
{
|
||||
this.iv[i] = this.prng.nextByte();
|
||||
}
|
||||
this.iv.length = 0;
|
||||
this.iv = null;
|
||||
}
|
||||
if(this.lastIV != null)
|
||||
{
|
||||
for(i = 0; i < this.iv.length; i++)
|
||||
{
|
||||
this.lastIV[i] = this.prng.nextByte();
|
||||
}
|
||||
this.lastIV.length = 0;
|
||||
this.lastIV = null;
|
||||
}
|
||||
this.key.dispose();
|
||||
this.key = null;
|
||||
this.padding = null;
|
||||
this.prng.dispose();
|
||||
this.prng = null;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function set IV(value:ByteArray) : void
|
||||
{
|
||||
this.iv = value;
|
||||
this.lastIV.length = 0;
|
||||
this.lastIV.writeBytes(this.iv);
|
||||
}
|
||||
|
||||
public function get IV() : ByteArray
|
||||
{
|
||||
return this.lastIV;
|
||||
}
|
||||
|
||||
protected function getIV4e() : ByteArray
|
||||
{
|
||||
var vec:ByteArray = new ByteArray();
|
||||
if(Boolean(this.iv))
|
||||
{
|
||||
vec.writeBytes(this.iv);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.prng.nextBytes(vec,this.blockSize);
|
||||
}
|
||||
this.lastIV.length = 0;
|
||||
this.lastIV.writeBytes(vec);
|
||||
return vec;
|
||||
}
|
||||
|
||||
protected function getIV4d() : ByteArray
|
||||
{
|
||||
var vec:ByteArray = new ByteArray();
|
||||
if(Boolean(this.iv))
|
||||
{
|
||||
vec.writeBytes(this.iv);
|
||||
return vec;
|
||||
}
|
||||
throw new Error("an IV must be set before calling decrypt()");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class NullPad implements IPad
|
||||
{
|
||||
|
||||
public function NullPad()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function unpad(a:ByteArray) : void
|
||||
{
|
||||
}
|
||||
|
||||
public function pad(a:ByteArray) : void
|
||||
{
|
||||
}
|
||||
|
||||
public function setBlockSize(bs:uint) : void
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class OFBMode extends IVMode implements IMode
|
||||
{
|
||||
|
||||
public function OFBMode(key:ISymmetricKey, padding:IPad = null)
|
||||
{
|
||||
super(key,null);
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray) : void
|
||||
{
|
||||
var vector:ByteArray = getIV4e();
|
||||
this.core(src,vector);
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray) : void
|
||||
{
|
||||
var vector:ByteArray = getIV4d();
|
||||
this.core(src,vector);
|
||||
}
|
||||
|
||||
private function core(src:ByteArray, iv:ByteArray) : void
|
||||
{
|
||||
var chunk:uint = 0;
|
||||
var j:uint = 0;
|
||||
var l:uint = src.length;
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
for(var i:uint = 0; i < src.length; i += blockSize)
|
||||
{
|
||||
key.encrypt(iv);
|
||||
tmp.position = 0;
|
||||
tmp.writeBytes(iv);
|
||||
chunk = i + blockSize < l ? blockSize : uint(l - i);
|
||||
for(j = 0; j < chunk; j++)
|
||||
{
|
||||
src[i + j] ^= iv[j];
|
||||
}
|
||||
iv.position = 0;
|
||||
iv.writeBytes(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return key.toString() + "-ofb";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class PKCS5 implements IPad
|
||||
{
|
||||
|
||||
private var blockSize:uint;
|
||||
|
||||
public function PKCS5(blockSize:uint = 0)
|
||||
{
|
||||
super();
|
||||
this.blockSize = blockSize;
|
||||
}
|
||||
|
||||
public function pad(a:ByteArray) : void
|
||||
{
|
||||
var c:uint = this.blockSize - a.length % this.blockSize;
|
||||
for(var i:uint = 0; i < c; i++)
|
||||
{
|
||||
a[a.length] = c;
|
||||
}
|
||||
}
|
||||
|
||||
public function unpad(a:ByteArray) : void
|
||||
{
|
||||
var v:uint = 0;
|
||||
var c:uint = a.length % this.blockSize;
|
||||
if(c != 0)
|
||||
{
|
||||
throw new Error("PKCS#5::unpad: ByteArray.length isn\'t a multiple of the blockSize");
|
||||
}
|
||||
c = uint(a[a.length - 1]);
|
||||
for(var i:uint = c; i > 0; i--)
|
||||
{
|
||||
v = uint(a[a.length - 1]);
|
||||
--a.length;
|
||||
if(c != v)
|
||||
{
|
||||
throw new Error("PKCS#5:unpad: Invalid padding value. expected [" + c + "], found [" + v + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function setBlockSize(bs:uint) : void
|
||||
{
|
||||
this.blockSize = bs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class SimpleIVMode implements IMode, ICipher
|
||||
{
|
||||
|
||||
protected var mode:IVMode;
|
||||
|
||||
protected var cipher:ICipher;
|
||||
|
||||
public function SimpleIVMode(mode:IVMode)
|
||||
{
|
||||
super();
|
||||
this.mode = mode;
|
||||
this.cipher = mode as ICipher;
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return this.mode.getBlockSize();
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
this.mode.dispose();
|
||||
this.mode = null;
|
||||
this.cipher = null;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function encrypt(src:ByteArray) : void
|
||||
{
|
||||
this.cipher.encrypt(src);
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
tmp.writeBytes(this.mode.IV);
|
||||
tmp.writeBytes(src);
|
||||
src.position = 0;
|
||||
src.writeBytes(tmp);
|
||||
}
|
||||
|
||||
public function decrypt(src:ByteArray) : void
|
||||
{
|
||||
var tmp:ByteArray = new ByteArray();
|
||||
tmp.writeBytes(src,0,this.getBlockSize());
|
||||
this.mode.IV = tmp;
|
||||
tmp = new ByteArray();
|
||||
tmp.writeBytes(src,this.getBlockSize());
|
||||
this.cipher.decrypt(tmp);
|
||||
src.length = 0;
|
||||
src.writeBytes(tmp);
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "simple-" + this.cipher.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class TripleDESKey extends DESKey
|
||||
{
|
||||
|
||||
protected var encKey2:Array;
|
||||
|
||||
protected var encKey3:Array;
|
||||
|
||||
protected var decKey2:Array;
|
||||
|
||||
protected var decKey3:Array;
|
||||
|
||||
public function TripleDESKey(key:ByteArray)
|
||||
{
|
||||
super(key);
|
||||
this.encKey2 = generateWorkingKey(false,key,8);
|
||||
this.decKey2 = generateWorkingKey(true,key,8);
|
||||
if(key.length > 16)
|
||||
{
|
||||
this.encKey3 = generateWorkingKey(true,key,16);
|
||||
this.decKey3 = generateWorkingKey(false,key,16);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.encKey3 = encKey;
|
||||
this.decKey3 = decKey;
|
||||
}
|
||||
}
|
||||
|
||||
override public function dispose() : void
|
||||
{
|
||||
super.dispose();
|
||||
var i:uint = 0;
|
||||
if(this.encKey2 != null)
|
||||
{
|
||||
i = 0;
|
||||
while(i < this.encKey2.length)
|
||||
{
|
||||
this.encKey2[i] = 0;
|
||||
i++;
|
||||
}
|
||||
this.encKey2 = null;
|
||||
}
|
||||
if(this.encKey3 != null)
|
||||
{
|
||||
i = 0;
|
||||
while(i < this.encKey3.length)
|
||||
{
|
||||
this.encKey3[i] = 0;
|
||||
i++;
|
||||
}
|
||||
this.encKey3 = null;
|
||||
}
|
||||
if(this.decKey2 != null)
|
||||
{
|
||||
i = 0;
|
||||
while(i < this.decKey2.length)
|
||||
{
|
||||
this.decKey2[i] = 0;
|
||||
i++;
|
||||
}
|
||||
this.decKey2 = null;
|
||||
}
|
||||
if(this.decKey3 != null)
|
||||
{
|
||||
i = 0;
|
||||
while(i < this.decKey3.length)
|
||||
{
|
||||
this.decKey3[i] = 0;
|
||||
i++;
|
||||
}
|
||||
this.decKey3 = null;
|
||||
}
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
override public function encrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
desFunc(encKey,block,index,block,index);
|
||||
desFunc(this.encKey2,block,index,block,index);
|
||||
desFunc(this.encKey3,block,index,block,index);
|
||||
}
|
||||
|
||||
override public function decrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
desFunc(this.decKey3,block,index,block,index);
|
||||
desFunc(this.decKey2,block,index,block,index);
|
||||
desFunc(decKey,block,index,block,index);
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "3des";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.hurlant.crypto.symmetric
|
||||
{
|
||||
import com.hurlant.crypto.prng.Random;
|
||||
import com.hurlant.util.Memory;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class XTeaKey implements ISymmetricKey
|
||||
{
|
||||
|
||||
public const NUM_ROUNDS:uint = 64;
|
||||
|
||||
private var k:Array;
|
||||
|
||||
public function XTeaKey(a:ByteArray)
|
||||
{
|
||||
super();
|
||||
a.position = 0;
|
||||
this.k = [a.readUnsignedInt(),a.readUnsignedInt(),a.readUnsignedInt(),a.readUnsignedInt()];
|
||||
}
|
||||
|
||||
public static function parseKey(K:String) : XTeaKey
|
||||
{
|
||||
var a:ByteArray = new ByteArray();
|
||||
a.writeUnsignedInt(parseInt(K.substr(0,8),16));
|
||||
a.writeUnsignedInt(parseInt(K.substr(8,8),16));
|
||||
a.writeUnsignedInt(parseInt(K.substr(16,8),16));
|
||||
a.writeUnsignedInt(parseInt(K.substr(24,8),16));
|
||||
a.position = 0;
|
||||
return new XTeaKey(a);
|
||||
}
|
||||
|
||||
public function getBlockSize() : uint
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
public function encrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
block.position = index;
|
||||
var v0:uint = block.readUnsignedInt();
|
||||
var v1:uint = block.readUnsignedInt();
|
||||
var sum:uint = 0;
|
||||
var delta:uint = 2654435769;
|
||||
for(i = 0; i < this.NUM_ROUNDS; i++)
|
||||
{
|
||||
v0 += (v1 << 4 ^ v1 >> 5) + v1 ^ sum + this.k[sum & 3];
|
||||
sum += delta;
|
||||
v1 += (v0 << 4 ^ v0 >> 5) + v0 ^ sum + this.k[sum >> 11 & 3];
|
||||
}
|
||||
block.position -= 8;
|
||||
block.writeUnsignedInt(v0);
|
||||
block.writeUnsignedInt(v1);
|
||||
}
|
||||
|
||||
public function decrypt(block:ByteArray, index:uint = 0) : void
|
||||
{
|
||||
var i:uint = 0;
|
||||
block.position = index;
|
||||
var v0:uint = block.readUnsignedInt();
|
||||
var v1:uint = block.readUnsignedInt();
|
||||
var delta:uint = 2654435769;
|
||||
var sum:uint = delta * this.NUM_ROUNDS;
|
||||
for(i = 0; i < this.NUM_ROUNDS; i++)
|
||||
{
|
||||
v1 -= (v0 << 4 ^ v0 >> 5) + v0 ^ sum + this.k[sum >> 11 & 3];
|
||||
sum -= delta;
|
||||
v0 -= (v1 << 4 ^ v1 >> 5) + v1 ^ sum + this.k[sum & 3];
|
||||
}
|
||||
block.position -= 8;
|
||||
block.writeUnsignedInt(v0);
|
||||
block.writeUnsignedInt(v1);
|
||||
}
|
||||
|
||||
public function dispose() : void
|
||||
{
|
||||
var r:Random = new Random();
|
||||
for(var i:uint = 0; i < this.k.length; i++)
|
||||
{
|
||||
this.k[i] = r.nextByte();
|
||||
delete this.k[i];
|
||||
}
|
||||
this.k = null;
|
||||
Memory.gc();
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "xtea";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.hurlant.math
|
||||
{
|
||||
use namespace bi_internal;
|
||||
|
||||
internal class BarrettReduction implements IReduction
|
||||
{
|
||||
|
||||
private var m:BigInteger;
|
||||
|
||||
private var r2:BigInteger;
|
||||
|
||||
private var q3:BigInteger;
|
||||
|
||||
private var mu:BigInteger;
|
||||
|
||||
public function BarrettReduction(m:BigInteger)
|
||||
{
|
||||
super();
|
||||
this.r2 = new BigInteger();
|
||||
this.q3 = new BigInteger();
|
||||
BigInteger.ONE.dlShiftTo(2 * m.t,this.r2);
|
||||
this.mu = this.r2.divide(m);
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public function revert(x:BigInteger) : BigInteger
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.multiplyTo(y,r);
|
||||
this.reduce(r);
|
||||
}
|
||||
|
||||
public function sqrTo(x:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.squareTo(r);
|
||||
this.reduce(r);
|
||||
}
|
||||
|
||||
public function convert(x:BigInteger) : BigInteger
|
||||
{
|
||||
var r:BigInteger = null;
|
||||
if(x.s < 0 || x.t > 2 * this.m.t)
|
||||
{
|
||||
return x.mod(this.m);
|
||||
}
|
||||
if(x.compareTo(this.m) < 0)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
r = new BigInteger();
|
||||
x.copyTo(r);
|
||||
this.reduce(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public function reduce(lx:BigInteger) : void
|
||||
{
|
||||
var x:BigInteger = lx as BigInteger;
|
||||
x.drShiftTo(this.m.t - 1,this.r2);
|
||||
if(x.t > this.m.t + 1)
|
||||
{
|
||||
x.t = this.m.t + 1;
|
||||
x.clamp();
|
||||
}
|
||||
this.mu.multiplyUpperTo(this.r2,this.m.t + 1,this.q3);
|
||||
this.m.multiplyLowerTo(this.q3,this.m.t + 1,this.r2);
|
||||
while(x.compareTo(this.r2) < 0)
|
||||
{
|
||||
x.dAddOffset(1,this.m.t + 1);
|
||||
}
|
||||
x.subTo(this.r2,x);
|
||||
while(x.compareTo(this.m) >= 0)
|
||||
{
|
||||
x.subTo(this.m,x);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,48 @@
|
||||
package com.hurlant.math
|
||||
{
|
||||
use namespace bi_internal;
|
||||
|
||||
internal class ClassicReduction implements IReduction
|
||||
{
|
||||
|
||||
private var m:BigInteger;
|
||||
|
||||
public function ClassicReduction(m:BigInteger)
|
||||
{
|
||||
super();
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public function convert(x:BigInteger) : BigInteger
|
||||
{
|
||||
if(x.s < 0 || x.compareTo(this.m) >= 0)
|
||||
{
|
||||
return x.mod(this.m);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public function revert(x:BigInteger) : BigInteger
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
public function reduce(x:BigInteger) : void
|
||||
{
|
||||
x.divRemTo(this.m,null,x);
|
||||
}
|
||||
|
||||
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.multiplyTo(y,r);
|
||||
this.reduce(r);
|
||||
}
|
||||
|
||||
public function sqrTo(x:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.squareTo(r);
|
||||
this.reduce(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.hurlant.math
|
||||
{
|
||||
internal interface IReduction
|
||||
{
|
||||
|
||||
function convert(param1:BigInteger) : BigInteger;
|
||||
|
||||
function revert(param1:BigInteger) : BigInteger;
|
||||
|
||||
function reduce(param1:BigInteger) : void;
|
||||
|
||||
function mulTo(param1:BigInteger, param2:BigInteger, param3:BigInteger) : void;
|
||||
|
||||
function sqrTo(param1:BigInteger, param2:BigInteger) : void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.hurlant.math
|
||||
{
|
||||
use namespace bi_internal;
|
||||
|
||||
internal class MontgomeryReduction implements IReduction
|
||||
{
|
||||
|
||||
private var m:BigInteger;
|
||||
|
||||
private var mp:int;
|
||||
|
||||
private var mpl:int;
|
||||
|
||||
private var mph:int;
|
||||
|
||||
private var um:int;
|
||||
|
||||
private var mt2:int;
|
||||
|
||||
public function MontgomeryReduction(m:BigInteger)
|
||||
{
|
||||
super();
|
||||
this.m = m;
|
||||
this.mp = m.invDigit();
|
||||
this.mpl = this.mp & 0x7FFF;
|
||||
this.mph = this.mp >> 15;
|
||||
this.um = (1 << BigInteger.DB - 15) - 1;
|
||||
this.mt2 = 2 * m.t;
|
||||
}
|
||||
|
||||
public function convert(x:BigInteger) : BigInteger
|
||||
{
|
||||
var r:BigInteger = new BigInteger();
|
||||
x.abs().dlShiftTo(this.m.t,r);
|
||||
r.divRemTo(this.m,null,r);
|
||||
if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0)
|
||||
{
|
||||
this.m.subTo(r,r);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public function revert(x:BigInteger) : BigInteger
|
||||
{
|
||||
var r:BigInteger = new BigInteger();
|
||||
x.copyTo(r);
|
||||
this.reduce(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public function reduce(x:BigInteger) : void
|
||||
{
|
||||
var j:int = 0;
|
||||
var u0:int = 0;
|
||||
while(x.t <= this.mt2)
|
||||
{
|
||||
x.a[x.t++] = 0;
|
||||
}
|
||||
for(var i:int = 0; i < this.m.t; i++)
|
||||
{
|
||||
j = x.a[i] & 0x7FFF;
|
||||
u0 = j * this.mpl + ((j * this.mph + (x.a[i] >> 15) * this.mpl & this.um) << 15) & BigInteger.DM;
|
||||
j = i + this.m.t;
|
||||
x.a[j] += this.m.am(0,u0,x,i,0,this.m.t);
|
||||
while(x.a[j] >= BigInteger.DV)
|
||||
{
|
||||
x.a[j] -= BigInteger.DV;
|
||||
++x.a[++j];
|
||||
}
|
||||
}
|
||||
x.clamp();
|
||||
x.drShiftTo(this.m.t,x);
|
||||
if(x.compareTo(this.m) >= 0)
|
||||
{
|
||||
x.subTo(this.m,x);
|
||||
}
|
||||
}
|
||||
|
||||
public function sqrTo(x:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.squareTo(r);
|
||||
this.reduce(r);
|
||||
}
|
||||
|
||||
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.multiplyTo(y,r);
|
||||
this.reduce(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.hurlant.math
|
||||
{
|
||||
use namespace bi_internal;
|
||||
|
||||
public class NullReduction implements IReduction
|
||||
{
|
||||
|
||||
public function NullReduction()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function revert(x:BigInteger) : BigInteger
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.multiplyTo(y,r);
|
||||
}
|
||||
|
||||
public function sqrTo(x:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.squareTo(r);
|
||||
}
|
||||
|
||||
public function convert(x:BigInteger) : BigInteger
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
public function reduce(x:BigInteger) : void
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.hurlant.math
|
||||
{
|
||||
public namespace bi_internal = "http://crypto.hurlant.com/BigInteger";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.hurlant.util
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class Base64
|
||||
{
|
||||
|
||||
private static const BASE64_CHARS:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
|
||||
public static const version:String = "1.0.0";
|
||||
|
||||
public function Base64()
|
||||
{
|
||||
super();
|
||||
throw new Error("Base64 class is static container only");
|
||||
}
|
||||
|
||||
public static function encode(data:String) : String
|
||||
{
|
||||
var bytes:ByteArray = new ByteArray();
|
||||
bytes.writeUTFBytes(data);
|
||||
return encodeByteArray(bytes);
|
||||
}
|
||||
|
||||
public static function encodeByteArray(data:ByteArray) : String
|
||||
{
|
||||
var dataBuffer:Array = null;
|
||||
var i:uint = 0;
|
||||
var j:uint = 0;
|
||||
var k:uint = 0;
|
||||
var output:String = "";
|
||||
var outputBuffer:Array = new Array(4);
|
||||
data.position = 0;
|
||||
while(data.bytesAvailable > 0)
|
||||
{
|
||||
dataBuffer = new Array();
|
||||
i = 0;
|
||||
while(i < 3 && data.bytesAvailable > 0)
|
||||
{
|
||||
dataBuffer[i] = data.readUnsignedByte();
|
||||
i++;
|
||||
}
|
||||
outputBuffer[0] = (dataBuffer[0] & 0xFC) >> 2;
|
||||
outputBuffer[1] = (dataBuffer[0] & 3) << 4 | dataBuffer[1] >> 4;
|
||||
outputBuffer[2] = (dataBuffer[1] & 0x0F) << 2 | dataBuffer[2] >> 6;
|
||||
outputBuffer[3] = dataBuffer[2] & 0x3F;
|
||||
for(j = dataBuffer.length; j < 3; j++)
|
||||
{
|
||||
outputBuffer[j + 1] = 64;
|
||||
}
|
||||
for(k = 0; k < outputBuffer.length; k++)
|
||||
{
|
||||
output += BASE64_CHARS.charAt(outputBuffer[k]);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public static function decode(data:String) : String
|
||||
{
|
||||
var bytes:ByteArray = decodeToByteArray(data);
|
||||
return bytes.readUTFBytes(bytes.length);
|
||||
}
|
||||
|
||||
public static function decodeToByteArray(data:String) : ByteArray
|
||||
{
|
||||
var j:uint = 0;
|
||||
var k:uint = 0;
|
||||
var output:ByteArray = new ByteArray();
|
||||
var dataBuffer:Array = new Array(4);
|
||||
var outputBuffer:Array = new Array(3);
|
||||
for(var i:uint = 0; i < data.length; i += 4)
|
||||
{
|
||||
j = 0;
|
||||
while(j < 4 && i + j < data.length)
|
||||
{
|
||||
dataBuffer[j] = BASE64_CHARS.indexOf(data.charAt(i + j));
|
||||
j++;
|
||||
}
|
||||
outputBuffer[0] = (dataBuffer[0] << 2) + ((dataBuffer[1] & 0x30) >> 4);
|
||||
outputBuffer[1] = ((dataBuffer[1] & 0x0F) << 4) + ((dataBuffer[2] & 0x3C) >> 2);
|
||||
outputBuffer[2] = ((dataBuffer[2] & 3) << 6) + dataBuffer[3];
|
||||
for(k = 0; k < outputBuffer.length; k++)
|
||||
{
|
||||
if(dataBuffer[k + 1] == 64)
|
||||
{
|
||||
break;
|
||||
}
|
||||
output.writeByte(outputBuffer[k]);
|
||||
}
|
||||
}
|
||||
output.position = 0;
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.hurlant.util
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class Hex
|
||||
{
|
||||
|
||||
public function Hex()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function toArray(hex:String) : ByteArray
|
||||
{
|
||||
hex = hex.replace(/\s|:/gm,"");
|
||||
var a:ByteArray = new ByteArray();
|
||||
if(Boolean(hex.length & 1 == 1))
|
||||
{
|
||||
hex = "0" + hex;
|
||||
}
|
||||
for(var i:uint = 0; i < hex.length; i += 2)
|
||||
{
|
||||
a[i / 2] = parseInt(hex.substr(i,2),16);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
public static function fromArray(array:ByteArray, colons:Boolean = false) : String
|
||||
{
|
||||
var s:String = "";
|
||||
for(var i:uint = 0; i < array.length; i++)
|
||||
{
|
||||
s += ("0" + array[i].toString(16)).substr(-2,2);
|
||||
if(colons)
|
||||
{
|
||||
if(i < array.length - 1)
|
||||
{
|
||||
s += ":";
|
||||
}
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static function toString(hex:String) : String
|
||||
{
|
||||
var a:ByteArray = toArray(hex);
|
||||
return a.readUTFBytes(a.length);
|
||||
}
|
||||
|
||||
public static function fromString(str:String, colons:Boolean = false) : String
|
||||
{
|
||||
var a:ByteArray = new ByteArray();
|
||||
a.writeUTFBytes(str);
|
||||
return fromArray(a,colons);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.hurlant.util
|
||||
{
|
||||
import flash.net.LocalConnection;
|
||||
import flash.system.System;
|
||||
|
||||
public class Memory
|
||||
{
|
||||
|
||||
public function Memory()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function gc() : void
|
||||
{
|
||||
try
|
||||
{
|
||||
new LocalConnection().connect("foo");
|
||||
new LocalConnection().connect("foo");
|
||||
}
|
||||
catch(e:*)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static function get used() : uint
|
||||
{
|
||||
return System.totalMemory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,469 @@
|
||||
package com.sbi.analytics
|
||||
{
|
||||
import com.carlcalderon.arthropod.Debug;
|
||||
import flash.events.DataEvent;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
import flash.events.TimerEvent;
|
||||
import flash.external.ExternalInterface;
|
||||
import flash.net.Socket;
|
||||
import flash.utils.Dictionary;
|
||||
import flash.utils.Timer;
|
||||
|
||||
public class SBTracker
|
||||
{
|
||||
|
||||
private static var _pageStack:Array;
|
||||
|
||||
private static var _batchTimer:Timer;
|
||||
|
||||
private static var _isExternalAvailable:Boolean;
|
||||
|
||||
private static var _couldNotConnect:Boolean;
|
||||
|
||||
private static var _pageView:String;
|
||||
|
||||
private static var _socket:Socket;
|
||||
|
||||
private static var _timeOffset:Number;
|
||||
|
||||
private static var _isFromLogin:Boolean;
|
||||
|
||||
private static var _retryLimit:int;
|
||||
|
||||
private static var _lastBatchCallback:Function;
|
||||
|
||||
private static var _trackingObjects:Dictionary;
|
||||
|
||||
private static var _latestTrackTimeStamp:Dictionary;
|
||||
|
||||
private static var _lastestDuration:Dictionary;
|
||||
|
||||
public static const TYPE_NORMAL:int = 0;
|
||||
|
||||
public static const TYPE_EVENT:int = 1;
|
||||
|
||||
public static const TYPE_ERROR:int = 2;
|
||||
|
||||
private static var MAX_RETRIES:int = 3;
|
||||
|
||||
public function SBTracker()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function create() : void
|
||||
{
|
||||
if(ExternalInterface.available && gMainFrame.clientInfo.sbTrackerIp != -1)
|
||||
{
|
||||
_isExternalAvailable = true;
|
||||
ExternalInterface.addCallback("receiveClose",receiveClose);
|
||||
if(!isNaN(gMainFrame.clientInfo.currentTimestamp))
|
||||
{
|
||||
_timeOffset = gMainFrame.clientInfo.currentTimestamp - new Date().valueOf() / 1000;
|
||||
}
|
||||
else
|
||||
{
|
||||
_timeOffset = 0;
|
||||
}
|
||||
_pageView = null;
|
||||
_pageStack = [];
|
||||
_socket = new Socket();
|
||||
_socket.addEventListener(Event.CLOSE,closeHandler);
|
||||
_socket.addEventListener(Event.CONNECT,connectHandler);
|
||||
_socket.addEventListener(DataEvent.DATA,dataHandler);
|
||||
_socket.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
|
||||
_socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler);
|
||||
_trackingObjects = new Dictionary();
|
||||
_trackingObjects[TYPE_NORMAL] = [];
|
||||
_trackingObjects[TYPE_EVENT] = [];
|
||||
_trackingObjects[TYPE_ERROR] = [];
|
||||
_latestTrackTimeStamp = new Dictionary();
|
||||
_latestTrackTimeStamp[TYPE_NORMAL] = 0;
|
||||
_lastestDuration = new Dictionary();
|
||||
_lastestDuration[TYPE_NORMAL] = 0;
|
||||
_batchTimer = new Timer(10000);
|
||||
_batchTimer.addEventListener(TimerEvent.TIMER,onBatchTimer,false,0,true);
|
||||
_batchTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
public static function receiveClose() : String
|
||||
{
|
||||
_batchTimer.stop();
|
||||
_batchTimer.removeEventListener(TimerEvent.TIMER,onBatchTimer);
|
||||
if(_pageView != null)
|
||||
{
|
||||
setupPageView();
|
||||
return _pageView;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function onError() : void
|
||||
{
|
||||
if(_isExternalAvailable)
|
||||
{
|
||||
ExternalInterface.call("reportAnalyticsError","Error Timeout",gMainFrame.clientInfo.sessionId);
|
||||
}
|
||||
Debug.log("Sending analytics error",Debug.RED);
|
||||
}
|
||||
|
||||
public static function trackPageview(pageURI:String, loginSessionId:int = -1, type:int = 0, throttled:Boolean = true) : void
|
||||
{
|
||||
var userId:int = 0;
|
||||
var currTime:Number = NaN;
|
||||
if(_isExternalAvailable && !_couldNotConnect)
|
||||
{
|
||||
_isFromLogin = loginSessionId != -1;
|
||||
if(_isFromLogin)
|
||||
{
|
||||
userId = 0;
|
||||
}
|
||||
else if(gMainFrame.clientInfo.dbUserId == undefined)
|
||||
{
|
||||
userId = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
userId = int(gMainFrame.clientInfo.dbUserId);
|
||||
}
|
||||
if(userId > 0)
|
||||
{
|
||||
if(throttled && userId % gMainFrame.clientInfo.sbTrackerModulator != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
currTime = Math.floor(new Date().valueOf() / 1000 + _timeOffset);
|
||||
if(gMainFrame.clientInfo.sessionId == undefined && _isFromLogin)
|
||||
{
|
||||
gMainFrame.clientInfo.sessionId = Math.floor(Math.random() * (int.MAX_VALUE + 1));
|
||||
}
|
||||
_trackingObjects[type].push(new URIObj(pageURI,currTime,_isFromLogin,type,_trackingObjects[type].length,throttled));
|
||||
}
|
||||
}
|
||||
|
||||
public static function handleErrorTracking(userId:int, time:int, order:int, duration:int, sessionId:Number, uri:String, uriParam:String, pop:int, value:int) : void
|
||||
{
|
||||
var tempSessionId:Number = Number(gMainFrame.clientInfo.sessionId);
|
||||
if(gMainFrame.clientInfo.sessionId == undefined)
|
||||
{
|
||||
tempSessionId = Math.round(Math.random() * (int.MAX_VALUE + 1));
|
||||
}
|
||||
if(gMainFrame.clientInfo.dbUserId == undefined)
|
||||
{
|
||||
gMainFrame.clientInfo.dbUserId = userId;
|
||||
}
|
||||
var customFields:Object = {
|
||||
"userId":(gMainFrame.clientInfo.dbUserId == undefined ? userId : null),
|
||||
"order":order,
|
||||
"duration":(duration == -1 ? null : duration),
|
||||
"sessionId":(sessionId == -1 ? tempSessionId : null)
|
||||
};
|
||||
_trackingObjects[TYPE_ERROR].push(new URIObj(uri + "#" + uriParam + "#" + pop + "#" + value,time == -1 ? Math.floor(new Date().valueOf() / 1000 + _timeOffset) : time,_isFromLogin,TYPE_ERROR,_trackingObjects[TYPE_ERROR].length,false,customFields));
|
||||
onBatchTimer(null);
|
||||
}
|
||||
|
||||
public static function handleOnKickOrLogout() : void
|
||||
{
|
||||
if(_isExternalAvailable && _pageView != null)
|
||||
{
|
||||
ExternalInterface.call("handleLogout",_pageView);
|
||||
}
|
||||
}
|
||||
|
||||
public static function push(type:int = 0) : void
|
||||
{
|
||||
var currTrackingObjects:Array = null;
|
||||
var trackingObject:Object = null;
|
||||
if(Boolean(_pageStack))
|
||||
{
|
||||
currTrackingObjects = _trackingObjects[type];
|
||||
if(currTrackingObjects.length > 0)
|
||||
{
|
||||
trackingObject = currTrackingObjects[currTrackingObjects.length - 1].trackingObject;
|
||||
_pageStack.push(trackingObject.uri + "#" + trackingObject.uriParams + "#pop#" + trackingObject.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function pop() : void
|
||||
{
|
||||
if(Boolean(_pageStack) && Boolean(_pageStack.length))
|
||||
{
|
||||
trackPageview(_pageStack.pop());
|
||||
}
|
||||
}
|
||||
|
||||
public static function flush(bPopFirst:Boolean = false) : void
|
||||
{
|
||||
if(Boolean(_pageStack) && Boolean(_pageStack.length))
|
||||
{
|
||||
if(bPopFirst)
|
||||
{
|
||||
trackPageview(_pageStack[0]);
|
||||
}
|
||||
_pageStack = [];
|
||||
}
|
||||
}
|
||||
|
||||
public static function completeLastTrackingBatch(callback:Function) : void
|
||||
{
|
||||
_lastBatchCallback = callback;
|
||||
if(Boolean(_batchTimer))
|
||||
{
|
||||
_batchTimer.stop();
|
||||
if(Boolean(_socket))
|
||||
{
|
||||
setupPageView(true);
|
||||
if(_pageView != null)
|
||||
{
|
||||
_batchTimer.reset();
|
||||
_socket.connect(gMainFrame.clientInfo.sbTrackerIp,5050);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(_lastBatchCallback != null)
|
||||
{
|
||||
_lastBatchCallback();
|
||||
_lastBatchCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getLastDuration(type:int) : Number
|
||||
{
|
||||
return _lastestDuration[type];
|
||||
}
|
||||
|
||||
public static function setLastDuration(type:int, duration:Number) : void
|
||||
{
|
||||
_lastestDuration[type] = duration;
|
||||
}
|
||||
|
||||
public static function getLastTimestamp(type:int) : Number
|
||||
{
|
||||
return _latestTrackTimeStamp[type];
|
||||
}
|
||||
|
||||
public static function setLastTimestamp(type:int, timeStamp:Number) : void
|
||||
{
|
||||
_latestTrackTimeStamp[type] = timeStamp;
|
||||
}
|
||||
|
||||
public static function getnextURIObjByType(index:int, type:int) : URIObj
|
||||
{
|
||||
var trackingArray:Array = _trackingObjects[type];
|
||||
if(trackingArray.length > 0 && trackingArray.length > index + 1)
|
||||
{
|
||||
return trackingArray[index + 1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getPreviousURIObjByType(index:int, type:int) : URIObj
|
||||
{
|
||||
var trackingArray:Array = _trackingObjects[type];
|
||||
if(trackingArray.length > 0 && trackingArray.length > index - 1)
|
||||
{
|
||||
return trackingArray[index - 1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static function findLatestTrackedURIObjByThrottleType(trackingObjects:Array, throttle:Boolean) : URIObj
|
||||
{
|
||||
var i:int = 0;
|
||||
if(Boolean(trackingObjects))
|
||||
{
|
||||
for(i = trackingObjects.length - 1; i >= 0; i--)
|
||||
{
|
||||
if(trackingObjects[i].throttled == throttle)
|
||||
{
|
||||
return trackingObjects[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static function onBatchTimer(t:TimerEvent) : void
|
||||
{
|
||||
if(Boolean(_socket))
|
||||
{
|
||||
setupPageView();
|
||||
if(_pageView != null)
|
||||
{
|
||||
_batchTimer.reset();
|
||||
_socket.connect(gMainFrame.clientInfo.sbTrackerIp,5050);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(_lastBatchCallback != null)
|
||||
{
|
||||
_lastBatchCallback();
|
||||
_lastBatchCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function setupPageView(updateLastItem:Boolean = false) : void
|
||||
{
|
||||
var myTrackString:String = null;
|
||||
var trackType:int = 0;
|
||||
var currUri:URIObj = null;
|
||||
var i:int = 0;
|
||||
var type:String = null;
|
||||
var currUriObjects:Array = null;
|
||||
var track:Boolean = false;
|
||||
if(_pageView == null)
|
||||
{
|
||||
myTrackString = "";
|
||||
for(type in _trackingObjects)
|
||||
{
|
||||
trackType = int(type);
|
||||
currUriObjects = _trackingObjects[trackType];
|
||||
if(currUriObjects.length > 0)
|
||||
{
|
||||
if(gMainFrame.clientInfo.sessionId != undefined)
|
||||
{
|
||||
for(i = 0; i < currUriObjects.length; i++)
|
||||
{
|
||||
currUri = currUriObjects[i];
|
||||
if(currUri.throttled)
|
||||
{
|
||||
if(!currUri.isFromLogin)
|
||||
{
|
||||
if(gMainFrame.clientInfo.dbUserId % gMainFrame.clientInfo.sbTrackerModulator != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if(gMainFrame.clientInfo.sessionId % gMainFrame.clientInfo.sbTrackerModulator != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
myTrackString += currUri.pageView;
|
||||
}
|
||||
if(updateLastItem)
|
||||
{
|
||||
if(currUri.throttled)
|
||||
{
|
||||
if(!currUri.isFromLogin)
|
||||
{
|
||||
if(gMainFrame.clientInfo.dbUserId % gMainFrame.clientInfo.sbTrackerModulator != 0)
|
||||
{
|
||||
track = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
track = true;
|
||||
}
|
||||
}
|
||||
else if(gMainFrame.clientInfo.sessionId % gMainFrame.clientInfo.sbTrackerModulator != 0)
|
||||
{
|
||||
track = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
track = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
track = true;
|
||||
}
|
||||
if(track)
|
||||
{
|
||||
myTrackString += currUri.ownPageView;
|
||||
}
|
||||
_trackingObjects[trackType] = [];
|
||||
currUriObjects = [];
|
||||
}
|
||||
else
|
||||
{
|
||||
_trackingObjects[trackType].splice(0,currUriObjects.length - 1);
|
||||
currUriObjects.splice(0,currUriObjects.length - 1);
|
||||
currUri.index = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(myTrackString != "")
|
||||
{
|
||||
_pageView = myTrackString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function closeHandler(event:Event) : void
|
||||
{
|
||||
_socket.close();
|
||||
}
|
||||
|
||||
private static function connectHandler(event:Event) : void
|
||||
{
|
||||
Debug.log(_pageView,Debug.YELLOW);
|
||||
_socket.writeUTFBytes(_pageView);
|
||||
_pageView = null;
|
||||
_socket.flush();
|
||||
_socket.close();
|
||||
_retryLimit = 0;
|
||||
_batchTimer.start();
|
||||
if(_lastBatchCallback != null)
|
||||
{
|
||||
_lastBatchCallback();
|
||||
_lastBatchCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function dataHandler(event:DataEvent) : void
|
||||
{
|
||||
}
|
||||
|
||||
private static function ioErrorHandler(event:IOErrorEvent) : void
|
||||
{
|
||||
if(_lastBatchCallback != null)
|
||||
{
|
||||
_lastBatchCallback();
|
||||
_lastBatchCallback = null;
|
||||
}
|
||||
if(_retryLimit < MAX_RETRIES)
|
||||
{
|
||||
++_retryLimit;
|
||||
Debug.log("IO error - retrying analytics connection",Debug.RED);
|
||||
_socket.connect(gMainFrame.clientInfo.sbTrackerIp,5050);
|
||||
return;
|
||||
}
|
||||
_couldNotConnect = true;
|
||||
}
|
||||
|
||||
private static function securityErrorHandler(event:SecurityErrorEvent) : void
|
||||
{
|
||||
if(_lastBatchCallback != null)
|
||||
{
|
||||
_lastBatchCallback();
|
||||
_lastBatchCallback = null;
|
||||
}
|
||||
if(_retryLimit < MAX_RETRIES)
|
||||
{
|
||||
Debug.log("Security error - retrying analytics connection",Debug.RED);
|
||||
++_retryLimit;
|
||||
_socket.connect(gMainFrame.clientInfo.sbTrackerIp,5050);
|
||||
return;
|
||||
}
|
||||
if(Boolean(_batchTimer))
|
||||
{
|
||||
_batchTimer.stop();
|
||||
_batchTimer.removeEventListener(TimerEvent.TIMER,onBatchTimer);
|
||||
}
|
||||
_couldNotConnect = true;
|
||||
_pageView = null;
|
||||
_socket = null;
|
||||
onError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
package com.sbi.analytics
|
||||
{
|
||||
import com.carlcalderon.arthropod.Debug;
|
||||
import flash.utils.getTimer;
|
||||
|
||||
public class URIObj
|
||||
{
|
||||
|
||||
private var _type:int;
|
||||
|
||||
private var _trackingObject:Object;
|
||||
|
||||
private var _containsAnUndefined:Boolean;
|
||||
|
||||
private var _pageView:String;
|
||||
|
||||
private var _userId:int;
|
||||
|
||||
private var _isFromLogin:Boolean;
|
||||
|
||||
private var _throttled:Boolean;
|
||||
|
||||
private var _index:int;
|
||||
|
||||
public function URIObj(uri:String, currTime:Number, isFromLogin:Boolean, type:int, index:int, throttled:Boolean, customFields:Object = null)
|
||||
{
|
||||
var sessionId:int = 0;
|
||||
var previousURIObj:URIObj = null;
|
||||
super();
|
||||
uri = uri.replace(/[',]/g,"");
|
||||
var pageStrings:Array = uri.split(/#/i);
|
||||
this._isFromLogin = isFromLogin;
|
||||
this._throttled = throttled;
|
||||
this._type = type;
|
||||
this._index = index;
|
||||
if(Boolean(customFields) && Boolean(customFields.userId))
|
||||
{
|
||||
this._userId = customFields.userId;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._userId = isFromLogin ? 0 : (gMainFrame.clientInfo.dbUserId == undefined ? -1 : int(gMainFrame.clientInfo.dbUserId));
|
||||
}
|
||||
if(Boolean(customFields) && Boolean(customFields.sessionId))
|
||||
{
|
||||
sessionId = int(customFields.sessionId);
|
||||
}
|
||||
else
|
||||
{
|
||||
sessionId = int(gMainFrame.clientInfo.sessionId);
|
||||
}
|
||||
var duration:int = -1;
|
||||
if(Boolean(customFields) && Boolean(customFields.duration))
|
||||
{
|
||||
duration = int(customFields.duration);
|
||||
}
|
||||
else
|
||||
{
|
||||
previousURIObj = SBTracker.getPreviousURIObjByType(index,type);
|
||||
if(Boolean(previousURIObj))
|
||||
{
|
||||
previousURIObj.setTimeAndDurationAndOrder();
|
||||
}
|
||||
}
|
||||
this._trackingObject = {
|
||||
"userId":this._userId,
|
||||
"time":currTime,
|
||||
"order":(Boolean(customFields) && Boolean(customFields.order) ? customFields.order : 0),
|
||||
"duration":duration,
|
||||
"sessionId":sessionId,
|
||||
"uri":pageStrings[0],
|
||||
"uriParams":(pageStrings[1] != null ? pageStrings[1] : ""),
|
||||
"pop":(pageStrings[2] != null && pageStrings[2] == "pop" ? 1 : 0),
|
||||
"value":(pageStrings[3] != null ? pageStrings[3] : ""),
|
||||
"type":type
|
||||
};
|
||||
var debugTrackView:String = "userId: " + this._trackingObject.userId + "\n" + "time: " + this._trackingObject.time + "\n" + "order: " + this._trackingObject.order + "\n" + "duration: " + this._trackingObject.duration + "\n" + "sessionId: " + this._trackingObject.sessionId + "\n" + "URI: " + this._trackingObject.uri + "\n" + "uriParams: " + this._trackingObject.uriParams + "\n" + "pop: " + this._trackingObject.pop + "\n" + "value: " + this._trackingObject.value + "\ntype: " + this._trackingObject.type;
|
||||
Debug.log(debugTrackView,Debug.PINK);
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
this._trackingObject = null;
|
||||
}
|
||||
|
||||
public function get isFromLogin() : Boolean
|
||||
{
|
||||
return this._isFromLogin;
|
||||
}
|
||||
|
||||
public function get trackingObject() : Object
|
||||
{
|
||||
return this._trackingObject;
|
||||
}
|
||||
|
||||
public function get throttled() : Boolean
|
||||
{
|
||||
return this._throttled;
|
||||
}
|
||||
|
||||
public function set index(value:int) : void
|
||||
{
|
||||
this._index = value;
|
||||
}
|
||||
|
||||
public function setTimeAndDurationAndOrder() : void
|
||||
{
|
||||
var previousURIObj:URIObj = null;
|
||||
var lastTimeStamp:Number = SBTracker.getLastTimestamp(this._type);
|
||||
var isTimeTheSame:Boolean = this._trackingObject.time - lastTimeStamp == 0;
|
||||
SBTracker.setLastTimestamp(this._type,this._trackingObject.time);
|
||||
if(isTimeTheSame && this._trackingObject.order == 0)
|
||||
{
|
||||
previousURIObj = SBTracker.getPreviousURIObjByType(this._index,this._type);
|
||||
if(Boolean(previousURIObj))
|
||||
{
|
||||
this._trackingObject.order = previousURIObj.trackingObject.order + 1;
|
||||
}
|
||||
}
|
||||
var lastDuration:Number = SBTracker.getLastDuration(this._type);
|
||||
var currTime:Number = getTimer();
|
||||
SBTracker.setLastDuration(this._type,currTime);
|
||||
if(this._trackingObject.duration == -1)
|
||||
{
|
||||
this._trackingObject.duration = Math.round((currTime - lastDuration) / 100);
|
||||
}
|
||||
}
|
||||
|
||||
public function get pageView() : String
|
||||
{
|
||||
if(this._trackingObject.duration != -1)
|
||||
{
|
||||
return (this._isFromLogin ? this._userId : gMainFrame.clientInfo.dbUserId) + "\n" + this._trackingObject.time + "\n" + this._trackingObject.order + "\n" + this._trackingObject.duration + "\n" + this._trackingObject.sessionId + "\n" + this._trackingObject.uri + "\n" + this._trackingObject.uriParams + "\n" + this._trackingObject.pop + "\n" + this._trackingObject.value + "\n" + this._trackingObject.type + "\n";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public function get ownPageView() : String
|
||||
{
|
||||
this.setTimeAndDurationAndOrder();
|
||||
return this.pageView;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.sbi.client
|
||||
{
|
||||
import com.sbi.popup.SBOkPopup;
|
||||
import flash.display.*;
|
||||
import flash.events.*;
|
||||
import flash.utils.Timer;
|
||||
import localization.LocalizationManager;
|
||||
|
||||
public class KeepAlive
|
||||
{
|
||||
|
||||
public static var popupLayer:DisplayObjectContainer;
|
||||
|
||||
private static var _keepAliveTimer:Timer;
|
||||
|
||||
private static var _timeLeftTimer:Timer;
|
||||
|
||||
private static var _bInputReceived:Boolean;
|
||||
|
||||
private static var _mcsToKeepAlive:Array;
|
||||
|
||||
private static var _lastMsgSentToServer:Number;
|
||||
|
||||
private static var _inputTimer:Timer;
|
||||
|
||||
private static var _kickWarningPopupShowing:Boolean;
|
||||
|
||||
private static var _isConnected:Function;
|
||||
|
||||
private static var _disconnectClient:Function;
|
||||
|
||||
private static var _playIdleWarningSound:Function;
|
||||
|
||||
private static var KICK_INTERVAL:int = 360000;
|
||||
|
||||
private static var SEND_MSG_INTERVAL:int = 180000;
|
||||
|
||||
private static var NOTIFY_USER_INTERVAL:int = 10000;
|
||||
|
||||
private static var NOTIFY_USER_TIME:int = 30000;
|
||||
|
||||
public function KeepAlive()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function init(init_popupLayer:DisplayObjectContainer, initIsConnected:Function, disconnectClient:Function = null, playIdleWarningSound:Function = null) : void
|
||||
{
|
||||
popupLayer = init_popupLayer;
|
||||
_keepAliveTimer = new Timer(SEND_MSG_INTERVAL);
|
||||
_keepAliveTimer.addEventListener(TimerEvent.TIMER,sendKeepAliveMsg);
|
||||
_timeLeftTimer = new Timer(NOTIFY_USER_INTERVAL);
|
||||
_timeLeftTimer.addEventListener(TimerEvent.TIMER,timeLeftTimer);
|
||||
_timeLeftTimer.start();
|
||||
_lastMsgSentToServer = new Date().getTime();
|
||||
_mcsToKeepAlive = new Array();
|
||||
_isConnected = initIsConnected;
|
||||
_disconnectClient = disconnectClient;
|
||||
_playIdleWarningSound = playIdleWarningSound;
|
||||
}
|
||||
|
||||
public static function startKATimer(mcToKeepAlive:DisplayObjectContainer) : void
|
||||
{
|
||||
mcToKeepAlive.addEventListener(MouseEvent.MOUSE_DOWN,inputReceivedHandler,false,0,true);
|
||||
mcToKeepAlive.addEventListener(KeyboardEvent.KEY_DOWN,inputReceivedHandler,false,0,true);
|
||||
_mcsToKeepAlive.push(mcToKeepAlive);
|
||||
_bInputReceived = true;
|
||||
sendKeepAliveMsg(null);
|
||||
_keepAliveTimer.start();
|
||||
}
|
||||
|
||||
public static function stopKATimer(mcToStop:DisplayObjectContainer) : void
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("ka",[],gMainFrame.server.isWorldZone);
|
||||
_keepAliveTimer.stop();
|
||||
for(var i:int = 0; i < _mcsToKeepAlive.length; i++)
|
||||
{
|
||||
if(_mcsToKeepAlive[i] == mcToStop)
|
||||
{
|
||||
_mcsToKeepAlive[i].removeEventListener(MouseEvent.MOUSE_DOWN,inputReceivedHandler);
|
||||
_mcsToKeepAlive[i].removeEventListener(KeyboardEvent.KEY_DOWN,inputReceivedHandler);
|
||||
_mcsToKeepAlive.splice(i,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function restartTimeLeftTimer() : void
|
||||
{
|
||||
if(Boolean(_timeLeftTimer))
|
||||
{
|
||||
_lastMsgSentToServer = new Date().getTime();
|
||||
_timeLeftTimer.stop();
|
||||
_timeLeftTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
private static function sendKeepAliveMsg(evt:TimerEvent) : void
|
||||
{
|
||||
if(_bInputReceived)
|
||||
{
|
||||
gMainFrame.server.setXtObject_Str("ka",[],gMainFrame.server.isWorldZone);
|
||||
_lastMsgSentToServer = new Date().getTime();
|
||||
_bInputReceived = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static function timeLeftTimer(evt:TimerEvent) : void
|
||||
{
|
||||
var rustPop:DisplayObject = null;
|
||||
var elapsedTime:Number = new Date().getTime() - _lastMsgSentToServer;
|
||||
if(!_kickWarningPopupShowing && elapsedTime > KICK_INTERVAL - NOTIFY_USER_TIME)
|
||||
{
|
||||
rustPop = new SBOkPopup(popupLayer,LocalizationManager.translateIdOnly(14681),true,onKickWarningPopup);
|
||||
_kickWarningPopupShowing = true;
|
||||
if(_playIdleWarningSound != null)
|
||||
{
|
||||
_playIdleWarningSound();
|
||||
}
|
||||
if(Boolean(gMainFrame.userInfo.isModerator))
|
||||
{
|
||||
_bInputReceived = true;
|
||||
sendKeepAliveMsg(null);
|
||||
_kickWarningPopupShowing = false;
|
||||
SBOkPopup.destroyInParentChain(rustPop);
|
||||
}
|
||||
}
|
||||
if(elapsedTime > KICK_INTERVAL)
|
||||
{
|
||||
if(Boolean(_isConnected()))
|
||||
{
|
||||
if(_disconnectClient != null)
|
||||
{
|
||||
_disconnectClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function onKickWarningPopup(evt:MouseEvent) : void
|
||||
{
|
||||
_bInputReceived = true;
|
||||
sendKeepAliveMsg(null);
|
||||
evt.stopPropagation();
|
||||
SBOkPopup.destroyInParentChain(evt.target.parent);
|
||||
_kickWarningPopupShowing = false;
|
||||
}
|
||||
|
||||
public static function inputReceivedHandler(evt:Event) : void
|
||||
{
|
||||
if(!_bInputReceived)
|
||||
{
|
||||
_bInputReceived = true;
|
||||
}
|
||||
if(new Date().getTime() - _lastMsgSentToServer > SEND_MSG_INTERVAL)
|
||||
{
|
||||
sendKeepAliveMsg(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,75 @@
|
||||
package com.sbi.client
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class SFEvent extends Event
|
||||
{
|
||||
|
||||
public static const ON_CONNECT:String = "OnConnect";
|
||||
|
||||
public static const ON_LOGIN:String = "OnLogin";
|
||||
|
||||
public static const ON_LOGOUT:String = "OnLogOut";
|
||||
|
||||
public static const ON_CONNECTION_LOST:String = "OnConectionLost";
|
||||
|
||||
public static const ON_CHAT_MESSAGE:String = "OnChatMessage";
|
||||
|
||||
public static const ON_RECEIVED_OBJECT:String = "OnReceivedObject";
|
||||
|
||||
public static const ON_ROOM_LIST:String = "OnRoomList";
|
||||
|
||||
public static const ON_CREATE_ROOM:String = "OnCreateRoom";
|
||||
|
||||
public static const ON_ROOM_CREATED:String = "onRoomCreated";
|
||||
|
||||
public static const ON_JOIN_ROOM:String = "OnJoinRoom";
|
||||
|
||||
public static const ON_LEFT_ROOM:String = "OnLeftRoom";
|
||||
|
||||
public static const ON_USER_ENTERED_ROOM:String = "OnUserEnteredRoom";
|
||||
|
||||
public static const ON_USER_LEFT_ROOM:String = "OnUserLeftRoom";
|
||||
|
||||
public static const ON_ROOM_POPULATION_CHANGE:String = "onRoomPopulationChange";
|
||||
|
||||
public static const ON_BUDDY_LIST:String = "onBuddyList";
|
||||
|
||||
public static const ON_BUDDY_LIST_UPDATE:String = "onBuddyListUpdate";
|
||||
|
||||
public static const ON_BUDDY_REQUEST:String = "onBuddyRequest";
|
||||
|
||||
public static const ON_BUDDY_ROOM:String = "onBuddyRoom";
|
||||
|
||||
public static const ON_XT_REPLY:String = "OnXtReply";
|
||||
|
||||
public static const ON_ROOM_DELETED:String = "onRoomDeleted";
|
||||
|
||||
public static const ON_ROOM_VAR:String = "OnRoomVar";
|
||||
|
||||
public var status:Boolean;
|
||||
|
||||
public var message:String;
|
||||
|
||||
public var statusId:int;
|
||||
|
||||
public var userId:int;
|
||||
|
||||
public var roomId:int;
|
||||
|
||||
public var userName:String;
|
||||
|
||||
public var obj:*;
|
||||
|
||||
public function SFEvent(type:String)
|
||||
{
|
||||
super(type);
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new SFEvent(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.sbi.client
|
||||
{
|
||||
public class SFRoom
|
||||
{
|
||||
|
||||
public var name:String;
|
||||
|
||||
public var id:int;
|
||||
|
||||
public var users:int;
|
||||
|
||||
public var maxUsers:int;
|
||||
|
||||
public var spectators:int;
|
||||
|
||||
public var maxSpectators:int;
|
||||
|
||||
public var isPrivate:Boolean;
|
||||
|
||||
public var isGame:Boolean;
|
||||
|
||||
public var isLimbo:Boolean;
|
||||
|
||||
public var isTemp:Boolean;
|
||||
|
||||
public function SFRoom()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.sbi.corelib
|
||||
{
|
||||
import com.sbi.debug.DebugUtility;
|
||||
import flash.utils.getDefinitionByName;
|
||||
|
||||
public class Utils
|
||||
{
|
||||
|
||||
public function Utils()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function getDefByName(getClassName:String) : Class
|
||||
{
|
||||
var returnClass:Class = null;
|
||||
try
|
||||
{
|
||||
returnClass = getDefinitionByName(getClassName) as Class;
|
||||
}
|
||||
catch(re:ReferenceError)
|
||||
{
|
||||
DebugUtility.debugTrace("WARNING: Missing class definition \"" + getClassName + "\"!");
|
||||
returnClass = null;
|
||||
}
|
||||
return returnClass;
|
||||
}
|
||||
|
||||
public static function damerauLevenshteinDistance(a:Array, b:Array, C:int) : int
|
||||
{
|
||||
var DB:int = 0;
|
||||
var j:int = 0;
|
||||
var i1:int = 0;
|
||||
var j1:int = 0;
|
||||
var d:int = 0;
|
||||
var INF:int = a.length + b.length;
|
||||
var H:SimpleMatrix = new SimpleMatrix(a.length + 2,b.length + 2);
|
||||
H[0][0] = INF;
|
||||
for(var hi:int = 0; hi <= a.length; hi++)
|
||||
{
|
||||
H[hi + 1][1] = hi;
|
||||
H[hi + 1][0] = INF;
|
||||
}
|
||||
for(var hj:int = 0; hj <= b.length; hj++)
|
||||
{
|
||||
H[1][hj + 1] = hj;
|
||||
H[0][hj + 1] = INF;
|
||||
}
|
||||
var DA:Array = new Array(C);
|
||||
for(var dad:int = 0; dad < C; dad++)
|
||||
{
|
||||
DA[dad] = 0;
|
||||
}
|
||||
for(var i:int = 1; i <= a.length; i++)
|
||||
{
|
||||
DB = 0;
|
||||
for(j = 1; j <= b.length; j++)
|
||||
{
|
||||
i1 = int(DA[b[j - 1]]);
|
||||
j1 = DB;
|
||||
d = a[i - 1] == b[j - 1] ? 0 : 1;
|
||||
if(d == 0)
|
||||
{
|
||||
DB = j;
|
||||
}
|
||||
H[i + 1][j + 1] = Math.min(H[i][j] + d,H[i + 1][j] + 1,H[i][j + 1] + 1,H[i1][j1] + (i - i1 - 1) + 1 + (j - j1 - 1));
|
||||
}
|
||||
DA[a[i - 1]] = i;
|
||||
}
|
||||
return H[a.length + 1][b.length + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dynamic class SimpleMatrix extends Array
|
||||
{
|
||||
|
||||
public var rows:int;
|
||||
|
||||
public var cols:int;
|
||||
|
||||
public function SimpleMatrix(nrows:int = 0, ncols:int = -1)
|
||||
{
|
||||
super(nrows);
|
||||
if(ncols == -1)
|
||||
{
|
||||
ncols = nrows;
|
||||
}
|
||||
for(var i:int = 0; i < nrows; i++)
|
||||
{
|
||||
this[i] = new Array(ncols);
|
||||
}
|
||||
this.rows = nrows;
|
||||
this.cols = ncols;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
package com.sbi.corelib.audio
|
||||
{
|
||||
import flash.net.SharedObject;
|
||||
import flash.utils.Dictionary;
|
||||
|
||||
public class SBAudio
|
||||
{
|
||||
|
||||
private static var _cachedSounds:Dictionary;
|
||||
|
||||
private static var _sharedObj:SharedObject;
|
||||
|
||||
private static var _muteCallback:Function;
|
||||
|
||||
private static var _sounds:Array = [];
|
||||
|
||||
private static var _music:Array = [];
|
||||
|
||||
private static var _isMusicMuted:Boolean = false;
|
||||
|
||||
private static var _areSoundsMuted:Boolean = false;
|
||||
|
||||
private static var _isInitialized:Boolean = false;
|
||||
|
||||
public function SBAudio()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function init(cachedSoundObjects:Object, muteCallBack:Function) : void
|
||||
{
|
||||
var sfxClassName:String = null;
|
||||
var sfxObject:Object = null;
|
||||
_cachedSounds = new Dictionary();
|
||||
for(sfxClassName in cachedSoundObjects)
|
||||
{
|
||||
sfxObject = cachedSoundObjects[sfxClassName];
|
||||
addCachedSound(sfxClassName,sfxObject.className,sfxObject.volume);
|
||||
}
|
||||
_muteCallback = muteCallBack;
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
public static function setupSharedObject(sharedObj:SharedObject) : void
|
||||
{
|
||||
if(_sharedObj == null && sharedObj != null)
|
||||
{
|
||||
_sharedObj = sharedObj;
|
||||
if(Boolean(_sharedObj.data.isMusicMuted))
|
||||
{
|
||||
muteMusic();
|
||||
}
|
||||
if(Boolean(_sharedObj.data.areSoundsMuted))
|
||||
{
|
||||
muteSounds();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function addCachedSound(className:String, classVar:Class, defVolume:Number = 0.3) : void
|
||||
{
|
||||
_cachedSounds[className] = new SBSound(classVar,false,defVolume);
|
||||
}
|
||||
|
||||
public static function get isMusicMuted() : Boolean
|
||||
{
|
||||
return _isMusicMuted;
|
||||
}
|
||||
|
||||
public static function get areSoundsMuted() : Boolean
|
||||
{
|
||||
return _areSoundsMuted;
|
||||
}
|
||||
|
||||
public static function get isInitialized() : Boolean
|
||||
{
|
||||
return _isInitialized;
|
||||
}
|
||||
|
||||
public static function addSound(sound:SBSound) : void
|
||||
{
|
||||
_sounds.push(sound);
|
||||
}
|
||||
|
||||
public static function removeSound(sound:SBSound) : void
|
||||
{
|
||||
_sounds.splice(_sounds.indexOf(sound),1);
|
||||
}
|
||||
|
||||
public static function addMusic(music:Object) : void
|
||||
{
|
||||
_music.push(music);
|
||||
}
|
||||
|
||||
public static function removeMusic(music:Object) : void
|
||||
{
|
||||
_music.splice(_music.indexOf(music),1);
|
||||
}
|
||||
|
||||
public static function playCachedSound(className:String, loopCount:int = 1) : void
|
||||
{
|
||||
var sfx:SBSound = _cachedSounds[className];
|
||||
if(!sfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
sfx.play(0,loopCount);
|
||||
}
|
||||
|
||||
public static function stopCachedSound(className:String) : void
|
||||
{
|
||||
var sfx:SBSound = _cachedSounds[className];
|
||||
if(!sfx)
|
||||
{
|
||||
return;
|
||||
}
|
||||
sfx.stop();
|
||||
}
|
||||
|
||||
public static function setVolumeAll(vol:Number) : void
|
||||
{
|
||||
setVolumeSounds(vol);
|
||||
setVolumeMusic(vol);
|
||||
}
|
||||
|
||||
public static function setVolumeSounds(vol:Number) : void
|
||||
{
|
||||
var s:SBSound = null;
|
||||
for each(s in _sounds)
|
||||
{
|
||||
s.volume = vol;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getVolumeMusic() : Number
|
||||
{
|
||||
var vol:Number = NaN;
|
||||
var m:Object = null;
|
||||
for each(m in _music)
|
||||
{
|
||||
vol = Number(m.volume);
|
||||
}
|
||||
return vol;
|
||||
}
|
||||
|
||||
public static function setVolumeMusic(vol:Number) : void
|
||||
{
|
||||
var m:Object = null;
|
||||
for each(m in _music)
|
||||
{
|
||||
m.volume = vol;
|
||||
}
|
||||
}
|
||||
|
||||
private static function setSharedObjMusicMuted(isMuted:Boolean) : void
|
||||
{
|
||||
if(_sharedObj != null && _sharedObj.data.isMusicMuted != isMuted)
|
||||
{
|
||||
_sharedObj.data.isMusicMuted = isMuted;
|
||||
try
|
||||
{
|
||||
_sharedObj.flush();
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function setSharedObjSoundsMuted(isMuted:Boolean) : void
|
||||
{
|
||||
if(_sharedObj != null && _sharedObj.data.areSoundsMuted != isMuted)
|
||||
{
|
||||
_sharedObj.data.areSoundsMuted = isMuted;
|
||||
try
|
||||
{
|
||||
_sharedObj.flush();
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function toggleMuteAll() : void
|
||||
{
|
||||
toggleMuteSounds();
|
||||
toggleMuteMusic();
|
||||
_muteCallback(_isMusicMuted);
|
||||
}
|
||||
|
||||
public static function muteAll() : void
|
||||
{
|
||||
muteSounds();
|
||||
muteMusic();
|
||||
}
|
||||
|
||||
public static function unmuteAll() : void
|
||||
{
|
||||
unmuteSounds();
|
||||
unmuteMusic();
|
||||
}
|
||||
|
||||
public static function toggleMuteSounds() : void
|
||||
{
|
||||
_areSoundsMuted = !_areSoundsMuted;
|
||||
setSharedObjSoundsMuted(_areSoundsMuted);
|
||||
}
|
||||
|
||||
public static function muteSounds() : void
|
||||
{
|
||||
_areSoundsMuted = true;
|
||||
setSharedObjSoundsMuted(true);
|
||||
}
|
||||
|
||||
public static function unmuteSounds() : void
|
||||
{
|
||||
_areSoundsMuted = false;
|
||||
setSharedObjSoundsMuted(false);
|
||||
}
|
||||
|
||||
public static function toggleMuteMusic() : void
|
||||
{
|
||||
var m:Object = null;
|
||||
for each(m in _music)
|
||||
{
|
||||
m.toggleMute();
|
||||
}
|
||||
_isMusicMuted = !_isMusicMuted;
|
||||
setSharedObjMusicMuted(_isMusicMuted);
|
||||
}
|
||||
|
||||
public static function muteMusic(setFlags:Boolean = true) : void
|
||||
{
|
||||
var m:Object = null;
|
||||
for each(m in _music)
|
||||
{
|
||||
m.mute();
|
||||
}
|
||||
if(setFlags)
|
||||
{
|
||||
_isMusicMuted = true;
|
||||
setSharedObjMusicMuted(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static function unmuteMusic(setFlags:Boolean = true) : void
|
||||
{
|
||||
var m:Object = null;
|
||||
for each(m in _music)
|
||||
{
|
||||
m.unmute();
|
||||
}
|
||||
if(setFlags)
|
||||
{
|
||||
_isMusicMuted = false;
|
||||
setSharedObjMusicMuted(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static function togglePauseAll() : void
|
||||
{
|
||||
togglePauseSounds();
|
||||
togglePauseMusic();
|
||||
}
|
||||
|
||||
public static function pauseAll() : void
|
||||
{
|
||||
pauseSounds();
|
||||
pauseMusic();
|
||||
}
|
||||
|
||||
public static function unpauseAll() : void
|
||||
{
|
||||
unpauseSounds();
|
||||
unpauseMusic();
|
||||
}
|
||||
|
||||
public static function togglePauseSounds() : void
|
||||
{
|
||||
var s:SBSound = null;
|
||||
for each(s in _sounds)
|
||||
{
|
||||
s.togglePause();
|
||||
}
|
||||
}
|
||||
|
||||
public static function pauseSounds() : void
|
||||
{
|
||||
var s:SBSound = null;
|
||||
for each(s in _sounds)
|
||||
{
|
||||
s.pause();
|
||||
}
|
||||
}
|
||||
|
||||
public static function unpauseSounds() : void
|
||||
{
|
||||
var s:SBSound = null;
|
||||
for each(s in _sounds)
|
||||
{
|
||||
s.unpause();
|
||||
}
|
||||
}
|
||||
|
||||
public static function togglePauseMusic() : void
|
||||
{
|
||||
var m:Object = null;
|
||||
for each(m in _music)
|
||||
{
|
||||
m.togglePause();
|
||||
}
|
||||
}
|
||||
|
||||
public static function pauseMusic() : void
|
||||
{
|
||||
var m:Object = null;
|
||||
for each(m in _music)
|
||||
{
|
||||
m.pause();
|
||||
}
|
||||
}
|
||||
|
||||
public static function unpauseMusic() : void
|
||||
{
|
||||
var m:Object = null;
|
||||
for each(m in _music)
|
||||
{
|
||||
m.unpause();
|
||||
}
|
||||
}
|
||||
|
||||
public static function stopAll() : void
|
||||
{
|
||||
stopSounds();
|
||||
stopMusic();
|
||||
}
|
||||
|
||||
public static function stopSounds() : void
|
||||
{
|
||||
var s:SBSound = null;
|
||||
for each(s in _sounds)
|
||||
{
|
||||
s.stop();
|
||||
}
|
||||
}
|
||||
|
||||
public static function stopMusic() : void
|
||||
{
|
||||
var m:Object = null;
|
||||
for each(m in _music)
|
||||
{
|
||||
m.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
package com.sbi.corelib.audio
|
||||
{
|
||||
import com.sbi.loader.LoaderCache;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.media.Sound;
|
||||
import flash.media.SoundChannel;
|
||||
import flash.media.SoundLoaderContext;
|
||||
import flash.media.SoundTransform;
|
||||
import flash.net.URLRequest;
|
||||
|
||||
public class SBMusic
|
||||
{
|
||||
|
||||
private var _hashKey:String;
|
||||
|
||||
private var _previouslyPlayedFilename:String;
|
||||
|
||||
private var _currFilename:String;
|
||||
|
||||
private var _previousVolume:Number;
|
||||
|
||||
private var _currVolume:Number;
|
||||
|
||||
public var paused:Boolean = false;
|
||||
|
||||
public var muted:Boolean = false;
|
||||
|
||||
public var mutedVolume:Number = 1;
|
||||
|
||||
public var playVolume:Number = 1;
|
||||
|
||||
public var s:Sound;
|
||||
|
||||
public var sc:SoundChannel;
|
||||
|
||||
public var position:Number;
|
||||
|
||||
public function SBMusic(filename:String, autoPlay:Boolean = true, vol:Number = 1, bufferTime:Number = 1000, checkForPolicyFile:Boolean = true)
|
||||
{
|
||||
super();
|
||||
this.playNewMusic(filename,autoPlay,vol,bufferTime,checkForPolicyFile);
|
||||
SBAudio.addMusic(this);
|
||||
}
|
||||
|
||||
public function playNewMusic(filename:String, autoPlay:Boolean = true, vol:Number = 1, bufferTime:Number = 1000, checkForPolicyFile:Boolean = true) : void
|
||||
{
|
||||
this._previouslyPlayedFilename = this._currFilename;
|
||||
this._currFilename = filename;
|
||||
this._previousVolume = this._currVolume;
|
||||
this._currVolume = vol;
|
||||
var cdnStreamURLRequest:URLRequest = LoaderCache.fetchCDNURLRequest("audio/" + filename);
|
||||
if(Boolean(this.s))
|
||||
{
|
||||
this.s.removeEventListener(IOErrorEvent.IO_ERROR,this.handleIOError);
|
||||
this.s = null;
|
||||
}
|
||||
if(Boolean(this.sc))
|
||||
{
|
||||
this.sc.stop();
|
||||
this.sc = null;
|
||||
}
|
||||
this.s = new Sound(cdnStreamURLRequest,new SoundLoaderContext(bufferTime,checkForPolicyFile));
|
||||
this.volume = vol;
|
||||
if(autoPlay)
|
||||
{
|
||||
this.play();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.stop();
|
||||
}
|
||||
this.s.addEventListener(IOErrorEvent.IO_ERROR,this.handleIOError,false,0,true);
|
||||
}
|
||||
|
||||
public function play(startTime:Number = 0, loops:int = 2147483647, sndTransform:SoundTransform = null) : void
|
||||
{
|
||||
if(this.s == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.sc = this.s.play(startTime,loops,sndTransform);
|
||||
if(this.sc == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.setTransformVolume(this.playVolume);
|
||||
}
|
||||
|
||||
public function get volume() : Number
|
||||
{
|
||||
return Boolean(this.sc) ? this.sc.soundTransform.volume : -1;
|
||||
}
|
||||
|
||||
public function set volume(vol:Number) : void
|
||||
{
|
||||
if(this.muted)
|
||||
{
|
||||
this.mutedVolume = vol;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.playVolume = vol;
|
||||
}
|
||||
if(Boolean(this.sc))
|
||||
{
|
||||
this.setTransformVolume(vol);
|
||||
}
|
||||
}
|
||||
|
||||
public function toggleMute() : void
|
||||
{
|
||||
if(this.muted)
|
||||
{
|
||||
this.unmute();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.mute();
|
||||
}
|
||||
}
|
||||
|
||||
public function mute() : void
|
||||
{
|
||||
if(!this.muted)
|
||||
{
|
||||
this.mutedVolume = this.volume;
|
||||
this.volume = 0;
|
||||
this.muted = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function unmute() : void
|
||||
{
|
||||
if(this.muted)
|
||||
{
|
||||
this.volume = this.mutedVolume;
|
||||
this.muted = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function togglePause() : void
|
||||
{
|
||||
if(this.paused)
|
||||
{
|
||||
this.unpause();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.pause();
|
||||
}
|
||||
}
|
||||
|
||||
public function pause() : void
|
||||
{
|
||||
if(Boolean(this.s) && Boolean(this.sc) && !this.paused)
|
||||
{
|
||||
this.position = this.sc.position;
|
||||
this.sc.stop();
|
||||
this.paused = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function unpause() : void
|
||||
{
|
||||
if(Boolean(this.s) && Boolean(this.sc) && this.paused)
|
||||
{
|
||||
this.sc = this.s.play(this.position);
|
||||
this.setTransformVolume(this.playVolume);
|
||||
this.paused = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function stop() : void
|
||||
{
|
||||
if(Boolean(this.sc))
|
||||
{
|
||||
this.sc.stop();
|
||||
}
|
||||
this.paused = false;
|
||||
this.muted = false;
|
||||
}
|
||||
|
||||
public function get previouslyPlayedFilename() : String
|
||||
{
|
||||
return this._previouslyPlayedFilename;
|
||||
}
|
||||
|
||||
public function get previousVolume() : Number
|
||||
{
|
||||
return this._previousVolume;
|
||||
}
|
||||
|
||||
private function setTransformVolume(vol:Number) : void
|
||||
{
|
||||
var transform:SoundTransform = this.sc.soundTransform;
|
||||
transform.volume = vol;
|
||||
this.sc.soundTransform = transform;
|
||||
}
|
||||
|
||||
private function handleIOError(i:IOErrorEvent) : void
|
||||
{
|
||||
if(Boolean(this.s))
|
||||
{
|
||||
trace("WARNING - IOError while attempting to load music:" + this.s.url);
|
||||
this.s = null;
|
||||
}
|
||||
if(Boolean(this.sc))
|
||||
{
|
||||
this.sc.stop();
|
||||
this.sc = null;
|
||||
}
|
||||
SBAudio.removeMusic(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.sbi.corelib.audio
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.media.Sound;
|
||||
import flash.media.SoundChannel;
|
||||
import flash.media.SoundTransform;
|
||||
|
||||
public class SBSound
|
||||
{
|
||||
|
||||
public var paused:Boolean = false;
|
||||
|
||||
public var playVolume:Number = 1;
|
||||
|
||||
public var s:Sound;
|
||||
|
||||
public var sc:SoundChannel;
|
||||
|
||||
private var _soundPlaying:Boolean;
|
||||
|
||||
public function SBSound(soundClassName:Class, autoPlay:Boolean = true, vol:Number = 1)
|
||||
{
|
||||
super();
|
||||
this.s = new soundClassName();
|
||||
this.volume = vol;
|
||||
if(autoPlay)
|
||||
{
|
||||
this.play();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.stop();
|
||||
}
|
||||
SBAudio.addSound(this);
|
||||
}
|
||||
|
||||
public function play(startTime:Number = 0, loops:int = 0, sndTransform:SoundTransform = null) : void
|
||||
{
|
||||
if(loops == -1)
|
||||
{
|
||||
loops = int.MAX_VALUE;
|
||||
}
|
||||
if(this.s == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.sc = this.s.play(startTime,loops,sndTransform);
|
||||
if(this.sc == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this._soundPlaying = true;
|
||||
this.sc.addEventListener(Event.SOUND_COMPLETE,this.soundStoppedHandler,false,0,true);
|
||||
this.setTransformVolume(this.playVolume);
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
this.stop();
|
||||
this.sc = null;
|
||||
this.s = null;
|
||||
SBAudio.removeSound(this);
|
||||
}
|
||||
|
||||
public function get volume() : Number
|
||||
{
|
||||
return Boolean(this.sc) ? this.sc.soundTransform.volume : -1;
|
||||
}
|
||||
|
||||
public function set volume(vol:Number) : void
|
||||
{
|
||||
this.playVolume = vol;
|
||||
if(Boolean(this.sc))
|
||||
{
|
||||
this.setTransformVolume(vol);
|
||||
}
|
||||
}
|
||||
|
||||
public function get isPlaying() : Boolean
|
||||
{
|
||||
return this._soundPlaying;
|
||||
}
|
||||
|
||||
public function togglePause() : void
|
||||
{
|
||||
if(this.paused)
|
||||
{
|
||||
this.unpause();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.pause();
|
||||
}
|
||||
}
|
||||
|
||||
public function pause() : void
|
||||
{
|
||||
if(Boolean(this.sc) && !this.paused)
|
||||
{
|
||||
this.sc.stop();
|
||||
this.paused = true;
|
||||
this._soundPlaying = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function unpause() : void
|
||||
{
|
||||
if(Boolean(this.s) && Boolean(this.sc) && this.paused)
|
||||
{
|
||||
this.sc = this.s.play(this.sc.position);
|
||||
if(this.sc == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this._soundPlaying = true;
|
||||
this.sc.addEventListener(Event.SOUND_COMPLETE,this.soundStoppedHandler,false,0,true);
|
||||
this.setTransformVolume(this.playVolume);
|
||||
this.paused = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function stop() : void
|
||||
{
|
||||
if(Boolean(this.sc))
|
||||
{
|
||||
this.sc.stop();
|
||||
}
|
||||
this.paused = false;
|
||||
this._soundPlaying = false;
|
||||
}
|
||||
|
||||
private function setTransformVolume(vol:Number) : void
|
||||
{
|
||||
var transform:SoundTransform = this.sc.soundTransform;
|
||||
if(SBAudio.isMusicMuted)
|
||||
{
|
||||
transform.volume = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.volume = vol;
|
||||
}
|
||||
this.sc.soundTransform = transform;
|
||||
}
|
||||
|
||||
private function soundStoppedHandler(e:Event) : void
|
||||
{
|
||||
this._soundPlaying = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.sbi.corelib.crypto
|
||||
{
|
||||
import com.hurlant.crypto.Crypto;
|
||||
import com.hurlant.crypto.hash.SHA256;
|
||||
import com.hurlant.crypto.symmetric.ICipher;
|
||||
import com.hurlant.crypto.symmetric.IPad;
|
||||
import com.hurlant.crypto.symmetric.IVMode;
|
||||
import com.hurlant.crypto.symmetric.PKCS5;
|
||||
import com.hurlant.util.Base64;
|
||||
import com.hurlant.util.Hex;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class SBCrypto
|
||||
{
|
||||
|
||||
public function SBCrypto()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function encrypt(input:String, key:String) : String
|
||||
{
|
||||
var sha:SHA256 = new SHA256();
|
||||
var keyData:ByteArray = sha.hash(Hex.toArray(Hex.fromString(key)));
|
||||
var data:ByteArray = Hex.toArray(Hex.fromString(input));
|
||||
var pad:IPad = new PKCS5();
|
||||
var mode:ICipher = Crypto.getCipher("aes-256-cbc",keyData,pad);
|
||||
mode.encrypt(data);
|
||||
var ivmode:IVMode = mode as IVMode;
|
||||
var combined:ByteArray = ivmode.IV;
|
||||
combined.writeBytes(data);
|
||||
return Base64.encodeByteArray(combined);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,444 @@
|
||||
package com.sbi.corelib.input
|
||||
{
|
||||
import flash.display.MovieClip;
|
||||
import flash.events.Event;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFormat;
|
||||
import flash.text.TextFormatAlign;
|
||||
import flash.text.TextLineMetrics;
|
||||
import flash.utils.setTimeout;
|
||||
import gui.EmoticonUtility;
|
||||
|
||||
public class SBTextField extends MovieClip
|
||||
{
|
||||
|
||||
private const CHAT_BUFFER_SIZE:int = 100;
|
||||
|
||||
private var _inputTxt:TextField;
|
||||
|
||||
private var _outputTxt:TextField;
|
||||
|
||||
private var _smileyHolder:MovieClip;
|
||||
|
||||
private var _smileyMask:MovieClip;
|
||||
|
||||
private var _smileyHistory:String;
|
||||
|
||||
private var _clearOutput:Boolean;
|
||||
|
||||
private var _smileyarray:Array;
|
||||
|
||||
private var _stringIndex:int;
|
||||
|
||||
private var _normalStringHistory:String;
|
||||
|
||||
private var _updateSizeFunction:Function;
|
||||
|
||||
private var updateAllEmotes:Boolean;
|
||||
|
||||
public function SBTextField(inputTextField:TextField, outputTextField:TextField, textDisplayMC:MovieClip, clearOutputEachTime:Boolean = false, useScrollBar:Boolean = false, updateSizeFunction:Function = null)
|
||||
{
|
||||
super();
|
||||
this._inputTxt = inputTextField;
|
||||
this._outputTxt = outputTextField;
|
||||
this._clearOutput = clearOutputEachTime;
|
||||
this._updateSizeFunction = updateSizeFunction;
|
||||
this._outputTxt.addEventListener(Event.SCROLL,this.scrollListener);
|
||||
if(Boolean(this._inputTxt))
|
||||
{
|
||||
this._inputTxt.text = "";
|
||||
}
|
||||
this._smileyHistory = "";
|
||||
this._smileyarray = new Array();
|
||||
this._stringIndex = 0;
|
||||
this._smileyHolder = new MovieClip();
|
||||
this._smileyHolder.graphics.beginFill(0,0);
|
||||
this._smileyHolder.graphics.drawRect(textDisplayMC.x,textDisplayMC.y,outputTextField.width,outputTextField.height);
|
||||
this._smileyHolder.graphics.endFill();
|
||||
this._smileyHolder.mouseChildren = false;
|
||||
this._smileyHolder.mouseEnabled = false;
|
||||
if(!this._clearOutput)
|
||||
{
|
||||
this._smileyMask = new MovieClip();
|
||||
this._smileyMask.graphics.beginFill(16777215,1);
|
||||
this._smileyMask.graphics.drawRect(textDisplayMC.x,textDisplayMC.y,textDisplayMC.width,textDisplayMC.height);
|
||||
this._smileyMask.graphics.endFill();
|
||||
this._smileyHolder.mask = this._smileyMask;
|
||||
}
|
||||
if(Boolean(textDisplayMC.parent))
|
||||
{
|
||||
textDisplayMC.parent.addChild(this._smileyHolder);
|
||||
if(!this._clearOutput)
|
||||
{
|
||||
textDisplayMC.parent.addChild(this._smileyMask);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
textDisplayMC.addChild(this._smileyHolder);
|
||||
if(!this._clearOutput)
|
||||
{
|
||||
textDisplayMC.addChild(this._smileyMask);
|
||||
}
|
||||
}
|
||||
if(outputTextField == null || textDisplayMC == null)
|
||||
{
|
||||
throw new Error("Output Textfield and/or text display movie clip cannot be null. Output Textfield = " + outputTextField + " text Display MC = " + textDisplayMC);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
}
|
||||
|
||||
public function trimHistory() : void
|
||||
{
|
||||
var tempStr:String = this._outputTxt.text;
|
||||
var index:int = tempStr.indexOf("\r") + 1;
|
||||
tempStr = tempStr.substr(index);
|
||||
this.clear();
|
||||
this.appendText(tempStr);
|
||||
}
|
||||
|
||||
public function adjustSmileys(value:Number) : void
|
||||
{
|
||||
this._smileyHolder.y -= value;
|
||||
}
|
||||
|
||||
public function get autoSize() : String
|
||||
{
|
||||
return this._outputTxt.autoSize;
|
||||
}
|
||||
|
||||
public function set autoSize(value:String) : void
|
||||
{
|
||||
this._outputTxt.autoSize = value;
|
||||
}
|
||||
|
||||
public function get text() : String
|
||||
{
|
||||
return this._outputTxt.text;
|
||||
}
|
||||
|
||||
public function set text(value:String) : void
|
||||
{
|
||||
if(this._clearOutput || value == "")
|
||||
{
|
||||
this.clear();
|
||||
}
|
||||
this.addText(value);
|
||||
}
|
||||
|
||||
public function get textColor() : uint
|
||||
{
|
||||
return this._outputTxt.textColor;
|
||||
}
|
||||
|
||||
public function set textColor(value:uint) : void
|
||||
{
|
||||
this._outputTxt.textColor = value;
|
||||
}
|
||||
|
||||
override public function get x() : Number
|
||||
{
|
||||
return this._outputTxt.x;
|
||||
}
|
||||
|
||||
override public function set x(value:Number) : void
|
||||
{
|
||||
this._outputTxt.x = value;
|
||||
}
|
||||
|
||||
override public function get y() : Number
|
||||
{
|
||||
return this._outputTxt.y;
|
||||
}
|
||||
|
||||
override public function set y(value:Number) : void
|
||||
{
|
||||
this._outputTxt.y = value;
|
||||
}
|
||||
|
||||
override public function get height() : Number
|
||||
{
|
||||
return this._outputTxt.height;
|
||||
}
|
||||
|
||||
override public function set height(value:Number) : void
|
||||
{
|
||||
this._outputTxt.height = value;
|
||||
}
|
||||
|
||||
override public function get width() : Number
|
||||
{
|
||||
return this._outputTxt.width;
|
||||
}
|
||||
|
||||
override public function set width(value:Number) : void
|
||||
{
|
||||
this._outputTxt.width = value;
|
||||
}
|
||||
|
||||
override public function get visible() : Boolean
|
||||
{
|
||||
return this._outputTxt.visible;
|
||||
}
|
||||
|
||||
override public function set visible(value:Boolean) : void
|
||||
{
|
||||
this._outputTxt.visible = value;
|
||||
}
|
||||
|
||||
override public function get alpha() : Number
|
||||
{
|
||||
return this._outputTxt.alpha;
|
||||
}
|
||||
|
||||
override public function set alpha(value:Number) : void
|
||||
{
|
||||
this._outputTxt.alpha = value;
|
||||
}
|
||||
|
||||
public function appendText(value:String) : void
|
||||
{
|
||||
if(this._clearOutput || value == "")
|
||||
{
|
||||
this.clear();
|
||||
}
|
||||
this.addText(value);
|
||||
}
|
||||
|
||||
public function set scrollV(value:int) : void
|
||||
{
|
||||
this._outputTxt.scrollV = value;
|
||||
}
|
||||
|
||||
public function get scrollV() : int
|
||||
{
|
||||
return this._outputTxt.scrollV;
|
||||
}
|
||||
|
||||
public function get maxScrollV() : int
|
||||
{
|
||||
return this._outputTxt.maxScrollV;
|
||||
}
|
||||
|
||||
public function get length() : int
|
||||
{
|
||||
return this._outputTxt.length;
|
||||
}
|
||||
|
||||
public function set defaultTextFormat(format:TextFormat) : void
|
||||
{
|
||||
format.align = TextFormatAlign.LEFT;
|
||||
this._outputTxt.defaultTextFormat = format;
|
||||
}
|
||||
|
||||
public function setTextFormat(format:TextFormat, beginIndex:int = -1, endIndex:int = -1) : void
|
||||
{
|
||||
format.align = TextFormatAlign.LEFT;
|
||||
this._outputTxt.setTextFormat(format,beginIndex,endIndex);
|
||||
this._outputTxt.defaultTextFormat = format;
|
||||
}
|
||||
|
||||
public function get numLines() : int
|
||||
{
|
||||
return this._outputTxt.numLines;
|
||||
}
|
||||
|
||||
public function get selectable() : Boolean
|
||||
{
|
||||
return this._outputTxt.selectable;
|
||||
}
|
||||
|
||||
public function set selectable(value:Boolean) : void
|
||||
{
|
||||
this._outputTxt.selectable = value;
|
||||
}
|
||||
|
||||
public function getTextFormat(beginIndex:int = -1, endIndex:int = -1) : TextFormat
|
||||
{
|
||||
return this._outputTxt.getTextFormat(beginIndex,endIndex);
|
||||
}
|
||||
|
||||
private function addText(str:String) : void
|
||||
{
|
||||
var i:String = null;
|
||||
var smiley:String = null;
|
||||
var n:int = 0;
|
||||
var h:String = null;
|
||||
var htmltag:Boolean = false;
|
||||
var formatedObj:Object = null;
|
||||
var temp:TextField = null;
|
||||
var tempTxt:String = null;
|
||||
var index:int = 0;
|
||||
if(str != "")
|
||||
{
|
||||
this._normalStringHistory += str;
|
||||
formatedObj = EmoticonUtility.formatStringForSmiley(str,this._stringIndex,this._smileyarray,this.updateAllEmotes);
|
||||
str = formatedObj.str;
|
||||
this._stringIndex = formatedObj.stringIndex;
|
||||
this._smileyarray = formatedObj.smileyArray;
|
||||
this.updateAllEmotes = false;
|
||||
this._outputTxt.appendText(str);
|
||||
if(this._outputTxt.scrollV + 1 >= this._outputTxt.maxScrollV)
|
||||
{
|
||||
this._outputTxt.scrollV = this._outputTxt.maxScrollV;
|
||||
}
|
||||
if(this.numLines >= this.CHAT_BUFFER_SIZE)
|
||||
{
|
||||
this._outputTxt.text = this._normalStringHistory;
|
||||
temp = this._outputTxt;
|
||||
while(temp.numLines > this.CHAT_BUFFER_SIZE * 0.5)
|
||||
{
|
||||
index = temp.text.indexOf("\r") + 1;
|
||||
temp.text = temp.text.substr(index);
|
||||
}
|
||||
tempTxt = temp.text.split("\r").join("\n");
|
||||
this.updateAllEmotes = true;
|
||||
this.clear();
|
||||
this.text = tempTxt;
|
||||
temp = null;
|
||||
return;
|
||||
}
|
||||
setTimeout(this.setupSmileys,1000 / 24,str);
|
||||
}
|
||||
}
|
||||
|
||||
private function setupSmileys(str:String) : void
|
||||
{
|
||||
var s:int = 0;
|
||||
var charboundaries:Rectangle = null;
|
||||
var finalLineMetrics:TextLineMetrics = null;
|
||||
var smileyMC:MovieClip = null;
|
||||
var currXPosition:Number = NaN;
|
||||
var lastYPosition:Number = 0;
|
||||
for(var itemsToAdd:Array = []; s < this._smileyarray.length; s++)
|
||||
{
|
||||
if(this._smileyarray[s] != null)
|
||||
{
|
||||
if(!this._smileyarray[s].added)
|
||||
{
|
||||
charboundaries = this._outputTxt.getCharBoundaries(this._smileyarray[s].strindex);
|
||||
if(Boolean(charboundaries))
|
||||
{
|
||||
finalLineMetrics = this._outputTxt.getLineMetrics(this._outputTxt.numLines - 1);
|
||||
smileyMC = this._smileyarray[s].emoticon;
|
||||
smileyMC.height = finalLineMetrics.height;
|
||||
smileyMC.scaleX = smileyMC.scaleY;
|
||||
currXPosition = charboundaries.x + smileyMC.width * 0.5;
|
||||
if(currXPosition > this._outputTxt.width)
|
||||
{
|
||||
charboundaries = this._outputTxt.getCharBoundaries(this._smileyarray[s].strindex + 1);
|
||||
if(!Boolean(charboundaries))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
smileyMC.x = charboundaries.x + this._outputTxt.x + smileyMC.width * 0.5 - 5;
|
||||
smileyMC.y = charboundaries.y + this._outputTxt.y + smileyMC.height * 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
smileyMC.x = charboundaries.x + this._outputTxt.x + smileyMC.width * 0.5;
|
||||
smileyMC.y = charboundaries.y + this._outputTxt.y + smileyMC.height * 0.5;
|
||||
}
|
||||
this._smileyHolder.addChild(smileyMC);
|
||||
this._smileyarray[s].added = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this._smileyHistory == "")
|
||||
{
|
||||
this._smileyHistory = str;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._smileyHistory += "\n" + str;
|
||||
}
|
||||
this._smileyarray = [];
|
||||
if(this._updateSizeFunction != null)
|
||||
{
|
||||
this._updateSizeFunction();
|
||||
}
|
||||
}
|
||||
|
||||
private function addSmileys(itemsToAdd:Array) : void
|
||||
{
|
||||
for(var i:int = 0; i < itemsToAdd.length; i++)
|
||||
{
|
||||
this._smileyHolder.addChild(itemsToAdd[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private function clear() : void
|
||||
{
|
||||
if(Boolean(this._inputTxt))
|
||||
{
|
||||
this._inputTxt.text = "";
|
||||
}
|
||||
this._smileyHolder.y = 0;
|
||||
while(this._smileyHolder.numChildren > 0)
|
||||
{
|
||||
this._smileyHolder.removeChildAt(0);
|
||||
}
|
||||
this._outputTxt.text = "";
|
||||
this._smileyarray = [];
|
||||
this._smileyHistory = "";
|
||||
this._stringIndex = 0;
|
||||
this._normalStringHistory = "";
|
||||
}
|
||||
|
||||
private function removeSpace(str:String) : String
|
||||
{
|
||||
var i:int = 0;
|
||||
var lastchar:String = "";
|
||||
var stringarray:Array = str.split("");
|
||||
for(i = 0; i < stringarray.length; i++)
|
||||
{
|
||||
if(lastchar == " ")
|
||||
{
|
||||
if(stringarray[i] == " ")
|
||||
{
|
||||
stringarray[i] = "";
|
||||
lastchar = " ";
|
||||
}
|
||||
else
|
||||
{
|
||||
lastchar = stringarray[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lastchar = stringarray[i];
|
||||
}
|
||||
}
|
||||
return stringarray.join("");
|
||||
}
|
||||
|
||||
private function scrollListener(evt:Event) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var metrics:TextLineMetrics = null;
|
||||
var ypos:Number = NaN;
|
||||
if(!this._clearOutput)
|
||||
{
|
||||
ypos = 0;
|
||||
for(i = 0; i < this._outputTxt.scrollV - 1; i++)
|
||||
{
|
||||
metrics = this._outputTxt.getLineMetrics(i);
|
||||
ypos += metrics.height;
|
||||
}
|
||||
this._smileyHolder.y = -ypos;
|
||||
}
|
||||
}
|
||||
|
||||
private function setSize(w:Number, h:Number) : void
|
||||
{
|
||||
this._smileyMask.width = w;
|
||||
this._smileyMask.height = h - 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
package com.sbi.corelib.math
|
||||
{
|
||||
import flash.geom.Point;
|
||||
|
||||
public class Collision
|
||||
{
|
||||
|
||||
public function Collision()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function segIntersection(p1:Point, p2:Point, p3:Point, p4:Point) : Point
|
||||
{
|
||||
var bx:Number = p2.x - p1.x;
|
||||
var by:Number = p2.y - p1.y;
|
||||
var dx:Number = p4.x - p3.x;
|
||||
var dy:Number = p4.y - p3.y;
|
||||
var b_dot_d_perp:Number = bx * dy - by * dx;
|
||||
if(b_dot_d_perp == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var cx:Number = p3.x - p1.x;
|
||||
var cy:Number = p3.y - p1.y;
|
||||
var t:Number = (cx * dy - cy * dx) / b_dot_d_perp;
|
||||
if(t < 0 || t > 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var u:Number = (cx * by - cy * bx) / b_dot_d_perp;
|
||||
if(u < 0 || u > 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Point(p1.x + t * bx,p1.y + t * by);
|
||||
}
|
||||
|
||||
public static function circleHitCircle(c1:Point, r1:Number, c2:Point, r2:Number) : Boolean
|
||||
{
|
||||
var dif:Point = c2.subtract(c1);
|
||||
var d:Number = dif.x * dif.x + dif.y * dif.y;
|
||||
return Boolean(d < (r1 + r2) * (r1 + r2));
|
||||
}
|
||||
|
||||
public static function pointHitCircle(p:Point, cp:Point, cr:Number) : Boolean
|
||||
{
|
||||
var diff:Point = p.subtract(cp);
|
||||
var distSqrd:Number = diff.x * diff.x + diff.y * diff.y;
|
||||
return Boolean(distSqrd < cr * cr);
|
||||
}
|
||||
|
||||
public static function movingCircleVsRay(cir:Point, radius:Number, vel:Point, tCol:Number, p1:Point, p2:Point) : Number
|
||||
{
|
||||
var d:Number = NaN;
|
||||
var Oz:Number = NaN;
|
||||
var t:Number = NaN;
|
||||
var ox:Number = NaN;
|
||||
var oy:Number = NaN;
|
||||
var norm:Number = NaN;
|
||||
var s:Number = NaN;
|
||||
var tColInfinite:Number = NaN;
|
||||
var vHitPosInfinite:Point = null;
|
||||
var vSegHitInfiniteP1:Point = null;
|
||||
var vSegHitInfiniteP2:Point = null;
|
||||
var vSeg:Point = p2.subtract(p1);
|
||||
var RC:Point = cir.subtract(p1);
|
||||
var D:Point = new Point();
|
||||
var raycos:Point = new Point(vel.x * tCol,vel.y * tCol);
|
||||
var velMag:Number = vel.x * vel.y;
|
||||
var nz:Number = raycos.x * vSeg.y - raycos.y * vSeg.x;
|
||||
var ln:Number = nz;
|
||||
if(ln == 0)
|
||||
{
|
||||
d = RC.x * vSeg.x + RC.y * vSeg.y;
|
||||
D.x = RC.x - vSeg.x * d;
|
||||
D.y = RC.y - vSeg.y * d;
|
||||
tCol = 0;
|
||||
return D.x * D.y <= radius ? -1 : 1;
|
||||
}
|
||||
nz /= ln;
|
||||
d = 0;
|
||||
if(d <= radius)
|
||||
{
|
||||
Oz = RC.x * vSeg.y - RC.y * vSeg.x;
|
||||
t = -(Oz * nz) / ln;
|
||||
ox = -(nz * vSeg.y);
|
||||
oy = nz * vSeg.x;
|
||||
norm = ox * ox + oy * oy;
|
||||
if(Boolean(norm))
|
||||
{
|
||||
norm = Math.sqrt(norm);
|
||||
ox /= norm;
|
||||
oy /= norm;
|
||||
}
|
||||
s = Math.abs(radius / (raycos.x * ox + raycos.y * oy));
|
||||
if(t < -s)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if(t - s > 1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
tColInfinite = t - s < 0 ? 0 : t - s;
|
||||
vHitPosInfinite = new Point(cir.x + vel.x * tColInfinite,cir.y + vel.y * tColInfinite);
|
||||
vSegHitInfiniteP1 = vHitPosInfinite.subtract(p1);
|
||||
vSegHitInfiniteP2 = vHitPosInfinite.subtract(p2);
|
||||
if(vSegHitInfiniteP1.x * vSeg.x + vSegHitInfiniteP1.y * vSeg.y < 0)
|
||||
{
|
||||
return Ray_Vs_Sphere(cir,vel,tCol,p1,radius);
|
||||
}
|
||||
if(vSegHitInfiniteP2.x * vSeg.x + vSegHitInfiniteP2.y * vSeg.y > 0)
|
||||
{
|
||||
return Ray_Vs_Sphere(cir,vel,tCol,p2,radius);
|
||||
}
|
||||
return tColInfinite;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static function rayHitCircle(c:Point, radius:Number, p1:Point, p2:Point) : Boolean
|
||||
{
|
||||
var dif:Point = c.subtract(p1);
|
||||
var dir:Point = p2.subtract(p1);
|
||||
var t:Number = (dif.x * dir.x + dif.y * dir.y) / (dir.x * dir.x + dir.y * dir.y);
|
||||
if(t < 0)
|
||||
{
|
||||
t = 0;
|
||||
}
|
||||
if(t > 1)
|
||||
{
|
||||
t = 1;
|
||||
}
|
||||
var closest:Point = new Point(p1.x + t * dir.x,p1.y + t * dir.y);
|
||||
var dist:Point = c.subtract(closest);
|
||||
var distsqr:Number = dist.x * dist.x + dist.y * dist.y;
|
||||
return Boolean(distsqr <= radius * radius);
|
||||
}
|
||||
|
||||
public static function Ray_Vs_Sphere(RayPos:Point, RayVel:Point, fRange:Number, S:Point, radius:Number) : Number
|
||||
{
|
||||
var x2:Number = NaN;
|
||||
var v_seg_mag:Number = NaN;
|
||||
var v_seg_mag_inv:Number = NaN;
|
||||
var v_seg_unit:Point = null;
|
||||
var x1:Number = NaN;
|
||||
var tCol:Number = NaN;
|
||||
var radius_sq:Number = radius * radius;
|
||||
var v_sphere:Point = S.subtract(RayPos);
|
||||
var v_sphere_mag_sq:Number = v_sphere.x * v_sphere.x + v_sphere.y * v_sphere.y;
|
||||
var v_seg:Point = new Point(RayVel.x * fRange,RayVel.y * fRange);
|
||||
var P2:Point = v_seg.add(RayPos);
|
||||
var test_2a:Number = v_seg.x * v_sphere.x + v_seg.y * v_sphere.y;
|
||||
var v_sphere2:Point = S.subtract(P2);
|
||||
var test_2b:Number = v_seg.x * v_sphere2.x + v_seg.y * v_sphere2.y;
|
||||
var test_2bb:Number = (v_sphere2.x + v_sphere2.y) * (v_sphere2.x + v_sphere2.y);
|
||||
var cpz:Number = v_seg.x * v_sphere.y - v_seg.y * v_sphere.x;
|
||||
var seg_dist_sq:Number = cpz * cpz;
|
||||
var v_seg_mag_sq:Number = v_seg.x * v_seg.x + v_seg.y * v_seg.y;
|
||||
if(test_2a > 0 && (test_2b < 0 || test_2bb < radius_sq) && seg_dist_sq < radius_sq * v_seg_mag_sq && v_seg_mag_sq > 0.00001)
|
||||
{
|
||||
x2 = Math.sqrt(radius_sq - seg_dist_sq / v_seg_mag_sq);
|
||||
v_seg_mag = Math.sqrt(v_seg_mag_sq);
|
||||
v_seg_mag_inv = 1 / v_seg_mag;
|
||||
v_seg_unit = new Point(v_seg.x * v_seg_mag_inv,v_seg.y * v_seg_mag_inv);
|
||||
x1 = v_seg_unit.x * v_sphere.x + v_seg_unit.y * v_sphere.y;
|
||||
tCol = fRange * (x1 - x2) * v_seg_mag_inv;
|
||||
return tCol < 0 ? 0 : tCol;
|
||||
}
|
||||
if(v_sphere_mag_sq < radius_sq)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.sbi.debug
|
||||
{
|
||||
import com.carlcalderon.arthropod.Debug;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
|
||||
public class DebugUtility
|
||||
{
|
||||
|
||||
public function DebugUtility()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function debugTrace(d:String, color:uint = 16711422) : void
|
||||
{
|
||||
trace(d);
|
||||
Debug.log(d,color);
|
||||
}
|
||||
|
||||
public static function debugTraceObject(oName:String, o:Object, lev:int = 0) : void
|
||||
{
|
||||
}
|
||||
|
||||
public static function debugTraceArray(aName:String, a:Array, oneElementPerLineMode:Boolean = false) : void
|
||||
{
|
||||
}
|
||||
|
||||
public static function debugTraceDisplayObjectContainer(docName:String, doc:DisplayObjectContainer, recurse:Boolean = false, lev:int = 0) : void
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,433 @@
|
||||
package com.sbi.graphics
|
||||
{
|
||||
import flash.display.BitmapData;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class BitmapByteArray
|
||||
{
|
||||
|
||||
private static const PALETTE_ALPHA_OFFSET:int = 25;
|
||||
|
||||
private static const SHADOW_GRADIENT_SCALE:int = 3;
|
||||
|
||||
private const TRANS:int = 0;
|
||||
|
||||
private var _palette:Array;
|
||||
|
||||
private var _h:int;
|
||||
|
||||
private var _w:int;
|
||||
|
||||
private var _offX:int;
|
||||
|
||||
private var _offY:int;
|
||||
|
||||
private var _ba:Vector.<int>;
|
||||
|
||||
public function BitmapByteArray()
|
||||
{
|
||||
super();
|
||||
this._palette = PaletteHelper.getAnimalPalette();
|
||||
}
|
||||
|
||||
public static function scaleAndPackImage(bm:BitmapData) : Object
|
||||
{
|
||||
var bmba:BitmapByteArray = new BitmapByteArray();
|
||||
bmba.loadBitmap(bm);
|
||||
bmba.halfImage();
|
||||
bmba.crop();
|
||||
return bmba.processPackImage();
|
||||
}
|
||||
|
||||
public static function scaleAndPackShadow(bm:BitmapData, xOff:int, yOff:int, cropW:int, cropH:int) : Object
|
||||
{
|
||||
var bmba:BitmapByteArray = new BitmapByteArray();
|
||||
return bmba.scaleShadow(bm,xOff,yOff,cropW,cropH);
|
||||
}
|
||||
|
||||
private function loadBitmap(bmd:BitmapData) : void
|
||||
{
|
||||
var x:uint = 0;
|
||||
var y:uint = 0;
|
||||
var color:uint = 0;
|
||||
this._w = bmd.width;
|
||||
this._h = bmd.height;
|
||||
this._ba = new Vector.<int>(this._w * this._h,true);
|
||||
var lastColor:uint = 0;
|
||||
var lastIndex:int = -1;
|
||||
var i:int = 0;
|
||||
for(y = 0; y < this._h; y++)
|
||||
{
|
||||
for(x = 0; x < this._w; x++)
|
||||
{
|
||||
color = bmd.getPixel32(x,y);
|
||||
if(lastColor != color || lastIndex < 0)
|
||||
{
|
||||
lastColor = color;
|
||||
lastIndex = int(this.findPaletteColor(color));
|
||||
}
|
||||
this._ba[i++] = lastIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function scaleShadow(bm:BitmapData, xOff:int, yOff:int, cropW:int, cropH:int) : Object
|
||||
{
|
||||
var c1:uint = 0;
|
||||
var c2:uint = 0;
|
||||
var c3:uint = 0;
|
||||
var c4:uint = 0;
|
||||
var x:int = 0;
|
||||
var pos:int = 0;
|
||||
this._w = bm.width;
|
||||
this._h = bm.height;
|
||||
var pixels:Vector.<uint> = bm.getVector(new Rectangle(0,0,this._w,this._h));
|
||||
var newBa:Vector.<int> = new Vector.<int>(this._w * this._h * 0.25,true);
|
||||
var p:int = 0;
|
||||
var i:int = 0;
|
||||
for(var y:int = 0; y < this._h; y += 2)
|
||||
{
|
||||
for(x = 0; x < this._w; x += 2)
|
||||
{
|
||||
p = x + y * this._w;
|
||||
c1 = pixels[p];
|
||||
c2 = pixels[p + 1];
|
||||
p += this._w;
|
||||
c3 = pixels[p];
|
||||
c4 = pixels[p + 1];
|
||||
newBa[i++] = this.blendShadowColors(c1,c2,c3,c4);
|
||||
}
|
||||
}
|
||||
this._ba = newBa;
|
||||
this._h /= 2;
|
||||
this._w /= 2;
|
||||
if(cropW != this._w || cropH != this._h)
|
||||
{
|
||||
i = 0;
|
||||
newBa = new Vector.<int>(cropW * cropH,true);
|
||||
for(y = yOff; y < yOff + cropH; y++)
|
||||
{
|
||||
pos = y * this._w + xOff;
|
||||
for(x = 0; x < cropW; x++)
|
||||
{
|
||||
p = this._ba[pos++];
|
||||
newBa[i++] = p;
|
||||
}
|
||||
}
|
||||
this._w = cropW;
|
||||
this._h = cropH;
|
||||
this._offX = xOff;
|
||||
this._offY = yOff;
|
||||
this._ba = newBa;
|
||||
}
|
||||
var ret:Object = this.processPackImage();
|
||||
ret.sm = SHADOW_GRADIENT_SCALE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
private function halfImage() : void
|
||||
{
|
||||
var c1:int = 0;
|
||||
var c2:int = 0;
|
||||
var c3:int = 0;
|
||||
var c4:int = 0;
|
||||
var x:int = 0;
|
||||
var newBa:Vector.<int> = new Vector.<int>(this._w * this._h * 0.25,true);
|
||||
var p:int = 0;
|
||||
var i:int = 0;
|
||||
for(var y:int = 0; y < this._h; y += 2)
|
||||
{
|
||||
for(x = 0; x < this._w; x += 2)
|
||||
{
|
||||
p = x + y * this._w;
|
||||
c1 = this._ba[p];
|
||||
c2 = this._ba[p + 1];
|
||||
p += this._w;
|
||||
c3 = this._ba[p];
|
||||
c4 = this._ba[p + 1];
|
||||
newBa[i++] = this.blendColors(c1,c2,c3,c4);
|
||||
}
|
||||
}
|
||||
this._ba = newBa;
|
||||
this._h /= 2;
|
||||
this._w /= 2;
|
||||
}
|
||||
|
||||
private function crop() : void
|
||||
{
|
||||
var p:uint = 0;
|
||||
var x:int = 0;
|
||||
var y:int = 0;
|
||||
var newBA:Vector.<int> = null;
|
||||
var pos:int = 0;
|
||||
var xmin:int = this._w;
|
||||
var xmax:int = 0;
|
||||
var ymin:int = this._h;
|
||||
var ymax:int = 0;
|
||||
var i:int = 0;
|
||||
for(y = 0; y < this._h; y++)
|
||||
{
|
||||
for(x = 0; x < this._w; x++)
|
||||
{
|
||||
p = uint(this._ba[i++]);
|
||||
if(p > 0)
|
||||
{
|
||||
if(x < xmin)
|
||||
{
|
||||
xmin = x;
|
||||
}
|
||||
if(x > xmax)
|
||||
{
|
||||
xmax = x;
|
||||
}
|
||||
if(y < ymin)
|
||||
{
|
||||
ymin = y;
|
||||
}
|
||||
if(y > ymax)
|
||||
{
|
||||
ymax = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this._offX = xmin;
|
||||
this._offY = ymin;
|
||||
var w:uint = xmax - xmin + 1;
|
||||
var h:uint = ymax - ymin + 1;
|
||||
if(xmin == this._w && ymin == this._h)
|
||||
{
|
||||
this._w = 0;
|
||||
this._h = 0;
|
||||
this._ba = null;
|
||||
return;
|
||||
}
|
||||
i = 0;
|
||||
if(w != this._w || h != this._h)
|
||||
{
|
||||
newBA = new Vector.<int>(w * h,true);
|
||||
for(y = ymin; y < ymin + h; y++)
|
||||
{
|
||||
pos = y * this._w + this._offX;
|
||||
for(x = 0; x < w; x++)
|
||||
{
|
||||
p = uint(this._ba[pos++]);
|
||||
newBA[i++] = p;
|
||||
}
|
||||
}
|
||||
this._w = w;
|
||||
this._h = h;
|
||||
this._ba = newBA;
|
||||
}
|
||||
}
|
||||
|
||||
private function processPackImage() : Object
|
||||
{
|
||||
var x:int = 0;
|
||||
var y:int = 0;
|
||||
var line:String = null;
|
||||
var c:uint = 0;
|
||||
if(this._ba == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var o:Object = {
|
||||
"x":this._offX,
|
||||
"y":this._offY,
|
||||
"w":this._w,
|
||||
"h":this._h
|
||||
};
|
||||
var pack:ByteArray = new ByteArray();
|
||||
o.b = pack;
|
||||
var len:int = int(this._ba.length);
|
||||
var lastColor:uint = 256;
|
||||
var sameCount:uint = 0;
|
||||
var p:int = 0;
|
||||
while(p < len)
|
||||
{
|
||||
c = uint(this._ba[p++]);
|
||||
if(lastColor == 256)
|
||||
{
|
||||
lastColor = c;
|
||||
}
|
||||
else if(c != lastColor)
|
||||
{
|
||||
if(Boolean(sameCount))
|
||||
{
|
||||
lastColor |= 128;
|
||||
while(sameCount > 255)
|
||||
{
|
||||
pack.writeByte(lastColor);
|
||||
pack.writeByte(uint(255));
|
||||
sameCount -= 256;
|
||||
}
|
||||
if(sameCount > 0)
|
||||
{
|
||||
pack.writeByte(lastColor);
|
||||
pack.writeByte(sameCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
pack.writeByte(uint(lastColor & 0x7F));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pack.writeByte(lastColor);
|
||||
}
|
||||
lastColor = c;
|
||||
sameCount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
sameCount++;
|
||||
}
|
||||
}
|
||||
if(Boolean(sameCount) || len == 1)
|
||||
{
|
||||
lastColor |= 128;
|
||||
while(sameCount > 255)
|
||||
{
|
||||
pack.writeByte(lastColor);
|
||||
pack.writeByte(uint(255));
|
||||
sameCount -= 256;
|
||||
}
|
||||
if(sameCount > 0)
|
||||
{
|
||||
pack.writeByte(lastColor);
|
||||
pack.writeByte(sameCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
pack.writeByte(uint(lastColor & 0x7F));
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
private function findPaletteColor(color:uint) : uint
|
||||
{
|
||||
var alpha:uint = uint((color & 0xFF000000) >> 24);
|
||||
if(alpha < 160)
|
||||
{
|
||||
return this.TRANS;
|
||||
}
|
||||
color |= 4278190080;
|
||||
for(var i:uint = 0; i < PALETTE_ALPHA_OFFSET; i++)
|
||||
{
|
||||
if(this._palette[i] == color)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
var cr:int = color >> 16 & 0xFF;
|
||||
var cg:int = color >> 8 & 0xFF;
|
||||
var cb:int = color & 0xFF;
|
||||
return this.findClosetPaletteIndex(cr,cg,cb);
|
||||
}
|
||||
|
||||
private function findClosetPaletteIndex(cr:int, cg:int, cb:int) : int
|
||||
{
|
||||
var a:int = 0;
|
||||
var r:int = 0;
|
||||
var g:int = 0;
|
||||
var b:int = 0;
|
||||
var distance:int = 0;
|
||||
var pc:uint = 0;
|
||||
var smallest:int = 10000000;
|
||||
var smallestIndex:int = 0;
|
||||
for(var j:uint = 0; j < PALETTE_ALPHA_OFFSET; j++)
|
||||
{
|
||||
pc = uint(this._palette[j]);
|
||||
r = (pc >> 16 & 0xFF) - cr;
|
||||
g = (pc >> 8 & 0xFF) - cg;
|
||||
b = (pc & 0xFF) - cb;
|
||||
distance = r * r + g * g + b * b;
|
||||
if(distance < smallest)
|
||||
{
|
||||
smallest = distance;
|
||||
smallestIndex = int(j);
|
||||
}
|
||||
}
|
||||
return smallestIndex;
|
||||
}
|
||||
|
||||
private function blendColors(c:uint, c1:uint, c2:uint, c3:uint) : uint
|
||||
{
|
||||
var newColor:uint = 0;
|
||||
var transCount:int = 0;
|
||||
var a:Array = null;
|
||||
var total:int = 0;
|
||||
var cr:int = 0;
|
||||
var cg:int = 0;
|
||||
var cb:int = 0;
|
||||
var i:int = 0;
|
||||
if(c == this.TRANS)
|
||||
{
|
||||
transCount++;
|
||||
}
|
||||
if(c1 == this.TRANS)
|
||||
{
|
||||
transCount++;
|
||||
}
|
||||
if(c2 == this.TRANS)
|
||||
{
|
||||
transCount++;
|
||||
}
|
||||
if(c3 == this.TRANS)
|
||||
{
|
||||
transCount++;
|
||||
}
|
||||
if(transCount == 4)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(c == c1 && c == c2 && c == c3)
|
||||
{
|
||||
newColor = c;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(a = [c,c1,c2,c3]; i < 4; )
|
||||
{
|
||||
if(a[i] != this.TRANS)
|
||||
{
|
||||
c = uint(this._palette[a[i]]);
|
||||
cr += c >> 16 & 0xFF;
|
||||
cg += c >> 8 & 0xFF;
|
||||
cb += c & 0xFF;
|
||||
total++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
cr /= total;
|
||||
cg /= total;
|
||||
cb /= total;
|
||||
newColor = uint(this.findClosetPaletteIndex(cr,cg,cb));
|
||||
}
|
||||
return uint(newColor + transCount * PALETTE_ALPHA_OFFSET);
|
||||
}
|
||||
|
||||
private function blendShadowColors(c1:uint, c2:uint, c3:uint, c4:uint) : int
|
||||
{
|
||||
var a:uint = ((c1 >> 24 & 0xFF) + (c2 >> 24 & 0xFF) + (c3 >> 24 & 0xFF) + (c4 >> 24 & 0xFF)) / 4;
|
||||
var c:uint = ((c1 & 0xFF & 0xFF) + (c2 & 0xFF & 0xFF) + (c3 & 0xFF & 0xFF) + (c4 & 0xFF & 0xFF)) / 4;
|
||||
if(Boolean(a))
|
||||
{
|
||||
c += (255 - c) * ((255 - a) / 255);
|
||||
c >>= BitmapByteArray.SHADOW_GRADIENT_SCALE;
|
||||
if(c == 0)
|
||||
{
|
||||
c = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
c = 0;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.sbi.graphics
|
||||
{
|
||||
import flash.display.BitmapData;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class ImageArray
|
||||
{
|
||||
|
||||
public static const VERSION:uint = 117967104;
|
||||
|
||||
private var _frames:Array;
|
||||
|
||||
public function ImageArray()
|
||||
{
|
||||
super();
|
||||
this._frames = new Array();
|
||||
}
|
||||
|
||||
public function get length() : int
|
||||
{
|
||||
return this._frames.length;
|
||||
}
|
||||
|
||||
public function release() : void
|
||||
{
|
||||
this._frames.splice(0,this._frames.length);
|
||||
}
|
||||
|
||||
public function addBitmap(bm:BitmapData) : void
|
||||
{
|
||||
var o:Object = BitmapByteArray.scaleAndPackImage(bm);
|
||||
this._frames.push(o);
|
||||
}
|
||||
|
||||
public function attachShadow(bm:BitmapData) : void
|
||||
{
|
||||
var current:Object = null;
|
||||
var o:Object = null;
|
||||
if(Boolean(this._frames.length))
|
||||
{
|
||||
current = this._frames[this._frames.length - 1];
|
||||
o = BitmapByteArray.scaleAndPackShadow(bm,current.x,current.y,current.w,current.h);
|
||||
current.s = o.b;
|
||||
current.sm = o.sm;
|
||||
}
|
||||
}
|
||||
|
||||
public function addFrame(o:Object) : void
|
||||
{
|
||||
this._frames.push(o);
|
||||
}
|
||||
|
||||
public function loadPackage(pack:ByteArray) : void
|
||||
{
|
||||
this.release();
|
||||
pack.position = 0;
|
||||
try
|
||||
{
|
||||
pack.uncompress();
|
||||
}
|
||||
catch(err:Error)
|
||||
{
|
||||
}
|
||||
var o:Object = pack.readObject();
|
||||
if(o.v == ImageArray.VERSION)
|
||||
{
|
||||
this._frames = o.f;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public function getFrame(i:int) : Object
|
||||
{
|
||||
return this._frames[i];
|
||||
}
|
||||
|
||||
public function getPackage(bCompress:Boolean = true) : ByteArray
|
||||
{
|
||||
var i:int = 0;
|
||||
var ba:ByteArray = null;
|
||||
var top:Object = null;
|
||||
if(Boolean(this._frames.length))
|
||||
{
|
||||
top = {
|
||||
"v":ImageArray.VERSION,
|
||||
"f":this._frames
|
||||
};
|
||||
ba = new ByteArray();
|
||||
ba.writeObject(top);
|
||||
ba.position = 0;
|
||||
if(bCompress)
|
||||
{
|
||||
ba.compress();
|
||||
}
|
||||
}
|
||||
return ba;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.sbi.graphics
|
||||
{
|
||||
public class ImageArrayHelper
|
||||
{
|
||||
|
||||
public function ImageArrayHelper()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function packId(aId:int, cId:int, lId:int) : uint
|
||||
{
|
||||
return aId << 24 | cId << 16 | lId;
|
||||
}
|
||||
|
||||
public static function avatarId(id:uint) : int
|
||||
{
|
||||
return id >> 24 & 0xFF;
|
||||
}
|
||||
|
||||
public static function categoryId(id:uint) : int
|
||||
{
|
||||
return id >> 16 & 0xFF;
|
||||
}
|
||||
|
||||
public static function layerId(id:uint) : int
|
||||
{
|
||||
return id & 0xFFFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.sbi.graphics
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class JPEGAsyncCompleteEvent extends Event
|
||||
{
|
||||
|
||||
public static const JPEGASYNC_COMPLETE:String = "JPEGAsyncComplete";
|
||||
|
||||
public var ImageData:ByteArray;
|
||||
|
||||
public function JPEGAsyncCompleteEvent(data:ByteArray)
|
||||
{
|
||||
this.ImageData = data;
|
||||
super(JPEGASYNC_COMPLETE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,702 @@
|
||||
package com.sbi.graphics
|
||||
{
|
||||
import flash.display.BitmapData;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.setTimeout;
|
||||
|
||||
public class JpegAsynchEncoder extends EventDispatcher
|
||||
{
|
||||
|
||||
public static const CONTENT_TYPE:String = "image/jpeg";
|
||||
|
||||
private var ZigZag:Array = [0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18,24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63];
|
||||
|
||||
private var std_dc_luminance_nrcodes:Array = [0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0];
|
||||
|
||||
private var std_dc_luminance_values:Array = [0,1,2,3,4,5,6,7,8,9,10,11];
|
||||
|
||||
private var std_ac_luminance_nrcodes:Array = [0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,125];
|
||||
|
||||
private var std_ac_luminance_values:Array = [1,2,3,0,4,17,5,18,33,49,65,6,19,81,97,7,34,113,20,50,129,145,161,8,35,66,177,193,21,82,209,240,36,51,98,114,130,9,10,22,23,24,25,26,37,38,39,40,41,42,52,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,225,226,227,228,229,230,231,232,233,234,241,242,243,244,245,246,247,248,249,250];
|
||||
|
||||
private var std_dc_chrominance_nrcodes:Array = [0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0];
|
||||
|
||||
private var std_dc_chrominance_values:Array = [0,1,2,3,4,5,6,7,8,9,10,11];
|
||||
|
||||
private var std_ac_chrominance_nrcodes:Array = [0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,119];
|
||||
|
||||
private var std_ac_chrominance_values:Array = [0,1,2,3,17,4,5,33,49,6,18,65,81,7,97,113,19,34,50,129,8,20,66,145,161,177,193,9,35,51,82,240,21,98,114,209,10,22,36,52,225,37,241,23,24,25,26,38,39,40,41,42,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,130,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,226,227,228,229,230,231,232,233,234,242,243,244,245,246,247,248,249,250];
|
||||
|
||||
private var YTable:Array = new Array(64);
|
||||
|
||||
private var UVTable:Array = new Array(64);
|
||||
|
||||
private var fdtbl_Y:Array = new Array(64);
|
||||
|
||||
private var fdtbl_UV:Array = new Array(64);
|
||||
|
||||
private var YDC_HT:Array;
|
||||
|
||||
private var UVDC_HT:Array;
|
||||
|
||||
private var YAC_HT:Array;
|
||||
|
||||
private var UVAC_HT:Array;
|
||||
|
||||
private var YDU:Array = new Array(64);
|
||||
|
||||
private var UDU:Array = new Array(64);
|
||||
|
||||
private var VDU:Array = new Array(64);
|
||||
|
||||
private var DU:Array = new Array(64);
|
||||
|
||||
private var bitcode:Array = new Array(65535);
|
||||
|
||||
private var category:Array = new Array(65535);
|
||||
|
||||
private var byteout:ByteArray;
|
||||
|
||||
private var bytenew:int = 0;
|
||||
|
||||
private var bytepos:int = 7;
|
||||
|
||||
private var DCY:Number = 0;
|
||||
|
||||
private var DCU:Number = 0;
|
||||
|
||||
private var DCV:Number = 0;
|
||||
|
||||
private var SrcWidth:int = 0;
|
||||
|
||||
private var SrcHeight:int = 0;
|
||||
|
||||
private var Source:Object = null;
|
||||
|
||||
private var TotalSize:int = 0;
|
||||
|
||||
private var PixelsPerIter:int = 128;
|
||||
|
||||
private var PercentageInc:int = 0;
|
||||
|
||||
private var NextProgressAt:int = 0;
|
||||
|
||||
private var CurrentTotalPos:int = 0;
|
||||
|
||||
private var Working:Boolean = false;
|
||||
|
||||
public function JpegAsynchEncoder()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function JPEGAsyncEncoder(quality:Number = 50) : void
|
||||
{
|
||||
if(quality <= 0)
|
||||
{
|
||||
quality = 1;
|
||||
}
|
||||
if(quality > 100)
|
||||
{
|
||||
quality = 100;
|
||||
}
|
||||
var sf:int = 0;
|
||||
if(quality < 50)
|
||||
{
|
||||
sf = int(5000 / quality);
|
||||
}
|
||||
else
|
||||
{
|
||||
sf = int(200 - quality * 2);
|
||||
}
|
||||
this.initHuffmanTbl();
|
||||
this.initCategoryNumber();
|
||||
this.initQuantTables(sf);
|
||||
}
|
||||
|
||||
public function get contentType() : String
|
||||
{
|
||||
return CONTENT_TYPE;
|
||||
}
|
||||
|
||||
public function get PixelsPerIteration() : int
|
||||
{
|
||||
return this.PixelsPerIter;
|
||||
}
|
||||
|
||||
public function set PixelsPerIteration(val:int) : void
|
||||
{
|
||||
this.PixelsPerIter = val;
|
||||
}
|
||||
|
||||
public function get ImageData() : ByteArray
|
||||
{
|
||||
return this.byteout;
|
||||
}
|
||||
|
||||
public function encodeByteArray(raw:ByteArray, width:int, height:int) : Boolean
|
||||
{
|
||||
return this.internalEncode(raw,width,height);
|
||||
}
|
||||
|
||||
public function encode(image:BitmapData) : Boolean
|
||||
{
|
||||
return this.internalEncode(image,image.width,image.height);
|
||||
}
|
||||
|
||||
private function internalEncode(newSource:Object, width:int, height:int) : Boolean
|
||||
{
|
||||
if(this.Working)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.Working = true;
|
||||
this.Source = newSource;
|
||||
this.SrcWidth = width;
|
||||
this.SrcHeight = height;
|
||||
this.TotalSize = width * height;
|
||||
this.PercentageInc = this.TotalSize / 100;
|
||||
this.NextProgressAt = this.PercentageInc;
|
||||
this.CurrentTotalPos = 0;
|
||||
setTimeout(this.StartEncode,10);
|
||||
return true;
|
||||
}
|
||||
|
||||
private function StartEncode() : void
|
||||
{
|
||||
this.byteout = new ByteArray();
|
||||
this.bytenew = 0;
|
||||
this.bytepos = 7;
|
||||
this.writeWord(65496);
|
||||
this.writeAPP0();
|
||||
this.writeDQT();
|
||||
this.writeSOF0(this.SrcWidth,this.SrcHeight);
|
||||
this.writeDHT();
|
||||
this.writeSOS();
|
||||
this.DCY = 0;
|
||||
this.DCV = 0;
|
||||
this.DCU = 0;
|
||||
this.bytenew = 0;
|
||||
this.bytepos = 7;
|
||||
this.dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS,false,false,0,this.TotalSize));
|
||||
setTimeout(this.AsyncLoop,10,0,0);
|
||||
}
|
||||
|
||||
private function AsyncLoop(xpos:int, ypos:int) : void
|
||||
{
|
||||
for(var i:int = 0; i < this.PixelsPerIter; i++)
|
||||
{
|
||||
this.RGB2YUV(this.Source,xpos,ypos,this.SrcWidth,this.SrcHeight);
|
||||
this.DCY = this.processDU(this.YDU,this.fdtbl_Y,this.DCY,this.YDC_HT,this.YAC_HT);
|
||||
this.DCU = this.processDU(this.UDU,this.fdtbl_UV,this.DCU,this.UVDC_HT,this.UVAC_HT);
|
||||
this.DCV = this.processDU(this.VDU,this.fdtbl_UV,this.DCV,this.UVDC_HT,this.UVAC_HT);
|
||||
xpos += 8;
|
||||
if(xpos >= this.SrcWidth)
|
||||
{
|
||||
xpos = 0;
|
||||
ypos += 8;
|
||||
}
|
||||
if(ypos >= this.SrcHeight)
|
||||
{
|
||||
setTimeout(this.FinishEncode,10);
|
||||
return;
|
||||
}
|
||||
this.CurrentTotalPos += 64;
|
||||
if(this.CurrentTotalPos >= this.NextProgressAt)
|
||||
{
|
||||
this.dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS,false,false,this.CurrentTotalPos,this.TotalSize));
|
||||
this.NextProgressAt += this.PercentageInc;
|
||||
}
|
||||
}
|
||||
setTimeout(this.AsyncLoop,10,xpos,ypos);
|
||||
}
|
||||
|
||||
private function FinishEncode() : void
|
||||
{
|
||||
var fillbits:BitString = null;
|
||||
if(this.bytepos >= 0)
|
||||
{
|
||||
fillbits = new BitString();
|
||||
fillbits.len = this.bytepos + 1;
|
||||
fillbits.val = (1 << this.bytepos + 1) - 1;
|
||||
this.writeBits(fillbits);
|
||||
}
|
||||
this.writeWord(65497);
|
||||
this.dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS,false,false,this.TotalSize,this.TotalSize));
|
||||
this.dispatchEvent(new JPEGAsyncCompleteEvent(this.byteout));
|
||||
this.Working = false;
|
||||
}
|
||||
|
||||
private function initQuantTables(sf:int) : void
|
||||
{
|
||||
var t:Number = NaN;
|
||||
var col:int = 0;
|
||||
var i:int = 0;
|
||||
var YQT:Array = [16,11,10,16,24,40,51,61,12,12,14,19,26,58,60,55,14,13,16,24,40,57,69,56,14,17,22,29,51,87,80,62,18,22,37,56,68,109,103,77,24,35,55,64,81,104,113,92,49,64,78,87,103,121,120,101,72,92,95,98,112,100,103,99];
|
||||
for(i = 0; i < 64; i++)
|
||||
{
|
||||
t = Math.floor((YQT[i] * sf + 50) / 100);
|
||||
if(t < 1)
|
||||
{
|
||||
t = 1;
|
||||
}
|
||||
else if(t > 255)
|
||||
{
|
||||
t = 255;
|
||||
}
|
||||
this.YTable[this.ZigZag[i]] = t;
|
||||
}
|
||||
var UVQT:Array = [17,18,24,47,99,99,99,99,18,21,26,66,99,99,99,99,24,26,56,99,99,99,99,99,47,66,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99];
|
||||
for(i = 0; i < 64; i++)
|
||||
{
|
||||
t = Math.floor((UVQT[i] * sf + 50) / 100);
|
||||
if(t < 1)
|
||||
{
|
||||
t = 1;
|
||||
}
|
||||
else if(t > 255)
|
||||
{
|
||||
t = 255;
|
||||
}
|
||||
this.UVTable[this.ZigZag[i]] = t;
|
||||
}
|
||||
var aasf:Array = [1,1.387039845,1.306562965,1.175875602,1,0.785694958,0.5411961,0.275899379];
|
||||
i = 0;
|
||||
for(var row:int = 0; row < 8; row++)
|
||||
{
|
||||
for(col = 0; col < 8; col++)
|
||||
{
|
||||
this.fdtbl_Y[i] = 1 / (this.YTable[this.ZigZag[i]] * aasf[row] * aasf[col] * 8);
|
||||
this.fdtbl_UV[i] = 1 / (this.UVTable[this.ZigZag[i]] * aasf[row] * aasf[col] * 8);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function computeHuffmanTbl(nrcodes:Array, std_table:Array) : Array
|
||||
{
|
||||
var j:int = 0;
|
||||
var codevalue:int = 0;
|
||||
var pos_in_table:int = 0;
|
||||
var HT:Array = new Array();
|
||||
for(var k:int = 1; k <= 16; k++)
|
||||
{
|
||||
for(j = 1; j <= nrcodes[k]; j++)
|
||||
{
|
||||
HT[std_table[pos_in_table]] = new BitString();
|
||||
HT[std_table[pos_in_table]].val = codevalue;
|
||||
HT[std_table[pos_in_table]].len = k;
|
||||
pos_in_table++;
|
||||
codevalue++;
|
||||
}
|
||||
codevalue *= 2;
|
||||
}
|
||||
return HT;
|
||||
}
|
||||
|
||||
private function initHuffmanTbl() : void
|
||||
{
|
||||
this.YDC_HT = this.computeHuffmanTbl(this.std_dc_luminance_nrcodes,this.std_dc_luminance_values);
|
||||
this.UVDC_HT = this.computeHuffmanTbl(this.std_dc_chrominance_nrcodes,this.std_dc_chrominance_values);
|
||||
this.YAC_HT = this.computeHuffmanTbl(this.std_ac_luminance_nrcodes,this.std_ac_luminance_values);
|
||||
this.UVAC_HT = this.computeHuffmanTbl(this.std_ac_chrominance_nrcodes,this.std_ac_chrominance_values);
|
||||
}
|
||||
|
||||
private function initCategoryNumber() : void
|
||||
{
|
||||
var nr:int = 0;
|
||||
var nrlower:int = 1;
|
||||
var nrupper:int = 2;
|
||||
for(var cat:int = 1; cat <= 15; cat++)
|
||||
{
|
||||
for(nr = nrlower; nr < nrupper; nr++)
|
||||
{
|
||||
this.category[32767 + nr] = cat;
|
||||
this.bitcode[32767 + nr] = new BitString();
|
||||
this.bitcode[32767 + nr].len = cat;
|
||||
this.bitcode[32767 + nr].val = nr;
|
||||
}
|
||||
for(nr = -(nrupper - 1); nr <= -nrlower; nr++)
|
||||
{
|
||||
this.category[32767 + nr] = cat;
|
||||
this.bitcode[32767 + nr] = new BitString();
|
||||
this.bitcode[32767 + nr].len = cat;
|
||||
this.bitcode[32767 + nr].val = nrupper - 1 + nr;
|
||||
}
|
||||
nrlower <<= 1;
|
||||
nrupper <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
private function writeBits(bs:BitString) : void
|
||||
{
|
||||
var value:int = bs.val;
|
||||
var posval:int = bs.len - 1;
|
||||
while(posval >= 0)
|
||||
{
|
||||
if(Boolean(value & uint(1 << posval)))
|
||||
{
|
||||
this.bytenew |= uint(1 << this.bytepos);
|
||||
}
|
||||
posval--;
|
||||
--this.bytepos;
|
||||
if(this.bytepos < 0)
|
||||
{
|
||||
if(this.bytenew == 255)
|
||||
{
|
||||
this.writeByte(255);
|
||||
this.writeByte(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.writeByte(this.bytenew);
|
||||
}
|
||||
this.bytepos = 7;
|
||||
this.bytenew = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function writeByte(value:int) : void
|
||||
{
|
||||
this.byteout.writeByte(value);
|
||||
}
|
||||
|
||||
private function writeWord(value:int) : void
|
||||
{
|
||||
this.writeByte(value >> 8 & 0xFF);
|
||||
this.writeByte(value & 0xFF);
|
||||
}
|
||||
|
||||
private function fDCTQuant(data:Array, fdtbl:Array) : Array
|
||||
{
|
||||
var i:int = 0;
|
||||
var tmp0:Number = NaN;
|
||||
var tmp7:Number = NaN;
|
||||
var tmp1:Number = NaN;
|
||||
var tmp6:Number = NaN;
|
||||
var tmp2:Number = NaN;
|
||||
var tmp5:Number = NaN;
|
||||
var tmp3:Number = NaN;
|
||||
var tmp4:Number = NaN;
|
||||
var tmp10:Number = NaN;
|
||||
var tmp13:Number = NaN;
|
||||
var tmp11:Number = NaN;
|
||||
var tmp12:Number = NaN;
|
||||
var z1:Number = NaN;
|
||||
var z5:Number = NaN;
|
||||
var z2:Number = NaN;
|
||||
var z4:Number = NaN;
|
||||
var z3:Number = NaN;
|
||||
var z11:Number = NaN;
|
||||
var z13:Number = NaN;
|
||||
var dataOff:int = 0;
|
||||
for(i = 0; i < 8; i++)
|
||||
{
|
||||
tmp0 = data[dataOff + 0] + data[dataOff + 7];
|
||||
tmp7 = data[dataOff + 0] - data[dataOff + 7];
|
||||
tmp1 = data[dataOff + 1] + data[dataOff + 6];
|
||||
tmp6 = data[dataOff + 1] - data[dataOff + 6];
|
||||
tmp2 = data[dataOff + 2] + data[dataOff + 5];
|
||||
tmp5 = data[dataOff + 2] - data[dataOff + 5];
|
||||
tmp3 = data[dataOff + 3] + data[dataOff + 4];
|
||||
tmp4 = data[dataOff + 3] - data[dataOff + 4];
|
||||
tmp10 = tmp0 + tmp3;
|
||||
tmp13 = tmp0 - tmp3;
|
||||
tmp11 = tmp1 + tmp2;
|
||||
tmp12 = tmp1 - tmp2;
|
||||
data[dataOff + 0] = tmp10 + tmp11;
|
||||
data[dataOff + 4] = tmp10 - tmp11;
|
||||
z1 = (tmp12 + tmp13) * 0.707106781;
|
||||
data[dataOff + 2] = tmp13 + z1;
|
||||
data[dataOff + 6] = tmp13 - z1;
|
||||
tmp10 = tmp4 + tmp5;
|
||||
tmp11 = tmp5 + tmp6;
|
||||
tmp12 = tmp6 + tmp7;
|
||||
z5 = (tmp10 - tmp12) * 0.382683433;
|
||||
z2 = 0.5411961 * tmp10 + z5;
|
||||
z4 = 1.306562965 * tmp12 + z5;
|
||||
z3 = tmp11 * 0.707106781;
|
||||
z11 = tmp7 + z3;
|
||||
z13 = tmp7 - z3;
|
||||
data[dataOff + 5] = z13 + z2;
|
||||
data[dataOff + 3] = z13 - z2;
|
||||
data[dataOff + 1] = z11 + z4;
|
||||
data[dataOff + 7] = z11 - z4;
|
||||
dataOff += 8;
|
||||
}
|
||||
dataOff = 0;
|
||||
for(i = 0; i < 8; i++)
|
||||
{
|
||||
tmp0 = data[dataOff + 0] + data[dataOff + 56];
|
||||
tmp7 = data[dataOff + 0] - data[dataOff + 56];
|
||||
tmp1 = data[dataOff + 8] + data[dataOff + 48];
|
||||
tmp6 = data[dataOff + 8] - data[dataOff + 48];
|
||||
tmp2 = data[dataOff + 16] + data[dataOff + 40];
|
||||
tmp5 = data[dataOff + 16] - data[dataOff + 40];
|
||||
tmp3 = data[dataOff + 24] + data[dataOff + 32];
|
||||
tmp4 = data[dataOff + 24] - data[dataOff + 32];
|
||||
tmp10 = tmp0 + tmp3;
|
||||
tmp13 = tmp0 - tmp3;
|
||||
tmp11 = tmp1 + tmp2;
|
||||
tmp12 = tmp1 - tmp2;
|
||||
data[dataOff + 0] = tmp10 + tmp11;
|
||||
data[dataOff + 32] = tmp10 - tmp11;
|
||||
z1 = (tmp12 + tmp13) * 0.707106781;
|
||||
data[dataOff + 16] = tmp13 + z1;
|
||||
data[dataOff + 48] = tmp13 - z1;
|
||||
tmp10 = tmp4 + tmp5;
|
||||
tmp11 = tmp5 + tmp6;
|
||||
tmp12 = tmp6 + tmp7;
|
||||
z5 = (tmp10 - tmp12) * 0.382683433;
|
||||
z2 = 0.5411961 * tmp10 + z5;
|
||||
z4 = 1.306562965 * tmp12 + z5;
|
||||
z3 = tmp11 * 0.707106781;
|
||||
z11 = tmp7 + z3;
|
||||
z13 = tmp7 - z3;
|
||||
data[dataOff + 40] = z13 + z2;
|
||||
data[dataOff + 24] = z13 - z2;
|
||||
data[dataOff + 8] = z11 + z4;
|
||||
data[dataOff + 56] = z11 - z4;
|
||||
dataOff++;
|
||||
}
|
||||
for(i = 0; i < 64; i++)
|
||||
{
|
||||
data[i] = Math.round(data[i] * fdtbl[i]);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private function writeAPP0() : void
|
||||
{
|
||||
this.writeWord(65504);
|
||||
this.writeWord(16);
|
||||
this.writeByte(74);
|
||||
this.writeByte(70);
|
||||
this.writeByte(73);
|
||||
this.writeByte(70);
|
||||
this.writeByte(0);
|
||||
this.writeByte(1);
|
||||
this.writeByte(1);
|
||||
this.writeByte(0);
|
||||
this.writeWord(1);
|
||||
this.writeWord(1);
|
||||
this.writeByte(0);
|
||||
this.writeByte(0);
|
||||
}
|
||||
|
||||
private function writeSOF0(width:int, height:int) : void
|
||||
{
|
||||
this.writeWord(65472);
|
||||
this.writeWord(17);
|
||||
this.writeByte(8);
|
||||
this.writeWord(height);
|
||||
this.writeWord(width);
|
||||
this.writeByte(3);
|
||||
this.writeByte(1);
|
||||
this.writeByte(17);
|
||||
this.writeByte(0);
|
||||
this.writeByte(2);
|
||||
this.writeByte(17);
|
||||
this.writeByte(1);
|
||||
this.writeByte(3);
|
||||
this.writeByte(17);
|
||||
this.writeByte(1);
|
||||
}
|
||||
|
||||
private function writeDQT() : void
|
||||
{
|
||||
var i:int = 0;
|
||||
this.writeWord(65499);
|
||||
this.writeWord(132);
|
||||
this.writeByte(0);
|
||||
for(i = 0; i < 64; i++)
|
||||
{
|
||||
this.writeByte(this.YTable[i]);
|
||||
}
|
||||
this.writeByte(1);
|
||||
for(i = 0; i < 64; i++)
|
||||
{
|
||||
this.writeByte(this.UVTable[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private function writeDHT() : void
|
||||
{
|
||||
var i:int = 0;
|
||||
this.writeWord(65476);
|
||||
this.writeWord(418);
|
||||
this.writeByte(0);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
this.writeByte(this.std_dc_luminance_nrcodes[i + 1]);
|
||||
}
|
||||
for(i = 0; i <= 11; i++)
|
||||
{
|
||||
this.writeByte(this.std_dc_luminance_values[i]);
|
||||
}
|
||||
this.writeByte(16);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
this.writeByte(this.std_ac_luminance_nrcodes[i + 1]);
|
||||
}
|
||||
for(i = 0; i <= 161; i++)
|
||||
{
|
||||
this.writeByte(this.std_ac_luminance_values[i]);
|
||||
}
|
||||
this.writeByte(1);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
this.writeByte(this.std_dc_chrominance_nrcodes[i + 1]);
|
||||
}
|
||||
for(i = 0; i <= 11; i++)
|
||||
{
|
||||
this.writeByte(this.std_dc_chrominance_values[i]);
|
||||
}
|
||||
this.writeByte(17);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
this.writeByte(this.std_ac_chrominance_nrcodes[i + 1]);
|
||||
}
|
||||
for(i = 0; i <= 161; i++)
|
||||
{
|
||||
this.writeByte(this.std_ac_chrominance_values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private function writeSOS() : void
|
||||
{
|
||||
this.writeWord(65498);
|
||||
this.writeWord(12);
|
||||
this.writeByte(3);
|
||||
this.writeByte(1);
|
||||
this.writeByte(0);
|
||||
this.writeByte(2);
|
||||
this.writeByte(17);
|
||||
this.writeByte(3);
|
||||
this.writeByte(17);
|
||||
this.writeByte(0);
|
||||
this.writeByte(63);
|
||||
this.writeByte(0);
|
||||
}
|
||||
|
||||
private function processDU(CDU:Array, fdtbl:Array, DC:Number, HTDC:Array, HTAC:Array) : Number
|
||||
{
|
||||
var i:int = 0;
|
||||
var startpos:int = 0;
|
||||
var nrzeroes:int = 0;
|
||||
var nrmarker:int = 0;
|
||||
var EOB:BitString = HTAC[0];
|
||||
var M16zeroes:BitString = HTAC[240];
|
||||
var DU_DCT:Array = this.fDCTQuant(CDU,fdtbl);
|
||||
for(i = 0; i < 64; i++)
|
||||
{
|
||||
this.DU[this.ZigZag[i]] = DU_DCT[i];
|
||||
}
|
||||
var Diff:int = this.DU[0] - DC;
|
||||
DC = Number(this.DU[0]);
|
||||
if(Diff == 0)
|
||||
{
|
||||
this.writeBits(HTDC[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.writeBits(HTDC[this.category[32767 + Diff]]);
|
||||
this.writeBits(this.bitcode[32767 + Diff]);
|
||||
}
|
||||
var end0pos:int = 63;
|
||||
while(end0pos > 0 && this.DU[end0pos] == 0)
|
||||
{
|
||||
end0pos--;
|
||||
}
|
||||
if(end0pos == 0)
|
||||
{
|
||||
this.writeBits(EOB);
|
||||
return DC;
|
||||
}
|
||||
i = 1;
|
||||
while(i <= end0pos)
|
||||
{
|
||||
startpos = i;
|
||||
while(this.DU[i] == 0 && i <= end0pos)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
nrzeroes = i - startpos;
|
||||
if(nrzeroes >= 16)
|
||||
{
|
||||
for(nrmarker = 1; nrmarker <= nrzeroes / 16; nrmarker++)
|
||||
{
|
||||
this.writeBits(M16zeroes);
|
||||
}
|
||||
nrzeroes = int(nrzeroes & 0x0F);
|
||||
}
|
||||
this.writeBits(HTAC[nrzeroes * 16 + this.category[32767 + this.DU[i]]]);
|
||||
this.writeBits(this.bitcode[32767 + this.DU[i]]);
|
||||
i++;
|
||||
}
|
||||
if(end0pos != 63)
|
||||
{
|
||||
this.writeBits(EOB);
|
||||
}
|
||||
return DC;
|
||||
}
|
||||
|
||||
private function RGB2YUV(source:Object, xpos:int, ypos:int, width:int = 0, height:int = 0) : void
|
||||
{
|
||||
var x:int = 0;
|
||||
var P:uint = 0;
|
||||
var R:Number = NaN;
|
||||
var G:Number = NaN;
|
||||
var B:Number = NaN;
|
||||
var pos:int = 0;
|
||||
for(var y:int = 0; y < 8; y++)
|
||||
{
|
||||
for(x = 0; x < 8; x++)
|
||||
{
|
||||
P = this.getPixel32(source,xpos + x,ypos + y,width,height);
|
||||
R = Number(P >> 16 & 0xFF);
|
||||
G = Number(P >> 8 & 0xFF);
|
||||
B = Number(P & 0xFF);
|
||||
this.YDU[pos] = 0.299 * R + 0.587 * G + 0.114 * B - 128;
|
||||
this.UDU[pos] = -0.16874 * R + -0.33126 * G + 0.5 * B;
|
||||
this.VDU[pos] = 0.5 * R + -0.41869 * G + -0.08131 * B;
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPixel32(source:Object, x:int, y:int, width:int = 0, height:int = 0) : uint
|
||||
{
|
||||
var bitmap:BitmapData = null;
|
||||
var byteArray:ByteArray = null;
|
||||
if(source is BitmapData)
|
||||
{
|
||||
bitmap = source as BitmapData;
|
||||
return bitmap.getPixel32(x,y);
|
||||
}
|
||||
if(source is ByteArray)
|
||||
{
|
||||
byteArray = source as ByteArray;
|
||||
byteArray.position = y * width * 4 + x * 4;
|
||||
return byteArray.readUnsignedInt();
|
||||
}
|
||||
throw new ArgumentError("The source argument must be an instance of flash.display.BitmapData or flash.utils.ByteArray.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BitString
|
||||
{
|
||||
|
||||
public var len:int = 0;
|
||||
|
||||
public var val:int = 0;
|
||||
|
||||
public function BitString()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,736 @@
|
||||
package com.sbi.graphics
|
||||
{
|
||||
import com.sbi.loader.ImageServerEvent;
|
||||
import com.sbi.loader.ImageServerURL;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.geom.Matrix;
|
||||
import flash.geom.Point;
|
||||
import flash.geom.Rectangle;
|
||||
|
||||
public class LayerAnim
|
||||
{
|
||||
|
||||
private static var _activePool:Array;
|
||||
|
||||
private static var _freePool:Array;
|
||||
|
||||
private static var _avOffsets:Array;
|
||||
|
||||
private static var _lastEntry:int;
|
||||
|
||||
private static var _useMaxThrottle:Function;
|
||||
|
||||
public static const PLAY_LOOP:int = 0;
|
||||
|
||||
public static const PLAY_ONE_SHOT:int = 1;
|
||||
|
||||
public static const PLAY_LOOP__KEEP_CURRENT_FRAME:int = 2;
|
||||
|
||||
public static const AN_SIT_NNE:int = 1;
|
||||
|
||||
public static const AN_SIT_NE:int = 2;
|
||||
|
||||
public static const AN_SIT_E:int = 3;
|
||||
|
||||
public static const AN_SIT_SE:int = 4;
|
||||
|
||||
public static const AN_SIT_SSE:int = 5;
|
||||
|
||||
public static const AN_MOVE_NNE:int = 7;
|
||||
|
||||
public static const AN_MOVE_NE:int = 8;
|
||||
|
||||
public static const AN_MOVE_E:int = 9;
|
||||
|
||||
public static const AN_MOVE_SE:int = 10;
|
||||
|
||||
public static const AN_MOVE_SSE:int = 11;
|
||||
|
||||
public static const AN_BBCARD:int = 13;
|
||||
|
||||
public static const AN_IDLE_SE:int = 14;
|
||||
|
||||
public static const AN_HUD_AVT:int = 15;
|
||||
|
||||
public static const AN_IDLE_NE:int = 16;
|
||||
|
||||
public static const AN_HOP:int = 17;
|
||||
|
||||
public static const AN_SLEEP:int = 22;
|
||||
|
||||
public static const AN_DANCE:int = 23;
|
||||
|
||||
public static const AN_PLAY:int = 6;
|
||||
|
||||
public static const AN_SWIM_N:int = 36;
|
||||
|
||||
public static const AN_SWIM_NE:int = 34;
|
||||
|
||||
public static const AN_SWIM_E:int = 29;
|
||||
|
||||
public static const AN_SWIM_SE:int = 35;
|
||||
|
||||
public static const AN_SWIM_S:int = 37;
|
||||
|
||||
public static const AN_FLOAT:int = 32;
|
||||
|
||||
public static const AN_WATER_DIVE:int = 41;
|
||||
|
||||
public static const AN_WATER_PLAY:int = 39;
|
||||
|
||||
public static const AN_WATER_SPIN:int = 33;
|
||||
|
||||
public static const AN_WATER_JIG:int = 38;
|
||||
|
||||
public static const AN_WATER_POSE:int = 40;
|
||||
|
||||
public static const AN_PHOTO:int = 42;
|
||||
|
||||
public static const AN_PARACHUTE_IDLE:int = 19;
|
||||
|
||||
public static const AN_PARACHUTE_JUMP:int = 24;
|
||||
|
||||
public static const AN_PARACHUTE_DISTRESS:int = 20;
|
||||
|
||||
public static const AN_PARACHUTE_LAND:int = 21;
|
||||
|
||||
public static const AN_WINDRIDER_JUMP:int = 28;
|
||||
|
||||
public static const AN_WINDRIDER_IDLE:int = 29;
|
||||
|
||||
public static const AN_WINDRIDER_FALL:int = 30;
|
||||
|
||||
public static const AN_WINDRIDER_START:int = 31;
|
||||
|
||||
public static const AN_WINDRIDER_DISTRESS:int = 20;
|
||||
|
||||
public static const AVATAR_BITMAP_OFFSET_X:int = 375;
|
||||
|
||||
public static const AVATAR_BITMAP_OFFSET_Y:int = 365;
|
||||
|
||||
private static var _throttle:int = 8;
|
||||
|
||||
private var _bitmap:LayerBitmap;
|
||||
|
||||
private var _avDefId:int;
|
||||
|
||||
private var _animId:int;
|
||||
|
||||
private var _frame:int;
|
||||
|
||||
private var _hFlip:Boolean;
|
||||
|
||||
private var _totalFrames:int;
|
||||
|
||||
private var _x:int;
|
||||
|
||||
private var _y:int;
|
||||
|
||||
private var _rotation:int;
|
||||
|
||||
private var _xOff:int;
|
||||
|
||||
private var _yOff:int;
|
||||
|
||||
private var _bPause:Boolean;
|
||||
|
||||
private var _layers:Array;
|
||||
|
||||
private var _colors:Array;
|
||||
|
||||
private var _callback:Function;
|
||||
|
||||
private var _mode:int;
|
||||
|
||||
private var _tStep:int;
|
||||
|
||||
private var _bRedraw:Boolean;
|
||||
|
||||
private var _bReload:Boolean;
|
||||
|
||||
private var _bBaseLayer:Boolean;
|
||||
|
||||
private var _avatarEnabled:Boolean = true;
|
||||
|
||||
private var _bNewAnim:Boolean;
|
||||
|
||||
private var _requestAnimId:int;
|
||||
|
||||
private var _receivedData:Array;
|
||||
|
||||
private var _requestedIds:Array;
|
||||
|
||||
private var _requestCallback:Function;
|
||||
|
||||
private var _requestMode:int;
|
||||
|
||||
private var _preloadRequestedIds:Array;
|
||||
|
||||
private var _preloadCallback:Function;
|
||||
|
||||
private var _bounceEnabled:Boolean;
|
||||
|
||||
public function LayerAnim(lock:Class)
|
||||
{
|
||||
super();
|
||||
if(lock != SingletonLock)
|
||||
{
|
||||
throw new Error("Invalid access. Use LayerAnim.getNew");
|
||||
}
|
||||
this._requestedIds = new Array();
|
||||
this._colors = new Array();
|
||||
}
|
||||
|
||||
public static function set avOffsets(a:Array) : void
|
||||
{
|
||||
_avOffsets = a;
|
||||
}
|
||||
|
||||
public static function getAvOffset(avDefId:int) : Point
|
||||
{
|
||||
if(Boolean(_avOffsets[avDefId]))
|
||||
{
|
||||
return _avOffsets[avDefId];
|
||||
}
|
||||
return new Point(-100,-100);
|
||||
}
|
||||
|
||||
public static function set throttle(t:int) : void
|
||||
{
|
||||
_throttle = t;
|
||||
}
|
||||
|
||||
public static function getNew() : LayerAnim
|
||||
{
|
||||
var an:LayerAnim = null;
|
||||
if(!_activePool)
|
||||
{
|
||||
_activePool = new Array();
|
||||
_freePool = new Array();
|
||||
}
|
||||
if(Boolean(_freePool.length))
|
||||
{
|
||||
an = _freePool.pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
an = new LayerAnim(SingletonLock);
|
||||
}
|
||||
_activePool.push(an);
|
||||
an.init();
|
||||
return an;
|
||||
}
|
||||
|
||||
public static function destroy(an:LayerAnim) : void
|
||||
{
|
||||
var i:int = _activePool.indexOf(an);
|
||||
if(i >= 0)
|
||||
{
|
||||
_activePool.splice(i,1);
|
||||
an.destroy();
|
||||
_freePool.push(an);
|
||||
}
|
||||
}
|
||||
|
||||
public static function heartbeat() : void
|
||||
{
|
||||
var total:int = 0;
|
||||
var countdown:int = 0;
|
||||
var throttle:int = 0;
|
||||
var i:int = 0;
|
||||
var la:LayerAnim = null;
|
||||
var tStep:int = 0;
|
||||
if(Boolean(_activePool) && Boolean(_activePool.length))
|
||||
{
|
||||
total = int(_activePool.length);
|
||||
countdown = total;
|
||||
throttle = total * 0.5;
|
||||
if(throttle < 1 || Boolean(_useMaxThrottle) && Boolean(_useMaxThrottle()))
|
||||
{
|
||||
throttle = 1;
|
||||
}
|
||||
if(throttle > _throttle)
|
||||
{
|
||||
throttle = _throttle;
|
||||
}
|
||||
i = _lastEntry;
|
||||
for each(la in _activePool)
|
||||
{
|
||||
++la._tStep;
|
||||
}
|
||||
while(throttle > 0 && countdown > 0)
|
||||
{
|
||||
if(i >= total)
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
la = _activePool[i++];
|
||||
tStep = la._tStep;
|
||||
if(tStep >= 2)
|
||||
{
|
||||
if((la._requestMode == PLAY_ONE_SHOT || isOnscreen(la)) && la.heartbeat())
|
||||
{
|
||||
la._tStep = 0;
|
||||
throttle--;
|
||||
}
|
||||
}
|
||||
countdown--;
|
||||
}
|
||||
_lastEntry = i;
|
||||
}
|
||||
}
|
||||
|
||||
private static function isOnscreen(la:LayerAnim) : Boolean
|
||||
{
|
||||
var left1:int = 0;
|
||||
var right1:int = 0;
|
||||
var top1:int = 0;
|
||||
var bottom1:int = 0;
|
||||
var rect:Rectangle = null;
|
||||
var theParent:DisplayObjectContainer = la.bitmap.parent;
|
||||
if(Boolean(theParent))
|
||||
{
|
||||
left1 = 0;
|
||||
right1 = 900;
|
||||
top1 = 0;
|
||||
bottom1 = 550;
|
||||
rect = theParent.getBounds(gMainFrame.stage);
|
||||
return rect.height == 0 || !(bottom1 < rect.top || top1 > rect.bottom || right1 < rect.left || left1 > rect.right);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function set useMaxThrottle(func:Function) : void
|
||||
{
|
||||
_useMaxThrottle = func;
|
||||
}
|
||||
|
||||
public function get bounceEnabled() : Boolean
|
||||
{
|
||||
return this._bounceEnabled;
|
||||
}
|
||||
|
||||
public function set bounceEnabled(b:Boolean) : void
|
||||
{
|
||||
this._bounceEnabled = b;
|
||||
}
|
||||
|
||||
private function init() : void
|
||||
{
|
||||
this._bitmap = new LayerBitmap();
|
||||
this._layers = null;
|
||||
this._requestAnimId = -1;
|
||||
this._avDefId = -1;
|
||||
this._animId = -1;
|
||||
this._bNewAnim = false;
|
||||
this._totalFrames = 0;
|
||||
this._bReload = true;
|
||||
this._tStep = 1;
|
||||
this._bounceEnabled = false;
|
||||
}
|
||||
|
||||
private function destroy() : void
|
||||
{
|
||||
this._bitmap = null;
|
||||
this._layers = null;
|
||||
if(this._requestedIds.length != 0)
|
||||
{
|
||||
ImageServerURL.instance.removeEventListener(ImageServerEvent.ON_NEW_DATA,this.onReceiveData);
|
||||
this._requestedIds.splice(0,this._requestedIds.length);
|
||||
}
|
||||
}
|
||||
|
||||
public function set avDefId(i:int) : void
|
||||
{
|
||||
if(i != this._avDefId)
|
||||
{
|
||||
this._avDefId = i;
|
||||
this._xOff = -getAvOffset(this._avDefId).x - AVATAR_BITMAP_OFFSET_X;
|
||||
this._yOff = -getAvOffset(this._avDefId).y - AVATAR_BITMAP_OFFSET_Y;
|
||||
this._bReload = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function get layers() : Array
|
||||
{
|
||||
return this._layers;
|
||||
}
|
||||
|
||||
public function get avDefId() : int
|
||||
{
|
||||
return this._avDefId;
|
||||
}
|
||||
|
||||
public function get animId() : int
|
||||
{
|
||||
return this._animId;
|
||||
}
|
||||
|
||||
public function get hFlip() : Boolean
|
||||
{
|
||||
return this._hFlip;
|
||||
}
|
||||
|
||||
public function get frame() : int
|
||||
{
|
||||
return this._frame;
|
||||
}
|
||||
|
||||
public function set frame(f:int) : void
|
||||
{
|
||||
this._frame = f;
|
||||
}
|
||||
|
||||
public function set avatarEnabled(b:Boolean) : void
|
||||
{
|
||||
this._avatarEnabled = b;
|
||||
}
|
||||
|
||||
public function set layers(l:Array) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var o:Object = null;
|
||||
var layerIndex:int = 0;
|
||||
var bDiffLayer:Boolean = true;
|
||||
var bDiffColor:Boolean = false;
|
||||
if(Boolean(this._layers) && this._layers.length == l.length)
|
||||
{
|
||||
bDiffLayer = false;
|
||||
for(i = 0; i < l.length; i++)
|
||||
{
|
||||
if(this._layers[i].l != l[i].l)
|
||||
{
|
||||
bDiffLayer = true;
|
||||
break;
|
||||
}
|
||||
if(this._layers[i].c != l[i].c)
|
||||
{
|
||||
bDiffColor = true;
|
||||
}
|
||||
}
|
||||
if(!bDiffLayer && !bDiffColor)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(l.length > 0)
|
||||
{
|
||||
this._layers = l;
|
||||
if(bDiffLayer)
|
||||
{
|
||||
this._bReload = true;
|
||||
}
|
||||
else if(bDiffColor)
|
||||
{
|
||||
for each(o in l)
|
||||
{
|
||||
layerIndex = ImageServerURL.instance.getLayerIndex(o.l);
|
||||
this._bitmap.setLayerColor(layerIndex,o.c);
|
||||
}
|
||||
this._bRedraw = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get x() : int
|
||||
{
|
||||
return this._x;
|
||||
}
|
||||
|
||||
public function get y() : int
|
||||
{
|
||||
return this._y;
|
||||
}
|
||||
|
||||
public function set x(x:int) : void
|
||||
{
|
||||
this._x = x;
|
||||
}
|
||||
|
||||
public function set y(y:int) : void
|
||||
{
|
||||
this._y = y;
|
||||
}
|
||||
|
||||
public function set alpha(a:Number) : void
|
||||
{
|
||||
this._bitmap.alpha = a;
|
||||
}
|
||||
|
||||
public function set rotation(deg:Number) : void
|
||||
{
|
||||
this._rotation = deg;
|
||||
}
|
||||
|
||||
public function set hFlip(f:Boolean) : void
|
||||
{
|
||||
if(f != this._hFlip)
|
||||
{
|
||||
this._hFlip = f;
|
||||
this._bRedraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function set visible(f:Boolean) : void
|
||||
{
|
||||
this._bitmap.visible = f;
|
||||
}
|
||||
|
||||
public function get visible() : Boolean
|
||||
{
|
||||
return this._bitmap.visible;
|
||||
}
|
||||
|
||||
public function set pause(p:Boolean) : void
|
||||
{
|
||||
this._bPause = p;
|
||||
}
|
||||
|
||||
public function get bitmap() : LayerBitmap
|
||||
{
|
||||
return this._bitmap;
|
||||
}
|
||||
|
||||
public function playAnim(animId:int, mode:int = 0, callback:Function = null) : void
|
||||
{
|
||||
if(this._requestAnimId == -1 && animId != this._animId || this._requestAnimId != animId)
|
||||
{
|
||||
this._requestCallback = callback;
|
||||
this._requestMode = mode;
|
||||
this._requestAnimId = animId;
|
||||
this._bReload = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function preload(animList:Array, callback:Function) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
this._preloadCallback = callback;
|
||||
for(this._preloadRequestedIds = []; i < animList.length; )
|
||||
{
|
||||
this.buildRequestArray(animList[i],this._preloadRequestedIds,null);
|
||||
i++;
|
||||
}
|
||||
ImageServerURL.instance.addEventListener(ImageServerEvent.ON_NEW_DATA,this.onReceiveData);
|
||||
ImageServerURL.instance.requestImages(this._preloadRequestedIds.slice());
|
||||
}
|
||||
|
||||
private function heartbeat() : Boolean
|
||||
{
|
||||
var bounceHeight:int = 0;
|
||||
var bPainted:Boolean = false;
|
||||
if(this._bReload)
|
||||
{
|
||||
this.loadAnim();
|
||||
}
|
||||
if(this._totalFrames == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(this._frame >= this._totalFrames)
|
||||
{
|
||||
if(this._mode == PLAY_ONE_SHOT)
|
||||
{
|
||||
this._frame = this._totalFrames > 0 ? int(this._totalFrames - 1) : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._frame = 0;
|
||||
}
|
||||
if(this._callback != null)
|
||||
{
|
||||
this._callback(this,this._animId);
|
||||
if(this._mode == PLAY_ONE_SHOT)
|
||||
{
|
||||
this._callback = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this._bRedraw)
|
||||
{
|
||||
this._bitmap.invalidate();
|
||||
this._bRedraw = false;
|
||||
}
|
||||
if(this._avatarEnabled)
|
||||
{
|
||||
bPainted = this._bitmap.paint(this._frame,this._hFlip);
|
||||
}
|
||||
var offSet:int = 0;
|
||||
if(this._bounceEnabled)
|
||||
{
|
||||
bounceHeight = 150;
|
||||
offSet = bounceHeight * (this._frame + 1) / this._totalFrames;
|
||||
if(offSet > bounceHeight / 2)
|
||||
{
|
||||
offSet = bounceHeight - offSet;
|
||||
}
|
||||
}
|
||||
this.updateBitmapPos(offSet);
|
||||
if(!this._bPause)
|
||||
{
|
||||
++this._frame;
|
||||
}
|
||||
return bPainted;
|
||||
}
|
||||
|
||||
private function loadAnim() : void
|
||||
{
|
||||
var anId:int = 0;
|
||||
if(this._layers != null && this._layers.length > 0)
|
||||
{
|
||||
anId = this._requestAnimId != -1 ? this._requestAnimId : this._animId;
|
||||
if(anId >= 0)
|
||||
{
|
||||
this._requestAnimId = anId;
|
||||
this.requestAnim(anId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function updateBitmapPos(offSet:int) : void
|
||||
{
|
||||
var m:Matrix = null;
|
||||
var ap:Point = this._bitmap.anchorPoint;
|
||||
var x:int = this._x + ap.x + this._xOff;
|
||||
var y:int = this._y + ap.y + this._yOff - offSet;
|
||||
if(Boolean(this._rotation))
|
||||
{
|
||||
m = this._bitmap.transform.matrix;
|
||||
m.identity();
|
||||
m.translate(ap.x + this._xOff,ap.y + this._yOff);
|
||||
m.rotate(this._rotation * (Math.PI / 180));
|
||||
m.translate(x,y);
|
||||
this._bitmap.transform.matrix = m;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(this._bitmap.rotation != this._rotation)
|
||||
{
|
||||
this._bitmap.rotation = this._rotation;
|
||||
}
|
||||
this._bitmap.x = x;
|
||||
this._bitmap.y = y;
|
||||
}
|
||||
}
|
||||
|
||||
private function requestAnim(id:int) : void
|
||||
{
|
||||
this._bNewAnim = false;
|
||||
this._requestedIds.splice(0,this._requestedIds.length);
|
||||
this._colors = [];
|
||||
this._receivedData = [];
|
||||
this.buildRequestArray(id,this._requestedIds,this._colors);
|
||||
ImageServerURL.instance.addEventListener(ImageServerEvent.ON_NEW_DATA,this.onReceiveData);
|
||||
ImageServerURL.instance.requestImages(this._requestedIds.slice());
|
||||
this._bReload = false;
|
||||
this._bBaseLayer = false;
|
||||
}
|
||||
|
||||
private function buildRequestArray(id:int, a:Array, colors:Array) : void
|
||||
{
|
||||
var o:Object = null;
|
||||
var packId:uint = 0;
|
||||
a.push(ImageArrayHelper.packId(this._avDefId,id,0));
|
||||
for each(o in this._layers)
|
||||
{
|
||||
packId = ImageArrayHelper.packId(this._avDefId,id,o.l);
|
||||
a.push(packId);
|
||||
if(Boolean(colors))
|
||||
{
|
||||
colors[packId] = o.c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function onReceiveData(e:ImageServerEvent) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var color:uint = 0;
|
||||
var o:Object = null;
|
||||
var layer:int = e.layer;
|
||||
if(Boolean(this._preloadRequestedIds) && Boolean(this._preloadRequestedIds.length))
|
||||
{
|
||||
i = this._preloadRequestedIds.indexOf(e.id);
|
||||
if(i >= 0)
|
||||
{
|
||||
this._preloadRequestedIds.splice(i,1);
|
||||
if(this._preloadRequestedIds.length == 0)
|
||||
{
|
||||
this._preloadRequestedIds = null;
|
||||
if(this._requestedIds.length == 0)
|
||||
{
|
||||
ImageServerURL.instance.removeEventListener(ImageServerEvent.ON_NEW_DATA,this.onReceiveData);
|
||||
}
|
||||
if(this._preloadCallback != null)
|
||||
{
|
||||
this._preloadCallback(this);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
i = this._requestedIds.indexOf(e.id);
|
||||
if(i >= 0)
|
||||
{
|
||||
this._requestedIds.splice(i,1);
|
||||
if(layer > 0)
|
||||
{
|
||||
color = uint(this._colors[e.id]);
|
||||
}
|
||||
if(e.success)
|
||||
{
|
||||
this._receivedData.push({
|
||||
"l":layer,
|
||||
"d":e.imageData,
|
||||
"c":color
|
||||
});
|
||||
}
|
||||
if(this._requestedIds.length == 0)
|
||||
{
|
||||
this._bNewAnim = true;
|
||||
if(this._preloadRequestedIds == null)
|
||||
{
|
||||
ImageServerURL.instance.removeEventListener(ImageServerEvent.ON_NEW_DATA,this.onReceiveData);
|
||||
}
|
||||
}
|
||||
if(layer == 1 || this._bNewAnim)
|
||||
{
|
||||
this._bBaseLayer = true;
|
||||
if(this._mode == LayerAnim.PLAY_LOOP__KEEP_CURRENT_FRAME)
|
||||
{
|
||||
this._mode == LayerAnim.PLAY_LOOP;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._frame = 0;
|
||||
}
|
||||
if(this._requestAnimId >= 0)
|
||||
{
|
||||
this._animId = this._requestAnimId;
|
||||
}
|
||||
this._callback = this._requestCallback;
|
||||
this._mode = this._requestMode;
|
||||
this._requestAnimId = -1;
|
||||
this._bitmap.release();
|
||||
}
|
||||
if(this._bBaseLayer)
|
||||
{
|
||||
for each(o in this._receivedData)
|
||||
{
|
||||
this._bitmap.setLayer(o.l,o.d,o.c);
|
||||
}
|
||||
this._totalFrames = this._bitmap.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SingletonLock
|
||||
{
|
||||
|
||||
public function SingletonLock()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,646 @@
|
||||
package com.sbi.graphics
|
||||
{
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.BitmapData;
|
||||
import flash.geom.Point;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class LayerBitmap extends Bitmap
|
||||
{
|
||||
|
||||
private const _backgroundColor:uint = 0;
|
||||
|
||||
private var _anchorPoint:Point;
|
||||
|
||||
private var _layers:Array;
|
||||
|
||||
private var _bmin:Point;
|
||||
|
||||
private var _bmax:Point;
|
||||
|
||||
private var _lastFrame:int;
|
||||
|
||||
private var _lastHFlip:Boolean;
|
||||
|
||||
private var _blendColor:uint;
|
||||
|
||||
private var _bColorChanged:Boolean;
|
||||
|
||||
public function LayerBitmap()
|
||||
{
|
||||
super();
|
||||
this._layers = new Array();
|
||||
this._anchorPoint = new Point();
|
||||
this._bmin = new Point();
|
||||
this._bmax = new Point();
|
||||
}
|
||||
|
||||
public function get length() : int
|
||||
{
|
||||
var o:Object = this._layers[0];
|
||||
if(!o)
|
||||
{
|
||||
o = this._layers[1];
|
||||
}
|
||||
if(!o)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return o.o.f.length;
|
||||
}
|
||||
|
||||
public function release() : void
|
||||
{
|
||||
this._layers.splice(0,this._layers.length);
|
||||
this._lastFrame = -1;
|
||||
this._bColorChanged = false;
|
||||
}
|
||||
|
||||
public function invalidate() : void
|
||||
{
|
||||
this._lastFrame = -1;
|
||||
}
|
||||
|
||||
public function setLayer(layer:int, o:Object, color:uint) : void
|
||||
{
|
||||
if(layer < 0 || layer > 10)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(Boolean(o))
|
||||
{
|
||||
if(this._layers[layer] == null)
|
||||
{
|
||||
this._layers[layer] = {
|
||||
"c":-1,
|
||||
"lastColor":-1,
|
||||
"blendColor":0
|
||||
};
|
||||
}
|
||||
this._layers[layer].o = o;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._layers[layer] = null;
|
||||
}
|
||||
this.setLayerColor(layer,color);
|
||||
this._lastFrame = -1;
|
||||
}
|
||||
|
||||
public function setLayerColor(layer:int, c:uint) : void
|
||||
{
|
||||
var o:Object = this._layers[layer];
|
||||
if(Boolean(o) && c != o.c)
|
||||
{
|
||||
o.c = c;
|
||||
this._bColorChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function setBlendColor(argb:uint) : void
|
||||
{
|
||||
if(this._blendColor != argb)
|
||||
{
|
||||
this._blendColor = argb;
|
||||
this._bColorChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function get anchorPoint() : Point
|
||||
{
|
||||
return this._anchorPoint;
|
||||
}
|
||||
|
||||
private function refreshLayerPalette(i:int) : void
|
||||
{
|
||||
var c:uint = 0;
|
||||
var gp:Array = null;
|
||||
var c1:int = 0;
|
||||
var c2:int = 0;
|
||||
var c3:int = 0;
|
||||
var c4:int = 0;
|
||||
var a:int = 0;
|
||||
var o:Object = this._layers[i];
|
||||
if(Boolean(o) && (o.lastColor != o.c || o.blendColor != this._blendColor))
|
||||
{
|
||||
c = uint(o.c);
|
||||
gp = PaletteHelper.gamePalette;
|
||||
c1 = c >> 24 & 0xFF;
|
||||
c2 = c >> 16 & 0xFF;
|
||||
c3 = c >> 8 & 0xFF;
|
||||
c4 = c & 0xFF;
|
||||
if(!o.pal)
|
||||
{
|
||||
o.pal = [];
|
||||
}
|
||||
PaletteHelper.BuildAnimalPalette(o.pal,gp[c1],gp[c2],gp[c3],gp[c4]);
|
||||
a = this._blendColor >> 24 & 0xFF;
|
||||
if(i != 3)
|
||||
{
|
||||
if(a > 0)
|
||||
{
|
||||
PaletteHelper.adjustPaletteColor(o.pal,this._blendColor);
|
||||
}
|
||||
o.blendColor = this._blendColor;
|
||||
}
|
||||
o.lastColor = c;
|
||||
this._lastFrame = -1;
|
||||
}
|
||||
}
|
||||
|
||||
private function refreshAllPalettes() : void
|
||||
{
|
||||
for(var i:int = 1; i <= 10; i++)
|
||||
{
|
||||
this.refreshLayerPalette(i);
|
||||
}
|
||||
this._bColorChanged = false;
|
||||
}
|
||||
|
||||
private function calcBounds(index:int) : void
|
||||
{
|
||||
var obj:Object = null;
|
||||
var o:Object = null;
|
||||
var total:int = 0;
|
||||
var fo:Object = null;
|
||||
var xOff:int = 0;
|
||||
var yOff:int = 0;
|
||||
var w:int = 0;
|
||||
var h:int = 0;
|
||||
this._bmin.x = 1000;
|
||||
this._bmin.y = 1000;
|
||||
this._bmax.x = 0;
|
||||
this._bmax.y = 0;
|
||||
for(var i:int = 1; i < this._layers.length; i++)
|
||||
{
|
||||
obj = this._layers[i];
|
||||
if(obj != null)
|
||||
{
|
||||
o = obj.o;
|
||||
if(o.v != ImageArray.VERSION)
|
||||
{
|
||||
return;
|
||||
}
|
||||
total = int(o.f.length);
|
||||
if(index < total)
|
||||
{
|
||||
fo = o.f[index];
|
||||
if(fo)
|
||||
{
|
||||
xOff = int(fo.x);
|
||||
yOff = int(fo.y);
|
||||
w = int(fo.w);
|
||||
h = int(fo.h);
|
||||
if(xOff < this._bmin.x)
|
||||
{
|
||||
this._bmin.x = xOff;
|
||||
}
|
||||
if(yOff < this._bmin.y)
|
||||
{
|
||||
this._bmin.y = yOff;
|
||||
}
|
||||
if(xOff + w > this._bmax.x)
|
||||
{
|
||||
this._bmax.x = xOff + w;
|
||||
}
|
||||
if(yOff + h > this._bmax.y)
|
||||
{
|
||||
this._bmax.y = yOff + h;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this._bmin.x == 1000 || this._bmin.y == 1000)
|
||||
{
|
||||
if(Boolean(this.bitmapData))
|
||||
{
|
||||
trace("WARNING: making new empty 1x1 bitmap data (parent.name:" + parent.name + ") - is index:" + index + " valid?");
|
||||
this.bitmapData = new BitmapData(1,1,true,this._backgroundColor);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.resizeBitmap(1 + this._bmax.x - this._bmin.x,1 + this._bmax.y - this._bmin.y,true);
|
||||
this._anchorPoint.x = this._bmin.x;
|
||||
this._anchorPoint.y = this._bmin.y;
|
||||
}
|
||||
|
||||
public function paint(index:int, bHFlip:Boolean = false, bUseSeq:Boolean = true) : Boolean
|
||||
{
|
||||
var o:Object = null;
|
||||
var bRet:Boolean = false;
|
||||
var i:int = 0;
|
||||
if(bUseSeq && this._layers[0] != null)
|
||||
{
|
||||
o = this._layers[0];
|
||||
index = int(o.o.f[index]);
|
||||
}
|
||||
if(index != this._lastFrame || bHFlip != this._lastHFlip || this._bColorChanged)
|
||||
{
|
||||
if(this._bColorChanged)
|
||||
{
|
||||
this.refreshAllPalettes();
|
||||
}
|
||||
this._lastFrame = index;
|
||||
this._lastHFlip = bHFlip;
|
||||
this.calcBounds(index);
|
||||
for(i = 1; i < this._layers.length; i++)
|
||||
{
|
||||
o = this._layers[i];
|
||||
if(o != null)
|
||||
{
|
||||
this.paintFrame(o.o,index,o.pal,bHFlip);
|
||||
}
|
||||
}
|
||||
bRet = true;
|
||||
if(bHFlip)
|
||||
{
|
||||
this._anchorPoint.x = 500 - this._bmax.x;
|
||||
}
|
||||
}
|
||||
return bRet;
|
||||
}
|
||||
|
||||
private function paintFrame(top:Object, index:int, palette:Array, bHFlip:Boolean) : void
|
||||
{
|
||||
var p:int = 0;
|
||||
var count:int = 0;
|
||||
var c:uint = 0;
|
||||
var d:uint = 0;
|
||||
var a1:int = 0;
|
||||
var r1:int = 0;
|
||||
var g1:int = 0;
|
||||
var b1:int = 0;
|
||||
var a2:int = 0;
|
||||
var r2:int = 0;
|
||||
var g2:int = 0;
|
||||
var b2:int = 0;
|
||||
var wOff:int = 0;
|
||||
var scr:Number = NaN;
|
||||
var c1:uint = 0;
|
||||
var shadowMultiplyer:int = 0;
|
||||
if(index >= top.f.length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var o:Object = top.f[index];
|
||||
if(!o)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var bm:BitmapData = this.bitmapData;
|
||||
var pack:ByteArray = o.b;
|
||||
var xOff:int = int(o.x);
|
||||
var yOff:int = int(o.y);
|
||||
var w:int = int(o.w);
|
||||
var h:int = int(o.h);
|
||||
xOff -= this._bmin.x;
|
||||
yOff -= this._bmin.y;
|
||||
w += xOff;
|
||||
pack.position = 0;
|
||||
var max:int = int(pack.length);
|
||||
var x:int = xOff;
|
||||
var y:int = yOff;
|
||||
this.bitmapData.lock();
|
||||
var ow:int = w - xOff;
|
||||
if(!bHFlip)
|
||||
{
|
||||
while(pack.position < max)
|
||||
{
|
||||
p = int(pack.readUnsignedByte());
|
||||
count = 1;
|
||||
if((p & 0x80) == 128)
|
||||
{
|
||||
p &= 127;
|
||||
count = pack.readUnsignedByte() + 1;
|
||||
}
|
||||
if(p == 0)
|
||||
{
|
||||
x += count;
|
||||
if(x >= w)
|
||||
{
|
||||
count = x - w;
|
||||
x = xOff + count % ow;
|
||||
y += count / ow + 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
c = uint(palette[p]);
|
||||
if(c >= 4278190080)
|
||||
{
|
||||
if(x + count < w)
|
||||
{
|
||||
while(--count > -1)
|
||||
{
|
||||
bm.setPixel32(x++,y,c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while(--count > -1)
|
||||
{
|
||||
bm.setPixel32(x++,y,c);
|
||||
if(x == w)
|
||||
{
|
||||
x = xOff;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while(--count > -1)
|
||||
{
|
||||
d = bm.getPixel32(x,y);
|
||||
if(d != this._backgroundColor)
|
||||
{
|
||||
a1 = c >> 24 & 0xFF;
|
||||
r1 = c >> 16 & 0xFF;
|
||||
g1 = c >> 8 & 0xFF;
|
||||
b1 = c & 0xFF;
|
||||
a2 = d >> 24 & 0xFF;
|
||||
r2 = d >> 16 & 0xFF;
|
||||
g2 = d >> 8 & 0xFF;
|
||||
b2 = d & 0xFF;
|
||||
if(a1 == 192)
|
||||
{
|
||||
r1 = (r1 + r1 + r1 + r2) * 0.25;
|
||||
g1 = (g1 + g1 + g1 + g2) * 0.25;
|
||||
b1 = (b1 + b1 + b1 + b2) * 0.25;
|
||||
}
|
||||
else if(a1 == 128)
|
||||
{
|
||||
r1 = (r1 + r2) * 0.5;
|
||||
g1 = (g1 + g2) * 0.5;
|
||||
b1 = (b1 + b2) * 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
r1 = (r1 + r2 + r2 + r2) * 0.25;
|
||||
g1 = (g1 + g2 + g2 + g2) * 0.25;
|
||||
b1 = (b1 + b2 + b2 + b2) * 0.25;
|
||||
}
|
||||
if(a2 > a1)
|
||||
{
|
||||
a1 = a2;
|
||||
}
|
||||
c = uint(a1 << 24 | r1 << 16 | g1 << 8 | b1);
|
||||
}
|
||||
bm.setPixel32(x++,y,c);
|
||||
if(x == w)
|
||||
{
|
||||
x = xOff;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wOff = this._bmax.x - this._bmin.x;
|
||||
while(pack.position < max)
|
||||
{
|
||||
p = int(pack.readUnsignedByte());
|
||||
count = 1;
|
||||
if((p & 0x80) == 128)
|
||||
{
|
||||
p &= 127;
|
||||
count = pack.readUnsignedByte() + 1;
|
||||
}
|
||||
if(p == 0)
|
||||
{
|
||||
x += count;
|
||||
if(x >= w)
|
||||
{
|
||||
count = x - w;
|
||||
x = xOff + count % ow;
|
||||
y += count / ow + 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
c = uint(palette[p]);
|
||||
if(c >= 4278190080)
|
||||
{
|
||||
if(x + count < w)
|
||||
{
|
||||
while(--count > -1)
|
||||
{
|
||||
bm.setPixel32(wOff - x++,y,c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while(--count > -1)
|
||||
{
|
||||
bm.setPixel32(wOff - x++,y,c);
|
||||
if(x == w)
|
||||
{
|
||||
x = xOff;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while(--count > -1)
|
||||
{
|
||||
d = bm.getPixel32(wOff - x,y);
|
||||
if(d != this._backgroundColor)
|
||||
{
|
||||
a1 = c >> 24 & 0xFF;
|
||||
r1 = c >> 16 & 0xFF;
|
||||
g1 = c >> 8 & 0xFF;
|
||||
b1 = c & 0xFF;
|
||||
a2 = d >> 24 & 0xFF;
|
||||
r2 = d >> 16 & 0xFF;
|
||||
g2 = d >> 8 & 0xFF;
|
||||
b2 = d & 0xFF;
|
||||
switch(a1)
|
||||
{
|
||||
case 192:
|
||||
r1 = (r1 + r1 + r1 + r2) * 0.25;
|
||||
g1 = (g1 + g1 + g1 + g2) * 0.25;
|
||||
b1 = (b1 + b1 + b1 + b2) * 0.25;
|
||||
break;
|
||||
case 128:
|
||||
r1 = (r1 + r2) * 0.5;
|
||||
g1 = (g1 + g2) * 0.5;
|
||||
b1 = (b1 + b2) * 0.5;
|
||||
break;
|
||||
case 64:
|
||||
r1 = (r1 + r2 + r2 + r2) * 0.25;
|
||||
g1 = (g1 + g2 + g2 + g2) * 0.25;
|
||||
b1 = (b1 + b2 + b2 + b2) * 0.25;
|
||||
}
|
||||
if(a2 > a1)
|
||||
{
|
||||
a1 = a2;
|
||||
}
|
||||
c = uint(a1 << 24 | r1 << 16 | g1 << 8 | b1);
|
||||
}
|
||||
bm.setPixel32(wOff - x++,y,c);
|
||||
if(x == w)
|
||||
{
|
||||
x = xOff;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(o.hasOwnProperty("s"))
|
||||
{
|
||||
shadowMultiplyer = int(o.sm);
|
||||
pack = o.s;
|
||||
max = int(pack.length);
|
||||
pack.position = 0;
|
||||
x = xOff;
|
||||
y = yOff;
|
||||
if(!bHFlip)
|
||||
{
|
||||
while(pack.position < max)
|
||||
{
|
||||
p = int(pack.readUnsignedByte());
|
||||
count = 1;
|
||||
if((p & 0x80) == 128)
|
||||
{
|
||||
p &= 127;
|
||||
count = pack.readUnsignedByte() + 1;
|
||||
}
|
||||
if(p == 0)
|
||||
{
|
||||
x += count;
|
||||
if(x >= w)
|
||||
{
|
||||
count = x - w;
|
||||
x = xOff + count % ow;
|
||||
y += count / ow + 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
c = uint(p << shadowMultiplyer);
|
||||
c += 24;
|
||||
if(c > 255)
|
||||
{
|
||||
scr = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
scr = c / 255;
|
||||
}
|
||||
while(--count > -1)
|
||||
{
|
||||
d = bm.getPixel32(x,y);
|
||||
if(d != this._backgroundColor)
|
||||
{
|
||||
a1 = d >> 24 & 0xFF;
|
||||
r1 = (d >> 16 & 0xFF) * scr;
|
||||
g1 = (d >> 8 & 0xFF) * scr;
|
||||
b1 = (d & 0xFF) * scr;
|
||||
c1 = uint(a1 << 24 | r1 << 16 | g1 << 8 | b1);
|
||||
bm.setPixel32(x,y,c1);
|
||||
}
|
||||
if(++x == w)
|
||||
{
|
||||
x = xOff;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wOff = this._bmax.x - this._bmin.x;
|
||||
while(pack.position < max)
|
||||
{
|
||||
p = int(pack.readUnsignedByte());
|
||||
count = 1;
|
||||
if((p & 0x80) == 128)
|
||||
{
|
||||
p &= 127;
|
||||
count = pack.readUnsignedByte() + 1;
|
||||
}
|
||||
if(p == 0)
|
||||
{
|
||||
x += count;
|
||||
if(x >= w)
|
||||
{
|
||||
count = x - w;
|
||||
x = xOff + count % ow;
|
||||
y += count / ow + 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
c = uint(p << shadowMultiplyer);
|
||||
c += 24;
|
||||
if(c > 255)
|
||||
{
|
||||
scr = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
scr = c / 255;
|
||||
}
|
||||
while(--count > -1)
|
||||
{
|
||||
d = bm.getPixel32(wOff - x,y);
|
||||
if(d != this._backgroundColor)
|
||||
{
|
||||
a1 = d >> 24 & 0xFF;
|
||||
r1 = (d >> 16 & 0xFF) * scr;
|
||||
g1 = (d >> 8 & 0xFF) * scr;
|
||||
b1 = (d & 0xFF) * scr;
|
||||
c1 = uint(a1 << 24 | r1 << 16 | g1 << 8 | b1);
|
||||
bm.setPixel32(wOff - x,y,c1);
|
||||
}
|
||||
if(++x == w)
|
||||
{
|
||||
x = xOff;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bm.unlock();
|
||||
}
|
||||
|
||||
private function resizeBitmap(w:int, h:int, bClearBitmap:Boolean) : void
|
||||
{
|
||||
var iw:int = w;
|
||||
var ih:int = h;
|
||||
if(!this.bitmapData)
|
||||
{
|
||||
bClearBitmap = true;
|
||||
}
|
||||
var rect:Rectangle = new Rectangle(0,0,iw,ih);
|
||||
var ba:ByteArray = null;
|
||||
if(!bClearBitmap)
|
||||
{
|
||||
ba = this.bitmapData.getPixels(rect);
|
||||
}
|
||||
if(Boolean(this.bitmapData))
|
||||
{
|
||||
this.bitmapData.dispose();
|
||||
}
|
||||
this.bitmapData = new BitmapData(w,h,true,this._backgroundColor);
|
||||
if(!bClearBitmap)
|
||||
{
|
||||
this.bitmapData.setPixels(rect,ba);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
package com.sbi.graphics
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class PaletteHelper
|
||||
{
|
||||
|
||||
public static var gamePalette:Array;
|
||||
|
||||
public static var avatarPalette1:Array;
|
||||
|
||||
public static var avatarPalette2:Array;
|
||||
|
||||
private static const PALETTE_ALPHA_OFFSET:int = 25;
|
||||
|
||||
public function PaletteHelper()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function setGamePalette(baPal:ByteArray, baAvatarPal1:ByteArray = null, baAvatarPal2:ByteArray = null) : void
|
||||
{
|
||||
var count:int = baPal.length / 4;
|
||||
gamePalette = new Array(count);
|
||||
var i:int = 0;
|
||||
while(i < count)
|
||||
{
|
||||
gamePalette[i++] = baPal.readUnsignedInt();
|
||||
}
|
||||
if(Boolean(baAvatarPal1))
|
||||
{
|
||||
count = int(baAvatarPal1.length);
|
||||
avatarPalette1 = new Array(count);
|
||||
i = 0;
|
||||
while(i < count)
|
||||
{
|
||||
avatarPalette1[i++] = baAvatarPal1.readUnsignedByte();
|
||||
}
|
||||
}
|
||||
if(Boolean(baAvatarPal2))
|
||||
{
|
||||
baAvatarPal2.position = 0;
|
||||
count = int(baAvatarPal2.length);
|
||||
avatarPalette2 = new Array(count);
|
||||
i = 0;
|
||||
while(i < count)
|
||||
{
|
||||
avatarPalette2[i++] = baAvatarPal2.readUnsignedByte();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function mixColors(color1:uint, color2:uint) : uint
|
||||
{
|
||||
var r1:uint = uint(color1 >> 16 & 0xFF);
|
||||
var g1:uint = uint(color1 >> 8 & 0xFF);
|
||||
var b1:uint = uint(color1 & 0xFF);
|
||||
var r2:uint = uint(color2 >> 16 & 0xFF);
|
||||
var g2:uint = uint(color2 >> 8 & 0xFF);
|
||||
var b2:uint = uint(color2 & 0xFF);
|
||||
r1 = (r1 + r2) / 2;
|
||||
g1 = (g1 + g2) / 2;
|
||||
b1 = (b1 + b2) / 2;
|
||||
return r1 << 16 | g1 << 8 | b1;
|
||||
}
|
||||
|
||||
public static function setColorGradient(palette:Array, color:uint, offset:uint, count:uint) : void
|
||||
{
|
||||
var c:uint = 0;
|
||||
var r:uint = uint(color >> 16 & 0xFF);
|
||||
var g:uint = uint(color >> 8 & 0xFF);
|
||||
var b:uint = uint(color & 0xFF);
|
||||
var r1:uint = r / (count + 2);
|
||||
var g1:uint = g / (count + 2);
|
||||
var b1:uint = b / (count + 2);
|
||||
var index:int = offset + count - 1;
|
||||
for(var i:uint = 0; i < count; i++)
|
||||
{
|
||||
c = uint(r << 16 | g << 8 | b);
|
||||
palette[index] = c | 255 << 24;
|
||||
palette[index + PALETTE_ALPHA_OFFSET] = c | 192 << 24;
|
||||
palette[index + PALETTE_ALPHA_OFFSET * 2] = c | 128 << 24;
|
||||
palette[index + PALETTE_ALPHA_OFFSET * 3] = c | 64 << 24;
|
||||
r -= r1;
|
||||
g -= g1;
|
||||
b -= b1;
|
||||
index--;
|
||||
}
|
||||
}
|
||||
|
||||
public static function AddRGB(color:uint, r:int, g:int, b:int) : uint
|
||||
{
|
||||
var ac:int = color >> 24 & 0xFF;
|
||||
var rc:int = color >> 16 & 0xFF;
|
||||
var gc:int = color >> 8 & 0xFF;
|
||||
var bc:int = color & 0xFF;
|
||||
rc += r;
|
||||
if(rc < 0)
|
||||
{
|
||||
rc = 0;
|
||||
}
|
||||
else if(rc > 255)
|
||||
{
|
||||
rc = 255;
|
||||
}
|
||||
gc += g;
|
||||
if(gc < 0)
|
||||
{
|
||||
gc = 0;
|
||||
}
|
||||
else if(gc > 255)
|
||||
{
|
||||
gc = 255;
|
||||
}
|
||||
bc += b;
|
||||
if(bc < 0)
|
||||
{
|
||||
bc = 0;
|
||||
}
|
||||
else if(bc > 255)
|
||||
{
|
||||
bc = 255;
|
||||
}
|
||||
return uint(ac << 24 | rc << 16 | gc << 8 | bc);
|
||||
}
|
||||
|
||||
public static function getAnimalPalette() : Array
|
||||
{
|
||||
var j:int = 0;
|
||||
var c:uint = 0;
|
||||
var nc:uint = 0;
|
||||
var ret:Array = new Array(uint(4278255615),uint(4286513152),uint(4290707456),uint(4294901760),uint(4278222592),uint(4278238976),uint(4278255360),uint(4278190207),uint(4278190271),uint(4278190335),uint(4286545791),uint(4290756543),uint(4294967295),uint(4282400768),uint(4286611456),uint(4278206528),uint(4278222976),uint(4282384448),uint(4286578816),uint(4286595136),uint(4294934656),uint(4282417216),uint(4286644096),uint(4282400896),uint(4286611711),uint(4278190080));
|
||||
var a:uint = uint(192 << 24);
|
||||
for(var i:int = 0; i < 3; i++)
|
||||
{
|
||||
for(j = 1; j <= PALETTE_ALPHA_OFFSET; j++)
|
||||
{
|
||||
c = uint(ret[j] & 0xFFFFFF);
|
||||
nc = uint(c | a);
|
||||
ret.push(nc);
|
||||
}
|
||||
a -= 64 << 24;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static function BuildAnimalPalette(_palette:Array, color1:uint, color2:uint, color3:uint, color4:uint) : void
|
||||
{
|
||||
setColorGradient(_palette,color1,1,3);
|
||||
setColorGradient(_palette,color2,4,3);
|
||||
setColorGradient(_palette,color3,7,3);
|
||||
setColorGradient(_palette,color4,10,3);
|
||||
setColorGradient(_palette,PaletteHelper.mixColors(color1,color2),13,2);
|
||||
setColorGradient(_palette,PaletteHelper.mixColors(color2,color3),15,2);
|
||||
setColorGradient(_palette,PaletteHelper.mixColors(color1,color3),17,2);
|
||||
setColorGradient(_palette,PaletteHelper.mixColors(color1,color4),19,2);
|
||||
setColorGradient(_palette,PaletteHelper.mixColors(color2,color4),21,2);
|
||||
setColorGradient(_palette,PaletteHelper.mixColors(color3,color4),23,2);
|
||||
}
|
||||
|
||||
public static function adjustPaletteColor(_palette:Array, argb:uint) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var color:uint = 0;
|
||||
var ac:int = 0;
|
||||
var rc:int = 0;
|
||||
var gc:int = 0;
|
||||
var bc:int = 0;
|
||||
var a:Number = NaN;
|
||||
var percent:Number = (argb >> 24 & 0xFF) / 255;
|
||||
var ra:int = argb >> 16 & 0xFF;
|
||||
var ga:int = argb >> 8 & 0xFF;
|
||||
for(var ba:int = argb & 0xFF; i < _palette.length; )
|
||||
{
|
||||
color = uint(_palette[i]);
|
||||
ac = color >> 24 & 0xFF;
|
||||
rc = color >> 16 & 0xFF;
|
||||
gc = color >> 8 & 0xFF;
|
||||
bc = color & 0xFF;
|
||||
a = ra - rc;
|
||||
a *= percent;
|
||||
rc += a;
|
||||
if(rc < 0)
|
||||
{
|
||||
rc = 0;
|
||||
}
|
||||
else if(rc > 255)
|
||||
{
|
||||
rc = 255;
|
||||
}
|
||||
a = ga - gc;
|
||||
a *= percent;
|
||||
gc += a;
|
||||
if(gc < 0)
|
||||
{
|
||||
gc = 0;
|
||||
}
|
||||
else if(gc > 255)
|
||||
{
|
||||
gc = 255;
|
||||
}
|
||||
a = ba - bc;
|
||||
a *= percent;
|
||||
bc += a;
|
||||
if(bc < 0)
|
||||
{
|
||||
bc = 0;
|
||||
}
|
||||
else if(bc > 255)
|
||||
{
|
||||
bc = 255;
|
||||
}
|
||||
_palette[i] = uint(ac << 24 | rc << 16 | gc << 8 | bc);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getRGBColors(packedColors:uint) : Array
|
||||
{
|
||||
var colors:Array = [];
|
||||
colors[0] = decToRGBObj(gamePalette[packedColors >> 24 & 0xFF]);
|
||||
colors[1] = decToRGBObj(gamePalette[packedColors >> 16 & 0xFF]);
|
||||
colors[2] = decToRGBObj(gamePalette[packedColors >> 8 & 0xFF]);
|
||||
colors[3] = decToRGBObj(gamePalette[packedColors & 0xFF]);
|
||||
return colors;
|
||||
}
|
||||
|
||||
private static function decToRGBObj(hex:uint) : Object
|
||||
{
|
||||
return {
|
||||
"r":hex >> 16 & 0xFF,
|
||||
"g":hex >> 8 & 0xFF,
|
||||
"b":hex & 0xFF
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
package com.sbi.graphics
|
||||
{
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Sprite;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.utils.Dictionary;
|
||||
|
||||
public class SortLayer extends Sprite
|
||||
{
|
||||
|
||||
private var _bottoms:Dictionary;
|
||||
|
||||
private var _nudge:Number = 0;
|
||||
|
||||
public function SortLayer()
|
||||
{
|
||||
super();
|
||||
this._bottoms = new Dictionary(true);
|
||||
}
|
||||
|
||||
override public function addChild(child:DisplayObject) : DisplayObject
|
||||
{
|
||||
var offset:int = int(child.name);
|
||||
child.name = (this.getNudge() + offset).toString();
|
||||
return super.addChild(child);
|
||||
}
|
||||
|
||||
override public function addChildAt(child:DisplayObject, index:int) : DisplayObject
|
||||
{
|
||||
var offset:int = int(child.name);
|
||||
child.name = (this.getNudge() + offset).toString();
|
||||
return super.addChildAt(child,index);
|
||||
}
|
||||
|
||||
public function release() : void
|
||||
{
|
||||
this._nudge = 0;
|
||||
this._bottoms = new Dictionary(true);
|
||||
}
|
||||
|
||||
public function depthSort(a:DisplayObject, b:DisplayObject) : int
|
||||
{
|
||||
return this._bottoms[a] - this._bottoms[b];
|
||||
}
|
||||
|
||||
public function heartbeat() : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var r:Rectangle = null;
|
||||
var bSort:Boolean = false;
|
||||
var d:DisplayObject = null;
|
||||
var y:Number = NaN;
|
||||
var offset:Number = NaN;
|
||||
var t:int = this.numChildren;
|
||||
var prev:Number = -999999999;
|
||||
if(t < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var sortArray:Array = [t];
|
||||
for(i = 0; i < t; i++)
|
||||
{
|
||||
d = this.getChildAt(i);
|
||||
sortArray[i] = d;
|
||||
r = d.getBounds(this);
|
||||
y = r.bottom;
|
||||
offset = Number(d.name);
|
||||
if(!offset)
|
||||
{
|
||||
offset = this.getNudge();
|
||||
d.name = offset.toString();
|
||||
}
|
||||
y -= offset;
|
||||
this._bottoms[d] = y;
|
||||
if(!bSort)
|
||||
{
|
||||
if(y < prev)
|
||||
{
|
||||
bSort = true;
|
||||
}
|
||||
prev = y;
|
||||
}
|
||||
}
|
||||
if(bSort)
|
||||
{
|
||||
sortArray.sort(this.depthSort);
|
||||
for(i = 0; i < t; i++)
|
||||
{
|
||||
this.setChildIndex(sortArray[i],i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getNudge() : Number
|
||||
{
|
||||
this._nudge += 0.001;
|
||||
if(this._nudge > 0.9)
|
||||
{
|
||||
this._nudge = 0;
|
||||
}
|
||||
return this._nudge;
|
||||
}
|
||||
|
||||
private function sort(a:Vector.<Number>) : void
|
||||
{
|
||||
this.quickSort(a,0,a.length - 1);
|
||||
this.InsertionSort(a,0,a.length - 1);
|
||||
}
|
||||
|
||||
private function quickSort(a:Vector.<Number>, l:int, r:int) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var j:int = 0;
|
||||
var v:Number = NaN;
|
||||
var M:int = 4;
|
||||
if(r - l > M)
|
||||
{
|
||||
i = (r + l) / 2;
|
||||
if(a[l] > a[i])
|
||||
{
|
||||
this.swap(a,l,i);
|
||||
}
|
||||
if(a[l] > a[r])
|
||||
{
|
||||
this.swap(a,l,r);
|
||||
}
|
||||
if(a[i] > a[r])
|
||||
{
|
||||
this.swap(a,i,r);
|
||||
}
|
||||
j = r - 1;
|
||||
this.swap(a,i,j);
|
||||
i = l;
|
||||
v = a[j];
|
||||
while(true)
|
||||
{
|
||||
while(a[++i] < v)
|
||||
{
|
||||
}
|
||||
while(a[--j] > v)
|
||||
{
|
||||
}
|
||||
if(j < i)
|
||||
{
|
||||
break;
|
||||
}
|
||||
this.swap(a,i,j);
|
||||
}
|
||||
this.swap(a,i,r - 1);
|
||||
this.quickSort(a,l,j);
|
||||
this.quickSort(a,i + 1,r);
|
||||
}
|
||||
}
|
||||
|
||||
private function swap(a:Vector.<Number>, i:int, j:int) : void
|
||||
{
|
||||
var T:Number = NaN;
|
||||
T = a[i];
|
||||
a[i] = a[j];
|
||||
a[j] = T;
|
||||
swapChildrenAt(i,j);
|
||||
}
|
||||
|
||||
private function move(a:Vector.<Number>, i:int, j:int) : void
|
||||
{
|
||||
a[j] = a[i];
|
||||
this.addChildAt(getChildAt(i),j);
|
||||
}
|
||||
|
||||
private function InsertionSort(a:Vector.<Number>, lo0:int, hi0:int) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var j:int = 0;
|
||||
var v:Number = NaN;
|
||||
for(i = lo0 + 1; i <= hi0; i++)
|
||||
{
|
||||
v = a[i];
|
||||
j = i;
|
||||
while(j > lo0 && a[j - 1] > v)
|
||||
{
|
||||
this.move(a,j - 1,j);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
package com.sbi.graphics
|
||||
{
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.system.System;
|
||||
import flash.text.StyleSheet;
|
||||
import flash.text.TextField;
|
||||
import flash.utils.getTimer;
|
||||
|
||||
public class Stats extends Sprite
|
||||
{
|
||||
|
||||
protected const WIDTH:uint = 70;
|
||||
|
||||
protected const HEIGHT:uint = 100;
|
||||
|
||||
protected var xml:XML;
|
||||
|
||||
protected var text:TextField;
|
||||
|
||||
protected var style:StyleSheet;
|
||||
|
||||
protected var timer:uint;
|
||||
|
||||
protected var fps:uint;
|
||||
|
||||
protected var ms:uint;
|
||||
|
||||
protected var ms_prev:uint;
|
||||
|
||||
protected var mem:Number;
|
||||
|
||||
protected var mem_max:Number;
|
||||
|
||||
protected var graph:Bitmap;
|
||||
|
||||
protected var rectangle:Rectangle;
|
||||
|
||||
protected var fps_graph:uint;
|
||||
|
||||
protected var mem_graph:uint;
|
||||
|
||||
protected var mem_max_graph:uint;
|
||||
|
||||
protected var theme:Object = {
|
||||
"bg":51,
|
||||
"fps":16776960,
|
||||
"ms":65280,
|
||||
"mem":65535,
|
||||
"memmax":16711792
|
||||
};
|
||||
|
||||
public function Stats(_theme:Object = null)
|
||||
{
|
||||
super();
|
||||
if(Boolean(_theme))
|
||||
{
|
||||
if(_theme.bg != null)
|
||||
{
|
||||
this.theme.bg = _theme.bg;
|
||||
}
|
||||
if(_theme.fps != null)
|
||||
{
|
||||
this.theme.fps = _theme.fps;
|
||||
}
|
||||
if(_theme.ms != null)
|
||||
{
|
||||
this.theme.ms = _theme.ms;
|
||||
}
|
||||
if(_theme.mem != null)
|
||||
{
|
||||
this.theme.mem = _theme.mem;
|
||||
}
|
||||
if(_theme.memmax != null)
|
||||
{
|
||||
this.theme.memmax = _theme.memmax;
|
||||
}
|
||||
}
|
||||
this.mem_max = 0;
|
||||
this.xml = <xml><fps>FPS:</fps><ms>MS:</ms><mem>MEM:</mem><memMax>MAX:</memMax></xml>;
|
||||
this.style = new StyleSheet();
|
||||
this.style.setStyle("xml",{
|
||||
"fontSize":"9px",
|
||||
"fontFamily":"_sans",
|
||||
"leading":"-2px"
|
||||
});
|
||||
this.style.setStyle("fps",{"color":this.hex2css(this.theme.fps)});
|
||||
this.style.setStyle("ms",{"color":this.hex2css(this.theme.ms)});
|
||||
this.style.setStyle("mem",{"color":this.hex2css(this.theme.mem)});
|
||||
this.style.setStyle("memMax",{"color":this.hex2css(this.theme.memmax)});
|
||||
this.text = new TextField();
|
||||
this.text.width = this.WIDTH;
|
||||
this.text.height = 50;
|
||||
this.text.styleSheet = this.style;
|
||||
this.text.condenseWhite = true;
|
||||
this.text.selectable = false;
|
||||
this.text.mouseEnabled = false;
|
||||
this.graph = new Bitmap();
|
||||
this.graph.y = 50;
|
||||
this.rectangle = new Rectangle(this.WIDTH - 1,0,1,this.HEIGHT - 50);
|
||||
addEventListener(Event.ADDED_TO_STAGE,this.init,false,0,true);
|
||||
addEventListener(Event.REMOVED_FROM_STAGE,this.destroy,false,0,true);
|
||||
}
|
||||
|
||||
private function init(e:Event) : void
|
||||
{
|
||||
graphics.beginFill(this.theme.bg);
|
||||
graphics.drawRect(0,0,this.WIDTH,this.HEIGHT);
|
||||
graphics.endFill();
|
||||
addChild(this.text);
|
||||
this.graph.bitmapData = new BitmapData(this.WIDTH,this.HEIGHT - 50,false,this.theme.bg);
|
||||
addChild(this.graph);
|
||||
addEventListener(MouseEvent.CLICK,this.onClick);
|
||||
addEventListener(Event.ENTER_FRAME,this.update);
|
||||
}
|
||||
|
||||
private function destroy(e:Event) : void
|
||||
{
|
||||
graphics.clear();
|
||||
while(numChildren > 0)
|
||||
{
|
||||
removeChildAt(0);
|
||||
}
|
||||
this.graph.bitmapData.dispose();
|
||||
removeEventListener(MouseEvent.CLICK,this.onClick);
|
||||
removeEventListener(Event.ENTER_FRAME,this.update);
|
||||
}
|
||||
|
||||
private function update(e:Event) : void
|
||||
{
|
||||
this.timer = getTimer();
|
||||
if(this.timer - 1000 > this.ms_prev)
|
||||
{
|
||||
this.ms_prev = this.timer;
|
||||
this.mem = Number((System.totalMemory * 9.54e-7).toFixed(3));
|
||||
this.mem_max = this.mem_max > this.mem ? this.mem_max : this.mem;
|
||||
this.fps_graph = Math.min(this.graph.height,this.fps / stage.frameRate * this.graph.height);
|
||||
this.mem_graph = Math.min(this.graph.height,Math.sqrt(Math.sqrt(this.mem * 5000))) - 2;
|
||||
this.mem_max_graph = Math.min(this.graph.height,Math.sqrt(Math.sqrt(this.mem_max * 5000))) - 2;
|
||||
this.graph.bitmapData.scroll(-1,0);
|
||||
this.graph.bitmapData.fillRect(this.rectangle,this.theme.bg);
|
||||
this.graph.bitmapData.setPixel(this.graph.width - 1,this.graph.height - this.fps_graph,this.theme.fps);
|
||||
this.graph.bitmapData.setPixel(this.graph.width - 1,this.graph.height - (this.timer - this.ms >> 1),this.theme.ms);
|
||||
this.graph.bitmapData.setPixel(this.graph.width - 1,this.graph.height - this.mem_graph,this.theme.mem);
|
||||
this.graph.bitmapData.setPixel(this.graph.width - 1,this.graph.height - this.mem_max_graph,this.theme.memmax);
|
||||
this.xml.fps = "FPS: " + this.fps + " / " + stage.frameRate;
|
||||
this.xml.mem = "MEM: " + this.mem;
|
||||
this.xml.memMax = "MAX: " + this.mem_max;
|
||||
this.fps = 0;
|
||||
}
|
||||
++this.fps;
|
||||
this.xml.ms = "MS: " + (this.timer - this.ms);
|
||||
this.ms = this.timer;
|
||||
this.text.htmlText = this.xml;
|
||||
}
|
||||
|
||||
private function onClick(e:MouseEvent) : void
|
||||
{
|
||||
if(mouseY / height > 0.5)
|
||||
{
|
||||
--stage.frameRate;
|
||||
}
|
||||
else
|
||||
{
|
||||
++stage.frameRate;
|
||||
}
|
||||
this.xml.fps = "FPS: " + this.fps + " / " + stage.frameRate;
|
||||
this.text.htmlText = this.xml;
|
||||
}
|
||||
|
||||
private function hex2css(color:int) : String
|
||||
{
|
||||
return "#" + color.toString(16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.events.EventDispatcher;
|
||||
|
||||
public class BaseFileServer extends EventDispatcher
|
||||
{
|
||||
|
||||
private var _contentPath:String;
|
||||
|
||||
private var _loaderArray:Array;
|
||||
|
||||
private var _cacheArray:Array;
|
||||
|
||||
public function BaseFileServer(path:String)
|
||||
{
|
||||
super();
|
||||
this._contentPath = path;
|
||||
this._loaderArray = new Array();
|
||||
this._cacheArray = new Array();
|
||||
}
|
||||
|
||||
public function updatePath(path:String) : void
|
||||
{
|
||||
this._contentPath = path;
|
||||
}
|
||||
|
||||
public function clearFromCache(path:String, id:int) : void
|
||||
{
|
||||
if(Boolean(this._cacheArray[path]))
|
||||
{
|
||||
if(Boolean(this._cacheArray[path][id]))
|
||||
{
|
||||
delete this._cacheArray[path][id];
|
||||
}
|
||||
}
|
||||
if(Boolean(this._loaderArray[path]))
|
||||
{
|
||||
if(Boolean(this._loaderArray[path][id]))
|
||||
{
|
||||
delete this._loaderArray[path][id];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function requestFile(id:uint, noCache:Boolean = false, contentType:int = 0, useDeployVersion:Boolean = true) : void
|
||||
{
|
||||
var l:LoaderCacheEntry_URL = null;
|
||||
if(noCache || this.getFromCache(id) == false)
|
||||
{
|
||||
if(!(Boolean(this._loaderArray[this._contentPath]) ? this._loaderArray[this._contentPath][id] : false))
|
||||
{
|
||||
l = new LoaderCacheEntry_URL(this._contentPath + id,false);
|
||||
l.id = id;
|
||||
l.contentType = contentType;
|
||||
l.addEventListener(LoaderEvent.ON_LOAD_COMPLETE,this.onResultGetData);
|
||||
l.load("binary",useDeployVersion);
|
||||
if(this._loaderArray[this._contentPath] == null)
|
||||
{
|
||||
this._loaderArray[this._contentPath] = [];
|
||||
}
|
||||
this._loaderArray[this._contentPath][id] = {
|
||||
"l":l,
|
||||
"c":1
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
++this._loaderArray[this._contentPath][id].c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function requestFiles(ids:Array) : void
|
||||
{
|
||||
for(var i:int = 0; i < ids.length; )
|
||||
{
|
||||
this.requestFile(ids[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private function getFromCache(id:uint) : Boolean
|
||||
{
|
||||
var r:Object = this.searchCache(id);
|
||||
if(Boolean(r))
|
||||
{
|
||||
this.newEvent(r.id,r.data,true,r.contentType);
|
||||
}
|
||||
return r == null ? false : true;
|
||||
}
|
||||
|
||||
private function searchCache(id:uint) : Object
|
||||
{
|
||||
return Boolean(this._cacheArray[this._contentPath]) ? this._cacheArray[this._contentPath][id] : null;
|
||||
}
|
||||
|
||||
private function onResultGetData(le:LoaderEvent) : void
|
||||
{
|
||||
var c:int = 0;
|
||||
var e:FileServerEvent = new FileServerEvent(FileServerEvent.ON_NEW_DATA);
|
||||
e.id = le.entry.id;
|
||||
e.contentType = le.entry.contentType;
|
||||
var o:Object = le.entry.data;
|
||||
if(o == null)
|
||||
{
|
||||
e.success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.data = o;
|
||||
if(this._cacheArray[this._contentPath] == null)
|
||||
{
|
||||
this._cacheArray[this._contentPath] = [];
|
||||
}
|
||||
this._cacheArray[this._contentPath][e.id] = {
|
||||
"id":e.id,
|
||||
"data":o,
|
||||
"contentType":e.contentType
|
||||
};
|
||||
}
|
||||
var currObj:Object = this._loaderArray[this._contentPath][e.id];
|
||||
if(Boolean(currObj))
|
||||
{
|
||||
currObj.l.removeEventListener(LoaderEvent.ON_LOAD_COMPLETE,this.onResultGetData);
|
||||
c = int(currObj.c);
|
||||
this._loaderArray[this._contentPath][e.id] = null;
|
||||
while(c-- > 0)
|
||||
{
|
||||
this.newEvent(e.id,e.data,e.success,e.contentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function newEvent(id:int, data:*, success:Boolean, contentType:int = 0) : void
|
||||
{
|
||||
var ne:FileServerEvent = new FileServerEvent(FileServerEvent.ON_NEW_DATA);
|
||||
ne.id = id;
|
||||
ne.data = data;
|
||||
ne.success = success;
|
||||
ne.contentType = contentType;
|
||||
dispatchEvent(ne);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SingletonLock
|
||||
{
|
||||
|
||||
public function SingletonLock()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class FileServerEvent extends Event
|
||||
{
|
||||
|
||||
public static const ON_NEW_DATA:String = "OnNewData";
|
||||
|
||||
public static const JSON_TYPE:int = 0;
|
||||
|
||||
public static const PLAIN_TEXT_TYPE:int = 1;
|
||||
|
||||
public static const AMF3_TYPE:int = 2;
|
||||
|
||||
public var id:uint;
|
||||
|
||||
public var data:*;
|
||||
|
||||
public var success:Boolean = true;
|
||||
|
||||
public var contentType:int = 0;
|
||||
|
||||
public function FileServerEvent(type:String)
|
||||
{
|
||||
super(type);
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new FileServerEvent(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
public interface IResourceStackable
|
||||
{
|
||||
|
||||
function init(param1:Function) : void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class ImageServerEvent extends Event
|
||||
{
|
||||
|
||||
public static const ON_NEW_DATA:String = "OnNewData";
|
||||
|
||||
public static const ON_GLOBAL_PALETTE:String = "OnGlobalPalette";
|
||||
|
||||
public var id:uint;
|
||||
|
||||
public var layer:int;
|
||||
|
||||
public var imageData:*;
|
||||
|
||||
public var versionNum:int;
|
||||
|
||||
public var genericData:*;
|
||||
|
||||
public var frames:int;
|
||||
|
||||
public var success:Boolean = true;
|
||||
|
||||
public function ImageServerEvent(type:String)
|
||||
{
|
||||
super(type);
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new ImageServerEvent(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import com.sbi.graphics.ImageArray;
|
||||
import com.sbi.graphics.ImageArrayHelper;
|
||||
import com.sbi.graphics.PaletteHelper;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class ImageServerURL extends EventDispatcher
|
||||
{
|
||||
|
||||
private static var _instance:ImageServerURL;
|
||||
|
||||
private static const IMAGE_ARRAY_PATH:String = "imageArrays/";
|
||||
|
||||
private static const PALETTE_NAME:String = "paletteData";
|
||||
|
||||
private var _imageCacheArray:Array;
|
||||
|
||||
private var _loaderCacheArray:Array;
|
||||
|
||||
private var _layerInfo:Object;
|
||||
|
||||
public function ImageServerURL(lock:Class)
|
||||
{
|
||||
super();
|
||||
if(lock != SingletonLock)
|
||||
{
|
||||
throw new Error("Invalid Singleton access. Use ImageServerURL.instance.");
|
||||
}
|
||||
this._imageCacheArray = new Array();
|
||||
this._loaderCacheArray = new Array();
|
||||
}
|
||||
|
||||
public static function get instance() : ImageServerURL
|
||||
{
|
||||
if(!_instance)
|
||||
{
|
||||
_instance = new ImageServerURL(SingletonLock);
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public function set layerInfo(o:Object) : void
|
||||
{
|
||||
this._layerInfo = o;
|
||||
}
|
||||
|
||||
public function getLayerIndex(layerId:int) : int
|
||||
{
|
||||
return this._layerInfo[layerId];
|
||||
}
|
||||
|
||||
public function requestGlobalPalette() : void
|
||||
{
|
||||
var e:ImageServerEvent = null;
|
||||
var l:LoaderCacheEntry_URL = null;
|
||||
if(this.isGlobalPaletteCached())
|
||||
{
|
||||
e = new ImageServerEvent(ImageServerEvent.ON_GLOBAL_PALETTE);
|
||||
e.imageData = null;
|
||||
trace("imageServer dispatching cached game palette");
|
||||
dispatchEvent(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
l = new LoaderCacheEntry_URL(PALETTE_NAME);
|
||||
l.addEventListener(LoaderEvent.ON_LOAD_COMPLETE,this.onResultGetGamePalette);
|
||||
l.load();
|
||||
this._loaderCacheArray["palette"] = {"l":l};
|
||||
}
|
||||
}
|
||||
|
||||
public function requestImage(id:uint, bUseCache:Boolean = true) : void
|
||||
{
|
||||
var l:LoaderCacheEntry_URL = null;
|
||||
if(!bUseCache || this.getFromCache(id) == false)
|
||||
{
|
||||
if(!this._loaderCacheArray[id])
|
||||
{
|
||||
l = new LoaderCacheEntry_URL(IMAGE_ARRAY_PATH + id);
|
||||
l.id = id;
|
||||
l.addEventListener(LoaderEvent.ON_LOAD_COMPLETE,this.onResultGetImageData);
|
||||
l.load();
|
||||
this._loaderCacheArray[id] = {
|
||||
"l":l,
|
||||
"c":1
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
++this._loaderCacheArray[id].c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function requestImages(ids:Array) : void
|
||||
{
|
||||
for(var i:int = 0; i < ids.length; i++)
|
||||
{
|
||||
this.requestImage(ids[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private function getFromCache(id:uint) : Boolean
|
||||
{
|
||||
var e:ImageServerEvent = null;
|
||||
var r:Object = this.searchCache(id);
|
||||
if(Boolean(r))
|
||||
{
|
||||
e = new ImageServerEvent(ImageServerEvent.ON_NEW_DATA);
|
||||
e.id = r.id;
|
||||
e.imageData = r.imageData;
|
||||
e.frames = r.frames;
|
||||
e.layer = r.layer;
|
||||
e.success = e.imageData == null ? false : true;
|
||||
dispatchEvent(e);
|
||||
}
|
||||
return r == null ? false : true;
|
||||
}
|
||||
|
||||
private function isGlobalPaletteCached() : Boolean
|
||||
{
|
||||
return Boolean(PaletteHelper.gamePalette);
|
||||
}
|
||||
|
||||
private function searchCache(id:uint) : Object
|
||||
{
|
||||
return this._imageCacheArray[id];
|
||||
}
|
||||
|
||||
private function onResultGetGamePalette(e:LoaderEvent) : void
|
||||
{
|
||||
var ie:ImageServerEvent = null;
|
||||
var ba:ByteArray = null;
|
||||
var pal:ByteArray = null;
|
||||
var a1pal:ByteArray = null;
|
||||
var a2pal:ByteArray = null;
|
||||
var len:int = 0;
|
||||
var pos:int = 0;
|
||||
if(Boolean(e))
|
||||
{
|
||||
this._loaderCacheArray["palette"].l.removeEventListener(LoaderEvent.ON_LOAD_COMPLETE,this.onResultGetGamePalette);
|
||||
this._loaderCacheArray["palette"] = null;
|
||||
ie = new ImageServerEvent(ImageServerEvent.ON_GLOBAL_PALETTE);
|
||||
ba = e.entry.data as ByteArray;
|
||||
pal = new ByteArray();
|
||||
a1pal = new ByteArray();
|
||||
a2pal = new ByteArray();
|
||||
ba.position = 0;
|
||||
len = ba.readInt();
|
||||
pos = 4;
|
||||
pal.writeBytes(ba,pos,len);
|
||||
pal.position = 0;
|
||||
pos += len;
|
||||
ba.position = pos;
|
||||
len = ba.readInt();
|
||||
pos += 4;
|
||||
a1pal.writeBytes(ba,pos,len);
|
||||
a1pal.position = 0;
|
||||
pos += len;
|
||||
ba.position = pos;
|
||||
len = ba.readInt();
|
||||
pos += 4;
|
||||
a2pal.writeBytes(ba,pos,len);
|
||||
a2pal.position = 0;
|
||||
ie.genericData = {
|
||||
"palette":pal,
|
||||
"avatarPalette1":a1pal,
|
||||
"avatarPalette2":a2pal
|
||||
};
|
||||
dispatchEvent(ie);
|
||||
return;
|
||||
}
|
||||
throw new Error("Got 0 for GetGamePalette request!");
|
||||
}
|
||||
|
||||
private function onResultGetImageData(le:LoaderEvent) : void
|
||||
{
|
||||
var ne:ImageServerEvent = null;
|
||||
var e:ImageServerEvent = new ImageServerEvent(ImageServerEvent.ON_NEW_DATA);
|
||||
e.id = le.entry.id;
|
||||
var o:Object = le.entry.data;
|
||||
if(o == null)
|
||||
{
|
||||
this._imageCacheArray[e.id] = {
|
||||
"id":e.id,
|
||||
"imageData":null,
|
||||
"layer":0,
|
||||
"frames":0
|
||||
};
|
||||
e.success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(o.v != ImageArray.VERSION)
|
||||
{
|
||||
throw new Error("ERROR: Unrecognized version number(" + o.v.toString(16) + ")!");
|
||||
}
|
||||
e.imageData = o;
|
||||
e.layer = this._layerInfo[ImageArrayHelper.layerId(e.id)];
|
||||
e.frames = o.f.length;
|
||||
this._imageCacheArray[e.id] = {
|
||||
"id":e.id,
|
||||
"imageData":o,
|
||||
"layer":e.layer,
|
||||
"frames":e.frames
|
||||
};
|
||||
}
|
||||
this._loaderCacheArray[e.id].l.removeEventListener(LoaderEvent.ON_LOAD_COMPLETE,this.onResultGetImageData);
|
||||
var c:int = int(this._loaderCacheArray[e.id].c);
|
||||
this._loaderCacheArray[e.id] = null;
|
||||
while(c-- > 0)
|
||||
{
|
||||
ne = new ImageServerEvent(ImageServerEvent.ON_NEW_DATA);
|
||||
ne.id = e.id;
|
||||
ne.imageData = e.imageData;
|
||||
ne.layer = e.layer;
|
||||
ne.frames = e.frames;
|
||||
ne.success = e.success;
|
||||
dispatchEvent(ne);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SingletonLock
|
||||
{
|
||||
|
||||
public function SingletonLock()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import com.adobe.crypto.MD5;
|
||||
import com.carlcalderon.arthropod.Debug;
|
||||
import com.sbi.debug.DebugUtility;
|
||||
import flash.net.URLRequest;
|
||||
|
||||
public class LoaderCache
|
||||
{
|
||||
|
||||
public static var cdnSalt:String;
|
||||
|
||||
public static var mainClassNames:Array;
|
||||
|
||||
public static var _contentURL:String = "http://dev-sfs01.smartbombinteractive.com:8008/animal/";
|
||||
|
||||
public static var buildVersion:String = "0";
|
||||
|
||||
public static var deployVersion:String = "0";
|
||||
|
||||
public static var localMode:Boolean = true;
|
||||
|
||||
private static var _clientIp:String = "127.0.0.1";
|
||||
|
||||
private static var _urlIndex:int = 0;
|
||||
|
||||
private var _list:Array = null;
|
||||
|
||||
public function LoaderCache()
|
||||
{
|
||||
super();
|
||||
this._list = new Array();
|
||||
}
|
||||
|
||||
public static function get contentURL() : String
|
||||
{
|
||||
return _contentURL;
|
||||
}
|
||||
|
||||
public static function set contentURL(value:String) : void
|
||||
{
|
||||
var regexp:RegExp = new RegExp("https*://","ig");
|
||||
_contentURL = value.replace(regexp,"");
|
||||
}
|
||||
|
||||
public static function get clientIp() : String
|
||||
{
|
||||
return _clientIp;
|
||||
}
|
||||
|
||||
public static function set clientIp(value:String) : void
|
||||
{
|
||||
_clientIp = value;
|
||||
}
|
||||
|
||||
public static function fetchCDNHash(assetPath:String, cdnRoot:String = "/") : String
|
||||
{
|
||||
var finalHashableString:String = cdnSalt + cdnRoot + assetPath + clientIp;
|
||||
return MD5.hash(finalHashableString);
|
||||
}
|
||||
|
||||
public static function fetchCDNURL(assetPath:String, cdnRoot:String = "/", useDeployVersion:Boolean = true) : String
|
||||
{
|
||||
var cdnURL:String = null;
|
||||
var rootStr:String = cdnRoot;
|
||||
var cdnURLDeployVersionStr:String = "";
|
||||
var deployVersionStr:String = deployVersion;
|
||||
if(deployVersionStr != "0" && useDeployVersion)
|
||||
{
|
||||
cdnURLDeployVersionStr = deployVersionStr + "/";
|
||||
rootStr += cdnURLDeployVersionStr;
|
||||
}
|
||||
var cdnHash:String = fetchCDNHash(assetPath,rootStr);
|
||||
if(useDeployVersion)
|
||||
{
|
||||
cdnURL = "http://" + contentURL + cdnURLDeployVersionStr + assetPath + "?px-hash=" + cdnHash + "&v=" + LoaderCache.buildVersion;
|
||||
}
|
||||
else
|
||||
{
|
||||
cdnURL = "http://" + contentURL + cdnURLDeployVersionStr + assetPath + "?px-hash=" + cdnHash;
|
||||
}
|
||||
Debug.log("CdnURL = " + cdnURL);
|
||||
return cdnURL;
|
||||
}
|
||||
|
||||
public static function fetchCDNURLRequest(assetPath:String, cdnRoot:String = "/", useDeployVersion:Boolean = true) : URLRequest
|
||||
{
|
||||
var cdnURL:String = fetchCDNURL(assetPath,cdnRoot,useDeployVersion);
|
||||
return new URLRequest(cdnURL);
|
||||
}
|
||||
|
||||
public function openFile(swf:String, completeCallback:Function, progressCallback:Function = null, dataFormat:String = "binary") : void
|
||||
{
|
||||
var entry:* = undefined;
|
||||
if(!this.findFile(swf))
|
||||
{
|
||||
entry = this.createLoaderCacheEntry(swf);
|
||||
this._list[swf] = entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugUtility.debugTrace("*LoaderCache name collision: " + swf);
|
||||
}
|
||||
this._list[swf].setCompleteCallback(completeCallback);
|
||||
if(progressCallback != null)
|
||||
{
|
||||
this._list[swf].setProgressCallback(progressCallback);
|
||||
}
|
||||
this._list[swf].load(dataFormat);
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
var key:Object = null;
|
||||
for(key in this._list)
|
||||
{
|
||||
this.remove(String(key));
|
||||
}
|
||||
}
|
||||
|
||||
private function findFile(name:String) : Boolean
|
||||
{
|
||||
return this._list[name] == null ? false : true;
|
||||
}
|
||||
|
||||
public function remove(swf:String) : void
|
||||
{
|
||||
this._list[swf].destroy();
|
||||
this._list[swf] = null;
|
||||
}
|
||||
|
||||
private function createLoaderCacheEntry(swf:String) : *
|
||||
{
|
||||
var l:* = undefined;
|
||||
var i:int = swf.lastIndexOf(".");
|
||||
var ext:String = swf.slice(i + 1,swf.length).toLowerCase();
|
||||
switch(ext)
|
||||
{
|
||||
case "swf":
|
||||
case "png":
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
l = new LoaderCacheEntry_Loader(swf);
|
||||
break;
|
||||
default:
|
||||
l = new LoaderCacheEntry_URL(swf);
|
||||
}
|
||||
l.parent = this;
|
||||
return l;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.display.Loader;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
|
||||
public class LoaderCacheEntry_Base extends EventDispatcher
|
||||
{
|
||||
|
||||
protected var _parent:LoaderCache;
|
||||
|
||||
protected var _loader:*;
|
||||
|
||||
protected var _swf:String;
|
||||
|
||||
protected var _isLoaded:Boolean;
|
||||
|
||||
protected var _completeCallback:Function;
|
||||
|
||||
protected var _data:Object;
|
||||
|
||||
protected var _id:*;
|
||||
|
||||
protected var _contentType:int;
|
||||
|
||||
private var _percent:Number;
|
||||
|
||||
private var _err:String;
|
||||
|
||||
private var _progressCallback:Function;
|
||||
|
||||
public function LoaderCacheEntry_Base(swf:String)
|
||||
{
|
||||
super();
|
||||
this._swf = swf;
|
||||
}
|
||||
|
||||
public function set parent(p:LoaderCache) : void
|
||||
{
|
||||
this._parent = p;
|
||||
}
|
||||
|
||||
public function set id(id:*) : void
|
||||
{
|
||||
this._id = id;
|
||||
}
|
||||
|
||||
public function get id() : *
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public function set contentType(ct:int) : void
|
||||
{
|
||||
this._contentType = ct;
|
||||
}
|
||||
|
||||
public function get contentType() : int
|
||||
{
|
||||
return this._contentType;
|
||||
}
|
||||
|
||||
public function get name() : String
|
||||
{
|
||||
return this._swf;
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
}
|
||||
|
||||
public function load(dataFormat:String = "binary", useDeployVersion:Boolean = true) : void
|
||||
{
|
||||
}
|
||||
|
||||
public function setCompleteCallback(completeCallback:Function) : void
|
||||
{
|
||||
if(this._completeCallback != completeCallback)
|
||||
{
|
||||
if(this._completeCallback != null)
|
||||
{
|
||||
removeEventListener(LoaderEvent.ON_LOAD_COMPLETE,this._completeCallback);
|
||||
}
|
||||
addEventListener(LoaderEvent.ON_LOAD_COMPLETE,completeCallback,false,0,true);
|
||||
this._completeCallback = completeCallback;
|
||||
}
|
||||
}
|
||||
|
||||
public function setProgressCallback(progressCallback:Function) : void
|
||||
{
|
||||
if(this._progressCallback != progressCallback)
|
||||
{
|
||||
if(this._progressCallback != null)
|
||||
{
|
||||
removeEventListener(LoaderEvent.ON_LOAD_PROGRESS,this._progressCallback);
|
||||
}
|
||||
addEventListener(LoaderEvent.ON_LOAD_PROGRESS,progressCallback,false,0,true);
|
||||
this._progressCallback = progressCallback;
|
||||
}
|
||||
}
|
||||
|
||||
public function get progress() : Number
|
||||
{
|
||||
return this._percent;
|
||||
}
|
||||
|
||||
public function get loader() : Loader
|
||||
{
|
||||
return this._loader;
|
||||
}
|
||||
|
||||
public function get data() : Object
|
||||
{
|
||||
return this._data;
|
||||
}
|
||||
|
||||
protected function onLoadCompleteEvent() : void
|
||||
{
|
||||
var newEvt:LoaderEvent = new LoaderEvent(LoaderEvent.ON_LOAD_COMPLETE);
|
||||
newEvt.status = true;
|
||||
newEvt.entry = this;
|
||||
dispatchEvent(newEvt);
|
||||
if(Boolean(this._parent))
|
||||
{
|
||||
this._parent.remove(this._swf);
|
||||
}
|
||||
}
|
||||
|
||||
protected function onLoadProgressEvent() : void
|
||||
{
|
||||
var newEvt:LoaderEvent = new LoaderEvent(LoaderEvent.ON_LOAD_PROGRESS);
|
||||
newEvt.status = true;
|
||||
newEvt.entry = this;
|
||||
newEvt.percent = this._percent;
|
||||
dispatchEvent(newEvt);
|
||||
}
|
||||
|
||||
protected function loadProgress(event:ProgressEvent) : void
|
||||
{
|
||||
this._percent = event.bytesLoaded / event.bytesTotal;
|
||||
this._percent = Math.round(this._percent * 100);
|
||||
this.onLoadProgressEvent();
|
||||
}
|
||||
|
||||
protected function ioError(event:IOErrorEvent) : void
|
||||
{
|
||||
var newEvt:LoaderEvent = new LoaderEvent(LoaderEvent.ON_LOAD_COMPLETE);
|
||||
newEvt.status = false;
|
||||
newEvt.entry = this;
|
||||
newEvt.message = event.text;
|
||||
dispatchEvent(newEvt);
|
||||
if(Boolean(this._parent))
|
||||
{
|
||||
this._parent.remove(this._swf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.display.Loader;
|
||||
import flash.display.LoaderInfo;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.net.URLRequest;
|
||||
import flash.system.ApplicationDomain;
|
||||
import flash.system.LoaderContext;
|
||||
import flash.system.SecurityDomain;
|
||||
|
||||
public class LoaderCacheEntry_Loader extends LoaderCacheEntry_Base
|
||||
{
|
||||
|
||||
public function LoaderCacheEntry_Loader(swf:String)
|
||||
{
|
||||
super(swf);
|
||||
_loader = new Loader();
|
||||
_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,loadProgress,false,0,true);
|
||||
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.loadComplete,false,0,true);
|
||||
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioError,false,0,true);
|
||||
}
|
||||
|
||||
override public function destroy() : void
|
||||
{
|
||||
_loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,loadProgress);
|
||||
_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,this.loadComplete);
|
||||
_loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,ioError);
|
||||
if(_completeCallback != null)
|
||||
{
|
||||
removeEventListener(LoaderEvent.ON_LOAD_COMPLETE,_completeCallback);
|
||||
_completeCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
override public function load(dataFormat:String = "binary", useDeployVersion:Boolean = true) : void
|
||||
{
|
||||
var request:URLRequest = null;
|
||||
var ldrContext:LoaderContext = null;
|
||||
if(!_isLoaded)
|
||||
{
|
||||
if(LoaderCache.localMode && (_swf.slice(0,7) == "assets/" || _swf.slice(0,6) == "games/" || _swf.indexOf("/") == -1))
|
||||
{
|
||||
request = new URLRequest(_swf);
|
||||
}
|
||||
else
|
||||
{
|
||||
request = LoaderCache.fetchCDNURLRequest(_swf,"/",useDeployVersion);
|
||||
}
|
||||
ldrContext = new LoaderContext(true,ApplicationDomain.currentDomain);
|
||||
if(!LoaderCache.localMode)
|
||||
{
|
||||
ldrContext.securityDomain = SecurityDomain.currentDomain;
|
||||
}
|
||||
_loader.load(request,ldrContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
onLoadCompleteEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private function loadComplete(e:Event) : void
|
||||
{
|
||||
_isLoaded = true;
|
||||
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
|
||||
_data = loaderInfo.content;
|
||||
onLoadCompleteEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLRequest;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class LoaderCacheEntry_URL extends LoaderCacheEntry_Base
|
||||
{
|
||||
|
||||
private var _isObj:Boolean;
|
||||
|
||||
public function LoaderCacheEntry_URL(swf:String, isObj:Boolean = true)
|
||||
{
|
||||
super(swf);
|
||||
this._isObj = isObj;
|
||||
_loader = new URLLoader();
|
||||
_loader.addEventListener(ProgressEvent.PROGRESS,loadProgress,false,0,true);
|
||||
_loader.addEventListener(Event.COMPLETE,this.loadComplete,false,0,true);
|
||||
_loader.addEventListener(IOErrorEvent.IO_ERROR,ioError,false,0,true);
|
||||
}
|
||||
|
||||
override public function destroy() : void
|
||||
{
|
||||
_loader.removeEventListener(ProgressEvent.PROGRESS,loadProgress);
|
||||
_loader.removeEventListener(Event.COMPLETE,this.loadComplete);
|
||||
_loader.removeEventListener(IOErrorEvent.IO_ERROR,ioError);
|
||||
if(_completeCallback != null)
|
||||
{
|
||||
removeEventListener(LoaderEvent.ON_LOAD_COMPLETE,_completeCallback);
|
||||
_completeCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
override public function load(dataFormat:String = "binary", useDeployVersion:Boolean = true) : void
|
||||
{
|
||||
var request:URLRequest = null;
|
||||
if(!_isLoaded)
|
||||
{
|
||||
request = LoaderCache.fetchCDNURLRequest(_swf,"/",useDeployVersion);
|
||||
_loader.dataFormat = dataFormat;
|
||||
trace("LoaderCacheEntry_URL - URLLoader.load being called for cdnURL:" + request.url + " dataFormat:" + dataFormat);
|
||||
_loader.load(request);
|
||||
}
|
||||
else
|
||||
{
|
||||
onLoadCompleteEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private function loadComplete(e:Event) : void
|
||||
{
|
||||
var ba:ByteArray = null;
|
||||
var o:Object = null;
|
||||
_isLoaded = true;
|
||||
_data = _loader.data;
|
||||
if(_data is ByteArray)
|
||||
{
|
||||
ba = _loader.data as ByteArray;
|
||||
try
|
||||
{
|
||||
ba.uncompress();
|
||||
}
|
||||
catch(err:Error)
|
||||
{
|
||||
}
|
||||
ba.position = 0;
|
||||
if(this._isObj)
|
||||
{
|
||||
o = ba.readObject();
|
||||
if(ba.bytesAvailable == 0)
|
||||
{
|
||||
_data = o;
|
||||
}
|
||||
else
|
||||
{
|
||||
ba.position = 0;
|
||||
_data = ba;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_data = ba;
|
||||
}
|
||||
}
|
||||
onLoadCompleteEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class LoaderEvent extends Event
|
||||
{
|
||||
|
||||
public static const ON_LOAD_COMPLETE:String = "OnLoadComplete";
|
||||
|
||||
public static const ON_LOAD_PROGRESS:String = "OnLoadProgress";
|
||||
|
||||
public var status:Boolean;
|
||||
|
||||
public var entry:LoaderCacheEntry_Base;
|
||||
|
||||
public var message:String;
|
||||
|
||||
public var percent:Number;
|
||||
|
||||
public function LoaderEvent(type:String)
|
||||
{
|
||||
super(type);
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new LoaderEvent(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import com.sbi.debug.DebugUtility;
|
||||
|
||||
public class ResourceStack
|
||||
{
|
||||
|
||||
private var _stack:Array;
|
||||
|
||||
private var _callback:Function;
|
||||
|
||||
private var _path:String;
|
||||
|
||||
private var _openFile:Function;
|
||||
|
||||
public function ResourceStack(initPath:String, initOpenFile:Function)
|
||||
{
|
||||
super();
|
||||
this._path = initPath;
|
||||
this._openFile = initOpenFile;
|
||||
this._stack = new Array();
|
||||
}
|
||||
|
||||
public function pushFile(file:String, isBlocking:Boolean = false) : void
|
||||
{
|
||||
this._stack.push({
|
||||
"type":"file",
|
||||
"data":file,
|
||||
"isBlocking":isBlocking,
|
||||
"inProgress":false
|
||||
});
|
||||
}
|
||||
|
||||
public function pushClass(classRef:IResourceStackable, isBlocking:Boolean = false) : void
|
||||
{
|
||||
this._stack.push({
|
||||
"type":"class",
|
||||
"data":classRef,
|
||||
"isBlocking":isBlocking,
|
||||
"inProgress":false
|
||||
});
|
||||
}
|
||||
|
||||
public function start(callback:Function) : void
|
||||
{
|
||||
this._callback = callback;
|
||||
this.fifo();
|
||||
}
|
||||
|
||||
private function fifo() : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var o:Object = null;
|
||||
var len:int = int(this._stack.length);
|
||||
DebugUtility.debugTrace("ResourceStack fifo len:" + len);
|
||||
if(!len)
|
||||
{
|
||||
DebugUtility.debugTrace("ResourceStack _callback:" + this._callback);
|
||||
if(this._callback != null)
|
||||
{
|
||||
this._callback();
|
||||
this._callback = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = 0; i < len; i++)
|
||||
{
|
||||
o = this._stack[i];
|
||||
DebugUtility.debugTrace("ResourceStack fifo next - o:" + o + " o.inProgress:" + o.inProgress + " o.type:" + o.type + " o.data:" + o.data + " o.isBlocking:" + o.isBlocking);
|
||||
if(!o.inProgress)
|
||||
{
|
||||
o.inProgress = true;
|
||||
switch(o.type)
|
||||
{
|
||||
case "file":
|
||||
this.loadFile(o.data);
|
||||
break;
|
||||
case "class":
|
||||
o.data.init(this.onInitClassComplete);
|
||||
}
|
||||
i = -1;
|
||||
len = int(this._stack.length);
|
||||
}
|
||||
else if(Boolean(o.isBlocking))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function loadFile(loadTarget:String) : void
|
||||
{
|
||||
var target:String = this._path + loadTarget;
|
||||
this._openFile(target,this.onLoadComplete,this.onLoadProgress);
|
||||
}
|
||||
|
||||
private function onLoadComplete(e:LoaderEvent) : void
|
||||
{
|
||||
if(e.status)
|
||||
{
|
||||
DebugUtility.debugTrace("ResourceStack onLoadComplete e:" + e + " name:" + e.entry.name);
|
||||
this.removeResource("file",e.entry.name);
|
||||
this.fifo();
|
||||
return;
|
||||
}
|
||||
throw new Error("could not load required resource!!! msg:" + e.message);
|
||||
}
|
||||
|
||||
private function onLoadProgress(e:LoaderEvent) : void
|
||||
{
|
||||
}
|
||||
|
||||
private function onInitClassComplete(classRef:IResourceStackable) : void
|
||||
{
|
||||
this.removeResource("class",classRef);
|
||||
this.fifo();
|
||||
}
|
||||
|
||||
private function removeResource(type:String, data:*) : void
|
||||
{
|
||||
var s:Object = null;
|
||||
var len:int = int(this._stack.length);
|
||||
for(var i:int = 0; i < len; i++)
|
||||
{
|
||||
s = this._stack[i];
|
||||
if(s.type == type && s.data == data)
|
||||
{
|
||||
this._stack.splice(i,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,350 @@
|
||||
package com.sbi.loader
|
||||
{
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Loader;
|
||||
import flash.display.LoaderInfo;
|
||||
import flash.display.MovieClip;
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.geom.Point;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.system.ApplicationDomain;
|
||||
import flash.system.LoaderContext;
|
||||
import flash.utils.Dictionary;
|
||||
import localization.LocalizationManager;
|
||||
|
||||
public class SceneLoader extends EventDispatcher
|
||||
{
|
||||
|
||||
public static const LOAD_STATE_NOTLOADED:int = 0;
|
||||
|
||||
public static const LOAD_STATE_LOADING:int = 1;
|
||||
|
||||
public static const LOAD_STATE_LOADED:int = 2;
|
||||
|
||||
private var _offset:Point;
|
||||
|
||||
private var _scene:Object;
|
||||
|
||||
private var _loaderCount:int;
|
||||
|
||||
private var _loader:Array;
|
||||
|
||||
private var _loadedAssets:Dictionary;
|
||||
|
||||
private var _loaderLUT:Dictionary;
|
||||
|
||||
private var _initCount:int;
|
||||
|
||||
private var _loadProgressCallback:Function;
|
||||
|
||||
public var _useDynamicLoading:Boolean;
|
||||
|
||||
public function SceneLoader(loadProgressCallback:Function = null)
|
||||
{
|
||||
super();
|
||||
this._loader = new Array();
|
||||
this._loadProgressCallback = loadProgressCallback;
|
||||
}
|
||||
|
||||
public function getOffset(stage:DisplayObject) : Point
|
||||
{
|
||||
var o:Object = null;
|
||||
var s:Loader = null;
|
||||
var rect:Rectangle = null;
|
||||
var layers:Array = this.getActorList("ActorLayer");
|
||||
for each(o in layers)
|
||||
{
|
||||
s = o.s;
|
||||
rect = s.getBounds(stage);
|
||||
if(rect.x < this._offset.x)
|
||||
{
|
||||
this._offset.x = rect.x;
|
||||
}
|
||||
if(rect.y < this._offset.y)
|
||||
{
|
||||
this._offset.y = rect.y;
|
||||
}
|
||||
}
|
||||
return this._offset;
|
||||
}
|
||||
|
||||
public function get isValid() : Boolean
|
||||
{
|
||||
return this._scene != null;
|
||||
}
|
||||
|
||||
public function get sceneObject() : Object
|
||||
{
|
||||
return this._scene;
|
||||
}
|
||||
|
||||
public function setScene(scene:Object, forceStaticLoad:Boolean = false) : void
|
||||
{
|
||||
this.release();
|
||||
this._scene = scene;
|
||||
this._loadedAssets = new Dictionary();
|
||||
this._loaderLUT = new Dictionary();
|
||||
if(Boolean(scene))
|
||||
{
|
||||
this.loadLayers(forceStaticLoad);
|
||||
}
|
||||
}
|
||||
|
||||
public function getActorList(name:String) : Array
|
||||
{
|
||||
return this._scene.actors[name];
|
||||
}
|
||||
|
||||
public function getLayer(name:String) : Object
|
||||
{
|
||||
return this.findLayer(name);
|
||||
}
|
||||
|
||||
public function cloneAsset(name:String) : Object
|
||||
{
|
||||
var loader:Loader = null;
|
||||
var o:Object = this.findLayer(name);
|
||||
if(Boolean(o))
|
||||
{
|
||||
loader = this.newAsset(o.assetName);
|
||||
loader.x = o.x;
|
||||
loader.y = o.y;
|
||||
o.loader = loader;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
public function release() : void
|
||||
{
|
||||
var l:Loader = null;
|
||||
while(Boolean(this._loader.length))
|
||||
{
|
||||
l = this._loader.pop();
|
||||
l.unloadAndStop();
|
||||
}
|
||||
}
|
||||
|
||||
public function releaseCloneAsset(l:Loader) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var le:Loader = null;
|
||||
while(i < this._loader.length)
|
||||
{
|
||||
le = this._loader[i];
|
||||
if(le == l)
|
||||
{
|
||||
l.unloadAndStop();
|
||||
this._loader.splice(i,1);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public function forceLoadComplete() : void
|
||||
{
|
||||
this._loadProgressCallback(false);
|
||||
}
|
||||
|
||||
private function findLayer(name:String) : Object
|
||||
{
|
||||
var o:Object = null;
|
||||
var i:int = 0;
|
||||
var a:Array = this.getActorList("ActorLayer");
|
||||
name = name.toLowerCase();
|
||||
for(i = 0; i < a.length; i++)
|
||||
{
|
||||
if(a[i].name == name)
|
||||
{
|
||||
o = new Object();
|
||||
o.assetName = a[i].assetName;
|
||||
o.loader = a[i].s;
|
||||
o.height = a[i].s.height;
|
||||
o.width = a[i].s.width;
|
||||
o.x = a[i].s.x;
|
||||
o.y = a[i].s.y;
|
||||
o.flip = a[i].flip;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(o == null)
|
||||
{
|
||||
trace("Layer Not Found: " + name);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
private function newAsset(name:String) : Loader
|
||||
{
|
||||
var l:Loader = null;
|
||||
var i:int = 0;
|
||||
name = name.toLowerCase();
|
||||
for(var a:Array = this._scene.assets; i < a.length; )
|
||||
{
|
||||
if(a[i].name.toLowerCase() == name)
|
||||
{
|
||||
l = new Loader();
|
||||
l.loadBytes(a[i].ba);
|
||||
l.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onNewLoaderComplete);
|
||||
l.cacheAsBitmap = true;
|
||||
this._loader.push(l);
|
||||
return l;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
private function onNewLoaderComplete(e:Event) : void
|
||||
{
|
||||
var l:LoaderInfo = e.target as LoaderInfo;
|
||||
l.removeEventListener(Event.COMPLETE,this.onLoaderComplete);
|
||||
if(l.content is MovieClip && MovieClip(l.content).totalFrames > 1)
|
||||
{
|
||||
l.content.cacheAsBitmap = false;
|
||||
}
|
||||
dispatchEvent(e);
|
||||
}
|
||||
|
||||
public function loadLayer(o:Object) : void
|
||||
{
|
||||
o.loaded = LOAD_STATE_LOADING;
|
||||
this._loaderLUT[o.s] = o;
|
||||
var l:Loader = this.loadAsset(o.assetName,o.s);
|
||||
++this._initCount;
|
||||
}
|
||||
|
||||
public function isValidDynamicAsset(o:Object) : Boolean
|
||||
{
|
||||
return o.name == "" && o.typeIndex != 1 && o.typeIndex != 2 && o.dx == 1 && o.dy == 1;
|
||||
}
|
||||
|
||||
private function loadLayers(forceStaticLoad:Boolean = false) : void
|
||||
{
|
||||
var i:int = 0;
|
||||
var o:Object = null;
|
||||
var l:Loader = null;
|
||||
this._offset = new Point(9999999,9999999);
|
||||
var a:Array = this.getActorList("ActorLayer");
|
||||
this._loaderCount = a.length;
|
||||
this._initCount = 0;
|
||||
if(Boolean(a.length > 0) && Boolean(a[0].hasOwnProperty("top")) && !forceStaticLoad)
|
||||
{
|
||||
this._useDynamicLoading = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._useDynamicLoading = false;
|
||||
}
|
||||
var namedAssetsLoading:Boolean = false;
|
||||
for(i = 0; i < a.length; i++)
|
||||
{
|
||||
o = a[i];
|
||||
o.dx = o.scrollX;
|
||||
o.dy = o.scrollY;
|
||||
if(this._useDynamicLoading)
|
||||
{
|
||||
o.offsetX = o.left - o.x;
|
||||
o.offsetY = o.top - o.y;
|
||||
if(Boolean(o.flip & 1))
|
||||
{
|
||||
o.offsetX -= o.width;
|
||||
}
|
||||
if(Boolean(o.flip & 2))
|
||||
{
|
||||
o.offsetY -= o.height;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
o.offsetX = 0;
|
||||
o.offsetY = 0;
|
||||
}
|
||||
if(this._useDynamicLoading && namedAssetsLoading && this.isValidDynamicAsset(o))
|
||||
{
|
||||
--this._loaderCount;
|
||||
l = new Loader();
|
||||
o.loaded = LOAD_STATE_NOTLOADED;
|
||||
}
|
||||
else
|
||||
{
|
||||
o.loaded = LOAD_STATE_LOADING;
|
||||
this._loadedAssets[o.assetName] = l = this.loadAsset(o.assetName);
|
||||
namedAssetsLoading = true;
|
||||
}
|
||||
o.s = l;
|
||||
this._loaderLUT[l] = o;
|
||||
l.x = Math.round(o.x);
|
||||
l.y = Math.round(o.y);
|
||||
l.rotation = o.rot;
|
||||
l.scaleX = o.scaleX;
|
||||
l.scaleY = o.scaleY;
|
||||
}
|
||||
}
|
||||
|
||||
private function loadAsset(name:String, loader:Loader = null) : Loader
|
||||
{
|
||||
var i:int = 0;
|
||||
var ldrContext:LoaderContext = null;
|
||||
var l:Loader = loader;
|
||||
name = name.toLowerCase();
|
||||
for(var a:Array = this._scene.assets; i < a.length; )
|
||||
{
|
||||
if(a[i].name.toLowerCase() == name)
|
||||
{
|
||||
if(l == null)
|
||||
{
|
||||
l = new Loader();
|
||||
}
|
||||
if(Boolean(a[i].ba))
|
||||
{
|
||||
ldrContext = new LoaderContext(false,ApplicationDomain.currentDomain);
|
||||
l.loadBytes(a[i].ba,ldrContext);
|
||||
l.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onLoaderComplete);
|
||||
l.cacheAsBitmap = true;
|
||||
this._loader.push(l);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
private function onLoaderComplete(e:Event) : void
|
||||
{
|
||||
var l:LoaderInfo = e.target as LoaderInfo;
|
||||
l.removeEventListener(Event.COMPLETE,this.onLoaderComplete);
|
||||
if(l.content is MovieClip)
|
||||
{
|
||||
LocalizationManager.findAllTextfields(l.content);
|
||||
if(MovieClip(l.content).totalFrames > 1)
|
||||
{
|
||||
l.content.cacheAsBitmap = false;
|
||||
}
|
||||
}
|
||||
--this._loaderCount;
|
||||
this._loaderLUT[l.loader].loaded = LOAD_STATE_LOADED;
|
||||
if(this._initCount > 0)
|
||||
{
|
||||
--this._initCount;
|
||||
if(this._initCount == 0)
|
||||
{
|
||||
this._loadProgressCallback(false);
|
||||
}
|
||||
}
|
||||
if(this._loaderCount == 0)
|
||||
{
|
||||
this.allLoadingComplete();
|
||||
}
|
||||
}
|
||||
|
||||
private function allLoadingComplete() : void
|
||||
{
|
||||
var e:Event = new Event(Event.COMPLETE);
|
||||
dispatchEvent(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.sbi.popup
|
||||
{
|
||||
import flash.display.*;
|
||||
import flash.events.*;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFieldAutoSize;
|
||||
|
||||
public dynamic class SBAJOkPopup extends SBPopup
|
||||
{
|
||||
|
||||
protected var _messageText:TextField;
|
||||
|
||||
protected var _titleText:TextField;
|
||||
|
||||
protected var _skin:MovieClip;
|
||||
|
||||
protected var _content:MovieClip;
|
||||
|
||||
protected var _top:MovieClip;
|
||||
|
||||
protected var _mid:MovieClip;
|
||||
|
||||
protected var _bot:MovieClip;
|
||||
|
||||
private var _titleToMessageDifference:int = 5;
|
||||
|
||||
private var _btnTxtGap:int = 10;
|
||||
|
||||
private var _verticalOffset:int = 13;
|
||||
|
||||
private var _okBtn:MovieClip;
|
||||
|
||||
private var _okBtnCallback:Function;
|
||||
|
||||
public function SBAJOkPopup(init_parent:DisplayObjectContainer, init_message:String = null, init_title:String = null, okBtnCallback:Function = null, init_darken:Boolean = true, init_content:MovieClip = null, init_skin:MovieClip = null, autoOpen:Boolean = true, init_enabled:Boolean = true, init_modal:Boolean = false, init_draggable:Boolean = false, init_x:Number = undefined, init_y:Number = undefined, init_width:Number = undefined, init_height:Number = undefined, init_children:Array = null)
|
||||
{
|
||||
if(okBtnCallback != null)
|
||||
{
|
||||
this._okBtnCallback = okBtnCallback;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._okBtnCallback = this.onOkBtn;
|
||||
}
|
||||
this._skin = GETDEFINITIONBYNAME("BroadcastPopupSkin");
|
||||
this._content = GETDEFINITIONBYNAME("BroadcastPopupContent");
|
||||
this._top = this._skin.ba.t;
|
||||
this._mid = this._skin.ba.m;
|
||||
this._bot = this._skin.ba.b;
|
||||
this._okBtn = this._content.okBtn;
|
||||
this._okBtn.addEventListener(MouseEvent.MOUSE_DOWN,this._okBtnCallback,false,0,true);
|
||||
this._messageText = this._content.text;
|
||||
this._titleText = this._content.titleTxt;
|
||||
this._messageText.autoSize = TextFieldAutoSize.CENTER;
|
||||
this._titleText.autoSize = TextFieldAutoSize.CENTER;
|
||||
this.setMessageText(init_message);
|
||||
if(Boolean(init_title))
|
||||
{
|
||||
this._titleText.text = init_title;
|
||||
}
|
||||
super(init_parent,this._skin,this._content,autoOpen,init_enabled,init_modal,init_draggable,init_darken,init_title,init_x,init_y,init_width,init_height,init_children);
|
||||
}
|
||||
|
||||
public static function destroyInParentChain(seekAndDestroy:DisplayObject) : void
|
||||
{
|
||||
while(Boolean(seekAndDestroy) && Boolean(seekAndDestroy != gMainFrame.stage) && !(seekAndDestroy is SBOkPopup))
|
||||
{
|
||||
seekAndDestroy = seekAndDestroy.parent;
|
||||
}
|
||||
if(seekAndDestroy is SBOkPopup)
|
||||
{
|
||||
SBOkPopup(seekAndDestroy).destroy();
|
||||
}
|
||||
}
|
||||
|
||||
override public function destroy() : void
|
||||
{
|
||||
this._okBtn.removeEventListener(MouseEvent.MOUSE_DOWN,this._okBtnCallback);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
public function setMessageText(newText:String) : void
|
||||
{
|
||||
this._messageText.text = newText;
|
||||
this.resize();
|
||||
}
|
||||
|
||||
private function resize() : void
|
||||
{
|
||||
this._mid.height = Math.floor(this._messageText.height);
|
||||
this._mid.y = Math.floor(-(this._mid.height * 0.5));
|
||||
this._top.y = this._mid.y - this._top.height;
|
||||
this._bot.y = this._mid.y + this._mid.height;
|
||||
this._titleText.y = 0;
|
||||
this._messageText.y = this._titleText.height + this._titleToMessageDifference;
|
||||
this._okBtn.y = this._messageText.y + this._messageText.height + this._btnTxtGap + this._okBtn.height * 0.5;
|
||||
this._skin.c.height = this._titleText.height + this._titleToMessageDifference + this._messageText.height + this._btnTxtGap + this._okBtn.height;
|
||||
this._skin.c.y = -(this._skin.ba.height * 0.5) + this._verticalOffset;
|
||||
this._content.x = this._skin.c.x;
|
||||
this._content.y = this._skin.c.y;
|
||||
this._content.width = this._skin.c.width;
|
||||
this._content.height = this._skin.c.height;
|
||||
}
|
||||
|
||||
private function onOkBtn(evt:MouseEvent) : void
|
||||
{
|
||||
evt.stopPropagation();
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.sbi.popup
|
||||
{
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.MovieClip;
|
||||
import flash.text.TextField;
|
||||
|
||||
public dynamic class SBMessage extends SBPopup
|
||||
{
|
||||
|
||||
public var messageTxt:TextField = new TextField();
|
||||
|
||||
public function SBMessage(init_parent:DisplayObjectContainer, init_skin:MovieClip, init_message:String, autoOpen:Boolean = true, init_enabled:Boolean = true, init_modal:Boolean = false, init_draggable:Boolean = true, init_darken:Boolean = false, init_title:String = null, init_x:Number = undefined, init_y:Number = undefined, init_width:Number = undefined, init_height:Number = undefined, init_children:Array = null)
|
||||
{
|
||||
this.messageTxt.text = init_message;
|
||||
super(init_parent,init_skin,this.messageTxt,autoOpen,init_enabled,init_modal,init_draggable,init_darken,init_title,init_x,init_y,init_width,init_height,init_children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.sbi.popup
|
||||
{
|
||||
import flash.display.*;
|
||||
import flash.events.*;
|
||||
import flash.ui.Keyboard;
|
||||
|
||||
public dynamic class SBOkPopup extends SBStandardPopup
|
||||
{
|
||||
|
||||
private var _okBtn:MovieClip;
|
||||
|
||||
private var _okBtnCallback:Function;
|
||||
|
||||
public function SBOkPopup(init_parent:DisplayObjectContainer, init_message:String = null, init_darken:Boolean = true, okBtnCallback:Function = null, autoOpen:Boolean = true, init_enabled:Boolean = true, init_modal:Boolean = false, init_draggable:Boolean = false, init_title:String = null, init_x:Number = undefined, init_y:Number = undefined, init_width:Number = undefined, init_height:Number = undefined, init_children:Array = null)
|
||||
{
|
||||
_verticalOffset = -20;
|
||||
_btnTxtGap = 6;
|
||||
_btnHeight = 44;
|
||||
if(okBtnCallback != null)
|
||||
{
|
||||
this._okBtnCallback = okBtnCallback;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._okBtnCallback = this.onOkBtn;
|
||||
}
|
||||
var skin:MovieClip = GETDEFINITIONBYNAME("OkPopupSkin");
|
||||
var content:MovieClip = GETDEFINITIONBYNAME("OkPopupContent");
|
||||
this._okBtn = content.okBtn;
|
||||
this._okBtn.addEventListener(MouseEvent.MOUSE_DOWN,this._okBtnCallback,false,0,true);
|
||||
_resizeCallback = this.onResize;
|
||||
super(init_parent,init_message,init_darken,content,skin,autoOpen,init_enabled,init_modal,init_draggable,init_title,init_x,init_y,init_width,init_height,init_children);
|
||||
stage.addEventListener(KeyboardEvent.KEY_DOWN,this.handleOkKeyDown,false,0,true);
|
||||
}
|
||||
|
||||
public static function destroyInParentChain(seekAndDestroy:DisplayObject) : void
|
||||
{
|
||||
while(Boolean(seekAndDestroy) && Boolean(seekAndDestroy != gMainFrame.stage) && !(seekAndDestroy is SBOkPopup))
|
||||
{
|
||||
seekAndDestroy = seekAndDestroy.parent;
|
||||
}
|
||||
if(seekAndDestroy is SBOkPopup)
|
||||
{
|
||||
SBOkPopup(seekAndDestroy).destroy();
|
||||
}
|
||||
}
|
||||
|
||||
override public function destroy() : void
|
||||
{
|
||||
this._okBtn.removeEventListener(MouseEvent.MOUSE_DOWN,this._okBtnCallback);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
private function onResize() : void
|
||||
{
|
||||
this._okBtn.y = _text.height + _btnTxtGap + 0.5 * _btnHeight;
|
||||
}
|
||||
|
||||
private function handleOkKeyDown(event:KeyboardEvent) : void
|
||||
{
|
||||
switch(event.keyCode)
|
||||
{
|
||||
case Keyboard.ENTER:
|
||||
case Keyboard.SPACE:
|
||||
this.onOkBtn(event);
|
||||
}
|
||||
}
|
||||
|
||||
private function onOkBtn(evt:Event) : void
|
||||
{
|
||||
evt.stopPropagation();
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
package com.sbi.popup
|
||||
{
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.MovieClip;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.text.TextFieldAutoSize;
|
||||
import gui.DarkenManager;
|
||||
import loader.MediaHelper;
|
||||
|
||||
public dynamic class SBParchmentPopup
|
||||
{
|
||||
|
||||
public static const TYPE_OK:int = 0;
|
||||
|
||||
public static const TYPE_YES_NO:int = 1;
|
||||
|
||||
public static const TYPE_CONTINUE_EXIT:int = 2;
|
||||
|
||||
public static const TYPE_CONTINUE_ONLY:int = 3;
|
||||
|
||||
private var _parent:DisplayObjectContainer;
|
||||
|
||||
private var _type:int;
|
||||
|
||||
private var _message:String;
|
||||
|
||||
private var _darken:Boolean;
|
||||
|
||||
private var _confirmCallback:Function;
|
||||
|
||||
private var _passback:Object;
|
||||
|
||||
private var _mediaHelper:MediaHelper;
|
||||
|
||||
private var _popup:MovieClip;
|
||||
|
||||
public function SBParchmentPopup(init_parent:DisplayObjectContainer, init_type:int = 0, init_message:String = null, init_darken:Boolean = true, init_confirmCallback:Function = null, init_passbackObject:Object = null)
|
||||
{
|
||||
super();
|
||||
DarkenManager.showLoadingSpiral(true);
|
||||
this._parent = init_parent;
|
||||
this._type = init_type;
|
||||
this._message = init_message;
|
||||
this._darken = init_darken;
|
||||
this._confirmCallback = init_confirmCallback;
|
||||
this._passback = init_passbackObject;
|
||||
this._mediaHelper = new MediaHelper();
|
||||
this._mediaHelper.init(2106,this.onMediaLoaded);
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
var idx:int = 0;
|
||||
if(Boolean(this._popup))
|
||||
{
|
||||
DarkenManager.unDarken(this._popup);
|
||||
if(Boolean(this._parent) && Boolean(this._popup.parent) && this._popup.parent == this._parent)
|
||||
{
|
||||
this._parent.removeChild(this._popup);
|
||||
}
|
||||
this._popup.removeEventListener(MouseEvent.MOUSE_DOWN,this.onPopup);
|
||||
switch(this._type)
|
||||
{
|
||||
case TYPE_CONTINUE_EXIT:
|
||||
this._popup.contBtn.removeEventListener(MouseEvent.MOUSE_DOWN,this.onBtnDown);
|
||||
this._popup.exitBtn.removeEventListener(MouseEvent.MOUSE_DOWN,this.onBtnDown);
|
||||
break;
|
||||
case TYPE_CONTINUE_ONLY:
|
||||
this._popup.contOnlyBtn.removeEventListener(MouseEvent.MOUSE_DOWN,this.onBtnDown);
|
||||
break;
|
||||
case TYPE_OK:
|
||||
this._popup.okBtn.removeEventListener(MouseEvent.MOUSE_DOWN,this.onBtnDown);
|
||||
break;
|
||||
case TYPE_YES_NO:
|
||||
this._popup.yesBtn.removeEventListener(MouseEvent.MOUSE_DOWN,this.onBtnDown);
|
||||
this._popup.noBtn.removeEventListener(MouseEvent.MOUSE_DOWN,this.onBtnDown);
|
||||
}
|
||||
idx = SBPopupManager.nonSBPopups.indexOf(this);
|
||||
if(idx >= 0)
|
||||
{
|
||||
SBPopupManager.nonSBPopups.splice(idx,1);
|
||||
}
|
||||
this._popup = null;
|
||||
}
|
||||
}
|
||||
|
||||
private function onMediaLoaded(img:MovieClip) : void
|
||||
{
|
||||
if(Boolean(img))
|
||||
{
|
||||
DarkenManager.showLoadingSpiral(false);
|
||||
this._popup = MovieClip(img.getChildAt(0));
|
||||
this._mediaHelper.destroy();
|
||||
this._mediaHelper = null;
|
||||
switch(this._type)
|
||||
{
|
||||
case TYPE_CONTINUE_EXIT:
|
||||
this._popup.okBtn.visible = false;
|
||||
this._popup.yesBtn.visible = false;
|
||||
this._popup.noBtn.visible = false;
|
||||
this._popup.contOnlyBtn.visible = false;
|
||||
this._popup.contBtn.addEventListener(MouseEvent.MOUSE_DOWN,this.onBtnDown,false,0,true);
|
||||
this._popup.exitBtn.addEventListener(MouseEvent.MOUSE_DOWN,this.onBtnDown,false,0,true);
|
||||
break;
|
||||
case TYPE_CONTINUE_ONLY:
|
||||
this._popup.okBtn.visible = false;
|
||||
this._popup.yesBtn.visible = false;
|
||||
this._popup.noBtn.visible = false;
|
||||
this._popup.exitBtn.visible = false;
|
||||
this._popup.contBtn.visible = false;
|
||||
this._popup.contOnlyBtn.addEventListener(MouseEvent.MOUSE_DOWN,this.onBtnDown,false,0,true);
|
||||
break;
|
||||
case TYPE_OK:
|
||||
this._popup.yesBtn.visible = false;
|
||||
this._popup.noBtn.visible = false;
|
||||
this._popup.contBtn.visible = false;
|
||||
this._popup.exitBtn.visible = false;
|
||||
this._popup.contOnlyBtn.visible = false;
|
||||
this._popup.okBtn.addEventListener(MouseEvent.MOUSE_DOWN,this.onBtnDown,false,0,true);
|
||||
break;
|
||||
case TYPE_YES_NO:
|
||||
this._popup.okBtn.visible = false;
|
||||
this._popup.contBtn.visible = false;
|
||||
this._popup.exitBtn.visible = false;
|
||||
this._popup.contOnlyBtn.visible = false;
|
||||
this._popup.yesBtn.addEventListener(MouseEvent.MOUSE_DOWN,this.onBtnDown,false,0,true);
|
||||
this._popup.noBtn.addEventListener(MouseEvent.MOUSE_DOWN,this.onBtnDown,false,0,true);
|
||||
}
|
||||
this._popup.txt.autoSize = TextFieldAutoSize.CENTER;
|
||||
this._popup.txt.text = this._message;
|
||||
with(this._popup.ba)
|
||||
{
|
||||
|
||||
m.height = Math.floor(_popup.txt.height) + 44 + 8;
|
||||
m.y = Math.floor(-(m.height * 0.5));
|
||||
t.y = m.y - t.height;
|
||||
b.y = m.y + m.height;
|
||||
_popup.txt.y = m.y + 4;
|
||||
_popup.yesBtn.y = m.y + _popup.txt.height + 13;
|
||||
_popup.noBtn.y = m.y + _popup.txt.height + 13;
|
||||
_popup.okBtn.y = m.y + _popup.txt.height + 9;
|
||||
_popup.contBtn.y = m.y + _popup.txt.height + 13;
|
||||
_popup.exitBtn.y = m.y + _popup.txt.height + 13;
|
||||
_popup.contOnlyBtn.y = m.y + _popup.txt.height + 13;
|
||||
}
|
||||
this._popup.addEventListener(MouseEvent.MOUSE_DOWN,this.onPopup,false,0,true);
|
||||
this._popup.x = MainFrame.VIEW_WIDTH * 0.5;
|
||||
this._popup.y = MainFrame.VIEW_HEIGHT * 0.5;
|
||||
this._parent.addChild(this._popup);
|
||||
if(this._darken)
|
||||
{
|
||||
DarkenManager.darken(this._popup);
|
||||
}
|
||||
SBPopupManager.nonSBPopups.push(this);
|
||||
}
|
||||
}
|
||||
|
||||
private function onPopup(evt:MouseEvent) : void
|
||||
{
|
||||
evt.stopPropagation();
|
||||
}
|
||||
|
||||
private function onBtnDown(evt:MouseEvent) : void
|
||||
{
|
||||
var o:Object = null;
|
||||
evt.stopPropagation();
|
||||
if(this._confirmCallback != null)
|
||||
{
|
||||
o = {
|
||||
"status":evt.currentTarget == this._popup.contBtn || evt.currentTarget == this._popup.contOnlyBtn || evt.currentTarget == this._popup.yesBtn || evt.currentTarget == this._popup.okBtn,
|
||||
"passback":this._passback
|
||||
};
|
||||
this.destroy();
|
||||
this._confirmCallback(o);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
package com.sbi.popup
|
||||
{
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.MovieClip;
|
||||
import flash.events.MouseEvent;
|
||||
import gui.DarkenManager;
|
||||
import gui.GuiRadioButtonGroup;
|
||||
import loader.MediaHelper;
|
||||
import localization.LocalizationManager;
|
||||
|
||||
public dynamic class SBPollPopup
|
||||
{
|
||||
|
||||
private static const POLL_POPUP_MEDIA_ID:int = 369;
|
||||
|
||||
private static const POLL_TY_POPUP_MEDIA_ID:int = 370;
|
||||
|
||||
private var _popupLayer:DisplayObjectContainer;
|
||||
|
||||
private var _tab:MovieClip;
|
||||
|
||||
private var _pollDef:Object;
|
||||
|
||||
private var _onVoteCallback:Function;
|
||||
|
||||
private var _onDoneCallback:Function;
|
||||
|
||||
private var _pollPopup:MovieClip;
|
||||
|
||||
private var _pollMediaHelper:MediaHelper;
|
||||
|
||||
private var _thankYouPopup:SBStandardTitlePopup;
|
||||
|
||||
private var _numOptions:int;
|
||||
|
||||
private var _randomizeOrder:Boolean;
|
||||
|
||||
private var _randOptionLookup:Array;
|
||||
|
||||
private var _answerSection:MovieClip;
|
||||
|
||||
private var _optionsGroup:GuiRadioButtonGroup;
|
||||
|
||||
public function SBPollPopup()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function init(initParent:DisplayObjectContainer, initTab:MovieClip, initOnVoteCallback:Function, initOnDoneCallback:Function, initRandomizeOrder:Boolean) : void
|
||||
{
|
||||
this._popupLayer = initParent;
|
||||
this._tab = initTab;
|
||||
this._onVoteCallback = initOnVoteCallback;
|
||||
this._onDoneCallback = initOnDoneCallback;
|
||||
this._randomizeOrder = initRandomizeOrder;
|
||||
this._pollDef = this._tab.def;
|
||||
this._randOptionLookup = [0,1,2,3,4];
|
||||
this._thankYouPopup = new SBStandardTitlePopup(this._popupLayer,LocalizationManager.translateIdOnly(14680),null,370,this._onDoneCallback,false);
|
||||
this._pollMediaHelper = new MediaHelper();
|
||||
this._pollMediaHelper.init(POLL_POPUP_MEDIA_ID,this.onMediaLoaded,true);
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
this._pollPopup.bx.removeEventListener(MouseEvent.MOUSE_DOWN,this.onCloseBtnDown);
|
||||
this._pollPopup.removeEventListener(MouseEvent.MOUSE_DOWN,this.onPopupDown);
|
||||
this._pollPopup = null;
|
||||
this._thankYouPopup.destroy();
|
||||
this._thankYouPopup = null;
|
||||
}
|
||||
|
||||
private function onMediaLoaded(img:MovieClip) : void
|
||||
{
|
||||
if(Boolean(img))
|
||||
{
|
||||
if(img.mediaHelper.id == POLL_POPUP_MEDIA_ID)
|
||||
{
|
||||
this._pollMediaHelper.destroy();
|
||||
this._pollMediaHelper = null;
|
||||
this._pollPopup = MovieClip(img.getChildAt(0));
|
||||
this.setUpPollPopup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function setUpPollPopup() : void
|
||||
{
|
||||
this._pollPopup.bx.addEventListener(MouseEvent.MOUSE_DOWN,this.onCloseBtnDown,false,0,true);
|
||||
this._pollPopup.addEventListener(MouseEvent.MOUSE_DOWN,this.onPopupDown,false,0,true);
|
||||
var text:String = this._pollDef.poll;
|
||||
var firstPipe:int = text.indexOf("|");
|
||||
this._pollPopup.bodyTxt.text = text.substring(0,firstPipe);
|
||||
var pollOptions:Array = text.substring(firstPipe + 1,text.length).split("|");
|
||||
if(this._randomizeOrder)
|
||||
{
|
||||
pollOptions = this.shuffleArray(pollOptions);
|
||||
}
|
||||
this._numOptions = pollOptions.length;
|
||||
this._pollPopup.titleTxt.text = this._pollDef.title;
|
||||
if(this._numOptions == 2)
|
||||
{
|
||||
this._answerSection = this._pollPopup.answer2;
|
||||
this._pollPopup.answer2.visible = true;
|
||||
this._pollPopup.answer3.visible = false;
|
||||
this._pollPopup.answer4.visible = false;
|
||||
this._pollPopup.answer5.visible = false;
|
||||
}
|
||||
else if(this._numOptions == 3)
|
||||
{
|
||||
this._answerSection = this._pollPopup.answer3;
|
||||
this._pollPopup.answer2.visible = false;
|
||||
this._pollPopup.answer3.visible = true;
|
||||
this._pollPopup.answer4.visible = false;
|
||||
this._pollPopup.answer5.visible = false;
|
||||
}
|
||||
else if(this._numOptions == 4)
|
||||
{
|
||||
this._answerSection = this._pollPopup.answer4;
|
||||
this._pollPopup.answer2.visible = false;
|
||||
this._pollPopup.answer3.visible = false;
|
||||
this._pollPopup.answer4.visible = true;
|
||||
this._pollPopup.answer5.visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._answerSection = this._pollPopup.answer5;
|
||||
this._pollPopup.answer2.visible = false;
|
||||
this._pollPopup.answer3.visible = false;
|
||||
this._pollPopup.answer4.visible = false;
|
||||
this._pollPopup.answer5.visible = true;
|
||||
}
|
||||
this._optionsGroup = new GuiRadioButtonGroup(this._answerSection.options);
|
||||
this._answerSection.voteBtn.activateGrayState(true);
|
||||
this._answerSection.voteBtn.addEventListener(MouseEvent.MOUSE_DOWN,this.onVoteBtnDown,false,0,true);
|
||||
for(var i:int = 1; i < this._numOptions + 1; i++)
|
||||
{
|
||||
this._answerSection["answer" + i + "Txt"].text = pollOptions[i - 1];
|
||||
this._answerSection.options["option" + i].addEventListener(MouseEvent.MOUSE_DOWN,this.onOptionSelected,false,0,true);
|
||||
}
|
||||
DarkenManager.showLoadingSpiral(false);
|
||||
this.open(this._pollPopup);
|
||||
}
|
||||
|
||||
private function shuffleArray(a:Array) : Array
|
||||
{
|
||||
var element:String = null;
|
||||
var i:int = 0;
|
||||
var rand:int = 0;
|
||||
var save:int = 0;
|
||||
var length:int = int(a.length);
|
||||
var shuffled:Array = a.slice();
|
||||
while(i < length)
|
||||
{
|
||||
element = shuffled[i];
|
||||
rand = Math.floor(Math.random() * length);
|
||||
if(i != rand)
|
||||
{
|
||||
shuffled[i] = shuffled[rand];
|
||||
shuffled[rand] = element;
|
||||
save = int(this._randOptionLookup[i]);
|
||||
this._randOptionLookup[i] = this._randOptionLookup[rand];
|
||||
this._randOptionLookup[rand] = save;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return shuffled;
|
||||
}
|
||||
|
||||
private function open(popup:MovieClip) : void
|
||||
{
|
||||
this._popupLayer.addChild(popup);
|
||||
popup.x = MainFrame.VIEW_WIDTH * 0.5;
|
||||
popup.y = MainFrame.VIEW_HEIGHT * 0.5;
|
||||
DarkenManager.darken(popup);
|
||||
popup.visible = true;
|
||||
}
|
||||
|
||||
private function close(popup:MovieClip) : void
|
||||
{
|
||||
popup.visible = false;
|
||||
DarkenManager.unDarken(popup);
|
||||
this._popupLayer.removeChild(popup);
|
||||
}
|
||||
|
||||
private function onVoteBtnDown(e:MouseEvent) : void
|
||||
{
|
||||
e.stopPropagation();
|
||||
if(!e.currentTarget.isGray)
|
||||
{
|
||||
if(this._onVoteCallback != null)
|
||||
{
|
||||
this._onVoteCallback(this._tab,this._randOptionLookup[this._optionsGroup.selected] + 1);
|
||||
}
|
||||
this.close(this._pollPopup);
|
||||
this._thankYouPopup.open();
|
||||
}
|
||||
}
|
||||
|
||||
private function onCloseBtnDown(e:MouseEvent) : void
|
||||
{
|
||||
e.stopPropagation();
|
||||
this.close(e.currentTarget.parent);
|
||||
this._onDoneCallback();
|
||||
}
|
||||
|
||||
private function onOptionSelected(e:MouseEvent) : void
|
||||
{
|
||||
e.stopPropagation();
|
||||
if(e.currentTarget == this._answerSection.options.option1)
|
||||
{
|
||||
this._answerSection.options.option1._circle.visible = true;
|
||||
}
|
||||
for(var i:int = 1; i < this._numOptions + 1; i++)
|
||||
{
|
||||
this._answerSection.options["option" + i].removeEventListener(MouseEvent.MOUSE_DOWN,this.onOptionSelected);
|
||||
}
|
||||
this._answerSection.voteBtn.activateGrayState(false);
|
||||
}
|
||||
|
||||
private function onPopupDown(e:MouseEvent) : void
|
||||
{
|
||||
e.stopPropagation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,355 @@
|
||||
package com.sbi.popup
|
||||
{
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.MovieClip;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.MouseEvent;
|
||||
|
||||
public dynamic class SBPopup extends Sprite
|
||||
{
|
||||
|
||||
public var skin:SBPopupSkin;
|
||||
|
||||
public var content:DisplayObject;
|
||||
|
||||
public var popupFilters:Array;
|
||||
|
||||
public var _enabled:Boolean = true;
|
||||
|
||||
public var _selected:Boolean = true;
|
||||
|
||||
public var _modal:Boolean = false;
|
||||
|
||||
public var _darken:Boolean = false;
|
||||
|
||||
public var suppressMouseDown:Boolean = false;
|
||||
|
||||
public var closeCallback:Function;
|
||||
|
||||
public var restoreLastPos:Boolean = true;
|
||||
|
||||
public var lastPosX:Number;
|
||||
|
||||
public var lastPosY:Number;
|
||||
|
||||
public var draggable:Boolean = true;
|
||||
|
||||
public var soundsEnabled:Boolean = true;
|
||||
|
||||
public var bxClosesPopup:Boolean = true;
|
||||
|
||||
public function SBPopup(init_parent:DisplayObjectContainer, init_skin:MovieClip, init_content:DisplayObject, autoOpen:Boolean = true, init_enabled:Boolean = true, init_modal:Boolean = false, init_draggable:Boolean = false, init_darken:Boolean = false, init_title:String = null, init_x:Number = undefined, init_y:Number = undefined, init_width:Number = undefined, init_height:Number = undefined, init_filters:Array = null, init_children:Array = null)
|
||||
{
|
||||
super();
|
||||
this.skin = new SBPopupSkin(init_skin);
|
||||
this.addChild(this.skin.s);
|
||||
if(Boolean(init_content))
|
||||
{
|
||||
this.content = init_content;
|
||||
this.content.name = "content";
|
||||
this.content.x = this.skin.s["c"].x;
|
||||
this.content.y = this.skin.s["c"].y;
|
||||
this.content.width = this.skin.s["c"].width;
|
||||
this.content.height = this.skin.s["c"].height;
|
||||
this.skin.s.addChildAt(this.content,this.skin.s.getChildIndex(this.skin.s["c"]));
|
||||
}
|
||||
this.skin.s["c"].visible = false;
|
||||
if(Boolean(this.skin.s.getChildByName("bx")))
|
||||
{
|
||||
this.skin.s["bx"].addEventListener(MouseEvent.MOUSE_DOWN,this.bxHandler,false,0,true);
|
||||
}
|
||||
init_parent.addChild(this);
|
||||
this.visible = false;
|
||||
width = Boolean(init_width) ? init_width : this.skin.s.width;
|
||||
height = Boolean(init_height) ? init_height : this.skin.s.height;
|
||||
if(Boolean(parent.stage))
|
||||
{
|
||||
x = Boolean(init_x) ? init_x : MainFrame.VIEW_WIDTH * 0.5;
|
||||
y = Boolean(init_y) ? init_y : MainFrame.VIEW_HEIGHT * 0.5;
|
||||
}
|
||||
this.lastPosX = x;
|
||||
this.lastPosY = y;
|
||||
this.modal = init_modal;
|
||||
this.draggable = init_draggable;
|
||||
this.enabled = init_enabled;
|
||||
this.suppressMouseDown = false;
|
||||
this.popupFilters = init_filters;
|
||||
SBPopupManager.popups.push(this);
|
||||
if(init_darken)
|
||||
{
|
||||
this._darken = true;
|
||||
}
|
||||
if(autoOpen)
|
||||
{
|
||||
this.open();
|
||||
}
|
||||
}
|
||||
|
||||
public static function isChildOf(testParent:DisplayObjectContainer, stopParent:DisplayObjectContainer, testChild:DisplayObject) : Boolean
|
||||
{
|
||||
var c:DisplayObject = testChild;
|
||||
while(c != stopParent)
|
||||
{
|
||||
if(c == testParent)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
c = c.parent;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get darken() : Boolean
|
||||
{
|
||||
return this._darken;
|
||||
}
|
||||
|
||||
public function get selected() : Boolean
|
||||
{
|
||||
return this._selected;
|
||||
}
|
||||
|
||||
public function set selected(select:Boolean) : void
|
||||
{
|
||||
if(select)
|
||||
{
|
||||
}
|
||||
this._selected = select;
|
||||
}
|
||||
|
||||
public function get enabled() : Boolean
|
||||
{
|
||||
return this._enabled;
|
||||
}
|
||||
|
||||
public function set enabled(enable:Boolean) : void
|
||||
{
|
||||
if(enable)
|
||||
{
|
||||
mouseChildren = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mouseChildren = false;
|
||||
}
|
||||
this._enabled = enable;
|
||||
}
|
||||
|
||||
override public function set visible(make_visible:Boolean) : void
|
||||
{
|
||||
if(make_visible)
|
||||
{
|
||||
if(this._modal)
|
||||
{
|
||||
SBPopupManager.modalSBPopup = this;
|
||||
}
|
||||
if(this._darken && SBPopupManager.darken != null)
|
||||
{
|
||||
SBPopupManager.darken(this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(this._modal && SBPopupManager.modalSBPopup == this)
|
||||
{
|
||||
SBPopupManager.modalSBPopup = null;
|
||||
}
|
||||
if(!this._darken && SBPopupManager.lighten != null)
|
||||
{
|
||||
SBPopupManager.lighten(this);
|
||||
}
|
||||
}
|
||||
super.visible = make_visible;
|
||||
}
|
||||
|
||||
public function get modal() : Boolean
|
||||
{
|
||||
return Boolean(this._modal && visible);
|
||||
}
|
||||
|
||||
public function set modal(make_modal:Boolean) : void
|
||||
{
|
||||
if(make_modal)
|
||||
{
|
||||
if(visible)
|
||||
{
|
||||
if(Boolean(SBPopupManager.modalSBPopup) && Boolean(SBPopupManager.modalSBPopup != this) && SBPopupManager.modalSBPopup.modal)
|
||||
{
|
||||
throw new Error("Attempted to make two or more modal dialogs active at once!");
|
||||
}
|
||||
SBPopupManager.modalSBPopup = this;
|
||||
}
|
||||
}
|
||||
else if(SBPopupManager.modalSBPopup == this)
|
||||
{
|
||||
SBPopupManager.modalSBPopup = null;
|
||||
}
|
||||
this._modal = make_modal;
|
||||
}
|
||||
|
||||
public function addListeners() : void
|
||||
{
|
||||
addEventListener(MouseEvent.MOUSE_DOWN,this.mouseDownHandler,false,0,true);
|
||||
addEventListener(MouseEvent.MOUSE_UP,this.mouseUpHandler,false,0,true);
|
||||
}
|
||||
|
||||
public function removeListeners() : void
|
||||
{
|
||||
removeEventListener(MouseEvent.MOUSE_DOWN,this.mouseDownHandler);
|
||||
removeEventListener(MouseEvent.MOUSE_UP,this.mouseUpHandler);
|
||||
}
|
||||
|
||||
public function open() : void
|
||||
{
|
||||
if(visible)
|
||||
{
|
||||
trace("WARNING: Tried to open an already opened popup... ignored...");
|
||||
return;
|
||||
}
|
||||
if(this._darken)
|
||||
{
|
||||
if(Boolean(SBPopupManager) && SBPopupManager.darken != null)
|
||||
{
|
||||
SBPopupManager.darken(this);
|
||||
}
|
||||
}
|
||||
this.addListeners();
|
||||
this.setFilters(this.popupFilters);
|
||||
if(Boolean(0))
|
||||
{
|
||||
x = this.lastPosX;
|
||||
y = this.lastPosY;
|
||||
}
|
||||
this.visible = true;
|
||||
if(Boolean(parent))
|
||||
{
|
||||
this.bringToFront();
|
||||
}
|
||||
if(this._modal)
|
||||
{
|
||||
SBPopupManager.modalSBPopup = this;
|
||||
}
|
||||
}
|
||||
|
||||
public function close() : void
|
||||
{
|
||||
if(!visible)
|
||||
{
|
||||
trace("WARNING: Tried to close an already closed popup... ignored...");
|
||||
return;
|
||||
}
|
||||
if(this._darken)
|
||||
{
|
||||
if(Boolean(SBPopupManager) && SBPopupManager.lighten != null)
|
||||
{
|
||||
SBPopupManager.lighten(this);
|
||||
}
|
||||
}
|
||||
this.removeListeners();
|
||||
this.setFilters([]);
|
||||
this.lastPosX = x;
|
||||
this.lastPosY = y;
|
||||
this.visible = false;
|
||||
if(this._modal)
|
||||
{
|
||||
if(SBPopupManager.modalSBPopup == this)
|
||||
{
|
||||
SBPopupManager.modalSBPopup = null;
|
||||
}
|
||||
}
|
||||
if(this.closeCallback != null)
|
||||
{
|
||||
this.closeCallback();
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy() : void
|
||||
{
|
||||
if(visible)
|
||||
{
|
||||
this.close();
|
||||
}
|
||||
if(Boolean(this.skin) && Boolean(this.skin.s))
|
||||
{
|
||||
removeChild(this.skin.s);
|
||||
if(Boolean(this.content))
|
||||
{
|
||||
this.skin.s.removeChild(this.content);
|
||||
this.content = null;
|
||||
}
|
||||
this.skin.s = null;
|
||||
}
|
||||
this.closeCallback = null;
|
||||
if(Boolean(parent))
|
||||
{
|
||||
parent.removeChild(this);
|
||||
}
|
||||
var idx:int = SBPopupManager.popups.indexOf(this);
|
||||
if(idx > 0)
|
||||
{
|
||||
SBPopupManager.popups.splice(idx,1);
|
||||
}
|
||||
}
|
||||
|
||||
public function setFilters(newFilters:Array = null) : void
|
||||
{
|
||||
}
|
||||
|
||||
public function bxHandler(m:MouseEvent) : void
|
||||
{
|
||||
m.stopPropagation();
|
||||
if(visible && this.bxClosesPopup)
|
||||
{
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
||||
public function bringContentToFront() : void
|
||||
{
|
||||
this.skin.s.setChildIndex(this.content,this.skin.s.getChildIndex(this.skin.s["c"]));
|
||||
}
|
||||
|
||||
public function mouseDownHandler(m:MouseEvent) : void
|
||||
{
|
||||
m.stopPropagation();
|
||||
if(this.suppressMouseDown)
|
||||
{
|
||||
this.suppressMouseDown = false;
|
||||
return;
|
||||
}
|
||||
if(!(m.target is DisplayObject))
|
||||
{
|
||||
throw new Error("mouseDownHandler mouse event got a non-DisplayObject object!");
|
||||
}
|
||||
if(this.draggable && SBPopupManager.checkModalSBPopup(this,true) && (Boolean(SBPopup.isChildOf(this.skin.s["ba"],this,DisplayObject(m.target)) || m.target == this.content) || Boolean(this.content is DisplayObjectContainer && DisplayObjectContainer(this.content).getChildByName("titleDragBar") && m.target == this.content["titleDragBar"])))
|
||||
{
|
||||
startDrag();
|
||||
}
|
||||
}
|
||||
|
||||
public function bringToFront() : void
|
||||
{
|
||||
parent.setChildIndex(this,parent.numChildren - 1);
|
||||
}
|
||||
|
||||
public function mouseUpHandler(m:MouseEvent) : void
|
||||
{
|
||||
m.stopPropagation();
|
||||
if(!(m.target is DisplayObject))
|
||||
{
|
||||
throw new Error("mouseDownHandler mouse event got a non-DisplayObject object!");
|
||||
}
|
||||
if(this.draggable && SBPopupManager.checkModalSBPopup(this,false) && (Boolean(SBPopup.isChildOf(this.skin.s["ba"],this,DisplayObject(m.target)) || m.target == this.content) || Boolean(this.content is DisplayObjectContainer && DisplayObjectContainer(this.content).getChildByName("titleDragBar") && m.target == this.content["titleDragBar"])))
|
||||
{
|
||||
stopDrag();
|
||||
}
|
||||
}
|
||||
|
||||
public function get closeBtn() : MovieClip
|
||||
{
|
||||
return this.skin.s["bx"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
package com.sbi.popup
|
||||
{
|
||||
import flash.filters.*;
|
||||
|
||||
public class SBPopupManager
|
||||
{
|
||||
|
||||
public static var _selected:SBPopup;
|
||||
|
||||
public static var _modalSBPopup:SBPopup;
|
||||
|
||||
public static var _prevModalSBPopup:SBPopup;
|
||||
|
||||
public static var darken:Function;
|
||||
|
||||
public static var lighten:Function;
|
||||
|
||||
public static var popups:Array = [];
|
||||
|
||||
public static var nonSBPopups:Array = [];
|
||||
|
||||
public static var enabled:Boolean = true;
|
||||
|
||||
public function SBPopupManager()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function get selected() : SBPopup
|
||||
{
|
||||
return _selected;
|
||||
}
|
||||
|
||||
public static function set selected(select:SBPopup) : void
|
||||
{
|
||||
if(select.selected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
select.selected = true;
|
||||
_selected = select;
|
||||
}
|
||||
|
||||
public static function get modalSBPopup() : SBPopup
|
||||
{
|
||||
return _modalSBPopup;
|
||||
}
|
||||
|
||||
public static function set modalSBPopup(newModal:SBPopup) : void
|
||||
{
|
||||
var p:SBPopup = null;
|
||||
var tempPrev:SBPopup = null;
|
||||
for each(p in popups)
|
||||
{
|
||||
if(p != newModal)
|
||||
{
|
||||
p.enabled = newModal == null;
|
||||
}
|
||||
}
|
||||
tempPrev = _prevModalSBPopup;
|
||||
if(Boolean(newModal) && Boolean(_modalSBPopup) && newModal != _modalSBPopup)
|
||||
{
|
||||
_prevModalSBPopup = _modalSBPopup;
|
||||
}
|
||||
_modalSBPopup = newModal;
|
||||
if(_modalSBPopup == null && Boolean(tempPrev))
|
||||
{
|
||||
_modalSBPopup = tempPrev;
|
||||
_prevModalSBPopup = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function checkModalSBPopup(toCheck:SBPopup, down:Boolean) : Boolean
|
||||
{
|
||||
if(_modalSBPopup == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(_modalSBPopup != toCheck)
|
||||
{
|
||||
if(down)
|
||||
{
|
||||
_modalSBPopup.alpha = 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
_modalSBPopup.alpha = 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getBlurFilter(blurAmountX:Number = 2, blurAmountY:Number = 2, blurQuality:int = 3) : BlurFilter
|
||||
{
|
||||
var blurFilter:BlurFilter = new BlurFilter();
|
||||
blurFilter.blurX = blurAmountX;
|
||||
blurFilter.blurY = blurAmountY;
|
||||
blurFilter.quality = blurQuality;
|
||||
return blurFilter;
|
||||
}
|
||||
|
||||
public static function getColorFilter(a:Number = 1, r:Number = 1, g:Number = 1, b:Number = 1) : ColorMatrixFilter
|
||||
{
|
||||
var colorMatrix:Array = new Array();
|
||||
colorMatrix = colorMatrix.concat([r,0,0,0,0]);
|
||||
colorMatrix = colorMatrix.concat([0,g,0,0,0]);
|
||||
colorMatrix = colorMatrix.concat([0,0,b,0,0]);
|
||||
colorMatrix = colorMatrix.concat([0,0,0,a,0]);
|
||||
return new ColorMatrixFilter(colorMatrix);
|
||||
}
|
||||
|
||||
public static function setAllPopupEffects(popupFilters:Array = null) : void
|
||||
{
|
||||
var p:SBPopup = null;
|
||||
for each(p in popups)
|
||||
{
|
||||
p.setFilters(popupFilters);
|
||||
}
|
||||
}
|
||||
|
||||
public static function setAllModalPopupEffects(popupFilters:Array = null) : void
|
||||
{
|
||||
var p:SBPopup = null;
|
||||
for each(p in popups)
|
||||
{
|
||||
if(p.modal)
|
||||
{
|
||||
p.setFilters(popupFilters);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function closeAll() : void
|
||||
{
|
||||
var p:SBPopup = null;
|
||||
modalSBPopup = null;
|
||||
for each(p in popups)
|
||||
{
|
||||
if(p.visible)
|
||||
{
|
||||
p.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function destroyAll() : void
|
||||
{
|
||||
var p:SBPopup = null;
|
||||
modalSBPopup = null;
|
||||
for each(p in popups)
|
||||
{
|
||||
p.destroy();
|
||||
}
|
||||
while(popups.length > 0)
|
||||
{
|
||||
popups.pop();
|
||||
}
|
||||
}
|
||||
|
||||
public static function destroyNonSBPopups() : void
|
||||
{
|
||||
var p:Object = null;
|
||||
for each(p in nonSBPopups)
|
||||
{
|
||||
p.destroy();
|
||||
}
|
||||
while(nonSBPopups.length > 0)
|
||||
{
|
||||
nonSBPopups.pop();
|
||||
}
|
||||
}
|
||||
|
||||
public static function destroySpecificNonSBPopup(o:Object) : void
|
||||
{
|
||||
for(var i:int = 0; i < nonSBPopups.length; i++)
|
||||
{
|
||||
if(nonSBPopups[i] == o)
|
||||
{
|
||||
nonSBPopups.splice(i,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.sbi.popup
|
||||
{
|
||||
import flash.display.MovieClip;
|
||||
|
||||
public dynamic class SBPopupSkin
|
||||
{
|
||||
|
||||
public var s:MovieClip;
|
||||
|
||||
public function SBPopupSkin(init_s:MovieClip)
|
||||
{
|
||||
super();
|
||||
this.s = init_s;
|
||||
if(!(Boolean(this.s["c"]) && Boolean(this.s["ba"])))
|
||||
{
|
||||
throw new Error("skin " + this.s.name + " is missing parts!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loaded 100 of 7925 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user