Example #1
0
        public void LoadSave(string path)
        {
            this.path = path;
            string slotJson = EncryptString.Decompress(File.ReadAllBytes(path));

            dynamicSlotData = new DynamicSerializable <SlotData>(slotJson);

            var bootJson = EncryptString.Decompress(SlotData.m_Dict["boot"]);

            dynamicBoot    = new DynamicSerializable <BootSaveGameFormat>(bootJson);
            OriginalRegion = Boot.m_SceneName.Value;

            var globalJson = EncryptString.Decompress(SlotData.m_Dict["global"]);

            dynamicGlobal = new DynamicSerializable <GlobalSaveGameFormat>(globalJson);

            Afflictions = new AfflictionsContainer(Global);
        }
Example #2
0
        public Profile(string path)
        {
            this.path = path;

            var json = EncryptString.Decompress(File.ReadAllBytes(path));

            // m_StatsDictionary is invalid json (unquoted keys), so fix it
            json = Regex.Replace(json, @"(\\*\""m_StatsDictionary\\*\"":\{)((?:[-0-9\.]+:\\*\""[-+0-9eE\.]+\\*\""\,?)+)(\})", delegate(Match match)
            {
                string jsonSubStr = Regex.Replace(match.Groups[2].ToString(), @"([-0-9]+):(\\*\"")", delegate(Match matchSub)
                {
                    var escapeStr = matchSub.Groups[2].ToString();
                    return(escapeStr + matchSub.Groups[1].ToString() + escapeStr + @":" + escapeStr);
                });
                return(match.Groups[1].ToString() + jsonSubStr + match.Groups[3].ToString());
            });

            dynamicState = new DynamicSerializable <ProfileState>(json);
        }
Example #3
0
        public Profile(string path)
        {
            this.path = path;

            var json = EncryptString.Decompress(File.ReadAllBytes(path));

            dynamicState = new DynamicSerializable <ProfileState>(json);

            #region Fix m_StatsDictionary
            int currentIndex = 0;
            // m_StatsDictionary is invalid json so we'll fix it
            // There's multiple instances of m_StatsDictionary
            // Ugly as f but works... for now
            while (true)
            {
                int statsDictStartIndex = json.IndexOf("m_StatsDictionary", currentIndex);
                if (statsDictStartIndex == -1)
                {
                    break;
                }
                statsDictStartIndex = json.IndexOf('{', statsDictStartIndex);
                currentIndex        = statsDictStartIndex;

                int statsDictEndIndex = json.IndexOf('}', statsDictStartIndex);

                // Save files contain json that has been serialized multiple times and not all m_StatsDictionarys are on the same depth
                var newStats = json.Substring(statsDictStartIndex, statsDictEndIndex - statsDictStartIndex);
                if (newStats.Length <= 2)
                {
                    continue;
                }
                int depth      = 0;
                int quoteIndex = newStats.IndexOf("\"");
                for (int i = quoteIndex - 1; newStats[i] == '\\'; i--, depth++)
                {
                }
                string escapes = new String('\\', depth);

                for (var i = 0; i < newStats.Length; i++)
                {
                    var c = newStats[i];

                    if ((c == '-' || char.IsDigit(c)))
                    {
                        if (newStats[i - 1] != '"' && newStats[i - 1] != '.')
                        {
                            newStats = newStats.Insert(i, escapes + "\"");
                            i       += 2 + depth;

                            while (char.IsDigit(newStats[i]) || newStats[i] == '-')
                            {
                                i++;
                            }
                            newStats = newStats.Insert(i, escapes + "\"");
                            i       += 1 + depth;
                        }
                        else
                        {
                            while (char.IsDigit(newStats[i]) || newStats[i] == '.' || newStats[i] == 'E' || newStats[i] == '-')
                            {
                                i++;
                            }
                        }
                    }
                }

                json = json.Substring(0, statsDictStartIndex) + newStats + json.Substring(statsDictEndIndex);
            }

            #endregion
        }