Example #1
0
    public static void SaveStrings()
    {
        if (setting.disablePlayerPrefs)
        {
            SetStrings.Clear();
            return;
        }
        StringBuilder lg = new StringBuilder();

        lg.AppendLine("saved keys" + playerPrefKeys.Count);
        foreach (var a in SetStrings)
        {
            PlayerPrefs.SetString(a.Key.ToLower(), a.Value);
            lg.AppendLine(a.Key + "\t\t\t" + a.Value);
        }
        print("Save strings " + SetStrings.Count + "\n" + (Debug.isDebugBuild ? lg.ToString() : lg.Length.ToString()));
        SetStrings.Clear();

        StringBuilder sb = new StringBuilder();

        foreach (var a in playerPrefKeys)
        {
            sb.Append(a).Append(",");
        }

        var s = Convert.ToBase64String(GZipStream.CompressString(sb.ToString()));

        print(sb.Length + " vs " + s.Length);
        PlayerPrefs.SetString2(keysNew3, s);


        PlayerPrefs.Save();
    }
Example #2
0
 protected bool Equals(Collection other)
 {
     return(Id == other.Id &&
            ArrayStrings.EquivalentTo(other.ArrayStrings) &&
            SetStrings.EquivalentTo(other.SetStrings) &&
            ListStrings.EquivalentTo(other.ListStrings) &&
            ArrayInts.EquivalentTo(other.ArrayInts) &&
            SetInts.EquivalentTo(other.SetInts) &&
            ListInts.EquivalentTo(other.ListInts) &&
            DictionaryInts.EquivalentTo(other.DictionaryInts) &&
            DictionaryStrings.EquivalentTo(other.DictionaryStrings) &&
            PocoLookup.EquivalentTo(other.PocoLookup, (a, b) => a.EquivalentTo(b)) &&
            PocoLookupMap.EquivalentTo(other.PocoLookupMap, (a, b) => a.EquivalentTo(b, (m1, m2) => m1.EquivalentTo(m2))));
 }
Example #3
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Id;
         hashCode = (hashCode * 397) ^ (ArrayStrings != null ? ArrayStrings.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (SetStrings != null ? SetStrings.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ListStrings != null ? ListStrings.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ArrayInts != null ? ArrayInts.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (SetInts != null ? SetInts.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ListInts != null ? ListInts.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (DictionaryInts != null ? DictionaryInts.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (DictionaryStrings != null ? DictionaryStrings.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (PocoLookup != null ? PocoLookup.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (PocoLookupMap != null ? PocoLookupMap.GetHashCode() : 0);
         return(hashCode);
     }
 }
    protected IEnumerator LoadPlayerPrefs(string text)
    {
        WWW w = null;

        //if (!statsSaved)
        {
            var s = mainSite + "/players/" + playerName.ToLower() + "/prefs.txt";
            if (isDebug)
            {
                s += "?" + Random.value;
            }
            Debug.Log(s);
            w = new WWW(s);
            while (!w.isDone)
            {
                popupText = Tr("Logging in ") + ((int)w.progress * 100) + "%";
                yield return(null);
            }
        }
        try
        {
            StringBuilder sb = new StringBuilder();
            Dictionary <string, string> dict = ParseDict(text);
            modTypeInt = int.Parse(dict.TryGetDontSet("modType", "0"));
            //sb.AppendLine("parsed Rep: " + reputation);
            //sb.AppendLine("parsed medals: " + medals);
            //sb.AppendLine("parsed modType: " + modTypeInt);
            userId = int.Parse(dict.TryGetDontSet("id", "0"));
            print("parsed userId: " + userId);
            bool crypt         = false;
            bool ovrd          = false;
            var  plnameToLower = playerName;
            if (string.IsNullOrEmpty(w.error))
            {
                var buffer = w.bytes;
                try
                {
                    Xor(buffer);
                    buffer = GZipStream.UncompressBuffer(buffer);
                }
                catch (System.Exception) { Debug.LogWarning("Failed uncompress"); Xor(buffer); }
                if (buffer.Length > 0)
                {
                    using (var ms = new BinaryReader(buffer))
                    {
                        sb.AppendLine("loading stats ");
                        int i     = 0;
                        var local = playerPrefKeys.Count;
                        while (ms.Position < ms.Length)
                        {
                            var key   = ms.ReadString();
                            var value = ms.ReadString();
                            if (value.Length > MaxLength || key.Length > MaxLength)
                            {
                                Debug.LogError(string.Format("too big value {0} {1}", key, value));
                                continue;
                            }
#if !UNITY_WP8
                            if (crypt)
                            {
                                key   = ObscuredString.EncryptDecrypt(key);
                                value = ObscuredString.EncryptDecrypt(value);
                            }
#endif
                            if (key == "Enc" && value == "Enc")
                            {
                                Debug.LogWarning("Encoded");
                                crypt = true;
                                continue;
                            }

                            if (key == _DefinePrefsTime && loggedInTime != 0)
                            {
                                ovrd = loggedInTime < int.Parse(value);

                                //if (ovrd)
                                //lastError = "Override Detected";
                                LogEvent(EventGroup.Debug, "Override Detected");
                                Debug.Log("Set override to: " + ovrd);
                                ovrd = false;
                                continue;
                            }
                            i++;

                            //if (!playerPrefKeys.Contains(key)) //may be incorrect
                            //{

                            //if (string.IsNullOrEmpty(PlayerPrefsGetString(key)))
                            var lowerKey = key.ToLower();
                            if (ResLoader.isEditor && !lowerKey.StartsWith(plnameToLower))
                            {
                                continue;
                            }

                            if (ovrd || !PlayerPrefs.HasKey(lowerKey))
                            {
                                PlayerPrefsSetString(key, value);
                            }
                            else
                            {
                                playerPrefKeys.Add(key);
                            }
                            //}
                            sb.Append(string.Format("{0}:{1},", key, value));
                        }

                        Debug.LogWarning("loading player prefs local:" + local + " remote:" + i + " \n" + (Debug.isDebugBuild ? sb.ToString() : sb.Length.ToString()));
                        SetStrings.Clear();
                        //statsSaved = true;
                    }
                }
                else
                {
                    Debug.LogWarning("player prefs empty");
                }
                //}
            }
            else //if (!w.error.StartsWith("404") && w.error.ToLower().StartsWith("failed downloading"))
            {
                throw new Exception(w.error);
            }
            //if (!setting.disPlayerPrefs2)
            //{
            //print("reputation " + reputation);
            //if (reputation < 5)
            if (_Loader.vkSite)
            {
                StartCoroutine(AddMethod(delegate
                {
                    reputation       = Mathf.Max(int.Parse(dict.TryGetDontSet("reputation", "0")), reputation);
                    medals           = Mathf.Max(int.Parse(dict.TryGetDontSet("medals", "0")), medals);
                    _Awards.xp.count = Mathf.Max(int.Parse(dict.TryGetDontSet("xp", "0")), _Awards.xp.count);
                }));
            }

            allowSavePrefs = bool.Parse(dict.TryGetDontSet("allowSavePrefs", "true"));
            //}
        }
        catch (System.Exception e)
        {
            SetStrings.Clear();
            //if (!statsSaved)
            {
                Debug.LogError(e);
                lastError = e.Message.Replace("\r", "   ").Replace("\n", "    ");
                //GoOffline();
                LogEvent("Login Failed Critical Error");
                OnLoginFailed(e.Message + "\n" + Tr(" Critical Error"));
                yield break;
            }
        }
        RefreshPrefs();
        //SaveStrings();
        OnLoggedIn();
        WindowPool();
    }