示例#1
0
        public void SaveEncryptedData()
        {
            string playerFile = Path.Combine(Location, "player.salakieli");

            if (File.Exists(playerFile))
            {
                string      contents = GameSaveCrypto.Decrypt(playerFile);
                XmlDocument xmlDoc   = new XmlDocument();
                xmlDoc.LoadXml(contents);

                XmlNode transformNode = xmlDoc.SelectSingleNode("//Entity/_Transform");
                transformNode.Attributes["position.x"].Value = PositionX.ToString();
                transformNode.Attributes["position.y"].Value = PositionY.ToString();

                XmlNode damageNode = xmlDoc.SelectSingleNode("//Entity/DamageModelComponent");
                damageNode.Attributes["hp"].Value     = (HP / 25f).ToString();
                damageNode.Attributes["max_hp"].Value = (MaxHP / 25f).ToString();

                XmlNode walletNode = xmlDoc.SelectSingleNode("//Entity/WalletComponent");
                walletNode.Attributes["money"].Value = Money.ToString();

                XmlNode gameLogNode = xmlDoc.SelectSingleNode("//Entity/GameLogComponent");
                gameLogNode.Attributes["report_damage"].Value = ReportDamage ? "1" : "0";

                using (var stringWriter = new StringWriter())
                    using (var xmlTextWriter = XmlWriter.Create(stringWriter))
                    {
                        xmlDoc.WriteTo(xmlTextWriter);
                        xmlTextWriter.Flush();
                        GameSaveCrypto.Encrypt(playerFile, stringWriter.GetStringBuilder().ToString());
                    }
            }
        }
示例#2
0
        public void Decrypt()
        {
            string playerFile = Path.Combine(Location, "player.salakieli");

            if (File.Exists(playerFile))
            {
                string contents = GameSaveCrypto.Decrypt(playerFile);
                File.WriteAllText(playerFile + ".xml", contents);
            }

            string worldStateFile = Path.Combine(Location, "world_state.salakieli");

            if (File.Exists(worldStateFile))
            {
                string contents = GameSaveCrypto.Decrypt(worldStateFile);
                File.WriteAllText(worldStateFile + ".xml", contents);
            }

            string magicNumbersFile = Path.Combine(Location, "magic_numbers.salakieli");

            if (File.Exists(magicNumbersFile))
            {
                string contents = GameSaveCrypto.Decrypt(magicNumbersFile);
                File.WriteAllText(magicNumbersFile + ".xml", contents);
            }
        }
示例#3
0
        public void LoadEncryptedData()
        {
            string playerFile = Path.Combine(Location, "player.salakieli");

            if (File.Exists(playerFile))
            {
                string      contents = GameSaveCrypto.Decrypt(playerFile);
                XmlDocument xmlDoc   = new XmlDocument();
                xmlDoc.LoadXml(contents);

                XmlNode transformNode = xmlDoc.SelectSingleNode("//Entity/_Transform");
                PositionX = float.Parse(transformNode.Attributes["position.x"].Value);
                PositionY = float.Parse(transformNode.Attributes["position.y"].Value);

                XmlNode damageNode = xmlDoc.SelectSingleNode("//Entity/DamageModelComponent");
                HP    = float.Parse(damageNode.Attributes["hp"].Value) * 25;
                MaxHP = float.Parse(damageNode.Attributes["max_hp"].Value) * 25;

                XmlNode walletNode = xmlDoc.SelectSingleNode("//Entity/WalletComponent");
                Money = uint.Parse(walletNode.Attributes["money"].Value);

                XmlNode gameLogNode = xmlDoc.SelectSingleNode("//Entity/GameLogComponent");
                ReportDamage = gameLogNode.Attributes["report_damage"].Value == "1";
            }
        }