RedHero Loader Code

Posts 1–11 of 11 · Page 1 of 1
RedHero Loader Code
Thought I'd post a separate thread here, because I'm pretty sure others have requested it in the past.
Messy but functioning loader code for RedHero.

If you don't know how to use it, go here: https://www.mpgh.net/forum/showthread.php?t=1117012

Code:
import flash.events.Event;
import flash.net.URLRequest;
import flash.net.URLRequestHeader;
import flash.external.ExternalInterface;

stop();
//Comments by Oliboli8769
//CHANGES FOR THE LOADING BAR ARE IN CAPS

Security.allowDomain("*");
//URLs as Strings used for easiness
var sFile; //used to store game version string
var versionLoader: URLLoader;
var Game: Object;
var swfContext: LoaderContext;
var swfLoader: Loader;
var swfRequest: URLRequest;
var gameToken: String;

getToken();

function GetVersion() {
	//checks for most recent game version from ASP file
	versionLoader = new URLLoader();
	versionLoader.addEventListener(Event.COMPLETE, onVersionComplete); //adds event listener for when the ASP is loaded
	versionLoader.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);
	versionLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpHandler);
	versionLoader.load(new URLRequest("https://redhero.online/responses/game/version")); //same as https://aqworldscdn.aq.com/game/gameversion.asp
}
function httpHandler(e: HTTPStatusEvent) {
	trace("http: " + e);
}
function loaderIOErrorHandler(e: IOErrorEvent) {
	trace("ioErrorHandler: " + e);
}
function onVersionComplete(param1: Event) {
	var vars: URLVariables;
	vars = new URLVariables(param1.target.data); //reads variables held on loaded AS
	if (vars.status == "success") //checks the 'status' var on ASP
	{
		sFile = vars.sFile; //reads game version linkage and saves as the variable sFile
		LoadGame(); //now the version is found, we can load the game
	}
}
function LoadGame() {
	swfContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
	swfLoader = new Loader();
	swfRequest = new URLRequest("https://redhero.online/gamefiles/" + sFile); //using sFile from before as updated game linkage
	//swfRequest = new URLRequest("https://www.augoeides.org/gamefiles/Client-04.24.16-HP.Rr9.swf");
	swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onGameComplete); //adds event listener for the game load
	swfLoader.contentLoaderInfo.addEventListener(flash.events.ProgressEvent.PROGRESS, onGameProgress); //adds event listener for how much the game has loaded
	swfLoader.load(swfRequest, swfContext);
	stage.quality = StageQuality.LOW; //sets stage quality to low, possibly reducing lag (optional)
}
function onGameComplete(loadEvent: Event) {
	stage.addChildAt(loadEvent.currentTarget.content, 0); //adds the loaded game content to the stage
	loadEvent.currentTarget.content.y = 0.0;
	loadEvent.currentTarget.content.x = 0.0;
	Game = Object(loadEvent.currentTarget.content); //stores loaded content onto the Object Game
	Game.params.sTitle = "Trainer Tutorial By OB";
	Game.params.sURL = "https://redhero.online/";
	Game.params.token = gameToken;
	loadingBar.visible = false;
}

function getToken() {
	var url: String = "https://redhero.online/game/play";

	var request: URLRequest = new URLRequest();
	request.method = URLRequestMethod.POST;
	request.url = url;

	var loader: URLLoader = new URLLoader();
	loader.addEventListener(Event.COMPLETE, handleSuccess);

	loader.load(request);
}
function handleSuccess(e: Event) {
	//I know this is really messy but it works. As far as I know AS3 doesn't have a nice HTML parser.
	var received = e.target.data;
	var short = received.substring(received.indexOf('<meta name="csrf-token"'), received.indexOf('<meta name="csrf-token"') + 76);
	short = short + "</meta>";
	var xmlData = new XML(short);
	gameToken = xmlData.attributes()[1];
	trace("Game token is: " + gameToken);
	GetVersion();
}

function onGameProgress(arg1: flash.events.ProgressEvent): void {
	//this can be used for progress bars/loaders before trainers
	//CHANGES THE X SCALE OF THE LOADING BAR BY 
	var percentage: *= arg1.bytesLoaded / arg1.bytesTotal;
	trace(percentage * 100); //traces how much the game has loaded as a percentage
	loadingBar.scaleX = percentage; //WHERE THE SCALE CHANGE TAKES PLACE
	return;
}
Loading infinitely in "joining lobby"
Quote Originally Posted by Haros View Post
Loading infinitely in "joining lobby"
You need to target flash version 10.3 in your publish settings.
Done! I need more time to fix shop loader. Thanks
Quest Loader, Bank, Custom Armor, Walk Speed Done 100%
Quote Originally Posted by Haros View Post
Done! I need more time to fix shop loader. Thanks
Quest Loader, Bank, Custom Armor, Walk Speed Done 100%
Nice one! Glad it came in useful. Have fun
Symbol 'loadingBar', Layer 'Layer 1', Frame 1, Line 53 1120: Access of undefined property loadingBar.
Symbol 'loadingBar', Layer 'Layer 1', Frame 1, Line 60 1120: Access of undefined property loadingBar.
i get this error
Quote Originally Posted by ylertaoz View Post
Symbol 'loadingBar', Layer 'Layer 1', Frame 1, Line 53 1120: Access of undefined property loadingBar.
Symbol 'loadingBar', Layer 'Layer 1', Frame 1, Line 60 1120: Access of undefined property loadingBar.
i get this error
Comment out those lines with "//" before them.
Line : 63 loadingBar.visible = false;
Line : 94 loadingBar.scaleX = percentage; //WHERE THE SCALE CHANGE TAKES PLACE
Quote Originally Posted by ylertaoz View Post
Line : 63 loadingBar.visible = false;
Line : 94 loadingBar.scaleX = percentage; //WHERE THE SCALE CHANGE TAKES PLACE
Just use this:

