using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.NetworkInformation; using System.Text; using System.Threading.Tasks; using UnityEngine; namespace ET { public class IdentifyHelper { private static string Localkey() { string path = Path.Combine(new DirectoryInfo(Application.persistentDataPath).Parent.FullName, "client"); if (!Directory.Exists(path)) { DirectoryInfo di = Directory.CreateDirectory(path); di.Attributes = FileAttributes.Directory | FileAttributes.Hidden; } path = Path.Combine(path, "key.key"); if (File.Exists(path)) { StreamReader sr = new StreamReader(path); string key = sr.ReadToEnd(); byte[] bytes = Encoding.UTF8.GetBytes(key); Utility.Encryption.GetSelfXorBytes(bytes, GameKeyComponent.Instance.xorKey); key= Encoding.UTF8.GetString(bytes); sr.Close(); return key; } else { StreamWriter sw = File.CreateText(path); string guid = Guid.NewGuid().ToString(); string key =$"{guid[3]}{guid[5]}{guid}"; byte[] bytes =Encoding.UTF8.GetBytes(key); Utility.Encryption.GetSelfXorBytes(bytes,GameKeyComponent.Instance.xorKey); string newKey = Encoding.UTF8.GetString(bytes); sw.Write(newKey); sw.Close(); return key; } } public static string Start() { string mac = GetMacAddress(); string id = GetAndroidID(); string device = SystemInfo.deviceUniqueIdentifier; string key = Localkey(); string str = $"{mac.Length}+{mac}+{id.Length}+{id}+{device.Length}+{device}+{key.Length}+{key}"; byte[] bytes = Encoding.UTF8.GetBytes(str); Utility.Encryption.GetSelfXorBytes(bytes, GameKeyComponent.Instance.xorKey); str = Encoding.UTF8.GetString(bytes); return str; } public static string GetAndroidID() { string _strAndroidID = "none"; if (string.IsNullOrEmpty(_strAndroidID)) { _strAndroidID = "none"; #if (UNITY_ANDROID && !UNITY_EDITOR) || ANDROID_CODE_VIEW try { using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { using (AndroidJavaObject currentActivity = unityPlayer.GetStatic("currentActivity")) { using (AndroidJavaObject contentResolver = currentActivity.Call("getContentResolver")) { using (AndroidJavaClass secure = new AndroidJavaClass("android.provider.Settings$Secure")) { _strAndroidID = secure.CallStatic("getString", contentResolver, "android_id"); if (string.IsNullOrEmpty(_strAndroidID)) { _strAndroidID = "none"; } } } } } } catch (System.Exception e) { } #endif return _strAndroidID; } return _strAndroidID; } private static string GetMacAddress() { string physicalAddress = ""; NetworkInterface[] nice = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adaper in nice) { if (adaper.Description == "en0") { physicalAddress = adaper.GetPhysicalAddress().ToString(); break; } else { physicalAddress = adaper.GetPhysicalAddress().ToString(); if (physicalAddress != "") { break; }; } } return physicalAddress; } } }