Section 1
//Background (mochicrypt.Background)
package mochicrypt {
import flash.display.*;
public class Background extends Bitmap {
public function Background(){
super();
}
}
}//package mochicrypt
Section 2
//Config (mochicrypt.Config)
package mochicrypt {
import mochicrypt.*;
class Config {
private static const data:Object = new ConfigData().readObject();
function Config(){
super();
}
public static function getBool(key:String, def:Boolean):Boolean{
return (((data[key] is Boolean)) ? data[key] : def);
}
public static function getInt(key:String, def:int):int{
return (((data[key] is int)) ? data[key] : def);
}
public static function getString(key:String, def:String):String{
return (((data[key] is String)) ? data[key] : def);
}
}
}//package mochicrypt
Section 3
//ConfigData (mochicrypt.ConfigData)
package mochicrypt {
import flash.utils.*;
public class ConfigData extends ByteArray {
public function ConfigData(){
super();
}
}
}//package mochicrypt
Section 4
//Payload (mochicrypt.Payload)
package mochicrypt {
import flash.utils.*;
public class Payload extends ByteArray {
public function Payload(){
super();
}
}
}//package mochicrypt
Section 5
//Preloader (mochicrypt.Preloader)
package mochicrypt {
import flash.events.*;
import flash.display.*;
import flash.net.*;
import flash.utils.*;
import flash.system.*;
public 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(event:ProgressEvent):void{
if (event.bytesLoaded == event.bytesTotal){
patchProgress = NaN;
} else {
patchProgress = (Number(event.bytesLoaded) / event.bytesTotal);
};
progress();
}
private function adIOErrorHandler(event: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 (width:Number, height:Number):void{
trace("adLoaded called");
theme.adLoaded(width, height);
};
obj.adjustProgress = function (msec:Number):void{
trace("adjustProgress called");
adServerControl = true;
adStarted = getTimer();
adDuration = msec;
};
obj.adjustFrameRate = function (newFrameRate:Number):void{
var newFrameRate = newFrameRate;
if (!isNaN(origFrameRate)){
stage.frameRate = newFrameRate;
};
//unresolved jump
var _slot1 = error;
trace("couldn't adjust stage.frameRate", newFrameRate);
};
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();
data = patchLoader.content["patch"](data);
//unresolved jump
var _slot1 = error;
trace("patch failed", _slot1);
if (!isNaN(origFrameRate)){
stage.frameRate = origFrameRate;
};
//unresolved jump
var _slot1 = error;
trace("resetting frameRate failed", _slot1);
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;
System.gc();
}
private function enterFrameHandler(event:Event):void{
progress();
if (((!(payloadDone)) && ((currentFrame == 2)))){
payloadDone = true;
finish();
};
}
private function initHandler(event:Event):void{
var event = event;
origFrameRate = stage.frameRate;
//unresolved jump
var _slot1 = error;
trace("can't access stage.frameRate in initHandler", _slot1);
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);
adLoader.load(req);
//unresolved jump
var _slot1 = error;
adDone = true;
patchLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, patchIOErrorHandler);
patchLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, patchProgressHandler);
patchLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, patchCompleteHandler);
patchLoader.load(new URLRequest(PATCH_URL));
//unresolved jump
var _slot1 = error;
patchDone = true;
theme = new Theme(adLoader, loaderInfo.width, loaderInfo.height);
addChild(theme);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
finish();
}
private function progressHandler(event:ProgressEvent):void{
if (event.bytesLoaded == event.bytesTotal){
payloadProgress = NaN;
} else {
payloadProgress = (Number(event.bytesLoaded) / event.bytesTotal);
};
progress();
}
private function completeHandler(event:Event):void{
nextFrame();
}
private function ioErrorHandler(event:IOErrorEvent):void{
}
private function patchCompleteHandler(event:Event):void{
patchDone = true;
finish();
}
private function progress():void{
var currProgress:Number;
currProgress = 1;
if (!adDone){
currProgress = (Number((getTimer() - adStarted)) / adDuration);
};
if (((((!(payloadDone)) && (!(isNaN(payloadProgress))))) && ((payloadProgress < currProgress)))){
currProgress = payloadProgress;
};
if (((((!(patchDone)) && (!(isNaN(patchProgress))))) && ((patchProgress < currProgress)))){
currProgress = patchProgress;
};
if (currProgress > 1){
currProgress = 1;
};
if (currProgress > lastProgress){
lastProgress = currProgress;
theme.updateProgress(lastProgress);
};
if (((!(adServerControl)) && ((getTimer() > (adStarted + adDuration))))){
trace("giving up... maybe?");
if (!adComplete){
adLoader.close();
};
adDone = true;
finish();
};
}
private function patchIOErrorHandler(event:IOErrorEvent):void{
patchDone = true;
finish();
}
private function adCompleteHandler(event: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(ad:DisplayObject, w:Number, h:Number){
progressBar = new Sprite();
barBackground = new Shape();
barForeground = new Shape();
barOutline = new Shape();
super();
var background:Bitmap = new Background();
background.width = w;
background.height = h;
setupProgressBar(w, h);
addChild(background);
addChild(ad);
addChild(progressBar);
}
public function adLoaded(width:Number, height:Number):void{
}
private function setupProgressBar(w:Number, h:Number):void{
var g:Graphics;
g = barBackground.graphics;
g.beginFill(BAR_BACK_COLOR);
g.drawRect(0, 0, (w - 20), 10);
g.endFill();
g = barForeground.graphics;
g.beginFill(BAR_FORE_COLOR);
g.drawRect(0, 0, (w - 20), 10);
g.endFill();
g = barOutline.graphics;
g.lineStyle(0, BAR_OUTLINE_COLOR);
g.drawRect(0, 0, (w - 20), 10);
progressBar.addChild(barBackground);
progressBar.addChild(barForeground);
progressBar.addChild(barOutline);
barForeground.scaleX = 0;
progressBar.x = 10;
progressBar.y = (h - 20);
}
public function updateProgress(progress:Number):void{
barForeground.scaleX = progress;
}
}
}//package mochicrypt