AdhityaRimba

AT5 Main

Mar 7th, 2021
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 15.01 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Runtime.Serialization.Formatters.Binary;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using TGlib;
  9. using UnityEngine;
  10. using UnityEngine.SceneManagement;
  11.  
  12. namespace FullVersion
  13. {
  14.     // Token: 0x020000D0 RID: 208
  15.     public class FullVerMgr : BaseObject
  16.     {
  17.         // Token: 0x0600052A RID: 1322 RVA: 0x00051F95 File Offset: 0x00050395
  18.         protected override void Awake()
  19.         {
  20.             base.Awake();
  21.             g.full_ver_mgr = this;
  22.             this.file_path = Application.persistentDataPath + "/at5_full_ver.dat";
  23.             this.CheckSavedFullVerState(FullVerMgr.CHECK_STATE.START_GAME);
  24.         }
  25.  
  26.         // Token: 0x0600052B RID: 1323 RVA: 0x00051FBF File Offset: 0x000503BF
  27.         public void ConsumeFullVerTest()
  28.         {
  29.         }
  30.  
  31.         // Token: 0x0600052C RID: 1324 RVA: 0x00051FC1 File Offset: 0x000503C1
  32.         public void CheckSavedFullVerState(FullVerMgr.CHECK_STATE state)
  33.         {
  34.             this.check_state = state;
  35.             this.loadConnectingVC();
  36.             this.GetDeviceInfo();
  37.         }
  38.  
  39.         // Token: 0x0600052D RID: 1325 RVA: 0x00051FD8 File Offset: 0x000503D8
  40.         private void CheckSavedFullVerFile()
  41.         {
  42.             if (File.Exists(this.file_path))
  43.             {
  44.                 this.VerifyEncodedKey();
  45.             }
  46.             else
  47.             {
  48.                 this.gl.FullVersion = 0;
  49.                 if (!this.file_checked && (SceneManager.GetActiveScene().name.Equals("Title") || SceneManager.GetActiveScene().name.Equals("CompanyLogo")))
  50.                 {
  51.                     this.closeConnectingVC();
  52.                     GameObject gameObject = GameObject.Find("TitleVC");
  53.                     if (gameObject != null)
  54.                     {
  55.                         gameObject.GetComponent<TitleManager>().ShowFullButton(true);
  56.                     }
  57.                 }
  58.                 else
  59.                 {
  60.                     this.CheckNetworkState();
  61.                 }
  62.                 this.file_checked = true;
  63.             }
  64.         }
  65.  
  66.         // Token: 0x0600052E RID: 1326 RVA: 0x0005208A File Offset: 0x0005048A
  67.         private void CheckNetworkState()
  68.         {
  69.             AndroidManager.curActivity.Call("javaNetworkState", new object[]
  70.             {
  71.                 0
  72.             });
  73.         }
  74.  
  75.         // Token: 0x0600052F RID: 1327 RVA: 0x000520AA File Offset: 0x000504AA
  76.         private void GetDeviceInfo()
  77.         {
  78.             AndroidManager.curActivity.Call("javaGetDeviceInfo", new object[0]);
  79.         }
  80.  
  81.         // Token: 0x06000530 RID: 1328 RVA: 0x000520C1 File Offset: 0x000504C1
  82.         private void CheckGoogleAccountFullVer()
  83.         {
  84.             AndroidManager.curActivity.Call("javaCheckFullVerState", new object[0]);
  85.         }
  86.  
  87.         // Token: 0x06000531 RID: 1329 RVA: 0x000520D8 File Offset: 0x000504D8
  88.         private void UpgradeFullVer()
  89.         {
  90.             AndroidManager.curActivity.Call("javaUpgradeFullVer", new object[0]);
  91.         }
  92.  
  93.         // Token: 0x06000532 RID: 1330 RVA: 0x000520F0 File Offset: 0x000504F0
  94.         public void NetworkState(string _state)
  95.         {
  96.             if (int.Parse(_state) == 0)
  97.             {
  98.                 this.closeConnectingVC();
  99.                 base.showMessageBox(2, 80);
  100.             }
  101.             else
  102.             {
  103.                 this.www_timeout = 10f;
  104.                 this.request_idx = FullVerMgr.REQUEST.CHECK_VERSION_0;
  105.                 this.RequestToServer("version.php", string.Empty);
  106.             }
  107.         }
  108.  
  109.         // Token: 0x06000533 RID: 1331 RVA: 0x00052140 File Offset: 0x00050540
  110.         public void DeviceInfo(string data)
  111.         {
  112.             if (data == null)
  113.             {
  114.                 this.closeConnectingVC();
  115.                 return;
  116.             }
  117.             this.device_id = data;
  118.             this.CheckSavedFullVerFile();
  119.         }
  120.  
  121.         // Token: 0x06000534 RID: 1332 RVA: 0x0005215C File Offset: 0x0005055C
  122.         public void FullVerState(string _state)
  123.         {
  124.             this.closeConnectingVC();
  125.             if (int.Parse(_state) == 0)
  126.             {
  127.                 base.showMessageBox(3, 241);
  128.             }
  129.             else
  130.             {
  131.                 this.www_timeout = 10f;
  132.                 this.full_ver_random_id = this.GenerateRandomID(50);
  133.                 string body = string.Format("{0}` {1}", this.full_ver_random_id, this.device_id);
  134.                 this.request_idx = FullVerMgr.REQUEST.GENERATE_FULL_VER_CODE;
  135.                 this.RequestToServer("in_app/generate_full_ver_code.php", body);
  136.             }
  137.         }
  138.  
  139.         // Token: 0x06000535 RID: 1333 RVA: 0x000521D0 File Offset: 0x000505D0
  140.         public void PurchasedTransaction(string data)
  141.         {
  142.             this.closeConnectingVC();
  143.             string[] array = Regex.Split(data, "` ");
  144.             if (array.Length != 3)
  145.             {
  146.                 return;
  147.             }
  148.             this.www_timeout = 15f;
  149.             string text = array[0];
  150.             string text2 = array[1];
  151.             string text3 = array[2];
  152.             this.full_ver_random_id = this.GenerateRandomID(50);
  153.             string body = string.Format("{0}` {1}` {2}` {3}` {4}", new object[]
  154.             {
  155.                 this.full_ver_random_id,
  156.                 this.device_id,
  157.                 text,
  158.                 text2,
  159.                 text3
  160.             });
  161.             this.request_idx = FullVerMgr.REQUEST.VERIFY_RECEIPT;
  162.             this.RequestToServer("in_app/verify_receipt_full_ver.php", body);
  163.         }
  164.  
  165.         // Token: 0x06000536 RID: 1334 RVA: 0x00052262 File Offset: 0x00050662
  166.         public void FailedTransaction()
  167.         {
  168.             base.showDelayMessageBox(2, 84, null, false);
  169.             this.closeConnectingVC();
  170.         }
  171.  
  172.         // Token: 0x06000537 RID: 1335 RVA: 0x00052275 File Offset: 0x00050675
  173.         public void FailedFullVerState()
  174.         {
  175.             this.gl.FullVersion = 0;
  176.             this.closeConnectingVC();
  177.         }
  178.  
  179.         // Token: 0x06000538 RID: 1336 RVA: 0x0005228C File Offset: 0x0005068C
  180.         private string GenerateRandomID(int length)
  181.         {
  182.             string text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  183.             StringBuilder stringBuilder = new StringBuilder();
  184.             System.Random random = new System.Random();
  185.             int length2 = text.Length;
  186.             for (int i = 0; i < length; i++)
  187.             {
  188.                 stringBuilder.Append(text[random.Next(length2)]);
  189.             }
  190.             return stringBuilder.ToString();
  191.         }
  192.  
  193.         // Token: 0x06000539 RID: 1337 RVA: 0x000522E4 File Offset: 0x000506E4
  194.         private void SaveServerKey(string server_key)
  195.         {
  196.             string param = string.Format("{0}` {1}", this.full_ver_random_id, server_key);
  197.             string graph = TGEncode.Encode(param);
  198.             BinaryFormatter binaryFormatter = new BinaryFormatter();
  199.             FileStream fileStream;
  200.             try
  201.             {
  202.                 fileStream = File.Create(this.file_path);
  203.                 binaryFormatter.Serialize(fileStream, graph);
  204.             }
  205.             catch (Exception ex)
  206.             {
  207.                 this.closeConnectingVC();
  208.                 return;
  209.             }
  210.             fileStream.Close();
  211.             this.closeConnectingVC();
  212.             this.gl.FullVersion = 1;
  213.             if (SceneManager.GetActiveScene().name.Equals("Title") || SceneManager.GetActiveScene().name.Equals("CompanyLogo"))
  214.             {
  215.                 GameObject gameObject = GameObject.Find("TitleVC");
  216.                 if (gameObject != null)
  217.                 {
  218.                     gameObject.GetComponent<TitleManager>().ShowFullButton(false);
  219.                 }
  220.                 base.showDelayMessageBox(1, 26, null, false);
  221.             }
  222.         }
  223.  
  224.         // Token: 0x0600053A RID: 1338 RVA: 0x000523CC File Offset: 0x000507CC
  225.         private void VerifyEncodedKey()
  226.         {
  227.             BinaryFormatter binaryFormatter = new BinaryFormatter();
  228.             try
  229.             {
  230.                 FileStream fileStream = File.Open(this.file_path, FileMode.Open);
  231.                 string text = (string)binaryFormatter.Deserialize(fileStream);
  232.                 text = TGEncode.Decode(text);
  233.                 fileStream.Close();
  234.                 string[] array = Regex.Split(text, "` ");
  235.                 if (array.Length != 2)
  236.                 {
  237.                     this.closeConnectingVC();
  238.                     this.DeleteFullVerFile();
  239.                 }
  240.                 else
  241.                 {
  242.                     string text2 = array[0];
  243.                     string text3 = array[1];
  244.                     text2 = text2.Substring(22, 20);
  245.                     string text4 = TGEncode.Encode(text2);
  246.                     text4 = FullVerMgr.EncodeWithKey(text4, this.device_id);
  247.                     this.closeConnectingVC();
  248.                     int startIndex = 71;
  249.                     text = text.Substring(startIndex, text4.Length);
  250.                     if (!text4.Equals(text))
  251.                     {
  252.                         this.DeleteFullVerFile();
  253.                     }
  254.                     else
  255.                     {
  256.                         this.gl.FullVersion = 1;
  257.                         this.file_checked = true;
  258.                         if (this.check_state == FullVerMgr.CHECK_STATE.LOAD_GAME)
  259.                         {
  260.                             g.game_mgr.startGame();
  261.                         }
  262.                         else if (this.check_state == FullVerMgr.CHECK_STATE.TURN_OVER)
  263.                         {
  264.                             g.game_mgr.showNextTurnOverMessage();
  265.                         }
  266.                         else if (this.check_state == FullVerMgr.CHECK_STATE.START_GAME || this.check_state == FullVerMgr.CHECK_STATE.PURCHASE_IN_TITLE)
  267.                         {
  268.                             GameObject gameObject = GameObject.Find("TitleVC");
  269.                             if (gameObject != null)
  270.                             {
  271.                                 gameObject.GetComponent<TitleManager>().ShowFullButton(false);
  272.                             }
  273.                         }
  274.                     }
  275.                 }
  276.             }
  277.             catch (Exception ex)
  278.             {
  279.                 this.DeleteFullVerFile();
  280.                 this.closeConnectingVC();
  281.             }
  282.         }
  283.  
  284.         // Token: 0x0600053B RID: 1339 RVA: 0x00052548 File Offset: 0x00050948
  285.         private void DeleteFullVerFile()
  286.         {
  287.             try
  288.             {
  289.                 this.gl.FullVersion = 0;
  290.                 File.Delete(this.file_path);
  291.                 if (this.gl.IsGamePlaying)
  292.                 {
  293.                     GameSlotManager.SaveGameSlot(5);
  294.                     g.game_mgr.logOut(GameManager.LOGOUT_TYPE.EXIT_BUTTON, null);
  295.                 }
  296.             }
  297.             catch (Exception ex)
  298.             {
  299.             }
  300.         }
  301.  
  302.         // Token: 0x0600053C RID: 1340 RVA: 0x000525AC File Offset: 0x000509AC
  303.         protected override void closeMessageYes(int message_index)
  304.         {
  305.             base.closeMessageYes(message_index);
  306.             if (message_index == 241)
  307.             {
  308.                 this.loadConnectingVC();
  309.                 this.UpgradeFullVer();
  310.             }
  311.         }
  312.  
  313.         // Token: 0x0600053D RID: 1341 RVA: 0x000525CC File Offset: 0x000509CC
  314.         private void ResponseFromServer(string content)
  315.         {
  316.             if (this.request_idx == FullVerMgr.REQUEST.CHECK_VERSION_0 || this.request_idx == FullVerMgr.REQUEST.CHECK_VERSION_1)
  317.             {
  318.                 if (content.Equals("1.0.0"))
  319.                 {
  320.                     this.loadConnectingVC();
  321.                     this.CheckGoogleAccountFullVer();
  322.                 }
  323.                 else
  324.                 {
  325.                     base.showDelayMessageBox(2, 75, null, false);
  326.                 }
  327.             }
  328.             else if (this.request_idx == FullVerMgr.REQUEST.VERIFY_RECEIPT)
  329.             {
  330.                 string[] array = Regex.Split(content, "` ");
  331.                 if (array[array.Length - 1].Equals("in_app_full_ver_ok"))
  332.                 {
  333.                     this.SaveServerKey(array[0]);
  334.                     base.showDelayMessageBox(1, 82, null, false);
  335.                 }
  336.                 else
  337.                 {
  338.                     base.showDelayMessageBox(2, 85, null, false);
  339.                 }
  340.             }
  341.             else if (this.request_idx == FullVerMgr.REQUEST.GENERATE_FULL_VER_CODE)
  342.             {
  343.                 string[] array2 = Regex.Split(content, "` ");
  344.                 if (array2[array2.Length - 1].Equals("full_ver_code_ok"))
  345.                 {
  346.                     this.SaveServerKey(array2[0]);
  347.                 }
  348.                 else
  349.                 {
  350.                     string message_add = string.Format("[{0}]", content);
  351.                     base.showDelayMessageBox(2, 15, message_add, false);
  352.                 }
  353.             }
  354.         }
  355.  
  356.         // Token: 0x0600053E RID: 1342 RVA: 0x000526CB File Offset: 0x00050ACB
  357.         private void RequestToServer(string php_file, string body, bool showConnectingVC)
  358.         {
  359.             if (showConnectingVC)
  360.             {
  361.                 this.loadConnectingVC();
  362.             }
  363.             base.StartCoroutine(this.Request(php_file, body));
  364.         }
  365.  
  366.         // Token: 0x0600053F RID: 1343 RVA: 0x000526E8 File Offset: 0x00050AE8
  367.         private void RequestToServer(string php_file, string body)
  368.         {
  369.             this.RequestToServer(php_file, body, true);
  370.         }
  371.  
  372.         // Token: 0x06000540 RID: 1344 RVA: 0x000526F3 File Offset: 0x00050AF3
  373.         private void loadConnectingVC()
  374.         {
  375.             if (this.connecting_vc == null)
  376.             {
  377.                 this.connecting_vc = UnityEngine.Object.Instantiate<GameObject>(Resources.Load<GameObject>("Prefabs/Misc/ConnectingVC"));
  378.             }
  379.         }
  380.  
  381.         // Token: 0x06000541 RID: 1345 RVA: 0x0005271B File Offset: 0x00050B1B
  382.         private void closeConnectingVC()
  383.         {
  384.             if (this.connecting_vc != null)
  385.             {
  386.                 UnityEngine.Object.Destroy(this.connecting_vc);
  387.                 this.connecting_vc = null;
  388.             }
  389.         }
  390.  
  391.         // Token: 0x06000542 RID: 1346 RVA: 0x00052740 File Offset: 0x00050B40
  392.         private IEnumerator Request(string php_file, string body)
  393.         {
  394.             string url = Global.IP + php_file;
  395.             Dictionary<string, string> headers = new Dictionary<string, string>();
  396.             headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
  397.             headers.Add("User-Agent", "AirTycoon5");
  398.             string encoded_data = TGEncode.Encode(body);
  399.             string data = "tgl=" + encoded_data;
  400.             WWW www = null;
  401.             for (int i = 0; i < 5; i++)
  402.             {
  403.                 float start_time = Time.time;
  404.                 bool failed = false;
  405.                 www = new WWW(url, Encoding.UTF8.GetBytes(data), headers);
  406.                 while (!failed && !www.isDone)
  407.                 {
  408.                     if (www.progress == 0f && Time.time - start_time > this.www_timeout)
  409.                     {
  410.                         if (www != null)
  411.                         {
  412.                             www.Dispose();
  413.                             www = null;
  414.                         }
  415.                         failed = true;
  416.                         break;
  417.                     }
  418.                     yield return null;
  419.                 }
  420.                 if (www == null || !string.IsNullOrEmpty(www.error))
  421.                 {
  422.                     failed = true;
  423.                 }
  424.                 if (!failed)
  425.                 {
  426.                     break;
  427.                 }
  428.                 yield return new WaitForSeconds(1f);
  429.             }
  430.             this.closeConnectingVC();
  431.             if (www == null || !string.IsNullOrEmpty(www.error))
  432.             {
  433.                 string arg;
  434.                 if (www == null)
  435.                 {
  436.                     arg = "The request timed out";
  437.                 }
  438.                 else
  439.                 {
  440.                     arg = www.error;
  441.                 }
  442.                 if (this.request_idx == FullVerMgr.REQUEST.CHECK_VERSION_0)
  443.                 {
  444.                     Global.IP = "http://121.190.7.75:8284/AT5/";
  445.                     this.www_timeout = 10f;
  446.                     this.request_idx = FullVerMgr.REQUEST.CHECK_VERSION_1;
  447.                     this.RequestToServer("version.php", string.Empty);
  448.                 }
  449.                 else if (this.request_idx == FullVerMgr.REQUEST.CHECK_VERSION_1)
  450.                 {
  451.                     Global.IP = "http://tradegame2.iptime.org:8284/AT5/";
  452.                     string message_add = string.Format("[{0}]", arg);
  453.                     base.showMessageBox(2, 69, message_add, false);
  454.                 }
  455.                 else
  456.                 {
  457.                     string message_add2 = string.Format("[{0}]", arg);
  458.                     base.showMessageBox(2, 69, message_add2, false);
  459.                 }
  460.             }
  461.             else
  462.             {
  463.                 string text = www.text;
  464.                 this.ResponseFromServer(text);
  465.             }
  466.             yield break;
  467.         }
  468.  
  469.         // Token: 0x06000543 RID: 1347 RVA: 0x0005276C File Offset: 0x00050B6C
  470.         private static string EncodeWithKey(string param, string key)
  471.         {
  472.             byte[] bytes = Encoding.UTF8.GetBytes(param);
  473.             byte[] bytes2 = Encoding.UTF8.GetBytes(key);
  474.             byte b = 0;
  475.             int length = key.Length;
  476.             byte[] array = new byte[bytes.Length];
  477.             for (int i = 0; i < bytes.Length; i++)
  478.             {
  479.                 byte b2 = bytes[i] ^ bytes2[i % length] ^ b;
  480.                 b = b2;
  481.                 array[i] = b2;
  482.             }
  483.             return Convert.ToBase64String(array);
  484.         }
  485.  
  486.         // Token: 0x04000AF0 RID: 2800
  487.         private GameObject connecting_vc;
  488.  
  489.         // Token: 0x04000AF1 RID: 2801
  490.         private string device_id = string.Empty;
  491.  
  492.         // Token: 0x04000AF2 RID: 2802
  493.         private string full_ver_random_id = string.Empty;
  494.  
  495.         // Token: 0x04000AF3 RID: 2803
  496.         private string file_path;
  497.  
  498.         // Token: 0x04000AF4 RID: 2804
  499.         private bool file_checked;
  500.  
  501.         // Token: 0x04000AF5 RID: 2805
  502.         private const int FULL_VER_KEY_LENGTH = 20;
  503.  
  504.         // Token: 0x04000AF6 RID: 2806
  505.         private const int FULL_VER_KEY_LENGTH_DUMMY = 50;
  506.  
  507.         // Token: 0x04000AF7 RID: 2807
  508.         private const int FULL_VER_KEY_START_OFFSET = 22;
  509.  
  510.         // Token: 0x04000AF8 RID: 2808
  511.         private const int SERVER_KEY_LENGTH_DUMMY = 46;
  512.  
  513.         // Token: 0x04000AF9 RID: 2809
  514.         private const int SERVER_KEY_START_OFFSET = 19;
  515.  
  516.         // Token: 0x04000AFA RID: 2810
  517.         private FullVerMgr.REQUEST request_idx;
  518.  
  519.         // Token: 0x04000AFB RID: 2811
  520.         private FullVerMgr.CHECK_STATE check_state;
  521.  
  522.         // Token: 0x04000AFC RID: 2812
  523.         private float www_timeout = 10f;
  524.  
  525.         // Token: 0x020000D1 RID: 209
  526.         private enum REQUEST
  527.         {
  528.             // Token: 0x04000AFE RID: 2814
  529.             CHECK_VERSION_0,
  530.             // Token: 0x04000AFF RID: 2815
  531.             CHECK_VERSION_1,
  532.             // Token: 0x04000B00 RID: 2816
  533.             GENERATE_FULL_VER_CODE,
  534.             // Token: 0x04000B01 RID: 2817
  535.             VERIFY_RECEIPT
  536.         }
  537.  
  538.         // Token: 0x020000D2 RID: 210
  539.         public enum CHECK_STATE
  540.         {
  541.             // Token: 0x04000B03 RID: 2819
  542.             START_GAME,
  543.             // Token: 0x04000B04 RID: 2820
  544.             PURCHASE_IN_TITLE,
  545.             // Token: 0x04000B05 RID: 2821
  546.             LOAD_GAME,
  547.             // Token: 0x04000B06 RID: 2822
  548.             TURN_OVER
  549.         }
  550.     }
  551. }
  552.  
Add Comment
Please, Sign In to add comment