Exemple #1
0
    private void SaveGameDescriptor(Stream stream)
    {
        ISerializationService service = Services.GetService <ISerializationService>();

        if (service != null)
        {
            XmlWriterSettings settings = new XmlWriterSettings
            {
                Encoding           = Encoding.UTF8,
                Indent             = true,
                IndentChars        = "  ",
                NewLineChars       = "\r\n",
                NewLineHandling    = NewLineHandling.Replace,
                OmitXmlDeclaration = true
            };
            using (System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create(stream, settings))
            {
                xmlWriter.WriteStartDocument();
                XmlSerializer xmlSerializer = service.GetXmlSerializer <GameSaveDescriptor>();
                xmlSerializer.Serialize(xmlWriter, this.GameSaveDescriptor);
                xmlWriter.WriteEndDocument();
                xmlWriter.Flush();
                xmlWriter.Close();
            }
        }
    }
Exemple #2
0
    public static IEnumerable <GameSaveDescriptor> GetListOfGameSaveDescritors(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            yield break;
        }
        if (!Directory.Exists(path))
        {
            yield break;
        }
        ISerializationService serializationService = Services.GetService <ISerializationService>();

        if (serializationService == null)
        {
            yield break;
        }
        XmlSerializer serializer = serializationService.GetXmlSerializer <GameSaveDescriptor>();
        List <string> fileNames  = new List <string>();

        fileNames.AddRange(Directory.GetFiles(path, "*.zip"));
        fileNames.AddRange(Directory.GetFiles(path, "*.sav"));
        Archive            archive            = null;
        GameSaveDescriptor gameSaveDescriptor = null;

        foreach (string fileName in fileNames)
        {
            gameSaveDescriptor = null;
            try
            {
                archive = Archive.Open(fileName, ArchiveMode.Open);
                MemoryStream stream = null;
                if (archive.TryGet(global::GameManager.GameSaveDescriptorFileName, out stream))
                {
                    XmlReaderSettings xmlReaderSettings = new XmlReaderSettings
                    {
                        IgnoreComments   = true,
                        IgnoreWhitespace = true,
                        CloseInput       = true
                    };
                    using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(stream, xmlReaderSettings))
                    {
                        if (reader.ReadToDescendant("GameSaveDescriptor"))
                        {
                            gameSaveDescriptor = (serializer.Deserialize(reader) as GameSaveDescriptor);
                            gameSaveDescriptor.SourceFileName = fileName;
                            if (gameSaveDescriptor.Version.Serial != Amplitude.Unity.Framework.Application.Version.Serial)
                            {
                                gameSaveDescriptor = null;
                            }
                        }
                    }
                }
            }
            catch
            {
                gameSaveDescriptor = null;
            }
            finally
            {
                if (archive != null)
                {
                    archive.Close();
                }
            }
            if (gameSaveDescriptor != null)
            {
                yield return(gameSaveDescriptor);
            }
        }
        yield break;
    }
