Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import actor.Player;
- import flash.desktop.Clipboard;
- import flash.desktop.ClipboardFormats;
- import flash.events.NetStatusEvent;
- import flash.net.SharedObject;
- import flash.net.SharedObjectFlushStatus;
- import mx.utils.StringUtil;
- import net.flashpunk.FP;
- import net.flashpunk.utils.Key;
- public class Saver
- {
- private static var MIN_DISK_SPACE:int = 2000;
- public var cookie:SharedObject;
- public var found_save_data:Boolean;
- private var _pass_code:String;
- public function Saver()
- {
- super();
- this.cookie = SharedObject.getLocal("qhtsp122/phoenotopia/save","/");
- if(this.cookie.data.game_data == undefined)
- {
- this.found_save_data = false;
- this.cookie.data.game_data = new Array(this._BlankSave(),this._BlankSave(),this._BlankSave());
- this.cookie.flush(MIN_DISK_SPACE);
- }
- else
- {
- this.found_save_data = true;
- this._GrowSaveDataFilesIfNecessary(this.cookie);
- }
- }
- private function _GrowSaveDataFilesIfNecessary(param1:SharedObject) : void
- {
- var _loc2_:Array = null;
- if(param1.data.game_data[0].length != 19)
- {
- return;
- }
- var _loc3_:int = 0;
- while(_loc3_ < 3)
- {
- _loc2_ = param1.data.game_data[_loc3_];
- _loc2_[19] = 90;
- _loc2_[20] = 88;
- _loc2_[21] = 67;
- _loc2_[22] = 83;
- _loc2_[23] = 0;
- _loc2_[24] = 0;
- _loc2_[25] = 0;
- _loc2_[26] = 0;
- _loc2_[27] = 0;
- _loc2_[28] = 0;
- _loc2_[29] = 0;
- _loc2_[30] = 0;
- _loc2_[31] = 0;
- _loc2_[32] = 0;
- _loc2_[33] = 0;
- _loc2_[34] = 0;
- _loc3_++;
- }
- param1.flush(MIN_DISK_SPACE);
- }
- public function QuitSave() : void
- {
- var _loc1_:int = FP.game_world.save_index_being_used;
- var _loc2_:SaveFileX = FP.game_world.local_save;
- var _loc3_:int = _loc2_.accumulated_time_played + 0.001 * (FP.game_world.GetTime() - _loc2_.time_started_playing);
- this.cookie.data.game_data[_loc1_][11] = _loc2_.times_died + 1;
- this.cookie.data.game_data[_loc1_][12] = _loc3_;
- this.cookie.flush(MIN_DISK_SPACE);
- }
- public function SaveGame(param1:Boolean = false) : void
- {
- var _loc2_:int = FP.game_world.save_index_being_used;
- var _loc3_:SaveFileX = FP.game_world.local_save;
- var _loc4_:Player = FP.game_world.player;
- if(param1)
- {
- this.cookie.data.game_data[_loc2_][9][351] = true;
- this.cookie.flush(MIN_DISK_SPACE);
- return;
- }
- this.CopyArray(_loc3_.inventory[0],this.cookie.data.game_data[_loc2_][8][0]);
- this.CopyArray(_loc3_.inventory[1],this.cookie.data.game_data[_loc2_][8][1]);
- this.CopyArray(_loc3_.inventory[2],this.cookie.data.game_data[_loc2_][8][2]);
- this.CopyArray(_loc3_.keys,this.cookie.data.game_data[_loc2_][10]);
- this.CopyArray(_loc3_.general,this.cookie.data.game_data[_loc2_][9]);
- var _loc5_:int = _loc3_.accumulated_time_played + 0.001 * (FP.game_world.GetTime() - _loc3_.time_started_playing);
- this.cookie.data.game_data[_loc2_] = new Array(_loc3_.game_room,_loc3_.game_time,_loc4_.max_hp,_loc4_.hp,_loc4_.x,_loc4_.y,_loc3_.coins,_loc4_.weapon_equipped,this.cookie.data.game_data[_loc2_][8],this.cookie.data.game_data[_loc2_][9],this.cookie.data.game_data[_loc2_][10],_loc3_.times_died,_loc5_,_loc3_.space_rocks,_loc3_.tool_equipped,_loc3_.coins_collected_total,_loc3_.boxes_broken_count,_loc3_.good_food_consumed,_loc3_.bad_food_consumed,Key.JUMP,Key.ACTION,Key.TOOL,Key.MENU,0,0,0,0,0,0,0,0,0,0,0,0);
- this.SuperFlush();
- this.UpdatePassCode();
- }
- public function SuperFlush() : void
- {
- var _loc1_:String = this.cookie.flush(MIN_DISK_SPACE);
- if(_loc1_ == SharedObjectFlushStatus.FLUSHED)
- {
- FP.game_world.texter.DisplayItemGet("O >> Game Saved!<< _____");
- FP.game_world.sound_g.savegame.play();
- }
- else
- {
- FP.game_world.sound_g.gale_bump.play();
- FP.game_world.texter.DisplayItemGet("O >> Failed to Save!<< _____");
- this.cookie.addEventListener(NetStatusEvent.NET_STATUS,this._OnFlushStatus);
- }
- }
- private function _OnFlushStatus(param1:NetStatusEvent) : void
- {
- switch(param1.info.code)
- {
- case "SharedObject.Flush.Success":
- break;
- case "SharedObject.Flush.Failed":
- }
- this.cookie.removeEventListener(NetStatusEvent.NET_STATUS,this._OnFlushStatus);
- }
- public function EraseGame(param1:int) : void
- {
- this.cookie.data.game_data[param1] = this._BlankSave();
- this.cookie.flush(MIN_DISK_SPACE);
- }
- public function CopyGame(param1:int, param2:int) : void
- {
- var _loc3_:Array = this.cookie.data.game_data[param1];
- var _loc4_:Array = this.cookie.data.game_data[param2];
- _loc4_[0] = new String(_loc3_[0]);
- _loc4_[1] = _loc3_[1];
- _loc4_[2] = _loc3_[2];
- _loc4_[3] = _loc3_[3];
- _loc4_[4] = _loc3_[4];
- _loc4_[5] = _loc3_[5];
- _loc4_[6] = _loc3_[6];
- _loc4_[7] = _loc3_[7];
- this.CopyArray(_loc3_[8][0],_loc4_[8][0]);
- this.CopyArray(_loc3_[8][1],_loc4_[8][1]);
- this.CopyArray(_loc3_[8][2],_loc4_[8][2]);
- this.CopyArray(_loc3_[9],_loc4_[9]);
- this.CopyArray(_loc3_[10],_loc4_[10]);
- _loc4_[11] = _loc3_[11];
- _loc4_[12] = _loc3_[12];
- _loc4_[13] = _loc3_[13];
- _loc4_[14] = _loc3_[14];
- _loc4_[15] = _loc3_[15];
- _loc4_[16] = _loc3_[16];
- _loc4_[17] = _loc3_[17];
- _loc4_[18] = _loc3_[18];
- _loc4_[19] = _loc3_[19];
- _loc4_[20] = _loc3_[20];
- _loc4_[21] = _loc3_[21];
- _loc4_[22] = _loc3_[22];
- _loc4_[23] = _loc3_[23];
- _loc4_[24] = _loc3_[24];
- _loc4_[25] = _loc3_[25];
- _loc4_[26] = _loc3_[26];
- _loc4_[27] = _loc3_[27];
- _loc4_[28] = _loc3_[28];
- _loc4_[29] = _loc3_[29];
- _loc4_[30] = _loc3_[30];
- _loc4_[31] = _loc3_[31];
- _loc4_[32] = _loc3_[32];
- _loc4_[33] = _loc3_[33];
- _loc4_[34] = _loc3_[34];
- this.cookie.flush(MIN_DISK_SPACE);
- }
- private function _BlankSave() : Array
- {
- return new Array("room_05",0,20,20,1724,402,0,0,[[0,0,0,0,0,0,0,1,1],[0,0,0,0,0,0,0,1,1],[0,0,0,0,53,0,0,0,0]],this.CreateBooleanArray(FP.NUM_SAVE_INDEXES),this.CreateBooleanArray(20),0,0,0,0,0,0,0,0,90,88,67,83,0,0,0,0,0,0,0,0,0,0,0,0);
- }
- public function MarkGeneralArray(param1:int, param2:Boolean = true) : Boolean
- {
- FP.sponsor_api.SaveIndexCheckMedals(param1);
- var _loc3_:Boolean = FP.game_world.local_save.general[param1];
- FP.game_world.local_save.general[param1] = param2;
- return _loc3_ != param2;
- }
- public function CheckGeneralArray(param1:int) : Boolean
- {
- return FP.game_world.local_save.general[param1];
- }
- public function GetSaveFile(param1:SaveFileX = null) : SaveFileX
- {
- var _loc2_:Array = this.cookie.data.game_data[FP.game_world.save_index_being_used];
- if(param1 == null)
- {
- param1 = new SaveFileX();
- }
- param1.game_room = _loc2_[0];
- param1.game_time = _loc2_[1];
- param1.player_maxhp = _loc2_[2];
- param1.player_hp = _loc2_[3];
- param1.player_x = _loc2_[4];
- param1.player_y = _loc2_[5];
- param1.coins = _loc2_[6];
- param1.equipped_club = _loc2_[7];
- var _loc3_:Array = this.CreateBooleanArray(8);
- var _loc4_:Array = this.CreateBooleanArray(8);
- var _loc5_:Array = this.CreateBooleanArray(8);
- this.CopyArray(_loc2_[8][0],_loc3_);
- this.CopyArray(_loc2_[8][1],_loc4_);
- this.CopyArray(_loc2_[8][2],_loc5_);
- param1.inventory = [_loc3_,_loc4_,_loc5_];
- var _loc6_:Array = this.CreateBooleanArray(FP.NUM_SAVE_INDEXES);
- this.CopyArray(_loc2_[9],_loc6_);
- param1.general = _loc6_;
- var _loc7_:Array = this.CreateBooleanArray(10);
- this.CopyArray(_loc2_[10],_loc7_);
- param1.keys = _loc7_;
- param1.times_died = _loc2_[11];
- param1.accumulated_time_played = _loc2_[12];
- param1.space_rocks = _loc2_[13];
- param1.tool_equipped = _loc2_[14];
- param1.coins_collected_total = _loc2_[15];
- param1.boxes_broken_count = _loc2_[16];
- param1.good_food_consumed = _loc2_[17];
- param1.bad_food_consumed = _loc2_[18];
- Key.JUMP = _loc2_[19];
- Key.ACTION = _loc2_[20];
- Key.TOOL = _loc2_[21];
- Key.MENU = _loc2_[22];
- return param1;
- }
- private function CreateBooleanArray(param1:int) : Array
- {
- var _loc2_:Array = new Array();
- var _loc3_:int = 0;
- while(_loc3_ < param1)
- {
- _loc2_.push(false);
- _loc3_++;
- }
- return _loc2_;
- }
- public function CopyArray(param1:Array, param2:Array) : void
- {
- var _loc3_:int = 0;
- while(_loc3_ < param1.length)
- {
- param2[_loc3_] = param1[_loc3_];
- _loc3_++;
- }
- }
- public function UpdatePassCode() : void
- {
- var _loc1_:Array = this.cookie.data.game_data[FP.game_world.save_index_being_used];
- var _loc2_:Date = new Date();
- var _loc3_:String = String(_loc2_.fullYear) + "-" + (_loc2_.month < 10?"0" + String(_loc2_.month):String(_loc2_.month)) + "-" + (_loc2_.day < 10?"0" + String(_loc2_.day):String(_loc2_.day)) + "-" + String(_loc2_.hours) + ":" + String(_loc2_.minutes);
- this._pass_code = "PHOENOTOPIA-" + _loc3_ + "-___" + Base64.encode(this._GameDataArrayToString(_loc1_)) + "___";
- }
- public function WritePasswordToClipboard() : void
- {
- Clipboard.generalClipboard.clear();
- Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT,this._pass_code,false);
- }
- public function UsedPassCode(param1:String) : String
- {
- var decoded_passcode:String = null;
- var new_game_data:Array = null;
- var pass_code:String = param1;
- if(this.cookie.data.game_data[FP.game_world.save_index_being_used][1] != 0)
- {
- return "Pass code can only be used on blank files!";
- }
- var stripped_pass_code:String = this._StripPassCode(pass_code);
- try
- {
- decoded_passcode = Base64.decode(stripped_pass_code);
- new_game_data = this._StringToGameDataArray(decoded_passcode);
- }
- catch(error:Error)
- {
- return "Incorrect Password. Cannot create file!";
- }
- this.cookie.data.game_data[FP.game_world.save_index_being_used] = new_game_data;
- this.cookie.flush(MIN_DISK_SPACE);
- return "SUCCESS!";
- }
- private function _StripPassCode(param1:String) : String
- {
- var _loc2_:Array = param1.split("_");
- var _loc3_:int = 0;
- while(_loc3_ < _loc2_.length)
- {
- if((_loc2_[_loc3_] as String).length > 200)
- {
- return _loc2_[_loc3_] as String;
- }
- _loc3_ = _loc3_ + 1;
- }
- return "Bad Password!";
- }
- public function _GameDataArrayToString(param1:Array) : String
- {
- var _loc3_:String = StringUtil.substitute("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25},{26},{27},{28},{29},{30},{31},{32},{33},{34}",param1[0],param1[1],param1[2],param1[3],param1[4],param1[5],param1[6],param1[7],this._StringifyNumArray(param1[8][0]) + this._StringifyNumArray(param1[8][1]) + this._StringifyNumArray(param1[8][2]),this._StringifyBooleanArray(param1[9]),this._StringifyKeyArray(param1[10]),param1[11],param1[12],param1[13],param1[14],param1[15],param1[16],param1[17],param1[18],param1[19],param1[20],param1[21],param1[22],param1[23],param1[24],param1[25],param1[26],param1[27],param1[28],param1[29],param1[30],param1[31],param1[32],param1[33],param1[34]);
- return _loc3_;
- }
- private function _StringToGameDataArray(param1:String) : Array
- {
- var _loc2_:Array = new Array();
- var _loc3_:Array = param1.split(",");
- _loc2_.push(_loc3_[0]);
- _loc2_.push(int(_loc3_[1]));
- _loc2_.push(int(_loc3_[2]));
- _loc2_.push(int(_loc3_[3]));
- _loc2_.push(int(_loc3_[4]));
- _loc2_.push(int(_loc3_[5]));
- _loc2_.push(int(_loc3_[6]));
- _loc2_.push(int(_loc3_[7]));
- _loc2_.push(this._ParseItemString(_loc3_[8]));
- _loc2_.push(this._ParseSaveIndexString(_loc3_[9]));
- _loc2_.push(this._ParseKeyString(_loc3_[10]));
- _loc2_.push(int(_loc3_[11]));
- var _loc4_:int = int(_loc3_[12]);
- if(_loc4_ < 3840)
- {
- _loc4_ = 3840;
- }
- _loc2_.push(_loc4_);
- _loc2_.push(int(_loc3_[13]));
- _loc2_.push(int(_loc3_[14]));
- _loc2_.push(int(_loc3_[15]));
- _loc2_.push(int(_loc3_[16]));
- _loc2_.push(int(_loc3_[17]));
- _loc2_.push(int(_loc3_[18]));
- _loc2_.push(int(_loc3_[19]));
- _loc2_.push(int(_loc3_[20]));
- _loc2_.push(int(_loc3_[21]));
- _loc2_.push(int(_loc3_[22]));
- _loc2_.push(int(_loc3_[23]));
- _loc2_.push(int(_loc3_[24]));
- _loc2_.push(int(_loc3_[25]));
- _loc2_.push(int(_loc3_[26]));
- _loc2_.push(int(_loc3_[27]));
- _loc2_.push(int(_loc3_[28]));
- _loc2_.push(int(_loc3_[29]));
- _loc2_.push(int(_loc3_[30]));
- _loc2_.push(int(_loc3_[31]));
- _loc2_.push(int(_loc3_[32]));
- _loc2_.push(int(_loc3_[33]));
- _loc2_.push(int(_loc3_[34]));
- return _loc2_;
- }
- private function _ParseKeyString(param1:String) : Array
- {
- var _loc2_:Array = param1.split("_");
- var _loc3_:Array = new Array();
- var _loc7_:int = 0;
- while(_loc7_ < _loc2_.length)
- {
- if(_loc2_[_loc7_] == "-1")
- {
- _loc3_.push(false);
- }
- else if(_loc2_[_loc7_] != "")
- {
- _loc3_.push(int(_loc2_[_loc7_]));
- }
- _loc7_ = _loc7_ + 1;
- }
- return _loc3_;
- }
- private function _ParseSaveIndexString(param1:String) : Array
- {
- var _loc2_:Array = new Array();
- var _loc5_:int = 0;
- var _loc6_:int = 0;
- var _loc7_:int = 0;
- while(_loc7_ < param1.length)
- {
- if(param1.charAt(_loc7_) == "ABCDEFGHIJKLM01234".charAt(_loc5_))
- {
- _loc2_.push(true);
- _loc5_ = (_loc5_ + 1) % "ABCDEFGHIJKLM01234".length;
- }
- else if(param1.charAt(_loc7_) == "NOPQRSTUVWXYZ56789".charAt(_loc6_))
- {
- _loc2_.push(false);
- _loc6_ = (_loc6_ + 1) % "NOPQRSTUVWXYZ56789".length;
- }
- else
- {
- throw new Error("Bad Password");
- }
- _loc7_ = _loc7_ + 1;
- }
- return _loc2_;
- }
- private function _ParseItemString(param1:String) : Array
- {
- var _loc2_:Array = param1.split("_");
- var _loc3_:Array = new Array();
- var _loc4_:Array = new Array();
- var _loc5_:Array = new Array();
- var _loc6_:int = 0;
- while(_loc6_ < _loc2_.length)
- {
- if(_loc6_ < 9)
- {
- _loc3_.push(int(_loc2_[_loc6_]));
- }
- else if(_loc6_ < 18)
- {
- _loc4_.push(int(_loc2_[_loc6_]));
- }
- else if(_loc6_ < 27)
- {
- _loc5_.push(int(_loc2_[_loc6_]));
- }
- _loc6_ = _loc6_ + 1;
- }
- return new Array(_loc3_,_loc4_,_loc5_);
- }
- private function _StringifyNumArray(param1:Array) : String
- {
- var _loc2_:String = "";
- var _loc3_:int = 0;
- while(_loc3_ < param1.length)
- {
- _loc2_ = _loc2_ + (param1[_loc3_] + "_");
- _loc3_ = _loc3_ + 1;
- }
- return _loc2_;
- }
- private function _StringifyKeyArray(param1:Array) : String
- {
- var _loc2_:* = "";
- var _loc3_:int = 0;
- while(_loc3_ < param1.length)
- {
- if(param1[_loc3_] == false)
- {
- _loc2_ = _loc2_ + "-1_";
- }
- else
- {
- _loc2_ = _loc2_ + (param1[_loc3_] + "_");
- }
- _loc3_ = _loc3_ + 1;
- }
- return _loc2_;
- }
- private function _StringifyBooleanArray(param1:Array) : String
- {
- var _loc2_:String = "";
- var _loc3_:int = 0;
- var _loc4_:int = 0;
- var _loc7_:int = 0;
- while(_loc7_ < param1.length)
- {
- if(param1[_loc7_])
- {
- _loc2_ = _loc2_ + "ABCDEFGHIJKLM01234".charAt(_loc3_);
- _loc3_ = (_loc3_ + 1) % "ABCDEFGHIJKLM01234".length;
- }
- else
- {
- _loc2_ = _loc2_ + "NOPQRSTUVWXYZ56789".charAt(_loc4_);
- _loc4_ = (_loc4_ + 1) % "NOPQRSTUVWXYZ56789".length;
- }
- _loc7_ = _loc7_ + 1;
- }
- return _loc2_;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement