Guest User

Untitled

a guest
Jun 24th, 2019
143
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SaveSystem2.cs
  2.  
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System.IO;
  6. using System;
  7. using System.Runtime.Serialization.Formatters.Binary;
  8.  
  9. public class SaveSystem : MonoBehaviour
  10. {
  11. public InputField importValue;
  12. public InputField exportValue;
  13.  
  14. public static string json = "";
  15.  
  16. protected static string encryptKey = "frick,this key is hidden :D!";
  17. protected static string savePath = "/playerdataV1.test";
  18.  
  19. public static void SavePlayer(PlayerData2 data)
  20. {
  21. using (StreamWriter writer = new StreamWriter(Application.persistentDataPath + savePath))
  22. {
  23. json = JsonUtility.ToJson(data);
  24. ConvertStringToBase64(writer, json);
  25. writer.Close();
  26. }
  27. }
  28.  
  29. public static string ConvertStringToBase64(StreamWriter writer, string x)
  30. {
  31. var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(x);
  32. string stringTemp = Convert.ToBase64String(plainTextBytes);
  33.  
  34. writer.WriteLine(SimpleAES.EncryptString(stringTemp, encryptKey));
  35. return stringTemp;
  36. }
  37.  
  38. public static void LoadPlayer(ref PlayerData2 data)
  39. {
  40. if (!File.Exists(Application.persistentDataPath + savePath))
  41. File.CreateText(Application.persistentDataPath + savePath);
  42.  
  43. using (StreamReader reader = new StreamReader(Application.persistentDataPath + savePath))
  44. {
  45. json = ConvertBase64ToString(reader);
  46. data = JsonUtility.FromJson<PlayerData2>(json);
  47. reader.Close();
  48. }
  49. }
  50.  
  51. public static string ConvertBase64ToString(StreamReader reader)
  52. {
  53. string stringConvert = reader.ReadLine();
  54. var base64EncodedBytes = Convert.FromBase64String(SimpleAES.DecryptString(stringConvert, encryptKey));
  55. return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
  56. }
  57.  
  58. public void ImportPlayer2(EthereumController playerData)
  59. {
  60. using (StreamWriter writer = new StreamWriter(Application.persistentDataPath + savePath))
  61. {
  62. writer.WriteLine(importValue.text);
  63. writer.Close();
  64. using (StreamReader reader = new StreamReader(Application.persistentDataPath + savePath))
  65. {
  66. json = ConvertBase64ToString(reader);
  67. playerData.data = JsonUtility.FromJson<PlayerData2>(json);
  68. reader.Close();
  69. }
  70. }
  71. }
  72.  
  73. public void ExportPlayer2()
  74. {
  75. using (StreamReader reader = new StreamReader(Application.persistentDataPath + savePath))
  76. {
  77. string outputData = reader.ReadLine();
  78. Debug.Log(outputData);
  79. reader.Close();
  80. exportValue.text = outputData;
  81. }
  82. }
  83. }
  84.  
  85. EthereumController.cs
  86. using System.Collections;
  87. using System.Collections.Generic;
  88. using UnityEngine;
  89. using UnityEngine.UI;
  90. using System;
  91. using BreakInfinity;
  92.  
  93. [Serializable]
  94. public class PlayerData2
  95. {
  96. public BigDouble ethereumForkVersion; // BigDouble is a double but bigger basically
  97. public BigDouble currentStat;
  98. public BigDouble hardforkStat;
  99. public BigDouble wallet_Faucet;
  100. public float hardforkRunTime;
  101.  
  102. public PlayerData2()
  103. {
  104. ethereumForkVersion = 1;
  105. currentStat = 1;
  106. hardforkStat = 1;
  107. wallet_Faucet = 0;
  108. hardforkRunTime = 0;
  109. }
  110. }
  111.  
  112. public class EthereumController : MonoBehaviour
  113. {
  114. public PlayerData2 data;
  115.  
  116. public void Start()
  117. {
  118. SaveSystem.LoadPlayer(ref data);
  119. }
  120.  
  121. public void Update()
  122. {
  123. SaveSystem.SavePlayer(data);
  124. }
  125. }
RAW Paste Data