· 7 years ago · Jun 28, 2018, 10:12 PM
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4using System.Text;
5using System.IO;
6using System.Threading;
7using System.Security.Cryptography;
8using Newtonsoft.Json;
9using CodeStage.AntiCheat.ObscuredTypes;
10using UnityEngine.SceneManagement;
11
12public class FristController : MonoBehaviour {
13 //메롱
14 private static FristController _instance = null;
15 public static FristController Instance
16 {
17 get
18 {
19 if (_instance == null)
20 {
21 _instance = FindObjectOfType(typeof(FristController)) as FristController;
22
23 if (_instance == null)
24 {
25 Debug.Log("없어");
26 }
27 }
28
29 return _instance;
30 }
31 }
32
33 public struct goCatInfo // ì²˜ìŒ ì„ íƒë˜ëŠ” 냥ì´;
34 {
35 public int cat_number { get; set; }
36 }
37
38 public struct CanInfo // ìº”ì •ë³´;
39 {
40 public int canCount { get; set; }
41 }
42
43 public struct ScoreInfo
44 {
45 public int scoreInfo { get; set; }
46 }
47
48 public struct CatStatInfo //ê³ ì–‘ì´ ì´ì •ë³´ 스탯
49 {
50 public string catname { get; set; }
51 public string catkorname { get; set; }
52 public int catnumber { get; set; }
53 public Dictionary<string, float> catStat { get; set; }
54
55 }
56 //ê³ ì–‘ì´ ëŠ¥ë ¥ì¹˜ 다르게 하는 í”Œë ˆì´ì–´ í”„ë ™ìŠ¤
57
58 // 코코 치즈 í„±ì‹œë„ ì 프 7 ê· ê° 5 ì½”ì¸ 5í¼ì„¼íЏ 1500냥
59 // ìš°ìœ ì‚¼ìƒ‰ì´ ì 프 6.5 ê· ê° 5 ì½”ì¸ 10í¼ì„¼íЏ 2000냥
60 // 샴 ë±…ê°ˆ 마우 러블 ì 프 6 ê· ê° 4.5 15 í¼ì„¼íЏ 2500냥
61 public ObscuredString keys = "1234567890123456";
62
63 ObscuredString m_savedFilePaht = "/goCatinfo.json";
64 ObscuredString m_cansavedFilePaht = "/canInfo.json";
65 // ObscuredString m_scoresaveFilepath = "/"
66 // Use this for initialization
67
68 void Start () {
69
70 findJsons();
71
72 }
73
74 // Update is called once per frame
75 void Update () {
76
77 }
78
79 public void goNext()
80 {
81 SceneManager.LoadScene("SampleScene");
82 DontDestroyOnLoad(this);
83 }
84
85 // íŒŒì¼ í™•ì¸ -> 없으면 ìƒì„± -> 있으면 넘어가기;
86
87 private void findJsons()
88 {
89 if(File.Exists(GetFilePath()) == true){
90 Debug.Log("íŒŒì¼ ìžˆì–´ìš”");
91 loadJsonGocatInfo();
92 }
93 else
94 {
95 Debug.Log("íŒŒì¼ ì—†ì–´ìš”");
96 makeJsonGocatInfo(0);
97 }
98
99 if(!File.Exists(Application.persistentDataPath + m_cansavedFilePaht))
100 {
101 //없으면임
102
103 makeCanInfo(0);
104 } else
105 {
106 //있으면임
107 Debug.Log("ìº”ì •ë³´ë„ ìžˆêµ°ìš”");
108 }
109
110 if(!File.Exists(Application.persistentDataPath + "/scoreInfo.json"))
111 {
112 makeScoreInfo(0);
113 } else
114 {
115 Debug.Log("스코어 ì •ë³´ë„ ìžˆì–´ìš”");
116 }
117
118 if(!File.Exists(Application.persistentDataPath + "/catStatInfo.json"))
119 {
120 //없으면
121 makeCatStats();
122
123 }
124 else
125 {
126 Debug.Log("냥ì´ë“¤ ìŠ¤íƒ¯ì •ë³´ë„ ìžˆì–´ìš”.");
127 }
128 }
129
130 private string GetFilePath()
131 {
132 string fullpath;
133
134 fullpath = Application.persistentDataPath + m_savedFilePaht;
135
136
137 return fullpath;
138 }
139
140 public string AesEncrypt256(string Input, string key) //암호화!
141 {
142 RijndaelManaged RijndaelCipher = new RijndaelManaged();
143
144 byte[] PlainText = Encoding.Unicode.GetBytes(Input);
145 byte[] Salt = Encoding.ASCII.GetBytes(key.Length.ToString());
146
147 PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(key, Salt);
148 ICryptoTransform Encryptor = RijndaelCipher.CreateEncryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));
149
150 MemoryStream memoryStream = new MemoryStream();
151 CryptoStream cryptoStream = new CryptoStream(memoryStream, Encryptor, CryptoStreamMode.Write);
152
153 cryptoStream.Write(PlainText, 0, PlainText.Length);
154 cryptoStream.FlushFinalBlock();
155
156 byte[] CipherBytes = memoryStream.ToArray();
157
158 memoryStream.Close();
159 cryptoStream.Close();
160
161 string EncryptedData = System.Convert.ToBase64String(CipherBytes);
162
163 return EncryptedData;
164 }
165
166 public string AesDecrypt256(string Input, string key)
167 {
168 RijndaelManaged RijndaelCipher = new RijndaelManaged();
169
170 byte[] EncryptedData = System.Convert.FromBase64String(Input);
171 byte[] Salt = Encoding.ASCII.GetBytes(key.Length.ToString());
172
173 PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(key, Salt);
174 ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));
175 MemoryStream memoryStream = new MemoryStream(EncryptedData);
176 CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read);
177
178 byte[] PlainText = new byte[EncryptedData.Length];
179
180 int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length);
181
182 memoryStream.Close();
183 cryptoStream.Close();
184
185 string DecryptedData = Encoding.Unicode.GetString(PlainText, 0, DecryptedCount);
186
187 return DecryptedData;
188
189 } //복호화..
190
191 private void makeJsonGocatInfo(int number)
192 {
193 goCatInfo name = new goCatInfo
194 {
195 cat_number = number
196 };
197
198 JsonSerializerSettings settings = new JsonSerializerSettings();
199
200 settings.Formatting = Formatting.Indented;
201 settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
202 List<goCatInfo> goCatinfosFromCode = new List<goCatInfo> { name };
203
204 string json = JsonConvert.SerializeObject(goCatinfosFromCode, settings);
205 string json2 = AesEncrypt256(json, keys);
206 string path = Path.Combine(Application.persistentDataPath, "goCatinfo.json");
207
208 File.WriteAllText(path, json2);
209
210 Debug.Log(GetFilePath());
211 Debug.Log(path);
212 } //ì²˜ìŒ ê³ ì–‘ì´ ì„ íƒí• ê±° 맴들기
213
214 public void makeCanInfo(int _canCount)
215 {
216 CanInfo canInfo = new CanInfo
217 {
218 canCount = _canCount
219 };
220
221 JsonSerializerSettings settings = new JsonSerializerSettings();
222
223 settings.Formatting = Formatting.Indented;
224 settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
225 List<CanInfo> canInfoFromCode = new List<CanInfo> { canInfo };
226
227 string json = JsonConvert.SerializeObject(canInfoFromCode, settings);
228 string json2 = AesEncrypt256(json, keys);
229 string path = Path.Combine(Application.persistentDataPath, "canInfo.json");
230
231 File.WriteAllText(path, json2);
232
233 Debug.Log(path);
234 }
235
236 public void makeScoreInfo(int _score)
237 {
238 ScoreInfo scroeInfo = new ScoreInfo
239 {
240 scoreInfo = _score
241 };
242
243 JsonSerializerSettings setting = new JsonSerializerSettings();
244
245 setting.Formatting = Formatting.Indented;
246 setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
247 List<ScoreInfo> scoreInfoFromCode = new List<ScoreInfo> { scroeInfo };
248
249 string json = JsonConvert.SerializeObject(scoreInfoFromCode, setting);
250 string json2 = AesEncrypt256(json, keys);
251 string path = Path.Combine(Application.persistentDataPath, "scoreInfo.json");
252
253 File.WriteAllText(path, json2);
254
255 Debug.Log(path);
256 }
257
258 public void makeCatStats()
259 {
260 string runVelocity = "runvelocity";//ì 프 높ì´; 1~10;
261 string relativeVelocityX = "relativeVelocityX"; //ê· í˜•ê°ê°; 1~10;
262 string plusGetPercent = "plusGetCanPercent"; //추가 íšë“캔
263
264 CatStatInfo koko = new CatStatInfo
265 {
266 catname = "Koko",
267 catkorname = "ê³ ì½”",
268 catnumber = 0,
269 catStat = new Dictionary<string, float>
270 {
271 {runVelocity, 7},
272 {relativeVelocityX, 5},
273 {plusGetPercent, 5 }
274 }
275 };
276
277 CatStatInfo cheese = new CatStatInfo
278 {
279 catname = "Cheese",
280 catkorname = "치즈",
281 catnumber = 1,
282 catStat = new Dictionary<string, float>
283 {
284 {runVelocity, 7},
285 {relativeVelocityX, 5},
286 {plusGetPercent, 5 }
287 }
288 };
289
290 CatStatInfo tuck = new CatStatInfo
291 {
292 catname = "Tuck",
293 catkorname = "턱시ë„",
294 catnumber = 2,
295 catStat = new Dictionary<string, float>
296 {
297 {runVelocity, 7},
298 {relativeVelocityX, 5},
299 {plusGetPercent, 5 }
300 }
301 };
302
303 CatStatInfo milk = new CatStatInfo
304 {
305 catname = "Milk",
306 catkorname = "ìš°ìœ ",
307 catnumber = 3,
308 catStat = new Dictionary<string, float>
309 {
310 {runVelocity, 6.5f},
311 {relativeVelocityX, 5},
312 {plusGetPercent, 10}
313 }
314 };
315
316 CatStatInfo sam = new CatStatInfo
317 {
318 catname = "ThreeColor",
319 catkorname = "삼색",
320 catnumber = 4,
321 catStat = new Dictionary<string, float>
322 {
323 {runVelocity, 6.5f},
324 {relativeVelocityX, 5},
325 {plusGetPercent, 10}
326 }
327 };
328
329 CatStatInfo siam = new CatStatInfo
330 {
331 catname = "Siam",
332 catkorname = "샴",
333 catnumber = 5,
334 catStat = new Dictionary<string, float>
335 {
336 {runVelocity, 6},
337 {relativeVelocityX, 4.5f},
338 {plusGetPercent, 15}
339 }
340 };
341
342 CatStatInfo beng = new CatStatInfo
343 {
344 catname = "bengal",
345 catkorname = "벵갈",
346 catnumber = 6,
347 catStat = new Dictionary<string, float>
348 {
349 {runVelocity, 6},
350 {relativeVelocityX, 4.5f},
351 {plusGetPercent, 15}
352 }
353 };
354
355 CatStatInfo mau = new CatStatInfo
356 {
357 catname = "Bengal",
358 catkorname = "벵갈",
359 catnumber = 7,
360 catStat = new Dictionary<string, float>
361 {
362 {runVelocity, 6},
363 {relativeVelocityX, 4.5f},
364 {plusGetPercent, 15}
365 }
366 };
367
368 CatStatInfo rubble = new CatStatInfo
369 {
370 catname = "Lovle",
371 catkorname = "러블",
372 catnumber = 8,
373 catStat = new Dictionary<string, float>
374 {
375 {runVelocity, 6},
376 {relativeVelocityX, 4.5f},
377 {plusGetPercent, 15}
378 }
379 };
380
381 JsonSerializerSettings settings = new JsonSerializerSettings();
382
383 settings.Formatting = Formatting.Indented;
384 settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
385
386 List<CatStatInfo> statInfoFromCode = new List<CatStatInfo> { koko, cheese, tuck, milk, sam, siam, beng, mau, rubble };
387
388 string json = JsonConvert.SerializeObject(statInfoFromCode, settings);
389 string json2 = AesEncrypt256(json, keys);
390 string path = Path.Combine(Application.persistentDataPath, "catStatInfo.json");
391
392 File.WriteAllText(path, json2);
393 }
394
395 public void loadJsonGocatInfo() //복호화 순서 파ì¼ë¶€í„° ë¶€ë¥´ê³ ë³µí˜¸í™”í•˜ê³ ë””ì‹œë¦¬ì–¼ë¼ì´ì¦ˆë“œ;
396 {
397 string path = Path.Combine(Application.persistentDataPath, "goCatinfo.json");
398 string read = File.ReadAllText(path);
399 string decry = AesDecrypt256(read, keys);
400 goCatInfo name = JsonConvert.DeserializeObject<List<goCatInfo>>(decry)[0];
401
402 Debug.Log("네임.캣네임 : " + name.cat_number);
403
404 }