Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private var parameters : String[];
- private var headers : Hashtable = new Hashtable();
- private var encoding : System.Text.Encoding = new System.Text.UTF8Encoding();
- private var rad : String = "/g8236klvBQ#&|;Zb*7CEA59%s`Oue1wziFp$rDVY@TKxUPWytSaGHJ>dmoMR^<0~4qNLhc(I+fjn)X";
- private var sbox : int[];
- private var key : int[];
- private var n : int;
- private var URL : String;
- var APIID : String;
- var password : String;
- var preloadSettings : boolean;
- var versionNumber : String;
- var DefaultUsername : String;
- //var flashPreloader : boolean;
- var medalID : int;
- var SessionID : String;
- var UserID : int;
- var UserName : String;
- var PublisherId : int;
- var BoardId : int;
- var Medals : medal[];
- var Testure : Texture2D;
- var unEncrypt : String;
- public class medal {
- public var id : int;
- public var name : String;
- public var points : int;
- public var difficulty : int;
- public var unlocked : boolean;
- public var secret : boolean;
- public var description : String;
- public var url : String;
- public var icon : Texture2D;
- public function medal (i : int, n : String, p : int, d : int, u : boolean, s : boolean, de : String, ur : String) {
- id = i;
- name = n;
- points = p;
- difficulty = d;
- unlocked = u;
- secret = s;
- description = de;
- url = ur;
- }}
- public class key {
- public var id : int;
- public var val : Object;
- public function key (i : int, v : Object) {
- id = i;
- val = v;
- }
- public function toString () {
- return "{id:" + id + ",value:" + val.toString() + "}";
- }}
- function Start () {
- var a : key[] = {key(316, 23.456), key(315, "Google"), key(318, true), key(317,317)};
- headers.Add("Content-Type", "application/x-www-form-urlencoded");
- headers.Add("Accept","*/*");
- DontDestroyOnLoad (transform.gameObject);
- yield WaitForSeconds (2);
- // unEncrypt = decrypt (unEncrypt);
- saveFilewithKeys ("George","A test save file","gibbeaeriohaeriueruigbaeiulrarghaaaeraoergoarrgrish",Testure, a);
- // loadSettings();
- // if (flashPreloader) {
- // Application.ExternalEval ("hideUnity()");
- // registerSession ();
- // postScore (Random.Range(0, 1000000000));
- // getMedals ();
- // unlockMedal (medalID);
- // loadMySite();
- }
- function decrypt (g : String) {
- g = g.Substring (1);
- g = deradix (g);
- g = g.Substring (32);
- g = HexStrToStr (g);
- g = EnDeCrypt (g);
- return g;
- }
- function downloadMedal (s : String) {
- var m : int = findMedal (s);
- var download : WWW = new WWW (Medals[m].url);
- Medals[m].icon = new Texture2D (1,1);
- yield download;
- download.LoadImageIntoTexture(Medals[m].icon);
- }
- function findMedal (s : String) {
- for (i = 0; i < Medals.Length; i++) {
- if (Medals[i].name == s)
- return i;
- }}
- Application.ExternalEval(" UnityObject2.instances[0].getUnity().SendMessage('" + name + "','bob', document.location.href);");
- function unlockMedal (a : int) {
- var seed : String = genSeed ();
- var text : String = '{"command_id":"unlockMedal","publisher_id":' + PublisherId + ',"session_id":"' + SessionID + '","medal_id":' + a + ',"seed":"' + seed + '"}';
- SecurePacket (seed, text);
- }
- function postScore (a : int) {
- var seed : String = genSeed ();
- var text : String = '{"command_id":"postScore","publisher_id":' + PublisherId + ',"session_id":"' + SessionID + '","board":' + BoardId + ',"value":' + a + ',"seed":"' + seed + '"}';
- SecurePacket (seed, text);
- }
- function getMedals () {
- var download : WWW = new WWW ("http://www.ngads.com/gateway_v2.php", encoding.GetBytes("command%5Fid=getMedals&tracker%5Fid=" + WWW.EscapeURL(APIID) + "&publisher%5Fid=" + PublisherId + "&user%5Fid=" + UserID), headers);
- yield download;
- }
- var saveGroup : int;
- function parseJSON (str : String) {
- var isString : boolean;
- // for (i
- }
- function loadSettings () {
- var download : WWW = new WWW ("http://www.ngads.com/gateway_v2.php", encoding.GetBytes("command%5Fid=preloadSettings&tracker%5Fid=" + WWW.EscapeURL(APIID) + "&publisher%5Fid=" + PublisherId + "&user%5Fid=" + UserID), headers);
- yield download;
- guiText.text = download.text;
- }
- function registerSession () {
- var a : String = "";
- if (preloadSettings)
- a = "&preload=1";
- var download : WWW = new WWW ("http://www.ngads.com/gateway_v2.php", encoding.GetBytes("command%5Fid=connectMovie&tracker%5Fid=" + WWW.EscapeURL(APIID) + "&publisher%5Fid=" + PublisherId + "&user%5Fid=" + UserID + "&host=" + URL + a +"&movie_version=" + versionNumber), headers);
- yield download;
- guiText.text = download.text;
- }
- function loadMySite () {
- var download : WWW = new WWW ("http://www.ngads.com/gateway_v2.php", encoding.GetBytes("command%5Fid=loadMySite&tracker%5Fid=" + WWW.EscapeURL(APIID) + "&host=" + URL), headers);
- yield download;
- guiText.text = download.text;
- }
- function encrypt (seed : String, text : String) {
- var hash : String = Md5Sum (seed);
- text = EnDeCrypt(text);
- text = StrToHexStr(text);
- text = hash + text;
- text = radix(text);
- return text;
- }
- function SecurePacket (seed : String, text : String) {
- text = encrypt (seed, text);
- text = "command%5Fid=securePacket&secure=" + WWW.EscapeURL(text) + "&tracker%5Fid=" + WWW.EscapeURL(APIID);
- var download : WWW = new WWW ("http://www.ngads.com/gateway_v2.php", encoding.GetBytes(text), headers);
- yield download;
- guiText.text += download.text + "\n";
- }
- function genSeed () {
- var seed : String = "";
- var iter : int = Random.Range (8,16);
- for (i = 0; i < iter; i++) {
- a = Random.Range (-26,36);
- if (a == -26)
- seed += "z";
- else if (a == -25)
- seed += "y";
- else if (a == -24)
- seed += "x";
- else if (a == -23)
- seed += "w";
- else if (a == -22)
- seed += "v";
- else if (a == -21)
- seed += "u";
- else if (a == -20)
- seed += "t";
- else if (a == -19)
- seed += "s";
- else if (a == -18)
- seed += "r";
- else if (a == -17)
- seed += "q";
- else if (a == -16)
- seed += "p";
- else if (a == -15)
- seed += "o";
- else if (a == -14)
- seed += "n";
- else if (a == -13)
- seed += "m";
- else if (a == -12)
- seed += "l";
- else if (a == -11)
- seed += "k";
- else if (a == -10)
- seed += "j";
- else if (a == -9)
- seed += "i";
- else if (a == -8)
- seed += "h";
- else if (a == -7)
- seed += "g";
- else if (a == -6)
- seed += "f";
- else if (a == -5)
- seed += "e";
- else if (a == -4)
- seed += "d";
- else if (a == -3)
- seed += "c";
- else if (a == -2)
- seed += "b";
- else if (a == -1)
- seed += "a";
- else if (a == 26)
- seed += "Z";
- else if (a == 25)
- seed += "Y";
- else if (a == 24)
- seed += "X";
- else if (a == 23)
- seed += "W";
- else if (a == 22)
- seed += "V";
- else if (a == 21)
- seed += "U";
- else if (a == 20)
- seed += "T";
- else if (a == 19)
- seed += "S";
- else if (a == 18)
- seed += "R";
- else if (a == 17)
- seed += "Q";
- else if (a == 16)
- seed += "P";
- else if (a == 15)
- seed += "O";
- else if (a == 14)
- seed += "N";
- else if (a == 13)
- seed += "M";
- else if (a == 12)
- seed += "L";
- else if (a == 11)
- seed += "K";
- else if (a == 10)
- seed += "J";
- else if (a == 9)
- seed += "I";
- else if (a == 8)
- seed += "H";
- else if (a == 7)
- seed += "G";
- else if (a == 6)
- seed += "F";
- else if (a == 5)
- seed += "E";
- else if (a == 4)
- seed += "D";
- else if (a == 3)
- seed += "C";
- else if (a == 2)
- seed += "B";
- else if (a == 1)
- seed += "A";
- else if (a == 0)
- seed += "0";
- else
- seed += (a-26);
- } return seed;
- }
- function Md5Sum (strToEncrypt: String) {
- var bytes = encoding.GetBytes(strToEncrypt);
- var md5 = System.Security.Cryptography.MD5CryptoServiceProvider();
- var hashBytes:byte[] = md5.ComputeHash(bytes);
- var hashString = "";
- for (var i = 0; i < hashBytes.Length; i++) {
- hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, "0"[0]);
- } return hashString.PadLeft(32, "0"[0]);
- }
- function EnDeCrypt(text : String) {
- RC4Initialize();
- var i : int = 0;
- var j : int = 0;
- var k : int = 0;
- var cipher = "";
- for (a = 0; a < text.Length; a++) {
- i = ((i + 1) % 256);
- j = ((j + sbox[i]) % 256);
- var tempSwap : int = sbox[i];
- sbox[i] = sbox[j];
- sbox[j] = tempSwap;
- k = sbox[(sbox[i] + sbox[j]) % 256];
- var cipherBy : int = text[a];
- cipherBy = cipherBy ^ k;
- cipher += (System.Convert.ToChar(cipherBy));
- } return cipher;
- }
- function StrToHexStr(str : String) {
- var sb = "";
- for (i = 0; i < str.Length; i++) {
- var v : int = str[i];
- sb += (String.Format("{0:X2}", v));
- } return sb;
- }
- function HexStrToStr(hexStr : String) {
- var sb = "";
- for (i = 0; i < hexStr.Length; i += 2) {
- var n : int = System.Int32.Parse(hexStr.Substring(i, 2), System.Globalization.NumberStyles.AllowHexSpecifier);
- sb += (System.Convert.ToChar(n));
- } return sb;
- }
- function RC4Initialize() {
- sbox = new int[256];
- key = new int[256];
- n = password.Length;
- for (a = 0; a < 256; a++) {
- key[a] = (password[a % n]);
- sbox[a] = a;
- } var b : int = 0;
- for (a = 0; a < 256; a++) {
- b = (b + sbox[a] + key[a]) % 256;
- var tempSwap : int = sbox[a];
- sbox[a] = sbox[b];
- sbox[b] = tempSwap;
- }}
- function radix (g : String) {
- var output : String = "";
- for (i = 0; (i< g.Length-6); i+=6) {
- var block : String = "";
- var d : int = System.Int32.Parse(g.Substring(i,6), System.Globalization.NumberStyles.AllowHexSpecifier);
- for (j = 0; j<4; j++){
- var l : int = d % 79;
- var car : char = rad[l];
- d -= l;
- d /= 79;
- block = car + block;
- } output +=block;
- } var block0 : String = "";
- var p : String = g.Substring(g.Length-(g.Length%6),(g.Length%6));
- if (p != "") {
- var o : int = System.Int32.Parse(g.Substring(g.Length-(g.Length%6),(g.Length%6)), System.Globalization.NumberStyles.AllowHexSpecifier);
- for (j = 0; j<4; j++) {
- var l0 : int = o % 79;
- var car0 : char = rad[l0];
- o -= l0;
- o /= 79;
- block0 = car0 + block0;
- } output +=block0;
- } output = ((g.Length) % 6) + output;
- return output;
- }
- private var HexRad : String = "0123456789ABCDEF";
- function deradix (g : String) {
- var output : String = "";
- for (i= 0; i < g.Length-3; i += 4) {
- var opal : String = g.Substring (i,4);
- var ruby : int = 0;
- for (j = 0; j < rad.Length; j++) {
- if (opal[0] == rad[j])
- ruby += (j*(493039));
- if (opal[1] == rad[j])
- ruby += (j*(6241));
- if (opal[2] == rad[j])
- ruby += (j*(79));
- if (opal[3] == rad[j])
- ruby += j;
- } var onix : String = "";
- for (k = 0; k < 6; k++) {
- var lapis : int = (ruby % 16);
- onix = HexRad[lapis] + onix;
- ruby -= lapis;
- ruby /= 16;
- } output += onix;
- } return output;
- }
- bob ("http://uploads.ungrounded.net/tmp/744000/744865/file/alternate/alternate_2.zip/?NewgroundsAPI_PublisherID=1&NewgroundsAPI_SandboxID=52fc429b7473a&NewgroundsAPI_SessionID=rP3basDm4txmIXUyF8O1813ce389f27095b178f1ec742f35d0ccba83d9f6Ir1k&NewgroundsAPI_UserName=Bcadren&NewgroundsAPI_UserID=4889253&ng_username=Bcadren");
- //copy of a valid URL for offline testing
- function bob (data : String) {
- var Delimiters : String[] = ['?','&','='];
- parameters = data.Split (Delimiters, System.StringSplitOptions.RemoveEmptyEntries);
- for (i = 0; i < parameters.length; i++)
- parameters[i] = WWW.UnEscapeURL (parameters[i]);
- for (j = 0; j < parameters.length; j++){
- if (parameters[j] == "NewgroundsAPI_SessionID")
- SessionID = parameters[j+1];
- else if (parameters[j] == "NewgroundsAPI_UserID")
- UserID = parseInt(parameters[j+1]);
- else if (parameters[j] == "NewgroundsAPI_UserName")
- UserName = parameters[j+1];
- else if (parameters[j] == "NewgroundsAPI_PublisherID")
- PublisherId = parseInt(parameters[j+1]);
- } URL = parameters[0];
- for (k = 0; k < URL.Length; k++)
- if ((URL[k] == "/") && (URL[k+1] != "/") && (URL[k-1] != "/"))
- URL = URL.Substring (0, k);
- if (UserName == "<deleted>")
- UserName = DefaultUsername;
- }
- /*
- function saveFile (overwriteFile : int, fileName: String, description: String, file: String, thumbnail: Texture2D) {
- var seed : String = genSeed ();
- var bytes : byte[] = thumbnail.EncodeToPNG();
- var text : String = '{"command_id":"saveFile","publisher_id":' + PublisherId + ',"file":"' + file + '","session_id":"' + SessionID + '","group":' + saveGroup + ',"description":"' + description + '","filename":"' + fileName + '","save_id":' + overwriteFile + ',"thumbnail":' + bytes.toString + ',"seed":"' + seed + '"}';
- SecurePacket (seed, text);
- }
- function saveFile (fileName: String, description: String, file: String, thumbnail: Texture2D) {
- var seed : String = genSeed ();
- var bytes : byte[] = thumbnail.EncodeToPNG();
- var text : String = '{"command_id":"saveFile","publisher_id":' + PublisherId + ',"file":"' + file + '","session_id":"' + SessionID + '","group":' + saveGroup + ',"description":"' + description + '","filename":"' + fileName + ',"thumbnail":"' + System.Convert.ToBase64String(bytes) + '","seed":"' + seed + '"}';
- guiText.text = text + "\n";
- SecurePacket (seed, text);
- }
- */
- function saveFile (fileName: String, description: String, file: String, thumbnail: Texture2D) {
- var seed = genSeed ();
- var JSON = '{"session_id":"' + SessionID + '","user_name":"' + UserName + '","description":"' + description + '","user_email":null,"seed":"' + seed + '","publisher_id":' + PublisherId + ',"keys":[],"ratings":[],"filename":"' + fileName + '","group":' + saveGroup + ',"command_id":"saveFile"}';
- guiText.text = JSON + "\n";
- JSON = encrypt (seed, JSON);
- var bytes : byte[] = thumbnail.EncodeToPNG();
- var form = new WWWForm();
- form.AddField ("command_id", "securePacket");
- form.AddField ("secure", JSON);
- form.AddField ("tracker_id", APIID);
- form.AddField ("Filename", "thumbnail");
- form.AddBinaryData ("thumbnail", bytes, "thumbnail", "image/png");
- form.AddField ("Filename", "file");
- form.AddBinaryData ("file", encoding.GetBytes(file), "file", "text/plain");
- form.AddField ("Upload", "Submit Query");
- var download : WWW = new WWW ("http://www.ngads.com/gateway_v2.php",form);
- yield download;
- guiText.text += download.text + "\n";
- }
- function saveFilewithKeys (fileName: String, description: String, file: String, thumbnail: Texture2D, keys: key[]) {
- var seed = genSeed ();
- var JSON = '{"session_id":"' + SessionID + '","user_name":"' + UserName + '","description":"' + description + '","user_email":null,"seed":"' + seed + '","publisher_id":' + PublisherId + ',"keys":' + keys.toString + ',"ratings":[],"filename":"' + fileName + '","group":' + saveGroup + ',"command_id":"saveFile"}';
- guiText.text = JSON + "\n";
- JSON = encrypt (seed, JSON);
- var bytes : byte[] = thumbnail.EncodeToPNG();
- var form = new WWWForm();
- form.AddField ("command_id", "securePacket");
- form.AddField ("secure", JSON);
- form.AddField ("tracker_id", APIID);
- form.AddField ("Filename", "thumbnail");
- form.AddBinaryData ("thumbnail", bytes, "thumbnail", "image/png");
- form.AddField ("Filename", "file");
- form.AddBinaryData ("file", encoding.GetBytes(file), "file", "text/plain");
- form.AddField ("Upload", "Submit Query");
- var download : WWW = new WWW ("http://www.ngads.com/gateway_v2.php",form);
- yield download;
- guiText.text += download.text + "\n";
- }
- /* {"session_id":"rP3basDm4txmIXUyF8O1813ce389f27095b178f1ec742f35d0ccba83d9f6Ir1k",
- "user_name":"Bcadren","description":"Test Desc","user_email":null,"seed":"~)fMPuQ@#wtRyBqA","publisher_id":1
- ,"keys":[],"ratings":[],"filename":"Test Name","group":915,"command_id":"saveFile"}
- save_id - The numeric id of an existing file to overwrite (optional)
- keys - An array of key/value objects containing the following properties: (optional)
- id - The numeric id of this key
- value - The key value for this file
- file - A binary file or text blob to be saved
- thumbnail - A PNG file or dataURL string */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement