Advertisement
Bcadren

Untitled

Feb 12th, 2014
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private var parameters : String[];
  2. private var headers : Hashtable = new Hashtable();
  3. private var encoding : System.Text.Encoding = new System.Text.UTF8Encoding();
  4. private var rad : String = "/g8236klvBQ#&|;Zb*7CEA59%s`Oue1wziFp$rDVY@TKxUPWytSaGHJ>dmoMR^<0~4qNLhc(I+fjn)X";
  5. private var sbox : int[];
  6. private var key : int[];
  7. private var n : int;
  8. private var URL : String;
  9. var APIID : String;
  10. var password : String;
  11. var preloadSettings : boolean;
  12. var versionNumber : String;
  13. var DefaultUsername : String;
  14. //var flashPreloader : boolean;
  15. var medalID : int;
  16. var SessionID : String;
  17. var UserID : int;
  18. var UserName : String;
  19. var PublisherId : int;
  20. var BoardId : int;
  21. var Medals : medal[];
  22. var Testure : Texture2D;
  23. var unEncrypt : String;
  24.  
  25. public class medal {
  26.     public var id : int;
  27.     public var name : String;
  28.     public var points : int;
  29.     public var difficulty : int;
  30.     public var unlocked : boolean;
  31.     public var secret : boolean;
  32.     public var description : String;
  33.     public var url : String;
  34.     public var icon : Texture2D;
  35.  
  36.     public function medal (i : int, n : String, p : int, d : int, u : boolean, s : boolean, de : String, ur : String) {
  37.         id = i;
  38.         name = n;
  39.         points = p;
  40.         difficulty = d;
  41.         unlocked = u;
  42.         secret = s;
  43.         description = de;
  44.         url = ur;
  45. }}
  46.  
  47. public class key {
  48.     public var id : int;
  49.     public var val : Object;
  50.    
  51.     public function key (i : int, v : Object) {
  52.         id = i;
  53.         val = v;
  54. }
  55.    
  56.     public function toString () {
  57.         return "{id:" + id + ",value:" + val.toString() + "}";
  58. }}
  59.  
  60. function Start () {
  61.     var a : key[] = {key(316, 23.456), key(315, "Google"), key(318, true), key(317,317)};
  62.     headers.Add("Content-Type", "application/x-www-form-urlencoded");
  63.     headers.Add("Accept","*/*");
  64.     DontDestroyOnLoad (transform.gameObject);
  65.     yield WaitForSeconds (2);
  66. //  unEncrypt = decrypt (unEncrypt);
  67.     saveFilewithKeys ("George","A test save file","gibbeaeriohaeriueruigbaeiulrarghaaaeraoergoarrgrish",Testure, a);
  68. //  loadSettings();
  69. //  if (flashPreloader) {
  70. //      Application.ExternalEval ("hideUnity()");
  71. //  registerSession ();
  72. //  postScore (Random.Range(0, 1000000000));
  73. //  getMedals ();
  74. //  unlockMedal (medalID);
  75. //  loadMySite();
  76. }
  77.  
  78. function decrypt (g : String) {
  79.     g = g.Substring (1);
  80.     g = deradix (g);
  81.     g = g.Substring (32);
  82.     g = HexStrToStr (g);
  83.     g = EnDeCrypt (g);
  84.     return g;
  85. }
  86.  
  87. function downloadMedal (s : String) {
  88.     var m : int = findMedal (s);
  89.     var download : WWW = new WWW (Medals[m].url);
  90.     Medals[m].icon = new Texture2D (1,1);
  91.     yield download;
  92.     download.LoadImageIntoTexture(Medals[m].icon);
  93. }
  94.  
  95. function findMedal (s : String) {
  96.     for (i = 0; i < Medals.Length; i++) {
  97.         if (Medals[i].name == s)
  98.             return i;
  99. }}
  100.  
  101. Application.ExternalEval(" UnityObject2.instances[0].getUnity().SendMessage('" + name + "','bob', document.location.href);");
  102.  
  103. function unlockMedal (a : int) {
  104.     var seed : String = genSeed ();
  105.     var text : String = '{"command_id":"unlockMedal","publisher_id":' + PublisherId + ',"session_id":"' + SessionID + '","medal_id":' + a + ',"seed":"' + seed + '"}';
  106.     SecurePacket (seed, text);
  107. }
  108.  
  109. function postScore (a : int) {
  110.     var seed : String = genSeed ();
  111.     var text : String = '{"command_id":"postScore","publisher_id":' + PublisherId + ',"session_id":"' + SessionID + '","board":' + BoardId + ',"value":' + a + ',"seed":"' + seed + '"}';
  112.     SecurePacket (seed, text); 
  113. }
  114.  
  115. function getMedals () {
  116.     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);
  117.     yield download;
  118. }
  119.  
  120. var saveGroup : int;
  121.  
  122. function parseJSON (str : String) {
  123.     var isString : boolean;
  124. //  for (i
  125. }
  126.  
  127. function loadSettings () {
  128.     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);
  129.     yield download;
  130.     guiText.text = download.text;
  131. }
  132.  
  133. function registerSession () {
  134.     var a : String = "";
  135.     if (preloadSettings)
  136.         a = "&preload=1";
  137.     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);
  138.     yield download;
  139.     guiText.text = download.text;
  140. }
  141.  
  142. function loadMySite () {
  143.     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);
  144.     yield download;
  145.     guiText.text = download.text;
  146. }
  147.  
  148. function encrypt (seed : String, text : String) {
  149.     var hash : String = Md5Sum (seed);
  150.     text = EnDeCrypt(text);
  151.     text = StrToHexStr(text);
  152.     text = hash + text;
  153.     text = radix(text);
  154.     return text;
  155. }
  156.  
  157. function SecurePacket (seed : String, text : String) {
  158.     text = encrypt (seed, text);
  159.     text = "command%5Fid=securePacket&secure=" + WWW.EscapeURL(text) + "&tracker%5Fid=" + WWW.EscapeURL(APIID);
  160.     var download : WWW = new WWW ("http://www.ngads.com/gateway_v2.php", encoding.GetBytes(text), headers);
  161.     yield download;
  162.     guiText.text += download.text + "\n";
  163. }
  164.  
  165. function genSeed () {
  166.     var seed : String = "";
  167.     var iter : int = Random.Range (8,16);
  168.     for (i = 0; i < iter; i++) {
  169.         a = Random.Range (-26,36);
  170.         if (a == -26)
  171.             seed += "z";
  172.         else if (a == -25)
  173.             seed += "y";
  174.         else if (a == -24)
  175.             seed += "x";
  176.         else if (a == -23)
  177.             seed += "w";
  178.         else if (a == -22)
  179.             seed += "v";
  180.         else if (a == -21)
  181.             seed += "u";
  182.         else if (a == -20)
  183.             seed += "t";
  184.         else if (a == -19)
  185.             seed += "s";
  186.         else if (a == -18)
  187.             seed += "r";
  188.         else if (a == -17)
  189.             seed += "q";
  190.         else if (a == -16)
  191.             seed += "p";
  192.         else if (a == -15)
  193.             seed += "o";
  194.         else if (a == -14)
  195.             seed += "n";
  196.         else if (a == -13)
  197.             seed += "m";
  198.         else if (a == -12)
  199.             seed += "l";
  200.         else if (a == -11)
  201.             seed += "k";
  202.         else if (a == -10)
  203.             seed += "j";
  204.         else if (a == -9)
  205.             seed += "i";
  206.         else if (a == -8)
  207.             seed += "h";
  208.         else if (a == -7)
  209.             seed += "g";
  210.         else if (a == -6)
  211.             seed += "f";
  212.         else if (a == -5)
  213.             seed += "e";
  214.         else if (a == -4)
  215.             seed += "d";
  216.         else if (a == -3)
  217.             seed += "c";
  218.         else if (a == -2)
  219.             seed += "b";
  220.         else if (a == -1)
  221.             seed += "a";
  222.         else if (a == 26)
  223.             seed += "Z";
  224.         else if (a == 25)
  225.             seed += "Y";
  226.         else if (a == 24)
  227.             seed += "X";
  228.         else if (a == 23)
  229.             seed += "W";
  230.         else if (a == 22)
  231.             seed += "V";
  232.         else if (a == 21)
  233.             seed += "U";
  234.         else if (a == 20)
  235.             seed += "T";
  236.         else if (a == 19)
  237.             seed += "S";
  238.         else if (a == 18)
  239.             seed += "R";
  240.         else if (a == 17)
  241.             seed += "Q";
  242.         else if (a == 16)
  243.             seed += "P";
  244.         else if (a == 15)
  245.             seed += "O";
  246.         else if (a == 14)
  247.             seed += "N";
  248.         else if (a == 13)
  249.             seed += "M";
  250.         else if (a == 12)
  251.             seed += "L";
  252.         else if (a == 11)
  253.             seed += "K";
  254.         else if (a == 10)
  255.             seed += "J";
  256.         else if (a == 9)
  257.             seed += "I";
  258.         else if (a == 8)
  259.             seed += "H";
  260.         else if (a == 7)
  261.             seed += "G";
  262.         else if (a == 6)
  263.             seed += "F";
  264.         else if (a == 5)
  265.             seed += "E";
  266.         else if (a == 4)
  267.             seed += "D";
  268.         else if (a == 3)
  269.             seed += "C";
  270.         else if (a == 2)
  271.             seed += "B";
  272.         else if (a == 1)
  273.             seed += "A";
  274.         else if (a == 0)
  275.             seed += "0";
  276.         else
  277.             seed += (a-26);
  278. }   return seed;
  279. }
  280.  
  281. function Md5Sum (strToEncrypt: String) {
  282.     var bytes = encoding.GetBytes(strToEncrypt);
  283.     var md5 = System.Security.Cryptography.MD5CryptoServiceProvider();
  284.     var hashBytes:byte[] = md5.ComputeHash(bytes);
  285.     var hashString = "";
  286.     for (var i = 0; i < hashBytes.Length; i++) {
  287.         hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, "0"[0]);
  288. }   return hashString.PadLeft(32, "0"[0]);
  289. }
  290.  
  291. function EnDeCrypt(text : String) {
  292.     RC4Initialize();
  293.     var i : int = 0;
  294.     var j : int = 0;
  295.     var k : int = 0;
  296.         var cipher = "";
  297.         for (a = 0; a < text.Length; a++) {
  298.             i = ((i + 1) % 256);
  299.             j = ((j + sbox[i]) % 256);
  300.             var tempSwap : int = sbox[i];
  301.             sbox[i] = sbox[j];
  302.             sbox[j] = tempSwap;
  303.             k = sbox[(sbox[i] + sbox[j]) % 256];
  304.             var cipherBy : int = text[a];
  305.             cipherBy = cipherBy ^ k;
  306.             cipher += (System.Convert.ToChar(cipherBy));
  307. }       return cipher;
  308. }
  309.  
  310. function StrToHexStr(str : String) {
  311.     var sb = "";
  312.     for (i = 0; i < str.Length; i++) {
  313.         var v : int = str[i];
  314.         sb += (String.Format("{0:X2}", v));
  315. }   return sb;
  316. }
  317.  
  318. function HexStrToStr(hexStr : String) {
  319.     var sb = "";
  320.     for (i = 0; i < hexStr.Length; i += 2) {
  321.         var n : int = System.Int32.Parse(hexStr.Substring(i, 2), System.Globalization.NumberStyles.AllowHexSpecifier);
  322.             sb += (System.Convert.ToChar(n));
  323. }   return sb;
  324. }
  325.    
  326. function RC4Initialize() {
  327.     sbox = new int[256];
  328.     key = new int[256];
  329.     n = password.Length;
  330.     for (a = 0; a < 256; a++)   {
  331.         key[a] = (password[a % n]);
  332.         sbox[a] = a;
  333. }   var b : int = 0;
  334.         for (a = 0; a < 256; a++)   {
  335.             b = (b + sbox[a] + key[a]) % 256;
  336.             var tempSwap : int = sbox[a];
  337.             sbox[a] = sbox[b];
  338.             sbox[b] = tempSwap;
  339. }}
  340.  
  341. function radix (g : String) {
  342.     var output : String = "";
  343.     for (i = 0; (i< g.Length-6); i+=6) {
  344.         var block : String = "";
  345.         var d : int = System.Int32.Parse(g.Substring(i,6), System.Globalization.NumberStyles.AllowHexSpecifier);
  346.         for (j = 0; j<4; j++){
  347.             var l : int = d % 79;
  348.             var car : char = rad[l];
  349.             d -= l;
  350.             d /= 79;
  351.             block = car + block;
  352. }       output +=block;
  353. }   var block0 : String = "";
  354.     var p : String = g.Substring(g.Length-(g.Length%6),(g.Length%6));
  355.     if (p != "") {
  356.         var o : int = System.Int32.Parse(g.Substring(g.Length-(g.Length%6),(g.Length%6)), System.Globalization.NumberStyles.AllowHexSpecifier);
  357.         for (j = 0; j<4; j++) {
  358.             var l0 : int = o % 79;
  359.             var car0 : char = rad[l0];
  360.             o -= l0;
  361.             o /= 79;
  362.             block0 = car0 + block0;
  363. }       output +=block0;
  364. }   output = ((g.Length) % 6) + output;
  365.     return output;
  366. }
  367.  
  368. private var HexRad : String = "0123456789ABCDEF";
  369.  
  370. function deradix (g : String) {
  371.     var output : String = "";
  372.     for (i= 0; i < g.Length-3; i += 4) {
  373.         var opal : String = g.Substring (i,4);
  374.         var ruby : int = 0;
  375.         for (j = 0; j < rad.Length; j++) {
  376.             if (opal[0] == rad[j])
  377.                 ruby += (j*(493039));
  378.             if (opal[1] == rad[j])
  379.                 ruby += (j*(6241));
  380.             if (opal[2] == rad[j])
  381.                 ruby += (j*(79));
  382.             if (opal[3] == rad[j])
  383.                 ruby += j;
  384. }       var onix : String = "";
  385.         for (k = 0; k < 6; k++) {
  386.             var lapis : int = (ruby % 16);
  387.             onix = HexRad[lapis] + onix;
  388.             ruby -= lapis;
  389.             ruby /= 16;
  390. }   output += onix;
  391. }   return output;
  392. }
  393.  
  394. 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");
  395. //copy of a valid URL for offline testing
  396.  
  397. function bob (data : String) {
  398.     var Delimiters : String[] = ['?','&','='];
  399.     parameters = data.Split (Delimiters, System.StringSplitOptions.RemoveEmptyEntries);
  400.     for (i = 0; i < parameters.length; i++)
  401.         parameters[i] = WWW.UnEscapeURL (parameters[i]);
  402.     for (j = 0; j < parameters.length; j++){
  403.         if (parameters[j] == "NewgroundsAPI_SessionID")
  404.             SessionID = parameters[j+1];
  405.         else if (parameters[j] == "NewgroundsAPI_UserID")
  406.             UserID = parseInt(parameters[j+1]);
  407.         else if (parameters[j] == "NewgroundsAPI_UserName")
  408.             UserName = parameters[j+1];
  409.         else if (parameters[j] == "NewgroundsAPI_PublisherID")
  410.             PublisherId = parseInt(parameters[j+1]);
  411. }   URL = parameters[0];
  412.     for (k = 0; k < URL.Length; k++)
  413.         if ((URL[k] == "/") && (URL[k+1] != "/") && (URL[k-1] != "/"))
  414.             URL = URL.Substring (0, k);
  415.     if (UserName == "&lt;deleted&gt;")
  416.         UserName = DefaultUsername;
  417. }
  418.  
  419. /*
  420. function saveFile (overwriteFile : int, fileName: String, description: String, file: String, thumbnail: Texture2D) {
  421.     var seed : String = genSeed ();
  422.     var bytes : byte[] = thumbnail.EncodeToPNG();
  423.     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 + '"}';
  424.     SecurePacket (seed, text);
  425. }
  426.  
  427. function saveFile (fileName: String, description: String, file: String, thumbnail: Texture2D) {
  428.     var seed : String = genSeed ();
  429.     var bytes : byte[] = thumbnail.EncodeToPNG();
  430.     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 + '"}';
  431.     guiText.text = text + "\n";
  432.     SecurePacket (seed, text);
  433. }
  434. */
  435.  
  436. function saveFile (fileName: String, description: String, file: String, thumbnail: Texture2D) {
  437.     var seed = genSeed ();
  438.     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"}';
  439.     guiText.text = JSON + "\n";
  440.     JSON = encrypt (seed, JSON);
  441.     var bytes : byte[] = thumbnail.EncodeToPNG();
  442.    
  443.     var form = new WWWForm();
  444.    
  445.     form.AddField ("command_id", "securePacket");
  446.     form.AddField ("secure", JSON);
  447.     form.AddField ("tracker_id", APIID);
  448.     form.AddField ("Filename", "thumbnail");
  449.     form.AddBinaryData ("thumbnail", bytes, "thumbnail", "image/png");
  450.     form.AddField ("Filename", "file");
  451.     form.AddBinaryData ("file", encoding.GetBytes(file), "file", "text/plain");
  452.     form.AddField ("Upload", "Submit Query");
  453.    
  454.     var download : WWW = new WWW ("http://www.ngads.com/gateway_v2.php",form);
  455.     yield download;
  456.     guiText.text += download.text + "\n";
  457. }
  458.  
  459.  
  460. function saveFilewithKeys (fileName: String, description: String, file: String, thumbnail: Texture2D, keys: key[]) {
  461.     var seed = genSeed ();
  462.     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"}';
  463.     guiText.text = JSON + "\n";
  464.     JSON = encrypt (seed, JSON);
  465.     var bytes : byte[] = thumbnail.EncodeToPNG();
  466.    
  467.     var form = new WWWForm();
  468.    
  469.     form.AddField ("command_id", "securePacket");
  470.     form.AddField ("secure", JSON);
  471.     form.AddField ("tracker_id", APIID);
  472.     form.AddField ("Filename", "thumbnail");
  473.     form.AddBinaryData ("thumbnail", bytes, "thumbnail", "image/png");
  474.     form.AddField ("Filename", "file");
  475.     form.AddBinaryData ("file", encoding.GetBytes(file), "file", "text/plain");
  476.     form.AddField ("Upload", "Submit Query");
  477.    
  478.     var download : WWW = new WWW ("http://www.ngads.com/gateway_v2.php",form);
  479.     yield download;
  480.     guiText.text += download.text + "\n";
  481. }
  482.  
  483. /* {"session_id":"rP3basDm4txmIXUyF8O1813ce389f27095b178f1ec742f35d0ccba83d9f6Ir1k",
  484. "user_name":"Bcadren","description":"Test Desc","user_email":null,"seed":"~)fMPuQ@#wtRyBqA","publisher_id":1
  485. ,"keys":[],"ratings":[],"filename":"Test Name","group":915,"command_id":"saveFile"}
  486.  
  487.  
  488. save_id - The numeric id of an existing file to overwrite (optional)
  489. keys - An array of key/value objects containing the following properties: (optional)
  490. id - The numeric id of this key
  491. value - The key value for this file
  492. file - A binary file or text blob to be saved
  493. thumbnail - A PNG file or dataURL string */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement