コード例 #1
0
        public void ReadHeader(string h_path)
        {
            //read and decode data
            byte[] h_file    = File.ReadAllBytes(h_path);
            byte[] h_decoded = DecodeEncode.Decode(h_file); // decoded is - dexored content only (since file starts with those 4 bytes)
            h_Raw = Encoding.UTF8.GetString(h_decoded);

            try
            {
                m_Header = Json.Decode(h_Raw);  //this is the header file
            }
            catch
            {
                SaveEmpty = true;
            }

            //fill episodestates
            list_EpStates.Clear();
            foreach (var episode in m_Header.cachedEpisodes)
            {
                list_EpStates.Add(episode);
            }

            //read the date of the save
            for (int i = 0; i < m_Header.saveDate.Length; i++)
            {
                dateofSave[i] = m_Header.saveDate[i]; //need to test if it's possible to write to this dynamic array without an intermediate one
            }
        }
コード例 #2
0
        Dictionary <string, GameVariable> m_Varnames  = new Dictionary <string, GameVariable>(); //string is the variable name here


        public void Read(string path)
        {
            byte[]  file      = File.ReadAllBytes(path);
            byte[]  decoded   = DecodeEncode.Decode(file);
            string  str       = Encoding.UTF8.GetString(decoded); //convert the byte array to a string
            dynamic json      = Json.Decode(str);
            dynamic variables = json.variables;

            foreach (dynamic variable in variables)
            {
                if (variable["$type"] == "StoryVariable")
                {
                    m_Variables[variable.uniqueId] = new GameVariable {
                        name = variable.objectName, id = variable.uniqueId
                    };
                    m_Varnames[variable.objectName] = new GameVariable {
                        name = variable.objectName, id = variable.uniqueId
                    };
                }
            }
        }
コード例 #3
0
        public void WriteHeader(string h_path, dynamic h_json_data)
        {
            h_Raw = Newtonsoft.Json.JsonConvert.SerializeObject(h_json_data, Newtonsoft.Json.Formatting.Indented);
            byte[] content      = Encoding.UTF8.GetBytes(h_Raw);
            byte[] chash        = contenthash.ComputeHash(content);
            byte[] encoded      = DecodeEncode.Decode(content);
            byte[] modded_hfile = new byte[20 + encoded.Length];
            byte[] file_header  = new byte[4] {
                81, 55, 110, 170
            };

            int num = 0;
            int i;

            for (i = 0; i < file_header.Length + num; i++)
            {
                modded_hfile[i] = file_header[i - num];
            }
            num = i;
            while (i < 16 + num)
            {
                modded_hfile[i] = chash[i - num];
                i++;
            }
            num = i;
            while (i < encoded.Length + num)
            {
                modded_hfile[i] = encoded[i - num];
                i++;
            }
            if (!File.Exists(h_path + @".bkp"))
            {
                File.Copy(h_path, h_path + @".bkp", false);
            }

            File.WriteAllBytes(h_path, modded_hfile); //write changes to Header.Save
            h_editsSaved = true;
        }
コード例 #4
0
        public void WriteData(string path, dynamic json_data)
        {
            Raw = Newtonsoft.Json.JsonConvert.SerializeObject(json_data, Newtonsoft.Json.Formatting.Indented); //Raw is a utf8 string.
            byte[] content     = Encoding.UTF8.GetBytes(Raw);                                                  //dexored (for now) new content
            byte[] chash       = contenthash.ComputeHash(content);                                             //md5 hash of dexored new content
            byte[] encoded     = DecodeEncode.Decode(content);                                                 //xor-ed new content. XOR functions can be applied on data to repeatedly encryptt and decrypt it.
            byte[] modded_file = new byte[20 + encoded.Length];
            byte[] file_header = new byte[4] {
                81, 55, 110, 170
            };

            int num = 0;
            int i;

            for (i = 0; i < file_header.Length + num; i++)
            {
                modded_file[i] = file_header[i - num];
            }
            num = i;
            while (i < 16 + num)
            {
                modded_file[i] = chash[i - num];
                i++;
            }
            num = i;
            while (i < encoded.Length + num)
            {
                modded_file[i] = encoded[i - num];
                i++;
            }
            if (!File.Exists(path + @".bkp"))
            {
                File.Copy(path, path + @".bkp", false);
            }

            File.WriteAllBytes(path, modded_file); //write changes to Data.Save
            editsSaved = true;
        }
コード例 #5
0
        public void Read(string path)
        {
            SaveEmpty = false;
            Checkpoints.Clear();
            EpisodePlayed.Clear();

            // read and decode Data
            byte[] file    = File.ReadAllBytes(path);
            byte[] decoded = DecodeEncode.Decode(file); // decoded is - dexored content only (since file starts with header)
            Raw = Encoding.UTF8.GetString(decoded);

            try
            {
                m_Data = Json.Decode(Raw);  //this is the save file, NOT initialdata
            }
            catch
            {
                SaveEmpty = true;
                return;
            }

            // add normal checkpoints
            foreach (var checkpoint in m_Data.checkpoints)
            {
                List <string> flags = new List <string>();
                var           vars  = ReadVarsForCheckpoint(checkpoint);
                foreach (var fl in checkpoint.flags)
                {
                    flags.Add(fl);
                }
                Checkpoints.Add(new Checkpoint(checkpoint, vars, flags));
            }

            // add currentcheckpoint (seems to be identical to latest checkpoint...)

            Dictionary <string, VariableState> variables;

            try
            {
                List <string> flags = new List <string>();
                foreach (var fl in m_Data.currentCheckpoint.stateCheckPoint.flags)
                {
                    flags.Add(fl);
                }
                variables = ReadVarsForCheckpoint(m_Data.currentCheckpoint.stateCheckPoint);
                Checkpoints.Add(new Checkpoint(m_Data.currentCheckpoint.stateCheckPoint, variables, flags));
            }
            catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException)
            {
                SaveEmpty = true;
                return;
            }

            // add global variables as a last checkpoint.. // hack...
            variables = ReadVarsForCheckpoint(m_Data);
            Checkpoints.Add(new Checkpoint(new { pointIdentifier = "Global Vars", currentObjective = "" }, variables));

            // fill episodeState (?)
            foreach (var episode in m_Data.episodes)
            {
                string name     = episode.name;
                string stateStr = episode.episodeState;
                bool   played   = false;
                if (stateStr == "kFinished" || stateStr == "kInProgress")
                {
                    played = true;
                }
                EpisodePlayed[name] = played;
            }
            if (File.Exists(Path.GetDirectoryName(path) + @"\Header.Save"))
            {
                ReadHeader(Path.GetDirectoryName(path) + @"\Header.Save");
            }
            else
            {
                m_Header = null;
            }
        }