Section 1
//Background (mochicrypt.Background)
package mochicrypt {
import flash.display.*;
public class Background extends Bitmap {
}
}//package mochicrypt
Section 2
//Config (mochicrypt.Config)
package mochicrypt {
import mochicrypt.*;
class Config {
private static const data:Object = new ConfigData().readObject();
public static function getBool(_arg1:String, _arg2:Boolean):Boolean{
return (((data[_arg1] is Boolean)) ? data[_arg1] : _arg2);
}
public static function getInt(_arg1:String, _arg2:int):int{
return (((data[_arg1] is int)) ? data[_arg1] : _arg2);
}
public static function getString(_arg1:String, _arg2:String):String{
return (((data[_arg1] is String)) ? data[_arg1] : _arg2);
}
}
}//package mochicrypt
Section 3
//ConfigData (mochicrypt.ConfigData)
package mochicrypt {
import flash.utils.*;
public class ConfigData extends ByteArray {
}
}//package mochicrypt
Section 4
//Payload (mochicrypt.Payload)
package mochicrypt {
import flash.utils.*;
public class Payload extends ByteArray {
}
}//package mochicrypt
Section 5
//Preloader (mochicrypt.Preloader)
package mochicrypt {
import flash.events.*;
import flash.display.*;
import flash.net.*;
import flash.utils.*;
public dynamic class Preloader extends MovieClip {
private var payloadLoader:Loader;
private var patchLoader:Loader;
private var adDone:Boolean;// = false
private var theme:Theme;
private var adServerControl:Boolean;// = false
private var adLoader:Loader;
private var adDuration:int;// = 11000
private var payloadProgress:Number;// = 0
private var patchProgress:Number;// = 0
private var adStarted:int;
private var lastProgress:Number;// = 0
private var patchDisabled:Boolean;// = false
private var patchDone:Boolean;// = false
private var payloadDone:Boolean;// = false
private var origFrameRate:Number;// = NAN
private var adComplete:Boolean;// = false
private var lc:LocalConnection;
private static const AD_BACKGROUND:Boolean = Config.getBool("adBackground", false);
private static const AD_URL:String = Config.getString("adURL", "http://x.mochiads.com/srv/1/");
private static const PATCH_URL:String = Config.getString("patchURL", "http://cdn.mochiads.com/patch.swf");
private static const ID:String = Config.getString("id", "test");
private static const PAYLOAD_NAME:String = "mochicrypt.Payload";
private static const VERSION:String = "2.3c";
public function Preloader(){
lc = new LocalConnection();
adLoader = new Loader();
patchLoader = new Loader();
adStarted = getTimer();
super();
loaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
loaderInfo.addEventListener(Event.INIT, initHandler);
loaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}
private function patchProgressHandler(_arg1:ProgressEvent):void{
if (_arg1.bytesLoaded == _arg1.bytesTotal){
patchProgress = NaN;
} else {
patchProgress = (Number(_arg1.bytesLoaded) / _arg1.bytesTotal);
};
progress();
}
private function adIOErrorHandler(_arg1:IOErrorEvent):void{
adDone = true;
finish();
}
private function makeLCClient():Object{
var obj:Object = {};
obj.unloadAd = function ():void{
trace("unloadAd");
adDone = true;
finish();
};
obj.adSkipped = function ():void{
trace("adSkipped");
adDone = true;
finish();
};
obj.adLoaded = function (_arg1:Number, _arg2:Number):void{
trace("adLoaded called");
theme.adLoaded(_arg1, _arg2);
};
obj.adjustProgress = function (_arg1:Number):void{
trace("adjustProgress called");
adServerControl = true;
adStarted = getTimer();
adDuration = _arg1;
};
obj.adjustFrameRate = function (_arg1:Number):void{
var newFrameRate = _arg1;
try {
if (!isNaN(origFrameRate)){
stage.frameRate = newFrameRate;
};
} catch(error:Error) {
trace("couldn't adjust stage.frameRate", error);
};
};
obj.disablePatch = function ():void{
patchDisabled = true;
};
return (obj);
}
private function finish():void{
var i:uint;
var j:uint;
var k:uint;
var n:uint;
var u:uint;
var v:uint;
if (((((!(payloadDone)) || (!(adDone)))) || (!(patchDone)))){
return;
};
if (payloadLoader){
trace("unexpected call to finish()");
return;
};
var payloadClass:Class = Class(getDefinitionByName(PAYLOAD_NAME));
var data:ByteArray = ByteArray(new (payloadClass));
trace("data.length", data.length);
var S:ByteArray = new ByteArray();
n = (data.length - 16);
i = 0;
while (i < 0x0100) {
S.writeByte(i);
i = (i + 1);
};
j = 0;
i = 0;
while (i < 0x0100) {
j = (((j + S[i]) + data[(n + (i & 15))]) & 0xFF);
u = S[i];
S[i] = S[j];
S[j] = u;
i = (i + 1);
};
if (n > 131072){
n = 131072;
};
var _local2:int;
j = _local2;
i = _local2;
k = 0;
while (k < n) {
i = ((i + 1) & 0xFF);
u = S[i];
j = ((j + u) & 0xFF);
v = S[j];
S[i] = v;
S[j] = u;
data[k] = (data[k] ^ S[((u + v) & 0xFF)]);
k = (k + 1);
};
data.uncompress();
try {
data = patchLoader.content["patch"](data);
} catch(error:Error) {
trace("patch failed", error);
};
try {
if (!isNaN(origFrameRate)){
stage.frameRate = origFrameRate;
};
} catch(error:Error) {
trace("resetting frameRate failed", error);
};
payloadLoader = new Loader();
addChild(payloadLoader);
payloadLoader.loadBytes(data);
patchLoader.unload();
adLoader.unload();
trace("ad should be gone...");
removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
loaderInfo.removeEventListener(ProgressEvent.PROGRESS, progressHandler);
loaderInfo.removeEventListener(Event.INIT, initHandler);
loaderInfo.removeEventListener(Event.COMPLETE, completeHandler);
loaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
patchLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, patchIOErrorHandler);
patchLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, patchProgressHandler);
patchLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, patchCompleteHandler);
adLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, adIOErrorHandler);
lc.close();
removeChild(theme);
theme.removeChild(adLoader);
lc = null;
adLoader = null;
patchLoader = null;
theme = null;
}
private function enterFrameHandler(_arg1:Event):void{
progress();
if (((!(payloadDone)) && ((currentFrame == 2)))){
payloadDone = true;
finish();
};
}
private function initHandler(_arg1:Event):void{
var event = _arg1;
try {
origFrameRate = stage.frameRate;
} catch(error:Error) {
trace("can't access stage.frameRate in initHandler", error);
};
var lcName:String = ["", Math.floor(new Date().getTime()), Math.floor((Math.random() * 999999))].join("_");
lc.client = makeLCClient();
lc.allowDomain("*", "x.mochiads.com");
lc.allowInsecureDomain("*", "x.mochiads.com");
lc.connect(lcName);
adLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, adIOErrorHandler);
adLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, adCompleteHandler);
var lv:URLVariables = new URLVariables();
lv.id = ID;
lv.res = ((("" + loaderInfo.width) + "x") + loaderInfo.height);
lv.method = "showPreloaderAd";
lv.swfv = loaderInfo.swfVersion;
lv.mav = VERSION;
lv.lc = lcName;
lv.st = getTimer();
lv.as3_swf = loaderInfo.loaderURL;
lv.no_bg = !(AD_BACKGROUND);
var req:URLRequest = new URLRequest(((AD_URL + ID) + ".swf"));
req.contentType = "application/x-www-form-urlencoded";
req.method = URLRequestMethod.POST;
req.data = lv;
adLoader.x = (0.5 * loaderInfo.width);
adLoader.y = (0.5 * loaderInfo.height);
try {
adLoader.load(req);
} catch(error:Error) {
adDone = true;
};
patchLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, patchIOErrorHandler);
patchLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, patchProgressHandler);
patchLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, patchCompleteHandler);
try {
patchLoader.load(new URLRequest(PATCH_URL));
} catch(error:Error) {
patchDone = true;
};
theme = new Theme(adLoader, loaderInfo.width, loaderInfo.height);
addChild(theme);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
finish();
}
private function progressHandler(_arg1:ProgressEvent):void{
if (_arg1.bytesLoaded == _arg1.bytesTotal){
payloadProgress = NaN;
} else {
payloadProgress = (Number(_arg1.bytesLoaded) / _arg1.bytesTotal);
};
progress();
}
private function completeHandler(_arg1:Event):void{
nextFrame();
}
private function ioErrorHandler(_arg1:IOErrorEvent):void{
}
private function patchCompleteHandler(_arg1:Event):void{
patchDone = true;
finish();
}
private function progress():void{
var _local1:Number;
_local1 = 1;
if (!adDone){
_local1 = (Number((getTimer() - adStarted)) / adDuration);
};
if (((((!(payloadDone)) && (!(isNaN(payloadProgress))))) && ((payloadProgress < _local1)))){
_local1 = payloadProgress;
};
if (((((!(patchDone)) && (!(isNaN(patchProgress))))) && ((patchProgress < _local1)))){
_local1 = patchProgress;
};
if (_local1 > 1){
_local1 = 1;
};
if (_local1 > lastProgress){
lastProgress = _local1;
theme.updateProgress(lastProgress);
};
if (((!(adServerControl)) && ((getTimer() > (adStarted + adDuration))))){
trace("giving up... maybe?");
if (!adComplete){
adLoader.close();
};
adDone = true;
finish();
};
}
private function patchIOErrorHandler(_arg1:IOErrorEvent):void{
patchDone = true;
finish();
}
private function adCompleteHandler(_arg1:Event):void{
if (!adServerControl){
adStarted = getTimer();
};
adComplete = true;
progress();
}
}
}//package mochicrypt
Section 6
//Theme (mochicrypt.Theme)
package mochicrypt {
import flash.display.*;
import mochicrypt.*;
class Theme extends Sprite {
private var barBackground:Shape;
private var barForeground:Shape;
private var progressBar:Sprite;
private var barOutline:Shape;
private static const BAR_BACK_COLOR:int = Config.getInt("barBackColor", 16777161);
private static const BAR_OUTLINE_COLOR:int = Config.getInt("barOutlineColor", 13994812);
private static const BAR_FORE_COLOR:int = Config.getInt("barForeColor", 0xFF8A00);
function Theme(_arg1:DisplayObject, _arg2:Number, _arg3:Number){
progressBar = new Sprite();
barBackground = new Shape();
barForeground = new Shape();
barOutline = new Shape();
super();
var _local4:Bitmap = new Background();
_local4.width = _arg2;
_local4.height = _arg3;
setupProgressBar(_arg2, _arg3);
addChild(_local4);
addChild(_arg1);
addChild(progressBar);
}
public function adLoaded(_arg1:Number, _arg2:Number):void{
}
private function setupProgressBar(_arg1:Number, _arg2:Number):void{
var _local3:Graphics;
_local3 = barBackground.graphics;
_local3.beginFill(BAR_BACK_COLOR);
_local3.drawRect(0, 0, (_arg1 - 20), 10);
_local3.endFill();
_local3 = barForeground.graphics;
_local3.beginFill(BAR_FORE_COLOR);
_local3.drawRect(0, 0, (_arg1 - 20), 10);
_local3.endFill();
_local3 = barOutline.graphics;
_local3.lineStyle(0, BAR_OUTLINE_COLOR);
_local3.drawRect(0, 0, (_arg1 - 20), 10);
progressBar.addChild(barBackground);
progressBar.addChild(barForeground);
progressBar.addChild(barOutline);
barForeground.scaleX = 0;
progressBar.x = 10;
progressBar.y = (_arg2 - 20);
}
public function updateProgress(_arg1:Number):void{
barForeground.scaleX = _arg1;
}
}
}//package mochicrypt