Exemple #3
0
 public bool TryExtractGameSaveDescriptorFromFile(string outputFilePath, out GameSaveDescriptor gameSaveDescriptor, bool makeCurrent)
 {
     gameSaveDescriptor = null;
     if (File.Exists(outputFilePath))
     {
         Archive archive = null;
         try
         {
             archive = Archive.Open(outputFilePath, ArchiveMode.Open);
             MemoryStream stream = null;
             if (archive.TryGet(global::GameManager.GameSaveDescriptorFileName, out stream))
             {
                 XmlReaderSettings settings = new XmlReaderSettings
                 {
                     CloseInput     = true,
                     IgnoreComments = true,
                     IgnoreProcessingInstructions = true,
                     IgnoreWhitespace             = true
                 };
                 using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stream, settings))
                 {
                     if (xmlReader.ReadToDescendant("GameSaveDescriptor"))
                     {
                         ISerializationService service = Services.GetService <ISerializationService>();
                         XmlSerializer         xmlSerializer;
                         if (service != null)
                         {
                             xmlSerializer = service.GetXmlSerializer <GameSaveDescriptor>();
                         }
                         else
                         {
                             xmlSerializer = new XmlSerializer(typeof(GameSaveDescriptor));
                         }
                         gameSaveDescriptor = (xmlSerializer.Deserialize(xmlReader) as GameSaveDescriptor);
                         gameSaveDescriptor.SourceFileName = outputFilePath;
                         if (gameSaveDescriptor.Version.Serial != Amplitude.Unity.Framework.Application.Version.Serial)
                         {
                             Diagnostics.LogError("Invalid game save; application version does not match.");
                             gameSaveDescriptor = null;
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             Diagnostics.LogWarning("Exception caught: " + ex.ToString());
             gameSaveDescriptor = null;
         }
         finally
         {
             if (archive != null)
             {
                 archive.Close();
             }
         }
         if (gameSaveDescriptor != null)
         {
             if (makeCurrent)
             {
                 this.GameSaveDescriptor = gameSaveDescriptor;
             }
             return(true);
         }
     }
     return(false);
 }
Exemple #4
0
    public IEnumerable <GameSaveDescriptor> GetListOfGameSaveDescritors(bool withAutoSave)
    {
        string path = global::Application.GameSaveDirectory;

        if (string.IsNullOrEmpty(path))
        {
            yield break;
        }
        if (!Directory.Exists(path))
        {
            yield break;
        }
        ISerializationService serializationService = Services.GetService <ISerializationService>();

        if (serializationService == null)
        {
            yield break;
        }
        XmlSerializer   serializer      = serializationService.GetXmlSerializer <GameSaveDescriptor>();
        DirectoryInfo   directory       = new DirectoryInfo(path);
        List <FileInfo> compatibleFiles = new List <FileInfo>();

        compatibleFiles.AddRange(directory.GetFiles("*.zip"));
        compatibleFiles.AddRange(directory.GetFiles("*.sav"));
        FileInfo[] files = (from f in compatibleFiles
                            orderby f.LastWriteTime descending
                            select f).ToArray <FileInfo>();
        Archive            archive            = null;
        GameSaveDescriptor gameSaveDescriptor = null;
        XmlReaderSettings  xmlReaderSettings  = new XmlReaderSettings
        {
            CloseInput     = true,
            IgnoreComments = true,
            IgnoreProcessingInstructions = true,
            IgnoreWhitespace             = true
        };

        for (int i = 0; i < files.Length; i++)
        {
            gameSaveDescriptor = null;
            string fileName = files[i].FullName;
            try
            {
                archive = Archive.Open(fileName, ArchiveMode.Open);
                MemoryStream stream = null;
                if (archive.TryGet(global::GameManager.GameSaveDescriptorFileName, out stream))
                {
                    using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(stream, xmlReaderSettings))
                    {
                        if (reader.ReadToDescendant("GameSaveDescriptor"))
                        {
                            gameSaveDescriptor = (serializer.Deserialize(reader) as GameSaveDescriptor);
                            gameSaveDescriptor.SourceFileName = fileName;
                            if (gameSaveDescriptor.Version.Serial != Amplitude.Unity.Framework.Application.Version.Serial)
                            {
                                gameSaveDescriptor = null;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Exception exception = ex;
                Diagnostics.LogWarning("Exception caught: " + exception.ToString());
                gameSaveDescriptor = null;
            }
            finally
            {
                if (archive != null)
                {
                    archive.Close();
                }
            }
            if (gameSaveDescriptor != null && gameSaveDescriptor.Closed)
            {
                gameSaveDescriptor = null;
            }
            if (gameSaveDescriptor != null && (withAutoSave || !gameSaveDescriptor.Title.StartsWith(global::GameManager.AutoSaveFileName)))
            {
                yield return(gameSaveDescriptor);
            }
        }
        yield break;
    }
Exemple #5
0
    public GameSaveDescriptor GetMostRecentGameSaveDescritor()
    {
        string gameSaveDirectory = global::Application.GameSaveDirectory;

        if (string.IsNullOrEmpty(gameSaveDirectory))
        {
            return(null);
        }
        if (!Directory.Exists(gameSaveDirectory))
        {
            return(null);
        }
        ISerializationService service = Services.GetService <ISerializationService>();

        if (service == null)
        {
            return(null);
        }
        List <string>   list     = null;
        IRuntimeService service2 = Services.GetService <IRuntimeService>();

        if (service2 != null)
        {
            Diagnostics.Assert(service2.Runtime != null);
            Diagnostics.Assert(service2.Runtime.RuntimeModules != null);
            list = (from runtimeModule in service2.Runtime.RuntimeModules
                    select runtimeModule.Name).ToList <string>();
        }
        DirectoryInfo   directoryInfo = new DirectoryInfo(gameSaveDirectory);
        List <FileInfo> list2         = new List <FileInfo>();

        list2.AddRange(directoryInfo.GetFiles("*.zip"));
        list2.AddRange(directoryInfo.GetFiles("*.sav"));
        FileInfo[] array = (from f in list2
                            orderby f.LastWriteTime descending
                            select f).ToArray <FileInfo>();
        GameSaveDescriptor gameSaveDescriptor = null;

        if (array != null)
        {
            foreach (FileInfo fileInfo in array)
            {
                Archive archive = null;
                try
                {
                    archive = Archive.Open(fileInfo.FullName, ArchiveMode.Open);
                    MemoryStream stream = null;
                    if (archive.TryGet(global::GameManager.GameSaveDescriptorFileName, out stream))
                    {
                        XmlReaderSettings settings = new XmlReaderSettings
                        {
                            CloseInput     = true,
                            IgnoreComments = true,
                            IgnoreProcessingInstructions = true,
                            IgnoreWhitespace             = true
                        };
                        using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stream, settings))
                        {
                            if (xmlReader.ReadToDescendant("GameSaveDescriptor"))
                            {
                                XmlSerializer xmlSerializer = service.GetXmlSerializer <GameSaveDescriptor>();
                                gameSaveDescriptor = (xmlSerializer.Deserialize(xmlReader) as GameSaveDescriptor);
                                gameSaveDescriptor.SourceFileName = fileInfo.FullName;
                                if (gameSaveDescriptor.Version.Serial != Amplitude.Unity.Framework.Application.Version.Serial)
                                {
                                    gameSaveDescriptor = null;
                                }
                                if (gameSaveDescriptor != null)
                                {
                                    if (gameSaveDescriptor.RuntimeModules == null)
                                    {
                                        if (service2 != null)
                                        {
                                            if (list.Count != 1 || !(list[0] == service2.VanillaModuleName))
                                            {
                                                gameSaveDescriptor = null;
                                            }
                                        }
                                        else
                                        {
                                            gameSaveDescriptor = null;
                                        }
                                    }
                                    else
                                    {
                                        List <string> list3 = list.Except(gameSaveDescriptor.RuntimeModules).ToList <string>();
                                        List <string> list4 = gameSaveDescriptor.RuntimeModules.Except(list).ToList <string>();
                                        if (list3.Count + list4.Count != 0)
                                        {
                                            gameSaveDescriptor = null;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Diagnostics.LogWarning("Exception caught: " + ex.ToString());
                    gameSaveDescriptor = null;
                }
                finally
                {
                    if (archive != null)
                    {
                        archive.Close();
                    }
                }
                if (gameSaveDescriptor != null)
                {
                    break;
                }
            }
        }
        return(gameSaveDescriptor);
    }
    protected override IEnumerator OnShow(params object[] parameters)
    {
        yield return(base.OnShow(parameters));

        base.enabled = true;
        this.ActionVideoPlaybackComplete = null;
        Amplitude.Unity.Video.IVideoSettingsService service = Services.GetService <Amplitude.Unity.Video.IVideoSettingsService>();
        this.DisplaySubtitles = service.DisplaySubtitles;
        this.CutsceneSubtitle.AgeTransform.Visible = false;
        if (this.SubtitleBackdrop != null)
        {
            this.SubtitleBackdrop.AgeTransform.Visible = false;
        }
        if (parameters == null)
        {
            throw new InvalidOperationException();
        }
        if (parameters.Length >= 2)
        {
            this.ActionVideoPlaybackComplete = (parameters[1] as Action);
            if (this.ActionVideoPlaybackComplete == null)
            {
                Diagnostics.LogWarning("Invalid parameters[1] that should be of type 'System.Action'.");
            }
        }
        if (parameters.Length >= 1)
        {
            string text  = parameters[0] as string;
            string text2 = "Movies/";
            string text3 = null;
            string text4 = "english";
            ILocalizationService service2 = Services.GetService <ILocalizationService>();
            if (service2 != null && !string.IsNullOrEmpty(service2.CurrentLanguage))
            {
                text4 = service2.CurrentLanguage;
                if (text4 == "tchinese" || text4 == "schinese")
                {
                    text3 = text;
                    string newValue = "Chinese " + text2;
                    text = text.Replace(text2, newValue);
                }
            }
            if (!string.IsNullOrEmpty(text))
            {
                if (text3 != null && !File.Exists(text))
                {
                    text  = text3;
                    text4 = "english";
                }
                if (File.Exists(text) && this.VideoFrame != null)
                {
                    float value  = Amplitude.Unity.Framework.Application.Registry.GetValue <float>(Amplitude.Unity.Audio.AudioManager.Registers.MasterVolume, 1f);
                    bool  value2 = Amplitude.Unity.Framework.Application.Registry.GetValue <bool>(Amplitude.Unity.Audio.AudioManager.Registers.MasterMute, false);
                    this.VideoFrame.Volume = ((!value2) ? value : 0f);
                    this.VideoFrame.LoadMovie(text, false, false);
                    if (this.DisplaySubtitles && this.VideoFrame.BinkMovie != null)
                    {
                        string extension = string.Format(".Subtitles-{0}.xml", text4);
                        string path      = System.IO.Path.ChangeExtension(text, extension);
                        if (!File.Exists(path))
                        {
                            goto IL_2BD;
                        }
                        ISerializationService service3 = Services.GetService <ISerializationService>();
                        if (service3 == null)
                        {
                            goto IL_2BD;
                        }
                        XmlSerializer xmlSerializer = service3.GetXmlSerializer <VideoSubtitles>();
                        if (xmlSerializer == null)
                        {
                            goto IL_2BD;
                        }
                        using (Stream stream = File.OpenRead(path))
                        {
                            VideoSubtitles videoSubtitles = xmlSerializer.Deserialize(stream) as VideoSubtitles;
                            if (videoSubtitles != null && videoSubtitles.Subtitles != null)
                            {
                                this.Subtitles            = videoSubtitles.Subtitles;
                                this.CurrentSubtitleIndex = videoSubtitles.Subtitles.Length;
                                this.NextSubtitleIndex    = 0;
                                this.binkSummary          = default(Bink.BINKSUMMARY);
                            }
                            yield break;
                        }
                    }
                    this.Subtitles            = null;
                    this.CurrentSubtitleIndex = 0;
                    this.NextSubtitleIndex    = 0;
                }
            }
        }
IL_2BD:
        yield break;
    }
    private void CreateCustomFaction()
    {
        this.Faction.Affinity        = new XmlNamedReference(this.selectedAffinity.Name);
        this.Faction.AffinityMapping = new XmlNamedReference(this.SelectedAffinityMapping.Name);
        this.Faction.TraitReferences = (from guiTrait in this.selectedGuiTraits
                                        select new XmlNamedReference(guiTrait.Name)).ToArray <XmlNamedReference>();
        this.Faction.LocalizedName        = this.NameTextField.AgePrimitiveLabel.Text.Trim();
        this.Faction.LocalizedDescription = this.DescriptionTextField.AgePrimitiveLabel.Text.Trim();
        this.Faction.Author     = this.AuthorTextField.AgePrimitiveLabel.Text.Trim();
        this.Faction.IsCustom   = true;
        this.Faction.IsStandard = false;
        List <GuiError> list = new List <GuiError>();

        if (!GuiFaction.IsValidCustomFaction(this.Faction, list))
        {
            string message = string.Join("\r\n", (from guiError in list
                                                  select guiError.ToString()).ToArray <string>());
            MessagePanel.Instance.Show(message, "%CustomFactionInvalidCustomFactionTitle", MessagePanelButtons.Ok, null, MessagePanelType.WARNING, new MessagePanelButton[0]);
            this.HandleCancelRequest();
            return;
        }
        if (string.IsNullOrEmpty(this.Faction.FileName))
        {
            string        path          = System.IO.Path.Combine(Amplitude.Unity.Framework.Application.GameDirectory, "Custom Factions");
            DirectoryInfo directoryInfo = new DirectoryInfo(path);
            if (!directoryInfo.Exists)
            {
                directoryInfo.Create();
            }
            string text = this.Faction.LocalizedName;
            char[] invalidFileNameChars = System.IO.Path.GetInvalidFileNameChars();
            foreach (char oldChar in invalidFileNameChars)
            {
                text = text.Replace(oldChar, '@');
            }
            this.Faction.FileName = System.IO.Path.Combine(directoryInfo.FullName, text);
            this.Faction.FileName = System.IO.Path.ChangeExtension(this.Faction.FileName, ".xml");
        }
        if (!string.IsNullOrEmpty(this.Faction.FileName))
        {
            ISerializationService service = Services.GetService <ISerializationService>();
            if (service != null)
            {
                XmlSerializer xmlSerializer = service.GetXmlSerializer <Faction>();
                if (xmlSerializer != null)
                {
                    using (Stream stream = File.Open(this.Faction.FileName, FileMode.Create))
                    {
                        xmlSerializer.Serialize(stream, this.Faction);
                    }
                }
            }
        }
        IDatabase <Faction> database = Databases.GetDatabase <Faction>(false);

        database.Touch(this.Faction);
        base.GuiService.GetGuiPanel <MenuNewGameScreen>().OnCustomFactionChanged(this.Faction);
        base.GuiService.GetGuiPanel <MenuFactionScreen>().Show(new object[]
        {
            this.empireIndex,
            this.Faction
        });
        this.Faction = null;
    }