Code:
import flash.events.Event;
import flash.net.URLRequest;
import flash.net.URLRequestHeader;
import flash.external.ExternalInterface;

stop();
//Comments by Oliboli8769
//CHANGES FOR THE LOADING BAR ARE IN CAPS

Security.allowDomain("*");
//URLs as Strings used for easiness
var sFile; //used to store game version string
var versionLoader: URLLoader;
var Game: Object;
var swfContext: LoaderContext;
var swfLoader: Loader;
var swfRequest: URLRequest;
var gameToken: String;

getToken();

function GetVersion() {
	//checks for most recent game version from ASP file
	versionLoader = new URLLoader();
	versionLoader.addEventListener(Event.COMPLETE, onVersionComplete); //adds event listener for when the ASP is loaded
	versionLoader.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);
	versionLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpHandler);
	versionLoader.load(new URLRequest("https://redhero.online/responses/game/version")); //same as https://aqworldscdn.aq.com/game/gameversion.asp
}
function httpHandler(e: HTTPStatusEvent) {
	trace("http: " + e);
}
function loaderIOErrorHandler(e: IOErrorEvent) {
	trace("ioErrorHandler: " + e);
}
function onVersionComplete(param1: Event) {
	var vars: URLVariables;
	vars = new URLVariables(param1.target.data); //reads variables held on loaded AS
	if (vars.status == "success") //checks the 'status' var on ASP
	{
		sFile = vars.sFile; //reads game version linkage and saves as the variable sFile
		LoadGame(); //now the version is found, we can load the game
	}
}
function LoadGame() {
	swfContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
	swfLoader = new Loader();
	swfRequest = new URLRequest("https://redhero.online/gamefiles/" + sFile); //using sFile from before as updated game linkage
	//swfRequest = new URLRequest("https://www.augoeides.org/gamefiles/Client-04.24.16-HP.Rr9.swf");
	swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onGameComplete); //adds event listener for the game load
	swfLoader.contentLoaderInfo.addEventListener(flash.events.ProgressEvent.PROGRESS, onGameProgress); //adds event listener for how much the game has loaded
	swfLoader.load(swfRequest, swfContext);
	stage.quality = StageQuality.LOW; //sets stage quality to low, possibly reducing lag (optional)
}
function onGameComplete(loadEvent: Event) {
	stage.addChildAt(loadEvent.currentTarget.content, 0); //adds the loaded game content to the stage
	loadEvent.currentTarget.content.y = 0.0;
	loadEvent.currentTarget.content.x = 0.0;
	Game = Object(loadEvent.currentTarget.content); //stores loaded content onto the Object Game
	Game.params.sTitle = "Trainer Tutorial By OB";
	Game.params.sURL = "https://redhero.online/";
	Game.params.token = gameToken;
}

function getToken() {
	var url: String = "https://redhero.online/game/play";

	var request: URLRequest = new URLRequest();
	request.method = URLRequestMethod.POST;
	request.url = url;

	var loader: URLLoader = new URLLoader();
	loader.addEventListener(Event.COMPLETE, handleSuccess);

	loader.load(request);
}
function handleSuccess(e: Event) {
	//I know this is really messy but it works. As far as I know AS3 doesn't have a nice HTML parser.
	var received = e.target.data;
	var short = received.substring(received.indexOf('<meta name="csrf-token"'), received.indexOf('<meta name="csrf-token"') + 76);
	short = short + "</meta>";
	var xmlData = new XML(short);
	gameToken = xmlData.attributes()[1];
	trace("Game token is: " + gameToken);
	GetVersion();
}

function onGameProgress(arg1: flash.events.ProgressEvent): void {
	//this can be used for progress bars/loaders before trainers
	//CHANGES THE X SCALE OF THE LOADING BAR BY 
	var percentage: *= arg1.bytesLoaded / arg1.bytesTotal;
	trace(percentage * 100); //traces how much the game has loaded as a percentage
	return;
}
Posts 1–11 of 11 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us